From bc1b535fde9492ca44a829a89b3dfd19ef6fa3c8 Mon Sep 17 00:00:00 2001 From: Pratik Vishwakarma Date: Mon, 12 Dec 2016 14:22:10 +0530 Subject: minigbm: amdgpu: Add mmap implementation for amdgpu BUG=chrome-os-partner:61504 TEST=graphics_Gbm Change-Id: I4ad23fa5b55a249e75ec44fe499c499052f687e0 Reviewed-on: https://chromium-review.googlesource.com/418425 Commit-Ready: Pratik Vishwakarma Tested-by: Pratik Vishwakarma Reviewed-by: Gurchetan Singh --- amdgpu.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'amdgpu.c') diff --git a/amdgpu.c b/amdgpu.c index 5338713..b796670 100644 --- a/amdgpu.c +++ b/amdgpu.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -352,12 +353,32 @@ static int amdgpu_bo_create(struct bo *bo, uint32_t width, uint32_t height, return ret; } +static void *amdgpu_bo_map(struct bo *bo, struct map_info *data, size_t plane) +{ + int ret; + union drm_amdgpu_gem_mmap gem_map; + + memset(&gem_map, 0, sizeof(gem_map)); + gem_map.in.handle = bo->handles[0].u32; + + ret = drmIoctl(bo->drv->fd, DRM_IOCTL_AMDGPU_GEM_MMAP, &gem_map); + if (ret) { + fprintf(stderr, "drv: DRM_IOCTL_AMDGPU_GEM_MMAP failed\n"); + return MAP_FAILED; + } + data->length = bo->sizes[0]; + + return mmap(0, bo->sizes[0], PROT_READ | PROT_WRITE, MAP_SHARED, + bo->drv->fd, gem_map.out.addr_ptr); +} + struct backend backend_amdgpu = { .name = "amdgpu", .init = amdgpu_init, .close = amdgpu_close, .bo_create = amdgpu_bo_create, .bo_destroy = drv_gem_bo_destroy, + .bo_map = amdgpu_bo_map, }; #endif -- cgit v1.2.3