iris: handle protected BO creation

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 14:17:33 +02:00 committed by Marge Bot
parent 5d88ab63e2
commit 9402ac8023
4 changed files with 56 additions and 29 deletions

View file

@ -871,7 +871,8 @@ alloc_bo_from_cache(struct iris_bufmgr *bufmgr,
unsigned flags,
bool match_zone)
{
if (!bucket)
/* Don't put anything protected in the BO cache. */
if (!bucket || (flags & BO_ALLOC_PROTECTED))
return NULL;
struct iris_bo *bo = NULL;
@ -964,42 +965,56 @@ alloc_fresh_bo(struct iris_bufmgr *bufmgr, uint64_t bo_size, unsigned flags)
/* If we have vram size, we have multiple memory regions and should choose
* one of them.
*/
if (bufmgr->vram.size > 0) {
if (bufmgr->vram.size > 0 || flags & BO_ALLOC_PROTECTED) {
/* All new BOs we get from the kernel are zeroed, so we don't need to
* worry about that here.
*/
struct drm_i915_gem_memory_class_instance regions[2];
uint32_t nregions = 0;
switch (bo->real.heap) {
case IRIS_HEAP_DEVICE_LOCAL_PREFERRED:
/* For vram allocations, still use system memory as a fallback. */
regions[nregions++] = bufmgr->vram.region;
regions[nregions++] = bufmgr->sys.region;
break;
case IRIS_HEAP_DEVICE_LOCAL:
regions[nregions++] = bufmgr->vram.region;
break;
case IRIS_HEAP_SYSTEM_MEMORY:
regions[nregions++] = bufmgr->sys.region;
break;
case IRIS_HEAP_MAX:
unreachable("invalid heap for BO");
}
struct drm_i915_gem_create_ext create = {
.size = bo_size,
};
struct drm_i915_gem_memory_class_instance regions[2];
struct drm_i915_gem_create_ext_memory_regions ext_regions = {
.base = { .name = I915_GEM_CREATE_EXT_MEMORY_REGIONS },
.num_regions = nregions,
.num_regions = 0,
.regions = (uintptr_t)regions,
};
struct drm_i915_gem_create_ext create = {
.size = bo_size,
.extensions = (uintptr_t)&ext_regions,
};
if (bufmgr->vram.size > 0) {
switch (bo->real.heap) {
case IRIS_HEAP_DEVICE_LOCAL_PREFERRED:
/* For vram allocations, still use system memory as a fallback. */
regions[ext_regions.num_regions++] = bufmgr->vram.region;
regions[ext_regions.num_regions++] = bufmgr->sys.region;
break;
case IRIS_HEAP_DEVICE_LOCAL:
regions[ext_regions.num_regions++] = bufmgr->vram.region;
break;
case IRIS_HEAP_SYSTEM_MEMORY:
regions[ext_regions.num_regions++] = bufmgr->sys.region;
break;
case IRIS_HEAP_MAX:
unreachable("invalid heap for BO");
}
if (!bufmgr->all_vram_mappable &&
bo->real.heap == IRIS_HEAP_DEVICE_LOCAL_PREFERRED) {
create.flags |= I915_GEM_CREATE_EXT_FLAG_NEEDS_CPU_ACCESS;
intel_gem_add_ext(&create.extensions,
I915_GEM_CREATE_EXT_MEMORY_REGIONS,
&ext_regions.base);
if (!bufmgr->all_vram_mappable &&
bo->real.heap == IRIS_HEAP_DEVICE_LOCAL_PREFERRED) {
create.flags |= I915_GEM_CREATE_EXT_FLAG_NEEDS_CPU_ACCESS;
}
}
/* Protected param */
struct drm_i915_gem_create_ext_protected_content protected_param = {
.flags = 0,
};
if (flags & BO_ALLOC_PROTECTED) {
intel_gem_add_ext(&create.extensions,
I915_GEM_CREATE_EXT_PROTECTED_CONTENT,
&protected_param.base);
}
/* It should be safe to use GEM_CREATE_EXT without checking, since we are
@ -1127,6 +1142,7 @@ iris_bo_alloc(struct iris_bufmgr *bufmgr,
bo->name = name;
p_atomic_set(&bo->refcount, 1);
bo->real.reusable = bucket && bufmgr->bo_reuse;
bo->real.protected = flags & BO_ALLOC_PROTECTED;
bo->index = -1;
bo->real.kflags = EXEC_OBJECT_SUPPORTS_48B_ADDRESS | EXEC_OBJECT_PINNED;

View file

@ -285,6 +285,9 @@ struct iris_bo {
/** Boolean of whether this buffer points into user memory */
bool userptr;
/** Boolean of whether this buffer is protected (HW encryption) */
bool protected;
} real;
struct {
struct pb_slab_entry entry;
@ -299,6 +302,7 @@ struct iris_bo {
#define BO_ALLOC_SCANOUT (1<<3)
#define BO_ALLOC_NO_SUBALLOC (1<<4)
#define BO_ALLOC_LMEM (1<<5)
#define BO_ALLOC_PROTECTED (1<<6)
/**
* Allocate a buffer object.

View file

@ -480,6 +480,9 @@ iris_resource_alloc_flags(const struct iris_screen *screen,
util_format_get_num_planes(templ->format) > 1)
flags |= BO_ALLOC_NO_SUBALLOC;
if (templ->bind & PIPE_BIND_PROTECTED)
flags |= BO_ALLOC_PROTECTED;
return flags;
}
@ -1944,7 +1947,8 @@ iris_invalidate_resource(struct pipe_context *ctx,
struct iris_bo *new_bo =
iris_bo_alloc(screen->bufmgr, res->bo->name, resource->width0,
iris_buffer_alignment(resource->width0),
iris_memzone_for_address(old_bo->address), 0);
iris_memzone_for_address(old_bo->address),
old_bo->real.protected ? BO_ALLOC_PROTECTED : 0);
if (!new_bo)
return;

View file

@ -311,7 +311,10 @@ iris_mocs(const struct iris_bo *bo,
const struct isl_device *dev,
isl_surf_usage_flags_t usage)
{
return isl_mocs(dev, usage, bo && iris_bo_is_external(bo));
return isl_mocs(dev,
usage |
((bo && bo->real.protected) ? ISL_SURF_USAGE_PROTECTED_BIT : 0),
bo && iris_bo_is_external(bo));
}
struct iris_format_info iris_format_for_usage(const struct intel_device_info *,