[Skiboot] [PATCH v2 02/11] OPAL: nest feature detection

Madhavan Srinivasan maddy at linux.vnet.ibm.com
Tue Jul 21 16:38:42 AEST 2015


Patch adds nest init function and Nest meta-data load functions.
Nest events supported by HW are passed as lid (meta-data),
called as "Catalogue". Catalogue lid loading is done in two parts. First,
it is queued for loading in the preload function and in the second, loaded
catalogue is verified and used to detect chip nest instrumentation support.
New file called "nest.c" added to "hw/" directory to contain nest support code.

Signed-off-by: Madhavan Srinivasan <maddy at linux.vnet.ibm.com>
---
 hw/fsp/fsp.c       |   3 ++
 hw/nest.c          | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/platform.h |   1 +
 include/types.h    |   1 +
 4 files changed, 126 insertions(+)
 create mode 100644 hw/nest.c

diff --git a/hw/fsp/fsp.c b/hw/fsp/fsp.c
index 9a27a6fbccec..7f9802bdb6ae 100644
--- a/hw/fsp/fsp.c
+++ b/hw/fsp/fsp.c
@@ -38,6 +38,7 @@
 #include <opal.h>
 #include <opal-msg.h>
 #include <ccan/list/list.h>
+#include <chip.h>
 
 DEFINE_LOG_ENTRY(OPAL_RC_FSP_POLL_TIMEOUT, OPAL_PLATFORM_ERR_EVT, OPAL_FSP,
 		 OPAL_PLATFORM_FIRMWARE, OPAL_ERROR_PANIC, OPAL_NA, NULL);
@@ -106,6 +107,7 @@ static u64 fsp_hir_timeout;
 #define KERNEL_LID_PHYP			0x80a00701
 #define KERNEL_LID_OPAL			0x80f00101
 #define INITRAMFS_LID_OPAL		0x80f00102
+#define NEST_CATALOGUE_LID		0x81e00610
 
 /*
  * We keep track on last logged values for some things to print only on
@@ -2224,6 +2226,7 @@ static struct {
 	{ RESOURCE_ID_CAPP,	CAPP_IDX_MURANO_DD21,	0x80a02001 },
 	{ RESOURCE_ID_CAPP,	CAPP_IDX_VENICE_DD10,	0x80a02003 },
 	{ RESOURCE_ID_CAPP,	CAPP_IDX_VENICE_DD20,	0x80a02004 },
+	{ RESOURCE_ID_CATALOGUE,RESOURCE_SUBID_NONE,	NEST_CATALOGUE_LID},
 };
 
 static void fsp_start_fetching_next_lid(void);
diff --git a/hw/nest.c b/hw/nest.c
new file mode 100644
index 000000000000..3a390540da19
--- /dev/null
+++ b/hw/nest.c
@@ -0,0 +1,121 @@
+/* Copyright 2015 IBM Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *	http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * Locking notes:
+ */
+
+#include <skiboot.h>
+#include <device.h>
+#include <nest.h>
+#include <chip.h>
+#include <cpu.h>
+#include <xscom.h>
+#include <timebase.h>
+#include <opal-api.h>
+#include <io.h>
+
+/*
+ * Pointer holding the Catalogue file in memory
+ */
+struct nest_catalogue_ptr *c_ptr;
+
+/*
+ * Catalogue Page-0 (each page is 4K bytes long) contains
+ * information about Event, Group, Formula structure and entry
+ * as page offsets. Cache these offset in struct nest_catalog_page_0
+ * to help the search later.
+ */
+struct nest_catalog_page_0 *page0_ptr;
+
+int preload_catalogue_lid()
+{
+	size_t size = NEST_CATALOGUE_SIZE;
+	int loaded;
+
+        c_ptr = malloc(sizeof(struct nest_catalogue_ptr));
+	if (!c_ptr) {
+		prerror("Nest_IMA: No mem for nest_catalogue_ptr structure\n");
+		return OPAL_NO_MEM;
+	}
+
+	c_ptr->catalogue = malloc(NEST_CATALOGUE_SIZE);
+	if (!c_ptr->catalogue) {
+		prerror("Nest_IMA: No mem for catalogue lid \n");
+		return OPAL_NO_MEM;
+	}
+
+	loaded = start_preload_resource(RESOURCE_ID_CATALOGUE,
+						RESOURCE_SUBID_NONE,
+						c_ptr->catalogue, &size);
+
+	return loaded;
+}
+
+int load_catalogue_lid(int loaded)
+{
+	if (loaded == OPAL_SUCCESS)
+		loaded = wait_for_resource_loaded(RESOURCE_ID_CATALOGUE,
+							RESOURCE_SUBID_NONE);
+
+	if (loaded != OPAL_SUCCESS) {
+		prerror("Nest_IMA: Error loading catalogue lid\n");
+		free(c_ptr->catalogue);
+		free(c_ptr);
+		return OPAL_RESOURCE;
+	}
+
+	/*
+	 * Now that we have loaded the catalogue, check for the
+	 * catalog magic and make sure we have loaded what we wanted
+	 */
+	page0_ptr = (struct nest_catalog_page_0 *)CATALOGUE(c_ptr);
+	if (page0_ptr->magic != CATALOG_MAGIC) {
+		prerror("Nest_IMA: Error catalogue magic number mismatch\n");
+		free(c_ptr->catalogue);
+		free(c_ptr);
+		return OPAL_RESOURCE;
+	}
+
+	/*
+	 * Check for Chip event support in this catalogue.
+	 */
+	if (page0_ptr->chip_group_offset == 0) {
+		prerror("Nest_IMA: Not Supported \n");
+		return OPAL_UNSUPPORTED;
+	}
+
+	/*
+	 * Lets save some entry points to help out search
+	 */
+	GROUP_ENTRY(c_ptr) = PAGE0(c_ptr) +
+					(page0_ptr->group_data_offs * 4096);
+	EVENT_ENTRY(c_ptr) = PAGE0(c_ptr) +
+					(page0_ptr->event_data_offs * 4096);
+	CHIP_EVENT_ENTRY(c_ptr) = EVENT_ENTRY(c_ptr) +
+					(page0_ptr->chip_event_offset);
+	CHIP_GROUP_ENTRY(c_ptr) = GROUP_ENTRY(c_ptr) +
+					(page0_ptr->chip_group_offset);
+
+	return OPAL_SUCCESS;
+}
+
+void nest_pmu_init(int loaded)
+{
+	if (load_catalogue_lid(loaded)) {
+		printf("Nest_IMA: IMA Catalog lid failed to load\n");
+		return;
+	}
+
+	return;
+}
diff --git a/include/platform.h b/include/platform.h
index 80aa8babbe43..400f99010da4 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -26,6 +26,7 @@ enum resource_id {
 	RESOURCE_ID_KERNEL,
 	RESOURCE_ID_INITRAMFS,
 	RESOURCE_ID_CAPP,
+	RESOURCE_ID_CATALOGUE,
 };
 #define RESOURCE_SUBID_NONE 0
 #define RESOURCE_SUBID_SUPPORTED 1
diff --git a/include/types.h b/include/types.h
index 36dc81d92247..4993dfdcbaf7 100644
--- a/include/types.h
+++ b/include/types.h
@@ -22,6 +22,7 @@
 typedef u16 __be16;
 typedef u32 __be32;
 typedef u64 __be64;
+typedef u8 __u8;
 
 #endif /* __TYPES_H */
 
-- 
1.9.1



More information about the Skiboot mailing list