[PATCH v3 05/11] iommu/mediatek: mt8195: Add iova_region_larb_msk

Yong Wu posted 11 patches 1 year, 9 months ago
There is a newer version of this series
[PATCH v3 05/11] iommu/mediatek: mt8195: Add iova_region_larb_msk
Posted by Yong Wu 1 year, 9 months ago
Add iova_region_larb_msk for mt8195. We separate the 16GB iova regions
by each device's larbid/portid.
Refer to include/dt-bindings/memory/mt8195-memory-port.h

Define a new macro MT8192_MULTI_REGION_MAX_NR to indicate
the index of mt8xxx_larb_region_msk and
"struct mtk_iommu_iova_region mt8192_multi_dom"
are the same.

Signed-off-by: Yong Wu <yong.wu@mediatek.com>
---
 drivers/iommu/mtk_iommu.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
index 7e2cb3b8cac8..3d9986fb49a5 100644
--- a/drivers/iommu/mtk_iommu.c
+++ b/drivers/iommu/mtk_iommu.c
@@ -332,7 +332,12 @@ static const struct mtk_iommu_iova_region single_domain[] = {
 	{.iova_base = 0,		.size = SZ_4G},
 };
 
-static const struct mtk_iommu_iova_region mt8192_multi_dom[] = {
+#define MT8192_MULTI_REGION_MAX_NR	6
+
+#define MT8192_MULTI_REGION_NR	(IS_ENABLED(CONFIG_ARCH_DMA_ADDR_T_64BIT) ? \
+				 MT8192_MULTI_REGION_MAX_NR : 1)
+
+static const struct mtk_iommu_iova_region mt8192_multi_dom[MT8192_MULTI_REGION_NR] = {
 	{ .iova_base = 0x0,		.size = SZ_4G},		/* 0 ~ 4G */
 	#if IS_ENABLED(CONFIG_ARCH_DMA_ADDR_T_64BIT)
 	{ .iova_base = SZ_4G,		.size = SZ_4G},		/* 4G ~ 8G */
@@ -1562,6 +1567,21 @@ static const struct mtk_iommu_plat_data mt8195_data_infra = {
 	.iova_region_nr   = ARRAY_SIZE(single_domain),
 };
 
+static const unsigned int mt8195_larb_region_msk[MT8192_MULTI_REGION_MAX_NR][MTK_LARB_NR_MAX] = {
+	[0] = {~0, ~0, ~0, ~0},               /* Region0: all ports for larb0/1/2/3 */
+	[1] = {0, 0, 0, 0, 0, 0, 0, 0,
+	       0, 0, 0, 0, 0, 0, 0, 0,
+	       0, 0, 0, ~0, ~0, ~0, ~0, ~0,   /* Region1: larb19/20/21/22/23/24 */
+	       ~0},
+	[2] = {0, 0, 0, 0, ~0, ~0, ~0, ~0,    /* Region2: the other larbs. */
+	       ~0, ~0, ~0, ~0, ~0, ~0, ~0, ~0,
+	       ~0, ~0, 0, 0, 0, 0, 0, 0,
+	       0, ~0, ~0, ~0, ~0},
+	[3] = {0},
+	[4] = {[18] = BIT(0) | BIT(1)},       /* Only larb18 port0/1 */
+	[5] = {[18] = BIT(2) | BIT(3)},       /* Only larb18 port2/3 */
+};
+
 static const struct mtk_iommu_plat_data mt8195_data_vdo = {
 	.m4u_plat	= M4U_MT8195,
 	.flags          = HAS_BCLK | HAS_SUB_COMM_2BITS | OUT_ORDER_WR_EN |
@@ -1572,6 +1592,7 @@ static const struct mtk_iommu_plat_data mt8195_data_vdo = {
 	.banks_enable   = {true},
 	.iova_region	= mt8192_multi_dom,
 	.iova_region_nr	= ARRAY_SIZE(mt8192_multi_dom),
+	.iova_region_larb_msk = mt8195_larb_region_msk,
 	.larbid_remap   = {{2, 0}, {21}, {24}, {7}, {19}, {9, 10, 11},
 			   {13, 17, 15/* 17b */, 25}, {5}},
 };
@@ -1586,6 +1607,7 @@ static const struct mtk_iommu_plat_data mt8195_data_vpp = {
 	.banks_enable   = {true},
 	.iova_region	= mt8192_multi_dom,
 	.iova_region_nr	= ARRAY_SIZE(mt8192_multi_dom),
+	.iova_region_larb_msk = mt8195_larb_region_msk,
 	.larbid_remap   = {{1}, {3},
 			   {22, MTK_INVALID_LARBID, MTK_INVALID_LARBID, MTK_INVALID_LARBID, 23},
 			   {8}, {20}, {12},
-- 
2.18.0
Re: [PATCH v3 05/11] iommu/mediatek: mt8195: Add iova_region_larb_msk
Posted by AngeloGioacchino Del Regno 1 year, 9 months ago
Il 14/02/23 04:11, Yong Wu ha scritto:
> Add iova_region_larb_msk for mt8195. We separate the 16GB iova regions
> by each device's larbid/portid.
> Refer to include/dt-bindings/memory/mt8195-memory-port.h
> 
> Define a new macro MT8192_MULTI_REGION_MAX_NR to indicate
> the index of mt8xxx_larb_region_msk and
> "struct mtk_iommu_iova_region mt8192_multi_dom"
> are the same.
> 
> Signed-off-by: Yong Wu <yong.wu@mediatek.com>

Sorry but... you *are* introducing a iova_region_larb_msk for MT8192 later,
while you're introducing definitions containing the `MT8192` name in a commit
that introduces the same but for MT8195.

I strongly suggest to, at this point, introduce MT8192 region mask here, along
with the MT8192 definitions, and MT8195 after that :-)


Regards,
Angelo
Re: [PATCH v3 05/11] iommu/mediatek: mt8195: Add iova_region_larb_msk
Posted by Yong Wu (吴勇) 1 year, 9 months ago
On Tue, 2023-02-14 at 10:36 +0100, AngeloGioacchino Del Regno wrote:
> Il 14/02/23 04:11, Yong Wu ha scritto:
> > Add iova_region_larb_msk for mt8195. We separate the 16GB iova
> > regions
> > by each device's larbid/portid.
> > Refer to include/dt-bindings/memory/mt8195-memory-port.h
> > 
> > Define a new macro MT8192_MULTI_REGION_MAX_NR to indicate
> > the index of mt8xxx_larb_region_msk and
> > "struct mtk_iommu_iova_region mt8192_multi_dom"
> > are the same.
> > 
> > Signed-off-by: Yong Wu <yong.wu@mediatek.com>
> 
> Sorry but... you *are* introducing a iova_region_larb_msk for MT8192
> later,
> while you're introducing definitions containing the `MT8192` name in
> a commit
> that introduces the same but for MT8195.
> 
> I strongly suggest to, at this point, introduce MT8192 region mask
> here, along
> with the MT8192 definitions, and MT8195 after that :-)

Make sense.
Thanks very much. Will fix it.

> 
> 
> Regards,
> Angelo
> 
>