From 41ee836c9ab89ee7b1a1384b64a341d3876f9491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Date: Thu, 6 Oct 2022 09:42:41 -0700 Subject: [PATCH] intel: Add and use intel_gem_can_render_on_fd() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Tapani Pälli Signed-off-by: José Roberto de Souza Part-of: --- src/intel/common/intel_gem.c | 6 ++++++ src/intel/common/intel_gem.h | 1 + src/intel/vulkan/anv_device.c | 7 ++----- src/intel/vulkan_hasvk/anv_device.c | 7 ++----- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/intel/common/intel_gem.c b/src/intel/common/intel_gem.c index 875620ac3044e..cdc6ed95fccdd 100644 --- a/src/intel/common/intel_gem.c +++ b/src/intel/common/intel_gem.c @@ -260,3 +260,9 @@ intel_gem_get_param(int fd, uint32_t param, int *value) }; return intel_ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp) == 0; } + +bool intel_gem_can_render_on_fd(int fd) +{ + int val; + return intel_gem_get_param(fd, I915_PARAM_CHIPSET_ID, &val) && val > 0; +} diff --git a/src/intel/common/intel_gem.h b/src/intel/common/intel_gem.h index 77d8e2c4992d7..f9fa12cea64d1 100644 --- a/src/intel/common/intel_gem.h +++ b/src/intel/common/intel_gem.h @@ -175,6 +175,7 @@ intel_gem_get_context_param(int fd, uint32_t context, uint32_t param, bool intel_gem_read_render_timestamp(int fd, uint64_t *value); bool intel_gem_get_param(int fd, uint32_t param, int *value); +bool intel_gem_can_render_on_fd(int fd); #ifdef __cplusplus } diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 48e445d2ea1c4..b1e6260131e7f 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -968,11 +968,8 @@ anv_physical_device_try_create(struct vk_instance *vk_instance, if (instance->vk.enabled_extensions.KHR_display) { master_fd = open(primary_path, O_RDWR | O_CLOEXEC); if (master_fd >= 0) { - int val; - /* prod the device with a GETPARAM call which will fail if - * we don't have permission to even render on this device - */ - if (!intel_gem_get_param(master_fd, I915_PARAM_CHIPSET_ID, &val) || !val) { + /* fail if we don't have permission to even render on this device */ + if (!intel_gem_can_render_on_fd(master_fd)) { close(master_fd); master_fd = -1; } diff --git a/src/intel/vulkan_hasvk/anv_device.c b/src/intel/vulkan_hasvk/anv_device.c index 85ee7fb5a041c..6f0c80985eee9 100644 --- a/src/intel/vulkan_hasvk/anv_device.c +++ b/src/intel/vulkan_hasvk/anv_device.c @@ -902,11 +902,8 @@ anv_physical_device_try_create(struct vk_instance *vk_instance, if (instance->vk.enabled_extensions.KHR_display) { master_fd = open(primary_path, O_RDWR | O_CLOEXEC); if (master_fd >= 0) { - int val; - /* prod the device with a GETPARAM call which will fail if - * we don't have permission to even render on this device - */ - if (!intel_gem_get_param(master_fd, I915_PARAM_CHIPSET_ID, &val) || !val) { + /* fail if we don't have permission to even render on this device */ + if (!intel_gem_can_render_on_fd(master_fd)) { close(master_fd); master_fd = -1; }