Skip to content

[ot] Merge hw/opentitan improvements - #337

Closed
siemen11 wants to merge 52 commits into
lowRISC:ot-10.2.0from
siemen11:merge-hw-opentitan
Closed

siemen11 wants to merge 52 commits into
lowRISC:ot-10.2.0from
siemen11:merge-hw-opentitan

Conversation

@siemen11

Copy link
Copy Markdown

Merge OpenTitan peripheral, board, debug/JTAG, and Ibex RVB (Xdraft093b) improvements from sasdf/qemu-ot:qemu-prototype, excluding core upstream QEMU TCG/TLB/memory/PLIC changes to preserve upstream sync maintainability.

sasdf and others added 3 commits October 30, 2026 14:38
Add top-level `BUILD.bazel` and `REPO.bazel` files so the QEMU repository
can be mounted directly as the `@qemu_opentitan` Bazel external repository,
exporting built artifacts (`build/qemu-system-riscv32*`, `build/qemu-img`)
and the `:qemu_src` / `:ot` filegroups consumed by OpenTitan's
`//third_party/qemu` package.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: Ib5d79f9b8776ec355bfab74d3d90d1796a6a6964
Earlgrey's Ibex core (RV32B = ibex_pkg::RV32BFull) implements RISC-V
Bitmanip draft v0.93 instructions (Zbf, Zbp, Zbr, Zbs, Zbt) alongside
ratified Zba/Zbb/Zbc/Zbs instructions.

Add the Xdraft093b decodetree specification (packu, bfp, xperm.h, grev,
grevi, gorc, gorci, shfl, shfli, unshfl, unshfli, slo, sloi, sro, sroi,
fsl, fsr, fsri, cmix, cmov), TCG translation routines in trans_rvb.c.inc,
runtime execution helpers in bitmanip_helper.c, and enable zbkb, zbkx,
and xdraft093b on the lowrisc-ibex CPU definition.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I09361f2def12ad7690c2400a9c975cdd6a6a6964
Align RISC-V performance monitoring counter CSRs with OpenTitan's Ibex
core implementation:

- Use icount_get_cycles() instead of icount_get() (nanoseconds) in
  riscv_pmu_ctr_get_fixed_counters_val() (target/riscv/csr.c) and
  riscv_pmu_cycle_update_priv() (target/riscv/pmu.c) so mcycle/mcycleh
  and privilege-mode cycle snapshots track elapsed CPU clock cycles
  rather than virtual nanoseconds in icount mode.
- Set .cfg.pmu_mask = MAKE_64BIT_MASK(3, 29) on
  TYPE_RISCV_CPU_LOWRISC_OPENTITAN (target/riscv/cpu.c) so all 29
  performance counters (mhpmcounter3..31, mhpmcounter3h..31h, and
  mhpmevent3..31) are accessible in M-mode and Debug Mode as in
  ibex_cs_registers.sv.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I53e76241fc59ff6e33c3fd08c848e3a96a6a6964

@sasdf sasdf left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks!

Context for future readers of this PR

Most of these changes were generated by AI. Because none of the QEMU-related code impacts production silicon, code reviews are conducted on a best-effort basis.

These patches have undergone extensive testing against the full OpenTitan test suite (using this fork, which enables all FPGA tests on QEMU as well). Software-observable behavior matches FPGA execution, and RTL bugs are intentionally replicated in QEMU to ensure exact fidelity.

The following approaches were used to generate and validate these changes between FPGA and QEMU:

  • Test result consistency across existing OpenTitan tests.
  • AI-generated consistency tests focused on edge and corner cases.
  • AI-generated consistency tests guided by QEMU model coverage.

Comment thread target/riscv/cpu.h Resolved
Comment thread target/riscv/csr.c Resolved
sasdf and others added 22 commits October 30, 2026 15:08
Align the RISC-V Debug Trigger Module, trigger context CSRs, and CPU
debug reset behavior with Earlgrey Ibex (`ibex_cs_registers.sv`):

1. In `tdata_csr_write()` (`target/riscv/debug.c`), preserve the current
   trigger type when a non-zero `tdata1` write specifies an unsupported
   type bit not present in `tinfo`, preventing arbitrary CSR writes (such
   as OpenOCD CSR test sweeps) from replacing Ibex's hardwired type-2
   address/data match trigger with `TRIGGER_TYPE_UNIMPL`.
2. In `riscv_trigger_reset_hold()` (`target/riscv/debug.c`), call
   `type2_breakpoint_remove(env, i)` instead of only zeroing the
   `cpu_breakpoint` / `cpu_watchpoint` pointers so active QEMU TCG
   breakpoints and watchpoints are unregistered on CPU reset.
3. In `riscv_csr_operations` (`target/riscv/csr.c`), wire `scontext`
   (`0x5a8`) and `mscontext` (`0x7aa`) under the `debug` (`ext_sdtrig`)
   predicate as `read_zero` / `write_ignore` CSRs.
4. In `riscv_cpu_reset_hold()` (`target/riscv/cpu.c`), clear
   `env->debugger`, `env->debug_cause`, `DCSR_STEP`, and
   `cs->singlestep_enabled` when the hart enters reset.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: Ied9537b848c8e733e38fd0701394980d6a6a6964
In Earlgrey's Ibex core (ibex_if_stage.sv), executing FENCE.I flushes the
instruction cache and invalidates the current ICache OTP scrambling key
(clearing CPUCTRLSTS.IC_SCR_KEY_VALID = 0) until a fresh key is received
from OTP.

Track FENCE.I execution via env->ic_scr_key_inval_cnt in trans_fence_i()
and report CPUCTRLSTS.IC_SCR_KEY_VALID = 0 on the first CSR read after
FENCE.I before restoring IC_SCR_KEY_VALID = 1 in read_cpuctrlsts().

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I5c6e93b44e1740fbab7887c02ba6d83f6a6a6964
Extend `OtOtpBeIfClass` in `include/hw/opentitan/ot_otp_be_if.h` with a
`set_lc_dft_en` callback so the OTP controller engine can forward the
lifecycle `lc_dft_en` broadcast signal to the OTP backend (`u_tlul_lc_gate`
on `prim_generic_otp` CSRs).

Also add `dis_rv_dm_late_debug_mb8` to `OtOTPHWCfg` in
`include/hw/opentitan/ot_otp_if.h` to expose the `HW_CFG0`
`DIS_RV_DM_LATE_DEBUG` multi-bit boolean to `pulp_rv_dm` for gating
`LATE_DEBUG_ENABLE` in the `DEV` lifecycle state.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I8a0af34ff378fb567e2045d33bdab8ab6a6a6964
Update `hw/opentitan/ot_ibex_wrapper.c`, `include/hw/opentitan/ot_ibex_wrapper.h`,
and `hw/riscv/ot_earlgrey.c` to match Earlgrey `rv_core_ibex` RTL:
- wire `OT_IBEX_WRAPPER_WDOG_BARK` from `aon_timer` and drive external
  (`riscv_cpu_set_rnmi`) and internal (`riscv_cpu_set_rnmi_int`) NMIs for
  watchdog bark, alert escalation, and load integrity errors;
- model the `RND_DATA` / `RND_STATUS` EDN request window so reading
  `RND_DATA` clears `RND_DATA_VALID` until the next EDN word arrives;
- pulse `SW_RECOV_ERR` / `ALERT_TEST` alerts and enforce 32-bit aligned
  TL-UL register access permissions via `ot_ibex_wrapper_regs_accepts`; and
- clear `remap` entries on reset.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: If3ad2cc7beee6f983886254b8589a9b46a6a6964
In `ot_shadow_reg_write()`, clear `sreg->staged_p = false` before
returning `OT_SHADOW_REG_ERROR` when the second write mismatches
`sreg->staged`. In `prim_subreg_shadow.sv`, an update error resets
`phase_q` back to `1'b0` so the next two-step write sequence starts
cleanly in Phase 1 instead of remaining stuck in Phase 2.

