hpc.c revision 1.14 1 /* $NetBSD: hpc.c,v 1.14 2003/09/25 16:35:50 lonewolf 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.14 2003/09/25 16:35:50 lonewolf 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 #define HPCDEV_IP22 (1U << 0) /* Indigo2 */
63 #define HPCDEV_IP24 (1U << 1) /* Indy */
64 } hpc_devices[] = {
65 { "zsc",
66 /* XXX Magic numbers */
67 HPC_PBUS_CH6_DEVREGS + 0x30, 0,
68 29,
69 HPCDEV_IP22 | HPCDEV_IP24 },
70
71 { "sq",
72 HPC_ENET_DEVREGS, HPC_ENET_REGS,
73 3,
74 HPCDEV_IP22 | HPCDEV_IP24 },
75
76 { "wdsc",
77 HPC_SCSI0_DEVREGS, HPC_SCSI0_REGS,
78 1, /* XXX 1 = IRQ_LOCAL0 + 1 */
79 HPCDEV_IP22 | HPCDEV_IP24 },
80
81 { "wdsc",
82 HPC_SCSI1_DEVREGS, HPC_SCSI1_REGS,
83 2, /* XXX 2 = IRQ_LOCAL0 + 2 */
84 HPCDEV_IP22 },
85
86 { "dsclock",
87 HPC_PBUS_BBRAM, 0,
88 -1,
89 HPCDEV_IP22 | HPCDEV_IP24 },
90
91 { "haltwo",
92 HPC_PBUS_CH0_DEVREGS, HPC_PBUS_DMAREGS,
93 8 + 4, /* XXX IRQ_LOCAL1 + 4 */
94 HPCDEV_IP24 },
95
96 { NULL,
97 0, 0,
98 0,
99 0
100 }
101 };
102
103 struct hpc_softc {
104 struct device sc_dev;
105
106 bus_addr_t sc_base;
107
108 bus_space_tag_t sc_ct;
109 bus_space_handle_t sc_ch;
110 };
111
112 extern int mach_type; /* IPxx type */
113 extern int mach_subtype; /* subtype: eg., Guiness/Fullhouse for IP22 */
114 extern int mach_boardrev; /* machine board revision, in case it matters */
115
116 extern struct sgimips_bus_dma_tag sgimips_default_bus_dma_tag;
117
118 static int powerintr_established;
119
120 int hpc_match(struct device *, struct cfdata *, void *);
121 void hpc_attach(struct device *, struct device *, void *);
122 int hpc_print(void *, const char *);
123
124 int hpc_submatch(struct device *, struct cfdata *, void *);
125
126 int hpc_power_intr(void *);
127
128 CFATTACH_DECL(hpc, sizeof(struct hpc_softc),
129 hpc_match, hpc_attach, NULL, NULL);
130
131 int
132 hpc_match(struct device *parent, struct cfdata *cf, void *aux)
133 {
134 struct gio_attach_args* ga = aux;
135
136 /* Make sure it's actually there and readable */
137 if (badaddr((void*)MIPS_PHYS_TO_KSEG1(ga->ga_addr), sizeof(u_int32_t)))
138 return 0;
139
140 return 1;
141 }
142
143 void
144 hpc_attach(struct device *parent, struct device *self, void *aux)
145 {
146 struct hpc_softc *sc = (struct hpc_softc *)self;
147 struct gio_attach_args* ga = aux;
148 struct hpc_attach_args ha;
149 const struct hpc_device *hd;
150 int sysmask, hpctype;
151
152 switch (mach_type) {
153 case MACH_SGI_IP22:
154 hpctype = 3;
155 if (mach_subtype == MACH_SGI_IP22_FULLHOUSE)
156 sysmask = HPCDEV_IP22;
157 else
158 sysmask = HPCDEV_IP24;
159 break;
160
161 default:
162 panic("hpc_attach: can't handle HPC on an IP%d",
163 mach_type);
164 };
165
166 printf(": SGI HPC%d\n", hpctype);
167
168 sc->sc_ct = 1;
169 sc->sc_ch = ga->ga_ioh;
170
171 sc->sc_base = ga->ga_addr;
172
173 for (hd = hpc_devices; hd->hd_name != NULL; hd++) {
174 if (!(hd->hd_sysmask & sysmask))
175 continue;
176
177 ha.ha_name = hd->hd_name;
178 ha.ha_devoff = hd->hd_devoff;
179 ha.ha_dmaoff = hd->hd_dmaoff;
180 ha.ha_irq = hd->hd_irq;
181
182 /* XXX This is disgusting. */
183 ha.ha_st = 1;
184 ha.ha_sh = MIPS_PHYS_TO_KSEG1(sc->sc_base);
185 ha.ha_dmat = &sgimips_default_bus_dma_tag;
186
187 (void) config_found_sm(self, &ha, hpc_print, hpc_submatch);
188 }
189
190 /*
191 * XXX: Only attach the powerfail interrupt once, since the
192 * interrupt code doesn't let you share interrupt just yet.
193 *
194 * Since the powerfail interrupt is hardcoded to read from
195 * a specific register anyway (XXX#2!), we don't care when
196 * it gets attached, as long as it only happens once.
197 */
198 if (!powerintr_established) {
199 cpu_intr_establish(9, IPL_NONE, hpc_power_intr, sc);
200 powerintr_established++;
201 }
202 }
203
204 int
205 hpc_submatch(struct device *parent, struct cfdata *cf, void *aux)
206 {
207 struct hpc_attach_args *ha = aux;
208
209 if (cf->cf_loc[HPCCF_OFFSET] != HPCCF_OFFSET_DEFAULT &&
210 (bus_addr_t) cf->cf_loc[HPCCF_OFFSET] != ha->ha_devoff)
211 return (0);
212
213 return (config_match(parent, cf, aux));
214 }
215
216 int
217 hpc_print(void *aux, const char *pnp)
218 {
219 struct hpc_attach_args *ha = aux;
220
221 if (pnp)
222 printf("%s at %s", ha->ha_name, pnp);
223
224 printf(" offset 0x%lx", ha->ha_devoff);
225
226 return (UNCONF);
227 }
228
229 int
230 hpc_power_intr(void *arg)
231 {
232 u_int32_t pwr_reg;
233
234 pwr_reg = *((volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(0x1fbd9850));
235 *((volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(0x1fbd9850)) = pwr_reg;
236
237 printf("hpc_power_intr: panel reg = %08x\n", pwr_reg);
238
239 if (pwr_reg & 2)
240 cpu_reboot(RB_HALT, NULL);
241
242 return 1;
243 }
244