From 01a19e1b9a0521c42bcb85fbeeb557a2285758f0 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Thu, 30 Jun 2011 14:33:48 +0200 Subject: ARM TCM sample code This is a simple sample snippet of ARM TCM code use, we create arm/test to host the code. Signed-off-by: Linus Walleij --- Documentation/arm/tcm.rst | 3 ++ arch/arm/Kconfig.debug | 1 + arch/arm/Makefile | 2 + arch/arm/test/Kconfig | 20 ++++++++++ arch/arm/test/Makefile | 2 + arch/arm/test/tcm-example.c | 95 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 123 insertions(+) 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.rst b/Documentation/arm/tcm.rst index b256f9783883..535d4de0a2f4 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 f46e18a77645..ded4bb190046 100644 --- a/arch/arm/Kconfig.debug +++ b/arch/arm/Kconfig.debug @@ -1935,3 +1935,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 7d5cd0f85461..46355d840ba3 100644 --- a/arch/arm/Makefile +++ b/arch/arm/Makefile @@ -292,6 +292,8 @@ core-y += $(machdirs) $(platdirs) core- += $(patsubst %,arch/arm/mach-%/, $(machine-)) core- += $(patsubst %,arch/arm/plat-%/, $(plat-)) +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 + */ + +#include +#include +#include +#include + +#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); -- cgit v1.2.3