[PATCH] powerpc: remove iSeries_Global_Device_List
[usb.git] / drivers / parport / procfs.c
blobcbe17184b9c755d2e6f1f47241f4e3bfff57de7a
1 /* Sysctl interface for parport devices.
2 *
3 * Authors: David Campbell <campbell@torque.net>
4 * Tim Waugh <tim@cyberelk.demon.co.uk>
5 * Philip Blundell <philb@gnu.org>
6 * Andrea Arcangeli
7 * Riccardo Facchetti <fizban@tin.it>
9 * based on work by Grant Guenther <grant@torque.net>
10 * and Philip Blundell
12 * Cleaned up include files - Russell King <linux@arm.uk.linux.org>
15 #include <linux/string.h>
16 #include <linux/config.h>
17 #include <linux/init.h>
18 #include <linux/module.h>
19 #include <linux/errno.h>
20 #include <linux/kernel.h>
21 #include <linux/slab.h>
22 #include <linux/parport.h>
23 #include <linux/ctype.h>
24 #include <linux/sysctl.h>
26 #include <asm/uaccess.h>
28 #if defined(CONFIG_SYSCTL) && defined(CONFIG_PROC_FS)
30 #define PARPORT_MIN_TIMESLICE_VALUE 1ul
31 #define PARPORT_MAX_TIMESLICE_VALUE ((unsigned long) HZ)
32 #define PARPORT_MIN_SPINTIME_VALUE 1
33 #define PARPORT_MAX_SPINTIME_VALUE 1000
35 static int do_active_device(ctl_table *table, int write, struct file *filp,
36 void __user *result, size_t *lenp, loff_t *ppos)
38 struct parport *port = (struct parport *)table->extra1;
39 char buffer[256];
40 struct pardevice *dev;
41 int len = 0;
43 if (write) /* can't happen anyway */
44 return -EACCES;
46 if (*ppos) {
47 *lenp = 0;
48 return 0;
51 for (dev = port->devices; dev ; dev = dev->next) {
52 if(dev == port->cad) {
53 len += sprintf(buffer, "%s\n", dev->name);
57 if(!len) {
58 len += sprintf(buffer, "%s\n", "none");
61 if (len > *lenp)
62 len = *lenp;
63 else
64 *lenp = len;
66 *ppos += len;
68 return copy_to_user(result, buffer, len) ? -EFAULT : 0;
71 #ifdef CONFIG_PARPORT_1284
72 static int do_autoprobe(ctl_table *table, int write, struct file *filp,
73 void __user *result, size_t *lenp, loff_t *ppos)
75 struct parport_device_info *info = table->extra2;
76 const char *str;
77 char buffer[256];
78 int len = 0;
80 if (write) /* permissions stop this */
81 return -EACCES;
83 if (*ppos) {
84 *lenp = 0;
85 return 0;
88 if ((str = info->class_name) != NULL)
89 len += sprintf (buffer + len, "CLASS:%s;\n", str);
91 if ((str = info->model) != NULL)
92 len += sprintf (buffer + len, "MODEL:%s;\n", str);
94 if ((str = info->mfr) != NULL)
95 len += sprintf (buffer + len, "MANUFACTURER:%s;\n", str);
97 if ((str = info->description) != NULL)
98 len += sprintf (buffer + len, "DESCRIPTION:%s;\n", str);
100 if ((str = info->cmdset) != NULL)
101 len += sprintf (buffer + len, "COMMAND SET:%s;\n", str);
103 if (len > *lenp)
104 len = *lenp;
105 else
106 *lenp = len;
108 *ppos += len;
110 return copy_to_user (result, buffer, len) ? -EFAULT : 0;
112 #endif /* IEEE1284.3 support. */
114 static int do_hardware_base_addr (ctl_table *table, int write,
115 struct file *filp, void __user *result,
116 size_t *lenp, loff_t *ppos)
118 struct parport *port = (struct parport *)table->extra1;
119 char buffer[20];
120 int len = 0;
122 if (*ppos) {
123 *lenp = 0;
124 return 0;
127 if (write) /* permissions prevent this anyway */
128 return -EACCES;
130 len += sprintf (buffer, "%lu\t%lu\n", port->base, port->base_hi);
132 if (len > *lenp)
133 len = *lenp;
134 else
135 *lenp = len;
137 *ppos += len;
139 return copy_to_user(result, buffer, len) ? -EFAULT : 0;
142 static int do_hardware_irq (ctl_table *table, int write,
143 struct file *filp, void __user *result,
144 size_t *lenp, loff_t *ppos)
146 struct parport *port = (struct parport *)table->extra1;
147 char buffer[20];
148 int len = 0;
150 if (*ppos) {
151 *lenp = 0;
152 return 0;
155 if (write) /* permissions prevent this anyway */
156 return -EACCES;
158 len += sprintf (buffer, "%d\n", port->irq);
160 if (len > *lenp)
161 len = *lenp;
162 else
163 *lenp = len;
165 *ppos += len;
167 return copy_to_user(result, buffer, len) ? -EFAULT : 0;
170 static int do_hardware_dma (ctl_table *table, int write,
171 struct file *filp, void __user *result,
172 size_t *lenp, loff_t *ppos)
174 struct parport *port = (struct parport *)table->extra1;
175 char buffer[20];
176 int len = 0;
178 if (*ppos) {
179 *lenp = 0;
180 return 0;
183 if (write) /* permissions prevent this anyway */
184 return -EACCES;
186 len += sprintf (buffer, "%d\n", port->dma);
188 if (len > *lenp)
189 len = *lenp;
190 else
191 *lenp = len;
193 *ppos += len;
195 return copy_to_user(result, buffer, len) ? -EFAULT : 0;
198 static int do_hardware_modes (ctl_table *table, int write,
199 struct file *filp, void __user *result,
200 size_t *lenp, loff_t *ppos)
202 struct parport *port = (struct parport *)table->extra1;
203 char buffer[40];
204 int len = 0;
206 if (*ppos) {
207 *lenp = 0;
208 return 0;
211 if (write) /* permissions prevent this anyway */
212 return -EACCES;
215 #define printmode(x) {if(port->modes&PARPORT_MODE_##x){len+=sprintf(buffer+len,"%s%s",f?",":"",#x);f++;}}
216 int f = 0;
217 printmode(PCSPP);
218 printmode(TRISTATE);
219 printmode(COMPAT);
220 printmode(EPP);
221 printmode(ECP);
222 printmode(DMA);
223 #undef printmode
225 buffer[len++] = '\n';
227 if (len > *lenp)
228 len = *lenp;
229 else
230 *lenp = len;
232 *ppos += len;
234 return copy_to_user(result, buffer, len) ? -EFAULT : 0;
237 #define PARPORT_PORT_DIR(child) { 0, NULL, NULL, 0, 0555, child }
238 #define PARPORT_PARPORT_DIR(child) { DEV_PARPORT, "parport", \
239 NULL, 0, 0555, child }
240 #define PARPORT_DEV_DIR(child) { CTL_DEV, "dev", NULL, 0, 0555, child }
241 #define PARPORT_DEVICES_ROOT_DIR { DEV_PARPORT_DEVICES, "devices", \
242 NULL, 0, 0555, NULL }
244 static const unsigned long parport_min_timeslice_value =
245 PARPORT_MIN_TIMESLICE_VALUE;
247 static const unsigned long parport_max_timeslice_value =
248 PARPORT_MAX_TIMESLICE_VALUE;
250 static const int parport_min_spintime_value =
251 PARPORT_MIN_SPINTIME_VALUE;
253 static const int parport_max_spintime_value =
254 PARPORT_MAX_SPINTIME_VALUE;
257 struct parport_sysctl_table {
258 struct ctl_table_header *sysctl_header;
259 ctl_table vars[12];
260 ctl_table device_dir[2];
261 ctl_table port_dir[2];
262 ctl_table parport_dir[2];
263 ctl_table dev_dir[2];
266 static const struct parport_sysctl_table parport_sysctl_template = {
267 NULL,
269 { DEV_PARPORT_SPINTIME, "spintime",
270 NULL, sizeof(int), 0644, NULL,
271 &proc_dointvec_minmax, NULL, NULL,
272 (void*) &parport_min_spintime_value,
273 (void*) &parport_max_spintime_value },
274 { DEV_PARPORT_BASE_ADDR, "base-addr",
275 NULL, 0, 0444, NULL,
276 &do_hardware_base_addr },
277 { DEV_PARPORT_IRQ, "irq",
278 NULL, 0, 0444, NULL,
279 &do_hardware_irq },
280 { DEV_PARPORT_DMA, "dma",
281 NULL, 0, 0444, NULL,
282 &do_hardware_dma },
283 { DEV_PARPORT_MODES, "modes",
284 NULL, 0, 0444, NULL,
285 &do_hardware_modes },
286 PARPORT_DEVICES_ROOT_DIR,
287 #ifdef CONFIG_PARPORT_1284
288 { DEV_PARPORT_AUTOPROBE, "autoprobe",
289 NULL, 0, 0444, NULL,
290 &do_autoprobe },
291 { DEV_PARPORT_AUTOPROBE + 1, "autoprobe0",
292 NULL, 0, 0444, NULL,
293 &do_autoprobe },
294 { DEV_PARPORT_AUTOPROBE + 2, "autoprobe1",
295 NULL, 0, 0444, NULL,
296 &do_autoprobe },
297 { DEV_PARPORT_AUTOPROBE + 3, "autoprobe2",
298 NULL, 0, 0444, NULL,
299 &do_autoprobe },
300 { DEV_PARPORT_AUTOPROBE + 4, "autoprobe3",
301 NULL, 0, 0444, NULL,
302 &do_autoprobe },
303 #endif /* IEEE 1284 support */
306 { {DEV_PARPORT_DEVICES_ACTIVE, "active", NULL, 0, 0444, NULL,
307 &do_active_device }, {0}},
308 { PARPORT_PORT_DIR(NULL), {0}},
309 { PARPORT_PARPORT_DIR(NULL), {0}},
310 { PARPORT_DEV_DIR(NULL), {0}}
313 struct parport_device_sysctl_table
315 struct ctl_table_header *sysctl_header;
316 ctl_table vars[2];
317 ctl_table device_dir[2];
318 ctl_table devices_root_dir[2];
319 ctl_table port_dir[2];
320 ctl_table parport_dir[2];
321 ctl_table dev_dir[2];
324 static const struct parport_device_sysctl_table
325 parport_device_sysctl_template = {
326 NULL,
328 { DEV_PARPORT_DEVICE_TIMESLICE, "timeslice",
329 NULL, sizeof(int), 0644, NULL,
330 &proc_doulongvec_ms_jiffies_minmax, NULL, NULL,
331 (void*) &parport_min_timeslice_value,
332 (void*) &parport_max_timeslice_value },
334 { {0, NULL, NULL, 0, 0555, NULL}, {0}},
335 { PARPORT_DEVICES_ROOT_DIR, {0}},
336 { PARPORT_PORT_DIR(NULL), {0}},
337 { PARPORT_PARPORT_DIR(NULL), {0}},
338 { PARPORT_DEV_DIR(NULL), {0}}
341 struct parport_default_sysctl_table
343 struct ctl_table_header *sysctl_header;
344 ctl_table vars[3];
345 ctl_table default_dir[2];
346 ctl_table parport_dir[2];
347 ctl_table dev_dir[2];
350 extern unsigned long parport_default_timeslice;
351 extern int parport_default_spintime;
353 static struct parport_default_sysctl_table
354 parport_default_sysctl_table = {
355 NULL,
357 { DEV_PARPORT_DEFAULT_TIMESLICE, "timeslice",
358 &parport_default_timeslice,
359 sizeof(parport_default_timeslice), 0644, NULL,
360 &proc_doulongvec_ms_jiffies_minmax, NULL, NULL,
361 (void*) &parport_min_timeslice_value,
362 (void*) &parport_max_timeslice_value },
363 { DEV_PARPORT_DEFAULT_SPINTIME, "spintime",
364 &parport_default_spintime,
365 sizeof(parport_default_spintime), 0644, NULL,
366 &proc_dointvec_minmax, NULL, NULL,
367 (void*) &parport_min_spintime_value,
368 (void*) &parport_max_spintime_value },
371 { { DEV_PARPORT_DEFAULT, "default", NULL, 0, 0555,
372 parport_default_sysctl_table.vars },{0}},
374 PARPORT_PARPORT_DIR(parport_default_sysctl_table.default_dir),
375 {0}},
376 { PARPORT_DEV_DIR(parport_default_sysctl_table.parport_dir), {0}}
380 int parport_proc_register(struct parport *port)
382 struct parport_sysctl_table *t;
383 int i;
385 t = kmalloc(sizeof(*t), GFP_KERNEL);
386 if (t == NULL)
387 return -ENOMEM;
388 memcpy(t, &parport_sysctl_template, sizeof(*t));
390 t->device_dir[0].extra1 = port;
392 for (i = 0; i < 8; i++)
393 t->vars[i].extra1 = port;
395 t->vars[0].data = &port->spintime;
396 t->vars[5].child = t->device_dir;
398 for (i = 0; i < 5; i++)
399 t->vars[6 + i].extra2 = &port->probe_info[i];
401 t->port_dir[0].procname = port->name;
402 t->port_dir[0].ctl_name = port->number + 1; /* nb 0 isn't legal here */
404 t->port_dir[0].child = t->vars;
405 t->parport_dir[0].child = t->port_dir;
406 t->dev_dir[0].child = t->parport_dir;
408 t->sysctl_header = register_sysctl_table(t->dev_dir, 0);
409 if (t->sysctl_header == NULL) {
410 kfree(t);
411 t = NULL;
413 port->sysctl_table = t;
414 return 0;
417 int parport_proc_unregister(struct parport *port)
419 if (port->sysctl_table) {
420 struct parport_sysctl_table *t = port->sysctl_table;
421 port->sysctl_table = NULL;
422 unregister_sysctl_table(t->sysctl_header);
423 kfree(t);
425 return 0;
428 int parport_device_proc_register(struct pardevice *device)
430 struct parport_device_sysctl_table *t;
431 struct parport * port = device->port;
433 t = kmalloc(sizeof(*t), GFP_KERNEL);
434 if (t == NULL)
435 return -ENOMEM;
436 memcpy(t, &parport_device_sysctl_template, sizeof(*t));
438 t->dev_dir[0].child = t->parport_dir;
439 t->parport_dir[0].child = t->port_dir;
440 t->port_dir[0].procname = port->name;
441 t->port_dir[0].ctl_name = port->number + 1; /* nb 0 isn't legal here */
442 t->port_dir[0].child = t->devices_root_dir;
443 t->devices_root_dir[0].child = t->device_dir;
445 #ifdef CONFIG_PARPORT_1284
447 t->device_dir[0].ctl_name =
448 parport_device_num(port->number, port->muxport,
449 device->daisy)
450 + 1; /* nb 0 isn't legal here */
452 #else /* No IEEE 1284 support */
454 /* parport_device_num isn't available. */
455 t->device_dir[0].ctl_name = 1;
457 #endif /* IEEE 1284 support or not */
459 t->device_dir[0].procname = device->name;
460 t->device_dir[0].extra1 = device;
461 t->device_dir[0].child = t->vars;
462 t->vars[0].data = &device->timeslice;
464 t->sysctl_header = register_sysctl_table(t->dev_dir, 0);
465 if (t->sysctl_header == NULL) {
466 kfree(t);
467 t = NULL;
469 device->sysctl_table = t;
470 return 0;
473 int parport_device_proc_unregister(struct pardevice *device)
475 if (device->sysctl_table) {
476 struct parport_device_sysctl_table *t = device->sysctl_table;
477 device->sysctl_table = NULL;
478 unregister_sysctl_table(t->sysctl_header);
479 kfree(t);
481 return 0;
484 static int __init parport_default_proc_register(void)
486 parport_default_sysctl_table.sysctl_header =
487 register_sysctl_table(parport_default_sysctl_table.dev_dir, 0);
488 return 0;
491 static void __exit parport_default_proc_unregister(void)
493 if (parport_default_sysctl_table.sysctl_header) {
494 unregister_sysctl_table(parport_default_sysctl_table.
495 sysctl_header);
496 parport_default_sysctl_table.sysctl_header = NULL;
500 #else /* no sysctl or no procfs*/
502 int parport_proc_register(struct parport *pp)
504 return 0;
507 int parport_proc_unregister(struct parport *pp)
509 return 0;
512 int parport_device_proc_register(struct pardevice *device)
514 return 0;
517 int parport_device_proc_unregister(struct pardevice *device)
519 return 0;
522 static int __init parport_default_proc_register (void)
524 return 0;
527 static void __exit parport_default_proc_unregister (void)
530 #endif
532 module_init(parport_default_proc_register)
533 module_exit(parport_default_proc_unregister)