Home | History | Annotate | Line # | Download | only in dev
imc.c revision 1.12
      1 /*	$NetBSD: imc.c,v 1.12 2004/01/13 13:05:17 sekiya 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.12 2004/01/13 13:05:17 sekiya 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 #include <machine/sysconf.h>
     43 
     44 #include <sgimips/dev/imcreg.h>
     45 
     46 #include "locators.h"
     47 
     48 struct imc_softc {
     49 	struct device sc_dev;
     50 
     51 	bus_space_tag_t iot;
     52 	bus_space_handle_t ioh;
     53 
     54 	int eisa_present : 1;
     55 };
     56 
     57 static int	imc_match(struct device *, struct cfdata *, void *);
     58 static void	imc_attach(struct device *, struct device *, void *);
     59 static int	imc_print(void *, const char *);
     60 void		imc_bus_reset(void);
     61 void		imc_bus_error(void);
     62 void		imc_watchdog_tickle(void);
     63 
     64 CFATTACH_DECL(imc, sizeof(struct imc_softc),
     65     imc_match, imc_attach, NULL, NULL);
     66 
     67 struct imc_attach_args {
     68 	const char* iaa_name;
     69 
     70 	bus_space_tag_t iaa_st;
     71 	bus_space_handle_t iaa_sh;
     72 
     73 /* ? */
     74 	long	iaa_offset;
     75 	int	iaa_intr;
     76 #if 0
     77 	int	iaa_stride;
     78 #endif
     79 };
     80 
     81 struct imc_softc isc;
     82 
     83 static int
     84 imc_match(parent, match, aux)
     85 	struct device *parent;
     86 	struct cfdata *match;
     87 	void *aux;
     88 {
     89 
     90 	if ( (mach_type == MACH_SGI_IP22) || (mach_type == MACH_SGI_IP20) )
     91 		return (1);
     92 
     93 	return (0);
     94 }
     95 
     96 static void
     97 imc_attach(parent, self, aux)
     98 	struct device *parent;
     99 	struct device *self;
    100 	void *aux;
    101 {
    102 	u_int32_t reg;
    103 	struct imc_attach_args iaa;
    104 	struct mainbus_attach_args *ma = aux;
    105 	u_int32_t sysid;
    106 
    107 	isc.iot = SGIMIPS_BUS_SPACE_HPC;
    108 	if (bus_space_map(isc.iot, ma->ma_addr, 0,
    109             BUS_SPACE_MAP_LINEAR, &isc.ioh))
    110                 panic("imc_attach: could not allocate memory\n");
    111 
    112 	platform.bus_reset = imc_bus_reset;
    113 
    114 	sysid = bus_space_read_4(isc.iot, isc.ioh, IMC_SYSID);
    115 
    116 	/* EISA present bit is on even on Indys, so don't trust it! */
    117 	if (mach_subtype == MACH_SGI_IP22_FULLHOUSE)
    118 		isc.eisa_present = (sysid & IMC_SYSID_HAVEISA);
    119 	else
    120 		isc.eisa_present = 0;
    121 
    122 	printf("\nimc0: Revision %d", (sysid & IMC_SYSID_REVMASK));
    123 
    124 	if (isc.eisa_present)
    125 		printf(", EISA bus present");
    126 
    127 	printf("\n");
    128 
    129 	/* Clear CPU/GIO error status registers to clear any leftover bits. */
    130 	bus_space_write_4(isc.iot, isc.ioh, IMC_CPU_ERRSTAT, 0);
    131 	bus_space_write_4(isc.iot, isc.ioh, IMC_GIO_ERRSTAT, 0);
    132 
    133 	/*
    134 	 * Enable parity reporting on GIO/main memory transactions.
    135 	 * Disable parity checking on CPU bus transactions (as turning
    136 	 * it on seems to cause spurious bus errors), but enable parity
    137 	 * checking on CPU reads from main memory (note that this bit
    138 	 * has the opposite sense... Turning it on turns the checks off!).
    139 	 * Finally, turn on interrupt writes to the CPU from the MC.
    140 	 */
    141 	reg = bus_space_read_4(isc.iot, isc.ioh, IMC_CPUCTRL0);
    142 	reg &= ~IMC_CPUCTRL0_NCHKMEMPAR;
    143 	reg |= (IMC_CPUCTRL0_GPR | IMC_CPUCTRL0_MPR | IMC_CPUCTRL0_INTENA);
    144 	bus_space_write_4(isc.iot, isc.ioh, IMC_CPUCTRL0, reg);
    145 
    146 	/* Setup the MC write buffer depth */
    147 	reg = bus_space_read_4(isc.iot, isc.ioh, IMC_CPUCTRL1);
    148 	reg = (reg & ~IMC_CPUCTRL1_MCHWMSK) | 13;
    149 	if (mach_type == MACH_SGI_IP20)
    150 		reg = (reg & ~IMC_CPUCTRL1_HPCLITTLE) | IMC_CPUCTRL1_HPCFX;
    151 	bus_space_write_4(isc.iot, isc.ioh, IMC_CPUCTRL1, reg);
    152 
    153 
    154 	/*
    155 	 * Set GIO64 arbitrator configuration register:
    156 	 *
    157 	 * Preserve PROM-set graphics-related bits, as they seem to depend
    158 	 * on the graphics variant present and I'm not sure how to figure
    159 	 * that out or 100% sure what the correct settings are for each.
    160 	 */
    161 	reg = bus_space_read_4(isc.iot, isc.ioh, IMC_GIO64ARB);
    162 	reg &= (IMC_GIO64ARB_GRX64 | IMC_GIO64ARB_GRXRT | IMC_GIO64ARB_GRXMST);
    163 
    164 	/* GIO64 invariant for all IP22 platforms: one GIO bus, HPC1 @ 64 */
    165 	reg |= IMC_GIO64ARB_ONEGIO | IMC_GIO64ARB_HPC64;
    166 
    167 	/* Rest of settings are machine/board dependant */
    168 	if (mach_type == MACH_SGI_IP20)
    169 	{
    170 	        reg |= (IMC_GIO64ARB_ONEGIO |
    171 			 IMC_GIO64ARB_EXP1RT | IMC_GIO64ARB_EXP0RT);
    172                 reg &= ~(IMC_GIO64ARB_HPC64 |
    173                          IMC_GIO64ARB_HPCEXP64 | IMC_GIO64ARB_EISA64 |
    174                          IMC_GIO64ARB_EXP064   | IMC_GIO64ARB_EXP164 |
    175                          IMC_GIO64ARB_EXP0PIPE | IMC_GIO64ARB_EXP1PIPE |
    176                          IMC_GIO64ARB_EXP0MST | IMC_GIO64ARB_EXP1MST);
    177 /* XXX second ethernet adapter */
    178                 reg |= IMC_GIO64ARB_EXP0MST;
    179 	}
    180 	else
    181 	{
    182 		switch (mach_subtype) {
    183 		case MACH_SGI_IP22_GUINESS:
    184 			/* EISA can bus-master, is 64-bit */
    185 			reg |= (IMC_GIO64ARB_EISAMST | IMC_GIO64ARB_EISA64);
    186 			break;
    187 
    188 		case MACH_SGI_IP22_FULLHOUSE:
    189 		/*
    190 		 * All Fullhouse boards have a 64-bit HPC2 and pipelined
    191 		 * EXP0 slot.
    192 		 */
    193 			reg |= (IMC_GIO64ARB_HPCEXP64 | IMC_GIO64ARB_EXP0PIPE);
    194 
    195 			if (mach_boardrev < 2) {
    196 			/* EXP0 realtime, EXP1 can master */
    197 				reg |= (IMC_GIO64ARB_EXP0RT | IMC_GIO64ARB_EXP1MST);
    198 			} else {
    199 				/* EXP1 pipelined as well, EISA masters */
    200 				reg |= (IMC_GIO64ARB_EXP1PIPE | IMC_GIO64ARB_EISAMST);
    201 			}
    202 			break;
    203 		}
    204 	}
    205 
    206 	bus_space_write_4(isc.iot, isc.ioh, IMC_GIO64ARB, reg);
    207 
    208 	if (isc.eisa_present) {
    209 #if notyet
    210 		memset(&iaa, 0, sizeof(iaa));
    211 
    212 		iaa.iaa_name = "eisa";
    213 		(void)config_found(self, (void*)&iaa, imc_print);
    214 #endif
    215 	}
    216 
    217 	memset(&iaa, 0, sizeof(iaa));
    218 
    219 	iaa.iaa_name = "gio";
    220 	(void)config_found(self, (void*)&iaa, imc_print);
    221 
    222 	/* enable watchdog and clear it */
    223 	reg = bus_space_read_4(isc.iot, isc.ioh, IMC_CPUCTRL0);
    224 	reg |= IMC_CPUCTRL0_WDOG;
    225 	bus_space_write_4(isc.iot, isc.ioh, IMC_CPUCTRL0, reg);
    226 	imc_watchdog_tickle();
    227 }
    228 
    229 
    230 static int
    231 imc_print(aux, name)
    232 	void *aux;
    233 	const char *name;
    234 {
    235 	struct imc_attach_args* iaa = aux;
    236 
    237 	if (name)
    238 		aprint_normal("%s at %s", iaa->iaa_name, name);
    239 
    240 	return UNCONF;
    241 }
    242 
    243 void
    244 imc_bus_reset(void)
    245 {
    246 	bus_space_write_4(isc.iot, isc.ioh, IMC_CPU_ERRSTAT, 0);
    247 	bus_space_write_4(isc.iot, isc.ioh, IMC_GIO_ERRSTAT, 0);
    248 }
    249 
    250 void
    251 imc_bus_error(void)
    252 {
    253 	printf("bus error: cpu_stat %08x addr %08x, gio_stat %08x addr %08x\n",
    254 			bus_space_read_4(isc.iot, isc.ioh, IMC_CPU_ERRSTAT),
    255 			bus_space_read_4(isc.iot, isc.ioh, IMC_CPU_ERRADDR),
    256 			bus_space_read_4(isc.iot, isc.ioh, IMC_GIO_ERRSTAT),
    257 			bus_space_read_4(isc.iot, isc.ioh, IMC_GIO_ERRADDR) );
    258 	imc_bus_reset();
    259 }
    260 
    261 void
    262 imc_watchdog_tickle(void)
    263 {
    264 	bus_space_write_4(isc.iot, isc.ioh, IMC_WDOG, 0);
    265 }
    266