From fd20df8f0944e41449162733d2ca1d3d8be4d734 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Wed, 7 Dec 2022 15:27:04 -0800 Subject: [PATCH] freedreno/drm: Invert BO destruction Sub-alloc'd heap BOs will need to do something a bit more special, ie. not immediately cleanup fences (because those will be needed to know when the BO is actually idle and vma node can be released), not tear down the mmap (because the BO doesn't own it), and not close the handle (also because the BO doesn't own it). Signed-off-by: Rob Clark Part-of: --- src/freedreno/drm/freedreno_bo.c | 20 ++++++++++++++++---- src/freedreno/drm/freedreno_priv.h | 1 + src/freedreno/drm/msm/msm_bo.c | 1 + src/freedreno/drm/virtio/virtio_bo.c | 2 ++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/freedreno/drm/freedreno_bo.c b/src/freedreno/drm/freedreno_bo.c index cc2f6b639c5..aab6e49fa0d 100644 --- a/src/freedreno/drm/freedreno_bo.c +++ b/src/freedreno/drm/freedreno_bo.c @@ -354,10 +354,15 @@ fd_bo_del_list_nocache(struct list_head *list) } /** - * The returned handle must be closed via a call to close_handles() + * Helper called by backends bo->funcs->destroy() + * + * Called under table_lock, bo_del_flush() *must* be called before + * table_lock is released (but bo->funcs->destroy() can be called + * multiple times before bo_del_flush(), as long as table_lock is + * held the entire time) */ -static uint32_t -bo_del(struct fd_bo *bo) +void +fd_bo_fini_common(struct fd_bo *bo) { struct fd_device *dev = bo->dev; uint32_t handle = bo->handle; @@ -380,9 +385,16 @@ bo_del(struct fd_bo *bo) _mesa_hash_table_remove_key(dev->name_table, &bo->name); simple_mtx_unlock(&table_lock); } +} +/** + * The returned handle must be closed via a call to close_handles() + */ +static uint32_t +bo_del(struct fd_bo *bo) +{ + uint32_t handle = bo->handle; bo->funcs->destroy(bo); - return handle; } diff --git a/src/freedreno/drm/freedreno_priv.h b/src/freedreno/drm/freedreno_priv.h index 99a3addf2fc..684403d7c72 100644 --- a/src/freedreno/drm/freedreno_priv.h +++ b/src/freedreno/drm/freedreno_priv.h @@ -351,6 +351,7 @@ enum fd_bo_state { enum fd_bo_state fd_bo_state(struct fd_bo *bo); void fd_bo_init_common(struct fd_bo *bo, struct fd_device *dev); +void fd_bo_fini_common(struct fd_bo *bo); struct fd_bo *fd_bo_new_ring(struct fd_device *dev, uint32_t size); diff --git a/src/freedreno/drm/msm/msm_bo.c b/src/freedreno/drm/msm/msm_bo.c index 57e7ba87b70..e649c369e44 100644 --- a/src/freedreno/drm/msm/msm_bo.c +++ b/src/freedreno/drm/msm/msm_bo.c @@ -140,6 +140,7 @@ static void msm_bo_destroy(struct fd_bo *bo) { struct msm_bo *msm_bo = to_msm_bo(bo); + fd_bo_fini_common(bo); free(msm_bo); } diff --git a/src/freedreno/drm/virtio/virtio_bo.c b/src/freedreno/drm/virtio/virtio_bo.c index 5b1d83b7810..9206f15635b 100644 --- a/src/freedreno/drm/virtio/virtio_bo.c +++ b/src/freedreno/drm/virtio/virtio_bo.c @@ -276,6 +276,8 @@ virtio_bo_destroy(struct fd_bo *bo) virtio_dev_free_iova(bo->dev, bo->iova, bo->size); } + fd_bo_fini_common(bo); + free(virtio_bo); }