summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Vetter <daniel.vetter@ffwll.ch>2014-03-14 16:00:22 +0100
committerDaniel Vetter <daniel.vetter@ffwll.ch>2014-03-14 16:00:22 +0100
commitea18fc16cd88a31b5d390721ad103efa07e288f1 (patch)
tree6ba621b91b8759e17a9537d90a1d8ad590bad7ae /lib
parent553d594b6efd117497791e708146588268c992a9 (diff)
lib: extract igt_open_forcewake_handle
... and I immediately regret that I've killed the return value for igt_debugfs_init, since we have callers which need to work without the forcewake stuff, e.g. the reg dumper needs to work without i915 loaded. Put this new helper to good use in the mmio code and the pm_pc8 testcase. Cc: Paulo Zanoni <paulo.r.zanoni@intel.com> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Diffstat (limited to 'lib')
-rw-r--r--lib/igt_debugfs.c45
-rw-r--r--lib/igt_debugfs.h1
-rw-r--r--lib/intel_mmio.c52
3 files changed, 42 insertions, 56 deletions
diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index 5c029019..79b2618b 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -76,13 +76,7 @@
* General debugfs helpers
*/
-/**
- * igt_debugfs_init:
- * @debugfs: debugfs access structure to initialize
- *
- * Initializes the debugfs access helper library.
- */
-void igt_debugfs_init(igt_debugfs_t *debugfs)
+static bool __igt_debugfs_init(igt_debugfs_t *debugfs)
{
const char *path = "/sys/kernel/debug";
struct stat st;
@@ -107,13 +101,24 @@ find_minor:
sprintf(debugfs->dri_path + len, "/i915_error_state");
if (stat(debugfs->dri_path, &st) == 0) {
debugfs->dri_path[len] = '\0';
- return;
+ return true;
}
}
debugfs->dri_path[0] = '\0';
- igt_fail(4);
+ return false;
+}
+
+/**
+ * igt_debugfs_init:
+ * @debugfs: debugfs access structure to initialize
+ *
+ * Initializes the debugfs access helper library.
+ */
+void igt_debugfs_init(igt_debugfs_t *debugfs)
+{
+ igt_assert(__igt_debugfs_init(debugfs));
}
/**
@@ -578,3 +583,25 @@ void igt_enable_prefault(void)
{
igt_prefault_control(true);
}
+
+/**
+ * igt_open_forcewake_handle:
+ *
+ * This functions opens the debugfs forcewake file and so prevents the GT from
+ * suspending. The reference is automatically dropped when the is closed.
+ *
+ * Returns: The file descriptor of the forcewake handle or -1 if that didn't
+ * work out.
+ */
+int igt_open_forcewake_handle(void)
+{
+ igt_debugfs_t debugfs;
+ int fd;
+
+ if (!__igt_debugfs_init(&debugfs))
+ return -1;
+
+ fd = igt_debugfs_open(&debugfs, "i915_forcewake_user", O_WRONLY);
+
+ return fd;
+}
diff --git a/lib/igt_debugfs.h b/lib/igt_debugfs.h
index 90e31d70..5e153b17 100644
--- a/lib/igt_debugfs.h
+++ b/lib/igt_debugfs.h
@@ -154,5 +154,6 @@ void igt_drop_caches_set(uint64_t val);
void igt_disable_prefault(void);
void igt_enable_prefault(void);
+int igt_open_forcewake_handle(void);
#endif /* __IGT_DEBUGFS_H__ */
diff --git a/lib/intel_mmio.c b/lib/intel_mmio.c
index 930a44f8..22480098 100644
--- a/lib/intel_mmio.c
+++ b/lib/intel_mmio.c
@@ -42,6 +42,7 @@
#include <sys/mman.h>
#include "intel_gpu_tools.h"
+#include "igt_debugfs.h"
#define FAKEKEY 0x2468ace0
@@ -50,8 +51,6 @@ void *mmio;
static struct _mmio_data {
int inited;
bool safe;
- char debugfs_path[FILENAME_MAX];
- char debugfs_forcewake_path[FILENAME_MAX];
uint32_t i915_devid;
struct intel_register_map map;
int key;
@@ -113,42 +112,6 @@ intel_get_mmio(struct pci_device *pci_dev)
}
}
-/*
- * If successful, i915_debugfs_path and i915_debugfs_forcewake_path are both
- * updated with the correct path.
- */
-static int
-find_debugfs_path(const char *dri_base)
-{
- char buf[FILENAME_MAX];
- struct stat sb;
- int i, ret;
-
- for (i = 0; i < 16; i++) {
- snprintf(buf, FILENAME_MAX, "%s/%i/name", dri_base, i);
-
- snprintf(mmio_data.debugfs_path, FILENAME_MAX,
- "%s/%i/", dri_base, i);
- snprintf(mmio_data.debugfs_forcewake_path, FILENAME_MAX,
- "%s/%i/i915_forcewake_user", dri_base, i);
-
- ret = stat(mmio_data.debugfs_forcewake_path, &sb);
- if (ret) {
- mmio_data.debugfs_path[0] = 0;
- mmio_data.debugfs_forcewake_path[0] = 0;
- } else
- return 0;
- }
-
- return -1;
-}
-
-static int
-get_forcewake_lock(void)
-{
- return open(mmio_data.debugfs_forcewake_path, 0);
-}
-
static void
release_forcewake_lock(int fd)
{
@@ -184,16 +147,11 @@ intel_register_access_init(struct pci_device *pci_dev, int safe)
/* Find where the forcewake lock is. Forcewake doesn't exist
* gen < 6, but the debugfs should do the right things for us.
*/
- ret = find_debugfs_path("/sys/kernel/debug/dri");
- if (ret) {
- ret = find_debugfs_path("/debug/dri");
- if (ret) {
- fprintf(stderr, "Couldn't find path to dri/debugfs entry\n");
- fprintf(stderr, "warning: forcewake will not be handled\n");
- }
+ ret = igt_open_forcewake_handle();
+ if (ret == -1)
mmio_data.key = FAKEKEY;
- } else
- mmio_data.key = get_forcewake_lock();
+ else
+ mmio_data.key = ret;
mmio_data.inited++;
return 0;