diff options
author | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2006-07-03 05:35:17 -0400 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2006-07-03 05:55:24 -0400 |
commit | cc9fd71c62f542233c412b5fabc1bbe0c4d5ad08 (patch) | |
tree | 67af54159a57029057765c7ce94b00081844a6c8 /arch/powerpc/kernel | |
parent | b9e5b4e6a991a5a6d521f2e20a65835404b4169f (diff) |
[POWERPC] New device-tree interrupt parsing code
Adds new routines to prom_parse to walk the device-tree for interrupt
information. This includes both direct mapping of interrupts and low
level parsing functions for use with partial trees.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/powerpc/kernel')
-rw-r--r-- | arch/powerpc/kernel/prom_parse.c | 443 |
1 files changed, 419 insertions, 24 deletions
diff --git a/arch/powerpc/kernel/prom_parse.c b/arch/powerpc/kernel/prom_parse.c index 45df420383cc..21009b1f7869 100644 --- a/arch/powerpc/kernel/prom_parse.c +++ b/arch/powerpc/kernel/prom_parse.c | |||
@@ -38,14 +38,6 @@ static void of_dump_addr(const char *s, u32 *addr, int na) | |||
38 | static void of_dump_addr(const char *s, u32 *addr, int na) { } | 38 | static void of_dump_addr(const char *s, u32 *addr, int na) { } |
39 | #endif | 39 | #endif |
40 | 40 | ||
41 | /* Read a big address */ | ||
42 | static inline u64 of_read_addr(u32 *cell, int size) | ||
43 | { | ||
44 | u64 r = 0; | ||
45 | while (size--) | ||
46 | r = (r << 32) | *(cell++); | ||
47 | return r; | ||
48 | } | ||
49 | 41 | ||
50 | /* Callbacks for bus specific translators */ | 42 | /* Callbacks for bus specific translators */ |
51 | struct of_bus { | 43 | struct of_bus { |
@@ -77,9 +69,9 @@ static u64 of_bus_default_map(u32 *addr, u32 *range, int na, int ns, int pna) | |||
77 | { | 69 | { |
78 | u64 cp, s, da; | 70 | u64 cp, s, da; |
79 | 71 | ||
80 | cp = of_read_addr(range, na); | 72 | cp = of_read_number(range, na); |
81 | s = of_read_addr(range + na + pna, ns); | 73 | s = of_read_number(range + na + pna, ns); |
82 | da = of_read_addr(addr, na); | 74 | da = of_read_number(addr, na); |
83 | 75 | ||
84 | DBG("OF: default map, cp="PRu64", s="PRu64", da="PRu64"\n", | 76 | DBG("OF: default map, cp="PRu64", s="PRu64", da="PRu64"\n", |
85 | cp, s, da); | 77 | cp, s, da); |
@@ -91,7 +83,7 @@ static u64 of_bus_default_map(u32 *addr, u32 *range, int na, int ns, int pna) | |||
91 | 83 | ||
92 | static int of_bus_default_translate(u32 *addr, u64 offset, int na) | 84 | static int of_bus_default_translate(u32 *addr, u64 offset, int na) |
93 | { | 85 | { |
94 | u64 a = of_read_addr(addr, na); | 86 | u64 a = of_read_number(addr, na); |
95 | memset(addr, 0, na * 4); | 87 | memset(addr, 0, na * 4); |
96 | a += offset; | 88 | a += offset; |
97 | if (na > 1) | 89 | if (na > 1) |
@@ -135,9 +127,9 @@ static u64 of_bus_pci_map(u32 *addr, u32 *range, int na, int ns, int pna) | |||
135 | return OF_BAD_ADDR; | 127 | return OF_BAD_ADDR; |
136 | 128 | ||
137 | /* Read address values, skipping high cell */ | 129 | /* Read address values, skipping high cell */ |
138 | cp = of_read_addr(range + 1, na - 1); | 130 | cp = of_read_number(range + 1, na - 1); |
139 | s = of_read_addr(range + na + pna, ns); | 131 | s = of_read_number(range + na + pna, ns); |
140 | da = of_read_addr(addr + 1, na - 1); | 132 | da = of_read_number(addr + 1, na - 1); |
141 | 133 | ||
142 | DBG("OF: PCI map, cp="PRu64", s="PRu64", da="PRu64"\n", cp, s, da); | 134 | DBG("OF: PCI map, cp="PRu64", s="PRu64", da="PRu64"\n", cp, s, da); |
143 | 135 | ||
@@ -195,9 +187,9 @@ static u64 of_bus_isa_map(u32 *addr, u32 *range, int na, int ns, int pna) | |||
195 | return OF_BAD_ADDR; | 187 | return OF_BAD_ADDR; |
196 | 188 | ||
197 | /* Read address values, skipping high cell */ | 189 | /* Read address values, skipping high cell */ |
198 | cp = of_read_addr(range + 1, na - 1); | 190 | cp = of_read_number(range + 1, na - 1); |
199 | s = of_read_addr(range + na + pna, ns); | 191 | s = of_read_number(range + na + pna, ns); |
200 | da = of_read_addr(addr + 1, na - 1); | 192 | da = of_read_number(addr + 1, na - 1); |
201 | 193 | ||
202 | DBG("OF: ISA map, cp="PRu64", s="PRu64", da="PRu64"\n", cp, s, da); | 194 | DBG("OF: ISA map, cp="PRu64", s="PRu64", da="PRu64"\n", cp, s, da); |
203 | 195 | ||
@@ -295,7 +287,7 @@ static int of_translate_one(struct device_node *parent, struct of_bus *bus, | |||
295 | */ | 287 | */ |
296 | ranges = (u32 *)get_property(parent, "ranges", &rlen); | 288 | ranges = (u32 *)get_property(parent, "ranges", &rlen); |
297 | if (ranges == NULL || rlen == 0) { | 289 | if (ranges == NULL || rlen == 0) { |
298 | offset = of_read_addr(addr, na); | 290 | offset = of_read_number(addr, na); |
299 | memset(addr, 0, pna * 4); | 291 | memset(addr, 0, pna * 4); |
300 | DBG("OF: no ranges, 1:1 translation\n"); | 292 | DBG("OF: no ranges, 1:1 translation\n"); |
301 | goto finish; | 293 | goto finish; |
@@ -378,7 +370,7 @@ u64 of_translate_address(struct device_node *dev, u32 *in_addr) | |||
378 | /* If root, we have finished */ | 370 | /* If root, we have finished */ |
379 | if (parent == NULL) { | 371 | if (parent == NULL) { |
380 | DBG("OF: reached root node\n"); | 372 | DBG("OF: reached root node\n"); |
381 | result = of_read_addr(addr, na); | 373 | result = of_read_number(addr, na); |
382 | break; | 374 | break; |
383 | } | 375 | } |
384 | 376 | ||
@@ -442,7 +434,7 @@ u32 *of_get_address(struct device_node *dev, int index, u64 *size, | |||
442 | for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++) | 434 | for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++) |
443 | if (i == index) { | 435 | if (i == index) { |
444 | if (size) | 436 | if (size) |
445 | *size = of_read_addr(prop + na, ns); | 437 | *size = of_read_number(prop + na, ns); |
446 | if (flags) | 438 | if (flags) |
447 | *flags = bus->get_flags(prop); | 439 | *flags = bus->get_flags(prop); |
448 | return prop; | 440 | return prop; |
@@ -484,7 +476,7 @@ u32 *of_get_pci_address(struct device_node *dev, int bar_no, u64 *size, | |||
484 | for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++) | 476 | for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++) |
485 | if ((prop[0] & 0xff) == ((bar_no * 4) + PCI_BASE_ADDRESS_0)) { | 477 | if ((prop[0] & 0xff) == ((bar_no * 4) + PCI_BASE_ADDRESS_0)) { |
486 | if (size) | 478 | if (size) |
487 | *size = of_read_addr(prop + na, ns); | 479 | *size = of_read_number(prop + na, ns); |
488 | if (flags) | 480 | if (flags) |
489 | *flags = bus->get_flags(prop); | 481 | *flags = bus->get_flags(prop); |
490 | return prop; | 482 | return prop; |
@@ -565,11 +557,414 @@ void of_parse_dma_window(struct device_node *dn, unsigned char *dma_window_prop, | |||
565 | prop = get_property(dn, "#address-cells", NULL); | 557 | prop = get_property(dn, "#address-cells", NULL); |
566 | 558 | ||
567 | cells = prop ? *(u32 *)prop : prom_n_addr_cells(dn); | 559 | cells = prop ? *(u32 *)prop : prom_n_addr_cells(dn); |
568 | *phys = of_read_addr(dma_window, cells); | 560 | *phys = of_read_number(dma_window, cells); |
569 | 561 | ||
570 | dma_window += cells; | 562 | dma_window += cells; |
571 | 563 | ||
572 | prop = get_property(dn, "ibm,#dma-size-cells", NULL); | 564 | prop = get_property(dn, "ibm,#dma-size-cells", NULL); |
573 | cells = prop ? *(u32 *)prop : prom_n_size_cells(dn); | 565 | cells = prop ? *(u32 *)prop : prom_n_size_cells(dn); |
574 | *size = of_read_addr(dma_window, cells); | 566 | *size = of_read_number(dma_window, cells); |
567 | } | ||
568 | |||
569 | /* | ||
570 | * Interrupt remapper | ||
571 | */ | ||
572 | |||
573 | static unsigned int of_irq_workarounds; | ||
574 | static struct device_node *of_irq_dflt_pic; | ||
575 | |||
576 | static struct device_node *of_irq_find_parent(struct device_node *child) | ||
577 | { | ||
578 | struct device_node *p; | ||
579 | phandle *parp; | ||
580 | |||
581 | if (!of_node_get(child)) | ||
582 | return NULL; | ||
583 | |||
584 | do { | ||
585 | parp = (phandle *)get_property(child, "interrupt-parent", NULL); | ||
586 | if (parp == NULL) | ||
587 | p = of_get_parent(child); | ||
588 | else { | ||
589 | if (of_irq_workarounds & OF_IMAP_NO_PHANDLE) | ||
590 | p = of_node_get(of_irq_dflt_pic); | ||
591 | else | ||
592 | p = of_find_node_by_phandle(*parp); | ||
593 | } | ||
594 | of_node_put(child); | ||
595 | child = p; | ||
596 | } while (p && get_property(p, "#interrupt-cells", NULL) == NULL); | ||
597 | |||
598 | return p; | ||
599 | } | ||
600 | |||
601 | static u8 of_irq_pci_swizzle(u8 slot, u8 pin) | ||
602 | { | ||
603 | return (((pin - 1) + slot) % 4) + 1; | ||
575 | } | 604 | } |
605 | |||
606 | /* This doesn't need to be called if you don't have any special workaround | ||
607 | * flags to pass | ||
608 | */ | ||
609 | void of_irq_map_init(unsigned int flags) | ||
610 | { | ||
611 | of_irq_workarounds = flags; | ||
612 | |||
613 | /* OldWorld, don't bother looking at other things */ | ||
614 | if (flags & OF_IMAP_OLDWORLD_MAC) | ||
615 | return; | ||
616 | |||
617 | /* If we don't have phandles, let's try to locate a default interrupt | ||
618 | * controller (happens when booting with BootX). We do a first match | ||
619 | * here, hopefully, that only ever happens on machines with one | ||
620 | * controller. | ||
621 | */ | ||
622 | if (flags & OF_IMAP_NO_PHANDLE) { | ||
623 | struct device_node *np; | ||
624 | |||
625 | for(np = NULL; (np = of_find_all_nodes(np)) != NULL;) { | ||
626 | if (get_property(np, "interrupt-controller", NULL) | ||
627 | == NULL) | ||
628 | continue; | ||
629 | /* Skip /chosen/interrupt-controller */ | ||
630 | if (strcmp(np->name, "chosen") == 0) | ||
631 | continue; | ||
632 | /* It seems like at least one person on this planet wants | ||
633 | * to use BootX on a machine with an AppleKiwi controller | ||
634 | * which happens to pretend to be an interrupt | ||
635 | * controller too. | ||
636 | */ | ||
637 | if (strcmp(np->name, "AppleKiwi") == 0) | ||
638 | continue; | ||
639 | /* I think we found one ! */ | ||
640 | of_irq_dflt_pic = np; | ||
641 | break; | ||
642 | } | ||
643 | } | ||
644 | |||
645 | } | ||
646 | |||
647 | int of_irq_map_raw(struct device_node *parent, u32 *intspec, u32 *addr, | ||
648 | struct of_irq *out_irq) | ||
649 | { | ||
650 | struct device_node *ipar, *tnode, *old = NULL, *newpar = NULL; | ||
651 | u32 *tmp, *imap, *imask; | ||
652 | u32 intsize = 1, addrsize, newintsize = 0, newaddrsize = 0; | ||
653 | int imaplen, match, i; | ||
654 | |||
655 | ipar = of_node_get(parent); | ||
656 | |||
657 | /* First get the #interrupt-cells property of the current cursor | ||
658 | * that tells us how to interpret the passed-in intspec. If there | ||
659 | * is none, we are nice and just walk up the tree | ||
660 | */ | ||
661 | do { | ||
662 | tmp = (u32 *)get_property(ipar, "#interrupt-cells", NULL); | ||
663 | if (tmp != NULL) { | ||
664 | intsize = *tmp; | ||
665 | break; | ||
666 | } | ||
667 | tnode = ipar; | ||
668 | ipar = of_irq_find_parent(ipar); | ||
669 | of_node_put(tnode); | ||
670 | } while (ipar); | ||
671 | if (ipar == NULL) { | ||
672 | DBG(" -> no parent found !\n"); | ||
673 | goto fail; | ||
674 | } | ||
675 | |||
676 | DBG("of_irq_map_raw: ipar=%s, size=%d\n", ipar->full_name, intsize); | ||
677 | |||
678 | /* Look for this #address-cells. We have to implement the old linux | ||
679 | * trick of looking for the parent here as some device-trees rely on it | ||
680 | */ | ||
681 | old = of_node_get(ipar); | ||
682 | do { | ||
683 | tmp = (u32 *)get_property(old, "#address-cells", NULL); | ||
684 | tnode = of_get_parent(old); | ||
685 | of_node_put(old); | ||
686 | old = tnode; | ||
687 | } while(old && tmp == NULL); | ||
688 | of_node_put(old); | ||
689 | old = NULL; | ||
690 | addrsize = (tmp == NULL) ? 2 : *tmp; | ||
691 | |||
692 | DBG(" -> addrsize=%d\n", addrsize); | ||
693 | |||
694 | /* Now start the actual "proper" walk of the interrupt tree */ | ||
695 | while (ipar != NULL) { | ||
696 | /* Now check if cursor is an interrupt-controller and if it is | ||
697 | * then we are done | ||
698 | */ | ||
699 | if (get_property(ipar, "interrupt-controller", NULL) != NULL) { | ||
700 | DBG(" -> got it !\n"); | ||
701 | memcpy(out_irq->specifier, intspec, | ||
702 | intsize * sizeof(u32)); | ||
703 | out_irq->size = intsize; | ||
704 | out_irq->controller = ipar; | ||
705 | of_node_put(old); | ||
706 | return 0; | ||
707 | } | ||
708 | |||
709 | /* Now look for an interrupt-map */ | ||
710 | imap = (u32 *)get_property(ipar, "interrupt-map", &imaplen); | ||
711 | /* No interrupt map, check for an interrupt parent */ | ||
712 | if (imap == NULL) { | ||
713 | DBG(" -> no map, getting parent\n"); | ||
714 | newpar = of_irq_find_parent(ipar); | ||
715 | goto skiplevel; | ||
716 | } | ||
717 | imaplen /= sizeof(u32); | ||
718 | |||
719 | /* Look for a mask */ | ||
720 | imask = (u32 *)get_property(ipar, "interrupt-map-mask", NULL); | ||
721 | |||
722 | /* If we were passed no "reg" property and we attempt to parse | ||
723 | * an interrupt-map, then #address-cells must be 0. | ||
724 | * Fail if it's not. | ||
725 | */ | ||
726 | if (addr == NULL && addrsize != 0) { | ||
727 | DBG(" -> no reg passed in when needed !\n"); | ||
728 | goto fail; | ||
729 | } | ||
730 | |||
731 | /* Parse interrupt-map */ | ||
732 | match = 0; | ||
733 | while (imaplen > (addrsize + intsize + 1) && !match) { | ||
734 | /* Compare specifiers */ | ||
735 | match = 1; | ||
736 | for (i = 0; i < addrsize && match; ++i) { | ||
737 | u32 mask = imask ? imask[i] : 0xffffffffu; | ||
738 | match = ((addr[i] ^ imap[i]) & mask) == 0; | ||
739 | } | ||
740 | for (; i < (addrsize + intsize) && match; ++i) { | ||
741 | u32 mask = imask ? imask[i] : 0xffffffffu; | ||
742 | match = | ||
743 | ((intspec[i-addrsize] ^ imap[i]) & mask) == 0; | ||
744 | } | ||
745 | imap += addrsize + intsize; | ||
746 | imaplen -= addrsize + intsize; | ||
747 | |||
748 | DBG(" -> match=%d (imaplen=%d)\n", match, imaplen); | ||
749 | |||
750 | /* Get the interrupt parent */ | ||
751 | if (of_irq_workarounds & OF_IMAP_NO_PHANDLE) | ||
752 | newpar = of_node_get(of_irq_dflt_pic); | ||
753 | else | ||
754 | newpar = of_find_node_by_phandle((phandle)*imap); | ||
755 | imap++; | ||
756 | --imaplen; | ||
757 | |||
758 | /* Check if not found */ | ||
759 | if (newpar == NULL) { | ||
760 | DBG(" -> imap parent not found !\n"); | ||
761 | goto fail; | ||
762 | } | ||
763 | |||
764 | /* Get #interrupt-cells and #address-cells of new | ||
765 | * parent | ||
766 | */ | ||
767 | tmp = (u32 *)get_property(newpar, "#interrupt-cells", | ||
768 | NULL); | ||
769 | if (tmp == NULL) { | ||
770 | DBG(" -> parent lacks #interrupt-cells !\n"); | ||
771 | goto fail; | ||
772 | } | ||
773 | newintsize = *tmp; | ||
774 | tmp = (u32 *)get_property(newpar, "#address-cells", | ||
775 | NULL); | ||
776 | newaddrsize = (tmp == NULL) ? 0 : *tmp; | ||
777 | |||
778 | DBG(" -> newintsize=%d, newaddrsize=%d\n", | ||
779 | newintsize, newaddrsize); | ||
780 | |||
781 | /* Check for malformed properties */ | ||
782 | if (imaplen < (newaddrsize + newintsize)) | ||
783 | goto fail; | ||
784 | |||
785 | imap += newaddrsize + newintsize; | ||
786 | imaplen -= newaddrsize + newintsize; | ||
787 | |||
788 | DBG(" -> imaplen=%d\n", imaplen); | ||
789 | } | ||
790 | if (!match) | ||
791 | goto fail; | ||
792 | |||
793 | of_node_put(old); | ||
794 | old = of_node_get(newpar); | ||
795 | addrsize = newaddrsize; | ||
796 | intsize = newintsize; | ||
797 | intspec = imap - intsize; | ||
798 | addr = intspec - addrsize; | ||
799 | |||
800 | skiplevel: | ||
801 | /* Iterate again with new parent */ | ||
802 | DBG(" -> new parent: %s\n", newpar ? newpar->full_name : "<>"); | ||
803 | of_node_put(ipar); | ||
804 | ipar = newpar; | ||
805 | newpar = NULL; | ||
806 | } | ||
807 | fail: | ||
808 | of_node_put(ipar); | ||
809 | of_node_put(old); | ||
810 | of_node_put(newpar); | ||
811 | |||
812 | return -EINVAL; | ||
813 | } | ||
814 | EXPORT_SYMBOL_GPL(of_irq_map_raw); | ||
815 | |||
816 | #if defined(CONFIG_PPC_PMAC) && defined(CONFIG_PPC32) | ||
817 | static int of_irq_map_oldworld(struct device_node *device, int index, | ||
818 | struct of_irq *out_irq) | ||
819 | { | ||
820 | u32 *ints; | ||
821 | int intlen; | ||
822 | |||
823 | /* | ||
824 | * Old machines just have a list of interrupt numbers | ||
825 | * and no interrupt-controller nodes. | ||
826 | */ | ||
827 | ints = (u32 *) get_property(device, "AAPL,interrupts", &intlen); | ||
828 | if (ints == NULL) | ||
829 | return -EINVAL; | ||
830 | intlen /= sizeof(u32); | ||
831 | |||
832 | if (index >= intlen) | ||
833 | return -EINVAL; | ||
834 | |||
835 | out_irq->controller = NULL; | ||
836 | out_irq->specifier[0] = ints[index]; | ||
837 | out_irq->size = 1; | ||
838 | |||
839 | return 0; | ||
840 | } | ||
841 | #else /* defined(CONFIG_PPC_PMAC) && defined(CONFIG_PPC32) */ | ||
842 | static int of_irq_map_oldworld(struct device_node *device, int index, | ||
843 | struct of_irq *out_irq) | ||
844 | { | ||
845 | return -EINVAL; | ||
846 | } | ||
847 | #endif /* !(defined(CONFIG_PPC_PMAC) && defined(CONFIG_PPC32)) */ | ||
848 | |||
849 | int of_irq_map_one(struct device_node *device, int index, struct of_irq *out_irq) | ||
850 | { | ||
851 | struct device_node *p; | ||
852 | u32 *intspec, *tmp, intsize, intlen, *addr; | ||
853 | int res; | ||
854 | |||
855 | DBG("of_irq_map_one: dev=%s, index=%d\n", device->full_name, index); | ||
856 | |||
857 | /* OldWorld mac stuff is "special", handle out of line */ | ||
858 | if (of_irq_workarounds & OF_IMAP_OLDWORLD_MAC) | ||
859 | return of_irq_map_oldworld(device, index, out_irq); | ||
860 | |||
861 | /* Get the interrupts property */ | ||
862 | intspec = (u32 *)get_property(device, "interrupts", &intlen); | ||
863 | if (intspec == NULL) | ||
864 | return -EINVAL; | ||
865 | intlen /= sizeof(u32); | ||
866 | |||
867 | /* Get the reg property (if any) */ | ||
868 | addr = (u32 *)get_property(device, "reg", NULL); | ||
869 | |||
870 | /* Look for the interrupt parent. */ | ||
871 | p = of_irq_find_parent(device); | ||
872 | if (p == NULL) | ||
873 | return -EINVAL; | ||
874 | |||
875 | /* Get size of interrupt specifier */ | ||
876 | tmp = (u32 *)get_property(p, "#interrupt-cells", NULL); | ||
877 | if (tmp == NULL) { | ||
878 | of_node_put(p); | ||
879 | return -EINVAL; | ||
880 | } | ||
881 | intsize = *tmp; | ||
882 | |||
883 | /* Check index */ | ||
884 | if (index * intsize >= intlen) | ||
885 | return -EINVAL; | ||
886 | |||
887 | /* Get new specifier and map it */ | ||
888 | res = of_irq_map_raw(p, intspec + index * intsize, addr, out_irq); | ||
889 | of_node_put(p); | ||
890 | return res; | ||
891 | } | ||
892 | EXPORT_SYMBOL_GPL(of_irq_map_one); | ||
893 | |||
894 | int of_irq_map_pci(struct pci_dev *pdev, struct of_irq *out_irq) | ||
895 | { | ||
896 | struct device_node *dn, *ppnode; | ||
897 | struct pci_dev *ppdev; | ||
898 | u32 lspec; | ||
899 | u32 laddr[3]; | ||
900 | u8 pin; | ||
901 | int rc; | ||
902 | |||
903 | /* Check if we have a device node, if yes, fallback to standard OF | ||
904 | * parsing | ||
905 | */ | ||
906 | dn = pci_device_to_OF_node(pdev); | ||
907 | if (dn) | ||
908 | return of_irq_map_one(dn, 0, out_irq); | ||
909 | |||
910 | /* Ok, we don't, time to have fun. Let's start by building up an | ||
911 | * interrupt spec. we assume #interrupt-cells is 1, which is standard | ||
912 | * for PCI. If you do different, then don't use that routine. | ||
913 | */ | ||
914 | rc = pci_read_config_byte(pdev, PCI_INTERRUPT_PIN, &pin); | ||
915 | if (rc != 0) | ||
916 | return rc; | ||
917 | /* No pin, exit */ | ||
918 | if (pin == 0) | ||
919 | return -ENODEV; | ||
920 | |||
921 | /* Now we walk up the PCI tree */ | ||
922 | lspec = pin; | ||
923 | for (;;) { | ||
924 | /* Get the pci_dev of our parent */ | ||
925 | ppdev = pdev->bus->self; | ||
926 | |||
927 | /* Ouch, it's a host bridge... */ | ||
928 | if (ppdev == NULL) { | ||
929 | #ifdef CONFIG_PPC64 | ||
930 | ppnode = pci_bus_to_OF_node(pdev->bus); | ||
931 | #else | ||
932 | struct pci_controller *host; | ||
933 | host = pci_bus_to_host(pdev->bus); | ||
934 | ppnode = host ? host->arch_data : NULL; | ||
935 | #endif | ||
936 | /* No node for host bridge ? give up */ | ||
937 | if (ppnode == NULL) | ||
938 | return -EINVAL; | ||
939 | } else | ||
940 | /* We found a P2P bridge, check if it has a node */ | ||
941 | ppnode = pci_device_to_OF_node(ppdev); | ||
942 | |||
943 | /* Ok, we have found a parent with a device-node, hand over to | ||
944 | * the OF parsing code. | ||
945 | * We build a unit address from the linux device to be used for | ||
946 | * resolution. Note that we use the linux bus number which may | ||
947 | * not match your firmware bus numbering. | ||
948 | * Fortunately, in most cases, interrupt-map-mask doesn't include | ||
949 | * the bus number as part of the matching. | ||
950 | * You should still be careful about that though if you intend | ||
951 | * to rely on this function (you ship a firmware that doesn't | ||
952 | * create device nodes for all PCI devices). | ||
953 | */ | ||
954 | if (ppnode) | ||
955 | break; | ||
956 | |||
957 | /* We can only get here if we hit a P2P bridge with no node, | ||
958 | * let's do standard swizzling and try again | ||
959 | */ | ||
960 | lspec = of_irq_pci_swizzle(PCI_SLOT(pdev->devfn), lspec); | ||
961 | pdev = ppdev; | ||
962 | } | ||
963 | |||
964 | laddr[0] = (pdev->bus->number << 16) | ||
965 | | (pdev->devfn << 8); | ||
966 | laddr[1] = laddr[2] = 0; | ||
967 | return of_irq_map_raw(ppnode, &lspec, laddr, out_irq); | ||
968 | } | ||
969 | EXPORT_SYMBOL_GPL(of_irq_map_pci); | ||
970 | |||