Blame SOURCES/0025-devtree-Add-VPD-info-for-BMC-based-IBM-Power-System.patch

99c779
From d0791b8831e2eee3e6942dbcbe716021576a72bd Mon Sep 17 00:00:00 2001
99c779
From: Jack Miller <jack@codezen.org>
99c779
Date: Thu, 20 Oct 2016 16:43:22 +0530
99c779
Subject: [PATCH 25/43] devtree: Add VPD info for BMC based IBM Power System
99c779
99c779
Power Systems supports various environment and various service
99c779
processor types (like IBM FSP, industry standard BMC, etc).
99c779
99c779
We have processor chip level VPD (part number, serial number etc)
99c779
and all cores under chip shares this information.
99c779
99c779
BMC based Power Systems provides chip VPD information under xscom
99c779
node. This patch adds support for adding VPD information for CPU
99c779
nodes on BMC based system.
99c779
99c779
Sample output:
99c779
     *-cpu:0
99c779
         description: POWER8 (raw), altivec supported
99c779
         product: 00UM003
99c779
         vendor: PROCESSOR
99c779
         physical id: 16
99c779
         bus info: cpu@0
99c779
         version: 2.0 (pvr 004d 0200)
99c779
         serial: YA1932579651
99c779
         size: 2061MHz
99c779
         capacity: 3491MHz
99c779
         capabilities: performance-monitor cpufreq
99c779
         configuration: threads=8
99c779
99c779
Signed-off-by: Jack Miller <jack@codezen.org>
99c779
[Reorganized code, updated description - Vasant]
99c779
Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
99c779
---
99c779
 src/core/device-tree.cc | 58 +++++++++++++++++++++++++++++++++++++++++++++++--
99c779
 1 file changed, 56 insertions(+), 2 deletions(-)
99c779
99c779
diff --git a/src/core/device-tree.cc b/src/core/device-tree.cc
99c779
index 16406fd..d61347b 100644
99c779
--- a/src/core/device-tree.cc
99c779
+++ b/src/core/device-tree.cc
99c779
@@ -443,16 +443,19 @@ static void scan_chip_vpd(map <uint32_t, chip_vpd_data *> & vpd)
99c779
 
99c779
 
99c779
 static void fill_core_vpd(hwNode & cpu, string & basepath,
99c779
-			  map <uint32_t, chip_vpd_data *> & chip_vpd)
99c779
+			  map <uint32_t, chip_vpd_data *> & chip_vpd,
99c779
+			  map <uint32_t, string> & xscoms)
99c779
 {
99c779
   uint32_t chip_id;
99c779
   chip_vpd_data *data;
99c779
+  string xscom_path;
99c779
 
99c779
   if (!exists(basepath + "/ibm,chip-id"))
99c779
     return;
99c779
 
99c779
   chip_id = get_u32(basepath + "/ibm,chip-id");
99c779
   data = chip_vpd[chip_id];
99c779
+  xscom_path = xscoms[chip_id];
99c779
 
99c779
   if (data)
99c779
   {
99c779
@@ -460,6 +463,25 @@ static void fill_core_vpd(hwNode & cpu, string & basepath,
99c779
     cpu.setSerial(data->serial);
99c779
     cpu.setSlot(data->slot);
99c779
   }
99c779
+
99c779
+  if (xscom_path != "")
99c779
+  {
99c779
+    vector <string> board_pieces;
99c779
+
99c779
+    splitlines(hw::strip(get_string(xscom_path + "/board-info")),
99c779
+	       board_pieces, ' ');
99c779
+    if (board_pieces.size() > 0)
99c779
+      cpu.setVendor(board_pieces[0]);
99c779
+
99c779
+    if (exists(xscom_path + "/serial-number"))
99c779
+      cpu.setSerial(hw::strip(get_string(xscom_path + "/serial-number")));
99c779
+
99c779
+    if (exists(xscom_path + "/ibm,slot-location-code"))
99c779
+      cpu.setSlot(hw::strip(get_string(xscom_path + "/ibm,slot-location-code")));
99c779
+
99c779
+    if (exists(xscom_path + "/part-number"))
99c779
+      cpu.setProduct(hw::strip(get_string(xscom_path + "/part-number")));
99c779
+  }
99c779
 }
99c779
 
99c779
 static void set_cpu_config_threads(hwNode & cpu, const string & basepath)
99c779
@@ -488,6 +510,34 @@ static void set_cpu_config_threads(hwNode & cpu, const string & basepath)
99c779
 }
99c779
 
99c779
 
99c779
+static void scan_xscom_node(map <uint32_t, string> & xscoms)
99c779
+{
99c779
+  int n;
99c779
+  struct dirent **namelist;
99c779
+
99c779
+  pushd(DEVICETREE);
99c779
+  n = scandir(".", &namelist, selectdir, alphasort);
99c779
+  popd();
99c779
+
99c779
+  if (n <= 0)
99c779
+    return;
99c779
+
99c779
+  for (int i = 0; i < n; i++) {
99c779
+    string sname = string(namelist[i]->d_name);
99c779
+    string fullpath = "";
99c779
+    int chip_id = 0;
99c779
+
99c779
+    if (sname.substr(0,5) == "xscom") {
99c779
+      fullpath = string(DEVICETREE) + "/" + sname;
99c779
+      chip_id = get_u32(fullpath + "/ibm,chip-id");
99c779
+      xscoms.insert(std::pair<uint32_t, string>(chip_id, fullpath));
99c779
+    }
99c779
+
99c779
+    free(namelist[i]);
99c779
+  }
99c779
+  free(namelist);
99c779
+}
99c779
+
99c779
 static void scan_devtree_cpu_power(hwNode & core)
99c779
 {
99c779
   int n;
99c779
@@ -496,6 +546,7 @@ static void scan_devtree_cpu_power(hwNode & core)
99c779
   map <uint32_t, pair<uint32_t, vector <hwNode> > > l2_caches;
99c779
   map <uint32_t, vector <hwNode> > l3_caches;
99c779
   map <uint32_t, chip_vpd_data *> chip_vpd;
99c779
+  map <uint32_t, string> xscoms;
99c779
 
99c779
   pushd(DEVICETREE "/cpus");
99c779
   n = scandir(".", &namelist, selectdir, alphasort);
99c779
@@ -578,6 +629,9 @@ static void scan_devtree_cpu_power(hwNode & core)
99c779
    */
99c779
   scan_chip_vpd(chip_vpd);
99c779
 
99c779
+  // List all xscom nodes under DT
99c779
+  scan_xscom_node(xscoms);
99c779
+
99c779
   for (int i = 0; i < n; i++) //second and final pass
99c779
   {
99c779
     uint32_t l2_key = 0;
99c779
@@ -608,7 +662,7 @@ static void scan_devtree_cpu_power(hwNode & core)
99c779
     if (version != 0)
99c779
       cpu.setVersion(tostring(version));
99c779
 
99c779
-    fill_core_vpd(cpu, basepath, chip_vpd);
99c779
+    fill_core_vpd(cpu, basepath, chip_vpd, xscoms);
99c779
 
99c779
     if (hw::strip(get_string(basepath + "/status")) != "okay")
99c779
       cpu.disable();
99c779
-- 
99c779
2.10.2
99c779