Skip to content

Commit

Permalink
Merge branch 'bugfix/memprot_cleanup_iram_attr' into 'master'
Browse files Browse the repository at this point in the history
memprot: move memprot functions out of IRAM

See merge request espressif/esp-idf!20697
  • Loading branch information
ESP-Marius committed Mar 28, 2023
2 parents 39087f3 + 43784e7 commit a5c70c2
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 481 deletions.
440 changes: 0 additions & 440 deletions components/esp_hw_support/include/soc/esp32c2/memprot.h

This file was deleted.

8 changes: 4 additions & 4 deletions components/esp_hw_support/include/soc/esp32s2/memprot.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ typedef enum {
* The address is given by region-specific global symbol exported from linker script,
* it is not read out from related configuration register.
*/
uint32_t *IRAM_ATTR esp_memprot_get_split_addr(mem_type_prot_t mem_type);
uint32_t * esp_memprot_get_split_addr(mem_type_prot_t mem_type);

/**
* @brief Initializes illegal memory access control for required memory section.
Expand Down Expand Up @@ -116,7 +116,7 @@ esp_err_t esp_memprot_clear_intr(mem_type_prot_t mem_type);
*
* @return Memory protection area type (see mem_type_prot_t enum)
*/
mem_type_prot_t IRAM_ATTR esp_memprot_get_active_intr_memtype(void);
mem_type_prot_t esp_memprot_get_active_intr_memtype(void);

/**
* @brief Gets interrupt status register contents for specified memory region
Expand All @@ -141,7 +141,7 @@ esp_err_t esp_memprot_get_fault_reg(mem_type_prot_t mem_type, uint32_t *fault_re
* DRAM0: 0 - non-atomic operation, 1 - atomic operation
* @return ESP_OK on success, ESP_ERR_INVALID_ARG on failure
*/
esp_err_t IRAM_ATTR esp_memprot_get_fault_status(mem_type_prot_t mem_type, uint32_t **faulting_address, uint32_t *op_type, uint32_t *op_subtype);
esp_err_t esp_memprot_get_fault_status(mem_type_prot_t mem_type, uint32_t **faulting_address, uint32_t *op_type, uint32_t *op_subtype);

/**
* @brief Gets string representation of required memory region identifier
Expand All @@ -150,7 +150,7 @@ esp_err_t IRAM_ATTR esp_memprot_get_fault_status(mem_type_prot_t mem_type, uint3
*
* @return mem_type as string
*/
const char *IRAM_ATTR esp_memprot_type_to_str(mem_type_prot_t mem_type);
const char * esp_memprot_type_to_str(mem_type_prot_t mem_type);

/**
* @brief Detects whether any of the interrupt locks is active (requires digital system reset to unlock)
Expand Down
18 changes: 9 additions & 9 deletions components/esp_hw_support/port/esp32c3/esp_memprot.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ esp_err_t esp_mprot_get_monitor_en(const esp_mprot_mem_t mem_type, bool *enabled
return ESP_OK;
}

esp_err_t IRAM_ATTR esp_mprot_monitor_clear_intr(const esp_mprot_mem_t mem_type, const int core __attribute__((unused)))
esp_err_t esp_mprot_monitor_clear_intr(const esp_mprot_mem_t mem_type, const int core __attribute__((unused)))
{
switch (mem_type) {
case MEMPROT_TYPE_IRAM0_SRAM:
Expand All @@ -433,7 +433,7 @@ esp_err_t IRAM_ATTR esp_mprot_monitor_clear_intr(const esp_mprot_mem_t mem_type,
return ESP_OK;
}

esp_err_t IRAM_ATTR esp_mprot_get_active_intr(esp_memp_intr_source_t *active_memp_intr)
esp_err_t esp_mprot_get_active_intr(esp_memp_intr_source_t *active_memp_intr)
{
if (active_memp_intr == NULL) {
return ESP_ERR_INVALID_ARG;
Expand All @@ -454,7 +454,7 @@ esp_err_t IRAM_ATTR esp_mprot_get_active_intr(esp_memp_intr_source_t *active_mem
return ESP_OK;
}

esp_err_t IRAM_ATTR esp_mprot_is_conf_locked_any(bool *locked)
esp_err_t esp_mprot_is_conf_locked_any(bool *locked)
{
if (locked == NULL) {
return ESP_ERR_INVALID_ARG;
Expand All @@ -481,7 +481,7 @@ esp_err_t IRAM_ATTR esp_mprot_is_conf_locked_any(bool *locked)
return ESP_OK;
}

esp_err_t IRAM_ATTR esp_mprot_is_intr_ena_any(bool *enabled)
esp_err_t esp_mprot_is_intr_ena_any(bool *enabled)
{
if (enabled == NULL) {
return ESP_ERR_INVALID_ARG;
Expand All @@ -500,7 +500,7 @@ esp_err_t IRAM_ATTR esp_mprot_is_intr_ena_any(bool *enabled)
return ESP_OK;
}

esp_err_t IRAM_ATTR esp_mprot_get_violate_addr(const esp_mprot_mem_t mem_type, void **fault_addr, const int core __attribute__((unused)))
esp_err_t esp_mprot_get_violate_addr(const esp_mprot_mem_t mem_type, void **fault_addr, const int core __attribute__((unused)))
{
if (fault_addr == NULL) {
return ESP_ERR_INVALID_ARG;
Expand All @@ -523,7 +523,7 @@ esp_err_t IRAM_ATTR esp_mprot_get_violate_addr(const esp_mprot_mem_t mem_type, v
return ESP_OK;
}

esp_err_t IRAM_ATTR esp_mprot_get_violate_world(const esp_mprot_mem_t mem_type, esp_mprot_pms_world_t *world, const int core __attribute__((unused)))
esp_err_t esp_mprot_get_violate_world(const esp_mprot_mem_t mem_type, esp_mprot_pms_world_t *world, const int core __attribute__((unused)))
{
if (world == NULL) {
return ESP_ERR_INVALID_ARG;
Expand Down Expand Up @@ -553,7 +553,7 @@ esp_err_t IRAM_ATTR esp_mprot_get_violate_world(const esp_mprot_mem_t mem_type,
return ESP_OK;
}

esp_err_t IRAM_ATTR esp_mprot_get_violate_operation(const esp_mprot_mem_t mem_type, uint32_t *oper, const int core __attribute__((unused)))
esp_err_t esp_mprot_get_violate_operation(const esp_mprot_mem_t mem_type, uint32_t *oper, const int core __attribute__((unused)))
{
if (oper == NULL) {
return ESP_ERR_INVALID_ARG;
Expand Down Expand Up @@ -587,12 +587,12 @@ esp_err_t IRAM_ATTR esp_mprot_get_violate_operation(const esp_mprot_mem_t mem_ty
return ESP_OK;
}

bool IRAM_ATTR esp_mprot_has_byte_enables(const esp_mprot_mem_t mem_type)
bool esp_mprot_has_byte_enables(const esp_mprot_mem_t mem_type)
{
return mem_type == MEMPROT_TYPE_DRAM0_SRAM;
}

esp_err_t IRAM_ATTR esp_mprot_get_violate_byte_enables(const esp_mprot_mem_t mem_type, uint32_t *byte_en, const int core __attribute__((unused)))
esp_err_t esp_mprot_get_violate_byte_enables(const esp_mprot_mem_t mem_type, uint32_t *byte_en, const int core __attribute__((unused)))
{
if (byte_en == NULL) {
return ESP_ERR_INVALID_ARG;
Expand Down
18 changes: 9 additions & 9 deletions components/esp_hw_support/port/esp32h4/esp_memprot.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ esp_err_t esp_mprot_get_monitor_en(const esp_mprot_mem_t mem_type, bool *enabled
return ESP_OK;
}

esp_err_t IRAM_ATTR esp_mprot_monitor_clear_intr(const esp_mprot_mem_t mem_type, const int core __attribute__((unused)))
esp_err_t esp_mprot_monitor_clear_intr(const esp_mprot_mem_t mem_type, const int core __attribute__((unused)))
{
return ESP_OK;
}

esp_err_t IRAM_ATTR esp_mprot_get_active_intr(esp_memp_intr_source_t *active_memp_intr)
esp_err_t esp_mprot_get_active_intr(esp_memp_intr_source_t *active_memp_intr)
{
if (active_memp_intr == NULL) {
return ESP_ERR_INVALID_ARG;
Expand All @@ -138,7 +138,7 @@ esp_err_t IRAM_ATTR esp_mprot_get_active_intr(esp_memp_intr_source_t *active_mem
return ESP_OK;
}

esp_err_t IRAM_ATTR esp_mprot_is_conf_locked_any(bool *locked)
esp_err_t esp_mprot_is_conf_locked_any(bool *locked)
{
if (locked == NULL) {
return ESP_ERR_INVALID_ARG;
Expand All @@ -149,7 +149,7 @@ esp_err_t IRAM_ATTR esp_mprot_is_conf_locked_any(bool *locked)
return ESP_OK;
}

esp_err_t IRAM_ATTR esp_mprot_is_intr_ena_any(bool *enabled)
esp_err_t esp_mprot_is_intr_ena_any(bool *enabled)
{
if (enabled == NULL) {
return ESP_ERR_INVALID_ARG;
Expand All @@ -160,7 +160,7 @@ esp_err_t IRAM_ATTR esp_mprot_is_intr_ena_any(bool *enabled)
return ESP_OK;
}

esp_err_t IRAM_ATTR esp_mprot_get_violate_addr(const esp_mprot_mem_t mem_type, void **fault_addr, const int core __attribute__((unused)))
esp_err_t esp_mprot_get_violate_addr(const esp_mprot_mem_t mem_type, void **fault_addr, const int core __attribute__((unused)))
{
if (fault_addr == NULL) {
return ESP_ERR_INVALID_ARG;
Expand All @@ -171,7 +171,7 @@ esp_err_t IRAM_ATTR esp_mprot_get_violate_addr(const esp_mprot_mem_t mem_type, v
return ESP_OK;
}

esp_err_t IRAM_ATTR esp_mprot_get_violate_world(const esp_mprot_mem_t mem_type, esp_mprot_pms_world_t *world, const int core __attribute__((unused)))
esp_err_t esp_mprot_get_violate_world(const esp_mprot_mem_t mem_type, esp_mprot_pms_world_t *world, const int core __attribute__((unused)))
{
if (world == NULL) {
return ESP_ERR_INVALID_ARG;
Expand All @@ -182,7 +182,7 @@ esp_err_t IRAM_ATTR esp_mprot_get_violate_world(const esp_mprot_mem_t mem_type,
return ESP_OK;
}

esp_err_t IRAM_ATTR esp_mprot_get_violate_operation(const esp_mprot_mem_t mem_type, uint32_t *oper, const int core __attribute__((unused)))
esp_err_t esp_mprot_get_violate_operation(const esp_mprot_mem_t mem_type, uint32_t *oper, const int core __attribute__((unused)))
{
if (oper == NULL) {
return ESP_ERR_INVALID_ARG;
Expand All @@ -193,12 +193,12 @@ esp_err_t IRAM_ATTR esp_mprot_get_violate_operation(const esp_mprot_mem_t mem_ty
return ESP_OK;
}

bool IRAM_ATTR esp_mprot_has_byte_enables(const esp_mprot_mem_t mem_type)
bool esp_mprot_has_byte_enables(const esp_mprot_mem_t mem_type)
{
return false;
}

esp_err_t IRAM_ATTR esp_mprot_get_violate_byte_enables(const esp_mprot_mem_t mem_type, uint32_t *byte_en, const int core __attribute__((unused)))
esp_err_t esp_mprot_get_violate_byte_enables(const esp_mprot_mem_t mem_type, uint32_t *byte_en, const int core __attribute__((unused)))
{
if (byte_en == NULL) {
return ESP_ERR_INVALID_ARG;
Expand Down
18 changes: 9 additions & 9 deletions components/esp_hw_support/port/esp32s3/esp_memprot.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ esp_err_t esp_mprot_get_monitor_en(esp_mprot_mem_t mem_type, bool *enabled, cons
//////////////////////////////////////////////////////////////////////////////
// PMS-violation interrupt handling APIs (IRAM section - called from panic-handler)

esp_err_t IRAM_ATTR esp_mprot_get_active_intr(esp_memp_intr_source_t *active_memp_intr)
esp_err_t esp_mprot_get_active_intr(esp_memp_intr_source_t *active_memp_intr)
{
if (active_memp_intr == NULL) {
return ESP_ERR_INVALID_ARG;
Expand Down Expand Up @@ -601,7 +601,7 @@ esp_err_t IRAM_ATTR esp_mprot_get_active_intr(esp_memp_intr_source_t *active_mem
return ESP_OK;
}

esp_err_t IRAM_ATTR esp_mprot_monitor_clear_intr(esp_mprot_mem_t mem_type, const int core)
esp_err_t esp_mprot_monitor_clear_intr(esp_mprot_mem_t mem_type, const int core)
{
esp_err_t err;
ESP_MEMPROT_ERR_CHECK(err, esp_mprot_cpuid_valid(core))
Expand All @@ -626,7 +626,7 @@ esp_err_t IRAM_ATTR esp_mprot_monitor_clear_intr(esp_mprot_mem_t mem_type, const
return ESP_OK;
}

esp_err_t IRAM_ATTR esp_mprot_is_conf_locked_any(bool *locked)
esp_err_t esp_mprot_is_conf_locked_any(bool *locked)
{
if (locked == NULL) {
return ESP_ERR_INVALID_ARG;
Expand Down Expand Up @@ -695,7 +695,7 @@ esp_err_t IRAM_ATTR esp_mprot_is_conf_locked_any(bool *locked)
return ESP_OK;
}

esp_err_t IRAM_ATTR esp_mprot_is_intr_ena_any(bool *enabled)
esp_err_t esp_mprot_is_intr_ena_any(bool *enabled)
{
if (enabled == NULL) {
return ESP_ERR_INVALID_ARG;
Expand Down Expand Up @@ -740,7 +740,7 @@ esp_err_t IRAM_ATTR esp_mprot_is_intr_ena_any(bool *enabled)
return ESP_OK;
}

esp_err_t IRAM_ATTR esp_mprot_get_violate_addr(const esp_mprot_mem_t mem_type, void **fault_addr, const int core)
esp_err_t esp_mprot_get_violate_addr(const esp_mprot_mem_t mem_type, void **fault_addr, const int core)
{
if (fault_addr == NULL) {
return ESP_ERR_INVALID_ARG;
Expand Down Expand Up @@ -770,7 +770,7 @@ esp_err_t IRAM_ATTR esp_mprot_get_violate_addr(const esp_mprot_mem_t mem_type, v
return ESP_OK;
}

esp_err_t IRAM_ATTR esp_mprot_get_violate_world(const esp_mprot_mem_t mem_type, esp_mprot_pms_world_t *world, const int core)
esp_err_t esp_mprot_get_violate_world(const esp_mprot_mem_t mem_type, esp_mprot_pms_world_t *world, const int core)
{
if (world == NULL) {
return ESP_ERR_INVALID_ARG;
Expand Down Expand Up @@ -804,7 +804,7 @@ esp_err_t IRAM_ATTR esp_mprot_get_violate_world(const esp_mprot_mem_t mem_type,
return ESP_OK;
}

esp_err_t IRAM_ATTR esp_mprot_get_violate_operation(const esp_mprot_mem_t mem_type, uint32_t *oper, const int core)
esp_err_t esp_mprot_get_violate_operation(const esp_mprot_mem_t mem_type, uint32_t *oper, const int core)
{
if (oper == NULL) {
return ESP_ERR_INVALID_ARG;
Expand Down Expand Up @@ -849,12 +849,12 @@ esp_err_t IRAM_ATTR esp_mprot_get_violate_operation(const esp_mprot_mem_t mem_ty
return ESP_OK;
}

bool IRAM_ATTR esp_mprot_has_byte_enables(const esp_mprot_mem_t mem_type)
bool esp_mprot_has_byte_enables(const esp_mprot_mem_t mem_type)
{
return mem_type == MEMPROT_TYPE_DRAM0_SRAM;
}

esp_err_t IRAM_ATTR esp_mprot_get_violate_byte_enables(const esp_mprot_mem_t mem_type, uint32_t *byte_en, const int core)
esp_err_t esp_mprot_get_violate_byte_enables(const esp_mprot_mem_t mem_type, uint32_t *byte_en, const int core)
{
if (byte_en == NULL) {
return ESP_ERR_INVALID_ARG;
Expand Down
4 changes: 1 addition & 3 deletions components/esp_system/esp_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#if CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
#if CONFIG_IDF_TARGET_ESP32S2
#include "esp32s2/memprot.h"
#elif CONFIG_IDF_TARGET_ESP32C2
#include "esp32c2/memprot.h"
#else
#include "esp_memprot.h"
#endif
Expand Down Expand Up @@ -47,7 +45,7 @@ esp_err_t esp_unregister_shutdown_handler(shutdown_handler_t handler)
}


void IRAM_ATTR esp_restart(void)
void esp_restart(void)
{
for (int i = SHUTDOWN_HANDLERS_NO - 1; i >= 0; i--) {
if (shutdown_handlers[i]) {
Expand Down
4 changes: 0 additions & 4 deletions components/esp_system/port/arch/riscv/panic_arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@
#include "soc/timer_periph.h"

#if CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
#if CONFIG_IDF_TARGET_ESP32C2
#include "esp32c2/memprot.h"
#else
#include "esp_private/esp_memprot_internal.h"
#include "esp_memprot.h"
#endif
#endif

#if CONFIG_ESP_SYSTEM_USE_EH_FRAME
#include "esp_private/eh_frame_parser.h"
Expand Down
1 change: 0 additions & 1 deletion components/esp_system/port/cpu_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
#include "esp32c2/rom/cache.h"
#include "esp32c2/rom/rtc.h"
#include "esp32c2/rom/secure_boot.h"
#include "esp32c2/memprot.h"
#endif

#include "esp_private/esp_mmu_map_private.h"
Expand Down
2 changes: 0 additions & 2 deletions components/esp_system/port/panic_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
#if CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
#ifdef CONFIG_IDF_TARGET_ESP32S2
#include "esp32s2/memprot.h"
#elif CONFIG_IDF_TARGET_ESP32C2
#include "esp32c2/memprot.h"
#else
#include "esp_memprot.h"
#endif
Expand Down

0 comments on commit a5c70c2

Please sign in to comment.