[BACK]Return to bus.h CVS log [TXT][DIR] Up to [local] / sys / arch / alpha / include

Annotation of sys/arch/alpha/include/bus.h, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: bus.h,v 1.24 2006/05/12 20:48:19 brad Exp $   */
                      2: /*     $NetBSD: bus.h,v 1.10 1996/12/02 22:19:32 cgd Exp $     */
                      3:
                      4: /*
                      5:  * Copyright (c) 1996 Carnegie-Mellon University.
                      6:  * All rights reserved.
                      7:  *
                      8:  * Author: Chris G. Demetriou
                      9:  *
                     10:  * Permission to use, copy, modify and distribute this software and
                     11:  * its documentation is hereby granted, provided that both the copyright
                     12:  * notice and this permission notice appear in all copies of the
                     13:  * software, derivative works or modified versions, and any portions
                     14:  * thereof, and that both notices appear in supporting documentation.
                     15:  *
                     16:  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
                     17:  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
                     18:  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
                     19:  *
                     20:  * Carnegie Mellon requests users of this software to return to
                     21:  *
                     22:  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
                     23:  *  School of Computer Science
                     24:  *  Carnegie Mellon University
                     25:  *  Pittsburgh PA 15213-3890
                     26:  *
                     27:  * any improvements or extensions that they make and grant Carnegie the
                     28:  * rights to redistribute these changes.
                     29:  */
                     30:
                     31: #ifndef _ALPHA_BUS_H_
                     32: #define        _ALPHA_BUS_H_
                     33:
                     34: /*
                     35:  * Addresses (in bus space).
                     36:  */
                     37: typedef u_long bus_addr_t;
                     38: typedef u_long bus_size_t;
                     39:
                     40: /*
                     41:  * Access methods for bus space.
                     42:  */
                     43: typedef struct alpha_bus_space *bus_space_tag_t;
                     44: typedef u_long bus_space_handle_t;
                     45:
                     46: struct alpha_bus_space {
                     47:        /* cookie */
                     48:        void            *abs_cookie;
                     49:
                     50:        /* mapping/unmapping */
                     51:        int             (*abs_map)(void *, bus_addr_t, bus_size_t,
                     52:                            int, bus_space_handle_t *);
                     53:        void            (*abs_unmap)(void *, bus_space_handle_t,
                     54:                            bus_size_t);
                     55:        int             (*abs_subregion)(void *, bus_space_handle_t,
                     56:                            bus_size_t, bus_size_t, bus_space_handle_t *);
                     57:
                     58:        /* allocation/deallocation */
                     59:        int             (*abs_alloc)(void *, bus_addr_t, bus_addr_t,
                     60:                            bus_size_t, bus_size_t, bus_size_t, int,
                     61:                            bus_addr_t *, bus_space_handle_t *);
                     62:        void            (*abs_free)(void *, bus_space_handle_t,
                     63:                            bus_size_t);
                     64:
                     65:        /* barrier */
                     66:        void            (*abs_barrier)(void *, bus_space_handle_t,
                     67:                            bus_size_t, bus_size_t, int);
                     68:
                     69:        /* read (single) */
                     70:        u_int8_t        (*abs_r_1)(void *, bus_space_handle_t,
                     71:                            bus_size_t);
                     72:        u_int16_t       (*abs_r_2)(void *, bus_space_handle_t,
                     73:                            bus_size_t);
                     74:        u_int32_t       (*abs_r_4)(void *, bus_space_handle_t,
                     75:                            bus_size_t);
                     76:        u_int64_t       (*abs_r_8)(void *, bus_space_handle_t,
                     77:                            bus_size_t);
                     78:
                     79:        /* read multiple */
                     80:        void            (*abs_rm_1)(void *, bus_space_handle_t,
                     81:                            bus_size_t, u_int8_t *, bus_size_t);
                     82:        void            (*abs_rm_2)(void *, bus_space_handle_t,
                     83:                            bus_size_t, u_int16_t *, bus_size_t);
                     84:        void            (*abs_rm_4)(void *, bus_space_handle_t,
                     85:                            bus_size_t, u_int32_t *, bus_size_t);
                     86:        void            (*abs_rm_8)(void *, bus_space_handle_t,
                     87:                            bus_size_t, u_int64_t *, bus_size_t);
                     88:
                     89:        /* read region */
                     90:        void            (*abs_rr_1)(void *, bus_space_handle_t,
                     91:                            bus_size_t, u_int8_t *, bus_size_t);
                     92:        void            (*abs_rr_2)(void *, bus_space_handle_t,
                     93:                            bus_size_t, u_int16_t *, bus_size_t);
                     94:        void            (*abs_rr_4)(void *, bus_space_handle_t,
                     95:                            bus_size_t, u_int32_t *, bus_size_t);
                     96:        void            (*abs_rr_8)(void *, bus_space_handle_t,
                     97:                            bus_size_t, u_int64_t *, bus_size_t);
                     98:
                     99:        /* write (single) */
                    100:        void            (*abs_w_1)(void *, bus_space_handle_t,
                    101:                            bus_size_t, u_int8_t);
                    102:        void            (*abs_w_2)(void *, bus_space_handle_t,
                    103:                            bus_size_t, u_int16_t);
                    104:        void            (*abs_w_4)(void *, bus_space_handle_t,
                    105:                            bus_size_t, u_int32_t);
                    106:        void            (*abs_w_8)(void *, bus_space_handle_t,
                    107:                            bus_size_t, u_int64_t);
                    108:
                    109:        /* write multiple */
                    110:        void            (*abs_wm_1)(void *, bus_space_handle_t,
                    111:                            bus_size_t, const u_int8_t *, bus_size_t);
                    112:        void            (*abs_wm_2)(void *, bus_space_handle_t,
                    113:                            bus_size_t, const u_int16_t *, bus_size_t);
                    114:        void            (*abs_wm_4)(void *, bus_space_handle_t,
                    115:                            bus_size_t, const u_int32_t *, bus_size_t);
                    116:        void            (*abs_wm_8)(void *, bus_space_handle_t,
                    117:                            bus_size_t, const u_int64_t *, bus_size_t);
                    118:
                    119:        /* write region */
                    120:        void            (*abs_wr_1)(void *, bus_space_handle_t,
                    121:                            bus_size_t, const u_int8_t *, bus_size_t);
                    122:        void            (*abs_wr_2)(void *, bus_space_handle_t,
                    123:                            bus_size_t, const u_int16_t *, bus_size_t);
                    124:        void            (*abs_wr_4)(void *, bus_space_handle_t,
                    125:                            bus_size_t, const u_int32_t *, bus_size_t);
                    126:        void            (*abs_wr_8)(void *, bus_space_handle_t,
                    127:                            bus_size_t, const u_int64_t *, bus_size_t);
                    128:
                    129:        /* set multiple */
                    130:        void            (*abs_sm_1)(void *, bus_space_handle_t,
                    131:                            bus_size_t, u_int8_t, bus_size_t);
                    132:        void            (*abs_sm_2)(void *, bus_space_handle_t,
                    133:                            bus_size_t, u_int16_t, bus_size_t);
                    134:        void            (*abs_sm_4)(void *, bus_space_handle_t,
                    135:                            bus_size_t, u_int32_t, bus_size_t);
                    136:        void            (*abs_sm_8)(void *, bus_space_handle_t,
                    137:                            bus_size_t, u_int64_t, bus_size_t);
                    138:
                    139:        /* set region */
                    140:        void            (*abs_sr_1)(void *, bus_space_handle_t,
                    141:                            bus_size_t, u_int8_t, bus_size_t);
                    142:        void            (*abs_sr_2)(void *, bus_space_handle_t,
                    143:                            bus_size_t, u_int16_t, bus_size_t);
                    144:        void            (*abs_sr_4)(void *, bus_space_handle_t,
                    145:                            bus_size_t, u_int32_t, bus_size_t);
                    146:        void            (*abs_sr_8)(void *, bus_space_handle_t,
                    147:                            bus_size_t, u_int64_t, bus_size_t);
                    148:
                    149:        /* copy */
                    150:        void            (*abs_c_1)(void *, bus_space_handle_t, bus_size_t,
                    151:                            bus_space_handle_t, bus_size_t, bus_size_t);
                    152:        void            (*abs_c_2)(void *, bus_space_handle_t, bus_size_t,
                    153:                            bus_space_handle_t, bus_size_t, bus_size_t);
                    154:        void            (*abs_c_4)(void *, bus_space_handle_t, bus_size_t,
                    155:                            bus_space_handle_t, bus_size_t, bus_size_t);
                    156:        void            (*abs_c_8)(void *, bus_space_handle_t, bus_size_t,
                    157:                            bus_space_handle_t, bus_size_t, bus_size_t);
                    158:
                    159:        /* OpenBSD extensions follows */
                    160:
                    161:        /* read multiple raw */
                    162:        void            (*abs_rrm_2)(void *, bus_space_handle_t,
                    163:                            bus_size_t, u_int8_t *, bus_size_t);
                    164:        void            (*abs_rrm_4)(void *, bus_space_handle_t,
                    165:                            bus_size_t, u_int8_t *, bus_size_t);
                    166:        void            (*abs_rrm_8)(void *, bus_space_handle_t,
                    167:                            bus_size_t, u_int8_t *, bus_size_t);
                    168:
                    169:        /* write multiple raw */
                    170:        void            (*abs_wrm_2)(void *, bus_space_handle_t,
                    171:                            bus_size_t, const u_int8_t *, bus_size_t);
                    172:        void            (*abs_wrm_4)(void *, bus_space_handle_t,
                    173:                            bus_size_t, const u_int8_t *, bus_size_t);
                    174:        void            (*abs_wrm_8)(void *, bus_space_handle_t,
                    175:                            bus_size_t, const u_int8_t *, bus_size_t);
                    176: };
                    177:
                    178:
                    179: /*
                    180:  * Utility macros; INTERNAL USE ONLY.
                    181:  */
                    182: #define        __abs_c(a,b)            __CONCAT(a,b)
                    183: #define        __abs_opname(op,size)   __abs_c(__abs_c(__abs_c(abs_,op),_),size)
                    184:
                    185: #define        __abs_rs(sz, t, h, o)                                           \
                    186:        (*(t)->__abs_opname(r,sz))((t)->abs_cookie, h, o)
                    187: #define        __abs_ws(sz, t, h, o, v)                                        \
                    188:        (*(t)->__abs_opname(w,sz))((t)->abs_cookie, h, o, v)
                    189: #define        __abs_nonsingle(type, sz, t, h, o, a, c)                        \
                    190:        (*(t)->__abs_opname(type,sz))((t)->abs_cookie, h, o, a, c)
                    191: #ifndef DEBUG
                    192: #define        __abs_aligned_nonsingle(type, sz, t, h, o, a, c)                \
                    193:        __abs_nonsingle(type, sz, (t), (h), (o), (a), (c))
                    194:
                    195: #else
                    196: #define        __abs_aligned_nonsingle(type, sz, t, h, o, a, c)                \
                    197:     do {                                                               \
                    198:        if (((unsigned long)a & (sz - 1)) != 0)                         \
                    199:                panic("bus non-single %d-byte unaligned (to %p) at %s:%d", \
                    200:                    sz, a, __FILE__, __LINE__);                         \
                    201:        (*(t)->__abs_opname(type,sz))((t)->abs_cookie, h, o, a, c);     \
                    202:     } while (0)
                    203: #endif
                    204: #define        __abs_set(type, sz, t, h, o, v, c)                              \
                    205:        (*(t)->__abs_opname(type,sz))((t)->abs_cookie, h, o, v, c)
                    206: #define        __abs_copy(sz, t, h1, o1, h2, o2, cnt)                  \
                    207:        (*(t)->__abs_opname(c,sz))((t)->abs_cookie, h1, o1, h2, o2, cnt)
                    208:
                    209: /*
                    210:  * Mapping and unmapping operations.
                    211:  */
                    212: #define        bus_space_map(t, a, s, c, hp)                                   \
                    213:        (*(t)->abs_map)((t)->abs_cookie, (a), (s), (c), (hp))
                    214: #define alpha_bus_space_map_noacct bus_space_map
                    215: #define        bus_space_unmap(t, h, s)                                        \
                    216:        (*(t)->abs_unmap)((t)->abs_cookie, (h), (s))
                    217: #define alpha_bus_space_unmap_noacct bus_space_unmap
                    218: #define        bus_space_subregion(t, h, o, s, hp)                             \
                    219:        (*(t)->abs_subregion)((t)->abs_cookie, (h), (o), (s), (hp))
                    220:
                    221:
                    222: /*
                    223:  * Allocation and deallocation operations.
                    224:  */
                    225: #define        bus_space_alloc(t, rs, re, s, a, b, c, ap, hp)                  \
                    226:        (*(t)->abs_alloc)((t)->abs_cookie, (rs), (re), (s), (a), (b),   \
                    227:            (c), (ap), (hp))
                    228: #define        bus_space_free(t, h, s)                                         \
                    229:        (*(t)->abs_free)((t)->abs_cookie, (h), (s))
                    230:
                    231:
                    232: /*
                    233:  * Bus barrier operations.
                    234:  */
                    235: #define        bus_space_barrier(t, h, o, l, f)                                \
                    236:        (*(t)->abs_barrier)((t)->abs_cookie, (h), (o), (l), (f))
                    237:
                    238: #define        BUS_BARRIER_READ        0x01
                    239: #define        BUS_BARRIER_WRITE       0x02
                    240: #define BUS_SPACE_BARRIER_READ BUS_BARRIER_READ
                    241: #define BUS_SPACE_BARRIER_WRITE        BUS_BARRIER_WRITE
                    242:
                    243:
                    244: /*
                    245:  * Bus read (single) operations.
                    246:  */
                    247: #define        bus_space_read_1(t, h, o)       __abs_rs(1,(t),(h),(o))
                    248: #define        bus_space_read_2(t, h, o)       __abs_rs(2,(t),(h),(o))
                    249: #define        bus_space_read_4(t, h, o)       __abs_rs(4,(t),(h),(o))
                    250: #define        bus_space_read_8(t, h, o)       __abs_rs(8,(t),(h),(o))
                    251:
                    252:
                    253: /*
                    254:  * Bus read multiple operations.
                    255:  */
                    256: #define        bus_space_read_multi_1(t, h, o, a, c)                           \
                    257:        __abs_nonsingle(rm,1,(t),(h),(o),(a),(c))
                    258: #define        bus_space_read_multi_2(t, h, o, a, c)                           \
                    259:        __abs_aligned_nonsingle(rm,2,(t),(h),(o),(a),(c))
                    260: #define        bus_space_read_multi_4(t, h, o, a, c)                           \
                    261:        __abs_aligned_nonsingle(rm,4,(t),(h),(o),(a),(c))
                    262: #define        bus_space_read_multi_8(t, h, o, a, c)                           \
                    263:        __abs_aligned_nonsingle(rm,8,(t),(h),(o),(a),(c))
                    264:
                    265:
                    266: /*
                    267:  *     void bus_space_read_raw_multi_N(bus_space_tag_t tag,
                    268:  *         bus_space_handle_t bsh, bus_size_t offset,
                    269:  *         u_int8_t *addr, size_t count);
                    270:  *
                    271:  * Read `count' bytes in 2, 4 or 8 byte wide quantities from bus space
                    272:  * described by tag/handle/offset and copy into buffer provided.  The buffer
                    273:  * must have proper alignment for the N byte wide entities.  Furthermore
                    274:  * possible byte-swapping should be done by these functions.
                    275:  */
                    276:
                    277: #define        bus_space_read_raw_multi_2(t, h, o, a, c)                       \
                    278:        __abs_nonsingle(rrm,2,(t),(h),(o),(a),(c))
                    279: #define        bus_space_read_raw_multi_4(t, h, o, a, c)                       \
                    280:        __abs_nonsingle(rrm,4,(t),(h),(o),(a),(c))
                    281: #define        bus_space_read_raw_multi_8(t, h, o, a, c)                       \
                    282:        __abs_nonsingle(rrm,8,(t),(h),(o),(a),(c))
                    283:
                    284: /*
                    285:  * Bus read region operations.
                    286:  */
                    287: #define        bus_space_read_region_1(t, h, o, a, c)                          \
                    288:        __abs_nonsingle(rr,1,(t),(h),(o),(a),(c))
                    289: #define        bus_space_read_region_2(t, h, o, a, c)                          \
                    290:        __abs_aligned_nonsingle(rr,2,(t),(h),(o),(a),(c))
                    291: #define        bus_space_read_region_4(t, h, o, a, c)                          \
                    292:        __abs_aligned_nonsingle(rr,4,(t),(h),(o),(a),(c))
                    293: #define        bus_space_read_region_8(t, h, o, a, c)                          \
                    294:        __abs_aligned_nonsingle(rr,8,(t),(h),(o),(a),(c))
                    295:
                    296:
                    297: /*
                    298:  *     void bus_space_read_raw_region_N(bus_space_tag_t tag,
                    299:  *         bus_space_handle_t bsh, bus_size_t offset,
                    300:  *         u_int8_t *addr, size_t count);
                    301:  *
                    302:  * Read `count' bytes in 2, 4 or 8 byte wide quantities from bus space
                    303:  * described by tag/handle and starting at `offset' from the
                    304:  * buffer provided.  The buffer must have proper alignment for the N byte
                    305:  * wide entities.  Furthermore possible byte-swapping should be done by
                    306:  * these functions.
                    307:  */
                    308:
                    309: #define bus_space_read_raw_region_2(t, h, o, a, c)                     \
                    310:     bus_space_read_region_2((t), (h), (o), (u_int16_t *)(a), (c) >> 1)
                    311: #define bus_space_read_raw_region_4(t, h, o, a, c)                     \
                    312:     bus_space_read_region_4((t), (h), (o), (u_int32_t *)(a), (c) >> 2)
                    313:
                    314: /*
                    315:  * Bus write (single) operations.
                    316:  */
                    317: #define        bus_space_write_1(t, h, o, v)   __abs_ws(1,(t),(h),(o),(v))
                    318: #define        bus_space_write_2(t, h, o, v)   __abs_ws(2,(t),(h),(o),(v))
                    319: #define        bus_space_write_4(t, h, o, v)   __abs_ws(4,(t),(h),(o),(v))
                    320: #define        bus_space_write_8(t, h, o, v)   __abs_ws(8,(t),(h),(o),(v))
                    321:
                    322:
                    323: /*
                    324:  * Bus write multiple operations.
                    325:  */
                    326: #define        bus_space_write_multi_1(t, h, o, a, c)                          \
                    327:        __abs_nonsingle(wm,1,(t),(h),(o),(a),(c))
                    328: #define        bus_space_write_multi_2(t, h, o, a, c)                          \
                    329:        __abs_aligned_nonsingle(wm,2,(t),(h),(o),(a),(c))
                    330: #define        bus_space_write_multi_4(t, h, o, a, c)                          \
                    331:        __abs_aligned_nonsingle(wm,4,(t),(h),(o),(a),(c))
                    332: #define        bus_space_write_multi_8(t, h, o, a, c)                          \
                    333:        __abs_aligned_nonsingle(wm,8,(t),(h),(o),(a),(c))
                    334:
                    335: /*
                    336:  *     void bus_space_write_raw_multi_N(bus_space_tag_t tag,
                    337:  *         bus_space_handle_t bsh, bus_size_t offset,
                    338:  *         u_int8_t *addr, size_t count);
                    339:  *
                    340:  * Write `count' bytes in 2, 4 or 8 byte wide quantities from the buffer
                    341:  * provided to bus space described by tag/handle/offset.  The buffer
                    342:  * must have proper alignment for the N byte wide entities.  Furthermore
                    343:  * possible byte-swapping should be done by these functions.
                    344:  */
                    345:
                    346: #define        bus_space_write_raw_multi_2(t, h, o, a, c)                      \
                    347:        __abs_nonsingle(wrm,2,(t),(h),(o),(a),(c))
                    348: #define        bus_space_write_raw_multi_4(t, h, o, a, c)                      \
                    349:        __abs_nonsingle(wrm,4,(t),(h),(o),(a),(c))
                    350: #define        bus_space_write_raw_multi_8(t, h, o, a, c)                      \
                    351:        __abs_nonsingle(wrm,8,(t),(h),(o),(a),(c))
                    352:
                    353: /*
                    354:  * Bus write region operations.
                    355:  */
                    356: #define        bus_space_write_region_1(t, h, o, a, c)                         \
                    357:        __abs_nonsingle(wr,1,(t),(h),(o),(a),(c))
                    358: #define        bus_space_write_region_2(t, h, o, a, c)                         \
                    359:        __abs_aligned_nonsingle(wr,2,(t),(h),(o),(a),(c))
                    360: #define        bus_space_write_region_4(t, h, o, a, c)                         \
                    361:        __abs_aligned_nonsingle(wr,4,(t),(h),(o),(a),(c))
                    362: #define        bus_space_write_region_8(t, h, o, a, c)                         \
                    363:        __abs_aligned_nonsingle(wr,8,(t),(h),(o),(a),(c))
                    364:
                    365:
                    366: /*
                    367:  *     void bus_space_write_raw_region_N(bus_space_tag_t tag,
                    368:  *         bus_space_handle_t bsh, bus_size_t offset,
                    369:  *         const u_int8_t *addr, size_t count);
                    370:  *
                    371:  * Write `count' bytes in 2, 4 or 8 byte wide quantities to bus space
                    372:  * described by tag/handle and starting at `offset' from the
                    373:  * buffer provided.  The buffer must have proper alignment for the N byte
                    374:  * wide entities.  Furthermore possible byte-swapping should be done by
                    375:  * these functions.
                    376:  */
                    377:
                    378: #define bus_space_write_raw_region_2(t, h, o, a, c)                    \
                    379:     bus_space_write_region_2((t), (h), (o), (const u_int16_t *)(a), (c) >> 1)
                    380: #define bus_space_write_raw_region_4(t, h, o, a, c)                    \
                    381:     bus_space_write_region_4((t), (h), (o), (const u_int32_t *)(a), (c) >> 2)
                    382:
                    383: /*
                    384:  * Set multiple operations.
                    385:  */
                    386: #define        bus_space_set_multi_1(t, h, o, v, c)                            \
                    387:        __abs_set(sm,1,(t),(h),(o),(v),(c))
                    388: #define        bus_space_set_multi_2(t, h, o, v, c)                            \
                    389:        __abs_set(sm,2,(t),(h),(o),(v),(c))
                    390: #define        bus_space_set_multi_4(t, h, o, v, c)                            \
                    391:        __abs_set(sm,4,(t),(h),(o),(v),(c))
                    392: #define        bus_space_set_multi_8(t, h, o, v, c)                            \
                    393:        __abs_set(sm,8,(t),(h),(o),(v),(c))
                    394:
                    395:
                    396: /*
                    397:  * Set region operations.
                    398:  */
                    399: #define        bus_space_set_region_1(t, h, o, v, c)                           \
                    400:        __abs_set(sr,1,(t),(h),(o),(v),(c))
                    401: #define        bus_space_set_region_2(t, h, o, v, c)                           \
                    402:        __abs_set(sr,2,(t),(h),(o),(v),(c))
                    403: #define        bus_space_set_region_4(t, h, o, v, c)                           \
                    404:        __abs_set(sr,4,(t),(h),(o),(v),(c))
                    405: #define        bus_space_set_region_8(t, h, o, v, c)                           \
                    406:        __abs_set(sr,8,(t),(h),(o),(v),(c))
                    407:
                    408:
                    409: /*
                    410:  * Copy operations.
                    411:  */
                    412: #define        bus_space_copy_1(t, h1, o1, h2, o2, c)                          \
                    413:        __abs_copy(1, t, h1, o1, h2, o2, c)
                    414: #define        bus_space_copy_2(t, h1, o1, h2, o2, c)                          \
                    415:        __abs_copy(2, t, h1, o1, h2, o2, c)
                    416: #define        bus_space_copy_4(t, h1, o1, h2, o2, c)                          \
                    417:        __abs_copy(4, t, h1, o1, h2, o2, c)
                    418: #define        bus_space_copy_8(t, h1, o1, h2, o2, c)                          \
                    419:        __abs_copy(8, t, h1, o1, h2, o2, c)
                    420:
                    421: /*
                    422:  * Bus DMA methods.
                    423:  */
                    424:
                    425: /*
                    426:  * Flags used in various bus DMA methods.
                    427:  */
                    428: #define        BUS_DMA_WAITOK          0x000   /* safe to sleep (pseudo-flag) */
                    429: #define        BUS_DMA_NOWAIT          0x001   /* not safe to sleep */
                    430: #define        BUS_DMA_ALLOCNOW        0x002   /* perform resource allocation now */
                    431: #define        BUS_DMA_COHERENT        0x004   /* hint: map memory DMA coherent */
                    432: #define        BUS_DMA_BUS1            0x010   /* placeholders for bus functions... */
                    433: #define        BUS_DMA_BUS2            0x020
                    434: #define        BUS_DMA_BUS3            0x040
                    435: #define        BUS_DMA_24BIT           0x080   /* isadma map */
                    436: #define        BUS_DMA_STREAMING       0x100   /* hint: sequential, unidirectional */
                    437: #define        BUS_DMA_READ            0x200   /* mapping is device -> memory only */
                    438: #define        BUS_DMA_WRITE           0x400   /* mapping is memory -> device only */
                    439:
                    440: /*
                    441:  * Private flags stored in the DMA map.
                    442:  */
                    443: #define        DMAMAP_NO_COALESCE      0x40000000      /* don't coalesce adjacent
                    444:                                                   segments */
                    445:
                    446: /* Forwards needed by prototypes below. */
                    447: struct mbuf;
                    448: struct uio;
                    449: struct alpha_sgmap;
                    450:
                    451: /*
                    452:  * Operations performed by bus_dmamap_sync().
                    453:  */
                    454: #define BUS_DMASYNC_PREREAD    0x01
                    455: #define BUS_DMASYNC_POSTREAD   0x02
                    456: #define BUS_DMASYNC_PREWRITE   0x04
                    457: #define BUS_DMASYNC_POSTWRITE  0x08
                    458:
                    459: /*
                    460:  *     alpha_bus_t
                    461:  *
                    462:  *     Busses supported by NetBSD/alpha, used by internal
                    463:  *     utility functions.  NOT TO BE USED BY MACHINE-INDEPENDENT
                    464:  *     CODE!
                    465:  */
                    466: typedef enum {
                    467:        ALPHA_BUS_TURBOCHANNEL,
                    468:        ALPHA_BUS_PCI,
                    469:        ALPHA_BUS_EISA,
                    470:        ALPHA_BUS_ISA,
                    471:        ALPHA_BUS_TLSB,
                    472: } alpha_bus_t;
                    473:
                    474: typedef struct alpha_bus_dma_tag       *bus_dma_tag_t;
                    475: typedef struct alpha_bus_dmamap                *bus_dmamap_t;
                    476:
                    477: /*
                    478:  *     bus_dma_segment_t
                    479:  *
                    480:  *     Describes a single contiguous DMA transaction.  Values
                    481:  *     are suitable for programming into DMA registers.
                    482:  */
                    483: struct alpha_bus_dma_segment {
                    484:        bus_addr_t      ds_addr;        /* DMA address */
                    485:        bus_size_t      ds_len;         /* length of transfer */
                    486: };
                    487: typedef struct alpha_bus_dma_segment   bus_dma_segment_t;
                    488:
                    489: /*
                    490:  *     bus_dma_tag_t
                    491:  *
                    492:  *     A machine-dependent opaque type describing the implementation of
                    493:  *     DMA for a given bus.
                    494:  */
                    495: struct alpha_bus_dma_tag {
                    496:        void    *_cookie;               /* cookie used in the guts */
                    497:        bus_addr_t _wbase;              /* DMA window base */
                    498:
                    499:        /*
                    500:         * The following two members are used to chain DMA windows
                    501:         * together.  If, during the course of a map load, the
                    502:         * resulting physical memory address is too large to
                    503:         * be addressed by the window, the next window will be
                    504:         * attempted.  These would be chained together like so:
                    505:         *
                    506:         *      direct -> sgmap -> NULL
                    507:         *  or
                    508:         *      sgmap -> NULL
                    509:         *  or
                    510:         *      direct -> NULL
                    511:         *
                    512:         * If the window size is 0, it will not be checked (e.g.
                    513:         * TurboChannel DMA).
                    514:         */
                    515:        bus_size_t _wsize;
                    516:        struct alpha_bus_dma_tag *_next_window;
                    517:
                    518:        /*
                    519:         * Some chipsets have a built-in boundary constraint, independent
                    520:         * of what the device requests.  This allows that boundary to
                    521:         * be specified.  If the device has a more restrictive constraint,
                    522:         * the map will use that, otherwise this boundary will be used.
                    523:         * This value is ignored if 0.
                    524:         */
                    525:        bus_size_t _boundary;
                    526:
                    527:        /*
                    528:         * A chipset may have more than one SGMAP window, so SGMAP
                    529:         * windows also get a pointer to their SGMAP state.
                    530:         */
                    531:        struct alpha_sgmap *_sgmap;
                    532:
                    533:        /*
                    534:         * The SGMAP MMU implements a prefetch FIFO to keep data
                    535:         * moving down the pipe, when doing host->bus DMA writes.
                    536:         * The threshold (distance until the next page) used to
                    537:         * trigger the prefetch is differnet on different chipsets,
                    538:         * and we need to know what it is in order to know whether
                    539:         * or not to allocate a spill page.
                    540:         */
                    541:        bus_size_t _pfthresh;
                    542:
                    543:        /*
                    544:         * Internal-use only utility methods.  NOT TO BE USED BY
                    545:         * MACHINE-INDEPENDENT CODE!
                    546:         */
                    547:        bus_dma_tag_t (*_get_tag)(bus_dma_tag_t, alpha_bus_t);
                    548:
                    549:        /*
                    550:         * DMA mapping methods.
                    551:         */
                    552:        int     (*_dmamap_create)(bus_dma_tag_t, bus_size_t, int,
                    553:                    bus_size_t, bus_size_t, int, bus_dmamap_t *);
                    554:        void    (*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t);
                    555:        int     (*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *,
                    556:                    bus_size_t, struct proc *, int);
                    557:        int     (*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t,
                    558:                    struct mbuf *, int);
                    559:        int     (*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t,
                    560:                    struct uio *, int);
                    561:        int     (*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t,
                    562:                    bus_dma_segment_t *, int, bus_size_t, int);
                    563:        void    (*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t);
                    564:        void    (*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t,
                    565:                    bus_addr_t, bus_size_t, int);
                    566:
                    567:        /*
                    568:         * DMA memory utility functions.
                    569:         */
                    570:        int     (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t,
                    571:                    bus_size_t, bus_dma_segment_t *, int, int *, int);
                    572:        void    (*_dmamem_free)(bus_dma_tag_t,
                    573:                    bus_dma_segment_t *, int);
                    574:        int     (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *,
                    575:                    int, size_t, caddr_t *, int);
                    576:        void    (*_dmamem_unmap)(bus_dma_tag_t, caddr_t, size_t);
                    577:        paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *,
                    578:                    int, off_t, int, int);
                    579: };
                    580:
                    581: #define        alphabus_dma_get_tag(t, b)                              \
                    582:        (*(t)->_get_tag)(t, b)
                    583:
                    584: #define        bus_dmamap_create(t, s, n, m, b, f, p)                  \
                    585:        (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
                    586: #define        bus_dmamap_destroy(t, p)                                \
                    587:        (*(t)->_dmamap_destroy)((t), (p))
                    588: #define        bus_dmamap_load(t, m, b, s, p, f)                       \
                    589:        (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
                    590: #define        bus_dmamap_load_mbuf(t, m, b, f)                        \
                    591:        (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
                    592: #define        bus_dmamap_load_uio(t, m, u, f)                         \
                    593:        (*(t)->_dmamap_load_uio)((t), (m), (u), (f))
                    594: #define        bus_dmamap_load_raw(t, m, sg, n, s, f)                  \
                    595:        (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
                    596: #define        bus_dmamap_unload(t, p)                                 \
                    597:        (void)(t),                                              \
                    598:        (*(p)->_dm_window->_dmamap_unload)((p)->_dm_window, (p))
                    599: #define        bus_dmamap_sync(t, p, a, s, op)                         \
                    600:        (void)(t),                                              \
                    601:        (*(p)->_dm_window->_dmamap_sync)((p)->_dm_window, (p), (a), (s), (op))
                    602: #define        bus_dmamem_alloc(t, s, a, b, sg, n, r, f)               \
                    603:        (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
                    604: #define        bus_dmamem_free(t, sg, n)                               \
                    605:        (*(t)->_dmamem_free)((t), (sg), (n))
                    606: #define        bus_dmamem_map(t, sg, n, s, k, f)                       \
                    607:        (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
                    608: #define        bus_dmamem_unmap(t, k, s)                               \
                    609:        (*(t)->_dmamem_unmap)((t), (k), (s))
                    610: #define        bus_dmamem_mmap(t, sg, n, o, p, f)                      \
                    611:        (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
                    612:
                    613: /*
                    614:  *     bus_dmamap_t
                    615:  *
                    616:  *     Describes a DMA mapping.
                    617:  */
                    618: struct alpha_bus_dmamap {
                    619:        /*
                    620:         * PRIVATE MEMBERS: not for use by machine-independent code.
                    621:         */
                    622:        bus_size_t      _dm_size;       /* largest DMA transfer mappable */
                    623:        int             _dm_segcnt;     /* number of segs this map can map */
                    624:        bus_size_t      _dm_maxsegsz;   /* largest possible segment */
                    625:        bus_size_t      _dm_boundary;   /* don't cross this */
                    626:        int             _dm_flags;      /* misc. flags */
                    627:
                    628:        /*
                    629:         * Private cookie to be used by the DMA back-end.
                    630:         */
                    631:        void            *_dm_cookie;
                    632:
                    633:        /*
                    634:         * The DMA window that we ended up being mapped in.
                    635:         */
                    636:        bus_dma_tag_t   _dm_window;
                    637:
                    638:        /*
                    639:         * PUBLIC MEMBERS: these are used by machine-independent code.
                    640:         */
                    641:        bus_size_t      dm_mapsize;     /* size of the mapping */
                    642:        int             dm_nsegs;       /* # valid segments in mapping */
                    643:        bus_dma_segment_t dm_segs[1];   /* segments; variable length */
                    644: };
                    645:
                    646: #ifdef _ALPHA_BUS_DMA_PRIVATE
                    647: int    _bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t,
                    648:            bus_size_t, int, bus_dmamap_t *);
                    649: void   _bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
                    650:
                    651: int    _bus_dmamap_load_direct(bus_dma_tag_t, bus_dmamap_t,
                    652:            void *, bus_size_t, struct proc *, int);
                    653: int    _bus_dmamap_load_mbuf_direct(bus_dma_tag_t,
                    654:            bus_dmamap_t, struct mbuf *, int);
                    655: int    _bus_dmamap_load_uio_direct(bus_dma_tag_t,
                    656:            bus_dmamap_t, struct uio *, int);
                    657: int    _bus_dmamap_load_raw_direct(bus_dma_tag_t,
                    658:            bus_dmamap_t, bus_dma_segment_t *, int, bus_size_t, int);
                    659:
                    660: void   _bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
                    661: void   _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
                    662:            bus_size_t, int);
                    663:
                    664: int    _bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size,
                    665:            bus_size_t alignment, bus_size_t boundary,
                    666:            bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags);
                    667: int    _bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size,
                    668:            bus_size_t alignment, bus_size_t boundary,
                    669:            bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
                    670:            paddr_t low, paddr_t high);
                    671: void   _bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs,
                    672:            int nsegs);
                    673: int    _bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs,
                    674:            int nsegs, size_t size, caddr_t *kvap, int flags);
                    675: void   _bus_dmamem_unmap(bus_dma_tag_t tag, caddr_t kva,
                    676:            size_t size);
                    677: paddr_t        _bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs,
                    678:            int nsegs, off_t off, int prot, int flags);
                    679: #endif /* _ALPHA_BUS_DMA_PRIVATE */
                    680:
                    681: #endif /* _ALPHA_BUS_H_ */

CVSweb