Skip to content

Commit

Permalink
core: linkable coherent memory section from CFG_TEE_COHERENT_START
Browse files Browse the repository at this point in the history
Using CFG_TEE_COHERENT_START/_SIZE, one can define a coherent
memory area that gets linked in optee_os core. One may use the
__coherent attribute to located data inside the coherent memory.

CFG_TEE_COHERENT_START/_SIZE can be located before or after the optee_os
reserved range that covers flat mapped areas and pager vaspace.

The coherent memory defined by CFG_TEE_COHERENT_START/_SIZE is
automatically to the core static mapping directive.

Update plat-sunxi/kernel.ld.S accordingly.

Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
  • Loading branch information
etienne-lms committed Sep 15, 2017
1 parent 565112b commit 00f75ad
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
26 changes: 26 additions & 0 deletions core/arch/arm/kernel/kern.ld.S
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,29 @@
OUTPUT_FORMAT(CFG_KERN_LINKER_FORMAT)
OUTPUT_ARCH(CFG_KERN_LINKER_ARCH)

#define LINK_COHERENT_RAM \
. = CFG_TEE_COHERENT_START; \
.coherent (NOLOAD) : { \
ASSERT(!(. & (SMALL_PAGE_SIZE - 1)), \
"Coherent memory start is not aligned"); \
__coherent_start = .; \
KEEP(*(.coherent_ram)); \
. = ALIGN(SMALL_PAGE_SIZE); \
__coherent_end = .; \
ASSERT(CFG_TEE_COHERENT_SIZE >= \
(. - __coherent_start), \
"Coherent memory is undersized"); \
}

ENTRY(_start)
SECTIONS
{
#if defined(CFG_TEE_COHERENT_START) && \
(CFG_TEE_COHERENT_START < TEE_TEXT_VA_START)
LINK_COHERENT_RAM
ASSERT(. <= TEE_TEXT_VA_START, "Coherent memory is oversized")
#endif

. = TEE_TEXT_VA_START;
#ifdef ARM32
ASSERT(!(TEE_TEXT_VA_START & 31), "text start should align to 32bytes")
Expand Down Expand Up @@ -434,6 +454,12 @@ SECTIONS
__flatmap_unpg_rw_size = _end_of_ram - __flatmap_unpg_rw_start;
#endif

#if defined(CFG_TEE_COHERENT_START) && \
(CFG_TEE_COHERENT_START > CFG_TEE_RAM_START)
ASSERT(. <= CFG_TEE_COHERENT_START, "Coherent memory does not fit")
LINK_COHERENT_RAM
#endif

/DISCARD/ : {
/* Strip unnecessary stuff */
*(.comment .note .eh_frame)
Expand Down
5 changes: 5 additions & 0 deletions core/arch/arm/mm/core_mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ static struct memaccess_area nsec_shared[] = {
register_sdp_mem(CFG_TEE_SDP_MEM_BASE, CFG_TEE_SDP_MEM_SIZE);
#endif

#ifdef CFG_TEE_COHERENT_START
register_phys_mem(MEM_AREA_TEE_COHERENT, CFG_TEE_COHERENT_START,
CFG_TEE_COHERENT_SIZE);
#endif

#ifdef CFG_CORE_RWDATA_NOEXEC
register_phys_mem(MEM_AREA_TEE_RAM_RX, VCORE_UNPG_RX_PA, VCORE_UNPG_RX_SZ);
register_phys_mem(MEM_AREA_TEE_RAM_RO, VCORE_UNPG_RO_PA, VCORE_UNPG_RO_SZ);
Expand Down
26 changes: 26 additions & 0 deletions core/arch/arm/plat-sunxi/kern.ld.S
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,32 @@
#define SMALL_PAGE_SIZE 4096
#endif

#define LINK_COHERENT_RAM \
. = CFG_TEE_COHERENT_START; \
.coherent (NOLOAD) : { \
ASSERT(!(. & (SMALL_PAGE_SIZE - 1)), \
"Coherent memory start is not aligned"); \
__coherent_start = .; \
KEEP(*(.coherent_ram)); \
. = ALIGN(SMALL_PAGE_SIZE); \
__coherent_end = .; \
ASSERT(CFG_TEE_COHERENT_SIZE >= \
(. - __coherent_start), \
"Coherent memory is undersized"); \
}

OUTPUT_FORMAT(CFG_KERN_LINKER_FORMAT)
OUTPUT_ARCH(CFG_KERN_LINKER_ARCH)

ENTRY(_start)
SECTIONS
{
#if defined(CFG_TEE_COHERENT_START) && \
(CFG_TEE_COHERENT_START < CFG_TEE_RAM_START)
LINK_COHERENT_RAM
ASSERT(. <= TEE_RAM_START, "Coherent memory is oversized")
#endif

. = TEE_RAM_START;
__flatmap_unpg_rx_start = .;

Expand Down Expand Up @@ -223,6 +243,12 @@ SECTIONS

__flatmap_unpg_rw_size = _end_of_ram - __flatmap_unpg_rw_start;

#if defined(CFG_TEE_COHERENT_START) && \
(CFG_TEE_COHERENT_START > CFG_TEE_RAM_START)
ASSERT(. <= CFG_TEE_COHERENT_START, "Coherent memory does not fit")
LINK_COHERENT_RAM
#endif

/* Strip unnecessary stuff */
/DISCARD/ : { *(.comment .note .eh_frame) }
}
Expand Down
1 change: 1 addition & 0 deletions lib/libutils/ext/include/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#define __rodata_unpaged __section(".rodata.__unpaged")
#define __early_ta __section(".rodata.early_ta")
#define __noprof __attribute__((no_instrument_function))
#define __coherent __section(".coherent_ram")

#define __compiler_bswap64(x) __builtin_bswap64((x))
#define __compiler_bswap32(x) __builtin_bswap32((x))
Expand Down

0 comments on commit 00f75ad

Please sign in to comment.