MT6779 IOMMU SUPPORT
Subsystems (5)
cover MT6779 IOMMU SUPPORT
I am sorry that previous patchset(2019/10/28) has a problem with e-mail format, some websites don't recevied it, so please based on this patchset to review, thanks!
This patchset adds mt6779 iommu support and adjusts mtk iommu software architecture mainly.
1. Add mt6779 basic function, such as smi_larb port define, registers define and so on.
2. In addition, this patchset will adjust current mtk iommu SW architecture mainly to adapt all the mtk platforms:
Firstly, mt6779 iommu can support more HW modules, but some modules have special requirements for iova region, for example, CCU only can access 0x4000_0000~0x47ff_ffff, VPU only can access 0x7da0_0000~0x7fbf_ffff. Current architecture only support one iommu domain(include 0~4GB), all the modules allocate iova from 0~4GB region, so it doesn't ensure to allocate expected iova region for special module(CCU and VPU). In order to resolve the problem, we will create different iommu domains for special module, and every domain can include iova region which module needs.
Secondly, all the iommus share one page table for current architecture by "mtk_iommu_get_m4u_data", to make the architecture look clearly, we will create a global page table firstly(mtk_iommu_pgtable), and all the iommus can use it. One page table can include 4GB iova space, so multiple iommu domains are created based on the same page table. New SW architecture diagram is as below:
iommu0 iommu1
| |
----------
|
mtk_iommu_pgtable
|
------------------------------------------
| | |
mtk_iommu_domain1 mtk_iommu_domain2 mtk_iommu_domain3
| | |
iommu_group1 iommu_group2 iommu_group3
| | |
iommu_domain1 iommu_domain2 iommu_domain3
| | |
iova region1(normal) iova region2(CCU) iova region3(VPU)
This patchset depends on "Improve tlb range flush"[1] and based on v5.4-rc1. [1]http://lists.infradead.org/pipermail/linux-mediatek/2019-October/024207.html
Chao Hao (13):
dt-bindings: mediatek: Add bindings for MT6779 iommu/mediatek: Add mt6779 IOMMU basic support iommu/mediatek: Add mtk_iommu_pgtable structure iommu/mediatek: Remove mtk_iommu_domain_finalise iommu/mediatek: Remove pgtable info in mtk_iommu_domain iommu/mediatek: Change get the way of m4u_group iommu/mediatek: Add smi_larb info about device iommu/mediatek: Add mtk_domain_data structure iommu/mediatek: Remove the usage of m4u_dom variable iommu/mediatek: Remove mtk_iommu_get_m4u_data api iommu/mediatek: Add iova reserved function iommu/mediatek: Change single domain to multiple domains iommu/mediatek: Add multiple mtk_iommu_domain support for mt6779
.../bindings/iommu/mediatek,iommu.txt | 2 + drivers/iommu/mtk_iommu.c | 488 +++++++++++++++--- drivers/iommu/mtk_iommu.h | 50 +- include/dt-bindings/memory/mt6779-larb-port.h | 217 ++++++++ 4 files changed, 685 insertions(+), 72 deletions(-)
--
2.18.0
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH RESEND 1/13 dt-bindings: mediatek: Add bindings for MT6779
This patch adds description for MT6779 IOMMU.
MT6779 has two iommus, they are MM_IOMMU and APU_IOMMU which use ARM Short-Descriptor translation format.
The MT6779 IOMMU hardware diagram is as below, it is only a brief diagram about iommu, it don't focus on the part of smi_larb, so I don't describe the smi_larb detailedly.
EMI
|
--------------------------------------
| |
MM_IOMMU APU_IOMMU
| |
SMI_COMMOM----------- APU_BUS
| | |
SMI_LARB(0~11) SMI_LARB12(FAKE) SMI_LARB13(FAKE)
| | |
| | --------------
| | | | |Multimedia engine CCU VPU MDLA EMDA
All the connections are hardware fixed, software can not adjust it.
From the diagram above, MM_IOMMU provides mapping for multimedia engine, but CCU is connected with smi_common directly, we can take them as larb12. APU_IOMMU provides mapping for APU engine, we can take them larb13. Larb12 and Larb13 are fake larbs.
--- .../bindings/iommu/mediatek,iommu.txt | 2 + include/dt-bindings/memory/mt6779-larb-port.h | 217 ++++++++++++++++++ 2 files changed, 219 insertions(+) create mode 100644 include/dt-bindings/memory/mt6779-larb-port.h
Documentation/devicetree/bindings/iommu/mediatek,iommu.txt +2 -0
@@ -58,6 +58,7 @@ Required properties: - compatible : must be one of the following string: "mediatek,mt2701-m4u" for mt2701 which uses generation one m4u HW. "mediatek,mt2712-m4u" for mt2712 which uses generation two m4u HW. + "mediatek,mt6779-m4u" for mt6779 which uses generation two m4u HW. "mediatek,mt7623-m4u", "mediatek,mt2701-m4u" for mt7623 which uses generation one m4u HW. "mediatek,mt8173-m4u" for mt8173 which uses generation two m4u HW.
@@ -78,6 +79,7 @@ Required properties: Specifies the mtk_m4u_id as defined in dt-binding/memory/mt2701-larb-port.h for mt2701, mt7623 dt-binding/memory/mt2712-larb-port.h for mt2712, + dt-binding/memory/mt6779-larb-port.h for mt6779, dt-binding/memory/mt8173-larb-port.h for mt8173, and dt-binding/memory/mt8183-larb-port.h for mt8183.
include/dt-bindings/memory/mt6779-larb-port.h new file +217 -0
217 lines not on this page · raw message
Signature · 6 lines
2.18.0 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [RESEND,PATCH 01/13] dt-bindings: mediatek: Add bindings for MT6779
Quoted 30 lines · Chao Hao
This patch adds description for MT6779 IOMMU.
MT6779 has two iommus, they are
MM_IOMMUandAPU_IOMMUwhich use ARM Short-Descriptor translation format.The MT6779 IOMMU hardware diagram is as below, it is only a brief diagram about iommu, it don't focus on the part of
smi_larb, so I don't describe thesmi_larbdetailedly.EMI | -------------------------------------- | | MM_IOMMU APU_IOMMU | | SMI_COMMOM----------- APU_BUS | | | SMI_LARB(0~11) SMI_LARB12(FAKE) SMI_LARB13(FAKE) | | | | | -------------- | | | | |Multimedia engine CCU VPU MDLA EMDA
All the connections are hardware fixed, software can not adjust it.
Quoted 1 line
From the diagram above,
MM_IOMMUprovides mapping for multimedia engine,but CCU is connected with
smi_commondirectly, we can take them as larb12.APU_IOMMUprovides mapping for APU engine, we can take them larb13. Larb12 and Larb13 are fake larbs.
Quoted 7 lines
Signed-off-by Chao Hao <[email protected]>--- .../bindings/iommu/mediatek,iommu.txt | 2 + include/dt-bindings/memory/mt6779-larb-port.h | 217 ++++++++++++++++++ 2 files changed, 219 insertions(+) create mode 100644 include/dt-bindings/memory/mt6779-larb-port.h
Yong Wu
maintainerRe: [RESEND,PATCH 01/13] dt-bindings: mediatek: Add bindings for MT6779
In reply to Chao HaoQuoted 121 lines · Chao Hao
This patch adds description for MT6779 IOMMU.
MT6779 has two iommus, they are
MM_IOMMUandAPU_IOMMUwhich use ARM Short-Descriptor translation format.The MT6779 IOMMU hardware diagram is as below, it is only a brief diagram about iommu, it don't focus on the part of
smi_larb, so I don't describe thesmi_larbdetailedly.EMI | -------------------------------------- | | MM_IOMMU APU_IOMMU | | SMI_COMMOM----------- APU_BUS | | | SMI_LARB(0~11) SMI_LARB12(FAKE) SMI_LARB13(FAKE) | | | | | -------------- | | | | |Multimedia engine CCU VPU MDLA EMDA
All the connections are hardware fixed, software can not adjust it.
From the diagram above,
MM_IOMMUprovides mapping for multimedia engine, but CCU is connected withsmi_commondirectly, we can take them as larb12.APU_IOMMUprovides mapping for APU engine, we can take them larb13. Larb12 and Larb13 are fake larbs.Signed-off-by Chao Hao <[email protected]>--- .../bindings/iommu/mediatek,iommu.txt | 2 + include/dt-bindings/memory/mt6779-larb-port.h | 217 ++++++++++++++++++ 2 files changed, 219 insertions(+) create mode 100644 include/dt-bindings/memory/mt6779-larb-port.hDocumentation/devicetree/bindings/iommu/mediatek,iommu.txt +2
-0@@ -58,6 +58,7 @@ Required properties: - compatible : must be one of the following string: "mediatek,mt2701-m4u" for mt2701 which uses generation one m4u HW. "mediatek,mt2712-m4u" for mt2712 which uses generation two m4u HW. + "mediatek,mt6779-m4u" for mt6779 which uses generation two m4u HW. "mediatek,mt7623-m4u", "mediatek,mt2701-m4u" for mt7623 which uses generation one m4u HW. "mediatek,mt8173-m4u" for mt8173 which uses generation two m4u HW.@@ -78,6 +79,7 @@ Required properties: Specifies the mtk_m4u_id as defined in dt-binding/memory/mt2701-larb-port.h for mt2701, mt7623 dt-binding/memory/mt2712-larb-port.h for mt2712, + dt-binding/memory/mt6779-larb-port.h for mt6779, dt-binding/memory/mt8173-larb-port.h for mt8173, and dt-binding/memory/mt8183-larb-port.h for mt8183.include/dt-bindings/memory/mt6779-larb-port.h new file +58
-0@@ -0,0 +1,217 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2019 MediaTek Inc. +* Author: Chao Hao <[email protected]> +*/ + +#ifndef _DTS_IOMMU_PORT_MT6779_H_ +#define _DTS_IOMMU_PORT_MT6779_H_ + +#define MTK_M4U_ID (larb, port) (((larb) << 5) | (port)) + +#define M4U_LARB0_ID 0 +#define M4U_LARB1_ID 1 +#define M4U_LARB2_ID 2 +#define M4U_LARB3_ID 3 +#define M4U_LARB4_ID 4 +#define M4U_LARB5_ID 5 +#define M4U_LARB6_ID 6 +#define M4U_LARB7_ID 7 +#define M4U_LARB8_ID 8 +#define M4U_LARB9_ID 9 +#define M4U_LARB10_ID 10 +#define M4U_LARB11_ID 11 +#define M4U_LARB12_ID 12 +#define M4U_LARB13_ID 13 + +/* larb0 */ +#define M4U_PORT_DISP_POSTMASK0 MTK_M4U_ID(M4U_LARB0_ID, 0) +#define M4U_PORT_DISP_OVL0_HDR MTK_M4U_ID(M4U_LARB0_ID, 1) +#define M4U_PORT_DISP_OVL1_HDR MTK_M4U_ID(M4U_LARB0_ID, 2) +#define M4U_PORT_DISP_OVL0 MTK_M4U_ID(M4U_LARB0_ID, 3) +#define M4U_PORT_DISP_OVL1 MTK_M4U_ID(M4U_LARB0_ID, 4) +#define M4U_PORT_DISP_PVRIC0 MTK_M4U_ID(M4U_LARB0_ID, 5) +#define M4U_PORT_DISP_RDMA0 MTK_M4U_ID(M4U_LARB0_ID, 6) +#define M4U_PORT_DISP_WDMA0 MTK_M4U_ID(M4U_LARB0_ID, 7) +#define M4U_PORT_DISP_FAKE0 MTK_M4U_ID(M4U_LARB0_ID, 8) + +/* larb1 */ +#define M4U_PORT_DISP_OVL0_2L_HDR MTK_M4U_ID(M4U_LARB1_ID, 0) +#define M4U_PORT_DISP_OVL1_2L_HDR MTK_M4U_ID(M4U_LARB1_ID, 1) +#define M4U_PORT_DISP_OVL0_2L MTK_M4U_ID(M4U_LARB1_ID, 2) +#define M4U_PORT_DISP_OVL1_2L MTK_M4U_ID(M4U_LARB1_ID, 3) +#define M4U_PORT_DISP_RDMA1 MTK_M4U_ID(M4U_LARB1_ID, 4) +#define M4U_PORT_MDP_PVRIC0 MTK_M4U_ID(M4U_LARB1_ID, 5) +#define M4U_PORT_MDP_PVRIC1 MTK_M4U_ID(M4U_LARB1_ID, 6) +#define M4U_PORT_MDP_RDMA0 MTK_M4U_ID(M4U_LARB1_ID, 7) +#define M4U_PORT_MDP_RDMA1 MTK_M4U_ID(M4U_LARB1_ID, 8) +#define M4U_PORT_MDP_WROT0_R MTK_M4U_ID(M4U_LARB1_ID, 9) +#define M4U_PORT_MDP_WROT0_W MTK_M4U_ID(M4U_LARB1_ID, 10) +#define M4U_PORT_MDP_WROT1_R MTK_M4U_ID(M4U_LARB1_ID, 11) +#define M4U_PORT_MDP_WROT1_W MTK_M4U_ID(M4U_LARB1_ID, 12) +#define M4U_PORT_DISP_FAKE1 MTK_M4U_ID(M4U_LARB1_ID, 13) + +/* larb2-VDEC */ +#define M4U_PORT_HW_VDEC_MC_EXT MTK_M4U_ID(M4U_LARB2_ID, 0) +#define M4U_PORT_HW_VDEC_UFO_EXT MTK_M4U_ID(M4U_LARB2_ID, 1) +#define M4U_PORT_HW_VDEC_PP_EXT MTK_M4U_ID(M4U_LARB2_ID, 2) +#define M4U_PORT_HW_VDEC_PRED_RD_EXT MTK_M4U_ID(M4U_LARB2_ID, 3)
include/dt-bindings/memory/mt6779-larb-port.h line 68
Quoted 10 lines
include/dt-bindings/memory/mt6779-larb-port.h new file +10
-0+#define M4U_PORT_HW_VDEC_PRED_WR_EXT MTK_M4U_ID(M4U_LARB2_ID, 4) +#define M4U_PORT_HW_VDEC_PPWRAP_EXT MTK_M4U_ID(M4U_LARB2_ID, 5) +#define M4U_PORT_HW_VDEC_TILE_EXT MTK_M4U_ID(M4U_LARB2_ID, 6) +#define M4U_PORT_HW_VDEC_VLD_EXT MTK_M4U_ID(M4U_LARB2_ID, 7) +#define M4U_PORT_HW_VDEC_VLD2_EXT MTK_M4U_ID(M4U_LARB2_ID, 8) +#define M4U_PORT_HW_VDEC_AVC_MV_EXT MTK_M4U_ID(M4U_LARB2_ID, 9) +#define M4U_PORT_HW_VDEC_UFO_ENC_EXT MTK_M4U_ID(M4U_LARB2_ID, 10) +#define M4U_PORT_HW_VDEC_RG_CTRL_DMA_EXT MTK_M4U_ID(M4U_LARB2_ID, 11) + +/*larb3-VENC*/
Normally add space before and after the word. Like: /* larb3-VENC */
below are the same.
Quoted 23 lines
include/dt-bindings/memory/mt6779-larb-port.h new file +23
-0+#define M4U_PORT_VENC_RCPU MTK_M4U_ID(M4U_LARB3_ID, 0) +#define M4U_PORT_VENC_REC MTK_M4U_ID(M4U_LARB3_ID, 1) +#define M4U_PORT_VENC_BSDMA MTK_M4U_ID(M4U_LARB3_ID, 2) +#define M4U_PORT_VENC_SV_COMV MTK_M4U_ID(M4U_LARB3_ID, 3) +#define M4U_PORT_VENC_RD_COMV MTK_M4U_ID(M4U_LARB3_ID, 4) +#define M4U_PORT_VENC_NBM_RDMA MTK_M4U_ID(M4U_LARB3_ID, 5) +#define M4U_PORT_VENC_NBM_RDMA_LITE MTK_M4U_ID(M4U_LARB3_ID, 6) +#define M4U_PORT_JPGENC_Y_RDMA MTK_M4U_ID(M4U_LARB3_ID, 7) +#define M4U_PORT_JPGENC_C_RDMA MTK_M4U_ID(M4U_LARB3_ID, 8) +#define M4U_PORT_JPGENC_Q_TABLE MTK_M4U_ID(M4U_LARB3_ID, 9) +#define M4U_PORT_JPGENC_BSDMA MTK_M4U_ID(M4U_LARB3_ID, 10) +#define M4U_PORT_JPGDEC_WDMA MTK_M4U_ID(M4U_LARB3_ID, 11) +#define M4U_PORT_JPGDEC_BSDMA MTK_M4U_ID(M4U_LARB3_ID, 12) +#define M4U_PORT_VENC_NBM_WDMA MTK_M4U_ID(M4U_LARB3_ID, 13) +#define M4U_PORT_VENC_NBM_WDMA_LITE MTK_M4U_ID(M4U_LARB3_ID, 14) +#define M4U_PORT_VENC_CUR_LUMA MTK_M4U_ID(M4U_LARB3_ID, 15) +#define M4U_PORT_VENC_CUR_CHROMA MTK_M4U_ID(M4U_LARB3_ID, 16) +#define M4U_PORT_VENC_REF_LUMA MTK_M4U_ID(M4U_LARB3_ID, 17) +#define M4U_PORT_VENC_REF_CHROMA MTK_M4U_ID(M4U_LARB3_ID, 18) + +/*larb4-dummy*/ + +/*larb5-IMG*/
[snip]
include/dt-bindings/memory/mt6779-larb-port.h line 215
Quoted 6 lines
include/dt-bindings/memory/mt6779-larb-port.h new file +6
-0+ +#define M4U_PORT_VPU MTK_M4U_ID(M4U_LARB13_ID, 0) +#define M4U_PORT_MDLA MTK_M4U_ID(M4U_LARB13_ID, 1) +#define M4U_PORT_EDMA MTK_M4U_ID(M4U_LARB13_ID, 2) + +#define M4U_PORT_UNKNOWN (M4U_PORT_EDMA + 1)
When do you need this UNKNOWN one? The other SoC doesn't have it. Please remove if it is unnecessary.
Quoted 2 lines
include/dt-bindings/memory/mt6779-larb-port.h new file +2
-0+ +#endif
Re: [RESEND,PATCH 01/13] dt-bindings: mediatek: Add bindings for MT6779
Quoted 163 lines · Yong Wu
Quoted 121 lines · Chao Hao
This patch adds description for MT6779 IOMMU.
MT6779 has two iommus, they are
MM_IOMMUandAPU_IOMMUwhich use ARM Short-Descriptor translation format.The MT6779 IOMMU hardware diagram is as below, it is only a brief diagram about iommu, it don't focus on the part of
smi_larb, so I don't describe thesmi_larbdetailedly.EMI | -------------------------------------- | | MM_IOMMU APU_IOMMU | | SMI_COMMOM----------- APU_BUS | | | SMI_LARB(0~11) SMI_LARB12(FAKE) SMI_LARB13(FAKE) | | | | | -------------- | | | | |Multimedia engine CCU VPU MDLA EMDA
All the connections are hardware fixed, software can not adjust it.
From the diagram above,
MM_IOMMUprovides mapping for multimedia engine, but CCU is connected withsmi_commondirectly, we can take them as larb12.APU_IOMMUprovides mapping for APU engine, we can take them larb13. Larb12 and Larb13 are fake larbs.Signed-off-by Chao Hao <[email protected]>--- .../bindings/iommu/mediatek,iommu.txt | 2 + include/dt-bindings/memory/mt6779-larb-port.h | 217 ++++++++++++++++++ 2 files changed, 219 insertions(+) create mode 100644 include/dt-bindings/memory/mt6779-larb-port.hDocumentation/devicetree/bindings/iommu/mediatek,iommu.txt +2
-0@@ -58,6 +58,7 @@ Required properties: - compatible : must be one of the following string: "mediatek,mt2701-m4u" for mt2701 which uses generation one m4u HW. "mediatek,mt2712-m4u" for mt2712 which uses generation two m4u HW. + "mediatek,mt6779-m4u" for mt6779 which uses generation two m4u HW. "mediatek,mt7623-m4u", "mediatek,mt2701-m4u" for mt7623 which uses generation one m4u HW. "mediatek,mt8173-m4u" for mt8173 which uses generation two m4u HW.@@ -78,6 +79,7 @@ Required properties: Specifies the mtk_m4u_id as defined in dt-binding/memory/mt2701-larb-port.h for mt2701, mt7623 dt-binding/memory/mt2712-larb-port.h for mt2712, + dt-binding/memory/mt6779-larb-port.h for mt6779, dt-binding/memory/mt8173-larb-port.h for mt8173, and dt-binding/memory/mt8183-larb-port.h for mt8183.include/dt-bindings/memory/mt6779-larb-port.h new file +58
-0@@ -0,0 +1,217 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2019 MediaTek Inc. +* Author: Chao Hao <[email protected]> +*/ + +#ifndef _DTS_IOMMU_PORT_MT6779_H_ +#define _DTS_IOMMU_PORT_MT6779_H_ + +#define MTK_M4U_ID (larb, port) (((larb) << 5) | (port)) + +#define M4U_LARB0_ID 0 +#define M4U_LARB1_ID 1 +#define M4U_LARB2_ID 2 +#define M4U_LARB3_ID 3 +#define M4U_LARB4_ID 4 +#define M4U_LARB5_ID 5 +#define M4U_LARB6_ID 6 +#define M4U_LARB7_ID 7 +#define M4U_LARB8_ID 8 +#define M4U_LARB9_ID 9 +#define M4U_LARB10_ID 10 +#define M4U_LARB11_ID 11 +#define M4U_LARB12_ID 12 +#define M4U_LARB13_ID 13 + +/* larb0 */ +#define M4U_PORT_DISP_POSTMASK0 MTK_M4U_ID(M4U_LARB0_ID, 0) +#define M4U_PORT_DISP_OVL0_HDR MTK_M4U_ID(M4U_LARB0_ID, 1) +#define M4U_PORT_DISP_OVL1_HDR MTK_M4U_ID(M4U_LARB0_ID, 2) +#define M4U_PORT_DISP_OVL0 MTK_M4U_ID(M4U_LARB0_ID, 3) +#define M4U_PORT_DISP_OVL1 MTK_M4U_ID(M4U_LARB0_ID, 4) +#define M4U_PORT_DISP_PVRIC0 MTK_M4U_ID(M4U_LARB0_ID, 5) +#define M4U_PORT_DISP_RDMA0 MTK_M4U_ID(M4U_LARB0_ID, 6) +#define M4U_PORT_DISP_WDMA0 MTK_M4U_ID(M4U_LARB0_ID, 7) +#define M4U_PORT_DISP_FAKE0 MTK_M4U_ID(M4U_LARB0_ID, 8) + +/* larb1 */ +#define M4U_PORT_DISP_OVL0_2L_HDR MTK_M4U_ID(M4U_LARB1_ID, 0) +#define M4U_PORT_DISP_OVL1_2L_HDR MTK_M4U_ID(M4U_LARB1_ID, 1) +#define M4U_PORT_DISP_OVL0_2L MTK_M4U_ID(M4U_LARB1_ID, 2) +#define M4U_PORT_DISP_OVL1_2L MTK_M4U_ID(M4U_LARB1_ID, 3) +#define M4U_PORT_DISP_RDMA1 MTK_M4U_ID(M4U_LARB1_ID, 4) +#define M4U_PORT_MDP_PVRIC0 MTK_M4U_ID(M4U_LARB1_ID, 5) +#define M4U_PORT_MDP_PVRIC1 MTK_M4U_ID(M4U_LARB1_ID, 6) +#define M4U_PORT_MDP_RDMA0 MTK_M4U_ID(M4U_LARB1_ID, 7) +#define M4U_PORT_MDP_RDMA1 MTK_M4U_ID(M4U_LARB1_ID, 8) +#define M4U_PORT_MDP_WROT0_R MTK_M4U_ID(M4U_LARB1_ID, 9) +#define M4U_PORT_MDP_WROT0_W MTK_M4U_ID(M4U_LARB1_ID, 10) +#define M4U_PORT_MDP_WROT1_R MTK_M4U_ID(M4U_LARB1_ID, 11) +#define M4U_PORT_MDP_WROT1_W MTK_M4U_ID(M4U_LARB1_ID, 12) +#define M4U_PORT_DISP_FAKE1 MTK_M4U_ID(M4U_LARB1_ID, 13) + +/* larb2-VDEC */ +#define M4U_PORT_HW_VDEC_MC_EXT MTK_M4U_ID(M4U_LARB2_ID, 0) +#define M4U_PORT_HW_VDEC_UFO_EXT MTK_M4U_ID(M4U_LARB2_ID, 1) +#define M4U_PORT_HW_VDEC_PP_EXT MTK_M4U_ID(M4U_LARB2_ID, 2) +#define M4U_PORT_HW_VDEC_PRED_RD_EXT MTK_M4U_ID(M4U_LARB2_ID, 3)include/dt-bindings/memory/mt6779-larb-port.h line 68
Quoted 10 lines
include/dt-bindings/memory/mt6779-larb-port.h new file +10
-0+#define M4U_PORT_HW_VDEC_PRED_WR_EXT MTK_M4U_ID(M4U_LARB2_ID, 4) +#define M4U_PORT_HW_VDEC_PPWRAP_EXT MTK_M4U_ID(M4U_LARB2_ID, 5) +#define M4U_PORT_HW_VDEC_TILE_EXT MTK_M4U_ID(M4U_LARB2_ID, 6) +#define M4U_PORT_HW_VDEC_VLD_EXT MTK_M4U_ID(M4U_LARB2_ID, 7) +#define M4U_PORT_HW_VDEC_VLD2_EXT MTK_M4U_ID(M4U_LARB2_ID, 8) +#define M4U_PORT_HW_VDEC_AVC_MV_EXT MTK_M4U_ID(M4U_LARB2_ID, 9) +#define M4U_PORT_HW_VDEC_UFO_ENC_EXT MTK_M4U_ID(M4U_LARB2_ID, 10) +#define M4U_PORT_HW_VDEC_RG_CTRL_DMA_EXT MTK_M4U_ID(M4U_LARB2_ID, 11) + +/*larb3-VENC*/ Normally add space before and after the word. Like: /* larb3-VENC */
below are the same.
Quoted 23 lines
include/dt-bindings/memory/mt6779-larb-port.h new file +23
-0+#define M4U_PORT_VENC_RCPU MTK_M4U_ID(M4U_LARB3_ID, 0) +#define M4U_PORT_VENC_REC MTK_M4U_ID(M4U_LARB3_ID, 1) +#define M4U_PORT_VENC_BSDMA MTK_M4U_ID(M4U_LARB3_ID, 2) +#define M4U_PORT_VENC_SV_COMV MTK_M4U_ID(M4U_LARB3_ID, 3) +#define M4U_PORT_VENC_RD_COMV MTK_M4U_ID(M4U_LARB3_ID, 4) +#define M4U_PORT_VENC_NBM_RDMA MTK_M4U_ID(M4U_LARB3_ID, 5) +#define M4U_PORT_VENC_NBM_RDMA_LITE MTK_M4U_ID(M4U_LARB3_ID, 6) +#define M4U_PORT_JPGENC_Y_RDMA MTK_M4U_ID(M4U_LARB3_ID, 7) +#define M4U_PORT_JPGENC_C_RDMA MTK_M4U_ID(M4U_LARB3_ID, 8) +#define M4U_PORT_JPGENC_Q_TABLE MTK_M4U_ID(M4U_LARB3_ID, 9) +#define M4U_PORT_JPGENC_BSDMA MTK_M4U_ID(M4U_LARB3_ID, 10) +#define M4U_PORT_JPGDEC_WDMA MTK_M4U_ID(M4U_LARB3_ID, 11) +#define M4U_PORT_JPGDEC_BSDMA MTK_M4U_ID(M4U_LARB3_ID, 12) +#define M4U_PORT_VENC_NBM_WDMA MTK_M4U_ID(M4U_LARB3_ID, 13) +#define M4U_PORT_VENC_NBM_WDMA_LITE MTK_M4U_ID(M4U_LARB3_ID, 14) +#define M4U_PORT_VENC_CUR_LUMA MTK_M4U_ID(M4U_LARB3_ID, 15) +#define M4U_PORT_VENC_CUR_CHROMA MTK_M4U_ID(M4U_LARB3_ID, 16) +#define M4U_PORT_VENC_REF_LUMA MTK_M4U_ID(M4U_LARB3_ID, 17) +#define M4U_PORT_VENC_REF_CHROMA MTK_M4U_ID(M4U_LARB3_ID, 18) + +/*larb4-dummy*/ + +/*larb5-IMG*/ [snip]
Quoted 10 lines
include/dt-bindings/memory/mt6779-larb-port.h line 215
Quoted 6 lines
include/dt-bindings/memory/mt6779-larb-port.h new file +6
-0+ +#define M4U_PORT_VPU MTK_M4U_ID(M4U_LARB13_ID, 0) +#define M4U_PORT_MDLA MTK_M4U_ID(M4U_LARB13_ID, 1) +#define M4U_PORT_EDMA MTK_M4U_ID(M4U_LARB13_ID, 2) + +#define M4U_PORT_UNKNOWN (M4U_PORT_EDMA + 1)When do you need this UNKNOWN one? The other SoC doesn't have it. Please remove if it is unnecessary.
ok, I will fix it in next version, thanks
Quoted 4 lines
Quoted 2 lines
include/dt-bindings/memory/mt6779-larb-port.h new file +2
-0+ +#endif
PATCH RESEND 2/13 iommu/mediatek: Add mt6779 IOMMU basic support
In reply to Chao Hao1. Add mt6779 registers define for iommu.
2. Add mt6779_data define to support mt6779 iommu HW init.
3. There are two iommus, one is mm_iommu, the other is vpu_iommu. MM_IOMMU is connected smi_larb to support multimedia engine to access DRAM, and VPU_IOMMU is connected to APU_bus to support VPU,MDLA,EDMA to access DRAM. MM_IOMMU and VPU_IOMMU use the same page table to simplify design by "mtk_iommu_get_m4u_data".
4. For smi_larb6, it doesn't use mm_iommu, so we can distinguish vpu_iommu by it when excutes iommu_probe.
5. For mt6779 APU_IOMMU fault id is irregular, so it was treated specially.
--- drivers/iommu/mtk_iommu.c | 91 +++++++++++++++++++++++++++++++++------ drivers/iommu/mtk_iommu.h | 10 ++++- 2 files changed, 87 insertions(+), 14 deletions(-)
drivers/iommu/mtk_iommu.c +78 -13
@@ -38,12 +38,24 @@#define REG_MMU_INVLD_END_A 0x028#define REG_MMU_INV_SEL 0x038 +#define REG_MMU_INV_SEL_MT6779 0x02c#define F_INVLD_EN0 BIT(0)#define F_INVLD_EN1 BIT(1)#define REG_MMU_STANDARD_AXI_MODE 0x048 + +#define REG_MMU_MISC_CRTL_MT6779 0x048 +#define REG_MMU_STANDARD_AXI_MODE_MT6779 (BIT(3) | BIT(19)) +#define REG_MMU_COHERENCE_EN (BIT(0) | BIT(16)) +#define REG_MMU_IN_ORDER_WR_EN (BIT(1) | BIT(17)) +#define F_MMU_HALF_ENTRY_MODE_L (BIT(5) | BIT(21)) +#define F_MMU_BLOCKING_MODE_L (BIT(4) | BIT(20)) +#define REG_MMU_DCM_DIS 0x050 +#define REG_MMU_WR_LEN 0x054 +#define F_MMU_WR_THROT_DIS (BIT(5) | BIT(21)) +#define REG_MMU_CTRL_REG 0x110#define F_MMU_TF_PROT_TO_PROGRAM_ADDR (2 << 4)#define F_MMU_PREFETCH_RT_REPLACE_MOD BIT(4)
@@ -88,10 +100,14 @@#define REG_MMU1_INVLD_PA 0x148#define REG_MMU0_INT_ID 0x150#define REG_MMU1_INT_ID 0x154 +#define F_MMU_INT_ID_COMM_ID (a) (((a) >> 9) & 0x7) +#define F_MMU_INT_ID_SUB_COMM_ID (a) (((a) >> 7) & 0x3)#define F_MMU_INT_ID_LARB_ID (a) (((a) >> 7) & 0x7)#define F_MMU_INT_ID_PORT_ID (a) (((a) >> 2) & 0x1f) +#define F_MMU_INT_ID_COMM_APU_ID (a) ((a) & 0x3) +#define F_MMU_INT_ID_SUB_APU_ID (a) (((a) >> 2) & 0x3) -#define MTK_PROTECT_PA_ALIGN 128 +#define MTK_PROTECT_PA_ALIGN 256/* * Get the local arbiter ID and the portid within the larb arbiter
@@ -165,7 +181,7 @@ static void mtk_iommu_tlb_flush_all(void *cookie)for_each_m4u (data) {writel_relaxed (F_INVLD_EN1 |F_INVLD_EN0 , - data->base +REG_MMU_INV_SEL ); + data->base + data->plat_data->inv_sel_reg);writel_relaxed (F_ALL_INVLD , data->base +REG_MMU_INVALIDATE );wmb ();/* Make sure the tlb flush all done */ }
@@ -182,7 +198,7 @@ static void mtk_iommu_tlb_flush_range_sync(unsigned long iova, size_t size,for_each_m4u (data) {spin_lock_irqsave (&data->tlb_lock, flags);writel_relaxed (F_INVLD_EN1 |F_INVLD_EN0 , - data->base +REG_MMU_INV_SEL ); + data->base + data->plat_data->inv_sel_reg);writel_relaxed (iova, data->base +REG_MMU_INVLD_START_A ); writel_relaxed(iova + size - 1,
@@ -226,7 +242,7 @@ static irqreturn_t mtk_iommu_isr(int irq, void *dev_id)struct mtk_iommu_data *data = dev_id;struct mtk_iommu_domain *dom = data->m4u_dom;u32 int_state, regval, fault_iova, fault_pa; -unsigned int fault_larb, fault_port; +unsigned int fault_larb, fault_port, sub_comm =0 ;bool layer, write;/* Read error info from registers */
@@ -242,17 +258,30 @@ static irqreturn_t mtk_iommu_isr(int irq, void *dev_id) } layer = fault_iova &F_MMU_FAULT_VA_LAYER_BIT ; write = fault_iova &F_MMU_FAULT_VA_WRITE_BIT ; - fault_larb =F_MMU_INT_ID_LARB_ID (regval); fault_port =F_MMU_INT_ID_PORT_ID (regval); +if (data->plat_data->has_sub_comm[data->m4u_id]) { +/* m4u1 is VPU in mt6779.*/ +if (data->m4u_id && data->plat_data->m4u_plat ==M4U_MT6779 ) { + fault_larb =F_MMU_INT_ID_COMM_APU_ID (regval); + sub_comm =F_MMU_INT_ID_SUB_APU_ID (regval); + fault_port =0 ;/* for mt6779 APU ID is irregular */ + }else { + fault_larb =F_MMU_INT_ID_COMM_ID (regval); + sub_comm =F_MMU_INT_ID_SUB_COMM_ID (regval); + } + }else { + fault_larb =F_MMU_INT_ID_LARB_ID (regval); + } - fault_larb = data->plat_data->larbid_remap[fault_larb]; + fault_larb = data->plat_data->larbid_remap[data->m4u_id][fault_larb];if (report_iommu_fault (&dom->domain, data->dev, fault_iova, write ?IOMMU_FAULT_WRITE :IOMMU_FAULT_READ )) {dev_err_ratelimited ( data->dev, -"fault type=0x%x iova=0x%x pa=0x%x larb=%d port=%d layer=%d %s\n" , - int_state, fault_iova, fault_pa, fault_larb, fault_port, +"fault type=0x%x iova=0x%x pa=0x%x larb=%d sub_comm=%d port=%d regval=0x%x layer=%d %s\n" , + int_state, fault_iova, fault_pa, fault_larb, + sub_comm, fault_port, regval, layer, write ?"write" :"read" ); }
@@ -545,11 +574,12 @@ static int mtk_iommu_hw_init(const struct mtk_iommu_data *data)return ret; } + regval =readl_relaxed (data->base +REG_MMU_CTRL_REG );if (data->plat_data->m4u_plat ==M4U_MT8173 ) - regval =F_MMU_PREFETCH_RT_REPLACE_MOD | + regval |=F_MMU_PREFETCH_RT_REPLACE_MOD |F_MMU_TF_PROT_TO_PROGRAM_ADDR_MT8173 ;else - regval =F_MMU_TF_PROT_TO_PROGRAM_ADDR ; + regval |=F_MMU_TF_PROT_TO_PROGRAM_ADDR ;writel_relaxed (regval, data->base +REG_MMU_CTRL_REG ); regval = F_L2_MULIT_HIT_EN |
@@ -589,6 +619,20 @@ static int mtk_iommu_hw_init(const struct mtk_iommu_data *data)if (data->plat_data->reset_axi)writel_relaxed (0 , data->base +REG_MMU_STANDARD_AXI_MODE ); +if (data->plat_data->has_wr_len) { +/* write command throttling mode */ + regval =readl_relaxed (data->base +REG_MMU_WR_LEN ); + regval &= ~F_MMU_WR_THROT_DIS ; +writel_relaxed (regval, data->base +REG_MMU_WR_LEN ); + } +/* special settings for mmu0 (multimedia iommu) */ +if (data->plat_data->has_misc_ctrl[data->m4u_id]) { + regval =readl_relaxed (data->base +REG_MMU_MISC_CRTL_MT6779 ); +/* non-standard AXI mode */ + regval &= ~REG_MMU_STANDARD_AXI_MODE_MT6779 ; +writel_relaxed (regval, data->base +REG_MMU_MISC_CRTL_MT6779 ); + } +if (devm_request_irq (data->dev, data->irq, mtk_iommu_isr,0 ,dev_name (data->dev), (void *)data)) {writel_relaxed (0 , data->base +REG_MMU_PT_BASE_ADDR );
@@ -678,6 +722,9 @@ static int mtk_iommu_probe(struct platform_device *pdev) } data->larb_imu[id].dev = &plarbdev->dev; +if (data->plat_data->m4u1_mask == (1 << id)) + data->m4u_id =1 ; +component_match_add_release (dev, &match, release_of, compare_of, larbnode); }
@@ -731,6 +778,7 @@ static int __maybe_unused mtk_iommu_suspend(struct device *dev)struct mtk_iommu_suspend_reg *reg = &data->reg;void __iomem *base = data->base; + reg->wr_len =readl_relaxed (base +REG_MMU_WR_LEN ); reg->standard_axi_mode =readl_relaxed (base +REG_MMU_STANDARD_AXI_MODE ); reg->dcm_dis =readl_relaxed (base +REG_MMU_DCM_DIS );
@@ -756,6 +804,7 @@ static int __maybe_unused mtk_iommu_resume(struct device *dev)dev_err (data->dev,"Failed to enable clk(%d) in resume\n" , ret);return ret; } +writel_relaxed (reg->wr_len, base +REG_MMU_WR_LEN );writel_relaxed (reg->standard_axi_mode, base +REG_MMU_STANDARD_AXI_MODE );writel_relaxed (reg->dcm_dis, base +REG_MMU_DCM_DIS );
@@ -779,7 +828,20 @@ static const struct mtk_iommu_plat_data mt2712_data = { .has_4gb_mode = true, .has_bclk = true, .has_vld_pa_rng = true, - .larbid_remap = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, + .larbid_remap[0] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, + .inv_sel_reg = REG_MMU_INV_SEL, +}; + +static const struct mtk_iommu_plat_data mt6779_data = { + .m4u_plat =M4U_MT6779 , + .larbid_remap[0 ] = {0 ,1 ,2 ,3 ,5 ,7 ,10 ,9 }, +/* vp6a, vp6b, mdla/core2, mdla/edmc*/ + .larbid_remap[1 ] = {2 ,0 ,3 ,1 }, + .has_sub_comm = {true, true}, + .has_wr_len = true, + .has_misc_ctrl = {true, false}, + .inv_sel_reg =REG_MMU_INV_SEL_MT6779 , + .m4u1_mask =BIT (6 ), }; static const struct mtk_iommu_plat_data mt8173_data = {
@@ -787,17 +849,20 @@ static const struct mtk_iommu_plat_data mt8173_data = { .has_4gb_mode = true, .has_bclk = true, .reset_axi = true, - .larbid_remap = {0, 1, 2, 3, 4, 5}, /* Linear mapping. */ + .larbid_remap[0] = {0, 1, 2, 3, 4, 5}, /* Linear mapping. */ + .inv_sel_reg = REG_MMU_INV_SEL, };static const struct mtk_iommu_plat_data mt8183_data = { .m4u_plat =M4U_MT8183 , .reset_axi = true, - .larbid_remap = {0 ,4 ,5 ,6 ,7 ,2 ,3 ,1 }, + .larbid_remap[0 ] = {0 ,4 ,5 ,6 ,7 ,2 ,3 ,1 }, + .inv_sel_reg =REG_MMU_INV_SEL , };static const struct of_device_id mtk_iommu_of_ids[] = { { .compatible ="mediatek,mt2712-m4u" , .data = &mt2712_data}, + { .compatible ="mediatek,mt6779-m4u" , .data = &mt6779_data}, { .compatible ="mediatek,mt8173-m4u" , .data = &mt8173_data}, { .compatible ="mediatek,mt8183-m4u" , .data = &mt8183_data}, {}
drivers/iommu/mtk_iommu.h +9 -1
@@ -25,11 +25,13 @@ struct mtk_iommu_suspend_reg {u32 int_main_control;u32 ivrp_paddr;u32 vld_pa_rng; +u32 wr_len; };enum mtk_iommu_plat {M4U_MT2701 ,M4U_MT2712 , +M4U_MT6779 ,M4U_MT8173 ,M4U_MT8183 , };
@@ -42,7 +44,12 @@ struct mtk_iommu_plat_data {bool has_bclk;bool has_vld_pa_rng;bool reset_axi; -unsigned char larbid_remap[MTK_LARB_NR_MAX ]; +bool has_sub_comm[2 ]; +bool has_wr_len; +bool has_misc_ctrl[2 ]; +u32 inv_sel_reg; +u32 m4u1_mask; +unsigned char larbid_remap[2 ][MTK_LARB_NR_MAX ]; };struct mtk_iommu_domain ;
@@ -59,6 +66,7 @@ struct mtk_iommu_data {bool enable_4GB;spinlock_t tlb_lock;/* lock for tlb range flush */ +u32 m4u_id;struct iommu_device iommu;const struct mtk_iommu_plat_data *plat_data;
Signature · 6 lines
2.18.0 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Yong Wu
maintainerRe: [RESEND,PATCH 02/13] iommu/mediatek: Add mt6779 IOMMU basic support
Quoted 23 lines · Chao Hao
1. Add mt6779 registers define for iommu.
2. Addmt6779_datadefine to support mt6779 iommu HW init.
3. There are two iommus, one ismm_iommu, the other isvpu_iommu.MM_IOMMUis connectedsmi_larbto support multimedia engine to access DRAM, andVPU_IOMMUis connected toAPU_busto support VPU,MDLA,EDMA to access DRAM.MM_IOMMUandVPU_IOMMUuse the same page table to simplify design by "mtk_iommu_get_m4u_data".
4. Forsmi_larb6, it doesn't usemm_iommu, so we can distinguishvpu_iommuby it when excutesiommu_probe.
5. For mt6779APU_IOMMUfault id is irregular, so it was treated specially.Signed-off-by Chao Hao <[email protected]>--- drivers/iommu/mtk_iommu.c | 91 +++++++++++++++++++++++++++++++++------ drivers/iommu/mtk_iommu.h | 10 ++++- 2 files changed, 87 insertions(+), 14 deletions(-)drivers/iommu/mtk_iommu.c +0
-0
drivers/iommu/mtk_iommu.c line 47
Quoted 10 lines
drivers/iommu/mtk_iommu.c +3
-0@@ -38,12 +38,24 @@#define REG_MMU_INVLD_END_A 0x028#define REG_MMU_INV_SEL 0x038 +#define REG_MMU_INV_SEL_MT6779 0x02c#define F_INVLD_EN0 BIT(0)#define F_INVLD_EN1 BIT(1)#define REG_MMU_STANDARD_AXI_MODE 0x048 + +#define REG_MMU_MISC_CRTL_MT6779 0x048
Defining two register in the same offset look strange. see below.
drivers/iommu/mtk_iommu.c line 52
Quoted 5 lines
drivers/iommu/mtk_iommu.c +5
-0+#define REG_MMU_STANDARD_AXI_MODE_MT6779 (BIT(3) | BIT(19)) +#define REG_MMU_COHERENCE_EN (BIT(0) | BIT(16)) +#define REG_MMU_IN_ORDER_WR_EN (BIT(1) | BIT(17)) +#define F_MMU_HALF_ENTRY_MODE_L (BIT(5) | BIT(21)) +#define F_MMU_BLOCKING_MODE_L (BIT(4) | BIT(20))
The last four ones are not used. Please remove.
Quoted 109 lines
drivers/iommu/mtk_iommu.c +35
-10+#define REG_MMU_DCM_DIS 0x050 +#define REG_MMU_WR_LEN 0x054 +#define F_MMU_WR_THROT_DIS (BIT(5) | BIT(21)) +#define REG_MMU_CTRL_REG 0x110#define F_MMU_TF_PROT_TO_PROGRAM_ADDR (2 << 4)#define F_MMU_PREFETCH_RT_REPLACE_MOD BIT(4)@@ -88,10 +100,14 @@#define REG_MMU1_INVLD_PA 0x148#define REG_MMU0_INT_ID 0x150#define REG_MMU1_INT_ID 0x154 +#define F_MMU_INT_ID_COMM_ID (a) (((a) >> 9) & 0x7) +#define F_MMU_INT_ID_SUB_COMM_ID (a) (((a) >> 7) & 0x3)#define F_MMU_INT_ID_LARB_ID (a) (((a) >> 7) & 0x7)#define F_MMU_INT_ID_PORT_ID (a) (((a) >> 2) & 0x1f) +#define F_MMU_INT_ID_COMM_APU_ID (a) ((a) & 0x3) +#define F_MMU_INT_ID_SUB_APU_ID (a) (((a) >> 2) & 0x3) -#define MTK_PROTECT_PA_ALIGN 128 +#define MTK_PROTECT_PA_ALIGN 256/* * Get the local arbiter ID and the portid within the larb arbiter @@ -165,7 +181,7 @@ static void mtk_iommu_tlb_flush_all(void *cookie)for_each_m4u (data) {writel_relaxed (F_INVLD_EN1 |F_INVLD_EN0 , - data->base +REG_MMU_INV_SEL ); + data->base + data->plat_data->inv_sel_reg);writel_relaxed (F_ALL_INVLD , data->base +REG_MMU_INVALIDATE );wmb ();/* Make sure the tlb flush all done */ }@@ -182,7 +198,7 @@ static void mtk_iommu_tlb_flush_range_sync(unsigned long iova, size_t size,for_each_m4u (data) {spin_lock_irqsave (&data->tlb_lock, flags);writel_relaxed (F_INVLD_EN1 |F_INVLD_EN0 , - data->base +REG_MMU_INV_SEL ); + data->base + data->plat_data->inv_sel_reg);writel_relaxed (iova, data->base +REG_MMU_INVLD_START_A ); writel_relaxed(iova + size - 1,@@ -226,7 +242,7 @@ static irqreturn_t mtk_iommu_isr(int irq, void *dev_id)struct mtk_iommu_data *data = dev_id;struct mtk_iommu_domain *dom = data->m4u_dom;u32 int_state, regval, fault_iova, fault_pa; -unsigned int fault_larb, fault_port; +unsigned int fault_larb, fault_port, sub_comm =0 ;bool layer, write;/* Read error info from registers */ @@ -242,17 +258,30 @@ static irqreturn_t mtk_iommu_isr(int irq, void *dev_id) } layer = fault_iova &F_MMU_FAULT_VA_LAYER_BIT ; write = fault_iova &F_MMU_FAULT_VA_WRITE_BIT ; - fault_larb =F_MMU_INT_ID_LARB_ID (regval); fault_port =F_MMU_INT_ID_PORT_ID (regval); +if (data->plat_data->has_sub_comm[data->m4u_id]) { +/* m4u1 is VPU in mt6779.*/ +if (data->m4u_id && data->plat_data->m4u_plat ==M4U_MT6779 ) { + fault_larb =F_MMU_INT_ID_COMM_APU_ID (regval); + sub_comm =F_MMU_INT_ID_SUB_APU_ID (regval); + fault_port =0 ;/* for mt6779 APU ID is irregular */ + }else { + fault_larb =F_MMU_INT_ID_COMM_ID (regval); + sub_comm =F_MMU_INT_ID_SUB_COMM_ID (regval); + } + }else { + fault_larb =F_MMU_INT_ID_LARB_ID (regval); + } - fault_larb = data->plat_data->larbid_remap[fault_larb]; + fault_larb = data->plat_data->larbid_remap[data->m4u_id][fault_larb];if (report_iommu_fault (&dom->domain, data->dev, fault_iova, write ?IOMMU_FAULT_WRITE :IOMMU_FAULT_READ )) {dev_err_ratelimited ( data->dev, -"fault type=0x%x iova=0x%x pa=0x%x larb=%d port=%d layer=%d %s\n" , - int_state, fault_iova, fault_pa, fault_larb, fault_port, +"fault type=0x%x iova=0x%x pa=0x%x larb=%d sub_comm=%d port=%d regval=0x%x layer=%d %s\n" , + int_state, fault_iova, fault_pa, fault_larb, + sub_comm, fault_port, regval, layer, write ?"write" :"read" ); }@@ -545,11 +574,12 @@ static int mtk_iommu_hw_init(const struct mtk_iommu_data *data)return ret; } + regval =readl_relaxed (data->base +REG_MMU_CTRL_REG );if (data->plat_data->m4u_plat ==M4U_MT8173 ) - regval =F_MMU_PREFETCH_RT_REPLACE_MOD | + regval |=F_MMU_PREFETCH_RT_REPLACE_MOD |F_MMU_TF_PROT_TO_PROGRAM_ADDR_MT8173 ;else - regval =F_MMU_TF_PROT_TO_PROGRAM_ADDR ; + regval |=F_MMU_TF_PROT_TO_PROGRAM_ADDR ;writel_relaxed (regval, data->base +REG_MMU_CTRL_REG ); regval = F_L2_MULIT_HIT_EN |@@ -589,6 +619,20 @@ static int mtk_iommu_hw_init(const struct mtk_iommu_data *data)if (data->plat_data->reset_axi)writel_relaxed (0 , data->base +REG_MMU_STANDARD_AXI_MODE ); +if (data->plat_data->has_wr_len) { +/* write command throttling mode */ + regval =readl_relaxed (data->base +REG_MMU_WR_LEN );
drivers/iommu/mtk_iommu.c static int mtk_iommu_hw_init(const struct mtk_iommu_data *data) · line 634
Quoted 10 lines
drivers/iommu/mtk_iommu.c +10
-0+ regval &= ~F_MMU_WR_THROT_DIS ; +writel_relaxed (regval, data->base +REG_MMU_WR_LEN ); + } +/* special settings for mmu0 (multimedia iommu) */ +if (data->plat_data->has_misc_ctrl[data->m4u_id]) { + regval =readl_relaxed (data->base +REG_MMU_MISC_CRTL_MT6779 ); +/* non-standard AXI mode */ + regval &= ~REG_MMU_STANDARD_AXI_MODE_MT6779 ; +writel_relaxed (regval, data->base +REG_MMU_MISC_CRTL_MT6779 ); + }
0x48 are REG_MMU_STANDARD_AXI_MODE in both mt8173 and mt8183, while
it is REG_MMU_MISC_CRTL in mt2712, mt6779 and the latest soc, right? I think we can use one defining, like this:
#define REG_MMU_MISC_CTRL 0x48
if (!data->plat_data->has_misc_ctrl[data->m4u_id]) {
/* Disable standard axi mode while it is
REG_MMU_STANDARD_AXI_MODE */
writel_relaxed(0, data->base + REG_MMU_MISC_CTRL);
} else if (data->m4u_id == 0) {
regval = readl_relaxed(data->base + REG_MMU_MISC_CTRL);
regval &= ~REG_MMU_STANDARD_AXI_MODE_MT6779;
writel_relaxed(regval, data->base + REG_MMU_MISC_CTRL);
}
Meanwhile remove the setting for REG_MMU_STANDARD_AXI_MODE above.Quoted 94 lines
drivers/iommu/mtk_iommu.c +25
-3+if (devm_request_irq (data->dev, data->irq, mtk_iommu_isr,0 ,dev_name (data->dev), (void *)data)) {writel_relaxed (0 , data->base +REG_MMU_PT_BASE_ADDR );@@ -678,6 +722,9 @@ static int mtk_iommu_probe(struct platform_device *pdev) } data->larb_imu[id].dev = &plarbdev->dev; +if (data->plat_data->m4u1_mask == (1 << id)) + data->m4u_id =1 ; +component_match_add_release (dev, &match, release_of, compare_of, larbnode); }@@ -731,6 +778,7 @@ static int __maybe_unused mtk_iommu_suspend(struct device *dev)struct mtk_iommu_suspend_reg *reg = &data->reg;void __iomem *base = data->base; + reg->wr_len =readl_relaxed (base +REG_MMU_WR_LEN ); reg->standard_axi_mode =readl_relaxed (base +REG_MMU_STANDARD_AXI_MODE ); reg->dcm_dis =readl_relaxed (base +REG_MMU_DCM_DIS );@@ -756,6 +804,7 @@ static int __maybe_unused mtk_iommu_resume(struct device *dev)dev_err (data->dev,"Failed to enable clk(%d) in resume\n" , ret);return ret; } +writel_relaxed (reg->wr_len, base +REG_MMU_WR_LEN );writel_relaxed (reg->standard_axi_mode, base +REG_MMU_STANDARD_AXI_MODE );writel_relaxed (reg->dcm_dis, base +REG_MMU_DCM_DIS );@@ -779,7 +828,20 @@ static const struct mtk_iommu_plat_data mt2712_data = { .has_4gb_mode = true, .has_bclk = true, .has_vld_pa_rng = true, - .larbid_remap = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, + .larbid_remap[0] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, + .inv_sel_reg = REG_MMU_INV_SEL, +}; + +static const struct mtk_iommu_plat_data mt6779_data = { + .m4u_plat =M4U_MT6779 , + .larbid_remap[0 ] = {0 ,1 ,2 ,3 ,5 ,7 ,10 ,9 }, +/* vp6a, vp6b, mdla/core2, mdla/edmc*/ + .larbid_remap[1 ] = {2 ,0 ,3 ,1 }, + .has_sub_comm = {true, true}, + .has_wr_len = true, + .has_misc_ctrl = {true, false}, + .inv_sel_reg =REG_MMU_INV_SEL_MT6779 , + .m4u1_mask =BIT (6 ), }; static const struct mtk_iommu_plat_data mt8173_data = {@@ -787,17 +849,20 @@ static const struct mtk_iommu_plat_data mt8173_data = { .has_4gb_mode = true, .has_bclk = true, .reset_axi = true, - .larbid_remap = {0, 1, 2, 3, 4, 5}, /* Linear mapping. */ + .larbid_remap[0] = {0, 1, 2, 3, 4, 5}, /* Linear mapping. */ + .inv_sel_reg = REG_MMU_INV_SEL, };static const struct mtk_iommu_plat_data mt8183_data = { .m4u_plat =M4U_MT8183 , .reset_axi = true, - .larbid_remap = {0 ,4 ,5 ,6 ,7 ,2 ,3 ,1 }, + .larbid_remap[0 ] = {0 ,4 ,5 ,6 ,7 ,2 ,3 ,1 }, + .inv_sel_reg =REG_MMU_INV_SEL , };static const struct of_device_id mtk_iommu_of_ids[] = { { .compatible ="mediatek,mt2712-m4u" , .data = &mt2712_data}, + { .compatible ="mediatek,mt6779-m4u" , .data = &mt6779_data}, { .compatible ="mediatek,mt8173-m4u" , .data = &mt8173_data}, { .compatible ="mediatek,mt8183-m4u" , .data = &mt8183_data}, {}drivers/iommu/mtk_iommu.h +2
-0@@ -25,11 +25,13 @@ struct mtk_iommu_suspend_reg {u32 int_main_control;u32 ivrp_paddr;u32 vld_pa_rng; +u32 wr_len; };enum mtk_iommu_plat {M4U_MT2701 ,M4U_MT2712 , +M4U_MT6779 ,M4U_MT8173 ,M4U_MT8183 , };
drivers/iommu/mtk_iommu.h struct mtk_iommu_plat_data { · line 51
Quoted 9 lines
drivers/iommu/mtk_iommu.h +5
-1@@ -42,7 +44,12 @@ struct mtk_iommu_plat_data {bool has_bclk;bool has_vld_pa_rng;bool reset_axi; -unsigned char larbid_remap[MTK_LARB_NR_MAX ]; +bool has_sub_comm[2 ]; +bool has_wr_len; +bool has_misc_ctrl[2 ]; +u32 inv_sel_reg; +u32 m4u1_mask;
alphabetically for the new ones.
drivers/iommu/mtk_iommu.h struct mtk_iommu_data { · line 71
Quoted 11 lines
drivers/iommu/mtk_iommu.h +2
-0+unsigned char larbid_remap[2 ][MTK_LARB_NR_MAX ]; };struct mtk_iommu_domain ;@@ -59,6 +66,7 @@ struct mtk_iommu_data {bool enable_4GB;spinlock_t tlb_lock;/* lock for tlb range flush */ +u32 m4u_id;struct iommu_device iommu;const struct mtk_iommu_plat_data *plat_data;
Basically this patch looks ok for me. But please split it to several patches:
1) Extend larbid_remap to larbid_remap[2].
Actually mt2712 also need this. this is the mt2712 definition. larbid_remap[0] = {0, 1, 2, 3},
larbid_remap[1] = {4, 5, 7, 8, 9},
2) Regarding the 0x48(misc_ctrl register)
3) Add m4u1_mask to distinguish the m4u_id.
4) Add REG_MMU_WR_LEN if you need.
5) Put inv_sel_reg in the plat_data for preparing add 0x2c support in mt6779.
6) Add new flow to get SUB_COMMON ID and VPU larbid in the translation fault.
7) Add mt6779 support.
Quoted 1 line
Re: [RESEND,PATCH 02/13] iommu/mediatek: Add mt6779 IOMMU basic support
Quoted 315 lines · Yong Wu
Quoted 23 lines · Chao Hao
1. Add mt6779 registers define for iommu.
2. Addmt6779_datadefine to support mt6779 iommu HW init.
3. There are two iommus, one ismm_iommu, the other isvpu_iommu.MM_IOMMUis connectedsmi_larbto support multimedia engine to access DRAM, andVPU_IOMMUis connected toAPU_busto support VPU,MDLA,EDMA to access DRAM.MM_IOMMUandVPU_IOMMUuse the same page table to simplify design by "mtk_iommu_get_m4u_data".
4. Forsmi_larb6, it doesn't usemm_iommu, so we can distinguishvpu_iommuby it when excutesiommu_probe.
5. For mt6779APU_IOMMUfault id is irregular, so it was treated specially.Signed-off-by Chao Hao <[email protected]>--- drivers/iommu/mtk_iommu.c | 91 +++++++++++++++++++++++++++++++++------ drivers/iommu/mtk_iommu.h | 10 ++++- 2 files changed, 87 insertions(+), 14 deletions(-)drivers/iommu/mtk_iommu.c +0
-0drivers/iommu/mtk_iommu.c line 47
Quoted 10 lines
drivers/iommu/mtk_iommu.c +3
-0@@ -38,12 +38,24 @@#define REG_MMU_INVLD_END_A 0x028#define REG_MMU_INV_SEL 0x038 +#define REG_MMU_INV_SEL_MT6779 0x02c#define F_INVLD_EN0 BIT(0)#define F_INVLD_EN1 BIT(1)#define REG_MMU_STANDARD_AXI_MODE 0x048 + +#define REG_MMU_MISC_CRTL_MT6779 0x048Defining two register in the same offset look strange. see below.
drivers/iommu/mtk_iommu.c line 52
Quoted 5 lines
drivers/iommu/mtk_iommu.c +5
-0+#define REG_MMU_STANDARD_AXI_MODE_MT6779 (BIT(3) | BIT(19)) +#define REG_MMU_COHERENCE_EN (BIT(0) | BIT(16)) +#define REG_MMU_IN_ORDER_WR_EN (BIT(1) | BIT(17)) +#define F_MMU_HALF_ENTRY_MODE_L (BIT(5) | BIT(21)) +#define F_MMU_BLOCKING_MODE_L (BIT(4) | BIT(20))The last four ones are not used. Please remove.
Quoted 109 lines
drivers/iommu/mtk_iommu.c +35
-10+#define REG_MMU_DCM_DIS 0x050 +#define REG_MMU_WR_LEN 0x054 +#define F_MMU_WR_THROT_DIS (BIT(5) | BIT(21)) +#define REG_MMU_CTRL_REG 0x110#define F_MMU_TF_PROT_TO_PROGRAM_ADDR (2 << 4)#define F_MMU_PREFETCH_RT_REPLACE_MOD BIT(4)@@ -88,10 +100,14 @@#define REG_MMU1_INVLD_PA 0x148#define REG_MMU0_INT_ID 0x150#define REG_MMU1_INT_ID 0x154 +#define F_MMU_INT_ID_COMM_ID (a) (((a) >> 9) & 0x7) +#define F_MMU_INT_ID_SUB_COMM_ID (a) (((a) >> 7) & 0x3)#define F_MMU_INT_ID_LARB_ID (a) (((a) >> 7) & 0x7)#define F_MMU_INT_ID_PORT_ID (a) (((a) >> 2) & 0x1f) +#define F_MMU_INT_ID_COMM_APU_ID (a) ((a) & 0x3) +#define F_MMU_INT_ID_SUB_APU_ID (a) (((a) >> 2) & 0x3) -#define MTK_PROTECT_PA_ALIGN 128 +#define MTK_PROTECT_PA_ALIGN 256/* * Get the local arbiter ID and the portid within the larb arbiter @@ -165,7 +181,7 @@ static void mtk_iommu_tlb_flush_all(void *cookie)for_each_m4u (data) {writel_relaxed (F_INVLD_EN1 |F_INVLD_EN0 , - data->base +REG_MMU_INV_SEL ); + data->base + data->plat_data->inv_sel_reg);writel_relaxed (F_ALL_INVLD , data->base +REG_MMU_INVALIDATE );wmb ();/* Make sure the tlb flush all done */ }@@ -182,7 +198,7 @@ static void mtk_iommu_tlb_flush_range_sync(unsigned long iova, size_t size,for_each_m4u (data) {spin_lock_irqsave (&data->tlb_lock, flags);writel_relaxed (F_INVLD_EN1 |F_INVLD_EN0 , - data->base +REG_MMU_INV_SEL ); + data->base + data->plat_data->inv_sel_reg);writel_relaxed (iova, data->base +REG_MMU_INVLD_START_A ); writel_relaxed(iova + size - 1,@@ -226,7 +242,7 @@ static irqreturn_t mtk_iommu_isr(int irq, void *dev_id)struct mtk_iommu_data *data = dev_id;struct mtk_iommu_domain *dom = data->m4u_dom;u32 int_state, regval, fault_iova, fault_pa; -unsigned int fault_larb, fault_port; +unsigned int fault_larb, fault_port, sub_comm =0 ;bool layer, write;/* Read error info from registers */ @@ -242,17 +258,30 @@ static irqreturn_t mtk_iommu_isr(int irq, void *dev_id) } layer = fault_iova &F_MMU_FAULT_VA_LAYER_BIT ; write = fault_iova &F_MMU_FAULT_VA_WRITE_BIT ; - fault_larb =F_MMU_INT_ID_LARB_ID (regval); fault_port =F_MMU_INT_ID_PORT_ID (regval); +if (data->plat_data->has_sub_comm[data->m4u_id]) { +/* m4u1 is VPU in mt6779.*/ +if (data->m4u_id && data->plat_data->m4u_plat ==M4U_MT6779 ) { + fault_larb =F_MMU_INT_ID_COMM_APU_ID (regval); + sub_comm =F_MMU_INT_ID_SUB_APU_ID (regval); + fault_port =0 ;/* for mt6779 APU ID is irregular */ + }else { + fault_larb =F_MMU_INT_ID_COMM_ID (regval); + sub_comm =F_MMU_INT_ID_SUB_COMM_ID (regval); + } + }else { + fault_larb =F_MMU_INT_ID_LARB_ID (regval); + } - fault_larb = data->plat_data->larbid_remap[fault_larb]; + fault_larb = data->plat_data->larbid_remap[data->m4u_id][fault_larb];if (report_iommu_fault (&dom->domain, data->dev, fault_iova, write ?IOMMU_FAULT_WRITE :IOMMU_FAULT_READ )) {dev_err_ratelimited ( data->dev, -"fault type=0x%x iova=0x%x pa=0x%x larb=%d port=%d layer=%d %s\n" , - int_state, fault_iova, fault_pa, fault_larb, fault_port, +"fault type=0x%x iova=0x%x pa=0x%x larb=%d sub_comm=%d port=%d regval=0x%x layer=%d %s\n" , + int_state, fault_iova, fault_pa, fault_larb, + sub_comm, fault_port, regval, layer, write ?"write" :"read" ); }@@ -545,11 +574,12 @@ static int mtk_iommu_hw_init(const struct mtk_iommu_data *data)return ret; } + regval =readl_relaxed (data->base +REG_MMU_CTRL_REG );if (data->plat_data->m4u_plat ==M4U_MT8173 ) - regval =F_MMU_PREFETCH_RT_REPLACE_MOD | + regval |=F_MMU_PREFETCH_RT_REPLACE_MOD |F_MMU_TF_PROT_TO_PROGRAM_ADDR_MT8173 ;else - regval =F_MMU_TF_PROT_TO_PROGRAM_ADDR ; + regval |=F_MMU_TF_PROT_TO_PROGRAM_ADDR ;writel_relaxed (regval, data->base +REG_MMU_CTRL_REG ); regval = F_L2_MULIT_HIT_EN |@@ -589,6 +619,20 @@ static int mtk_iommu_hw_init(const struct mtk_iommu_data *data)if (data->plat_data->reset_axi)writel_relaxed (0 , data->base +REG_MMU_STANDARD_AXI_MODE ); +if (data->plat_data->has_wr_len) { +/* write command throttling mode */ + regval =readl_relaxed (data->base +REG_MMU_WR_LEN );drivers/iommu/mtk_iommu.c static int mtk_iommu_hw_init(const struct mtk_iommu_data *data) · line 634
Quoted 10 lines
drivers/iommu/mtk_iommu.c +10
-0+ regval &= ~F_MMU_WR_THROT_DIS ; +writel_relaxed (regval, data->base +REG_MMU_WR_LEN ); + } +/* special settings for mmu0 (multimedia iommu) */ +if (data->plat_data->has_misc_ctrl[data->m4u_id]) { + regval =readl_relaxed (data->base +REG_MMU_MISC_CRTL_MT6779 ); +/* non-standard AXI mode */ + regval &= ~REG_MMU_STANDARD_AXI_MODE_MT6779 ; +writel_relaxed (regval, data->base +REG_MMU_MISC_CRTL_MT6779 ); + }0x48 are REG_MMU_STANDARD_AXI_MODE in both mt8173 and mt8183, whileit is
REG_MMU_MISC_CRTLin mt2712, mt6779 and the latest soc, right? I think we can use one defining, like this:#define REG_MMU_MISC_CTRL 0x48 if (!data->plat_data->has_misc_ctrl[data->m4u_id]) { /* Disable standard axi mode while it is REG_MMU_STANDARD_AXI_MODE */ writel_relaxed(0, data->base + REG_MMU_MISC_CTRL); } else if (data->m4u_id == 0) { regval = readl_relaxed(data->base + REG_MMU_MISC_CTRL); regval &= ~REG_MMU_STANDARD_AXI_MODE_MT6779; writel_relaxed(regval, data->base + REG_MMU_MISC_CTRL); } Meanwhile remove the setting for REG_MMU_STANDARD_AXI_MODE above.Quoted 94 lines
drivers/iommu/mtk_iommu.c +25
-3+if (devm_request_irq (data->dev, data->irq, mtk_iommu_isr,0 ,dev_name (data->dev), (void *)data)) {writel_relaxed (0 , data->base +REG_MMU_PT_BASE_ADDR );@@ -678,6 +722,9 @@ static int mtk_iommu_probe(struct platform_device *pdev) } data->larb_imu[id].dev = &plarbdev->dev; +if (data->plat_data->m4u1_mask == (1 << id)) + data->m4u_id =1 ; +component_match_add_release (dev, &match, release_of, compare_of, larbnode); }@@ -731,6 +778,7 @@ static int __maybe_unused mtk_iommu_suspend(struct device *dev)struct mtk_iommu_suspend_reg *reg = &data->reg;void __iomem *base = data->base; + reg->wr_len =readl_relaxed (base +REG_MMU_WR_LEN ); reg->standard_axi_mode =readl_relaxed (base +REG_MMU_STANDARD_AXI_MODE ); reg->dcm_dis =readl_relaxed (base +REG_MMU_DCM_DIS );@@ -756,6 +804,7 @@ static int __maybe_unused mtk_iommu_resume(struct device *dev)dev_err (data->dev,"Failed to enable clk(%d) in resume\n" , ret);return ret; } +writel_relaxed (reg->wr_len, base +REG_MMU_WR_LEN );writel_relaxed (reg->standard_axi_mode, base +REG_MMU_STANDARD_AXI_MODE );writel_relaxed (reg->dcm_dis, base +REG_MMU_DCM_DIS );@@ -779,7 +828,20 @@ static const struct mtk_iommu_plat_data mt2712_data = { .has_4gb_mode = true, .has_bclk = true, .has_vld_pa_rng = true, - .larbid_remap = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, + .larbid_remap[0] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, + .inv_sel_reg = REG_MMU_INV_SEL, +}; + +static const struct mtk_iommu_plat_data mt6779_data = { + .m4u_plat =M4U_MT6779 , + .larbid_remap[0 ] = {0 ,1 ,2 ,3 ,5 ,7 ,10 ,9 }, +/* vp6a, vp6b, mdla/core2, mdla/edmc*/ + .larbid_remap[1 ] = {2 ,0 ,3 ,1 }, + .has_sub_comm = {true, true}, + .has_wr_len = true, + .has_misc_ctrl = {true, false}, + .inv_sel_reg =REG_MMU_INV_SEL_MT6779 , + .m4u1_mask =BIT (6 ), }; static const struct mtk_iommu_plat_data mt8173_data = {@@ -787,17 +849,20 @@ static const struct mtk_iommu_plat_data mt8173_data = { .has_4gb_mode = true, .has_bclk = true, .reset_axi = true, - .larbid_remap = {0, 1, 2, 3, 4, 5}, /* Linear mapping. */ + .larbid_remap[0] = {0, 1, 2, 3, 4, 5}, /* Linear mapping. */ + .inv_sel_reg = REG_MMU_INV_SEL, };static const struct mtk_iommu_plat_data mt8183_data = { .m4u_plat =M4U_MT8183 , .reset_axi = true, - .larbid_remap = {0 ,4 ,5 ,6 ,7 ,2 ,3 ,1 }, + .larbid_remap[0 ] = {0 ,4 ,5 ,6 ,7 ,2 ,3 ,1 }, + .inv_sel_reg =REG_MMU_INV_SEL , };static const struct of_device_id mtk_iommu_of_ids[] = { { .compatible ="mediatek,mt2712-m4u" , .data = &mt2712_data}, + { .compatible ="mediatek,mt6779-m4u" , .data = &mt6779_data}, { .compatible ="mediatek,mt8173-m4u" , .data = &mt8173_data}, { .compatible ="mediatek,mt8183-m4u" , .data = &mt8183_data}, {}drivers/iommu/mtk_iommu.h +2
-0@@ -25,11 +25,13 @@ struct mtk_iommu_suspend_reg {u32 int_main_control;u32 ivrp_paddr;u32 vld_pa_rng; +u32 wr_len; };enum mtk_iommu_plat {M4U_MT2701 ,M4U_MT2712 , +M4U_MT6779 ,M4U_MT8173 ,M4U_MT8183 , };drivers/iommu/mtk_iommu.h struct mtk_iommu_plat_data { · line 51
Quoted 9 lines
drivers/iommu/mtk_iommu.h +5
-1@@ -42,7 +44,12 @@ struct mtk_iommu_plat_data {bool has_bclk;bool has_vld_pa_rng;bool reset_axi; -unsigned char larbid_remap[MTK_LARB_NR_MAX ]; +bool has_sub_comm[2 ]; +bool has_wr_len; +bool has_misc_ctrl[2 ]; +u32 inv_sel_reg; +u32 m4u1_mask;alphabetically for the new ones.
drivers/iommu/mtk_iommu.h struct mtk_iommu_data { · line 71
Quoted 11 lines
drivers/iommu/mtk_iommu.h +2
-0+unsigned char larbid_remap[2 ][MTK_LARB_NR_MAX ]; };struct mtk_iommu_domain ;@@ -59,6 +66,7 @@ struct mtk_iommu_data {bool enable_4GB;spinlock_t tlb_lock;/* lock for tlb range flush */ +u32 m4u_id;struct iommu_device iommu;const struct mtk_iommu_plat_data *plat_data;Basically this patch looks ok for me. But please split it to several patches:
1) Extend
larbid_remapto larbid_remap[2].
Actually mt2712 also need this. this is the mt2712 definition. larbid_remap[0] = {0, 1, 2, 3},
larbid_remap[1] = {4, 5, 7, 8, 9},2) Regarding the 0x48(misc_ctrl register)
3) Add
m4u1_maskto distinguish them4u_id.4) Add
REG_MMU_WR_LENif you need.
Quoted 9 lines
5) Put
inv_sel_regin theplat_datafor preparing add0x2csupport in mt6779.6) Add new flow to get
SUB_COMMONID and VPU larbid in the translation fault.7) Add mt6779 support.
Quoted 1 line
ok, I will modify them for your above comments in next version, thanks
Quoted 3 lines
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH RESEND 3/13 iommu/mediatek: Add mtk_iommu_pgtable structure
In reply to Chao HaoStart with this patch, we will change the SW architecture to support multiple domains. SW architecture will has a big change, so we need to modify a little bit by more than one patch. The new SW overall architecture is as below:
iommu0 iommu1
| |
-----------
|
mtk_iommu_pgtable
|
------------------------------------------
| | |
mtk_iommu_domain1 mtk_iommu_domain2 mtk_iommu_domain3
| | |
iommu_group1 iommu_group2 iommu_group3
| | |
iommu_domain1 iommu_domain2 iommu_domain3
| | |
iova region1(normal) iova region2(CCU) iova region3(VPU)
For current structure, no matter how many iommus there are, they use the same page table to simplify the usage of module. In order to make the software architecture more explicit, this patch will create a global mtk_iommu_pgtable structure to describe page table and all the iommus use it.
The diagram is as below:
mtk_iommu_data1(MM) mtk_iommu_data2(APU) | | | | ------mtk_iommu_pgtable-----
We need to create global mtk_iommu_pgtable to include all the iova regions firstly and special iova regions by divided based on it, so the information of pgtable needs to be created in device_group.
--- drivers/iommu/mtk_iommu.c | 84 +++++++++++++++++++++++++++++++++++++++ drivers/iommu/mtk_iommu.h | 1 + 2 files changed, 85 insertions(+)
drivers/iommu/mtk_iommu.c +84 -0
@@ -123,6 +123,12 @@ struct mtk_iommu_domain {struct iommu_domain domain; }; +struct mtk_iommu_pgtable { +struct io_pgtable_cfg cfg; +struct io_pgtable_ops *iop; +}; + +static struct mtk_iommu_pgtable *share_pgtable;static const struct iommu_ops mtk_iommu_ops;/*
@@ -170,6 +176,11 @@ static struct mtk_iommu_data *mtk_iommu_get_m4u_data(void)return NULL ; } +static struct mtk_iommu_pgtable *mtk_iommu_get_pgtable (void ) +{ +return share_pgtable; +} +static struct mtk_iommu_domain *to_mtk_domain (struct iommu_domain *dom) { return container_of(dom, struct mtk_iommu_domain, domain);
@@ -322,6 +333,13 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom) { struct mtk_iommu_data *data = mtk_iommu_get_m4u_data(); + if (data->pgtable) { + dom->cfg = data->pgtable->cfg; + dom->iop = data->pgtable->iop; + dom->domain.pgsize_bitmap = data->pgtable->cfg.pgsize_bitmap; + return 0; + } + dom->cfg = (struct io_pgtable_cfg) { .quirks = IO_PGTABLE_QUIRK_ARM_NS | IO_PGTABLE_QUIRK_NO_PERMS |
@@ -345,6 +363,61 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom)return 0 ; } +static struct mtk_iommu_pgtable *create_pgtable (struct mtk_iommu_data *data) +{ +struct mtk_iommu_pgtable *pgtable; + + pgtable =kzalloc (sizeof (*pgtable),GFP_KERNEL ); +if (!pgtable) +return ERR_PTR (-ENOMEM ); + + pgtable->cfg = (struct io_pgtable_cfg ) { + .quirks =IO_PGTABLE_QUIRK_ARM_NS | +IO_PGTABLE_QUIRK_NO_PERMS | +IO_PGTABLE_QUIRK_TLBI_ON_MAP | +IO_PGTABLE_QUIRK_ARM_MTK_EXT , + .pgsize_bitmap = mtk_iommu_ops.pgsize_bitmap, + .ias =32 , + .oas =34 , + .tlb = &mtk_iommu_flush_ops, + .iommu_dev = data->dev, + }; + + pgtable->iop =alloc_io_pgtable_ops (ARM_V7S , &pgtable->cfg, data); +if (!pgtable->iop) { +dev_err (data->dev,"Failed to alloc io pgtable\n" ); +return ERR_PTR (-EINVAL ); + } + +dev_info (data->dev,"%s create pgtable done\n" , __func__); + +return pgtable; +} + +static int mtk_iommu_attach_pgtable (struct mtk_iommu_data *data, +struct device *dev) +{ +struct mtk_iommu_pgtable *pgtable =mtk_iommu_get_pgtable (); + +/* create share pgtable */ +if (!pgtable) { + pgtable =create_pgtable (data); +if (IS_ERR (pgtable)) { +dev_err (data->dev,"Failed to create pgtable\n" ); +return -ENOMEM ; + } + + share_pgtable = pgtable; + } + +/* binding to pgtable */ + data->pgtable = pgtable; + +dev_info (data->dev,"m4u%d attach_pgtable done!\n" , data->m4u_id); + +return 0 ; +} +static struct iommu_domain *mtk_iommu_domain_alloc (unsigned type) {struct mtk_iommu_domain *dom;
@@ -508,10 +581,21 @@ static void mtk_iommu_remove_device(struct device *dev)static struct iommu_group *mtk_iommu_device_group (struct device *dev) {struct mtk_iommu_data *data =mtk_iommu_get_m4u_data (); +struct mtk_iommu_pgtable *pgtable; +int ret =0 ;if (!data)return ERR_PTR (-ENODEV ); + pgtable = data->pgtable; +if (!pgtable) { + ret =mtk_iommu_attach_pgtable (data, dev); +if (ret) { +dev_err (data->dev,"Failed to device_group\n" ); +return NULL ; + } + } +/* All the client devices are in the same m4u iommu-group */ if (!data->m4u_group) { data->m4u_group =iommu_group_alloc ();
drivers/iommu/mtk_iommu.h +1 -0
@@ -61,6 +61,7 @@ struct mtk_iommu_data {struct clk *bclk;phys_addr_t protect_base;/* protect memory base */ struct mtk_iommu_suspend_reg reg; +struct mtk_iommu_pgtable *pgtable;struct mtk_iommu_domain *m4u_dom;struct iommu_group *m4u_group;bool enable_4GB;
Signature · 6 lines
2.18.0 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Yong Wu
maintainerRe: [RESEND,PATCH 03/13] iommu/mediatek: Add mtk_iommu_pgtable structure
Quoted 21 lines · Chao Hao
Start with this patch, we will change the SW architecture to support multiple domains. SW architecture will has a big change, so we need to modify a little bit by more than one patch. The new SW overall architecture is as below:
iommu0 iommu1
| |
-----------
|
mtk_iommu_pgtable
|
------------------------------------------
| | |
mtk_iommu_domain1mtk_iommu_domain2mtk_iommu_domain3
| | |
iommu_group1iommu_group2iommu_group3
| | |
iommu_domain1iommu_domain2iommu_domain3
| | |
iova region1(normal) iova region2(CCU) iova region3(VPU)
Quoted 5 lines
For current structure, no matter how many iommus there are, they use the same page table to simplify the usage of module. In order to make the software architecture more explicit, this patch will create a global
mtk_iommu_pgtablestructure to describe page table and all the iommus use it.
Thanks for the hard work of this file. Actually this patch and the later ones confuse me. Why do you make this flow change?
for making the code "more explicit" or for adding multi-domain support in 13/13.
IMHO, the change is unnecessary.
a) For me, this change has no improvement. currently we use a global mtk_iommu_get_m4u_data to get the M4U data. I will be very glad if you could get rid of it. But in this patchset, You use a another global mtk_iommu_pgtable to instead. For me. It has no improvement.
b) This patchset break the original flow. device_group give you a software chance for initializing, then you move pagetable allocating code into it. But it isn't device_group job.
I can not decide if your flow is right. But if you only want to add support multi-domain, I guess you could extend the current "m4u_group" to a array "m4u_group[N]". It may be more simple. To make mt6779 progress easily, I suggest you can use this way to support multi-domain firstly. Then you could send this new mtk_iommu_pgtable patchset for the code "more explicit" if you insist.
Quoted 156 lines
The diagram is as below:
mtk_iommu_data1(MM) mtk_iommu_data2(APU) | | | | ------mtk_iommu_pgtable-----We need to create global
mtk_iommu_pgtableto include all the iova regions firstly and special iova regions by divided based on it, so the information of pgtable needs to be created indevice_group.Signed-off-by Chao Hao <[email protected]>--- drivers/iommu/mtk_iommu.c | 84 +++++++++++++++++++++++++++++++++++++++ drivers/iommu/mtk_iommu.h | 1 + 2 files changed, 85 insertions(+)drivers/iommu/mtk_iommu.c +84
-0@@ -123,6 +123,12 @@ struct mtk_iommu_domain {struct iommu_domain domain; }; +struct mtk_iommu_pgtable { +struct io_pgtable_cfg cfg; +struct io_pgtable_ops *iop; +}; + +static struct mtk_iommu_pgtable *share_pgtable;static const struct iommu_ops mtk_iommu_ops;/* @@ -170,6 +176,11 @@ static struct mtk_iommu_data *mtk_iommu_get_m4u_data(void)return NULL ; } +static struct mtk_iommu_pgtable *mtk_iommu_get_pgtable (void ) +{ +return share_pgtable; +} +static struct mtk_iommu_domain *to_mtk_domain (struct iommu_domain *dom) { return container_of(dom, struct mtk_iommu_domain, domain);@@ -322,6 +333,13 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom) { struct mtk_iommu_data *data = mtk_iommu_get_m4u_data(); + if (data->pgtable) { + dom->cfg = data->pgtable->cfg; + dom->iop = data->pgtable->iop; + dom->domain.pgsize_bitmap = data->pgtable->cfg.pgsize_bitmap; + return 0; + } + dom->cfg = (struct io_pgtable_cfg) { .quirks = IO_PGTABLE_QUIRK_ARM_NS | IO_PGTABLE_QUIRK_NO_PERMS |@@ -345,6 +363,61 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom)return 0 ; } +static struct mtk_iommu_pgtable *create_pgtable (struct mtk_iommu_data *data) +{ +struct mtk_iommu_pgtable *pgtable; + + pgtable =kzalloc (sizeof (*pgtable),GFP_KERNEL ); +if (!pgtable) +return ERR_PTR (-ENOMEM ); + + pgtable->cfg = (struct io_pgtable_cfg ) { + .quirks =IO_PGTABLE_QUIRK_ARM_NS | +IO_PGTABLE_QUIRK_NO_PERMS | +IO_PGTABLE_QUIRK_TLBI_ON_MAP | +IO_PGTABLE_QUIRK_ARM_MTK_EXT , + .pgsize_bitmap = mtk_iommu_ops.pgsize_bitmap, + .ias =32 , + .oas =34 , + .tlb = &mtk_iommu_flush_ops, + .iommu_dev = data->dev, + }; + + pgtable->iop =alloc_io_pgtable_ops (ARM_V7S , &pgtable->cfg, data); +if (!pgtable->iop) { +dev_err (data->dev,"Failed to alloc io pgtable\n" ); +return ERR_PTR (-EINVAL ); + } + +dev_info (data->dev,"%s create pgtable done\n" , __func__); + +return pgtable; +} + +static int mtk_iommu_attach_pgtable (struct mtk_iommu_data *data, +struct device *dev) +{ +struct mtk_iommu_pgtable *pgtable =mtk_iommu_get_pgtable (); + +/* create share pgtable */ +if (!pgtable) { + pgtable =create_pgtable (data); +if (IS_ERR (pgtable)) { +dev_err (data->dev,"Failed to create pgtable\n" ); +return -ENOMEM ; + } + + share_pgtable = pgtable; + } + +/* binding to pgtable */ + data->pgtable = pgtable; + +dev_info (data->dev,"m4u%d attach_pgtable done!\n" , data->m4u_id); + +return 0 ; +} +static struct iommu_domain *mtk_iommu_domain_alloc (unsigned type) {struct mtk_iommu_domain *dom;@@ -508,10 +581,21 @@ static void mtk_iommu_remove_device(struct device *dev)static struct iommu_group *mtk_iommu_device_group (struct device *dev) {struct mtk_iommu_data *data =mtk_iommu_get_m4u_data (); +struct mtk_iommu_pgtable *pgtable; +int ret =0 ;if (!data)return ERR_PTR (-ENODEV ); + pgtable = data->pgtable; +if (!pgtable) { + ret =mtk_iommu_attach_pgtable (data, dev); +if (ret) { +dev_err (data->dev,"Failed to device_group\n" ); +return NULL ; + } + } +/* All the client devices are in the same m4u iommu-group */ if (!data->m4u_group) { data->m4u_group =iommu_group_alloc ();drivers/iommu/mtk_iommu.h +1
-0@@ -61,6 +61,7 @@ struct mtk_iommu_data {struct clk *bclk;phys_addr_t protect_base;/* protect memory base */ struct mtk_iommu_suspend_reg reg; +struct mtk_iommu_pgtable *pgtable;struct mtk_iommu_domain *m4u_dom;struct iommu_group *m4u_group;bool enable_4GB;
Re: [RESEND,PATCH 03/13] iommu/mediatek: Add mtk_iommu_pgtable structure
Quoted 33 lines · Yong Wu
Quoted 21 lines · Chao Hao
Start with this patch, we will change the SW architecture to support multiple domains. SW architecture will has a big change, so we need to modify a little bit by more than one patch. The new SW overall architecture is as below:
iommu0 iommu1
| |
-----------
|
mtk_iommu_pgtable
|
------------------------------------------
| | |
mtk_iommu_domain1mtk_iommu_domain2mtk_iommu_domain3
| | |
iommu_group1iommu_group2iommu_group3
| | |
iommu_domain1iommu_domain2iommu_domain3
| | |
iova region1(normal) iova region2(CCU) iova region3(VPU)Quoted 5 lines
For current structure, no matter how many iommus there are, they use the same page table to simplify the usage of module. In order to make the software architecture more explicit, this patch will create a global
mtk_iommu_pgtablestructure to describe page table and all the iommus use it.Thanks for the hard work of this file. Actually this patch and the later ones confuse me. Why do you make this flow change?
for making the code "more explicit" or for adding multi-domain support in 13/13.
Quoted 5 lines
IMHO, the change is unnecessary.
a) For me, this change has no improvement. currently we use a globalmtk_iommu_get_m4u_datato get the M4U data. I will be very glad if you could get rid of it. But in this patchset, You use a another globalmtk_iommu_pgtableto instead. For me. It has no improvement.
Thanks for you advice!
For current SW arch, all the IOMMU HW use the same page table, we can use a global mtk_iommu_pgtable to discribe the information of page table and all the IOMMU attach it, I think that it is more clear and unambiguous. For beginners, it maybe more easily explicable?
Quoted 5 lines
b) This patchset break the original flow.
device_groupgive you a software chance for initializing, then you move pagetable allocating code into it. But it isn'tdevice_groupjob.
As is shown above diagram, mtk_iommu_pgtable includes iommu_group and iommu_domain,so we need to allocate mtk_iommu_pgtable and initialize it in device_group firstly,and then execute the original flow, it only changes place for creating mtk_iommu_pgtable and don't break original device_group flow.
Quoted 155 lines
I can not decide if your flow is right. But if you only want to add support multi-domain, I guess you could extend the current "
m4u_group" to a array "m4u_group[N]". It may be more simple. To make mt6779 progress easily, I suggest you can use this way to support multi-domain firstly. Then you could send this newmtk_iommu_pgtablepatchset for the code "more explicit" if you insist.Quoted 148 lines
The diagram is as below:
mtk_iommu_data1(MM) mtk_iommu_data2(APU) | | | | ------mtk_iommu_pgtable-----We need to create global
mtk_iommu_pgtableto include all the iova regions firstly and special iova regions by divided based on it, so the information of pgtable needs to be created indevice_group.Signed-off-by Chao Hao <[email protected]>--- drivers/iommu/mtk_iommu.c | 84 +++++++++++++++++++++++++++++++++++++++ drivers/iommu/mtk_iommu.h | 1 + 2 files changed, 85 insertions(+)drivers/iommu/mtk_iommu.c +84
-0@@ -123,6 +123,12 @@ struct mtk_iommu_domain {struct iommu_domain domain; }; +struct mtk_iommu_pgtable { +struct io_pgtable_cfg cfg; +struct io_pgtable_ops *iop; +}; + +static struct mtk_iommu_pgtable *share_pgtable;static const struct iommu_ops mtk_iommu_ops;/* @@ -170,6 +176,11 @@ static struct mtk_iommu_data *mtk_iommu_get_m4u_data(void)return NULL ; } +static struct mtk_iommu_pgtable *mtk_iommu_get_pgtable (void ) +{ +return share_pgtable; +} +static struct mtk_iommu_domain *to_mtk_domain (struct iommu_domain *dom) { return container_of(dom, struct mtk_iommu_domain, domain);@@ -322,6 +333,13 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom) { struct mtk_iommu_data *data = mtk_iommu_get_m4u_data(); + if (data->pgtable) { + dom->cfg = data->pgtable->cfg; + dom->iop = data->pgtable->iop; + dom->domain.pgsize_bitmap = data->pgtable->cfg.pgsize_bitmap; + return 0; + } + dom->cfg = (struct io_pgtable_cfg) { .quirks = IO_PGTABLE_QUIRK_ARM_NS | IO_PGTABLE_QUIRK_NO_PERMS |@@ -345,6 +363,61 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom)return 0 ; } +static struct mtk_iommu_pgtable *create_pgtable (struct mtk_iommu_data *data) +{ +struct mtk_iommu_pgtable *pgtable; + + pgtable =kzalloc (sizeof (*pgtable),GFP_KERNEL ); +if (!pgtable) +return ERR_PTR (-ENOMEM ); + + pgtable->cfg = (struct io_pgtable_cfg ) { + .quirks =IO_PGTABLE_QUIRK_ARM_NS | +IO_PGTABLE_QUIRK_NO_PERMS | +IO_PGTABLE_QUIRK_TLBI_ON_MAP | +IO_PGTABLE_QUIRK_ARM_MTK_EXT , + .pgsize_bitmap = mtk_iommu_ops.pgsize_bitmap, + .ias =32 , + .oas =34 , + .tlb = &mtk_iommu_flush_ops, + .iommu_dev = data->dev, + }; + + pgtable->iop =alloc_io_pgtable_ops (ARM_V7S , &pgtable->cfg, data); +if (!pgtable->iop) { +dev_err (data->dev,"Failed to alloc io pgtable\n" ); +return ERR_PTR (-EINVAL ); + } + +dev_info (data->dev,"%s create pgtable done\n" , __func__); + +return pgtable; +} + +static int mtk_iommu_attach_pgtable (struct mtk_iommu_data *data, +struct device *dev) +{ +struct mtk_iommu_pgtable *pgtable =mtk_iommu_get_pgtable (); + +/* create share pgtable */ +if (!pgtable) { + pgtable =create_pgtable (data); +if (IS_ERR (pgtable)) { +dev_err (data->dev,"Failed to create pgtable\n" ); +return -ENOMEM ; + } + + share_pgtable = pgtable; + } + +/* binding to pgtable */ + data->pgtable = pgtable; + +dev_info (data->dev,"m4u%d attach_pgtable done!\n" , data->m4u_id); + +return 0 ; +} +static struct iommu_domain *mtk_iommu_domain_alloc (unsigned type) {struct mtk_iommu_domain *dom;@@ -508,10 +581,21 @@ static void mtk_iommu_remove_device(struct device *dev)static struct iommu_group *mtk_iommu_device_group (struct device *dev) {struct mtk_iommu_data *data =mtk_iommu_get_m4u_data (); +struct mtk_iommu_pgtable *pgtable; +int ret =0 ;if (!data)return ERR_PTR (-ENODEV ); + pgtable = data->pgtable; +if (!pgtable) { + ret =mtk_iommu_attach_pgtable (data, dev); +if (ret) { +dev_err (data->dev,"Failed to device_group\n" ); +return NULL ; + } + } +/* All the client devices are in the same m4u iommu-group */ if (!data->m4u_group) { data->m4u_group =iommu_group_alloc ();drivers/iommu/mtk_iommu.h +0
-0
Quoted 10 lines
drivers/iommu/mtk_iommu.h struct mtk_iommu_data { · line 67
Quoted 8 lines
drivers/iommu/mtk_iommu.h +1
-0@@ -61,6 +61,7 @@ struct mtk_iommu_data {struct clk *bclk;phys_addr_t protect_base;/* protect memory base */ struct mtk_iommu_suspend_reg reg; +struct mtk_iommu_pgtable *pgtable;struct mtk_iommu_domain *m4u_dom;struct iommu_group *m4u_group;bool enable_4GB;
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Yong Wu
maintainerRe: [RESEND,PATCH 03/13] iommu/mediatek: Add mtk_iommu_pgtable structure
Quoted 40 lines · chao hao
Quoted 33 lines · Yong Wu
Quoted 21 lines · Chao Hao
Start with this patch, we will change the SW architecture to support multiple domains. SW architecture will has a big change, so we need to modify a little bit by more than one patch. The new SW overall architecture is as below:
iommu0 iommu1
| |
-----------
|
mtk_iommu_pgtable
|
------------------------------------------
| | |
mtk_iommu_domain1mtk_iommu_domain2mtk_iommu_domain3
| | |
iommu_group1iommu_group2iommu_group3
| | |
iommu_domain1iommu_domain2iommu_domain3
| | |
iova region1(normal) iova region2(CCU) iova region3(VPU)Quoted 5 lines
For current structure, no matter how many iommus there are, they use the same page table to simplify the usage of module. In order to make the software architecture more explicit, this patch will create a global
mtk_iommu_pgtablestructure to describe page table and all the iommus use it.Thanks for the hard work of this file. Actually this patch and the later ones confuse me. Why do you make this flow change?
for making the code "more explicit" or for adding multi-domain support in 13/13.Quoted 5 lines
IMHO, the change is unnecessary.
a) For me, this change has no improvement. currently we use a globalmtk_iommu_get_m4u_datato get the M4U data. I will be very glad if you could get rid of it. But in this patchset, You use a another globalmtk_iommu_pgtableto instead. For me. It has no improvement.
Quoted 4 lines
Thanks for you advice!
For current SW arch, all the IOMMU HW use the same page table, we can use a global
mtk_iommu_pgtableto discribe the information of page table
What's your plan if the 4GB iova range is not enough for us in future? Do you plan to add a new global mtk_iommu_pgtable again?
Quoted 2 lines
and all the IOMMU attach it, I think that it is more clear and unambiguous. For beginners, it maybe more easily explicable?
I still don't get the necessity of this change. it is only for making code clear from your point for view, right?
This code has been reviewed for many years, I don't know why you think it is ambiguous. it is clear for me at lease. and I will complain that you add a new global variable in this change.
Quoted 11 lines
Quoted 5 lines
b) This patchset break the original flow.
device_groupgive you a software chance for initializing, then you move pagetable allocating code into it. But it isn'tdevice_groupjob.As is shown above diagram,
mtk_iommu_pgtableincludesiommu_groupand iommu_domain,so we need to allocatemtk_iommu_pgtableand initialize it indevice_groupfirstly,and then execute the original flow, it only changes place for creatingmtk_iommu_pgtableand don't break originaldevice_groupflow.
I understand you have to do this change after you adjust the structure. I mean that it may be not proper since allocating pagetable should not be done in device_group logically. From here, Could we get this change looks not good?.
Quoted 6 lines
Quoted 6 lines
I can not decide if your flow is right. But if you only want to add support multi-domain, I guess you could extend the current "
m4u_group" to a array "m4u_group[N]". It may be more simple. To make mt6779 progress easily, I suggest you can use this way to support multi-domain firstly. Then you could send this newmtk_iommu_pgtablepatchset for the code "more explicit" if you insist.
Could you help try this way if it could meet your requirement? Then let's compare which one is better.
BTW, your patches(including v2) cause hangup as below since "data->m4u_dom" was uninitialized.
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000010 ... pc : mtk_iommu_tlb_flush_page_nosync+0x38/0xb8 lr : __arm_v7s_unmap+0x174/0x598 ... Call trace: mtk_iommu_tlb_flush_page_nosync+0x38/0xb8 __arm_v7s_unmap+0x174/0x598 arm_v7s_unmap+0x30/0x48 mtk_iommu_unmap+0x20/0x28 __iommu_unmap+0xa4/0xf8 iommu_unmap+0x44/0x90
Quoted 161 lines
Quoted 159 lines
Quoted 157 lines
The diagram is as below:
mtk_iommu_data1(MM) mtk_iommu_data2(APU) | | | | ------mtk_iommu_pgtable-----We need to create global
mtk_iommu_pgtableto include all the iova regions firstly and special iova regions by divided based on it, so the information of pgtable needs to be created indevice_group.Signed-off-by Chao Hao <[email protected]>--- drivers/iommu/mtk_iommu.c | 84 +++++++++++++++++++++++++++++++++++++++ drivers/iommu/mtk_iommu.h | 1 + 2 files changed, 85 insertions(+)drivers/iommu/mtk_iommu.c +84
-0@@ -123,6 +123,12 @@ struct mtk_iommu_domain {struct iommu_domain domain; }; +struct mtk_iommu_pgtable { +struct io_pgtable_cfg cfg; +struct io_pgtable_ops *iop; +}; + +static struct mtk_iommu_pgtable *share_pgtable;static const struct iommu_ops mtk_iommu_ops;/* @@ -170,6 +176,11 @@ static struct mtk_iommu_data *mtk_iommu_get_m4u_data(void)return NULL ; } +static struct mtk_iommu_pgtable *mtk_iommu_get_pgtable (void ) +{ +return share_pgtable; +} +static struct mtk_iommu_domain *to_mtk_domain (struct iommu_domain *dom) { return container_of(dom, struct mtk_iommu_domain, domain);@@ -322,6 +333,13 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom) { struct mtk_iommu_data *data = mtk_iommu_get_m4u_data(); + if (data->pgtable) { + dom->cfg = data->pgtable->cfg; + dom->iop = data->pgtable->iop; + dom->domain.pgsize_bitmap = data->pgtable->cfg.pgsize_bitmap; + return 0; + } + dom->cfg = (struct io_pgtable_cfg) { .quirks = IO_PGTABLE_QUIRK_ARM_NS | IO_PGTABLE_QUIRK_NO_PERMS |@@ -345,6 +363,61 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom)return 0 ; } +static struct mtk_iommu_pgtable *create_pgtable (struct mtk_iommu_data *data) +{ +struct mtk_iommu_pgtable *pgtable; + + pgtable =kzalloc (sizeof (*pgtable),GFP_KERNEL ); +if (!pgtable) +return ERR_PTR (-ENOMEM ); + + pgtable->cfg = (struct io_pgtable_cfg ) { + .quirks =IO_PGTABLE_QUIRK_ARM_NS | +IO_PGTABLE_QUIRK_NO_PERMS | +IO_PGTABLE_QUIRK_TLBI_ON_MAP | +IO_PGTABLE_QUIRK_ARM_MTK_EXT , + .pgsize_bitmap = mtk_iommu_ops.pgsize_bitmap, + .ias =32 , + .oas =34 , + .tlb = &mtk_iommu_flush_ops, + .iommu_dev = data->dev, + }; + + pgtable->iop =alloc_io_pgtable_ops (ARM_V7S , &pgtable->cfg, data); +if (!pgtable->iop) { +dev_err (data->dev,"Failed to alloc io pgtable\n" ); +return ERR_PTR (-EINVAL ); + } + +dev_info (data->dev,"%s create pgtable done\n" , __func__); + +return pgtable; +} + +static int mtk_iommu_attach_pgtable (struct mtk_iommu_data *data, +struct device *dev) +{ +struct mtk_iommu_pgtable *pgtable =mtk_iommu_get_pgtable (); + +/* create share pgtable */ +if (!pgtable) { + pgtable =create_pgtable (data); +if (IS_ERR (pgtable)) { +dev_err (data->dev,"Failed to create pgtable\n" ); +return -ENOMEM ; + } + + share_pgtable = pgtable; + } + +/* binding to pgtable */ + data->pgtable = pgtable; + +dev_info (data->dev,"m4u%d attach_pgtable done!\n" , data->m4u_id); + +return 0 ; +} +static struct iommu_domain *mtk_iommu_domain_alloc (unsigned type) {struct mtk_iommu_domain *dom;@@ -508,10 +581,21 @@ static void mtk_iommu_remove_device(struct device *dev)static struct iommu_group *mtk_iommu_device_group (struct device *dev) {struct mtk_iommu_data *data =mtk_iommu_get_m4u_data (); +struct mtk_iommu_pgtable *pgtable; +int ret =0 ;if (!data)return ERR_PTR (-ENODEV ); + pgtable = data->pgtable; +if (!pgtable) { + ret =mtk_iommu_attach_pgtable (data, dev); +if (ret) { +dev_err (data->dev,"Failed to device_group\n" ); +return NULL ; + } + } +/* All the client devices are in the same m4u iommu-group */ if (!data->m4u_group) { data->m4u_group =iommu_group_alloc ();drivers/iommu/mtk_iommu.h +1
-0@@ -61,6 +61,7 @@ struct mtk_iommu_data {struct clk *bclk;phys_addr_t protect_base;/* protect memory base */ struct mtk_iommu_suspend_reg reg; +struct mtk_iommu_pgtable *pgtable;struct mtk_iommu_domain *m4u_dom;struct iommu_group *m4u_group;bool enable_4GB;
Re: [RESEND,PATCH 03/13] iommu/mediatek: Add mtk_iommu_pgtable structure
Quoted 41 lines · Yong Wu
Quoted 40 lines · chao hao
Quoted 38 lines · Yong Wu
Quoted 21 lines · Chao Hao
Start with this patch, we will change the SW architecture to support multiple domains. SW architecture will has a big change, so we need to modify a little bit by more than one patch. The new SW overall architecture is as below:
iommu0 iommu1
| |
-----------
|
mtk_iommu_pgtable
|
------------------------------------------
| | |
mtk_iommu_domain1mtk_iommu_domain2mtk_iommu_domain3
| | |
iommu_group1iommu_group2iommu_group3
| | |
iommu_domain1iommu_domain2iommu_domain3
| | |
iova region1(normal) iova region2(CCU) iova region3(VPU)Quoted 5 lines
For current structure, no matter how many iommus there are, they use the same page table to simplify the usage of module. In order to make the software architecture more explicit, this patch will create a global
mtk_iommu_pgtablestructure to describe page table and all the iommus use it.Thanks for the hard work of this file. Actually this patch and the later ones confuse me. Why do you make this flow change?
for making the code "more explicit" or for adding multi-domain support in 13/13.IMHO, the change is unnecessary.
a) For me, this change has no improvement. currently we use a globalmtk_iommu_get_m4u_datato get the M4U data. I will be very glad if you could get rid of it. But in this patchset, You use a another globalmtk_iommu_pgtableto instead. For me. It has no improvement.
Quoted 8 lines
Quoted 4 lines
Thanks for you advice!
For current SW arch, all the IOMMU HW use the same page table, we can use a global
mtk_iommu_pgtableto discribe the information of page tableWhat's your plan if the 4GB iova range is not enough for us in future? Do you plan to add a new global
mtk_iommu_pgtableagain?
if the 4GB iova range is not enough, we only need to modify mtk_domain_data structure: min_iova and max_iova, Compare with current SW arch:
dom->domain.geometry.aperture_start = 0; dom->domain.geometry.aperture_end = DMA_BIT_MASK(32);
==>
dom->domain.geometry.aperture_start = pgtable->dom_region->min_iova; dom->domain.geometry.aperture_end = pgtable->dom_region->max_iova;
struct mtk_domain_data {
dma_addr_t min_iova;
dma_addr_t max_iova;};
Quoted 22 lines
Quoted 2 lines
and all the IOMMU attach it, I think that it is more clear and unambiguous. For beginners, it maybe more easily explicable?
I still don't get the necessity of this change. it is only for making code clear from your point for view, right?
This code has been reviewed for many years, I don't know why you think it is ambiguous. it is clear for me at lease. and I will complain that you add a new global variable in this change.
Quoted 11 lines
Quoted 5 lines
b) This patchset break the original flow.
device_groupgive you a software chance for initializing, then you move pagetable allocating code into it. But it isn'tdevice_groupjob.As is shown above diagram,
mtk_iommu_pgtableincludesiommu_groupand iommu_domain,so we need to allocatemtk_iommu_pgtableand initialize it indevice_groupfirstly,and then execute the original flow, it only changes place for creatingmtk_iommu_pgtableand don't break originaldevice_groupflow.
Quoted 5 lines
I understand you have to do this change after you adjust the structure. I mean that it may be not proper since allocating pagetable should not be done in
device_grouplogically. From here, Could we get this change looks not good?.
gentle ping ...
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
I can not decide if your flow is right. But if you only want to add support multi-domain, I guess you could extend the current "
m4u_group" to a array "m4u_group[N]". It may be more simple. To make mt6779 progress easily, I suggest you can use this way to support multi-domain firstly. Then you could send this newmtk_iommu_pgtablepatchset for the code "more explicit" if you insist.Could you help try this way if it could meet your requirement? Then let's compare which one is better.
BTW, your patches(including v2) cause hangup as below since "
data->m4u_dom" was uninitialized.
Quoted 14 lines
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000010 ... pc : mtk_iommu_tlb_flush_page_nosync+0x38/0xb8 lr : __arm_v7s_unmap+0x174/0x598 ... Call trace: mtk_iommu_tlb_flush_page_nosync+0x38/0xb8 __arm_v7s_unmap+0x174/0x598 arm_v7s_unmap+0x30/0x48 mtk_iommu_unmap+0x20/0x28 __iommu_unmap+0xa4/0xf8 iommu_unmap+0x44/0x90
yes, you are right. I will modify it in next version, thanks
Quoted 153 lines
Quoted 153 lines
Quoted 153 lines
Quoted 153 lines
The diagram is as below:
mtk_iommu_data1(MM) mtk_iommu_data2(APU) | | | | ------mtk_iommu_pgtable-----We need to create global
mtk_iommu_pgtableto include all the iova regions firstly and special iova regions by divided based on it, so the information of pgtable needs to be created indevice_group.Signed-off-by Chao Hao <[email protected]>--- drivers/iommu/mtk_iommu.c | 84 +++++++++++++++++++++++++++++++++++++++ drivers/iommu/mtk_iommu.h | 1 + 2 files changed, 85 insertions(+)drivers/iommu/mtk_iommu.c +84
-0@@ -123,6 +123,12 @@ struct mtk_iommu_domain {struct iommu_domain domain; }; +struct mtk_iommu_pgtable { +struct io_pgtable_cfg cfg; +struct io_pgtable_ops *iop; +}; + +static struct mtk_iommu_pgtable *share_pgtable;static const struct iommu_ops mtk_iommu_ops;/* @@ -170,6 +176,11 @@ static struct mtk_iommu_data *mtk_iommu_get_m4u_data(void)return NULL ; } +static struct mtk_iommu_pgtable *mtk_iommu_get_pgtable (void ) +{ +return share_pgtable; +} +static struct mtk_iommu_domain *to_mtk_domain (struct iommu_domain *dom) { return container_of(dom, struct mtk_iommu_domain, domain);@@ -322,6 +333,13 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom) { struct mtk_iommu_data *data = mtk_iommu_get_m4u_data(); + if (data->pgtable) { + dom->cfg = data->pgtable->cfg; + dom->iop = data->pgtable->iop; + dom->domain.pgsize_bitmap = data->pgtable->cfg.pgsize_bitmap; + return 0; + } + dom->cfg = (struct io_pgtable_cfg) { .quirks = IO_PGTABLE_QUIRK_ARM_NS | IO_PGTABLE_QUIRK_NO_PERMS |@@ -345,6 +363,61 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom)return 0 ; } +static struct mtk_iommu_pgtable *create_pgtable (struct mtk_iommu_data *data) +{ +struct mtk_iommu_pgtable *pgtable; + + pgtable =kzalloc (sizeof (*pgtable),GFP_KERNEL ); +if (!pgtable) +return ERR_PTR (-ENOMEM ); + + pgtable->cfg = (struct io_pgtable_cfg ) { + .quirks =IO_PGTABLE_QUIRK_ARM_NS | +IO_PGTABLE_QUIRK_NO_PERMS | +IO_PGTABLE_QUIRK_TLBI_ON_MAP | +IO_PGTABLE_QUIRK_ARM_MTK_EXT , + .pgsize_bitmap = mtk_iommu_ops.pgsize_bitmap, + .ias =32 , + .oas =34 , + .tlb = &mtk_iommu_flush_ops, + .iommu_dev = data->dev, + }; + + pgtable->iop =alloc_io_pgtable_ops (ARM_V7S , &pgtable->cfg, data); +if (!pgtable->iop) { +dev_err (data->dev,"Failed to alloc io pgtable\n" ); +return ERR_PTR (-EINVAL ); + } + +dev_info (data->dev,"%s create pgtable done\n" , __func__); + +return pgtable; +} + +static int mtk_iommu_attach_pgtable (struct mtk_iommu_data *data, +struct device *dev) +{ +struct mtk_iommu_pgtable *pgtable =mtk_iommu_get_pgtable (); + +/* create share pgtable */ +if (!pgtable) { + pgtable =create_pgtable (data); +if (IS_ERR (pgtable)) { +dev_err (data->dev,"Failed to create pgtable\n" ); +return -ENOMEM ; + } + + share_pgtable = pgtable; + } + +/* binding to pgtable */ + data->pgtable = pgtable; + +dev_info (data->dev,"m4u%d attach_pgtable done!\n" , data->m4u_id); + +return 0 ; +} +static struct iommu_domain *mtk_iommu_domain_alloc (unsigned type) {struct mtk_iommu_domain *dom;@@ -508,10 +581,21 @@ static void mtk_iommu_remove_device(struct device *dev)static struct iommu_group *mtk_iommu_device_group (struct device *dev) {struct mtk_iommu_data *data =mtk_iommu_get_m4u_data (); +struct mtk_iommu_pgtable *pgtable; +int ret =0 ;if (!data)return ERR_PTR (-ENODEV ); + pgtable = data->pgtable; +if (!pgtable) { + ret =mtk_iommu_attach_pgtable (data, dev); +if (ret) { +dev_err (data->dev,"Failed to device_group\n" ); +return NULL ; + } + } +/* All the client devices are in the same m4u iommu-group */ if (!data->m4u_group) { data->m4u_group =iommu_group_alloc ();drivers/iommu/mtk_iommu.h +0
-0@@ -61,6 +61,7 @@ struct mtk_iommu_data {struct clk *bclk;phys_addr_t protect_base;/* protect memory base */ struct mtk_iommu_suspend_reg reg;
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
drivers/iommu/mtk_iommu.h struct mtk_iommu_data { · line 67
Quoted 4 lines
drivers/iommu/mtk_iommu.h +1
-0+struct mtk_iommu_pgtable *pgtable;struct mtk_iommu_domain *m4u_dom;struct iommu_group *m4u_group;bool enable_4GB;
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [RESEND,PATCH 03/13] iommu/mediatek: Add mtk_iommu_pgtable structure
In reply to Yong WuQuoted 71 lines · Yong Wu
Quoted 40 lines · chao hao
Quoted 33 lines · Yong Wu
Quoted 21 lines · Chao Hao
Start with this patch, we will change the SW architecture to support multiple domains. SW architecture will has a big change, so we need to modify a little bit by more than one patch. The new SW overall architecture is as below:
iommu0 iommu1
| |
-----------
|
mtk_iommu_pgtable
|
------------------------------------------
| | |
mtk_iommu_domain1mtk_iommu_domain2mtk_iommu_domain3
| | |
iommu_group1iommu_group2iommu_group3
| | |
iommu_domain1iommu_domain2iommu_domain3
| | |
iova region1(normal) iova region2(CCU) iova region3(VPU)Quoted 5 lines
For current structure, no matter how many iommus there are, they use the same page table to simplify the usage of module. In order to make the software architecture more explicit, this patch will create a global
mtk_iommu_pgtablestructure to describe page table and all the iommus use it.Thanks for the hard work of this file. Actually this patch and the later ones confuse me. Why do you make this flow change?
for making the code "more explicit" or for adding multi-domain support in 13/13.Quoted 5 lines
IMHO, the change is unnecessary.
a) For me, this change has no improvement. currently we use a globalmtk_iommu_get_m4u_datato get the M4U data. I will be very glad if you could get rid of it. But in this patchset, You use a another globalmtk_iommu_pgtableto instead. For me. It has no improvement.Quoted 4 lines
Thanks for you advice!
For current SW arch, all the IOMMU HW use the same page table, we can use a global
mtk_iommu_pgtableto discribe the information of page tableWhat's your plan if the 4GB iova range is not enough for us in future? Do you plan to add a new global
mtk_iommu_pgtableagain?Quoted 2 lines
and all the IOMMU attach it, I think that it is more clear and unambiguous. For beginners, it maybe more easily explicable?
I still don't get the necessity of this change. it is only for making code clear from your point for view, right?
This code has been reviewed for many years, I don't know why you think it is ambiguous. it is clear for me at lease. and I will complain that you add a new global variable in this change.
Quoted 11 lines
Quoted 5 lines
b) This patchset break the original flow.
device_groupgive you a software chance for initializing, then you move pagetable allocating code into it. But it isn'tdevice_groupjob.As is shown above diagram,
mtk_iommu_pgtableincludesiommu_groupand iommu_domain,so we need to allocatemtk_iommu_pgtableand initialize it indevice_groupfirstly,and then execute the original flow, it only changes place for creatingmtk_iommu_pgtableand don't break originaldevice_groupflow.
Quoted 5 lines
I understand you have to do this change after you adjust the structure. I mean that it may be not proper since allocating pagetable should not be done in
device_grouplogically. From here, Could we get this change looks not good?.
gentle ping ...
Dear Matthias and Joerg,
From mt6779 platform, mtk_iommu.c needs to support multiple domains for different iova regions.About the change, there are some disagreements among our internal. We hope to get your helps and advices:
Based on current SW architecture to support multiple domain, diagram is as below:
iommu0 iommu1
| |
----------
|
------------------------------------------
| | |
iommu_group1 iommu_group2 iommu_group3
| | |
mtk_iommu_domain1 mtk_iommu_domain2 mtk_iommu_domain3
| | |
iova region1(normal) iova region2(CCU) iova region3(VPU)
PS: the information of page table is included struct mtk_iommu_domain
In my opinion, if all the iommus share the same page table(include all iova regions) and different iova regions are created based on the page table, we can put the information of page table to a global structure(mtk_iommu_pgtable) and all the iommus attach it. It maybe make the SW architecture look clearly.
New SW architecture diagram is as below(This patchset is based on it):
iommu0 iommu1
| |
----------
|
mtk_iommu_pgtable
|
------------------------------------------
| | |
mtk_iommu_domain1 mtk_iommu_domain2 mtk_iommu_domain3
| | |
iommu_group1 iommu_group2 iommu_group3
| | |
iommu_domain1 iommu_domain2 iommu_domain3
| | |
iova region1(normal) iova region2(CCU) iova region3(VPU)
From above new SW architecture, we will create a global page table firstly(mtk_iommu_pgtable), and all the iommus can use it. The page table can include 4GB iova space, different iova regions are created based on it, so the information of pgtable needs to be created in device_group.
I have two problems to consult you, can you provide some advices? Thanks for Matthias and Joerg so much!
(1) I don't understand if the pgtable can be created in device_group ?
(2) In addition, can you help to review which SW architecture are more reasonable or whether it is necessary to change current SW architecture to support multiple domain ?
Dear Yong,
If I described ambiguously, please help to add extra explanation. Thanks a lot.
Quoted 192 lines
Quoted 6 lines
Quoted 6 lines
I can not decide if your flow is right. But if you only want to add support multi-domain, I guess you could extend the current "
m4u_group" to a array "m4u_group[N]". It may be more simple. To make mt6779 progress easily, I suggest you can use this way to support multi-domain firstly. Then you could send this newmtk_iommu_pgtablepatchset for the code "more explicit" if you insist.Could you help try this way if it could meet your requirement? Then let's compare which one is better.
BTW, your patches(including v2) cause hangup as below since "
data->m4u_dom" was uninitialized.Unable to handle kernel NULL pointer dereference at virtual address 0000000000000010 ... pc : mtk_iommu_tlb_flush_page_nosync+0x38/0xb8 lr : __arm_v7s_unmap+0x174/0x598 ... Call trace: mtk_iommu_tlb_flush_page_nosync+0x38/0xb8 __arm_v7s_unmap+0x174/0x598 arm_v7s_unmap+0x30/0x48 mtk_iommu_unmap+0x20/0x28 __iommu_unmap+0xa4/0xf8 iommu_unmap+0x44/0x90Quoted 161 lines
Quoted 159 lines
Quoted 157 lines
The diagram is as below:
mtk_iommu_data1(MM) mtk_iommu_data2(APU) | | | | ------mtk_iommu_pgtable-----We need to create global
mtk_iommu_pgtableto include all the iova regions firstly and special iova regions by divided based on it, so the information of pgtable needs to be created indevice_group.Signed-off-by Chao Hao <[email protected]>--- drivers/iommu/mtk_iommu.c | 84 +++++++++++++++++++++++++++++++++++++++ drivers/iommu/mtk_iommu.h | 1 + 2 files changed, 85 insertions(+)drivers/iommu/mtk_iommu.c +84
-0@@ -123,6 +123,12 @@ struct mtk_iommu_domain {struct iommu_domain domain; }; +struct mtk_iommu_pgtable { +struct io_pgtable_cfg cfg; +struct io_pgtable_ops *iop; +}; + +static struct mtk_iommu_pgtable *share_pgtable;static const struct iommu_ops mtk_iommu_ops;/* @@ -170,6 +176,11 @@ static struct mtk_iommu_data *mtk_iommu_get_m4u_data(void)return NULL ; } +static struct mtk_iommu_pgtable *mtk_iommu_get_pgtable (void ) +{ +return share_pgtable; +} +static struct mtk_iommu_domain *to_mtk_domain (struct iommu_domain *dom) { return container_of(dom, struct mtk_iommu_domain, domain);@@ -322,6 +333,13 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom) { struct mtk_iommu_data *data = mtk_iommu_get_m4u_data(); + if (data->pgtable) { + dom->cfg = data->pgtable->cfg; + dom->iop = data->pgtable->iop; + dom->domain.pgsize_bitmap = data->pgtable->cfg.pgsize_bitmap; + return 0; + } + dom->cfg = (struct io_pgtable_cfg) { .quirks = IO_PGTABLE_QUIRK_ARM_NS | IO_PGTABLE_QUIRK_NO_PERMS |@@ -345,6 +363,61 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom)return 0 ; } +static struct mtk_iommu_pgtable *create_pgtable (struct mtk_iommu_data *data) +{ +struct mtk_iommu_pgtable *pgtable; + + pgtable =kzalloc (sizeof (*pgtable),GFP_KERNEL ); +if (!pgtable) +return ERR_PTR (-ENOMEM ); + + pgtable->cfg = (struct io_pgtable_cfg ) { + .quirks =IO_PGTABLE_QUIRK_ARM_NS | +IO_PGTABLE_QUIRK_NO_PERMS | +IO_PGTABLE_QUIRK_TLBI_ON_MAP | +IO_PGTABLE_QUIRK_ARM_MTK_EXT , + .pgsize_bitmap = mtk_iommu_ops.pgsize_bitmap, + .ias =32 , + .oas =34 , + .tlb = &mtk_iommu_flush_ops, + .iommu_dev = data->dev, + }; + + pgtable->iop =alloc_io_pgtable_ops (ARM_V7S , &pgtable->cfg, data); +if (!pgtable->iop) { +dev_err (data->dev,"Failed to alloc io pgtable\n" ); +return ERR_PTR (-EINVAL ); + } + +dev_info (data->dev,"%s create pgtable done\n" , __func__); + +return pgtable; +} + +static int mtk_iommu_attach_pgtable (struct mtk_iommu_data *data, +struct device *dev) +{ +struct mtk_iommu_pgtable *pgtable =mtk_iommu_get_pgtable (); + +/* create share pgtable */ +if (!pgtable) { + pgtable =create_pgtable (data); +if (IS_ERR (pgtable)) { +dev_err (data->dev,"Failed to create pgtable\n" ); +return -ENOMEM ; + } + + share_pgtable = pgtable; + } + +/* binding to pgtable */ + data->pgtable = pgtable; + +dev_info (data->dev,"m4u%d attach_pgtable done!\n" , data->m4u_id); + +return 0 ; +} +static struct iommu_domain *mtk_iommu_domain_alloc (unsigned type) {struct mtk_iommu_domain *dom;@@ -508,10 +581,21 @@ static void mtk_iommu_remove_device(struct device *dev)static struct iommu_group *mtk_iommu_device_group (struct device *dev) {struct mtk_iommu_data *data =mtk_iommu_get_m4u_data (); +struct mtk_iommu_pgtable *pgtable; +int ret =0 ;if (!data)return ERR_PTR (-ENODEV ); + pgtable = data->pgtable; +if (!pgtable) { + ret =mtk_iommu_attach_pgtable (data, dev); +if (ret) { +dev_err (data->dev,"Failed to device_group\n" ); +return NULL ; + } + } +/* All the client devices are in the same m4u iommu-group */ if (!data->m4u_group) { data->m4u_group =iommu_group_alloc ();drivers/iommu/mtk_iommu.h +1
-0@@ -61,6 +61,7 @@ struct mtk_iommu_data {struct clk *bclk;phys_addr_t protect_base;/* protect memory base */ struct mtk_iommu_suspend_reg reg; +struct mtk_iommu_pgtable *pgtable;struct mtk_iommu_domain *m4u_dom;struct iommu_group *m4u_group;bool enable_4GB;
PATCH RESEND 4/13 iommu/mediatek: Remove mtk_iommu_domain_finalise
In reply to Chao HaoWe already have global mtk_iommu_pgtable structure to describe page table and create it in group_device, "mtk_iommu_domain_finalise" is as the same as that, so so we will remove mtk_iommu_domain_finalise.
--- drivers/iommu/mtk_iommu.c | 48 ++++++++------------------------------- 1 file changed, 10 insertions(+), 38 deletions(-)
drivers/iommu/mtk_iommu.c +10 -38
@@ -329,40 +329,6 @@ static void mtk_iommu_config(struct mtk_iommu_data *data, } } -static int mtk_iommu_domain_finalise (struct mtk_iommu_domain *dom) -{ -struct mtk_iommu_data *data =mtk_iommu_get_m4u_data (); - -if (data->pgtable) { - dom->cfg = data->pgtable->cfg; - dom->iop = data->pgtable->iop; - dom->domain.pgsize_bitmap = data->pgtable->cfg.pgsize_bitmap; -return 0 ; - } - - dom->cfg = (struct io_pgtable_cfg ) { - .quirks =IO_PGTABLE_QUIRK_ARM_NS | -IO_PGTABLE_QUIRK_NO_PERMS | -IO_PGTABLE_QUIRK_TLBI_ON_MAP | -IO_PGTABLE_QUIRK_ARM_MTK_EXT , - .pgsize_bitmap = mtk_iommu_ops.pgsize_bitmap, - .ias =32 , - .oas =34 , - .tlb = &mtk_iommu_flush_ops, - .iommu_dev = data->dev, - }; - - dom->iop =alloc_io_pgtable_ops (ARM_V7S , &dom->cfg, data); -if (!dom->iop) { -dev_err (data->dev,"Failed to alloc io pgtable\n" ); -return -EINVAL ; - } - -/* Update our support page sizes bitmap */ - dom->domain.pgsize_bitmap = dom->cfg.pgsize_bitmap; -return 0 ; -} -static struct mtk_iommu_pgtable *create_pgtable (struct mtk_iommu_data *data) {struct mtk_iommu_pgtable *pgtable;
@@ -420,11 +386,17 @@ static int mtk_iommu_attach_pgtable(struct mtk_iommu_data *data,static struct iommu_domain *mtk_iommu_domain_alloc (unsigned type) { +struct mtk_iommu_pgtable *pgtable =mtk_iommu_get_pgtable ();struct mtk_iommu_domain *dom;if (type !=IOMMU_DOMAIN_DMA )return NULL ; +if (!pgtable) { +pr_err ("%s, pgtable is not ready\n" , __func__); +return NULL ; + } + dom =kzalloc (sizeof (*dom),GFP_KERNEL );if (!dom)return NULL ;
@@ -432,8 +404,10 @@ static struct iommu_domain *mtk_iommu_domain_alloc(unsigned type)if (iommu_get_dma_cookie (&dom->domain)) goto free_dom; -if (mtk_iommu_domain_finalise (dom)) - goto put_dma_cookie; + dom->cfg = pgtable->cfg; + dom->iop = pgtable->iop; +/* Update our support page sizes bitmap */ + dom->domain.pgsize_bitmap = pgtable->cfg.pgsize_bitmap; dom->domain.geometry.aperture_start =0 ; dom->domain.geometry.aperture_end =DMA_BIT_MASK (32 );
@@ -441,8 +415,6 @@ static struct iommu_domain *mtk_iommu_domain_alloc(unsigned type)return &dom->domain; -put_dma_cookie: -iommu_put_dma_cookie (&dom->domain); free_dom:kfree (dom);return NULL ;
Signature · 6 lines
2.18.0 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH RESEND 5/13 iommu/mediatek: Remove pgtable info in mtk_iommu_domain
In reply to Chao HaoThis patch will use mtk_iommu_pgtable to replace the part of pgtable in mtk_iommu_domain, so we can remove the information of pgtable in mtk_iommu_domain.
--- drivers/iommu/mtk_iommu.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-)
drivers/iommu/mtk_iommu.c +17 -20
@@ -117,9 +117,6 @@#define MTK_M4U_TO_PORT (id) ((id) & 0x1f)struct mtk_iommu_domain { -struct io_pgtable_cfg cfg; -struct io_pgtable_ops *iop; -struct iommu_domain domain; };
@@ -379,6 +376,10 @@ static int mtk_iommu_attach_pgtable(struct mtk_iommu_data *data,/* binding to pgtable */ data->pgtable = pgtable; +/* update HW settings */ +writel (pgtable->cfg.arm_v7s_cfg.ttbr[0 ] &MMU_PT_ADDR_MASK , + data->base +REG_MMU_PT_BASE_ADDR ); +dev_info (data->dev,"m4u%d attach_pgtable done!\n" , data->m4u_id);return 0 ;
@@ -404,8 +405,6 @@ static struct iommu_domain *mtk_iommu_domain_alloc(unsigned type)if (iommu_get_dma_cookie (&dom->domain)) goto free_dom; - dom->cfg = pgtable->cfg; - dom->iop = pgtable->iop;/* Update our support page sizes bitmap */ dom->domain.pgsize_bitmap = pgtable->cfg.pgsize_bitmap;
@@ -422,11 +421,12 @@ static struct iommu_domain *mtk_iommu_domain_alloc(unsigned type)static void mtk_iommu_domain_free (struct iommu_domain *domain) { -struct mtk_iommu_domain *dom =to_mtk_domain (domain); +struct mtk_iommu_pgtable *pgtable =mtk_iommu_get_pgtable (); -free_io_pgtable_ops (dom->iop);iommu_put_dma_cookie (domain);kfree (to_mtk_domain (domain)); +free_io_pgtable_ops (pgtable->iop); +kfree (pgtable); } static int mtk_iommu_attach_device(struct iommu_domain *domain,
@@ -439,11 +439,8 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain,return -ENODEV ;/* Update the pgtable base address register of the M4U HW */ -if (!data->m4u_dom) { +if (!data->m4u_dom) data->m4u_dom = dom; -writel (dom->cfg.arm_v7s_cfg.ttbr[0 ] &MMU_PT_ADDR_MASK , - data->base +REG_MMU_PT_BASE_ADDR ); - }mtk_iommu_config (data, dev, true);return 0 ;
@@ -463,7 +460,7 @@ static void mtk_iommu_detach_device(struct iommu_domain *domain,static int mtk_iommu_map (struct iommu_domain *domain,unsigned long iova,phys_addr_t paddr,size_t size,int prot) { -struct mtk_iommu_domain *dom =to_mtk_domain (domain); +struct mtk_iommu_pgtable *pgtable =mtk_iommu_get_pgtable ();struct mtk_iommu_data *data =mtk_iommu_get_m4u_data ();/* The "4GB mode" M4U physically can not use the lower remap of Dram. */
@@ -471,16 +468,16 @@ static int mtk_iommu_map(struct iommu_domain *domain, unsigned long iova, paddr |=BIT_ULL (32 );/* Synchronize with the tlb_lock */ -return dom->iop->map (dom->iop, iova, paddr, size, prot); +return pgtable->iop->map (pgtable->iop, iova, paddr, size, prot); }static size_t mtk_iommu_unmap (struct iommu_domain *domain,unsigned long iova,size_t size,struct iommu_iotlb_gather *gather) { -struct mtk_iommu_domain *dom =to_mtk_domain (domain); +struct mtk_iommu_pgtable *pgtable =mtk_iommu_get_pgtable (); -return dom->iop->unmap (dom->iop, iova, size, gather); +return pgtable->iop->unmap (pgtable->iop, iova, size, gather); }static void mtk_iommu_flush_iotlb_all (struct iommu_domain *domain)
@@ -504,11 +501,11 @@ static void mtk_iommu_iotlb_sync(struct iommu_domain *domain,static phys_addr_t mtk_iommu_iova_to_phys (struct iommu_domain *domain,dma_addr_t iova) { -struct mtk_iommu_domain *dom =to_mtk_domain (domain); +struct mtk_iommu_pgtable *pgtable =mtk_iommu_get_pgtable ();struct mtk_iommu_data *data =mtk_iommu_get_m4u_data ();phys_addr_t pa; - pa = dom->iop->iova_to_phys (dom->iop, iova); + pa = pgtable->iop->iova_to_phys (pgtable->iop, iova);if (data->enable_4GB && pa >=MTK_IOMMU_4GB_MODE_REMAP_BASE ) pa &= ~BIT_ULL (32 );
@@ -850,8 +847,8 @@ static int __maybe_unused mtk_iommu_suspend(struct device *dev)static int __maybe_unused mtk_iommu_resume (struct device *dev) {struct mtk_iommu_data *data =dev_get_drvdata (dev); +struct mtk_iommu_pgtable *pgtable = data->pgtable;struct mtk_iommu_suspend_reg *reg = &data->reg; -struct mtk_iommu_domain *m4u_dom = data->m4u_dom;void __iomem *base = data->base;int ret;
@@ -869,8 +866,8 @@ static int __maybe_unused mtk_iommu_resume(struct device *dev)writel_relaxed (reg->int_main_control, base +REG_MMU_INT_MAIN_CONTROL );writel_relaxed (reg->ivrp_paddr, base +REG_MMU_IVRP_PADDR );writel_relaxed (reg->vld_pa_rng, base +REG_MMU_VLD_PA_RNG ); -if (m4u_dom) -writel (m4u_dom->cfg.arm_v7s_cfg.ttbr[0 ] &MMU_PT_ADDR_MASK , +if (pgtable) +writel (pgtable->cfg.arm_v7s_cfg.ttbr[0 ] &MMU_PT_ADDR_MASK , base +REG_MMU_PT_BASE_ADDR );return 0 ; }
Signature · 6 lines
2.18.0 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH RESEND 6/13 iommu/mediatek: Change get the way of m4u_group
In reply to Chao Hao1. Redefine mtk_iommu_domain structure, it will include iommu_group and iommu_domain. Different mtk_iommu_domains can be distinguished by ID. When we realize multiple mtk_iommu_domains, every mtk_iommu_domain can describe one iova region.
2. In theory, every device has one iommu_group, so this patch will get iommu_group by checking device. All the devices belong to the same m4u_group currently, so they also use the same mtk_iommu_domain(id=0).
--- drivers/iommu/mtk_iommu.c | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
drivers/iommu/mtk_iommu.c +46 -0
@@ -117,12 +117,16 @@#define MTK_M4U_TO_PORT (id) ((id) & 0x1f)struct mtk_iommu_domain { +u32 id;struct iommu_domain domain; +struct iommu_group *group; +struct list_head list; };struct mtk_iommu_pgtable {struct io_pgtable_cfg cfg;struct io_pgtable_ops *iop; +struct list_head m4u_dom_v2; };static struct mtk_iommu_pgtable *share_pgtable;
@@ -173,6 +177,41 @@ static struct mtk_iommu_data *mtk_iommu_get_m4u_data(void)return NULL ; } +static u32 get_domain_id (void ) +{ +/* only support one mtk_iommu_domain currently */ +return 0 ; +} + +static u32 mtk_iommu_get_domain_id (void ) +{ +return get_domain_id (); +} + +static struct mtk_iommu_domain *get_mtk_domain (struct device *dev) +{ +struct mtk_iommu_data *data = dev->iommu_fwspec->iommu_priv; +struct mtk_iommu_domain *dom; +u32 domain_id =mtk_iommu_get_domain_id (); + +list_for_each_entry (dom, &data->pgtable->m4u_dom_v2, list) { +if (dom->id == domain_id) +return dom; + } +return NULL ; +} + +static struct iommu_group *mtk_iommu_get_group (struct device *dev) +{ +struct mtk_iommu_domain *dom; + + dom =get_mtk_domain (dev); +if (dom) +return dom->group; + +return NULL ; +} +static struct mtk_iommu_pgtable *mtk_iommu_get_pgtable (void ) {return share_pgtable;
@@ -334,6 +373,8 @@ static struct mtk_iommu_pgtable *create_pgtable(struct mtk_iommu_data *data)if (!pgtable)return ERR_PTR (-ENOMEM ); +INIT_LIST_HEAD (&pgtable->m4u_dom_v2); + pgtable->cfg = (struct io_pgtable_cfg ) { .quirks =IO_PGTABLE_QUIRK_ARM_NS | IO_PGTABLE_QUIRK_NO_PERMS |
@@ -388,6 +429,7 @@ static int mtk_iommu_attach_pgtable(struct mtk_iommu_data *data,static struct iommu_domain *mtk_iommu_domain_alloc (unsigned type) {struct mtk_iommu_pgtable *pgtable =mtk_iommu_get_pgtable (); +struct mtk_iommu_data *data =mtk_iommu_get_m4u_data ();struct mtk_iommu_domain *dom;if (type !=IOMMU_DOMAIN_DMA )
@@ -405,12 +447,15 @@ static struct iommu_domain *mtk_iommu_domain_alloc(unsigned type)if (iommu_get_dma_cookie (&dom->domain)) goto free_dom; + dom->group = data->m4u_group; + dom->id =mtk_iommu_get_domain_id ();/* Update our support page sizes bitmap */ dom->domain.pgsize_bitmap = pgtable->cfg.pgsize_bitmap; dom->domain.geometry.aperture_start =0 ; dom->domain.geometry.aperture_end =DMA_BIT_MASK (32 ); dom->domain.geometry.force_aperture = true; +list_add_tail (&dom->list, &pgtable->m4u_dom_v2);return &dom->domain;
@@ -566,6 +611,7 @@ static struct iommu_group *mtk_iommu_device_group(struct device *dev) }/* All the client devices are in the same m4u iommu-group */ + data->m4u_group =mtk_iommu_get_group (dev);if (!data->m4u_group) { data->m4u_group =iommu_group_alloc ();if (IS_ERR (data->m4u_group))
Signature · 1 line
2.18.0
PATCH RESEND 7/13 iommu/mediatek: Add smi_larb info about device
In reply to Chao HaoAll the devices which used iommu are connected to SMI_larb port, so when different devices driver execute initialization, iommu can check larb_id and port_id to distinguish them and then make them match to iommu_group accordingly. We also add dom_cnt variable to describe the number of mtk_iommu_domain.
Larb_id and port_id define can refer to "mtxxxx-larb-port.h(ex:mt6779-larb-port.h)" file
--- drivers/iommu/mtk_iommu.c | 50 ++++++++++++++++++++++++++++++++------- drivers/iommu/mtk_iommu.h | 1 + 2 files changed, 43 insertions(+), 8 deletions(-)
drivers/iommu/mtk_iommu.c +42 -8
@@ -126,6 +126,7 @@ struct mtk_iommu_domain {struct mtk_iommu_pgtable {struct io_pgtable_cfg cfg;struct io_pgtable_ops *iop; +struct device *init_dev;struct list_head m4u_dom_v2; };
@@ -177,22 +178,35 @@ static struct mtk_iommu_data *mtk_iommu_get_m4u_data(void)return NULL ; } -static u32 get_domain_id (void ) +static u32 get_domain_id (struct mtk_iommu_data *data,u32 portid) { -/* only support one mtk_iommu_domain currently */ -return 0 ; +u32 dom_id =0 ; +int i; + +/* only support one mtk_iommu_domain currently(dom_cnt = 1) */ +for (i =0 ; i < data->plat_data->dom_cnt; i++) +return i; + +return dom_id; } -static u32 mtk_iommu_get_domain_id (void ) +static u32 mtk_iommu_get_domain_id (struct device *dev) { -return get_domain_id (); +struct iommu_fwspec *fwspec = dev->iommu_fwspec; +struct mtk_iommu_data *data = dev->iommu_fwspec->iommu_priv; +u32 portid = fwspec->ids[0 ]; + +return get_domain_id (data, portid); }static struct mtk_iommu_domain *get_mtk_domain (struct device *dev) {struct mtk_iommu_data *data = dev->iommu_fwspec->iommu_priv;struct mtk_iommu_domain *dom; -u32 domain_id =mtk_iommu_get_domain_id (); +u32 domain_id =mtk_iommu_get_domain_id (dev); + +if (domain_id >= data->plat_data->dom_cnt) +return NULL ;list_for_each_entry (dom, &data->pgtable->m4u_dom_v2, list) {if (dom->id == domain_id)
@@ -431,11 +445,18 @@ static struct iommu_domain *mtk_iommu_domain_alloc(unsigned type)struct mtk_iommu_pgtable *pgtable =mtk_iommu_get_pgtable ();struct mtk_iommu_data *data =mtk_iommu_get_m4u_data ();struct mtk_iommu_domain *dom; +struct device *dev;if (type !=IOMMU_DOMAIN_DMA )return NULL ; -if (!pgtable) { +if (pgtable) { + dev = pgtable->init_dev; +if (!data->m4u_group) { +pr_err ("%s, find m4u_group failed\n" , __func__); +return NULL ; + } + }else {pr_err ("%s, pgtable is not ready\n" , __func__);return NULL ; }
@@ -447,8 +468,11 @@ static struct iommu_domain *mtk_iommu_domain_alloc(unsigned type)if (iommu_get_dma_cookie (&dom->domain)) goto free_dom; + dom->id =mtk_iommu_get_domain_id (dev); +if (dom->id >= data->plat_data->dom_cnt) + goto put_dma_cookie; + dom->group = data->m4u_group; - dom->id =mtk_iommu_get_domain_id ();/* Update our support page sizes bitmap */ dom->domain.pgsize_bitmap = pgtable->cfg.pgsize_bitmap;
@@ -459,6 +483,8 @@ static struct iommu_domain *mtk_iommu_domain_alloc(unsigned type)return &dom->domain; +put_dma_cookie: +iommu_put_dma_cookie (&dom->domain); free_dom:kfree (dom);return NULL ;
@@ -619,6 +645,10 @@ static struct iommu_group *mtk_iommu_device_group(struct device *dev) }else {iommu_group_ref_get (data->m4u_group); } + +/* save the latest init device */ + pgtable->init_dev = dev; +return data->m4u_group; }
@@ -927,12 +957,14 @@ static const struct mtk_iommu_plat_data mt2712_data = { .has_4gb_mode = true, .has_bclk = true, .has_vld_pa_rng = true, + .dom_cnt = 1, .larbid_remap[0] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, .inv_sel_reg = REG_MMU_INV_SEL, };static const struct mtk_iommu_plat_data mt6779_data = { .m4u_plat =M4U_MT6779 , + .dom_cnt =1 , .larbid_remap[0 ] = {0 ,1 ,2 ,3 ,5 ,7 ,10 ,9 },/* vp6a, vp6b, mdla/core2, mdla/edmc*/ .larbid_remap[1] = {2, 0, 3, 1},
@@ -948,6 +980,7 @@ static const struct mtk_iommu_plat_data mt8173_data = { .has_4gb_mode = true, .has_bclk = true, .reset_axi = true, + .dom_cnt = 1, .larbid_remap[0] = {0, 1, 2, 3, 4, 5}, /* Linear mapping. */ .inv_sel_reg = REG_MMU_INV_SEL, };
@@ -955,6 +988,7 @@ static const struct mtk_iommu_plat_data mt8173_data = {static const struct mtk_iommu_plat_data mt8183_data = { .m4u_plat =M4U_MT8183 , .reset_axi = true, + .dom_cnt =1 , .larbid_remap[0 ] = {0 ,4 ,5 ,6 ,7 ,2 ,3 ,1 }, .inv_sel_reg =REG_MMU_INV_SEL , };
drivers/iommu/mtk_iommu.h +1 -0
@@ -49,6 +49,7 @@ struct mtk_iommu_plat_data {bool has_misc_ctrl[2 ];u32 inv_sel_reg;u32 m4u1_mask; +u32 dom_cnt;unsigned char larbid_remap[2 ][MTK_LARB_NR_MAX ]; };
Signature · 6 lines
2.18.0 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH RESEND 8/13 iommu/mediatek: Add mtk_domain_data structure
In reply to Chao HaoAdd mtk_domain_data structure to describe how many iova regions there are and the relevant the start and end address of each iova region. The number of iova region is equal to the number of mtk_iommu_domain. So we will use mtk_domain_data to initialize the start and end iova of mtk_iommu_domain.
--- drivers/iommu/mtk_iommu.c | 17 +++++++++++++++-- drivers/iommu/mtk_iommu.h | 17 +++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-)
drivers/iommu/mtk_iommu.c +15 -2
@@ -128,6 +128,12 @@ struct mtk_iommu_pgtable {struct io_pgtable_ops *iop;struct device *init_dev;struct list_head m4u_dom_v2; +const struct mtk_domain_data *dom_region; +}; + +const struct mtk_domain_data single_dom = { + .min_iova =0x0 , + .max_iova =DMA_BIT_MASK (32 ) };static struct mtk_iommu_pgtable *share_pgtable;
@@ -406,6 +412,7 @@ static struct mtk_iommu_pgtable *create_pgtable(struct mtk_iommu_data *data)dev_err (data->dev,"Failed to alloc io pgtable\n" );return ERR_PTR (-EINVAL ); } + pgtable->dom_region = data->plat_data->dom_data;dev_info (data->dev,"%s create pgtable done\n" , __func__);
@@ -476,8 +483,10 @@ static struct iommu_domain *mtk_iommu_domain_alloc(unsigned type)/* Update our support page sizes bitmap */ dom->domain.pgsize_bitmap = pgtable->cfg.pgsize_bitmap; - dom->domain.geometry.aperture_start =0 ; - dom->domain.geometry.aperture_end =DMA_BIT_MASK (32 ); + dom->domain.geometry.aperture_start = + pgtable->dom_region->min_iova; + dom->domain.geometry.aperture_end = + pgtable->dom_region->max_iova; dom->domain.geometry.force_aperture = true;list_add_tail (&dom->list, &pgtable->m4u_dom_v2);
@@ -958,6 +967,7 @@ static const struct mtk_iommu_plat_data mt2712_data = { .has_bclk = true, .has_vld_pa_rng = true, .dom_cnt = 1, + .dom_data = &single_dom, .larbid_remap[0] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, .inv_sel_reg = REG_MMU_INV_SEL, };
@@ -965,6 +975,7 @@ static const struct mtk_iommu_plat_data mt2712_data = {static const struct mtk_iommu_plat_data mt6779_data = { .m4u_plat =M4U_MT6779 , .dom_cnt =1 , + .dom_data = &single_dom, .larbid_remap[0 ] = {0 ,1 ,2 ,3 ,5 ,7 ,10 ,9 },/* vp6a, vp6b, mdla/core2, mdla/edmc*/ .larbid_remap[1 ] = {2 ,0 ,3 ,1 },
@@ -981,6 +992,7 @@ static const struct mtk_iommu_plat_data mt8173_data = { .has_bclk = true, .reset_axi = true, .dom_cnt = 1, + .dom_data = &single_dom, .larbid_remap[0] = {0, 1, 2, 3, 4, 5}, /* Linear mapping. */ .inv_sel_reg = REG_MMU_INV_SEL, };
@@ -989,6 +1001,7 @@ static const struct mtk_iommu_plat_data mt8183_data = { .m4u_plat = M4U_MT8183, .reset_axi = true, .dom_cnt = 1, + .dom_data = &single_dom, .larbid_remap[0] = {0, 4, 5, 6, 7, 2, 3, 1}, .inv_sel_reg = REG_MMU_INV_SEL, };
drivers/iommu/mtk_iommu.h +17 -0
@@ -36,6 +36,22 @@ enum mtk_iommu_plat { M4U_MT8183, }; +/* +* reserved IOVA Domain for IOMMU users of HW limitation. +*/ + +/* +* struct mtk_domain_data: domain configuration +* @min_iova: Start address of iova +* @max_iova: End address of iova +* Note: one user can only belong to one domain +*/ + +struct mtk_domain_data { +dma_addr_t min_iova; +dma_addr_t max_iova; +}; +struct mtk_iommu_plat_data {enum mtk_iommu_plat m4u_plat;bool has_4gb_mode;
@@ -51,6 +67,7 @@ struct mtk_iommu_plat_data {u32 m4u1_mask;u32 dom_cnt;unsigned char larbid_remap[2 ][MTK_LARB_NR_MAX ]; +const struct mtk_domain_data *dom_data; };struct mtk_iommu_domain ;
Signature · 1 line
2.18.0
PATCH RESEND 9/13 iommu/mediatek: Remove the usage of m4u_dom variable
In reply to Chao HaoThis patch will remove the usage of the m4u_dom variable.
We have already redefined mtk_iommu_domain structure and it includes iommu_domain, so m4u_dom variable will not be used.
--- drivers/iommu/mtk_iommu.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-)
drivers/iommu/mtk_iommu.c +20 -7
@@ -113,6 +113,7 @@* Get the local arbiter ID and the portid within the larb arbiter * from mtk_m4u_id which is defined by MTK_M4U_ID. */ +#define MTK_M4U_ID (larb, port) (((larb) << 5) | (port))#define MTK_M4U_TO_LARB (id) (((id) >> 5) & 0xf)#define MTK_M4U_TO_PORT (id) ((id) & 0x1f)
@@ -205,6 +206,22 @@ static u32 mtk_iommu_get_domain_id(struct device *dev)return get_domain_id (data, portid); } +static struct iommu_domain *_get_mtk_domain (struct mtk_iommu_data *data, +u32 larbid,u32 portid) +{ +u32 domain_id; +u32 port_mask =MTK_M4U_ID (larbid, portid); +struct mtk_iommu_domain *dom; + + domain_id =get_domain_id (data, port_mask); + +list_for_each_entry (dom, &data->pgtable->m4u_dom_v2, list) { +if (dom->id == domain_id) +return &dom->domain; + } +return NULL ; +} +static struct mtk_iommu_domain *get_mtk_domain (struct device *dev) {struct mtk_iommu_data *data = dev->iommu_fwspec->iommu_priv;
@@ -307,7 +324,7 @@ static const struct iommu_flush_ops mtk_iommu_flush_ops = {static irqreturn_t mtk_iommu_isr (int irq,void *dev_id) {struct mtk_iommu_data *data = dev_id; -struct mtk_iommu_domain *dom = data->m4u_dom; +struct iommu_domain *domain;u32 int_state, regval, fault_iova, fault_pa;unsigned int fault_larb, fault_port, sub_comm =0 ;bool layer, write;
@@ -342,7 +359,8 @@ static irqreturn_t mtk_iommu_isr(int irq, void *dev_id) fault_larb = data->plat_data->larbid_remap[data->m4u_id][fault_larb]; -if (report_iommu_fault (&dom->domain, data->dev, fault_iova, + domain =_get_mtk_domain (data, fault_larb, fault_port); +if (report_iommu_fault (domain, data->dev, fault_iova, write ?IOMMU_FAULT_WRITE :IOMMU_FAULT_READ )) { dev_err_ratelimited( data->dev,
@@ -512,16 +530,11 @@ static void mtk_iommu_domain_free(struct iommu_domain *domain)static int mtk_iommu_attach_device (struct iommu_domain *domain,struct device *dev) { -struct mtk_iommu_domain *dom =to_mtk_domain (domain);struct mtk_iommu_data *data =dev_iommu_fwspec_get (dev)->iommu_priv;if (!data)return -ENODEV ; -/* Update the pgtable base address register of the M4U HW */ -if (!data->m4u_dom) - data->m4u_dom = dom; -mtk_iommu_config (data, dev, true);return 0 ; }
Signature · 1 line
2.18.0
PATCH RESEND 10/13 iommu/mediatek: Remove mtk_iommu_get_m4u_data api
In reply to Chao HaoBased on previous modifications in the patchset, A mtk_iommu_data structure represent a iommu, we will add mtk_iommu_data to mtk_iommu_domain to show the iommu which mtk_iommu_domain belongs to, so we can get mtk_iommu_data by mtk_iommu_domain, don't use to "mtk_iommu_get_m4u_data" any more.
Besides, there is a small SW adjustment, we will move alloc iommu_group into "create_iommu_group"
--- drivers/iommu/mtk_iommu.c | 74 +++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 37 deletions(-)
drivers/iommu/mtk_iommu.c +37 -37
@@ -121,6 +121,7 @@ struct mtk_iommu_domain {u32 id;struct iommu_domain domain;struct iommu_group *group; +struct mtk_iommu_data *data;struct list_head list; };
@@ -168,23 +169,6 @@ static LIST_HEAD(m4ulist); /* List all the M4U HWs */#define for_each_m4u (data) list_for_each_entry(data, &m4ulist, list) -/* -* There may be 1 or 2 M4U HWs, But we always expect they are in the same domain -* for the performance. -* -* Here always return the mtk_iommu_data of the first probed M4U where the -* iommu domain information is recorded. -*/ -static struct mtk_iommu_data *mtk_iommu_get_m4u_data (void ) -{ -struct mtk_iommu_data *data; - -for_each_m4u (data) -return data; - -return NULL ; -} -static u32 get_domain_id (struct mtk_iommu_data *data,u32 portid) {u32 dom_id =0 ;
@@ -403,6 +387,27 @@ static void mtk_iommu_config(struct mtk_iommu_data *data, } } +static struct iommu_group *create_iommu_group (struct mtk_iommu_data *data, +struct device *dev) +{ +struct mtk_iommu_pgtable *pgtable =mtk_iommu_get_pgtable (); + +/* Prepare for allocate mtk_iommu_domain */ + data->m4u_group =mtk_iommu_get_group (dev); +if (!data->m4u_group) { + data->m4u_group =iommu_group_alloc (); +if (IS_ERR (data->m4u_group)) +dev_err (dev,"Failed to allocate M4U IOMMU group\n" ); + }else { +iommu_group_ref_get (data->m4u_group); + } + +/* save the latest init device */ + pgtable->init_dev = dev; + +return data->m4u_group; +} +static struct mtk_iommu_pgtable *create_pgtable (struct mtk_iommu_data *data) {struct mtk_iommu_pgtable *pgtable;
@@ -468,7 +473,7 @@ static int mtk_iommu_attach_pgtable(struct mtk_iommu_data *data,static struct iommu_domain *mtk_iommu_domain_alloc (unsigned type) {struct mtk_iommu_pgtable *pgtable =mtk_iommu_get_pgtable (); -struct mtk_iommu_data *data =mtk_iommu_get_m4u_data (); +struct mtk_iommu_data *data;struct mtk_iommu_domain *dom;struct device *dev;
@@ -477,6 +482,7 @@ static struct iommu_domain *mtk_iommu_domain_alloc(unsigned type)if (pgtable) { dev = pgtable->init_dev; + data =dev_iommu_fwspec_get (dev)->iommu_priv;if (!data->m4u_group) {pr_err ("%s, find m4u_group failed\n" , __func__);return NULL ;
@@ -497,6 +503,7 @@ static struct iommu_domain *mtk_iommu_domain_alloc(unsigned type)if (dom->id >= data->plat_data->dom_cnt) goto put_dma_cookie; + dom->data = data; dom->group = data->m4u_group;/* Update our support page sizes bitmap */ dom->domain.pgsize_bitmap = pgtable->cfg.pgsize_bitmap;
@@ -554,7 +561,8 @@ static int mtk_iommu_map(struct iommu_domain *domain, unsigned long iova, phys_addr_t paddr, size_t size, int prot) { struct mtk_iommu_pgtable *pgtable = mtk_iommu_get_pgtable(); -struct mtk_iommu_data *data =mtk_iommu_get_m4u_data (); +struct mtk_iommu_domain *dom =to_mtk_domain (domain); +struct mtk_iommu_data *data = dom->data;/* The "4GB mode" M4U physically can not use the lower remap of Dram. */ if (data->enable_4GB)
@@ -575,27 +583,30 @@ static size_t mtk_iommu_unmap(struct iommu_domain *domain,static void mtk_iommu_flush_iotlb_all (struct iommu_domain *domain) { -mtk_iommu_tlb_flush_all (mtk_iommu_get_m4u_data ()); +struct mtk_iommu_domain *dom =to_mtk_domain (domain); + +mtk_iommu_tlb_flush_all (dom->data); }static void mtk_iommu_iotlb_sync (struct iommu_domain *domain,struct iommu_iotlb_gather *gather) { -struct mtk_iommu_data *data =mtk_iommu_get_m4u_data (); +struct mtk_iommu_domain *dom =to_mtk_domain (domain);size_t length = gather->end - gather->start;if (gather->start ==ULONG_MAX )return ;mtk_iommu_tlb_flush_range_sync (gather->start, length, gather->pgsize, - data); + dom->data); }static phys_addr_t mtk_iommu_iova_to_phys (struct iommu_domain *domain,dma_addr_t iova) {struct mtk_iommu_pgtable *pgtable =mtk_iommu_get_pgtable (); -struct mtk_iommu_data *data =mtk_iommu_get_m4u_data (); +struct mtk_iommu_domain *dom =to_mtk_domain (domain); +struct mtk_iommu_data *data = dom->data;phys_addr_t pa; pa = pgtable->iop->iova_to_phys (pgtable->iop, iova);
@@ -642,7 +653,7 @@ static void mtk_iommu_remove_device(struct device *dev)static struct iommu_group *mtk_iommu_device_group (struct device *dev) { -struct mtk_iommu_data *data =mtk_iommu_get_m4u_data (); +struct mtk_iommu_data *data = dev->iommu_fwspec->iommu_priv;struct mtk_iommu_pgtable *pgtable;int ret =0 ;
@@ -658,20 +669,9 @@ static struct iommu_group *mtk_iommu_device_group(struct device *dev) } } -/* All the client devices are in the same m4u iommu-group */ - data->m4u_group =mtk_iommu_get_group (dev); -if (!data->m4u_group) { - data->m4u_group =iommu_group_alloc (); -if (IS_ERR (data->m4u_group)) -dev_err (dev,"Failed to allocate M4U IOMMU group\n" ); - }else { -iommu_group_ref_get (data->m4u_group); - } +dev_info (data->dev,"%s, init data:%d\n" , __func__, data->m4u_id); -/* save the latest init device */ - pgtable->init_dev = dev; - -return data->m4u_group; +return create_iommu_group (data, dev); }static int mtk_iommu_of_xlate (struct device *dev,struct of_phandle_args *args)
Signature · 1 line
2.18.0
PATCH RESEND 11/13 iommu/mediatek: Add iova reserved function
In reply to Chao HaoFor multiple iommu_domains, we need to reserve some iova regions, so we will add mtk_iommu_resv_iova_region structure. It includes the start address and size of iova and iommu_resv_type. Based on the function, we will realize multiple mtk_iommu_domains
--- drivers/iommu/mtk_iommu.c | 47 +++++++++++++++++++++++++++++++++++++++ drivers/iommu/mtk_iommu.h | 12 ++++++++++ 2 files changed, 59 insertions(+)
drivers/iommu/mtk_iommu.c +47 -0
@@ -697,6 +697,51 @@ static int mtk_iommu_of_xlate(struct device *dev, struct of_phandle_args *args)return iommu_fwspec_add_ids (dev, args->args,1 ); } +/* reserve/dir-map iova region */ +static void mtk_iommu_get_resv_regions (struct device *dev, +struct list_head *head) +{ +struct mtk_iommu_data *data =dev_iommu_fwspec_get (dev)->iommu_priv; +unsigned int i, total_cnt = data->plat_data->resv_cnt; +const struct mtk_iommu_resv_iova_region *resv_data; +struct iommu_resv_region *region; +unsigned long base =0 ; +size_t size =0 ; +int prot =IOMMU_WRITE |IOMMU_READ ; + + resv_data = data->plat_data->resv_region; + +for (i =0 ; i < total_cnt; i++) { + size =0 ; +if (resv_data[i].iova_size) { + base = (unsigned long )resv_data[i].iova_base; + size = resv_data[i].iova_size; + } +if (!size) +continue ; + + region =iommu_alloc_resv_region (base, size, prot, + resv_data[i].type); +if (!region) +return ; + +list_add_tail (®ion->list, head); + +dev_dbg (data->dev,"%s iova 0x%x ~ 0x%x\n" , + (resv_data[i].type ==IOMMU_RESV_DIRECT ) ?"dm" :"rsv" , + (unsigned int )base, (unsigned int )(base + size -1 )); + } +} + +static void mtk_iommu_put_resv_regions (struct device *dev, +struct list_head *head) +{ +struct iommu_resv_region *entry, *next; + +list_for_each_entry_safe (entry, next, head, list) +kfree (entry); +} +static const struct iommu_ops mtk_iommu_ops = { .domain_alloc = mtk_iommu_domain_alloc, .domain_free = mtk_iommu_domain_free,
@@ -711,6 +756,8 @@ static const struct iommu_ops mtk_iommu_ops = { .remove_device = mtk_iommu_remove_device, .device_group = mtk_iommu_device_group, .of_xlate = mtk_iommu_of_xlate, + .get_resv_regions = mtk_iommu_get_resv_regions, + .put_resv_regions = mtk_iommu_put_resv_regions, .pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M, };
drivers/iommu/mtk_iommu.h +12 -0
@@ -36,6 +36,12 @@ enum mtk_iommu_plat { M4U_MT8183, }; +struct mtk_iommu_resv_iova_region { +dma_addr_t iova_base; +size_t iova_size; +enum iommu_resv_type type; +}; +/* * reserved IOVA Domain for IOMMU users of HW limitation. */
@@ -68,6 +74,12 @@ struct mtk_iommu_plat_data {u32 dom_cnt;unsigned char larbid_remap[2 ][MTK_LARB_NR_MAX ];const struct mtk_domain_data *dom_data; +/* +* reserve/dir-mapping iova region data +* todo: for different reserve needs on multiple iommu domains +*/ +const unsigned int resv_cnt; +const struct mtk_iommu_resv_iova_region *resv_region; };struct mtk_iommu_domain ;
Signature · 1 line
2.18.0
PATCH RESEND 12/13 iommu/mediatek: Change single domain to multiple domains
In reply to Chao HaoBased on one mtk_iommu_domain, this patch supports multiple mtk_iommu_domains to realize different iova regions.
Every module has one smi_larb port, so we can create different mtk_iommu_domains by smi_larb port define. So we will add port_mask variable to mtk_domain_data, if some modules need special iova regions, they can write smi_larb port which corresponding to themselves to post_mask variable and specify the start and end address of iova region. The form of port_mask can use "MTK_M4U_ID(larb, port)", larb and port can refer to "mtxxxx-larb-port.h(ex: mt6779-larb-port.h)" file.
The architecture diagram is as below:
mtk_iommu_pgtable | mtk_domain_data | ------------------------------------------------- | | | mtk_iommu_domain1 mtk_iommu_domain2 mtk_iommu_domain3
--- drivers/iommu/mtk_iommu.c | 48 +++++++++++++++++++++++++++++++++------ drivers/iommu/mtk_iommu.h | 11 ++++++++- 2 files changed, 51 insertions(+), 8 deletions(-)
drivers/iommu/mtk_iommu.c +41 -7
@@ -130,6 +130,8 @@ struct mtk_iommu_pgtable {struct io_pgtable_ops *iop;struct device *init_dev;struct list_head m4u_dom_v2; +spinlock_t domain_lock;/* lock for domain count */ +u32 domain_count;const struct mtk_domain_data *dom_region; };
@@ -172,11 +174,15 @@ static LIST_HEAD(m4ulist); /* List all the M4U HWs */static u32 get_domain_id (struct mtk_iommu_data *data,u32 portid) {u32 dom_id =0 ; -int i; +const struct mtk_domain_data *mtk_dom_array = data->plat_data->dom_data; +int i, j; -/* only support one mtk_iommu_domain currently(dom_cnt = 1) */ -for (i =0 ; i < data->plat_data->dom_cnt; i++) -return i; +for (i =0 ; i < data->plat_data->dom_cnt; i++) { +for (j =0 ; j <MTK_MAX_PORT_NUM ; j++) { +if (portid == mtk_dom_array[i].port_mask[j]) +return i; + } + }return dom_id; }
@@ -416,6 +422,8 @@ static struct mtk_iommu_pgtable *create_pgtable(struct mtk_iommu_data *data)if (!pgtable)return ERR_PTR (-ENOMEM ); +spin_lock_init (&pgtable->domain_lock); + pgtable->domain_count =0 ;INIT_LIST_HEAD (&pgtable->m4u_dom_v2); pgtable->cfg = (struct io_pgtable_cfg ) {
@@ -476,6 +484,7 @@ static struct iommu_domain *mtk_iommu_domain_alloc(unsigned type)struct mtk_iommu_data *data;struct mtk_iommu_domain *dom;struct device *dev; +unsigned long flags;if (type !=IOMMU_DOMAIN_DMA )return NULL ;
@@ -503,18 +512,34 @@ static struct iommu_domain *mtk_iommu_domain_alloc(unsigned type)if (dom->id >= data->plat_data->dom_cnt) goto put_dma_cookie; +spin_lock_irqsave (&pgtable->domain_lock, flags); +if (pgtable->domain_count >= data->plat_data->dom_cnt) { +spin_unlock_irqrestore (&pgtable->domain_lock, flags); +dev_err (dev,"%s, too many domain, count=%u\n" , + __func__, pgtable->domain_count); + goto put_dma_cookie; + } + pgtable->domain_count++; +spin_unlock_irqrestore (&pgtable->domain_lock, flags); dom->data = data; dom->group = data->m4u_group; +/* Update our support page sizes bitmap */ dom->domain.pgsize_bitmap = pgtable->cfg.pgsize_bitmap; dom->domain.geometry.aperture_start = - pgtable->dom_region->min_iova; + pgtable->dom_region[dom->id].min_iova; dom->domain.geometry.aperture_end = - pgtable->dom_region->max_iova; + pgtable->dom_region[dom->id].max_iova; dom->domain.geometry.force_aperture = true;list_add_tail (&dom->list, &pgtable->m4u_dom_v2); +dev_info (dev,"%s: dom_id:%u, start:%pa, end:%pa, dom_cnt:%u\n" , + __func__, dom->id, + &dom->domain.geometry.aperture_start, + &dom->domain.geometry.aperture_end, + pgtable->domain_count); +return &dom->domain; put_dma_cookie:
@@ -527,9 +552,17 @@ static struct iommu_domain *mtk_iommu_domain_alloc(unsigned type)static void mtk_iommu_domain_free (struct iommu_domain *domain) {struct mtk_iommu_pgtable *pgtable =mtk_iommu_get_pgtable (); +unsigned long flags;iommu_put_dma_cookie (domain);kfree (to_mtk_domain (domain)); +spin_lock_irqsave (&pgtable->domain_lock, flags); + pgtable->domain_count--; +if (pgtable->domain_count >0 ) { +spin_unlock_irqrestore (&pgtable->domain_lock, flags); +return ; + } +spin_unlock_irqrestore (&pgtable->domain_lock, flags);free_io_pgtable_ops (pgtable->iop);kfree (pgtable); }
@@ -703,6 +736,7 @@ static void mtk_iommu_get_resv_regions(struct device *dev, {struct mtk_iommu_data *data =dev_iommu_fwspec_get (dev)->iommu_priv;unsigned int i, total_cnt = data->plat_data->resv_cnt; +u32 dom_id =mtk_iommu_get_domain_id (dev);const struct mtk_iommu_resv_iova_region *resv_data;struct iommu_resv_region *region;unsigned long base =0 ;
@@ -717,7 +751,7 @@ static void mtk_iommu_get_resv_regions(struct device *dev, base = (unsigned long )resv_data[i].iova_base; size = resv_data[i].iova_size; } -if (!size) +if (!size || resv_data[i].dom_id != dom_id)continue ; region = iommu_alloc_resv_region(base, size, prot,
drivers/iommu/mtk_iommu.h +10 -1
@@ -37,6 +37,7 @@ enum mtk_iommu_plat { };struct mtk_iommu_resv_iova_region { +u32 dom_id;dma_addr_t iova_base;size_t iova_size;enum iommu_resv_type type;
@@ -50,12 +51,20 @@ struct mtk_iommu_resv_iova_region {* struct mtk_domain_data: domain configuration * @min_iova: Start address of iova * @max_iova: End address of iova -* Note: one user can only belong to one domain +* @port_mask: User can specify mtk_iommu_domain by smi larb and port. +* Different mtk_iommu_domain have different iova space, +* port_mask is made up of larb_id and port_id. +* The format of larb and port can refer to mtxxxx-larb-port.h. +* bit[4:0] = port_id bit[11:5] = larb_id. +* Note: one user can only belong to one domain, +* the port mask is in unit of SMI larb. */ +#define MTK_MAX_PORT_NUM 5struct mtk_domain_data {dma_addr_t min_iova;dma_addr_t max_iova; +u32 port_mask[MTK_MAX_PORT_NUM ]; };struct mtk_iommu_plat_data {
Signature · 1 line
2.18.0
PATCH RESEND 13/13 iommu/mediatek: Add multiple mtk_iommu_domain support for mt6779
In reply to Chao HaoFor mt6779, it need to support three mtk_iommu_domains, every mtk_iommu_domain's iova space is different.
Three mtk_iommu_domains is as below:
1. Normal mtk_iommu_domain exclude 0x4000_0000~0x47ff_ffff and 0x7da0_0000~7fbf_ffff.
2. CCU mtk_iommu_domain include 0x4000_0000~0x47ff_ffff.
3. VPU mtk_iommu_domain 0x7da0_0000~0x7fbf_ffff.
--- drivers/iommu/mtk_iommu.c | 45 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-)
drivers/iommu/mtk_iommu.c +43 -2
@@ -140,6 +140,30 @@ const struct mtk_domain_data single_dom = { .max_iova = DMA_BIT_MASK(32) }; +/* +* related file: mt6779-larb-port.h +*/ +const struct mtk_domain_data mt6779_multi_dom[] = { +/* normal domain */ + { + .min_iova =0x0 , + .max_iova =DMA_BIT_MASK (32 ), + }, +/* ccu domain */ + { + .min_iova =0x40000000 , + .max_iova =0x48000000 -1 , + .port_mask = {MTK_M4U_ID (9 ,21 ),MTK_M4U_ID (9 ,22 ), +MTK_M4U_ID (12 ,0 ),MTK_M4U_ID (12 ,1 )} + }, +/* vpu domain */ + { + .min_iova =0x7da00000 , + .max_iova =0x7fc00000 -1 , + .port_mask = {MTK_M4U_ID (13 ,0 )} + } +}; +static struct mtk_iommu_pgtable *share_pgtable;static const struct iommu_ops mtk_iommu_ops;
@@ -1055,6 +1079,21 @@ static const struct dev_pm_ops mtk_iommu_pm_ops = {SET_NOIRQ_SYSTEM_SLEEP_PM_OPS (mtk_iommu_suspend, mtk_iommu_resume) }; +static const struct mtk_iommu_resv_iova_region mt6779_iommu_rsv_list[] = { + { + .dom_id =0 , + .iova_base =0x40000000 ,/* CCU */ + .iova_size =0x8000000 , + .type =IOMMU_RESV_RESERVED , + }, + { + .dom_id =0 , + .iova_base =0x7da00000 ,/* VPU/MDLA */ + .iova_size =0x2700000 , + .type =IOMMU_RESV_RESERVED , + }, +}; +static const struct mtk_iommu_plat_data mt2712_data = { .m4u_plat =M4U_MT2712 , .has_4gb_mode = true,
@@ -1068,8 +1107,10 @@ static const struct mtk_iommu_plat_data mt2712_data = {static const struct mtk_iommu_plat_data mt6779_data = { .m4u_plat =M4U_MT6779 , - .dom_cnt =1 , - .dom_data = &single_dom, + .resv_cnt =ARRAY_SIZE (mt6779_iommu_rsv_list), + .resv_region = mt6779_iommu_rsv_list, + .dom_cnt =ARRAY_SIZE (mt6779_multi_dom), + .dom_data = mt6779_multi_dom, .larbid_remap[0 ] = {0 ,1 ,2 ,3 ,5 ,7 ,10 ,9 },/* vp6a, vp6b, mdla/core2, mdla/edmc*/ .larbid_remap[1 ] = {2 ,0 ,3 ,1 },
Signature · 1 line
2.18.0