summaryrefslogtreecommitdiff
path: root/lib/drmtest.c
diff options
context:
space:
mode:
authorMicah Fedke <micah.fedke@collabora.co.uk>2015-07-22 21:42:51 +0000
committerThomas Wood <thomas.wood@intel.com>2015-09-11 14:39:43 +0100
commite2241805a43e2cbd5287010e90005542845b48cd (patch)
tree0e1492fb642bcf904d1a55dfd2607f256390ac91 /lib/drmtest.c
parent2bacd07eb3be30fd30ed4fa4645901683b1c6b09 (diff)
lib: adding drm_open_driver() interface
The drm_open_driver*() functions replace the drm_open_any*() functions and provide the same utility, but in a way that is platform agnostic, not intel-specific. This opens the path for adopting intel-gpu-tools to non-intel platforms. This commit renames the calls and adds the chipset parameter which can be used to restrict the opening to a specific hardware family. For example, drm_open_driver(DRIVER_INTEL) will only return a valid fd if an intel GPU is found on the system, along with performing intel-specific initialization stuff like gem_quiescent_gpu(), et al. If OPEN_ANY_GPU is specified, the first available drm device of any type will be opened. Other hardware type flags may be added in the future. The drm_open_any*() calls are retained as aliases of drm_open_driver*(OPEN_ANY_GPU) but will be removed in a subsequent patch. Signed-off-by: Micah Fedke <micah.fedke@collabora.co.uk> Signed-off-by: Thomas Wood <thomas.wood@intel.com>
Diffstat (limited to 'lib/drmtest.c')
-rw-r--r--lib/drmtest.c97
1 files changed, 61 insertions, 36 deletions
diff --git a/lib/drmtest.c b/lib/drmtest.c
index 46b6618a..f22e44ca 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -75,23 +75,32 @@
uint16_t __drm_device_id;
-static int is_i915_device(int fd)
+static int __get_drm_device_name(int fd, char *name)
{
drm_version_t version;
- char name[5] = "";
memset(&version, 0, sizeof(version));
version.name_len = 4;
version.name = name;
- if (drmIoctl(fd, DRM_IOCTL_VERSION, &version))
+ if (!drmIoctl(fd, DRM_IOCTL_VERSION, &version)){
return 0;
+ }
+
+ return -1;
+}
- return strcmp("i915", name) == 0;
+static bool is_i915_device(int fd)
+{
+ int ret;
+ char name[5] = "";
+
+ ret = __get_drm_device_name(fd, name);
+
+ return !ret && strcmp("i915", name) == 0;
}
-static int
-is_intel(int fd)
+static bool is_intel(int fd)
{
struct drm_i915_getparam gp;
int devid = 0;
@@ -101,13 +110,13 @@ is_intel(int fd)
gp.value = &devid;
if (ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp)))
- return 0;
+ return false;
if (!IS_INTEL(devid))
- return 0;
+ return false;
__drm_device_id = devid;
- return 1;
+ return true;
}
static void check_stop_rings(void)
@@ -230,19 +239,31 @@ int drm_get_card(void)
return -1;
}
-/** Open the first DRM device we can find, searching up to 16 device nodes */
-int __drm_open_any(void)
+/**
+ * __drm_open_driver:
+ *
+ * Open the first DRM device we can find, searching up to 16 device nodes
+ *
+ * @chipset: OR'd flags for each chipset to search, eg. DRIVER_INTEL
+ *
+ * Returns:
+ * An open DRM fd or -1 on error
+ */
+int __drm_open_driver(int chipset)
{
for (int i = 0; i < 16; i++) {
char name[80];
int fd;
+ bool found_intel;
sprintf(name, "/dev/dri/card%u", i);
fd = open(name, O_RDWR);
if (fd == -1)
continue;
- if (is_i915_device(fd) && is_intel(fd))
+ found_intel = is_i915_device(fd) && is_intel(fd) && (chipset & DRIVER_INTEL);
+
+ if ((chipset & DRIVER_ANY) || found_intel)
return fd;
close(fd);
@@ -252,7 +273,7 @@ int __drm_open_any(void)
return -1;
}
-static int __drm_open_any_render(void)
+static int __drm_open_driver_render(int chipset)
{
char *name;
int i, fd;
@@ -307,41 +328,43 @@ static void quiescent_gpu_at_exit_render(int sig)
}
/**
- * drm_open_any:
+ * drm_open_driver:
*
- * Open an i915 drm legacy device node. This function always returns a valid
+ * Open a drm legacy device node. This function always returns a valid
* file descriptor.
*
- * Returns: a i915 drm file descriptor
+ * Returns: a drm file descriptor
*/
-int drm_open_any(void)
+int drm_open_driver(int chipset)
{
static int open_count;
- int fd = __drm_open_any();
+ int fd = __drm_open_driver(chipset);
igt_require(fd >= 0);
if (__sync_fetch_and_add(&open_count, 1))
return fd;
- gem_quiescent_gpu(fd);
- at_exit_drm_fd = __drm_open_any();
- igt_install_exit_handler(quiescent_gpu_at_exit);
+ if(chipset & DRIVER_INTEL){
+ gem_quiescent_gpu(fd);
+ igt_install_exit_handler(quiescent_gpu_at_exit);
+ }
+ at_exit_drm_fd = __drm_open_driver(chipset);
return fd;
}
/**
- * drm_open_any_master:
+ * drm_open_driver_master:
*
- * Open an i915 drm legacy device node and ensure that it is drm master.
+ * Open a drm legacy device node and ensure that it is drm master.
*
* Returns:
- * The i915 drm file descriptor or -1 on error
+ * The drm file descriptor or -1 on error
*/
-int drm_open_any_master(void)
+int drm_open_driver_master(int chipset)
{
- int fd = drm_open_any();
+ int fd = drm_open_driver(chipset);
igt_require(fd >= 0);
igt_require_f(drmSetMaster(fd) == 0, "Can't become DRM master, "
@@ -351,28 +374,30 @@ int drm_open_any_master(void)
}
/**
- * drm_open_any_render:
+ * drm_open_driver_render:
*
- * Open an i915 drm render device node.
+ * Open a drm render device node.
*
* Returns:
- * The i915 drm file descriptor or -1 on error
+ * The drm file descriptor or -1 on error
*/
-int drm_open_any_render(void)
+int drm_open_driver_render(int chipset)
{
static int open_count;
- int fd = __drm_open_any_render();
+ int fd = __drm_open_driver_render(chipset);
- /* no render nodes, fallback to drm_open_any() */
+ /* no render nodes, fallback to drm_open_driver() */
if (fd == -1)
- return drm_open_any();
+ return drm_open_driver(chipset);
if (__sync_fetch_and_add(&open_count, 1))
return fd;
- at_exit_drm_render_fd = __drm_open_any();
- gem_quiescent_gpu(fd);
- igt_install_exit_handler(quiescent_gpu_at_exit_render);
+ at_exit_drm_render_fd = __drm_open_driver(chipset);
+ if(chipset & DRIVER_INTEL){
+ gem_quiescent_gpu(fd);
+ igt_install_exit_handler(quiescent_gpu_at_exit_render);
+ }
return fd;
}