Skip to content

arch/tricore: drop iLLD dependence for irq - #21309

Closed
zhangyu981027 wants to merge 23 commits into
apache:masterfrom
zhangyu981027:tricore_irq_pr4
Closed

zhangyu981027 wants to merge 23 commits into
apache:masterfrom
zhangyu981027:tricore_irq_pr4

Conversation

@zhangyu981027

@zhangyu981027 zhangyu981027 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Note: Please adhere to Contributing Guidelines.

Summary

Drop the iLLD dependence of the TriCore irq and core register code:

  • add the full 255-entry BIV interrupt vector table; each entry is a 32-byte aligned code slot that saves context and jumps to the handler, SRPN 1 routes to taskswitch and SRPN 2~255 to the fast direct path
  • define the core SFRs (PCXI/PSW/PC/SYSCON/CORE_ID/ICR/PPRS/FCX/LCX, CCTRL/CCNT), trap status registers and MPU registers in NuttX headers instead of the iLLD IfxCpu_* headers; tricore_systimer.c uses CONFIG_CPU_CLOCK_FREQUENCY instead of its local IFX_CFG_CPU_CLOCK_FREQUENCY
  • access the SRC and INT registers directly instead of IfxSrc/IfxCpu/IfxInt: add the SRC bit layout (different between TC3xx and TC4xx) and INT LASR base addresses to tc3xx/tc4xx irq.h, add tricore_src_init(), and use the disable/restore/enable instructions directly

Code that still talks to iLLD drivers directly (tricore_main.c, tricore_systimer.c, chip serial) includes the iLLD headers itself. This also removes the IFX_CFG_CPU_CLOCK_FREQUENCY redefinition warning in the cmake build.

Dependency

Depends on #21308. This branch is stacked on top of it, so it also contains the commits of the dependent PR(s); only the last 3 commit(s) belong to this PR:

  • arch/tricore: fully implement 255 interrupt tables
  • arch/tricore: drop the last illd headers and define registers ourselves
  • arch/tricore: drop illd dependence for irq

Impact

TriCore architecture only (arch/tricore). No functional change intended; the irq path no longer depends on iLLD. No impact on other architectures.

Testing

Built triboard_tc4x9_com:nsh (TC4xx, cmake) and a2g-tc397-5v-tft:nsh (TC3xx, both make and cmake) with tricore-elf-gcc on Ubuntu host. Each commit passes checkpatch and builds on its own.

Tested on both TC4xx (TC4x9) and TC3xx (TC397) boards: system boots normally and ostest passes.

nsh> uname -a
NuttX 13.1.0 eb4b5fd60ba Oct 31 2026 21:35:02 tricore triboard_tc4x9_com
nsh> ostest
...
ostest_main: Exiting with status 0

@github-actions github-actions Bot added Area: Build system Arch: tricore Issues related to the TriCore architecture from Infineon Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. Board: tricore labels Oct 31, 2026
@zhangyu981027
zhangyu981027 marked this pull request as draft October 31, 2026 14:10
@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

zhangyu981027 and others added 14 commits November 2, 2026 14:04
When a svcall trap is taken, the trap entry has already saved the
context into CSAs, and then the svcall handler is executed by 'call',
which allocates one more CSA that is not needed.

Use 'ji' to jump to the svcall handler instead, so one CSA is saved
for each svcall.

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
The current trapcall function comes in through the jump instruction, so
the return method needs to be modified.

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
Add tricore_bustrap_register_hook() so that safety test modules can
intercept expected bus errors during self-tests. If the registered
hook handles the trap, tricore_bustrap returns normally instead of
triggering a system panic.

Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
Implement the BTV trap vector table in tricore_vectors.c and remove
the dependency on the iLLD IfxCpu_Trap.c and Ifx_Cfg_Trap.h.

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
An FCU (Free Context list Underflow) trap occurs when FCX=0 and the
software attempts to save context (e.g., via svlcx). Without a dedicated
recovery pool, the trap handler itself cannot allocate a CSA to save
context, causing a fatal loop on svlcx and preventing the panic/assert
path from running. tricore_fcu_register_pool() provides an external CSA
pool that the FCU trap handler uses to break out of this predicament.

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
Extract tricore_trap_alert() to deduplicate the _alert boilerplate
that was inlined into each of the 7 trap handlers. Convert if-else
dispatch to switch, inline tricore_trapinfo(), and gate diagnostic
strings under CONFIG_DEBUG_TRAP_ALERT so they can be compiled out for
release builds.

tricore_trapcall.o size comparison:
before                    text=2166  rodata=1634
now + DEBUG_TRAP_ALERT=y  text=968   rodata=1396
now + DEBUG_TRAP_ALERT=n  text=608   rodata=107

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
Route the irq to the cpu that enables it instead of always cpu0,
use per-cpu GPSR for irq trigger, and support up_affinity_irq.

Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
Signed-off-by: zhangyuan29 <zhangyuan29@xiaomi.com>
tc3xx core2~core5 tos is 2~5, change to get the right tos value.

Signed-off-by: zhangyuan29 <zhangyuan29@xiaomi.com>
for tc3xx cpu0~cpu5 tos is 0,2~6, is not right to
use tos0 + cpuidx to get the tos number.

