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>2019-07-23 09:21:11 +0200
commitc58807b8835f09fd5a8628e4ba9503cf8747817b (patch)
tree8c742062fbcecdc3289636a23c5ef94e7ea01aea
parent5f9e832c137075045d15cd6899ab0505cfb2ca4b (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.rst3
-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, 123 insertions, 0 deletions
diff --git a/Documentation/arm/tcm.rst b/Documentation/arm/tcm.rst
index effd9c7bc968..5cf995cc88fd 100644
--- a/Documentation/arm/tcm.rst
+++ b/Documentation/arm/tcm.rst
@@ -159,3 +159,6 @@ Example code::
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 c929bea9a9ff..b8ee712c1a44 100644
--- a/arch/arm/Kconfig.debug
+++ b/arch/arm/Kconfig.debug
@@ -1909,3 +1909,4 @@ config PID_IN_CONTEXTIDR
are planning to use hardware trace tools with this kernel.
source "drivers/hwtracing/coresight/Kconfig"
+source "arch/arm/test/Kconfig"
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index c3624ca6c0bc..7c922e754723 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -290,6 +290,8 @@ core-y += arch/arm/net/
core-y += arch/arm/crypto/
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);