aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pnp/pnpbios
diff options
context:
space:
mode:
authorBjorn Helgaas <bjorn.helgaas@hp.com>2008-06-27 18:56:57 -0400
committerAndi Kleen <andi@basil.nowhere.org>2008-07-16 17:27:05 -0400
commitaee3ad815dd291a7193ab01da0f1a30c84d00061 (patch)
treeb0549b2a98ddfe6734e1e5f7cedd3958eec18503 /drivers/pnp/pnpbios
parent20bfdbba7212d19613b93dcea93f26cb65af91fe (diff)
PNP: replace pnp_resource_table with dynamically allocated resources
PNP used to have a fixed-size pnp_resource_table for tracking the resources used by a device. This table often overflowed, so we've had to increase the table size, which wastes memory because most devices have very few resources. This patch replaces the table with a linked list of resources where the entries are allocated on demand. This removes messages like these: pnpacpi: exceeded the max number of IO resources 00:01: too many I/O port resources References: http://bugzilla.kernel.org/show_bug.cgi?id=9535 http://bugzilla.kernel.org/show_bug.cgi?id=9740 http://lkml.org/lkml/2007/11/30/110 This patch also changes the way PNP uses the IORESOURCE_UNSET, IORESOURCE_AUTO, and IORESOURCE_DISABLED flags. Prior to this patch, the pnp_resource_table entries used the flags like this: IORESOURCE_UNSET This table entry is unused and available for use. When this flag is set, we shouldn't look at anything else in the resource structure. This flag is set when a resource table entry is initialized. IORESOURCE_AUTO This resource was assigned automatically by pnp_assign_{io,mem,etc}(). This flag is set when a resource table entry is initialized and cleared whenever we discover a resource setting by reading an ISAPNP config register, parsing a PNPBIOS resource data stream, parsing an ACPI _CRS list, or interpreting a sysfs "set" command. Resources marked IORESOURCE_AUTO are reinitialized and marked as IORESOURCE_UNSET by pnp_clean_resource_table() in these cases: - before we attempt to assign resources automatically, - if we fail to assign resources automatically, - after disabling a device IORESOURCE_DISABLED Set by pnp_assign_{io,mem,etc}() when automatic assignment fails. Also set by PNPBIOS and PNPACPI for: - invalid IRQs or GSI registration failures - invalid DMA channels - I/O ports above 0x10000 - mem ranges with negative length After this patch, there is no pnp_resource_table, and the resource list entries use the flags like this: IORESOURCE_UNSET This flag is no longer used in PNP. Instead of keeping IORESOURCE_UNSET entries in the resource list, we remove entries from the list and free them. IORESOURCE_AUTO No change in meaning: it still means the resource was assigned automatically by pnp_assign_{port,mem,etc}(), but these functions now set the bit explicitly. We still "clean" a device's resource list in the same places, but rather than reinitializing IORESOURCE_AUTO entries, we just remove them from the list. Note that IORESOURCE_AUTO entries are always at the end of the list, so removing them doesn't reorder other list entries. This is because non-IORESOURCE_AUTO entries are added by the ISAPNP, PNPBIOS, or PNPACPI "get resources" methods and by the sysfs "set" command. In each of these cases, we completely free the resource list first. IORESOURCE_DISABLED In addition to the cases where we used to set this flag, ISAPNP now adds an IORESOURCE_DISABLED resource when it reads a configuration register with a "disabled" value. Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com> Signed-off-by: Len Brown <len.brown@intel.com> Signed-off-by: Andi Kleen <ak@linux.intel.com>
Diffstat (limited to 'drivers/pnp/pnpbios')
-rw-r--r--drivers/pnp/pnpbios/rsparser.c95
1 files changed, 69 insertions, 26 deletions
diff --git a/drivers/pnp/pnpbios/rsparser.c b/drivers/pnp/pnpbios/rsparser.c
index 5ff9a4c0447e..01f0c3dd1b08 100644
--- a/drivers/pnp/pnpbios/rsparser.c
+++ b/drivers/pnp/pnpbios/rsparser.c
@@ -526,8 +526,16 @@ len_err:
526static void pnpbios_encode_mem(struct pnp_dev *dev, unsigned char *p, 526static void pnpbios_encode_mem(struct pnp_dev *dev, unsigned char *p,
527 struct resource *res) 527 struct resource *res)
528{ 528{
529 unsigned long base = res->start; 529 unsigned long base;
530 unsigned long len = res->end - res->start + 1; 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 }
531 539
532 p[4] = (base >> 8) & 0xff; 540 p[4] = (base >> 8) & 0xff;
533 p[5] = ((base >> 8) >> 8) & 0xff; 541 p[5] = ((base >> 8) >> 8) & 0xff;
@@ -536,15 +544,22 @@ static void pnpbios_encode_mem(struct pnp_dev *dev, unsigned char *p,
536 p[10] = (len >> 8) & 0xff; 544 p[10] = (len >> 8) & 0xff;
537 p[11] = ((len >> 8) >> 8) & 0xff; 545 p[11] = ((len >> 8) >> 8) & 0xff;
538 546
539 dev_dbg(&dev->dev, " encode mem %#llx-%#llx\n", 547 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} 548}
542 549
543static void pnpbios_encode_mem32(struct pnp_dev *dev, unsigned char *p, 550static void pnpbios_encode_mem32(struct pnp_dev *dev, unsigned char *p,
544 struct resource *res) 551 struct resource *res)
545{ 552{
546 unsigned long base = res->start; 553 unsigned long base;
547 unsigned long len = res->end - res->start + 1; 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 }
548 563
549 p[4] = base & 0xff; 564 p[4] = base & 0xff;
550 p[5] = (base >> 8) & 0xff; 565 p[5] = (base >> 8) & 0xff;
@@ -559,15 +574,22 @@ static void pnpbios_encode_mem32(struct pnp_dev *dev, unsigned char *p,
559 p[18] = (len >> 16) & 0xff; 574 p[18] = (len >> 16) & 0xff;
560 p[19] = (len >> 24) & 0xff; 575 p[19] = (len >> 24) & 0xff;
561 576
562 dev_dbg(&dev->dev, " encode mem32 %#llx-%#llx\n", 577 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} 578}
565 579
566static void pnpbios_encode_fixed_mem32(struct pnp_dev *dev, unsigned char *p, 580static void pnpbios_encode_fixed_mem32(struct pnp_dev *dev, unsigned char *p,
567 struct resource *res) 581 struct resource *res)
568{ 582{
569 unsigned long base = res->start; 583 unsigned long base;
570 unsigned long len = res->end - res->start + 1; 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 }
571 593
572 p[4] = base & 0xff; 594 p[4] = base & 0xff;
573 p[5] = (base >> 8) & 0xff; 595 p[5] = (base >> 8) & 0xff;
@@ -578,40 +600,54 @@ static void pnpbios_encode_fixed_mem32(struct pnp_dev *dev, unsigned char *p,
578 p[10] = (len >> 16) & 0xff; 600 p[10] = (len >> 16) & 0xff;
579 p[11] = (len >> 24) & 0xff; 601 p[11] = (len >> 24) & 0xff;
580 602
581 dev_dbg(&dev->dev, " encode fixed_mem32 %#llx-%#llx\n", 603 dev_dbg(&dev->dev, " encode fixed_mem32 %#lx-%#lx\n", base,
582 (unsigned long long) res->start, (unsigned long long) res->end); 604 base + len - 1);
583} 605}
584 606
585static void pnpbios_encode_irq(struct pnp_dev *dev, unsigned char *p, 607static void pnpbios_encode_irq(struct pnp_dev *dev, unsigned char *p,
586 struct resource *res) 608 struct resource *res)
587{ 609{
588 unsigned long map = 0; 610 unsigned long map;
611
612 if (pnp_resource_enabled(res))
613 map = 1 << res->start;
614 else
615 map = 0;
589 616
590 map = 1 << res->start;
591 p[1] = map & 0xff; 617 p[1] = map & 0xff;
592 p[2] = (map >> 8) & 0xff; 618 p[2] = (map >> 8) & 0xff;
593 619
594 dev_dbg(&dev->dev, " encode irq %llu\n", 620 dev_dbg(&dev->dev, " encode irq mask %#lx\n", map);
595 (unsigned long long)res->start);
596} 621}
597 622
598static void pnpbios_encode_dma(struct pnp_dev *dev, unsigned char *p, 623static void pnpbios_encode_dma(struct pnp_dev *dev, unsigned char *p,
599 struct resource *res) 624 struct resource *res)
600{ 625{
601 unsigned long map = 0; 626 unsigned long map;
627
628 if (pnp_resource_enabled(res))
629 map = 1 << res->start;
630 else
631 map = 0;
602 632
603 map = 1 << res->start;
604 p[1] = map & 0xff; 633 p[1] = map & 0xff;
605 634
606 dev_dbg(&dev->dev, " encode dma %llu\n", 635 dev_dbg(&dev->dev, " encode dma mask %#lx\n", map);
607 (unsigned long long)res->start);
608} 636}
609 637
610static void pnpbios_encode_port(struct pnp_dev *dev, unsigned char *p, 638static void pnpbios_encode_port(struct pnp_dev *dev, unsigned char *p,
611 struct resource *res) 639 struct resource *res)
612{ 640{
613 unsigned long base = res->start; 641 unsigned long base;
614 unsigned long len = res->end - res->start + 1; 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 }
615 651
616 p[2] = base & 0xff; 652 p[2] = base & 0xff;
617 p[3] = (base >> 8) & 0xff; 653 p[3] = (base >> 8) & 0xff;
@@ -619,8 +655,7 @@ static void pnpbios_encode_port(struct pnp_dev *dev, unsigned char *p,
619 p[5] = (base >> 8) & 0xff; 655 p[5] = (base >> 8) & 0xff;
620 p[7] = len & 0xff; 656 p[7] = len & 0xff;
621 657
622 dev_dbg(&dev->dev, " encode io %#llx-%#llx\n", 658 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} 659}
625 660
626static void pnpbios_encode_fixed_port(struct pnp_dev *dev, unsigned char *p, 661static void pnpbios_encode_fixed_port(struct pnp_dev *dev, unsigned char *p,
@@ -629,12 +664,20 @@ static void pnpbios_encode_fixed_port(struct pnp_dev *dev, unsigned char *p,
629 unsigned long base = res->start; 664 unsigned long base = res->start;
630 unsigned long len = res->end - res->start + 1; 665 unsigned long len = res->end - res->start + 1;
631 666
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
632 p[1] = base & 0xff; 675 p[1] = base & 0xff;
633 p[2] = (base >> 8) & 0xff; 676 p[2] = (base >> 8) & 0xff;
634 p[3] = len & 0xff; 677 p[3] = len & 0xff;
635 678
636 dev_dbg(&dev->dev, " encode fixed_io %#llx-%#llx\n", 679 dev_dbg(&dev->dev, " encode fixed_io %#lx-%#lx\n", base,
637 (unsigned long long) res->start, (unsigned long long) res->end); 680 base + len - 1);
638} 681}
639 682
640static unsigned char *pnpbios_encode_allocated_resource_data(struct pnp_dev 683static unsigned char *pnpbios_encode_allocated_resource_data(struct pnp_dev