asp.c revision 1.14
1/*	$OpenBSD: asp.c,v 1.14 2005/06/09 18:01:36 mickey Exp $	*/
2
3/*
4 * Copyright (c) 1998-2003 Michael Shalayeff
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26 * THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/*
30 * References:
31 *
32 * 1. Cobra/Coral I/O Subsystem External Reference Specification
33 *    Hewlett-Packard
34 *
35 */
36
37#include <sys/param.h>
38#include <sys/systm.h>
39#include <sys/device.h>
40#include <sys/reboot.h>
41
42#include <machine/bus.h>
43#include <machine/iomod.h>
44#include <machine/autoconf.h>
45#include <machine/cpufunc.h>
46
47#include <hppa/dev/cpudevs.h>
48#include <hppa/dev/viper.h>
49
50#include <hppa/gsc/gscbusvar.h>
51
52struct asp_hwr {
53	u_int8_t asp_reset;
54	u_int8_t asp_resv[31];
55	u_int8_t asp_version;
56	u_int8_t asp_resv1[15];
57	u_int8_t asp_scsidsync;
58	u_int8_t asp_resv2[15];
59	u_int8_t asp_error;
60};
61
62struct asp_trs {
63	u_int32_t asp_irr;
64	u_int32_t asp_imr;
65	u_int32_t asp_ipr;
66	u_int32_t asp_icr;
67	u_int32_t asp_iar;
68	u_int32_t asp_resv[3];
69	u_int8_t  asp_cled;
70	u_int8_t  asp_resv1[3];
71	struct {
72		u_int		:20,
73			asp_spu	: 3,	/* SPU ID board jumper */
74#define	ASP_SPUCOBRA	0
75#define	ASP_SPUCORAL	1
76#define	ASP_SPUBUSH	2
77#define	ASP_SPUHARDBALL	3
78#define	ASP_SPUSCORPIO	4
79#define	ASP_SPUCORAL2	5
80			asp_sw	: 1,	/* front switch is normal */
81			asp_clk : 1,	/* SCSI clock is doubled */
82			asp_lan : 2,	/* LAN iface selector */
83#define	ASP_LANINVAL	0
84#define	ASP_LANAUI	1
85#define	ASP_LANTHIN	2
86#define	ASP_LANMISS	3
87			asp_lanf: 1,	/* LAN AUI fuse is ok */
88			asp_spwr: 1,	/* SCSI power ok */
89			asp_scsi: 3;	/* SCSI ctrl ID */
90	} _asp_ios;
91#define	asp_spu		_asp_ios.asp_spu
92#define	asp_sw		_asp_ios.asp_sw
93#define	asp_clk		_asp_ios.asp_clk
94#define	asp_lan		_asp_ios.asp_lan
95#define	asp_lanf	_asp_ios.asp_lanf
96#define	asp_spwr	_asp_ios.asp_spwr
97#define	asp_scsi	_asp_ios.asp_scsi
98};
99
100const struct asp_spus_tag {
101	char	name[12];
102	int	ledword;
103} asp_spus[] = {
104	{ "Cobra", 0 },
105	{ "Coral", 0 },
106	{ "Bushmaster", 0 },
107	{ "Hardball", 1 },
108	{ "Scorpio", 0 },
109	{ "Coral II", 1 },
110	{ "#6", 0 },
111	{ "#7", 0 }
112};
113
114struct asp_softc {
115	struct  device sc_dev;
116	struct gscbus_ic sc_ic;
117
118	volatile struct asp_hwr *sc_hw;
119	volatile struct asp_trs *sc_trs;
120};
121
122#define	ASP_IOMASK	0xfe000000
123/* ASP "Primary Controller" HPA */
124#define	ASP_CHPA	0xF0800000
125
126int	aspmatch(struct device *, void *, void *);
127void	aspattach(struct device *, struct device *, void *);
128
129struct cfattach asp_ca = {
130	sizeof(struct asp_softc), aspmatch, aspattach
131};
132
133struct cfdriver asp_cd = {
134	NULL, "asp", DV_DULL
135};
136
137int
138aspmatch(parent, cfdata, aux)
139	struct device *parent;
140	void *cfdata;
141	void *aux;
142{
143	struct confargs *ca = aux;
144	/* struct cfdata *cf = cfdata; */
145
146	if (ca->ca_type.iodc_type != HPPA_TYPE_BHA ||
147	    ca->ca_type.iodc_sv_model != HPPA_BHA_ASP)
148		return 0;
149
150	return 1;
151}
152
153void
154aspattach(parent, self, aux)
155	struct device *parent;
156	struct device *self;
157	void *aux;
158{
159	register struct confargs *ca = aux;
160	register struct asp_softc *sc = (struct asp_softc *)self;
161	struct gsc_attach_args ga;
162	bus_space_handle_t ioh;
163	register u_int32_t irr;
164	register int s;
165
166	if (bus_space_map(ca->ca_iot, ca->ca_hpa, IOMOD_HPASIZE, 0, &ioh)) {
167		printf(": can't map IO space\n");
168		return;
169	}
170
171	sc->sc_trs = (struct asp_trs *)ASP_CHPA;
172	sc->sc_hw = (struct asp_hwr *)ca->ca_hpa;
173
174#ifdef USELEDS
175	machine_ledaddr = &sc->sc_trs->asp_cled;
176	machine_ledword = asp_spus[sc->sc_trs->asp_spu].ledword;
177#endif
178
179	/* reset ASP */
180	/* sc->sc_hw->asp_reset = 1; */
181	/* delay(400000); */
182
183	s = splhigh();
184	viper_setintrwnd(1 << ca->ca_irq);
185
186	sc->sc_trs->asp_imr = ~0;
187	irr = sc->sc_trs->asp_irr;
188	sc->sc_trs->asp_imr = 0;
189	splx(s);
190
191	printf (": %s rev %d, lan %d scsi %d\n",
192	    asp_spus[sc->sc_trs->asp_spu].name, sc->sc_hw->asp_version,
193	    sc->sc_trs->asp_lan, sc->sc_trs->asp_scsi);
194
195	sc->sc_ic.gsc_type = gsc_asp;
196	sc->sc_ic.gsc_dv = sc;
197	sc->sc_ic.gsc_base = sc->sc_trs;
198
199	ga.ga_ca = *ca;	/* clone from us */
200	ga.ga_dp.dp_bc[0] = ga.ga_dp.dp_bc[1];
201	ga.ga_dp.dp_bc[1] = ga.ga_dp.dp_bc[2];
202	ga.ga_dp.dp_bc[2] = ga.ga_dp.dp_bc[3];
203	ga.ga_dp.dp_bc[3] = ga.ga_dp.dp_bc[4];
204	ga.ga_dp.dp_bc[4] = ga.ga_dp.dp_bc[5];
205	ga.ga_dp.dp_bc[5] = ga.ga_dp.dp_mod;
206	ga.ga_dp.dp_mod = 0;
207	ga.ga_hpamask = ASP_IOMASK;
208	ga.ga_name = "gsc";
209	ga.ga_ic = &sc->sc_ic;
210	config_found(self, &ga, gscprint);
211}
212