Home | History | Annotate | Line # | Download | only in ioc
ioc.c revision 1.9
      1 /* $NetBSD: ioc.c,v 1.9 2011/07/01 18:53:47 dyoung Exp $	 */
      2 
      3 /*
      4  * Copyright (c) 2003 Christopher Sekiya
      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. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *          This product includes software developed for the
     18  *          NetBSD Project.  See http://www.NetBSD.org/ for
     19  *          information about NetBSD.
     20  * 4. The name of the author may not be used to endorse or promote products
     21  *    derived from this software without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33  */
     34 
     35 /*
     36  * ip20/22/24 I/O Controller (IOC)
     37  */
     38 
     39 #include <sys/cdefs.h>
     40 __KERNEL_RCSID(0, "$NetBSD: ioc.c,v 1.9 2011/07/01 18:53:47 dyoung Exp $");
     41 
     42 #include <sys/param.h>
     43 #include <sys/systm.h>
     44 #include <sys/device.h>
     45 #include <sys/callout.h>
     46 #include <sys/malloc.h>
     47 #include <sys/kernel.h>
     48 #include <sys/socket.h>
     49 #include <sys/ioctl.h>
     50 #include <sys/errno.h>
     51 #include <sys/syslog.h>
     52 
     53 #include <uvm/uvm_extern.h>
     54 
     55 #include <sys/bus.h>
     56 #include <machine/cpu.h>
     57 #include <machine/locore.h>
     58 #include <machine/autoconf.h>
     59 #include <machine/machtype.h>
     60 
     61 #include <sgimips/ioc/iocreg.h>
     62 #include <sgimips/ioc/iocvar.h>
     63 
     64 #include "locators.h"
     65 
     66 struct ioc_softc {
     67 	struct device   sc_dev;
     68 
     69 	bus_space_tag_t sc_iot;
     70 	bus_space_handle_t sc_ioh;
     71 };
     72 
     73 static int      ioc_match(struct device *, struct cfdata *, void *);
     74 static void     ioc_attach(struct device *, struct device *, void *);
     75 #if defined(notyet)
     76 static int      ioc_print(void *, const char *);
     77 static int      ioc_search(struct device *, struct cfdata *,
     78 			   const int *, void *);
     79 #endif
     80 
     81 CFATTACH_DECL(ioc, sizeof(struct ioc_softc),
     82 	      ioc_match, ioc_attach, NULL, NULL);
     83 
     84 #if defined(BLINK)
     85 static callout_t ioc_blink_ch;
     86 static void     ioc_blink(void *);
     87 #endif
     88 
     89 static int
     90 ioc_match(struct device * parent, struct cfdata * match, void *aux)
     91 {
     92 	if (mach_type == MACH_SGI_IP22)
     93 		return 1;
     94 
     95 	return 0;
     96 }
     97 
     98 static void
     99 ioc_attach(struct device * parent, struct device * self, void *aux)
    100 {
    101 	struct ioc_softc *sc = (struct ioc_softc *) self;
    102 	struct mainbus_attach_args *maa = aux;
    103 	u_int32_t       sysid;
    104 
    105 #ifdef BLINK
    106 	callout_init(&ioc_blink_ch, 0);
    107 #endif
    108 
    109 	sc->sc_iot = SGIMIPS_BUS_SPACE_HPC;
    110 
    111 	if (bus_space_map(sc->sc_iot, maa->ma_addr, 0,
    112 			  BUS_SPACE_MAP_LINEAR, &sc->sc_ioh))
    113 		panic("ioc_attach: could not allocate memory\n");
    114 
    115 	sysid = bus_space_read_4(sc->sc_iot, sc->sc_ioh, IOC_SYSID) & 0x01;
    116 
    117 	if (sysid)
    118 		mach_subtype = MACH_SGI_IP22_FULLHOUSE;
    119 	else
    120 		mach_subtype = MACH_SGI_IP22_GUINNESS;
    121 
    122 	aprint_normal(": rev %d, machine %s, board rev %d\n",
    123 		   ((sysid & IOC_SYSID_CHIPREV) >> IOC_SYSID_CHIPREV_SHIFT),
    124 		    (sysid & IOC_SYSID_SYSTYPE) ? "Indigo2 (Fullhouse)" :
    125 		    "Indy (Guinness)",
    126 		   ((sysid & IOC_SYSID_BOARDREV) >> IOC_SYSID_BOARDREV_SHIFT));
    127 
    128 	/* Reset IOC */
    129 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, IOC_RESET,
    130 			  IOC_RESET_PARALLEL | IOC_RESET_PCKBC |
    131 			  IOC_RESET_EISA | IOC_RESET_ISDN |
    132 			  IOC_RESET_LED_GREEN );
    133 
    134 	/*
    135          * Set the 10BaseT port to use UTP cable, set autoselect mode for
    136          * the ethernet interface (AUI vs. TP), set the two serial ports
    137          * to PC mode.
    138          */
    139 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, IOC_WRITE,
    140 			  IOC_WRITE_ENET_AUTO | IOC_WRITE_ENET_UTP |
    141 			  IOC_WRITE_PC_UART2 | IOC_WRITE_PC_UART1);
    142 
    143 /* XXX: the firmware should have taken care of this already */
    144 #if 0
    145 	if (mach_subtype == MACH_SGI_IP22_GUINNESS) {
    146 		bus_space_write_4(sc->sc_iot, sc->sc_ioh, IOC_GCSEL, 0xff);
    147 		bus_space_write_4(sc->sc_iot, sc->sc_ioh, IOC_GCREG, 0xff);
    148 	}
    149 #endif
    150 
    151 #if defined(BLINK)
    152 	ioc_blink(sc);
    153 #endif
    154 
    155 #if defined(notyet)
    156 	/*
    157 	 * pckbc, zstty, and lpt should attach under the IOC.  This begs the
    158 	 * question of how we sort things out with ip20, which has no IOC.
    159 	 * For now, we pretend that everything attaches at HPC and ignore
    160 	 * the IOC.
    161 	 */
    162 
    163 	config_search_ia(ioc_search, self, "ioc", NULL);
    164 #endif
    165 }
    166 
    167 #if defined(notyet)
    168 static int
    169 ioc_print(void *aux, const char *pnp)
    170 {
    171 	struct ioc_attach_args *iaa = aux;
    172 
    173 	if (pnp != 0)
    174 		return QUIET;
    175 
    176 	if (iaa->iaa_offset != IOCCF_OFFSET_DEFAULT)
    177 		aprint_normal(" offset 0x%lx", iaa->iaa_offset);
    178 	if (iaa->iaa_intr != IOCCF_INTR_DEFAULT)
    179 		aprint_normal(" intr %d", iaa->iaa_intr);
    180 
    181 	return UNCONF;
    182 }
    183 
    184 static int
    185 ioc_search(struct device * parent, struct cfdata * cf,
    186 	   const int *ldesc, void *aux)
    187 {
    188 	struct ioc_softc *sc = (struct ioc_softc *) parent;
    189 	struct ioc_attach_args iaa;
    190 	int             tryagain;
    191 
    192 	do {
    193 		iaa.iaa_offset = cf->cf_loc[IOCCF_OFFSET];
    194 		iaa.iaa_intr = cf->cf_loc[IOCCF_INTR];
    195 		iaa.iaa_st = SGIMIPS_BUS_SPACE_HPC;
    196 		iaa.iaa_sh = sc->sc_ioh;	/* XXX */
    197 
    198 		tryagain = 0;
    199 		if (config_match(parent, cf, &iaa) > 0) {
    200 			config_attach(parent, cf, &iaa, ioc_print);
    201 			tryagain = (cf->cf_fstate == FSTATE_STAR);
    202 		}
    203 	} while (tryagain);
    204 
    205 	return 0;
    206 }
    207 #endif
    208 
    209 #if defined(BLINK)
    210 static void
    211 ioc_blink(void *self)
    212 {
    213 	struct ioc_softc *sc = (struct ioc_softc *) self;
    214 	register int    s;
    215 	int             value;
    216 
    217 	s = splhigh();
    218 
    219 	/* This is a bit odd.  To strobe the green LED, we have to toggle the
    220 	   red control bit. */
    221 
    222 	value = bus_space_read_4(sc->sc_iot, sc->sc_ioh, IOC_RESET) & 0xff;
    223 	value ^= IOC_RESET_LED_RED;
    224 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, IOC_RESET, value);
    225 	splx(s);
    226 	/*
    227 	 * Blink rate is:
    228 	 *      full cycle every second if completely idle (loadav = 0)
    229 	 *      full cycle every 2 seconds if loadav = 1
    230 	 *      full cycle every 3 seconds if loadav = 2
    231 	 * etc.
    232 	 */
    233 	s = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1));
    234 	callout_reset(&ioc_blink_ch, s, ioc_blink, sc);
    235 
    236 }
    237 #endif
    238