@@ -1619,6 +1619,53 @@ static int add_nfit_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
free(path);
return rc;
}
+static void populate_dimm_attributes(struct ndctl_dimm *dimm,
+ const char *dimm_base)
+{
+ char buf[SYSFS_ATTR_SIZE];
+ struct ndctl_ctx *ctx = dimm->bus->ctx;
+ char *path = calloc(1, strlen(dimm_base) + 100);
+
+ sprintf(path, "%s/phys_id", dimm_base);
+ if (sysfs_read_attr(ctx, path, buf) < 0)
+ goto err_read;
+ dimm->phys_id = strtoul(buf, NULL, 0);
+
+ sprintf(path, "%s/handle", dimm_base);
+ if (sysfs_read_attr(ctx, path, buf) < 0)
+ goto err_read;
+ dimm->handle = strtoul(buf, NULL, 0);
+
+ sprintf(path, "%s/vendor", dimm_base);
+ if (sysfs_read_attr(ctx, path, buf) == 0)
+ dimm->vendor_id = strtoul(buf, NULL, 0);
+
+ sprintf(path, "%s/id", dimm_base);
+ if (sysfs_read_attr(ctx, path, buf) == 0) {
+ unsigned int b[9];
+
+ dimm->unique_id = strdup(buf);
+ if (!dimm->unique_id)
+ goto err_read;
+ if (sscanf(dimm->unique_id, "%02x%02x-%02x-%02x%02x-%02x%02x%02x%02x",
+ &b[0], &b[1], &b[2], &b[3], &b[4],
+ &b[5], &b[6], &b[7], &b[8]) == 9) {
+ dimm->manufacturing_date = b[3] << 8 | b[4];
+ dimm->manufacturing_location = b[2];
+ }
+ }
+ sprintf(path, "%s/subsystem_vendor", dimm_base);
+ if (sysfs_read_attr(ctx, path, buf) == 0)
+ dimm->subsystem_vendor_id = strtoul(buf, NULL, 0);
+
+
+ sprintf(path, "%s/dirty_shutdown", dimm_base);
+ if (sysfs_read_attr(ctx, path, buf) == 0)
+ dimm->dirty_shutdown = strtoll(buf, NULL, 0);
+
+err_read:
+ free(path);
+}
static void *add_dimm(void *parent, int id, const char *dimm_base)
{
@@ -1694,6 +1741,10 @@ static void *add_dimm(void *parent, int id, const char *dimm_base)
} else
parse_dimm_flags(dimm, buf);
+ /* add the available dimm attributes, the platform can override or add
+ * additional attributes later */
+ populate_dimm_attributes(dimm, dimm_base);
+
/* Check if the given dimm supports nfit */
if (ndctl_bus_has_nfit(bus)) {
dimm->formats = formats;
Add attributes to generic dimms that are independent of platforms like the test dimms. Signed-off-by: Santosh Sivaraj <santosh@fossix.org> --- ndctl/lib/libndctl.c | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)