内核中tcm(arm)与sram代码
2014-07-01 10:45
120 查看
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 <asm/tcm.h>
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 <asm/tcm.h>
/* 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);
了解一下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 <asm/tcm.h>
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 <asm/tcm.h>
/* 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);
相关文章推荐
- (亚嵌)ARM920T的MMU与Cache之操作MMU和Cache的内核启动代码
- arm linux kernel 从入口到start_kernel 的代码分析(2.6内核)
- (亚嵌)ARM920T的MMU与Cache之操作MMU和Cache的内核启动代码
- 内核裁剪,将自己写的驱动加入内核及按键驱动的代码(arm TQ2440)
- 苹果开源内核代码iOS, ARM macOS
- 开发者因GPLv2问题移除ARM内核浮点模拟代码
- C代码替代汇编代码实现启动ARM-M内核CPU
- 基于ARM Cortex-M0+内核的bootloader程序升级原理及代码解析
- ARM内核目标系统中的代码运行时间测试
- Linux 内核高-低端内存设置代码跟踪(ARM构架)
- Code maturity level options 代码成熟度选项 [*]Prompt for development and/or incomplete code/drivers 显示尚在开发中或尚未完成的代码与驱动.除非你是测试人员或者开发者,否则请勿选择 我是开发者,所以选[*] Loadable module support 可加载模块支持 [*]Enable loadable module support 内核编译配置选项简介 (2.4.20-8
- Atmel at91rm9200的armlinux的bootloader启动代码分析
- 嵌入式Linux内核移植相关代码分析
- ARM2410启动代码和uc/os移植调试总结
- 用模拟器加载基于ARM平台的WinCE6.0 内核(NK.bin)
- 嵌入式Linux内核移植相关代码分析
- 嵌入式Linux内核移植相关代码分析
- ARM启动代码分析
- arm linux 启动流程之 进入内核
- Linux系统内核抢占补丁的原理/代码