Blame SOURCES/0038-devtree-Report-memory-info-for-BMC-based-Power-Syste.patch

21ef37
From f1cd42c0c6f434e15ba322970cfa4519ee1f523d Mon Sep 17 00:00:00 2001
21ef37
From: Jack Miller <jack@codezen.org>
21ef37
Date: Tue, 16 Aug 2016 15:08:51 -0500
21ef37
Subject: [PATCH 38/43] devtree: Report memory info for BMC based Power System
21ef37
21ef37
Some variants of Power System (BMC service processor system) device tree
21ef37
contains SPD information. Also it has memory-buffer representation in
21ef37
device tree.
21ef37
21ef37
This patch adds support to display memory information on this system.
21ef37
21ef37
Sample output;
21ef37
        *-bank:1
21ef37
             description: RDIMM DDR3 1600 MHz (0.6ns)
21ef37
             product: HMT42GR7BFR4A-PB
21ef37
             vendor: Hynix Semiconductor (Hyundai Electronics)
21ef37
             physical id: 1
21ef37
             version: 5438,15 33,01
21ef37
             serial: 0x10c0af2c
21ef37
             slot: Physical:/Sys0/Node0/DIMM11
21ef37
             size: 16GiB
21ef37
             clock: 1333MHz (0.8ns)
21ef37
             capabilities: ecc spd-1.3
21ef37
             configuration: errordetection=ecc
21ef37
21ef37
Signed-off-by: Jack Miller <jack@codezen.org>
21ef37
[Updated description, fixed minor issues - Vasant]
21ef37
Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
21ef37
---
21ef37
 src/core/device-tree.cc | 71 +++++++++++++++++++++++++++++++++++++++++++++----
21ef37
 1 file changed, 66 insertions(+), 5 deletions(-)
21ef37
21ef37
diff --git a/src/core/device-tree.cc b/src/core/device-tree.cc
21ef37
index 41034e5..b7d0d57 100644
21ef37
--- a/src/core/device-tree.cc
21ef37
+++ b/src/core/device-tree.cc
21ef37
@@ -753,6 +753,57 @@ static void scan_devtree_cpu_power(hwNode & core)
21ef37
     delete it->second;
21ef37
 }
21ef37
 
21ef37
+static bool add_memory_bank_mba_dimm(string path,
21ef37
+				     unsigned long serial, hwNode & bank)
21ef37
+{
21ef37
+  bool found = false;
21ef37
+  int n;
21ef37
+  struct dirent **namelist;
21ef37
+
21ef37
+  pushd(path);
21ef37
+  n = scandir(".", &namelist, selectdir, alphasort);
21ef37
+  popd();
21ef37
+
21ef37
+  if (n < 0)
21ef37
+    return found;
21ef37
+
21ef37
+  for (int i = 0; i < n; i++)
21ef37
+  {
21ef37
+    string sname = string(namelist[i]->d_name);
21ef37
+    string fullpath = path + "/" + sname;
21ef37
+
21ef37
+    if (found)
21ef37
+    {
21ef37
+      free(namelist[i]);
21ef37
+      continue;
21ef37
+    }
21ef37
+
21ef37
+    if (sname.substr(0, 13) == "memory-buffer")
21ef37
+    {
21ef37
+      if (exists(fullpath + "/frequency-mhz"))
21ef37
+      {
21ef37
+        int hz = get_u32(fullpath + "/frequency-mhz") * 1000000;
21ef37
+        bank.setClock(hz);
21ef37
+      }
21ef37
+      found = add_memory_bank_mba_dimm(fullpath, serial, bank);
21ef37
+    } else if (sname.substr(0, 3) == "mba") {
21ef37
+      found = add_memory_bank_mba_dimm(fullpath, serial, bank);
21ef37
+    } else if ((sname.substr(0, 4) == "dimm") &&
21ef37
+	       (get_u32(fullpath + "/serial-number") == serial)) {
21ef37
+      vector < reg_entry > regs = get_reg_property(fullpath);
21ef37
+      bank.setSize(regs[0].size);
21ef37
+
21ef37
+      bank.setSlot(hw::strip(get_string(fullpath + "/ibm,slot-location-code")));
21ef37
+      found = true;
21ef37
+    }
21ef37
+    free(namelist[i]);
21ef37
+  }
21ef37
+
21ef37
+  free(namelist);
21ef37
+  return found;
21ef37
+}
21ef37
+
21ef37
+
21ef37
 static void add_memory_bank_spd(string path, hwNode & bank)
21ef37
 {
21ef37
   char dimmversion[20];
21ef37
@@ -885,6 +936,8 @@ static void add_memory_bank_spd(string path, hwNode & bank)
21ef37
   snprintf(buff, sizeof(buff), "0x%lx", serial);
21ef37
   bank.setSerial(buff);
21ef37
 
21ef37
+  add_memory_bank_mba_dimm(DEVICETREE, serial, bank);
21ef37
+
21ef37
   snprintf(buff, sizeof(buff), "spd-%d.%d", (version & 0xF0) >> 4, version & 0x0F);
21ef37
   bank.addCapability(buff);
21ef37
 }
21ef37
@@ -895,18 +948,17 @@ static void add_memory_bank(string name, string path, hwNode & core)
21ef37
   string product;
21ef37
   int n;
21ef37
 
21ef37
+  hwNode *memory = core.getChild("memory");
21ef37
+  if(!memory)
21ef37
+    memory = core.addChild(hwNode("memory", hw::memory));
21ef37
+
21ef37
   pushd(path + name);
21ef37
   if(name.substr(0, 7) == "ms-dimm")
21ef37
   {
21ef37
-    hwNode *memory = core.getChild("memory");
21ef37
-
21ef37
     hwNode bank("bank", hw::memory);
21ef37
     bank.claim(true);
21ef37
     bank.addHint("icon", string("memory"));
21ef37
 
21ef37
-    if(!memory)
21ef37
-      memory = core.addChild(hwNode("memory", hw::memory));
21ef37
-
21ef37
     if(exists("serial-number"))
21ef37
       bank.setSerial(hw::strip(get_string("serial-number")));
21ef37
 
21ef37
@@ -926,6 +978,15 @@ static void add_memory_bank(string name, string path, hwNode & core)
21ef37
       bank.setSize(size*1024*1024);
21ef37
 
21ef37
     memory->addChild(bank);
21ef37
+  } else if(name.substr(0, 4) == "dimm") {
21ef37
+    hwNode bank("bank", hw::memory);
21ef37
+    bank.claim(true);
21ef37
+    bank.addHint("icon", string("memory"));
21ef37
+
21ef37
+    // Parse Memory SPD data
21ef37
+    add_memory_bank_spd(path + name + "/spd", bank);
21ef37
+
21ef37
+    memory->addChild(bank);
21ef37
   }
21ef37
 
21ef37
   n = scandir(".", &dirlist, selectdir, alphasort);
21ef37
-- 
21ef37
2.10.2
21ef37