aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pnp/pnpbios/rsparser.c
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2008-07-17 17:57:20 -0400
committerIngo Molnar <mingo@elte.hu>2008-07-17 17:57:20 -0400
commit393d81aa026e19b6ede6f5f11955c97ee62e5df5 (patch)
treea1d9511e488e19d41089ff0a736f6ce52a81c6e5 /drivers/pnp/pnpbios/rsparser.c
parent93a0886e2368eafb9df5e2021fb185195cee88b2 (diff)
parent5b664cb235e97afbf34db9c4d77f08ebd725335e (diff)
Merge branch 'linus' into xen-64bit
Diffstat (limited to 'drivers/pnp/pnpbios/rsparser.c')
-rw-r--r--drivers/pnp/pnpbios/rsparser.c274
1 files changed, 146 insertions, 128 deletions
diff --git a/drivers/pnp/pnpbios/rsparser.c b/drivers/pnp/pnpbios/rsparser.c
index 5ff9a4c0447e..ca567671379e 100644
--- a/drivers/pnp/pnpbios/rsparser.c
+++ b/drivers/pnp/pnpbios/rsparser.c
@@ -216,137 +216,116 @@ len_err:
216 216
217static __init void pnpbios_parse_mem_option(struct pnp_dev *dev, 217static __init void pnpbios_parse_mem_option(struct pnp_dev *dev,
218 unsigned char *p, int size, 218 unsigned char *p, int size,
219 struct pnp_option *option) 219 unsigned int option_flags)
220{ 220{
221 struct pnp_mem *mem; 221 resource_size_t min, max, align, len;
222 222 unsigned char flags;
223 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); 223
224 if (!mem) 224 min = ((p[5] << 8) | p[4]) << 8;
225 return; 225 max = ((p[7] << 8) | p[6]) << 8;
226 mem->min = ((p[5] << 8) | p[4]) << 8; 226 align = (p[9] << 8) | p[8];
227 mem->max = ((p[7] << 8) | p[6]) << 8; 227 len = ((p[11] << 8) | p[10]) << 8;
228 mem->align = (p[9] << 8) | p[8]; 228 flags = p[3];
229 mem->size = ((p[11] << 8) | p[10]) << 8; 229 pnp_register_mem_resource(dev, option_flags, min, max, align, len,
230 mem->flags = p[3]; 230 flags);
231 pnp_register_mem_resource(dev, option, mem);
232} 231}
233 232
234static __init void pnpbios_parse_mem32_option(struct pnp_dev *dev, 233static __init void pnpbios_parse_mem32_option(struct pnp_dev *dev,
235 unsigned char *p, int size, 234 unsigned char *p, int size,
236 struct pnp_option *option) 235 unsigned int option_flags)
237{ 236{
238 struct pnp_mem *mem; 237 resource_size_t min, max, align, len;
239 238 unsigned char flags;
240 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); 239
241 if (!mem) 240 min = (p[7] << 24) | (p[6] << 16) | (p[5] << 8) | p[4];
242 return; 241 max = (p[11] << 24) | (p[10] << 16) | (p[9] << 8) | p[8];
243 mem->min = (p[7] << 24) | (p[6] << 16) | (p[5] << 8) | p[4]; 242 align = (p[15] << 24) | (p[14] << 16) | (p[13] << 8) | p[12];
244 mem->max = (p[11] << 24) | (p[10] << 16) | (p[9] << 8) | p[8]; 243 len = (p[19] << 24) | (p[18] << 16) | (p[17] << 8) | p[16];
245 mem->align = (p[15] << 24) | (p[14] << 16) | (p[13] << 8) | p[12]; 244 flags = p[3];
246 mem->size = (p[19] << 24) | (p[18] << 16) | (p[17] << 8) | p[16]; 245 pnp_register_mem_resource(dev, option_flags, min, max, align, len,
247 mem->flags = p[3]; 246 flags);
248 pnp_register_mem_resource(dev, option, mem);
249} 247}
250 248
251static __init void pnpbios_parse_fixed_mem32_option(struct pnp_dev *dev, 249static __init void pnpbios_parse_fixed_mem32_option(struct pnp_dev *dev,
252 unsigned char *p, int size, 250 unsigned char *p, int size,
253 struct pnp_option *option) 251 unsigned int option_flags)
254{ 252{
255 struct pnp_mem *mem; 253 resource_size_t base, len;
256 254 unsigned char flags;
257 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); 255
258 if (!mem) 256 base = (p[7] << 24) | (p[6] << 16) | (p[5] << 8) | p[4];
259 return; 257 len = (p[11] << 24) | (p[10] << 16) | (p[9] << 8) | p[8];
260 mem->min = mem->max = (p[7] << 24) | (p[6] << 16) | (p[5] << 8) | p[4]; 258 flags = p[3];
261 mem->size = (p[11] << 24) | (p[10] << 16) | (p[9] << 8) | p[8]; 259 pnp_register_mem_resource(dev, option_flags, base, base, 0, len, flags);
262 mem->align = 0;
263 mem->flags = p[3];
264 pnp_register_mem_resource(dev, option, mem);
265} 260}
266 261
267static __init void pnpbios_parse_irq_option(struct pnp_dev *dev, 262static __init void pnpbios_parse_irq_option(struct pnp_dev *dev,
268 unsigned char *p, int size, 263 unsigned char *p, int size,
269 struct pnp_option *option) 264 unsigned int option_flags)
270{ 265{
271 struct pnp_irq *irq;
272 unsigned long bits; 266 unsigned long bits;
267 pnp_irq_mask_t map;
268 unsigned char flags = IORESOURCE_IRQ_HIGHEDGE;
273 269
274 irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
275 if (!irq)
276 return;
277 bits = (p[2] << 8) | p[1]; 270 bits = (p[2] << 8) | p[1];
278 bitmap_copy(irq->map, &bits, 16); 271
272 bitmap_zero(map.bits, PNP_IRQ_NR);
273 bitmap_copy(map.bits, &bits, 16);
274
279 if (size > 2) 275 if (size > 2)
280 irq->flags = p[3]; 276 flags = p[3];
281 else 277
282 irq->flags = IORESOURCE_IRQ_HIGHEDGE; 278 pnp_register_irq_resource(dev, option_flags, &map, flags);
283 pnp_register_irq_resource(dev, option, irq);
284} 279}
285 280
286static __init void pnpbios_parse_dma_option(struct pnp_dev *dev, 281static __init void pnpbios_parse_dma_option(struct pnp_dev *dev,
287 unsigned char *p, int size, 282 unsigned char *p, int size,
288 struct pnp_option *option) 283 unsigned int option_flags)
289{ 284{
290 struct pnp_dma *dma; 285 pnp_register_dma_resource(dev, option_flags, p[1], p[2]);
291
292 dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL);
293 if (!dma)
294 return;
295 dma->map = p[1];
296 dma->flags = p[2];
297 pnp_register_dma_resource(dev, option, dma);
298} 286}
299 287
300static __init void pnpbios_parse_port_option(struct pnp_dev *dev, 288static __init void pnpbios_parse_port_option(struct pnp_dev *dev,
301 unsigned char *p, int size, 289 unsigned char *p, int size,
302 struct pnp_option *option) 290 unsigned int option_flags)
303{ 291{
304 struct pnp_port *port; 292 resource_size_t min, max, align, len;
305 293 unsigned char flags;
306 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); 294
307 if (!port) 295 min = (p[3] << 8) | p[2];
308 return; 296 max = (p[5] << 8) | p[4];
309 port->min = (p[3] << 8) | p[2]; 297 align = p[6];
310 port->max = (p[5] << 8) | p[4]; 298 len = p[7];
311 port->align = p[6]; 299 flags = p[1] ? IORESOURCE_IO_16BIT_ADDR : 0;
312 port->size = p[7]; 300 pnp_register_port_resource(dev, option_flags, min, max, align, len,
313 port->flags = p[1] ? PNP_PORT_FLAG_16BITADDR : 0; 301 flags);
314 pnp_register_port_resource(dev, option, port);
315} 302}
316 303
317static __init void pnpbios_parse_fixed_port_option(struct pnp_dev *dev, 304static __init void pnpbios_parse_fixed_port_option(struct pnp_dev *dev,
318 unsigned char *p, int size, 305 unsigned char *p, int size,
319 struct pnp_option *option) 306 unsigned int option_flags)
320{ 307{
321 struct pnp_port *port; 308 resource_size_t base, len;
322 309
323 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); 310 base = (p[2] << 8) | p[1];
324 if (!port) 311 len = p[3];
325 return; 312 pnp_register_port_resource(dev, option_flags, base, base, 0, len,
326 port->min = port->max = (p[2] << 8) | p[1]; 313 IORESOURCE_IO_FIXED);
327 port->size = p[3];
328 port->align = 0;
329 port->flags = PNP_PORT_FLAG_FIXED;
330 pnp_register_port_resource(dev, option, port);
331} 314}
332 315
333static __init unsigned char * 316static __init unsigned char *
334pnpbios_parse_resource_option_data(unsigned char *p, unsigned char *end, 317pnpbios_parse_resource_option_data(unsigned char *p, unsigned char *end,
335 struct pnp_dev *dev) 318 struct pnp_dev *dev)
336{ 319{
337 unsigned int len, tag; 320 unsigned int len, tag;
338 int priority = 0; 321 int priority;
339 struct pnp_option *option, *option_independent; 322 unsigned int option_flags;
340 323
341 if (!p) 324 if (!p)
342 return NULL; 325 return NULL;
343 326
344 dev_dbg(&dev->dev, "parse resource options\n"); 327 dev_dbg(&dev->dev, "parse resource options\n");
345 328 option_flags = 0;
346 option_independent = option = pnp_register_independent_option(dev);
347 if (!option)
348 return NULL;
349
350 while ((char *)p < (char *)end) { 329 while ((char *)p < (char *)end) {
351 330
352 /* determine the type of tag */ 331 /* determine the type of tag */
@@ -363,37 +342,38 @@ pnpbios_parse_resource_option_data(unsigned char *p, unsigned char *end,
363 case LARGE_TAG_MEM: 342 case LARGE_TAG_MEM:
364 if (len != 9) 343 if (len != 9)
365 goto len_err; 344 goto len_err;
366 pnpbios_parse_mem_option(dev, p, len, option); 345 pnpbios_parse_mem_option(dev, p, len, option_flags);
367 break; 346 break;
368 347
369 case LARGE_TAG_MEM32: 348 case LARGE_TAG_MEM32:
370 if (len != 17) 349 if (len != 17)
371 goto len_err; 350 goto len_err;
372 pnpbios_parse_mem32_option(dev, p, len, option); 351 pnpbios_parse_mem32_option(dev, p, len, option_flags);
373 break; 352 break;
374 353
375 case LARGE_TAG_FIXEDMEM32: 354 case LARGE_TAG_FIXEDMEM32:
376 if (len != 9) 355 if (len != 9)
377 goto len_err; 356 goto len_err;
378 pnpbios_parse_fixed_mem32_option(dev, p, len, option); 357 pnpbios_parse_fixed_mem32_option(dev, p, len,
358 option_flags);
379 break; 359 break;
380 360
381 case SMALL_TAG_IRQ: 361 case SMALL_TAG_IRQ:
382 if (len < 2 || len > 3) 362 if (len < 2 || len > 3)
383 goto len_err; 363 goto len_err;
384 pnpbios_parse_irq_option(dev, p, len, option); 364 pnpbios_parse_irq_option(dev, p, len, option_flags);
385 break; 365 break;
386 366
387 case SMALL_TAG_DMA: 367 case SMALL_TAG_DMA:
388 if (len != 2) 368 if (len != 2)
389 goto len_err; 369 goto len_err;
390 pnpbios_parse_dma_option(dev, p, len, option); 370 pnpbios_parse_dma_option(dev, p, len, option_flags);
391 break; 371 break;
392 372
393 case SMALL_TAG_PORT: 373 case SMALL_TAG_PORT:
394 if (len != 7) 374 if (len != 7)
395 goto len_err; 375 goto len_err;
396 pnpbios_parse_port_option(dev, p, len, option); 376 pnpbios_parse_port_option(dev, p, len, option_flags);
397 break; 377 break;
398 378
399 case SMALL_TAG_VENDOR: 379 case SMALL_TAG_VENDOR:
@@ -403,28 +383,23 @@ pnpbios_parse_resource_option_data(unsigned char *p, unsigned char *end,
403 case SMALL_TAG_FIXEDPORT: 383 case SMALL_TAG_FIXEDPORT:
404 if (len != 3) 384 if (len != 3)
405 goto len_err; 385 goto len_err;
406 pnpbios_parse_fixed_port_option(dev, p, len, option); 386 pnpbios_parse_fixed_port_option(dev, p, len,
387 option_flags);
407 break; 388 break;
408 389
409 case SMALL_TAG_STARTDEP: 390 case SMALL_TAG_STARTDEP:
410 if (len > 1) 391 if (len > 1)
411 goto len_err; 392 goto len_err;
412 priority = 0x100 | PNP_RES_PRIORITY_ACCEPTABLE; 393 priority = PNP_RES_PRIORITY_ACCEPTABLE;
413 if (len > 0) 394 if (len > 0)
414 priority = 0x100 | p[1]; 395 priority = p[1];
415 option = pnp_register_dependent_option(dev, priority); 396 option_flags = pnp_new_dependent_set(dev, priority);
416 if (!option)
417 return NULL;
418 break; 397 break;
419 398
420 case SMALL_TAG_ENDDEP: 399 case SMALL_TAG_ENDDEP:
421 if (len != 0) 400 if (len != 0)
422 goto len_err; 401 goto len_err;
423 if (option_independent == option) 402 option_flags = 0;
424 dev_warn(&dev->dev, "missing "
425 "SMALL_TAG_STARTDEP tag\n");
426 option = option_independent;
427 dev_dbg(&dev->dev, "end dependent options\n");
428 break; 403 break;
429 404
430 case SMALL_TAG_END: 405 case SMALL_TAG_END:
@@ -526,8 +501,16 @@ len_err:
526static void pnpbios_encode_mem(struct pnp_dev *dev, unsigned char *p, 501static void pnpbios_encode_mem(struct pnp_dev *dev, unsigned char *p,
527 struct resource *res) 502 struct resource *res)
528{ 503{
529 unsigned long base = res->start; 504 unsigned long base;
530 unsigned long len = res->end - res->start + 1; 505 unsigned long len;
506
507 if (pnp_resource_enabled(res)) {
508 base = res->start;
509 len = res->end - res->start + 1;
510 } else {
511 base = 0;
512 len = 0;
513 }
531 514
532 p[4] = (base >> 8) & 0xff; 515 p[4] = (base >> 8) & 0xff;
533 p[5] = ((base >> 8) >> 8) & 0xff; 516 p[5] = ((base >> 8) >> 8) & 0xff;
@@ -536,15 +519,22 @@ static void pnpbios_encode_mem(struct pnp_dev *dev, unsigned char *p,
536 p[10] = (len >> 8) & 0xff; 519 p[10] = (len >> 8) & 0xff;
537 p[11] = ((len >> 8) >> 8) & 0xff; 520 p[11] = ((len >> 8) >> 8) & 0xff;
538 521
539 dev_dbg(&dev->dev, " encode mem %#llx-%#llx\n", 522 dev_dbg(&dev->dev, " encode mem %#lx-%#lx\n", base, base + len - 1);
540 (unsigned long long) res->start, (unsigned long long) res->end);
541} 523}
542 524
543static void pnpbios_encode_mem32(struct pnp_dev *dev, unsigned char *p, 525static void pnpbios_encode_mem32(struct pnp_dev *dev, unsigned char *p,
544 struct resource *res) 526 struct resource *res)
545{ 527{
546 unsigned long base = res->start; 528 unsigned long base;
547 unsigned long len = res->end - res->start + 1; 529 unsigned long len;
530
531 if (pnp_resource_enabled(res)) {
532 base = res->start;
533 len = res->end - res->start + 1;
534 } else {
535 base = 0;
536 len = 0;
537 }
548 538
549 p[4] = base & 0xff; 539 p[4] = base & 0xff;
550 p[5] = (base >> 8) & 0xff; 540 p[5] = (base >> 8) & 0xff;
@@ -559,15 +549,22 @@ static void pnpbios_encode_mem32(struct pnp_dev *dev, unsigned char *p,
559 p[18] = (len >> 16) & 0xff; 549 p[18] = (len >> 16) & 0xff;
560 p[19] = (len >> 24) & 0xff; 550 p[19] = (len >> 24) & 0xff;
561 551
562 dev_dbg(&dev->dev, " encode mem32 %#llx-%#llx\n", 552 dev_dbg(&dev->dev, " encode mem32 %#lx-%#lx\n", base, base + len - 1);
563 (unsigned long long) res->start, (unsigned long long) res->end);
564} 553}
565 554
566static void pnpbios_encode_fixed_mem32(struct pnp_dev *dev, unsigned char *p, 555static void pnpbios_encode_fixed_mem32(struct pnp_dev *dev, unsigned char *p,
567 struct resource *res) 556 struct resource *res)
568{ 557{
569 unsigned long base = res->start; 558 unsigned long base;
570 unsigned long len = res->end - res->start + 1; 559 unsigned long len;
560
561 if (pnp_resource_enabled(res)) {
562 base = res->start;
563 len = res->end - res->start + 1;
564 } else {
565 base = 0;
566 len = 0;
567 }
571 568
572 p[4] = base & 0xff; 569 p[4] = base & 0xff;
573 p[5] = (base >> 8) & 0xff; 570 p[5] = (base >> 8) & 0xff;
@@ -578,40 +575,54 @@ static void pnpbios_encode_fixed_mem32(struct pnp_dev *dev, unsigned char *p,
578 p[10] = (len >> 16) & 0xff; 575 p[10] = (len >> 16) & 0xff;
579 p[11] = (len >> 24) & 0xff; 576 p[11] = (len >> 24) & 0xff;
580 577
581 dev_dbg(&dev->dev, " encode fixed_mem32 %#llx-%#llx\n", 578 dev_dbg(&dev->dev, " encode fixed_mem32 %#lx-%#lx\n", base,
582 (unsigned long long) res->start, (unsigned long long) res->end); 579 base + len - 1);
583} 580}
584 581
585static void pnpbios_encode_irq(struct pnp_dev *dev, unsigned char *p, 582static void pnpbios_encode_irq(struct pnp_dev *dev, unsigned char *p,
586 struct resource *res) 583 struct resource *res)
587{ 584{
588 unsigned long map = 0; 585 unsigned long map;
586
587 if (pnp_resource_enabled(res))
588 map = 1 << res->start;
589 else
590 map = 0;
589 591
590 map = 1 << res->start;
591 p[1] = map & 0xff; 592 p[1] = map & 0xff;
592 p[2] = (map >> 8) & 0xff; 593 p[2] = (map >> 8) & 0xff;
593 594
594 dev_dbg(&dev->dev, " encode irq %llu\n", 595 dev_dbg(&dev->dev, " encode irq mask %#lx\n", map);
595 (unsigned long long)res->start);
596} 596}
597 597
598static void pnpbios_encode_dma(struct pnp_dev *dev, unsigned char *p, 598static void pnpbios_encode_dma(struct pnp_dev *dev, unsigned char *p,
599 struct resource *res) 599 struct resource *res)
600{ 600{
601 unsigned long map = 0; 601 unsigned long map;
602
603 if (pnp_resource_enabled(res))
604 map = 1 << res->start;
605 else
606 map = 0;
602 607
603 map = 1 << res->start;
604 p[1] = map & 0xff; 608 p[1] = map & 0xff;
605 609
606 dev_dbg(&dev->dev, " encode dma %llu\n", 610 dev_dbg(&dev->dev, " encode dma mask %#lx\n", map);
607 (unsigned long long)res->start);
608} 611}
609 612
610static void pnpbios_encode_port(struct pnp_dev *dev, unsigned char *p, 613static void pnpbios_encode_port(struct pnp_dev *dev, unsigned char *p,
611 struct resource *res) 614 struct resource *res)
612{ 615{
613 unsigned long base = res->start; 616 unsigned long base;
614 unsigned long len = res->end - res->start + 1; 617 unsigned long len;
618
619 if (pnp_resource_enabled(res)) {
620 base = res->start;
621 len = res->end - res->start + 1;
622 } else {
623 base = 0;
624 len = 0;
625 }
615 626
616 p[2] = base & 0xff; 627 p[2] = base & 0xff;
617 p[3] = (base >> 8) & 0xff; 628 p[3] = (base >> 8) & 0xff;
@@ -619,8 +630,7 @@ static void pnpbios_encode_port(struct pnp_dev *dev, unsigned char *p,
619 p[5] = (base >> 8) & 0xff; 630 p[5] = (base >> 8) & 0xff;
620 p[7] = len & 0xff; 631 p[7] = len & 0xff;
621 632
622 dev_dbg(&dev->dev, " encode io %#llx-%#llx\n", 633 dev_dbg(&dev->dev, " encode io %#lx-%#lx\n", base, base + len - 1);
623 (unsigned long long) res->start, (unsigned long long) res->end);
624} 634}
625 635
626static void pnpbios_encode_fixed_port(struct pnp_dev *dev, unsigned char *p, 636static void pnpbios_encode_fixed_port(struct pnp_dev *dev, unsigned char *p,
@@ -629,12 +639,20 @@ static void pnpbios_encode_fixed_port(struct pnp_dev *dev, unsigned char *p,
629 unsigned long base = res->start; 639 unsigned long base = res->start;
630 unsigned long len = res->end - res->start + 1; 640 unsigned long len = res->end - res->start + 1;
631 641
642 if (pnp_resource_enabled(res)) {
643 base = res->start;
644 len = res->end - res->start + 1;
645 } else {
646 base = 0;
647 len = 0;
648 }
649
632 p[1] = base & 0xff; 650 p[1] = base & 0xff;
633 p[2] = (base >> 8) & 0xff; 651 p[2] = (base >> 8) & 0xff;
634 p[3] = len & 0xff; 652 p[3] = len & 0xff;
635 653
636 dev_dbg(&dev->dev, " encode fixed_io %#llx-%#llx\n", 654 dev_dbg(&dev->dev, " encode fixed_io %#lx-%#lx\n", base,
637 (unsigned long long) res->start, (unsigned long long) res->end); 655 base + len - 1);
638} 656}
639 657
640static unsigned char *pnpbios_encode_allocated_resource_data(struct pnp_dev 658static unsigned char *pnpbios_encode_allocated_resource_data(struct pnp_dev