blob: 0316c3ea2eac5effcea8b6929f677034d53cc9e1 [file] [log] [blame]
Daniel Vetter61b98062011-09-09 20:44:27 +02001/*
2 * Copyright © 2011 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Daniel Vetter <daniel.vetter@ffwll.ch> (based on gem_storedw_*.c)
25 *
26 */
27
28#include <stdlib.h>
29#include <stdio.h>
30#include <string.h>
Daniel Vetter61b98062011-09-09 20:44:27 +020031#include <fcntl.h>
32#include <inttypes.h>
33#include <errno.h>
34#include <sys/stat.h>
35#include <sys/time.h>
36#include "drm.h"
37#include "i915_drm.h"
38#include "drmtest.h"
39#include "intel_bufmgr.h"
40#include "intel_batchbuffer.h"
41#include "intel_gpu_tools.h"
42#include "i830_reg.h"
43
44static drm_intel_bufmgr *bufmgr;
45struct intel_batchbuffer *batch;
46static drm_intel_bo *target_buffer;
47
48/*
49 * Testcase: Basic check of ring<->ring sync using a dummy reloc
50 *
51 * Extremely efficient at catching missed irqs with semaphores=0 ...
52 */
53
54#define MI_COND_BATCH_BUFFER_END (0x36<<23 | 1)
55#define MI_DO_COMPARE (1<<21)
56
57static void
Xiang, Haihao0a413cd2013-04-23 15:06:41 +080058store_dword_loop(int fd)
Daniel Vetter61b98062011-09-09 20:44:27 +020059{
60 int i;
Zhong Li8ddf84d2013-05-03 15:54:48 +080061 int num_rings = gem_get_num_rings(fd);
Daniel Vetter61b98062011-09-09 20:44:27 +020062
63 srandom(0xdeadbeef);
64
Damien Lespiaud1e86232013-03-25 20:06:20 +000065 for (i = 0; i < SLOW_QUICK(0x100000, 10); i++) {
Xiang, Haihao0a413cd2013-04-23 15:06:41 +080066 int ring = random() % num_rings + 1;
Daniel Vetter61b98062011-09-09 20:44:27 +020067
68 if (ring == I915_EXEC_RENDER) {
69 BEGIN_BATCH(4);
70 OUT_BATCH(MI_COND_BATCH_BUFFER_END | MI_DO_COMPARE);
71 OUT_BATCH(0xffffffff); /* compare dword */
72 OUT_RELOC(target_buffer, I915_GEM_DOMAIN_RENDER,
73 I915_GEM_DOMAIN_RENDER, 0);
74 OUT_BATCH(MI_NOOP);
75 ADVANCE_BATCH();
76 } else {
77 BEGIN_BATCH(4);
78 OUT_BATCH(MI_FLUSH_DW | 1);
79 OUT_BATCH(0); /* reserved */
80 OUT_RELOC(target_buffer, I915_GEM_DOMAIN_RENDER,
81 I915_GEM_DOMAIN_RENDER, 0);
82 OUT_BATCH(MI_NOOP | (1<<22) | (0xf));
83 ADVANCE_BATCH();
84 }
85 intel_batchbuffer_flush_on_ring(batch, ring);
86 }
87
88 drm_intel_bo_map(target_buffer, 0);
89 // map to force waiting on rendering
90 drm_intel_bo_unmap(target_buffer);
91}
92
93int main(int argc, char **argv)
94{
95 int fd;
96 int devid;
97
98 if (argc != 1) {
99 fprintf(stderr, "usage: %s\n", argv[0]);
Daniel Vetter5e25fcc2013-08-13 12:56:06 +0200100 igt_fail(-1);
Daniel Vetter61b98062011-09-09 20:44:27 +0200101 }
102
103 fd = drm_open_any();
104 devid = intel_get_drm_devid(fd);
105 if (!HAS_BLT_RING(devid)) {
106 fprintf(stderr, "inter ring check needs gen6+\n");
Daniel Vetter19d69952011-09-13 11:05:13 +0200107 return 77;
Daniel Vetter61b98062011-09-09 20:44:27 +0200108 }
109
110
111 bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
112 if (!bufmgr) {
113 fprintf(stderr, "failed to init libdrm\n");
Daniel Vetter5e25fcc2013-08-13 12:56:06 +0200114 igt_fail(-1);
Daniel Vetter61b98062011-09-09 20:44:27 +0200115 }
116 drm_intel_bufmgr_gem_enable_reuse(bufmgr);
117
118 batch = intel_batchbuffer_alloc(bufmgr, devid);
119 if (!batch) {
120 fprintf(stderr, "failed to create batch buffer\n");
Daniel Vetter5e25fcc2013-08-13 12:56:06 +0200121 igt_fail(-1);
Daniel Vetter61b98062011-09-09 20:44:27 +0200122 }
123
124 target_buffer = drm_intel_bo_alloc(bufmgr, "target bo", 4096, 4096);
125 if (!target_buffer) {
126 fprintf(stderr, "failed to alloc target buffer\n");
Daniel Vetter5e25fcc2013-08-13 12:56:06 +0200127 igt_fail(-1);
Daniel Vetter61b98062011-09-09 20:44:27 +0200128 }
129
Xiang, Haihao0a413cd2013-04-23 15:06:41 +0800130 store_dword_loop(fd);
Daniel Vetter61b98062011-09-09 20:44:27 +0200131
132 drm_intel_bo_unreference(target_buffer);
133 intel_batchbuffer_free(batch);
134 drm_intel_bufmgr_destroy(bufmgr);
135
Daniel Vetter61b98062011-09-09 20:44:27 +0200136 close(fd);
137
138 return 0;
139}