aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pnp/resource.c
diff options
context:
space:
mode:
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 "