Loading...
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * ISA Plug & Play support
4 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
5 */
6
7#include <linux/module.h>
8#include <linux/isapnp.h>
9#include <linux/proc_fs.h>
10#include <linux/init.h>
11#include <linux/uaccess.h>
12
13extern struct pnp_protocol isapnp_protocol;
14
15static struct proc_dir_entry *isapnp_proc_bus_dir = NULL;
16
17static loff_t isapnp_proc_bus_lseek(struct file *file, loff_t off, int whence)
18{
19 return fixed_size_llseek(file, off, whence, 256);
20}
21
22static ssize_t isapnp_proc_bus_read(struct file *file, char __user * buf,
23 size_t nbytes, loff_t * ppos)
24{
25 struct pnp_dev *dev = pde_data(file_inode(file));
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
37 if (!access_ok(buf, cnt))
38 return -EINVAL;
39
40 isapnp_cfg_begin(dev->card->number, dev->number);
41 for (; pos < 256 && cnt > 0; pos++, buf++, cnt--) {
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
52static const struct proc_ops isapnp_proc_bus_proc_ops = {
53 .proc_lseek = isapnp_proc_bus_lseek,
54 .proc_read = isapnp_proc_bus_read,
55};
56
57static int isapnp_proc_attach_device(struct pnp_dev *dev)
58{
59 struct pnp_card *bus = dev->card;
60 char name[16];
61
62 if (!bus->procdir) {
63 sprintf(name, "%02x", bus->number);
64 bus->procdir = proc_mkdir(name, isapnp_proc_bus_dir);
65 if (!bus->procdir)
66 return -ENOMEM;
67 }
68 sprintf(name, "%02x", dev->number);
69 dev->procent = proc_create_data(name, S_IFREG | S_IRUGO, bus->procdir,
70 &isapnp_proc_bus_proc_ops, dev);
71 if (!dev->procent)
72 return -ENOMEM;
73 proc_set_size(dev->procent, 256);
74 return 0;
75}
76
77int __init isapnp_proc_init(void)
78{
79 struct pnp_dev *dev;
80
81 isapnp_proc_bus_dir = proc_mkdir("bus/isapnp", NULL);
82 protocol_for_each_dev(&isapnp_protocol, dev) {
83 isapnp_proc_attach_device(dev);
84 }
85 return 0;
86}
1/*
2 * ISA Plug & Play support
3 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
4 *
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.
18 */
19
20#include <linux/module.h>
21#include <linux/isapnp.h>
22#include <linux/proc_fs.h>
23#include <linux/init.h>
24#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{
32 loff_t new = -1;
33 struct inode *inode = file->f_path.dentry->d_inode;
34
35 mutex_lock(&inode->i_mutex);
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 }
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;
53}
54
55static ssize_t isapnp_proc_bus_read(struct file *file, char __user * buf,
56 size_t nbytes, loff_t * ppos)
57{
58 struct inode *ino = file->f_path.dentry->d_inode;
59 struct proc_dir_entry *dp = PDE(ino);
60 struct pnp_dev *dev = dp->data;
61 int pos = *ppos;
62 int cnt, size = 256;
63
64 if (pos >= size)
65 return 0;
66 if (nbytes >= size)
67 nbytes = size;
68 if (pos + nbytes > size)
69 nbytes = size - pos;
70 cnt = nbytes;
71
72 if (!access_ok(VERIFY_WRITE, buf, cnt))
73 return -EINVAL;
74
75 isapnp_cfg_begin(dev->card->number, dev->number);
76 for (; pos < 256 && cnt > 0; pos++, buf++, cnt--) {
77 unsigned char val;
78 val = isapnp_read_byte(pos);
79 __put_user(val, buf);
80 }
81 isapnp_cfg_end();
82
83 *ppos = pos;
84 return nbytes;
85}
86
87static const struct file_operations isapnp_proc_bus_file_operations = {
88 .owner = THIS_MODULE,
89 .llseek = isapnp_proc_bus_lseek,
90 .read = isapnp_proc_bus_read,
91};
92
93static int isapnp_proc_attach_device(struct pnp_dev *dev)
94{
95 struct pnp_card *bus = dev->card;
96 struct proc_dir_entry *de, *e;
97 char name[16];
98
99 if (!(de = bus->procdir)) {
100 sprintf(name, "%02x", bus->number);
101 de = bus->procdir = proc_mkdir(name, isapnp_proc_bus_dir);
102 if (!de)
103 return -ENOMEM;
104 }
105 sprintf(name, "%02x", dev->number);
106 e = dev->procent = proc_create_data(name, S_IFREG | S_IRUGO, de,
107 &isapnp_proc_bus_file_operations, dev);
108 if (!e)
109 return -ENOMEM;
110 e->size = 256;
111 return 0;
112}
113
114int __init isapnp_proc_init(void)
115{
116 struct pnp_dev *dev;
117
118 isapnp_proc_bus_dir = proc_mkdir("bus/isapnp", NULL);
119 protocol_for_each_dev(&isapnp_protocol, dev) {
120 isapnp_proc_attach_device(dev);
121 }
122 return 0;
123}