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