Make gem_mmap__{cpu,gtt,wc}() assert on failure

Rename the current gem_mmap__{cpu,gtt,wc}() functions into
__gem_mmap__{cpu,gtt,wc}(), and add back wrappers with the original name
that assert that the pointer is valid. Most callers will expect a valid
pointer and shouldn't have to bother with failures.

To avoid changing anything (yet), sed 's/gem_mmap__/__gem_mmap__/g'
over the entire codebase.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Stochastically-reviwewed-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
Ville Syrjälä
2015-10-09 18:29:28 +03:00
parent 106fe21373
commit b8a77dd6c8
52 changed files with 212 additions and 152 deletions
+3 -3
View File
@@ -252,7 +252,7 @@ static void draw_rect_mmap_cpu(int fd, struct buf_data *buf, struct rect *rect,
if (tiling != I915_TILING_NONE)
igt_require(intel_gen(intel_get_drm_devid(fd)) >= 5);
ptr = gem_mmap__cpu(fd, buf->handle, 0, buf->size, 0);
ptr = __gem_mmap__cpu(fd, buf->handle, 0, buf->size, 0);
igt_assert(ptr);
switch (tiling) {
@@ -281,7 +281,7 @@ static void draw_rect_mmap_gtt(int fd, struct buf_data *buf, struct rect *rect,
gem_set_domain(fd, buf->handle, I915_GEM_DOMAIN_GTT,
I915_GEM_DOMAIN_GTT);
ptr = gem_mmap__gtt(fd, buf->handle, buf->size, PROT_READ | PROT_WRITE);
ptr = __gem_mmap__gtt(fd, buf->handle, buf->size, PROT_READ | PROT_WRITE);
igt_assert(ptr);
draw_rect_ptr_linear(ptr, buf->stride, rect, color, buf->bpp);
@@ -303,7 +303,7 @@ static void draw_rect_mmap_wc(int fd, struct buf_data *buf, struct rect *rect,
if (tiling != I915_TILING_NONE)
igt_require(intel_gen(intel_get_drm_devid(fd)) >= 5);
ptr = gem_mmap__wc(fd, buf->handle, 0, buf->size,
ptr = __gem_mmap__wc(fd, buf->handle, 0, buf->size,
PROT_READ | PROT_WRITE);
igt_assert(ptr);
+2 -2
View File
@@ -745,7 +745,7 @@ static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
/* Setup cairo context */
blit->linear.map = gem_mmap__cpu(fd,
blit->linear.map = __gem_mmap__cpu(fd,
blit->linear.handle,
0,
blit->linear.size,
@@ -774,7 +774,7 @@ static void destroy_cairo_surface__gtt(void *arg)
static void create_cairo_surface__gtt(int fd, struct igt_fb *fb)
{
void *ptr = gem_mmap__gtt(fd, fb->gem_handle, fb->size, PROT_READ | PROT_WRITE);
void *ptr = __gem_mmap__gtt(fd, fb->gem_handle, fb->size, PROT_READ | PROT_WRITE);
igt_assert(ptr);
fb->cairo_surface =
+62 -6
View File
@@ -447,7 +447,7 @@ void gem_execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf)
}
/**
* gem_mmap__gtt:
* __gem_mmap__gtt:
* @fd: open i915 drm file descriptor
* @handle: gem buffer object handle
* @size: size of the gem buffer
@@ -458,7 +458,7 @@ void gem_execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf)
*
* Returns: A pointer to the created memory mapping, NULL on failure.
*/
void *gem_mmap__gtt(int fd, uint32_t handle, uint64_t size, unsigned prot)
void *__gem_mmap__gtt(int fd, uint32_t handle, uint64_t size, unsigned prot)
{
struct drm_i915_gem_mmap_gtt mmap_arg;
void *ptr;
@@ -477,6 +477,24 @@ void *gem_mmap__gtt(int fd, uint32_t handle, uint64_t size, unsigned prot)
return ptr;
}
/**
* gem_mmap__gtt:
* @fd: open i915 drm file descriptor
* @handle: gem buffer object handle
* @size: size of the gem buffer
* @prot: memory protection bits as used by mmap()
*
* Like __gem_mmap__gtt() except we assert on failure.
*
* Returns: A pointer to the created memory mapping
*/
void *gem_mmap__gtt(int fd, uint32_t handle, uint64_t size, unsigned prot)
{
void *ptr = __gem_mmap__gtt(fd, handle, size, prot);
igt_assert(ptr);
return ptr;
}
struct local_i915_gem_mmap_v2 {
uint32_t handle;
uint32_t pad;
@@ -523,7 +541,7 @@ bool gem_mmap__has_wc(int fd)
}
/**
* gem_mmap__wc:
* __gem_mmap__wc:
* @fd: open i915 drm file descriptor
* @handle: gem buffer object handle
* @offset: offset in the gem buffer of the mmap arena
@@ -537,7 +555,7 @@ bool gem_mmap__has_wc(int fd)
*
* Returns: A pointer to the created memory mapping, NULL on failure.
*/
void *gem_mmap__wc(int fd, uint32_t handle, uint64_t offset, uint64_t size, unsigned prot)
void *__gem_mmap__wc(int fd, uint32_t handle, uint64_t offset, uint64_t size, unsigned prot)
{
struct local_i915_gem_mmap_v2 arg;
@@ -559,7 +577,26 @@ void *gem_mmap__wc(int fd, uint32_t handle, uint64_t offset, uint64_t size, unsi
}
/**
* gem_mmap__cpu:
* gem_mmap__wc:
* @fd: open i915 drm file descriptor
* @handle: gem buffer object handle
* @offset: offset in the gem buffer of the mmap arena
* @size: size of the mmap arena
* @prot: memory protection bits as used by mmap()
*
* Like __gem_mmap__wc() except we assert on failure.
*
* Returns: A pointer to the created memory mapping
*/
void *gem_mmap__wc(int fd, uint32_t handle, uint64_t offset, uint64_t size, unsigned prot)
{
void *ptr = __gem_mmap__wc(fd, handle, offset, size, prot);
igt_assert(ptr);
return ptr;
}
/**
* __gem_mmap__cpu:
* @fd: open i915 drm file descriptor
* @handle: gem buffer object handle
* @offset: offset in the gem buffer of the mmap arena
@@ -571,7 +608,7 @@ void *gem_mmap__wc(int fd, uint32_t handle, uint64_t offset, uint64_t size, unsi
*
* Returns: A pointer to the created memory mapping, NULL on failure.
*/
void *gem_mmap__cpu(int fd, uint32_t handle, uint64_t offset, uint64_t size, unsigned prot)
void *__gem_mmap__cpu(int fd, uint32_t handle, uint64_t offset, uint64_t size, unsigned prot)
{
struct drm_i915_gem_mmap mmap_arg;
@@ -586,6 +623,25 @@ void *gem_mmap__cpu(int fd, uint32_t handle, uint64_t offset, uint64_t size, uns
return (void *)(uintptr_t)mmap_arg.addr_ptr;
}
/**
* gem_mmap__cpu:
* @fd: open i915 drm file descriptor
* @handle: gem buffer object handle
* @offset: offset in the gem buffer of the mmap arena
* @size: size of the mmap arena
* @prot: memory protection bits as used by mmap()
*
* Like __gem_mmap__cpu() except we assert on failure.
*
* Returns: A pointer to the created memory mapping
*/
void *gem_mmap__cpu(int fd, uint32_t handle, uint64_t offset, uint64_t size, unsigned prot)
{
void *ptr = __gem_mmap__cpu(fd, handle, offset, size, prot);
igt_assert(ptr);
return ptr;
}
/**
* gem_madvise:
* @fd: open i915 drm file descriptor
+4
View File
@@ -66,6 +66,10 @@ void *gem_mmap__cpu(int fd, uint32_t handle, uint64_t offset, uint64_t size, uns
bool gem_mmap__has_wc(int fd);
void *gem_mmap__wc(int fd, uint32_t handle, uint64_t offset, uint64_t size, unsigned prot);
void *__gem_mmap__gtt(int fd, uint32_t handle, uint64_t size, unsigned prot);
void *__gem_mmap__cpu(int fd, uint32_t handle, uint64_t offset, uint64_t size, unsigned prot);
void *__gem_mmap__wc(int fd, uint32_t handle, uint64_t offset, uint64_t size, unsigned prot);
/**
* gem_require_mmap_wc:
* @fd: open i915 drm file descriptor