blob: a876ecf7028c06c003d5fc1aed974bb9f5f97f98 [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>
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -06006 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
7 * Bjorn Helgaas <bjorn.helgaas@hp.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
9
10#include <linux/pnp.h>
11#include <linux/string.h>
12#include <linux/errno.h>
13#include <linux/list.h>
14#include <linux/types.h>
Daniel Walkerb3bd86e2008-02-06 01:40:04 -080015#include <linux/pnp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/stat.h>
17#include <linux/ctype.h>
18#include <linux/slab.h>
Daniel Walkerb3bd86e2008-02-06 01:40:04 -080019#include <linux/mutex.h>
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/uaccess.h>
22
23#include "base.h"
24
25struct pnp_info_buffer {
26 char *buffer; /* pointer to begin of buffer */
27 char *curr; /* current position in buffer */
28 unsigned long size; /* current size */
29 unsigned long len; /* total length of buffer */
30 int stop; /* stop flag */
31 int error; /* error code */
32};
33
34typedef struct pnp_info_buffer pnp_info_buffer_t;
35
Bjorn Helgaas9dd78462007-07-26 10:41:20 -070036static int pnp_printf(pnp_info_buffer_t * buffer, char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037{
38 va_list args;
39 int res;
40
41 if (buffer->stop || buffer->error)
42 return 0;
43 va_start(args, fmt);
44 res = vsnprintf(buffer->curr, buffer->len - buffer->size, fmt, args);
45 va_end(args);
46 if (buffer->size + res >= buffer->len) {
47 buffer->stop = 1;
48 return 0;
49 }
50 buffer->curr += res;
51 buffer->size += res;
52 return res;
53}
54
Bjorn Helgaas9dd78462007-07-26 10:41:20 -070055static void pnp_print_port(pnp_info_buffer_t * buffer, char *space,
56 struct pnp_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
Bjorn Helgaas169aaff2008-06-27 16:57:06 -060058 pnp_printf(buffer, "%sport %#llx-%#llx, align %#llx, size %#llx, "
59 "%i-bit address decoding\n", space,
60 (unsigned long long) port->min,
61 (unsigned long long) port->max,
62 port->align ? ((unsigned long long) port->align - 1) : 0,
63 (unsigned long long) port->size,
Bjorn Helgaas08c9f262008-06-27 16:57:03 -060064 port->flags & IORESOURCE_IO_16BIT_ADDR ? 16 : 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065}
66
Bjorn Helgaas9dd78462007-07-26 10:41:20 -070067static void pnp_print_irq(pnp_info_buffer_t * buffer, char *space,
68 struct pnp_irq *irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
70 int first = 1, i;
71
72 pnp_printf(buffer, "%sirq ", space);
73 for (i = 0; i < PNP_IRQ_NR; i++)
Bjorn Helgaas7aefff52008-06-27 16:57:05 -060074 if (test_bit(i, irq->map.bits)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 if (!first) {
76 pnp_printf(buffer, ",");
77 } else {
78 first = 0;
79 }
80 if (i == 2 || i == 9)
81 pnp_printf(buffer, "2/9");
82 else
83 pnp_printf(buffer, "%i", i);
84 }
Bjorn Helgaas7aefff52008-06-27 16:57:05 -060085 if (bitmap_empty(irq->map.bits, PNP_IRQ_NR))
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 pnp_printf(buffer, "<none>");
87 if (irq->flags & IORESOURCE_IRQ_HIGHEDGE)
88 pnp_printf(buffer, " High-Edge");
89 if (irq->flags & IORESOURCE_IRQ_LOWEDGE)
90 pnp_printf(buffer, " Low-Edge");
91 if (irq->flags & IORESOURCE_IRQ_HIGHLEVEL)
92 pnp_printf(buffer, " High-Level");
93 if (irq->flags & IORESOURCE_IRQ_LOWLEVEL)
94 pnp_printf(buffer, " Low-Level");
Bjorn Helgaasd5ebde62008-06-27 16:57:14 -060095 if (irq->flags & IORESOURCE_IRQ_OPTIONAL)
96 pnp_printf(buffer, " (optional)");
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 pnp_printf(buffer, "\n");
98}
99
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700100static void pnp_print_dma(pnp_info_buffer_t * buffer, char *space,
101 struct pnp_dma *dma)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102{
103 int first = 1, i;
104 char *s;
105
106 pnp_printf(buffer, "%sdma ", space);
107 for (i = 0; i < 8; i++)
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700108 if (dma->map & (1 << i)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 if (!first) {
110 pnp_printf(buffer, ",");
111 } else {
112 first = 0;
113 }
114 pnp_printf(buffer, "%i", i);
115 }
116 if (!dma->map)
117 pnp_printf(buffer, "<none>");
118 switch (dma->flags & IORESOURCE_DMA_TYPE_MASK) {
119 case IORESOURCE_DMA_8BIT:
120 s = "8-bit";
121 break;
122 case IORESOURCE_DMA_8AND16BIT:
123 s = "8-bit&16-bit";
124 break;
125 default:
126 s = "16-bit";
127 }
128 pnp_printf(buffer, " %s", s);
129 if (dma->flags & IORESOURCE_DMA_MASTER)
130 pnp_printf(buffer, " master");
131 if (dma->flags & IORESOURCE_DMA_BYTE)
132 pnp_printf(buffer, " byte-count");
133 if (dma->flags & IORESOURCE_DMA_WORD)
134 pnp_printf(buffer, " word-count");
135 switch (dma->flags & IORESOURCE_DMA_SPEED_MASK) {
136 case IORESOURCE_DMA_TYPEA:
137 s = "type-A";
138 break;
139 case IORESOURCE_DMA_TYPEB:
140 s = "type-B";
141 break;
142 case IORESOURCE_DMA_TYPEF:
143 s = "type-F";
144 break;
145 default:
146 s = "compatible";
147 break;
148 }
149 pnp_printf(buffer, " %s\n", s);
150}
151
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700152static void pnp_print_mem(pnp_info_buffer_t * buffer, char *space,
153 struct pnp_mem *mem)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
155 char *s;
156
Bjorn Helgaas169aaff2008-06-27 16:57:06 -0600157 pnp_printf(buffer, "%sMemory %#llx-%#llx, align %#llx, size %#llx",
158 space, (unsigned long long) mem->min,
159 (unsigned long long) mem->max,
160 (unsigned long long) mem->align,
161 (unsigned long long) mem->size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 if (mem->flags & IORESOURCE_MEM_WRITEABLE)
163 pnp_printf(buffer, ", writeable");
164 if (mem->flags & IORESOURCE_MEM_CACHEABLE)
165 pnp_printf(buffer, ", cacheable");
166 if (mem->flags & IORESOURCE_MEM_RANGELENGTH)
167 pnp_printf(buffer, ", range-length");
168 if (mem->flags & IORESOURCE_MEM_SHADOWABLE)
169 pnp_printf(buffer, ", shadowable");
170 if (mem->flags & IORESOURCE_MEM_EXPANSIONROM)
171 pnp_printf(buffer, ", expansion ROM");
172 switch (mem->flags & IORESOURCE_MEM_TYPE_MASK) {
173 case IORESOURCE_MEM_8BIT:
174 s = "8-bit";
175 break;
176 case IORESOURCE_MEM_8AND16BIT:
177 s = "8-bit&16-bit";
178 break;
179 case IORESOURCE_MEM_32BIT:
180 s = "32-bit";
181 break;
182 default:
183 s = "16-bit";
184 }
185 pnp_printf(buffer, ", %s\n", s);
186}
187
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700188static void pnp_print_option(pnp_info_buffer_t * buffer, char *space,
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -0600189 struct pnp_option *option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190{
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -0600191 switch (option->type) {
192 case IORESOURCE_IO:
193 pnp_print_port(buffer, space, &option->u.port);
194 break;
195 case IORESOURCE_MEM:
196 pnp_print_mem(buffer, space, &option->u.mem);
197 break;
198 case IORESOURCE_IRQ:
199 pnp_print_irq(buffer, space, &option->u.irq);
200 break;
201 case IORESOURCE_DMA:
202 pnp_print_dma(buffer, space, &option->u.dma);
203 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205}
206
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700207static ssize_t pnp_show_options(struct device *dmdev,
208 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
210 struct pnp_dev *dev = to_pnp_dev(dmdev);
Bjorn Helgaasb72ee1f12008-06-27 16:57:02 -0600211 pnp_info_buffer_t *buffer;
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -0600212 struct pnp_option *option;
213 int ret, dep = 0, set = 0;
214 char *indent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
Bjorn Helgaasb72ee1f12008-06-27 16:57:02 -0600216 buffer = pnp_alloc(sizeof(pnp_info_buffer_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 if (!buffer)
218 return -ENOMEM;
219
220 buffer->len = PAGE_SIZE;
221 buffer->buffer = buf;
222 buffer->curr = buffer->buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -0600224 list_for_each_entry(option, &dev->options, list) {
225 if (pnp_option_is_dependent(option)) {
226 indent = " ";
227 if (!dep || pnp_option_set(option) != set) {
228 set = pnp_option_set(option);
229 dep = 1;
230 pnp_printf(buffer, "Dependent: %02i - "
231 "Priority %s\n", set,
232 pnp_option_priority_name(option));
233 }
234 } else {
235 dep = 0;
236 indent = "";
237 }
238 pnp_print_option(buffer, indent, option);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 }
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -0600240
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 ret = (buffer->curr - buf);
242 kfree(buffer);
243 return ret;
244}
245
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700246static DEVICE_ATTR(options, S_IRUGO, pnp_show_options, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700248static ssize_t pnp_show_current_resources(struct device *dmdev,
249 struct device_attribute *attr,
250 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251{
252 struct pnp_dev *dev = to_pnp_dev(dmdev);
Bjorn Helgaasb72ee1f12008-06-27 16:57:02 -0600253 pnp_info_buffer_t *buffer;
Bjorn Helgaasf61ed7e2008-06-27 16:57:00 -0600254 struct pnp_resource *pnp_res;
Bjorn Helgaas95ab3662008-04-28 16:34:26 -0600255 struct resource *res;
Bjorn Helgaasf61ed7e2008-06-27 16:57:00 -0600256 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
258 if (!dev)
259 return -EINVAL;
260
Bjorn Helgaasb72ee1f12008-06-27 16:57:02 -0600261 buffer = pnp_alloc(sizeof(pnp_info_buffer_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 if (!buffer)
263 return -ENOMEM;
Bjorn Helgaasb72ee1f12008-06-27 16:57:02 -0600264
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 buffer->len = PAGE_SIZE;
266 buffer->buffer = buf;
267 buffer->curr = buffer->buffer;
268
Bjorn Helgaasf61ed7e2008-06-27 16:57:00 -0600269 pnp_printf(buffer, "state = %s\n", dev->active ? "active" : "disabled");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
Bjorn Helgaasf61ed7e2008-06-27 16:57:00 -0600271 list_for_each_entry(pnp_res, &dev->resources, list) {
272 res = &pnp_res->res;
273
274 pnp_printf(buffer, pnp_resource_type_name(res));
275
276 if (res->flags & IORESOURCE_DISABLED) {
Bjorn Helgaasaee3ad82008-06-27 16:56:57 -0600277 pnp_printf(buffer, " disabled\n");
Bjorn Helgaasf61ed7e2008-06-27 16:57:00 -0600278 continue;
279 }
280
281 switch (pnp_resource_type(res)) {
282 case IORESOURCE_IO:
283 case IORESOURCE_MEM:
284 pnp_printf(buffer, " %#llx-%#llx\n",
Bjorn Helgaasaee3ad82008-06-27 16:56:57 -0600285 (unsigned long long) res->start,
286 (unsigned long long) res->end);
Bjorn Helgaasf61ed7e2008-06-27 16:57:00 -0600287 break;
288 case IORESOURCE_IRQ:
289 case IORESOURCE_DMA:
Bjorn Helgaasaee3ad82008-06-27 16:56:57 -0600290 pnp_printf(buffer, " %lld\n",
291 (unsigned long long) res->start);
Bjorn Helgaasf61ed7e2008-06-27 16:57:00 -0600292 break;
293 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 }
Bjorn Helgaasf61ed7e2008-06-27 16:57:00 -0600295
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 ret = (buffer->curr - buf);
297 kfree(buffer);
298 return ret;
299}
300
Bjorn Helgaasb72ee1f12008-06-27 16:57:02 -0600301static ssize_t pnp_set_current_resources(struct device *dmdev,
302 struct device_attribute *attr,
303 const char *ubuf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304{
305 struct pnp_dev *dev = to_pnp_dev(dmdev);
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700306 char *buf = (void *)ubuf;
307 int retval = 0;
Bjorn Helgaascc8c2e32008-04-28 16:34:36 -0600308 resource_size_t start, end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
310 if (dev->status & PNP_ATTACHED) {
311 retval = -EBUSY;
Bjorn Helgaasa05d0782007-10-16 23:31:10 -0700312 dev_info(&dev->dev, "in use; can't configure\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 goto done;
314 }
315
316 while (isspace(*buf))
317 ++buf;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700318 if (!strnicmp(buf, "disable", 7)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 retval = pnp_disable_dev(dev);
320 goto done;
321 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700322 if (!strnicmp(buf, "activate", 8)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 retval = pnp_activate_dev(dev);
324 goto done;
325 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700326 if (!strnicmp(buf, "fill", 4)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 if (dev->active)
328 goto done;
329 retval = pnp_auto_config_dev(dev);
330 goto done;
331 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700332 if (!strnicmp(buf, "auto", 4)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 if (dev->active)
334 goto done;
Bjorn Helgaasf4490002008-04-28 16:34:09 -0600335 pnp_init_resources(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 retval = pnp_auto_config_dev(dev);
337 goto done;
338 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700339 if (!strnicmp(buf, "clear", 5)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 if (dev->active)
341 goto done;
Bjorn Helgaasf4490002008-04-28 16:34:09 -0600342 pnp_init_resources(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 goto done;
344 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700345 if (!strnicmp(buf, "get", 3)) {
Daniel Walkerb3bd86e2008-02-06 01:40:04 -0800346 mutex_lock(&pnp_res_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 if (pnp_can_read(dev))
Bjorn Helgaas59284cb2008-04-28 16:34:05 -0600348 dev->protocol->get(dev);
Daniel Walkerb3bd86e2008-02-06 01:40:04 -0800349 mutex_unlock(&pnp_res_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 goto done;
351 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700352 if (!strnicmp(buf, "set", 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 if (dev->active)
354 goto done;
355 buf += 3;
Bjorn Helgaasf4490002008-04-28 16:34:09 -0600356 pnp_init_resources(dev);
Daniel Walkerb3bd86e2008-02-06 01:40:04 -0800357 mutex_lock(&pnp_res_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 while (1) {
359 while (isspace(*buf))
360 ++buf;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700361 if (!strnicmp(buf, "io", 2)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 buf += 2;
363 while (isspace(*buf))
364 ++buf;
Bjorn Helgaascc8c2e32008-04-28 16:34:36 -0600365 start = simple_strtoul(buf, &buf, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 while (isspace(*buf))
367 ++buf;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700368 if (*buf == '-') {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 buf += 1;
370 while (isspace(*buf))
371 ++buf;
Bjorn Helgaascc8c2e32008-04-28 16:34:36 -0600372 end = simple_strtoul(buf, &buf, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 } else
Bjorn Helgaascc8c2e32008-04-28 16:34:36 -0600374 end = start;
Bjorn Helgaas87e4acf2008-06-27 16:56:53 -0600375 pnp_add_io_resource(dev, start, end, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 continue;
377 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700378 if (!strnicmp(buf, "mem", 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 buf += 3;
380 while (isspace(*buf))
381 ++buf;
Bjorn Helgaasd6180f32008-04-28 16:34:37 -0600382 start = simple_strtoul(buf, &buf, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 while (isspace(*buf))
384 ++buf;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700385 if (*buf == '-') {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 buf += 1;
387 while (isspace(*buf))
388 ++buf;
Bjorn Helgaasd6180f32008-04-28 16:34:37 -0600389 end = simple_strtoul(buf, &buf, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 } else
Bjorn Helgaasd6180f32008-04-28 16:34:37 -0600391 end = start;
Bjorn Helgaas87e4acf2008-06-27 16:56:53 -0600392 pnp_add_mem_resource(dev, start, end, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 continue;
394 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700395 if (!strnicmp(buf, "irq", 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 buf += 3;
397 while (isspace(*buf))
398 ++buf;
Bjorn Helgaasdbddd032008-04-28 16:34:34 -0600399 start = simple_strtoul(buf, &buf, 0);
Bjorn Helgaas87e4acf2008-06-27 16:56:53 -0600400 pnp_add_irq_resource(dev, start, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 continue;
402 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700403 if (!strnicmp(buf, "dma", 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 buf += 3;
405 while (isspace(*buf))
406 ++buf;
Bjorn Helgaasdc16f5f2008-04-28 16:34:35 -0600407 start = simple_strtoul(buf, &buf, 0);
Bjorn Helgaas87e4acf2008-06-27 16:56:53 -0600408 pnp_add_dma_resource(dev, start, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 continue;
410 }
411 break;
412 }
Daniel Walkerb3bd86e2008-02-06 01:40:04 -0800413 mutex_unlock(&pnp_res_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 goto done;
415 }
Bjorn Helgaas1e0aa9a2007-08-15 10:32:08 -0600416
417done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 if (retval < 0)
419 return retval;
420 return count;
421}
422
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700423static DEVICE_ATTR(resources, S_IRUGO | S_IWUSR,
424 pnp_show_current_resources, pnp_set_current_resources);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700426static ssize_t pnp_show_current_ids(struct device *dmdev,
427 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428{
429 char *str = buf;
430 struct pnp_dev *dev = to_pnp_dev(dmdev);
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700431 struct pnp_id *pos = dev->id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
433 while (pos) {
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700434 str += sprintf(str, "%s\n", pos->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 pos = pos->next;
436 }
437 return (str - buf);
438}
439
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700440static DEVICE_ATTR(id, S_IRUGO, pnp_show_current_ids, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
442int pnp_interface_attach_device(struct pnp_dev *dev)
443{
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700444 int rc = device_create_file(&dev->dev, &dev_attr_options);
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700445
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700446 if (rc)
447 goto err;
448 rc = device_create_file(&dev->dev, &dev_attr_resources);
449 if (rc)
450 goto err_opt;
451 rc = device_create_file(&dev->dev, &dev_attr_id);
452 if (rc)
453 goto err_res;
Jeff Garzikbfc7ee22006-12-06 20:35:33 -0800454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 return 0;
Jeff Garzikbfc7ee22006-12-06 20:35:33 -0800456
Bjorn Helgaas1e0aa9a2007-08-15 10:32:08 -0600457err_res:
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700458 device_remove_file(&dev->dev, &dev_attr_resources);
Bjorn Helgaas1e0aa9a2007-08-15 10:32:08 -0600459err_opt:
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700460 device_remove_file(&dev->dev, &dev_attr_options);
Bjorn Helgaas1e0aa9a2007-08-15 10:32:08 -0600461err:
Jeff Garzikbfc7ee22006-12-06 20:35:33 -0800462 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463}