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