1 /* $NetBSD: dec_kn20aa.c,v 1.52 2002/09/27 15:35:35 provos Exp $ */ 2 3 /* 4 * Copyright (c) 1995, 1996, 1997 Carnegie-Mellon University. 5 * All rights reserved. 6 * 7 * Author: Chris G. Demetriou 8 * 9 * Permission to use, copy, modify and distribute this software and 10 * its documentation is hereby granted, provided that both the copyright 11 * notice and this permission notice appear in all copies of the 12 * software, derivative works or modified versions, and any portions 13 * thereof, and that both notices appear in supporting documentation. 14 * 15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 18 * 19 * Carnegie Mellon requests users of this software to return to 20 * 21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 22 * School of Computer Science 23 * Carnegie Mellon University 24 * Pittsburgh PA 15213-3890 25 * 26 * any improvements or extensions that they make and grant Carnegie the 27 * rights to redistribute these changes. 28 */ 29 /* 30 * Additional Copyright (c) 1997 by Matthew Jacob for NASA/Ames Research Center 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_kn20aa.c,v 1.52 2002/09/27 15:35:35 provos Exp $"); 38 39 #include <sys/param.h> 40 #include <sys/systm.h> 41 #include <sys/device.h> 42 #include <sys/termios.h> 43 #include <sys/conf.h> 44 #include <dev/cons.h> 45 46 #include <machine/rpb.h> 47 #include <machine/autoconf.h> 48 #include <machine/cpuconf.h> 49 #include <machine/bus.h> 50 #include <machine/alpha.h> 51 #include <machine/logout.h> 52 53 #include <dev/ic/comreg.h> 54 #include <dev/ic/comvar.h> 55 56 #include <dev/isa/isareg.h> 57 #include <dev/isa/isavar.h> 58 #include <dev/ic/i8042reg.h> 59 #include <dev/ic/pckbcvar.h> 60 #include <dev/pci/pcireg.h> 61 #include <dev/pci/pcivar.h> 62 63 #include <alpha/pci/ciareg.h> 64 #include <alpha/pci/ciavar.h> 65 66 #include <dev/scsipi/scsi_all.h> 67 #include <dev/scsipi/scsipi_all.h> 68 #include <dev/scsipi/scsiconf.h> 69 70 #include "pckbd.h" 71 72 #ifndef CONSPEED 73 #define CONSPEED TTYDEF_SPEED 74 #endif 75 static int comcnrate = CONSPEED; 76 77 void dec_kn20aa_init __P((void)); 78 static void dec_kn20aa_cons_init __P((void)); 79 static void dec_kn20aa_device_register __P((struct device *, void *)); 80 81 static void dec_kn20aa_mcheck_handler 82 __P((unsigned long, struct trapframe *, unsigned long, unsigned long)); 83 84 static void dec_kn20aa_mcheck __P((unsigned long, unsigned long, 85 unsigned long, struct trapframe *)); 86 87 #ifdef KGDB 88 #include <machine/db_machdep.h> 89 90 static const char *kgdb_devlist[] = { 91 "com", 92 NULL, 93 }; 94 #endif /* KGDB */ 95 96 const struct alpha_variation_table dec_kn20aa_variations[] = { 97 { 0, "AlphaStation 500 or 600 (KN20AA)" }, 98 { 0, NULL }, 99 }; 100 101 void 102 dec_kn20aa_init() 103 { 104 u_int64_t variation; 105 106 platform.family = "AlphaStation 500 or 600 (KN20AA)"; 107 108 if ((platform.model = alpha_dsr_sysname()) == NULL) { 109 variation = hwrpb->rpb_variation & SV_ST_MASK; 110 if ((platform.model = alpha_variation_name(variation, 111 dec_kn20aa_variations)) == NULL) 112 platform.model = alpha_unknown_sysname(); 113 } 114 115 platform.iobus = "cia"; 116 platform.cons_init = dec_kn20aa_cons_init; 117 platform.device_register = dec_kn20aa_device_register; 118 platform.mcheck_handler = dec_kn20aa_mcheck_handler; 119 } 120 121 static void 122 dec_kn20aa_cons_init() 123 { 124 struct ctb *ctb; 125 struct cia_config *ccp; 126 extern struct cia_config cia_configuration; 127 128 ccp = &cia_configuration; 129 cia_init(ccp, 0); 130 131 ctb = (struct ctb *)(((caddr_t)hwrpb) + hwrpb->rpb_ctb_off); 132 133 switch (ctb->ctb_term_type) { 134 case CTB_PRINTERPORT: 135 /* serial console ... */ 136 /* XXX */ 137 { 138 /* 139 * Delay to allow PROM putchars to complete. 140 * FIFO depth * character time, 141 * character time = (1000000 / (defaultrate / 10)) 142 */ 143 DELAY(160000000 / comcnrate); 144 145 if(comcnattach(&ccp->cc_iot, 0x3f8, comcnrate, 146 COM_FREQ, 147 (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)) 148 panic("can't init serial console"); 149 150 break; 151 } 152 153 case CTB_GRAPHICS: 154 #if NPCKBD > 0 155 /* display console ... */ 156 /* XXX */ 157 (void) pckbc_cnattach(&ccp->cc_iot, IO_KBD, KBCMDP, 158 PCKBC_KBD_SLOT); 159 160 if (CTB_TURBOSLOT_TYPE(ctb->ctb_turboslot) == 161 CTB_TURBOSLOT_TYPE_ISA) 162 isa_display_console(&ccp->cc_iot, &ccp->cc_memt); 163 else 164 pci_display_console(&ccp->cc_iot, &ccp->cc_memt, 165 &ccp->cc_pc, CTB_TURBOSLOT_BUS(ctb->ctb_turboslot), 166 CTB_TURBOSLOT_SLOT(ctb->ctb_turboslot), 0); 167 #else 168 panic("not configured to use display && keyboard console"); 169 #endif 170 break; 171 172 default: 173 printf("ctb->ctb_term_type = 0x%lx\n", ctb->ctb_term_type); 174 printf("ctb->ctb_turboslot = 0x%lx\n", ctb->ctb_turboslot); 175 176 panic("consinit: unknown console type %ld", 177 ctb->ctb_term_type); 178 } 179 #ifdef KGDB 180 /* Attach the KGDB device. */ 181 alpha_kgdb_init(kgdb_devlist, &ccp->cc_iot); 182 #endif /* KGDB */ 183 } 184 185 static void 186 dec_kn20aa_device_register(dev, aux) 187 struct device *dev; 188 void *aux; 189 { 190 static int found, initted, scsiboot, netboot; 191 static struct device *pcidev, *scsidev; 192 struct bootdev_data *b = bootdev_data; 193 struct device *parent = dev->dv_parent; 194 struct cfdata *cf = dev->dv_cfdata; 195 const char *name = cf->cf_name; 196 197 if (found) 198 return; 199 200 if (!initted) { 201 scsiboot = (strcmp(b->protocol, "SCSI") == 0); 202 netboot = (strcmp(b->protocol, "BOOTP") == 0) || 203 (strcmp(b->protocol, "MOP") == 0); 204 #if 0 205 printf("scsiboot = %d, netboot = %d\n", scsiboot, netboot); 206 #endif 207 initted =1; 208 } 209 210 if (pcidev == NULL) { 211 if (strcmp(name, "pci")) 212 return; 213 else { 214 struct pcibus_attach_args *pba = aux; 215 216 if ((b->slot / 1000) != pba->pba_bus) 217 return; 218 219 pcidev = dev; 220 #if 0 221 printf("\npcidev = %s\n", pcidev->dv_xname); 222 #endif 223 return; 224 } 225 } 226 227 if (scsiboot && (scsidev == NULL)) { 228 if (parent != pcidev) 229 return; 230 else { 231 struct pci_attach_args *pa = aux; 232 233 if ((b->slot % 1000) != pa->pa_device) 234 return; 235 236 /* XXX function? */ 237 238 scsidev = dev; 239 #if 0 240 printf("\nscsidev = %s\n", scsidev->dv_xname); 241 #endif 242 return; 243 } 244 } 245 246 if (scsiboot && 247 (!strcmp(name, "sd") || 248 !strcmp(name, "st") || 249 !strcmp(name, "cd"))) { 250 struct scsipibus_attach_args *sa = aux; 251 252 if (parent->dv_parent != scsidev) 253 return; 254 255 if (b->unit / 100 != sa->sa_periph->periph_target) 256 return; 257 258 /* XXX LUN! */ 259 260 switch (b->boot_dev_type) { 261 case 0: 262 if (strcmp(name, "sd") && 263 strcmp(name, "cd")) 264 return; 265 break; 266 case 1: 267 if (strcmp(name, "st")) 268 return; 269 break; 270 default: 271 return; 272 } 273 274 /* we've found it! */ 275 booted_device = dev; 276 #if 0 277 printf("\nbooted_device = %s\n", booted_device->dv_xname); 278 #endif 279 found = 1; 280 } 281 282 if (netboot) { 283 if (parent != pcidev) 284 return; 285 else { 286 struct pci_attach_args *pa = aux; 287 288 if ((b->slot % 1000) != pa->pa_device) 289 return; 290 291 /* XXX function? */ 292 293 booted_device = dev; 294 #if 0 295 printf("\nbooted_device = %s\n", booted_device->dv_xname); 296 #endif 297 found = 1; 298 return; 299 } 300 } 301 } 302 303 static void 304 dec_kn20aa_mcheck(mces, type, logout, framep) 305 unsigned long mces; 306 unsigned long type; 307 unsigned long logout; 308 struct trapframe *framep; 309 { 310 struct mchkinfo *mcp; 311 mc_hdr_ev5 *hdr; 312 mc_uc_ev5 *mptr; 313 314 /* 315 * If we expected a machine check, just go handle it in common code. 316 */ 317 mcp = &curcpu()->ci_mcinfo; 318 if (mcp->mc_expected) { 319 machine_check(mces, framep, type, logout); 320 return; 321 } 322 323 hdr = (mc_hdr_ev5 *) logout; 324 mptr = (mc_uc_ev5 *) (logout + sizeof (*hdr)); 325 326 /* 327 * Now we can finally print some stuff... 328 */ 329 ev5_logout_print(hdr, mptr); 330 331 machine_check(mces, framep, type, logout); 332 } 333 334 static void 335 dec_kn20aa_mcheck_handler(mces, framep, vector, param) 336 unsigned long mces; 337 struct trapframe *framep; 338 unsigned long vector; 339 unsigned long param; 340 { 341 342 switch (vector) { 343 case ALPHA_SYS_MCHECK: 344 case ALPHA_PROC_MCHECK: 345 dec_kn20aa_mcheck(mces, vector, param, framep); 346 break; 347 default: 348 printf("KN20AA_MCHECK: unknown check vector 0x%lx\n", vector); 349 machine_check(mces, framep, vector, param); 350 break; 351 } 352 } 353