Commit 58facf8c authored by Zhi Wang's avatar Zhi Wang Committed by Zhenyu Wang

drm/i915/gvt: Refine find_bb_size()

Returns the error code if something is wrong and the size of batch buffer
is passed through the pointer.
Signed-off-by: default avatarZhi Wang <zhi.a.wang@intel.com>
parent 5e86ccef
...@@ -1594,23 +1594,23 @@ static int batch_buffer_needs_scan(struct parser_exec_state *s) ...@@ -1594,23 +1594,23 @@ static int batch_buffer_needs_scan(struct parser_exec_state *s)
return 1; return 1;
} }
static int find_bb_size(struct parser_exec_state *s) static int find_bb_size(struct parser_exec_state *s, unsigned long *bb_size)
{ {
unsigned long gma = 0; unsigned long gma = 0;
struct cmd_info *info; struct cmd_info *info;
int bb_size = 0;
uint32_t cmd_len = 0; uint32_t cmd_len = 0;
bool met_bb_end = false; bool bb_end = false;
struct intel_vgpu *vgpu = s->vgpu; struct intel_vgpu *vgpu = s->vgpu;
u32 cmd; u32 cmd;
*bb_size = 0;
/* get the start gm address of the batch buffer */ /* get the start gm address of the batch buffer */
gma = get_gma_bb_from_cmd(s, 1); gma = get_gma_bb_from_cmd(s, 1);
if (gma == INTEL_GVT_INVALID_ADDR) if (gma == INTEL_GVT_INVALID_ADDR)
return -EFAULT; return -EFAULT;
cmd = cmd_val(s, 0); cmd = cmd_val(s, 0);
info = get_cmd_info(s->vgpu->gvt, cmd, s->ring_id); info = get_cmd_info(s->vgpu->gvt, cmd, s->ring_id);
if (info == NULL) { if (info == NULL) {
gvt_vgpu_err("unknown cmd 0x%x, opcode=0x%x\n", gvt_vgpu_err("unknown cmd 0x%x, opcode=0x%x\n",
...@@ -1629,20 +1629,18 @@ static int find_bb_size(struct parser_exec_state *s) ...@@ -1629,20 +1629,18 @@ static int find_bb_size(struct parser_exec_state *s)
} }
if (info->opcode == OP_MI_BATCH_BUFFER_END) { if (info->opcode == OP_MI_BATCH_BUFFER_END) {
met_bb_end = true; bb_end = true;
} else if (info->opcode == OP_MI_BATCH_BUFFER_START) { } else if (info->opcode == OP_MI_BATCH_BUFFER_START) {
if (BATCH_BUFFER_2ND_LEVEL_BIT(cmd) == 0) { if (BATCH_BUFFER_2ND_LEVEL_BIT(cmd) == 0)
/* chained batch buffer */ /* chained batch buffer */
met_bb_end = true; bb_end = true;
}
} }
cmd_len = get_cmd_length(info, cmd) << 2; cmd_len = get_cmd_length(info, cmd) << 2;
bb_size += cmd_len; *bb_size += cmd_len;
gma += cmd_len; gma += cmd_len;
} while (!bb_end);
} while (!met_bb_end); return 0;
return bb_size;
} }
static int perform_bb_shadow(struct parser_exec_state *s) static int perform_bb_shadow(struct parser_exec_state *s)
...@@ -1650,7 +1648,7 @@ static int perform_bb_shadow(struct parser_exec_state *s) ...@@ -1650,7 +1648,7 @@ static int perform_bb_shadow(struct parser_exec_state *s)
struct intel_shadow_bb_entry *entry_obj; struct intel_shadow_bb_entry *entry_obj;
struct intel_vgpu *vgpu = s->vgpu; struct intel_vgpu *vgpu = s->vgpu;
unsigned long gma = 0; unsigned long gma = 0;
int bb_size; unsigned long bb_size;
void *dst = NULL; void *dst = NULL;
int ret = 0; int ret = 0;
...@@ -1660,9 +1658,9 @@ static int perform_bb_shadow(struct parser_exec_state *s) ...@@ -1660,9 +1658,9 @@ static int perform_bb_shadow(struct parser_exec_state *s)
return -EFAULT; return -EFAULT;
/* get the size of the batch buffer */ /* get the size of the batch buffer */
bb_size = find_bb_size(s); ret = find_bb_size(s, &bb_size);
if (bb_size < 0) if (ret)
return bb_size; return ret;
/* allocate shadow batch buffer */ /* allocate shadow batch buffer */
entry_obj = kmalloc(sizeof(*entry_obj), GFP_KERNEL); entry_obj = kmalloc(sizeof(*entry_obj), GFP_KERNEL);
......
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