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