tc.c revision 1.1 1 /* $NetBSD: tc.c,v 1.1 1995/12/20 00:48:32 cgd Exp $ */
2
3 /*
4 * Copyright (c) 1994, 1995 Carnegie-Mellon University.
5 * All rights reserved.
6 *
7 * Author: Chris G. Demetriou
8 *
9 * Permission to use, copy, modify and distribute this software and
10 * its documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
14 *
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 *
19 * Carnegie Mellon requests users of this software to return to
20 *
21 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
25 *
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
28 */
29
30 #include <sys/param.h>
31 #include <sys/device.h>
32
33 #include <dev/tc/tcreg.h>
34 #include <dev/tc/tcvar.h>
35
36 struct tc_softc {
37 struct device sc_dv;
38
39 int sc_nslots;
40 struct tc_slotdesc *sc_slots;
41
42 void (*sc_intr_establish) __P((struct device *, void *,
43 tc_intrlevel_t, int (*)(void *), void *));
44 void (*sc_intr_disestablish) __P((struct device *, void *));
45 };
46
47 /* Definition of the driver for autoconfig. */
48 int tcmatch __P((struct device *, void *, void *));
49 void tcattach __P((struct device *, struct device *, void *));
50 struct cfdriver tccd =
51 { NULL, "tc", tcmatch, tcattach, DV_DULL, sizeof (struct tc_softc) };
52
53 int tcprint __P((void *, char *));
54 int tc_checkslot __P((tc_addr_t, char *));
55
56 int
57 tcmatch(parent, cfdata, aux)
58 struct device *parent;
59 void *cfdata;
60 void *aux;
61 {
62
63 return (1);
64 }
65
66 void
67 tcattach(parent, self, aux)
68 struct device *parent;
69 struct device *self;
70 void *aux;
71 {
72 struct tc_softc *sc = (struct tc_softc *)self;
73 struct tc_attach_args *tc = aux;
74 struct tcdev_attach_args tcdev;
75 const struct tc_builtin *builtin;
76 struct tc_slotdesc *slot;
77 tc_addr_t tcaddr;
78 int i;
79
80 printf("\n");
81
82 /*
83 * Save important CPU/chipset information.
84 */
85 sc->sc_nslots = tc->tca_nslots;
86 sc->sc_slots = tc->tca_slots;
87 sc->sc_intr_establish = tc->tca_intr_establish;
88 sc->sc_intr_disestablish = tc->tca_intr_disestablish;
89
90 /*
91 * Try to configure each built-in device
92 */
93 for (i = 0; i < tc->tca_nbuiltins; i++) {
94 builtin = &tc->tca_builtins[i];
95
96 /* sanity check! */
97 if (builtin->tcb_slot > sc->sc_nslots)
98 panic("tcattach: builtin %d slot > nslots", i);
99
100 /*
101 * Make sure device is really there, because some
102 * built-in devices are really optional.
103 */
104 tcaddr = sc->sc_slots[builtin->tcb_slot].tcs_addr +
105 builtin->tcb_offset;
106 if (tc_badaddr(tcaddr))
107 continue;
108
109 /*
110 * Set up the device attachment information.
111 */
112 strncpy(tcdev.tcda_modname, builtin->tcb_modname, TC_ROM_LLEN);
113 tcdev.tcda_modname[TC_ROM_LLEN] = '\0';
114 tcdev.tcda_slot = builtin->tcb_slot;
115 tcdev.tcda_offset = builtin->tcb_offset;
116 tcdev.tcda_addr = tcaddr;
117 tcdev.tcda_cookie = builtin->tcb_cookie;
118
119 /*
120 * Mark the slot as used, so we don't check it later.
121 */
122 sc->sc_slots[builtin->tcb_slot].tcs_used = 1;
123
124 /*
125 * Attach the device.
126 */
127 config_found(self, &tcdev, tcprint);
128 }
129
130 /*
131 * Try to configure each unused slot, last to first.
132 */
133 for (i = sc->sc_nslots - 1; i >= 0; i--) {
134 slot = &sc->sc_slots[i];
135
136 /* If already checked above, don't look again now. */
137 if (slot->tcs_used)
138 continue;
139
140 /*
141 * Make sure something is there, and find out what it is.
142 */
143 tcaddr = slot->tcs_addr;
144 if (tc_badaddr(tcaddr))
145 continue;
146 if (tc_checkslot(tcaddr, tcdev.tcda_modname) == 0)
147 continue;
148
149 /*
150 * Set up the rest of the attachment information.
151 */
152 tcdev.tcda_slot = i;
153 tcdev.tcda_offset = 0;
154 tcdev.tcda_addr = tcaddr;
155 tcdev.tcda_cookie = slot->tcs_cookie;
156
157 /*
158 * Mark the slot as used.
159 */
160 slot->tcs_used = 1;
161
162 /*
163 * Attach the device.
164 */
165 config_found(self, &tcdev, tcprint);
166 }
167 }
168
169 int
170 tcprint(aux, pnp)
171 void *aux;
172 char *pnp;
173 {
174 struct tcdev_attach_args *tcdev = aux;
175
176 if (pnp)
177 printf("%s at %s", tcdev->tcda_modname, pnp); /* XXX */
178 printf(" slot %d offset 0x%lx", tcdev->tcda_slot,
179 (long)tcdev->tcda_offset);
180 return (UNCONF);
181 }
182
183 int
184 tc_submatch(match, d)
185 struct cfdata *match;
186 struct tcdev_attach_args *d;
187 {
188
189 return (((match->tccf_slot == d->tcda_slot) ||
190 (match->tccf_slot == TCCF_SLOT_UNKNOWN)) &&
191 ((match->tccf_offset == d->tcda_offset) ||
192 (match->tccf_offset == TCCF_OFFSET_UNKNOWN)));
193 }
194
195
196 #define NTC_ROMOFFS 2
197 static tc_offset_t tc_slot_romoffs[NTC_ROMOFFS] = {
198 TC_SLOT_ROM,
199 TC_SLOT_PROTOROM,
200 };
201
202 int
203 tc_checkslot(slotbase, namep)
204 tc_addr_t slotbase;
205 char *namep;
206 {
207 struct tc_rommap *romp;
208 int i, j;
209
210 for (i = 0; i < NTC_ROMOFFS; i++) {
211 romp = (struct tc_rommap *)
212 (slotbase + tc_slot_romoffs[i]);
213
214 switch (romp->tcr_width.v) {
215 case 1:
216 case 2:
217 case 4:
218 break;
219
220 default:
221 continue;
222 }
223
224 if (romp->tcr_stride.v != 4)
225 continue;
226
227 for (j = 0; j < 4; j++)
228 if (romp->tcr_test[j+0*romp->tcr_stride.v] != 0x55 ||
229 romp->tcr_test[j+1*romp->tcr_stride.v] != 0x00 ||
230 romp->tcr_test[j+2*romp->tcr_stride.v] != 0xaa ||
231 romp->tcr_test[j+3*romp->tcr_stride.v] != 0xff)
232 continue;
233
234 for (j = 0; j < TC_ROM_LLEN; j++)
235 namep[j] = romp->tcr_modname[j].v;
236 namep[j] = '\0';
237 return (1);
238 }
239 return (0);
240 }
241
242 void
243 tc_intr_establish(dev, cookie, level, handler, arg)
244 struct device *dev;
245 void *cookie, *arg;
246 tc_intrlevel_t level;
247 int (*handler) __P((void *));
248 {
249 struct tc_softc *sc = (struct tc_softc *)dev;
250
251 (*sc->sc_intr_establish)(sc->sc_dv.dv_parent, cookie, level,
252 handler, arg);
253 }
254
255 void
256 tc_intr_disestablish(dev, cookie)
257 struct device *dev;
258 void *cookie;
259 {
260 struct tc_softc *sc = (struct tc_softc *)dev;
261
262 (*sc->sc_intr_disestablish)(sc->sc_dv.dv_parent, cookie);
263 }
264