sbus.c revision 1.5 1 1.5 deraadt /* $NetBSD: sbus.c,v 1.5 1994/11/23 07:02:19 deraadt Exp $ */
2 1.4 deraadt
3 1.1 deraadt /*
4 1.1 deraadt * Copyright (c) 1992, 1993
5 1.1 deraadt * The Regents of the University of California. All rights reserved.
6 1.1 deraadt *
7 1.1 deraadt * This software was developed by the Computer Systems Engineering group
8 1.1 deraadt * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 1.1 deraadt * contributed to Berkeley.
10 1.1 deraadt *
11 1.1 deraadt * All advertising materials mentioning features or use of this software
12 1.1 deraadt * must display the following acknowledgement:
13 1.1 deraadt * This product includes software developed by the University of
14 1.1 deraadt * California, Lawrence Berkeley Laboratory.
15 1.1 deraadt *
16 1.1 deraadt * Redistribution and use in source and binary forms, with or without
17 1.1 deraadt * modification, are permitted provided that the following conditions
18 1.1 deraadt * are met:
19 1.1 deraadt * 1. Redistributions of source code must retain the above copyright
20 1.1 deraadt * notice, this list of conditions and the following disclaimer.
21 1.1 deraadt * 2. Redistributions in binary form must reproduce the above copyright
22 1.1 deraadt * notice, this list of conditions and the following disclaimer in the
23 1.1 deraadt * documentation and/or other materials provided with the distribution.
24 1.1 deraadt * 3. All advertising materials mentioning features or use of this software
25 1.1 deraadt * must display the following acknowledgement:
26 1.1 deraadt * This product includes software developed by the University of
27 1.1 deraadt * California, Berkeley and its contributors.
28 1.1 deraadt * 4. Neither the name of the University nor the names of its contributors
29 1.1 deraadt * may be used to endorse or promote products derived from this software
30 1.1 deraadt * without specific prior written permission.
31 1.1 deraadt *
32 1.1 deraadt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 1.1 deraadt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 1.1 deraadt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 1.1 deraadt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 1.1 deraadt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.1 deraadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.1 deraadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.1 deraadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 1.1 deraadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 1.1 deraadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 1.1 deraadt * SUCH DAMAGE.
43 1.1 deraadt *
44 1.1 deraadt * @(#)sbus.c 8.1 (Berkeley) 6/11/93
45 1.1 deraadt */
46 1.1 deraadt
47 1.1 deraadt /*
48 1.1 deraadt * Sbus stuff.
49 1.1 deraadt */
50 1.1 deraadt
51 1.1 deraadt #include <sys/param.h>
52 1.1 deraadt #include <sys/device.h>
53 1.1 deraadt
54 1.1 deraadt #include <machine/autoconf.h>
55 1.1 deraadt
56 1.2 deraadt #include <sparc/dev/sbusreg.h>
57 1.2 deraadt #include <sparc/dev/sbusvar.h>
58 1.1 deraadt
59 1.1 deraadt /* autoconfiguration driver */
60 1.1 deraadt void sbus_attach __P((struct device *, struct device *, void *));
61 1.5 deraadt int sbus_match __P((struct device *, void *, void *));
62 1.2 deraadt struct cfdriver sbuscd = {
63 1.3 deraadt NULL, "sbus", sbus_match, sbus_attach,
64 1.2 deraadt DV_DULL, sizeof(struct sbus_softc)
65 1.2 deraadt };
66 1.1 deraadt
67 1.1 deraadt /*
68 1.1 deraadt * Print the location of some sbus-attached device (called just
69 1.1 deraadt * before attaching that device). If `sbus' is not NULL, the
70 1.1 deraadt * device was found but not configured; print the sbus as well.
71 1.1 deraadt * Return UNCONF (config_find ignores this if the device was configured).
72 1.1 deraadt */
73 1.1 deraadt int
74 1.1 deraadt sbus_print(args, sbus)
75 1.1 deraadt void *args;
76 1.1 deraadt char *sbus;
77 1.1 deraadt {
78 1.2 deraadt register struct confargs *ca = args;
79 1.1 deraadt
80 1.1 deraadt if (sbus)
81 1.2 deraadt printf("%s at %s", ca->ca_ra.ra_name, sbus);
82 1.2 deraadt printf(" slot %d offset 0x%x", ca->ca_slot, ca->ca_offset);
83 1.1 deraadt return (UNCONF);
84 1.1 deraadt }
85 1.1 deraadt
86 1.3 deraadt int
87 1.5 deraadt sbus_match(parent, vcf, aux)
88 1.3 deraadt struct device *parent;
89 1.5 deraadt void *vcf, *aux;
90 1.3 deraadt {
91 1.5 deraadt struct cfdata *cf = vcf;
92 1.3 deraadt register struct confargs *ca = aux;
93 1.3 deraadt register struct romaux *ra = &ca->ca_ra;
94 1.3 deraadt
95 1.3 deraadt if (cputyp==CPU_SUN4)
96 1.3 deraadt return (0);
97 1.3 deraadt return (strcmp(cf->cf_driver->cd_name, ra->ra_name) == 0);
98 1.3 deraadt }
99 1.3 deraadt
100 1.1 deraadt /*
101 1.1 deraadt * Attach an Sbus.
102 1.1 deraadt */
103 1.1 deraadt void
104 1.1 deraadt sbus_attach(parent, self, aux)
105 1.1 deraadt struct device *parent;
106 1.1 deraadt struct device *self;
107 1.1 deraadt void *aux;
108 1.1 deraadt {
109 1.1 deraadt register struct sbus_softc *sc = (struct sbus_softc *)self;
110 1.2 deraadt struct confargs *ca = aux;
111 1.2 deraadt register struct romaux *ra = &ca->ca_ra;
112 1.1 deraadt register int base, node, slot;
113 1.1 deraadt register char *name;
114 1.2 deraadt struct confargs oca;
115 1.1 deraadt
116 1.1 deraadt /*
117 1.1 deraadt * XXX there is only one Sbus, for now -- do not know how to
118 1.1 deraadt * address children on others
119 1.1 deraadt */
120 1.1 deraadt if (sc->sc_dev.dv_unit > 0) {
121 1.1 deraadt printf(" unsupported\n");
122 1.1 deraadt return;
123 1.1 deraadt }
124 1.1 deraadt
125 1.1 deraadt /*
126 1.1 deraadt * Record clock frequency for synchronous SCSI.
127 1.1 deraadt * IS THIS THE CORRECT DEFAULT??
128 1.1 deraadt */
129 1.1 deraadt node = ra->ra_node;
130 1.1 deraadt sc->sc_clockfreq = getpropint(node, "clock-frequency", 25*1000*1000);
131 1.1 deraadt printf(": clock = %s MHz\n", clockfreq(sc->sc_clockfreq));
132 1.1 deraadt
133 1.1 deraadt if (ra->ra_bp != NULL && strcmp(ra->ra_bp->name, "sbus") == 0)
134 1.2 deraadt oca.ca_ra.ra_bp = ra->ra_bp + 1;
135 1.1 deraadt else
136 1.2 deraadt oca.ca_ra.ra_bp = NULL;
137 1.1 deraadt
138 1.1 deraadt /*
139 1.1 deraadt * Loop through ROM children, fixing any relative addresses
140 1.1 deraadt * and then configuring each device.
141 1.1 deraadt */
142 1.1 deraadt for (node = firstchild(node); node; node = nextsibling(node)) {
143 1.1 deraadt name = getpropstring(node, "name");
144 1.2 deraadt if (!romprop(&oca.ca_ra, name, node))
145 1.1 deraadt continue;
146 1.2 deraadt base = (int)oca.ca_ra.ra_paddr;
147 1.1 deraadt if (SBUS_ABS(base)) {
148 1.2 deraadt oca.ca_slot = SBUS_ABS_TO_SLOT(base);
149 1.2 deraadt oca.ca_offset = SBUS_ABS_TO_OFFSET(base);
150 1.1 deraadt } else {
151 1.2 deraadt oca.ca_slot = slot = oca.ca_ra.ra_iospace;
152 1.2 deraadt oca.ca_offset = base;
153 1.2 deraadt oca.ca_ra.ra_paddr = (void *)SBUS_ADDR(slot, base);
154 1.1 deraadt }
155 1.2 deraadt oca.ca_bustype = BUS_SBUS;
156 1.2 deraadt (void) config_found(&sc->sc_dev, (void *)&oca, sbus_print);
157 1.1 deraadt }
158 1.1 deraadt }
159 1.1 deraadt
160 1.1 deraadt /*
161 1.1 deraadt * Each attached device calls sbus_establish after it initializes
162 1.1 deraadt * its sbusdev portion.
163 1.1 deraadt */
164 1.1 deraadt void
165 1.1 deraadt sbus_establish(sd, dev)
166 1.1 deraadt register struct sbusdev *sd;
167 1.1 deraadt register struct device *dev;
168 1.1 deraadt {
169 1.1 deraadt register struct sbus_softc *sc = (struct sbus_softc *)dev->dv_parent;
170 1.1 deraadt
171 1.1 deraadt sd->sd_dev = dev;
172 1.1 deraadt sd->sd_bchain = sc->sc_sbdev;
173 1.1 deraadt sc->sc_sbdev = sd;
174 1.1 deraadt }
175 1.1 deraadt
176 1.1 deraadt /*
177 1.1 deraadt * Reset the given sbus. (???)
178 1.1 deraadt */
179 1.1 deraadt void
180 1.1 deraadt sbusreset(sbus)
181 1.1 deraadt int sbus;
182 1.1 deraadt {
183 1.1 deraadt register struct sbusdev *sd;
184 1.1 deraadt struct sbus_softc *sc = sbuscd.cd_devs[sbus];
185 1.1 deraadt struct device *dev;
186 1.1 deraadt
187 1.1 deraadt printf("reset %s:", sc->sc_dev.dv_xname);
188 1.1 deraadt for (sd = sc->sc_sbdev; sd != NULL; sd = sd->sd_bchain) {
189 1.1 deraadt if (sd->sd_reset) {
190 1.1 deraadt dev = sd->sd_dev;
191 1.1 deraadt (*sd->sd_reset)(dev);
192 1.1 deraadt printf(" %s", dev->dv_xname);
193 1.1 deraadt }
194 1.1 deraadt }
195 1.1 deraadt }
196