[Skiboot] [PATCH 02/14] hdat: Parse hostboot memory reservations from HDAT

Oliver O'Halloran oohall at gmail.com
Thu Jan 12 14:54:01 AEDT 2017


From: Vasant Hegde <hegdevasant at linux.vnet.ibm.com>

Hostboot reserves some memory and passes via HDAT. This patch
adds code to parse node reservation details and marks it as
REGION_HW_RESERVED. Later mem_region_add_dt_reserved() populates
DT entry.

Signed-off-by: Oliver O'Halloran <oohall at gmail.com>
Cc: Vasant Hegde <hegdevasant at linux.vnet.ibm.com>
---
Vasant, I dropped your Signed-off-by since this is pretty heavily
modified from your v2. Can you review and give your S-o-b if you're OK
with the changes?
---
 hdata/memory.c     | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hdata/test/stubs.c |  1 +
 2 files changed, 58 insertions(+)

diff --git a/hdata/memory.c b/hdata/memory.c
index c6080917d134..745ce74d1dbb 100644
--- a/hdata/memory.c
+++ b/hdata/memory.c
@@ -19,7 +19,9 @@
 #include <vpd.h>
 #include <ccan/str/str.h>
 #include <libfdt/libfdt.h>
+#include <mem_region.h>
 #include <types.h>
+#include <inttypes.h>
 
 #include "spira.h"
 #include "hdata.h"
@@ -382,6 +384,59 @@ static void get_msareas(struct dt_node *root,
 	}
 }
 
+#define HRMOR_BIT (1ul << 63)
+
+static void get_hb_reserved_mem(struct HDIF_common_hdr *ms_vpd)
+{
+	const struct msvpd_hb_reserved_mem *hb_resv_mem;
+	u64 start_addr, end_addr, label_size;
+	int unnamed = 0, count, i;
+	char label[65];
+
+	/*
+	 * XXX: Reservation names only exist on P9 and on P7/8 we get the
+	 *      reserved ranges through the hostboot mini-FDT instead.
+	 */
+	if (proc_gen < proc_gen_p9)
+		return;
+
+	count = HDIF_get_iarray_size(ms_vpd, MSVPD_IDATA_HB_RESERVED_MEM);
+	if (count <= 0) {
+		prerror("MS VPD: No hostboot reserved memory found\n");
+		return;
+	}
+
+	for (i = 0; i < count; i++) {
+		hb_resv_mem = HDIF_get_iarray_item(ms_vpd,
+						   MSVPD_IDATA_HB_RESERVED_MEM,
+						   i, NULL);
+		if (!CHECK_SPPTR(hb_resv_mem))
+			continue;
+
+		label_size = be32_to_cpu(hb_resv_mem->label_size);
+		start_addr = be64_to_cpu(hb_resv_mem->start_addr);
+		end_addr = be64_to_cpu(hb_resv_mem->end_addr);
+
+		/* remove the HRMOR bypass bit */
+		start_addr &= ~HRMOR_BIT;
+		end_addr &= ~HRMOR_BIT;
+
+		if (label_size > 64)
+			label_size = 64;
+
+		memcpy(label, hb_resv_mem->label, label_size);
+		label[label_size] = '\0';
+
+		if (strlen(label) == 0)
+			snprintf(label, 64, "hostboot-reserve-%d", unnamed++);
+
+		mem_reserve_hw(label, start_addr, end_addr - start_addr);
+
+		prlog(PR_DEBUG, "MEM: Reserve '%s' %#" PRIx64 "-%#" PRIx64 "\n",
+			label, start_addr, end_addr);
+	}
+}
+
 static bool __memory_parse(struct dt_node *root)
 {
 	struct HDIF_common_hdr *ms_vpd;
@@ -430,6 +485,8 @@ static bool __memory_parse(struct dt_node *root)
 
 	get_msareas(root, ms_vpd);
 
+	get_hb_reserved_mem(ms_vpd);
+
 	prlog(PR_INFO, "MS VPD: Total MB of RAM: 0x%llx\n",
 	       (long long)be64_to_cpu(tcms->total_in_mb));
 
diff --git a/hdata/test/stubs.c b/hdata/test/stubs.c
index 9687b315f2a1..735813f21363 100644
--- a/hdata/test/stubs.c
+++ b/hdata/test/stubs.c
@@ -49,3 +49,4 @@ STUB(op_display);
 STUB(fsp_preload_lid);
 STUB(fsp_wait_lid_loaded);
 STUB(fsp_adjust_lid_side);
+STUB(mem_reserve_hw);
-- 
2.7.4



More information about the Skiboot mailing list