Also add `OT_MULTIBITBOOL32_{TRUE,FALSE,WIDTH,MASK}` constants matching
`prim_mubi_pkg::mubi32_t` (`0x96969696` / `0x69696969`).

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I6d1fbab418011784a35f7c6f1dc7e2a96a6a6964
Generalize `ot_common_get_local_cpu()` via `ot_common_get_local_object()`
to support looking up sibling QOM devices (such as `TYPE_OT_IBEX_WRAPPER`)
on the local hart hierarchy, and add two common bus/CPU fault helpers:
- `ot_common_stall_cpu_on_unclocked_mmio()`: clears the device MMIO
  reentrancy guard and invokes `riscv_cpu_stall_on_unclocked_mmio()`
  with the faulting physical address (`base + offset`).
- `ot_common_raise_load_integrity_error()`: locates the local
  `ot-ibex_wrapper` and raises an NMI/load integrity fault at
  `base + offset`.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I3b6fb565d3af246fd74a90d71e9afdc86a6a6964
Align OpenTitan's Ibex virtual address mapper (ot_vmapper) with RTL
address translation and execution-permission semantics:

- Order ranges with identical start addresses by slot priority in
  ot_vmapper_compare() and fix prefix/interior range splitting in
  ot_vmapper_range_discretize() so Slot 0 overrides or splits Slot 1.
- Detect sub-page (< 4 KiB or non-page-aligned offset) mappings via
  ot_vmapper_is_subpage() and set env->tlb_subpage in
  ot_vmapper_get_phy_addr() so sub-page NAPOT windows use sub-page TLB
  entries.
- Fill 1:1 default ranges before splitting no-exec regions in
  ot_vmapper_update(), fix range end-bound calculation in
  ot_vmapper_range_split_noexec(), and flush TLB/TB state synchronously
  when called from the vCPU thread.
- Allow translation windows reaching the 4 GiB boundary in
  ot_vmapper_translate() and pass boolean tree selectors to
  ot_vmapper_flush_tree() in ot_vmapper_reset_enter().

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I57cc5a07753a06aa8f71bd133c9fc42a6a6a6964
Add an `"enabled"` QOM property (default `true`) and a named GPIO input
(`TAP_CTRL_RBB_ENABLE` / `"enable"`) to `tap-ctrl-rbb`:
- When `enabled` is deasserted (`false`), reset the TAP state machine,
  ignore TCK/TMS/TDI steps in `tap_ctrl_rbb_step()`, and drive TDO high
  (`'1'`) on OpenOCD remote-bitbang read requests.
- Wire `OT_EG_SOC_DEV_TAP_CTRL` (`rv_dm` TAP) in `hw/riscv/ot_earlgrey.c`
  with `enabled = false` initially and connect its `TAP_CTRL_RBB_ENABLE`
  input to `OT_EG_SOC_SPLITTER_LC_HW_DEBUG` so the RISC-V JTAG TAP is
  only responsive when `lc_ctrl` asserts `LC_HW_DEBUG_EN`.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I257190a0fb818c64b358ca7656727c226a6a6964
Align the RISC-V Debug Module (`hw/riscv/dm.c`, `include/hw/riscv/dm.h`,
`include/hw/riscv/debug.h`) and JTAG Debug Transport Module
(`hw/riscv/dtm.c`) with OpenTitan Earlgrey (`rv_dm.sv`, `dm_csrs.sv`,
`dm_mem.sv`, `dm_sba.sv`, and `dmi_jtag.sv`):

1. Add `RISCV_DM_NDMRESET_LINE` (`"riscv-dm.ndmreset"`) and `in_ndmreset`
   tracking on `RISCVDebugDeviceState` so `dmcontrol.ndmreset` drives a
   level-sensitive non-debug system reset without wiping `RISCVDMState`
   or `RISCVDTMState` CSRs, setting `allhavereset` on reset exit and
   re-halting immediately if `haltreq` is held.
2. Update PULP debug ROM mailbox offsets (`RISCV_DM_GOING_OFFSET = 0x108`,
   `RISCV_DM_RESUMING_OFFSET = 0x110`, `RISCV_DM_EXCEPTION_OFFSET = 0x118`)
   to match `dm_mem.sv` 64-bit aligned slots.
3. Enforce `dm_sba.sv` System Bus Access (`sbcs`/`sbaddress0`/`sbdata0`)
   natural alignment checks (`SBERROR_ALIGNMENT`) and suppress auto-read
   when `sberror != 0`.
4. Execute DMI `read_rq`/`read_value` during JTAG `Update-DR` in
   `hw/riscv/dtm.c` and latch `(address, data, dmistat)` for the
   subsequent `Capture-DR` per RISC-V Debug Spec §6.1.5 and `dmi_jtag.sv`.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: Ib986b19d946170181a0f0b9f5b1e24d96a6a6964
Align the OpenTitan RV_DM (`pulp-rv-dm`) model and its Earlgrey SoC
`otp-ctrl` link (`hw/riscv/ot_earlgrey.c`) with `rv_dm.sv`, `dm_mem.sv`,
and `debug_rom.sv`:
- Update `PULP_RV_DM_RESUME_OFFSET` (`0x08`) and
  `PULP_RV_DM_EXCEPTION_OFFSET` (`0x10`), populate the exact
  `debug_rom.sv` (`0x800..0x89c`) and `DEFAULT_ABSTRACT_CMD`
  (`0x338..0x35c`) opcodes, and reject CPU writes to Debug ROM with
  `MEMTX_DECODE_ERROR` (`dm_mem.sv:400`).
- Implement `LATE_DEBUG_ENABLE_REGWEN` (`rw0c`) and `LATE_DEBUG_ENABLE`
  (`mubi32_t`) CSRs and `lc-hw-debug-en` / `lc-dft-en` GPIO inputs gated
  by OTP `CREATOR_SW_CFG_RV_DM_LATE_DEBUG_DIS` (`rv_dm.sv:238-243`), and
  wire `otp-ctrl` on `OT_EG_SOC_DEV_RV_DM` in `hw/riscv/ot_earlgrey.c`.
- Enforce `RV_DM_REGS_PERMIT` and `dm_mem.sv` (`FullRegMask`/`OneBitMask`)
  sub-word write faults and unmapped hole (`0x0c`, `0x000`, `0x104`,
  `0x304..0x337`, `0x388..0x3ff`) decode errors (`MEMTX_DECODE_ERROR`).
- Make `ALERT_TEST` (`0x00`) a transient 1-cycle pulse so consecutive
  writes of `1` each trigger `fatal_fault`.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I7c0773c9335088a937090b077eebf7f46a6a6964
Align the OpenTitan RV_PLIC extension device (hw/opentitan/ot_plic_ext.c)
with hw/ip/rv_plic/rtl/rv_plic.sv and rv_plic_reg_top.sv:

- Pulse the fatal_fault alert line (1 -> 0) on writes to ALERT_TEST
  instead of latching the alert output high, allowing alert_handler
  W1C acknowledgement.
- Add ot_plic_ext_accepts() to both the MSIP and ALERT_TEST MMIO
  regions to reject unaligned sub-word writes ((addr & 3) != 0),
  matching RV_PLIC_PERMIT = 4'b0001 in rv_plic_reg_pkg.sv.
- Clear s->msip_regs to 0 in ot_plic_ext_reset_enter() so MSIP0 resets
  cleanly across warm resets.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I0e9a2fb7cb3a58b1edd14aab8e08cb3c6a6a6964
Extend the QEMU `m25p80` SPI NOR flash device model (`hw/block/m25p80.c`,
`hw/block/m25p80_sfdp.c`, `hw/block/m25p80_sfdp.h`) to support OpenTitan
Earlgrey SPI flash PMOD and bootstrap tests:
- Add JEDEC SFDP (`RDSFDP = 0x5a`) table responders for `w25q256`
  (Winbond), `gd25q256` / `gd25b512` (GigaDevice), and `mx66l1g`
  (Macronix) flash parts.
- Support Quad Enable (`QE`), 4-byte address mode (`EN4B`/`EX4B`),
  extended status/config register reads/writes (`RDSR2`, `RDSR3`,
  `WRSR2`, `WRSR3`, `RDCR`), and soft reset (`RSTEN = 0x66`, `RST = 0x99`).

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I385be32d6cb7e2df4851e9d0931d7c8a6a6a6964
Align the OpenTitan Earlgrey OTP controller (`ot-otp-eg`,
`ot-otp-engine`, and `ot-otp_ot_be`) and its `0x40138000` `prim_tl` SoC
MMIO mapping (`hw/riscv/ot_earlgrey.c`) with `otp_ctrl.sv`,
`otp_ctrl_dai.sv`, and `otp_ctrl_prim_reg_top.sv`:
- Derive `STATUS` error bits `[12:0]` dynamically from `ERR_CODE_0..12`,
  zero `DIRECT_ACCESS_RDATA_0/1` at DAI operation start and while busy,
  and set `INTR_OTP_OPERATION_DONE` upon DAI completion.
