diff options
author | Mark Janes <[email protected]> | 2019-07-25 10:50:36 -0700 |
---|---|---|
committer | Mark Janes <[email protected]> | 2019-08-01 16:38:40 -0700 |
commit | 7852fe54159cb6602a4408b8107b52999890dc79 (patch) | |
tree | a81d986430509aedc6defb1f1cb3b78e2e6fb677 /src/gallium | |
parent | b40ba2db6c81021f83465a4ac32922a064cc91b2 (diff) |
intel/common: provide common ioctl routine
i965 links against libdrm for drmIoctl, but anv and iris both
re-implement this routine to avoid the dependency.
intel/dev also needs an ioctl wrapper, so lets share the same
implementation everywhere.
Reviewed-by: Kenneth Graunke <[email protected]>
Reviewed-by: Lionel Landwerlin <[email protected]>
Diffstat (limited to 'src/gallium')
-rw-r--r-- | src/gallium/drivers/iris/iris_batch.c | 3 | ||||
-rw-r--r-- | src/gallium/drivers/iris/iris_bufmgr.c | 58 | ||||
-rw-r--r-- | src/gallium/drivers/iris/iris_fence.c | 15 | ||||
-rw-r--r-- | src/gallium/drivers/iris/iris_screen.c | 3 |
4 files changed, 34 insertions, 45 deletions
diff --git a/src/gallium/drivers/iris/iris_batch.c b/src/gallium/drivers/iris/iris_batch.c index 38405187772..27acf8a5387 100644 --- a/src/gallium/drivers/iris/iris_batch.c +++ b/src/gallium/drivers/iris/iris_batch.c @@ -44,6 +44,7 @@ #include "drm-uapi/i915_drm.h" +#include "intel/common/gen_gem.h" #include "util/hash_table.h" #include "util/set.h" #include "main/macros.h" @@ -574,7 +575,7 @@ submit_batch(struct iris_batch *batch) int ret = 0; if (!batch->screen->no_hw && - drm_ioctl(batch->screen->fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf)) + gen_ioctl(batch->screen->fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf)) ret = -errno; for (int i = 0; i < batch->exec_count; i++) { diff --git a/src/gallium/drivers/iris/iris_bufmgr.c b/src/gallium/drivers/iris/iris_bufmgr.c index d8094582409..32adae53670 100644 --- a/src/gallium/drivers/iris/iris_bufmgr.c +++ b/src/gallium/drivers/iris/iris_bufmgr.c @@ -93,20 +93,6 @@ #define FILE_DEBUG_FLAG DEBUG_BUFMGR -/** - * Call ioctl, restarting if it is interupted - */ -int -drm_ioctl(int fd, unsigned long request, void *arg) -{ - int ret; - - do { - ret = ioctl(fd, request, arg); - } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); - return ret; -} - static inline int atomic_add_unless(int *v, int add, int unless) { @@ -320,7 +306,7 @@ iris_bo_busy(struct iris_bo *bo) struct iris_bufmgr *bufmgr = bo->bufmgr; struct drm_i915_gem_busy busy = { .handle = bo->gem_handle }; - int ret = drm_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_BUSY, &busy); + int ret = gen_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_BUSY, &busy); if (ret == 0) { bo->idle = !busy.busy; return busy.busy; @@ -337,7 +323,7 @@ iris_bo_madvise(struct iris_bo *bo, int state) .retained = 1, }; - drm_ioctl(bo->bufmgr->fd, DRM_IOCTL_I915_GEM_MADVISE, &madv); + gen_ioctl(bo->bufmgr->fd, DRM_IOCTL_I915_GEM_MADVISE, &madv); return madv.retained; } @@ -429,7 +415,7 @@ alloc_fresh_bo(struct iris_bufmgr *bufmgr, uint64_t bo_size) /* All new BOs we get from the kernel are zeroed, so we don't need to * worry about that here. */ - if (drm_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CREATE, &create) != 0) { + if (gen_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CREATE, &create) != 0) { free(bo); return NULL; } @@ -452,7 +438,7 @@ alloc_fresh_bo(struct iris_bufmgr *bufmgr, uint64_t bo_size) .write_domain = 0, }; - if (drm_ioctl(bo->bufmgr->fd, DRM_IOCTL_I915_GEM_SET_DOMAIN, &sd) != 0) { + if (gen_ioctl(bo->bufmgr->fd, DRM_IOCTL_I915_GEM_SET_DOMAIN, &sd) != 0) { bo_free(bo); return NULL; } @@ -531,7 +517,7 @@ bo_alloc_internal(struct iris_bufmgr *bufmgr, .handle = bo->gem_handle, .caching = 1, }; - if (drm_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_SET_CACHING, &arg) == 0) { + if (gen_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_SET_CACHING, &arg) == 0) { bo->cache_coherent = true; bo->reusable = false; } @@ -582,7 +568,7 @@ iris_bo_create_userptr(struct iris_bufmgr *bufmgr, const char *name, .user_ptr = (uintptr_t)ptr, .user_size = size, }; - if (drm_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_USERPTR, &arg)) + if (gen_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_USERPTR, &arg)) goto err_free; bo->gem_handle = arg.handle; @@ -591,7 +577,7 @@ iris_bo_create_userptr(struct iris_bufmgr *bufmgr, const char *name, .handle = bo->gem_handle, .read_domains = I915_GEM_DOMAIN_CPU, }; - if (drm_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_SET_DOMAIN, &sd)) + if (gen_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_SET_DOMAIN, &sd)) goto err_close; bo->name = name; @@ -617,7 +603,7 @@ iris_bo_create_userptr(struct iris_bufmgr *bufmgr, const char *name, return bo; err_close: - drm_ioctl(bufmgr->fd, DRM_IOCTL_GEM_CLOSE, &bo->gem_handle); + gen_ioctl(bufmgr->fd, DRM_IOCTL_GEM_CLOSE, &bo->gem_handle); err_free: free(bo); return NULL; @@ -649,7 +635,7 @@ iris_bo_gem_create_from_name(struct iris_bufmgr *bufmgr, } struct drm_gem_open open_arg = { .name = handle }; - int ret = drm_ioctl(bufmgr->fd, DRM_IOCTL_GEM_OPEN, &open_arg); + int ret = gen_ioctl(bufmgr->fd, DRM_IOCTL_GEM_OPEN, &open_arg); if (ret != 0) { DBG("Couldn't reference %s handle 0x%08x: %s\n", name, handle, strerror(errno)); @@ -687,7 +673,7 @@ iris_bo_gem_create_from_name(struct iris_bufmgr *bufmgr, _mesa_hash_table_insert(bufmgr->name_table, &bo->global_name, bo); struct drm_i915_gem_get_tiling get_tiling = { .handle = bo->gem_handle }; - ret = drm_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_GET_TILING, &get_tiling); + ret = gen_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_GET_TILING, &get_tiling); if (ret != 0) goto err_unref; @@ -713,7 +699,7 @@ bo_close(struct iris_bo *bo) /* Close this object */ struct drm_gem_close close = { .handle = bo->gem_handle }; - int ret = drm_ioctl(bufmgr->fd, DRM_IOCTL_GEM_CLOSE, &close); + int ret = gen_ioctl(bufmgr->fd, DRM_IOCTL_GEM_CLOSE, &close); if (ret != 0) { DBG("DRM_IOCTL_GEM_CLOSE %d failed (%s): %s\n", bo->gem_handle, bo->name, strerror(errno)); @@ -904,7 +890,7 @@ iris_bo_map_cpu(struct pipe_debug_callback *dbg, .handle = bo->gem_handle, .size = bo->size, }; - int ret = drm_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_MMAP, &mmap_arg); + int ret = gen_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_MMAP, &mmap_arg); if (ret != 0) { DBG("%s:%d: Error mapping buffer %d (%s): %s .\n", __FILE__, __LINE__, bo->gem_handle, bo->name, strerror(errno)); @@ -965,7 +951,7 @@ iris_bo_map_wc(struct pipe_debug_callback *dbg, .size = bo->size, .flags = I915_MMAP_WC, }; - int ret = drm_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_MMAP, &mmap_arg); + int ret = gen_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_MMAP, &mmap_arg); if (ret != 0) { DBG("%s:%d: Error mapping buffer %d (%s): %s .\n", __FILE__, __LINE__, bo->gem_handle, bo->name, strerror(errno)); @@ -1027,7 +1013,7 @@ iris_bo_map_gtt(struct pipe_debug_callback *dbg, struct drm_i915_gem_mmap_gtt mmap_arg = { .handle = bo->gem_handle }; /* Get the fake offset back... */ - int ret = drm_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &mmap_arg); + int ret = gen_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &mmap_arg); if (ret != 0) { DBG("%s:%d: Error preparing buffer map %d (%s): %s .\n", __FILE__, __LINE__, bo->gem_handle, bo->name, strerror(errno)); @@ -1185,7 +1171,7 @@ iris_bo_wait(struct iris_bo *bo, int64_t timeout_ns) .bo_handle = bo->gem_handle, .timeout_ns = timeout_ns, }; - int ret = drm_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_WAIT, &wait); + int ret = gen_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_WAIT, &wait); if (ret != 0) return -errno; @@ -1322,7 +1308,7 @@ iris_bo_import_dmabuf(struct iris_bufmgr *bufmgr, int prime_fd) bo->gtt_offset = vma_alloc(bufmgr, IRIS_MEMZONE_OTHER, bo->size, 1); struct drm_i915_gem_get_tiling get_tiling = { .handle = bo->gem_handle }; - if (drm_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_GET_TILING, &get_tiling)) + if (gen_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_GET_TILING, &get_tiling)) goto err; bo->tiling_mode = get_tiling.tiling_mode; @@ -1393,7 +1379,7 @@ iris_bo_flink(struct iris_bo *bo, uint32_t *name) if (!bo->global_name) { struct drm_gem_flink flink = { .handle = bo->gem_handle }; - if (drm_ioctl(bufmgr->fd, DRM_IOCTL_GEM_FLINK, &flink)) + if (gen_ioctl(bufmgr->fd, DRM_IOCTL_GEM_FLINK, &flink)) return -errno; mtx_lock(&bufmgr->lock); @@ -1458,7 +1444,7 @@ uint32_t iris_create_hw_context(struct iris_bufmgr *bufmgr) { struct drm_i915_gem_context_create create = { }; - int ret = drm_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &create); + int ret = gen_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &create); if (ret != 0) { DBG("DRM_IOCTL_I915_GEM_CONTEXT_CREATE failed: %s\n", strerror(errno)); return 0; @@ -1513,7 +1499,7 @@ iris_hw_context_set_priority(struct iris_bufmgr *bufmgr, int err; err = 0; - if (drm_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, &p)) + if (gen_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, &p)) err = -errno; return err; @@ -1538,7 +1524,7 @@ iris_destroy_hw_context(struct iris_bufmgr *bufmgr, uint32_t ctx_id) struct drm_i915_gem_context_destroy d = { .ctx_id = ctx_id }; if (ctx_id != 0 && - drm_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_DESTROY, &d) != 0) { + gen_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_DESTROY, &d) != 0) { fprintf(stderr, "DRM_IOCTL_I915_GEM_CONTEXT_DESTROY failed: %s\n", strerror(errno)); } @@ -1548,7 +1534,7 @@ int iris_reg_read(struct iris_bufmgr *bufmgr, uint32_t offset, uint64_t *result) { struct drm_i915_reg_read reg_read = { .offset = offset }; - int ret = drm_ioctl(bufmgr->fd, DRM_IOCTL_I915_REG_READ, ®_read); + int ret = gen_ioctl(bufmgr->fd, DRM_IOCTL_I915_REG_READ, ®_read); *result = reg_read.val; return ret; @@ -1563,7 +1549,7 @@ iris_gtt_size(int fd) struct drm_i915_gem_context_param p = { .param = I915_CONTEXT_PARAM_GTT_SIZE, }; - if (!drm_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p)) + if (!gen_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p)) return p.value; return 0; diff --git a/src/gallium/drivers/iris/iris_fence.c b/src/gallium/drivers/iris/iris_fence.c index 53102dff3a0..d4ce3c16728 100644 --- a/src/gallium/drivers/iris/iris_fence.c +++ b/src/gallium/drivers/iris/iris_fence.c @@ -27,6 +27,7 @@ */ #include "util/u_inlines.h" +#include "intel/common/gen_gem.h" #include "iris_batch.h" #include "iris_bufmgr.h" @@ -41,7 +42,7 @@ gem_syncobj_create(int fd, uint32_t flags) .flags = flags, }; - drm_ioctl(fd, DRM_IOCTL_SYNCOBJ_CREATE, &args); + gen_ioctl(fd, DRM_IOCTL_SYNCOBJ_CREATE, &args); return args.handle; } @@ -53,7 +54,7 @@ gem_syncobj_destroy(int fd, uint32_t handle) .handle = handle, }; - drm_ioctl(fd, DRM_IOCTL_SYNCOBJ_DESTROY, &args); + gen_ioctl(fd, DRM_IOCTL_SYNCOBJ_DESTROY, &args); } /** @@ -152,7 +153,7 @@ iris_wait_syncpt(struct pipe_screen *p_screen, .count_handles = 1, .timeout_nsec = timeout_nsec, }; - return drm_ioctl(screen->fd, DRM_IOCTL_SYNCOBJ_WAIT, &args); + return gen_ioctl(screen->fd, DRM_IOCTL_SYNCOBJ_WAIT, &args); } static void @@ -246,7 +247,7 @@ iris_fence_finish(struct pipe_screen *p_screen, .timeout_nsec = rel2abs(timeout), /* XXX */ .flags = DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL }; - return drm_ioctl(screen->fd, DRM_IOCTL_SYNCOBJ_WAIT, &args) == 0; + return gen_ioctl(screen->fd, DRM_IOCTL_SYNCOBJ_WAIT, &args) == 0; } #ifndef SYNC_IOC_MAGIC @@ -282,7 +283,7 @@ sync_merge_fd(int sync_fd, int new_fd) .fence = -1, }; - drm_ioctl(sync_fd, SYNC_IOC_MERGE, &args); + gen_ioctl(sync_fd, SYNC_IOC_MERGE, &args); close(new_fd); close(sync_fd); @@ -303,7 +304,7 @@ iris_fence_get_fd(struct pipe_screen *p_screen, .fd = -1, }; - drm_ioctl(screen->fd, DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD, &args); + gen_ioctl(screen->fd, DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD, &args); fd = sync_merge_fd(fd, args.fd); } @@ -323,7 +324,7 @@ iris_fence_create_fd(struct pipe_context *ctx, .flags = DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE, .fd = fd, }; - drm_ioctl(screen->fd, DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE, &args); + gen_ioctl(screen->fd, DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE, &args); struct iris_syncpt *syncpt = malloc(sizeof(*syncpt)); syncpt->handle = args.handle; diff --git a/src/gallium/drivers/iris/iris_screen.c b/src/gallium/drivers/iris/iris_screen.c index 0c497329dea..ceacae239a0 100644 --- a/src/gallium/drivers/iris/iris_screen.c +++ b/src/gallium/drivers/iris/iris_screen.c @@ -52,6 +52,7 @@ #include "iris_resource.h" #include "iris_screen.h" #include "intel/compiler/brw_compiler.h" +#include "intel/common/gen_gem.h" static void iris_flush_frontbuffer(struct pipe_screen *_screen, @@ -97,7 +98,7 @@ static uint64_t get_aperture_size(int fd) { struct drm_i915_gem_get_aperture aperture = {}; - drm_ioctl(fd, DRM_IOCTL_I915_GEM_GET_APERTURE, &aperture); + gen_ioctl(fd, DRM_IOCTL_I915_GEM_GET_APERTURE, &aperture); return aperture.aper_size; } |