blob: 5edee645d890e6037578da6f26aa0be5daaf61d0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ISA Plug & Play support
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02003 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * 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 Torvalds1da177e2005-04-16 15:20:36 -070018 */
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/module.h>
21#include <linux/isapnp.h>
22#include <linux/proc_fs.h>
23#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/uaccess.h>
25
26extern struct pnp_protocol isapnp_protocol;
27
28static struct proc_dir_entry *isapnp_proc_bus_dir = NULL;
29
30static loff_t isapnp_proc_bus_lseek(struct file *file, loff_t off, int whence)
31{
Al Viroc09ed2a2013-06-23 12:09:11 +040032 return fixed_size_llseek(file, off, whence, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -070033}
34
Bjorn Helgaas9dd78462007-07-26 10:41:20 -070035static ssize_t isapnp_proc_bus_read(struct file *file, char __user * buf,
36 size_t nbytes, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037{
Al Virod9dda782013-03-31 18:16:14 -040038 struct pnp_dev *dev = PDE_DATA(file_inode(file));
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 int pos = *ppos;
40 int cnt, size = 256;
41
42 if (pos >= size)
43 return 0;
44 if (nbytes >= size)
45 nbytes = size;
46 if (pos + nbytes > size)
47 nbytes = size - pos;
48 cnt = nbytes;
49
50 if (!access_ok(VERIFY_WRITE, buf, cnt))
51 return -EINVAL;
52
53 isapnp_cfg_begin(dev->card->number, dev->number);
Bjorn Helgaas9dd78462007-07-26 10:41:20 -070054 for (; pos < 256 && cnt > 0; pos++, buf++, cnt--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 unsigned char val;
56 val = isapnp_read_byte(pos);
57 __put_user(val, buf);
58 }
59 isapnp_cfg_end();
60
61 *ppos = pos;
62 return nbytes;
63}
64
Bjorn Helgaas9dd78462007-07-26 10:41:20 -070065static const struct file_operations isapnp_proc_bus_file_operations = {
Denis V. Lunevc7705f32008-04-29 01:02:35 -070066 .owner = THIS_MODULE,
Bjorn Helgaas9dd78462007-07-26 10:41:20 -070067 .llseek = isapnp_proc_bus_lseek,
68 .read = isapnp_proc_bus_read,
Linus Torvalds1da177e2005-04-16 15:20:36 -070069};
70
71static int isapnp_proc_attach_device(struct pnp_dev *dev)
72{
73 struct pnp_card *bus = dev->card;
74 struct proc_dir_entry *de, *e;
75 char name[16];
76
77 if (!(de = bus->procdir)) {
78 sprintf(name, "%02x", bus->number);
79 de = bus->procdir = proc_mkdir(name, isapnp_proc_bus_dir);
80 if (!de)
81 return -ENOMEM;
82 }
83 sprintf(name, "%02x", dev->number);
Denis V. Lunevc7705f32008-04-29 01:02:35 -070084 e = dev->procent = proc_create_data(name, S_IFREG | S_IRUGO, de,
85 &isapnp_proc_bus_file_operations, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 if (!e)
87 return -ENOMEM;
David Howells271a15e2013-04-12 00:38:51 +010088 proc_set_size(e, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 return 0;
90}
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092int __init isapnp_proc_init(void)
93{
94 struct pnp_dev *dev;
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -070095
Alexey Dobriyan9c370662008-04-29 01:01:41 -070096 isapnp_proc_bus_dir = proc_mkdir("bus/isapnp", NULL);
Bjorn Helgaas9dd78462007-07-26 10:41:20 -070097 protocol_for_each_dev(&isapnp_protocol, dev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 isapnp_proc_attach_device(dev);
99 }
100 return 0;
101}