Skip to content

arch/rp23xx: Fix six register/bit macro name clashes - #19535

Merged
acassis merged 1 commit into
apache:masterfrom
casaroli:rp23xx-powman-macro-clash
Jul 27, 2026
Merged

arch/rp23xx: Fix six register/bit macro name clashes#19535
acassis merged 1 commit into
apache:masterfrom
casaroli:rp23xx-powman-macro-clash

Conversation

@casaroli

@casaroli casaroli commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Summary

The rp23xx hardware headers define a register address macro for every register,
then a block of register bit definitions. In three headers a bit definition
reuses the name of a register address macro, so that register address is
silently redefined as a bit mask:

Macro Intended (register address) Redefined to
RP23XX_POWMAN_BADPASSWD 0x40100000 (1 << 0)
RP23XX_POWMAN_BOD_CTRL 0x40100018 (1 << 12)
RP23XX_POWMAN_DBG_PWRCFG 0x401000a4 (1 << 0)
RP23XX_BUSCTRL_BUS_PRIORITY_ACK 0x40068004 (1 << 0)
RP23XX_BUSCTRL_PERFCTR_EN 0x40068008 (1 << 0)
RP23XX_PADS_QSPI_VOLTAGE_SELECT 0x40040000 (1 << 0)

None of these headers has an in-tree consumer yet, which is why this has gone
unnoticed; each clash surfaces as a "..." redefined warning the moment a
driver includes the header. Code that included one of them and used the
register by name would dereference 1 or 0x1000 rather than the register.

Changes

Two of the POWMAN clashes were plain duplicates. Per the RP2350 datasheet
BOD_CTRL bit 12 is ISOLATE and DBG_PWRCFG bit 0 is IGNORE, and
RP23XX_POWMAN_BOD_CTRL_ISOLATE / RP23XX_POWMAN_DBG_PWRCFG_IGNORE were
already defined with those exact values on the immediately following lines. The
bare names are therefore removed, with no loss of information.

While removing the BOD_CTRL line, the blank line separating the
VREG_LP_EXIT group from the BOD_CTRL group is restored — its absence is
what allowed the duplicate to hide inside the preceding group.

The other four are single-field registers whose field carries no separate
name; the datasheet and the SDK describe each as a one-bit register (the SDK
exposes only the register-level _BITS, 0x1). Their bit definitions are
renamed to <REGISTER>_MASK, matching the _MASK spelling these headers
already use for a field extent, and written in hex like their peers.

The rp23xx-rv copies of all three headers are byte-identical to the arm
ones apart from the include guard and carry the same clashes, so they receive
the same change. All three pairs are verified to remain in sync.

Impact

No functional change: none of the six names has a single user anywhere in the
tree, so nothing can change behaviour. This is a latent-bug and warning fix.

