1 /* $NetBSD: dec_eb64plus.c,v 1.29 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_eb64plus.c,v 1.29 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 <uvm/uvm_extern.h> 47 48 #include <machine/rpb.h> 49 #include <machine/alpha.h> 50 #include <machine/autoconf.h> 51 #include <machine/cpuconf.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/apecsreg.h> 64 #include <alpha/pci/apecsvar.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_eb64plus_init __P((void)); 78 static void dec_eb64plus_cons_init __P((void)); 79 static void dec_eb64plus_device_register __P((struct device *, void *)); 80 81 #ifdef KGDB 82 #include <machine/db_machdep.h> 83 84 static const char *kgdb_devlist[] = { 85 "com", 86 NULL, 87 }; 88 #endif /* KGDB */ 89 90 const struct alpha_variation_table dec_eb64plus_variations[] = { 91 { 0, "DEC EB64+" }, 92 { 0, NULL }, 93 }; 94 95 void 96 dec_eb64plus_init() 97 { 98 u_int64_t variation; 99 100 platform.family = "EB64+"; 101 102 if ((platform.model = alpha_dsr_sysname()) == NULL) { 103 variation = hwrpb->rpb_variation & SV_ST_MASK; 104 if ((platform.model = alpha_variation_name(variation, 105 dec_eb64plus_variations)) == NULL) 106 platform.model = alpha_unknown_sysname(); 107 } 108 109 platform.iobus = "apecs"; 110 platform.cons_init = dec_eb64plus_cons_init; 111 platform.device_register = dec_eb64plus_device_register; 112 113 /* 114 * EB64+ systems can have 512K, 1M, or 2M secondary 115 * caches. Default to middle-of-the-road. 116 * 117 * XXX Need to dynamically size it! 118 */ 119 uvmexp.ncolors = atop(1 * 1024 * 1024); 120 } 121 122 static void 123 dec_eb64plus_cons_init() 124 { 125 struct ctb *ctb; 126 struct apecs_config *acp; 127 extern struct apecs_config apecs_configuration; 128 129 acp = &apecs_configuration; 130 apecs_init(acp, 0); 131 132 ctb = (struct ctb *)(((caddr_t)hwrpb) + hwrpb->rpb_ctb_off); 133 134 switch (ctb->ctb_term_type) { 135 case CTB_PRINTERPORT: 136 /* serial console ... */ 137 /* XXX */ 138 { 139 /* 140 * Delay to allow PROM putchars to complete. 141 * FIFO depth * character time, 142 * character time = (1000000 / (defaultrate / 10)) 143 */ 144 DELAY(160000000 / comcnrate); 145 146 if(comcnattach(&acp->ac_iot, 0x3f8, comcnrate, 147 COM_FREQ, 148 (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)) 149 panic("can't init serial console"); 150 151 break; 152 } 153 154 case CTB_GRAPHICS: 155 #if NPCKBD > 0 156 /* display console ... */ 157 /* XXX */ 158 (void) pckbc_cnattach(&acp->ac_iot, IO_KBD, KBCMDP, 159 PCKBC_KBD_SLOT); 160 161 if (CTB_TURBOSLOT_TYPE(ctb->ctb_turboslot) == 162 CTB_TURBOSLOT_TYPE_ISA) 163 isa_display_console(&acp->ac_iot, &acp->ac_memt); 164 else 165 pci_display_console(&acp->ac_iot, &acp->ac_memt, 166 &acp->ac_pc, CTB_TURBOSLOT_BUS(ctb->ctb_turboslot), 167 CTB_TURBOSLOT_SLOT(ctb->ctb_turboslot), 0); 168 #else 169 panic("not configured to use display && keyboard console"); 170 #endif 171 break; 172 173 default: 174 printf("ctb->ctb_term_type = 0x%lx\n", ctb->ctb_term_type); 175 printf("ctb->ctb_turboslot = 0x%lx\n", ctb->ctb_turboslot); 176 177 panic("consinit: unknown console type %ld", 178 ctb->ctb_term_type); 179 } 180 #ifdef KGDB 181 /* Attach the KGDB device. */ 182 alpha_kgdb_init(kgdb_devlist, &acp->ac_iot); 183 #endif /* KGDB */ 184 } 185 186 static void 187 dec_eb64plus_device_register(dev, aux) 188 struct device *dev; 189 void *aux; 190 { 191 static int found, initted, scsiboot, netboot; 192 static struct device *pcidev, *scsidev; 193 struct bootdev_data *b = bootdev_data; 194 struct device *parent = dev->dv_parent; 195 struct cfdata *cf = dev->dv_cfdata; 196 const char *name = cf->cf_name; 197 198 if (found) 199 return; 200 201 if (!initted) { 202 scsiboot = (strcmp(b->protocol, "SCSI") == 0); 203 netboot = (strcmp(b->protocol, "BOOTP") == 0) || 204 (strcmp(b->protocol, "MOP") == 0); 205 #if 0 206 printf("scsiboot = %d, netboot = %d\n", scsiboot, netboot); 207 #endif 208 initted =1; 209 } 210 211 if (pcidev == NULL) { 212 if (strcmp(name, "pci")) 213 return; 214 else { 215 struct pcibus_attach_args *pba = aux; 216 217 if ((b->slot / 1000) != pba->pba_bus) 218 return; 219 220 pcidev = dev; 221 #if 0 222 printf("\npcidev = %s\n", pcidev->dv_xname); 223 #endif 224 return; 225 } 226 } 227 228 if (scsiboot && (scsidev == NULL)) { 229 if (parent != pcidev) 230 return; 231 else { 232 struct pci_attach_args *pa = aux; 233 234 if ((b->slot % 1000) != pa->pa_device) 235 return; 236 237 /* XXX function? */ 238 239 scsidev = dev; 240 #if 0 241 printf("\nscsidev = %s\n", scsidev->dv_xname); 242 #endif 243 return; 244 } 245 } 246 247 if (scsiboot && 248 (!strcmp(name, "sd") || 249 !strcmp(name, "st") || 250 !strcmp(name, "cd"))) { 251 struct scsipibus_attach_args *sa = aux; 252 253 if (parent->dv_parent != scsidev) 254 return; 255 256 if (b->unit / 100 != sa->sa_periph->periph_target) 257 return; 258 259 /* XXX LUN! */ 260 261 switch (b->boot_dev_type) { 262 case 0: 263 if (strcmp(name, "sd") && 264 strcmp(name, "cd")) 265 return; 266 break; 267 case 1: 268 if (strcmp(name, "st")) 269 return; 270 break; 271 default: 272 return; 273 } 274 275 /* we've found it! */ 276 booted_device = dev; 277 #if 0 278 printf("\nbooted_device = %s\n", booted_device->dv_xname); 279 #endif 280 found = 1; 281 } 282 283 if (netboot) { 284 if (parent != pcidev) 285 return; 286 else { 287 struct pci_attach_args *pa = aux; 288 289 if ((b->slot % 1000) != pa->pa_device) 290 return; 291 292 /* XXX function? */ 293 294 booted_device = dev; 295 #if 0 296 printf("\nbooted_device = %s\n", booted_device->dv_xname); 297 #endif 298 found = 1; 299 return; 300 } 301 } 302 } 303