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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/pnp.h> |
| 9 | #include <linux/string.h> |
| 10 | #include <linux/errno.h> |
| 11 | #include <linux/list.h> |
| 12 | #include <linux/types.h> |
Daniel Walker | b3bd86e | 2008-02-06 01:40:04 -0800 | [diff] [blame] | 13 | #include <linux/pnp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/stat.h> |
| 15 | #include <linux/ctype.h> |
| 16 | #include <linux/slab.h> |
Daniel Walker | b3bd86e | 2008-02-06 01:40:04 -0800 | [diff] [blame] | 17 | #include <linux/mutex.h> |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <asm/uaccess.h> |
| 20 | |
| 21 | #include "base.h" |
| 22 | |
| 23 | struct pnp_info_buffer { |
| 24 | char *buffer; /* pointer to begin of buffer */ |
| 25 | char *curr; /* current position in buffer */ |
| 26 | unsigned long size; /* current size */ |
| 27 | unsigned long len; /* total length of buffer */ |
| 28 | int stop; /* stop flag */ |
| 29 | int error; /* error code */ |
| 30 | }; |
| 31 | |
| 32 | typedef struct pnp_info_buffer pnp_info_buffer_t; |
| 33 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 34 | static int pnp_printf(pnp_info_buffer_t * buffer, char *fmt, ...) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | { |
| 36 | va_list args; |
| 37 | int res; |
| 38 | |
| 39 | if (buffer->stop || buffer->error) |
| 40 | return 0; |
| 41 | va_start(args, fmt); |
| 42 | res = vsnprintf(buffer->curr, buffer->len - buffer->size, fmt, args); |
| 43 | va_end(args); |
| 44 | if (buffer->size + res >= buffer->len) { |
| 45 | buffer->stop = 1; |
| 46 | return 0; |
| 47 | } |
| 48 | buffer->curr += res; |
| 49 | buffer->size += res; |
| 50 | return res; |
| 51 | } |
| 52 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 53 | static void pnp_print_port(pnp_info_buffer_t * buffer, char *space, |
| 54 | struct pnp_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 56 | pnp_printf(buffer, |
| 57 | "%sport 0x%x-0x%x, align 0x%x, size 0x%x, %i-bit address decoding\n", |
| 58 | space, port->min, port->max, |
| 59 | port->align ? (port->align - 1) : 0, port->size, |
| 60 | port->flags & PNP_PORT_FLAG_16BITADDR ? 16 : 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 63 | static void pnp_print_irq(pnp_info_buffer_t * buffer, char *space, |
| 64 | struct pnp_irq *irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | { |
| 66 | int first = 1, i; |
| 67 | |
| 68 | pnp_printf(buffer, "%sirq ", space); |
| 69 | for (i = 0; i < PNP_IRQ_NR; i++) |
| 70 | if (test_bit(i, irq->map)) { |
| 71 | if (!first) { |
| 72 | pnp_printf(buffer, ","); |
| 73 | } else { |
| 74 | first = 0; |
| 75 | } |
| 76 | if (i == 2 || i == 9) |
| 77 | pnp_printf(buffer, "2/9"); |
| 78 | else |
| 79 | pnp_printf(buffer, "%i", i); |
| 80 | } |
| 81 | if (bitmap_empty(irq->map, PNP_IRQ_NR)) |
| 82 | pnp_printf(buffer, "<none>"); |
| 83 | if (irq->flags & IORESOURCE_IRQ_HIGHEDGE) |
| 84 | pnp_printf(buffer, " High-Edge"); |
| 85 | if (irq->flags & IORESOURCE_IRQ_LOWEDGE) |
| 86 | pnp_printf(buffer, " Low-Edge"); |
| 87 | if (irq->flags & IORESOURCE_IRQ_HIGHLEVEL) |
| 88 | pnp_printf(buffer, " High-Level"); |
| 89 | if (irq->flags & IORESOURCE_IRQ_LOWLEVEL) |
| 90 | pnp_printf(buffer, " Low-Level"); |
| 91 | pnp_printf(buffer, "\n"); |
| 92 | } |
| 93 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 94 | static void pnp_print_dma(pnp_info_buffer_t * buffer, char *space, |
| 95 | struct pnp_dma *dma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | { |
| 97 | int first = 1, i; |
| 98 | char *s; |
| 99 | |
| 100 | pnp_printf(buffer, "%sdma ", space); |
| 101 | for (i = 0; i < 8; i++) |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 102 | if (dma->map & (1 << i)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | if (!first) { |
| 104 | pnp_printf(buffer, ","); |
| 105 | } else { |
| 106 | first = 0; |
| 107 | } |
| 108 | pnp_printf(buffer, "%i", i); |
| 109 | } |
| 110 | if (!dma->map) |
| 111 | pnp_printf(buffer, "<none>"); |
| 112 | switch (dma->flags & IORESOURCE_DMA_TYPE_MASK) { |
| 113 | case IORESOURCE_DMA_8BIT: |
| 114 | s = "8-bit"; |
| 115 | break; |
| 116 | case IORESOURCE_DMA_8AND16BIT: |
| 117 | s = "8-bit&16-bit"; |
| 118 | break; |
| 119 | default: |
| 120 | s = "16-bit"; |
| 121 | } |
| 122 | pnp_printf(buffer, " %s", s); |
| 123 | if (dma->flags & IORESOURCE_DMA_MASTER) |
| 124 | pnp_printf(buffer, " master"); |
| 125 | if (dma->flags & IORESOURCE_DMA_BYTE) |
| 126 | pnp_printf(buffer, " byte-count"); |
| 127 | if (dma->flags & IORESOURCE_DMA_WORD) |
| 128 | pnp_printf(buffer, " word-count"); |
| 129 | switch (dma->flags & IORESOURCE_DMA_SPEED_MASK) { |
| 130 | case IORESOURCE_DMA_TYPEA: |
| 131 | s = "type-A"; |
| 132 | break; |
| 133 | case IORESOURCE_DMA_TYPEB: |
| 134 | s = "type-B"; |
| 135 | break; |
| 136 | case IORESOURCE_DMA_TYPEF: |
| 137 | s = "type-F"; |
| 138 | break; |
| 139 | default: |
| 140 | s = "compatible"; |
| 141 | break; |
| 142 | } |
| 143 | pnp_printf(buffer, " %s\n", s); |
| 144 | } |
| 145 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 146 | static void pnp_print_mem(pnp_info_buffer_t * buffer, char *space, |
| 147 | struct pnp_mem *mem) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | { |
| 149 | char *s; |
| 150 | |
| 151 | pnp_printf(buffer, "%sMemory 0x%x-0x%x, align 0x%x, size 0x%x", |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 152 | space, mem->min, mem->max, mem->align, mem->size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | if (mem->flags & IORESOURCE_MEM_WRITEABLE) |
| 154 | pnp_printf(buffer, ", writeable"); |
| 155 | if (mem->flags & IORESOURCE_MEM_CACHEABLE) |
| 156 | pnp_printf(buffer, ", cacheable"); |
| 157 | if (mem->flags & IORESOURCE_MEM_RANGELENGTH) |
| 158 | pnp_printf(buffer, ", range-length"); |
| 159 | if (mem->flags & IORESOURCE_MEM_SHADOWABLE) |
| 160 | pnp_printf(buffer, ", shadowable"); |
| 161 | if (mem->flags & IORESOURCE_MEM_EXPANSIONROM) |
| 162 | pnp_printf(buffer, ", expansion ROM"); |
| 163 | switch (mem->flags & IORESOURCE_MEM_TYPE_MASK) { |
| 164 | case IORESOURCE_MEM_8BIT: |
| 165 | s = "8-bit"; |
| 166 | break; |
| 167 | case IORESOURCE_MEM_8AND16BIT: |
| 168 | s = "8-bit&16-bit"; |
| 169 | break; |
| 170 | case IORESOURCE_MEM_32BIT: |
| 171 | s = "32-bit"; |
| 172 | break; |
| 173 | default: |
| 174 | s = "16-bit"; |
| 175 | } |
| 176 | pnp_printf(buffer, ", %s\n", s); |
| 177 | } |
| 178 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 179 | static void pnp_print_option(pnp_info_buffer_t * buffer, char *space, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | struct pnp_option *option, int dep) |
| 181 | { |
| 182 | char *s; |
| 183 | struct pnp_port *port; |
| 184 | struct pnp_irq *irq; |
| 185 | struct pnp_dma *dma; |
| 186 | struct pnp_mem *mem; |
| 187 | |
| 188 | if (dep) { |
| 189 | switch (option->priority) { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 190 | case PNP_RES_PRIORITY_PREFERRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | s = "preferred"; |
| 192 | break; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 193 | case PNP_RES_PRIORITY_ACCEPTABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | s = "acceptable"; |
| 195 | break; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 196 | case PNP_RES_PRIORITY_FUNCTIONAL: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | s = "functional"; |
| 198 | break; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 199 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | s = "invalid"; |
| 201 | } |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 202 | pnp_printf(buffer, "Dependent: %02i - Priority %s\n", dep, s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | for (port = option->port; port; port = port->next) |
| 206 | pnp_print_port(buffer, space, port); |
| 207 | for (irq = option->irq; irq; irq = irq->next) |
| 208 | pnp_print_irq(buffer, space, irq); |
| 209 | for (dma = option->dma; dma; dma = dma->next) |
| 210 | pnp_print_dma(buffer, space, dma); |
| 211 | for (mem = option->mem; mem; mem = mem->next) |
| 212 | pnp_print_mem(buffer, space, mem); |
| 213 | } |
| 214 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 215 | static ssize_t pnp_show_options(struct device *dmdev, |
| 216 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | { |
| 218 | struct pnp_dev *dev = to_pnp_dev(dmdev); |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 219 | struct pnp_option *independent = dev->independent; |
| 220 | struct pnp_option *dependent = dev->dependent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | int ret, dep = 1; |
| 222 | |
| 223 | pnp_info_buffer_t *buffer = (pnp_info_buffer_t *) |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 224 | pnp_alloc(sizeof(pnp_info_buffer_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | if (!buffer) |
| 226 | return -ENOMEM; |
| 227 | |
| 228 | buffer->len = PAGE_SIZE; |
| 229 | buffer->buffer = buf; |
| 230 | buffer->curr = buffer->buffer; |
| 231 | if (independent) |
| 232 | pnp_print_option(buffer, "", independent, 0); |
| 233 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 234 | while (dependent) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | pnp_print_option(buffer, " ", dependent, dep); |
| 236 | dependent = dependent->next; |
| 237 | dep++; |
| 238 | } |
| 239 | ret = (buffer->curr - buf); |
| 240 | kfree(buffer); |
| 241 | return ret; |
| 242 | } |
| 243 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 244 | static DEVICE_ATTR(options, S_IRUGO, pnp_show_options, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 246 | static ssize_t pnp_show_current_resources(struct device *dmdev, |
| 247 | struct device_attribute *attr, |
| 248 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | { |
| 250 | struct pnp_dev *dev = to_pnp_dev(dmdev); |
| 251 | int i, ret; |
| 252 | pnp_info_buffer_t *buffer; |
| 253 | |
| 254 | if (!dev) |
| 255 | return -EINVAL; |
| 256 | |
| 257 | buffer = (pnp_info_buffer_t *) pnp_alloc(sizeof(pnp_info_buffer_t)); |
| 258 | if (!buffer) |
| 259 | return -ENOMEM; |
| 260 | buffer->len = PAGE_SIZE; |
| 261 | buffer->buffer = buf; |
| 262 | buffer->curr = buffer->buffer; |
| 263 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 264 | pnp_printf(buffer, "state = "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | if (dev->active) |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 266 | pnp_printf(buffer, "active\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | else |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 268 | pnp_printf(buffer, "disabled\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
| 270 | for (i = 0; i < PNP_MAX_PORT; i++) { |
| 271 | if (pnp_port_valid(dev, i)) { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 272 | pnp_printf(buffer, "io"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | if (pnp_port_flags(dev, i) & IORESOURCE_DISABLED) |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 274 | pnp_printf(buffer, " disabled\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | else |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 276 | pnp_printf(buffer, " 0x%llx-0x%llx\n", |
| 277 | (unsigned long long) |
| 278 | pnp_port_start(dev, i), |
| 279 | (unsigned long long)pnp_port_end(dev, |
| 280 | i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | for (i = 0; i < PNP_MAX_MEM; i++) { |
| 284 | if (pnp_mem_valid(dev, i)) { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 285 | pnp_printf(buffer, "mem"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | if (pnp_mem_flags(dev, i) & IORESOURCE_DISABLED) |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 287 | pnp_printf(buffer, " disabled\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | else |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 289 | pnp_printf(buffer, " 0x%llx-0x%llx\n", |
| 290 | (unsigned long long) |
| 291 | pnp_mem_start(dev, i), |
| 292 | (unsigned long long)pnp_mem_end(dev, |
| 293 | i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | for (i = 0; i < PNP_MAX_IRQ; i++) { |
| 297 | if (pnp_irq_valid(dev, i)) { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 298 | pnp_printf(buffer, "irq"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | if (pnp_irq_flags(dev, i) & IORESOURCE_DISABLED) |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 300 | pnp_printf(buffer, " disabled\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | else |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 302 | pnp_printf(buffer, " %lld\n", |
| 303 | (unsigned long long)pnp_irq(dev, i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | } |
| 305 | } |
| 306 | for (i = 0; i < PNP_MAX_DMA; i++) { |
| 307 | if (pnp_dma_valid(dev, i)) { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 308 | pnp_printf(buffer, "dma"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | if (pnp_dma_flags(dev, i) & IORESOURCE_DISABLED) |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 310 | pnp_printf(buffer, " disabled\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | else |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 312 | pnp_printf(buffer, " %lld\n", |
| 313 | (unsigned long long)pnp_dma(dev, i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | ret = (buffer->curr - buf); |
| 317 | kfree(buffer); |
| 318 | return ret; |
| 319 | } |
| 320 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | static ssize_t |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 322 | pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr, |
| 323 | const char *ubuf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | { |
| 325 | struct pnp_dev *dev = to_pnp_dev(dmdev); |
Bjorn Helgaas | 470feb1 | 2008-04-28 16:34:20 -0600 | [diff] [blame] | 326 | struct resource *res; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 327 | char *buf = (void *)ubuf; |
| 328 | int retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
| 330 | if (dev->status & PNP_ATTACHED) { |
| 331 | retval = -EBUSY; |
Bjorn Helgaas | a05d078 | 2007-10-16 23:31:10 -0700 | [diff] [blame] | 332 | dev_info(&dev->dev, "in use; can't configure\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | goto done; |
| 334 | } |
| 335 | |
| 336 | while (isspace(*buf)) |
| 337 | ++buf; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 338 | if (!strnicmp(buf, "disable", 7)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | retval = pnp_disable_dev(dev); |
| 340 | goto done; |
| 341 | } |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 342 | if (!strnicmp(buf, "activate", 8)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | retval = pnp_activate_dev(dev); |
| 344 | goto done; |
| 345 | } |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 346 | if (!strnicmp(buf, "fill", 4)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | if (dev->active) |
| 348 | goto done; |
| 349 | retval = pnp_auto_config_dev(dev); |
| 350 | goto done; |
| 351 | } |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 352 | if (!strnicmp(buf, "auto", 4)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | if (dev->active) |
| 354 | goto done; |
Bjorn Helgaas | f449000 | 2008-04-28 16:34:09 -0600 | [diff] [blame] | 355 | pnp_init_resources(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | retval = pnp_auto_config_dev(dev); |
| 357 | goto done; |
| 358 | } |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 359 | if (!strnicmp(buf, "clear", 5)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | if (dev->active) |
| 361 | goto done; |
Bjorn Helgaas | f449000 | 2008-04-28 16:34:09 -0600 | [diff] [blame] | 362 | pnp_init_resources(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | goto done; |
| 364 | } |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 365 | if (!strnicmp(buf, "get", 3)) { |
Daniel Walker | b3bd86e | 2008-02-06 01:40:04 -0800 | [diff] [blame] | 366 | mutex_lock(&pnp_res_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | if (pnp_can_read(dev)) |
Bjorn Helgaas | 59284cb | 2008-04-28 16:34:05 -0600 | [diff] [blame] | 368 | dev->protocol->get(dev); |
Daniel Walker | b3bd86e | 2008-02-06 01:40:04 -0800 | [diff] [blame] | 369 | mutex_unlock(&pnp_res_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | goto done; |
| 371 | } |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 372 | if (!strnicmp(buf, "set", 3)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | int nport = 0, nmem = 0, nirq = 0, ndma = 0; |
| 374 | if (dev->active) |
| 375 | goto done; |
| 376 | buf += 3; |
Bjorn Helgaas | f449000 | 2008-04-28 16:34:09 -0600 | [diff] [blame] | 377 | pnp_init_resources(dev); |
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 | while (1) { |
| 380 | while (isspace(*buf)) |
| 381 | ++buf; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 382 | if (!strnicmp(buf, "io", 2)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | buf += 2; |
| 384 | while (isspace(*buf)) |
| 385 | ++buf; |
Bjorn Helgaas | f6505fe | 2008-04-28 16:34:25 -0600 | [diff] [blame^] | 386 | res = pnp_get_resource(dev, IORESOURCE_IO, |
| 387 | nport); |
| 388 | if (!res) |
| 389 | break; |
Bjorn Helgaas | 470feb1 | 2008-04-28 16:34:20 -0600 | [diff] [blame] | 390 | res->start = simple_strtoul(buf, &buf, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | while (isspace(*buf)) |
| 392 | ++buf; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 393 | if (*buf == '-') { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | buf += 1; |
| 395 | while (isspace(*buf)) |
| 396 | ++buf; |
Bjorn Helgaas | 470feb1 | 2008-04-28 16:34:20 -0600 | [diff] [blame] | 397 | res->end = simple_strtoul(buf, &buf, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | } else |
Bjorn Helgaas | 470feb1 | 2008-04-28 16:34:20 -0600 | [diff] [blame] | 399 | res->end = res->start; |
| 400 | res->flags = IORESOURCE_IO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | nport++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | continue; |
| 403 | } |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 404 | if (!strnicmp(buf, "mem", 3)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | buf += 3; |
| 406 | while (isspace(*buf)) |
| 407 | ++buf; |
Bjorn Helgaas | f6505fe | 2008-04-28 16:34:25 -0600 | [diff] [blame^] | 408 | res = pnp_get_resource(dev, IORESOURCE_MEM, |
| 409 | nmem); |
| 410 | if (!res) |
| 411 | break; |
Bjorn Helgaas | 470feb1 | 2008-04-28 16:34:20 -0600 | [diff] [blame] | 412 | res->start = simple_strtoul(buf, &buf, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | while (isspace(*buf)) |
| 414 | ++buf; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 415 | if (*buf == '-') { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | buf += 1; |
| 417 | while (isspace(*buf)) |
| 418 | ++buf; |
Bjorn Helgaas | 470feb1 | 2008-04-28 16:34:20 -0600 | [diff] [blame] | 419 | res->end = simple_strtoul(buf, &buf, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | } else |
Bjorn Helgaas | 470feb1 | 2008-04-28 16:34:20 -0600 | [diff] [blame] | 421 | res->end = res->start; |
| 422 | res->flags = IORESOURCE_MEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | nmem++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | continue; |
| 425 | } |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 426 | if (!strnicmp(buf, "irq", 3)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | buf += 3; |
| 428 | while (isspace(*buf)) |
| 429 | ++buf; |
Bjorn Helgaas | f6505fe | 2008-04-28 16:34:25 -0600 | [diff] [blame^] | 430 | res = pnp_get_resource(dev, IORESOURCE_IRQ, |
| 431 | nirq); |
| 432 | if (!res) |
| 433 | break; |
Bjorn Helgaas | 470feb1 | 2008-04-28 16:34:20 -0600 | [diff] [blame] | 434 | res->start = res->end = |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 435 | simple_strtoul(buf, &buf, 0); |
Bjorn Helgaas | 470feb1 | 2008-04-28 16:34:20 -0600 | [diff] [blame] | 436 | res->flags = IORESOURCE_IRQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | nirq++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | continue; |
| 439 | } |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 440 | if (!strnicmp(buf, "dma", 3)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | buf += 3; |
| 442 | while (isspace(*buf)) |
| 443 | ++buf; |
Bjorn Helgaas | f6505fe | 2008-04-28 16:34:25 -0600 | [diff] [blame^] | 444 | res = pnp_get_resource(dev, IORESOURCE_DMA, |
| 445 | ndma); |
| 446 | if (!res) |
| 447 | break; |
Bjorn Helgaas | 470feb1 | 2008-04-28 16:34:20 -0600 | [diff] [blame] | 448 | res->start = res->end = |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 449 | simple_strtoul(buf, &buf, 0); |
Bjorn Helgaas | 470feb1 | 2008-04-28 16:34:20 -0600 | [diff] [blame] | 450 | res->flags = IORESOURCE_DMA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | ndma++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | continue; |
| 453 | } |
| 454 | break; |
| 455 | } |
Daniel Walker | b3bd86e | 2008-02-06 01:40:04 -0800 | [diff] [blame] | 456 | mutex_unlock(&pnp_res_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | goto done; |
| 458 | } |
Bjorn Helgaas | 1e0aa9a | 2007-08-15 10:32:08 -0600 | [diff] [blame] | 459 | |
| 460 | done: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | if (retval < 0) |
| 462 | return retval; |
| 463 | return count; |
| 464 | } |
| 465 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 466 | static DEVICE_ATTR(resources, S_IRUGO | S_IWUSR, |
| 467 | pnp_show_current_resources, pnp_set_current_resources); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 469 | static ssize_t pnp_show_current_ids(struct device *dmdev, |
| 470 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | { |
| 472 | char *str = buf; |
| 473 | struct pnp_dev *dev = to_pnp_dev(dmdev); |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 474 | struct pnp_id *pos = dev->id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | |
| 476 | while (pos) { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 477 | str += sprintf(str, "%s\n", pos->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | pos = pos->next; |
| 479 | } |
| 480 | return (str - buf); |
| 481 | } |
| 482 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 483 | static DEVICE_ATTR(id, S_IRUGO, pnp_show_current_ids, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
| 485 | int pnp_interface_attach_device(struct pnp_dev *dev) |
| 486 | { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 487 | int rc = device_create_file(&dev->dev, &dev_attr_options); |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 488 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 489 | if (rc) |
| 490 | goto err; |
| 491 | rc = device_create_file(&dev->dev, &dev_attr_resources); |
| 492 | if (rc) |
| 493 | goto err_opt; |
| 494 | rc = device_create_file(&dev->dev, &dev_attr_id); |
| 495 | if (rc) |
| 496 | goto err_res; |
Jeff Garzik | bfc7ee2 | 2006-12-06 20:35:33 -0800 | [diff] [blame] | 497 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | return 0; |
Jeff Garzik | bfc7ee2 | 2006-12-06 20:35:33 -0800 | [diff] [blame] | 499 | |
Bjorn Helgaas | 1e0aa9a | 2007-08-15 10:32:08 -0600 | [diff] [blame] | 500 | err_res: |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 501 | device_remove_file(&dev->dev, &dev_attr_resources); |
Bjorn Helgaas | 1e0aa9a | 2007-08-15 10:32:08 -0600 | [diff] [blame] | 502 | err_opt: |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 503 | device_remove_file(&dev->dev, &dev_attr_options); |
Bjorn Helgaas | 1e0aa9a | 2007-08-15 10:32:08 -0600 | [diff] [blame] | 504 | err: |
Jeff Garzik | bfc7ee2 | 2006-12-06 20:35:33 -0800 | [diff] [blame] | 505 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | } |