diff options
Diffstat (limited to 'arch/powerpc/kernel/pci-common.c')
-rw-r--r-- | arch/powerpc/kernel/pci-common.c | 216 |
1 files changed, 167 insertions, 49 deletions
diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c index ea0c61e09b76..01ce8c38bae6 100644 --- a/arch/powerpc/kernel/pci-common.c +++ b/arch/powerpc/kernel/pci-common.c | |||
@@ -56,6 +56,34 @@ resource_size_t isa_mem_base; | |||
56 | /* Default PCI flags is 0 */ | 56 | /* Default PCI flags is 0 */ |
57 | unsigned int ppc_pci_flags; | 57 | unsigned int ppc_pci_flags; |
58 | 58 | ||
59 | static struct dma_mapping_ops *pci_dma_ops; | ||
60 | |||
61 | void set_pci_dma_ops(struct dma_mapping_ops *dma_ops) | ||
62 | { | ||
63 | pci_dma_ops = dma_ops; | ||
64 | } | ||
65 | |||
66 | struct dma_mapping_ops *get_pci_dma_ops(void) | ||
67 | { | ||
68 | return pci_dma_ops; | ||
69 | } | ||
70 | EXPORT_SYMBOL(get_pci_dma_ops); | ||
71 | |||
72 | int pci_set_dma_mask(struct pci_dev *dev, u64 mask) | ||
73 | { | ||
74 | return dma_set_mask(&dev->dev, mask); | ||
75 | } | ||
76 | |||
77 | int pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask) | ||
78 | { | ||
79 | int rc; | ||
80 | |||
81 | rc = dma_set_mask(&dev->dev, mask); | ||
82 | dev->dev.coherent_dma_mask = dev->dma_mask; | ||
83 | |||
84 | return rc; | ||
85 | } | ||
86 | |||
59 | struct pci_controller *pcibios_alloc_controller(struct device_node *dev) | 87 | struct pci_controller *pcibios_alloc_controller(struct device_node *dev) |
60 | { | 88 | { |
61 | struct pci_controller *phb; | 89 | struct pci_controller *phb; |
@@ -180,6 +208,26 @@ char __devinit *pcibios_setup(char *str) | |||
180 | return str; | 208 | return str; |
181 | } | 209 | } |
182 | 210 | ||
211 | void __devinit pcibios_setup_new_device(struct pci_dev *dev) | ||
212 | { | ||
213 | struct dev_archdata *sd = &dev->dev.archdata; | ||
214 | |||
215 | sd->of_node = pci_device_to_OF_node(dev); | ||
216 | |||
217 | DBG("PCI: device %s OF node: %s\n", pci_name(dev), | ||
218 | sd->of_node ? sd->of_node->full_name : "<none>"); | ||
219 | |||
220 | sd->dma_ops = pci_dma_ops; | ||
221 | #ifdef CONFIG_PPC32 | ||
222 | sd->dma_data = (void *)PCI_DRAM_OFFSET; | ||
223 | #endif | ||
224 | set_dev_node(&dev->dev, pcibus_to_node(dev->bus)); | ||
225 | |||
226 | if (ppc_md.pci_dma_dev_setup) | ||
227 | ppc_md.pci_dma_dev_setup(dev); | ||
228 | } | ||
229 | EXPORT_SYMBOL(pcibios_setup_new_device); | ||
230 | |||
183 | /* | 231 | /* |
184 | * Reads the interrupt pin to determine if interrupt is use by card. | 232 | * Reads the interrupt pin to determine if interrupt is use by card. |
185 | * If the interrupt is used, then gets the interrupt line from the | 233 | * If the interrupt is used, then gets the interrupt line from the |
@@ -371,7 +419,7 @@ pgprot_t pci_phys_mem_access_prot(struct file *file, | |||
371 | struct pci_dev *pdev = NULL; | 419 | struct pci_dev *pdev = NULL; |
372 | struct resource *found = NULL; | 420 | struct resource *found = NULL; |
373 | unsigned long prot = pgprot_val(protection); | 421 | unsigned long prot = pgprot_val(protection); |
374 | unsigned long offset = pfn << PAGE_SHIFT; | 422 | resource_size_t offset = ((resource_size_t)pfn) << PAGE_SHIFT; |
375 | int i; | 423 | int i; |
376 | 424 | ||
377 | if (page_is_ram(pfn)) | 425 | if (page_is_ram(pfn)) |
@@ -422,7 +470,8 @@ pgprot_t pci_phys_mem_access_prot(struct file *file, | |||
422 | int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma, | 470 | int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma, |
423 | enum pci_mmap_state mmap_state, int write_combine) | 471 | enum pci_mmap_state mmap_state, int write_combine) |
424 | { | 472 | { |
425 | resource_size_t offset = vma->vm_pgoff << PAGE_SHIFT; | 473 | resource_size_t offset = |
474 | ((resource_size_t)vma->vm_pgoff) << PAGE_SHIFT; | ||
426 | struct resource *rp; | 475 | struct resource *rp; |
427 | int ret; | 476 | int ret; |
428 | 477 | ||
@@ -731,11 +780,6 @@ static void __devinit fixup_resource(struct resource *res, struct pci_dev *dev) | |||
731 | 780 | ||
732 | res->start = (res->start + offset) & mask; | 781 | res->start = (res->start + offset) & mask; |
733 | res->end = (res->end + offset) & mask; | 782 | res->end = (res->end + offset) & mask; |
734 | |||
735 | pr_debug("PCI:%s %016llx-%016llx\n", | ||
736 | pci_name(dev), | ||
737 | (unsigned long long)res->start, | ||
738 | (unsigned long long)res->end); | ||
739 | } | 783 | } |
740 | 784 | ||
741 | 785 | ||
@@ -781,6 +825,11 @@ static void __devinit pcibios_fixup_resources(struct pci_dev *dev) | |||
781 | (unsigned int)res->flags); | 825 | (unsigned int)res->flags); |
782 | 826 | ||
783 | fixup_resource(res, dev); | 827 | fixup_resource(res, dev); |
828 | |||
829 | pr_debug("PCI:%s %016llx-%016llx\n", | ||
830 | pci_name(dev), | ||
831 | (unsigned long long)res->start, | ||
832 | (unsigned long long)res->end); | ||
784 | } | 833 | } |
785 | 834 | ||
786 | /* Call machine specific resource fixup */ | 835 | /* Call machine specific resource fixup */ |
@@ -789,58 +838,127 @@ static void __devinit pcibios_fixup_resources(struct pci_dev *dev) | |||
789 | } | 838 | } |
790 | DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pcibios_fixup_resources); | 839 | DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pcibios_fixup_resources); |
791 | 840 | ||
792 | static void __devinit __pcibios_fixup_bus(struct pci_bus *bus) | 841 | /* This function tries to figure out if a bridge resource has been initialized |
842 | * by the firmware or not. It doesn't have to be absolutely bullet proof, but | ||
843 | * things go more smoothly when it gets it right. It should covers cases such | ||
844 | * as Apple "closed" bridge resources and bare-metal pSeries unassigned bridges | ||
845 | */ | ||
846 | static int __devinit pcibios_uninitialized_bridge_resource(struct pci_bus *bus, | ||
847 | struct resource *res) | ||
793 | { | 848 | { |
794 | struct pci_controller *hose = pci_bus_to_host(bus); | 849 | struct pci_controller *hose = pci_bus_to_host(bus); |
795 | struct pci_dev *dev = bus->self; | 850 | struct pci_dev *dev = bus->self; |
851 | resource_size_t offset; | ||
852 | u16 command; | ||
853 | int i; | ||
796 | 854 | ||
797 | pr_debug("PCI: Fixup bus %d (%s)\n", bus->number, dev ? pci_name(dev) : "PHB"); | 855 | /* We don't do anything if PCI_PROBE_ONLY is set */ |
856 | if (ppc_pci_flags & PPC_PCI_PROBE_ONLY) | ||
857 | return 0; | ||
798 | 858 | ||
799 | /* Fixup PCI<->PCI bridges. Host bridges are handled separately, for | 859 | /* Job is a bit different between memory and IO */ |
800 | * now differently between 32 and 64 bits. | 860 | if (res->flags & IORESOURCE_MEM) { |
801 | */ | 861 | /* If the BAR is non-0 (res != pci_mem_offset) then it's probably been |
802 | if (dev != NULL) { | 862 | * initialized by somebody |
803 | struct resource *res; | 863 | */ |
804 | int i; | 864 | if (res->start != hose->pci_mem_offset) |
865 | return 0; | ||
805 | 866 | ||
806 | for (i = 0; i < PCI_BUS_NUM_RESOURCES; ++i) { | 867 | /* The BAR is 0, let's check if memory decoding is enabled on |
807 | if ((res = bus->resource[i]) == NULL) | 868 | * the bridge. If not, we consider it unassigned |
808 | continue; | 869 | */ |
809 | if (!res->flags) | 870 | pci_read_config_word(dev, PCI_COMMAND, &command); |
810 | continue; | 871 | if ((command & PCI_COMMAND_MEMORY) == 0) |
811 | if (i >= 3 && bus->self->transparent) | 872 | return 1; |
812 | continue; | ||
813 | /* On PowerMac, Apple leaves bridge windows open over | ||
814 | * an inaccessible region of memory space (0...fffff) | ||
815 | * which is somewhat bogus, but that's what they think | ||
816 | * means disabled... | ||
817 | * | ||
818 | * We clear those to force them to be reallocated later | ||
819 | * | ||
820 | * We detect such regions by the fact that the base is | ||
821 | * equal to the pci_mem_offset of the host bridge and | ||
822 | * their size is smaller than 1M. | ||
823 | */ | ||
824 | if (res->flags & IORESOURCE_MEM && | ||
825 | res->start == hose->pci_mem_offset && | ||
826 | res->end < 0x100000) { | ||
827 | printk(KERN_INFO | ||
828 | "PCI: Closing bogus Apple Firmware" | ||
829 | " region %d on bus 0x%02x\n", | ||
830 | i, bus->number); | ||
831 | res->flags = 0; | ||
832 | continue; | ||
833 | } | ||
834 | 873 | ||
835 | pr_debug("PCI:%s Bus rsrc %d %016llx-%016llx [%x] fixup...\n", | 874 | /* Memory decoding is enabled and the BAR is 0. If any of the bridge |
836 | pci_name(dev), i, | 875 | * resources covers that starting address (0 then it's good enough for |
837 | (unsigned long long)res->start,\ | 876 | * us for memory |
838 | (unsigned long long)res->end, | 877 | */ |
839 | (unsigned int)res->flags); | 878 | for (i = 0; i < 3; i++) { |
879 | if ((hose->mem_resources[i].flags & IORESOURCE_MEM) && | ||
880 | hose->mem_resources[i].start == hose->pci_mem_offset) | ||
881 | return 0; | ||
882 | } | ||
840 | 883 | ||
841 | fixup_resource(res, dev); | 884 | /* Well, it starts at 0 and we know it will collide so we may as |
885 | * well consider it as unassigned. That covers the Apple case. | ||
886 | */ | ||
887 | return 1; | ||
888 | } else { | ||
889 | /* If the BAR is non-0, then we consider it assigned */ | ||
890 | offset = (unsigned long)hose->io_base_virt - _IO_BASE; | ||
891 | if (((res->start - offset) & 0xfffffffful) != 0) | ||
892 | return 0; | ||
893 | |||
894 | /* Here, we are a bit different than memory as typically IO space | ||
895 | * starting at low addresses -is- valid. What we do instead if that | ||
896 | * we consider as unassigned anything that doesn't have IO enabled | ||
897 | * in the PCI command register, and that's it. | ||
898 | */ | ||
899 | pci_read_config_word(dev, PCI_COMMAND, &command); | ||
900 | if (command & PCI_COMMAND_IO) | ||
901 | return 0; | ||
902 | |||
903 | /* It's starting at 0 and IO is disabled in the bridge, consider | ||
904 | * it unassigned | ||
905 | */ | ||
906 | return 1; | ||
907 | } | ||
908 | } | ||
909 | |||
910 | /* Fixup resources of a PCI<->PCI bridge */ | ||
911 | static void __devinit pcibios_fixup_bridge(struct pci_bus *bus) | ||
912 | { | ||
913 | struct resource *res; | ||
914 | int i; | ||
915 | |||
916 | struct pci_dev *dev = bus->self; | ||
917 | |||
918 | for (i = 0; i < PCI_BUS_NUM_RESOURCES; ++i) { | ||
919 | if ((res = bus->resource[i]) == NULL) | ||
920 | continue; | ||
921 | if (!res->flags) | ||
922 | continue; | ||
923 | if (i >= 3 && bus->self->transparent) | ||
924 | continue; | ||
925 | |||
926 | pr_debug("PCI:%s Bus rsrc %d %016llx-%016llx [%x] fixup...\n", | ||
927 | pci_name(dev), i, | ||
928 | (unsigned long long)res->start,\ | ||
929 | (unsigned long long)res->end, | ||
930 | (unsigned int)res->flags); | ||
931 | |||
932 | /* Perform fixup */ | ||
933 | fixup_resource(res, dev); | ||
934 | |||
935 | /* Try to detect uninitialized P2P bridge resources, | ||
936 | * and clear them out so they get re-assigned later | ||
937 | */ | ||
938 | if (pcibios_uninitialized_bridge_resource(bus, res)) { | ||
939 | res->flags = 0; | ||
940 | pr_debug("PCI:%s (unassigned)\n", pci_name(dev)); | ||
941 | } else { | ||
942 | |||
943 | pr_debug("PCI:%s %016llx-%016llx\n", | ||
944 | pci_name(dev), | ||
945 | (unsigned long long)res->start, | ||
946 | (unsigned long long)res->end); | ||
842 | } | 947 | } |
843 | } | 948 | } |
949 | } | ||
950 | |||
951 | static void __devinit __pcibios_fixup_bus(struct pci_bus *bus) | ||
952 | { | ||
953 | struct pci_dev *dev = bus->self; | ||
954 | |||
955 | pr_debug("PCI: Fixup bus %d (%s)\n", bus->number, dev ? pci_name(dev) : "PHB"); | ||
956 | |||
957 | /* Fixup PCI<->PCI bridges. Host bridges are handled separately, for | ||
958 | * now differently between 32 and 64 bits. | ||
959 | */ | ||
960 | if (dev != NULL) | ||
961 | pcibios_fixup_bridge(bus); | ||
844 | 962 | ||
845 | /* Additional setup that is different between 32 and 64 bits for now */ | 963 | /* Additional setup that is different between 32 and 64 bits for now */ |
846 | pcibios_do_bus_setup(bus); | 964 | pcibios_do_bus_setup(bus); |