arch/xtensa/src/esp32: Extract the IRAM region as a separate heap.

Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
This commit is contained in:
Abdelatif Guettouche
2021-06-18 19:13:18 +01:00
committed by Masayuki Ishikawa
parent 1719e9df94
commit 1e49f2929f
13 changed files with 360 additions and 22 deletions
+1
View File
@@ -185,6 +185,7 @@ endif
endif
ifeq ($(CONFIG_ARCH_USE_TEXT_HEAP),y)
CHIP_CSRCS += esp32_iramheap.c
CHIP_CSRCS += esp32_textheap.c
CMN_ASRCS += xtensa_loadstore.S
endif
+191
View File
@@ -0,0 +1,191 @@
/****************************************************************************
* arch/xtensa/src/esp32/esp32_iramheap.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/arch.h>
#include <nuttx/fs/procfs.h>
#include <nuttx/mm/mm.h>
#include <malloc.h>
#include "esp32_iramheap.h"
/****************************************************************************
* Private Data
****************************************************************************/
static struct mm_heap_s g_iramheap;
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: esp32_iramheap_initialize
*
* Description:
* Initialize the IRAM heap.
*
****************************************************************************/
void esp32_iramheap_initialize(void)
{
void *start;
size_t size;
/* These values come from the linker scripts. Check boards/xtensa/esp32. */
extern uint8_t *_siramheap;
extern uint8_t *_eiramheap;
start = (void *)&_siramheap;
size = (size_t)((uintptr_t)&_eiramheap - (uintptr_t)&_siramheap);
mm_initialize(&g_iramheap, start, size);
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO)
static struct procfs_meminfo_entry_s g_iram_procfs;
g_iram_procfs.name = "iramheap";
g_iram_procfs.mallinfo = (void *)mm_mallinfo;
g_iram_procfs.user_data = &g_iramheap;
procfs_register_meminfo(&g_iram_procfs);
#endif
}
/****************************************************************************
* Name: esp32_iramheap_malloc
*
* Description:
* Allocate memory from the IRAM heap.
*
****************************************************************************/
void *esp32_iramheap_malloc(size_t size)
{
return mm_malloc(&g_iramheap, size);
}
/****************************************************************************
* Name: esp32_iramheap_calloc
*
* Description:
* Calculates the size of the allocation and allocate memory from
* the IRAM heap.
*
****************************************************************************/
void *esp32_iramheap_calloc(size_t n, size_t elem_size)
{
return mm_calloc(&g_iramheap, n, elem_size);
}
/****************************************************************************
* Name: esp32_iramheap_realloc
*
* Description:
* Reallocate memory from the IRAM heap.
*
****************************************************************************/
void *esp32_iramheap_realloc(void *ptr, size_t size)
{
return mm_realloc(&g_iramheap, ptr, size);
}
/****************************************************************************
* Name: esp32_iramheap_zalloc
*
* Description:
* Allocate and zero memory from the IRAM heap.
*
****************************************************************************/
void *esp32_iramheap_zalloc(size_t size)
{
return mm_zalloc(&g_iramheap, size);
}
/****************************************************************************
* Name: esp32_iramheap_free
*
* Description:
* Free memory from the IRAM heap.
*
****************************************************************************/
void esp32_iramheap_free(void *mem)
{
mm_free(&g_iramheap, mem);
}
/****************************************************************************
* Name: esp32_iramheap_memalign
*
* Description:
* memalign requests more than enough space from malloc, finds a region
* within that chunk that meets the alignment request and then frees any
* leading or trailing space.
*
* The alignment argument must be a power of two (not checked). 8-byte
* alignment is guaranteed by normal malloc calls.
*
****************************************************************************/
void *esp32_iramheap_memalign(size_t alignment, size_t size)
{
return mm_memalign(&g_iramheap, alignment, size);
}
/****************************************************************************
* Name: esp32_iramheap_heapmember
*
* Description:
* Check if an address lies in the IRAM heap.
*
* Parameters:
* mem - The address to check
*
* Return Value:
* true if the address is a member of the IRAM heap. false if not
*
****************************************************************************/
bool esp32_iramheap_heapmember(void *mem)
{
return mm_heapmember(&g_iramheap, mem);
}
/****************************************************************************
* Name: esp32_iramheap_mallinfo
*
* Description:
* mallinfo returns a copy of updated current heap information for the
* user heap.
*
****************************************************************************/
int esp32_iramheap_mallinfo(struct mallinfo *info)
{
return mm_mallinfo(&g_iramheap, info);
}
+146
View File
@@ -0,0 +1,146 @@
/****************************************************************************
* arch/xtensa/src/esp32/esp32_iramheap.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __ARCH_XTENSA_SRC_ESP32_ESP32_IRAMHEAP_H
#define __ARCH_XTENSA_SRC_ESP32_ESP32_IRAMHEAP_H
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
struct mallinfo; /* Forward reference, see malloc.h */
/****************************************************************************
* Name: esp32_iramheap_initialize
*
* Description:
* Initialize the IRAM heap.
*
****************************************************************************/
void esp32_iramheap_initialize(void);
/****************************************************************************
* Name: esp32_iramheap_malloc
*
* Description:
* Allocate memory from the IRAM heap.
*
****************************************************************************/
void *esp32_iramheap_malloc(size_t size);
/****************************************************************************
* Name: esp32_iramheap_calloc
*
* Description:
* Calculates the size of the allocation and allocate memory from
* the IRAM heap.
*
****************************************************************************/
void *esp32_iramheap_calloc(size_t n, size_t elem_size);
/****************************************************************************
* Name: esp32_iramheap_realloc
*
* Description:
* Reallocate memory from the IRAM heap.
*
****************************************************************************/
void *esp32_iramheap_realloc(void *ptr, size_t size);
/****************************************************************************
* Name: esp32_iramheap_zalloc
*
* Description:
* Allocate and zero memory from the IRAM heap.
*
****************************************************************************/
void *esp32_iramheap_zalloc(size_t size);
/****************************************************************************
* Name: esp32_iramheap_free
*
* Description:
* Free memory from the IRAM heap.
*
****************************************************************************/
void esp32_iramheap_free(void *mem);
/****************************************************************************
* Name: esp32_iramheap_memalign
*
* Description:
* memalign requests more than enough space from malloc, finds a region
* within that chunk that meets the alignment request and then frees any
* leading or trailing space.
*
* The alignment argument must be a power of two (not checked). 8-byte
* alignment is guaranteed by normal malloc calls.
*
****************************************************************************/
void *esp32_iramheap_memalign(size_t alignment, size_t size);
/****************************************************************************
* Name: esp32_iramheap_heapmember
*
* Description:
* Check if an address lies in the IRAM heap.
*
* Parameters:
* mem - The address to check
*
* Return Value:
* true if the address is a member of the IRAM heap. false if not
*
****************************************************************************/
bool esp32_iramheap_heapmember(void *mem);
/****************************************************************************
* Name: esp32_iramheap_mallinfo
*
* Description:
* mallinfo returns a copy of updated current heap information for the
* user heap.
*
****************************************************************************/
int esp32_iramheap_mallinfo(struct mallinfo *info);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __ARCH_XTENSA_SRC_ESP32_ESP32_IRAMHEAP_H */
+4 -4
View File
@@ -39,8 +39,8 @@
****************************************************************************/
#ifdef CONFIG_ARCH_USE_TEXT_HEAP
extern uint32_t _stextheap;
extern uint32_t _etextheap;
extern uint32_t _siramheap;
extern uint32_t _eiramheap;
#endif
/****************************************************************************
@@ -338,8 +338,8 @@ uint32_t *xtensa_user(int exccause, uint32_t *regs)
*/
if (exccause == XCHAL_EXCCAUSE_LOAD_STORE_ERROR &&
(uintptr_t)&_stextheap <= regs[REG_EXCVADDR] &&
(uintptr_t)&_etextheap > regs[REG_EXCVADDR])
(uintptr_t)&_siramheap <= regs[REG_EXCVADDR] &&
(uintptr_t)&_eiramheap > regs[REG_EXCVADDR])
{
uint8_t *pc = (uint8_t *)regs[REG_PC];
uint8_t imm8;
@@ -78,9 +78,9 @@ MEMORY
_eheap = 0x40000000 - CONFIG_ESP32_TRACEMEM_RESERVE_DRAM;
/* Text heap ends at top of dram0_0_seg */
/* IRAM heap ends at top of dram0_0_seg */
_etextheap = 0x400a0000;
_eiramheap = 0x400a0000;
/* Mark the end of the RTC heap (top of the RTC region) */
@@ -63,10 +63,10 @@ SECTIONS
*(.phyiram .phyiram.*)
_iram_text_end = ABSOLUTE(.);
/* Text heap starts at the end of iram0_0_seg */
/* IRAM heap starts at the end of iram0_0_seg */
. = ALIGN (4);
_stextheap = ABSOLUTE(.);
_siramheap = ABSOLUTE(.);
} > iram0_0_seg
/* Shared RAM */
@@ -70,10 +70,10 @@ SECTIONS
_text_end = ABSOLUTE(.);
_etext = .;
/* Text heap starts at the end of iram0_0_seg */
/* IRAM heap starts at the end of iram0_0_seg */
. = ALIGN (4);
_stextheap = ABSOLUTE(.);
_siramheap = ABSOLUTE(.);
} > iram0_0_seg
/* Shared RAM */
@@ -78,9 +78,9 @@ MEMORY
_eheap = 0x40000000 - CONFIG_ESP32_TRACEMEM_RESERVE_DRAM;
/* Text heap ends at top of dram0_0_seg */
/* IRAM heap ends at top of dram0_0_seg */
_etextheap = 0x400a0000;
_eiramheap = 0x400a0000;
/* Mark the end of the RTC heap (top of the RTC region) */
@@ -66,10 +66,10 @@ SECTIONS
*(.phyiram .phyiram.*)
_iram_text_end = ABSOLUTE(.);
/* Text heap starts at the end of iram0_0_seg */
/* IRAM heap starts at the end of iram0_0_seg */
. = ALIGN (4);
_stextheap = ABSOLUTE(.);
_siramheap = ABSOLUTE(.);
} > iram0_0_seg
/* Shared RAM */
@@ -70,10 +70,10 @@ SECTIONS
_text_end = ABSOLUTE(.);
_etext = .;
/* Text heap starts at the end of iram0_0_seg */
/* IRAM heap starts at the end of iram0_0_seg */
. = ALIGN (4);
_stextheap = ABSOLUTE(.);
_siramheap = ABSOLUTE(.);
} > iram0_0_seg
/* Shared RAM */
@@ -78,9 +78,9 @@ MEMORY
_eheap = 0x40000000 - CONFIG_ESP32_TRACEMEM_RESERVE_DRAM;
/* Text heap ends at top of dram0_0_seg */
/* IRAM heap ends at top of dram0_0_seg */
_etextheap = 0x400a0000;
_eiramheap = 0x400a0000;
/* Mark the end of the RTC heap (top of the RTC region) */
@@ -66,10 +66,10 @@ SECTIONS
*(.phyiram .phyiram.*)
_iram_text_end = ABSOLUTE(.);
/* Text heap starts at the end of iram0_0_seg */
/* iram heap starts at the end of iram0_0_seg */
. = ALIGN (4);
_stextheap = ABSOLUTE(.);
_siramheap = ABSOLUTE(.);
} > iram0_0_seg
/* Shared RAM */
@@ -70,10 +70,10 @@ SECTIONS
_text_end = ABSOLUTE(.);
_etext = .;
/* Text heap starts at the end of iram0_0_seg */
/* IRAM heap starts at the end of iram0_0_seg */
. = ALIGN (4);
_stextheap = ABSOLUTE(.);
_siramheap = ABSOLUTE(.);
} > iram0_0_seg
/* Shared RAM */