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