11da177e4SLinus Torvalds /* Sysctl interface for parport devices. 21da177e4SLinus Torvalds * 3bdca3f20SAdrian Bunk * Authors: David Campbell 41da177e4SLinus Torvalds * Tim Waugh <tim@cyberelk.demon.co.uk> 51da177e4SLinus Torvalds * Philip Blundell <philb@gnu.org> 61da177e4SLinus Torvalds * Andrea Arcangeli 71da177e4SLinus Torvalds * Riccardo Facchetti <fizban@tin.it> 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * based on work by Grant Guenther <grant@torque.net> 101da177e4SLinus Torvalds * and Philip Blundell 111da177e4SLinus Torvalds * 121da177e4SLinus Torvalds * Cleaned up include files - Russell King <linux@arm.uk.linux.org> 131da177e4SLinus Torvalds */ 141da177e4SLinus Torvalds 151da177e4SLinus Torvalds #include <linux/string.h> 161da177e4SLinus Torvalds #include <linux/init.h> 171da177e4SLinus Torvalds #include <linux/module.h> 181da177e4SLinus Torvalds #include <linux/errno.h> 191da177e4SLinus Torvalds #include <linux/kernel.h> 201da177e4SLinus Torvalds #include <linux/slab.h> 211da177e4SLinus Torvalds #include <linux/parport.h> 221da177e4SLinus Torvalds #include <linux/ctype.h> 231da177e4SLinus Torvalds #include <linux/sysctl.h> 241da177e4SLinus Torvalds 251da177e4SLinus Torvalds #include <asm/uaccess.h> 261da177e4SLinus Torvalds 271da177e4SLinus Torvalds #if defined(CONFIG_SYSCTL) && defined(CONFIG_PROC_FS) 281da177e4SLinus Torvalds 291da177e4SLinus Torvalds #define PARPORT_MIN_TIMESLICE_VALUE 1ul 301da177e4SLinus Torvalds #define PARPORT_MAX_TIMESLICE_VALUE ((unsigned long) HZ) 311da177e4SLinus Torvalds #define PARPORT_MIN_SPINTIME_VALUE 1 321da177e4SLinus Torvalds #define PARPORT_MAX_SPINTIME_VALUE 1000 331da177e4SLinus Torvalds 341da177e4SLinus Torvalds static int do_active_device(ctl_table *table, int write, struct file *filp, 351da177e4SLinus Torvalds void __user *result, size_t *lenp, loff_t *ppos) 361da177e4SLinus Torvalds { 371da177e4SLinus Torvalds struct parport *port = (struct parport *)table->extra1; 381da177e4SLinus Torvalds char buffer[256]; 391da177e4SLinus Torvalds struct pardevice *dev; 401da177e4SLinus Torvalds int len = 0; 411da177e4SLinus Torvalds 421da177e4SLinus Torvalds if (write) /* can't happen anyway */ 431da177e4SLinus Torvalds return -EACCES; 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds if (*ppos) { 461da177e4SLinus Torvalds *lenp = 0; 471da177e4SLinus Torvalds return 0; 481da177e4SLinus Torvalds } 491da177e4SLinus Torvalds 501da177e4SLinus Torvalds for (dev = port->devices; dev ; dev = dev->next) { 511da177e4SLinus Torvalds if(dev == port->cad) { 521da177e4SLinus Torvalds len += sprintf(buffer, "%s\n", dev->name); 531da177e4SLinus Torvalds } 541da177e4SLinus Torvalds } 551da177e4SLinus Torvalds 561da177e4SLinus Torvalds if(!len) { 571da177e4SLinus Torvalds len += sprintf(buffer, "%s\n", "none"); 581da177e4SLinus Torvalds } 591da177e4SLinus Torvalds 601da177e4SLinus Torvalds if (len > *lenp) 611da177e4SLinus Torvalds len = *lenp; 621da177e4SLinus Torvalds else 631da177e4SLinus Torvalds *lenp = len; 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds *ppos += len; 661da177e4SLinus Torvalds 671da177e4SLinus Torvalds return copy_to_user(result, buffer, len) ? -EFAULT : 0; 681da177e4SLinus Torvalds } 691da177e4SLinus Torvalds 701da177e4SLinus Torvalds #ifdef CONFIG_PARPORT_1284 711da177e4SLinus Torvalds static int do_autoprobe(ctl_table *table, int write, struct file *filp, 721da177e4SLinus Torvalds void __user *result, size_t *lenp, loff_t *ppos) 731da177e4SLinus Torvalds { 741da177e4SLinus Torvalds struct parport_device_info *info = table->extra2; 751da177e4SLinus Torvalds const char *str; 761da177e4SLinus Torvalds char buffer[256]; 771da177e4SLinus Torvalds int len = 0; 781da177e4SLinus Torvalds 791da177e4SLinus Torvalds if (write) /* permissions stop this */ 801da177e4SLinus Torvalds return -EACCES; 811da177e4SLinus Torvalds 821da177e4SLinus Torvalds if (*ppos) { 831da177e4SLinus Torvalds *lenp = 0; 841da177e4SLinus Torvalds return 0; 851da177e4SLinus Torvalds } 861da177e4SLinus Torvalds 871da177e4SLinus Torvalds if ((str = info->class_name) != NULL) 881da177e4SLinus Torvalds len += sprintf (buffer + len, "CLASS:%s;\n", str); 891da177e4SLinus Torvalds 901da177e4SLinus Torvalds if ((str = info->model) != NULL) 911da177e4SLinus Torvalds len += sprintf (buffer + len, "MODEL:%s;\n", str); 921da177e4SLinus Torvalds 931da177e4SLinus Torvalds if ((str = info->mfr) != NULL) 941da177e4SLinus Torvalds len += sprintf (buffer + len, "MANUFACTURER:%s;\n", str); 951da177e4SLinus Torvalds 961da177e4SLinus Torvalds if ((str = info->description) != NULL) 971da177e4SLinus Torvalds len += sprintf (buffer + len, "DESCRIPTION:%s;\n", str); 981da177e4SLinus Torvalds 991da177e4SLinus Torvalds if ((str = info->cmdset) != NULL) 1001da177e4SLinus Torvalds len += sprintf (buffer + len, "COMMAND SET:%s;\n", str); 1011da177e4SLinus Torvalds 1021da177e4SLinus Torvalds if (len > *lenp) 1031da177e4SLinus Torvalds len = *lenp; 1041da177e4SLinus Torvalds else 1051da177e4SLinus Torvalds *lenp = len; 1061da177e4SLinus Torvalds 1071da177e4SLinus Torvalds *ppos += len; 1081da177e4SLinus Torvalds 1091da177e4SLinus Torvalds return copy_to_user (result, buffer, len) ? -EFAULT : 0; 1101da177e4SLinus Torvalds } 1111da177e4SLinus Torvalds #endif /* IEEE1284.3 support. */ 1121da177e4SLinus Torvalds 1131da177e4SLinus Torvalds static int do_hardware_base_addr (ctl_table *table, int write, 1141da177e4SLinus Torvalds struct file *filp, void __user *result, 1151da177e4SLinus Torvalds size_t *lenp, loff_t *ppos) 1161da177e4SLinus Torvalds { 1171da177e4SLinus Torvalds struct parport *port = (struct parport *)table->extra1; 1181da177e4SLinus Torvalds char buffer[20]; 1191da177e4SLinus Torvalds int len = 0; 1201da177e4SLinus Torvalds 1211da177e4SLinus Torvalds if (*ppos) { 1221da177e4SLinus Torvalds *lenp = 0; 1231da177e4SLinus Torvalds return 0; 1241da177e4SLinus Torvalds } 1251da177e4SLinus Torvalds 1261da177e4SLinus Torvalds if (write) /* permissions prevent this anyway */ 1271da177e4SLinus Torvalds return -EACCES; 1281da177e4SLinus Torvalds 1291da177e4SLinus Torvalds len += sprintf (buffer, "%lu\t%lu\n", port->base, port->base_hi); 1301da177e4SLinus Torvalds 1311da177e4SLinus Torvalds if (len > *lenp) 1321da177e4SLinus Torvalds len = *lenp; 1331da177e4SLinus Torvalds else 1341da177e4SLinus Torvalds *lenp = len; 1351da177e4SLinus Torvalds 1361da177e4SLinus Torvalds *ppos += len; 1371da177e4SLinus Torvalds 1381da177e4SLinus Torvalds return copy_to_user(result, buffer, len) ? -EFAULT : 0; 1391da177e4SLinus Torvalds } 1401da177e4SLinus Torvalds 1411da177e4SLinus Torvalds static int do_hardware_irq (ctl_table *table, int write, 1421da177e4SLinus Torvalds struct file *filp, void __user *result, 1431da177e4SLinus Torvalds size_t *lenp, loff_t *ppos) 1441da177e4SLinus Torvalds { 1451da177e4SLinus Torvalds struct parport *port = (struct parport *)table->extra1; 1461da177e4SLinus Torvalds char buffer[20]; 1471da177e4SLinus Torvalds int len = 0; 1481da177e4SLinus Torvalds 1491da177e4SLinus Torvalds if (*ppos) { 1501da177e4SLinus Torvalds *lenp = 0; 1511da177e4SLinus Torvalds return 0; 1521da177e4SLinus Torvalds } 1531da177e4SLinus Torvalds 1541da177e4SLinus Torvalds if (write) /* permissions prevent this anyway */ 1551da177e4SLinus Torvalds return -EACCES; 1561da177e4SLinus Torvalds 1571da177e4SLinus Torvalds len += sprintf (buffer, "%d\n", port->irq); 1581da177e4SLinus Torvalds 1591da177e4SLinus Torvalds if (len > *lenp) 1601da177e4SLinus Torvalds len = *lenp; 1611da177e4SLinus Torvalds else 1621da177e4SLinus Torvalds *lenp = len; 1631da177e4SLinus Torvalds 1641da177e4SLinus Torvalds *ppos += len; 1651da177e4SLinus Torvalds 1661da177e4SLinus Torvalds return copy_to_user(result, buffer, len) ? -EFAULT : 0; 1671da177e4SLinus Torvalds } 1681da177e4SLinus Torvalds 1691da177e4SLinus Torvalds static int do_hardware_dma (ctl_table *table, int write, 1701da177e4SLinus Torvalds struct file *filp, void __user *result, 1711da177e4SLinus Torvalds size_t *lenp, loff_t *ppos) 1721da177e4SLinus Torvalds { 1731da177e4SLinus Torvalds struct parport *port = (struct parport *)table->extra1; 1741da177e4SLinus Torvalds char buffer[20]; 1751da177e4SLinus Torvalds int len = 0; 1761da177e4SLinus Torvalds 1771da177e4SLinus Torvalds if (*ppos) { 1781da177e4SLinus Torvalds *lenp = 0; 1791da177e4SLinus Torvalds return 0; 1801da177e4SLinus Torvalds } 1811da177e4SLinus Torvalds 1821da177e4SLinus Torvalds if (write) /* permissions prevent this anyway */ 1831da177e4SLinus Torvalds return -EACCES; 1841da177e4SLinus Torvalds 1851da177e4SLinus Torvalds len += sprintf (buffer, "%d\n", port->dma); 1861da177e4SLinus Torvalds 1871da177e4SLinus Torvalds if (len > *lenp) 1881da177e4SLinus Torvalds len = *lenp; 1891da177e4SLinus Torvalds else 1901da177e4SLinus Torvalds *lenp = len; 1911da177e4SLinus Torvalds 1921da177e4SLinus Torvalds *ppos += len; 1931da177e4SLinus Torvalds 1941da177e4SLinus Torvalds return copy_to_user(result, buffer, len) ? -EFAULT : 0; 1951da177e4SLinus Torvalds } 1961da177e4SLinus Torvalds 1971da177e4SLinus Torvalds static int do_hardware_modes (ctl_table *table, int write, 1981da177e4SLinus Torvalds struct file *filp, void __user *result, 1991da177e4SLinus Torvalds size_t *lenp, loff_t *ppos) 2001da177e4SLinus Torvalds { 2011da177e4SLinus Torvalds struct parport *port = (struct parport *)table->extra1; 2021da177e4SLinus Torvalds char buffer[40]; 2031da177e4SLinus Torvalds int len = 0; 2041da177e4SLinus Torvalds 2051da177e4SLinus Torvalds if (*ppos) { 2061da177e4SLinus Torvalds *lenp = 0; 2071da177e4SLinus Torvalds return 0; 2081da177e4SLinus Torvalds } 2091da177e4SLinus Torvalds 2101da177e4SLinus Torvalds if (write) /* permissions prevent this anyway */ 2111da177e4SLinus Torvalds return -EACCES; 2121da177e4SLinus Torvalds 2131da177e4SLinus Torvalds { 2141da177e4SLinus Torvalds #define printmode(x) {if(port->modes&PARPORT_MODE_##x){len+=sprintf(buffer+len,"%s%s",f?",":"",#x);f++;}} 2151da177e4SLinus Torvalds int f = 0; 2161da177e4SLinus Torvalds printmode(PCSPP); 2171da177e4SLinus Torvalds printmode(TRISTATE); 2181da177e4SLinus Torvalds printmode(COMPAT); 2191da177e4SLinus Torvalds printmode(EPP); 2201da177e4SLinus Torvalds printmode(ECP); 2211da177e4SLinus Torvalds printmode(DMA); 2221da177e4SLinus Torvalds #undef printmode 2231da177e4SLinus Torvalds } 2241da177e4SLinus Torvalds buffer[len++] = '\n'; 2251da177e4SLinus Torvalds 2261da177e4SLinus Torvalds if (len > *lenp) 2271da177e4SLinus Torvalds len = *lenp; 2281da177e4SLinus Torvalds else 2291da177e4SLinus Torvalds *lenp = len; 2301da177e4SLinus Torvalds 2311da177e4SLinus Torvalds *ppos += len; 2321da177e4SLinus Torvalds 2331da177e4SLinus Torvalds return copy_to_user(result, buffer, len) ? -EFAULT : 0; 2341da177e4SLinus Torvalds } 2351da177e4SLinus Torvalds 2362564b7bdSEric W. Biederman #define PARPORT_PORT_DIR(CHILD) { .ctl_name = 0, .procname = NULL, .mode = 0555, .child = CHILD } 2372564b7bdSEric W. Biederman #define PARPORT_PARPORT_DIR(CHILD) { .ctl_name = DEV_PARPORT, .procname = "parport", \ 2382564b7bdSEric W. Biederman .mode = 0555, .child = CHILD } 2392564b7bdSEric W. Biederman #define PARPORT_DEV_DIR(CHILD) { .ctl_name = CTL_DEV, .procname = "dev", .mode = 0555, .child = CHILD } 2402564b7bdSEric W. Biederman #define PARPORT_DEVICES_ROOT_DIR { .ctl_name = DEV_PARPORT_DEVICES, .procname = "devices", \ 2412564b7bdSEric W. Biederman .mode = 0555, .child = NULL } 2421da177e4SLinus Torvalds 2431da177e4SLinus Torvalds static const unsigned long parport_min_timeslice_value = 2441da177e4SLinus Torvalds PARPORT_MIN_TIMESLICE_VALUE; 2451da177e4SLinus Torvalds 2461da177e4SLinus Torvalds static const unsigned long parport_max_timeslice_value = 2471da177e4SLinus Torvalds PARPORT_MAX_TIMESLICE_VALUE; 2481da177e4SLinus Torvalds 2491da177e4SLinus Torvalds static const int parport_min_spintime_value = 2501da177e4SLinus Torvalds PARPORT_MIN_SPINTIME_VALUE; 2511da177e4SLinus Torvalds 2521da177e4SLinus Torvalds static const int parport_max_spintime_value = 2531da177e4SLinus Torvalds PARPORT_MAX_SPINTIME_VALUE; 2541da177e4SLinus Torvalds 2551da177e4SLinus Torvalds 2561da177e4SLinus Torvalds struct parport_sysctl_table { 2571da177e4SLinus Torvalds struct ctl_table_header *sysctl_header; 2581da177e4SLinus Torvalds ctl_table vars[12]; 2591da177e4SLinus Torvalds ctl_table device_dir[2]; 2601da177e4SLinus Torvalds ctl_table port_dir[2]; 2611da177e4SLinus Torvalds ctl_table parport_dir[2]; 2621da177e4SLinus Torvalds ctl_table dev_dir[2]; 2631da177e4SLinus Torvalds }; 2641da177e4SLinus Torvalds 2651da177e4SLinus Torvalds static const struct parport_sysctl_table parport_sysctl_template = { 2662564b7bdSEric W. Biederman .sysctl_header = NULL, 2671da177e4SLinus Torvalds { 2682564b7bdSEric W. Biederman { 2692564b7bdSEric W. Biederman .ctl_name = DEV_PARPORT_SPINTIME, 2702564b7bdSEric W. Biederman .procname = "spintime", 2712564b7bdSEric W. Biederman .data = NULL, 2722564b7bdSEric W. Biederman .maxlen = sizeof(int), 2732564b7bdSEric W. Biederman .mode = 0644, 2742564b7bdSEric W. Biederman .proc_handler = &proc_dointvec_minmax, 2752564b7bdSEric W. Biederman .extra1 = (void*) &parport_min_spintime_value, 2762564b7bdSEric W. Biederman .extra2 = (void*) &parport_max_spintime_value 2772564b7bdSEric W. Biederman }, 2782564b7bdSEric W. Biederman { 2792564b7bdSEric W. Biederman .ctl_name = DEV_PARPORT_BASE_ADDR, 2802564b7bdSEric W. Biederman .procname = "base-addr", 2812564b7bdSEric W. Biederman .data = NULL, 2822564b7bdSEric W. Biederman .maxlen = 0, 2832564b7bdSEric W. Biederman .mode = 0444, 2842564b7bdSEric W. Biederman .proc_handler = &do_hardware_base_addr 2852564b7bdSEric W. Biederman }, 2862564b7bdSEric W. Biederman { 2872564b7bdSEric W. Biederman .ctl_name = DEV_PARPORT_IRQ, 2882564b7bdSEric W. Biederman .procname = "irq", 2892564b7bdSEric W. Biederman .data = NULL, 2902564b7bdSEric W. Biederman .maxlen = 0, 2912564b7bdSEric W. Biederman .mode = 0444, 2922564b7bdSEric W. Biederman .proc_handler = &do_hardware_irq 2932564b7bdSEric W. Biederman }, 2942564b7bdSEric W. Biederman { 2952564b7bdSEric W. Biederman .ctl_name = DEV_PARPORT_DMA, 2962564b7bdSEric W. Biederman .procname = "dma", 2972564b7bdSEric W. Biederman .data = NULL, 2982564b7bdSEric W. Biederman .maxlen = 0, 2992564b7bdSEric W. Biederman .mode = 0444, 3002564b7bdSEric W. Biederman .proc_handler = &do_hardware_dma 3012564b7bdSEric W. Biederman }, 3022564b7bdSEric W. Biederman { 3032564b7bdSEric W. Biederman .ctl_name = DEV_PARPORT_MODES, 3042564b7bdSEric W. Biederman .procname = "modes", 3052564b7bdSEric W. Biederman .data = NULL, 3062564b7bdSEric W. Biederman .maxlen = 0, 3072564b7bdSEric W. Biederman .mode = 0444, 3082564b7bdSEric W. Biederman .proc_handler = &do_hardware_modes 3092564b7bdSEric W. Biederman }, 3101da177e4SLinus Torvalds PARPORT_DEVICES_ROOT_DIR, 3111da177e4SLinus Torvalds #ifdef CONFIG_PARPORT_1284 3122564b7bdSEric W. Biederman { 3132564b7bdSEric W. Biederman .ctl_name = DEV_PARPORT_AUTOPROBE, 3142564b7bdSEric W. Biederman .procname = "autoprobe", 3152564b7bdSEric W. Biederman .data = NULL, 3162564b7bdSEric W. Biederman .maxlen = 0, 3172564b7bdSEric W. Biederman .mode = 0444, 3182564b7bdSEric W. Biederman .proc_handler = &do_autoprobe 3191da177e4SLinus Torvalds }, 3202564b7bdSEric W. Biederman { 3212564b7bdSEric W. Biederman .ctl_name = DEV_PARPORT_AUTOPROBE + 1, 3222564b7bdSEric W. Biederman .procname = "autoprobe0", 3232564b7bdSEric W. Biederman .data = NULL, 3242564b7bdSEric W. Biederman .maxlen = 0, 3252564b7bdSEric W. Biederman .mode = 0444, 3262564b7bdSEric W. Biederman .proc_handler = &do_autoprobe 3272564b7bdSEric W. Biederman }, 3282564b7bdSEric W. Biederman { 3292564b7bdSEric W. Biederman .ctl_name = DEV_PARPORT_AUTOPROBE + 2, 3302564b7bdSEric W. Biederman .procname = "autoprobe1", 3312564b7bdSEric W. Biederman .data = NULL, 3322564b7bdSEric W. Biederman .maxlen = 0, 3332564b7bdSEric W. Biederman .mode = 0444, 3342564b7bdSEric W. Biederman .proc_handler = &do_autoprobe 3352564b7bdSEric W. Biederman }, 3362564b7bdSEric W. Biederman { 3372564b7bdSEric W. Biederman .ctl_name = DEV_PARPORT_AUTOPROBE + 3, 3382564b7bdSEric W. Biederman .procname = "autoprobe2", 3392564b7bdSEric W. Biederman .data = NULL, 3402564b7bdSEric W. Biederman .maxlen = 0, 3412564b7bdSEric W. Biederman .mode = 0444, 3422564b7bdSEric W. Biederman .proc_handler = &do_autoprobe 3432564b7bdSEric W. Biederman }, 3442564b7bdSEric W. Biederman { 3452564b7bdSEric W. Biederman .ctl_name = DEV_PARPORT_AUTOPROBE + 4, 3462564b7bdSEric W. Biederman .procname = "autoprobe3", 3472564b7bdSEric W. Biederman .data = NULL, 3482564b7bdSEric W. Biederman .maxlen = 0, 3492564b7bdSEric W. Biederman .mode = 0444, 3502564b7bdSEric W. Biederman .proc_handler = &do_autoprobe 3512564b7bdSEric W. Biederman }, 3522564b7bdSEric W. Biederman #endif /* IEEE 1284 support */ 3532564b7bdSEric W. Biederman {} 3542564b7bdSEric W. Biederman }, 3552564b7bdSEric W. Biederman { 3562564b7bdSEric W. Biederman { 3572564b7bdSEric W. Biederman .ctl_name = DEV_PARPORT_DEVICES_ACTIVE, 3582564b7bdSEric W. Biederman .procname = "active", 3592564b7bdSEric W. Biederman .data = NULL, 3602564b7bdSEric W. Biederman .maxlen = 0, 3612564b7bdSEric W. Biederman .mode = 0444, 3622564b7bdSEric W. Biederman .proc_handler = &do_active_device 3632564b7bdSEric W. Biederman }, 3642564b7bdSEric W. Biederman {} 3652564b7bdSEric W. Biederman }, 3662564b7bdSEric W. Biederman { 3672564b7bdSEric W. Biederman PARPORT_PORT_DIR(NULL), 3682564b7bdSEric W. Biederman {} 3692564b7bdSEric W. Biederman }, 3702564b7bdSEric W. Biederman { 3712564b7bdSEric W. Biederman PARPORT_PARPORT_DIR(NULL), 3722564b7bdSEric W. Biederman {} 3732564b7bdSEric W. Biederman }, 3742564b7bdSEric W. Biederman { 3752564b7bdSEric W. Biederman PARPORT_DEV_DIR(NULL), 3762564b7bdSEric W. Biederman {} 3772564b7bdSEric W. Biederman } 3781da177e4SLinus Torvalds }; 3791da177e4SLinus Torvalds 3801da177e4SLinus Torvalds struct parport_device_sysctl_table 3811da177e4SLinus Torvalds { 3821da177e4SLinus Torvalds struct ctl_table_header *sysctl_header; 3831da177e4SLinus Torvalds ctl_table vars[2]; 3841da177e4SLinus Torvalds ctl_table device_dir[2]; 3851da177e4SLinus Torvalds ctl_table devices_root_dir[2]; 3861da177e4SLinus Torvalds ctl_table port_dir[2]; 3871da177e4SLinus Torvalds ctl_table parport_dir[2]; 3881da177e4SLinus Torvalds ctl_table dev_dir[2]; 3891da177e4SLinus Torvalds }; 3901da177e4SLinus Torvalds 3911da177e4SLinus Torvalds static const struct parport_device_sysctl_table 3921da177e4SLinus Torvalds parport_device_sysctl_template = { 3932564b7bdSEric W. Biederman .sysctl_header = NULL, 3941da177e4SLinus Torvalds { 3952564b7bdSEric W. Biederman { 3962564b7bdSEric W. Biederman .ctl_name = DEV_PARPORT_DEVICE_TIMESLICE, 3972564b7bdSEric W. Biederman .procname = "timeslice", 3982564b7bdSEric W. Biederman .data = NULL, 3992564b7bdSEric W. Biederman .maxlen = sizeof(int), 4002564b7bdSEric W. Biederman .mode = 0644, 4012564b7bdSEric W. Biederman .proc_handler = &proc_doulongvec_ms_jiffies_minmax, 4022564b7bdSEric W. Biederman .extra1 = (void*) &parport_min_timeslice_value, 4032564b7bdSEric W. Biederman .extra2 = (void*) &parport_max_timeslice_value 4041da177e4SLinus Torvalds }, 4052564b7bdSEric W. Biederman }, 4062564b7bdSEric W. Biederman { 4072564b7bdSEric W. Biederman { 4082564b7bdSEric W. Biederman .ctl_name = 0, 4092564b7bdSEric W. Biederman .procname = NULL, 4102564b7bdSEric W. Biederman .data = NULL, 4112564b7bdSEric W. Biederman .maxlen = 0, 4122564b7bdSEric W. Biederman .mode = 0555, 4132564b7bdSEric W. Biederman .child = NULL 4142564b7bdSEric W. Biederman }, 4152564b7bdSEric W. Biederman {} 4162564b7bdSEric W. Biederman }, 4172564b7bdSEric W. Biederman { 4182564b7bdSEric W. Biederman PARPORT_DEVICES_ROOT_DIR, 4192564b7bdSEric W. Biederman {} 4202564b7bdSEric W. Biederman }, 4212564b7bdSEric W. Biederman { 4222564b7bdSEric W. Biederman PARPORT_PORT_DIR(NULL), 4232564b7bdSEric W. Biederman {} 4242564b7bdSEric W. Biederman }, 4252564b7bdSEric W. Biederman { 4262564b7bdSEric W. Biederman PARPORT_PARPORT_DIR(NULL), 4272564b7bdSEric W. Biederman {} 4282564b7bdSEric W. Biederman }, 4292564b7bdSEric W. Biederman { 4302564b7bdSEric W. Biederman PARPORT_DEV_DIR(NULL), 4312564b7bdSEric W. Biederman {} 4322564b7bdSEric W. Biederman } 4331da177e4SLinus Torvalds }; 4341da177e4SLinus Torvalds 4351da177e4SLinus Torvalds struct parport_default_sysctl_table 4361da177e4SLinus Torvalds { 4371da177e4SLinus Torvalds struct ctl_table_header *sysctl_header; 4381da177e4SLinus Torvalds ctl_table vars[3]; 4391da177e4SLinus Torvalds ctl_table default_dir[2]; 4401da177e4SLinus Torvalds ctl_table parport_dir[2]; 4411da177e4SLinus Torvalds ctl_table dev_dir[2]; 4421da177e4SLinus Torvalds }; 4431da177e4SLinus Torvalds 4441da177e4SLinus Torvalds extern unsigned long parport_default_timeslice; 4451da177e4SLinus Torvalds extern int parport_default_spintime; 4461da177e4SLinus Torvalds 4471da177e4SLinus Torvalds static struct parport_default_sysctl_table 4481da177e4SLinus Torvalds parport_default_sysctl_table = { 4492564b7bdSEric W. Biederman .sysctl_header = NULL, 4501da177e4SLinus Torvalds { 4512564b7bdSEric W. Biederman { 4522564b7bdSEric W. Biederman .ctl_name = DEV_PARPORT_DEFAULT_TIMESLICE, 4532564b7bdSEric W. Biederman .procname = "timeslice", 4542564b7bdSEric W. Biederman .data = &parport_default_timeslice, 4552564b7bdSEric W. Biederman .maxlen = sizeof(parport_default_timeslice), 4562564b7bdSEric W. Biederman .mode = 0644, 4572564b7bdSEric W. Biederman .proc_handler = &proc_doulongvec_ms_jiffies_minmax, 4582564b7bdSEric W. Biederman .extra1 = (void*) &parport_min_timeslice_value, 4592564b7bdSEric W. Biederman .extra2 = (void*) &parport_max_timeslice_value 4601da177e4SLinus Torvalds }, 4612564b7bdSEric W. Biederman { 4622564b7bdSEric W. Biederman .ctl_name = DEV_PARPORT_DEFAULT_SPINTIME, 4632564b7bdSEric W. Biederman .procname = "spintime", 4642564b7bdSEric W. Biederman .data = &parport_default_spintime, 4652564b7bdSEric W. Biederman .maxlen = sizeof(parport_default_spintime), 4662564b7bdSEric W. Biederman .mode = 0644, 4672564b7bdSEric W. Biederman .proc_handler = &proc_dointvec_minmax, 4682564b7bdSEric W. Biederman .extra1 = (void*) &parport_min_spintime_value, 4692564b7bdSEric W. Biederman .extra2 = (void*) &parport_max_spintime_value 4702564b7bdSEric W. Biederman }, 4712564b7bdSEric W. Biederman {} 4722564b7bdSEric W. Biederman }, 4732564b7bdSEric W. Biederman { 4742564b7bdSEric W. Biederman { 4752564b7bdSEric W. Biederman .ctl_name = DEV_PARPORT_DEFAULT, 4762564b7bdSEric W. Biederman .procname = "default", 4772564b7bdSEric W. Biederman .mode = 0555, 4782564b7bdSEric W. Biederman .child = parport_default_sysctl_table.vars 4792564b7bdSEric W. Biederman }, 4802564b7bdSEric W. Biederman {} 4812564b7bdSEric W. Biederman }, 4821da177e4SLinus Torvalds { 4831da177e4SLinus Torvalds PARPORT_PARPORT_DIR(parport_default_sysctl_table.default_dir), 4842564b7bdSEric W. Biederman {} 4852564b7bdSEric W. Biederman }, 4862564b7bdSEric W. Biederman { 4872564b7bdSEric W. Biederman PARPORT_DEV_DIR(parport_default_sysctl_table.parport_dir), 4882564b7bdSEric W. Biederman {} 4892564b7bdSEric W. Biederman } 4901da177e4SLinus Torvalds }; 4911da177e4SLinus Torvalds 4921da177e4SLinus Torvalds 4931da177e4SLinus Torvalds int parport_proc_register(struct parport *port) 4941da177e4SLinus Torvalds { 4951da177e4SLinus Torvalds struct parport_sysctl_table *t; 4961da177e4SLinus Torvalds int i; 4971da177e4SLinus Torvalds 4981da177e4SLinus Torvalds t = kmalloc(sizeof(*t), GFP_KERNEL); 4991da177e4SLinus Torvalds if (t == NULL) 5001da177e4SLinus Torvalds return -ENOMEM; 5011da177e4SLinus Torvalds memcpy(t, &parport_sysctl_template, sizeof(*t)); 5021da177e4SLinus Torvalds 5031da177e4SLinus Torvalds t->device_dir[0].extra1 = port; 5041da177e4SLinus Torvalds 5051da177e4SLinus Torvalds for (i = 0; i < 8; i++) 5061da177e4SLinus Torvalds t->vars[i].extra1 = port; 5071da177e4SLinus Torvalds 5081da177e4SLinus Torvalds t->vars[0].data = &port->spintime; 5091da177e4SLinus Torvalds t->vars[5].child = t->device_dir; 5101da177e4SLinus Torvalds 5111da177e4SLinus Torvalds for (i = 0; i < 5; i++) 5121da177e4SLinus Torvalds t->vars[6 + i].extra2 = &port->probe_info[i]; 5131da177e4SLinus Torvalds 5141da177e4SLinus Torvalds t->port_dir[0].procname = port->name; 5151da177e4SLinus Torvalds t->port_dir[0].ctl_name = port->number + 1; /* nb 0 isn't legal here */ 5161da177e4SLinus Torvalds 5171da177e4SLinus Torvalds t->port_dir[0].child = t->vars; 5181da177e4SLinus Torvalds t->parport_dir[0].child = t->port_dir; 5191da177e4SLinus Torvalds t->dev_dir[0].child = t->parport_dir; 5201da177e4SLinus Torvalds 521*0b4d4147SEric W. Biederman t->sysctl_header = register_sysctl_table(t->dev_dir); 5221da177e4SLinus Torvalds if (t->sysctl_header == NULL) { 5231da177e4SLinus Torvalds kfree(t); 5241da177e4SLinus Torvalds t = NULL; 5251da177e4SLinus Torvalds } 5261da177e4SLinus Torvalds port->sysctl_table = t; 5271da177e4SLinus Torvalds return 0; 5281da177e4SLinus Torvalds } 5291da177e4SLinus Torvalds 5301da177e4SLinus Torvalds int parport_proc_unregister(struct parport *port) 5311da177e4SLinus Torvalds { 5321da177e4SLinus Torvalds if (port->sysctl_table) { 5331da177e4SLinus Torvalds struct parport_sysctl_table *t = port->sysctl_table; 5341da177e4SLinus Torvalds port->sysctl_table = NULL; 5351da177e4SLinus Torvalds unregister_sysctl_table(t->sysctl_header); 5361da177e4SLinus Torvalds kfree(t); 5371da177e4SLinus Torvalds } 5381da177e4SLinus Torvalds return 0; 5391da177e4SLinus Torvalds } 5401da177e4SLinus Torvalds 5411da177e4SLinus Torvalds int parport_device_proc_register(struct pardevice *device) 5421da177e4SLinus Torvalds { 5431da177e4SLinus Torvalds struct parport_device_sysctl_table *t; 5441da177e4SLinus Torvalds struct parport * port = device->port; 5451da177e4SLinus Torvalds 5461da177e4SLinus Torvalds t = kmalloc(sizeof(*t), GFP_KERNEL); 5471da177e4SLinus Torvalds if (t == NULL) 5481da177e4SLinus Torvalds return -ENOMEM; 5491da177e4SLinus Torvalds memcpy(t, &parport_device_sysctl_template, sizeof(*t)); 5501da177e4SLinus Torvalds 5511da177e4SLinus Torvalds t->dev_dir[0].child = t->parport_dir; 5521da177e4SLinus Torvalds t->parport_dir[0].child = t->port_dir; 5531da177e4SLinus Torvalds t->port_dir[0].procname = port->name; 5541da177e4SLinus Torvalds t->port_dir[0].ctl_name = port->number + 1; /* nb 0 isn't legal here */ 5551da177e4SLinus Torvalds t->port_dir[0].child = t->devices_root_dir; 5561da177e4SLinus Torvalds t->devices_root_dir[0].child = t->device_dir; 5571da177e4SLinus Torvalds 5581da177e4SLinus Torvalds #ifdef CONFIG_PARPORT_1284 5591da177e4SLinus Torvalds 5601da177e4SLinus Torvalds t->device_dir[0].ctl_name = 5611da177e4SLinus Torvalds parport_device_num(port->number, port->muxport, 5621da177e4SLinus Torvalds device->daisy) 5631da177e4SLinus Torvalds + 1; /* nb 0 isn't legal here */ 5641da177e4SLinus Torvalds 5651da177e4SLinus Torvalds #else /* No IEEE 1284 support */ 5661da177e4SLinus Torvalds 5671da177e4SLinus Torvalds /* parport_device_num isn't available. */ 5681da177e4SLinus Torvalds t->device_dir[0].ctl_name = 1; 5691da177e4SLinus Torvalds 5701da177e4SLinus Torvalds #endif /* IEEE 1284 support or not */ 5711da177e4SLinus Torvalds 5721da177e4SLinus Torvalds t->device_dir[0].procname = device->name; 5731da177e4SLinus Torvalds t->device_dir[0].extra1 = device; 5741da177e4SLinus Torvalds t->device_dir[0].child = t->vars; 5751da177e4SLinus Torvalds t->vars[0].data = &device->timeslice; 5761da177e4SLinus Torvalds 577*0b4d4147SEric W. Biederman t->sysctl_header = register_sysctl_table(t->dev_dir); 5781da177e4SLinus Torvalds if (t->sysctl_header == NULL) { 5791da177e4SLinus Torvalds kfree(t); 5801da177e4SLinus Torvalds t = NULL; 5811da177e4SLinus Torvalds } 5821da177e4SLinus Torvalds device->sysctl_table = t; 5831da177e4SLinus Torvalds return 0; 5841da177e4SLinus Torvalds } 5851da177e4SLinus Torvalds 5861da177e4SLinus Torvalds int parport_device_proc_unregister(struct pardevice *device) 5871da177e4SLinus Torvalds { 5881da177e4SLinus Torvalds if (device->sysctl_table) { 5891da177e4SLinus Torvalds struct parport_device_sysctl_table *t = device->sysctl_table; 5901da177e4SLinus Torvalds device->sysctl_table = NULL; 5911da177e4SLinus Torvalds unregister_sysctl_table(t->sysctl_header); 5921da177e4SLinus Torvalds kfree(t); 5931da177e4SLinus Torvalds } 5941da177e4SLinus Torvalds return 0; 5951da177e4SLinus Torvalds } 5961da177e4SLinus Torvalds 5971da177e4SLinus Torvalds static int __init parport_default_proc_register(void) 5981da177e4SLinus Torvalds { 5991da177e4SLinus Torvalds parport_default_sysctl_table.sysctl_header = 600*0b4d4147SEric W. Biederman register_sysctl_table(parport_default_sysctl_table.dev_dir); 6011da177e4SLinus Torvalds return 0; 6021da177e4SLinus Torvalds } 6031da177e4SLinus Torvalds 6041da177e4SLinus Torvalds static void __exit parport_default_proc_unregister(void) 6051da177e4SLinus Torvalds { 6061da177e4SLinus Torvalds if (parport_default_sysctl_table.sysctl_header) { 6071da177e4SLinus Torvalds unregister_sysctl_table(parport_default_sysctl_table. 6081da177e4SLinus Torvalds sysctl_header); 6091da177e4SLinus Torvalds parport_default_sysctl_table.sysctl_header = NULL; 6101da177e4SLinus Torvalds } 6111da177e4SLinus Torvalds } 6121da177e4SLinus Torvalds 6131da177e4SLinus Torvalds #else /* no sysctl or no procfs*/ 6141da177e4SLinus Torvalds 6151da177e4SLinus Torvalds int parport_proc_register(struct parport *pp) 6161da177e4SLinus Torvalds { 6171da177e4SLinus Torvalds return 0; 6181da177e4SLinus Torvalds } 6191da177e4SLinus Torvalds 6201da177e4SLinus Torvalds int parport_proc_unregister(struct parport *pp) 6211da177e4SLinus Torvalds { 6221da177e4SLinus Torvalds return 0; 6231da177e4SLinus Torvalds } 6241da177e4SLinus Torvalds 6251da177e4SLinus Torvalds int parport_device_proc_register(struct pardevice *device) 6261da177e4SLinus Torvalds { 6271da177e4SLinus Torvalds return 0; 6281da177e4SLinus Torvalds } 6291da177e4SLinus Torvalds 6301da177e4SLinus Torvalds int parport_device_proc_unregister(struct pardevice *device) 6311da177e4SLinus Torvalds { 6321da177e4SLinus Torvalds return 0; 6331da177e4SLinus Torvalds } 6341da177e4SLinus Torvalds 6351da177e4SLinus Torvalds static int __init parport_default_proc_register (void) 6361da177e4SLinus Torvalds { 6371da177e4SLinus Torvalds return 0; 6381da177e4SLinus Torvalds } 6391da177e4SLinus Torvalds 6401da177e4SLinus Torvalds static void __exit parport_default_proc_unregister (void) 6411da177e4SLinus Torvalds { 6421da177e4SLinus Torvalds } 6431da177e4SLinus Torvalds #endif 6441da177e4SLinus Torvalds 6451da177e4SLinus Torvalds module_init(parport_default_proc_register) 6461da177e4SLinus Torvalds module_exit(parport_default_proc_unregister) 647