dec_6600.c revision 1.15
11.15Sthorpej/* $NetBSD: dec_6600.c,v 1.15 2002/09/26 19:05:01 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.11Slukem#include "opt_kgdb.h"
311.11Slukem
321.1Sross#include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
331.1Sross
341.15Sthorpej__KERNEL_RCSID(0, "$NetBSD: dec_6600.c,v 1.15 2002/09/26 19:05:01 thorpej Exp $");
351.1Sross
361.1Sross#include <sys/param.h>
371.1Sross#include <sys/systm.h>
381.1Sross#include <sys/device.h>
391.1Sross#include <sys/termios.h>
401.14Sgehenna#include <sys/conf.h>
411.1Sross#include <dev/cons.h>
421.1Sross
431.1Sross#include <machine/rpb.h>
441.1Sross#include <machine/autoconf.h>
451.14Sgehenna#include <machine/cpuconf.h>
461.1Sross#include <machine/bus.h>
471.1Sross
481.1Sross#include <dev/ic/comreg.h>
491.1Sross#include <dev/ic/comvar.h>
501.1Sross
511.2Sthorpej#include <dev/isa/isareg.h>
521.1Sross#include <dev/isa/isavar.h>
531.6Ssoda#include <dev/ic/i8042reg.h>
541.2Sthorpej#include <dev/ic/pckbcvar.h>
551.1Sross#include <dev/pci/pcireg.h>
561.1Sross#include <dev/pci/pcivar.h>
571.1Sross
581.1Sross#include <alpha/pci/tsreg.h>
591.1Sross#include <alpha/pci/tsvar.h>
601.1Sross
611.1Sross#include <dev/scsipi/scsi_all.h>
621.1Sross#include <dev/scsipi/scsipi_all.h>
631.1Sross#include <dev/scsipi/scsiconf.h>
641.3Sveego#include <dev/ata/atavar.h>
651.13Sbouyer#include <dev/ata/wdvar.h>
661.1Sross
671.1Sross#include "pckbd.h"
681.1Sross
691.1Sross#ifndef CONSPEED
701.1Sross#define CONSPEED TTYDEF_SPEED
711.1Sross#endif
721.1Sross
731.1Sross#define	DR_VERBOSE(f) while (0)
741.1Sross
751.1Srossstatic int comcnrate __attribute__((unused)) = CONSPEED;
761.1Sross
771.1Srossvoid dec_6600_init __P((void));
781.1Srossstatic void dec_6600_cons_init __P((void));
791.1Srossstatic void dec_6600_device_register __P((struct device *, void *));
801.1Sross
811.9Sthorpej#ifdef KGDB
821.9Sthorpej#include <machine/db_machdep.h>
831.9Sthorpej
841.9Sthorpejstatic const char *kgdb_devlist[] = {
851.9Sthorpej	"com",
861.9Sthorpej	NULL,
871.9Sthorpej};
881.9Sthorpej#endif /* KGDB */
891.9Sthorpej
901.1Srossvoid
911.1Srossdec_6600_init()
921.1Sross{
931.1Sross
941.1Sross	platform.family = "6600";
951.1Sross
961.1Sross	if ((platform.model = alpha_dsr_sysname()) == NULL) {
971.1Sross		/* XXX Don't know the system variations, yet. */
981.1Sross		platform.model = alpha_unknown_sysname();
991.1Sross	}
1001.1Sross
1011.1Sross	platform.iobus = "tsc";
1021.1Sross	platform.cons_init = dec_6600_cons_init;
1031.1Sross	platform.device_register = dec_6600_device_register;
1041.1Sross	STQP(TS_C_DIM0) = 0UL;
1051.1Sross	STQP(TS_C_DIM1) = 0UL;
1061.1Sross}
1071.1Sross
1081.1Srossstatic void
1091.1Srossdec_6600_cons_init()
1101.1Sross{
1111.1Sross	struct ctb *ctb;
1121.1Sross	u_int64_t ctbslot;
1131.1Sross	struct tsp_config *tsp;
1141.1Sross
1151.1Sross	ctb = (struct ctb *)(((caddr_t)hwrpb) + hwrpb->rpb_ctb_off);
1161.1Sross	ctbslot = ctb->ctb_turboslot;
1171.1Sross
1181.8Sthorpej	/* Console hose defaults to hose 0. */
1191.8Sthorpej	tsp_console_hose = 0;
1201.8Sthorpej
1211.8Sthorpej	tsp = tsp_init(0, tsp_console_hose);
1221.1Sross
1231.1Sross	switch (ctb->ctb_term_type) {
1241.12Sthorpej	case CTB_PRINTERPORT:
1251.1Sross		/* serial console ... */
1261.1Sross		assert(CTB_TURBOSLOT_HOSE(ctbslot) == 0);
1271.1Sross		/* XXX */
1281.1Sross		{
1291.1Sross			/*
1301.1Sross			 * Delay to allow PROM putchars to complete.
1311.1Sross			 * FIFO depth * character time,
1321.1Sross			 * character time = (1000000 / (defaultrate / 10))
1331.1Sross			 */
1341.1Sross			DELAY(160000000 / comcnrate);
1351.1Sross
1361.1Sross			if(comcnattach(&tsp->pc_iot, 0x3f8, comcnrate,
1371.1Sross			    COM_FREQ,
1381.1Sross			    (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8))
1391.1Sross				panic("can't init serial console");
1401.1Sross
1411.1Sross			break;
1421.1Sross		}
1431.1Sross
1441.12Sthorpej	case CTB_GRAPHICS:
1451.1Sross#if NPCKBD > 0
1461.1Sross		/* display console ... */
1471.1Sross		/* XXX */
1481.6Ssoda		(void) pckbc_cnattach(&tsp->pc_iot, IO_KBD, KBCMDP,
1491.6Ssoda		    PCKBC_KBD_SLOT);
1501.1Sross
1511.1Sross		if (CTB_TURBOSLOT_TYPE(ctbslot) ==
1521.1Sross		    CTB_TURBOSLOT_TYPE_ISA)
1531.1Sross			isa_display_console(&tsp->pc_iot, &tsp->pc_memt);
1541.1Sross		else {
1551.1Sross			/* The display PCI might be different */
1561.8Sthorpej			tsp_console_hose = CTB_TURBOSLOT_HOSE(ctbslot);
1571.8Sthorpej			tsp = tsp_init(0, tsp_console_hose);
1581.1Sross			pci_display_console(&tsp->pc_iot, &tsp->pc_memt,
1591.1Sross			    &tsp->pc_pc, CTB_TURBOSLOT_BUS(ctbslot),
1601.1Sross			    CTB_TURBOSLOT_SLOT(ctbslot), 0);
1611.1Sross		}
1621.1Sross#else
1631.1Sross		panic("not configured to use display && keyboard console");
1641.1Sross#endif
1651.1Sross		break;
1661.1Sross
1671.1Sross	default:
1681.1Sross		printf("ctb_term_type = 0x%lx ctb_turboslot = 0x%lx"
1691.1Sross		    " hose = %ld\n", ctb->ctb_term_type, ctbslot,
1701.1Sross		    CTB_TURBOSLOT_HOSE(ctbslot));
1711.1Sross
1721.1Sross		panic("consinit: unknown console type %ld\n",
1731.1Sross		    ctb->ctb_term_type);
1741.1Sross	}
1751.9Sthorpej#ifdef KGDB
1761.9Sthorpej	/* Attach the KGDB device. */
1771.9Sthorpej	alpha_kgdb_init(kgdb_devlist, &tsp->pc_iot);
1781.9Sthorpej#endif /* KGDB */
1791.1Sross}
1801.1Sross
1811.1Srossstatic void
1821.1Srossdec_6600_device_register(dev, aux)
1831.1Sross	struct device *dev;
1841.1Sross	void *aux;
1851.1Sross{
1861.1Sross	static int found, initted, scsiboot, ideboot, netboot;
1871.1Sross	static struct device *primarydev, *pcidev, *scsipidev;
1881.1Sross	struct bootdev_data *b = bootdev_data;
1891.1Sross	struct device *parent = dev->dv_parent;
1901.1Sross	struct cfdata *cf = dev->dv_cfdata;
1911.15Sthorpej	const char *name = cf->cf_driver->cd_name;
1921.1Sross
1931.1Sross	if (found)
1941.1Sross		return;
1951.1Sross
1961.1Sross	if (!initted) {
1971.1Sross		scsiboot = (strcmp(b->protocol, "SCSI") == 0);
1981.4Sthorpej		netboot = (strcmp(b->protocol, "BOOTP") == 0) ||
1991.4Sthorpej		    (strcmp(b->protocol, "MOP") == 0);
2001.1Sross		/*
2011.1Sross		 * Add an extra check to boot from ide drives:
2021.1Sross		 * Newer SRM firmware use the protocol identifier IDE,
2031.1Sross		 * older SRM firmware use the protocol identifier SCSI.
2041.1Sross		 */
2051.1Sross		ideboot = (strcmp(b->protocol, "IDE") == 0);
2061.1Sross		DR_VERBOSE(printf("scsiboot = %d, ideboot = %d, netboot = %d\n",
2071.1Sross		    scsiboot, ideboot, netboot));
2081.1Sross		initted = 1;
2091.1Sross	}
2101.1Sross	if (primarydev == NULL) {
2111.15Sthorpej		if (strcmp(name, "tsp"))
2121.1Sross			return;
2131.1Sross		else {
2141.1Sross			struct tsp_attach_args *tsp = aux;
2151.1Sross
2161.1Sross			if (b->bus != tsp->tsp_slot)
2171.1Sross				return;
2181.1Sross			primarydev = dev;
2191.1Sross			DR_VERBOSE(printf("\nprimarydev = %s\n",
2201.1Sross			    primarydev->dv_xname));
2211.1Sross			return;
2221.1Sross		}
2231.1Sross	}
2241.1Sross	if (pcidev == NULL) {
2251.1Sross		if (parent != primarydev)
2261.1Sross			return;
2271.15Sthorpej		if (strcmp(name, "pci"))
2281.1Sross			return;
2291.1Sross		else {
2301.1Sross			struct pcibus_attach_args *pba = aux;
2311.1Sross
2321.1Sross			if ((b->slot / 1000) != pba->pba_bus)
2331.1Sross				return;
2341.1Sross
2351.1Sross			pcidev = dev;
2361.3Sveego			DR_VERBOSE(printf("\npcidev = %s\n",
2371.3Sveego			    pcidev->dv_xname));
2381.1Sross			return;
2391.1Sross		}
2401.1Sross	}
2411.3Sveego	if ((ideboot || scsiboot) && (scsipidev == NULL)) {
2421.1Sross		if (parent != pcidev)
2431.1Sross			return;
2441.1Sross		else {
2451.1Sross			struct pci_attach_args *pa = aux;
2461.1Sross
2471.1Sross			if (b->slot % 1000 / 100 != pa->pa_function)
2481.1Sross				return;
2491.1Sross			if (b->slot % 100 != pa->pa_device)
2501.1Sross				return;
2511.1Sross
2521.1Sross			scsipidev = dev;
2531.1Sross			DR_VERBOSE(printf("\nscsipidev = %s\n",
2541.1Sross			    scsipidev->dv_xname));
2551.1Sross			return;
2561.1Sross		}
2571.1Sross	}
2581.7Smatt	if ((ideboot || scsiboot) &&
2591.15Sthorpej	    (!strcmp(name, "sd") ||
2601.15Sthorpej	     !strcmp(name, "st") ||
2611.15Sthorpej	     !strcmp(name, "cd"))) {
2621.1Sross		struct scsipibus_attach_args *sa = aux;
2631.1Sross
2641.1Sross		if (parent->dv_parent != scsipidev)
2651.1Sross			return;
2661.1Sross
2671.10Sbouyer		if ((sa->sa_periph->periph_channel->chan_bustype->bustype_type
2681.10Sbouyer		     == SCSIPI_BUSTYPE_SCSI ||
2691.10Sbouyer		     sa->sa_periph->periph_channel->chan_bustype->bustype_type
2701.10Sbouyer		     == SCSIPI_BUSTYPE_ATAPI)
2711.10Sbouyer		    && b->unit / 100 != sa->sa_periph->periph_target)
2721.1Sross			return;
2731.1Sross
2741.1Sross		/* XXX LUN! */
2751.1Sross
2761.1Sross		switch (b->boot_dev_type) {
2771.1Sross		case 0:
2781.15Sthorpej			if (strcmp(name, "sd") &&
2791.15Sthorpej			    strcmp(name, "cd"))
2801.1Sross				return;
2811.1Sross			break;
2821.1Sross		case 1:
2831.15Sthorpej			if (strcmp(name, "st"))
2841.1Sross				return;
2851.1Sross			break;
2861.1Sross		default:
2871.1Sross			return;
2881.1Sross		}
2891.1Sross
2901.1Sross		/* we've found it! */
2911.1Sross		booted_device = dev;
2921.1Sross		DR_VERBOSE(printf("\nbooted_device = %s\n",
2931.1Sross		    booted_device->dv_xname));
2941.1Sross		found = 1;
2951.1Sross	}
2961.1Sross
2971.1Sross	/*
2981.1Sross	 * Support to boot from IDE drives.
2991.1Sross	 */
3001.15Sthorpej	if ((ideboot || scsiboot) && !strcmp(name, "wd")) {
3011.13Sbouyer		struct ata_device *adev = aux;
3021.1Sross		if ((strncmp("pciide", parent->dv_xname, 6) != 0)) {
3031.1Sross			return;
3041.1Sross		} else {
3051.1Sross			if (parent != scsipidev)
3061.1Sross				return;
3071.1Sross		}
3081.3Sveego		DR_VERBOSE(printf("\nAtapi info: drive: %d, channel %d\n",
3091.13Sbouyer		    adev->adev_drv_data->drive, adev->adev_channel));
3101.3Sveego		DR_VERBOSE(printf("Bootdev info: unit: %d, channel: %d\n",
3111.3Sveego		    b->unit, b->channel));
3121.13Sbouyer		if (b->unit != adev->adev_drv_data->drive ||
3131.13Sbouyer		    b->channel != adev->adev_channel)
3141.3Sveego			return;
3151.1Sross
3161.1Sross		/* we've found it! */
3171.1Sross		booted_device = dev;
3181.3Sveego		DR_VERBOSE(printf("booted_device = %s\n",
3191.1Sross		    booted_device->dv_xname));
3201.1Sross		found = 1;
3211.1Sross	}
3221.1Sross	if (netboot) {
3231.1Sross		if (parent != pcidev)
3241.1Sross			return;
3251.1Sross		else {
3261.1Sross			struct pci_attach_args *pa = aux;
3271.1Sross
3281.1Sross			if (b->slot % 1000 / 100 != pa->pa_function)
3291.1Sross				return;
3301.1Sross			if ((b->slot % 100) != pa->pa_device)
3311.1Sross				return;
3321.1Sross
3331.1Sross			booted_device = dev;
3341.1Sross			DR_VERBOSE(printf("\nbooted_device = %s\n",
3351.1Sross			    booted_device->dv_xname));
3361.1Sross			found = 1;
3371.1Sross			return;
3381.1Sross		}
3391.1Sross	}
3401.1Sross}
341