1 /* $NetBSD: dec_kn300.c,v 1.23 2001/08/20 12:20:04 wiz Exp $ */ 2 3 /* 4 * Copyright (c) 1998 by Matthew Jacob 5 * NASA AMES Research Center. 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 immediately at the beginning of the file, without modification, 13 * this list of conditions, and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33 #include "opt_kgdb.h" 34 35 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 36 37 __KERNEL_RCSID(0, "$NetBSD: dec_kn300.c,v 1.23 2001/08/20 12:20:04 wiz Exp $"); 38 39 #include <sys/param.h> 40 #include <sys/systm.h> 41 #include <sys/device.h> 42 #include <sys/termios.h> 43 #include <dev/cons.h> 44 45 #include <machine/rpb.h> 46 #include <machine/alpha.h> 47 #include <machine/autoconf.h> 48 #include <machine/conf.h> 49 #include <machine/frame.h> 50 #include <machine/cpuconf.h> 51 52 #include <dev/ic/comreg.h> 53 #include <dev/ic/comvar.h> 54 55 #include <dev/isa/isareg.h> 56 #include <dev/isa/isavar.h> 57 #include <dev/ic/i8042reg.h> 58 #include <dev/ic/pckbcvar.h> 59 #include <dev/pci/pcireg.h> 60 #include <dev/pci/pcivar.h> 61 62 #include <uvm/uvm_extern.h> 63 64 #include <alpha/mcbus/mcbusreg.h> 65 #include <alpha/mcbus/mcbusvar.h> 66 #include <alpha/pci/mcpciareg.h> 67 #include <alpha/pci/mcpciavar.h> 68 #include <alpha/pci/pci_kn300.h> 69 #include <machine/logout.h> 70 71 #include <dev/scsipi/scsi_all.h> 72 #include <dev/scsipi/scsipi_all.h> 73 #include <dev/scsipi/scsiconf.h> 74 75 76 #include "pckbd.h" 77 78 #ifndef CONSPEED 79 #define CONSPEED TTYDEF_SPEED 80 #endif 81 static int comcnrate = CONSPEED; 82 83 void dec_kn300_init __P((void)); 84 void dec_kn300_cons_init __P((void)); 85 static void dec_kn300_device_register __P((struct device *, void *)); 86 static void dec_kn300_mcheck_handler 87 __P((unsigned long, struct trapframe *, unsigned long, unsigned long)); 88 89 #ifdef KGDB 90 #include <machine/db_machdep.h> 91 92 static const char *kgdb_devlist[] = { 93 "com", 94 NULL, 95 }; 96 #endif /* KGDB */ 97 98 #define ALPHASERVER_4100 "AlphaServer 4100" 99 100 const struct alpha_variation_table dec_kn300_variations[] = { 101 { 0, ALPHASERVER_4100 }, 102 { 0, NULL }, 103 }; 104 105 void 106 dec_kn300_init() 107 { 108 u_int64_t variation; 109 int cachesize; 110 111 platform.family = ALPHASERVER_4100; 112 113 if ((platform.model = alpha_dsr_sysname()) == NULL) { 114 variation = hwrpb->rpb_variation & SV_ST_MASK; 115 if ((platform.model = alpha_variation_name(variation, 116 dec_kn300_variations)) == NULL) 117 platform.model = alpha_unknown_sysname(); 118 } 119 120 platform.iobus = "mcbus"; 121 platform.cons_init = dec_kn300_cons_init; 122 platform.device_register = dec_kn300_device_register; 123 platform.mcheck_handler = dec_kn300_mcheck_handler; 124 125 /* 126 * Determine B-cache size by looking at the primary (console) 127 * MCPCIA's WHOAMI register. 128 */ 129 mcpcia_init(); 130 131 if (mcbus_primary.mcbus_valid) { 132 switch (mcbus_primary.mcbus_bcache) { 133 default: 134 case CPU_BCache_0MB: 135 /* No B-cache or invalid; default to 1MB. */ 136 /* FALLTHROUGH */ 137 138 case CPU_BCache_1MB: 139 cachesize = (1 * 1024 * 1024); 140 break; 141 142 case CPU_BCache_2MB: 143 cachesize = (2 * 1024 * 1024); 144 break; 145 146 case CPU_BCache_4MB: 147 cachesize = (4 * 1024 * 1024); 148 break; 149 } 150 } else { 151 /* Default to 1MB. */ 152 cachesize = (1 * 1024 * 1024); 153 } 154 155 uvmexp.ncolors = atop(cachesize); 156 } 157 158 void 159 dec_kn300_cons_init() 160 { 161 struct ctb *ctb; 162 struct mcpcia_config *ccp; 163 extern struct mcpcia_config mcpcia_console_configuration; 164 165 ccp = &mcpcia_console_configuration; 166 /* It's already initialized. */ 167 168 ctb = (struct ctb *)(((caddr_t)hwrpb) + hwrpb->rpb_ctb_off); 169 170 switch (ctb->ctb_term_type) { 171 case CTB_PRINTERPORT: 172 /* serial console ... */ 173 /* 174 * Delay to allow PROM putchars to complete. 175 * FIFO depth * character time, 176 * character time = (1000000 / (defaultrate / 10)) 177 */ 178 DELAY(160000000 / comcnrate); 179 if (comcnattach(&ccp->cc_iot, 0x3f8, comcnrate, 180 COM_FREQ, (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)) { 181 panic("can't init serial console"); 182 183 } 184 break; 185 186 case CTB_GRAPHICS: 187 #if NPCKBD > 0 188 /* display console ... */ 189 /* XXX */ 190 (void) pckbc_cnattach(&ccp->cc_iot, IO_KBD, KBCMDP, 191 PCKBC_KBD_SLOT); 192 193 if (CTB_TURBOSLOT_TYPE(ctb->ctb_turboslot) == 194 CTB_TURBOSLOT_TYPE_ISA) 195 isa_display_console(&ccp->cc_iot, &ccp->cc_memt); 196 else 197 pci_display_console(&ccp->cc_iot, &ccp->cc_memt, 198 &ccp->cc_pc, CTB_TURBOSLOT_BUS(ctb->ctb_turboslot), 199 CTB_TURBOSLOT_SLOT(ctb->ctb_turboslot), 0); 200 #else 201 panic("not configured to use display && keyboard console"); 202 #endif 203 break; 204 205 default: 206 printf("ctb->ctb_term_type = 0x%lx\n", ctb->ctb_term_type); 207 printf("ctb->ctb_turboslot = 0x%lx\n", ctb->ctb_turboslot); 208 209 panic("consinit: unknown console type %ld\n", 210 ctb->ctb_term_type); 211 } 212 #ifdef KGDB 213 /* Attach the KGDB device. */ 214 alpha_kgdb_init(kgdb_devlist, &ccp->cc_iot); 215 #endif /* KGDB */ 216 } 217 218 /* #define BDEBUG 1 */ 219 static void 220 dec_kn300_device_register(dev, aux) 221 struct device *dev; 222 void *aux; 223 { 224 static int found, initted, scsiboot, netboot; 225 static struct device *pcidev, *scsidev; 226 struct bootdev_data *b = bootdev_data; 227 struct device *parent = dev->dv_parent; 228 struct cfdata *cf = dev->dv_cfdata; 229 struct cfdriver *cd = cf->cf_driver; 230 231 if (found) 232 return; 233 234 if (!initted) { 235 scsiboot = (strcmp(b->protocol, "SCSI") == 0); 236 netboot = (strcmp(b->protocol, "BOOTP") == 0) || 237 (strcmp(b->protocol, "MOP") == 0); 238 #ifdef BDEBUG 239 printf("proto:%s bus:%d slot:%d chan:%d", b->protocol, 240 b->bus, b->slot, b->channel); 241 if (b->remote_address) 242 printf(" remote_addr:%s", b->remote_address); 243 printf(" un:%d bdt:%d", b->unit, b->boot_dev_type); 244 if (b->ctrl_dev_type) 245 printf(" cdt:%s\n", b->ctrl_dev_type); 246 else 247 printf("\n"); 248 printf("scsiboot = %d, netboot = %d\n", scsiboot, netboot); 249 #endif 250 initted = 1; 251 } 252 253 if (pcidev == NULL) { 254 if (strcmp(cd->cd_name, "pci")) 255 return; 256 else { 257 struct pcibus_attach_args *pba = aux; 258 259 if ((b->slot / 1000) != pba->pba_bus) 260 return; 261 262 pcidev = dev; 263 #ifdef BDEBUG 264 printf("\npcidev = %s\n", pcidev->dv_xname); 265 #endif 266 return; 267 } 268 } 269 270 if (scsiboot && (scsidev == NULL)) { 271 if (parent != pcidev) 272 return; 273 else { 274 struct pci_attach_args *pa = aux; 275 276 if ((b->slot % 1000) != pa->pa_device) 277 return; 278 279 /* XXX function? */ 280 281 scsidev = dev; 282 #ifdef BDEBUG 283 printf("\nscsidev = %s\n", scsidev->dv_xname); 284 #endif 285 286 return; 287 } 288 } 289 290 if (scsiboot && 291 (!strcmp(cd->cd_name, "sd") || 292 !strcmp(cd->cd_name, "st") || 293 !strcmp(cd->cd_name, "cd"))) { 294 struct scsipibus_attach_args *sa = aux; 295 296 if (parent->dv_parent != scsidev) 297 return; 298 299 if (b->unit / 100 != sa->sa_periph->periph_target) 300 return; 301 302 /* XXX LUN! */ 303 304 /* 305 * the value in boot_dev_type is some weird number 306 * XXX: Only support SD booting for now. 307 */ 308 if (strcmp(cd->cd_name, "sd") && 309 strcmp(cd->cd_name, "cd") && 310 strcmp(cd->cd_name, "st")) 311 return; 312 313 /* we've found it! */ 314 booted_device = dev; 315 #ifdef BDEBUG 316 printf("\nbooted_device = %s\n", booted_device->dv_xname); 317 #endif 318 found = 1; 319 } 320 321 if (netboot) { 322 if (parent != pcidev) 323 return; 324 else { 325 struct pci_attach_args *pa = aux; 326 327 if ((b->slot % 1000) != pa->pa_device) 328 return; 329 330 /* XXX function? */ 331 332 booted_device = dev; 333 #ifdef BDEBUG 334 printf("\nbooted_device = %s\n", 335 booted_device->dv_xname); 336 #endif 337 found = 1; 338 return; 339 } 340 } 341 } 342 343 344 /* 345 * KN300 Machine Check Handlers. 346 */ 347 static void kn300_softerr __P((unsigned long, unsigned long, 348 unsigned long, struct trapframe *)); 349 350 static void kn300_mcheck __P((unsigned long, unsigned long, 351 unsigned long, struct trapframe *)); 352 353 /* 354 * "soft" error structure in system area for KN300 processor. 355 * It differs from the EV5 'common' structure in a minor but 356 * exceedingly stupid and annoying fashion. 357 */ 358 359 typedef struct { 360 /* 361 * Should be mc_cc_ev5 structure. Contents are the same, 362 * just in different places. 363 */ 364 u_int64_t ei_stat; 365 u_int64_t ei_addr; 366 u_int64_t fill_syndrome; 367 u_int64_t isr; 368 /* 369 * Platform Specific Area 370 */ 371 u_int32_t whami; 372 u_int32_t sys_env; 373 u_int64_t mcpcia_regs; 374 u_int32_t pci_rev; 375 u_int32_t mc_err0; 376 u_int32_t mc_err1; 377 u_int32_t cap_err; 378 u_int32_t mdpa_stat; 379 u_int32_t mdpa_syn; 380 u_int32_t mdpb_stat; 381 u_int32_t mdpb_syn; 382 u_int64_t end_rsvd; 383 } mc_soft300; 384 #define CAP_ERR_CRDX 204 385 386 static void 387 kn300_softerr(mces, type, logout, framep) 388 unsigned long mces; 389 unsigned long type; 390 unsigned long logout; 391 struct trapframe *framep; 392 { 393 static const char *sys = "system"; 394 static const char *proc = "processor"; 395 int whami; 396 mc_hdr_ev5 *hdr; 397 mc_soft300 *ptr; 398 static const char *fmt1 = " %-25s = 0x%l016x\n"; 399 400 hdr = (mc_hdr_ev5 *) logout; 401 ptr = (mc_soft300 *) (logout + sizeof (*hdr)); 402 whami = alpha_pal_whami(); 403 404 printf("kn300: CPU ID %d %s correctable error corrected by %s\n", whami, 405 (type == ALPHA_SYS_ERROR)? sys : proc, 406 ((hdr->mcheck_code & 0xff00) == (EV5_CORRECTED << 16))? proc : 407 (((hdr->mcheck_code & 0xff00) == (CAP_ERR_CRDX << 16)) ? 408 "I/O Bridge Module" : sys)); 409 410 printf(" Machine Check Code 0x%lx\n", hdr->mcheck_code); 411 printf(" Physical Address of Error 0x%lx\n", ptr->ei_addr); 412 if (ptr->ei_stat & 0x80000000L) 413 printf(" Corrected ECC Error "); 414 else 415 printf(" Other Error"); 416 if (ptr->ei_stat & 0x40000000L) 417 printf("in Memory "); 418 else 419 printf("in B-Cache "); 420 if (ptr->ei_stat & 0x400000000L) 421 printf("during I-Cache fill\n"); 422 else 423 printf("during D-Cache fill\n"); 424 425 printf(fmt1, "EI Status", ptr->ei_stat); 426 printf(fmt1, "Fill Syndrome", ptr->fill_syndrome); 427 printf(fmt1, "Interrupt Status Reg.", ptr->isr); 428 printf("\n"); 429 printf(fmt1, "Whami Reg.", ptr->whami); 430 printf(fmt1, "Sys. Env. Reg.", ptr->sys_env); 431 printf(fmt1, "MCPCIA Regs.", ptr->mcpcia_regs); 432 printf(fmt1, "PCI Rev. Reg.", ptr->pci_rev); 433 printf(fmt1, "MC_ERR0 Reg.", ptr->mc_err0); 434 printf(fmt1, "MC_ERR1 Reg.", ptr->mc_err1); 435 printf(fmt1, "CAP_ERR Reg.", ptr->cap_err); 436 printf(fmt1, "MDPA_STAT Reg.", ptr->mdpa_stat); 437 printf(fmt1, "MDPA_SYN Reg.", ptr->mdpa_syn); 438 printf(fmt1, "MDPB_STAT Reg.", ptr->mdpb_stat); 439 printf(fmt1, "MDPB_SYN Reg.", ptr->mdpb_syn); 440 441 /* 442 * Clear error by rewriting register. 443 */ 444 alpha_pal_wrmces(mces); 445 } 446 447 /* 448 * KN300 specific machine check handler 449 */ 450 451 static void 452 kn300_mcheck(mces, type, logout, framep) 453 unsigned long mces; 454 unsigned long type; 455 unsigned long logout; 456 struct trapframe *framep; 457 { 458 struct mchkinfo *mcp; 459 static const char *fmt1 = " %-25s = 0x%l016x\n"; 460 int i; 461 mc_hdr_ev5 *hdr; 462 mc_uc_ev5 *ptr; 463 struct mcpcia_iodsnap *iodsnp; 464 465 /* 466 * If we expected a machine check, just go handle it in common code. 467 */ 468 mcp = &curcpu()->ci_mcinfo; 469 if (mcp->mc_expected) { 470 machine_check(mces, framep, type, logout); 471 return; 472 } 473 474 hdr = (mc_hdr_ev5 *) logout; 475 ptr = (mc_uc_ev5 *) (logout + sizeof (*hdr)); 476 ev5_logout_print(hdr, ptr); 477 478 iodsnp = (struct mcpcia_iodsnap *) ((unsigned long) hdr + 479 (unsigned long) hdr->la_system_offset); 480 for (i = 0; i < MCPCIA_PER_MCBUS; i++, iodsnp++) { 481 if (!IS_MCPCIA_MAGIC(iodsnp->pci_rev)) { 482 continue; 483 } 484 printf(" IOD %d register dump:\n", i); 485 printf(fmt1, "Base Addr of PCI bridge", iodsnp->base_addr); 486 printf(fmt1, "Whami Reg.", iodsnp->whami); 487 printf(fmt1, "Sys. Env. Reg.", iodsnp->sys_env); 488 printf(fmt1, "PCI Rev. Reg.", iodsnp->pci_rev); 489 printf(fmt1, "CAP_CTL Reg.", iodsnp->cap_ctrl); 490 printf(fmt1, "HAE_MEM Reg.", iodsnp->hae_mem); 491 printf(fmt1, "HAE_IO Reg.", iodsnp->hae_io); 492 printf(fmt1, "INT_CTL Reg.", iodsnp->int_ctl); 493 printf(fmt1, "INT_REG Reg.", iodsnp->int_reg); 494 printf(fmt1, "INT_MASK0 Reg.", iodsnp->int_mask0); 495 printf(fmt1, "INT_MASK1 Reg.", iodsnp->int_mask1); 496 printf(fmt1, "MC_ERR0 Reg.", iodsnp->mc_err0); 497 printf(fmt1, "MC_ERR1 Reg.", iodsnp->mc_err1); 498 printf(fmt1, "CAP_ERR Reg.", iodsnp->cap_err); 499 printf(fmt1, "PCI_ERR1 Reg.", iodsnp->pci_err1); 500 printf(fmt1, "MDPA_STAT Reg.", iodsnp->mdpa_stat); 501 printf(fmt1, "MDPA_SYN Reg.", iodsnp->mdpa_syn); 502 printf(fmt1, "MDPB_STAT Reg.", iodsnp->mdpb_stat); 503 printf(fmt1, "MDPB_SYN Reg.", iodsnp->mdpb_syn); 504 505 } 506 /* 507 * Now that we've printed all sorts of useful information 508 * and have decided that we really can't do any more to 509 * respond to the error, go on to the common code for 510 * final disposition. Usually this means that we die. 511 */ 512 /* 513 * XXX: HANDLE PCI ERRORS HERE? 514 */ 515 machine_check(mces, framep, type, logout); 516 } 517 518 static void 519 dec_kn300_mcheck_handler(mces, framep, vector, param) 520 unsigned long mces; 521 struct trapframe *framep; 522 unsigned long vector; 523 unsigned long param; 524 { 525 switch (vector) { 526 case ALPHA_SYS_ERROR: 527 case ALPHA_PROC_ERROR: 528 kn300_softerr(mces, vector, param, framep); 529 break; 530 531 case ALPHA_SYS_MCHECK: 532 case ALPHA_PROC_MCHECK: 533 kn300_mcheck(mces, vector, param, framep); 534 break; 535 default: 536 printf("KN300_MCHECK: unknown check vector 0x%lx\n", vector); 537 machine_check(mces, framep, vector, param); 538 break; 539 } 540 } 541