Skip to content

Conversation

@AlexJones0
Copy link

See the commit messages for more details - fix bugs in LAST_READ_ADDR register writability and the chip select status value being reported inverted. Also reduce the arbitrary flipbuf pacing delay so that large SPI transfers do not end up delayed by 1+ second each time (see comment for more details).

* a buffer flip event) then this will not happen, and the timer must exhaust
* on its own, thus we only set this delay to a small arbitrary value of 10 ms.
*
* @todo: A better approach might be to yield to the vCPU every few bytes/words

Choose a reason for hiding this comment

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

Yes that could be a better alternative; however would need to be carefully measured with several kind of hosts, as it might come with a large overhead, depending on the host.

Copy link
Author

Choose a reason for hiding this comment

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

I agree - I do not know how common this pattern of guest SW relying on concurrent operation with the SPI Host buffer reads is but it would not be ideal to slow down general SPI Host usage because of it. It would need to be more carefully thought out (hence the todo 😅)

Copy link

@engdoreis engdoreis left a comment

Choose a reason for hiding this comment

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

LGTM.

Comment on lines -770 to +779
if (ot_spi_device_is_cs_active(s)) {
if (!ot_spi_device_is_cs_active(s)) {

Choose a reason for hiding this comment

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

Now that TPM mode has been implemented there is also the STATUS.tpm_csb bit which is also active low: Hardware Interfaces, so maybe this function should be inlined here and extended to also do that.

Copy link
Author

Choose a reason for hiding this comment

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

Even though TPM mode is now implemented, the TPM CS itself is not (we only have 1 CS in the protocol currently) - see relevant discussion here.

I think that it's a good idea to make sure this isn't lost though, so I've added a TODO capturing this missing field.

This register is read-only, it should not be writable.

Signed-off-by: Alex Jones <alex.jones@lowrisc.org>
The SPI Device's `STATUS.csb` field is the "Direct input of CSb signal".
The current logic reports a 1 if the CS is active (i.e. we are not idle
or in some error state, the SPI bus is active), but /CS is active low
and as such it should report a 0 when active, and a 1 when not.

Signed-off-by: Alex Jones <alex.jones@lowrisc.org>
See the relevant comment - this arbitrary timeout is much longer than
expected and can cause unexpected timeouts when using the SPI device for
large reads with software that does not expect to handle this event and fill
these buffers.

When using an icount shift of 6, we can often end up waiting just over a
second for the read to resume, greatly slowing down SPI operation.

Signed-off-by: Alex Jones <alex.jones@lowrisc.org>
Copy link

@rivos-eblot rivos-eblot left a comment

Choose a reason for hiding this comment

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

LGTM

@AlexJones0 AlexJones0 merged commit 5013d60 into lowRISC:ot-9.2.0 Nov 18, 2025
10 checks passed
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.

4 participants