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>
This commit is contained in:
Gurchetan Singh 2017-09-28 17:14:50 -07:00 committed by chrome-bot
parent f7f633aca5
commit cfb8876755
10 changed files with 35 additions and 23 deletions

View file

@ -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)

4
drv.c
View file

@ -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);

View 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);

View file

@ -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;

View file

@ -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);

5
i915.c
View file

@ -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;
}

View 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;

View 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;

11
tegra.c
View file

@ -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;

5
vc4.c
View file

@ -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 = {