- Reject `SW_CFG_WINDOW` writes in `ot_otp_eg_swcfg_accepts`
  (`ErrOnWrite = 1`) without raising `OTP_ERROR`, remove the
  `SW_CFG_WINDOW` digest read-lock bypass (`otp_ctrl_part_unbuf.sv:248`),
  and restrict the DAI read-lock digest exception to `hw_digest`
  partitions (`otp_ctrl_dai.sv:315`).
- Enforce `u_tlul_lc_gate` (`lc_dft_en`) and `CSR0..CSR6` field masks in
  `ot_otp_ot_be.c`, map `OT_EG_SOC_DEV_OTP_BACKEND` at `0x40138000` in
  `hw/riscv/ot_earlgrey.c`, and enforce `OTP_CTRL_CORE_PERMIT` and
  `OTP_CTRL_PRIM_PERMIT` sub-word write access faults.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: Ie81e4f9a83c39630474d835c6b9926106a6a6964
Align the OpenTitan Flash Controller (`ot-flash`) model with
`flash_ctrl.sv`, `flash_ctrl_rd.sv`, `flash_ctrl_lcmgr.sv`, and
`flash_ctrl_core_reg_top.sv`:
- Implement the `OT_FLASH_RMA_REQ` / `OT_FLASH_RMA_ACK` RMA wipe
  interface so `ot-lc_ctrl` RMA transitions erase flash banks and
  acknowledge completion.
- Enforce `MP_REGION_CFG_0..7`, `MP_BANK_CFG_SHADOWED` (two-step shadow
  register writes gated by `BANK_CFG_REGWEN`), `BANK0/1_INFO0..2_PAGE_CFG`
  (`INFO_SEL = 0..2`), `PROG_TYPE_EN` (`rw0c`), `INIT` (`rw1s`), and
  `FIFO_LVL` (`0x1f1f`) CSR semantics.
- Model the registered `u_flash_ctrl_rd.op_err_addr_o` flop
  (`flash_ctrl_rd.sv:96-102, 135-147`) via `rd_err_addr` so `OP_READ`
  faults on the final word (`remaining == 1`) latch the prior `rd_err_addr`
  into `ERR_ADDR`.
- Enforce `FLASH_CTRL_CORE_PERMIT` and `FLASH_CTRL_PRIM_PERMIT`
  (`u_tlul_lc_gate` `lc_dft_en` qualification on `0x41008000`) sub-word
  write faults, plus `tlul_adapter_sram` read/write faults (`ErrOnRead`
  on `PROG_FIFO`, `ErrOnWrite` on `RD_FIFO` and `eflash` with
  `SecdedInv3932ZeroEcc` `store_resp_intg_err_o` integrity fault).

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: If867bb51866fb6cc32295375510ee22a6a6a6964
Align the OpenTitan ROM Controller (`hw/opentitan/ot_rom_ctrl.c`) with
Earlgrey RTL (`rom_ctrl.sv`, `rom_ctrl_regs_reg_top.sv`, and
`rom_ctrl_reg_pkg.sv`):

1. Add an overlapping MMIO subregion (`ot_rom_ctrl_digest_mem_ops`) over
   the top 32 bytes (`OT_ROM_DIGEST_BYTES`) of the ROM window so CPU
   bus reads to the raw `EXP_DIGEST` words after initial KMAC readout
   raise an Ibex load integrity error (`ot_common_raise_load_integrity_error`)
   matching `rom_ctrl.sv` (`EnableDataIntgPt = 1`).
2. Log `LOG_GUEST_ERROR` instead of aborting with `error_fatal` when
   `DIGEST` does not match `EXP_DIGEST` so `pwrmgr_good = false` is
   cleanly signaled to `pwrmgr`.
3. Pulse `s->alert` transiently on `R_ALERT_TEST` writes and restore the
   sticky `R_FATAL_ALERT_CAUSE` level, and clear `s->alert` in
   `ot_rom_ctrl_reset_hold()`.
4. Enforce `ROM_CTRL_REGS_PERMIT` subword write byte enables (`0x1u` for
   `ALERT_TEST`/`FATAL_ALERT_CAUSE`, `0xfu` for `DIGEST`/`EXP_DIGEST`)
   in `ot_rom_ctrl_regs_accepts()`.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I0a2a4994d45a6fd2ad755acff3b0acaf6a6a6964
Align the OpenTitan Earlgrey AES hardware model (hw/opentitan/ot_aes.c
and include/hw/opentitan/ot_aes.h) with hw/ip/aes/rtl/aes_core.sv,
aes_control_fsm.sv, aes_ctrl_reg_shadowed.sv, and aes_reg_top.sv:

- Sanitize sparse fields in CTRL_SHADOWED on write commit (OPERATION=0
  -> AES_ENC, MODE=0 -> AES_NONE, KEY_LEN=0 -> AES_256, PRNG_RESEED_RATE=0
  -> PER_1) and ignore TRIGGER.START when MODE == AES_NONE or
  MANUAL_OPERATION == 0.
- Set STATUS.ALERT_RECOV_CTRL_UPDATE_ERR on CTRL_SHADOWED /
  CTRL_AUX_SHADOWED shadow update mismatch and clear on subsequent valid
  shadowed write; enforce CTRL_AUX_REGWEN gating on CTRL_AUX_SHADOWED.
- Handle OT_AES_LC_ESCALATE_EN lifecycle escalation input by latching
  STATUS.ALERT_FATAL_FAULT and halting the cipher FSM.
- Enforce AES_PERMIT sub-word MMIO write checks, W/O TRIGGER read-zero,
  and 1-cycle ALERT_TEST pulse semantics.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I36f4f2875f2908c0cd335d876ce4321b6a6a6964
Align the OpenTitan Earlgrey HMAC model (hw/opentitan/ot_hmac.c) with
hw/ip/hmac/rtl/hmac.sv, prim_sha2.sv, and hmac_reg_top.sv:

- Replicate SHA-256 digest words (DIGEST_0..7) into DIGEST_8..15 and
  write back the full 512-bit SHA-512 state (DIGEST_12..15 = state[6..7])
  on SHA-384 completion and context saves.
- Store WIPE_SECRET in big-endian word order so DIGEST_0..15 readback
  respects CFG.DIGEST_SWAP, and clear DIGEST_0..15 to 0 only on the
  falling edge (1 -> 0) of CFG.SHA_EN while preserving MSG_LENGTH.
- Allow CFG writes after CMD.HASH_STOP when clearing SHA_EN, ignore
  CMD.HASH_STOP when idle, and stall CMD.HASH_PROCESS on 64-bit
  MSG_LENGTH overflow (msg_length_overflow).
- Latch ERR_CODE only when INTR_STATE.HMAC_ERR is not already pending,
  report SwPushMsgWhenDisallowed when pushing to MSG_FIFO with SHA_EN=0,
  exclude status-type FIFO_EMPTY from INTR_STATE W1C, and enforce
  HMAC_PERMIT sub-word MMIO and write-only MSG_FIFO access checks.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I9aa4b51b4f89d6eb3d7b147123982a6d6a6a6964
Align the OpenTitan KMAC/SHA3 accelerator (`hw/opentitan/ot_kmac.c` and
`include/hw/opentitan/ot_kmac.h`) with Earlgrey RTL (`kmac.sv`,
`kmac_core.sv`, `kmac_entropy.sv`, `kmac_errchk.sv`, `kmac_app.sv`, and
`kmac_reg_pkg.sv`):

1. Implement the `kmac_entropy.sv` state machine (`entropy_mode` latching
   in `StRandReset`, 5-word `ENTROPY_SEED` counter, EDN endpoint request
   and `edn_wait_timer` `OT_KMAC_ERR_WAIT_TIMER_EXPIRED` timeout, and
   `ENTROPY_REFRESH_HASH_CNT` clearing on `CMD.entropy_req` /
   `CMD.hash_cnt_clr`).
2. Align `kmac_errchk.sv` `ERR_CODE` formatting (`0x0804002e` for invalid
   command sequences, `ErrModeStrength` when
   `EN_UNSUPPORTED_MODESTRENGTH=0`, `ErrKeyNotValid` on invalid sideload
   keys, and `ErrSwIssuedCmdInAppActive`).
3. Fix cSHAKE customization string `S` length offset in
   `ot_kmac_decode_sw_prefix()` (`offset += customstr_len`), gate
   `INTR_STATE.fifo_empty` on `msgfifo_full_seen_q`, and mask `STATE`
   share readouts during squeeze.
4. Add `OT_KMAC_LC_ESCALATE_EN` input handling to transition KMAC, app
   mux, and entropy FSMs into terminal error and assert `ALERT_FATAL`,
   and enforce `KMAC_PERMIT`, read-only `STATE`, and write-only
   `MSG_FIFO` MMIO `accepts` checks.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: Ibb78cbc038c93db6e5bf494001b180cb6a6a6964
Align the OpenTitan OTBN peripheral model (C wrapper and Rust instruction
engine) with Earlgrey RTL (`hw/ip/otbn/rtl/otbn.sv`, `otbn_controller.sv`,
`otbn_alu_bignum.sv`, `otbn_rf_base.sv`, `otbn_loop_controller.sv`, and
`otbn_rnd.sv`):

1. Enforce `OTBN_PERMIT[]` sub-word write checks and `ByteAccess = 0` on
   IMEM/DMEM, advance `LOAD_CHECKSUM` on idle/locked bus reads (`wdata=0`)
   and 32-bit writes (`otbn.sv:737-746`), and implement write-any-clears-to-0
   on `ERR_BITS` and `INSN_CNT` while idle or locked (`otbn.sv:926-996`).
2. Model host IMEM/DMEM illegal bus access during `BUSY_EXECUTE`
   (`ERR_BITS.ILLEGAL_BUS_ACCESS`, `FATAL_ALERT_CAUSE`, `STATUS_LOCKED`, and
   pre-lock un-encoded `39'b0` read blanking raising Ibex `FATAL_INTG_ERR`),
   plus OTP scrambling nonce generation tracking (`imem_key_gen` /
   `dmem_key_gen`) for `IMEM_INTG_VIOLATION` and `DMEM_INTG_VIOLATION`.
3. Add `OT_OTBN_LC_ESCALATE_EN` (`lc_escalate_en_i`) handling to latch
   `ERR_BITS.LIFECYCLE_ESCALATION` (`0x400000`) and lock OTBN, plus 256-bit
   `URND` PRNG seeding/advancement and post-stop 2-round internal secure wipe.
4. Fix `BN.ADDM` when `a + b == MOD` (`otbn_alu_bignum.sv:905`), `CSR FLAGS`
   (`0x7C8`) mapping to `FG0`/`FG1` and inter-execution `FLAGS`/`MOD`/`ACC`
   zeroing, `x1` call-stack simultaneous pop-before-push and dual-read port
   semantics, and `ERR_BITS.LOOP` detection at active loop end addresses.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: Ic6c2dcd10f934e671eb25dbe5c656eb96a6a6964
Align `hw/opentitan/ot_entropy_src.c` with Earlgrey `entropy_src_core.sv`
and `entropy_src_main_sm.sv`:
- Implement RepCnt, RepCntS, AdaptP, Bucket, and Markov health test windows,
  watermarks, fail counters, alert threshold checks, and recoverable alerts.
- Implement `FW_OV_CONTROL` (`FW_OV_MODE` and `FW_OV_ENTROPY_INSERT`),
  `FW_OV_SHA3_START` write-when-disabled and MuBi4 field alerts, observe FIFO
  threshold interrupts, and `FW_OV_WR_FIFO_FULL` gating.
- Support `ES_TYPE` bypass vs SHA-3 conditioning, `ES_FINAL_FIFO_DEPTH = 3`,
  12-word `ENTROPY_DATA` software reads (`swread_fifo`), 64-bit `es_bus_cmp`
  duplicate seed detection, `ERR_CODE_TEST` FSM escalation (`0x13d`), and
  TL-UL `reg_permit` byte-enable checks.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I4193ce74cf94eb787272bb02323ad8a16a6a6964
Align the OpenTitan CSRNG model (`hw/opentitan/ot_csrng.c`) with Earlgrey
RTL (`csrng_core.sv`, `csrng_main_sm.sv`, and `csrng_ctr_drbg_cmd.sv`):

- Implement continuous 128-bit block repetition check (`CMD_GEN_CNT_ERR`)
  and `flag0` (`no_glast_update`) state update semantics.
- Accept `UNINSTANTIATE` commands on already-uninstantiated application
  instances (`csrng_main_sm.sv` / `csrng_ctr_drbg_cmd.sv`), only removing
  an instance from `cmd_requests` when `ot_csrng_is_in_queue(inst)` is
  true.
- Align `INT_STATE_NUM`, `INT_STATE_READ_ENABLE`, and `INT_STATE_VAL`
  state dump indexing (`state_db_ix`, `state_db_dump_id`) and `GENBITS`
  read gating when `sw_app_enable` is disabled.
- Continuously latch invalid `CTRL` MuBi4 field alerts in `RECOV_ALERT_STS`,
  pulse `HW_EXC_STS` on command stage errors, and transition to
  `CSRNG_ERROR` (`MAIN_SM_ERR`) on FSM bits in `ERR_CODE_TEST`.
- Add `ot_csrng_regs_accepts` and expand the MMIO region to `0x80` bytes
  so unaligned/sub-word accesses and unmapped offset `0x7c` fault.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: Ib39f93ca66ba3b97fec22854d2e22e1b6a6a6964
Align the OpenTitan Earlgrey EDN model (hw/opentitan/ot_edn.c) with RTL
(edn_core.sv and edn_main_sm.sv):
- Implement HW_CMD_STS (BOOT_MODE, AUTO_MODE, CMD_TYPE, CMD_ACK, CMD_STS)
  and SW_CMD_STS state tracking across boot-request, auto-request, and SW
  port modes, including dropping SW_CMD_STS.CMD_RDY to 0 while CMD_REG_RDY
  remains 1 in AutoFirstAckWait and forwarding an all-zero command word to
  CSRNG on empty sfifo_rescmd / sfifo_gencmd replay FIFO underflow.
- Implement RECOV_ALERT_STS CSRNG_ACK_ERR and EDN_BUS_CMP_ALERT (detecting
  repeated 128-bit CSRNG packets and entering RejectCsrngEntropy 0x018).
- Implement ERR_CODE / ERR_CODE_TEST fatal alerts (gating FIFO error bits
  0, 1, 28..30 by edn_enable_fo and excluding standalone bit 30 from
  fatal_loc_events), ALERT_TEST pulse generation, sub-word CSR write
  rejection, and immediate endpoint request servicing in
  ot_edn_request_entropy().

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: Ic524fa00040071347fb9bce1792d81406a6a6964
sasdf and others added 27 commits October 30, 2026 15:25
Align the OpenTitan Alert Handler model (ot_alert) with Earlgrey RTL:

- Implement the full class escalation FSM (STATE_IDLE, STATE_TIMEOUT,
  STATE_PHASE0..3, STATE_TERMINAL), accumulation threshold triggers,
  CLASS_CTRL_SHADOWED.LOCK auto-clearing CLASS_CLR_REGWEN, and
  multi-signal escalation assertion/release (esc_tx_release_mask).
- Latch the 9-word alert crash dump (latched_dump[9]) at the configured
  CLASS_CRASHDUMP_TRIGGER_SHADOWED phase and export
  ot_alert_get_crash_dump() for ot_rstmgr.
- Add EDN ping-timer entropy reseeding (reseed_timer), local alert 5
  (LOCAL_ALERT_SHADOW_REG_UPDATE_ERROR) on shadow write mismatch,
  continuous level-high alert re-latching (alert_levels), and
  ALERT_HANDLER_PERMIT sub-word write byte-enable validation.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I14c04905884b4c1232e9c5715247fb616a6a6964
Align the OpenTitan RISC-V Timer model (ot_timer) with Earlgrey RTL
(rv_timer.sv / timer_core.sv / rv_timer_reg_top.sv):

