@@ -1533,6 +1533,9 @@ void pnv_pci_sriov_disable(struct pci_dev *pdev)
1533
1533
1534
1534
static void pnv_pci_ioda2_setup_dma_pe (struct pnv_phb * phb ,
1535
1535
struct pnv_ioda_pe * pe );
1536
+ #ifdef CONFIG_IOMMU_API
1537
+ static void pnv_ioda_setup_bus_iommu_group (struct pnv_ioda_pe * pe );
1538
+ #endif
1536
1539
static void pnv_ioda_setup_vf_PE (struct pci_dev * pdev , u16 num_vfs )
1537
1540
{
1538
1541
struct pci_bus * bus ;
@@ -1586,6 +1589,9 @@ static void pnv_ioda_setup_vf_PE(struct pci_dev *pdev, u16 num_vfs)
1586
1589
mutex_unlock (& phb -> ioda .pe_list_mutex );
1587
1590
1588
1591
pnv_pci_ioda2_setup_dma_pe (phb , pe );
1592
+ #ifdef CONFIG_IOMMU_API
1593
+ pnv_ioda_setup_bus_iommu_group (pe );
1594
+ #endif
1589
1595
}
1590
1596
}
1591
1597
@@ -1925,21 +1931,16 @@ static u64 pnv_pci_ioda_dma_get_required_mask(struct pci_dev *pdev)
1925
1931
return mask ;
1926
1932
}
1927
1933
1928
- static void pnv_ioda_setup_bus_dma (struct pnv_ioda_pe * pe ,
1929
- struct pci_bus * bus ,
1930
- bool add_to_group )
1934
+ static void pnv_ioda_setup_bus_dma (struct pnv_ioda_pe * pe , struct pci_bus * bus )
1931
1935
{
1932
1936
struct pci_dev * dev ;
1933
1937
1934
1938
list_for_each_entry (dev , & bus -> devices , bus_list ) {
1935
1939
set_iommu_table_base (& dev -> dev , pe -> table_group .tables [0 ]);
1936
1940
set_dma_offset (& dev -> dev , pe -> tce_bypass_base );
1937
- if (add_to_group )
1938
- iommu_add_device (& pe -> table_group , & dev -> dev );
1939
1941
1940
1942
if ((pe -> flags & PNV_IODA_PE_BUS_ALL ) && dev -> subordinate )
1941
- pnv_ioda_setup_bus_dma (pe , dev -> subordinate ,
1942
- add_to_group );
1943
+ pnv_ioda_setup_bus_dma (pe , dev -> subordinate );
1943
1944
}
1944
1945
}
1945
1946
@@ -2369,7 +2370,7 @@ static void pnv_pci_ioda1_setup_dma_pe(struct pnv_phb *phb,
2369
2370
iommu_init_table (tbl , phb -> hose -> node );
2370
2371
2371
2372
if (pe -> flags & (PNV_IODA_PE_BUS | PNV_IODA_PE_BUS_ALL ))
2372
- pnv_ioda_setup_bus_dma (pe , pe -> pbus , true );
2373
+ pnv_ioda_setup_bus_dma (pe , pe -> pbus );
2373
2374
2374
2375
return ;
2375
2376
fail :
@@ -2602,7 +2603,7 @@ static void pnv_ioda2_take_ownership(struct iommu_table_group *table_group)
2602
2603
pnv_pci_ioda2_set_bypass (pe , false);
2603
2604
pnv_pci_ioda2_unset_window (& pe -> table_group , 0 );
2604
2605
if (pe -> pbus )
2605
- pnv_ioda_setup_bus_dma (pe , pe -> pbus , false );
2606
+ pnv_ioda_setup_bus_dma (pe , pe -> pbus );
2606
2607
iommu_tce_table_put (tbl );
2607
2608
}
2608
2609
@@ -2613,7 +2614,7 @@ static void pnv_ioda2_release_ownership(struct iommu_table_group *table_group)
2613
2614
2614
2615
pnv_pci_ioda2_setup_default_config (pe );
2615
2616
if (pe -> pbus )
2616
- pnv_ioda_setup_bus_dma (pe , pe -> pbus , false );
2617
+ pnv_ioda_setup_bus_dma (pe , pe -> pbus );
2617
2618
}
2618
2619
2619
2620
static struct iommu_table_group_ops pnv_pci_ioda2_ops = {
@@ -2730,12 +2731,68 @@ static struct iommu_table_group_ops pnv_pci_ioda2_npu_ops = {
2730
2731
.release_ownership = pnv_ioda2_release_ownership ,
2731
2732
};
2732
2733
2734
+ static void pnv_ioda_setup_bus_iommu_group_add_devices (struct pnv_ioda_pe * pe ,
2735
+ struct pci_bus * bus )
2736
+ {
2737
+ struct pci_dev * dev ;
2738
+
2739
+ list_for_each_entry (dev , & bus -> devices , bus_list ) {
2740
+ iommu_add_device (& pe -> table_group , & dev -> dev );
2741
+
2742
+ if ((pe -> flags & PNV_IODA_PE_BUS_ALL ) && dev -> subordinate )
2743
+ pnv_ioda_setup_bus_iommu_group_add_devices (pe ,
2744
+ dev -> subordinate );
2745
+ }
2746
+ }
2747
+
2748
+ static void pnv_ioda_setup_bus_iommu_group (struct pnv_ioda_pe * pe )
2749
+ {
2750
+ if (!pnv_pci_ioda_pe_dma_weight (pe ))
2751
+ return ;
2752
+
2753
+ iommu_register_group (& pe -> table_group , pe -> phb -> hose -> global_number ,
2754
+ pe -> pe_number );
2755
+
2756
+ /*
2757
+ * set_iommu_table_base(&pe->pdev->dev, tbl) should have been called
2758
+ * by now
2759
+ */
2760
+ if (pe -> flags & PNV_IODA_PE_DEV )
2761
+ iommu_add_device (& pe -> table_group , & pe -> pdev -> dev );
2762
+ else if (pe -> flags & (PNV_IODA_PE_BUS | PNV_IODA_PE_BUS_ALL ))
2763
+ pnv_ioda_setup_bus_iommu_group_add_devices (pe , pe -> pbus );
2764
+ }
2765
+
2733
2766
static void pnv_pci_ioda_setup_iommu_api (void )
2734
2767
{
2735
2768
struct pci_controller * hose , * tmp ;
2736
2769
struct pnv_phb * phb ;
2737
2770
struct pnv_ioda_pe * pe , * gpe ;
2738
2771
2772
+ /*
2773
+ * There are 4 types of PEs:
2774
+ * - PNV_IODA_PE_BUS: a downstream port with an adapter,
2775
+ * created from pnv_pci_setup_bridge();
2776
+ * - PNV_IODA_PE_BUS_ALL: a PCI-PCIX bridge with devices behind it,
2777
+ * created from pnv_pci_setup_bridge();
2778
+ * - PNV_IODA_PE_VF: a SRIOV virtual function,
2779
+ * created from pnv_pcibios_sriov_enable();
2780
+ * - PNV_IODA_PE_DEV: an NPU or OCAPI device,
2781
+ * created from pnv_pci_ioda_fixup().
2782
+ *
2783
+ * Normally a PE is represented by an IOMMU group, however for
2784
+ * devices with side channels the groups need to be more strict.
2785
+ */
2786
+ list_for_each_entry (hose , & hose_list , list_node ) {
2787
+ phb = hose -> private_data ;
2788
+
2789
+ if (phb -> type == PNV_PHB_NPU_NVLINK )
2790
+ continue ;
2791
+
2792
+ list_for_each_entry (pe , & phb -> ioda .pe_list , list )
2793
+ pnv_ioda_setup_bus_iommu_group (pe );
2794
+ }
2795
+
2739
2796
/*
2740
2797
* Now we have all PHBs discovered, time to add NPU devices to
2741
2798
* the corresponding IOMMU groups.
@@ -2796,9 +2853,6 @@ static void pnv_pci_ioda2_setup_dma_pe(struct pnv_phb *phb,
2796
2853
/* TVE #1 is selected by PCI address bit 59 */
2797
2854
pe -> tce_bypass_base = 1ull << 59 ;
2798
2855
2799
- iommu_register_group (& pe -> table_group , phb -> hose -> global_number ,
2800
- pe -> pe_number );
2801
-
2802
2856
/* The PE will reserve all possible 32-bits space */
2803
2857
pe_info (pe , "Setting up 32-bit TCE table at 0..%08x\n" ,
2804
2858
phb -> ioda .m32_pci_base );
@@ -2819,7 +2873,7 @@ static void pnv_pci_ioda2_setup_dma_pe(struct pnv_phb *phb,
2819
2873
return ;
2820
2874
2821
2875
if (pe -> flags & (PNV_IODA_PE_BUS | PNV_IODA_PE_BUS_ALL ))
2822
- pnv_ioda_setup_bus_dma (pe , pe -> pbus , true );
2876
+ pnv_ioda_setup_bus_dma (pe , pe -> pbus );
2823
2877
}
2824
2878
2825
2879
int64_t pnv_opal_pci_msi_eoi (struct irq_chip * chip , unsigned int hw_irq )
0 commit comments