Skip to content

Commit a34ba68

Browse files
Tvrtko Ursulinlucasdemarchi
authored andcommitted
drm/xe: Consolidate LRC offset calculations
Attempt to consolidate the LRC offsets calculations by aligning the recently added wa_bb_offset with the naming scheme in the file and also change the size stored in struct xe_lrc to not include the ring buffer. The former makes it somewhat visually easier to follow the layout of the various logical blocks stored in the LRC bo, while the latter reduces the number of sprinkled around calculations. Signed-off-by: Tvrtko Ursulin <[email protected]> Cc: Matthew Brost <[email protected]> Cc: Matt Roper <[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 5ac5e19 commit a34ba68

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed

drivers/gpu/drm/xe/xe_lrc.c

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -717,8 +717,12 @@ static u32 __xe_lrc_ctx_timestamp_udw_offset(struct xe_lrc *lrc)
717717

718718
static inline u32 __xe_lrc_indirect_ring_offset(struct xe_lrc *lrc)
719719
{
720-
/* Indirect ring state page is at the very end of LRC */
721-
return lrc->size - LRC_INDIRECT_RING_STATE_SIZE;
720+
return xe_bo_size(lrc->bo) - LRC_WA_BB_SIZE - LRC_INDIRECT_RING_STATE_SIZE;
721+
}
722+
723+
static inline u32 __xe_lrc_wa_bb_offset(struct xe_lrc *lrc)
724+
{
725+
return xe_bo_size(lrc->bo) - LRC_WA_BB_SIZE;
722726
}
723727

724728
#define DECL_MAP_ADDR_HELPERS(elem) \
@@ -973,11 +977,6 @@ struct wa_bb_setup {
973977
u32 *batch, size_t max_size);
974978
};
975979

976-
static size_t wa_bb_offset(struct xe_lrc *lrc)
977-
{
978-
return xe_bo_size(lrc->bo) - LRC_WA_BB_SIZE;
979-
}
980-
981980
static int setup_wa_bb(struct xe_lrc *lrc, struct xe_hw_engine *hwe)
982981
{
983982
const size_t max_size = LRC_WA_BB_SIZE;
@@ -993,7 +992,7 @@ static int setup_wa_bb(struct xe_lrc *lrc, struct xe_hw_engine *hwe)
993992
return -ENOMEM;
994993
cmd = buf;
995994
} else {
996-
cmd = lrc->bo->vmap.vaddr + wa_bb_offset(lrc);
995+
cmd = lrc->bo->vmap.vaddr + __xe_lrc_wa_bb_offset(lrc);
997996
}
998997

999998
remain = max_size / sizeof(*cmd);
@@ -1017,13 +1016,13 @@ static int setup_wa_bb(struct xe_lrc *lrc, struct xe_hw_engine *hwe)
10171016

10181017
if (buf) {
10191018
xe_map_memcpy_to(gt_to_xe(lrc->gt), &lrc->bo->vmap,
1020-
wa_bb_offset(lrc), buf,
1019+
__xe_lrc_wa_bb_offset(lrc), buf,
10211020
(cmd - buf) * sizeof(*cmd));
10221021
kfree(buf);
10231022
}
10241023

10251024
xe_lrc_write_ctx_reg(lrc, CTX_BB_PER_CTX_PTR, xe_bo_ggtt_addr(lrc->bo) +
1026-
wa_bb_offset(lrc) + 1);
1025+
__xe_lrc_wa_bb_offset(lrc) + 1);
10271026

10281027
return 0;
10291028

