nubus.c revision 1.28 1 1.26 christos /* $NetBSD: nubus.c,v 1.28 1996/12/16 16:17:10 scottr Exp $ */
2 1.8 cgd
3 1.11 briggs /*
4 1.11 briggs * Copyright (c) 1995 Allen Briggs. All rights reserved.
5 1.1 briggs *
6 1.1 briggs * Redistribution and use in source and binary forms, with or without
7 1.1 briggs * modification, are permitted provided that the following conditions
8 1.1 briggs * are met:
9 1.1 briggs * 1. Redistributions of source code must retain the above copyright
10 1.1 briggs * notice, this list of conditions and the following disclaimer.
11 1.1 briggs * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 briggs * notice, this list of conditions and the following disclaimer in the
13 1.1 briggs * documentation and/or other materials provided with the distribution.
14 1.1 briggs * 3. All advertising materials mentioning features or use of this software
15 1.1 briggs * must display the following acknowledgement:
16 1.11 briggs * This product includes software developed by Allen Briggs.
17 1.11 briggs * 4. The name of the author may not be used to endorse or promote products
18 1.11 briggs * derived from this software without specific prior written permission.
19 1.1 briggs *
20 1.11 briggs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.1 briggs * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.1 briggs * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.11 briggs * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.1 briggs * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.1 briggs * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.1 briggs * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.1 briggs * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.11 briggs * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.11 briggs * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1 briggs */
31 1.1 briggs
32 1.4 briggs #include <sys/param.h>
33 1.4 briggs #include <sys/systm.h>
34 1.10 briggs #include <sys/device.h>
35 1.10 briggs
36 1.19 briggs #include <machine/autoconf.h>
37 1.4 briggs #include <machine/cpu.h>
38 1.1 briggs
39 1.12 briggs #include <vm/vm.h>
40 1.12 briggs
41 1.1 briggs #include "nubus.h"
42 1.1 briggs
43 1.23 scottr #ifdef DEBUG
44 1.12 briggs static int nubus_debug = 0x01;
45 1.12 briggs #define NDB_PROBE 0x1
46 1.12 briggs #define NDB_FOLLOW 0x2
47 1.12 briggs #define NDB_ARITH 0x4
48 1.12 briggs #endif
49 1.12 briggs
50 1.28 scottr static int nubus_print __P((void *, const char *));
51 1.28 scottr static int nubus_match __P((struct device *, struct cfdata *, void *));
52 1.28 scottr static void nubus_attach __P((struct device *, struct device *, void *));
53 1.28 scottr int nubus_video_resource __P((int));
54 1.11 briggs
55 1.11 briggs static int probe_slot __P((int slot, nubus_slot *fmt));
56 1.11 briggs static u_long IncPtr __P((nubus_slot *fmt, u_long base, long amt));
57 1.11 briggs static u_long nubus_calc_CRC __P((nubus_slot *fmt));
58 1.11 briggs static u_char GetByte __P((nubus_slot *fmt, u_long ptr));
59 1.17 briggs #ifdef notyet
60 1.17 briggs /* unused */ static u_short GetWord __P((nubus_slot *fmt, u_long ptr));
61 1.17 briggs #endif
62 1.11 briggs static u_long GetLong __P((nubus_slot *fmt, u_long ptr));
63 1.18 scottr
64 1.16 thorpej struct cfattach nubus_ca = {
65 1.28 scottr sizeof(struct nubus_softc), nubus_match, nubus_attach
66 1.16 thorpej };
67 1.16 thorpej
68 1.16 thorpej struct cfdriver nubus_cd = {
69 1.28 scottr NULL, "nubus", DV_DULL,
70 1.11 briggs };
71 1.1 briggs
72 1.19 briggs static int
73 1.28 scottr nubus_match(parent, cf, aux)
74 1.19 briggs struct device *parent;
75 1.28 scottr struct cfdata *cf;
76 1.28 scottr void *aux;
77 1.19 briggs {
78 1.19 briggs struct confargs *ca = aux;
79 1.19 briggs
80 1.19 briggs if (ca->ca_bustype != BUS_NUBUS)
81 1.28 scottr return 0;
82 1.28 scottr return 1;
83 1.19 briggs }
84 1.19 briggs
85 1.11 briggs static void
86 1.28 scottr nubus_attach(parent, self, aux)
87 1.28 scottr struct device *parent, *self;
88 1.28 scottr void *aux;
89 1.11 briggs {
90 1.28 scottr struct nubus_attach_args na_args;
91 1.28 scottr nubus_slot fmtblock;
92 1.28 scottr nubus_dir dir;
93 1.28 scottr nubus_dirent dirent;
94 1.28 scottr nubus_type slottype;
95 1.28 scottr int i, rsrcid;
96 1.1 briggs
97 1.26 christos printf("\n");
98 1.1 briggs
99 1.19 briggs for (i = NUBUS_MIN_SLOT; i <= NUBUS_MAX_SLOT; i++) {
100 1.28 scottr if (probe_slot(i, &fmtblock) <= 0)
101 1.28 scottr continue;
102 1.28 scottr
103 1.28 scottr if ((rsrcid = nubus_video_resource(i)) == (-1))
104 1.28 scottr rsrcid = 0x80;
105 1.28 scottr
106 1.28 scottr nubus_get_main_dir(&fmtblock, &dir);
107 1.28 scottr
108 1.28 scottr if (nubus_find_rsrc(&fmtblock, &dir, rsrcid, &dirent) <= 0)
109 1.28 scottr continue;
110 1.28 scottr
111 1.28 scottr nubus_get_dir_from_rsrc(&fmtblock, &dirent, &dir);
112 1.28 scottr
113 1.28 scottr if (nubus_find_rsrc(&fmtblock, &dir, NUBUS_RSRC_TYPE,
114 1.28 scottr &dirent) <= 0)
115 1.28 scottr continue;
116 1.28 scottr
117 1.28 scottr if (nubus_get_ind_data(&fmtblock, &dirent,
118 1.28 scottr (caddr_t) &slottype, sizeof(nubus_type)) <= 0)
119 1.28 scottr continue;
120 1.28 scottr
121 1.28 scottr na_args.slot = i;
122 1.28 scottr na_args.rsrcid = rsrcid;
123 1.28 scottr na_args.category = slottype.category;
124 1.28 scottr na_args.type = slottype.type;
125 1.28 scottr na_args.drsw = slottype.drsw;
126 1.28 scottr na_args.drhw = slottype.drhw;
127 1.28 scottr na_args.fmt = &fmtblock;
128 1.28 scottr
129 1.28 scottr config_found(self, &na_args, nubus_print);
130 1.12 briggs }
131 1.1 briggs }
132 1.1 briggs
133 1.10 briggs static int
134 1.28 scottr nubus_print(aux, name)
135 1.28 scottr void *aux;
136 1.28 scottr const char *name;
137 1.11 briggs {
138 1.28 scottr struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
139 1.1 briggs
140 1.11 briggs if (name) {
141 1.28 scottr printf("%s: slot %x: %s ", name, na->fmt->slot,
142 1.28 scottr nubus_get_card_name(na->fmt));
143 1.26 christos printf("(Vendor: %s, ",
144 1.28 scottr nubus_get_vendor(na->fmt, NUBUS_RSRC_VEND_ID));
145 1.28 scottr printf("Part: %s)",
146 1.28 scottr nubus_get_vendor(na->fmt, NUBUS_RSRC_VEND_PART));
147 1.1 briggs }
148 1.11 briggs return (UNCONF);
149 1.28 scottr }
150 1.28 scottr
151 1.28 scottr int
152 1.28 scottr nubus_video_resource(slot)
153 1.28 scottr int slot;
154 1.28 scottr {
155 1.28 scottr extern u_int16_t mac68k_vrsrc_vec[];
156 1.28 scottr int i;
157 1.28 scottr
158 1.28 scottr for (i = 0 ; i < 6 ; i++)
159 1.28 scottr if ((mac68k_vrsrc_vec[i] & 0xff) == slot)
160 1.28 scottr return ((mac68k_vrsrc_vec[i] >> 8) & 0xff);
161 1.28 scottr return (-1);
162 1.1 briggs }
163 1.1 briggs
164 1.11 briggs /*
165 1.11 briggs * Probe a given nubus slot. If a card is there and we can get the
166 1.11 briggs * format block from it's clutching decl. ROMs, fill the format block
167 1.11 briggs * and return non-zero. If we can't find a card there with a valid
168 1.11 briggs * decl. ROM, return 0.
169 1.11 briggs *
170 1.11 briggs * First, we check to see if we can access the memory at the tail
171 1.11 briggs * end of the slot. If so, then we check for a bytelanes byte. We
172 1.11 briggs * could probably just return a failure status if we bus error on
173 1.11 briggs * the first try, but there really is little reason not to go ahead
174 1.11 briggs * and check the other three locations in case there's a wierd card
175 1.11 briggs * out there.
176 1.11 briggs *
177 1.11 briggs * Checking for a card involves locating the "bytelanes" byte which
178 1.11 briggs * tells us how to interpret the declaration ROM's data. The format
179 1.11 briggs * block is at the top of the card's standard memory space and the
180 1.11 briggs * bytelanes byte is at the end of that block.
181 1.11 briggs *
182 1.11 briggs * After some inspection of the bytelanes byte, it appears that it
183 1.11 briggs * takes the form 0xXY where Y is a bitmask of the bytelanes in use
184 1.11 briggs * and X is a bitmask of the lanes to ignore. Hence, (X ^ Y) == 0
185 1.11 briggs * and (less obviously), Y will have the upper N bits clear if it is
186 1.11 briggs * found N bytes from the last possible location. Both that and
187 1.11 briggs * the exclusive-or check are made.
188 1.11 briggs *
189 1.11 briggs * If a valid
190 1.11 briggs */
191 1.11 briggs static u_char nbits[]={0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};
192 1.11 briggs static int
193 1.11 briggs probe_slot(slot, fmt)
194 1.11 briggs int slot;
195 1.11 briggs nubus_slot *fmt;
196 1.1 briggs {
197 1.11 briggs caddr_t rom_probe;
198 1.19 briggs vm_offset_t hdr;
199 1.23 scottr #ifdef DEBUG
200 1.23 scottr vm_offset_t pa;
201 1.23 scottr #endif
202 1.19 briggs u_int data;
203 1.11 briggs int hdr_size, i;
204 1.10 briggs
205 1.11 briggs fmt->bytelanes = 0;
206 1.11 briggs fmt->slot = (u_long)slot;
207 1.10 briggs
208 1.19 briggs rom_probe = (caddr_t) (NUBUS_SLOT_TO_PADDR(fmt->slot) + NBMEMSIZE);
209 1.10 briggs
210 1.12 briggs #ifdef DEBUG
211 1.12 briggs if (nubus_debug & NDB_PROBE) {
212 1.23 scottr pa = pmap_extract(pmap_kernel(), (vm_offset_t) rom_probe - 1);
213 1.27 scottr printf("probing slot %d, first probe at 0x%p (PA 0x%lx).\n",
214 1.23 scottr slot, rom_probe - 1, pa);
215 1.12 briggs }
216 1.12 briggs #endif
217 1.12 briggs
218 1.11 briggs for (i = 4; i && (fmt->bytelanes == 0); i--) {
219 1.10 briggs
220 1.11 briggs rom_probe--;
221 1.10 briggs
222 1.19 briggs data = bus_peek(BUS_NUBUS, (vm_offset_t) rom_probe, 1);
223 1.19 briggs if (data == -1)
224 1.11 briggs continue;
225 1.10 briggs
226 1.19 briggs if (data == 0)
227 1.11 briggs continue;
228 1.1 briggs
229 1.11 briggs if ( ((((data & 0xf0) >> 4) ^ (data & 0x0f)) == 0x0f)
230 1.11 briggs && ((data & 0x0f) < (1 << i)) ) {
231 1.11 briggs fmt->bytelanes = data;
232 1.11 briggs fmt->step = nbits[(data & 0x0f)];
233 1.11 briggs }
234 1.1 briggs }
235 1.11 briggs #ifdef DEBUG
236 1.12 briggs if (nubus_debug & NDB_PROBE)
237 1.12 briggs if (fmt->bytelanes == 0)
238 1.26 christos printf("bytelanes not found for slot 0x%x.\n", slot);
239 1.11 briggs #endif
240 1.11 briggs
241 1.11 briggs if (fmt->bytelanes == 0)
242 1.11 briggs return 0;
243 1.11 briggs
244 1.11 briggs #ifdef DEBUG
245 1.12 briggs if (nubus_debug & NDB_PROBE)
246 1.26 christos printf("bytelanes of 0x%x found for slot 0x%x.\n",
247 1.20 briggs fmt->bytelanes, slot);
248 1.11 briggs #endif
249 1.1 briggs
250 1.11 briggs hdr_size = 20;
251 1.10 briggs
252 1.11 briggs /*
253 1.11 briggs * Go ahead and attempt to load format header.
254 1.11 briggs * First, we need to find the first byte beyond memory that
255 1.11 briggs * would be valid. This is necessary for NUBUS_ROM_offset()
256 1.11 briggs * to work.
257 1.11 briggs */
258 1.19 briggs hdr = (vm_offset_t)
259 1.19 briggs bus_mapin(BUS_NUBUS,NUBUS_SLOT_TO_PADDR(fmt->slot),NBMEMSIZE);
260 1.19 briggs if (hdr == NULL) {
261 1.26 christos printf("Failed to map %d bytes for NuBUS slot %d probe. ",
262 1.22 briggs NBMEMSIZE, fmt->slot);
263 1.26 christos printf("Physical slot address %x\n",
264 1.22 briggs (unsigned int) NUBUS_SLOT_TO_PADDR(fmt->slot));
265 1.19 briggs }
266 1.19 briggs fmt->virtual_base = hdr;
267 1.19 briggs hdr += NBMEMSIZE;
268 1.19 briggs
269 1.11 briggs i = 0x10 | (fmt->bytelanes & 0x0f);
270 1.11 briggs while ((i & 1) == 0) {
271 1.11 briggs hdr++;
272 1.11 briggs i >>= 1;
273 1.11 briggs }
274 1.11 briggs fmt->top = hdr;
275 1.11 briggs hdr = IncPtr(fmt, hdr, -hdr_size);
276 1.11 briggs #ifdef DEBUG
277 1.12 briggs if (nubus_debug & NDB_PROBE)
278 1.27 scottr printf("fmt->top is 0x%lx, that minus 0x%x puts us at 0x%lx.\n",
279 1.12 briggs fmt->top, hdr_size, hdr);
280 1.11 briggs #if 0
281 1.11 briggs for (i=1 ; i < 8 ; i++) {
282 1.26 christos printf("0x%x - 0x%x = 0x%x, + 0x%x = 0x%x.\n",
283 1.11 briggs hdr, i, IncPtr(fmt, hdr, -i),
284 1.11 briggs i, IncPtr(fmt, hdr, i));
285 1.11 briggs }
286 1.11 briggs #endif
287 1.11 briggs #endif
288 1.11 briggs
289 1.11 briggs fmt->directory_offset = 0xff000000 | GetLong(fmt, hdr);
290 1.11 briggs hdr = IncPtr(fmt, hdr, 4);
291 1.11 briggs fmt->length = GetLong(fmt, hdr);
292 1.11 briggs hdr = IncPtr(fmt, hdr, 4);
293 1.11 briggs fmt->crc = GetLong(fmt, hdr);
294 1.11 briggs hdr = IncPtr(fmt, hdr, 4);
295 1.11 briggs fmt->revision_level = GetByte(fmt, hdr);
296 1.11 briggs hdr = IncPtr(fmt, hdr, 1);
297 1.11 briggs fmt->format = GetByte(fmt, hdr);
298 1.11 briggs hdr = IncPtr(fmt, hdr, 1);
299 1.11 briggs fmt->test_pattern = GetLong(fmt, hdr);
300 1.11 briggs
301 1.23 scottr #ifdef DEBUG
302 1.12 briggs if (nubus_debug & NDB_PROBE) {
303 1.26 christos printf("Directory offset 0x%x\t", fmt->directory_offset);
304 1.26 christos printf("Length 0x%x\t", fmt->length);
305 1.26 christos printf("CRC 0x%x\n", fmt->crc);
306 1.26 christos printf("Revision level 0x%x\t", fmt->revision_level);
307 1.26 christos printf("Format 0x%x\t", fmt->format);
308 1.26 christos printf("Test Pattern 0x%x\n", fmt->test_pattern);
309 1.12 briggs }
310 1.11 briggs #endif
311 1.11 briggs
312 1.12 briggs if ((fmt->directory_offset & 0x00ff0000) == 0) {
313 1.26 christos printf("Invalid looking directory offset (0x%x)!\n",
314 1.12 briggs fmt->directory_offset);
315 1.12 briggs return 0;
316 1.12 briggs }
317 1.11 briggs if (fmt->test_pattern != NUBUS_ROM_TEST_PATTERN) {
318 1.26 christos printf("Nubus--test pattern invalid:\n");
319 1.26 christos printf(" slot 0x%x, bytelanes 0x%x?\n",
320 1.11 briggs fmt->slot, fmt->bytelanes);
321 1.26 christos printf(" read test 0x%x, compare with 0x%x.\n",
322 1.11 briggs fmt->test_pattern, NUBUS_ROM_TEST_PATTERN);
323 1.11 briggs return 0;
324 1.11 briggs }
325 1.11 briggs
326 1.11 briggs /* Perform CRC */
327 1.11 briggs if (fmt->crc != nubus_calc_CRC(fmt)) {
328 1.26 christos printf("Nubus--crc check failed, slot 0x%x.\n",
329 1.11 briggs fmt->slot);
330 1.11 briggs return 0;
331 1.1 briggs }
332 1.10 briggs
333 1.11 briggs return 1;
334 1.1 briggs }
335 1.1 briggs
336 1.11 briggs /*
337 1.11 briggs * Compute byte offset on card, taking into account bytelanes.
338 1.11 briggs * Base must be on a valid bytelane for this function to work.
339 1.11 briggs * Return the new address.
340 1.11 briggs *
341 1.11 briggs * XXX -- There has GOT to be a better way to do this.
342 1.11 briggs */
343 1.11 briggs static u_long
344 1.11 briggs IncPtr(fmt, base, amt)
345 1.11 briggs nubus_slot *fmt;
346 1.11 briggs u_long base;
347 1.11 briggs long amt;
348 1.11 briggs {
349 1.11 briggs u_char b, t;
350 1.11 briggs
351 1.11 briggs if (!amt)
352 1.11 briggs return base;
353 1.11 briggs
354 1.11 briggs if (amt < 0) {
355 1.11 briggs amt = -amt;
356 1.11 briggs b = fmt->bytelanes;
357 1.11 briggs t = (b << 4);
358 1.11 briggs b <<= (3 - (base & 0x3));
359 1.11 briggs while (amt) {
360 1.11 briggs b <<= 1;
361 1.11 briggs if (b == t)
362 1.11 briggs b = fmt->bytelanes;
363 1.11 briggs if (b & 0x08)
364 1.11 briggs amt--;
365 1.11 briggs base--;
366 1.11 briggs }
367 1.11 briggs return base;
368 1.11 briggs }
369 1.10 briggs
370 1.11 briggs t = (fmt->bytelanes & 0xf) | 0x10;
371 1.11 briggs b = t >> (base & 0x3);
372 1.11 briggs while (amt) {
373 1.11 briggs b >>= 1;
374 1.11 briggs if (b == 1)
375 1.11 briggs b = t;
376 1.11 briggs if (b & 1)
377 1.11 briggs amt--;
378 1.11 briggs base++;
379 1.11 briggs }
380 1.11 briggs
381 1.11 briggs return base;
382 1.11 briggs }
383 1.11 briggs
384 1.11 briggs static u_long
385 1.11 briggs nubus_calc_CRC(fmt)
386 1.11 briggs nubus_slot *fmt;
387 1.11 briggs {
388 1.11 briggs #if 0
389 1.11 briggs u_long base, ptr, crc_loc, sum;
390 1.11 briggs int i;
391 1.11 briggs
392 1.11 briggs base = fmt->top;
393 1.11 briggs crc_loc = NUBUS_ROM_offset(fmt, base, -12);
394 1.11 briggs ptr = NUBUS_ROM_offset(fmt, base, -fmt->length);
395 1.11 briggs
396 1.11 briggs sum = 0;
397 1.11 briggs while (ptr < base)
398 1.11 briggs roll #1, sum
399 1.11 briggs if (ptr == crc_loc) {
400 1.11 briggs roll #3, sum
401 1.11 briggs ptr = IncPtr(fmt, ptr, 3);
402 1.11 briggs } else {
403 1.11 briggs sum += GetByte(fmt, ptr);
404 1.11 briggs }
405 1.11 briggs ptr = IncPtr(fmt, ptr, 1);
406 1.1 briggs }
407 1.10 briggs
408 1.11 briggs return sum;
409 1.11 briggs #endif
410 1.11 briggs return fmt->crc;
411 1.1 briggs }
412 1.1 briggs
413 1.11 briggs static u_char
414 1.11 briggs GetByte(fmt, ptr)
415 1.11 briggs nubus_slot *fmt;
416 1.11 briggs u_long ptr;
417 1.1 briggs {
418 1.11 briggs return *(caddr_t)ptr;
419 1.1 briggs }
420 1.1 briggs
421 1.17 briggs #ifdef notyet
422 1.17 briggs /* Nothing uses this, yet */
423 1.11 briggs static u_short
424 1.11 briggs GetWord(fmt, ptr)
425 1.11 briggs nubus_slot *fmt;
426 1.11 briggs u_long ptr;
427 1.1 briggs {
428 1.11 briggs u_short s;
429 1.10 briggs
430 1.11 briggs s = (GetByte(fmt, ptr) << 8);
431 1.11 briggs ptr = IncPtr(fmt, ptr, 1);
432 1.11 briggs s |= GetByte(fmt, ptr);
433 1.11 briggs return s;
434 1.11 briggs }
435 1.17 briggs #endif
436 1.1 briggs
437 1.11 briggs static u_long
438 1.11 briggs GetLong(fmt, ptr)
439 1.11 briggs nubus_slot *fmt;
440 1.11 briggs u_long ptr;
441 1.11 briggs {
442 1.11 briggs register u_long l;
443 1.11 briggs register int i;
444 1.10 briggs
445 1.11 briggs l = 0;
446 1.11 briggs for ( i = 0; i < 4; i++) {
447 1.11 briggs l = (l << 8) | GetByte(fmt, ptr);
448 1.11 briggs ptr = IncPtr(fmt, ptr, 1);
449 1.11 briggs }
450 1.11 briggs return l;
451 1.11 briggs }
452 1.10 briggs
453 1.11 briggs void
454 1.11 briggs nubus_get_main_dir(slot, dir_return)
455 1.11 briggs nubus_slot *slot;
456 1.11 briggs nubus_dir *dir_return;
457 1.11 briggs {
458 1.23 scottr #ifdef DEBUG
459 1.12 briggs if (nubus_debug & NDB_FOLLOW)
460 1.26 christos printf("nubus_get_main_dir(0x%x, 0x%x)\n",
461 1.12 briggs (u_int) slot, (u_int) dir_return);
462 1.12 briggs #endif
463 1.11 briggs dir_return->dirbase = IncPtr(slot, slot->top,
464 1.11 briggs slot->directory_offset - 20);
465 1.11 briggs dir_return->curr_ent = dir_return->dirbase;
466 1.1 briggs }
467 1.1 briggs
468 1.11 briggs int
469 1.11 briggs nubus_find_rsrc(slot, dir, rsrcid, dirent_return)
470 1.11 briggs nubus_slot *slot;
471 1.11 briggs nubus_dir *dir;
472 1.11 briggs u_int8_t rsrcid;
473 1.11 briggs nubus_dirent *dirent_return;
474 1.1 briggs {
475 1.11 briggs u_long entry;
476 1.11 briggs u_char byte;
477 1.10 briggs
478 1.23 scottr #ifdef DEBUG
479 1.12 briggs if (nubus_debug & NDB_FOLLOW)
480 1.26 christos printf("nubus_find_rsrc(0x%x, 0x%x, 0x%x, 0x%x)\n",
481 1.12 briggs (u_int) slot, (u_int) dir, (u_int) rsrcid,
482 1.12 briggs (u_int) dirent_return);
483 1.11 briggs #endif
484 1.12 briggs if (slot->test_pattern != NUBUS_ROM_TEST_PATTERN)
485 1.12 briggs return -1;
486 1.12 briggs
487 1.12 briggs entry = dir->curr_ent;
488 1.11 briggs do {
489 1.11 briggs byte = GetByte(slot, entry);
490 1.23 scottr #ifdef DEBUG
491 1.12 briggs if (nubus_debug & NDB_FOLLOW)
492 1.26 christos printf("\tFound rsrc 0x%x.\n", byte);
493 1.11 briggs #endif
494 1.11 briggs if (byte == rsrcid) {
495 1.11 briggs dirent_return->myloc = entry;
496 1.11 briggs dirent_return->rsrc_id = rsrcid;
497 1.11 briggs entry = GetLong(slot, entry);
498 1.11 briggs dirent_return->offset = (entry & 0x00ffffff);
499 1.11 briggs return 1;
500 1.11 briggs }
501 1.11 briggs if (byte == 0xff) {
502 1.11 briggs entry = dir->dirbase;
503 1.11 briggs } else {
504 1.11 briggs entry = IncPtr(slot, entry, 4);
505 1.11 briggs }
506 1.11 briggs } while (entry != (u_long) dir->curr_ent);
507 1.11 briggs return 0;
508 1.1 briggs }
509 1.1 briggs
510 1.11 briggs void
511 1.11 briggs nubus_get_dir_from_rsrc(slot, dirent, dir_return)
512 1.11 briggs nubus_slot *slot;
513 1.11 briggs nubus_dirent *dirent;
514 1.11 briggs nubus_dir *dir_return;
515 1.1 briggs {
516 1.11 briggs u_long loc;
517 1.10 briggs
518 1.23 scottr #ifdef DEBUG
519 1.12 briggs if (nubus_debug & NDB_FOLLOW)
520 1.26 christos printf("nubus_get_dir_from_rsrc(0x%x, 0x%x, 0x%x).\n",
521 1.12 briggs (u_int) slot, (u_int) dirent, (u_int) dir_return);
522 1.12 briggs #endif
523 1.11 briggs if ((loc = dirent->offset) & 0x800000) {
524 1.11 briggs loc |= 0xff000000;
525 1.1 briggs }
526 1.11 briggs dir_return->dirbase = IncPtr(slot, dirent->myloc, loc);
527 1.11 briggs dir_return->curr_ent = dir_return->dirbase;
528 1.1 briggs }
529 1.1 briggs
530 1.11 briggs int
531 1.11 briggs nubus_get_ind_data(slot, dirent, data_return, nbytes)
532 1.11 briggs nubus_slot *slot;
533 1.11 briggs nubus_dirent *dirent;
534 1.11 briggs caddr_t data_return;
535 1.11 briggs int nbytes;
536 1.11 briggs {
537 1.11 briggs u_long loc;
538 1.1 briggs
539 1.23 scottr #ifdef DEBUG
540 1.12 briggs if (nubus_debug & NDB_FOLLOW)
541 1.26 christos printf("nubus_get_ind_data(0x%x, 0x%x, 0x%x, %d).\n",
542 1.12 briggs (u_int) slot, (u_int) dirent, (u_int) data_return,
543 1.12 briggs nbytes);
544 1.12 briggs #endif
545 1.11 briggs if ((loc = dirent->offset) & 0x800000) {
546 1.11 briggs loc |= 0xff000000;
547 1.11 briggs }
548 1.11 briggs loc = IncPtr(slot, dirent->myloc, loc);
549 1.1 briggs
550 1.11 briggs while (nbytes--) {
551 1.11 briggs *data_return++ = GetByte(slot, loc);
552 1.11 briggs loc = IncPtr(slot, loc, 1);
553 1.1 briggs }
554 1.11 briggs return 1;
555 1.1 briggs }
556 1.1 briggs
557 1.11 briggs int
558 1.11 briggs nubus_get_c_string(slot, dirent, data_return, max_bytes)
559 1.11 briggs nubus_slot *slot;
560 1.11 briggs nubus_dirent *dirent;
561 1.11 briggs caddr_t data_return;
562 1.11 briggs int max_bytes;
563 1.1 briggs {
564 1.11 briggs u_long loc;
565 1.10 briggs
566 1.23 scottr #ifdef DEBUG
567 1.12 briggs if (nubus_debug & NDB_FOLLOW)
568 1.26 christos printf("nubus_get_c_string(0x%x, 0x%x, 0x%x, %d).\n",
569 1.12 briggs (u_int) slot, (u_int) dirent, (u_int) data_return,
570 1.12 briggs max_bytes);
571 1.12 briggs #endif
572 1.11 briggs if ((loc = dirent->offset) & 0x800000) {
573 1.11 briggs loc |= 0xff000000;
574 1.11 briggs }
575 1.11 briggs loc = IncPtr(slot, dirent->myloc, loc);
576 1.10 briggs
577 1.11 briggs *data_return = '\0';
578 1.11 briggs while (max_bytes--) {
579 1.11 briggs if ((*data_return++ = GetByte(slot, loc)) == 0)
580 1.11 briggs return 1;
581 1.11 briggs loc = IncPtr(slot, loc, 1);
582 1.11 briggs }
583 1.11 briggs return 0;
584 1.1 briggs }
585 1.2 briggs
586 1.11 briggs static char *huh = "???";
587 1.3 briggs
588 1.11 briggs char *
589 1.11 briggs nubus_get_vendor(slot, rsrc)
590 1.11 briggs nubus_slot *slot;
591 1.11 briggs int rsrc;
592 1.3 briggs {
593 1.11 briggs static char str_ret[64];
594 1.11 briggs nubus_dir dir;
595 1.11 briggs nubus_dirent ent;
596 1.3 briggs
597 1.23 scottr #ifdef DEBUG
598 1.12 briggs if (nubus_debug & NDB_FOLLOW)
599 1.26 christos printf("nubus_get_vendor(0x%x, 0x%x).\n", (u_int) slot, rsrc);
600 1.12 briggs #endif
601 1.11 briggs nubus_get_main_dir(slot, &dir);
602 1.11 briggs if (nubus_find_rsrc(slot, &dir, 1, &ent) <= 0)
603 1.11 briggs return huh;
604 1.11 briggs nubus_get_dir_from_rsrc(slot, &ent, &dir);
605 1.2 briggs
606 1.11 briggs if (nubus_find_rsrc(slot, &dir, NUBUS_RSRC_VENDORINFO, &ent) <= 0)
607 1.11 briggs return huh;
608 1.11 briggs nubus_get_dir_from_rsrc(slot, &ent, &dir);
609 1.10 briggs
610 1.11 briggs if (nubus_find_rsrc(slot, &dir, rsrc, &ent) <= 0)
611 1.11 briggs return huh;
612 1.10 briggs
613 1.11 briggs nubus_get_c_string(slot, &ent, str_ret, 64);
614 1.2 briggs
615 1.11 briggs return str_ret;
616 1.2 briggs }
617 1.2 briggs
618 1.11 briggs char *
619 1.11 briggs nubus_get_card_name(slot)
620 1.11 briggs nubus_slot *slot;
621 1.2 briggs {
622 1.11 briggs static char name_ret[64];
623 1.11 briggs nubus_dir dir;
624 1.11 briggs nubus_dirent ent;
625 1.2 briggs
626 1.23 scottr #ifdef DEBUG
627 1.12 briggs if (nubus_debug & NDB_FOLLOW)
628 1.26 christos printf("nubus_get_card_name(0x%lx).\n", (u_long) slot);
629 1.12 briggs #endif
630 1.11 briggs nubus_get_main_dir(slot, &dir);
631 1.2 briggs
632 1.11 briggs if (nubus_find_rsrc(slot, &dir, 1, &ent) <= 0)
633 1.11 briggs return huh;
634 1.2 briggs
635 1.11 briggs nubus_get_dir_from_rsrc(slot, &ent, &dir);
636 1.2 briggs
637 1.11 briggs if (nubus_find_rsrc(slot, &dir, NUBUS_RSRC_NAME, &ent) <= 0)
638 1.11 briggs return huh;
639 1.2 briggs
640 1.11 briggs nubus_get_c_string(slot, &ent, name_ret, 64);
641 1.2 briggs
642 1.11 briggs return name_ret;
643 1.2 briggs }
644