-
Notifications
You must be signed in to change notification settings - Fork 13
[ot] hw/opentitan: ot_spi_device: Implement the TPM mode #249
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
base: ot-9.2.0
Are you sure you want to change the base?
Conversation
2ed5386
to
aa2670c
Compare
8ba3a5c
to
8cc7204
Compare
I'll review it soon; I've noticed there are a couple of type mismatches (e.g. |
see also the PR title, as they now follow the
formatting, i.e. |
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 got part way through reviewing but then @engdoreis told me this is still being actively worked on as a draft. I'll leave the comments I had for now though to aid development, but I haven't looked at any of the TPM logic itself yet.
c004a06
to
8675744
Compare
Based on the table in the spi_device/doc/programmers_guide Signed-off-by: Douglas Reis <[email protected]>
Signed-off-by: Douglas Reis <[email protected]>
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.
Note: I would recommend to add new trace_ot_spi_device_...
Traces are very useful for debugging the emulation itself, but they are also very useful when developping guest SW (RISC-V code) and remote host peer SW. Thanks.
#define SPI_SRAM_MBX_SIZE 0x400u | ||
#define SPI_SRAM_SFDP_OFFSET (SPI_SRAM_MBX_OFFSET + SPI_SRAM_MBX_SIZE) | ||
#define SPI_SRAM_SFDP_SIZE 0x100u | ||
|
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.
try to remove extra empty lines.
#define SPI_SRAM_PAYLOAD_OFFSET (SPI_SRAM_SFDP_OFFSET + SPI_SRAM_SFDP_SIZE) | ||
#define SPI_SRAM_INGRESS_OFFSET 0xE00u | ||
|
||
static_assert(SPI_SRAM_INGRESS_OFFSET >= |
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.
try to move the assertions after the constant definitions
} OtSpiFlashState; | ||
|
||
typedef enum { | ||
SPI_TPM_IDLE, // Wait for the fist byte of the header. |
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.
QEMU comments only use C style (/* */
)
OtSpiTpmState state; | ||
uint32_t can_receive; | ||
uint32_t transfer_size; | ||
bool read; |
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.
try to move it near the other bool
*/ | ||
static bool ot_spi_device_is_tpm_mode_crb(const OtSPIDeviceState *s) | ||
{ | ||
return ( |
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.
very weird formatting :-)
there is an explci cast to an enumerated balue but you're returning a bool
?
Looks like the cast is copy/pasted.
SpiDeviceTpm *tpm = &s->tpm; | ||
|
||
if (size != tpm->can_receive) { | ||
error_setg(&error_fatal, "TPM expected %u bytes, got %u\n", |
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.
Suspicious fatal error (just checking): Is this an internal error or something that can be triggered from the peer?
if (size != tpm->can_receive) { | ||
error_setg(&error_fatal, "TPM expected %u bytes, got %u\n", | ||
tpm->can_receive, size); | ||
tpm->state = SPI_TPM_END; |
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.
won't be reached :-)
return; | ||
} | ||
|
||
tpm->reg = buf[1] << 8 | buf[2]; |
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.
missing u
s
tpm->locality = tpm->reg >> 12u; | ||
s->tpm_regs[R_TPM_CMD_ADDR] = | ||
(tpm->opcode << R_TPM_CMD_ADDR_CMD_SHIFT) | tpm->reg; | ||
if (tpm->read) { // When read, we immidiatelly release the software to fill |
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.
C++ style comment + typo
if (tpm->read) { | ||
tpm->state = tpm->should_sw_handle ? SPI_TPM_READ : SPI_TPM_READ_HW_REG; | ||
} | ||
tx_buf[size - 1] = 0x01u; |
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.
u
ThIs PR does not cover all the TPM implementation, the HW registers will be covered by a follow up PR.
To test use the Opentitan PR lowRISC/opentitan#28542 and run: