kms_rotation_crc: Allow the sprite test to run even without universal planes
[platform/upstream/intel-gpu-tools.git] / tests / gem_non_secure_batch.c
1 /*
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>
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_chipset.h"
42 #include "intel_io.h"
43 #include "i830_reg.h"
44
45 static drm_intel_bufmgr *bufmgr;
46 struct intel_batchbuffer *batch;
47
48 /*
49  * Testcase: Basic check of non-secure batches
50  *
51  * This test tries to stop the render ring with a MI_LOAD_REG command, which
52  * should fail if the non-secure handling works correctly.
53  */
54
55 #define MI_LOAD_REGISTER_IMM                 (0x22<<23)
56
57 static int num_rings = 1;
58
59 static void
60 mi_lri_loop(void)
61 {
62         int i;
63
64         srandom(0xdeadbeef);
65
66         for (i = 0; i < 0x100; i++) {
67                 int ring = random() % num_rings + 1;
68
69                 BEGIN_BATCH(4);
70                 OUT_BATCH(MI_LOAD_REGISTER_IMM | 1);
71                 OUT_BATCH(0x203c); /* RENDER RING CTL */
72                 OUT_BATCH(0); /* try to stop the ring */
73                 OUT_BATCH(MI_NOOP);
74                 ADVANCE_BATCH();
75
76                 intel_batchbuffer_flush_on_ring(batch, ring);
77         }
78 }
79
80 igt_simple_main
81 {
82         int fd;
83         int devid;
84
85         fd = drm_open_any();
86         devid = intel_get_drm_devid(fd);
87
88         if (HAS_BSD_RING(devid))
89                 num_rings++;
90
91         if (HAS_BLT_RING(devid))
92                 num_rings++;
93
94
95         igt_info("num rings detected: %i\n", num_rings);
96
97         bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
98         igt_assert(bufmgr);
99         drm_intel_bufmgr_gem_enable_reuse(bufmgr);
100
101         batch = intel_batchbuffer_alloc(bufmgr, devid);
102         igt_assert(batch);
103
104         mi_lri_loop();
105         gem_quiescent_gpu(fd);
106
107         intel_batchbuffer_free(batch);
108         drm_intel_bufmgr_destroy(bufmgr);
109
110         close(fd);
111 }