]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/nubus/nubus.c
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>
21 #include <asm/hwtest.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
;
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
;
91 while (not_useful(p
, map
))
100 static void nubus_rewind(unsigned char **ptr
, int len
, int map
)
102 unsigned char *p
= *ptr
;
106 pr_err("rewind of 0x%08x!\n", len
);
110 } while (not_useful(p
, map
));
116 static void nubus_advance(unsigned char **ptr
, int len
, int map
)
118 unsigned char *p
= *ptr
;
121 pr_err("advance of 0x%08x!\n", len
);
123 while (not_useful(p
, map
))
131 static void nubus_move(unsigned char **ptr
, int len
, int map
)
134 nubus_advance(ptr
, len
, map
);
136 nubus_rewind(ptr
, -len
, map
);
139 /* Now, functions to read the sResource tree */
141 /* Each sResource entry consists of a 1-byte ID and a 3-byte data
142 field. If that data field contains an offset, then obviously we
143 have to expand it from a 24-bit signed number to a 32-bit signed
146 static inline long nubus_expand32(long foo
)
148 if (foo
& 0x00800000) /* 24bit negative */
153 static inline void *nubus_rom_addr(int slot
)
156 * Returns the first byte after the card. We then walk
157 * backwards to get the lane register and the config
159 return (void *)(0xF1000000 + (slot
<< 24));
162 static unsigned char *nubus_dirptr(const struct nubus_dirent
*nd
)
164 unsigned char *p
= nd
->base
;
166 /* Essentially, just step over the bytelanes using whatever
167 offset we might have found */
168 nubus_move(&p
, nubus_expand32(nd
->data
), nd
->mask
);
169 /* And return the value */
173 /* These two are for pulling resource data blocks (i.e. stuff that's
174 pointed to with offsets) out of the card ROM. */
176 void nubus_get_rsrc_mem(void *dest
, const struct nubus_dirent
*dirent
,
179 unsigned char *t
= (unsigned char *)dest
;
180 unsigned char *p
= nubus_dirptr(dirent
);
183 *t
++ = nubus_get_rom(&p
, 1, dirent
->mask
);
187 EXPORT_SYMBOL(nubus_get_rsrc_mem
);
189 void nubus_get_rsrc_str(void *dest
, const struct nubus_dirent
*dirent
,
192 unsigned char *t
= (unsigned char *)dest
;
193 unsigned char *p
= nubus_dirptr(dirent
);
196 *t
= nubus_get_rom(&p
, 1, dirent
->mask
);
202 EXPORT_SYMBOL(nubus_get_rsrc_str
);
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
;
212 EXPORT_SYMBOL(nubus_get_root_dir
);
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
;
223 EXPORT_SYMBOL(nubus_get_func_dir
);
225 int nubus_get_board_dir(const struct nubus_board
*board
,
226 struct nubus_dir
*dir
)
228 struct nubus_dirent ent
;
230 dir
->ptr
= dir
->base
= board
->directory
;
232 dir
->mask
= board
->lanes
;
234 /* Now dereference it (the first directory is always the board
236 if (nubus_readdir(dir
, &ent
) == -1)
238 if (nubus_get_subdir(&ent
, dir
) == -1)
242 EXPORT_SYMBOL(nubus_get_board_dir
);
244 int nubus_get_subdir(const struct nubus_dirent
*ent
,
245 struct nubus_dir
*dir
)
247 dir
->ptr
= dir
->base
= nubus_dirptr(ent
);
249 dir
->mask
= ent
->mask
;
252 EXPORT_SYMBOL(nubus_get_subdir
);
254 int nubus_readdir(struct nubus_dir
*nd
, struct nubus_dirent
*ent
)
261 /* Do this first, otherwise nubus_rewind & co are off by 4 */
264 /* This moves nd->ptr forward */
265 resid
= nubus_get_rom(&nd
->ptr
, 4, nd
->mask
);
267 /* EOL marker, as per the Apple docs */
268 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
;
281 EXPORT_SYMBOL(nubus_readdir
);
283 int nubus_rewinddir(struct nubus_dir
*dir
)
285 dir
->ptr
= dir
->base
;
289 EXPORT_SYMBOL(nubus_rewinddir
);
291 /* Driver interface functions, more or less like in pci.c */
294 nubus_find_device(unsigned short category
, unsigned short type
,
295 unsigned short dr_hw
, unsigned short dr_sw
,
296 const struct nubus_dev
*from
)
298 struct nubus_dev
*itor
= from
? from
->next
: nubus_devices
;
301 if (itor
->category
== category
&& itor
->type
== type
&&
302 itor
->dr_hw
== dr_hw
&& itor
->dr_sw
== dr_sw
)
308 EXPORT_SYMBOL(nubus_find_device
);
311 nubus_find_type(unsigned short category
, unsigned short type
,
312 const struct nubus_dev
*from
)
314 struct nubus_dev
*itor
= from
? from
->next
: nubus_devices
;
317 if (itor
->category
== category
&& itor
->type
== type
)
323 EXPORT_SYMBOL(nubus_find_type
);
326 nubus_find_slot(unsigned int slot
, const struct nubus_dev
*from
)
328 struct nubus_dev
*itor
= from
? from
->next
: nubus_devices
;
331 if (itor
->board
->slot
== slot
)
337 EXPORT_SYMBOL(nubus_find_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
)
349 EXPORT_SYMBOL(nubus_find_rsrc
);
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 initialization, 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 pr_info(" gamma directory offset: 0x%06x\n", ent
->data
);
367 case 0x0080 ... 0x0085:
368 pr_info(" mode %02X info offset: 0x%06x\n",
369 ent
->type
, ent
->data
);
372 pr_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
:
386 nubus_get_rsrc_mem(addr
, ent
, 6);
387 pr_info(" MAC address: %pM\n", addr
);
391 pr_info(" unknown resource %02X, data 0x%06x\n",
392 ent
->type
, ent
->data
);
397 static int __init
nubus_show_cpu_resource(struct nubus_dev
*dev
,
398 const struct nubus_dirent
*ent
)
401 case NUBUS_RESID_MEMINFO
:
403 unsigned long meminfo
[2];
405 nubus_get_rsrc_mem(&meminfo
, ent
, 8);
406 pr_info(" memory: [ 0x%08lx 0x%08lx ]\n",
407 meminfo
[0], meminfo
[1]);
410 case NUBUS_RESID_ROMINFO
:
412 unsigned long rominfo
[2];
414 nubus_get_rsrc_mem(&rominfo
, ent
, 8);
415 pr_info(" ROM: [ 0x%08lx 0x%08lx ]\n",
416 rominfo
[0], rominfo
[1]);
420 pr_info(" unknown resource %02X, data 0x%06x\n",
421 ent
->type
, ent
->data
);
426 static int __init
nubus_show_private_resource(struct nubus_dev
*dev
,
427 const struct nubus_dirent
*ent
)
429 switch (dev
->category
) {
430 case NUBUS_CAT_DISPLAY
:
431 nubus_show_display_resource(dev
, ent
);
433 case NUBUS_CAT_NETWORK
:
434 nubus_show_network_resource(dev
, ent
);
437 nubus_show_cpu_resource(dev
, ent
);
440 pr_info(" unknown resource %02X, data 0x%06x\n",
441 ent
->type
, ent
->data
);
446 static struct nubus_dev
* __init
447 nubus_get_functional_resource(struct nubus_board
*board
, int slot
,
448 const struct nubus_dirent
*parent
)
450 struct nubus_dir dir
;
451 struct nubus_dirent ent
;
452 struct nubus_dev
*dev
;
454 pr_info(" Function 0x%02x:\n", parent
->type
);
455 nubus_get_subdir(parent
, &dir
);
457 /* Apple seems to have botched the ROM on the IIx */
458 if (slot
== 0 && (unsigned long)dir
.base
% 2)
461 pr_debug("%s: parent is 0x%p, dir is 0x%p\n",
462 __func__
, parent
->base
, dir
.base
);
464 /* Actually we should probably panic if this fails */
465 if ((dev
= kzalloc(sizeof(*dev
), GFP_ATOMIC
)) == NULL
)
467 dev
->resid
= parent
->type
;
468 dev
->directory
= dir
.base
;
471 while (nubus_readdir(&dir
, &ent
) != -1) {
473 case NUBUS_RESID_TYPE
:
475 unsigned short nbtdata
[4];
477 nubus_get_rsrc_mem(nbtdata
, &ent
, 8);
478 dev
->category
= nbtdata
[0];
479 dev
->type
= nbtdata
[1];
480 dev
->dr_sw
= nbtdata
[2];
481 dev
->dr_hw
= nbtdata
[3];
482 pr_info(" type: [cat 0x%x type 0x%x sw 0x%x hw 0x%x]\n",
483 nbtdata
[0], nbtdata
[1], nbtdata
[2], nbtdata
[3]);
486 case NUBUS_RESID_NAME
:
488 nubus_get_rsrc_str(dev
->name
, &ent
, 64);
489 pr_info(" name: %s\n", dev
->name
);
492 case NUBUS_RESID_DRVRDIR
:
494 /* MacOS driver. If we were NetBSD we might
496 struct nubus_dir drvr_dir
;
497 struct nubus_dirent drvr_ent
;
499 nubus_get_subdir(&ent
, &drvr_dir
);
500 nubus_readdir(&drvr_dir
, &drvr_ent
);
501 dev
->driver
= nubus_dirptr(&drvr_ent
);
502 pr_info(" driver at: 0x%p\n", dev
->driver
);
505 case NUBUS_RESID_MINOR_BASEOS
:
506 /* We will need this in order to support
507 multiple framebuffers. It might be handy
508 for Ethernet as well */
509 nubus_get_rsrc_mem(&dev
->iobase
, &ent
, 4);
510 pr_info(" memory offset: 0x%08lx\n", dev
->iobase
);
512 case NUBUS_RESID_MINOR_LENGTH
:
514 nubus_get_rsrc_mem(&dev
->iosize
, &ent
, 4);
515 pr_info(" memory length: 0x%08lx\n", dev
->iosize
);
517 case NUBUS_RESID_FLAGS
:
518 dev
->flags
= ent
.data
;
519 pr_info(" flags: 0x%06x\n", dev
->flags
);
521 case NUBUS_RESID_HWDEVID
:
522 dev
->hwdevid
= ent
.data
;
523 pr_info(" hwdevid: 0x%06x\n", dev
->hwdevid
);
526 /* Local/Private resources have their own
528 nubus_show_private_resource(dev
, &ent
);
536 static int __init
nubus_get_vidnames(struct nubus_board
*board
,
537 const struct nubus_dirent
*parent
)
539 struct nubus_dir dir
;
540 struct nubus_dirent ent
;
542 /* FIXME: obviously we want to put this in a header file soon */
545 /* Don't know what this is yet */
547 /* Longest one I've seen so far is 26 characters */
551 pr_info(" video modes supported:\n");
552 nubus_get_subdir(parent
, &dir
);
553 pr_debug("%s: parent is 0x%p, dir is 0x%p\n",
554 __func__
, parent
->base
, dir
.base
);
556 while (nubus_readdir(&dir
, &ent
) != -1) {
560 /* First get the length */
561 nubus_get_rsrc_mem(&size
, &ent
, 4);
563 /* Now clobber the whole thing */
564 if (size
> sizeof(mode
) - 1)
565 size
= sizeof(mode
) - 1;
566 memset(&mode
, 0, sizeof(mode
));
567 nubus_get_rsrc_mem(&mode
, &ent
, size
);
568 pr_info(" %02X: (%02X) %s\n", ent
.type
,
574 /* This is *really* cool. */
575 static int __init
nubus_get_icon(struct nubus_board
*board
,
576 const struct nubus_dirent
*ent
)
578 /* Should be 32x32 if my memory serves me correctly */
579 unsigned char icon
[128];
582 nubus_get_rsrc_mem(&icon
, ent
, 128);
585 /* We should actually plot these somewhere in the framebuffer
586 init. This is just to demonstrate that they do, in fact,
588 for (y
= 0; y
< 32; y
++) {
590 for (x
= 0; x
< 32; x
++) {
591 if (icon
[y
* 4 + x
/ 8] & (0x80 >> (x
% 8)))
601 static int __init
nubus_get_vendorinfo(struct nubus_board
*board
,
602 const struct nubus_dirent
*parent
)
604 struct nubus_dir dir
;
605 struct nubus_dirent ent
;
606 static char *vendor_fields
[6] = { "ID", "serial", "revision",
607 "part", "date", "unknown field" };
609 pr_info(" vendor info:\n");
610 nubus_get_subdir(parent
, &dir
);
611 pr_debug("%s: parent is 0x%p, dir is 0x%p\n",
612 __func__
, parent
->base
, dir
.base
);
614 while (nubus_readdir(&dir
, &ent
) != -1) {
617 /* These are all strings, we think */
618 nubus_get_rsrc_str(name
, &ent
, 64);
621 pr_info(" %s: %s\n", vendor_fields
[ent
.type
- 1], name
);
626 static int __init
nubus_get_board_resource(struct nubus_board
*board
, int slot
,
627 const struct nubus_dirent
*parent
)
629 struct nubus_dir dir
;
630 struct nubus_dirent ent
;
632 nubus_get_subdir(parent
, &dir
);
633 pr_debug("%s: parent is 0x%p, dir is 0x%p\n",
634 __func__
, parent
->base
, dir
.base
);
636 while (nubus_readdir(&dir
, &ent
) != -1) {
638 case NUBUS_RESID_TYPE
:
640 unsigned short nbtdata
[4];
641 /* This type is always the same, and is not
642 useful except insofar as it tells us that
643 we really are looking at a board resource. */
644 nubus_get_rsrc_mem(nbtdata
, &ent
, 8);
645 pr_info(" type: [cat 0x%x type 0x%x sw 0x%x hw 0x%x]\n",
646 nbtdata
[0], nbtdata
[1], nbtdata
[2], nbtdata
[3]);
647 if (nbtdata
[0] != 1 || nbtdata
[1] != 0 ||
648 nbtdata
[2] != 0 || nbtdata
[3] != 0)
649 pr_err("this sResource is not a board resource!\n");
652 case NUBUS_RESID_NAME
:
653 nubus_get_rsrc_str(board
->name
, &ent
, 64);
654 pr_info(" name: %s\n", board
->name
);
656 case NUBUS_RESID_ICON
:
657 nubus_get_icon(board
, &ent
);
659 case NUBUS_RESID_BOARDID
:
660 pr_info(" board id: 0x%x\n", ent
.data
);
662 case NUBUS_RESID_PRIMARYINIT
:
663 pr_info(" primary init offset: 0x%06x\n", ent
.data
);
665 case NUBUS_RESID_VENDORINFO
:
666 nubus_get_vendorinfo(board
, &ent
);
668 case NUBUS_RESID_FLAGS
:
669 pr_info(" flags: 0x%06x\n", ent
.data
);
671 case NUBUS_RESID_HWDEVID
:
672 pr_info(" hwdevid: 0x%06x\n", ent
.data
);
674 case NUBUS_RESID_SECONDINIT
:
675 pr_info(" secondary init offset: 0x%06x\n", ent
.data
);
677 /* WTF isn't this in the functional resources? */
678 case NUBUS_RESID_VIDNAMES
:
679 nubus_get_vidnames(board
, &ent
);
681 /* Same goes for this */
682 case NUBUS_RESID_VIDMODES
:
683 pr_info(" video mode parameter directory offset: 0x%06x\n",
687 pr_info(" unknown resource %02X, data 0x%06x\n",
694 /* Attempt to bypass the somewhat non-obvious arrangement of
695 sResources in the motherboard ROM */
696 static void __init
nubus_find_rom_dir(struct nubus_board
* board
)
699 unsigned char *romdir
;
700 struct nubus_dir dir
;
701 struct nubus_dirent ent
;
703 /* Check for the extra directory just under the format block */
705 nubus_rewind(&rp
, 4, board
->lanes
);
706 if (nubus_get_rom(&rp
, 4, board
->lanes
) != NUBUS_TEST_PATTERN
) {
707 /* OK, the ROM was telling the truth */
708 board
->directory
= board
->fblock
;
709 nubus_move(&board
->directory
,
710 nubus_expand32(board
->doffset
),
715 /* On "slot zero", you have to walk down a few more
716 directories to get to the equivalent of a real card's root
717 directory. We don't know what they were smoking when they
718 came up with this. */
719 romdir
= nubus_rom_addr(board
->slot
);
720 nubus_rewind(&romdir
, ROM_DIR_OFFSET
, board
->lanes
);
721 dir
.base
= dir
.ptr
= romdir
;
723 dir
.mask
= board
->lanes
;
725 /* This one points to an "Unknown Macintosh" directory */
726 if (nubus_readdir(&dir
, &ent
) == -1)
729 if (console_loglevel
>= CONSOLE_LOGLEVEL_DEBUG
)
730 printk(KERN_INFO
"nubus_get_rom_dir: entry %02x %06x\n", ent
.type
, ent
.data
);
731 /* This one takes us to where we want to go. */
732 if (nubus_readdir(&dir
, &ent
) == -1)
734 if (console_loglevel
>= CONSOLE_LOGLEVEL_DEBUG
)
735 printk(KERN_DEBUG
"nubus_get_rom_dir: entry %02x %06x\n", ent
.type
, ent
.data
);
736 nubus_get_subdir(&ent
, &dir
);
738 /* Resource ID 01, also an "Unknown Macintosh" */
739 if (nubus_readdir(&dir
, &ent
) == -1)
741 if (console_loglevel
>= CONSOLE_LOGLEVEL_DEBUG
)
742 printk(KERN_DEBUG
"nubus_get_rom_dir: entry %02x %06x\n", ent
.type
, ent
.data
);
744 /* FIXME: the first one is *not* always the right one. We
745 suspect this has something to do with the ROM revision.
746 "The HORROR ROM" (LC-series) uses 0x7e, while "The HORROR
747 Continues" (Q630) uses 0x7b. The DAFB Macs evidently use
748 something else. Please run "Slots" on your Mac (see
749 include/linux/nubus.h for where to get this program) and
750 tell us where the 'SiDirPtr' for Slot 0 is. If you feel
751 brave, you should also use MacsBug to walk down the ROM
752 directories like this function does and try to find the
753 path to that address... */
754 if (nubus_readdir(&dir
, &ent
) == -1)
756 if (console_loglevel
>= CONSOLE_LOGLEVEL_DEBUG
)
757 printk(KERN_DEBUG
"nubus_get_rom_dir: entry %02x %06x\n", ent
.type
, ent
.data
);
760 nubus_get_subdir(&ent
, &dir
);
761 board
->directory
= dir
.base
;
764 /* Even more evil laughter... */
766 board
->directory
= board
->fblock
;
767 nubus_move(&board
->directory
, nubus_expand32(board
->doffset
), board
->lanes
);
768 printk(KERN_ERR
"nubus_get_rom_dir: ROM weirdness! Notify the developers...\n");
771 /* Add a board (might be many devices) to the list */
772 static struct nubus_board
* __init
nubus_add_board(int slot
, int bytelanes
)
774 struct nubus_board
*board
;
775 struct nubus_board
**boardp
;
778 struct nubus_dir dir
;
779 struct nubus_dirent ent
;
781 /* Move to the start of the format block */
782 rp
= nubus_rom_addr(slot
);
783 nubus_rewind(&rp
, FORMAT_BLOCK_SIZE
, bytelanes
);
785 /* Actually we should probably panic if this fails */
786 if ((board
= kzalloc(sizeof(*board
), GFP_ATOMIC
)) == NULL
)
790 /* Dump the format block for debugging purposes */
791 pr_debug("Slot %X, format block at 0x%p:\n", slot
, rp
);
792 pr_debug("%02lx\n", nubus_get_rom(&rp
, 1, bytelanes
));
793 pr_debug("%02lx\n", nubus_get_rom(&rp
, 1, bytelanes
));
794 pr_debug("%08lx\n", nubus_get_rom(&rp
, 4, bytelanes
));
795 pr_debug("%02lx\n", nubus_get_rom(&rp
, 1, bytelanes
));
796 pr_debug("%02lx\n", nubus_get_rom(&rp
, 1, bytelanes
));
797 pr_debug("%08lx\n", nubus_get_rom(&rp
, 4, bytelanes
));
798 pr_debug("%08lx\n", nubus_get_rom(&rp
, 4, bytelanes
));
799 pr_debug("%08lx\n", nubus_get_rom(&rp
, 4, bytelanes
));
803 board
->slot_addr
= (unsigned long)nubus_slot_addr(slot
);
804 board
->doffset
= nubus_get_rom(&rp
, 4, bytelanes
);
805 /* rom_length is *supposed* to be the total length of the
806 * ROM. In practice it is the "amount of ROM used to compute
807 * the CRC." So some jokers decide to set it to zero and
808 * set the crc to zero so they don't have to do any math.
809 * See the Performa 460 ROM, for example. Those Apple "engineers".
811 board
->rom_length
= nubus_get_rom(&rp
, 4, bytelanes
);
812 board
->crc
= nubus_get_rom(&rp
, 4, bytelanes
);
813 board
->rev
= nubus_get_rom(&rp
, 1, bytelanes
);
814 board
->format
= nubus_get_rom(&rp
, 1, bytelanes
);
815 board
->lanes
= bytelanes
;
817 /* Directory offset should be small and negative... */
818 if (!(board
->doffset
& 0x00FF0000))
819 pr_warn("Dodgy doffset!\n");
820 dpat
= nubus_get_rom(&rp
, 4, bytelanes
);
821 if (dpat
!= NUBUS_TEST_PATTERN
)
822 pr_warn("Wrong test pattern %08lx!\n", dpat
);
825 * I wonder how the CRC is meant to work -
827 * CSA: According to MAC docs, not all cards pass the CRC anyway,
828 * since the initial Macintosh ROM releases skipped the check.
831 /* Attempt to work around slot zero weirdness */
832 nubus_find_rom_dir(board
);
833 nubus_get_root_dir(board
, &dir
);
835 /* We're ready to rock */
836 pr_info("Slot %X:\n", slot
);
838 /* Each slot should have one board resource and any number of
839 functional resources. So we'll fill in some fields in the
840 struct nubus_board from the board resource, then walk down
841 the list of functional resources, spinning out a nubus_dev
843 if (nubus_readdir(&dir
, &ent
) == -1) {
844 /* We can't have this! */
845 pr_err("Board resource not found!\n");
848 pr_info(" Board resource:\n");
849 nubus_get_board_resource(board
, slot
, &ent
);
852 /* Aaaarrrrgghh! The LC III motherboard has *two* board
853 resources. I have no idea WTF to do about this. */
855 while (nubus_readdir(&dir
, &ent
) != -1) {
856 struct nubus_dev
*dev
;
857 struct nubus_dev
**devp
;
859 dev
= nubus_get_functional_resource(board
, slot
, &ent
);
863 /* We zeroed this out above */
864 if (board
->first_dev
== NULL
)
865 board
->first_dev
= dev
;
867 /* Put it on the global NuBus device chain. Keep entries in order. */
868 for (devp
= &nubus_devices
; *devp
!= NULL
;
869 devp
= &((*devp
)->next
))
875 /* Put it on the global NuBus board chain. Keep entries in order. */
876 for (boardp
= &nubus_boards
; *boardp
!= NULL
;
877 boardp
= &((*boardp
)->next
))
885 void __init
nubus_probe_slot(int slot
)
891 rp
= nubus_rom_addr(slot
);
892 for (i
= 4; i
; i
--) {
896 card_present
= hwreg_present(rp
);
904 /* The last byte of the format block consists of two
905 nybbles which are "mirror images" of each other.
906 These show us the valid bytelanes */
907 if ((((dp
>> 4) ^ dp
) & 0x0F) != 0x0F)
909 /* Check that this value is actually *on* one of the
910 bytelanes it claims are valid! */
911 if ((dp
& 0x0F) >= (1 << i
))
914 /* Looks promising. Let's put it on the list. */
915 nubus_add_board(slot
, dp
);
921 void __init
nubus_scan_bus(void)
925 /* This might not work on your machine */
926 #ifdef I_WANT_TO_PROBE_SLOT_ZERO
929 for (slot
= 9; slot
< 15; slot
++) {
930 nubus_probe_slot(slot
);
934 static int __init
nubus_init(void)
939 /* Initialize the NuBus interrupts */
946 #ifdef TRY_TO_DODGE_WSOD
947 /* Rogue Ethernet interrupts can kill the machine if we don't
948 do this. Obviously this is bogus. Hopefully the local VIA
949 gurus can fix the real cause of the problem. */
954 pr_info("NuBus: Scanning NuBus slots.\n");
955 nubus_devices
= NULL
;
962 subsys_initcall(nubus_init
);