- Allow CFG0 writes while CTRL.ACTIVE0 == 1 and snapshot the current
  64-bit mtime before updating CFG0, TIMER_V_LOWER0, or TIMER_V_UPPER0
  so in-flight 32-bit half writes do not rewind the other half to
  origin_ns, while modeling the 12-bit tick_count wrap burst
  (runaway_rem_cycles = 4096 - tick_count per timer_core.sv:32, 39) when
  CFG0.PRESCALE is lowered below the in-flight tick_count.
- Evaluate mtime >= mtimecmp in ot_timer_rearm() even when CFG0.STEP == 0
  and update IRQs when CTRL.ACTIVE0 is cleared.
- Pulse alert on ALERT_TEST writes without latching s->regs[R_ALERT_TEST].
- Enforce RV_TIMER_PERMIT byte-enable masks and unmapped offset decode
  errors via ot_timer_accepts().

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I477ce924d2061b6242979f4be4e6c14f6a6a6964
Align the OpenTitan Always-On Timer model (ot_aon_timer) with Earlgrey
RTL (aon_timer.sv / aon_timer_core.sv / aon_timer_reg_top.sv):

- Synchronize prescale_count, wkup_count, and wdog_count in
  ot_aon_timer_sync_wkup() and ot_aon_timer_sync_wdog(), and model
  rising-edge interrupt detection (wkup_intr_level / wdog_bark_level).
- Support WDOG_CTRL.PAUSE_IN_SLEEP (OT_AON_TIMER_SLEEP_MODE), lifecycle
  escalation stop (OT_AON_TIMER_LC_ESCALATE), and RESET_TYPE_WAKEUP
  retention across deep sleep.
- Allow WDOG_COUNT writes when WDOG_REGWEN == 0, pulse ALERT_TEST
  without latching, and enforce AON_TIMER_PERMIT sub-word write masks.
- Wire OT_AON_TIMER_BARK to IBEX_WRAPPER and OT_AON_TIMER_LC_ESCALATE to
  OT_EG_SOC_SPLITTER_LC_ESCALATE in hw/riscv/ot_earlgrey.c.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: Ib2f1fae937c7227cb8c97b936aa24b156a6a6964
Align `hw/opentitan/ot_ast_eg.c` with Earlgrey `ast_reg_top.sv` and AST RNG
timing:
- Increase `OT_AST_EG_NOISE_4BIT_RATE` from 50 kHz to 200 kHz (24 MHz / 120
  clocks) to match the 24 MHz AST main clock rate.
- Enforce `SwAccessRO` on `REGA28` (`0x70`), `SwAccessWO` (read-zero) on
  `REGAL` (`0x98`), and full 32-bit width on `REGA2..REGA37`, while
  ignoring expected ROM `crt_section_copy` bulk-copy writes across read-only
  `REGA0`, `REGA1`, and `REGA28` without logging guest errors.
- Add `ot_ast_eg_regs_accepts` over the `0x400`-byte MMIO window to fault on
  the `0x9c..0x1ff` unmapped hole, offsets `>= 0x214`, and subword writes.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I3c0a77949faf9a02b9104c5f8dd6d3066a6a6964
Implement Earlgrey `sensor_ctrl` (`ot-sensor-eg`) alert, wakeup, and
register accuracy:
- Model `ast_alert_latch` (`ast_alert.sv`), `ALERT_TRIG`, `ALERT_EN_0..10`
  (`Mubi4`), `FATAL_ALERT_EN`, W1C `RECOV_ALERT`, and read-only
  `FATAL_ALERT` routing to `alerts[0..1]` and `OT_SENSOR_WKUP`.
- Export `ot_sensor_eg_trigger_recov_event()` for AST/low-power sensor
  wakeup injection.
- Initialize `R_STATUS` to `AST_INIT_DONE | IO_POK` (`0x7`) and preserve
  AON registers (`R_ALERT_TRIG`, `R_RECOV_ALERT`) across resets.
- Implement `MANUAL_PAD_ATTR_0..3` storage and TL-UL sub-word write
  byte-enable checks (`ot_sensor_eg_regs_accepts`).
- Wire `SENSOR_CTRL` PLIC interrupts (158, 159) and `OT_SENSOR_WKUP` to
  `OT_PWRMGR_WAKEUP_SENSOR` in `hw/riscv/ot_earlgrey.c`.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: Ieebff30a3beb4d51e645731990ed36d06a6a6964
Align the OpenTitan Reset Manager (`ot-rstmgr`) model and its Earlgrey
SoC `USB_AON` reset line wiring (`hw/riscv/ot_earlgrey.c`) with
`rstmgr.sv` and `rstmgr_crash_info.sv`:
- Implement `ALERT_INFO` (`ALERT_INFO_ATTR = 9`) and `CPU_INFO`
  (`CPU_INFO_ATTR = 8`, `idx % 8`) crash dump capture across non-POR
  resets, preserving `ALERT_INFO_CTRL.INDEX` / `CPU_INFO_CTRL.INDEX`
  across software resets and `.EN` across low-power exit resets.
- Model `RESET_REQ` (`kMultiBitBool4True`) software reset with a 1 us
  `sw_reset_timer` delay and cancel the pending timer if `RESET_REQ` is
  cleared (`0x9`) before expiry.
- Fix `SW_RST_CTRL_N_0..7` bit-0 mask evaluation (`SW_RST_CTRL_VAL_MASK`),
  wire `OT_RSTMGR_RST_USB_AON` in `hw/riscv/ot_earlgrey.c`, and expose
  `ot_rstmgr_is_low_power_exit()` / `is_por_reset()` / `is_ndm_reset()`
  helpers.
- Pulse `ALERT_TEST` for 1 cycle and enforce `RSTMGR_PERMIT` sub-word
  write access faults (`ot_rstmgr_regs_accepts`).

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: Ie830dc3780800570434a8addcfb974256a6a6964
Align the Earlgrey power manager (`ot_pwrmgr`) model with RTL (`pwrmgr.sv`,
`pwrmgr_fsm.sv`, `pwrmgr_slow_fsm.sv`, `pwrmgr_wake_info.sv`, and
`pwrmgr_reg_top.sv`):

- Implement low-power entry and wakeup handling (`ot_pwrmgr_check_wakeup`,
  `ot_pwrmgr_set_low_power`): wait for CPU WFI (`core_sleeping_i`), abort
  low-power entry with `WAKE_INFO.ABORT` (`FastPwrStateNvmIdleChk`) if flash is
  busy, drive `OT_PWRMGR_SLEEP_EN` and `ot_aon_timer_set_sleep_mode`, update
  USB clock gating (`USB_CLK_EN_LP` vs `USB_CLK_EN_ACTIVE`), continuously
  latch `WAKE_INFO` while `record_en` (`!WAKE_INFO_CAPTURE_DIS`) is active, and
  trigger `OT_RSTMGR_RESET_LOW_POWER` on deep-sleep (`MAIN_PD_N=0`) wakeup or
  `INTR_STATE.WAKEUP` on shallow-sleep (`MAIN_PD_N=1`) wakeup.
- Add `OT_PWRMGR_NDM_RST`, `OT_PWRMGR_LC_DFT_EN`, and
  `OT_PWRMGR_LC_HW_DEBUG_EN` GPIOs to gate `ndmreset_req_i` on
  `(lc_dft_en || lc_hw_debug_en) && !in_low_power` and issue
  `OT_RSTMGR_RESET_NDM`, gate peripheral reset requests via
  `slow_regs.reset_en`, and wire `ot_pwrmgr_trigger_check()` /
  `ot_pwrmgr_cancel_check()` in `ot_rstmgr.c` and `OT_PWRMGR_NDM_RST` /
  `RESET_TYPE_WAKEUP` in `ot_earlgrey.c`.
- Enforce `RW0C` on `WAKEUP_EN_REGWEN` and `RESET_EN_REGWEN`, 1-bit `0x1`
  masking on `INTR_ENABLE`/`INTR_STATE`/`INTR_TEST`, `PWRMGR_PERMIT` sub-word
  write checks (`0x3` for `CONTROL`, `0x1` for other CSRs), and AON register
  preservation across non-POR resets (`!is_por`).

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: Iac734f158632fe86a5182e744dbb16a96a6a6964
Align the OpenTitan Key Manager (`hw/opentitan/ot_keymgr.c`) with
Earlgrey RTL (`keymgr.sv`, `keymgr_ctrl.sv`, `keymgr_sideload_key_ctrl.sv`,
and `keymgr_reg_pkg.sv`):

