[v9,20/25] MPIPL: Prepare OPAL data tag
diff mbox series

Message ID 20190712111802.23560-21-hegdevasant@linux.vnet.ibm.com
State Accepted
Headers show
Series
  • MPIPL support
Related show

Checks

Context Check Description
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot-dco success Signed-off-by present
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot success Test snowpatch/job/snowpatch-skiboot on branch master
snowpatch_ozlabs/apply_patch success Successfully applied on branch master (4db38a36b31045f0a116d388ddeac850b38c8680)

Commit Message

Vasant Hegde July 12, 2019, 11:17 a.m. UTC
Post MPIPL kernel needs OPAL metadata to create opalcore. This patch
sets up OPAL metadata tag. Next patch will add API to pass metadata
pointer to kernel.

Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
---
 core/opal-dump.c   | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/opal-api.h | 20 ++++++++++++++++++
 2 files changed, 81 insertions(+)

Patch
diff mbox series

diff --git a/core/opal-dump.c b/core/opal-dump.c
index bb90c45d0..15f82146c 100644
--- a/core/opal-dump.c
+++ b/core/opal-dump.c
@@ -41,6 +41,10 @@  static struct spira_ntuple *ntuple_mdrt;
 
 static struct mpipl_metadata    *mpipl_metadata;
 
+/* Dump metadata area */
+static struct opal_mpipl_fadump *opal_mpipl_data;
+
+
 static int opal_mpipl_add_entry(u8 region, u64 src, u64 dest, u64 size)
 {
 	int i, max_cnt;
@@ -329,6 +333,60 @@  static int64_t opal_mpipl_register_tag(enum opal_mpipl_tags tag,
 	return rc;
 }
 
+static void post_mpipl_get_opal_data(void)
+{
+	struct mdrt_table *mdrt = (void *)(MDRT_TABLE_BASE);
+	int i, j = 0, count = 0;
+	u32 mdrt_cnt = ntuple_mdrt->act_cnt;
+	struct opal_mpipl_region *region;
+
+	/* Count OPAL dump regions */
+	for (i = 0; i < mdrt_cnt; i++) {
+		if (mdrt->data_region == DUMP_REGION_OPAL_MEMORY)
+			count++;
+		mdrt++;
+	}
+
+	if (count == 0) {
+		prlog(PR_INFO, "OPAL dump is not available\n");
+		return;
+	}
+
+	opal_mpipl_data = zalloc(sizeof(struct opal_mpipl_fadump) +
+				 count * sizeof(struct opal_mpipl_region));
+	if (!opal_mpipl_data) {
+		prlog(PR_ERR, "Failed to allocate memory\n");
+		return;
+	}
+
+	/* Fill OPAL dump details */
+	opal_mpipl_data->version = OPAL_MPIPL_VERSION;
+	opal_mpipl_data->crashing_pir = mpipl_metadata->crashing_pir;
+	opal_mpipl_data->region_cnt = count;
+	region = opal_mpipl_data->region;
+
+	mdrt = (void *)(MDRT_TABLE_BASE);
+	for (i = 0; i < mdrt_cnt; i++) {
+		if (mdrt->data_region != DUMP_REGION_OPAL_MEMORY) {
+			mdrt++;
+			continue;
+		}
+
+		region[j].src  = mdrt->src_addr  & ~(HRMOR_BIT);
+		region[j].dest = mdrt->dest_addr & ~(HRMOR_BIT);
+		region[j].size = mdrt->size;
+
+		prlog(PR_NOTICE, "OPAL reserved region %d - src : 0x%llx, "
+		      "dest : 0x%llx, size : 0x%llx\n", j, region[j].src,
+		      region[j].dest, region[j].size);
+
+		mdrt++;
+		j++;
+		if (j == count)
+			break;
+	}
+}
+
 void opal_mpipl_save_crashing_pir(void)
 {
 	mpipl_metadata->crashing_pir = this_cpu()->pir;
@@ -353,6 +411,9 @@  void opal_mpipl_init(void)
 	/* Get metadata area pointer */
 	mpipl_metadata = (void *)(DUMP_METADATA_AREA_BASE);
 
+	if (dt_find_property(dump_node, "mpipl-boot"))
+		post_mpipl_get_opal_data();
+
 	/* Clear OPAL metadata area */
 	if (sizeof(struct mpipl_metadata) > DUMP_METADATA_AREA_SIZE) {
 		prlog(PR_ERR, "INSUFFICIENT OPAL METADATA AREA\n");
diff --git a/include/opal-api.h b/include/opal-api.h
index 939b836ca..25f4872e7 100644
--- a/include/opal-api.h
+++ b/include/opal-api.h
@@ -1236,6 +1236,26 @@  enum opal_mpipl_tags {
 	OPAL_MPIPL_TAG_BOOT_MEM	= 3,
 };
 
+/* Preserved memory details */
+struct opal_mpipl_region {
+	u64	src;
+	u64	dest;
+	u64	size;
+};
+
+/* Structure version */
+#define OPAL_MPIPL_VERSION		0x01
+
+struct opal_mpipl_fadump {
+	u8	version;
+	u8	reserved[7];
+	u32	crashing_pir;	/* OPAL crashing CPU PIR */
+	u32	cpu_data_version;
+	u32	cpu_data_size;
+	u32	region_cnt;
+	struct	opal_mpipl_region region[];
+} __packed;
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* __OPAL_API_H */