| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: amiga_init.c,v 1.103 2008/12/31 19:54:40 tsutsui Exp $ */ | | 1 | /* $NetBSD: amiga_init.c,v 1.104 2009/01/03 07:04:42 tsutsui Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1994 Michael L. Hitch | | 4 | * Copyright (c) 1994 Michael L. Hitch |
5 | * Copyright (c) 1993 Markus Wild | | 5 | * Copyright (c) 1993 Markus Wild |
6 | * All rights reserved. | | 6 | * All rights reserved. |
7 | * | | 7 | * |
8 | * Redistribution and use in source and binary forms, with or without | | 8 | * Redistribution and use in source and binary forms, with or without |
9 | * modification, are permitted provided that the following conditions | | 9 | * modification, are permitted provided that the following conditions |
10 | * are met: | | 10 | * are met: |
11 | * 1. Redistributions of source code must retain the above copyright | | 11 | * 1. Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. | | 12 | * notice, this list of conditions and the following disclaimer. |
13 | * 2. Redistributions in binary form must reproduce the above copyright | | 13 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | | 14 | * notice, this list of conditions and the following disclaimer in the |
| @@ -26,27 +26,27 @@ | | | @@ -26,27 +26,27 @@ |
26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
27 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 27 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
31 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 31 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
32 | */ | | 32 | */ |
33 | | | 33 | |
34 | #include "opt_amigaccgrf.h" | | 34 | #include "opt_amigaccgrf.h" |
35 | #include "opt_p5ppc68kboard.h" | | 35 | #include "opt_p5ppc68kboard.h" |
36 | #include "opt_devreload.h" | | 36 | #include "opt_devreload.h" |
37 | | | 37 | |
38 | #include <sys/cdefs.h> | | 38 | #include <sys/cdefs.h> |
39 | __KERNEL_RCSID(0, "$NetBSD: amiga_init.c,v 1.103 2008/12/31 19:54:40 tsutsui Exp $"); | | 39 | __KERNEL_RCSID(0, "$NetBSD: amiga_init.c,v 1.104 2009/01/03 07:04:42 tsutsui Exp $"); |
40 | | | 40 | |
41 | #include <sys/param.h> | | 41 | #include <sys/param.h> |
42 | #include <sys/systm.h> | | 42 | #include <sys/systm.h> |
43 | #include <sys/proc.h> | | 43 | #include <sys/proc.h> |
44 | #include <uvm/uvm_extern.h> | | 44 | #include <uvm/uvm_extern.h> |
45 | #include <sys/user.h> | | 45 | #include <sys/user.h> |
46 | #include <sys/ioctl.h> | | 46 | #include <sys/ioctl.h> |
47 | #include <sys/select.h> | | 47 | #include <sys/select.h> |
48 | #include <sys/tty.h> | | 48 | #include <sys/tty.h> |
49 | #include <sys/buf.h> | | 49 | #include <sys/buf.h> |
50 | #include <sys/msgbuf.h> | | 50 | #include <sys/msgbuf.h> |
51 | #include <sys/mbuf.h> | | 51 | #include <sys/mbuf.h> |
52 | #include <sys/protosw.h> | | 52 | #include <sys/protosw.h> |
| @@ -208,26 +208,29 @@ start_c(id, fphystart, fphysize, cphysiz | | | @@ -208,26 +208,29 @@ start_c(id, fphystart, fphysize, cphysiz |
208 | extern u_int protorp[2]; | | 208 | extern u_int protorp[2]; |
209 | struct cfdev *cd; | | 209 | struct cfdev *cd; |
210 | paddr_t pstart, pend; | | 210 | paddr_t pstart, pend; |
211 | vaddr_t vstart, vend; | | 211 | vaddr_t vstart, vend; |
212 | psize_t avail; | | 212 | psize_t avail; |
213 | paddr_t ptpa; | | 213 | paddr_t ptpa; |
214 | psize_t ptsize; | | 214 | psize_t ptsize; |
215 | u_int ptextra, kstsize; | | 215 | u_int ptextra, kstsize; |
216 | paddr_t Sysptmap_pa; | | 216 | paddr_t Sysptmap_pa; |
217 | register st_entry_t sg_proto, *sg, *esg; | | 217 | register st_entry_t sg_proto, *sg, *esg; |
218 | register pt_entry_t pg_proto, *pg, *epg; | | 218 | register pt_entry_t pg_proto, *pg, *epg; |
219 | vaddr_t end_loaded; | | 219 | vaddr_t end_loaded; |
220 | u_int ncd, i; | | 220 | u_int ncd, i; |
| | | 221 | #if defined(M68040) || defined(M68060) |
| | | 222 | u_int nl1desc, nl2desc; |
| | | 223 | #endif |
221 | vaddr_t kva; | | 224 | vaddr_t kva; |
222 | struct boot_memlist *ml; | | 225 | struct boot_memlist *ml; |
223 | | | 226 | |
224 | #ifdef DEBUG_KERNEL_START | | 227 | #ifdef DEBUG_KERNEL_START |
225 | /* XXX this only is valid if Altais is in slot 0 */ | | 228 | /* XXX this only is valid if Altais is in slot 0 */ |
226 | volatile u_int8_t *altaiscolpt = (u_int8_t *)0x200003c8; | | 229 | volatile u_int8_t *altaiscolpt = (u_int8_t *)0x200003c8; |
227 | volatile u_int8_t *altaiscol = (u_int8_t *)0x200003c9; | | 230 | volatile u_int8_t *altaiscol = (u_int8_t *)0x200003c9; |
228 | #endif | | 231 | #endif |
229 | | | 232 | |
230 | #ifdef DEBUG_KERNEL_START | | 233 | #ifdef DEBUG_KERNEL_START |
231 | if ((id>>24)==0x7D) { | | 234 | if ((id>>24)==0x7D) { |
232 | *altaiscolpt = 0; | | 235 | *altaiscolpt = 0; |
233 | *altaiscol = 40; | | 236 | *altaiscol = 40; |
| @@ -422,70 +425,72 @@ start_c(id, fphystart, fphysize, cphysiz | | | @@ -422,70 +425,72 @@ start_c(id, fphystart, fphysize, cphysiz |
422 | */ | | 425 | */ |
423 | sg = (st_entry_t *)RELOC(Sysseg_pa, u_int); | | 426 | sg = (st_entry_t *)RELOC(Sysseg_pa, u_int); |
424 | esg = &sg[kstsize * NPTEPG]; | | 427 | esg = &sg[kstsize * NPTEPG]; |
425 | while (sg < esg) | | 428 | while (sg < esg) |
426 | *sg++ = SG_NV; | | 429 | *sg++ = SG_NV; |
427 | /* | | 430 | /* |
428 | * Initialize level 2 descriptors (which immediately | | 431 | * Initialize level 2 descriptors (which immediately |
429 | * follow the level 1 table). We need: | | 432 | * follow the level 1 table). We need: |
430 | * NPTEPG / SG4_LEV3SIZE | | 433 | * NPTEPG / SG4_LEV3SIZE |
431 | * level 2 descriptors to map each of the nptpages | | 434 | * level 2 descriptors to map each of the nptpages |
432 | * pages of PTEs. Note that we set the "used" bit | | 435 | * pages of PTEs. Note that we set the "used" bit |
433 | * now to save the HW the expense of doing it. | | 436 | * now to save the HW the expense of doing it. |
434 | */ | | 437 | */ |
435 | i = (ptsize >> PGSHIFT) * (NPTEPG / SG4_LEV3SIZE); | | 438 | nl2desc = (ptsize >> PGSHIFT) * (NPTEPG / SG4_LEV3SIZE); |
436 | sg = &((st_entry_t *)(RELOC(Sysseg_pa, u_int)))[SG4_LEV1SIZE]; | | 439 | sg = (st_entry_t *)RELOC(Sysseg_pa, u_int); |
437 | esg = &sg[i]; | | 440 | sg = &sg[SG4_LEV1SIZE]; |
| | | 441 | esg = &sg[nl2desc]; |
438 | sg_proto = ptpa | SG_U | SG_RW | SG_V; | | 442 | sg_proto = ptpa | SG_U | SG_RW | SG_V; |
439 | while (sg < esg) { | | 443 | while (sg < esg) { |
440 | *sg++ = sg_proto; | | 444 | *sg++ = sg_proto; |
441 | sg_proto += (SG4_LEV3SIZE * sizeof (st_entry_t)); | | 445 | sg_proto += (SG4_LEV3SIZE * sizeof (st_entry_t)); |
442 | } | | 446 | } |
443 | | | 447 | |
444 | /* | | 448 | /* |
445 | * Initialize level 1 descriptors. We need: | | 449 | * Initialize level 1 descriptors. We need: |
446 | * roundup(num, SG4_LEV2SIZE) / SG4_LEVEL2SIZE | | 450 | * roundup(nl2desc, SG4_LEV2SIZE) / SG4_LEVEL2SIZE |
447 | * level 1 descriptors to map the 'num' level 2's. | | 451 | * level 1 descriptors to map the 'nl2desc' level 2's. |
448 | */ | | 452 | */ |
449 | i = roundup(i, SG4_LEV2SIZE) / SG4_LEV2SIZE; | | 453 | nl1desc = roundup(nl2desc, SG4_LEV2SIZE) / SG4_LEV2SIZE; |
450 | /* Include additional level 2 table for Sysmap in protostfree */ | | | |
451 | RELOC(protostfree, u_int) = | | | |
452 | (-1 << (i + 2)) /* & ~(-1 << MAXKL2SIZE) */; | | | |
453 | sg = (st_entry_t *)RELOC(Sysseg_pa, u_int); | | 454 | sg = (st_entry_t *)RELOC(Sysseg_pa, u_int); |
454 | esg = &sg[i]; | | 455 | esg = &sg[nl1desc]; |
455 | sg_proto = (paddr_t)&sg[SG4_LEV1SIZE] | SG_U | SG_RW | SG_V; | | 456 | sg_proto = (paddr_t)&sg[SG4_LEV1SIZE] | SG_U | SG_RW | SG_V; |
456 | while (sg < esg) { | | 457 | while (sg < esg) { |
457 | *sg++ = sg_proto; | | 458 | *sg++ = sg_proto; |
458 | sg_proto += (SG4_LEV2SIZE * sizeof(st_entry_t)); | | 459 | sg_proto += (SG4_LEV2SIZE * sizeof(st_entry_t)); |
459 | } | | 460 | } |
460 | | | 461 | |
461 | /* Sysmap is last entry in level 1 */ | | 462 | /* Sysmap is last entry in level 1 */ |
462 | sg = (st_entry_t *)RELOC(Sysseg_pa, u_int); | | 463 | sg = (st_entry_t *)RELOC(Sysseg_pa, u_int); |
463 | sg = &sg[SG4_LEV1SIZE - 1]; | | 464 | sg = &sg[SG4_LEV1SIZE - 1]; |
464 | *sg = sg_proto; | | 465 | *sg = sg_proto; |
465 | | | 466 | |
466 | /* | | 467 | /* |
467 | * Kernel segment table at end of next level 2 table | | 468 | * Kernel segment table at end of next level 2 table |
468 | */ | | 469 | */ |
469 | /* XXX fix calculations XXX */ | | 470 | i = SG4_LEV1SIZE + (nl1desc * SG4_LEV2SIZE); |
470 | i = ((((ptsize >> PGSHIFT) + 3) & -2) - 1) * (NPTEPG / SG4_LEV3SIZE); | | 471 | sg = (st_entry_t *)RELOC(Sysseg_pa, u_int); |
471 | sg = &((st_entry_t *)(RELOC(Sysseg_pa, u_int)))[SG4_LEV1SIZE + i]; | | 472 | sg = &sg[i + SG4_LEV2SIZE - (NPTEPG / SG4_LEV3SIZE)]; |
472 | esg = &sg[NPTEPG / SG4_LEV3SIZE]; | | 473 | esg = &sg[NPTEPG / SG4_LEV3SIZE]; |
473 | sg_proto = Sysptmap_pa | SG_U | SG_RW | SG_V; | | 474 | sg_proto = Sysptmap_pa | SG_U | SG_RW | SG_V; |
474 | while (sg < esg) { | | 475 | while (sg < esg) { |
475 | *sg++ = sg_proto; | | 476 | *sg++ = sg_proto; |
476 | sg_proto += (SG4_LEV3SIZE * sizeof (st_entry_t)); | | 477 | sg_proto += (SG4_LEV3SIZE * sizeof (st_entry_t)); |
477 | } | | 478 | } |
478 | | | 479 | |
| | | 480 | /* Include additional level 2 table for Sysmap in protostfree */ |
| | | 481 | RELOC(protostfree, u_int) = |
| | | 482 | (~0 << (1 + nl1desc + 1)) /* & ~(~0 << MAXKL2SIZE) */; |
| | | 483 | |
479 | /* | | 484 | /* |
480 | * Initialize Sysptmap | | 485 | * Initialize Sysptmap |
481 | */ | | 486 | */ |
482 | pg = (pt_entry_t *)Sysptmap_pa; | | 487 | pg = (pt_entry_t *)Sysptmap_pa; |
483 | epg = &pg[ptsize >> PGSHIFT]; | | 488 | epg = &pg[ptsize >> PGSHIFT]; |
484 | pg_proto = ptpa | PG_RW | PG_CI | PG_V; | | 489 | pg_proto = ptpa | PG_RW | PG_CI | PG_V; |
485 | while (pg < epg) { | | 490 | while (pg < epg) { |
486 | *pg++ = pg_proto; | | 491 | *pg++ = pg_proto; |
487 | pg_proto += PAGE_SIZE; | | 492 | pg_proto += PAGE_SIZE; |
488 | } | | 493 | } |
489 | /* | | 494 | /* |
490 | * Invalidate rest of Sysptmap page | | 495 | * Invalidate rest of Sysptmap page |
491 | */ | | 496 | */ |