Thomas Gleixner | 74ba920 | 2019-05-20 09:19:02 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * ISA Plug & Play support |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 4 | * Copyright (c) by Jaroslav Kysela <perex@perex.cz> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <linux/module.h> |
| 8 | #include <linux/isapnp.h> |
| 9 | #include <linux/proc_fs.h> |
| 10 | #include <linux/init.h> |
Andy Lutomirski | 13d4ea0 | 2016-07-14 13:22:57 -0700 | [diff] [blame] | 11 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
| 13 | extern struct pnp_protocol isapnp_protocol; |
| 14 | |
| 15 | static struct proc_dir_entry *isapnp_proc_bus_dir = NULL; |
| 16 | |
| 17 | static loff_t isapnp_proc_bus_lseek(struct file *file, loff_t off, int whence) |
| 18 | { |
Al Viro | c09ed2a | 2013-06-23 12:09:11 +0400 | [diff] [blame] | 19 | return fixed_size_llseek(file, off, whence, 256); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | } |
| 21 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 22 | static ssize_t isapnp_proc_bus_read(struct file *file, char __user * buf, |
| 23 | size_t nbytes, loff_t * ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | { |
Muchun Song | 359745d | 2022-01-21 22:14:23 -0800 | [diff] [blame] | 25 | struct pnp_dev *dev = pde_data(file_inode(file)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | int pos = *ppos; |
| 27 | int cnt, size = 256; |
| 28 | |
| 29 | if (pos >= size) |
| 30 | return 0; |
| 31 | if (nbytes >= size) |
| 32 | nbytes = size; |
| 33 | if (pos + nbytes > size) |
| 34 | nbytes = size - pos; |
| 35 | cnt = nbytes; |
| 36 | |
Linus Torvalds | 96d4f26 | 2019-01-03 18:57:57 -0800 | [diff] [blame] | 37 | if (!access_ok(buf, cnt)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | return -EINVAL; |
| 39 | |
| 40 | isapnp_cfg_begin(dev->card->number, dev->number); |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 41 | for (; pos < 256 && cnt > 0; pos++, buf++, cnt--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | unsigned char val; |
| 43 | val = isapnp_read_byte(pos); |
| 44 | __put_user(val, buf); |
| 45 | } |
| 46 | isapnp_cfg_end(); |
| 47 | |
| 48 | *ppos = pos; |
| 49 | return nbytes; |
| 50 | } |
| 51 | |
Alexey Dobriyan | 97a3253 | 2020-02-03 17:37:17 -0800 | [diff] [blame] | 52 | static const struct proc_ops isapnp_proc_bus_proc_ops = { |
| 53 | .proc_lseek = isapnp_proc_bus_lseek, |
| 54 | .proc_read = isapnp_proc_bus_read, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | static int isapnp_proc_attach_device(struct pnp_dev *dev) |
| 58 | { |
| 59 | struct pnp_card *bus = dev->card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | char name[16]; |
| 61 | |
Anupama K Patil | daadabf | 2021-04-29 01:09:01 +0530 | [diff] [blame] | 62 | if (!bus->procdir) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | sprintf(name, "%02x", bus->number); |
Anupama K Patil | daadabf | 2021-04-29 01:09:01 +0530 | [diff] [blame] | 64 | bus->procdir = proc_mkdir(name, isapnp_proc_bus_dir); |
| 65 | if (!bus->procdir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | return -ENOMEM; |
| 67 | } |
| 68 | sprintf(name, "%02x", dev->number); |
Anupama K Patil | daadabf | 2021-04-29 01:09:01 +0530 | [diff] [blame] | 69 | dev->procent = proc_create_data(name, S_IFREG | S_IRUGO, bus->procdir, |
Alexey Dobriyan | 97a3253 | 2020-02-03 17:37:17 -0800 | [diff] [blame] | 70 | &isapnp_proc_bus_proc_ops, dev); |
Anupama K Patil | daadabf | 2021-04-29 01:09:01 +0530 | [diff] [blame] | 71 | if (!dev->procent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | return -ENOMEM; |
Anupama K Patil | daadabf | 2021-04-29 01:09:01 +0530 | [diff] [blame] | 73 | proc_set_size(dev->procent, 256); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | return 0; |
| 75 | } |
| 76 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | int __init isapnp_proc_init(void) |
| 78 | { |
| 79 | struct pnp_dev *dev; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 80 | |
Alexey Dobriyan | 9c37066 | 2008-04-29 01:01:41 -0700 | [diff] [blame] | 81 | isapnp_proc_bus_dir = proc_mkdir("bus/isapnp", NULL); |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 82 | protocol_for_each_dev(&isapnp_protocol, dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | isapnp_proc_attach_device(dev); |
| 84 | } |
| 85 | return 0; |
| 86 | } |