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/errno.h>
18 #include <linux/kernel.h>
19 #include <linux/malloc.h>
20 #include <linux/parport.h>
21 #include <linux/ctype.h>
22 #include <linux/sysctl.h>
24 #include <asm/uaccess.h>
26 #if defined(CONFIG_SYSCTL) && defined(CONFIG_PROC_FS)
28 #define PARPORT_MIN_TIMESLICE_VALUE 1ul
29 #define PARPORT_MAX_TIMESLICE_VALUE ((unsigned long) HZ)
30 #define PARPORT_MIN_SPINTIME_VALUE 1
31 #define PARPORT_MAX_SPINTIME_VALUE 1000
33 static int do_active_device(ctl_table
*table
, int write
, struct file
*filp
,
34 void *result
, size_t *lenp
)
36 struct parport
*port
= (struct parport
*)table
->extra1
;
38 struct pardevice
*dev
;
41 if (write
) /* can't happen anyway */
49 for (dev
= port
->devices
; dev
; dev
= dev
->next
) {
50 if(dev
== port
->cad
) {
51 len
+= sprintf(buffer
, "%s\n", dev
->name
);
56 len
+= sprintf(buffer
, "%s\n", "none");
66 return copy_to_user(result
, buffer
, len
) ? -EFAULT
: 0;
69 #ifdef CONFIG_PARPORT_1284
70 static int do_autoprobe(ctl_table
*table
, int write
, struct file
*filp
,
71 void *result
, size_t *lenp
)
73 struct parport_device_info
*info
= table
->extra2
;
78 if (write
) /* permissions stop this */
86 if ((str
= info
->class_name
) != NULL
)
87 len
+= sprintf (buffer
+ len
, "CLASS:%s;\n", str
);
89 if ((str
= info
->model
) != NULL
)
90 len
+= sprintf (buffer
+ len
, "MODEL:%s;\n", str
);
92 if ((str
= info
->mfr
) != NULL
)
93 len
+= sprintf (buffer
+ len
, "MANUFACTURER:%s;\n", str
);
95 if ((str
= info
->description
) != NULL
)
96 len
+= sprintf (buffer
+ len
, "DESCRIPTION:%s;\n", str
);
98 if ((str
= info
->cmdset
) != NULL
)
99 len
+= sprintf (buffer
+ len
, "COMMAND SET:%s;\n", str
);
108 return copy_to_user (result
, buffer
, len
) ? -EFAULT
: 0;
110 #endif /* IEEE1284.3 support. */
112 static int do_hardware(ctl_table
*table
, int write
, struct file
*filp
,
113 void *result
, size_t *lenp
)
115 struct parport
*port
= (struct parport
*)table
->extra1
;
124 if (write
) /* can't happen anyway */
127 len
+= sprintf(buffer
+len
, "base:\t0x%lx", port
->base
);
129 len
+= sprintf(buffer
+len
, " (0x%lx)", port
->base_hi
);
130 buffer
[len
++] = '\n';
132 if (port
->irq
== PARPORT_IRQ_NONE
) {
133 len
+= sprintf(buffer
+len
, "irq:\tnone\n");
135 len
+= sprintf(buffer
+len
, "irq:\t%d\n", port
->irq
);
138 if (port
->dma
== PARPORT_DMA_NONE
)
139 len
+= sprintf(buffer
+len
, "dma:\tnone\n");
141 len
+= sprintf(buffer
+len
, "dma:\t%d\n", port
->dma
);
143 len
+= sprintf(buffer
+len
, "modes:\t");
145 #define printmode(x) {if(port->modes&PARPORT_MODE_##x){len+=sprintf(buffer+len,"%s%s",f?",":"",#x);f++;}}
155 buffer
[len
++] = '\n';
164 return copy_to_user(result
, buffer
, len
) ? -EFAULT
: 0;
167 #define PARPORT_PORT_DIR(child) { 0, NULL, NULL, 0, 0555, child }
168 #define PARPORT_PARPORT_DIR(child) { DEV_PARPORT, "parport", \
169 NULL, 0, 0555, child }
170 #define PARPORT_DEV_DIR(child) { CTL_DEV, "dev", NULL, 0, 0555, child }
171 #define PARPORT_DEVICES_ROOT_DIR { DEV_PARPORT_DEVICES, "devices", \
172 NULL, 0, 0555, NULL }
174 static const unsigned long parport_min_timeslice_value
=
175 PARPORT_MIN_TIMESLICE_VALUE
;
177 static const unsigned long parport_max_timeslice_value
=
178 PARPORT_MAX_TIMESLICE_VALUE
;
180 static const int parport_min_spintime_value
=
181 PARPORT_MIN_SPINTIME_VALUE
;
183 static const int parport_max_spintime_value
=
184 PARPORT_MAX_SPINTIME_VALUE
;
187 struct parport_sysctl_table
{
188 struct ctl_table_header
*sysctl_header
;
190 ctl_table device_dir
[2];
191 ctl_table port_dir
[2];
192 ctl_table parport_dir
[2];
193 ctl_table dev_dir
[2];
196 static const struct parport_sysctl_table parport_sysctl_template
= {
199 { DEV_PARPORT_SPINTIME
, "spintime",
200 NULL
, sizeof(int), 0644, NULL
,
201 &proc_dointvec_minmax
, NULL
, NULL
,
202 (void*) &parport_min_spintime_value
,
203 (void*) &parport_max_spintime_value
},
204 { DEV_PARPORT_HARDWARE
, "hardware",
207 PARPORT_DEVICES_ROOT_DIR
,
208 #ifdef CONFIG_PARPORT_1284
209 { DEV_PARPORT_AUTOPROBE
, "autoprobe",
212 { DEV_PARPORT_AUTOPROBE
+ 1, "autoprobe0",
215 { DEV_PARPORT_AUTOPROBE
+ 2, "autoprobe1",
218 { DEV_PARPORT_AUTOPROBE
+ 3, "autoprobe2",
221 { DEV_PARPORT_AUTOPROBE
+ 4, "autoprobe3",
224 #endif /* IEEE 1284 support */
227 { {DEV_PARPORT_DEVICES_ACTIVE
, "active", NULL
, 0, 444, NULL
,
228 &do_active_device
}, {0}},
229 { PARPORT_PORT_DIR(NULL
), {0}},
230 { PARPORT_PARPORT_DIR(NULL
), {0}},
231 { PARPORT_DEV_DIR(NULL
), {0}}
234 struct parport_device_sysctl_table
236 struct ctl_table_header
*sysctl_header
;
238 ctl_table device_dir
[2];
239 ctl_table devices_root_dir
[2];
240 ctl_table port_dir
[2];
241 ctl_table parport_dir
[2];
242 ctl_table dev_dir
[2];
245 static const struct parport_device_sysctl_table
246 parport_device_sysctl_template
= {
249 { DEV_PARPORT_DEVICE_TIMESLICE
, "timeslice",
250 NULL
, sizeof(int), 0644, NULL
,
251 &proc_doulongvec_ms_jiffies_minmax
, NULL
, NULL
,
252 (void*) &parport_min_timeslice_value
,
253 (void*) &parport_max_timeslice_value
},
255 { {0, NULL
, NULL
, 0, 0555, NULL
}, {0}},
256 { PARPORT_DEVICES_ROOT_DIR
, {0}},
257 { PARPORT_PORT_DIR(NULL
), {0}},
258 { PARPORT_PARPORT_DIR(NULL
), {0}},
259 { PARPORT_DEV_DIR(NULL
), {0}}
262 struct parport_default_sysctl_table
264 struct ctl_table_header
*sysctl_header
;
266 ctl_table default_dir
[2];
267 ctl_table parport_dir
[2];
268 ctl_table dev_dir
[2];
271 extern unsigned long parport_default_timeslice
;
272 extern int parport_default_spintime
;
274 static struct parport_default_sysctl_table
275 parport_default_sysctl_table
= {
278 { DEV_PARPORT_DEFAULT_TIMESLICE
, "timeslice",
279 &parport_default_timeslice
,
280 sizeof(parport_default_timeslice
), 0644, NULL
,
281 &proc_doulongvec_ms_jiffies_minmax
, NULL
, NULL
,
282 (void*) &parport_min_timeslice_value
,
283 (void*) &parport_max_timeslice_value
},
284 { DEV_PARPORT_DEFAULT_SPINTIME
, "spintime",
285 &parport_default_spintime
,
286 sizeof(parport_default_spintime
), 0644, NULL
,
287 &proc_dointvec_minmax
, NULL
, NULL
,
288 (void*) &parport_min_spintime_value
,
289 (void*) &parport_max_spintime_value
},
292 { { DEV_PARPORT_DEFAULT
, "default", NULL
, 0, 0555,
293 parport_default_sysctl_table
.vars
},{0}},
295 PARPORT_PARPORT_DIR(parport_default_sysctl_table
.default_dir
),
297 { PARPORT_DEV_DIR(parport_default_sysctl_table
.parport_dir
), {0}}
301 int parport_proc_register(struct parport
*port
)
303 struct parport_sysctl_table
*t
;
306 t
= kmalloc(sizeof(*t
), GFP_KERNEL
);
309 memcpy(t
, &parport_sysctl_template
, sizeof(*t
));
311 t
->device_dir
[0].extra1
= port
;
313 for (i
= 0; i
< 8; i
++)
314 t
->vars
[i
].extra1
= port
;
316 t
->vars
[0].data
= &port
->spintime
;
317 t
->vars
[2].child
= t
->device_dir
;
319 for (i
= 0; i
< 5; i
++)
320 t
->vars
[3 + i
].extra2
= &port
->probe_info
[i
];
322 t
->port_dir
[0].procname
= port
->name
;
323 t
->port_dir
[0].ctl_name
= port
->number
+ 1; /* nb 0 isn't legal here */
325 t
->port_dir
[0].child
= t
->vars
;
326 t
->parport_dir
[0].child
= t
->port_dir
;
327 t
->dev_dir
[0].child
= t
->parport_dir
;
329 t
->sysctl_header
= register_sysctl_table(t
->dev_dir
, 0);
330 if (t
->sysctl_header
== NULL
) {
334 port
->sysctl_table
= t
;
338 int parport_proc_unregister(struct parport
*port
)
340 if (port
->sysctl_table
) {
341 struct parport_sysctl_table
*t
= port
->sysctl_table
;
342 port
->sysctl_table
= NULL
;
343 unregister_sysctl_table(t
->sysctl_header
);
349 int parport_device_proc_register(struct pardevice
*device
)
351 struct parport_device_sysctl_table
*t
;
352 struct parport
* port
= device
->port
;
354 t
= kmalloc(sizeof(*t
), GFP_KERNEL
);
357 memcpy(t
, &parport_device_sysctl_template
, sizeof(*t
));
359 t
->dev_dir
[0].child
= t
->parport_dir
;
360 t
->parport_dir
[0].child
= t
->port_dir
;
361 t
->port_dir
[0].procname
= port
->name
;
362 t
->port_dir
[0].ctl_name
= port
->number
+ 1; /* nb 0 isn't legal here */
363 t
->port_dir
[0].child
= t
->devices_root_dir
;
364 t
->devices_root_dir
[0].child
= t
->device_dir
;
366 #ifdef CONFIG_PARPORT_1284
368 t
->device_dir
[0].ctl_name
=
369 parport_device_num(port
->number
, port
->muxport
,
371 + 1; /* nb 0 isn't legal here */
373 #else /* No IEEE 1284 support */
375 /* parport_device_num isn't available. */
376 t
->device_dir
[0].ctl_name
= 1;
378 #endif /* IEEE 1284 support or not */
380 t
->device_dir
[0].procname
= device
->name
;
381 t
->device_dir
[0].extra1
= device
;
382 t
->device_dir
[0].child
= t
->vars
;
383 t
->vars
[0].data
= &device
->timeslice
;
385 t
->sysctl_header
= register_sysctl_table(t
->dev_dir
, 0);
386 if (t
->sysctl_header
== NULL
) {
390 device
->sysctl_table
= t
;
394 int parport_device_proc_unregister(struct pardevice
*device
)
396 if (device
->sysctl_table
) {
397 struct parport_device_sysctl_table
*t
= device
->sysctl_table
;
398 device
->sysctl_table
= NULL
;
399 unregister_sysctl_table(t
->sysctl_header
);
405 int parport_default_proc_register(void)
407 parport_default_sysctl_table
.sysctl_header
=
408 register_sysctl_table(parport_default_sysctl_table
.dev_dir
, 0);
412 int parport_default_proc_unregister(void)
414 if (parport_default_sysctl_table
.sysctl_header
) {
415 unregister_sysctl_table(parport_default_sysctl_table
.
417 parport_default_sysctl_table
.sysctl_header
= NULL
;
422 #else /* no sysctl or no procfs*/
424 int parport_proc_register(struct parport
*pp
)
429 int parport_proc_unregister(struct parport
*pp
)
434 int parport_device_proc_register(struct pardevice
*device
)
439 int parport_device_proc_unregister(struct pardevice
*device
)
444 int parport_default_proc_register (void)
449 int parport_default_proc_unregister (void)