OSDN Git Service

minigbm: pass in map flags to (*bo_map) callback
authorGurchetan Singh <gurchetansingh@chromium.org>
Fri, 29 Sep 2017 00:14:50 +0000 (17:14 -0700)
committerchrome-bot <chrome-bot@chromium.org>
Tue, 3 Oct 2017 06:28:25 +0000 (23:28 -0700)
Some eagle-eyed observers have commented that we lose some
potentially useful information for the (*bo_map) callback when
we convert our map flags to page protection flags. Let's not
lose this information, so pass in the map flags. We can convert
to page protection flags using a helper function.

BUG=chromium:764871
TEST=Boot Android and play games on Eve

Change-Id: Ie2cf395109eb5a8de663dfb97a343d20ff0df30c
Reviewed-on: https://chromium-review.googlesource.com/691425
Commit-Ready: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
amdgpu.c
drv.c
drv_priv.h
helpers.c
helpers.h
i915.c
mediatek.c
rockchip.c
tegra.c
vc4.c

index 8448968..9d2f5b5 100644 (file)
--- a/amdgpu.c
+++ b/amdgpu.c
@@ -402,7 +402,7 @@ static int amdgpu_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint
        return ret;
 }
 
-static void *amdgpu_bo_map(struct bo *bo, struct map_info *data, size_t plane, int prot)
+static void *amdgpu_bo_map(struct bo *bo, struct map_info *data, size_t plane, uint32_t map_flags)
 {
        int ret;
        union drm_amdgpu_gem_mmap gem_map;
@@ -415,9 +415,11 @@ static void *amdgpu_bo_map(struct bo *bo, struct map_info *data, size_t plane, i
                fprintf(stderr, "drv: DRM_IOCTL_AMDGPU_GEM_MMAP failed\n");
                return MAP_FAILED;
        }
+
        data->length = bo->total_size;
 
-       return mmap(0, bo->total_size, prot, MAP_SHARED, bo->drv->fd, gem_map.out.addr_ptr);
+       return mmap(0, bo->total_size, drv_get_prot(map_flags), MAP_SHARED, bo->drv->fd,
+                   gem_map.out.addr_ptr);
 }
 
 static uint32_t amdgpu_resolve_format(uint32_t format, uint64_t use_flags)
diff --git a/drv.c b/drv.c
index fc8132a..b7a8f91 100644 (file)
--- a/drv.c
+++ b/drv.c
@@ -367,7 +367,6 @@ void *drv_bo_map(struct bo *bo, uint32_t x, uint32_t y, uint32_t width, uint32_t
        uint8_t *addr;
        size_t offset;
        struct map_info *data;
-       int prot;
 
        assert(width > 0);
        assert(height > 0);
@@ -384,8 +383,7 @@ void *drv_bo_map(struct bo *bo, uint32_t x, uint32_t y, uint32_t width, uint32_t
        }
 
        data = calloc(1, sizeof(*data));
-       prot = BO_MAP_WRITE & map_flags ? PROT_WRITE | PROT_READ : PROT_READ;
-       addr = bo->drv->backend->bo_map(bo, data, plane, prot);
+       addr = bo->drv->backend->bo_map(bo, data, plane, map_flags);
        if (addr == MAP_FAILED) {
                *map_data = NULL;
                free(data);
index 739e1a0..a195e0e 100644 (file)
@@ -75,7 +75,7 @@ struct backend {
                                        uint32_t format, const uint64_t *modifiers, uint32_t count);
        int (*bo_destroy)(struct bo *bo);
        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, int prot);
+       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_flush)(struct bo *bo, struct map_info *data);
        uint32_t (*resolve_format)(uint32_t format, uint64_t use_flags);
index a470b9c..def03f5 100644 (file)
--- a/helpers.c
+++ b/helpers.c
@@ -309,7 +309,7 @@ int drv_prime_bo_import(struct bo *bo, struct drv_import_fd_data *data)
        return 0;
 }
 