1. Split flash seed validity checking (`ot_keymgr_check_flash_seed`)
   from KDF input appending (`ot_keymgr_kdf_append_flash_seed`) so
   `CREATOR_SEED` is validated during `KEYMGR_STAGE_CREATOR` while
   `OWNER_SEED` is validated during `KEYMGR_STAGE_OWNER_INT`, and restrict
   `disable-flash-seed-check` to unprovisioned (`0xFF`) flash words.
2. Gate CDI state updates, `SW_SHARE0/1_OUTPUT`, hardware sideload key
   pushes, and `SW_BINDING_REGWEN` unlocking on `valid_inputs`
   (`~op_err & ~op_fault_err`), and re-apply `ot_keymgr_sideload_clear()`
   after HW key generation when `SIDELOAD_CLEAR` is active.
3. Route unenumerated `CONTROL_SHADOWED.OPERATION` encodings (`> 4`) to
   `KEYMGR_STAGE_DISABLE` (`OpDisable` per `keymgr_ctrl.sv:154`), flag
   `ERR_CODE.INVALID_OP` when `START` is triggered in `KEYMGR_ST_DISABLED`,
   and keep `FAULT_STATUS` sticky across alert updates.
4. Gate `CFG_REGWEN` (`reset = 0`) and `SW_BINDING_REGWEN` on
   `s->enabled` (`lc_keymgr_en_i`) and enforce `KEYMGR_PERMIT` subword
   write byte enables in `ot_keymgr_regs_accepts()`.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: Ib8affa06c72c74683937d2180027d72f6a6a6964
Align the OpenTitan Life Cycle Controller (`ot-lc_ctrl`) model and its
Earlgrey SoC wiring (`hw/riscv/ot_earlgrey.c`) with `lc_ctrl.sv`:
- Enforce strict 8-bit `mubi8_t` (`MUBI8_TRUE` = `0x69`) evaluation on
  `CLAIM_TRANSITION_IF`, retaining raw 8-bit values on readback while
  masking mutex-gated CSRs (`TRANSITION_TOKEN_*`, `TRANSITION_TARGET`,
  `OTP_VENDOR_TEST_CTRL`) to 0 when unclaimed (`lc_ctrl.sv:345-386`).
- Support lifecycle transitions into `LC_STATE_RMA` (with `OT_LC_RMA`
  flash RMA wipe handshake) and `LC_STATE_SCRAP`, and preserve
  `OT_LC_HW_DEBUG_EN` across NDM resets so `rv_dm` remains active.
- Pulse `ALERT_TEST` for 1 cycle (`lc_ctrl.sv:573-606`) so back-to-back
  writes re-trigger alerts, and enforce `LC_CTRL_PERMIT` sub-word write
  and unmapped offset (`>= 0x8c`) bus access faults.
- Wire `OT_LC_RMA`, `OT_LC_DFT_EN`, `OT_LC_HW_DEBUG_EN`, and
  `OT_LC_ESCALATE_EN` splitters and `volatile_raw_unlock = false`
  (`SecVolatileRawUnlockEn = 0`) in `hw/riscv/ot_earlgrey.c`.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I113df0df8333dac80ff1fd90841c113c6a6a6964
Align the OpenTitan SRAM Controller (`ot-sram_ctrl`) model with
`sram_ctrl.sv` and `sram_ctrl_regs_reg_top.sv`:
- Implement `SCR_KEY_ROTATED` `mubi4_and_hi` W1C semantics and `CTRL`
  write-only readback (`0`), and raise an Ibex load integrity error
  (`ot_common_raise_load_integrity_error`) when reading pre-rotation
  SRAM cells after `RENEW_SCR_KEY` without `CTRL.INIT`.
- Add the `OT_SRAM_CTRL_LC_ESCALATE_EN` GPIO input (and wire it from
  `OT_EG_SOC_SPLITTER_LC_ESCALATE` to `SRAM_RET_CTRL` and `SRAM_MAIN_CTRL`
  in `hw/riscv/ot_earlgrey.c`) to set `STATUS.ESCALATED` and disable the
  SRAM region upon escalation, and re-evaluate instruction fetch
  permissions on `OT_SRAM_CTRL_HW_DEBUG_EN`.
- Preserve retention SRAM (`ot_id == "ret"`) contents and CSR state
  across low-power exit resets (`ot_rstmgr_is_low_power_exit()`).
- Pulse `ALERT_TEST` for 1 cycle and enforce `SRAM_CTRL_REGS_PERMIT`
  (`4'b0001`) sub-word write faults in `ot_sram_ctrl_regs_accepts`.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: Ied47b9b28dd65832a6a03b31df9e9a776a6a6964
Align the OpenTitan Earlgrey Clock Manager (hw/opentitan/ot_clkmgr.c
and include/hw/opentitan/ot_clkmgr.h) with hw/ip/clkmgr/rtl/clkmgr.sv,
clkmgr_meas_chk.sv, and clkmgr_reg_top.sv:

- Implement per-clock measurement counter width (ot_clkmgr_get_measure_width),
  cycle count evaluation (ot_clkmgr_check_measurement), RECOV_ERR_CODE
  measurement error bits, and MuBi4False reset defaults for MEAS_CTRL_EN.
- Gate EXTCLK_STATUS settlement on OT_CLKMGR_LC_HW_DEBUG_EN and model
  low-speed external clock divider step-down (HI_SPEED_SEL = MuBi4False).
- Match clkmgr_reg_top.sv JITTER_ENABLE write behavior (latching MuBi4True),
  pulse ALERT_TEST for 1 cycle, preserve AON registers across deep-sleep
  low_power_exit while resetting MEAS_CTRL_EN and MEASURE_CTRL_REGWEN,
  and enforce CLKMGR_PERMIT sub-word MMIO write checks.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I2c51944d6fd3d4831579d15810bb1ebb6a6a6964
Implement the Earlgrey AON ADC Controller device model (TYPE_OT_ADC_CTRL,
hw/ip/adc_ctrl/rtl/adc_ctrl_core.sv and adc_ctrl_fsm.sv):

- Model all 29 adc_ctrl registers with subword write byte-enable checks
  (ADC_CTRL_PERMIT), Status-type RO INTR_STATE evaluation, and one-shot
  ALERT_TEST pulses.
- Implement the 200 kHz AON clock conversion FSM (PWRUP_TIME, WAKEUP_TIME,
  LP_SAMPLE_CNT, NP_SAMPLE_CNT, ONESHOT_MODE re-trigger latching, and
  ADC_FSM_RST gating), including 16-bit NP_SAMPLE_CTL=0 (65,536 samples)
  and 8-bit LP_SAMPLE_CTL=0 (256 samples) threshold underflow per
  adc_ctrl_fsm.sv:183, 187.
- Evaluate all 8 dual-channel 10-bit voltage filters (in-range and
  out-of-range match conditions), LP-to-NP transition detection (TRANS),
  FILTER_STATUS / ADC_INTR_STATUS W1C clearing, and OT_ADC_CTRL_WKUP
  wakeup generation to pwrmgr.
- Preserve AON filter/wakeup configuration across non-PoR sleep exits and
  wire OT_EG_SOC_DEV_ADC_CTRL in hw/riscv/ot_earlgrey.c.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I2301230c2ab4014c75310ff481e811396a6a6964
Align the OpenTitan Earlgrey UART model (hw/opentitan/ot_uart.c and
include/hw/opentitan/ot_uart.h) with hw/ip/uart/rtl/uart_core.sv and
uart_reg_top.sv:

- Add NCO baudrate-paced TX and RX timers (tx_timer, rx_timer) and an
  rx_staging_fifo so FIFO_STATUS levels, STATUS.TXIDLE/TXEMPTY, and
  TX/RX watermark and overflow interrupts match hardware timing.
- Implement TIMEOUT_CTRL RX timeout timer (rx_timeout_timer), including
  immediate INTR_STATE.RX_TIMEOUT assertion when EN=1 and VAL=0.
