intel: Replace open-coded drmIoctl with calls to drmIoctl()

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
main
Chris Wilson 2010-09-25 21:32:59 +01:00
parent 81fa7a9f56
commit 6299722c47
1 changed files with 62 additions and 83 deletions

View File

@ -507,9 +507,7 @@ drm_intel_gem_bo_busy(drm_intel_bo *bo)
memset(&busy, 0, sizeof(busy)); memset(&busy, 0, sizeof(busy));
busy.handle = bo_gem->gem_handle; busy.handle = bo_gem->gem_handle;
do { ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_BUSY, &busy);
ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_BUSY, &busy);
} while (ret == -1 && errno == EINTR);
return (ret == 0 && busy.busy); return (ret == 0 && busy.busy);
} }
@ -523,7 +521,7 @@ drm_intel_gem_bo_madvise_internal(drm_intel_bufmgr_gem *bufmgr_gem,
madv.handle = bo_gem->gem_handle; madv.handle = bo_gem->gem_handle;
madv.madv = state; madv.madv = state;
madv.retained = 1; madv.retained = 1;
ioctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_MADVISE, &madv); drmIoctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_MADVISE, &madv);
return madv.retained; return madv.retained;
} }
@ -650,11 +648,9 @@ retry:
memset(&create, 0, sizeof(create)); memset(&create, 0, sizeof(create));
create.size = bo_size; create.size = bo_size;
do { ret = drmIoctl(bufmgr_gem->fd,
ret = ioctl(bufmgr_gem->fd,
DRM_IOCTL_I915_GEM_CREATE, DRM_IOCTL_I915_GEM_CREATE,
&create); &create);
} while (ret == -1 && errno == EINTR);
bo_gem->gem_handle = create.handle; bo_gem->gem_handle = create.handle;
bo_gem->bo.handle = bo_gem->gem_handle; bo_gem->bo.handle = bo_gem->gem_handle;
if (ret != 0) { if (ret != 0) {
@ -782,11 +778,9 @@ drm_intel_bo_gem_create_from_name(drm_intel_bufmgr *bufmgr,
memset(&open_arg, 0, sizeof(open_arg)); memset(&open_arg, 0, sizeof(open_arg));
open_arg.name = handle; open_arg.name = handle;
do { ret = drmIoctl(bufmgr_gem->fd,
ret = ioctl(bufmgr_gem->fd,
DRM_IOCTL_GEM_OPEN, DRM_IOCTL_GEM_OPEN,
&open_arg); &open_arg);
} while (ret == -1 && errno == EINTR);
if (ret != 0) { if (ret != 0) {
fprintf(stderr, "Couldn't reference %s handle 0x%08x: %s\n", fprintf(stderr, "Couldn't reference %s handle 0x%08x: %s\n",
name, handle, strerror(errno)); name, handle, strerror(errno));
@ -806,7 +800,9 @@ drm_intel_bo_gem_create_from_name(drm_intel_bufmgr *bufmgr,
memset(&get_tiling, 0, sizeof(get_tiling)); memset(&get_tiling, 0, sizeof(get_tiling));
get_tiling.handle = bo_gem->gem_handle; get_tiling.handle = bo_gem->gem_handle;
ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_GET_TILING, &get_tiling); ret = drmIoctl(bufmgr_gem->fd,
DRM_IOCTL_I915_GEM_GET_TILING,
&get_tiling);
if (ret != 0) { if (ret != 0) {
drm_intel_gem_bo_unreference(&bo_gem->bo); drm_intel_gem_bo_unreference(&bo_gem->bo);
return NULL; return NULL;
@ -837,7 +833,7 @@ drm_intel_gem_bo_free(drm_intel_bo *bo)
/* Close this object */ /* Close this object */
memset(&close, 0, sizeof(close)); memset(&close, 0, sizeof(close));
close.handle = bo_gem->gem_handle; close.handle = bo_gem->gem_handle;
ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_GEM_CLOSE, &close); ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_GEM_CLOSE, &close);
if (ret != 0) { if (ret != 0) {
fprintf(stderr, fprintf(stderr,
"DRM_IOCTL_GEM_CLOSE %d failed (%s): %s\n", "DRM_IOCTL_GEM_CLOSE %d failed (%s): %s\n",
@ -974,11 +970,9 @@ static int drm_intel_gem_bo_map(drm_intel_bo *bo, int write_enable)
mmap_arg.handle = bo_gem->gem_handle; mmap_arg.handle = bo_gem->gem_handle;
mmap_arg.offset = 0; mmap_arg.offset = 0;
mmap_arg.size = bo->size; mmap_arg.size = bo->size;
do { ret = drmIoctl(bufmgr_gem->fd,
ret = ioctl(bufmgr_gem->fd,
DRM_IOCTL_I915_GEM_MMAP, DRM_IOCTL_I915_GEM_MMAP,
&mmap_arg); &mmap_arg);
} while (ret == -1 && errno == EINTR);
if (ret != 0) { if (ret != 0) {
ret = -errno; ret = -errno;
fprintf(stderr, fprintf(stderr,
@ -1000,11 +994,9 @@ static int drm_intel_gem_bo_map(drm_intel_bo *bo, int write_enable)
set_domain.write_domain = I915_GEM_DOMAIN_CPU; set_domain.write_domain = I915_GEM_DOMAIN_CPU;
else else
set_domain.write_domain = 0; set_domain.write_domain = 0;
do { ret = drmIoctl(bufmgr_gem->fd,
ret = ioctl(bufmgr_gem->fd,
DRM_IOCTL_I915_GEM_SET_DOMAIN, DRM_IOCTL_I915_GEM_SET_DOMAIN,
&set_domain); &set_domain);
} while (ret == -1 && errno == EINTR);
if (ret != 0) { if (ret != 0) {
fprintf(stderr, "%s:%d: Error setting to CPU domain %d: %s\n", fprintf(stderr, "%s:%d: Error setting to CPU domain %d: %s\n",
__FILE__, __LINE__, bo_gem->gem_handle, __FILE__, __LINE__, bo_gem->gem_handle,
@ -1036,11 +1028,9 @@ int drm_intel_gem_bo_map_gtt(drm_intel_bo *bo)
mmap_arg.handle = bo_gem->gem_handle; mmap_arg.handle = bo_gem->gem_handle;
/* Get the fake offset back... */ /* Get the fake offset back... */
do { ret = drmIoctl(bufmgr_gem->fd,
ret = ioctl(bufmgr_gem->fd,
DRM_IOCTL_I915_GEM_MMAP_GTT, DRM_IOCTL_I915_GEM_MMAP_GTT,
&mmap_arg); &mmap_arg);
} while (ret == -1 && errno == EINTR);
if (ret != 0) { if (ret != 0) {
ret = -errno; ret = -errno;
fprintf(stderr, fprintf(stderr,
@ -1078,11 +1068,9 @@ int drm_intel_gem_bo_map_gtt(drm_intel_bo *bo)
set_domain.handle = bo_gem->gem_handle; set_domain.handle = bo_gem->gem_handle;
set_domain.read_domains = I915_GEM_DOMAIN_GTT; set_domain.read_domains = I915_GEM_DOMAIN_GTT;
set_domain.write_domain = I915_GEM_DOMAIN_GTT; set_domain.write_domain = I915_GEM_DOMAIN_GTT;
do { ret = drmIoctl(bufmgr_gem->fd,
ret = ioctl(bufmgr_gem->fd,
DRM_IOCTL_I915_GEM_SET_DOMAIN, DRM_IOCTL_I915_GEM_SET_DOMAIN,
&set_domain); &set_domain);
} while (ret == -1 && errno == EINTR);
if (ret != 0) { if (ret != 0) {
fprintf(stderr, "%s:%d: Error setting domain %d: %s\n", fprintf(stderr, "%s:%d: Error setting domain %d: %s\n",
__FILE__, __LINE__, bo_gem->gem_handle, __FILE__, __LINE__, bo_gem->gem_handle,
@ -1130,11 +1118,9 @@ static int drm_intel_gem_bo_unmap(drm_intel_bo *bo)
* results show up in a timely manner. * results show up in a timely manner.
*/ */
sw_finish.handle = bo_gem->gem_handle; sw_finish.handle = bo_gem->gem_handle;
do { ret = drmIoctl(bufmgr_gem->fd,
ret = ioctl(bufmgr_gem->fd,
DRM_IOCTL_I915_GEM_SW_FINISH, DRM_IOCTL_I915_GEM_SW_FINISH,
&sw_finish); &sw_finish);
} while (ret == -1 && errno == EINTR);
ret = ret == -1 ? -errno : 0; ret = ret == -1 ? -errno : 0;
bo->virtual = NULL; bo->virtual = NULL;
@ -1157,11 +1143,9 @@ drm_intel_gem_bo_subdata(drm_intel_bo *bo, unsigned long offset,
pwrite.offset = offset; pwrite.offset = offset;
pwrite.size = size; pwrite.size = size;
pwrite.data_ptr = (uint64_t) (uintptr_t) data; pwrite.data_ptr = (uint64_t) (uintptr_t) data;
do { ret = drmIoctl(bufmgr_gem->fd,
ret = ioctl(bufmgr_gem->fd,
DRM_IOCTL_I915_GEM_PWRITE, DRM_IOCTL_I915_GEM_PWRITE,
&pwrite); &pwrite);
} while (ret == -1 && errno == EINTR);
if (ret != 0) { if (ret != 0) {
ret = -errno; ret = -errno;
fprintf(stderr, fprintf(stderr,
@ -1181,7 +1165,8 @@ drm_intel_gem_get_pipe_from_crtc_id(drm_intel_bufmgr *bufmgr, int crtc_id)
int ret; int ret;
get_pipe_from_crtc_id.crtc_id = crtc_id; get_pipe_from_crtc_id.crtc_id = crtc_id;
ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_I915_GET_PIPE_FROM_CRTC_ID, ret = drmIoctl(bufmgr_gem->fd,
DRM_IOCTL_I915_GET_PIPE_FROM_CRTC_ID,
&get_pipe_from_crtc_id); &get_pipe_from_crtc_id);
if (ret != 0) { if (ret != 0) {
/* We return -1 here to signal that we don't /* We return -1 here to signal that we don't
@ -1210,11 +1195,9 @@ drm_intel_gem_bo_get_subdata(drm_intel_bo *bo, unsigned long offset,
pread.offset = offset; pread.offset = offset;
pread.size = size; pread.size = size;
pread.data_ptr = (uint64_t) (uintptr_t) data; pread.data_ptr = (uint64_t) (uintptr_t) data;
do { ret = drmIoctl(bufmgr_gem->fd,
ret = ioctl(bufmgr_gem->fd,
DRM_IOCTL_I915_GEM_PREAD, DRM_IOCTL_I915_GEM_PREAD,
&pread); &pread);
} while (ret == -1 && errno == EINTR);
if (ret != 0) { if (ret != 0) {
ret = -errno; ret = -errno;
fprintf(stderr, fprintf(stderr,
@ -1251,11 +1234,9 @@ drm_intel_gem_bo_start_gtt_access(drm_intel_bo *bo, int write_enable)
set_domain.handle = bo_gem->gem_handle; set_domain.handle = bo_gem->gem_handle;
set_domain.read_domains = I915_GEM_DOMAIN_GTT; set_domain.read_domains = I915_GEM_DOMAIN_GTT;
set_domain.write_domain = write_enable ? I915_GEM_DOMAIN_GTT : 0; set_domain.write_domain = write_enable ? I915_GEM_DOMAIN_GTT : 0;
do { ret = drmIoctl(bufmgr_gem->fd,
ret = ioctl(bufmgr_gem->fd,
DRM_IOCTL_I915_GEM_SET_DOMAIN, DRM_IOCTL_I915_GEM_SET_DOMAIN,
&set_domain); &set_domain);
} while (ret == -1 && errno == EINTR);
if (ret != 0) { if (ret != 0) {
fprintf(stderr, fprintf(stderr,
"%s:%d: Error setting memory domains %d (%08x %08x): %s .\n", "%s:%d: Error setting memory domains %d (%08x %08x): %s .\n",
@ -1526,12 +1507,9 @@ drm_intel_gem_bo_exec(drm_intel_bo *bo, int used,
execbuf.DR1 = 0; execbuf.DR1 = 0;
execbuf.DR4 = DR4; execbuf.DR4 = DR4;
do { ret = drmIoctl(bufmgr_gem->fd,
ret = ioctl(bufmgr_gem->fd,
DRM_IOCTL_I915_GEM_EXECBUFFER, DRM_IOCTL_I915_GEM_EXECBUFFER,
&execbuf); &execbuf);
} while (ret != 0 && errno == EINTR);
if (ret != 0) { if (ret != 0) {
ret = -errno; ret = -errno;
if (errno == ENOSPC) { if (errno == ENOSPC) {
@ -1599,11 +1577,9 @@ drm_intel_gem_bo_mrb_exec2(drm_intel_bo *bo, int used,
execbuf.rsvd1 = 0; execbuf.rsvd1 = 0;
execbuf.rsvd2 = 0; execbuf.rsvd2 = 0;
do { ret = drmIoctl(bufmgr_gem->fd,
ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, DRM_IOCTL_I915_GEM_EXECBUFFER2,
&execbuf); &execbuf);
} while (ret != 0 && errno == EINTR);
if (ret != 0) { if (ret != 0) {
ret = -errno; ret = -errno;
if (ret == -ENOSPC) { if (ret == -ENOSPC) {
@ -1658,12 +1634,9 @@ drm_intel_gem_bo_pin(drm_intel_bo *bo, uint32_t alignment)
pin.handle = bo_gem->gem_handle; pin.handle = bo_gem->gem_handle;
pin.alignment = alignment; pin.alignment = alignment;
do { ret = drmIoctl(bufmgr_gem->fd,
ret = ioctl(bufmgr_gem->fd,
DRM_IOCTL_I915_GEM_PIN, DRM_IOCTL_I915_GEM_PIN,
&pin); &pin);
} while (ret == -1 && errno == EINTR);
if (ret != 0) if (ret != 0)
return -errno; return -errno;
@ -1682,7 +1655,7 @@ drm_intel_gem_bo_unpin(drm_intel_bo *bo)
memset(&unpin, 0, sizeof(unpin)); memset(&unpin, 0, sizeof(unpin));
unpin.handle = bo_gem->gem_handle; unpin.handle = bo_gem->gem_handle;
ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_UNPIN, &unpin); ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_UNPIN, &unpin);
if (ret != 0) if (ret != 0)
return -errno; return -errno;
@ -1706,6 +1679,10 @@ drm_intel_gem_bo_set_tiling_internal(drm_intel_bo *bo,
memset(&set_tiling, 0, sizeof(set_tiling)); memset(&set_tiling, 0, sizeof(set_tiling));
do { do {
/* set_tiling is slightly broken and overwrites the
* input on the error path, so we have to open code
* rmIoctl.
*/
set_tiling.handle = bo_gem->gem_handle; set_tiling.handle = bo_gem->gem_handle;
set_tiling.tiling_mode = tiling_mode; set_tiling.tiling_mode = tiling_mode;
set_tiling.stride = stride; set_tiling.stride = stride;
@ -1713,7 +1690,7 @@ drm_intel_gem_bo_set_tiling_internal(drm_intel_bo *bo,
ret = ioctl(bufmgr_gem->fd, ret = ioctl(bufmgr_gem->fd,
DRM_IOCTL_I915_GEM_SET_TILING, DRM_IOCTL_I915_GEM_SET_TILING,
&set_tiling); &set_tiling);
} while (ret == -1 && errno == EINTR); } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
if (ret == -1) if (ret == -1)
return -errno; return -errno;
@ -1768,7 +1745,7 @@ drm_intel_gem_bo_flink(drm_intel_bo *bo, uint32_t * name)
memset(&flink, 0, sizeof(flink)); memset(&flink, 0, sizeof(flink));
flink.handle = bo_gem->gem_handle; flink.handle = bo_gem->gem_handle;
ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_GEM_FLINK, &flink); ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_GEM_FLINK, &flink);
if (ret != 0) if (ret != 0)
return -errno; return -errno;
bo_gem->global_name = flink.name; bo_gem->global_name = flink.name;
@ -2099,7 +2076,9 @@ drm_intel_bufmgr_gem_init(int fd, int batch_size)
return NULL; return NULL;
} }
ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_GET_APERTURE, &aperture); ret = drmIoctl(bufmgr_gem->fd,
DRM_IOCTL_I915_GEM_GET_APERTURE,
&aperture);
if (ret == 0) if (ret == 0)
bufmgr_gem->gtt_size = aperture.aper_available_size; bufmgr_gem->gtt_size = aperture.aper_available_size;
@ -2115,7 +2094,7 @@ drm_intel_bufmgr_gem_init(int fd, int batch_size)
gp.param = I915_PARAM_CHIPSET_ID; gp.param = I915_PARAM_CHIPSET_ID;
gp.value = &bufmgr_gem->pci_device; gp.value = &bufmgr_gem->pci_device;
ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_I915_GETPARAM, &gp); ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_I915_GETPARAM, &gp);
if (ret) { if (ret) {
fprintf(stderr, "get chip id failed: %d [%d]\n", ret, errno); fprintf(stderr, "get chip id failed: %d [%d]\n", ret, errno);
fprintf(stderr, "param: %d, val: %d\n", gp.param, *gp.value); fprintf(stderr, "param: %d, val: %d\n", gp.param, *gp.value);
@ -2131,19 +2110,19 @@ drm_intel_bufmgr_gem_init(int fd, int batch_size)
bufmgr_gem->gen = 6; bufmgr_gem->gen = 6;
gp.param = I915_PARAM_HAS_EXECBUF2; gp.param = I915_PARAM_HAS_EXECBUF2;
ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_I915_GETPARAM, &gp); ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_I915_GETPARAM, &gp);
if (!ret) if (!ret)
exec2 = 1; exec2 = 1;
gp.param = I915_PARAM_HAS_BSD; gp.param = I915_PARAM_HAS_BSD;
ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_I915_GETPARAM, &gp); ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_I915_GETPARAM, &gp);
if (!ret) if (!ret)
has_bsd = 1; has_bsd = 1;
if (bufmgr_gem->gen < 4) { if (bufmgr_gem->gen < 4) {
gp.param = I915_PARAM_NUM_FENCES_AVAIL; gp.param = I915_PARAM_NUM_FENCES_AVAIL;
gp.value = &bufmgr_gem->available_fences; gp.value = &bufmgr_gem->available_fences;
ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_I915_GETPARAM, &gp); ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_I915_GETPARAM, &gp);
if (ret) { if (ret) {
fprintf(stderr, "get fences failed: %d [%d]\n", ret, fprintf(stderr, "get fences failed: %d [%d]\n", ret,
errno); errno);