2 * Copyright © 2014 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 * Daniel Vetter <daniel.vetter@ffwll.ch> (based on gem_ring_sync_loop_*.c)
25 * Zhao Yakui <yakui.zhao@intel.com>
38 #include "ioctl_wrappers.h"
40 #include "intel_bufmgr.h"
41 #include "intel_batchbuffer.h"
44 #include "intel_chipset.h"
46 static drm_intel_bufmgr *bufmgr;
47 struct intel_batchbuffer *batch;
48 static drm_intel_bo *target_buffer;
52 static int mfd[NUM_FD];
53 static drm_intel_bufmgr *mbufmgr[NUM_FD];
54 static struct intel_batchbuffer *mbatch[NUM_FD];
55 static drm_intel_bo *mbuffer[NUM_FD];
59 * Testcase: Basic check of ring<->ring sync using a dummy reloc
61 * Extremely efficient at catching missed irqs with semaphores=0 ...
64 #define MI_COND_BATCH_BUFFER_END (0x36<<23 | 1)
65 #define MI_DO_COMPARE (1<<21)
68 store_dword_loop(int fd)
71 int num_rings = gem_get_num_rings(fd);
75 for (i = 0; i < SLOW_QUICK(0x100000, 10); i++) {
77 ring = random() % num_rings + 1;
78 mindex = random() % NUM_FD;
79 batch = mbatch[mindex];
80 if (ring == I915_EXEC_RENDER) {
82 OUT_BATCH(MI_COND_BATCH_BUFFER_END | MI_DO_COMPARE);
83 OUT_BATCH(0xffffffff); /* compare dword */
84 OUT_RELOC(mbuffer[mindex], I915_GEM_DOMAIN_RENDER,
85 I915_GEM_DOMAIN_RENDER, 0);
90 OUT_BATCH(MI_FLUSH_DW | 1);
91 OUT_BATCH(0); /* reserved */
92 OUT_RELOC(mbuffer[mindex], I915_GEM_DOMAIN_RENDER,
93 I915_GEM_DOMAIN_RENDER, 0);
94 OUT_BATCH(MI_NOOP | (1<<22) | (0xf));
97 intel_batchbuffer_flush_on_ring(batch, ring);
100 drm_intel_bo_map(target_buffer, 0);
101 // map to force waiting on rendering
102 drm_intel_bo_unmap(target_buffer);
112 devid = intel_get_drm_devid(fd);
113 gem_require_ring(fd, I915_EXEC_BLT);
116 bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
117 igt_assert_f(bufmgr, "fail to initialize the buf manager\n");
118 drm_intel_bufmgr_gem_enable_reuse(bufmgr);
121 target_buffer = drm_intel_bo_alloc(bufmgr, "target bo", 4096, 4096);
122 igt_assert_f(target_buffer, "fail to create the gem bo\n");
124 /* Create multiple drm_fd and map one gem_object among multi drm_fd */
126 unsigned int target_flink;
127 char buffer_name[32];
128 igt_assert(dri_bo_flink(target_buffer, &target_flink) == 0);
130 for (i = 0; i < NUM_FD; i++) {
131 sprintf(buffer_name, "Target buffer %d\n", i);
132 mfd[i] = drm_open_any();
133 mbufmgr[i] = drm_intel_bufmgr_gem_init(mfd[i], 4096);
134 igt_assert_f(mbufmgr[i],
135 "fail to initialize buf manager for drm_fd %d\n",
137 drm_intel_bufmgr_gem_enable_reuse(mbufmgr[i]);
138 mbatch[i] = intel_batchbuffer_alloc(mbufmgr[i], devid);
139 igt_assert_f(mbatch[i],
140 "fail to create batchbuffer for drm_fd %d\n",
142 mbuffer[i] = intel_bo_gem_create_from_name(mbufmgr[i], buffer_name, target_flink);
143 igt_assert_f(mbuffer[i],
144 "fail to create buffer bo from global "
145 "gem handle %d for drm_fd %d\n",
146 target_flink, mfd[i]);
150 store_dword_loop(fd);
153 for (i = 0; i < NUM_FD; i++) {
154 dri_bo_unreference(mbuffer[i]);
155 intel_batchbuffer_free(mbatch[i]);
156 drm_intel_bufmgr_destroy(mbufmgr[i]);
160 drm_intel_bo_unreference(target_buffer);
161 drm_intel_bufmgr_destroy(bufmgr);