1 /* $NetBSD: machdep.c,v 1.7 2009/03/18 10:22:28 cegger Exp $ */
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (lennart@augustsson.net) at Sandburst Corp.
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 Wolfgang Solfrank.
34 * Copyright (C) 1995, 1996 TooLs GmbH.
35 * All rights reserved.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
45 * 3. All advertising materials mentioning features or use of this software
46 * must display the following acknowledgement:
47 * This product includes software developed by TooLs GmbH.
48 * 4. The name of TooLs GmbH may not be used to endorse or promote products
49 * derived from this software without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
52 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
53 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
54 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
56 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
57 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
58 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
59 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
60 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 #include <sys/cdefs.h>
64 __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.7 2009/03/18 10:22:28 cegger Exp $");
66 #include "opt_compat_netbsd.h"
68 #include "opt_ddbparam.h"
70 #include "opt_ccitt.h"
73 #include "opt_ipkdb.h"
75 #include <sys/param.h>
78 #include <sys/device.h>
80 #include <sys/extent.h>
81 #include <sys/kernel.h>
83 #include <sys/malloc.h>
85 #include <sys/mount.h>
86 #include <sys/msgbuf.h>
88 #include <sys/reboot.h>
89 #include <sys/syscallargs.h>
90 #include <sys/syslog.h>
91 #include <sys/sysctl.h>
92 #include <sys/systm.h>
93 #include <sys/ksyms.h>
96 #include <uvm/uvm_extern.h>
98 #include <net/netisr.h>
100 #include <machine/bus.h>
101 #include <machine/db_machdep.h>
102 #include <machine/intr.h>
103 #include <machine/pio.h>
104 #include <machine/pmap.h>
105 #include <machine/powerpc.h>
106 #include <machine/trap.h>
107 #include <machine/pmppc.h>
109 #include <powerpc/oea/bat.h>
110 #include <arch/powerpc/pic/picvar.h>
112 #include <ddb/db_extern.h>
114 #include <dev/cons.h>
116 #include <dev/ic/cpc700reg.h>
117 #include <dev/ic/cpc700uic.h>
121 #include <sys/termios.h>
122 #include <dev/ic/comreg.h>
123 #include <dev/ic/comvar.h>
128 struct powerpc_bus_space pmppc_mem_tag
= {
129 _BUS_SPACE_LITTLE_ENDIAN
|_BUS_SPACE_MEM_TYPE
,
133 struct powerpc_bus_space pmppc_pci_io_tag
= {
134 _BUS_SPACE_LITTLE_ENDIAN
|_BUS_SPACE_MEM_TYPE
,
135 0, CPC_PCI_IO_BASE
, 0xffffffff,
139 static char ex_storage
[1][EXTENT_FIXED_STORAGE_SIZE(8)]
140 __attribute__((aligned(8)));
144 char kgdb_devname
[] = KGDB_DEVNAME
;
145 int comkgdbaddr
= KGDB_DEVADDR
;
146 int comkgdbrate
= KGDB_DEVRATE
;
149 #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
151 int comkgdbmode
= KGDB_DEVMODE
;
153 void kgdb_port_init(void);
157 * Global variables used here and there
159 struct mem_region physmemr
[2], availmemr
[2];
161 struct a_config a_config
;
163 void initppc(u_int
, u_int
, u_int
, void *); /* Called from locore */
164 void pmppc_setup(void);
165 void setleds(int leds
);
168 * Force cpu_info to be in the data segment to avoid the
169 * memset() blowing away the data set up by locore.S.
172 /* this is defined in powerpc/oea/cpu_subr.c, I don't understand the above
175 struct cpu_info cpu_info
[1] = { { .ci_curlwp
= &lwp0
, }, };
179 initppc(u_int startkernel
, u_int endkernel
, u_int args
, void *btinfo
)
181 extern void consinit(void);
182 extern u_long ticks_per_sec
;
183 extern unsigned char edata
[], end
[];
185 memset(&edata
, 0, end
- edata
); /* clear BSS */
189 physmemr
[0].start
= 0;
190 physmemr
[0].size
= a_config
.a_mem_size
;
191 physmemr
[1].size
= 0;
192 availmemr
[0].start
= (endkernel
+ PGOFSET
) & ~PGOFSET
;
193 availmemr
[0].size
= a_config
.a_mem_size
- availmemr
[0].start
;
194 availmemr
[1].size
= 0;
200 boothowto
= BOOTHOWTO
;
203 if (bus_space_init(&pmppc_mem_tag
, "iomem",
204 ex_storage
[0], sizeof(ex_storage
[0])))
205 panic("bus_space_init failed");
210 ticks_per_sec
= a_config
.a_bus_freq
;
211 ticks_per_sec
/= 4; /* 4 cycles per DEC tick */
212 cpu_timebase
= ticks_per_sec
;
216 * Initialize the BAT registers
219 PMPPC_FLASH_BASE
, BAT_BL_256M
, /* flash (etc) memory 256M area */
220 CPC_PCI_MEM_BASE
, BAT_BL_256M
, /* PCI memory 256M area */
221 CPC_PCI_IO_BASE
, BAT_BL_128M
, /* PCI I/O 128M area */
225 * Set up trap vectors
232 consinit(); /* XXX should not be here */
234 printf("console set up\n");
242 * Initialize pmap module.
244 pmap_bootstrap(startkernel
, endkernel
);
251 if (boothowto
& RB_KDB
)
256 if (boothowto
& RB_KDB
) {
264 mem_regions(struct mem_region
**mem
, struct mem_region
**avail
)
271 * Machine dependent startup code.
280 * Now that we have VM, malloc()s are OK in bus_space.
282 bus_space_mallocok();
284 /* Set up the PCI bus tag. */
285 if (bus_space_init(&pmppc_pci_io_tag
, "pcimem", NULL
, 0))
286 panic("bus_space_init pci failed");
288 /* Set up interrupt controller */
289 cpc700_init_intr(&pmppc_mem_tag
, CPC_UIC_BASE
,
290 CPC_INTR_MASK(PMPPC_I_ETH_INT
), 0);
293 (void)setup_cpc700();
294 oea_install_extint(pic_ext_intr
);
297 /* XXX doesn't seem to be needed anymore */
299 * Now allow hardware interrupts.
301 __asm
volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0"
302 : "=r"(msr
) : "K"(PSL_EE
));
308 * Initialize system console.
323 tag
= &pmppc_mem_tag
;
325 if(comcnattach(tag
, CPC_COM0
, 9600, CPC_COM_SPEED(a_config
.a_bus_freq
),
327 ((TTYDEF_CFLAG
& ~(CSIZE
| CSTOPB
| PARENB
)) | CS8
)))
328 panic("can't init serial console");
333 panic("console device missing -- serial console not in kernel");
334 /* Of course, this is moot if there is no console... */
342 if(!strcmp(kgdb_devname
, "com")) {
343 bus_space_tag_t tag
= &pmppc_mem_tag
;
344 com_kgdb_attach(tag
, comkgdbaddr
, comkgdbrate
,
345 CPC_COM_SPEED(a_config
.a_bus_freq
),
346 COM_TYPE_NORMAL
, comkgdbmode
);
353 * Halt or reboot the machine after syncing/dumping according to howto.
356 cpu_reboot(int howto
, char *what
)
359 static char str
[256];
360 char *ap
= str
, *ap1
= ap
;
361 extern void disable_intr(void);
364 if (!cold
&& !(howto
& RB_NOSYNC
) && !syncing
) {
366 vfs_shutdown(); /* sync */
367 resettodr(); /* set wall clock */
370 if (howto
& RB_HALT
) {
372 pmf_system_shutdown(boothowto
);
373 printf("halted\n\n");
376 if (!cold
&& (howto
& RB_DUMP
))
380 pmf_system_shutdown(boothowto
);
381 printf("rebooting\n\n");
383 if (strlen(what
) > sizeof str
- 5)
384 printf("boot string too large, ignored\n");
387 ap1
= ap
= str
+ strlen(str
);
392 if (howto
& RB_SINGLE
)
402 /* Write the two byte reset sequence to the reset register. */
403 out8(PMPPC_RESET
, PMPPC_RESET_SEQ_STEP1
);
404 out8(PMPPC_RESET
, PMPPC_RESET_SEQ_STEP2
);
412 out8(PMPPC_LEDS
, leds
);
418 uint config0
, config1
;
420 config0
= in8(PMPPC_CONFIG0
);
421 config1
= in8(PMPPC_CONFIG1
);
423 /* from page 2-8 in the Artesyn User's manual */
424 a_config
.a_boot_device
= config1
& 0x80 ? A_BOOT_FLASH
: A_BOOT_ROM
;
425 a_config
.a_has_ecc
= (config1
& 0x40) != 0;
426 switch (config1
& 0x30) {
427 case 0x00: a_config
.a_mem_size
= 32 * 1024 * 1024; break;
428 case 0x10: a_config
.a_mem_size
= 64 * 1024 * 1024; break;
429 case 0x20: a_config
.a_mem_size
= 128 * 1024 * 1024; break;
430 case 0x30: a_config
.a_mem_size
= 256 * 1024 * 1024; break;
432 a_config
.a_l2_cache
= (config1
>> 2) & 3;
433 switch (config1
& 0x03) {
434 case 0x00: a_config
.a_bus_freq
= 66666666; break;
435 case 0x01: a_config
.a_bus_freq
= 83333333; break;
436 case 0x02: a_config
.a_bus_freq
= 100000000; break;
437 case 0x03: a_config
.a_bus_freq
= 0; break; /* XXX */
439 a_config
.a_is_monarch
= (config0
& 0x80) == 0;
440 a_config
.a_has_eth
= (config0
& 0x20) != 0;
441 a_config
.a_has_rtc
= (config0
& 0x10) == 0;
442 switch (config0
& 0x0c) {
443 case 0x00: a_config
.a_flash_size
= 256 * 1024 * 1024; break;
444 case 0x04: a_config
.a_flash_size
= 128 * 1024 * 1024; break;
445 case 0x08: a_config
.a_flash_size
= 64 * 1024 * 1024; break;
446 case 0x0c: a_config
.a_flash_size
= 32 * 1024 * 1024; break;
448 switch (config0
& 0x03) {
449 case 0x00: a_config
.a_flash_width
= 64; break;
450 case 0x01: a_config
.a_flash_width
= 32; break;
451 case 0x02: a_config
.a_flash_width
= 16; break;
452 case 0x03: a_config
.a_flash_width
= 0; break;