[PATCH 05/10] iommu/amd: Add function copy_dev_tables

From: Baoquan He
Date: Thu Sep 24 2015 - 02:40:11 EST


Signed-off-by: Baoquan He <bhe@xxxxxxxxxx>
---
drivers/iommu/amd_iommu_init.c | 26 ++++++++++++++++++++++++++
drivers/iommu/amd_iommu_types.h | 2 ++
2 files changed, 28 insertions(+)

diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
index 1fc369e..913a718 100644
--- a/drivers/iommu/amd_iommu_init.c
+++ b/drivers/iommu/amd_iommu_init.c
@@ -690,6 +690,32 @@ static void iommu_enable_gt(struct amd_iommu *iommu)
iommu_feature_enable(iommu, CONTROL_GT_EN);
}

+static void copy_dev_tables(void)
+{
+ u64 entry;
+ u32 lo, hi;
+ phys_addr_t old_devtb_phys;
+ struct dev_table_entry *old_devtb;
+ struct amd_iommu *iommu;
+ u16 dom_id;
+ u32 devid;
+
+ for_each_iommu(iommu) {
+ lo = readl(iommu->mmio_base + MMIO_DEV_TABLE_OFFSET);
+ hi = readl(iommu->mmio_base + MMIO_DEV_TABLE_OFFSET + 4);
+ entry = (((u64) hi) << 32) + lo;
+ old_devtb_phys = entry & PAGE_MASK;
+ old_devtb = ioremap_cache(old_devtb_phys, dev_table_size);
+ for (devid = 0; devid <= amd_iommu_last_bdf; ++devid) {
+ amd_iommu_dev_table[devid] = old_devtb[devid];
+ dom_id = amd_iommu_dev_table[devid].data[1] & DEV_DOMID_MASK;
+ __set_bit(dom_id, amd_iommu_pd_alloc_bitmap);
+ }
+ iounmap(old_devtb);
+ }
+
+}
+
/* sets a specific bit in the device table entry. */
static void set_dev_entry_bit(u16 devid, u8 bit)
{
diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h
index f659088..d0f0cfb 100644
--- a/drivers/iommu/amd_iommu_types.h
+++ b/drivers/iommu/amd_iommu_types.h
@@ -194,6 +194,8 @@
#define DEV_ENTRY_MODE_MASK 0x07
#define DEV_ENTRY_MODE_SHIFT 0x09

+#define DEV_DOMID_MASK 0xffff
+
#define MAX_DEV_TABLE_ENTRIES 0xffff

/* constants to configure the command buffer */
--
2.4.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/