1 /* Sysctl interface for parport devices.
3 * Authors: David Campbell <campbell@torque.net>
4 * Tim Waugh <tim@cyberelk.demon.co.uk>
5 * Philip Blundell <philb@gnu.org>
7 * Riccardo Facchetti <fizban@tin.it>
9 * based on work by Grant Guenther <grant@torque.net>
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
;
40 struct pardevice
*dev
;
43 if (write
) /* can't happen anyway */
51 for (dev
= port
->devices
; dev
; dev
= dev
->next
) {
52 if(dev
== port
->cad
) {
53 len
+= sprintf(buffer
, "%s\n", dev
->name
);
58 len
+= sprintf(buffer
, "%s\n", "none");
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
;
80 if (write
) /* permissions stop this */
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
);
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
;
127 if (write
) /* permissions prevent this anyway */
130 len
+= sprintf (buffer
, "%lu\t%lu\n", port
->base
, port
->base_hi
);
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
;
155 if (write
) /* permissions prevent this anyway */
158 len
+= sprintf (buffer
, "%d\n", port
->irq
);
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
;
183 if (write
) /* permissions prevent this anyway */
186 len
+= sprintf (buffer
, "%d\n", port
->dma
);
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
;
211 if (write
) /* permissions prevent this anyway */
215 #define printmode(x) {if(port->modes&PARPORT_MODE_##x){len+=sprintf(buffer+len,"%s%s",f?",":"",#x);f++;}}
225 buffer
[len
++] = '\n';
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
;
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
= {
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",
276 &do_hardware_base_addr
},
277 { DEV_PARPORT_IRQ
, "irq",
280 { DEV_PARPORT_DMA
, "dma",
283 { DEV_PARPORT_MODES
, "modes",
285 &do_hardware_modes
},
286 PARPORT_DEVICES_ROOT_DIR
,
287 #ifdef CONFIG_PARPORT_1284
288 { DEV_PARPORT_AUTOPROBE
, "autoprobe",
291 { DEV_PARPORT_AUTOPROBE
+ 1, "autoprobe0",
294 { DEV_PARPORT_AUTOPROBE
+ 2, "autoprobe1",
297 { DEV_PARPORT_AUTOPROBE
+ 3, "autoprobe2",
300 { DEV_PARPORT_AUTOPROBE
+ 4, "autoprobe3",
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
;
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
= {
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
;
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
= {
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
),
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
;
385 t
= kmalloc(sizeof(*t
), GFP_KERNEL
);
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
) {
413 port
->sysctl_table
= t
;
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
);
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
);
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
,
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
) {
469 device
->sysctl_table
= t
;
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
);
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);
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
.
496 parport_default_sysctl_table
.sysctl_header
= NULL
;
500 #else /* no sysctl or no procfs*/
502 int parport_proc_register(struct parport
*pp
)
507 int parport_proc_unregister(struct parport
*pp
)
512 int parport_device_proc_register(struct pardevice
*device
)
517 int parport_device_proc_unregister(struct pardevice
*device
)
522 static int __init
parport_default_proc_register (void)
527 static void __exit
parport_default_proc_unregister (void)
532 module_init(parport_default_proc_register
)
533 module_exit(parport_default_proc_unregister
)