1 /* $NetBSD: pci_alignstride_bus_mem_chipdep.c,v 1.7 2008/04/28 20:23:10 martin Exp $ */
4 * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
34 * All rights reserved.
36 * Author: Chris G. Demetriou
38 * Permission to use, copy, modify and distribute this software and
39 * its documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
46 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 * Carnegie Mellon requests users of this software to return to
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
55 * any improvements or extensions that they make and grant Carnegie the
56 * rights to redistribute these changes.
60 * Common PCI Chipset "bus I/O" functions, for chipsets which have to
61 * deal with only a single PCI interface chip in a machine.
64 * CHIP name of the 'chip' it's being compiled for.
65 * CHIP_MEM_BASE Mem space base to use.
67 * If defined, device-provided static storage area
68 * for the sparse memory space extent. If this is
69 * defined, CHIP_MEM_EX_STORE_SIZE must also be
70 * defined. If this is not defined, a static area
72 * CHIP_MEM_EX_STORE_SIZE
73 * Size of the device-provided static storage area
74 * for the sparse memory space extent.
77 #include <sys/cdefs.h>
78 __KERNEL_RCSID(1, "$NetBSD: pci_alignstride_bus_mem_chipdep.c,v 1.7 2008/04/28 20:23:10 martin Exp $");
80 #include <sys/extent.h>
82 #define __C(A,B) __CONCAT(A,B)
83 #define __S(S) __STRING(S)
85 /* mapping/unmapping */
86 int __C(CHIP
,_mem_map
)(void *, bus_addr_t
, bus_size_t
, int,
87 bus_space_handle_t
*, int);
88 void __C(CHIP
,_mem_unmap
)(void *, bus_space_handle_t
,
90 int __C(CHIP
,_mem_subregion
)(void *, bus_space_handle_t
,
91 bus_size_t
, bus_size_t
, bus_space_handle_t
*);
93 int __C(CHIP
,_mem_translate
)(void *, bus_addr_t
, bus_size_t
,
94 int, struct mips_bus_space_translation
*);
95 int __C(CHIP
,_mem_get_window
)(void *, int,
96 struct mips_bus_space_translation
*);
98 /* allocation/deallocation */
99 int __C(CHIP
,_mem_alloc
)(void *, bus_addr_t
, bus_addr_t
,
100 bus_size_t
, bus_size_t
, bus_addr_t
, int, bus_addr_t
*,
101 bus_space_handle_t
*);
102 void __C(CHIP
,_mem_free
)(void *, bus_space_handle_t
,
105 /* get kernel virtual address */
106 void * __C(CHIP
,_mem_vaddr
)(void *, bus_space_handle_t
);
109 paddr_t
__C(CHIP
,_mem_mmap
)(void *, bus_addr_t
, off_t
, int, int);
112 inline void __C(CHIP
,_mem_barrier
)(void *, bus_space_handle_t
,
113 bus_size_t
, bus_size_t
, int);
116 inline u_int8_t
__C(CHIP
,_mem_read_1
)(void *, bus_space_handle_t
,
118 inline u_int16_t
__C(CHIP
,_mem_read_2
)(void *, bus_space_handle_t
,
120 inline u_int32_t
__C(CHIP
,_mem_read_4
)(void *, bus_space_handle_t
,
122 inline u_int64_t
__C(CHIP
,_mem_read_8
)(void *, bus_space_handle_t
,
126 void __C(CHIP
,_mem_read_multi_1
)(void *, bus_space_handle_t
,
127 bus_size_t
, u_int8_t
*, bus_size_t
);
128 void __C(CHIP
,_mem_read_multi_2
)(void *, bus_space_handle_t
,
129 bus_size_t
, u_int16_t
*, bus_size_t
);
130 void __C(CHIP
,_mem_read_multi_4
)(void *, bus_space_handle_t
,
131 bus_size_t
, u_int32_t
*, bus_size_t
);
132 void __C(CHIP
,_mem_read_multi_8
)(void *, bus_space_handle_t
,
133 bus_size_t
, u_int64_t
*, bus_size_t
);
136 void __C(CHIP
,_mem_read_region_1
)(void *, bus_space_handle_t
,
137 bus_size_t
, u_int8_t
*, bus_size_t
);
138 void __C(CHIP
,_mem_read_region_2
)(void *, bus_space_handle_t
,
139 bus_size_t
, u_int16_t
*, bus_size_t
);
140 void __C(CHIP
,_mem_read_region_4
)(void *, bus_space_handle_t
,
141 bus_size_t
, u_int32_t
*, bus_size_t
);
142 void __C(CHIP
,_mem_read_region_8
)(void *, bus_space_handle_t
,
143 bus_size_t
, u_int64_t
*, bus_size_t
);
146 inline void __C(CHIP
,_mem_write_1
)(void *, bus_space_handle_t
,
147 bus_size_t
, u_int8_t
);
148 inline void __C(CHIP
,_mem_write_2
)(void *, bus_space_handle_t
,
149 bus_size_t
, u_int16_t
);
150 inline void __C(CHIP
,_mem_write_4
)(void *, bus_space_handle_t
,
151 bus_size_t
, u_int32_t
);
152 inline void __C(CHIP
,_mem_write_8
)(void *, bus_space_handle_t
,
153 bus_size_t
, u_int64_t
);
156 void __C(CHIP
,_mem_write_multi_1
)(void *, bus_space_handle_t
,
157 bus_size_t
, const u_int8_t
*, bus_size_t
);
158 void __C(CHIP
,_mem_write_multi_2
)(void *, bus_space_handle_t
,
159 bus_size_t
, const u_int16_t
*, bus_size_t
);
160 void __C(CHIP
,_mem_write_multi_4
)(void *, bus_space_handle_t
,
161 bus_size_t
, const u_int32_t
*, bus_size_t
);
162 void __C(CHIP
,_mem_write_multi_8
)(void *, bus_space_handle_t
,
163 bus_size_t
, const u_int64_t
*, bus_size_t
);
166 void __C(CHIP
,_mem_write_region_1
)(void *, bus_space_handle_t
,
167 bus_size_t
, const u_int8_t
*, bus_size_t
);
168 void __C(CHIP
,_mem_write_region_2
)(void *, bus_space_handle_t
,
169 bus_size_t
, const u_int16_t
*, bus_size_t
);
170 void __C(CHIP
,_mem_write_region_4
)(void *, bus_space_handle_t
,
171 bus_size_t
, const u_int32_t
*, bus_size_t
);
172 void __C(CHIP
,_mem_write_region_8
)(void *, bus_space_handle_t
,
173 bus_size_t
, const u_int64_t
*, bus_size_t
);
176 void __C(CHIP
,_mem_set_multi_1
)(void *, bus_space_handle_t
,
177 bus_size_t
, u_int8_t
, bus_size_t
);
178 void __C(CHIP
,_mem_set_multi_2
)(void *, bus_space_handle_t
,
179 bus_size_t
, u_int16_t
, bus_size_t
);
180 void __C(CHIP
,_mem_set_multi_4
)(void *, bus_space_handle_t
,
181 bus_size_t
, u_int32_t
, bus_size_t
);
182 void __C(CHIP
,_mem_set_multi_8
)(void *, bus_space_handle_t
,
183 bus_size_t
, u_int64_t
, bus_size_t
);
186 void __C(CHIP
,_mem_set_region_1
)(void *, bus_space_handle_t
,
187 bus_size_t
, u_int8_t
, bus_size_t
);
188 void __C(CHIP
,_mem_set_region_2
)(void *, bus_space_handle_t
,
189 bus_size_t
, u_int16_t
, bus_size_t
);
190 void __C(CHIP
,_mem_set_region_4
)(void *, bus_space_handle_t
,
191 bus_size_t
, u_int32_t
, bus_size_t
);
192 void __C(CHIP
,_mem_set_region_8
)(void *, bus_space_handle_t
,
193 bus_size_t
, u_int64_t
, bus_size_t
);
196 void __C(CHIP
,_mem_copy_region_1
)(void *, bus_space_handle_t
,
197 bus_size_t
, bus_space_handle_t
, bus_size_t
, bus_size_t
);
198 void __C(CHIP
,_mem_copy_region_2
)(void *, bus_space_handle_t
,
199 bus_size_t
, bus_space_handle_t
, bus_size_t
, bus_size_t
);
200 void __C(CHIP
,_mem_copy_region_4
)(void *, bus_space_handle_t
,
201 bus_size_t
, bus_space_handle_t
, bus_size_t
, bus_size_t
);
202 void __C(CHIP
,_mem_copy_region_8
)(void *, bus_space_handle_t
,
203 bus_size_t
, bus_space_handle_t
, bus_size_t
, bus_size_t
);
205 #ifndef CHIP_MEM_EX_STORE
207 __C(CHIP
,_mem_ex_storage
)[EXTENT_FIXED_STORAGE_SIZE(8) / sizeof(long)];
208 #define CHIP_MEM_EX_STORE(v) (__C(CHIP,_mem_ex_storage))
209 #define CHIP_MEM_EX_STORE_SIZE(v) (sizeof __C(CHIP,_mem_ex_storage))
212 #ifndef CHIP_ALIGN_STRIDE
213 #define CHIP_ALIGN_STRIDE 0
217 __C(CHIP
,_bus_mem_init
)(t
, v
)
224 * Initialize the bus space tag.
230 /* mapping/unmapping */
231 t
->bs_map
= __C(CHIP
,_mem_map
);
232 t
->bs_unmap
= __C(CHIP
,_mem_unmap
);
233 t
->bs_subregion
= __C(CHIP
,_mem_subregion
);
235 t
->bs_translate
= __C(CHIP
,_mem_translate
);
236 t
->bs_get_window
= __C(CHIP
,_mem_get_window
);
238 /* allocation/deallocation */
239 t
->bs_alloc
= __C(CHIP
,_mem_alloc
);
240 t
->bs_free
= __C(CHIP
,_mem_free
);
242 /* get kernel virtual address */
243 t
->bs_vaddr
= __C(CHIP
,_mem_vaddr
);
246 t
->bs_mmap
= __C(CHIP
,_mem_mmap
);
249 t
->bs_barrier
= __C(CHIP
,_mem_barrier
);
252 t
->bs_r_1
= __C(CHIP
,_mem_read_1
);
253 t
->bs_r_2
= __C(CHIP
,_mem_read_2
);
254 t
->bs_r_4
= __C(CHIP
,_mem_read_4
);
255 t
->bs_r_8
= __C(CHIP
,_mem_read_8
);
258 t
->bs_rm_1
= __C(CHIP
,_mem_read_multi_1
);
259 t
->bs_rm_2
= __C(CHIP
,_mem_read_multi_2
);
260 t
->bs_rm_4
= __C(CHIP
,_mem_read_multi_4
);
261 t
->bs_rm_8
= __C(CHIP
,_mem_read_multi_8
);
264 t
->bs_rr_1
= __C(CHIP
,_mem_read_region_1
);
265 t
->bs_rr_2
= __C(CHIP
,_mem_read_region_2
);
266 t
->bs_rr_4
= __C(CHIP
,_mem_read_region_4
);
267 t
->bs_rr_8
= __C(CHIP
,_mem_read_region_8
);
270 t
->bs_w_1
= __C(CHIP
,_mem_write_1
);
271 t
->bs_w_2
= __C(CHIP
,_mem_write_2
);
272 t
->bs_w_4
= __C(CHIP
,_mem_write_4
);
273 t
->bs_w_8
= __C(CHIP
,_mem_write_8
);
276 t
->bs_wm_1
= __C(CHIP
,_mem_write_multi_1
);
277 t
->bs_wm_2
= __C(CHIP
,_mem_write_multi_2
);
278 t
->bs_wm_4
= __C(CHIP
,_mem_write_multi_4
);
279 t
->bs_wm_8
= __C(CHIP
,_mem_write_multi_8
);
282 t
->bs_wr_1
= __C(CHIP
,_mem_write_region_1
);
283 t
->bs_wr_2
= __C(CHIP
,_mem_write_region_2
);
284 t
->bs_wr_4
= __C(CHIP
,_mem_write_region_4
);
285 t
->bs_wr_8
= __C(CHIP
,_mem_write_region_8
);
288 t
->bs_sm_1
= __C(CHIP
,_mem_set_multi_1
);
289 t
->bs_sm_2
= __C(CHIP
,_mem_set_multi_2
);
290 t
->bs_sm_4
= __C(CHIP
,_mem_set_multi_4
);
291 t
->bs_sm_8
= __C(CHIP
,_mem_set_multi_8
);
294 t
->bs_sr_1
= __C(CHIP
,_mem_set_region_1
);
295 t
->bs_sr_2
= __C(CHIP
,_mem_set_region_2
);
296 t
->bs_sr_4
= __C(CHIP
,_mem_set_region_4
);
297 t
->bs_sr_8
= __C(CHIP
,_mem_set_region_8
);
300 t
->bs_c_1
= __C(CHIP
,_mem_copy_region_1
);
301 t
->bs_c_2
= __C(CHIP
,_mem_copy_region_2
);
302 t
->bs_c_4
= __C(CHIP
,_mem_copy_region_4
);
303 t
->bs_c_8
= __C(CHIP
,_mem_copy_region_8
);
305 /* XXX WE WANT EXTENT_NOCOALESCE, BUT WE CAN'T USE IT. XXX */
306 ex
= extent_create(__S(__C(CHIP
,_bus_mem
)), 0x0UL
, 0xffffffffUL
,
307 M_DEVBUF
, (void *)CHIP_MEM_EX_STORE(v
), CHIP_MEM_EX_STORE_SIZE(v
),
309 extent_alloc_region(ex
, 0, 0xffffffffUL
, EX_NOWAIT
);
311 #ifdef CHIP_MEM_W1_BUS_START
313 printf("mem: freeing from 0x%lx to 0x%lx\n",
314 CHIP_MEM_W1_BUS_START(v
), CHIP_MEM_W1_BUS_END(v
));
316 extent_free(ex
, CHIP_MEM_W1_BUS_START(v
),
317 CHIP_MEM_W1_BUS_END(v
) - CHIP_MEM_W1_BUS_START(v
) + 1,
320 #ifdef CHIP_MEM_W2_BUS_START
321 if (CHIP_MEM_W2_BUS_START(v
) != CHIP_MEM_W1_BUS_START(v
)) {
323 printf("mem: freeing from 0x%lx to 0x%lx\n",
324 CHIP_MEM_W2_BUS_START(v
), CHIP_MEM_W2_BUS_END(v
));
326 extent_free(ex
, CHIP_MEM_W2_BUS_START(v
),
327 CHIP_MEM_W2_BUS_END(v
) - CHIP_MEM_W2_BUS_START(v
) + 1,
331 printf("mem: window 2 (0x%lx to 0x%lx) overlaps window 1\n",
332 CHIP_MEM_W2_BUS_START(v
), CHIP_MEM_W2_BUS_END(v
));
336 #ifdef CHIP_MEM_W3_BUS_START
337 if (CHIP_MEM_W3_BUS_START(v
) != CHIP_MEM_W1_BUS_START(v
) &&
338 CHIP_MEM_W3_BUS_START(v
) != CHIP_MEM_W2_BUS_START(v
)) {
340 printf("mem: freeing from 0x%lx to 0x%lx\n",
341 CHIP_MEM_W3_BUS_START(v
), CHIP_MEM_W3_BUS_END(v
));
343 extent_free(ex
, CHIP_MEM_W3_BUS_START(v
),
344 CHIP_MEM_W3_BUS_END(v
) - CHIP_MEM_W3_BUS_START(v
) + 1,
348 printf("mem: window 2 (0x%lx to 0x%lx) overlaps window 1\n",
349 CHIP_MEM_W2_BUS_START(v
), CHIP_MEM_W2_BUS_END(v
));
357 CHIP_MEM_EXTENT(v
) = ex
;
361 __C(CHIP
,_mem_translate
)(v
, memaddr
, memlen
, flags
, mbst
)
366 struct mips_bus_space_translation
*mbst
;
368 bus_addr_t memend
= memaddr
+ (memlen
- 1);
369 #if CHIP_ALIGN_STRIDE != 0
370 int linear
= flags
& BUS_SPACE_MAP_LINEAR
;
373 * Can't map memory space linearly.
379 #ifdef CHIP_MEM_W1_BUS_START
380 if (memaddr
>= CHIP_MEM_W1_BUS_START(v
) &&
381 memend
<= CHIP_MEM_W1_BUS_END(v
))
382 return (__C(CHIP
,_mem_get_window
)(v
, 0, mbst
));
385 #ifdef CHIP_MEM_W2_BUS_START
386 if (memaddr
>= CHIP_MEM_W2_BUS_START(v
) &&
387 memend
<= CHIP_MEM_W2_BUS_END(v
))
388 return (__C(CHIP
,_mem_get_window
)(v
, 1, mbst
));
391 #ifdef CHIP_MEM_W3_BUS_START
392 if (memaddr
>= CHIP_MEM_W3_BUS_START(v
) &&
393 memend
<= CHIP_MEM_W3_BUS_END(v
))
394 return (__C(CHIP
,_mem_get_window
)(v
, 2, mbst
));
399 #ifdef CHIP_MEM_W1_BUS_START
400 printf("%s: window[1]=0x%lx-0x%lx\n",
401 __S(__C(CHIP
,_mem_map
)), CHIP_MEM_W1_BUS_START(v
),
402 CHIP_MEM_W1_BUS_END(v
));
404 #ifdef CHIP_MEM_W2_BUS_START
405 printf("%s: window[2]=0x%lx-0x%lx\n",
406 __S(__C(CHIP
,_mem_map
)), CHIP_MEM_W2_BUS_START(v
),
407 CHIP_MEM_W2_BUS_END(v
));
409 #ifdef CHIP_MEM_W3_BUS_START
410 printf("%s: window[3]=0x%lx-0x%lx\n",
411 __S(__C(CHIP
,_mem_map
)), CHIP_MEM_W3_BUS_START(v
),
412 CHIP_MEM_W3_BUS_END(v
));
414 #endif /* EXTENT_DEBUG */
415 /* No translation. */
420 __C(CHIP
,_mem_get_window
)(v
, window
, mbst
)
423 struct mips_bus_space_translation
*mbst
;
427 #ifdef CHIP_MEM_W1_BUS_START
429 mbst
->mbst_bus_start
= CHIP_MEM_W1_BUS_START(v
);
430 mbst
->mbst_bus_end
= CHIP_MEM_W1_BUS_END(v
);
431 mbst
->mbst_sys_start
= CHIP_MEM_W1_SYS_START(v
);
432 mbst
->mbst_sys_end
= CHIP_MEM_W1_SYS_END(v
);
433 mbst
->mbst_align_stride
= CHIP_ALIGN_STRIDE
;
434 mbst
->mbst_flags
= 0;
438 #ifdef CHIP_MEM_W2_BUS_START
440 mbst
->mbst_bus_start
= CHIP_MEM_W2_BUS_START(v
);
441 mbst
->mbst_bus_end
= CHIP_MEM_W2_BUS_END(v
);
442 mbst
->mbst_sys_start
= CHIP_MEM_W2_SYS_START(v
);
443 mbst
->mbst_sys_end
= CHIP_MEM_W2_SYS_END(v
);
444 mbst
->mbst_align_stride
= CHIP_ALIGN_STRIDE
;
445 mbst
->mbst_flags
= 0;
449 #ifdef CHIP_MEM_W3_BUS_START
451 mbst
->mbst_bus_start
= CHIP_MEM_W3_BUS_START(v
);
452 mbst
->mbst_bus_end
= CHIP_MEM_W3_BUS_END(v
);
453 mbst
->mbst_sys_start
= CHIP_MEM_W3_SYS_START(v
);
454 mbst
->mbst_sys_end
= CHIP_MEM_W3_SYS_END(v
);
455 mbst
->mbst_align_stride
= CHIP_ALIGN_STRIDE
;
456 mbst
->mbst_flags
= 0;
461 panic(__S(__C(CHIP
,_mem_get_window
)) ": invalid window %d",
469 __C(CHIP
,_mem_map
)(v
, memaddr
, memsize
, flags
, memhp
, acct
)
474 bus_space_handle_t
*memhp
;
477 struct mips_bus_space_translation mbst
;
481 * Get the translation for this address.
483 error
= __C(CHIP
,_mem_translate
)(v
, memaddr
, memsize
, flags
, &mbst
);
491 printf("mem: allocating 0x%lx to 0x%lx\n", memaddr
,
492 memaddr
+ memsize
- 1);
494 error
= extent_alloc_region(CHIP_MEM_EXTENT(v
), memaddr
, memsize
,
495 EX_NOWAIT
| (CHIP_EX_MALLOC_SAFE(v
) ? EX_MALLOCOK
: 0));
498 printf("mem: allocation failed (%d)\n", error
);
499 extent_print(CHIP_MEM_EXTENT(v
));
505 if (flags
& BUS_SPACE_MAP_CACHEABLE
)
506 *memhp
= MIPS_PHYS_TO_KSEG0(mbst
.mbst_sys_start
+
507 (memaddr
- mbst
.mbst_bus_start
));
509 *memhp
= MIPS_PHYS_TO_KSEG1(mbst
.mbst_sys_start
+
510 (memaddr
- mbst
.mbst_bus_start
));
516 __C(CHIP
,_mem_unmap
)(v
, memh
, memsize
, acct
)
518 bus_space_handle_t memh
;
529 printf("mem: freeing handle 0x%lx for 0x%lx\n", memh
, memsize
);
532 if (memh
>= MIPS_KSEG0_START
&& memh
< MIPS_KSEG1_START
)
533 memh
= MIPS_KSEG0_TO_PHYS(memh
);
535 memh
= MIPS_KSEG1_TO_PHYS(memh
);
537 #ifdef CHIP_MEM_W1_BUS_START
538 if (memh
>= CHIP_MEM_W1_SYS_START(v
) &&
539 memh
<= CHIP_MEM_W1_SYS_END(v
)) {
540 memaddr
= CHIP_MEM_W1_BUS_START(v
) +
541 (memh
- CHIP_MEM_W1_SYS_START(v
));
544 #ifdef CHIP_MEM_W2_BUS_START
545 if (memh
>= CHIP_MEM_W2_SYS_START(v
) &&
546 memh
<= CHIP_MEM_W2_SYS_END(v
)) {
547 memaddr
= CHIP_MEM_W2_BUS_START(v
) +
548 (memh
- CHIP_MEM_W2_SYS_START(v
));
551 #ifdef CHIP_MEM_W3_BUS_START
552 if (memh
>= CHIP_MEM_W3_SYS_START(v
) &&
553 memh
<= CHIP_MEM_W3_SYS_END(v
)) {
554 memaddr
= CHIP_MEM_W3_BUS_START(v
) +
555 (memh
- CHIP_MEM_W3_SYS_START(v
));
560 #ifdef CHIP_MEM_W1_BUS_START
561 printf("%s: sys window[1]=0x%lx-0x%lx\n",
562 __S(__C(CHIP
,_mem_map
)), CHIP_MEM_W1_SYS_START(v
),
563 CHIP_MEM_W1_SYS_END(v
));
565 #ifdef CHIP_MEM_W2_BUS_START
566 printf("%s: sys window[2]=0x%lx-0x%lx\n",
567 __S(__C(CHIP
,_mem_map
)), CHIP_MEM_W2_SYS_START(v
),
568 CHIP_MEM_W2_SYS_END(v
));
570 #ifdef CHIP_MEM_W3_BUS_START
571 printf("%s: sys window[3]=0x%lx-0x%lx\n",
572 __S(__C(CHIP
,_mem_map
)), CHIP_MEM_W3_SYS_START(v
),
573 CHIP_MEM_W3_SYS_END(v
));
575 panic("%s: don't know how to unmap %lx",
576 __S(__C(CHIP
,_mem_unmap
)), memh
);
580 printf("mem: freeing 0x%lx to 0x%lx\n", memaddr
,
581 memaddr
+ memsize
- 1);
583 error
= extent_free(CHIP_MEM_EXTENT(v
), memaddr
, memsize
,
584 EX_NOWAIT
| (CHIP_EX_MALLOC_SAFE(v
) ? EX_MALLOCOK
: 0));
586 printf("%s: WARNING: could not unmap 0x%lx-0x%lx (error %d)\n",
587 __S(__C(CHIP
,_mem_unmap
)), memaddr
, memaddr
+ memsize
- 1,
590 extent_print(CHIP_MEM_EXTENT(v
));
596 __C(CHIP
,_mem_subregion
)(v
, memh
, offset
, size
, nmemh
)
598 bus_space_handle_t memh
, *nmemh
;
599 bus_size_t offset
, size
;
602 *nmemh
= memh
+ (offset
<< CHIP_ALIGN_STRIDE
);
607 __C(CHIP
,_mem_alloc
)(v
, rstart
, rend
, size
, align
, boundary
, flags
,
610 bus_addr_t rstart
, rend
, *addrp
;
611 bus_size_t size
, align
, boundary
;
613 bus_space_handle_t
*bshp
;
615 struct mips_bus_space_translation mbst
;
618 #if CHIP_ALIGN_STRIDE != 0
619 int linear
= flags
& BUS_SPACE_MAP_LINEAR
;
622 * Can't map memory space linearly.
629 * Do the requested allocation.
632 printf("mem: allocating from 0x%lx to 0x%lx\n", rstart
, rend
);
634 error
= extent_alloc_subregion(CHIP_MEM_EXTENT(v
), rstart
, rend
,
635 size
, align
, boundary
,
636 EX_FAST
| EX_NOWAIT
| (CHIP_EX_MALLOC_SAFE(v
) ? EX_MALLOCOK
: 0),
640 printf("mem: allocation failed (%d)\n", error
);
641 extent_print(CHIP_MEM_EXTENT(v
));
647 printf("mem: allocated 0x%lx to 0x%lx\n", memaddr
,
651 error
= __C(CHIP
,_mem_translate
)(v
, memaddr
, size
, flags
, &mbst
);
653 (void) extent_free(CHIP_MEM_EXTENT(v
), memaddr
, size
,
654 EX_NOWAIT
| (CHIP_EX_MALLOC_SAFE(v
) ? EX_MALLOCOK
: 0));
659 if (flags
& BUS_SPACE_MAP_CACHEABLE
)
660 *bshp
= MIPS_PHYS_TO_KSEG0(mbst
.mbst_sys_start
+
661 (memaddr
- mbst
.mbst_bus_start
));
663 *bshp
= MIPS_PHYS_TO_KSEG1(mbst
.mbst_sys_start
+
664 (memaddr
- mbst
.mbst_bus_start
));
670 __C(CHIP
,_mem_free
)(v
, bsh
, size
)
672 bus_space_handle_t bsh
;
676 /* Unmap does all we need to do. */
677 __C(CHIP
,_mem_unmap
)(v
, bsh
, size
, 1);
681 __C(CHIP
,_mem_vaddr
)(v
, bsh
)
683 bus_space_handle_t bsh
;
686 #if CHIP_ALIGN_STRIDE != 0
687 /* Linear mappings not possible. */
690 return ((void *)bsh
);
695 __C(CHIP
,_mem_mmap
)(v
, addr
, off
, prot
, flags
)
702 struct mips_bus_space_translation mbst
;
706 * Get the translation for this address.
708 error
= __C(CHIP
,_mem_translate
)(v
, addr
, off
+ PAGE_SIZE
, flags
,
713 return (mips_btop(mbst
.mbst_sys_start
+
714 (addr
- mbst
.mbst_bus_start
) + off
));
718 __C(CHIP
,_mem_barrier
)(v
, h
, o
, l
, f
)
720 bus_space_handle_t h
;
726 if ((f
& BUS_SPACE_BARRIER_WRITE
) != 0)
731 __C(CHIP
,_mem_read_1
)(v
, memh
, off
)
733 bus_space_handle_t memh
;
736 u_int8_t
*ptr
= (void *)(memh
+ (off
<< CHIP_ALIGN_STRIDE
));
742 __C(CHIP
,_mem_read_2
)(v
, memh
, off
)
744 bus_space_handle_t memh
;
747 #if CHIP_ALIGN_STRIDE >= 1
748 u_int16_t
*ptr
= (void *)(memh
+ (off
<< (CHIP_ALIGN_STRIDE
- 1)));
750 u_int16_t
*ptr
= (void *)(memh
+ off
);
757 __C(CHIP
,_mem_read_4
)(v
, memh
, off
)
759 bus_space_handle_t memh
;
762 #if CHIP_ALIGN_STRIDE >= 2
763 u_int32_t
*ptr
= (void *)(memh
+ (off
<< (CHIP_ALIGN_STRIDE
- 2)));
765 u_int32_t
*ptr
= (void *)(memh
+ off
);
772 __C(CHIP
,_mem_read_8
)(v
, memh
, off
)
774 bus_space_handle_t memh
;
779 panic("%s not implemented", __S(__C(CHIP
,_mem_read_8
)));
782 #define CHIP_mem_read_multi_N(BYTES,TYPE) \
784 __C(__C(CHIP,_mem_read_multi_),BYTES)(v, h, o, a, c) \
786 bus_space_handle_t h; \
792 __C(CHIP,_mem_barrier)(v, h, o, sizeof *a, \
793 BUS_SPACE_BARRIER_READ); \
794 *a++ = __C(__C(CHIP,_mem_read_),BYTES)(v, h, o); \
797 CHIP_mem_read_multi_N(1,u_int8_t
)
798 CHIP_mem_read_multi_N(2,u_int16_t
)
799 CHIP_mem_read_multi_N(4,u_int32_t
)
800 CHIP_mem_read_multi_N(8,u_int64_t
)
802 #define CHIP_mem_read_region_N(BYTES,TYPE) \
804 __C(__C(CHIP,_mem_read_region_),BYTES)(v, h, o, a, c) \
806 bus_space_handle_t h; \
812 *a++ = __C(__C(CHIP,_mem_read_),BYTES)(v, h, o); \
816 CHIP_mem_read_region_N(1,u_int8_t
)
817 CHIP_mem_read_region_N(2,u_int16_t
)
818 CHIP_mem_read_region_N(4,u_int32_t
)
819 CHIP_mem_read_region_N(8,u_int64_t
)
822 __C(CHIP
,_mem_write_1
)(v
, memh
, off
, val
)
824 bus_space_handle_t memh
;
828 u_int8_t
*ptr
= (void *)(memh
+ (off
<< CHIP_ALIGN_STRIDE
));
834 __C(CHIP
,_mem_write_2
)(v
, memh
, off
, val
)
836 bus_space_handle_t memh
;
840 #if CHIP_ALIGN_STRIDE >= 1
841 u_int16_t
*ptr
= (void *)(memh
+ (off
<< (CHIP_ALIGN_STRIDE
- 1)));
843 u_int16_t
*ptr
= (void *)(memh
+ off
);
850 __C(CHIP
,_mem_write_4
)(v
, memh
, off
, val
)
852 bus_space_handle_t memh
;
856 #if CHIP_ALIGN_STRIDE >= 2
857 u_int32_t
*ptr
= (void *)(memh
+ (off
<< (CHIP_ALIGN_STRIDE
- 2)));
859 u_int32_t
*ptr
= (void *)(memh
+ off
);
866 __C(CHIP
,_mem_write_8
)(v
, memh
, off
, val
)
868 bus_space_handle_t memh
;
874 panic("%s not implemented", __S(__C(CHIP
,_mem_write_8
)));
877 #define CHIP_mem_write_multi_N(BYTES,TYPE) \
879 __C(__C(CHIP,_mem_write_multi_),BYTES)(v, h, o, a, c) \
881 bus_space_handle_t h; \
887 __C(__C(CHIP,_mem_write_),BYTES)(v, h, o, *a++); \
888 __C(CHIP,_mem_barrier)(v, h, o, sizeof *a, \
889 BUS_SPACE_BARRIER_WRITE); \
892 CHIP_mem_write_multi_N(1,u_int8_t
)
893 CHIP_mem_write_multi_N(2,u_int16_t
)
894 CHIP_mem_write_multi_N(4,u_int32_t
)
895 CHIP_mem_write_multi_N(8,u_int64_t
)
897 #define CHIP_mem_write_region_N(BYTES,TYPE) \
899 __C(__C(CHIP,_mem_write_region_),BYTES)(v, h, o, a, c) \
901 bus_space_handle_t h; \
907 __C(__C(CHIP,_mem_write_),BYTES)(v, h, o, *a++); \
911 CHIP_mem_write_region_N(1,u_int8_t
)
912 CHIP_mem_write_region_N(2,u_int16_t
)
913 CHIP_mem_write_region_N(4,u_int32_t
)
914 CHIP_mem_write_region_N(8,u_int64_t
)
916 #define CHIP_mem_set_multi_N(BYTES,TYPE) \
918 __C(__C(CHIP,_mem_set_multi_),BYTES)(v, h, o, val, c) \
920 bus_space_handle_t h; \
926 __C(__C(CHIP,_mem_write_),BYTES)(v, h, o, val); \
927 __C(CHIP,_mem_barrier)(v, h, o, sizeof val, \
928 BUS_SPACE_BARRIER_WRITE); \
931 CHIP_mem_set_multi_N(1,u_int8_t
)
932 CHIP_mem_set_multi_N(2,u_int16_t
)
933 CHIP_mem_set_multi_N(4,u_int32_t
)
934 CHIP_mem_set_multi_N(8,u_int64_t
)
936 #define CHIP_mem_set_region_N(BYTES,TYPE) \
938 __C(__C(CHIP,_mem_set_region_),BYTES)(v, h, o, val, c) \
940 bus_space_handle_t h; \
946 __C(__C(CHIP,_mem_write_),BYTES)(v, h, o, val); \
950 CHIP_mem_set_region_N(1,u_int8_t
)
951 CHIP_mem_set_region_N(2,u_int16_t
)
952 CHIP_mem_set_region_N(4,u_int32_t
)
953 CHIP_mem_set_region_N(8,u_int64_t
)
955 #define CHIP_mem_copy_region_N(BYTES) \
957 __C(__C(CHIP,_mem_copy_region_),BYTES)(v, h1, o1, h2, o2, c) \
959 bus_space_handle_t h1, h2; \
960 bus_size_t o1, o2, c; \
964 if ((h1 + o1) >= (h2 + o2)) { \
965 /* src after dest: copy forward */ \
966 for (o = 0; c != 0; c--, o += BYTES) \
967 __C(__C(CHIP,_mem_write_),BYTES)(v, h2, o2 + o, \
968 __C(__C(CHIP,_mem_read_),BYTES)(v, h1, o1 + o)); \
970 /* dest after src: copy backwards */ \
971 for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES) \
972 __C(__C(CHIP,_mem_write_),BYTES)(v, h2, o2 + o, \
973 __C(__C(CHIP,_mem_read_),BYTES)(v, h1, o1 + o)); \
976 CHIP_mem_copy_region_N(1)
977 CHIP_mem_copy_region_N(2)
978 CHIP_mem_copy_region_N(4)
979 CHIP_mem_copy_region_N(8)