Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6c3fad6
arch/tricore: use 'ji' instead of 'call' to execute svcall function
zhangyu981027 Jun 4, 2025
e83ad98
arch/tricore: return from trapcall by jump since it is entered by jump
zhangyu981027 Aug 26, 2025
455f981
arch/tricore: add bus error hook func to handle safety bus test
yangsong8-a1 Feb 24, 2026
0af9e09
arch/tricore: Implementing trap vector table without relying on illd
zhangyu981027 Jun 16, 2026
4bead1d
arch/tricore: handling FCU exception(FCX=0, means no csa any more)
zhangyu981027 Jun 17, 2026
e3f3a1a
arch/tricore: cleanup trap related code for small codesize
zhangyu981027 Jul 13, 2026
c3fcb59
arch/tricore: adaptive multi cores for irq
gneworld Dec 17, 2024
99b2771
arch/tricore: fixed tc3xx tos issue
zyfeier Aug 14, 2025
7c85c74
arch/tricore: get right tos for tc3xx
zyfeier Sep 19, 2025
62f9dc1
arch/tricore: use psw.is to determine interrupt context
zhangyu981027 Apr 3, 2026
4e584b1
arch/tricore: do not use up_interrupt_context() in trap handler
zhangyu981027 Jun 11, 2026
fa43f07
arch/tricore: use ICR.CCPN instead of ICR.IE for interrupt masking
zhangyu981027 Apr 13, 2026
d45900c
arch/tricore: add srpn_to_irq map vector
zhangyu981027 Apr 13, 2026
3f0be68
arch/tricore: add tricore_register_irq_srpn for MCAL IRQ integration
yangsong8-a1 Jun 17, 2026
3671cf3
arch/tricore: remove up_irq_to_ndx implementation
zhangyu981027 Apr 27, 2026
b10c314
irq: shrink IRQ mapping table element types to save memory
zyfeier Aug 12, 2026
e8a70bb
arch/tricore: support interrupt nested
zhangyu981027 Apr 21, 2026
4c260e3
arch/tricore: support sw-managed single-entry IRQ dispatch
zhangyu981027 Oct 30, 2026
85e4af9
arch/tricore: return 0 in up_getusrsp when regs is NULL
zhangyu981027 May 7, 2026
d35556f
arch/tricore: use lasr register to get irq number
zhangyu981027 Oct 30, 2026
8819a03
arch/tricore: fully implement 255 interrupt tables
zhangyu981027 Oct 30, 2026
744429b
arch/tricore: drop the last illd headers and define registers ourselves
zhangyu981027 Aug 31, 2026
dc18bd9
arch/tricore: drop illd dependence for irq
zhangyu981027 Oct 31, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions arch/tricore/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ config ARCH_TC1V6
bool
select ARCH_HAVE_DEBUG
select ARCH_HAVE_MPU
select ARCH_HAVE_HIPRI_INTERRUPT
select ARCH_HAVE_IRQPRIO
select ARCH_HAVE_IRQTRIGGER
select ARCH_HAVE_PERF_EVENTS
select ARCH_HAVE_POWEROFF
Expand All @@ -41,6 +43,8 @@ config ARCH_TC1V8
select ARCH_HAVE_DEBUG
select ARCH_ICACHE
select ARCH_HAVE_MPU
select ARCH_HAVE_HIPRI_INTERRUPT
select ARCH_HAVE_IRQPRIO
select ARCH_HAVE_IRQTRIGGER
select ARCH_HAVE_PERF_EVENTS
select ARCH_HAVE_PERF_EVENTS_USER_ACCESS
Expand Down Expand Up @@ -88,6 +92,24 @@ config ARCH_CHIP
default "tc3xx" if ARCH_CHIP_TC3XX
default "tc4xx" if ARCH_CHIP_TC4XX

config ARCH_IRQ_DISABLE_PRIORITY
int "IRQ disable priority threshold"
default 250
range 1 255
depends on ARCH_HIPRI_INTERRUPT
---help---
Interrupts with SRPN > this value are treated as
high-priority and will not be masked.