Testing

  • Verified with grep that none of the six macro names is referenced anywhere
    in the tree outside the headers themselves, so the renames and the two
    removals cannot break any caller.
  • Confirmed against the Pico SDK register headers (rp2350/hardware_regs) that
    BOD_CTRL bit 12 is ISOLATE, DBG_PWRCFG bit 0 is IGNORE, and that
    BADPASSWD, BUS_PRIORITY_ACK, PERFCTR_EN and VOLTAGE_SELECT are each a
    one-bit register with no separately named field.
  • Mechanically verified that no duplicate #define name remains in any of the
    six files, and that each arm/risc-v pair is still identical apart from its
    include guard.
  • Before/after build. Since none of these headers is compiled today, they
    were temporarily included from an always-built translation unit and
    raspberrypi-pico-2:nsh built both ways:
    • with master's headers: 6 redefined warnings, exactly the six above;
    • with this patch: 0 warnings, image links.
      The temporary include was then reverted and is not part of this PR.
  • Independently, raspberrypi-pico-2:nsh was built with a real POWMAN consumer
    (the RTC driver in arch/arm/rp23xx: Add RTC using the POWMAN always-on timer #19526): the three POWMAN warnings before, clean after,
    with the driver still linking.
  • tools/checkpatch.sh -g clean.

Note for reviewers

Two further duplicate definitions exist in these headers but are deliberately
left alone, as they are harmless rather than bugs — both redefine a name to the
identical token sequence, which is legal C and raises no warning:

  • RP23XX_OTP_BASE in rp23xx_memorymap.h (both arches), same value twice
  • RP23XX_DMA_SECCFG_MISC_TIMER3_S in rp23xx_dma.h (both arches), same value
    twice, differing only in a trailing comment

They are redundant lines rather than shadowed registers. Happy to remove them
too if reviewers would like this PR to leave the headers entirely
duplicate-free.

(RP23XX_IDLESTACK_BASE in the risc-v rp23xx_memorymap.h also appears twice,
but correctly so — the two definitions are in mutually exclusive
#ifndef __ASSEMBLY__ / #else branches.)

@github-actions github-actions Bot added Arch: arm Issues related to ARM (32-bit) architecture Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Size: XS The size of the change in this PR is very small labels Jul 25, 2026
The rp23xx hardware headers define a register address macro for every
register, then a block of register bit definitions.  In three headers a bit
definition reuses the name of a register address macro, so the register
address is silently redefined as a bit mask:

  RP23XX_POWMAN_BADPASSWD           address 0x40100000 -> (1 << 0)
  RP23XX_POWMAN_BOD_CTRL            address 0x40100018 -> (1 << 12)
  RP23XX_POWMAN_DBG_PWRCFG          address 0x401000a4 -> (1 << 0)
  RP23XX_BUSCTRL_BUS_PRIORITY_ACK   address 0x40068004 -> (1 << 0)
  RP23XX_BUSCTRL_PERFCTR_EN         address 0x40068008 -> (1 << 0)
  RP23XX_PADS_QSPI_VOLTAGE_SELECT   address 0x40040000 -> (1 << 0)

None of these headers has an in-tree user yet, which is why this has gone
unnoticed; each clash appears as a "macro redefined" warning as soon as a
driver includes the header.  Code that included one of them and used the
register by name would have dereferenced 1 or 0x1000 instead of the register.

Two of the POWMAN clashes were plain duplicates.  Per the RP2350 datasheet
BOD_CTRL bit 12 is ISOLATE and DBG_PWRCFG bit 0 is IGNORE, and the correctly
named RP23XX_POWMAN_BOD_CTRL_ISOLATE and RP23XX_POWMAN_DBG_PWRCFG_IGNORE were
already defined with the same values on the following lines, so the bare names
are simply removed.  The blank line separating the VREG_LP_EXIT and BOD_CTRL
groups is restored at the same time; its absence is what let the duplicate
hide inside the preceding group.

The other four are single field registers whose field carries no separate name
(the datasheet and the SDK describe each as a one bit register), so their bit
definitions are renamed to <REGISTER>_MASK, following the _MASK spelling these
headers already use for a field extent, and written in hex like their peers.

The rp23xx-rv copies of the three headers are identical to the arm ones and
carry the same clashes, so they get the same change and stay in sync.

No functional change: none of the six names has any user in the tree.

Assisted-by: Claude Code:claude-opus-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
@github-actions

github-actions Bot commented Jul 25, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

@casaroli
casaroli force-pushed the rp23xx-powman-macro-clash branch from 0fbef7b to 9a6e708 Compare July 25, 2026 14:22
@github-actions github-actions Bot added Size: S The size of the change in this PR is small and removed Size: XS The size of the change in this PR is very small labels Jul 25, 2026
@casaroli casaroli changed the title arch/rp23xx: Fix three POWMAN register/bit macro name clashes arch/rp23xx: Fix six register/bit macro name clashes Jul 25, 2026
@casaroli casaroli closed this Jul 25, 2026
@casaroli casaroli reopened this Jul 25, 2026
@casaroli

Copy link
Copy Markdown
Contributor Author

The failing sim:alsa CI job is unrelated to this PR's RP23xx register-macro changes.

The Linux (sim-01) log fails while linking the bundled LAME encoder, with unresolved x86 runtime-dispatch vector symbols including quantize_lines_xrpow_avx2, quantize_lines_xrpow_sse2, and count_bit_esc_sse2. This is the same pre-existing CMake source-integration issue seen by other PRs: the LAME CMake target omits the vector translation units enabled by its generated configuration.

The fixes are tracked separately:

The two fixes were validated together with the CI-equivalent sim:alsa CMake/Ninja build. The Apps PR should merge first; subsequent NuttX PR CI runs will then use the corrected Apps master.

@casaroli casaroli closed this Jul 26, 2026
@casaroli casaroli reopened this Jul 26, 2026
@acassis
acassis merged commit 11d1965 into apache:master Jul 27, 2026
120 of 159 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: arm Issues related to ARM (32-bit) architecture Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants