From: "Michał Winiarski" <michal.winiarski@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t 2/6] lib/igt_device: Introduce igt_device_get_card_index
Date: Wed, 13 Mar 2019 13:53:28 +0100 [thread overview]
Message-ID: <20190313125332.12471-3-michal.winiarski@intel.com> (raw)
In-Reply-To: <20190313125332.12471-1-michal.winiarski@intel.com>
And use it! But let's start small.
Rather than going with "and by the way, here's the card index" from
igt_sysfs_path, we're making things more explicit.
Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
---
lib/igt_device.c | 19 +++++++++++++++++++
lib/igt_device.h | 2 ++
lib/igt_sysfs.c | 11 +++++++----
lib/igt_sysfs.h | 2 +-
tests/i915/i915_pm_rpm.c | 2 +-
5 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/lib/igt_device.c b/lib/igt_device.c
index 5b3722c8..08f39c8b 100644
--- a/lib/igt_device.c
+++ b/lib/igt_device.c
@@ -22,6 +22,8 @@
*
*/
+#include <sys/stat.h>
+#include <sys/sysmacros.h>
#include "igt.h"
#include "igt_device.h"
@@ -84,3 +86,20 @@ void igt_device_drop_master(int fd)
"Failed to drop DRM master.\n");
}
}
+
+/**
+ * igt_device_get_card_index:
+ * @fd: the device
+ *
+ * Returns:
+ * Index (N) of /dev/dri/cardN or /dev/dri/renderDN corresponding with fd.
+ *
+ */
+int igt_device_get_card_index(int fd)
+{
+ struct stat st;
+
+ igt_fail_on(fstat(fd, &st) || !S_ISCHR(st.st_mode));
+
+ return minor(st.st_rdev);
+}
diff --git a/lib/igt_device.h b/lib/igt_device.h
index 2995f969..9d7dc2c3 100644
--- a/lib/igt_device.h
+++ b/lib/igt_device.h
@@ -31,4 +31,6 @@ void igt_device_set_master(int fd);
int __igt_device_drop_master(int fd);
void igt_device_drop_master(int fd);
+int igt_device_get_card_index(int fd);
+
#endif /* __IGT_DEVICE_H__ */
diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index c57e4ae2..fd075cd6 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -41,6 +41,7 @@
#include "igt_core.h"
#include "igt_sysfs.h"
+#include "igt_device.h"
/**
* SECTION:igt_sysfs
@@ -96,7 +97,7 @@ static int writeN(int fd, const char *buf, int len)
* Returns:
* The directory path, or NULL on failure.
*/
-char *igt_sysfs_path(int device, char *path, int pathlen, int *idx)
+char *igt_sysfs_path(int device, char *path, int pathlen)
{
struct stat st;
@@ -125,8 +126,7 @@ char *igt_sysfs_path(int device, char *path, int pathlen, int *idx)
continue;
path[len] = '\0';
- if (idx)
- *idx = n;
+
return path;
}
@@ -148,9 +148,12 @@ int igt_sysfs_open(int device, int *idx)
{
char path[80];
- if (!igt_sysfs_path(device, path, sizeof(path), idx))
+ if (!igt_sysfs_path(device, path, sizeof(path)))
return -1;
+ if (idx)
+ *idx = igt_device_get_card_index(device);
+
return open(path, O_RDONLY);
}
diff --git a/lib/igt_sysfs.h b/lib/igt_sysfs.h
index 2ce5b7bd..b181a95f 100644
--- a/lib/igt_sysfs.h
+++ b/lib/igt_sysfs.h
@@ -28,7 +28,7 @@
#include <stdbool.h>
#include <stdarg.h>
-char *igt_sysfs_path(int device, char *path, int pathlen, int *idx);
+char *igt_sysfs_path(int device, char *path, int pathlen);
int igt_sysfs_open(int device, int *idx);
int igt_sysfs_open_parameters(int device);
bool igt_sysfs_set_parameter(int device,
diff --git a/tests/i915/i915_pm_rpm.c b/tests/i915/i915_pm_rpm.c
index 759c76ea..03de609c 100644
--- a/tests/i915/i915_pm_rpm.c
+++ b/tests/i915/i915_pm_rpm.c
@@ -962,7 +962,7 @@ static void sysfs_read_subtest(void)
{
char path[80];
- igt_require_f(igt_sysfs_path(drm_fd, path, sizeof(path), NULL),
+ igt_require_f(igt_sysfs_path(drm_fd, path, sizeof(path)),
"Can't find the sysfs directory\n");
walk_fs(path);
}
--
2.20.1
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
next prev parent reply other threads:[~2019-03-13 12:55 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-13 12:53 [igt-dev] [PATCH i-g-t 0/6] Attempt to get rid of some globals Michał Winiarski
2019-03-13 12:53 ` [igt-dev] [PATCH i-g-t 1/6] tests/gem_exec_blt: Drop benchmark mode, use igt_sysfs Michał Winiarski
2019-03-13 12:58 ` Chris Wilson
2019-03-13 12:53 ` Michał Winiarski [this message]
2019-03-13 13:02 ` [igt-dev] [PATCH i-g-t 2/6] lib/igt_device: Introduce igt_device_get_card_index Chris Wilson
2019-03-13 12:53 ` [igt-dev] [PATCH i-g-t 3/6] lib: Kill drm_get_card() Michał Winiarski
2019-03-13 13:05 ` Chris Wilson
2019-03-13 12:53 ` [igt-dev] [PATCH i-g-t 4/6] lib/igt_sysfs: Remove idx from sysfs_open Michał Winiarski
2019-03-13 13:08 ` Chris Wilson
2019-03-13 12:53 ` [igt-dev] [PATCH i-g-t 5/6] lib/igt_sysfs: Simplify obtaining sysfs path Michał Winiarski
2019-03-13 14:09 ` Chris Wilson
2019-03-13 12:53 ` [igt-dev] [PATCH i-g-t 6/6] lib/igt_device: Move intel_get_pci_device under igt_device Michał Winiarski
2019-03-13 14:27 ` Chris Wilson
2019-03-13 14:06 ` [igt-dev] ✓ Fi.CI.BAT: success for Attempt to get rid of some globals Patchwork
2019-03-13 18:07 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
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=20190313125332.12471-3-michal.winiarski@intel.com \
--to=michal.winiarski@intel.com \
--cc=igt-dev@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