1 /*
2  * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <stdbool.h>
8 
9 #include "hal/mpu_hal.h"
10 #include "hal/mpu_types.h"
11 #include "soc/soc_caps.h"
12 #include "bootloader_mem.h"
13 #include "esp_cpu.h"
14 
15 #if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
16 #include "soc/hp_apm_reg.h"
17 #include "soc/lp_apm_reg.h"
18 #include "soc/lp_apm0_reg.h"
19 #endif
20 
bootloader_init_mem(void)21 void bootloader_init_mem(void)
22 {
23 #if SOC_APM_SUPPORTED
24     /* By default, these access path filters are enable and allow the
25      * access to masters only if they are in TEE mode. Since all masters
26      * except HP CPU boots in REE mode, default setting of these filters
27      * will deny the access to all masters except HP CPU.
28      * So, at boot disabling these filters. They will enable as per the
29      * use case by TEE initialization code.
30      */
31     REG_WRITE(LP_APM_FUNC_CTRL_REG, 0);
32     REG_WRITE(LP_APM0_FUNC_CTRL_REG, 0);
33     REG_WRITE(HP_APM_FUNC_CTRL_REG, 0);
34 #endif
35 
36 #ifdef CONFIG_BOOTLOADER_REGION_PROTECTION_ENABLE
37     // protect memory region
38     esp_cpu_configure_region_protection();
39 #endif
40 }
41