1 /* $NetBSD: dec_2100_a500.c,v 1.5 2001/06/05 04:53:11 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 1999 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jason R. Thorpe. 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 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 /* 40 * Copyright (c) 1995, 1996, 1997 Carnegie-Mellon University. 41 * All rights reserved. 42 * 43 * Author: Chris G. Demetriou 44 * 45 * Permission to use, copy, modify and distribute this software and 46 * its documentation is hereby granted, provided that both the copyright 47 * notice and this permission notice appear in all copies of the 48 * software, derivative works or modified versions, and any portions 49 * thereof, and that both notices appear in supporting documentation. 50 * 51 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 52 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 53 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 54 * 55 * Carnegie Mellon requests users of this software to return to 56 * 57 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 58 * School of Computer Science 59 * Carnegie Mellon University 60 * Pittsburgh PA 15213-3890 61 * 62 * any improvements or extensions that they make and grant Carnegie the 63 * rights to redistribute these changes. 64 */ 65 66 #include "opt_kgdb.h" 67 68 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 69 70 __KERNEL_RCSID(0, "$NetBSD: dec_2100_a500.c,v 1.5 2001/06/05 04:53:11 thorpej Exp $"); 71 72 #include <sys/param.h> 73 #include <sys/systm.h> 74 #include <sys/device.h> 75 #include <sys/termios.h> 76 #include <dev/cons.h> 77 78 #include <machine/rpb.h> 79 #include <machine/autoconf.h> 80 #include <machine/conf.h> 81 #include <machine/bus.h> 82 #include <machine/alpha.h> 83 84 #include <dev/ic/comreg.h> 85 #include <dev/ic/comvar.h> 86 87 #include <dev/isa/isareg.h> 88 #include <dev/isa/isavar.h> 89 #include <dev/ic/i8042reg.h> 90 #include <dev/ic/pckbcvar.h> 91 #include <dev/pci/pcireg.h> 92 #include <dev/pci/pcivar.h> 93 94 #include <alpha/pci/ttwogareg.h> 95 #include <alpha/pci/ttwogavar.h> 96 97 #include <dev/scsipi/scsi_all.h> 98 #include <dev/scsipi/scsipi_all.h> 99 #include <dev/scsipi/scsiconf.h> 100 101 #include "pckbd.h" 102 103 #ifndef CONSPEED 104 #define CONSPEED TTYDEF_SPEED 105 #endif 106 static int comcnrate = CONSPEED; 107 108 void _dec_2100_a500_init(void); 109 static void dec_2100_a500_cons_init(void); 110 static void dec_2100_a500_device_register(struct device *, void *); 111 static void dec_2100_a500_machine_check(unsigned long, struct trapframe *, 112 unsigned long, unsigned long); 113 114 #ifdef KGDB 115 #include <machine/db_machdep.h> 116 117 static const char *kgdb_devlist[] = { 118 "com", 119 NULL, 120 }; 121 #endif /* KGDB */ 122 123 void 124 _dec_2100_a500_init(void) 125 { 126 127 switch (cputype) { 128 case ST_DEC_2100_A500: 129 if (alpha_implver() == ALPHA_IMPLVER_EV5) 130 platform.family = "AlphaServer 2100 (\"Sable-Gamma\")"; 131 else 132 platform.family = "AlphaServer 2100 (\"Sable\")"; 133 break; 134 135 case ST_DEC_2100A_A500: 136 platform.family = "AlphaServer 2100A (\"Lynx\")"; 137 break; 138 139 default: 140 panic("dec_2100_a500_init: Not a Sable, Sable-Gamma, or Lynx?"); 141 } 142 143 if ((platform.model = alpha_dsr_sysname()) == NULL) { 144 /* XXX don't know variations yet */ 145 platform.model = alpha_unknown_sysname(); 146 } 147 148 platform.iobus = "ttwoga"; 149 platform.cons_init = dec_2100_a500_cons_init; 150 platform.device_register = dec_2100_a500_device_register; 151 platform.mcheck_handler = dec_2100_a500_machine_check; 152 } 153 154 static void 155 dec_2100_a500_cons_init(void) 156 { 157 struct ctb *ctb; 158 u_int64_t ctbslot; 159 struct ttwoga_config *tcp; 160 161 ctb = (struct ctb *)(((caddr_t)hwrpb) + hwrpb->rpb_ctb_off); 162 ctbslot = ctb->ctb_turboslot; 163 164 tcp = ttwoga_init(0, 0); 165 166 switch (ctb->ctb_term_type) { 167 case CTB_PRINTERPORT: 168 /* serial console ... */ 169 assert(CTB_TURBOSLOT_HOSE(ctbslot) == 0); 170 /* XXX */ 171 { 172 /* 173 * Delay to allow PROM putchars to complete. 174 * FIFO depth * character time, 175 * character time = (1000000 / (defaultrate / 10)) 176 */ 177 DELAY(160000000 / comcnrate); 178 179 if(comcnattach(&tcp->tc_iot, 0x3f8, comcnrate, 180 COM_FREQ, 181 (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)) 182 panic("can't init serial console"); 183 184 break; 185 } 186 187 case CTB_GRAPHICS: 188 #if NPCKBD > 0 189 /* display console ... */ 190 /* XXX */ 191 (void) pckbc_cnattach(&tcp->tc_iot, IO_KBD, KBCMDP, 192 PCKBC_KBD_SLOT); 193 194 switch (CTB_TURBOSLOT_TYPE(ctbslot)) { 195 case CTB_TURBOSLOT_TYPE_ISA: 196 /* 197 * XXX The following is apparently necessary for an 198 * XXX ISA VGA card, but what happens with real EISA 199 * XXX VGA cards? 200 */ 201 case CTB_TURBOSLOT_TYPE_EISA: 202 isa_display_console(&tcp->tc_iot, &tcp->tc_memt); 203 break; 204 205 case CTB_TURBOSLOT_TYPE_PCI: 206 /* The display PCI might be different */ 207 tcp = ttwoga_init(0, CTB_TURBOSLOT_HOSE(ctbslot)); 208 pci_display_console(&tcp->tc_iot, &tcp->tc_memt, 209 &tcp->tc_pc, CTB_TURBOSLOT_BUS(ctbslot), 210 CTB_TURBOSLOT_SLOT(ctbslot), 0); 211 break; 212 213 default: 214 printf("type = 0x%lx, hose = 0x%lx, bus = 0x%lx, " 215 "slot = 0x%lx\n", 216 CTB_TURBOSLOT_TYPE(ctbslot), 217 CTB_TURBOSLOT_HOSE(ctbslot), 218 CTB_TURBOSLOT_BUS(ctbslot), 219 CTB_TURBOSLOT_SLOT(ctbslot)); 220 panic("unknown display console type"); 221 } 222 #else 223 panic("not configured to use display && keyboard console"); 224 #endif 225 break; 226 227 default: 228 printf("ctb->ctb_term_type = 0x%lx\n", ctb->ctb_term_type); 229 printf("ctb->ctb_turboslot = 0x%lx\n", ctb->ctb_turboslot); 230 231 panic("consinit: unknown console type %ld\n", 232 ctb->ctb_term_type); 233 } 234 #ifdef KGDB 235 /* Attach the KGDB device. */ 236 alpha_kgdb_init(kgdb_devlist, &tcp->tc_iot); 237 #endif /* KGDB */ 238 } 239 240 static void 241 dec_2100_a500_device_register(struct device *dev, void *aux) 242 { 243 static int found, initted, scsiboot, netboot; 244 static struct device *pcidev, *scsidev; 245 struct bootdev_data *b = bootdev_data; 246 struct device *parent = dev->dv_parent; 247 struct cfdata *cf = dev->dv_cfdata; 248 struct cfdriver *cd = cf->cf_driver; 249 250 if (found) 251 return; 252 253 if (!initted) { 254 scsiboot = (strcmp(b->protocol, "SCSI") == 0); 255 netboot = (strcmp(b->protocol, "BOOTP") == 0); 256 #if 0 257 printf("scsiboot = %d, netboot = %d\n", scsiboot, netboot); 258 #endif 259 initted =1; 260 } 261 262 if (pcidev == NULL) { 263 if (strcmp(cd->cd_name, "pci")) 264 return; 265 else { 266 struct pcibus_attach_args *pba = aux; 267 268 if ((b->slot / 1000) != pba->pba_bus) 269 return; 270 271 pcidev = dev; 272 #if 0 273 printf("\npcidev = %s\n", pcidev->dv_xname); 274 #endif 275 return; 276 } 277 } 278 279 if (scsiboot && (scsidev == NULL)) { 280 if (parent != pcidev) 281 return; 282 else { 283 struct pci_attach_args *pa = aux; 284 285 if ((b->slot % 1000) != pa->pa_device) 286 return; 287 288 /* XXX function? */ 289 290 scsidev = dev; 291 #if 0 292 printf("\nscsidev = %s\n", scsidev->dv_xname); 293 #endif 294 return; 295 } 296 } 297 298 if (scsiboot && 299 (!strcmp(cd->cd_name, "sd") || 300 !strcmp(cd->cd_name, "st") || 301 !strcmp(cd->cd_name, "cd"))) { 302 struct scsipibus_attach_args *sa = aux; 303 304 if (parent->dv_parent != scsidev) 305 return; 306 307 if (b->unit / 100 != sa->sa_periph->periph_target) 308 return; 309 310 /* XXX LUN! */ 311 312 switch (b->boot_dev_type) { 313 case 0: 314 if (strcmp(cd->cd_name, "sd") && 315 strcmp(cd->cd_name, "cd")) 316 return; 317 break; 318 case 1: 319 if (strcmp(cd->cd_name, "st")) 320 return; 321 break; 322 default: 323 return; 324 } 325 326 /* we've found it! */ 327 booted_device = dev; 328 #if 0 329 printf("\nbooted_device = %s\n", booted_device->dv_xname); 330 #endif 331 found = 1; 332 } 333 334 if (netboot) { 335 if (parent != pcidev) 336 return; 337 else { 338 struct pci_attach_args *pa = aux; 339 340 if ((b->slot % 1000) != pa->pa_device) 341 return; 342 343 /* XXX function? */ 344 345 booted_device = dev; 346 #if 0 347 printf("\nbooted_device = %s\n", 348 booted_device->dv_xname); 349 #endif 350 found = 1; 351 return; 352 } 353 } 354 } 355 356 /* 357 * Sable, Sable-Gamma, and Lynx machine check handlers. 358 */ 359 360 static void 361 dec_2100_a500_machine_check(unsigned long mces, struct trapframe *framep, 362 unsigned long vector, unsigned long param) 363 { 364 struct mchkinfo *mcp = &curcpu()->ci_mcinfo; 365 366 /* 367 * This is a work-around for a T2 core logic bug. See 368 * alpha/pci/ttwoga_pci.c. 369 */ 370 371 if (ttwoga_conf_cpu == cpu_number()) 372 mcp->mc_expected = 1; 373 374 machine_check(mces, framep, vector, param); 375 } 376