Blame SOURCES/0014-devtree-Add-capabilites-to-the-OPAL-Firmware.patch

33b0a4
From 29f69ac618fd5ace9ed9aae7839b5cfdc1fb5130 Mon Sep 17 00:00:00 2001
33b0a4
From: Shivaprasad G Bhat <sbhat@linux.ibm.com>
33b0a4
Date: Wed, 1 Apr 2020 09:25:52 -0500
33b0a4
Subject: [PATCH 14/17] devtree: Add capabilites to the OPAL Firmware
33b0a4
33b0a4
On OpenPower systems, the presence of the "/ibm,opal" entry in the device tree
33b0a4
signifies machines are running under OPAL firmware (i.e skiboot). Under this
33b0a4
node OPAL exports certain available interfaces. And also this node have a
33b0a4
compatible property listing "ibm,opal-v<X> which denotes the OPAL compatability.
33b0a4
33b0a4
This change adds a function to parse information about those OPAL firmware
33b0a4
capabilities and add it to skiboot firmware node. With a current OpenPower
33b0a4
machine, we get something like this:
33b0a4
33b0a4
     *-firmware:0
33b0a4
          description: skiboot
33b0a4
          product: OPAL firmware
33b0a4
          physical id: 2
33b0a4
          version: 5.4.3-35bf9d9
33b0a4
          capabilities: opal-v2 opal-v3 prd ipmi
33b0a4
33b0a4
33b0a4
Signed-off-by: Pridhiviraj Paidipeddi <ppaidipe@linux.vnet.ibm.com>
33b0a4
Signed-off-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
33b0a4
---
33b0a4
 src/core/device-tree.cc | 42 +++++++++++++++++++++++++++++++++++++++++
33b0a4
 1 file changed, 42 insertions(+)
33b0a4
33b0a4
diff --git a/src/core/device-tree.cc b/src/core/device-tree.cc
33b0a4
index af665a4d8e1a..e7227e1f74b7 100644
33b0a4
--- a/src/core/device-tree.cc
33b0a4
+++ b/src/core/device-tree.cc
33b0a4
@@ -219,11 +219,48 @@ static void scan_devtree_bootrom(hwNode & core)
33b0a4
   }
33b0a4
 }
33b0a4
 
33b0a4
+static hwNode *add_base_opal_node(hwNode & core)
33b0a4
+{
33b0a4
+  vector < string >:: iterator it;
33b0a4
+  vector < string > compat;
33b0a4
+  string basepath = DEVICETREE "/ibm,opal";
33b0a4
+  hwNode opal("firmware");
33b0a4
+
33b0a4
+  if (!exists(basepath))
33b0a4
+    return NULL;
33b0a4
+
33b0a4
+  pushd(basepath);
33b0a4
+
33b0a4
+  opal.setProduct("OPAL firmware");
33b0a4
+  opal.setDescription("skiboot");
33b0a4
+
33b0a4
+  compat = get_strings(basepath + "/compatible");
33b0a4
+  for (it = compat.begin(); it != compat.end(); ++it) {
33b0a4
+    if (matches(*it, "^ibm,opal-v"))
33b0a4
+      opal.addCapability((*it).erase(0,4));
33b0a4
+  }
33b0a4
+
33b0a4
+  if (exists(basepath + "/ipmi/compatible") &&
33b0a4
+    matches(get_string(basepath + "/ipmi/compatible"), "^ibm,opal-ipmi"))
33b0a4
+    opal.addCapability("ipmi");
33b0a4
+
33b0a4
+  if (exists(basepath + "/diagnostics/compatible") &&
33b0a4
+    matches(get_string(basepath + "/diagnostics/compatible"), "^ibm,opal-prd"))
33b0a4
+    opal.addCapability("prd");
33b0a4
+
33b0a4
+  popd();
33b0a4
+
33b0a4
+  opal.claim();
33b0a4
+  return core.addChild(opal);
33b0a4
+}
33b0a4
+
33b0a4
 static void scan_devtree_firmware_powernv(hwNode & core)
33b0a4
 {
33b0a4
   int n;
33b0a4
   struct dirent **namelist;
33b0a4
 
33b0a4
+  hwNode *opal = add_base_opal_node(core);
33b0a4
+
33b0a4
   if (!exists(DEVICETREE "/ibm,firmware-versions"))
33b0a4
     return;
33b0a4
 
33b0a4
@@ -245,6 +282,11 @@ static void scan_devtree_firmware_powernv(hwNode & core)
33b0a4
       fwnode.setDescription(sname);
33b0a4
       fwnode.setVersion(hw::strip(get_string(fullpath)));
33b0a4
       fwnode.claim();
33b0a4
+      if (opal && sname == "skiboot") {
33b0a4
+        opal->merge(fwnode);
33b0a4
+        free(namelist[i]);
33b0a4
+        continue;
33b0a4
+      }
33b0a4
       core.addChild(fwnode);
33b0a4
     }
33b0a4
     free(namelist[i]);
33b0a4
-- 
33b0a4
2.17.1
33b0a4