- Add ot_uart_update_pinmux() to dynamically route chardev TX/RX streams
  across UART0..3 when pinmux MIO_OUTSEL / MIO_PERIPH_INSEL changes,
  support CTRL.LLPBK line loopback, and detect PTY parity mismatches.
- Latch status-type bits in INTR_TEST, pulse ALERT_TEST for 1 cycle,
  preserve OVRD.TXEN and update VAL (0xffff) when enabled, allow RDATA
  reads to pop rx_fifo when CTRL.RX=0, default toggle-break to true,
  and enforce UART_PERMIT sub-word MMIO byte-enable rules.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: Ibb9d3907042b7abf30004dc80d0ea6396a6a6964
Align `ot_spi_host` with Earlgrey RTL (`spi_host.sv` / `spi_host_core.sv`
/ `spi_host_fsm.sv`):
- Model the 4-entry `u_cmd_queue` (`CmdDepth = 4`) plus active FSM slot
  (`fsm_active`), validating and queueing `COMMAND` writes even while
  `CONTROL.SPIEN == 0`.
- Enforce level-sensitive `CONTROL.SW_RST` holding TX/RX/command FIFOs
  and the core FSM in synchronous reset while asserted.
- Implement `STATUS.STALL` (`rx_stall`) and `rx_pending_word` buffering
  when `RXFIFO` is full, single-cycle `ALERT_TEST` pulsing, and
  `CONFIGOPTS` reserved bit 28 masking (`0xefffffff`).
- Expose `ot_spi_host_get_passthrough_en()` and wire `SPI_HOST0`
  (`peri.io`) and `SPI_HOST1` (`peri.io_div2`) clocks in `ot_earlgrey.c`.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I0db37964ffdc48b81a85fbd584fc4d666a6a6964
Fix runtime QOM pad control and `POR_N` reset line handling in
`hw/opentitan/ot_eg_pad_ring.c` so host `qom-set` commands on
`ot-eg-pad-ring.0` (used by `opentitanlib`'s `QemuReset` to assert and
deassert `por_n`) propagate immediately to connected SoC peripherals:

1. Replace `object_property_add_ibex_gpio` with `ot_eg_pad_ring_pad_set`
   in `ot_eg_pad_ring_init` so setting any pad property via QMP `qom-set`
   at runtime updates `s->default_levels[ix]`, drives `s->outputs[ix]`,
   and invokes `ot_eg_pad_ring_por_update(s)` when `por_n` changes.
2. Deassert `ibex_irq_set(&s->por, 0)` in `ot_eg_pad_ring_por_update` when
   `POR_N` returns high or Hi-Z (`ibex_gpio_is_hiz(level) || blevel`), and
   remove the premature `ibex_irq_set(&s->por, 0)` from
   `ot_eg_pad_ring_reset_enter` so `s->por` stays asserted across
   `system_reset` while `por_n` is held low.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I2f0a56251ea4be92941ed76aafbab3b46a6a6964
Align `ot_i2c` with Earlgrey RTL (`i2c.sv` / `i2c_core.sv` /
`i2c_controller_fsm.sv` / `i2c_target_fsm.sv`):
- Set `OT_I2C_FIFO_SIZE` to 64 entries (`fmt_fifo`, `rx_fifo`, `tx_fifo`,
  `acq_fifo`), allow `FDATA`/`TXDATA` preloading while disabled, and
  enforce `HOST_FIFO_CONFIG` / `TARGET_FIFO_CONFIG` threshold IRQs.
- Implement target mode addressing (`TARGET_ID`), `ACQDATA` / `TXDATA`
  framing, `TARGET_NACK_COUNT` (`SwAccessRC`), and cross-instance bus
  routing (`ot_i2c_get_active_target_bus`).
- Implement clock-stretching (`TIMEOUT_CTRL`, `HOST_TIMEOUT_CTRL`),
  `OVRD` bitbang waveform override, and GPIO bitbang target stepping.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: If3f296521f3a0dcd72f8f67be69f4b7d6a6a6964
Add the "pmod-i2c-sensor" I2CSlave QOM device in hw/opentitan/ot_i2c.c
and wire it onto ot-i2c0..2 in hw/riscv/ot_earlgrey.c across the
OpenTitan PMOD I2C peripheral addresses (0x10, 0x1d, 0x22, 0x29, 0x30,
0x40, 0x51, 0x52, 0x59, 0x7c).

Emulate register-level responses and state transitions for the PMOD I2C
breakout board targets (ADXL345 accelerometer 0x1d, clock-stretching
target 0x22, LTR303ALS ambient light detector 0x29, MMC34160PJ compass
0x30, HDC1080 humidity/temperature sensor 0x40, MB85RC64V FRAM 0x51/0x7c,
24LC64 EEPROM 0x52 with busy-write NAK polling, SGP30 gas sensor 0x59,
and ADM1191 power monitor 0x10). Also connect pmod-i2c-sensor address
0x22 rx_delay_ms/tx_delay_ms registers to ot_i2c_get_target_stretch_ns().

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I9f9776c9e9e2279f03761ea86ec87b286a6a6964
Implement the Earlgrey 6-channel AON PWM controller device model
(TYPE_OT_PWM, hw/ip/pwm/rtl/pwm_core.sv and pwm_chan.sv):

- Model all 23 PWM registers (ALERT_TEST, REGWEN, CFG, PWM_EN, INVERT,
  PWM_PARAM_0..5, DUTY_CYCLE_0..5, BLINK_PARAM_0..5) with RW0C REGWEN
  write-protection, subword write byte-enable checks, and one-shot
  ALERT_TEST pulses.
- Implement 16-bit phase counter beat synthesis (preserving phase_ctr_q
  across CFG updates unless beat_ctr_q == CLK_DIV per pwm_core.sv:85-103),
  DC_RESN dc_mask rounding, PHASE_DELAY offsets, INVERT polarity, standard
  blink mode (BLINK_EN=1, HTBT_EN=0), and positive/negative heartbeat
  ramping (BLINK_EN=1, HTBT_EN=1, reloading dc_htbt_q from DUTY_CYCLE.A
  only while HTBT_EN == 0 per pwm_chan.sv:140-154).
- Preserve AON PWM state across non-PoR low-power exits and export
  ot_pwm_get_pin_level() for Pinmux/GPIO pad evaluation.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I9dc9d812da87178d856e135fa1acc35c6a6a6964
Implement the Earlgrey 2-channel hardware pattern generator model
(TYPE_OT_PATTGEN, hw/ip/pattgen/rtl/pattgen_core.sv and pattgen_chan.sv):

- Model all pattgen registers (INTR_STATE/ENABLE/TEST, ALERT_TEST, CTRL,
  PREDIV_CH0/CH1, DATA_CH0_0..1, DATA_CH1_0..1, SIZE) with subword write
  byte-enable checks (ot_pattgen_regs_accepts) and active-channel write
  protection when ENABLE_CHx is asserted.
- Implement dual-channel 64-bit serial bit shifting (PDA0/PCL0,
  PDA1/PCL1), clock pre-divider timing, POLARITY inversion,
  INACTIVE_LEVEL_PDA/PCL retention across mid-pattern aborts vs. full
  REPS completion, and DONE_CH0/DONE_CH1 interrupt assertion.
- Export ot_pattgen_get_pin_level() in include/hw/opentitan/ot_pattgen.h
  and add Kconfig symbols (OT_PATTGEN).

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I9ad73a5f87d0eddb30cc8a656c3f459e6a6a6964
Implement the Earlgrey AON System Reset Controller device model
(TYPE_OT_SYSRST_CTRL, hw/ip/sysrst_ctrl/rtl/sysrst_ctrl.sv):

- Model all 26 sysrst_ctrl registers with RW0C REGWEN write protection,
  subword write byte-enable checks (SYSRST_CTRL_PERMIT), Status-type RO
  INTR_STATE evaluation, and one-shot ALERT_TEST pulses.
- Implement the 4 key-combo pre-condition and detection state machines
  (COM_PRE_SEL_CTL_0..3, COM_PRE_DET_CTL_0..3, COM_SEL_CTL_0..3,
  COM_DET_CTL_0..3, COM_OUT_CTL_0..3) driving COMBO_INTR_STATUS,
  EC_RST_L stretch pulses (EC_RST_CTL), and OT_SYSRST_CTRL_RST_REQ.
