Skip to content

Commit 946e719

Browse files
xuchengci24968joergroedel
authored andcommitted
iommu/mediatek: Add enable IOMMU SMC command for INFRA masters
Prepare for MT8188. In MT8188, the register which enables IOMMU for INFRA masters are in the secure world for security concerns, therefore we add a SMC command for INFRA masters to enable IOMMU in ATF. Signed-off-by: Chengci.Xu <[email protected]> Signed-off-by: Yong Wu <[email protected]> Reviewed-by: AngeloGioacchino Del Regno <[email protected]> Reviewed-by: Alexandre Mergnat <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 9a89051 commit 946e719

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

drivers/iommu/mtk_iommu.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright (c) 2015-2016 MediaTek Inc.
44
* Author: Yong Wu <[email protected]>
55
*/
6+
#include <linux/arm-smccc.h>
67
#include <linux/bitfield.h>
78
#include <linux/bug.h>
89
#include <linux/clk.h>
@@ -27,6 +28,7 @@
2728
#include <linux/slab.h>
2829
#include <linux/spinlock.h>
2930
#include <linux/soc/mediatek/infracfg.h>
31+
#include <linux/soc/mediatek/mtk_sip_svc.h>
3032
#include <asm/barrier.h>
3133
#include <soc/mediatek/smi.h>
3234

@@ -143,6 +145,7 @@
143145
#define PGTABLE_PA_35_EN BIT(17)
144146
#define TF_PORT_TO_ADDR_MT8173 BIT(18)
145147
#define INT_ID_PORT_WIDTH_6 BIT(19)
148+
#define CFG_IFA_MASTER_IN_ATF BIT(20)
146149

147150
#define MTK_IOMMU_HAS_FLAG_MASK(pdata, _x, mask) \
148151
((((pdata)->flags) & (mask)) == (_x))
@@ -580,6 +583,7 @@ static int mtk_iommu_config(struct mtk_iommu_data *data, struct device *dev,
580583
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
581584
const struct mtk_iommu_iova_region *region;
582585
unsigned long portid_msk = 0;
586+
struct arm_smccc_res res;
583587
int i, ret = 0;
584588

585589
for (i = 0; i < fwspec->num_ids; ++i) {
@@ -605,17 +609,24 @@ static int mtk_iommu_config(struct mtk_iommu_data *data, struct device *dev,
605609
else
606610
larb_mmu->mmu &= ~portid_msk;
607611
} else if (MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_INFRA)) {
608-
/* PCI dev has only one output id, enable the next writing bit for PCIe */
609-
if (dev_is_pci(dev)) {
610-
if (fwspec->num_ids != 1) {
611-
dev_err(dev, "PCI dev can only have one port.\n");
612-
return -ENODEV;
612+
if (MTK_IOMMU_HAS_FLAG(data->plat_data, CFG_IFA_MASTER_IN_ATF)) {
613+
arm_smccc_smc(MTK_SIP_KERNEL_IOMMU_CONTROL,
614+
IOMMU_ATF_CMD_CONFIG_INFRA_IOMMU,
615+
portid_msk, enable, 0, 0, 0, 0, &res);
616+
ret = res.a0;
617+
} else {
618+
/* PCI dev has only one output id, enable the next writing bit for PCIe */
619+
if (dev_is_pci(dev)) {
620+
if (fwspec->num_ids != 1) {
621+
dev_err(dev, "PCI dev can only have one port.\n");
622+
return -ENODEV;
623+
}
624+
portid_msk |= BIT(portid + 1);
613625
}
614-
portid_msk |= BIT(portid + 1);
615-
}
616626

617-
ret = regmap_update_bits(data->pericfg, PERICFG_IOMMU_1,
618-
(u32)portid_msk, enable ? (u32)portid_msk : 0);
627+
ret = regmap_update_bits(data->pericfg, PERICFG_IOMMU_1,
628+
(u32)portid_msk, enable ? (u32)portid_msk : 0);
629+
}
619630
if (ret)
620631
dev_err(dev, "%s iommu(%s) inframaster 0x%lx fail(%d).\n",
621632
enable ? "enable" : "disable",
@@ -1330,7 +1341,8 @@ static int mtk_iommu_probe(struct platform_device *pdev)
13301341
dev_err_probe(dev, ret, "mm dts parse fail\n");
13311342
goto out_runtime_disable;
13321343
}
1333-
} else if (MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_INFRA)) {
1344+
} else if (MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_INFRA) &&
1345+
!MTK_IOMMU_HAS_FLAG(data->plat_data, CFG_IFA_MASTER_IN_ATF)) {
13341346
p = data->plat_data->pericfg_comp_str;
13351347
data->pericfg = syscon_regmap_lookup_by_compatible(p);
13361348
if (IS_ERR(data->pericfg)) {

include/soc/mediatek/smi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
enum iommu_atf_cmd {
1515
IOMMU_ATF_CMD_CONFIG_SMI_LARB, /* For mm master to en/disable iommu */
16+
IOMMU_ATF_CMD_CONFIG_INFRA_IOMMU, /* For infra master to enable iommu */
1617
IOMMU_ATF_CMD_MAX,
1718
};
1819

0 commit comments

Comments
 (0)