config ARCH_IRQ_MAX_PRIORITY
int "Number of interrupt vector table entries"
default 255
range 1 255
---help---
Number of entries generated in the interrupt vector table.
Hardware supports up to 255. Reduce to save flash on
resource-constrained cores.

config ARCH_DCACHE_ADDR
hex "AURIX Dcache base address"
default 0x7003C000
Expand All @@ -113,6 +135,11 @@ config ARCH_MPU_CODE_NREGIONS
---help---
The code regions count

config ARCH_DEBUG_TRAP_ALERT
bool "TriCore Trap Alert Debug"
default !DEFAULT_SMALL
depends on DEBUG_ALERT

config HAVE_SECURITY_CORE
bool
---help---
Expand Down
41 changes: 41 additions & 0 deletions arch/tricore/include/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@
* Pre-processor Definitions
****************************************************************************/

/* TriCore core special function register (CSFR) */

#define CPU_PCXI 0xFE00 /* Previous Context Information */
#define CPU_PSW 0xFE04 /* Program Status Word */
#define CPU_PC 0xFE08 /* Program Counter */
#define CPU_SYSCON 0xFE14 /* System Control Register */
#define CPU_CORE_ID 0xFE1C /* CPU Core Identification */
#define CPU_ICR 0xFE2C /* Interrupt Control Register */
#define CPU_PPRS 0xFE34 /* Physical Protection Selection */
#define CPU_FCX 0xFE38 /* Free CSA List Head Pointer */
#define CPU_LCX 0xFE3C /* Free CSA List Limit Pointer */

#define CPU_CCTRL 0xFC00 /* Counter Control */
#define CPU_CCNT 0xFC04 /* CPU Clock Cycle Count */

/* MTCR and MFCR - move to / from Core Special Function Register */

#define tricore_mtcr(reg, val) \
Expand All @@ -58,6 +73,32 @@
__val; \
})

/* Jump back to the return address. */

#ifdef CONFIG_TRICORE_TOOLCHAIN_TASKING
# define tricore_jump_backto_link() __asm__ volatile ("ji a11")
#else
# define tricore_jump_backto_link() __asm__ volatile ("ji %a11")
#endif

/* Read the return address register. */

#ifdef CONFIG_TRICORE_TOOLCHAIN_TASKING
# define tricore_get_a11() \
({ \
uintptr_t __ra; \
__asm__ volatile ("mov.aa %0, a11" : "=a"(__ra) : : "a11"); \
__ra; \
})
#else
# define tricore_get_a11() \
({ \
uintptr_t __ra; \
__asm__ volatile ("mov.aa %0, %%a11" : "=a"(__ra) : : "a11"); \
__ra; \
})
#endif

/****************************************************************************
* Public Types
****************************************************************************/
Expand Down
130 changes: 86 additions & 44 deletions arch/tricore/include/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@

#include <arch/chip/irq.h>
#include <arch/arch.h>
#include <IfxCpu_Intrinsics.h>

/****************************************************************************
* Pre-processor Prototypes
Expand Down Expand Up @@ -133,10 +132,41 @@
#define FCX_FREE (FCX_FCXS_MASK | FCX_FCXO_MASK) /* Free CSA manipulation */

#define TRICORE_SRCNUM_PER_GPSR 8
#define TRICORE_SRC2IRQ(src_addr) \
(((uintptr_t)(src_addr) - (uintptr_t)&MODULE_SRC) / 4)
#define TRICORE_SRC_SPACING 4
#define TRICORE_SRC2IRQ(src) \
(((uintptr_t)(src) - TRICORE_SRC_BASEADDR) / TRICORE_SRC_SPACING)
#define TRICORE_IRQ2SRC(irq) \
(TRICORE_SRC_BASEADDR + (irq) * TRICORE_SRC_SPACING)
#define TRICORE_GPSR_IRQNUM(src_cpu, dest_cpu) \
TRICORE_SRC2IRQ(&SRC_GPSR00 + src_cpu * 8 + dest_cpu)
TRICORE_SRC2IRQ(TRICORE_SRC_GPSR0_SR0 + \
((src_cpu) * TRICORE_SRCNUM_PER_GPSR + (dest_cpu)) * \
TRICORE_SRC_SPACING)

