Skip to content

Commit 6b71779

Browse files
Chao Haojoergroedel
authored andcommitted
iommu/mediatek: Use a u32 flags to describe different HW features
Given the fact that we are adding more and more plat_data bool values, it would make sense to use a u32 flags register and add the appropriate macro definitions to set and check for a flag present. No functional change. Suggested-by: Matthias Brugger <[email protected]> Signed-off-by: Chao Hao <[email protected]> Reviewed-by: Matthias Brugger <[email protected]> Cc: Yong Wu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 75eed35 commit 6b71779

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

drivers/iommu/mtk_iommu.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@
100100
#define MTK_M4U_TO_LARB(id) (((id) >> 5) & 0xf)
101101
#define MTK_M4U_TO_PORT(id) ((id) & 0x1f)
102102

103+
#define HAS_4GB_MODE BIT(0)
104+
/* HW will use the EMI clock if there isn't the "bclk". */
105+
#define HAS_BCLK BIT(1)
106+
#define HAS_VLD_PA_RNG BIT(2)
107+
#define RESET_AXI BIT(3)
108+
109+
#define MTK_IOMMU_HAS_FLAG(pdata, _x) \
110+
((((pdata)->flags) & (_x)) == (_x))
111+
103112
struct mtk_iommu_domain {
104113
struct io_pgtable_cfg cfg;
105114
struct io_pgtable_ops *iop;
@@ -563,7 +572,8 @@ static int mtk_iommu_hw_init(const struct mtk_iommu_data *data)
563572
upper_32_bits(data->protect_base);
564573
writel_relaxed(regval, data->base + REG_MMU_IVRP_PADDR);
565574

566-
if (data->enable_4GB && data->plat_data->has_vld_pa_rng) {
575+
if (data->enable_4GB &&
576+
MTK_IOMMU_HAS_FLAG(data->plat_data, HAS_VLD_PA_RNG)) {
567577
/*
568578
* If 4GB mode is enabled, the validate PA range is from
569579
* 0x1_0000_0000 to 0x1_ffff_ffff. here record bit[32:30].
@@ -573,7 +583,7 @@ static int mtk_iommu_hw_init(const struct mtk_iommu_data *data)
573583
}
574584
writel_relaxed(0, data->base + REG_MMU_DCM_DIS);
575585

576-
if (data->plat_data->reset_axi) {
586+
if (MTK_IOMMU_HAS_FLAG(data->plat_data, RESET_AXI)) {
577587
/* The register is called STANDARD_AXI_MODE in this case */
578588
writel_relaxed(0, data->base + REG_MMU_MISC_CTRL);
579589
}
@@ -618,7 +628,7 @@ static int mtk_iommu_probe(struct platform_device *pdev)
618628

619629
/* Whether the current dram is over 4GB */
620630
data->enable_4GB = !!(max_pfn > (BIT_ULL(32) >> PAGE_SHIFT));
621-
if (!data->plat_data->has_4gb_mode)
631+
if (!MTK_IOMMU_HAS_FLAG(data->plat_data, HAS_4GB_MODE))
622632
data->enable_4GB = false;
623633

624634
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -631,7 +641,7 @@ static int mtk_iommu_probe(struct platform_device *pdev)
631641
if (data->irq < 0)
632642
return data->irq;
633643

634-
if (data->plat_data->has_bclk) {
644+
if (MTK_IOMMU_HAS_FLAG(data->plat_data, HAS_BCLK)) {
635645
data->bclk = devm_clk_get(dev, "bclk");
636646
if (IS_ERR(data->bclk))
637647
return PTR_ERR(data->bclk);
@@ -763,23 +773,19 @@ static const struct dev_pm_ops mtk_iommu_pm_ops = {
763773

764774
static const struct mtk_iommu_plat_data mt2712_data = {
765775
.m4u_plat = M4U_MT2712,
766-
.has_4gb_mode = true,
767-
.has_bclk = true,
768-
.has_vld_pa_rng = true,
776+
.flags = HAS_4GB_MODE | HAS_BCLK | HAS_VLD_PA_RNG,
769777
.larbid_remap = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
770778
};
771779

772780
static const struct mtk_iommu_plat_data mt8173_data = {
773781
.m4u_plat = M4U_MT8173,
774-
.has_4gb_mode = true,
775-
.has_bclk = true,
776-
.reset_axi = true,
782+
.flags = HAS_4GB_MODE | HAS_BCLK | RESET_AXI,
777783
.larbid_remap = {0, 1, 2, 3, 4, 5}, /* Linear mapping. */
778784
};
779785

780786
static const struct mtk_iommu_plat_data mt8183_data = {
781787
.m4u_plat = M4U_MT8183,
782-
.reset_axi = true,
788+
.flags = RESET_AXI,
783789
.larbid_remap = {0, 4, 5, 6, 7, 2, 3, 1},
784790
};
785791

drivers/iommu/mtk_iommu.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ enum mtk_iommu_plat {
3939

4040
struct mtk_iommu_plat_data {
4141
enum mtk_iommu_plat m4u_plat;
42-
bool has_4gb_mode;
43-
44-
/* HW will use the EMI clock if there isn't the "bclk". */
45-
bool has_bclk;
46-
bool has_vld_pa_rng;
47-
bool reset_axi;
42+
u32 flags;
4843
unsigned char larbid_remap[MTK_LARB_NR_MAX];
4944
};
5045

0 commit comments

Comments
 (0)