Home | History | Annotate | Line # | Download | only in dev
imc.c revision 1.9
      1 /*	$NetBSD: imc.c,v 1.9 2003/07/15 03:35:52 lukem Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2001 Rafal K. Boni
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. The name of the author may not be used to endorse or promote products
     16  *    derived from this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  */
     29 
     30 #include <sys/cdefs.h>
     31 __KERNEL_RCSID(0, "$NetBSD: imc.c,v 1.9 2003/07/15 03:35:52 lukem Exp $");
     32 
     33 #include <sys/param.h>
     34 #include <sys/device.h>
     35 #include <sys/systm.h>
     36 
     37 #include <machine/cpu.h>
     38 #include <machine/locore.h>
     39 #include <machine/autoconf.h>
     40 #include <machine/bus.h>
     41 #include <machine/machtype.h>
     42 
     43 #include <sgimips/dev/imcreg.h>
     44 
     45 #include "locators.h"
     46 
     47 struct imc_softc {
     48 	struct device sc_dev;
     49 
     50 	int eisa_present : 1;
     51 };
     52 
     53 static int	imc_match(struct device *, struct cfdata *, void *);
     54 static void	imc_attach(struct device *, struct device *, void *);
     55 static int	imc_print(void *, const char *);
     56 
     57 CFATTACH_DECL(imc, sizeof(struct imc_softc),
     58     imc_match, imc_attach, NULL, NULL);
     59 
     60 struct imc_attach_args {
     61 	const char* iaa_name;
     62 
     63 	bus_space_tag_t iaa_st;
     64 	bus_space_handle_t iaa_sh;
     65 
     66 /* ? */
     67 	long	iaa_offset;
     68 	int	iaa_intr;
     69 #if 0
     70 	int	iaa_stride;
     71 #endif
     72 };
     73 
     74 static int
     75 imc_match(parent, match, aux)
     76 	struct device *parent;
     77 	struct cfdata *match;
     78 	void *aux;
     79 {
     80 
     81 	/*
     82 	 * The IMC is an INDY/INDIGO2 thing.
     83 	 */
     84 	if (mach_type != MACH_SGI_IP22)
     85 		return (0);
     86 
     87 	/* Make sure it's actually there and readable */
     88 	if (badaddr((void*)MIPS_PHYS_TO_KSEG1(IMC_SYSID), sizeof(u_int32_t)))
     89 		return (0);
     90 
     91 	return (1);
     92 }
     93 
     94 static void
     95 imc_attach(parent, self, aux)
     96 	struct device *parent;
     97 	struct device *self;
     98 	void *aux;
     99 {
    100 	u_int32_t reg;
    101 	struct imc_attach_args iaa;
    102 	struct imc_softc *isc = (void *) self;
    103 	u_int32_t sysid = *(volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(IMC_SYSID);
    104 
    105 	/* EISA present bit is on even on Indys, so don't trust it! */
    106 	if (mach_subtype == MACH_SGI_IP22_FULLHOUSE)
    107 		isc->eisa_present = (sysid & IMC_SYSID_HAVEISA);
    108 	else
    109 		isc->eisa_present = 0;
    110 
    111 	printf("\nimc0: Revision %d", (sysid & IMC_SYSID_REVMASK));
    112 
    113 	if (isc->eisa_present)
    114 		printf(", EISA bus present");
    115 
    116 	printf("\n");
    117 
    118 	/* Clear CPU/GIO error status registers to clear any leftover bits. */
    119 	*(volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(IMC_CPU_ERRSTAT) = 0;
    120 	*(volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(IMC_GIO_ERRSTAT) = 0;
    121 
    122 	/*
    123 	 * Enable parity reporting on GIO/main memory transactions.
    124 	 * Disable parity checking on CPU bus transactions (as turning
    125 	 * it on seems to cause spurious bus errors), but enable parity
    126 	 * checking on CPU reads from main memory (note that this bit
    127 	 * has the opposite sense... Turning it on turns the checks off!).
    128 	 * Finally, turn on interrupt writes to the CPU from the MC.
    129 	 */
    130 	reg = *(volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(IMC_CPUCTRL0);
    131 	reg &= ~IMC_CPUCTRL0_NCHKMEMPAR;
    132 	reg |= (IMC_CPUCTRL0_GPR | IMC_CPUCTRL0_MPR | IMC_CPUCTRL0_INTENA);
    133 	*(volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(IMC_CPUCTRL0) = reg;
    134 
    135 	/* Setup the MC write buffer depth */
    136 	reg = *(volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(IMC_CPUCTRL1);
    137 	reg = (reg & ~IMC_CPUCTRL1_MCHWMSK) | 13;
    138 	*(volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(IMC_CPUCTRL1) = reg;
    139 
    140 	/*
    141 	 * Set GIO64 arbitrator configuration register:
    142 	 *
    143 	 * Preserve PROM-set graphics-related bits, as they seem to depend
    144 	 * on the graphics variant present and I'm not sure how to figure
    145 	 * that out or 100% sure what the correct settings are for each.
    146 	 */
    147 	reg = *(volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(IMC_GIO64ARB);
    148 	reg &= (IMC_GIO64ARB_GRX64 | IMC_GIO64ARB_GRXRT | IMC_GIO64ARB_GRXMST);
    149 
    150 	/* GIO64 invariant for all IP22 platforms: one GIO bus, HPC1 @ 64 */
    151 	reg |= IMC_GIO64ARB_ONEGIO | IMC_GIO64ARB_HPC64;
    152 
    153 	/* Rest of settings are machine/board dependant */
    154 	switch (mach_subtype) {
    155 	case MACH_SGI_IP22_GUINESS:
    156 		/* EISA can bus-master, is 64-bit */
    157 		reg |= (IMC_GIO64ARB_EISAMST | IMC_GIO64ARB_EISA64);
    158 		break;
    159 
    160 	case MACH_SGI_IP22_FULLHOUSE:
    161 		/*
    162 		 * All Fullhouse boards have a 64-bit HPC2 and pipelined
    163 		 * EXP0 slot.
    164 		 */
    165 		reg |= (IMC_GIO64ARB_HPCEXP64 | IMC_GIO64ARB_EXP0PIPE);
    166 
    167 		if (mach_boardrev < 2) {
    168 			/* EXP0 realtime, EXP1 can master */
    169 			reg |= (IMC_GIO64ARB_EXP0RT | IMC_GIO64ARB_EXP1MST);
    170 		} else {
    171 			/* EXP1 pipelined as well, EISA masters */
    172 			reg |= (IMC_GIO64ARB_EXP1PIPE | IMC_GIO64ARB_EISAMST);
    173 		}
    174 		break;
    175 	}
    176 
    177 	*(volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(IMC_GIO64ARB) = reg;
    178 
    179 	if (isc->eisa_present) {
    180 #if notyet
    181 		memset(&iaa, 0, sizeof(iaa));
    182 
    183 		iaa.iaa_name = "eisa";
    184 		(void)config_found(self, (void*)&iaa, imc_print);
    185 #endif
    186 	}
    187 
    188 	memset(&iaa, 0, sizeof(iaa));
    189 
    190 	iaa.iaa_name = "gio";
    191 	(void)config_found(self, (void*)&iaa, imc_print);
    192 }
    193 
    194 
    195 static int
    196 imc_print(aux, name)
    197 	void *aux;
    198 	const char *name;
    199 {
    200 	struct imc_attach_args* iaa = aux;
    201 
    202 	if (name)
    203 		aprint_normal("%s at %s", iaa->iaa_name, name);
    204 
    205 	return UNCONF;
    206 }
    207 
    208