blob: c172b6de6b71af59c924872fc70d5b38f3310e0a [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,
Bjorn Helgaas08c9f262008-06-27 16:57:03 -060060 port->flags & IORESOURCE_IO_16BIT_ADDR ? 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 Helgaasb72ee1f12008-06-27 16:57:02 -0600219 pnp_info_buffer_t *buffer;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700220 struct pnp_option *independent = dev->independent;
221 struct pnp_option *dependent = dev->dependent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 int ret, dep = 1;
223
Bjorn Helgaasb72ee1f12008-06-27 16:57:02 -0600224 buffer = 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);
Bjorn Helgaasb72ee1f12008-06-27 16:57:02 -0600251 pnp_info_buffer_t *buffer;
Bjorn Helgaasf61ed7e2008-06-27 16:57:00 -0600252 struct pnp_resource *pnp_res;
Bjorn Helgaas95ab3662008-04-28 16:34:26 -0600253 struct resource *res;
Bjorn Helgaasf61ed7e2008-06-27 16:57:00 -0600254 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
256 if (!dev)
257 return -EINVAL;
258
Bjorn Helgaasb72ee1f12008-06-27 16:57:02 -0600259 buffer = pnp_alloc(sizeof(pnp_info_buffer_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 if (!buffer)
261 return -ENOMEM;
Bjorn Helgaasb72ee1f12008-06-27 16:57:02 -0600262
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 buffer->len = PAGE_SIZE;
264 buffer->buffer = buf;
265 buffer->curr = buffer->buffer;
266
Bjorn Helgaasf61ed7e2008-06-27 16:57:00 -0600267 pnp_printf(buffer, "state = %s\n", dev->active ? "active" : "disabled");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Bjorn Helgaasf61ed7e2008-06-27 16:57:00 -0600269 list_for_each_entry(pnp_res, &dev->resources, list) {
270 res = &pnp_res->res;
271
272 pnp_printf(buffer, pnp_resource_type_name(res));
273
274 if (res->flags & IORESOURCE_DISABLED) {
Bjorn Helgaasaee3ad82008-06-27 16:56:57 -0600275 pnp_printf(buffer, " disabled\n");
Bjorn Helgaasf61ed7e2008-06-27 16:57:00 -0600276 continue;
277 }
278
279 switch (pnp_resource_type(res)) {
280 case IORESOURCE_IO:
281 case IORESOURCE_MEM:
282 pnp_printf(buffer, " %#llx-%#llx\n",
Bjorn Helgaasaee3ad82008-06-27 16:56:57 -0600283 (unsigned long long) res->start,
284 (unsigned long long) res->end);
Bjorn Helgaasf61ed7e2008-06-27 16:57:00 -0600285 break;
286 case IORESOURCE_IRQ:
287 case IORESOURCE_DMA:
Bjorn Helgaasaee3ad82008-06-27 16:56:57 -0600288 pnp_printf(buffer, " %lld\n",
289 (unsigned long long) res->start);
Bjorn Helgaasf61ed7e2008-06-27 16:57:00 -0600290 break;
291 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 }
Bjorn Helgaasf61ed7e2008-06-27 16:57:00 -0600293
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 ret = (buffer->curr - buf);
295 kfree(buffer);
296 return ret;
297}
298
Bjorn Helgaasb72ee1f12008-06-27 16:57:02 -0600299static ssize_t pnp_set_current_resources(struct device *dmdev,
300 struct device_attribute *attr,
301 const char *ubuf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302{
303 struct pnp_dev *dev = to_pnp_dev(dmdev);
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700304 char *buf = (void *)ubuf;
305 int retval = 0;
Bjorn Helgaascc8c2e32008-04-28 16:34:36 -0600306 resource_size_t start, end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
308 if (dev->status & PNP_ATTACHED) {
309 retval = -EBUSY;
Bjorn Helgaasa05d0782007-10-16 23:31:10 -0700310 dev_info(&dev->dev, "in use; can't configure\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 goto done;
312 }
313
314 while (isspace(*buf))
315 ++buf;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700316 if (!strnicmp(buf, "disable", 7)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 retval = pnp_disable_dev(dev);
318 goto done;
319 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700320 if (!strnicmp(buf, "activate", 8)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 retval = pnp_activate_dev(dev);
322 goto done;
323 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700324 if (!strnicmp(buf, "fill", 4)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 if (dev->active)
326 goto done;
327 retval = pnp_auto_config_dev(dev);
328 goto done;
329 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700330 if (!strnicmp(buf, "auto", 4)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 if (dev->active)
332 goto done;
Bjorn Helgaasf4490002008-04-28 16:34:09 -0600333 pnp_init_resources(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 retval = pnp_auto_config_dev(dev);
335 goto done;
336 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700337 if (!strnicmp(buf, "clear", 5)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 if (dev->active)
339 goto done;
Bjorn Helgaasf4490002008-04-28 16:34:09 -0600340 pnp_init_resources(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 goto done;
342 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700343 if (!strnicmp(buf, "get", 3)) {
Daniel Walkerb3bd86e2008-02-06 01:40:04 -0800344 mutex_lock(&pnp_res_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 if (pnp_can_read(dev))
Bjorn Helgaas59284cb2008-04-28 16:34:05 -0600346 dev->protocol->get(dev);
Daniel Walkerb3bd86e2008-02-06 01:40:04 -0800347 mutex_unlock(&pnp_res_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 goto done;
349 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700350 if (!strnicmp(buf, "set", 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 if (dev->active)
352 goto done;
353 buf += 3;
Bjorn Helgaasf4490002008-04-28 16:34:09 -0600354 pnp_init_resources(dev);
Daniel Walkerb3bd86e2008-02-06 01:40:04 -0800355 mutex_lock(&pnp_res_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 while (1) {
357 while (isspace(*buf))
358 ++buf;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700359 if (!strnicmp(buf, "io", 2)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 buf += 2;
361 while (isspace(*buf))
362 ++buf;
Bjorn Helgaascc8c2e32008-04-28 16:34:36 -0600363 start = simple_strtoul(buf, &buf, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 while (isspace(*buf))
365 ++buf;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700366 if (*buf == '-') {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 buf += 1;
368 while (isspace(*buf))
369 ++buf;
Bjorn Helgaascc8c2e32008-04-28 16:34:36 -0600370 end = simple_strtoul(buf, &buf, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 } else
Bjorn Helgaascc8c2e32008-04-28 16:34:36 -0600372 end = start;
Bjorn Helgaas87e4acf2008-06-27 16:56:53 -0600373 pnp_add_io_resource(dev, start, end, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 continue;
375 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700376 if (!strnicmp(buf, "mem", 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 buf += 3;
378 while (isspace(*buf))
379 ++buf;
Bjorn Helgaasd6180f32008-04-28 16:34:37 -0600380 start = simple_strtoul(buf, &buf, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 while (isspace(*buf))
382 ++buf;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700383 if (*buf == '-') {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 buf += 1;
385 while (isspace(*buf))
386 ++buf;
Bjorn Helgaasd6180f32008-04-28 16:34:37 -0600387 end = simple_strtoul(buf, &buf, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 } else
Bjorn Helgaasd6180f32008-04-28 16:34:37 -0600389 end = start;
Bjorn Helgaas87e4acf2008-06-27 16:56:53 -0600390 pnp_add_mem_resource(dev, start, end, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 continue;
392 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700393 if (!strnicmp(buf, "irq", 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 buf += 3;
395 while (isspace(*buf))
396 ++buf;
Bjorn Helgaasdbddd032008-04-28 16:34:34 -0600397 start = simple_strtoul(buf, &buf, 0);
Bjorn Helgaas87e4acf2008-06-27 16:56:53 -0600398 pnp_add_irq_resource(dev, start, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 continue;
400 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700401 if (!strnicmp(buf, "dma", 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 buf += 3;
403 while (isspace(*buf))
404 ++buf;
Bjorn Helgaasdc16f5f2008-04-28 16:34:35 -0600405 start = simple_strtoul(buf, &buf, 0);
Bjorn Helgaas87e4acf2008-06-27 16:56:53 -0600406 pnp_add_dma_resource(dev, start, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 continue;
408 }
409 break;
410 }
Daniel Walkerb3bd86e2008-02-06 01:40:04 -0800411 mutex_unlock(&pnp_res_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 goto done;
413 }
Bjorn Helgaas1e0aa9a2007-08-15 10:32:08 -0600414
415done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 if (retval < 0)
417 return retval;
418 return count;
419}
420
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700421static DEVICE_ATTR(resources, S_IRUGO | S_IWUSR,
422 pnp_show_current_resources, pnp_set_current_resources);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700424static ssize_t pnp_show_current_ids(struct device *dmdev,
425 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426{
427 char *str = buf;
428 struct pnp_dev *dev = to_pnp_dev(dmdev);
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700429 struct pnp_id *pos = dev->id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
431 while (pos) {
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700432 str += sprintf(str, "%s\n", pos->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 pos = pos->next;
434 }
435 return (str - buf);
436}
437
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700438static DEVICE_ATTR(id, S_IRUGO, pnp_show_current_ids, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
440int pnp_interface_attach_device(struct pnp_dev *dev)
441{
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700442 int rc = device_create_file(&dev->dev, &dev_attr_options);
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700443
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700444 if (rc)
445 goto err;
446 rc = device_create_file(&dev->dev, &dev_attr_resources);
447 if (rc)
448 goto err_opt;
449 rc = device_create_file(&dev->dev, &dev_attr_id);
450 if (rc)
451 goto err_res;
Jeff Garzikbfc7ee22006-12-06 20:35:33 -0800452
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 return 0;
Jeff Garzikbfc7ee22006-12-06 20:35:33 -0800454
Bjorn Helgaas1e0aa9a2007-08-15 10:32:08 -0600455err_res:
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700456 device_remove_file(&dev->dev, &dev_attr_resources);
Bjorn Helgaas1e0aa9a2007-08-15 10:32:08 -0600457err_opt:
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700458 device_remove_file(&dev->dev, &dev_attr_options);
Bjorn Helgaas1e0aa9a2007-08-15 10:32:08 -0600459err:
Jeff Garzikbfc7ee22006-12-06 20:35:33 -0800460 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461}