Skip to content

Commit da4cf22

Browse files
committed
arch/tricore: Run one SMP kernel on all CPUs.
With SMP the other CPUs run this image instead of their own: CPU0 no longer releases them to __start1 and up at boot, and up_cpu_start() starts them at __start_secondary once the kernel runs. A secondary CPU builds its CSA pool, interrupt stack and idle stack in its own data scratchpad RAM, takes the trap and interrupt vectors of CPU0 and joins as its idle task. CPU0 attaches and enables the GPSR of every CPU pair as inter-CPU interrupt; an IPI is one write to the software broadcast register. On TC4x CPU0 lets every CPU use the interrupt router, the scratchpad RAMs and DLMUs, the STM of CPU0 and the console UART. The data cache stays bypassed, since data in a cached segment would not be coherent. The context switch now also balances the CSA frames and restores the critical section of the new task, and the idle loop waits for an interrupt instead of spinning so it can balance too. The idle stacks of the secondary CPUs are colored like the other stacks, so the stack usage shows right. SMP needs the GNU toolchain, as the secondary entry is only in the GNU startup code; a build with SMP and another toolchain stops with an error. Signed-off-by: Santhosh Charles <santhosh@linumiz.com>
1 parent 695a24b commit da4cf22

15 files changed

Lines changed: 609 additions & 5 deletions

‎arch/tricore/src/common/CMakeLists.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ if(CONFIG_ARCH_HAVE_DEBUG)
7575
list(APPEND SRCS tricore_hwdebug.c)
7676
endif()
7777

78+
if(CONFIG_SMP)
79+
list(APPEND SRCS tricore_cpustart.c)
80+
endif()
81+
7882
target_sources(arch PRIVATE ${SRCS})
7983
target_sources(nuttx PRIVATE tricore_doirq.c)
8084

‎arch/tricore/src/common/Make.defs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ ifeq ($(CONFIG_ARCH_HAVE_DEBUG),y)
8888
CMN_CSRCS += tricore_hwdebug.c
8989
endif
9090

91+
ifeq ($(CONFIG_SMP),y)
92+
CMN_CSRCS += tricore_cpustart.c
93+
endif
94+
9195
# TASKING toolchain: build a fake libc_fpu.a to override the toolchain's
9296
# default C library and provide stubs for the symbols the linker still
9397
# references (see tricore_libc.c for details).

‎arch/tricore/src/common/aurix/tricore_serial.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
# include "tc3x_wdt.h"
5050
#elif defined(CONFIG_ARCH_CHIP_TC4X)
5151
# include "hardware/tc4x_port.h"
52+
# ifdef CONFIG_SMP
53+
# include "hardware/tc4x_cpu.h"
54+
# endif
5255
#endif
5356

5457
#include <chip.h>
@@ -361,6 +364,11 @@ static void asclin_init(struct up_dev_s *priv)
361364
tc3x_wdt_cpu_endinit(true);
362365
#endif
363366

367+
#if defined(CONFIG_SMP) && defined(CONFIG_ARCH_CHIP_TC4X)
368+
asclin_modify(ASCLIN_REG(priv, ACCEN_WRA), 0,
369+
TC4X_CPU_TAGS_ALL(CONFIG_SMP_NCPUS));
370+
#endif
371+
364372
/* Clock off, initialise mode, bit timing and baud rate */
365373

366374
asclin_set_clock(priv, ASCLIN_CSR_CLKSEL_NONE);

‎arch/tricore/src/common/gnu/tricore_head.S‎

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
#include <nuttx/config.h>
2828
#include <arch/csfr.h>
29+
#ifdef CONFIG_SMP
30+
# include "tricore_smp.h"
31+
#endif
2932

3033
/****************************************************************************
3134
* Pre-processor Definitions
@@ -34,6 +37,18 @@
3437
#define TRICORE_PSW_RESET 0x980 /* Supervisor, call depth counting on */
3538
#define TRICORE_BIV_VECTOR 0x1fe0 /* Single interrupt vector at INTTAB + 0x1fe0 */
3639

40+
/* DCON0: with SMP the data cache stays bypassed, as data in a cached
41+
* segment would not be coherent between the CPUs
42+
*/
43+
44+
#define TRICORE_DCON0_DCBYP 0x2
45+
46+
#ifdef CONFIG_SMP
47+
# define TRICORE_DCON0_BOOT TRICORE_DCON0_DCBYP
48+
#else
49+
# define TRICORE_DCON0_BOOT 0
50+
#endif
51+
3752
#ifdef CONFIG_ARCH_CHIP_TC3X
3853
# define TC3X_WDTCPU0_CON0 0xf003624c /* CPU0 watchdog CON0, 0xc apart per CPU */
3954
#endif
@@ -151,6 +166,7 @@ tricore_head:
151166
mov %d15, 0
152167
mtcr TRICORE_CPU_PCON0, %d15
153168
isync
169+
mov %d15, TRICORE_DCON0_BOOT
154170
mtcr TRICORE_CPU_DCON0, %d15
155171
isync
156172

