Skip to content

Commit

Permalink
armv7-a/qemu: add Bound Multi-Processing (BMP) support
Browse files Browse the repository at this point in the history
Signed-off-by: chao an <[email protected]>
  • Loading branch information
anchao committed Aug 27, 2024
1 parent a72fd00 commit e0c0e8f
Show file tree
Hide file tree
Showing 20 changed files with 219 additions and 98 deletions.
4 changes: 2 additions & 2 deletions arch/arm/include/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ extern "C"
* such value for each processor that can receive an interrupt.
*/

EXTERN volatile uint32_t *g_current_regs[CONFIG_SMP_NCPUS];
EXTERN volatile uint32_t *g_current_regs[CONFIG_NR_CPUS];
#define CURRENT_REGS (g_current_regs[up_cpu_index()])

/****************************************************************************
Expand All @@ -121,7 +121,7 @@ EXTERN volatile uint32_t *g_current_regs[CONFIG_SMP_NCPUS];
*
****************************************************************************/

#ifdef CONFIG_SMP
#if defined(CONFIG_SMP) || defined(CONFIG_BMP)
int up_cpu_index(void) noinstrument_function;
#else
# define up_cpu_index() (0)
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/src/armv7-a/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ ifeq ($(CONFIG_ARCH_FPU),y)
CMN_ASRCS += arm_fpuconfig.S
endif

ifeq ($(CONFIG_SMP),y)
ifeq ($(CONFIG_SMP)$(CONFIG_BMP),y)
CMN_CSRCS += arm_cpuindex.c arm_cpustart.c arm_cpupause.c arm_cpuidlestack.c
CMN_CSRCS += arm_scu.c
endif
Expand Down
38 changes: 19 additions & 19 deletions arch/arm/src/armv7-a/arm_cpuhead.S
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "chip.h"
#include "arm_internal.h"

#ifdef CONFIG_SMP
#if defined(CONFIG_SMP) || defined(CONFIG_BMP)

.file "arm_cpuhead.S"

Expand Down Expand Up @@ -81,7 +81,7 @@
*
****************************************************************************/

#if CONFIG_SMP_NCPUS > 1
#if CONFIG_NR_CPUS > 1
.global __cpu1_start
.type __cpu1_start, #function

Expand All @@ -104,7 +104,7 @@ __cpu1_start:
.long .Lcpu1_stacktop
.size __cpu1_start, .-__cpu1_start

#if CONFIG_SMP_NCPUS > 2
#if CONFIG_NR_CPUS > 2
.global __cpu2_start
.type __cpu2_start, #function

Expand All @@ -127,7 +127,7 @@ __cpu2_start:
.long .Lcpu2_stacktop
.size __cpu2_start, .-__cpu2_start

#if CONFIG_SMP_NCPUS > 3
#if CONFIG_NR_CPUS > 3
.global __cpu3_start
.type __cpu3_start, #function

Expand All @@ -150,13 +150,13 @@ __cpu3_start:
.long .Lcpu3_stacktop
.size __cpu3_start, .-__cpu3_start

#if CONFIG_SMP_NCPUS > 4
# error This logic needs to extended for CONFIG_SMP_NCPUS > 4
#if CONFIG_NR_CPUS > 4
# error This logic needs to extended for CONFIG_NR_CPUS > 4

#endif /* CONFIG_SMP_NCPUS > 4 */
#endif /* CONFIG_SMP_NCPUS > 3 */
#endif /* CONFIG_SMP_NCPUS > 2 */
#endif /* CONFIG_SMP_NCPUS > 1 */
#endif /* CONFIG_NR_CPUS > 4 */
#endif /* CONFIG_NR_CPUS > 3 */
#endif /* CONFIG_NR_CPUS > 2 */
#endif /* CONFIG_NR_CPUS > 1 */

