feat(esp_tee): Support for ESP32-C5 - the esp_tee component
This commit is contained in:
@@ -39,22 +39,37 @@ static void assert_valid_block(const heap_t *heap, const block_header_t *block)
|
||||
esp_err_t esp_tee_heap_init(void *start_ptr, size_t size)
|
||||
{
|
||||
assert(start_ptr);
|
||||
if (size < (tlsf_size() + tlsf_block_size_min() + sizeof(heap_t))) {
|
||||
// Region too small to be a heap.
|
||||
|
||||
heap_t *result = (heap_t *)start_ptr;
|
||||
size_t usable_size = size - sizeof(heap_t);
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
bool too_small = (usable_size < tlsf_size() + tlsf_block_size_min());
|
||||
#else
|
||||
bool too_small = (size < sizeof(heap_t));
|
||||
#endif
|
||||
|
||||
if (too_small) {
|
||||
return ESP_ERR_INVALID_SIZE;
|
||||
}
|
||||
|
||||
heap_t *result = (heap_t *)start_ptr;
|
||||
size -= sizeof(heap_t);
|
||||
#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
|
||||
void *heap = tlsf_create_with_pool(start_ptr + sizeof(heap_t), usable_size);
|
||||
size_t overhead = tlsf_size();
|
||||
#else
|
||||
size_t max_bytes = 0;
|
||||
void *heap = tlsf_create_with_pool(start_ptr + sizeof(heap_t), usable_size, max_bytes);
|
||||
size_t overhead = tlsf_size(heap);
|
||||
#endif
|
||||
|
||||
result->heap_data = tlsf_create_with_pool(start_ptr + sizeof(heap_t), size);
|
||||
if (result->heap_data == NULL) {
|
||||
if (heap == NULL) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
result->heap_data = heap;
|
||||
result->lock = NULL;
|
||||
result->free_bytes = size - tlsf_size();
|
||||
result->pool_size = size;
|
||||
result->free_bytes = usable_size - overhead;
|
||||
result->pool_size = usable_size;
|
||||
result->minimum_free_bytes = result->free_bytes;
|
||||
|
||||
tee_heap = (multi_heap_handle_t)result;
|
||||
|
||||
@@ -15,8 +15,17 @@
|
||||
#include "riscv/rv_utils.h"
|
||||
#include "riscv/rvruntime-frames.h"
|
||||
|
||||
#include "hal/cache_types.h"
|
||||
#include "hal/cache_ll.h"
|
||||
#include "hal/cache_hal.h"
|
||||
#include "hal/apm_hal.h"
|
||||
|
||||
#if SOC_INT_PLIC_SUPPORTED
|
||||
#include "soc/plic_reg.h"
|
||||
#elif SOC_INT_CLIC_SUPPORTED
|
||||
#include "soc/clic_reg.h"
|
||||
#endif
|
||||
|
||||
#include "esp_tee.h"
|
||||
#include "esp_tee_apm_intr.h"
|
||||
#include "esp_tee_rv_utils.h"
|
||||
@@ -32,11 +41,16 @@ static void tee_panic_end(void)
|
||||
rv_utils_tee_intr_global_disable();
|
||||
|
||||
// Disable the cache
|
||||
Cache_Disable_ICache();
|
||||
cache_hal_disable(CACHE_LL_LEVEL_EXT_MEM, CACHE_TYPE_ALL);
|
||||
|
||||
// Clear the interrupt controller configurations
|
||||
#if SOC_INT_PLIC_SUPPORTED
|
||||
memset((void *)DR_REG_PLIC_MX_BASE, 0x00, (PLIC_MXINT_CLAIM_REG + 4 - DR_REG_PLIC_MX_BASE));
|
||||
memset((void *)DR_REG_PLIC_UX_BASE, 0x00, (PLIC_UXINT_CLAIM_REG + 4 - DR_REG_PLIC_UX_BASE));
|
||||
#elif SOC_INT_CLIC_SUPPORTED
|
||||
memset((void *)DR_REG_CLIC_CTRL_BASE, 0x00, (REG_GET_FIELD(CLIC_INT_INFO_REG, CLIC_INT_INFO_NUM_INT)) * 4);
|
||||
REG_WRITE(CLIC_INT_THRESH_REG, 0x00);
|
||||
#endif
|
||||
|
||||
// Make sure all the panic handler output is sent from UART FIFO
|
||||
if (CONFIG_ESP_CONSOLE_UART_NUM >= 0) {
|
||||
|
||||
@@ -7,11 +7,12 @@
|
||||
#include "esp_attr.h"
|
||||
#include "esp_rom_sys.h"
|
||||
#include "esp_private/panic_reason.h"
|
||||
#include "esp_private/vectors_const.h"
|
||||
|
||||
#include "riscv/csr.h"
|
||||
#include "riscv/encoding.h"
|
||||
#include "riscv/rvruntime-frames.h"
|
||||
|
||||
#include "soc/tee_reg.h"
|
||||
#include "esp_tee.h"
|
||||
#include "panic_helper.h"
|
||||
#include "sdkconfig.h"
|
||||
@@ -60,16 +61,26 @@ void panic_print_registers(const void *f, int core)
|
||||
const char *name;
|
||||
uint32_t value;
|
||||
} csr_regs[] = {
|
||||
{ "MIE ", RV_READ_CSR(mie) },
|
||||
{ "MIP ", RV_READ_CSR(mip) },
|
||||
{ "MSCRATCH", RV_READ_CSR(mscratch) },
|
||||
{ "UEPC ", RV_READ_CSR(uepc) },
|
||||
{ "USTATUS ", RV_READ_CSR(ustatus) },
|
||||
{ "UTVEC ", RV_READ_CSR(utvec) },
|
||||
{ "UCAUSE ", RV_READ_CSR(ucause) },
|
||||
{ "UTVAL ", RV_READ_CSR(utval) },
|
||||
{ "UIE ", RV_READ_CSR(uie) },
|
||||
{ "UIP ", RV_READ_CSR(uip) },
|
||||
{ "MSCRATCH ", RV_READ_CSR(mscratch) },
|
||||
{ "UEPC ", RV_READ_CSR(uepc) },
|
||||
{ "USTATUS ", RV_READ_CSR(ustatus) },
|
||||
{ "UTVEC ", RV_READ_CSR(utvec) },
|
||||
{ "UCAUSE ", RV_READ_CSR(ucause) },
|
||||
#if CONFIG_IDF_TARGET_ESP32C6
|
||||
{ "MIE ", RV_READ_CSR(mie) },
|
||||
{ "MIP ", RV_READ_CSR(mip) },
|
||||
{ "UTVAL ", RV_READ_CSR(utval) },
|
||||
{ "UIE ", RV_READ_CSR(uie) },
|
||||
{ "UIP ", RV_READ_CSR(uip) },
|
||||
#endif
|
||||
#if CONFIG_IDF_TARGET_ESP32C5
|
||||
{ "USCRATCH ", RV_READ_CSR(0x040) },
|
||||
{ "MEXSTATUS ", RV_READ_CSR(0x7E1) },
|
||||
{ "MINTSTATUS", RV_READ_CSR(0xFB1) },
|
||||
{ "MINTTHRESH", RV_READ_CSR(0x347) },
|
||||
{ "UINTSTATUS", RV_READ_CSR(0xCB1) },
|
||||
{ "UINTTHRESH", RV_READ_CSR(0x047) },
|
||||
#endif
|
||||
};
|
||||
|
||||
tee_panic_print("\n\n");
|
||||
@@ -116,9 +127,10 @@ void panic_print_exccause(const void *f, int core)
|
||||
};
|
||||
|
||||
const char *rsn = NULL;
|
||||
if (regs->mcause < (sizeof(reason) / sizeof(reason[0]))) {
|
||||
if (reason[regs->mcause] != NULL) {
|
||||
rsn = (reason[regs->mcause]);
|
||||
uint32_t mcause = regs->mcause & (VECTORS_MCAUSE_INTBIT_MASK | VECTORS_MCAUSE_REASON_MASK);
|
||||
if (mcause < (sizeof(reason) / sizeof(reason[0]))) {
|
||||
if (reason[mcause] != NULL) {
|
||||
rsn = (reason[mcause]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user