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