aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/platforms/powernv/pci-ioda.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/powerpc/platforms/powernv/pci-ioda.c')
-rw-r--r--arch/powerpc/platforms/powernv/pci-ioda.c216
1 files changed, 193 insertions, 23 deletions
diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
index 414fd1a00fda..573ae1994097 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -116,16 +116,6 @@ static int __init iommu_setup(char *str)
116} 116}
117early_param("iommu", iommu_setup); 117early_param("iommu", iommu_setup);
118 118
119/*
120 * stdcix is only supposed to be used in hypervisor real mode as per
121 * the architecture spec
122 */
123static inline void __raw_rm_writeq(u64 val, volatile void __iomem *paddr)
124{
125 __asm__ __volatile__("stdcix %0,0,%1"
126 : : "r" (val), "r" (paddr) : "memory");
127}
128
129static inline bool pnv_pci_is_mem_pref_64(unsigned long flags) 119static inline bool pnv_pci_is_mem_pref_64(unsigned long flags)
130{ 120{
131 return ((flags & (IORESOURCE_MEM_64 | IORESOURCE_PREFETCH)) == 121 return ((flags & (IORESOURCE_MEM_64 | IORESOURCE_PREFETCH)) ==
@@ -344,7 +334,7 @@ static void __init pnv_ioda_parse_m64_window(struct pnv_phb *phb)
344 return; 334 return;
345 } 335 }
346 336
347 if (!firmware_has_feature(FW_FEATURE_OPALv3)) { 337 if (!firmware_has_feature(FW_FEATURE_OPAL)) {
348 pr_info(" Firmware too old to support M64 window\n"); 338 pr_info(" Firmware too old to support M64 window\n");
349 return; 339 return;
350 } 340 }
@@ -357,6 +347,7 @@ static void __init pnv_ioda_parse_m64_window(struct pnv_phb *phb)
357 } 347 }
358 348
359 res = &hose->mem_resources[1]; 349 res = &hose->mem_resources[1];
350 res->name = dn->full_name;
360 res->start = of_translate_address(dn, r + 2); 351 res->start = of_translate_address(dn, r + 2);
361 res->end = res->start + of_read_number(r + 4, 2) - 1; 352 res->end = res->start + of_read_number(r + 4, 2) - 1;
362 res->flags = (IORESOURCE_MEM | IORESOURCE_MEM_64 | IORESOURCE_PREFETCH); 353 res->flags = (IORESOURCE_MEM | IORESOURCE_MEM_64 | IORESOURCE_PREFETCH);
@@ -780,8 +771,12 @@ static int pnv_ioda_configure_pe(struct pnv_phb *phb, struct pnv_ioda_pe *pe)
780 return -ENXIO; 771 return -ENXIO;
781 } 772 }
782 773
783 /* Configure PELTV */ 774 /*
784 pnv_ioda_set_peltv(phb, pe, true); 775 * Configure PELTV. NPUs don't have a PELTV table so skip
776 * configuration on them.
777 */
778 if (phb->type != PNV_PHB_NPU)
779 pnv_ioda_set_peltv(phb, pe, true);
785 780
786 /* Setup reverse map */ 781 /* Setup reverse map */
787 for (rid = pe->rid; rid < rid_end; rid++) 782 for (rid = pe->rid; rid < rid_end; rid++)
@@ -924,7 +919,6 @@ static int pnv_pci_vf_resource_shift(struct pci_dev *dev, int offset)
924} 919}
925#endif /* CONFIG_PCI_IOV */ 920#endif /* CONFIG_PCI_IOV */
926 921
927#if 0
928static struct pnv_ioda_pe *pnv_ioda_setup_dev_PE(struct pci_dev *dev) 922static struct pnv_ioda_pe *pnv_ioda_setup_dev_PE(struct pci_dev *dev)
929{ 923{
930 struct pci_controller *hose = pci_bus_to_host(dev->bus); 924 struct pci_controller *hose = pci_bus_to_host(dev->bus);
@@ -941,11 +935,7 @@ static struct pnv_ioda_pe *pnv_ioda_setup_dev_PE(struct pci_dev *dev)
941 if (pdn->pe_number != IODA_INVALID_PE) 935 if (pdn->pe_number != IODA_INVALID_PE)
942 return NULL; 936 return NULL;
943 937
944 /* PE#0 has been pre-set */ 938 pe_num = pnv_ioda_alloc_pe(phb);
945 if (dev->bus->number == 0)
946 pe_num = 0;
947 else
948 pe_num = pnv_ioda_alloc_pe(phb);
949 if (pe_num == IODA_INVALID_PE) { 939 if (pe_num == IODA_INVALID_PE) {
950 pr_warning("%s: Not enough PE# available, disabling device\n", 940 pr_warning("%s: Not enough PE# available, disabling device\n",
951 pci_name(dev)); 941 pci_name(dev));
@@ -963,6 +953,7 @@ static struct pnv_ioda_pe *pnv_ioda_setup_dev_PE(struct pci_dev *dev)
963 pci_dev_get(dev); 953 pci_dev_get(dev);
964 pdn->pcidev = dev; 954 pdn->pcidev = dev;
965 pdn->pe_number = pe_num; 955 pdn->pe_number = pe_num;
956 pe->flags = PNV_IODA_PE_DEV;
966 pe->pdev = dev; 957 pe->pdev = dev;
967 pe->pbus = NULL; 958 pe->pbus = NULL;
968 pe->tce32_seg = -1; 959 pe->tce32_seg = -1;
@@ -993,7 +984,6 @@ static struct pnv_ioda_pe *pnv_ioda_setup_dev_PE(struct pci_dev *dev)
993 984
994 return pe; 985 return pe;
995} 986}
996#endif /* Useful for SRIOV case */
997 987
998static void pnv_ioda_setup_same_PE(struct pci_bus *bus, struct pnv_ioda_pe *pe) 988static void pnv_ioda_setup_same_PE(struct pci_bus *bus, struct pnv_ioda_pe *pe)
999{ 989{
@@ -1007,6 +997,7 @@ static void pnv_ioda_setup_same_PE(struct pci_bus *bus, struct pnv_ioda_pe *pe)
1007 pci_name(dev)); 997 pci_name(dev));
1008 continue; 998 continue;
1009 } 999 }
1000 pdn->pcidev = dev;
1010 pdn->pe_number = pe->pe_number; 1001 pdn->pe_number = pe->pe_number;
1011 pe->dma_weight += pnv_ioda_dma_weight(dev); 1002 pe->dma_weight += pnv_ioda_dma_weight(dev);
1012 if ((pe->flags & PNV_IODA_PE_BUS_ALL) && dev->subordinate) 1003 if ((pe->flags & PNV_IODA_PE_BUS_ALL) && dev->subordinate)
@@ -1083,6 +1074,77 @@ static void pnv_ioda_setup_bus_PE(struct pci_bus *bus, bool all)
1083 pnv_ioda_link_pe_by_weight(phb, pe); 1074 pnv_ioda_link_pe_by_weight(phb, pe);
1084} 1075}
1085 1076
1077static struct pnv_ioda_pe *pnv_ioda_setup_npu_PE(struct pci_dev *npu_pdev)
1078{
1079 int pe_num, found_pe = false, rc;
1080 long rid;
1081 struct pnv_ioda_pe *pe;
1082 struct pci_dev *gpu_pdev;
1083 struct pci_dn *npu_pdn;
1084 struct pci_controller *hose = pci_bus_to_host(npu_pdev->bus);
1085 struct pnv_phb *phb = hose->private_data;
1086
1087 /*
1088 * Due to a hardware errata PE#0 on the NPU is reserved for
1089 * error handling. This means we only have three PEs remaining
1090 * which need to be assigned to four links, implying some
1091 * links must share PEs.
1092 *
1093 * To achieve this we assign PEs such that NPUs linking the
1094 * same GPU get assigned the same PE.
1095 */
1096 gpu_pdev = pnv_pci_get_gpu_dev(npu_pdev);
1097 for (pe_num = 0; pe_num < phb->ioda.total_pe; pe_num++) {
1098 pe = &phb->ioda.pe_array[pe_num];
1099 if (!pe->pdev)
1100 continue;
1101
1102 if (pnv_pci_get_gpu_dev(pe->pdev) == gpu_pdev) {
1103 /*
1104 * This device has the same peer GPU so should
1105 * be assigned the same PE as the existing
1106 * peer NPU.
1107 */
1108 dev_info(&npu_pdev->dev,
1109 "Associating to existing PE %d\n", pe_num);
1110 pci_dev_get(npu_pdev);
1111 npu_pdn = pci_get_pdn(npu_pdev);
1112 rid = npu_pdev->bus->number << 8 | npu_pdn->devfn;
1113 npu_pdn->pcidev = npu_pdev;
1114 npu_pdn->pe_number = pe_num;
1115 pe->dma_weight += pnv_ioda_dma_weight(npu_pdev);
1116 phb->ioda.pe_rmap[rid] = pe->pe_number;
1117
1118 /* Map the PE to this link */
1119 rc = opal_pci_set_pe(phb->opal_id, pe_num, rid,
1120 OpalPciBusAll,
1121 OPAL_COMPARE_RID_DEVICE_NUMBER,
1122 OPAL_COMPARE_RID_FUNCTION_NUMBER,
1123 OPAL_MAP_PE);
1124 WARN_ON(rc != OPAL_SUCCESS);
1125 found_pe = true;
1126 break;
1127 }
1128 }
1129
1130 if (!found_pe)
1131 /*
1132 * Could not find an existing PE so allocate a new
1133 * one.
1134 */
1135 return pnv_ioda_setup_dev_PE(npu_pdev);
1136 else
1137 return pe;
1138}
1139
1140static void pnv_ioda_setup_npu_PEs(struct pci_bus *bus)
1141{
1142 struct pci_dev *pdev;
1143
1144 list_for_each_entry(pdev, &bus->devices, bus_list)
1145 pnv_ioda_setup_npu_PE(pdev);
1146}
1147
1086static void pnv_ioda_setup_PEs(struct pci_bus *bus) 1148static void pnv_ioda_setup_PEs(struct pci_bus *bus)
1087{ 1149{
1088 struct pci_dev *dev; 1150 struct pci_dev *dev;
@@ -1119,7 +1181,17 @@ static void pnv_pci_ioda_setup_PEs(void)
1119 if (phb->reserve_m64_pe) 1181 if (phb->reserve_m64_pe)
1120 phb->reserve_m64_pe(hose->bus, NULL, true); 1182 phb->reserve_m64_pe(hose->bus, NULL, true);
1121 1183
1122 pnv_ioda_setup_PEs(hose->bus); 1184 /*
1185 * On NPU PHB, we expect separate PEs for individual PCI
1186 * functions. PCI bus dependent PEs are required for the
1187 * remaining types of PHBs.
1188 */
1189 if (phb->type == PNV_PHB_NPU) {
1190 /* PE#0 is needed for error reporting */
1191 pnv_ioda_reserve_pe(phb, 0);
1192 pnv_ioda_setup_npu_PEs(hose->bus);
1193 } else
1194 pnv_ioda_setup_PEs(hose->bus);
1123 } 1195 }
1124} 1196}
1125 1197
@@ -1578,6 +1650,8 @@ static int pnv_pci_ioda_dma_set_mask(struct pci_dev *pdev, u64 dma_mask)
1578 struct pnv_ioda_pe *pe; 1650 struct pnv_ioda_pe *pe;
1579 uint64_t top; 1651 uint64_t top;
1580 bool bypass = false; 1652 bool bypass = false;
1653 struct pci_dev *linked_npu_dev;
1654 int i;
1581 1655
1582 if (WARN_ON(!pdn || pdn->pe_number == IODA_INVALID_PE)) 1656 if (WARN_ON(!pdn || pdn->pe_number == IODA_INVALID_PE))
1583 return -ENODEV;; 1657 return -ENODEV;;
@@ -1596,6 +1670,18 @@ static int pnv_pci_ioda_dma_set_mask(struct pci_dev *pdev, u64 dma_mask)
1596 set_dma_ops(&pdev->dev, &dma_iommu_ops); 1670 set_dma_ops(&pdev->dev, &dma_iommu_ops);
1597 } 1671 }
1598 *pdev->dev.dma_mask = dma_mask; 1672 *pdev->dev.dma_mask = dma_mask;
1673
1674 /* Update peer npu devices */
1675 if (pe->flags & PNV_IODA_PE_PEER)
1676 for (i = 0; i < PNV_IODA_MAX_PEER_PES; i++) {
1677 if (!pe->peers[i])
1678 continue;
1679
1680 linked_npu_dev = pe->peers[i]->pdev;
1681 if (dma_get_mask(&linked_npu_dev->dev) != dma_mask)
1682 dma_set_mask(&linked_npu_dev->dev, dma_mask);
1683 }
1684
1599 return 0; 1685 return 0;
1600} 1686}
1601 1687
@@ -1740,12 +1826,23 @@ static inline void pnv_pci_ioda2_tce_invalidate_entire(struct pnv_ioda_pe *pe)
1740 /* 01xb - invalidate TCEs that match the specified PE# */ 1826 /* 01xb - invalidate TCEs that match the specified PE# */
1741 unsigned long val = (0x4ull << 60) | (pe->pe_number & 0xFF); 1827 unsigned long val = (0x4ull << 60) | (pe->pe_number & 0xFF);
1742 struct pnv_phb *phb = pe->phb; 1828 struct pnv_phb *phb = pe->phb;
1829 struct pnv_ioda_pe *npe;
1830 int i;
1743 1831
1744 if (!phb->ioda.tce_inval_reg) 1832 if (!phb->ioda.tce_inval_reg)
1745 return; 1833 return;
1746 1834
1747 mb(); /* Ensure above stores are visible */ 1835 mb(); /* Ensure above stores are visible */
1748 __raw_writeq(cpu_to_be64(val), phb->ioda.tce_inval_reg); 1836 __raw_writeq(cpu_to_be64(val), phb->ioda.tce_inval_reg);
1837
1838 if (pe->flags & PNV_IODA_PE_PEER)
1839 for (i = 0; i < PNV_IODA_MAX_PEER_PES; i++) {
1840 npe = pe->peers[i];
1841 if (!npe || npe->phb->type != PNV_PHB_NPU)
1842 continue;
1843
1844 pnv_npu_tce_invalidate_entire(npe);
1845 }
1749} 1846}
1750 1847
1751static void pnv_pci_ioda2_do_tce_invalidate(unsigned pe_number, bool rm, 1848static void pnv_pci_ioda2_do_tce_invalidate(unsigned pe_number, bool rm,
@@ -1780,15 +1877,28 @@ static void pnv_pci_ioda2_tce_invalidate(struct iommu_table *tbl,
1780 struct iommu_table_group_link *tgl; 1877 struct iommu_table_group_link *tgl;
1781 1878
1782 list_for_each_entry_rcu(tgl, &tbl->it_group_list, next) { 1879 list_for_each_entry_rcu(tgl, &tbl->it_group_list, next) {
1880 struct pnv_ioda_pe *npe;
1783 struct pnv_ioda_pe *pe = container_of(tgl->table_group, 1881 struct pnv_ioda_pe *pe = container_of(tgl->table_group,
1784 struct pnv_ioda_pe, table_group); 1882 struct pnv_ioda_pe, table_group);
1785 __be64 __iomem *invalidate = rm ? 1883 __be64 __iomem *invalidate = rm ?
1786 (__be64 __iomem *)pe->phb->ioda.tce_inval_reg_phys : 1884 (__be64 __iomem *)pe->phb->ioda.tce_inval_reg_phys :
1787 pe->phb->ioda.tce_inval_reg; 1885 pe->phb->ioda.tce_inval_reg;
1886 int i;
1788 1887
1789 pnv_pci_ioda2_do_tce_invalidate(pe->pe_number, rm, 1888 pnv_pci_ioda2_do_tce_invalidate(pe->pe_number, rm,
1790 invalidate, tbl->it_page_shift, 1889 invalidate, tbl->it_page_shift,
1791 index, npages); 1890 index, npages);
1891
1892 if (pe->flags & PNV_IODA_PE_PEER)
1893 /* Invalidate PEs using the same TCE table */
1894 for (i = 0; i < PNV_IODA_MAX_PEER_PES; i++) {
1895 npe = pe->peers[i];
1896 if (!npe || npe->phb->type != PNV_PHB_NPU)
1897 continue;
1898
1899 pnv_npu_tce_invalidate(npe, tbl, index,
1900 npages, rm);
1901 }
1792 } 1902 }
1793} 1903}
1794 1904
@@ -2436,10 +2546,17 @@ static void pnv_ioda_setup_dma(struct pnv_phb *phb)
2436 pe_info(pe, "DMA weight %d, assigned %d DMA32 segments\n", 2546 pe_info(pe, "DMA weight %d, assigned %d DMA32 segments\n",
2437 pe->dma_weight, segs); 2547 pe->dma_weight, segs);
2438 pnv_pci_ioda_setup_dma_pe(phb, pe, base, segs); 2548 pnv_pci_ioda_setup_dma_pe(phb, pe, base, segs);
2439 } else { 2549 } else if (phb->type == PNV_PHB_IODA2) {
2440 pe_info(pe, "Assign DMA32 space\n"); 2550 pe_info(pe, "Assign DMA32 space\n");
2441 segs = 0; 2551 segs = 0;
2442 pnv_pci_ioda2_setup_dma_pe(phb, pe); 2552 pnv_pci_ioda2_setup_dma_pe(phb, pe);
2553 } else if (phb->type == PNV_PHB_NPU) {
2554 /*
2555 * We initialise the DMA space for an NPU PHB
2556 * after setup of the PHB is complete as we
2557 * point the NPU TVT to the the same location
2558 * as the PHB3 TVT.
2559 */
2443 } 2560 }
2444 2561
2445 remaining -= segs; 2562 remaining -= segs;
@@ -2881,6 +2998,11 @@ static void pnv_pci_ioda_setup_seg(void)
2881 2998
2882 list_for_each_entry_safe(hose, tmp, &hose_list, list_node) { 2999 list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
2883 phb = hose->private_data; 3000 phb = hose->private_data;
3001
3002 /* NPU PHB does not support IO or MMIO segmentation */
3003 if (phb->type == PNV_PHB_NPU)
3004 continue;
3005
2884 list_for_each_entry(pe, &phb->ioda.pe_list, list) { 3006 list_for_each_entry(pe, &phb->ioda.pe_list, list) {
2885 pnv_ioda_setup_pe_seg(hose, pe); 3007 pnv_ioda_setup_pe_seg(hose, pe);
2886 } 3008 }
@@ -2920,6 +3042,27 @@ static void pnv_pci_ioda_create_dbgfs(void)
2920#endif /* CONFIG_DEBUG_FS */ 3042#endif /* CONFIG_DEBUG_FS */
2921} 3043}
2922 3044
3045static void pnv_npu_ioda_fixup(void)
3046{
3047 bool enable_bypass;
3048 struct pci_controller *hose, *tmp;
3049 struct pnv_phb *phb;
3050 struct pnv_ioda_pe *pe;
3051
3052 list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
3053 phb = hose->private_data;
3054 if (phb->type != PNV_PHB_NPU)
3055 continue;
3056
3057 list_for_each_entry(pe, &phb->ioda.pe_dma_list, dma_link) {
3058 enable_bypass = dma_get_mask(&pe->pdev->dev) ==
3059 DMA_BIT_MASK(64);
3060 pnv_npu_init_dma_pe(pe);
3061 pnv_npu_dma_set_bypass(pe, enable_bypass);
3062 }
3063 }
3064}
3065
2923static void pnv_pci_ioda_fixup(void) 3066static void pnv_pci_ioda_fixup(void)
2924{ 3067{
2925 pnv_pci_ioda_setup_PEs(); 3068 pnv_pci_ioda_setup_PEs();
@@ -2932,6 +3075,9 @@ static void pnv_pci_ioda_fixup(void)
2932 eeh_init(); 3075 eeh_init();
2933 eeh_addr_cache_build(); 3076 eeh_addr_cache_build();
2934#endif 3077#endif
3078
3079 /* Link NPU IODA tables to their PCI devices. */
3080 pnv_npu_ioda_fixup();
2935} 3081}
2936 3082
2937/* 3083/*
@@ -3046,6 +3192,19 @@ static const struct pci_controller_ops pnv_pci_ioda_controller_ops = {
3046 .shutdown = pnv_pci_ioda_shutdown, 3192 .shutdown = pnv_pci_ioda_shutdown,
3047}; 3193};
3048 3194
3195static const struct pci_controller_ops pnv_npu_ioda_controller_ops = {
3196 .dma_dev_setup = pnv_pci_dma_dev_setup,
3197#ifdef CONFIG_PCI_MSI
3198 .setup_msi_irqs = pnv_setup_msi_irqs,
3199 .teardown_msi_irqs = pnv_teardown_msi_irqs,
3200#endif
3201 .enable_device_hook = pnv_pci_enable_device_hook,
3202 .window_alignment = pnv_pci_window_alignment,
3203 .reset_secondary_bus = pnv_pci_reset_secondary_bus,
3204 .dma_set_mask = pnv_npu_dma_set_mask,
3205 .shutdown = pnv_pci_ioda_shutdown,
3206};
3207
3049static void __init pnv_pci_init_ioda_phb(struct device_node *np, 3208static void __init pnv_pci_init_ioda_phb(struct device_node *np,
3050 u64 hub_id, int ioda_type) 3209 u64 hub_id, int ioda_type)
3051{ 3210{
@@ -3101,6 +3260,8 @@ static void __init pnv_pci_init_ioda_phb(struct device_node *np,
3101 phb->model = PNV_PHB_MODEL_P7IOC; 3260 phb->model = PNV_PHB_MODEL_P7IOC;
3102 else if (of_device_is_compatible(np, "ibm,power8-pciex")) 3261 else if (of_device_is_compatible(np, "ibm,power8-pciex"))
3103 phb->model = PNV_PHB_MODEL_PHB3; 3262 phb->model = PNV_PHB_MODEL_PHB3;
3263 else if (of_device_is_compatible(np, "ibm,power8-npu-pciex"))
3264 phb->model = PNV_PHB_MODEL_NPU;
3104 else 3265 else
3105 phb->model = PNV_PHB_MODEL_UNKNOWN; 3266 phb->model = PNV_PHB_MODEL_UNKNOWN;
3106 3267
@@ -3201,7 +3362,11 @@ static void __init pnv_pci_init_ioda_phb(struct device_node *np,
3201 * the child P2P bridges) can form individual PE. 3362 * the child P2P bridges) can form individual PE.
3202 */ 3363 */
3203 ppc_md.pcibios_fixup = pnv_pci_ioda_fixup; 3364 ppc_md.pcibios_fixup = pnv_pci_ioda_fixup;
3204 hose->controller_ops = pnv_pci_ioda_controller_ops; 3365
3366 if (phb->type == PNV_PHB_NPU)
3367 hose->controller_ops = pnv_npu_ioda_controller_ops;
3368 else
3369 hose->controller_ops = pnv_pci_ioda_controller_ops;
3205 3370
3206#ifdef CONFIG_PCI_IOV 3371#ifdef CONFIG_PCI_IOV
3207 ppc_md.pcibios_fixup_sriov = pnv_pci_ioda_fixup_iov_resources; 3372 ppc_md.pcibios_fixup_sriov = pnv_pci_ioda_fixup_iov_resources;
@@ -3236,6 +3401,11 @@ void __init pnv_pci_init_ioda2_phb(struct device_node *np)
3236 pnv_pci_init_ioda_phb(np, 0, PNV_PHB_IODA2); 3401 pnv_pci_init_ioda_phb(np, 0, PNV_PHB_IODA2);
3237} 3402}
3238 3403
3404void __init pnv_pci_init_npu_phb(struct device_node *np)
3405{
3406 pnv_pci_init_ioda_phb(np, 0, PNV_PHB_NPU);
3407}
3408
3239void __init pnv_pci_init_ioda_hub(struct device_node *np) 3409void __init pnv_pci_init_ioda_hub(struct device_node *np)
3240{ 3410{
3241 struct device_node *phbn; 3411 struct device_node *phbn;