blob: b09f67de13d091701b7c188cbff090dedb9c6630 [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 Helgaas169aaff2008-06-27 16:57:06 -060056 pnp_printf(buffer, "%sport %#llx-%#llx, align %#llx, size %#llx, "
57 "%i-bit address decoding\n", space,
58 (unsigned long long) port->min,
59 (unsigned long long) port->max,
60 port->align ? ((unsigned long long) port->align - 1) : 0,
61 (unsigned long long) port->size,
Bjorn Helgaas08c9f262008-06-27 16:57:03 -060062 port->flags & IORESOURCE_IO_16BIT_ADDR ? 16 : 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063}
64
Bjorn Helgaas9dd78462007-07-26 10:41:20 -070065static void pnp_print_irq(pnp_info_buffer_t * buffer, char *space,
66 struct pnp_irq *irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
68 int first = 1, i;
69
70 pnp_printf(buffer, "%sirq ", space);
71 for (i = 0; i < PNP_IRQ_NR; i++)
Bjorn Helgaas7aefff52008-06-27 16:57:05 -060072 if (test_bit(i, irq->map.bits)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 if (!first) {
74 pnp_printf(buffer, ",");
75 } else {
76 first = 0;
77 }
78 if (i == 2 || i == 9)
79 pnp_printf(buffer, "2/9");
80 else
81 pnp_printf(buffer, "%i", i);
82 }
Bjorn Helgaas7aefff52008-06-27 16:57:05 -060083 if (bitmap_empty(irq->map.bits, PNP_IRQ_NR))
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 pnp_printf(buffer, "<none>");
85 if (irq->flags & IORESOURCE_IRQ_HIGHEDGE)
86 pnp_printf(buffer, " High-Edge");
87 if (irq->flags & IORESOURCE_IRQ_LOWEDGE)
88 pnp_printf(buffer, " Low-Edge");
89 if (irq->flags & IORESOURCE_IRQ_HIGHLEVEL)
90 pnp_printf(buffer, " High-Level");
91 if (irq->flags & IORESOURCE_IRQ_LOWLEVEL)
92 pnp_printf(buffer, " Low-Level");
93 pnp_printf(buffer, "\n");
94}
95
Bjorn Helgaas9dd78462007-07-26 10:41:20 -070096static void pnp_print_dma(pnp_info_buffer_t * buffer, char *space,
97 struct pnp_dma *dma)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098{
99 int first = 1, i;
100 char *s;
101
102 pnp_printf(buffer, "%sdma ", space);
103 for (i = 0; i < 8; i++)
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700104 if (dma->map & (1 << i)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 if (!first) {
106 pnp_printf(buffer, ",");
107 } else {
108 first = 0;
109 }
110 pnp_printf(buffer, "%i", i);
111 }
112 if (!dma->map)
113 pnp_printf(buffer, "<none>");
114 switch (dma->flags & IORESOURCE_DMA_TYPE_MASK) {
115 case IORESOURCE_DMA_8BIT:
116 s = "8-bit";
117 break;
118 case IORESOURCE_DMA_8AND16BIT:
119 s = "8-bit&16-bit";
120 break;
121 default:
122 s = "16-bit";
123 }
124 pnp_printf(buffer, " %s", s);
125 if (dma->flags & IORESOURCE_DMA_MASTER)
126 pnp_printf(buffer, " master");
127 if (dma->flags & IORESOURCE_DMA_BYTE)
128 pnp_printf(buffer, " byte-count");
129 if (dma->flags & IORESOURCE_DMA_WORD)
130 pnp_printf(buffer, " word-count");
131 switch (dma->flags & IORESOURCE_DMA_SPEED_MASK) {
132 case IORESOURCE_DMA_TYPEA:
133 s = "type-A";
134 break;
135 case IORESOURCE_DMA_TYPEB:
136 s = "type-B";
137 break;
138 case IORESOURCE_DMA_TYPEF:
139 s = "type-F";
140 break;
141 default:
142 s = "compatible";
143 break;
144 }
145 pnp_printf(buffer, " %s\n", s);
146}
147
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700148static void pnp_print_mem(pnp_info_buffer_t * buffer, char *space,
149 struct pnp_mem *mem)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150{
151 char *s;
152
Bjorn Helgaas169aaff2008-06-27 16:57:06 -0600153 pnp_printf(buffer, "%sMemory %#llx-%#llx, align %#llx, size %#llx",
154 space, (unsigned long long) mem->min,
155 (unsigned long long) mem->max,
156 (unsigned long long) mem->align,
157 (unsigned long long) mem->size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 if (mem->flags & IORESOURCE_MEM_WRITEABLE)
159 pnp_printf(buffer, ", writeable");
160 if (mem->flags & IORESOURCE_MEM_CACHEABLE)
161 pnp_printf(buffer, ", cacheable");
162 if (mem->flags & IORESOURCE_MEM_RANGELENGTH)
163 pnp_printf(buffer, ", range-length");
164 if (mem->flags & IORESOURCE_MEM_SHADOWABLE)
165 pnp_printf(buffer, ", shadowable");
166 if (mem->flags & IORESOURCE_MEM_EXPANSIONROM)
167 pnp_printf(buffer, ", expansion ROM");
168 switch (mem->flags & IORESOURCE_MEM_TYPE_MASK) {
169 case IORESOURCE_MEM_8BIT:
170 s = "8-bit";
171 break;
172 case IORESOURCE_MEM_8AND16BIT:
173 s = "8-bit&16-bit";
174 break;
175 case IORESOURCE_MEM_32BIT:
176 s = "32-bit";
177 break;
178 default:
179 s = "16-bit";
180 }
181 pnp_printf(buffer, ", %s\n", s);
182}
183
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700184static void pnp_print_option(pnp_info_buffer_t * buffer, char *space,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 struct pnp_option *option, int dep)
186{
187 char *s;
188 struct pnp_port *port;
189 struct pnp_irq *irq;
190 struct pnp_dma *dma;
191 struct pnp_mem *mem;
192
193 if (dep) {
194 switch (option->priority) {
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700195 case PNP_RES_PRIORITY_PREFERRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 s = "preferred";
197 break;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700198 case PNP_RES_PRIORITY_ACCEPTABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 s = "acceptable";
200 break;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700201 case PNP_RES_PRIORITY_FUNCTIONAL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 s = "functional";
203 break;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700204 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 s = "invalid";
206 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700207 pnp_printf(buffer, "Dependent: %02i - Priority %s\n", dep, s);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 }
209
210 for (port = option->port; port; port = port->next)
211 pnp_print_port(buffer, space, port);
212 for (irq = option->irq; irq; irq = irq->next)
213 pnp_print_irq(buffer, space, irq);
214 for (dma = option->dma; dma; dma = dma->next)
215 pnp_print_dma(buffer, space, dma);
216 for (mem = option->mem; mem; mem = mem->next)
217 pnp_print_mem(buffer, space, mem);
218}
219
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700220static ssize_t pnp_show_options(struct device *dmdev,
221 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222{
223 struct pnp_dev *dev = to_pnp_dev(dmdev);
Bjorn Helgaasb72ee1f12008-06-27 16:57:02 -0600224 pnp_info_buffer_t *buffer;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700225 struct pnp_option *independent = dev->independent;
226 struct pnp_option *dependent = dev->dependent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 int ret, dep = 1;
228
Bjorn Helgaasb72ee1f12008-06-27 16:57:02 -0600229 buffer = pnp_alloc(sizeof(pnp_info_buffer_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 if (!buffer)
231 return -ENOMEM;
232
233 buffer->len = PAGE_SIZE;
234 buffer->buffer = buf;
235 buffer->curr = buffer->buffer;
236 if (independent)
237 pnp_print_option(buffer, "", independent, 0);
238
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700239 while (dependent) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 pnp_print_option(buffer, " ", dependent, dep);
241 dependent = dependent->next;
242 dep++;
243 }
244 ret = (buffer->curr - buf);
245 kfree(buffer);
246 return ret;
247}
248
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700249static DEVICE_ATTR(options, S_IRUGO, pnp_show_options, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700251static ssize_t pnp_show_current_resources(struct device *dmdev,
252 struct device_attribute *attr,
253 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
255 struct pnp_dev *dev = to_pnp_dev(dmdev);
Bjorn Helgaasb72ee1f12008-06-27 16:57:02 -0600256 pnp_info_buffer_t *buffer;
Bjorn Helgaasf61ed7e2008-06-27 16:57:00 -0600257 struct pnp_resource *pnp_res;
Bjorn Helgaas95ab3662008-04-28 16:34:26 -0600258 struct resource *res;
Bjorn Helgaasf61ed7e2008-06-27 16:57:00 -0600259 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
261 if (!dev)
262 return -EINVAL;
263
Bjorn Helgaasb72ee1f12008-06-27 16:57:02 -0600264 buffer = pnp_alloc(sizeof(pnp_info_buffer_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 if (!buffer)
266 return -ENOMEM;
Bjorn Helgaasb72ee1f12008-06-27 16:57:02 -0600267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 buffer->len = PAGE_SIZE;
269 buffer->buffer = buf;
270 buffer->curr = buffer->buffer;
271
Bjorn Helgaasf61ed7e2008-06-27 16:57:00 -0600272 pnp_printf(buffer, "state = %s\n", dev->active ? "active" : "disabled");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Bjorn Helgaasf61ed7e2008-06-27 16:57:00 -0600274 list_for_each_entry(pnp_res, &dev->resources, list) {
275 res = &pnp_res->res;
276
277 pnp_printf(buffer, pnp_resource_type_name(res));
278
279 if (res->flags & IORESOURCE_DISABLED) {
Bjorn Helgaasaee3ad82008-06-27 16:56:57 -0600280 pnp_printf(buffer, " disabled\n");
Bjorn Helgaasf61ed7e2008-06-27 16:57:00 -0600281 continue;
282 }
283
284 switch (pnp_resource_type(res)) {
285 case IORESOURCE_IO:
286 case IORESOURCE_MEM:
287 pnp_printf(buffer, " %#llx-%#llx\n",
Bjorn Helgaasaee3ad82008-06-27 16:56:57 -0600288 (unsigned long long) res->start,
289 (unsigned long long) res->end);
Bjorn Helgaasf61ed7e2008-06-27 16:57:00 -0600290 break;
291 case IORESOURCE_IRQ:
292 case IORESOURCE_DMA:
Bjorn Helgaasaee3ad82008-06-27 16:56:57 -0600293 pnp_printf(buffer, " %lld\n",
294 (unsigned long long) res->start);
Bjorn Helgaasf61ed7e2008-06-27 16:57:00 -0600295 break;
296 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 }
Bjorn Helgaasf61ed7e2008-06-27 16:57:00 -0600298
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 ret = (buffer->curr - buf);
300 kfree(buffer);
301 return ret;
302}
303
Bjorn Helgaasb72ee1f12008-06-27 16:57:02 -0600304static ssize_t pnp_set_current_resources(struct device *dmdev,
305 struct device_attribute *attr,
306 const char *ubuf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307{
308 struct pnp_dev *dev = to_pnp_dev(dmdev);
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700309 char *buf = (void *)ubuf;
310 int retval = 0;
Bjorn Helgaascc8c2e32008-04-28 16:34:36 -0600311 resource_size_t start, end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
313 if (dev->status & PNP_ATTACHED) {
314 retval = -EBUSY;
Bjorn Helgaasa05d0782007-10-16 23:31:10 -0700315 dev_info(&dev->dev, "in use; can't configure\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 goto done;
317 }
318
319 while (isspace(*buf))
320 ++buf;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700321 if (!strnicmp(buf, "disable", 7)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 retval = pnp_disable_dev(dev);
323 goto done;
324 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700325 if (!strnicmp(buf, "activate", 8)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 retval = pnp_activate_dev(dev);
327 goto done;
328 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700329 if (!strnicmp(buf, "fill", 4)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 if (dev->active)
331 goto done;
332 retval = pnp_auto_config_dev(dev);
333 goto done;
334 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700335 if (!strnicmp(buf, "auto", 4)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 if (dev->active)
337 goto done;
Bjorn Helgaasf4490002008-04-28 16:34:09 -0600338 pnp_init_resources(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 retval = pnp_auto_config_dev(dev);
340 goto done;
341 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700342 if (!strnicmp(buf, "clear", 5)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 if (dev->active)
344 goto done;
Bjorn Helgaasf4490002008-04-28 16:34:09 -0600345 pnp_init_resources(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 goto done;
347 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700348 if (!strnicmp(buf, "get", 3)) {
Daniel Walkerb3bd86e2008-02-06 01:40:04 -0800349 mutex_lock(&pnp_res_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 if (pnp_can_read(dev))
Bjorn Helgaas59284cb2008-04-28 16:34:05 -0600351 dev->protocol->get(dev);
Daniel Walkerb3bd86e2008-02-06 01:40:04 -0800352 mutex_unlock(&pnp_res_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 goto done;
354 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700355 if (!strnicmp(buf, "set", 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 if (dev->active)
357 goto done;
358 buf += 3;
Bjorn Helgaasf4490002008-04-28 16:34:09 -0600359 pnp_init_resources(dev);
Daniel Walkerb3bd86e2008-02-06 01:40:04 -0800360 mutex_lock(&pnp_res_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 while (1) {
362 while (isspace(*buf))
363 ++buf;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700364 if (!strnicmp(buf, "io", 2)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 buf += 2;
366 while (isspace(*buf))
367 ++buf;
Bjorn Helgaascc8c2e32008-04-28 16:34:36 -0600368 start = simple_strtoul(buf, &buf, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 while (isspace(*buf))
370 ++buf;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700371 if (*buf == '-') {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 buf += 1;
373 while (isspace(*buf))
374 ++buf;
Bjorn Helgaascc8c2e32008-04-28 16:34:36 -0600375 end = simple_strtoul(buf, &buf, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 } else
Bjorn Helgaascc8c2e32008-04-28 16:34:36 -0600377 end = start;
Bjorn Helgaas87e4acf2008-06-27 16:56:53 -0600378 pnp_add_io_resource(dev, start, end, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 continue;
380 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700381 if (!strnicmp(buf, "mem", 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 buf += 3;
383 while (isspace(*buf))
384 ++buf;
Bjorn Helgaasd6180f32008-04-28 16:34:37 -0600385 start = simple_strtoul(buf, &buf, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 while (isspace(*buf))
387 ++buf;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700388 if (*buf == '-') {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 buf += 1;
390 while (isspace(*buf))
391 ++buf;
Bjorn Helgaasd6180f32008-04-28 16:34:37 -0600392 end = simple_strtoul(buf, &buf, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 } else
Bjorn Helgaasd6180f32008-04-28 16:34:37 -0600394 end = start;
Bjorn Helgaas87e4acf2008-06-27 16:56:53 -0600395 pnp_add_mem_resource(dev, start, end, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 continue;
397 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700398 if (!strnicmp(buf, "irq", 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 buf += 3;
400 while (isspace(*buf))
401 ++buf;
Bjorn Helgaasdbddd032008-04-28 16:34:34 -0600402 start = simple_strtoul(buf, &buf, 0);
Bjorn Helgaas87e4acf2008-06-27 16:56:53 -0600403 pnp_add_irq_resource(dev, start, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 continue;
405 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700406 if (!strnicmp(buf, "dma", 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 buf += 3;
408 while (isspace(*buf))
409 ++buf;
Bjorn Helgaasdc16f5f2008-04-28 16:34:35 -0600410 start = simple_strtoul(buf, &buf, 0);
Bjorn Helgaas87e4acf2008-06-27 16:56:53 -0600411 pnp_add_dma_resource(dev, start, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 continue;
413 }
414 break;
415 }
Daniel Walkerb3bd86e2008-02-06 01:40:04 -0800416 mutex_unlock(&pnp_res_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 goto done;
418 }
Bjorn Helgaas1e0aa9a2007-08-15 10:32:08 -0600419
420done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 if (retval < 0)
422 return retval;
423 return count;
424}
425
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700426static DEVICE_ATTR(resources, S_IRUGO | S_IWUSR,
427 pnp_show_current_resources, pnp_set_current_resources);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700429static ssize_t pnp_show_current_ids(struct device *dmdev,
430 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431{
432 char *str = buf;
433 struct pnp_dev *dev = to_pnp_dev(dmdev);
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700434 struct pnp_id *pos = dev->id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
436 while (pos) {
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700437 str += sprintf(str, "%s\n", pos->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 pos = pos->next;
439 }
440 return (str - buf);
441}
442
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700443static DEVICE_ATTR(id, S_IRUGO, pnp_show_current_ids, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
445int pnp_interface_attach_device(struct pnp_dev *dev)
446{
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700447 int rc = device_create_file(&dev->dev, &dev_attr_options);
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700448
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700449 if (rc)
450 goto err;
451 rc = device_create_file(&dev->dev, &dev_attr_resources);
452 if (rc)
453 goto err_opt;
454 rc = device_create_file(&dev->dev, &dev_attr_id);
455 if (rc)
456 goto err_res;
Jeff Garzikbfc7ee22006-12-06 20:35:33 -0800457
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 return 0;
Jeff Garzikbfc7ee22006-12-06 20:35:33 -0800459
Bjorn Helgaas1e0aa9a2007-08-15 10:32:08 -0600460err_res:
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700461 device_remove_file(&dev->dev, &dev_attr_resources);
Bjorn Helgaas1e0aa9a2007-08-15 10:32:08 -0600462err_opt:
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700463 device_remove_file(&dev->dev, &dev_attr_options);
Bjorn Helgaas1e0aa9a2007-08-15 10:32:08 -0600464err:
Jeff Garzikbfc7ee22006-12-06 20:35:33 -0800465 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466}