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