Repository navigation
Align QEMU with FPGA's behavior on eg100 branch - #339
Merged
Merged
Conversation
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
Build a gcov-instrumented QEMU binary (qemu-system-riscv32-cov) linked against --coverage static libraries (libsystem-ot-cov.a and libqemu-riscv32-softmmu-ot-cov.a) for the riscv32-softmmu target, and package qemu-system-riscv32-cov together with its .gcno note files in scripts/opentitan/make_release.sh so Bazel test runs can collect host hardware model line/branch coverage. Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com> Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com> Change-Id: I6af52fbd3d1537704e491b047b41ac1d6a6a6964
Support exact non-power-of-two CPU clock frequencies and deterministic sleep/idle virtual clock warping in TCG icount mode for OpenTitan Earlgrey: - Add icount_set_freq_hz() and update icount_to_ns() / icount_round() to use muldiv64() against icount_freq_hz when set, avoiding power-of-two icount_time_shift rounding drift relative to 24 MHz / 500 kHz peripheral clocks. - Add icount_get_cycles() and icount_advance_bias_ns() to track total elapsed CPU cycles (executed instructions plus idle warp and host I/O poll bias). - Clamp warp_delta in icount_warp_rt() to the nearest non-external QEMU_CLOCK_VIRTUAL timer deadline so idle time warps never overshoot scheduled virtual timer expirations. - Treat cpu->disabled as idle in cpu_thread_is_idle() so QEMU_CLOCK_VIRTUAL warps forward to AON wakeup timer deadlines while the Ibex core is powered down in deep sleep. - Configure icount_set_freq_hz(24 MHz / 500 kHz) in Earlgrey AST initialization (ot_eg_soc_ast_configure). Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com> Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com> Change-Id: I4ceb2556ebaa94e832a702d3331617426a6a6964
Support sub-page (< 4 KiB) address translation offsets and instruction fetches required by OpenTitan's Ibex address translation (ot_vmapper) and sub-page ePMP regions: - Check tlb_entry_is_empty() in tlb_hit_page_mask_anyprot() and mask with TARGET_PAGE_MASK so empty TLB entries (-1) do not falsely match sub-page masked TLB invalidations. - Preserve the intra-page offset delta ((full->phys_addr & ~TARGET_PAGE_MASK) - (addr & ~TARGET_PAGE_MASK)) in tlb_set_page_full() and use addition in io_failed() so sub-page NAPOT windows remapped to different intra-page offsets translate accurately. - Allow get_page_addr_code_hostp() to resolve host code pointers when full->lg_page_size < TARGET_PAGE_BITS so instruction fetches inside sub-page ePMP and vmapper regions execute without faulting. Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com> Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com> Change-Id: Iefd28c41c65b315d9a80f6c8199fe0bb6a6a6964
In access_with_adjusted_size(), when a sub-word access (size < access_size, such as an 8-bit or 16-bit access to a MemoryRegion with valid.min_access_size = 1 and impl.min_access_size = 4) targets a little-endian device, align the dispatch address to the containing word (addr - byte_off), shift by -(byte_off * 8), and pass the byte-lane mask MAKE_64BIT_MASK(byte_off * 8, size * 8). Without this alignment and shift, sub-word reads/writes at non-zero intra-word offsets (+1, +2, +3) pass unaligned offsets with shift = 0 and a full 32-bit access_mask to the 32-bit MMIO handler, returning wrong byte lanes on sub-word reads and mis-evaluating TL-UL sub-word write permit masks. Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com> Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com> Change-Id: Ie88da62f10dbe52772e2078c828304cc6a6a6964
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
When software updates pmpcfg, pmpaddr, or mseccfg CSRs, tlb_flush() alone does not invalidate already-translated TCG blocks in the current page, and multi-instruction TBs can cross 4-byte sub-page ePMP boundaries. - Call queue_tb_flush(env_cpu(env)) alongside tlb_flush() in pmpcfg_csr_write(), pmpaddr_csr_write(), and mseccfg_csr_write(). - Limit DisasContext max_insns to 1 in riscv_tr_init_disas_context() when pmp_get_tlb_size(env, ctx->base.pc_first) == 1. - Add env->tlb_subpage and enforce tlb_size = 1 in riscv_cpu_tlb_fill() when tlb_subpage or sub-page address translation is active. Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com> Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com> Change-Id: Ie467ca9827763118aa7e8c7b2eeb4a0d6a6a6964
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
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
Earlgrey's Ibex core (ibex_controller.sv and ibex_cs_registers.sv)
implements custom Non-Maskable Interrupt (NMI) handling rather than the
ratified Smrnmi extension:
- External NMI (irq 31, mcause 0x8000001f) and internal NMI causes
(cause 0..30, mcause 0xffffffe0 | cause) both vector to mtvec + 31 * 4.
- Entering an NMI saves mstatus.{mpie,mpp}, mepc, and mcause into internal
mstack shadow CSRs and asserts nmi_mode, masking all further interrupts
and nested NMIs until MRET.
- Executing MRET while in nmi_mode restores mstatus.{mpie,mpp}, mepc, and
mcause from mstack, exits nmi_mode, and re-evaluates pending interrupts.
Add riscv_cpu_set_rnmi_int(), mstack/nmi_mode state tracking in
riscv_cpu_do_interrupt() and helper_mret(), and WFI wake on rnmip.
Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com>
Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
Change-Id: I4a014d5e33ac0f5804e4a58c5fb75b5d6a6a6964
Model Earlgrey Ibex core crash dump and pipeline stall state (ibex_core.sv and ibex_controller.sv): - Track synchronous exception nesting (sync_exc_seen) across traps and MRET; when a second synchronous fault occurs before MRET, latch double_fault_seen, preserve prev_exception_pc/prev_exception_addr, and halt the CPU. - Track WFI instruction PC (wfi_pc) and the preceding store address (last_data_addr) in helper_wfi() so resets triggered during WFI report accurate current_pc, next_pc, and mdaa in rstmgr's CPU_INFO dump. - Implement riscv_cpu_get_crash_dump() (8-word crash dump state) and riscv_cpu_stall_on_unclocked_mmio() for bus accesses to clock-gated peripherals. Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com> Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com> Change-Id: I9fe781b5536cb36ad107efbd25b973f66a6a6964
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 `hw/intc/sifive_plic.c` with OpenTitan Earlgrey `rv_plic` RTL (`rv_plic_target.sv` and `rv_plic_reg_top.sv`): - Allow `CC0` claim reads (`sifive_plic_claimed(..., ignore_threshold = true)`) to claim the highest-priority enabled and pending interrupt even when `prio <= THRESHOLD0`, while keeping `THRESHOLD0` gating on the external `MEIP` line (`ignore_threshold = false`). - Track claimed state (`sifive_plic_is_claimed()`) so level-triggered IRQs are not re-marked pending while claimed, and re-set `IP` upon `CC0` completion write (masked to `src_bits`) when the input level remains high. - Allow 2-bit WARL writes to `PRIO0`, mask unimplemented upper bits in the last `IE` word (`(1u << (num_sources & 31)) - 1u`), and check `pending_base` against `bitfield_words << 2`. - Implement `sifive_plic_accepts()` to enforce `RV_PLIC_PERMIT` sub-word byte-enable rules and raise TL-UL access faults on unmapped offsets. Co-authored-by: Google Antigravity <242056456+google-antigravity@users.noreply.github.com> Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com> Change-Id: I59b5a09073e5466cdaa19fe09d00edb36a6a6964
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 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
approved these changes
Nov 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
These commits align the behavior between QEMU and FPGA, based on the eg100 branch. Software-observable behavior matches FPGA execution, and RTL bugs are intentionally replicated in QEMU to ensure exact fidelity.
Also, this PR introduces a coverage build of qemu for measuring the coverage of qemu model. Both normal and coverage builds will be bundled in releases.
These patches have undergone extensive testing against the full OpenTitan test suite (using this fork, which enables all FPGA tests on QEMU as well).
Most of these changes were generated by AI, and the following approaches were used to generate and validate these changes between FPGA and QEMU: