Home | History | Annotate | Line # | Download | only in pmppc
machdep.c revision 1.11
      1 /*	$NetBSD: machdep.c,v 1.11 2011/06/20 07:18:06 matt Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2002 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Lennart Augustsson (lennart (at) augustsson.net) at Sandburst Corp.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     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.
     18  *
     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.
     30  */
     31 
     32 /*
     33  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
     34  * Copyright (C) 1995, 1996 TooLs GmbH.
     35  * All rights reserved.
     36  *
     37  * Redistribution and use in source and binary forms, with or without
     38  * modification, are permitted provided that the following conditions
     39  * are met:
     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.
     50  *
     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.
     61  */
     62 
     63 #include <sys/cdefs.h>
     64 __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.11 2011/06/20 07:18:06 matt Exp $");
     65 
     66 #include "opt_compat_netbsd.h"
     67 #include "opt_ddb.h"
     68 #include "opt_ddbparam.h"
     69 #include "opt_inet.h"
     70 #include "opt_ccitt.h"
     71 #include "opt_iso.h"
     72 #include "opt_ns.h"
     73 #include "opt_ipkdb.h"
     74 
     75 #include <sys/param.h>
     76 #include <sys/buf.h>
     77 #include <sys/bus.h>
     78 #include <sys/conf.h>
     79 #include <sys/device.h>
     80 #include <sys/exec.h>
     81 #include <sys/extent.h>
     82 #include <sys/intr.h>
     83 #include <sys/kernel.h>
     84 #include <sys/kgdb.h>
     85 #include <sys/ksyms.h>
     86 #include <sys/malloc.h>
     87 #include <sys/mbuf.h>
     88 #include <sys/mount.h>
     89 #include <sys/msgbuf.h>
     90 #include <sys/proc.h>
     91 #include <sys/reboot.h>
     92 #include <sys/syscallargs.h>
     93 #include <sys/sysctl.h>
     94 #include <sys/syslog.h>
     95 #include <sys/systm.h>
     96 
     97 #include <uvm/uvm_extern.h>
     98 
     99 #include <machine/powerpc.h>
    100 #include <machine/pmppc.h>
    101 
    102 #include <powerpc/db_machdep.h>
    103 #include <powerpc/pio.h>
    104 #include <powerpc/pmap.h>
    105 #include <powerpc/trap.h>
    106 
    107 #include <powerpc/oea/bat.h>
    108 #include <powerpc/pic/picvar.h>
    109 
    110 #include <ddb/db_extern.h>
    111 
    112 #include <dev/cons.h>
    113 
    114 #include <dev/ic/cpc700reg.h>
    115 #include <dev/ic/cpc700uic.h>
    116 
    117 #include "com.h"
    118 #if (NCOM > 0)
    119 #include <sys/termios.h>
    120 #include <dev/ic/comreg.h>
    121 #include <dev/ic/comvar.h>
    122 #endif
    123 
    124 #include "ksyms.h"
    125 
    126 struct powerpc_bus_space pmppc_mem_tag = {
    127 	_BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
    128 	0, 0, 0xffffffff,
    129 	NULL,
    130 };
    131 struct powerpc_bus_space pmppc_pci_io_tag = {
    132 	_BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
    133 	0, CPC_PCI_IO_BASE, 0xffffffff,
    134 	NULL,
    135 };
    136 
    137 static char ex_storage[1][EXTENT_FIXED_STORAGE_SIZE(8)]
    138     __attribute__((aligned(8)));
    139 
    140 
    141 #ifdef KGDB
    142 char kgdb_devname[] = KGDB_DEVNAME;
    143 int comkgdbaddr = KGDB_DEVADDR;
    144 int comkgdbrate = KGDB_DEVRATE;
    145 
    146 #ifndef KGDB_DEVMODE
    147 #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    148 #endif
    149 int comkgdbmode = KGDB_DEVMODE;
    150 
    151 void kgdb_port_init(void);
    152 #endif /* KGDB */
    153 
    154 /*
    155  * Global variables used here and there
    156  */
    157 struct mem_region physmemr[2], availmemr[2];
    158 
    159 struct a_config a_config;
    160 
    161 void initppc(u_int, u_int, u_int, void *); /* Called from locore */
    162 void pmppc_setup(void);
    163 void setleds(int leds);
    164 
    165 void
    166 initppc(u_int startkernel, u_int endkernel, u_int args, void *btinfo)
    167 {
    168 	extern void consinit(void);
    169 	extern u_long ticks_per_sec;
    170 	extern unsigned char edata[], end[];
    171 
    172 	memset(&edata, 0, end - edata); /* clear BSS */
    173 
    174 	pmppc_setup();
    175 
    176 	physmemr[0].start = 0;
    177 	physmemr[0].size = a_config.a_mem_size;
    178 	physmemr[1].size = 0;
    179 	availmemr[0].start = (endkernel + PGOFSET) & ~PGOFSET;
    180 	availmemr[0].size = a_config.a_mem_size - availmemr[0].start;
    181 	availmemr[1].size = 0;
    182 
    183 #ifdef BOOTHOWTO
    184 	/*
    185 	 * boothowto
    186 	 */
    187 	boothowto = BOOTHOWTO;
    188 #endif
    189 
    190 	if (bus_space_init(&pmppc_mem_tag, "iomem",
    191 			   ex_storage[0], sizeof(ex_storage[0])))
    192 		panic("bus_space_init failed");
    193 
    194 	/*
    195 	 * Initialize the BAT registers
    196 	 */
    197 	oea_batinit(
    198 	    PMPPC_FLASH_BASE, BAT_BL_256M, /* flash (etc) memory 256M area */
    199 	    CPC_PCI_MEM_BASE, BAT_BL_256M, /* PCI memory 256M area */
    200 	    CPC_PCI_IO_BASE,  BAT_BL_128M, /* PCI I/O 128M area */
    201 	    0);
    202 
    203 	/*
    204 	 * Set up trap vectors
    205 	 */
    206 	oea_init(NULL);
    207 
    208 	/*
    209 	 * Get CPU clock
    210 	 */
    211 	ticks_per_sec = a_config.a_bus_freq;
    212 	ticks_per_sec /= 4;	/* 4 cycles per DEC tick */
    213 	cpu_timebase = ticks_per_sec;
    214 
    215 	/*
    216 	 * Set up console.
    217 	 */
    218 	consinit();		/* XXX should not be here */
    219 
    220 	printf("console set up\n");
    221 
    222         /*
    223 	 * Set the page size.
    224 	 */
    225 	uvm_setpagesize();
    226 
    227 	/*
    228 	 * Initialize pmap module.
    229 	 */
    230 	pmap_bootstrap(startkernel, endkernel);
    231 
    232 #ifdef IPKDB
    233 	/*
    234 	 * Now trap to IPKDB
    235 	 */
    236 	ipkdb_init();
    237 	if (boothowto & RB_KDB)
    238 		ipkdb_connect(0);
    239 #endif
    240 #ifdef KGDB
    241 	kgdb_port_init();
    242 	if (boothowto & RB_KDB) {
    243 		kgdb_debug_init = 1;
    244 		kgdb_connect(1);
    245 	}
    246 #endif
    247 }
    248 
    249 void
    250 mem_regions(struct mem_region **mem, struct mem_region **avail)
    251 {
    252 	*mem = physmemr;
    253 	*avail = availmemr;
    254 }
    255 
    256 /*
    257  * Machine dependent startup code.
    258  */
    259 void
    260 cpu_startup(void)
    261 {
    262 
    263 	oea_startup(NULL);
    264 
    265 	/*
    266 	 * Now that we have VM, malloc()s are OK in bus_space.
    267 	 */
    268 	bus_space_mallocok();
    269 
    270 	/* Set up the PCI bus tag. */
    271 	if (bus_space_init(&pmppc_pci_io_tag, "pcimem", NULL, 0))
    272 		panic("bus_space_init pci failed");
    273 
    274 	/* Set up interrupt controller */
    275 	cpc700_init_intr(&pmppc_mem_tag, CPC_UIC_BASE,
    276 	    CPC_INTR_MASK(PMPPC_I_ETH_INT), 0);
    277 
    278 	pic_init();
    279 	(void)setup_cpc700();
    280 	oea_install_extint(pic_ext_intr);
    281 
    282 #if 0
    283 /* XXX doesn't seem to be needed anymore */
    284 	/*
    285 	 * Now allow hardware interrupts.
    286 	 */
    287 	__asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0"
    288 	    : "=r"(msr) : "K"(PSL_EE));
    289 #endif
    290 }
    291 
    292 /*
    293  * consinit
    294  * Initialize system console.
    295  */
    296 void
    297 consinit(void)
    298 {
    299 	static int initted;
    300 #if (NCOM > 0)
    301 	bus_space_tag_t tag;
    302 #endif
    303 
    304 	if (initted)
    305 		return;
    306 	initted = 1;
    307 
    308 #if (NCOM > 0)
    309 	tag = &pmppc_mem_tag;
    310 
    311 	if(comcnattach(tag, CPC_COM0, 9600, CPC_COM_SPEED(a_config.a_bus_freq),
    312 	    COM_TYPE_NORMAL,
    313             ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8)))
    314 		panic("can't init serial console");
    315 	else
    316 		return;
    317 #endif
    318 
    319 	panic("console device missing -- serial console not in kernel");
    320 	/* Of course, this is moot if there is no console... */
    321 }
    322 
    323 #ifdef KGDB
    324 void
    325 kgdb_port_init(void)
    326 {
    327 #if (NCOM > 0)
    328 	if(!strcmp(kgdb_devname, "com")) {
    329 		bus_space_tag_t tag = &pmppc_mem_tag;
    330 		com_kgdb_attach(tag, comkgdbaddr, comkgdbrate,
    331 				CPC_COM_SPEED(a_config.a_bus_freq),
    332 				COM_TYPE_NORMAL, comkgdbmode);
    333 	}
    334 #endif
    335 }
    336 #endif
    337 
    338 /*
    339  * Halt or reboot the machine after syncing/dumping according to howto.
    340  */
    341 void
    342 cpu_reboot(int howto, char *what)
    343 {
    344 	static int syncing;
    345 	static char str[256];
    346 	char *ap = str, *ap1 = ap;
    347 	extern void disable_intr(void);
    348 
    349 	boothowto = howto;
    350 	if (!cold && !(howto & RB_NOSYNC) && !syncing) {
    351 		syncing = 1;
    352 		vfs_shutdown();		/* sync */
    353 		resettodr();		/* set wall clock */
    354 	}
    355 	splhigh();
    356 	if (howto & RB_HALT) {
    357 		doshutdownhooks();
    358 		pmf_system_shutdown(boothowto);
    359 		printf("halted\n\n");
    360 		while(1);
    361 	}
    362 	if (!cold && (howto & RB_DUMP))
    363 		oea_dumpsys();
    364 	doshutdownhooks();
    365 
    366 	pmf_system_shutdown(boothowto);
    367 	printf("rebooting\n\n");
    368 	if (what && *what) {
    369 		if (strlen(what) > sizeof str - 5)
    370 			printf("boot string too large, ignored\n");
    371 		else {
    372 			strcpy(str, what);
    373 			ap1 = ap = str + strlen(str);
    374 			*ap++ = ' ';
    375 		}
    376 	}
    377 	*ap++ = '-';
    378 	if (howto & RB_SINGLE)
    379 		*ap++ = 's';
    380 	if (howto & RB_KDB)
    381 		*ap++ = 'd';
    382 	*ap++ = 0;
    383 	if (ap[-2] == '-')
    384 		*ap1 = 0;
    385 
    386 	disable_intr();
    387 
    388         /* Write the two byte reset sequence to the reset register. */
    389 	out8(PMPPC_RESET, PMPPC_RESET_SEQ_STEP1);
    390 	out8(PMPPC_RESET, PMPPC_RESET_SEQ_STEP2);
    391 
    392 	while (1);
    393 }
    394 
    395 void
    396 setleds(int leds)
    397 {
    398 	out8(PMPPC_LEDS, leds);
    399 }
    400 
    401 void
    402 pmppc_setup(void)
    403 {
    404 	uint config0, config1;
    405 
    406 	config0 = in8(PMPPC_CONFIG0);
    407 	config1 = in8(PMPPC_CONFIG1);
    408 
    409 	/* from page 2-8 in the Artesyn User's manual */
    410 	a_config.a_boot_device = config1 & 0x80 ? A_BOOT_FLASH : A_BOOT_ROM;
    411 	a_config.a_has_ecc = (config1 & 0x40) != 0;
    412 	switch (config1 & 0x30) {
    413 	case 0x00: a_config.a_mem_size = 32 * 1024 * 1024; break;
    414 	case 0x10: a_config.a_mem_size = 64 * 1024 * 1024; break;
    415 	case 0x20: a_config.a_mem_size = 128 * 1024 * 1024; break;
    416 	case 0x30: a_config.a_mem_size = 256 * 1024 * 1024; break;
    417 	}
    418 	a_config.a_l2_cache = (config1 >> 2) & 3;
    419 	switch (config1 & 0x03) {
    420 	case 0x00: a_config.a_bus_freq = 66666666; break;
    421 	case 0x01: a_config.a_bus_freq = 83333333; break;
    422 	case 0x02: a_config.a_bus_freq = 100000000; break;
    423 	case 0x03: a_config.a_bus_freq = 0; break; /* XXX */
    424 	}
    425 	a_config.a_is_monarch = (config0 & 0x80) == 0;
    426 	a_config.a_has_eth = (config0 & 0x20) != 0;
    427 	a_config.a_has_rtc = (config0 & 0x10) == 0;
    428 	switch (config0 & 0x0c) {
    429 	case 0x00: a_config.a_flash_size = 256 * 1024 * 1024; break;
    430 	case 0x04: a_config.a_flash_size = 128 * 1024 * 1024; break;
    431 	case 0x08: a_config.a_flash_size = 64 * 1024 * 1024; break;
    432 	case 0x0c: a_config.a_flash_size = 32 * 1024 * 1024; break;
    433 	}
    434 	switch (config0 & 0x03) {
    435 	case 0x00: a_config.a_flash_width = 64; break;
    436 	case 0x01: a_config.a_flash_width = 32; break;
    437 	case 0x02: a_config.a_flash_width = 16; break;
    438 	case 0x03: a_config.a_flash_width = 0; break;
    439 	}
    440 }
    441