-void *drv_dumb_bo_map(struct bo *bo, struct map_info *data, size_t plane, int prot)
+void *drv_dumb_bo_map(struct bo *bo, struct map_info *data, size_t plane, uint32_t map_flags)
 {
        int ret;
        size_t i;
@@ -328,7 +328,8 @@ void *drv_dumb_bo_map(struct bo *bo, struct map_info *data, size_t plane, int pr
                if (bo->handles[i].u32 == bo->handles[plane].u32)
                        data->length += bo->sizes[i];
 
-       return mmap(0, data->length, prot, MAP_SHARED, bo->drv->fd, map_dumb.offset);
+       return mmap(0, data->length, drv_get_prot(map_flags), MAP_SHARED, bo->drv->fd,
+                   map_dumb.offset);
 }
 
 int drv_bo_munmap(struct bo *bo, struct map_info *data)
@@ -365,6 +366,11 @@ int drv_map_info_destroy(struct bo *bo)
        return 0;
 }
 
+int drv_get_prot(uint32_t map_flags)
+{
+       return (BO_MAP_WRITE & map_flags) ? PROT_WRITE | PROT_READ : PROT_READ;
+}
+
 uintptr_t drv_get_reference_count(struct driver *drv, struct bo *bo, size_t plane)
 {
        void *count;
index 6192086..766b7d1 100644 (file)
--- a/helpers.h
+++ b/helpers.h
@@ -15,11 +15,12 @@ int drv_bo_from_format(struct bo *bo, uint32_t stride, uint32_t aligned_height,
 int drv_dumb_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
                       uint64_t use_flags);
 int drv_dumb_bo_destroy(struct bo *bo);
-int drv_map_info_destroy(struct bo *bo);
 int drv_gem_bo_destroy(struct bo *bo);
 int drv_prime_bo_import(struct bo *bo, struct drv_import_fd_data *data);
-void *drv_dumb_bo_map(struct bo *bo, struct map_info *data, size_t plane, int prot);
+void *drv_dumb_bo_map(struct bo *bo, struct map_info *data, size_t plane, uint32_t map_flags);
 int drv_bo_munmap(struct bo *bo, struct map_info *data);
+int drv_map_info_destroy(struct bo *bo);
+int drv_get_prot(uint32_t map_flags);
 uintptr_t drv_get_reference_count(struct driver *drv, struct bo *bo, size_t plane);
 void drv_increment_reference_count(struct driver *drv, struct bo *bo, size_t plane);
 void drv_decrement_reference_count(struct driver *drv, struct bo *bo, size_t plane);
diff --git a/i915.c b/i915.c
index 47d33c0..2d75793 100644 (file)
--- a/i915.c
+++ b/i915.c
@@ -418,7 +418,7 @@ static int i915_bo_import(struct bo *bo, struct drv_import_fd_data *data)
        return 0;
 }
 
-static void *i915_bo_map(struct bo *bo, struct map_info *data, size_t plane, int prot)
+static void *i915_bo_map(struct bo *bo, struct map_info *data, size_t plane, uint32_t map_flags)
 {
        int ret;
        void *addr;
@@ -459,7 +459,8 @@ static void *i915_bo_map(struct bo *bo, struct map_info *data, size_t plane, int
                        return MAP_FAILED;
                }
 
-               addr = mmap(0, bo->total_size, prot, MAP_SHARED, bo->drv->fd, gem_map.offset);
+               addr = mmap(0, bo->total_size, drv_get_prot(map_flags), MAP_SHARED, bo->drv->fd,
+                           gem_map.offset);
                set_domain.read_domains = I915_GEM_DOMAIN_GTT;
                set_domain.write_domain = I915_GEM_DOMAIN_GTT;
        }
index b999e28..8494c3d 100644 (file)
@@ -78,7 +78,7 @@ static int mediatek_bo_create(struct bo *bo, uint32_t width, uint32_t height, ui
        return 0;
 }
 
-static void *mediatek_bo_map(struct bo *bo, struct map_info *data, size_t plane, int prot)
+static void *mediatek_bo_map(struct bo *bo, struct map_info *data, size_t plane, uint32_t map_flags)
 {
        int ret;
        struct drm_mtk_gem_map_off gem_map;
@@ -93,7 +93,8 @@ static void *mediatek_bo_map(struct bo *bo, struct map_info *data, size_t plane,
                return MAP_FAILED;
        }
 
-       void *addr = mmap(0, bo->total_size, prot, MAP_SHARED, bo->drv->fd, gem_map.offset);
+       void *addr = mmap(0, bo->total_size, drv_get_prot(map_flags), MAP_SHARED, bo->drv->fd,
+                         gem_map.offset);
 
        data->length = bo->total_size;
 
index 58a60aa..6de5e92 100644 (file)
@@ -239,7 +239,7 @@ static int rockchip_bo_create(struct bo *bo, uint32_t width, uint32_t height, ui
                                                 ARRAY_SIZE(modifiers));
 }
 
