2 * /proc/bus/pnp interface for Plug and Play devices
4 * Written by David Hinds, dahinds@users.sourceforge.net
5 * Modified by Thomas Hood
7 * The .../devices and .../<node> and .../boot/<node> files are
8 * utilized by the lspnp and setpnp utilities, supplied with the
10 * http://pcmcia-cs.sourceforge.net
12 * The .../escd file is utilized by the lsescd utility written by
15 * The .../legacy_device_resources file is not used yet.
17 * The other files are human-readable.
20 #include <linux/module.h>
21 #include <linux/kernel.h>
22 #include <linux/slab.h>
23 #include <linux/types.h>
24 #include <linux/proc_fs.h>
25 #include <linux/pnp.h>
26 #include <linux/seq_file.h>
27 #include <linux/init.h>
29 #include <asm/uaccess.h>
33 static struct proc_dir_entry
*proc_pnp
= NULL
;
34 static struct proc_dir_entry
*proc_pnp_boot
= NULL
;
36 static int pnpconfig_proc_show(struct seq_file
*m
, void *v
)
38 struct pnp_isa_config_struc pnps
;
40 if (pnp_bios_isapnp_config(&pnps
))
42 seq_printf(m
, "structure_revision %d\n"
44 "ISA_read_data_port 0x%x\n",
45 pnps
.revision
, pnps
.no_csns
, pnps
.isa_rd_data_port
);
49 static int pnpconfig_proc_open(struct inode
*inode
, struct file
*file
)
51 return single_open(file
, pnpconfig_proc_show
, NULL
);
54 static const struct file_operations pnpconfig_proc_fops
= {
56 .open
= pnpconfig_proc_open
,
59 .release
= single_release
,
62 static int escd_info_proc_show(struct seq_file
*m
, void *v
)
64 struct escd_info_struc escd
;
66 if (pnp_bios_escd_info(&escd
))
68 seq_printf(m
, "min_ESCD_write_size %d\n"
71 escd
.min_escd_write_size
,
72 escd
.escd_size
, escd
.nv_storage_base
);
76 static int escd_info_proc_open(struct inode
*inode
, struct file
*file
)
78 return single_open(file
, escd_info_proc_show
, NULL
);
81 static const struct file_operations escd_info_proc_fops
= {
83 .open
= escd_info_proc_open
,
86 .release
= single_release
,
89 #define MAX_SANE_ESCD_SIZE (32*1024)
90 static int escd_proc_show(struct seq_file
*m
, void *v
)
92 struct escd_info_struc escd
;
96 if (pnp_bios_escd_info(&escd
))
100 if (escd
.escd_size
> MAX_SANE_ESCD_SIZE
) {
102 "PnPBIOS: %s: ESCD size reported by BIOS escd_info call is too great\n", __func__
);
106 tmpbuf
= kzalloc(escd
.escd_size
, GFP_KERNEL
);
110 if (pnp_bios_read_escd(tmpbuf
, escd
.nv_storage_base
)) {
116 (unsigned char)(tmpbuf
[0]) + (unsigned char)(tmpbuf
[1]) * 256;
119 if (escd_size
> MAX_SANE_ESCD_SIZE
) {
120 printk(KERN_ERR
"PnPBIOS: %s: ESCD size reported by"
121 " BIOS read_escd call is too great\n", __func__
);
126 seq_write(m
, tmpbuf
, escd_size
);
131 static int escd_proc_open(struct inode
*inode
, struct file
*file
)
133 return single_open(file
, escd_proc_show
, NULL
);
136 static const struct file_operations escd_proc_fops
= {
137 .owner
= THIS_MODULE
,
138 .open
= escd_proc_open
,
141 .release
= single_release
,
144 static int pnp_legacyres_proc_show(struct seq_file
*m
, void *v
)
148 buf
= kmalloc(65536, GFP_KERNEL
);
151 if (pnp_bios_get_stat_res(buf
)) {
156 seq_write(m
, buf
, 65536);
161 static int pnp_legacyres_proc_open(struct inode
*inode
, struct file
*file
)
163 return single_open(file
, pnp_legacyres_proc_show
, NULL
);
166 static const struct file_operations pnp_legacyres_proc_fops
= {
167 .owner
= THIS_MODULE
,
168 .open
= pnp_legacyres_proc_open
,
171 .release
= single_release
,
174 static int pnp_devices_proc_show(struct seq_file
*m
, void *v
)
176 struct pnp_bios_node
*node
;
179 node
= kzalloc(node_info
.max_node_size
, GFP_KERNEL
);
183 for (nodenum
= 0; nodenum
< 0xff;) {
184 u8 thisnodenum
= nodenum
;
186 if (pnp_bios_get_dev_node(&nodenum
, PNPMODE_DYNAMIC
, node
))
188 seq_printf(m
, "%02x\t%08x\t%3phC\t%04x\n",
189 node
->handle
, node
->eisa_id
,
190 node
->type_code
, node
->flags
);
191 if (nodenum
<= thisnodenum
) {
193 "%s Node number 0x%x is out of sequence following node 0x%x. Aborting.\n",
194 "PnPBIOS: proc_read_devices:",
195 (unsigned int)nodenum
,
196 (unsigned int)thisnodenum
);
204 static int pnp_devices_proc_open(struct inode
*inode
, struct file
*file
)
206 return single_open(file
, pnp_devices_proc_show
, NULL
);
209 static const struct file_operations pnp_devices_proc_fops
= {
210 .owner
= THIS_MODULE
,
211 .open
= pnp_devices_proc_open
,
214 .release
= single_release
,
217 static int pnpbios_proc_show(struct seq_file
*m
, void *v
)
219 void *data
= m
->private;
220 struct pnp_bios_node
*node
;
221 int boot
= (long)data
>> 8;
222 u8 nodenum
= (long)data
;
225 node
= kzalloc(node_info
.max_node_size
, GFP_KERNEL
);
228 if (pnp_bios_get_dev_node(&nodenum
, boot
, node
)) {
232 len
= node
->size
- sizeof(struct pnp_bios_node
);
233 seq_write(m
, node
->data
, len
);
238 static int pnpbios_proc_open(struct inode
*inode
, struct file
*file
)
240 return single_open(file
, pnpbios_proc_show
, PDE_DATA(inode
));
243 static ssize_t
pnpbios_proc_write(struct file
*file
, const char __user
*buf
,
244 size_t count
, loff_t
*pos
)
246 void *data
= PDE_DATA(file_inode(file
));
247 struct pnp_bios_node
*node
;
248 int boot
= (long)data
>> 8;
249 u8 nodenum
= (long)data
;
252 node
= kzalloc(node_info
.max_node_size
, GFP_KERNEL
);
255 if (pnp_bios_get_dev_node(&nodenum
, boot
, node
)) {
259 if (count
!= node
->size
- sizeof(struct pnp_bios_node
)) {
263 if (copy_from_user(node
->data
, buf
, count
)) {
267 if (pnp_bios_set_dev_node(node
->handle
, boot
, node
) != 0) {
277 static const struct file_operations pnpbios_proc_fops
= {
278 .owner
= THIS_MODULE
,
279 .open
= pnpbios_proc_open
,
282 .release
= single_release
,
283 .write
= pnpbios_proc_write
,
286 int pnpbios_interface_attach_device(struct pnp_bios_node
*node
)
290 sprintf(name
, "%02x", node
->handle
);
294 if (!pnpbios_dont_use_current_config
) {
295 proc_create_data(name
, 0644, proc_pnp
, &pnpbios_proc_fops
,
296 (void *)(long)(node
->handle
));
301 if (proc_create_data(name
, 0644, proc_pnp_boot
, &pnpbios_proc_fops
,
302 (void *)(long)(node
->handle
+ 0x100)))
308 * When this is called, pnpbios functions are assumed to
309 * work and the pnpbios_dont_use_current_config flag
310 * should already have been set to the appropriate value
312 int __init
pnpbios_proc_init(void)
314 proc_pnp
= proc_mkdir("bus/pnp", NULL
);
317 proc_pnp_boot
= proc_mkdir("boot", proc_pnp
);
320 proc_create("devices", 0, proc_pnp
, &pnp_devices_proc_fops
);
321 proc_create("configuration_info", 0, proc_pnp
, &pnpconfig_proc_fops
);
322 proc_create("escd_info", 0, proc_pnp
, &escd_info_proc_fops
);
323 proc_create("escd", S_IRUSR
, proc_pnp
, &escd_proc_fops
);
324 proc_create("legacy_device_resources", 0, proc_pnp
, &pnp_legacyres_proc_fops
);
329 void __exit
pnpbios_proc_exit(void)
337 for (i
= 0; i
< 0xff; i
++) {
338 sprintf(name
, "%02x", i
);
339 if (!pnpbios_dont_use_current_config
)
340 remove_proc_entry(name
, proc_pnp
);
341 remove_proc_entry(name
, proc_pnp_boot
);
343 remove_proc_entry("legacy_device_resources", proc_pnp
);
344 remove_proc_entry("escd", proc_pnp
);
345 remove_proc_entry("escd_info", proc_pnp
);
346 remove_proc_entry("configuration_info", proc_pnp
);
347 remove_proc_entry("devices", proc_pnp
);
348 remove_proc_entry("boot", proc_pnp
);
349 remove_proc_entry("bus/pnp", NULL
);