@@ -74,6 +74,7 @@ libutil_a_SOURCES = \
util/wrapper.c \
util/filter.c \
util/bitmap.c \
- util/abspath.c
+ util/abspath.c \
+ util/iomem.c
nobase_include_HEADERS = daxctl/libdaxctl.h
@@ -9,6 +9,8 @@ lib_LTLIBRARIES = libdaxctl.la
libdaxctl_la_SOURCES =\
../libdaxctl.h \
libdaxctl-private.h \
+ ../../util/iomem.c \
+ ../../util/iomem.h \
../../util/sysfs.c \
../../util/sysfs.h \
../../util/log.c \
@@ -65,6 +65,7 @@ struct daxctl_dev {
size_t buf_len;
char *dev_path;
struct list_node list;
+ unsigned long long resource;
unsigned long long size;
struct kmod_module *module;
struct kmod_list *kmod_list;
@@ -24,6 +24,7 @@
#include <util/log.h>
#include <util/sysfs.h>
+#include <util/iomem.h>
#include <daxctl/libdaxctl.h>
#include "libdaxctl-private.h"
@@ -369,6 +370,12 @@ static void *add_dax_dev(void *parent, int id, const char *daxdev_base)
dev->major = major(st.st_rdev);
dev->minor = minor(st.st_rdev);
+ sprintf(path, "%s/resource", daxdev_base);
+ if (sysfs_read_attr(ctx, path, buf) == 0)
+ dev->resource = strtoull(buf, NULL, 0);
+ else
+ dev->resource = iomem_get_dev_resource(ctx, daxdev_base);
+
sprintf(path, "%s/size", daxdev_base);
if (sysfs_read_attr(ctx, path, buf) < 0)
goto err_read;
@@ -878,6 +885,11 @@ DAXCTL_EXPORT int daxctl_dev_get_minor(struct daxctl_dev *dev)
return dev->minor;
}
+DAXCTL_EXPORT unsigned long long daxctl_dev_get_resource(struct daxctl_dev *dev)
+{
+ return dev->resource;
+}
+
DAXCTL_EXPORT unsigned long long daxctl_dev_get_size(struct daxctl_dev *dev)
{
return dev->size;
@@ -58,4 +58,5 @@ global:
daxctl_dev_disable;
daxctl_dev_enable_devdax;
daxctl_dev_enable_ram;
+ daxctl_dev_get_resource;
} LIBDAXCTL_5;
@@ -66,6 +66,7 @@ int daxctl_dev_get_id(struct daxctl_dev *dev);
const char *daxctl_dev_get_devname(struct daxctl_dev *dev);
int daxctl_dev_get_major(struct daxctl_dev *dev);
int daxctl_dev_get_minor(struct daxctl_dev *dev);
+unsigned long long daxctl_dev_get_resource(struct daxctl_dev *dev);
unsigned long long daxctl_dev_get_size(struct daxctl_dev *dev);
struct daxctl_ctx *daxctl_dev_get_ctx(struct daxctl_dev *dev);
int daxctl_dev_is_enabled(struct daxctl_dev *dev);
new file mode 100644
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright(c) 2019 Intel Corporation. All rights reserved. */
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <util/log.h>
+#include <util/iomem.h>
+#include <util/sysfs.h>
+
+unsigned long long __iomem_get_dev_resource(struct log_ctx *ctx,
+ const char *devpath)
+{
+ const char *devname = devpath_to_devname(devpath);
+ FILE *fp = fopen("/proc/iomem", "r");
+ unsigned long long res;
+ char name[256];
+
+ if (fp == NULL) {
+ log_err(ctx, "%s: open /proc/iomem: %s\n", devname,
+ strerror(errno));
+ return 0;
+ }
+
+ while (fscanf(fp, "%llx-%*x : %254[^\n]\n", &res, name) == 2) {
+ if (strcmp(name, devname) == 0) {
+ log_dbg(ctx, "%s: got resource via iomem: %#llx\n",
+ devname, res);
+ fclose(fp);
+ return res;
+ }
+ }
+
+ log_dbg(ctx, "%s: not found in iomem\n", devname);
+ fclose(fp);
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright(c) 2019 Intel Corporation. All rights reserved. */
+#ifndef _NDCTL_IOMEM_H_
+#define _NDCTL_IOMEM_H_
+
+struct log_ctx;
+unsigned long long __iomem_get_dev_resource(struct log_ctx *ctx,
+ const char *path);
+
+#define iomem_get_dev_resource(c, p) __iomem_get_dev_resource(&(c)->ctx, (p))
+
+#endif /* _NDCTL_IOMEM_H_ */