#ifdef CONFIG_ARCH_IRQPRIO
# define TRICORE_SCHEDIRQ \
TRICORE_GPSR_IRQNUM(up_cpu_index(), up_cpu_index())
#endif

/* TriCore interrupt priority range, higher value means higher priority. */

#ifdef CONFIG_ARCH_HIPRI_INTERRUPT
#define TRICORE_IRQ_DISABLE_PRIORITY CONFIG_ARCH_IRQ_DISABLE_PRIORITY
#endif

#define TRICORE_IRQ_MIN_PRIORITY 1
#define TRICORE_IRQ_MAX_PRIORITY CONFIG_ARCH_IRQ_MAX_PRIORITY

/* ICR (Interrupt Control Register) bit definitions.
* [7:0] CCPN - Current CPU Priority Number
* [15] IE - Interrupt Enable (global)
* [23:16] PIPN - Previous Interrupt Priority Number
*/

#define ICR_CCPN_SHIFT 0
#define ICR_CCPN_MASK (0xffu << ICR_CCPN_SHIFT)
#define ICR_IE (1u << 15)
#define ICR_PIPN_SHIFT 16
#define ICR_PIPN_MASK (0xffu << ICR_PIPN_SHIFT)

/* For use with EABI and floating point, the stack must be aligned to 8-byte
* addresses.
Expand Down Expand Up @@ -185,14 +215,6 @@ struct xcptcontext
uintptr_t *regs;
};

/****************************************************************************
* Public Data
****************************************************************************/

/* g_interrupt_context store irq status */

extern volatile bool g_interrupt_context[CONFIG_SMP_NCPUS];

/****************************************************************************
* Public Function Prototypes
****************************************************************************/
Expand Down Expand Up @@ -236,51 +258,75 @@ noinstrument_function static inline_function uintptr_t up_getsp(void)
* Name: up_irq_save
*
* Description:
* Disable interrupts and return the previous value of the mstatus register
* Disable interrupts and return the previous interrupt state.
*
* When CONFIG_ARCH_HIPRI_INTERRUPT is enabled, this raises ICR.CCPN
* to TRICORE_IRQ_DISABLE_PRIORITY so that high-priority interrupts
* (SRPN > TRICORE_IRQ_DISABLE_PRIORITY) remain unmasked. up_irq_save
* only raises CCPN, up_irq_restore only lowers it. This prevents the
* masking level from being accidentally lowered.
*
* Otherwise, uses the hardware disable instruction (ICR.IE = 0)
* for minimal overhead.
*
****************************************************************************/

noinstrument_function static inline_function irqstate_t up_irq_save(void)
{
return __disable_and_save();
#ifdef CONFIG_ARCH_HIPRI_INTERRUPT
uint32_t icr = tricore_mfcr(CPU_ICR);
irqstate_t ccpn = (icr & ICR_CCPN_MASK) >> ICR_CCPN_SHIFT;

if (TRICORE_IRQ_DISABLE_PRIORITY > ccpn)
{
icr &= ~ICR_CCPN_MASK;
icr |= TRICORE_IRQ_DISABLE_PRIORITY << ICR_CCPN_SHIFT;
tricore_mtcr(CPU_ICR, icr);
UP_ISB();
}

return ccpn;
#else
irqstate_t flags;

__asm__ volatile ("disable %0" : "=d"(flags) :: "memory");
return flags;
#endif
}

/****************************************************************************
* Name: up_irq_restore
*
* Description:
* Restore the value of the mstatus register
* Restore the previous interrupt state saved by up_irq_save().
*
* When CONFIG_ARCH_HIPRI_INTERRUPT is enabled, restores ICR.CCPN.
* Otherwise, restores ICR.IE via the hardware restore instruction.
*
****************************************************************************/

