dec_6600.c revision 1.10
1/* $NetBSD: dec_6600.c,v 1.10 2001/04/25 17:53:05 bouyer 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#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 31 32__KERNEL_RCSID(0, "$NetBSD: dec_6600.c,v 1.10 2001/04/25 17:53:05 bouyer Exp $"); 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 40#include <machine/rpb.h> 41#include <machine/autoconf.h> 42#include <machine/conf.h> 43#include <machine/bus.h> 44 45#include <dev/ic/comreg.h> 46#include <dev/ic/comvar.h> 47 48#include <dev/isa/isareg.h> 49#include <dev/isa/isavar.h> 50#include <dev/ic/i8042reg.h> 51#include <dev/ic/pckbcvar.h> 52#include <dev/pci/pcireg.h> 53#include <dev/pci/pcivar.h> 54 55#include <alpha/pci/tsreg.h> 56#include <alpha/pci/tsvar.h> 57 58#include <dev/scsipi/scsi_all.h> 59#include <dev/scsipi/scsipi_all.h> 60#include <dev/scsipi/scsiconf.h> 61#include <dev/ata/atavar.h> 62 63#include "pckbd.h" 64 65#ifndef CONSPEED 66#define CONSPEED TTYDEF_SPEED 67#endif 68 69#define DR_VERBOSE(f) while (0) 70 71static int comcnrate __attribute__((unused)) = CONSPEED; 72 73void dec_6600_init __P((void)); 74static void dec_6600_cons_init __P((void)); 75static void dec_6600_device_register __P((struct device *, void *)); 76 77#ifdef KGDB 78#include <machine/db_machdep.h> 79 80static const char *kgdb_devlist[] = { 81 "com", 82 NULL, 83}; 84#endif /* KGDB */ 85 86void 87dec_6600_init() 88{ 89 90 platform.family = "6600"; 91 92 if ((platform.model = alpha_dsr_sysname()) == NULL) { 93 /* XXX Don't know the system variations, yet. */ 94 platform.model = alpha_unknown_sysname(); 95 } 96 97 platform.iobus = "tsc"; 98 platform.cons_init = dec_6600_cons_init; 99 platform.device_register = dec_6600_device_register; 100 STQP(TS_C_DIM0) = 0UL; 101 STQP(TS_C_DIM1) = 0UL; 102} 103 104static void 105dec_6600_cons_init() 106{ 107 struct ctb *ctb; 108 u_int64_t ctbslot; 109 struct tsp_config *tsp; 110 111 ctb = (struct ctb *)(((caddr_t)hwrpb) + hwrpb->rpb_ctb_off); 112 ctbslot = ctb->ctb_turboslot; 113 114 /* Console hose defaults to hose 0. */ 115 tsp_console_hose = 0; 116 117 tsp = tsp_init(0, tsp_console_hose); 118 119 switch (ctb->ctb_term_type) { 120 case 2: 121 /* serial console ... */ 122 assert(CTB_TURBOSLOT_HOSE(ctbslot) == 0); 123 /* XXX */ 124 { 125 /* 126 * Delay to allow PROM putchars to complete. 127 * FIFO depth * character time, 128 * character time = (1000000 / (defaultrate / 10)) 129 */ 130 DELAY(160000000 / comcnrate); 131 132 if(comcnattach(&tsp->pc_iot, 0x3f8, comcnrate, 133 COM_FREQ, 134 (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)) 135 panic("can't init serial console"); 136 137 break; 138 } 139 140 case 3: 141#if NPCKBD > 0 142 /* display console ... */ 143 /* XXX */ 144 (void) pckbc_cnattach(&tsp->pc_iot, IO_KBD, KBCMDP, 145 PCKBC_KBD_SLOT); 146 147 if (CTB_TURBOSLOT_TYPE(ctbslot) == 148 CTB_TURBOSLOT_TYPE_ISA) 149 isa_display_console(&tsp->pc_iot, &tsp->pc_memt); 150 else { 151 /* The display PCI might be different */ 152 tsp_console_hose = CTB_TURBOSLOT_HOSE(ctbslot); 153 tsp = tsp_init(0, tsp_console_hose); 154 pci_display_console(&tsp->pc_iot, &tsp->pc_memt, 155 &tsp->pc_pc, CTB_TURBOSLOT_BUS(ctbslot), 156 CTB_TURBOSLOT_SLOT(ctbslot), 0); 157 } 158#else 159 panic("not configured to use display && keyboard console"); 160#endif 161 break; 162 163 default: 164 printf("ctb_term_type = 0x%lx ctb_turboslot = 0x%lx" 165 " hose = %ld\n", ctb->ctb_term_type, ctbslot, 166 CTB_TURBOSLOT_HOSE(ctbslot)); 167 168 panic("consinit: unknown console type %ld\n", 169 ctb->ctb_term_type); 170 } 171#ifdef KGDB 172 /* Attach the KGDB device. */ 173 alpha_kgdb_init(kgdb_devlist, &tsp->pc_iot); 174#endif /* KGDB */ 175} 176 177static void 178dec_6600_device_register(dev, aux) 179 struct device *dev; 180 void *aux; 181{ 182 static int found, initted, scsiboot, ideboot, netboot; 183 static struct device *primarydev, *pcidev, *scsipidev; 184 struct bootdev_data *b = bootdev_data; 185 struct device *parent = dev->dv_parent; 186 struct cfdata *cf = dev->dv_cfdata; 187 struct cfdriver *cd = cf->cf_driver; 188 189 if (found) 190 return; 191 192 if (!initted) { 193 scsiboot = (strcmp(b->protocol, "SCSI") == 0); 194 netboot = (strcmp(b->protocol, "BOOTP") == 0) || 195 (strcmp(b->protocol, "MOP") == 0); 196 /* 197 * Add an extra check to boot from ide drives: 198 * Newer SRM firmware use the protocol identifier IDE, 199 * older SRM firmware use the protocol identifier SCSI. 200 */ 201 ideboot = (strcmp(b->protocol, "IDE") == 0); 202 DR_VERBOSE(printf("scsiboot = %d, ideboot = %d, netboot = %d\n", 203 scsiboot, ideboot, netboot)); 204 initted = 1; 205 } 206 if (primarydev == NULL) { 207 if (strcmp(cd->cd_name, "tsp")) 208 return; 209 else { 210 struct tsp_attach_args *tsp = aux; 211 212 if (b->bus != tsp->tsp_slot) 213 return; 214 primarydev = dev; 215 DR_VERBOSE(printf("\nprimarydev = %s\n", 216 primarydev->dv_xname)); 217 return; 218 } 219 } 220 if (pcidev == NULL) { 221 if (parent != primarydev) 222 return; 223 if (strcmp(cd->cd_name, "pci")) 224 return; 225 else { 226 struct pcibus_attach_args *pba = aux; 227 228 if ((b->slot / 1000) != pba->pba_bus) 229 return; 230 231 pcidev = dev; 232 DR_VERBOSE(printf("\npcidev = %s\n", 233 pcidev->dv_xname)); 234 return; 235 } 236 } 237 if ((ideboot || scsiboot) && (scsipidev == NULL)) { 238 if (parent != pcidev) 239 return; 240 else { 241 struct pci_attach_args *pa = aux; 242 243 if (b->slot % 1000 / 100 != pa->pa_function) 244 return; 245 if (b->slot % 100 != pa->pa_device) 246 return; 247 248 scsipidev = dev; 249 DR_VERBOSE(printf("\nscsipidev = %s\n", 250 scsipidev->dv_xname)); 251 return; 252 } 253 } 254 if ((ideboot || scsiboot) && 255 (!strcmp(cd->cd_name, "sd") || 256 !strcmp(cd->cd_name, "st") || 257 !strcmp(cd->cd_name, "cd"))) { 258 struct scsipibus_attach_args *sa = aux; 259 260 if (parent->dv_parent != scsipidev) 261 return; 262 263 if ((sa->sa_periph->periph_channel->chan_bustype->bustype_type 264 == SCSIPI_BUSTYPE_SCSI || 265 sa->sa_periph->periph_channel->chan_bustype->bustype_type 266 == SCSIPI_BUSTYPE_ATAPI) 267 && b->unit / 100 != sa->sa_periph->periph_target) 268 return; 269 270 /* XXX LUN! */ 271 272 switch (b->boot_dev_type) { 273 case 0: 274 if (strcmp(cd->cd_name, "sd") && 275 strcmp(cd->cd_name, "cd")) 276 return; 277 break; 278 case 1: 279 if (strcmp(cd->cd_name, "st")) 280 return; 281 break; 282 default: 283 return; 284 } 285 286 /* we've found it! */ 287 booted_device = dev; 288 DR_VERBOSE(printf("\nbooted_device = %s\n", 289 booted_device->dv_xname)); 290 found = 1; 291 } 292 293 /* 294 * Support to boot from IDE drives. 295 */ 296 if ((ideboot || scsiboot) && !strcmp(cd->cd_name, "wd")) { 297 struct ata_atapi_attach *aa_link = aux; 298 if ((strncmp("pciide", parent->dv_xname, 6) != 0)) { 299 return; 300 } else { 301 if (parent != scsipidev) 302 return; 303 } 304 DR_VERBOSE(printf("\nAtapi info: drive: %d, channel %d\n", 305 aa_link->aa_drv_data->drive, aa_link->aa_channel)); 306 DR_VERBOSE(printf("Bootdev info: unit: %d, channel: %d\n", 307 b->unit, b->channel)); 308 if (b->unit != aa_link->aa_drv_data->drive || 309 b->channel != aa_link->aa_channel) 310 return; 311 312 /* we've found it! */ 313 booted_device = dev; 314 DR_VERBOSE(printf("booted_device = %s\n", 315 booted_device->dv_xname)); 316 found = 1; 317 } 318 if (netboot) { 319 if (parent != pcidev) 320 return; 321 else { 322 struct pci_attach_args *pa = aux; 323 324 if (b->slot % 1000 / 100 != pa->pa_function) 325 return; 326 if ((b->slot % 100) != pa->pa_device) 327 return; 328 329 booted_device = dev; 330 DR_VERBOSE(printf("\nbooted_device = %s\n", 331 booted_device->dv_xname)); 332 found = 1; 333 return; 334 } 335 } 336} 337