[igt-dev] [PATCH i-g-t] tests/kms: Return false in gem_has_lmem for kernels not having DRM_I915_QUERY_MEMORY_REGIONS support

Vidya Srinivas vidya.srinivas at intel.com
Sat Jul 24 16:53:17 UTC 2021


Starting commit (tests/kms: Create buffer object from LMEM for discrete)
it checks for LMEM. This is breaking older kernels like 5.4 without
DRM_I915_QUERY_MEMORY_REGIONS support.

Patch returns false from gem_has_lmem if kernel doesnt have support
for DRM_I915_QUERY_MEMORY_REGIONS.

Signed-off-by: Lin Charlton <charlton.lin at intel.com>
Signed-off-by: Vidya Srinivas <vidya.srinivas at intel.com>
---
 lib/i915/intel_memory_region.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/lib/i915/intel_memory_region.c b/lib/i915/intel_memory_region.c
index 144ae12ca7a0..bdd88967b417 100644
--- a/lib/i915/intel_memory_region.c
+++ b/lib/i915/intel_memory_region.c
@@ -76,6 +76,17 @@ bool gem_has_query_support(int fd)
 	return __i915_query(fd, &query) == 0;
 }
 
+bool gem_has_memregion_query_support(int fd)
+{
+	struct drm_i915_query_item item;
+	int ret;
+
+	memset(&item, 0, sizeof(item));
+	item.query_id = DRM_I915_QUERY_MEMORY_REGIONS;
+	ret = __i915_query_items(fd, &item, 1);
+	return ret;
+}
+
 const char *get_memory_region_name(uint32_t region)
 {
 	uint16_t class = MEMORY_TYPE_FROM_REGION(region);
@@ -164,6 +175,9 @@ uint8_t gem_get_lmem_region_count(int fd)
  */
 bool gem_has_lmem(int fd)
 {
+	int ret = gem_has_memregion_query_support(fd);
+	if (ret == ENOSYS || ret == ENOTSUP)
+		return false;
 	return gem_get_lmem_region_count(fd) > 0;
 }
 
-- 
2.32.0



More information about the igt-dev mailing list