Home | History | Annotate | Line # | Download | only in ioc
      1 /* $NetBSD: ioc.c,v 1.15 2026/04/30 03:12:39 adrian 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.15 2026/04/30 03:12:39 adrian 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/kernel.h>
     47 #include <sys/socket.h>
     48 #include <sys/ioctl.h>
     49 #include <sys/errno.h>
     50 #include <sys/syslog.h>
     51 
     52 #include <uvm/uvm_extern.h>
     53 
     54 #include <sys/bus.h>
     55 #include <machine/cpu.h>
     56 #include <machine/locore.h>
     57 #include <machine/autoconf.h>
     58 #include <machine/machtype.h>
     59 
     60 #include <sgimips/ioc/iocreg.h>
     61 #include <sgimips/ioc/iocvar.h>
     62 
     63 #include "locators.h"
     64 
     65 struct ioc_softc {
     66 	bus_space_tag_t sc_iot;
     67 	bus_space_handle_t sc_ioh;
     68 };
     69 
     70 static int      ioc_match(device_t, cfdata_t, void *);
     71 static void     ioc_attach(device_t, device_t, void *);
     72 #if defined(notyet)
     73 static int      ioc_print(void *, const char *);
     74 static int      ioc_search(device_t, cfdata_t, const int *, void *);
     75 #endif
     76 
     77 CFATTACH_DECL_NEW(ioc, sizeof(struct ioc_softc),
     78 	      ioc_match, ioc_attach, NULL, NULL);
     79 
     80 #if defined(BLINK)
     81 static callout_t ioc_blink_ch;
     82 static void     ioc_blink(void *);
     83 #endif
     84 
     85 static int
     86 ioc_match(device_t parent, cfdata_t match, void *aux)
     87 {
     88 	if (mach_type == MACH_SGI_IP22)
     89 		return 1;
     90 
     91 	return 0;
     92 }
     93 
     94 static void
     95 ioc_attach(device_t parent, device_t self, void *aux)
     96 {
     97 	struct ioc_softc *sc = device_private(self);
     98 	struct mainbus_attach_args *maa = aux;
     99 	u_int32_t       sysid;
    100 
    101 #ifdef BLINK
    102 	callout_init(&ioc_blink_ch, 0);
    103 #endif
    104 
    105 	sc->sc_iot = normal_memt;
    106 
    107 	if (bus_space_map(sc->sc_iot, maa->ma_addr, 0x100,
    108 			  BUS_SPACE_MAP_LINEAR, &sc->sc_ioh))
    109 		panic("ioc_attach: could not allocate memory\n");
    110 
    111 	sysid = bus_space_read_4(sc->sc_iot, sc->sc_ioh, IOC_SYSID) & 0x01;
    112 
    113 	/*
    114 	 * NOTE: this has to happen before mach_subtype is used -
    115 	 * including for dev/int.c.  So it's initialised earlier
    116 	 * in sgimips/machdep.c for early boot.
    117 	 */
    118 	if (sysid)
    119 		mach_subtype = MACH_SGI_IP22_FULLHOUSE;
    120 	else
    121 		mach_subtype = MACH_SGI_IP22_GUINNESS;
    122 
    123 	aprint_normal(": rev %d, machine %s, board rev %d\n",
    124 		   ((sysid & IOC_SYSID_CHIPREV) >> IOC_SYSID_CHIPREV_SHIFT),
    125 		    (sysid & IOC_SYSID_SYSTYPE) ? "Indigo2 (Fullhouse)" :
    126 		    "Indy (Guinness)",
    127 		   ((sysid & IOC_SYSID_BOARDREV) >> IOC_SYSID_BOARDREV_SHIFT));
    128 
    129 	/* Reset IOC */
    130 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, IOC_RESET,
    131 			  IOC_RESET_PARALLEL | IOC_RESET_PCKBC |
    132 			  IOC_RESET_EISA | IOC_RESET_ISDN |
    133 			  IOC_RESET_LED_GREEN );
    134 
    135 	/*
    136          * Set the 10BaseT port to use UTP cable, set autoselect mode for
    137          * the ethernet interface (AUI vs. TP), set the two serial ports
    138          * to PC mode.
    139          */
    140 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, IOC_WRITE,
    141 			  IOC_WRITE_ENET_AUTO | IOC_WRITE_ENET_UTP |
    142 			  IOC_WRITE_PC_UART2 | IOC_WRITE_PC_UART1);
    143 
    144 /* XXX: the firmware should have taken care of this already */
    145 #if 0
    146 	if (mach_subtype == MACH_SGI_IP22_GUINNESS) {
    147 		bus_space_write_4(sc->sc_iot, sc->sc_ioh, IOC_GCSEL, 0xff);
    148 		bus_space_write_4(sc->sc_iot, sc->sc_ioh, IOC_GCREG, 0xff);
    149 	}
    150 #endif
    151 
    152 #if defined(BLINK)
    153 	ioc_blink(sc);
    154 #endif
    155 
    156 #if defined(notyet)
    157 	/*
    158 	 * pckbc, zstty, and lpt should attach under the IOC.  This begs the
    159 	 * question of how we sort things out with ip20, which has no IOC.
    160 	 * For now, we pretend that everything attaches at HPC and ignore
    161 	 * the IOC.
    162 	 */
    163 
    164 	config_search(self, NULL,
    165 	    CFARGS(.search = ioc_search));
    166 #endif
    167 }
    168 
    169 #if defined(notyet)
    170 static int
    171 ioc_print(void *aux, const char *pnp)
    172 {
    173 	struct ioc_attach_args *iaa = aux;
    174 
    175 	if (pnp != 0)
    176 		return QUIET;
    177 
    178 	if (iaa->iaa_offset != IOCCF_OFFSET_DEFAULT)
    179 		aprint_normal(" offset 0x%lx", iaa->iaa_offset);
    180 	if (iaa->iaa_intr != IOCCF_INTR_DEFAULT)
    181 		aprint_normal(" intr %d", iaa->iaa_intr);
    182 
    183 	return UNCONF;
    184 }
    185 
    186 static int
    187 ioc_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
    188 {
    189 	struct ioc_softc *sc = device_private(parent);
    190 	struct ioc_attach_args iaa;
    191 	int             tryagain;
    192 
    193 	do {
    194 		iaa.iaa_offset = cf->cf_loc[IOCCF_OFFSET];
    195 		iaa.iaa_intr = cf->cf_loc[IOCCF_INTR];
    196 		iaa.iaa_st = normal_memt;
    197 		iaa.iaa_sh = sc->sc_ioh;	/* XXX */
    198 
    199 		tryagain = 0;
    200 		if (config_probe(parent, cf, &iaa)) {
    201 			config_attach(parent, cf, &iaa, ioc_print, CFARGS_NONE);
    202 			tryagain = (cf->cf_fstate == FSTATE_STAR);
    203 		}
    204 	} while (tryagain);
    205 
    206 	return 0;
    207 }
    208 #endif
    209 
    210 #if defined(BLINK)
    211 static void
    212 ioc_blink(void *self)
    213 {
    214 	struct ioc_softc *sc = device_private(self);
    215 	register int    s;
    216 	int             value;
    217 
    218 	s = splhigh();
    219 
    220 	/* This is a bit odd.  To strobe the green LED, we have to toggle the
    221 	   red control bit. */
    222 
    223 	value = bus_space_read_4(sc->sc_iot, sc->sc_ioh, IOC_RESET) & 0xff;
    224 	value ^= IOC_RESET_LED_RED;
    225 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, IOC_RESET, value);
    226 	splx(s);
    227 	/*
    228 	 * Blink rate is:
    229 	 *      full cycle every second if completely idle (loadav = 0)
    230 	 *      full cycle every 2 seconds if loadav = 1
    231 	 *      full cycle every 3 seconds if loadav = 2
    232 	 * etc.
    233 	 */
    234 	s = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1));
    235 	callout_reset(&ioc_blink_ch, s, ioc_blink, sc);
    236 
    237 }
    238 #endif
    239