1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 21da177e4SLinus Torvalds /* Sysctl interface for parport devices. 31da177e4SLinus Torvalds * 4bdca3f20SAdrian Bunk * Authors: David Campbell 51da177e4SLinus Torvalds * Tim Waugh <tim@cyberelk.demon.co.uk> 61da177e4SLinus Torvalds * Philip Blundell <philb@gnu.org> 71da177e4SLinus Torvalds * Andrea Arcangeli 81da177e4SLinus Torvalds * Riccardo Facchetti <fizban@tin.it> 91da177e4SLinus Torvalds * 101da177e4SLinus Torvalds * based on work by Grant Guenther <grant@torque.net> 111da177e4SLinus Torvalds * and Philip Blundell 121da177e4SLinus Torvalds * 131da177e4SLinus Torvalds * Cleaned up include files - Russell King <linux@arm.uk.linux.org> 141da177e4SLinus Torvalds */ 151da177e4SLinus Torvalds 161da177e4SLinus Torvalds #include <linux/string.h> 171da177e4SLinus Torvalds #include <linux/init.h> 181da177e4SLinus Torvalds #include <linux/module.h> 191da177e4SLinus Torvalds #include <linux/errno.h> 201da177e4SLinus Torvalds #include <linux/kernel.h> 211da177e4SLinus Torvalds #include <linux/slab.h> 221da177e4SLinus Torvalds #include <linux/parport.h> 231da177e4SLinus Torvalds #include <linux/ctype.h> 241da177e4SLinus Torvalds #include <linux/sysctl.h> 256fa45a22SSudip Mukherjee #include <linux/device.h> 261da177e4SLinus Torvalds 277c0f6ba6SLinus Torvalds #include <linux/uaccess.h> 281da177e4SLinus Torvalds 291da177e4SLinus Torvalds #if defined(CONFIG_SYSCTL) && defined(CONFIG_PROC_FS) 301da177e4SLinus Torvalds 311da177e4SLinus Torvalds #define PARPORT_MIN_TIMESLICE_VALUE 1ul 321da177e4SLinus Torvalds #define PARPORT_MAX_TIMESLICE_VALUE ((unsigned long) HZ) 331da177e4SLinus Torvalds #define PARPORT_MIN_SPINTIME_VALUE 1 341da177e4SLinus Torvalds #define PARPORT_MAX_SPINTIME_VALUE 1000 35*93810936SJoel Granados /* 36*93810936SJoel Granados * PARPORT_BASE_* is the size of the known parts of the sysctl path 37*93810936SJoel Granados * in dev/partport/%s/devices/%s. "dev/parport/"(12), "/devices/"(9 38*93810936SJoel Granados * and null char(1). 39*93810936SJoel Granados */ 40*93810936SJoel Granados #define PARPORT_BASE_PATH_SIZE 13 41*93810936SJoel Granados #define PARPORT_BASE_DEVICES_PATH_SIZE 22 421da177e4SLinus Torvalds 43be424c63SJoe Perches static int do_active_device(struct ctl_table *table, int write, 4432927393SChristoph Hellwig void *result, size_t *lenp, loff_t *ppos) 451da177e4SLinus Torvalds { 461da177e4SLinus Torvalds struct parport *port = (struct parport *)table->extra1; 471da177e4SLinus Torvalds char buffer[256]; 481da177e4SLinus Torvalds struct pardevice *dev; 491da177e4SLinus Torvalds int len = 0; 501da177e4SLinus Torvalds 511da177e4SLinus Torvalds if (write) /* can't happen anyway */ 521da177e4SLinus Torvalds return -EACCES; 531da177e4SLinus Torvalds 541da177e4SLinus Torvalds if (*ppos) { 551da177e4SLinus Torvalds *lenp = 0; 561da177e4SLinus Torvalds return 0; 571da177e4SLinus Torvalds } 581da177e4SLinus Torvalds 591da177e4SLinus Torvalds for (dev = port->devices; dev ; dev = dev->next) { 601da177e4SLinus Torvalds if(dev == port->cad) { 611da177e4SLinus Torvalds len += sprintf(buffer, "%s\n", dev->name); 621da177e4SLinus Torvalds } 631da177e4SLinus Torvalds } 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds if(!len) { 661da177e4SLinus Torvalds len += sprintf(buffer, "%s\n", "none"); 671da177e4SLinus Torvalds } 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds if (len > *lenp) 701da177e4SLinus Torvalds len = *lenp; 711da177e4SLinus Torvalds else 721da177e4SLinus Torvalds *lenp = len; 731da177e4SLinus Torvalds 741da177e4SLinus Torvalds *ppos += len; 7532927393SChristoph Hellwig memcpy(result, buffer, len); 7632927393SChristoph Hellwig return 0; 771da177e4SLinus Torvalds } 781da177e4SLinus Torvalds 791da177e4SLinus Torvalds #ifdef CONFIG_PARPORT_1284 80be424c63SJoe Perches static int do_autoprobe(struct ctl_table *table, int write, 8132927393SChristoph Hellwig void *result, size_t *lenp, loff_t *ppos) 821da177e4SLinus Torvalds { 831da177e4SLinus Torvalds struct parport_device_info *info = table->extra2; 841da177e4SLinus Torvalds const char *str; 851da177e4SLinus Torvalds char buffer[256]; 861da177e4SLinus Torvalds int len = 0; 871da177e4SLinus Torvalds 881da177e4SLinus Torvalds if (write) /* permissions stop this */ 891da177e4SLinus Torvalds return -EACCES; 901da177e4SLinus Torvalds 911da177e4SLinus Torvalds if (*ppos) { 921da177e4SLinus Torvalds *lenp = 0; 931da177e4SLinus Torvalds return 0; 941da177e4SLinus Torvalds } 951da177e4SLinus Torvalds 961da177e4SLinus Torvalds if ((str = info->class_name) != NULL) 971da177e4SLinus Torvalds len += sprintf (buffer + len, "CLASS:%s;\n", str); 981da177e4SLinus Torvalds 991da177e4SLinus Torvalds if ((str = info->model) != NULL) 1001da177e4SLinus Torvalds len += sprintf (buffer + len, "MODEL:%s;\n", str); 1011da177e4SLinus Torvalds 1021da177e4SLinus Torvalds if ((str = info->mfr) != NULL) 1031da177e4SLinus Torvalds len += sprintf (buffer + len, "MANUFACTURER:%s;\n", str); 1041da177e4SLinus Torvalds 1051da177e4SLinus Torvalds if ((str = info->description) != NULL) 1061da177e4SLinus Torvalds len += sprintf (buffer + len, "DESCRIPTION:%s;\n", str); 1071da177e4SLinus Torvalds 1081da177e4SLinus Torvalds if ((str = info->cmdset) != NULL) 1091da177e4SLinus Torvalds len += sprintf (buffer + len, "COMMAND SET:%s;\n", str); 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds if (len > *lenp) 1121da177e4SLinus Torvalds len = *lenp; 1131da177e4SLinus Torvalds else 1141da177e4SLinus Torvalds *lenp = len; 1151da177e4SLinus Torvalds 1161da177e4SLinus Torvalds *ppos += len; 1171da177e4SLinus Torvalds 11832927393SChristoph Hellwig memcpy(result, buffer, len); 11932927393SChristoph Hellwig return 0; 1201da177e4SLinus Torvalds } 1211da177e4SLinus Torvalds #endif /* IEEE1284.3 support. */ 1221da177e4SLinus Torvalds 123be424c63SJoe Perches static int do_hardware_base_addr(struct ctl_table *table, int write, 12432927393SChristoph Hellwig void *result, size_t *lenp, loff_t *ppos) 1251da177e4SLinus Torvalds { 1261da177e4SLinus Torvalds struct parport *port = (struct parport *)table->extra1; 1271da177e4SLinus Torvalds char buffer[20]; 1281da177e4SLinus Torvalds int len = 0; 1291da177e4SLinus Torvalds 1301da177e4SLinus Torvalds if (*ppos) { 1311da177e4SLinus Torvalds *lenp = 0; 1321da177e4SLinus Torvalds return 0; 1331da177e4SLinus Torvalds } 1341da177e4SLinus Torvalds 1351da177e4SLinus Torvalds if (write) /* permissions prevent this anyway */ 1361da177e4SLinus Torvalds return -EACCES; 1371da177e4SLinus Torvalds 1381da177e4SLinus Torvalds len += sprintf (buffer, "%lu\t%lu\n", port->base, port->base_hi); 1391da177e4SLinus Torvalds 1401da177e4SLinus Torvalds if (len > *lenp) 1411da177e4SLinus Torvalds len = *lenp; 1421da177e4SLinus Torvalds else 1431da177e4SLinus Torvalds *lenp = len; 1441da177e4SLinus Torvalds 1451da177e4SLinus Torvalds *ppos += len; 14632927393SChristoph Hellwig memcpy(result, buffer, len); 14732927393SChristoph Hellwig return 0; 1481da177e4SLinus Torvalds } 1491da177e4SLinus Torvalds 150be424c63SJoe Perches static int do_hardware_irq(struct ctl_table *table, int write, 15132927393SChristoph Hellwig void *result, size_t *lenp, loff_t *ppos) 1521da177e4SLinus Torvalds { 1531da177e4SLinus Torvalds struct parport *port = (struct parport *)table->extra1; 1541da177e4SLinus Torvalds char buffer[20]; 1551da177e4SLinus Torvalds int len = 0; 1561da177e4SLinus Torvalds 1571da177e4SLinus Torvalds if (*ppos) { 1581da177e4SLinus Torvalds *lenp = 0; 1591da177e4SLinus Torvalds return 0; 1601da177e4SLinus Torvalds } 1611da177e4SLinus Torvalds 1621da177e4SLinus Torvalds if (write) /* permissions prevent this anyway */ 1631da177e4SLinus Torvalds return -EACCES; 1641da177e4SLinus Torvalds 1651da177e4SLinus Torvalds len += sprintf (buffer, "%d\n", port->irq); 1661da177e4SLinus Torvalds 1671da177e4SLinus Torvalds if (len > *lenp) 1681da177e4SLinus Torvalds len = *lenp; 1691da177e4SLinus Torvalds else 1701da177e4SLinus Torvalds *lenp = len; 1711da177e4SLinus Torvalds 1721da177e4SLinus Torvalds *ppos += len; 17332927393SChristoph Hellwig memcpy(result, buffer, len); 17432927393SChristoph Hellwig return 0; 1751da177e4SLinus Torvalds } 1761da177e4SLinus Torvalds 177be424c63SJoe Perches static int do_hardware_dma(struct ctl_table *table, int write, 17832927393SChristoph Hellwig void *result, size_t *lenp, loff_t *ppos) 1791da177e4SLinus Torvalds { 1801da177e4SLinus Torvalds struct parport *port = (struct parport *)table->extra1; 1811da177e4SLinus Torvalds char buffer[20]; 1821da177e4SLinus Torvalds int len = 0; 1831da177e4SLinus Torvalds 1841da177e4SLinus Torvalds if (*ppos) { 1851da177e4SLinus Torvalds *lenp = 0; 1861da177e4SLinus Torvalds return 0; 1871da177e4SLinus Torvalds } 1881da177e4SLinus Torvalds 1891da177e4SLinus Torvalds if (write) /* permissions prevent this anyway */ 1901da177e4SLinus Torvalds return -EACCES; 1911da177e4SLinus Torvalds 1921da177e4SLinus Torvalds len += sprintf (buffer, "%d\n", port->dma); 1931da177e4SLinus Torvalds 1941da177e4SLinus Torvalds if (len > *lenp) 1951da177e4SLinus Torvalds len = *lenp; 1961da177e4SLinus Torvalds else 1971da177e4SLinus Torvalds *lenp = len; 1981da177e4SLinus Torvalds 1991da177e4SLinus Torvalds *ppos += len; 20032927393SChristoph Hellwig memcpy(result, buffer, len); 20132927393SChristoph Hellwig return 0; 2021da177e4SLinus Torvalds } 2031da177e4SLinus Torvalds 204be424c63SJoe Perches static int do_hardware_modes(struct ctl_table *table, int write, 20532927393SChristoph Hellwig void *result, size_t *lenp, loff_t *ppos) 2061da177e4SLinus Torvalds { 2071da177e4SLinus Torvalds struct parport *port = (struct parport *)table->extra1; 2081da177e4SLinus Torvalds char buffer[40]; 2091da177e4SLinus Torvalds int len = 0; 2101da177e4SLinus Torvalds 2111da177e4SLinus Torvalds if (*ppos) { 2121da177e4SLinus Torvalds *lenp = 0; 2131da177e4SLinus Torvalds return 0; 2141da177e4SLinus Torvalds } 2151da177e4SLinus Torvalds 2161da177e4SLinus Torvalds if (write) /* permissions prevent this anyway */ 2171da177e4SLinus Torvalds return -EACCES; 2181da177e4SLinus Torvalds 2191da177e4SLinus Torvalds { 220a6abfdffSJoe Perches #define printmode(x) \ 221a6abfdffSJoe Perches do { \ 222a6abfdffSJoe Perches if (port->modes & PARPORT_MODE_##x) \ 223a6abfdffSJoe Perches len += sprintf(buffer + len, "%s%s", f++ ? "," : "", #x); \ 224a6abfdffSJoe Perches } while (0) 2251da177e4SLinus Torvalds int f = 0; 2261da177e4SLinus Torvalds printmode(PCSPP); 2271da177e4SLinus Torvalds printmode(TRISTATE); 2281da177e4SLinus Torvalds printmode(COMPAT); 2291da177e4SLinus Torvalds printmode(EPP); 2301da177e4SLinus Torvalds printmode(ECP); 2311da177e4SLinus Torvalds printmode(DMA); 2321da177e4SLinus Torvalds #undef printmode 2331da177e4SLinus Torvalds } 2341da177e4SLinus Torvalds buffer[len++] = '\n'; 2351da177e4SLinus Torvalds 2361da177e4SLinus Torvalds if (len > *lenp) 2371da177e4SLinus Torvalds len = *lenp; 2381da177e4SLinus Torvalds else 2391da177e4SLinus Torvalds *lenp = len; 2401da177e4SLinus Torvalds 2411da177e4SLinus Torvalds *ppos += len; 24232927393SChristoph Hellwig memcpy(result, buffer, len); 24332927393SChristoph Hellwig return 0; 2441da177e4SLinus Torvalds } 2451da177e4SLinus Torvalds 246894d2491SEric W. Biederman #define PARPORT_PORT_DIR(CHILD) { .procname = NULL, .mode = 0555, .child = CHILD } 247894d2491SEric W. Biederman #define PARPORT_PARPORT_DIR(CHILD) { .procname = "parport", \ 2482564b7bdSEric W. Biederman .mode = 0555, .child = CHILD } 249894d2491SEric W. Biederman #define PARPORT_DEV_DIR(CHILD) { .procname = "dev", .mode = 0555, .child = CHILD } 25025398a15SEric W. Biederman #define PARPORT_DEVICES_ROOT_DIR { .procname = "devices", \ 2512564b7bdSEric W. Biederman .mode = 0555, .child = NULL } 2521da177e4SLinus Torvalds 2531da177e4SLinus Torvalds static const unsigned long parport_min_timeslice_value = 2541da177e4SLinus Torvalds PARPORT_MIN_TIMESLICE_VALUE; 2551da177e4SLinus Torvalds 2561da177e4SLinus Torvalds static const unsigned long parport_max_timeslice_value = 2571da177e4SLinus Torvalds PARPORT_MAX_TIMESLICE_VALUE; 2581da177e4SLinus Torvalds 2591da177e4SLinus Torvalds static const int parport_min_spintime_value = 2601da177e4SLinus Torvalds PARPORT_MIN_SPINTIME_VALUE; 2611da177e4SLinus Torvalds 2621da177e4SLinus Torvalds static const int parport_max_spintime_value = 2631da177e4SLinus Torvalds PARPORT_MAX_SPINTIME_VALUE; 2641da177e4SLinus Torvalds 2651da177e4SLinus Torvalds 2661da177e4SLinus Torvalds struct parport_sysctl_table { 2671da177e4SLinus Torvalds struct ctl_table_header *sysctl_header; 268be424c63SJoe Perches struct ctl_table vars[12]; 269be424c63SJoe Perches struct ctl_table device_dir[2]; 2701da177e4SLinus Torvalds }; 2711da177e4SLinus Torvalds 2721da177e4SLinus Torvalds static const struct parport_sysctl_table parport_sysctl_template = { 2732564b7bdSEric W. Biederman .sysctl_header = NULL, 2741da177e4SLinus Torvalds { 2752564b7bdSEric W. Biederman { 2762564b7bdSEric W. Biederman .procname = "spintime", 2772564b7bdSEric W. Biederman .data = NULL, 2782564b7bdSEric W. Biederman .maxlen = sizeof(int), 2792564b7bdSEric W. Biederman .mode = 0644, 2806d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 2812564b7bdSEric W. Biederman .extra1 = (void*) &parport_min_spintime_value, 2822564b7bdSEric W. Biederman .extra2 = (void*) &parport_max_spintime_value 2832564b7bdSEric W. Biederman }, 2842564b7bdSEric W. Biederman { 2852564b7bdSEric W. Biederman .procname = "base-addr", 2862564b7bdSEric W. Biederman .data = NULL, 2872564b7bdSEric W. Biederman .maxlen = 0, 2882564b7bdSEric W. Biederman .mode = 0444, 2896d456111SEric W. Biederman .proc_handler = do_hardware_base_addr 2902564b7bdSEric W. Biederman }, 2912564b7bdSEric W. Biederman { 2922564b7bdSEric W. Biederman .procname = "irq", 2932564b7bdSEric W. Biederman .data = NULL, 2942564b7bdSEric W. Biederman .maxlen = 0, 2952564b7bdSEric W. Biederman .mode = 0444, 2966d456111SEric W. Biederman .proc_handler = do_hardware_irq 2972564b7bdSEric W. Biederman }, 2982564b7bdSEric W. Biederman { 2992564b7bdSEric W. Biederman .procname = "dma", 3002564b7bdSEric W. Biederman .data = NULL, 3012564b7bdSEric W. Biederman .maxlen = 0, 3022564b7bdSEric W. Biederman .mode = 0444, 3036d456111SEric W. Biederman .proc_handler = do_hardware_dma 3042564b7bdSEric W. Biederman }, 3052564b7bdSEric W. Biederman { 3062564b7bdSEric W. Biederman .procname = "modes", 3072564b7bdSEric W. Biederman .data = NULL, 3082564b7bdSEric W. Biederman .maxlen = 0, 3092564b7bdSEric W. Biederman .mode = 0444, 3106d456111SEric W. Biederman .proc_handler = do_hardware_modes 3112564b7bdSEric W. Biederman }, 3121da177e4SLinus Torvalds #ifdef CONFIG_PARPORT_1284 3132564b7bdSEric W. Biederman { 3142564b7bdSEric W. Biederman .procname = "autoprobe", 3152564b7bdSEric W. Biederman .data = NULL, 3162564b7bdSEric W. Biederman .maxlen = 0, 3172564b7bdSEric W. Biederman .mode = 0444, 3186d456111SEric W. Biederman .proc_handler = do_autoprobe 3191da177e4SLinus Torvalds }, 3202564b7bdSEric W. Biederman { 3212564b7bdSEric W. Biederman .procname = "autoprobe0", 3222564b7bdSEric W. Biederman .data = NULL, 3232564b7bdSEric W. Biederman .maxlen = 0, 3242564b7bdSEric W. Biederman .mode = 0444, 3256d456111SEric W. Biederman .proc_handler = do_autoprobe 3262564b7bdSEric W. Biederman }, 3272564b7bdSEric W. Biederman { 3282564b7bdSEric W. Biederman .procname = "autoprobe1", 3292564b7bdSEric W. Biederman .data = NULL, 3302564b7bdSEric W. Biederman .maxlen = 0, 3312564b7bdSEric W. Biederman .mode = 0444, 3326d456111SEric W. Biederman .proc_handler = do_autoprobe 3332564b7bdSEric W. Biederman }, 3342564b7bdSEric W. Biederman { 3352564b7bdSEric W. Biederman .procname = "autoprobe2", 3362564b7bdSEric W. Biederman .data = NULL, 3372564b7bdSEric W. Biederman .maxlen = 0, 3382564b7bdSEric W. Biederman .mode = 0444, 3396d456111SEric W. Biederman .proc_handler = do_autoprobe 3402564b7bdSEric W. Biederman }, 3412564b7bdSEric W. Biederman { 3422564b7bdSEric W. Biederman .procname = "autoprobe3", 3432564b7bdSEric W. Biederman .data = NULL, 3442564b7bdSEric W. Biederman .maxlen = 0, 3452564b7bdSEric W. Biederman .mode = 0444, 3466d456111SEric W. Biederman .proc_handler = do_autoprobe 3472564b7bdSEric W. Biederman }, 3482564b7bdSEric W. Biederman #endif /* IEEE 1284 support */ 3492564b7bdSEric W. Biederman {} 3502564b7bdSEric W. Biederman }, 3512564b7bdSEric W. Biederman { 3522564b7bdSEric W. Biederman { 3532564b7bdSEric W. Biederman .procname = "active", 3542564b7bdSEric W. Biederman .data = NULL, 3552564b7bdSEric W. Biederman .maxlen = 0, 3562564b7bdSEric W. Biederman .mode = 0444, 3576d456111SEric W. Biederman .proc_handler = do_active_device 3582564b7bdSEric W. Biederman }, 3592564b7bdSEric W. Biederman {} 3602564b7bdSEric W. Biederman }, 3611da177e4SLinus Torvalds }; 3621da177e4SLinus Torvalds 3631da177e4SLinus Torvalds struct parport_device_sysctl_table 3641da177e4SLinus Torvalds { 3651da177e4SLinus Torvalds struct ctl_table_header *sysctl_header; 366be424c63SJoe Perches struct ctl_table vars[2]; 367be424c63SJoe Perches struct ctl_table device_dir[2]; 368be424c63SJoe Perches struct ctl_table devices_root_dir[2]; 369be424c63SJoe Perches struct ctl_table port_dir[2]; 370be424c63SJoe Perches struct ctl_table parport_dir[2]; 371be424c63SJoe Perches struct ctl_table dev_dir[2]; 3721da177e4SLinus Torvalds }; 3731da177e4SLinus Torvalds 3741da177e4SLinus Torvalds static const struct parport_device_sysctl_table 3751da177e4SLinus Torvalds parport_device_sysctl_template = { 3762564b7bdSEric W. Biederman .sysctl_header = NULL, 3771da177e4SLinus Torvalds { 3782564b7bdSEric W. Biederman { 3792564b7bdSEric W. Biederman .procname = "timeslice", 3802564b7bdSEric W. Biederman .data = NULL, 38160af8803SEric Dumazet .maxlen = sizeof(unsigned long), 3822564b7bdSEric W. Biederman .mode = 0644, 3836d456111SEric W. Biederman .proc_handler = proc_doulongvec_ms_jiffies_minmax, 3842564b7bdSEric W. Biederman .extra1 = (void*) &parport_min_timeslice_value, 3852564b7bdSEric W. Biederman .extra2 = (void*) &parport_max_timeslice_value 3861da177e4SLinus Torvalds }, 3872564b7bdSEric W. Biederman }, 3882564b7bdSEric W. Biederman { 3892564b7bdSEric W. Biederman { 3902564b7bdSEric W. Biederman .procname = NULL, 3912564b7bdSEric W. Biederman .data = NULL, 3922564b7bdSEric W. Biederman .maxlen = 0, 3932564b7bdSEric W. Biederman .mode = 0555, 3942564b7bdSEric W. Biederman .child = NULL 3952564b7bdSEric W. Biederman }, 3962564b7bdSEric W. Biederman {} 3972564b7bdSEric W. Biederman }, 3982564b7bdSEric W. Biederman { 3992564b7bdSEric W. Biederman PARPORT_DEVICES_ROOT_DIR, 4002564b7bdSEric W. Biederman {} 4012564b7bdSEric W. Biederman }, 4022564b7bdSEric W. Biederman { 4032564b7bdSEric W. Biederman PARPORT_PORT_DIR(NULL), 4042564b7bdSEric W. Biederman {} 4052564b7bdSEric W. Biederman }, 4062564b7bdSEric W. Biederman { 4072564b7bdSEric W. Biederman PARPORT_PARPORT_DIR(NULL), 4082564b7bdSEric W. Biederman {} 4092564b7bdSEric W. Biederman }, 4102564b7bdSEric W. Biederman { 4112564b7bdSEric W. Biederman PARPORT_DEV_DIR(NULL), 4122564b7bdSEric W. Biederman {} 4132564b7bdSEric W. Biederman } 4141da177e4SLinus Torvalds }; 4151da177e4SLinus Torvalds 4161da177e4SLinus Torvalds struct parport_default_sysctl_table 4171da177e4SLinus Torvalds { 4181da177e4SLinus Torvalds struct ctl_table_header *sysctl_header; 419be424c63SJoe Perches struct ctl_table vars[3]; 420be424c63SJoe Perches struct ctl_table default_dir[2]; 421be424c63SJoe Perches struct ctl_table parport_dir[2]; 422be424c63SJoe Perches struct ctl_table dev_dir[2]; 4231da177e4SLinus Torvalds }; 4241da177e4SLinus Torvalds 4251da177e4SLinus Torvalds static struct parport_default_sysctl_table 4261da177e4SLinus Torvalds parport_default_sysctl_table = { 4272564b7bdSEric W. Biederman .sysctl_header = NULL, 4281da177e4SLinus Torvalds { 4292564b7bdSEric W. Biederman { 4302564b7bdSEric W. Biederman .procname = "timeslice", 4312564b7bdSEric W. Biederman .data = &parport_default_timeslice, 4322564b7bdSEric W. Biederman .maxlen = sizeof(parport_default_timeslice), 4332564b7bdSEric W. Biederman .mode = 0644, 4346d456111SEric W. Biederman .proc_handler = proc_doulongvec_ms_jiffies_minmax, 4352564b7bdSEric W. Biederman .extra1 = (void*) &parport_min_timeslice_value, 4362564b7bdSEric W. Biederman .extra2 = (void*) &parport_max_timeslice_value 4371da177e4SLinus Torvalds }, 4382564b7bdSEric W. Biederman { 4392564b7bdSEric W. Biederman .procname = "spintime", 4402564b7bdSEric W. Biederman .data = &parport_default_spintime, 4412564b7bdSEric W. Biederman .maxlen = sizeof(parport_default_spintime), 4422564b7bdSEric W. Biederman .mode = 0644, 4436d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 4442564b7bdSEric W. Biederman .extra1 = (void*) &parport_min_spintime_value, 4452564b7bdSEric W. Biederman .extra2 = (void*) &parport_max_spintime_value 4462564b7bdSEric W. Biederman }, 4472564b7bdSEric W. Biederman {} 4482564b7bdSEric W. Biederman }, 4492564b7bdSEric W. Biederman { 4502564b7bdSEric W. Biederman { 4512564b7bdSEric W. Biederman .procname = "default", 4522564b7bdSEric W. Biederman .mode = 0555, 4532564b7bdSEric W. Biederman .child = parport_default_sysctl_table.vars 4542564b7bdSEric W. Biederman }, 4552564b7bdSEric W. Biederman {} 4562564b7bdSEric W. Biederman }, 4571da177e4SLinus Torvalds { 4581da177e4SLinus Torvalds PARPORT_PARPORT_DIR(parport_default_sysctl_table.default_dir), 4592564b7bdSEric W. Biederman {} 4602564b7bdSEric W. Biederman }, 4612564b7bdSEric W. Biederman { 4622564b7bdSEric W. Biederman PARPORT_DEV_DIR(parport_default_sysctl_table.parport_dir), 4632564b7bdSEric W. Biederman {} 4642564b7bdSEric W. Biederman } 4651da177e4SLinus Torvalds }; 4661da177e4SLinus Torvalds 4671da177e4SLinus Torvalds int parport_proc_register(struct parport *port) 4681da177e4SLinus Torvalds { 4691da177e4SLinus Torvalds struct parport_sysctl_table *t; 470*93810936SJoel Granados struct ctl_table_header *devices_h; 471*93810936SJoel Granados char *tmp_dir_path; 472*93810936SJoel Granados size_t tmp_path_len, port_name_len; 473*93810936SJoel Granados int bytes_written, i, err = 0; 4741da177e4SLinus Torvalds 4752451a848SSilviu-Mihai Popescu t = kmemdup(&parport_sysctl_template, sizeof(*t), GFP_KERNEL); 4761da177e4SLinus Torvalds if (t == NULL) 4771da177e4SLinus Torvalds return -ENOMEM; 4781da177e4SLinus Torvalds 4791da177e4SLinus Torvalds t->device_dir[0].extra1 = port; 4801da177e4SLinus Torvalds 4811da177e4SLinus Torvalds t->vars[0].data = &port->spintime; 482*93810936SJoel Granados for (i = 0; i < 5; i++) { 483*93810936SJoel Granados t->vars[i].extra1 = port; 484*93810936SJoel Granados t->vars[5 + i].extra2 = &port->probe_info[i]; 4851da177e4SLinus Torvalds } 486*93810936SJoel Granados 487*93810936SJoel Granados port_name_len = strnlen(port->name, PARPORT_NAME_MAX_LEN); 488*93810936SJoel Granados /* 489*93810936SJoel Granados * Allocate a buffer for two paths: dev/parport/PORT and dev/parport/PORT/devices. 490*93810936SJoel Granados * We calculate for the second as that will give us enough for the first. 491*93810936SJoel Granados */ 492*93810936SJoel Granados tmp_path_len = PARPORT_BASE_DEVICES_PATH_SIZE + port_name_len; 493*93810936SJoel Granados tmp_dir_path = kzalloc(tmp_path_len, GFP_KERNEL); 494*93810936SJoel Granados if (!tmp_dir_path) { 495*93810936SJoel Granados err = -ENOMEM; 496*93810936SJoel Granados goto exit_free_t; 497*93810936SJoel Granados } 498*93810936SJoel Granados 499*93810936SJoel Granados bytes_written = snprintf(tmp_dir_path, tmp_path_len, 500*93810936SJoel Granados "dev/parport/%s/devices", port->name); 501*93810936SJoel Granados if (tmp_path_len <= bytes_written) { 502*93810936SJoel Granados err = -ENOENT; 503*93810936SJoel Granados goto exit_free_tmp_dir_path; 504*93810936SJoel Granados } 505*93810936SJoel Granados devices_h = register_sysctl(tmp_dir_path, t->device_dir); 506*93810936SJoel Granados if (devices_h == NULL) { 507*93810936SJoel Granados err = -ENOENT; 508*93810936SJoel Granados goto exit_free_tmp_dir_path; 509*93810936SJoel Granados } 510*93810936SJoel Granados 511*93810936SJoel Granados tmp_path_len = PARPORT_BASE_PATH_SIZE + port_name_len; 512*93810936SJoel Granados bytes_written = snprintf(tmp_dir_path, tmp_path_len, 513*93810936SJoel Granados "dev/parport/%s", port->name); 514*93810936SJoel Granados if (tmp_path_len <= bytes_written) { 515*93810936SJoel Granados err = -ENOENT; 516*93810936SJoel Granados goto unregister_devices_h; 517*93810936SJoel Granados } 518*93810936SJoel Granados 519*93810936SJoel Granados t->sysctl_header = register_sysctl(tmp_dir_path, t->vars); 520*93810936SJoel Granados if (t->sysctl_header == NULL) { 521*93810936SJoel Granados err = -ENOENT; 522*93810936SJoel Granados goto unregister_devices_h; 523*93810936SJoel Granados } 524*93810936SJoel Granados 5251da177e4SLinus Torvalds port->sysctl_table = t; 526*93810936SJoel Granados 527*93810936SJoel Granados kfree(tmp_dir_path); 5281da177e4SLinus Torvalds return 0; 529*93810936SJoel Granados 530*93810936SJoel Granados unregister_devices_h: 531*93810936SJoel Granados unregister_sysctl_table(devices_h); 532*93810936SJoel Granados 533*93810936SJoel Granados exit_free_tmp_dir_path: 534*93810936SJoel Granados kfree(tmp_dir_path); 535*93810936SJoel Granados 536*93810936SJoel Granados exit_free_t: 537*93810936SJoel Granados kfree(t); 538*93810936SJoel Granados return err; 5391da177e4SLinus Torvalds } 5401da177e4SLinus Torvalds 5411da177e4SLinus Torvalds int parport_proc_unregister(struct parport *port) 5421da177e4SLinus Torvalds { 5431da177e4SLinus Torvalds if (port->sysctl_table) { 5441da177e4SLinus Torvalds struct parport_sysctl_table *t = port->sysctl_table; 5451da177e4SLinus Torvalds port->sysctl_table = NULL; 5461da177e4SLinus Torvalds unregister_sysctl_table(t->sysctl_header); 5471da177e4SLinus Torvalds kfree(t); 5481da177e4SLinus Torvalds } 5491da177e4SLinus Torvalds return 0; 5501da177e4SLinus Torvalds } 5511da177e4SLinus Torvalds 5521da177e4SLinus Torvalds int parport_device_proc_register(struct pardevice *device) 5531da177e4SLinus Torvalds { 5541da177e4SLinus Torvalds struct parport_device_sysctl_table *t; 5551da177e4SLinus Torvalds struct parport * port = device->port; 5561da177e4SLinus Torvalds 5572451a848SSilviu-Mihai Popescu t = kmemdup(&parport_device_sysctl_template, sizeof(*t), GFP_KERNEL); 5581da177e4SLinus Torvalds if (t == NULL) 5591da177e4SLinus Torvalds return -ENOMEM; 5601da177e4SLinus Torvalds 5611da177e4SLinus Torvalds t->dev_dir[0].child = t->parport_dir; 5621da177e4SLinus Torvalds t->parport_dir[0].child = t->port_dir; 5631da177e4SLinus Torvalds t->port_dir[0].procname = port->name; 5641da177e4SLinus Torvalds t->port_dir[0].child = t->devices_root_dir; 5651da177e4SLinus Torvalds t->devices_root_dir[0].child = t->device_dir; 5661da177e4SLinus Torvalds 5671da177e4SLinus Torvalds t->device_dir[0].procname = device->name; 5681da177e4SLinus Torvalds t->device_dir[0].child = t->vars; 5691da177e4SLinus Torvalds t->vars[0].data = &device->timeslice; 5701da177e4SLinus Torvalds 5710b4d4147SEric W. Biederman t->sysctl_header = register_sysctl_table(t->dev_dir); 5721da177e4SLinus Torvalds if (t->sysctl_header == NULL) { 5731da177e4SLinus Torvalds kfree(t); 5741da177e4SLinus Torvalds t = NULL; 5751da177e4SLinus Torvalds } 5761da177e4SLinus Torvalds device->sysctl_table = t; 5771da177e4SLinus Torvalds return 0; 5781da177e4SLinus Torvalds } 5791da177e4SLinus Torvalds 5801da177e4SLinus Torvalds int parport_device_proc_unregister(struct pardevice *device) 5811da177e4SLinus Torvalds { 5821da177e4SLinus Torvalds if (device->sysctl_table) { 5831da177e4SLinus Torvalds struct parport_device_sysctl_table *t = device->sysctl_table; 5841da177e4SLinus Torvalds device->sysctl_table = NULL; 5851da177e4SLinus Torvalds unregister_sysctl_table(t->sysctl_header); 5861da177e4SLinus Torvalds kfree(t); 5871da177e4SLinus Torvalds } 5881da177e4SLinus Torvalds return 0; 5891da177e4SLinus Torvalds } 5901da177e4SLinus Torvalds 5911da177e4SLinus Torvalds static int __init parport_default_proc_register(void) 5921da177e4SLinus Torvalds { 5936fa45a22SSudip Mukherjee int ret; 5946fa45a22SSudip Mukherjee 5951da177e4SLinus Torvalds parport_default_sysctl_table.sysctl_header = 5960b4d4147SEric W. Biederman register_sysctl_table(parport_default_sysctl_table.dev_dir); 5976fa45a22SSudip Mukherjee if (!parport_default_sysctl_table.sysctl_header) 5986fa45a22SSudip Mukherjee return -ENOMEM; 5996fa45a22SSudip Mukherjee ret = parport_bus_init(); 6006fa45a22SSudip Mukherjee if (ret) { 6016fa45a22SSudip Mukherjee unregister_sysctl_table(parport_default_sysctl_table. 6026fa45a22SSudip Mukherjee sysctl_header); 6036fa45a22SSudip Mukherjee return ret; 6046fa45a22SSudip Mukherjee } 6051da177e4SLinus Torvalds return 0; 6061da177e4SLinus Torvalds } 6071da177e4SLinus Torvalds 6081da177e4SLinus Torvalds static void __exit parport_default_proc_unregister(void) 6091da177e4SLinus Torvalds { 6101da177e4SLinus Torvalds if (parport_default_sysctl_table.sysctl_header) { 6111da177e4SLinus Torvalds unregister_sysctl_table(parport_default_sysctl_table. 6121da177e4SLinus Torvalds sysctl_header); 6131da177e4SLinus Torvalds parport_default_sysctl_table.sysctl_header = NULL; 6141da177e4SLinus Torvalds } 6156fa45a22SSudip Mukherjee parport_bus_exit(); 6161da177e4SLinus Torvalds } 6171da177e4SLinus Torvalds 6181da177e4SLinus Torvalds #else /* no sysctl or no procfs*/ 6191da177e4SLinus Torvalds 6201da177e4SLinus Torvalds int parport_proc_register(struct parport *pp) 6211da177e4SLinus Torvalds { 6221da177e4SLinus Torvalds return 0; 6231da177e4SLinus Torvalds } 6241da177e4SLinus Torvalds 6251da177e4SLinus Torvalds int parport_proc_unregister(struct parport *pp) 6261da177e4SLinus Torvalds { 6271da177e4SLinus Torvalds return 0; 6281da177e4SLinus Torvalds } 6291da177e4SLinus Torvalds 6301da177e4SLinus Torvalds int parport_device_proc_register(struct pardevice *device) 6311da177e4SLinus Torvalds { 6321da177e4SLinus Torvalds return 0; 6331da177e4SLinus Torvalds } 6341da177e4SLinus Torvalds 6351da177e4SLinus Torvalds int parport_device_proc_unregister(struct pardevice *device) 6361da177e4SLinus Torvalds { 6371da177e4SLinus Torvalds return 0; 6381da177e4SLinus Torvalds } 6391da177e4SLinus Torvalds 6401da177e4SLinus Torvalds static int __init parport_default_proc_register (void) 6411da177e4SLinus Torvalds { 6426fa45a22SSudip Mukherjee return parport_bus_init(); 6431da177e4SLinus Torvalds } 6441da177e4SLinus Torvalds 6451da177e4SLinus Torvalds static void __exit parport_default_proc_unregister (void) 6461da177e4SLinus Torvalds { 6476fa45a22SSudip Mukherjee parport_bus_exit(); 6481da177e4SLinus Torvalds } 6491da177e4SLinus Torvalds #endif 6501da177e4SLinus Torvalds 651bbca503bSSudip Mukherjee subsys_initcall(parport_default_proc_register) 6521da177e4SLinus Torvalds module_exit(parport_default_proc_unregister) 653