2 * Macintosh Nubus Interface Code
4 * Originally by Alan Cox
6 * Mostly rewritten by David Huggins-Daines, C. Scott Ananian,
10 #include <linux/types.h>
11 #include <linux/kernel.h>
12 #include <linux/string.h>
13 #include <linux/nubus.h>
14 #include <linux/errno.h>
15 #include <linux/init.h>
16 #include <linux/delay.h>
17 #include <asm/setup.h>
18 #include <asm/system.h>
20 #include <asm/hwtest.h>
21 #include <linux/proc_fs.h>
22 #include <asm/mac_via.h>
23 #include <asm/mac_oss.h>
25 extern void via_nubus_init(void);
26 extern void oss_nubus_init(void);
30 /* This is, of course, the size in bytelanes, rather than the size in
32 #define FORMAT_BLOCK_SIZE 20
33 #define ROM_DIR_OFFSET 0x24
35 #define NUBUS_TEST_PATTERN 0x5A932BC7
37 /* Define this if you like to live dangerously - it is known not to
38 work on pretty much every machine except the Quadra 630 and the LC
40 #undef I_WANT_TO_PROBE_SLOT_ZERO
42 /* This sometimes helps combat failure to boot */
43 #undef TRY_TO_DODGE_WSOD
47 struct nubus_dev
* nubus_devices
;
48 struct nubus_board
* nubus_boards
;
50 /* Meaning of "bytelanes":
52 The card ROM may appear on any or all bytes of each long word in
53 NuBus memory. The low 4 bits of the "map" value found in the
54 format block (at the top of the slot address space, as well as at
55 the top of the MacOS ROM) tells us which bytelanes, i.e. which byte
56 offsets within each longword, are valid. Thus:
58 A map of 0x0f, as found in the MacOS ROM, means that all bytelanes
61 A map of 0xf0 means that no bytelanes are valid (We pray that we
62 will never encounter this, but stranger things have happened)
64 A map of 0xe1 means that only the MSB of each long word is actually
65 part of the card ROM. (We hope to never encounter NuBus on a
66 little-endian machine. Again, stranger things have happened)
68 A map of 0x78 means that only the LSB of each long word is valid.
70 Etcetera, etcetera. Hopefully this clears up some confusion over
71 what the following code actually does. */
73 static inline int not_useful(void *p
, int map
)
75 unsigned long pv
=(unsigned long)p
;
82 static unsigned long nubus_get_rom(unsigned char **ptr
, int len
, int map
)
84 /* This will hold the result */
86 unsigned char *p
= *ptr
;
91 while(not_useful(p
,map
))
100 static void nubus_rewind(unsigned char **ptr
, int len
, int map
)
102 unsigned char *p
=*ptr
;
106 printk(KERN_ERR
"rewind of 0x%08x!\n", len
);
113 while(not_useful(p
, map
));
119 static void nubus_advance(unsigned char **ptr
, int len
, int map
)
121 unsigned char *p
= *ptr
;
123 printk(KERN_ERR
"advance of 0x%08x!\n", len
);
126 while(not_useful(p
,map
))
134 static void nubus_move(unsigned char **ptr
, int len
, int map
)
137 nubus_advance(ptr
, len
, map
);
139 nubus_rewind(ptr
, -len
, map
);
142 /* Now, functions to read the sResource tree */
144 /* Each sResource entry consists of a 1-byte ID and a 3-byte data
145 field. If that data field contains an offset, then obviously we
146 have to expand it from a 24-bit signed number to a 32-bit signed
149 static inline long nubus_expand32(long foo
)
151 if(foo
& 0x00800000) /* 24bit negative */
156 static inline void *nubus_rom_addr(int slot
)
159 * Returns the first byte after the card. We then walk
160 * backwards to get the lane register and the config
162 return (void *)(0xF1000000+(slot
<<24));
165 static unsigned char *nubus_dirptr(const struct nubus_dirent
*nd
)
167 unsigned char *p
= nd
->base
;
168 /* Essentially, just step over the bytelanes using whatever
169 offset we might have found */
170 nubus_move(&p
, nubus_expand32(nd
->data
), nd
->mask
);
171 /* And return the value */
175 /* These two are for pulling resource data blocks (i.e. stuff that's
176 pointed to with offsets) out of the card ROM. */
178 void nubus_get_rsrc_mem(void *dest
, const struct nubus_dirent
* dirent
,
181 unsigned char *t
= (unsigned char *)dest
;
182 unsigned char *p
= nubus_dirptr(dirent
);
185 *t
++ = nubus_get_rom(&p
, 1, dirent
->mask
);
190 void nubus_get_rsrc_str(void *dest
, const struct nubus_dirent
* dirent
,
193 unsigned char *t
=(unsigned char *)dest
;
194 unsigned char *p
= nubus_dirptr(dirent
);
197 *t
= nubus_get_rom(&p
, 1, dirent
->mask
);
204 int nubus_get_root_dir(const struct nubus_board
* board
,
205 struct nubus_dir
* dir
)
207 dir
->ptr
= dir
->base
= board
->directory
;
209 dir
->mask
= board
->lanes
;
213 /* This is a slyly renamed version of the above */
214 int nubus_get_func_dir(const struct nubus_dev
* dev
,
215 struct nubus_dir
* dir
)
217 dir
->ptr
= dir
->base
= dev
->directory
;
219 dir
->mask
= dev
->board
->lanes
;
223 int nubus_get_board_dir(const struct nubus_board
* board
,
224 struct nubus_dir
* dir
)
226 struct nubus_dirent ent
;
228 dir
->ptr
= dir
->base
= board
->directory
;
230 dir
->mask
= board
->lanes
;
232 /* Now dereference it (the first directory is always the board
234 if (nubus_readdir(dir
, &ent
) == -1)
236 if (nubus_get_subdir(&ent
, dir
) == -1)
241 int nubus_get_subdir(const struct nubus_dirent
*ent
,
242 struct nubus_dir
*dir
)
244 dir
->ptr
= dir
->base
= nubus_dirptr(ent
);
246 dir
->mask
= ent
->mask
;
250 int nubus_readdir(struct nubus_dir
*nd
, struct nubus_dirent
*ent
)
256 /* Do this first, otherwise nubus_rewind & co are off by 4 */
259 /* This moves nd->ptr forward */
260 resid
= nubus_get_rom(&nd
->ptr
, 4, nd
->mask
);
262 /* EOL marker, as per the Apple docs */
263 if((resid
&0xff000000) == 0xff000000)
265 /* Mark it as done */
270 /* First byte is the resource ID */
271 ent
->type
= resid
>> 24;
272 /* Low 3 bytes might contain data (or might not) */
273 ent
->data
= resid
& 0xffffff;
274 ent
->mask
= nd
->mask
;
278 int nubus_rewinddir(struct nubus_dir
* dir
)
280 dir
->ptr
= dir
->base
;
284 /* Driver interface functions, more or less like in pci.c */
287 nubus_find_device(unsigned short category
,
289 unsigned short dr_hw
,
290 unsigned short dr_sw
,
291 const struct nubus_dev
* from
)
293 struct nubus_dev
* itor
=
294 from
? from
->next
: nubus_devices
;
297 if (itor
->category
== category
298 && itor
->type
== type
299 && itor
->dr_hw
== dr_hw
300 && itor
->dr_sw
== dr_sw
)
308 nubus_find_type(unsigned short category
,
310 const struct nubus_dev
* from
)
312 struct nubus_dev
* itor
=
313 from
? from
->next
: nubus_devices
;
316 if (itor
->category
== category
317 && itor
->type
== type
)
325 nubus_find_slot(unsigned int slot
,
326 const struct nubus_dev
* from
)
328 struct nubus_dev
* itor
=
329 from
? from
->next
: nubus_devices
;
332 if (itor
->board
->slot
== slot
)
340 nubus_find_rsrc(struct nubus_dir
* dir
, unsigned char rsrc_type
,
341 struct nubus_dirent
* ent
)
343 while (nubus_readdir(dir
, ent
) != -1) {
344 if (ent
->type
== rsrc_type
)
350 /* Initialization functions - decide which slots contain stuff worth
351 looking at, and print out lots and lots of information from the
354 /* FIXME: A lot of this stuff will eventually be useful after
355 initializaton, for intelligently probing Ethernet and video chips,
356 among other things. The rest of it should go in the /proc code.
357 For now, we just use it to give verbose boot logs. */
359 static int __init
nubus_show_display_resource(struct nubus_dev
* dev
,
360 const struct nubus_dirent
* ent
)
363 case NUBUS_RESID_GAMMADIR
:
364 printk(KERN_INFO
" gamma directory offset: 0x%06x\n", ent
->data
);
366 case 0x0080 ... 0x0085:
367 printk(KERN_INFO
" mode %02X info offset: 0x%06x\n",
368 ent
->type
, ent
->data
);
371 printk(KERN_INFO
" unknown resource %02X, data 0x%06x\n",
372 ent
->type
, ent
->data
);
377 static int __init
nubus_show_network_resource(struct nubus_dev
* dev
,
378 const struct nubus_dirent
* ent
)
381 case NUBUS_RESID_MAC_ADDRESS
:
386 nubus_get_rsrc_mem(addr
, ent
, 6);
387 printk(KERN_INFO
" MAC address: ");
388 for (i
= 0; i
< 6; i
++)
389 printk("%02x%s", addr
[i
] & 0xff,
395 printk(KERN_INFO
" unknown resource %02X, data 0x%06x\n",
396 ent
->type
, ent
->data
);
401 static int __init
nubus_show_cpu_resource(struct nubus_dev
* dev
,
402 const struct nubus_dirent
* ent
)
405 case NUBUS_RESID_MEMINFO
:
407 unsigned long meminfo
[2];
408 nubus_get_rsrc_mem(&meminfo
, ent
, 8);
409 printk(KERN_INFO
" memory: [ 0x%08lx 0x%08lx ]\n",
410 meminfo
[0], meminfo
[1]);
413 case NUBUS_RESID_ROMINFO
:
415 unsigned long rominfo
[2];
416 nubus_get_rsrc_mem(&rominfo
, ent
, 8);
417 printk(KERN_INFO
" ROM: [ 0x%08lx 0x%08lx ]\n",
418 rominfo
[0], rominfo
[1]);
422 printk(KERN_INFO
" unknown resource %02X, data 0x%06x\n",
423 ent
->type
, ent
->data
);
428 static int __init
nubus_show_private_resource(struct nubus_dev
* dev
,
429 const struct nubus_dirent
* ent
)
431 switch (dev
->category
) {
432 case NUBUS_CAT_DISPLAY
:
433 nubus_show_display_resource(dev
, ent
);
435 case NUBUS_CAT_NETWORK
:
436 nubus_show_network_resource(dev
, ent
);
439 nubus_show_cpu_resource(dev
, ent
);
442 printk(KERN_INFO
" unknown resource %02X, data 0x%06x\n",
443 ent
->type
, ent
->data
);
448 static struct nubus_dev
* __init
449 nubus_get_functional_resource(struct nubus_board
* board
,
451 const struct nubus_dirent
* parent
)
453 struct nubus_dir dir
;
454 struct nubus_dirent ent
;
455 struct nubus_dev
* dev
;
457 printk(KERN_INFO
" Function 0x%02x:\n", parent
->type
);
458 nubus_get_subdir(parent
, &dir
);
460 /* Apple seems to have botched the ROM on the IIx */
461 if (slot
== 0 && (unsigned long)dir
.base
% 2)
464 if (console_loglevel
>= 10)
465 printk(KERN_DEBUG
"nubus_get_functional_resource: parent is 0x%p, dir is 0x%p\n",
466 parent
->base
, dir
.base
);
468 /* Actually we should probably panic if this fails */
469 if ((dev
= kzalloc(sizeof(*dev
), GFP_ATOMIC
)) == NULL
)
471 dev
->resid
= parent
->type
;
472 dev
->directory
= dir
.base
;
475 while (nubus_readdir(&dir
, &ent
) != -1)
479 case NUBUS_RESID_TYPE
:
481 unsigned short nbtdata
[4];
482 nubus_get_rsrc_mem(nbtdata
, &ent
, 8);
483 dev
->category
= nbtdata
[0];
484 dev
->type
= nbtdata
[1];
485 dev
->dr_sw
= nbtdata
[2];
486 dev
->dr_hw
= nbtdata
[3];
487 printk(KERN_INFO
" type: [cat 0x%x type 0x%x hw 0x%x sw 0x%x]\n",
488 nbtdata
[0], nbtdata
[1], nbtdata
[2], nbtdata
[3]);
491 case NUBUS_RESID_NAME
:
493 nubus_get_rsrc_str(dev
->name
, &ent
, 64);
494 printk(KERN_INFO
" name: %s\n", dev
->name
);
497 case NUBUS_RESID_DRVRDIR
:
499 /* MacOS driver. If we were NetBSD we might
501 struct nubus_dir drvr_dir
;
502 struct nubus_dirent drvr_ent
;
503 nubus_get_subdir(&ent
, &drvr_dir
);
504 nubus_readdir(&drvr_dir
, &drvr_ent
);
505 dev
->driver
= nubus_dirptr(&drvr_ent
);
506 printk(KERN_INFO
" driver at: 0x%p\n",
510 case NUBUS_RESID_MINOR_BASEOS
:
511 /* We will need this in order to support
512 multiple framebuffers. It might be handy
513 for Ethernet as well */
514 nubus_get_rsrc_mem(&dev
->iobase
, &ent
, 4);
515 printk(KERN_INFO
" memory offset: 0x%08lx\n",
518 case NUBUS_RESID_MINOR_LENGTH
:
520 nubus_get_rsrc_mem(&dev
->iosize
, &ent
, 4);
521 printk(KERN_INFO
" memory length: 0x%08lx\n",
524 case NUBUS_RESID_FLAGS
:
525 dev
->flags
= ent
.data
;
526 printk(KERN_INFO
" flags: 0x%06x\n", dev
->flags
);
528 case NUBUS_RESID_HWDEVID
:
529 dev
->hwdevid
= ent
.data
;
530 printk(KERN_INFO
" hwdevid: 0x%06x\n", dev
->hwdevid
);
533 /* Local/Private resources have their own
535 nubus_show_private_resource(dev
, &ent
);
543 static int __init
nubus_get_vidnames(struct nubus_board
* board
,
544 const struct nubus_dirent
* parent
)
546 struct nubus_dir dir
;
547 struct nubus_dirent ent
;
548 /* FIXME: obviously we want to put this in a header file soon */
551 /* Don't know what this is yet */
553 /* Longest one I've seen so far is 26 characters */
557 printk(KERN_INFO
" video modes supported:\n");
558 nubus_get_subdir(parent
, &dir
);
559 if (console_loglevel
>= 10)
560 printk(KERN_DEBUG
"nubus_get_vidnames: parent is 0x%p, dir is 0x%p\n",
561 parent
->base
, dir
.base
);
563 while(nubus_readdir(&dir
, &ent
) != -1)
568 /* First get the length */
569 nubus_get_rsrc_mem(&size
, &ent
, 4);
571 /* Now clobber the whole thing */
572 if (size
> sizeof(mode
) - 1)
573 size
= sizeof(mode
) - 1;
574 memset(&mode
, 0, sizeof(mode
));
575 nubus_get_rsrc_mem(&mode
, &ent
, size
);
576 printk (KERN_INFO
" %02X: (%02X) %s\n", ent
.type
,
582 /* This is *really* cool. */
583 static int __init
nubus_get_icon(struct nubus_board
* board
,
584 const struct nubus_dirent
* ent
)
586 /* Should be 32x32 if my memory serves me correctly */
587 unsigned char icon
[128];
590 nubus_get_rsrc_mem(&icon
, ent
, 128);
591 printk(KERN_INFO
" icon:\n");
593 /* We should actually plot these somewhere in the framebuffer
594 init. This is just to demonstrate that they do, in fact,
596 for (y
= 0; y
< 32; y
++) {
597 printk(KERN_INFO
" ");
598 for (x
= 0; x
< 32; x
++) {
610 static int __init
nubus_get_vendorinfo(struct nubus_board
* board
,
611 const struct nubus_dirent
* parent
)
613 struct nubus_dir dir
;
614 struct nubus_dirent ent
;
615 static char* vendor_fields
[6] = {"ID", "serial", "revision",
616 "part", "date", "unknown field"};
618 printk(KERN_INFO
" vendor info:\n");
619 nubus_get_subdir(parent
, &dir
);
620 if (console_loglevel
>= 10)
621 printk(KERN_DEBUG
"nubus_get_vendorinfo: parent is 0x%p, dir is 0x%p\n",
622 parent
->base
, dir
.base
);
624 while(nubus_readdir(&dir
, &ent
) != -1)
628 /* These are all strings, we think */
629 nubus_get_rsrc_str(name
, &ent
, 64);
632 printk(KERN_INFO
" %s: %s\n",
633 vendor_fields
[ent
.type
-1], name
);
638 static int __init
nubus_get_board_resource(struct nubus_board
* board
, int slot
,
639 const struct nubus_dirent
* parent
)
641 struct nubus_dir dir
;
642 struct nubus_dirent ent
;
644 nubus_get_subdir(parent
, &dir
);
645 if (console_loglevel
>= 10)
646 printk(KERN_DEBUG
"nubus_get_board_resource: parent is 0x%p, dir is 0x%p\n",
647 parent
->base
, dir
.base
);
649 while(nubus_readdir(&dir
, &ent
) != -1)
652 case NUBUS_RESID_TYPE
:
654 unsigned short nbtdata
[4];
655 /* This type is always the same, and is not
656 useful except insofar as it tells us that
657 we really are looking at a board resource. */
658 nubus_get_rsrc_mem(nbtdata
, &ent
, 8);
659 printk(KERN_INFO
" type: [cat 0x%x type 0x%x hw 0x%x sw 0x%x]\n",
660 nbtdata
[0], nbtdata
[1], nbtdata
[2],
662 if (nbtdata
[0] != 1 || nbtdata
[1] != 0 ||
663 nbtdata
[2] != 0 || nbtdata
[3] != 0)
664 printk(KERN_ERR
"this sResource is not a board resource!\n");
667 case NUBUS_RESID_NAME
:
668 nubus_get_rsrc_str(board
->name
, &ent
, 64);
669 printk(KERN_INFO
" name: %s\n", board
->name
);
671 case NUBUS_RESID_ICON
:
672 nubus_get_icon(board
, &ent
);
674 case NUBUS_RESID_BOARDID
:
675 printk(KERN_INFO
" board id: 0x%x\n", ent
.data
);
677 case NUBUS_RESID_PRIMARYINIT
:
678 printk(KERN_INFO
" primary init offset: 0x%06x\n", ent
.data
);
680 case NUBUS_RESID_VENDORINFO
:
681 nubus_get_vendorinfo(board
, &ent
);
683 case NUBUS_RESID_FLAGS
:
684 printk(KERN_INFO
" flags: 0x%06x\n", ent
.data
);
686 case NUBUS_RESID_HWDEVID
:
687 printk(KERN_INFO
" hwdevid: 0x%06x\n", ent
.data
);
689 case NUBUS_RESID_SECONDINIT
:
690 printk(KERN_INFO
" secondary init offset: 0x%06x\n", ent
.data
);
692 /* WTF isn't this in the functional resources? */
693 case NUBUS_RESID_VIDNAMES
:
694 nubus_get_vidnames(board
, &ent
);
696 /* Same goes for this */
697 case NUBUS_RESID_VIDMODES
:
698 printk(KERN_INFO
" video mode parameter directory offset: 0x%06x\n",
702 printk(KERN_INFO
" unknown resource %02X, data 0x%06x\n",
709 /* Attempt to bypass the somewhat non-obvious arrangement of
710 sResources in the motherboard ROM */
711 static void __init
nubus_find_rom_dir(struct nubus_board
* board
)
714 unsigned char* romdir
;
715 struct nubus_dir dir
;
716 struct nubus_dirent ent
;
718 /* Check for the extra directory just under the format block */
720 nubus_rewind(&rp
, 4, board
->lanes
);
721 if (nubus_get_rom(&rp
, 4, board
->lanes
) != NUBUS_TEST_PATTERN
) {
722 /* OK, the ROM was telling the truth */
723 board
->directory
= board
->fblock
;
724 nubus_move(&board
->directory
,
725 nubus_expand32(board
->doffset
),
730 /* On "slot zero", you have to walk down a few more
731 directories to get to the equivalent of a real card's root
732 directory. We don't know what they were smoking when they
733 came up with this. */
734 romdir
= nubus_rom_addr(board
->slot
);
735 nubus_rewind(&romdir
, ROM_DIR_OFFSET
, board
->lanes
);
736 dir
.base
= dir
.ptr
= romdir
;
738 dir
.mask
= board
->lanes
;
740 /* This one points to an "Unknown Macintosh" directory */
741 if (nubus_readdir(&dir
, &ent
) == -1)
744 if (console_loglevel
>= 10)
745 printk(KERN_INFO
"nubus_get_rom_dir: entry %02x %06x\n", ent
.type
, ent
.data
);
746 /* This one takes us to where we want to go. */
747 if (nubus_readdir(&dir
, &ent
) == -1)
749 if (console_loglevel
>= 10)
750 printk(KERN_DEBUG
"nubus_get_rom_dir: entry %02x %06x\n", ent
.type
, ent
.data
);
751 nubus_get_subdir(&ent
, &dir
);
753 /* Resource ID 01, also an "Unknown Macintosh" */
754 if (nubus_readdir(&dir
, &ent
) == -1)
756 if (console_loglevel
>= 10)
757 printk(KERN_DEBUG
"nubus_get_rom_dir: entry %02x %06x\n", ent
.type
, ent
.data
);
759 /* FIXME: the first one is *not* always the right one. We
760 suspect this has something to do with the ROM revision.
761 "The HORROR ROM" (LC-series) uses 0x7e, while "The HORROR
762 Continues" (Q630) uses 0x7b. The DAFB Macs evidently use
763 something else. Please run "Slots" on your Mac (see
764 include/linux/nubus.h for where to get this program) and
765 tell us where the 'SiDirPtr' for Slot 0 is. If you feel
766 brave, you should also use MacsBug to walk down the ROM
767 directories like this function does and try to find the
768 path to that address... */
769 if (nubus_readdir(&dir
, &ent
) == -1)
771 if (console_loglevel
>= 10)
772 printk(KERN_DEBUG
"nubus_get_rom_dir: entry %02x %06x\n", ent
.type
, ent
.data
);
775 nubus_get_subdir(&ent
, &dir
);
776 board
->directory
= dir
.base
;
779 /* Even more evil laughter... */
781 board
->directory
= board
->fblock
;
782 nubus_move(&board
->directory
, nubus_expand32(board
->doffset
), board
->lanes
);
783 printk(KERN_ERR
"nubus_get_rom_dir: ROM weirdness! Notify the developers...\n");
786 /* Add a board (might be many devices) to the list */
787 static struct nubus_board
* __init
nubus_add_board(int slot
, int bytelanes
)
789 struct nubus_board
* board
;
790 struct nubus_board
** boardp
;
794 struct nubus_dir dir
;
795 struct nubus_dirent ent
;
797 /* Move to the start of the format block */
798 rp
= nubus_rom_addr(slot
);
799 nubus_rewind(&rp
, FORMAT_BLOCK_SIZE
, bytelanes
);
801 /* Actually we should probably panic if this fails */
802 if ((board
= kzalloc(sizeof(*board
), GFP_ATOMIC
)) == NULL
)
806 /* Dump the format block for debugging purposes */
807 if (console_loglevel
>= 10) {
809 printk(KERN_DEBUG
"Slot %X, format block at 0x%p\n",
811 printk(KERN_DEBUG
"Format block: ");
812 for (i
= 0; i
< FORMAT_BLOCK_SIZE
; i
+= 4) {
813 unsigned short foo
, bar
;
814 foo
= nubus_get_rom(&rp
, 2, bytelanes
);
815 bar
= nubus_get_rom(&rp
, 2, bytelanes
);
816 printk("%04x %04x ", foo
, bar
);
823 board
->slot_addr
= (unsigned long) nubus_slot_addr(slot
);
824 board
->doffset
= nubus_get_rom(&rp
, 4, bytelanes
);
825 /* rom_length is *supposed* to be the total length of the
826 * ROM. In practice it is the "amount of ROM used to compute
827 * the CRC." So some jokers decide to set it to zero and
828 * set the crc to zero so they don't have to do any math.
829 * See the Performa 460 ROM, for example. Those Apple "engineers".
831 board
->rom_length
= nubus_get_rom(&rp
, 4, bytelanes
);
832 board
->crc
= nubus_get_rom(&rp
, 4, bytelanes
);
833 board
->rev
= nubus_get_rom(&rp
, 1, bytelanes
);
834 board
->format
= nubus_get_rom(&rp
,1, bytelanes
);
835 board
->lanes
= bytelanes
;
837 /* Directory offset should be small and negative... */
838 if(!(board
->doffset
& 0x00FF0000))
839 printk(KERN_WARNING
"Dodgy doffset!\n");
840 dpat
= nubus_get_rom(&rp
, 4, bytelanes
);
841 if(dpat
!= NUBUS_TEST_PATTERN
)
842 printk(KERN_WARNING
"Wrong test pattern %08lx!\n", dpat
);
845 * I wonder how the CRC is meant to work -
847 * CSA: According to MAC docs, not all cards pass the CRC anyway,
848 * since the initial Macintosh ROM releases skipped the check.
851 /* Attempt to work around slot zero weirdness */
852 nubus_find_rom_dir(board
);
853 nubus_get_root_dir(board
, &dir
);
855 /* We're ready to rock */
856 printk(KERN_INFO
"Slot %X:\n", slot
);
858 /* Each slot should have one board resource and any number of
859 functional resources. So we'll fill in some fields in the
860 struct nubus_board from the board resource, then walk down
861 the list of functional resources, spinning out a nubus_dev
863 if (nubus_readdir(&dir
, &ent
) == -1) {
864 /* We can't have this! */
865 printk(KERN_ERR
"Board resource not found!\n");
868 printk(KERN_INFO
" Board resource:\n");
869 nubus_get_board_resource(board
, slot
, &ent
);
872 /* Aaaarrrrgghh! The LC III motherboard has *two* board
873 resources. I have no idea WTF to do about this. */
875 while (nubus_readdir(&dir
, &ent
) != -1) {
876 struct nubus_dev
* dev
;
877 struct nubus_dev
** devp
;
878 dev
= nubus_get_functional_resource(board
, slot
, &ent
);
882 /* We zeroed this out above */
883 if (board
->first_dev
== NULL
)
884 board
->first_dev
= dev
;
886 /* Put it on the global NuBus device chain. Keep entries in order. */
887 for (devp
=&nubus_devices
; *devp
!=NULL
; devp
=&((*devp
)->next
))
893 /* Put it on the global NuBus board chain. Keep entries in order. */
894 for (boardp
=&nubus_boards
; *boardp
!=NULL
; boardp
=&((*boardp
)->next
))
902 void __init
nubus_probe_slot(int slot
)
908 rp
= nubus_rom_addr(slot
);
915 local_irq_save(flags
);
916 card_present
= hwreg_present(rp
);
917 local_irq_restore(flags
);
922 printk(KERN_DEBUG
"Now probing slot %X at %p\n", slot
, rp
);
927 /* The last byte of the format block consists of two
928 nybbles which are "mirror images" of each other.
929 These show us the valid bytelanes */
930 if ((((dp
>>4) ^ dp
) & 0x0F) != 0x0F)
932 /* Check that this value is actually *on* one of the
933 bytelanes it claims are valid! */
934 if ((dp
& 0x0F) >= (1<<i
))
937 /* Looks promising. Let's put it on the list. */
938 nubus_add_board(slot
, dp
);
944 #if defined(CONFIG_PROC_FS)
946 /* /proc/nubus stuff */
948 static int sprint_nubus_board(struct nubus_board
* board
, char* ptr
, int len
)
953 sprintf(ptr
, "Slot %X: %s\n",
954 board
->slot
, board
->name
);
959 static int nubus_read_proc(char *page
, char **start
, off_t off
,
960 int count
, int *eof
, void *data
)
962 int nprinted
, len
, begin
= 0;
963 int size
= PAGE_SIZE
;
964 struct nubus_board
* board
;
966 len
= sprintf(page
, "Nubus devices found:\n");
967 /* Walk the list of NuBus boards */
968 for (board
= nubus_boards
; board
!= NULL
; board
= board
->next
)
970 nprinted
= sprint_nubus_board(board
, page
+ len
, size
- len
);
974 if (len
+begin
< off
) {
978 if (len
+begin
>= off
+count
)
994 void __init
nubus_scan_bus(void)
997 /* This might not work on your machine */
998 #ifdef I_WANT_TO_PROBE_SLOT_ZERO
1001 for(slot
= 9; slot
< 15; slot
++)
1003 nubus_probe_slot(slot
);
1007 static int __init
nubus_init(void)
1012 /* Initialize the NuBus interrupts */
1019 #ifdef TRY_TO_DODGE_WSOD
1020 /* Rogue Ethernet interrupts can kill the machine if we don't
1021 do this. Obviously this is bogus. Hopefully the local VIA
1022 gurus can fix the real cause of the problem. */
1027 printk("NuBus: Scanning NuBus slots.\n");
1028 nubus_devices
= NULL
;
1029 nubus_boards
= NULL
;
1032 #ifdef CONFIG_PROC_FS
1033 create_proc_read_entry("nubus", 0, NULL
, nubus_read_proc
, NULL
);
1039 subsys_initcall(nubus_init
);