diff --git a/media_softlet/linux/common/os/i915/mos_bufmgr.c b/media_softlet/linux/common/os/i915/mos_bufmgr.c index 07b84b322e..1a25310064 100644 --- a/media_softlet/linux/common/os/i915/mos_bufmgr.c +++ b/media_softlet/linux/common/os/i915/mos_bufmgr.c @@ -1118,7 +1118,7 @@ mos_gem_bo_alloc_internal(struct mos_bufmgr *bufmgr, bo_gem->bo.size = bo_size; bo_gem->mem_region = I915_MEMORY_CLASS_SYSTEM; - bo_gem->pat_index = pat_index; + bo_gem->pat_index = PAT_INDEX_INVALID; bo_gem->cpu_cacheable = true; if (bufmgr_gem->has_lmem && @@ -1146,33 +1146,46 @@ mos_gem_bo_alloc_internal(struct mos_bufmgr *bufmgr, bo_gem->bo.handle = bo_gem->gem_handle; bo_gem->mem_region = I915_MEMORY_CLASS_DEVICE; } - else if (pat_index != PAT_INDEX_INVALID) + else { - struct drm_i915_gem_create_ext_set_pat set_pat_ext; - memclear(set_pat_ext); - set_pat_ext.base.name = I915_GEM_CREATE_EXT_SET_PAT; - set_pat_ext.pat_index = pat_index; - - struct drm_i915_gem_create_ext create; - memclear(create); - create.size = bo_size; - create.extensions = (uintptr_t)(&set_pat_ext); - ret = drmIoctl(bufmgr_gem->fd, - DRM_IOCTL_I915_GEM_CREATE_EXT, + ret = -EINVAL; + if (pat_index != PAT_INDEX_INVALID) + { + struct drm_i915_gem_create_ext_set_pat set_pat_ext; + memclear(set_pat_ext); + set_pat_ext.base.name = I915_GEM_CREATE_EXT_SET_PAT; + set_pat_ext.pat_index = pat_index; + + struct drm_i915_gem_create_ext create; + memclear(create); + create.size = bo_size; + create.extensions = (uintptr_t)(&set_pat_ext); + ret = drmIoctl(bufmgr_gem->fd, + DRM_IOCTL_I915_GEM_CREATE_EXT, + &create); + bo_gem->gem_handle = create.handle; + bo_gem->bo.handle = bo_gem->gem_handle; + bo_gem->pat_index = pat_index; + bo_gem->cpu_cacheable = cpu_cacheable; + } + /* For old kernel without pat_index support, + * DRM_IOCTL_I915_GEM_CREATE_EXT with unknown + * set_pat_ext extension will return error + * Add below code for old kernel compatibility + */ + if (ret != 0) + { + struct drm_i915_gem_create create; + memclear(create); + create.size = bo_size; + ret = drmIoctl(bufmgr_gem->fd, + DRM_IOCTL_I915_GEM_CREATE, &create); - bo_gem->gem_handle = create.handle; - bo_gem->bo.handle = bo_gem->gem_handle; - bo_gem->cpu_cacheable = cpu_cacheable; - } - else { - struct drm_i915_gem_create create; - memclear(create); - create.size = bo_size; - ret = drmIoctl(bufmgr_gem->fd, - DRM_IOCTL_I915_GEM_CREATE, - &create); - bo_gem->gem_handle = create.handle; - bo_gem->bo.handle = bo_gem->gem_handle; + bo_gem->gem_handle = create.handle; + bo_gem->bo.handle = bo_gem->gem_handle; + bo_gem->pat_index = PAT_INDEX_INVALID; + bo_gem->cpu_cacheable = true; + } } if (ret != 0) { free(bo_gem);