Home | History | Annotate | Line # | Download | only in dev
imc.c revision 1.8.2.6
      1  1.8.2.6    skrll /*	$NetBSD: imc.c,v 1.8.2.6 2005/11/10 13:58:33 skrll Exp $	*/
      2      1.1  thorpej 
      3      1.1  thorpej /*
      4      1.1  thorpej  * Copyright (c) 2001 Rafal K. Boni
      5      1.1  thorpej  * All rights reserved.
      6      1.4   simonb  *
      7      1.1  thorpej  * Redistribution and use in source and binary forms, with or without
      8      1.1  thorpej  * modification, are permitted provided that the following conditions
      9      1.1  thorpej  * are met:
     10      1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     11      1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     12      1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     14      1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     15      1.1  thorpej  * 3. The name of the author may not be used to endorse or promote products
     16      1.1  thorpej  *    derived from this software without specific prior written permission.
     17      1.4   simonb  *
     18      1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19      1.1  thorpej  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20      1.1  thorpej  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21      1.1  thorpej  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22      1.1  thorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23      1.1  thorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24      1.1  thorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25      1.1  thorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26      1.1  thorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27      1.1  thorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28      1.1  thorpej  */
     29      1.1  thorpej 
     30  1.8.2.1    skrll #include <sys/cdefs.h>
     31  1.8.2.6    skrll __KERNEL_RCSID(0, "$NetBSD: imc.c,v 1.8.2.6 2005/11/10 13:58:33 skrll Exp $");
     32  1.8.2.1    skrll 
     33      1.1  thorpej #include <sys/param.h>
     34      1.1  thorpej #include <sys/device.h>
     35      1.1  thorpej #include <sys/systm.h>
     36      1.1  thorpej 
     37      1.1  thorpej #include <machine/cpu.h>
     38      1.1  thorpej #include <machine/locore.h>
     39      1.1  thorpej #include <machine/autoconf.h>
     40      1.1  thorpej #include <machine/bus.h>
     41      1.2  thorpej #include <machine/machtype.h>
     42  1.8.2.1    skrll #include <machine/sysconf.h>
     43      1.1  thorpej 
     44      1.3    rafal #include <sgimips/dev/imcreg.h>
     45      1.3    rafal 
     46      1.1  thorpej #include "locators.h"
     47      1.1  thorpej 
     48      1.1  thorpej struct imc_softc {
     49      1.1  thorpej 	struct device sc_dev;
     50      1.1  thorpej 
     51  1.8.2.1    skrll 	bus_space_tag_t iot;
     52  1.8.2.1    skrll 	bus_space_handle_t ioh;
     53  1.8.2.1    skrll 
     54  1.8.2.1    skrll 	int eisa_present;
     55      1.1  thorpej };
     56      1.1  thorpej 
     57      1.1  thorpej static int	imc_match(struct device *, struct cfdata *, void *);
     58      1.1  thorpej static void	imc_attach(struct device *, struct device *, void *);
     59      1.1  thorpej static int	imc_print(void *, const char *);
     60  1.8.2.1    skrll static void	imc_bus_reset(void);
     61  1.8.2.1    skrll static void	imc_bus_error(u_int32_t, u_int32_t, u_int32_t, u_int32_t);
     62  1.8.2.1    skrll static void	imc_watchdog_reset(void);
     63  1.8.2.1    skrll static void	imc_watchdog_disable(void);
     64  1.8.2.1    skrll static void	imc_watchdog_enable(void);
     65      1.1  thorpej 
     66      1.6  thorpej CFATTACH_DECL(imc, sizeof(struct imc_softc),
     67      1.7  thorpej     imc_match, imc_attach, NULL, NULL);
     68      1.1  thorpej 
     69      1.1  thorpej struct imc_attach_args {
     70      1.1  thorpej 	const char* iaa_name;
     71      1.1  thorpej 
     72      1.1  thorpej 	bus_space_tag_t iaa_st;
     73      1.1  thorpej 	bus_space_handle_t iaa_sh;
     74      1.1  thorpej 
     75      1.1  thorpej /* ? */
     76      1.4   simonb 	long	iaa_offset;
     77      1.4   simonb 	int	iaa_intr;
     78      1.1  thorpej #if 0
     79      1.4   simonb 	int	iaa_stride;
     80      1.1  thorpej #endif
     81      1.1  thorpej };
     82      1.1  thorpej 
     83  1.8.2.1    skrll struct imc_softc isc;
     84  1.8.2.1    skrll 
     85      1.1  thorpej static int
     86  1.8.2.5    skrll imc_match(struct device *parent, struct cfdata *match, void *aux)
     87      1.1  thorpej {
     88      1.1  thorpej 
     89  1.8.2.1    skrll 	if ( (mach_type == MACH_SGI_IP22) || (mach_type == MACH_SGI_IP20) )
     90  1.8.2.1    skrll 		return (1);
     91      1.2  thorpej 
     92  1.8.2.1    skrll 	return (0);
     93      1.1  thorpej }
     94      1.1  thorpej 
     95      1.1  thorpej static void
     96  1.8.2.5    skrll imc_attach(struct device *parent, struct device *self, void *aux)
     97      1.1  thorpej {
     98      1.1  thorpej 	u_int32_t reg;
     99      1.1  thorpej 	struct imc_attach_args iaa;
    100  1.8.2.1    skrll 	struct mainbus_attach_args *ma = aux;
    101  1.8.2.1    skrll 	u_int32_t sysid;
    102      1.1  thorpej 
    103  1.8.2.1    skrll 	isc.iot = SGIMIPS_BUS_SPACE_HPC;
    104  1.8.2.1    skrll 	if (bus_space_map(isc.iot, ma->ma_addr, 0,
    105  1.8.2.6    skrll 	    BUS_SPACE_MAP_LINEAR, &isc.ioh))
    106  1.8.2.6    skrll 		panic("imc_attach: could not allocate memory\n");
    107  1.8.2.1    skrll 
    108  1.8.2.1    skrll 	platform.bus_reset = imc_bus_reset;
    109  1.8.2.1    skrll 	platform.watchdog_reset = imc_watchdog_reset;
    110  1.8.2.1    skrll 	platform.watchdog_disable = imc_watchdog_disable;
    111  1.8.2.1    skrll 	platform.watchdog_enable = imc_watchdog_enable;
    112  1.8.2.1    skrll 
    113  1.8.2.1    skrll 	sysid = bus_space_read_4(isc.iot, isc.ioh, IMC_SYSID);
    114  1.8.2.1    skrll 
    115  1.8.2.5    skrll 	/* EISA exists on IP22 only */
    116  1.8.2.5    skrll 	if (mach_subtype == MACH_SGI_IP22_FULLHOUSE)
    117  1.8.2.1    skrll 		isc.eisa_present = (sysid & IMC_SYSID_HAVEISA);
    118  1.8.2.5    skrll 	else
    119  1.8.2.5    skrll 		isc.eisa_present = 0;
    120      1.1  thorpej 
    121  1.8.2.1    skrll 	printf(": revision %d", (sysid & IMC_SYSID_REVMASK));
    122      1.1  thorpej 
    123  1.8.2.1    skrll 	if (isc.eisa_present)
    124      1.4   simonb 		printf(", EISA bus present");
    125      1.1  thorpej 
    126      1.1  thorpej 	printf("\n");
    127      1.1  thorpej 
    128      1.1  thorpej 	/* Clear CPU/GIO error status registers to clear any leftover bits. */
    129  1.8.2.1    skrll 	imc_bus_reset();
    130  1.8.2.1    skrll 
    131  1.8.2.1    skrll 	/* Hook the bus error handler into the ISR */
    132  1.8.2.1    skrll 	platform.intr4 = imc_bus_error;
    133      1.1  thorpej 
    134      1.4   simonb 	/*
    135      1.3    rafal 	 * Enable parity reporting on GIO/main memory transactions.
    136      1.3    rafal 	 * Disable parity checking on CPU bus transactions (as turning
    137      1.3    rafal 	 * it on seems to cause spurious bus errors), but enable parity
    138      1.4   simonb 	 * checking on CPU reads from main memory (note that this bit
    139      1.3    rafal 	 * has the opposite sense... Turning it on turns the checks off!).
    140      1.3    rafal 	 * Finally, turn on interrupt writes to the CPU from the MC.
    141      1.1  thorpej 	 */
    142  1.8.2.1    skrll 	reg = bus_space_read_4(isc.iot, isc.ioh, IMC_CPUCTRL0);
    143      1.3    rafal 	reg &= ~IMC_CPUCTRL0_NCHKMEMPAR;
    144      1.3    rafal 	reg |= (IMC_CPUCTRL0_GPR | IMC_CPUCTRL0_MPR | IMC_CPUCTRL0_INTENA);
    145  1.8.2.1    skrll 	bus_space_write_4(isc.iot, isc.ioh, IMC_CPUCTRL0, reg);
    146      1.4   simonb 
    147      1.1  thorpej 	/* Setup the MC write buffer depth */
    148  1.8.2.1    skrll 	reg = bus_space_read_4(isc.iot, isc.ioh, IMC_CPUCTRL1);
    149      1.3    rafal 	reg = (reg & ~IMC_CPUCTRL1_MCHWMSK) | 13;
    150  1.8.2.2    skrll 
    151  1.8.2.2    skrll 	/*
    152  1.8.2.2    skrll 	 * Force endianness on the onboard HPC and both slots.
    153  1.8.2.2    skrll 	 * This should be safe for Fullhouse, but leave it conditional
    154  1.8.2.2    skrll 	 * for now.
    155  1.8.2.2    skrll 	 */
    156  1.8.2.2    skrll 	if (mach_type == MACH_SGI_IP20 || (mach_type == MACH_SGI_IP22 &&
    157  1.8.2.2    skrll 	    mach_subtype == MACH_SGI_IP22_GUINESS)) {
    158  1.8.2.2    skrll 		reg |=  IMC_CPUCTRL1_HPCFX;
    159  1.8.2.2    skrll 		reg |=  IMC_CPUCTRL1_EXP0FX;
    160  1.8.2.2    skrll 		reg |=  IMC_CPUCTRL1_EXP1FX;
    161  1.8.2.2    skrll 		reg &= ~IMC_CPUCTRL1_HPCLITTLE;
    162  1.8.2.2    skrll 		reg &= ~IMC_CPUCTRL1_EXP0LITTLE;
    163  1.8.2.2    skrll 		reg &= ~IMC_CPUCTRL1_EXP1LITTLE;
    164  1.8.2.2    skrll 	}
    165  1.8.2.1    skrll 	bus_space_write_4(isc.iot, isc.ioh, IMC_CPUCTRL1, reg);
    166  1.8.2.1    skrll 
    167      1.1  thorpej 
    168      1.4   simonb 	/*
    169      1.3    rafal 	 * Set GIO64 arbitrator configuration register:
    170      1.3    rafal 	 *
    171      1.3    rafal 	 * Preserve PROM-set graphics-related bits, as they seem to depend
    172      1.4   simonb 	 * on the graphics variant present and I'm not sure how to figure
    173      1.3    rafal 	 * that out or 100% sure what the correct settings are for each.
    174      1.3    rafal 	 */
    175  1.8.2.1    skrll 	reg = bus_space_read_4(isc.iot, isc.ioh, IMC_GIO64ARB);
    176      1.3    rafal 	reg &= (IMC_GIO64ARB_GRX64 | IMC_GIO64ARB_GRXRT | IMC_GIO64ARB_GRXMST);
    177      1.1  thorpej 
    178      1.3    rafal 	/* Rest of settings are machine/board dependant */
    179  1.8.2.1    skrll 	if (mach_type == MACH_SGI_IP20)
    180  1.8.2.1    skrll 	{
    181  1.8.2.2    skrll 		reg |=   IMC_GIO64ARB_ONEGIO;
    182  1.8.2.2    skrll 	        reg |=  (IMC_GIO64ARB_EXP0RT	| IMC_GIO64ARB_EXP1RT);
    183  1.8.2.2    skrll 		reg |=  (IMC_GIO64ARB_EXP0MST	| IMC_GIO64ARB_EXP1MST);
    184  1.8.2.6    skrll 		reg &= ~(IMC_GIO64ARB_HPC64	|
    185  1.8.2.6    skrll 			 IMC_GIO64ARB_HPCEXP64	| IMC_GIO64ARB_EISA64 |
    186  1.8.2.6    skrll 			 IMC_GIO64ARB_EXP064	| IMC_GIO64ARB_EXP164 |
    187  1.8.2.6    skrll 			 IMC_GIO64ARB_EXP0PIPE	| IMC_GIO64ARB_EXP1PIPE);
    188  1.8.2.1    skrll 	}
    189  1.8.2.1    skrll 	else
    190  1.8.2.1    skrll 	{
    191  1.8.2.2    skrll 		/*
    192  1.8.2.2    skrll 		 * GIO64 invariant for all IP22 platforms: one GIO bus,
    193  1.8.2.2    skrll 		 * HPC1 @ 64
    194  1.8.2.2    skrll 		 */
    195  1.8.2.2    skrll 		reg |= IMC_GIO64ARB_ONEGIO | IMC_GIO64ARB_HPC64;
    196  1.8.2.2    skrll 
    197  1.8.2.1    skrll 		switch (mach_subtype) {
    198  1.8.2.1    skrll 		case MACH_SGI_IP22_GUINESS:
    199  1.8.2.2    skrll 			/* XXX is MST mutually exclusive? */
    200  1.8.2.2    skrll 	        	reg |=  (IMC_GIO64ARB_EXP0RT	| IMC_GIO64ARB_EXP1RT);
    201  1.8.2.2    skrll 			reg |=  (IMC_GIO64ARB_EXP0MST	| IMC_GIO64ARB_EXP1MST);
    202  1.8.2.2    skrll 
    203  1.8.2.1    skrll 			/* EISA can bus-master, is 64-bit */
    204  1.8.2.1    skrll 			reg |= (IMC_GIO64ARB_EISAMST | IMC_GIO64ARB_EISA64);
    205  1.8.2.1    skrll 			break;
    206      1.4   simonb 
    207  1.8.2.1    skrll 		case MACH_SGI_IP22_FULLHOUSE:
    208      1.4   simonb 		/*
    209      1.4   simonb 		 * All Fullhouse boards have a 64-bit HPC2 and pipelined
    210      1.4   simonb 		 * EXP0 slot.
    211      1.4   simonb 		 */
    212  1.8.2.1    skrll 			reg |= (IMC_GIO64ARB_HPCEXP64 | IMC_GIO64ARB_EXP0PIPE);
    213      1.4   simonb 
    214  1.8.2.1    skrll 			if (mach_boardrev < 2) {
    215      1.4   simonb 			/* EXP0 realtime, EXP1 can master */
    216  1.8.2.1    skrll 				reg |= (IMC_GIO64ARB_EXP0RT | IMC_GIO64ARB_EXP1MST);
    217  1.8.2.1    skrll 			} else {
    218  1.8.2.1    skrll 				/* EXP1 pipelined as well, EISA masters */
    219  1.8.2.1    skrll 				reg |= (IMC_GIO64ARB_EXP1PIPE | IMC_GIO64ARB_EISAMST);
    220  1.8.2.1    skrll 			}
    221  1.8.2.1    skrll 			break;
    222      1.4   simonb 		}
    223      1.3    rafal 	}
    224      1.4   simonb 
    225  1.8.2.1    skrll 	bus_space_write_4(isc.iot, isc.ioh, IMC_GIO64ARB, reg);
    226      1.1  thorpej 
    227  1.8.2.1    skrll 	if (isc.eisa_present) {
    228      1.1  thorpej #if notyet
    229      1.4   simonb 		memset(&iaa, 0, sizeof(iaa));
    230      1.3    rafal 
    231  1.8.2.5    skrll 		config_found_ia(self, "eisabus", (void*)&iaa, eisabusprint);
    232      1.1  thorpej #endif
    233      1.1  thorpej 	}
    234      1.1  thorpej 
    235      1.1  thorpej 	memset(&iaa, 0, sizeof(iaa));
    236      1.1  thorpej 
    237  1.8.2.3    skrll 	config_found_ia(self, "giobus", (void*)&iaa, imc_print);
    238  1.8.2.1    skrll 
    239  1.8.2.1    skrll 	imc_watchdog_enable();
    240      1.1  thorpej }
    241      1.1  thorpej 
    242      1.1  thorpej 
    243      1.1  thorpej static int
    244  1.8.2.5    skrll imc_print(void *aux, const char *name)
    245      1.1  thorpej {
    246      1.1  thorpej 	if (name)
    247  1.8.2.5    skrll 		aprint_normal("gio at %s", name);
    248      1.1  thorpej 
    249      1.1  thorpej 	return UNCONF;
    250      1.1  thorpej }
    251      1.1  thorpej 
    252  1.8.2.1    skrll static void
    253  1.8.2.1    skrll imc_bus_reset(void)
    254  1.8.2.1    skrll {
    255  1.8.2.1    skrll 	bus_space_write_4(isc.iot, isc.ioh, IMC_CPU_ERRSTAT, 0);
    256  1.8.2.1    skrll 	bus_space_write_4(isc.iot, isc.ioh, IMC_GIO_ERRSTAT, 0);
    257  1.8.2.1    skrll }
    258  1.8.2.1    skrll 
    259  1.8.2.1    skrll static void
    260  1.8.2.1    skrll imc_bus_error(u_int32_t status, u_int32_t cause, u_int32_t pc, u_int32_t ipending)
    261  1.8.2.1    skrll {
    262  1.8.2.1    skrll 	printf("bus error: cpu_stat %08x addr %08x, gio_stat %08x addr %08x\n",
    263  1.8.2.1    skrll 			bus_space_read_4(isc.iot, isc.ioh, IMC_CPU_ERRSTAT),
    264  1.8.2.1    skrll 			bus_space_read_4(isc.iot, isc.ioh, IMC_CPU_ERRADDR),
    265  1.8.2.1    skrll 			bus_space_read_4(isc.iot, isc.ioh, IMC_GIO_ERRSTAT),
    266  1.8.2.1    skrll 			bus_space_read_4(isc.iot, isc.ioh, IMC_GIO_ERRADDR) );
    267  1.8.2.1    skrll 	imc_bus_reset();
    268  1.8.2.1    skrll }
    269  1.8.2.1    skrll 
    270  1.8.2.1    skrll static void
    271  1.8.2.1    skrll imc_watchdog_reset(void)
    272  1.8.2.1    skrll {
    273  1.8.2.1    skrll 	bus_space_write_4(isc.iot, isc.ioh, IMC_WDOG, 0);
    274  1.8.2.1    skrll }
    275  1.8.2.1    skrll 
    276  1.8.2.1    skrll static void
    277  1.8.2.1    skrll imc_watchdog_disable(void)
    278  1.8.2.1    skrll {
    279  1.8.2.1    skrll 	u_int32_t reg;
    280  1.8.2.1    skrll 
    281  1.8.2.1    skrll 	bus_space_write_4(isc.iot, isc.ioh, IMC_WDOG, 0);
    282  1.8.2.1    skrll 	reg = bus_space_read_4(isc.iot, isc.ioh, IMC_CPUCTRL0);
    283  1.8.2.1    skrll 	reg &= ~(IMC_CPUCTRL0_WDOG);
    284  1.8.2.6    skrll 	bus_space_write_4(isc.iot, isc.ioh, IMC_CPUCTRL0, reg);
    285  1.8.2.1    skrll }
    286  1.8.2.1    skrll 
    287  1.8.2.1    skrll static void
    288  1.8.2.1    skrll imc_watchdog_enable(void)
    289  1.8.2.1    skrll {
    290  1.8.2.1    skrll 	u_int32_t reg;
    291  1.8.2.1    skrll 
    292  1.8.2.1    skrll 	/* enable watchdog and clear it */
    293  1.8.2.1    skrll 	reg = bus_space_read_4(isc.iot, isc.ioh, IMC_CPUCTRL0);
    294  1.8.2.1    skrll 	reg |= IMC_CPUCTRL0_WDOG;
    295  1.8.2.1    skrll 	bus_space_write_4(isc.iot, isc.ioh, IMC_CPUCTRL0, reg);
    296  1.8.2.1    skrll 	imc_watchdog_reset();
    297  1.8.2.1    skrll }
    298