asp.c revision 1.1.6.2 1 1.1.6.2 yamt /* $NetBSD: asp.c,v 1.1.6.2 2014/05/22 11:39:50 yamt Exp $ */
2 1.1.6.2 yamt
3 1.1.6.2 yamt /* $OpenBSD: asp.c,v 1.5 2000/02/09 05:04:22 mickey Exp $ */
4 1.1.6.2 yamt
5 1.1.6.2 yamt /*
6 1.1.6.2 yamt * Copyright (c) 1998-2003 Michael Shalayeff
7 1.1.6.2 yamt * All rights reserved.
8 1.1.6.2 yamt *
9 1.1.6.2 yamt * Redistribution and use in source and binary forms, with or without
10 1.1.6.2 yamt * modification, are permitted provided that the following conditions
11 1.1.6.2 yamt * are met:
12 1.1.6.2 yamt * 1. Redistributions of source code must retain the above copyright
13 1.1.6.2 yamt * notice, this list of conditions and the following disclaimer.
14 1.1.6.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
15 1.1.6.2 yamt * notice, this list of conditions and the following disclaimer in the
16 1.1.6.2 yamt * documentation and/or other materials provided with the distribution.
17 1.1.6.2 yamt *
18 1.1.6.2 yamt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.1.6.2 yamt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.1.6.2 yamt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.1.6.2 yamt * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
22 1.1.6.2 yamt * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 1.1.6.2 yamt * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 1.1.6.2 yamt * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 1.1.6.2 yamt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 1.1.6.2 yamt * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 1.1.6.2 yamt * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 1.1.6.2 yamt * THE POSSIBILITY OF SUCH DAMAGE.
29 1.1.6.2 yamt */
30 1.1.6.2 yamt
31 1.1.6.2 yamt /*
32 1.1.6.2 yamt * References:
33 1.1.6.2 yamt *
34 1.1.6.2 yamt * 1. Cobra/Coral I/O Subsystem External Reference Specification
35 1.1.6.2 yamt * Hewlett-Packard
36 1.1.6.2 yamt *
37 1.1.6.2 yamt */
38 1.1.6.2 yamt
39 1.1.6.2 yamt #include <sys/cdefs.h>
40 1.1.6.2 yamt __KERNEL_RCSID(0, "$NetBSD: asp.c,v 1.1.6.2 2014/05/22 11:39:50 yamt Exp $");
41 1.1.6.2 yamt
42 1.1.6.2 yamt #include <sys/param.h>
43 1.1.6.2 yamt #include <sys/systm.h>
44 1.1.6.2 yamt #include <sys/device.h>
45 1.1.6.2 yamt #include <sys/reboot.h>
46 1.1.6.2 yamt
47 1.1.6.2 yamt #include <sys/bus.h>
48 1.1.6.2 yamt #include <machine/iomod.h>
49 1.1.6.2 yamt #include <machine/autoconf.h>
50 1.1.6.2 yamt #include <machine/cpufunc.h>
51 1.1.6.2 yamt
52 1.1.6.2 yamt #include <hppa/hppa/machdep.h>
53 1.1.6.2 yamt #include <hppa/dev/cpudevs.h>
54 1.1.6.2 yamt #include <hppa/dev/viper.h>
55 1.1.6.2 yamt
56 1.1.6.2 yamt #include <hppa/gsc/gscbusvar.h>
57 1.1.6.2 yamt
58 1.1.6.2 yamt struct asp_hwr {
59 1.1.6.2 yamt uint8_t asp_reset;
60 1.1.6.2 yamt uint8_t asp_resv[31];
61 1.1.6.2 yamt uint8_t asp_version;
62 1.1.6.2 yamt uint8_t asp_resv1[15];
63 1.1.6.2 yamt uint8_t asp_scsidsync;
64 1.1.6.2 yamt uint8_t asp_resv2[15];
65 1.1.6.2 yamt uint8_t asp_error;
66 1.1.6.2 yamt };
67 1.1.6.2 yamt
68 1.1.6.2 yamt struct asp_trs {
69 1.1.6.2 yamt uint32_t asp_irr;
70 1.1.6.2 yamt uint32_t asp_imr;
71 1.1.6.2 yamt uint32_t asp_ipr;
72 1.1.6.2 yamt uint32_t asp_icr;
73 1.1.6.2 yamt uint32_t asp_iar;
74 1.1.6.2 yamt uint32_t asp_resv[3];
75 1.1.6.2 yamt uint8_t asp_cled;
76 1.1.6.2 yamt uint8_t asp_resv1[3];
77 1.1.6.2 yamt struct {
78 1.1.6.2 yamt u_int :20,
79 1.1.6.2 yamt asp_spu : 3, /* SPU ID board jumper */
80 1.1.6.2 yamt #define ASP_SPUCOBRA 0
81 1.1.6.2 yamt #define ASP_SPUCORAL 1
82 1.1.6.2 yamt #define ASP_SPUBUSH 2
83 1.1.6.2 yamt #define ASP_SPUHARDBALL 3
84 1.1.6.2 yamt #define ASP_SPUSCORPIO 4
85 1.1.6.2 yamt #define ASP_SPUCORAL2 5
86 1.1.6.2 yamt asp_sw : 1, /* front switch is normal */
87 1.1.6.2 yamt asp_clk : 1, /* SCSI clock is doubled */
88 1.1.6.2 yamt asp_lan : 2, /* LAN iface selector */
89 1.1.6.2 yamt #define ASP_LANINVAL 0
90 1.1.6.2 yamt #define ASP_LANAUI 1
91 1.1.6.2 yamt #define ASP_LANTHIN 2
92 1.1.6.2 yamt #define ASP_LANMISS 3
93 1.1.6.2 yamt asp_lanf: 1, /* LAN AUI fuse is ok */
94 1.1.6.2 yamt asp_spwr: 1, /* SCSI power ok */
95 1.1.6.2 yamt asp_scsi: 3; /* SCSI ctrl ID */
96 1.1.6.2 yamt } _asp_ios;
97 1.1.6.2 yamt #define asp_spu _asp_ios.asp_spu
98 1.1.6.2 yamt #define asp_sw _asp_ios.asp_sw
99 1.1.6.2 yamt #define asp_clk _asp_ios.asp_clk
100 1.1.6.2 yamt #define asp_lan _asp_ios.asp_lan
101 1.1.6.2 yamt #define asp_lanf _asp_ios.asp_lanf
102 1.1.6.2 yamt #define asp_spwr _asp_ios.asp_spwr
103 1.1.6.2 yamt #define asp_scsi _asp_ios.asp_scsi
104 1.1.6.2 yamt };
105 1.1.6.2 yamt
106 1.1.6.2 yamt #define ASP_BANK_SZ 0x02000000
107 1.1.6.2 yamt #define ASP_REG_INT 0x00800000
108 1.1.6.2 yamt #define ASP_ETHER_ADDR 0x00810000
109 1.1.6.2 yamt #define ASP_REG_MISC 0x0082f000
110 1.1.6.2 yamt
111 1.1.6.2 yamt const struct asp_spus_tag {
112 1.1.6.2 yamt char name[12];
113 1.1.6.2 yamt int ledword;
114 1.1.6.2 yamt } asp_spus[] = {
115 1.1.6.2 yamt { "Cobra", 0 },
116 1.1.6.2 yamt { "Coral", 0 },
117 1.1.6.2 yamt { "Bushmaster", 0 },
118 1.1.6.2 yamt { "Hardball", 1 },
119 1.1.6.2 yamt { "Scorpio", 0 },
120 1.1.6.2 yamt { "Coral II", 1 },
121 1.1.6.2 yamt { "#6", 0 },
122 1.1.6.2 yamt { "#7", 0 }
123 1.1.6.2 yamt };
124 1.1.6.2 yamt
125 1.1.6.2 yamt struct asp_softc {
126 1.1.6.2 yamt device_t sc_dev;
127 1.1.6.2 yamt
128 1.1.6.2 yamt struct hppa_interrupt_register sc_ir;
129 1.1.6.2 yamt
130 1.1.6.2 yamt volatile struct asp_hwr *sc_hw;
131 1.1.6.2 yamt volatile struct asp_trs *sc_trs;
132 1.1.6.2 yamt };
133 1.1.6.2 yamt
134 1.1.6.2 yamt int aspmatch(device_t, cfdata_t, void *);
135 1.1.6.2 yamt void aspattach(device_t, device_t, void *);
136 1.1.6.2 yamt
137 1.1.6.2 yamt CFATTACH_DECL_NEW(asp, sizeof(struct asp_softc),
138 1.1.6.2 yamt aspmatch, aspattach, NULL, NULL);
139 1.1.6.2 yamt
140 1.1.6.2 yamt /*
141 1.1.6.2 yamt * Before a module is matched, this fixes up its gsc_attach_args.
142 1.1.6.2 yamt */
143 1.1.6.2 yamt static void asp_fix_args(void *, struct gsc_attach_args *);
144 1.1.6.2 yamt static void
145 1.1.6.2 yamt asp_fix_args(void *_sc, struct gsc_attach_args *ga)
146 1.1.6.2 yamt {
147 1.1.6.2 yamt hppa_hpa_t module_offset;
148 1.1.6.2 yamt struct asp_softc *sc = _sc;
149 1.1.6.2 yamt
150 1.1.6.2 yamt /*
151 1.1.6.2 yamt * Determine this module's interrupt bit.
152 1.1.6.2 yamt */
153 1.1.6.2 yamt module_offset = ga->ga_hpa - (hppa_hpa_t) sc->sc_trs;
154 1.1.6.2 yamt ga->ga_irq = HPPACF_IRQ_UNDEF;
155 1.1.6.2 yamt #define ASP_IRQ(off, irq) if (module_offset == off) ga->ga_irq = irq
156 1.1.6.2 yamt ASP_IRQ(0x22000, 6); /* com1 */
157 1.1.6.2 yamt ASP_IRQ(0x23000, 5); /* com0 */
158 1.1.6.2 yamt ASP_IRQ(0x24000, 7); /* lpt */
159 1.1.6.2 yamt ASP_IRQ(0x25000, 9); /* osiop */
160 1.1.6.2 yamt ASP_IRQ(0x26000, 8); /* ie */
161 1.1.6.2 yamt ASP_IRQ(0x30000, 3); /* siop */
162 1.1.6.2 yamt ASP_IRQ(0x800000, 13); /* harmony */
163 1.1.6.2 yamt #undef ASP_IRQ
164 1.1.6.2 yamt }
165 1.1.6.2 yamt
166 1.1.6.2 yamt int
167 1.1.6.2 yamt aspmatch(device_t parent, cfdata_t cf, void *aux)
168 1.1.6.2 yamt {
169 1.1.6.2 yamt struct confargs *ca = aux;
170 1.1.6.2 yamt
171 1.1.6.2 yamt if (ca->ca_type.iodc_type != HPPA_TYPE_BHA ||
172 1.1.6.2 yamt ca->ca_type.iodc_sv_model != HPPA_BHA_ASP)
173 1.1.6.2 yamt return 0;
174 1.1.6.2 yamt
175 1.1.6.2 yamt /*
176 1.1.6.2 yamt * Forcibly mask the HPA down to the start of the ASP
177 1.1.6.2 yamt * chip address space.
178 1.1.6.2 yamt */
179 1.1.6.2 yamt ca->ca_hpa &= ~(ASP_BANK_SZ - 1);
180 1.1.6.2 yamt
181 1.1.6.2 yamt return 1;
182 1.1.6.2 yamt }
183 1.1.6.2 yamt
184 1.1.6.2 yamt void
185 1.1.6.2 yamt aspattach(device_t parent, device_t self, void *aux)
186 1.1.6.2 yamt {
187 1.1.6.2 yamt struct confargs *ca = aux;
188 1.1.6.2 yamt struct asp_softc *sc = device_private(self);
189 1.1.6.2 yamt struct gsc_attach_args ga;
190 1.1.6.2 yamt struct cpu_info *ci = &cpus[0];
191 1.1.6.2 yamt bus_space_handle_t ioh;
192 1.1.6.2 yamt int s;
193 1.1.6.2 yamt
194 1.1.6.2 yamt sc->sc_dev = self;
195 1.1.6.2 yamt
196 1.1.6.2 yamt ca->ca_irq = hppa_intr_allocate_bit(&ci->ci_ir, ca->ca_irq);
197 1.1.6.2 yamt if (ca->ca_irq == HPPACF_IRQ_UNDEF) {
198 1.1.6.2 yamt aprint_error_dev(self, ": can't allocate interrupt");
199 1.1.6.2 yamt return;
200 1.1.6.2 yamt }
201 1.1.6.2 yamt
202 1.1.6.2 yamt /*
203 1.1.6.2 yamt * Map the ASP interrupt registers.
204 1.1.6.2 yamt */
205 1.1.6.2 yamt if (bus_space_map(ca->ca_iot, ca->ca_hpa + ASP_REG_INT,
206 1.1.6.2 yamt sizeof(struct asp_trs), 0, &ioh)) {
207 1.1.6.2 yamt aprint_error(": can't map interrupt registers.\n");
208 1.1.6.2 yamt return;
209 1.1.6.2 yamt }
210 1.1.6.2 yamt sc->sc_trs = (struct asp_trs *)ioh;
211 1.1.6.2 yamt
212 1.1.6.2 yamt /*
213 1.1.6.2 yamt * Map the ASP miscellaneous registers.
214 1.1.6.2 yamt */
215 1.1.6.2 yamt if (bus_space_map(ca->ca_iot, ca->ca_hpa + ASP_REG_MISC,
216 1.1.6.2 yamt sizeof(struct asp_hwr), 0, &ioh)) {
217 1.1.6.2 yamt aprint_error(": can't map miscellaneous registers.\n");
218 1.1.6.2 yamt return;
219 1.1.6.2 yamt }
220 1.1.6.2 yamt sc->sc_hw = (struct asp_hwr *)ioh;
221 1.1.6.2 yamt
222 1.1.6.2 yamt /*
223 1.1.6.2 yamt * Map the Ethernet address and read it out.
224 1.1.6.2 yamt */
225 1.1.6.2 yamt if (bus_space_map(ca->ca_iot, ca->ca_hpa + ASP_ETHER_ADDR,
226 1.1.6.2 yamt sizeof(ga.ga_ether_address), 0, &ioh)) {
227 1.1.6.2 yamt aprint_error(": can't map EEPROM.\n");
228 1.1.6.2 yamt return;
229 1.1.6.2 yamt }
230 1.1.6.2 yamt bus_space_read_region_1(ca->ca_iot, ioh, 0,
231 1.1.6.2 yamt ga.ga_ether_address, sizeof(ga.ga_ether_address));
232 1.1.6.2 yamt bus_space_unmap(ca->ca_iot, ioh, sizeof(ga.ga_ether_address));
233 1.1.6.2 yamt
234 1.1.6.2 yamt #ifdef USELEDS
235 1.1.6.2 yamt machine_ledaddr = &sc->sc_trs->asp_cled;
236 1.1.6.2 yamt machine_ledword = asp_spus[sc->sc_trs->asp_spu].ledword;
237 1.1.6.2 yamt #endif
238 1.1.6.2 yamt
239 1.1.6.2 yamt /* reset ASP */
240 1.1.6.2 yamt /* sc->sc_hw->asp_reset = 1; */
241 1.1.6.2 yamt /* delay(400000); */
242 1.1.6.2 yamt
243 1.1.6.2 yamt s = splhigh();
244 1.1.6.2 yamt viper_setintrwnd(1 << ca->ca_irq);
245 1.1.6.2 yamt
246 1.1.6.2 yamt sc->sc_trs->asp_imr = ~0;
247 1.1.6.2 yamt (void)sc->sc_trs->asp_irr;
248 1.1.6.2 yamt sc->sc_trs->asp_imr = 0;
249 1.1.6.2 yamt
250 1.1.6.2 yamt /* Establish the interrupt register. */
251 1.1.6.2 yamt hppa_interrupt_register_establish(ci, &sc->sc_ir);
252 1.1.6.2 yamt sc->sc_ir.ir_name = device_xname(self);
253 1.1.6.2 yamt sc->sc_ir.ir_mask = &sc->sc_trs->asp_imr;
254 1.1.6.2 yamt sc->sc_ir.ir_req = &sc->sc_trs->asp_irr;
255 1.1.6.2 yamt
256 1.1.6.2 yamt splx(s);
257 1.1.6.2 yamt
258 1.1.6.2 yamt aprint_normal(": %s rev %d, lan %d scsi %d\n",
259 1.1.6.2 yamt asp_spus[sc->sc_trs->asp_spu].name, sc->sc_hw->asp_version,
260 1.1.6.2 yamt sc->sc_trs->asp_lan, sc->sc_trs->asp_scsi);
261 1.1.6.2 yamt
262 1.1.6.2 yamt /* Attach the GSC bus. */
263 1.1.6.2 yamt ga.ga_ca = *ca; /* clone from us */
264 1.1.6.2 yamt if (strcmp(device_xname(parent), "mainbus0") == 0) {
265 1.1.6.2 yamt ga.ga_dp.dp_bc[0] = ga.ga_dp.dp_bc[1];
266 1.1.6.2 yamt ga.ga_dp.dp_bc[1] = ga.ga_dp.dp_bc[2];
267 1.1.6.2 yamt ga.ga_dp.dp_bc[2] = ga.ga_dp.dp_bc[3];
268 1.1.6.2 yamt ga.ga_dp.dp_bc[3] = ga.ga_dp.dp_bc[4];
269 1.1.6.2 yamt ga.ga_dp.dp_bc[4] = ga.ga_dp.dp_bc[5];
270 1.1.6.2 yamt ga.ga_dp.dp_bc[5] = ga.ga_dp.dp_mod;
271 1.1.6.2 yamt ga.ga_dp.dp_mod = 0;
272 1.1.6.2 yamt }
273 1.1.6.2 yamt
274 1.1.6.2 yamt ga.ga_name = "gsc";
275 1.1.6.2 yamt ga.ga_ir = &sc->sc_ir;
276 1.1.6.2 yamt ga.ga_fix_args = asp_fix_args;
277 1.1.6.2 yamt ga.ga_fix_args_cookie = sc;
278 1.1.6.2 yamt ga.ga_scsi_target = sc->sc_trs->asp_scsi;
279 1.1.6.2 yamt config_found(self, &ga, gscprint);
280 1.1.6.2 yamt }
281