Skip to content

Commit e8941ac

Browse files
committed
drm/vc4: Remove BOs seqnos
`bo->seqno`, `bo->write_seqno`, and `exec->bin_dep_seqno` are leftovers from a time when VC4 didn't support DMA Reservation Objects. Before DMA Resv was introduced, tracking the correspondence between BOs and jobs through the job's seqno made sense. However, this is no longer needed, as VC4 now supports DMA Reservation Objects and attaches the "job done" fence to the BOs. Therefore, remove the BOs seqnos in favor of using DMA Resv Objects. Signed-off-by: Maíra Canal <[email protected]> Reviewed-by: Maxime Ripard <[email protected]> Reviewed-by: Melissa Wen <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 21bd85f commit e8941ac

File tree

4 files changed

+17
-113
lines changed

4 files changed

+17
-113
lines changed

drivers/gpu/drm/vc4/vc4_crtc.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -884,11 +884,7 @@ struct vc4_async_flip_state {
884884
struct drm_framebuffer *fb;
885885
struct drm_framebuffer *old_fb;
886886
struct drm_pending_vblank_event *event;
887-
888-
union {
889-
struct dma_fence_cb fence;
890-
struct vc4_seqno_cb seqno;
891-
} cb;
887+
struct dma_fence_cb cb;
892888
};
893889

894890
/* Called when the V3D execution for the BO being flipped to is done, so that
@@ -919,10 +915,11 @@ vc4_async_page_flip_complete(struct vc4_async_flip_state *flip_state)
919915
kfree(flip_state);
920916
}
921917

922-
static void vc4_async_page_flip_seqno_complete(struct vc4_seqno_cb *cb)
918+
static void vc4_async_page_flip_complete_with_cleanup(struct dma_fence *fence,
919+
struct dma_fence_cb *cb)
923920
{
924921
struct vc4_async_flip_state *flip_state =
925-
container_of(cb, struct vc4_async_flip_state, cb.seqno);
922+
container_of(cb, struct vc4_async_flip_state, cb);
926923
struct vc4_bo *bo = NULL;
927924

928925
if (flip_state->old_fb) {
@@ -932,6 +929,7 @@ static void vc4_async_page_flip_seqno_complete(struct vc4_seqno_cb *cb)
932929
}
933930

934931
vc4_async_page_flip_complete(flip_state);
932+
dma_fence_put(fence);
935933

936934
/*
937935
* Decrement the BO usecnt in order to keep the inc/dec
@@ -950,7 +948,7 @@ static void vc4_async_page_flip_fence_complete(struct dma_fence *fence,
950948
struct dma_fence_cb *cb)
951949
{
952950
struct vc4_async_flip_state *flip_state =
953-
container_of(cb, struct vc4_async_flip_state, cb.fence);
951+
container_of(cb, struct vc4_async_flip_state, cb);
954952

955953
vc4_async_page_flip_complete(flip_state);
956954
dma_fence_put(fence);
@@ -961,31 +959,30 @@ static int vc4_async_set_fence_cb(struct drm_device *dev,
961959
{
962960
struct drm_framebuffer *fb = flip_state->fb;
963961
struct drm_gem_dma_object *dma_bo = drm_fb_dma_get_gem_obj(fb, 0);
962+
dma_fence_func_t async_page_flip_complete_function;
964963
struct vc4_dev *vc4 = to_vc4_dev(dev);
965964
struct dma_fence *fence;
966965
int ret;
967966

968-
if (vc4->gen == VC4_GEN_4) {
969-
struct vc4_bo *bo = to_vc4_bo(&dma_bo->base);
970-
971-
return vc4_queue_seqno_cb(dev, &flip_state->cb.seqno, bo->seqno,
972-
vc4_async_page_flip_seqno_complete);
973-
}
967+
if (vc4->gen == VC4_GEN_4)
968+
async_page_flip_complete_function = vc4_async_page_flip_complete_with_cleanup;
969+
else
970+
async_page_flip_complete_function = vc4_async_page_flip_fence_complete;
974971

975972
ret = dma_resv_get_singleton(dma_bo->base.resv, DMA_RESV_USAGE_READ, &fence);
976973
if (ret)
977974
return ret;
978975

979976
/* If there's no fence, complete the page flip immediately */
980977
if (!fence) {
981-
vc4_async_page_flip_fence_complete(fence, &flip_state->cb.fence);
978+
async_page_flip_complete_function(fence, &flip_state->cb);
982979
return 0;
983980
}
984981

985982
/* If the fence has already been completed, complete the page flip */
986-
if (dma_fence_add_callback(fence, &flip_state->cb.fence,
987-
vc4_async_page_flip_fence_complete))
988-
vc4_async_page_flip_fence_complete(fence, &flip_state->cb.fence);
983+
if (dma_fence_add_callback(fence, &flip_state->cb,
984+
async_page_flip_complete_function))
985+
async_page_flip_complete_function(fence, &flip_state->cb);
989986

