-
Notifications
You must be signed in to change notification settings - Fork 791
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
[Sival, spi_dev] Tpm mode #20679
[Sival, spi_dev] Tpm mode #20679
Conversation
68fd178
to
409b08b
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.
The changes so far are fine, but we'll need the host part for the test to work on the FPGA. :)
409b08b
to
8c28ba6
Compare
f646d85
to
368eb5f
Compare
I rebased the PR. Regarding the changes needed on the FPGAs, I marked this test as broken and we can merge it. This way It can be used with Silicon and manual runs on FPGAs with the MOD. |
b1e2209
to
15685ec
Compare
15685ec
to
c8292b5
Compare
@@ -49,7 +49,7 @@ class chip_sw_spi_device_tpm_vseq extends chip_sw_base_vseq; | |||
cfg.m_spi_host_agent_cfg.csid = 1; | |||
|
|||
// enable spi agent interface to begin | |||
`DV_WAIT(cfg.sw_logger_vif.printed_log == "Begin TPM Test", | |||
`DV_WAIT(cfg.sw_logger_vif.printed_log == "SYNC: Begin TPM Test", |
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.
Is this just coding style or is this necessary for proper synchronization of the DV test?
fn tpm_read_test(opts: &Opts, transport: &TransportWrapper) -> Result<()> { | ||
let uart = transport.uart("console")?; | ||
let spi = transport.spi(&opts.spi)?; | ||
transport.pin_strapping("SPI_TPM")?.apply()?; |
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.
Stupid question: I would have expected the console name and the strapping name to be related somehow. Or is SPI_TPM
a strapping for all SPIs? Or maybe should there be an alias for the SPI TPM in opentitanlib?
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.
This has nothing to do with the console, actually. It's a strapping for the debugger to set itself up to drive the TPM portion of spi_device on earlgrey, which has a separate GPIO for the chip select and shares all the other pins with the BOOTSTRAP SPI configuration.
The BOOTSTRAP and TPM SPI devices cannot be used simultaneously. On hyperdebug, they are actually driven by entirely different IPs: There is no one SPI IP in that MCU that can handle both use cases.
The strapping config is here:
opentitan/sw/host/opentitanlib/src/app/config/hyperdebug_cw310.json
Lines 44 to 76 in c8de39a
"name": "SPI_TPM", | |
"pins": [ | |
{ | |
"name": "SPI_DEV_SCK", | |
"mode": "Input" | |
}, | |
{ | |
"name": "SPI_DEV_D0", | |
"mode": "Input" | |
}, | |
{ | |
"name": "SPI_DEV_D1", | |
"mode": "Input" | |
}, | |
{ | |
"name": "SPI_TPM_SCK", | |
"mode": "Alternate" | |
}, | |
{ | |
"name": "SPI_TPM_MOSI", | |
"mode": "Alternate" | |
}, | |
{ | |
"name": "SPI_TPM_MISO", | |
"mode": "Alternate" | |
}, | |
{ | |
"name": "SPI_TPM_CSB", | |
"mode": "PushPull" | |
} | |
] | |
} | |
], |
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.
Looks correct to me, thanks @engdoreis
CHECK_DIF_OK(dif_pinmux_pad_write_attrs(&pinmux, kTopEarlgreyMuxedPadsIoa7, | ||
kDifPinmuxPadKindMio, in_attr, | ||
&out_attr)); | ||
} |
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.
Should we add something like else { CHECK(false, "unsupported test platform %d", kDeviceType) }
here?
let tpm = tpm::SpiDriver::new(spi); | ||
let test_data = [0xA5; 10]; | ||
|
||
for _ in 0..10 { |
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'm not sure I understand the test properly - why does this run 10 times? Just for redundantly checking it works?
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 believe the original test would randomize the transactions and do 10 different ones. This logic might need to be updated so it doesn't do 10x of the same transaction, hehe.
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.
Overall it looks good to me but the commits do not seem to be atomic: there are DV changes in SiVal commits, some restyling changes mixed-up with other changes. I would suggest to rewrite the commit history maybe?
I have an unrelated question: is the code in static void atomic_wait_for_interrupt(void) {
irq_global_ctrl(false);
if (!header_interrupt_received) {
wait_for_interrupt();
}
irq_global_ctrl(true);
} Since interrupts are globally disabled, an interrupt will wake up the core at |
c8292b5
to
7233908
Compare
I think it is correct, the opentitan/sw/device/tests/aon_timer_irq_test.c Lines 132 to 145 in c8de39a
|
Signed-off-by: Douglas Reis <[email protected]>
Signed-off-by: Douglas Reis <[email protected]>
7233908
to
8586675
Compare
Some clarification here: You're correct that the interrupt won't be serviced while interrupts are "globally" disabled, but this is a misnomer. The only thing that is disabled is Ibex's jump to an ISR. The PLIC has still latched the pending interrupt and is maintaining the level signaling to Ibex ( So, if an interrupt broke us out of WFI, we will immediately jump to its ISR once |
It's not quite right. The condition must always be checked before proceeding. We cannot assume that exiting WFI means we got the event we were waiting for. This test is also able to get interrupts that break out of WFI but don't touch So, instead, it should probably look something like this: static void atomic_wait_for_interrupt(void) {
do {
// Because this next check's result is to determine whether to go to WFI,
// the check and WFI instruction must be atomic.
irq_global_ctrl(false);
if (!header_interrupt_received) {
wait_for_interrupt();
}
irq_global_ctrl(true);
// But don't proceed unless we actually have received a command!
} while (!header_interrupt_received);
} |
8586675
to
c556a4d
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.
LGTM, modulo the CI failures. It'd probably be good to fix up that atomic_wait_for_interrupt()
function, too, though.
const SIZE : usize = 10; | ||
|
||
for _ in 0..10 { | ||
let test_data : Vec<u8> = (0..SIZE).map(|_| rand::random()).collect(); |
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.
This could probably be punted to another PR, but we might want randomly-generated stimulus to be provided by some PRNG that is fed by a random (but controllable) seed. Otherwise, failures can become a bit more annoying to reproduce.
Signed-off-by: Douglas Reis <[email protected]>
This will be important to run the test on sival. Signed-off-by: Douglas Reis <[email protected]>
c556a4d
to
a342f0d
Compare
Signed-off-by: Douglas Reis <[email protected]>
c4374d8
to
84eb346
Compare
Signed-off-by: Douglas Reis <[email protected]>
84eb346
to
fa0a6d5
Compare
Backport failed for Please cherry-pick the changes locally and resolve any conflicts. git fetch origin earlgrey_es_sival
git worktree add -d .worktree/backport-20679-to-earlgrey_es_sival origin/earlgrey_es_sival
cd .worktree/backport-20679-to-earlgrey_es_sival
git switch --create backport-20679-to-earlgrey_es_sival
git cherry-pick -x 114700c5e43c1614d13a216c6b4d4c5cab0066e0 8ad34f8987839f7b7b2d280871c007d24bf4c20c 76061b5e3f464adae3140abf3c21d511fa781bd4 044c4671520142de47082845b28cd48fc3ff6a93 6373b9c7e69ad5993b5d613b3f880355b44211ca fa0a6d5f10f3a57714334f57ae3eda7aab7a0bfe |
This PR port the
spi_device_tpm_tx_rx_test
for Sival.Note: This does not work on the current Cw310 + Hyperdebug for reasons explained here.