Browse Source

feat(mt8188): add emi mpu protection for APU secure memory

Add emi mpu protection of APU secure memory.

Change-Id: I949cfce97565d8a313caae4ea41af60a171042a6
Signed-off-by: Chungying Lu <chungying.lu@mediatek.com>
Signed-off-by: Karl Li <karl.li@mediatek.com>
pull/1999/head
Chungying Lu 2 years ago
committed by Karl Li
parent
commit
176846a50b
  1. 3
      plat/mediatek/drivers/apusys/apusys.c
  2. 1
      plat/mediatek/drivers/apusys/apusys.h
  3. 25
      plat/mediatek/drivers/apusys/apusys_rv/2.0/apusys_rv.c
  4. 1
      plat/mediatek/drivers/apusys/apusys_rv/2.0/apusys_rv.h
  5. 3
      plat/mediatek/drivers/emi_mpu/emi_mpu.h
  6. 19
      plat/mediatek/drivers/emi_mpu/mt8188/emi_mpu.c
  7. 7
      plat/mediatek/drivers/emi_mpu/mt8188/emi_mpu_priv.h

3
plat/mediatek/drivers/apusys/apusys.c

@ -53,6 +53,9 @@ static u_register_t apusys_kernel_handler(u_register_t x1,
case MTK_APUSYS_KERNEL_OP_DEVAPC_INIT_RCX:
ret = apusys_devapc_rcx_init();
break;
case MTK_APUSYS_KERNEL_OP_APUSYS_RV_SETUP_SEC_MEM:
ret = apusys_kernel_apusys_rv_setup_sec_mem();
break;
default:
ERROR(MODULE_TAG "%s unknown request_ops = %x\n", MODULE_TAG, request_ops);
break;

1
plat/mediatek/drivers/apusys/apusys.h

@ -18,6 +18,7 @@ enum MTK_APUSYS_KERNEL_OP {
MTK_APUSYS_KERNEL_OP_APUSYS_RV_START_MP, /* 5 */
MTK_APUSYS_KERNEL_OP_APUSYS_RV_STOP_MP, /* 6 */
MTK_APUSYS_KERNEL_OP_DEVAPC_INIT_RCX, /* 7 */
MTK_APUSYS_KERNEL_OP_APUSYS_RV_SETUP_SEC_MEM, /* 8 */
MTK_APUSYS_KERNEL_OP_NUM,
};

25
plat/mediatek/drivers/apusys/apusys_rv/2.0/apusys_rv.c

@ -14,6 +14,7 @@
#include "apusys.h"
#include "apusys_rv.h"
#include "apusys_rv_mbox_mpu.h"
#include "emi_mpu.h"
static spinlock_t apusys_rv_lock;
@ -181,3 +182,27 @@ int apusys_kernel_apusys_rv_stop_mp(void)
return 0;
}
int apusys_kernel_apusys_rv_setup_sec_mem(void)
{
static bool apusys_rv_setup_sec_mem_called;
int ret;
spin_lock(&apusys_rv_lock);
if (apusys_rv_setup_sec_mem_called) {
WARN(MODULE_TAG "%s: already initialized\n", __func__);
spin_unlock(&apusys_rv_lock);
return -1;
}
apusys_rv_setup_sec_mem_called = true;
ret = set_apu_emi_mpu_region();
if (ret != 0) {
ERROR(MODULE_TAG "%s: set emimpu protection failed\n", __func__);
}
spin_unlock(&apusys_rv_lock);
return ret;
}

1
plat/mediatek/drivers/apusys/apusys_rv/2.0/apusys_rv.h

@ -106,5 +106,6 @@ int apusys_kernel_apusys_rv_reset_mp(void);
int apusys_kernel_apusys_rv_setup_boot(void);
int apusys_kernel_apusys_rv_start_mp(void);
int apusys_kernel_apusys_rv_stop_mp(void);
int apusys_kernel_apusys_rv_setup_sec_mem(void);
#endif /* APUSYS_RV_H */

3
plat/mediatek/drivers/emi_mpu/emi_mpu.h

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2022-2023, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@ -60,5 +60,6 @@ struct emi_region_info_t {
int emi_mpu_init(void);
int emi_mpu_set_protection(struct emi_region_info_t *region_info);
void set_emi_mpu_regions(void);
int set_apu_emi_mpu_region(void);
#endif

19
plat/mediatek/drivers/emi_mpu/mt8188/emi_mpu.c

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2022-2023, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@ -12,3 +12,20 @@ void set_emi_mpu_regions(void)
/* TODO: set emi mpu region */
INFO("%s, emi mpu is not setting currently\n", __func__);
}
int set_apu_emi_mpu_region(void)
{
struct emi_region_info_t region_info;
region_info.start = (unsigned long long)APUSYS_SEC_BUF_PA;
region_info.end = (unsigned long long)(APUSYS_SEC_BUF_PA + APUSYS_SEC_BUF_SZ) - 1;
region_info.region = APUSYS_SEC_BUF_EMI_REGION;
SET_ACCESS_PERMISSION(region_info.apc, UNLOCK,
FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
NO_PROTECTION, FORBIDDEN, NO_PROTECTION, FORBIDDEN,
FORBIDDEN, FORBIDDEN, FORBIDDEN, SEC_RW);
return emi_mpu_set_protection(&region_info);
}

7
plat/mediatek/drivers/emi_mpu/mt8188/emi_mpu_priv.h

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2022-2023, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@ -42,4 +42,9 @@
#define EMI_MPU_DGROUP_NUM (EMI_MPU_DOMAIN_NUM / 8)
/* APU EMI MPU Setting */
#define APUSYS_SEC_BUF_EMI_REGION (21)
#define APUSYS_SEC_BUF_PA (0x55000000)
#define APUSYS_SEC_BUF_SZ (0x100000)
#endif

Loading…
Cancel
Save