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