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