1 /* $NetBSD: machdep.c,v 1.42 2009/11/26 00:19:17 matt Exp $ */
4 * Copyright 2001, 2002 Wasabi Systems, Inc.
7 * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the NetBSD Project by
20 * Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
39 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
40 * Copyright (C) 1995, 1996 TooLs GmbH.
41 * All rights reserved.
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. All advertising materials mentioning features or use of this software
52 * must display the following acknowledgement:
53 * This product includes software developed by TooLs GmbH.
54 * 4. The name of TooLs GmbH may not be used to endorse or promote products
55 * derived from this software without specific prior written permission.
57 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
58 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
59 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
60 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
61 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
62 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
63 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
64 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
65 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
66 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
69 #include <sys/cdefs.h>
70 __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.42 2009/11/26 00:19:17 matt Exp $");
72 #include "opt_compat_netbsd.h"
74 #include "opt_ipkdb.h"
75 #include "opt_modular.h"
77 #include <sys/param.h>
80 #include <sys/malloc.h>
82 #include <sys/mount.h>
83 #include <sys/msgbuf.h>
85 #include <sys/reboot.h>
86 #include <sys/syscallargs.h>
87 #include <sys/syslog.h>
88 #include <sys/systm.h>
89 #include <sys/kernel.h>
90 #include <sys/boot_flag.h>
91 #include <sys/ksyms.h>
92 #include <sys/device.h>
94 #include <uvm/uvm_extern.h>
96 #include <net/netisr.h>
98 #include <prop/proplib.h>
100 #include <machine/bus.h>
101 #include <machine/powerpc.h>
102 #include <machine/trap.h>
103 #include <machine/walnut.h>
105 #include <powerpc/spr.h>
106 #include <powerpc/ibm4xx/dcr405gp.h>
108 #include <dev/cons.h>
113 #include <machine/db_machdep.h>
114 #include <ddb/db_extern.h>
118 #define TLB_PG_SIZE (16*1024*1024)
121 * Global variables used here and there
123 struct vm_map
*mb_map
= NULL
;
124 struct vm_map
*phys_map
= NULL
;
127 * This should probably be in autoconf! XXX
130 char machine
[] = MACHINE
; /* from <machine/param.h> */
131 char machine_arch
[] = MACHINE_ARCH
; /* from <machine/param.h> */
134 paddr_t msgbuf_paddr
;
135 vaddr_t msgbuf_vaddr
;
137 #if NKSYMS || defined(DDB) || defined(MODULAR)
138 void *startsym
, *endsym
;
142 void initppc(u_int
, u_int
, char *, void *);
144 static void dumpsys(void);
145 static void install_extint(void (*)(void));
148 struct mem_region physmemr
[MEMREGIONS
]; /* Hard code memory */
149 struct mem_region availmemr
[MEMREGIONS
]; /* Who's supposed to set these up? */
151 struct board_cfg_data board_data
;
154 initppc(u_int startkernel
, u_int endkernel
, char *args
, void *info_block
)
156 extern int defaulttrap
, defaultsize
;
157 extern int sctrap
, scsize
;
158 extern int alitrap
, alisize
;
159 extern int dsitrap
, dsisize
;
160 extern int isitrap
, isisize
;
161 extern int mchktrap
, mchksize
;
162 extern int tlbimiss4xx
, tlbim4size
;
163 extern int tlbdmiss4xx
, tlbdm4size
;
164 extern int pitfitwdog
, pitfitwdogsize
;
165 extern int debugtrap
, debugsize
;
166 extern int errata51handler
, errata51size
;
168 extern int ddblow
, ddbsize
;
171 extern int ipkdblow
, ipkdbsize
;
175 struct cpu_info
* const ci
= curcpu();
177 /* Disable all external interrupts */
178 mtdcr(DCR_UIC0_ER
, 0);
180 /* Initialize cache info for memcpy, etc. */
183 /* Save info block */
184 memcpy(&board_data
, info_block
, sizeof(board_data
));
186 memset(physmemr
, 0, sizeof physmemr
);
187 memset(availmemr
, 0, sizeof availmemr
);
188 physmemr
[0].start
= 0;
189 physmemr
[0].size
= board_data
.mem_size
& ~PGOFSET
;
190 /* Lower memory reserved by eval board BIOS */
191 availmemr
[0].start
= startkernel
;
192 availmemr
[0].size
= board_data
.mem_size
- availmemr
[0].start
;
194 /* Linear map kernel memory */
195 for (va
= 0; va
< endkernel
; va
+= TLB_PG_SIZE
)
196 ppc4xx_tlb_reserve(va
, va
, TLB_PG_SIZE
, TLB_EX
);
198 /* Map console after physmem (see pmap_tlbmiss()) */
199 ppc4xx_tlb_reserve(0xef000000, roundup(physmemr
[0].size
, TLB_PG_SIZE
),
200 TLB_PG_SIZE
, TLB_I
| TLB_G
);
203 * Initialize lwp0 and current pcb and pmap pointers.
207 curpcb
= lwp_getpcb(&lwp0
);
208 memset(curpcb
, 0, sizeof(struct pcb
));
209 curpcb
->pcb_pm
= pmap_kernel();
212 * Set up trap vectors
214 for (exc
= EXC_RSVD
; exc
<= EXC_LAST
; exc
+= 0x100)
217 memcpy((void *)exc
, &defaulttrap
, (size_t)&defaultsize
);
221 * This one is (potentially) installed during autoconf
225 memcpy((void *)EXC_SC
, &sctrap
, (size_t)&scsize
);
228 memcpy((void *)EXC_ALI
, &alitrap
, (size_t)&alisize
);
231 memcpy((void *)EXC_DSI
, &dsitrap
, (size_t)&dsisize
);
234 memcpy((void *)EXC_ISI
, &isitrap
, (size_t)&isisize
);
237 memcpy((void *)EXC_MCHK
, &mchktrap
, (size_t)&mchksize
);
240 memcpy((void *)EXC_ITMISS
, &tlbimiss4xx
,
241 (size_t)&tlbim4size
);
244 memcpy((void *)EXC_DTMISS
, &tlbdmiss4xx
,
245 (size_t)&tlbdm4size
);
248 * EXC_PIT, EXC_FIT, EXC_WDOG handlers
249 * are spaced by 0x10 bytes only..
252 memcpy((void *)EXC_PIT
, &pitfitwdog
,
253 (size_t)&pitfitwdogsize
);
256 memcpy((void *)EXC_DEBUG
, &debugtrap
,
259 case EXC_DTMISS
|EXC_ALI
:
260 /* PPC405GP Rev D errata item 51 */
261 memcpy((void *)(EXC_DTMISS
|EXC_ALI
), &errata51handler
,
262 (size_t)&errata51size
);
264 #if defined(DDB) || defined(IPKDB)
267 memcpy((void *)exc
, &ddblow
, (size_t)&ddbsize
);
269 memcpy((void *)exc
, &ipkdblow
, (size_t)&ipkdbsize
);
271 #endif /* DDB | IPKDB */
275 __syncicache((void *)EXC_RST
, EXC_LAST
- EXC_RST
+ 0x100);
276 mtspr(SPR_EVPR
, 0); /* Set Exception vector base */
280 /* Handle trap instruction as PGM exception */
281 __asm
volatile("mfspr %0,%1":"=r"(dbcr0
):"K"(SPR_DBCR0
));
282 __asm
volatile("mtspr %0,%1"::"K"(SPR_DBCR0
),"r"(dbcr0
& ~DBCR0_TDE
));
285 * external interrupt handler install
287 install_extint(ext_intr
);
290 * Now enable translation (and machine checks/recoverable interrupts).
292 __asm
volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0; isync"
293 : : "r"(0), "K"(PSL_IR
|PSL_DR
));
294 /* XXXX PSL_ME - With ME set kernel gets stuck... */
299 * Initialize pmap module.
301 pmap_bootstrap(startkernel
, endkernel
);
304 printf("Board config data:\n");
305 printf(" usr_config_ver = %s\n", board_data
.usr_config_ver
);
306 printf(" rom_sw_ver = %s\n", board_data
.rom_sw_ver
);
307 printf(" mem_size = %u\n", board_data
.mem_size
);
308 printf(" mac_address_local = %02x:%02x:%02x:%02x:%02x:%02x\n",
309 board_data
.mac_address_local
[0], board_data
.mac_address_local
[1],
310 board_data
.mac_address_local
[2], board_data
.mac_address_local
[3],
311 board_data
.mac_address_local
[4], board_data
.mac_address_local
[5]);
312 printf(" mac_address_pci = %02x:%02x:%02x:%02x:%02x:%02x\n",
313 board_data
.mac_address_pci
[0], board_data
.mac_address_pci
[1],
314 board_data
.mac_address_pci
[2], board_data
.mac_address_pci
[3],
315 board_data
.mac_address_pci
[4], board_data
.mac_address_pci
[5]);
316 printf(" processor_speed = %u\n", board_data
.processor_speed
);
317 printf(" plb_speed = %u\n", board_data
.plb_speed
);
318 printf(" pci_speed = %u\n", board_data
.pci_speed
);
321 #if NKSYMS || defined(DDB) || defined(MODULAR)
322 ksyms_addsyms_elf((int)((u_int
)endsym
- (u_int
)startsym
), startsym
, endsym
);
325 if (boothowto
& RB_KDB
)
333 if (boothowto
& RB_KDB
)
339 install_extint(void (*handler
)(void))
341 extern int extint
, extsize
;
342 extern u_long extint_call
;
343 u_long offset
= (u_long
)handler
- (u_long
)&extint_call
;
347 if (offset
> 0x1ffffff)
348 panic("install_extint: too far away");
350 __asm
volatile ("mfmsr %0; wrteei 0" : "=r"(msr
));
351 extint_call
= (extint_call
& 0xfc000003) | offset
;
352 memcpy((void *)EXC_EXI
, &extint
, (size_t)&extsize
);
353 __syncicache((void *)&extint_call
, sizeof extint_call
);
354 __syncicache((void *)EXC_EXI
, (int)&extsize
);
355 __asm
volatile ("mtmsr %0" :: "r"(msr
));
359 * Machine dependent startup code.
362 char msgbuf
[MSGBUFSIZE
];
367 vaddr_t minaddr
, maxaddr
;
373 * Initialize error message buffer (at end of core).
375 #if 0 /* For some reason this fails... --Artem
376 * Besides, do we really have to put it at the end of core?
377 * Let's use static buffer for now
379 if (!(msgbuf_vaddr
= uvm_km_alloc(kernel_map
, round_page(MSGBUFSIZE
), 0,
381 panic("startup: no room for message buffer");
382 for (i
= 0; i
< btoc(MSGBUFSIZE
); i
++)
383 pmap_kenter_pa(msgbuf_vaddr
+ i
* PAGE_SIZE
,
384 msgbuf_paddr
+ i
* PAGE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, 0);
385 initmsgbuf((void *)msgbuf_vaddr
, round_page(MSGBUFSIZE
));
387 initmsgbuf((void *)msgbuf
, round_page(MSGBUFSIZE
));
390 printf("%s%s", copyright
, version
);
391 printf("Walnut PowerPC 405GP Evaluation Board\n");
393 format_bytes(pbuf
, sizeof(pbuf
), ctob(physmem
));
394 printf("total memory = %s\n", pbuf
);
398 * Allocate a submap for physio
400 phys_map
= uvm_km_suballoc(kernel_map
, &minaddr
, &maxaddr
,
401 VM_PHYS_SIZE
, 0, false, NULL
);
404 * No need to allocate an mbuf cluster submap. Mbuf clusters
405 * are allocated via the pool allocator, and we use direct-mapped
409 format_bytes(pbuf
, sizeof(pbuf
), ptoa(uvmexp
.free
));
410 printf("avail memory = %s\n", pbuf
);
413 * Set up the board properties dictionary.
415 board_properties
= prop_dictionary_create();
416 KASSERT(board_properties
!= NULL
);
418 pn
= prop_number_create_integer(board_data
.mem_size
);
420 if (prop_dictionary_set(board_properties
, "mem-size", pn
) == false)
421 panic("setting mem-size");
422 prop_object_release(pn
);
424 pd
= prop_data_create_data_nocopy(board_data
.mac_address_local
,
425 sizeof(board_data
.mac_address_local
));
427 if (prop_dictionary_set(board_properties
, "emac0-mac-addr",
429 panic("setting emac0-mac-addr");
430 prop_object_release(pd
);
432 pd
= prop_data_create_data_nocopy(board_data
.mac_address_pci
,
433 sizeof(board_data
.mac_address_pci
));
435 if (prop_dictionary_set(board_properties
, "sip0-mac-addr",
437 panic("setting sip0-mac-addr");
438 prop_object_release(pd
);
440 pn
= prop_number_create_integer(board_data
.processor_speed
);
442 if (prop_dictionary_set(board_properties
, "processor-frequency",
444 panic("setting processor-frequency");
445 prop_object_release(pn
);
448 * Now that we have VM, malloc()s are OK in bus_space.
450 bus_space_mallocok();
459 printf("dumpsys: TBD\n");
463 * Halt or reboot the machine after syncing/dumping according to howto.
466 cpu_reboot(int howto
, char *what
)
469 static char str
[256];
470 char *ap
= str
, *ap1
= ap
;
473 if (!cold
&& !(howto
& RB_NOSYNC
) && !syncing
) {
475 vfs_shutdown(); /* sync */
476 resettodr(); /* set wall clock */
481 if (!cold
&& (howto
& RB_DUMP
))
486 pmf_system_shutdown(boothowto
);
488 if ((howto
& RB_POWERDOWN
) == RB_POWERDOWN
) {
489 /* Power off here if we know how...*/
492 if (howto
& RB_HALT
) {
493 printf("halted\n\n");
495 goto reboot
; /* XXX for now... */
498 printf("dropping to debugger\n");
504 printf("rebooting\n\n");
506 if (strlen(what
) > sizeof str
- 5)
507 printf("boot string too large, ignored\n");
510 ap1
= ap
= str
+ strlen(str
);
515 if (howto
& RB_SINGLE
)
523 /* flush cache for msgbuf */
524 __syncicache((void *)msgbuf_paddr
, round_page(MSGBUFSIZE
));
529 printf("ppc4xx_reset() failed!\n");
543 return spllower(ipl
); /* XXX */
547 mem_regions(struct mem_region
**mem
, struct mem_region
**avail
)