diff options
author | Bjorn Helgaas <bjorn.helgaas@hp.com> | 2006-03-28 17:04:00 -0500 |
---|---|---|
committer | Len Brown <len.brown@intel.com> | 2006-04-01 21:26:45 -0500 |
commit | b5f2490b6e3317059e87ba40d4f659d1c30afc1f (patch) | |
tree | 8eaa4898b89001bc5e53922d2414967f911b84dd /drivers/pnp/pnpacpi/rsparser.c | |
parent | 1acfb7f2b0d460ee86bdb25ad0679070ec8a5f0d (diff) |
PNPACPI: remove some code duplication
Factor out the duplicated switch from pnpacpi_count_resources() and
pnpacpi_type_resources(). Remove the unnecessary re-initialization of
resource->type and length from all the encode functions (id and length are
originally set in the pnpacpi_build_resource_template() ->
pnpacpi_type_resources() path).
Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'drivers/pnp/pnpacpi/rsparser.c')
-rw-r--r-- | drivers/pnp/pnpacpi/rsparser.c | 67 |
1 files changed, 18 insertions, 49 deletions
diff --git a/drivers/pnp/pnpacpi/rsparser.c b/drivers/pnp/pnpacpi/rsparser.c index 522d697cff0b..b13f85e0bc34 100644 --- a/drivers/pnp/pnpacpi/rsparser.c +++ b/drivers/pnp/pnpacpi/rsparser.c | |||
@@ -647,13 +647,8 @@ acpi_status pnpacpi_parse_resource_option_data(acpi_handle handle, | |||
647 | return status; | 647 | return status; |
648 | } | 648 | } |
649 | 649 | ||
650 | /* | 650 | static int pnpacpi_supported_resource(struct acpi_resource *res) |
651 | * Set resource | ||
652 | */ | ||
653 | static acpi_status pnpacpi_count_resources(struct acpi_resource *res, | ||
654 | void *data) | ||
655 | { | 651 | { |
656 | int *res_cnt = (int *)data; | ||
657 | switch (res->type) { | 652 | switch (res->type) { |
658 | case ACPI_RESOURCE_TYPE_IRQ: | 653 | case ACPI_RESOURCE_TYPE_IRQ: |
659 | case ACPI_RESOURCE_TYPE_DMA: | 654 | case ACPI_RESOURCE_TYPE_DMA: |
@@ -666,15 +661,21 @@ static acpi_status pnpacpi_count_resources(struct acpi_resource *res, | |||
666 | case ACPI_RESOURCE_TYPE_ADDRESS32: | 661 | case ACPI_RESOURCE_TYPE_ADDRESS32: |
667 | case ACPI_RESOURCE_TYPE_ADDRESS64: | 662 | case ACPI_RESOURCE_TYPE_ADDRESS64: |
668 | case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: | 663 | case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: |
669 | (*res_cnt) ++; | 664 | return 1; |
670 | case ACPI_RESOURCE_TYPE_START_DEPENDENT: | ||
671 | case ACPI_RESOURCE_TYPE_END_DEPENDENT: | ||
672 | case ACPI_RESOURCE_TYPE_VENDOR: | ||
673 | case ACPI_RESOURCE_TYPE_END_TAG: | ||
674 | case ACPI_RESOURCE_TYPE_GENERIC_REGISTER: | ||
675 | default: | ||
676 | return AE_OK; | ||
677 | } | 665 | } |
666 | return 0; | ||
667 | } | ||
668 | |||
669 | /* | ||
670 | * Set resource | ||
671 | */ | ||
672 | static acpi_status pnpacpi_count_resources(struct acpi_resource *res, | ||
673 | void *data) | ||
674 | { | ||
675 | int *res_cnt = (int *)data; | ||
676 | |||
677 | if (pnpacpi_supported_resource(res)) | ||
678 | (*res_cnt)++; | ||
678 | return AE_OK; | 679 | return AE_OK; |
679 | } | 680 | } |
680 | 681 | ||
@@ -682,27 +683,11 @@ static acpi_status pnpacpi_type_resources(struct acpi_resource *res, | |||
682 | void *data) | 683 | void *data) |
683 | { | 684 | { |
684 | struct acpi_resource **resource = (struct acpi_resource **)data; | 685 | struct acpi_resource **resource = (struct acpi_resource **)data; |
685 | switch (res->type) { | 686 | |
686 | case ACPI_RESOURCE_TYPE_IRQ: | 687 | if (pnpacpi_supported_resource(res)) { |
687 | case ACPI_RESOURCE_TYPE_DMA: | ||
688 | case ACPI_RESOURCE_TYPE_IO: | ||
689 | case ACPI_RESOURCE_TYPE_FIXED_IO: | ||
690 | case ACPI_RESOURCE_TYPE_MEMORY24: | ||
691 | case ACPI_RESOURCE_TYPE_MEMORY32: | ||
692 | case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: | ||
693 | case ACPI_RESOURCE_TYPE_ADDRESS16: | ||
694 | case ACPI_RESOURCE_TYPE_ADDRESS32: | ||
695 | case ACPI_RESOURCE_TYPE_ADDRESS64: | ||
696 | case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: | ||
697 | (*resource)->type = res->type; | 688 | (*resource)->type = res->type; |
689 | (*resource)->length = sizeof(struct acpi_resource); | ||
698 | (*resource)++; | 690 | (*resource)++; |
699 | case ACPI_RESOURCE_TYPE_START_DEPENDENT: | ||
700 | case ACPI_RESOURCE_TYPE_END_DEPENDENT: | ||
701 | case ACPI_RESOURCE_TYPE_VENDOR: | ||
702 | case ACPI_RESOURCE_TYPE_END_TAG: | ||
703 | case ACPI_RESOURCE_TYPE_GENERIC_REGISTER: | ||
704 | default: | ||
705 | return AE_OK; | ||
706 | } | 691 | } |
707 | 692 | ||
708 | return AE_OK; | 693 | return AE_OK; |
@@ -749,8 +734,6 @@ static void pnpacpi_encode_irq(struct acpi_resource *resource, | |||
749 | 734 | ||
750 | decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, | 735 | decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, |
751 | &polarity); | 736 | &polarity); |
752 | resource->type = ACPI_RESOURCE_TYPE_IRQ; | ||
753 | resource->length = sizeof(struct acpi_resource); | ||
754 | resource->data.irq.triggering = triggering; | 737 | resource->data.irq.triggering = triggering; |
755 | resource->data.irq.polarity = polarity; | 738 | resource->data.irq.polarity = polarity; |
756 | if (triggering == ACPI_EDGE_SENSITIVE) | 739 | if (triggering == ACPI_EDGE_SENSITIVE) |
@@ -768,8 +751,6 @@ static void pnpacpi_encode_ext_irq(struct acpi_resource *resource, | |||
768 | 751 | ||
769 | decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, | 752 | decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, |
770 | &polarity); | 753 | &polarity); |
771 | resource->type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ; | ||
772 | resource->length = sizeof(struct acpi_resource); | ||
773 | resource->data.extended_irq.producer_consumer = ACPI_CONSUMER; | 754 | resource->data.extended_irq.producer_consumer = ACPI_CONSUMER; |
774 | resource->data.extended_irq.triggering = triggering; | 755 | resource->data.extended_irq.triggering = triggering; |
775 | resource->data.extended_irq.polarity = polarity; | 756 | resource->data.extended_irq.polarity = polarity; |
@@ -784,8 +765,6 @@ static void pnpacpi_encode_ext_irq(struct acpi_resource *resource, | |||
784 | static void pnpacpi_encode_dma(struct acpi_resource *resource, | 765 | static void pnpacpi_encode_dma(struct acpi_resource *resource, |
785 | struct resource *p) | 766 | struct resource *p) |
786 | { | 767 | { |
787 | resource->type = ACPI_RESOURCE_TYPE_DMA; | ||
788 | resource->length = sizeof(struct acpi_resource); | ||
789 | /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */ | 768 | /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */ |
790 | if (p->flags & IORESOURCE_DMA_COMPATIBLE) | 769 | if (p->flags & IORESOURCE_DMA_COMPATIBLE) |
791 | resource->data.dma.type = ACPI_COMPATIBILITY; | 770 | resource->data.dma.type = ACPI_COMPATIBILITY; |
@@ -809,8 +788,6 @@ static void pnpacpi_encode_dma(struct acpi_resource *resource, | |||
809 | static void pnpacpi_encode_io(struct acpi_resource *resource, | 788 | static void pnpacpi_encode_io(struct acpi_resource *resource, |
810 | struct resource *p) | 789 | struct resource *p) |
811 | { | 790 | { |
812 | resource->type = ACPI_RESOURCE_TYPE_IO; | ||
813 | resource->length = sizeof(struct acpi_resource); | ||
814 | /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */ | 791 | /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */ |
815 | resource->data.io.io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR)? | 792 | resource->data.io.io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR)? |
816 | ACPI_DECODE_16 : ACPI_DECODE_10; | 793 | ACPI_DECODE_16 : ACPI_DECODE_10; |
@@ -823,8 +800,6 @@ static void pnpacpi_encode_io(struct acpi_resource *resource, | |||
823 | static void pnpacpi_encode_fixed_io(struct acpi_resource *resource, | 800 | static void pnpacpi_encode_fixed_io(struct acpi_resource *resource, |
824 | struct resource *p) | 801 | struct resource *p) |
825 | { | 802 | { |
826 | resource->type = ACPI_RESOURCE_TYPE_FIXED_IO; | ||
827 | resource->length = sizeof(struct acpi_resource); | ||
828 | resource->data.fixed_io.address = p->start; | 803 | resource->data.fixed_io.address = p->start; |
829 | resource->data.fixed_io.address_length = p->end - p->start + 1; | 804 | resource->data.fixed_io.address_length = p->end - p->start + 1; |
830 | } | 805 | } |
@@ -832,8 +807,6 @@ static void pnpacpi_encode_fixed_io(struct acpi_resource *resource, | |||
832 | static void pnpacpi_encode_mem24(struct acpi_resource *resource, | 807 | static void pnpacpi_encode_mem24(struct acpi_resource *resource, |
833 | struct resource *p) | 808 | struct resource *p) |
834 | { | 809 | { |
835 | resource->type = ACPI_RESOURCE_TYPE_MEMORY24; | ||
836 | resource->length = sizeof(struct acpi_resource); | ||
837 | /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */ | 810 | /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */ |
838 | resource->data.memory24.write_protect = | 811 | resource->data.memory24.write_protect = |
839 | (p->flags & IORESOURCE_MEM_WRITEABLE) ? | 812 | (p->flags & IORESOURCE_MEM_WRITEABLE) ? |
@@ -847,8 +820,6 @@ static void pnpacpi_encode_mem24(struct acpi_resource *resource, | |||
847 | static void pnpacpi_encode_mem32(struct acpi_resource *resource, | 820 | static void pnpacpi_encode_mem32(struct acpi_resource *resource, |
848 | struct resource *p) | 821 | struct resource *p) |
849 | { | 822 | { |
850 | resource->type = ACPI_RESOURCE_TYPE_MEMORY32; | ||
851 | resource->length = sizeof(struct acpi_resource); | ||
852 | resource->data.memory32.write_protect = | 823 | resource->data.memory32.write_protect = |
853 | (p->flags & IORESOURCE_MEM_WRITEABLE) ? | 824 | (p->flags & IORESOURCE_MEM_WRITEABLE) ? |
854 | ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; | 825 | ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; |
@@ -861,8 +832,6 @@ static void pnpacpi_encode_mem32(struct acpi_resource *resource, | |||
861 | static void pnpacpi_encode_fixed_mem32(struct acpi_resource *resource, | 832 | static void pnpacpi_encode_fixed_mem32(struct acpi_resource *resource, |
862 | struct resource *p) | 833 | struct resource *p) |
863 | { | 834 | { |
864 | resource->type = ACPI_RESOURCE_TYPE_FIXED_MEMORY32; | ||
865 | resource->length = sizeof(struct acpi_resource); | ||
866 | resource->data.fixed_memory32.write_protect = | 835 | resource->data.fixed_memory32.write_protect = |
867 | (p->flags & IORESOURCE_MEM_WRITEABLE) ? | 836 | (p->flags & IORESOURCE_MEM_WRITEABLE) ? |
868 | ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; | 837 | ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; |