dec_6600.c revision 1.8
11.8Sthorpej/* $NetBSD: dec_6600.c,v 1.8 2000/06/25 19:17:39 thorpej Exp $ */
21.1Sross
31.1Sross/*
41.1Sross * Copyright (c) 1995, 1996, 1997 Carnegie-Mellon University.
51.1Sross * All rights reserved.
61.1Sross *
71.1Sross * Author: Chris G. Demetriou
81.1Sross *
91.1Sross * Permission to use, copy, modify and distribute this software and
101.1Sross * its documentation is hereby granted, provided that both the copyright
111.1Sross * notice and this permission notice appear in all copies of the
121.1Sross * software, derivative works or modified versions, and any portions
131.1Sross * thereof, and that both notices appear in supporting documentation.
141.1Sross *
151.1Sross * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
161.1Sross * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
171.1Sross * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
181.1Sross *
191.1Sross * Carnegie Mellon requests users of this software to return to
201.1Sross *
211.1Sross *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
221.1Sross *  School of Computer Science
231.1Sross *  Carnegie Mellon University
241.1Sross *  Pittsburgh PA 15213-3890
251.1Sross *
261.1Sross * any improvements or extensions that they make and grant Carnegie the
271.1Sross * rights to redistribute these changes.
281.1Sross */
291.1Sross
301.1Sross#include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
311.1Sross
321.8Sthorpej__KERNEL_RCSID(0, "$NetBSD: dec_6600.c,v 1.8 2000/06/25 19:17:39 thorpej Exp $");
331.1Sross
341.1Sross#include <sys/param.h>
351.1Sross#include <sys/systm.h>
361.1Sross#include <sys/device.h>
371.1Sross#include <sys/termios.h>
381.1Sross#include <dev/cons.h>
391.1Sross
401.1Sross#include <machine/rpb.h>
411.1Sross#include <machine/autoconf.h>
421.1Sross#include <machine/conf.h>
431.1Sross#include <machine/bus.h>
441.1Sross
451.1Sross#include <dev/ic/comreg.h>
461.1Sross#include <dev/ic/comvar.h>
471.1Sross
481.2Sthorpej#include <dev/isa/isareg.h>
491.1Sross#include <dev/isa/isavar.h>
501.6Ssoda#include <dev/ic/i8042reg.h>
511.2Sthorpej#include <dev/ic/pckbcvar.h>
521.1Sross#include <dev/pci/pcireg.h>
531.1Sross#include <dev/pci/pcivar.h>
541.1Sross
551.1Sross#include <alpha/pci/tsreg.h>
561.1Sross#include <alpha/pci/tsvar.h>
571.1Sross
581.1Sross#include <dev/scsipi/scsi_all.h>
591.1Sross#include <dev/scsipi/scsipi_all.h>
601.1Sross#include <dev/scsipi/scsiconf.h>
611.3Sveego#include <dev/ata/atavar.h>
621.1Sross
631.1Sross#include "pckbd.h"
641.1Sross
651.1Sross#ifndef CONSPEED
661.1Sross#define CONSPEED TTYDEF_SPEED
671.1Sross#endif
681.1Sross
691.1Sross#define	DR_VERBOSE(f) while (0)
701.1Sross
711.1Srossstatic int comcnrate __attribute__((unused)) = CONSPEED;
721.1Sross
731.1Srossvoid dec_6600_init __P((void));
741.1Srossstatic void dec_6600_cons_init __P((void));
751.1Srossstatic void dec_6600_device_register __P((struct device *, void *));
761.1Sross
771.1Srossvoid
781.1Srossdec_6600_init()
791.1Sross{
801.1Sross
811.1Sross	platform.family = "6600";
821.1Sross
831.1Sross	if ((platform.model = alpha_dsr_sysname()) == NULL) {
841.1Sross		/* XXX Don't know the system variations, yet. */
851.1Sross		platform.model = alpha_unknown_sysname();
861.1Sross	}
871.1Sross
881.1Sross	platform.iobus = "tsc";
891.1Sross	platform.cons_init = dec_6600_cons_init;
901.1Sross	platform.device_register = dec_6600_device_register;
911.1Sross	STQP(TS_C_DIM0) = 0UL;
921.1Sross	STQP(TS_C_DIM1) = 0UL;
931.1Sross}
941.1Sross
951.1Srossstatic void
961.1Srossdec_6600_cons_init()
971.1Sross{
981.1Sross	struct ctb *ctb;
991.1Sross	u_int64_t ctbslot;
1001.1Sross	struct tsp_config *tsp;
1011.1Sross
1021.1Sross	ctb = (struct ctb *)(((caddr_t)hwrpb) + hwrpb->rpb_ctb_off);
1031.1Sross	ctbslot = ctb->ctb_turboslot;
1041.1Sross
1051.8Sthorpej	/* Console hose defaults to hose 0. */
1061.8Sthorpej	tsp_console_hose = 0;
1071.8Sthorpej
1081.8Sthorpej	tsp = tsp_init(0, tsp_console_hose);
1091.1Sross
1101.1Sross	switch (ctb->ctb_term_type) {
1111.1Sross	case 2:
1121.1Sross		/* serial console ... */
1131.1Sross		assert(CTB_TURBOSLOT_HOSE(ctbslot) == 0);
1141.1Sross		/* XXX */
1151.1Sross		{
1161.1Sross			/*
1171.1Sross			 * Delay to allow PROM putchars to complete.
1181.1Sross			 * FIFO depth * character time,
1191.1Sross			 * character time = (1000000 / (defaultrate / 10))
1201.1Sross			 */
1211.1Sross			DELAY(160000000 / comcnrate);
1221.1Sross
1231.1Sross			if(comcnattach(&tsp->pc_iot, 0x3f8, comcnrate,
1241.1Sross			    COM_FREQ,
1251.1Sross			    (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8))
1261.1Sross				panic("can't init serial console");
1271.1Sross
1281.1Sross			break;
1291.1Sross		}
1301.1Sross
1311.1Sross	case 3:
1321.1Sross#if NPCKBD > 0
1331.1Sross		/* display console ... */
1341.1Sross		/* XXX */
1351.6Ssoda		(void) pckbc_cnattach(&tsp->pc_iot, IO_KBD, KBCMDP,
1361.6Ssoda		    PCKBC_KBD_SLOT);
1371.1Sross
1381.1Sross		if (CTB_TURBOSLOT_TYPE(ctbslot) ==
1391.1Sross		    CTB_TURBOSLOT_TYPE_ISA)
1401.1Sross			isa_display_console(&tsp->pc_iot, &tsp->pc_memt);
1411.1Sross		else {
1421.1Sross			/* The display PCI might be different */
1431.8Sthorpej			tsp_console_hose = CTB_TURBOSLOT_HOSE(ctbslot);
1441.8Sthorpej			tsp = tsp_init(0, tsp_console_hose);
1451.1Sross			pci_display_console(&tsp->pc_iot, &tsp->pc_memt,
1461.1Sross			    &tsp->pc_pc, CTB_TURBOSLOT_BUS(ctbslot),
1471.1Sross			    CTB_TURBOSLOT_SLOT(ctbslot), 0);
1481.1Sross		}
1491.1Sross#else
1501.1Sross		panic("not configured to use display && keyboard console");
1511.1Sross#endif
1521.1Sross		break;
1531.1Sross
1541.1Sross	default:
1551.1Sross		printf("ctb_term_type = 0x%lx ctb_turboslot = 0x%lx"
1561.1Sross		    " hose = %ld\n", ctb->ctb_term_type, ctbslot,
1571.1Sross		    CTB_TURBOSLOT_HOSE(ctbslot));
1581.1Sross
1591.1Sross		panic("consinit: unknown console type %ld\n",
1601.1Sross		    ctb->ctb_term_type);
1611.1Sross	}
1621.1Sross}
1631.1Sross
1641.1Srossstatic void
1651.1Srossdec_6600_device_register(dev, aux)
1661.1Sross	struct device *dev;
1671.1Sross	void *aux;
1681.1Sross{
1691.1Sross	static int found, initted, scsiboot, ideboot, netboot;
1701.1Sross	static struct device *primarydev, *pcidev, *scsipidev;
1711.1Sross	struct bootdev_data *b = bootdev_data;
1721.1Sross	struct device *parent = dev->dv_parent;
1731.1Sross	struct cfdata *cf = dev->dv_cfdata;
1741.1Sross	struct cfdriver *cd = cf->cf_driver;
1751.1Sross
1761.1Sross	if (found)
1771.1Sross		return;
1781.1Sross
1791.1Sross	if (!initted) {
1801.1Sross		scsiboot = (strcmp(b->protocol, "SCSI") == 0);
1811.4Sthorpej		netboot = (strcmp(b->protocol, "BOOTP") == 0) ||
1821.4Sthorpej		    (strcmp(b->protocol, "MOP") == 0);
1831.1Sross		/*
1841.1Sross		 * Add an extra check to boot from ide drives:
1851.1Sross		 * Newer SRM firmware use the protocol identifier IDE,
1861.1Sross		 * older SRM firmware use the protocol identifier SCSI.
1871.1Sross		 */
1881.1Sross		ideboot = (strcmp(b->protocol, "IDE") == 0);
1891.1Sross		DR_VERBOSE(printf("scsiboot = %d, ideboot = %d, netboot = %d\n",
1901.1Sross		    scsiboot, ideboot, netboot));
1911.1Sross		initted = 1;
1921.1Sross	}
1931.1Sross	if (primarydev == NULL) {
1941.1Sross		if (strcmp(cd->cd_name, "tsp"))
1951.1Sross			return;
1961.1Sross		else {
1971.1Sross			struct tsp_attach_args *tsp = aux;
1981.1Sross
1991.1Sross			if (b->bus != tsp->tsp_slot)
2001.1Sross				return;
2011.1Sross			primarydev = dev;
2021.1Sross			DR_VERBOSE(printf("\nprimarydev = %s\n",
2031.1Sross			    primarydev->dv_xname));
2041.1Sross			return;
2051.1Sross		}
2061.1Sross	}
2071.1Sross	if (pcidev == NULL) {
2081.1Sross		if (parent != primarydev)
2091.1Sross			return;
2101.1Sross		if (strcmp(cd->cd_name, "pci"))
2111.1Sross			return;
2121.1Sross		else {
2131.1Sross			struct pcibus_attach_args *pba = aux;
2141.1Sross
2151.1Sross			if ((b->slot / 1000) != pba->pba_bus)
2161.1Sross				return;
2171.1Sross
2181.1Sross			pcidev = dev;
2191.3Sveego			DR_VERBOSE(printf("\npcidev = %s\n",
2201.3Sveego			    pcidev->dv_xname));
2211.1Sross			return;
2221.1Sross		}
2231.1Sross	}
2241.3Sveego	if ((ideboot || scsiboot) && (scsipidev == NULL)) {
2251.1Sross		if (parent != pcidev)
2261.1Sross			return;
2271.1Sross		else {
2281.1Sross			struct pci_attach_args *pa = aux;
2291.1Sross
2301.1Sross			if (b->slot % 1000 / 100 != pa->pa_function)
2311.1Sross				return;
2321.1Sross			if (b->slot % 100 != pa->pa_device)
2331.1Sross				return;
2341.1Sross
2351.1Sross			scsipidev = dev;
2361.1Sross			DR_VERBOSE(printf("\nscsipidev = %s\n",
2371.1Sross			    scsipidev->dv_xname));
2381.1Sross			return;
2391.1Sross		}
2401.1Sross	}
2411.7Smatt	if ((ideboot || scsiboot) &&
2421.1Sross	    (!strcmp(cd->cd_name, "sd") ||
2431.1Sross	     !strcmp(cd->cd_name, "st") ||
2441.1Sross	     !strcmp(cd->cd_name, "cd"))) {
2451.1Sross		struct scsipibus_attach_args *sa = aux;
2461.1Sross
2471.1Sross		if (parent->dv_parent != scsipidev)
2481.1Sross			return;
2491.1Sross
2501.5Smatt		if (sa->sa_sc_link->type == BUS_SCSI
2511.5Smatt		    && b->unit / 100 != sa->sa_sc_link->scsipi_scsi.target)
2521.5Smatt			return;
2531.5Smatt		if (sa->sa_sc_link->type == BUS_ATAPI
2541.5Smatt		    && b->unit / 100 != sa->sa_sc_link->scsipi_atapi.drive)
2551.1Sross			return;
2561.1Sross
2571.1Sross		/* XXX LUN! */
2581.1Sross
2591.1Sross		switch (b->boot_dev_type) {
2601.1Sross		case 0:
2611.1Sross			if (strcmp(cd->cd_name, "sd") &&
2621.1Sross			    strcmp(cd->cd_name, "cd"))
2631.1Sross				return;
2641.1Sross			break;
2651.1Sross		case 1:
2661.1Sross			if (strcmp(cd->cd_name, "st"))
2671.1Sross				return;
2681.1Sross			break;
2691.1Sross		default:
2701.1Sross			return;
2711.1Sross		}
2721.1Sross
2731.1Sross		/* we've found it! */
2741.1Sross		booted_device = dev;
2751.1Sross		DR_VERBOSE(printf("\nbooted_device = %s\n",
2761.1Sross		    booted_device->dv_xname));
2771.1Sross		found = 1;
2781.1Sross	}
2791.1Sross
2801.1Sross	/*
2811.1Sross	 * Support to boot from IDE drives.
2821.1Sross	 */
2831.1Sross	if ((ideboot || scsiboot) && !strcmp(cd->cd_name, "wd")) {
2841.3Sveego		struct ata_atapi_attach *aa_link = aux;
2851.1Sross		if ((strncmp("pciide", parent->dv_xname, 6) != 0)) {
2861.1Sross			return;
2871.1Sross		} else {
2881.1Sross			if (parent != scsipidev)
2891.1Sross				return;
2901.1Sross		}
2911.3Sveego		DR_VERBOSE(printf("\nAtapi info: drive: %d, channel %d\n",
2921.3Sveego		    aa_link->aa_drv_data->drive, aa_link->aa_channel));
2931.3Sveego		DR_VERBOSE(printf("Bootdev info: unit: %d, channel: %d\n",
2941.3Sveego		    b->unit, b->channel));
2951.3Sveego		if (b->unit != aa_link->aa_drv_data->drive ||
2961.3Sveego		    b->channel != aa_link->aa_channel)
2971.3Sveego			return;
2981.1Sross
2991.1Sross		/* we've found it! */
3001.1Sross		booted_device = dev;
3011.3Sveego		DR_VERBOSE(printf("booted_device = %s\n",
3021.1Sross		    booted_device->dv_xname));
3031.1Sross		found = 1;
3041.1Sross	}
3051.1Sross	if (netboot) {
3061.1Sross		if (parent != pcidev)
3071.1Sross			return;
3081.1Sross		else {
3091.1Sross			struct pci_attach_args *pa = aux;
3101.1Sross
3111.1Sross			if (b->slot % 1000 / 100 != pa->pa_function)
3121.1Sross				return;
3131.1Sross			if ((b->slot % 100) != pa->pa_device)
3141.1Sross				return;
3151.1Sross
3161.1Sross			booted_device = dev;
3171.1Sross			DR_VERBOSE(printf("\nbooted_device = %s\n",
3181.1Sross			    booted_device->dv_xname));
3191.1Sross			found = 1;
3201.1Sross			return;
3211.1Sross		}
3221.1Sross	}
3231.1Sross}
324