• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2016 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  */
24 
25 #ifndef __IGT_DUMMYLOAD_H__
26 #define __IGT_DUMMYLOAD_H__
27 
28 #include <stdint.h>
29 #include <time.h>
30 
31 #include "igt_core.h"
32 #include "igt_list.h"
33 #include "i915_drm.h"
34 
35 typedef struct igt_spin {
36 	unsigned int handle;
37 	timer_t timer;
38 	struct igt_list link;
39 
40 	uint32_t *condition;
41 	uint32_t cmd_precondition;
42 
43 	int out_fence;
44 	struct drm_i915_gem_exec_object2 obj[2];
45 #define IGT_SPIN_BATCH   1
46 	struct drm_i915_gem_execbuffer2 execbuf;
47 	uint32_t poll_handle;
48 	uint32_t *poll;
49 #define SPIN_POLL_START_IDX 0
50 } igt_spin_t;
51 
52 struct igt_spin_factory {
53 	uint32_t ctx;
54 	uint32_t dependency;
55 	unsigned int engine;
56 	unsigned int flags;
57 };
58 
59 #define IGT_SPIN_FENCE_OUT     (1 << 0)
60 #define IGT_SPIN_POLL_RUN      (1 << 1)
61 #define IGT_SPIN_FAST          (1 << 2)
62 #define IGT_SPIN_NO_PREEMPTION (1 << 3)
63 
64 igt_spin_t *
65 __igt_spin_factory(int fd, const struct igt_spin_factory *opts);
66 igt_spin_t *
67 igt_spin_factory(int fd, const struct igt_spin_factory *opts);
68 
69 #define __igt_spin_new(fd, ...) \
70 	__igt_spin_factory(fd, &((struct igt_spin_factory){__VA_ARGS__}))
71 #define igt_spin_new(fd, ...) \
72 	igt_spin_factory(fd, &((struct igt_spin_factory){__VA_ARGS__}))
73 
74 void igt_spin_set_timeout(igt_spin_t *spin, int64_t ns);
75 void igt_spin_reset(igt_spin_t *spin);
76 void igt_spin_end(igt_spin_t *spin);
77 void igt_spin_free(int fd, igt_spin_t *spin);
78 
igt_spin_has_poll(const igt_spin_t * spin)79 static inline bool igt_spin_has_poll(const igt_spin_t *spin)
80 {
81 	return spin->poll;
82 }
83 
igt_spin_has_started(igt_spin_t * spin)84 static inline bool igt_spin_has_started(igt_spin_t *spin)
85 {
86 	return READ_ONCE(spin->poll[SPIN_POLL_START_IDX]);
87 }
88 
igt_spin_busywait_until_started(igt_spin_t * spin)89 static inline void igt_spin_busywait_until_started(igt_spin_t *spin)
90 {
91 	while (!igt_spin_has_started(spin))
92 		;
93 }
94 
95 void igt_terminate_spins(void);
96 void igt_unshare_spins(void);
97 
98 enum igt_cork_type {
99 	CORK_SYNC_FD = 1,
100 	CORK_VGEM_HANDLE
101 };
102 
103 struct igt_cork_vgem {
104 	int device;
105 	uint32_t fence;
106 };
107 
108 struct igt_cork_sw_sync {
109 	int timeline;
110 };
111 
112 struct igt_cork {
113 	enum igt_cork_type type;
114 
115 	union {
116 		int fd;
117 
118 		struct igt_cork_vgem vgem;
119 		struct igt_cork_sw_sync sw_sync;
120 	};
121 };
122 
123 #define IGT_CORK(name, cork_type) struct igt_cork name = { .type = cork_type, .fd = -1}
124 #define IGT_CORK_HANDLE(name) IGT_CORK(name, CORK_VGEM_HANDLE)
125 #define IGT_CORK_FENCE(name) IGT_CORK(name, CORK_SYNC_FD)
126 
127 uint32_t igt_cork_plug(struct igt_cork *cork, int fd);
128 void igt_cork_unplug(struct igt_cork *cork);
129 
130 #endif /* __IGT_DUMMYLOAD_H__ */
131