hpc.c revision 1.18 1 /* $NetBSD: hpc.c,v 1.18 2003/11/22 03:58:52 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.18 2003/11/22 03:58:52 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/hpc/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 + 0x30, 0,
66 29,
67 HPCDEV_IP22 | HPCDEV_IP24 },
68
69 { "pckbc",
70 HPC_PBUS_CH6_DEVREGS + 0x40, 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_IP22:
162 hpctype = 3;
163 if (mach_subtype == MACH_SGI_IP22_FULLHOUSE)
164 sysmask = HPCDEV_IP22;
165 else
166 sysmask = HPCDEV_IP24;
167 break;
168
169 default:
170 panic("hpc_attach: can't handle HPC on an IP%d",
171 mach_type);
172 };
173
174 printf(": SGI HPC%d\n", hpctype);
175
176 sc->sc_ct = 1;
177 sc->sc_ch = ga->ga_ioh;
178
179 sc->sc_base = ga->ga_addr;
180
181 for (hd = hpc_devices; hd->hd_name != NULL; hd++) {
182 if (!(hd->hd_sysmask & sysmask))
183 continue;
184
185 ha.ha_name = hd->hd_name;
186 ha.ha_devoff = hd->hd_devoff;
187 ha.ha_dmaoff = hd->hd_dmaoff;
188 ha.ha_irq = hd->hd_irq;
189
190 /* XXX This is disgusting. */
191 ha.ha_st = 1;
192 ha.ha_sh = MIPS_PHYS_TO_KSEG1(sc->sc_base);
193 ha.ha_dmat = &sgimips_default_bus_dma_tag;
194
195 (void) config_found_sm(self, &ha, hpc_print, hpc_submatch);
196 }
197
198 /*
199 * XXX: Only attach the powerfail interrupt once, since the
200 * interrupt code doesn't let you share interrupt just yet.
201 *
202 * Since the powerfail interrupt is hardcoded to read from
203 * a specific register anyway (XXX#2!), we don't care when
204 * it gets attached, as long as it only happens once.
205 */
206 if (!powerintr_established) {
207 cpu_intr_establish(9, IPL_NONE, hpc_power_intr, sc);
208 powerintr_established++;
209 }
210 }
211
212 int
213 hpc_submatch(struct device *parent, struct cfdata *cf, void *aux)
214 {
215 struct hpc_attach_args *ha = aux;
216
217 if (cf->cf_loc[HPCCF_OFFSET] != HPCCF_OFFSET_DEFAULT &&
218 (bus_addr_t) cf->cf_loc[HPCCF_OFFSET] != ha->ha_devoff)
219 return (0);
220
221 return (config_match(parent, cf, aux));
222 }
223
224 int
225 hpc_print(void *aux, const char *pnp)
226 {
227 struct hpc_attach_args *ha = aux;
228
229 if (pnp)
230 printf("%s at %s", ha->ha_name, pnp);
231
232 printf(" offset 0x%lx", ha->ha_devoff);
233
234 return (UNCONF);
235 }
236
237 int
238 hpc_power_intr(void *arg)
239 {
240 u_int32_t pwr_reg;
241
242 pwr_reg = *((volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(0x1fbd9850));
243 *((volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(0x1fbd9850)) = pwr_reg;
244
245 printf("hpc_power_intr: panel reg = %08x\n", pwr_reg);
246
247 if (pwr_reg & 2)
248 cpu_reboot(RB_HALT, NULL);
249
250 return 1;
251 }
252