[igt-dev] [PATCH i-g-t 3/3] lib: Use drm_get_param where it is applicable

Lukasz Kalamarz lukasz.kalamarz at intel.com
Fri Nov 23 14:27:26 UTC 2018


With usage of implemented drm_get_param helper function, we can
remove some duplicated code lines across few libs.

Signed-off-by: Lukasz Kalamarz <lukasz.kalamarz at intel.com>

Cc: Michal Winiarski <michal.winiarski at intel.com>
Cc: Katarzyna Dec <katarzyna.dec at intel.com>
Cc: Daniele Ceraolo Spurio <daniele.ceraolospurio at intel.com>
---
 lib/drmtest.c             |  7 ++---
 lib/i915/gem_scheduler.c  |  8 +----
 lib/i915/gem_submission.c | 10 +++---
 lib/igt_gt.c              |  7 ++---
 lib/intel_chipset.c       |  6 +---
 lib/ioctl_wrappers.c      | 65 ++++++---------------------------------
 6 files changed, 21 insertions(+), 82 deletions(-)

diff --git a/lib/drmtest.c b/lib/drmtest.c
index fee9d33a..81383fd4 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -107,14 +107,11 @@ bool is_i915_device(int fd)
 
 static bool has_known_intel_chipset(int fd)
 {
-	struct drm_i915_getparam gp;
 	int devid = 0;
 
-	memset(&gp, 0, sizeof(gp));
-	gp.param = I915_PARAM_CHIPSET_ID;
-	gp.value = &devid;
+	devid = drm_get_param(fd, I915_PARAM_CHIPSET_ID);
 
-	if (ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp)))
+	if (devid <= 0)
 		return false;
 
 	if (!intel_gen(devid))
diff --git a/lib/i915/gem_scheduler.c b/lib/i915/gem_scheduler.c
index ad156306..7366c8eb 100644
--- a/lib/i915/gem_scheduler.c
+++ b/lib/i915/gem_scheduler.c
@@ -52,14 +52,8 @@ unsigned gem_scheduler_capability(int fd)
 	static int caps = -1;
 
 	if (caps < 0) {
-		struct drm_i915_getparam gp;
-
-		memset(&gp, 0, sizeof(gp));
-		gp.param = LOCAL_I915_PARAM_HAS_SCHEDULER;
-		gp.value = ∩︀
-
 		caps = 0;
-		ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp));
+		caps = drm_get_params(fd, LOCAL_I915_PARAM_HAS_SCHEDULER);
 		errno = 0;
 	}
 
diff --git a/lib/i915/gem_submission.c b/lib/i915/gem_submission.c
index 2fd460d5..d6bc80e2 100644
--- a/lib/i915/gem_submission.c
+++ b/lib/i915/gem_submission.c
@@ -53,12 +53,12 @@
 static bool has_semaphores(int fd, int dir)
 {
 	int val = 0;
-	struct drm_i915_getparam gp = {
-		gp.param = I915_PARAM_HAS_SEMAPHORES,
-		gp.value = &val,
-	};
-	if (ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp) < 0)
+
+	val = drm_get_params(fd, I915_PARAM_HAS_SEMAPHORES);
+
+	if (val < 0)
 		val = igt_sysfs_get_boolean(dir, "semaphores");
+
 	return val;
 }
 
diff --git a/lib/igt_gt.c b/lib/igt_gt.c
index a2061924..18cd922b 100644
--- a/lib/igt_gt.c
+++ b/lib/igt_gt.c
@@ -57,14 +57,11 @@ static bool has_gpu_reset(int fd)
 {
 	static int once = -1;
 	if (once < 0) {
-		struct drm_i915_getparam gp;
 		int val = 0;
 
-		memset(&gp, 0, sizeof(gp));
-		gp.param = 35; /* HAS_GPU_RESET */
-		gp.value = &val;
+		val = drm_get_param(fd, 35); /* HAS_GPU_RESET */
 
-		if (ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp))
+		if (val > 0)
 			once = intel_gen(intel_get_drm_devid(fd)) >= 5;
 		else
 			once = val > 0;
diff --git a/lib/intel_chipset.c b/lib/intel_chipset.c
index 4748a3fb..a9245a90 100644
--- a/lib/intel_chipset.c
+++ b/lib/intel_chipset.c
@@ -125,7 +125,6 @@ intel_get_pci_device(void)
 uint32_t
 intel_get_drm_devid(int fd)
 {
-	struct drm_i915_getparam gp;
 	const char *override;
 	int devid = 0;
 
@@ -135,10 +134,7 @@ intel_get_drm_devid(int fd)
 	if (override)
 		return strtol(override, NULL, 0);
 
-	memset(&gp, 0, sizeof(gp));
-	gp.param = I915_PARAM_CHIPSET_ID;
-	gp.value = &devid;
-	ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp));
+	devid = drm_get_param(fd, I915_PARAM_CHIPSET_ID);
 
 	return devid;
 }
diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
index 8fea9fa9..1d4404ee 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -485,16 +485,12 @@ int drm_get_param(int fd, uint32_t param)
 bool gem_create__has_stolen_support(int fd)
 {
 	static int has_stolen_support = -1;
-	struct drm_i915_getparam gp;
 	int val = -1;
 
 	if (has_stolen_support < 0) {
-		memset(&gp, 0, sizeof(gp));
-		gp.param = 38; /* CREATE_VERSION */
-		gp.value = &val;
+		val = drm_get_param(fd, 38); /* CREATE_VERSION */
 
 		/* Do we have the extended gem_create_ioctl? */
-		ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
 		has_stolen_support = val >= 2;
 	}
 
@@ -720,15 +716,8 @@ bool gem_mmap__has_wc(int fd)
 
 		has_wc = 0;
 
-		memset(&gp, 0, sizeof(gp));
-		gp.param = 40; /* MMAP_GTT_VERSION */
-		gp.value = &gtt_version;
-		ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
-
-		memset(&gp, 0, sizeof(gp));
-		gp.param = 30; /* MMAP_VERSION */
-		gp.value = &mmap_version;
-		ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
+		gtt_version = drm_get_param(fd, 40); /* MMAP_GTT_VERSION */
+		mmap_version = drm_get_param(fd, 30); /* MMAP_VERSION */
 
 		/* Do we have the new mmap_ioctl with DOMAIN_WC? */
 		if (mmap_version >= 1 && gtt_version >= 2) {
@@ -973,17 +962,11 @@ bool gem_bo_busy(int fd, uint32_t handle)
  */
 static int gem_gtt_type(int fd)
 {
-	struct drm_i915_getparam gp;
 	int val = 0;
 
-	memset(&gp, 0, sizeof(gp));
-	gp.param = 18; /* HAS_ALIASING_PPGTT */
-	gp.value = &val;
-
-	if (ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp)))
-		return 0;
-
+	val = drm_get_param(fd, 18); /* HAS_ALIASING_PPGTT */
 	errno = 0;
+
 	return val;
 }
 
@@ -1027,13 +1010,9 @@ bool gem_uses_full_ppgtt(int fd)
  */
 int gem_gpu_reset_type(int fd)
 {
-	struct drm_i915_getparam gp;
 	int gpu_reset_type = -1;
 
-	memset(&gp, 0, sizeof(gp));
-	gp.param = I915_PARAM_HAS_GPU_RESET;
-	gp.value = &gpu_reset_type;
-	drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
+	gpu_reset_type = drm_get_param(fd, I915_PARAM_HAS_GPU_RESET);
 
 	return gpu_reset_type;
 }
@@ -1081,14 +1060,8 @@ int gem_available_fences(int fd)
 	static int num_fences = -1;
 
 	if (num_fences < 0) {
-		struct drm_i915_getparam gp;
-
-		memset(&gp, 0, sizeof(gp));
-		gp.param = I915_PARAM_NUM_FENCES_AVAIL;
-		gp.value = &num_fences;
-
 		num_fences = 0;
-		ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp));
+		num_fences = drm_get_param(fd, I915_PARAM_NUM_FENCES_AVAIL);
 		errno = 0;
 	}
 
@@ -1100,14 +1073,8 @@ bool gem_has_llc(int fd)
 	static int has_llc = -1;
 
 	if (has_llc < 0) {
-		struct drm_i915_getparam gp;
-
-		memset(&gp, 0, sizeof(gp));
-		gp.param = I915_PARAM_HAS_LLC;
-		gp.value = &has_llc;
-
 		has_llc = 0;
-		ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp));
+		has_llc = drm_get_param(fd, I915_PARAM_HAS_LLC);
 		errno = 0;
 	}
 
@@ -1357,14 +1324,8 @@ bool gem_has_softpin(int fd)
 	static int has_softpin = -1;
 
 	if (has_softpin < 0) {
-		struct drm_i915_getparam gp;
-
-		memset(&gp, 0, sizeof(gp));
-		gp.param = I915_PARAM_HAS_EXEC_SOFTPIN;
-		gp.value = &has_softpin;
-
 		has_softpin = 0;
-		ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp));
+		has_softpin = drm_get_param(fd, I915_PARAM_HAS_EXEC_SOFTPIN);
 		errno = 0;
 	}
 
@@ -1385,14 +1346,8 @@ bool gem_has_exec_fence(int fd)
 	static int has_exec_fence = -1;
 
 	if (has_exec_fence < 0) {
-		struct drm_i915_getparam gp;
-
-		memset(&gp, 0, sizeof(gp));
-		gp.param = I915_PARAM_HAS_EXEC_FENCE;
-		gp.value = &has_exec_fence;
-
 		has_exec_fence = 0;
-		ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp));
+		has_exec_fence = drm_get_param(fd, I915_PARAM_HAS_EXEC_FENCE);
 		errno = 0;
 	}
 
-- 
2.17.2



More information about the igt-dev mailing list