From 2655005762b8915d5f44d1d1ee7e6c2eb34841d7 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 11 Jun 2008 14:42:40 -0700 Subject: [gem] Move potentially device-specific ioctls to the intel driver. This is the create (may want location flags), pread/pwrite/mmap (performance tuning hints), and set_domain (will 32 bits be enough for everyone?) ioctls. Left in the generic set are just flink/open/close. The 2D driver must be updated for this change, and API but not ABI is broken for 3D. The driver version is bumped to mark this. --- libdrm/intel/intel_bufmgr_fake.c | 2 +- libdrm/intel/intel_bufmgr_gem.c | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) (limited to 'libdrm/intel') diff --git a/libdrm/intel/intel_bufmgr_fake.c b/libdrm/intel/intel_bufmgr_fake.c index 3f5a22d3..06e85b2b 100644 --- a/libdrm/intel/intel_bufmgr_fake.c +++ b/libdrm/intel/intel_bufmgr_fake.c @@ -1062,7 +1062,7 @@ dri_fake_process_relocs(dri_bo *batch_buf) dri_fake_calculate_domains(batch_buf); - batch_fake->read_domains = DRM_GEM_DOMAIN_I915_COMMAND; + batch_fake->read_domains = I915_GEM_DOMAIN_COMMAND; /* we've ran out of RAM so blow the whole lot away and retry */ restart: diff --git a/libdrm/intel/intel_bufmgr_gem.c b/libdrm/intel/intel_bufmgr_gem.c index a65ae982..e057d949 100644 --- a/libdrm/intel/intel_bufmgr_gem.c +++ b/libdrm/intel/intel_bufmgr_gem.c @@ -299,7 +299,7 @@ dri_gem_bo_alloc(dri_bufmgr *bufmgr, const char *name, } if (!alloc_from_cache) { - struct drm_gem_create create; + struct drm_i915_gem_create create; bo_gem = calloc(1, sizeof(*bo_gem)); if (!bo_gem) @@ -309,7 +309,7 @@ dri_gem_bo_alloc(dri_bufmgr *bufmgr, const char *name, memset(&create, 0, sizeof(create)); create.size = bo_size; - ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_GEM_CREATE, &create); + ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_CREATE, &create); bo_gem->gem_handle = create.handle; if (ret != 0) { free(bo_gem); @@ -455,7 +455,7 @@ dri_gem_bo_map(dri_bo *bo, int write_enable) { dri_bufmgr_gem *bufmgr_gem; dri_bo_gem *bo_gem = (dri_bo_gem *)bo; - struct drm_gem_set_domain set_domain; + struct drm_i915_gem_set_domain set_domain; int ret; bufmgr_gem = (dri_bufmgr_gem *)bo->bufmgr; @@ -470,13 +470,13 @@ dri_gem_bo_map(dri_bo *bo, int write_enable) DBG("bo_map: %d (%s)\n", bo_gem->gem_handle, bo_gem->name); if (bo_gem->virtual == NULL) { - struct drm_gem_mmap mmap_arg; + struct drm_i915_gem_mmap mmap_arg; memset(&mmap_arg, 0, sizeof(mmap_arg)); mmap_arg.handle = bo_gem->gem_handle; mmap_arg.offset = 0; mmap_arg.size = bo->size; - ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_GEM_MMAP, &mmap_arg); + ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_MMAP, &mmap_arg); if (ret != 0) { fprintf(stderr, "%s:%d: Error mapping buffer %d (%s): %s .\n", __FILE__, __LINE__, @@ -491,9 +491,9 @@ dri_gem_bo_map(dri_bo *bo, int write_enable) if (!bo_gem->cpu_domain_set) { set_domain.handle = bo_gem->gem_handle; - set_domain.read_domains = DRM_GEM_DOMAIN_CPU; - set_domain.write_domain = write_enable ? DRM_GEM_DOMAIN_CPU : 0; - ret = ioctl (bufmgr_gem->fd, DRM_IOCTL_GEM_SET_DOMAIN, &set_domain); + set_domain.read_domains = I915_GEM_DOMAIN_CPU; + set_domain.write_domain = write_enable ? I915_GEM_DOMAIN_CPU : 0; + ret = ioctl (bufmgr_gem->fd, DRM_IOCTL_I915_GEM_SET_DOMAIN, &set_domain); if (ret != 0) { fprintf (stderr, "%s:%d: Error setting memory domains %d (%08x %08x): %s .\n", __FILE__, __LINE__, @@ -525,7 +525,7 @@ dri_gem_bo_subdata (dri_bo *bo, unsigned long offset, { dri_bufmgr_gem *bufmgr_gem = (dri_bufmgr_gem *)bo->bufmgr; dri_bo_gem *bo_gem = (dri_bo_gem *)bo; - struct drm_gem_pwrite pwrite; + struct drm_i915_gem_pwrite pwrite; int ret; memset (&pwrite, 0, sizeof (pwrite)); @@ -533,7 +533,7 @@ dri_gem_bo_subdata (dri_bo *bo, unsigned long offset, pwrite.offset = offset; pwrite.size = size; pwrite.data_ptr = (uint64_t) (uintptr_t) data; - ret = ioctl (bufmgr_gem->fd, DRM_IOCTL_GEM_PWRITE, &pwrite); + ret = ioctl (bufmgr_gem->fd, DRM_IOCTL_I915_GEM_PWRITE, &pwrite); if (ret != 0) { fprintf (stderr, "%s:%d: Error writing data to buffer %d: (%d %d) %s .\n", __FILE__, __LINE__, @@ -549,7 +549,7 @@ dri_gem_bo_get_subdata (dri_bo *bo, unsigned long offset, { dri_bufmgr_gem *bufmgr_gem = (dri_bufmgr_gem *)bo->bufmgr; dri_bo_gem *bo_gem = (dri_bo_gem *)bo; - struct drm_gem_pread pread; + struct drm_i915_gem_pread pread; int ret; memset (&pread, 0, sizeof (pread)); @@ -557,7 +557,7 @@ dri_gem_bo_get_subdata (dri_bo *bo, unsigned long offset, pread.offset = offset; pread.size = size; pread.data_ptr = (uint64_t) (uintptr_t) data; - ret = ioctl (bufmgr_gem->fd, DRM_IOCTL_GEM_PREAD, &pread); + ret = ioctl (bufmgr_gem->fd, DRM_IOCTL_I915_GEM_PREAD, &pread); if (ret != 0) { fprintf (stderr, "%s:%d: Error reading data from buffer %d: (%d %d) %s .\n", __FILE__, __LINE__, @@ -572,13 +572,13 @@ dri_gem_bo_wait_rendering(dri_bo *bo) { dri_bufmgr_gem *bufmgr_gem = (dri_bufmgr_gem *)bo->bufmgr; dri_bo_gem *bo_gem = (dri_bo_gem *)bo; - struct drm_gem_set_domain set_domain; + struct drm_i915_gem_set_domain set_domain; int ret; set_domain.handle = bo_gem->gem_handle; - set_domain.read_domains = DRM_GEM_DOMAIN_CPU; + set_domain.read_domains = I915_GEM_DOMAIN_CPU; set_domain.write_domain = 0; - ret = ioctl (bufmgr_gem->fd, DRM_IOCTL_GEM_SET_DOMAIN, &set_domain); + ret = ioctl (bufmgr_gem->fd, DRM_IOCTL_I915_GEM_SET_DOMAIN, &set_domain); if (ret != 0) { fprintf (stderr, "%s:%d: Error setting memory domains %d (%08x %08x): %s .\n", __FILE__, __LINE__, -- cgit v1.2.3 From 57b4c4c32d3b474939775042bb8a17423def446d Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 11 Jun 2008 15:58:33 -0700 Subject: Move the renaming of mm.c symbols to #defines in the header. This reduces the diff from Mesa and reduces the illegibility of what I did. --- libdrm/intel/intel_bufmgr_fake.c | 12 ++++++------ libdrm/intel/mm.c | 12 ++++++------ libdrm/intel/mm.h | 22 +++++++++++++++------- 3 files changed, 27 insertions(+), 19 deletions(-) (limited to 'libdrm/intel') diff --git a/libdrm/intel/intel_bufmgr_fake.c b/libdrm/intel/intel_bufmgr_fake.c index 06e85b2b..e988eb58 100644 --- a/libdrm/intel/intel_bufmgr_fake.c +++ b/libdrm/intel/intel_bufmgr_fake.c @@ -252,7 +252,7 @@ alloc_block(dri_bo *bo) sz = (bo->size + bo_fake->alignment - 1) & ~(bo_fake->alignment - 1); - block->mem = drmmmAllocMem(bufmgr_fake->heap, sz, align_log2, 0); + block->mem = mmAllocMem(bufmgr_fake->heap, sz, align_log2, 0); if (!block->mem) { free(block); return 0; @@ -300,7 +300,7 @@ static void free_block(dri_bufmgr_fake *bufmgr_fake, struct block *block) DBG(" - free immediately\n"); DRMLISTDEL(block); - drmmmFreeMem(block->mem); + mmFreeMem(block->mem); free(block); } } @@ -415,7 +415,7 @@ static int clear_fenced(dri_bufmgr_fake *bufmgr_fake, DBG("delayed free: offset %x sz %x\n", block->mem->ofs, block->mem->size); DRMLISTDEL(block); - drmmmFreeMem(block->mem); + mmFreeMem(block->mem); free(block); } else { @@ -923,7 +923,7 @@ dri_fake_destroy(dri_bufmgr *bufmgr) { dri_bufmgr_fake *bufmgr_fake = (dri_bufmgr_fake *)bufmgr; - drmmmDestroy(bufmgr_fake->heap); + mmDestroy(bufmgr_fake->heap); free(bufmgr); } @@ -1074,7 +1074,7 @@ dri_fake_process_relocs(dri_bo *batch_buf) bufmgr_fake->fail = 0; goto restart; } else /* dump out the memory here */ - drmmmDumpMemInfo(bufmgr_fake->heap); + mmDumpMemInfo(bufmgr_fake->heap); } assert(ret == 0); @@ -1193,7 +1193,7 @@ intel_bufmgr_fake_init(unsigned long low_offset, void *low_virtual, bufmgr_fake->low_offset = low_offset; bufmgr_fake->virtual = low_virtual; bufmgr_fake->size = size; - bufmgr_fake->heap = drmmmInit(low_offset, size); + bufmgr_fake->heap = mmInit(low_offset, size); /* Hook in methods */ bufmgr_fake->bufmgr.bo_alloc = dri_fake_bo_alloc; diff --git a/libdrm/intel/mm.c b/libdrm/intel/mm.c index 2605d8ec..98146405 100644 --- a/libdrm/intel/mm.c +++ b/libdrm/intel/mm.c @@ -29,7 +29,7 @@ #include "mm.h" void -drmmmDumpMemInfo(const struct mem_block *heap) +mmDumpMemInfo(const struct mem_block *heap) { drmMsg("Memory heap %p:\n", (void *)heap); if (heap == 0) { @@ -56,7 +56,7 @@ drmmmDumpMemInfo(const struct mem_block *heap) } struct mem_block * -drmmmInit(int ofs, int size) +mmInit(int ofs, int size) { struct mem_block *heap, *block; @@ -163,7 +163,7 @@ SliceBlock(struct mem_block *p, struct mem_block * -drmmmAllocMem(struct mem_block *heap, int size, int align2, int startSearch) +mmAllocMem(struct mem_block *heap, int size, int align2, int startSearch) { struct mem_block *p; const int mask = (1 << align2)-1; @@ -196,7 +196,7 @@ drmmmAllocMem(struct mem_block *heap, int size, int align2, int startSearch) struct mem_block * -drmmmFindBlock(struct mem_block *heap, int start) +mmFindBlock(struct mem_block *heap, int start) { struct mem_block *p; @@ -235,7 +235,7 @@ Join2Blocks(struct mem_block *p) } int -drmmmFreeMem(struct mem_block *b) +mmFreeMem(struct mem_block *b) { if (!b) return 0; @@ -264,7 +264,7 @@ drmmmFreeMem(struct mem_block *b) void -drmmmDestroy(struct mem_block *heap) +mmDestroy(struct mem_block *heap) { struct mem_block *p; diff --git a/libdrm/intel/mm.h b/libdrm/intel/mm.h index 965bb0cd..49e3eecc 100644 --- a/libdrm/intel/mm.h +++ b/libdrm/intel/mm.h @@ -40,13 +40,21 @@ struct mem_block { unsigned int reserved:1; }; - +/* Rename the variables in the drm copy of this code so that it doesn't + * conflict with mesa or whoever else has copied it around. + */ +#define mmInit drm_mmInit +#define mmAllocMem drm_mmAllocMem +#define mmFreeMem drm_mmFreeMem +#define mmFindBlock drm_mmFindBlock +#define mmDestroy drm_mmDestroy +#define mmDumpMemInfo drm_mmDumpMemInfo /** * input: total size in bytes * return: a heap pointer if OK, NULL if error */ -extern struct mem_block *drmmmInit(int ofs, int size); +extern struct mem_block *mmInit(int ofs, int size); /** * Allocate 'size' bytes with 2^align2 bytes alignment, @@ -58,7 +66,7 @@ extern struct mem_block *drmmmInit(int ofs, int size); * startSearch = linear offset from start of heap to begin search * return: pointer to the allocated block, 0 if error */ -extern struct mem_block *drmmmAllocMem(struct mem_block *heap, int size, +extern struct mem_block *mmAllocMem(struct mem_block *heap, int size, int align2, int startSearch); /** @@ -66,23 +74,23 @@ extern struct mem_block *drmmmAllocMem(struct mem_block *heap, int size, * input: pointer to a block * return: 0 if OK, -1 if error */ -extern int drmmmFreeMem(struct mem_block *b); +extern int mmFreeMem(struct mem_block *b); /** * Free block starts at offset * input: pointer to a heap, start offset * return: pointer to a block */ -extern struct mem_block *drmmmFindBlock(struct mem_block *heap, int start); +extern struct mem_block *mmFindBlock(struct mem_block *heap, int start); /** * destroy MM */ -extern void drmmmDestroy(struct mem_block *mmInit); +extern void mmDestroy(struct mem_block *mmInit); /** * For debuging purpose. */ -extern void drmmmDumpMemInfo(const struct mem_block *mmInit); +extern void mmDumpMemInfo(const struct mem_block *mmInit); #endif -- cgit v1.2.3 From e558e1d7dacafa1e7f9681f1eaec072d663287de Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Fri, 13 Jun 2008 10:04:14 -0700 Subject: [gem] Catch -EINTR from blocking ioctls and restart them. Thanks to Thomas Hellstrom for catching the issue, no thanks to the kernel developer who authoritatively told me that they would get restarted on their own. --- libdrm/intel/intel_bufmgr_gem.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'libdrm/intel') diff --git a/libdrm/intel/intel_bufmgr_gem.c b/libdrm/intel/intel_bufmgr_gem.c index e057d949..5a28bd14 100644 --- a/libdrm/intel/intel_bufmgr_gem.c +++ b/libdrm/intel/intel_bufmgr_gem.c @@ -493,7 +493,10 @@ dri_gem_bo_map(dri_bo *bo, int write_enable) set_domain.handle = bo_gem->gem_handle; set_domain.read_domains = I915_GEM_DOMAIN_CPU; set_domain.write_domain = write_enable ? I915_GEM_DOMAIN_CPU : 0; - ret = ioctl (bufmgr_gem->fd, DRM_IOCTL_I915_GEM_SET_DOMAIN, &set_domain); + do { + ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_SET_DOMAIN, + &set_domain); + } while (ret == -1 && errno == EINTR); if (ret != 0) { fprintf (stderr, "%s:%d: Error setting memory domains %d (%08x %08x): %s .\n", __FILE__, __LINE__, @@ -533,7 +536,9 @@ dri_gem_bo_subdata (dri_bo *bo, unsigned long offset, pwrite.offset = offset; pwrite.size = size; pwrite.data_ptr = (uint64_t) (uintptr_t) data; - ret = ioctl (bufmgr_gem->fd, DRM_IOCTL_I915_GEM_PWRITE, &pwrite); + do { + ret = ioctl (bufmgr_gem->fd, DRM_IOCTL_I915_GEM_PWRITE, &pwrite); + } while (ret == -1 && errno == EINTR); if (ret != 0) { fprintf (stderr, "%s:%d: Error writing data to buffer %d: (%d %d) %s .\n", __FILE__, __LINE__, @@ -557,7 +562,9 @@ dri_gem_bo_get_subdata (dri_bo *bo, unsigned long offset, pread.offset = offset; pread.size = size; pread.data_ptr = (uint64_t) (uintptr_t) data; - ret = ioctl (bufmgr_gem->fd, DRM_IOCTL_I915_GEM_PREAD, &pread); + do { + ret = ioctl (bufmgr_gem->fd, DRM_IOCTL_I915_GEM_PREAD, &pread); + } while (ret == -1 && errno == EINTR); if (ret != 0) { fprintf (stderr, "%s:%d: Error reading data from buffer %d: (%d %d) %s .\n", __FILE__, __LINE__, -- cgit v1.2.3