arm/cortex-a,r: replace cp15 instruct to macros to align operation

This is continue work of https://github.com/apache/nuttx/pull/13486

Discussion here:
https://github.com/apache/nuttx/pull/13486#discussion_r1764354675

1. move cp15.h to arch public
2. replace cp15 instruct to macros to align operation
3. add memory barrier to avoid compiler optimization

Signed-off-by: chao an <anchao@lixiang.com>
This commit is contained in:
chao an 2024-09-19 08:32:35 +08:00 committed by Xiang Xiao
parent e627850442
commit b82717b9e6
32 changed files with 82 additions and 85 deletions

View File

@ -1,5 +1,5 @@
/****************************************************************************
* arch/arm/src/armv7-a/cp15.h
* arch/arm/include/armv7-a/cp15.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with

View File

@ -36,6 +36,8 @@
# include <stdint.h>
#endif
#include <arch/armv7-a/cp15.h>
/****************************************************************************
* Pre-processor Prototypes
****************************************************************************/
@ -457,11 +459,7 @@ static inline_function int up_cpu_index(void)
/* Read the Multiprocessor Affinity Register (MPIDR) */
__asm__ __volatile__
(
"mrc " "p15, " "0" ", %0, " "c0" ", " "c0" ", " "5" "\n"
: "=r"(mpidr)
);
mpidr = CP15_GET(MPIDR);
/* And return the CPU ID field */
@ -500,23 +498,13 @@ static inline_function uint32_t up_getsp(void)
noinstrument_function
static inline_function uint32_t *up_current_regs(void)
{
uint32_t *regs;
__asm__ __volatile__
(
"mrc " "p15, " "0" ", %0, " "c13" ", " "c0" ", " "4" "\n"
: "=r"(regs)
);
return regs;
return (uint32_t *)CP15_GET(TPIDRPRW);
}
noinstrument_function
static inline_function void up_set_current_regs(uint32_t *regs)
{
__asm__ __volatile__
(
"mcr " "p15, " "0" ", %0, " "c13" ", " "c0" ", " "4" "\n"
:: "r"(regs)
);
CP15_SET(TPIDRPRW, regs);
}
noinstrument_function

View File

