diff options
author | Grant Likely <grant.likely@secretlab.ca> | 2010-06-08 09:48:06 -0400 |
---|---|---|
committer | Grant Likely <grant.likely@secretlab.ca> | 2010-07-05 18:14:25 -0400 |
commit | 7dc2e1134a22dc242175d5321c0c9e97d16eb87b (patch) | |
tree | 213406e4688340c788b40a8eb272255e8c44c8fe /arch/powerpc/kernel/prom_parse.c | |
parent | b83da291b4c73eaddc20e2edb614123a6d681b3b (diff) |
of/irq: merge irq mapping code
Merge common irq mapping code between PowerPC and Microblaze.
This patch merges of_irq_find_parent(), of_irq_map_raw() and
of_irq_map_one(). The functions are dependent on one another, so all
three are merged in a single patch. Other than cosmetic difference
(ie. DBG() vs. pr_debug()), the implementations are identical.
of_irq_to_resource() is also merged, but in this case the
implementations are different. This patch drops the microblaze version
and uses the powerpc implementation unchanged. The microblaze version
essentially open-coded irq_of_parse_and_map() which it does not need
to do. Therefore the powerpc version is safe to adopt.
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
CC: Michal Simek <monstr@monstr.eu>
CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
CC: Stephen Rothwell <sfr@canb.auug.org.au>
Diffstat (limited to 'arch/powerpc/kernel/prom_parse.c')
-rw-r--r-- | arch/powerpc/kernel/prom_parse.c | 266 |
1 files changed, 0 insertions, 266 deletions
diff --git a/arch/powerpc/kernel/prom_parse.c b/arch/powerpc/kernel/prom_parse.c index dfa6de6572bb..d61a5c5fe690 100644 --- a/arch/powerpc/kernel/prom_parse.c +++ b/arch/powerpc/kernel/prom_parse.c | |||
@@ -678,257 +678,6 @@ void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop, | |||
678 | *size = of_read_number(dma_window, cells); | 678 | *size = of_read_number(dma_window, cells); |
679 | } | 679 | } |
680 | 680 | ||
681 | /* | ||
682 | * Interrupt remapper | ||
683 | */ | ||
684 | |||
685 | static struct device_node *of_irq_find_parent(struct device_node *child) | ||
686 | { | ||
687 | struct device_node *p; | ||
688 | const phandle *parp; | ||
689 | |||
690 | if (!of_node_get(child)) | ||
691 | return NULL; | ||
692 | |||
693 | do { | ||
694 | parp = of_get_property(child, "interrupt-parent", NULL); | ||
695 | if (parp == NULL) | ||
696 | p = of_get_parent(child); | ||
697 | else { | ||
698 | if (of_irq_workarounds & OF_IMAP_NO_PHANDLE) | ||
699 | p = of_node_get(of_irq_dflt_pic); | ||
700 | else | ||
701 | p = of_find_node_by_phandle(*parp); | ||
702 | } | ||
703 | of_node_put(child); | ||
704 | child = p; | ||
705 | } while (p && of_get_property(p, "#interrupt-cells", NULL) == NULL); | ||
706 | |||
707 | return p; | ||
708 | } | ||
709 | |||
710 | int of_irq_map_raw(struct device_node *parent, const u32 *intspec, u32 ointsize, | ||
711 | const u32 *addr, struct of_irq *out_irq) | ||
712 | { | ||
713 | struct device_node *ipar, *tnode, *old = NULL, *newpar = NULL; | ||
714 | const u32 *tmp, *imap, *imask; | ||
715 | u32 intsize = 1, addrsize, newintsize = 0, newaddrsize = 0; | ||
716 | int imaplen, match, i; | ||
717 | |||
718 | DBG("of_irq_map_raw: par=%s,intspec=[0x%08x 0x%08x...],ointsize=%d\n", | ||
719 | parent->full_name, intspec[0], intspec[1], ointsize); | ||
720 | |||
721 | ipar = of_node_get(parent); | ||
722 | |||
723 | /* First get the #interrupt-cells property of the current cursor | ||
724 | * that tells us how to interpret the passed-in intspec. If there | ||
725 | * is none, we are nice and just walk up the tree | ||
726 | */ | ||
727 | do { | ||
728 | tmp = of_get_property(ipar, "#interrupt-cells", NULL); | ||
729 | if (tmp != NULL) { | ||
730 | intsize = *tmp; | ||
731 | break; | ||
732 | } | ||
733 | tnode = ipar; | ||
734 | ipar = of_irq_find_parent(ipar); | ||
735 | of_node_put(tnode); | ||
736 | } while (ipar); | ||
737 | if (ipar == NULL) { | ||
738 | DBG(" -> no parent found !\n"); | ||
739 | goto fail; | ||
740 | } | ||
741 | |||
742 | DBG("of_irq_map_raw: ipar=%s, size=%d\n", ipar->full_name, intsize); | ||
743 | |||
744 | if (ointsize != intsize) | ||
745 | return -EINVAL; | ||
746 | |||
747 | /* Look for this #address-cells. We have to implement the old linux | ||
748 | * trick of looking for the parent here as some device-trees rely on it | ||
749 | */ | ||
750 | old = of_node_get(ipar); | ||
751 | do { | ||
752 | tmp = of_get_property(old, "#address-cells", NULL); | ||
753 | tnode = of_get_parent(old); | ||
754 | of_node_put(old); | ||
755 | old = tnode; | ||
756 | } while(old && tmp == NULL); | ||
757 | of_node_put(old); | ||
758 | old = NULL; | ||
759 | addrsize = (tmp == NULL) ? 2 : *tmp; | ||
760 | |||
761 | DBG(" -> addrsize=%d\n", addrsize); | ||
762 | |||
763 | /* Now start the actual "proper" walk of the interrupt tree */ | ||
764 | while (ipar != NULL) { | ||
765 | /* Now check if cursor is an interrupt-controller and if it is | ||
766 | * then we are done | ||
767 | */ | ||
768 | if (of_get_property(ipar, "interrupt-controller", NULL) != | ||
769 | NULL) { | ||
770 | DBG(" -> got it !\n"); | ||
771 | memcpy(out_irq->specifier, intspec, | ||
772 | intsize * sizeof(u32)); | ||
773 | out_irq->size = intsize; | ||
774 | out_irq->controller = ipar; | ||
775 | of_node_put(old); | ||
776 | return 0; | ||
777 | } | ||
778 | |||
779 | /* Now look for an interrupt-map */ | ||
780 | imap = of_get_property(ipar, "interrupt-map", &imaplen); | ||
781 | /* No interrupt map, check for an interrupt parent */ | ||
782 | if (imap == NULL) { | ||
783 | DBG(" -> no map, getting parent\n"); | ||
784 | newpar = of_irq_find_parent(ipar); | ||
785 | goto skiplevel; | ||
786 | } | ||
787 | imaplen /= sizeof(u32); | ||
788 | |||
789 | /* Look for a mask */ | ||
790 | imask = of_get_property(ipar, "interrupt-map-mask", NULL); | ||
791 | |||
792 | /* If we were passed no "reg" property and we attempt to parse | ||
793 | * an interrupt-map, then #address-cells must be 0. | ||
794 | * Fail if it's not. | ||
795 | */ | ||
796 | if (addr == NULL && addrsize != 0) { | ||
797 | DBG(" -> no reg passed in when needed !\n"); | ||
798 | goto fail; | ||
799 | } | ||
800 | |||
801 | /* Parse interrupt-map */ | ||
802 | match = 0; | ||
803 | while (imaplen > (addrsize + intsize + 1) && !match) { | ||
804 | /* Compare specifiers */ | ||
805 | match = 1; | ||
806 | for (i = 0; i < addrsize && match; ++i) { | ||
807 | u32 mask = imask ? imask[i] : 0xffffffffu; | ||
808 | match = ((addr[i] ^ imap[i]) & mask) == 0; | ||
809 | } | ||
810 | for (; i < (addrsize + intsize) && match; ++i) { | ||
811 | u32 mask = imask ? imask[i] : 0xffffffffu; | ||
812 | match = | ||
813 | ((intspec[i-addrsize] ^ imap[i]) & mask) == 0; | ||
814 | } | ||
815 | imap += addrsize + intsize; | ||
816 | imaplen -= addrsize + intsize; | ||
817 | |||
818 | DBG(" -> match=%d (imaplen=%d)\n", match, imaplen); | ||
819 | |||
820 | /* Get the interrupt parent */ | ||
821 | if (of_irq_workarounds & OF_IMAP_NO_PHANDLE) | ||
822 | newpar = of_node_get(of_irq_dflt_pic); | ||
823 | else | ||
824 | newpar = of_find_node_by_phandle((phandle)*imap); | ||
825 | imap++; | ||
826 | --imaplen; | ||
827 | |||
828 | /* Check if not found */ | ||
829 | if (newpar == NULL) { | ||
830 | DBG(" -> imap parent not found !\n"); | ||
831 | goto fail; | ||
832 | } | ||
833 | |||
834 | /* Get #interrupt-cells and #address-cells of new | ||
835 | * parent | ||
836 | */ | ||
837 | tmp = of_get_property(newpar, "#interrupt-cells", NULL); | ||
838 | if (tmp == NULL) { | ||
839 | DBG(" -> parent lacks #interrupt-cells !\n"); | ||
840 | goto fail; | ||
841 | } | ||
842 | newintsize = *tmp; | ||
843 | tmp = of_get_property(newpar, "#address-cells", NULL); | ||
844 | newaddrsize = (tmp == NULL) ? 0 : *tmp; | ||
845 | |||
846 | DBG(" -> newintsize=%d, newaddrsize=%d\n", | ||
847 | newintsize, newaddrsize); | ||
848 | |||
849 | /* Check for malformed properties */ | ||
850 | if (imaplen < (newaddrsize + newintsize)) | ||
851 | goto fail; | ||
852 | |||
853 | imap += newaddrsize + newintsize; | ||
854 | imaplen -= newaddrsize + newintsize; | ||
855 | |||
856 | DBG(" -> imaplen=%d\n", imaplen); | ||
857 | } | ||
858 | if (!match) | ||
859 | goto fail; | ||
860 | |||
861 | of_node_put(old); | ||
862 | old = of_node_get(newpar); | ||
863 | addrsize = newaddrsize; | ||
864 | intsize = newintsize; | ||
865 | intspec = imap - intsize; | ||
866 | addr = intspec - addrsize; | ||
867 | |||
868 | skiplevel: | ||
869 | /* Iterate again with new parent */ | ||
870 | DBG(" -> new parent: %s\n", newpar ? newpar->full_name : "<>"); | ||
871 | of_node_put(ipar); | ||
872 | ipar = newpar; | ||
873 | newpar = NULL; | ||
874 | } | ||
875 | fail: | ||
876 | of_node_put(ipar); | ||
877 | of_node_put(old); | ||
878 | of_node_put(newpar); | ||
879 | |||
880 | return -EINVAL; | ||
881 | } | ||
882 | EXPORT_SYMBOL_GPL(of_irq_map_raw); | ||
883 | |||
884 | int of_irq_map_one(struct device_node *device, int index, struct of_irq *out_irq) | ||
885 | { | ||
886 | struct device_node *p; | ||
887 | const u32 *intspec, *tmp, *addr; | ||
888 | u32 intsize, intlen; | ||
889 | int res = -EINVAL; | ||
890 | |||
891 | DBG("of_irq_map_one: dev=%s, index=%d\n", device->full_name, index); | ||
892 | |||
893 | /* OldWorld mac stuff is "special", handle out of line */ | ||
894 | if (of_irq_workarounds & OF_IMAP_OLDWORLD_MAC) | ||
895 | return of_irq_map_oldworld(device, index, out_irq); | ||
896 | |||
897 | /* Get the interrupts property */ | ||
898 | intspec = of_get_property(device, "interrupts", &intlen); | ||
899 | if (intspec == NULL) | ||
900 | return -EINVAL; | ||
901 | intlen /= sizeof(u32); | ||
902 | |||
903 | /* Get the reg property (if any) */ | ||
904 | addr = of_get_property(device, "reg", NULL); | ||
905 | |||
906 | /* Look for the interrupt parent. */ | ||
907 | p = of_irq_find_parent(device); | ||
908 | if (p == NULL) | ||
909 | return -EINVAL; | ||
910 | |||
911 | /* Get size of interrupt specifier */ | ||
912 | tmp = of_get_property(p, "#interrupt-cells", NULL); | ||
913 | if (tmp == NULL) | ||
914 | goto out; | ||
915 | intsize = *tmp; | ||
916 | |||
917 | DBG(" intsize=%d intlen=%d\n", intsize, intlen); | ||
918 | |||
919 | /* Check index */ | ||
920 | if ((index + 1) * intsize > intlen) | ||
921 | goto out; | ||
922 | |||
923 | /* Get new specifier and map it */ | ||
924 | res = of_irq_map_raw(p, intspec + index * intsize, intsize, | ||
925 | addr, out_irq); | ||
926 | out: | ||
927 | of_node_put(p); | ||
928 | return res; | ||
929 | } | ||
930 | EXPORT_SYMBOL_GPL(of_irq_map_one); | ||
931 | |||
932 | /** | 681 | /** |
933 | * Search the device tree for the best MAC address to use. 'mac-address' is | 682 | * Search the device tree for the best MAC address to use. 'mac-address' is |
934 | * checked first, because that is supposed to contain to "most recent" MAC | 683 | * checked first, because that is supposed to contain to "most recent" MAC |
@@ -967,21 +716,6 @@ const void *of_get_mac_address(struct device_node *np) | |||
967 | } | 716 | } |
968 | EXPORT_SYMBOL(of_get_mac_address); | 717 | EXPORT_SYMBOL(of_get_mac_address); |
969 | 718 | ||
970 | int of_irq_to_resource(struct device_node *dev, int index, struct resource *r) | ||
971 | { | ||
972 | int irq = irq_of_parse_and_map(dev, index); | ||
973 | |||
974 | /* Only dereference the resource if both the | ||
975 | * resource and the irq are valid. */ | ||
976 | if (r && irq != NO_IRQ) { | ||
977 | r->start = r->end = irq; | ||
978 | r->flags = IORESOURCE_IRQ; | ||
979 | } | ||
980 | |||
981 | return irq; | ||
982 | } | ||
983 | EXPORT_SYMBOL_GPL(of_irq_to_resource); | ||
984 | |||
985 | void __iomem *of_iomap(struct device_node *np, int index) | 719 | void __iomem *of_iomap(struct device_node *np, int index) |
986 | { | 720 | { |
987 | struct resource res; | 721 | struct resource res; |