[BACK]Return to bus.h CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / arch / newsmips / include

Annotation of src/sys/arch/newsmips/include/bus.h, Revision 1.15

1.15    ! yamt        1: /*     $NetBSD: bus.h,v 1.14 2006/02/16 20:17:14 perry Exp $   */
1.1       onoe        2:
                      3: /*
1.3       thorpej     4:  * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
1.1       onoe        5:  * All rights reserved.
                      6:  *
                      7:  * This code is derived from software contributed to The NetBSD Foundation
                      8:  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
                      9:  * NASA Ames Research Center.
                     10:  *
                     11:  * Redistribution and use in source and binary forms, with or without
                     12:  * modification, are permitted provided that the following conditions
                     13:  * are met:
                     14:  * 1. Redistributions of source code must retain the above copyright
                     15:  *    notice, this list of conditions and the following disclaimer.
                     16:  * 2. Redistributions in binary form must reproduce the above copyright
                     17:  *    notice, this list of conditions and the following disclaimer in the
                     18:  *    documentation and/or other materials provided with the distribution.
                     19:  * 3. All advertising materials mentioning features or use of this software
                     20:  *    must display the following acknowledgement:
                     21:  *     This product includes software developed by the NetBSD
                     22:  *     Foundation, Inc. and its contributors.
                     23:  * 4. Neither the name of The NetBSD Foundation nor the names of its
                     24:  *    contributors may be used to endorse or promote products derived
                     25:  *    from this software without specific prior written permission.
                     26:  *
                     27:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     28:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     29:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     30:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     31:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     32:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     33:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     34:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     35:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     36:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     37:  * POSSIBILITY OF SUCH DAMAGE.
                     38:  */
                     39:
                     40: #ifndef _NEWSMIPS_BUS_H_
                     41: #define _NEWSMIPS_BUS_H_
                     42:
                     43: #include <mips/locore.h>
                     44:
                     45: /*
                     46:  * Utility macros; do not use outside this file.
                     47:  */
1.10      tsutsui    48: #define        __PB_TYPENAME_PREFIX(BITS)      ___CONCAT(uint,BITS)
1.1       onoe       49: #define        __PB_TYPENAME(BITS)             ___CONCAT(__PB_TYPENAME_PREFIX(BITS),_t)
                     50:
                     51: /*
                     52:  * Bus address and size types
                     53:  */
                     54: typedef u_long bus_addr_t;
                     55: typedef u_long bus_size_t;
                     56:
                     57: /*
                     58:  * Access methods for bus resources and address space.
                     59:  */
                     60: typedef int    bus_space_tag_t;
                     61: typedef u_long bus_space_handle_t;
                     62:
                     63: /*
                     64:  *     int bus_space_map(bus_space_tag_t t, bus_addr_t addr,
                     65:  *         bus_size_t size, int flags, bus_space_handle_t *bshp);
                     66:  *
                     67:  * Map a region of bus space.
                     68:  */
                     69:
                     70: #define        BUS_SPACE_MAP_CACHEABLE         0x01
                     71: #define        BUS_SPACE_MAP_LINEAR            0x02
                     72: #define BUS_SPACE_MAP_PREFETCHABLE     0x04
                     73:
                     74: int    bus_space_map(bus_space_tag_t, bus_addr_t, bus_size_t,
                     75:            int, bus_space_handle_t *);
                     76:
                     77: /*
                     78:  *     void bus_space_unmap(bus_space_tag_t t,
                     79:  *          bus_space_handle_t bsh, bus_size_t size);
                     80:  *
                     81:  * Unmap a region of bus space.
                     82:  */
                     83:
                     84: void   bus_space_unmap (bus_space_tag_t, bus_space_handle_t, bus_size_t);
                     85:
                     86: /*
                     87:  *     int bus_space_subregion(bus_space_tag_t t,
                     88:  *         bus_space_handle_t bsh, bus_size_t offset, bus_size_t size,
                     89:  *         bus_space_handle_t *nbshp);
                     90:  *
                     91:  * Get a new handle for a subregion of an already-mapped area of bus space.
                     92:  */
                     93:
                     94: int    bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh,
                     95:            bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp);
                     96:
                     97: /*
                     98:  *     int bus_space_alloc(bus_space_tag_t t, bus_addr_t, rstart,
                     99:  *         bus_addr_t rend, bus_size_t size, bus_size_t align,
                    100:  *         bus_size_t boundary, int flags, bus_addr_t *addrp,
                    101:  *         bus_space_handle_t *bshp);
                    102:  *
                    103:  * Allocate a region of bus space.
                    104:  */
                    105:
                    106: int    bus_space_alloc (bus_space_tag_t t, bus_addr_t rstart,
                    107:            bus_addr_t rend, bus_size_t size, bus_size_t align,
                    108:            bus_size_t boundary, int cacheable, bus_addr_t *addrp,
                    109:            bus_space_handle_t *bshp);
                    110:
                    111: /*
                    112:  *     int bus_space_free (bus_space_tag_t t,
                    113:  *         bus_space_handle_t bsh, bus_size_t size);
                    114:  *
                    115:  * Free a region of bus space.
                    116:  */
                    117:
                    118: void   bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh,
                    119:            bus_size_t size);
                    120:
                    121: /*
1.9       tsutsui   122:  *     uintN_t bus_space_read_N(bus_space_tag_t tag,
1.1       onoe      123:  *         bus_space_handle_t bsh, bus_size_t offset);
                    124:  *
                    125:  * Read a 1, 2, 4, or 8 byte quantity from bus space
                    126:  * described by tag/handle/offset.
                    127:  */
                    128:
                    129: #define        bus_space_read_1(t, h, o)                                       \
