2 * Copyright © 2008 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * Eric Anholt <eric@anholt.net>
36 #include <sys/ioctl.h>
38 #include "ioctl_wrappers.h"
41 #define OBJECT_SIZE 16384
47 struct drm_i915_gem_mmap arg;
48 uint8_t expected[OBJECT_SIZE];
49 uint8_t buf[OBJECT_SIZE];
56 igt_subtest("bad-object") {
57 memset(&arg, 0, sizeof(arg));
58 arg.handle = 0x10101010;
61 ret = ioctl(fd, DRM_IOCTL_I915_GEM_MMAP, &arg);
62 igt_assert(ret == -1 && errno == ENOENT);
66 handle = gem_create(fd, OBJECT_SIZE);
68 igt_subtest("new-object") {
71 arg.size = OBJECT_SIZE;
72 ret = ioctl(fd, DRM_IOCTL_I915_GEM_MMAP, &arg);
74 addr = (uint8_t *)(uintptr_t)arg.addr_ptr;
76 igt_info("Testing contents of newly created object.\n");
77 memset(expected, 0, sizeof(expected));
78 igt_assert(memcmp(addr, expected, sizeof(expected)) == 0);
80 igt_info("Testing coherency of writes and mmap reads.\n");
81 memset(buf, 0, sizeof(buf));
82 memset(buf + 1024, 0x01, 1024);
83 memset(expected + 1024, 0x01, 1024);
84 gem_write(fd, handle, 0, buf, OBJECT_SIZE);
85 igt_assert(memcmp(buf, addr, sizeof(buf)) == 0);
87 igt_info("Testing that mapping stays after close\n");
88 gem_close(fd, handle);
89 igt_assert(memcmp(buf, addr, sizeof(buf)) == 0);
91 igt_info("Testing unmapping\n");
92 munmap(addr, OBJECT_SIZE);
95 igt_subtest("short-mmap") {
96 igt_assert(OBJECT_SIZE > 4096);
97 addr = gem_mmap__cpu(fd, handle, 4096, PROT_WRITE);
98 memset(addr, 0, 4096);