diff mbox

opal-prd: display explicit message on IBM Power systems

Message ID 1447177694-14661-1-git-send-email-clg@fr.ibm.com
State Superseded
Headers show

Commit Message

Cédric Le Goater Nov. 10, 2015, 5:48 p.m. UTC
Today, when run on an IBM Power systems, opal-prd complains in syslog
with a set of messages similar to these :

	opal-prd: CTRL: Starting PRD daemon
	opal-prd: I2C: Found Chip: 00000000 engine 1 port 0
	opal-prd: I2C: Found Chip: 00000010 engine 1 port 0
	opal-prd: CTRL: Listening on control socket /run/opal-prd-control
	opal-prd: FW: Can't open PRD device /dev/opal-prd: No such file or directory
	opal-prd: FW: Error initialising PRD channel
	opal-prd: CTRL: stopping PRD daemon

Which are difficult to interpret for a person not initiated to power
firmware.

The patch below detects if the platform is an IBM or an Open Power
system by looking at the device tree property :

	/sys/firmware/devicetree/base/compatible

and stops opal-prd early in the main routine with an explicit
message for the user.

Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
---
 external/opal-prd/opal-prd.c |   61 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

Comments

Benjamin Herrenschmidt Nov. 10, 2015, 7:50 p.m. UTC | #1
On Tue, 2015-11-10 at 18:48 +0100, Cédric Le Goater wrote:

> +static const char * const openpower_systems[] = {
> +	"ibm,firestone", "tyan,habanero", "tyan,palmetto"
> +};

Hi Cedric !

I'm not fan of this. For each new machine (Garrison, Rattlesnake, ...)
we'll have to update the binary.

We should instead look for the properties that indicate the supprot for
the PRD in the device-tree. Jeremy, what do you recommend ?

Cheers,
Ben.
Cédric Le Goater Nov. 10, 2015, 8:42 p.m. UTC | #2
Hello,

On 11/10/2015 08:50 PM, Benjamin Herrenschmidt wrote:
> On Tue, 2015-11-10 at 18:48 +0100, Cédric Le Goater wrote:
>>  
>> +static const char * const openpower_systems[] = {
>> +	"ibm,firestone", "tyan,habanero", "tyan,palmetto"
>> +};
> 
> Hi Cedric !
> 
> I'm not fan of this. For each new machine (Garrison, Rattlesnake, ...)
> we'll have to update the binary.

Indeed ...

> We should instead look for the properties that indicate the supprot for
> the PRD in the device-tree. Jeremy, what do you recommend ?
 
and for that purpose, we already have :  

	/sys/firmware/devicetree/base/ibm,opal/diagnostics/

I will let Jeremy comment on the v2.

Thanks,

C.
diff mbox

Patch

Index: skiboot.git/external/opal-prd/opal-prd.c
===================================================================
--- skiboot.git.orig/external/opal-prd/opal-prd.c
+++ skiboot.git/external/opal-prd/opal-prd.c
@@ -50,6 +50,8 @@ 
 #include <opal-api.h>
 #include <types.h>
 
+#include <ccan/array_size/array_size.h>
+
 #include "opal-prd.h"
 #include "hostboot-interface.h"
 #include "module.h"
@@ -1032,6 +1034,60 @@  out_free:
 	return rc;
 }
 
+bool find_string(const char *buffer, size_t len, const char *s)
+{
+	const char *c, *end;
+
+	if (!buffer)
+		return false;
+	c = buffer;
+	end = c + len;
+
+	while (c < end) {
+		if (!strcasecmp(s, c))
+			return true;
+		c += strlen(c) + 1;
+	}
+	return false;
+}
+
+static const char * const openpower_systems[] = {
+	"ibm,firestone", "tyan,habanero", "tyan,palmetto"
+};
+
+static int is_openpower(void)
+{
+	char *path;
+	int rc;
+	int len;
+	char *buf;
+	int i;
+
+	rc = asprintf(&path, "%s/compatible", devicetree_base);
+	if (rc < 0) {
+		pr_log(LOG_ERR, "FW: error creating 'compatible' node path: %m");
+		return -1;
+	}
+
+	rc = open_and_read(path, (void *) &buf, &len);
+	if (rc)
+		goto out_free;
+
+	if (buf[len - 1] != '\0')
+		pr_log(LOG_INFO, "FW: node %s is not nul-terminated", path);
+
+	for (i = 0; i < ARRAY_SIZE(openpower_systems); i++) {
+		if (find_string(buf, len, openpower_systems[i]))
+			break;
+	}
+
+	if (i == ARRAY_SIZE(openpower_systems))
+		rc = -1;
+out_free:
+	free(buf);
+	return rc;
+}
+
 static int prd_init(struct opal_prd_ctx *ctx)
 {
 	int rc;
@@ -1963,6 +2019,11 @@  int main(int argc, char *argv[])
 		action = ACTION_RUN_DAEMON;
 	}
 
+	if (is_openpower() < 0) {
+		pr_log(LOG_ERR, "CTRL: Can't run PRD commands on an IBM Power system");
+		return -1;
+	}
+
 	switch (action) {
 	case ACTION_RUN_DAEMON:
 		rc = run_prd_daemon(ctx);