noinstrument_function static inline_function
void up_irq_restore(irqstate_t flags)
{
__restore(flags);
#ifdef CONFIG_ARCH_HIPRI_INTERRUPT
uint32_t icr = tricore_mfcr(CPU_ICR);

if (flags < ((icr & ICR_CCPN_MASK) >> ICR_CCPN_SHIFT))
{
icr &= ~ICR_CCPN_MASK;
icr |= flags << ICR_CCPN_SHIFT;
tricore_mtcr(CPU_ICR, icr);
UP_ISB();
}
#else
__asm__ volatile ("restore %0" :: "d"(flags) : "memory");
#endif
}

/****************************************************************************
* Inline Functions
****************************************************************************/

/****************************************************************************
* Name: up_set_interrupt_context
*
* Description:
* Set the interrupt handler context.
*
****************************************************************************/

noinstrument_function
static inline_function void up_set_interrupt_context(bool flag)
{
#ifdef CONFIG_SMP
g_interrupt_context[up_this_cpu()] = flag;
#else
g_interrupt_context[0] = flag;
#endif
}

/****************************************************************************
* Name: up_interrupt_context
*
Expand All @@ -293,16 +339,7 @@ static inline_function void up_set_interrupt_context(bool flag)
noinstrument_function
static inline_function bool up_interrupt_context(void)
{
#ifdef CONFIG_SMP
irqstate_t flags = up_irq_save();
bool ret = g_interrupt_context[up_this_cpu()];

up_irq_restore(flags);

return ret;
#else
return g_interrupt_context[0];
#endif
return (tricore_mfcr(CPU_PSW) & PSW_IS) != 0;
}

/****************************************************************************
Expand All @@ -313,6 +350,11 @@ static inline_function uintptr_t up_getusrsp(void *regs)
{
uintptr_t *csaregs = (uintptr_t *)regs;

if (csaregs == NULL)
{
return 0;
}

if (csaregs[REG_LPCXI] & PCXI_UL)
{
csaregs = tricore_csa2addr(csaregs[REG_LPCXI]);
Expand Down
44 changes: 44 additions & 0 deletions arch/tricore/include/tc3xx/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,50 @@
* Pre-processor Prototypes
****************************************************************************/

/* Service Request Control (SRC) register bit definitions.
*
* TC3xx layout:
* [7:0] SRPN - Service Request Priority Number
* [10] SRE - Service Request Enable
* [13:11] TOS - Type of Service (3-bit, CPU0-5/DMA)
* No VM / CS fields.
*
* Common bits (identical on both TC3xx/TC4xx):
* [24] SRR, [25] CLRR, [26] SETR, [27] IOV, [28] IOVCLR
*/

#define SRCR_SRPN_SHIFT 0
#define SRCR_SRPN_MASK (0xffu << SRCR_SRPN_SHIFT)
#define SRCR_VM_SHIFT 0
#define SRCR_VM_MASK 0
#define SRCR_CS 0
#define SRCR_TOS_SHIFT 11
#define SRCR_TOS_MASK (0x7u << SRCR_TOS_SHIFT)
#define SRCR_SRE (1u << 10)
#define SRCR_SRR (1u << 24)
#define SRCR_CLRR (1u << 25)
#define SRCR_SETR (1u << 26)
#define SRCR_IOV (1u << 27)
#define SRCR_IOVCLR (1u << 28)

/* Service Request Control (SRC) */

#define TRICORE_SRC_BASEADDR 0xf0038000
#define TRICORE_SRC_GPSR0_SR0 0xf0038990
#define TRICORE_INT_SRB0_ADDR 0xf0037010
#define TRICORE_INT_LASR0_ADDR 0xf0037204
#define TRICORE_INT_LASR_SPACING 0x10

/* Type of Service (TOS) */

#define TRICORE_TOS_CPU0 0 /* CPU0 */
#define TRICORE_TOS_DMA 1 /* DMA */
#define TRICORE_TOS_CPU1 2 /* CPU1 */
#define TRICORE_TOS_CPU2 3 /* CPU2 */
#define TRICORE_TOS_CPU3 4 /* CPU3 */
#define TRICORE_TOS_CPU4 5 /* CPU4 */
#define TRICORE_TOS_CPU5 6 /* CPU5 */

#define TRICORE_UART_RX_IRQ 21

/****************************************************************************
Expand Down
Loading
Loading