2 * Copyright © 2013 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 * Chris Wilson <chris@chris-wilson.co.uk>
37 #include <sys/ioctl.h>
43 #define OBJECT_SIZE 1024*1024*4
45 #define COPY_BLT_CMD (2<<29|0x53<<22|0x6)
46 #define BLT_WRITE_ALPHA (1<<21)
47 #define BLT_WRITE_RGB (1<<20)
49 static void selfcopy(int fd, uint32_t handle)
51 struct drm_i915_gem_relocation_entry reloc[2];
52 struct drm_i915_gem_exec_object2 gem_exec[2];
53 struct drm_i915_gem_execbuffer2 execbuf;
57 memset(reloc, 0, sizeof(reloc));
58 memset(gem_exec, 0, sizeof(gem_exec));
59 memset(&execbuf, 0, sizeof(execbuf));
61 buf[0] = COPY_BLT_CMD | BLT_WRITE_ALPHA | BLT_WRITE_RGB;
62 buf[1] = 0xcc << 16 | 1 << 25 | 1 << 24 | (4*1024);
64 buf[3] = 1024 << 16 | 1024;
66 reloc[0].offset = 4 * sizeof(uint32_t);
68 reloc[0].target_handle = handle;
69 reloc[0].read_domains = I915_GEM_DOMAIN_RENDER;
70 reloc[0].write_domain = I915_GEM_DOMAIN_RENDER;
71 reloc[0].presumed_offset = 0;
76 reloc[1].offset = 7 * sizeof(uint32_t);
78 reloc[1].target_handle = handle;
79 reloc[1].read_domains = I915_GEM_DOMAIN_RENDER;
80 reloc[1].write_domain = 0;
81 reloc[1].presumed_offset = 0;
83 buf[8] = MI_BATCH_BUFFER_END;
86 gem_exec[0].handle = handle;
88 batch = gem_create(fd, 4096);
90 gem_write(fd, batch, 0, buf, sizeof(buf));
91 gem_exec[1].handle = batch;
92 gem_exec[1].relocation_count = 2;
93 gem_exec[1].relocs_ptr = (uintptr_t)reloc;
95 execbuf.buffers_ptr = (uintptr_t)&gem_exec;
96 execbuf.buffer_count = 2;
97 execbuf.batch_len = sizeof(buf);
98 if (HAS_BLT_RING(intel_get_drm_devid(fd)))
99 execbuf.flags |= I915_EXEC_BLT;
101 gem_execbuf(fd, &execbuf);
104 static int open_drm(void)
108 sprintf(name, "/dev/dri/card%d", drm_get_card());
109 return open(name, O_RDWR);
112 static uint32_t load(int fd)
116 handle = gem_create(fd, OBJECT_SIZE);
120 selfcopy(fd, handle);
124 static void run(int child)
130 igt_assert(fd != -1);
134 gem_read(fd, handle, 0, &handle, sizeof(handle));
137 int main(int argc, char *argv[])
139 igt_skip_on_simulation();
140 igt_subtest_init(argc, argv);
142 igt_subtest("gem-close-race")