-
Notifications
You must be signed in to change notification settings - Fork 12
[ot] hw/opentitan: spi_device: fix off-by-one last_read_addr #195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know OpenTitan's SPI device well but this looks correct to me from the docs and code.
Some relevant links I found if it helps anyone else reviewing:
- Docs about update on CS de-assertion https://opentitan.org/book/hw/ip/spi_device/doc/registers.html#last_read_addr
- Relevant part of the read command where the address was incremented:
qemu/hw/opentitan/ot_spi_device.c
Line 1231 in 996a48e
f->address += 1u; - Also https://opentitan.org/book/hw/ip/spi_device/doc/theory_of_operation.html#buffer-management:
The LAST_READ_ADDR shows the last read address of the recent read command. For instance, if the host system issues 0xABCD_E000 and reads 128 (or 0x80) bytes, the LAST_READ_ADDR after the transaction will show 0xABCD_E07F. It does not show the commands falling into the mailbox region or Read SFDP command’s address
39bca91
to
6491d7f
Compare
Thanks for the links |
Read commands automatically increment the address so the last read address register was too high. I don't want to assign to this register before we do the increment because the OpenTitan docs say it's only updated on CS release. Signed-off-by: James Wainwright <james.wainwright@lowrisc.org>
6491d7f
to
70ed529
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jwnrt, this LGTM now.
Signed-off-by: James Wainwright <james.wainwright@lowrisc.org>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Read commands automatically increment the address so the last read address register was too high. We still need to do the register assignment on CS deassert to match the RTL (see Alex's comment below).
I tested this against the OpenTitan
spi_device_flash_smoketest
.