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 char device[80];
51 static void selfcopy(int fd, uint32_t handle)
53 struct drm_i915_gem_relocation_entry reloc[2];
54 struct drm_i915_gem_exec_object2 gem_exec[2];
55 struct drm_i915_gem_execbuffer2 execbuf;
59 memset(reloc, 0, sizeof(reloc));
60 memset(gem_exec, 0, sizeof(gem_exec));
61 memset(&execbuf, 0, sizeof(execbuf));
63 buf[0] = COPY_BLT_CMD | BLT_WRITE_ALPHA | BLT_WRITE_RGB;
64 buf[1] = 0xcc << 16 | 1 << 25 | 1 << 24 | (4*1024);
66 buf[3] = 512 << 16 | 1024;
68 reloc[0].offset = 4 * sizeof(uint32_t);
69 reloc[0].target_handle = handle;
70 reloc[0].read_domains = I915_GEM_DOMAIN_RENDER;
71 reloc[0].write_domain = I915_GEM_DOMAIN_RENDER;
76 reloc[1].offset = 7 * sizeof(uint32_t);
77 reloc[1].target_handle = handle;
78 reloc[1].read_domains = I915_GEM_DOMAIN_RENDER;
79 reloc[1].write_domain = 0;
81 buf[8] = MI_BATCH_BUFFER_END;
84 gem_exec[0].handle = handle;
86 gem_exec[1].handle = gem_create(fd, 4096);
87 gem_exec[1].relocation_count = 2;
88 gem_exec[1].relocs_ptr = (uintptr_t)reloc;
90 gem_write(fd, gem_exec[1].handle, 0, buf, sizeof(buf));
92 execbuf.buffers_ptr = (uintptr_t)gem_exec;
93 execbuf.buffer_count = 2;
94 execbuf.batch_len = sizeof(buf);
95 if (HAS_BLT_RING(intel_get_drm_devid(fd)))
96 execbuf.flags |= I915_EXEC_BLT;
98 for (loop = 30; loop--; )
99 gem_execbuf(fd, &execbuf);
102 static uint32_t load(int fd)
106 handle = gem_create(fd, OBJECT_SIZE);
110 selfcopy(fd, handle);
114 static void run(int child)
119 fd = open(device, O_RDWR);
120 igt_assert(fd != -1);
123 if ((child & 63) == 63)
124 gem_read(fd, handle, 0, &handle, sizeof(handle));
127 int main(int argc, char *argv[])
129 igt_skip_on_simulation();
130 igt_subtest_init(argc, argv);
132 sprintf(device, "/dev/dri/card%d", drm_get_card());
134 igt_subtest("gem-close-race") {
135 igt_fork(child, 2000)