blob: 982658477a58b4695df2ac979b00090cba9b1101 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * interface.c - contains everything related to the user interface
3 *
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02004 * Some code, especially possible resource dumping is based on isapnp_proc.c (c) Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Copyright 2002 Adam Belay <ambx1@neo.rr.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
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 Walkerb3bd86e2008-02-06 01:40:04 -080013#include <linux/pnp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/stat.h>
15#include <linux/ctype.h>
16#include <linux/slab.h>
Daniel Walkerb3bd86e2008-02-06 01:40:04 -080017#include <linux/mutex.h>
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/uaccess.h>
20
21#include "base.h"
22
23struct 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
32typedef struct pnp_info_buffer pnp_info_buffer_t;
33
Bjorn Helgaas9dd78462007-07-26 10:41:20 -070034static int pnp_printf(pnp_info_buffer_t * buffer, char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035{
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 Helgaas9dd78462007-07-26 10:41:20 -070053static void pnp_print_port(pnp_info_buffer_t * buffer, char *space,
54 struct pnp_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
Bjorn Helgaas9dd78462007-07-26 10:41:20 -070056 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 Torvalds1da177e2005-04-16 15:20:36 -070061}
62
Bjorn Helgaas9dd78462007-07-26 10:41:20 -070063static void pnp_print_irq(pnp_info_buffer_t * buffer, char *space,
64 struct pnp_irq *irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
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 Helgaas9dd78462007-07-26 10:41:20 -070094static void pnp_print_dma(pnp_info_buffer_t * buffer, char *space,
95 struct pnp_dma *dma)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096{
97 int first = 1, i;
98 char *s;
99
100 pnp_printf(buffer, "%sdma ", space);
101 for (i = 0; i < 8; i++)
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700102 if (dma->map & (1 << i)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 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 Helgaas9dd78462007-07-26 10:41:20 -0700146static void pnp_print_mem(pnp_info_buffer_t * buffer, char *space,
147 struct pnp_mem *mem)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148{
149 char *s;
150
151 pnp_printf(buffer, "%sMemory 0x%x-0x%x, align 0x%x, size 0x%x",
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700152 space, mem->min, mem->max, mem->align, mem->size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 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 Helgaas9dd78462007-07-26 10:41:20 -0700179static void pnp_print_option(pnp_info_buffer_t * buffer, char *space,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 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 Helgaas9dd78462007-07-26 10:41:20 -0700190 case PNP_RES_PRIORITY_PREFERRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 s = "preferred";
192 break;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700193 case PNP_RES_PRIORITY_ACCEPTABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 s = "acceptable";
195 break;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700196 case PNP_RES_PRIORITY_FUNCTIONAL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 s = "functional";
198 break;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700199 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 s = "invalid";
201 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700202 pnp_printf(buffer, "Dependent: %02i - Priority %s\n", dep, s);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 }
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 Helgaas9dd78462007-07-26 10:41:20 -0700215static ssize_t pnp_show_options(struct device *dmdev,
216 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217{
218 struct pnp_dev *dev = to_pnp_dev(dmdev);
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700219 struct pnp_option *independent = dev->independent;
220 struct pnp_option *dependent = dev->dependent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 int ret, dep = 1;
222
223 pnp_info_buffer_t *buffer = (pnp_info_buffer_t *)
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700224 pnp_alloc(sizeof(pnp_info_buffer_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 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 Helgaas9dd78462007-07-26 10:41:20 -0700234 while (dependent) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 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 Helgaas9dd78462007-07-26 10:41:20 -0700244static DEVICE_ATTR(options, S_IRUGO, pnp_show_options, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700246static ssize_t pnp_show_current_resources(struct device *dmdev,
247 struct device_attribute *attr,
248 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249{
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 Helgaas9dd78462007-07-26 10:41:20 -0700264 pnp_printf(buffer, "state = ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 if (dev->active)
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700266 pnp_printf(buffer, "active\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 else
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700268 pnp_printf(buffer, "disabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270 for (i = 0; i < PNP_MAX_PORT; i++) {
271 if (pnp_port_valid(dev, i)) {
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700272 pnp_printf(buffer, "io");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 if (pnp_port_flags(dev, i) & IORESOURCE_DISABLED)
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700274 pnp_printf(buffer, " disabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 else
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700276 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 Torvalds1da177e2005-04-16 15:20:36 -0700281 }
282 }
283 for (i = 0; i < PNP_MAX_MEM; i++) {
284 if (pnp_mem_valid(dev, i)) {
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700285 pnp_printf(buffer, "mem");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 if (pnp_mem_flags(dev, i) & IORESOURCE_DISABLED)
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700287 pnp_printf(buffer, " disabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 else
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700289 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 Torvalds1da177e2005-04-16 15:20:36 -0700294 }
295 }
296 for (i = 0; i < PNP_MAX_IRQ; i++) {
297 if (pnp_irq_valid(dev, i)) {
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700298 pnp_printf(buffer, "irq");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 if (pnp_irq_flags(dev, i) & IORESOURCE_DISABLED)
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700300 pnp_printf(buffer, " disabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 else
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700302 pnp_printf(buffer, " %lld\n",
303 (unsigned long long)pnp_irq(dev, i));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 }
305 }
306 for (i = 0; i < PNP_MAX_DMA; i++) {
307 if (pnp_dma_valid(dev, i)) {
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700308 pnp_printf(buffer, "dma");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 if (pnp_dma_flags(dev, i) & IORESOURCE_DISABLED)
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700310 pnp_printf(buffer, " disabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 else
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700312 pnp_printf(buffer, " %lld\n",
313 (unsigned long long)pnp_dma(dev, i));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 }
315 }
316 ret = (buffer->curr - buf);
317 kfree(buffer);
318 return ret;
319}
320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321static ssize_t
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700322pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
323 const char *ubuf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324{
325 struct pnp_dev *dev = to_pnp_dev(dmdev);
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700326 char *buf = (void *)ubuf;
327 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
329 if (dev->status & PNP_ATTACHED) {
330 retval = -EBUSY;
Bjorn Helgaasa05d0782007-10-16 23:31:10 -0700331 dev_info(&dev->dev, "in use; can't configure\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 goto done;
333 }
334
335 while (isspace(*buf))
336 ++buf;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700337 if (!strnicmp(buf, "disable", 7)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 retval = pnp_disable_dev(dev);
339 goto done;
340 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700341 if (!strnicmp(buf, "activate", 8)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 retval = pnp_activate_dev(dev);
343 goto done;
344 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700345 if (!strnicmp(buf, "fill", 4)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 if (dev->active)
347 goto done;
348 retval = pnp_auto_config_dev(dev);
349 goto done;
350 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700351 if (!strnicmp(buf, "auto", 4)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 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 Helgaas9dd78462007-07-26 10:41:20 -0700358 if (!strnicmp(buf, "clear", 5)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 if (dev->active)
360 goto done;
361 pnp_init_resource_table(&dev->res);
362 goto done;
363 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700364 if (!strnicmp(buf, "get", 3)) {
Daniel Walkerb3bd86e2008-02-06 01:40:04 -0800365 mutex_lock(&pnp_res_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 if (pnp_can_read(dev))
367 dev->protocol->get(dev, &dev->res);
Daniel Walkerb3bd86e2008-02-06 01:40:04 -0800368 mutex_unlock(&pnp_res_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 goto done;
370 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700371 if (!strnicmp(buf, "set", 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 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);
Daniel Walkerb3bd86e2008-02-06 01:40:04 -0800377 mutex_lock(&pnp_res_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 while (1) {
379 while (isspace(*buf))
380 ++buf;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700381 if (!strnicmp(buf, "io", 2)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 buf += 2;
383 while (isspace(*buf))
384 ++buf;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700385 dev->res.port_resource[nport].start =
386 simple_strtoul(buf, &buf, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 while (isspace(*buf))
388 ++buf;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700389 if (*buf == '-') {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 buf += 1;
391 while (isspace(*buf))
392 ++buf;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700393 dev->res.port_resource[nport].end =
394 simple_strtoul(buf, &buf, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 } else
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700396 dev->res.port_resource[nport].end =
397 dev->res.port_resource[nport].start;
398 dev->res.port_resource[nport].flags =
399 IORESOURCE_IO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 nport++;
401 if (nport >= PNP_MAX_PORT)
402 break;
403 continue;
404 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700405 if (!strnicmp(buf, "mem", 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 buf += 3;
407 while (isspace(*buf))
408 ++buf;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700409 dev->res.mem_resource[nmem].start =
410 simple_strtoul(buf, &buf, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 while (isspace(*buf))
412 ++buf;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700413 if (*buf == '-') {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 buf += 1;
415 while (isspace(*buf))
416 ++buf;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700417 dev->res.mem_resource[nmem].end =
418 simple_strtoul(buf, &buf, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 } else
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700420 dev->res.mem_resource[nmem].end =
421 dev->res.mem_resource[nmem].start;
422 dev->res.mem_resource[nmem].flags =
423 IORESOURCE_MEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 nmem++;
425 if (nmem >= PNP_MAX_MEM)
426 break;
427 continue;
428 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700429 if (!strnicmp(buf, "irq", 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 buf += 3;
431 while (isspace(*buf))
432 ++buf;
433 dev->res.irq_resource[nirq].start =
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700434 dev->res.irq_resource[nirq].end =
435 simple_strtoul(buf, &buf, 0);
436 dev->res.irq_resource[nirq].flags =
437 IORESOURCE_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 nirq++;
439 if (nirq >= PNP_MAX_IRQ)
440 break;
441 continue;
442 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700443 if (!strnicmp(buf, "dma", 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 buf += 3;
445 while (isspace(*buf))
446 ++buf;
447 dev->res.dma_resource[ndma].start =
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700448 dev->res.dma_resource[ndma].end =
449 simple_strtoul(buf, &buf, 0);
450 dev->res.dma_resource[ndma].flags =
451 IORESOURCE_DMA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 ndma++;
453 if (ndma >= PNP_MAX_DMA)
454 break;
455 continue;
456 }
457 break;
458 }
Daniel Walkerb3bd86e2008-02-06 01:40:04 -0800459 mutex_unlock(&pnp_res_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 goto done;
461 }
Bjorn Helgaas1e0aa9a2007-08-15 10:32:08 -0600462
463done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 if (retval < 0)
465 return retval;
466 return count;
467}
468
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700469static DEVICE_ATTR(resources, S_IRUGO | S_IWUSR,
470 pnp_show_current_resources, pnp_set_current_resources);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700472static ssize_t pnp_show_current_ids(struct device *dmdev,
473 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474{
475 char *str = buf;
476 struct pnp_dev *dev = to_pnp_dev(dmdev);
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700477 struct pnp_id *pos = dev->id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
479 while (pos) {
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700480 str += sprintf(str, "%s\n", pos->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 pos = pos->next;
482 }
483 return (str - buf);
484}
485
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700486static DEVICE_ATTR(id, S_IRUGO, pnp_show_current_ids, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
488int pnp_interface_attach_device(struct pnp_dev *dev)
489{
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700490 int rc = device_create_file(&dev->dev, &dev_attr_options);
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700491
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700492 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 Garzikbfc7ee22006-12-06 20:35:33 -0800500
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 return 0;
Jeff Garzikbfc7ee22006-12-06 20:35:33 -0800502
Bjorn Helgaas1e0aa9a2007-08-15 10:32:08 -0600503err_res:
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700504 device_remove_file(&dev->dev, &dev_attr_resources);
Bjorn Helgaas1e0aa9a2007-08-15 10:32:08 -0600505err_opt:
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700506 device_remove_file(&dev->dev, &dev_attr_options);
Bjorn Helgaas1e0aa9a2007-08-15 10:32:08 -0600507err:
Jeff Garzikbfc7ee22006-12-06 20:35:33 -0800508 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509}