1 /* $NetBSD: pci_alignstride_bus_io_chipdep.c,v 1.8 2008/04/28 20:23:10 martin Exp $ */
4 * Copyright (c) 1998, 2000, 2001 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_IO_BASE Sparse I/O space base to use.
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
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_alignstride_bus_io_chipdep.c,v 1.8 2008/04/28 20:23:10 martin Exp $");
81 #include <sys/extent.h>
83 #define __C(A,B) __CONCAT(A,B)
84 #define __S(S) __STRING(S)
86 /* mapping/unmapping */
87 int __C(CHIP
,_io_map
)(void *, bus_addr_t
, bus_size_t
, int,
88 bus_space_handle_t
*, int);
89 void __C(CHIP
,_io_unmap
)(void *, bus_space_handle_t
,
91 int __C(CHIP
,_io_subregion
)(void *, bus_space_handle_t
,
92 bus_size_t
, bus_size_t
, bus_space_handle_t
*);
94 int __C(CHIP
,_io_translate
)(void *, bus_addr_t
, bus_size_t
,
95 int, struct mips_bus_space_translation
*);
96 int __C(CHIP
,_io_get_window
)(void *, int,
97 struct mips_bus_space_translation
*);
99 /* allocation/deallocation */
100 int __C(CHIP
,_io_alloc
)(void *, bus_addr_t
, bus_addr_t
,
101 bus_size_t
, bus_size_t
, bus_addr_t
, int, bus_addr_t
*,
102 bus_space_handle_t
*);
103 void __C(CHIP
,_io_free
)(void *, bus_space_handle_t
,
106 /* get kernel virtual address */
107 void * __C(CHIP
,_io_vaddr
)(void *, bus_space_handle_t
);
110 paddr_t
__C(CHIP
,_io_mmap
)(void *, bus_addr_t
, off_t
, int, int);
113 inline void __C(CHIP
,_io_barrier
)(void *, bus_space_handle_t
,
114 bus_size_t
, bus_size_t
, int);
117 inline u_int8_t
__C(CHIP
,_io_read_1
)(void *, bus_space_handle_t
,
119 inline u_int16_t
__C(CHIP
,_io_read_2
)(void *, bus_space_handle_t
,
121 inline u_int32_t
__C(CHIP
,_io_read_4
)(void *, bus_space_handle_t
,
123 inline u_int64_t
__C(CHIP
,_io_read_8
)(void *, bus_space_handle_t
,
127 void __C(CHIP
,_io_read_multi_1
)(void *, bus_space_handle_t
,
128 bus_size_t
, u_int8_t
*, bus_size_t
);
129 void __C(CHIP
,_io_read_multi_2
)(void *, bus_space_handle_t
,
130 bus_size_t
, u_int16_t
*, bus_size_t
);
131 void __C(CHIP
,_io_read_multi_4
)(void *, bus_space_handle_t
,
132 bus_size_t
, u_int32_t
*, bus_size_t
);
133 void __C(CHIP
,_io_read_multi_8
)(void *, bus_space_handle_t
,
134 bus_size_t
, u_int64_t
*, bus_size_t
);
137 void __C(CHIP
,_io_read_region_1
)(void *, bus_space_handle_t
,
138 bus_size_t
, u_int8_t
*, bus_size_t
);
139 void __C(CHIP
,_io_read_region_2
)(void *, bus_space_handle_t
,
140 bus_size_t
, u_int16_t
*, bus_size_t
);
141 void __C(CHIP
,_io_read_region_4
)(void *, bus_space_handle_t
,
142 bus_size_t
, u_int32_t
*, bus_size_t
);
143 void __C(CHIP
,_io_read_region_8
)(void *, bus_space_handle_t
,
144 bus_size_t
, u_int64_t
*, bus_size_t
);
147 inline void __C(CHIP
,_io_write_1
)(void *, bus_space_handle_t
,
148 bus_size_t
, u_int8_t
);
149 inline void __C(CHIP
,_io_write_2
)(void *, bus_space_handle_t
,
150 bus_size_t
, u_int16_t
);
151 inline void __C(CHIP
,_io_write_4
)(void *, bus_space_handle_t
,
152 bus_size_t
, u_int32_t
);
153 inline void __C(CHIP
,_io_write_8
)(void *, bus_space_handle_t
,
154 bus_size_t
, u_int64_t
);
157 void __C(CHIP
,_io_write_multi_1
)(void *, bus_space_handle_t
,
158 bus_size_t
, const u_int8_t
*, bus_size_t
);
159 void __C(CHIP
,_io_write_multi_2
)(void *, bus_space_handle_t
,
160 bus_size_t
, const u_int16_t
*, bus_size_t
);
161 void __C(CHIP
,_io_write_multi_4
)(void *, bus_space_handle_t
,
162 bus_size_t
, const u_int32_t
*, bus_size_t
);
163 void __C(CHIP
,_io_write_multi_8
)(void *, bus_space_handle_t
,
164 bus_size_t
, const u_int64_t
*, bus_size_t
);
167 void __C(CHIP
,_io_write_region_1
)(void *, bus_space_handle_t
,
168 bus_size_t
, const u_int8_t
*, bus_size_t
);
169 void __C(CHIP
,_io_write_region_2
)(void *, bus_space_handle_t
,
170 bus_size_t
, const u_int16_t
*, bus_size_t
);
171 void __C(CHIP
,_io_write_region_4
)(void *, bus_space_handle_t
,
172 bus_size_t
, const u_int32_t
*, bus_size_t
);
173 void __C(CHIP
,_io_write_region_8
)(void *, bus_space_handle_t
,
174 bus_size_t
, const u_int64_t
*, bus_size_t
);
177 void __C(CHIP
,_io_set_multi_1
)(void *, bus_space_handle_t
,
178 bus_size_t
, u_int8_t
, bus_size_t
);
179 void __C(CHIP
,_io_set_multi_2
)(void *, bus_space_handle_t
,
180 bus_size_t
, u_int16_t
, bus_size_t
);
181 void __C(CHIP
,_io_set_multi_4
)(void *, bus_space_handle_t
,
182 bus_size_t
, u_int32_t
, bus_size_t
);
183 void __C(CHIP
,_io_set_multi_8
)(void *, bus_space_handle_t
,
184 bus_size_t
, u_int64_t
, bus_size_t
);
187 void __C(CHIP
,_io_set_region_1
)(void *, bus_space_handle_t
,
188 bus_size_t
, u_int8_t
, bus_size_t
);
189 void __C(CHIP
,_io_set_region_2
)(void *, bus_space_handle_t
,
190 bus_size_t
, u_int16_t
, bus_size_t
);
191 void __C(CHIP
,_io_set_region_4
)(void *, bus_space_handle_t
,
192 bus_size_t
, u_int32_t
, bus_size_t
);
193 void __C(CHIP
,_io_set_region_8
)(void *, bus_space_handle_t
,
194 bus_size_t
, u_int64_t
, bus_size_t
);
197 void __C(CHIP
,_io_copy_region_1
)(void *, bus_space_handle_t
,
198 bus_size_t
, bus_space_handle_t
, bus_size_t
, bus_size_t
);
199 void __C(CHIP
,_io_copy_region_2
)(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_4
)(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_8
)(void *, bus_space_handle_t
,
204 bus_size_t
, bus_space_handle_t
, bus_size_t
, bus_size_t
);
206 #ifdef CHIP_IO_EXTENT
207 #ifndef CHIP_IO_EX_STORE
209 __C(CHIP
,_io_ex_storage
)[EXTENT_FIXED_STORAGE_SIZE(8) / sizeof(long)];
210 #define CHIP_IO_EX_STORE(v) (__C(CHIP, _io_ex_storage))
211 #define CHIP_IO_EX_STORE_SIZE(v) (sizeof __C(CHIP, _io_ex_storage))
213 #endif /* CHIP_IO_EXTENT */
215 #ifndef CHIP_ALIGN_STRIDE
216 #define CHIP_ALIGN_STRIDE 0
220 __C(CHIP
,_bus_io_init
)(t
, v
)
224 #ifdef CHIP_IO_EXTENT
229 * Initialize the bus space tag.
235 /* mapping/unmapping */
236 t
->bs_map
= __C(CHIP
,_io_map
);
237 t
->bs_unmap
= __C(CHIP
,_io_unmap
);
238 t
->bs_subregion
= __C(CHIP
,_io_subregion
);
240 t
->bs_translate
= __C(CHIP
,_io_translate
);
241 t
->bs_get_window
= __C(CHIP
,_io_get_window
);
243 /* allocation/deallocation */
244 t
->bs_alloc
= __C(CHIP
,_io_alloc
);
245 t
->bs_free
= __C(CHIP
,_io_free
);
247 /* get kernel virtual address */
248 t
->bs_vaddr
= __C(CHIP
,_io_vaddr
);
251 t
->bs_mmap
= __C(CHIP
,_io_mmap
);
254 t
->bs_barrier
= __C(CHIP
,_io_barrier
);
257 t
->bs_r_1
= __C(CHIP
,_io_read_1
);
258 t
->bs_r_2
= __C(CHIP
,_io_read_2
);
259 t
->bs_r_4
= __C(CHIP
,_io_read_4
);
260 t
->bs_r_8
= __C(CHIP
,_io_read_8
);
263 t
->bs_rm_1
= __C(CHIP
,_io_read_multi_1
);
264 t
->bs_rm_2
= __C(CHIP
,_io_read_multi_2
);
265 t
->bs_rm_4
= __C(CHIP
,_io_read_multi_4
);
266 t
->bs_rm_8
= __C(CHIP
,_io_read_multi_8
);
269 t
->bs_rr_1
= __C(CHIP
,_io_read_region_1
);
270 t
->bs_rr_2
= __C(CHIP
,_io_read_region_2
);
271 t
->bs_rr_4
= __C(CHIP
,_io_read_region_4
);
272 t
->bs_rr_8
= __C(CHIP
,_io_read_region_8
);
275 t
->bs_w_1
= __C(CHIP
,_io_write_1
);
276 t
->bs_w_2
= __C(CHIP
,_io_write_2
);
277 t
->bs_w_4
= __C(CHIP
,_io_write_4
);
278 t
->bs_w_8
= __C(CHIP
,_io_write_8
);
281 t
->bs_wm_1
= __C(CHIP
,_io_write_multi_1
);
282 t
->bs_wm_2
= __C(CHIP
,_io_write_multi_2
);
283 t
->bs_wm_4
= __C(CHIP
,_io_write_multi_4
);
284 t
->bs_wm_8
= __C(CHIP
,_io_write_multi_8
);
287 t
->bs_wr_1
= __C(CHIP
,_io_write_region_1
);
288 t
->bs_wr_2
= __C(CHIP
,_io_write_region_2
);
289 t
->bs_wr_4
= __C(CHIP
,_io_write_region_4
);
290 t
->bs_wr_8
= __C(CHIP
,_io_write_region_8
);
293 t
->bs_sm_1
= __C(CHIP
,_io_set_multi_1
);
294 t
->bs_sm_2
= __C(CHIP
,_io_set_multi_2
);
295 t
->bs_sm_4
= __C(CHIP
,_io_set_multi_4
);
296 t
->bs_sm_8
= __C(CHIP
,_io_set_multi_8
);
299 t
->bs_sr_1
= __C(CHIP
,_io_set_region_1
);
300 t
->bs_sr_2
= __C(CHIP
,_io_set_region_2
);
301 t
->bs_sr_4
= __C(CHIP
,_io_set_region_4
);
302 t
->bs_sr_8
= __C(CHIP
,_io_set_region_8
);
305 t
->bs_c_1
= __C(CHIP
,_io_copy_region_1
);
306 t
->bs_c_2
= __C(CHIP
,_io_copy_region_2
);
307 t
->bs_c_4
= __C(CHIP
,_io_copy_region_4
);
308 t
->bs_c_8
= __C(CHIP
,_io_copy_region_8
);
310 #ifdef CHIP_IO_EXTENT
311 /* XXX WE WANT EXTENT_NOCOALESCE, BUT WE CAN'T USE IT. XXX */
312 ex
= extent_create(__S(__C(CHIP
,_bus_io
)), 0x0UL
, 0xffffffffUL
,
313 M_DEVBUF
, (void *)CHIP_IO_EX_STORE(v
), CHIP_IO_EX_STORE_SIZE(v
),
315 extent_alloc_region(ex
, 0, 0xffffffffUL
, EX_NOWAIT
);
317 #ifdef CHIP_IO_W1_BUS_START
319 * The window may be disabled. We notice this by seeing
320 * -1 as the bus base address.
322 if (CHIP_IO_W1_BUS_START(v
) == (bus_addr_t
) -1) {
324 printf("io: this space is disabled\n");
330 printf("io: freeing from 0x%lx to 0x%lx\n", CHIP_IO_W1_BUS_START(v
),
331 CHIP_IO_W1_BUS_END(v
));
333 extent_free(ex
, CHIP_IO_W1_BUS_START(v
),
334 CHIP_IO_W1_BUS_END(v
) - CHIP_IO_W1_BUS_START(v
) + 1, EX_NOWAIT
);
336 #ifdef CHIP_IO_W2_BUS_START
338 printf("io: freeing from 0x%lx to 0x%lx\n", CHIP_IO_W2_BUS_START(v
),
339 CHIP_IO_W2_BUS_END(v
));
341 extent_free(ex
, CHIP_IO_W2_BUS_START(v
),
342 CHIP_IO_W2_BUS_END(v
) - CHIP_IO_W2_BUS_START(v
) + 1, EX_NOWAIT
);
348 CHIP_IO_EXTENT(v
) = ex
;
349 #endif /* CHIP_IO_EXTENT */
353 __C(CHIP
,_io_translate
)(v
, ioaddr
, iolen
, flags
, mbst
)
358 struct mips_bus_space_translation
*mbst
;
360 bus_addr_t ioend
= ioaddr
+ (iolen
- 1);
361 int linear
= flags
& BUS_SPACE_MAP_LINEAR
;
364 * Can't map i/o space linearly.
369 #ifdef CHIP_IO_W1_BUS_START
370 if (ioaddr
>= CHIP_IO_W1_BUS_START(v
) &&
371 ioend
<= CHIP_IO_W1_BUS_END(v
))
372 return (__C(CHIP
,_io_get_window
)(v
, 0, mbst
));
375 #ifdef CHIP_IO_W2_BUS_START
376 if (ioaddr
>= CHIP_IO_W2_BUS_START(v
) &&
377 ioend
<= CHIP_IO_W2_BUS_END(v
))
378 return (__C(CHIP
,_io_get_window
)(v
, 1, mbst
));
383 #ifdef CHIP_IO_W1_BUS_START
384 printf("%s: window[1]=0x%lx-0x%lx\n",
385 __S(__C(CHIP
,_io_map
)), CHIP_IO_W1_BUS_START(v
),
386 CHIP_IO_W1_BUS_END(v
));
388 #ifdef CHIP_IO_W2_BUS_START
389 printf("%s: window[2]=0x%lx-0x%lx\n",
390 __S(__C(CHIP
,_io_map
)), CHIP_IO_W2_BUS_START(v
),
391 CHIP_IO_W2_BUS_END(v
));
393 #endif /* EXTENT_DEBUG */
394 /* No translation. */
399 __C(CHIP
,_io_get_window
)(v
, window
, mbst
)
402 struct mips_bus_space_translation
*mbst
;
406 #ifdef CHIP_IO_W1_BUS_START
408 mbst
->mbst_bus_start
= CHIP_IO_W1_BUS_START(v
);
409 mbst
->mbst_bus_end
= CHIP_IO_W1_BUS_END(v
);
410 mbst
->mbst_sys_start
= CHIP_IO_W1_SYS_START(v
);
411 mbst
->mbst_sys_end
= CHIP_IO_W1_SYS_END(v
);
412 mbst
->mbst_align_stride
= CHIP_ALIGN_STRIDE
;
413 mbst
->mbst_flags
= 0;
417 #ifdef CHIP_IO_W2_BUS_START
419 mbst
->mbst_bus_start
= CHIP_IO_W2_BUS_START(v
);
420 mbst
->mbst_bus_end
= CHIP_IO_W2_BUS_END(v
);
421 mbst
->mbst_sys_start
= CHIP_IO_W2_SYS_START(v
);
422 mbst
->mbst_sys_end
= CHIP_IO_W2_SYS_END(v
);
423 mbst
->mbst_align_stride
= CHIP_ALIGN_STRIDE
;
424 mbst
->mbst_flags
= 0;
429 panic(__S(__C(CHIP
,_io_get_window
)) ": invalid window %d",
437 __C(CHIP
,_io_map
)(v
, ioaddr
, iosize
, flags
, iohp
, acct
)
442 bus_space_handle_t
*iohp
;
445 struct mips_bus_space_translation mbst
;
449 * Get the translation for this address.
451 error
= __C(CHIP
,_io_translate
)(v
, ioaddr
, iosize
, flags
, &mbst
);
455 #ifdef CHIP_IO_EXTENT
460 printf("io: allocating 0x%lx to 0x%lx\n", ioaddr
, ioaddr
+ iosize
- 1);
462 error
= extent_alloc_region(CHIP_IO_EXTENT(v
), ioaddr
, iosize
,
463 EX_NOWAIT
| (CHIP_EX_MALLOC_SAFE(v
) ? EX_MALLOCOK
: 0));
466 printf("io: allocation failed (%d)\n", error
);
467 extent_print(CHIP_IO_EXTENT(v
));
473 #endif /* CHIP_IO_EXTENT */
474 if (flags
& BUS_SPACE_MAP_CACHEABLE
)
475 *iohp
= MIPS_PHYS_TO_KSEG0(mbst
.mbst_sys_start
+
476 (ioaddr
- mbst
.mbst_bus_start
));
478 *iohp
= MIPS_PHYS_TO_KSEG1(mbst
.mbst_sys_start
+
479 (ioaddr
- mbst
.mbst_bus_start
));
485 __C(CHIP
,_io_unmap
)(v
, ioh
, iosize
, acct
)
487 bus_space_handle_t ioh
;
491 #ifdef CHIP_IO_EXTENT
499 printf("io: freeing handle 0x%lx for 0x%lx\n", ioh
, iosize
);
502 if (ioh
>= MIPS_KSEG0_START
&& ioh
< MIPS_KSEG1_START
)
503 ioh
= MIPS_KSEG0_TO_PHYS(ioh
);
505 ioh
= MIPS_KSEG1_TO_PHYS(ioh
);
507 #ifdef CHIP_IO_W1_BUS_START
508 if (ioh
>= CHIP_IO_W1_SYS_START(v
) &&
509 ioh
<= CHIP_IO_W1_SYS_END(v
)) {
510 ioaddr
= CHIP_IO_W1_BUS_START(v
) +
511 (ioh
- CHIP_IO_W1_SYS_START(v
));
514 #ifdef CHIP_IO_W2_BUS_START
515 if (ioh
>= CHIP_IO_W2_SYS_START(v
) &&
516 ioh
<= CHIP_IO_W2_SYS_END(v
)) {
517 ioaddr
= CHIP_IO_W2_BUS_START(v
) +
518 (ioh
- CHIP_IO_W2_SYS_START(v
));
523 #ifdef CHIP_IO_W1_BUS_START
524 printf("%s: sys window[1]=0x%lx-0x%lx\n",
525 __S(__C(CHIP
,_io_map
)), CHIP_IO_W1_SYS_START(v
),
526 CHIP_IO_W1_SYS_END(v
));
528 #ifdef CHIP_IO_W2_BUS_START
529 printf("%s: sys window[2]=0x%lx-0x%lx\n",
530 __S(__C(CHIP
,_io_map
)), CHIP_IO_W2_SYS_START(v
),
531 CHIP_IO_W2_SYS_END(v
));
533 panic("%s: don't know how to unmap %lx",
534 __S(__C(CHIP
,_io_unmap
)), ioh
);
538 printf("io: freeing 0x%lx to 0x%lx\n", ioaddr
, ioaddr
+ iosize
- 1);
540 error
= extent_free(CHIP_IO_EXTENT(v
), ioaddr
, iosize
,
541 EX_NOWAIT
| (CHIP_EX_MALLOC_SAFE(v
) ? EX_MALLOCOK
: 0));
543 printf("%s: WARNING: could not unmap 0x%lx-0x%lx (error %d)\n",
544 __S(__C(CHIP
,_io_unmap
)), ioaddr
, ioaddr
+ iosize
- 1,
547 extent_print(CHIP_IO_EXTENT(v
));
550 #endif /* CHIP_IO_EXTENT */
554 __C(CHIP
,_io_subregion
)(v
, ioh
, offset
, size
, nioh
)
556 bus_space_handle_t ioh
, *nioh
;
557 bus_size_t offset
, size
;
560 *nioh
= ioh
+ (offset
<< CHIP_ALIGN_STRIDE
);
565 __C(CHIP
,_io_alloc
)(v
, rstart
, rend
, size
, align
, boundary
, flags
,
568 bus_addr_t rstart
, rend
, *addrp
;
569 bus_size_t size
, align
, boundary
;
571 bus_space_handle_t
*bshp
;
573 #ifdef CHIP_IO_EXTENT
574 struct mips_bus_space_translation mbst
;
575 int linear
= flags
& BUS_SPACE_MAP_LINEAR
;
580 * Can't map i/o space linearly.
586 * Do the requested allocation.
589 printf("io: allocating from 0x%lx to 0x%lx\n", rstart
, rend
);
591 error
= extent_alloc_subregion(CHIP_IO_EXTENT(v
), rstart
, rend
,
592 size
, align
, boundary
,
593 EX_FAST
| EX_NOWAIT
| (CHIP_EX_MALLOC_SAFE(v
) ? EX_MALLOCOK
: 0),
597 printf("io: allocation failed (%d)\n", error
);
598 extent_print(CHIP_IO_EXTENT(v
));
604 printf("io: allocated 0x%lx to 0x%lx\n", ioaddr
, ioaddr
+ size
- 1);
607 error
= __C(CHIP
,_io_translate
)(v
, ioaddr
, size
, flags
, &mbst
);
609 (void) extent_free(CHIP_IO_EXTENT(v
), ioaddr
, size
,
610 EX_NOWAIT
| (CHIP_EX_MALLOC_SAFE(v
) ? EX_MALLOCOK
: 0));
615 if (flags
& BUS_SPACE_MAP_CACHEABLE
)
616 *bshp
= MIPS_PHYS_TO_KSEG0(mbst
.mbst_sys_start
+
617 (ioaddr
- mbst
.mbst_bus_start
));
619 *bshp
= MIPS_PHYS_TO_KSEG1(mbst
.mbst_sys_start
+
620 (ioaddr
- mbst
.mbst_bus_start
));
623 #else /* ! CHIP_IO_EXTENT */
625 #endif /* CHIP_IO_EXTENT */
629 __C(CHIP
,_io_free
)(v
, bsh
, size
)
631 bus_space_handle_t bsh
;
635 /* Unmap does all we need to do. */
636 __C(CHIP
,_io_unmap
)(v
, bsh
, size
, 1);
640 __C(CHIP
,_io_vaddr
)(v
, bsh
)
642 bus_space_handle_t bsh
;
645 * _io_translate() catches BUS_SPACE_MAP_LINEAR,
646 * so we shouldn't get here
652 __C(CHIP
,_io_mmap
)(v
, addr
, off
, prot
, flags
)
660 /* Not supported for I/O space. */
665 __C(CHIP
,_io_barrier
)(v
, h
, o
, l
, f
)
667 bus_space_handle_t h
;
673 if ((f
& BUS_SPACE_BARRIER_WRITE
) != 0)
678 __C(CHIP
,_io_read_1
)(v
, ioh
, off
)
680 bus_space_handle_t ioh
;
683 u_int8_t
*ptr
= (void *)(ioh
+ (off
<< CHIP_ALIGN_STRIDE
));
689 __C(CHIP
,_io_read_2
)(v
, ioh
, off
)
691 bus_space_handle_t ioh
;
694 #if CHIP_ALIGN_STRIDE >= 1
695 u_int16_t
*ptr
= (void *)(ioh
+ (off
<< (CHIP_ALIGN_STRIDE
- 1)));
697 u_int16_t
*ptr
= (void *)(ioh
+ off
);
704 __C(CHIP
,_io_read_4
)(v
, ioh
, off
)
706 bus_space_handle_t ioh
;
709 #if CHIP_ALIGN_STRIDE >= 2
710 u_int32_t
*ptr
= (void *)(ioh
+ (off
<< (CHIP_ALIGN_STRIDE
- 2)));
712 u_int32_t
*ptr
= (void *)(ioh
+ off
);
719 __C(CHIP
,_io_read_8
)(v
, ioh
, off
)
721 bus_space_handle_t ioh
;
726 panic("%s not implemented", __S(__C(CHIP
,_io_read_8
)));
729 #define CHIP_io_read_multi_N(BYTES,TYPE) \
731 __C(__C(CHIP,_io_read_multi_),BYTES)(v, h, o, a, c) \
733 bus_space_handle_t h; \
739 __C(CHIP,_io_barrier)(v, h, o, sizeof *a, \
740 BUS_SPACE_BARRIER_READ); \
741 *a++ = __C(__C(CHIP,_io_read_),BYTES)(v, h, o); \
744 CHIP_io_read_multi_N(1,u_int8_t
)
745 CHIP_io_read_multi_N(2,u_int16_t
)
746 CHIP_io_read_multi_N(4,u_int32_t
)
747 CHIP_io_read_multi_N(8,u_int64_t
)
749 #define CHIP_io_read_region_N(BYTES,TYPE) \
751 __C(__C(CHIP,_io_read_region_),BYTES)(v, h, o, a, c) \
753 bus_space_handle_t h; \
759 *a++ = __C(__C(CHIP,_io_read_),BYTES)(v, h, o); \
763 CHIP_io_read_region_N(1,u_int8_t
)
764 CHIP_io_read_region_N(2,u_int16_t
)
765 CHIP_io_read_region_N(4,u_int32_t
)
766 CHIP_io_read_region_N(8,u_int64_t
)
769 __C(CHIP
,_io_write_1
)(v
, ioh
, off
, val
)
771 bus_space_handle_t ioh
;
775 u_int8_t
*ptr
= (void *)(ioh
+ (off
<< CHIP_ALIGN_STRIDE
));
781 __C(CHIP
,_io_write_2
)(v
, ioh
, off
, val
)
783 bus_space_handle_t ioh
;
787 #if CHIP_ALIGN_STRIDE >= 1
788 u_int16_t
*ptr
= (void *)(ioh
+ (off
<< (CHIP_ALIGN_STRIDE
- 1)));
790 u_int16_t
*ptr
= (void *)(ioh
+ off
);
797 __C(CHIP
,_io_write_4
)(v
, ioh
, off
, val
)
799 bus_space_handle_t ioh
;
803 #if CHIP_ALIGN_STRIDE >= 2
804 u_int32_t
*ptr
= (void *)(ioh
+ (off
<< (CHIP_ALIGN_STRIDE
- 2)));
806 u_int32_t
*ptr
= (void *)(ioh
+ off
);
813 __C(CHIP
,_io_write_8
)(v
, ioh
, off
, val
)
815 bus_space_handle_t ioh
;
821 panic("%s not implemented", __S(__C(CHIP
,_io_write_8
)));
824 #define CHIP_io_write_multi_N(BYTES,TYPE) \
826 __C(__C(CHIP,_io_write_multi_),BYTES)(v, h, o, a, c) \
828 bus_space_handle_t h; \
834 __C(__C(CHIP,_io_write_),BYTES)(v, h, o, *a++); \
835 __C(CHIP,_io_barrier)(v, h, o, sizeof *a, \
836 BUS_SPACE_BARRIER_WRITE); \
839 CHIP_io_write_multi_N(1,u_int8_t
)
840 CHIP_io_write_multi_N(2,u_int16_t
)
841 CHIP_io_write_multi_N(4,u_int32_t
)
842 CHIP_io_write_multi_N(8,u_int64_t
)
844 #define CHIP_io_write_region_N(BYTES,TYPE) \
846 __C(__C(CHIP,_io_write_region_),BYTES)(v, h, o, a, c) \
848 bus_space_handle_t h; \
854 __C(__C(CHIP,_io_write_),BYTES)(v, h, o, *a++); \
858 CHIP_io_write_region_N(1,u_int8_t
)
859 CHIP_io_write_region_N(2,u_int16_t
)
860 CHIP_io_write_region_N(4,u_int32_t
)
861 CHIP_io_write_region_N(8,u_int64_t
)
863 #define CHIP_io_set_multi_N(BYTES,TYPE) \
865 __C(__C(CHIP,_io_set_multi_),BYTES)(v, h, o, val, c) \
867 bus_space_handle_t h; \
873 __C(__C(CHIP,_io_write_),BYTES)(v, h, o, val); \
874 __C(CHIP,_io_barrier)(v, h, o, sizeof val, \
875 BUS_SPACE_BARRIER_WRITE); \
878 CHIP_io_set_multi_N(1,u_int8_t
)
879 CHIP_io_set_multi_N(2,u_int16_t
)
880 CHIP_io_set_multi_N(4,u_int32_t
)
881 CHIP_io_set_multi_N(8,u_int64_t
)
883 #define CHIP_io_set_region_N(BYTES,TYPE) \
885 __C(__C(CHIP,_io_set_region_),BYTES)(v, h, o, val, c) \
887 bus_space_handle_t h; \
893 __C(__C(CHIP,_io_write_),BYTES)(v, h, o, val); \
897 CHIP_io_set_region_N(1,u_int8_t
)
898 CHIP_io_set_region_N(2,u_int16_t
)
899 CHIP_io_set_region_N(4,u_int32_t
)
900 CHIP_io_set_region_N(8,u_int64_t
)
902 #define CHIP_io_copy_region_N(BYTES) \
904 __C(__C(CHIP,_io_copy_region_),BYTES)(v, h1, o1, h2, o2, c) \
906 bus_space_handle_t h1, h2; \
907 bus_size_t o1, o2, c; \
911 if ((h1 + o1) >= (h2 + o2)) { \
912 /* src after dest: copy forward */ \
913 for (o = 0; c != 0; c--, o += BYTES) \
914 __C(__C(CHIP,_io_write_),BYTES)(v, h2, o2 + o, \
915 __C(__C(CHIP,_io_read_),BYTES)(v, h1, o1 + o)); \
917 /* dest after src: copy backwards */ \
918 for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES) \
919 __C(__C(CHIP,_io_write_),BYTES)(v, h2, o2 + o, \
920 __C(__C(CHIP,_io_read_),BYTES)(v, h1, o1 + o)); \
923 CHIP_io_copy_region_N(1)
924 CHIP_io_copy_region_N(2)
925 CHIP_io_copy_region_N(4)
926 CHIP_io_copy_region_N(8)