• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2013 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>
25  * 	Damien Lespiau <damien.lespiau@intel.com>
26  */
27 
28 #ifndef __IGT_KMS_H__
29 #define __IGT_KMS_H__
30 
31 #include <stdbool.h>
32 #include <stdint.h>
33 #include <stddef.h>
34 #include <assert.h>
35 
36 #include <xf86drmMode.h>
37 
38 #include "igt_fb.h"
39 #include "ioctl_wrappers.h"
40 
41 /* Low-level helpers with kmstest_ prefix */
42 
43 /**
44  * pipe:
45  * @PIPE_NONE: Invalid pipe, used for disconnecting a output from a pipe.
46  * @PIPE_ANY: Deprecated alias for @PIPE_NONE.
47  * @PIPE_A: First crtc.
48  * @PIPE_B: Second crtc.
49  * @PIPE_C: Third crtc.
50  * @PIPE_D: Fourth crtc.
51  * @PIPE_E: Fifth crtc.
52  * @PIPE_F: Sixth crtc.
53  * @IGT_MAX_PIPES: Max number of pipes allowed.
54  */
55 enum pipe {
56         PIPE_NONE = -1,
57         PIPE_ANY = PIPE_NONE,
58         PIPE_A = 0,
59         PIPE_B,
60         PIPE_C,
61         PIPE_D,
62         PIPE_E,
63         PIPE_F,
64         IGT_MAX_PIPES
65 };
66 const char *kmstest_pipe_name(enum pipe pipe);
67 int kmstest_pipe_to_index(char pipe);
68 const char *kmstest_plane_type_name(int plane_type);
69 
70 enum port {
71         PORT_A = 0,
72         PORT_B,
73         PORT_C,
74         PORT_D,
75         PORT_E,
76         I915_MAX_PORTS
77 };
78 
79 /**
80  * kmstest_port_name:
81  * @port: display plane
82  *
83  * Returns: String representing @port, e.g. "A".
84  */
85 #define kmstest_port_name(port) ((port) + 'A')
86 
87 const char *kmstest_encoder_type_str(int type);
88 const char *kmstest_connector_status_str(int status);
89 const char *kmstest_connector_type_str(int type);
90 
91 void kmstest_dump_mode(drmModeModeInfo *mode);
92 
93 int kmstest_get_pipe_from_crtc_id(int fd, int crtc_id);
94 void kmstest_set_vt_graphics_mode(void);
95 void kmstest_restore_vt_mode(void);
96 
97 enum igt_atomic_crtc_properties {
98        IGT_CRTC_BACKGROUND = 0,
99        IGT_CRTC_CTM,
100        IGT_CRTC_GAMMA_LUT,
101        IGT_CRTC_GAMMA_LUT_SIZE,
102        IGT_CRTC_DEGAMMA_LUT,
103        IGT_CRTC_DEGAMMA_LUT_SIZE,
104        IGT_CRTC_MODE_ID,
105        IGT_CRTC_ACTIVE,
106        IGT_CRTC_OUT_FENCE_PTR,
107        IGT_CRTC_VRR_ENABLED,
108        IGT_NUM_CRTC_PROPS
109 };
110 
111 /**
112  * igt_crtc_prop_names
113  *
114  * igt_crtc_prop_names contains a list of crtc property names,
115  * as indexed by the igt_atomic_crtc_properties enum.
116  */
117 extern const char * const igt_crtc_prop_names[];
118 
119 enum igt_atomic_connector_properties {
120        IGT_CONNECTOR_SCALING_MODE = 0,
121        IGT_CONNECTOR_CRTC_ID,
122        IGT_CONNECTOR_DPMS,
123        IGT_CONNECTOR_BROADCAST_RGB,
124        IGT_CONNECTOR_CONTENT_PROTECTION,
125        IGT_CONNECTOR_VRR_CAPABLE,
126        IGT_CONNECTOR_HDCP_CONTENT_TYPE,
127        IGT_CONNECTOR_LINK_STATUS,
128        IGT_NUM_CONNECTOR_PROPS
129 };
130 
131 /**
132  * igt_connector_prop_names
133  *
134  * igt_connector_prop_names contains a list of crtc property names,
135  * as indexed by the igt_atomic_connector_properties enum.
136  */
137 extern const char * const igt_connector_prop_names[];
138 
139 struct kmstest_connector_config {
140 	drmModeCrtc *crtc;
141 	drmModeConnector *connector;
142 	drmModeEncoder *encoder;
143 	drmModeModeInfo default_mode;
144 
145 	int pipe;
146 	unsigned valid_crtc_idx_mask;
147 };
148 
149 struct kmstest_plane {
150 	int id;
151 	int index;
152 	int type;
153 	int pos_x;
154 	int pos_y;
155 	int width;
156 	int height;
157 };
158 
159 struct kmstest_crtc {
160 	int id;
161 	int pipe;
162 	bool active;
163 	int width;
164 	int height;
165 	int n_planes;
166 	struct kmstest_plane *planes;
167 };
168 
169 /**
170  * kmstest_force_connector_state:
171  * @FORCE_CONNECTOR_UNSPECIFIED: Unspecified
172  * @FORCE_CONNECTOR_ON: On
173  * @FORCE_CONNECTOR_DIGITAL: Digital
174  * @FORCE_CONNECTOR_OFF: Off
175  */
176 enum kmstest_force_connector_state {
177 	FORCE_CONNECTOR_UNSPECIFIED,
178 	FORCE_CONNECTOR_ON,
179 	FORCE_CONNECTOR_DIGITAL,
180 	FORCE_CONNECTOR_OFF
181 };
182 
183 /**
184  * intel_broadcast_rgb_mode:
185  * @BROADCAST_RGB_AUTO: Choose the color range to use automatically
186  * @BROADCAST_RGB_FULL: Force the connector to use full color range
187  * @BROADCAST_RGB_16_235: Force the connector to use a limited 16:235 color
188  * range
189  */
190 enum intel_broadcast_rgb_mode {
191 	BROADCAST_RGB_AUTO = 0,
192 	BROADCAST_RGB_FULL,
193 	BROADCAST_RGB_16_235
194 };
195 
196 struct edid;
197 
198 bool kmstest_force_connector(int fd, drmModeConnector *connector,
199 			     enum kmstest_force_connector_state state);
200 void kmstest_force_edid(int drm_fd, drmModeConnector *connector,
201 			const struct edid *edid);
202 
203 bool kmstest_get_connector_default_mode(int drm_fd, drmModeConnector *connector,
204 					drmModeModeInfo *mode);
205 bool kmstest_get_connector_config(int drm_fd, uint32_t connector_id,
206 				  unsigned long crtc_idx_mask,
207 				  struct kmstest_connector_config *config);
208 bool kmstest_probe_connector_config(int drm_fd, uint32_t connector_id,
209 				    unsigned long crtc_idx_mask,
210 				    struct kmstest_connector_config *config);
211 void kmstest_free_connector_config(struct kmstest_connector_config *config);
212 
213 void kmstest_set_connector_dpms(int fd, drmModeConnector *connector, int mode);
214 bool kmstest_get_property(int drm_fd, uint32_t object_id, uint32_t object_type,
215 			  const char *name, uint32_t *prop_id, uint64_t *value,
216 			  drmModePropertyPtr *prop);
217 void kmstest_unset_all_crtcs(int drm_fd, drmModeResPtr resources);
218 int kmstest_get_crtc_idx(drmModeRes *res, uint32_t crtc_id);
219 uint32_t kmstest_find_crtc_for_connector(int fd, drmModeRes *res,
220 					 drmModeConnector *connector,
221 					 uint32_t crtc_blacklist_idx_mask);
222 
223 uint32_t kmstest_dumb_create(int fd, int width, int height, int bpp,
224 			     unsigned *stride, uint64_t *size);
225 
226 void *kmstest_dumb_map_buffer(int fd, uint32_t handle, uint64_t size,
227 			      unsigned prot);
228 void kmstest_dumb_destroy(int fd, uint32_t handle);
229 void kmstest_wait_for_pageflip(int fd);
230 unsigned int kmstest_get_vblank(int fd, int pipe, unsigned int flags);
231 void igt_assert_plane_visible(int fd, enum pipe pipe, int plane_index, bool visibility);
232 
233 bool kms_has_vblank(int fd);
234 
235 /*
236  * A small modeset API
237  */
238 
239 /* High-level kms api with igt_ prefix */
240 
241 /**
242  * igt_commit_style:
243  * @COMMIT_LEGACY: Changes will be committed using the legacy API.
244  * @COMMIT_UNIVERSAL: Changes will be committed with the universal plane API, no modesets are allowed.
245  * @COMMIT_ATOMIC: Changes will be committed using the atomic API.
246  */
247 enum igt_commit_style {
248 	COMMIT_LEGACY = 0,
249 	COMMIT_UNIVERSAL,
250 	COMMIT_ATOMIC,
251 };
252 
253 enum igt_atomic_plane_properties {
254        IGT_PLANE_SRC_X = 0,
255        IGT_PLANE_SRC_Y,
256        IGT_PLANE_SRC_W,
257        IGT_PLANE_SRC_H,
258 
259        IGT_PLANE_CRTC_X,
260        IGT_PLANE_CRTC_Y,
261        IGT_PLANE_CRTC_W,
262        IGT_PLANE_CRTC_H,
263 
264 /* Append new properties after IGT_PLANE_COORD_CHANGED_MASK */
265 #define IGT_PLANE_COORD_CHANGED_MASK 0xff
266 
267        IGT_PLANE_FB_ID,
268        IGT_PLANE_CRTC_ID,
269        IGT_PLANE_IN_FENCE_FD,
270        IGT_PLANE_TYPE,
271        IGT_PLANE_ROTATION,
272        IGT_PLANE_IN_FORMATS,
273        IGT_PLANE_COLOR_ENCODING,
274        IGT_PLANE_COLOR_RANGE,
275        IGT_PLANE_PIXEL_BLEND_MODE,
276        IGT_PLANE_ALPHA,
277        IGT_PLANE_ZPOS,
278        IGT_NUM_PLANE_PROPS
279 };
280 
281 /**
282  * igt_plane_prop_names
283  *
284  * igt_plane_prop_names contains a list of crtc property names,
285  * as indexed by the igt_atomic_plane_properties enum.
286  */
287 extern const char * const igt_plane_prop_names[];
288 
289 typedef struct igt_display igt_display_t;
290 typedef struct igt_pipe igt_pipe_t;
291 typedef uint32_t igt_fixed_t;			/* 16.16 fixed point */
292 
293 typedef enum {
294 	/* this maps to the kernel API */
295 	IGT_ROTATION_0   = 1 << 0,
296 	IGT_ROTATION_90  = 1 << 1,
297 	IGT_ROTATION_180 = 1 << 2,
298 	IGT_ROTATION_270 = 1 << 3,
299 	IGT_REFLECT_X    = 1 << 4,
300 	IGT_REFLECT_Y    = 1 << 5,
301 } igt_rotation_t;
302 
303 #define IGT_ROTATION_MASK \
304 	(IGT_ROTATION_0 | IGT_ROTATION_90 | IGT_ROTATION_180 | IGT_ROTATION_270)
305 
306 typedef struct igt_plane {
307 	/*< private >*/
308 	igt_pipe_t *pipe;
309 	struct igt_plane *ref;
310 	int index;
311 	/* capabilities */
312 	int type;
313 
314 	/*
315 	 * drm_plane can be NULL for primary and cursor planes (when not
316 	 * using the atomic modeset API)
317 	 */
318 	drmModePlane *drm_plane;
319 
320 	/* gem handle for fb */
321 	uint32_t gem_handle;
322 
323 	struct {
324 		uint64_t values[IGT_NUM_COLOR_ENCODINGS];
325 	} color_encoding;
326 	struct {
327 		uint64_t values[IGT_NUM_COLOR_RANGES];
328 	} color_range;
329 
330 	uint64_t changed;
331 	uint32_t props[IGT_NUM_PLANE_PROPS];
332 	uint64_t values[IGT_NUM_PLANE_PROPS];
333 
334 	uint64_t *modifiers;
335 	uint32_t *formats;
336 	int format_mod_count;
337 } igt_plane_t;
338 
339 struct igt_pipe {
340 	igt_display_t *display;
341 	enum pipe pipe;
342 
343 	int n_planes;
344 	int plane_cursor;
345 	int plane_primary;
346 	igt_plane_t *planes;
347 
348 	uint64_t changed;
349 	uint32_t props[IGT_NUM_CRTC_PROPS];
350 	uint64_t values[IGT_NUM_CRTC_PROPS];
351 
352 	uint32_t crtc_id;
353 
354 	int32_t out_fence_fd;
355 };
356 
357 typedef struct {
358 	/*< private >*/
359 	igt_display_t *display;
360 	uint32_t id;					/* KMS id */
361 	struct kmstest_connector_config config;
362 	char *name;
363 	bool force_reprobe;
364 	enum pipe pending_pipe;
365 	bool use_override_mode;
366 	drmModeModeInfo override_mode;
367 
368 	/* bitmask of changed properties */
369 	uint64_t changed;
370 
371 	uint32_t props[IGT_NUM_CONNECTOR_PROPS];
372 	uint64_t values[IGT_NUM_CONNECTOR_PROPS];
373 } igt_output_t;
374 
375 struct igt_display {
376 	int drm_fd;
377 	int log_shift;
378 	int n_pipes;
379 	int n_planes;
380 	int n_outputs;
381 	igt_output_t *outputs;
382 	igt_plane_t *planes;
383 	igt_pipe_t *pipes;
384 	bool has_cursor_plane;
385 	bool is_atomic;
386 	bool first_commit;
387 
388 	uint64_t *modifiers;
389 	uint32_t *formats;
390 	int format_mod_count;
391 };
392 
393 void igt_display_require(igt_display_t *display, int drm_fd);
394 void igt_display_fini(igt_display_t *display);
395 void igt_display_reset(igt_display_t *display);
396 int  igt_display_commit2(igt_display_t *display, enum igt_commit_style s);
397 int  igt_display_commit(igt_display_t *display);
398 int  igt_display_try_commit_atomic(igt_display_t *display, uint32_t flags, void *user_data);
399 void igt_display_commit_atomic(igt_display_t *display, uint32_t flags, void *user_data);
400 int  igt_display_try_commit2(igt_display_t *display, enum igt_commit_style s);
401 int  igt_display_drop_events(igt_display_t *display);
402 int  igt_display_get_n_pipes(igt_display_t *display);
403 void igt_display_require_output(igt_display_t *display);
404 void igt_display_require_output_on_pipe(igt_display_t *display, enum pipe pipe);
405 
406 const char *igt_output_name(igt_output_t *output);
407 drmModeModeInfo *igt_output_get_mode(igt_output_t *output);
408 void igt_output_override_mode(igt_output_t *output, const drmModeModeInfo *mode);
409 void igt_output_set_pipe(igt_output_t *output, enum pipe pipe);
410 igt_plane_t *igt_output_get_plane(igt_output_t *output, int plane_idx);
411 igt_plane_t *igt_output_get_plane_type(igt_output_t *output, int plane_type);
412 int igt_output_count_plane_type(igt_output_t *output, int plane_type);
413 igt_plane_t *igt_output_get_plane_type_index(igt_output_t *output,
414 					     int plane_type, int index);
415 igt_output_t *igt_output_from_connector(igt_display_t *display,
416     drmModeConnector *connector);
417 const drmModeModeInfo *igt_std_1024_mode_get(void);
418 
419 igt_plane_t *igt_pipe_get_plane_type(igt_pipe_t *pipe, int plane_type);
420 int igt_pipe_count_plane_type(igt_pipe_t *pipe, int plane_type);
421 igt_plane_t *igt_pipe_get_plane_type_index(igt_pipe_t *pipe, int plane_type,
422 					   int index);
423 igt_output_t *igt_get_single_output_for_pipe(igt_display_t *display, enum pipe pipe);
424 
425 void igt_pipe_request_out_fence(igt_pipe_t *pipe);
426 
427 void igt_plane_set_fb(igt_plane_t *plane, struct igt_fb *fb);
428 void igt_plane_set_fence_fd(igt_plane_t *plane, int fence_fd);
429 void igt_plane_set_pipe(igt_plane_t *plane, igt_pipe_t *pipe);
430 void igt_plane_set_position(igt_plane_t *plane, int x, int y);
431 void igt_plane_set_size(igt_plane_t *plane, int w, int h);
432 void igt_plane_set_rotation(igt_plane_t *plane, igt_rotation_t rotation);
433 void igt_fb_set_position(struct igt_fb *fb, igt_plane_t *plane,
434 	uint32_t x, uint32_t y);
435 void igt_fb_set_size(struct igt_fb *fb, igt_plane_t *plane,
436 	uint32_t w, uint32_t h);
437 
438 void igt_wait_for_vblank(int drm_fd, enum pipe pipe);
439 void igt_wait_for_vblank_count(int drm_fd, enum pipe pipe, int count);
440 
igt_output_is_connected(igt_output_t * output)441 static inline bool igt_output_is_connected(igt_output_t *output)
442 {
443 	/* Something went wrong during probe? */
444 	if (!output->config.connector ||
445 	    !output->config.connector->count_modes)
446 		return false;
447 
448 	if (output->config.connector->connection == DRM_MODE_CONNECTED)
449 		return true;
450 
451 	return false;
452 }
453 
454 /**
455  * igt_pipe_connector_valid:
456  * @pipe: pipe to check.
457  * @output: #igt_output_t to check.
458  *
459  * Checks whether the given pipe and output can be used together.
460  */
461 #define igt_pipe_connector_valid(pipe, output) \
462 	(igt_output_is_connected((output)) && \
463 	       (output->config.valid_crtc_idx_mask & (1 << (pipe))))
464 
465 #define for_each_if(condition) if (!(condition)) {} else
466 
467 /**
468  * for_each_connected_output:
469  * @display: a pointer to an #igt_display_t structure
470  * @output: The output to iterate.
471  *
472  * This for loop iterates over all outputs.
473  */
474 #define for_each_connected_output(display, output)		\
475 	for (int i__ = 0;  assert(igt_can_fail()), i__ < (display)->n_outputs; i__++)	\
476 		for_each_if ((((output) = &(display)->outputs[i__]), \
477 			      igt_output_is_connected((output))))
478 
479 /**
480  * for_each_pipe_static:
481  * @pipe: The pipe to iterate.
482  *
483  * This for loop iterates over all pipes supported by IGT libraries.
484  *
485  * This should be used to enumerate per-pipe subtests since it has no runtime
486  * depencies.
487  */
488 #define for_each_pipe_static(pipe) \
489 	for (pipe = 0; pipe < IGT_MAX_PIPES; pipe++)
490 
491 /**
492  * for_each_pipe:
493  * @display: a pointer to an #igt_display_t structure
494  * @pipe: The pipe to iterate.
495  *
496  * This for loop iterates over all pipes.
497  *
498  * Note that this cannot be used to enumerate per-pipe subtest names since it
499  * depends upon runtime probing of the actual kms driver that is being tested.
500  * Use #for_each_pipe_static instead.
501  */
502 #define for_each_pipe(display, pipe)					\
503 	for (pipe = 0; assert(igt_can_fail()), pipe < igt_display_get_n_pipes(display); pipe++)
504 
505 /**
506  * for_each_pipe_with_valid_output:
507  * @display: a pointer to an #igt_display_t structure
508  * @pipe: The pipe for which this @pipe / @output combination is valid.
509  * @output: The output for which this @pipe / @output combination is valid.
510  *
511  * This for loop is called over all connected outputs. This function
512  * will try every combination of @pipe and @output.
513  *
514  * If you only need to test a single output for each pipe, use
515  * for_each_pipe_with_single_output(), if you only need an
516  * output for a single pipe, use igt_get_single_output_for_pipe().
517  */
518 #define for_each_pipe_with_valid_output(display, pipe, output) \
519 	for (int con__ = (pipe) = 0; \
520 	     assert(igt_can_fail()), (pipe) < igt_display_get_n_pipes((display)) && con__ < (display)->n_outputs; \
521 	     con__ = (con__ + 1 < (display)->n_outputs) ? con__ + 1 : (pipe = pipe + 1, 0)) \
522 		for_each_if ((((output) = &(display)->outputs[con__]), \
523 			     igt_pipe_connector_valid((pipe), (output))))
524 
525 igt_output_t **__igt_pipe_populate_outputs(igt_display_t *display,
526 					   igt_output_t **chosen_outputs);
527 
528 /**
529  * for_each_pipe_with_single_output:
530  * @display: a pointer to an #igt_display_t structure
531  * @pipe: The pipe for which this @pipe / @output combination is valid.
532  * @output: The output for which this @pipe / @output combination is valid.
533  *
534  * This loop is called over all pipes, and will try to find a compatible output
535  * for each pipe. Unlike for_each_pipe_with_valid_output(), this function will
536  * be called at most once for each pipe.
537  */
538 #define for_each_pipe_with_single_output(display, pipe, output) \
539 	for (igt_output_t *__outputs[(display)->n_pipes], \
540 	     **__output = __igt_pipe_populate_outputs((display), __outputs); \
541 	     __output < &__outputs[(display)->n_pipes]; __output++) \
542 		for_each_if (*__output && \
543 			     ((pipe) = (__output - __outputs), (output) = *__output, 1))
544 
545 /**
546  * for_each_valid_output_on_pipe:
547  * @display: a pointer to an #igt_display_t structure
548  * @pipe: Pipe to enumerate valid outputs over
549  * @output: The enumerated output.
550  *
551  * This for loop is called over all connected @output that can be used
552  * on this @pipe . If there are no valid outputs for this pipe, nothing
553  * happens.
554  */
555 #define for_each_valid_output_on_pipe(display, pipe, output) \
556 	for_each_connected_output((display), (output)) \
557 		for_each_if (igt_pipe_connector_valid((pipe), (output)))
558 
559 #define for_each_plane_on_pipe(display, pipe, plane)			\
560 	for (int j__ = 0; assert(igt_can_fail()), (plane) = &(display)->pipes[(pipe)].planes[j__], \
561 		     j__ < (display)->pipes[(pipe)].n_planes; j__++)
562 
563 #define IGT_FIXED(i,f)	((i) << 16 | (f))
564 
565 /**
566  * igt_plane_has_prop:
567  * @plane: Plane to check.
568  * @prop: Property to check.
569  *
570  * Check whether plane supports a given property.
571  *
572  * Returns: True if the property is supported, otherwise false.
573  */
574 static inline bool
igt_plane_has_prop(igt_plane_t * plane,enum igt_atomic_plane_properties prop)575 igt_plane_has_prop(igt_plane_t *plane, enum igt_atomic_plane_properties prop)
576 {
577 	return plane->props[prop];
578 }
579 
580 uint64_t igt_plane_get_prop(igt_plane_t *plane, enum igt_atomic_plane_properties prop);
581 
582 #define igt_plane_is_prop_changed(plane, prop) \
583 	(!!((plane)->changed & (1 << (prop))))
584 
585 #define igt_plane_set_prop_changed(plane, prop) \
586 	(plane)->changed |= 1 << (prop)
587 
588 #define igt_plane_clear_prop_changed(plane, prop) \
589 	(plane)->changed &= ~(1 << (prop))
590 
591 #define igt_plane_set_prop_value(plane, prop, value) \
592 	do { \
593 		plane->values[prop] = value; \
594 		igt_plane_set_prop_changed(plane, prop); \
595 	} while (0)
596 
597 extern bool igt_plane_try_prop_enum(igt_plane_t *plane,
598 				    enum igt_atomic_plane_properties prop,
599 				    const char *val);
600 
601 extern void igt_plane_set_prop_enum(igt_plane_t *plane,
602 				    enum igt_atomic_plane_properties prop,
603 				    const char *val);
604 
605 extern void igt_plane_replace_prop_blob(igt_plane_t *plane,
606 					enum igt_atomic_plane_properties prop,
607 					const void *ptr, size_t length);
608 
609 /**
610  * igt_output_has_prop:
611  * @output: Output to check.
612  * @prop: Property to check.
613  *
614  * Check whether output supports a given property.
615  *
616  * Returns: True if the property is supported, otherwise false.
617  */
618 static inline bool
igt_output_has_prop(igt_output_t * output,enum igt_atomic_connector_properties prop)619 igt_output_has_prop(igt_output_t *output, enum igt_atomic_connector_properties prop)
620 {
621 	return output->props[prop];
622 }
623 
624 uint64_t igt_output_get_prop(igt_output_t *output, enum igt_atomic_connector_properties prop);
625 
626 #define igt_output_is_prop_changed(output, prop) \
627 	(!!((output)->changed & (1 << (prop))))
628 #define igt_output_set_prop_changed(output, prop) \
629 	(output)->changed |= 1 << (prop)
630 
631 #define igt_output_clear_prop_changed(output, prop) \
632 	(output)->changed &= ~(1 << (prop))
633 
634 #define igt_output_set_prop_value(output, prop, value) \
635 	do { \
636 		(output)->values[prop] = (value); \
637 		igt_output_set_prop_changed(output, prop); \
638 	} while (0)
639 
640 extern bool igt_output_try_prop_enum(igt_output_t *output,
641 				     enum igt_atomic_connector_properties prop,
642 				     const char *val);
643 
644 extern void igt_output_set_prop_enum(igt_output_t *output,
645 				     enum igt_atomic_connector_properties prop,
646 				     const char *val);
647 
648 extern void igt_output_replace_prop_blob(igt_output_t *output,
649 					 enum igt_atomic_connector_properties prop,
650 					 const void *ptr, size_t length);
651 /**
652  * igt_pipe_obj_has_prop:
653  * @pipe: Pipe to check.
654  * @prop: Property to check.
655  *
656  * Check whether pipe supports a given property.
657  *
658  * Returns: True if the property is supported, otherwise false.
659  */
660 static inline bool
igt_pipe_obj_has_prop(igt_pipe_t * pipe,enum igt_atomic_crtc_properties prop)661 igt_pipe_obj_has_prop(igt_pipe_t *pipe, enum igt_atomic_crtc_properties prop)
662 {
663 	return pipe->props[prop];
664 }
665 
666 uint64_t igt_pipe_obj_get_prop(igt_pipe_t *pipe, enum igt_atomic_crtc_properties prop);
667 
668 /**
669  * igt_pipe_get_prop:
670  * @display: Pointer to display.
671  * @pipe: Target pipe.
672  * @prop: Property to return.
673  *
674  * Return current value on a pipe for a given property.
675  *
676  * Returns: The value the property is set to, if this
677  * is a blob, the blob id is returned. This can be passed
678  * to drmModeGetPropertyBlob() to get the contents of the blob.
679  */
680 static inline uint64_t
igt_pipe_get_prop(igt_display_t * display,enum pipe pipe,enum igt_atomic_crtc_properties prop)681 igt_pipe_get_prop(igt_display_t *display, enum pipe pipe,
682 		  enum igt_atomic_crtc_properties prop)
683 {
684 	return igt_pipe_obj_get_prop(&display->pipes[pipe], prop);
685 }
686 
687 /**
688  * igt_pipe_has_prop:
689  * @display: Pointer to display.
690  * @pipe: Pipe to check.
691  * @prop: Property to check.
692  *
693  * Check whether pipe supports a given property.
694  *
695  * Returns: True if the property is supported, otherwise false.
696  */
697 static inline bool
igt_pipe_has_prop(igt_display_t * display,enum pipe pipe,enum igt_atomic_crtc_properties prop)698 igt_pipe_has_prop(igt_display_t *display, enum pipe pipe,
699 		  enum igt_atomic_crtc_properties prop)
700 {
701 	return display->pipes[pipe].props[prop];
702 }
703 
704 #define igt_pipe_obj_is_prop_changed(pipe_obj, prop) \
705 	(!!((pipe_obj)->changed & (1 << (prop))))
706 
707 #define igt_pipe_is_prop_changed(display, pipe, prop) \
708 	igt_pipe_obj_is_prop_changed(&(display)->pipes[(pipe)], prop)
709 
710 #define igt_pipe_obj_set_prop_changed(pipe_obj, prop) \
711 	(pipe_obj)->changed |= 1 << (prop)
712 
713 #define igt_pipe_set_prop_changed(display, pipe, prop) \
714 	igt_pipe_obj_set_prop_changed(&(display)->pipes[(pipe)], prop)
715 
716 #define igt_pipe_obj_clear_prop_changed(pipe_obj, prop) \
717 	(pipe_obj)->changed &= ~(1 << (prop))
718 
719 #define igt_pipe_clear_prop_changed(display, pipe, prop) \
720 	igt_pipe_obj_clear_prop_changed(&(display)->pipes[(pipe)], prop)
721 
722 #define igt_pipe_obj_set_prop_value(pipe_obj, prop, value) \
723 	do { \
724 		(pipe_obj)->values[prop] = (value); \
725 		igt_pipe_obj_set_prop_changed(pipe_obj, prop); \
726 	} while (0)
727 
728 #define igt_pipe_set_prop_value(display, pipe, prop, value) \
729 	igt_pipe_obj_set_prop_value(&(display)->pipes[(pipe)], prop, value)
730 
731 extern bool igt_pipe_obj_try_prop_enum(igt_pipe_t *pipe,
732 				       enum igt_atomic_crtc_properties prop,
733 				       const char *val);
734 
735 extern void igt_pipe_obj_set_prop_enum(igt_pipe_t *pipe,
736 				       enum igt_atomic_crtc_properties prop,
737 				       const char *val);
738 
739 #define igt_pipe_try_prop_enum(display, pipe, prop, val) \
740 	igt_pipe_obj_try_prop_enum(&(display)->pipes[(pipe)], prop, val)
741 
742 #define igt_pipe_set_prop_enum(display, pipe, prop, val) \
743 	igt_pipe_obj_set_prop_enum(&(display)->pipes[(pipe)], prop, val)
744 
745 extern void igt_pipe_obj_replace_prop_blob(igt_pipe_t *pipe,
746 					   enum igt_atomic_crtc_properties prop,
747 					   const void *ptr, size_t length);
748 
749 #define igt_pipe_replace_prop_blob(display, pipe, prop, ptr, length) \
750 	igt_pipe_obj_replace_prop_blob(&(display)->pipes[(pipe)], prop, ptr, length)
751 
752 void igt_pipe_refresh(igt_display_t *display, enum pipe pipe, bool force);
753 
754 void igt_enable_connectors(int drm_fd);
755 void igt_reset_connectors(void);
756 
757 uint32_t kmstest_get_vbl_flag(uint32_t pipe_id);
758 
759 const struct edid *igt_kms_get_base_edid(void);
760 const struct edid *igt_kms_get_alt_edid(void);
761 const struct edid *igt_kms_get_hdmi_audio_edid(void);
762 const struct edid *igt_kms_get_dp_audio_edid(void);
763 const struct edid *igt_kms_get_4k_edid(void);
764 const struct edid *igt_kms_get_3d_edid(void);
765 
766 struct udev_monitor *igt_watch_hotplug(void);
767 bool igt_hotplug_detected(struct udev_monitor *mon,
768 			  int timeout_secs);
769 bool igt_lease_change_detected(struct udev_monitor *mon,
770 			       int timeout_secs);
771 void igt_flush_hotplugs(struct udev_monitor *mon);
772 void igt_cleanup_hotplug(struct udev_monitor *mon);
773 
774 bool igt_display_has_format_mod(igt_display_t *display, uint32_t format, uint64_t modifier);
775 bool igt_plane_has_format_mod(igt_plane_t *plane, uint32_t format, uint64_t modifier);
776 
777 /**
778  * igt_vblank_after_eq:
779  * @a: First vblank sequence number.
780  * @b: Second vblank sequence number.
781  *
782  * Compare vblank sequence numbers,
783  * handling wraparound correctly.
784  *
785  * Returns: @a >= @b
786  */
igt_vblank_after_eq(uint32_t a,uint32_t b)787 static inline bool igt_vblank_after_eq(uint32_t a, uint32_t b)
788 {
789 	return (int32_t)(a - b) >= 0;
790 }
791 
792 /**
793  * igt_vblank_before_eq:
794  * @a: First vblank sequence number.
795  * @b: Second vblank sequence number.
796  *
797  * Compare vblank sequence numbers,
798  * handling wraparound correctly.
799  *
800  * Returns: @a <= @b
801  */
igt_vblank_before_eq(uint32_t a,uint32_t b)802 static inline bool igt_vblank_before_eq(uint32_t a, uint32_t b)
803 {
804 	return igt_vblank_after_eq(b, a);
805 }
806 
807 /**
808  * igt_vblank_after:
809  * @a: First vblank sequence number.
810  * @b: Second vblank sequence number.
811  *
812  * Compare vblank sequence numbers,
813  * handling wraparound correctly.
814  *
815  * Returns: @a > @b
816  */
igt_vblank_after(uint32_t a,uint32_t b)817 static inline bool igt_vblank_after(uint32_t a, uint32_t b)
818 {
819 	return (int32_t)(b - a) < 0;
820 }
821 
822 /**
823  * igt_vblank_before:
824  * @a: First vblank sequence number.
825  * @b: Second vblank sequence number.
826  *
827  * Compare vblank sequence numbers,
828  * handling wraparound correctly.
829  *
830  * Returns: @a < @b
831  */
igt_vblank_before(uint32_t a,uint32_t b)832 static inline bool igt_vblank_before(uint32_t a, uint32_t b)
833 {
834 	return igt_vblank_after(b, a);
835 }
836 
837 #endif /* __IGT_KMS_H__ */
838