1.9       tsutsui   130:      ((void) t, (*(volatile uint8_t *)((h) + (o))))
1.1       onoe      131:
                    132: #define        bus_space_read_2(t, h, o)                                       \
1.9       tsutsui   133:      ((void) t, (*(volatile uint16_t *)((h) + (o))))
1.1       onoe      134:
                    135: #define        bus_space_read_4(t, h, o)                                       \
1.9       tsutsui   136:      ((void) t, (*(volatile uint32_t *)((h) + (o))))
1.1       onoe      137:
                    138: #if 0  /* Cause a link error for bus_space_read_8 */
                    139: #define        bus_space_read_8(t, h, o)       !!! bus_space_read_8 unimplemented !!!
                    140: #endif
                    141:
                    142: /*
                    143:  *     void bus_space_read_multi_N(bus_space_tag_t tag,
                    144:  *         bus_space_handle_t bsh, bus_size_t offset,
1.9       tsutsui   145:  *         uintN_t *addr, size_t count);
1.1       onoe      146:  *
                    147:  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
                    148:  * described by tag/handle/offset and copy into buffer provided.
                    149:  */
                    150:
                    151: #define __NEWSMIPS_bus_space_read_multi(BYTES,BITS)                    \
1.14      perry     152: static __inline void __CONCAT(bus_space_read_multi_,BYTES)             \
1.1       onoe      153:        (bus_space_tag_t, bus_space_handle_t, bus_size_t,               \
                    154:        __PB_TYPENAME(BITS) *, size_t);                                 \
                    155:                                                                        \
1.14      perry     156: static __inline void                                                   \
1.1       onoe      157: __CONCAT(bus_space_read_multi_,BYTES)(t, h, o, a, c)                   \
                    158:        bus_space_tag_t t;                                              \
                    159:        bus_space_handle_t h;                                           \
                    160:        bus_size_t o;                                                   \
                    161:        __PB_TYPENAME(BITS) *a;                                         \
                    162:        size_t c;                                                       \
                    163: {                                                                      \
                    164:                                                                        \
                    165:        while (c--)                                                     \
                    166:                *a++ = __CONCAT(bus_space_read_,BYTES)(t, h, o);        \
                    167: }
                    168:
                    169: __NEWSMIPS_bus_space_read_multi(1,8)
                    170: __NEWSMIPS_bus_space_read_multi(2,16)
                    171: __NEWSMIPS_bus_space_read_multi(4,32)
                    172:
                    173: #if 0  /* Cause a link error for bus_space_read_multi_8 */
                    174: #define        bus_space_read_multi_8  !!! bus_space_read_multi_8 unimplemented !!!
                    175: #endif
                    176:
                    177: #undef __NEWSMIPS_bus_space_read_multi
                    178:
                    179: /*
                    180:  *     void bus_space_read_region_N(bus_space_tag_t tag,
                    181:  *         bus_space_handle_t bsh, bus_size_t offset,
1.9       tsutsui   182:  *         uintN_t *addr, size_t count);
1.1       onoe      183:  *
                    184:  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
                    185:  * described by tag/handle and starting at `offset' and copy into
                    186:  * buffer provided.
                    187:  */
                    188:
                    189: #define __NEWSMIPS_bus_space_read_region(BYTES,BITS)                   \
