1 /* $OpenBSD: dec_2100_a50.c,v 1.16 2002/06/25 21:33:19 miod Exp $ */ 2 /* $NetBSD: dec_2100_a50.c,v 1.43 2000/05/22 20:13:31 thorpej Exp $ */ 3 4 /* 5 * Copyright (c) 1995, 1996, 1997 Carnegie-Mellon University. 6 * All rights reserved. 7 * 8 * Author: Chris G. Demetriou 9 * 10 * Permission to use, copy, modify and distribute this software and 11 * its documentation is hereby granted, provided that both the copyright 12 * notice and this permission notice appear in all copies of the 13 * software, derivative works or modified versions, and any portions 14 * thereof, and that both notices appear in supporting documentation. 15 * 16 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 17 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 18 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 19 * 20 * Carnegie Mellon requests users of this software to return to 21 * 22 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 23 * School of Computer Science 24 * Carnegie Mellon University 25 * Pittsburgh PA 15213-3890 26 * 27 * any improvements or extensions that they make and grant Carnegie the 28 * rights to redistribute these changes. 29 */ 30 /* 31 * Additional Copyright (c) 1997 by Matthew Jacob for NASA/Ames Research Center 32 */ 33 34 #include <sys/param.h> 35 #include <sys/systm.h> 36 #include <sys/device.h> 37 #include <sys/termios.h> 38 #include <dev/cons.h> 39 #include <sys/conf.h> 40 41 #include <machine/rpb.h> 42 #include <machine/autoconf.h> 43 #include <machine/bus.h> 44 #include <machine/cpuconf.h> 45 46 #include <dev/ic/comreg.h> 47 #include <dev/ic/comvar.h> 48 49 #include <dev/isa/isareg.h> 50 #include <dev/isa/isavar.h> 51 #include <dev/ic/i8042reg.h> 52 #include <dev/ic/pckbcvar.h> 53 #include <dev/pci/pcireg.h> 54 #include <dev/pci/pcivar.h> 55 56 #include <alpha/pci/apecsreg.h> 57 #include <alpha/pci/apecsvar.h> 58 59 #include <scsi/scsi_all.h> 60 #include <scsi/scsiconf.h> 61 62 #include "pckbd.h" 63 64 #ifndef CONSPEED 65 #define CONSPEED TTYDEF_SPEED 66 #endif 67 static int comcnrate = CONSPEED; 68 69 void dec_2100_a50_init(void); 70 static void dec_2100_a50_cons_init(void); 71 static void dec_2100_a50_device_register(struct device *, void *); 72 73 const struct alpha_variation_table dec_2100_a50_variations[] = { 74 { SV_ST_AVANTI, "AlphaStation 400 4/233 (\"Avanti\")" }, 75 { SV_ST_MUSTANG2_4_166, "AlphaStation 200 4/166 (\"Mustang II\")" }, 76 { SV_ST_MUSTANG2_4_233, "AlphaStation 200 4/233 (\"Mustang II\")" }, 77 { SV_ST_AVANTI_4_266, "AlphaStation 250 4/266" }, 78 { SV_ST_MUSTANG2_4_100, "AlphaStation 200 4/100 (\"Mustang II\")" }, 79 { SV_ST_AVANTI_4_233, "AlphaStation 255/233" }, 80 { 0, NULL }, 81 }; 82 83 void 84 dec_2100_a50_init() 85 { 86 u_int64_t variation; 87 88 platform.family = "AlphaStation 200/400 (\"Avanti\")"; 89 90 if ((platform.model = alpha_dsr_sysname()) == NULL) { 91 variation = hwrpb->rpb_variation & SV_ST_MASK; 92 if (variation == SV_ST_AVANTI_XXX) { 93 /* XXX apparently the same? */ 94 variation = SV_ST_AVANTI; 95 } 96 if ((platform.model = alpha_variation_name(variation, 97 dec_2100_a50_variations)) == NULL) 98 platform.model = alpha_unknown_sysname(); 99 } 100 101 platform.iobus = "apecs"; 102 platform.cons_init = dec_2100_a50_cons_init; 103 platform.device_register = dec_2100_a50_device_register; 104 } 105 106 static void 107 dec_2100_a50_cons_init() 108 { 109 struct ctb *ctb; 110 struct apecs_config *acp; 111 extern struct apecs_config apecs_configuration; 112 113 acp = &apecs_configuration; 114 apecs_init(acp, 0); 115 116 ctb = (struct ctb *)(((caddr_t)hwrpb) + hwrpb->rpb_ctb_off); 117 118 switch (ctb->ctb_term_type) { 119 case CTB_PRINTERPORT: 120 /* serial console ... */ 121 /* XXX */ 122 { 123 /* 124 * Delay to allow PROM putchars to complete. 125 * FIFO depth * character time, 126 * character time = (1000000 / (defaultrate / 10)) 127 */ 128 DELAY(160000000 / comcnrate); 129 130 if(comcnattach(&acp->ac_iot, 0x3f8, comcnrate, 131 COM_FREQ, 132 (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)) 133 panic("can't init serial console"); 134 135 break; 136 } 137 138 case CTB_GRAPHICS: 139 #if NPCKBD > 0 140 /* display console ... */ 141 /* XXX */ 142 (void) pckbc_cnattach(&acp->ac_iot, IO_KBD, KBCMDP, 143 PCKBC_KBD_SLOT); 144 145 if (CTB_TURBOSLOT_TYPE(ctb->ctb_turboslot) == 146 CTB_TURBOSLOT_TYPE_ISA) 147 isa_display_console(&acp->ac_iot, &acp->ac_memt); 148 else 149 pci_display_console(&acp->ac_iot, &acp->ac_memt, 150 &acp->ac_pc, CTB_TURBOSLOT_BUS(ctb->ctb_turboslot), 151 CTB_TURBOSLOT_SLOT(ctb->ctb_turboslot), 0); 152 #else 153 panic("not configured to use display && keyboard console"); 154 #endif 155 break; 156 157 default: 158 printf("ctb->ctb_term_type = 0x%lx\n", ctb->ctb_term_type); 159 printf("ctb->ctb_turboslot = 0x%lx\n", ctb->ctb_turboslot); 160 161 panic("consinit: unknown console type %ld", 162 ctb->ctb_term_type); 163 } 164 } 165 166 static void 167 dec_2100_a50_device_register(dev, aux) 168 struct device *dev; 169 void *aux; 170 { 171 static int found, initted, scsiboot, netboot; 172 static struct device *pcidev, *scsidev; 173 struct bootdev_data *b = bootdev_data; 174 struct device *parent = dev->dv_parent; 175 struct cfdata *cf = dev->dv_cfdata; 176 struct cfdriver *cd = cf->cf_driver; 177 178 if (found) 179 return; 180 181 if (!initted) { 182 scsiboot = (strcmp(b->protocol, "SCSI") == 0); 183 netboot = (strcmp(b->protocol, "BOOTP") == 0) || 184 (strcmp(b->protocol, "MOP") == 0); 185 #if 0 186 printf("scsiboot = %d, netboot = %d\n", scsiboot, netboot); 187 #endif 188 initted =1; 189 } 190 191 if (pcidev == NULL) { 192 if (strcmp(cd->cd_name, "pci")) 193 return; 194 else { 195 struct pcibus_attach_args *pba = aux; 196 197 if ((b->slot / 1000) != pba->pba_bus) 198 return; 199 200 pcidev = dev; 201 #if 0 202 printf("\npcidev = %s\n", pcidev->dv_xname); 203 #endif 204 return; 205 } 206 } 207 208 if (scsiboot && (scsidev == NULL)) { 209 if (parent != pcidev) 210 return; 211 else { 212 struct pci_attach_args *pa = aux; 213 214 if ((b->slot % 1000) != pa->pa_device) 215 return; 216 217 /* XXX function? */ 218 219 scsidev = dev; 220 #if 0 221 printf("\nscsidev = %s\n", scsidev->dv_xname); 222 #endif 223 return; 224 } 225 } 226 227 if (scsiboot && 228 (!strcmp(cd->cd_name, "sd") || 229 !strcmp(cd->cd_name, "st") || 230 !strcmp(cd->cd_name, "cd"))) { 231 struct scsibus_attach_args *sa = aux; 232 233 if (parent->dv_parent != scsidev) 234 return; 235 236 if (b->unit / 100 != sa->sa_sc_link->target) 237 return; 238 239 /* XXX LUN! */ 240 241 switch (b->boot_dev_type) { 242 case 0: 243 if (strcmp(cd->cd_name, "sd") && 244 strcmp(cd->cd_name, "cd")) 245 return; 246 break; 247 case 1: 248 if (strcmp(cd->cd_name, "st")) 249 return; 250 break; 251 default: 252 return; 253 } 254 255 /* we've found it! */ 256 booted_device = dev; 257 #if 0 258 printf("\nbooted_device = %s\n", booted_device->dv_xname); 259 #endif 260 found = 1; 261 } 262 263 if (netboot) { 264 if (parent != pcidev) 265 return; 266 else { 267 struct pci_attach_args *pa = aux; 268 269 if ((b->slot % 1000) != pa->pa_device) 270 return; 271 272 /* XXX function? */ 273 274 booted_device = dev; 275 #if 0 276 printf("\nbooted_device = %s\n", booted_device->dv_xname); 277 #endif 278 found = 1; 279 return; 280 } 281 } 282 } 283