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