Signed-off-by: zhangyuan29 <zhangyuan29@xiaomi.com>
Use PSW.IS instead of g_interrupt_context to determine interrupt
context. This method relies on independent interrupt stack; otherwise
psw.is = 1 in thread context, which cannot distinguish between threads
and interrupts.

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
The trap handler is already in interrupt context, so it should not
use up_interrupt_context().

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
Replace global interrupt disable (ICR.IE) with ICR.CCPN threshold
masking when CONFIG_ARCH_HIPRI_INTERRUPT is enabled, similar to ARM
BASEPRI. High-priority interrupts above the threshold remain unmasked.
This prepares for the later CONFIG_ARCH_HIPRI_INTERRUPT support.

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
Decouple interrupt priority (SRPN) from the IRQ index used by
up_irq_to_ndx. Add a per-CPU SRPN-to-IRQ mapping table so that SRPN can
be independently allocated and reassigned without affecting the IRQ
numbering scheme.

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
Add tricore_register_irq_srpn() to register SRPN-to-IRQ mappings for
SRC interrupts configured externally by MCAL (e.g., IrqDma_Init or
IrqAsclin_Init). The function reads SRPN directly from the SRC
register and records it in the NuttX dispatch table.

Signed-off-by: yangsong8 <yangsong8@xiaomi.com>
zhangyu981027 and others added 9 commits November 2, 2026 14:16
Reason for revert: the mapping from IRQ to NDX should only be a logical
relationship; Tricore directly treated Prio as NDX, which led to the
existence of this interface.

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
g_irqrevmap and the TriCore g_srpn_to_irq table both store IRQ numbers
but were declared as int[], wasting memory since these tables are
replicated per-CPU under BMP. Change their element type to irq_t, sized
to hold the largest IRQ number, shrinking each entry with no truncation
risk.

Co-authored-by: Claude <claude@anthropic.com>
Signed-off-by: zhangyuan29 <zhangyuan29@xiaomi.com>
Split the single interrupt entry (tricore_doirq) into two paths:
tricore_irq_direct: fast dispatch with re-enable for nesting,
triggers a low-priority GPSR if context switch is needed.

tricore_irq_taskswitch: deferred context switch handler at the
lowest SRPN, runs only after all nested interrupts complete.

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
When CONFIG_ARCH_IRQPRIO is disabled, all IRQs go through
tricore_irq_sched, which does ack, dispatch and context switch.
No interrupt nesting and no scheduling GPSR are used.

When CONFIG_ARCH_IRQPRIO is enabled, keep the two paths: SRPN 1 for
the scheduling GPSR and SRPN 2~255 for the nestable direct path.

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
The fast irq path (like CONFIG_ARCH_HIPRI_INTERRUPT) does not save
regs in irq, similar to arm's pendsv, so xcp.regs may be NULL.
TriCore cannot access the NULL address, so check regs before use.

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
Read the irq number from the ICU LASR register of the current core
instead of translating the SRPN through g_srpn_to_irq. LASR must be
read before interrupts are re-enabled.

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
Add the full BIV interrupt vector table. Unlike ARM/RISC-V which store
function pointers, TriCore's vector table contains executable code
directly, each entry is a 32 byte aligned slot that saves context and
jumps to the handler. SRPN 1 routes to taskswitch, SRPN 2 to 255 route
to the fast direct dispatch path.

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
tricore_internal.h no longer includes IfxCpu_Intrinsics.h, IfxCpu_reg.h
and the illd compiler headers.  The core special function
registers used by the arch code (PCXI/PSW/PC/SYSCON/CORE_ID/ICR/PPRS/
FCX/LCX, CCTRL/CCNT) are now defined in arch/arch.h, the trap status
registers (PSTR/DSTR/DATR/DEADD) are defined in tricore_vectors.h, and
the MPU protection range and enable registers (DPRn/CPRn, DPRE/DPWE/
CPXE) are defined in tricore_mpu.c.  The SRC/GPSR/SRB base addresses
and TOS values are defined in tc3xx/tc4xx irq.h.

Code that still talks to illd drivers directly (tricore_main.c,
tricore_systimer.c, chip serial) includes the illd headers itself.

tricore_systimer.c also drops its local IFX_CFG_CPU_CLOCK_FREQUENCY
definition and uses CONFIG_CPU_CLOCK_FREQUENCY for the minimum delay.

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
Access the SRC (Service Request Control) and INT registers directly
instead of going through IfxSrc/IfxCpu/IfxInt:

- tc3xx/tc4xx irq.h: add the SRC register bit layout (it differs between
  TC3xx and TC4xx) and the INT LASR base addresses.
- irq.h: drop IfxCpu_Intrinsics.h and IfxCpu_reg.h, add the ICR.CCPN
  field definitions, and use the "disable"/"restore" instructions
  directly in up_irq_save()/up_irq_restore().
- tricore_irq.c: add tricore_src_init() replacing IfxSrc_init(), and
  replace the remaining IfxSrc/IfxCpu calls with register accesses and
  the "enable" instruction.
- tc4xx CMakeLists.txt/Make.defs: drop the SRC_GPSR00 and SRC_CPU_CPU0_SB
  aliases that are no longer used.

Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
@parthitce

Copy link
Copy Markdown
Contributor

Likwie here, did we not agreed to wait for the cleanup #19041 and iLLD removal is duplicated effort?

@xiaoxiang781216

Copy link
Copy Markdown
Contributor

Likwie here, did we not agreed to wait for the cleanup #19041 and iLLD removal is duplicated effort?

this patch is changed to the draft state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: tricore Issues related to the TriCore architecture from Infineon Area: OS Components OS Components issues Board: tricore Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants