[coreboot-gerrit] Change in coreboot[master]: lib/bootmem: Introduce custom bootmem tags

Patrick Rudolph (Code Review) gerrit at coreboot.org
Thu Apr 12 13:07:08 CEST 2018


Patrick Rudolph has uploaded this change for review. ( https://review.coreboot.org/25633


Change subject: lib/bootmem: Introduce custom bootmem tags
......................................................................

lib/bootmem: Introduce custom bootmem tags

Introduce bootmem custom memory tags and use them instead of reusing
LB_MEM tags.

Tested with uImage payload on Cavium SoC.

Change-Id: I7be8fa792fc7933ca218ecd43d250d3a9c55caa6
Signed-off-by: Patrick Rudolph <patrick.rudolph at 9elements.com>
---
M src/arch/x86/tables.c
M src/include/bootmem.h
M src/lib/bootmem.c
M src/lib/imd_cbmem.c
M src/lib/selfboot.c
5 files changed, 66 insertions(+), 21 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/33/25633/1

diff --git a/src/arch/x86/tables.c b/src/arch/x86/tables.c
index 057f665..0a9a3d5 100644
--- a/src/arch/x86/tables.c
+++ b/src/arch/x86/tables.c
@@ -266,5 +266,5 @@
 	/* Memory from 0 through the forwarding_table is reserved. */
 	const uintptr_t base = 0;
 
-	bootmem_add_range(base, forwarding_table - base, LB_MEM_TABLE);
+	bootmem_add_range(base, forwarding_table - base, BM_MEM_TABLE);
 }
diff --git a/src/include/bootmem.h b/src/include/bootmem.h
index 10c8d51..bfe31f2 100644
--- a/src/include/bootmem.h
+++ b/src/include/bootmem.h
@@ -20,6 +20,22 @@
 #include <stdint.h>
 #include <boot/coreboot_tables.h>
 
+/**
+ * Bootmem types match to LB_MEM tags.
+ * Start at 17 to make sure that the caller doesn't provide LB_MEM tags.
+ */
+enum bootmem_type {
+	BM_MEM_FIRST = 17,	/* First entry in this list */
+	BM_MEM_RAM,		/* Memory anyone can use */
+	BM_MEM_RESERVED,	/* Don't use this memory region */
+	BM_MEM_ACPI,		/* ACPI Tables */
+	BM_MEM_NVS,		/* ACPI NVS Memory */
+	BM_MEM_UNUSABLE,	/* Unusable address space */
+	BM_MEM_VENDOR_RSVD,	/* Vendor Reserved */
+	BM_MEM_TABLE,		/* Ram configuration tables are kept in */
+	BM_MEM_LAST,		/* Last entry in this list */
+};
+
 /*
  * Initialize the memory address space prior to payload loading. The bootmem
  * serves as the source for the lb_mem table.
@@ -30,7 +46,8 @@
 void bootmem_arch_add_ranges(void);
 
 /* Add a range of a given type to the bootmem address space. */
-void bootmem_add_range(uint64_t start, uint64_t size, uint32_t type);
+void bootmem_add_range(uint64_t start, uint64_t size,
+		       const enum bootmem_type tag);
 
 /* Write memory coreboot table. */
 void bootmem_write_memory_table(struct lb_memory *mem);
diff --git a/src/lib/bootmem.c b/src/lib/bootmem.c
index ea02a16..9d30b25 100644
--- a/src/lib/bootmem.c
+++ b/src/lib/bootmem.c
@@ -20,9 +20,34 @@
 #include <cbmem.h>
 #include <device/resource.h>
 #include <stdlib.h>
+#include <assert.h>
 
 static struct memranges bootmem;
 
+/* Convert bootmem tag to LB_MEM tag */
+static uint32_t bootmem_to_lb_tag(const enum bootmem_type tag)
+{
+	switch (tag) {
+		case BM_MEM_RAM:
+			return LB_MEM_RAM;
+		case BM_MEM_RESERVED:
+			return LB_MEM_RESERVED;
+		case BM_MEM_ACPI:
+			return LB_MEM_ACPI;
+		case BM_MEM_NVS:
+			return LB_MEM_NVS;
+		case BM_MEM_UNUSABLE:
+			return LB_MEM_UNUSABLE;
+		case BM_MEM_VENDOR_RSVD:
+			return LB_MEM_VENDOR_RSVD;
+		case BM_MEM_TABLE:
+			return LB_MEM_TABLE;
+		default:
+			printk(BIOS_ERR, "ERROR: Unsupported tag %u\n", tag);
+			return LB_MEM_RESERVED;
+	}
+}
+
 void bootmem_init(void)
 {
 	const unsigned long cacheable = IORESOURCE_CACHEABLE;
@@ -34,8 +59,8 @@
 	 * that each overlapping range will take over the next. Therefore,
 	 * add cacheable resources as RAM then add the reserved resources.
 	 */
-	memranges_init(bm, cacheable, cacheable, LB_MEM_RAM);
-	memranges_add_resources(bm, reserved, reserved, LB_MEM_RESERVED);
+	memranges_init(bm, cacheable, cacheable, BM_MEM_RAM);
+	memranges_add_resources(bm, reserved, reserved, BM_MEM_RESERVED);
 
 	/* Add memory used by CBMEM. */
 	cbmem_add_bootmem();
@@ -43,9 +68,12 @@
 	bootmem_arch_add_ranges();
 }
 
