intel: Add and use intel_gem_set_context_param()

Again sharing the same function across all Intel drivers.

Signed-off-by: José Roberto de Souza <jose.souza@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18974>
This commit is contained in:
José Roberto de Souza 2022-10-05 09:10:24 -07:00 committed by Marge Bot
parent 6ae6921216
commit 39486661e9
10 changed files with 35 additions and 58 deletions

View file

@ -1538,12 +1538,8 @@ crocus_create_hw_context(struct crocus_bufmgr *bufmgr)
* context is lost, and we will do the recovery ourselves. Ideally,
* we'll have two lost batches instead of a continual stream of hangs.
*/
struct drm_i915_gem_context_param p = {
.ctx_id = ctx_id,
.param = I915_CONTEXT_PARAM_RECOVERABLE,
.value = false,
};
drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, &p);
intel_gem_set_context_param(bufmgr->fd, ctx_id,
I915_CONTEXT_PARAM_RECOVERABLE, false);
return ctx_id;
}
@ -1564,15 +1560,9 @@ crocus_hw_context_set_priority(struct crocus_bufmgr *bufmgr,
uint32_t ctx_id,
int priority)
{
struct drm_i915_gem_context_param p = {
.ctx_id = ctx_id,
.param = I915_CONTEXT_PARAM_PRIORITY,
.value = priority,
};
int err;
err = 0;
if (intel_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, &p))
int err = 0;
if (!intel_gem_set_context_param(bufmgr->fd, ctx_id,
I915_CONTEXT_PARAM_PRIORITY, priority))
err = -errno;
return err;

View file

@ -2184,12 +2184,8 @@ iris_hw_context_set_unrecoverable(struct iris_bufmgr *bufmgr,
* context is lost, and we will do the recovery ourselves. Ideally,
* we'll have two lost batches instead of a continual stream of hangs.
*/
struct drm_i915_gem_context_param p = {
.ctx_id = ctx_id,
.param = I915_CONTEXT_PARAM_RECOVERABLE,
.value = false,
};
intel_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, &p);
intel_gem_set_context_param(bufmgr->fd, ctx_id,
I915_CONTEXT_PARAM_RECOVERABLE, false);
}
void
@ -2198,16 +2194,11 @@ iris_hw_context_set_vm_id(struct iris_bufmgr *bufmgr, uint32_t ctx_id)
if (!bufmgr->use_global_vm)
return;
struct drm_i915_gem_context_param p = {
.ctx_id = ctx_id,
.param = I915_CONTEXT_PARAM_VM,
.value = bufmgr->global_vm_id,
};
int ret = intel_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, &p);
if (ret != 0) {
if (!intel_gem_set_context_param(bufmgr->fd, ctx_id,
I915_CONTEXT_PARAM_VM,
bufmgr->global_vm_id))
DBG("DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM failed: %s\n",
strerror(errno));
}
}
uint32_t
@ -2251,15 +2242,9 @@ iris_hw_context_set_priority(struct iris_bufmgr *bufmgr,
uint32_t ctx_id,
int priority)
{
struct drm_i915_gem_context_param p = {
.ctx_id = ctx_id,
.param = I915_CONTEXT_PARAM_PRIORITY,
.value = priority,
};
int err;
err = 0;
if (intel_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, &p))
int err = 0;
if (!intel_gem_set_context_param(bufmgr->fd, ctx_id,
I915_CONTEXT_PARAM_PRIORITY, priority))
err = -errno;
return err;

View file

@ -161,6 +161,17 @@ intel_gem_create_context_engines(int fd,
return true;
}
bool
intel_gem_set_context_param(int fd, uint32_t context, uint32_t param,
uint64_t value)
{
struct drm_i915_gem_context_param p = {
.ctx_id = context,
.param = param,
.value = value,
};
return intel_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, &p) == 0;
}
bool intel_gem_read_render_timestamp(int fd, uint64_t *value)
{

View file

@ -166,6 +166,9 @@ intel_gem_create_context_engines(int fd,
const struct intel_query_engine_info *info,
int num_engines, enum intel_engine_class *engine_classes,
uint32_t *context_id);
bool
intel_gem_set_context_param(int fd, uint32_t context, uint32_t param,
uint64_t value);
bool intel_gem_read_render_timestamp(int fd, uint64_t *value);

View file

@ -320,19 +320,13 @@ vk_priority_to_i915(VkQueueGlobalPriorityKHR priority)
}
int
anv_gem_set_context_param(int fd, int context, uint32_t param, uint64_t value)
anv_gem_set_context_param(int fd, uint32_t context, uint32_t param, uint64_t value)
{
if (param == I915_CONTEXT_PARAM_PRIORITY)
value = vk_priority_to_i915(value);
struct drm_i915_gem_context_param p = {
.ctx_id = context,
.param = param,
.value = value,
};
int err = 0;
if (intel_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, &p))
if (!intel_gem_set_context_param(fd, context, param, value))
err = -errno;
return err;
}

View file

@ -125,7 +125,7 @@ anv_gem_get_param(int fd, uint32_t param)
}
int
anv_gem_set_context_param(int fd, int context, uint32_t param, uint64_t value)
anv_gem_set_context_param(int fd, uint32_t context, uint32_t param, uint64_t value)
{
unreachable("Unused");
}

View file

@ -1347,7 +1347,7 @@ int anv_gem_execbuffer(struct anv_device *device,
int anv_gem_set_tiling(struct anv_device *device, uint32_t gem_handle,
uint32_t stride, uint32_t tiling);
bool anv_gem_has_context_priority(int fd, VkQueueGlobalPriorityKHR priority);
int anv_gem_set_context_param(int fd, int context, uint32_t param,
int anv_gem_set_context_param(int fd, uint32_t context, uint32_t param,
uint64_t value);
int anv_gem_get_param(int fd, uint32_t param);
int anv_gem_get_tiling(struct anv_device *device, uint32_t gem_handle);

View file

@ -274,16 +274,10 @@ anv_gem_has_context_priority(int fd, int priority)
}
int
anv_gem_set_context_param(int fd, int context, uint32_t param, uint64_t value)
anv_gem_set_context_param(int fd, uint32_t context, uint32_t param, uint64_t value)
{
struct drm_i915_gem_context_param p = {
.ctx_id = context,
.param = param,
.value = value,
};
int err = 0;
if (intel_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, &p))
if (!intel_gem_set_context_param(fd, context, param, value))
err = -errno;
return err;
}

View file

@ -117,7 +117,7 @@ anv_gem_get_param(int fd, uint32_t param)
}
int
anv_gem_set_context_param(int fd, int context, uint32_t param, uint64_t value)
anv_gem_set_context_param(int fd, uint32_t context, uint32_t param, uint64_t value)
{
unreachable("Unused");
}

View file

@ -1382,7 +1382,7 @@ int anv_gem_execbuffer(struct anv_device *device,
int anv_gem_set_tiling(struct anv_device *device, uint32_t gem_handle,
uint32_t stride, uint32_t tiling);
bool anv_gem_has_context_priority(int fd, int priority);
int anv_gem_set_context_param(int fd, int context, uint32_t param,
int anv_gem_set_context_param(int fd, uint32_t context, uint32_t param,
uint64_t value);
int anv_gem_get_param(int fd, uint32_t param);
int anv_gem_get_tiling(struct anv_device *device, uint32_t gem_handle);