2 * Macintosh Nubus Interface Code
4 * Originally by Alan Cox
6 * Mostly rewritten by David Huggins-Daines, C. Scott Ananian,
10 #include <linux/config.h>
11 #include <linux/ptrace.h>
12 #include <linux/types.h>
13 #include <linux/kernel.h>
14 #include <linux/string.h>
15 #include <linux/nubus.h>
16 #include <linux/errno.h>
17 #include <linux/init.h>
18 #include <linux/delay.h>
19 #include <asm/setup.h>
20 #include <asm/system.h>
22 #include <asm/hwtest.h>
23 #include <linux/proc_fs.h>
24 #include <asm/mac_via.h>
25 #include <asm/mac_oss.h>
27 extern void via_nubus_init(void);
28 extern void oss_nubus_init(void);
30 extern int console_loglevel
;
34 /* This is, of course, the size in bytelanes, rather than the size in
36 #define FORMAT_BLOCK_SIZE 20
37 #define ROM_DIR_OFFSET 0x24
39 #define NUBUS_TEST_PATTERN 0x5A932BC7
41 /* Define this if you like to live dangerously - it is known not to
42 work on pretty much every machine except the Quadra 630 and the LC
44 #undef I_WANT_TO_PROBE_SLOT_ZERO
46 /* This sometimes helps combat failure to boot */
47 #undef TRY_TO_DODGE_WSOD
51 struct nubus_dev
* nubus_devices
;
52 struct nubus_board
* nubus_boards
;
54 /* Meaning of "bytelanes":
56 The card ROM may appear on any or all bytes of each long word in
57 NuBus memory. The low 4 bits of the "map" value found in the
58 format block (at the top of the slot address space, as well as at
59 the top of the MacOS ROM) tells us which bytelanes, i.e. which byte
60 offsets within each longword, are valid. Thus:
62 A map of 0x0f, as found in the MacOS ROM, means that all bytelanes
65 A map of 0xf0 means that no bytelanes are valid (We pray that we
66 will never encounter this, but stranger things have happened)
68 A map of 0xe1 means that only the MSB of each long word is actually
69 part of the card ROM. (We hope to never encounter NuBus on a
70 little-endian machine. Again, stranger things have happened)
72 A map of 0x78 means that only the LSB of each long word is valid.
74 Etcetera, etcetera. Hopefully this clears up some confusion over
75 what the following code actually does. */
77 extern inline int not_useful(void *p
, int map
)
79 unsigned long pv
=(unsigned long)p
;
86 static unsigned long nubus_get_rom(unsigned char **ptr
, int len
, int map
)
88 /* This will hold the result */
90 unsigned char *p
= *ptr
;
95 while(not_useful(p
,map
))
104 static void nubus_rewind(unsigned char **ptr
, int len
, int map
)
106 unsigned char *p
=*ptr
;
110 printk(KERN_ERR
"rewind of 0x%08x!\n", len
);
117 while(not_useful(p
, map
));
123 static void nubus_advance(unsigned char **ptr
, int len
, int map
)
125 unsigned char *p
= *ptr
;
127 printk(KERN_ERR
"advance of 0x%08x!\n", len
);
130 while(not_useful(p
,map
))
138 static void nubus_move(unsigned char **ptr
, int len
, int map
)
141 nubus_advance(ptr
, len
, map
);
143 nubus_rewind(ptr
, -len
, map
);
146 /* Now, functions to read the sResource tree */
148 /* Each sResource entry consists of a 1-byte ID and a 3-byte data
149 field. If that data field contains an offset, then obviously we
150 have to expand it from a 24-bit signed number to a 32-bit signed
153 extern inline long nubus_expand32(long foo
)
155 if(foo
& 0x00800000) /* 24bit negative */
160 extern inline void *nubus_rom_addr(int slot
)
163 * Returns the first byte after the card. We then walk
164 * backwards to get the lane register and the config
166 return (void *)(0xF1000000+(slot
<<24));
169 static unsigned char *nubus_dirptr(const struct nubus_dirent
*nd
)
171 unsigned char *p
= nd
->base
;
172 /* Essentially, just step over the bytelanes using whatever
173 offset we might have found */
174 nubus_move(&p
, nubus_expand32(nd
->data
), nd
->mask
);
175 /* And return the value */
179 /* These two are for pulling resource data blocks (i.e. stuff that's
180 pointed to with offsets) out of the card ROM. */
182 void nubus_get_rsrc_mem(void *dest
, const struct nubus_dirent
* dirent
,
185 unsigned char *t
= (unsigned char *)dest
;
186 unsigned char *p
= nubus_dirptr(dirent
);
189 *t
++ = nubus_get_rom(&p
, 1, dirent
->mask
);
194 void nubus_get_rsrc_str(void *dest
, const struct nubus_dirent
* dirent
,
197 unsigned char *t
=(unsigned char *)dest
;
198 unsigned char *p
= nubus_dirptr(dirent
);
201 *t
= nubus_get_rom(&p
, 1, dirent
->mask
);
208 int nubus_get_root_dir(const struct nubus_board
* board
,
209 struct nubus_dir
* dir
)
211 dir
->ptr
= dir
->base
= board
->directory
;
213 dir
->mask
= board
->lanes
;
217 /* This is a slyly renamed version of the above */
218 int nubus_get_func_dir(const struct nubus_dev
* dev
,
219 struct nubus_dir
* dir
)
221 dir
->ptr
= dir
->base
= dev
->directory
;
223 dir
->mask
= dev
->board
->lanes
;
227 int nubus_get_board_dir(const struct nubus_board
* board
,
228 struct nubus_dir
* dir
)
230 struct nubus_dirent ent
;
232 dir
->ptr
= dir
->base
= board
->directory
;
234 dir
->mask
= board
->lanes
;
236 /* Now dereference it (the first directory is always the board
238 if (nubus_readdir(dir
, &ent
) == -1)
240 if (nubus_get_subdir(&ent
, dir
) == -1)
245 int nubus_get_subdir(const struct nubus_dirent
*ent
,
246 struct nubus_dir
*dir
)
248 dir
->ptr
= dir
->base
= nubus_dirptr(ent
);
250 dir
->mask
= ent
->mask
;
254 int nubus_readdir(struct nubus_dir
*nd
, struct nubus_dirent
*ent
)
260 /* Do this first, otherwise nubus_rewind & co are off by 4 */
263 /* This moves nd->ptr forward */
264 resid
= nubus_get_rom(&nd
->ptr
, 4, nd
->mask
);
266 /* EOL marker, as per the Apple docs */
267 if((resid
&0xff000000) == 0xff000000)
269 /* Mark it as done */
274 /* First byte is the resource ID */
275 ent
->type
= resid
>> 24;
276 /* Low 3 bytes might contain data (or might not) */
277 ent
->data
= resid
& 0xffffff;
278 ent
->mask
= nd
->mask
;
282 int nubus_rewinddir(struct nubus_dir
* dir
)
284 dir
->ptr
= dir
->base
;
288 /* Driver interface functions, more or less like in pci.c */
291 nubus_find_device(unsigned short category
,
293 unsigned short dr_hw
,
294 unsigned short dr_sw
,
295 const struct nubus_dev
* from
)
297 struct nubus_dev
* itor
=
298 from
? from
->next
: nubus_devices
;
301 if (itor
->category
== category
302 && itor
->type
== type
303 && itor
->dr_hw
== dr_hw
304 && itor
->dr_sw
== dr_sw
)
312 nubus_find_type(unsigned short category
,
314 const struct nubus_dev
* from
)
316 struct nubus_dev
* itor
=
317 from
? from
->next
: nubus_devices
;
320 if (itor
->category
== category
321 && itor
->type
== type
)
329 nubus_find_slot(unsigned int slot
,
330 const struct nubus_dev
* from
)
332 struct nubus_dev
* itor
=
333 from
? from
->next
: nubus_devices
;
336 if (itor
->board
->slot
== slot
)
344 nubus_find_rsrc(struct nubus_dir
* dir
, unsigned char rsrc_type
,
345 struct nubus_dirent
* ent
)
347 while (nubus_readdir(dir
, ent
) != -1) {
348 if (ent
->type
== rsrc_type
)
354 /* Initialization functions - decide which slots contain stuff worth
355 looking at, and print out lots and lots of information from the
358 /* FIXME: A lot of this stuff will eventually be useful after
359 initializaton, for intelligently probing Ethernet and video chips,
360 among other things. The rest of it should go in the /proc code.
361 For now, we just use it to give verbose boot logs. */
363 static int __init
nubus_show_display_resource(struct nubus_dev
* dev
,
364 const struct nubus_dirent
* ent
)
367 case NUBUS_RESID_GAMMADIR
:
368 printk(KERN_INFO
" gamma directory offset: 0x%06x\n", ent
->data
);
370 case 0x0080 ... 0x0085:
371 printk(KERN_INFO
" mode %02X info offset: 0x%06x\n",
372 ent
->type
, ent
->data
);
375 printk(KERN_INFO
" unknown resource %02X, data 0x%06x\n",
376 ent
->type
, ent
->data
);
381 static int __init
nubus_show_network_resource(struct nubus_dev
* dev
,
382 const struct nubus_dirent
* ent
)
385 case NUBUS_RESID_MAC_ADDRESS
:
390 nubus_get_rsrc_mem(addr
, ent
, 6);
391 printk(KERN_INFO
" MAC address: ");
392 for (i
= 0; i
< 6; i
++)
393 printk("%02x%s", addr
[i
] & 0xff,
399 printk(KERN_INFO
" unknown resource %02X, data 0x%06x\n",
400 ent
->type
, ent
->data
);
405 static int __init
nubus_show_cpu_resource(struct nubus_dev
* dev
,
406 const struct nubus_dirent
* ent
)
409 case NUBUS_RESID_MEMINFO
:
411 unsigned long meminfo
[2];
412 nubus_get_rsrc_mem(&meminfo
, ent
, 8);
413 printk(KERN_INFO
" memory: [ 0x%08lx 0x%08lx ]\n",
414 meminfo
[0], meminfo
[1]);
417 case NUBUS_RESID_ROMINFO
:
419 unsigned long rominfo
[2];
420 nubus_get_rsrc_mem(&rominfo
, ent
, 8);
421 printk(KERN_INFO
" ROM: [ 0x%08lx 0x%08lx ]\n",
422 rominfo
[0], rominfo
[1]);
426 printk(KERN_INFO
" unknown resource %02X, data 0x%06x\n",
427 ent
->type
, ent
->data
);
432 static int __init
nubus_show_private_resource(struct nubus_dev
* dev
,
433 const struct nubus_dirent
* ent
)
435 switch (dev
->category
) {
436 case NUBUS_CAT_DISPLAY
:
437 nubus_show_display_resource(dev
, ent
);
439 case NUBUS_CAT_NETWORK
:
440 nubus_show_network_resource(dev
, ent
);
443 nubus_show_cpu_resource(dev
, ent
);
446 printk(KERN_INFO
" unknown resource %02X, data 0x%06x\n",
447 ent
->type
, ent
->data
);
452 static struct nubus_dev
* __init
453 nubus_get_functional_resource(struct nubus_board
* board
,
455 const struct nubus_dirent
* parent
)
457 struct nubus_dir dir
;
458 struct nubus_dirent ent
;
459 struct nubus_dev
* dev
;
461 printk(KERN_INFO
" Function 0x%02x:\n", parent
->type
);
462 nubus_get_subdir(parent
, &dir
);
464 /* Apple seems to have botched the ROM on the IIx */
465 if (slot
== 0 && (unsigned long)dir
.base
% 2)
468 if (console_loglevel
>= 10)
469 printk(KERN_DEBUG
"nubus_get_functional_resource: parent is 0x%p, dir is 0x%p\n",
470 parent
->base
, dir
.base
);
472 /* Actually we should probably panic if this fails */
473 if ((dev
= kmalloc(sizeof(*dev
), GFP_ATOMIC
)) == NULL
)
475 memset(dev
, 0, sizeof(*dev
));
476 dev
->resid
= parent
->type
;
477 dev
->directory
= dir
.base
;
480 while (nubus_readdir(&dir
, &ent
) != -1)
484 case NUBUS_RESID_TYPE
:
486 unsigned short nbtdata
[4];
487 nubus_get_rsrc_mem(nbtdata
, &ent
, 8);
488 dev
->category
= nbtdata
[0];
489 dev
->type
= nbtdata
[1];
490 dev
->dr_sw
= nbtdata
[2];
491 dev
->dr_hw
= nbtdata
[3];
492 printk(KERN_INFO
" type: [cat 0x%x type 0x%x hw 0x%x sw 0x%x]\n",
493 nbtdata
[0], nbtdata
[1], nbtdata
[2], nbtdata
[3]);
496 case NUBUS_RESID_NAME
:
498 nubus_get_rsrc_str(dev
->name
, &ent
, 64);
499 printk(KERN_INFO
" name: %s\n", dev
->name
);
502 case NUBUS_RESID_DRVRDIR
:
504 /* MacOS driver. If we were NetBSD we might
506 struct nubus_dir drvr_dir
;
507 struct nubus_dirent drvr_ent
;
508 nubus_get_subdir(&ent
, &drvr_dir
);
509 nubus_readdir(&drvr_dir
, &drvr_ent
);
510 dev
->driver
= nubus_dirptr(&drvr_ent
);
511 printk(KERN_INFO
" driver at: 0x%p\n",
515 case NUBUS_RESID_MINOR_BASEOS
:
516 /* We will need this in order to support
517 multiple framebuffers. It might be handy
518 for Ethernet as well */
519 nubus_get_rsrc_mem(&dev
->iobase
, &ent
, 4);
520 printk(KERN_INFO
" memory offset: 0x%08lx\n",
523 case NUBUS_RESID_MINOR_LENGTH
:
525 nubus_get_rsrc_mem(&dev
->iosize
, &ent
, 4);
526 printk(KERN_INFO
" memory length: 0x%08lx\n",
529 case NUBUS_RESID_FLAGS
:
530 dev
->flags
= ent
.data
;
531 printk(KERN_INFO
" flags: 0x%06x\n", dev
->flags
);
533 case NUBUS_RESID_HWDEVID
:
534 dev
->hwdevid
= ent
.data
;
535 printk(KERN_INFO
" hwdevid: 0x%06x\n", dev
->hwdevid
);
538 /* Local/Private resources have their own
540 nubus_show_private_resource(dev
, &ent
);
548 static int __init
nubus_get_vidnames(struct nubus_board
* board
,
549 const struct nubus_dirent
* parent
)
551 struct nubus_dir dir
;
552 struct nubus_dirent ent
;
553 /* FIXME: obviously we want to put this in a header file soon */
556 /* Don't know what this is yet */
558 /* Longest one I've seen so far is 26 characters */
562 printk(KERN_INFO
" video modes supported:\n");
563 nubus_get_subdir(parent
, &dir
);
564 if (console_loglevel
>= 10)
565 printk(KERN_DEBUG
"nubus_get_vidnames: parent is 0x%p, dir is 0x%p\n",
566 parent
->base
, dir
.base
);
568 while(nubus_readdir(&dir
, &ent
) != -1)
573 /* First get the length */
574 nubus_get_rsrc_mem(&size
, &ent
, 4);
576 /* Now clobber the whole thing */
577 if (size
> sizeof(mode
) - 1)
578 size
= sizeof(mode
) - 1;
579 memset(&mode
, sizeof(mode
), 0);
580 nubus_get_rsrc_mem(&mode
, &ent
, size
);
581 printk (KERN_INFO
" %02X: (%02X) %s\n", ent
.type
,
587 /* This is *really* cool. */
588 static int __init
nubus_get_icon(struct nubus_board
* board
,
589 const struct nubus_dirent
* ent
)
591 /* Should be 32x32 if my memory serves me correctly */
592 unsigned char icon
[128];
595 nubus_get_rsrc_mem(&icon
, ent
, 128);
596 printk(KERN_INFO
" icon:\n");
598 /* We should actually plot these somewhere in the framebuffer
599 init. This is just to demonstrate that they do, in fact,
601 for (y
= 0; y
< 32; y
++) {
602 printk(KERN_INFO
" ");
603 for (x
= 0; x
< 32; x
++) {
615 static int __init
nubus_get_vendorinfo(struct nubus_board
* board
,
616 const struct nubus_dirent
* parent
)
618 struct nubus_dir dir
;
619 struct nubus_dirent ent
;
620 static char* vendor_fields
[6] = {"ID", "serial", "revision",
621 "part", "date", "unknown field"};
623 printk(KERN_INFO
" vendor info:\n");
624 nubus_get_subdir(parent
, &dir
);
625 if (console_loglevel
>= 10)
626 printk(KERN_DEBUG
"nubus_get_vendorinfo: parent is 0x%p, dir is 0x%p\n",
627 parent
->base
, dir
.base
);
629 while(nubus_readdir(&dir
, &ent
) != -1)
633 /* These are all strings, we think */
634 nubus_get_rsrc_str(name
, &ent
, 64);
637 printk(KERN_INFO
" %s: %s\n",
638 vendor_fields
[ent
.type
-1], name
);
643 static int __init
nubus_get_board_resource(struct nubus_board
* board
, int slot
,
644 const struct nubus_dirent
* parent
)
646 struct nubus_dir dir
;
647 struct nubus_dirent ent
;
649 nubus_get_subdir(parent
, &dir
);
650 if (console_loglevel
>= 10)
651 printk(KERN_DEBUG
"nubus_get_board_resource: parent is 0x%p, dir is 0x%p\n",
652 parent
->base
, dir
.base
);
654 while(nubus_readdir(&dir
, &ent
) != -1)
657 case NUBUS_RESID_TYPE
:
659 unsigned short nbtdata
[4];
660 /* This type is always the same, and is not
661 useful except insofar as it tells us that
662 we really are looking at a board resource. */
663 nubus_get_rsrc_mem(nbtdata
, &ent
, 8);
664 printk(KERN_INFO
" type: [cat 0x%x type 0x%x hw 0x%x sw 0x%x]\n",
665 nbtdata
[0], nbtdata
[1], nbtdata
[2],
667 if (nbtdata
[0] != 1 || nbtdata
[1] != 0 ||
668 nbtdata
[2] != 0 || nbtdata
[3] != 0)
669 printk(KERN_ERR
"this sResource is not a board resource!\n");
672 case NUBUS_RESID_NAME
:
673 nubus_get_rsrc_str(board
->name
, &ent
, 64);
674 printk(KERN_INFO
" name: %s\n", board
->name
);
676 case NUBUS_RESID_ICON
:
677 nubus_get_icon(board
, &ent
);
679 case NUBUS_RESID_BOARDID
:
680 printk(KERN_INFO
" board id: 0x%x\n", ent
.data
);
682 case NUBUS_RESID_PRIMARYINIT
:
683 printk(KERN_INFO
" primary init offset: 0x%06x\n", ent
.data
);
685 case NUBUS_RESID_VENDORINFO
:
686 nubus_get_vendorinfo(board
, &ent
);
688 case NUBUS_RESID_FLAGS
:
689 printk(KERN_INFO
" flags: 0x%06x\n", ent
.data
);
691 case NUBUS_RESID_HWDEVID
:
692 printk(KERN_INFO
" hwdevid: 0x%06x\n", ent
.data
);
694 case NUBUS_RESID_SECONDINIT
:
695 printk(KERN_INFO
" secondary init offset: 0x%06x\n", ent
.data
);
697 /* WTF isn't this in the functional resources? */
698 case NUBUS_RESID_VIDNAMES
:
699 nubus_get_vidnames(board
, &ent
);
701 /* Same goes for this */
702 case NUBUS_RESID_VIDMODES
:
703 printk(KERN_INFO
" video mode parameter directory offset: 0x%06x\n",
707 printk(KERN_INFO
" unknown resource %02X, data 0x%06x\n",
714 /* Attempt to bypass the somewhat non-obvious arrangement of
715 sResources in the motherboard ROM */
716 static void __init
nubus_find_rom_dir(struct nubus_board
* board
)
719 unsigned char* romdir
;
720 struct nubus_dir dir
;
721 struct nubus_dirent ent
;
723 /* Check for the extra directory just under the format block */
725 nubus_rewind(&rp
, 4, board
->lanes
);
726 if (nubus_get_rom(&rp
, 4, board
->lanes
) != NUBUS_TEST_PATTERN
) {
727 /* OK, the ROM was telling the truth */
728 board
->directory
= board
->fblock
;
729 nubus_move(&board
->directory
,
730 nubus_expand32(board
->doffset
),
735 /* On "slot zero", you have to walk down a few more
736 directories to get to the equivalent of a real card's root
737 directory. We don't know what they were smoking when they
738 came up with this. */
739 romdir
= nubus_rom_addr(board
->slot
);
740 nubus_rewind(&romdir
, ROM_DIR_OFFSET
, board
->lanes
);
741 dir
.base
= dir
.ptr
= romdir
;
743 dir
.mask
= board
->lanes
;
745 /* This one points to an "Unknown Macintosh" directory */
746 if (nubus_readdir(&dir
, &ent
) == -1)
749 if (console_loglevel
>= 10)
750 printk(KERN_INFO
"nubus_get_rom_dir: entry %02x %06x\n", ent
.type
, ent
.data
);
751 /* This one takes us to where we want to go. */
752 if (nubus_readdir(&dir
, &ent
) == -1)
754 if (console_loglevel
>= 10)
755 printk(KERN_DEBUG
"nubus_get_rom_dir: entry %02x %06x\n", ent
.type
, ent
.data
);
756 nubus_get_subdir(&ent
, &dir
);
758 /* Resource ID 01, also an "Unknown Macintosh" */
759 if (nubus_readdir(&dir
, &ent
) == -1)
761 if (console_loglevel
>= 10)
762 printk(KERN_DEBUG
"nubus_get_rom_dir: entry %02x %06x\n", ent
.type
, ent
.data
);
764 /* FIXME: the first one is *not* always the right one. We
765 suspect this has something to do with the ROM revision.
766 "The HORROR ROM" (LC-series) uses 0x7e, while "The HORROR
767 Continues" (Q630) uses 0x7b. The DAFB Macs evidently use
768 something else. Please run "Slots" on your Mac (see
769 include/linux/nubus.h for where to get this program) and
770 tell us where the 'SiDirPtr' for Slot 0 is. If you feel
771 brave, you should also use MacsBug to walk down the ROM
772 directories like this function does and try to find the
773 path to that address... */
774 if (nubus_readdir(&dir
, &ent
) == -1)
776 if (console_loglevel
>= 10)
777 printk(KERN_DEBUG
"nubus_get_rom_dir: entry %02x %06x\n", ent
.type
, ent
.data
);
780 nubus_get_subdir(&ent
, &dir
);
781 board
->directory
= dir
.base
;
784 /* Even more evil laughter... */
786 board
->directory
= board
->fblock
;
787 nubus_move(&board
->directory
, nubus_expand32(board
->doffset
), board
->lanes
);
788 printk(KERN_ERR
"nubus_get_rom_dir: ROM weirdness! Notify the developers...\n");
791 /* Add a board (might be many devices) to the list */
792 static struct nubus_board
* __init
nubus_add_board(int slot
, int bytelanes
)
794 struct nubus_board
* board
;
795 struct nubus_board
** boardp
;
799 struct nubus_dir dir
;
800 struct nubus_dirent ent
;
802 /* Move to the start of the format block */
803 rp
= nubus_rom_addr(slot
);
804 nubus_rewind(&rp
, FORMAT_BLOCK_SIZE
, bytelanes
);
806 /* Actually we should probably panic if this fails */
807 if ((board
= kmalloc(sizeof(*board
), GFP_ATOMIC
)) == NULL
)
809 memset(board
, 0, sizeof(*board
));
812 /* Dump the format block for debugging purposes */
813 if (console_loglevel
>= 10) {
815 printk(KERN_DEBUG
"Slot %X, format block at 0x%p\n",
817 printk(KERN_DEBUG
"Format block: ");
818 for (i
= 0; i
< FORMAT_BLOCK_SIZE
; i
+= 4) {
819 unsigned short foo
, bar
;
820 foo
= nubus_get_rom(&rp
, 2, bytelanes
);
821 bar
= nubus_get_rom(&rp
, 2, bytelanes
);
822 printk("%04x %04x ", foo
, bar
);
829 board
->slot_addr
= (unsigned long) nubus_slot_addr(slot
);
830 board
->doffset
= nubus_get_rom(&rp
, 4, bytelanes
);
831 /* rom_length is *supposed* to be the total length of the
832 * ROM. In practice it is the "amount of ROM used to compute
833 * the CRC." So some jokers decide to set it to zero and
834 * set the crc to zero so they don't have to do any math.
835 * See the Performa 460 ROM, for example. Those Apple "engineers".
837 board
->rom_length
= nubus_get_rom(&rp
, 4, bytelanes
);
838 board
->crc
= nubus_get_rom(&rp
, 4, bytelanes
);
839 board
->rev
= nubus_get_rom(&rp
, 1, bytelanes
);
840 board
->format
= nubus_get_rom(&rp
,1, bytelanes
);
841 board
->lanes
= bytelanes
;
843 /* Directory offset should be small and negative... */
844 if(!(board
->doffset
& 0x00FF0000))
845 printk(KERN_WARNING
"Dodgy doffset!\n");
846 dpat
= nubus_get_rom(&rp
, 4, bytelanes
);
847 if(dpat
!= NUBUS_TEST_PATTERN
)
848 printk(KERN_WARNING
"Wrong test pattern %08lx!\n", dpat
);
851 * I wonder how the CRC is meant to work -
853 * CSA: According to MAC docs, not all cards pass the CRC anyway,
854 * since the initial Macintosh ROM releases skipped the check.
857 /* Attempt to work around slot zero weirdness */
858 nubus_find_rom_dir(board
);
859 nubus_get_root_dir(board
, &dir
);
861 /* We're ready to rock */
862 printk(KERN_INFO
"Slot %X:\n", slot
);
864 /* Each slot should have one board resource and any number of
865 functional resources. So we'll fill in some fields in the
866 struct nubus_board from the board resource, then walk down
867 the list of functional resources, spinning out a nubus_dev
869 if (nubus_readdir(&dir
, &ent
) == -1) {
870 /* We can't have this! */
871 printk(KERN_ERR
"Board resource not found!\n");
874 printk(KERN_INFO
" Board resource:\n");
875 nubus_get_board_resource(board
, slot
, &ent
);
878 /* Aaaarrrrgghh! The LC III motherboard has *two* board
879 resources. I have no idea WTF to do about this. */
881 while (nubus_readdir(&dir
, &ent
) != -1) {
882 struct nubus_dev
* dev
;
883 struct nubus_dev
** devp
;
884 dev
= nubus_get_functional_resource(board
, slot
, &ent
);
888 /* We zeroed this out above */
889 if (board
->first_dev
== NULL
)
890 board
->first_dev
= dev
;
892 /* Put it on the global NuBus device chain. Keep entries in order. */
893 for (devp
=&nubus_devices
; *devp
!=NULL
; devp
=&((*devp
)->next
))
899 /* Put it on the global NuBus board chain. Keep entries in order. */
900 for (boardp
=&nubus_boards
; *boardp
!=NULL
; boardp
=&((*boardp
)->next
))
908 void __init
nubus_probe_slot(int slot
)
914 rp
= nubus_rom_addr(slot
);
923 card_present
= hwreg_present(rp
);
924 restore_flags(flags
);
929 printk(KERN_DEBUG
"Now probing slot %X at %p\n", slot
, rp
);
934 /* The last byte of the format block consists of two
935 nybbles which are "mirror images" of each other.
936 These show us the valid bytelanes */
937 if ((((dp
>>4) ^ dp
) & 0x0F) != 0x0F)
939 /* Check that this value is actually *on* one of the
940 bytelanes it claims are valid! */
941 if ((dp
& 0x0F) >= (1<<i
))
944 /* Looks promising. Let's put it on the list. */
945 nubus_add_board(slot
, dp
);
951 #if defined(CONFIG_PROC_FS)
953 /* /proc/nubus stuff */
955 static int sprint_nubus_board(struct nubus_board
* board
, char* ptr
, int len
)
960 sprintf(ptr
, "Slot %X: %s\n",
961 board
->slot
, board
->name
);
966 static int nubus_read_proc(char *buf
, char **start
, off_t off
,
967 int count
, int *eof
, void *data
)
969 int nprinted
, len
, begin
= 0;
972 len
= sprintf(buf
, "Nubus devices found:\n");
973 /* Walk the list of NuBus boards */
974 for (board
= nubus_boards
; board
!= NULL
; board
= board
->next
)
976 nprinted
= sprint_nubus_board(board
, buf
+ len
, size
- len
);
980 if (len
+begin
< off
) {
984 if (len
+begin
>= off
+count
)
987 if (slot
==16 || len
+begin
< off
)
1000 void __init
nubus_scan_bus(void)
1003 /* This might not work on your machine */
1004 #ifdef I_WANT_TO_PROBE_SLOT_ZERO
1005 nubus_probe_slot(0);
1007 for(slot
= 9; slot
< 15; slot
++)
1009 nubus_probe_slot(slot
);
1013 void __init
nubus_init(void)
1018 /* Initialize the NuBus interrupts */
1025 #ifdef TRY_TO_DODGE_WSOD
1026 /* Rogue Ethernet interrupts can kill the machine if we don't
1027 do this. Obviously this is bogus. Hopefully the local VIA
1028 gurus can fix the real cause of the problem. */
1033 printk("NuBus: Scanning NuBus slots.\n");
1034 nubus_devices
= NULL
;
1035 nubus_boards
= NULL
;
1038 #ifdef CONFIG_PROC_FS
1039 create_proc_read_entry("nubus", 0, NULL
, nubus_read_proc
, NULL
);