[coreboot-gerrit] Change in coreboot[master]: lib/stage_cache: Add save/get raw storage

Marshall Dawson (Code Review) gerrit at coreboot.org
Wed Jan 31 19:59:13 CET 2018


Marshall Dawson has uploaded this change for review. ( https://review.coreboot.org/23518


Change subject: lib/stage_cache: Add save/get raw storage
......................................................................

lib/stage_cache: Add save/get raw storage

Leverage the stage_cache mechanism to store a non-specific type
of data.  This is not interesting when the location for the cache
is in cbmem.  However it will be more useful when an external
location is used, e.g. when the cache is in TSEG, locked from user
modification.

Change-Id: Iaf0b25ebe14c176bbd24fc8942f902f627ca8e6f
Signed-off-by: Marshall Dawson <marshalldawson3rd at gmail.com>
---
M src/commonlib/include/commonlib/cbmem_id.h
M src/include/stage_cache.h
M src/lib/cbmem_stage_cache.c
M src/lib/ext_stage_cache.c
4 files changed, 77 insertions(+), 0 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/18/23518/1

diff --git a/src/commonlib/include/commonlib/cbmem_id.h b/src/commonlib/include/commonlib/cbmem_id.h
index 9a66246..3529fef 100644
--- a/src/commonlib/include/commonlib/cbmem_id.h
+++ b/src/commonlib/include/commonlib/cbmem_id.h
@@ -61,6 +61,7 @@
 #define CBMEM_ID_SMM_SAVE_SPACE	0x07e9acee
 #define CBMEM_ID_STAGEx_META	0x57a9e000
 #define CBMEM_ID_STAGEx_CACHE	0x57a9e100
+#define CBMEM_ID_STAGEx_RAW	0x57a9e200
 #define CBMEM_ID_STORAGE_DATA	0x53746f72
 #define CBMEM_ID_TCPA_LOG	0x54435041
 #define CBMEM_ID_TIMESTAMP	0x54494d45
diff --git a/src/include/stage_cache.h b/src/include/stage_cache.h
index 08312ff..f276380 100644
--- a/src/include/stage_cache.h
+++ b/src/include/stage_cache.h
@@ -24,10 +24,15 @@
 	STAGE_RAMSTAGE,
 	STAGE_REFCODE,
 	STAGE_POSTCAR,
+	STAGE_S3_DATA,
 };
 
 /* Cache the loaded stage provided according to the parameters. */
 void stage_cache_add(int stage_id, const struct prog *stage);
+/* Cache non-specific data or code. */
+void stage_cache_add_raw(int stage_id, const void *base, const size_t size);
+/* Get a pointer to cached raw data and its size. */
+void stage_cache_get_raw(int stage_id, void **base, size_t *size);
 /* Load the cached stage at given location returning the stage entry point. */
 void stage_cache_load_stage(int stage_id, struct prog *stage);
 /* Fill in parameters for the external stage cache, if utilized. */
diff --git a/src/lib/cbmem_stage_cache.c b/src/lib/cbmem_stage_cache.c
index cc4832f..299cb00 100644
--- a/src/lib/cbmem_stage_cache.c
+++ b/src/lib/cbmem_stage_cache.c
@@ -17,6 +17,7 @@
 #include <cbmem.h>
 #include <stage_cache.h>
 #include <string.h>
+#include <console/console.h>
 
 /* Stage cache uses cbmem. */
 void stage_cache_add(int stage_id, const struct prog *stage)
@@ -44,6 +45,35 @@
 	memcpy(c, prog_start(stage), prog_size(stage));
 }
 
+void stage_cache_add_raw(int stage_id, const void *base, const size_t size)
+{
+	void *c;
+
+	c = cbmem_add(CBMEM_ID_STAGEx_RAW + stage_id, size);
+	if (c == NULL) {
+		printk(BIOS_DEBUG, "Error: Can't add %x raw data to cbmem\n",
+				CBMEM_ID_STAGEx_RAW + stage_id);
+		return;
+	}
+
+	memcpy(c, base, size);
+}
+
+void stage_cache_get_raw(int stage_id, void **base, size_t *size)
+{
+	const struct cbmem_entry *e;
+
+	e = cbmem_entry_find(CBMEM_ID_STAGEx_RAW + stage_id);
+	if (e == NULL) {
+		printk(BIOS_ERR, "Error: Can't find raw %x data in cbmem\n",
+				CBMEM_ID_STAGEx_RAW + stage_id);
+		return;
+	}
+
+	*base = cbmem_entry_start(e);
+	*size = cbmem_entry_size(e);
+}
+
 void stage_cache_load_stage(int stage_id, struct prog *stage)
 {
 	struct stage_cache *meta;
diff --git a/src/lib/ext_stage_cache.c b/src/lib/ext_stage_cache.c
index cea9f52..ab78347 100644
--- a/src/lib/ext_stage_cache.c
+++ b/src/lib/ext_stage_cache.c
@@ -93,6 +93,47 @@
 	memcpy(c, prog_start(stage), prog_size(stage));
 }
 
+void stage_cache_add_raw(int stage_id, const void *base, const size_t size)
+{
+	struct imd *imd;
+	const struct imd_entry *e;
+	void *c;
+
+	imd = imd_get();
+	e = imd_entry_add(imd, CBMEM_ID_STAGEx_RAW + stage_id, size);
+	if (e == NULL) {
+		printk(BIOS_DEBUG, "Error: Can't add %x raw data to imd\n",
+				CBMEM_ID_STAGEx_RAW + stage_id);
+		return;
+	}
+
+	c = imd_entry_at(imd, e);
+	if (c == NULL) {
+		printk(BIOS_DEBUG, "Error: Can't get %x raw entry in imd\n",
+				CBMEM_ID_STAGEx_RAW + stage_id);
+		return;
+	}
+
+	memcpy(c, base, size);
+}
+
+void stage_cache_get_raw(int stage_id, void **base, size_t *size)
+{
+	struct imd *imd;
+	const struct imd_entry *e;
+
+	imd = imd_get();
+	e = imd_entry_find(imd, CBMEM_ID_STAGEx_RAW + stage_id);
+	if (e == NULL) {
+		printk(BIOS_DEBUG, "Error: Can't find %x raw data to imd\n",
+				CBMEM_ID_STAGEx_RAW + stage_id);
+		return;
+	}
+
+	*base = imd_entry_at(imd, e);
+	*size = imd_entry_size(imd, e);
+}
+
 void stage_cache_load_stage(int stage_id, struct prog *stage)
 {
 	struct imd *imd;

-- 
To view, visit https://review.coreboot.org/23518
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaf0b25ebe14c176bbd24fc8942f902f627ca8e6f
Gerrit-Change-Number: 23518
Gerrit-PatchSet: 1
Gerrit-Owner: Marshall Dawson <marshalldawson3rd at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20180131/40396643/attachment-0001.html>


More information about the coreboot-gerrit mailing list