diff options
author | Boris Brezillon <[email protected]> | 2019-07-02 13:21:55 +0200 |
---|---|---|
committer | Boris Brezillon <[email protected]> | 2019-07-02 14:58:51 +0200 |
commit | c684a796692cd12d806dabb640ed277c530ef6f2 (patch) | |
tree | 08731bc35d16e824d4fb61536183d215500b94cc /src/gallium/drivers/panfrost/pan_drm.c | |
parent | 948fddfc4294a7d5e93b2e1d76ad0058cd9e9889 (diff) |
panfrost: Add the panfrost_drm_{create,release}_bo() helpers
To avoid the panfrost_memory <-> panfrost_bo dance done in
panfrost_resource_create_bo() and panfrost_bo_unreference().
Signed-off-by: Boris Brezillon <[email protected]>
Diffstat (limited to 'src/gallium/drivers/panfrost/pan_drm.c')
-rw-r--r-- | src/gallium/drivers/panfrost/pan_drm.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/gallium/drivers/panfrost/pan_drm.c b/src/gallium/drivers/panfrost/pan_drm.c index b21005feaeb..d49c999e077 100644 --- a/src/gallium/drivers/panfrost/pan_drm.c +++ b/src/gallium/drivers/panfrost/pan_drm.c @@ -65,6 +65,68 @@ panfrost_drm_mmap_bo(struct panfrost_screen *screen, struct panfrost_bo *bo) pandecode_inject_mmap(bo->gpu, bo->cpu, bo->size, NULL); } +static void +panfrost_drm_munmap_bo(struct panfrost_screen *screen, struct panfrost_bo *bo) +{ + if (!bo->cpu) + return; + + if (os_munmap((void *) (uintptr_t)bo->cpu, bo->size)) { + perror("munmap"); + abort(); + } + + bo->cpu = NULL; +} + +struct panfrost_bo * +panfrost_drm_create_bo(struct panfrost_screen *screen, size_t size, + uint32_t flags) +{ + struct panfrost_bo *bo = rzalloc(screen, struct panfrost_bo); + struct drm_panfrost_create_bo create_bo = { + .size = size, + .flags = flags, + }; + int ret; + + ret = drmIoctl(screen->fd, DRM_IOCTL_PANFROST_CREATE_BO, &create_bo); + if (ret) { + fprintf(stderr, "DRM_IOCTL_PANFROST_CREATE_BO failed: %d\n", ret); + assert(0); + } + + bo->size = create_bo.size; + bo->gpu = create_bo.offset; + bo->gem_handle = create_bo.handle; + + // TODO map and unmap on demand? + panfrost_drm_mmap_bo(screen, bo); + + pipe_reference_init(&bo->reference, 1); + return bo; +} + +void +panfrost_drm_release_bo(struct panfrost_screen *screen, struct panfrost_bo *bo) +{ + struct drm_gem_close gem_close = { .handle = bo->gem_handle }; + int ret; + + if (!bo) + return; + + panfrost_drm_munmap_bo(screen, bo); + + ret = drmIoctl(screen->fd, DRM_IOCTL_GEM_CLOSE, &gem_close); + if (ret) { + fprintf(stderr, "DRM_IOCTL_GEM_CLOSE failed: %d\n", ret); + assert(0); + } + + ralloc_free(bo); +} + void panfrost_drm_allocate_slab(struct panfrost_screen *screen, struct panfrost_memory *mem, |