Skip to content

Commit 95efe53

Browse files
committed
Merge branch 'ci/tee_apm_pms_test_app' into 'master'
ci(hal): Add HAL/LL-based test app for the TEE and APM peripherals Closes IDF-8614, IDF-8615, IDF-9229, IDF-9230, IDF-10422, IDF-12646, IDF-12647, IDF-12648, IDF-12649, and IDF-12877 See merge request espressif/esp-idf!39873
2 parents 0920278 + 15a4d63 commit 95efe53

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+4333
-41
lines changed

.gitlab/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
/components/freertos/ @esp-idf-codeowners/system
126126
/components/hal/ @esp-idf-codeowners/peripherals
127127
/components/hal/test_apps/crypto/ @esp-idf-codeowners/peripherals @esp-idf-codeowners/security
128+
/components/hal/test_apps/tee_apm/ @esp-idf-codeowners/peripherals @esp-idf-codeowners/security
128129
/components/heap/ @esp-idf-codeowners/system
129130
/components/http_parser/ @esp-idf-codeowners/app-utilities
130131
/components/idf_test/ @esp-idf-codeowners/peripherals @esp-idf-codeowners/system

components/esp_hw_support/port/esp32c5/cpu_region_protect.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ void esp_cpu_configure_region_protection(void)
136136
_Static_assert(SOC_CPU_SUBSYSTEM_LOW < SOC_CPU_SUBSYSTEM_HIGH, "Invalid CPU subsystem region");
137137

138138
// 2. I/D-ROM
139+
#if CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT && !BOOTLOADER_BUILD
139140
const uint32_t drom_start = (uint32_t) (ets_rom_layout_p->drom_start);
140141
if ((drom_start & (SOC_CPU_PMP_REGION_GRANULARITY - 1)) == 0) {
141142
// We can skip configuring the PMP entry for the [SOC_IROM_MASK_LOW - drom_start]
@@ -144,9 +145,11 @@ void esp_cpu_configure_region_protection(void)
144145
// the region as cacheable. Thus, we save on one PMP entry.
145146
PMP_ENTRY_SET(1, drom_start, NONE);
146147
PMP_ENTRY_SET(2, SOC_DROM_MASK_HIGH, PMP_TOR | R);
147-
} else {
148+
} else
149+
#endif
150+
{
148151
PMP_ENTRY_SET(1, SOC_IROM_MASK_LOW, NONE);
149-
PMP_ENTRY_SET(2, SOC_IROM_MASK_HIGH, PMP_TOR | RX);
152+
PMP_ENTRY_SET(2, SOC_IROM_MASK_HIGH, PMP_TOR | CONDITIONAL_RX);
150153
_Static_assert(SOC_IROM_MASK_LOW < SOC_IROM_MASK_HIGH, "Invalid I/D-ROM region");
151154
}
152155

components/esp_hw_support/port/esp32c61/cpu_region_protect.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,17 @@ void esp_cpu_configure_region_protection(void)
133133
_Static_assert(SOC_CPU_SUBSYSTEM_LOW < SOC_CPU_SUBSYSTEM_HIGH, "Invalid CPU subsystem region");
134134

135135
// 2. I/D-ROM
136+
#if CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT && !BOOTLOADER_BUILD
136137
const uint32_t drom_start = (uint32_t) (ets_rom_layout_p->drom_start);
137138
if ((drom_start & (SOC_CPU_PMP_REGION_GRANULARITY - 1)) == 0) {
138139
PMP_ENTRY_SET(1, SOC_IROM_MASK_LOW, NONE);
139140
PMP_ENTRY_SET(2, drom_start, PMP_TOR | RX);
140141
PMP_ENTRY_SET(3, SOC_DROM_MASK_HIGH, PMP_TOR | RW);
141-
} else {
142+
} else
143+
#endif
144+
{
142145
const uint32_t pmpaddr1 = PMPADDR_NAPOT(SOC_IROM_MASK_LOW, SOC_IROM_MASK_HIGH);
143-
PMP_ENTRY_SET(1, pmpaddr1, PMP_NAPOT | RX);
146+
PMP_ENTRY_SET(1, pmpaddr1, PMP_NAPOT | CONDITIONAL_RX);
144147
_Static_assert(SOC_IROM_MASK_LOW < SOC_IROM_MASK_HIGH, "Invalid I/D-ROM region");
145148
}
146149

components/hal/.build-test-rules.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ components/hal/test_apps/hal_i2c:
1111
components/hal/test_apps/hal_utils:
1212
enable:
1313
- if: IDF_TARGET == "linux"
14+
15+
components/hal/test_apps/tee_apm:
16+
disable:
17+
- if: IDF_TARGET not in ["esp32c6", "esp32h2", "esp32c5", "esp32c61"]

components/hal/apm_hal.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,84 @@ void apm_hal_enable_region_filter(apm_ctrl_module_t ctrl_mod, uint32_t regn_num,
218218
}
219219
}
220220

221+
void apm_hal_set_region_start_addr(apm_ctrl_module_t ctrl_mod, uint32_t regn_num, uint32_t addr)
222+
{
223+
switch (ctrl_mod) {
224+
case APM_CTRL_HP_APM:
225+
apm_ll_hp_apm_set_region_start_addr(regn_num, addr);
226+
break;
227+
#if SOC_APM_LP_APM0_SUPPORTED
228+
case APM_CTRL_LP_APM0:
229+
apm_ll_lp_apm0_set_region_start_addr(regn_num, addr);
230+
break;
231+
#endif
232+
case APM_CTRL_LP_APM:
233+
apm_ll_lp_apm_set_region_start_addr(regn_num, addr);
234+
break;
235+
#if SOC_APM_CPU_APM_SUPPORTED
236+
case APM_CTRL_CPU_APM:
237+
apm_ll_cpu_apm_set_region_start_addr(regn_num, addr);
238+
break;
239+
#endif
240+
default:
241+
break;
242+
}
243+
}
244+
245+
void apm_hal_set_region_end_addr(apm_ctrl_module_t ctrl_mod, uint32_t regn_num, uint32_t addr)
246+
{
247+
switch (ctrl_mod) {
248+
case APM_CTRL_HP_APM:
249+
apm_ll_hp_apm_set_region_end_addr(regn_num, addr);
250+
break;
251+
#if SOC_APM_LP_APM0_SUPPORTED
252+
case APM_CTRL_LP_APM0:
253+
apm_ll_lp_apm0_set_region_end_addr(regn_num, addr);
254+
break;
255+
#endif
256+
case APM_CTRL_LP_APM:
257+
apm_ll_lp_apm_set_region_end_addr(regn_num, addr);
258+
break;
259+
#if SOC_APM_CPU_APM_SUPPORTED
260+
case APM_CTRL_CPU_APM:
261+
apm_ll_cpu_apm_set_region_end_addr(regn_num, addr);
262+
break;
263+
#endif
264+
default:
265+
break;
266+
}
267+
}
268+
269+
void apm_hal_set_sec_mode_region_attr(apm_ctrl_module_t ctrl_mod, uint32_t regn_num, apm_security_mode_t mode, uint32_t regn_pms)
270+
{
271+
HAL_ASSERT(mode != APM_SEC_MODE_TEE);
272+
273+
switch (ctrl_mod) {
274+
case APM_CTRL_HP_APM:
275+
apm_ll_hp_apm_set_sec_mode_region_attr(regn_num, mode, regn_pms);
276+
break;
277+
#if SOC_APM_LP_APM0_SUPPORTED
278+
case APM_CTRL_LP_APM0:
279+
apm_ll_lp_apm0_set_sec_mode_region_attr(regn_num, mode, regn_pms);
280+
break;
281+
#endif
282+
case APM_CTRL_LP_APM:
283+
apm_ll_lp_apm_set_sec_mode_region_attr(regn_num, mode, regn_pms);
284+
break;
285+
#if SOC_APM_CPU_APM_SUPPORTED
286+
case APM_CTRL_CPU_APM:
287+
apm_ll_cpu_apm_set_sec_mode_region_attr(regn_num, mode, regn_pms);
288+
break;
289+
#endif
290+
default:
291+
break;
292+
}
293+
}
294+
221295
void apm_hal_set_region_filter_cfg(apm_ctrl_module_t ctrl_mod, apm_security_mode_t mode, const apm_hal_ctrl_region_cfg_t *regn_cfg)
222296
{
223297
HAL_ASSERT(regn_cfg);
298+
HAL_ASSERT(mode != APM_SEC_MODE_TEE);
224299

225300
switch (ctrl_mod) {
226301
case APM_CTRL_HP_APM:

components/hal/esp32c61/include/hal/apm_ll.h

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "soc/hp_apm_struct.h"
1515
#include "soc/lp_apm_reg.h"
1616
#include "soc/lp_apm_struct.h"
17+
#include "soc/cpu_apm_reg.h"
18+
#include "soc/cpu_apm_struct.h"
1719

1820
#include "soc/pcr_reg.h"
1921
#include "soc/interrupts.h"
@@ -448,6 +450,195 @@ static inline int apm_ll_lp_apm_get_ctrl_intr_src(apm_ctrl_access_path_t path)
448450
return ETS_LP_APM_M0_INTR_SOURCE;
449451
}
450452

453+
/**
454+
* @brief Enable/disable controller filter for specific path in CPU-APM
455+
*
456+
* @param path Access path
457+
* @param enable True to enable, false to disable
458+
*/
459+
static inline void apm_ll_cpu_apm_enable_ctrl_filter(apm_ctrl_access_path_t path, bool enable)
460+
{
461+
if (enable) {
462+
REG_SET_BIT(CPU_APM_FUNC_CTRL_REG, BIT(path));
463+
} else {
464+
REG_CLR_BIT(CPU_APM_FUNC_CTRL_REG, BIT(path));
465+
}
466+
}
467+
468+
/**
469+
* @brief Enable/disable all controller filters in CPU-APM
470+
*
471+
* @param enable True to enable, false to disable
472+
*/
473+
static inline void apm_ll_cpu_apm_enable_ctrl_filter_all(bool enable)
474+
{
475+
REG_WRITE(CPU_APM_FUNC_CTRL_REG, enable ? UINT32_MAX : 0);
476+
}
477+
478+
/**
479+
* @brief Enable/disable region filter in CPU-APM
480+
*
481+
* @param regn_num Region number
482+
* @param enable True to enable, false to disable
483+
*/
484+
static inline void apm_ll_cpu_apm_enable_region_filter(uint32_t regn_num, bool enable)
485+
{
486+
if (enable) {
487+
REG_SET_BIT(CPU_APM_REGION_FILTER_EN_REG, BIT(regn_num));
488+
} else {
489+
REG_CLR_BIT(CPU_APM_REGION_FILTER_EN_REG, BIT(regn_num));
490+
}
491+
}
492+
493+
/**
494+
* @brief Set region start address in CPU-APM
495+
*
496+
* @param regn_num Region number
497+
* @param addr Start address
498+
*/
499+
static inline void apm_ll_cpu_apm_set_region_start_addr(uint32_t regn_num, uint32_t addr)
500+
{
501+
REG_WRITE(CPU_APM_REGION0_ADDR_START_REG + APM_REGION_ADDR_OFFSET * regn_num, addr);
502+
}
503+
504+
/**
505+
* @brief Set region end address in CPU-APM
506+
*
507+
* @param regn_num Region number
508+
* @param addr End address
509+
*/
510+
static inline void apm_ll_cpu_apm_set_region_end_addr(uint32_t regn_num, uint32_t addr)
511+
{
512+
REG_WRITE(CPU_APM_REGION0_ADDR_END_REG + APM_REGION_ADDR_OFFSET * regn_num, addr);
513+
}
514+
515+
/**
516+
* @brief Set security mode region attributes in CPU-APM
517+
*
518+
* @param regn_num Region number
519+
* @param mode Security mode
520+
* @param regn_pms Region PMS attributes
521+
*/
522+
static inline void apm_ll_cpu_apm_set_sec_mode_region_attr(uint32_t regn_num, apm_security_mode_t mode, uint32_t regn_pms)
523+
{
524+
uint32_t reg = CPU_APM_REGION0_ATTR_REG + APM_REGION_ATTR_OFFSET * regn_num;
525+
uint32_t val = REG_READ(reg);
526+
val &= ~APM_REGION_PMS_MASK(mode);
527+
val |= APM_REGION_PMS_FIELD(mode, regn_pms);
528+
REG_WRITE(reg, val);
529+
}
530+
531+
/**
532+
* @brief Lock security mode region attributes in CPU-APM
533+
*
534+
* @param regn_num Region number
535+
*/
536+
static inline void apm_ll_cpu_apm_lock_sec_mode_region_attr(uint32_t regn_num)
537+
{
538+
REG_SET_BIT(CPU_APM_REGION0_ATTR_REG + APM_REGION_ATTR_OFFSET * regn_num, APM_REGION_LOCK_BIT);
539+
}
540+
541+
/**
542+
* @brief Get exception data (regn, master, security mode) from CPU-APM
543+
*
544+
* @param path Access path
545+
* @return Exception data
546+
*/
547+
static inline uint32_t apm_ll_cpu_apm_get_excp_data(apm_ctrl_access_path_t path)
548+
{
549+
return REG_READ(CPU_APM_M0_EXCEPTION_INFO0_REG + APM_EXCP_INFO_OFFSET * path);
550+
}
551+
552+
/**
553+
* @brief Get exception status from CPU-APM
554+
*
555+
* @param path Access path
556+
* @return Exception type
557+
*/
558+
static inline uint32_t apm_ll_cpu_apm_get_excp_type(apm_ctrl_access_path_t path)
559+
{
560+
return REG_READ(CPU_APM_M0_STATUS_REG + APM_EXCP_INFO_OFFSET * path);
561+
}
562+
563+
/**
564+
* @brief Get exception address from CPU-APM
565+
*
566+
* @param path Access path
567+
* @return Exception address
568+
*/
569+
static inline uint32_t apm_ll_cpu_apm_get_excp_addr(apm_ctrl_access_path_t path)
570+
{
571+
return REG_READ(CPU_APM_M0_EXCEPTION_INFO1_REG + APM_EXCP_INFO_OFFSET * path);
572+
}
573+
574+
/**
575+
* @brief Get exception information from CPU-APM
576+
*
577+
* @param path Access path
578+
* @param info Pointer to store exception information
579+
*/
580+
static inline void apm_ll_cpu_apm_get_excp_info(apm_ctrl_access_path_t path, apm_ctrl_exception_info_t *info)
581+
{
582+
cpu_apm_m0_exception_info0_reg_t reg;
583+
reg.val = apm_ll_cpu_apm_get_excp_data(path);
584+
info->regn = reg.apm_m0_exception_region;
585+
info->mode = reg.apm_m0_exception_mode;
586+
info->id = reg.apm_m0_exception_id;
587+
588+
info->type = apm_ll_cpu_apm_get_excp_type(path);
589+
info->addr = apm_ll_cpu_apm_get_excp_addr(path);
590+
}
591+
592+
/**
593+
* @brief Clear controller exception status in CPU-APM
594+
*
595+
* @param path Access path
596+
*/
597+
static inline void apm_ll_cpu_apm_clear_ctrl_excp_status(apm_ctrl_access_path_t path)
598+
{
599+
REG_SET_BIT(CPU_APM_M0_STATUS_CLR_REG + APM_EXCP_INFO_OFFSET * path, APM_EXCP_STATUS_CLR_BIT);
600+
}
601+
602+
/**
603+
* @brief Enable/disable controller interrupt in CPU-APM
604+
*
605+
* @param path Access path
606+
* @param enable True to enable, false to disable
607+
*/
608+
static inline void apm_ll_cpu_apm_enable_ctrl_intr(apm_ctrl_access_path_t path, bool enable)
609+
{
610+
if (enable) {
611+
REG_SET_BIT(CPU_APM_INT_EN_REG, BIT(path));
612+
} else {
613+
REG_CLR_BIT(CPU_APM_INT_EN_REG, BIT(path));
614+
}
615+
}
616+
617+
/**
618+
* @brief Enable/disable controller clock gating in CPU-APM
619+
*
620+
* @param enable True to enable, false to disable
621+
*/
622+
static inline void apm_ll_cpu_apm_enable_ctrl_clk_gating(bool enable)
623+
{
624+
if (enable) {
625+
REG_CLR_BIT(CPU_APM_CLOCK_GATE_REG, CPU_APM_CLK_EN);
626+
} else {
627+
REG_SET_BIT(CPU_APM_CLOCK_GATE_REG, CPU_APM_CLK_EN);
628+
}
629+
}
630+
631+
/**
632+
* @brief Get controller interrupt source number from CPU-APM
633+
*
634+
* @param path Access path
635+
* @return Interrupt source number
636+
*/
637+
static inline int apm_ll_cpu_apm_get_ctrl_intr_src(apm_ctrl_access_path_t path)
638+
{
639+
return ETS_CPU_APM_M0_INTR_SOURCE + path;
640+
}
641+
451642
/**
452643
* @brief Enable/disable APM reset event bypass
453644
*

components/hal/include/hal/apm_hal.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,33 @@ void apm_hal_enable_ctrl_filter_all(bool enable);
253253
*/
254254
void apm_hal_enable_region_filter(apm_ctrl_module_t ctrl_mod, uint32_t regn_num, bool enable);
255255

256+
/**
257+
* @brief Set the start address for the given region
258+
*
259+
* @param ctrl_mod APM controller module
260+
* @param regn_num Region number
261+
* @param addr Address
262+
*/
263+
void apm_hal_set_region_start_addr(apm_ctrl_module_t ctrl_mod, uint32_t regn_num, uint32_t addr);
264+
265+
/**
266+
* @brief Set the end address for the given region
267+
*
268+
* @param ctrl_mod APM controller module
269+
* @param regn_num Region number
270+
* @param addr Address
271+
*/
272+
void apm_hal_set_region_end_addr(apm_ctrl_module_t ctrl_mod, uint32_t regn_num, uint32_t addr);
273+
274+
/**
275+
* @brief Set the permissions for the specified security mode for the given region
276+
*
277+
* @param ctrl_mod APM controller module
278+
* @param regn_num Region number
279+
* @param mode Security mode
280+
*/
281+
void apm_hal_set_sec_mode_region_attr(apm_ctrl_module_t ctrl_mod, uint32_t regn_num, apm_security_mode_t mode, uint32_t regn_pms);
282+
256283
/**
257284
* @brief Set region filter configuration
258285
*
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#This is the project CMakeLists.txt file for the test subproject
2+
cmake_minimum_required(VERSION 3.16)
3+
4+
# "Trim" the build. Include the minimal set of components, main, and anything it depends on.
5+
set(COMPONENTS main)
6+
7+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
8+
9+
project(test_tee_apm)
10+
11+
include($ENV{IDF_PATH}/tools/ci/check_register_rw_half_word.cmake)
12+
message(STATUS "Checking tee/apm registers are not read-write by half-word")
13+
check_register_rw_half_word(SOC_MODULES "*tee" # tee, lp_tee
14+
"*apm *apm0" # hp_apm, lp_apm, cpu_apm, lp_apm0
15+
HAL_MODULES "apm")

0 commit comments

Comments
 (0)