summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGurchetan Singh <gurchetansingh@chromium.org>2017-09-28 17:14:50 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-10-02 23:28:25 -0700
commitcfb88767557632701252c1545d3c17905c6c0f83 (patch)
treed4370867852b23d7f6b500f0ee18caac5abdef3c
parentf7f633aca589e0feb838773fc1afb85260747913 (diff)
minigbm: pass in map flags to (*bo_map) callback
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>
-rw-r--r--amdgpu.c6
-rw-r--r--drv.c4
-rw-r--r--drv_priv.h2
-rw-r--r--helpers.c10
-rw-r--r--helpers.h5
-rw-r--r--i915.c5
-rw-r--r--mediatek.c5
-rw-r--r--rockchip.c5
-rw-r--r--tegra.c11
-rw-r--r--vc4.c5
10 files changed, 35 insertions, 23 deletions
diff --git a/amdgpu.c b/amdgpu.c
index 8448968..9d2f5b5 100644
--- 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
--- 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);
diff --git a/drv_priv.h b/drv_priv.h
index 739e1a0..a195e0e 100644
--- a/drv_priv.h
+++ b/drv_priv.h
@@ -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);
diff --git a/helpers.c b/helpers.c
index a470b9c..def03f5 100644
--- 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;
diff --git a/helpers.h b/helpers.h
index 6192086..766b7d1 100644
--- 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
--- 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;
}
diff --git a/mediatek.c b/mediatek.c
index b999e28..8494c3d 100644
--- a/mediatek.c
+++ b/mediatek.c
@@ -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;
diff --git a/rockchip.c b/rockchip.c
index 58a60aa..6de5e92 100644
--- a/rockchip.c
+++ b/rockchip.c
@@ -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
--- 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
--- 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 = {