1.14      perry     190: static __inline void __CONCAT(bus_space_read_region_,BYTES)            \
1.1       onoe      191:        (bus_space_tag_t, bus_space_handle_t, bus_size_t,               \
                    192:        __PB_TYPENAME(BITS) *, size_t);                                 \
                    193:                                                                        \
1.14      perry     194: static __inline void                                                   \
1.1       onoe      195: __CONCAT(bus_space_read_region_,BYTES)(t, h, o, a, c)                  \
                    196:        bus_space_tag_t t;                                              \
                    197:        bus_space_handle_t h;                                           \
                    198:        bus_size_t o;                                                   \
                    199:        __PB_TYPENAME(BITS) *a;                                         \
                    200:        size_t c;                                                       \
                    201: {                                                                      \
                    202:                                                                        \
                    203:        while (c--) {                                                   \
                    204:                *a++ = __CONCAT(bus_space_read_,BYTES)(t, h, o);        \
                    205:                o += BYTES;                                             \
                    206:        }                                                               \
                    207: }
                    208:
                    209: __NEWSMIPS_bus_space_read_region(1,8)
                    210: __NEWSMIPS_bus_space_read_region(2,16)
                    211: __NEWSMIPS_bus_space_read_region(4,32)
                    212:
                    213: #if 0  /* Cause a link error for bus_space_read_region_8 */
                    214: #define        bus_space_read_region_8 !!! bus_space_read_region_8 unimplemented !!!
                    215: #endif
                    216:
                    217: #undef __NEWSMIPS_bus_space_read_region
                    218:
                    219: /*
                    220:  *     void bus_space_write_N(bus_space_tag_t tag,
                    221:  *         bus_space_handle_t bsh, bus_size_t offset,
1.9       tsutsui   222:  *         uintN_t value);
1.1       onoe      223:  *
                    224:  * Write the 1, 2, 4, or 8 byte value `value' to bus space
                    225:  * described by tag/handle/offset.
                    226:  */
                    227:
                    228: #define        bus_space_write_1(t, h, o, v)                                   \
                    229: do {                                                                   \
                    230:        (void) t;                                                       \
1.9       tsutsui   231:        *(volatile uint8_t *)((h) + (o)) = (v);                 \
1.1       onoe      232: } while (0)
                    233:
                    234: #define        bus_space_write_2(t, h, o, v)                                   \
                    235: do {                                                                   \
                    236:        (void) t;                                                       \
1.9       tsutsui   237:        *(volatile uint16_t *)((h) + (o)) = (v);                        \
1.1       onoe      238: } while (0)
                    239:
                    240: #define        bus_space_write_4(t, h, o, v)                                   \
                    241: do {                                                                   \
                    242:        (void) t;                                                       \
1.9       tsutsui   243:        *(volatile uint32_t *)((h) + (o)) = (v);                        \
1.1       onoe      244: } while (0)
                    245:
                    246: #if 0  /* Cause a link error for bus_space_write_8 */
                    247: #define        bus_space_write_8       !!! bus_space_write_8 not implemented !!!
                    248: #endif
                    249:
                    250: /*
                    251:  *     void bus_space_write_multi_N(bus_space_tag_t tag,
                    252:  *         bus_space_handle_t bsh, bus_size_t offset,
1.9       tsutsui   253:  *         const uintN_t *addr, size_t count);
1.1       onoe      254:  *
                    255:  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
                    256:  * provided to bus space described by tag/handle/offset.
                    257:  */
                    258:
                    259: #define __NEWSMIPS_bus_space_write_multi(BYTES,BITS)                   \
1.14      perry     260: static __inline void __CONCAT(bus_space_write_multi_,BYTES)            \
1.1       onoe      261:        (bus_space_tag_t, bus_space_handle_t, bus_size_t,               \
                    262:        const __PB_TYPENAME(BITS) *, size_t);                           \
                    263:                                                                        \
1.14      perry     264: static __inline void                                                   \
1.1       onoe      265: __CONCAT(bus_space_write_multi_,BYTES)(t, h, o, a, c)                  \
                    266:        bus_space_tag_t t;                                              \
                    267:        bus_space_handle_t h;                                           \
                    268:        bus_size_t o;                                                   \
                    269:        const __PB_TYPENAME(BITS) *a;                                   \
                    270:        size_t c;                                                       \
                    271: {                                                                      \
                    272:                                                                        \
                    273:        while (c--)                                                     \
                    274:                __CONCAT(bus_space_write_,BYTES)(t, h, o, *a++);        \
                    275: }
                    276:
                    277: __NEWSMIPS_bus_space_write_multi(1,8)
                    278: __NEWSMIPS_bus_space_write_multi(2,16)
                    279: __NEWSMIPS_bus_space_write_multi(4,32)
                    280:
                    281: #if 0  /* Cause a link error for bus_space_write_8 */
                    282: #define        bus_space_write_multi_8(t, h, o, a, c)                          \
                    283:                        !!! bus_space_write_multi_8 unimplimented !!!
                    284: #endif
                    285:
                    286: #undef __NEWSMIPS_bus_space_write_multi
                    287:
                    288: /*
                    289:  *     void bus_space_write_region_N(bus_space_tag_t tag,
                    290:  *         bus_space_handle_t bsh, bus_size_t offset,
1.9       tsutsui   291:  *         const uintN_t *addr, size_t count);
1.1       onoe      292:  *
                    293:  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
                    294:  * to bus space described by tag/handle starting at `offset'.
                    295:  */
                    296:
                    297: #define __NEWSMIPS_bus_space_write_region(BYTES,BITS)                  \
1.14      perry     298: static __inline void __CONCAT(bus_space_write_region_,BYTES)           \
1.1       onoe      299:        (bus_space_tag_t, bus_space_handle_t, bus_size_t,               \
                    300:        const __PB_TYPENAME(BITS) *, size_t);                           \
                    301:                                                                        \
1.14      perry     302: static __inline void                                                   \
1.1       onoe      303: __CONCAT(bus_space_write_region_,BYTES)(t, h, o, a, c)                 \
                    304:        bus_space_tag_t t;                                              \
                    305:        bus_space_handle_t h;                                           \
                    306:        bus_size_t o;                                                   \
                    307:        const __PB_TYPENAME(BITS) *a;                                   \
                    308:        size_t c;                                                       \
                    309: {                                                                      \
                    310:                                                                        \
                    311:        while (c--) {                                                   \
                    312:                __CONCAT(bus_space_write_,BYTES)(t, h, o, *a++);        \
                    313:                o += BYTES;                                             \
                    314:        }                                                               \
                    315: }
                    316:
                    317: __NEWSMIPS_bus_space_write_region(1,8)
                    318: __NEWSMIPS_bus_space_write_region(2,16)
                    319: __NEWSMIPS_bus_space_write_region(4,32)
                    320:
                    321: #if 0  /* Cause a link error for bus_space_write_region_8 */
                    322: #define        bus_space_write_region_8                                        \
                    323:                        !!! bus_space_write_region_8 unimplemented !!!
                    324: #endif
                    325:
                    326: #undef __NEWSMIPS_bus_space_write_region
                    327:
                    328: /*
                    329:  *     void bus_space_set_multi_N(bus_space_tag_t tag,
1.9       tsutsui   330:  *         bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
1.1       onoe      331:  *         size_t count);
                    332:  *
                    333:  * Write the 1, 2, 4, or 8 byte value `val' to bus space described
                    334:  * by tag/handle/offset `count' times.
                    335:  */
                    336:
                    337: #define __NEWSMIPS_bus_space_set_multi(BYTES,BITS)                     \
1.14      perry     338: static __inline void __CONCAT(bus_space_set_multi_,BYTES)              \
1.1       onoe      339:        (bus_space_tag_t, bus_space_handle_t, bus_size_t,               \
                    340:        __PB_TYPENAME(BITS), size_t);                                   \
                    341:                                                                        \
