From fd14fcb9f995efcd08fddfd00101fe626f9bbe4b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Date: Wed, 5 Oct 2022 09:41:10 -0700 Subject: [PATCH] intel: Add and use intel_gem_get_context_param() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Again sharing the same function across all Intel drivers. There is still two additional DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM calls, one in intel/dev and other in perf. The first one can't call intel_gem_get_context_param() because of the build order of libs and the second one because it sets the size parameter. Will revisit those calls in future but this is already an improvement. v2: - using intel_gem_get_context_param() for the recently added query for I915_CONTEXT_PARAM_PROTECTED_CONTENT Signed-off-by: José Roberto de Souza Reviewed-by: Lionel Landwerlin Part-of: --- src/gallium/drivers/crocus/crocus_bufmgr.c | 10 +++---- src/gallium/drivers/iris/iris_bufmgr.c | 31 +++++++++------------- src/intel/common/intel_gem.c | 14 ++++++++++ src/intel/common/intel_gem.h | 3 +++ 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/gallium/drivers/crocus/crocus_bufmgr.c b/src/gallium/drivers/crocus/crocus_bufmgr.c index a17f87da9a5..d6c8c3a6028 100644 --- a/src/gallium/drivers/crocus/crocus_bufmgr.c +++ b/src/gallium/drivers/crocus/crocus_bufmgr.c @@ -1547,12 +1547,10 @@ crocus_create_hw_context(struct crocus_bufmgr *bufmgr) static int crocus_hw_context_get_priority(struct crocus_bufmgr *bufmgr, uint32_t ctx_id) { - struct drm_i915_gem_context_param p = { - .ctx_id = ctx_id, - .param = I915_CONTEXT_PARAM_PRIORITY, - }; - drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p); - return p.value; /* on error, return 0 i.e. default priority */ + uint64_t priority = 0; + intel_gem_get_context_param(bufmgr->fd, ctx_id, + I915_CONTEXT_PARAM_PRIORITY, &priority); + return priority; /* on error, return 0 i.e. default priority */ } int diff --git a/src/gallium/drivers/iris/iris_bufmgr.c b/src/gallium/drivers/iris/iris_bufmgr.c index 9228de94b96..15ea13d8c2b 100644 --- a/src/gallium/drivers/iris/iris_bufmgr.c +++ b/src/gallium/drivers/iris/iris_bufmgr.c @@ -2229,12 +2229,10 @@ iris_create_hw_context(struct iris_bufmgr *bufmgr, bool protected) int iris_kernel_context_get_priority(struct iris_bufmgr *bufmgr, uint32_t ctx_id) { - struct drm_i915_gem_context_param p = { - .ctx_id = ctx_id, - .param = I915_CONTEXT_PARAM_PRIORITY, - }; - intel_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p); - return p.value; /* on error, return 0 i.e. default priority */ + uint64_t priority = 0; + intel_gem_get_context_param(bufmgr->fd, ctx_id, + I915_CONTEXT_PARAM_PRIORITY, &priority); + return priority; /* on error, return 0 i.e. default priority */ } int @@ -2253,12 +2251,11 @@ iris_hw_context_set_priority(struct iris_bufmgr *bufmgr, static bool iris_hw_context_get_protected(struct iris_bufmgr *bufmgr, uint32_t ctx_id) { - struct drm_i915_gem_context_param p = { - .ctx_id = ctx_id, - .param = I915_CONTEXT_PARAM_PROTECTED_CONTENT, - }; - drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p); - return p.value; /* on error, return 0 i.e. default priority */ + uint64_t protected_content = 0; + intel_gem_get_context_param(bufmgr->fd, ctx_id, + I915_CONTEXT_PARAM_PROTECTED_CONTENT, + &protected_content); + return protected_content; } uint32_t @@ -2373,17 +2370,13 @@ iris_bufmgr_get_meminfo(struct iris_bufmgr *bufmgr, static void iris_bufmgr_init_global_vm(int fd, struct iris_bufmgr *bufmgr) { - struct drm_i915_gem_context_param gcp = { - .ctx_id = 0, - .param = I915_CONTEXT_PARAM_VM, - }; - - if (intel_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM, &gcp)) { + uint64_t value; + if (!intel_gem_get_context_param(fd, 0, I915_CONTEXT_PARAM_VM, &value)) { bufmgr->use_global_vm = false; bufmgr->global_vm_id = 0; } else { bufmgr->use_global_vm = true; - bufmgr->global_vm_id = gcp.value; + bufmgr->global_vm_id = value; } } diff --git a/src/intel/common/intel_gem.c b/src/intel/common/intel_gem.c index af6b75c5fe7..72200437096 100644 --- a/src/intel/common/intel_gem.c +++ b/src/intel/common/intel_gem.c @@ -173,6 +173,20 @@ intel_gem_set_context_param(int fd, uint32_t context, uint32_t param, return intel_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, &p) == 0; } +bool +intel_gem_get_context_param(int fd, uint32_t context, uint32_t param, + uint64_t *value) +{ + struct drm_i915_gem_context_param gp = { + .ctx_id = context, + .param = param, + }; + if (intel_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM, &gp)) + return false; + *value = gp.value; + return true; +} + bool intel_gem_read_render_timestamp(int fd, uint64_t *value) { struct drm_i915_reg_read reg_read = { diff --git a/src/intel/common/intel_gem.h b/src/intel/common/intel_gem.h index 9d49710f4b2..74c7850abfe 100644 --- a/src/intel/common/intel_gem.h +++ b/src/intel/common/intel_gem.h @@ -169,6 +169,9 @@ intel_gem_create_context_engines(int fd, bool intel_gem_set_context_param(int fd, uint32_t context, uint32_t param, uint64_t value); +bool +intel_gem_get_context_param(int fd, uint32_t context, uint32_t param, + uint64_t *value); bool intel_gem_read_render_timestamp(int fd, uint64_t *value); -- 2.34.1