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