990987
return 0;
991988
}

drivers/gpu/drm/vc4/vc4_drv.h

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,6 @@ struct vc4_dev {
186186
*/
187187
struct vc4_perfmon *active_perfmon;
188188

189-
/* List of struct vc4_seqno_cb for callbacks to be made from a
190-
* workqueue when the given seqno is passed.
191-
*/
192-
struct list_head seqno_cb_list;
193-
194189
/* The memory used for storing binner tile alloc, tile state,
195190
* and overflow memory allocations. This is freed when V3D
196191
* powers down.
@@ -247,16 +242,6 @@ struct vc4_dev {
247242
struct vc4_bo {
248243
struct drm_gem_dma_object base;
249244

250-
/* seqno of the last job to render using this BO. */
251-
uint64_t seqno;
252-
253-
/* seqno of the last job to use the RCL to write to this BO.
254-
*
255-
* Note that this doesn't include binner overflow memory
256-
* writes.
257-
*/
258-
uint64_t write_seqno;
259-
260245
bool t_format;
261246

262247
/* List entry for the BO's position in either
@@ -304,12 +289,6 @@ struct vc4_fence {
304289
#define to_vc4_fence(_fence) \
305290
container_of_const(_fence, struct vc4_fence, base)
306291

307-
struct vc4_seqno_cb {
308-
struct work_struct work;
309-
uint64_t seqno;
310-
void (*func)(struct vc4_seqno_cb *cb);
311-
};
312-
313292
struct vc4_v3d {
314293
struct vc4_dev *vc4;
315294
struct platform_device *pdev;
@@ -695,9 +674,6 @@ struct vc4_exec_info {
695674
/* Sequence number for this bin/render job. */
696675
uint64_t seqno;
697676

698-
/* Latest write_seqno of any BO that binning depends on. */
699-
uint64_t bin_dep_seqno;
700-
701677
struct dma_fence *fence;
702678

703679
/* Last current addresses the hardware was processing when the
@@ -1025,9 +1001,6 @@ void vc4_move_job_to_render(struct drm_device *dev, struct vc4_exec_info *exec);
10251001
int vc4_wait_for_seqno(struct drm_device *dev, uint64_t seqno,
10261002
uint64_t timeout_ns, bool interruptible);
10271003
void vc4_job_handle_completed(struct vc4_dev *vc4);
1028-
int vc4_queue_seqno_cb(struct drm_device *dev,
1029-
struct vc4_seqno_cb *cb, uint64_t seqno,
1030-
void (*func)(struct vc4_seqno_cb *cb));
10311004
int vc4_gem_madvise_ioctl(struct drm_device *dev, void *data,
10321005
struct drm_file *file_priv);
10331006

drivers/gpu/drm/vc4/vc4_gem.c

Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -553,27 +553,19 @@ vc4_move_job_to_render(struct drm_device *dev, struct vc4_exec_info *exec)
553553
}
554554

555555
static void
556-
vc4_update_bo_seqnos(struct vc4_exec_info *exec, uint64_t seqno)
556+
vc4_attach_fences(struct vc4_exec_info *exec)
557557
{
558558
struct vc4_bo *bo;
559559
unsigned i;
560560

561561
for (i = 0; i < exec->bo_count; i++) {
562562
bo = to_vc4_bo(exec->bo[i]);
563-
bo->seqno = seqno;
564-
565563
dma_resv_add_fence(bo->base.base.resv, exec->fence,
566564
DMA_RESV_USAGE_READ);
567565
}
568566

569-
list_for_each_entry(bo, &exec->unref_list, unref_head) {
570-
bo->seqno = seqno;
571-
}
572-
573567
for (i = 0; i < exec->rcl_write_bo_count; i++) {
574568
bo = to_vc4_bo(&exec->rcl_write_bo[i]->base);
575-
bo->write_seqno = seqno;
576-
577569
dma_resv_add_fence(bo->base.base.resv, exec->fence,
578570
DMA_RESV_USAGE_WRITE);
579571
}
@@ -647,7 +639,7 @@ vc4_queue_submit(struct drm_device *dev, struct vc4_exec_info *exec,
647639
if (out_sync)
648640
drm_syncobj_replace_fence(out_sync, exec->fence);
649641

650-
vc4_update_bo_seqnos(exec, seqno);
642+
vc4_attach_fences(exec);
651643

652644
drm_exec_fini(exec_ctx);
653645

@@ -845,12 +837,6 @@ vc4_get_bcl(struct drm_device *dev, struct vc4_exec_info *exec)
845837
goto fail;
846838
}
847839

848-
/* Block waiting on any previous rendering into the CS's VBO,
849-
* IB, or textures, so that pixels are actually written by the
850-
* time we try to read them.
851-
*/
852-
ret = vc4_wait_for_seqno(dev, exec->bin_dep_seqno, ~0ull, true);
853-
854840
fail:
855841
kvfree(temp);
856842
return ret;
@@ -909,7 +895,6 @@ void
909895
vc4_job_handle_completed(struct vc4_dev *vc4)
910896
{
911897
unsigned long irqflags;
912-
struct vc4_seqno_cb *cb, *cb_temp;
913898

914899
if (WARN_ON_ONCE(vc4->gen > VC4_GEN_4))
915900
return;
@@ -926,48 +911,9 @@ vc4_job_handle_completed(struct vc4_dev *vc4)
926911
spin_lock_irqsave(&vc4->job_lock, irqflags);
927912
}
928913

929-
list_for_each_entry_safe(cb, cb_temp, &vc4->seqno_cb_list, work.entry) {
930-
if (cb->seqno <= vc4->finished_seqno) {
931-
list_del_init(&cb->work.entry);
932-
schedule_work(&cb->work);
933-
}
934-
}
935-
936914
spin_unlock_irqrestore(&vc4->job_lock, irqflags);
937915
}
938916

