lib/igt_kms: Unify pipe name helpers
[platform/upstream/intel-gpu-tools.git] / tests / gem_storedw_loop_vebox.c
1 /*
2  * Copyright © 2012 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  *    Xiang, Haihao <haihao.xiang@intel.com> (based on gem_store_dw_loop_*)
25  *
26  */
27
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <string.h>
31 #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 "ioctl_wrappers.h"
38 #include "drmtest.h"
39 #include "intel_bufmgr.h"
40 #include "intel_batchbuffer.h"
41 #include "intel_io.h"
42 #include "intel_chipset.h"
43
44 #define LOCAL_I915_EXEC_VEBOX (4<<0)
45
46 static drm_intel_bufmgr *bufmgr;
47 struct intel_batchbuffer *batch;
48 static drm_intel_bo *target_buffer;
49
50 /*
51  * Testcase: Basic vebox MI check using MI_STORE_DATA_IMM
52  */
53
54 static void
55 store_dword_loop(int divider)
56 {
57         int cmd, i, val = 0;
58         uint32_t *buf;
59
60         igt_info("running storedw loop on blt with stall every %i batch\n", divider);
61
62         cmd = MI_STORE_DWORD_IMM;
63
64         for (i = 0; i < SLOW_QUICK(0x2000, 0x10); i++) {
65                 BEGIN_BATCH(4);
66                 OUT_BATCH(cmd);
67                 if (intel_gen(batch->devid) < 8)
68                         OUT_BATCH(0); /* reserved */
69                 OUT_RELOC(target_buffer, I915_GEM_DOMAIN_INSTRUCTION,
70                           I915_GEM_DOMAIN_INSTRUCTION, 0);
71                 BLIT_RELOC_UDW(batch->devid);
72                 OUT_BATCH(val);
73                 ADVANCE_BATCH();
74
75                 intel_batchbuffer_flush_on_ring(batch, LOCAL_I915_EXEC_VEBOX);
76
77                 if (i % divider != 0)
78                         goto cont;
79
80                 drm_intel_bo_map(target_buffer, 0);
81
82                 buf = target_buffer->virtual;
83                 igt_assert_cmpint (buf[0], ==, val);
84
85                 drm_intel_bo_unmap(target_buffer);
86
87 cont:
88                 val++;
89         }
90
91         drm_intel_bo_map(target_buffer, 0);
92         buf = target_buffer->virtual;
93
94         igt_info("completed %d writes successfully, current value: 0x%08x\n", i,
95                         buf[0]);
96         drm_intel_bo_unmap(target_buffer);
97 }
98
99 igt_simple_main
100 {
101         int fd;
102
103         fd = drm_open_any();
104
105         igt_require(gem_has_vebox(fd));
106         igt_require(gem_uses_aliasing_ppgtt(fd));
107
108         bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
109         igt_assert(bufmgr);
110         drm_intel_bufmgr_gem_enable_reuse(bufmgr);
111
112         batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd));
113         igt_require(batch);
114
115         target_buffer = drm_intel_bo_alloc(bufmgr, "target bo", 4096, 4096);
116         igt_require(target_buffer);
117
118         store_dword_loop(1);
119         store_dword_loop(2);
120         if (!igt_run_in_simulation()) {
121                 store_dword_loop(3);
122                 store_dword_loop(5);
123         }
124
125         drm_intel_bo_unreference(target_buffer);
126         intel_batchbuffer_free(batch);
127         drm_intel_bufmgr_destroy(bufmgr);
128
129         close(fd);
130 }