aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2011-06-30 14:33:48 +0200
committerLinus Walleij <linus.walleij@linaro.org>2018-04-06 09:44:55 +0200
commitaaecc8ca7e62e8f7ff9ac4dc5e6f6c8b79dc39b3 (patch)
treeebba2e6f926ec55c634dc07b4b1e8b09aa034aba
parent0adb32858b0bddf4ada5f364a84ed60b196dbcda (diff)
downloadlinux-stericsson-tcm.tar.gz
ARM TCM sample codetcm
This is a simple sample snippet of ARM TCM code use, we create arm/test to host the code. Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r--Documentation/arm/tcm.txt60
-rw-r--r--arch/arm/Kconfig.debug1
-rw-r--r--arch/arm/Makefile2
-rw-r--r--arch/arm/test/Kconfig20
-rw-r--r--arch/arm/test/Makefile2
-rw-r--r--arch/arm/test/tcm-example.c95
6 files changed, 122 insertions, 58 deletions
diff --git a/Documentation/arm/tcm.txt b/Documentation/arm/tcm.txt
index 7c15871c1885..f6ead49c4e62 100644
--- a/Documentation/arm/tcm.txt
+++ b/Documentation/arm/tcm.txt
@@ -95,61 +95,5 @@ 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);
- }
-}
+Example code can be found in the samples/arm_tcm directory of the kernel
+tree, and can be compiled in using menuconfig.
diff --git a/arch/arm/Kconfig.debug b/arch/arm/Kconfig.debug
index 199ebc1c4538..c021fc590bc6 100644
--- a/arch/arm/Kconfig.debug
+++ b/arch/arm/Kconfig.debug
@@ -1854,5 +1854,6 @@ config PID_IN_CONTEXTIDR
are planning to use hardware trace tools with this kernel.
source "drivers/hwtracing/coresight/Kconfig"
+source "arch/arm/test/Kconfig"
endmenu
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index e83f5161fdd8..732ce4dbc833 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -298,6 +298,8 @@ core-y += arch/arm/crypto/
core-y += arch/arm/firmware/
core-y += $(machdirs) $(platdirs)
+core-$(CONFIG_ARM_TEST) += arch/arm/test/
+
drivers-$(CONFIG_OPROFILE) += arch/arm/oprofile/
libs-y := arch/arm/lib/ $(libs-y)
diff --git a/arch/arm/test/Kconfig b/arch/arm/test/Kconfig
new file mode 100644
index 000000000000..13c38e11ab6d
--- /dev/null
+++ b/arch/arm/test/Kconfig
@@ -0,0 +1,20 @@
+config ARM_TEST
+ bool "Enable ARM kernel tests"
+
+if ARM_TEST
+
+menu "ARM Kernel tests"
+
+comment "test code to exercise the ARM kernel"
+
+config ARM_TCM_TEST
+ bool "ARM TCM test"
+ depends on HAVE_TCM
+ help
+ Enables some test code snippets to exercise the TCM memory
+ on platforms that have it. The code will not be executed
+ if no TCM memory is found.
+
+endmenu
+
+endif
diff --git a/arch/arm/test/Makefile b/arch/arm/test/Makefile
new file mode 100644
index 000000000000..9161440d5345
--- /dev/null
+++ b/arch/arm/test/Makefile
@@ -0,0 +1,2 @@
+obj-y :=
+obj-$(CONFIG_ARM_TCM_TEST) += tcm-example.o
diff --git a/arch/arm/test/tcm-example.c b/arch/arm/test/tcm-example.c
new file mode 100644
index 000000000000..b90273869a3c
--- /dev/null
+++ b/arch/arm/test/tcm-example.c
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2010 ST-Ericsson AB
+ * License terms: GNU General Public License (GPL) version 2
+ * TCM memory test
+ *
+ * Author: Linus Walleij <linus.walleij@stericsson.com>
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <asm/bug.h>
+#include <asm/tcm.h>
+
+#define CANARY1 0xDEADBEEFU
+#define CANARY2 0x2BADBABEU
+#define CANARY3 0xCAFEBABEU
+
+/* Uninitialized data */
+static u32 __tcmdata tcmvar;
+/* Initialized data */
+static u32 __tcmdata tcmassigned = CANARY2;
+/* Constant */
+static const u32 __tcmconst tcmconst = CANARY3;
+
+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 int __init test_tcm(void)
+{
+ u32 *tcmem;
+ int i;
+
+ if (!tcm_dtcm_present() && !tcm_itcm_present()) {
+ pr_info("CPU: no TCMs present, skipping tests\n");
+ return 0;
+ }
+
+ if (!tcm_itcm_present())
+ goto skip_itcm_tests;
+
+ hello_tcm();
+ pr_info("CPU: hello TCM executed from ITCM RAM\n");
+
+ pr_info("CPU: TCM variable from testrun: %u @ %p\n",
+ tcmvar, &tcmvar);
+ BUG_ON(tcmvar != 200);
+
+skip_itcm_tests:
+ tcmvar = CANARY1;
+ pr_info("CPU: TCM variable: 0x%x @ %p\n", tcmvar, &tcmvar);
+ BUG_ON(tcmvar != CANARY1);
+
+ pr_info("CPU: TCM assigned variable: 0x%x @ %p\n",
+ tcmassigned, &tcmassigned);
+ BUG_ON(tcmassigned != CANARY2);
+
+ pr_info("CPU: TCM constant: 0x%x @ %p\n", tcmconst, &tcmconst);
+ BUG_ON(tcmconst != CANARY3);
+
+ /* Allocate some TCM memory from the pool */
+ tcmem = tcm_alloc(20);
+ if (tcmem) {
+ pr_info("CPU: TCM Allocated 20 bytes of TCM @ %p\n", tcmem);
+ tcmem[0] = CANARY1;
+ tcmem[1] = CANARY2;
+ tcmem[2] = CANARY3;
+ tcmem[3] = CANARY1;
+ tcmem[4] = CANARY2;
+ for (i = 0; i < 5; i++)
+ pr_info("CPU: TCM tcmem[%d] = %08x\n", i, tcmem[i]);
+ BUG_ON(tcmem[0] != CANARY1);
+ BUG_ON(tcmem[1] != CANARY2);
+ BUG_ON(tcmem[2] != CANARY3);
+ BUG_ON(tcmem[3] != CANARY1);
+ BUG_ON(tcmem[4] != CANARY2);
+ tcm_free(tcmem, 20);
+ }
+ return 0;
+}
+
+late_initcall(test_tcm);