[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250616025628.25454-4-xueqi.zhang@mediatek.com>
Date: Mon, 16 Jun 2025 10:56:09 +0800
From: Xueqi Zhang <xueqi.zhang@...iatek.com>
To: Yong Wu <yong.wu@...iatek.com>, Will Deacon <will@...nel.org>, "Robin
Murphy" <robin.murphy@....com>, Joerg Roedel <joro@...tes.org>, Rob Herring
<robh@...nel.org>, Krzysztof Kozlowski <krzk+dt@...nel.org>, Conor Dooley
<conor+dt@...nel.org>, Matthias Brugger <matthias.bgg@...il.com>,
AngeloGioacchino Del Regno <angelogioacchino.delregno@...labora.com>
CC: <Project_Global_Chrome_Upstream_Group@...iatek.com>, Ning li
<ning.li@...iatek.com>, <linux-mediatek@...ts.infradead.org>,
<linux-kernel@...r.kernel.org>, <linux-arm-kernel@...ts.infradead.org>,
<devicetree@...r.kernel.org>, <iommu@...ts.linux.dev>, Xueqi Zhang
<xueqi.zhang@...iatek.com>
Subject: [RFC PATCH 3/8] iommu/arm-smmu-v3: Add implementation for MT8196 MM SMMU
Add implementation for mediatek MM SMMU.
Signed-off-by: Xueqi Zhang <xueqi.zhang@...iatek.com>
---
.../arm/arm-smmu-v3/arm-smmu-v3-mediatek.c | 72 ++++++++++++++++++-
1 file changed, 71 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-mediatek.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-mediatek.c
index 381268968185..c00ee687d839 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-mediatek.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-mediatek.c
@@ -4,10 +4,80 @@
* Author: Ning li <ning.li@...iatek.com>
* Author: Xueqi Zhang <xueqi.zhang@...iatek.com>
*/
+#include <linux/bitops.h>
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_platform.h>
#include "arm-smmu-v3.h"
-struct arm_smmu_device *arm_smmu_v3_impl_mtk_init(struct arm_smmu_device *smmu)
+#define MTK_SMMU_COMP_STR_LEN 64
+#define MTK_SMMU_HAS_FLAG(pdata, _x) (!!(((pdata)->flags) & (_x)))
+
+enum mtk_smmu_type {
+ MTK_SMMU_MM,
+ MTK_SMMU_TYPE_NUM,
+};
+
+struct mtk_smmu_v3_plat {
+ enum mtk_smmu_type smmu_type;
+ u32 flags;
+};
+
+struct mtk_smmu_v3 {
+ struct arm_smmu_device smmu;
+ const struct mtk_smmu_v3_plat *plat_data;
+};
+
+static const struct mtk_smmu_v3_plat mt8196_data_mm = {
+ .smmu_type = MTK_SMMU_MM,
+};
+
+struct mtk_smmu_v3_of_device_data {
+ char compatible[MTK_SMMU_COMP_STR_LEN];
+ const void *data;
+};
+
+static const struct mtk_smmu_v3_of_device_data mtk_smmu_v3_of_ids[] = {
+ { .compatible = "mediatek,mt8196-mm-smmu", .data = &mt8196_data_mm},
+};
+
+static inline struct mtk_smmu_v3 *to_mtk_smmu_v3(struct arm_smmu_device *smmu)
{
+ return container_of(smmu, struct mtk_smmu_v3, smmu);
+}
+
+static const struct mtk_smmu_v3_plat *mtk_smmu_v3_get_plat_data(const struct device_node *np)
+{
+ const struct mtk_smmu_v3_of_device_data *of_device = mtk_smmu_v3_of_ids;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(mtk_smmu_v3_of_ids); i++, of_device++) {
+ if (of_device_is_compatible(np, of_device->compatible))
+ return of_device->data;
+ }
return NULL;
}
+
+struct arm_smmu_device *arm_smmu_v3_impl_mtk_init(struct arm_smmu_device *smmu)
+{
+ struct mtk_smmu_v3 *mtk_smmu_v3;
+ struct device *dev = smmu->dev;
+ struct platform_device *parent_pdev;
+ struct device_node *parent_node;
+
+ mtk_smmu_v3 = devm_krealloc(dev, smmu, sizeof(*mtk_smmu_v3), GFP_KERNEL);
+ if (!mtk_smmu_v3)
+ return ERR_PTR(-ENOMEM);
+
+ mtk_smmu_v3->plat_data = mtk_smmu_v3_get_plat_data(dev->of_node);
+ if (!mtk_smmu_v3->plat_data) {
+ dev_err(dev, "Get platform data fail\n");
+ return ERR_PTR(-EINVAL);
+ }
+
+ return &mtk_smmu_v3->smmu;
+}
--
2.46.0
Powered by blists - more mailing lists