Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Dale B Stimson <dale.b.stimson@intel.com>
To: igt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org
Subject: [Intel-gfx] [RFC i-g-t] lib/i915/gem_mmio_base.c - add support for mmio_base via sysfs
Date: Fri, 14 Feb 2020 18:34:21 -0800	[thread overview]
Message-ID: <20200215023421.41563-1-dale.b.stimson@intel.com> (raw)

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

                 reply	other threads:[~2020-02-15  2:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200215023421.41563-1-dale.b.stimson@intel.com \
    --to=dale.b.stimson@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox