dec_6600.c revision 1.26
1/* $NetBSD: dec_6600.c,v 1.26 2007/03/04 15:18:10 yamt 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.26 2007/03/04 15:18:10 yamt Exp $"); 35 36#include <sys/param.h> 37#include <sys/systm.h> 38#include <sys/device.h> 39#include <sys/termios.h> 40#include <sys/conf.h> 41#include <dev/cons.h> 42 43#include <machine/rpb.h> 44#include <machine/autoconf.h> 45#include <machine/cpuconf.h> 46#include <machine/bus.h> 47 48#include <dev/ic/comreg.h> 49#include <dev/ic/comvar.h> 50 51#include <dev/isa/isareg.h> 52#include <dev/isa/isavar.h> 53#include <dev/ic/i8042reg.h> 54#include <dev/ic/pckbcvar.h> 55#include <dev/pci/pcireg.h> 56#include <dev/pci/pcivar.h> 57 58#include <alpha/pci/tsreg.h> 59#include <alpha/pci/tsvar.h> 60 61#include <dev/scsipi/scsi_all.h> 62#include <dev/scsipi/scsipi_all.h> 63#include <dev/scsipi/scsiconf.h> 64#include <dev/ata/atavar.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 *)(((char *)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, COM_TYPE_NORMAL, 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", 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, diskboot, netboot; 186 static struct device *primarydev, *pcidev, *ctrlrdev; 187 struct bootdev_data *b = bootdev_data; 188 struct device *parent = device_parent(dev); 189 190 if (found) 191 return; 192 193 if (!initted) { 194 diskboot = (strcasecmp(b->protocol, "SCSI") == 0) || 195 (strcasecmp(b->protocol, "IDE") == 0); 196 netboot = (strcasecmp(b->protocol, "BOOTP") == 0) || 197 (strcasecmp(b->protocol, "MOP") == 0); 198 DR_VERBOSE(printf("diskboot = %d, netboot = %d\n", diskboot, 199 netboot)); 200 initted = 1; 201 } 202 203 if (primarydev == NULL) { 204 if (!device_is_a(dev, "tsp")) 205 return; 206 else { 207 struct tsp_attach_args *tsp = aux; 208 209 if (b->bus != tsp->tsp_slot) 210 return; 211 primarydev = dev; 212 DR_VERBOSE(printf("\nprimarydev = %s\n", 213 dev->dv_xname)); 214 return; 215 } 216 } 217 218 if (pcidev == NULL) { 219 if (!device_is_a(dev, "pci")) 220 return; 221 /* 222 * Try to find primarydev anywhere in the ancestry. This is 223 * necessary if the PCI bus is hidden behind a bridge. 224 */ 225 while (parent) { 226 if (parent == primarydev) 227 break; 228 parent = device_parent(parent); 229 } 230 if (!parent) 231 return; 232 else { 233 struct pcibus_attach_args *pba = aux; 234 235 if ((b->slot / 1000) != pba->pba_bus) 236 return; 237 238 pcidev = dev; 239 DR_VERBOSE(printf("\npcidev = %s\n", dev->dv_xname)); 240 return; 241 } 242 } 243 244 if (ctrlrdev == NULL) { 245 if (parent != pcidev) 246 return; 247 else { 248 struct pci_attach_args *pa = aux; 249 int slot; 250 251 slot = pa->pa_bus * 1000 + pa->pa_function * 100 + 252 pa->pa_device; 253 if (b->slot != slot) 254 return; 255 256 if (netboot) { 257 booted_device = dev; 258 DR_VERBOSE(printf("\nbooted_device = %s\n", 259 dev->dv_xname)); 260 found = 1; 261 } else { 262 ctrlrdev = dev; 263 DR_VERBOSE(printf("\nctrlrdev = %s\n", 264 dev->dv_xname)); 265 } 266 return; 267 } 268 } 269 270 if (!diskboot) 271 return; 272 273 if (device_is_a(dev, "sd") || 274 device_is_a(dev, "st") || 275 device_is_a(dev, "cd")) { 276 struct scsipibus_attach_args *sa = aux; 277 struct scsipi_periph *periph = sa->sa_periph; 278 int unit; 279 280 if (device_parent(parent) != ctrlrdev) 281 return; 282 283 unit = periph->periph_target * 100 + periph->periph_lun; 284 if (b->unit != unit) 285 return; 286 if (b->channel != periph->periph_channel->chan_channel) 287 return; 288 289 /* we've found it! */ 290 booted_device = dev; 291 DR_VERBOSE(printf("\nbooted_device = %s\n", dev->dv_xname)); 292 found = 1; 293 } 294 295 /* 296 * Support to boot from IDE drives. 297 */ 298 if (device_is_a(dev, "wd")) { 299 struct ata_device *adev = aux; 300 301 if (!device_is_a(parent, "atabus")) 302 return; 303 if (device_parent(parent) != ctrlrdev) 304 return; 305 306 DR_VERBOSE(printf("\nAtapi info: drive: %d, channel %d\n", 307 adev->adev_drv_data->drive, adev->adev_channel)); 308 DR_VERBOSE(printf("Bootdev info: unit: %d, channel: %d\n", 309 b->unit, b->channel)); 310 if (b->unit != adev->adev_drv_data->drive || 311 b->channel != adev->adev_channel) 312 return; 313 314 /* we've found it! */ 315 booted_device = dev; 316 DR_VERBOSE(printf("booted_device = %s\n", dev->dv_xname)); 317 found = 1; 318 } 319} 320