- Implement ULP Z3 debounce (ULP_AC/LID/PWRB_DEBOUNCE_CTL, ULP_CTL,
  ULP_STATUS), key H2L/L2H edge interrupts (KEY_INTR_CTL,
  KEY_INTR_STATUS), auto-block overrides, and PIN_OUT_CTL/PIN_OUT_VALUE.
- Export ot_sysrst_ctrl_get_outsel_level() and preserve AON state across
  non-PoR sleep exits.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I047370c775f33c7247415f0f385026cd6a6a6964
Implement Earlgrey Pinmux AON pad attributes, sleep retention multiplexing,
and wakeup detectors in ot_pinmux_eg (hw/top_earlgrey/ip/pinmux/rtl/):

- Enforce per-pad WARL masks (prim_xilinx_pad_attr.sv) on MIO_PAD_ATTR_0..46
  and DIO_PAD_ATTR_0..15, and RW0C write-locking across all 7 REGWEN
  register families.
- Implement MIO/DIO deep-sleep retention latching (TIE_LOW, TIE_HIGH,
  HIGH_Z, KEEP) on OT_PINMUX_SLEEP_EN entry and RW0C clearing on
  MIO_PAD_SLEEP_STATUS / DIO_PAD_SLEEP_STATUS.
- Implement all 8 AON wakeup detectors (POSEDGE, NEGEDGE, EDGE, TIMEDHIGH,
  TIMEDLOW) driving WKUP_CAUSE and OT_PINMUX_WKUP to pwrmgr, including
  ungated cnt_eq_th matching in TIMEDHIGH/TIMEDLOW when
  WKUP_DETECTOR_CNT_TH_i == 0 (pinmux_wkup.sv:52, 65-72).
- Route MIO/DIO pad inputs and outputs across GPIO, sysrst_ctrl, UART,
  and USBDEV VBUS sense, and wire OT_EG_SOC_DEV_PINMUX in ot_earlgrey.c.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I99d1584e3b63e4ed45ee6588517ea8fe6a6a6964
Implement Earlgrey 32-pin GPIO and 63-pad (47 MIO + 16 DIO) padring
multiplexing and the virtual pad monitor chardev protocol in
ot_gpio_eg:

- Evaluate effective GPIO DATA_IN and MIO/DIO pad levels by combining
  GPIO DIRECT_OUT/DIRECT_OE, Pinmux MIO_OUTSEL/MIO_PERIPH_INSEL, pad
  attributes (INVERT, OD_EN, VIRTUAL_OD_EN, PULL_EN, PULL_SELECT,
  INPUT_DISABLE), sleep retention overrides, and peripheral outputs from
  ot_pattgen, ot_pwm, and ot_sysrst_ctrl.
- Support STRAPS (STRAP_SAMPLED and DLATCH) hardware strap sampling,
  level/edge interrupt evaluation, and masked halfword writes.
- Extend the QEMU GPIO chardev wire protocol to stream timestamped logic
  analyzer waveforms (B:/T:/O:) and bitbang host I/O (W:/M:/D:/P:/H:/Q)
  for opentitanlib.
- Link ot_pwm.c, ot_pattgen.c, and ot_sysrst_ctrl.c in
  hw/opentitan/meson.build and wire OT_EG_SOC_DEV_GPIO,
  OT_EG_SOC_DEV_PATTGEN, OT_EG_SOC_DEV_PWM, and OT_EG_SOC_DEV_SYSRST_CTRL
  in hw/riscv/ot_earlgrey.c now that all mutual pad callbacks are defined.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I9309f4a145ff6111e2662283e49873296a6a6964
Align `ot_usbdev` with Earlgrey RTL (`usbdev.sv` / `usbdev_iomux.sv` /
`usbdev_aon_wake.sv`):
- Implement `PHY_PINS_SENSE` / `PHY_PINS_DRIVE` transceiver loopback,
  `pinmux-sense` QOM property (`ot_usbdev_set_pinmux_sense`), and
  `PHY_CONFIG` reset value (`eop_single_bit = 1`).
- Implement the AON wake module (`WAKE_CONTROL`, `WAKE_EVENTS`) and wire
  the `OT_USBDEV_WKUP` wakeup signal to `ot_pwrmgr` in `ot_earlgrey.c`.
- Enforce `AVSETUPBUFFER` (depth 4) / `AVOUTBUFFER` (depth 8) overflow
  (`INTR_STATE.av_overflow`), event counter field masks, and unclocked
  `USBDEV_BUFFER` SRAM access fault stalling.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I23c8953d85c4fa5161dd45df7dc2bcaf6a6a6964
Extend the OpenTitan chardev I2C host proxy (`ot_i2c_host_proxy`) to
support Earlgrey I2C target-mode protocol requirements:
- Add `ProxyPendingOp` (`PROXY_PENDING_WRITE_ACK`,
  `PROXY_PENDING_READ_BYTE`) and `stop_wait_ticks` polling in
  `ot_i2c_host_proxy_timer` to stall chardev byte processing while the
  guest `ot_i2c` target stretches SCL (`ACQ` full, `ACK_CTRL_EN`, or
  `TX` empty) and return deferred ACK/NACK results via
  `ot_i2c_bus_target_get_last_ack`.
- Support target-mode repeated start (`Sr`) address updates via
  `ot_i2c_bus_target_repeated_start`, send `i2c_nack` prior to STOP/Sr
  after read transfers, and route transfers to the active `ot_i2c`
  target bus via `ot_i2c_get_active_target_bus`.
- Trigger MIO7 (`IOA7`) pinmux sleep wakeup via
  `ot_pinmux_eg_trigger_mio_wkup(7u)` when an I2C transfer starts while
  the SoC is in low-power sleep.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I97cc8ecf0e3e882868c0f189e8e42a376a6a6964
Align the OpenTitan Earlgrey SPI Device (hw/opentitan/ot_spi_device.c)
with hw/ip/spi_device/rtl/spi_device.sv, spid_status.sv, spid_addr_4b.sv,
and spi_device_reg_top.sv:

- Gate passthrough_en on FLASH_STATUS.BUSY while idle, commit SW writes
  to FLASH_STATUS on CSb de-assertion (committed_flash_status), set
  ADDR_MODE.PENDING (bit 31) on SW writes until the next command, and
  include READ_PIPELINE_MODE [23:22] in CMD_INFO_0..23 masks.
- Drive DIO pad 13 (CSb) and sample MIO peripheral input 31 (TPM_CSB)
  via ot_pinmux_eg, and pace flash/poll transactions across CSb edges.
- Gate TPM_CMD_ADDR and INTR_TPM_HEADER_NOT_EMPTY on SW-handled TPM
  transfers, latch TPM_CMD_ADDR on TPM write completion, and align
  TPM_CFG/TPM_ACCESS_1/TPM_INT_VECTOR/TPM_RID bitmasks.
- Pulse ALERT_TEST for 1 cycle, reflect INTR_TEST.TPM_HEADER_NOT_EMPTY
  in INTR_STATE, fault on egress SRAM reads (ErrOnRead=1) and sub-word
  writes (ByteAccess=0), and enforce SPI_DEVICE_PERMIT byte-enables.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I3f2be30bf3f07910b9db8f0f41ac4e5e6a6a6964
Wire the `pmod-i2c-sensor` (`0x18`, `0x1e`, `0x44`, `0x48`, `0x53`,
`0x76`) and `at24c-eeprom` (`0x50`, `0x52`, 256-byte) devices onto the
Earlgrey CW310/CW340 board I2C2 bus in `ot_earlgrey_board_realize`, and
select `AT24C` under `CONFIG_OT_EARLGREY` in `hw/riscv/Kconfig`.

Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: Ia4942bf7a81819f0c67de85761f8f4ee6a6a6964
Remove the removed flash_storage_ ML-DSA test target aliases and replace
print_flash_storage_mldsa_certs_overlapped_test_sim_qemu_rom_ext with
print_mldsa_certs_overlapped_test_sim_qemu_rom_ext following OpenTitan
commit c21599172c.

Signed-off-by: Siemen Dhooghe <sdhooghe@google.com>
@siemen11 siemen11 closed this Oct 30, 2026
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.

2 participants