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