1 /* $NetBSD: pci_bwx_bus_mem_chipdep.c,v 1.21 2008/04/28 20:23:11 martin Exp $ */
4 * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
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
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.
65 * CHIP name of the 'chip' it's being compiled for.
66 * CHIP_MEM_BASE Mem space base to use.
68 * If defined, device-provided static storage area
69 * for the memory space extent. If this is
70 * defined, CHIP_MEM_EX_STORE_SIZE must also be
71 * defined. If this is not defined, a static area
73 * CHIP_MEM_EX_STORE_SIZE
74 * Size of the device-provided static storage area
75 * for the memory space extent.
78 #include <sys/cdefs.h>
79 __KERNEL_RCSID(1, "$NetBSD: pci_bwx_bus_mem_chipdep.c,v 1.21 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
,_mem_map
)(void *, bus_addr_t
, bus_size_t
, int,
90 bus_space_handle_t
*, int);
91 void __C(CHIP
,_mem_unmap
)(void *, bus_space_handle_t
,
93 int __C(CHIP
,_mem_subregion
)(void *, bus_space_handle_t
,
94 bus_size_t
, bus_size_t
, bus_space_handle_t
*);
96 int __C(CHIP
,_mem_translate
)(void *, bus_addr_t
, bus_size_t
,
97 int, struct alpha_bus_space_translation
*);
98 int __C(CHIP
,_mem_get_window
)(void *, int,
99 struct alpha_bus_space_translation
*);
101 /* allocation/deallocation */
102 int __C(CHIP
,_mem_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
,_mem_free
)(void *, bus_space_handle_t
,
108 /* get kernel virtual address */
109 void * __C(CHIP
,_mem_vaddr
)(void *, bus_space_handle_t
);
112 paddr_t
__C(CHIP
,_mem_mmap
)(void *, bus_addr_t
, off_t
, int, int);
115 inline void __C(CHIP
,_mem_barrier
)(void *, bus_space_handle_t
,
116 bus_size_t
, bus_size_t
, int);
119 inline u_int8_t
__C(CHIP
,_mem_read_1
)(void *, bus_space_handle_t
,
121 inline u_int16_t
__C(CHIP
,_mem_read_2
)(void *, bus_space_handle_t
,
123 inline u_int32_t
__C(CHIP
,_mem_read_4
)(void *, bus_space_handle_t
,
125 inline u_int64_t
__C(CHIP
,_mem_read_8
)(void *, bus_space_handle_t
,
129 void __C(CHIP
,_mem_read_multi_1
)(void *, bus_space_handle_t
,
130 bus_size_t
, u_int8_t
*, bus_size_t
);
131 void __C(CHIP
,_mem_read_multi_2
)(void *, bus_space_handle_t
,
132 bus_size_t
, u_int16_t
*, bus_size_t
);
133 void __C(CHIP
,_mem_read_multi_4
)(void *, bus_space_handle_t
,
134 bus_size_t
, u_int32_t
*, bus_size_t
);
135 void __C(CHIP
,_mem_read_multi_8
)(void *, bus_space_handle_t
,
136 bus_size_t
, u_int64_t
*, bus_size_t
);
139 void __C(CHIP
,_mem_read_region_1
)(void *, bus_space_handle_t
,
140 bus_size_t
, u_int8_t
*, bus_size_t
);
141 void __C(CHIP
,_mem_read_region_2
)(void *, bus_space_handle_t
,
142 bus_size_t
, u_int16_t
*, bus_size_t
);
143 void __C(CHIP
,_mem_read_region_4
)(void *, bus_space_handle_t
,
144 bus_size_t
, u_int32_t
*, bus_size_t
);
145 void __C(CHIP
,_mem_read_region_8
)(void *, bus_space_handle_t
,
146 bus_size_t
, u_int64_t
*, bus_size_t
);
149 inline void __C(CHIP
,_mem_write_1
)(void *, bus_space_handle_t
,
150 bus_size_t
, u_int8_t
);
151 inline void __C(CHIP
,_mem_write_2
)(void *, bus_space_handle_t
,
152 bus_size_t
, u_int16_t
);
153 inline void __C(CHIP
,_mem_write_4
)(void *, bus_space_handle_t
,
154 bus_size_t
, u_int32_t
);
155 inline void __C(CHIP
,_mem_write_8
)(void *, bus_space_handle_t
,
156 bus_size_t
, u_int64_t
);
159 void __C(CHIP
,_mem_write_multi_1
)(void *, bus_space_handle_t
,
160 bus_size_t
, const u_int8_t
*, bus_size_t
);
161 void __C(CHIP
,_mem_write_multi_2
)(void *, bus_space_handle_t
,
162 bus_size_t
, const u_int16_t
*, bus_size_t
);
163 void __C(CHIP
,_mem_write_multi_4
)(void *, bus_space_handle_t
,
164 bus_size_t
, const u_int32_t
*, bus_size_t
);
165 void __C(CHIP
,_mem_write_multi_8
)(void *, bus_space_handle_t
,
166 bus_size_t
, const u_int64_t
*, bus_size_t
);
169 void __C(CHIP
,_mem_write_region_1
)(void *, bus_space_handle_t
,
170 bus_size_t
, const u_int8_t
*, bus_size_t
);
171 void __C(CHIP
,_mem_write_region_2
)(void *, bus_space_handle_t
,
172 bus_size_t
, const u_int16_t
*, bus_size_t
);
173 void __C(CHIP
,_mem_write_region_4
)(void *, bus_space_handle_t
,
174 bus_size_t
, const u_int32_t
*, bus_size_t
);
175 void __C(CHIP
,_mem_write_region_8
)(void *, bus_space_handle_t
,
176 bus_size_t
, const u_int64_t
*, bus_size_t
);
179 void __C(CHIP
,_mem_set_multi_1
)(void *, bus_space_handle_t
,
180 bus_size_t
, u_int8_t
, bus_size_t
);
181 void __C(CHIP
,_mem_set_multi_2
)(void *, bus_space_handle_t
,
182 bus_size_t
, u_int16_t
, bus_size_t
);
183 void __C(CHIP
,_mem_set_multi_4
)(void *, bus_space_handle_t
,
184 bus_size_t
, u_int32_t
, bus_size_t
);
185 void __C(CHIP
,_mem_set_multi_8
)(void *, bus_space_handle_t
,
186 bus_size_t
, u_int64_t
, bus_size_t
);
189 void __C(CHIP
,_mem_set_region_1
)(void *, bus_space_handle_t
,
190 bus_size_t
, u_int8_t
, bus_size_t
);
191 void __C(CHIP
,_mem_set_region_2
)(void *, bus_space_handle_t
,
192 bus_size_t
, u_int16_t
, bus_size_t
);
193 void __C(CHIP
,_mem_set_region_4
)(void *, bus_space_handle_t
,
194 bus_size_t
, u_int32_t
, bus_size_t
);
195 void __C(CHIP
,_mem_set_region_8
)(void *, bus_space_handle_t
,
196 bus_size_t
, u_int64_t
, bus_size_t
);
199 void __C(CHIP
,_mem_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
,_mem_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
,_mem_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
,_mem_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_MEM_EX_STORE
210 __C(CHIP
,_mem_ex_storage
)[EXTENT_FIXED_STORAGE_SIZE(8) / sizeof(long)];
211 #define CHIP_MEM_EX_STORE(v) (__C(CHIP,_mem_ex_storage))
212 #define CHIP_MEM_EX_STORE_SIZE(v) (sizeof __C(CHIP,_mem_ex_storage))
216 __C(CHIP
,_bus_mem_init
)(t
, v
)
223 * Initialize the bus space tag.
229 /* mapping/unmapping */
230 t
->abs_map
= __C(CHIP
,_mem_map
);
231 t
->abs_unmap
= __C(CHIP
,_mem_unmap
);
232 t
->abs_subregion
= __C(CHIP
,_mem_subregion
);
234 t
->abs_translate
= __C(CHIP
,_mem_translate
);
235 t
->abs_get_window
= __C(CHIP
,_mem_get_window
);
237 /* allocation/deallocation */
238 t
->abs_alloc
= __C(CHIP
,_mem_alloc
);
239 t
->abs_free
= __C(CHIP
,_mem_free
);
241 /* get kernel virtual address */
242 t
->abs_vaddr
= __C(CHIP
,_mem_vaddr
);
245 t
->abs_mmap
= __C(CHIP
,_mem_mmap
);
248 t
->abs_barrier
= __C(CHIP
,_mem_barrier
);
251 t
->abs_r_1
= __C(CHIP
,_mem_read_1
);
252 t
->abs_r_2
= __C(CHIP
,_mem_read_2
);
253 t
->abs_r_4
= __C(CHIP
,_mem_read_4
);
254 t
->abs_r_8
= __C(CHIP
,_mem_read_8
);
257 t
->abs_rm_1
= __C(CHIP
,_mem_read_multi_1
);
258 t
->abs_rm_2
= __C(CHIP
,_mem_read_multi_2
);
259 t
->abs_rm_4
= __C(CHIP
,_mem_read_multi_4
);
260 t
->abs_rm_8
= __C(CHIP
,_mem_read_multi_8
);
263 t
->abs_rr_1
= __C(CHIP
,_mem_read_region_1
);
264 t
->abs_rr_2
= __C(CHIP
,_mem_read_region_2
);
265 t
->abs_rr_4
= __C(CHIP
,_mem_read_region_4
);
266 t
->abs_rr_8
= __C(CHIP
,_mem_read_region_8
);
269 t
->abs_w_1
= __C(CHIP
,_mem_write_1
);
270 t
->abs_w_2
= __C(CHIP
,_mem_write_2
);
271 t
->abs_w_4
= __C(CHIP
,_mem_write_4
);
272 t
->abs_w_8
= __C(CHIP
,_mem_write_8
);
275 t
->abs_wm_1
= __C(CHIP
,_mem_write_multi_1
);
276 t
->abs_wm_2
= __C(CHIP
,_mem_write_multi_2
);
277 t
->abs_wm_4
= __C(CHIP
,_mem_write_multi_4
);
278 t
->abs_wm_8
= __C(CHIP
,_mem_write_multi_8
);
281 t
->abs_wr_1
= __C(CHIP
,_mem_write_region_1
);
282 t
->abs_wr_2
= __C(CHIP
,_mem_write_region_2
);
283 t
->abs_wr_4
= __C(CHIP
,_mem_write_region_4
);
284 t
->abs_wr_8
= __C(CHIP
,_mem_write_region_8
);
287 t
->abs_sm_1
= __C(CHIP
,_mem_set_multi_1
);
288 t
->abs_sm_2
= __C(CHIP
,_mem_set_multi_2
);
289 t
->abs_sm_4
= __C(CHIP
,_mem_set_multi_4
);
290 t
->abs_sm_8
= __C(CHIP
,_mem_set_multi_8
);
293 t
->abs_sr_1
= __C(CHIP
,_mem_set_region_1
);
294 t
->abs_sr_2
= __C(CHIP
,_mem_set_region_2
);
295 t
->abs_sr_4
= __C(CHIP
,_mem_set_region_4
);
296 t
->abs_sr_8
= __C(CHIP
,_mem_set_region_8
);
299 t
->abs_c_1
= __C(CHIP
,_mem_copy_region_1
);
300 t
->abs_c_2
= __C(CHIP
,_mem_copy_region_2
);
301 t
->abs_c_4
= __C(CHIP
,_mem_copy_region_4
);
302 t
->abs_c_8
= __C(CHIP
,_mem_copy_region_8
);
304 ex
= extent_create(__S(__C(CHIP
,_bus_mem
)), 0x0UL
, 0xffffffffUL
,
305 M_DEVBUF
, (void *)CHIP_MEM_EX_STORE(v
), CHIP_MEM_EX_STORE_SIZE(v
),
306 EX_NOWAIT
|EX_NOCOALESCE
);
308 CHIP_MEM_EXTENT(v
) = ex
;
312 __C(CHIP
,_mem_translate
)(v
, memaddr
, memlen
, flags
, abst
)
317 struct alpha_bus_space_translation
*abst
;
325 __C(CHIP
,_mem_get_window
)(v
, window
, abst
)
328 struct alpha_bus_space_translation
*abst
;
333 abst
->abst_bus_start
= 0;
334 abst
->abst_bus_end
= 0xffffffffUL
;
335 abst
->abst_sys_start
= CHIP_MEM_SYS_START(v
);
336 abst
->abst_sys_end
= CHIP_MEM_SYS_START(v
) + abst
->abst_bus_end
;
337 abst
->abst_addr_shift
= 0;
338 abst
->abst_size_shift
= 0;
339 abst
->abst_flags
= ABST_DENSE
|ABST_BWX
;
343 panic(__S(__C(CHIP
,_mem_get_window
)) ": invalid window %d",
351 __C(CHIP
,_mem_map
)(v
, memaddr
, memsize
, flags
, memhp
, acct
)
356 bus_space_handle_t
*memhp
;
365 printf("mem: allocating 0x%lx to 0x%lx\n", memaddr
,
366 memaddr
+ memsize
- 1);
368 error
= extent_alloc_region(CHIP_MEM_EXTENT(v
), memaddr
, memsize
,
369 EX_NOWAIT
| (CHIP_EX_MALLOC_SAFE(v
) ? EX_MALLOCOK
: 0));
372 printf("mem: allocation failed (%d)\n", error
);
373 extent_print(CHIP_MEM_EXTENT(v
));
379 *memhp
= ALPHA_PHYS_TO_K0SEG(CHIP_MEM_SYS_START(v
)) + memaddr
;
385 __C(CHIP
,_mem_unmap
)(v
, memh
, memsize
, acct
)
387 bus_space_handle_t memh
;
398 printf("mem: freeing handle 0x%lx for 0x%lx\n", memh
, memsize
);
401 memaddr
= memh
- ALPHA_PHYS_TO_K0SEG(CHIP_MEM_SYS_START(v
));
404 printf("mem: freeing 0x%lx to 0x%lx\n", memaddr
, memaddr
+ memsize
- 1);
407 error
= extent_free(CHIP_MEM_EXTENT(v
), memaddr
, memsize
,
408 EX_NOWAIT
| (CHIP_EX_MALLOC_SAFE(v
) ? EX_MALLOCOK
: 0));
410 printf("%s: WARNING: could not unmap 0x%lx-0x%lx (error %d)\n",
411 __S(__C(CHIP
,_mem_unmap
)), memaddr
, memaddr
+ memsize
- 1,
414 extent_print(CHIP_MEM_EXTENT(v
));
420 __C(CHIP
,_mem_subregion
)(v
, memh
, offset
, size
, nmemh
)
422 bus_space_handle_t memh
, *nmemh
;
423 bus_size_t offset
, size
;
426 *nmemh
= memh
+ offset
;
431 __C(CHIP
,_mem_alloc
)(v
, rstart
, rend
, size
, align
, boundary
, flags
,
434 bus_addr_t rstart
, rend
, *addrp
;
435 bus_size_t size
, align
, boundary
;
437 bus_space_handle_t
*bshp
;
443 * Do the requested allocation.
446 printf("mem: allocating from 0x%lx to 0x%lx\n", rstart
, rend
);
448 error
= extent_alloc_subregion(CHIP_MEM_EXTENT(v
), rstart
, rend
,
449 size
, align
, boundary
,
450 EX_FAST
| EX_NOWAIT
| (CHIP_EX_MALLOC_SAFE(v
) ? EX_MALLOCOK
: 0),
454 printf("mem: allocation failed (%d)\n", error
);
455 extent_print(CHIP_MEM_EXTENT(v
));
460 printf("mem: allocated 0x%lx to 0x%lx\n", memaddr
, memaddr
+ size
- 1);
464 *bshp
= ALPHA_PHYS_TO_K0SEG(CHIP_MEM_SYS_START(v
)) + memaddr
;
470 __C(CHIP
,_mem_free
)(v
, bsh
, size
)
472 bus_space_handle_t bsh
;
476 /* Unmap does all we need to do. */
477 __C(CHIP
,_mem_unmap
)(v
, bsh
, size
, 1);
481 __C(CHIP
,_mem_vaddr
)(v
, bsh
)
483 bus_space_handle_t bsh
;
486 return ((void *)bsh
);
490 __C(CHIP
,_mem_mmap
)(v
, addr
, off
, prot
, flags
)
498 return (alpha_btop(CHIP_MEM_SYS_START(v
) + addr
+ off
));
502 __C(CHIP
,_mem_barrier
)(v
, h
, o
, l
, f
)
504 bus_space_handle_t h
;
509 if ((f
& BUS_SPACE_BARRIER_READ
) != 0)
511 else if ((f
& BUS_SPACE_BARRIER_WRITE
) != 0)
516 __C(CHIP
,_mem_read_1
)(v
, memh
, off
)
518 bus_space_handle_t memh
;
525 return (alpha_ldbu((u_int8_t
*)addr
));
529 __C(CHIP
,_mem_read_2
)(v
, memh
, off
)
531 bus_space_handle_t memh
;
539 panic(__S(__C(CHIP
,_mem_read_2
)) ": addr 0x%lx not aligned",
543 return (alpha_ldwu((u_int16_t
*)addr
));
547 __C(CHIP
,_mem_read_4
)(v
, memh
, off
)
549 bus_space_handle_t memh
;
557 panic(__S(__C(CHIP
,_mem_read_4
)) ": addr 0x%lx not aligned",
561 return (*(u_int32_t
*)addr
);
565 __C(CHIP
,_mem_read_8
)(v
, memh
, off
)
567 bus_space_handle_t memh
;
574 panic("%s not implemented", __S(__C(CHIP
,_mem_read_8
)));
577 #define CHIP_mem_read_multi_N(BYTES,TYPE) \
579 __C(__C(CHIP,_mem_read_multi_),BYTES)(v, h, o, a, c) \
581 bus_space_handle_t h; \
587 __C(CHIP,_mem_barrier)(v, h, o, sizeof *a, \
588 BUS_SPACE_BARRIER_READ); \
589 *a++ = __C(__C(CHIP,_mem_read_),BYTES)(v, h, o); \
592 CHIP_mem_read_multi_N(1,u_int8_t
)
593 CHIP_mem_read_multi_N(2,u_int16_t
)
594 CHIP_mem_read_multi_N(4,u_int32_t
)
595 CHIP_mem_read_multi_N(8,u_int64_t
)
597 #define CHIP_mem_read_region_N(BYTES,TYPE) \
599 __C(__C(CHIP,_mem_read_region_),BYTES)(v, h, o, a, c) \
601 bus_space_handle_t h; \
607 *a++ = __C(__C(CHIP,_mem_read_),BYTES)(v, h, o); \
611 CHIP_mem_read_region_N(1,u_int8_t
)
612 CHIP_mem_read_region_N(2,u_int16_t
)
613 CHIP_mem_read_region_N(4,u_int32_t
)
614 CHIP_mem_read_region_N(8,u_int64_t
)
617 __C(CHIP
,_mem_write_1
)(v
, memh
, off
, val
)
619 bus_space_handle_t memh
;
626 alpha_stb((u_int8_t
*)addr
, val
);
631 __C(CHIP
,_mem_write_2
)(v
, memh
, off
, val
)
633 bus_space_handle_t memh
;
642 panic(__S(__C(CHIP
,_mem_write_2
)) ": addr 0x%lx not aligned",
645 alpha_stw((u_int16_t
*)addr
, val
);
650 __C(CHIP
,_mem_write_4
)(v
, memh
, off
, val
)
652 bus_space_handle_t memh
;
661 panic(__S(__C(CHIP
,_mem_write_4
)) ": addr 0x%lx not aligned",
664 *(u_int32_t
*)addr
= val
;
669 __C(CHIP
,_mem_write_8
)(v
, memh
, off
, val
)
671 bus_space_handle_t memh
;
677 panic("%s not implemented", __S(__C(CHIP
,_mem_write_8
)));
681 #define CHIP_mem_write_multi_N(BYTES,TYPE) \
683 __C(__C(CHIP,_mem_write_multi_),BYTES)(v, h, o, a, c) \
685 bus_space_handle_t h; \
691 __C(__C(CHIP,_mem_write_),BYTES)(v, h, o, *a++); \
692 __C(CHIP,_mem_barrier)(v, h, o, sizeof *a, \
693 BUS_SPACE_BARRIER_WRITE); \
696 CHIP_mem_write_multi_N(1,u_int8_t
)
697 CHIP_mem_write_multi_N(2,u_int16_t
)
698 CHIP_mem_write_multi_N(4,u_int32_t
)
699 CHIP_mem_write_multi_N(8,u_int64_t
)
701 #define CHIP_mem_write_region_N(BYTES,TYPE) \
703 __C(__C(CHIP,_mem_write_region_),BYTES)(v, h, o, a, c) \
705 bus_space_handle_t h; \
711 __C(__C(CHIP,_mem_write_),BYTES)(v, h, o, *a++); \
715 CHIP_mem_write_region_N(1,u_int8_t
)
716 CHIP_mem_write_region_N(2,u_int16_t
)
717 CHIP_mem_write_region_N(4,u_int32_t
)
718 CHIP_mem_write_region_N(8,u_int64_t
)
720 #define CHIP_mem_set_multi_N(BYTES,TYPE) \
722 __C(__C(CHIP,_mem_set_multi_),BYTES)(v, h, o, val, c) \
724 bus_space_handle_t h; \
730 __C(__C(CHIP,_mem_write_),BYTES)(v, h, o, val); \
731 __C(CHIP,_mem_barrier)(v, h, o, sizeof val, \
732 BUS_SPACE_BARRIER_WRITE); \
735 CHIP_mem_set_multi_N(1,u_int8_t
)
736 CHIP_mem_set_multi_N(2,u_int16_t
)
737 CHIP_mem_set_multi_N(4,u_int32_t
)
738 CHIP_mem_set_multi_N(8,u_int64_t
)
740 #define CHIP_mem_set_region_N(BYTES,TYPE) \
742 __C(__C(CHIP,_mem_set_region_),BYTES)(v, h, o, val, c) \
744 bus_space_handle_t h; \
750 __C(__C(CHIP,_mem_write_),BYTES)(v, h, o, val); \
754 CHIP_mem_set_region_N(1,u_int8_t
)
755 CHIP_mem_set_region_N(2,u_int16_t
)
756 CHIP_mem_set_region_N(4,u_int32_t
)
757 CHIP_mem_set_region_N(8,u_int64_t
)
759 #define CHIP_mem_copy_region_N(BYTES) \
761 __C(__C(CHIP,_mem_copy_region_),BYTES)(v, h1, o1, h2, o2, c) \
763 bus_space_handle_t h1, h2; \
764 bus_size_t o1, o2, c; \
768 if ((h1 + o1) >= (h2 + o2)) { \
769 /* src after dest: copy forward */ \
770 for (o = 0; c != 0; c--, o += BYTES) { \
771 __C(__C(CHIP,_mem_write_),BYTES)(v, h2, o2 + o, \
772 __C(__C(CHIP,_mem_read_),BYTES)(v, h1, o1 + o)); \
775 /* dest after src: copy backwards */ \
776 for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES) { \
777 __C(__C(CHIP,_mem_write_),BYTES)(v, h2, o2 + o, \
778 __C(__C(CHIP,_mem_read_),BYTES)(v, h1, o1 + o)); \
782 CHIP_mem_copy_region_N(1)
783 CHIP_mem_copy_region_N(2)
784 CHIP_mem_copy_region_N(4)
785 CHIP_mem_copy_region_N(8)