Commit bcd0aede authored by Chris Wilson's avatar Chris Wilson Committed by Zhenyu Wang

drm/i915/gvt: Use common mapping routines for indirect_ctx object

We have the ability to map an object, so use it rather than opencode it
badly.
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: default avatarZhenyu Wang <zhenyuw@linux.intel.com>
parent 66bbc3b2
...@@ -2717,7 +2717,7 @@ static int shadow_indirect_ctx(struct intel_shadow_wa_ctx *wa_ctx) ...@@ -2717,7 +2717,7 @@ static int shadow_indirect_ctx(struct intel_shadow_wa_ctx *wa_ctx)
unsigned long guest_gma = wa_ctx->indirect_ctx.guest_gma; unsigned long guest_gma = wa_ctx->indirect_ctx.guest_gma;
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
int ret = 0; int ret = 0;
void *dest = NULL; void *map;
obj = i915_gem_object_create(dev, obj = i915_gem_object_create(dev,
roundup(ctx_size + CACHELINE_BYTES, roundup(ctx_size + CACHELINE_BYTES,
...@@ -2725,18 +2725,12 @@ static int shadow_indirect_ctx(struct intel_shadow_wa_ctx *wa_ctx) ...@@ -2725,18 +2725,12 @@ static int shadow_indirect_ctx(struct intel_shadow_wa_ctx *wa_ctx)
if (IS_ERR(obj)) if (IS_ERR(obj))
return PTR_ERR(obj); return PTR_ERR(obj);
ret = i915_gem_object_get_pages(obj);
if (ret)
goto put_obj;
i915_gem_object_pin_pages(obj);
/* get the va of the shadow batch buffer */ /* get the va of the shadow batch buffer */
dest = (void *)vmap_batch(obj, 0, ctx_size + CACHELINE_BYTES); map = i915_gem_object_pin_map(obj, I915_MAP_WB);
if (!dest) { if (IS_ERR(map)) {
gvt_err("failed to vmap shadow indirect ctx\n"); gvt_err("failed to vmap shadow indirect ctx\n");
ret = -ENOMEM; ret = PTR_ERR(map);
goto unpin_src; goto put_obj;
} }
ret = i915_gem_object_set_to_cpu_domain(obj, false); ret = i915_gem_object_set_to_cpu_domain(obj, false);
...@@ -2745,25 +2739,21 @@ static int shadow_indirect_ctx(struct intel_shadow_wa_ctx *wa_ctx) ...@@ -2745,25 +2739,21 @@ static int shadow_indirect_ctx(struct intel_shadow_wa_ctx *wa_ctx)
goto unmap_src; goto unmap_src;
} }
wa_ctx->indirect_ctx.shadow_va = dest;
memset(dest, 0, round_up(ctx_size + CACHELINE_BYTES, PAGE_SIZE));
ret = copy_gma_to_hva(wa_ctx->workload->vgpu, ret = copy_gma_to_hva(wa_ctx->workload->vgpu,
wa_ctx->workload->vgpu->gtt.ggtt_mm, wa_ctx->workload->vgpu->gtt.ggtt_mm,
guest_gma, guest_gma + ctx_size, dest); guest_gma, guest_gma + ctx_size,
map);
if (ret) { if (ret) {
gvt_err("fail to copy guest indirect ctx\n"); gvt_err("fail to copy guest indirect ctx\n");
goto unmap_src; goto unmap_src;
} }
wa_ctx->indirect_ctx.obj = obj; wa_ctx->indirect_ctx.obj = obj;
wa_ctx->indirect_ctx.shadow_va = map;
return 0; return 0;
unmap_src: unmap_src:
vunmap(dest); i915_gem_object_unpin_map(obj);
unpin_src:
i915_gem_object_unpin_pages(wa_ctx->indirect_ctx.obj);
put_obj: put_obj:
i915_gem_object_put(wa_ctx->indirect_ctx.obj); i915_gem_object_put(wa_ctx->indirect_ctx.obj);
return ret; return ret;
......
...@@ -518,8 +518,8 @@ static void release_shadow_wa_ctx(struct intel_shadow_wa_ctx *wa_ctx) ...@@ -518,8 +518,8 @@ static void release_shadow_wa_ctx(struct intel_shadow_wa_ctx *wa_ctx)
if (wa_ctx->indirect_ctx.size == 0) if (wa_ctx->indirect_ctx.size == 0)
return; return;
i915_gem_object_unpin_map(wa_ctx->indirect_ctx.obj);
i915_gem_object_put(wa_ctx->indirect_ctx.obj); i915_gem_object_put(wa_ctx->indirect_ctx.obj);
kvfree(wa_ctx->indirect_ctx.shadow_va);
} }
static int complete_execlist_workload(struct intel_vgpu_workload *workload) static int complete_execlist_workload(struct intel_vgpu_workload *workload)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment