| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | *  ISA Plug & Play support | 
| Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 3 | *  Copyright (c) by Jaroslav Kysela <perex@perex.cz> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | *   This program is free software; you can redistribute it and/or modify | 
|  | 6 | *   it under the terms of the GNU General Public License as published by | 
|  | 7 | *   the Free Software Foundation; either version 2 of the License, or | 
|  | 8 | *   (at your option) any later version. | 
|  | 9 | * | 
|  | 10 | *   This program is distributed in the hope that it will be useful, | 
|  | 11 | *   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 12 | *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|  | 13 | *   GNU General Public License for more details. | 
|  | 14 | * | 
|  | 15 | *   You should have received a copy of the GNU General Public License | 
|  | 16 | *   along with this program; if not, write to the Free Software | 
|  | 17 | *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | */ | 
|  | 19 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/module.h> | 
|  | 21 | #include <linux/isapnp.h> | 
|  | 22 | #include <linux/proc_fs.h> | 
|  | 23 | #include <linux/init.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <asm/uaccess.h> | 
|  | 25 |  | 
|  | 26 | extern struct pnp_protocol isapnp_protocol; | 
|  | 27 |  | 
|  | 28 | static struct proc_dir_entry *isapnp_proc_bus_dir = NULL; | 
|  | 29 |  | 
|  | 30 | static loff_t isapnp_proc_bus_lseek(struct file *file, loff_t off, int whence) | 
|  | 31 | { | 
|  | 32 | loff_t new = -1; | 
| Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 33 | struct inode *inode = file_inode(file); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 |  | 
| Arnd Bergmann | 6117d21 | 2010-06-05 13:28:09 +0200 | [diff] [blame] | 35 | mutex_lock(&inode->i_mutex); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | switch (whence) { | 
|  | 37 | case 0: | 
|  | 38 | new = off; | 
|  | 39 | break; | 
|  | 40 | case 1: | 
|  | 41 | new = file->f_pos + off; | 
|  | 42 | break; | 
|  | 43 | case 2: | 
|  | 44 | new = 256 + off; | 
|  | 45 | break; | 
|  | 46 | } | 
| Arnd Bergmann | 6117d21 | 2010-06-05 13:28:09 +0200 | [diff] [blame] | 47 | if (new < 0 || new > 256) | 
|  | 48 | new = -EINVAL; | 
|  | 49 | else | 
|  | 50 | file->f_pos = new; | 
|  | 51 | mutex_unlock(&inode->i_mutex); | 
|  | 52 | return new; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | } | 
|  | 54 |  | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 55 | static ssize_t isapnp_proc_bus_read(struct file *file, char __user * buf, | 
|  | 56 | size_t nbytes, loff_t * ppos) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { | 
| Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 58 | struct pnp_dev *dev = PDE_DATA(file_inode(file)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | int pos = *ppos; | 
|  | 60 | int cnt, size = 256; | 
|  | 61 |  | 
|  | 62 | if (pos >= size) | 
|  | 63 | return 0; | 
|  | 64 | if (nbytes >= size) | 
|  | 65 | nbytes = size; | 
|  | 66 | if (pos + nbytes > size) | 
|  | 67 | nbytes = size - pos; | 
|  | 68 | cnt = nbytes; | 
|  | 69 |  | 
|  | 70 | if (!access_ok(VERIFY_WRITE, buf, cnt)) | 
|  | 71 | return -EINVAL; | 
|  | 72 |  | 
|  | 73 | isapnp_cfg_begin(dev->card->number, dev->number); | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 74 | for (; pos < 256 && cnt > 0; pos++, buf++, cnt--) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | unsigned char val; | 
|  | 76 | val = isapnp_read_byte(pos); | 
|  | 77 | __put_user(val, buf); | 
|  | 78 | } | 
|  | 79 | isapnp_cfg_end(); | 
|  | 80 |  | 
|  | 81 | *ppos = pos; | 
|  | 82 | return nbytes; | 
|  | 83 | } | 
|  | 84 |  | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 85 | static const struct file_operations isapnp_proc_bus_file_operations = { | 
| Denis V. Lunev | c7705f3 | 2008-04-29 01:02:35 -0700 | [diff] [blame] | 86 | .owner	= THIS_MODULE, | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 87 | .llseek = isapnp_proc_bus_lseek, | 
|  | 88 | .read = isapnp_proc_bus_read, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | }; | 
|  | 90 |  | 
|  | 91 | static int isapnp_proc_attach_device(struct pnp_dev *dev) | 
|  | 92 | { | 
|  | 93 | struct pnp_card *bus = dev->card; | 
|  | 94 | struct proc_dir_entry *de, *e; | 
|  | 95 | char name[16]; | 
|  | 96 |  | 
|  | 97 | if (!(de = bus->procdir)) { | 
|  | 98 | sprintf(name, "%02x", bus->number); | 
|  | 99 | de = bus->procdir = proc_mkdir(name, isapnp_proc_bus_dir); | 
|  | 100 | if (!de) | 
|  | 101 | return -ENOMEM; | 
|  | 102 | } | 
|  | 103 | sprintf(name, "%02x", dev->number); | 
| Denis V. Lunev | c7705f3 | 2008-04-29 01:02:35 -0700 | [diff] [blame] | 104 | e = dev->procent = proc_create_data(name, S_IFREG | S_IRUGO, de, | 
|  | 105 | &isapnp_proc_bus_file_operations, dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | if (!e) | 
|  | 107 | return -ENOMEM; | 
| David Howells | 271a15e | 2013-04-12 00:38:51 +0100 | [diff] [blame] | 108 | proc_set_size(e, 256); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | return 0; | 
|  | 110 | } | 
|  | 111 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | int __init isapnp_proc_init(void) | 
|  | 113 | { | 
|  | 114 | struct pnp_dev *dev; | 
| Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 115 |  | 
| Alexey Dobriyan | 9c37066 | 2008-04-29 01:01:41 -0700 | [diff] [blame] | 116 | isapnp_proc_bus_dir = proc_mkdir("bus/isapnp", NULL); | 
| Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 117 | protocol_for_each_dev(&isapnp_protocol, dev) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | isapnp_proc_attach_device(dev); | 
|  | 119 | } | 
|  | 120 | return 0; | 
|  | 121 | } |