Skip to content

Commit

Permalink
Enable virtual engine (single pipe) on Gen11.
Browse files Browse the repository at this point in the history
  • Loading branch information
zxye committed Feb 21, 2019
1 parent c5962c7 commit f27fed8
Show file tree
Hide file tree
Showing 9 changed files with 404 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ static __inline MOS_STATUS CodecHalEncodeSinglePipeVE_SetHintParams(

if(!MOS_VE_CTXBASEDSCHEDULING_SUPPORTED(pVEInterface->pOsInterface))
{
CODECHAL_ENCODE_CHK_STATUS_RETURN(pVEInterface->pfnVESetHintParams(pVEInterface, pVESetParams));
if(pVEInterface->pfnVESetHintParams)
{
CODECHAL_ENCODE_CHK_STATUS_RETURN(pVEInterface->pfnVESetHintParams(pVEInterface, pVESetParams));
}
}

return eStatus;
Expand Down
17 changes: 17 additions & 0 deletions media_driver/linux/common/os/i915/include/mos_bufmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,23 @@ int mos_get_aperture_sizes(int fd, size_t *mappable, size_t *total);
int mos_bufmgr_gem_get_devid(struct mos_bufmgr *bufmgr);

struct mos_linux_context *mos_gem_context_create(struct mos_bufmgr *bufmgr);
struct mos_linux_context *mos_gem_context_create_v2(struct mos_bufmgr *bufmgr, __u32 flags);
struct class_instance {
uint16_t engine_class;
uint16_t engine_instance;
};

#define MAX_ENGINE_INSTANCE_NUM 8

int mos_query_engines(int fd,
__u16 engine_class,
__u64 caps,
unsigned int *nengine,
struct class_instance *ci);
int mos_set_context_param_load_balance(struct mos_linux_context *ctx,
const struct class_instance *ci,
unsigned int count);

void mos_gem_context_destroy(struct mos_linux_context *ctx);
int mos_gem_bo_context_exec(struct mos_linux_bo *bo, struct mos_linux_context *ctx,
int used, unsigned int flags);
Expand Down
156 changes: 156 additions & 0 deletions media_driver/linux/common/os/i915/mos_bufmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -4648,3 +4648,159 @@ mos_bufmgr_gem_init(int fd, int batch_size)

return bufmgr_gem != nullptr ? &bufmgr_gem->bufmgr : nullptr;
}

struct mos_linux_context *
mos_gem_context_create_v2(struct mos_bufmgr *bufmgr, __u32 flags)
{
struct mos_bufmgr_gem *bufmgr_gem = (struct mos_bufmgr_gem *)bufmgr;
struct drm_i915_gem_context_create_ext create;
struct mos_linux_context *context = nullptr;
int ret;

context = (struct mos_linux_context *)calloc(1, sizeof(*context));
if (!context)
return nullptr;

memclear(create);
create.flags = flags;
create.extensions = 0;
ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE_EXT, &create);
if (ret != 0) {
MOS_DBG("DRM_IOCTL_I915_GEM_CONTEXT_CREATE failed: %s\n",
strerror(errno));
free(context);
return nullptr;
}

context->ctx_id = create.ctx_id;
context->bufmgr = bufmgr;

return context;
}


int mos_query_engines(int fd,
__u16 engine_class,
__u64 caps,
unsigned int *nengine,
struct class_instance *ci)
{
struct drm_i915_query query;
struct drm_i915_query_item query_item;
struct drm_i915_query_engine_info *engines;
int ret, len;

engines = (drm_i915_query_engine_info *)malloc(4096);
memset(engines,0,4096);
memclear(query_item);
query_item.query_id = DRM_I915_QUERY_ENGINE_INFO;
query_item.length = 0;
query_item.data_ptr = (uintptr_t)engines;
memclear(query);
query.num_items = 1;
query.items_ptr = (uintptr_t)&query_item;

ret = drmIoctl(fd, DRM_IOCTL_I915_QUERY, &query);
if (ret)
{
goto fini;
}
len = query_item.length;

memset(engines,0,4096);
memclear(query_item);
query_item.query_id = DRM_I915_QUERY_ENGINE_INFO;
query_item.length = len;
query_item.data_ptr = (uintptr_t)engines;
memclear(query);
query.num_items = 1;
query.items_ptr = (uintptr_t)&query_item;

ret = drmIoctl(fd, DRM_IOCTL_I915_QUERY, &query);
if (ret)
{
goto fini;
}

int i, num;
for (i = 0, num = 0; i < engines->num_engines; i++) {
struct drm_i915_engine_info *engine =
(struct drm_i915_engine_info *)&engines->engines[i];
if ( engine_class == engine->engine_class
&& ((caps & engine->capabilities) || caps == 0))
{
ci->engine_class = engine_class;
ci->engine_instance = engine->engine_instance;
ci++;
num++;
}
}
if (num > *nengine)
{
fprintf(stderr,"%s: Number of engine instances out of range, %d,%d\n",
__FUNCTION__, num, *nengine);
goto fini;
}
*nengine = num;


fini:
free(engines);
return ret;
}

int mos_set_context_param_load_balance(struct mos_linux_context *ctx,
const struct class_instance *ci,
unsigned int count)
{
int ret;

assert(ci);

struct balancer {
uint64_t next_extension;
uint64_t name;

uint64_t flags;
uint64_t mask;

uint64_t mbz[4];
} balancer;
memclear(balancer);
balancer.name = I915_CONTEXT_ENGINES_EXT_LOAD_BALANCE;
balancer.mask = ~0ull;

/*
struct set_engines {
uint64_t extension;
struct class_instance engines[count];
} set_engines;
*/
uint32_t size = sizeof(uint64_t) + (count + 1) * sizeof(struct class_instance);
uint32_t* set_engines = (uint32_t*) malloc(size);
if (NULL == set_engines)
{
return -ENOMEM;
}

/* set_engines->extension */
*((uint64_t*)set_engines) = (uintptr_t)(&balancer);

/* set_engines->engines[0],
KMD requires the first entry of the engine map to be:
class=I915_ENGINE_CLASS_INVALID:instance=I915_ENGINE_CLASS_INVALID_NONE
*/
struct class_instance* ptr = (struct class_instance*)(set_engines+2);
ptr->engine_class = I915_ENGINE_CLASS_INVALID;
ptr->engine_instance = I915_ENGINE_CLASS_INVALID_NONE;

/* set_engines->engines[1]..[count], the "real" engine map */
memcpy(set_engines+3, ci, count * sizeof(struct class_instance));

ret = mos_set_context_param(ctx,
size,
I915_CONTEXT_PARAM_ENGINES,
(uintptr_t)set_engines);
free(set_engines);
return ret;
}

0 comments on commit f27fed8

Please sign in to comment.