1.14      perry     342: static __inline void                                                   \
1.1       onoe      343: __CONCAT(bus_space_set_multi_,BYTES)(t, h, o, v, c)                    \
                    344:        bus_space_tag_t t;                                              \
                    345:        bus_space_handle_t h;                                           \
                    346:        bus_size_t o;                                                   \
                    347:        __PB_TYPENAME(BITS) v;                                          \
                    348:        size_t c;                                                       \
                    349: {                                                                      \
                    350:                                                                        \
                    351:        while (c--)                                                     \
                    352:                __CONCAT(bus_space_write_,BYTES)(t, h, o, v);           \
                    353: }
                    354:
                    355: __NEWSMIPS_bus_space_set_multi(1,8)
                    356: __NEWSMIPS_bus_space_set_multi(2,16)
                    357: __NEWSMIPS_bus_space_set_multi(4,32)
                    358:
                    359: #if 0  /* Cause a link error for bus_space_set_multi_8 */
                    360: #define        bus_space_set_multi_8                                           \
                    361:                        !!! bus_space_set_multi_8 unimplemented !!!
                    362: #endif
                    363:
                    364: #undef __NEWSMIPS_bus_space_set_multi
                    365:
                    366: /*
                    367:  *     void bus_space_set_region_N(bus_space_tag_t tag,
1.9       tsutsui   368:  *         bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
1.1       onoe      369:  *         size_t count);
                    370:  *
                    371:  * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
                    372:  * by tag/handle starting at `offset'.
                    373:  */
                    374:
                    375: #define __NEWSMIPS_bus_space_set_region(BYTES,BITS)                    \
1.14      perry     376: static __inline void __CONCAT(bus_space_set_region_,BYTES)             \
1.1       onoe      377:        (bus_space_tag_t, bus_space_handle_t, bus_size_t,               \
                    378:        __PB_TYPENAME(BITS), size_t);                                   \
                    379:                                                                        \
1.14      perry     380: static __inline void                                                   \
1.1       onoe      381: __CONCAT(bus_space_set_region_,BYTES)(t, h, o, v, c)                   \
                    382:        bus_space_tag_t t;                                              \
                    383:        bus_space_handle_t h;                                           \
                    384:        bus_size_t o;                                                   \
                    385:        __PB_TYPENAME(BITS) v;                                          \
                    386:        size_t c;                                                       \
                    387: {                                                                      \
                    388:                                                                        \
                    389:        while (c--) {                                                   \
                    390:                __CONCAT(bus_space_write_,BYTES)(t, h, o, v);           \
                    391:                o += BYTES;                                             \
                    392:        }                                                               \
                    393: }
                    394:
                    395: __NEWSMIPS_bus_space_set_region(1,8)
                    396: __NEWSMIPS_bus_space_set_region(2,16)
                    397: __NEWSMIPS_bus_space_set_region(4,32)
                    398:
                    399: #if 0  /* Cause a link error for bus_space_set_region_8 */
                    400: #define        bus_space_set_region_8                                          \
                    401:                        !!! bus_space_set_region_8 unimplemented !!!
                    402: #endif
                    403:
                    404: #undef __NEWSMIPS_bus_space_set_region
                    405:
                    406: /*
                    407:  *     void bus_space_copy_region_N(bus_space_tag_t tag,
                    408:  *         bus_space_handle_t bsh1, bus_size_t off1,
                    409:  *         bus_space_handle_t bsh2, bus_size_t off2,
                    410:  *         bus_size_t count);
                    411:  *
                    412:  * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
                    413:  * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
                    414:  */
                    415:
                    416: #define        __NEWSMIPS_copy_region(BYTES)                                   \
1.14      perry     417: static __inline void __CONCAT(bus_space_copy_region_,BYTES)            \
1.1       onoe      418:        (bus_space_tag_t,                                               \
                    419:            bus_space_handle_t bsh1, bus_size_t off1,                   \
                    420:            bus_space_handle_t bsh2, bus_size_t off2,                   \
                    421:            bus_size_t count);                                          \
                    422:                                                                        \