@@ -1040,19 +1039,22 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
10401039
u32 init_flags)
10411040
{
10421041
struct xe_gt *gt = hwe->gt;
1042+
const u32 lrc_size = xe_gt_lrc_size(gt, hwe->class);
1043+
const u32 bo_size = ring_size + lrc_size + LRC_WA_BB_SIZE;
10431044
struct xe_tile *tile = gt_to_tile(gt);
10441045
struct xe_device *xe = gt_to_xe(gt);
10451046
struct iosys_map map;
10461047
void *init_data = NULL;
10471048
u32 arb_enable;
1048-
u32 lrc_size;
10491049
u32 bo_flags;
10501050
int err;
10511051

10521052
kref_init(&lrc->refcount);
10531053
lrc->gt = gt;
1054+
lrc->size = lrc_size;
10541055
lrc->flags = 0;
1055-
lrc_size = ring_size + xe_gt_lrc_size(gt, hwe->class);
1056+
lrc->ring.size = ring_size;
1057+
lrc->ring.tail = 0;
10561058
if (xe_gt_has_indirect_ring_state(gt))
10571059
lrc->flags |= XE_LRC_FLAG_INDIRECT_RING_STATE;
10581060

@@ -1065,17 +1067,12 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
10651067
* FIXME: Perma-pinning LRC as we don't yet support moving GGTT address
10661068
* via VM bind calls.
10671069
*/
1068-
lrc->bo = xe_bo_create_pin_map(xe, tile, NULL,
1069-
lrc_size + LRC_WA_BB_SIZE,
1070+
lrc->bo = xe_bo_create_pin_map(xe, tile, NULL, bo_size,
10701071
ttm_bo_type_kernel,
10711072
bo_flags);
10721073
if (IS_ERR(lrc->bo))
10731074
return PTR_ERR(lrc->bo);
10741075

1075-
lrc->size = lrc_size;
1076-
lrc->ring.size = ring_size;
1077-
lrc->ring.tail = 0;
1078-
10791076
xe_hw_fence_ctx_init(&lrc->fence_ctx, hwe->gt,
10801077
hwe->fence_irq, hwe->name);
10811078

@@ -1096,10 +1093,9 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
10961093
xe_map_memset(xe, &map, 0, 0, LRC_PPHWSP_SIZE); /* PPHWSP */
10971094
xe_map_memcpy_to(xe, &map, LRC_PPHWSP_SIZE,
10981095
gt->default_lrc[hwe->class] + LRC_PPHWSP_SIZE,
1099-
xe_gt_lrc_size(gt, hwe->class) - LRC_PPHWSP_SIZE);
1096+
lrc_size - LRC_PPHWSP_SIZE);
11001097
} else {
1101-
xe_map_memcpy_to(xe, &map, 0, init_data,
1102-
xe_gt_lrc_size(gt, hwe->class));
1098+
xe_map_memcpy_to(xe, &map, 0, init_data, lrc_size);
11031099
kfree(init_data);
11041100
}
11051101

@@ -1859,8 +1855,7 @@ struct xe_lrc_snapshot *xe_lrc_snapshot_capture(struct xe_lrc *lrc)
18591855
snapshot->seqno = xe_lrc_seqno(lrc);
18601856
snapshot->lrc_bo = xe_bo_get(lrc->bo);
18611857
snapshot->lrc_offset = xe_lrc_pphwsp_offset(lrc);
1862-
snapshot->lrc_size = xe_bo_size(lrc->bo) - snapshot->lrc_offset -
1863-
LRC_WA_BB_SIZE;
1858+
snapshot->lrc_size = lrc->size;
18641859
snapshot->lrc_snapshot = NULL;
18651860
snapshot->ctx_timestamp = lower_32_bits(xe_lrc_ctx_timestamp(lrc));
18661861
snapshot->ctx_job_timestamp = xe_lrc_ctx_job_timestamp(lrc);

drivers/gpu/drm/xe/xe_lrc_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct xe_lrc {
2222
*/
2323
struct xe_bo *bo;
2424

25-
/** @size: size of lrc including any indirect ring state page */
25+
/** @size: size of the lrc and optional indirect ring state */
2626
u32 size;
2727

2828
/** @gt: gt which this LRC belongs to */

0 commit comments

Comments
 (0)