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/types.h>
12 #include <linux/kernel.h>
13 #include <linux/string.h>
14 #include <linux/nubus.h>
15 #include <linux/errno.h>
16 #include <linux/init.h>
17 #include <linux/delay.h>
18 #include <asm/setup.h>
19 #include <asm/system.h>
21 #include <asm/hwtest.h>
22 #include <linux/proc_fs.h>
23 #include <asm/mac_via.h>
24 #include <asm/mac_oss.h>
26 extern void via_nubus_init(void);
27 extern void oss_nubus_init(void);
31 /* This is, of course, the size in bytelanes, rather than the size in
33 #define FORMAT_BLOCK_SIZE 20
34 #define ROM_DIR_OFFSET 0x24
36 #define NUBUS_TEST_PATTERN 0x5A932BC7
38 /* Define this if you like to live dangerously - it is known not to
39 work on pretty much every machine except the Quadra 630 and the LC
41 #undef I_WANT_TO_PROBE_SLOT_ZERO
43 /* This sometimes helps combat failure to boot */
44 #undef TRY_TO_DODGE_WSOD
48 struct nubus_dev
* nubus_devices
;
49 struct nubus_board
* nubus_boards
;
51 /* Meaning of "bytelanes":
53 The card ROM may appear on any or all bytes of each long word in
54 NuBus memory. The low 4 bits of the "map" value found in the
55 format block (at the top of the slot address space, as well as at
56 the top of the MacOS ROM) tells us which bytelanes, i.e. which byte
57 offsets within each longword, are valid. Thus:
59 A map of 0x0f, as found in the MacOS ROM, means that all bytelanes
62 A map of 0xf0 means that no bytelanes are valid (We pray that we
63 will never encounter this, but stranger things have happened)
65 A map of 0xe1 means that only the MSB of each long word is actually
66 part of the card ROM. (We hope to never encounter NuBus on a
67 little-endian machine. Again, stranger things have happened)
69 A map of 0x78 means that only the LSB of each long word is valid.
71 Etcetera, etcetera. Hopefully this clears up some confusion over
72 what the following code actually does. */
74 static inline int not_useful(void *p
, int map
)
76 unsigned long pv
=(unsigned long)p
;
83 static unsigned long nubus_get_rom(unsigned char **ptr
, int len
, int map
)
85 /* This will hold the result */
87 unsigned char *p
= *ptr
;
92 while(not_useful(p
,map
))
101 static void nubus_rewind(unsigned char **ptr
, int len
, int map
)
103 unsigned char *p
=*ptr
;
107 printk(KERN_ERR
"rewind of 0x%08x!\n", len
);
114 while(not_useful(p
, map
));
120 static void nubus_advance(unsigned char **ptr
, int len
, int map
)
122 unsigned char *p
= *ptr
;
124 printk(KERN_ERR
"advance of 0x%08x!\n", len
);
127 while(not_useful(p
,map
))
135 static void nubus_move(unsigned char **ptr
, int len
, int map
)
138 nubus_advance(ptr
, len
, map
);
140 nubus_rewind(ptr
, -len
, map
);
143 /* Now, functions to read the sResource tree */
145 /* Each sResource entry consists of a 1-byte ID and a 3-byte data
146 field. If that data field contains an offset, then obviously we
147 have to expand it from a 24-bit signed number to a 32-bit signed
150 static inline long nubus_expand32(long foo
)
152 if(foo
& 0x00800000) /* 24bit negative */
157 static inline void *nubus_rom_addr(int slot
)
160 * Returns the first byte after the card. We then walk
161 * backwards to get the lane register and the config
163 return (void *)(0xF1000000+(slot
<<24));
166 static unsigned char *nubus_dirptr(const struct nubus_dirent
*nd
)
168 unsigned char *p
= nd
->base
;
169 /* Essentially, just step over the bytelanes using whatever
170 offset we might have found */
171 nubus_move(&p
, nubus_expand32(nd
->data
), nd
->mask
);
172 /* And return the value */
176 /* These two are for pulling resource data blocks (i.e. stuff that's
177 pointed to with offsets) out of the card ROM. */
179 void nubus_get_rsrc_mem(void *dest
, const struct nubus_dirent
* dirent
,
182 unsigned char *t
= (unsigned char *)dest
;
183 unsigned char *p
= nubus_dirptr(dirent
);
186 *t
++ = nubus_get_rom(&p
, 1, dirent
->mask
);
191 void nubus_get_rsrc_str(void *dest
, const struct nubus_dirent
* dirent
,
194 unsigned char *t
=(unsigned char *)dest
;
195 unsigned char *p
= nubus_dirptr(dirent
);
198 *t
= nubus_get_rom(&p
, 1, dirent
->mask
);
205 int nubus_get_root_dir(const struct nubus_board
* board
,
206 struct nubus_dir
* dir
)
208 dir
->ptr
= dir
->base
= board
->directory
;
210 dir
->mask
= board
->lanes
;
214 /* This is a slyly renamed version of the above */
215 int nubus_get_func_dir(const struct nubus_dev
* dev
,
216 struct nubus_dir
* dir
)
218 dir
->ptr
= dir
->base
= dev
->directory
;
220 dir
->mask
= dev
->board
->lanes
;
224 int nubus_get_board_dir(const struct nubus_board
* board
,
225 struct nubus_dir
* dir
)
227 struct nubus_dirent ent
;
229 dir
->ptr
= dir
->base
= board
->directory
;
231 dir
->mask
= board
->lanes
;
233 /* Now dereference it (the first directory is always the board
235 if (nubus_readdir(dir
, &ent
) == -1)
237 if (nubus_get_subdir(&ent
, dir
) == -1)
242 int nubus_get_subdir(const struct nubus_dirent
*ent
,
243 struct nubus_dir
*dir
)
245 dir
->ptr
= dir
->base
= nubus_dirptr(ent
);
247 dir
->mask
= ent
->mask
;
251 int nubus_readdir(struct nubus_dir
*nd
, struct nubus_dirent
*ent
)
257 /* Do this first, otherwise nubus_rewind & co are off by 4 */
260 /* This moves nd->ptr forward */
261 resid
= nubus_get_rom(&nd
->ptr
, 4, nd
->mask
);
263 /* EOL marker, as per the Apple docs */
264 if((resid
&0xff000000) == 0xff000000)
266 /* Mark it as done */
271 /* First byte is the resource ID */
272 ent
->type
= resid
>> 24;
273 /* Low 3 bytes might contain data (or might not) */
274 ent
->data
= resid
& 0xffffff;
275 ent
->mask
= nd
->mask
;
279 int nubus_rewinddir(struct nubus_dir
* dir
)
281 dir
->ptr
= dir
->base
;
285 /* Driver interface functions, more or less like in pci.c */
288 nubus_find_device(unsigned short category
,
290 unsigned short dr_hw
,
291 unsigned short dr_sw
,
292 const struct nubus_dev
* from
)
294 struct nubus_dev
* itor
=
295 from
? from
->next
: nubus_devices
;
298 if (itor
->category
== category
299 && itor
->type
== type
300 && itor
->dr_hw
== dr_hw
301 && itor
->dr_sw
== dr_sw
)
309 nubus_find_type(unsigned short category
,
311 const struct nubus_dev
* from
)
313 struct nubus_dev
* itor
=
314 from
? from
->next
: nubus_devices
;
317 if (itor
->category
== category
318 && itor
->type
== type
)
326 nubus_find_slot(unsigned int slot
,
327 const struct nubus_dev
* from
)
329 struct nubus_dev
* itor
=
330 from
? from
->next
: nubus_devices
;
333 if (itor
->board
->slot
== slot
)
341 nubus_find_rsrc(struct nubus_dir
* dir
, unsigned char rsrc_type
,
342 struct nubus_dirent
* ent
)
344 while (nubus_readdir(dir
, ent
) != -1) {
345 if (ent
->type
== rsrc_type
)
351 /* Initialization functions - decide which slots contain stuff worth
352 looking at, and print out lots and lots of information from the
355 /* FIXME: A lot of this stuff will eventually be useful after
356 initializaton, for intelligently probing Ethernet and video chips,
357 among other things. The rest of it should go in the /proc code.
358 For now, we just use it to give verbose boot logs. */
360 static int __init
nubus_show_display_resource(struct nubus_dev
* dev
,
361 const struct nubus_dirent
* ent
)
364 case NUBUS_RESID_GAMMADIR
:
365 printk(KERN_INFO
" gamma directory offset: 0x%06x\n", ent
->data
);
367 case 0x0080 ... 0x0085:
368 printk(KERN_INFO
" mode %02X info offset: 0x%06x\n",
369 ent
->type
, ent
->data
);
372 printk(KERN_INFO
" unknown resource %02X, data 0x%06x\n",
373 ent
->type
, ent
->data
);
378 static int __init
nubus_show_network_resource(struct nubus_dev
* dev
,
379 const struct nubus_dirent
* ent
)
382 case NUBUS_RESID_MAC_ADDRESS
:
387 nubus_get_rsrc_mem(addr
, ent
, 6);
388 printk(KERN_INFO
" MAC address: ");
389 for (i
= 0; i
< 6; i
++)
390 printk("%02x%s", addr
[i
] & 0xff,
396 printk(KERN_INFO
" unknown resource %02X, data 0x%06x\n",
397 ent
->type
, ent
->data
);
402 static int __init
nubus_show_cpu_resource(struct nubus_dev
* dev
,
403 const struct nubus_dirent
* ent
)
406 case NUBUS_RESID_MEMINFO
:
408 unsigned long meminfo
[2];
409 nubus_get_rsrc_mem(&meminfo
, ent
, 8);
410 printk(KERN_INFO
" memory: [ 0x%08lx 0x%08lx ]\n",
411 meminfo
[0], meminfo
[1]);
414 case NUBUS_RESID_ROMINFO
:
416 unsigned long rominfo
[2];
417 nubus_get_rsrc_mem(&rominfo
, ent
, 8);
418 printk(KERN_INFO
" ROM: [ 0x%08lx 0x%08lx ]\n",
419 rominfo
[0], rominfo
[1]);
423 printk(KERN_INFO
" unknown resource %02X, data 0x%06x\n",
424 ent
->type
, ent
->data
);
429 static int __init
nubus_show_private_resource(struct nubus_dev
* dev
,
430 const struct nubus_dirent
* ent
)
432 switch (dev
->category
) {
433 case NUBUS_CAT_DISPLAY
:
434 nubus_show_display_resource(dev
, ent
);
436 case NUBUS_CAT_NETWORK
:
437 nubus_show_network_resource(dev
, ent
);
440 nubus_show_cpu_resource(dev
, ent
);
443 printk(KERN_INFO
" unknown resource %02X, data 0x%06x\n",
444 ent
->type
, ent
->data
);
449 static struct nubus_dev
* __init
450 nubus_get_functional_resource(struct nubus_board
* board
,
452 const struct nubus_dirent
* parent
)
454 struct nubus_dir dir
;
455 struct nubus_dirent ent
;
456 struct nubus_dev
* dev
;
458 printk(KERN_INFO
" Function 0x%02x:\n", parent
->type
);
459 nubus_get_subdir(parent
, &dir
);
461 /* Apple seems to have botched the ROM on the IIx */
462 if (slot
== 0 && (unsigned long)dir
.base
% 2)
465 if (console_loglevel
>= 10)
466 printk(KERN_DEBUG
"nubus_get_functional_resource: parent is 0x%p, dir is 0x%p\n",
467 parent
->base
, dir
.base
);
469 /* Actually we should probably panic if this fails */
470 if ((dev
= kmalloc(sizeof(*dev
), GFP_ATOMIC
)) == NULL
)
472 memset(dev
, 0, sizeof(*dev
));
473 dev
->resid
= parent
->type
;
474 dev
->directory
= dir
.base
;
477 while (nubus_readdir(&dir
, &ent
) != -1)
481 case NUBUS_RESID_TYPE
:
483 unsigned short nbtdata
[4];
484 nubus_get_rsrc_mem(nbtdata
, &ent
, 8);
485 dev
->category
= nbtdata
[0];
486 dev
->type
= nbtdata
[1];
487 dev
->dr_sw
= nbtdata
[2];
488 dev
->dr_hw
= nbtdata
[3];
489 printk(KERN_INFO
" type: [cat 0x%x type 0x%x hw 0x%x sw 0x%x]\n",
490 nbtdata
[0], nbtdata
[1], nbtdata
[2], nbtdata
[3]);
493 case NUBUS_RESID_NAME
:
495 nubus_get_rsrc_str(dev
->name
, &ent
, 64);
496 printk(KERN_INFO
" name: %s\n", dev
->name
);
499 case NUBUS_RESID_DRVRDIR
:
501 /* MacOS driver. If we were NetBSD we might
503 struct nubus_dir drvr_dir
;
504 struct nubus_dirent drvr_ent
;
505 nubus_get_subdir(&ent
, &drvr_dir
);
506 nubus_readdir(&drvr_dir
, &drvr_ent
);
507 dev
->driver
= nubus_dirptr(&drvr_ent
);
508 printk(KERN_INFO
" driver at: 0x%p\n",
512 case NUBUS_RESID_MINOR_BASEOS
:
513 /* We will need this in order to support
514 multiple framebuffers. It might be handy
515 for Ethernet as well */
516 nubus_get_rsrc_mem(&dev
->iobase
, &ent
, 4);
517 printk(KERN_INFO
" memory offset: 0x%08lx\n",
520 case NUBUS_RESID_MINOR_LENGTH
:
522 nubus_get_rsrc_mem(&dev
->iosize
, &ent
, 4);
523 printk(KERN_INFO
" memory length: 0x%08lx\n",
526 case NUBUS_RESID_FLAGS
:
527 dev
->flags
= ent
.data
;
528 printk(KERN_INFO
" flags: 0x%06x\n", dev
->flags
);
530 case NUBUS_RESID_HWDEVID
:
531 dev
->hwdevid
= ent
.data
;
532 printk(KERN_INFO
" hwdevid: 0x%06x\n", dev
->hwdevid
);
535 /* Local/Private resources have their own
537 nubus_show_private_resource(dev
, &ent
);
545 static int __init
nubus_get_vidnames(struct nubus_board
* board
,
546 const struct nubus_dirent
* parent
)
548 struct nubus_dir dir
;
549 struct nubus_dirent ent
;
550 /* FIXME: obviously we want to put this in a header file soon */
553 /* Don't know what this is yet */
555 /* Longest one I've seen so far is 26 characters */
559 printk(KERN_INFO
" video modes supported:\n");
560 nubus_get_subdir(parent
, &dir
);
561 if (console_loglevel
>= 10)
562 printk(KERN_DEBUG
"nubus_get_vidnames: parent is 0x%p, dir is 0x%p\n",
563 parent
->base
, dir
.base
);
565 while(nubus_readdir(&dir
, &ent
) != -1)
570 /* First get the length */
571 nubus_get_rsrc_mem(&size
, &ent
, 4);
573 /* Now clobber the whole thing */
574 if (size
> sizeof(mode
) - 1)
575 size
= sizeof(mode
) - 1;
576 memset(&mode
, 0, sizeof(mode
));
577 nubus_get_rsrc_mem(&mode
, &ent
, size
);
578 printk (KERN_INFO
" %02X: (%02X) %s\n", ent
.type
,
584 /* This is *really* cool. */
585 static int __init
nubus_get_icon(struct nubus_board
* board
,
586 const struct nubus_dirent
* ent
)
588 /* Should be 32x32 if my memory serves me correctly */
589 unsigned char icon
[128];
592 nubus_get_rsrc_mem(&icon
, ent
, 128);
593 printk(KERN_INFO
" icon:\n");
595 /* We should actually plot these somewhere in the framebuffer
596 init. This is just to demonstrate that they do, in fact,
598 for (y
= 0; y
< 32; y
++) {
599 printk(KERN_INFO
" ");
600 for (x
= 0; x
< 32; x
++) {
612 static int __init
nubus_get_vendorinfo(struct nubus_board
* board
,
613 const struct nubus_dirent
* parent
)
615 struct nubus_dir dir
;
616 struct nubus_dirent ent
;
617 static char* vendor_fields
[6] = {"ID", "serial", "revision",
618 "part", "date", "unknown field"};
620 printk(KERN_INFO
" vendor info:\n");
621 nubus_get_subdir(parent
, &dir
);
622 if (console_loglevel
>= 10)
623 printk(KERN_DEBUG
"nubus_get_vendorinfo: parent is 0x%p, dir is 0x%p\n",
624 parent
->base
, dir
.base
);
626 while(nubus_readdir(&dir
, &ent
) != -1)
630 /* These are all strings, we think */
631 nubus_get_rsrc_str(name
, &ent
, 64);
634 printk(KERN_INFO
" %s: %s\n",
635 vendor_fields
[ent
.type
-1], name
);
640 static int __init
nubus_get_board_resource(struct nubus_board
* board
, int slot
,
641 const struct nubus_dirent
* parent
)
643 struct nubus_dir dir
;
644 struct nubus_dirent ent
;
646 nubus_get_subdir(parent
, &dir
);
647 if (console_loglevel
>= 10)
648 printk(KERN_DEBUG
"nubus_get_board_resource: parent is 0x%p, dir is 0x%p\n",
649 parent
->base
, dir
.base
);
651 while(nubus_readdir(&dir
, &ent
) != -1)
654 case NUBUS_RESID_TYPE
:
656 unsigned short nbtdata
[4];
657 /* This type is always the same, and is not
658 useful except insofar as it tells us that
659 we really are looking at a board resource. */
660 nubus_get_rsrc_mem(nbtdata
, &ent
, 8);
661 printk(KERN_INFO
" type: [cat 0x%x type 0x%x hw 0x%x sw 0x%x]\n",
662 nbtdata
[0], nbtdata
[1], nbtdata
[2],
664 if (nbtdata
[0] != 1 || nbtdata
[1] != 0 ||
665 nbtdata
[2] != 0 || nbtdata
[3] != 0)
666 printk(KERN_ERR
"this sResource is not a board resource!\n");
669 case NUBUS_RESID_NAME
:
670 nubus_get_rsrc_str(board
->name
, &ent
, 64);
671 printk(KERN_INFO
" name: %s\n", board
->name
);
673 case NUBUS_RESID_ICON
:
674 nubus_get_icon(board
, &ent
);
676 case NUBUS_RESID_BOARDID
:
677 printk(KERN_INFO
" board id: 0x%x\n", ent
.data
);
679 case NUBUS_RESID_PRIMARYINIT
:
680 printk(KERN_INFO
" primary init offset: 0x%06x\n", ent
.data
);
682 case NUBUS_RESID_VENDORINFO
:
683 nubus_get_vendorinfo(board
, &ent
);
685 case NUBUS_RESID_FLAGS
:
686 printk(KERN_INFO
" flags: 0x%06x\n", ent
.data
);
688 case NUBUS_RESID_HWDEVID
:
689 printk(KERN_INFO
" hwdevid: 0x%06x\n", ent
.data
);
691 case NUBUS_RESID_SECONDINIT
:
692 printk(KERN_INFO
" secondary init offset: 0x%06x\n", ent
.data
);
694 /* WTF isn't this in the functional resources? */
695 case NUBUS_RESID_VIDNAMES
:
696 nubus_get_vidnames(board
, &ent
);
698 /* Same goes for this */
699 case NUBUS_RESID_VIDMODES
:
700 printk(KERN_INFO
" video mode parameter directory offset: 0x%06x\n",
704 printk(KERN_INFO
" unknown resource %02X, data 0x%06x\n",
711 /* Attempt to bypass the somewhat non-obvious arrangement of
712 sResources in the motherboard ROM */
713 static void __init
nubus_find_rom_dir(struct nubus_board
* board
)
716 unsigned char* romdir
;
717 struct nubus_dir dir
;
718 struct nubus_dirent ent
;
720 /* Check for the extra directory just under the format block */
722 nubus_rewind(&rp
, 4, board
->lanes
);
723 if (nubus_get_rom(&rp
, 4, board
->lanes
) != NUBUS_TEST_PATTERN
) {
724 /* OK, the ROM was telling the truth */
725 board
->directory
= board
->fblock
;
726 nubus_move(&board
->directory
,
727 nubus_expand32(board
->doffset
),
732 /* On "slot zero", you have to walk down a few more
733 directories to get to the equivalent of a real card's root
734 directory. We don't know what they were smoking when they
735 came up with this. */
736 romdir
= nubus_rom_addr(board
->slot
);
737 nubus_rewind(&romdir
, ROM_DIR_OFFSET
, board
->lanes
);
738 dir
.base
= dir
.ptr
= romdir
;
740 dir
.mask
= board
->lanes
;
742 /* This one points to an "Unknown Macintosh" directory */
743 if (nubus_readdir(&dir
, &ent
) == -1)
746 if (console_loglevel
>= 10)
747 printk(KERN_INFO
"nubus_get_rom_dir: entry %02x %06x\n", ent
.type
, ent
.data
);
748 /* This one takes us to where we want to go. */
749 if (nubus_readdir(&dir
, &ent
) == -1)
751 if (console_loglevel
>= 10)
752 printk(KERN_DEBUG
"nubus_get_rom_dir: entry %02x %06x\n", ent
.type
, ent
.data
);
753 nubus_get_subdir(&ent
, &dir
);
755 /* Resource ID 01, also an "Unknown Macintosh" */
756 if (nubus_readdir(&dir
, &ent
) == -1)
758 if (console_loglevel
>= 10)
759 printk(KERN_DEBUG
"nubus_get_rom_dir: entry %02x %06x\n", ent
.type
, ent
.data
);
761 /* FIXME: the first one is *not* always the right one. We
762 suspect this has something to do with the ROM revision.
763 "The HORROR ROM" (LC-series) uses 0x7e, while "The HORROR
764 Continues" (Q630) uses 0x7b. The DAFB Macs evidently use
765 something else. Please run "Slots" on your Mac (see
766 include/linux/nubus.h for where to get this program) and
767 tell us where the 'SiDirPtr' for Slot 0 is. If you feel
768 brave, you should also use MacsBug to walk down the ROM
769 directories like this function does and try to find the
770 path to that address... */
771 if (nubus_readdir(&dir
, &ent
) == -1)
773 if (console_loglevel
>= 10)
774 printk(KERN_DEBUG
"nubus_get_rom_dir: entry %02x %06x\n", ent
.type
, ent
.data
);
777 nubus_get_subdir(&ent
, &dir
);
778 board
->directory
= dir
.base
;
781 /* Even more evil laughter... */
783 board
->directory
= board
->fblock
;
784 nubus_move(&board
->directory
, nubus_expand32(board
->doffset
), board
->lanes
);
785 printk(KERN_ERR
"nubus_get_rom_dir: ROM weirdness! Notify the developers...\n");
788 /* Add a board (might be many devices) to the list */
789 static struct nubus_board
* __init
nubus_add_board(int slot
, int bytelanes
)
791 struct nubus_board
* board
;
792 struct nubus_board
** boardp
;
796 struct nubus_dir dir
;
797 struct nubus_dirent ent
;
799 /* Move to the start of the format block */
800 rp
= nubus_rom_addr(slot
);
801 nubus_rewind(&rp
, FORMAT_BLOCK_SIZE
, bytelanes
);
803 /* Actually we should probably panic if this fails */
804 if ((board
= kmalloc(sizeof(*board
), GFP_ATOMIC
)) == NULL
)
806 memset(board
, 0, sizeof(*board
));
809 /* Dump the format block for debugging purposes */
810 if (console_loglevel
>= 10) {
812 printk(KERN_DEBUG
"Slot %X, format block at 0x%p\n",
814 printk(KERN_DEBUG
"Format block: ");
815 for (i
= 0; i
< FORMAT_BLOCK_SIZE
; i
+= 4) {
816 unsigned short foo
, bar
;
817 foo
= nubus_get_rom(&rp
, 2, bytelanes
);
818 bar
= nubus_get_rom(&rp
, 2, bytelanes
);
819 printk("%04x %04x ", foo
, bar
);
826 board
->slot_addr
= (unsigned long) nubus_slot_addr(slot
);
827 board
->doffset
= nubus_get_rom(&rp
, 4, bytelanes
);
828 /* rom_length is *supposed* to be the total length of the
829 * ROM. In practice it is the "amount of ROM used to compute
830 * the CRC." So some jokers decide to set it to zero and
831 * set the crc to zero so they don't have to do any math.
832 * See the Performa 460 ROM, for example. Those Apple "engineers".
834 board
->rom_length
= nubus_get_rom(&rp
, 4, bytelanes
);
835 board
->crc
= nubus_get_rom(&rp
, 4, bytelanes
);
836 board
->rev
= nubus_get_rom(&rp
, 1, bytelanes
);
837 board
->format
= nubus_get_rom(&rp
,1, bytelanes
);
838 board
->lanes
= bytelanes
;
840 /* Directory offset should be small and negative... */
841 if(!(board
->doffset
& 0x00FF0000))
842 printk(KERN_WARNING
"Dodgy doffset!\n");
843 dpat
= nubus_get_rom(&rp
, 4, bytelanes
);
844 if(dpat
!= NUBUS_TEST_PATTERN
)
845 printk(KERN_WARNING
"Wrong test pattern %08lx!\n", dpat
);
848 * I wonder how the CRC is meant to work -
850 * CSA: According to MAC docs, not all cards pass the CRC anyway,
851 * since the initial Macintosh ROM releases skipped the check.
854 /* Attempt to work around slot zero weirdness */
855 nubus_find_rom_dir(board
);
856 nubus_get_root_dir(board
, &dir
);
858 /* We're ready to rock */
859 printk(KERN_INFO
"Slot %X:\n", slot
);
861 /* Each slot should have one board resource and any number of
862 functional resources. So we'll fill in some fields in the
863 struct nubus_board from the board resource, then walk down
864 the list of functional resources, spinning out a nubus_dev
866 if (nubus_readdir(&dir
, &ent
) == -1) {
867 /* We can't have this! */
868 printk(KERN_ERR
"Board resource not found!\n");
871 printk(KERN_INFO
" Board resource:\n");
872 nubus_get_board_resource(board
, slot
, &ent
);
875 /* Aaaarrrrgghh! The LC III motherboard has *two* board
876 resources. I have no idea WTF to do about this. */
878 while (nubus_readdir(&dir
, &ent
) != -1) {
879 struct nubus_dev
* dev
;
880 struct nubus_dev
** devp
;
881 dev
= nubus_get_functional_resource(board
, slot
, &ent
);
885 /* We zeroed this out above */
886 if (board
->first_dev
== NULL
)
887 board
->first_dev
= dev
;
889 /* Put it on the global NuBus device chain. Keep entries in order. */
890 for (devp
=&nubus_devices
; *devp
!=NULL
; devp
=&((*devp
)->next
))
896 /* Put it on the global NuBus board chain. Keep entries in order. */
897 for (boardp
=&nubus_boards
; *boardp
!=NULL
; boardp
=&((*boardp
)->next
))
905 void __init
nubus_probe_slot(int slot
)
911 rp
= nubus_rom_addr(slot
);
918 local_irq_save(flags
);
919 card_present
= hwreg_present(rp
);
920 local_irq_restore(flags
);
925 printk(KERN_DEBUG
"Now probing slot %X at %p\n", slot
, rp
);
930 /* The last byte of the format block consists of two
931 nybbles which are "mirror images" of each other.
932 These show us the valid bytelanes */
933 if ((((dp
>>4) ^ dp
) & 0x0F) != 0x0F)
935 /* Check that this value is actually *on* one of the
936 bytelanes it claims are valid! */
937 if ((dp
& 0x0F) >= (1<<i
))
940 /* Looks promising. Let's put it on the list. */
941 nubus_add_board(slot
, dp
);
947 #if defined(CONFIG_PROC_FS)
949 /* /proc/nubus stuff */
951 static int sprint_nubus_board(struct nubus_board
* board
, char* ptr
, int len
)
956 sprintf(ptr
, "Slot %X: %s\n",
957 board
->slot
, board
->name
);
962 static int nubus_read_proc(char *page
, char **start
, off_t off
,
963 int count
, int *eof
, void *data
)
965 int nprinted
, len
, begin
= 0;
966 int size
= PAGE_SIZE
;
967 struct nubus_board
* board
;
969 len
= sprintf(page
, "Nubus devices found:\n");
970 /* Walk the list of NuBus boards */
971 for (board
= nubus_boards
; board
!= NULL
; board
= board
->next
)
973 nprinted
= sprint_nubus_board(board
, page
+ len
, size
- len
);
977 if (len
+begin
< off
) {
981 if (len
+begin
>= off
+count
)
997 void __init
nubus_scan_bus(void)
1000 /* This might not work on your machine */
1001 #ifdef I_WANT_TO_PROBE_SLOT_ZERO
1002 nubus_probe_slot(0);
1004 for(slot
= 9; slot
< 15; slot
++)
1006 nubus_probe_slot(slot
);
1010 static int __init
nubus_init(void)
1015 /* Initialize the NuBus interrupts */
1022 #ifdef TRY_TO_DODGE_WSOD
1023 /* Rogue Ethernet interrupts can kill the machine if we don't
1024 do this. Obviously this is bogus. Hopefully the local VIA
1025 gurus can fix the real cause of the problem. */
1030 printk("NuBus: Scanning NuBus slots.\n");
1031 nubus_devices
= NULL
;
1032 nubus_boards
= NULL
;
1035 #ifdef CONFIG_PROC_FS
1036 create_proc_read_entry("nubus", 0, NULL
, nubus_read_proc
, NULL
);
1042 subsys_initcall(nubus_init
);