Blame view

Documentation/arm/tcm.rst 5.1 KB
dc7a12bdf   Mauro Carvalho Chehab   docs: arm: conver...
1
  ==================================================
bc581770c   Linus Walleij   ARM: 5580/2: ARM ...
2
  ARM TCM (Tightly-Coupled Memory) handling in Linux
dc7a12bdf   Mauro Carvalho Chehab   docs: arm: conver...
3
  ==================================================
bc581770c   Linus Walleij   ARM: 5580/2: ARM ...
4
  Written by Linus Walleij <linus.walleij@stericsson.com>
2d5dfb591   Jonathan Neuschäfer   docs: arm: tcm: F...
5
  Some ARM SoCs have a so-called TCM (Tightly-Coupled Memory).
bc581770c   Linus Walleij   ARM: 5580/2: ARM ...
6
7
  This is usually just a few (4-64) KiB of RAM inside the ARM
  processor.
2d5dfb591   Jonathan Neuschäfer   docs: arm: tcm: F...
8
  Due to being embedded inside the CPU, the TCM has a
bc581770c   Linus Walleij   ARM: 5580/2: ARM ...
9
10
11
12
13
  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.
  The size of DTCM or ITCM is minimum 4KiB so the typical
  minimum configuration is 4KiB ITCM and 4KiB DTCM.
2d5dfb591   Jonathan Neuschäfer   docs: arm: tcm: F...
14
  ARM CPUs have special registers to read out status, physical
bc581770c   Linus Walleij   ARM: 5580/2: ARM ...
15
16
17
18
19
  location and size of TCM memories. arch/arm/include/asm/cputype.h
  defines a CPUID_TCM register that you can read out from the
  system control coprocessor. Documentation from ARM can be found
  at http://infocenter.arm.com, search for "TCM Status Register"
  to see documents for all CPUs. Reading this register you can
1dbd30e98   Linus Walleij   ARM: 6225/1: make...
20
21
  determine if ITCM (bits 1-0) and/or DTCM (bit 17-16) is present
  in the machine.
