OSDN Git Service

minigbm: add buffer invalidation function
authorGurchetan Singh <gurchetansingh@chromium.org>
Tue, 10 Oct 2017 00:59:47 +0000 (17:59 -0700)
committerchrome-bot <chrome-bot@chromium.org>
Wed, 18 Oct 2017 06:14:19 +0000 (23:14 -0700)
We may need to invalidate a buffer before reading it. Some use
cases are:

- DRM_IOCTL_I915_GEM_SET_DOMAIN
        - DMA_BUF_IOCTL_SYNC with the SYNC_START option
        - DRM_IOCTL_VIRTGPU_TRANSFER_FROM_HOST

This patch adds the function hook.

BUG=chromium:764871
TEST=compiles

Change-Id: I85811407252b859a12294381c65ff3545424636b
Reviewed-on: https://chromium-review.googlesource.com/710322
Commit-Ready: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
cros_gralloc/cros_gralloc_buffer.cc
drv.c
drv.h
drv_priv.h

index f799129..fe9c01a 100644 (file)
@@ -59,8 +59,9 @@ int32_t cros_gralloc_buffer::lock(uint32_t map_flags, uint8_t *addr[DRV_MAX_PLAN
                return -EINVAL;
        }
 
-       if (map_flags & BO_MAP_READ_WRITE) {
+       if (map_flags) {
                if (lock_data_[0]) {
+                       drv_bo_invalidate(bo_, lock_data_[0]);
                        vaddr = lock_data_[0]->addr;
                } else {
                        vaddr = drv_bo_map(bo_, 0, 0, drv_bo_get_width(bo_), drv_bo_get_height(bo_),
diff --git a/drv.c b/drv.c
index 6094ad5..3ea46e6 100644 (file)
--- a/drv.c
+++ b/drv.c
@@ -423,6 +423,7 @@ 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);
@@ -452,6 +453,18 @@ int drv_bo_unmap(struct bo *bo, struct map_info *data)
        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;
+}
+
 int drv_bo_flush(struct bo *bo, struct map_info *data)
 {
        int ret = 0;
diff --git a/drv.h b/drv.h
index e62d164..7abaf79 100644 (file)
--- a/drv.h
+++ b/drv.h
@@ -115,6 +115,8 @@ void *drv_bo_map(struct bo *bo, uint32_t x, uint32_t y, uint32_t width, uint32_t
 
 int drv_bo_unmap(struct bo *bo, struct map_info *data);
 
+int drv_bo_invalidate(struct bo *bo, struct map_info *data);
+
 int drv_bo_flush(struct bo *bo, struct map_info *data);
 
 uint32_t drv_bo_get_width(struct bo *bo);
index a195e0e..8978e8d 100644 (file)
@@ -77,6 +77,7 @@ struct backend {
        int (*bo_import)(struct bo *bo, struct drv_import_fd_data *data);
        void *(*bo_map)(struct bo *bo, struct map_info *data, size_t plane, uint32_t map_flags);
        int (*bo_unmap)(struct bo *bo, struct map_info *data);
+       int (*bo_invalidate)(struct bo *bo, struct map_info *data);
        int (*bo_flush)(struct bo *bo, struct map_info *data);
        uint32_t (*resolve_format)(uint32_t format, uint64_t use_flags);
 };