From 96e2977856cd70b9e5de8c33a0361354d4f16ee2 Mon Sep 17 00:00:00 2001 From: Unknown <0.tamas.marton@gmail.com> Date: Sun, 13 May 2018 17:20:52 +0100 Subject: [PATCH] updated kernel interfaces --- driver/driver.c | 5 +++ driver/kernelInterface.c | 92 ++++++++++++++++++++++++++++++++++------ driver/kernelInterface.h | 13 +++++- 3 files changed, 95 insertions(+), 15 deletions(-) diff --git a/driver/driver.c b/driver/driver.c index fc8aa82..e333128 100644 --- a/driver/driver.c +++ b/driver/driver.c @@ -449,6 +449,11 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance( int chip_info = vc4_get_chip_info(renderFd); int has_tiling = vc4_test_tiling(renderFd); + int has_control_flow = vc4_has_feature(renderFd, DRM_VC4_PARAM_SUPPORTS_BRANCHES); + int has_etc1 = vc4_has_feature(renderFd, DRM_VC4_PARAM_SUPPORTS_ETC1); + int has_threaded_fs = vc4_has_feature(renderFd, DRM_VC4_PARAM_SUPPORTS_THREADED_FS); + int has_madvise = vc4_has_feature(renderFd, DRM_VC4_PARAM_SUPPORTS_MADVISE); + return VK_SUCCESS; } diff --git a/driver/kernelInterface.c b/driver/kernelInterface.c index 1ad1a94..c008224 100644 --- a/driver/kernelInterface.c +++ b/driver/kernelInterface.c @@ -27,6 +27,19 @@ void closeIoctl() close(renderFd); } +static uint32_t align(uint32_t num, uint32_t alignment) +{ + uint32_t mod = num%alignment; + if(!mod) + { + return num; + } + else + { + return num + alignment - mod; + } +} + int vc4_get_chip_info(int fd) { struct drm_vc4_get_param ident0 = { @@ -109,7 +122,6 @@ uint64_t vc4_bo_get_tiling(int fd, uint32_t bo, uint64_t mod) }; int ret = drmIoctl(fd, DRM_IOCTL_VC4_GET_TILING, &get_tiling); - //TODO if (ret != 0) { return DRM_FORMAT_MOD_LINEAR; } else if (mod == DRM_FORMAT_MOD_INVALID) { @@ -167,7 +179,7 @@ void* vc4_bo_map_unsynchronized(int fd, uint32_t bo, uint32_t size) return mapPtr; } -int vc4_bo_wait_ioctl(int fd, uint32_t handle, uint64_t timeout_ns) +static int vc4_bo_wait_ioctl(int fd, uint32_t handle, uint64_t timeout_ns) { struct drm_vc4_wait_bo wait = { .handle = handle, @@ -185,7 +197,21 @@ int vc4_bo_wait_ioctl(int fd, uint32_t handle, uint64_t timeout_ns) } } -int vc4_seqno_wait_ioctl(int fd, uint64_t seqno, uint64_t timeout_ns) +int vc4_bo_wait(int fd, uint32_t bo, uint64_t timeout_ns) +{ + int ret = vc4_bo_wait_ioctl(fd, bo, timeout_ns); + if (ret) { + if (ret != -ETIME) { + fprintf(stderr, "wait failed: %d\n", ret); + } + + return 0; + } + + return 1; +} + +static int vc4_seqno_wait_ioctl(int fd, uint64_t seqno, uint64_t timeout_ns) { struct drm_vc4_wait_seqno wait = { .seqno = seqno, @@ -201,7 +227,24 @@ int vc4_seqno_wait_ioctl(int fd, uint64_t seqno, uint64_t timeout_ns) { return 1; } +} +int vc4_seqno_wait(int fd, uint64_t* lastFinishedSeqno, uint64_t seqno, uint64_t timeout_ns) +{ + if (*lastFinishedSeqno >= seqno) + return 1; + + int ret = vc4_seqno_wait_ioctl(fd, seqno, timeout_ns); + if (ret) { + if (ret != -ETIME) { + printf("wait failed: %d\n", ret); + } + + return 0; + } + + *lastFinishedSeqno = seqno; + return 1; } int vc4_bo_flink(int fd, uint32_t bo, uint32_t *name) @@ -227,11 +270,10 @@ uint32_t vc4_bo_alloc_shader(int fd, const void *data, uint32_t* size) { int ret; - //TODO - uint32_t alignedSize = *size;//align(*size, 4096); + uint32_t alignedSize = align(*size, ARM_PAGE_SIZE); struct drm_vc4_create_shader_bo create = { - .size = *size, //TODO why isn't this alignedSize? + .size = *alignedSize, .data = (uintptr_t)data, }; @@ -261,9 +303,7 @@ uint32_t vc4_bo_open_name(int fd, uint32_t name) return 0; } - //TODO - //return vc4_bo_open_handle(screen, winsys_stride, o.handle, o.size); - return 1; + return o.handle; } uint32_t vc4_bo_alloc(int fd, uint32_t size, const char *name) @@ -272,8 +312,7 @@ uint32_t vc4_bo_alloc(int fd, uint32_t size, const char *name) struct drm_vc4_create_bo create; int ret; - //TODO - uint32_t alignedSize = size;//align(size, 4096); + uint32_t alignedSize = align(size, ARM_PAGE_SIZE); /*bo = vc4_bo_from_cache(screen, size, name); if (bo) { @@ -303,8 +342,7 @@ uint32_t vc4_bo_alloc(int fd, uint32_t size, const char *name) return 0; } - //TODO - //vc4_bo_label(screen, bo, "%s", name); + vc4_bo_label(screen, bo, "%s", name); return handle; } @@ -366,3 +404,31 @@ void vc4_bo_label(int fd, uint32_t bo, const char* name) }; drmIoctl(fd, DRM_IOCTL_VC4_LABEL_BO, &label); } + +int vc4_bo_get_dmabuf(int fd, uint32_t bo) +{ + int boFd; + int ret = drmPrimeHandleToFD(fd, bo, + O_CLOEXEC, &boFd); + if (ret != 0) { + printf("Failed to export gem bo %d to dmabuf\n", + bo); + return 0; + } + + return boFd; +} + +void* vc4_bo_map(int fd, uint32_t bo, uint32_t size) +{ + void* map = vc4_bo_map_unsynchronized(fd, bo, size); + + //wait infinitely + int ok = vc4_bo_wait(fd, bo, WAIT_TIMEOUT_INFINITE); + if (!ok) { + printf("BO wait for map failed\n"); + return 0; + } + + return map; +} diff --git a/driver/kernelInterface.h b/driver/kernelInterface.h index bb4696f..d0df6f1 100644 --- a/driver/kernelInterface.h +++ b/driver/kernelInterface.h @@ -24,6 +24,9 @@ extern "C" { #define DRM_IOCTL_CTRL_DEV_FILE_NAME "/dev/dri/card0" #define DRM_IOCTL_RENDER_DEV_FILE_NAME "/dev/dri/renderD128" //TODO does this need to be dynamic? (eg. iterate through renderDn?) +#define WAIT_TIMEOUT_INFINITE 0xffffffffffffffffull +#define ARM_PAGE_SIZE 4096 + extern int controlFd; extern int renderFd; @@ -36,8 +39,10 @@ int vc4_test_tiling(int fd); uint64_t vc4_bo_get_tiling(int fd, uint32_t bo, uint64_t mod); int vc4_bo_set_tiling(int fd, uint32_t bo, uint64_t mod); void* vc4_bo_map_unsynchronized(int fd, uint32_t bo, uint32_t size); -int vc4_bo_wait_ioctl(int fd, uint32_t handle, uint64_t timeout_ns); -int vc4_seqno_wait_ioctl(int fd, uint64_t seqno, uint64_t timeout_ns); +//int vc4_bo_wait_ioctl(int fd, uint32_t handle, uint64_t timeout_ns); +int vc4_bo_wait(int fd, uint32_t bo, uint64_t timeout_ns); +//int vc4_seqno_wait_ioctl(int fd, uint64_t seqno, uint64_t timeout_ns); +int vc4_seqno_wait(int fd, uint64_t* lastFinishedSeqno, uint64_t seqno, uint64_t timeout_ns); int vc4_bo_flink(int fd, uint32_t bo, uint32_t *name); uint32_t vc4_bo_alloc_shader(int fd, const void *data, uint32_t* size); uint32_t vc4_bo_open_name(int fd, uint32_t name); @@ -46,6 +51,10 @@ void vc4_bo_free(int fd, uint32_t bo, void* mappedAddr, uint32_t size); int vc4_bo_unpurgeable(int fd, uint32_t bo, int hasMadvise); void vc4_bo_purgeable(int fd, uint32_t bo, int hasMadvise); void vc4_bo_label(int fd, uint32_t bo, const char* name); +int vc4_bo_get_dmabuf(int fd, uint32_t bo); +void* vc4_bo_map(int fd, uint32_t bo, uint32_t size); + +//TODO perfmon #if defined (__cplusplus) }