@ -1,5 +1,5 @@
/****************************************************************************
* arch/arm/src/armv7-r/cp15.h
* arch/arm/include/armv7-r/cp15.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with

View File

@ -36,6 +36,8 @@
# include <stdint.h>
#endif
#include <arch/armv7-r/cp15.h>
/****************************************************************************
* Pre-processor Prototypes
****************************************************************************/
@ -357,7 +359,7 @@ static inline irqstate_t irqstate(void)
/* Disable IRQs and return the previous IRQ state */
static inline irqstate_t up_irq_save(void)
noinstrument_function static inline irqstate_t up_irq_save(void)
{
unsigned int cpsr;
@ -417,7 +419,7 @@ static inline irqstate_t up_irq_disable(void)
/* Restore saved IRQ & FIQ state */
static inline void up_irq_restore(irqstate_t flags)
noinstrument_function static inline void up_irq_restore(irqstate_t flags)
{
__asm__ __volatile__
(
@ -452,11 +454,7 @@ static inline_function int up_cpu_index(void)
/* Read the Multiprocessor Affinity Register (MPIDR) */
__asm__ __volatile__
(
"mrc " "p15, " "0" ", %0, " "c0" ", " "c0" ", " "5" "\n"
: "=r"(mpidr)
);
mpidr = CP15_GET(MPIDR);
/* And return the CPU ID field */
@ -479,26 +477,29 @@ static inline_function uint32_t up_getsp(void)
return sp;
}
/****************************************************************************
* Name:
* up_current_regs/up_set_current_regs
*
* Description:
* We use the following code to manipulate the TPIDRPRW register,
* which exists uniquely for each CPU and is primarily designed to store
* current thread information. Currently, we leverage it to store interrupt
* information, with plans to further optimize its use for storing both
* thread and interrupt information in the future.
*
****************************************************************************/
noinstrument_function
static inline_function uint32_t *up_current_regs(void)
{
uint32_t *regs;
__asm__ __volatile__
(
"mrc " "p15, " "0" ", %0, " "c13" ", " "c0" ", " "4" "\n"
: "=r"(regs)
);
return regs;
return (uint32_t *)CP15_GET(TPIDRPRW);
}
noinstrument_function
static inline_function void up_set_current_regs(uint32_t *regs)
{
__asm__ __volatile__
(
"mcr " "p15, " "0" ", %0, " "c13" ", " "c0" ", " "4" "\n"
:: "r"(regs)
);
CP15_SET(TPIDRPRW, regs);
}
noinstrument_function

View File

@ -1,5 +1,5 @@
/****************************************************************************
* arch/arm/src/armv8-r/cp15.h
* arch/arm/include/armv8-r/cp15.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with

View File

@ -36,6 +36,8 @@
# include <stdint.h>
#endif
#include <arch/armv8-r/cp15.h>
/****************************************************************************
* Pre-processor Prototypes
****************************************************************************/
@ -357,7 +359,7 @@ static inline irqstate_t irqstate(void)
/* Disable IRQs and return the previous IRQ state */
static inline irqstate_t up_irq_save(void)
noinstrument_function static inline irqstate_t up_irq_save(void)
{
unsigned int cpsr;
@ -417,7 +419,7 @@ static inline irqstate_t up_irq_disable(void)
/* Restore saved IRQ & FIQ state */
static inline void up_irq_restore(irqstate_t flags)
noinstrument_function static inline void up_irq_restore(irqstate_t flags)
{
__asm__ __volatile__
(
@ -452,11 +454,7 @@ static inline_function int up_cpu_index(void)
/* Read the Multiprocessor Affinity Register (MPIDR) */
__asm__ __volatile__
(
"mrc " "p15, " "0" ", %0, " "c0" ", " "c0" ", " "5" "\n"
: "=r"(mpidr)
);
mpidr = CP15_GET(MPIDR);
/* And return the CPU ID field */
@ -479,26 +477,29 @@ static inline_function uint32_t up_getsp(void)
return sp;
}
/****************************************************************************
* Name:
* up_current_regs/up_set_current_regs
*
* Description:
* We use the following code to manipulate the TPIDRPRW register,
* which exists uniquely for each CPU and is primarily designed to store
* current thread information. Currently, we leverage it to store interrupt
* information, with plans to further optimize its use for storing both
* thread and interrupt information in the future.
*
****************************************************************************/
noinstrument_function
static inline_function uint32_t *up_current_regs(void)
{
uint32_t *regs;
__asm__ __volatile__
(
"mrc " "p15, " "0" ", %0, " "c13" ", " "c0" ", " "4" "\n"
: "=r"(regs)
);
return regs;
return (uint32_t *)CP15_GET(TPIDRPRW);
}
noinstrument_function
static inline_function void up_set_current_regs(uint32_t *regs)
{
__asm__ __volatile__
(
"mcr " "p15, " "0" ", %0, " "c13" ", " "c0" ", " "4" "\n"
:: "r"(regs)
);
CP15_SET(TPIDRPRW, regs);
}
noinstrument_function

View File

@ -27,7 +27,6 @@
#include <arch/irq.h>
#include "arm.h"
#include "cp15.h"
#include "sctlr.h"
#include "mmu.h"
#include "smp.h"

View File

@ -26,9 +26,10 @@
#include <nuttx/config.h>
#include <nuttx/fs/procfs.h>
#include <arch/irq.h>
#include "arm_internal.h"
#include "hwcap.h"
#include "cp15.h"
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_CPUINFO)

View File

@ -23,7 +23,8 @@
****************************************************************************/
#include <nuttx/config.h>
#include "cp15.h"
#include <arch/irq.h>
#ifdef CONFIG_ARCH_FPU

View File

@ -24,8 +24,9 @@
#include <nuttx/config.h>
#include <arch/irq.h>
#include "arm.h"
#include "cp15.h"
#include "sctlr.h"
#include "mmu.h"
#include "chip.h"

View File

@ -25,8 +25,9 @@
#include <nuttx/config.h>
#include <nuttx/page.h>
#include <arch/irq.h>
#include "arm.h"
#include "cp15.h"
#include "sctlr.h"
#include "mmu.h"
#include "chip.h"

View File

@ -26,12 +26,13 @@
#include <stdint.h>
#include <arch/irq.h>
#include "arm_internal.h"
#include "cp15_cacheops.h"
#include "barriers.h"
#include "sctlr.h"
#include "scu.h"
#include "cp15.h"
/****************************************************************************
* Public Functions

View File

@ -27,10 +27,11 @@
#include <nuttx/irq.h>
#include <nuttx/kmalloc.h>
#include <arch/irq.h>
#include "arm_timer.h"
#include "barriers.h"
#include "gic.h"
#include "cp15.h"
/****************************************************************************
* Pre-processor Definitions

View File

@ -26,7 +26,6 @@
#include <nuttx/irq.h>
#include "arm.h"
#include "cp15.h"
#include "chip.h"
.file "arm_vectors.S"

View File

@ -34,8 +34,9 @@
* Included Files
****************************************************************************/
#include <arch/irq.h>
#include "barriers.h"
#include "cp15.h"
/****************************************************************************
* Pre-processor Definitions

View File

@ -27,7 +27,6 @@
#include <arch/irq.h>
#include "arm.h"
#include "cp15.h"
#include "sctlr.h"
#include "smp.h"
#include "chip.h"

View File

@ -26,9 +26,10 @@
#include <nuttx/config.h>
#include <nuttx/fs/procfs.h>
#include <arch/irq.h>
#include "arm_internal.h"
#include "hwcap.h"
#include "cp15.h"
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_CPUINFO)

View File

@ -23,7 +23,8 @@
****************************************************************************/
#include <nuttx/config.h>
#include "cp15.h"
#include <arch/irq.h>
#ifdef CONFIG_ARCH_FPU

View File

@ -24,8 +24,9 @@
#include <nuttx/config.h>
#include <arch/irq.h>
#include "arm.h"
#include "cp15.h"
#include "sctlr.h"
#include "arm_internal.h"

View File

@ -26,12 +26,13 @@
#include <stdint.h>
#include <arch/irq.h>
#include "arm_internal.h"
#include "cp15_cacheops.h"
#include "barriers.h"
#include "sctlr.h"
#include "scu.h"
#include "cp15.h"
/****************************************************************************
* Public Functions

View File

@ -30,7 +30,6 @@
#include "arm_timer.h"
#include "barriers.h"
#include "gic.h"
#include "cp15.h"
/****************************************************************************
* Pre-processor Definitions

View File

@ -26,7 +26,6 @@
#include <nuttx/irq.h>
#include "arm.h"
#include "cp15.h"
.file "arm_vectors.S"

View File

@ -34,7 +34,6 @@
# include <debug.h>
# include "sctlr.h"
# include "cp15.h"
#endif
/****************************************************************************

View File

@ -32,8 +32,9 @@
* Included Files
****************************************************************************/
#include <arch/irq.h>
#include "barriers.h"
#include "cp15.h"
/****************************************************************************
* Pre-processor Definitions

View File

@ -34,7 +34,6 @@
#include <nuttx/timers/arch_alarm.h>
#include "barriers.h"
#include "cp15.h"
#include "arm_gic.h"
#include "arm_arch_timer.h"
@ -418,4 +417,4 @@ void arm_arch_timer_secondary_init()
arm_arch_timer_enable(true);
#endif
}
#endif
#endif

View File

@ -26,9 +26,10 @@
#include <nuttx/config.h>
#include <nuttx/fs/procfs.h>
#include <arch/irq.h>
#include "arm_internal.h"
#include "hwcap.h"
#include "cp15.h"
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_CPUINFO)

View File

@ -23,7 +23,8 @@
****************************************************************************/
#include <nuttx/config.h>
#include "cp15.h"
#include <arch/irq.h>
#ifdef CONFIG_ARCH_FPU

View File

@ -33,7 +33,6 @@
#include "arm_internal.h"
#include "barriers.h"
#include "cp15.h"
#include "arm_gic.h"
/***************************************************************************

View File

@ -24,8 +24,9 @@
#include <nuttx/config.h>
#include <arch/irq.h>
#include "arm.h"
#include "cp15.h"
#include "cp15_cacheops.h"
#include "sctlr.h"
#include "arm_internal.h"

View File

@ -26,7 +26,6 @@
#include <nuttx/irq.h>
#include "arm.h"
#include "cp15.h"
.file "arm_vectors.S"

View File

@ -32,8 +32,9 @@
* Included Files
****************************************************************************/
#include <arch/irq.h>
#include "barriers.h"
#include "cp15.h"
/****************************************************************************
* Pre-processor Definitions

View File

@ -28,12 +28,12 @@
#include <assert.h>
#include <debug.h>
#include <arch/irq.h>
#include <arch/chip/chip.h>
#include "arm_internal.h"
#include "barriers.h"
#include "cp15.h"
#include "arm_gic.h"
#include "chip.h"
#include "fvp_boot.h"