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 <linux/module.h>
18 #include <linux/slab.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);
32 /* This is, of course, the size in bytelanes, rather than the size in
34 #define FORMAT_BLOCK_SIZE 20
35 #define ROM_DIR_OFFSET 0x24
37 #define NUBUS_TEST_PATTERN 0x5A932BC7
39 /* Define this if you like to live dangerously - it is known not to
40 work on pretty much every machine except the Quadra 630 and the LC
42 #undef I_WANT_TO_PROBE_SLOT_ZERO
44 /* This sometimes helps combat failure to boot */
45 #undef TRY_TO_DODGE_WSOD
49 struct nubus_dev
* nubus_devices
;
50 struct nubus_board
* nubus_boards
;
52 /* Meaning of "bytelanes":
54 The card ROM may appear on any or all bytes of each long word in
55 NuBus memory. The low 4 bits of the "map" value found in the
56 format block (at the top of the slot address space, as well as at
57 the top of the MacOS ROM) tells us which bytelanes, i.e. which byte
58 offsets within each longword, are valid. Thus:
60 A map of 0x0f, as found in the MacOS ROM, means that all bytelanes
63 A map of 0xf0 means that no bytelanes are valid (We pray that we
64 will never encounter this, but stranger things have happened)
66 A map of 0xe1 means that only the MSB of each long word is actually
67 part of the card ROM. (We hope to never encounter NuBus on a
68 little-endian machine. Again, stranger things have happened)
70 A map of 0x78 means that only the LSB of each long word is valid.
72 Etcetera, etcetera. Hopefully this clears up some confusion over
73 what the following code actually does. */
75 static inline int not_useful(void *p
, int map
)
77 unsigned long pv
=(unsigned long)p
;
84 static unsigned long nubus_get_rom(unsigned char **ptr
, int len
, int map
)
86 /* This will hold the result */
88 unsigned char *p
= *ptr
;
93 while(not_useful(p
,map
))
102 static void nubus_rewind(unsigned char **ptr
, int len
, int map
)
104 unsigned char *p
=*ptr
;
108 printk(KERN_ERR
"rewind of 0x%08x!\n", len
);
115 while(not_useful(p
, map
));
121 static void nubus_advance(unsigned char **ptr
, int len
, int map
)
123 unsigned char *p
= *ptr
;
125 printk(KERN_ERR
"advance of 0x%08x!\n", len
);
128 while(not_useful(p
,map
))
136 static void nubus_move(unsigned char **ptr
, int len
, int map
)
139 nubus_advance(ptr
, len
, map
);
141 nubus_rewind(ptr
, -len
, map
);
144 /* Now, functions to read the sResource tree */
146 /* Each sResource entry consists of a 1-byte ID and a 3-byte data
147 field. If that data field contains an offset, then obviously we
148 have to expand it from a 24-bit signed number to a 32-bit signed
151 static inline long nubus_expand32(long foo
)
153 if(foo
& 0x00800000) /* 24bit negative */
158 static inline void *nubus_rom_addr(int slot
)
161 * Returns the first byte after the card. We then walk
162 * backwards to get the lane register and the config
164 return (void *)(0xF1000000+(slot
<<24));
167 static unsigned char *nubus_dirptr(const struct nubus_dirent
*nd
)
169 unsigned char *p
= nd
->base
;
170 /* Essentially, just step over the bytelanes using whatever
171 offset we might have found */
172 nubus_move(&p
, nubus_expand32(nd
->data
), nd
->mask
);
173 /* And return the value */
177 /* These two are for pulling resource data blocks (i.e. stuff that's
178 pointed to with offsets) out of the card ROM. */
180 void nubus_get_rsrc_mem(void *dest
, const struct nubus_dirent
* dirent
,
183 unsigned char *t
= (unsigned char *)dest
;
184 unsigned char *p
= nubus_dirptr(dirent
);
187 *t
++ = nubus_get_rom(&p
, 1, dirent
->mask
);
191 EXPORT_SYMBOL(nubus_get_rsrc_mem
);
193 void nubus_get_rsrc_str(void *dest
, const struct nubus_dirent
* dirent
,
196 unsigned char *t
=(unsigned char *)dest
;
197 unsigned char *p
= nubus_dirptr(dirent
);
200 *t
= nubus_get_rom(&p
, 1, dirent
->mask
);
206 EXPORT_SYMBOL(nubus_get_rsrc_str
);
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
;
216 EXPORT_SYMBOL(nubus_get_root_dir
);
218 /* This is a slyly renamed version of the above */
219 int nubus_get_func_dir(const struct nubus_dev
* dev
,
220 struct nubus_dir
* dir
)
222 dir
->ptr
= dir
->base
= dev
->directory
;
224 dir
->mask
= dev
->board
->lanes
;
227 EXPORT_SYMBOL(nubus_get_func_dir
);
229 int nubus_get_board_dir(const struct nubus_board
* board
,
230 struct nubus_dir
* dir
)
232 struct nubus_dirent ent
;
234 dir
->ptr
= dir
->base
= board
->directory
;
236 dir
->mask
= board
->lanes
;
238 /* Now dereference it (the first directory is always the board
240 if (nubus_readdir(dir
, &ent
) == -1)
242 if (nubus_get_subdir(&ent
, dir
) == -1)
246 EXPORT_SYMBOL(nubus_get_board_dir
);
248 int nubus_get_subdir(const struct nubus_dirent
*ent
,
249 struct nubus_dir
*dir
)
251 dir
->ptr
= dir
->base
= nubus_dirptr(ent
);
253 dir
->mask
= ent
->mask
;
256 EXPORT_SYMBOL(nubus_get_subdir
);
258 int nubus_readdir(struct nubus_dir
*nd
, struct nubus_dirent
*ent
)
264 /* Do this first, otherwise nubus_rewind & co are off by 4 */
267 /* This moves nd->ptr forward */
268 resid
= nubus_get_rom(&nd
->ptr
, 4, nd
->mask
);
270 /* EOL marker, as per the Apple docs */
271 if((resid
&0xff000000) == 0xff000000)
273 /* Mark it as done */
278 /* First byte is the resource ID */
279 ent
->type
= resid
>> 24;
280 /* Low 3 bytes might contain data (or might not) */
281 ent
->data
= resid
& 0xffffff;
282 ent
->mask
= nd
->mask
;
285 EXPORT_SYMBOL(nubus_readdir
);
287 int nubus_rewinddir(struct nubus_dir
* dir
)
289 dir
->ptr
= dir
->base
;
292 EXPORT_SYMBOL(nubus_rewinddir
);
294 /* Driver interface functions, more or less like in pci.c */
297 nubus_find_device(unsigned short category
,
299 unsigned short dr_hw
,
300 unsigned short dr_sw
,
301 const struct nubus_dev
* from
)
303 struct nubus_dev
* itor
=
304 from
? from
->next
: nubus_devices
;
307 if (itor
->category
== category
308 && itor
->type
== type
309 && itor
->dr_hw
== dr_hw
310 && itor
->dr_sw
== dr_sw
)
316 EXPORT_SYMBOL(nubus_find_device
);
319 nubus_find_type(unsigned short category
,
321 const struct nubus_dev
* from
)
323 struct nubus_dev
* itor
=
324 from
? from
->next
: nubus_devices
;
327 if (itor
->category
== category
328 && itor
->type
== type
)
334 EXPORT_SYMBOL(nubus_find_type
);
337 nubus_find_slot(unsigned int slot
,
338 const struct nubus_dev
* from
)
340 struct nubus_dev
* itor
=
341 from
? from
->next
: nubus_devices
;
344 if (itor
->board
->slot
== slot
)
350 EXPORT_SYMBOL(nubus_find_slot
);
353 nubus_find_rsrc(struct nubus_dir
* dir
, unsigned char rsrc_type
,
354 struct nubus_dirent
* ent
)
356 while (nubus_readdir(dir
, ent
) != -1) {
357 if (ent
->type
== rsrc_type
)
362 EXPORT_SYMBOL(nubus_find_rsrc
);
364 /* Initialization functions - decide which slots contain stuff worth
365 looking at, and print out lots and lots of information from the
368 /* FIXME: A lot of this stuff will eventually be useful after
369 initialization, for intelligently probing Ethernet and video chips,
370 among other things. The rest of it should go in the /proc code.
371 For now, we just use it to give verbose boot logs. */
373 static int __init
nubus_show_display_resource(struct nubus_dev
* dev
,
374 const struct nubus_dirent
* ent
)
377 case NUBUS_RESID_GAMMADIR
:
378 printk(KERN_INFO
" gamma directory offset: 0x%06x\n", ent
->data
);
380 case 0x0080 ... 0x0085:
381 printk(KERN_INFO
" mode %02X info offset: 0x%06x\n",
382 ent
->type
, ent
->data
);
385 printk(KERN_INFO
" unknown resource %02X, data 0x%06x\n",
386 ent
->type
, ent
->data
);
391 static int __init
nubus_show_network_resource(struct nubus_dev
* dev
,
392 const struct nubus_dirent
* ent
)
395 case NUBUS_RESID_MAC_ADDRESS
:
400 nubus_get_rsrc_mem(addr
, ent
, 6);
401 printk(KERN_INFO
" MAC address: ");
402 for (i
= 0; i
< 6; i
++)
403 printk("%02x%s", addr
[i
] & 0xff,
409 printk(KERN_INFO
" unknown resource %02X, data 0x%06x\n",
410 ent
->type
, ent
->data
);
415 static int __init
nubus_show_cpu_resource(struct nubus_dev
* dev
,
416 const struct nubus_dirent
* ent
)
419 case NUBUS_RESID_MEMINFO
:
421 unsigned long meminfo
[2];
422 nubus_get_rsrc_mem(&meminfo
, ent
, 8);
423 printk(KERN_INFO
" memory: [ 0x%08lx 0x%08lx ]\n",
424 meminfo
[0], meminfo
[1]);
427 case NUBUS_RESID_ROMINFO
:
429 unsigned long rominfo
[2];
430 nubus_get_rsrc_mem(&rominfo
, ent
, 8);
431 printk(KERN_INFO
" ROM: [ 0x%08lx 0x%08lx ]\n",
432 rominfo
[0], rominfo
[1]);
436 printk(KERN_INFO
" unknown resource %02X, data 0x%06x\n",
437 ent
->type
, ent
->data
);
442 static int __init
nubus_show_private_resource(struct nubus_dev
* dev
,
443 const struct nubus_dirent
* ent
)
445 switch (dev
->category
) {
446 case NUBUS_CAT_DISPLAY
:
447 nubus_show_display_resource(dev
, ent
);
449 case NUBUS_CAT_NETWORK
:
450 nubus_show_network_resource(dev
, ent
);
453 nubus_show_cpu_resource(dev
, ent
);
456 printk(KERN_INFO
" unknown resource %02X, data 0x%06x\n",
457 ent
->type
, ent
->data
);
462 static struct nubus_dev
* __init
463 nubus_get_functional_resource(struct nubus_board
* board
,
465 const struct nubus_dirent
* parent
)
467 struct nubus_dir dir
;
468 struct nubus_dirent ent
;
469 struct nubus_dev
* dev
;
471 printk(KERN_INFO
" Function 0x%02x:\n", parent
->type
);
472 nubus_get_subdir(parent
, &dir
);
474 /* Apple seems to have botched the ROM on the IIx */
475 if (slot
== 0 && (unsigned long)dir
.base
% 2)
478 if (console_loglevel
>= 10)
479 printk(KERN_DEBUG
"nubus_get_functional_resource: parent is 0x%p, dir is 0x%p\n",
480 parent
->base
, dir
.base
);
482 /* Actually we should probably panic if this fails */
483 if ((dev
= kzalloc(sizeof(*dev
), GFP_ATOMIC
)) == NULL
)
485 dev
->resid
= parent
->type
;
486 dev
->directory
= dir
.base
;
489 while (nubus_readdir(&dir
, &ent
) != -1)
493 case NUBUS_RESID_TYPE
:
495 unsigned short nbtdata
[4];
496 nubus_get_rsrc_mem(nbtdata
, &ent
, 8);
497 dev
->category
= nbtdata
[0];
498 dev
->type
= nbtdata
[1];
499 dev
->dr_sw
= nbtdata
[2];
500 dev
->dr_hw
= nbtdata
[3];
501 printk(KERN_INFO
" type: [cat 0x%x type 0x%x hw 0x%x sw 0x%x]\n",
502 nbtdata
[0], nbtdata
[1], nbtdata
[2], nbtdata
[3]);
505 case NUBUS_RESID_NAME
:
507 nubus_get_rsrc_str(dev
->name
, &ent
, 64);
508 printk(KERN_INFO
" name: %s\n", dev
->name
);
511 case NUBUS_RESID_DRVRDIR
:
513 /* MacOS driver. If we were NetBSD we might
515 struct nubus_dir drvr_dir
;
516 struct nubus_dirent drvr_ent
;
517 nubus_get_subdir(&ent
, &drvr_dir
);
518 nubus_readdir(&drvr_dir
, &drvr_ent
);
519 dev
->driver
= nubus_dirptr(&drvr_ent
);
520 printk(KERN_INFO
" driver at: 0x%p\n",
524 case NUBUS_RESID_MINOR_BASEOS
:
525 /* We will need this in order to support
526 multiple framebuffers. It might be handy
527 for Ethernet as well */
528 nubus_get_rsrc_mem(&dev
->iobase
, &ent
, 4);
529 printk(KERN_INFO
" memory offset: 0x%08lx\n",
532 case NUBUS_RESID_MINOR_LENGTH
:
534 nubus_get_rsrc_mem(&dev
->iosize
, &ent
, 4);
535 printk(KERN_INFO
" memory length: 0x%08lx\n",
538 case NUBUS_RESID_FLAGS
:
539 dev
->flags
= ent
.data
;
540 printk(KERN_INFO
" flags: 0x%06x\n", dev
->flags
);
542 case NUBUS_RESID_HWDEVID
:
543 dev
->hwdevid
= ent
.data
;
544 printk(KERN_INFO
" hwdevid: 0x%06x\n", dev
->hwdevid
);
547 /* Local/Private resources have their own
549 nubus_show_private_resource(dev
, &ent
);
557 static int __init
nubus_get_vidnames(struct nubus_board
* board
,
558 const struct nubus_dirent
* parent
)
560 struct nubus_dir dir
;
561 struct nubus_dirent ent
;
562 /* FIXME: obviously we want to put this in a header file soon */
565 /* Don't know what this is yet */
567 /* Longest one I've seen so far is 26 characters */
571 printk(KERN_INFO
" video modes supported:\n");
572 nubus_get_subdir(parent
, &dir
);
573 if (console_loglevel
>= 10)
574 printk(KERN_DEBUG
"nubus_get_vidnames: parent is 0x%p, dir is 0x%p\n",
575 parent
->base
, dir
.base
);
577 while(nubus_readdir(&dir
, &ent
) != -1)
582 /* First get the length */
583 nubus_get_rsrc_mem(&size
, &ent
, 4);
585 /* Now clobber the whole thing */
586 if (size
> sizeof(mode
) - 1)
587 size
= sizeof(mode
) - 1;
588 memset(&mode
, 0, sizeof(mode
));
589 nubus_get_rsrc_mem(&mode
, &ent
, size
);
590 printk (KERN_INFO
" %02X: (%02X) %s\n", ent
.type
,
596 /* This is *really* cool. */
597 static int __init
nubus_get_icon(struct nubus_board
* board
,
598 const struct nubus_dirent
* ent
)
600 /* Should be 32x32 if my memory serves me correctly */
601 unsigned char icon
[128];
604 nubus_get_rsrc_mem(&icon
, ent
, 128);
605 printk(KERN_INFO
" icon:\n");
607 /* We should actually plot these somewhere in the framebuffer
608 init. This is just to demonstrate that they do, in fact,
610 for (y
= 0; y
< 32; y
++) {
611 printk(KERN_INFO
" ");
612 for (x
= 0; x
< 32; x
++) {
624 static int __init
nubus_get_vendorinfo(struct nubus_board
* board
,
625 const struct nubus_dirent
* parent
)
627 struct nubus_dir dir
;
628 struct nubus_dirent ent
;
629 static char* vendor_fields
[6] = {"ID", "serial", "revision",
630 "part", "date", "unknown field"};
632 printk(KERN_INFO
" vendor info:\n");
633 nubus_get_subdir(parent
, &dir
);
634 if (console_loglevel
>= 10)
635 printk(KERN_DEBUG
"nubus_get_vendorinfo: parent is 0x%p, dir is 0x%p\n",
636 parent
->base
, dir
.base
);
638 while(nubus_readdir(&dir
, &ent
) != -1)
642 /* These are all strings, we think */
643 nubus_get_rsrc_str(name
, &ent
, 64);
646 printk(KERN_INFO
" %s: %s\n",
647 vendor_fields
[ent
.type
-1], name
);
652 static int __init
nubus_get_board_resource(struct nubus_board
* board
, int slot
,
653 const struct nubus_dirent
* parent
)
655 struct nubus_dir dir
;
656 struct nubus_dirent ent
;
658 nubus_get_subdir(parent
, &dir
);
659 if (console_loglevel
>= 10)
660 printk(KERN_DEBUG
"nubus_get_board_resource: parent is 0x%p, dir is 0x%p\n",
661 parent
->base
, dir
.base
);
663 while(nubus_readdir(&dir
, &ent
) != -1)
666 case NUBUS_RESID_TYPE
:
668 unsigned short nbtdata
[4];
669 /* This type is always the same, and is not
670 useful except insofar as it tells us that
671 we really are looking at a board resource. */
672 nubus_get_rsrc_mem(nbtdata
, &ent
, 8);
673 printk(KERN_INFO
" type: [cat 0x%x type 0x%x hw 0x%x sw 0x%x]\n",
674 nbtdata
[0], nbtdata
[1], nbtdata
[2],
676 if (nbtdata
[0] != 1 || nbtdata
[1] != 0 ||
677 nbtdata
[2] != 0 || nbtdata
[3] != 0)
678 printk(KERN_ERR
"this sResource is not a board resource!\n");
681 case NUBUS_RESID_NAME
:
682 nubus_get_rsrc_str(board
->name
, &ent
, 64);
683 printk(KERN_INFO
" name: %s\n", board
->name
);
685 case NUBUS_RESID_ICON
:
686 nubus_get_icon(board
, &ent
);
688 case NUBUS_RESID_BOARDID
:
689 printk(KERN_INFO
" board id: 0x%x\n", ent
.data
);
691 case NUBUS_RESID_PRIMARYINIT
:
692 printk(KERN_INFO
" primary init offset: 0x%06x\n", ent
.data
);
694 case NUBUS_RESID_VENDORINFO
:
695 nubus_get_vendorinfo(board
, &ent
);
697 case NUBUS_RESID_FLAGS
:
698 printk(KERN_INFO
" flags: 0x%06x\n", ent
.data
);
700 case NUBUS_RESID_HWDEVID
:
701 printk(KERN_INFO
" hwdevid: 0x%06x\n", ent
.data
);
703 case NUBUS_RESID_SECONDINIT
:
704 printk(KERN_INFO
" secondary init offset: 0x%06x\n", ent
.data
);
706 /* WTF isn't this in the functional resources? */
707 case NUBUS_RESID_VIDNAMES
:
708 nubus_get_vidnames(board
, &ent
);
710 /* Same goes for this */
711 case NUBUS_RESID_VIDMODES
:
712 printk(KERN_INFO
" video mode parameter directory offset: 0x%06x\n",
716 printk(KERN_INFO
" unknown resource %02X, data 0x%06x\n",
723 /* Attempt to bypass the somewhat non-obvious arrangement of
724 sResources in the motherboard ROM */
725 static void __init
nubus_find_rom_dir(struct nubus_board
* board
)
728 unsigned char* romdir
;
729 struct nubus_dir dir
;
730 struct nubus_dirent ent
;
732 /* Check for the extra directory just under the format block */
734 nubus_rewind(&rp
, 4, board
->lanes
);
735 if (nubus_get_rom(&rp
, 4, board
->lanes
) != NUBUS_TEST_PATTERN
) {
736 /* OK, the ROM was telling the truth */
737 board
->directory
= board
->fblock
;
738 nubus_move(&board
->directory
,
739 nubus_expand32(board
->doffset
),
744 /* On "slot zero", you have to walk down a few more
745 directories to get to the equivalent of a real card's root
746 directory. We don't know what they were smoking when they
747 came up with this. */
748 romdir
= nubus_rom_addr(board
->slot
);
749 nubus_rewind(&romdir
, ROM_DIR_OFFSET
, board
->lanes
);
750 dir
.base
= dir
.ptr
= romdir
;
752 dir
.mask
= board
->lanes
;
754 /* This one points to an "Unknown Macintosh" directory */
755 if (nubus_readdir(&dir
, &ent
) == -1)
758 if (console_loglevel
>= 10)
759 printk(KERN_INFO
"nubus_get_rom_dir: entry %02x %06x\n", ent
.type
, ent
.data
);
760 /* This one takes us to where we want to go. */
761 if (nubus_readdir(&dir
, &ent
) == -1)
763 if (console_loglevel
>= 10)
764 printk(KERN_DEBUG
"nubus_get_rom_dir: entry %02x %06x\n", ent
.type
, ent
.data
);
765 nubus_get_subdir(&ent
, &dir
);
767 /* Resource ID 01, also an "Unknown Macintosh" */
768 if (nubus_readdir(&dir
, &ent
) == -1)
770 if (console_loglevel
>= 10)
771 printk(KERN_DEBUG
"nubus_get_rom_dir: entry %02x %06x\n", ent
.type
, ent
.data
);
773 /* FIXME: the first one is *not* always the right one. We
774 suspect this has something to do with the ROM revision.
775 "The HORROR ROM" (LC-series) uses 0x7e, while "The HORROR
776 Continues" (Q630) uses 0x7b. The DAFB Macs evidently use
777 something else. Please run "Slots" on your Mac (see
778 include/linux/nubus.h for where to get this program) and
779 tell us where the 'SiDirPtr' for Slot 0 is. If you feel
780 brave, you should also use MacsBug to walk down the ROM
781 directories like this function does and try to find the
782 path to that address... */
783 if (nubus_readdir(&dir
, &ent
) == -1)
785 if (console_loglevel
>= 10)
786 printk(KERN_DEBUG
"nubus_get_rom_dir: entry %02x %06x\n", ent
.type
, ent
.data
);
789 nubus_get_subdir(&ent
, &dir
);
790 board
->directory
= dir
.base
;
793 /* Even more evil laughter... */
795 board
->directory
= board
->fblock
;
796 nubus_move(&board
->directory
, nubus_expand32(board
->doffset
), board
->lanes
);
797 printk(KERN_ERR
"nubus_get_rom_dir: ROM weirdness! Notify the developers...\n");
800 /* Add a board (might be many devices) to the list */
801 static struct nubus_board
* __init
nubus_add_board(int slot
, int bytelanes
)
803 struct nubus_board
* board
;
804 struct nubus_board
** boardp
;
808 struct nubus_dir dir
;
809 struct nubus_dirent ent
;
811 /* Move to the start of the format block */
812 rp
= nubus_rom_addr(slot
);
813 nubus_rewind(&rp
, FORMAT_BLOCK_SIZE
, bytelanes
);
815 /* Actually we should probably panic if this fails */
816 if ((board
= kzalloc(sizeof(*board
), GFP_ATOMIC
)) == NULL
)
820 /* Dump the format block for debugging purposes */
821 if (console_loglevel
>= 10) {
823 printk(KERN_DEBUG
"Slot %X, format block at 0x%p\n",
825 printk(KERN_DEBUG
"Format block: ");
826 for (i
= 0; i
< FORMAT_BLOCK_SIZE
; i
+= 4) {
827 unsigned short foo
, bar
;
828 foo
= nubus_get_rom(&rp
, 2, bytelanes
);
829 bar
= nubus_get_rom(&rp
, 2, bytelanes
);
830 printk("%04x %04x ", foo
, bar
);
837 board
->slot_addr
= (unsigned long) nubus_slot_addr(slot
);
838 board
->doffset
= nubus_get_rom(&rp
, 4, bytelanes
);
839 /* rom_length is *supposed* to be the total length of the
840 * ROM. In practice it is the "amount of ROM used to compute
841 * the CRC." So some jokers decide to set it to zero and
842 * set the crc to zero so they don't have to do any math.
843 * See the Performa 460 ROM, for example. Those Apple "engineers".
845 board
->rom_length
= nubus_get_rom(&rp
, 4, bytelanes
);
846 board
->crc
= nubus_get_rom(&rp
, 4, bytelanes
);
847 board
->rev
= nubus_get_rom(&rp
, 1, bytelanes
);
848 board
->format
= nubus_get_rom(&rp
,1, bytelanes
);
849 board
->lanes
= bytelanes
;
851 /* Directory offset should be small and negative... */
852 if(!(board
->doffset
& 0x00FF0000))
853 printk(KERN_WARNING
"Dodgy doffset!\n");
854 dpat
= nubus_get_rom(&rp
, 4, bytelanes
);
855 if(dpat
!= NUBUS_TEST_PATTERN
)
856 printk(KERN_WARNING
"Wrong test pattern %08lx!\n", dpat
);
859 * I wonder how the CRC is meant to work -
861 * CSA: According to MAC docs, not all cards pass the CRC anyway,
862 * since the initial Macintosh ROM releases skipped the check.
865 /* Attempt to work around slot zero weirdness */
866 nubus_find_rom_dir(board
);
867 nubus_get_root_dir(board
, &dir
);
869 /* We're ready to rock */
870 printk(KERN_INFO
"Slot %X:\n", slot
);
872 /* Each slot should have one board resource and any number of
873 functional resources. So we'll fill in some fields in the
874 struct nubus_board from the board resource, then walk down
875 the list of functional resources, spinning out a nubus_dev
877 if (nubus_readdir(&dir
, &ent
) == -1) {
878 /* We can't have this! */
879 printk(KERN_ERR
"Board resource not found!\n");
882 printk(KERN_INFO
" Board resource:\n");
883 nubus_get_board_resource(board
, slot
, &ent
);
886 /* Aaaarrrrgghh! The LC III motherboard has *two* board
887 resources. I have no idea WTF to do about this. */
889 while (nubus_readdir(&dir
, &ent
) != -1) {
890 struct nubus_dev
* dev
;
891 struct nubus_dev
** devp
;
892 dev
= nubus_get_functional_resource(board
, slot
, &ent
);
896 /* We zeroed this out above */
897 if (board
->first_dev
== NULL
)
898 board
->first_dev
= dev
;
900 /* Put it on the global NuBus device chain. Keep entries in order. */
901 for (devp
=&nubus_devices
; *devp
!=NULL
; devp
=&((*devp
)->next
))
907 /* Put it on the global NuBus board chain. Keep entries in order. */
908 for (boardp
=&nubus_boards
; *boardp
!=NULL
; boardp
=&((*boardp
)->next
))
916 void __init
nubus_probe_slot(int slot
)
922 rp
= nubus_rom_addr(slot
);
929 local_irq_save(flags
);
930 card_present
= hwreg_present(rp
);
931 local_irq_restore(flags
);
936 printk(KERN_DEBUG
"Now probing slot %X at %p\n", slot
, rp
);
941 /* The last byte of the format block consists of two
942 nybbles which are "mirror images" of each other.
943 These show us the valid bytelanes */
944 if ((((dp
>>4) ^ dp
) & 0x0F) != 0x0F)
946 /* Check that this value is actually *on* one of the
947 bytelanes it claims are valid! */
948 if ((dp
& 0x0F) >= (1<<i
))
951 /* Looks promising. Let's put it on the list. */
952 nubus_add_board(slot
, dp
);
958 #if defined(CONFIG_PROC_FS)
960 /* /proc/nubus stuff */
962 static int sprint_nubus_board(struct nubus_board
* board
, char* ptr
, int len
)
967 sprintf(ptr
, "Slot %X: %s\n",
968 board
->slot
, board
->name
);
973 static int nubus_read_proc(char *page
, char **start
, off_t off
,
974 int count
, int *eof
, void *data
)
976 int nprinted
, len
, begin
= 0;
977 int size
= PAGE_SIZE
;
978 struct nubus_board
* board
;
980 len
= sprintf(page
, "Nubus devices found:\n");
981 /* Walk the list of NuBus boards */
982 for (board
= nubus_boards
; board
!= NULL
; board
= board
->next
)
984 nprinted
= sprint_nubus_board(board
, page
+ len
, size
- len
);
988 if (len
+begin
< off
) {
992 if (len
+begin
>= off
+count
)
1008 void __init
nubus_scan_bus(void)
1011 /* This might not work on your machine */
1012 #ifdef I_WANT_TO_PROBE_SLOT_ZERO
1013 nubus_probe_slot(0);
1015 for(slot
= 9; slot
< 15; slot
++)
1017 nubus_probe_slot(slot
);
1021 static int __init
nubus_init(void)
1026 /* Initialize the NuBus interrupts */
1033 #ifdef TRY_TO_DODGE_WSOD
1034 /* Rogue Ethernet interrupts can kill the machine if we don't
1035 do this. Obviously this is bogus. Hopefully the local VIA
1036 gurus can fix the real cause of the problem. */
1041 printk("NuBus: Scanning NuBus slots.\n");
1042 nubus_devices
= NULL
;
1043 nubus_boards
= NULL
;
1046 #ifdef CONFIG_PROC_FS
1047 create_proc_read_entry("nubus", 0, NULL
, nubus_read_proc
, NULL
);
1053 subsys_initcall(nubus_init
);