939-
static void vc4_seqno_cb_work(struct work_struct *work)
940-
{
941-
struct vc4_seqno_cb *cb = container_of(work, struct vc4_seqno_cb, work);
942-
943-
cb->func(cb);
944-
}
945-
946-
int vc4_queue_seqno_cb(struct drm_device *dev,
947-
struct vc4_seqno_cb *cb, uint64_t seqno,
948-
void (*func)(struct vc4_seqno_cb *cb))
949-
{
950-
struct vc4_dev *vc4 = to_vc4_dev(dev);
951-
unsigned long irqflags;
952-
953-
if (WARN_ON_ONCE(vc4->gen > VC4_GEN_4))
954-
return -ENODEV;
955-
956-
cb->func = func;
957-
INIT_WORK(&cb->work, vc4_seqno_cb_work);
958-
959-
spin_lock_irqsave(&vc4->job_lock, irqflags);
960-
if (seqno > vc4->finished_seqno) {
961-
cb->seqno = seqno;
962-
list_add_tail(&cb->work.entry, &vc4->seqno_cb_list);
963-
} else {
964-
schedule_work(&cb->work);
965-
}
966-
spin_unlock_irqrestore(&vc4->job_lock, irqflags);
967-
968-
return 0;
969-
}
970-
971917
/* Scheduled when any job has been completed, this walks the list of
972918
* jobs that had completed and unrefs their BOs and frees their exec
973919
* structs.
@@ -1221,7 +1167,6 @@ int vc4_gem_init(struct drm_device *dev)
12211167
INIT_LIST_HEAD(&vc4->bin_job_list);
12221168
INIT_LIST_HEAD(&vc4->render_job_list);
12231169
INIT_LIST_HEAD(&vc4->job_done_list);
1224-
INIT_LIST_HEAD(&vc4->seqno_cb_list);
12251170
spin_lock_init(&vc4->job_lock);
12261171

12271172
INIT_WORK(&vc4->hangcheck.reset_work, vc4_reset_work);

drivers/gpu/drm/vc4/vc4_validate.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,6 @@ validate_indexed_prim_list(VALIDATE_ARGS)
284284
if (!ib)
285285
return -EINVAL;
286286

287-
exec->bin_dep_seqno = max(exec->bin_dep_seqno,
288-
to_vc4_bo(&ib->base)->write_seqno);
289-
290287
if (offset > ib->base.size ||
291288
(ib->base.size - offset) / index_size < length) {
292289
DRM_DEBUG("IB access overflow (%d + %d*%d > %zd)\n",
@@ -738,11 +735,6 @@ reloc_tex(struct vc4_exec_info *exec,
738735

739736
*validated_p0 = tex->dma_addr + p0;
740737

741-
if (is_cs) {
742-
exec->bin_dep_seqno = max(exec->bin_dep_seqno,
743-
to_vc4_bo(&tex->base)->write_seqno);
744-
}
745-
746738
return true;
747739
fail:
748740
DRM_INFO("Texture p0 at %d: 0x%08x\n", sample->p_offset[0], p0);
@@ -904,9 +896,6 @@ validate_gl_shader_rec(struct drm_device *dev,
904896
uint32_t stride = *(uint8_t *)(pkt_u + o + 5);
905897
uint32_t max_index;
906898

907-
exec->bin_dep_seqno = max(exec->bin_dep_seqno,
908-
to_vc4_bo(&vbo->base)->write_seqno);
909-
910899
if (state->addr & 0x8)
911900
stride |= (*(uint32_t *)(pkt_u + 100 + i * 4)) & ~0xff;
912901

0 commit comments

Comments
 (0)