^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * ISA Plug & Play support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/isapnp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) extern struct pnp_protocol isapnp_protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) static struct proc_dir_entry *isapnp_proc_bus_dir = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) static loff_t isapnp_proc_bus_lseek(struct file *file, loff_t off, int whence)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) return fixed_size_llseek(file, off, whence, 256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static ssize_t isapnp_proc_bus_read(struct file *file, char __user * buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) size_t nbytes, loff_t * ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct pnp_dev *dev = PDE_DATA(file_inode(file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) int pos = *ppos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) int cnt, size = 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) if (pos >= size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) if (nbytes >= size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) nbytes = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) if (pos + nbytes > size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) nbytes = size - pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) cnt = nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) if (!access_ok(buf, cnt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) isapnp_cfg_begin(dev->card->number, dev->number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) for (; pos < 256 && cnt > 0; pos++, buf++, cnt--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) unsigned char val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) val = isapnp_read_byte(pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) __put_user(val, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) isapnp_cfg_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) *ppos = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static const struct proc_ops isapnp_proc_bus_proc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) .proc_lseek = isapnp_proc_bus_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) .proc_read = isapnp_proc_bus_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static int isapnp_proc_attach_device(struct pnp_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct pnp_card *bus = dev->card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct proc_dir_entry *de, *e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) char name[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) if (!(de = bus->procdir)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) sprintf(name, "%02x", bus->number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) de = bus->procdir = proc_mkdir(name, isapnp_proc_bus_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (!de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) sprintf(name, "%02x", dev->number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) e = dev->procent = proc_create_data(name, S_IFREG | S_IRUGO, de,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) &isapnp_proc_bus_proc_ops, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) if (!e)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) proc_set_size(e, 256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) int __init isapnp_proc_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) struct pnp_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) isapnp_proc_bus_dir = proc_mkdir("bus/isapnp", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) protocol_for_each_dev(&isapnp_protocol, dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) isapnp_proc_attach_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }