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