内核中tcm(arm)与sram代码

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);

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值