Skip to content

[ot] hw/opentitan: ot_uart: model watermark/empty as status interrupts#328

Merged
moidx merged 1 commit into
lowRISC:ot-10.2.0from
moidx:qemu-updates
Jun 14, 2026
Merged

[ot] hw/opentitan: ot_uart: model watermark/empty as status interrupts#328
moidx merged 1 commit into
lowRISC:ot-10.2.0from
moidx:qemu-updates

Conversation

@moidx

@moidx moidx commented May 31, 2026

Copy link
Copy Markdown

tx_watermark, rx_watermark and tx_empty are declared as status-type interrupts in the UART HWIP (uart.hjson / prim_intr_hw IntrT="Status"): their INTR_STATE bits track the live FIFO condition every cycle rather than latching, and a RW1C write has no lasting effect while the condition holds. The model treated them as event-type, latching the bit on a receive batch and clearing it only via RW1C. As a result, once software drained the RX FIFO the latched rx_watermark bit stayed asserted, so the next received byte produced no fresh interrupt edge and interrupt-driven RX (e.g. a software-loopback test on ot-earlgrey) would hang.

Compute the status-type bits live from the FIFO levels and OR them with the latched event-type bits when reading INTR_STATE and when driving the IRQ lines, so they assert and de-assert with the hardware condition:

  • rx_watermark: rx_fifo_depth >= threshold
  • tx_watermark: tx_fifo_depth < threshold
  • tx_empty: tx_fifo_depth == 0

Re-evaluate the lines after an RDATA pop and on FIFO_CTRL writes, and drop the now-unused tx_watermark edge-tracking state.

Also align the FIFO depths (TxFifoDepth=32, RxFifoDepth=64) and the watermark threshold mappings (TX saturates at TxFifoDepth/2; RX saturates at RxFifoDepth-2, with rxilvl=7 disabling the interrupt) with uart_core.sv, and only push as many received bytes as the RX FIFO can hold.

@moidx moidx requested review from cfrantz and luismarques May 31, 2026 00:13

@luismarques luismarques 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.

@jwnrt and I looked into this. We created some additional test cases, and in at least one case the behaviour of the OT_UART model is still not correct (double-checked by comparing the FPGA and QEMU executions), and will require follow-up improvements. The next step should be for us to produce a proper PR for those additional test cases. Still, this is a good improvement in correctness, so I think it can be merged, and follow-up commits can address the other scenarios we investigated. See the in-line feedback for some minor points, though.

Comment thread hw/opentitan/ot_uart.c Outdated
Comment thread hw/opentitan/ot_uart.c Outdated
tx_watermark, rx_watermark and tx_empty are declared as status-type
interrupts in the UART HWIP (uart.hjson / prim_intr_hw IntrT="Status"):
their INTR_STATE bits are read-only and track the live FIFO condition
every cycle rather than latching, so INTR_STATE writes do not affect them
and they de-assert automatically once the condition clears. The model
treated them as event-type, latching the bit on a receive batch and
clearing it only via RW1C. As a result, once software drained the RX FIFO
the latched rx_watermark bit stayed asserted, so the next received byte
produced no fresh interrupt edge and interrupt-driven RX (e.g. a
software-loopback test on ot-earlgrey) would hang.

Compute the status-type bits live from the FIFO levels and OR them with
the latched event-type bits when reading INTR_STATE and when driving the
IRQ lines, so they assert and de-assert with the hardware condition:

  - rx_watermark: rx_fifo_depth >= threshold
  - tx_watermark: tx_fifo_depth <  threshold
  - tx_empty:     tx_fifo_depth == 0

Re-evaluate the lines after an RDATA pop and on FIFO_CTRL writes, and drop
the now-unused tx_watermark edge-tracking state. The status-type bits are
ro and never stored in regs[R_INTR_STATE], so the INTR_STATE RW1C write
masks them out and only clears event-type bits.

Also align the FIFO depths (TxFifoDepth=32, RxFifoDepth=64) and the
watermark threshold mappings (TX saturates at TxFifoDepth/2; RX saturates
at RxFifoDepth-2, with rxilvl=7 disabling the interrupt) with
uart_core.sv, and only push as many received bytes as the RX FIFO can
hold.

Signed-off-by: Miguel Osorio <miguelosorio@google.com>
@moidx moidx merged commit 81285c4 into lowRISC:ot-10.2.0 Jun 14, 2026
7 of 10 checks passed
@moidx moidx deleted the qemu-updates branch June 14, 2026 02:48
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.

3 participants