xref: /arm-trusted-firmware/plat/mediatek/drivers/iommu/mt8188/mtk_iommu_plat.c (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu /*
2*91f16700Schasinglulu  * Copyright (c) 2022, MediaTek Inc. All rights reserved.
3*91f16700Schasinglulu  *
4*91f16700Schasinglulu  * SPDX-License-Identifier: BSD-3-Clause
5*91f16700Schasinglulu  */
6*91f16700Schasinglulu 
7*91f16700Schasinglulu #include <mtk_iommu_plat.h>
8*91f16700Schasinglulu #include <mtk_mmap_pool.h>
9*91f16700Schasinglulu #include <platform_def.h>
10*91f16700Schasinglulu 
11*91f16700Schasinglulu /* mm iommu */
12*91f16700Schasinglulu #define SMI_L0_ID		(0)
13*91f16700Schasinglulu #define SMI_L1_ID		(1)
14*91f16700Schasinglulu #define SMI_L2_ID		(2)
15*91f16700Schasinglulu #define SMI_L3_ID		(3)
16*91f16700Schasinglulu #define SMI_L4_ID		(4)
17*91f16700Schasinglulu #define SMI_L5_ID		(5)
18*91f16700Schasinglulu #define SMI_L6_ID		(6)
19*91f16700Schasinglulu #define SMI_L7_ID		(7)
20*91f16700Schasinglulu #define SMI_L9_ID		(8)
21*91f16700Schasinglulu #define SMI_L10_ID		(9)
22*91f16700Schasinglulu #define SMI_L11A_ID		(10)
23*91f16700Schasinglulu #define SMI_L11B_ID		(11)
24*91f16700Schasinglulu #define SMI_L11C_ID		(12)
25*91f16700Schasinglulu #define SMI_L12_ID		(13)
26*91f16700Schasinglulu #define SMI_L13_ID		(14)
27*91f16700Schasinglulu #define SMI_L14_ID		(15)
28*91f16700Schasinglulu #define SMI_L15_ID		(16)
29*91f16700Schasinglulu #define SMI_L16A_ID		(17)
30*91f16700Schasinglulu #define SMI_L16B_ID		(18)
31*91f16700Schasinglulu #define SMI_L17A_ID		(19)
32*91f16700Schasinglulu #define SMI_L17B_ID		(20)
33*91f16700Schasinglulu #define SMI_L19_ID		(21)
34*91f16700Schasinglulu #define SMI_L21_ID		(22)
35*91f16700Schasinglulu #define SMI_L23_ID		(23)
36*91f16700Schasinglulu #define SMI_L27_ID		(24)
37*91f16700Schasinglulu #define SMI_L28_ID		(25)
38*91f16700Schasinglulu 
39*91f16700Schasinglulu /* infra iommu */
40*91f16700Schasinglulu #define PERI_MST_PROT		(0x710)
41*91f16700Schasinglulu #define PERICFG_AO_IOMMU_1	(0x714)
42*91f16700Schasinglulu #define MMU_DEV_PCIE_0		(0)
43*91f16700Schasinglulu #define IFR_CFG_GROUP_NUM	(1)
44*91f16700Schasinglulu 
45*91f16700Schasinglulu static struct mtk_smi_larb_config mt8188_larb_cfg[SMI_LARB_NUM] = {
46*91f16700Schasinglulu 	[SMI_L0_ID] = LARB_CFG_ENTRY(SMI_LARB_0_BASE, 7, 0),
47*91f16700Schasinglulu 	[SMI_L1_ID] = LARB_CFG_ENTRY(SMI_LARB_1_BASE, 7, 0),
48*91f16700Schasinglulu 	[SMI_L2_ID] = LARB_CFG_ENTRY(SMI_LARB_2_BASE, 5, 0),
49*91f16700Schasinglulu 	[SMI_L3_ID] = LARB_CFG_ENTRY(SMI_LARB_3_BASE, 7, 0),
50*91f16700Schasinglulu 	[SMI_L4_ID] = LARB_CFG_ENTRY(SMI_LARB_4_BASE, 7, 0),
51*91f16700Schasinglulu 	[SMI_L5_ID] = LARB_CFG_ENTRY(SMI_LARB_5_BASE, 8, 0),
52*91f16700Schasinglulu 	[SMI_L6_ID] = LARB_CFG_ENTRY(SMI_LARB_6_BASE, 4, 0),
53*91f16700Schasinglulu 	[SMI_L7_ID] = LARB_CFG_ENTRY(SMI_LARB_7_BASE, 3, 0),
54*91f16700Schasinglulu 	[SMI_L9_ID] = LARB_CFG_ENTRY(SMI_LARB_9_BASE, 25, 0),
55*91f16700Schasinglulu 	[SMI_L10_ID] = LARB_CFG_ENTRY(SMI_LARB_10_BASE, 20, 0),
56*91f16700Schasinglulu 	[SMI_L11A_ID] = LARB_CFG_ENTRY(SMI_LARB_11A_BASE, 30, 0),
57*91f16700Schasinglulu 	[SMI_L11B_ID] = LARB_CFG_ENTRY(SMI_LARB_11B_BASE, 30, 0),
58*91f16700Schasinglulu 	[SMI_L11C_ID] = LARB_CFG_ENTRY(SMI_LARB_11C_BASE, 30, 0),
59*91f16700Schasinglulu 	[SMI_L12_ID] = LARB_CFG_ENTRY(SMI_LARB_12_BASE, 16, 0),
60*91f16700Schasinglulu 	[SMI_L13_ID] = LARB_CFG_ENTRY(SMI_LARB_13_BASE, 24, 0),
61*91f16700Schasinglulu 	[SMI_L14_ID] = LARB_CFG_ENTRY(SMI_LARB_14_BASE, 23, 0),
62*91f16700Schasinglulu 	[SMI_L15_ID] = LARB_CFG_ENTRY(SMI_LARB_15_BASE, 19, 0),
63*91f16700Schasinglulu 	[SMI_L16A_ID] = LARB_CFG_ENTRY(SMI_LARB_16A_BASE, 17, 0),
64*91f16700Schasinglulu 	[SMI_L16B_ID] = LARB_CFG_ENTRY(SMI_LARB_16B_BASE, 17, 0),
65*91f16700Schasinglulu 	[SMI_L17A_ID] = LARB_CFG_ENTRY(SMI_LARB_17A_BASE, 7, 0),
66*91f16700Schasinglulu 	[SMI_L17B_ID] = LARB_CFG_ENTRY(SMI_LARB_17B_BASE, 7, 0),
67*91f16700Schasinglulu 	/* venc nbm ports (5/6/11/15/16/17) to sram */
68*91f16700Schasinglulu 	[SMI_L19_ID] = LARB_CFG_ENTRY_WITH_PATH(SMI_LARB_19_BASE, 27, 0, 0x38860),
69*91f16700Schasinglulu 	[SMI_L21_ID] = LARB_CFG_ENTRY(SMI_LARB_21_BASE, 11, 0),
70*91f16700Schasinglulu 	[SMI_L23_ID] = LARB_CFG_ENTRY(SMI_LARB_23_BASE, 9, 0),
71*91f16700Schasinglulu 	[SMI_L27_ID] = LARB_CFG_ENTRY(SMI_LARB_27_BASE, 4, 0),
72*91f16700Schasinglulu 	[SMI_L28_ID] = LARB_CFG_ENTRY(SMI_LARB_28_BASE, 0, 0),
73*91f16700Schasinglulu };
74*91f16700Schasinglulu 
75*91f16700Schasinglulu static bool is_protected;
76*91f16700Schasinglulu 
77*91f16700Schasinglulu static uint32_t mt8188_ifr_mst_cfg_base[IFR_CFG_GROUP_NUM] = {
78*91f16700Schasinglulu 	PERICFG_AO_BASE,
79*91f16700Schasinglulu };
80*91f16700Schasinglulu static uint32_t mt8188_ifr_mst_cfg_offs[IFR_CFG_GROUP_NUM] = {
81*91f16700Schasinglulu 	PERICFG_AO_IOMMU_1,
82*91f16700Schasinglulu };
83*91f16700Schasinglulu static struct mtk_ifr_mst_config mt8188_ifr_mst_cfg[MMU_DEV_NUM] = {
84*91f16700Schasinglulu 	[MMU_DEV_PCIE_0] = IFR_MST_CFG_ENTRY(0, 18),
85*91f16700Schasinglulu };
86*91f16700Schasinglulu 
87*91f16700Schasinglulu struct mtk_smi_larb_config *g_larb_cfg = &mt8188_larb_cfg[0];
88*91f16700Schasinglulu struct mtk_ifr_mst_config *g_ifr_mst_cfg = &mt8188_ifr_mst_cfg[0];
89*91f16700Schasinglulu uint32_t *g_ifr_mst_cfg_base = &mt8188_ifr_mst_cfg_base[0];
90*91f16700Schasinglulu uint32_t *g_ifr_mst_cfg_offs = &mt8188_ifr_mst_cfg_offs[0];
91*91f16700Schasinglulu 
92*91f16700Schasinglulu /* Protect infra iommu enable setting registers as secure access. */
93*91f16700Schasinglulu void mtk_infra_iommu_enable_protect(void)
94*91f16700Schasinglulu {
95*91f16700Schasinglulu 	if (!is_protected) {
96*91f16700Schasinglulu 		mmio_write_32(PERICFG_AO_BASE + PERI_MST_PROT, 0xffffffff);
97*91f16700Schasinglulu 		is_protected = true;
98*91f16700Schasinglulu 	}
99*91f16700Schasinglulu }
100