| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: mainbus.c,v 1.57 2009/12/02 13:45:13 skrll Exp $ */ | | 1 | /* $NetBSD: mainbus.c,v 1.58 2009/12/02 13:49:32 skrll Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Matthew Fredette. | | 8 | * by Matthew Fredette. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -48,51 +48,63 @@ | | | @@ -48,51 +48,63 @@ |
48 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 48 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
49 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 49 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
50 | * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, | | 50 | * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, |
51 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | | 51 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
52 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | | 52 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
53 | * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 53 | * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
54 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | | 54 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
55 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | | 55 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
56 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | 56 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
57 | * THE POSSIBILITY OF SUCH DAMAGE. | | 57 | * THE POSSIBILITY OF SUCH DAMAGE. |
58 | */ | | 58 | */ |
59 | | | 59 | |
60 | #include <sys/cdefs.h> | | 60 | #include <sys/cdefs.h> |
61 | __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.57 2009/12/02 13:45:13 skrll Exp $"); | | 61 | __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.58 2009/12/02 13:49:32 skrll Exp $"); |
62 | | | 62 | |
63 | #include "locators.h" | | 63 | #include "locators.h" |
64 | #include "power.h" | | 64 | #include "power.h" |
65 | | | 65 | |
66 | #include <sys/param.h> | | 66 | #include <sys/param.h> |
67 | #include <sys/systm.h> | | 67 | #include <sys/systm.h> |
68 | #include <sys/device.h> | | 68 | #include <sys/device.h> |
69 | #include <sys/reboot.h> | | 69 | #include <sys/reboot.h> |
70 | #include <sys/extent.h> | | 70 | #include <sys/extent.h> |
71 | #include <sys/mbuf.h> | | 71 | #include <sys/mbuf.h> |
72 | | | 72 | |
73 | #include <uvm/uvm_page.h> | | 73 | #include <uvm/uvm_page.h> |
74 | #include <uvm/uvm.h> | | 74 | #include <uvm/uvm.h> |
75 | | | 75 | |
76 | #include <machine/pdc.h> | | 76 | #include <machine/pdc.h> |
77 | #include <machine/iomod.h> | | 77 | #include <machine/iomod.h> |
78 | #include <machine/autoconf.h> | | 78 | #include <machine/autoconf.h> |
79 | | | 79 | |
80 | #include <hp700/hp700/machdep.h> | | 80 | #include <hp700/hp700/machdep.h> |
81 | #include <hp700/hp700/intr.h> | | 81 | #include <hp700/hp700/intr.h> |
82 | #include <hp700/dev/cpudevs.h> | | 82 | #include <hp700/dev/cpudevs.h> |
83 | | | 83 | |
84 | static struct pdc_hpa pdc_hpa PDC_ALIGNMENT; | | 84 | static struct pdc_hpa pdc_hpa PDC_ALIGNMENT; |
85 | | | 85 | |
| | | 86 | #ifdef MBUSDEBUG |
| | | 87 | |
| | | 88 | #define DPRINTF(s) do { \ |
| | | 89 | if (mbusdebug) \ |
| | | 90 | printf s; \ |
| | | 91 | } while(0) |
| | | 92 | |
| | | 93 | int mbusdebug = 1; |
| | | 94 | #else |
| | | 95 | #define DPRINTF(s) /* */ |
| | | 96 | #endif |
| | | 97 | |
86 | struct mainbus_softc { | | 98 | struct mainbus_softc { |
87 | device_t sc_dv; | | 99 | device_t sc_dv; |
88 | | | 100 | |
89 | hppa_hpa_t sc_hpa; | | 101 | hppa_hpa_t sc_hpa; |
90 | }; | | 102 | }; |
91 | | | 103 | |
92 | int mbmatch(device_t, cfdata_t, void *); | | 104 | int mbmatch(device_t, cfdata_t, void *); |
93 | void mbattach(device_t, device_t, void *); | | 105 | void mbattach(device_t, device_t, void *); |
94 | | | 106 | |
95 | CFATTACH_DECL_NEW(mainbus, sizeof(struct mainbus_softc), | | 107 | CFATTACH_DECL_NEW(mainbus, sizeof(struct mainbus_softc), |
96 | mbmatch, mbattach, NULL, NULL); | | 108 | mbmatch, mbattach, NULL, NULL); |
97 | | | 109 | |
98 | extern struct cfdriver mainbus_cd; | | 110 | extern struct cfdriver mainbus_cd; |
| @@ -168,26 +180,29 @@ int _bus_dmamap_load_buffer(bus_dma_tag_ | | | @@ -168,26 +180,29 @@ int _bus_dmamap_load_buffer(bus_dma_tag_ |
168 | bus_size_t buflen, struct vmspace *vm, int flags, paddr_t *lastaddrp, | | 180 | bus_size_t buflen, struct vmspace *vm, int flags, paddr_t *lastaddrp, |
169 | int *segp, int first); | | 181 | int *segp, int first); |
170 | | | 182 | |
171 | int | | 183 | int |
172 | mbus_add_mapping(bus_addr_t bpa, bus_size_t size, int flags, | | 184 | mbus_add_mapping(bus_addr_t bpa, bus_size_t size, int flags, |
173 | bus_space_handle_t *bshp) | | 185 | bus_space_handle_t *bshp) |
174 | { | | 186 | { |
175 | u_int frames; | | 187 | u_int frames; |
176 | #ifdef USE_BTLB | | 188 | #ifdef USE_BTLB |
177 | vsize_t btlb_size; | | 189 | vsize_t btlb_size; |
178 | int error; | | 190 | int error; |
179 | #endif /* USE_BTLB */ | | 191 | #endif /* USE_BTLB */ |
180 | | | 192 | |
| | | 193 | DPRINTF(("\n%s(%lx,%lx,%scachable,%p)\n", __func__, |
| | | 194 | bpa, size, flags? "" : "non", bshp)); |
| | | 195 | |
181 | /* | | 196 | /* |
182 | * We must be called with a page-aligned address in | | 197 | * We must be called with a page-aligned address in |
183 | * I/O space, and with a multiple of the page size. | | 198 | * I/O space, and with a multiple of the page size. |
184 | */ | | 199 | */ |
185 | KASSERT((bpa & PGOFSET) == 0); | | 200 | KASSERT((bpa & PGOFSET) == 0); |
186 | KASSERT(bpa >= HPPA_IOSPACE); | | 201 | KASSERT(bpa >= HPPA_IOSPACE); |
187 | KASSERT((size & PGOFSET) == 0); | | 202 | KASSERT((size & PGOFSET) == 0); |
188 | | | 203 | |
189 | /* | | 204 | /* |
190 | * Assume that this will succeed. | | 205 | * Assume that this will succeed. |
191 | */ | | 206 | */ |
192 | *bshp = bpa; | | 207 | *bshp = bpa; |
193 | | | 208 | |
| @@ -320,29 +335,29 @@ mbus_map(void *v, bus_addr_t bpa, bus_si | | | @@ -320,29 +335,29 @@ mbus_map(void *v, bus_addr_t bpa, bus_si |
320 | /* | | 335 | /* |
321 | * Allocate the region of I/O space. | | 336 | * Allocate the region of I/O space. |
322 | */ | | 337 | */ |
323 | error = extent_alloc_region(hp700_io_extent, bpa, size, EX_NOWAIT); | | 338 | error = extent_alloc_region(hp700_io_extent, bpa, size, EX_NOWAIT); |
324 | if (error) | | 339 | if (error) |
325 | return (error); | | 340 | return (error); |
326 | | | 341 | |
327 | /* | | 342 | /* |
328 | * Map the region of I/O space. | | 343 | * Map the region of I/O space. |
329 | */ | | 344 | */ |
330 | error = mbus_add_mapping(bpa, size, flags, bshp); | | 345 | error = mbus_add_mapping(bpa, size, flags, bshp); |
331 | *bshp |= offset; | | 346 | *bshp |= offset; |
332 | if (error) { | | 347 | if (error) { |
| | | 348 | DPRINTF(("bus_space_map: pa 0x%lx, size 0x%lx failed\n", |
| | | 349 | bpa, size)); |
333 | if (extent_free(hp700_io_extent, bpa, size, EX_NOWAIT)) { | | 350 | if (extent_free(hp700_io_extent, bpa, size, EX_NOWAIT)) { |
334 | printf ("bus_space_map: pa 0x%lx, size 0x%lx\n", | | | |
335 | bpa, size); | | | |
336 | printf ("bus_space_map: can't free region\n"); | | 351 | printf ("bus_space_map: can't free region\n"); |
337 | } | | 352 | } |
338 | } | | 353 | } |
339 | | | 354 | |
340 | return error; | | 355 | return error; |
341 | } | | 356 | } |
342 | | | 357 | |
343 | void | | 358 | void |
344 | mbus_unmap(void *v, bus_space_handle_t bsh, bus_size_t size) | | 359 | mbus_unmap(void *v, bus_space_handle_t bsh, bus_size_t size) |
345 | { | | 360 | { |
346 | bus_size_t offset; | | 361 | bus_size_t offset; |
347 | bus_addr_t bpa; | | 362 | bus_addr_t bpa; |
348 | int error; | | 363 | int error; |
| @@ -357,28 +372,28 @@ mbus_unmap(void *v, bus_space_handle_t b | | | @@ -357,28 +372,28 @@ mbus_unmap(void *v, bus_space_handle_t b |
357 | | | 372 | |
358 | /* | | 373 | /* |
359 | * Unmap the region of I/O space. | | 374 | * Unmap the region of I/O space. |
360 | */ | | 375 | */ |
361 | error = mbus_remove_mapping(bsh, size, &bpa); | | 376 | error = mbus_remove_mapping(bsh, size, &bpa); |
362 | if (error) | | 377 | if (error) |
363 | panic("mbus_unmap: can't unmap region (%d)", error); | | 378 | panic("mbus_unmap: can't unmap region (%d)", error); |
364 | | | 379 | |
365 | /* | | 380 | /* |
366 | * Free the region of I/O space. | | 381 | * Free the region of I/O space. |
367 | */ | | 382 | */ |
368 | error = extent_free(hp700_io_extent, bpa, size, EX_NOWAIT); | | 383 | error = extent_free(hp700_io_extent, bpa, size, EX_NOWAIT); |
369 | if (error) { | | 384 | if (error) { |
370 | printf("bus_space_unmap: ps 0x%lx, size 0x%lx\n", | | 385 | DPRINTF(("bus_space_unmap: ps 0x%lx, size 0x%lx\n", |
371 | bpa, size); | | 386 | bpa, size)); |
372 | panic("bus_space_unmap: can't free region (%d)", error); | | 387 | panic("bus_space_unmap: can't free region (%d)", error); |
373 | } | | 388 | } |
374 | } | | 389 | } |
375 | | | 390 | |
376 | int | | 391 | int |
377 | mbus_alloc(void *v, bus_addr_t rstart, bus_addr_t rend, bus_size_t size, | | 392 | mbus_alloc(void *v, bus_addr_t rstart, bus_addr_t rend, bus_size_t size, |
378 | bus_size_t align, bus_size_t boundary, int flags, bus_addr_t *addrp, | | 393 | bus_size_t align, bus_size_t boundary, int flags, bus_addr_t *addrp, |
379 | bus_space_handle_t *bshp) | | 394 | bus_space_handle_t *bshp) |
380 | { | | 395 | { |
381 | bus_addr_t bpa; | | 396 | bus_addr_t bpa; |
382 | int error; | | 397 | int error; |
383 | | | 398 | |
384 | if (rstart < hp700_io_extent->ex_start || | | 399 | if (rstart < hp700_io_extent->ex_start || |
| @@ -395,29 +410,29 @@ mbus_alloc(void *v, bus_addr_t rstart, b | | | @@ -395,29 +410,29 @@ mbus_alloc(void *v, bus_addr_t rstart, b |
395 | /* | | 410 | /* |
396 | * Allocate the region of I/O space. | | 411 | * Allocate the region of I/O space. |
397 | */ | | 412 | */ |
398 | error = extent_alloc_subregion1(hp700_io_extent, rstart, rend, size, | | 413 | error = extent_alloc_subregion1(hp700_io_extent, rstart, rend, size, |
399 | align, 0, boundary, EX_NOWAIT, &bpa); | | 414 | align, 0, boundary, EX_NOWAIT, &bpa); |
400 | if (error) | | 415 | if (error) |
401 | return (error); | | 416 | return (error); |
402 | | | 417 | |
403 | /* | | 418 | /* |
404 | * Map the region of I/O space. | | 419 | * Map the region of I/O space. |
405 | */ | | 420 | */ |
406 | error = mbus_add_mapping(bpa, size, flags, bshp); | | 421 | error = mbus_add_mapping(bpa, size, flags, bshp); |
407 | if (error) { | | 422 | if (error) { |
| | | 423 | DPRINTF(("bus_space_alloc: pa 0x%lx, size 0x%lx failed\n", |
| | | 424 | bpa, size)); |
408 | if (extent_free(hp700_io_extent, bpa, size, EX_NOWAIT)) { | | 425 | if (extent_free(hp700_io_extent, bpa, size, EX_NOWAIT)) { |
409 | printf("bus_space_alloc: pa 0x%lx, size 0x%lx\n", | | | |
410 | bpa, size); | | | |
411 | printf("bus_space_alloc: can't free region\n"); | | 426 | printf("bus_space_alloc: can't free region\n"); |
412 | } | | 427 | } |
413 | } | | 428 | } |
414 | | | 429 | |
415 | *addrp = bpa; | | 430 | *addrp = bpa; |
416 | | | 431 | |
417 | return error; | | 432 | return error; |
418 | } | | 433 | } |
419 | | | 434 | |
420 | void | | 435 | void |
421 | mbus_free(void *v, bus_space_handle_t h, bus_size_t size) | | 436 | mbus_free(void *v, bus_space_handle_t h, bus_size_t size) |
422 | { | | 437 | { |
423 | /* bus_space_unmap() does all that we need to do. */ | | 438 | /* bus_space_unmap() does all that we need to do. */ |