machdep.c revision 1.12
1/* $NetBSD: machdep.c,v 1.12 2013/03/01 18:25:39 joerg 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@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.12 2013/03/01 18:25:39 joerg 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 125struct powerpc_bus_space pmppc_mem_tag = { 126 _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE, 127 0, 0, 0xffffffff, 128 NULL, 129}; 130struct 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 136static char ex_storage[1][EXTENT_FIXED_STORAGE_SIZE(8)] 137 __attribute__((aligned(8))); 138 139 140#ifdef KGDB 141char kgdb_devname[] = KGDB_DEVNAME; 142int comkgdbaddr = KGDB_DEVADDR; 143int comkgdbrate = KGDB_DEVRATE; 144 145#ifndef KGDB_DEVMODE 146#define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ 147#endif 148int comkgdbmode = KGDB_DEVMODE; 149 150void kgdb_port_init(void); 151#endif /* KGDB */ 152 153/* 154 * Global variables used here and there 155 */ 156struct mem_region physmemr[2], availmemr[2]; 157 158struct a_config a_config; 159 160void initppc(u_int, u_int, u_int, void *); /* Called from locore */ 161void pmppc_setup(void); 162void setleds(int leds); 163 164void 165initppc(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 /* 222 * Set the page size. 223 */ 224 uvm_setpagesize(); 225 226 /* 227 * Initialize pmap module. 228 */ 229 pmap_bootstrap(startkernel, endkernel); 230 231#ifdef IPKDB 232 /* 233 * Now trap to IPKDB 234 */ 235 ipkdb_init(); 236 if (boothowto & RB_KDB) 237 ipkdb_connect(0); 238#endif 239#ifdef KGDB 240 kgdb_port_init(); 241 if (boothowto & RB_KDB) { 242 kgdb_debug_init = 1; 243 kgdb_connect(1); 244 } 245#endif 246} 247 248void 249mem_regions(struct mem_region **mem, struct mem_region **avail) 250{ 251 *mem = physmemr; 252 *avail = availmemr; 253} 254 255/* 256 * Machine dependent startup code. 257 */ 258void 259cpu_startup(void) 260{ 261 262 oea_startup(NULL); 263 264 /* 265 * Now that we have VM, malloc()s are OK in bus_space. 266 */ 267 bus_space_mallocok(); 268 269 /* Set up the PCI bus tag. */ 270 if (bus_space_init(&pmppc_pci_io_tag, "pcimem", NULL, 0)) 271 panic("bus_space_init pci failed"); 272 273 /* Set up interrupt controller */ 274 cpc700_init_intr(&pmppc_mem_tag, CPC_UIC_BASE, 275 CPC_INTR_MASK(PMPPC_I_ETH_INT), 0); 276 277 pic_init(); 278 (void)setup_cpc700(); 279 oea_install_extint(pic_ext_intr); 280 281#if 0 282/* XXX doesn't seem to be needed anymore */ 283 /* 284 * Now allow hardware interrupts. 285 */ 286 __asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0" 287 : "=r"(msr) : "K"(PSL_EE)); 288#endif 289} 290 291/* 292 * consinit 293 * Initialize system console. 294 */ 295void 296consinit(void) 297{ 298 static int initted; 299#if (NCOM > 0) 300 bus_space_tag_t tag; 301#endif 302 303 if (initted) 304 return; 305 initted = 1; 306 307#if (NCOM > 0) 308 tag = &pmppc_mem_tag; 309 310 if(comcnattach(tag, CPC_COM0, 9600, CPC_COM_SPEED(a_config.a_bus_freq), 311 COM_TYPE_NORMAL, 312 ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8))) 313 panic("can't init serial console"); 314 else 315 return; 316#endif 317 318 panic("console device missing -- serial console not in kernel"); 319 /* Of course, this is moot if there is no console... */ 320} 321 322#ifdef KGDB 323void 324kgdb_port_init(void) 325{ 326#if (NCOM > 0) 327 if(!strcmp(kgdb_devname, "com")) { 328 bus_space_tag_t tag = &pmppc_mem_tag; 329 com_kgdb_attach(tag, comkgdbaddr, comkgdbrate, 330 CPC_COM_SPEED(a_config.a_bus_freq), 331 COM_TYPE_NORMAL, comkgdbmode); 332 } 333#endif 334} 335#endif 336 337/* 338 * Halt or reboot the machine after syncing/dumping according to howto. 339 */ 340void 341cpu_reboot(int howto, char *what) 342{ 343 static int syncing; 344 static char str[256]; 345 char *ap = str, *ap1 = ap; 346 extern void disable_intr(void); 347 348 boothowto = howto; 349 if (!cold && !(howto & RB_NOSYNC) && !syncing) { 350 syncing = 1; 351 vfs_shutdown(); /* sync */ 352 resettodr(); /* set wall clock */ 353 } 354 splhigh(); 355 if (howto & RB_HALT) { 356 doshutdownhooks(); 357 pmf_system_shutdown(boothowto); 358 printf("halted\n\n"); 359 while(1); 360 } 361 if (!cold && (howto & RB_DUMP)) 362 oea_dumpsys(); 363 doshutdownhooks(); 364 365 pmf_system_shutdown(boothowto); 366 printf("rebooting\n\n"); 367 if (what && *what) { 368 if (strlen(what) > sizeof str - 5) 369 printf("boot string too large, ignored\n"); 370 else { 371 strcpy(str, what); 372 ap1 = ap = str + strlen(str); 373 *ap++ = ' '; 374 } 375 } 376 *ap++ = '-'; 377 if (howto & RB_SINGLE) 378 *ap++ = 's'; 379 if (howto & RB_KDB) 380 *ap++ = 'd'; 381 *ap++ = 0; 382 if (ap[-2] == '-') 383 *ap1 = 0; 384 385 disable_intr(); 386 387 /* Write the two byte reset sequence to the reset register. */ 388 out8(PMPPC_RESET, PMPPC_RESET_SEQ_STEP1); 389 out8(PMPPC_RESET, PMPPC_RESET_SEQ_STEP2); 390 391 while (1); 392} 393 394void 395setleds(int leds) 396{ 397 out8(PMPPC_LEDS, leds); 398} 399 400void 401pmppc_setup(void) 402{ 403 uint config0, config1; 404 405 config0 = in8(PMPPC_CONFIG0); 406 config1 = in8(PMPPC_CONFIG1); 407 408 /* from page 2-8 in the Artesyn User's manual */ 409 a_config.a_boot_device = config1 & 0x80 ? A_BOOT_FLASH : A_BOOT_ROM; 410 a_config.a_has_ecc = (config1 & 0x40) != 0; 411 switch (config1 & 0x30) { 412 case 0x00: a_config.a_mem_size = 32 * 1024 * 1024; break; 413 case 0x10: a_config.a_mem_size = 64 * 1024 * 1024; break; 414 case 0x20: a_config.a_mem_size = 128 * 1024 * 1024; break; 415 case 0x30: a_config.a_mem_size = 256 * 1024 * 1024; break; 416 } 417 a_config.a_l2_cache = (config1 >> 2) & 3; 418 switch (config1 & 0x03) { 419 case 0x00: a_config.a_bus_freq = 66666666; break; 420 case 0x01: a_config.a_bus_freq = 83333333; break; 421 case 0x02: a_config.a_bus_freq = 100000000; break; 422 case 0x03: a_config.a_bus_freq = 0; break; /* XXX */ 423 } 424 a_config.a_is_monarch = (config0 & 0x80) == 0; 425 a_config.a_has_eth = (config0 & 0x20) != 0; 426 a_config.a_has_rtc = (config0 & 0x10) == 0; 427 switch (config0 & 0x0c) { 428 case 0x00: a_config.a_flash_size = 256 * 1024 * 1024; break; 429 case 0x04: a_config.a_flash_size = 128 * 1024 * 1024; break; 430 case 0x08: a_config.a_flash_size = 64 * 1024 * 1024; break; 431 case 0x0c: a_config.a_flash_size = 32 * 1024 * 1024; break; 432 } 433 switch (config0 & 0x03) { 434 case 0x00: a_config.a_flash_width = 64; break; 435 case 0x01: a_config.a_flash_width = 32; break; 436 case 0x02: a_config.a_flash_width = 16; break; 437 case 0x03: a_config.a_flash_width = 0; break; 438 } 439} 440