Skip to content

ast10x0: lock the SCU after use with a nesting-safe unlock_and_lock_after - #666

Open
EnmanuelParache wants to merge 2 commits into
OpenPRoT:mainfrom
EnmanuelParache:feat/scu_lock_after
Open

EnmanuelParache wants to merge 2 commits into
OpenPRoT:mainfrom
EnmanuelParache:feat/scu_lock_after

Conversation

@EnmanuelParache

@EnmanuelParache EnmanuelParache commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Replaces ScuRegisters::new_global_unlocked(), which left the SCU unlocked for the rest of runtime, with unlock_and_lock_after, which unlocks the SCU for the duration of a closure and re-locks it afterwards. Addresses #635.

Changes

  • ScuRegisters::unlock_and_lock_after(|scu| ...) replaces new_global_unlocked() and the inline unlock_write_protection() calls. unlock_write_protection is now private, so callers can't leave the SCU unlocked.
  • Nesting-safe. A depth counter means only the outermost call unlocks and re-locks. Without it, an inner call (for example set_spim_internal_mux inside the SPI transaction setup) locked the SCU under the enclosing closure and later writes were silently dropped.
  • SCU setters take the lock themselves: gate_clock_mask, ungate_clock_mask, assert_reset_mask, deassert_reset_mask, apply_pinctrl_group and dcache_invd_all. Callers no longer need to remember to unlock first. These writes would otherwise silently fail now that the SCU is re-locked.
  • Raw PAC writes moved onto ScuRegisters: the I3C per-bus reset and clock writes (i3c/registers.rs) and the SGPIOM pin enable in board/src/spim_wiring.rs. The I3C ones were found by hardware testing (see below).
  • pre_init re-locks the SCU after init_cache, so the SCU is no longer left unlocked from boot until the first later user. This closes the part of SCU left unlocked #635 that the first revision missed.
  • HACE holds the SCU unlocked only for its clock and reset writes, not for the engine drain loop.
  • Rebased on current main. tests/flash and tests/flash_service, added on main, were moved from new_global_unlocked() to new_global().
  • Fixed the unlock_and_lock_after documentation and example, and the stale "call unlock_write_protection()" comments in clock.rs and reset.rs.

Testing

  • ./pw presubmit: clippy, format, lockfile check and presubmit checks all pass.
  • AST1060 EVB (AST1060_EVB_PI_HOST=amd@rot-ast-ctrl, --config=k_ast1060_evb): 25 of 25 hardware tests pass with the test cache disabled, covering flash, GPIO, SGPIOM, HACE, I2C, I3C, OTP, SMC and SPI monitor.
  • Hardware testing found a regression in the first revision: i3c/i3c_irq timed out, because the I3C driver writes SCU reset and clock registers directly through the PAC and relied on the SCU staying unlocked. It passed on the pre-PR commit and passes again with the fix.
  • Not run: mctp/server, spdm/auth (both timeout = "eternal" and manual), spdm/vca (manual), and gpioj_loopback (manual, needs jumper wires).

Not covered

  • peripherals/i2c/slave.rs writes SCUA54 and SCUA58 directly through the PAC. The I2C slave tests pass, so I left it alone, but it bypasses ScuRegisters and should be checked.
  • Re-locking the SCU is not a strong control by itself: the unlock key is a public constant, and mapping the SCU only to the processes that need it remains the real boundary (see SCU left unlocked #635).

🤖 Generated with Claude Code

@EnmanuelParache
EnmanuelParache marked this pull request as ready for review November 5, 2026 18:43
@rusty1968
rusty1968 requested a review from yvettewu1 November 5, 2026 18:45
@EnmanuelParache EnmanuelParache self-assigned this Nov 10, 2026
@EnmanuelParache
EnmanuelParache force-pushed the feat/scu_lock_after branch 3 times, most recently from f04153b to 5a8e17e Compare November 12, 2026 03:10
EnmanuelParache and others added 2 commits November 18, 2026 14:02
unlock_and_lock_after now tracks a nesting depth so only the outermost
call unlocks and re-locks the SCU. An inner call no longer re-locks the
SCU under an enclosing closure.

Now that the SCU is re-locked, writes that relied on it staying
unlocked would be silently dropped, so:
- gate/ungate_clock_mask, assert/deassert_reset_mask,
  apply_pinctrl_group and dcache_invd_all take the lock themselves.
- The I3C reset/clock writes and the SGPIOM pin enable in spim_wiring
  go through ScuRegisters instead of raw PAC writes.
- HACE only holds the SCU unlocked for its clock and reset writes.
- pre_init re-locks the SCU after init_cache.

Fix the unlock_and_lock_after documentation and the stale "call
unlock_write_protection()" comments.

Validated on the AST1060 EVB: 25/25 non-manual hardware tests pass (rebased on main).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@EnmanuelParache EnmanuelParache changed the title unlock_and_lock_after to ensure scu is locked after a procedure that … ast10x0: lock the SCU after use with a nesting-safe unlock_and_lock_after Nov 18, 2026

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant