]> err.no Git - linux-2.6/blob - drivers/pnp/pnpbios/rsparser.c
PNP: change pnp_add_id() to allocate its own pnp_id structures
[linux-2.6] / 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_irqresource(struct pnp_resource_table *res,
58                                                 int irq)
59 {
60         int i = 0;
61
62         while (!(res->irq_resource[i].flags & IORESOURCE_UNSET)
63                && i < PNP_MAX_IRQ)
64                 i++;
65         if (i < PNP_MAX_IRQ) {
66                 res->irq_resource[i].flags = IORESOURCE_IRQ;    // Also clears _UNSET flag
67                 if (irq == -1) {
68                         res->irq_resource[i].flags |= IORESOURCE_DISABLED;
69                         return;
70                 }
71                 res->irq_resource[i].start =
72                     res->irq_resource[i].end = (unsigned long)irq;
73                 pcibios_penalize_isa_irq(irq, 1);
74         }
75 }
76
77 static void pnpbios_parse_allocated_dmaresource(struct pnp_resource_table *res,
78                                                 int dma)
79 {
80         int i = 0;
81
82         while (i < PNP_MAX_DMA &&
83                !(res->dma_resource[i].flags & IORESOURCE_UNSET))
84                 i++;
85         if (i < PNP_MAX_DMA) {
86                 res->dma_resource[i].flags = IORESOURCE_DMA;    // Also clears _UNSET flag
87                 if (dma == -1) {
88                         res->dma_resource[i].flags |= IORESOURCE_DISABLED;
89                         return;
90                 }
91                 res->dma_resource[i].start =
92                     res->dma_resource[i].end = (unsigned long)dma;
93         }
94 }
95
96 static void pnpbios_parse_allocated_ioresource(struct pnp_resource_table *res,
97                                                int io, int len)
98 {
99         int i = 0;
100
101         while (!(res->port_resource[i].flags & IORESOURCE_UNSET)
102                && i < PNP_MAX_PORT)
103                 i++;
104         if (i < PNP_MAX_PORT) {
105                 res->port_resource[i].flags = IORESOURCE_IO;    // Also clears _UNSET flag
106                 if (len <= 0 || (io + len - 1) >= 0x10003) {
107                         res->port_resource[i].flags |= IORESOURCE_DISABLED;
108                         return;
109                 }
110                 res->port_resource[i].start = (unsigned long)io;
111                 res->port_resource[i].end = (unsigned long)(io + len - 1);
112         }
113 }
114
115 static void pnpbios_parse_allocated_memresource(struct pnp_resource_table *res,
116                                                 int mem, int len)
117 {
118         int i = 0;
119
120         while (!(res->mem_resource[i].flags & IORESOURCE_UNSET)
121                && i < PNP_MAX_MEM)
122                 i++;
123         if (i < PNP_MAX_MEM) {
124                 res->mem_resource[i].flags = IORESOURCE_MEM;    // Also clears _UNSET flag
125                 if (len <= 0) {
126                         res->mem_resource[i].flags |= IORESOURCE_DISABLED;
127                         return;
128                 }
129                 res->mem_resource[i].start = (unsigned long)mem;
130                 res->mem_resource[i].end = (unsigned long)(mem + len - 1);
131         }
132 }
133
134 static unsigned char *pnpbios_parse_allocated_resource_data(unsigned char *p,
135                                                             unsigned char *end,
136                                                             struct
137                                                             pnp_resource_table
138                                                             *res)
139 {
140         unsigned int len, tag;
141         int io, size, mask, i;
142
143         if (!p)
144                 return NULL;
145
146         /* Blank the resource table values */
147         pnp_init_resource_table(res);
148
149         while ((char *)p < (char *)end) {
150
151                 /* determine the type of tag */
152                 if (p[0] & LARGE_TAG) { /* large tag */
153                         len = (p[2] << 8) | p[1];
154                         tag = p[0];
155                 } else {        /* small tag */
156                         len = p[0] & 0x07;
157                         tag = ((p[0] >> 3) & 0x0f);
158                 }
159
160                 switch (tag) {
161
162                 case LARGE_TAG_MEM:
163                         if (len != 9)
164                                 goto len_err;
165                         io = *(short *)&p[4];
166                         size = *(short *)&p[10];
167                         pnpbios_parse_allocated_memresource(res, io, size);
168                         break;
169
170                 case LARGE_TAG_ANSISTR:
171                         /* ignore this for now */
172                         break;
173
174                 case LARGE_TAG_VENDOR:
175                         /* do nothing */
176                         break;
177
178                 case LARGE_TAG_MEM32:
179                         if (len != 17)
180                                 goto len_err;
181                         io = *(int *)&p[4];
182                         size = *(int *)&p[16];
183                         pnpbios_parse_allocated_memresource(res, io, size);
184                         break;
185
186                 case LARGE_TAG_FIXEDMEM32:
187                         if (len != 9)
188                                 goto len_err;
189                         io = *(int *)&p[4];
190                         size = *(int *)&p[8];
191                         pnpbios_parse_allocated_memresource(res, io, size);
192                         break;
193
194                 case SMALL_TAG_IRQ:
195                         if (len < 2 || len > 3)
196                                 goto len_err;
197                         io = -1;
198                         mask = p[1] + p[2] * 256;
199                         for (i = 0; i < 16; i++, mask = mask >> 1)
200                                 if (mask & 0x01)
201                                         io = i;
202                         pnpbios_parse_allocated_irqresource(res, io);
203                         break;
204
205                 case SMALL_TAG_DMA:
206                         if (len != 2)
207                                 goto len_err;
208                         io = -1;
209                         mask = p[1];
210                         for (i = 0; i < 8; i++, mask = mask >> 1)
211                                 if (mask & 0x01)
212                                         io = i;
213                         pnpbios_parse_allocated_dmaresource(res, io);
214                         break;
215
216                 case SMALL_TAG_PORT:
217                         if (len != 7)
218                                 goto len_err;
219                         io = p[2] + p[3] * 256;
220                         size = p[7];
221                         pnpbios_parse_allocated_ioresource(res, io, size);
222                         break;
223
224                 case SMALL_TAG_VENDOR:
225                         /* do nothing */
226                         break;
227
228                 case SMALL_TAG_FIXEDPORT:
229                         if (len != 3)
230                                 goto len_err;
231                         io = p[1] + p[2] * 256;
232                         size = p[3];
233                         pnpbios_parse_allocated_ioresource(res, io, size);
234                         break;
235
236                 case SMALL_TAG_END:
237                         p = p + 2;
238                         return (unsigned char *)p;
239                         break;
240
241                 default:        /* an unkown tag */
242 len_err:
243                         printk(KERN_ERR
244                                "PnPBIOS: Unknown tag '0x%x', length '%d'.\n",
245                                tag, len);
246                         break;
247                 }
248
249                 /* continue to the next tag */
250                 if (p[0] & LARGE_TAG)
251                         p += len + 3;
252                 else
253                         p += len + 1;
254         }
255
256         printk(KERN_ERR
257                "PnPBIOS: Resource structure does not contain an end tag.\n");
258
259         return NULL;
260 }
261
262 /*
263  * Resource Configuration Options
264  */
265
266 static __init void pnpbios_parse_mem_option(unsigned char *p, int size,
267                                             struct pnp_option *option)
268 {
269         struct pnp_mem *mem;
270
271         mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
272         if (!mem)
273                 return;
274         mem->min = ((p[5] << 8) | p[4]) << 8;
275         mem->max = ((p[7] << 8) | p[6]) << 8;
276         mem->align = (p[9] << 8) | p[8];
277         mem->size = ((p[11] << 8) | p[10]) << 8;
278         mem->flags = p[3];
279         pnp_register_mem_resource(option, mem);
280 }
281
282 static __init void pnpbios_parse_mem32_option(unsigned char *p, int size,
283                                               struct pnp_option *option)
284 {
285         struct pnp_mem *mem;
286
287         mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
288         if (!mem)
289                 return;
290         mem->min = (p[7] << 24) | (p[6] << 16) | (p[5] << 8) | p[4];
291         mem->max = (p[11] << 24) | (p[10] << 16) | (p[9] << 8) | p[8];
292         mem->align = (p[15] << 24) | (p[14] << 16) | (p[13] << 8) | p[12];
293         mem->size = (p[19] << 24) | (p[18] << 16) | (p[17] << 8) | p[16];
294         mem->flags = p[3];
295         pnp_register_mem_resource(option, mem);
296 }
297
298 static __init void pnpbios_parse_fixed_mem32_option(unsigned char *p, int size,
299                                                     struct pnp_option *option)
300 {
301         struct pnp_mem *mem;
302
303         mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
304         if (!mem)
305                 return;
306         mem->min = mem->max = (p[7] << 24) | (p[6] << 16) | (p[5] << 8) | p[4];
307         mem->size = (p[11] << 24) | (p[10] << 16) | (p[9] << 8) | p[8];
308         mem->align = 0;
309         mem->flags = p[3];
310         pnp_register_mem_resource(option, mem);
311 }
312
313 static __init void pnpbios_parse_irq_option(unsigned char *p, int size,
314                                      struct pnp_option *option)
315 {
316         struct pnp_irq *irq;
317         unsigned long bits;
318
319         irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
320         if (!irq)
321                 return;
322         bits = (p[2] << 8) | p[1];
323         bitmap_copy(irq->map, &bits, 16);
324         if (size > 2)
325                 irq->flags = p[3];
326         else
327                 irq->flags = IORESOURCE_IRQ_HIGHEDGE;
328         pnp_register_irq_resource(option, irq);
329 }
330
331 static __init void pnpbios_parse_dma_option(unsigned char *p, int size,
332                                      struct pnp_option *option)
333 {
334         struct pnp_dma *dma;
335
336         dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL);
337         if (!dma)
338                 return;
339         dma->map = p[1];
340         dma->flags = p[2];
341         pnp_register_dma_resource(option, dma);
342 }
343
344 static __init void pnpbios_parse_port_option(unsigned char *p, int size,
345                                              struct pnp_option *option)
346 {
347         struct pnp_port *port;
348
349         port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
350         if (!port)
351                 return;
352         port->min = (p[3] << 8) | p[2];
353         port->max = (p[5] << 8) | p[4];
354         port->align = p[6];
355         port->size = p[7];
356         port->flags = p[1] ? PNP_PORT_FLAG_16BITADDR : 0;
357         pnp_register_port_resource(option, port);
358 }
359
360 static __init void pnpbios_parse_fixed_port_option(unsigned char *p, int size,
361                                                    struct pnp_option *option)
362 {
363         struct pnp_port *port;
364
365         port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
366         if (!port)
367                 return;
368         port->min = port->max = (p[2] << 8) | p[1];
369         port->size = p[3];
370         port->align = 0;
371         port->flags = PNP_PORT_FLAG_FIXED;
372         pnp_register_port_resource(option, port);
373 }
374
375 static __init unsigned char *
376 pnpbios_parse_resource_option_data(unsigned char *p, unsigned char *end,
377                                         struct pnp_dev *dev)
378 {
379         unsigned int len, tag;
380         int priority = 0;
381         struct pnp_option *option, *option_independent;
382
383         if (!p)
384                 return NULL;
385
386         option_independent = option = pnp_register_independent_option(dev);
387         if (!option)
388                 return NULL;
389
390         while ((char *)p < (char *)end) {
391
392                 /* determine the type of tag */
393                 if (p[0] & LARGE_TAG) { /* large tag */
394                         len = (p[2] << 8) | p[1];
395                         tag = p[0];
396                 } else {        /* small tag */
397                         len = p[0] & 0x07;
398                         tag = ((p[0] >> 3) & 0x0f);
399                 }
400
401                 switch (tag) {
402
403                 case LARGE_TAG_MEM:
404                         if (len != 9)
405                                 goto len_err;
406                         pnpbios_parse_mem_option(p, len, option);
407                         break;
408
409                 case LARGE_TAG_MEM32:
410                         if (len != 17)
411                                 goto len_err;
412                         pnpbios_parse_mem32_option(p, len, option);
413                         break;
414
415                 case LARGE_TAG_FIXEDMEM32:
416                         if (len != 9)
417                                 goto len_err;
418                         pnpbios_parse_fixed_mem32_option(p, len, option);
419                         break;
420
421                 case SMALL_TAG_IRQ:
422                         if (len < 2 || len > 3)
423                                 goto len_err;
424                         pnpbios_parse_irq_option(p, len, option);
425                         break;
426
427                 case SMALL_TAG_DMA:
428                         if (len != 2)
429                                 goto len_err;
430                         pnpbios_parse_dma_option(p, len, option);
431                         break;
432
433                 case SMALL_TAG_PORT:
434                         if (len != 7)
435                                 goto len_err;
436                         pnpbios_parse_port_option(p, len, option);
437                         break;
438
439                 case SMALL_TAG_VENDOR:
440                         /* do nothing */
441                         break;
442
443                 case SMALL_TAG_FIXEDPORT:
444                         if (len != 3)
445                                 goto len_err;
446                         pnpbios_parse_fixed_port_option(p, len, option);
447                         break;
448
449                 case SMALL_TAG_STARTDEP:
450                         if (len > 1)
451                                 goto len_err;
452                         priority = 0x100 | PNP_RES_PRIORITY_ACCEPTABLE;
453                         if (len > 0)
454                                 priority = 0x100 | p[1];
455                         option = pnp_register_dependent_option(dev, priority);
456                         if (!option)
457                                 return NULL;
458                         break;
459
460                 case SMALL_TAG_ENDDEP:
461                         if (len != 0)
462                                 goto len_err;
463                         if (option_independent == option)
464                                 printk(KERN_WARNING
465                                        "PnPBIOS: Missing SMALL_TAG_STARTDEP tag\n");
466                         option = option_independent;
467                         break;
468
469                 case SMALL_TAG_END:
470                         return p + 2;
471
472                 default:        /* an unkown tag */
473 len_err:
474                         printk(KERN_ERR
475                                "PnPBIOS: Unknown tag '0x%x', length '%d'.\n",
476                                tag, len);
477                         break;
478                 }
479
480                 /* continue to the next tag */
481                 if (p[0] & LARGE_TAG)
482                         p += len + 3;
483                 else
484                         p += len + 1;
485         }
486
487         printk(KERN_ERR
488                "PnPBIOS: Resource structure does not contain an end tag.\n");
489
490         return NULL;
491 }
492
493 /*
494  * Compatible Device IDs
495  */
496
497 #define HEX(id,a) hex[((id)>>a) & 15]
498 #define CHAR(id,a) (0x40 + (((id)>>a) & 31))
499
500 void pnpid32_to_pnpid(u32 id, char *str)
501 {
502         const char *hex = "0123456789abcdef";
503
504         id = be32_to_cpu(id);
505         str[0] = CHAR(id, 26);
506         str[1] = CHAR(id, 21);
507         str[2] = CHAR(id, 16);
508         str[3] = HEX(id, 12);
509         str[4] = HEX(id, 8);
510         str[5] = HEX(id, 4);
511         str[6] = HEX(id, 0);
512         str[7] = '\0';
513 }
514
515 #undef CHAR
516 #undef HEX
517
518 static unsigned char *pnpbios_parse_compatible_ids(unsigned char *p,
519                                                    unsigned char *end,
520                                                    struct pnp_dev *dev)
521 {
522         int len, tag;
523         char id[8];
524         struct pnp_id *dev_id;
525
526         if (!p)
527                 return NULL;
528
529         while ((char *)p < (char *)end) {
530
531                 /* determine the type of tag */
532                 if (p[0] & LARGE_TAG) { /* large tag */
533                         len = (p[2] << 8) | p[1];
534                         tag = p[0];
535                 } else {        /* small tag */
536                         len = p[0] & 0x07;
537                         tag = ((p[0] >> 3) & 0x0f);
538                 }
539
540                 switch (tag) {
541
542                 case LARGE_TAG_ANSISTR:
543                         strncpy(dev->name, p + 3,
544                                 len >= PNP_NAME_LEN ? PNP_NAME_LEN - 2 : len);
545                         dev->name[len >=
546                                   PNP_NAME_LEN ? PNP_NAME_LEN - 1 : len] = '\0';
547                         break;
548
549                 case SMALL_TAG_COMPATDEVID:     /* compatible ID */
550                         if (len != 4)
551                                 goto len_err;
552                         pnpid32_to_pnpid(p[1] | p[2] << 8 | p[3] << 16 | p[4] <<
553                                          24, id);
554                         dev_id = pnp_add_id(dev, id);
555                         if (!dev_id)
556                                 return NULL;
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 __init pnpbios_parse_data_stream(struct pnp_dev *dev,
784                                         struct pnp_bios_node *node)
785 {
786         unsigned char *p = (char *)node->data;
787         unsigned char *end = (char *)(node->data + node->size);
788
789         p = pnpbios_parse_allocated_resource_data(p, end, &dev->res);
790         if (!p)
791                 return -EIO;
792         p = pnpbios_parse_resource_option_data(p, end, dev);
793         if (!p)
794                 return -EIO;
795         p = pnpbios_parse_compatible_ids(p, end, dev);
796         if (!p)
797                 return -EIO;
798         return 0;
799 }
800
801 int pnpbios_read_resources_from_node(struct pnp_resource_table *res,
802                                      struct pnp_bios_node *node)
803 {
804         unsigned char *p = (char *)node->data;
805         unsigned char *end = (char *)(node->data + node->size);
806
807         p = pnpbios_parse_allocated_resource_data(p, end, res);
808         if (!p)
809                 return -EIO;
810         return 0;
811 }
812
813 int pnpbios_write_resources_to_node(struct pnp_resource_table *res,
814                                     struct pnp_bios_node *node)
815 {
816         unsigned char *p = (char *)node->data;
817         unsigned char *end = (char *)(node->data + node->size);
818
819         p = pnpbios_encode_allocated_resource_data(p, end, res);
820         if (!p)
821                 return -EIO;
822         return 0;
823 }