bc581770c   Linus Walleij   ARM: 5580/2: ARM ...
22
23
24
25
26
27
28
29
  
  There is further a TCM region register (search for "TCM Region
  Registers" at the ARM site) that can report and modify the location
  size of TCM memories at runtime. This is used to read out and modify
  TCM location and size. Notice that this is not a MMU table: you
  actually move the physical location of the TCM around. At the
  place you put it, it will mask any underlying RAM from the
  CPU so it is usually wise not to overlap any physical RAM with
610ea6c67   Linus Walleij   ARM: 5738/1: Corr...
30
  the TCM.
bc581770c   Linus Walleij   ARM: 5580/2: ARM ...
31

610ea6c67   Linus Walleij   ARM: 5738/1: Corr...
32
33
34
35
  The TCM memory can then be remapped to another address again using
  the MMU, but notice that the TCM if often used in situations where
  the MMU is turned off. To avoid confusion the current Linux
  implementation will map the TCM 1 to 1 from physical to virtual
1dbd30e98   Linus Walleij   ARM: 6225/1: make...
36
37
38
39
40
41
42
43
44
  memory in the location specified by the kernel. Currently Linux
  will map ITCM to 0xfffe0000 and on, and DTCM to 0xfffe8000 and
  on, supporting a maximum of 32KiB of ITCM and 32KiB of DTCM.
  
  Newer versions of the region registers also support dividing these
  TCMs in two separate banks, so for example an 8KiB ITCM is divided
  into two 4KiB banks with its own control registers. The idea is to
  be able to lock and hide one of the banks for use by the secure
  world (TrustZone).
bc581770c   Linus Walleij   ARM: 5580/2: ARM ...
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
  
  TCM is used for a few things:
  
  - FIQ and other interrupt handlers that need deterministic
    timing and cannot wait for cache misses.
  
  - Idle loops where all external RAM is set to self-refresh
    retention mode, so only on-chip RAM is accessible by
    the CPU and then we hang inside ITCM waiting for an
    interrupt.
  
  - Other operations which implies shutting off or reconfiguring
    the external RAM controller.
  
  There is an interface for using TCM on the ARM architecture
  in <asm/tcm.h>. Using this interface it is possible to:
  
  - Define the physical address and size of ITCM and DTCM.
  
  - Tag functions to be compiled into ITCM.
  
  - Tag data and constants to be allocated to DTCM and ITCM.
  
  - Have the remaining TCM RAM added to a special
    allocation pool with gen_pool_create() and gen_pool_add()
    and provice tcm_alloc() and tcm_free() for this
    memory. Such a heap is great for things like saving
    device state when shutting off device power domains.
1dbd30e98   Linus Walleij   ARM: 6225/1: make...
73
74
75
  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>
bc581770c   Linus Walleij   ARM: 5580/2: ARM ...
76
77
78
  
  Functions to go into itcm can be tagged like this:
  int __tcmfunc foo(int bar);
1dbd30e98   Linus Walleij   ARM: 6225/1: make...
79
80
81
82
  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.
dc7a12bdf   Mauro Carvalho Chehab   docs: arm: conver...
83
84
85
86
87
  Variables to go into dtcm can be tagged like this::
  
    int __tcmdata foo;
  
  Constants can be tagged like this::
bc581770c   Linus Walleij   ARM: 5580/2: ARM ...
88

dc7a12bdf   Mauro Carvalho Chehab   docs: arm: conver...
89
90
91
92
93
    int __tcmconst foo;
  
  To put assembler into TCM just use::
  
    .section ".tcm.text" or .section ".tcm.data"
bc581770c   Linus Walleij   ARM: 5580/2: ARM ...
94

bc581770c   Linus Walleij   ARM: 5580/2: ARM ...
95
  respectively.
dc7a12bdf   Mauro Carvalho Chehab   docs: arm: conver...
96
  Example code::
bc581770c   Linus Walleij   ARM: 5580/2: ARM ...
97

dc7a12bdf   Mauro Carvalho Chehab   docs: arm: conver...
98
    #include <asm/tcm.h>
bc581770c   Linus Walleij   ARM: 5580/2: ARM ...
99

dc7a12bdf   Mauro Carvalho Chehab   docs: arm: conver...
100
101
102
103
104
105
    /* Uninitialized data */
    static u32 __tcmdata tcmvar;
    /* Initialized data */
    static u32 __tcmdata tcmassigned = 0x2BADBABEU;
    /* Constant */
    static const u32 __tcmconst tcmconst = 0xCAFEBABEU;
bc581770c   Linus Walleij   ARM: 5580/2: ARM ...
106

dc7a12bdf   Mauro Carvalho Chehab   docs: arm: conver...
107
108
    static void __tcmlocalfunc tcm_to_tcm(void)
    {
bc581770c   Linus Walleij   ARM: 5580/2: ARM ...
109
110
111
  	int i;
  	for (i = 0; i < 100; i++)
  		tcmvar ++;
dc7a12bdf   Mauro Carvalho Chehab   docs: arm: conver...
112
    }
bc581770c   Linus Walleij   ARM: 5580/2: ARM ...
113

dc7a12bdf   Mauro Carvalho Chehab   docs: arm: conver...
114
115
    static void __tcmfunc hello_tcm(void)
    {
bc581770c   Linus Walleij   ARM: 5580/2: ARM ...
116
117
118
119
120
121
  	/* Some abstract code that runs in ITCM */
  	int i;
  	for (i = 0; i < 100; i++) {
  		tcmvar ++;
  	}
  	tcm_to_tcm();
dc7a12bdf   Mauro Carvalho Chehab   docs: arm: conver...
122
    }
bc581770c   Linus Walleij   ARM: 5580/2: ARM ...
123

dc7a12bdf   Mauro Carvalho Chehab   docs: arm: conver...
124
125
    static void __init test_tcm(void)
    {
bc581770c   Linus Walleij   ARM: 5580/2: ARM ...
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
  	u32 *tcmem;
  	int i;
  
  	hello_tcm();
  	printk("Hello TCM executed from ITCM RAM
  ");
  
  	printk("TCM variable from testrun: %u @ %p
  ", tcmvar, &tcmvar);
  	tcmvar = 0xDEADBEEFU;
  	printk("TCM variable: 0x%x @ %p
  ", tcmvar, &tcmvar);
  
  	printk("TCM assigned variable: 0x%x @ %p
  ", tcmassigned, &tcmassigned);
  
  	printk("TCM constant: 0x%x @ %p
  ", tcmconst, &tcmconst);
  
  	/* Allocate some TCM memory from the pool */
  	tcmem = tcm_alloc(20);
  	if (tcmem) {
  		printk("TCM Allocated 20 bytes of TCM @ %p
  ", 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
  ", i, tcmem[i]);
  		tcm_free(tcmem, 20);
  	}
dc7a12bdf   Mauro Carvalho Chehab   docs: arm: conver...
160
    }