From 3120bb4b56b401792215d4fd7151ae52dd0ac3ec Mon Sep 17 00:00:00 2001 From: Venkatesan Krishnamoorthy Date: Thu, 3 Dec 2026 14:27:25 +0530 Subject: [PATCH 1/3] UPSTREAM: arch: arm: cortex_m: add ARMV8_M_CDE_CP0 option commit a96482ecb77ea431d51f80f82d47a89e93549201 upstream. Add a Kconfig option for SoCs that implement an Arm Custom Datapath Extension coprocessor on CP0. GCC rejects +cdecp0 on -mcpu, so when the option is set build with -march=armv8[.1]-m.main[+dsp|+mve|+mve.fp]+cdecp0 and -mtune set to the CPU, via the new GCC_M_ARCH and GCC_M_TUNE variables. This applies to any ARMv8-M Mainline CPU rather than Cortex-M33 only. Clang takes +cdecp0 on -mcpu. The option is not selected by any SoC yet, so there is no change in behavior for existing targets. Signed-off-by: Venkatesan Krishnamoorthy --- arch/arm/core/cortex_m/Kconfig | 10 ++++++++++ cmake/compiler/clang/target_arm.cmake | 7 ++++++- cmake/compiler/gcc/target_arm.cmake | 10 +++++++++- cmake/gcc-m-cpu.cmake | 19 +++++++++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/arch/arm/core/cortex_m/Kconfig b/arch/arm/core/cortex_m/Kconfig index 2da72c2049406..63c121eb85c1d 100644 --- a/arch/arm/core/cortex_m/Kconfig +++ b/arch/arm/core/cortex_m/Kconfig @@ -290,6 +290,16 @@ config ARMV8_M_DSP This option signifies the use of an ARMv8-M processor implementation supporting the DSP Extension. +config ARMV8_M_CDE_CP0 + bool + depends on ARMV8_M_MAINLINE + help + This option signifies the use of an ARMv8-M processor implementation + with an Arm Custom Datapath Extension (CDE) coprocessor on CP0. The + compiler is told to enable the cdecp0 feature so the CDE intrinsics + from arm_cde.h can be used. The SoC is responsible for enabling access + to the coprocessor (CPACR) before it is used. + config ARMV8_1_M_MVEI bool depends on ARMV8_1_M_MAINLINE diff --git a/cmake/compiler/clang/target_arm.cmake b/cmake/compiler/clang/target_arm.cmake index d1d51cb4d61e2..e58f993f152eb 100644 --- a/cmake/compiler/clang/target_arm.cmake +++ b/cmake/compiler/clang/target_arm.cmake @@ -2,7 +2,12 @@ set(ARM_C_FLAGS) -list(APPEND ARM_C_FLAGS -mcpu=${GCC_M_CPU}) +if(CONFIG_ARMV8_M_CDE_CP0) + # Clang takes the CDE feature on -mcpu rather than -march + list(APPEND ARM_C_FLAGS -mcpu=${GCC_M_CPU}+cdecp0) +else() + list(APPEND ARM_C_FLAGS -mcpu=${GCC_M_CPU}) +endif() if(CONFIG_COMPILER_ISA_THUMB2) list(APPEND ARM_C_FLAGS -mthumb) diff --git a/cmake/compiler/gcc/target_arm.cmake b/cmake/compiler/gcc/target_arm.cmake index 4e4523c43c579..c9971dd7c907c 100644 --- a/cmake/compiler/gcc/target_arm.cmake +++ b/cmake/compiler/gcc/target_arm.cmake @@ -2,7 +2,15 @@ set(ARM_C_FLAGS) -list(APPEND ARM_C_FLAGS -mcpu=${GCC_M_CPU}) +if(DEFINED GCC_M_ARCH) + # The CPU alone cannot express the requested architecture features + list(APPEND ARM_C_FLAGS -march=${GCC_M_ARCH}) + if(DEFINED GCC_M_TUNE) + list(APPEND ARM_C_FLAGS -mtune=${GCC_M_TUNE}) + endif() +else() + list(APPEND ARM_C_FLAGS -mcpu=${GCC_M_CPU}) +endif() if(CONFIG_COMPILER_ISA_THUMB2) list(APPEND ARM_C_FLAGS -mthumb) diff --git a/cmake/gcc-m-cpu.cmake b/cmake/gcc-m-cpu.cmake index f5117b1d4356a..e9a74bb82e64d 100644 --- a/cmake/gcc-m-cpu.cmake +++ b/cmake/gcc-m-cpu.cmake @@ -107,6 +107,25 @@ if("${ARCH}" STREQUAL "arm") else() message(FATAL_ERROR "Expected CONFIG_CPU_CORTEX_x to be defined") endif() + + if(CONFIG_ARMV8_M_CDE_CP0) + # GCC does not accept the cdecp0 feature on -mcpu, so select the + # architecture explicitly and keep the CPU for tuning. + if(CONFIG_ARMV8_1_M_MAINLINE) + set(GCC_M_ARCH armv8.1-m.main) + else() + set(GCC_M_ARCH armv8-m.main) + endif() + if(CONFIG_ARMV8_1_M_MVEF) + string(APPEND GCC_M_ARCH +mve.fp) + elseif(CONFIG_ARMV8_1_M_MVEI) + string(APPEND GCC_M_ARCH +mve) + elseif(CONFIG_ARMV8_M_DSP) + string(APPEND GCC_M_ARCH +dsp) + endif() + string(APPEND GCC_M_ARCH +cdecp0) + string(REGEX REPLACE "\\+.*" "" GCC_M_TUNE ${GCC_M_CPU}) + endif() elseif("${ARCH}" STREQUAL "arm64") if(CONFIG_CPU_CORTEX_A53) set(GCC_M_CPU cortex-a53) From 988298e625a99cd0810b79b02c80cf778532f870 Mon Sep 17 00:00:00 2001 From: Venkatesan Krishnamoorthy Date: Thu, 3 Dec 2026 14:27:26 +0530 Subject: [PATCH 2/3] UPSTREAM: soc: ti: am13: select ARMV8_M_CDE_CP0 commit 59510f99b2456548da2549917f45769fd92348ac upstream. Select ARMV8_M_CDE_CP0 so the build enables the CDE coprocessor on CP0 for this SoC. Signed-off-by: Venkatesan Krishnamoorthy --- soc/ti/am13/am13e/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/soc/ti/am13/am13e/Kconfig b/soc/ti/am13/am13e/Kconfig index d8ff981776dbd..1244641032458 100644 --- a/soc/ti/am13/am13e/Kconfig +++ b/soc/ti/am13/am13e/Kconfig @@ -7,6 +7,7 @@ config SOC_AM13E23019 select ARM select ARMV8_M_DSP + select ARMV8_M_CDE_CP0 select BUILD_OUTPUT_BIN select BUILD_OUTPUT_HEX select CPU_CORTEX_M33 From 77a400dae99ab5131d3569205f480b71327082cc Mon Sep 17 00:00:00 2001 From: Venkatesan Krishnamoorthy Date: Thu, 3 Dec 2026 14:27:26 +0530 Subject: [PATCH 3/3] UPSTREAM: tests: arch: arm: add build-only test for ARMV8_M_CDE_CP0 commit e040823e347dae9225276a0545b4b5b653b19168 upstream. Add a build-only test that enables ARMV8_M_CDE_CP0 through a test-local Kconfig symbol and uses the CDE intrinsics from arm_cde.h on coprocessor 0. The test checks __ARM_FEATURE_CDE and the coprocessor mask at compile time, so a missing +cdecp0 in the compiler flags fails the build. The code is never run: whether CP0 is implemented and enabled depends on the SoC. Built with GCC and Clang, and confirmed that the build fails with the option disabled. Signed-off-by: Venkatesan Krishnamoorthy --- tests/arch/arm/arm_cde_cp0/CMakeLists.txt | 8 ++++++ tests/arch/arm/arm_cde_cp0/Kconfig | 12 +++++++++ tests/arch/arm/arm_cde_cp0/prj.conf | 1 + tests/arch/arm/arm_cde_cp0/src/main.c | 31 +++++++++++++++++++++++ tests/arch/arm/arm_cde_cp0/tests.yaml | 13 ++++++++++ 5 files changed, 65 insertions(+) create mode 100644 tests/arch/arm/arm_cde_cp0/CMakeLists.txt create mode 100644 tests/arch/arm/arm_cde_cp0/Kconfig create mode 100644 tests/arch/arm/arm_cde_cp0/prj.conf create mode 100644 tests/arch/arm/arm_cde_cp0/src/main.c create mode 100644 tests/arch/arm/arm_cde_cp0/tests.yaml diff --git a/tests/arch/arm/arm_cde_cp0/CMakeLists.txt b/tests/arch/arm/arm_cde_cp0/CMakeLists.txt new file mode 100644 index 0000000000000..5a20d22c895dd --- /dev/null +++ b/tests/arch/arm/arm_cde_cp0/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.28.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(arm_cde_cp0) + +target_sources(app PRIVATE src/main.c) diff --git a/tests/arch/arm/arm_cde_cp0/Kconfig b/tests/arch/arm/arm_cde_cp0/Kconfig new file mode 100644 index 0000000000000..d5513143aa6ca --- /dev/null +++ b/tests/arch/arm/arm_cde_cp0/Kconfig @@ -0,0 +1,12 @@ +# Copyright (c) 2026 Texas Instruments Incorporated +# SPDX-License-Identifier: Apache-2.0 + +# ARMV8_M_CDE_CP0 is normally selected by the SoC. Select it here so that the +# option can be exercised on any Armv8-M Mainline target. +config TEST_ARM_CDE_CP0 + bool "Build with the CDE coprocessor on CP0 enabled" + default y + depends on ARMV8_M_MAINLINE + select ARMV8_M_CDE_CP0 + +source "Kconfig.zephyr" diff --git a/tests/arch/arm/arm_cde_cp0/prj.conf b/tests/arch/arm/arm_cde_cp0/prj.conf new file mode 100644 index 0000000000000..9881313609aae --- /dev/null +++ b/tests/arch/arm/arm_cde_cp0/prj.conf @@ -0,0 +1 @@ +# SPDX-License-Identifier: Apache-2.0 diff --git a/tests/arch/arm/arm_cde_cp0/src/main.c b/tests/arch/arm/arm_cde_cp0/src/main.c new file mode 100644 index 0000000000000..87d751f50d235 --- /dev/null +++ b/tests/arch/arm/arm_cde_cp0/src/main.c @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2026 Texas Instruments Incorporated + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +/* + * Build-only check that CONFIG_ARMV8_M_CDE_CP0 makes the compiler accept CDE + * instructions on coprocessor 0. The code is never run, since whether CP0 is + * implemented and enabled depends on the SoC. + */ + +#ifndef __ARM_FEATURE_CDE +#error "CDE is not enabled by the compiler flags" +#endif + +#if !(__ARM_FEATURE_CDE_COPROC & BIT(0)) +#error "CDE coprocessor 0 is not enabled by the compiler flags" +#endif + +int main(void) +{ + uint32_t val = __arm_cx1(0, 0); + + val = __arm_cx2(0, val, 0); + + return (int)val; +} diff --git a/tests/arch/arm/arm_cde_cp0/tests.yaml b/tests/arch/arm/arm_cde_cp0/tests.yaml new file mode 100644 index 0000000000000..a1fdc155caebe --- /dev/null +++ b/tests/arch/arm/arm_cde_cp0/tests.yaml @@ -0,0 +1,13 @@ +tests: + arch.arm.cde_cp0: + tags: + - arm + build_only: true + arch_allow: + - arm + platform_allow: + - mps2/an521/cpu0 + - mps2/an521/cpu0/ns + - mps3/corstone300/an547 + - mps4/corstone315/fvp + - lp_am13e230