• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "igt.h"
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <string.h>
32 #include <fcntl.h>
33 #include <inttypes.h>
34 #include <errno.h>
35 #include <sys/stat.h>
36 #include <sys/time.h>
37 #include "drm.h"
38 #include "intel_bufmgr.h"
39 #include "i830_reg.h"
40 
41 IGT_TEST_DESCRIPTION("Basic check of non-secure batches.");
42 
43 static drm_intel_bufmgr *bufmgr;
44 struct intel_batchbuffer *batch;
45 
46 /*
47  * Testcase: Basic check of non-secure batches
48  *
49  * This test tries to stop the render ring with a MI_LOAD_REG command, which
50  * should fail if the non-secure handling works correctly.
51  */
52 
53 static int num_rings = 1;
54 
55 static void
mi_lri_loop(void)56 mi_lri_loop(void)
57 {
58 	int i;
59 
60 	srandom(0xdeadbeef);
61 
62 	for (i = 0; i < 0x100; i++) {
63 		int ring = random() % num_rings + 1;
64 
65 		BEGIN_BATCH(4, 0);
66 		OUT_BATCH(MI_LOAD_REGISTER_IMM);
67 		OUT_BATCH(0x203c); /* RENDER RING CTL */
68 		OUT_BATCH(0); /* try to stop the ring */
69 		OUT_BATCH(MI_NOOP);
70 		ADVANCE_BATCH();
71 
72 		intel_batchbuffer_flush_on_ring(batch, ring);
73 	}
74 }
75 
76 igt_simple_main
77 {
78 	int fd;
79 	int devid;
80 
81 	fd = drm_open_driver(DRIVER_INTEL);
82 	devid = intel_get_drm_devid(fd);
83 
84 	if (HAS_BSD_RING(devid))
85 		num_rings++;
86 
87 	if (HAS_BLT_RING(devid))
88 		num_rings++;
89 
90 
91 	igt_info("num rings detected: %i\n", num_rings);
92 
93 	bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
94 	igt_assert(bufmgr);
95 	drm_intel_bufmgr_gem_enable_reuse(bufmgr);
96 
97 	batch = intel_batchbuffer_alloc(bufmgr, devid);
98 	igt_assert(batch);
99 
100 	mi_lri_loop();
101 	gem_quiescent_gpu(fd);
102 
103 	intel_batchbuffer_free(batch);
104 	drm_intel_bufmgr_destroy(bufmgr);
105 
106 	close(fd);
107 }
108