**TCM (Tightly-Coupled Memory)
**了解一下tcm,虽然所用的平台上并没有tcm。
Some ARM SoC:s have a so-called TCM (Tightly-Coupled Memory). This is usually just a few (4-64) KiB of RAM inside the ARM processor.
Due to being embedded inside the CPU The TCM has a Harvard-architecture, so there is an ITCM (instruction TCM) and a DTCM (data TCM). The DTCM can not contain any instructions, but the ITCM can actually contain data.
A machine that has TCM memory shall select HAVE_TCM from arch/arm/Kconfig for itself. Code that needs to use TCM shall #include
Functions to go into itcm can be tagged like this: int __tcmfunc foo(int bar);
Since these are marked to become long_calls and you may want to have functions called locally inside the TCM without wasting space, there is also the __tcmlocalfunc prefix that will make the call relative.
Variables to go into dtcm can be tagged like this: int __tcmdata foo;
Constants can be tagged like this: int __tcmconst foo;
To put assembler into TCM just use .section ".tcm.text" or .section ".tcm.data" respectively.
Example code:
#include
/* Uninitialized data */ static u32 __tcmdata tcmvar; /* Initialized data */ static u32 __tcmdata tcmassigned = 0x2BADBABEU; /* Constant */ static const u32 __tcmconst tcmconst = 0xCAFEBABEU;
static void __tcmlocalfunc tcm_to_tcm(void) { int i;
for (i = 0; i < 100; i++) tcmvar ++; }
static void __tcmfunc hello_tcm(void) { /* Some abstract code that runs in ITCM */
int i;
for (i = 0; i < 100; i++) { tcmvar ++; }
tcm_to_tcm(); }
static void __init test_tcm(void) { u32 *tcmem;
int i;
hello_tcm();
printk("Hello TCM executed from ITCM RAM\n");
printk("TCM variable from testrun: %u @ %p\n", tcmvar, &tcmvar);
tcmvar = 0xDEADBEEFU;
printk("TCM variable: 0x%x @ %p\n", tcmvar, &tcmvar);
printk("TCM assigned variable: 0x%x @ %p\n", tcmassigned, &tcmassigned);
printk("TCM constant: 0x%x @ %p\n", tcmconst, &tcmconst);
/* Allocate some TCM memory from the pool */
tcmem = tcm_alloc(20);
if (tcmem) { printk("TCM Allocated 20 bytes of TCM @ %p\n", tcmem);
tcmem[0] = 0xDEADBEEFU;
tcmem[1] = 0x2BADBABEU;
tcmem[2] = 0xCAFEBABEU;
tcmem[3] = 0xDEADBEEFU;
tcmem[4] = 0x2BADBABEU;
for (i = 0; i < 5; i++) printk("TCM tcmem[%d] = %08x\n", i, tcmem[i]); tcm_free(tcmem, 20); } }
**sram
**soc芯片往往都有片上ram,但有些平台内核没有使用这些ram,这是浪费,下面是davinci平台的ram相关代码。
初始化
arch/arm/mach-davinci/sram.c
static int __init sram_init(void)
{
unsigned len = davinci_soc_info.sram_len;
int status = 0;
if (len) {
len = min_t(unsigned, len, SRAM_SIZE);
sram_pool = gen_pool_create(ilog2(SRAM_GRANULARITY), -1);
if (!sram_pool)
status = -ENOMEM;
}
if (sram_pool)
status = gen_pool_add(sram_pool, SRAM_VIRT, len, -1);
WARN_ON(status < 0);
return status;
}
core_initcall(sram_init);
申请和释放用下面的接口:
EXPORT_SYMBOL(sram_alloc);
EXPORT_SYMBOL(sram_free);
手机扫一扫
移动阅读更方便
你可能感兴趣的文章