Commit 2f7dd07e authored by Finn Thain's avatar Finn Thain Committed by Geert Uytterhoeven

nubus: Rework /proc/bus/nubus/s/ implementation

The /proc/bus/nubus/s/ directory tree for any slot s is missing a lot
of information. The struct file_operations methods have long been left
unimplemented (hence the familiar compile-time warning, "Need to set
some I/O handlers here").

Slot resources have a complex structure which varies depending on board
function. The logic for interpreting these ROM data structures is found
in nubus.c. Let's not duplicate that logic in proc.c.

Create the /proc/bus/nubus/s/ inodes while scanning slot s. During
descent through slot resource subdirectories, call the new
nubus_proc_add_foo() functions to create the procfs inodes.

Also add a new function, nubus_seq_write_rsrc_mem(), to write the
contents of a particular slot resource to a given seq_file. This is
used by the procfs file_operations methods, to finally give userspace
access to slot ROM information, such as the available video modes.
Tested-by: default avatarStan Johnson <userm57@yahoo.com>
Signed-off-by: default avatarFinn Thain <fthain@telegraphics.com.au>
Signed-off-by: default avatarGeert Uytterhoeven <geert@linux-m68k.org>
parent 883b8cb3
This diff is collapsed.
...@@ -11,24 +11,28 @@ ...@@ -11,24 +11,28 @@
structure in /proc analogous to the structure of the NuBus ROM structure in /proc analogous to the structure of the NuBus ROM
resources. resources.
Therefore each NuBus device is in fact a directory, which may in Therefore each board function gets a directory, which may in turn
turn contain subdirectories. The "files" correspond to NuBus contain subdirectories. Each slot resource is a file. Unrecognized
resource records. For those types of records which we know how to resources are empty files, since every resource ID requires a special
convert to formats that are meaningful to userspace (mostly just case (e.g. if the resource ID implies a directory or block, then its
icons) these files will provide "cooked" data. Otherwise they will value has to be interpreted as a slot ROM pointer etc.).
simply provide raw access (read-only of course) to the ROM. */ */
#include <linux/types.h> #include <linux/types.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/nubus.h> #include <linux/nubus.h>
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#include <linux/seq_file.h> #include <linux/seq_file.h>
#include <linux/slab.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <asm/byteorder.h> #include <asm/byteorder.h>
/*
* /proc/bus/nubus/devices stuff
*/
static int static int
nubus_devices_proc_show(struct seq_file *m, void *v) nubus_devices_proc_show(struct seq_file *m, void *v)
{ {
...@@ -61,96 +65,141 @@ static const struct file_operations nubus_devices_proc_fops = { ...@@ -61,96 +65,141 @@ static const struct file_operations nubus_devices_proc_fops = {
static struct proc_dir_entry *proc_bus_nubus_dir; 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
*/
struct proc_dir_entry *nubus_proc_add_board(struct nubus_board *board)
{
char name[2];
if (!proc_bus_nubus_dir)
return NULL;
snprintf(name, sizeof(name), "%x", board->slot);
return proc_mkdir(name, proc_bus_nubus_dir);
}
/* The PDE private data for any directory under /proc/bus/nubus/x/
* is the bytelanes value for the board in slot x.
*/
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;
if (!procdir)
return NULL;
snprintf(name, sizeof(name), "%x", ent->type);
return proc_mkdir_data(name, 0555, procdir, (void *)lanes);
}
/* 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.
*/
struct nubus_proc_pde_data {
unsigned char *res_ptr;
unsigned int res_size;
}; };
static void nubus_proc_subdir(struct nubus_dev* dev, static struct nubus_proc_pde_data *
struct proc_dir_entry* parent, nubus_proc_alloc_pde_data(unsigned char *ptr, unsigned int size)
struct nubus_dir* dir)
{ {
struct nubus_dirent ent; struct nubus_proc_pde_data *pde_data;
/* Some of these are directories, others aren't */ pde_data = kmalloc(sizeof(*pde_data), GFP_KERNEL);
while (nubus_readdir(dir, &ent) != -1) { if (!pde_data)
char name[9]; return NULL;
struct proc_dir_entry* e;
pde_data->res_ptr = ptr;
snprintf(name, sizeof(name), "%x", ent.type); pde_data->res_size = size;
e = proc_create(name, S_IFREG | S_IRUGO | S_IWUSR, parent, return pde_data;
&nubus_proc_subdir_fops);
if (!e)
return;
}
} }
/* Can't do this recursively since the root directory is structured static int nubus_proc_rsrc_show(struct seq_file *m, void *v)
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; struct inode *inode = m->private;
struct nubus_proc_pde_data *pde_data;
/* We know these are all directories (board resource + one or
more functional resources) */ pde_data = PDE_DATA(inode);
while (nubus_readdir(root, &ent) != -1) { if (!pde_data)
char name[9]; return 0;
struct proc_dir_entry* e;
struct nubus_dir dir; if (pde_data->res_size > m->size)
return -EFBIG;
snprintf(name, sizeof(name), "%x", ent.type);
e = proc_mkdir(name, parent); if (pde_data->res_size) {
if (!e) return; int lanes = (int)proc_get_parent_data(inode);
struct nubus_dirent ent;
/* And descend */
if (nubus_get_subdir(&ent, &dir) == -1) { if (!lanes)
/* This shouldn't happen */ return 0;
printk(KERN_ERR "NuBus root directory node %x:%x has no subdir!\n",
dev->board->slot, ent.type); ent.mask = lanes;
continue; ent.base = pde_data->res_ptr;
} else { ent.data = 0;
nubus_proc_subdir(dev, e, &dir); nubus_seq_write_rsrc_mem(m, &ent, pde_data->res_size);
} } else {
unsigned int data = (unsigned int)pde_data->res_ptr;
seq_putc(m, data >> 16);
seq_putc(m, data >> 8);
seq_putc(m, data >> 0);
} }
return 0;
} }
int nubus_proc_attach_device(struct nubus_dev *dev) static int nubus_proc_rsrc_open(struct inode *inode, struct file *file)
{
return single_open(file, nubus_proc_rsrc_show, inode);
}
static const struct file_operations nubus_proc_rsrc_fops = {
.open = nubus_proc_rsrc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
void nubus_proc_add_rsrc_mem(struct proc_dir_entry *procdir,
const struct nubus_dirent *ent,
unsigned int size)
{ {
struct proc_dir_entry *e;
struct nubus_dir root;
char name[9]; char name[9];
struct nubus_proc_pde_data *pde_data;
if (dev == NULL) { if (!procdir)
printk(KERN_ERR return;
"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;
}
if (dev->board->procdir)
return 0;
/* Create a directory */ snprintf(name, sizeof(name), "%x", ent->type);
snprintf(name, sizeof(name), "%x", dev->board->slot); if (size)
e = proc_mkdir(name, proc_bus_nubus_dir); pde_data = nubus_proc_alloc_pde_data(nubus_dirptr(ent), size);
dev->board->procdir = e; else
if (!e) pde_data = NULL;
return -ENOMEM; proc_create_data(name, S_IFREG | 0444, procdir,
&nubus_proc_rsrc_fops, pde_data);
}
/* Now recursively populate it with files */ void nubus_proc_add_rsrc(struct proc_dir_entry *procdir,
nubus_get_root_dir(dev->board, &root); const struct nubus_dirent *ent)
nubus_proc_populate(dev, e, &root); {
char name[9];
unsigned char *data = (unsigned char *)ent->data;
return 0; if (!procdir)
return;
snprintf(name, sizeof(name), "%x", ent->type);
proc_create_data(name, S_IFREG | 0444, procdir,
&nubus_proc_rsrc_fops,
nubus_proc_alloc_pde_data(data, 0));
} }
EXPORT_SYMBOL(nubus_proc_attach_device);
/* /*
* /proc/nubus stuff * /proc/nubus stuff
...@@ -219,18 +268,11 @@ static const struct file_operations nubus_proc_fops = { ...@@ -219,18 +268,11 @@ static const struct file_operations nubus_proc_fops = {
.release = seq_release, .release = seq_release,
}; };
void __init proc_bus_nubus_add_devices(void)
{
struct nubus_dev *dev;
for(dev = nubus_devices; dev; dev = dev->next)
nubus_proc_attach_device(dev);
}
void __init nubus_proc_init(void) void __init nubus_proc_init(void)
{ {
proc_create("nubus", 0, NULL, &nubus_proc_fops); proc_create("nubus", 0, NULL, &nubus_proc_fops);
proc_bus_nubus_dir = proc_mkdir("bus/nubus", NULL); proc_bus_nubus_dir = proc_mkdir("bus/nubus", NULL);
if (!proc_bus_nubus_dir)
return;
proc_create("devices", 0, proc_bus_nubus_dir, &nubus_devices_proc_fops); proc_create("devices", 0, proc_bus_nubus_dir, &nubus_devices_proc_fops);
proc_bus_nubus_add_devices();
} }
...@@ -13,11 +13,15 @@ ...@@ -13,11 +13,15 @@
#include <asm/nubus.h> #include <asm/nubus.h>
#include <uapi/linux/nubus.h> #include <uapi/linux/nubus.h>
struct proc_dir_entry;
struct seq_file;
struct nubus_dir { struct nubus_dir {
unsigned char *base; unsigned char *base;
unsigned char *ptr; unsigned char *ptr;
int done; int done;
int mask; int mask;
struct proc_dir_entry *procdir;
}; };
struct nubus_dirent { struct nubus_dirent {
...@@ -84,12 +88,33 @@ extern struct nubus_board *nubus_boards; ...@@ -84,12 +88,33 @@ extern struct nubus_board *nubus_boards;
/* Generic NuBus interface functions, modelled after the PCI interface */ /* Generic NuBus interface functions, modelled after the PCI interface */
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
extern void nubus_proc_init(void); void nubus_proc_init(void);
struct proc_dir_entry *nubus_proc_add_board(struct nubus_board *board);
struct proc_dir_entry *nubus_proc_add_rsrc_dir(struct proc_dir_entry *procdir,
const struct nubus_dirent *ent,
struct nubus_board *board);
void nubus_proc_add_rsrc_mem(struct proc_dir_entry *procdir,
const struct nubus_dirent *ent,
unsigned int size);
void nubus_proc_add_rsrc(struct proc_dir_entry *procdir,
const struct nubus_dirent *ent);
#else #else
static inline void nubus_proc_init(void) {} static inline void nubus_proc_init(void) {}
static inline
struct proc_dir_entry *nubus_proc_add_board(struct nubus_board *board)
{ return NULL; }
static inline
struct proc_dir_entry *nubus_proc_add_rsrc_dir(struct proc_dir_entry *procdir,
const struct nubus_dirent *ent,
struct nubus_board *board)
{ return NULL; }
static inline void nubus_proc_add_rsrc_mem(struct proc_dir_entry *procdir,
const struct nubus_dirent *ent,
unsigned int size) {}
static inline void nubus_proc_add_rsrc(struct proc_dir_entry *procdir,
const struct nubus_dirent *ent) {}
#endif #endif
int nubus_proc_attach_device(struct nubus_dev *dev);
/* If we need more precision we can add some more of these */ /* If we need more precision we can add some more of these */
struct nubus_dev *nubus_find_type(unsigned short category, struct nubus_dev *nubus_find_type(unsigned short category,
unsigned short type, unsigned short type,
...@@ -125,8 +150,12 @@ int nubus_get_subdir(const struct nubus_dirent *ent, ...@@ -125,8 +150,12 @@ int nubus_get_subdir(const struct nubus_dirent *ent,
struct nubus_dir *dir); struct nubus_dir *dir);
void nubus_get_rsrc_mem(void *dest, const struct nubus_dirent *dirent, void nubus_get_rsrc_mem(void *dest, const struct nubus_dirent *dirent,
unsigned int len); unsigned int len);
void nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent, unsigned int nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent,
unsigned int maxlen); unsigned int len);
void nubus_seq_write_rsrc_mem(struct seq_file *m,
const struct nubus_dirent *dirent,
unsigned int len);
unsigned char *nubus_dirptr(const struct nubus_dirent *nd);
/* Returns a pointer to the "standard" slot space. */ /* Returns a pointer to the "standard" slot space. */
static inline void *nubus_slot_addr(int slot) static inline void *nubus_slot_addr(int slot)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment