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