Merge branch 'vendor/DIFFUTILS'
[dragonfly.git] / share / man / man9 / bus_space.9
1 .\" $NetBSD: bus_space.9,v 1.9 1999/03/06 22:09:29 mycroft Exp $
2 .\"
3 .\" Copyright (c) 2005 M. Warner Losh.  All Rights Reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
13 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
14 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
15 .\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
16 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
17 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
18 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
19 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
20 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22 .\" POSSIBILITY OF SUCH DAMAGE.
23 .\"
24 .\"
25 .\" Copyright (c) 1997 The NetBSD Foundation, Inc.
26 .\" All rights reserved.
27 .\"
28 .\" This code is derived from software contributed to The NetBSD Foundation
29 .\" by Christopher G. Demetriou.
30 .\"
31 .\" Redistribution and use in source and binary forms, with or without
32 .\" modification, are permitted provided that the following conditions
33 .\" are met:
34 .\" 1. Redistributions of source code must retain the above copyright
35 .\"    notice, this list of conditions and the following disclaimer.
36 .\" 2. Redistributions in binary form must reproduce the above copyright
37 .\"    notice, this list of conditions and the following disclaimer in the
38 .\"    documentation and/or other materials provided with the distribution.
39 .\" 3. All advertising materials mentioning features or use of this software
40 .\"    must display the following acknowledgment:
41 .\"     This product includes software developed by the NetBSD
42 .\"     Foundation, Inc. and its contributors.
43 .\" 4. Neither the name of The NetBSD Foundation nor the names of its
44 .\"    contributors may be used to endorse or promote products derived
45 .\"    from this software without specific prior written permission.
46 .\"
47 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
48 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
49 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
50 .\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
51 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
52 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
53 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
54 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
55 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
56 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
57 .\" POSSIBILITY OF SUCH DAMAGE.
58 .\"
59 .\" $FreeBSD: src/share/man/man9/bus_space.9,v 1.5 2008/03/07 17:02:34 rwatson Exp $
60 .\"
61 .Dd March 16, 2008
62 .Dt BUS_SPACE 9
63 .Os
64 .Sh NAME
65 .Nm bus_space ,
66 .Nm bus_space_barrier ,
67 .Nm bus_space_copy_region_1 ,
68 .Nm bus_space_copy_region_2 ,
69 .Nm bus_space_copy_region_4 ,
70 .Nm bus_space_copy_region_stream_1 ,
71 .Nm bus_space_copy_region_stream_2 ,
72 .Nm bus_space_copy_region_stream_4 ,
73 .Nm bus_space_free ,
74 .Nm bus_space_map ,
75 .Nm bus_space_read_1 ,
76 .Nm bus_space_read_2 ,
77 .Nm bus_space_read_4 ,
78 .Nm bus_space_read_multi_1 ,
79 .Nm bus_space_read_multi_2 ,
80 .Nm bus_space_read_multi_4 ,
81 .Nm bus_space_read_multi_stream_1 ,
82 .Nm bus_space_read_multi_stream_2 ,
83 .Nm bus_space_read_multi_stream_4 ,
84 .Nm bus_space_read_region_1 ,
85 .Nm bus_space_read_region_2 ,
86 .Nm bus_space_read_region_4 ,
87 .Nm bus_space_read_region_stream_1 ,
88 .Nm bus_space_read_region_stream_2 ,
89 .Nm bus_space_read_region_stream_4 ,
90 .Nm bus_space_read_stream_1 ,
91 .Nm bus_space_read_stream_2 ,
92 .Nm bus_space_read_stream_4 ,
93 .Nm bus_space_set_multi_1 ,
94 .Nm bus_space_set_multi_2 ,
95 .Nm bus_space_set_multi_4 ,
96 .Nm bus_space_set_multi_stream_1 ,
97 .Nm bus_space_set_multi_stream_2 ,
98 .Nm bus_space_set_multi_stream_4 ,
99 .Nm bus_space_set_region_1 ,
100 .Nm bus_space_set_region_2 ,
101 .Nm bus_space_set_region_4 ,
102 .Nm bus_space_set_region_stream_1 ,
103 .Nm bus_space_set_region_stream_2 ,
104 .Nm bus_space_set_region_stream_4 ,
105 .Nm bus_space_subregion ,
106 .Nm bus_space_unmap ,
107 .Nm bus_space_write_1 ,
108 .Nm bus_space_write_2 ,
109 .Nm bus_space_write_4 ,
110 .Nm bus_space_write_multi_1 ,
111 .Nm bus_space_write_multi_2 ,
112 .Nm bus_space_write_multi_4 ,
113 .Nm bus_space_write_multi_stream_1 ,
114 .Nm bus_space_write_multi_stream_2 ,
115 .Nm bus_space_write_multi_stream_4 ,
116 .Nm bus_space_write_region_1 ,
117 .Nm bus_space_write_region_2 ,
118 .Nm bus_space_write_region_4 ,
119 .Nm bus_space_write_region_stream_1 ,
120 .Nm bus_space_write_region_stream_2 ,
121 .Nm bus_space_write_region_stream_4 ,
122 .Nm bus_space_write_stream_1 ,
123 .Nm bus_space_write_stream_2 ,
124 .Nm bus_space_write_stream_4
125 .Nd "bus space manipulation functions"
126 .Sh SYNOPSIS
127 .In sys/bus.h
128 .Ft int
129 .Fo bus_space_map
130 .Fa "bus_space_tag_t space" "bus_addr_t address"
131 .Fa "bus_size_t size" "int flags" "bus_space_handle_t *handlep"
132 .Fc
133 .Ft void
134 .Fo bus_space_unmap
135 .Fa "bus_space_tag_t space" "bus_space_handle_t handle" "bus_size_t size"
136 .Fc
137 .Ft int
138 .Fo bus_space_subregion
139 .Fa "bus_space_tag_t space" "bus_space_handle_t handle"
140 .Fa "bus_size_t offset" "bus_size_t size" "bus_space_handle_t *nhandlep"
141 .Fc
142 .Ft int
143 .Fo bus_space_alloc
144 .Fa "bus_space_tag_t space" "bus_addr_t reg_start" "bus_addr_t reg_end"
145 .Fa "bus_size_t size" "bus_size_t alignment" "bus_size_t boundary"
146 .Fa "int flags" "bus_addr_t *addrp" "bus_space_handle_t *handlep"
147 .Fc
148 .Ft void
149 .Fo bus_space_free
150 .Fa "bus_space_tag_t space" "bus_space_handle_t handle" "bus_size_t size"
151 .Fc
152 .Ft u_int8_t
153 .Fo bus_space_read_1
154 .Fa "bus_space_tag_t space" "bus_space_handle_t handle" "bus_size_t offset"
155 .Fc
156 .Ft u_int16_t
157 .Fo bus_space_read_2
158 .Fa "bus_space_tag_t space" "bus_space_handle_t handle" "bus_size_t offset"
159 .Fc
160 .Ft u_int32_t
161 .Fo bus_space_read_4
162 .Fa "bus_space_tag_t space" "bus_space_handle_t handle" "bus_size_t offset"
163 .Fc
164 .Ft u_int8_t
165 .Fo bus_space_read_stream_1
166 .Fa "bus_space_tag_t space" "bus_space_handle_t handle" "bus_size_t offset"
167 .Fc
168 .Ft u_int16_t
169 .Fo bus_space_read_stream_2
170 .Fa "bus_space_tag_t space" "bus_space_handle_t handle" "bus_size_t offset"
171 .Fc
172 .Ft u_int32_t
173 .Fo bus_space_read_stream_4
174 .Fa "bus_space_tag_t space" "bus_space_handle_t handle" "bus_size_t offset"
175 .Fc
176 .Ft void
177 .Fo bus_space_write_1
178 .Fa "bus_space_tag_t space" "bus_space_handle_t handle"
179 .Fa "bus_size_t offset" "u_int8_t value"
180 .Fc
181 .Ft void
182 .Fo bus_space_write_2
183 .Fa "bus_space_tag_t space" "bus_space_handle_t handle"
184 .Fa "bus_size_t offset" "u_int16_t value"
185 .Fc
186 .Ft void
187 .Fo bus_space_write_4
188 .Fa "bus_space_tag_t space" "bus_space_handle_t handle"
189 .Fa "bus_size_t offset" "u_int32_t value"
190 .Fc
191 .Ft void
192 .Fo bus_space_write_stream_1
193 .Fa "bus_space_tag_t space" "bus_space_handle_t handle"
194 .Fa "bus_size_t offset" "u_int8_t value"
195 .Fc
196 .Ft void
197 .Fo bus_space_write_stream_2
198 .Fa "bus_space_tag_t space" "bus_space_handle_t handle"
199 .Fa "bus_size_t offset" "u_int16_t value"
200 .Fc
201 .Ft void
202 .Fo bus_space_write_stream_4
203 .Fa "bus_space_tag_t space" "bus_space_handle_t handle"
204 .Fa "bus_size_t offset" "u_int32_t value"
205 .Fc
206 .Ft void
207 .Fo bus_space_barrier
208 .Fa "bus_space_tag_t space" "bus_space_handle_t handle"
209 .Fa "bus_size_t offset" "bus_size_t length" "int flags"
210 .Fc
211 .Ft void
212 .Fo bus_space_read_region_1
213 .Fa "bus_space_tag_t space"
214 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int8_t *datap"
215 .Fa "bus_size_t count"
216 .Fc
217 .Ft void
218 .Fo bus_space_read_region_2
219 .Fa "bus_space_tag_t space"
220 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int16_t *datap"
221 .Fa "bus_size_t count"
222 .Fc
223 .Ft void
224 .Fo bus_space_read_region_4
225 .Fa "bus_space_tag_t space"
226 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int32_t *datap"
227 .Fa "bus_size_t count"
228 .Fc
229 .Ft void
230 .Fo bus_space_read_region_stream_1
231 .Fa "bus_space_tag_t space"
232 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int8_t *datap"
233 .Fa "bus_size_t count"
234 .Fc
235 .Ft void
236 .Fo bus_space_read_region_stream_2
237 .Fa "bus_space_tag_t space"
238 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int16_t *datap"
239 .Fa "bus_size_t count"
240 .Fc
241 .Ft void
242 .Fo bus_space_read_region_stream_4
243 .Fa "bus_space_tag_t space"
244 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int32_t *datap"
245 .Fa "bus_size_t count"
246 .Fc
247 .Ft void
248 .Fo bus_space_write_region_1
249 .Fa "bus_space_tag_t space"
250 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int8_t *datap"
251 .Fa "bus_size_t count"
252 .Fc
253 .Ft void
254 .Fo bus_space_write_region_2
255 .Fa "bus_space_tag_t space"
256 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int16_t *datap"
257 .Fa "bus_size_t count"
258 .Fc
259 .Ft void
260 .Fo bus_space_write_region_4
261 .Fa "bus_space_tag_t space"
262 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int32_t *datap"
263 .Fa "bus_size_t count"
264 .Fc
265 .Ft void
266 .Fo bus_space_write_region_stream_1
267 .Fa "bus_space_tag_t space"
268 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int8_t *datap"
269 .Fa "bus_size_t count"
270 .Fc
271 .Ft void
272 .Fo bus_space_write_region_stream_2
273 .Fa "bus_space_tag_t space"
274 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int16_t *datap"
275 .Fa "bus_size_t count"
276 .Fc
277 .Ft void
278 .Fo bus_space_write_region_stream_4
279 .Fa "bus_space_tag_t space"
280 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int32_t *datap"
281 .Fa "bus_size_t count"
282 .Fc
283 .Ft void
284 .Fo bus_space_copy_region_1
285 .Fa "bus_space_tag_t space"
286 .Fa "bus_space_handle_t srchandle" "bus_size_t srcoffset"
287 .Fa "bus_space_handle_t dsthandle" "bus_size_t dstoffset" "bus_size_t count"
288 .Fc
289 .Ft void
290 .Fo bus_space_copy_region_2
291 .Fa "bus_space_tag_t space"
292 .Fa "bus_space_handle_t srchandle" "bus_size_t srcoffset"
293 .Fa "bus_space_handle_t dsthandle" "bus_size_t dstoffset" "bus_size_t count"
294 .Fc
295 .Ft void
296 .Fo bus_space_copy_region_4
297 .Fa "bus_space_tag_t space"
298 .Fa "bus_space_handle_t srchandle" "bus_size_t srcoffset"
299 .Fa "bus_space_handle_t dsthandle" "bus_size_t dstoffset" "bus_size_t count"
300 .Fc
301 .Ft void
302 .Fo bus_space_copy_region_stream_1
303 .Fa "bus_space_tag_t space"
304 .Fa "bus_space_handle_t srchandle" "bus_size_t srcoffset"
305 .Fa "bus_space_handle_t dsthandle" "bus_size_t dstoffset" "bus_size_t count"
306 .Fc
307 .Ft void
308 .Fo bus_space_copy_region_stream_2
309 .Fa "bus_space_tag_t space"
310 .Fa "bus_space_handle_t srchandle" "bus_size_t srcoffset"
311 .Fa "bus_space_handle_t dsthandle" "bus_size_t dstoffset" "bus_size_t count"
312 .Fc
313 .Ft void
314 .Fo bus_space_copy_region_stream_4
315 .Fa "bus_space_tag_t space"
316 .Fa "bus_space_handle_t srchandle" "bus_size_t srcoffset"
317 .Fa "bus_space_handle_t dsthandle" "bus_size_t dstoffset" "bus_size_t count"
318 .Fc
319 .Ft void
320 .Fo bus_space_set_region_1
321 .Fa "bus_space_tag_t space"
322 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int8_t value"
323 .Fa "bus_size_t count"
324 .Fc
325 .Ft void
326 .Fo bus_space_set_region_2
327 .Fa "bus_space_tag_t space"
328 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int16_t value"
329 .Fa "bus_size_t count"
330 .Fc
331 .Ft void
332 .Fo bus_space_set_region_4
333 .Fa "bus_space_tag_t space"
334 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int32_t value"
335 .Fa "bus_size_t count"
336 .Fc
337 .Ft void
338 .Fo bus_space_set_region_stream_1
339 .Fa "bus_space_tag_t space"
340 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int8_t value"
341 .Fa "bus_size_t count"
342 .Fc
343 .Ft void
344 .Fo bus_space_set_region_stream_2
345 .Fa "bus_space_tag_t space"
346 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int16_t value"
347 .Fa "bus_size_t count"
348 .Fc
349 .Ft void
350 .Fo bus_space_set_region_stream_4
351 .Fa "bus_space_tag_t space"
352 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int32_t value"
353 .Fa "bus_size_t count"
354 .Fc
355 .Ft void
356 .Fo bus_space_read_multi_1
357 .Fa "bus_space_tag_t space"
358 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int8_t *datap"
359 .Fa "bus_size_t count"
360 .Fc
361 .Ft void
362 .Fo bus_space_read_multi_2
363 .Fa "bus_space_tag_t space"
364 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int16_t *datap"
365 .Fa "bus_size_t count"
366 .Fc
367 .Ft void
368 .Fo bus_space_read_multi_4
369 .Fa "bus_space_tag_t space"
370 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int32_t *datap"
371 .Fa "bus_size_t count"
372 .Fc
373 .Ft void
374 .Fo bus_space_read_multi_stream_1
375 .Fa "bus_space_tag_t space"
376 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int8_t *datap"
377 .Fa "bus_size_t count"
378 .Fc
379 .Ft void
380 .Fo bus_space_read_multi_stream_2
381 .Fa "bus_space_tag_t space"
382 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int16_t *datap"
383 .Fa "bus_size_t count"
384 .Fc
385 .Ft void
386 .Fo bus_space_read_multi_stream_4
387 .Fa "bus_space_tag_t space"
388 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int32_t *datap"
389 .Fa "bus_size_t count"
390 .Fc
391 .Ft void
392 .Fo bus_space_write_multi_1
393 .Fa "bus_space_tag_t space"
394 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int8_t *datap"
395 .Fa "bus_size_t count"
396 .Fc
397 .Ft void
398 .Fo bus_space_write_multi_2
399 .Fa "bus_space_tag_t space"
400 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int16_t *datap"
401 .Fa "bus_size_t count"
402 .Fc
403 .Ft void
404 .Fo bus_space_write_multi_4
405 .Fa "bus_space_tag_t space"
406 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int32_t *datap"
407 .Fa "bus_size_t count"
408 .Fc
409 .Ft void
410 .Fo bus_space_write_multi_stream_1
411 .Fa "bus_space_tag_t space"
412 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int8_t *datap"
413 .Fa "bus_size_t count"
414 .Fc
415 .Ft void
416 .Fo bus_space_write_multi_stream_2
417 .Fa "bus_space_tag_t space"
418 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int16_t *datap"
419 .Fa "bus_size_t count"
420 .Fc
421 .Ft void
422 .Fo bus_space_write_multi_stream_4
423 .Fa "bus_space_tag_t space"
424 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int32_t *datap"
425 .Fa "bus_size_t count"
426 .Fc
427 .Ft void
428 .Fo bus_space_set_multi_1
429 .Fa "bus_space_tag_t space"
430 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int8_t value"
431 .Fa "bus_size_t count"
432 .Fc
433 .Ft void
434 .Fo bus_space_set_multi_2
435 .Fa "bus_space_tag_t space"
436 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int16_t value"
437 .Fa "bus_size_t count"
438 .Fc
439 .Ft void
440 .Fo bus_space_set_multi_4
441 .Fa "bus_space_tag_t space"
442 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int32_t value"
443 .Fa "bus_size_t count"
444 .Fc
445 .Ft void
446 .Fo bus_space_set_multi_stream_1
447 .Fa "bus_space_tag_t space"
448 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int8_t value"
449 .Fa "bus_size_t count"
450 .Fc
451 .Ft void
452 .Fo bus_space_set_multi_stream_2
453 .Fa "bus_space_tag_t space"
454 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int16_t value"
455 .Fa "bus_size_t count"
456 .Fc
457 .Ft void
458 .Fo bus_space_set_multi_stream_4
459 .Fa "bus_space_tag_t space"
460 .Fa "bus_space_handle_t handle" "bus_size_t offset" "u_int32_t value"
461 .Fa "bus_size_t count"
462 .Fc
463 .Sh DESCRIPTION
464 The
465 .Nm
466 functions exist to allow device drivers
467 machine-independent access to bus memory and register areas.
468 All of the
469 functions and types described in this document can be used by including
470 the
471 .In sys/bus.h
472 header file.
473 .Pp
474 Many common devices are used on multiple architectures, but are accessed
475 differently on each because of architectural constraints.
476 For instance, a device which is mapped in one system's I/O space may be
477 mapped in memory space on a second system.
478 On a third system, architectural
479 limitations might change the way registers need to be accessed (e.g.\&
480 creating a non-linear register space).
481 In some cases, a single
482 driver may need to access the same type of device in multiple ways in a
483 single system or architecture.
484 The goal of the
485 .Nm
486 functions is to allow a single driver source file to manipulate a set
487 of devices on different system architectures, and to allow a single driver
488 object file to manipulate a set of devices on multiple bus types on a
489 single architecture.
490 .Pp
491 Not all busses have to implement all functions described in this
492 document, though that is encouraged if the operations are logically
493 supported by the bus.
494 Unimplemented functions should cause
495 compile-time errors if possible.
496 .Pp
497 All of the interface definitions described in this document are shown as
498 function prototypes and discussed as if they were required to be
499 functions.
500 Implementations are encouraged to implement prototyped
501 (type-checked) versions of these interfaces, but may implement them as
502 macros if appropriate.
503 Machine-dependent types, variables, and functions
504 should be marked clearly
505 to avoid confusion with the
506 machine-independent types and functions, and, if possible, should be
507 given names which make the machine-dependence clear.
508 .Sh CONCEPTS AND GUIDELINES
509 Bus spaces are described by bus space tags, which can be created only by
510 machine-dependent code.
511 A given machine may have several different types
512 of bus space (e.g.\& memory space and I/O space), and thus may provide
513 multiple different bus space tags.
514 Individual busses or devices on a machine may use more than one bus space
515 tag.
516 For instance, ISA devices are
517 given an ISA memory space tag and an ISA I/O space tag.
518 Architectures
519 may have several different tags which represent the same type of
520 space, for instance because of multiple different host bus interface
521 chipsets.
522 .Pp
523 A range in bus space is described by a bus address and a bus size.
524 The
525 bus address describes the start of the range in bus space.
526 The bus
527 size describes the size of the range in bytes.
528 Busses which are not byte
529 addressable may require use of bus space ranges with appropriately
530 aligned addresses and properly rounded sizes.
531 .Pp
532 Access to regions of bus space is facilitated by use of bus space handles,
533 which are usually created by mapping a specific range of a bus space.
534 Handles may also be created by allocating
535 and mapping a range of bus space, the actual location of which is picked
536 by the implementation within bounds specified by the caller of the
537 allocation function.
538 .Pp
539 All of the bus space access functions require one bus space tag
540 argument, at least one handle argument, and at least one offset argument
541 (a bus size).
542 The bus space tag specifies the space, each handle specifies a region in
543 the space, and each offset specifies the offset into the region of the
544 actual location(s) to be accessed.
545 Offsets are given in bytes, though busses
546 may impose alignment constraints.
547 The offset used to access data
548 relative to a given handle must be such that all of the data being
549 accessed is in the mapped region that the handle describes.
550 Trying to
551 access data outside that region is an error.
552 .Pp
553 Because some architectures' memory systems use buffering to improve
554 memory and device access performance, there is a mechanism which can be
555 used to create
556 .Dq barriers
557 in the bus space read and write stream.
558 There
559 are three types of barriers: read, write, and read/write.
560 All reads
561 started to the region before a read barrier must complete before any reads
562 after the read barrier are started.
563 (The analogous requirement is true for
564 write barriers.)
565 Read/write barriers force all reads and writes started
566 before the barrier to complete before any reads or writes after the
567 barrier are started.
568 Correctly-written drivers will include all
569 appropriate barriers, and assume only the read/write ordering imposed by
570 the barrier operations.
571 .Pp
572 People trying to write portable drivers with the
573 .Nm
574 functions should
575 try to make minimal assumptions about what the system allows.
576 In particular,
577 they should expect that the system requires bus space addresses being
578 accessed to be naturally aligned (i.e., base address of handle added to
579 offset is a multiple of the access size), and that the system does
580 alignment checking on pointers (i.e., pointer to objects being read and
581 written must point to properly-aligned data).
582 .Pp
583 The descriptions of the
584 .Nm
585 functions given below all assume that
586 they are called with proper arguments.
587 If called with invalid arguments
588 or arguments that are out of range (e.g.\& trying to access data outside of
589 the region mapped when a given handle was created), undefined behaviour
590 results.
591 In that case, they may cause the
592 system to halt, either intentionally (via panic) or unintentionally (by
593 causing a fatal trap of by some other means) or may cause improper
594 operation which is not immediately fatal.
595 Functions which return
596 .Ft void
597 or which return data read from bus space (i.e., functions which
598 do not obviously return an error code) do not fail.
599 They could only fail
600 if given invalid arguments, and in that case their behaviour is undefined.
601 .Sh TYPES
602 Several types are defined
603 to facilitate use of the
604 .Nm
605 functions by drivers.
606 .Ss Vt bus_addr_t
607 The
608 .Vt bus_addr_t
609 type is used to describe bus addresses.
610 It must be an
611 unsigned integral type
612 capable of holding the largest bus address usable by the architecture.
613 This
614 type is primarily used when mapping and unmapping bus space.
615 .Ss Vt bus_size_t
616 The
617 .Vt bus_size_t
618 type is used to describe sizes of ranges in bus space.
619 It must be an
620 unsigned integral type capable of holding the size of the largest bus
621 address range usable on the architecture.
622 This type is used by virtually all
623 of the
624 .Nm
625 functions, describing sizes when mapping regions and
626 offsets into regions when performing space access operations.
627 .Ss Vt bus_space_tag_t
628 The
629 .Vt bus_space_tag_t
630 type is used to describe a particular bus space on a machine.
631 Its
632 contents are machine-dependent and should be considered opaque by
633 machine-independent code.
634 This type is used by all
635 .Nm
636 functions to name the space on which they are operating.
637 .Ss Vt bus_space_handle_t
638 The
639 .Vt bus_space_handle_t
640 type is used to describe a mapping of a range of bus space.
641 Its
642 contents are machine-dependent and should be considered opaque by
643 machine-independent code.
644 This type is used when performing bus space
645 access operations.
646 .Sh MAPPING AND UNMAPPING BUS SPACE
647 This section is specific to the
648 .Nx
649 version of these functions and may or may not apply to the
650 .Dx
651 version.
652 .Pp
653 Bus space must be mapped before it can be used, and should be
654 unmapped when it is no longer needed.
655 The
656 .Fn bus_space_map
657 and
658 .Fn bus_space_unmap
659 functions provide these capabilities.
660 .Pp
661 Some drivers need to be able to pass a subregion of already-mapped bus
662 space to another driver or module within a driver.
663 The
664 .Fn bus_space_subregion
665 function allows such subregions to be created.
666 .Ss Fn bus_space_map space address size flags handlep
667 The
668 .Fn bus_space_map
669 function maps the region of bus space named by the
670 .Fa space , address ,
671 and
672 .Fa size
673 arguments.
674 If successful, it returns zero
675 and fills in the bus space handle pointed to by
676 .Fa handlep
677 with the handle
678 that can be used to access the mapped region.
679 If unsuccessful,
680 it will return non-zero and leave the bus space handle pointed
681 to by
682 .Fa handlep
683 in an undefined state.
684 .Pp
685 The
686 .Fa flags
687 argument controls how the space is to be mapped.
688 Supported flags include:
689 .Bl -tag -width ".Dv BUS_SPACE_MAP_CACHEABLE"
690 .It Dv BUS_SPACE_MAP_CACHEABLE
691 Try to map the space so that accesses can be cached and/or
692 prefetched by the system.
693 If this flag is not specified, the
694 implementation should map the space so that it will not be cached or
695 prefetched.
696 .Pp
697 This flag must have a value of 1 on all implementations for backward
698 compatibility.
699 .It Dv BUS_SPACE_MAP_LINEAR
700 Try to map the space so that its contents can be accessed linearly via
701 normal memory access methods (e.g.\& pointer dereferencing and structure
702 accesses).
703 This is useful when software wants to do direct access to a memory
704 device, e.g.\& a frame buffer.
705 If this flag is specified and linear
706 mapping is not possible, the
707 .Fn bus_space_map
708 call should fail.
709 If this
710 flag is not specified, the system may map the space in whatever way is
711 most convenient.
712 .El
713 .Pp
714 Not all combinations of flags make sense or are supported with all
715 spaces.
716 For instance,
717 .Dv BUS_SPACE_MAP_CACHEABLE
718 may be meaningless when
719 used on many systems' I/O port spaces, and on some systems
720 .Dv BUS_SPACE_MAP_LINEAR
721 without
722 .Dv BUS_SPACE_MAP_CACHEABLE
723 may never work.
724 When the system hardware or firmware provides hints as to how spaces should be
725 mapped (e.g.\& the PCI memory mapping registers'
726 .Dq prefetchable
727 bit), those
728 hints should be followed for maximum compatibility.
729 On some systems,
730 requesting a mapping that cannot be satisfied (e.g.\& requesting a
731 non-cacheable mapping when the system can only provide a cacheable one)
732 will cause the request to fail.
733 .Pp
734 Some implementations may keep track of use of bus space for some or all
735 bus spaces and refuse to allow duplicate allocations.
736 This is encouraged
737 for bus spaces which have no notion of slot-specific space addressing,
738 such as ISA and VME, and for spaces which coexist with those spaces
739 (e.g.\& EISA and PCI memory and I/O spaces co-existing with ISA memory and
740 I/O spaces).
741 .Pp
742 Mapped regions may contain areas for which there is no device on the
743 bus.
744 If space in those areas is accessed, the results are
745 bus-dependent.
746 .Ss Fn bus_space_unmap space handle size
747 The
748 .Fn bus_space_unmap
749 function unmaps a region of bus space mapped with
750 .Fn bus_space_map .
751 When unmapping a region, the
752 .Fa size
753 specified should be
754 the same as the size given to
755 .Fn bus_space_map
756 when mapping that region.
757 .Pp
758 After
759 .Fn bus_space_unmap
760 is called on a handle, that handle is no longer
761 valid.
762 (If copies were made of the handle they are no longer valid,
763 either.)
764 .Pp
765 This function will never fail.
766 If it would fail (e.g.\& because of an
767 argument error), that indicates a software bug which should cause a
768 panic.
769 In that case,
770 .Fn bus_space_unmap
771 will never return.
772 .Ss Fn bus_space_subregion space handle offset size nhandlep
773 The
774 .Fn bus_space_subregion
775 function is a convenience function which makes a
776 new handle to some subregion of an already-mapped region of bus space.
777 The subregion described by the new handle starts at byte offset
778 .Fa offset
779 into the region described by
780 .Fa handle ,
781 with the size give by
782 .Fa size ,
783 and must be wholly contained within the original region.
784 .Pp
785 If successful,
786 .Fn bus_space_subregion
787 returns zero and fills in the bus
788 space handle pointed to by
789 .Fa nhandlep .
790 If unsuccessful, it returns non-zero and leaves the bus space handle
791 pointed to by
792 .Fa nhandlep
793 in an
794 undefined state.
795 In either case, the handle described by
796 .Fa handle
797 remains valid and is unmodified.
798 .Pp
799 When done with a handle created by
800 .Fn bus_space_subregion ,
801 the handle should
802 be thrown away.
803 Under no circumstances should
804 .Fn bus_space_unmap
805 be used on the handle.
806 Doing so may confuse any resource management
807 being done on the space, and will result in undefined behaviour.
808 When
809 .Fn bus_space_unmap
810 or
811 .Fn bus_space_free
812 is called on a handle, all subregions of that handle become invalid.
813 .Sh ALLOCATING AND FREEING BUS SPACE
814 This section is specific to the
815 .Nx
816 version of these functions and may or may not apply to the
817 .Dx
818 version.
819 .Pp
820 Some devices require or allow bus space to be allocated by the operating
821 system for device use.
822 When the devices no longer need the space, the
823 operating system should free it for use by other devices.
824 The
825 .Fn bus_space_alloc
826 and
827 .Fn bus_space_free
828 functions provide these capabilities.
829 .Ss Fn bus_space_alloc space reg_start reg_end size alignment boundary \
830 flags addrp handlep
831 The
832 .Fn bus_space_alloc
833 function allocates and maps a region of bus space with the size given by
834 .Fa size ,
835 corresponding to the given constraints.
836 If successful, it returns
837 zero, fills in the bus address pointed to by
838 .Fa addrp
839 with the bus space address of the allocated region, and fills in
840 the bus space handle pointed to by
841 .Fa handlep
842 with the handle that can be used to access that region.
843 If unsuccessful, it returns non-zero and leaves the bus address pointed to by
844 .Fa addrp
845 and the bus space handle pointed to by
846 .Fa handlep
847 in an undefined state.
848 .Pp
849 Constraints on the allocation are given by the
850 .Fa reg_start , reg_end , alignment ,
851 and
852 .Fa boundary
853 parameters.
854 The allocated region will start at or after
855 .Fa reg_start
856 and end before or at
857 .Fa reg_end .
858 The
859 .Fa alignment
860 constraint must be a power of two, and the allocated region will start at
861 an address that is an even multiple of that power of two.
862 The
863 .Fa boundary
864 constraint, if non-zero, ensures that the region is allocated so that
865 .Fa "first address in region"
866 /
867 .Fa boundary
868 has the same value as
869 .Fa "last address in region"
870 /
871 .Fa boundary .
872 If the constraints cannot be met,
873 .Fn bus_space_alloc
874 will fail.
875 It is an error to specify a set of
876 constraints that can never be met
877 (for example,
878 .Fa size
879 greater than
880 .Fa boundary ) .
881 .Pp
882 The
883 .Fa flags
884 parameter is the same as the like-named parameter to
885 .Fn bus_space_map ,
886 the same flag values should be used, and they have the
887 same meanings.
888 .Pp
889 Handles created by
890 .Fn bus_space_alloc
891 should only be freed with
892 .Fn bus_space_free .
893 Trying to use
894 .Fn bus_space_unmap
895 on them causes undefined behaviour.
896 The
897 .Fn bus_space_subregion
898 function can be used on
899 handles created by
900 .Fn bus_space_alloc .
901 .Ss Fn bus_space_free space handle size
902 The
903 .Fn bus_space_free
904 function unmaps and frees a region of bus space mapped
905 and allocated with
906 .Fn bus_space_alloc .
907 When unmapping a region, the
908 .Fa size
909 specified should be the same as the size given to
910 .Fn bus_space_alloc
911 when allocating the region.
912 .Pp
913 After
914 .Fn bus_space_free
915 is called on a handle, that handle is no longer valid.
916 (If copies were
917 made of the handle, they are no longer valid, either.)
918 .Pp
919 This function will never fail.
920 If it would fail (e.g.\& because of an
921 argument error), that indicates a software bug which should cause a
922 panic.
923 In that case,
924 .Fn bus_space_free
925 will never return.
926 .Sh READING AND WRITING SINGLE DATA ITEMS
927 The simplest way to access bus space is to read or write a single data
928 item.
929 The
930 .Fn bus_space_read_N
931 and
932 .Fn bus_space_write_N
933 families of functions provide
934 the ability to read and write 1, 2, and 4 byte data items on busses
935 which support those access sizes.
936 .Ss Fn bus_space_read_1 space handle offset
937 .Ss Fn bus_space_read_2 space handle offset
938 .Ss Fn bus_space_read_4 space handle offset
939 The
940 .Fn bus_space_read_N
941 family of functions reads a 1, 2, or 4 byte data item from
942 the offset specified by
943 .Fa offset
944 into the region specified by
945 .Fa handle
946 of the bus space specified by
947 .Fa space .
948 The location being read must lie within the bus space region specified by
949 .Fa handle .
950 .Pp
951 For portability, the starting address of the region specified by
952 .Fa handle
953 plus the offset should be a multiple of the size of data item being read.
954 On some systems, not obeying this requirement may cause incorrect data to
955 be read, on others it may cause a system crash.
956 .Pp
957 Read operations done by the
958 .Fn bus_space_read_N
959 functions may be executed out
960 of order with respect to other pending read and write operations unless
961 order is enforced by use of the
962 .Fn bus_space_barrier
963 function.
964 .Pp
965 These functions will never fail.
966 If they would fail (e.g.\& because of an
967 argument error), that indicates a software bug which should cause a
968 panic.
969 In that case, they will never return.
970 .Ss Fn bus_space_write_1 space handle offset value
971 .Ss Fn bus_space_write_2 space handle offset value
972 .Ss Fn bus_space_write_4 space handle offset value
973 The
974 .Fn bus_space_write_N
975 family of functions writes a 1, 2, or 4 byte data item to the offset
976 specified by
977 .Fa offset
978 into the region specified by
979 .Fa handle
980 of the bus space specified by
981 .Fa space .
982 The location being written must lie within
983 the bus space region specified by
984 .Fa handle .
985 .Pp
986 For portability, the starting address of the region specified by
987 .Fa handle
988 plus the offset should be a multiple of the size of data item being
989 written.
990 On some systems, not obeying this requirement may cause
991 incorrect data to be written, on others it may cause a system crash.
992 .Pp
993 Write operations done by the
994 .Fn bus_space_write_N
995 functions may be executed
996 out of order with respect to other pending read and write operations
997 unless order is enforced by use of the
998 .Fn bus_space_barrier
999 function.
1000 .Pp
1001 These functions will never fail.
1002 If they would fail (e.g.\& because of an
1003 argument error), that indicates a software bug which should cause a
1004 panic.
1005 In that case, they will never return.
1006 .Sh BARRIERS
1007 In order to allow high-performance buffering implementations to avoid bus
1008 activity on every operation, read and write ordering should be specified
1009 explicitly by drivers when necessary.
1010 The
1011 .Fn bus_space_barrier
1012 function provides that ability.
1013 .Ss Fn bus_space_barrier space handle offset length flags
1014 The
1015 .Fn bus_space_barrier
1016 function enforces ordering of bus space read and write operations
1017 for the specified subregion (described by the
1018 .Fa offset
1019 and
1020 .Fa length
1021 parameters) of the region named by
1022 .Fa handle
1023 in the space named by
1024 .Fa space .
1025 .Pp
1026 The
1027 .Fa flags
1028 argument controls what types of operations are to be ordered.
1029 Supported flags are:
1030 .Bl -tag -width ".Dv BUS_SPACE_BARRIER_WRITE"
1031 .It Dv BUS_SPACE_BARRIER_READ
1032 Synchronize read operations.
1033 .It Dv BUS_SPACE_BARRIER_WRITE
1034 Synchronize write operations.
1035 .El
1036 .Pp
1037 Those flags can be combined (or-ed together) to enforce ordering on both
1038 read and write operations.
1039 .Pp
1040 All of the specified type(s) of operation which are done to the region
1041 before the barrier operation are guaranteed to complete before any of the
1042 specified type(s) of operation done after the barrier.
1043 .Pp
1044 Example: Consider a hypothetical device with two single-byte ports, one
1045 write-only input port (at offset 0) and a read-only output port (at
1046 offset 1).
1047 Operation of the device is as follows: data bytes are written
1048 to the input port, and are placed by the device on a stack, the top of
1049 which is read by reading from the output port.
1050 The sequence to correctly
1051 write two data bytes to the device then read those two data bytes back
1052 would be:
1053 .Bd -literal
1054 /*
1055  * t and h are the tag and handle for the mapped device's
1056  * space.
1057  */
1058 bus_space_write_1(t, h, 0, data0);
1059 bus_space_barrier(t, h, 0, 1, BUS_SPACE_BARRIER_WRITE);  /* 1 */
1060 bus_space_write_1(t, h, 0, data1);
1061 bus_space_barrier(t, h, 0, 2,
1062     BUS_SPACE_BARRIER_READ|BUS_SPACE_BARRIER_WRITE);     /* 2 */
1063 ndata1 = bus_space_read_1(t, h, 1);
1064 bus_space_barrier(t, h, 1, 1, BUS_SPACE_BARRIER_READ);   /* 3 */
1065 ndata0 = bus_space_read_1(t, h, 1);
1066 /* data0 == ndata0, data1 == ndata1 */
1067 .Ed
1068 .Pp
1069 The first barrier makes sure that the first write finishes before the
1070 second write is issued, so that two writes to the input port are done
1071 in order and are not collapsed into a single write.
1072 This ensures that
1073 the data bytes are written to the device correctly and in order.
1074 .Pp
1075 The second barrier makes sure that the writes to the output port finish
1076 before any of the reads to the input port are issued, thereby making sure
1077 that all of the writes are finished before data is read.
1078 This ensures
1079 that the first byte read from the device really is the last one that was
1080 written.
1081 .Pp
1082 The third barrier makes sure that the first read finishes before the
1083 second read is issued, ensuring that data is read correctly and in order.
1084 .Pp
1085 The barriers in the example above are specified to cover the absolute
1086 minimum number of bus space locations.
1087 It is correct (and often
1088 easier) to make barrier operations cover the device's whole range of bus
1089 space, that is, to specify an offset of zero and the size of the
1090 whole region.
1091 .Sh REGION OPERATIONS
1092 Some devices use buffers which are mapped as regions in bus space.
1093 Often, drivers want to copy the contents of those buffers to or from
1094 memory, e.g.\& into mbufs which can be passed to higher levels of the
1095 system or from mbufs to be output to a network.
1096 In order to allow
1097 drivers to do this as efficiently as possible, the
1098 .Fn bus_space_read_region_N
1099 and
1100 .Fn bus_space_write_region_N
1101 families of functions are provided.
1102 .Pp
1103 Drivers occasionally need to copy one region of a bus space to another,
1104 or to set all locations in a region of bus space to contain a single
1105 value.
1106 The
1107 .Fn bus_space_copy_region_N
1108 family of functions and the
1109 .Fn bus_space_set_region_N
1110 family of functions allow drivers to perform these operations.
1111 .Ss Fn bus_space_read_region_1 space handle offset datap count
1112 .Ss Fn bus_space_read_region_2 space handle offset datap count
1113 .Ss Fn bus_space_read_region_4 space handle offset datap count
1114 The
1115 .Fn bus_space_read_region_N
1116 family of functions reads
1117 .Fa count
1118 1, 2, or 4 byte data items from bus space
1119 starting at byte offset
1120 .Fa offset
1121 in the region specified by
1122 .Fa handle
1123 of the bus space specified by
1124 .Fa space
1125 and writes them into the array specified by
1126 .Fa datap .
1127 Each successive data item is read from an offset
1128 1, 2, or 4 bytes after the previous data item (depending on which
1129 function is used).
1130 All locations being read must lie within the bus
1131 space region specified by
1132 .Fa handle .
1133 .Pp
1134 For portability, the starting address of the region specified by
1135 .Fa handle
1136 plus the offset should be a multiple of the size of data items being
1137 read and the data array pointer should be properly aligned.
1138 On some
1139 systems, not obeying these requirements may cause incorrect data to be
1140 read, on others it may cause a system crash.
1141 .Pp
1142 Read operations done by the
1143 .Fn bus_space_read_region_N
1144 functions may be executed in any order.
1145 They may also be executed out
1146 of order with respect to other pending read and write operations unless
1147 order is enforced by use of the
1148 .Fn bus_space_barrier
1149 function.
1150 There is no way to insert barriers between reads of
1151 individual bus space locations executed by the
1152 .Fn bus_space_read_region_N
1153 functions.
1154 .Pp
1155 These functions will never fail.
1156 If they would fail (e.g.\& because of an
1157 argument error), that indicates a software bug which should cause a
1158 panic.
1159 In that case, they will never return.
1160 .Ss Fn bus_space_write_region_1 space handle offset datap count
1161 .Ss Fn bus_space_write_region_2 space handle offset datap count
1162 .Ss Fn bus_space_write_region_4 space handle offset datap count
1163 The
1164 .Fn bus_space_write_region_N
1165 family of functions reads
1166 .Fa count
1167 1, 2, or 4 byte data items from the array
1168 specified by
1169 .Fa datap
1170 and writes them to bus space starting at byte offset
1171 .Fa offset
1172 in the region specified by
1173 .Fa handle
1174 of the bus space specified
1175 by
1176 .Fa space .
1177 Each successive data item is written to an offset 1, 2, or 4
1178 bytes after the previous data item (depending on which function is
1179 used).
1180 All locations being written must lie within the bus space region
1181 specified by
1182 .Fa handle .
1183 .Pp
1184 For portability, the starting address of the region specified by
1185 .Fa handle
1186 plus the offset should be a multiple of the size of data items being
1187 written and the data array pointer should be properly aligned.
1188 On some
1189 systems, not obeying these requirements may cause incorrect data to be
1190 written, on others it may cause a system crash.
1191 .Pp
1192 Write operations done by the
1193 .Fn bus_space_write_region_N
1194 functions may be
1195 executed in any order.
1196 They may also be executed out of order with
1197 respect to other pending read and write operations unless order is
1198 enforced by use of the
1199 .Fn bus_space_barrier
1200 function.
1201 There is no way to insert barriers between writes of
1202 individual bus space locations executed by the
1203 .Fn bus_space_write_region_N
1204 functions.
1205 .Pp
1206 These functions will never fail.
1207 If they would fail (e.g.\& because of an
1208 argument error), that indicates a software bug which should cause a
1209 panic.
1210 In that case, they will never return.
1211 .Ss Fn bus_space_copy_region_1 space srchandle srcoffset dsthandle \
1212 dstoffset count
1213 .Ss Fn bus_space_copy_region_2 space srchandle srcoffset dsthandle \
1214 dstoffset count
1215 .Ss Fn bus_space_copy_region_4 space srchandle srcoffset dsthandle \
1216 dstoffset count
1217 The
1218 .Fn bus_space_copy_region_N
1219 family of functions copies
1220 .Fa count
1221 1, 2, or 4 byte data items in bus space
1222 from the area starting at byte offset
1223 .Fa srcoffset
1224 in the region specified by
1225 .Fa srchandle
1226 of the bus space specified by
1227 .Fa space
1228 to the area starting at byte offset
1229 .Fa dstoffset
1230 in the region specified by
1231 .Fa dsthandle
1232 in the same bus space.
1233 Each successive data item read or written has
1234 an offset 1, 2, or 4 bytes after the previous data item (depending
1235 on which function is used).
1236 All locations being read and written must
1237 lie within the bus space region specified by their respective handles.
1238 .Pp
1239 For portability, the starting addresses of the regions specified by the
1240 each handle plus its respective offset should be a multiple of the size
1241 of data items being copied.
1242 On some systems, not obeying this
1243 requirement may cause incorrect data to be copied, on others it may cause
1244 a system crash.
1245 .Pp
1246 Read and write operations done by the
1247 .Fn bus_space_copy_region_N
1248 functions may be executed in any order.
1249 They may also be executed out
1250 of order with respect to other pending read and write operations unless
1251 order is enforced by use of the
1252 .Fn bus_space_barrier
1253 function .
1254 There is no way to insert barriers between reads or writes of
1255 individual bus space locations executed by the
1256 .Fn bus_space_copy_region_N
1257 functions.
1258 .Pp
1259 Overlapping copies between different subregions of a single region
1260 of bus space are handled correctly by the
1261 .Fn bus_space_copy_region_N
1262 functions.
1263 .Pp
1264 These functions will never fail.
1265 If they would fail (e.g.\& because of an
1266 argument error), that indicates a software bug which should cause a
1267 panic.
1268 In that case, they will never return.
1269 .Ss Fn bus_space_set_region_1 space handle offset value count
1270 .Ss Fn bus_space_set_region_2 space handle offset value count
1271 .Ss Fn bus_space_set_region_4 space handle offset value count
1272 The
1273 .Fn bus_space_set_region_N
1274 family of functions writes the given
1275 .Fa value
1276 to
1277 .Fa count
1278 1, 2, or 4 byte
1279 data items in bus space starting at byte offset
1280 .Fa offset
1281 in the region specified by
1282 .Fa handle
1283 of the bus space specified by
1284 .Fa space .
1285 Each successive data item has an offset 1, 2, or 4 bytes after the
1286 previous data item (depending on which function is used).
1287 All
1288 locations being written must lie within the bus space region specified
1289 by
1290 .Fa handle .
1291 .Pp
1292 For portability, the starting address of the region specified by
1293 .Fa handle
1294 plus the offset should be a multiple of the size of data items being
1295 written.
1296 On some systems, not obeying this requirement may cause
1297 incorrect data to be written, on others it may cause a system crash.
1298 .Pp
1299 Write operations done by the
1300 .Fn bus_space_set_region_N
1301 functions may be
1302 executed in any order.
1303 They may also be executed out of order with
1304 respect to other pending read and write operations unless order is
1305 enforced by use of the
1306 .Fn bus_space_barrier
1307 function.
1308 There is no way to insert barriers between writes of
1309 individual bus space locations executed by the
1310 .Fn bus_space_set_region_N
1311 functions.
1312 .Pp
1313 These functions will never fail.
1314 If they would fail (e.g.\& because of an
1315 argument error), that indicates a software bug which should cause a
1316 panic.
1317 In that case, they will never return.
1318 .Sh READING AND WRITING A SINGLE LOCATION MULTIPLE TIMES
1319 Some devices implement single locations in bus space which are to be read
1320 or written multiple times to communicate data, e.g.\& some ethernet
1321 devices' packet buffer FIFOs.
1322 In order to allow drivers to manipulate
1323 these types of devices as efficiently as possible, the
1324 .Fn bus_space_read_multi_N ,
1325 .Fn bus_space_set_multi_N ,
1326 and
1327 .Fn bus_space_write_multi_N
1328 families of functions are provided.
1329 .Ss Fn bus_space_read_multi_1 space handle offset datap count
1330 .Ss Fn bus_space_read_multi_2 space handle offset datap count
1331 .Ss Fn bus_space_read_multi_4 space handle offset datap count
1332 The
1333 .Fn bus_space_read_multi_N
1334 family of functions reads
1335 .Fa count
1336 1, 2, or 4 byte data items from bus space
1337 at byte offset
1338 .Fa offset
1339 in the region specified by
1340 .Fa handle
1341 of the bus space specified by
1342 .Fa space
1343 and writes them into the array specified by
1344 .Fa datap .
1345 Each successive data item is read from the same location in bus
1346 space.
1347 The location being read must lie within the bus space region
1348 specified by
1349 .Fa handle .
1350 .Pp
1351 For portability, the starting address of the region specified by
1352 .Fa handle
1353 plus the offset should be a multiple of the size of data items being
1354 read and the data array pointer should be properly aligned.
1355 On some
1356 systems, not obeying these requirements may cause incorrect data to be
1357 read, on others it may cause a system crash.
1358 .Pp
1359 Read operations done by the
1360 .Fn bus_space_read_multi_N
1361 functions may be
1362 executed out of order with respect to other pending read and write
1363 operations unless order is enforced by use of the
1364 .Fn bus_space_barrier
1365 function.
1366 Because the
1367 .Fn bus_space_read_multi_N
1368 functions read the same bus space location multiple times, they
1369 place an implicit read barrier between each successive read of that bus
1370 space location.
1371 .Pp
1372 These functions will never fail.
1373 If they would fail (e.g.\& because of an
1374 argument error), that indicates a software bug which should cause a
1375 panic.
1376 In that case, they will never return.
1377 .Ss Fn bus_space_write_multi_1 space handle offset datap count
1378 .Ss Fn bus_space_write_multi_2 space handle offset datap count
1379 .Ss Fn bus_space_write_multi_4 space handle offset datap count
1380 The
1381 .Fn bus_space_write_multi_N
1382 family of functions reads
1383 .Fa count
1384 1, 2, or 4 byte data items from the array
1385 specified by
1386 .Fa datap
1387 and writes them into bus space at byte offset
1388 .Fa offset
1389 in the region specified by
1390 .Fa handle
1391 of the bus space specified by
1392 .Fa space .
1393 Each successive data item is written to the same location in
1394 bus space.
1395 The location being written must lie within the bus space
1396 region specified by
1397 .Fa handle .
1398 .Pp
1399 For portability, the starting address of the region specified by
1400 .Fa handle
1401 plus the offset should be a multiple of the size of data items being
1402 written and the data array pointer should be properly aligned.
1403 On some
1404 systems, not obeying these requirements may cause incorrect data to be
1405 written, on others it may cause a system crash.
1406 .Pp
1407 Write operations done by the
1408 .Fn bus_space_write_multi_N
1409 functions may be executed out of order with respect to other pending
1410 read and write operations unless order is enforced by use of the
1411 .Fn bus_space_barrier
1412 function.
1413 Because the
1414 .Fn bus_space_write_multi_N
1415 functions write the same bus space location multiple times, they
1416 place an implicit write barrier between each successive write of that
1417 bus space location.
1418 .Pp
1419 These functions will never fail.
1420 If they would fail (e.g.\& because of an
1421 argument error), that indicates a software bug which should cause a
1422 panic.
1423 In that case, they will never return.
1424 .Ss Fn bus_space_set_multi_1 space handle offset value count
1425 .Ss Fn bus_space_set_multi_2 space handle offset value count
1426 .Ss Fn bus_space_set_multi_4 space handle offset value count
1427 The
1428 .Fn bus_space_set_multi_N
1429 writes
1430 .Fa value
1431 into bus space at byte offset
1432 .Fa offset
1433 in the region specified by
1434 .Fa handle
1435 of the bus space specified by
1436 .Fa space ,
1437 .Fa count
1438 times.
1439 The location being written must lie within the bus space
1440 region specified by
1441 .Fa handle .
1442 .Pp
1443 For portability, the starting address of the region specified by
1444 .Fa handle
1445 plus the offset should be a multiple of the size of data items being
1446 written and the data array pointer should be properly aligned.
1447 On some
1448 systems, not obeying these requirements may cause incorrect data to be
1449 written, on others it may cause a system crash.
1450 .Pp
1451 Write operations done by the
1452 .Fn bus_space_set_multi_N
1453 functions may be executed out of order with respect to other pending
1454 read and write operations unless order is enforced by use of the
1455 .Fn bus_space_barrier
1456 function.
1457 Because the
1458 .Fn bus_space_set_multi_N
1459 functions write the same bus space location multiple times, they
1460 place an implicit write barrier between each successive write of that
1461 bus space location.
1462 .Pp
1463 These functions will never fail.
1464 If they would fail (e.g.\& because of an
1465 argument error), that indicates a software bug which should cause a
1466 panic.
1467 In that case, they will never return.
1468 .Sh STREAM FUNCTIONS
1469 Most of the
1470 .Nm
1471 functions imply a host byte-order and a bus byte-order and take care of
1472 any translation for the caller.
1473 In some cases, however, hardware may map a FIFO or some other memory region
1474 for which the caller may want to use multi-word, yet untranslated access.
1475 Access to these types of memory regions should be with the
1476 .Fn bus_space_*_stream_N
1477 functions.
1478 .Pp
1479 .Bl -tag -compact -width ".Fn bus_space_write_region_stream_1"
1480 .It Fn bus_space_read_stream_1
1481 .It Fn bus_space_read_stream_2
1482 .It Fn bus_space_read_stream_4
1483 .It Fn bus_space_read_multi_stream_1
1484 .It Fn bus_space_read_multi_stream_2
1485 .It Fn bus_space_read_multi_stream_4
1486 .It Fn bus_space_read_region_stream_1
1487 .It Fn bus_space_read_region_stream_2
1488 .It Fn bus_space_read_region_stream_4
1489 .It Fn bus_space_write_stream_1
1490 .It Fn bus_space_write_stream_2
1491 .It Fn bus_space_write_stream_4
1492 .It Fn bus_space_write_multi_stream_1
1493 .It Fn bus_space_write_multi_stream_2
1494 .It Fn bus_space_write_multi_stream_4
1495 .It Fn bus_space_write_region_stream_1
1496 .It Fn bus_space_write_region_stream_2
1497 .It Fn bus_space_write_region_stream_4
1498 .It Fn bus_space_copy_region_stream_1
1499 .It Fn bus_space_copy_region_stream_2
1500 .It Fn bus_space_copy_region_stream_4
1501 .It Fn bus_space_set_multi_stream_1
1502 .It Fn bus_space_set_multi_stream_2
1503 .It Fn bus_space_set_multi_stream_4
1504 .It Fn bus_space_set_region_stream_1
1505 .It Fn bus_space_set_region_stream_2
1506 .It Fn bus_space_set_region_stream_4
1507 .El
1508 .Pp
1509 These functions are defined just as their non-stream counterparts,
1510 except that they provide no byte-order translation.
1511 .Sh COMPATIBILITY
1512 The current
1513 .Nx
1514 version of the
1515 .Nm
1516 interface specification differs slightly from the original
1517 specification that came into wide use and
1518 .Fx
1519 adopted.
1520 A few of the function names and arguments have changed
1521 for consistency and increased functionality.
1522 .Sh SEE ALSO
1523 .Xr bus_dma 9
1524 .Sh HISTORY
1525 The
1526 .Nm
1527 functions were introduced in a different form (memory and I/O spaces
1528 were accessed via different sets of functions) in
1529 .Nx 1.2 .
1530 The functions were merged to work on generic
1531 .Dq spaces
1532 early in the
1533 .Nx 1.3
1534 development cycle, and many drivers were converted to use them.
1535 This document was written later during the
1536 .Nx 1.3
1537 development cycle, and the specification was updated to fix some
1538 consistency problems and to add some missing functionality.
1539 .Pp
1540 The manual page was then adapted to the version of the interface that
1541 .Fx
1542 imported for the CAM SCSI drivers, plus subsequent evolution.
1543 The
1544 .Fx
1545 .Nm
1546 version was imported in
1547 .Fx 3.0 .
1548 .Sh AUTHORS
1549 .An -nosplit
1550 The
1551 .Nm
1552 interfaces were designed and implemented by the
1553 .Nx
1554 developer
1555 community.
1556 Primary contributors and implementors were
1557 .An Chris Demetriou ,
1558 .An Jason Thorpe ,
1559 and
1560 .An Charles Hannum ,
1561 but the rest of the
1562 .Nx
1563 developers and the user community played a significant role in development.
1564 .Pp
1565 .An Justin Gibbs
1566 ported these interfaces to
1567 .Fx .
1568 .Pp
1569 .An Chris Demetriou
1570 wrote this manual page.
1571 .Pp
1572 .An Warner Losh
1573 modified it for the
1574 .Fx
1575 implementation.
1576 .Sh BUGS
1577 This manual may not completely and accurately document the interface,
1578 and many parts of the interface are unspecified.