Skip to content

Commit fa7c2a2

Browse files
Tvrtko Ursulinlucasdemarchi
authored andcommitted
drm/xe: Generalize wa bb emission code
Generalize the wa bb emission by splitting it into three phases - setup, emit and finish, and extract setup and finish steps into helpers. This will enable using the same infrastructure for emitting the indirect context workarounds. 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 e08c0fa commit fa7c2a2

File tree

1 file changed

+48
-22
lines changed

1 file changed

+48
-22
lines changed

drivers/gpu/drm/xe/xe_lrc.c

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -972,32 +972,36 @@ static ssize_t wa_bb_setup_utilization(struct xe_lrc *lrc, struct xe_hw_engine *
972972
return cmd - batch;
973973
}
974974

975-
struct wa_bb_setup {
975+
struct bo_setup {
976976
ssize_t (*setup)(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
977977
u32 *batch, size_t max_size);
978978
};
979979

980-
static int setup_wa_bb(struct xe_lrc *lrc, struct xe_hw_engine *hwe)
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)
981987
{
982-
const size_t max_size = LRC_WA_BB_SIZE;
983-
static const struct wa_bb_setup funcs[] = {
984-
{ .setup = wa_bb_setup_utilization },
985-
};
986-
ssize_t remain;
987988
u32 *cmd, *buf = NULL;
989+
ssize_t remain;
988990

989991
if (lrc->bo->vmap.is_iomem) {
990992
buf = kmalloc(max_size, GFP_KERNEL);
991993
if (!buf)
992-
return -ENOMEM;
994+
return ERR_PTR(-ENOMEM);
993995
cmd = buf;
996+
*free = buf;
994997
} else {
995-
cmd = lrc->bo->vmap.vaddr + __xe_lrc_wa_bb_offset(lrc);
998+
cmd = lrc->bo->vmap.vaddr + offset;
999+
*free = NULL;
9961000
}
9971001

9981002
remain = max_size / sizeof(*cmd);
9991003

1000-
for (size_t i = 0; i < ARRAY_SIZE(funcs); i++) {
1004+
for (size_t i = 0; i < num_funcs; i++) {
10011005
ssize_t len = funcs[i].setup(lrc, hwe, cmd, remain);
10021006

10031007
remain -= len;
@@ -1012,23 +1016,45 @@ static int setup_wa_bb(struct xe_lrc *lrc, struct xe_hw_engine *hwe)
10121016
cmd += len;
10131017
}
10141018

1019+
return cmd;
1020+
1021+
fail:
1022+
kfree(buf);
1023+
return ERR_PTR(-ENOSPC);
1024+
}
1025+
1026+
static void finish_bo(struct xe_lrc *lrc, unsigned int offset, u32 *cmd,
1027+
u32 *free)
1028+
{
1029+
if (!free)
1030+
return;
1031+
1032+
xe_map_memcpy_to(gt_to_xe(lrc->gt), &lrc->bo->vmap, offset, free,
1033+
(cmd - free) * sizeof(*cmd));
1034+
kfree(free);
1035+
}
1036+
1037+
static int setup_wa_bb(struct xe_lrc *lrc, struct xe_hw_engine *hwe)
1038+
{
1039+
static const struct bo_setup funcs[] = {
1040+
{ .setup = wa_bb_setup_utilization },
1041+
};
1042+
unsigned int offset = __xe_lrc_wa_bb_offset(lrc);
1043+
u32 *cmd, *buf = NULL;
1044+
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);
1049+
10151050
*cmd++ = MI_BATCH_BUFFER_END;
10161051

1017-
if (buf) {
1018-
xe_map_memcpy_to(gt_to_xe(lrc->gt), &lrc->bo->vmap,
1019-
__xe_lrc_wa_bb_offset(lrc), buf,
1020-
(cmd - buf) * sizeof(*cmd));
1021-
kfree(buf);
1022-
}
1052+
finish_bo(lrc, offset, cmd, buf);
10231053

1024-
xe_lrc_write_ctx_reg(lrc, CTX_BB_PER_CTX_PTR, xe_bo_ggtt_addr(lrc->bo) +
1025-
__xe_lrc_wa_bb_offset(lrc) + 1);
1054+
xe_lrc_write_ctx_reg(lrc, CTX_BB_PER_CTX_PTR,
1055+
xe_bo_ggtt_addr(lrc->bo) + offset + 1);
10261056

10271057
return 0;
1028-
1029-
fail:
1030-
kfree(buf);
1031-
return -ENOSPC;
10321058
}
10331059

10341060
#define PVC_CTX_ASID (0x2e + 1)

0 commit comments

Comments
 (0)