OSDN Git Service

minigbm/i915: Add support for I915_FORMAT_MOD_Y_TILED_CCS.
[android-x86/external-minigbm.git] / drv.c
diff --git a/drv.c b/drv.c
index 6094ad5..6e2c693 100644 (file)
--- a/drv.c
+++ b/drv.c
@@ -6,7 +6,6 @@
 #include <assert.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <pthread.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -19,6 +18,7 @@
 #include "drv_priv.h"
 #include "helpers.h"
 #include "util.h"
+#include "i915_private.h"
 
 #ifdef DRV_AMDGPU
 extern struct backend backend_amdgpu;
@@ -126,12 +126,9 @@ struct driver *drv_create(int fd)
        if (!drv->backend)
                goto free_driver;
 
-       if (pthread_mutex_init(&drv->driver_lock, NULL))
-               goto free_driver;
-
        drv->buffer_table = drmHashCreate();
        if (!drv->buffer_table)
-               goto free_lock;
+               goto free_driver;
 
        drv->map_table = drmHashCreate();
        if (!drv->map_table)
@@ -153,14 +150,14 @@ struct driver *drv_create(int fd)
                }
        }
 
+       ATOMIC_VAR_INIT(drv->driver_lock);
+
        return drv;
 
 free_map_table:
        drmHashDestroy(drv->map_table);
 free_buffer_table:
        drmHashDestroy(drv->buffer_table);
-free_lock:
-       pthread_mutex_destroy(&drv->driver_lock);
 free_driver:
        free(drv);
        return NULL;
@@ -168,7 +165,7 @@ free_driver:
 
 void drv_destroy(struct driver *drv)
 {
-       pthread_mutex_lock(&drv->driver_lock);
+       ATOMIC_LOCK(&drv->driver_lock);
 
        if (drv->backend->close)
                drv->backend->close(drv);
@@ -178,8 +175,7 @@ void drv_destroy(struct driver *drv)
 
        free(drv->combos.data);
 
-       pthread_mutex_unlock(&drv->driver_lock);
-       pthread_mutex_destroy(&drv->driver_lock);
+       ATOMIC_UNLOCK(&drv->driver_lock);
 
        free(drv);
 }
@@ -257,7 +253,7 @@ struct bo *drv_bo_create(struct driver *drv, uint32_t width, uint32_t height, ui
                return NULL;
        }
 
-       pthread_mutex_lock(&drv->driver_lock);
+       ATOMIC_LOCK(&drv->driver_lock);
 
        for (plane = 0; plane < bo->num_planes; plane++) {
                if (plane > 0)
@@ -266,7 +262,7 @@ struct bo *drv_bo_create(struct driver *drv, uint32_t width, uint32_t height, ui
                drv_increment_reference_count(drv, bo, plane);
        }
 
-       pthread_mutex_unlock(&drv->driver_lock);
+       ATOMIC_UNLOCK(&drv->driver_lock);
 
        return bo;
 }
@@ -295,7 +291,7 @@ struct bo *drv_bo_create_with_modifiers(struct driver *drv, uint32_t width, uint
                return NULL;
        }
 
-       pthread_mutex_lock(&drv->driver_lock);
+       ATOMIC_LOCK(&drv->driver_lock);
 
        for (plane = 0; plane < bo->num_planes; plane++) {
                if (plane > 0)
@@ -304,7 +300,7 @@ struct bo *drv_bo_create_with_modifiers(struct driver *drv, uint32_t width, uint
                drv_increment_reference_count(drv, bo, plane);
        }
 
-       pthread_mutex_unlock(&drv->driver_lock);
+       ATOMIC_UNLOCK(&drv->driver_lock);
 
        return bo;
 }
@@ -315,7 +311,7 @@ void drv_bo_destroy(struct bo *bo)
        uintptr_t total = 0;
        struct driver *drv = bo->drv;
 
-       pthread_mutex_lock(&drv->driver_lock);
+       ATOMIC_LOCK(&drv->driver_lock);
 
        for (plane = 0; plane < bo->num_planes; plane++)
                drv_decrement_reference_count(drv, bo, plane);
@@ -323,7 +319,7 @@ void drv_bo_destroy(struct bo *bo)
        for (plane = 0; plane < bo->num_planes; plane++)
                total += drv_get_reference_count(drv, bo, plane);
 
-       pthread_mutex_unlock(&drv->driver_lock);
+       ATOMIC_UNLOCK(&drv->driver_lock);
 
        if (total == 0) {
                assert(drv_map_info_destroy(bo) == 0);
@@ -396,8 +392,10 @@ void *drv_bo_map(struct bo *bo, uint32_t x, uint32_t y, uint32_t width, uint32_t
        assert(x + width <= drv_bo_get_width(bo));
        assert(y + height <= drv_bo_get_height(bo));
        assert(BO_MAP_READ_WRITE & map_flags);
+       /* No CPU access for protected buffers. */
+       assert(!(bo->use_flags & BO_USE_PROTECTED));
 
-       pthread_mutex_lock(&bo->drv->driver_lock);
+       ATOMIC_LOCK(&bo->drv->driver_lock);
 
        if (!drmHashLookup(bo->drv->map_table, bo->handles[plane].u32, &ptr)) {
                data = (struct map_info *)ptr;
@@ -412,7 +410,7 @@ void *drv_bo_map(struct bo *bo, uint32_t x, uint32_t y, uint32_t width, uint32_t
        if (addr == MAP_FAILED) {
                *map_data = NULL;
                free(data);
-               pthread_mutex_unlock(&bo->drv->driver_lock);
+               ATOMIC_UNLOCK(&bo->drv->driver_lock);
                return MAP_FAILED;
        }
 
@@ -423,12 +421,13 @@ void *drv_bo_map(struct bo *bo, uint32_t x, uint32_t y, uint32_t width, uint32_t
        drmHashInsert(bo->drv->map_table, bo->handles[plane].u32, (void *)data);
 
 success:
+       drv_bo_invalidate(bo, data);
        *map_data = data;
        offset = drv_bo_get_plane_stride(bo, plane) * y;
        offset += drv_stride_from_format(bo->format, x, plane);
        addr = (uint8_t *)data->addr;
        addr += drv_bo_get_plane_offset(bo, plane) + offset;
-       pthread_mutex_unlock(&bo->drv->driver_lock);
+       ATOMIC_UNLOCK(&bo->drv->driver_lock);
 
        return (void *)addr;
 }
@@ -439,7 +438,7 @@ int drv_bo_unmap(struct bo *bo, struct map_info *data)
        if (ret)
                return ret;
 
-       pthread_mutex_lock(&bo->drv->driver_lock);
+       ATOMIC_LOCK(&bo->drv->driver_lock);
 
        if (!--data->refcount) {
                ret = bo->drv->backend->bo_unmap(bo, data);
@@ -447,7 +446,19 @@ int drv_bo_unmap(struct bo *bo, struct map_info *data)
                free(data);
        }
 
-       pthread_mutex_unlock(&bo->drv->driver_lock);
+       ATOMIC_UNLOCK(&bo->drv->driver_lock);;
+
+       return ret;
+}
+
+int drv_bo_invalidate(struct bo *bo, struct map_info *data)
+{
+       int ret = 0;
+       assert(data);
+       assert(data->refcount >= 0);
+
+       if (bo->drv->backend->bo_invalidate)
+               ret = bo->drv->backend->bo_invalidate(bo, data);
 
        return ret;
 }
@@ -457,6 +468,7 @@ int drv_bo_flush(struct bo *bo, struct map_info *data)
        int ret = 0;
        assert(data);
        assert(data->refcount >= 0);
+       assert(!(bo->use_flags & BO_USE_PROTECTED));
 
        if (bo->drv->backend->bo_flush)
                ret = bo->drv->backend->bo_flush(bo, data);
@@ -600,8 +612,7 @@ size_t drv_num_planes_from_format(uint32_t format)
                return 3;
        }
 
-       fprintf(stderr, "drv: UNKNOWN FORMAT %d\n", format);
-       return 0;
+       return i915_private_num_planes_from_format(format);
 }
 
 uint32_t drv_num_buffers_per_bo(struct bo *bo)