123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- #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 <linux/uaccess.h>
- #include <asm/byteorder.h>
- static int
- nubus_devices_proc_show(struct seq_file *m, void *v)
- {
- struct nubus_rsrc *fres;
- 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 struct proc_dir_entry *proc_bus_nubus_dir;
- 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);
- }
- 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);
- }
- struct nubus_proc_pde_data {
- unsigned char *res_ptr;
- unsigned int res_size;
- };
- static struct nubus_proc_pde_data *
- nubus_proc_alloc_pde_data(unsigned char *ptr, unsigned int size)
- {
- struct nubus_proc_pde_data *pded;
- pded = kmalloc(sizeof(*pded), GFP_KERNEL);
- if (!pded)
- return NULL;
- pded->res_ptr = ptr;
- pded->res_size = size;
- return pded;
- }
- static int nubus_proc_rsrc_show(struct seq_file *m, void *v)
- {
- 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 int nubus_rsrc_proc_open(struct inode *inode, struct file *file)
- {
- return single_open(file, nubus_proc_rsrc_show, inode);
- }
- 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,
- };
- void nubus_proc_add_rsrc_mem(struct proc_dir_entry *procdir,
- const struct nubus_dirent *ent,
- unsigned int size)
- {
- char name[9];
- struct nubus_proc_pde_data *pded;
- if (!procdir)
- return;
- snprintf(name, sizeof(name), "%x", ent->type);
- if (size)
- pded = nubus_proc_alloc_pde_data(nubus_dirptr(ent), size);
- else
- pded = NULL;
- 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)
- {
- char name[9];
- unsigned char *data = (unsigned char *)ent->data;
- if (!procdir)
- return;
- snprintf(name, sizeof(name), "%x", ent->type);
- proc_create_data(name, S_IFREG | 0444, procdir,
- &nubus_rsrc_proc_ops,
- nubus_proc_alloc_pde_data(data, 0));
- }
- void __init nubus_proc_init(void)
- {
- proc_create_single("nubus", 0, NULL, nubus_proc_show);
- proc_bus_nubus_dir = proc_mkdir("bus/nubus", NULL);
- if (!proc_bus_nubus_dir)
- return;
- proc_create_single("devices", 0, proc_bus_nubus_dir,
- nubus_devices_proc_show);
- }
|