]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/pnp/pnpbios/rsparser.c
7f8d657285992c7f132c1a1903104fea213ae590
[linux-2.6-omap-h63xx.git] / drivers / pnp / pnpbios / rsparser.c
1 /*
2  * rsparser.c - parses and encodes pnpbios resource data streams
3  */
4
5 #include <linux/ctype.h>
6 #include <linux/pnp.h>
7 #include <linux/pnpbios.h>
8 #include <linux/string.h>
9 #include <linux/slab.h>
10
11 #ifdef CONFIG_PCI
12 #include <linux/pci.h>
13 #else
14 inline void pcibios_penalize_isa_irq(int irq, int active)
15 {
16 }
17 #endif                          /* CONFIG_PCI */
18
19 #include "../base.h"
20 #include "pnpbios.h"
21
22 /* standard resource tags */
23 #define SMALL_TAG_PNPVERNO              0x01
24 #define SMALL_TAG_LOGDEVID              0x02
25 #define SMALL_TAG_COMPATDEVID           0x03
26 #define SMALL_TAG_IRQ                   0x04
27 #define SMALL_TAG_DMA                   0x05
28 #define SMALL_TAG_STARTDEP              0x06
29 #define SMALL_TAG_ENDDEP                0x07
30 #define SMALL_TAG_PORT                  0x08
31 #define SMALL_TAG_FIXEDPORT             0x09
32 #define SMALL_TAG_VENDOR                0x0e
33 #define SMALL_TAG_END                   0x0f
34 #define LARGE_TAG                       0x80
35 #define LARGE_TAG_MEM                   0x81
36 #define LARGE_TAG_ANSISTR               0x82
37 #define LARGE_TAG_UNICODESTR            0x83
38 #define LARGE_TAG_VENDOR                0x84
39 #define LARGE_TAG_MEM32                 0x85
40 #define LARGE_TAG_FIXEDMEM32            0x86
41
42 /*
43  * Resource Data Stream Format:
44  *
45  * Allocated Resources (required)
46  * end tag ->
47  * Resource Configuration Options (optional)
48  * end tag ->
49  * Compitable Device IDs (optional)
50  * final end tag ->
51  */
52
53 /*
54  * Allocated Resources
55  */
56
57 static void pnpbios_parse_allocated_ioresource(struct pnp_dev *dev,
58                                                int io, int len)
59 {
60         struct resource *res;
61         int i;
62
63         for (i = 0; i < PNP_MAX_PORT; i++) {
64                 res = pnp_get_resource(dev, IORESOURCE_IO, i);
65                 if (!pnp_resource_valid(res))
66                         break;
67         }
68
69         if (i < PNP_MAX_PORT) {
70                 res->flags = IORESOURCE_IO;     // Also clears _UNSET flag
71                 if (len <= 0 || (io + len - 1) >= 0x10003) {
72                         res->flags |= IORESOURCE_DISABLED;
73                         return;
74                 }
75                 res->start = (unsigned long)io;
76                 res->end = (unsigned long)(io + len - 1);
77         }
78 }
79
80 static void pnpbios_parse_allocated_memresource(struct pnp_dev *dev,
81                                                 int mem, int len)
82 {
83         struct resource *res;
84         int i;
85
86         for (i = 0; i < PNP_MAX_MEM; i++) {
87                 res = pnp_get_resource(dev, IORESOURCE_MEM, i);
88                 if (!pnp_resource_valid(res))
89                         break;
90         }
91
92         if (i < PNP_MAX_MEM) {
93                 res->flags = IORESOURCE_MEM;    // Also clears _UNSET flag
94                 if (len <= 0) {
95                         res->flags |= IORESOURCE_DISABLED;
96                         return;
97                 }
98                 res->start = (unsigned long)mem;
99                 res->end = (unsigned long)(mem + len - 1);
100         }
101 }
102
103 static unsigned char *pnpbios_parse_allocated_resource_data(struct pnp_dev *dev,
104                                                             unsigned char *p,
105                                                             unsigned char *end)
106 {
107         unsigned int len, tag;
108         int io, size, mask, i, flags;
109
110         if (!p)
111                 return NULL;
112
113         dev_dbg(&dev->dev, "parse allocated resources\n");
114
115         pnp_init_resources(dev);
116
117         while ((char *)p < (char *)end) {
118
119                 /* determine the type of tag */
120                 if (p[0] & LARGE_TAG) { /* large tag */
121                         len = (p[2] << 8) | p[1];
122                         tag = p[0];
123                 } else {        /* small tag */
124                         len = p[0] & 0x07;
125                         tag = ((p[0] >> 3) & 0x0f);
126                 }
127
128                 switch (tag) {
129
130                 case LARGE_TAG_MEM:
131                         if (len != 9)
132                                 goto len_err;
133                         io = *(short *)&p[4];
134                         size = *(short *)&p[10];
135                         pnpbios_parse_allocated_memresource(dev, io, size);
136                         break;
137
138                 case LARGE_TAG_ANSISTR:
139                         /* ignore this for now */
140                         break;
141
142                 case LARGE_TAG_VENDOR:
143                         /* do nothing */
144                         break;
145
146                 case LARGE_TAG_MEM32:
147                         if (len != 17)
148                                 goto len_err;
149                         io = *(int *)&p[4];
150                         size = *(int *)&p[16];
151                         pnpbios_parse_allocated_memresource(dev, io, size);
152                         break;
153
154                 case LARGE_TAG_FIXEDMEM32:
155                         if (len != 9)
156                                 goto len_err;
157                         io = *(int *)&p[4];
158                         size = *(int *)&p[8];
159                         pnpbios_parse_allocated_memresource(dev, io, size);
160                         break;
161
162                 case SMALL_TAG_IRQ:
163                         if (len < 2 || len > 3)
164                                 goto len_err;
165                         flags = 0;
166                         io = -1;
167                         mask = p[1] + p[2] * 256;
168                         for (i = 0; i < 16; i++, mask = mask >> 1)
169                                 if (mask & 0x01)
170                                         io = i;
171                         if (io != -1)
172                                 pcibios_penalize_isa_irq(io, 1);
173                         else
174                                 flags = IORESOURCE_DISABLED;
175                         pnp_add_irq_resource(dev, io, flags);
176                         break;
177
178                 case SMALL_TAG_DMA:
179                         if (len != 2)
180                                 goto len_err;
181                         flags = 0;
182                         io = -1;
183                         mask = p[1];
184                         for (i = 0; i < 8; i++, mask = mask >> 1)
185                                 if (mask & 0x01)
186                                         io = i;
187                         if (io == -1)
188                                 flags = IORESOURCE_DISABLED;
189                         pnp_add_dma_resource(dev, io, flags);
190                         break;
191
192                 case SMALL_TAG_PORT:
193                         if (len != 7)
194                                 goto len_err;
195                         io = p[2] + p[3] * 256;
196                         size = p[7];
197                         pnpbios_parse_allocated_ioresource(dev, io, size);
198                         break;
199
200                 case SMALL_TAG_VENDOR:
201                         /* do nothing */
202                         break;
203
204                 case SMALL_TAG_FIXEDPORT:
205                         if (len != 3)
206                                 goto len_err;
207                         io = p[1] + p[2] * 256;
208                         size = p[3];
209                         pnpbios_parse_allocated_ioresource(dev, io, size);
210                         break;
211
212                 case SMALL_TAG_END:
213                         p = p + 2;
214                         return (unsigned char *)p;
215                         break;
216
217                 default:        /* an unkown tag */
218 len_err:
219                         dev_err(&dev->dev, "unknown tag %#x length %d\n",
220                                 tag, len);
221                         break;
222                 }
223
224                 /* continue to the next tag */
225                 if (p[0] & LARGE_TAG)
226                         p += len + 3;
227                 else
228                         p += len + 1;
229         }
230
231         dev_err(&dev->dev, "no end tag in resource structure\n");
232
233         return NULL;
234 }
235
236 /*
237  * Resource Configuration Options
238  */
239
240 static __init void pnpbios_parse_mem_option(struct pnp_dev *dev,
241                                             unsigned char *p, int size,
242                                             struct pnp_option *option)
243 {
244         struct pnp_mem *mem;
245
246         mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
247         if (!mem)
248                 return;
249         mem->min = ((p[5] << 8) | p[4]) << 8;
250         mem->max = ((p[7] << 8) | p[6]) << 8;
251         mem->align = (p[9] << 8) | p[8];
252         mem->size = ((p[11] << 8) | p[10]) << 8;
253         mem->flags = p[3];
254         pnp_register_mem_resource(dev, option, mem);
255 }
256
257 static __init void pnpbios_parse_mem32_option(struct pnp_dev *dev,
258                                               unsigned char *p, int size,
259                                               struct pnp_option *option)
260 {
261         struct pnp_mem *mem;
262
263         mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
264         if (!mem)
265                 return;
266         mem->min = (p[7] << 24) | (p[6] << 16) | (p[5] << 8) | p[4];
267         mem->max = (p[11] << 24) | (p[10] << 16) | (p[9] << 8) | p[8];
268         mem->align = (p[15] << 24) | (p[14] << 16) | (p[13] << 8) | p[12];
269         mem->size = (p[19] << 24) | (p[18] << 16) | (p[17] << 8) | p[16];
270         mem->flags = p[3];
271         pnp_register_mem_resource(dev, option, mem);
272 }
273
274 static __init void pnpbios_parse_fixed_mem32_option(struct pnp_dev *dev,
275                                                     unsigned char *p, int size,
276                                                     struct pnp_option *option)
277 {
278         struct pnp_mem *mem;
279
280         mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
281         if (!mem)
282                 return;
283         mem->min = mem->max = (p[7] << 24) | (p[6] << 16) | (p[5] << 8) | p[4];
284         mem->size = (p[11] << 24) | (p[10] << 16) | (p[9] << 8) | p[8];
285         mem->align = 0;
286         mem->flags = p[3];
287         pnp_register_mem_resource(dev, option, mem);
288 }
289
290 static __init void pnpbios_parse_irq_option(struct pnp_dev *dev,
291                                             unsigned char *p, int size,
292                                             struct pnp_option *option)
293 {
294         struct pnp_irq *irq;
295         unsigned long bits;
296
297         irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
298         if (!irq)
299                 return;
300         bits = (p[2] << 8) | p[1];
301         bitmap_copy(irq->map, &bits, 16);
302         if (size > 2)
303                 irq->flags = p[3];
304         else
305                 irq->flags = IORESOURCE_IRQ_HIGHEDGE;
306         pnp_register_irq_resource(dev, option, irq);
307 }
308
309 static __init void pnpbios_parse_dma_option(struct pnp_dev *dev,
310                                             unsigned char *p, int size,
311                                             struct pnp_option *option)
312 {
313         struct pnp_dma *dma;
314
315         dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL);
316         if (!dma)
317                 return;
318         dma->map = p[1];
319         dma->flags = p[2];
320         pnp_register_dma_resource(dev, option, dma);
321 }
322
323 static __init void pnpbios_parse_port_option(struct pnp_dev *dev,
324                                              unsigned char *p, int size,
325                                              struct pnp_option *option)
326 {
327         struct pnp_port *port;
328
329         port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
330         if (!port)
331                 return;
332         port->min = (p[3] << 8) | p[2];
333         port->max = (p[5] << 8) | p[4];
334         port->align = p[6];
335         port->size = p[7];
336         port->flags = p[1] ? PNP_PORT_FLAG_16BITADDR : 0;
337         pnp_register_port_resource(dev, option, port);
338 }
339
340 static __init void pnpbios_parse_fixed_port_option(struct pnp_dev *dev,
341                                                    unsigned char *p, int size,
342                                                    struct pnp_option *option)
343 {
344         struct pnp_port *port;
345
346         port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
347         if (!port)
348                 return;
349         port->min = port->max = (p[2] << 8) | p[1];
350         port->size = p[3];
351         port->align = 0;
352         port->flags = PNP_PORT_FLAG_FIXED;
353         pnp_register_port_resource(dev, option, port);
354 }
355
356 static __init unsigned char *
357 pnpbios_parse_resource_option_data(unsigned char *p, unsigned char *end,
358                                         struct pnp_dev *dev)
359 {
360         unsigned int len, tag;
361         int priority = 0;
362         struct pnp_option *option, *option_independent;
363
364         if (!p)
365                 return NULL;
366
367         dev_dbg(&dev->dev, "parse resource options\n");
368
369         option_independent = option = pnp_register_independent_option(dev);
370         if (!option)
371                 return NULL;
372
373         while ((char *)p < (char *)end) {
374
375                 /* determine the type of tag */
376                 if (p[0] & LARGE_TAG) { /* large tag */
377                         len = (p[2] << 8) | p[1];
378                         tag = p[0];
379                 } else {        /* small tag */
380                         len = p[0] & 0x07;
381                         tag = ((p[0] >> 3) & 0x0f);
382                 }
383
384                 switch (tag) {
385
386                 case LARGE_TAG_MEM:
387                         if (len != 9)
388                                 goto len_err;
389                         pnpbios_parse_mem_option(dev, p, len, option);
390                         break;
391
392                 case LARGE_TAG_MEM32:
393                         if (len != 17)
394                                 goto len_err;
395                         pnpbios_parse_mem32_option(dev, p, len, option);
396                         break;
397
398                 case LARGE_TAG_FIXEDMEM32:
399                         if (len != 9)
400                                 goto len_err;
401                         pnpbios_parse_fixed_mem32_option(dev, p, len, option);
402                         break;
403
404                 case SMALL_TAG_IRQ:
405                         if (len < 2 || len > 3)
406                                 goto len_err;
407                         pnpbios_parse_irq_option(dev, p, len, option);
408                         break;
409
410                 case SMALL_TAG_DMA:
411                         if (len != 2)
412                                 goto len_err;
413                         pnpbios_parse_dma_option(dev, p, len, option);
414                         break;
415
416                 case SMALL_TAG_PORT:
417                         if (len != 7)
418                                 goto len_err;
419                         pnpbios_parse_port_option(dev, p, len, option);
420                         break;
421
422                 case SMALL_TAG_VENDOR:
423                         /* do nothing */
424                         break;
425
426                 case SMALL_TAG_FIXEDPORT:
427                         if (len != 3)
428                                 goto len_err;
429                         pnpbios_parse_fixed_port_option(dev, p, len, option);
430                         break;
431
432                 case SMALL_TAG_STARTDEP:
433                         if (len > 1)
434                                 goto len_err;
435                         priority = 0x100 | PNP_RES_PRIORITY_ACCEPTABLE;
436                         if (len > 0)
437                                 priority = 0x100 | p[1];
438                         option = pnp_register_dependent_option(dev, priority);
439                         if (!option)
440                                 return NULL;
441                         break;
442
443                 case SMALL_TAG_ENDDEP:
444                         if (len != 0)
445                                 goto len_err;
446                         if (option_independent == option)
447                                 dev_warn(&dev->dev, "missing "
448                                          "SMALL_TAG_STARTDEP tag\n");
449                         option = option_independent;
450                         dev_dbg(&dev->dev, "end dependent options\n");
451                         break;
452
453                 case SMALL_TAG_END:
454                         return p + 2;
455
456                 default:        /* an unkown tag */
457 len_err:
458                         dev_err(&dev->dev, "unknown tag %#x length %d\n",
459                                 tag, len);
460                         break;
461                 }
462
463                 /* continue to the next tag */
464                 if (p[0] & LARGE_TAG)
465                         p += len + 3;
466                 else
467                         p += len + 1;
468         }
469
470         dev_err(&dev->dev, "no end tag in resource structure\n");
471
472         return NULL;
473 }
474
475 /*
476  * Compatible Device IDs
477  */
478
479 static unsigned char *pnpbios_parse_compatible_ids(unsigned char *p,
480                                                    unsigned char *end,
481                                                    struct pnp_dev *dev)
482 {
483         int len, tag;
484         u32 eisa_id;
485         char id[8];
486         struct pnp_id *dev_id;
487
488         if (!p)
489                 return NULL;
490
491         while ((char *)p < (char *)end) {
492
493                 /* determine the type of tag */
494                 if (p[0] & LARGE_TAG) { /* large tag */
495                         len = (p[2] << 8) | p[1];
496                         tag = p[0];
497                 } else {        /* small tag */
498                         len = p[0] & 0x07;
499                         tag = ((p[0] >> 3) & 0x0f);
500                 }
501
502                 switch (tag) {
503
504                 case LARGE_TAG_ANSISTR:
505                         strncpy(dev->name, p + 3,
506                                 len >= PNP_NAME_LEN ? PNP_NAME_LEN - 2 : len);
507                         dev->name[len >=
508                                   PNP_NAME_LEN ? PNP_NAME_LEN - 1 : len] = '\0';
509                         break;
510
511                 case SMALL_TAG_COMPATDEVID:     /* compatible ID */
512                         if (len != 4)
513                                 goto len_err;
514                         eisa_id = p[1] | p[2] << 8 | p[3] << 16 | p[4] << 24;
515                         pnp_eisa_id_to_string(eisa_id & PNP_EISA_ID_MASK, id);
516                         dev_id = pnp_add_id(dev, id);
517                         if (!dev_id)
518                                 return NULL;
519                         break;
520
521                 case SMALL_TAG_END:
522                         p = p + 2;
523                         return (unsigned char *)p;
524                         break;
525
526                 default:        /* an unkown tag */
527 len_err:
528                         dev_err(&dev->dev, "unknown tag %#x length %d\n",
529                                 tag, len);
530                         break;
531                 }
532
533                 /* continue to the next tag */
534                 if (p[0] & LARGE_TAG)
535                         p += len + 3;
536                 else
537                         p += len + 1;
538         }
539
540         dev_err(&dev->dev, "no end tag in resource structure\n");
541
542         return NULL;
543 }
544
545 /*
546  * Allocated Resource Encoding
547  */
548
549 static void pnpbios_encode_mem(struct pnp_dev *dev, unsigned char *p,
550                                struct resource *res)
551 {
552         unsigned long base = res->start;
553         unsigned long len = res->end - res->start + 1;
554
555         p[4] = (base >> 8) & 0xff;
556         p[5] = ((base >> 8) >> 8) & 0xff;
557         p[6] = (base >> 8) & 0xff;
558         p[7] = ((base >> 8) >> 8) & 0xff;
559         p[10] = (len >> 8) & 0xff;
560         p[11] = ((len >> 8) >> 8) & 0xff;
561
562         dev_dbg(&dev->dev, "  encode mem %#llx-%#llx\n",
563                 (unsigned long long) res->start, (unsigned long long) res->end);
564 }
565
566 static void pnpbios_encode_mem32(struct pnp_dev *dev, unsigned char *p,
567                                  struct resource *res)
568 {
569         unsigned long base = res->start;
570         unsigned long len = res->end - res->start + 1;
571
572         p[4] = base & 0xff;
573         p[5] = (base >> 8) & 0xff;
574         p[6] = (base >> 16) & 0xff;
575         p[7] = (base >> 24) & 0xff;
576         p[8] = base & 0xff;
577         p[9] = (base >> 8) & 0xff;
578         p[10] = (base >> 16) & 0xff;
579         p[11] = (base >> 24) & 0xff;
580         p[16] = len & 0xff;
581         p[17] = (len >> 8) & 0xff;
582         p[18] = (len >> 16) & 0xff;
583         p[19] = (len >> 24) & 0xff;
584
585         dev_dbg(&dev->dev, "  encode mem32 %#llx-%#llx\n",
586                 (unsigned long long) res->start, (unsigned long long) res->end);
587 }
588
589 static void pnpbios_encode_fixed_mem32(struct pnp_dev *dev, unsigned char *p,
590                                        struct resource *res)
591 {
592         unsigned long base = res->start;
593         unsigned long len = res->end - res->start + 1;
594
595         p[4] = base & 0xff;
596         p[5] = (base >> 8) & 0xff;
597         p[6] = (base >> 16) & 0xff;
598         p[7] = (base >> 24) & 0xff;
599         p[8] = len & 0xff;
600         p[9] = (len >> 8) & 0xff;
601         p[10] = (len >> 16) & 0xff;
602         p[11] = (len >> 24) & 0xff;
603
604         dev_dbg(&dev->dev, "  encode fixed_mem32 %#llx-%#llx\n",
605                 (unsigned long long) res->start, (unsigned long long) res->end);
606 }
607
608 static void pnpbios_encode_irq(struct pnp_dev *dev, unsigned char *p,
609                                struct resource *res)
610 {
611         unsigned long map = 0;
612
613         map = 1 << res->start;
614         p[1] = map & 0xff;
615         p[2] = (map >> 8) & 0xff;
616
617         dev_dbg(&dev->dev, "  encode irq %d\n", res->start);
618 }
619
620 static void pnpbios_encode_dma(struct pnp_dev *dev, unsigned char *p,
621                                struct resource *res)
622 {
623         unsigned long map = 0;
624
625         map = 1 << res->start;
626         p[1] = map & 0xff;
627
628         dev_dbg(&dev->dev, "  encode dma %d\n", res->start);
629 }
630
631 static void pnpbios_encode_port(struct pnp_dev *dev, unsigned char *p,
632                                 struct resource *res)
633 {
634         unsigned long base = res->start;
635         unsigned long len = res->end - res->start + 1;
636
637         p[2] = base & 0xff;
638         p[3] = (base >> 8) & 0xff;
639         p[4] = base & 0xff;
640         p[5] = (base >> 8) & 0xff;
641         p[7] = len & 0xff;
642
643         dev_dbg(&dev->dev, "  encode io %#llx-%#llx\n",
644                 (unsigned long long) res->start, (unsigned long long) res->end);
645 }
646
647 static void pnpbios_encode_fixed_port(struct pnp_dev *dev, unsigned char *p,
648                                       struct resource *res)
649 {
650         unsigned long base = res->start;
651         unsigned long len = res->end - res->start + 1;
652
653         p[1] = base & 0xff;
654         p[2] = (base >> 8) & 0xff;
655         p[3] = len & 0xff;
656
657         dev_dbg(&dev->dev, "  encode fixed_io %#llx-%#llx\n",
658                 (unsigned long long) res->start, (unsigned long long) res->end);
659 }
660
661 static unsigned char *pnpbios_encode_allocated_resource_data(struct pnp_dev
662                                                                 *dev,
663                                                              unsigned char *p,
664                                                              unsigned char *end)
665 {
666         unsigned int len, tag;
667         int port = 0, irq = 0, dma = 0, mem = 0;
668
669         if (!p)
670                 return NULL;
671
672         while ((char *)p < (char *)end) {
673
674                 /* determine the type of tag */
675                 if (p[0] & LARGE_TAG) { /* large tag */
676                         len = (p[2] << 8) | p[1];
677                         tag = p[0];
678                 } else {        /* small tag */
679                         len = p[0] & 0x07;
680                         tag = ((p[0] >> 3) & 0x0f);
681                 }
682
683                 switch (tag) {
684
685                 case LARGE_TAG_MEM:
686                         if (len != 9)
687                                 goto len_err;
688                         pnpbios_encode_mem(dev, p,
689                                 pnp_get_resource(dev, IORESOURCE_MEM, mem));
690                         mem++;
691                         break;
692
693                 case LARGE_TAG_MEM32:
694                         if (len != 17)
695                                 goto len_err;
696                         pnpbios_encode_mem32(dev, p,
697                                 pnp_get_resource(dev, IORESOURCE_MEM, mem));
698                         mem++;
699                         break;
700
701                 case LARGE_TAG_FIXEDMEM32:
702                         if (len != 9)
703                                 goto len_err;
704                         pnpbios_encode_fixed_mem32(dev, p,
705                                 pnp_get_resource(dev, IORESOURCE_MEM, mem));
706                         mem++;
707                         break;
708
709                 case SMALL_TAG_IRQ:
710                         if (len < 2 || len > 3)
711                                 goto len_err;
712                         pnpbios_encode_irq(dev, p,
713                                 pnp_get_resource(dev, IORESOURCE_IRQ, irq));
714                         irq++;
715                         break;
716
717                 case SMALL_TAG_DMA:
718                         if (len != 2)
719                                 goto len_err;
720                         pnpbios_encode_dma(dev, p,
721                                 pnp_get_resource(dev, IORESOURCE_DMA, dma));
722                         dma++;
723                         break;
724
725                 case SMALL_TAG_PORT:
726                         if (len != 7)
727                                 goto len_err;
728                         pnpbios_encode_port(dev, p,
729                                 pnp_get_resource(dev, IORESOURCE_IO, port));
730                         port++;
731                         break;
732
733                 case SMALL_TAG_VENDOR:
734                         /* do nothing */
735                         break;
736
737                 case SMALL_TAG_FIXEDPORT:
738                         if (len != 3)
739                                 goto len_err;
740                         pnpbios_encode_fixed_port(dev, p,
741                                 pnp_get_resource(dev, IORESOURCE_IO, port));
742                         port++;
743                         break;
744
745                 case SMALL_TAG_END:
746                         p = p + 2;
747                         return (unsigned char *)p;
748                         break;
749
750                 default:        /* an unkown tag */
751 len_err:
752                         dev_err(&dev->dev, "unknown tag %#x length %d\n",
753                                 tag, len);
754                         break;
755                 }
756
757                 /* continue to the next tag */
758                 if (p[0] & LARGE_TAG)
759                         p += len + 3;
760                 else
761                         p += len + 1;
762         }
763
764         dev_err(&dev->dev, "no end tag in resource structure\n");
765
766         return NULL;
767 }
768
769 /*
770  * Core Parsing Functions
771  */
772
773 int __init pnpbios_parse_data_stream(struct pnp_dev *dev,
774                                         struct pnp_bios_node *node)
775 {
776         unsigned char *p = (char *)node->data;
777         unsigned char *end = (char *)(node->data + node->size);
778
779         p = pnpbios_parse_allocated_resource_data(dev, p, end);
780         if (!p)
781                 return -EIO;
782         p = pnpbios_parse_resource_option_data(p, end, dev);
783         if (!p)
784                 return -EIO;
785         p = pnpbios_parse_compatible_ids(p, end, dev);
786         if (!p)
787                 return -EIO;
788         return 0;
789 }
790
791 int pnpbios_read_resources_from_node(struct pnp_dev *dev,
792                                      struct pnp_bios_node *node)
793 {
794         unsigned char *p = (char *)node->data;
795         unsigned char *end = (char *)(node->data + node->size);
796
797         p = pnpbios_parse_allocated_resource_data(dev, p, end);
798         if (!p)
799                 return -EIO;
800         return 0;
801 }
802
803 int pnpbios_write_resources_to_node(struct pnp_dev *dev,
804                                     struct pnp_bios_node *node)
805 {
806         unsigned char *p = (char *)node->data;
807         unsigned char *end = (char *)(node->data + node->size);
808
809         p = pnpbios_encode_allocated_resource_data(dev, p, end);
810         if (!p)
811                 return -EIO;
812         return 0;
813 }