From: Suravee Suthikulpanit <suravee.suthikulpa...@amd.com>

Include struct amd_iommu_pci_seg as a function parameter since
we need to access per PCI segment device table.

Co-developed-by: Vasant Hegde <vasant.he...@amd.com>
Signed-off-by: Vasant Hegde <vasant.he...@amd.com>
Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpa...@amd.com>
---
 drivers/iommu/amd/init.c | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
index 70eb6338b45d..dba1e03e0cd2 100644
--- a/drivers/iommu/amd/init.c
+++ b/drivers/iommu/amd/init.c
@@ -238,7 +238,7 @@ static enum iommu_init_state init_state = IOMMU_START_STATE;
 
 static int amd_iommu_enable_interrupts(void);
 static int __init iommu_go_to_state(enum iommu_init_state state);
-static void init_device_table_dma(void);
+static void init_device_table_dma(struct amd_iommu_pci_seg *pci_seg);
 
 static bool amd_iommu_pre_enabled = true;
 
@@ -2115,6 +2115,7 @@ static void print_iommu_info(void)
 static int __init amd_iommu_init_pci(void)
 {
        struct amd_iommu *iommu;
+       struct amd_iommu_pci_seg *pci_seg;
        int ret;
 
        for_each_iommu(iommu) {
@@ -2145,7 +2146,8 @@ static int __init amd_iommu_init_pci(void)
                goto out;
        }
 
-       init_device_table_dma();
+       for_each_pci_segment(pci_seg)
+               init_device_table_dma(pci_seg);
 
        for_each_iommu(iommu)
                iommu_flush_all_caches(iommu);
@@ -2508,9 +2510,13 @@ static int __init init_memory_definitions(struct 
acpi_table_header *table)
 /*
  * Init the device table to not allow DMA access for devices
  */
-static void init_device_table_dma(void)
+static void init_device_table_dma(struct amd_iommu_pci_seg *pci_seg)
 {
        u32 devid;
+       struct dev_table_entry *dev_table = pci_seg->dev_table;
+
+       if (dev_table == NULL)
+               return;
 
        for (devid = 0; devid <= amd_iommu_last_bdf; ++devid) {
                set_dev_entry_bit(devid, DEV_ENTRY_VALID);
@@ -2518,13 +2524,17 @@ static void init_device_table_dma(void)
        }
 }
 
-static void __init uninit_device_table_dma(void)
+static void __init uninit_device_table_dma(struct amd_iommu_pci_seg *pci_seg)
 {
        u32 devid;
+       struct dev_table_entry *dev_table = pci_seg->dev_table;
+
+       if (dev_table == NULL)
+               return;
 
        for (devid = 0; devid <= amd_iommu_last_bdf; ++devid) {
-               amd_iommu_dev_table[devid].data[0] = 0ULL;
-               amd_iommu_dev_table[devid].data[1] = 0ULL;
+               dev_table[devid].data[0] = 0ULL;
+               dev_table[devid].data[1] = 0ULL;
        }
 }
 
@@ -3117,8 +3127,11 @@ static int __init state_next(void)
                        free_iommu_resources();
                } else {
                        struct amd_iommu *iommu;
+                       struct amd_iommu_pci_seg *pci_seg;
+
+                       for_each_pci_segment(pci_seg)
+                               uninit_device_table_dma(pci_seg);
 
-                       uninit_device_table_dma();
                        for_each_iommu(iommu)
                                iommu_flush_all_caches(iommu);
                }
-- 
2.27.0

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Reply via email to