Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * interface.c - contains everything related to the user interface |
| 4 | * |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 5 | * Some code, especially possible resource dumping is based on isapnp_proc.c (c) Jaroslav Kysela <perex@perex.cz> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * Copyright 2002 Adam Belay <ambx1@neo.rr.com> |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 7 | * Copyright (C) 2008 Hewlett-Packard Development Company, L.P. |
| 8 | * Bjorn Helgaas <bjorn.helgaas@hp.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <linux/pnp.h> |
| 12 | #include <linux/string.h> |
| 13 | #include <linux/errno.h> |
| 14 | #include <linux/list.h> |
| 15 | #include <linux/types.h> |
| 16 | #include <linux/stat.h> |
| 17 | #include <linux/ctype.h> |
| 18 | #include <linux/slab.h> |
Daniel Walker | b3bd86e | 2008-02-06 01:40:04 -0800 | [diff] [blame] | 19 | #include <linux/mutex.h> |
| 20 | |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 21 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 23 | #include "base.h" |
| 24 | |
| 25 | struct pnp_info_buffer { |
| 26 | char *buffer; /* pointer to begin of buffer */ |
| 27 | char *curr; /* current position in buffer */ |
| 28 | unsigned long size; /* current size */ |
| 29 | unsigned long len; /* total length of buffer */ |
| 30 | int stop; /* stop flag */ |
| 31 | int error; /* error code */ |
| 32 | }; |
| 33 | |
| 34 | typedef struct pnp_info_buffer pnp_info_buffer_t; |
| 35 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 36 | static int pnp_printf(pnp_info_buffer_t * buffer, char *fmt, ...) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | { |
| 38 | va_list args; |
| 39 | int res; |
| 40 | |
| 41 | if (buffer->stop || buffer->error) |
| 42 | return 0; |
| 43 | va_start(args, fmt); |
| 44 | res = vsnprintf(buffer->curr, buffer->len - buffer->size, fmt, args); |
| 45 | va_end(args); |
| 46 | if (buffer->size + res >= buffer->len) { |
| 47 | buffer->stop = 1; |
| 48 | return 0; |
| 49 | } |
| 50 | buffer->curr += res; |
| 51 | buffer->size += res; |
| 52 | return res; |
| 53 | } |
| 54 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 55 | static void pnp_print_port(pnp_info_buffer_t * buffer, char *space, |
| 56 | struct pnp_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { |
Bjorn Helgaas | 169aaff | 2008-06-27 16:57:06 -0600 | [diff] [blame] | 58 | pnp_printf(buffer, "%sport %#llx-%#llx, align %#llx, size %#llx, " |
| 59 | "%i-bit address decoding\n", space, |
| 60 | (unsigned long long) port->min, |
| 61 | (unsigned long long) port->max, |
| 62 | port->align ? ((unsigned long long) port->align - 1) : 0, |
| 63 | (unsigned long long) port->size, |
Bjorn Helgaas | 08c9f26 | 2008-06-27 16:57:03 -0600 | [diff] [blame] | 64 | port->flags & IORESOURCE_IO_16BIT_ADDR ? 16 : 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 67 | static void pnp_print_irq(pnp_info_buffer_t * buffer, char *space, |
| 68 | struct pnp_irq *irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | { |
| 70 | int first = 1, i; |
| 71 | |
| 72 | pnp_printf(buffer, "%sirq ", space); |
| 73 | for (i = 0; i < PNP_IRQ_NR; i++) |
Bjorn Helgaas | 7aefff5 | 2008-06-27 16:57:05 -0600 | [diff] [blame] | 74 | if (test_bit(i, irq->map.bits)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | if (!first) { |
| 76 | pnp_printf(buffer, ","); |
| 77 | } else { |
| 78 | first = 0; |
| 79 | } |
| 80 | if (i == 2 || i == 9) |
| 81 | pnp_printf(buffer, "2/9"); |
| 82 | else |
| 83 | pnp_printf(buffer, "%i", i); |
| 84 | } |
Bjorn Helgaas | 7aefff5 | 2008-06-27 16:57:05 -0600 | [diff] [blame] | 85 | if (bitmap_empty(irq->map.bits, PNP_IRQ_NR)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | pnp_printf(buffer, "<none>"); |
| 87 | if (irq->flags & IORESOURCE_IRQ_HIGHEDGE) |
| 88 | pnp_printf(buffer, " High-Edge"); |
| 89 | if (irq->flags & IORESOURCE_IRQ_LOWEDGE) |
| 90 | pnp_printf(buffer, " Low-Edge"); |
| 91 | if (irq->flags & IORESOURCE_IRQ_HIGHLEVEL) |
| 92 | pnp_printf(buffer, " High-Level"); |
| 93 | if (irq->flags & IORESOURCE_IRQ_LOWLEVEL) |
| 94 | pnp_printf(buffer, " Low-Level"); |
Bjorn Helgaas | d5ebde6 | 2008-06-27 16:57:14 -0600 | [diff] [blame] | 95 | if (irq->flags & IORESOURCE_IRQ_OPTIONAL) |
| 96 | pnp_printf(buffer, " (optional)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | pnp_printf(buffer, "\n"); |
| 98 | } |
| 99 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 100 | static void pnp_print_dma(pnp_info_buffer_t * buffer, char *space, |
| 101 | struct pnp_dma *dma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | { |
| 103 | int first = 1, i; |
| 104 | char *s; |
| 105 | |
| 106 | pnp_printf(buffer, "%sdma ", space); |
| 107 | for (i = 0; i < 8; i++) |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 108 | if (dma->map & (1 << i)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | if (!first) { |
| 110 | pnp_printf(buffer, ","); |
| 111 | } else { |
| 112 | first = 0; |
| 113 | } |
| 114 | pnp_printf(buffer, "%i", i); |
| 115 | } |
| 116 | if (!dma->map) |
| 117 | pnp_printf(buffer, "<none>"); |
| 118 | switch (dma->flags & IORESOURCE_DMA_TYPE_MASK) { |
| 119 | case IORESOURCE_DMA_8BIT: |
| 120 | s = "8-bit"; |
| 121 | break; |
| 122 | case IORESOURCE_DMA_8AND16BIT: |
| 123 | s = "8-bit&16-bit"; |
| 124 | break; |
| 125 | default: |
| 126 | s = "16-bit"; |
| 127 | } |
| 128 | pnp_printf(buffer, " %s", s); |
| 129 | if (dma->flags & IORESOURCE_DMA_MASTER) |
| 130 | pnp_printf(buffer, " master"); |
| 131 | if (dma->flags & IORESOURCE_DMA_BYTE) |
| 132 | pnp_printf(buffer, " byte-count"); |
| 133 | if (dma->flags & IORESOURCE_DMA_WORD) |
| 134 | pnp_printf(buffer, " word-count"); |
| 135 | switch (dma->flags & IORESOURCE_DMA_SPEED_MASK) { |
| 136 | case IORESOURCE_DMA_TYPEA: |
| 137 | s = "type-A"; |
| 138 | break; |
| 139 | case IORESOURCE_DMA_TYPEB: |
| 140 | s = "type-B"; |
| 141 | break; |
| 142 | case IORESOURCE_DMA_TYPEF: |
| 143 | s = "type-F"; |
| 144 | break; |
| 145 | default: |
| 146 | s = "compatible"; |
| 147 | break; |
| 148 | } |
| 149 | pnp_printf(buffer, " %s\n", s); |
| 150 | } |
| 151 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 152 | static void pnp_print_mem(pnp_info_buffer_t * buffer, char *space, |
| 153 | struct pnp_mem *mem) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | { |
| 155 | char *s; |
| 156 | |
Bjorn Helgaas | 169aaff | 2008-06-27 16:57:06 -0600 | [diff] [blame] | 157 | pnp_printf(buffer, "%sMemory %#llx-%#llx, align %#llx, size %#llx", |
| 158 | space, (unsigned long long) mem->min, |
| 159 | (unsigned long long) mem->max, |
| 160 | (unsigned long long) mem->align, |
| 161 | (unsigned long long) mem->size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | if (mem->flags & IORESOURCE_MEM_WRITEABLE) |
| 163 | pnp_printf(buffer, ", writeable"); |
| 164 | if (mem->flags & IORESOURCE_MEM_CACHEABLE) |
| 165 | pnp_printf(buffer, ", cacheable"); |
| 166 | if (mem->flags & IORESOURCE_MEM_RANGELENGTH) |
| 167 | pnp_printf(buffer, ", range-length"); |
| 168 | if (mem->flags & IORESOURCE_MEM_SHADOWABLE) |
| 169 | pnp_printf(buffer, ", shadowable"); |
| 170 | if (mem->flags & IORESOURCE_MEM_EXPANSIONROM) |
| 171 | pnp_printf(buffer, ", expansion ROM"); |
| 172 | switch (mem->flags & IORESOURCE_MEM_TYPE_MASK) { |
| 173 | case IORESOURCE_MEM_8BIT: |
| 174 | s = "8-bit"; |
| 175 | break; |
| 176 | case IORESOURCE_MEM_8AND16BIT: |
| 177 | s = "8-bit&16-bit"; |
| 178 | break; |
| 179 | case IORESOURCE_MEM_32BIT: |
| 180 | s = "32-bit"; |
| 181 | break; |
| 182 | default: |
| 183 | s = "16-bit"; |
| 184 | } |
| 185 | pnp_printf(buffer, ", %s\n", s); |
| 186 | } |
| 187 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 188 | static void pnp_print_option(pnp_info_buffer_t * buffer, char *space, |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 189 | struct pnp_option *option) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | { |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 191 | switch (option->type) { |
| 192 | case IORESOURCE_IO: |
| 193 | pnp_print_port(buffer, space, &option->u.port); |
| 194 | break; |
| 195 | case IORESOURCE_MEM: |
| 196 | pnp_print_mem(buffer, space, &option->u.mem); |
| 197 | break; |
| 198 | case IORESOURCE_IRQ: |
| 199 | pnp_print_irq(buffer, space, &option->u.irq); |
| 200 | break; |
| 201 | case IORESOURCE_DMA: |
| 202 | pnp_print_dma(buffer, space, &option->u.dma); |
| 203 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Greg Kroah-Hartman | 2df4390 | 2013-10-06 23:55:42 -0700 | [diff] [blame] | 207 | static ssize_t options_show(struct device *dmdev, struct device_attribute *attr, |
| 208 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | { |
| 210 | struct pnp_dev *dev = to_pnp_dev(dmdev); |
Bjorn Helgaas | b72ee1f1 | 2008-06-27 16:57:02 -0600 | [diff] [blame] | 211 | pnp_info_buffer_t *buffer; |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 212 | struct pnp_option *option; |
| 213 | int ret, dep = 0, set = 0; |
| 214 | char *indent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
Bjorn Helgaas | b72ee1f1 | 2008-06-27 16:57:02 -0600 | [diff] [blame] | 216 | buffer = pnp_alloc(sizeof(pnp_info_buffer_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | if (!buffer) |
| 218 | return -ENOMEM; |
| 219 | |
| 220 | buffer->len = PAGE_SIZE; |
| 221 | buffer->buffer = buf; |
| 222 | buffer->curr = buffer->buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 224 | list_for_each_entry(option, &dev->options, list) { |
| 225 | if (pnp_option_is_dependent(option)) { |
| 226 | indent = " "; |
| 227 | if (!dep || pnp_option_set(option) != set) { |
| 228 | set = pnp_option_set(option); |
| 229 | dep = 1; |
| 230 | pnp_printf(buffer, "Dependent: %02i - " |
| 231 | "Priority %s\n", set, |
| 232 | pnp_option_priority_name(option)); |
| 233 | } |
| 234 | } else { |
| 235 | dep = 0; |
| 236 | indent = ""; |
| 237 | } |
| 238 | pnp_print_option(buffer, indent, option); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | } |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 240 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | ret = (buffer->curr - buf); |
| 242 | kfree(buffer); |
| 243 | return ret; |
| 244 | } |
Greg Kroah-Hartman | 2df4390 | 2013-10-06 23:55:42 -0700 | [diff] [blame] | 245 | static DEVICE_ATTR_RO(options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
Greg Kroah-Hartman | 2df4390 | 2013-10-06 23:55:42 -0700 | [diff] [blame] | 247 | static ssize_t resources_show(struct device *dmdev, |
| 248 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | { |
| 250 | struct pnp_dev *dev = to_pnp_dev(dmdev); |
Bjorn Helgaas | b72ee1f1 | 2008-06-27 16:57:02 -0600 | [diff] [blame] | 251 | pnp_info_buffer_t *buffer; |
Bjorn Helgaas | f61ed7e | 2008-06-27 16:57:00 -0600 | [diff] [blame] | 252 | struct pnp_resource *pnp_res; |
Bjorn Helgaas | 95ab366 | 2008-04-28 16:34:26 -0600 | [diff] [blame] | 253 | struct resource *res; |
Bjorn Helgaas | f61ed7e | 2008-06-27 16:57:00 -0600 | [diff] [blame] | 254 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
| 256 | if (!dev) |
| 257 | return -EINVAL; |
| 258 | |
Bjorn Helgaas | b72ee1f1 | 2008-06-27 16:57:02 -0600 | [diff] [blame] | 259 | buffer = pnp_alloc(sizeof(pnp_info_buffer_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | if (!buffer) |
| 261 | return -ENOMEM; |
Bjorn Helgaas | b72ee1f1 | 2008-06-27 16:57:02 -0600 | [diff] [blame] | 262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | buffer->len = PAGE_SIZE; |
| 264 | buffer->buffer = buf; |
| 265 | buffer->curr = buffer->buffer; |
| 266 | |
Bjorn Helgaas | f61ed7e | 2008-06-27 16:57:00 -0600 | [diff] [blame] | 267 | pnp_printf(buffer, "state = %s\n", dev->active ? "active" : "disabled"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
Bjorn Helgaas | f61ed7e | 2008-06-27 16:57:00 -0600 | [diff] [blame] | 269 | list_for_each_entry(pnp_res, &dev->resources, list) { |
| 270 | res = &pnp_res->res; |
| 271 | |
| 272 | pnp_printf(buffer, pnp_resource_type_name(res)); |
| 273 | |
| 274 | if (res->flags & IORESOURCE_DISABLED) { |
Bjorn Helgaas | aee3ad8 | 2008-06-27 16:56:57 -0600 | [diff] [blame] | 275 | pnp_printf(buffer, " disabled\n"); |
Bjorn Helgaas | f61ed7e | 2008-06-27 16:57:00 -0600 | [diff] [blame] | 276 | continue; |
| 277 | } |
| 278 | |
| 279 | switch (pnp_resource_type(res)) { |
| 280 | case IORESOURCE_IO: |
| 281 | case IORESOURCE_MEM: |
Bjorn Helgaas | 7e0e9c0 | 2010-03-05 10:47:57 -0700 | [diff] [blame] | 282 | case IORESOURCE_BUS: |
Bjorn Helgaas | fa35b492 | 2010-03-05 10:47:52 -0700 | [diff] [blame] | 283 | pnp_printf(buffer, " %#llx-%#llx%s\n", |
Bjorn Helgaas | aee3ad8 | 2008-06-27 16:56:57 -0600 | [diff] [blame] | 284 | (unsigned long long) res->start, |
Bjorn Helgaas | fa35b492 | 2010-03-05 10:47:52 -0700 | [diff] [blame] | 285 | (unsigned long long) res->end, |
| 286 | res->flags & IORESOURCE_WINDOW ? |
| 287 | " window" : ""); |
Bjorn Helgaas | f61ed7e | 2008-06-27 16:57:00 -0600 | [diff] [blame] | 288 | break; |
| 289 | case IORESOURCE_IRQ: |
| 290 | case IORESOURCE_DMA: |
Bjorn Helgaas | aee3ad8 | 2008-06-27 16:56:57 -0600 | [diff] [blame] | 291 | pnp_printf(buffer, " %lld\n", |
| 292 | (unsigned long long) res->start); |
Bjorn Helgaas | f61ed7e | 2008-06-27 16:57:00 -0600 | [diff] [blame] | 293 | break; |
| 294 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | } |
Bjorn Helgaas | f61ed7e | 2008-06-27 16:57:00 -0600 | [diff] [blame] | 296 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | ret = (buffer->curr - buf); |
| 298 | kfree(buffer); |
| 299 | return ret; |
| 300 | } |
| 301 | |
Witold Szczeponik | c937766 | 2012-12-15 01:00:14 +0100 | [diff] [blame] | 302 | static char *pnp_get_resource_value(char *buf, |
| 303 | unsigned long type, |
| 304 | resource_size_t *start, |
| 305 | resource_size_t *end, |
| 306 | unsigned long *flags) |
| 307 | { |
| 308 | if (start) |
| 309 | *start = 0; |
| 310 | if (end) |
| 311 | *end = 0; |
| 312 | if (flags) |
| 313 | *flags = 0; |
| 314 | |
| 315 | /* TBD: allow for disabled resources */ |
| 316 | |
| 317 | buf = skip_spaces(buf); |
| 318 | if (start) { |
| 319 | *start = simple_strtoull(buf, &buf, 0); |
| 320 | if (end) { |
| 321 | buf = skip_spaces(buf); |
| 322 | if (*buf == '-') { |
| 323 | buf = skip_spaces(buf + 1); |
| 324 | *end = simple_strtoull(buf, &buf, 0); |
| 325 | } else |
| 326 | *end = *start; |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | /* TBD: allow for additional flags, e.g., IORESOURCE_WINDOW */ |
| 331 | |
| 332 | return buf; |
| 333 | } |
| 334 | |
Greg Kroah-Hartman | 2df4390 | 2013-10-06 23:55:42 -0700 | [diff] [blame] | 335 | static ssize_t resources_store(struct device *dmdev, |
| 336 | struct device_attribute *attr, const char *ubuf, |
| 337 | size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | { |
| 339 | struct pnp_dev *dev = to_pnp_dev(dmdev); |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 340 | char *buf = (void *)ubuf; |
| 341 | int retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
| 343 | if (dev->status & PNP_ATTACHED) { |
| 344 | retval = -EBUSY; |
Bjorn Helgaas | a05d078 | 2007-10-16 23:31:10 -0700 | [diff] [blame] | 345 | dev_info(&dev->dev, "in use; can't configure\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | goto done; |
| 347 | } |
| 348 | |
André Goddard Rosa | e7d2860 | 2009-12-14 18:01:06 -0800 | [diff] [blame] | 349 | buf = skip_spaces(buf); |
Rasmus Villemoes | 7fb1cab | 2014-10-13 15:54:54 -0700 | [diff] [blame] | 350 | if (!strncasecmp(buf, "disable", 7)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | retval = pnp_disable_dev(dev); |
| 352 | goto done; |
| 353 | } |
Rasmus Villemoes | 7fb1cab | 2014-10-13 15:54:54 -0700 | [diff] [blame] | 354 | if (!strncasecmp(buf, "activate", 8)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | retval = pnp_activate_dev(dev); |
| 356 | goto done; |
| 357 | } |
Rasmus Villemoes | 7fb1cab | 2014-10-13 15:54:54 -0700 | [diff] [blame] | 358 | if (!strncasecmp(buf, "fill", 4)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | if (dev->active) |
| 360 | goto done; |
| 361 | retval = pnp_auto_config_dev(dev); |
| 362 | goto done; |
| 363 | } |
Rasmus Villemoes | 7fb1cab | 2014-10-13 15:54:54 -0700 | [diff] [blame] | 364 | if (!strncasecmp(buf, "auto", 4)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | if (dev->active) |
| 366 | goto done; |
Bjorn Helgaas | f449000 | 2008-04-28 16:34:09 -0600 | [diff] [blame] | 367 | pnp_init_resources(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | retval = pnp_auto_config_dev(dev); |
| 369 | goto done; |
| 370 | } |
Rasmus Villemoes | 7fb1cab | 2014-10-13 15:54:54 -0700 | [diff] [blame] | 371 | if (!strncasecmp(buf, "clear", 5)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | if (dev->active) |
| 373 | goto done; |
Bjorn Helgaas | f449000 | 2008-04-28 16:34:09 -0600 | [diff] [blame] | 374 | pnp_init_resources(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | goto done; |
| 376 | } |
Rasmus Villemoes | 7fb1cab | 2014-10-13 15:54:54 -0700 | [diff] [blame] | 377 | if (!strncasecmp(buf, "get", 3)) { |
Daniel Walker | b3bd86e | 2008-02-06 01:40:04 -0800 | [diff] [blame] | 378 | mutex_lock(&pnp_res_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | if (pnp_can_read(dev)) |
Bjorn Helgaas | 59284cb | 2008-04-28 16:34:05 -0600 | [diff] [blame] | 380 | dev->protocol->get(dev); |
Daniel Walker | b3bd86e | 2008-02-06 01:40:04 -0800 | [diff] [blame] | 381 | mutex_unlock(&pnp_res_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | goto done; |
| 383 | } |
Rasmus Villemoes | 7fb1cab | 2014-10-13 15:54:54 -0700 | [diff] [blame] | 384 | if (!strncasecmp(buf, "set", 3)) { |
Witold Szczeponik | c937766 | 2012-12-15 01:00:14 +0100 | [diff] [blame] | 385 | resource_size_t start; |
| 386 | resource_size_t end; |
| 387 | unsigned long flags; |
| 388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | if (dev->active) |
| 390 | goto done; |
| 391 | buf += 3; |
Bjorn Helgaas | f449000 | 2008-04-28 16:34:09 -0600 | [diff] [blame] | 392 | pnp_init_resources(dev); |
Daniel Walker | b3bd86e | 2008-02-06 01:40:04 -0800 | [diff] [blame] | 393 | mutex_lock(&pnp_res_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | while (1) { |
André Goddard Rosa | e7d2860 | 2009-12-14 18:01:06 -0800 | [diff] [blame] | 395 | buf = skip_spaces(buf); |
Rasmus Villemoes | 7fb1cab | 2014-10-13 15:54:54 -0700 | [diff] [blame] | 396 | if (!strncasecmp(buf, "io", 2)) { |
Witold Szczeponik | c937766 | 2012-12-15 01:00:14 +0100 | [diff] [blame] | 397 | buf = pnp_get_resource_value(buf + 2, |
| 398 | IORESOURCE_IO, |
| 399 | &start, &end, |
| 400 | &flags); |
| 401 | pnp_add_io_resource(dev, start, end, flags); |
Rasmus Villemoes | 7fb1cab | 2014-10-13 15:54:54 -0700 | [diff] [blame] | 402 | } else if (!strncasecmp(buf, "mem", 3)) { |
Witold Szczeponik | c937766 | 2012-12-15 01:00:14 +0100 | [diff] [blame] | 403 | buf = pnp_get_resource_value(buf + 3, |
| 404 | IORESOURCE_MEM, |
| 405 | &start, &end, |
| 406 | &flags); |
| 407 | pnp_add_mem_resource(dev, start, end, flags); |
Rasmus Villemoes | 7fb1cab | 2014-10-13 15:54:54 -0700 | [diff] [blame] | 408 | } else if (!strncasecmp(buf, "irq", 3)) { |
Witold Szczeponik | c937766 | 2012-12-15 01:00:14 +0100 | [diff] [blame] | 409 | buf = pnp_get_resource_value(buf + 3, |
| 410 | IORESOURCE_IRQ, |
| 411 | &start, NULL, |
| 412 | &flags); |
| 413 | pnp_add_irq_resource(dev, start, flags); |
Rasmus Villemoes | 7fb1cab | 2014-10-13 15:54:54 -0700 | [diff] [blame] | 414 | } else if (!strncasecmp(buf, "dma", 3)) { |
Witold Szczeponik | c937766 | 2012-12-15 01:00:14 +0100 | [diff] [blame] | 415 | buf = pnp_get_resource_value(buf + 3, |
| 416 | IORESOURCE_DMA, |
| 417 | &start, NULL, |
| 418 | &flags); |
| 419 | pnp_add_dma_resource(dev, start, flags); |
Rasmus Villemoes | 7fb1cab | 2014-10-13 15:54:54 -0700 | [diff] [blame] | 420 | } else if (!strncasecmp(buf, "bus", 3)) { |
Witold Szczeponik | c937766 | 2012-12-15 01:00:14 +0100 | [diff] [blame] | 421 | buf = pnp_get_resource_value(buf + 3, |
| 422 | IORESOURCE_BUS, |
| 423 | &start, &end, |
| 424 | NULL); |
| 425 | pnp_add_bus_resource(dev, start, end); |
| 426 | } else |
| 427 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | } |
Daniel Walker | b3bd86e | 2008-02-06 01:40:04 -0800 | [diff] [blame] | 429 | mutex_unlock(&pnp_res_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | goto done; |
| 431 | } |
Bjorn Helgaas | 1e0aa9a | 2007-08-15 10:32:08 -0600 | [diff] [blame] | 432 | |
| 433 | done: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | if (retval < 0) |
| 435 | return retval; |
| 436 | return count; |
| 437 | } |
Greg Kroah-Hartman | 2df4390 | 2013-10-06 23:55:42 -0700 | [diff] [blame] | 438 | static DEVICE_ATTR_RW(resources); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | |
Greg Kroah-Hartman | 2df4390 | 2013-10-06 23:55:42 -0700 | [diff] [blame] | 440 | static ssize_t id_show(struct device *dmdev, struct device_attribute *attr, |
| 441 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | { |
| 443 | char *str = buf; |
| 444 | struct pnp_dev *dev = to_pnp_dev(dmdev); |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 445 | struct pnp_id *pos = dev->id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
| 447 | while (pos) { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 448 | str += sprintf(str, "%s\n", pos->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | pos = pos->next; |
| 450 | } |
| 451 | return (str - buf); |
| 452 | } |
Greg Kroah-Hartman | 2df4390 | 2013-10-06 23:55:42 -0700 | [diff] [blame] | 453 | static DEVICE_ATTR_RO(id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | |
Greg Kroah-Hartman | 2df4390 | 2013-10-06 23:55:42 -0700 | [diff] [blame] | 455 | static struct attribute *pnp_dev_attrs[] = { |
| 456 | &dev_attr_resources.attr, |
| 457 | &dev_attr_options.attr, |
| 458 | &dev_attr_id.attr, |
| 459 | NULL, |
| 460 | }; |
| 461 | |
| 462 | static const struct attribute_group pnp_dev_group = { |
| 463 | .attrs = pnp_dev_attrs, |
| 464 | }; |
| 465 | |
| 466 | const struct attribute_group *pnp_dev_groups[] = { |
| 467 | &pnp_dev_group, |
| 468 | NULL, |
Drew Moseley | 8a89efd | 2008-09-28 01:31:35 +0200 | [diff] [blame] | 469 | }; |