Skip to content

Commit 81b7967

Browse files
Tvrtko Ursulinlucasdemarchi
authored andcommitted
drm/xe: Pass wa bb setup arguments in a struct
Group the function arguments in a struct for more readable code and easier extending. Signed-off-by: Tvrtko Ursulin <[email protected]> Cc: Lucas De Marchi <[email protected]> Reviewed-by: Lucas De Marchi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lucas De Marchi <[email protected]>
1 parent fa7c2a2 commit 81b7967

File tree

1 file changed

+53
-40
lines changed

1 file changed

+53
-40
lines changed

drivers/gpu/drm/xe/xe_lrc.c

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -977,82 +977,95 @@ struct bo_setup {
977977
u32 *batch, size_t max_size);
978978
};
979979

980-
static u32 *setup_bo(struct xe_lrc *lrc,
981-
struct xe_hw_engine *hwe,
982-
const size_t max_size,
983-
unsigned int offset,
984-
const struct bo_setup *funcs,
985-
unsigned int num_funcs,
986-
u32 **free)
987-
{
988-
u32 *cmd, *buf = NULL;
980+
struct bo_setup_state {
981+
/* Input: */
982+
struct xe_lrc *lrc;
983+
struct xe_hw_engine *hwe;
984+
size_t max_size;
985+
unsigned int offset;
986+
const struct bo_setup *funcs;
987+
unsigned int num_funcs;
988+
989+
/* State: */
990+
u32 *buffer;
991+
u32 *ptr;
992+
};
993+
994+
static int setup_bo(struct bo_setup_state *state)
995+
{
989996
ssize_t remain;
990997

991-
if (lrc->bo->vmap.is_iomem) {
992-
buf = kmalloc(max_size, GFP_KERNEL);
993-
if (!buf)
994-
return ERR_PTR(-ENOMEM);
995-
cmd = buf;
996-
*free = buf;
998+
if (state->lrc->bo->vmap.is_iomem) {
999+
state->buffer = kmalloc(state->max_size, GFP_KERNEL);
1000+
if (!state->buffer)
1001+
return -ENOMEM;
1002+
state->ptr = state->buffer;
9971003
} else {
998-
cmd = lrc->bo->vmap.vaddr + offset;
999-
*free = NULL;
1004+
state->ptr = state->lrc->bo->vmap.vaddr + state->offset;
1005+
state->buffer = NULL;
10001006
}
10011007

1002-
remain = max_size / sizeof(*cmd);
1008+
remain = state->max_size / sizeof(u32);
10031009

1004-
for (size_t i = 0; i < num_funcs; i++) {
1005-
ssize_t len = funcs[i].setup(lrc, hwe, cmd, remain);
1010+
for (size_t i = 0; i < state->num_funcs; i++) {
1011+
ssize_t len = state->funcs[i].setup(state->lrc, state->hwe,
1012+
state->ptr, remain);
10061013

10071014
remain -= len;
10081015

10091016
/*
10101017
* There should always be at least 1 additional dword for
10111018
* the end marker
10121019
*/
1013-
if (len < 0 || xe_gt_WARN_ON(lrc->gt, remain < 1))
1020+
if (len < 0 || xe_gt_WARN_ON(state->lrc->gt, remain < 1))
10141021
goto fail;
10151022

1016-
cmd += len;
1023+
state->ptr += len;
10171024
}
10181025

1019-
return cmd;
1026+
return 0;
10201027

10211028
fail:
1022-
kfree(buf);
1023-
return ERR_PTR(-ENOSPC);
1029+
kfree(state->buffer);
1030+
return -ENOSPC;
10241031
}
10251032

1026-
static void finish_bo(struct xe_lrc *lrc, unsigned int offset, u32 *cmd,
1027-
u32 *free)
1033+
static void finish_bo(struct bo_setup_state *state)
10281034
{
1029-
if (!free)
1035+
if (!state->buffer)
10301036
return;
10311037

1032-
xe_map_memcpy_to(gt_to_xe(lrc->gt), &lrc->bo->vmap, offset, free,
1033-
(cmd - free) * sizeof(*cmd));
1034-
kfree(free);
1038+
xe_map_memcpy_to(gt_to_xe(state->lrc->gt), &state->lrc->bo->vmap,
1039+
state->offset, state->buffer,
1040+
(state->ptr - state->buffer) * sizeof(u32));
1041+
kfree(state->buffer);
10351042
}
10361043

10371044
static int setup_wa_bb(struct xe_lrc *lrc, struct xe_hw_engine *hwe)
10381045
{
10391046
static const struct bo_setup funcs[] = {
10401047
{ .setup = wa_bb_setup_utilization },
10411048
};
1042-
unsigned int offset = __xe_lrc_wa_bb_offset(lrc);
1043-
u32 *cmd, *buf = NULL;
1049+
struct bo_setup_state state = {
1050+
.lrc = lrc,
1051+
.hwe = hwe,
1052+
.max_size = LRC_WA_BB_SIZE,
1053+
.offset = __xe_lrc_wa_bb_offset(lrc),
1054+
.funcs = funcs,
1055+
.num_funcs = ARRAY_SIZE(funcs),
1056+
};
1057+
int ret;
10441058

1045-
cmd = setup_bo(lrc, hwe, LRC_WA_BB_SIZE, offset, funcs,
1046-
ARRAY_SIZE(funcs), &buf);
1047-
if (IS_ERR(cmd))
1048-
return PTR_ERR(cmd);
1059+
ret = setup_bo(&state);
1060+
if (ret)
1061+
return ret;
10491062

1050-
*cmd++ = MI_BATCH_BUFFER_END;
1063+
*state.ptr++ = MI_BATCH_BUFFER_END;
10511064

1052-
finish_bo(lrc, offset, cmd, buf);
1065+
finish_bo(&state);
10531066

10541067
xe_lrc_write_ctx_reg(lrc, CTX_BB_PER_CTX_PTR,
1055-
xe_bo_ggtt_addr(lrc->bo) + offset + 1);
1068+
xe_bo_ggtt_addr(lrc->bo) + state.offset + 1);
10561069

10571070
return 0;
10581071
}

0 commit comments

Comments
 (0)