nubus.c revision 1.26 1 1.26 christos /* $NetBSD: nubus.c,v 1.26 1996/10/13 03:21:25 christos 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.24 cgd static int nubusprint __P((void *, const char *));
51 1.19 briggs static int nubusmatch __P((struct device *, void *, void *));
52 1.19 briggs static void nubusattach __P((struct device *, struct device *, void *));
53 1.11 briggs
54 1.11 briggs static int probe_slot __P((int slot, nubus_slot *fmt));
55 1.11 briggs static u_long IncPtr __P((nubus_slot *fmt, u_long base, long amt));
56 1.11 briggs static u_long nubus_calc_CRC __P((nubus_slot *fmt));
57 1.11 briggs static u_char GetByte __P((nubus_slot *fmt, u_long ptr));
58 1.17 briggs #ifdef notyet
59 1.17 briggs /* unused */ static u_short GetWord __P((nubus_slot *fmt, u_long ptr));
60 1.17 briggs #endif
61 1.11 briggs static u_long GetLong __P((nubus_slot *fmt, u_long ptr));
62 1.18 scottr
63 1.16 thorpej struct cfattach nubus_ca = {
64 1.19 briggs sizeof(struct nubus_softc), nubusmatch, nubusattach
65 1.16 thorpej };
66 1.16 thorpej
67 1.16 thorpej struct cfdriver nubus_cd = {
68 1.16 thorpej NULL, "nubus", DV_DULL, 1
69 1.11 briggs };
70 1.1 briggs
71 1.19 briggs static int
72 1.19 briggs nubusmatch(parent, vcf, aux)
73 1.19 briggs struct device *parent;
74 1.19 briggs void *vcf, *aux;
75 1.19 briggs {
76 1.19 briggs struct confargs *ca = aux;
77 1.19 briggs
78 1.19 briggs if (ca->ca_bustype != BUS_NUBUS)
79 1.19 briggs return (0);
80 1.19 briggs return(1);
81 1.19 briggs }
82 1.19 briggs
83 1.11 briggs static void
84 1.11 briggs nubusattach(parent, self, aux)
85 1.11 briggs struct device *parent, *self;
86 1.11 briggs void *aux;
87 1.11 briggs {
88 1.14 briggs nubus_slot fmtblock;
89 1.14 briggs int i;
90 1.1 briggs
91 1.26 christos printf("\n");
92 1.1 briggs
93 1.19 briggs for (i = NUBUS_MIN_SLOT; i <= NUBUS_MAX_SLOT; i++) {
94 1.14 briggs if (probe_slot(i, &fmtblock)) {
95 1.19 briggs /*config_search(bus_scan, &fmtblock, nubusprint);*/
96 1.14 briggs config_found(self, &fmtblock, nubusprint);
97 1.14 briggs }
98 1.12 briggs }
99 1.1 briggs }
100 1.1 briggs
101 1.10 briggs static int
102 1.11 briggs nubusprint(aux, name)
103 1.11 briggs void *aux;
104 1.24 cgd const char *name;
105 1.11 briggs {
106 1.11 briggs nubus_slot *fmt;
107 1.1 briggs
108 1.11 briggs fmt = (nubus_slot *) aux;
109 1.11 briggs if (name) {
110 1.26 christos printf("%s: slot %x: %s ", name, fmt->slot,
111 1.11 briggs nubus_get_card_name(fmt));
112 1.26 christos printf("(Vendor: %s, ",
113 1.11 briggs nubus_get_vendor(fmt, NUBUS_RSRC_VEND_ID));
114 1.26 christos printf("Part: %s) ",
115 1.11 briggs nubus_get_vendor(fmt, NUBUS_RSRC_VEND_PART));
116 1.1 briggs }
117 1.11 briggs return (UNCONF);
118 1.1 briggs }
119 1.1 briggs
120 1.11 briggs /*
121 1.11 briggs * Probe a given nubus slot. If a card is there and we can get the
122 1.11 briggs * format block from it's clutching decl. ROMs, fill the format block
123 1.11 briggs * and return non-zero. If we can't find a card there with a valid
124 1.11 briggs * decl. ROM, return 0.
125 1.11 briggs *
126 1.11 briggs * First, we check to see if we can access the memory at the tail
127 1.11 briggs * end of the slot. If so, then we check for a bytelanes byte. We
128 1.11 briggs * could probably just return a failure status if we bus error on
129 1.11 briggs * the first try, but there really is little reason not to go ahead
130 1.11 briggs * and check the other three locations in case there's a wierd card
131 1.11 briggs * out there.
132 1.11 briggs *
133 1.11 briggs * Checking for a card involves locating the "bytelanes" byte which
134 1.11 briggs * tells us how to interpret the declaration ROM's data. The format
135 1.11 briggs * block is at the top of the card's standard memory space and the
136 1.11 briggs * bytelanes byte is at the end of that block.
137 1.11 briggs *
138 1.11 briggs * After some inspection of the bytelanes byte, it appears that it
139 1.11 briggs * takes the form 0xXY where Y is a bitmask of the bytelanes in use
140 1.11 briggs * and X is a bitmask of the lanes to ignore. Hence, (X ^ Y) == 0
141 1.11 briggs * and (less obviously), Y will have the upper N bits clear if it is
142 1.11 briggs * found N bytes from the last possible location. Both that and
143 1.11 briggs * the exclusive-or check are made.
144 1.11 briggs *
145 1.11 briggs * If a valid
146 1.11 briggs */
147 1.11 briggs static u_char nbits[]={0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};
148 1.11 briggs static int
149 1.11 briggs probe_slot(slot, fmt)
150 1.11 briggs int slot;
151 1.11 briggs nubus_slot *fmt;
152 1.1 briggs {
153 1.11 briggs caddr_t rom_probe;
154 1.19 briggs vm_offset_t hdr;
155 1.23 scottr #ifdef DEBUG
156 1.23 scottr vm_offset_t pa;
157 1.23 scottr #endif
158 1.19 briggs u_int data;
159 1.11 briggs int hdr_size, i;
160 1.10 briggs
161 1.11 briggs fmt->bytelanes = 0;
162 1.11 briggs fmt->slot = (u_long)slot;
163 1.10 briggs
164 1.19 briggs rom_probe = (caddr_t) (NUBUS_SLOT_TO_PADDR(fmt->slot) + NBMEMSIZE);
165 1.10 briggs
166 1.12 briggs #ifdef DEBUG
167 1.12 briggs if (nubus_debug & NDB_PROBE) {
168 1.23 scottr pa = pmap_extract(pmap_kernel(), (vm_offset_t) rom_probe - 1);
169 1.26 christos printf("probing slot %d, first probe at 0x%x (PA 0x%p).\n",
170 1.23 scottr slot, rom_probe - 1, pa);
171 1.12 briggs }
172 1.12 briggs #endif
173 1.12 briggs
174 1.11 briggs for (i = 4; i && (fmt->bytelanes == 0); i--) {
175 1.10 briggs
176 1.11 briggs rom_probe--;
177 1.10 briggs
178 1.19 briggs data = bus_peek(BUS_NUBUS, (vm_offset_t) rom_probe, 1);
179 1.19 briggs if (data == -1)
180 1.11 briggs continue;
181 1.10 briggs
182 1.19 briggs if (data == 0)
183 1.11 briggs continue;
184 1.1 briggs
185 1.11 briggs if ( ((((data & 0xf0) >> 4) ^ (data & 0x0f)) == 0x0f)
186 1.11 briggs && ((data & 0x0f) < (1 << i)) ) {
187 1.11 briggs fmt->bytelanes = data;
188 1.11 briggs fmt->step = nbits[(data & 0x0f)];
189 1.11 briggs }
190 1.1 briggs }
191 1.11 briggs #ifdef DEBUG
192 1.12 briggs if (nubus_debug & NDB_PROBE)
193 1.12 briggs if (fmt->bytelanes == 0)
194 1.26 christos printf("bytelanes not found for slot 0x%x.\n", slot);
195 1.11 briggs #endif
196 1.11 briggs
197 1.11 briggs if (fmt->bytelanes == 0)
198 1.11 briggs return 0;
199 1.11 briggs
200 1.11 briggs #ifdef DEBUG
201 1.12 briggs if (nubus_debug & NDB_PROBE)
202 1.26 christos printf("bytelanes of 0x%x found for slot 0x%x.\n",
203 1.20 briggs fmt->bytelanes, slot);
204 1.11 briggs #endif
205 1.1 briggs
206 1.11 briggs hdr_size = 20;
207 1.10 briggs
208 1.11 briggs /*
209 1.11 briggs * Go ahead and attempt to load format header.
210 1.11 briggs * First, we need to find the first byte beyond memory that
211 1.11 briggs * would be valid. This is necessary for NUBUS_ROM_offset()
212 1.11 briggs * to work.
213 1.11 briggs */
214 1.19 briggs hdr = (vm_offset_t)
215 1.19 briggs bus_mapin(BUS_NUBUS,NUBUS_SLOT_TO_PADDR(fmt->slot),NBMEMSIZE);
216 1.19 briggs if (hdr == NULL) {
217 1.26 christos printf("Failed to map %d bytes for NuBUS slot %d probe. ",
218 1.22 briggs NBMEMSIZE, fmt->slot);
219 1.26 christos printf("Physical slot address %x\n",
220 1.22 briggs (unsigned int) NUBUS_SLOT_TO_PADDR(fmt->slot));
221 1.19 briggs }
222 1.19 briggs fmt->virtual_base = hdr;
223 1.19 briggs hdr += NBMEMSIZE;
224 1.19 briggs
225 1.11 briggs i = 0x10 | (fmt->bytelanes & 0x0f);
226 1.11 briggs while ((i & 1) == 0) {
227 1.11 briggs hdr++;
228 1.11 briggs i >>= 1;
229 1.11 briggs }
230 1.11 briggs fmt->top = hdr;
231 1.11 briggs hdr = IncPtr(fmt, hdr, -hdr_size);
232 1.11 briggs #ifdef DEBUG
233 1.12 briggs if (nubus_debug & NDB_PROBE)
234 1.26 christos printf("fmt->top is 0x%p, that minus 0x%x puts us at 0x%p.\n",
235 1.12 briggs fmt->top, hdr_size, hdr);
236 1.11 briggs #if 0
237 1.11 briggs for (i=1 ; i < 8 ; i++) {
238 1.26 christos printf("0x%x - 0x%x = 0x%x, + 0x%x = 0x%x.\n",
239 1.11 briggs hdr, i, IncPtr(fmt, hdr, -i),
240 1.11 briggs i, IncPtr(fmt, hdr, i));
241 1.11 briggs }
242 1.11 briggs #endif
243 1.11 briggs #endif
244 1.11 briggs
245 1.11 briggs fmt->directory_offset = 0xff000000 | GetLong(fmt, hdr);
246 1.11 briggs hdr = IncPtr(fmt, hdr, 4);
247 1.11 briggs fmt->length = GetLong(fmt, hdr);
248 1.11 briggs hdr = IncPtr(fmt, hdr, 4);
249 1.11 briggs fmt->crc = GetLong(fmt, hdr);
250 1.11 briggs hdr = IncPtr(fmt, hdr, 4);
251 1.11 briggs fmt->revision_level = GetByte(fmt, hdr);
252 1.11 briggs hdr = IncPtr(fmt, hdr, 1);
253 1.11 briggs fmt->format = GetByte(fmt, hdr);
254 1.11 briggs hdr = IncPtr(fmt, hdr, 1);
255 1.11 briggs fmt->test_pattern = GetLong(fmt, hdr);
256 1.11 briggs
257 1.23 scottr #ifdef DEBUG
258 1.12 briggs if (nubus_debug & NDB_PROBE) {
259 1.26 christos printf("Directory offset 0x%x\t", fmt->directory_offset);
260 1.26 christos printf("Length 0x%x\t", fmt->length);
261 1.26 christos printf("CRC 0x%x\n", fmt->crc);
262 1.26 christos printf("Revision level 0x%x\t", fmt->revision_level);
263 1.26 christos printf("Format 0x%x\t", fmt->format);
264 1.26 christos printf("Test Pattern 0x%x\n", fmt->test_pattern);
265 1.12 briggs }
266 1.11 briggs #endif
267 1.11 briggs
268 1.12 briggs if ((fmt->directory_offset & 0x00ff0000) == 0) {
269 1.26 christos printf("Invalid looking directory offset (0x%x)!\n",
270 1.12 briggs fmt->directory_offset);
271 1.12 briggs return 0;
272 1.12 briggs }
273 1.11 briggs if (fmt->test_pattern != NUBUS_ROM_TEST_PATTERN) {
274 1.26 christos printf("Nubus--test pattern invalid:\n");
275 1.26 christos printf(" slot 0x%x, bytelanes 0x%x?\n",
276 1.11 briggs fmt->slot, fmt->bytelanes);
277 1.26 christos printf(" read test 0x%x, compare with 0x%x.\n",
278 1.11 briggs fmt->test_pattern, NUBUS_ROM_TEST_PATTERN);
279 1.11 briggs return 0;
280 1.11 briggs }
281 1.11 briggs
282 1.11 briggs /* Perform CRC */
283 1.11 briggs if (fmt->crc != nubus_calc_CRC(fmt)) {
284 1.26 christos printf("Nubus--crc check failed, slot 0x%x.\n",
285 1.11 briggs fmt->slot);
286 1.11 briggs return 0;
287 1.1 briggs }
288 1.10 briggs
289 1.11 briggs return 1;
290 1.1 briggs }
291 1.1 briggs
292 1.11 briggs /*
293 1.11 briggs * Compute byte offset on card, taking into account bytelanes.
294 1.11 briggs * Base must be on a valid bytelane for this function to work.
295 1.11 briggs * Return the new address.
296 1.11 briggs *
297 1.11 briggs * XXX -- There has GOT to be a better way to do this.
298 1.11 briggs */
299 1.11 briggs static u_long
300 1.11 briggs IncPtr(fmt, base, amt)
301 1.11 briggs nubus_slot *fmt;
302 1.11 briggs u_long base;
303 1.11 briggs long amt;
304 1.11 briggs {
305 1.11 briggs u_char b, t;
306 1.11 briggs
307 1.11 briggs if (!amt)
308 1.11 briggs return base;
309 1.11 briggs
310 1.11 briggs if (amt < 0) {
311 1.11 briggs amt = -amt;
312 1.11 briggs b = fmt->bytelanes;
313 1.11 briggs t = (b << 4);
314 1.11 briggs b <<= (3 - (base & 0x3));
315 1.11 briggs while (amt) {
316 1.11 briggs b <<= 1;
317 1.11 briggs if (b == t)
318 1.11 briggs b = fmt->bytelanes;
319 1.11 briggs if (b & 0x08)
320 1.11 briggs amt--;
321 1.11 briggs base--;
322 1.11 briggs }
323 1.11 briggs return base;
324 1.11 briggs }
325 1.10 briggs
326 1.11 briggs t = (fmt->bytelanes & 0xf) | 0x10;
327 1.11 briggs b = t >> (base & 0x3);
328 1.11 briggs while (amt) {
329 1.11 briggs b >>= 1;
330 1.11 briggs if (b == 1)
331 1.11 briggs b = t;
332 1.11 briggs if (b & 1)
333 1.11 briggs amt--;
334 1.11 briggs base++;
335 1.11 briggs }
336 1.11 briggs
337 1.11 briggs return base;
338 1.11 briggs }
339 1.11 briggs
340 1.11 briggs static u_long
341 1.11 briggs nubus_calc_CRC(fmt)
342 1.11 briggs nubus_slot *fmt;
343 1.11 briggs {
344 1.11 briggs #if 0
345 1.11 briggs u_long base, ptr, crc_loc, sum;
346 1.11 briggs int i;
347 1.11 briggs
348 1.11 briggs base = fmt->top;
349 1.11 briggs crc_loc = NUBUS_ROM_offset(fmt, base, -12);
350 1.11 briggs ptr = NUBUS_ROM_offset(fmt, base, -fmt->length);
351 1.11 briggs
352 1.11 briggs sum = 0;
353 1.11 briggs while (ptr < base)
354 1.11 briggs roll #1, sum
355 1.11 briggs if (ptr == crc_loc) {
356 1.11 briggs roll #3, sum
357 1.11 briggs ptr = IncPtr(fmt, ptr, 3);
358 1.11 briggs } else {
359 1.11 briggs sum += GetByte(fmt, ptr);
360 1.11 briggs }
361 1.11 briggs ptr = IncPtr(fmt, ptr, 1);
362 1.1 briggs }
363 1.10 briggs
364 1.11 briggs return sum;
365 1.11 briggs #endif
366 1.11 briggs return fmt->crc;
367 1.1 briggs }
368 1.1 briggs
369 1.11 briggs static u_char
370 1.11 briggs GetByte(fmt, ptr)
371 1.11 briggs nubus_slot *fmt;
372 1.11 briggs u_long ptr;
373 1.1 briggs {
374 1.11 briggs return *(caddr_t)ptr;
375 1.1 briggs }
376 1.1 briggs
377 1.17 briggs #ifdef notyet
378 1.17 briggs /* Nothing uses this, yet */
379 1.11 briggs static u_short
380 1.11 briggs GetWord(fmt, ptr)
381 1.11 briggs nubus_slot *fmt;
382 1.11 briggs u_long ptr;
383 1.1 briggs {
384 1.11 briggs u_short s;
385 1.10 briggs
386 1.11 briggs s = (GetByte(fmt, ptr) << 8);
387 1.11 briggs ptr = IncPtr(fmt, ptr, 1);
388 1.11 briggs s |= GetByte(fmt, ptr);
389 1.11 briggs return s;
390 1.11 briggs }
391 1.17 briggs #endif
392 1.1 briggs
393 1.11 briggs static u_long
394 1.11 briggs GetLong(fmt, ptr)
395 1.11 briggs nubus_slot *fmt;
396 1.11 briggs u_long ptr;
397 1.11 briggs {
398 1.11 briggs register u_long l;
399 1.11 briggs register int i;
400 1.10 briggs
401 1.11 briggs l = 0;
402 1.11 briggs for ( i = 0; i < 4; i++) {
403 1.11 briggs l = (l << 8) | GetByte(fmt, ptr);
404 1.11 briggs ptr = IncPtr(fmt, ptr, 1);
405 1.11 briggs }
406 1.11 briggs return l;
407 1.11 briggs }
408 1.10 briggs
409 1.11 briggs void
410 1.11 briggs nubus_get_main_dir(slot, dir_return)
411 1.11 briggs nubus_slot *slot;
412 1.11 briggs nubus_dir *dir_return;
413 1.11 briggs {
414 1.23 scottr #ifdef DEBUG
415 1.12 briggs if (nubus_debug & NDB_FOLLOW)
416 1.26 christos printf("nubus_get_main_dir(0x%x, 0x%x)\n",
417 1.12 briggs (u_int) slot, (u_int) dir_return);
418 1.12 briggs #endif
419 1.11 briggs dir_return->dirbase = IncPtr(slot, slot->top,
420 1.11 briggs slot->directory_offset - 20);
421 1.11 briggs dir_return->curr_ent = dir_return->dirbase;
422 1.1 briggs }
423 1.1 briggs
424 1.11 briggs int
425 1.11 briggs nubus_find_rsrc(slot, dir, rsrcid, dirent_return)
426 1.11 briggs nubus_slot *slot;
427 1.11 briggs nubus_dir *dir;
428 1.11 briggs u_int8_t rsrcid;
429 1.11 briggs nubus_dirent *dirent_return;
430 1.1 briggs {
431 1.11 briggs u_long entry;
432 1.11 briggs u_char byte;
433 1.10 briggs
434 1.23 scottr #ifdef DEBUG
435 1.12 briggs if (nubus_debug & NDB_FOLLOW)
436 1.26 christos printf("nubus_find_rsrc(0x%x, 0x%x, 0x%x, 0x%x)\n",
437 1.12 briggs (u_int) slot, (u_int) dir, (u_int) rsrcid,
438 1.12 briggs (u_int) dirent_return);
439 1.11 briggs #endif
440 1.12 briggs if (slot->test_pattern != NUBUS_ROM_TEST_PATTERN)
441 1.12 briggs return -1;
442 1.12 briggs
443 1.12 briggs entry = dir->curr_ent;
444 1.11 briggs do {
445 1.11 briggs byte = GetByte(slot, entry);
446 1.23 scottr #ifdef DEBUG
447 1.12 briggs if (nubus_debug & NDB_FOLLOW)
448 1.26 christos printf("\tFound rsrc 0x%x.\n", byte);
449 1.11 briggs #endif
450 1.11 briggs if (byte == rsrcid) {
451 1.11 briggs dirent_return->myloc = entry;
452 1.11 briggs dirent_return->rsrc_id = rsrcid;
453 1.11 briggs entry = GetLong(slot, entry);
454 1.11 briggs dirent_return->offset = (entry & 0x00ffffff);
455 1.11 briggs return 1;
456 1.11 briggs }
457 1.11 briggs if (byte == 0xff) {
458 1.11 briggs entry = dir->dirbase;
459 1.11 briggs } else {
460 1.11 briggs entry = IncPtr(slot, entry, 4);
461 1.11 briggs }
462 1.11 briggs } while (entry != (u_long) dir->curr_ent);
463 1.11 briggs return 0;
464 1.1 briggs }
465 1.1 briggs
466 1.11 briggs void
467 1.11 briggs nubus_get_dir_from_rsrc(slot, dirent, dir_return)
468 1.11 briggs nubus_slot *slot;
469 1.11 briggs nubus_dirent *dirent;
470 1.11 briggs nubus_dir *dir_return;
471 1.1 briggs {
472 1.11 briggs u_long loc;
473 1.10 briggs
474 1.23 scottr #ifdef DEBUG
475 1.12 briggs if (nubus_debug & NDB_FOLLOW)
476 1.26 christos printf("nubus_get_dir_from_rsrc(0x%x, 0x%x, 0x%x).\n",
477 1.12 briggs (u_int) slot, (u_int) dirent, (u_int) dir_return);
478 1.12 briggs #endif
479 1.11 briggs if ((loc = dirent->offset) & 0x800000) {
480 1.11 briggs loc |= 0xff000000;
481 1.1 briggs }
482 1.11 briggs dir_return->dirbase = IncPtr(slot, dirent->myloc, loc);
483 1.11 briggs dir_return->curr_ent = dir_return->dirbase;
484 1.1 briggs }
485 1.1 briggs
486 1.11 briggs int
487 1.11 briggs nubus_get_ind_data(slot, dirent, data_return, nbytes)
488 1.11 briggs nubus_slot *slot;
489 1.11 briggs nubus_dirent *dirent;
490 1.11 briggs caddr_t data_return;
491 1.11 briggs int nbytes;
492 1.11 briggs {
493 1.11 briggs u_long loc;
494 1.1 briggs
495 1.23 scottr #ifdef DEBUG
496 1.12 briggs if (nubus_debug & NDB_FOLLOW)
497 1.26 christos printf("nubus_get_ind_data(0x%x, 0x%x, 0x%x, %d).\n",
498 1.12 briggs (u_int) slot, (u_int) dirent, (u_int) data_return,
499 1.12 briggs nbytes);
500 1.12 briggs #endif
501 1.11 briggs if ((loc = dirent->offset) & 0x800000) {
502 1.11 briggs loc |= 0xff000000;
503 1.11 briggs }
504 1.11 briggs loc = IncPtr(slot, dirent->myloc, loc);
505 1.1 briggs
506 1.11 briggs while (nbytes--) {
507 1.11 briggs *data_return++ = GetByte(slot, loc);
508 1.11 briggs loc = IncPtr(slot, loc, 1);
509 1.1 briggs }
510 1.11 briggs return 1;
511 1.1 briggs }
512 1.1 briggs
513 1.11 briggs int
514 1.11 briggs nubus_get_c_string(slot, dirent, data_return, max_bytes)
515 1.11 briggs nubus_slot *slot;
516 1.11 briggs nubus_dirent *dirent;
517 1.11 briggs caddr_t data_return;
518 1.11 briggs int max_bytes;
519 1.1 briggs {
520 1.11 briggs u_long loc;
521 1.10 briggs
522 1.23 scottr #ifdef DEBUG
523 1.12 briggs if (nubus_debug & NDB_FOLLOW)
524 1.26 christos printf("nubus_get_c_string(0x%x, 0x%x, 0x%x, %d).\n",
525 1.12 briggs (u_int) slot, (u_int) dirent, (u_int) data_return,
526 1.12 briggs max_bytes);
527 1.12 briggs #endif
528 1.11 briggs if ((loc = dirent->offset) & 0x800000) {
529 1.11 briggs loc |= 0xff000000;
530 1.11 briggs }
531 1.11 briggs loc = IncPtr(slot, dirent->myloc, loc);
532 1.10 briggs
533 1.11 briggs *data_return = '\0';
534 1.11 briggs while (max_bytes--) {
535 1.11 briggs if ((*data_return++ = GetByte(slot, loc)) == 0)
536 1.11 briggs return 1;
537 1.11 briggs loc = IncPtr(slot, loc, 1);
538 1.11 briggs }
539 1.11 briggs return 0;
540 1.1 briggs }
541 1.2 briggs
542 1.11 briggs static char *huh = "???";
543 1.3 briggs
544 1.11 briggs char *
545 1.11 briggs nubus_get_vendor(slot, rsrc)
546 1.11 briggs nubus_slot *slot;
547 1.11 briggs int rsrc;
548 1.3 briggs {
549 1.11 briggs static char str_ret[64];
550 1.11 briggs nubus_dir dir;
551 1.11 briggs nubus_dirent ent;
552 1.3 briggs
553 1.23 scottr #ifdef DEBUG
554 1.12 briggs if (nubus_debug & NDB_FOLLOW)
555 1.26 christos printf("nubus_get_vendor(0x%x, 0x%x).\n", (u_int) slot, rsrc);
556 1.12 briggs #endif
557 1.11 briggs nubus_get_main_dir(slot, &dir);
558 1.11 briggs if (nubus_find_rsrc(slot, &dir, 1, &ent) <= 0)
559 1.11 briggs return huh;
560 1.11 briggs nubus_get_dir_from_rsrc(slot, &ent, &dir);
561 1.2 briggs
562 1.11 briggs if (nubus_find_rsrc(slot, &dir, NUBUS_RSRC_VENDORINFO, &ent) <= 0)
563 1.11 briggs return huh;
564 1.11 briggs nubus_get_dir_from_rsrc(slot, &ent, &dir);
565 1.10 briggs
566 1.11 briggs if (nubus_find_rsrc(slot, &dir, rsrc, &ent) <= 0)
567 1.11 briggs return huh;
568 1.10 briggs
569 1.11 briggs nubus_get_c_string(slot, &ent, str_ret, 64);
570 1.2 briggs
571 1.11 briggs return str_ret;
572 1.2 briggs }
573 1.2 briggs
574 1.11 briggs char *
575 1.11 briggs nubus_get_card_name(slot)
576 1.11 briggs nubus_slot *slot;
577 1.2 briggs {
578 1.11 briggs static char name_ret[64];
579 1.11 briggs nubus_dir dir;
580 1.11 briggs nubus_dirent ent;
581 1.2 briggs
582 1.23 scottr #ifdef DEBUG
583 1.12 briggs if (nubus_debug & NDB_FOLLOW)
584 1.26 christos printf("nubus_get_card_name(0x%lx).\n", (u_long) slot);
585 1.12 briggs #endif
586 1.11 briggs nubus_get_main_dir(slot, &dir);
587 1.2 briggs
588 1.11 briggs if (nubus_find_rsrc(slot, &dir, 1, &ent) <= 0)
589 1.11 briggs return huh;
590 1.2 briggs
591 1.11 briggs nubus_get_dir_from_rsrc(slot, &ent, &dir);
592 1.2 briggs
593 1.11 briggs if (nubus_find_rsrc(slot, &dir, NUBUS_RSRC_NAME, &ent) <= 0)
594 1.11 briggs return huh;
595 1.2 briggs
596 1.11 briggs nubus_get_c_string(slot, &ent, name_ret, 64);
597 1.2 briggs
598 1.11 briggs return name_ret;
599 1.2 briggs }
600