/Documentation/arm/tcm.txt

https://bitbucket.org/fhunleth/dm36x-kernel · Plain Text · 147 lines · 117 code · 30 blank · 0 comment · 0 complexity · c8317609ec8f859a1e6ab6d1fe457c9b MD5 · raw file

  1. ARM TCM (Tightly-Coupled Memory) handling in Linux
  2. ----
  3. Written by Linus Walleij <linus.walleij@stericsson.com>
  4. Some ARM SoC:s have a so-called TCM (Tightly-Coupled Memory).
  5. This is usually just a few (4-64) KiB of RAM inside the ARM
  6. processor.
  7. Due to being embedded inside the CPU The TCM has a
  8. Harvard-architecture, so there is an ITCM (instruction TCM)
  9. and a DTCM (data TCM). The DTCM can not contain any
  10. instructions, but the ITCM can actually contain data.
  11. The size of DTCM or ITCM is minimum 4KiB so the typical
  12. minimum configuration is 4KiB ITCM and 4KiB DTCM.
  13. ARM CPU:s have special registers to read out status, physical
  14. location and size of TCM memories. arch/arm/include/asm/cputype.h
  15. defines a CPUID_TCM register that you can read out from the
  16. system control coprocessor. Documentation from ARM can be found
  17. at http://infocenter.arm.com, search for "TCM Status Register"
  18. to see documents for all CPUs. Reading this register you can
  19. determine if ITCM (bit 0) and/or DTCM (bit 16) is present in the
  20. machine.
  21. There is further a TCM region register (search for "TCM Region
  22. Registers" at the ARM site) that can report and modify the location
  23. size of TCM memories at runtime. This is used to read out and modify
  24. TCM location and size. Notice that this is not a MMU table: you
  25. actually move the physical location of the TCM around. At the
  26. place you put it, it will mask any underlying RAM from the
  27. CPU so it is usually wise not to overlap any physical RAM with
  28. the TCM.
  29. The TCM memory can then be remapped to another address again using
  30. the MMU, but notice that the TCM if often used in situations where
  31. the MMU is turned off. To avoid confusion the current Linux
  32. implementation will map the TCM 1 to 1 from physical to virtual
  33. memory in the location specified by the machine.
  34. TCM is used for a few things:
  35. - FIQ and other interrupt handlers that need deterministic
  36. timing and cannot wait for cache misses.
  37. - Idle loops where all external RAM is set to self-refresh
  38. retention mode, so only on-chip RAM is accessible by
  39. the CPU and then we hang inside ITCM waiting for an
  40. interrupt.
  41. - Other operations which implies shutting off or reconfiguring
  42. the external RAM controller.
  43. There is an interface for using TCM on the ARM architecture
  44. in <asm/tcm.h>. Using this interface it is possible to:
  45. - Define the physical address and size of ITCM and DTCM.
  46. - Tag functions to be compiled into ITCM.
  47. - Tag data and constants to be allocated to DTCM and ITCM.
  48. - Have the remaining TCM RAM added to a special
  49. allocation pool with gen_pool_create() and gen_pool_add()
  50. and provice tcm_alloc() and tcm_free() for this
  51. memory. Such a heap is great for things like saving
  52. device state when shutting off device power domains.
  53. A machine that has TCM memory shall select HAVE_TCM in
  54. arch/arm/Kconfig for itself, and then the
  55. rest of the functionality will depend on the physical
  56. location and size of ITCM and DTCM to be defined in
  57. mach/memory.h for the machine. Code that needs to use
  58. TCM shall #include <asm/tcm.h> If the TCM is not located
  59. at the place given in memory.h it will be moved using
  60. the TCM Region registers.
  61. Functions to go into itcm can be tagged like this:
  62. int __tcmfunc foo(int bar);
  63. Variables to go into dtcm can be tagged like this:
  64. int __tcmdata foo;
  65. Constants can be tagged like this:
  66. int __tcmconst foo;
  67. To put assembler into TCM just use
  68. .section ".tcm.text" or .section ".tcm.data"
  69. respectively.
  70. Example code:
  71. #include <asm/tcm.h>
  72. /* Uninitialized data */
  73. static u32 __tcmdata tcmvar;
  74. /* Initialized data */
  75. static u32 __tcmdata tcmassigned = 0x2BADBABEU;
  76. /* Constant */
  77. static const u32 __tcmconst tcmconst = 0xCAFEBABEU;
  78. static void __tcmlocalfunc tcm_to_tcm(void)
  79. {
  80. int i;
  81. for (i = 0; i < 100; i++)
  82. tcmvar ++;
  83. }
  84. static void __tcmfunc hello_tcm(void)
  85. {
  86. /* Some abstract code that runs in ITCM */
  87. int i;
  88. for (i = 0; i < 100; i++) {
  89. tcmvar ++;
  90. }
  91. tcm_to_tcm();
  92. }
  93. static void __init test_tcm(void)
  94. {
  95. u32 *tcmem;
  96. int i;
  97. hello_tcm();
  98. printk("Hello TCM executed from ITCM RAM\n");
  99. printk("TCM variable from testrun: %u @ %p\n", tcmvar, &tcmvar);
  100. tcmvar = 0xDEADBEEFU;
  101. printk("TCM variable: 0x%x @ %p\n", tcmvar, &tcmvar);
  102. printk("TCM assigned variable: 0x%x @ %p\n", tcmassigned, &tcmassigned);
  103. printk("TCM constant: 0x%x @ %p\n", tcmconst, &tcmconst);
  104. /* Allocate some TCM memory from the pool */
  105. tcmem = tcm_alloc(20);
  106. if (tcmem) {
  107. printk("TCM Allocated 20 bytes of TCM @ %p\n", tcmem);
  108. tcmem[0] = 0xDEADBEEFU;
  109. tcmem[1] = 0x2BADBABEU;
  110. tcmem[2] = 0xCAFEBABEU;
  111. tcmem[3] = 0xDEADBEEFU;
  112. tcmem[4] = 0x2BADBABEU;
  113. for (i = 0; i < 5; i++)
  114. printk("TCM tcmem[%d] = %08x\n", i, tcmem[i]);
  115. tcm_free(tcmem, 20);
  116. }
  117. }