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 348d65af78SAlexey Dobriyan static int do_active_device(ctl_table *table, int write, 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 718d65af78SAlexey Dobriyan static int do_autoprobe(ctl_table *table, int write, 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, 1148d65af78SAlexey Dobriyan 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, 1428d65af78SAlexey Dobriyan 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, 1708d65af78SAlexey Dobriyan 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, 1988d65af78SAlexey Dobriyan 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 236894d2491SEric W. Biederman #define PARPORT_PORT_DIR(CHILD) { .procname = NULL, .mode = 0555, .child = CHILD } 237894d2491SEric W. Biederman #define PARPORT_PARPORT_DIR(CHILD) { .procname = "parport", \ 2382564b7bdSEric W. Biederman .mode = 0555, .child = CHILD } 239894d2491SEric W. Biederman #define PARPORT_DEV_DIR(CHILD) { .procname = "dev", .mode = 0555, .child = CHILD } 24025398a15SEric W. Biederman #define PARPORT_DEVICES_ROOT_DIR { .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 .procname = "spintime", 2702564b7bdSEric W. Biederman .data = NULL, 2712564b7bdSEric W. Biederman .maxlen = sizeof(int), 2722564b7bdSEric W. Biederman .mode = 0644, 2736d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 2742564b7bdSEric W. Biederman .extra1 = (void*) &parport_min_spintime_value, 2752564b7bdSEric W. Biederman .extra2 = (void*) &parport_max_spintime_value 2762564b7bdSEric W. Biederman }, 2772564b7bdSEric W. Biederman { 2782564b7bdSEric W. Biederman .procname = "base-addr", 2792564b7bdSEric W. Biederman .data = NULL, 2802564b7bdSEric W. Biederman .maxlen = 0, 2812564b7bdSEric W. Biederman .mode = 0444, 2826d456111SEric W. Biederman .proc_handler = do_hardware_base_addr 2832564b7bdSEric W. Biederman }, 2842564b7bdSEric W. Biederman { 2852564b7bdSEric W. Biederman .procname = "irq", 2862564b7bdSEric W. Biederman .data = NULL, 2872564b7bdSEric W. Biederman .maxlen = 0, 2882564b7bdSEric W. Biederman .mode = 0444, 2896d456111SEric W. Biederman .proc_handler = do_hardware_irq 2902564b7bdSEric W. Biederman }, 2912564b7bdSEric W. Biederman { 2922564b7bdSEric W. Biederman .procname = "dma", 2932564b7bdSEric W. Biederman .data = NULL, 2942564b7bdSEric W. Biederman .maxlen = 0, 2952564b7bdSEric W. Biederman .mode = 0444, 2966d456111SEric W. Biederman .proc_handler = do_hardware_dma 2972564b7bdSEric W. Biederman }, 2982564b7bdSEric W. Biederman { 2992564b7bdSEric W. Biederman .procname = "modes", 3002564b7bdSEric W. Biederman .data = NULL, 3012564b7bdSEric W. Biederman .maxlen = 0, 3022564b7bdSEric W. Biederman .mode = 0444, 3036d456111SEric W. Biederman .proc_handler = do_hardware_modes 3042564b7bdSEric W. Biederman }, 3051da177e4SLinus Torvalds PARPORT_DEVICES_ROOT_DIR, 3061da177e4SLinus Torvalds #ifdef CONFIG_PARPORT_1284 3072564b7bdSEric W. Biederman { 3082564b7bdSEric W. Biederman .procname = "autoprobe", 3092564b7bdSEric W. Biederman .data = NULL, 3102564b7bdSEric W. Biederman .maxlen = 0, 3112564b7bdSEric W. Biederman .mode = 0444, 3126d456111SEric W. Biederman .proc_handler = do_autoprobe 3131da177e4SLinus Torvalds }, 3142564b7bdSEric W. Biederman { 3152564b7bdSEric W. Biederman .procname = "autoprobe0", 3162564b7bdSEric W. Biederman .data = NULL, 3172564b7bdSEric W. Biederman .maxlen = 0, 3182564b7bdSEric W. Biederman .mode = 0444, 3196d456111SEric W. Biederman .proc_handler = do_autoprobe 3202564b7bdSEric W. Biederman }, 3212564b7bdSEric W. Biederman { 3222564b7bdSEric W. Biederman .procname = "autoprobe1", 3232564b7bdSEric W. Biederman .data = NULL, 3242564b7bdSEric W. Biederman .maxlen = 0, 3252564b7bdSEric W. Biederman .mode = 0444, 3266d456111SEric W. Biederman .proc_handler = do_autoprobe 3272564b7bdSEric W. Biederman }, 3282564b7bdSEric W. Biederman { 3292564b7bdSEric W. Biederman .procname = "autoprobe2", 3302564b7bdSEric W. Biederman .data = NULL, 3312564b7bdSEric W. Biederman .maxlen = 0, 3322564b7bdSEric W. Biederman .mode = 0444, 3336d456111SEric W. Biederman .proc_handler = do_autoprobe 3342564b7bdSEric W. Biederman }, 3352564b7bdSEric W. Biederman { 3362564b7bdSEric W. Biederman .procname = "autoprobe3", 3372564b7bdSEric W. Biederman .data = NULL, 3382564b7bdSEric W. Biederman .maxlen = 0, 3392564b7bdSEric W. Biederman .mode = 0444, 3406d456111SEric W. Biederman .proc_handler = do_autoprobe 3412564b7bdSEric W. Biederman }, 3422564b7bdSEric W. Biederman #endif /* IEEE 1284 support */ 3432564b7bdSEric W. Biederman {} 3442564b7bdSEric W. Biederman }, 3452564b7bdSEric W. Biederman { 3462564b7bdSEric W. Biederman { 3472564b7bdSEric W. Biederman .procname = "active", 3482564b7bdSEric W. Biederman .data = NULL, 3492564b7bdSEric W. Biederman .maxlen = 0, 3502564b7bdSEric W. Biederman .mode = 0444, 3516d456111SEric W. Biederman .proc_handler = do_active_device 3522564b7bdSEric W. Biederman }, 3532564b7bdSEric W. Biederman {} 3542564b7bdSEric W. Biederman }, 3552564b7bdSEric W. Biederman { 3562564b7bdSEric W. Biederman PARPORT_PORT_DIR(NULL), 3572564b7bdSEric W. Biederman {} 3582564b7bdSEric W. Biederman }, 3592564b7bdSEric W. Biederman { 3602564b7bdSEric W. Biederman PARPORT_PARPORT_DIR(NULL), 3612564b7bdSEric W. Biederman {} 3622564b7bdSEric W. Biederman }, 3632564b7bdSEric W. Biederman { 3642564b7bdSEric W. Biederman PARPORT_DEV_DIR(NULL), 3652564b7bdSEric W. Biederman {} 3662564b7bdSEric W. Biederman } 3671da177e4SLinus Torvalds }; 3681da177e4SLinus Torvalds 3691da177e4SLinus Torvalds struct parport_device_sysctl_table 3701da177e4SLinus Torvalds { 3711da177e4SLinus Torvalds struct ctl_table_header *sysctl_header; 3721da177e4SLinus Torvalds ctl_table vars[2]; 3731da177e4SLinus Torvalds ctl_table device_dir[2]; 3741da177e4SLinus Torvalds ctl_table devices_root_dir[2]; 3751da177e4SLinus Torvalds ctl_table port_dir[2]; 3761da177e4SLinus Torvalds ctl_table parport_dir[2]; 3771da177e4SLinus Torvalds ctl_table dev_dir[2]; 3781da177e4SLinus Torvalds }; 3791da177e4SLinus Torvalds 3801da177e4SLinus Torvalds static const struct parport_device_sysctl_table 3811da177e4SLinus Torvalds parport_device_sysctl_template = { 3822564b7bdSEric W. Biederman .sysctl_header = NULL, 3831da177e4SLinus Torvalds { 3842564b7bdSEric W. Biederman { 3852564b7bdSEric W. Biederman .procname = "timeslice", 3862564b7bdSEric W. Biederman .data = NULL, 38760af8803SEric Dumazet .maxlen = sizeof(unsigned long), 3882564b7bdSEric W. Biederman .mode = 0644, 3896d456111SEric W. Biederman .proc_handler = proc_doulongvec_ms_jiffies_minmax, 3902564b7bdSEric W. Biederman .extra1 = (void*) &parport_min_timeslice_value, 3912564b7bdSEric W. Biederman .extra2 = (void*) &parport_max_timeslice_value 3921da177e4SLinus Torvalds }, 3932564b7bdSEric W. Biederman }, 3942564b7bdSEric W. Biederman { 3952564b7bdSEric W. Biederman { 3962564b7bdSEric W. Biederman .procname = NULL, 3972564b7bdSEric W. Biederman .data = NULL, 3982564b7bdSEric W. Biederman .maxlen = 0, 3992564b7bdSEric W. Biederman .mode = 0555, 4002564b7bdSEric W. Biederman .child = NULL 4012564b7bdSEric W. Biederman }, 4022564b7bdSEric W. Biederman {} 4032564b7bdSEric W. Biederman }, 4042564b7bdSEric W. Biederman { 4052564b7bdSEric W. Biederman PARPORT_DEVICES_ROOT_DIR, 4062564b7bdSEric W. Biederman {} 4072564b7bdSEric W. Biederman }, 4082564b7bdSEric W. Biederman { 4092564b7bdSEric W. Biederman PARPORT_PORT_DIR(NULL), 4102564b7bdSEric W. Biederman {} 4112564b7bdSEric W. Biederman }, 4122564b7bdSEric W. Biederman { 4132564b7bdSEric W. Biederman PARPORT_PARPORT_DIR(NULL), 4142564b7bdSEric W. Biederman {} 4152564b7bdSEric W. Biederman }, 4162564b7bdSEric W. Biederman { 4172564b7bdSEric W. Biederman PARPORT_DEV_DIR(NULL), 4182564b7bdSEric W. Biederman {} 4192564b7bdSEric W. Biederman } 4201da177e4SLinus Torvalds }; 4211da177e4SLinus Torvalds 4221da177e4SLinus Torvalds struct parport_default_sysctl_table 4231da177e4SLinus Torvalds { 4241da177e4SLinus Torvalds struct ctl_table_header *sysctl_header; 4251da177e4SLinus Torvalds ctl_table vars[3]; 4261da177e4SLinus Torvalds ctl_table default_dir[2]; 4271da177e4SLinus Torvalds ctl_table parport_dir[2]; 4281da177e4SLinus Torvalds ctl_table dev_dir[2]; 4291da177e4SLinus Torvalds }; 4301da177e4SLinus Torvalds 4311da177e4SLinus Torvalds static struct parport_default_sysctl_table 4321da177e4SLinus Torvalds parport_default_sysctl_table = { 4332564b7bdSEric W. Biederman .sysctl_header = NULL, 4341da177e4SLinus Torvalds { 4352564b7bdSEric W. Biederman { 4362564b7bdSEric W. Biederman .procname = "timeslice", 4372564b7bdSEric W. Biederman .data = &parport_default_timeslice, 4382564b7bdSEric W. Biederman .maxlen = sizeof(parport_default_timeslice), 4392564b7bdSEric W. Biederman .mode = 0644, 4406d456111SEric W. Biederman .proc_handler = proc_doulongvec_ms_jiffies_minmax, 4412564b7bdSEric W. Biederman .extra1 = (void*) &parport_min_timeslice_value, 4422564b7bdSEric W. Biederman .extra2 = (void*) &parport_max_timeslice_value 4431da177e4SLinus Torvalds }, 4442564b7bdSEric W. Biederman { 4452564b7bdSEric W. Biederman .procname = "spintime", 4462564b7bdSEric W. Biederman .data = &parport_default_spintime, 4472564b7bdSEric W. Biederman .maxlen = sizeof(parport_default_spintime), 4482564b7bdSEric W. Biederman .mode = 0644, 4496d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 4502564b7bdSEric W. Biederman .extra1 = (void*) &parport_min_spintime_value, 4512564b7bdSEric W. Biederman .extra2 = (void*) &parport_max_spintime_value 4522564b7bdSEric W. Biederman }, 4532564b7bdSEric W. Biederman {} 4542564b7bdSEric W. Biederman }, 4552564b7bdSEric W. Biederman { 4562564b7bdSEric W. Biederman { 4572564b7bdSEric W. Biederman .procname = "default", 4582564b7bdSEric W. Biederman .mode = 0555, 4592564b7bdSEric W. Biederman .child = parport_default_sysctl_table.vars 4602564b7bdSEric W. Biederman }, 4612564b7bdSEric W. Biederman {} 4622564b7bdSEric W. Biederman }, 4631da177e4SLinus Torvalds { 4641da177e4SLinus Torvalds PARPORT_PARPORT_DIR(parport_default_sysctl_table.default_dir), 4652564b7bdSEric W. Biederman {} 4662564b7bdSEric W. Biederman }, 4672564b7bdSEric W. Biederman { 4682564b7bdSEric W. Biederman PARPORT_DEV_DIR(parport_default_sysctl_table.parport_dir), 4692564b7bdSEric W. Biederman {} 4702564b7bdSEric W. Biederman } 4711da177e4SLinus Torvalds }; 4721da177e4SLinus Torvalds 4731da177e4SLinus Torvalds 4741da177e4SLinus Torvalds int parport_proc_register(struct parport *port) 4751da177e4SLinus Torvalds { 4761da177e4SLinus Torvalds struct parport_sysctl_table *t; 4771da177e4SLinus Torvalds int i; 4781da177e4SLinus Torvalds 479*2451a848SSilviu-Mihai Popescu t = kmemdup(&parport_sysctl_template, sizeof(*t), GFP_KERNEL); 4801da177e4SLinus Torvalds if (t == NULL) 4811da177e4SLinus Torvalds return -ENOMEM; 4821da177e4SLinus Torvalds 4831da177e4SLinus Torvalds t->device_dir[0].extra1 = port; 4841da177e4SLinus Torvalds 48525398a15SEric W. Biederman for (i = 0; i < 5; i++) 4861da177e4SLinus Torvalds t->vars[i].extra1 = port; 4871da177e4SLinus Torvalds 4881da177e4SLinus Torvalds t->vars[0].data = &port->spintime; 4891da177e4SLinus Torvalds t->vars[5].child = t->device_dir; 4901da177e4SLinus Torvalds 4911da177e4SLinus Torvalds for (i = 0; i < 5; i++) 4921da177e4SLinus Torvalds t->vars[6 + i].extra2 = &port->probe_info[i]; 4931da177e4SLinus Torvalds 4941da177e4SLinus Torvalds t->port_dir[0].procname = port->name; 4951da177e4SLinus Torvalds 4961da177e4SLinus Torvalds t->port_dir[0].child = t->vars; 4971da177e4SLinus Torvalds t->parport_dir[0].child = t->port_dir; 4981da177e4SLinus Torvalds t->dev_dir[0].child = t->parport_dir; 4991da177e4SLinus Torvalds 5000b4d4147SEric W. Biederman t->sysctl_header = register_sysctl_table(t->dev_dir); 5011da177e4SLinus Torvalds if (t->sysctl_header == NULL) { 5021da177e4SLinus Torvalds kfree(t); 5031da177e4SLinus Torvalds t = NULL; 5041da177e4SLinus Torvalds } 5051da177e4SLinus Torvalds port->sysctl_table = t; 5061da177e4SLinus Torvalds return 0; 5071da177e4SLinus Torvalds } 5081da177e4SLinus Torvalds 5091da177e4SLinus Torvalds int parport_proc_unregister(struct parport *port) 5101da177e4SLinus Torvalds { 5111da177e4SLinus Torvalds if (port->sysctl_table) { 5121da177e4SLinus Torvalds struct parport_sysctl_table *t = port->sysctl_table; 5131da177e4SLinus Torvalds port->sysctl_table = NULL; 5141da177e4SLinus Torvalds unregister_sysctl_table(t->sysctl_header); 5151da177e4SLinus Torvalds kfree(t); 5161da177e4SLinus Torvalds } 5171da177e4SLinus Torvalds return 0; 5181da177e4SLinus Torvalds } 5191da177e4SLinus Torvalds 5201da177e4SLinus Torvalds int parport_device_proc_register(struct pardevice *device) 5211da177e4SLinus Torvalds { 5221da177e4SLinus Torvalds struct parport_device_sysctl_table *t; 5231da177e4SLinus Torvalds struct parport * port = device->port; 5241da177e4SLinus Torvalds 525*2451a848SSilviu-Mihai Popescu t = kmemdup(&parport_device_sysctl_template, sizeof(*t), GFP_KERNEL); 5261da177e4SLinus Torvalds if (t == NULL) 5271da177e4SLinus Torvalds return -ENOMEM; 5281da177e4SLinus Torvalds 5291da177e4SLinus Torvalds t->dev_dir[0].child = t->parport_dir; 5301da177e4SLinus Torvalds t->parport_dir[0].child = t->port_dir; 5311da177e4SLinus Torvalds t->port_dir[0].procname = port->name; 5321da177e4SLinus Torvalds t->port_dir[0].child = t->devices_root_dir; 5331da177e4SLinus Torvalds t->devices_root_dir[0].child = t->device_dir; 5341da177e4SLinus Torvalds 5351da177e4SLinus Torvalds t->device_dir[0].procname = device->name; 5361da177e4SLinus Torvalds t->device_dir[0].child = t->vars; 5371da177e4SLinus Torvalds t->vars[0].data = &device->timeslice; 5381da177e4SLinus Torvalds 5390b4d4147SEric W. Biederman t->sysctl_header = register_sysctl_table(t->dev_dir); 5401da177e4SLinus Torvalds if (t->sysctl_header == NULL) { 5411da177e4SLinus Torvalds kfree(t); 5421da177e4SLinus Torvalds t = NULL; 5431da177e4SLinus Torvalds } 5441da177e4SLinus Torvalds device->sysctl_table = t; 5451da177e4SLinus Torvalds return 0; 5461da177e4SLinus Torvalds } 5471da177e4SLinus Torvalds 5481da177e4SLinus Torvalds int parport_device_proc_unregister(struct pardevice *device) 5491da177e4SLinus Torvalds { 5501da177e4SLinus Torvalds if (device->sysctl_table) { 5511da177e4SLinus Torvalds struct parport_device_sysctl_table *t = device->sysctl_table; 5521da177e4SLinus Torvalds device->sysctl_table = NULL; 5531da177e4SLinus Torvalds unregister_sysctl_table(t->sysctl_header); 5541da177e4SLinus Torvalds kfree(t); 5551da177e4SLinus Torvalds } 5561da177e4SLinus Torvalds return 0; 5571da177e4SLinus Torvalds } 5581da177e4SLinus Torvalds 5591da177e4SLinus Torvalds static int __init parport_default_proc_register(void) 5601da177e4SLinus Torvalds { 5611da177e4SLinus Torvalds parport_default_sysctl_table.sysctl_header = 5620b4d4147SEric W. Biederman register_sysctl_table(parport_default_sysctl_table.dev_dir); 5631da177e4SLinus Torvalds return 0; 5641da177e4SLinus Torvalds } 5651da177e4SLinus Torvalds 5661da177e4SLinus Torvalds static void __exit parport_default_proc_unregister(void) 5671da177e4SLinus Torvalds { 5681da177e4SLinus Torvalds if (parport_default_sysctl_table.sysctl_header) { 5691da177e4SLinus Torvalds unregister_sysctl_table(parport_default_sysctl_table. 5701da177e4SLinus Torvalds sysctl_header); 5711da177e4SLinus Torvalds parport_default_sysctl_table.sysctl_header = NULL; 5721da177e4SLinus Torvalds } 5731da177e4SLinus Torvalds } 5741da177e4SLinus Torvalds 5751da177e4SLinus Torvalds #else /* no sysctl or no procfs*/ 5761da177e4SLinus Torvalds 5771da177e4SLinus Torvalds int parport_proc_register(struct parport *pp) 5781da177e4SLinus Torvalds { 5791da177e4SLinus Torvalds return 0; 5801da177e4SLinus Torvalds } 5811da177e4SLinus Torvalds 5821da177e4SLinus Torvalds int parport_proc_unregister(struct parport *pp) 5831da177e4SLinus Torvalds { 5841da177e4SLinus Torvalds return 0; 5851da177e4SLinus Torvalds } 5861da177e4SLinus Torvalds 5871da177e4SLinus Torvalds int parport_device_proc_register(struct pardevice *device) 5881da177e4SLinus Torvalds { 5891da177e4SLinus Torvalds return 0; 5901da177e4SLinus Torvalds } 5911da177e4SLinus Torvalds 5921da177e4SLinus Torvalds int parport_device_proc_unregister(struct pardevice *device) 5931da177e4SLinus Torvalds { 5941da177e4SLinus Torvalds return 0; 5951da177e4SLinus Torvalds } 5961da177e4SLinus Torvalds 5971da177e4SLinus Torvalds static int __init parport_default_proc_register (void) 5981da177e4SLinus Torvalds { 5991da177e4SLinus Torvalds return 0; 6001da177e4SLinus Torvalds } 6011da177e4SLinus Torvalds 6021da177e4SLinus Torvalds static void __exit parport_default_proc_unregister (void) 6031da177e4SLinus Torvalds { 6041da177e4SLinus Torvalds } 6051da177e4SLinus Torvalds #endif 6061da177e4SLinus Torvalds 6071da177e4SLinus Torvalds module_init(parport_default_proc_register) 6081da177e4SLinus Torvalds module_exit(parport_default_proc_unregister) 609