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