1 /* $NetBSD: bus_funcs.h,v 1.1 2011/07/19 15:31:44 dyoung Exp $ */ 2 3 /*- 4 * Copyright (c) 1997, 1998, 2000, 2001, 2002 The NetBSD Foundation, Inc. 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 * 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 /* 34 * Copyright (c) 1996 Carnegie-Mellon University. 35 * All rights reserved. 36 * 37 * Author: Chris G. Demetriou 38 * 39 * Permission to use, copy, modify and distribute this software and 40 * its documentation is hereby granted, provided that both the copyright 41 * notice and this permission notice appear in all copies of the 42 * software, derivative works or modified versions, and any portions 43 * thereof, and that both notices appear in supporting documentation. 44 * 45 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 46 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 47 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 48 * 49 * Carnegie Mellon requests users of this software to return to 50 * 51 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 52 * School of Computer Science 53 * Carnegie Mellon University 54 * Pittsburgh PA 15213-3890 55 * 56 * any improvements or extensions that they make and grant Carnegie the 57 * rights to redistribute these changes. 58 */ 59 60 #ifndef _HPCSH_BUS_FUNCS_H_ 61 #define _HPCSH_BUS_FUNCS_H_ 62 63 #ifdef _KERNEL 64 65 /* 66 * Create default bus_space tag. 67 */ 68 bus_space_tag_t bus_space_create(bus_space_tag_t, const char *, bus_addr_t, 69 bus_size_t); 70 void bus_space_destroy(bus_space_tag_t); 71 72 #define __hbs_c(a,b) __CONCAT(a,b) 73 #define __hbs_opname(op,size) __hbs_c(__hbs_c(__hbs_c(hbs_,op),_),size) 74 75 #define __hbs_rs(sz, tn, t, h, o) \ 76 (__BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"), \ 77 (*(t)->__hbs_opname(r,sz))((t)->hbs_cookie, h, o)) 78 79 #define __hbs_ws(sz, tn, t, h, o, v) \ 80 do { \ 81 __BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"); \ 82 (*(t)->__hbs_opname(w,sz))((t)->hbs_cookie, h, o, v); \ 83 } while (0) 84 85 #define __hbs_nonsingle(type, sz, tn, t, h, o, a, c) \ 86 do { \ 87 __BUS_SPACE_ADDRESS_SANITY((a), tn, "buffer"); \ 88 __BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"); \ 89 (*(t)->__hbs_opname(type,sz))((t)->hbs_cookie, h, o, a, c); \ 90 } while (0) 91 92 #define __hbs_set(type, sz, tn, t, h, o, v, c) \ 93 do { \ 94 __BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"); \ 95 (*(t)->__hbs_opname(type,sz))((t)->hbs_cookie, h, o, v, c); \ 96 } while (0) 97 98 #define __hbs_copy(sz, tn, t, h1, o1, h2, o2, cnt) \ 99 do { \ 100 __BUS_SPACE_ADDRESS_SANITY((h1) + (o1), tn, "bus addr 1"); \ 101 __BUS_SPACE_ADDRESS_SANITY((h2) + (o2), tn, "bus addr 2"); \ 102 (*(t)->__hbs_opname(c,sz))((t)->hbs_cookie, h1, o1, h2, o2, cnt); \ 103 } while (0) 104 105 /* 106 * Mapping and unmapping operations. 107 */ 108 #define bus_space_map(t, a, s, f, hp) \ 109 (*(t)->hbs_map)((t)->hbs_cookie, (a), (s), (f), (hp)) 110 #define bus_space_unmap(t, h, s) \ 111 (*(t)->hbs_unmap)((t)->hbs_cookie, (h), (s)) 112 #define bus_space_subregion(t, h, o, s, hp) \ 113 (*(t)->hbs_subregion)((t)->hbs_cookie, (h), (o), (s), (hp)) 114 115 /* 116 * Allocation and deallocation operations. 117 */ 118 #define bus_space_alloc(t, rs, re, s, a, b, f, ap, hp) \ 119 (*(t)->hbs_alloc)((t)->hbs_cookie, (rs), (re), (s), (a), (b), \ 120 (f), (ap), (hp)) 121 #define bus_space_free(t, h, s) \ 122 (*(t)->hbs_free)((t)->hbs_cookie, (h), (s)) 123 124 /* 125 * Get kernel virtual address for ranges mapped BUS_SPACE_MAP_LINEAR. 126 */ 127 #define bus_space_vaddr(t, h) \ 128 (*(t)->hbs_vaddr)((t)->hbs_cookie, (h)) 129 130 /* 131 * Bus barrier operations. The hpcsh does not currently require 132 * barriers, but we must provide the flags to MI code. 133 */ 134 #define bus_space_barrier(t, h, o, l, f) \ 135 ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f))) 136 137 /* 138 * Bus read (single) operations. 139 */ 140 #define bus_space_read_1(t, h, o) __hbs_rs(1,uint8_t,(t),(h),(o)) 141 #define bus_space_read_2(t, h, o) __hbs_rs(2,uint16_t,(t),(h),(o)) 142 #define bus_space_read_4(t, h, o) __hbs_rs(4,uint32_t,(t),(h),(o)) 143 #define bus_space_read_8(t, h, o) __hbs_rs(8,uint64_t,(t),(h),(o)) 144 145 146 /* 147 * Bus read multiple operations. 148 */ 149 #define bus_space_read_multi_1(t, h, o, a, c) \ 150 __hbs_nonsingle(rm,1,uint8_t,(t),(h),(o),(a),(c)) 151 #define bus_space_read_multi_2(t, h, o, a, c) \ 152 __hbs_nonsingle(rm,2,uint16_t,(t),(h),(o),(a),(c)) 153 #define bus_space_read_multi_4(t, h, o, a, c) \ 154 __hbs_nonsingle(rm,4,uint32_t,(t),(h),(o),(a),(c)) 155 #define bus_space_read_multi_8(t, h, o, a, c) \ 156 __hbs_nonsingle(rm,8,uint64_t,(t),(h),(o),(a),(c)) 157 158 159 /* 160 * Bus read region operations. 161 */ 162 #define bus_space_read_region_1(t, h, o, a, c) \ 163 __hbs_nonsingle(rr,1,uint8_t,(t),(h),(o),(a),(c)) 164 #define bus_space_read_region_2(t, h, o, a, c) \ 165 __hbs_nonsingle(rr,2,uint16_t,(t),(h),(o),(a),(c)) 166 #define bus_space_read_region_4(t, h, o, a, c) \ 167 __hbs_nonsingle(rr,4,uint32_t,(t),(h),(o),(a),(c)) 168 #define bus_space_read_region_8(t, h, o, a, c) \ 169 __hbs_nonsingle(rr,8,uint64_t,(t),(h),(o),(a),(c)) 170 171 172 /* 173 * Bus write (single) operations. 174 */ 175 #define bus_space_write_1(t, h, o, v) __hbs_ws(1,uint8_t,(t),(h),(o),(v)) 176 #define bus_space_write_2(t, h, o, v) __hbs_ws(2,uint16_t,(t),(h),(o),(v)) 177 #define bus_space_write_4(t, h, o, v) __hbs_ws(4,uint32_t,(t),(h),(o),(v)) 178 #define bus_space_write_8(t, h, o, v) __hbs_ws(8,uint64_t,(t),(h),(o),(v)) 179 180 181 /* 182 * Bus write multiple operations. 183 */ 184 #define bus_space_write_multi_1(t, h, o, a, c) \ 185 __hbs_nonsingle(wm,1,uint8_t,(t),(h),(o),(a),(c)) 186 #define bus_space_write_multi_2(t, h, o, a, c) \ 187 __hbs_nonsingle(wm,2,uint16_t,(t),(h),(o),(a),(c)) 188 #define bus_space_write_multi_4(t, h, o, a, c) \ 189 __hbs_nonsingle(wm,4,uint32_t,(t),(h),(o),(a),(c)) 190 #define bus_space_write_multi_8(t, h, o, a, c) \ 191 __hbs_nonsingle(wm,8,uint64_t,(t),(h),(o),(a),(c)) 192 193 194 /* 195 * Bus write region operations. 196 */ 197 #define bus_space_write_region_1(t, h, o, a, c) \ 198 __hbs_nonsingle(wr,1,uint8_t,(t),(h),(o),(a),(c)) 199 #define bus_space_write_region_2(t, h, o, a, c) \ 200 __hbs_nonsingle(wr,2,uint16_t,(t),(h),(o),(a),(c)) 201 #define bus_space_write_region_4(t, h, o, a, c) \ 202 __hbs_nonsingle(wr,4,uint32_t,(t),(h),(o),(a),(c)) 203 #define bus_space_write_region_8(t, h, o, a, c) \ 204 __hbs_nonsingle(wr,8,uint64_t,(t),(h),(o),(a),(c)) 205 206 207 /* 208 * Set multiple operations. 209 */ 210 #define bus_space_set_multi_1(t, h, o, v, c) \ 211 __hbs_set(sm,1,uint8_t,(t),(h),(o),(v),(c)) 212 #define bus_space_set_multi_2(t, h, o, v, c) \ 213 __hbs_set(sm,2,uint16_t,(t),(h),(o),(v),(c)) 214 #define bus_space_set_multi_4(t, h, o, v, c) \ 215 __hbs_set(sm,4,uint32_t,(t),(h),(o),(v),(c)) 216 #define bus_space_set_multi_8(t, h, o, v, c) \ 217 __hbs_set(sm,8,uint64_t,(t),(h),(o),(v),(c)) 218 219 220 /* 221 * Set region operations. 222 */ 223 #define bus_space_set_region_1(t, h, o, v, c) \ 224 __hbs_set(sr,1,uint8_t,(t),(h),(o),(v),(c)) 225 #define bus_space_set_region_2(t, h, o, v, c) \ 226 __hbs_set(sr,2,uint16_t,(t),(h),(o),(v),(c)) 227 #define bus_space_set_region_4(t, h, o, v, c) \ 228 __hbs_set(sr,4,uint32_t,(t),(h),(o),(v),(c)) 229 #define bus_space_set_region_8(t, h, o, v, c) \ 230 __hbs_set(sr,8,uint64_t,(t),(h),(o),(v),(c)) 231 232 233 /* 234 * Copy region operations. 235 */ 236 #define bus_space_copy_region_1(t, h1, o1, h2, o2, c) \ 237 __hbs_copy(1, uint8_t, (t), (h1), (o1), (h2), (o2), (c)) 238 #define bus_space_copy_region_2(t, h1, o1, h2, o2, c) \ 239 __hbs_copy(2, uint16_t, (t), (h1), (o1), (h2), (o2), (c)) 240 #define bus_space_copy_region_4(t, h1, o1, h2, o2, c) \ 241 __hbs_copy(4, uint32_t, (t), (h1), (o1), (h2), (o2), (c)) 242 #define bus_space_copy_region_8(t, h1, o1, h2, o2, c) \ 243 __hbs_copy(8, uint64_t, (t), (h1), (o1), (h2), (o2), (c)) 244 245 /* 246 * Bus stream operations--defined in terms of non-stream counterparts 247 */ 248 #define __BUS_SPACE_HAS_STREAM_METHODS 1 249 #define bus_space_read_stream_1 bus_space_read_1 250 #define bus_space_read_stream_2 bus_space_read_2 251 #define bus_space_read_stream_4 bus_space_read_4 252 #define bus_space_read_stream_8 bus_space_read_8 253 #define bus_space_read_multi_stream_1 bus_space_read_multi_1 254 #define bus_space_read_multi_stream_2 bus_space_read_multi_2 255 #define bus_space_read_multi_stream_4 bus_space_read_multi_4 256 #define bus_space_read_multi_stream_8 bus_space_read_multi_8 257 #define bus_space_read_region_stream_1 bus_space_read_region_1 258 #define bus_space_read_region_stream_2 bus_space_read_region_2 259 #define bus_space_read_region_stream_4 bus_space_read_region_4 260 #define bus_space_read_region_stream_8 bus_space_read_region_8 261 #define bus_space_write_stream_1 bus_space_write_1 262 #define bus_space_write_stream_2 bus_space_write_2 263 #define bus_space_write_stream_4 bus_space_write_4 264 #define bus_space_write_stream_8 bus_space_write_8 265 #define bus_space_write_multi_stream_1 bus_space_write_multi_1 266 #define bus_space_write_multi_stream_2 bus_space_write_multi_2 267 #define bus_space_write_multi_stream_4 bus_space_write_multi_4 268 #define bus_space_write_multi_stream_8 bus_space_write_multi_8 269 #define bus_space_write_region_stream_1 bus_space_write_region_1 270 #define bus_space_write_region_stream_2 bus_space_write_region_2 271 #define bus_space_write_region_stream_4 bus_space_write_region_4 272 #define bus_space_write_region_stream_8 bus_space_write_region_8 273 274 #endif /* _KERNEL */ 275 276 #define bus_dmamap_create(t, s, n, m, b, f, p) \ 277 (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p)) 278 #define bus_dmamap_destroy(t, p) \ 279 (*(t)->_dmamap_destroy)((t), (p)) 280 #define bus_dmamap_load(t, m, b, s, p, f) \ 281 (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f)) 282 #define bus_dmamap_load_mbuf(t, m, b, f) \ 283 (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f)) 284 #define bus_dmamap_load_uio(t, m, u, f) \ 285 (*(t)->_dmamap_load_uio)((t), (m), (u), (f)) 286 #define bus_dmamap_load_raw(t, m, sg, n, s, f) \ 287 (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f)) 288 #define bus_dmamap_unload(t, p) \ 289 (*(t)->_dmamap_unload)((t), (p)) 290 #define bus_dmamap_sync(t, m, o, l, op) \ 291 (void)((t)->_dmamap_sync ? \ 292 (*(t)->_dmamap_sync)((t), (m), (o), (l), (op)) : (void)0) 293 294 #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \ 295 (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f)) 296 #define bus_dmamem_free(t, sg, n) \ 297 (*(t)->_dmamem_free)((t), (sg), (n)) 298 #define bus_dmamem_map(t, sg, n, s, k, f) \ 299 (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f)) 300 #define bus_dmamem_unmap(t, k, s) \ 301 (*(t)->_dmamem_unmap)((t), (k), (s)) 302 #define bus_dmamem_mmap(t, sg, n, o, p, f) \ 303 (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f)) 304 305 #define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP 306 #define bus_dmatag_destroy(t) 307 308 #ifdef _HPCSH_BUS_DMA_PRIVATE 309 int _bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t, 310 bus_size_t, int, bus_dmamap_t *); 311 void _bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t); 312 int _bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, 313 bus_size_t, struct proc *, int); 314 int _bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, 315 struct mbuf *, int); 316 int _bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, 317 struct uio *, int); 318 int _bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, 319 bus_dma_segment_t *, int, bus_size_t, int); 320 void _bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t); 321 void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t, 322 bus_size_t, int); 323 324 int _bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size, 325 bus_size_t alignment, bus_size_t boundary, 326 bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags); 327 void _bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs, 328 int nsegs); 329 int _bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs, 330 int nsegs, size_t size, void **kvap, int flags); 331 void _bus_dmamem_unmap(bus_dma_tag_t tag, void *kva, 332 size_t size); 333 paddr_t _bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs, 334 int nsegs, off_t off, int prot, int flags); 335 336 int _bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size, 337 bus_size_t alignment, bus_size_t boundary, 338 bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags, 339 vaddr_t low, vaddr_t high); 340 #endif /* _HPCSH_BUS_DMA_PRIVATE */ 341 342 #endif /* _HPCSH_BUS_FUNCS_H_ */ 343