intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [Intel-gfx] [RFC i-g-t] lib/i915/gem_mmio_base.c - add support for mmio_base via sysfs
@ 2020-02-15  2:34 Dale B Stimson
  0 siblings, 0 replies; only message in thread
From: Dale B Stimson @ 2020-02-15  2:34 UTC (permalink / raw)
  To: igt-dev, intel-gfx

Obtaining mmio_base info via sysfs (if available).  This is in addition
to the already existing support for obtaining that data via debugfs.
The use of sysfs data is preferred.

This patch depends upon the following proposed IGT patch, which is not
presently merged:
  i915/gem_mmio_base.c - get mmio_base from debugfs (if possible)

The availability of sysfs info for mmio_base depends on the presence of
these two proposed kernel patches, not presently merged:
  drm/i915/gt: Expose engine properties via sysfs
  drm/i915/gt: Expose engine->mmio_base via sysfs

Signed-off-by: Dale B Stimson <dale.b.stimson@intel.com>
---
 lib/i915/gem_mmio_base.c | 79 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)

diff --git a/lib/i915/gem_mmio_base.c b/lib/i915/gem_mmio_base.c
index 514f87f42..8a29a9150 100644
--- a/lib/i915/gem_mmio_base.c
+++ b/lib/i915/gem_mmio_base.c
@@ -5,8 +5,11 @@
 #include <ctype.h>
 
 #include <fcntl.h>
+#include <sys/types.h>
+#include <dirent.h>
 
 #include "igt.h"
+#include "igt_sysfs.h"
 
 struct eng_mmio_base_s {
 	char       name[8];
@@ -102,6 +105,82 @@ static struct eng_mmio_base_table_s *_gem_engine_mmio_base_info_get_legacy(int f
 	return mbp;
 }
 
+static struct eng_mmio_base_table_s *_gem_engine_mmio_base_info_get_sysfs(int fd_dev)
+{
+	struct eng_mmio_base_table_s mbt;
+	struct eng_mmio_base_table_s *mbp = NULL;
+	const size_t name_max = sizeof(mbt.mb_tab[0].name);
+	int fd_top = -1;
+	int fd_engines = -1;
+	int fd_this;
+	int fd_mmio_base;
+	DIR *dirp = NULL;
+	struct dirent *pde;
+	const char *eng_name;
+	ssize_t nb;
+	char rbuf[32];
+	unsigned long int ulv;
+	uint32_t uiv;
+
+	memset(&mbt, 0, sizeof(mbt));
+
+	fd_top = igt_sysfs_open(fd_dev);
+	if (fd_top < 0)
+		goto mbsf_cleanup;
+
+	fd_engines = openat(fd_top, "engine", O_RDONLY);
+	if (fd_engines < 0)
+		goto mbsf_cleanup;
+
+	dirp = fdopendir(fd_engines);
+	if (!dirp)
+		goto mbsf_cleanup;
+
+	for (;;) {
+		pde = readdir(dirp);
+		if (!pde)
+			break;
+
+		if ((pde->d_type == DT_DIR) || (pde->d_type == DT_UNKNOWN)) {
+			eng_name = pde->d_name;
+			if (eng_name[0] == '.')
+				continue;
+			fd_this = openat(fd_engines, eng_name, O_RDONLY);
+			if (fd_this < 0)
+				continue;
+			fd_mmio_base = openat(fd_this, "mmio_base", O_RDONLY);
+			close(fd_this);
+			if (fd_mmio_base < 0)
+				goto mbsf_cleanup;
+			nb = read(fd_mmio_base, rbuf, sizeof(rbuf));
+			close(fd_mmio_base);
+			if (nb > 0) {
+				ulv = strtoul(rbuf, NULL, 16);
+				uiv = (uint32_t) ulv;
+
+				strncpy(mbt.mb_tab[mbt.mb_cnt].name,
+					eng_name, name_max);
+				mbt.mb_tab[mbt.mb_cnt].mmio_base = uiv;
+				mbt.mb_cnt++;
+			}
+		}
+	}
+
+	if (mbt.mb_cnt > 0)
+		mbp = _gem_engine_mmio_info_dup(&mbt);
+
+mbsf_cleanup:
+	if (dirp)
+		closedir(dirp);
+
+	if (fd_engines >= 0)
+		close(fd_engines);
+	if (fd_top >= 0)
+		close(fd_top);
+
+	return mbp;
+}
+
 
 /**
  * _gem_engine_mmio_base_info_get_debugfs:
-- 
2.25.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-02-15  2:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-15  2:34 [Intel-gfx] [RFC i-g-t] lib/i915/gem_mmio_base.c - add support for mmio_base via sysfs Dale B Stimson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).