aboutsummaryrefslogtreecommitdiffstats
path: root/arch/microblaze
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/microblaze
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/microblaze')
-rw-r--r--arch/microblaze/include/asm/prom.h31
-rw-r--r--arch/microblaze/kernel/prom_parse.c290
2 files changed, 0 insertions, 321 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;