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