[09/10] discover/platform-powerpc: Determine ppc platform type

Message ID 20170825055940.24134-10-sam@mendozajonas.com
State New
Headers show

Commit Message

Samuel Mendoza-Jonas Aug. 25, 2017, 5:59 a.m.
Some platform setup for platform-powerpc depends on the whether the
platform includes an IBM FSP or a BMC used on OpenPOWER platforms.
Rather than checking each time it is needed, check once in probe() and
record the information.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
---
 discover/platform-powerpc.c | 35 +++++++++++++++++++++++------------
 1 file changed, 23 insertions(+), 12 deletions(-)

Patch

diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c
index a2b3ba5..e659919 100644
--- a/discover/platform-powerpc.c
+++ b/discover/platform-powerpc.c
@@ -47,6 +47,12 @@  struct platform_powerpc {
 	int 		(*set_os_boot_sensor)(
 				struct platform_powerpc *platform);
 	int		(*get_platform_versions)(struct system_info *info);
+
+	enum {
+			POWERPC_PLATFORM_FSP,
+			POWERPC_PLATFORM_BMC,
+			POWERPC_PLATFORM_UNKNOWN,
+	} type;
 };
 
 static const char *known_params[] = {
@@ -1225,11 +1231,9 @@  static void get_ipmi_network_override(struct platform_powerpc *platform,
 	}
 }
 
-static void get_active_consoles(struct config *config)
+static void get_active_consoles(struct platform_powerpc *platform,
+		struct config *config)
 {
-	struct stat sbuf;
-	char *fsp_prop = NULL;
-
 	config->n_consoles = 2;
 	config->consoles = talloc_array(config, char *, config->n_consoles);
 	if (!config->consoles)
@@ -1240,8 +1244,7 @@  static void get_active_consoles(struct config *config)
 	config->consoles[1] = talloc_asprintf(config->consoles,
 					"/dev/tty1 [VGA]");
 
-	fsp_prop = talloc_asprintf(config, "%sfsps", devtree_dir);
-	if (stat(fsp_prop, &sbuf) == 0) {
+	if (platform->type == POWERPC_PLATFORM_FSP) {
 		/* FSP based machines also have a separate serial console */
 		config->consoles = talloc_realloc(config, config->consoles,
 						char *,	config->n_consoles + 1);
@@ -1282,7 +1285,7 @@  static int load_config(struct platform *p, struct config *config)
 	if (platform->ipmi)
 		get_ipmi_network_override(platform, config);
 
-	get_active_consoles(config);
+	get_active_consoles(platform, config);
 
 	return 0;
 }
@@ -1349,7 +1352,6 @@  static bool probe(struct platform *p, void *ctx)
 {
 	struct platform_powerpc *platform;
 	struct stat statbuf;
-	bool bmc_present;
 	int rc;
 
 	/* we need a device tree */
@@ -1365,9 +1367,14 @@  static bool probe(struct platform *p, void *ctx)
 
 	p->platform_data = platform;
 
-	bmc_present = stat("/proc/device-tree/bmc", &statbuf) == 0;
+	if (stat("/proc/device-tree/fsps", &statbuf) == 0)
+		platform->type = POWERPC_PLATFORM_FSP;
+	else if (stat("/proc/device-tree/bmc", &statbuf) == 0)
+		platform->type = POWERPC_PLATFORM_BMC;
+	else
+		platform->type = POWERPC_PLATFORM_UNKNOWN;
 
-	if (ipmi_present() && bmc_present) {
+	if (ipmi_present() && platform->type == POWERPC_PLATFORM_BMC) {
 		pb_debug("platform: using direct IPMI for IPMI paramters\n");
 		platform->ipmi = ipmi_open(platform);
 		platform->get_ipmi_bootdev = get_ipmi_bootdev_ipmi;
@@ -1382,8 +1389,12 @@  static bool probe(struct platform *p, void *ctx)
 		pb_log("platform: no IPMI parameter support\n");
 	}
 
-	if (bmc_present)
-		platform->get_platform_versions = hostboot_load_versions;
+	if (platform->type == POWERPC_PLATFORM_BMC) {
+		if (!stat("/proc/device-tree/ibm,firmware-versions", &statbuf))
+			platform->get_platform_versions = device_tree_find_firmware_versions;
+		else
+			platform->get_platform_versions = hostboot_load_versions;
+	}
 
 	return true;
 }