-void bootmem_add_range(uint64_t start, uint64_t size, uint32_t type)
+void bootmem_add_range(uint64_t start, uint64_t size,
+		       const enum bootmem_type tag)
 {
-	memranges_insert(&bootmem, start, size, type);
+	assert (tag > BM_MEM_FIRST && tag < BM_MEM_LAST);
+
+	memranges_insert(&bootmem, start, size, tag);
 }
 
 void bootmem_write_memory_table(struct lb_memory *mem)
@@ -60,7 +88,7 @@
 	memranges_each_entry(r, &bootmem) {
 		lb_r->start = pack_lb64(range_entry_base(r));
 		lb_r->size = pack_lb64(range_entry_size(r));
-		lb_r->type = range_entry_tag(r);
+		lb_r->type = bootmem_to_lb_tag(range_entry_tag(r));
 
 		lb_r++;
 		mem->size += sizeof(struct lb_memory_range);
@@ -68,21 +96,21 @@
 }
 
 struct range_strings {
-	unsigned long tag;
+	enum bootmem_type tag;
 	const char *str;
 };
 
 static const struct range_strings type_strings[] = {
-	{ LB_MEM_RAM, "RAM" },
-	{ LB_MEM_RESERVED, "RESERVED" },
-	{ LB_MEM_ACPI, "ACPI" },
-	{ LB_MEM_NVS, "NVS" },
-	{ LB_MEM_UNUSABLE, "UNUSABLE" },
-	{ LB_MEM_VENDOR_RSVD, "VENDOR RESERVED" },
-	{ LB_MEM_TABLE, "CONFIGURATION TABLES" },
+	{ BM_MEM_RAM, "RAM" },
+	{ BM_MEM_RESERVED, "RESERVED" },
+	{ BM_MEM_ACPI, "ACPI" },
+	{ BM_MEM_NVS, "NVS" },
+	{ BM_MEM_UNUSABLE, "UNUSABLE" },
+	{ BM_MEM_VENDOR_RSVD, "VENDOR RESERVED" },
+	{ BM_MEM_TABLE, "CONFIGURATION TABLES" },
 };
 
-static const char *bootmem_range_string(unsigned long tag)
+static const char *bootmem_range_string(const enum bootmem_type tag)
 {
 	int i;
 
@@ -119,7 +147,7 @@
 			break;
 
 		if (start >= range_entry_base(r) && end <= range_entry_end(r)) {
-			if (range_entry_tag(r) == LB_MEM_RAM)
+			if (range_entry_tag(r) == BM_MEM_RAM)
 				return 1;
 		}
 	}
@@ -142,7 +170,7 @@
 		if (range_entry_size(r) < size)
 			continue;
 
-		if (range_entry_tag(r) != LB_MEM_RAM)
+		if (range_entry_tag(r) != BM_MEM_RAM)
 			continue;
 
 		if (range_entry_base(r) >= max_addr)
@@ -169,7 +197,7 @@
 	begin = end - size;
 
 	/* Mark buffer as unusuable for future buffer use. */
-	bootmem_add_range(begin, size, LB_MEM_UNUSABLE);
+	bootmem_add_range(begin, size, BM_MEM_UNUSABLE);
 
 	return (void *)(uintptr_t)begin;
 }
diff --git a/src/lib/imd_cbmem.c b/src/lib/imd_cbmem.c
index 5713c2c..23dd74b 100644
--- a/src/lib/imd_cbmem.c
+++ b/src/lib/imd_cbmem.c
@@ -299,7 +299,7 @@
 	size_t size = 0;
 
 	imd_region_used(cbmem_get_imd(), &baseptr, &size);
-	bootmem_add_range((uintptr_t)baseptr, size, LB_MEM_TABLE);
+	bootmem_add_range((uintptr_t)baseptr, size, BM_MEM_TABLE);
 }
 
 #if ENV_RAMSTAGE || (IS_ENABLED(CONFIG_EARLY_CBMEM_LIST) \
diff --git a/src/lib/selfboot.c b/src/lib/selfboot.c
index 160e8f5..20886b4 100644
--- a/src/lib/selfboot.c
+++ b/src/lib/selfboot.c
@@ -381,7 +381,7 @@
 		 */
 		if (check_regions) {
 			bootmem_add_range(ptr->s_dstaddr, ptr->s_memsz,
-					  LB_MEM_UNUSABLE);
+					  BM_MEM_UNUSABLE);
 		}
 
 		if (!overlaps_coreboot(ptr))

-- 
To view, visit https://review.coreboot.org/25633
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: I7be8fa792fc7933ca218ecd43d250d3a9c55caa6
Gerrit-Change-Number: 25633
Gerrit-PatchSet: 1
Gerrit-Owner: Patrick Rudolph <patrick.rudolph at 9elements.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20180412/74d09ebf/attachment.html>


More information about the coreboot-gerrit mailing list