aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@secretlab.ca>2010-06-08 09:48:06 -0400
committerGrant Likely <grant.likely@secretlab.ca>2010-07-05 18:14:25 -0400
commit7dc2e1134a22dc242175d5321c0c9e97d16eb87b (patch)
tree213406e4688340c788b40a8eb272255e8c44c8fe /arch
parentb83da291b4c73eaddc20e2edb614123a6d681b3b (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')
-rw-r--r--arch/microblaze/include/asm/prom.h31
-rw-r--r--arch/microblaze/kernel/prom_parse.c290
-rw-r--r--arch/powerpc/include/asm/prom.h47
-rw-r--r--arch/powerpc/kernel/prom_parse.c266
4 files changed, 0 insertions, 634 deletions
diff --git a/arch/microblaze/include/asm/prom.h b/arch/microblaze/include/asm/prom.h
index 4f34bc5baa83..5fbdfe76fe76 100644
--- a/arch/microblaze/include/asm/prom.h
+++ b/arch/microblaze/include/asm/prom.h
@@ -89,34 +89,6 @@ struct device_node *of_get_cpu_node(int cpu, unsigned int *thread);
89/* Get the MAC address */ 89/* Get the MAC address */
90extern const void *of_get_mac_address(struct device_node *np); 90extern const void *of_get_mac_address(struct device_node *np);
91 91
92/*
93 * OF interrupt mapping
94 */
95
96#define OF_IMAP_OLDWORLD_MAC 0x00000001
97#define OF_IMAP_NO_PHANDLE 0x00000002
98
99/**
100 * of_irq_map_raw - Low level interrupt tree parsing
101 * @parent: the device interrupt parent
102 * @intspec: interrupt specifier ("interrupts" property of the device)
103 * @ointsize: size of the passed in interrupt specifier
104 * @addr: address specifier (start of "reg" property of the device)
105 * @out_irq: structure of_irq filled by this function
106 *
107 * Returns 0 on success and a negative number on error
108 *
109 * This function is a low-level interrupt tree walking function. It
110 * can be used to do a partial walk with synthetized reg and interrupts
111 * properties, for example when resolving PCI interrupts when no device
112 * node exist for the parent.
113 *
114 */
115
116extern int of_irq_map_raw(struct device_node *parent, const u32 *intspec,
117 u32 ointsize, const u32 *addr,
118 struct of_irq *out_irq);
119
120/** 92/**
121 * of_irq_map_pci - Resolve the interrupt for a PCI device 93 * of_irq_map_pci - Resolve the interrupt for a PCI device
122 * @pdev: the device whose interrupt is to be resolved 94 * @pdev: the device whose interrupt is to be resolved
@@ -131,9 +103,6 @@ extern int of_irq_map_raw(struct device_node *parent, const u32 *intspec,
131struct pci_dev; 103struct pci_dev;
132extern int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq); 104extern int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq);
133 105
134extern int of_irq_to_resource(struct device_node *dev, int index,
135 struct resource *r);
136
137/** 106/**
138 * of_iomap - Maps the memory mapped IO for a given device_node 107 * of_iomap - Maps the memory mapped IO for a given device_node
139 * @device: the device whose io range will be mapped 108 * @device: the device whose io range will be mapped
diff --git a/arch/microblaze/kernel/prom_parse.c b/arch/microblaze/kernel/prom_parse.c
index cba05812ab46..e28968fa34c1 100644
--- a/arch/microblaze/kernel/prom_parse.c
+++ b/arch/microblaze/kernel/prom_parse.c
@@ -644,267 +644,6 @@ void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop,
644 *size = of_read_number(dma_window, cells); 644 *size = of_read_number(dma_window, cells);
645} 645}
646 646
647/*
648 * Interrupt remapper
649 */
650
651static unsigned int of_irq_workarounds;
652static struct device_node *of_irq_dflt_pic;
653
654static struct device_node *of_irq_find_parent(struct device_node *child)
655{
656 struct device_node *p;
657 const phandle *parp;
658
659 if (!of_node_get(child))
660 return NULL;
661
662 do {
663 parp = of_get_property(child, "interrupt-parent", NULL);
664 if (parp == NULL)
665 p = of_get_parent(child);
666 else {
667 if (of_irq_workarounds & OF_IMAP_NO_PHANDLE)
668 p = of_node_get(of_irq_dflt_pic);
669 else
670 p = of_find_node_by_phandle(*parp);
671 }
672 of_node_put(child);
673 child = p;
674 } while (p && of_get_property(p, "#interrupt-cells", NULL) == NULL);
675
676 return p;
677}
678
679int of_irq_map_raw(struct device_node *parent, const u32 *intspec, u32 ointsize,
680 const u32 *addr, struct of_irq *out_irq)
681{
682 struct device_node *ipar, *tnode, *old = NULL, *newpar = NULL;
683 const u32 *tmp, *imap, *imask;
684 u32 intsize = 1, addrsize, newintsize = 0, newaddrsize = 0;
685 int imaplen, match, i;
686
687 pr_debug("of_irq_map_raw: par=%s,intspec=[0x%08x 0x%08x...],"
688 "ointsize=%d\n",
689 parent->full_name, intspec[0], intspec[1], ointsize);
690
691 ipar = of_node_get(parent);
692
693 /* First get the #interrupt-cells property of the current cursor
694 * that tells us how to interpret the passed-in intspec. If there
695 * is none, we are nice and just walk up the tree
696 */
697 do {
698 tmp = of_get_property(ipar, "#interrupt-cells", NULL);
699 if (tmp != NULL) {
700 intsize = *tmp;
701 break;
702 }
703 tnode = ipar;
704 ipar = of_irq_find_parent(ipar);
705 of_node_put(tnode);
706 } while (ipar);
707 if (ipar == NULL) {
708 pr_debug(" -> no parent found !\n");
709 goto fail;
710 }
711
712 pr_debug("of_irq_map_raw: ipar=%s, size=%d\n",
713 ipar->full_name, intsize);
714
715 if (ointsize != intsize)
716 return -EINVAL;
717
718 /* Look for this #address-cells. We have to implement the old linux
719 * trick of looking for the parent here as some device-trees rely on it
720 */
721 old = of_node_get(ipar);
722 do {
723 tmp = of_get_property(old, "#address-cells", NULL);
724 tnode = of_get_parent(old);
725 of_node_put(old);
726 old = tnode;
727 } while (old && tmp == NULL);
728 of_node_put(old);
729 old = NULL;
730 addrsize = (tmp == NULL) ? 2 : *tmp;
731
732 pr_debug(" -> addrsize=%d\n", addrsize);
733
734 /* Now start the actual "proper" walk of the interrupt tree */
735 while (ipar != NULL) {
736 /* Now check if cursor is an interrupt-controller and if it is
737 * then we are done
738 */
739 if (of_get_property(ipar, "interrupt-controller", NULL) !=
740 NULL) {
741 pr_debug(" -> got it !\n");
742 memcpy(out_irq->specifier, intspec,
743 intsize * sizeof(u32));
744 out_irq->size = intsize;
745 out_irq->controller = ipar;
746 of_node_put(old);
747 return 0;
748 }
749
750 /* Now look for an interrupt-map */
751 imap = of_get_property(ipar, "interrupt-map", &imaplen);
752 /* No interrupt map, check for an interrupt parent */
753 if (imap == NULL) {
754 pr_debug(" -> no map, getting parent\n");
755 newpar = of_irq_find_parent(ipar);
756 goto skiplevel;
757 }
758 imaplen /= sizeof(u32);
759
760 /* Look for a mask */
761 imask = of_get_property(ipar, "interrupt-map-mask", NULL);
762
763 /* If we were passed no "reg" property and we attempt to parse
764 * an interrupt-map, then #address-cells must be 0.
765 * Fail if it's not.
766 */
767 if (addr == NULL && addrsize != 0) {
768 pr_debug(" -> no reg passed in when needed !\n");
769 goto fail;
770 }
771
772 /* Parse interrupt-map */
773 match = 0;
774 while (imaplen > (addrsize + intsize + 1) && !match) {
775 /* Compare specifiers */
776 match = 1;
777 for (i = 0; i < addrsize && match; ++i) {
778 u32 mask = imask ? imask[i] : 0xffffffffu;
779 match = ((addr[i] ^ imap[i]) & mask) == 0;
780 }
781 for (; i < (addrsize + intsize) && match; ++i) {
782 u32 mask = imask ? imask[i] : 0xffffffffu;
783 match =
784 ((intspec[i-addrsize] ^ imap[i])
785 & mask) == 0;
786 }
787 imap += addrsize + intsize;
788 imaplen -= addrsize + intsize;
789
790 pr_debug(" -> match=%d (imaplen=%d)\n", match, imaplen);
791
792 /* Get the interrupt parent */
793 if (of_irq_workarounds & OF_IMAP_NO_PHANDLE)
794 newpar = of_node_get(of_irq_dflt_pic);
795 else
796 newpar =
797 of_find_node_by_phandle((phandle)*imap);
798 imap++;
799 --imaplen;
800
801 /* Check if not found */
802 if (newpar == NULL) {
803 pr_debug(" -> imap parent not found !\n");
804 goto fail;
805 }
806
807 /* Get #interrupt-cells and #address-cells of new
808 * parent
809 */
810 tmp = of_get_property(newpar, "#interrupt-cells", NULL);
811 if (tmp == NULL) {
812 pr_debug(" -> parent lacks "
813 "#interrupt-cells!\n");
814 goto fail;
815 }
816 newintsize = *tmp;
817 tmp = of_get_property(newpar, "#address-cells", NULL);
818 newaddrsize = (tmp == NULL) ? 0 : *tmp;
819
820 pr_debug(" -> newintsize=%d, newaddrsize=%d\n",
821 newintsize, newaddrsize);
822
823 /* Check for malformed properties */
824 if (imaplen < (newaddrsize + newintsize))
825 goto fail;
826
827 imap += newaddrsize + newintsize;
828 imaplen -= newaddrsize + newintsize;
829
830 pr_debug(" -> imaplen=%d\n", imaplen);
831 }
832 if (!match)
833 goto fail;
834
835 of_node_put(old);
836 old = of_node_get(newpar);
837 addrsize = newaddrsize;
838 intsize = newintsize;
839 intspec = imap - intsize;
840 addr = intspec - addrsize;
841
842skiplevel:
843 /* Iterate again with new parent */
844 pr_debug(" -> new parent: %s\n",
845 newpar ? newpar->full_name : "<>");
846 of_node_put(ipar);
847 ipar = newpar;
848 newpar = NULL;
849 }
850fail:
851 of_node_put(ipar);
852 of_node_put(old);
853 of_node_put(newpar);
854
855 return -EINVAL;
856}
857EXPORT_SYMBOL_GPL(of_irq_map_raw);
858
859int of_irq_map_one(struct device_node *device,
860 int index, struct of_irq *out_irq)
861{
862 struct device_node *p;
863 const u32 *intspec, *tmp, *addr;
864 u32 intsize, intlen;
865 int res;
866
867 pr_debug("of_irq_map_one: dev=%s, index=%d\n",
868 device->full_name, index);
869
870 /* Get the interrupts property */
871 intspec = of_get_property(device, "interrupts", (int *) &intlen);
872 if (intspec == NULL)
873 return -EINVAL;
874 intlen /= sizeof(u32);
875
876 pr_debug(" intspec=%d intlen=%d\n", *intspec, intlen);
877
878 /* Get the reg property (if any) */
879 addr = of_get_property(device, "reg", NULL);
880
881 /* Look for the interrupt parent. */
882 p = of_irq_find_parent(device);
883 if (p == NULL)
884 return -EINVAL;
885
886 /* Get size of interrupt specifier */
887 tmp = of_get_property(p, "#interrupt-cells", NULL);
888 if (tmp == NULL) {
889 of_node_put(p);
890 return -EINVAL;
891 }
892 intsize = *tmp;
893
894 pr_debug(" intsize=%d intlen=%d\n", intsize, intlen);
895
896 /* Check index */
897 if ((index + 1) * intsize > intlen)
898 return -EINVAL;
899
900 /* Get new specifier and map it */
901 res = of_irq_map_raw(p, intspec + index * intsize, intsize,
902 addr, out_irq);
903 of_node_put(p);
904 return res;
905}
906EXPORT_SYMBOL_GPL(of_irq_map_one);
907
908/** 647/**
909 * Search the device tree for the best MAC address to use. 'mac-address' is 648 * Search the device tree for the best MAC address to use. 'mac-address' is
910 * checked first, because that is supposed to contain to "most recent" MAC 649 * checked first, because that is supposed to contain to "most recent" MAC
@@ -943,35 +682,6 @@ const void *of_get_mac_address(struct device_node *np)
943} 682}
944EXPORT_SYMBOL(of_get_mac_address); 683EXPORT_SYMBOL(of_get_mac_address);
945 684
946int of_irq_to_resource(struct device_node *dev, int index, struct resource *r)
947{
948 struct of_irq out_irq;
949 int irq;
950 int res;
951
952 res = of_irq_map_one(dev, index, &out_irq);
953
954 /* Get irq for the device */
955 if (res) {
956 pr_debug("IRQ not found... code = %d", res);
957 return NO_IRQ;
958 }
959 /* Assuming single interrupt controller... */
960 irq = out_irq.specifier[0];
961
962 pr_debug("IRQ found = %d", irq);
963
964 /* Only dereference the resource if both the
965 * resource and the irq are valid. */
966 if (r && irq != NO_IRQ) {
967 r->start = r->end = irq;
968 r->flags = IORESOURCE_IRQ;
969 }
970
971 return irq;
972}
973EXPORT_SYMBOL_GPL(of_irq_to_resource);
974
975void __iomem *of_iomap(struct device_node *np, int index) 685void __iomem *of_iomap(struct device_node *np, int index)
976{ 686{
977 struct resource res; 687 struct resource res;
diff --git a/arch/powerpc/include/asm/prom.h b/arch/powerpc/include/asm/prom.h
index 4486765db6e7..10d5ee556702 100644
--- a/arch/powerpc/include/asm/prom.h
+++ b/arch/powerpc/include/asm/prom.h
@@ -105,50 +105,6 @@ struct device_node *of_find_next_cache_node(struct device_node *np);
105/* Get the MAC address */ 105/* Get the MAC address */
106extern const void *of_get_mac_address(struct device_node *np); 106extern const void *of_get_mac_address(struct device_node *np);
107 107
108/*
109 * OF interrupt mapping
110 */
111
112#define OF_IMAP_OLDWORLD_MAC 0x00000001
113#define OF_IMAP_NO_PHANDLE 0x00000002
114
115#if defined(CONFIG_PPC32) && defined(CONFIG_PPC_PMAC)
116/* Workarounds only needed for 32bit powermac machines */
117extern unsigned int of_irq_workarounds;
118extern struct device_node *of_irq_dflt_pic;
119extern int of_irq_map_oldworld(struct device_node *device, int index,
120 struct of_irq *out_irq);
121#else
122#define of_irq_workarounds (0)
123#define of_irq_dflt_pic (NULL)
124static inline int of_irq_map_oldworld(struct device_node *device, int index,
125 struct of_irq *out_irq)
126{
127 return -EINVAL;
128}
129#endif
130
131/**
132 * of_irq_map_raw - Low level interrupt tree parsing
133 * @parent: the device interrupt parent
134 * @intspec: interrupt specifier ("interrupts" property of the device)
135 * @ointsize: size of the passed in interrupt specifier
136 * @addr: address specifier (start of "reg" property of the device)
137 * @out_irq: structure of_irq filled by this function
138 *
139 * Returns 0 on success and a negative number on error
140 *
141 * This function is a low-level interrupt tree walking function. It
142 * can be used to do a partial walk with synthetized reg and interrupts
143 * properties, for example when resolving PCI interrupts when no device
144 * node exist for the parent.
145 *
146 */
147
148extern int of_irq_map_raw(struct device_node *parent, const u32 *intspec,
149 u32 ointsize, const u32 *addr,
150 struct of_irq *out_irq);
151
152/** 108/**
153 * of_irq_map_pci - Resolve the interrupt for a PCI device 109 * of_irq_map_pci - Resolve the interrupt for a PCI device
154 * @pdev: the device whose interrupt is to be resolved 110 * @pdev: the device whose interrupt is to be resolved
@@ -163,9 +119,6 @@ extern int of_irq_map_raw(struct device_node *parent, const u32 *intspec,
163struct pci_dev; 119struct pci_dev;
164extern int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq); 120extern int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq);
165 121
166extern int of_irq_to_resource(struct device_node *dev, int index,
167 struct resource *r);
168
169/** 122/**
170 * of_iomap - Maps the memory mapped IO for a given device_node 123 * of_iomap - Maps the memory mapped IO for a given device_node
171 * @device: the device whose io range will be mapped 124 * @device: the device whose io range will be mapped
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
685static 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
710int 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}
882EXPORT_SYMBOL_GPL(of_irq_map_raw);
883
884int 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);
926out:
927 of_node_put(p);
928 return res;
929}
930EXPORT_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}
968EXPORT_SYMBOL(of_get_mac_address); 717EXPORT_SYMBOL(of_get_mac_address);
969 718
970int 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}
983EXPORT_SYMBOL_GPL(of_irq_to_resource);
984
985void __iomem *of_iomap(struct device_node *np, int index) 719void __iomem *of_iomap(struct device_node *np, int index)
986{ 720{
987 struct resource res; 721 struct resource res;