/*
* Macintosh Nubus Interface Code
*
* Originally by Alan Cox
*
* Mostly rewritten by David Huggins-Daines, C. Scott Ananian,
* and others.
*/
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/nubus.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/module.h>
#include <asm/setup.h>
#include <asm/system.h>
#include <asm/page.h>
#include <asm/hwtest.h>
#include <linux/proc_fs.h>
#include <asm/mac_via.h>
#include <asm/mac_oss.h>
extern void via_nubus_init(void);
extern void oss_nubus_init(void);
/* Constants */
/* This is, of course, the size in bytelanes, rather than the size in
actual bytes */
#define FORMAT_BLOCK_SIZE 20
#define ROM_DIR_OFFSET 0x24
#define NUBUS_TEST_PATTERN 0x5A932BC7
/* Define this if you like to live dangerously - it is known not to
work on pretty much every machine except the Quadra 630 and the LC
III. */
#undef I_WANT_TO_PROBE_SLOT_ZERO
/* This sometimes helps combat failure to boot */
#undef TRY_TO_DODGE_WSOD
/* Globals */
struct nubus_dev* nubus_devices;
struct nubus_board* nubus_boards;
/* Meaning of "bytelanes":
The card ROM may appear on any or all bytes of each long word in
NuBus memory. The low 4 bits of the "map" value found in the
format block (at the top of the slot address space, as well as at
the top of the MacOS ROM) tells us which bytelanes, i.e. which byte
offsets within each longword, are valid. Thus:
A map of 0x0f, as found in the MacOS ROM, means that all bytelanes
are valid.
A map of 0xf0 means that no bytelanes are valid (We pray that we
will never encounter this, but stranger things have happened)
A map of 0xe1 means that only the MSB of each long word is actually
part of the card ROM. (We hope to never encounter NuBus on a
little-endian machine. Again, stranger things have happened)
A map of 0x78 means that only the LSB of each long word is valid.
Etcetera, etcetera. Hopefully this clears up some confusion over
what the following code actually does. */
static inline int not_useful(void *p, int map)
{
unsigned long pv=(unsigned long)p;
pv &= 3;
if(map & (1<<pv))
return 0;
return 1;
}
static unsigned long nubus_get_rom(unsigned char **ptr, int len, int map)
{
/* This will hold the result */
unsigned long v = 0;
unsigned char *p = *ptr;
while(len)
{
v <<= 8;
while(not_useful(p,map))
p++;
v |= *p++;
len--;
}
*ptr = p;
return v;
}
static void nubus_rewind(unsigned char **ptr, int len, int map)
{
unsigned char *p=*ptr;
/* Sanity check */
if(len > 65536)
printk(KERN_ERR "rewind of 0x%08x!\n", len);
while(len)
{
do
{
p--;
}
while(not_useful(p, map));
len--;
}
*ptr=p;
}
static void nubus_advance(unsigned char **ptr, int len, int map)
{
unsigned char *p = *ptr;
if(len>65536)
printk(KERN_ERR "advance of 0x%08x!\n", len);
while(len)
{
while(not_useful(p,map))
p++;
p++;
len--;
}
*ptr = p;
}
static void nubus_move(unsigned char **ptr, int len, int map)
{
if(len > 0)
nubus_advance(ptr, len, map);
else if(len < 0)
nubus_rewind(ptr, -len, map);
}
/* Now, functions to read the sResource tree */
/* Each sResource entry consists of a 1-byte ID and a 3-byte data
field. If that data field contains an offset, then obviously we
have to expand it from a 24-bit signed number to a 32-bit signed
number. */
static inline long nubus_expand32(long foo)
{
if(foo & 0x00800000) /* 24bit negative */
foo |= 0xFF000000;
return foo;
}
static inline void *nubus_rom_addr(int slot)
{
/*
* Returns the first byte after the card. We then walk
* backwards to get the lane register and the config
*/
return (void *)(0xF1000000+(slot<<24));
}
static unsigned char *nubus_dirptr(const struct nubus_dirent *nd)
{
unsigned char *p = nd->base;
/* Essentially, just step over the bytelanes using whatever
offset we might have found */
nubus_move(&p, nubus_expand32(nd->data), nd->mask);
/* And return the value */
return p;
}
/* These two are for pulling resource data blocks (i.e. stuff that's
pointed to with offsets) out of the card ROM. */
void nubus_get_rsrc_mem(void *dest, const struct nubus_dirent* dirent,
int len)
{
unsigned char