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