-static void *rockchip_bo_map(struct bo *bo, struct map_info *data, size_t plane, int prot)
+static void *rockchip_bo_map(struct bo *bo, struct map_info *data, size_t plane, uint32_t map_flags)
 {
        int ret;
        struct drm_rockchip_gem_map_off gem_map;
@@ -259,7 +259,8 @@ static void *rockchip_bo_map(struct bo *bo, struct map_info *data, size_t plane,
                return MAP_FAILED;
        }
 
-       void *addr = mmap(0, bo->total_size, prot, MAP_SHARED, bo->drv->fd, gem_map.offset);
+       void *addr = mmap(0, bo->total_size, drv_get_prot(map_flags), MAP_SHARED, bo->drv->fd,
+                         gem_map.offset);
 
        data->length = bo->total_size;
 
diff --git a/tegra.c b/tegra.c
index a3e864e..f116c36 100644 (file)
--- a/tegra.c
+++ b/tegra.c
@@ -44,7 +44,7 @@ enum tegra_map_type {
 struct tegra_private_map_data {
        void *tiled;
        void *untiled;
-       int prot;
+       uint32_t map_flags;
 };
 
 static const uint32_t render_target_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888 };
@@ -301,7 +301,7 @@ static int tegra_bo_import(struct bo *bo, struct drv_import_fd_data *data)
        return 0;
 }
 
-static void *tegra_bo_map(struct bo *bo, struct map_info *data, size_t plane, int prot)
+static void *tegra_bo_map(struct bo *bo, struct map_info *data, size_t plane, uint32_t map_flags)
 {
        int ret;
        struct drm_tegra_gem_mmap gem_map;
@@ -316,13 +316,14 @@ static void *tegra_bo_map(struct bo *bo, struct map_info *data, size_t plane, in
                return MAP_FAILED;
        }
 
-       void *addr = mmap(0, bo->total_size, prot, MAP_SHARED, bo->drv->fd, gem_map.offset);
+       void *addr = mmap(0, bo->total_size, drv_get_prot(map_flags), MAP_SHARED, bo->drv->fd,
+                         gem_map.offset);
        data->length = bo->total_size;
        if ((bo->tiling & 0xFF) == NV_MEM_KIND_C32_2CRA && addr != MAP_FAILED) {
                priv = calloc(1, sizeof(*priv));
                priv->untiled = calloc(1, bo->total_size);
                priv->tiled = addr;
-               priv->prot = prot;
+               priv->map_flags = map_flags;
                data->priv = priv;
                transfer_tiled_memory(bo, priv->tiled, priv->untiled, TEGRA_READ_TILED_BUFFER);
                addr = priv->untiled;
@@ -348,7 +349,7 @@ static int tegra_bo_flush(struct bo *bo, struct map_info *data)
 {
        struct tegra_private_map_data *priv = data->priv;
 
-       if (priv && priv->prot & PROT_WRITE)
+       if (priv && (priv->map_flags & BO_MAP_WRITE))
                transfer_tiled_memory(bo, priv->tiled, priv->untiled, TEGRA_WRITE_TILED_BUFFER);
 
        return 0;
diff --git a/vc4.c b/vc4.c
index 04e0ad9..20431d9 100644 (file)
--- a/vc4.c
+++ b/vc4.c
@@ -62,7 +62,7 @@ static int vc4_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_
        return 0;
 }
 
-static void *vc4_bo_map(struct bo *bo, struct map_info *data, size_t plane, int prot)
+static void *vc4_bo_map(struct bo *bo, struct map_info *data, size_t plane, uint32_t map_flags)
 {
        int ret;
        struct drm_vc4_mmap_bo bo_map;
@@ -77,7 +77,8 @@ static void *vc4_bo_map(struct bo *bo, struct map_info *data, size_t plane, int
        }
 
        data->length = bo->total_size;
-       return mmap(0, bo->total_size, prot, MAP_SHARED, bo->drv->fd, bo_map.offset);
+       return mmap(0, bo->total_size, drv_get_prot(map_flags), MAP_SHARED, bo->drv->fd,
+                   bo_map.offset);
 }
 
 struct backend backend_vc4 = {