From: Lucas De Marchi <lucas.demarchi@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: "Ville Syrjälä" <ville.syrjala@linux.intel.com>,
"Matt Roper" <matthew.d.roper@intel.com>,
"Lucas De Marchi" <lucas.demarchi@intel.com>
Subject: [PATCH v2 3/5] lib/igt_gt: Add igt_open_forcewake_handle_for_pcidev()
Date: Mon, 23 Sep 2024 17:11:44 -0500 [thread overview]
Message-ID: <20240923221146.125848-4-lucas.demarchi@intel.com> (raw)
In-Reply-To: <20240923221146.125848-1-lucas.demarchi@intel.com>
In several places we are getting the pci_dev for an fd and then passing
both the pci_dev and the fd to intel_register_access_init(). Add a
helper so intel_register_access_init() can operate on pci_dev only.
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
---
lib/igt_gt.c | 37 +++++++++++++++++++++++++++++++++++++
lib/igt_gt.h | 3 +++
2 files changed, 40 insertions(+)
diff --git a/lib/igt_gt.c b/lib/igt_gt.c
index 0cc3ee131..c9fd9164f 100644
--- a/lib/igt_gt.c
+++ b/lib/igt_gt.c
@@ -30,6 +30,7 @@
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
+#include <pciaccess.h>
#include "drmtest.h"
#include "i915/gem.h"
@@ -514,6 +515,42 @@ int igt_open_forcewake_handle(int fd)
return igt_debugfs_open(fd, fn, O_RDONLY);
}
+int igt_open_forcewake_handle_for_pcidev(const struct pci_device *pci_dev)
+{
+ static const char *FORCEWAKE_FILES[] = {
+ "forcewake_all", "i915_forcewake_user",
+ NULL
+ };
+ const char *debugfs_root = igt_debugfs_mount(), **fn;
+ char path[PATH_MAX];
+ int dirlen, ret;
+
+ if (!debugfs_root)
+ return -ENOENT;
+
+ ret = snprintf(path, sizeof(path), "%s/dri/%04u:%02u:%02u.%u",
+ debugfs_root,
+ pci_dev->domain, pci_dev->bus, pci_dev->dev,
+ pci_dev->func);
+ if (ret < 0 || ret >= sizeof(path))
+ return -EINVAL;
+
+ dirlen = ret;
+ for (fn = FORCEWAKE_FILES; *fn; fn++) {
+ ret = snprintf(path + dirlen, sizeof(path) - dirlen,
+ "/%s", *fn);
+ if (ret < 0 || ret >= sizeof(path) - dirlen)
+ return -EINVAL;
+
+ ret = open(path, O_RDONLY);
+ if (ret >= 0 || errno != ENOENT)
+ return ret;
+ }
+
+ return -ENOENT;
+
+}
+
#if defined(__x86_64__) || defined(__i386__)
static unsigned int clflush_size;
diff --git a/lib/igt_gt.h b/lib/igt_gt.h
index d0c5510b1..4a67cd9f0 100644
--- a/lib/igt_gt.h
+++ b/lib/igt_gt.h
@@ -31,6 +31,8 @@
#include "i915/i915_drm_local.h"
#include "i915_drm.h"
+struct pci_device;
+
void igt_require_hang_ring(int fd, uint32_t ctx, int ring);
typedef struct igt_hang {
@@ -63,6 +65,7 @@ void igt_fork_hang_helper(void);
void igt_stop_hang_helper(void);
int igt_open_forcewake_handle(int fd);
+int igt_open_forcewake_handle_for_pcidev(const struct pci_device *pci_dev);
int igt_setup_clflush(void);
void igt_clflush_range(void *addr, int size);
--
2.46.1
next prev parent reply other threads:[~2024-09-23 22:12 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-23 22:11 [PATCH v2 0/5] Add forcewake support for xe Lucas De Marchi
2024-09-23 22:11 ` [PATCH v2 1/5] lib/igt_gt: Fix forcewake open Lucas De Marchi
2024-09-23 22:11 ` [PATCH v2 2/5] lib/igt_gt: Make igt_open_forcewake_handle() xe-compatible Lucas De Marchi
2024-09-23 22:11 ` Lucas De Marchi [this message]
2024-09-24 2:06 ` [PATCH v2 3/5] lib/igt_gt: Add igt_open_forcewake_handle_for_pcidev() Lucas De Marchi
2024-09-24 8:23 ` Ville Syrjälä
2024-09-23 22:11 ` [PATCH v2 4/5] treewide: Fix intel_register_access_init() Lucas De Marchi
2024-09-24 8:24 ` Ville Syrjälä
2024-09-23 22:11 ` [PATCH v2 5/5] lib/igt_gt: Stop passing fd == -1 in igt_open_forcewake_handle() Lucas De Marchi
2024-09-24 8:25 ` Ville Syrjälä
2024-09-24 14:08 ` Lucas De Marchi
2024-09-26 0:39 ` ✓ CI.xeBAT: success for Add forcewake support for xe (rev3) Patchwork
2024-09-26 0:52 ` ✓ Fi.CI.BAT: " Patchwork
2024-09-26 6:07 ` ✗ CI.xeFULL: failure " Patchwork
2024-09-26 9:36 ` ✗ Fi.CI.IGT: " 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=20240923221146.125848-4-lucas.demarchi@intel.com \
--to=lucas.demarchi@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=matthew.d.roper@intel.com \
--cc=ville.syrjala@linux.intel.com \
/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