1 /* $NetBSD: pci_swiz_bus_io_chipdep.c,v 1.37 2009/03/14 14:45:53 dsl Exp $ */
4 * Copyright (c) 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_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_swiz_bus_io_chipdep.c,v 1.37 2009/03/14 14:45:53 dsl 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 alpha_bus_space_translation
*);
96 int __C(CHIP
,_io_get_window
)(void *, int,
97 struct alpha_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 #ifndef CHIP_IO_EX_STORE
208 __C(CHIP
,_io_ex_storage
)[EXTENT_FIXED_STORAGE_SIZE(8) / sizeof(long)];
209 #define CHIP_IO_EX_STORE(v) (__C(CHIP, _io_ex_storage))
210 #define CHIP_IO_EX_STORE_SIZE(v) (sizeof __C(CHIP, _io_ex_storage))
213 #ifndef CHIP_ADDR_SHIFT
214 #define CHIP_ADDR_SHIFT 5
217 #ifndef CHIP_SIZE_SHIFT
218 #define CHIP_SIZE_SHIFT 3
222 __C(CHIP
,_bus_io_init
)(bus_space_tag_t t
, void *v
)
227 * Initialize the bus space tag.
233 /* mapping/unmapping */
234 t
->abs_map
= __C(CHIP
,_io_map
);
235 t
->abs_unmap
= __C(CHIP
,_io_unmap
);
236 t
->abs_subregion
= __C(CHIP
,_io_subregion
);
238 t
->abs_translate
= __C(CHIP
,_io_translate
);
239 t
->abs_get_window
= __C(CHIP
,_io_get_window
);
241 /* allocation/deallocation */
242 t
->abs_alloc
= __C(CHIP
,_io_alloc
);
243 t
->abs_free
= __C(CHIP
,_io_free
);
245 /* get kernel virtual address */
246 t
->abs_vaddr
= __C(CHIP
,_io_vaddr
);
249 t
->abs_mmap
= __C(CHIP
,_io_mmap
);
252 t
->abs_barrier
= __C(CHIP
,_io_barrier
);
255 t
->abs_r_1
= __C(CHIP
,_io_read_1
);
256 t
->abs_r_2
= __C(CHIP
,_io_read_2
);
257 t
->abs_r_4
= __C(CHIP
,_io_read_4
);
258 t
->abs_r_8
= __C(CHIP
,_io_read_8
);
261 t
->abs_rm_1
= __C(CHIP
,_io_read_multi_1
);
262 t
->abs_rm_2
= __C(CHIP
,_io_read_multi_2
);
263 t
->abs_rm_4
= __C(CHIP
,_io_read_multi_4
);
264 t
->abs_rm_8
= __C(CHIP
,_io_read_multi_8
);
267 t
->abs_rr_1
= __C(CHIP
,_io_read_region_1
);
268 t
->abs_rr_2
= __C(CHIP
,_io_read_region_2
);
269 t
->abs_rr_4
= __C(CHIP
,_io_read_region_4
);
270 t
->abs_rr_8
= __C(CHIP
,_io_read_region_8
);
273 t
->abs_w_1
= __C(CHIP
,_io_write_1
);
274 t
->abs_w_2
= __C(CHIP
,_io_write_2
);
275 t
->abs_w_4
= __C(CHIP
,_io_write_4
);
276 t
->abs_w_8
= __C(CHIP
,_io_write_8
);
279 t
->abs_wm_1
= __C(CHIP
,_io_write_multi_1
);
280 t
->abs_wm_2
= __C(CHIP
,_io_write_multi_2
);
281 t
->abs_wm_4
= __C(CHIP
,_io_write_multi_4
);
282 t
->abs_wm_8
= __C(CHIP
,_io_write_multi_8
);
285 t
->abs_wr_1
= __C(CHIP
,_io_write_region_1
);
286 t
->abs_wr_2
= __C(CHIP
,_io_write_region_2
);
287 t
->abs_wr_4
= __C(CHIP
,_io_write_region_4
);
288 t
->abs_wr_8
= __C(CHIP
,_io_write_region_8
);
291 t
->abs_sm_1
= __C(CHIP
,_io_set_multi_1
);
292 t
->abs_sm_2
= __C(CHIP
,_io_set_multi_2
);
293 t
->abs_sm_4
= __C(CHIP
,_io_set_multi_4
);
294 t
->abs_sm_8
= __C(CHIP
,_io_set_multi_8
);
297 t
->abs_sr_1
= __C(CHIP
,_io_set_region_1
);
298 t
->abs_sr_2
= __C(CHIP
,_io_set_region_2
);
299 t
->abs_sr_4
= __C(CHIP
,_io_set_region_4
);
300 t
->abs_sr_8
= __C(CHIP
,_io_set_region_8
);
303 t
->abs_c_1
= __C(CHIP
,_io_copy_region_1
);
304 t
->abs_c_2
= __C(CHIP
,_io_copy_region_2
);
305 t
->abs_c_4
= __C(CHIP
,_io_copy_region_4
);
306 t
->abs_c_8
= __C(CHIP
,_io_copy_region_8
);
308 /* XXX WE WANT EXTENT_NOCOALESCE, BUT WE CAN'T USE IT. XXX */
309 ex
= extent_create(__S(__C(CHIP
,_bus_io
)), 0x0UL
, 0xffffffffUL
,
310 M_DEVBUF
, (void *)CHIP_IO_EX_STORE(v
), CHIP_IO_EX_STORE_SIZE(v
),
312 extent_alloc_region(ex
, 0, 0xffffffffUL
, EX_NOWAIT
);
314 #ifdef CHIP_IO_W1_BUS_START
316 printf("io: freeing from 0x%lx to 0x%lx\n", CHIP_IO_W1_BUS_START(v
),
317 CHIP_IO_W1_BUS_END(v
));
319 extent_free(ex
, CHIP_IO_W1_BUS_START(v
),
320 CHIP_IO_W1_BUS_END(v
) - CHIP_IO_W1_BUS_START(v
) + 1, EX_NOWAIT
);
322 #ifdef CHIP_IO_W2_BUS_START
324 printf("io: freeing from 0x%lx to 0x%lx\n", CHIP_IO_W2_BUS_START(v
),
325 CHIP_IO_W2_BUS_END(v
));
327 extent_free(ex
, CHIP_IO_W2_BUS_START(v
),
328 CHIP_IO_W2_BUS_END(v
) - CHIP_IO_W2_BUS_START(v
) + 1, EX_NOWAIT
);
334 CHIP_IO_EXTENT(v
) = ex
;
338 __C(CHIP
,_io_translate
)(void *v
, bus_addr_t ioaddr
, bus_size_t iolen
,
339 int flags
, struct alpha_bus_space_translation
*abst
)
341 bus_addr_t ioend
= ioaddr
+ (iolen
- 1);
342 int linear
= flags
& BUS_SPACE_MAP_LINEAR
;
345 * Can't map i/o space linearly.
350 #ifdef CHIP_IO_W1_BUS_START
351 if (ioaddr
>= CHIP_IO_W1_BUS_START(v
) &&
352 ioend
<= CHIP_IO_W1_BUS_END(v
))
353 return (__C(CHIP
,_io_get_window
)(v
, 0, abst
));
356 #ifdef CHIP_IO_W2_BUS_START
357 if (ioaddr
>= CHIP_IO_W2_BUS_START(v
) &&
358 ioend
<= CHIP_IO_W2_BUS_END(v
))
359 return (__C(CHIP
,_io_get_window
)(v
, 1, abst
));
364 #ifdef CHIP_IO_W1_BUS_START
365 printf("%s: window[1]=0x%lx-0x%lx\n",
366 __S(__C(CHIP
,_io_map
)), CHIP_IO_W1_BUS_START(v
),
367 CHIP_IO_W1_BUS_END(v
));
369 #ifdef CHIP_IO_W2_BUS_START
370 printf("%s: window[2]=0x%lx-0x%lx\n",
371 __S(__C(CHIP
,_io_map
)), CHIP_IO_W2_BUS_START(v
),
372 CHIP_IO_W2_BUS_END(v
));
374 #endif /* EXTENT_DEBUG */
375 /* No translation. */
380 __C(CHIP
,_io_get_window
)(void *v
, int window
,
381 struct alpha_bus_space_translation
*abst
)
385 #ifdef CHIP_IO_W1_BUS_START
387 abst
->abst_bus_start
= CHIP_IO_W1_BUS_START(v
);
388 abst
->abst_bus_end
= CHIP_IO_W1_BUS_END(v
);
389 abst
->abst_sys_start
= CHIP_IO_W1_SYS_START(v
);
390 abst
->abst_sys_end
= CHIP_IO_W1_SYS_END(v
);
391 abst
->abst_addr_shift
= CHIP_ADDR_SHIFT
;
392 abst
->abst_size_shift
= CHIP_SIZE_SHIFT
;
393 abst
->abst_flags
= 0;
397 #ifdef CHIP_IO_W2_BUS_START
399 abst
->abst_bus_start
= CHIP_IO_W2_BUS_START(v
);
400 abst
->abst_bus_end
= CHIP_IO_W2_BUS_END(v
);
401 abst
->abst_sys_start
= CHIP_IO_W2_SYS_START(v
);
402 abst
->abst_sys_end
= CHIP_IO_W2_SYS_END(v
);
403 abst
->abst_addr_shift
= CHIP_ADDR_SHIFT
;
404 abst
->abst_size_shift
= CHIP_SIZE_SHIFT
;
405 abst
->abst_flags
= 0;
410 panic(__S(__C(CHIP
,_io_get_window
)) ": invalid window %d",
418 __C(CHIP
,_io_map
)(void *v
, bus_addr_t ioaddr
, bus_size_t iosize
,
419 int flags
, bus_space_handle_t
*iohp
, int acct
)
421 struct alpha_bus_space_translation abst
;
425 * Get the translation for this address.
427 error
= __C(CHIP
,_io_translate
)(v
, ioaddr
, iosize
, flags
, &abst
);
435 printf("io: allocating 0x%lx to 0x%lx\n", ioaddr
, ioaddr
+ iosize
- 1);
437 error
= extent_alloc_region(CHIP_IO_EXTENT(v
), ioaddr
, iosize
,
438 EX_NOWAIT
| (CHIP_EX_MALLOC_SAFE(v
) ? EX_MALLOCOK
: 0));
441 printf("io: allocation failed (%d)\n", error
);
442 extent_print(CHIP_IO_EXTENT(v
));
448 *iohp
= (ALPHA_PHYS_TO_K0SEG(abst
.abst_sys_start
) >>
449 CHIP_ADDR_SHIFT
) + (ioaddr
- abst
.abst_bus_start
);
455 __C(CHIP
,_io_unmap
)(void *v
, bus_space_handle_t ioh
,
456 bus_size_t iosize
, int acct
)
465 printf("io: freeing handle 0x%lx for 0x%lx\n", ioh
, iosize
);
468 ioh
= ALPHA_K0SEG_TO_PHYS(ioh
<< CHIP_ADDR_SHIFT
) >> CHIP_ADDR_SHIFT
;
470 #ifdef CHIP_IO_W1_BUS_START
471 if ((ioh
<< CHIP_ADDR_SHIFT
) >= CHIP_IO_W1_SYS_START(v
) &&
472 (ioh
<< CHIP_ADDR_SHIFT
) <= CHIP_IO_W1_SYS_END(v
)) {
473 ioaddr
= CHIP_IO_W1_BUS_START(v
) +
474 (ioh
- (CHIP_IO_W1_SYS_START(v
) >> CHIP_ADDR_SHIFT
));
477 #ifdef CHIP_IO_W2_BUS_START
478 if ((ioh
<< CHIP_ADDR_SHIFT
) >= CHIP_IO_W2_SYS_START(v
) &&
479 (ioh
<< CHIP_ADDR_SHIFT
) <= CHIP_IO_W2_SYS_END(v
)) {
480 ioaddr
= CHIP_IO_W2_BUS_START(v
) +
481 (ioh
- (CHIP_IO_W2_SYS_START(v
) >> CHIP_ADDR_SHIFT
));
486 #ifdef CHIP_IO_W1_BUS_START
487 printf("%s: sys window[1]=0x%lx-0x%lx\n",
488 __S(__C(CHIP
,_io_map
)), CHIP_IO_W1_SYS_START(v
),
489 CHIP_IO_W1_SYS_END(v
));
491 #ifdef CHIP_IO_W2_BUS_START
492 printf("%s: sys window[2]=0x%lx-0x%lx\n",
493 __S(__C(CHIP
,_io_map
)), CHIP_IO_W2_SYS_START(v
),
494 CHIP_IO_W2_SYS_END(v
));
496 panic("%s: don't know how to unmap %lx",
497 __S(__C(CHIP
,_io_unmap
)), (ioh
<< CHIP_ADDR_SHIFT
));
501 printf("io: freeing 0x%lx to 0x%lx\n", ioaddr
, ioaddr
+ iosize
- 1);
503 error
= extent_free(CHIP_IO_EXTENT(v
), ioaddr
, iosize
,
504 EX_NOWAIT
| (CHIP_EX_MALLOC_SAFE(v
) ? EX_MALLOCOK
: 0));
506 printf("%s: WARNING: could not unmap 0x%lx-0x%lx (error %d)\n",
507 __S(__C(CHIP
,_io_unmap
)), ioaddr
, ioaddr
+ iosize
- 1,
510 extent_print(CHIP_IO_EXTENT(v
));
516 __C(CHIP
,_io_subregion
)(void *v
, bus_space_handle_t ioh
,
517 bus_size_t offset
, bus_size_t size
, bus_space_handle_t
*nioh
)
520 *nioh
= ioh
+ offset
;
525 __C(CHIP
,_io_alloc
)(void *v
, bus_addr_t rstart
, bus_addr_t rend
,
526 bus_size_t size
, bus_size_t align
, bus_size_t boundary
, int flags
,
527 bus_addr_t
*addrp
, bus_space_handle_t
*bshp
)
529 struct alpha_bus_space_translation abst
;
530 int linear
= flags
& BUS_SPACE_MAP_LINEAR
;
535 * Can't map i/o space linearly.
541 * Do the requested allocation.
544 printf("io: allocating from 0x%lx to 0x%lx\n", rstart
, rend
);
546 error
= extent_alloc_subregion(CHIP_IO_EXTENT(v
), rstart
, rend
,
547 size
, align
, boundary
,
548 EX_FAST
| EX_NOWAIT
| (CHIP_EX_MALLOC_SAFE(v
) ? EX_MALLOCOK
: 0),
552 printf("io: allocation failed (%d)\n", error
);
553 extent_print(CHIP_IO_EXTENT(v
));
559 printf("io: allocated 0x%lx to 0x%lx\n", ioaddr
, ioaddr
+ size
- 1);
562 error
= __C(CHIP
,_io_translate
)(v
, ioaddr
, size
, flags
, &abst
);
564 (void) extent_free(CHIP_IO_EXTENT(v
), ioaddr
, size
,
565 EX_NOWAIT
| (CHIP_EX_MALLOC_SAFE(v
) ? EX_MALLOCOK
: 0));
570 *bshp
= (ALPHA_PHYS_TO_K0SEG(abst
.abst_sys_start
) >>
571 CHIP_ADDR_SHIFT
) + (ioaddr
- abst
.abst_bus_start
);
577 __C(CHIP
,_io_free
)(void *v
, bus_space_handle_t bsh
, bus_size_t size
)
580 /* Unmap does all we need to do. */
581 __C(CHIP
,_io_unmap
)(v
, bsh
, size
, 1);
585 __C(CHIP
,_io_vaddr
)(void *v
, bus_space_handle_t bsh
)
588 * _io_translate() catches BUS_SPACE_MAP_LINEAR,
589 * so we shouldn't get here
595 __C(CHIP
,_io_mmap
)(void *v
, bus_addr_t addr
, off_t off
, int prot
, int flags
)
598 /* Not supported for I/O space. */
603 __C(CHIP
,_io_barrier
)(void *v
, bus_space_handle_t h
,
604 bus_size_t o
, bus_size_t l
, int f
)
607 if ((f
& BUS_SPACE_BARRIER_READ
) != 0)
609 else if ((f
& BUS_SPACE_BARRIER_WRITE
) != 0)
614 __C(CHIP
,_io_read_1
)(void *v
, bus_space_handle_t ioh
, bus_size_t off
)
616 register bus_space_handle_t tmpioh
;
617 register u_int32_t
*port
, val
;
618 register u_int8_t rval
;
625 port
= (u_int32_t
*)((tmpioh
<< CHIP_ADDR_SHIFT
) |
626 (0 << CHIP_SIZE_SHIFT
));
628 rval
= ((val
) >> (8 * offset
)) & 0xff;
634 __C(CHIP
,_io_read_2
)(void *v
, bus_space_handle_t ioh
, bus_size_t off
)
636 register bus_space_handle_t tmpioh
;
637 register u_int32_t
*port
, val
;
638 register u_int16_t rval
;
645 port
= (u_int32_t
*)((tmpioh
<< CHIP_ADDR_SHIFT
) |
646 (1 << CHIP_SIZE_SHIFT
));
648 rval
= ((val
) >> (8 * offset
)) & 0xffff;
654 __C(CHIP
,_io_read_4
)(void *v
, bus_space_handle_t ioh
, bus_size_t off
)
656 register bus_space_handle_t tmpioh
;
657 register u_int32_t
*port
, val
;
658 register u_int32_t rval
;
665 port
= (u_int32_t
*)((tmpioh
<< CHIP_ADDR_SHIFT
) |
666 (3 << CHIP_SIZE_SHIFT
));
669 rval
= ((val
) >> (8 * offset
)) & 0xffffffff;
678 __C(CHIP
,_io_read_8
)(void *v
, bus_space_handle_t ioh
, bus_size_t off
)
682 panic("%s not implemented", __S(__C(CHIP
,_io_read_8
)));
685 #define CHIP_io_read_multi_N(BYTES,TYPE) \
687 __C(__C(CHIP,_io_read_multi_),BYTES)(void *v, bus_space_handle_t h, bus_size_t o, TYPE *a, bus_size_t c) \
691 __C(CHIP,_io_barrier)(v, h, o, sizeof *a, \
692 BUS_SPACE_BARRIER_READ); \
693 *a++ = __C(__C(CHIP,_io_read_),BYTES)(v, h, o); \
696 CHIP_io_read_multi_N(1,u_int8_t
)
697 CHIP_io_read_multi_N(2,u_int16_t
)
698 CHIP_io_read_multi_N(4,u_int32_t
)
699 CHIP_io_read_multi_N(8,u_int64_t
)
701 #define CHIP_io_read_region_N(BYTES,TYPE) \
703 __C(__C(CHIP,_io_read_region_),BYTES)(void *v, bus_space_handle_t h, bus_size_t o, TYPE *a, bus_size_t c) \
707 *a++ = __C(__C(CHIP,_io_read_),BYTES)(v, h, o); \
711 CHIP_io_read_region_N(1,u_int8_t
)
712 CHIP_io_read_region_N(2,u_int16_t
)
713 CHIP_io_read_region_N(4,u_int32_t
)
714 CHIP_io_read_region_N(8,u_int64_t
)
717 __C(CHIP
,_io_write_1
)(void *v
, bus_space_handle_t ioh
,
718 bus_size_t off
, uint8_t val
)
720 register bus_space_handle_t tmpioh
;
721 register u_int32_t
*port
, nval
;
726 nval
= val
<< (8 * offset
);
727 port
= (u_int32_t
*)((tmpioh
<< CHIP_ADDR_SHIFT
) |
728 (0 << CHIP_SIZE_SHIFT
));
734 __C(CHIP
,_io_write_2
)(void *v
, bus_space_handle_t ioh
,
735 bus_size_t off
, uint16_t val
)
737 register bus_space_handle_t tmpioh
;
738 register u_int32_t
*port
, nval
;
743 nval
= val
<< (8 * offset
);
744 port
= (u_int32_t
*)((tmpioh
<< CHIP_ADDR_SHIFT
) |
745 (1 << CHIP_SIZE_SHIFT
));
751 __C(CHIP
,_io_write_4
)(void *v
, bus_space_handle_t ioh
,
752 bus_size_t off
, uint32_t val
)
754 register bus_space_handle_t tmpioh
;
755 register u_int32_t
*port
, nval
;
760 nval
= val
/*<< (8 * offset)*/;
761 port
= (u_int32_t
*)((tmpioh
<< CHIP_ADDR_SHIFT
) |
762 (3 << CHIP_SIZE_SHIFT
));
768 __C(CHIP
,_io_write_8
)(void *v
, bus_space_handle_t ioh
,
769 bus_size_t off
, uint64_t val
)
773 panic("%s not implemented", __S(__C(CHIP
,_io_write_8
)));
777 #define CHIP_io_write_multi_N(BYTES,TYPE) \
779 __C(__C(CHIP,_io_write_multi_),BYTES)(void *v, bus_space_handle_t h, bus_size_t o, const TYPE *a, bus_size_t c) \
783 __C(__C(CHIP,_io_write_),BYTES)(v, h, o, *a++); \
784 __C(CHIP,_io_barrier)(v, h, o, sizeof *a, \
785 BUS_SPACE_BARRIER_WRITE); \
788 CHIP_io_write_multi_N(1,u_int8_t
)
789 CHIP_io_write_multi_N(2,u_int16_t
)
790 CHIP_io_write_multi_N(4,u_int32_t
)
791 CHIP_io_write_multi_N(8,u_int64_t
)
793 #define CHIP_io_write_region_N(BYTES,TYPE) \
795 __C(__C(CHIP,_io_write_region_),BYTES)(void *v, bus_space_handle_t h, bus_size_t o, const TYPE *a, bus_size_t c) \
799 __C(__C(CHIP,_io_write_),BYTES)(v, h, o, *a++); \
803 CHIP_io_write_region_N(1,u_int8_t
)
804 CHIP_io_write_region_N(2,u_int16_t
)
805 CHIP_io_write_region_N(4,u_int32_t
)
806 CHIP_io_write_region_N(8,u_int64_t
)
808 #define CHIP_io_set_multi_N(BYTES,TYPE) \
810 __C(__C(CHIP,_io_set_multi_),BYTES)(void *v, bus_space_handle_t h, bus_size_t o, TYPE val, bus_size_t c) \
814 __C(__C(CHIP,_io_write_),BYTES)(v, h, o, val); \
815 __C(CHIP,_io_barrier)(v, h, o, sizeof val, \
816 BUS_SPACE_BARRIER_WRITE); \
819 CHIP_io_set_multi_N(1,u_int8_t
)
820 CHIP_io_set_multi_N(2,u_int16_t
)
821 CHIP_io_set_multi_N(4,u_int32_t
)
822 CHIP_io_set_multi_N(8,u_int64_t
)
824 #define CHIP_io_set_region_N(BYTES,TYPE) \
826 __C(__C(CHIP,_io_set_region_),BYTES)(void *v, bus_space_handle_t h, bus_size_t o, TYPE val, bus_size_t c) \
830 __C(__C(CHIP,_io_write_),BYTES)(v, h, o, val); \
834 CHIP_io_set_region_N(1,u_int8_t
)
835 CHIP_io_set_region_N(2,u_int16_t
)
836 CHIP_io_set_region_N(4,u_int32_t
)
837 CHIP_io_set_region_N(8,u_int64_t
)
839 #define CHIP_io_copy_region_N(BYTES) \
841 __C(__C(CHIP,_io_copy_region_),BYTES)(void *v, bus_space_handle_t h1, bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c) \
845 if ((h1 + o1) >= (h2 + o2)) { \
846 /* src after dest: copy forward */ \
847 for (o = 0; c != 0; c--, o += BYTES) \
848 __C(__C(CHIP,_io_write_),BYTES)(v, h2, o2 + o, \
849 __C(__C(CHIP,_io_read_),BYTES)(v, h1, o1 + o)); \
851 /* dest after src: copy backwards */ \
852 for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES) \
853 __C(__C(CHIP,_io_write_),BYTES)(v, h2, o2 + o, \
854 __C(__C(CHIP,_io_read_),BYTES)(v, h1, o1 + o)); \
857 CHIP_io_copy_region_N(1)
858 CHIP_io_copy_region_N(2)
859 CHIP_io_copy_region_N(4)
860 CHIP_io_copy_region_N(8)