1.14      perry     423: static __inline void                                                   \
1.1       onoe      424: __CONCAT(bus_space_copy_region_,BYTES)(t, h1, o1, h2, o2, c)           \
                    425:        bus_space_tag_t t;                                              \
                    426:        bus_space_handle_t h1, h2;                                      \
                    427:        bus_size_t o1, o2, c;                                           \
                    428: {                                                                      \
                    429:        bus_size_t o;                                                   \
                    430:                                                                        \
                    431:        if ((h1 + o1) >= (h2 + o2)) {                                   \
                    432:                /* src after dest: copy forward */                      \
                    433:                for (o = 0; c != 0; c--, o += BYTES)                    \
                    434:                        __CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o, \
                    435:                            __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
                    436:        } else {                                                        \
                    437:                /* dest after src: copy backwards */                    \
                    438:                for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES)      \
                    439:                        __CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o, \
                    440:                            __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
                    441:        }                                                               \
                    442: }
                    443:
                    444: __NEWSMIPS_copy_region(1)
                    445: __NEWSMIPS_copy_region(2)
                    446: __NEWSMIPS_copy_region(4)
                    447:
                    448: #if 0  /* Cause a link error for bus_space_copy_region_8 */
                    449: #define        bus_space_copy_region_8                                         \
                    450:                        !!! bus_space_copy_region_8 unimplemented !!!
                    451: #endif
                    452:
                    453: #undef __NEWSMIPS_copy_region
                    454:
                    455: /*
                    456:  * Bus read/write barrier methods.
                    457:  *
                    458:  *     void bus_space_barrier(bus_space_tag_t tag,
                    459:  *         bus_space_handle_t bsh, bus_size_t offset,
                    460:  *         bus_size_t len, int flags);
                    461:  *
                    462:  * On the MIPS, we just flush the write buffer.
                    463:  */
                    464: #define        bus_space_barrier(t, h, o, l, f)        \
                    465:        ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)), \
                    466:         wbflush())
                    467: #define        BUS_SPACE_BARRIER_READ  0x01            /* force read barrier */
                    468: #define        BUS_SPACE_BARRIER_WRITE 0x02            /* force write barrier */
                    469:
                    470: #undef __PB_TYPENAME_PREFIX
                    471: #undef __PB_TYPENAME
                    472:
                    473: #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
                    474:
                    475: /*
                    476:  * Flags used in various bus DMA methods.
                    477:  */
1.4       thorpej   478: #define        BUS_DMA_WAITOK          0x000   /* safe to sleep (pseudo-flag) */
                    479: #define        BUS_DMA_NOWAIT          0x001   /* not safe to sleep */
                    480: #define        BUS_DMA_ALLOCNOW        0x002   /* perform resource allocation now */
                    481: #define        BUS_DMA_COHERENT        0x004   /* hint: map memory DMA coherent */
                    482: #define        BUS_DMA_STREAMING       0x008   /* hint: sequential, unidirectional */
                    483: #define        BUS_DMA_BUS1            0x010   /* placeholders for bus functions... */
                    484: #define        BUS_DMA_BUS2            0x020
                    485: #define        BUS_DMA_BUS3            0x040
                    486: #define        BUS_DMA_BUS4            0x080
                    487: #define        BUS_DMA_READ            0x100   /* mapping is device -> memory only */
                    488: #define        BUS_DMA_WRITE           0x200   /* mapping is memory -> device only */
1.7       kent      489: #define        BUS_DMA_NOCACHE         0x400   /* hint: map non-cached memory */
1.1       onoe      490:
1.6       simonb    491: #define        NEWSMIPS_DMAMAP_COHERENT 0x10000 /* no cache flush necessary on sync */
                    492: #define        NEWSMIPS_DMAMAP_MAPTBL  0x20000 /* use DMA maping table */
