hpc.c revision 1.21 1 /* $NetBSD: hpc.c,v 1.21 2003/12/16 05:27:40 sekiya Exp $ */
2
3 /*
4 * Copyright (c) 2000 Soren S. Jorvang
5 * Copyright (c) 2001 Rafal K. Boni
6 * Copyright (c) 2001 Jason R. Thorpe
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the
20 * NetBSD Project. See http://www.NetBSD.org/ for
21 * information about NetBSD.
22 * 4. The name of the author may not be used to endorse or promote products
23 * derived from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: hpc.c,v 1.21 2003/12/16 05:27:40 sekiya Exp $");
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/device.h>
43 #include <sys/reboot.h>
44
45 #include <machine/machtype.h>
46
47 #include <sgimips/gio/gioreg.h>
48 #include <sgimips/gio/giovar.h>
49
50 #include <sgimips/hpc/hpcvar.h>
51 #include <sgimips/hpc/hpcreg.h>
52 #include <sgimips/ioc/iocreg.h>
53
54 #include "locators.h"
55
56 const struct hpc_device {
57 const char *hd_name;
58 bus_addr_t hd_devoff;
59 bus_addr_t hd_dmaoff;
60 int hd_irq;
61 int hd_sysmask;
62 } hpc_devices[] = {
63 { "zsc",
64 /* XXX Magic numbers */
65 HPC_PBUS_CH6_DEVREGS + IOC_SERIAL_REGS, 0,
66 29,
67 HPCDEV_IP22 | HPCDEV_IP24 },
68
69 { "pckbc",
70 HPC_PBUS_CH6_DEVREGS + IOC_KB_REGS, 0,
71 28,
72 HPCDEV_IP22 | HPCDEV_IP24 },
73
74 { "sq",
75 HPC_ENET_DEVREGS, HPC_ENET_REGS,
76 3,
77 HPCDEV_IP22 | HPCDEV_IP24 },
78
79 { "wdsc",
80 HPC_SCSI0_DEVREGS, HPC_SCSI0_REGS,
81 1, /* XXX 1 = IRQ_LOCAL0 + 1 */
82 HPCDEV_IP22 | HPCDEV_IP24 },
83
84 { "wdsc",
85 HPC_SCSI1_DEVREGS, HPC_SCSI1_REGS,
86 2, /* XXX 2 = IRQ_LOCAL0 + 2 */
87 HPCDEV_IP22 },
88
89 { "dpclock",
90 HPC1_PBUS_BBRAM, 0,
91 -1,
92 HPCDEV_IP20 },
93
94 { "dsclock",
95 HPC_PBUS_BBRAM, 0,
96 -1,
97 HPCDEV_IP22 | HPCDEV_IP24 },
98
99 { "haltwo",
100 HPC_PBUS_CH0_DEVREGS, HPC_PBUS_DMAREGS,
101 8 + 4, /* XXX IRQ_LOCAL1 + 4 */
102 HPCDEV_IP22 | HPCDEV_IP24 },
103
104 { NULL,
105 0, 0,
106 0,
107 0
108 }
109 };
110
111 struct hpc_softc {
112 struct device sc_dev;
113
114 bus_addr_t sc_base;
115
116 bus_space_tag_t sc_ct;
117 bus_space_handle_t sc_ch;
118 };
119
120 extern int mach_type; /* IPxx type */
121 extern int mach_subtype; /* subtype: eg., Guiness/Fullhouse for IP22 */
122 extern int mach_boardrev; /* machine board revision, in case it matters */
123
124 extern struct sgimips_bus_dma_tag sgimips_default_bus_dma_tag;
125
126 static int powerintr_established;
127
128 int hpc_match(struct device *, struct cfdata *, void *);
129 void hpc_attach(struct device *, struct device *, void *);
130 int hpc_print(void *, const char *);
131
132 int hpc_submatch(struct device *, struct cfdata *, void *);
133
134 int hpc_power_intr(void *);
135
136 CFATTACH_DECL(hpc, sizeof(struct hpc_softc),
137 hpc_match, hpc_attach, NULL, NULL);
138
139 int
140 hpc_match(struct device *parent, struct cfdata *cf, void *aux)
141 {
142 struct gio_attach_args* ga = aux;
143
144 /* Make sure it's actually there and readable */
145 if (badaddr((void*)MIPS_PHYS_TO_KSEG1(ga->ga_addr), sizeof(u_int32_t)))
146 return 0;
147
148 return 1;
149 }
150
151 void
152 hpc_attach(struct device *parent, struct device *self, void *aux)
153 {
154 struct hpc_softc *sc = (struct hpc_softc *)self;
155 struct gio_attach_args* ga = aux;
156 struct hpc_attach_args ha;
157 const struct hpc_device *hd;
158 int sysmask, hpctype;
159
160 switch (mach_type) {
161 case MACH_SGI_IP20:
162 hpctype = 15;
163 sysmask = HPCDEV_IP20;
164 break;
165 case MACH_SGI_IP22:
166 hpctype = 3;
167 if (mach_subtype == MACH_SGI_IP22_FULLHOUSE)
168 sysmask = HPCDEV_IP22;
169 else
170 sysmask = HPCDEV_IP24;
171 break;
172
173 default:
174 panic("hpc_attach: can't handle HPC on an IP%d",
175 mach_type);
176 };
177
178 printf(": SGI HPC%d\n", hpctype);
179
180 sc->sc_ct = 1;
181 sc->sc_ch = ga->ga_ioh;
182
183 sc->sc_base = ga->ga_addr;
184
185 for (hd = hpc_devices; hd->hd_name != NULL; hd++) {
186 if (!(hd->hd_sysmask & sysmask))
187 continue;
188
189 ha.ha_name = hd->hd_name;
190 ha.ha_devoff = hd->hd_devoff;
191 ha.ha_dmaoff = hd->hd_dmaoff;
192 ha.ha_irq = hd->hd_irq;
193
194 /* XXX This is disgusting. */
195 ha.ha_st = 1;
196 ha.ha_sh = MIPS_PHYS_TO_KSEG1(sc->sc_base);
197 ha.ha_dmat = &sgimips_default_bus_dma_tag;
198
199 (void) config_found_sm(self, &ha, hpc_print, hpc_submatch);
200 }
201
202 /*
203 * XXX: Only attach the powerfail interrupt once, since the
204 * interrupt code doesn't let you share interrupt just yet.
205 *
206 * Since the powerfail interrupt is hardcoded to read from
207 * a specific register anyway (XXX#2!), we don't care when
208 * it gets attached, as long as it only happens once.
209 */
210 if (!powerintr_established) {
211 cpu_intr_establish(9, IPL_NONE, hpc_power_intr, sc);
212 powerintr_established++;
213 }
214 }
215
216 int
217 hpc_submatch(struct device *parent, struct cfdata *cf, void *aux)
218 {
219 struct hpc_attach_args *ha = aux;
220
221 if (cf->cf_loc[HPCCF_OFFSET] != HPCCF_OFFSET_DEFAULT &&
222 (bus_addr_t) cf->cf_loc[HPCCF_OFFSET] != ha->ha_devoff)
223 return (0);
224
225 return (config_match(parent, cf, aux));
226 }
227
228 int
229 hpc_print(void *aux, const char *pnp)
230 {
231 struct hpc_attach_args *ha = aux;
232
233 if (pnp)
234 printf("%s at %s", ha->ha_name, pnp);
235
236 printf(" offset 0x%lx", ha->ha_devoff);
237
238 return (UNCONF);
239 }
240
241 int
242 hpc_power_intr(void *arg)
243 {
244 u_int32_t pwr_reg;
245
246 pwr_reg = *((volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(0x1fbd9850));
247 *((volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(0x1fbd9850)) = pwr_reg;
248
249 printf("hpc_power_intr: panel reg = %08x\n", pwr_reg);
250
251 if (pwr_reg & 2)
252 cpu_reboot(RB_HALT, NULL);
253
254 return 1;
255 }
256