1 /* 2 * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #pragma once 8 9 #include "sdkconfig.h" 10 #if CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_MEMPROT_TEST 11 12 #include <stdbool.h> 13 #include <stdint.h> 14 #include "esp_err.h" 15 #include "esp_memprot_err.h" 16 #include "hal/memprot_types.h" 17 #include "soc_memprot_types.h" 18 #include "esp_memprot_types.h" 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 /** 25 * @brief Convert Memprot low level errors to esp_err_t 26 */ 27 esp_err_t esp_mprot_ll_err_to_esp_err(const memprot_ll_err_t err); 28 29 /** 30 * @brief Convert Memprot low level PMS World IDs to esp_mprot_pms_world_t 31 */ 32 esp_mprot_pms_world_t esp_mprot_ll_world_to_hl_world(const memprot_ll_world_t world); 33 34 /** 35 * @brief Converts operation type to string, no combination of operations allowed 36 * 37 * @param oper_type PMS operation type 38 */ 39 const char *esp_mprot_oper_type_to_str(const uint32_t oper_type); 40 41 /** 42 * @brief Converts PMS World type to string 43 * 44 * @param area_type PMS World type 45 */ 46 const char *esp_mprot_pms_world_to_str(const esp_mprot_pms_world_t world_type); 47 48 /** 49 * @brief Sets splitting address for given line type in the target Memory type 50 * 51 * @param mem_type memory type 52 * @param line_type split address type 53 * @param line_addr target address from a memory range relevant to given line_addr 54 * 55 * @return ESP_OK on success 56 * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type 57 * ESP_ERR_MEMPROT_SPLIT_ADDR_INVALID on invalid line_type 58 * ESP_ERR_MEMPROT_SPLIT_ADDR_OUT_OF_RANGE on splitting line out of given memory-type range 59 * ESP_ERR_MEMPROT_SPLIT_ADDR_UNALIGNED on splitting line not aligned to PMS-required boundaries 60 */ 61 esp_err_t esp_mprot_set_split_addr(const esp_mprot_mem_t mem_type, const esp_mprot_split_addr_t line_type, const void *line_addr); 62 63 /** 64 * @brief Gets PMS splitting address for given split_addr type 65 * 66 * The value is read from the PMS configuration registers 67 * 68 * @param mem_type memory type 69 * @param line_type Split line type (see esp_mprot_split_addr_t enum) 70 * @param[out] line_addr Split line address from the configuration register 71 * 72 * @return ESP_OK on success 73 * ESP_ERR_INVALID_ARG on line_addr is pointer 74 * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type 75 * ESP_ERR_MEMPROT_SPLIT_ADDR_INVALID on invalid line_type 76 */ 77 esp_err_t esp_mprot_get_split_addr(const esp_mprot_mem_t mem_type, const esp_mprot_split_addr_t line_type, void **line_addr); 78 79 /** 80 * @brief Returns default main I/D splitting address for given Memory type 81 * 82 * @param mem_type memory type 83 * @param[out] def_split_addr Main I/D splitting address of required mem_type 84 * 85 * @return ESP_OK on success 86 * ESP_ERR_INVALID_ARG on invalid def_split_addr pointer 87 * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type 88 */ 89 esp_err_t esp_mprot_get_default_main_split_addr(const esp_mprot_mem_t mem_type, void **def_split_addr); 90 91 /** 92 * @brief Sets a lock for the main IRAM/DRAM splitting addresses 93 * Locks can be unlocked only by digital system reset 94 * 95 * @param mem_type memory type 96 * 97 * @return ESP_OK on success 98 * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type 99 */ 100 esp_err_t esp_mprot_set_split_addr_lock(const esp_mprot_mem_t mem_type); 101 102 /** 103 * @brief Gets a lock status for the splitting address configuration of given Memory type 104 * 105 * @param mem_type memory type 106 * @param[out] locked mem_type related lock status 107 * 108 * @return ESP_OK on success 109 * ESP_ERR_INVALID_ARGUMENT on invalid locked pointer 110 * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type 111 */ 112 esp_err_t esp_mprot_get_split_addr_lock(const esp_mprot_mem_t mem_type, bool *locked); 113 114 /** 115 * @brief Sets a lock for PMS Area settings of required Memory type 116 * Locks can be unlocked only by digital system reset 117 * 118 * @param mem_type memory type 119 * 120 * @return ESP_OK on success 121 * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type 122 */ 123 esp_err_t esp_mprot_set_pms_lock(const esp_mprot_mem_t mem_type); 124 125 /** 126 * @brief Gets a lock status for PMS Area settings of required Memory type 127 * 128 * @param mem_type memory type 129 * @param[out] locked mem_type related lock status 130 * 131 * @return ESP_OK on success 132 * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type 133 * ESP_ERR_INVALID_ARGUMENT on invalid locked pointer 134 */ 135 esp_err_t esp_mprot_get_pms_lock(const esp_mprot_mem_t mem_type, bool *locked); 136 137 /** 138 * @brief Sets permissions for given PMS Area 139 * 140 * @param area_type PMS area type 141 * @param flags combination of MEMPROT_OP_* defines 142 * 143 * @return ESP_OK on success 144 * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type 145 */ 146 esp_err_t esp_mprot_set_pms_area(const esp_mprot_pms_area_t area_type, const uint32_t flags); 147 148 /** 149 * @brief Gets current permissions for given PMS Area 150 * 151 * @param area_type PMS area type 152 * @param[out] flags combination of MEMPROT_OP_* defines 153 * 154 * @return ESP_OK on success 155 * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type 156 * ESP_ERR_INVALID_ARG on invalid flags pointer 157 */ 158 esp_err_t esp_mprot_get_pms_area(const esp_mprot_pms_area_t area_type, uint32_t *flags); 159 160 /** 161 * @brief Sets a lock for PMS interrupt monitor settings of required Memory type 162 * 163 * Locks can be unlocked only by digital system reset 164 * 165 * @param mem_type memory type (see esp_mprot_mem_t enum) 166 * 167 * @return ESP_OK on success 168 * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type 169 */ 170 esp_err_t esp_mprot_set_monitor_lock(const esp_mprot_mem_t mem_type); 171 172 /** 173 * @brief Gets a lock status for PMS interrupt monitor settings of required Memory type 174 * 175 * @param mem_type memory type 176 * @param[out] locked mem_type related lock status 177 * 178 * @return ESP_OK on success 179 * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type 180 * ESP_ERR_INVALID_ARG on invalid locked pointer 181 */ 182 esp_err_t esp_mprot_get_monitor_lock(const esp_mprot_mem_t mem_type, bool *locked); 183 184 /** 185 * @brief Enable PMS violation interrupt monitoring of required Memory type 186 * 187 * @param mem_type memory type 188 * @param enable enable/disable violation interrupt monitoring 189 * 190 * @return ESP_OK on success 191 * ESP_ERR_MEMPROT_MEMORY_TYPE_INVALID on invalid mem_type 192 */ 193 esp_err_t esp_mprot_set_monitor_en(const esp_mprot_mem_t mem_type, const bool enable); 194 195 #ifdef __cplusplus 196 } 197 #endif 198 199 #endif //CONFIG_ESP_SYSTEM_MEMPROT_FEATURE || CONFIG_ESP_SYSTEM_MEMPROT_TEST 200