1 // SPDX-License-Identifier: GPL-2.0
3 * /proc/bus/pnp interface for Plug and Play devices
6 * Modified by Thomas Hood
8 * The .../devices and .../<node> and .../boot/<node> files are
9 * utilized by the lspnp and setpnp utilities, supplied with the
11 * http://pcmcia-cs.sourceforge.net
13 * The .../escd file is utilized by the lsescd utility written by
16 * The .../legacy_device_resources file is not used yet.
18 * The other files are human-readable.
21 #include <linux/module.h>
22 #include <linux/kernel.h>
23 #include <linux/slab.h>
24 #include <linux/types.h>
25 #include <linux/proc_fs.h>
26 #include <linux/pnp.h>
27 #include <linux/seq_file.h>
28 #include <linux/init.h>
30 #include <linux/uaccess.h>
34 static struct proc_dir_entry *proc_pnp = NULL;
35 static struct proc_dir_entry *proc_pnp_boot = NULL;
37 static int pnpconfig_proc_show(struct seq_file *m, void *v)
39 struct pnp_isa_config_struc pnps;
41 if (pnp_bios_isapnp_config(&pnps))
43 seq_printf(m, "structure_revision %d\n"
45 "ISA_read_data_port 0x%x\n",
46 pnps.revision, pnps.no_csns, pnps.isa_rd_data_port);
50 static int escd_info_proc_show(struct seq_file *m, void *v)
52 struct escd_info_struc escd;
54 if (pnp_bios_escd_info(&escd))
56 seq_printf(m, "min_ESCD_write_size %d\n"
59 escd.min_escd_write_size,
60 escd.escd_size, escd.nv_storage_base);
64 #define MAX_SANE_ESCD_SIZE (32*1024)
65 static int escd_proc_show(struct seq_file *m, void *v)
67 struct escd_info_struc escd;
71 if (pnp_bios_escd_info(&escd))
75 if (escd.escd_size > MAX_SANE_ESCD_SIZE) {
77 "PnPBIOS: %s: ESCD size reported by BIOS escd_info call is too great\n", __func__);
81 tmpbuf = kzalloc(escd.escd_size, GFP_KERNEL);
85 if (pnp_bios_read_escd(tmpbuf, escd.nv_storage_base)) {
91 (unsigned char)(tmpbuf[0]) + (unsigned char)(tmpbuf[1]) * 256;
94 if (escd_size > MAX_SANE_ESCD_SIZE) {
95 printk(KERN_ERR "PnPBIOS: %s: ESCD size reported by"
96 " BIOS read_escd call is too great\n", __func__);
101 seq_write(m, tmpbuf, escd_size);
106 static int pnp_legacyres_proc_show(struct seq_file *m, void *v)
110 buf = kmalloc(65536, GFP_KERNEL);
113 if (pnp_bios_get_stat_res(buf)) {
118 seq_write(m, buf, 65536);
123 static int pnp_devices_proc_show(struct seq_file *m, void *v)
125 struct pnp_bios_node *node;
128 node = kzalloc(node_info.max_node_size, GFP_KERNEL);
132 for (nodenum = 0; nodenum < 0xff;) {
133 u8 thisnodenum = nodenum;
135 if (pnp_bios_get_dev_node(&nodenum, PNPMODE_DYNAMIC, node))
137 seq_printf(m, "%02x\t%08x\t%3phC\t%04x\n",
138 node->handle, node->eisa_id,
139 node->type_code, node->flags);
140 if (nodenum <= thisnodenum) {
142 "%s Node number 0x%x is out of sequence following node 0x%x. Aborting.\n",
143 "PnPBIOS: proc_read_devices:",
144 (unsigned int)nodenum,
145 (unsigned int)thisnodenum);
153 static int pnpbios_proc_show(struct seq_file *m, void *v)
155 void *data = m->private;
156 struct pnp_bios_node *node;
157 int boot = (long)data >> 8;
158 u8 nodenum = (long)data;
161 node = kzalloc(node_info.max_node_size, GFP_KERNEL);
164 if (pnp_bios_get_dev_node(&nodenum, boot, node)) {
168 len = node->size - sizeof(struct pnp_bios_node);
169 seq_write(m, node->data, len);
174 static int pnpbios_proc_open(struct inode *inode, struct file *file)
176 return single_open(file, pnpbios_proc_show, PDE_DATA(inode));
179 static ssize_t pnpbios_proc_write(struct file *file, const char __user *buf,
180 size_t count, loff_t *pos)
182 void *data = PDE_DATA(file_inode(file));
183 struct pnp_bios_node *node;
184 int boot = (long)data >> 8;
185 u8 nodenum = (long)data;
188 node = kzalloc(node_info.max_node_size, GFP_KERNEL);
191 if (pnp_bios_get_dev_node(&nodenum, boot, node)) {
195 if (count != node->size - sizeof(struct pnp_bios_node)) {
199 if (copy_from_user(node->data, buf, count)) {
203 if (pnp_bios_set_dev_node(node->handle, boot, node) != 0) {
213 static const struct file_operations pnpbios_proc_fops = {
214 .owner = THIS_MODULE,
215 .open = pnpbios_proc_open,
218 .release = single_release,
219 .write = pnpbios_proc_write,
222 int pnpbios_interface_attach_device(struct pnp_bios_node *node)
226 sprintf(name, "%02x", node->handle);
230 if (!pnpbios_dont_use_current_config) {
231 proc_create_data(name, 0644, proc_pnp, &pnpbios_proc_fops,
232 (void *)(long)(node->handle));
237 if (proc_create_data(name, 0644, proc_pnp_boot, &pnpbios_proc_fops,
238 (void *)(long)(node->handle + 0x100)))
244 * When this is called, pnpbios functions are assumed to
245 * work and the pnpbios_dont_use_current_config flag
246 * should already have been set to the appropriate value
248 int __init pnpbios_proc_init(void)
250 proc_pnp = proc_mkdir("bus/pnp", NULL);
253 proc_pnp_boot = proc_mkdir("boot", proc_pnp);
256 proc_create_single("devices", 0, proc_pnp, pnp_devices_proc_show);
257 proc_create_single("configuration_info", 0, proc_pnp,
258 pnpconfig_proc_show);
259 proc_create_single("escd_info", 0, proc_pnp, escd_info_proc_show);
260 proc_create_single("escd", S_IRUSR, proc_pnp, escd_proc_show);
261 proc_create_single("legacy_device_resources", 0, proc_pnp,
262 pnp_legacyres_proc_show);
266 void __exit pnpbios_proc_exit(void)
274 for (i = 0; i < 0xff; i++) {
275 sprintf(name, "%02x", i);
276 if (!pnpbios_dont_use_current_config)
277 remove_proc_entry(name, proc_pnp);
278 remove_proc_entry(name, proc_pnp_boot);
280 remove_proc_entry("legacy_device_resources", proc_pnp);
281 remove_proc_entry("escd", proc_pnp);
282 remove_proc_entry("escd_info", proc_pnp);
283 remove_proc_entry("configuration_info", proc_pnp);
284 remove_proc_entry("devices", proc_pnp);
285 remove_proc_entry("boot", proc_pnp);
286 remove_proc_entry("bus/pnp", NULL);