Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / alpha / pci / pci_bwx_bus_io_chipdep.c
blob57ac017adb7fed62e0422a21f423fd782e906ce0
1 /* $NetBSD: pci_bwx_bus_io_chipdep.c,v 1.17 2008/04/28 20:23:11 martin Exp $ */
3 /*-
4 * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
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.
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.
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.
34 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
35 * All rights reserved.
37 * Author: Chris G. Demetriou
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.
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.
49 * Carnegie Mellon requests users of this software to return to
51 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
52 * School of Computer Science
53 * Carnegie Mellon University
54 * Pittsburgh PA 15213-3890
56 * any improvements or extensions that they make and grant Carnegie the
57 * rights to redistribute these changes.
61 * Common PCI Chipset "bus I/O" functions, for chipsets which have to
62 * deal with only a single PCI interface chip in a machine.
64 * uses:
65 * CHIP name of the 'chip' it's being compiled for.
66 * CHIP_IO_BASE I/O space base to use.
67 * CHIP_IO_EX_STORE
68 * If defined, device-provided static storage area
69 * for the I/O space extent. If this is defined,
70 * CHIP_IO_EX_STORE_SIZE must also be defined. If
71 * this is not defined, a static area will be
72 * declared.
73 * CHIP_IO_EX_STORE_SIZE
74 * Size of the device-provided static storage area
75 * for the I/O memory space extent.
78 #include <sys/cdefs.h>
79 __KERNEL_RCSID(1, "$NetBSD: pci_bwx_bus_io_chipdep.c,v 1.17 2008/04/28 20:23:11 martin Exp $");
81 #include <sys/extent.h>
83 #include <machine/bwx.h>
85 #define __C(A,B) __CONCAT(A,B)
86 #define __S(S) __STRING(S)
88 /* mapping/unmapping */
89 int __C(CHIP,_io_map)(void *, bus_addr_t, bus_size_t, int,
90 bus_space_handle_t *, int);
91 void __C(CHIP,_io_unmap)(void *, bus_space_handle_t,
92 bus_size_t, int);
93 int __C(CHIP,_io_subregion)(void *, bus_space_handle_t,
94 bus_size_t, bus_size_t, bus_space_handle_t *);
96 int __C(CHIP,_io_translate)(void *, bus_addr_t, bus_size_t,
97 int, struct alpha_bus_space_translation *);
98 int __C(CHIP,_io_get_window)(void *, int,
99 struct alpha_bus_space_translation *);
101 /* allocation/deallocation */
102 int __C(CHIP,_io_alloc)(void *, bus_addr_t, bus_addr_t,
103 bus_size_t, bus_size_t, bus_addr_t, int, bus_addr_t *,
104 bus_space_handle_t *);
105 void __C(CHIP,_io_free)(void *, bus_space_handle_t,
106 bus_size_t);
108 /* get kernel virtual address */
109 void * __C(CHIP,_io_vaddr)(void *, bus_space_handle_t);
111 /* mmap for user */
112 paddr_t __C(CHIP,_io_mmap)(void *, bus_addr_t, off_t, int, int);
114 /* barrier */
115 inline void __C(CHIP,_io_barrier)(void *, bus_space_handle_t,
116 bus_size_t, bus_size_t, int);
118 /* read (single) */
119 inline u_int8_t __C(CHIP,_io_read_1)(void *, bus_space_handle_t,
120 bus_size_t);
121 inline u_int16_t __C(CHIP,_io_read_2)(void *, bus_space_handle_t,
122 bus_size_t);
123 inline u_int32_t __C(CHIP,_io_read_4)(void *, bus_space_handle_t,
124 bus_size_t);
125 inline u_int64_t __C(CHIP,_io_read_8)(void *, bus_space_handle_t,
126 bus_size_t);
128 /* read multiple */
129 void __C(CHIP,_io_read_multi_1)(void *, bus_space_handle_t,
130 bus_size_t, u_int8_t *, bus_size_t);
131 void __C(CHIP,_io_read_multi_2)(void *, bus_space_handle_t,
132 bus_size_t, u_int16_t *, bus_size_t);
133 void __C(CHIP,_io_read_multi_4)(void *, bus_space_handle_t,
134 bus_size_t, u_int32_t *, bus_size_t);
135 void __C(CHIP,_io_read_multi_8)(void *, bus_space_handle_t,
136 bus_size_t, u_int64_t *, bus_size_t);
138 /* read region */
139 void __C(CHIP,_io_read_region_1)(void *, bus_space_handle_t,
140 bus_size_t, u_int8_t *, bus_size_t);
141 void __C(CHIP,_io_read_region_2)(void *, bus_space_handle_t,
142 bus_size_t, u_int16_t *, bus_size_t);
143 void __C(CHIP,_io_read_region_4)(void *, bus_space_handle_t,
144 bus_size_t, u_int32_t *, bus_size_t);
145 void __C(CHIP,_io_read_region_8)(void *, bus_space_handle_t,
146 bus_size_t, u_int64_t *, bus_size_t);
148 /* write (single) */
149 inline void __C(CHIP,_io_write_1)(void *, bus_space_handle_t,
150 bus_size_t, u_int8_t);
151 inline void __C(CHIP,_io_write_2)(void *, bus_space_handle_t,
152 bus_size_t, u_int16_t);
153 inline void __C(CHIP,_io_write_4)(void *, bus_space_handle_t,
154 bus_size_t, u_int32_t);
155 inline void __C(CHIP,_io_write_8)(void *, bus_space_handle_t,
156 bus_size_t, u_int64_t);
158 /* write multiple */
159 void __C(CHIP,_io_write_multi_1)(void *, bus_space_handle_t,
160 bus_size_t, const u_int8_t *, bus_size_t);
161 void __C(CHIP,_io_write_multi_2)(void *, bus_space_handle_t,
162 bus_size_t, const u_int16_t *, bus_size_t);
163 void __C(CHIP,_io_write_multi_4)(void *, bus_space_handle_t,
164 bus_size_t, const u_int32_t *, bus_size_t);
165 void __C(CHIP,_io_write_multi_8)(void *, bus_space_handle_t,
166 bus_size_t, const u_int64_t *, bus_size_t);
168 /* write region */
169 void __C(CHIP,_io_write_region_1)(void *, bus_space_handle_t,
170 bus_size_t, const u_int8_t *, bus_size_t);
171 void __C(CHIP,_io_write_region_2)(void *, bus_space_handle_t,
172 bus_size_t, const u_int16_t *, bus_size_t);
173 void __C(CHIP,_io_write_region_4)(void *, bus_space_handle_t,
174 bus_size_t, const u_int32_t *, bus_size_t);
175 void __C(CHIP,_io_write_region_8)(void *, bus_space_handle_t,
176 bus_size_t, const u_int64_t *, bus_size_t);
178 /* set multiple */
179 void __C(CHIP,_io_set_multi_1)(void *, bus_space_handle_t,
180 bus_size_t, u_int8_t, bus_size_t);
181 void __C(CHIP,_io_set_multi_2)(void *, bus_space_handle_t,
182 bus_size_t, u_int16_t, bus_size_t);
183 void __C(CHIP,_io_set_multi_4)(void *, bus_space_handle_t,
184 bus_size_t, u_int32_t, bus_size_t);
185 void __C(CHIP,_io_set_multi_8)(void *, bus_space_handle_t,
186 bus_size_t, u_int64_t, bus_size_t);
188 /* set region */
189 void __C(CHIP,_io_set_region_1)(void *, bus_space_handle_t,
190 bus_size_t, u_int8_t, bus_size_t);
191 void __C(CHIP,_io_set_region_2)(void *, bus_space_handle_t,
192 bus_size_t, u_int16_t, bus_size_t);
193 void __C(CHIP,_io_set_region_4)(void *, bus_space_handle_t,
194 bus_size_t, u_int32_t, bus_size_t);
195 void __C(CHIP,_io_set_region_8)(void *, bus_space_handle_t,
196 bus_size_t, u_int64_t, bus_size_t);
198 /* copy */
199 void __C(CHIP,_io_copy_region_1)(void *, bus_space_handle_t,
200 bus_size_t, bus_space_handle_t, bus_size_t, bus_size_t);
201 void __C(CHIP,_io_copy_region_2)(void *, bus_space_handle_t,
202 bus_size_t, bus_space_handle_t, bus_size_t, bus_size_t);
203 void __C(CHIP,_io_copy_region_4)(void *, bus_space_handle_t,
204 bus_size_t, bus_space_handle_t, bus_size_t, bus_size_t);
205 void __C(CHIP,_io_copy_region_8)(void *, bus_space_handle_t,
206 bus_size_t, bus_space_handle_t, bus_size_t, bus_size_t);
208 #ifndef CHIP_IO_EX_STORE
209 static long
210 __C(CHIP,_io_ex_storage)[EXTENT_FIXED_STORAGE_SIZE(8) / sizeof(long)];
211 #define CHIP_IO_EX_STORE(v) (__C(CHIP, _io_ex_storage))
212 #define CHIP_IO_EX_STORE_SIZE(v) (sizeof __C(CHIP, _io_ex_storage))
213 #endif
215 void
216 __C(CHIP,_bus_io_init)(t, v)
217 bus_space_tag_t t;
218 void *v;
220 struct extent *ex;
223 * Initialize the bus space tag.
226 /* cookie */
227 t->abs_cookie = v;
229 /* mapping/unmapping */
230 t->abs_map = __C(CHIP,_io_map);
231 t->abs_unmap = __C(CHIP,_io_unmap);
232 t->abs_subregion = __C(CHIP,_io_subregion);
234 t->abs_translate = __C(CHIP,_io_translate);
235 t->abs_get_window = __C(CHIP,_io_get_window);
237 /* allocation/deallocation */
238 t->abs_alloc = __C(CHIP,_io_alloc);
239 t->abs_free = __C(CHIP,_io_free);
241 /* get kernel virtual address */
242 t->abs_vaddr = __C(CHIP,_io_vaddr);
244 /* mmap for user */
245 t->abs_mmap = __C(CHIP,_io_mmap);
247 /* barrier */
248 t->abs_barrier = __C(CHIP,_io_barrier);
250 /* read (single) */
251 t->abs_r_1 = __C(CHIP,_io_read_1);
252 t->abs_r_2 = __C(CHIP,_io_read_2);
253 t->abs_r_4 = __C(CHIP,_io_read_4);
254 t->abs_r_8 = __C(CHIP,_io_read_8);
256 /* read multiple */
257 t->abs_rm_1 = __C(CHIP,_io_read_multi_1);
258 t->abs_rm_2 = __C(CHIP,_io_read_multi_2);
259 t->abs_rm_4 = __C(CHIP,_io_read_multi_4);
260 t->abs_rm_8 = __C(CHIP,_io_read_multi_8);
262 /* read region */
263 t->abs_rr_1 = __C(CHIP,_io_read_region_1);
264 t->abs_rr_2 = __C(CHIP,_io_read_region_2);
265 t->abs_rr_4 = __C(CHIP,_io_read_region_4);
266 t->abs_rr_8 = __C(CHIP,_io_read_region_8);
268 /* write (single) */
269 t->abs_w_1 = __C(CHIP,_io_write_1);
270 t->abs_w_2 = __C(CHIP,_io_write_2);
271 t->abs_w_4 = __C(CHIP,_io_write_4);
272 t->abs_w_8 = __C(CHIP,_io_write_8);
274 /* write multiple */
275 t->abs_wm_1 = __C(CHIP,_io_write_multi_1);
276 t->abs_wm_2 = __C(CHIP,_io_write_multi_2);
277 t->abs_wm_4 = __C(CHIP,_io_write_multi_4);
278 t->abs_wm_8 = __C(CHIP,_io_write_multi_8);
280 /* write region */
281 t->abs_wr_1 = __C(CHIP,_io_write_region_1);
282 t->abs_wr_2 = __C(CHIP,_io_write_region_2);
283 t->abs_wr_4 = __C(CHIP,_io_write_region_4);
284 t->abs_wr_8 = __C(CHIP,_io_write_region_8);
286 /* set multiple */
287 t->abs_sm_1 = __C(CHIP,_io_set_multi_1);
288 t->abs_sm_2 = __C(CHIP,_io_set_multi_2);
289 t->abs_sm_4 = __C(CHIP,_io_set_multi_4);
290 t->abs_sm_8 = __C(CHIP,_io_set_multi_8);
292 /* set region */
293 t->abs_sr_1 = __C(CHIP,_io_set_region_1);
294 t->abs_sr_2 = __C(CHIP,_io_set_region_2);
295 t->abs_sr_4 = __C(CHIP,_io_set_region_4);
296 t->abs_sr_8 = __C(CHIP,_io_set_region_8);
298 /* copy */
299 t->abs_c_1 = __C(CHIP,_io_copy_region_1);
300 t->abs_c_2 = __C(CHIP,_io_copy_region_2);
301 t->abs_c_4 = __C(CHIP,_io_copy_region_4);
302 t->abs_c_8 = __C(CHIP,_io_copy_region_8);
304 ex = extent_create(__S(__C(CHIP,_bus_io)), 0x0UL, 0xffffffffUL,
305 M_DEVBUF, (void *)CHIP_IO_EX_STORE(v), CHIP_IO_EX_STORE_SIZE(v),
306 EX_NOWAIT|EX_NOCOALESCE);
308 CHIP_IO_EXTENT(v) = ex;
312 __C(CHIP,_io_translate)(v, ioaddr, iolen, flags, abst)
313 void *v;
314 bus_addr_t ioaddr;
315 bus_size_t iolen;
316 int flags;
317 struct alpha_bus_space_translation *abst;
319 int linear = flags & BUS_SPACE_MAP_LINEAR;
322 * Can't map i/o space linearly.
324 if (linear)
325 return (EOPNOTSUPP);
327 return (__C(CHIP,_io_get_window)(v, 0, abst));
331 __C(CHIP,_io_get_window)(v, window, abst)
332 void *v;
333 int window;
334 struct alpha_bus_space_translation *abst;
337 switch (window) {
338 case 0:
339 abst->abst_bus_start = 0;
340 abst->abst_bus_end = 0xffffffffUL;
341 abst->abst_sys_start = CHIP_IO_SYS_START(v);
342 abst->abst_sys_end = CHIP_IO_SYS_START(v) + abst->abst_bus_end;
343 abst->abst_addr_shift = 0;
344 abst->abst_size_shift = 0;
345 abst->abst_flags = ABST_DENSE|ABST_BWX;
346 break;
348 default:
349 panic(__S(__C(CHIP,_io_get_window)) ": invalid window %d",
350 window);
353 return (0);
357 __C(CHIP,_io_map)(v, ioaddr, iosize, flags, iohp, acct)
358 void *v;
359 bus_addr_t ioaddr;
360 bus_size_t iosize;
361 int flags;
362 bus_space_handle_t *iohp;
363 int acct;
365 struct alpha_bus_space_translation abst;
366 int error;
369 * Get the translation for this address.
371 error = __C(CHIP,_io_translate)(v, ioaddr, iosize, flags, &abst);
372 if (error)
373 return (error);
375 if (acct == 0)
376 goto mapit;
378 #ifdef EXTENT_DEBUG
379 printf("io: allocating 0x%lx to 0x%lx\n", ioaddr, ioaddr + iosize - 1);
380 #endif
381 error = extent_alloc_region(CHIP_IO_EXTENT(v), ioaddr, iosize,
382 EX_NOWAIT | (CHIP_EX_MALLOC_SAFE(v) ? EX_MALLOCOK : 0));
383 if (error) {
384 #ifdef EXTENT_DEBUG
385 printf("io: allocation failed (%d)\n", error);
386 extent_print(CHIP_IO_EXTENT(v));
387 #endif
388 return (error);
391 mapit:
392 *iohp = ALPHA_PHYS_TO_K0SEG(abst.abst_sys_start + ioaddr);
394 return (0);
397 void
398 __C(CHIP,_io_unmap)(v, ioh, iosize, acct)
399 void *v;
400 bus_space_handle_t ioh;
401 bus_size_t iosize;
402 int acct;
404 bus_addr_t ioaddr;
405 int error;
407 if (acct == 0)
408 return;
410 #ifdef EXTENT_DEBUG
411 printf("io: freeing handle 0x%lx for 0x%lx\n", ioh, iosize);
412 #endif
414 ioaddr = ioh - ALPHA_PHYS_TO_K0SEG(CHIP_IO_SYS_START(v));
416 #ifdef EXTENT_DEBUG
417 printf("io: freeing 0x%lx to 0x%lx\n", ioaddr, ioaddr + iosize - 1);
418 #endif
419 error = extent_free(CHIP_IO_EXTENT(v), ioaddr, iosize,
420 EX_NOWAIT | (CHIP_EX_MALLOC_SAFE(v) ? EX_MALLOCOK : 0));
421 if (error) {
422 printf("%s: WARNING: could not unmap 0x%lx-0x%lx (error %d)\n",
423 __S(__C(CHIP,_io_unmap)), ioaddr, ioaddr + iosize - 1,
424 error);
425 #ifdef EXTENT_DEBUG
426 extent_print(CHIP_IO_EXTENT(v));
427 #endif
432 __C(CHIP,_io_subregion)(v, ioh, offset, size, nioh)
433 void *v;
434 bus_space_handle_t ioh, *nioh;
435 bus_size_t offset, size;
438 *nioh = ioh + offset;
439 return (0);
443 __C(CHIP,_io_alloc)(v, rstart, rend, size, align, boundary, flags,
444 addrp, bshp)
445 void *v;
446 bus_addr_t rstart, rend, *addrp;
447 bus_size_t size, align, boundary;
448 int flags;
449 bus_space_handle_t *bshp;
451 struct alpha_bus_space_translation abst;
452 int linear = flags & BUS_SPACE_MAP_LINEAR;
453 bus_addr_t ioaddr;
454 int error;
457 * Can't map i/o space linearly.
459 if (linear)
460 return (EOPNOTSUPP);
463 * Do the requested allocation.
465 #ifdef EXTENT_DEBUG
466 printf("io: allocating from 0x%lx to 0x%lx\n", rstart, rend);
467 #endif
468 error = extent_alloc_subregion(CHIP_IO_EXTENT(v), rstart, rend,
469 size, align, boundary,
470 EX_FAST | EX_NOWAIT | (CHIP_EX_MALLOC_SAFE(v) ? EX_MALLOCOK : 0),
471 &ioaddr);
472 if (error) {
473 #ifdef EXTENT_DEBUG
474 printf("io: allocation failed (%d)\n", error);
475 extent_print(CHIP_IO_EXTENT(v));
476 #endif
477 return (error);
480 #ifdef EXTENT_DEBUG
481 printf("io: allocated 0x%lx to 0x%lx\n", ioaddr, ioaddr + size - 1);
482 #endif
484 error = __C(CHIP,_io_translate)(v, ioaddr, size, flags, &abst);
485 if (error) {
486 (void) extent_free(CHIP_IO_EXTENT(v), ioaddr, size,
487 EX_NOWAIT | (CHIP_EX_MALLOC_SAFE(v) ? EX_MALLOCOK : 0));
488 return (error);
491 *addrp = ioaddr;
492 *bshp = ALPHA_PHYS_TO_K0SEG(abst.abst_sys_start + ioaddr);
494 return (0);
497 void
498 __C(CHIP,_io_free)(v, bsh, size)
499 void *v;
500 bus_space_handle_t bsh;
501 bus_size_t size;
504 /* Unmap does all we need to do. */
505 __C(CHIP,_io_unmap)(v, bsh, size, 1);
508 void *
509 __C(CHIP,_io_vaddr)(v, bsh)
510 void *v;
511 bus_space_handle_t bsh;
514 * _io_translate() catches BUS_SPACE_MAP_LINEAR,
515 * so we shouldn't get here
517 panic("_io_vaddr");
520 paddr_t
521 __C(CHIP,_io_mmap)(v, addr, off, prot, flags)
522 void *v;
523 bus_addr_t addr;
524 off_t off;
525 int prot;
526 int flags;
529 /* Not supported for I/O space. */
530 return (-1);
533 inline void
534 __C(CHIP,_io_barrier)(v, h, o, l, f)
535 void *v;
536 bus_space_handle_t h;
537 bus_size_t o, l;
538 int f;
541 if ((f & BUS_SPACE_BARRIER_READ) != 0)
542 alpha_mb();
543 else if ((f & BUS_SPACE_BARRIER_WRITE) != 0)
544 alpha_wmb();
547 inline u_int8_t
548 __C(CHIP,_io_read_1)(v, ioh, off)
549 void *v;
550 bus_space_handle_t ioh;
551 bus_size_t off;
553 bus_addr_t addr;
555 addr = ioh + off;
556 alpha_mb();
557 return (alpha_ldbu((u_int8_t *)addr));
560 inline u_int16_t
561 __C(CHIP,_io_read_2)(v, ioh, off)
562 void *v;
563 bus_space_handle_t ioh;
564 bus_size_t off;
566 bus_addr_t addr;
568 addr = ioh + off;
569 #ifdef DIAGNOSTIC
570 if (addr & 1)
571 panic(__S(__C(CHIP,_io_read_2)) ": addr 0x%lx not aligned",
572 addr);
573 #endif
574 alpha_mb();
575 return (alpha_ldwu((u_int16_t *)addr));
578 inline u_int32_t
579 __C(CHIP,_io_read_4)(v, ioh, off)
580 void *v;
581 bus_space_handle_t ioh;
582 bus_size_t off;
584 bus_addr_t addr;
586 addr = ioh + off;
587 #ifdef DIAGNOSTIC
588 if (addr & 3)
589 panic(__S(__C(CHIP,_io_read_4)) ": addr 0x%lx not aligned",
590 addr);
591 #endif
592 alpha_mb();
593 return (*(u_int32_t *)addr);
596 inline u_int64_t
597 __C(CHIP,_io_read_8)(v, ioh, off)
598 void *v;
599 bus_space_handle_t ioh;
600 bus_size_t off;
603 /* XXX XXX XXX */
604 panic("%s not implemented", __S(__C(CHIP,_io_read_8)));
607 #define CHIP_io_read_multi_N(BYTES,TYPE) \
608 void \
609 __C(__C(CHIP,_io_read_multi_),BYTES)(v, h, o, a, c) \
610 void *v; \
611 bus_space_handle_t h; \
612 bus_size_t o, c; \
613 TYPE *a; \
616 while (c-- > 0) { \
617 __C(CHIP,_io_barrier)(v, h, o, sizeof *a, \
618 BUS_SPACE_BARRIER_READ); \
619 *a++ = __C(__C(CHIP,_io_read_),BYTES)(v, h, o); \
622 CHIP_io_read_multi_N(1,u_int8_t)
623 CHIP_io_read_multi_N(2,u_int16_t)
624 CHIP_io_read_multi_N(4,u_int32_t)
625 CHIP_io_read_multi_N(8,u_int64_t)
627 #define CHIP_io_read_region_N(BYTES,TYPE) \
628 void \
629 __C(__C(CHIP,_io_read_region_),BYTES)(v, h, o, a, c) \
630 void *v; \
631 bus_space_handle_t h; \
632 bus_size_t o, c; \
633 TYPE *a; \
636 while (c-- > 0) { \
637 *a++ = __C(__C(CHIP,_io_read_),BYTES)(v, h, o); \
638 o += sizeof *a; \
641 CHIP_io_read_region_N(1,u_int8_t)
642 CHIP_io_read_region_N(2,u_int16_t)
643 CHIP_io_read_region_N(4,u_int32_t)
644 CHIP_io_read_region_N(8,u_int64_t)
646 inline void
647 __C(CHIP,_io_write_1)(v, ioh, off, val)
648 void *v;
649 bus_space_handle_t ioh;
650 bus_size_t off;
651 u_int8_t val;
653 bus_addr_t addr;
655 addr = ioh + off;
656 alpha_stb((u_int8_t *)addr, val);
657 alpha_mb();
660 inline void
661 __C(CHIP,_io_write_2)(v, ioh, off, val)
662 void *v;
663 bus_space_handle_t ioh;
664 bus_size_t off;
665 u_int16_t val;
667 bus_addr_t addr;
669 addr = ioh + off;
670 #ifdef DIAGNOSTIC
671 if (addr & 1)
672 panic(__S(__C(CHIP,_io_write_2)) ": addr 0x%lx not aligned",
673 addr);
674 #endif
675 alpha_stw((u_int16_t *)addr, val);
676 alpha_mb();
679 inline void
680 __C(CHIP,_io_write_4)(v, ioh, off, val)
681 void *v;
682 bus_space_handle_t ioh;
683 bus_size_t off;
684 u_int32_t val;
686 bus_addr_t addr;
688 addr = ioh + off;
689 #ifdef DIAGNOSTIC
690 if (addr & 3)
691 panic(__S(__C(CHIP,_io_write_4)) ": addr 0x%lx not aligned",
692 addr);
693 #endif
694 *(u_int32_t *)addr = val;
695 alpha_mb();
698 inline void
699 __C(CHIP,_io_write_8)(v, ioh, off, val)
700 void *v;
701 bus_space_handle_t ioh;
702 bus_size_t off;
703 u_int64_t val;
706 /* XXX XXX XXX */
707 panic("%s not implemented", __S(__C(CHIP,_io_write_8)));
708 alpha_mb();
711 #define CHIP_io_write_multi_N(BYTES,TYPE) \
712 void \
713 __C(__C(CHIP,_io_write_multi_),BYTES)(v, h, o, a, c) \
714 void *v; \
715 bus_space_handle_t h; \
716 bus_size_t o, c; \
717 const TYPE *a; \
720 while (c-- > 0) { \
721 __C(__C(CHIP,_io_write_),BYTES)(v, h, o, *a++); \
722 __C(CHIP,_io_barrier)(v, h, o, sizeof *a, \
723 BUS_SPACE_BARRIER_WRITE); \
726 CHIP_io_write_multi_N(1,u_int8_t)
727 CHIP_io_write_multi_N(2,u_int16_t)
728 CHIP_io_write_multi_N(4,u_int32_t)
729 CHIP_io_write_multi_N(8,u_int64_t)
731 #define CHIP_io_write_region_N(BYTES,TYPE) \
732 void \
733 __C(__C(CHIP,_io_write_region_),BYTES)(v, h, o, a, c) \
734 void *v; \
735 bus_space_handle_t h; \
736 bus_size_t o, c; \
737 const TYPE *a; \
740 while (c-- > 0) { \
741 __C(__C(CHIP,_io_write_),BYTES)(v, h, o, *a++); \
742 o += sizeof *a; \
745 CHIP_io_write_region_N(1,u_int8_t)
746 CHIP_io_write_region_N(2,u_int16_t)
747 CHIP_io_write_region_N(4,u_int32_t)
748 CHIP_io_write_region_N(8,u_int64_t)
750 #define CHIP_io_set_multi_N(BYTES,TYPE) \
751 void \
752 __C(__C(CHIP,_io_set_multi_),BYTES)(v, h, o, val, c) \
753 void *v; \
754 bus_space_handle_t h; \
755 bus_size_t o, c; \
756 TYPE val; \
759 while (c-- > 0) { \
760 __C(__C(CHIP,_io_write_),BYTES)(v, h, o, val); \
761 __C(CHIP,_io_barrier)(v, h, o, sizeof val, \
762 BUS_SPACE_BARRIER_WRITE); \
765 CHIP_io_set_multi_N(1,u_int8_t)
766 CHIP_io_set_multi_N(2,u_int16_t)
767 CHIP_io_set_multi_N(4,u_int32_t)
768 CHIP_io_set_multi_N(8,u_int64_t)
770 #define CHIP_io_set_region_N(BYTES,TYPE) \
771 void \
772 __C(__C(CHIP,_io_set_region_),BYTES)(v, h, o, val, c) \
773 void *v; \
774 bus_space_handle_t h; \
775 bus_size_t o, c; \
776 TYPE val; \
779 while (c-- > 0) { \
780 __C(__C(CHIP,_io_write_),BYTES)(v, h, o, val); \
781 o += sizeof val; \
784 CHIP_io_set_region_N(1,u_int8_t)
785 CHIP_io_set_region_N(2,u_int16_t)
786 CHIP_io_set_region_N(4,u_int32_t)
787 CHIP_io_set_region_N(8,u_int64_t)
789 #define CHIP_io_copy_region_N(BYTES) \
790 void \
791 __C(__C(CHIP,_io_copy_region_),BYTES)(v, h1, o1, h2, o2, c) \
792 void *v; \
793 bus_space_handle_t h1, h2; \
794 bus_size_t o1, o2, c; \
796 bus_size_t o; \
798 if ((h1 + o1) >= (h2 + o2)) { \
799 /* src after dest: copy forward */ \
800 for (o = 0; c != 0; c--, o += BYTES) { \
801 __C(__C(CHIP,_io_write_),BYTES)(v, h2, o2 + o, \
802 __C(__C(CHIP,_io_read_),BYTES)(v, h1, o1 + o)); \
804 } else { \
805 /* dest after src: copy backwards */ \
806 for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES) { \
807 __C(__C(CHIP,_io_write_),BYTES)(v, h2, o2 + o, \
808 __C(__C(CHIP,_io_read_),BYTES)(v, h1, o1 + o)); \
812 CHIP_io_copy_region_N(1)
813 CHIP_io_copy_region_N(2)
814 CHIP_io_copy_region_N(4)
815 CHIP_io_copy_region_N(8)