]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * /proc/bus/pnp interface for Plug and Play devices | |
3 | * | |
4 | * Written by David Hinds, dahinds@users.sourceforge.net | |
5 | * Modified by Thomas Hood | |
6 | * | |
7 | * The .../devices and .../<node> and .../boot/<node> files are | |
8 | * utilized by the lspnp and setpnp utilities, supplied with the | |
9 | * pcmcia-cs package. | |
10 | * http://pcmcia-cs.sourceforge.net | |
11 | * | |
12 | * The .../escd file is utilized by the lsescd utility written by | |
13 | * Gunther Mayer. | |
1da177e4 LT |
14 | * |
15 | * The .../legacy_device_resources file is not used yet. | |
16 | * | |
17 | * The other files are human-readable. | |
18 | */ | |
19 | ||
1da177e4 LT |
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> | |
dfd2e1b4 | 25 | #include <linux/pnp.h> |
5116fa2b | 26 | #include <linux/seq_file.h> |
1da177e4 LT |
27 | #include <linux/init.h> |
28 | ||
7c0f6ba6 | 29 | #include <linux/uaccess.h> |
1da177e4 LT |
30 | |
31 | #include "pnpbios.h" | |
32 | ||
33 | static struct proc_dir_entry *proc_pnp = NULL; | |
34 | static struct proc_dir_entry *proc_pnp_boot = NULL; | |
35 | ||
5116fa2b | 36 | static int pnpconfig_proc_show(struct seq_file *m, void *v) |
1da177e4 LT |
37 | { |
38 | struct pnp_isa_config_struc pnps; | |
39 | ||
40 | if (pnp_bios_isapnp_config(&pnps)) | |
41 | return -EIO; | |
5116fa2b AD |
42 | seq_printf(m, "structure_revision %d\n" |
43 | "number_of_CSNs %d\n" | |
44 | "ISA_read_data_port 0x%x\n", | |
45 | pnps.revision, pnps.no_csns, pnps.isa_rd_data_port); | |
46 | return 0; | |
1da177e4 LT |
47 | } |
48 | ||
5116fa2b AD |
49 | static int pnpconfig_proc_open(struct inode *inode, struct file *file) |
50 | { | |
51 | return single_open(file, pnpconfig_proc_show, NULL); | |
52 | } | |
53 | ||
54 | static const struct file_operations pnpconfig_proc_fops = { | |
55 | .owner = THIS_MODULE, | |
56 | .open = pnpconfig_proc_open, | |
57 | .read = seq_read, | |
58 | .llseek = seq_lseek, | |
59 | .release = single_release, | |
60 | }; | |
61 | ||
62 | static int escd_info_proc_show(struct seq_file *m, void *v) | |
1da177e4 LT |
63 | { |
64 | struct escd_info_struc escd; | |
65 | ||
66 | if (pnp_bios_escd_info(&escd)) | |
67 | return -EIO; | |
5116fa2b | 68 | seq_printf(m, "min_ESCD_write_size %d\n" |
9dd78466 BH |
69 | "ESCD_size %d\n" |
70 | "NVRAM_base 0x%x\n", | |
71 | escd.min_escd_write_size, | |
72 | escd.escd_size, escd.nv_storage_base); | |
5116fa2b | 73 | return 0; |
1da177e4 LT |
74 | } |
75 | ||
5116fa2b AD |
76 | static int escd_info_proc_open(struct inode *inode, struct file *file) |
77 | { | |
78 | return single_open(file, escd_info_proc_show, NULL); | |
79 | } | |
80 | ||
81 | static const struct file_operations escd_info_proc_fops = { | |
82 | .owner = THIS_MODULE, | |
83 | .open = escd_info_proc_open, | |
84 | .read = seq_read, | |
85 | .llseek = seq_lseek, | |
86 | .release = single_release, | |
87 | }; | |
88 | ||
1da177e4 | 89 | #define MAX_SANE_ESCD_SIZE (32*1024) |
5116fa2b | 90 | static int escd_proc_show(struct seq_file *m, void *v) |
1da177e4 LT |
91 | { |
92 | struct escd_info_struc escd; | |
93 | char *tmpbuf; | |
5116fa2b | 94 | int escd_size; |
1da177e4 LT |
95 | |
96 | if (pnp_bios_escd_info(&escd)) | |
97 | return -EIO; | |
98 | ||
99 | /* sanity check */ | |
100 | if (escd.escd_size > MAX_SANE_ESCD_SIZE) { | |
9dd78466 | 101 | printk(KERN_ERR |
5116fa2b | 102 | "PnPBIOS: %s: ESCD size reported by BIOS escd_info call is too great\n", __func__); |
1da177e4 LT |
103 | return -EFBIG; |
104 | } | |
105 | ||
cd861280 | 106 | tmpbuf = kzalloc(escd.escd_size, GFP_KERNEL); |
9dd78466 BH |
107 | if (!tmpbuf) |
108 | return -ENOMEM; | |
1da177e4 LT |
109 | |
110 | if (pnp_bios_read_escd(tmpbuf, escd.nv_storage_base)) { | |
111 | kfree(tmpbuf); | |
112 | return -EIO; | |
113 | } | |
114 | ||
9dd78466 BH |
115 | escd_size = |
116 | (unsigned char)(tmpbuf[0]) + (unsigned char)(tmpbuf[1]) * 256; | |
1da177e4 LT |
117 | |
118 | /* sanity check */ | |
119 | if (escd_size > MAX_SANE_ESCD_SIZE) { | |
5116fa2b AD |
120 | printk(KERN_ERR "PnPBIOS: %s: ESCD size reported by" |
121 | " BIOS read_escd call is too great\n", __func__); | |
a8b0ac08 | 122 | kfree(tmpbuf); |
1da177e4 LT |
123 | return -EFBIG; |
124 | } | |
125 | ||
5116fa2b | 126 | seq_write(m, tmpbuf, escd_size); |
1da177e4 | 127 | kfree(tmpbuf); |
5116fa2b | 128 | return 0; |
1da177e4 LT |
129 | } |
130 | ||
5116fa2b AD |
131 | static int escd_proc_open(struct inode *inode, struct file *file) |
132 | { | |
133 | return single_open(file, escd_proc_show, NULL); | |
134 | } | |
135 | ||
136 | static const struct file_operations escd_proc_fops = { | |
137 | .owner = THIS_MODULE, | |
138 | .open = escd_proc_open, | |
139 | .read = seq_read, | |
140 | .llseek = seq_lseek, | |
141 | .release = single_release, | |
142 | }; | |
143 | ||
144 | static int pnp_legacyres_proc_show(struct seq_file *m, void *v) | |
1da177e4 | 145 | { |
5116fa2b AD |
146 | void *buf; |
147 | ||
148 | buf = kmalloc(65536, GFP_KERNEL); | |
149 | if (!buf) | |
150 | return -ENOMEM; | |
151 | if (pnp_bios_get_stat_res(buf)) { | |
152 | kfree(buf); | |
1da177e4 | 153 | return -EIO; |
5116fa2b AD |
154 | } |
155 | ||
156 | seq_write(m, buf, 65536); | |
157 | kfree(buf); | |
158 | return 0; | |
159 | } | |
1da177e4 | 160 | |
5116fa2b AD |
161 | static int pnp_legacyres_proc_open(struct inode *inode, struct file *file) |
162 | { | |
163 | return single_open(file, pnp_legacyres_proc_show, NULL); | |
1da177e4 LT |
164 | } |
165 | ||
5116fa2b AD |
166 | static const struct file_operations pnp_legacyres_proc_fops = { |
167 | .owner = THIS_MODULE, | |
168 | .open = pnp_legacyres_proc_open, | |
169 | .read = seq_read, | |
170 | .llseek = seq_lseek, | |
171 | .release = single_release, | |
172 | }; | |
173 | ||
174 | static int pnp_devices_proc_show(struct seq_file *m, void *v) | |
1da177e4 LT |
175 | { |
176 | struct pnp_bios_node *node; | |
177 | u8 nodenum; | |
1da177e4 | 178 | |
cd861280 | 179 | node = kzalloc(node_info.max_node_size, GFP_KERNEL); |
9dd78466 BH |
180 | if (!node) |
181 | return -ENOMEM; | |
1da177e4 | 182 | |
5116fa2b | 183 | for (nodenum = 0; nodenum < 0xff;) { |
1da177e4 | 184 | u8 thisnodenum = nodenum; |
5116fa2b | 185 | |
1da177e4 LT |
186 | if (pnp_bios_get_dev_node(&nodenum, PNPMODE_DYNAMIC, node)) |
187 | break; | |
ac2a509e | 188 | seq_printf(m, "%02x\t%08x\t%3phC\t%04x\n", |
1da177e4 | 189 | node->handle, node->eisa_id, |
ac2a509e | 190 | node->type_code, node->flags); |
1da177e4 | 191 | if (nodenum <= thisnodenum) { |
9dd78466 BH |
192 | printk(KERN_ERR |
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); | |
1da177e4 LT |
197 | break; |
198 | } | |
199 | } | |
200 | kfree(node); | |
5116fa2b AD |
201 | return 0; |
202 | } | |
203 | ||
204 | static int pnp_devices_proc_open(struct inode *inode, struct file *file) | |
205 | { | |
206 | return single_open(file, pnp_devices_proc_show, NULL); | |
1da177e4 LT |
207 | } |
208 | ||
5116fa2b AD |
209 | static const struct file_operations pnp_devices_proc_fops = { |
210 | .owner = THIS_MODULE, | |
211 | .open = pnp_devices_proc_open, | |
212 | .read = seq_read, | |
213 | .llseek = seq_lseek, | |
214 | .release = single_release, | |
215 | }; | |
216 | ||
217 | static int pnpbios_proc_show(struct seq_file *m, void *v) | |
1da177e4 | 218 | { |
5116fa2b | 219 | void *data = m->private; |
1da177e4 LT |
220 | struct pnp_bios_node *node; |
221 | int boot = (long)data >> 8; | |
222 | u8 nodenum = (long)data; | |
223 | int len; | |
224 | ||
cd861280 | 225 | node = kzalloc(node_info.max_node_size, GFP_KERNEL); |
9dd78466 BH |
226 | if (!node) |
227 | return -ENOMEM; | |
1da177e4 LT |
228 | if (pnp_bios_get_dev_node(&nodenum, boot, node)) { |
229 | kfree(node); | |
230 | return -EIO; | |
231 | } | |
232 | len = node->size - sizeof(struct pnp_bios_node); | |
5116fa2b | 233 | seq_write(m, node->data, len); |
1da177e4 | 234 | kfree(node); |
5116fa2b AD |
235 | return 0; |
236 | } | |
237 | ||
238 | static int pnpbios_proc_open(struct inode *inode, struct file *file) | |
239 | { | |
d9dda78b | 240 | return single_open(file, pnpbios_proc_show, PDE_DATA(inode)); |
1da177e4 LT |
241 | } |
242 | ||
5116fa2b AD |
243 | static ssize_t pnpbios_proc_write(struct file *file, const char __user *buf, |
244 | size_t count, loff_t *pos) | |
1da177e4 | 245 | { |
d9dda78b | 246 | void *data = PDE_DATA(file_inode(file)); |
1da177e4 LT |
247 | struct pnp_bios_node *node; |
248 | int boot = (long)data >> 8; | |
249 | u8 nodenum = (long)data; | |
250 | int ret = count; | |
251 | ||
cd861280 | 252 | node = kzalloc(node_info.max_node_size, GFP_KERNEL); |
1da177e4 LT |
253 | if (!node) |
254 | return -ENOMEM; | |
255 | if (pnp_bios_get_dev_node(&nodenum, boot, node)) { | |
256 | ret = -EIO; | |
257 | goto out; | |
258 | } | |
259 | if (count != node->size - sizeof(struct pnp_bios_node)) { | |
260 | ret = -EINVAL; | |
261 | goto out; | |
262 | } | |
263 | if (copy_from_user(node->data, buf, count)) { | |
264 | ret = -EFAULT; | |
265 | goto out; | |
266 | } | |
267 | if (pnp_bios_set_dev_node(node->handle, boot, node) != 0) { | |
268 | ret = -EINVAL; | |
269 | goto out; | |
270 | } | |
271 | ret = count; | |
1e0aa9ad | 272 | out: |
1da177e4 LT |
273 | kfree(node); |
274 | return ret; | |
275 | } | |
276 | ||
5116fa2b AD |
277 | static const struct file_operations pnpbios_proc_fops = { |
278 | .owner = THIS_MODULE, | |
279 | .open = pnpbios_proc_open, | |
280 | .read = seq_read, | |
281 | .llseek = seq_lseek, | |
282 | .release = single_release, | |
283 | .write = pnpbios_proc_write, | |
284 | }; | |
285 | ||
9dd78466 | 286 | int pnpbios_interface_attach_device(struct pnp_bios_node *node) |
1da177e4 LT |
287 | { |
288 | char name[3]; | |
1da177e4 LT |
289 | |
290 | sprintf(name, "%02x", node->handle); | |
291 | ||
292 | if (!proc_pnp) | |
293 | return -EIO; | |
9dd78466 | 294 | if (!pnpbios_dont_use_current_config) { |
5116fa2b AD |
295 | proc_create_data(name, 0644, proc_pnp, &pnpbios_proc_fops, |
296 | (void *)(long)(node->handle)); | |
1da177e4 LT |
297 | } |
298 | ||
299 | if (!proc_pnp_boot) | |
300 | return -EIO; | |
5116fa2b AD |
301 | if (proc_create_data(name, 0644, proc_pnp_boot, &pnpbios_proc_fops, |
302 | (void *)(long)(node->handle + 0x100))) | |
1da177e4 | 303 | return 0; |
1da177e4 LT |
304 | return -EIO; |
305 | } | |
306 | ||
307 | /* | |
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 | |
311 | */ | |
9dd78466 | 312 | int __init pnpbios_proc_init(void) |
1da177e4 | 313 | { |
9c37066d | 314 | proc_pnp = proc_mkdir("bus/pnp", NULL); |
1da177e4 LT |
315 | if (!proc_pnp) |
316 | return -EIO; | |
317 | proc_pnp_boot = proc_mkdir("boot", proc_pnp); | |
318 | if (!proc_pnp_boot) | |
319 | return -EIO; | |
5116fa2b AD |
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); | |
1da177e4 LT |
325 | |
326 | return 0; | |
327 | } | |
328 | ||
329 | void __exit pnpbios_proc_exit(void) | |
330 | { | |
331 | int i; | |
332 | char name[3]; | |
333 | ||
334 | if (!proc_pnp) | |
335 | return; | |
336 | ||
9dd78466 | 337 | for (i = 0; i < 0xff; i++) { |
1da177e4 | 338 | sprintf(name, "%02x", i); |
9dd78466 | 339 | if (!pnpbios_dont_use_current_config) |
1da177e4 LT |
340 | remove_proc_entry(name, proc_pnp); |
341 | remove_proc_entry(name, proc_pnp_boot); | |
342 | } | |
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); | |
9c37066d | 349 | remove_proc_entry("bus/pnp", NULL); |
1da177e4 | 350 | } |