1/* $NetBSD: api_up1000.c,v 1.28 2011/07/01 19:22:35 dyoung 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: api_up1000.c,v 1.28 2011/07/01 19:22:35 dyoung 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 <machine/alpha.h> 47#include <machine/rpb.h> 48#include <machine/autoconf.h> 49#include <machine/cpuconf.h> 50#include <sys/bus.h> 51 52#include <dev/ic/comreg.h> 53#include <dev/ic/comvar.h> 54 55#include <dev/isa/isareg.h> 56#include <dev/isa/isavar.h> 57#include <dev/ic/i8042reg.h> 58#include <dev/ic/pckbcvar.h> 59#include <dev/pci/pcireg.h> 60#include <dev/pci/pcivar.h> 61 62#include <alpha/pci/irongatereg.h> 63#include <alpha/pci/irongatevar.h> 64 65#include <dev/scsipi/scsi_all.h> 66#include <dev/scsipi/scsipi_all.h> 67#include <dev/scsipi/scsiconf.h> 68#include <dev/ata/atavar.h> 69 70#include "pckbd.h" 71 72#ifndef CONSPEED 73#define CONSPEED TTYDEF_SPEED 74#endif 75static int comcnrate = CONSPEED; 76 77#define DPRINTF(x) if (bootdev_debug) printf x 78 79void api_up1000_init(void); 80static void api_up1000_cons_init(void); 81static void api_up1000_device_register(device_t, void *); 82 83#ifdef KGDB 84#include <machine/db_machdep.h> 85 86static const char *kgdb_devlist[] = { 87 "com", 88 NULL, 89}; 90#endif /* KGDB */ 91 92void 93api_up1000_init(void) 94{ 95 96 platform.family = "Alpha Processor, Inc. UP1000"; 97 98 if ((platform.model = alpha_dsr_sysname()) == NULL) { 99 /* XXX Don't know the system variations, yet. */ 100 platform.model = alpha_unknown_sysname(); 101 } 102 103 platform.iobus = "irongate"; 104 platform.cons_init = api_up1000_cons_init; 105 platform.device_register = api_up1000_device_register; 106} 107 108static void 109api_up1000_cons_init(void) 110{ 111 struct ctb *ctb; 112 struct irongate_config *icp; 113 extern struct irongate_config irongate_configuration; 114 115 icp = &irongate_configuration; 116 irongate_init(icp, 0); 117 118 ctb = (struct ctb *)(((char *)hwrpb) + hwrpb->rpb_ctb_off); 119 120 switch (ctb->ctb_term_type) { 121 case CTB_PRINTERPORT: 122 /* serial console ... */ 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(&icp->ic_iot, 0x3f8, comcnrate, 133 COM_FREQ, COM_TYPE_NORMAL, 134 (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)) 135 panic("can't init serial console"); 136 137 break; 138 } 139 140 case CTB_GRAPHICS: 141#if NPCKBD > 0 142 /* display console ... */ 143 /* XXX */ 144 (void) pckbc_cnattach(&icp->ic_iot, IO_KBD, KBCMDP, 145 PCKBC_KBD_SLOT); 146 147 if (CTB_TURBOSLOT_TYPE(ctb->ctb_turboslot) == 148 CTB_TURBOSLOT_TYPE_ISA) 149 isa_display_console(&icp->ic_iot, &icp->ic_memt); 150 else 151 pci_display_console(&icp->ic_iot, &icp->ic_memt, 152 &icp->ic_pc, CTB_TURBOSLOT_BUS(ctb->ctb_turboslot), 153 CTB_TURBOSLOT_SLOT(ctb->ctb_turboslot), 0); 154#else 155 panic("not configured to use display && keyboard console"); 156#endif 157 break; 158 159 default: 160 printf("ctb->ctb_term_type = 0x%lx\n", ctb->ctb_term_type); 161 printf("ctb->ctb_turboslot = 0x%lx\n", ctb->ctb_turboslot); 162 163 panic("consinit: unknown console type %ld", 164 ctb->ctb_term_type); 165 } 166#ifdef KGDB 167 /* Attach the KGDB device. */ 168 alpha_kgdb_init(kgdb_devlist, &icp->ic_iot); 169#endif /* KGDB */ 170} 171 172static void 173api_up1000_device_register(device_t dev, void *aux) 174{ 175 static int found, initted, diskboot, netboot; 176 static device_t pcidev, ctrlrdev; 177 struct bootdev_data *b = bootdev_data; 178 device_t parent = device_parent(dev); 179 180 if (found) 181 return; 182 183 if (!initted) { 184 diskboot = (strcasecmp(b->protocol, "SCSI") == 0) || 185 (strcasecmp(b->protocol, "IDE") == 0); 186 netboot = (strcasecmp(b->protocol, "BOOTP") == 0) || 187 (strcasecmp(b->protocol, "MOP") == 0); 188 DPRINTF(("\ndiskboot = %d, netboot = %d\n", diskboot, netboot)); 189 initted = 1; 190 } 191 192 if (pcidev == NULL) { 193 if (!device_is_a(dev, "pci")) 194 return; 195 else { 196 struct pcibus_attach_args *pba = aux; 197 198 if ((b->slot / 1000) != pba->pba_bus) 199 return; 200 201 pcidev = dev; 202 DPRINTF(("\npcidev = %s\n", device_xname(dev))); 203 return; 204 } 205 } 206 207 if (ctrlrdev == NULL) { 208 if (parent != pcidev) 209 return; 210 else { 211 struct pci_attach_args *pa = aux; 212 int slot; 213 214 slot = pa->pa_bus * 1000 + pa->pa_function * 100 + 215 pa->pa_device; 216 if (b->slot != slot) 217 return; 218 219 if (netboot) { 220 booted_device = dev; 221 DPRINTF(("\nbooted_device = %s\n", 222 device_xname(dev))); 223 found = 1; 224 } else { 225 ctrlrdev = dev; 226 DPRINTF(("\nctrlrdev = %s\n", device_xname(dev))); 227 } 228 return; 229 } 230 } 231 232 if (!diskboot) 233 return; 234 235 if (device_is_a(dev, "sd") || 236 device_is_a(dev, "st") || 237 device_is_a(dev, "cd")) { 238 struct scsipibus_attach_args *sa = aux; 239 struct scsipi_periph *periph = sa->sa_periph; 240 int unit; 241 242 if (device_parent(parent) != ctrlrdev) 243 return; 244 245 unit = periph->periph_target * 100 + periph->periph_lun; 246 if (b->unit != unit) 247 return; 248 if (b->channel != periph->periph_channel->chan_channel) 249 return; 250 251 /* we've found it! */ 252 booted_device = dev; 253 DPRINTF(("\nbooted_device = %s\n", device_xname(dev))); 254 found = 1; 255 } 256 257 /* 258 * Support to boot from IDE drives. 259 */ 260 if (device_is_a(dev, "wd")) { 261 struct ata_device *adev = aux; 262 263 if (!device_is_a(parent, "atabus")) 264 return; 265 if (device_parent(parent) != ctrlrdev) 266 return; 267 268 DPRINTF(("\natapi info: drive %d, channel %d\n", 269 adev->adev_drv_data->drive, adev->adev_channel)); 270 DPRINTF(("bootdev info: unit: %d, channel: %d\n", 271 b->unit, b->channel)); 272 if (b->unit != adev->adev_drv_data->drive || 273 b->channel != adev->adev_channel) 274 return; 275 276 /* we've found it! */ 277 booted_device = dev; 278 DPRINTF(("booted_device = %s\n", device_xname(dev))); 279 found = 1; 280 } 281} 282