Commit 6fff1f87 authored by Chris Wilson's avatar Chris Wilson 😣

ioctl_wrappers: Pass in offset to CPU mmaps

Signed-off-by: Chris Wilson's avatarChris Wilson <chris@chris-wilson.co.uk>
parent 676ccf86
...@@ -471,7 +471,8 @@ void *gem_mmap__gtt(int fd, uint32_t handle, int size, int prot) ...@@ -471,7 +471,8 @@ void *gem_mmap__gtt(int fd, uint32_t handle, int size, int prot)
* gem_mmap__cpu: * gem_mmap__cpu:
* @fd: open i915 drm file descriptor * @fd: open i915 drm file descriptor
* @handle: gem buffer object handle * @handle: gem buffer object handle
* @size: size of the gem buffer * @offset: offset in the gem buffer of te mmap arena
* @size: size of the mmap arena
* @prot: memory protection bits as used by mmap() * @prot: memory protection bits as used by mmap()
* *
* This functions wraps up procedure to establish a memory mapping through * This functions wraps up procedure to establish a memory mapping through
...@@ -479,13 +480,13 @@ void *gem_mmap__gtt(int fd, uint32_t handle, int size, int prot) ...@@ -479,13 +480,13 @@ void *gem_mmap__gtt(int fd, uint32_t handle, int size, int prot)
* *
* Returns: A pointer to the created memory mapping. * Returns: A pointer to the created memory mapping.
*/ */
void *gem_mmap__cpu(int fd, uint32_t handle, int size, int prot) void *gem_mmap__cpu(int fd, uint32_t handle, int offset, int size, int prot)
{ {
struct drm_i915_gem_mmap mmap_arg; struct drm_i915_gem_mmap mmap_arg;
memset(&mmap_arg, 0, sizeof(mmap_arg)); memset(&mmap_arg, 0, sizeof(mmap_arg));
mmap_arg.handle = handle; mmap_arg.handle = handle;
mmap_arg.offset = 0; mmap_arg.offset = offset;
mmap_arg.size = size; mmap_arg.size = size;
if (drmIoctl(fd, DRM_IOCTL_I915_GEM_MMAP, &mmap_arg)) if (drmIoctl(fd, DRM_IOCTL_I915_GEM_MMAP, &mmap_arg))
return NULL; return NULL;
......
...@@ -61,7 +61,7 @@ uint32_t gem_create(int fd, int size); ...@@ -61,7 +61,7 @@ uint32_t gem_create(int fd, int size);
void gem_execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf); void gem_execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf);
void *gem_mmap__gtt(int fd, uint32_t handle, int size, int prot); void *gem_mmap__gtt(int fd, uint32_t handle, int size, int prot);
void *gem_mmap__cpu(int fd, uint32_t handle, int size, int prot); void *gem_mmap__cpu(int fd, uint32_t handle, int offset, int size, int prot);
/** /**
* gem_mmap: * gem_mmap:
* *
......
...@@ -116,7 +116,7 @@ static void run_on_ring(int fd, unsigned ring_id, const char *ring_name) ...@@ -116,7 +116,7 @@ static void run_on_ring(int fd, unsigned ring_id, const char *ring_name)
igt_progress(buf, split, BATCH_SIZE/8 - 1); igt_progress(buf, split, BATCH_SIZE/8 - 1);
handle_new = gem_create(fd, BATCH_SIZE); handle_new = gem_create(fd, BATCH_SIZE);
batch_ptr = gem_mmap__cpu(fd, handle_new, BATCH_SIZE, batch_ptr = gem_mmap__cpu(fd, handle_new, 0, BATCH_SIZE,
PROT_READ | PROT_WRITE); PROT_READ | PROT_WRITE);
batch_ptr[split*2] = MI_BATCH_BUFFER_END; batch_ptr[split*2] = MI_BATCH_BUFFER_END;
......
...@@ -131,7 +131,7 @@ copy(int fd, uint32_t dst, uint32_t src, uint32_t *all_bo, int n_bo) ...@@ -131,7 +131,7 @@ copy(int fd, uint32_t dst, uint32_t src, uint32_t *all_bo, int n_bo)
static void clear(int fd, uint32_t handle, int size) static void clear(int fd, uint32_t handle, int size)
{ {
void *base = gem_mmap__cpu(fd, handle, size, PROT_READ | PROT_WRITE); void *base = gem_mmap__cpu(fd, handle, 0, size, PROT_READ | PROT_WRITE);
igt_assert(base != NULL); igt_assert(base != NULL);
memset(base, 0, size); memset(base, 0, size);
......
...@@ -68,7 +68,7 @@ bo_create (int fd, int tiling) ...@@ -68,7 +68,7 @@ bo_create (int fd, int tiling)
handle = gem_create(fd, OBJECT_SIZE); handle = gem_create(fd, OBJECT_SIZE);
/* dirty cpu caches a bit ... */ /* dirty cpu caches a bit ... */
ptr = gem_mmap__cpu(fd, handle, OBJECT_SIZE, PROT_READ | PROT_WRITE); ptr = gem_mmap__cpu(fd, handle, 0, OBJECT_SIZE, PROT_READ | PROT_WRITE);
igt_assert(ptr); igt_assert(ptr);
memset(ptr, 0, OBJECT_SIZE); memset(ptr, 0, OBJECT_SIZE);
munmap(ptr, OBJECT_SIZE); munmap(ptr, OBJECT_SIZE);
......
...@@ -90,7 +90,7 @@ int main(int argc, char **argv) ...@@ -90,7 +90,7 @@ int main(int argc, char **argv)
I915_GEM_DOMAIN_CPU); I915_GEM_DOMAIN_CPU);
{ {
uint32_t *base = gem_mmap__cpu(fd, handle, size, PROT_READ | PROT_WRITE); uint32_t *base = gem_mmap__cpu(fd, handle, 0, size, PROT_READ | PROT_WRITE);
volatile uint32_t *ptr = base; volatile uint32_t *ptr = base;
int x = 0; int x = 0;
...@@ -105,7 +105,7 @@ int main(int argc, char **argv) ...@@ -105,7 +105,7 @@ int main(int argc, char **argv)
/* mmap read */ /* mmap read */
gettimeofday(&start, NULL); gettimeofday(&start, NULL);
for (loop = 0; loop < 1000; loop++) { for (loop = 0; loop < 1000; loop++) {
base = gem_mmap__cpu(fd, handle, size, PROT_READ | PROT_WRITE); base = gem_mmap__cpu(fd, handle, 0, size, PROT_READ | PROT_WRITE);
ptr = base; ptr = base;
x = 0; x = 0;
...@@ -124,7 +124,7 @@ int main(int argc, char **argv) ...@@ -124,7 +124,7 @@ int main(int argc, char **argv)
/* mmap write */ /* mmap write */
gettimeofday(&start, NULL); gettimeofday(&start, NULL);
for (loop = 0; loop < 1000; loop++) { for (loop = 0; loop < 1000; loop++) {
base = gem_mmap__cpu(fd, handle, size, PROT_READ | PROT_WRITE); base = gem_mmap__cpu(fd, handle, 0, size, PROT_READ | PROT_WRITE);
ptr = base; ptr = base;
for (i = 0; i < size/sizeof(*ptr); i++) for (i = 0; i < size/sizeof(*ptr); i++)
...@@ -138,7 +138,7 @@ int main(int argc, char **argv) ...@@ -138,7 +138,7 @@ int main(int argc, char **argv)
gettimeofday(&start, NULL); gettimeofday(&start, NULL);
for (loop = 0; loop < 1000; loop++) { for (loop = 0; loop < 1000; loop++) {
base = gem_mmap__cpu(fd, handle, size, PROT_READ | PROT_WRITE); base = gem_mmap__cpu(fd, handle, 0, size, PROT_READ | PROT_WRITE);
memset(base, 0, size); memset(base, 0, size);
munmap(base, size); munmap(base, size);
} }
...@@ -147,7 +147,7 @@ int main(int argc, char **argv) ...@@ -147,7 +147,7 @@ int main(int argc, char **argv)
size/1024, elapsed(&start, &end, loop)); size/1024, elapsed(&start, &end, loop));
gettimeofday(&start, NULL); gettimeofday(&start, NULL);
base = gem_mmap__cpu(fd, handle, size, PROT_READ | PROT_WRITE); base = gem_mmap__cpu(fd, handle, 0, size, PROT_READ | PROT_WRITE);
for (loop = 0; loop < 1000; loop++) for (loop = 0; loop < 1000; loop++)
memset(base, 0, size); memset(base, 0, size);
munmap(base, size); munmap(base, size);
......
...@@ -93,7 +93,7 @@ igt_main ...@@ -93,7 +93,7 @@ igt_main
igt_subtest("short-mmap") { igt_subtest("short-mmap") {
igt_assert(OBJECT_SIZE > 4096); igt_assert(OBJECT_SIZE > 4096);
handle = gem_create(fd, OBJECT_SIZE); handle = gem_create(fd, OBJECT_SIZE);
addr = gem_mmap__cpu(fd, handle, 4096, PROT_WRITE); addr = gem_mmap__cpu(fd, handle, 0, 4096, PROT_WRITE);
memset(addr, 0, 4096); memset(addr, 0, 4096);
munmap(addr, 4096); munmap(addr, 4096);
gem_close(fd, handle); gem_close(fd, handle);
......
...@@ -286,7 +286,7 @@ test_write_cpu_read_gtt(int fd) ...@@ -286,7 +286,7 @@ test_write_cpu_read_gtt(int fd)
dst = gem_mmap(fd, handle, OBJECT_SIZE, PROT_READ); dst = gem_mmap(fd, handle, OBJECT_SIZE, PROT_READ);
igt_assert(dst != (uint32_t *)MAP_FAILED); igt_assert(dst != (uint32_t *)MAP_FAILED);
src = gem_mmap__cpu(fd, handle, OBJECT_SIZE, PROT_WRITE); src = gem_mmap__cpu(fd, handle, 0, OBJECT_SIZE, PROT_WRITE);
igt_assert(src != (uint32_t *)MAP_FAILED); igt_assert(src != (uint32_t *)MAP_FAILED);
gem_close(fd, handle); gem_close(fd, handle);
......
...@@ -141,8 +141,8 @@ static void as_cpu_mmap(int fd, uint32_t src, uint32_t dst, void *buf, int len, ...@@ -141,8 +141,8 @@ static void as_cpu_mmap(int fd, uint32_t src, uint32_t dst, void *buf, int len,
uint32_t *src_ptr, *dst_ptr; uint32_t *src_ptr, *dst_ptr;
BUILD_EXEC; BUILD_EXEC;
src_ptr = gem_mmap__cpu(fd, src, OBJECT_SIZE, PROT_WRITE); src_ptr = gem_mmap__cpu(fd, src, 0, OBJECT_SIZE, PROT_WRITE);
dst_ptr = gem_mmap__cpu(fd, dst, OBJECT_SIZE, PROT_READ); dst_ptr = gem_mmap__cpu(fd, dst, 0, OBJECT_SIZE, PROT_READ);
while (loops--) { while (loops--) {
gem_set_domain(fd, src, gem_set_domain(fd, src,
...@@ -210,8 +210,8 @@ static void test_as_cpu_mmap(int fd, uint32_t src, uint32_t dst, int len) ...@@ -210,8 +210,8 @@ static void test_as_cpu_mmap(int fd, uint32_t src, uint32_t dst, int len)
int i; int i;
BUILD_EXEC; BUILD_EXEC;
src_ptr = gem_mmap__cpu(fd, src, OBJECT_SIZE, PROT_WRITE); src_ptr = gem_mmap__cpu(fd, src, 0, OBJECT_SIZE, PROT_WRITE);
dst_ptr = gem_mmap__cpu(fd, dst, OBJECT_SIZE, PROT_READ); dst_ptr = gem_mmap__cpu(fd, dst, 0, OBJECT_SIZE, PROT_READ);
gem_set_domain(fd, src, I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU); gem_set_domain(fd, src, I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
for (i = 0; i < len/4; i++) for (i = 0; i < len/4; i++)
......
...@@ -687,7 +687,7 @@ static void *umap(int fd, uint32_t handle) ...@@ -687,7 +687,7 @@ static void *umap(int fd, uint32_t handle)
} else { } else {
uint32_t tmp = gem_create(fd, sizeof(linear)); uint32_t tmp = gem_create(fd, sizeof(linear));
copy(fd, tmp, handle, 0); copy(fd, tmp, handle, 0);
ptr = gem_mmap__cpu(fd, tmp, sizeof(linear), PROT_READ); ptr = gem_mmap__cpu(fd, tmp, 0, sizeof(linear), PROT_READ);
gem_close(fd, tmp); gem_close(fd, tmp);
} }
......
...@@ -224,7 +224,7 @@ static void test_crc(data_t *data, enum test_mode mode) ...@@ -224,7 +224,7 @@ static void test_crc(data_t *data, enum test_mode mode)
break; break;
case TEST_MMAP_CPU: case TEST_MMAP_CPU:
case TEST_PAGE_FLIP_AND_MMAP_CPU: case TEST_PAGE_FLIP_AND_MMAP_CPU:
ptr = gem_mmap__cpu(data->drm_fd, handle, 4096, PROT_WRITE); ptr = gem_mmap__cpu(data->drm_fd, handle, 0, 4096, PROT_WRITE);
gem_set_domain(data->drm_fd, handle, I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU); gem_set_domain(data->drm_fd, handle, I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
memset(ptr, 0xff, 4); memset(ptr, 0xff, 4);
munmap(ptr, 4096); munmap(ptr, 4096);
......
...@@ -359,7 +359,7 @@ static void test_crc(data_t *data) ...@@ -359,7 +359,7 @@ static void test_crc(data_t *data)
munmap(ptr, 4096); munmap(ptr, 4096);
break; break;
case MMAP_CPU: case MMAP_CPU:
ptr = gem_mmap__cpu(data->drm_fd, handle, 4096, PROT_WRITE); ptr = gem_mmap__cpu(data->drm_fd, handle, 0, 4096, PROT_WRITE);
gem_set_domain(data->drm_fd, handle, gem_set_domain(data->drm_fd, handle,
I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU); I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
memset(ptr, 0, 4); memset(ptr, 0, 4);
......
...@@ -978,7 +978,7 @@ static void gem_mmap_subtest(bool gtt_mmap) ...@@ -978,7 +978,7 @@ static void gem_mmap_subtest(bool gtt_mmap)
gem_buf = gem_mmap__gtt(drm_fd, handle, buf_size, gem_buf = gem_mmap__gtt(drm_fd, handle, buf_size,
PROT_READ | PROT_WRITE); PROT_READ | PROT_WRITE);
else else
gem_buf = gem_mmap__cpu(drm_fd, handle, buf_size, 0); gem_buf = gem_mmap__cpu(drm_fd, handle, 0, buf_size, 0);
for (i = 0; i < buf_size; i++) for (i = 0; i < buf_size; i++)
...@@ -1013,7 +1013,7 @@ static void gem_mmap_subtest(bool gtt_mmap) ...@@ -1013,7 +1013,7 @@ static void gem_mmap_subtest(bool gtt_mmap)
gem_buf = gem_mmap__gtt(drm_fd, handle, buf_size, gem_buf = gem_mmap__gtt(drm_fd, handle, buf_size,
PROT_READ | PROT_WRITE); PROT_READ | PROT_WRITE);
else else
gem_buf = gem_mmap__cpu(drm_fd, handle, buf_size, 0); gem_buf = gem_mmap__cpu(drm_fd, handle, 0, buf_size, 0);
igt_assert(wait_for_suspended()); igt_assert(wait_for_suspended());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment