OSDN Git Service

freedreno: annotate public functions
[android-x86/external-libdrm.git] / freedreno / freedreno_bo.c
index 331b822..efc5b71 100644 (file)
  *    Rob Clark <robclark@freedesktop.org>
  */
 
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
 #include "freedreno_drmif.h"
 #include "freedreno_priv.h"
 
@@ -82,14 +78,15 @@ static struct fd_bo * bo_from_handle(struct fd_device *dev,
        return bo;
 }
 
-struct fd_bo *
-fd_bo_new(struct fd_device *dev, uint32_t size, uint32_t flags)
+static struct fd_bo *
+bo_new(struct fd_device *dev, uint32_t size, uint32_t flags,
+               struct fd_bo_cache *cache)
 {
        struct fd_bo *bo = NULL;
        uint32_t handle;
        int ret;
 
-       bo = fd_bo_cache_alloc(&dev->bo_cache, &size, flags);
+       bo = fd_bo_cache_alloc(cache, &size, flags);
        if (bo)
                return bo;
 
@@ -99,7 +96,6 @@ fd_bo_new(struct fd_device *dev, uint32_t size, uint32_t flags)
 
        pthread_mutex_lock(&table_lock);
        bo = bo_from_handle(dev, size, handle);
-       bo->bo_reuse = TRUE;
        pthread_mutex_unlock(&table_lock);
 
        VG_BO_ALLOC(bo);
@@ -107,7 +103,30 @@ fd_bo_new(struct fd_device *dev, uint32_t size, uint32_t flags)
        return bo;
 }
 
-struct fd_bo *
+drm_public struct fd_bo *
+fd_bo_new(struct fd_device *dev, uint32_t size, uint32_t flags)
+{
+       struct fd_bo *bo = bo_new(dev, size, flags, &dev->bo_cache);
+       if (bo)
+               bo->bo_reuse = BO_CACHE;
+       return bo;
+}
+
+/* internal function to allocate bo's that use the ringbuffer cache
+ * instead of the normal bo_cache.  The purpose is, because cmdstream
+ * bo's get vmap'd on the kernel side, and that is expensive, we want
+ * to re-use cmdstream bo's for cmdstream and not unrelated purposes.
+ */
+drm_private struct fd_bo *
+fd_bo_new_ring(struct fd_device *dev, uint32_t size, uint32_t flags)
+{
+       struct fd_bo *bo = bo_new(dev, size, flags, &dev->ring_cache);
+       if (bo)
+               bo->bo_reuse = RING_CACHE;
+       return bo;
+}
+
+drm_public struct fd_bo *
 fd_bo_from_handle(struct fd_device *dev, uint32_t handle, uint32_t size)
 {
        struct fd_bo *bo = NULL;
@@ -128,7 +147,7 @@ out_unlock:
        return bo;
 }
 
-struct fd_bo *
+drm_public struct fd_bo *
 fd_bo_from_dmabuf(struct fd_device *dev, int fd)
 {
        int ret, size;
@@ -160,7 +179,7 @@ out_unlock:
        return bo;
 }
 
-struct fd_bo * fd_bo_from_name(struct fd_device *dev, uint32_t name)
+drm_public struct fd_bo * fd_bo_from_name(struct fd_device *dev, uint32_t name)
 {
        struct drm_gem_open req = {
                        .name = name,
@@ -195,23 +214,23 @@ out_unlock:
        return bo;
 }
 
-uint64_t fd_bo_get_iova(struct fd_bo *bo)
+drm_public uint64_t fd_bo_get_iova(struct fd_bo *bo)
 {
        return bo->funcs->iova(bo);
 }
 
-void fd_bo_put_iova(struct fd_bo *bo)
+drm_public void fd_bo_put_iova(struct fd_bo *bo)
 {
        /* currently a no-op */
 }
 
-struct fd_bo * fd_bo_ref(struct fd_bo *bo)
+drm_public struct fd_bo * fd_bo_ref(struct fd_bo *bo)
 {
        atomic_inc(&bo->refcnt);
        return bo;
 }
 
-void fd_bo_del(struct fd_bo *bo)
+drm_public void fd_bo_del(struct fd_bo *bo)
 {
        struct fd_device *dev = bo->dev;
 
@@ -220,7 +239,9 @@ void fd_bo_del(struct fd_bo *bo)
 
        pthread_mutex_lock(&table_lock);
 
-       if (bo->bo_reuse && (fd_bo_cache_free(&dev->bo_cache, bo) == 0))
+       if ((bo->bo_reuse == BO_CACHE) && (fd_bo_cache_free(&dev->bo_cache, bo) == 0))
+               goto out;
+       if ((bo->bo_reuse == RING_CACHE) && (fd_bo_cache_free(&dev->ring_cache, bo) == 0))
                goto out;
 
        bo_del(bo);
@@ -254,7 +275,7 @@ drm_private void bo_del(struct fd_bo *bo)
        bo->funcs->destroy(bo);
 }
 
-int fd_bo_get_name(struct fd_bo *bo, uint32_t *name)
+drm_public int fd_bo_get_name(struct fd_bo *bo, uint32_t *name)
 {
        if (!bo->name) {
                struct drm_gem_flink req = {
@@ -270,7 +291,7 @@ int fd_bo_get_name(struct fd_bo *bo, uint32_t *name)
                pthread_mutex_lock(&table_lock);
                set_name(bo, req.name);
                pthread_mutex_unlock(&table_lock);
-               bo->bo_reuse = FALSE;
+               bo->bo_reuse = NO_CACHE;
        }
 
        *name = bo->name;
@@ -278,12 +299,12 @@ int fd_bo_get_name(struct fd_bo *bo, uint32_t *name)
        return 0;
 }
 
-uint32_t fd_bo_handle(struct fd_bo *bo)
+drm_public uint32_t fd_bo_handle(struct fd_bo *bo)
 {
        return bo->handle;
 }
 
-int fd_bo_dmabuf(struct fd_bo *bo)
+drm_public int fd_bo_dmabuf(struct fd_bo *bo)
 {
        int ret, prime_fd;
 
@@ -294,17 +315,17 @@ int fd_bo_dmabuf(struct fd_bo *bo)
                return ret;
        }
 
-       bo->bo_reuse = FALSE;
+       bo->bo_reuse = NO_CACHE;
 
        return prime_fd;
 }
 
-uint32_t fd_bo_size(struct fd_bo *bo)
+drm_public uint32_t fd_bo_size(struct fd_bo *bo)
 {
        return bo->size;
 }
 
-void * fd_bo_map(struct fd_bo *bo)
+drm_public void * fd_bo_map(struct fd_bo *bo)
 {
        if (!bo->map) {
                uint64_t offset;
@@ -326,18 +347,18 @@ void * fd_bo_map(struct fd_bo *bo)
 }
 
 /* a bit odd to take the pipe as an arg, but it's a, umm, quirk of kgsl.. */
-int fd_bo_cpu_prep(struct fd_bo *bo, struct fd_pipe *pipe, uint32_t op)
+drm_public int fd_bo_cpu_prep(struct fd_bo *bo, struct fd_pipe *pipe, uint32_t op)
 {
        return bo->funcs->cpu_prep(bo, pipe, op);
 }
 
-void fd_bo_cpu_fini(struct fd_bo *bo)
+drm_public void fd_bo_cpu_fini(struct fd_bo *bo)
 {
        bo->funcs->cpu_fini(bo);
 }
 
 #if !HAVE_FREEDRENO_KGSL
-struct fd_bo * fd_bo_from_fbdev(struct fd_pipe *pipe, int fbfd, uint32_t size)
+drm_public struct fd_bo * fd_bo_from_fbdev(struct fd_pipe *pipe, int fbfd, uint32_t size)
 {
     return NULL;
 }