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