aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pnp/resource.c
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/resource.c
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/resource.c')
-rw-r--r--drivers/pnp/resource.c86
1 files changed, 18 insertions, 68 deletions
diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
index cce341f743d4..0797a77bd042 100644
--- a/drivers/pnp/resource.c
+++ b/drivers/pnp/resource.c
@@ -237,7 +237,7 @@ void pnp_free_option(struct pnp_option *option)
237 !((*(enda) < *(startb)) || (*(endb) < *(starta))) 237 !((*(enda) < *(startb)) || (*(endb) < *(starta)))
238 238
239#define cannot_compare(flags) \ 239#define cannot_compare(flags) \
240((flags) & (IORESOURCE_UNSET | IORESOURCE_DISABLED)) 240((flags) & IORESOURCE_DISABLED)
241 241
242int pnp_check_port(struct pnp_dev *dev, struct resource *res) 242int pnp_check_port(struct pnp_dev *dev, struct resource *res)
243{ 243{
@@ -505,81 +505,31 @@ int pnp_resource_type(struct resource *res)
505 IORESOURCE_IRQ | IORESOURCE_DMA); 505 IORESOURCE_IRQ | IORESOURCE_DMA);
506} 506}
507 507
508struct pnp_resource *pnp_get_pnp_resource(struct pnp_dev *dev,
509 unsigned int type, unsigned int num)
510{
511 struct pnp_resource_table *res = dev->res;
512
513 switch (type) {
514 case IORESOURCE_IO:
515 if (num >= PNP_MAX_PORT)
516 return NULL;
517 return &res->port[num];
518 case IORESOURCE_MEM:
519 if (num >= PNP_MAX_MEM)
520 return NULL;
521 return &res->mem[num];
522 case IORESOURCE_IRQ:
523 if (num >= PNP_MAX_IRQ)
524 return NULL;
525 return &res->irq[num];
526 case IORESOURCE_DMA:
527 if (num >= PNP_MAX_DMA)
528 return NULL;
529 return &res->dma[num];
530 }
531 return NULL;
532}
533
534struct resource *pnp_get_resource(struct pnp_dev *dev, 508struct resource *pnp_get_resource(struct pnp_dev *dev,
535 unsigned int type, unsigned int num) 509 unsigned int type, unsigned int num)
536{ 510{
537 struct pnp_resource *pnp_res; 511 struct pnp_resource *pnp_res;
512 struct resource *res;
538 513
539 pnp_res = pnp_get_pnp_resource(dev, type, num); 514 list_for_each_entry(pnp_res, &dev->resources, list) {
540 if (pnp_res) 515 res = &pnp_res->res;
541 return &pnp_res->res; 516 if (pnp_resource_type(res) == type && num-- == 0)
542 517 return res;
518 }
543 return NULL; 519 return NULL;
544} 520}
545EXPORT_SYMBOL(pnp_get_resource); 521EXPORT_SYMBOL(pnp_get_resource);
546 522
547static struct pnp_resource *pnp_new_resource(struct pnp_dev *dev, int type) 523static struct pnp_resource *pnp_new_resource(struct pnp_dev *dev)
548{ 524{
549 struct pnp_resource *pnp_res; 525 struct pnp_resource *pnp_res;
550 int i;
551 526
552 switch (type) { 527 pnp_res = kzalloc(sizeof(struct pnp_resource), GFP_KERNEL);
553 case IORESOURCE_IO: 528 if (!pnp_res)
554 for (i = 0; i < PNP_MAX_PORT; i++) { 529 return NULL;
555 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IO, i); 530
556 if (pnp_res && !pnp_resource_valid(&pnp_res->res)) 531 list_add_tail(&pnp_res->list, &dev->resources);
557 return pnp_res; 532 return pnp_res;
558 }
559 break;
560 case IORESOURCE_MEM:
561 for (i = 0; i < PNP_MAX_MEM; i++) {
562 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_MEM, i);
563 if (pnp_res && !pnp_resource_valid(&pnp_res->res))
564 return pnp_res;
565 }
566 break;
567 case IORESOURCE_IRQ:
568 for (i = 0; i < PNP_MAX_IRQ; i++) {
569 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IRQ, i);
570 if (pnp_res && !pnp_resource_valid(&pnp_res->res))
571 return pnp_res;
572 }
573 break;
574 case IORESOURCE_DMA:
575 for (i = 0; i < PNP_MAX_DMA; i++) {
576 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_DMA, i);
577 if (pnp_res && !pnp_resource_valid(&pnp_res->res))
578 return pnp_res;
579 }
580 break;
581 }
582 return NULL;
583} 533}
584 534
585struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq, 535struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
@@ -589,7 +539,7 @@ struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
589 struct resource *res; 539 struct resource *res;
590 static unsigned char warned; 540 static unsigned char warned;
591 541
592 pnp_res = pnp_new_resource(dev, IORESOURCE_IRQ); 542 pnp_res = pnp_new_resource(dev);
593 if (!pnp_res) { 543 if (!pnp_res) {
594 if (!warned) { 544 if (!warned) {
595 dev_err(&dev->dev, "can't add resource for IRQ %d\n", 545 dev_err(&dev->dev, "can't add resource for IRQ %d\n",
@@ -615,7 +565,7 @@ struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma,
615 struct resource *res; 565 struct resource *res;
616 static unsigned char warned; 566 static unsigned char warned;
617 567
618 pnp_res = pnp_new_resource(dev, IORESOURCE_DMA); 568 pnp_res = pnp_new_resource(dev);
619 if (!pnp_res) { 569 if (!pnp_res) {
620 if (!warned) { 570 if (!warned) {
621 dev_err(&dev->dev, "can't add resource for DMA %d\n", 571 dev_err(&dev->dev, "can't add resource for DMA %d\n",
@@ -642,7 +592,7 @@ struct pnp_resource *pnp_add_io_resource(struct pnp_dev *dev,
642 struct resource *res; 592 struct resource *res;
643 static unsigned char warned; 593 static unsigned char warned;
644 594
645 pnp_res = pnp_new_resource(dev, IORESOURCE_IO); 595 pnp_res = pnp_new_resource(dev);
646 if (!pnp_res) { 596 if (!pnp_res) {
647 if (!warned) { 597 if (!warned) {
648 dev_err(&dev->dev, "can't add resource for IO " 598 dev_err(&dev->dev, "can't add resource for IO "
@@ -671,7 +621,7 @@ struct pnp_resource *pnp_add_mem_resource(struct pnp_dev *dev,
671 struct resource *res; 621 struct resource *res;
672 static unsigned char warned; 622 static unsigned char warned;
673 623
674 pnp_res = pnp_new_resource(dev, IORESOURCE_MEM); 624 pnp_res = pnp_new_resource(dev);
675 if (!pnp_res) { 625 if (!pnp_res) {
676 if (!warned) { 626 if (!warned) {
677 dev_err(&dev->dev, "can't add resource for MEM " 627 dev_err(&dev->dev, "can't add resource for MEM "