0001
0002
0003
0004
0005
0006
0007 #include <linux/module.h>
0008 #include <linux/isapnp.h>
0009 #include <linux/proc_fs.h>
0010 #include <linux/init.h>
0011 #include <linux/uaccess.h>
0012
0013 extern struct pnp_protocol isapnp_protocol;
0014
0015 static struct proc_dir_entry *isapnp_proc_bus_dir = NULL;
0016
0017 static loff_t isapnp_proc_bus_lseek(struct file *file, loff_t off, int whence)
0018 {
0019 return fixed_size_llseek(file, off, whence, 256);
0020 }
0021
0022 static ssize_t isapnp_proc_bus_read(struct file *file, char __user * buf,
0023 size_t nbytes, loff_t * ppos)
0024 {
0025 struct pnp_dev *dev = pde_data(file_inode(file));
0026 int pos = *ppos;
0027 int cnt, size = 256;
0028
0029 if (pos >= size)
0030 return 0;
0031 if (nbytes >= size)
0032 nbytes = size;
0033 if (pos + nbytes > size)
0034 nbytes = size - pos;
0035 cnt = nbytes;
0036
0037 if (!access_ok(buf, cnt))
0038 return -EINVAL;
0039
0040 isapnp_cfg_begin(dev->card->number, dev->number);
0041 for (; pos < 256 && cnt > 0; pos++, buf++, cnt--) {
0042 unsigned char val;
0043 val = isapnp_read_byte(pos);
0044 __put_user(val, buf);
0045 }
0046 isapnp_cfg_end();
0047
0048 *ppos = pos;
0049 return nbytes;
0050 }
0051
0052 static const struct proc_ops isapnp_proc_bus_proc_ops = {
0053 .proc_lseek = isapnp_proc_bus_lseek,
0054 .proc_read = isapnp_proc_bus_read,
0055 };
0056
0057 static int isapnp_proc_attach_device(struct pnp_dev *dev)
0058 {
0059 struct pnp_card *bus = dev->card;
0060 char name[16];
0061
0062 if (!bus->procdir) {
0063 sprintf(name, "%02x", bus->number);
0064 bus->procdir = proc_mkdir(name, isapnp_proc_bus_dir);
0065 if (!bus->procdir)
0066 return -ENOMEM;
0067 }
0068 sprintf(name, "%02x", dev->number);
0069 dev->procent = proc_create_data(name, S_IFREG | S_IRUGO, bus->procdir,
0070 &isapnp_proc_bus_proc_ops, dev);
0071 if (!dev->procent)
0072 return -ENOMEM;
0073 proc_set_size(dev->procent, 256);
0074 return 0;
0075 }
0076
0077 int __init isapnp_proc_init(void)
0078 {
0079 struct pnp_dev *dev;
0080
0081 isapnp_proc_bus_dir = proc_mkdir("bus/isapnp", NULL);
0082 protocol_for_each_dev(&isapnp_protocol, dev) {
0083 isapnp_proc_attach_device(dev);
0084 }
0085 return 0;
0086 }