1.1       onoe      493:
                    494: /* Forwards needed by prototypes below. */
                    495: struct mbuf;
                    496: struct uio;
                    497:
                    498: /*
                    499:  * Operations performed by bus_dmamap_sync().
                    500:  */
                    501: #define        BUS_DMASYNC_PREREAD     0x01    /* pre-read synchronization */
                    502: #define        BUS_DMASYNC_POSTREAD    0x02    /* post-read synchronization */
                    503: #define        BUS_DMASYNC_PREWRITE    0x04    /* pre-write synchronization */
                    504: #define        BUS_DMASYNC_POSTWRITE   0x08    /* post-write synchronization */
                    505:
                    506: typedef struct newsmips_bus_dma_tag            *bus_dma_tag_t;
                    507: typedef struct newsmips_bus_dmamap             *bus_dmamap_t;
1.8       fvdl      508:
                    509: #define BUS_DMA_TAG_VALID(t)    ((t) != (bus_dma_tag_t)0)
1.1       onoe      510:
                    511: /*
                    512:  *     bus_dma_segment_t
                    513:  *
                    514:  *     Describes a single contiguous DMA transaction.  Values
                    515:  *     are suitable for programming into DMA registers.
                    516:  */
                    517: struct newsmips_bus_dma_segment {
                    518:        bus_addr_t      ds_addr;        /* DMA address */
                    519:        bus_size_t      ds_len;         /* length of transfer */
                    520:        bus_addr_t      _ds_vaddr;      /* virtual address, 0 if invalid */
                    521: };
                    522: typedef struct newsmips_bus_dma_segment        bus_dma_segment_t;
                    523:
                    524: /*
                    525:  *     bus_dma_tag_t
                    526:  *
                    527:  *     A machine-dependent opaque type describing the implementation of
                    528:  *     DMA for a given bus.
                    529:  */
                    530:
                    531: struct newsmips_bus_dma_tag {
                    532:        /*
                    533:         * DMA mapping methods.
                    534:         */
                    535:        int     (*_dmamap_create)(bus_dma_tag_t, bus_size_t, int,
                    536:                    bus_size_t, bus_size_t, int, bus_dmamap_t *);
                    537:        void    (*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t);
                    538:        int     (*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *,
                    539:                    bus_size_t, struct proc *, int);
                    540:        int     (*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t,
                    541:                    struct mbuf *, int);
                    542:        int     (*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t,
                    543:                    struct uio *, int);
                    544:        int     (*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t,
                    545:                    bus_dma_segment_t *, int, bus_size_t, int);
                    546:        void    (*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t);
                    547:        void    (*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t,
                    548:                    bus_addr_t, bus_size_t, int);
                    549:
                    550:        /*
                    551:         * DMA memory utility functions.
                    552:         */
                    553:        int     (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t,
                    554:                    bus_size_t, bus_dma_segment_t *, int, int *, int);
                    555:        void    (*_dmamem_free)(bus_dma_tag_t,
                    556:                    bus_dma_segment_t *, int);
                    557:        int     (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *,
                    558:                    int, size_t, caddr_t *, int);
                    559:        void    (*_dmamem_unmap)(bus_dma_tag_t, caddr_t, size_t);
                    560:        paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *,
                    561:                    int, off_t, int, int);
                    562:
                    563:        /*
                    564:         * NEWSMIPS quirks.
                    565:         * This is NOT a constant.  Slot dependent information is
                    566:         * required to flush DMA cache correctly.
                    567:         */
                    568:        int     _slotno;
                    569:        bus_space_tag_t _slotbaset;
                    570:        bus_space_handle_t _slotbaseh;
                    571: };
                    572:
                    573: #define        bus_dmamap_create(t, s, n, m, b, f, p)                  \
                    574:        (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
                    575: #define        bus_dmamap_destroy(t, p)                                \
                    576:        (*(t)->_dmamap_destroy)((t), (p))
                    577: #define        bus_dmamap_load(t, m, b, s, p, f)                       \
                    578:        (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
                    579: #define        bus_dmamap_load_mbuf(t, m, b, f)                        \
                    580:        (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
                    581: #define        bus_dmamap_load_uio(t, m, u, f)                         \
                    582:        (*(t)->_dmamap_load_uio)((t), (m), (u), (f))
                    583: #define        bus_dmamap_load_raw(t, m, sg, n, s, f)                  \
                    584:        (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
                    585: #define        bus_dmamap_unload(t, p)                                 \
                    586:        (*(t)->_dmamap_unload)((t), (p))
                    587: #define        bus_dmamap_sync(t, p, o, l, ops)                        \
                    588:        (*(t)->_dmamap_sync)((t), (p), (o), (l), (ops))
                    589:
                    590: #define        bus_dmamem_alloc(t, s, a, b, sg, n, r, f)               \
                    591:        (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
                    592: #define        bus_dmamem_free(t, sg, n)                               \
                    593:        (*(t)->_dmamem_free)((t), (sg), (n))
                    594: #define        bus_dmamem_map(t, sg, n, s, k, f)                       \
                    595:        (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
                    596: #define        bus_dmamem_unmap(t, k, s)                               \
                    597:        (*(t)->_dmamem_unmap)((t), (k), (s))
                    598: #define        bus_dmamem_mmap(t, sg, n, o, p, f)                      \
                    599:        (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
                    600:
                    601: /*
                    602:  *     bus_dmamap_t
                    603:  *
                    604:  *     Describes a DMA mapping.
                    605:  */
                    606: struct newsmips_bus_dmamap {
                    607:        /*
                    608:         * PRIVATE MEMBERS: not for use my machine-independent code.
                    609:         */
                    610:        bus_size_t      _dm_size;       /* largest DMA transfer mappable */
                    611:        int             _dm_segcnt;     /* number of segs this map can map */
1.11      matt      612:        bus_size_t      _dm_maxmaxsegsz; /* fixed largest possible segment */
1.1       onoe      613:        bus_size_t      _dm_boundary;   /* don't cross this */
                    614:        int             _dm_flags;      /* misc. flags */
1.2       onoe      615:        int             _dm_maptbl;     /* DMA mapping table index */
                    616:        int             _dm_maptblcnt;  /* number of DMA mapping table */
1.15    ! yamt      617:        struct vmspace  *_dm_vmspace;   /* vmspace that owns the mapping */
1.1       onoe      618:
                    619:        /*
                    620:         * PUBLIC MEMBERS: these are used by machine-independent code.
                    621:         */
1.11      matt      622:        bus_size_t      dm_maxsegsz;    /* largest possible segment */
1.1       onoe      623:        bus_size_t      dm_mapsize;     /* size of the mapping */
                    624:        int             dm_nsegs;       /* # valid segments in mapping */
                    625:        bus_dma_segment_t dm_segs[1];   /* segments; variable length */
                    626: };
                    627:
                    628: #ifdef _NEWSMIPS_BUS_DMA_PRIVATE
1.5       thorpej   629: void   newsmips_bus_dma_init(void);
                    630:
1.1       onoe      631: int    _bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t,
                    632:            bus_size_t, int, bus_dmamap_t *);
                    633: void   _bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
                    634: int    _bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *,
                    635:            bus_size_t, struct proc *, int);
                    636: int    _bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t,
                    637:            struct mbuf *, int);
                    638: int    _bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t,
                    639:            struct uio *, int);
                    640: int    _bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t,
                    641:            bus_dma_segment_t *, int, bus_size_t, int);
                    642: void   _bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
1.5       thorpej   643: void   _bus_dmamap_sync_r3k(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
                    644:            bus_size_t, int);
                    645: void   _bus_dmamap_sync_r4k(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
1.1       onoe      646:            bus_size_t, int);
                    647:
                    648: int    _bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size,
                    649:            bus_size_t alignment, bus_size_t boundary,
                    650:            bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags);
                    651: void   _bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs,
                    652:            int nsegs);
                    653: int    _bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs,
                    654:            int nsegs, size_t size, caddr_t *kvap, int flags);
                    655: void   _bus_dmamem_unmap(bus_dma_tag_t tag, caddr_t kva,
                    656:            size_t size);
                    657: paddr_t        _bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs,
                    658:            int nsegs, off_t off, int prot, int flags);
                    659:
                    660: int    _bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size,
                    661:            bus_size_t alignment, bus_size_t boundary,
                    662:            bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
                    663:            vaddr_t low, vaddr_t high);
                    664:
                    665: extern struct newsmips_bus_dma_tag newsmips_default_bus_dma_tag;
                    666: #endif /* _NEWSMIPS_BUS_DMA_PRIVATE */
                    667:
                    668: #endif /* _NEWSMIPS_BUS_H_ */

CVSweb <webmaster@jp.NetBSD.org>