[PATCH] iommu/amd: delay dma init right before dma_ops areinitialized - backport

From: Shuah Khan
Date: Fri Dec 21 2012 - 18:28:03 EST



Signed-off-by: Shuah Khan <shuahkhan@xxxxxxxxx>
---
drivers/iommu/amd_iommu_init.c | 45 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 44 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
index 18a89b7..33a9a6e 100644
--- a/drivers/iommu/amd_iommu_init.c
+++ b/drivers/iommu/amd_iommu_init.c
@@ -1308,7 +1308,7 @@ static int __init init_memory_definitions(struct acpi_table_header *table)
* Init the device table to not allow DMA access for devices and
* suppress all page faults
*/
-static void init_device_table(void)
+static void init_device_table_dma(void)
{
u32 devid;

@@ -1318,6 +1318,32 @@ static void init_device_table(void)
}
}

+/*
+Dont' need - probably
+static void __init uninit_device_table_dma(void)
+{
+ u32 devid;
+
+ 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;
+ }
+}
+*/
+
+static void init_device_table(void)
+{
+/*
+Dont' need - probably
+
+ u32 devid;
+
+ for (devid = 0; devid <= amd_iommu_last_bdf; ++devid)
+ set_dev_entry_bit(devid, DEV_ENTRY_IRQ_TBL_EN);
+*/
+ return;
+}
+
static void iommu_init_flags(struct amd_iommu *iommu)
{
iommu->acpi_flags & IVHD_FLAG_HT_TUN_EN_MASK ?
@@ -1494,6 +1520,16 @@ static void __init free_on_init_error(void)
#endif
}

+static void __init free_dma_resources(void)
+{
+ amd_iommu_uninit_devices();
+
+ free_pages((unsigned long)amd_iommu_pd_alloc_bitmap,
+ get_order(MAX_DOMAIN_ID/8));
+
+ free_unity_maps();
+}
+
/*
* This is the hardware init function for AMD IOMMU in the system.
* This function is called either from amd_iommu_init or from the interrupt
@@ -1657,8 +1693,14 @@ static bool detect_ivrs(void)

static int amd_iommu_init_dma(void)
{
+ struct amd_iommu *iommu;
int ret;

+ init_device_table_dma();
+
+ for_each_iommu(iommu)
+ iommu_flush_all_caches(iommu);
+
if (iommu_pass_through)
ret = amd_iommu_init_passthrough();
else
@@ -1762,6 +1804,7 @@ static int __init amd_iommu_init(void)

ret = iommu_go_to_state(IOMMU_INITIALIZED);
if (ret) {
+ free_dma_resources();
disable_iommus();
free_on_init_error();
}
--
1.7.9.5


--=-9Y90mSEDPkKGf20NaSCm
Content-Disposition: attachment; filename="iommu-moving-initialization-earlier.patch"
Content-Type: text/x-patch; name="iommu-moving-initialization-earlier.patch";
charset="UTF-8"
Content-Transfer-Encoding: 7bit

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index ddbdaca..1065a1a 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -861,7 +861,7 @@ static int __init iommu_init(void)

return 0;
}
-subsys_initcall(iommu_init);
+arch_initcall(iommu_init);

int iommu_domain_get_attr(struct iommu_domain *domain,
enum iommu_attr attr, void *data)

--=-9Y90mSEDPkKGf20NaSCm--

--
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/