/****************************************************************************
* Name: .Lcpu_start
Expand Down Expand Up @@ -458,7 +458,7 @@ __cpu3_start:

.section .noinit, "aw"

#if CONFIG_SMP_NCPUS > 1
#if CONFIG_NR_CPUS > 1
.align 8
.globl g_cpu1_idlestack
.type g_cpu1_idlestack, object
Expand All @@ -468,7 +468,7 @@ g_cpu1_idlestack:
.Lcpu1_stacktop:
.size g_cpu1_idlestack, .Lcpu1_stacktop-g_cpu1_idlestack

#if CONFIG_SMP_NCPUS > 2
#if CONFIG_NR_CPUS > 2
.align 8
.globl g_cpu2_idlestack
.type g_cpu2_idlestack, object
Expand All @@ -478,7 +478,7 @@ g_cpu2_idlestack:
.Lcpu2_stacktop:
.size g_cpu2_idlestack, .Lcpu2_stacktop-g_cpu2_idlestack

#if CONFIG_SMP_NCPUS > 3
#if CONFIG_NR_CPUS > 3
.align 8
.globl g_cpu3_idlestack
.type g_cpu3_idlestack, object
Expand All @@ -488,12 +488,12 @@ g_cpu3_idlestack:
.Lcpu3_stacktop:
.size g_cpu3_idlestack, .Lcpu3_stacktop-g_cpu3_idlestack

#if CONFIG_SMP_NCPUS > 4
# error This logic needs to extended for CONFIG_SMP_NCPUS > 4
#if CONFIG_NR_CPUS > 4
# error This logic needs to extended for CONFIG_NR_CPUS > 4

#endif /* CONFIG_SMP_NCPUS > 4 */
#endif /* CONFIG_SMP_NCPUS > 3 */
#endif /* CONFIG_SMP_NCPUS > 2 */
#endif /* CONFIG_SMP_NCPUS > 1 */
#endif /* CONFIG_NR_CPUS > 4 */
#endif /* CONFIG_NR_CPUS > 3 */
#endif /* CONFIG_NR_CPUS > 2 */
#endif /* CONFIG_NR_CPUS > 1 */
#endif /* CONFIG_SMP */
.end
18 changes: 9 additions & 9 deletions arch/arm/src/armv7-a/arm_cpuidlestack.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "smp.h"
#include "arm_internal.h"

#ifdef CONFIG_SMP
#if defined(CONFIG_SMP) || defined(CONFIG_BMP)

/****************************************************************************
* Pre-processor Definitions
Expand All @@ -47,17 +47,17 @@
* Private Data
****************************************************************************/

#if CONFIG_SMP_NCPUS > 1
static const uint32_t *g_cpu_stackalloc[CONFIG_SMP_NCPUS] =
#if CONFIG_NR_CPUS > 1
static const uint32_t *g_cpu_stackalloc[CONFIG_NR_CPUS] =
{
0
, g_cpu1_idlestack
#if CONFIG_SMP_NCPUS > 2
#if CONFIG_NR_CPUS > 2
, g_cpu2_idlestack
#if CONFIG_SMP_NCPUS > 3
#if CONFIG_NR_CPUS > 3
, g_cpu3_idlestack
#endif /* CONFIG_SMP_NCPUS > 3 */
#endif /* CONFIG_SMP_NCPUS > 2 */
#endif /* CONFIG_NR_CPUS > 3 */
#endif /* CONFIG_NR_CPUS > 2 */
};
#endif

Expand Down Expand Up @@ -110,10 +110,10 @@ static const uint32_t *g_cpu_stackalloc[CONFIG_SMP_NCPUS] =

