<p>Marshall Dawson has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/23518">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">lib/stage_cache: Add save/get raw storage<br><br>Leverage the stage_cache mechanism to store a non-specific type<br>of data.  This is not interesting when the location for the cache<br>is in cbmem.  However it will be more useful when an external<br>location is used, e.g. when the cache is in TSEG, locked from user<br>modification.<br><br>Change-Id: Iaf0b25ebe14c176bbd24fc8942f902f627ca8e6f<br>Signed-off-by: Marshall Dawson <marshalldawson3rd@gmail.com><br>---<br>M src/commonlib/include/commonlib/cbmem_id.h<br>M src/include/stage_cache.h<br>M src/lib/cbmem_stage_cache.c<br>M src/lib/ext_stage_cache.c<br>4 files changed, 77 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/18/23518/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/commonlib/include/commonlib/cbmem_id.h b/src/commonlib/include/commonlib/cbmem_id.h</span><br><span>index 9a66246..3529fef 100644</span><br><span>--- a/src/commonlib/include/commonlib/cbmem_id.h</span><br><span>+++ b/src/commonlib/include/commonlib/cbmem_id.h</span><br><span>@@ -61,6 +61,7 @@</span><br><span> #define CBMEM_ID_SMM_SAVE_SPACE        0x07e9acee</span><br><span> #define CBMEM_ID_STAGEx_META      0x57a9e000</span><br><span> #define CBMEM_ID_STAGEx_CACHE     0x57a9e100</span><br><span style="color: hsl(120, 100%, 40%);">+#define CBMEM_ID_STAGEx_RAW 0x57a9e200</span><br><span> #define CBMEM_ID_STORAGE_DATA     0x53746f72</span><br><span> #define CBMEM_ID_TCPA_LOG 0x54435041</span><br><span> #define CBMEM_ID_TIMESTAMP        0x54494d45</span><br><span>diff --git a/src/include/stage_cache.h b/src/include/stage_cache.h</span><br><span>index 08312ff..f276380 100644</span><br><span>--- a/src/include/stage_cache.h</span><br><span>+++ b/src/include/stage_cache.h</span><br><span>@@ -24,10 +24,15 @@</span><br><span>    STAGE_RAMSTAGE,</span><br><span>      STAGE_REFCODE,</span><br><span>       STAGE_POSTCAR,</span><br><span style="color: hsl(120, 100%, 40%);">+        STAGE_S3_DATA,</span><br><span> };</span><br><span> </span><br><span> /* Cache the loaded stage provided according to the parameters. */</span><br><span> void stage_cache_add(int stage_id, const struct prog *stage);</span><br><span style="color: hsl(120, 100%, 40%);">+/* Cache non-specific data or code. */</span><br><span style="color: hsl(120, 100%, 40%);">+void stage_cache_add_raw(int stage_id, const void *base, const size_t size);</span><br><span style="color: hsl(120, 100%, 40%);">+/* Get a pointer to cached raw data and its size. */</span><br><span style="color: hsl(120, 100%, 40%);">+void stage_cache_get_raw(int stage_id, void **base, size_t *size);</span><br><span> /* Load the cached stage at given location returning the stage entry point. */</span><br><span> void stage_cache_load_stage(int stage_id, struct prog *stage);</span><br><span> /* Fill in parameters for the external stage cache, if utilized. */</span><br><span>diff --git a/src/lib/cbmem_stage_cache.c b/src/lib/cbmem_stage_cache.c</span><br><span>index cc4832f..299cb00 100644</span><br><span>--- a/src/lib/cbmem_stage_cache.c</span><br><span>+++ b/src/lib/cbmem_stage_cache.c</span><br><span>@@ -17,6 +17,7 @@</span><br><span> #include <cbmem.h></span><br><span> #include <stage_cache.h></span><br><span> #include <string.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <console/console.h></span><br><span> </span><br><span> /* Stage cache uses cbmem. */</span><br><span> void stage_cache_add(int stage_id, const struct prog *stage)</span><br><span>@@ -44,6 +45,35 @@</span><br><span>     memcpy(c, prog_start(stage), prog_size(stage));</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+void stage_cache_add_raw(int stage_id, const void *base, const size_t size)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+      void *c;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    c = cbmem_add(CBMEM_ID_STAGEx_RAW + stage_id, size);</span><br><span style="color: hsl(120, 100%, 40%);">+  if (c == NULL) {</span><br><span style="color: hsl(120, 100%, 40%);">+              printk(BIOS_DEBUG, "Error: Can't add %x raw data to cbmem\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                           CBMEM_ID_STAGEx_RAW + stage_id);</span><br><span style="color: hsl(120, 100%, 40%);">+              return;</span><br><span style="color: hsl(120, 100%, 40%);">+       }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   memcpy(c, base, size);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+void stage_cache_get_raw(int stage_id, void **base, size_t *size)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     const struct cbmem_entry *e;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        e = cbmem_entry_find(CBMEM_ID_STAGEx_RAW + stage_id);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (e == NULL) {</span><br><span style="color: hsl(120, 100%, 40%);">+              printk(BIOS_ERR, "Error: Can't find raw %x data in cbmem\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                            CBMEM_ID_STAGEx_RAW + stage_id);</span><br><span style="color: hsl(120, 100%, 40%);">+              return;</span><br><span style="color: hsl(120, 100%, 40%);">+       }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   *base = cbmem_entry_start(e);</span><br><span style="color: hsl(120, 100%, 40%);">+ *size = cbmem_entry_size(e);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> void stage_cache_load_stage(int stage_id, struct prog *stage)</span><br><span> {</span><br><span>      struct stage_cache *meta;</span><br><span>diff --git a/src/lib/ext_stage_cache.c b/src/lib/ext_stage_cache.c</span><br><span>index cea9f52..ab78347 100644</span><br><span>--- a/src/lib/ext_stage_cache.c</span><br><span>+++ b/src/lib/ext_stage_cache.c</span><br><span>@@ -93,6 +93,47 @@</span><br><span>      memcpy(c, prog_start(stage), prog_size(stage));</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+void stage_cache_add_raw(int stage_id, const void *base, const size_t size)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+      struct imd *imd;</span><br><span style="color: hsl(120, 100%, 40%);">+      const struct imd_entry *e;</span><br><span style="color: hsl(120, 100%, 40%);">+    void *c;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    imd = imd_get();</span><br><span style="color: hsl(120, 100%, 40%);">+      e = imd_entry_add(imd, CBMEM_ID_STAGEx_RAW + stage_id, size);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (e == NULL) {</span><br><span style="color: hsl(120, 100%, 40%);">+              printk(BIOS_DEBUG, "Error: Can't add %x raw data to imd\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                             CBMEM_ID_STAGEx_RAW + stage_id);</span><br><span style="color: hsl(120, 100%, 40%);">+              return;</span><br><span style="color: hsl(120, 100%, 40%);">+       }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   c = imd_entry_at(imd, e);</span><br><span style="color: hsl(120, 100%, 40%);">+     if (c == NULL) {</span><br><span style="color: hsl(120, 100%, 40%);">+              printk(BIOS_DEBUG, "Error: Can't get %x raw entry in imd\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                            CBMEM_ID_STAGEx_RAW + stage_id);</span><br><span style="color: hsl(120, 100%, 40%);">+              return;</span><br><span style="color: hsl(120, 100%, 40%);">+       }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   memcpy(c, base, size);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+void stage_cache_get_raw(int stage_id, void **base, size_t *size)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     struct imd *imd;</span><br><span style="color: hsl(120, 100%, 40%);">+      const struct imd_entry *e;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  imd = imd_get();</span><br><span style="color: hsl(120, 100%, 40%);">+      e = imd_entry_find(imd, CBMEM_ID_STAGEx_RAW + stage_id);</span><br><span style="color: hsl(120, 100%, 40%);">+      if (e == NULL) {</span><br><span style="color: hsl(120, 100%, 40%);">+              printk(BIOS_DEBUG, "Error: Can't find %x raw data to imd\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                            CBMEM_ID_STAGEx_RAW + stage_id);</span><br><span style="color: hsl(120, 100%, 40%);">+              return;</span><br><span style="color: hsl(120, 100%, 40%);">+       }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   *base = imd_entry_at(imd, e);</span><br><span style="color: hsl(120, 100%, 40%);">+ *size = imd_entry_size(imd, e);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> void stage_cache_load_stage(int stage_id, struct prog *stage)</span><br><span> {</span><br><span>   struct imd *imd;</span><br><span></span><br></pre><p>To view, visit <a href="https://review.coreboot.org/23518">change 23518</a>. To unsubscribe, or for help writing mail filters, 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/23518"/><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: Iaf0b25ebe14c176bbd24fc8942f902f627ca8e6f </div>
<div style="display:none"> Gerrit-Change-Number: 23518 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Marshall Dawson <marshalldawson3rd@gmail.com> </div>