<p>Marshall Dawson has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/22849">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">amd/common/psp: Flush buffer before commands<br><br>The PSP and x86 caches are not coherent.  Although the PSP can read<br>information from the x86 cache, its updates to the command-response<br>buffer go to DRAM.<br><br>Flush the cacheline(s) containing the command-response buffer prior<br>to issuing the command, and ensure it is accurately read after the<br>completion.<br><br>BUG=b:67309243<br><br>Change-Id: I2aa7bbddcb2197aeb9f92683465d014ec97ac64c<br>Signed-off-by: Marshall Dawson <marshalldawson3rd@gmail.com><br>---<br>M src/soc/amd/common/block/psp/psp.c<br>1 file changed, 26 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/49/22849/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/src/soc/amd/common/block/psp/psp.c b/src/soc/amd/common/block/psp/psp.c<br>index 8035a61..e9f9da8 100644<br>--- a/src/soc/amd/common/block/psp/psp.c<br>+++ b/src/soc/amd/common/block/psp/psp.c<br>@@ -15,6 +15,8 @@<br> <br> #include <arch/io.h><br> #include <arch/early_variables.h><br>+#include <cpu/x86/mp.h><br>+#include <cpu/x86/cache.h><br> #include <cbfs.h><br> #include <region_file.h><br> #include <timer.h><br>@@ -173,6 +175,28 @@<br> }<br> <br> /*<br>+ * The PSP's cache is not fully coherent with the x86's and PSP writes to the<br>+ * buffer go to DRAM.  This flushes the buffer so that once the x86 reads the<br>+ * buffer again, it refills modified values from DRAM.<br>+ *<br>+ * This function should be called on an as-needed basis depending on the<br>+ * command.  Some commands do not use a buffer.<br>+ */<br>+static void flush_buffer(void *buffer, size_t sz)<br>+{<br>+       int i;<br>+       u8 *b = (u8 *)buffer;<br>+        int lines = ALIGN_UP((uintptr_t)buffer + sz, CACHELINE_SIZE)<br>+                         - ALIGN_DOWN((uintptr_t)buffer, CACHELINE_SIZE);<br>+     lines /= CACHELINE_SIZE;<br>+<br>+  for (i = 0 ; i < lines ; i++) {<br>+           mfence();<br>+            clflush(b + i * 64);<br>+ }<br>+}<br>+<br>+/*<br>  * Notify the PSP that DRAM is present.  Upon receiving this command, the PSP<br>  * will load its OS into fenced DRAM that is not accessible to the x86 cores.<br>  */<br>@@ -187,6 +211,7 @@<br> <br>   printk(BIOS_DEBUG, "PSP: Notify that DRAM is available... ");<br> <br>+   flush_buffer(&buffer, sizeof(buffer));<br>    cmd_status = send_psp_command(MBOX_BIOS_CMD_DRAM_INFO, &buffer);<br> <br>       /* buffer's status shouldn't change but report it if it does */<br>@@ -217,6 +242,7 @@<br> <br>       printk(BIOS_DEBUG, "PSP: Notify that POST is finishing... ");<br> <br>+   flush_buffer(&buffer, sizeof(buffer));<br>    cmd_status = send_psp_command(MBOX_BIOS_CMD_BOOT_DONE, &buffer);<br> <br>       /* buffer's status shouldn't change but report it if it does */<br></pre><p>To view, visit <a href="https://review.coreboot.org/22849">change 22849</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/22849"/><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: I2aa7bbddcb2197aeb9f92683465d014ec97ac64c </div>
<div style="display:none"> Gerrit-Change-Number: 22849 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Marshall Dawson <marshalldawson3rd@gmail.com> </div>