[PATCH] ARM TCM sample code

Linus Walleij linus.walleij at linaro.org
Thu Jun 30 08:33:48 EDT 2011


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 at linaro.org>
---
 Documentation/arm/tcm.txt   |   60 +--------------------------
 arch/arm/Kconfig.debug      |    2 +
 arch/arm/Makefile           |    2 +
 arch/arm/test/Kconfig       |   20 +++++++++
 arch/arm/test/Makefile      |    2 +
 arch/arm/test/tcm-example.c |   94 +++++++++++++++++++++++++++++++++++++++++++
 samples/Kconfig             |    9 ++++
 samples/Makefile            |    2 +-
 8 files changed, 132 insertions(+), 59 deletions(-)
 create mode 100644 arch/arm/test/Kconfig
 create mode 100644 arch/arm/test/Makefile
 create mode 100644 arch/arm/test/tcm-example.c

diff --git a/Documentation/arm/tcm.txt b/Documentation/arm/tcm.txt
index 7c15871..f6ead49 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 81cbe40..82bf536 100644
--- a/arch/arm/Kconfig.debug
+++ b/arch/arm/Kconfig.debug
@@ -129,4 +129,6 @@ config DEBUG_S3C_UART
 	  The uncompressor code port configuration is now handled
 	  by CONFIG_S3C_LOWLEVEL_UART_PORT.

+source "arch/arm/test/Kconfig"
+
 endmenu
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index 70c424e..f2f370b 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -255,6 +255,8 @@ core-$(CONFIG_VFP)		+= arch/arm/vfp/
 core-y				+= arch/arm/kernel/ arch/arm/mm/ arch/arm/common/
 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 0000000..13c38e1
--- /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 0000000..9161440
--- /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 0000000..156d97e
--- /dev/null
+++ b/arch/arm/test/tcm-example.c
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2010 ST-Ericsson AB
+ * License terms: GNU General Public License (GPL) version 2
+ * TCM memory test
+ *
+ * Author: Linus Walleij <linus.walleij at stericsson.com>
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.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);
diff --git a/samples/Kconfig b/samples/Kconfig
index 96a7572..91260c6 100644
--- a/samples/Kconfig
+++ b/samples/Kconfig
@@ -67,4 +67,13 @@ config SAMPLE_HIDRAW
 	help
 	  Build an example of how to use hidraw from userspace.

+config SAMPLE_ARM_TCM
+	bool "TCM sample testing module"
+	depends on HAVE_TCM
+	help
+	  This enables a small testing module that execise the ARM TCM
+	  memory on the platform at startup to make sure it's working.
+	  If you're really using the TCM it is a scarce resource so
+	  this should only be selected for testing and education.
+
 endif # SAMPLES
diff --git a/samples/Makefile b/samples/Makefile
index 6280817..11a1d27 100644
--- a/samples/Makefile
+++ b/samples/Makefile
@@ -1,4 +1,4 @@
 # Makefile for Linux samples code

 obj-$(CONFIG_SAMPLES)	+= kobject/ kprobes/ tracepoints/ trace_events/ \
-			   hw_breakpoint/ kfifo/ kdb/ hidraw/
+			   hw_breakpoint/ kfifo/ kdb/ hidraw/ arm_tcm/
-- 
1.7.3.2


> Are they visible to userspace?

Nope, that's a much asked-for feature, but I don't quite
know how to deal with that.

Thanks,
Linus Walleij



More information about the linux-arm-kernel mailing list