<p>Vadim Bendebury has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/22231">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">spi/tpm: Make sure AP properly syncs up with Cr50<br><br>When Cr50 TPM is being reset, it continues replying to the SPI bus<br>requests, sends wrong register values in response to read requests.<br><br>This patch makes sure that the TPM driver does not proceed unless<br>proper value is read from the TPM device identification register.<br><br>If the read value is till wrong after 10 retries taken with 10 ms<br>intervals, the driver gives up and declares TPM broken/unavailable.<br><br>BRANCH=cr50<br>BUG=b:68012381<br>TEST=ran a script resetting the Fizz device as soon as the "index<br>     0x1007 return code 0" string shows up in the AP console output.<br>     The script keeps rebooting the Fizz indefinitely, before this<br>     script Fizz would fail to read TPM properly and fall into<br>     recovery after no more than four reboots.<br><br>Change-Id: I7e67ec62c2bf31077b9ae558e09214d07eccf96b<br>Signed-off-by: Vadim Bendebury <vbendeb@chromium.org><br>---<br>M src/drivers/spi/tpm/tpm.c<br>1 file changed, 30 insertions(+), 3 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/31/22231/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/src/drivers/spi/tpm/tpm.c b/src/drivers/spi/tpm/tpm.c<br>index 0b5a835..145f3a1 100644<br>--- a/src/drivers/spi/tpm/tpm.c<br>+++ b/src/drivers/spi/tpm/tpm.c<br>@@ -368,21 +368,48 @@<br>        return 1;<br> }<br> <br>+/* Device/vendor ID values of the TPM devices this driver supports. */<br>+static const uint32_t supported_did_vids[] = {<br>+   0x281ae0  /* H1 based Cr50 security chip. */<br>+};<br>+<br> int tpm2_init(struct spi_slave *spi_if)<br> {<br>    uint32_t did_vid, status;<br>     uint8_t cmd;<br>  struct tpm2_info *tpm_info = car_get_var_ptr(&g_tpm_info);<br>        struct spi_slave *spi_slave = car_get_var_ptr(&g_spi_slave);<br>+     int retries;<br> <br>       memcpy(spi_slave, spi_if, sizeof(*spi_if));<br> <br>        /*<br>-    * It is enough to check the first register read error status to bail<br>-         * out in case of malfunctioning TPM.<br>+         * 100 ms should be enough to synchronize with the TPM even under the<br>+         * worst nested reset request conditions. In vast majority of cases<br>+   * there would be no wait at all.<br>      */<br>-  if (!tpm2_read_reg(TPM_DID_VID_REG, &did_vid, sizeof(did_vid)))<br>+  for (retries = 10; retries > 0; retries--) {<br>+              int i;<br>+<br>+            tpm2_read_reg(TPM_DID_VID_REG, &did_vid, sizeof(did_vid));<br>+<br>+            for (i = 0; i < ARRAY_SIZE(supported_did_vids); i++)<br>+                      if (did_vid == supported_did_vids[i])<br>+                                break; /* Tpm is up and ready. */<br>+<br>+         if (i < ARRAY_SIZE(supported_did_vids))<br>+                   break;<br>+<br>+            /* TPM might be resetting, let's retry in a bit. */<br>+              udelay(10 * 1000);<br>+           printk(BIOS_ERR, ".");<br>+     }<br>+<br>+ if (!retries) {<br>+              printk(BIOS_ERR, "%s: Failed to connect to the TPM\n",<br>+                    __func__);<br>             return -1;<br>+   }<br> <br>  /* Claim locality 0. */<br>       if (!tpm2_claim_locality())<br></pre><p>To view, visit <a href="https://review.coreboot.org/22231">change 22231</a>. To unsubscribe, visit <a href="https://review.coreboot.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://review.coreboot.org/22231"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: coreboot </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I7e67ec62c2bf31077b9ae558e09214d07eccf96b </div>
<div style="display:none"> Gerrit-Change-Number: 22231 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Vadim Bendebury <vbendeb@chromium.org> </div>