MT8188 IOMMU SUPPORT
Subsystems (6)
Yong Wu
maintainerv8 cover MT8188 IOMMU SUPPORT
MT8188 have 3 IOMMU HWs. 2 IOMMU HW is for multimedia, and 1 IOMMU HW is for infra-master, like PCIe.
About the 2 MM IOMMU HW, the connection could be something like this:
IOMMU(VDO) IOMMU(VPP)
| |
SMI_COMMON(VDO) SMI_COMMON(VPP)
--------------- ----------------
| | ... | | ...
larb0 larb2 ... larb1 larb3 ...INFRA IOMMU does not have SMI, the master connects to IOMMU directly.
Although multiple banks supported in MT8188, we only use one of them, which means PCIe is put in bank0 of INFRA IOMMU.
So we have two pgtable for MT8188, specifically, these two MM IOMMU HW share a pgtable while INFRA IOMMU HW use a independent pgtable.
Another change is that we add some SMC command for INFRA master to enable/disable INFRA IOMMU in ATF considering security concerns.
We also adjust the flow of mtk_iommu_config to reduce indention.
change since v8:
- Base on v6.3-rc1 and mtk-iommu-dma-range-v5:
https://lore.kernel.org/linux-mediatek/[email protected]/
- Add a new patch set_dma_mask since mt8188 support the PA of pgtable 35bits.
changes since v7:
- Base on mtk-iommu-dma-range-v4:
https://lore.kernel.org/linux-mediatek/[email protected]/
- Add a new patch for two IOMMU share pagetable issue.
- Add a new patch for adding iova_region_larb_msk for mt8188.
- Add the comment in the dt-binding header file about larb index. This is for readable when updating the iova_region_larb_msk.
Since there is something wrong for chengci's mail account when sending to devicetree mail list, we don't know why. I help send this patchset.
https://lore.kernel.org/linux-mediatek/[email protected]/
changes since v6:
https://lore.kernel.org/linux-mediatek/[email protected]/
- base on tag: next-20221220.
- update commit message of patch[2/4].
changes since v5:
- base on tag: next-20221205.
- add flag PGTABLE_PA_35_EN for all IOMMU in MT8188.
- modify the type of "portid_msk" from "u32" to "unsigned long".
changes since v4:
- base on tag: next-20221018.
- add patch[2/4] to reduce indention by adjust mtk_iommu_config flow.
changes since v3:
- base on tag: next-20220916.
- use license "GPL-2.0-only OR BSD-2-Clause" in bingings head file.
- drop redundant "portid" assignment when configure infra master.
- reduce indentation by using "else if" when config infra master.
- update probe flow about "pericfg" for CFG_IFA_MASTER_IN_ATF.
- drop unused "pericfg_comp_str" in mt8188_data_infra.
- drop words like "This commit/patch".
changes since v2:
- base on tag: next-20220831.
- rename "mt8188-memory-port.h" to "mediatek,mt8188-memory-port.h".
- use dual-license in "mediatek,mt8188-memory-port.h"
- remove unnecessary "()" when define SMI_LARB_ID
changes since v1:
- base on tag: next-20220803.
- adds MT8188 IOMMU support.
Chengci.Xu (5):
dt-bindings: mediatek: mt8188: Add binding for MM & INFRA IOMMU iommu/mediatek: Fix two IOMMU share pagetable issue iommu/mediatek: Adjust mtk_iommu_config flow iommu/mediatek: Add enable IOMMU SMC command for INFRA master iommu/mediatek: Add MT8188 IOMMU Support
Yong Wu (2):
iommu/mediatek: Set dma_mask for PGTABLE_PA_35_EN iommu/mediatek: mt8188: Add iova_region_larb_msk
.../bindings/iommu/mediatek,iommu.yaml | 12 +- drivers/iommu/mtk_iommu.c | 159 ++++-- .../memory/mediatek,mt8188-memory-port.h | 489 ++++++++++++++++++ include/soc/mediatek/smi.h | 1 + 4 files changed, 629 insertions(+), 32 deletions(-) create mode 100644 include/dt-bindings/memory/mediatek,mt8188-memory-port.h
Signature · 1 line
2.18.0
Yong Wu
maintainerPATCH v8 1/7 dt-bindings: mediatek: mt8188: Add binding for MM & INFRA IOMMU
From: "Chengci.Xu" <[email protected]>
Add descriptions for mt8188 IOMMU which also use ARM Short-Descriptor translation table format.
In mt8188, there are two smi-common HW and IOMMU, one is for vdo(video output), the other is for vpp(video processing pipe). They connects with different smi-larbs, then some setting(larbid_remap) is different. Differentiate them with the compatible string.
Something like this:
IOMMU(VDO) IOMMU(VPP)
| | SMI_COMMON_VDO SMI_COMMON_VPP
--------------- ----------------
| | ... | | ... larb0 larb2 ... larb1 larb3 ...
We also have an IOMMU that is for infra master like PCIe. And infra master don't have the larb and ports.
--- .../bindings/iommu/mediatek,iommu.yaml | 12 +- .../memory/mediatek,mt8188-memory-port.h | 489 ++++++++++++++++++ 2 files changed, 500 insertions(+), 1 deletion(-) create mode 100644 include/dt-bindings/memory/mediatek,mt8188-memory-port.h
Documentation/devicetree/bindings/iommu/mediatek,iommu.yaml +11 -1
@@ -78,6 +78,9 @@ properties: - mediatek,mt8173-m4u # generation two - mediatek,mt8183-m4u # generation two - mediatek,mt8186-iommu-mm # generation two + - mediatek,mt8188-iommu-vdo # generation two + - mediatek,mt8188-iommu-vpp # generation two + - mediatek,mt8188-iommu-infra # generation two - mediatek,mt8192-m4u # generation two - mediatek,mt8195-iommu-vdo # generation two - mediatek,mt8195-iommu-vpp # generation two
@@ -123,6 +126,7 @@ properties: description: | This is the mtk_m4u_id according to the HW. Specifies the mtk_m4u_id as defined in + dt-binding/memory/mediatek,mt8188-memory-port.h for mt8188, dt-binding/memory/mt2701-larb-port.h for mt2701 and mt7623, dt-binding/memory/mt2712-larb-port.h for mt2712, dt-binding/memory/mt6779-larb-port.h for mt6779,
@@ -155,6 +159,8 @@ allOf: - mediatek,mt6795-m4u - mediatek,mt8173-m4u - mediatek,mt8186-iommu-mm + - mediatek,mt8188-iommu-vdo + - mediatek,mt8188-iommu-vpp - mediatek,mt8192-m4u - mediatek,mt8195-iommu-vdo - mediatek,mt8195-iommu-vpp
@@ -168,6 +174,8 @@ allOf: compatible: enum: - mediatek,mt8186-iommu-mm + - mediatek,mt8188-iommu-vdo + - mediatek,mt8188-iommu-vpp - mediatek,mt8192-m4u - mediatek,mt8195-iommu-vdo - mediatek,mt8195-iommu-vpp
@@ -194,7 +202,9 @@ allOf: properties: compatible: contains: - const: mediatek,mt8195-iommu-infra + enum: + - mediatek,mt8188-iommu-infra + - mediatek,mt8195-iommu-infra then: required:
include/dt-bindings/memory/mediatek,mt8188-memory-port.h new file +489 -0
489 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v8 1/7] dt-bindings: mediatek: mt8188: Add binding for MM & INFRA IOMMU
Il 07/03/23 09:05, Yong Wu ha scritto:
Quoted 20 lines
From: "Chengci.Xu" <[email protected]>
Add descriptions for mt8188 IOMMU which also use ARM Short-Descriptor translation table format.
In mt8188, there are two smi-common HW and IOMMU, one is for vdo(video output), the other is for vpp(video processing pipe). They connects with different smi-larbs, then some
setting(larbid_remap)is different. Differentiate them with the compatible string.Something like this:
IOMMU(VDO) IOMMU(VPP)
| | SMI_COMMON_VDO SMI_COMMON_VPP--------------- ----------------
| | ... | | ... larb0 larb2 ... larb1 larb3 ...
Quoted 6 lines
We also have an IOMMU that is for infra master like PCIe. And infra master don't have the larb and ports.
Signed-off-by Chengci.Xu <[email protected]>Reviewed-by Yong Wu <[email protected]>
Yong, if you're sending someone else's patch, you have to add your own signoff tag, otherwise it's not going to be accepted.
With that fixed:
Re: [PATCH v8 1/7] dt-bindings: mediatek: mt8188: Add binding for MM & INFRA IOMMU
In reply to Yong WuQuoted 20 lines · Yong Wu
From: "Chengci.Xu" <[email protected]>
Add descriptions for mt8188 IOMMU which also use ARM Short-Descriptor translation table format.
In mt8188, there are two smi-common HW and IOMMU, one is for vdo(video output), the other is for vpp(video processing pipe). They connects with different smi-larbs, then some
setting(larbid_remap)is different. Differentiate them with the compatible string.Something like this:
IOMMU(VDO) IOMMU(VPP)
| | SMI_COMMON_VDO SMI_COMMON_VPP--------------- ----------------
| | ... | | ... larb0 larb2 ... larb1 larb3 ...
Quoted 6 lines
We also have an IOMMU that is for infra master like PCIe. And infra master don't have the larb and ports.
Signed-off-by Chengci.Xu <[email protected]>Reviewed-by Yong Wu <[email protected]>
Indeed, I missed broken checkpatch/DCO chain.
NAK. Please fix the chain.
Best regards,
Krzysztof
Yong Wu (吴勇)
maintainerRe: [PATCH v8 1/7] dt-bindings: mediatek: mt8188: Add binding for MM & INFRA IOMMU
Hi Krzysztof,
Thanks very much for your help review.
Quoted 24 lines · Krzysztof Kozlowski
Quoted 23 lines · Yong Wu
From: "Chengci.Xu" <[email protected]>
Add descriptions for mt8188 IOMMU which also use ARM Short- Descriptor
translation table format.In mt8188, there are two smi-common HW and IOMMU, one is for vdo(video
output), the other is for vpp(video processing pipe). They connects with different smi-larbs, then somesetting(larbid_remap)is different.
Differentiate them with the compatible string.Something like this:
IOMMU(VDO) IOMMU(VPP)
| | SMI_COMMON_VDO SMI_COMMON_VPP--------------- ----------------
| | ... | | ... larb0 larb2 ... larb1 larb3 ...
Quoted 8 lines
Quoted 6 lines
We also have an IOMMU that is for infra master like PCIe. And infra master don't have the larb and ports.
Signed-off-by Chengci.Xu <[email protected]>Reviewed-by Yong Wu <[email protected]>Indeed, I missed broken checkpatch/DCO chain.
Just confirm what this means.
Do you mean MAINTAINERS need to be updated since we add a prefix "mediatek," for the header file?
Quoted 6 lines
NAK. Please fix the chain.
Best regards,
Krzysztof
Re: [PATCH v8 1/7] dt-bindings: mediatek: mt8188: Add binding for MM & INFRA IOMMU
Quoted 36 lines · Yong Wu (吴勇)
Hi Krzysztof,
Thanks very much for your help review.
Quoted 31 lines · Krzysztof Kozlowski
Quoted 29 lines · Yong Wu
From: "Chengci.Xu" <[email protected]>
Add descriptions for mt8188 IOMMU which also use ARM Short- Descriptor
translation table format.In mt8188, there are two smi-common HW and IOMMU, one is for vdo(video
output), the other is for vpp(video processing pipe). They connects with different smi-larbs, then somesetting(larbid_remap)is different.
Differentiate them with the compatible string.Something like this:
IOMMU(VDO) IOMMU(VPP)
| | SMI_COMMON_VDO SMI_COMMON_VPP--------------- ----------------
| | ... | | ... larb0 larb2 ... larb1 larb3 ...We also have an IOMMU that is for infra master like PCIe. And infra master don't have the larb and ports.
Signed-off-by Chengci.Xu <[email protected]>Reviewed-by Yong Wu <[email protected]>
Quoted 6 lines
Quoted 1 line
Indeed, I missed broken checkpatch/DCO chain.
Just confirm what this means.
Do you mean
MAINTAINERSneed to be updated since we add a prefix "mediatek," for the header file?
No it means, run checkpatch.
Best regards,
Krzysztof
Yong Wu (吴勇)
maintainerRe: [PATCH v8 1/7] dt-bindings: mediatek: mt8188: Add binding for MM & INFRA IOMMU
Quoted 38 lines · Krzysztof Kozlowski
Quoted 37 lines · Yong Wu (吴勇)
Hi Krzysztof,
Thanks very much for your help review.
Quoted 32 lines · Krzysztof Kozlowski
Quoted 30 lines · Yong Wu
From: "Chengci.Xu" <[email protected]>
Add descriptions for mt8188 IOMMU which also use ARM Short- Descriptor
translation table format.In mt8188, there are two smi-common HW and IOMMU, one is for vdo(video
output), the other is for vpp(video processing pipe). They connects
with different smi-larbs, then somesetting(larbid_remap)is different.
Differentiate them with the compatible string.Something like this:
IOMMU(VDO) IOMMU(VPP)
| | SMI_COMMON_VDO SMI_COMMON_VPP--------------- ----------------
| | ... | | ... larb0 larb2 ... larb1 larb3 ...We also have an IOMMU that is for infra master like PCIe. And infra master don't have the larb and ports.
Signed-off-by Chengci.Xu <[email protected]>Reviewed-by Yong Wu <[email protected]>
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Indeed, I missed broken checkpatch/DCO chain.
Just confirm what this means.
Do you mean
MAINTAINERSneed to be updated since we add a prefix "mediatek," for the header file?No it means, run checkpatch.
"WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating?"
This is the only warning when I run checkpatch. I will update theMAINTAINERS in next version. Please tell me if I missed other parts.
Thanks.
Quoted 5 lines
Best regards,
Krzysztof
Re: [PATCH v8 1/7] dt-bindings: mediatek: mt8188: Add binding for MM & INFRA IOMMU
Quoted 46 lines · Yong Wu (吴勇)
Quoted 45 lines · Krzysztof Kozlowski
Quoted 43 lines · Yong Wu (吴勇)
Hi Krzysztof,
Thanks very much for your help review.
Quoted 25 lines · Krzysztof Kozlowski
Quoted 24 lines · Yong Wu
From: "Chengci.Xu" <[email protected]>
Add descriptions for mt8188 IOMMU which also use ARM Short- Descriptor
translation table format.In mt8188, there are two smi-common HW and IOMMU, one is for vdo(video
output), the other is for vpp(video processing pipe). They connects
with different smi-larbs, then somesetting(larbid_remap)is different.
Differentiate them with the compatible string.Something like this:
IOMMU(VDO) IOMMU(VPP)
| | SMI_COMMON_VDO SMI_COMMON_VPP--------------- ----------------
| | ... | | ... larb0 larb2 ... larb1 larb3 ...Quoted 8 lines
Quoted 6 lines
We also have an IOMMU that is for infra master like PCIe. And infra master don't have the larb and ports.
Signed-off-by Chengci.Xu <[email protected]>Reviewed-by Yong Wu <[email protected]>Indeed, I missed broken checkpatch/DCO chain.
Just confirm what this means.
Do you mean
MAINTAINERSneed to be updated since we add a prefix "mediatek," for the header file?
Quoted 8 lines
Quoted 1 line
No it means, run checkpatch.
"WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does
MAINTAINERSneed updating?"This is the only warning when I run checkpatch. I will update the
MAINTAINERSin next version. Please tell me if I missed other parts.
Hm, I guess you are right. Your Signed-off-by is missing.
Best regards,
Krzysztof
Yong Wu
maintainerPATCH v8 2/7 iommu/mediatek: Set dma_mask for PGTABLE_PA_35_EN
In reply to Yong WuWhen we enable PGTABLE_PA_35_EN, the PA for pgtable may be 35bits. Thus add dma_mask for it.
--- drivers/iommu/mtk_iommu.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/iommu/mtk_iommu.c +8 -0
@@ -1297,6 +1297,14 @@ static int mtk_iommu_probe(struct platform_device *pdev)return PTR_ERR (data->bclk); } +if (MTK_IOMMU_HAS_FLAG (data->plat_data,PGTABLE_PA_35_EN )) { + ret =dma_set_mask (dev,DMA_BIT_MASK (35 )); +if (!ret) { +dev_err (dev,"Failed to set dma_mask 35.\n" ); +return ret; + } + } +pm_runtime_enable (dev);if (MTK_IOMMU_IS_TYPE (data->plat_data,MTK_IOMMU_TYPE_MM )) {
Signature · 1 line
2.25.1
Re: [PATCH v8 2/7] iommu/mediatek: Set dma_mask for PGTABLE_PA_35_EN
Il 07/03/23 09:05, Yong Wu ha scritto:
Quoted 6 lines
When we enable
PGTABLE_PA_35_EN, the PA for pgtable may be 35bits. Thus adddma_maskfor it.Fixes 301c3ca12576 ("iommu/mediatek: Allow page table PA up to 35bit")Signed-off-by Chengci.Xu <[email protected]>Signed-off-by Yong Wu <[email protected]>
I would send this patch separately from the MT8188 series, as that's purely a (quite important) fix that is not specific to the introduction of MT8188, even though that SoC needs that fix.
Regardless of that,
Yong Wu
maintainerPATCH v8 3/7 iommu/mediatek: Fix two IOMMU share pagetable issue
In reply to Yong WuFrom: "Chengci.Xu" <[email protected]>
Prepare for mt8188 to fix a two IOMMU HWs share pagetable issue.
We have two MM IOMMU HWs in mt8188, one is VPP-IOMMU, another is VDO-IOMMU. The 2 MM IOMMU HWs share pagetable don't work in this case:
a) VPP-IOMMU probe firstly.
b) VDO-IOMMU probe.
c) The master for VDO-IOMMU probe (means frstdata is vpp-iommu).
d) The master in another domain probe. No matter it is vdo or vpp.
Then it still create a new pagetable in step d). The problem is "frstdata->bank[0]->m4u_dom" was not initialized. Then when d) enter, it still create a new one.
In this patch, we create a new variable "share_dom" for this share pgtable case, it should be helpful for readable. and put all the share pgtable logic in the mtk_iommu_domain_finalise.
In mt8195, the master of VPP-IOMMU probes before than VDO-IOMMU from its dtsi node sequence, we don't see this issue in it. Prepare for mt8188.
--- drivers/iommu/mtk_iommu.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)
drivers/iommu/mtk_iommu.c +14 -8
@@ -258,6 +258,8 @@ struct mtk_iommu_data {struct device *smicomm_dev;struct mtk_iommu_bank_data *bank; +struct mtk_iommu_domain *share_dom;/* For 2 HWs share pgtable */ +struct regmap *pericfg;struct mutex mutex;/* Protect m4u_group/m4u_dom above */
@@ -624,15 +626,14 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom,struct mtk_iommu_data *data, unsigned int region_id) { + struct mtk_iommu_domain *share_dom = data->share_dom;const struct mtk_iommu_iova_region *region; -struct mtk_iommu_domain *m4u_dom; - -/* Always use bank0 in sharing pgtable case */ - m4u_dom = data->bank[0 ].m4u_dom; -if (m4u_dom) { - dom->iop = m4u_dom->iop; - dom->cfg = m4u_dom->cfg; - dom->domain.pgsize_bitmap = m4u_dom->cfg.pgsize_bitmap; + +/* Always use share domain in sharing pgtable case */ +if (MTK_IOMMU_HAS_FLAG (data->plat_data,SHARE_PGTABLE ) && share_dom) { + dom->iop = share_dom->iop; + dom->cfg = share_dom->cfg; + dom->domain.pgsize_bitmap = share_dom->cfg.pgsize_bitmap; goto update_iova_region; }
@@ -662,6 +663,9 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom,/* Update our support page sizes bitmap */ dom->domain.pgsize_bitmap = dom->cfg.pgsize_bitmap; +if (MTK_IOMMU_HAS_FLAG (data->plat_data,SHARE_PGTABLE )) + data->share_dom = dom; + update_iova_region:/* Update the iova region for this domain */ region = data->plat_data->iova_region + region_id;
@@ -712,7 +716,9 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain,/* Data is in the frstdata in sharing pgtable case. */ frstdata =mtk_iommu_get_frst_data (hw_list); +mutex_lock (&frstdata->mutex); ret =mtk_iommu_domain_finalise (dom, frstdata, region_id); +mutex_unlock (&frstdata->mutex);if (ret) {mutex_unlock (&dom->mutex);return ret;
Signature · 1 line
2.25.1
Yong Wu
maintainerPATCH v8 4/7 iommu/mediatek: Adjust mtk_iommu_config flow
In reply to Yong WuFrom: "Chengci.Xu" <[email protected]>
For reduce indention without functional change, prepare for MT8188. If there are many ports in a same larb, current flow will update larb_mmu->mmu or update INFRA register for too many times. So we save all ports to portid_msk in the front of mtk_iommu_config(), and then update only once for IOMMU configure. By this modification, we can prevent MT8188 from sending to many SMC calls, avoiding enter ATF for each port.
--- drivers/iommu/mtk_iommu.c | 58 +++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 26 deletions(-)
drivers/iommu/mtk_iommu.c +32 -26
@@ -583,41 +583,47 @@ static int mtk_iommu_config(struct mtk_iommu_data *data, struct device *dev,unsigned int larbid, portid;struct iommu_fwspec *fwspec =dev_iommu_fwspec_get (dev);const struct mtk_iommu_iova_region *region; -u32 peri_mmuen, peri_mmuen_msk; +unsigned long portid_msk =0 ;int i, ret =0 ;for (i =0 ; i < fwspec->num_ids; ++i) { - larbid =MTK_M4U_TO_LARB (fwspec->ids[i]); portid =MTK_M4U_TO_PORT (fwspec->ids[i]); + portid_msk |=BIT (portid); + } -if (MTK_IOMMU_IS_TYPE (data->plat_data,MTK_IOMMU_TYPE_MM )) { - larb_mmu = &data->larb_imu[larbid]; +if (MTK_IOMMU_IS_TYPE (data->plat_data,MTK_IOMMU_TYPE_MM )) { +/* All ports should be in the same larb. just use 0 here */ + larbid =MTK_M4U_TO_LARB (fwspec->ids[0 ]); + larb_mmu = &data->larb_imu[larbid]; + region = data->plat_data->iova_region + regionid; - region = data->plat_data->iova_region + regionid; +for_each_set_bit (portid, &portid_msk,32 ) larb_mmu->bank[portid] =upper_32_bits (region->iova_base); -dev_dbg (dev,"%s iommu for larb(%s) port %d region %d rgn-bank %d.\n" , - enable ?"enable" :"disable" ,dev_name (larb_mmu->dev), - portid, regionid, larb_mmu->bank[portid]); - -if (enable) - larb_mmu->mmu |=MTK_SMI_MMU_EN (portid); -else - larb_mmu->mmu &= ~MTK_SMI_MMU_EN (portid); - }else if (MTK_IOMMU_IS_TYPE (data->plat_data,MTK_IOMMU_TYPE_INFRA )) { - peri_mmuen_msk =BIT (portid); -/* PCI dev has only one output id, enable the next writing bit for PCIe */ -if (dev_is_pci (dev)) - peri_mmuen_msk |=BIT (portid +1 ); - - peri_mmuen = enable ? peri_mmuen_msk :0 ; - ret =regmap_update_bits (data->pericfg,PERICFG_IOMMU_1 , - peri_mmuen_msk, peri_mmuen); -if (ret) -dev_err (dev,"%s iommu(%s) inframaster 0x%x fail(%d).\n" , - enable ?"enable" :"disable" , -dev_name (data->dev), peri_mmuen_msk, ret); +dev_dbg (dev,"%s iommu for larb(%s) port 0x%lx region %d rgn-bank %d.\n" , + enable ?"enable" :"disable" ,dev_name (larb_mmu->dev), + portid_msk, regionid,upper_32_bits (region->iova_base)); + +if (enable) + larb_mmu->mmu |= portid_msk; +else + larb_mmu->mmu &= ~portid_msk; + }else if (MTK_IOMMU_IS_TYPE (data->plat_data,MTK_IOMMU_TYPE_INFRA )) { +/* PCI dev has only one output id, enable the next writing bit for PCIe */ +if (dev_is_pci (dev)) { +if (fwspec->num_ids !=1 ) { +dev_err (dev,"PCI dev can only have one port.\n" ); +return -ENODEV ; + } + portid_msk |=BIT (portid +1 ); } + + ret =regmap_update_bits (data->pericfg,PERICFG_IOMMU_1 , + (u32 )portid_msk, enable ? (u32 )portid_msk :0 ); +if (ret) +dev_err (dev,"%s iommu(%s) inframaster 0x%lx fail(%d).\n" , + enable ?"enable" :"disable" , +dev_name (data->dev), portid_msk, ret); }return ret; }
Signature · 1 line
2.25.1
Yong Wu
maintainerPATCH v8 5/7 iommu/mediatek: Add enable IOMMU SMC command for INFRA master
In reply to Yong WuFrom: "Chengci.Xu" <[email protected]>
The register which can enable IOMMU for INFRA master should be setted in secure world for security concerns. Therefore, we add a SMC command for INFRA master to enable/disable INFRA IOMMU in ATF. This function is prepared for MT8188.
--- drivers/iommu/mtk_iommu.c | 32 ++++++++++++++++++++++---------- include/soc/mediatek/smi.h | 1 + 2 files changed, 23 insertions(+), 10 deletions(-)
drivers/iommu/mtk_iommu.c +22 -10
@@ -3,6 +3,7 @@* Copyright (c) 2015-2016 MediaTek Inc. * Author: Yong Wu <[email protected]> */ +#include <linux/arm-smccc.h> #include <linux/bitfield.h> #include <linux/bug.h> #include <linux/clk.h>
@@ -27,6 +28,7 @@#include <linux/slab.h> #include <linux/spinlock.h> #include <linux/soc/mediatek/infracfg.h> +#include <linux/soc/mediatek/mtk_sip_svc.h> #include <asm/barrier.h> #include <soc/mediatek/smi.h>
@@ -143,6 +145,7 @@#define PGTABLE_PA_35_EN BIT(17)#define TF_PORT_TO_ADDR_MT8173 BIT(18)#define INT_ID_PORT_WIDTH_6 BIT(19) +#define CFG_IFA_MASTER_IN_ATF BIT(20)#define MTK_IOMMU_HAS_FLAG_MASK (pdata, _x, mask) \ ((((pdata)->flags) & (mask)) == (_x))
@@ -584,6 +587,7 @@ static int mtk_iommu_config(struct mtk_iommu_data *data, struct device *dev,struct iommu_fwspec *fwspec =dev_iommu_fwspec_get (dev);const struct mtk_iommu_iova_region *region;unsigned long portid_msk =0 ; +struct arm_smccc_res res;int i, ret =0 ;for (i =0 ; i < fwspec->num_ids; ++i) {
@@ -609,17 +613,24 @@ static int mtk_iommu_config(struct mtk_iommu_data *data, struct device *dev,else larb_mmu->mmu &= ~portid_msk; }else if (MTK_IOMMU_IS_TYPE (data->plat_data,MTK_IOMMU_TYPE_INFRA )) { -/* PCI dev has only one output id, enable the next writing bit for PCIe */ -if (dev_is_pci (dev)) { -if (fwspec->num_ids !=1 ) { -dev_err (dev,"PCI dev can only have one port.\n" ); -return -ENODEV ; +if (MTK_IOMMU_HAS_FLAG (data->plat_data,CFG_IFA_MASTER_IN_ATF )) { +arm_smccc_smc (MTK_SIP_KERNEL_IOMMU_CONTROL , +IOMMU_ATF_CMD_CONFIG_INFRA_IOMMU , + portid_msk, enable,0 ,0 ,0 ,0 , &res); + ret = res.a0; + }else { +/* PCI dev has only one output id, enable the next writing bit for PCIe */ +if (dev_is_pci (dev)) { +if (fwspec->num_ids !=1 ) { +dev_err (dev,"PCI dev can only have one port.\n" ); +return -ENODEV ; + } + portid_msk |=BIT (portid +1 ); } - portid_msk |=BIT (portid +1 ); - } - ret =regmap_update_bits (data->pericfg,PERICFG_IOMMU_1 , - (u32 )portid_msk, enable ? (u32 )portid_msk :0 ); + ret =regmap_update_bits (data->pericfg,PERICFG_IOMMU_1 , + (u32 )portid_msk, enable ? (u32 )portid_msk :0 ); + }if (ret) dev_err(dev, "%s iommu(%s) inframaster 0x%lx fail(%d).\n", enable ? "enable" : "disable",
@@ -1325,7 +1336,8 @@ static int mtk_iommu_probe(struct platform_device *pdev)dev_err_probe (dev, ret,"mm dts parse fail\n" ); goto out_runtime_disable; } - }else if (MTK_IOMMU_IS_TYPE (data->plat_data,MTK_IOMMU_TYPE_INFRA )) { + }else if (MTK_IOMMU_IS_TYPE (data->plat_data,MTK_IOMMU_TYPE_INFRA ) && + !MTK_IOMMU_HAS_FLAG (data->plat_data,CFG_IFA_MASTER_IN_ATF )) { p = data->plat_data->pericfg_comp_str; data->pericfg =syscon_regmap_lookup_by_compatible (p);if (IS_ERR (data->pericfg)) {
include/soc/mediatek/smi.h +1 -0
@@ -13,6 +13,7 @@enum iommu_atf_cmd {IOMMU_ATF_CMD_CONFIG_SMI_LARB ,/* For mm master to en/disable iommu */ +IOMMU_ATF_CMD_CONFIG_INFRA_IOMMU ,/* For infra master to enable iommu */ IOMMU_ATF_CMD_MAX , };
Signature · 1 line
2.25.1
Yong Wu
maintainerPATCH v8 6/7 iommu/mediatek: Add MT8188 IOMMU Support
In reply to Yong WuFrom: "Chengci.Xu" <[email protected]>
MT8188 has 3 IOMMU, containing 2 MM IOMMUs, one is for vdo, the other is for vpp. and 1 INFRA IOMMU.
--- drivers/iommu/mtk_iommu.c | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)
drivers/iommu/mtk_iommu.c +49 -0
@@ -170,6 +170,7 @@ enum mtk_iommu_plat {M4U_MT8173 ,M4U_MT8183 ,M4U_MT8186 , +M4U_MT8188 ,M4U_MT8192 ,M4U_MT8195 , M4U_MT8365,
@@ -1590,6 +1591,51 @@ static const struct mtk_iommu_plat_data mt8186_data_mm = { .iova_region_larb_msk = mt8186_larb_region_msk, }; +static const struct mtk_iommu_plat_data mt8188_data_infra = { + .m4u_plat =M4U_MT8188 , + .flags =WR_THROT_EN |DCM_DISABLE |STD_AXI_MODE |PM_CLK_AO | +MTK_IOMMU_TYPE_INFRA |IFA_IOMMU_PCIE_SUPPORT | +PGTABLE_PA_35_EN |CFG_IFA_MASTER_IN_ATF , + .inv_sel_reg =REG_MMU_INV_SEL_GEN2 , + .banks_num =1 , + .banks_enable = {true}, + .iova_region = single_domain, + .iova_region_nr =ARRAY_SIZE (single_domain), +}; + +static const struct mtk_iommu_plat_data mt8188_data_vdo = { + .m4u_plat =M4U_MT8188 , + .flags =HAS_BCLK |HAS_SUB_COMM_3BITS |OUT_ORDER_WR_EN | +WR_THROT_EN |IOVA_34_EN |SHARE_PGTABLE | +PGTABLE_PA_35_EN |MTK_IOMMU_TYPE_MM , + .hw_list = &m4ulist, + .inv_sel_reg =REG_MMU_INV_SEL_GEN2 , + .banks_num =1 , + .banks_enable = {true}, + .iova_region = mt8192_multi_dom, + .iova_region_nr =ARRAY_SIZE (mt8192_multi_dom), + .larbid_remap = {{2 }, {0 }, {21 }, {0 }, {19 }, {9 ,10 , +11 /* 11a */ ,25 /* 11c */ }, + {13 ,0 ,29 /* 16b */ ,30 /* 17b */ ,0 }, {5 }}, +}; + +static const struct mtk_iommu_plat_data mt8188_data_vpp = { + .m4u_plat =M4U_MT8188 , + .flags =HAS_BCLK |HAS_SUB_COMM_3BITS |OUT_ORDER_WR_EN | +WR_THROT_EN |IOVA_34_EN |SHARE_PGTABLE | +PGTABLE_PA_35_EN |MTK_IOMMU_TYPE_MM , + .hw_list = &m4ulist, + .inv_sel_reg =REG_MMU_INV_SEL_GEN2 , + .banks_num =1 , + .banks_enable = {true}, + .iova_region = mt8192_multi_dom, + .iova_region_nr =ARRAY_SIZE (mt8192_multi_dom), + .larbid_remap = {{1 }, {3 }, {23 }, {7 }, {MTK_INVALID_LARBID }, + {12 ,15 ,24 /* 11b */ }, {14 ,MTK_INVALID_LARBID , +16 /* 16a */ ,17 /* 17a */ ,MTK_INVALID_LARBID , +27 ,28 /* ccu0 */ ,MTK_INVALID_LARBID }, {4 ,6 }}, +}; +static const unsigned int mt8192_larb_region_msk[MT8192_MULTI_REGION_NR_MAX ][MTK_LARB_NR_MAX ] = { [0 ] = {~0 , ~0 },/* Region0: larb0/1 */ [1 ] = {0 ,0 ,0 ,0 , ~0 , ~0 ,0 , ~0 },/* Region1: larb4/5/7 */
@@ -1698,6 +1744,9 @@ static const struct of_device_id mtk_iommu_of_ids[] = { { .compatible = "mediatek,mt8173-m4u", .data = &mt8173_data}, { .compatible = "mediatek,mt8183-m4u", .data = &mt8183_data}, { .compatible = "mediatek,mt8186-iommu-mm", .data = &mt8186_data_mm}, /* mm: m4u */ + { .compatible = "mediatek,mt8188-iommu-infra", .data = &mt8188_data_infra}, + { .compatible = "mediatek,mt8188-iommu-vdo", .data = &mt8188_data_vdo}, + { .compatible = "mediatek,mt8188-iommu-vpp", .data = &mt8188_data_vpp}, { .compatible = "mediatek,mt8192-m4u", .data = &mt8192_data}, { .compatible = "mediatek,mt8195-iommu-infra", .data = &mt8195_data_infra}, { .compatible = "mediatek,mt8195-iommu-vdo", .data = &mt8195_data_vdo},
Signature · 1 line
2.25.1
Yong Wu
maintainerPATCH v8 7/7 iommu/mediatek: mt8188: Add iova_region_larb_msk
In reply to Yong WuAdd iova_region_larb_msk for mt8188. We separate the 16GB iova regions by each device's larbid/portid.
Refer to include/dt-bindings/memory/mediatek,mt8188-memory-port.h
Note: larb19(21) as commented in that h above, it means larb19 while its SW index is 21.
--- drivers/iommu/mtk_iommu.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/iommu/mtk_iommu.c +16 -0
@@ -1603,6 +1603,20 @@ static const struct mtk_iommu_plat_data mt8188_data_infra = { .iova_region_nr = ARRAY_SIZE(single_domain), }; +static const u32 mt8188_larb_region_msk[MT8192_MULTI_REGION_NR_MAX ][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(21)/21(22)/23 */ + [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 }, + [3 ] = {0 }, + [4 ] = {[24 ] =BIT (0 ) |BIT (1 )},/* Only larb27(24) port0/1 */ + [5 ] = {[24 ] =BIT (2 ) |BIT (3 )},/* Only larb27(24) port2/3 */ +}; +static const struct mtk_iommu_plat_data mt8188_data_vdo = { .m4u_plat =M4U_MT8188 , .flags = HAS_BCLK | HAS_SUB_COMM_3BITS | OUT_ORDER_WR_EN |
@@ -1614,6 +1628,7 @@ static const struct mtk_iommu_plat_data mt8188_data_vdo = { .banks_enable = {true}, .iova_region = mt8192_multi_dom, .iova_region_nr = ARRAY_SIZE(mt8192_multi_dom), + .iova_region_larb_msk = mt8188_larb_region_msk, .larbid_remap = {{2}, {0}, {21}, {0}, {19}, {9, 10, 11 /* 11a */, 25 /* 11c */}, {13, 0, 29 /* 16b */, 30 /* 17b */, 0}, {5}},
@@ -1630,6 +1645,7 @@ static const struct mtk_iommu_plat_data mt8188_data_vpp = { .banks_enable = {true}, .iova_region = mt8192_multi_dom, .iova_region_nr = ARRAY_SIZE(mt8192_multi_dom), + .iova_region_larb_msk = mt8188_larb_region_msk, .larbid_remap = {{1}, {3}, {23}, {7}, {MTK_INVALID_LARBID}, {12, 15, 24 /* 11b */}, {14, MTK_INVALID_LARBID, 16 /* 16a */, 17 /* 17a */, MTK_INVALID_LARBID,
Signature · 1 line
2.25.1
Re: [PATCH v8 7/7] iommu/mediatek: mt8188: Add iova_region_larb_msk
Il 07/03/23 09:05, Yong Wu ha scritto:
Quoted 8 lines
Add
iova_region_larb_mskfor mt8188. We separate the 16GB iova regions by each device's larbid/portid.
Refer toinclude/dt-bindings/memory/mediatek,mt8188-memory-port.hNote: larb19(21) as commented in that h above, it means larb19 while its SW index is 21.
Signed-off-by Yong Wu <[email protected]>
Please clarify the commit description:
"larb19(21) as commented in that h above" => "As commented in the code, larb19(21) means .."
After which: