hpc.c revision 1.49 1 1.49 rumble /* $NetBSD: hpc.c,v 1.49 2006/12/22 23:36:42 rumble 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.49 rumble __KERNEL_RCSID(0, "$NetBSD: hpc.c,v 1.49 2006/12/22 23:36:42 rumble 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.39 rumble #define _SGIMIPS_BUS_DMA_PRIVATE
48 1.39 rumble #include <machine/bus.h>
49 1.1 thorpej #include <machine/machtype.h>
50 1.1 thorpej
51 1.1 thorpej #include <sgimips/gio/gioreg.h>
52 1.1 thorpej #include <sgimips/gio/giovar.h>
53 1.1 thorpej
54 1.1 thorpej #include <sgimips/hpc/hpcvar.h>
55 1.1 thorpej #include <sgimips/hpc/hpcreg.h>
56 1.21 sekiya #include <sgimips/ioc/iocreg.h>
57 1.1 thorpej
58 1.42 rumble #include <dev/ic/smc93cx6var.h>
59 1.42 rumble
60 1.1 thorpej #include "locators.h"
61 1.1 thorpej
62 1.45 rumble struct hpc_device {
63 1.3 thorpej const char *hd_name;
64 1.29 rumble bus_addr_t hd_base;
65 1.3 thorpej bus_addr_t hd_devoff;
66 1.3 thorpej bus_addr_t hd_dmaoff;
67 1.3 thorpej int hd_irq;
68 1.3 thorpej int hd_sysmask;
69 1.45 rumble };
70 1.17 sekiya
71 1.45 rumble static const struct hpc_device hpc1_devices[] = {
72 1.25 sekiya /* probe order is important for IP20 zsc */
73 1.25 sekiya
74 1.45 rumble { "zsc", /* Personal Iris/Indigo serial 0/1 duart 1 */
75 1.29 rumble HPC_BASE_ADDRESS_0,
76 1.24 sekiya 0x0d10, 0,
77 1.24 sekiya 5,
78 1.27 pooka HPCDEV_IP12 | HPCDEV_IP20 },
79 1.24 sekiya
80 1.45 rumble { "zsc", /* Personal Iris/Indigo kbd/ms duart 0 */
81 1.29 rumble HPC_BASE_ADDRESS_0,
82 1.25 sekiya 0x0d00, 0,
83 1.25 sekiya 5,
84 1.27 pooka HPCDEV_IP12 | HPCDEV_IP20 },
85 1.25 sekiya
86 1.45 rumble { "sq", /* Personal Iris/Indigo onboard ethernet */
87 1.29 rumble HPC_BASE_ADDRESS_0,
88 1.22 sekiya HPC1_ENET_DEVREGS, HPC1_ENET_REGS,
89 1.22 sekiya 3,
90 1.27 pooka HPCDEV_IP12 | HPCDEV_IP20 },
91 1.45 rumble
92 1.45 rumble { "sq", /* E++ GIO adapter slot 0 (Indigo) */
93 1.29 rumble HPC_BASE_ADDRESS_1,
94 1.29 rumble HPC1_ENET_DEVREGS, HPC1_ENET_REGS,
95 1.29 rumble 6,
96 1.29 rumble HPCDEV_IP12 | HPCDEV_IP20 },
97 1.29 rumble
98 1.45 rumble { "sq", /* E++ GIO adapter slot 0 (Indy) */
99 1.29 rumble HPC_BASE_ADDRESS_1,
100 1.29 rumble HPC1_ENET_DEVREGS, HPC1_ENET_REGS,
101 1.29 rumble 22,
102 1.29 rumble HPCDEV_IP24 },
103 1.29 rumble
104 1.45 rumble { "sq", /* E++ GIO adapter slot 1 (Indigo) */
105 1.29 rumble HPC_BASE_ADDRESS_2,
106 1.29 rumble HPC1_ENET_DEVREGS, HPC1_ENET_REGS,
107 1.44 rumble 6,
108 1.29 rumble HPCDEV_IP12 | HPCDEV_IP20 },
109 1.29 rumble
110 1.45 rumble { "sq", /* E++ GIO adapter slot 1 (Indy/Challenge S) */
111 1.29 rumble HPC_BASE_ADDRESS_2,
112 1.29 rumble HPC1_ENET_DEVREGS, HPC1_ENET_REGS,
113 1.29 rumble 23,
114 1.29 rumble HPCDEV_IP24 },
115 1.29 rumble
116 1.45 rumble { "wdsc", /* Personal Iris/Indigo onboard SCSI */
117 1.45 rumble HPC_BASE_ADDRESS_0,
118 1.45 rumble HPC1_SCSI0_DEVREGS, HPC1_SCSI0_REGS,
119 1.45 rumble 2, /* XXX 1 = IRQ_LOCAL0 + 2 */
120 1.45 rumble HPCDEV_IP12 | HPCDEV_IP20 },
121 1.45 rumble
122 1.45 rumble { "dpclock", /* Personal Iris/Indigo clock */
123 1.45 rumble HPC_BASE_ADDRESS_0,
124 1.45 rumble HPC1_PBUS_BBRAM, 0,
125 1.45 rumble -1,
126 1.45 rumble HPCDEV_IP12 | HPCDEV_IP20 },
127 1.45 rumble
128 1.45 rumble { NULL,
129 1.45 rumble 0,
130 1.45 rumble 0, 0,
131 1.45 rumble 0,
132 1.45 rumble 0
133 1.45 rumble }
134 1.45 rumble };
135 1.45 rumble
136 1.45 rumble static const struct hpc_device hpc3_devices[] = {
137 1.45 rumble { "zsc", /* serial 0/1 duart 0 */
138 1.45 rumble HPC_BASE_ADDRESS_0,
139 1.45 rumble /* XXX Magic numbers */
140 1.45 rumble HPC3_PBUS_CH6_DEVREGS + IOC_SERIAL_REGS, 0,
141 1.45 rumble 29,
142 1.45 rumble HPCDEV_IP22 | HPCDEV_IP24 },
143 1.45 rumble
144 1.45 rumble { "pckbc", /* Indigo2/Indy ps2 keyboard/mouse controller */
145 1.45 rumble HPC_BASE_ADDRESS_0,
146 1.45 rumble HPC3_PBUS_CH6_DEVREGS + IOC_KB_REGS, 0,
147 1.45 rumble 28,
148 1.45 rumble HPCDEV_IP22 | HPCDEV_IP24 },
149 1.45 rumble
150 1.45 rumble { "sq", /* Indigo2/Indy/Challenge S/Challenge M onboard enet */
151 1.45 rumble HPC_BASE_ADDRESS_0,
152 1.45 rumble HPC3_ENET_DEVREGS, HPC3_ENET_REGS,
153 1.45 rumble 3,
154 1.45 rumble HPCDEV_IP22 | HPCDEV_IP24 },
155 1.45 rumble
156 1.45 rumble { "sq", /* Challenge S IOPLUS secondary ethernet */
157 1.45 rumble HPC_BASE_ADDRESS_1,
158 1.45 rumble HPC3_ENET_DEVREGS, HPC3_ENET_REGS,
159 1.45 rumble 22,
160 1.45 rumble HPCDEV_IP24 },
161 1.45 rumble
162 1.45 rumble { "wdsc", /* Indigo2/Indy/Challenge S/Challenge M onboard SCSI */
163 1.29 rumble HPC_BASE_ADDRESS_0,
164 1.31 rumble HPC3_SCSI0_DEVREGS, HPC3_SCSI0_REGS,
165 1.3 thorpej 1, /* XXX 1 = IRQ_LOCAL0 + 1 */
166 1.3 thorpej HPCDEV_IP22 | HPCDEV_IP24 },
167 1.3 thorpej
168 1.45 rumble { "wdsc", /* Indigo2/Challenge M secondary onboard SCSI */
169 1.29 rumble HPC_BASE_ADDRESS_0,
170 1.31 rumble HPC3_SCSI1_DEVREGS, HPC3_SCSI1_REGS,
171 1.3 thorpej 2, /* XXX 2 = IRQ_LOCAL0 + 2 */
172 1.3 thorpej HPCDEV_IP22 },
173 1.18 sekiya
174 1.45 rumble { "dsclock", /* Indigo2/Indy/Challenge S/Challenge M clock */
175 1.29 rumble HPC_BASE_ADDRESS_0,
176 1.31 rumble HPC3_PBUS_BBRAM, 0,
177 1.3 thorpej -1,
178 1.3 thorpej HPCDEV_IP22 | HPCDEV_IP24 },
179 1.14 lonewolf
180 1.45 rumble { "haltwo", /* Indigo2/Indy onboard audio */
181 1.29 rumble HPC_BASE_ADDRESS_0,
182 1.31 rumble HPC3_PBUS_CH0_DEVREGS, HPC3_PBUS_DMAREGS,
183 1.14 lonewolf 8 + 4, /* XXX IRQ_LOCAL1 + 4 */
184 1.15 lonewolf HPCDEV_IP22 | HPCDEV_IP24 },
185 1.3 thorpej
186 1.45 rumble { "pi1ppc", /* Indigo2/Indy/Challenge S/Challenge M onboard pport */
187 1.35 kurahone HPC_BASE_ADDRESS_0,
188 1.35 kurahone HPC3_PBUS_CH6_DEVREGS + IOC_PLP_REGS, 0,
189 1.35 kurahone -1,
190 1.35 kurahone HPCDEV_IP22 | HPCDEV_IP24 },
191 1.35 kurahone
192 1.3 thorpej { NULL,
193 1.29 rumble 0,
194 1.3 thorpej 0, 0,
195 1.3 thorpej 0,
196 1.3 thorpej 0
197 1.3 thorpej }
198 1.3 thorpej };
199 1.3 thorpej
200 1.1 thorpej struct hpc_softc {
201 1.1 thorpej struct device sc_dev;
202 1.1 thorpej
203 1.1 thorpej bus_addr_t sc_base;
204 1.1 thorpej
205 1.1 thorpej bus_space_tag_t sc_ct;
206 1.1 thorpej bus_space_handle_t sc_ch;
207 1.1 thorpej };
208 1.1 thorpej
209 1.22 sekiya static struct hpc_values hpc1_values = {
210 1.23 sekiya .revision = 1,
211 1.23 sekiya .scsi0_regs = HPC1_SCSI0_REGS,
212 1.23 sekiya .scsi0_regs_size = HPC1_SCSI0_REGS_SIZE,
213 1.23 sekiya .scsi0_cbp = HPC1_SCSI0_CBP,
214 1.23 sekiya .scsi0_ndbp = HPC1_SCSI0_NDBP,
215 1.23 sekiya .scsi0_bc = HPC1_SCSI0_BC,
216 1.23 sekiya .scsi0_ctl = HPC1_SCSI0_CTL,
217 1.23 sekiya .scsi0_gio = HPC1_SCSI0_GIO,
218 1.23 sekiya .scsi0_dev = HPC1_SCSI0_DEV,
219 1.23 sekiya .scsi0_dmacfg = HPC1_SCSI0_DMACFG,
220 1.23 sekiya .scsi0_piocfg = HPC1_SCSI0_PIOCFG,
221 1.48 rumble .scsi1_regs = 0,
222 1.48 rumble .scsi1_regs_size = 0,
223 1.48 rumble .scsi1_cbp = 0,
224 1.48 rumble .scsi1_ndbp = 0,
225 1.48 rumble .scsi1_bc = 0,
226 1.48 rumble .scsi1_ctl = 0,
227 1.48 rumble .scsi1_gio = 0,
228 1.48 rumble .scsi1_dev = 0,
229 1.48 rumble .scsi1_dmacfg = 0,
230 1.48 rumble .scsi1_piocfg = 0,
231 1.23 sekiya .enet_regs = HPC1_ENET_REGS,
232 1.23 sekiya .enet_regs_size = HPC1_ENET_REGS_SIZE,
233 1.23 sekiya .enet_intdelay = HPC1_ENET_INTDELAY,
234 1.30 rumble .enet_intdelayval = HPC1_ENET_INTDELAY_OFF,
235 1.23 sekiya .enetr_cbp = HPC1_ENETR_CBP,
236 1.23 sekiya .enetr_ndbp = HPC1_ENETR_NDBP,
237 1.23 sekiya .enetr_bc = HPC1_ENETR_BC,
238 1.23 sekiya .enetr_ctl = HPC1_ENETR_CTL,
239 1.23 sekiya .enetr_ctl_active = HPC1_ENETR_CTL_ACTIVE,
240 1.23 sekiya .enetr_reset = HPC1_ENETR_RESET,
241 1.23 sekiya .enetr_dmacfg = 0,
242 1.30 rumble .enetr_piocfg = 0,
243 1.23 sekiya .enetx_cbp = HPC1_ENETX_CBP,
244 1.23 sekiya .enetx_ndbp = HPC1_ENETX_NDBP,
245 1.23 sekiya .enetx_bc = HPC1_ENETX_BC,
246 1.23 sekiya .enetx_ctl = HPC1_ENETX_CTL,
247 1.23 sekiya .enetx_ctl_active = HPC1_ENETX_CTL_ACTIVE,
248 1.30 rumble .enetx_dev = 0,
249 1.23 sekiya .enetr_fifo = HPC1_ENETR_FIFO,
250 1.23 sekiya .enetr_fifo_size = HPC1_ENETR_FIFO_SIZE,
251 1.23 sekiya .enetx_fifo = HPC1_ENETX_FIFO,
252 1.23 sekiya .enetx_fifo_size = HPC1_ENETX_FIFO_SIZE,
253 1.23 sekiya .scsi0_devregs_size = HPC1_SCSI0_DEVREGS_SIZE,
254 1.48 rumble .scsi1_devregs_size = 0,
255 1.23 sekiya .enet_devregs = HPC1_ENET_DEVREGS,
256 1.23 sekiya .enet_devregs_size = HPC1_ENET_DEVREGS_SIZE,
257 1.30 rumble .pbus_fifo = 0,
258 1.30 rumble .pbus_fifo_size = 0,
259 1.30 rumble .pbus_bbram = 0,
260 1.22 sekiya #define MAX_SCSI_XFER (512*1024)
261 1.23 sekiya .scsi_max_xfer = MAX_SCSI_XFER,
262 1.48 rumble .scsi_dma_segs = (MAX_SCSI_XFER / 4096),
263 1.23 sekiya .scsi_dma_segs_size = 4096,
264 1.49 rumble .scsi_dma_datain_cmd = (HPC1_SCSI_DMACTL_ACTIVE | HPC1_SCSI_DMACTL_DIR),
265 1.49 rumble .scsi_dma_dataout_cmd = HPC1_SCSI_DMACTL_ACTIVE,
266 1.48 rumble .scsi_dmactl_flush = HPC1_SCSI_DMACTL_FLUSH,
267 1.48 rumble .scsi_dmactl_active = HPC1_SCSI_DMACTL_ACTIVE,
268 1.48 rumble .scsi_dmactl_reset = HPC1_SCSI_DMACTL_RESET
269 1.22 sekiya };
270 1.22 sekiya
271 1.22 sekiya static struct hpc_values hpc3_values = {
272 1.37 sekiya .revision = 3,
273 1.31 rumble .scsi0_regs = HPC3_SCSI0_REGS,
274 1.31 rumble .scsi0_regs_size = HPC3_SCSI0_REGS_SIZE,
275 1.31 rumble .scsi0_cbp = HPC3_SCSI0_CBP,
276 1.31 rumble .scsi0_ndbp = HPC3_SCSI0_NDBP,
277 1.31 rumble .scsi0_bc = HPC3_SCSI0_BC,
278 1.31 rumble .scsi0_ctl = HPC3_SCSI0_CTL,
279 1.31 rumble .scsi0_gio = HPC3_SCSI0_GIO,
280 1.31 rumble .scsi0_dev = HPC3_SCSI0_DEV,
281 1.31 rumble .scsi0_dmacfg = HPC3_SCSI0_DMACFG,
282 1.31 rumble .scsi0_piocfg = HPC3_SCSI0_PIOCFG,
283 1.31 rumble .scsi1_regs = HPC3_SCSI1_REGS,
284 1.31 rumble .scsi1_regs_size = HPC3_SCSI1_REGS_SIZE,
285 1.31 rumble .scsi1_cbp = HPC3_SCSI1_CBP,
286 1.31 rumble .scsi1_ndbp = HPC3_SCSI1_NDBP,
287 1.31 rumble .scsi1_bc = HPC3_SCSI1_BC,
288 1.31 rumble .scsi1_ctl = HPC3_SCSI1_CTL,
289 1.31 rumble .scsi1_gio = HPC3_SCSI1_GIO,
290 1.31 rumble .scsi1_dev = HPC3_SCSI1_DEV,
291 1.31 rumble .scsi1_dmacfg = HPC3_SCSI1_DMACFG,
292 1.31 rumble .scsi1_piocfg = HPC3_SCSI1_PIOCFG,
293 1.31 rumble .enet_regs = HPC3_ENET_REGS,
294 1.31 rumble .enet_regs_size = HPC3_ENET_REGS_SIZE,
295 1.23 sekiya .enet_intdelay = 0,
296 1.23 sekiya .enet_intdelayval = 0,
297 1.31 rumble .enetr_cbp = HPC3_ENETR_CBP,
298 1.31 rumble .enetr_ndbp = HPC3_ENETR_NDBP,
299 1.31 rumble .enetr_bc = HPC3_ENETR_BC,
300 1.31 rumble .enetr_ctl = HPC3_ENETR_CTL,
301 1.31 rumble .enetr_ctl_active = HPC3_ENETR_CTL_ACTIVE,
302 1.31 rumble .enetr_reset = HPC3_ENETR_RESET,
303 1.31 rumble .enetr_dmacfg = HPC3_ENETR_DMACFG,
304 1.31 rumble .enetr_piocfg = HPC3_ENETR_PIOCFG,
305 1.31 rumble .enetx_cbp = HPC3_ENETX_CBP,
306 1.31 rumble .enetx_ndbp = HPC3_ENETX_NDBP,
307 1.31 rumble .enetx_bc = HPC3_ENETX_BC,
308 1.31 rumble .enetx_ctl = HPC3_ENETX_CTL,
309 1.31 rumble .enetx_ctl_active = HPC3_ENETX_CTL_ACTIVE,
310 1.31 rumble .enetx_dev = HPC3_ENETX_DEV,
311 1.31 rumble .enetr_fifo = HPC3_ENETR_FIFO,
312 1.31 rumble .enetr_fifo_size = HPC3_ENETR_FIFO_SIZE,
313 1.31 rumble .enetx_fifo = HPC3_ENETX_FIFO,
314 1.31 rumble .enetx_fifo_size = HPC3_ENETX_FIFO_SIZE,
315 1.31 rumble .scsi0_devregs_size = HPC3_SCSI0_DEVREGS_SIZE,
316 1.31 rumble .scsi1_devregs_size = HPC3_SCSI1_DEVREGS_SIZE,
317 1.31 rumble .enet_devregs = HPC3_ENET_DEVREGS,
318 1.31 rumble .enet_devregs_size = HPC3_ENET_DEVREGS_SIZE,
319 1.31 rumble .pbus_fifo = HPC3_PBUS_FIFO,
320 1.31 rumble .pbus_fifo_size = HPC3_PBUS_FIFO_SIZE,
321 1.31 rumble .pbus_bbram = HPC3_PBUS_BBRAM,
322 1.23 sekiya .scsi_max_xfer = MAX_SCSI_XFER,
323 1.48 rumble .scsi_dma_segs = (MAX_SCSI_XFER / 8192),
324 1.23 sekiya .scsi_dma_segs_size = 8192,
325 1.49 rumble .scsi_dma_datain_cmd = HPC3_SCSI_DMACTL_ACTIVE,
326 1.49 rumble .scsi_dma_dataout_cmd =(HPC3_SCSI_DMACTL_ACTIVE | HPC3_SCSI_DMACTL_DIR),
327 1.48 rumble .scsi_dmactl_flush = HPC3_SCSI_DMACTL_FLUSH,
328 1.48 rumble .scsi_dmactl_active = HPC3_SCSI_DMACTL_ACTIVE,
329 1.48 rumble .scsi_dmactl_reset = HPC3_SCSI_DMACTL_RESET
330 1.22 sekiya };
331 1.22 sekiya
332 1.22 sekiya
333 1.6 rafal static int powerintr_established;
334 1.6 rafal
335 1.41 rumble static int hpc_match(struct device *, struct cfdata *, void *);
336 1.41 rumble static void hpc_attach(struct device *, struct device *, void *);
337 1.41 rumble static int hpc_print(void *, const char *);
338 1.1 thorpej
339 1.41 rumble static int hpc_revision(struct hpc_softc *, struct gio_attach_args *);
340 1.29 rumble
341 1.41 rumble static int hpc_submatch(struct device *, struct cfdata *,
342 1.33 drochner const int *, void *);
343 1.3 thorpej
344 1.41 rumble static int hpc_power_intr(void *);
345 1.1 thorpej
346 1.26 sekiya #if defined(BLINK)
347 1.26 sekiya static struct callout hpc_blink_ch = CALLOUT_INITIALIZER;
348 1.26 sekiya static void hpc_blink(void *);
349 1.26 sekiya #endif
350 1.26 sekiya
351 1.42 rumble static int hpc_read_eeprom(int, bus_space_tag_t, bus_space_handle_t,
352 1.42 rumble uint8_t *, size_t);
353 1.42 rumble
354 1.11 thorpej CFATTACH_DECL(hpc, sizeof(struct hpc_softc),
355 1.11 thorpej hpc_match, hpc_attach, NULL, NULL);
356 1.1 thorpej
357 1.41 rumble static int
358 1.3 thorpej hpc_match(struct device *parent, struct cfdata *cf, void *aux)
359 1.1 thorpej {
360 1.1 thorpej struct gio_attach_args* ga = aux;
361 1.1 thorpej
362 1.1 thorpej /* Make sure it's actually there and readable */
363 1.1 thorpej if (badaddr((void*)MIPS_PHYS_TO_KSEG1(ga->ga_addr), sizeof(u_int32_t)))
364 1.1 thorpej return 0;
365 1.1 thorpej
366 1.7 simonb return 1;
367 1.1 thorpej }
368 1.1 thorpej
369 1.41 rumble static void
370 1.3 thorpej hpc_attach(struct device *parent, struct device *self, void *aux)
371 1.1 thorpej {
372 1.1 thorpej struct hpc_softc *sc = (struct hpc_softc *)self;
373 1.1 thorpej struct gio_attach_args* ga = aux;
374 1.1 thorpej struct hpc_attach_args ha;
375 1.3 thorpej const struct hpc_device *hd;
376 1.27 pooka uint32_t hpctype;
377 1.46 rumble int isonboard;
378 1.46 rumble int isioplus;
379 1.27 pooka int sysmask;
380 1.3 thorpej
381 1.3 thorpej switch (mach_type) {
382 1.27 pooka case MACH_SGI_IP12:
383 1.27 pooka sysmask = HPCDEV_IP12;
384 1.27 pooka break;
385 1.27 pooka
386 1.20 sekiya case MACH_SGI_IP20:
387 1.20 sekiya sysmask = HPCDEV_IP20;
388 1.20 sekiya break;
389 1.23 sekiya
390 1.3 thorpej case MACH_SGI_IP22:
391 1.3 thorpej if (mach_subtype == MACH_SGI_IP22_FULLHOUSE)
392 1.3 thorpej sysmask = HPCDEV_IP22;
393 1.3 thorpej else
394 1.3 thorpej sysmask = HPCDEV_IP24;
395 1.3 thorpej break;
396 1.3 thorpej
397 1.3 thorpej default:
398 1.23 sekiya panic("hpc_attach: can't handle HPC on an IP%d", mach_type);
399 1.3 thorpej };
400 1.1 thorpej
401 1.29 rumble if ((hpctype = hpc_revision(sc, ga)) == 0)
402 1.29 rumble panic("hpc_attach: could not identify HPC revision\n");
403 1.24 sekiya
404 1.29 rumble /* force big-endian mode */
405 1.29 rumble if (hpctype == 15)
406 1.29 rumble *(uint32_t *)MIPS_PHYS_TO_KSEG1(ga->ga_addr+HPC1_BIGENDIAN) = 0;
407 1.46 rumble
408 1.46 rumble /*
409 1.46 rumble * All machines have only one HPC on the mainboard itself. ''Extra''
410 1.46 rumble * HPCs require bus arbiter and other magic to run happily.
411 1.46 rumble */
412 1.46 rumble isonboard = (ga->ga_addr == HPC_BASE_ADDRESS_0);
413 1.46 rumble isioplus = (ga->ga_addr == HPC_BASE_ADDRESS_1 && hpctype == 3 &&
414 1.46 rumble sysmask == HPCDEV_IP24);
415 1.23 sekiya
416 1.46 rumble printf(": SGI HPC%d%s (%s)\n", (hpctype == 3) ? 3 : 1,
417 1.46 rumble (hpctype == 15) ? ".5" : "", (isonboard) ? "onboard" :
418 1.46 rumble (isioplus) ? "IOPLUS mezzanine" : "GIO slot");
419 1.46 rumble
420 1.46 rumble /* configure the bus arbiter appropriately (never happens on Indigo2) */
421 1.46 rumble if (!isonboard) {
422 1.46 rumble int arb_slot;
423 1.46 rumble
424 1.46 rumble arb_slot = (ga->ga_addr == HPC_BASE_ADDRESS_1) ?
425 1.46 rumble GIO_SLOT_EXP0 : GIO_SLOT_EXP1;
426 1.46 rumble
427 1.46 rumble if (gio_arb_config(arb_slot, GIO_ARB_RT | GIO_ARB_MST)) {
428 1.46 rumble printf("%s: failed to configure GIO bus arbiter\n",
429 1.46 rumble sc->sc_dev.dv_xname);
430 1.46 rumble return;
431 1.46 rumble }
432 1.46 rumble }
433 1.1 thorpej
434 1.47 rumble sc->sc_ct = SGIMIPS_BUS_SPACE_HPC;
435 1.1 thorpej sc->sc_ch = ga->ga_ioh;
436 1.1 thorpej
437 1.1 thorpej sc->sc_base = ga->ga_addr;
438 1.3 thorpej
439 1.45 rumble hd = (hpctype == 3) ? hpc3_devices : hpc1_devices;
440 1.45 rumble for (; hd->hd_name != NULL; hd++) {
441 1.29 rumble if (!(hd->hd_sysmask & sysmask) || hd->hd_base != sc->sc_base)
442 1.5 rafal continue;
443 1.5 rafal
444 1.5 rafal ha.ha_name = hd->hd_name;
445 1.5 rafal ha.ha_devoff = hd->hd_devoff;
446 1.5 rafal ha.ha_dmaoff = hd->hd_dmaoff;
447 1.5 rafal ha.ha_irq = hd->hd_irq;
448 1.5 rafal
449 1.5 rafal /* XXX This is disgusting. */
450 1.47 rumble ha.ha_st = SGIMIPS_BUS_SPACE_HPC;
451 1.5 rafal ha.ha_sh = MIPS_PHYS_TO_KSEG1(sc->sc_base);
452 1.5 rafal ha.ha_dmat = &sgimips_default_bus_dma_tag;
453 1.22 sekiya if (hpctype == 3)
454 1.22 sekiya ha.hpc_regs = &hpc3_values;
455 1.22 sekiya else
456 1.22 sekiya ha.hpc_regs = &hpc1_values;
457 1.23 sekiya ha.hpc_regs->revision = hpctype;
458 1.42 rumble hpc_read_eeprom(hpctype, ha.ha_st, ha.ha_sh, ha.hpc_eeprom,
459 1.42 rumble sizeof(ha.hpc_eeprom));
460 1.5 rafal
461 1.32 drochner (void) config_found_sm_loc(self, "hpc", NULL, &ha, hpc_print,
462 1.32 drochner hpc_submatch);
463 1.3 thorpej }
464 1.1 thorpej
465 1.7 simonb /*
466 1.7 simonb * XXX: Only attach the powerfail interrupt once, since the
467 1.6 rafal * interrupt code doesn't let you share interrupt just yet.
468 1.6 rafal *
469 1.7 simonb * Since the powerfail interrupt is hardcoded to read from
470 1.6 rafal * a specific register anyway (XXX#2!), we don't care when
471 1.6 rafal * it gets attached, as long as it only happens once.
472 1.1 thorpej */
473 1.23 sekiya if (mach_type == MACH_SGI_IP22 && !powerintr_established) {
474 1.6 rafal cpu_intr_establish(9, IPL_NONE, hpc_power_intr, sc);
475 1.6 rafal powerintr_established++;
476 1.6 rafal }
477 1.26 sekiya
478 1.26 sekiya #if defined(BLINK)
479 1.28 pooka if (mach_type == MACH_SGI_IP12 || mach_type == MACH_SGI_IP20)
480 1.26 sekiya hpc_blink(sc);
481 1.26 sekiya #endif
482 1.1 thorpej }
483 1.1 thorpej
484 1.40 rumble /*
485 1.40 rumble * HPC revision detection isn't as simple as it should be. Devices probe
486 1.40 rumble * differently depending on their slots, but luckily there is only one
487 1.40 rumble * instance in which we have to decide the major revision (HPC1 vs HPC3).
488 1.40 rumble *
489 1.40 rumble * The HPC is found in the following configurations:
490 1.40 rumble * o Personal Iris 4D/3x:
491 1.40 rumble * One on-board HPC1 or HPC1.5.
492 1.40 rumble *
493 1.40 rumble * o Indigo R3k/R4k:
494 1.40 rumble * One on-board HPC1 or HPC1.5.
495 1.40 rumble * Up to two additional HPC1.5's in GIO slots 0 and 1.
496 1.40 rumble *
497 1.40 rumble * o Indy:
498 1.40 rumble * One on-board HPC3.
499 1.40 rumble * Up to two additional HPC1.5's in GIO slots 0 and 1.
500 1.40 rumble *
501 1.40 rumble * o Challenge S
502 1.40 rumble * One on-board HPC3.
503 1.40 rumble * Up to one additional HPC3 on the IOPLUS board (if installed).
504 1.40 rumble * Up to one additional HPC1.5 in slot 1 of the IOPLUS board.
505 1.40 rumble *
506 1.40 rumble * o Indigo2, Challenge M
507 1.40 rumble * One on-board HPC3.
508 1.40 rumble *
509 1.40 rumble * All we really have to worry about is the IP22 case.
510 1.40 rumble */
511 1.41 rumble static int
512 1.29 rumble hpc_revision(struct hpc_softc *sc, struct gio_attach_args *ga)
513 1.29 rumble {
514 1.29 rumble
515 1.40 rumble /* No hardware ever supported the last hpc base address. */
516 1.40 rumble if (ga->ga_addr == HPC_BASE_ADDRESS_3)
517 1.29 rumble return (0);
518 1.29 rumble
519 1.40 rumble if (mach_type == MACH_SGI_IP12 || mach_type == MACH_SGI_IP20) {
520 1.29 rumble u_int32_t reg;
521 1.29 rumble
522 1.29 rumble if (!badaddr((void *)MIPS_PHYS_TO_KSEG1(ga->ga_addr +
523 1.29 rumble HPC1_BIGENDIAN), 4)) {
524 1.29 rumble reg = *(uint32_t *)MIPS_PHYS_TO_KSEG1(ga->ga_addr +
525 1.29 rumble HPC1_BIGENDIAN);
526 1.29 rumble
527 1.29 rumble if (((reg >> HPC1_REVSHIFT) & HPC1_REVMASK) ==
528 1.29 rumble HPC1_REV15)
529 1.40 rumble return (15);
530 1.29 rumble else
531 1.40 rumble return (1);
532 1.40 rumble }
533 1.40 rumble
534 1.40 rumble return (1);
535 1.40 rumble }
536 1.40 rumble
537 1.40 rumble /*
538 1.40 rumble * If IP22, probe slot 0 to determine if HPC1.5 or HPC3. Slot 1 must
539 1.40 rumble * be HPC1.5.
540 1.40 rumble *
541 1.40 rumble * XXX - If Challenge S is Fullhouse, but without the eisa presence bit,
542 1.40 rumble * we could just conditionalise on that, no? Or is it Guinness?
543 1.40 rumble */
544 1.40 rumble if (mach_type == MACH_SGI_IP22) {
545 1.40 rumble if (ga->ga_addr == HPC_BASE_ADDRESS_0)
546 1.40 rumble return (3);
547 1.40 rumble
548 1.40 rumble if (ga->ga_addr == HPC_BASE_ADDRESS_2)
549 1.40 rumble return (15);
550 1.40 rumble
551 1.40 rumble /*
552 1.40 rumble * Probe for it. We use one of the PBUS registers. Note
553 1.40 rumble * that this probe succeeds with my E++ adapter in slot 1,
554 1.40 rumble * but it appears to do the right thing in slot 0!
555 1.40 rumble */
556 1.40 rumble if (badaddr((void *)MIPS_PHYS_TO_KSEG1(ga->ga_addr +
557 1.40 rumble HPC3_PBUS_CH7_BP), 4))
558 1.40 rumble return (15);
559 1.40 rumble else
560 1.40 rumble return (3);
561 1.29 rumble }
562 1.29 rumble
563 1.40 rumble return (0);
564 1.29 rumble }
565 1.29 rumble
566 1.41 rumble static int
567 1.32 drochner hpc_submatch(struct device *parent, struct cfdata *cf,
568 1.33 drochner const int *ldesc, void *aux)
569 1.1 thorpej {
570 1.1 thorpej struct hpc_attach_args *ha = aux;
571 1.1 thorpej
572 1.3 thorpej if (cf->cf_loc[HPCCF_OFFSET] != HPCCF_OFFSET_DEFAULT &&
573 1.12 thorpej (bus_addr_t) cf->cf_loc[HPCCF_OFFSET] != ha->ha_devoff)
574 1.3 thorpej return (0);
575 1.1 thorpej
576 1.8 thorpej return (config_match(parent, cf, aux));
577 1.3 thorpej }
578 1.3 thorpej
579 1.41 rumble static int
580 1.3 thorpej hpc_print(void *aux, const char *pnp)
581 1.3 thorpej {
582 1.3 thorpej struct hpc_attach_args *ha = aux;
583 1.1 thorpej
584 1.3 thorpej if (pnp)
585 1.3 thorpej printf("%s at %s", ha->ha_name, pnp);
586 1.1 thorpej
587 1.3 thorpej printf(" offset 0x%lx", ha->ha_devoff);
588 1.1 thorpej
589 1.3 thorpej return (UNCONF);
590 1.1 thorpej }
591 1.1 thorpej
592 1.41 rumble static int
593 1.3 thorpej hpc_power_intr(void *arg)
594 1.1 thorpej {
595 1.1 thorpej u_int32_t pwr_reg;
596 1.1 thorpej
597 1.1 thorpej pwr_reg = *((volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(0x1fbd9850));
598 1.1 thorpej *((volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(0x1fbd9850)) = pwr_reg;
599 1.1 thorpej
600 1.1 thorpej printf("hpc_power_intr: panel reg = %08x\n", pwr_reg);
601 1.1 thorpej
602 1.1 thorpej if (pwr_reg & 2)
603 1.3 thorpej cpu_reboot(RB_HALT, NULL);
604 1.1 thorpej
605 1.1 thorpej return 1;
606 1.1 thorpej }
607 1.26 sekiya
608 1.26 sekiya #if defined(BLINK)
609 1.26 sekiya static void
610 1.26 sekiya hpc_blink(void *self)
611 1.26 sekiya {
612 1.26 sekiya struct hpc_softc *sc = (struct hpc_softc *) self;
613 1.26 sekiya register int s;
614 1.26 sekiya int value;
615 1.26 sekiya
616 1.26 sekiya s = splhigh();
617 1.26 sekiya
618 1.43 rumble value = *(volatile uint8_t *)MIPS_PHYS_TO_KSEG1(HPC_BASE_ADDRESS_0 +
619 1.43 rumble HPC1_AUX_REGS);
620 1.26 sekiya value ^= HPC1_AUX_CONSLED;
621 1.43 rumble *(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(HPC_BASE_ADDRESS_0 +
622 1.43 rumble HPC1_AUX_REGS) = value;
623 1.26 sekiya splx(s);
624 1.26 sekiya
625 1.26 sekiya /*
626 1.26 sekiya * Blink rate is:
627 1.26 sekiya * full cycle every second if completely idle (loadav = 0)
628 1.26 sekiya * full cycle every 2 seconds if loadav = 1
629 1.26 sekiya * full cycle every 3 seconds if loadav = 2
630 1.26 sekiya * etc.
631 1.26 sekiya */
632 1.26 sekiya s = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1));
633 1.26 sekiya callout_reset(&hpc_blink_ch, s, hpc_blink, sc);
634 1.26 sekiya }
635 1.26 sekiya #endif
636 1.26 sekiya
637 1.42 rumble /*
638 1.42 rumble * Read the eeprom associated with one of the HPC's.
639 1.42 rumble *
640 1.42 rumble * NB: An eeprom is not always present, but the HPC should be able to
641 1.42 rumble * handle this gracefully. Any consumers should validate the data to
642 1.42 rumble * ensure it's reasonable.
643 1.42 rumble */
644 1.42 rumble static int
645 1.42 rumble hpc_read_eeprom(int hpctype, bus_space_tag_t t, bus_space_handle_t h,
646 1.42 rumble uint8_t *buf, size_t len)
647 1.42 rumble {
648 1.42 rumble struct seeprom_descriptor sd;
649 1.42 rumble bus_space_handle_t bsh;
650 1.42 rumble bus_space_tag_t tag;
651 1.42 rumble bus_size_t offset;
652 1.42 rumble
653 1.42 rumble if (!len || len & 0x1)
654 1.42 rumble return (1);
655 1.42 rumble
656 1.43 rumble offset = (hpctype == 3) ? HPC3_EEPROM_DATA : HPC1_AUX_REGS;
657 1.42 rumble
658 1.42 rumble tag = SGIMIPS_BUS_SPACE_NORMAL;
659 1.42 rumble if (bus_space_subregion(t, h, offset, 1, &bsh) != 0)
660 1.42 rumble return (1);
661 1.42 rumble
662 1.42 rumble sd.sd_chip = C56_66;
663 1.42 rumble sd.sd_tag = tag;
664 1.42 rumble sd.sd_bsh = bsh;
665 1.42 rumble sd.sd_regsize = 1;
666 1.42 rumble sd.sd_control_offset = 0;
667 1.42 rumble sd.sd_status_offset = 0;
668 1.42 rumble sd.sd_dataout_offset = 0;
669 1.42 rumble sd.sd_DI = 0x10; /* EEPROM -> CPU */
670 1.42 rumble sd.sd_DO = 0x08; /* CPU -> EEPROM */
671 1.42 rumble sd.sd_CK = 0x04;
672 1.42 rumble sd.sd_CS = 0x02;
673 1.42 rumble sd.sd_MS = 0;
674 1.42 rumble sd.sd_RDY = 0;
675 1.42 rumble
676 1.42 rumble if (read_seeprom(&sd, (uint16_t *)buf, 0, len / 2) != 1)
677 1.42 rumble return (1);
678 1.42 rumble
679 1.42 rumble bus_space_unmap(t, bsh, 1);
680 1.42 rumble
681 1.42 rumble return (0);
682 1.42 rumble }
683