iris: enable protected contexts

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8092>
This commit is contained in:
Lionel Landwerlin 2020-12-14 12:30:33 +02:00 committed by Marge Bot
parent 13d75495a0
commit 57a1d13279
6 changed files with 69 additions and 13 deletions

View file

@ -255,7 +255,7 @@ iris_init_non_engine_contexts(struct iris_context *ice, int priority)
struct iris_screen *screen = (void *) ice->ctx.screen;
iris_foreach_batch(ice, batch) {
batch->ctx_id = iris_create_hw_context(screen->bufmgr);
batch->ctx_id = iris_create_hw_context(screen->bufmgr, ice->protected);
batch->exec_flags = I915_EXEC_RENDER;
batch->has_engines_context = false;
assert(batch->ctx_id);

View file

@ -2214,19 +2214,54 @@ iris_hw_context_set_vm_id(struct iris_bufmgr *bufmgr, uint32_t ctx_id)
}
uint32_t
iris_create_hw_context(struct iris_bufmgr *bufmgr)
iris_create_hw_context(struct iris_bufmgr *bufmgr, bool protected)
{
struct drm_i915_gem_context_create create = { };
int ret = intel_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &create);
if (ret != 0) {
DBG("DRM_IOCTL_I915_GEM_CONTEXT_CREATE failed: %s\n", strerror(errno));
return 0;
uint32_t ctx_id;
if (protected) {
struct drm_i915_gem_context_create_ext_setparam recoverable_param = {
.param = {
.param = I915_CONTEXT_PARAM_RECOVERABLE,
.value = false,
},
};
struct drm_i915_gem_context_create_ext_setparam protected_param = {
.param = {
.param = I915_CONTEXT_PARAM_PROTECTED_CONTENT,
.value = true,
},
};
struct drm_i915_gem_context_create_ext create = { 0 };
intel_gem_add_ext(&create.extensions,
I915_CONTEXT_CREATE_EXT_SETPARAM,
&recoverable_param.base);
intel_gem_add_ext(&create.extensions,
I915_CONTEXT_CREATE_EXT_SETPARAM,
&protected_param.base);
int ret = intel_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE_EXT, &create);
if (ret == -1) {
DBG("DRM_IOCTL_I915_GEM_CONTEXT_CREATE_EXT failed: %s\n", strerror(errno));
return 0;
}
ctx_id = create.ctx_id;
} else {
struct drm_i915_gem_context_create create = { };
int ret = intel_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &create);
if (ret != 0) {
DBG("DRM_IOCTL_I915_GEM_CONTEXT_CREATE failed: %s\n", strerror(errno));
return 0;
}
ctx_id = create.ctx_id;
}
iris_hw_context_set_unrecoverable(bufmgr, create.ctx_id);
iris_hw_context_set_vm_id(bufmgr, create.ctx_id);
iris_hw_context_set_unrecoverable(bufmgr, ctx_id);
iris_hw_context_set_vm_id(bufmgr, ctx_id);
return create.ctx_id;
return ctx_id;
}
int
@ -2259,10 +2294,23 @@ iris_hw_context_set_priority(struct iris_bufmgr *bufmgr,
return err;
}
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 */
}
uint32_t
iris_clone_hw_context(struct iris_bufmgr *bufmgr, uint32_t ctx_id)
{
uint32_t new_ctx = iris_create_hw_context(bufmgr);
uint32_t new_ctx =
iris_create_hw_context(bufmgr,
iris_hw_context_get_protected(bufmgr, ctx_id));
if (new_ctx) {
int priority = iris_kernel_context_get_priority(bufmgr, ctx_id);

View file

@ -497,7 +497,7 @@ void* iris_bufmgr_get_aux_map_context(struct iris_bufmgr *bufmgr);
int iris_bo_wait(struct iris_bo *bo, int64_t timeout_ns);
uint32_t iris_create_hw_context(struct iris_bufmgr *bufmgr);
uint32_t iris_create_hw_context(struct iris_bufmgr *bufmgr, bool protected);
uint32_t iris_clone_hw_context(struct iris_bufmgr *bufmgr, uint32_t ctx_id);
int iris_kernel_context_get_priority(struct iris_bufmgr *bufmgr, uint32_t ctx_id);

View file

@ -364,6 +364,8 @@ iris_create_context(struct pipe_screen *pscreen, void *priv, unsigned flags)
priority = INTEL_CONTEXT_HIGH_PRIORITY;
if (flags & PIPE_CONTEXT_LOW_PRIORITY)
priority = INTEL_CONTEXT_LOW_PRIORITY;
if (flags & PIPE_CONTEXT_PROTECTED)
ice->protected = true;
if (INTEL_DEBUG(DEBUG_BATCH))
ice->state.sizes = _mesa_hash_table_u64_create(ice);

View file

@ -408,6 +408,9 @@ iris_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
case PIPE_CAP_QUERY_TIMESTAMP_BITS:
return TIMESTAMP_BITS;
case PIPE_CAP_DEVICE_PROTECTED_CONTEXT:
return screen->kernel_features & KERNEL_HAS_PROTECTED_CONTEXT;
default:
return u_pipe_screen_get_param_defaults(pscreen, param);
}
@ -747,6 +750,8 @@ iris_detect_kernel_features(struct iris_screen *screen)
/* Kernel 5.2+ */
if (intel_gem_supports_syncobj_wait(screen->fd))
screen->kernel_features |= KERNEL_HAS_WAIT_FOR_SUBMIT;
if (intel_gem_supports_protected_context(screen->fd))
screen->kernel_features |= KERNEL_HAS_PROTECTED_CONTEXT;
}
static bool

View file

@ -189,7 +189,8 @@ struct iris_screen {
/** Does the kernel support various features (KERNEL_HAS_* bitfield)? */
unsigned kernel_features;
#define KERNEL_HAS_WAIT_FOR_SUBMIT (1<<0)
#define KERNEL_HAS_WAIT_FOR_SUBMIT (1U<<0)
#define KERNEL_HAS_PROTECTED_CONTEXT (1U<<1)
/**
* Last sequence number allocated by the cache tracking mechanism.