hujun260 opened a new pull request, #22096:
URL: https://github.com/apache/nuttx/pull/22096
# arch/arm64: gicv2: implement `up_trigger_irq`
## Summary
Replace the GICv2-private `arm_cpu_sgi()` and `arm64_gic_raise_sgi()` helpers
with the generic `up_trigger_irq()` entry point that the other architectures
already expose. GICv2 and GICv3 back ends then present the same interface, so
`arm64_smpcall.c` no longer needs a GIC-version-specific call.
```diff
int up_send_smp_sched(int cpu)
{
/* Execute SGI2 */
- arm64_gic_raise_sgi(GIC_SMP_SCHED, (1 << cpu));
+ up_trigger_irq(GIC_SMP_SCHED, (1 << cpu));
return OK;
}
```
## Change
Three things happen in `arm64_gicv2.c`:
1. `arm_cpu_sgi()` is removed and its body folded into `up_trigger_irq()`.
2. The old `up_trigger_irq()` (which handled both SGIs and ordinary IRQs) is
removed from its previous location; the new one is placed next to
`arm64_gic_secondary_init()` at the bottom of the SMP section.
3. `arm64_gic_raise_sgi()` is removed in favour of the new function.
Net effect is −95/+43 lines in `arm64_gicv2.c` plus a one-line change in
`arm64_smpcall.c`.
## Two problems found and fixed
The commit as originally written does not compile, and drops a code path.
Both
are addressed here.
### 1. Conflicting declaration of `up_trigger_irq`
`include/nuttx/arch.h` declares the prototype, guarded by
`CONFIG_ARCH_HAVE_IRQTRIGGER`:
```c
#ifdef CONFIG_ARCH_HAVE_IRQTRIGGER
void up_trigger_irq(int irq, cpu_set_t cpuset);
#endif
```
where `cpu_set_t` is `volatile uint32_t` (`include/sys/types.h:278`). The new
definition used `uint16_t` instead, which is a hard error, not a warning:
```text
$ tools/configure.sh -a ../apps raspberrypi-4b:smp
$ make -j$(nproc)
CC: misc/reboot_notifier.c common/arm64_gicv2.c:1365:6: error: conflicting
types for 'up_trigger_irq'; have 'void(int, uint16_t)'
{aka 'void(int, short unsigned int)'}
1365 | void up_trigger_irq(int irq, uint16_t cpuset)
| ^~~~~~~~~~~~~~
In file included from common/arm64_gicv2.c:43:
include/nuttx/arch.h:1919:6: note: previous declaration of 'up_trigger_irq'
with type 'void(int, volatile cpu_set_t)' {aka 'void(int, volatile
unsigned int)'}
```
This only shows up when `CONFIG_SMP=y`, because the definition sits inside
the
`#ifdef CONFIG_SMP` block. Non-SMP builds of the same board compile fine,
which
is presumably why it was not caught. Fixed by using `cpu_set_t`:
```diff
-void up_trigger_irq(int irq, uint16_t cpuset)
+void up_trigger_irq(int irq, cpu_set_t cpuset)
```
GICv3 already uses `cpu_set_t` for the same function, so this also makes the
two
back ends consistent.
### 2. Ordinary (non-SGI) interrupts were dropped
The function being replaced handled both cases:
```c
void up_trigger_irq(int irq, cpu_set_t cpuset)
{
if (irq >= 0 && irq <= GIC_IRQ_SGI15)
{
arm_cpu_sgi(irq, cpuset);
}
else if (irq >= 0 && irq < NR_IRQS)
{
regaddr = GIC_ICDISPR(irq);
putreg32(GIC_ICDISPR_INT(irq), regaddr);
}
}
```
The new version only kept the SGI branch, so a caller passing a peripheral
IRQ
would have silently done nothing. Restored, matching what `arm64_gicv3.c`
does
for the same case:
```c
else if (irq >= 0 && irq < NR_IRQS)
{
/* Write '1' to the corresponding bit in the distributor Interrupt
* Set-Pending (ICDISPR)
*/
putreg32(GIC_ICDISPR_INT(irq), GIC_ICDISPR(irq));
}
```
## Verification
### Build
| Configuration | GIC | SMP | Before fix | After fix |
| --- | --- | --- | --- | --- |
| `raspberrypi-4b:smp` | v2 | yes | **FAIL** (conflicting types) | PASS |
| `raspberrypi-4b:nsh` | v2 | no | PASS | PASS |
| `qemu-armv8a:nsh_smp` | v3 | yes | PASS | PASS |
```text
$ tools/configure.sh -a ../apps raspberrypi-4b:smp
$ make -j$(nproc)
...
LD: nuttx
CP: nuttx.hex
CP: nuttx.bin
Generating config.txt
```
The GICv3 configuration is included because `arm64_smpcall.c` is shared: both
`up_send_smp_sched()` and `up_send_smp_call()` now call `up_trigger_irq()`,
so a
regression there would hit the GICv3 path too.
### Runtime
The GICv3 SMP build was booted as a regression check for the shared
`arm64_smpcall.c` path:
```text
$ qemu-system-aarch64 -cpu cortex-a53 -smp 2 -nographic \
-machine virt,virtualization=on,gic-version=3 \
-net none -chardev stdio,id=con,mux=on \
-serial chardev:con -monitor none -kernel nuttx
```
```text
- Ready to Boot Primary CPU
- Boot from EL2
- Boot from EL1
- Boot to C runtime for OS Initialize
- Ready to Boot Second CPU
- Boot from EL2
- Boot from EL1
- Boot to C runtime for OS Initialize
nsh> uname -a
NuttX 13.1.1-RC0 3954b442c39-dirty Nov 20 2026 11:34:25 arm64 qemu-armv8a
nsh> ps
TID PID PPID CPU PRI POLICY TYPE NPX STATE EVENT SIGMASK
STACK USED FILLED COMMAND
0 0 0 0 0 FIFO Kthread - Assigned
0000000000000000 0016336 0001872 11.4% CPU0 IDLE
1 0 0 1 0 FIFO Kthread - Running
0000000000000000 0016336 0000992 6.0% CPU1 IDLE
2 0 0 --- 192 RR Kthread - Waiting Semaphore
0000000000000000 0016272 0001184 7.2% hpwork 0x4046dba0 0x4046dc28
4 4 0 --- 100 RR Task - Waiting Semaphore
0000000000000000 0016304 0002032 12.4% init_main
5 5 4 0 100 RR Task - Running
0000000000000000 0016304 0003216 19.7% sh
```
Both cores come up and the scheduler IPI path works, which is the code that
`up_trigger_irq()` is reached from.
### checkpatch
```text
$ tools/checkpatch.sh -c -u -m -g ff4d9b2ec67..HEAD
Used config files:
1: .codespellrc
✔️ All checks pass.
```
## Honest notes
- **No GICv2 runtime verification.** There is no BCM2711 model in QEMU and no
Raspberry Pi 4 available here, so `raspberrypi-4b:smp` is build-verified
only.
The runtime log above exercises the *GICv3* path, which shares
`arm64_smpcall.c` but not `arm64_gicv2.c`. The GICv2 `putreg32()` sequences
themselves were not executed.
- **`up_trigger_irq()` only exists when `CONFIG_SMP=y`.** It is defined
inside
the `#ifdef CONFIG_SMP` block in `arm64_gicv2.c`, while the declaration in
`arch.h` is gated on `CONFIG_ARCH_HAVE_IRQTRIGGER`. Those two conditions
are
not equivalent: BCM2711 and Goldfish `select ARCH_HAVE_IRQTRIGGER`
unconditionally, and Goldfish also selects `ARCH_HAVE_MULTICPU`, so
`IRQTRIGGER=y` with `SMP=n` is reachable. It does not break today only
because the sole in-tree caller, `drivers/rptun/rptun_bmp.c`, additionally
requires `CONFIG_RPTUN`. The non-SMP `raspberrypi-4b:nsh` build above
passes
for that reason. If `CONFIG_RPTUN` ever becomes selectable in a non-SMP
arm64
build, this becomes a link error. Moving the definition out of the
`CONFIG_SMP` block would be the safer arrangement and is left as a
follow-up
because it changes more than this commit does.
- **`arm64_gic_raise_sgi()` is kept.** It is still declared in `arm64_gic.h`
and
used by `arm64_gicv3.c`, so only the GICv2 definition was removed. The
declaration stays in the shared header.
- **Commit message rewritten.** The original subject had a doubled space
(`arch/arm64: gicv2`) and its body merely repeated the subject. It now
describes what the change actually does.
--
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]