panfrost: Add reference type for unowned pool
authorAlyssa Rosenzweig <alyssa@collabora.com>
Thu, 13 May 2021 15:25:31 +0000 (11:25 -0400)
committerMarge Bot <eric+marge@anholt.net>
Tue, 18 May 2021 19:19:01 +0000 (19:19 +0000)
This allows implementing the common pattern of allocating from an
unowned pool and immediately taking a reference.

Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10866>

src/panfrost/lib/pan_pool.h

index 48e6a69..e53ec3f 100644 (file)
@@ -61,6 +61,30 @@ struct pan_pool {
         bool owned;
 };
 
+/* Reference to pool allocated memory for an unowned pool */
+
+struct pan_pool_ref {
+        /* Owning BO */
+        struct panfrost_bo *bo;
+
+        /* Mapped GPU VA */
+        mali_ptr gpu;
+};
+
+/* Take a reference to an allocation pool. Call directly after allocating from
+ * an unowned pool for correct operation. */
+
+static inline struct pan_pool_ref
+pan_take_ref(struct pan_pool *pool, mali_ptr ptr)
+{
+        panfrost_bo_reference(pool->transient_bo);
+
+        return (struct pan_pool_ref) {
+                .gpu = ptr,
+                .bo = pool->transient_bo
+        };
+}
+
 void
 panfrost_pool_init(struct pan_pool *pool, void *memctx,
                    struct panfrost_device *dev, unsigned create_flags,