summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics/inc
diff options
context:
space:
mode:
authorSimon Rettberg2022-08-01 17:02:06 +0200
committerSimon Rettberg2022-08-01 17:02:06 +0200
commit792fad14bab9ef3030201737f36268cab9a2dcef (patch)
treea23402773d3a7d83622ae45521a5a85c198e85dd /modules-available/statistics/inc
parent[remoteaccess] Don't uncheck currently disabled locations in group edit (diff)
downloadslx-admin-792fad14bab9ef3030201737f36268cab9a2dcef.tar.gz
slx-admin-792fad14bab9ef3030201737f36268cab9a2dcef.tar.xz
slx-admin-792fad14bab9ef3030201737f36268cab9a2dcef.zip
[statistics] Simplify SPD value interpretation now that I get it
Diffstat (limited to 'modules-available/statistics/inc')
-rw-r--r--modules-available/statistics/inc/hardwareparser.inc.php65
1 files changed, 26 insertions, 39 deletions
diff --git a/modules-available/statistics/inc/hardwareparser.inc.php b/modules-available/statistics/inc/hardwareparser.inc.php
index 0bad832f..5dd29e16 100644
--- a/modules-available/statistics/inc/hardwareparser.inc.php
+++ b/modules-available/statistics/inc/hardwareparser.inc.php
@@ -57,47 +57,20 @@ class HardwareParser
break;
}
if ($id !== 0) {
- static $data = false;
- if ($data === false) $data = json_decode(file_get_contents(dirname(__FILE__) . '/jedec.json'), true);
- if (array_key_exists('bank' . $bank, $data) && array_key_exists('id' . $id, $data['bank' . $bank]))
- return $data['bank' . $bank]['id' . $id];
+ $id = self::lookupJedec($bank, $id);
+ if ($id !== null)
+ return $id;
}
- } elseif (preg_match('/Unknown.{0,16}[\[(](?:0x)?([0-9a-fA-F]+)[\])]/', $string, $out)) {
- // Seems to be yet another encoding, from SPD, but somehow related to JEDEC too.
- // Saw this in two machines' dmidecode output, found the table you see here
- // at https://review.coreboot.org/plugins/gitiles/coreboot/+/HEAD/src/device/dram/spd.c
+ } elseif (preg_match('/Unknown.{0,16}[\[(](?:0x)?([0-9a-fA-F]{2,4})[\])]/', $string, $out)) {
+ // 16bit encoding from DDR3+: lower byte is number of 0x7f bytes, upper byte is id within bank
$id = hexdec($out[1]);
- switch ($id) {
- case 0x9b85:
- return "Crucial";
- case 0x4304:
- return "Ramaxel";
- case 0x4f01:
- return "Transcend";
- case 0x9801:
- return "Kingston";
- case 0x987f:
- case 0xad00:
- return "Hynix";
- case 0x9e02:
- return "Corsair";
- case 0xb004:
- return "OCZ";
- case 0xad80:
- return "Hynix/Hyundai";
- case 0x3486:
- return "Super Talent";
- case 0xcd04:
- return "GSkill";
- case 0xce80:
- case 0xce00:
- return "Samsung";
- case 0xfe02:
- return "Elpida";
- case 0x2c80:
- case 0x2c00:
- return "Micron";
- }
+ // Our bank counting starts at one. Also ignore parity bit.
+ $bank = ($id & 0x7f) + 1;
+ // Shift down id, get rid of parity bit
+ $id = ($id >> 8) & 0x7f;
+ $id = self::lookupJedec($bank, $id);
+ if ($id !== null)
+ return $id;
}
return $string;
}
@@ -756,4 +729,18 @@ class HardwareParser
return count($thisMachineHwIds);
}
+ /**
+ * @return ?string
+ */
+ private static function lookupJedec(int $bank, int $id)
+ {
+ static $data = false;
+ if ($data === false) {
+ $data = json_decode(file_get_contents(dirname(__FILE__) . '/jedec.json'), true);
+ }
+ if (array_key_exists('bank' . $bank, $data) && array_key_exists('id' . $id, $data['bank' . $bank]))
+ return $data['bank' . $bank]['id' . $id];
+ return null;
+ }
+
}