int up_cpu_idlestack(int cpu, struct tcb_s *tcb, size_t stack_size)
{
#if CONFIG_SMP_NCPUS > 1
#if CONFIG_NR_CPUS > 1
uintptr_t stack_alloc;

DEBUGASSERT(cpu > 0 && cpu < CONFIG_SMP_NCPUS && tcb != NULL &&
DEBUGASSERT(cpu > 0 && cpu < CONFIG_NR_CPUS && tcb != NULL &&
stack_size <= SMP_STACK_SIZE);

/* Get the top of the stack */
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/src/armv7-a/arm_cpuindex.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "cp15.h"
#include "sctlr.h"

#ifdef CONFIG_SMP
#if defined(CONFIG_SMP) || defined(CONFIG_BMP)

/****************************************************************************
* Public Functions
Expand Down
8 changes: 4 additions & 4 deletions arch/arm/src/armv7-a/arm_head.S
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
.type __start, #function

__start:
#if defined(CONFIG_SMP) && CONFIG_SMP_NCPUS > 1
#if (defined(CONFIG_SMP) || defined(CONFIG_BMP)) && CONFIG_NR_CPUS > 1
/* Get cpuindex, cpu0 continue boot, others wait event from cpu0 */

mrc CP15_MPIDR(r0)
Expand All @@ -196,15 +196,15 @@ __start:

cmp r0, #1
beq __cpu1_start
# if CONFIG_SMP_NCPUS > 2
# if CONFIG_NR_CPUS > 2
cmp r0, #2
beq __cpu2_start
# endif
# if CONFIG_SMP_NCPUS > 3
# if CONFIG_NR_CPUS > 3
cmp r0, #3
beq __cpu3_start
# endif
# if CONFIG_SMP_NCPUS > 4
# if CONFIG_NR_CPUS > 4
cmp r0, #4
beq __cpu4_start
# endif
Expand Down
18 changes: 14 additions & 4 deletions arch/arm/src/armv7-a/arm_initialstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,20 @@ void up_initial_state(struct tcb_s *tcb)

if (tcb->pid == IDLE_PROCESS_ID)
{
tcb->stack_alloc_ptr = (void *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE;
#ifdef CONFIG_BMP
if (up_cpu_index() > 0)
{
up_cpu_idlestack(up_cpu_index(), tcb,
CONFIG_IDLETHREAD_STACKSIZE);
}
else
#endif
{
tcb->stack_alloc_ptr = (void *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE;
}

#ifdef CONFIG_STACK_COLORATION
/* If stack debug is enabled, then fill the stack with a
Expand Down
12 changes: 6 additions & 6 deletions arch/arm/src/armv7-a/arm_vectors.S
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
*
****************************************************************************/

#if !defined(CONFIG_SMP) && CONFIG_ARCH_INTERRUPTSTACK > 7
#if !defined(CONFIG_SMP) && !defined(CONFIG_BMP) && CONFIG_ARCH_INTERRUPTSTACK > 7
.macro cpuindex, index
.mov \index, #0
.endm
Expand All @@ -67,7 +67,7 @@
*
****************************************************************************/

#if !defined(CONFIG_SMP) && CONFIG_ARCH_INTERRUPTSTACK > 7
#if !defined(CONFIG_SMP) && !defined(CONFIG_BMP) && CONFIG_ARCH_INTERRUPTSTACK > 7
.macro setirqstack, tmp1, tmp2
ldr sp, .Lirqstacktop /* SP = IRQ stack top */
.endm
Expand All @@ -82,7 +82,7 @@
*
****************************************************************************/

#if !defined(CONFIG_SMP) && CONFIG_ARCH_INTERRUPTSTACK > 7
#if !defined(CONFIG_SMP) && !defined(CONFIG_BMP) && CONFIG_ARCH_INTERRUPTSTACK > 7
.macro setfiqstack, tmp1, tmp2
ldr sp, .Lfiqstacktop /* SP = FIQ stack top */
.endm
Expand Down Expand Up @@ -262,7 +262,7 @@ arm_vectorirq:

rfeia r14

#if !defined(CONFIG_SMP) && CONFIG_ARCH_INTERRUPTSTACK > 7
#if !defined(CONFIG_SMP) && !defined(CONFIG_BMP) && CONFIG_ARCH_INTERRUPTSTACK > 7
.Lirqstacktop:
.word g_intstacktop
#endif
Expand Down Expand Up @@ -722,7 +722,7 @@ arm_vectorfiq:

rfeia r14

#if !defined(CONFIG_SMP) && CONFIG_ARCH_INTERRUPTSTACK > 7
#if !defined(CONFIG_SMP) && !defined(CONFIG_BMP) && CONFIG_ARCH_INTERRUPTSTACK > 7
.Lfiqstacktop:
.word g_fiqstacktop
#endif
Expand Down Expand Up @@ -752,7 +752,7 @@ arm_vectoraddrexcptn:
* Name: g_intstackalloc/g_intstacktop
****************************************************************************/

#if !defined(CONFIG_SMP) && CONFIG_ARCH_INTERRUPTSTACK > 7
#if !defined(CONFIG_SMP) && !defined(CONFIG_BMP) && CONFIG_ARCH_INTERRUPTSTACK > 7
.bss
.balign 8

Expand Down
4 changes: 2 additions & 2 deletions arch/arm/src/armv7-a/mmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@
#define MMU_ROMFLAGS (PMD_TYPE_SECT | PMD_SECT_AP_R1 | PMD_CACHEABLE | \
PMD_SECT_DOM(0))

#ifdef CONFIG_SMP
#if defined(CONFIG_SMP) || defined(CONFIG_BMP)
#define MMU_MEMFLAGS (PMD_TYPE_SECT | PMD_SECT_AP_RW1 | PMD_CACHEABLE | \
PMD_SECT_S | PMD_SECT_DOM(0))
#else
Expand All @@ -605,7 +605,7 @@
#endif

#define MMU_L1_DATAFLAGS (PMD_TYPE_PTE | PMD_PTE_PXN | PMD_PTE_DOM(0))
#ifndef CONFIG_SMP
#if !defined(CONFIG_SMP) && !defined(CONFIG_BMP)
# define MMU_L2_UDATAFLAGS (PTE_TYPE_SMALL | PTE_WRITE_BACK | PTE_AP_RW01)
# define MMU_L2_KDATAFLAGS (PTE_TYPE_SMALL | PTE_WRITE_BACK | PTE_AP_RW1)
# define MMU_L2_UALLOCFLAGS (PTE_TYPE_SMALL | PTE_WRITE_BACK | PTE_AP_RW01)
Expand Down
30 changes: 15 additions & 15 deletions arch/arm/src/armv7-a/smp.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#include <nuttx/config.h>

#ifdef CONFIG_SMP
#if defined(CONFIG_SMP) || defined(CONFIG_BMP)

/****************************************************************************
* Pre-processor Definitions
Expand All @@ -49,18 +49,18 @@

#ifndef __ASSEMBLY__

#if CONFIG_SMP_NCPUS > 1
#if CONFIG_NR_CPUS > 1
extern uint32_t g_cpu1_idlestack[SMP_STACK_WORDS];
#if CONFIG_SMP_NCPUS > 2
#if CONFIG_NR_CPUS > 2
extern uint32_t g_cpu2_idlestack[SMP_STACK_WORDS];
#if CONFIG_SMP_NCPUS > 3
#if CONFIG_NR_CPUS > 3
extern uint32_t g_cpu3_idlestack[SMP_STACK_WORDS];
#if CONFIG_SMP_NCPUS > 4
# error This logic needs to extended for CONFIG_SMP_NCPUS > 4
#endif /* CONFIG_SMP_NCPUS > 4 */
#endif /* CONFIG_SMP_NCPUS > 3 */
#endif /* CONFIG_SMP_NCPUS > 2 */
#endif /* CONFIG_SMP_NCPUS > 1 */
#if CONFIG_NR_CPUS > 4
# error This logic needs to extended for CONFIG_NR_CPUS > 4
#endif /* CONFIG_NR_CPUS > 4 */
#endif /* CONFIG_NR_CPUS > 3 */
#endif /* CONFIG_NR_CPUS > 2 */
#endif /* CONFIG_NR_CPUS > 1 */

/****************************************************************************
* Public Function Prototypes
Expand All @@ -84,20 +84,20 @@ extern uint32_t g_cpu3_idlestack[SMP_STACK_WORDS];
*
****************************************************************************/

#if CONFIG_SMP_NCPUS > 1
#if CONFIG_NR_CPUS > 1
void __cpu1_start(void);
#endif

#if CONFIG_SMP_NCPUS > 2
#if CONFIG_NR_CPUS > 2
void __cpu2_start(void);
#endif

#if CONFIG_SMP_NCPUS > 3
#if CONFIG_NR_CPUS > 3
void __cpu3_start(void);
#endif

#if CONFIG_SMP_NCPUS > 4
# error This logic needs to extended for CONFIG_SMP_NCPUS > 4
#if CONFIG_NR_CPUS > 4
# error This logic needs to extended for CONFIG_NR_CPUS > 4
#endif

/****************************************************************************
Expand Down
10 changes: 9 additions & 1 deletion arch/arm/src/common/arm_allocateheap.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,22 @@ void weak_function up_allocate_heap(void **heap_start, size_t *heap_size)
/* Return the heap settings */

board_autoled_on(LED_HEAPALLOCATE);
*heap_start = (void *)g_idle_topstack;

#ifdef CONFIG_ARCH_PGPOOL_PBASE
*heap_size = CONFIG_ARCH_PGPOOL_PBASE - g_idle_topstack;
#else
*heap_size = CONFIG_RAM_END - g_idle_topstack;
#endif

#ifdef CONFIG_BMP
size_t reserve = g_cpu_data_size * (CONFIG_BMP_NCPUS - 1);
*heap_size = (*heap_size - reserve) / CONFIG_BMP_NCPUS;
*heap_start = (void *)((uintptr_t)g_idle_topstack + reserve +
*heap_size * up_cpu_index());
#else
*heap_start = (void *)g_idle_topstack;
#endif

#endif
}

Expand Down
Loading

0 comments on commit e0c0e8f

Please sign in to comment.