hpc.c revision 1.2 1 /* $NetBSD: hpc.c,v 1.2 2001/08/19 03:16:21 wdk Exp $ */
2
3 /*
4 * Copyright (c) 2000 Soren S. Jorvang
5 * Copyright (c) 2001 Rafal K. Boni
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed for the
19 * NetBSD Project. See http://www.netbsd.org/ for
20 * information about NetBSD.
21 * 4. The name of the author may not be used to endorse or promote products
22 * derived from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/device.h>
39 #include <sys/reboot.h>
40
41 #include <machine/machtype.h>
42
43 #include <sgimips/gio/gioreg.h>
44 #include <sgimips/gio/giovar.h>
45
46 #include <sgimips/hpc/hpcvar.h>
47 #include <sgimips/hpc/hpcreg.h>
48 #include <sgimips/hpc/iocreg.h>
49
50 #include "locators.h"
51
52 struct hpc_softc {
53 struct device sc_dev;
54
55 bus_addr_t sc_base;
56
57 bus_space_tag_t sc_ct;
58 bus_space_handle_t sc_ch;
59 };
60
61 extern int mach_type; /* IPxx type */
62 extern int mach_subtype; /* subtype: eg., Guiness/Fullhouse for IP22 */
63 extern int mach_boardrev; /* machine board revision, in case it matters */
64
65 extern struct sgimips_bus_dma_tag sgimips_default_bus_dma_tag;
66
67 static int hpc_match(struct device *, struct cfdata *, void *);
68 static void hpc_attach(struct device *, struct device *, void *);
69 static int hpc_print(void *, const char *);
70 static int hpc_search(struct device *, struct cfdata *, void *);
71
72 static int hpc_power_intr(void *);
73
74 struct cfattach hpc_ca = {
75 sizeof(struct hpc_softc), hpc_match, hpc_attach
76 };
77
78 static int
79 hpc_match(parent, match, aux)
80 struct device *parent;
81 struct cfdata *match;
82 void *aux;
83 {
84 struct gio_attach_args* ga = aux;
85
86 /* Make sure it's actually there and readable */
87 if (badaddr((void*)MIPS_PHYS_TO_KSEG1(ga->ga_addr), sizeof(u_int32_t)))
88 return 0;
89
90 return 1;
91 }
92
93 static void
94 hpc_attach(parent, self, aux)
95 struct device *parent;
96 struct device *self;
97 void *aux;
98 {
99 struct hpc_softc *sc = (struct hpc_softc *)self;
100 struct gio_attach_args* ga = aux;
101 struct hpc_attach_args ha;
102
103 /*
104 * XXX
105 */
106 printf("\n");
107
108 sc->sc_ct = 1;
109 sc->sc_ch = ga->ga_ioh;
110
111 sc->sc_base = ga->ga_addr;
112 config_search(hpc_search, self, &ha);
113
114 /*
115 * XXXrkb: only true for first HPC, but didn't know where else to
116 * shove it (ip22_intr is too early). I suppose I should request
117 * a post-config callback or something, but where?
118 */
119 cpu_intr_establish(9, IPL_NONE, hpc_power_intr, sc);
120 }
121
122 static int
123 hpc_print(aux, name)
124 void *aux;
125 const char *name;
126 {
127 struct hpc_attach_args *ha = aux;
128
129 if (name != 0)
130 return QUIET;
131
132 if (ha->ha_offset != HPCCF_OFFSET_DEFAULT)
133 printf(" offset 0x%lx", ha->ha_offset);
134
135 return UNCONF;
136 }
137
138 static int
139 hpc_search(parent, cf, aux)
140 struct device *parent;
141 struct cfdata *cf;
142 void *aux;
143 {
144 struct hpc_attach_args *haa = aux;
145 struct hpc_softc *sc = (struct hpc_softc *)parent;
146
147 do {
148 haa->ha_name = cf->cf_driver->cd_name;
149 haa->ha_offset = cf->cf_loc[HPCCF_OFFSET];
150
151 haa->ha_iot = 1; /* XXX */
152 haa->ha_ioh = MIPS_PHYS_TO_KSEG1(sc->sc_base);
153 haa->ha_dmat = &sgimips_default_bus_dma_tag;
154
155 if ((*cf->cf_attach->ca_match)(parent, cf, haa) > 0)
156 config_attach(parent, cf, haa, hpc_print);
157 } while (cf->cf_fstate == FSTATE_STAR);
158
159 return 0;
160 }
161
162 static int
163 hpc_power_intr(void * arg)
164 {
165 u_int32_t pwr_reg;
166
167 pwr_reg = *((volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(0x1fbd9850));
168 *((volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(0x1fbd9850)) = pwr_reg;
169
170 printf("hpc_power_intr: panel reg = %08x\n", pwr_reg);
171
172 if (pwr_reg & 2)
173 cpu_reboot(RB_HALT, NULL);
174
175 return 1;
176 }
177
178