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