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