diff options
Diffstat (limited to 'drivers/nubus')
| -rw-r--r-- | drivers/nubus/Makefile | 3 | ||||
| -rw-r--r-- | drivers/nubus/bus.c | 106 | ||||
| -rw-r--r-- | drivers/nubus/nubus.c | 915 | ||||
| -rw-r--r-- | drivers/nubus/proc.c | 304 |
4 files changed, 649 insertions, 679 deletions
diff --git a/drivers/nubus/Makefile b/drivers/nubus/Makefile index 21bda2031e7e..0f03032d2c01 100644 --- a/drivers/nubus/Makefile +++ b/drivers/nubus/Makefile @@ -1,7 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-only # # Makefile for the nubus specific drivers. # -obj-y := nubus.o +obj-y := nubus.o bus.o obj-$(CONFIG_PROC_FS) += proc.o diff --git a/drivers/nubus/bus.c b/drivers/nubus/bus.c new file mode 100644 index 000000000000..12df4d88970c --- /dev/null +++ b/drivers/nubus/bus.c @@ -0,0 +1,106 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Bus implementation for the NuBus subsystem. +// +// Copyright (C) 2017 Finn Thain + +#include <linux/device.h> +#include <linux/dma-mapping.h> +#include <linux/list.h> +#include <linux/nubus.h> +#include <linux/seq_file.h> +#include <linux/slab.h> + +#define to_nubus_board(d) container_of(d, struct nubus_board, dev) +#define to_nubus_driver(d) container_of(d, struct nubus_driver, driver) + +static int nubus_device_probe(struct device *dev) +{ + struct nubus_driver *ndrv = to_nubus_driver(dev->driver); + int err = -ENODEV; + + if (ndrv->probe) + err = ndrv->probe(to_nubus_board(dev)); + return err; +} + +static void nubus_device_remove(struct device *dev) +{ + struct nubus_driver *ndrv = to_nubus_driver(dev->driver); + + if (ndrv->remove) + ndrv->remove(to_nubus_board(dev)); +} + +static const struct bus_type nubus_bus_type = { + .name = "nubus", + .probe = nubus_device_probe, + .remove = nubus_device_remove, +}; + +int nubus_driver_register(struct nubus_driver *ndrv) +{ + ndrv->driver.bus = &nubus_bus_type; + return driver_register(&ndrv->driver); +} +EXPORT_SYMBOL(nubus_driver_register); + +void nubus_driver_unregister(struct nubus_driver *ndrv) +{ + driver_unregister(&ndrv->driver); +} +EXPORT_SYMBOL(nubus_driver_unregister); + +static struct device nubus_parent = { + .init_name = "nubus", +}; + +static int __init nubus_bus_register(void) +{ + return bus_register(&nubus_bus_type); +} +postcore_initcall(nubus_bus_register); + +int __init nubus_parent_device_register(void) +{ + return device_register(&nubus_parent); +} + +static void nubus_device_release(struct device *dev) +{ + struct nubus_board *board = to_nubus_board(dev); + struct nubus_rsrc *fres, *tmp; + + list_for_each_entry_safe(fres, tmp, &nubus_func_rsrcs, list) + if (fres->board == board) { + list_del(&fres->list); + kfree(fres); + } + kfree(board); +} + +int nubus_device_register(struct nubus_board *board) +{ + board->dev.parent = &nubus_parent; + board->dev.release = nubus_device_release; + board->dev.bus = &nubus_bus_type; + dev_set_name(&board->dev, "slot.%X", board->slot); + board->dev.dma_mask = &board->dev.coherent_dma_mask; + dma_set_mask(&board->dev, DMA_BIT_MASK(32)); + return device_register(&board->dev); +} + +static int nubus_print_device_name_fn(struct device *dev, void *data) +{ + struct nubus_board *board = to_nubus_board(dev); + struct seq_file *m = data; + + seq_printf(m, "Slot %X: %s\n", board->slot, board->name); + return 0; +} + +int nubus_proc_show(struct seq_file *m, void *data) +{ + return bus_for_each_dev(&nubus_bus_type, NULL, m, + nubus_print_device_name_fn); +} diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c index 43926cd25ae8..ab0f32b901c8 100644 --- a/drivers/nubus/nubus.c +++ b/drivers/nubus/nubus.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Macintosh Nubus Interface Code * @@ -13,17 +14,12 @@ #include <linux/nubus.h> #include <linux/errno.h> #include <linux/init.h> -#include <linux/delay.h> #include <linux/module.h> +#include <linux/seq_file.h> #include <linux/slab.h> #include <asm/setup.h> #include <asm/page.h> #include <asm/hwtest.h> -#include <asm/mac_via.h> -#include <asm/mac_oss.h> - -extern void via_nubus_init(void); -extern void oss_nubus_init(void); /* Constants */ @@ -34,18 +30,16 @@ extern void oss_nubus_init(void); #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; +/* The "nubus.populate_procfs" parameter makes slot resources available in + * procfs. It's deprecated and disabled by default because procfs is no longer + * thought to be suitable for that and some board ROMs make it too expensive. + */ +bool nubus_populate_procfs; +module_param_named(populate_procfs, nubus_populate_procfs, bool, 0); + +LIST_HEAD(nubus_func_rsrcs); /* Meaning of "bytelanes": @@ -69,26 +63,26 @@ struct nubus_board* nubus_boards; 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; + unsigned long pv = (unsigned long)p; + pv &= 3; - if(map & (1<<pv)) + 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) - { + while (len) { v <<= 8; - while(not_useful(p,map)) + while (not_useful(p, map)) p++; v |= *p++; len--; @@ -99,31 +93,23 @@ static unsigned long nubus_get_rom(unsigned char **ptr, int len, int map) static void nubus_rewind(unsigned char **ptr, int len, int map) { - unsigned char *p=*ptr; + unsigned char *p = *ptr; - /* Sanity check */ - if(len > 65536) - printk(KERN_ERR "rewind of 0x%08x!\n", len); - while(len) - { - do - { + while (len) { + do { p--; - } - while(not_useful(p, map)); + } while (not_useful(p, map)); len--; } - *ptr=p; + *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)) + + while (len) { + while (not_useful(p, map)) p++; p++; len--; @@ -133,10 +119,15 @@ static void nubus_advance(unsigned char **ptr, int len, int map) static void nubus_move(unsigned char **ptr, int len, int map) { - if(len > 0) + unsigned long slot_space = (unsigned long)*ptr & 0xFF000000; + + if (len > 0) nubus_advance(ptr, len, map); - else if(len < 0) + else if (len < 0) nubus_rewind(ptr, -len, map); + + if (((unsigned long)*ptr & 0xFF000000) != slot_space) + pr_err("%s: moved out of slot address space!\n", __func__); } /* Now, functions to read the sResource tree */ @@ -148,23 +139,24 @@ static void nubus_move(unsigned char **ptr, int len, int map) static inline long nubus_expand32(long foo) { - if(foo & 0x00800000) /* 24bit negative */ + 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)); + return (void *)(0xF1000000 + (slot << 24)); } -static unsigned char *nubus_dirptr(const struct nubus_dirent *nd) +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); @@ -175,36 +167,64 @@ static unsigned char *nubus_dirptr(const struct nubus_dirent *nd) /* 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) +void nubus_get_rsrc_mem(void *dest, const struct nubus_dirent *dirent, + unsigned int len) { - unsigned char *t = (unsigned char *)dest; + unsigned char *t = dest; unsigned char *p = nubus_dirptr(dirent); - while(len) - { + + while (len) { *t++ = nubus_get_rom(&p, 1, dirent->mask); len--; } } EXPORT_SYMBOL(nubus_get_rsrc_mem); -void nubus_get_rsrc_str(void *dest, const struct nubus_dirent* dirent, - int len) +unsigned int nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent, + unsigned int len) { - unsigned char *t=(unsigned char *)dest; + char *t = dest; unsigned char *p = nubus_dirptr(dirent); - while(len) - { - *t = nubus_get_rom(&p, 1, dirent->mask); - if(!*t++) + + while (len > 1) { + unsigned char c = nubus_get_rom(&p, 1, dirent->mask); + + if (!c) break; + *t++ = c; len--; } + if (len > 0) + *t = '\0'; + return t - dest; } EXPORT_SYMBOL(nubus_get_rsrc_str); -int nubus_get_root_dir(const struct nubus_board* board, - struct nubus_dir* dir) +void nubus_seq_write_rsrc_mem(struct seq_file *m, + const struct nubus_dirent *dirent, + unsigned int len) +{ + unsigned long buf[32]; + unsigned int buf_size = sizeof(buf); + unsigned char *p = nubus_dirptr(dirent); + + /* If possible, write out full buffers */ + while (len >= buf_size) { + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(buf); i++) + buf[i] = nubus_get_rom(&p, sizeof(buf[0]), + dirent->mask); + seq_write(m, buf, buf_size); + len -= buf_size; + } + /* If not, write out individual bytes */ + while (len--) + seq_putc(m, nubus_get_rom(&p, 1, dirent->mask)); +} + +int nubus_get_root_dir(const struct nubus_board *board, + struct nubus_dir *dir) { dir->ptr = dir->base = board->directory; dir->done = 0; @@ -214,21 +234,20 @@ int nubus_get_root_dir(const struct nubus_board* board, EXPORT_SYMBOL(nubus_get_root_dir); /* This is a slyly renamed version of the above */ -int nubus_get_func_dir(const struct nubus_dev* dev, - struct nubus_dir* dir) +int nubus_get_func_dir(const struct nubus_rsrc *fres, struct nubus_dir *dir) { - dir->ptr = dir->base = dev->directory; + dir->ptr = dir->base = fres->directory; dir->done = 0; - dir->mask = dev->board->lanes; + dir->mask = fres->board->lanes; return 0; } EXPORT_SYMBOL(nubus_get_func_dir); -int nubus_get_board_dir(const struct nubus_board* board, - struct nubus_dir* dir) +int nubus_get_board_dir(const struct nubus_board *board, + struct nubus_dir *dir) { struct nubus_dirent ent; - + dir->ptr = dir->base = board->directory; dir->done = 0; dir->mask = board->lanes; @@ -256,6 +275,7 @@ EXPORT_SYMBOL(nubus_get_subdir); int nubus_readdir(struct nubus_dir *nd, struct nubus_dirent *ent) { u32 resid; + if (nd->done) return -1; @@ -266,95 +286,54 @@ int nubus_readdir(struct nubus_dir *nd, struct nubus_dirent *ent) resid = nubus_get_rom(&nd->ptr, 4, nd->mask); /* EOL marker, as per the Apple docs */ - if((resid&0xff000000) == 0xff000000) - { + if ((resid & 0xff000000) == 0xff000000) { /* Mark it as done */ nd->done = 1; return -1; } /* First byte is the resource ID */ - ent->type = resid >> 24; + ent->type = resid >> 24; /* Low 3 bytes might contain data (or might not) */ ent->data = resid & 0xffffff; - ent->mask = nd->mask; + ent->mask = nd->mask; return 0; } EXPORT_SYMBOL(nubus_readdir); -int nubus_rewinddir(struct nubus_dir* dir) +int nubus_rewinddir(struct nubus_dir *dir) { dir->ptr = dir->base; + dir->done = 0; return 0; } EXPORT_SYMBOL(nubus_rewinddir); /* Driver interface functions, more or less like in pci.c */ -struct nubus_dev* -nubus_find_device(unsigned short category, - unsigned short type, - unsigned short dr_hw, - unsigned short dr_sw, - const struct nubus_dev* from) -{ - struct nubus_dev* itor = - from ? from->next : nubus_devices; - - while (itor) { - if (itor->category == category - && itor->type == type - && itor->dr_hw == dr_hw - && itor->dr_sw == dr_sw) - return itor; - itor = itor->next; - } - return NULL; -} -EXPORT_SYMBOL(nubus_find_device); - -struct nubus_dev* -nubus_find_type(unsigned short category, - unsigned short type, - const struct nubus_dev* from) +struct nubus_rsrc *nubus_first_rsrc_or_null(void) { - struct nubus_dev* itor = - from ? from->next : nubus_devices; - - while (itor) { - if (itor->category == category - && itor->type == type) - return itor; - itor = itor->next; - } - return NULL; + return list_first_entry_or_null(&nubus_func_rsrcs, struct nubus_rsrc, + list); } -EXPORT_SYMBOL(nubus_find_type); +EXPORT_SYMBOL(nubus_first_rsrc_or_null); -struct nubus_dev* -nubus_find_slot(unsigned int slot, - const struct nubus_dev* from) +struct nubus_rsrc *nubus_next_rsrc_or_null(struct nubus_rsrc *from) { - struct nubus_dev* itor = - from ? from->next : nubus_devices; - - while (itor) { - if (itor->board->slot == slot) - return itor; - itor = itor->next; - } - return NULL; + if (list_is_last(&from->list, &nubus_func_rsrcs)) + return NULL; + return list_next_entry(from, list); } -EXPORT_SYMBOL(nubus_find_slot); +EXPORT_SYMBOL(nubus_next_rsrc_or_null); int -nubus_find_rsrc(struct nubus_dir* dir, unsigned char rsrc_type, - struct nubus_dirent* ent) +nubus_find_rsrc(struct nubus_dir *dir, unsigned char rsrc_type, + struct nubus_dirent *ent) { while (nubus_readdir(dir, ent) != -1) { if (ent->type == rsrc_type) return 0; - } + } return -1; } EXPORT_SYMBOL(nubus_find_rsrc); @@ -363,303 +342,310 @@ EXPORT_SYMBOL(nubus_find_rsrc); looking at, and print out lots and lots of information from the resource blocks. */ -/* FIXME: A lot of this stuff will eventually be useful after - initialization, for intelligently probing Ethernet and video chips, - among other things. The rest of it should go in the /proc code. - For now, we just use it to give verbose boot logs. */ +static int __init nubus_get_block_rsrc_dir(struct nubus_board *board, + struct proc_dir_entry *procdir, + const struct nubus_dirent *parent) +{ + struct nubus_dir dir; + struct nubus_dirent ent; -static int __init nubus_show_display_resource(struct nubus_dev* dev, - const struct nubus_dirent* ent) + nubus_get_subdir(parent, &dir); + dir.procdir = nubus_proc_add_rsrc_dir(procdir, parent, board); + + while (nubus_readdir(&dir, &ent) != -1) { + u32 size; + + nubus_get_rsrc_mem(&size, &ent, 4); + pr_debug(" block (0x%x), size %d\n", ent.type, size); + nubus_proc_add_rsrc_mem(dir.procdir, &ent, size); + } + return 0; +} + +static int __init nubus_get_display_vidmode(struct nubus_board *board, + struct proc_dir_entry *procdir, + const struct nubus_dirent *parent) +{ + struct nubus_dir dir; + struct nubus_dirent ent; + + nubus_get_subdir(parent, &dir); + dir.procdir = nubus_proc_add_rsrc_dir(procdir, parent, board); + + while (nubus_readdir(&dir, &ent) != -1) { + switch (ent.type) { + case 1: /* mVidParams */ + case 2: /* mTable */ + { + u32 size; + + nubus_get_rsrc_mem(&size, &ent, 4); + pr_debug(" block (0x%x), size %d\n", ent.type, + size); + nubus_proc_add_rsrc_mem(dir.procdir, &ent, size); + break; + } + default: + pr_debug(" unknown resource 0x%02x, data 0x%06x\n", + ent.type, ent.data); + nubus_proc_add_rsrc_mem(dir.procdir, &ent, 0); + } + } + return 0; +} + +static int __init nubus_get_display_resource(struct nubus_rsrc *fres, + struct proc_dir_entry *procdir, + const struct nubus_dirent *ent) { switch (ent->type) { case NUBUS_RESID_GAMMADIR: - printk(KERN_INFO " gamma directory offset: 0x%06x\n", ent->data); + pr_debug(" gamma directory offset: 0x%06x\n", ent->data); + nubus_get_block_rsrc_dir(fres->board, procdir, ent); break; case 0x0080 ... 0x0085: - printk(KERN_INFO " mode %02X info offset: 0x%06x\n", - ent->type, ent->data); + pr_debug(" mode 0x%02x info offset: 0x%06x\n", + ent->type, ent->data); + nubus_get_display_vidmode(fres->board, procdir, ent); break; default: - printk(KERN_INFO " unknown resource %02X, data 0x%06x\n", - ent->type, ent->data); + pr_debug(" unknown resource 0x%02x, data 0x%06x\n", + ent->type, ent->data); + nubus_proc_add_rsrc_mem(procdir, ent, 0); } return 0; } -static int __init nubus_show_network_resource(struct nubus_dev* dev, - const struct nubus_dirent* ent) +static int __init nubus_get_network_resource(struct nubus_rsrc *fres, + struct proc_dir_entry *procdir, + const struct nubus_dirent *ent) { switch (ent->type) { case NUBUS_RESID_MAC_ADDRESS: { char addr[6]; - int i; - + nubus_get_rsrc_mem(addr, ent, 6); - printk(KERN_INFO " MAC address: "); - for (i = 0; i < 6; i++) - printk("%02x%s", addr[i] & 0xff, - i == 5 ? "" : ":"); - printk("\n"); + pr_debug(" MAC address: %pM\n", addr); + nubus_proc_add_rsrc_mem(procdir, ent, 6); break; } default: - printk(KERN_INFO " unknown resource %02X, data 0x%06x\n", - ent->type, ent->data); + pr_debug(" unknown resource 0x%02x, data 0x%06x\n", + ent->type, ent->data); + nubus_proc_add_rsrc_mem(procdir, ent, 0); } return 0; } -static int __init nubus_show_cpu_resource(struct nubus_dev* dev, - const struct nubus_dirent* ent) +static int __init nubus_get_cpu_resource(struct nubus_rsrc *fres, + struct proc_dir_entry *procdir, + const struct nubus_dirent *ent) { switch (ent->type) { case NUBUS_RESID_MEMINFO: { unsigned long meminfo[2]; + nubus_get_rsrc_mem(&meminfo, ent, 8); - printk(KERN_INFO " memory: [ 0x%08lx 0x%08lx ]\n", - meminfo[0], meminfo[1]); + pr_debug(" memory: [ 0x%08lx 0x%08lx ]\n", + meminfo[0], meminfo[1]); + nubus_proc_add_rsrc_mem(procdir, ent, 8); break; } case NUBUS_RESID_ROMINFO: { unsigned long rominfo[2]; + nubus_get_rsrc_mem(&rominfo, ent, 8); - printk(KERN_INFO " ROM: [ 0x%08lx 0x%08lx ]\n", - rominfo[0], rominfo[1]); + pr_debug(" ROM: [ 0x%08lx 0x%08lx ]\n", + rominfo[0], rominfo[1]); + nubus_proc_add_rsrc_mem(procdir, ent, 8); break; } default: - printk(KERN_INFO " unknown resource %02X, data 0x%06x\n", - ent->type, ent->data); + pr_debug(" unknown resource 0x%02x, data 0x%06x\n", + ent->type, ent->data); + nubus_proc_add_rsrc_mem(procdir, ent, 0); } return 0; } -static int __init nubus_show_private_resource(struct nubus_dev* dev, - const struct nubus_dirent* ent) +static int __init nubus_get_private_resource(struct nubus_rsrc *fres, + struct proc_dir_entry *procdir, + const struct nubus_dirent *ent) { - switch (dev->category) { + switch (fres->category) { case NUBUS_CAT_DISPLAY: - nubus_show_display_resource(dev, ent); + nubus_get_display_resource(fres, procdir, ent); break; case NUBUS_CAT_NETWORK: - nubus_show_network_resource(dev, ent); + nubus_get_network_resource(fres, procdir, ent); break; case NUBUS_CAT_CPU: - nubus_show_cpu_resource(dev, ent); + nubus_get_cpu_resource(fres, procdir, ent); break; default: - printk(KERN_INFO " unknown resource %02X, data 0x%06x\n", - ent->type, ent->data); + pr_debug(" unknown resource 0x%02x, data 0x%06x\n", + ent->type, ent->data); + nubus_proc_add_rsrc_mem(procdir, ent, 0); } return 0; } -static struct nubus_dev* __init - nubus_get_functional_resource(struct nubus_board* board, - int slot, - const struct nubus_dirent* parent) +static struct nubus_rsrc * __init +nubus_get_functional_resource(struct nubus_board *board, int slot, + const struct nubus_dirent *parent) { - struct nubus_dir dir; + struct nubus_dir dir; struct nubus_dirent ent; - struct nubus_dev* dev; - - printk(KERN_INFO " Function 0x%02x:\n", parent->type); - nubus_get_subdir(parent, &dir); + struct nubus_rsrc *fres; - /* Apple seems to have botched the ROM on the IIx */ - if (slot == 0 && (unsigned long)dir.base % 2) - dir.base += 1; - - if (console_loglevel >= 10) - printk(KERN_DEBUG "nubus_get_functional_resource: parent is 0x%p, dir is 0x%p\n", - parent->base, dir.base); + pr_debug(" Functional resource 0x%02x:\n", parent->type); + nubus_get_subdir(parent, &dir); + dir.procdir = nubus_proc_add_rsrc_dir(board->procdir, parent, board); /* Actually we should probably panic if this fails */ - if ((dev = kzalloc(sizeof(*dev), GFP_ATOMIC)) == NULL) - return NULL; - dev->resid = parent->type; - dev->directory = dir.base; - dev->board = board; - - while (nubus_readdir(&dir, &ent) != -1) - { - switch(ent.type) - { + fres = kzalloc(sizeof(*fres), GFP_ATOMIC); + if (!fres) + return NULL; + fres->resid = parent->type; + fres->directory = dir.base; + fres->board = board; + + while (nubus_readdir(&dir, &ent) != -1) { + switch (ent.type) { case NUBUS_RESID_TYPE: { unsigned short nbtdata[4]; + nubus_get_rsrc_mem(nbtdata, &ent, 8); - dev->category = nbtdata[0]; - dev->type = nbtdata[1]; - dev->dr_sw = nbtdata[2]; - dev->dr_hw = nbtdata[3]; - printk(KERN_INFO " type: [cat 0x%x type 0x%x hw 0x%x sw 0x%x]\n", - nbtdata[0], nbtdata[1], nbtdata[2], nbtdata[3]); + fres->category = nbtdata[0]; + fres->type = nbtdata[1]; + fres->dr_sw = nbtdata[2]; + fres->dr_hw = nbtdata[3]; + pr_debug(" type: [cat 0x%x type 0x%x sw 0x%x hw 0x%x]\n", + nbtdata[0], nbtdata[1], nbtdata[2], nbtdata[3]); + nubus_proc_add_rsrc_mem(dir.procdir, &ent, 8); break; } case NUBUS_RESID_NAME: { - nubus_get_rsrc_str(dev->name, &ent, 64); - printk(KERN_INFO " name: %s\n", dev->name); + char name[64]; + unsigned int len; + + len = nubus_get_rsrc_str(name, &ent, sizeof(name)); + pr_debug(" name: %s\n", name); + nubus_proc_add_rsrc_mem(dir.procdir, &ent, len + 1); break; } case NUBUS_RESID_DRVRDIR: { /* MacOS driver. If we were NetBSD we might use this :-) */ - struct nubus_dir drvr_dir; - struct nubus_dirent drvr_ent; - nubus_get_subdir(&ent, &drvr_dir); - nubus_readdir(&drvr_dir, &drvr_ent); - dev->driver = nubus_dirptr(&drvr_ent); - printk(KERN_INFO " driver at: 0x%p\n", - dev->driver); + pr_debug(" driver directory offset: 0x%06x\n", + ent.data); + nubus_get_block_rsrc_dir(board, dir.procdir, &ent); break; } case NUBUS_RESID_MINOR_BASEOS: + { /* We will need this in order to support multiple framebuffers. It might be handy for Ethernet as well */ - nubus_get_rsrc_mem(&dev->iobase, &ent, 4); - printk(KERN_INFO " memory offset: 0x%08lx\n", - dev->iobase); + u32 base_offset; + + nubus_get_rsrc_mem(&base_offset, &ent, 4); + pr_debug(" memory offset: 0x%08x\n", base_offset); + nubus_proc_add_rsrc_mem(dir.procdir, &ent, 4); break; + } case NUBUS_RESID_MINOR_LENGTH: + { /* Ditto */ - nubus_get_rsrc_mem(&dev->iosize, &ent, 4); - printk(KERN_INFO " memory length: 0x%08lx\n", - dev->iosize); - break; + u32 length; + + nubus_get_rsrc_mem(&length, &ent, 4); + pr_debug(" memory length: 0x%08x\n", length); + nubus_proc_add_rsrc_mem(dir.procdir, &ent, 4); + break; + } case NUBUS_RESID_FLAGS: - dev->flags = ent.data; - printk(KERN_INFO " flags: 0x%06x\n", dev->flags); + pr_debug(" flags: 0x%06x\n", ent.data); + nubus_proc_add_rsrc(dir.procdir, &ent); break; case NUBUS_RESID_HWDEVID: - dev->hwdevid = ent.data; - printk(KERN_INFO " hwdevid: 0x%06x\n", dev->hwdevid); + pr_debug(" hwdevid: 0x%06x\n", ent.data); + nubus_proc_add_rsrc(dir.procdir, &ent); break; default: - /* Local/Private resources have their own - function */ - nubus_show_private_resource(dev, &ent); + if (nubus_populate_procfs) + nubus_get_private_resource(fres, dir.procdir, + &ent); } } - - return dev; -} - -/* This is cool. */ -static int __init nubus_get_vidnames(struct nubus_board* board, - const struct nubus_dirent* parent) -{ - struct nubus_dir dir; - struct nubus_dirent ent; - /* FIXME: obviously we want to put this in a header file soon */ - struct vidmode { - u32 size; - /* Don't know what this is yet */ - u16 id; - /* Longest one I've seen so far is 26 characters */ - char name[32]; - }; - - printk(KERN_INFO " video modes supported:\n"); - nubus_get_subdir(parent, &dir); - if (console_loglevel >= 10) - printk(KERN_DEBUG "nubus_get_vidnames: parent is 0x%p, dir is 0x%p\n", - parent->base, dir.base); - - while(nubus_readdir(&dir, &ent) != -1) - { - struct vidmode mode; - u32 size; - /* First get the length */ - nubus_get_rsrc_mem(&size, &ent, 4); - - /* Now clobber the whole thing */ - if (size > sizeof(mode) - 1) - size = sizeof(mode) - 1; - memset(&mode, 0, sizeof(mode)); - nubus_get_rsrc_mem(&mode, &ent, size); - printk (KERN_INFO " %02X: (%02X) %s\n", ent.type, - mode.id, mode.name); - } - return 0; + return fres; } /* This is *really* cool. */ -static int __init nubus_get_icon(struct nubus_board* board, - const struct nubus_dirent* ent) +static int __init nubus_get_icon(struct nubus_board *board, + struct proc_dir_entry *procdir, + const struct nubus_dirent *ent) { /* Should be 32x32 if my memory serves me correctly */ - unsigned char icon[128]; - int x, y; - + u32 icon[32]; + int i; + nubus_get_rsrc_mem(&icon, ent, 128); - printk(KERN_INFO " icon:\n"); - - /* We should actually plot these somewhere in the framebuffer - init. This is just to demonstrate that they do, in fact, - exist */ - for (y = 0; y < 32; y++) { - printk(KERN_INFO " "); - for (x = 0; x < 32; x++) { - if (icon[y*4 + x/8] - & (0x80 >> (x%8))) - printk("*"); - else - printk(" "); - } - printk("\n"); - } + pr_debug(" icon:\n"); + for (i = 0; i < 8; i++) + pr_debug(" %08x %08x %08x %08x\n", + icon[i * 4 + 0], icon[i * 4 + 1], + icon[i * 4 + 2], icon[i * 4 + 3]); + nubus_proc_add_rsrc_mem(procdir, ent, 128); + return 0; } -static int __init nubus_get_vendorinfo(struct nubus_board* board, - const struct nubus_dirent* parent) +static int __init nubus_get_vendorinfo(struct nubus_board *board, + struct proc_dir_entry *procdir, + const struct nubus_dirent *parent) { - struct nubus_dir dir; + struct nubus_dir dir; struct nubus_dirent ent; - static char* vendor_fields[6] = {"ID", "serial", "revision", - "part", "date", "unknown field"}; + static char *vendor_fields[6] = { "ID", "serial", "revision", + "part", "date", "unknown field" }; - printk(KERN_INFO " vendor info:\n"); + pr_debug(" vendor info:\n"); nubus_get_subdir(parent, &dir); - if (console_loglevel >= 10) - printk(KERN_DEBUG "nubus_get_vendorinfo: parent is 0x%p, dir is 0x%p\n", - parent->base, dir.base); + dir.procdir = nubus_proc_add_rsrc_dir(procdir, parent, board); - while(nubus_readdir(&dir, &ent) != -1) - { + while (nubus_readdir(&dir, &ent) != -1) { char name[64]; - + unsigned int len; + /* These are all strings, we think */ - nubus_get_rsrc_str(name, &ent, 64); - if (ent.type > 5) + len = nubus_get_rsrc_str(name, &ent, sizeof(name)); + if (ent.type < 1 || ent.type > 5) ent.type = 5; - printk(KERN_INFO " %s: %s\n", - vendor_fields[ent.type-1], name); + pr_debug(" %s: %s\n", vendor_fields[ent.type - 1], name); + nubus_proc_add_rsrc_mem(dir.procdir, &ent, len + 1); } return 0; } -static int __init nubus_get_board_resource(struct nubus_board* board, int slot, - const struct nubus_dirent* parent) +static int __init nubus_get_board_resource(struct nubus_board *board, int slot, + const struct nubus_dirent *parent) { - struct nubus_dir dir; + struct nubus_dir dir; struct nubus_dirent ent; - + + pr_debug(" Board resource 0x%02x:\n", parent->type); nubus_get_subdir(parent, &dir); - if (console_loglevel >= 10) - printk(KERN_DEBUG "nubus_get_board_resource: parent is 0x%p, dir is 0x%p\n", - parent->base, dir.base); + dir.procdir = nubus_proc_add_rsrc_dir(board->procdir, parent, board); - while(nubus_readdir(&dir, &ent) != -1) - { + while (nubus_readdir(&dir, &ent) != -1) { switch (ent.type) { case NUBUS_RESID_TYPE: { @@ -668,171 +654,105 @@ static int __init nubus_get_board_resource(struct nubus_board* board, int slot, useful except insofar as it tells us that we really are looking at a board resource. */ nubus_get_rsrc_mem(nbtdata, &ent, 8); - printk(KERN_INFO " type: [cat 0x%x type 0x%x hw 0x%x sw 0x%x]\n", - nbtdata[0], nbtdata[1], nbtdata[2], - nbtdata[3]); + pr_debug(" type: [cat 0x%x type 0x%x sw 0x%x hw 0x%x]\n", + nbtdata[0], nbtdata[1], nbtdata[2], nbtdata[3]); if (nbtdata[0] != 1 || nbtdata[1] != 0 || nbtdata[2] != 0 || nbtdata[3] != 0) - printk(KERN_ERR "this sResource is not a board resource!\n"); + pr_err("Slot %X: sResource is not a board resource!\n", + slot); + nubus_proc_add_rsrc_mem(dir.procdir, &ent, 8); break; } case NUBUS_RESID_NAME: - nubus_get_rsrc_str(board->name, &ent, 64); - printk(KERN_INFO " name: %s\n", board->name); + { + unsigned int len; + + len = nubus_get_rsrc_str(board->name, &ent, + sizeof(board->name)); + pr_debug(" name: %s\n", board->name); + nubus_proc_add_rsrc_mem(dir.procdir, &ent, len + 1); break; + } case NUBUS_RESID_ICON: - nubus_get_icon(board, &ent); + nubus_get_icon(board, dir.procdir, &ent); break; case NUBUS_RESID_BOARDID: - printk(KERN_INFO " board id: 0x%x\n", ent.data); + pr_debug(" board id: 0x%x\n", ent.data); + nubus_proc_add_rsrc(dir.procdir, &ent); break; case NUBUS_RESID_PRIMARYINIT: - printk(KERN_INFO " primary init offset: 0x%06x\n", ent.data); + pr_debug(" primary init offset: 0x%06x\n", ent.data); + nubus_proc_add_rsrc(dir.procdir, &ent); break; case NUBUS_RESID_VENDORINFO: - nubus_get_vendorinfo(board, &ent); + nubus_get_vendorinfo(board, dir.procdir, &ent); break; case NUBUS_RESID_FLAGS: - printk(KERN_INFO " flags: 0x%06x\n", ent.data); + pr_debug(" flags: 0x%06x\n", ent.data); + nubus_proc_add_rsrc(dir.procdir, &ent); break; case NUBUS_RESID_HWDEVID: - printk(KERN_INFO " hwdevid: 0x%06x\n", ent.data); + pr_debug(" hwdevid: 0x%06x\n", ent.data); + nubus_proc_add_rsrc(dir.procdir, &ent); break; case NUBUS_RESID_SECONDINIT: - printk(KERN_INFO " secondary init offset: 0x%06x\n", ent.data); + pr_debug(" secondary init offset: 0x%06x\n", + ent.data); + nubus_proc_add_rsrc(dir.procdir, &ent); break; - /* WTF isn't this in the functional resources? */ + /* WTF isn't this in the functional resources? */ case NUBUS_RESID_VIDNAMES: - nubus_get_vidnames(board, &ent); + pr_debug(" vidnames directory offset: 0x%06x\n", + ent.data); + nubus_get_block_rsrc_dir(board, dir.procdir, &ent); break; /* Same goes for this */ case NUBUS_RESID_VIDMODES: - printk(KERN_INFO " video mode parameter directory offset: 0x%06x\n", - ent.data); - break; + pr_debug(" video mode parameter directory offset: 0x%06x\n", + ent.data); + nubus_proc_add_rsrc(dir.procdir, &ent); + break; default: - printk(KERN_INFO " unknown resource %02X, data 0x%06x\n", - ent.type, ent.data); + pr_debug(" unknown resource 0x%02x, data 0x%06x\n", + ent.type, ent.data); + nubus_proc_add_rsrc_mem(dir.procdir, &ent, 0); } } return 0; } -/* Attempt to bypass the somewhat non-obvious arrangement of - sResources in the motherboard ROM */ -static void __init nubus_find_rom_dir(struct nubus_board* board) +static void __init nubus_add_board(int slot, int bytelanes) { - unsigned char* rp; - unsigned char* romdir; - struct nubus_dir dir; - struct nubus_dirent ent; - - /* Check for the extra directory just under the format block */ - rp = board->fblock; - nubus_rewind(&rp, 4, board->lanes); - if (nubus_get_rom(&rp, 4, board->lanes) != NUBUS_TEST_PATTERN) { - /* OK, the ROM was telling the truth */ - board->directory = board->fblock; - nubus_move(&board->directory, - nubus_expand32(board->doffset), - board->lanes); - return; - } - - /* On "slot zero", you have to walk down a few more - directories to get to the equivalent of a real card's root - directory. We don't know what they were smoking when they - came up with this. */ - romdir = nubus_rom_addr(board->slot); - nubus_rewind(&romdir, ROM_DIR_OFFSET, board->lanes); - dir.base = dir.ptr = romdir; - dir.done = 0; - dir.mask = board->lanes; - - /* This one points to an "Unknown Macintosh" directory */ - if (nubus_readdir(&dir, &ent) == -1) - goto badrom; - - if (console_loglevel >= 10) - printk(KERN_INFO "nubus_get_rom_dir: entry %02x %06x\n", ent.type, ent.data); - /* This one takes us to where we want to go. */ - if (nubus_readdir(&dir, &ent) == -1) - goto badrom; - if (console_loglevel >= 10) - printk(KERN_DEBUG "nubus_get_rom_dir: entry %02x %06x\n", ent.type, ent.data); - nubus_get_subdir(&ent, &dir); - - /* Resource ID 01, also an "Unknown Macintosh" */ - if (nubus_readdir(&dir, &ent) == -1) - goto badrom; - if (console_loglevel >= 10) - printk(KERN_DEBUG "nubus_get_rom_dir: entry %02x %06x\n", ent.type, ent.data); - - /* FIXME: the first one is *not* always the right one. We - suspect this has something to do with the ROM revision. - "The HORROR ROM" (LC-series) uses 0x7e, while "The HORROR - Continues" (Q630) uses 0x7b. The DAFB Macs evidently use - something else. Please run "Slots" on your Mac (see - include/linux/nubus.h for where to get this program) and - tell us where the 'SiDirPtr' for Slot 0 is. If you feel - brave, you should also use MacsBug to walk down the ROM - directories like this function does and try to find the - path to that address... */ - if (nubus_readdir(&dir, &ent) == -1) - goto badrom; - if (console_loglevel >= 10) - printk(KERN_DEBUG "nubus_get_rom_dir: entry %02x %06x\n", ent.type, ent.data); - - /* Bwahahahaha... */ - nubus_get_subdir(&ent, &dir); - board->directory = dir.base; - return; - - /* Even more evil laughter... */ - badrom: - board->directory = board->fblock; - nubus_move(&board->directory, nubus_expand32(board->doffset), board->lanes); - printk(KERN_ERR "nubus_get_rom_dir: ROM weirdness! Notify the developers...\n"); -} - -/* Add a board (might be many devices) to the list */ -static struct nubus_board* __init nubus_add_board(int slot, int bytelanes) -{ - struct nubus_board* board; - struct nubus_board** boardp; - + struct nubus_board *board; unsigned char *rp; unsigned long dpat; struct nubus_dir dir; struct nubus_dirent ent; + int prev_resid = -1; /* Move to the start of the format block */ - rp = nubus_rom_addr(slot); + rp = nubus_rom_addr(slot); nubus_rewind(&rp, FORMAT_BLOCK_SIZE, bytelanes); /* Actually we should probably panic if this fails */ if ((board = kzalloc(sizeof(*board), GFP_ATOMIC)) == NULL) - return NULL; + return; board->fblock = rp; /* Dump the format block for debugging purposes */ - if (console_loglevel >= 10) { - int i; - printk(KERN_DEBUG "Slot %X, format block at 0x%p\n", - slot, rp); - printk(KERN_DEBUG "Format block: "); - for (i = 0; i < FORMAT_BLOCK_SIZE; i += 4) { - unsigned short foo, bar; - foo = nubus_get_rom(&rp, 2, bytelanes); - bar = nubus_get_rom(&rp, 2, bytelanes); - printk("%04x %04x ", foo, bar); - } - printk("\n"); - rp = board->fblock; - } - + pr_debug("Slot %X, format block at 0x%p:\n", slot, rp); + pr_debug("%08lx\n", nubus_get_rom(&rp, 4, bytelanes)); + pr_debug("%08lx\n", nubus_get_rom(&rp, 4, bytelanes)); + pr_debug("%08lx\n", nubus_get_rom(&rp, 4, bytelanes)); + pr_debug("%02lx\n", nubus_get_rom(&rp, 1, bytelanes)); + pr_debug("%02lx\n", nubus_get_rom(&rp, 1, bytelanes)); + pr_debug("%08lx\n", nubus_get_rom(&rp, 4, bytelanes)); + pr_debug("%02lx\n", nubus_get_rom(&rp, 1, bytelanes)); + pr_debug("%02lx\n", nubus_get_rom(&rp, 1, bytelanes)); + rp = board->fblock; + board->slot = slot; - board->slot_addr = (unsigned long) nubus_slot_addr(slot); + board->slot_addr = (unsigned long)nubus_slot_addr(slot); board->doffset = nubus_get_rom(&rp, 4, bytelanes); /* rom_length is *supposed* to be the total length of the * ROM. In practice it is the "amount of ROM used to compute @@ -843,16 +763,16 @@ static struct nubus_board* __init nubus_add_board(int slot, int bytelanes) board->rom_length = nubus_get_rom(&rp, 4, bytelanes); board->crc = nubus_get_rom(&rp, 4, bytelanes); board->rev = nubus_get_rom(&rp, 1, bytelanes); - board->format = nubus_get_rom(&rp,1, bytelanes); + board->format = nubus_get_rom(&rp, 1, bytelanes); board->lanes = bytelanes; /* Directory offset should be small and negative... */ - if(!(board->doffset & 0x00FF0000)) - printk(KERN_WARNING "Dodgy doffset!\n"); + if (!(board->doffset & 0x00FF0000)) + pr_warn("Slot %X: Dodgy doffset!\n", slot); dpat = nubus_get_rom(&rp, 4, bytelanes); - if(dpat != NUBUS_TEST_PATTERN) - printk(KERN_WARNING "Wrong test pattern %08lx!\n", dpat); - + if (dpat != NUBUS_TEST_PATTERN) + pr_warn("Slot %X: Wrong test pattern %08lx!\n", slot, dpat); + /* * I wonder how the CRC is meant to work - * any takers ? @@ -860,90 +780,81 @@ static struct nubus_board* __init nubus_add_board(int slot, int bytelanes) * since the initial Macintosh ROM releases skipped the check. */ - /* Attempt to work around slot zero weirdness */ - nubus_find_rom_dir(board); - nubus_get_root_dir(board, &dir); + /* Set up the directory pointer */ + board->directory = board->fblock; + nubus_move(&board->directory, nubus_expand32(board->doffset), + board->lanes); + + nubus_get_root_dir(board, &dir); /* We're ready to rock */ - printk(KERN_INFO "Slot %X:\n", slot); + pr_debug("Slot %X resources:\n", slot); /* Each slot should have one board resource and any number of - functional resources. So we'll fill in some fields in the - struct nubus_board from the board resource, then walk down - the list of functional resources, spinning out a nubus_dev - for each of them. */ + * functional resources. So we'll fill in some fields in the + * struct nubus_board from the board resource, then walk down + * the list of functional resources, spinning out a nubus_rsrc + * for each of them. + */ if (nubus_readdir(&dir, &ent) == -1) { /* We can't have this! */ - printk(KERN_ERR "Board resource not found!\n"); - return NULL; - } else { - printk(KERN_INFO " Board resource:\n"); - nubus_get_board_resource(board, slot, &ent); + pr_err("Slot %X: Board resource not found!\n", slot); + kfree(board); + return; } - /* Aaaarrrrgghh! The LC III motherboard has *two* board - resources. I have no idea WTF to do about this. */ + if (ent.type < 1 || ent.type > 127) + pr_warn("Slot %X: Board resource ID is invalid!\n", slot); + + board->procdir = nubus_proc_add_board(board); + + nubus_get_board_resource(board, slot, &ent); while (nubus_readdir(&dir, &ent) != -1) { - struct nubus_dev* dev; - struct nubus_dev** devp; - dev = nubus_get_functional_resource(board, slot, &ent); - if (dev == NULL) + struct nubus_rsrc *fres; + + fres = nubus_get_functional_resource(board, slot, &ent); + if (fres == NULL) continue; - /* We zeroed this out above */ - if (board->first_dev == NULL) - board->first_dev = dev; - - /* Put it on the global NuBus device chain. Keep entries in order. */ - for (devp=&nubus_devices; *devp!=NULL; devp=&((*devp)->next)) - /* spin */; - *devp = dev; - dev->next = NULL; + /* Resources should appear in ascending ID order. This sanity + * check prevents duplicate resource IDs. + */ + if (fres->resid <= prev_resid) { + kfree(fres); + continue; + } + prev_resid = fres->resid; + + list_add_tail(&fres->list, &nubus_func_rsrcs); } - /* Put it on the global NuBus board chain. Keep entries in order. */ - for (boardp=&nubus_boards; *boardp!=NULL; boardp=&((*boardp)->next)) - /* spin */; - *boardp = board; - board->next = NULL; - - return board; + if (nubus_device_register(board)) + put_device(&board->dev); } -void __init nubus_probe_slot(int slot) +static void __init nubus_probe_slot(int slot) { unsigned char dp; - unsigned char* rp; + unsigned char *rp; int i; - rp = nubus_rom_addr(slot); - for(i = 4; i; i--) - { - unsigned long flags; - int card_present; - + rp = nubus_rom_addr(slot); + for (i = 4; i; i--) { rp--; - local_irq_save(flags); - card_present = hwreg_present(rp); - local_irq_restore(flags); - - if (!card_present) + if (!hwreg_present(rp)) continue; - printk(KERN_DEBUG "Now probing slot %X at %p\n", slot, rp); dp = *rp; - if(dp == 0) - continue; /* The last byte of the format block consists of two nybbles which are "mirror images" of each other. These show us the valid bytelanes */ - if ((((dp>>4) ^ dp) & 0x0F) != 0x0F) + if ((((dp >> 4) ^ dp) & 0x0F) != 0x0F) continue; /* Check that this value is actually *on* one of the bytelanes it claims are valid! */ - if ((dp & 0x0F) >= (1<<i)) + if (not_useful(rp, dp)) continue; /* Looks promising. Let's put it on the list. */ @@ -953,44 +864,28 @@ void __init nubus_probe_slot(int slot) } } -void __init nubus_scan_bus(void) +static void __init nubus_scan_bus(void) { int slot; - /* This might not work on your machine */ -#ifdef I_WANT_TO_PROBE_SLOT_ZERO - nubus_probe_slot(0); -#endif - for(slot = 9; slot < 15; slot++) - { + + pr_info("NuBus: Scanning NuBus slots.\n"); + for (slot = 9; slot < 15; slot++) { nubus_probe_slot(slot); } } static int __init nubus_init(void) { - if (!MACH_IS_MAC) - return 0; + int err; - /* Initialize the NuBus interrupts */ - if (oss_present) { - oss_nubus_init(); - } else { - via_nubus_init(); - } + if (!MACH_IS_MAC) + return 0; -#ifdef TRY_TO_DODGE_WSOD - /* Rogue Ethernet interrupts can kill the machine if we don't - do this. Obviously this is bogus. Hopefully the local VIA - gurus can fix the real cause of the problem. */ - mdelay(1000); -#endif - - /* And probe */ - printk("NuBus: Scanning NuBus slots.\n"); - nubus_devices = NULL; - nubus_boards = NULL; - nubus_scan_bus(); nubus_proc_init(); + err = nubus_parent_device_register(); + if (err) + return err; + nubus_scan_bus(); return 0; } diff --git a/drivers/nubus/proc.c b/drivers/nubus/proc.c index 5371b374f1fe..e7a347db708c 100644 --- a/drivers/nubus/proc.c +++ b/drivers/nubus/proc.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0 /* drivers/nubus/proc.c: Proc FS interface for NuBus. By David Huggins-Daines <dhd@debian.org> @@ -10,224 +11,191 @@ structure in /proc analogous to the structure of the NuBus ROM resources. - Therefore each NuBus device is in fact a directory, which may in - turn contain subdirectories. The "files" correspond to NuBus - resource records. For those types of records which we know how to - convert to formats that are meaningful to userspace (mostly just - icons) these files will provide "cooked" data. Otherwise they will - simply provide raw access (read-only of course) to the ROM. */ + Therefore each board function gets a directory, which may in turn + contain subdirectories. Each slot resource is a file. Unrecognized + resources are empty files, since every resource ID requires a special + case (e.g. if the resource ID implies a directory or block, then its + value has to be interpreted as a slot ROM pointer etc.). + */ #include <linux/types.h> #include <linux/kernel.h> #include <linux/nubus.h> #include <linux/proc_fs.h> #include <linux/seq_file.h> +#include <linux/slab.h> #include <linux/init.h> #include <linux/module.h> - -#include <asm/uaccess.h> +#include <linux/uaccess.h> #include <asm/byteorder.h> +/* + * /proc/bus/nubus/devices stuff + */ + static int nubus_devices_proc_show(struct seq_file *m, void *v) { - struct nubus_dev *dev = nubus_devices; - - while (dev) { - seq_printf(m, "%x\t%04x %04x %04x %04x", - dev->board->slot, - dev->category, - dev->type, - dev->dr_sw, - dev->dr_hw); - seq_printf(m, "\t%08lx\n", dev->board->slot_addr); - dev = dev->next; - } - return 0; -} + struct nubus_rsrc *fres; -static int nubus_devices_proc_open(struct inode *inode, struct file *file) -{ - return single_open(file, nubus_devices_proc_show, NULL); + for_each_func_rsrc(fres) + seq_printf(m, "%x\t%04x %04x %04x %04x\t%08lx\n", + fres->board->slot, fres->category, fres->type, + fres->dr_sw, fres->dr_hw, fres->board->slot_addr); + return 0; } -static const struct file_operations nubus_devices_proc_fops = { - .open = nubus_devices_proc_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - static struct proc_dir_entry *proc_bus_nubus_dir; -static const struct file_operations nubus_proc_subdir_fops = { -#warning Need to set some I/O handlers here -}; +/* + * /proc/bus/nubus/x/ stuff + */ -static void nubus_proc_subdir(struct nubus_dev* dev, - struct proc_dir_entry* parent, - struct nubus_dir* dir) +struct proc_dir_entry *nubus_proc_add_board(struct nubus_board *board) { - struct nubus_dirent ent; - - /* Some of these are directories, others aren't */ - while (nubus_readdir(dir, &ent) != -1) { - char name[8]; - struct proc_dir_entry* e; - - sprintf(name, "%x", ent.type); - e = proc_create(name, S_IFREG | S_IRUGO | S_IWUSR, parent, - &nubus_proc_subdir_fops); - if (!e) - return; - } -} + char name[2]; -/* Can't do this recursively since the root directory is structured - somewhat differently from the subdirectories */ -static void nubus_proc_populate(struct nubus_dev* dev, - struct proc_dir_entry* parent, - struct nubus_dir* root) -{ - struct nubus_dirent ent; - - /* We know these are all directories (board resource + one or - more functional resources) */ - while (nubus_readdir(root, &ent) != -1) { - char name[8]; - struct proc_dir_entry* e; - struct nubus_dir dir; - - sprintf(name, "%x", ent.type); - e = proc_mkdir(name, parent); - if (!e) return; - - /* And descend */ - if (nubus_get_subdir(&ent, &dir) == -1) { - /* This shouldn't happen */ - printk(KERN_ERR "NuBus root directory node %x:%x has no subdir!\n", - dev->board->slot, ent.type); - continue; - } else { - nubus_proc_subdir(dev, e, &dir); - } - } + if (!proc_bus_nubus_dir || !nubus_populate_procfs) + return NULL; + snprintf(name, sizeof(name), "%x", board->slot); + return proc_mkdir(name, proc_bus_nubus_dir); } -int nubus_proc_attach_device(struct nubus_dev *dev) -{ - struct proc_dir_entry *e; - struct nubus_dir root; - char name[8]; - - if (dev == NULL) { - printk(KERN_ERR - "NULL pointer in nubus_proc_attach_device, shoot the programmer!\n"); - return -1; - } - - if (dev->board == NULL) { - printk(KERN_ERR - "NULL pointer in nubus_proc_attach_device, shoot the programmer!\n"); - printk("dev = %p, dev->board = %p\n", dev, dev->board); - return -1; - } - - /* Create a directory */ - sprintf(name, "%x", dev->board->slot); - e = dev->procdir = proc_mkdir(name, proc_bus_nubus_dir); - if (!e) - return -ENOMEM; +/* The PDE private data for any directory under /proc/bus/nubus/x/ + * is the bytelanes value for the board in slot x. + */ - /* Now recursively populate it with files */ - nubus_get_root_dir(dev->board, &root); - nubus_proc_populate(dev, e, &root); +struct proc_dir_entry *nubus_proc_add_rsrc_dir(struct proc_dir_entry *procdir, + const struct nubus_dirent *ent, + struct nubus_board *board) +{ + char name[9]; + int lanes = board->lanes; - return 0; + if (!procdir || !nubus_populate_procfs) + return NULL; + snprintf(name, sizeof(name), "%x", ent->type); + remove_proc_subtree(name, procdir); + return proc_mkdir_data(name, 0555, procdir, (void *)lanes); } -EXPORT_SYMBOL(nubus_proc_attach_device); -/* - * /proc/nubus stuff +/* The PDE private data for a file under /proc/bus/nubus/x/ is a pointer to + * an instance of the following structure, which gives the location and size + * of the resource data in the slot ROM. For slot resources which hold only a + * small integer, this integer value is stored directly and size is set to 0. + * A NULL private data pointer indicates an unrecognized resource. */ -static int nubus_proc_show(struct seq_file *m, void *v) -{ - const struct nubus_board *board = v; - /* Display header on line 1 */ - if (v == SEQ_START_TOKEN) - seq_puts(m, "Nubus devices found:\n"); - else - seq_printf(m, "Slot %X: %s\n", board->slot, board->name); - return 0; -} +struct nubus_proc_pde_data { + unsigned char *res_ptr; + unsigned int res_size; +}; -static void *nubus_proc_start(struct seq_file *m, loff_t *_pos) +static struct nubus_proc_pde_data * +nubus_proc_alloc_pde_data(unsigned char *ptr, unsigned int size) { - struct nubus_board *board; - unsigned pos; + struct nubus_proc_pde_data *pded; - if (*_pos > LONG_MAX) + pded = kmalloc(sizeof(*pded), GFP_KERNEL); + if (!pded) return NULL; - pos = *_pos; - if (pos == 0) - return SEQ_START_TOKEN; - for (board = nubus_boards; board; board = board->next) - if (--pos == 0) - break; - return board; + + pded->res_ptr = ptr; + pded->res_size = size; + return pded; } -static void *nubus_proc_next(struct seq_file *p, void *v, loff_t *_pos) +static int nubus_proc_rsrc_show(struct seq_file *m, void *v) { - /* Walk the list of NuBus boards */ - struct nubus_board *board = v; - - ++*_pos; - if (v == SEQ_START_TOKEN) - board = nubus_boards; - else if (board) - board = board->next; - return board; + struct inode *inode = m->private; + struct nubus_proc_pde_data *pded; + + pded = pde_data(inode); + if (!pded) + return 0; + + if (pded->res_size > m->size) + return -EFBIG; + + if (pded->res_size) { + int lanes = (int)proc_get_parent_data(inode); + struct nubus_dirent ent; + + if (!lanes) + return 0; + + ent.mask = lanes; + ent.base = pded->res_ptr; + ent.data = 0; + nubus_seq_write_rsrc_mem(m, &ent, pded->res_size); + } else { + unsigned int data = (unsigned int)pded->res_ptr; + + seq_putc(m, data >> 16); + seq_putc(m, data >> 8); + seq_putc(m, data >> 0); + } + return 0; } -static void nubus_proc_stop(struct seq_file *p, void *v) +static int nubus_rsrc_proc_open(struct inode *inode, struct file *file) { + return single_open(file, nubus_proc_rsrc_show, inode); } -static const struct seq_operations nubus_proc_seqops = { - .start = nubus_proc_start, - .next = nubus_proc_next, - .stop = nubus_proc_stop, - .show = nubus_proc_show, +static const struct proc_ops nubus_rsrc_proc_ops = { + .proc_open = nubus_rsrc_proc_open, + .proc_read = seq_read, + .proc_lseek = seq_lseek, + .proc_release = single_release, }; -static int nubus_proc_open(struct inode *inode, struct file *file) +void nubus_proc_add_rsrc_mem(struct proc_dir_entry *procdir, + const struct nubus_dirent *ent, + unsigned int size) { - return seq_open(file, &nubus_proc_seqops); -} + char name[9]; + struct nubus_proc_pde_data *pded; -static const struct file_operations nubus_proc_fops = { - .open = nubus_proc_open, - .read = seq_read, - .llseek = seq_lseek, - .release = seq_release, -}; + if (!procdir || !nubus_populate_procfs) + return; -void __init proc_bus_nubus_add_devices(void) + snprintf(name, sizeof(name), "%x", ent->type); + if (size) + pded = nubus_proc_alloc_pde_data(nubus_dirptr(ent), size); + else + pded = NULL; + remove_proc_subtree(name, procdir); + proc_create_data(name, S_IFREG | 0444, procdir, + &nubus_rsrc_proc_ops, pded); +} + +void nubus_proc_add_rsrc(struct proc_dir_entry *procdir, + const struct nubus_dirent *ent) { - struct nubus_dev *dev; - - for(dev = nubus_devices; dev; dev = dev->next) - nubus_proc_attach_device(dev); + char name[9]; + unsigned char *data = (unsigned char *)ent->data; + + if (!procdir || !nubus_populate_procfs) + return; + + snprintf(name, sizeof(name), "%x", ent->type); + remove_proc_subtree(name, procdir); + proc_create_data(name, S_IFREG | 0444, procdir, + &nubus_rsrc_proc_ops, + nubus_proc_alloc_pde_data(data, 0)); } +/* + * /proc/nubus stuff + */ + void __init nubus_proc_init(void) { - proc_create("nubus", 0, NULL, &nubus_proc_fops); - if (!MACH_IS_MAC) - return; + proc_create_single("nubus", 0, NULL, nubus_proc_show); proc_bus_nubus_dir = proc_mkdir("bus/nubus", NULL); - proc_create("devices", 0, proc_bus_nubus_dir, &nubus_devices_proc_fops); - proc_bus_nubus_add_devices(); + if (!proc_bus_nubus_dir) + return; + proc_create_single("devices", 0, proc_bus_nubus_dir, + nubus_devices_proc_show); } |
