From b8a77dd6c8e9f73493b2f86f293ff9c06fc08049 Mon Sep 17 00:00:00 2001 From: Ville Syrjälä Date: Fri, 9 Oct 2015 18:29:28 +0300 Subject: Make gem_mmap__{cpu,gtt,wc}() assert on failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ä Stochastically-reviwewed-by: Chris Wilson --- lib/ioctl_wrappers.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 6 deletions(-) (limited to 'lib/ioctl_wrappers.c') diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c index eb745bc0..36982a73 100644 --- a/lib/ioctl_wrappers.c +++ b/lib/ioctl_wrappers.c @@ -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 -- cgit v1.2.3