hujun260 opened a new pull request, #21622:
URL: https://github.com/apache/nuttx/pull/21622
# NuttX PR Description
## Title
arm64: Fix secure-world timer interrupt routing
## Description
This PR updates ARM and ARM64 interrupt handling for systems running with a
secure-world TEE. It adds the required architectural register definitions,
removes inappropriate FIQ masking from ARM64 DAIF helpers, and delegates the
non-secure physical timer interrupt to the normal world during ARM32 secure
world initialization.
## Changes
1. **arm64/arch: Add ICC_ASGI1R and CNTP_CTL register definitions**
- Add the `ICC_ASGI1R` system register definition (`S3_0_C12_C11_6`) for
generating Group 1 Non-Secure SGIs from secure state.
- Add `CNTP_CTL_ENABLE_BIT` and `CNTP_CTL_IMASK_BIT` for the physical
timer
control register.
- Keep the physical timer definitions consistent with the existing
`CNTV_CTL_*` definitions.
2. **arm64/irq: Remove TRUSTZONE_SECURE FIQ masking from DAIF helpers**
- Remove the `CONFIG_ARCH_TRUSTZONE_SECURE` conditional branches in
`up_irq_save()` and `up_irq_enable()`.
- Always use `IRQ_DAIF_MASK` in the kernel IRQ helpers.
- Leave FIQ routing to the TEE at the EL3 level.
3. **arm/timer: Delegate the non-secure timer IRQ in secure world**
- During ARM32 timer initialization, call
`up_secure_irq(GIC_IRQ_PTM, false)` when running in secure state.
- Delegate the non-secure physical timer interrupt to the normal world.
- Perform the delegation on every CPU because PPI security groups are
configured per CPU.
## Motivation
Ensure that timer interrupts are routed correctly between the secure and
normal
worlds. This allows the normal-world NuttX kernel to receive its non-secure
physical timer interrupt while the TEE retains responsibility for
secure-world
FIQ routing.
## Testing
- [ ] Compile-tested
- [x] Runtime-tested on Vela QEMU ARM64
### QEMU runtime test
The changes were tested with the Vela QEMU ARM64 platform using the following
configuration:
- Board: `qemu-arm64-v8a-ap`
- CPU: Cortex-A53
- SMP: 4 CPUs
- Memory: 1057 MiB
- Shared memory: 4 MiB ivshmem region
- GDB server: TCP port `7775`
The boot log confirms that the secure monitor, BL32 TEE image, and
normal-world
NuttX image were loaded successfully:
```text
NOTICE: Booting Trusted Firmware
NOTICE: BL1: v2.14.0(debug):fb1381d84
INFO: BL2: Loading image id 4
INFO: BL2: Loading image id 5
INFO: Handoff to BL32
NOTICE: BL1: Booting BL31
INFO: NUTTXSPD: BL32 ep=0xe100000
INFO: NUTTXSPD: BL32 CPU0 entry done
INFO: NUTTXSPD: BL32 CPU1 entry done
INFO: NUTTXSPD: BL32 CPU2 entry done
INFO: NUTTXSPD: BL32 CPU3 entry done
INFO: Entry point address = 0x40280000
```
The normal-world kernel detected the ivshmem shared-memory region and
completed
device initialization:
```text
0.382308 8 I 0 ap pci_sdhci_probe: SDHCI controller at 10001000 irq=37
0.383143 8 I 0 ap pci_ivshmem_probe: shmem addr=0x8000400000 size=4194304
reg=0x10001100
0.393617 8 I 0 ap board_init_emmc: GPT partitions registered
NuttX 12.7.2 49d23ab02201-dirty Nov 10 2026 13:39:07 arm64 ap
```
The TEE initialization completed successfully, including timer, crypto, host
filesystem, key manager, and memory-object initialization:
```text
21 I 0 tee D/TC:0 21 call_initcalls:40 level 1 register_time_source()
21 I 0 tee D/TC:0 21 call_initcalls:40 level 3 tee_cryp_init()
21 I 0 tee D/TC:0 21 call_initcalls:40 level 4 host_fs_init()
21 I 0 tee D/TC:0 21 host_fs_init:141 perform host_fs_init action
21 I 0 tee D/TC:0 21 host_fs_init:162 host fs init success
21 I 0 tee D/TC:0 21 call_initcalls:40 level 4 tee_fs_init_key_manager()
21 I 0 tee D/TC:0 21 call_initcalls:40 level 6 default_mobj_init()
```
### AP-side `ostest`
The AP-side `ostest` completed successfully. The SMP call test passed and the
test process exited with status 0:
```text
qemu-armv8a-ap> ostest
...
user_main: smp call test
cpu_call_test: Test start
cpu_call_test: Call cpu 0, wait
cpu_call_test: Call cpu 1, wait
cpu_call_test: Call cpu 2, wait
cpu_call_test: Call cpu 3, wait
cpu_call_test: Call multi cpu, wait
cpu_call_test: Test success
user_main: Exiting
ostest_main: Exiting with status 0
```
### TEE-side `ostest`
The TEE-side `ostest` also completed successfully, including the SMP call
test:
```text
tee> ostest
...
user_main: smp call test
cpu_call_test: Test start
cpu_call_test: Call cpu 0, wait
cpu_call_test: Call cpu 1, wait
cpu_call_test: Call cpu 2, wait
cpu_call_test: Call cpu 3, wait
cpu_call_test: Call multi cpu, wait
cpu_call_test: Test success
user_main: Exiting
ostest_main: Exiting with status 0
```
The full QEMU console capture is available in the test log associated with
this
PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]