1 /* $NetBSD: machdep.c,v 1.26 2009/11/27 03:23:11 rmind Exp $ */ 2 3 /* 4 * Copyright (C) 1995, 1996 Wolfgang Solfrank. 5 * Copyright (C) 1995, 1996 TooLs GmbH. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by TooLs GmbH. 19 * 4. The name of TooLs GmbH may not be used to endorse or promote products 20 * derived from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #include <sys/cdefs.h> 35 __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.26 2009/11/27 03:23:11 rmind Exp $"); 36 37 #include "opt_compat_netbsd.h" 38 #include "opt_mvmetype.h" 39 #include "opt_ddb.h" 40 41 #include <sys/param.h> 42 #include <sys/buf.h> 43 #include <sys/conf.h> 44 #include <sys/device.h> 45 #include <sys/exec.h> 46 #include <sys/extent.h> 47 #include <sys/kernel.h> 48 #include <sys/malloc.h> 49 #include <sys/mbuf.h> 50 #include <sys/mount.h> 51 #include <sys/msgbuf.h> 52 #include <sys/proc.h> 53 #include <sys/reboot.h> 54 #include <sys/syscallargs.h> 55 #include <sys/syslog.h> 56 #include <sys/systm.h> 57 58 #include <uvm/uvm_extern.h> 59 60 #include <sys/sysctl.h> 61 62 #include <net/netisr.h> 63 64 #include <machine/autoconf.h> 65 #include <machine/bootinfo.h> 66 #include <machine/bus.h> 67 #include <machine/intr.h> 68 #include <machine/pmap.h> 69 #include <machine/platform.h> 70 #include <machine/powerpc.h> 71 #include <machine/trap.h> 72 73 #include <powerpc/oea/bat.h> 74 75 #include <dev/cons.h> 76 77 #if 0 78 #include "vga.h" 79 #if (NVGA > 0) 80 #include <dev/ic/mc6845reg.h> 81 #include <dev/ic/pcdisplayvar.h> 82 #include <dev/ic/vgareg.h> 83 #include <dev/ic/vgavar.h> 84 #endif 85 86 #include "pckbc.h" 87 #if (NPCKBC > 0) 88 #include <dev/isa/isareg.h> 89 #include <dev/ic/i8042reg.h> 90 #include <dev/ic/pckbcvar.h> 91 #endif 92 #endif 93 94 #include "com.h" 95 #if (NCOM > 0) 96 #include <sys/termios.h> 97 #include <dev/ic/comreg.h> 98 #include <dev/ic/comvar.h> 99 #endif 100 101 void initppc(u_long, u_long, void *); 102 103 /* 104 * Global variables used here and there 105 */ 106 struct mvmeppc_bootinfo bootinfo; 107 vaddr_t prep_intr_reg; /* PReP-compatible interrupt vector register */ 108 uint32_t prep_intr_reg_off = INTR_VECTOR_REG; 109 struct mem_region physmemr[2], availmemr[2]; 110 paddr_t avail_end; /* XXX temporary */ 111 struct pic_ops *isa_pic; 112 113 void 114 initppc(u_long startkernel, u_long endkernel, void *btinfo) 115 { 116 /* 117 * Copy bootinfo. 118 */ 119 memcpy(&bootinfo, btinfo, sizeof(bootinfo)); 120 121 /* 122 * Figure out the board family/type. 123 */ 124 ident_platform(); 125 126 if (platform == NULL) { 127 extern void _mvmeppc_unsup_board(const char *, const char *); 128 char msg[80]; 129 130 sprintf(msg, "Unsupported model: MVME%04x", 131 bootinfo.bi_modelnumber); 132 _mvmeppc_unsup_board(msg, &msg[strlen(msg)]); 133 /* NOTREACHED */ 134 } 135 136 /* 137 * Set memory region 138 */ 139 physmemr[0].start = 0; 140 physmemr[0].size = bootinfo.bi_memsize & ~PGOFSET; 141 availmemr[0].start = (endkernel + PGOFSET) & ~PGOFSET; 142 availmemr[0].size = bootinfo.bi_memsize - availmemr[0].start; 143 avail_end = physmemr[0].start + physmemr[0].size; /* XXX temporary */ 144 145 /* 146 * Set CPU clock 147 */ 148 { 149 extern u_long ticks_per_sec, ns_per_tick; 150 151 ticks_per_sec = bootinfo.bi_clocktps; 152 ns_per_tick = 1000000000 / ticks_per_sec; 153 } 154 155 prep_initppc(startkernel, endkernel, boothowto); 156 157 (*platform->pic_setup)(); 158 } 159 160 /* 161 * Machine dependent startup code. 162 */ 163 void 164 cpu_startup(void) 165 { 166 char modelbuf[256]; 167 168 /* 169 * Mapping PReP-compatible interrput vector register. 170 */ 171 prep_intr_reg = (vaddr_t) mapiodev(MVMEPPC_INTR_REG, PAGE_SIZE); 172 if (!prep_intr_reg) 173 panic("startup: no room for interrupt register"); 174 175 sprintf(modelbuf, "%s\nCore Speed: %dMHz, Bus Speed: %dMHz\n", 176 platform->model, 177 bootinfo.bi_mpuspeed/1000000, 178 bootinfo.bi_busspeed/1000000); 179 oea_startup(modelbuf); 180 181 /* 182 * Now allow hardware interrupts. 183 */ 184 { 185 int msr; 186 187 splraise(-1); 188 __asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0" 189 : "=r"(msr) : "K"(PSL_EE)); 190 } 191 192 bus_space_mallocok(); 193 } 194 195 /* 196 * consinit 197 * Initialize system console. 198 */ 199 void 200 consinit(void) 201 { 202 static int initted = 0; 203 204 if (initted) 205 return; 206 initted = 1; 207 208 #if 0 209 210 #if (NPFB > 0) 211 if (!strcmp(consinfo->devname, "fb")) { 212 pfb_cnattach(consinfo->addr); 213 #if (NPCKBC > 0) 214 pckbc_cnattach(&mvmeppc_isa_io_space_tag, IO_KBD, KBCMDP, 215 PCKBC_KBD_SLOT); 216 #endif 217 return; 218 } 219 #endif 220 221 #if (NVGA > 0) || (NGTEN > 0) 222 if (!strcmp(consinfo->devname, "vga")) { 223 #if (NGTEN > 0) 224 if (!gten_cnattach(&mvmeppc_mem_space_tag)) 225 goto dokbd; 226 #endif 227 #if (NVGA > 0) 228 if (!vga_cnattach(&mvmeppc_io_space_tag, &mvmeppc_mem_space_tag, 229 -1, 1)) 230 goto dokbd; 231 #endif 232 dokbd: 233 #if (NPCKBC > 0) 234 pckbc_cnattach(&mvmeppc_isa_io_space_tag, IO_KBD, KBCMDP, 235 PCKBC_KBD_SLOT); 236 #endif 237 return; 238 } 239 #endif /* PC | VGA */ 240 241 #endif 242 243 #if (NCOM > 0) 244 if (!strcmp(bootinfo.bi_consoledev, "PC16550")) { 245 bus_space_tag_t tag = &genppc_isa_io_space_tag; 246 static const bus_addr_t caddr[2] = {0x3f8, 0x2f8}; 247 int rv; 248 rv = comcnattach(tag, caddr[bootinfo.bi_consolechan], 249 bootinfo.bi_consolespeed, COM_FREQ, COM_TYPE_NORMAL, 250 bootinfo.bi_consolecflag); 251 if (rv) 252 panic("can't init serial console"); 253 254 return; 255 } 256 #endif 257 panic("invalid console device %s", bootinfo.bi_consoledev); 258 } 259 260 /* 261 * Halt or reboot the machine after syncing/dumping according to howto. 262 */ 263 void 264 cpu_reboot(int howto, char *what) 265 { 266 static int syncing; 267 268 if (cold) { 269 howto |= RB_HALT; 270 goto halt_sys; 271 } 272 273 boothowto = howto; 274 if ((howto & RB_NOSYNC) == 0 && syncing == 0) { 275 syncing = 1; 276 vfs_shutdown(); /* sync */ 277 resettodr(); /* set wall clock */ 278 } 279 280 /* Disable intr */ 281 splhigh(); 282 283 /* Do dump if requested */ 284 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) 285 oea_dumpsys(); 286 287 halt_sys: 288 doshutdownhooks(); 289 290 pmf_system_shutdown(boothowto); 291 292 if (howto & RB_HALT) { 293 printf("\n"); 294 printf("The operating system has halted.\n"); 295 printf("Please press any key to reboot.\n\n"); 296 cnpollc(1); /* for proper keyboard command handling */ 297 cngetc(); 298 cnpollc(0); 299 } 300 301 printf("rebooting...\n\n"); 302 303 (*platform->reset)(); 304 305 printf("Oops! Board reset failed!\n"); 306 307 for (;;) 308 continue; 309 /* NOTREACHED */ 310 } 311