@@ -243,6 +259,112 @@ tricore_head:
243259
lea %a15, [%a15]lo:tricore_start
244260
ji %a15
245261

262+
#ifdef CONFIG_SMP
263+
/****************************************************************************
264+
* Name: __start_secondary
265+
*
266+
* Description:
267+
* Entry of CPU1 and up with SMP, where up_cpu_start() releases them from
268+
* the boot halt once the kernel runs on CPU0. Set up the core registers
269+
* like tricore_head, with the CSA pool, the interrupt stack and the idle
270+
* stack at the start of the data scratchpad RAM of this core (see
271+
* tricore_smp.h), disable the watchdog of this CPU and call
272+
* tricore_cpu_boot. .data, .bss and the clocks are already set up.
273+
* Only CPU0 has the hypervisor context, so the virtualization is left
274+
* alone here.
275+
*
276+
****************************************************************************/
277+
278+
.global __start_secondary
279+
.type __start_secondary, %function
280+
__start_secondary:
281+
#ifdef CONFIG_ARCH_CHIP_TC3X
282+
jl tc3x_endinit_clear
283+
#endif
284+
285+
/* D12 is the base of the data scratchpad RAM of this core */
286+
287+
mfcr %d12, TRICORE_CPU_CORE_ID
288+
extr.u %d12, %d12, 0, 3
289+
rsub %d12, %d12, TRICORE_SMP_DSPR_SEG_TOP
290+
sh %d12, %d12, TRICORE_SMP_SEG_SHIFT
291+
292+
movh.a %a15, hi:__TRAPTAB_CPU0
293+
lea %a15, [%a15]lo:__TRAPTAB_CPU0
294+
mov.d %d15, %a15
295+
mtcr TRICORE_CPU_BTV, %d15
296+
isync
297+
298+
mov %d15, 0
299+
mtcr TRICORE_CPU_PCON0, %d15
300+
isync
301+
mov %d15, TRICORE_DCON0_BOOT
302+
mtcr TRICORE_CPU_DCON0, %d15
303+
isync
304+
305+
movh.a %a15, hi:__INTTAB_CPU0
306+
lea %a15, [%a15]lo:__INTTAB_CPU0
307+
lea %a15, [%a15]TRICORE_BIV_VECTOR
308+
mov.d %d15, %a15
309+
mtcr TRICORE_CPU_BIV, %d15
310+
isync
311+
312+
movh %d15, hi:TRICORE_SMP_ISTACK_TOP
313+
addi %d15, %d15, lo:TRICORE_SMP_ISTACK_TOP
314+
add %d15, %d15, %d12
315+
mtcr TRICORE_CPU_ISP, %d15
316+
isync
317+
318+
/* Free CSA list over the pool of this core, LCX at the third last */
319+
320+
mov.a %a15, %d12
321+
movh %d15, hi:TRICORE_SMP_CSA_SIZE
322+
addi %d15, %d15, lo:TRICORE_SMP_CSA_SIZE
323+
add %d15, %d15, %d12
324+
mov.a %a14, %d15
325+
mov.d %d15, %a15
326+
tricore_csa_link %d15, %d14, %d13
327+
mtcr TRICORE_CPU_FCX, %d15
328+
isync
329+
1:
330+
addi %d15, %d15, 1
331+
st.w [%a15], %d15
332+
lea %a15, [%a15]TRICORE_SMP_CSA_FRAME
333+
jne.a %a15, %a14, 1b
334+
mov %d14, 0
335+
st.w [%a15]-TRICORE_SMP_CSA_FRAME, %d14
336+
addi %d15, %d15, -TRICORE_SMP_CSA_RESERVE
337+
mtcr TRICORE_CPU_LCX, %d15
338+
isync
339+
340+
#ifdef CONFIG_ARCH_CHIP_TC3X
341+
jl tc3x_endinit_set
342+
#endif
343+
344+
movh %d15, hi:TRICORE_SMP_USTACK_TOP
345+
addi %d15, %d15, lo:TRICORE_SMP_USTACK_TOP
346+
add %d15, %d15, %d12
347+
mov.a %sp, %d15
348+
dsync
349+
350+
movh.a %a1, hi:__a1_mem
351+
lea %a1, [%a1]lo:__a1_mem
352+
movh.a %a0, hi:__a0_mem
353+
lea %a0, [%a0]lo:__a0_mem
354+
movh.a %a8, hi:__a8_mem
355+
lea %a8, [%a8]lo:__a8_mem
356+
movh.a %a9, hi:__a9_mem
357+
lea %a9, [%a9]lo:__a9_mem
358+
359+
mov %d0, TRICORE_PSW_RESET
360+
mtcr TRICORE_CPU_PSW, %d0
361+
isync
362+
363+
call tricore_wdt_disable
364+
call tricore_cpu_boot
365+
debug
366+
#endif
367+
246368
#ifdef CONFIG_ARCH_CHIP_TC3X
247369
/****************************************************************************
248370
* Name: tc3x_endinit_clear, tc3x_endinit_set

0 commit comments

Comments
 (0)