hpc.c revision 1.27 1 1.27 pooka /* $NetBSD: hpc.c,v 1.27 2004/04/10 21:59:42 pooka Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*
4 1.1 thorpej * Copyright (c) 2000 Soren S. Jorvang
5 1.1 thorpej * Copyright (c) 2001 Rafal K. Boni
6 1.3 thorpej * Copyright (c) 2001 Jason R. Thorpe
7 1.1 thorpej * All rights reserved.
8 1.7 simonb *
9 1.1 thorpej * Redistribution and use in source and binary forms, with or without
10 1.1 thorpej * modification, are permitted provided that the following conditions
11 1.1 thorpej * are met:
12 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
13 1.1 thorpej * notice, this list of conditions and the following disclaimer.
14 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
16 1.1 thorpej * documentation and/or other materials provided with the distribution.
17 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
18 1.1 thorpej * must display the following acknowledgement:
19 1.1 thorpej * This product includes software developed for the
20 1.16 keihan * NetBSD Project. See http://www.NetBSD.org/ for
21 1.1 thorpej * information about NetBSD.
22 1.1 thorpej * 4. The name of the author may not be used to endorse or promote products
23 1.1 thorpej * derived from this software without specific prior written permission.
24 1.7 simonb *
25 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26 1.1 thorpej * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 1.1 thorpej * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 1.1 thorpej * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29 1.1 thorpej * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 1.1 thorpej * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 1.1 thorpej * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 1.1 thorpej * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 1.1 thorpej * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 1.1 thorpej * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 1.1 thorpej */
36 1.13 lukem
37 1.13 lukem #include <sys/cdefs.h>
38 1.27 pooka __KERNEL_RCSID(0, "$NetBSD: hpc.c,v 1.27 2004/04/10 21:59:42 pooka Exp $");
39 1.1 thorpej
40 1.1 thorpej #include <sys/param.h>
41 1.1 thorpej #include <sys/systm.h>
42 1.26 sekiya #include <sys/kernel.h>
43 1.1 thorpej #include <sys/device.h>
44 1.1 thorpej #include <sys/reboot.h>
45 1.26 sekiya #include <sys/callout.h>
46 1.1 thorpej
47 1.1 thorpej #include <machine/machtype.h>
48 1.1 thorpej
49 1.1 thorpej #include <sgimips/gio/gioreg.h>
50 1.1 thorpej #include <sgimips/gio/giovar.h>
51 1.1 thorpej
52 1.1 thorpej #include <sgimips/hpc/hpcvar.h>
53 1.1 thorpej #include <sgimips/hpc/hpcreg.h>
54 1.21 sekiya #include <sgimips/ioc/iocreg.h>
55 1.1 thorpej
56 1.1 thorpej #include "locators.h"
57 1.1 thorpej
58 1.3 thorpej const struct hpc_device {
59 1.3 thorpej const char *hd_name;
60 1.3 thorpej bus_addr_t hd_devoff;
61 1.3 thorpej bus_addr_t hd_dmaoff;
62 1.3 thorpej int hd_irq;
63 1.3 thorpej int hd_sysmask;
64 1.3 thorpej } hpc_devices[] = {
65 1.3 thorpej { "zsc",
66 1.3 thorpej /* XXX Magic numbers */
67 1.19 lonewolf HPC_PBUS_CH6_DEVREGS + IOC_SERIAL_REGS, 0,
68 1.3 thorpej 29,
69 1.17 sekiya HPCDEV_IP22 | HPCDEV_IP24 },
70 1.17 sekiya
71 1.25 sekiya /* probe order is important for IP20 zsc */
72 1.25 sekiya
73 1.24 sekiya { "zsc", /* serial 0/1 duart 1 */
74 1.24 sekiya 0x0d10, 0,
75 1.24 sekiya 5,
76 1.27 pooka HPCDEV_IP12 | HPCDEV_IP20 },
77 1.24 sekiya
78 1.25 sekiya { "zsc", /* serial 0/1 duart 0 */
79 1.25 sekiya 0x0d00, 0,
80 1.25 sekiya 5,
81 1.27 pooka HPCDEV_IP12 | HPCDEV_IP20 },
82 1.25 sekiya
83 1.17 sekiya { "pckbc",
84 1.19 lonewolf HPC_PBUS_CH6_DEVREGS + IOC_KB_REGS, 0,
85 1.17 sekiya 28,
86 1.3 thorpej HPCDEV_IP22 | HPCDEV_IP24 },
87 1.3 thorpej
88 1.3 thorpej { "sq",
89 1.3 thorpej HPC_ENET_DEVREGS, HPC_ENET_REGS,
90 1.3 thorpej 3,
91 1.3 thorpej HPCDEV_IP22 | HPCDEV_IP24 },
92 1.3 thorpej
93 1.22 sekiya { "sq",
94 1.22 sekiya HPC1_ENET_DEVREGS, HPC1_ENET_REGS,
95 1.22 sekiya 3,
96 1.27 pooka HPCDEV_IP12 | HPCDEV_IP20 },
97 1.22 sekiya
98 1.3 thorpej { "wdsc",
99 1.3 thorpej HPC_SCSI0_DEVREGS, HPC_SCSI0_REGS,
100 1.3 thorpej 1, /* XXX 1 = IRQ_LOCAL0 + 1 */
101 1.3 thorpej HPCDEV_IP22 | HPCDEV_IP24 },
102 1.3 thorpej
103 1.3 thorpej { "wdsc",
104 1.3 thorpej HPC_SCSI1_DEVREGS, HPC_SCSI1_REGS,
105 1.3 thorpej 2, /* XXX 2 = IRQ_LOCAL0 + 2 */
106 1.3 thorpej HPCDEV_IP22 },
107 1.18 sekiya
108 1.22 sekiya { "wdsc",
109 1.22 sekiya HPC1_SCSI0_DEVREGS, HPC1_SCSI0_REGS,
110 1.22 sekiya 2, /* XXX 1 = IRQ_LOCAL0 + 2 */
111 1.27 pooka HPCDEV_IP12 | HPCDEV_IP20 },
112 1.22 sekiya
113 1.18 sekiya { "dpclock",
114 1.18 sekiya HPC1_PBUS_BBRAM, 0,
115 1.18 sekiya -1,
116 1.27 pooka HPCDEV_IP12 | HPCDEV_IP20 },
117 1.3 thorpej
118 1.3 thorpej { "dsclock",
119 1.3 thorpej HPC_PBUS_BBRAM, 0,
120 1.3 thorpej -1,
121 1.3 thorpej HPCDEV_IP22 | HPCDEV_IP24 },
122 1.14 lonewolf
123 1.14 lonewolf { "haltwo",
124 1.14 lonewolf HPC_PBUS_CH0_DEVREGS, HPC_PBUS_DMAREGS,
125 1.14 lonewolf 8 + 4, /* XXX IRQ_LOCAL1 + 4 */
126 1.15 lonewolf HPCDEV_IP22 | HPCDEV_IP24 },
127 1.3 thorpej
128 1.3 thorpej { NULL,
129 1.3 thorpej 0, 0,
130 1.3 thorpej 0,
131 1.3 thorpej 0
132 1.3 thorpej }
133 1.3 thorpej };
134 1.3 thorpej
135 1.1 thorpej struct hpc_softc {
136 1.1 thorpej struct device sc_dev;
137 1.1 thorpej
138 1.1 thorpej bus_addr_t sc_base;
139 1.1 thorpej
140 1.1 thorpej bus_space_tag_t sc_ct;
141 1.1 thorpej bus_space_handle_t sc_ch;
142 1.1 thorpej };
143 1.1 thorpej
144 1.22 sekiya static struct hpc_values hpc1_values = {
145 1.23 sekiya .revision = 1,
146 1.23 sekiya .scsi0_regs = HPC1_SCSI0_REGS,
147 1.23 sekiya .scsi0_regs_size = HPC1_SCSI0_REGS_SIZE,
148 1.23 sekiya .scsi0_cbp = HPC1_SCSI0_CBP,
149 1.23 sekiya .scsi0_ndbp = HPC1_SCSI0_NDBP,
150 1.23 sekiya .scsi0_bc = HPC1_SCSI0_BC,
151 1.23 sekiya .scsi0_ctl = HPC1_SCSI0_CTL,
152 1.23 sekiya .scsi0_gio = HPC1_SCSI0_GIO,
153 1.23 sekiya .scsi0_dev = HPC1_SCSI0_DEV,
154 1.23 sekiya .scsi0_dmacfg = HPC1_SCSI0_DMACFG,
155 1.23 sekiya .scsi0_piocfg = HPC1_SCSI0_PIOCFG,
156 1.23 sekiya .scsi1_regs = HPC1_SCSI1_REGS,
157 1.23 sekiya .scsi1_regs_size = HPC1_SCSI1_REGS_SIZE,
158 1.23 sekiya .scsi1_cbp = HPC1_SCSI1_CBP,
159 1.23 sekiya .scsi1_ndbp = HPC1_SCSI1_NDBP,
160 1.23 sekiya .scsi1_bc = HPC1_SCSI1_BC,
161 1.23 sekiya .scsi1_ctl = HPC1_SCSI1_CTL,
162 1.23 sekiya .scsi1_gio = HPC1_SCSI1_GIO,
163 1.23 sekiya .scsi1_dev = HPC1_SCSI1_DEV,
164 1.23 sekiya .scsi1_dmacfg = HPC1_SCSI1_DMACFG,
165 1.23 sekiya .scsi1_piocfg = HPC1_SCSI1_PIOCFG,
166 1.23 sekiya .dmactl_dir = HPC1_DMACTL_DIR,
167 1.23 sekiya .dmactl_flush = HPC1_DMACTL_FLUSH,
168 1.23 sekiya .dmactl_active = HPC1_DMACTL_ACTIVE,
169 1.23 sekiya .dmactl_reset = HPC1_DMACTL_RESET,
170 1.23 sekiya .enet_regs = HPC1_ENET_REGS,
171 1.23 sekiya .enet_regs_size = HPC1_ENET_REGS_SIZE,
172 1.23 sekiya .enet_intdelay = HPC1_ENET_INTDELAY,
173 1.23 sekiya .enet_intdelayval = HPC1_ENET_INTDELAYVAL,
174 1.23 sekiya .enetr_cbp = HPC1_ENETR_CBP,
175 1.23 sekiya .enetr_ndbp = HPC1_ENETR_NDBP,
176 1.23 sekiya .enetr_bc = HPC1_ENETR_BC,
177 1.23 sekiya .enetr_ctl = HPC1_ENETR_CTL,
178 1.23 sekiya .enetr_ctl_active = HPC1_ENETR_CTL_ACTIVE,
179 1.23 sekiya .enetr_reset = HPC1_ENETR_RESET,
180 1.23 sekiya .enetr_dmacfg = 0,
181 1.23 sekiya .enetr_piocfg = HPC1_ENETR_PIOCFG,
182 1.23 sekiya .enetx_cbp = HPC1_ENETX_CBP,
183 1.23 sekiya .enetx_ndbp = HPC1_ENETX_NDBP,
184 1.23 sekiya .enetx_bc = HPC1_ENETX_BC,
185 1.23 sekiya .enetx_ctl = HPC1_ENETX_CTL,
186 1.23 sekiya .enetx_ctl_active = HPC1_ENETX_CTL_ACTIVE,
187 1.23 sekiya .enetx_dev = HPC1_ENETX_DEV,
188 1.23 sekiya .enetr_fifo = HPC1_ENETR_FIFO,
189 1.23 sekiya .enetr_fifo_size = HPC1_ENETR_FIFO_SIZE,
190 1.23 sekiya .enetx_fifo = HPC1_ENETX_FIFO,
191 1.23 sekiya .enetx_fifo_size = HPC1_ENETX_FIFO_SIZE,
192 1.23 sekiya .scsi0_devregs_size = HPC1_SCSI0_DEVREGS_SIZE,
193 1.23 sekiya .scsi1_devregs_size = HPC1_SCSI0_DEVREGS_SIZE,
194 1.23 sekiya .enet_devregs = HPC1_ENET_DEVREGS,
195 1.23 sekiya .enet_devregs_size = HPC1_ENET_DEVREGS_SIZE,
196 1.23 sekiya .pbus_fifo = HPC1_PBUS_FIFO,
197 1.23 sekiya .pbus_fifo_size = HPC1_PBUS_FIFO_SIZE,
198 1.23 sekiya .pbus_bbram = HPC1_PBUS_BBRAM,
199 1.22 sekiya #define MAX_SCSI_XFER (512*1024)
200 1.23 sekiya .scsi_max_xfer = MAX_SCSI_XFER,
201 1.23 sekiya .scsi_dma_segs = (MAX_SCSI_XFER / 4096),
202 1.23 sekiya .scsi_dma_segs_size = 4096,
203 1.23 sekiya .clk_freq = 100,
204 1.23 sekiya .dma_datain_cmd = (HPC1_DMACTL_ACTIVE | HPC1_DMACTL_DIR),
205 1.23 sekiya .dma_dataout_cmd = HPC1_DMACTL_ACTIVE,
206 1.23 sekiya .scsi_dmactl_flush = HPC1_DMACTL_FLUSH,
207 1.23 sekiya .scsi_dmactl_active = HPC1_DMACTL_ACTIVE,
208 1.23 sekiya .scsi_dmactl_reset = HPC1_DMACTL_RESET
209 1.22 sekiya };
210 1.22 sekiya
211 1.22 sekiya static struct hpc_values hpc3_values = {
212 1.23 sekiya .revision 3,
213 1.23 sekiya .scsi0_regs = HPC_SCSI0_REGS,
214 1.23 sekiya .scsi0_regs_size = HPC_SCSI0_REGS_SIZE,
215 1.23 sekiya .scsi0_cbp = HPC_SCSI0_CBP,
216 1.23 sekiya .scsi0_ndbp = HPC_SCSI0_NDBP,
217 1.23 sekiya .scsi0_bc = HPC_SCSI0_BC,
218 1.23 sekiya .scsi0_ctl = HPC_SCSI0_CTL,
219 1.23 sekiya .scsi0_gio = HPC_SCSI0_GIO,
220 1.23 sekiya .scsi0_dev = HPC_SCSI0_DEV,
221 1.23 sekiya .scsi0_dmacfg = HPC_SCSI0_DMACFG,
222 1.23 sekiya .scsi0_piocfg = HPC_SCSI0_PIOCFG,
223 1.23 sekiya .scsi1_regs = HPC_SCSI1_REGS,
224 1.23 sekiya .scsi1_regs_size = HPC_SCSI1_REGS_SIZE,
225 1.23 sekiya .scsi1_cbp = HPC_SCSI1_CBP,
226 1.23 sekiya .scsi1_ndbp = HPC_SCSI1_NDBP,
227 1.23 sekiya .scsi1_bc = HPC_SCSI1_BC,
228 1.23 sekiya .scsi1_ctl = HPC_SCSI1_CTL,
229 1.23 sekiya .scsi1_gio = HPC_SCSI1_GIO,
230 1.23 sekiya .scsi1_dev = HPC_SCSI1_DEV,
231 1.23 sekiya .scsi1_dmacfg = HPC_SCSI1_DMACFG,
232 1.23 sekiya .scsi1_piocfg = HPC_SCSI1_PIOCFG,
233 1.23 sekiya .dmactl_dir = HPC_DMACTL_DIR,
234 1.23 sekiya .dmactl_flush = HPC_DMACTL_FLUSH,
235 1.23 sekiya .dmactl_active = HPC_DMACTL_ACTIVE,
236 1.23 sekiya .dmactl_reset = HPC_DMACTL_RESET,
237 1.23 sekiya .enet_regs = HPC_ENET_REGS,
238 1.23 sekiya .enet_regs_size = HPC_ENET_REGS_SIZE,
239 1.23 sekiya .enet_intdelay = 0,
240 1.23 sekiya .enet_intdelayval = 0,
241 1.23 sekiya .enetr_cbp = HPC_ENETR_CBP,
242 1.23 sekiya .enetr_ndbp = HPC_ENETR_NDBP,
243 1.23 sekiya .enetr_bc = HPC_ENETR_BC,
244 1.23 sekiya .enetr_ctl = HPC_ENETR_CTL,
245 1.23 sekiya .enetr_ctl_active = ENETR_CTL_ACTIVE,
246 1.23 sekiya .enetr_reset = HPC_ENETR_RESET,
247 1.23 sekiya .enetr_dmacfg = HPC_ENETR_DMACFG,
248 1.23 sekiya .enetr_piocfg = HPC_ENETR_PIOCFG,
249 1.23 sekiya .enetx_cbp = HPC_ENETX_CBP,
250 1.23 sekiya .enetx_ndbp = HPC_ENETX_NDBP,
251 1.23 sekiya .enetx_bc = HPC_ENETX_BC,
252 1.23 sekiya .enetx_ctl = HPC_ENETX_CTL,
253 1.23 sekiya .enetx_ctl_active = ENETX_CTL_ACTIVE,
254 1.23 sekiya .enetx_dev = HPC_ENETX_DEV,
255 1.23 sekiya .enetr_fifo = HPC_ENETR_FIFO,
256 1.23 sekiya .enetr_fifo_size = HPC_ENETR_FIFO_SIZE,
257 1.23 sekiya .enetx_fifo = HPC_ENETX_FIFO,
258 1.23 sekiya .enetx_fifo_size = HPC_ENETX_FIFO_SIZE,
259 1.23 sekiya .scsi0_devregs_size = HPC_SCSI0_DEVREGS_SIZE,
260 1.23 sekiya .scsi1_devregs_size = HPC_SCSI1_DEVREGS_SIZE,
261 1.23 sekiya .enet_devregs = HPC_ENET_DEVREGS,
262 1.23 sekiya .enet_devregs_size = HPC_ENET_DEVREGS_SIZE,
263 1.23 sekiya .pbus_fifo = HPC_PBUS_FIFO,
264 1.23 sekiya .pbus_fifo_size = HPC_PBUS_FIFO_SIZE,
265 1.23 sekiya .pbus_bbram = HPC_PBUS_BBRAM,
266 1.23 sekiya .scsi_max_xfer = MAX_SCSI_XFER,
267 1.23 sekiya .scsi_dma_segs = (MAX_SCSI_XFER / 8192),
268 1.23 sekiya .scsi_dma_segs_size = 8192,
269 1.23 sekiya .clk_freq = 100,
270 1.23 sekiya .dma_datain_cmd = HPC_DMACTL_ACTIVE,
271 1.23 sekiya .dma_dataout_cmd = (HPC_DMACTL_ACTIVE | HPC_DMACTL_DIR),
272 1.23 sekiya .scsi_dmactl_flush = HPC_DMACTL_FLUSH,
273 1.23 sekiya .scsi_dmactl_active = HPC_DMACTL_ACTIVE,
274 1.23 sekiya .scsi_dmactl_reset = HPC_DMACTL_RESET
275 1.22 sekiya };
276 1.22 sekiya
277 1.22 sekiya
278 1.1 thorpej extern int mach_type; /* IPxx type */
279 1.1 thorpej extern int mach_subtype; /* subtype: eg., Guiness/Fullhouse for IP22 */
280 1.1 thorpej extern int mach_boardrev; /* machine board revision, in case it matters */
281 1.1 thorpej
282 1.2 wdk extern struct sgimips_bus_dma_tag sgimips_default_bus_dma_tag;
283 1.2 wdk
284 1.6 rafal static int powerintr_established;
285 1.6 rafal
286 1.3 thorpej int hpc_match(struct device *, struct cfdata *, void *);
287 1.3 thorpej void hpc_attach(struct device *, struct device *, void *);
288 1.3 thorpej int hpc_print(void *, const char *);
289 1.1 thorpej
290 1.3 thorpej int hpc_submatch(struct device *, struct cfdata *, void *);
291 1.3 thorpej
292 1.3 thorpej int hpc_power_intr(void *);
293 1.1 thorpej
294 1.26 sekiya #if defined(BLINK)
295 1.26 sekiya static struct callout hpc_blink_ch = CALLOUT_INITIALIZER;
296 1.26 sekiya static void hpc_blink(void *);
297 1.26 sekiya #endif
298 1.26 sekiya
299 1.11 thorpej CFATTACH_DECL(hpc, sizeof(struct hpc_softc),
300 1.11 thorpej hpc_match, hpc_attach, NULL, NULL);
301 1.1 thorpej
302 1.3 thorpej int
303 1.3 thorpej hpc_match(struct device *parent, struct cfdata *cf, void *aux)
304 1.1 thorpej {
305 1.1 thorpej struct gio_attach_args* ga = aux;
306 1.1 thorpej
307 1.1 thorpej /* Make sure it's actually there and readable */
308 1.1 thorpej if (badaddr((void*)MIPS_PHYS_TO_KSEG1(ga->ga_addr), sizeof(u_int32_t)))
309 1.1 thorpej return 0;
310 1.1 thorpej
311 1.7 simonb return 1;
312 1.1 thorpej }
313 1.1 thorpej
314 1.3 thorpej void
315 1.3 thorpej hpc_attach(struct device *parent, struct device *self, void *aux)
316 1.1 thorpej {
317 1.1 thorpej struct hpc_softc *sc = (struct hpc_softc *)self;
318 1.1 thorpej struct gio_attach_args* ga = aux;
319 1.1 thorpej struct hpc_attach_args ha;
320 1.3 thorpej const struct hpc_device *hd;
321 1.27 pooka uint32_t hpctype;
322 1.27 pooka int sysmask;
323 1.3 thorpej
324 1.3 thorpej switch (mach_type) {
325 1.27 pooka case MACH_SGI_IP12:
326 1.27 pooka hpctype = 1;
327 1.27 pooka sysmask = HPCDEV_IP12;
328 1.27 pooka break;
329 1.27 pooka
330 1.20 sekiya case MACH_SGI_IP20:
331 1.20 sekiya hpctype = 15;
332 1.20 sekiya sysmask = HPCDEV_IP20;
333 1.20 sekiya break;
334 1.23 sekiya
335 1.3 thorpej case MACH_SGI_IP22:
336 1.3 thorpej hpctype = 3;
337 1.3 thorpej if (mach_subtype == MACH_SGI_IP22_FULLHOUSE)
338 1.3 thorpej sysmask = HPCDEV_IP22;
339 1.3 thorpej else
340 1.3 thorpej sysmask = HPCDEV_IP24;
341 1.3 thorpej break;
342 1.3 thorpej
343 1.3 thorpej default:
344 1.23 sekiya panic("hpc_attach: can't handle HPC on an IP%d", mach_type);
345 1.3 thorpej };
346 1.1 thorpej
347 1.27 pooka /*
348 1.27 pooka * Verify HPC1 or HPC1.5
349 1.27 pooka *
350 1.27 pooka * For some reason the endian register isn't mapped on all
351 1.27 pooka * machines (HPC1 machines?).
352 1.27 pooka */
353 1.27 pooka if (hpctype != 3 &&
354 1.27 pooka !badaddr((void *)MIPS_PHYS_TO_KSEG1(ga->ga_addr+HPC1_BIGENDIAN),4)){
355 1.27 pooka hpctype = *(uint32_t *)
356 1.27 pooka MIPS_PHYS_TO_KSEG1(ga->ga_addr + HPC1_BIGENDIAN);
357 1.23 sekiya
358 1.23 sekiya if (((hpctype >> HPC1_REVSHIFT) & HPC1_REVMASK) == HPC1_REV15)
359 1.23 sekiya hpctype = 15;
360 1.23 sekiya else
361 1.23 sekiya hpctype = 1;
362 1.24 sekiya
363 1.24 sekiya /* force big-endian mode */
364 1.27 pooka *(uint32_t *)MIPS_PHYS_TO_KSEG1(ga->ga_addr + HPC1_BIGENDIAN)
365 1.27 pooka = hpctype & 0xe0;
366 1.23 sekiya }
367 1.23 sekiya
368 1.23 sekiya printf(": SGI HPC%d%s\n", (hpctype == 3) ? 3 : 1,
369 1.23 sekiya (hpctype == 15) ? ".5" : "");
370 1.1 thorpej
371 1.1 thorpej sc->sc_ct = 1;
372 1.1 thorpej sc->sc_ch = ga->ga_ioh;
373 1.1 thorpej
374 1.1 thorpej sc->sc_base = ga->ga_addr;
375 1.3 thorpej
376 1.3 thorpej for (hd = hpc_devices; hd->hd_name != NULL; hd++) {
377 1.5 rafal if (!(hd->hd_sysmask & sysmask))
378 1.5 rafal continue;
379 1.5 rafal
380 1.5 rafal ha.ha_name = hd->hd_name;
381 1.5 rafal ha.ha_devoff = hd->hd_devoff;
382 1.5 rafal ha.ha_dmaoff = hd->hd_dmaoff;
383 1.5 rafal ha.ha_irq = hd->hd_irq;
384 1.5 rafal
385 1.5 rafal /* XXX This is disgusting. */
386 1.5 rafal ha.ha_st = 1;
387 1.5 rafal ha.ha_sh = MIPS_PHYS_TO_KSEG1(sc->sc_base);
388 1.5 rafal ha.ha_dmat = &sgimips_default_bus_dma_tag;
389 1.22 sekiya if (hpctype == 3)
390 1.22 sekiya ha.hpc_regs = &hpc3_values;
391 1.22 sekiya else
392 1.22 sekiya ha.hpc_regs = &hpc1_values;
393 1.23 sekiya ha.hpc_regs->revision = hpctype;
394 1.5 rafal
395 1.5 rafal (void) config_found_sm(self, &ha, hpc_print, hpc_submatch);
396 1.3 thorpej }
397 1.1 thorpej
398 1.7 simonb /*
399 1.7 simonb * XXX: Only attach the powerfail interrupt once, since the
400 1.6 rafal * interrupt code doesn't let you share interrupt just yet.
401 1.6 rafal *
402 1.7 simonb * Since the powerfail interrupt is hardcoded to read from
403 1.6 rafal * a specific register anyway (XXX#2!), we don't care when
404 1.6 rafal * it gets attached, as long as it only happens once.
405 1.1 thorpej */
406 1.23 sekiya if (mach_type == MACH_SGI_IP22 && !powerintr_established) {
407 1.6 rafal cpu_intr_establish(9, IPL_NONE, hpc_power_intr, sc);
408 1.6 rafal powerintr_established++;
409 1.6 rafal }
410 1.26 sekiya
411 1.26 sekiya #if defined(BLINK)
412 1.26 sekiya if (mach_type == MACH_SGI_IP20)
413 1.26 sekiya hpc_blink(sc);
414 1.26 sekiya #endif
415 1.1 thorpej }
416 1.1 thorpej
417 1.3 thorpej int
418 1.3 thorpej hpc_submatch(struct device *parent, struct cfdata *cf, void *aux)
419 1.1 thorpej {
420 1.1 thorpej struct hpc_attach_args *ha = aux;
421 1.1 thorpej
422 1.3 thorpej if (cf->cf_loc[HPCCF_OFFSET] != HPCCF_OFFSET_DEFAULT &&
423 1.12 thorpej (bus_addr_t) cf->cf_loc[HPCCF_OFFSET] != ha->ha_devoff)
424 1.3 thorpej return (0);
425 1.1 thorpej
426 1.8 thorpej return (config_match(parent, cf, aux));
427 1.3 thorpej }
428 1.3 thorpej
429 1.3 thorpej int
430 1.3 thorpej hpc_print(void *aux, const char *pnp)
431 1.3 thorpej {
432 1.3 thorpej struct hpc_attach_args *ha = aux;
433 1.1 thorpej
434 1.3 thorpej if (pnp)
435 1.3 thorpej printf("%s at %s", ha->ha_name, pnp);
436 1.1 thorpej
437 1.3 thorpej printf(" offset 0x%lx", ha->ha_devoff);
438 1.1 thorpej
439 1.3 thorpej return (UNCONF);
440 1.1 thorpej }
441 1.1 thorpej
442 1.3 thorpej int
443 1.3 thorpej hpc_power_intr(void *arg)
444 1.1 thorpej {
445 1.1 thorpej u_int32_t pwr_reg;
446 1.1 thorpej
447 1.1 thorpej pwr_reg = *((volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(0x1fbd9850));
448 1.1 thorpej *((volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(0x1fbd9850)) = pwr_reg;
449 1.1 thorpej
450 1.1 thorpej printf("hpc_power_intr: panel reg = %08x\n", pwr_reg);
451 1.1 thorpej
452 1.1 thorpej if (pwr_reg & 2)
453 1.3 thorpej cpu_reboot(RB_HALT, NULL);
454 1.1 thorpej
455 1.1 thorpej return 1;
456 1.1 thorpej }
457 1.26 sekiya
458 1.26 sekiya #if defined(BLINK)
459 1.26 sekiya static void
460 1.26 sekiya hpc_blink(void *self)
461 1.26 sekiya {
462 1.26 sekiya struct hpc_softc *sc = (struct hpc_softc *) self;
463 1.26 sekiya register int s;
464 1.26 sekiya int value;
465 1.26 sekiya
466 1.26 sekiya s = splhigh();
467 1.26 sekiya
468 1.26 sekiya value = *(volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(HPC1_AUX_REGS);
469 1.26 sekiya value ^= HPC1_AUX_CONSLED;
470 1.26 sekiya *(volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(HPC1_AUX_REGS) = value;
471 1.26 sekiya splx(s);
472 1.26 sekiya
473 1.26 sekiya /*
474 1.26 sekiya * Blink rate is:
475 1.26 sekiya * full cycle every second if completely idle (loadav = 0)
476 1.26 sekiya * full cycle every 2 seconds if loadav = 1
477 1.26 sekiya * full cycle every 3 seconds if loadav = 2
478 1.26 sekiya * etc.
479 1.26 sekiya */
480 1.26 sekiya s = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1));
481 1.26 sekiya callout_reset(&hpc_blink_ch, s, hpc_blink, sc);
482 1.26 sekiya }
483 1.26 sekiya #endif
484 1.26 sekiya
485