iommu: msm: Refactor code to separate compilation
Modify the code and update makefile and defconfig to allow us to
only compile one of the two IOMMU drivers that we have. Only one of
the drivers are needed at the same time. This will ensure we are not
compiling and linking code that is not needed.
Change-Id: I7db69f873245e57bddab6625e0b04e2ed48f44b6
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
diff --git a/drivers/iommu/msm_iommu_dev-v0.c b/drivers/iommu/msm_iommu_dev-v0.c
index 4ee65d8..2d0fba2 100644
--- a/drivers/iommu/msm_iommu_dev-v0.c
+++ b/drivers/iommu/msm_iommu_dev-v0.c
@@ -32,64 +32,8 @@
#include <mach/iommu.h>
#include <mach/msm_bus.h>
-static DEFINE_MUTEX(iommu_list_lock);
-static LIST_HEAD(iommu_list);
-
static struct of_device_id msm_iommu_v0_ctx_match_table[];
-
-void msm_iommu_add_drv(struct msm_iommu_drvdata *drv)
-{
- mutex_lock(&iommu_list_lock);
- list_add(&drv->list, &iommu_list);
- mutex_unlock(&iommu_list_lock);
-}
-
-void msm_iommu_remove_drv(struct msm_iommu_drvdata *drv)
-{
- mutex_lock(&iommu_list_lock);
- list_del(&drv->list);
- mutex_unlock(&iommu_list_lock);
-}
-
-static int find_iommu_ctx(struct device *dev, void *data)
-{
- struct msm_iommu_ctx_drvdata *c;
-
- c = dev_get_drvdata(dev);
- if (!c || !c->name)
- return 0;
-
- return !strcmp(data, c->name);
-}
-
-static struct device *find_context(struct device *dev, const char *name)
-{
- return device_find_child(dev, (void *)name, find_iommu_ctx);
-}
-
-struct device *msm_iommu_get_ctx(const char *ctx_name)
-{
- struct msm_iommu_drvdata *drv;
- struct device *dev = NULL;
-
- mutex_lock(&iommu_list_lock);
- list_for_each_entry(drv, &iommu_list, list) {
- dev = find_context(drv->dev, ctx_name);
- if (dev)
- break;
- }
- mutex_unlock(&iommu_list_lock);
-
- put_device(dev);
-
- if (!dev || !dev_get_drvdata(dev)) {
- pr_debug("Could not find context <%s>\n", ctx_name);
- dev = ERR_PTR(-EPROBE_DEFER);
- }
-
- return dev;
-}
-EXPORT_SYMBOL(msm_iommu_get_ctx);
+static struct iommu_access_ops *msm_iommu_access_ops;
static void msm_iommu_reset(void __iomem *base, void __iomem *glb_base, int ncb)
{
@@ -454,7 +398,7 @@
drvdata->dev = &pdev->dev;
- iommu_access_ops_v0.iommu_clk_on(drvdata);
+ msm_iommu_access_ops->iommu_clk_on(drvdata);
msm_iommu_reset(drvdata->base, drvdata->glb_base, drvdata->ncb);
@@ -462,7 +406,7 @@
if (ret)
goto fail_clk;
- iommu_access_ops_v0.iommu_clk_off(drvdata);
+ msm_iommu_access_ops->iommu_clk_off(drvdata);
pr_info("device %s mapped at %p, with %d ctx banks\n",
drvdata->name, drvdata->base, drvdata->ncb);
@@ -478,7 +422,7 @@
pr_info("%s: pmon not available.\n", drvdata->name);
} else {
pmon_info->iommu.base = drvdata->base;
- pmon_info->iommu.ops = &iommu_access_ops_v0;
+ pmon_info->iommu.ops = msm_iommu_access_ops;
pmon_info->iommu.hw_ops = iommu_pm_get_hw_ops_v0();
pmon_info->iommu.iommu_name = drvdata->name;
pmon_info->iommu.always_on = 1;
@@ -497,7 +441,7 @@
return 0;
fail_clk:
- iommu_access_ops_v0.iommu_clk_off(drvdata);
+ msm_iommu_access_ops->iommu_clk_off(drvdata);
fail:
__put_bus_vote_client(drvdata);
fail_mem:
@@ -697,9 +641,9 @@
goto fail;
}
- iommu_access_ops_v0.iommu_clk_on(drvdata);
+ msm_iommu_access_ops->iommu_clk_on(drvdata);
__program_m2v_tables(drvdata, ctx_drvdata);
- iommu_access_ops_v0.iommu_clk_off(drvdata);
+ msm_iommu_access_ops->iommu_clk_off(drvdata);
dev_info(&pdev->dev, "context %s using bank %d\n", ctx_drvdata->name,
ctx_drvdata->num);
@@ -746,6 +690,11 @@
static int __init msm_iommu_driver_init(void)
{
int ret;
+
+ if (msm_soc_version_supports_iommu_v0()) {
+ msm_set_iommu_access_ops(&iommu_access_ops_v0);
+ msm_iommu_access_ops = msm_get_iommu_access_ops();
+ }
ret = platform_driver_register(&msm_iommu_driver);
if (ret != 0) {
pr_err("Failed to register IOMMU driver\n");