igt_kms.h 25.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * Copyright © 2013 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 *
Daniel Vetter's avatar
Daniel Vetter committed
23 24 25
 * Authors:
 * 	Daniel Vetter <daniel.vetter@ffwll.ch>
 * 	Damien Lespiau <damien.lespiau@intel.com>
26 27 28 29 30
 */

#ifndef __IGT_KMS_H__
#define __IGT_KMS_H__

Damien Lespiau's avatar
Damien Lespiau committed
31
#include <stdbool.h>
32
#include <stdint.h>
33
#include <stddef.h>
34
#include <assert.h>
35

36 37
#include <xf86drmMode.h>

38
#include "igt_fb.h"
39
#include "ioctl_wrappers.h"
40

41 42
/* Low-level helpers with kmstest_ prefix */

43 44 45 46 47 48 49
/**
 * pipe:
 * @PIPE_NONE: Invalid pipe, used for disconnecting a output from a pipe.
 * @PIPE_ANY: Deprecated alias for @PIPE_NONE.
 * @PIPE_A: First crtc.
 * @PIPE_B: Second crtc.
 * @PIPE_C: Third crtc.
50 51 52
 * @PIPE_D: Fourth crtc.
 * @PIPE_E: Fifth crtc.
 * @PIPE_F: Sixth crtc.
53
 * @IGT_MAX_PIPES: Max number of pipes allowed.
54
 */
55
enum pipe {
56 57
        PIPE_NONE = -1,
        PIPE_ANY = PIPE_NONE,
58 59 60
        PIPE_A = 0,
        PIPE_B,
        PIPE_C,
61 62 63
        PIPE_D,
        PIPE_E,
        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 71 72 73 74 75 76 77

enum port {
        PORT_A = 0,
        PORT_B,
        PORT_C,
        PORT_D,
        PORT_E,
        I915_MAX_PORTS
};
78 79 80 81 82

/**
 * kmstest_port_name:
 * @port: display plane
 *
83
 * Returns: String representing @port, e.g. "A".
84 85
 */
#define kmstest_port_name(port) ((port) + 'A')
86

87 88 89
const char *kmstest_encoder_type_str(int type);
const char *kmstest_connector_status_str(int status);
const char *kmstest_connector_type_str(int type);
Damien Lespiau's avatar
Damien Lespiau committed
90

91 92 93 94
void kmstest_dump_mode(drmModeModeInfo *mode);

int kmstest_get_pipe_from_crtc_id(int fd, int crtc_id);
void kmstest_set_vt_graphics_mode(void);
Thomas Wood's avatar
Thomas Wood committed
95
void kmstest_restore_vt_mode(void);
96
void kmstest_set_vt_text_mode(void);
97

98 99
enum igt_atomic_crtc_properties {
       IGT_CRTC_BACKGROUND = 0,
100 101
       IGT_CRTC_CTM,
       IGT_CRTC_GAMMA_LUT,
102 103 104
       IGT_CRTC_GAMMA_LUT_SIZE,
       IGT_CRTC_DEGAMMA_LUT,
       IGT_CRTC_DEGAMMA_LUT_SIZE,
105 106
       IGT_CRTC_MODE_ID,
       IGT_CRTC_ACTIVE,
107
       IGT_CRTC_OUT_FENCE_PTR,
108
       IGT_CRTC_VRR_ENABLED,
109 110 111
       IGT_NUM_CRTC_PROPS
};

112 113 114 115 116 117
/**
 * igt_crtc_prop_names
 *
 * igt_crtc_prop_names contains a list of crtc property names,
 * as indexed by the igt_atomic_crtc_properties enum.
 */
118
extern const char * const igt_crtc_prop_names[];
119

120 121
enum igt_atomic_connector_properties {
       IGT_CONNECTOR_SCALING_MODE = 0,
122
       IGT_CONNECTOR_CRTC_ID,
123
       IGT_CONNECTOR_DPMS,
124
       IGT_CONNECTOR_BROADCAST_RGB,
125
       IGT_CONNECTOR_CONTENT_PROTECTION,
126
       IGT_CONNECTOR_VRR_CAPABLE,
127
       IGT_CONNECTOR_HDCP_CONTENT_TYPE,
128
       IGT_CONNECTOR_LINK_STATUS,
129
       IGT_CONNECTOR_MAX_BPC,
130
       IGT_CONNECTOR_HDR_OUTPUT_METADATA,
131 132 133
       IGT_NUM_CONNECTOR_PROPS
};

134 135 136 137 138 139
/**
 * igt_connector_prop_names
 *
 * igt_connector_prop_names contains a list of crtc property names,
 * as indexed by the igt_atomic_connector_properties enum.
 */
140
extern const char * const igt_connector_prop_names[];
141

142 143 144 145 146
struct kmstest_connector_config {
	drmModeCrtc *crtc;
	drmModeConnector *connector;
	drmModeEncoder *encoder;
	drmModeModeInfo default_mode;
147

148
	int pipe;
149
	unsigned valid_crtc_idx_mask;
150 151
};

152 153
struct kmstest_plane {
	int id;
154
	int index;
155
	int type;
156 157 158 159 160 161 162 163 164 165 166 167
	int pos_x;
	int pos_y;
	int width;
	int height;
};

struct kmstest_crtc {
	int id;
	int pipe;
	bool active;
	int width;
	int height;
168 169
	int n_planes;
	struct kmstest_plane *planes;
170 171
};

172 173 174 175 176 177 178 179 180 181 182 183 184 185
/**
 * kmstest_force_connector_state:
 * @FORCE_CONNECTOR_UNSPECIFIED: Unspecified
 * @FORCE_CONNECTOR_ON: On
 * @FORCE_CONNECTOR_DIGITAL: Digital
 * @FORCE_CONNECTOR_OFF: Off
 */
enum kmstest_force_connector_state {
	FORCE_CONNECTOR_UNSPECIFIED,
	FORCE_CONNECTOR_ON,
	FORCE_CONNECTOR_DIGITAL,
	FORCE_CONNECTOR_OFF
};

186
/**
187
 * intel_broadcast_rgb_mode:
188 189 190 191 192
 * @BROADCAST_RGB_AUTO: Choose the color range to use automatically
 * @BROADCAST_RGB_FULL: Force the connector to use full color range
 * @BROADCAST_RGB_16_235: Force the connector to use a limited 16:235 color
 * range
 */
193
enum intel_broadcast_rgb_mode {
194 195 196 197 198
	BROADCAST_RGB_AUTO = 0,
	BROADCAST_RGB_FULL,
	BROADCAST_RGB_16_235
};

199
struct edid;
200

201 202 203
bool kmstest_force_connector(int fd, drmModeConnector *connector,
			     enum kmstest_force_connector_state state);
void kmstest_force_edid(int drm_fd, drmModeConnector *connector,
204
			const struct edid *edid);
205

206 207
bool kmstest_get_connector_default_mode(int drm_fd, drmModeConnector *connector,
					drmModeModeInfo *mode);
208 209 210
bool kmstest_get_connector_config(int drm_fd, uint32_t connector_id,
				  unsigned long crtc_idx_mask,
				  struct kmstest_connector_config *config);
211 212 213
bool kmstest_probe_connector_config(int drm_fd, uint32_t connector_id,
				    unsigned long crtc_idx_mask,
				    struct kmstest_connector_config *config);
214 215
void kmstest_free_connector_config(struct kmstest_connector_config *config);

216
void kmstest_set_connector_dpms(int fd, drmModeConnector *connector, int mode);
217 218 219
bool kmstest_get_property(int drm_fd, uint32_t object_id, uint32_t object_type,
			  const char *name, uint32_t *prop_id, uint64_t *value,
			  drmModePropertyPtr *prop);
220
void kmstest_unset_all_crtcs(int drm_fd, drmModeResPtr resources);
221
int kmstest_get_crtc_idx(drmModeRes *res, uint32_t crtc_id);
222 223 224
uint32_t kmstest_find_crtc_for_connector(int fd, drmModeRes *res,
					 drmModeConnector *connector,
					 uint32_t crtc_blacklist_idx_mask);
225

226
uint32_t kmstest_dumb_create(int fd, int width, int height, int bpp,
227
			     unsigned *stride, uint64_t *size);
228

229 230
void *kmstest_dumb_map_buffer(int fd, uint32_t handle, uint64_t size,
			      unsigned prot);
231
void kmstest_dumb_destroy(int fd, uint32_t handle);
232
void kmstest_wait_for_pageflip(int fd);
233
unsigned int kmstest_get_vblank(int fd, int pipe, unsigned int flags);
234

235 236
bool kms_has_vblank(int fd);

Damien Lespiau's avatar
Damien Lespiau committed
237 238 239 240
/*
 * A small modeset API
 */

241
/* High-level kms api with igt_ prefix */
242 243 244 245 246 247 248

/**
 * igt_commit_style:
 * @COMMIT_LEGACY: Changes will be committed using the legacy API.
 * @COMMIT_UNIVERSAL: Changes will be committed with the universal plane API, no modesets are allowed.
 * @COMMIT_ATOMIC: Changes will be committed using the atomic API.
 */
249 250 251
enum igt_commit_style {
	COMMIT_LEGACY = 0,
	COMMIT_UNIVERSAL,
252
	COMMIT_ATOMIC,
253 254
};

255 256 257 258 259 260 261 262 263 264 265
enum igt_atomic_plane_properties {
       IGT_PLANE_SRC_X = 0,
       IGT_PLANE_SRC_Y,
       IGT_PLANE_SRC_W,
       IGT_PLANE_SRC_H,

       IGT_PLANE_CRTC_X,
       IGT_PLANE_CRTC_Y,
       IGT_PLANE_CRTC_W,
       IGT_PLANE_CRTC_H,

266 267 268
/* Append new properties after IGT_PLANE_COORD_CHANGED_MASK */
#define IGT_PLANE_COORD_CHANGED_MASK 0xff

269 270
       IGT_PLANE_FB_ID,
       IGT_PLANE_CRTC_ID,
271
       IGT_PLANE_IN_FENCE_FD,
272 273
       IGT_PLANE_TYPE,
       IGT_PLANE_ROTATION,
274
       IGT_PLANE_IN_FORMATS,
275 276
       IGT_PLANE_COLOR_ENCODING,
       IGT_PLANE_COLOR_RANGE,
277 278
       IGT_PLANE_PIXEL_BLEND_MODE,
       IGT_PLANE_ALPHA,
279
       IGT_PLANE_ZPOS,
280 281 282
       IGT_NUM_PLANE_PROPS
};

283 284 285 286 287 288
/**
 * igt_plane_prop_names
 *
 * igt_plane_prop_names contains a list of crtc property names,
 * as indexed by the igt_atomic_plane_properties enum.
 */
289
extern const char * const igt_plane_prop_names[];
290

Damien Lespiau's avatar
Damien Lespiau committed
291 292
typedef struct igt_display igt_display_t;
typedef struct igt_pipe igt_pipe_t;
293
typedef uint32_t igt_fixed_t;			/* 16.16 fixed point */
Damien Lespiau's avatar
Damien Lespiau committed
294

295 296 297 298 299 300
typedef enum {
	/* this maps to the kernel API */
	IGT_ROTATION_0   = 1 << 0,
	IGT_ROTATION_90  = 1 << 1,
	IGT_ROTATION_180 = 1 << 2,
	IGT_ROTATION_270 = 1 << 3,
301 302
	IGT_REFLECT_X    = 1 << 4,
	IGT_REFLECT_Y    = 1 << 5,
303 304
} igt_rotation_t;

305 306 307
#define IGT_ROTATION_MASK \
	(IGT_ROTATION_0 | IGT_ROTATION_90 | IGT_ROTATION_180 | IGT_ROTATION_270)

308
typedef struct igt_plane {
Thomas Wood's avatar
Thomas Wood committed
309
	/*< private >*/
Damien Lespiau's avatar
Damien Lespiau committed
310
	igt_pipe_t *pipe;
311
	struct igt_plane *ref;
Damien Lespiau's avatar
Damien Lespiau committed
312
	int index;
313
	/* capabilities */
314
	int type;
315

316 317 318 319 320
	/*
	 * drm_plane can be NULL for primary and cursor planes (when not
	 * using the atomic modeset API)
	 */
	drmModePlane *drm_plane;
321

322 323
	/* gem handle for fb */
	uint32_t gem_handle;
324

325 326 327 328 329 330 331
	struct {
		uint64_t values[IGT_NUM_COLOR_ENCODINGS];
	} color_encoding;
	struct {
		uint64_t values[IGT_NUM_COLOR_RANGES];
	} color_range;

332 333 334
	uint64_t changed;
	uint32_t props[IGT_NUM_PLANE_PROPS];
	uint64_t values[IGT_NUM_PLANE_PROPS];
335 336 337 338

	uint64_t *modifiers;
	uint32_t *formats;
	int format_mod_count;
Damien Lespiau's avatar
Damien Lespiau committed
339 340 341 342 343
} igt_plane_t;

struct igt_pipe {
	igt_display_t *display;
	enum pipe pipe;
344

Damien Lespiau's avatar
Damien Lespiau committed
345
	int n_planes;
346 347 348
	int plane_cursor;
	int plane_primary;
	igt_plane_t *planes;
349

350 351 352
	uint64_t changed;
	uint32_t props[IGT_NUM_CRTC_PROPS];
	uint64_t values[IGT_NUM_CRTC_PROPS];
353

354
	uint32_t crtc_id;
355

356
	int32_t out_fence_fd;
Damien Lespiau's avatar
Damien Lespiau committed
357 358 359
};

typedef struct {
Thomas Wood's avatar
Thomas Wood committed
360
	/*< private >*/
Damien Lespiau's avatar
Damien Lespiau committed
361 362 363 364
	igt_display_t *display;
	uint32_t id;					/* KMS id */
	struct kmstest_connector_config config;
	char *name;
365
	bool force_reprobe;
366
	enum pipe pending_pipe;
367 368
	bool use_override_mode;
	drmModeModeInfo override_mode;
369 370 371 372 373 374

	/* bitmask of changed properties */
	uint64_t changed;

	uint32_t props[IGT_NUM_CONNECTOR_PROPS];
	uint64_t values[IGT_NUM_CONNECTOR_PROPS];
Damien Lespiau's avatar
Damien Lespiau committed
375 376 377 378 379 380
} igt_output_t;

struct igt_display {
	int drm_fd;
	int log_shift;
	int n_pipes;
381
	int n_planes;
Damien Lespiau's avatar
Damien Lespiau committed
382 383
	int n_outputs;
	igt_output_t *outputs;
384
	igt_plane_t *planes;
385
	igt_pipe_t *pipes;
386
	bool has_cursor_plane;
387
	bool is_atomic;
388
	bool first_commit;
389 390 391 392

	uint64_t *modifiers;
	uint32_t *formats;
	int format_mod_count;
Damien Lespiau's avatar
Damien Lespiau committed
393 394
};

395 396 397 398 399 400 401 402
typedef struct {
	int tile_group_id;
	bool tile_is_single_monitor;
	uint8_t num_h_tile, num_v_tile;
	uint8_t tile_h_loc, tile_v_loc;
	uint16_t tile_h_size, tile_v_size;
} igt_tile_info_t;

403
void igt_display_require(igt_display_t *display, int drm_fd);
Damien Lespiau's avatar
Damien Lespiau committed
404
void igt_display_fini(igt_display_t *display);
405
void igt_display_reset(igt_display_t *display);
406
int  igt_display_commit2(igt_display_t *display, enum igt_commit_style s);
Damien Lespiau's avatar
Damien Lespiau committed
407
int  igt_display_commit(igt_display_t *display);
408 409
int  igt_display_try_commit_atomic(igt_display_t *display, uint32_t flags, void *user_data);
void igt_display_commit_atomic(igt_display_t *display, uint32_t flags, void *user_data);
410
int  igt_display_try_commit2(igt_display_t *display, enum igt_commit_style s);
411
int  igt_display_drop_events(igt_display_t *display);
412
int  igt_display_get_n_pipes(igt_display_t *display);
413 414
void igt_display_require_output(igt_display_t *display);
void igt_display_require_output_on_pipe(igt_display_t *display, enum pipe pipe);
Damien Lespiau's avatar
Damien Lespiau committed
415 416 417

const char *igt_output_name(igt_output_t *output);
drmModeModeInfo *igt_output_get_mode(igt_output_t *output);
418
void igt_output_override_mode(igt_output_t *output, const drmModeModeInfo *mode);
Damien Lespiau's avatar
Damien Lespiau committed
419
void igt_output_set_pipe(igt_output_t *output, enum pipe pipe);
420 421
igt_plane_t *igt_output_get_plane(igt_output_t *output, int plane_idx);
igt_plane_t *igt_output_get_plane_type(igt_output_t *output, int plane_type);
422 423 424
int igt_output_count_plane_type(igt_output_t *output, int plane_type);
igt_plane_t *igt_output_get_plane_type_index(igt_output_t *output,
					     int plane_type, int index);
425
igt_output_t *igt_output_from_connector(igt_display_t *display,
426
    drmModeConnector *connector);
427
void igt_output_refresh(igt_output_t *output);
428
const drmModeModeInfo *igt_std_1024_mode_get(void);
429

430
igt_plane_t *igt_pipe_get_plane_type(igt_pipe_t *pipe, int plane_type);
431 432 433
int igt_pipe_count_plane_type(igt_pipe_t *pipe, int plane_type);
igt_plane_t *igt_pipe_get_plane_type_index(igt_pipe_t *pipe, int plane_type,
					   int index);
434
igt_output_t *igt_get_single_output_for_pipe(igt_display_t *display, enum pipe pipe);
Damien Lespiau's avatar
Damien Lespiau committed
435

436
void igt_pipe_request_out_fence(igt_pipe_t *pipe);
437

438
void igt_plane_set_fb(igt_plane_t *plane, struct igt_fb *fb);
439
void igt_plane_set_fence_fd(igt_plane_t *plane, int fence_fd);
440
void igt_plane_set_pipe(igt_plane_t *plane, igt_pipe_t *pipe);
441
void igt_plane_set_position(igt_plane_t *plane, int x, int y);
442
void igt_plane_set_size(igt_plane_t *plane, int w, int h);
443
void igt_plane_set_rotation(igt_plane_t *plane, igt_rotation_t rotation);
444 445 446 447
void igt_fb_set_position(struct igt_fb *fb, igt_plane_t *plane,
	uint32_t x, uint32_t y);
void igt_fb_set_size(struct igt_fb *fb, igt_plane_t *plane,
	uint32_t w, uint32_t h);
Damien Lespiau's avatar
Damien Lespiau committed
448

449
void igt_wait_for_vblank(int drm_fd, enum pipe pipe);
450
void igt_wait_for_vblank_count(int drm_fd, enum pipe pipe, int count);
451

452 453 454
static inline bool igt_output_is_connected(igt_output_t *output)
{
	/* Something went wrong during probe? */
455 456
	if (!output->config.connector ||
	    !output->config.connector->count_modes)
457 458 459 460 461 462 463 464
		return false;

	if (output->config.connector->connection == DRM_MODE_CONNECTED)
		return true;

	return false;
}

465 466 467 468 469 470 471 472 473 474
/**
 * igt_pipe_connector_valid:
 * @pipe: pipe to check.
 * @output: #igt_output_t to check.
 *
 * Checks whether the given pipe and output can be used together.
 */
#define igt_pipe_connector_valid(pipe, output) \
	(igt_output_is_connected((output)) && \
	       (output->config.valid_crtc_idx_mask & (1 << (pipe))))
475 476 477

#define for_each_if(condition) if (!(condition)) {} else

478 479 480 481 482 483 484
/**
 * for_each_connected_output:
 * @display: a pointer to an #igt_display_t structure
 * @output: The output to iterate.
 *
 * This for loop iterates over all outputs.
 */
485
#define for_each_connected_output(display, output)		\
486
	for (int i__ = 0;  assert(igt_can_fail()), i__ < (display)->n_outputs; i__++)	\
487 488
		for_each_if ((((output) = &(display)->outputs[i__]), \
			      igt_output_is_connected((output))))
489

490
/**
491
 * for_each_pipe_static:
492 493 494 495 496 497 498 499 500 501
 * @pipe: The pipe to iterate.
 *
 * This for loop iterates over all pipes supported by IGT libraries.
 *
 * This should be used to enumerate per-pipe subtests since it has no runtime
 * depencies.
 */
#define for_each_pipe_static(pipe) \
	for (pipe = 0; pipe < IGT_MAX_PIPES; pipe++)

502 503 504 505 506 507
/**
 * for_each_pipe:
 * @display: a pointer to an #igt_display_t structure
 * @pipe: The pipe to iterate.
 *
 * This for loop iterates over all pipes.
508 509 510
 *
 * Note that this cannot be used to enumerate per-pipe subtest names since it
 * depends upon runtime probing of the actual kms driver that is being tested.
511
 * Use #for_each_pipe_static instead.
512
 */
513
#define for_each_pipe(display, pipe)					\
514
	for (pipe = 0; assert(igt_can_fail()), pipe < igt_display_get_n_pipes(display); pipe++)
515

516 517 518 519 520 521 522 523
/**
 * for_each_pipe_with_valid_output:
 * @display: a pointer to an #igt_display_t structure
 * @pipe: The pipe for which this @pipe / @output combination is valid.
 * @output: The output for which this @pipe / @output combination is valid.
 *
 * This for loop is called over all connected outputs. This function
 * will try every combination of @pipe and @output.
524 525 526 527
 *
 * If you only need to test a single output for each pipe, use
 * for_each_pipe_with_single_output(), if you only need an
 * output for a single pipe, use igt_get_single_output_for_pipe().
528
 */
529
#define for_each_pipe_with_valid_output(display, pipe, output) \
530 531
	for (int con__ = (pipe) = 0; \
	     assert(igt_can_fail()), (pipe) < igt_display_get_n_pipes((display)) && con__ < (display)->n_outputs; \
532
	     con__ = (con__ + 1 < (display)->n_outputs) ? con__ + 1 : (pipe = pipe + 1, 0)) \
533 534
		for_each_if ((((output) = &(display)->outputs[con__]), \
			     igt_pipe_connector_valid((pipe), (output))))
535

536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
igt_output_t **__igt_pipe_populate_outputs(igt_display_t *display,
					   igt_output_t **chosen_outputs);

/**
 * for_each_pipe_with_single_output:
 * @display: a pointer to an #igt_display_t structure
 * @pipe: The pipe for which this @pipe / @output combination is valid.
 * @output: The output for which this @pipe / @output combination is valid.
 *
 * This loop is called over all pipes, and will try to find a compatible output
 * for each pipe. Unlike for_each_pipe_with_valid_output(), this function will
 * be called at most once for each pipe.
 */
#define for_each_pipe_with_single_output(display, pipe, output) \
	for (igt_output_t *__outputs[(display)->n_pipes], \
	     **__output = __igt_pipe_populate_outputs((display), __outputs); \
	     __output < &__outputs[(display)->n_pipes]; __output++) \
		for_each_if (*__output && \
			     ((pipe) = (__output - __outputs), (output) = *__output, 1))

556 557 558 559 560 561 562 563 564 565
/**
 * for_each_valid_output_on_pipe:
 * @display: a pointer to an #igt_display_t structure
 * @pipe: Pipe to enumerate valid outputs over
 * @output: The enumerated output.
 *
 * This for loop is called over all connected @output that can be used
 * on this @pipe . If there are no valid outputs for this pipe, nothing
 * happens.
 */
566
#define for_each_valid_output_on_pipe(display, pipe, output) \
567 568
	for_each_connected_output((display), (output)) \
		for_each_if (igt_pipe_connector_valid((pipe), (output)))
569

570
#define for_each_plane_on_pipe(display, pipe, plane)			\
571
	for (int j__ = 0; assert(igt_can_fail()), (plane) = &(display)->pipes[(pipe)].planes[j__], \
572
		     j__ < (display)->pipes[(pipe)].n_planes; j__++)
573

574 575
#define IGT_FIXED(i,f)	((i) << 16 | (f))

576
/**
577
 * igt_plane_has_prop:
578 579 580
 * @plane: Plane to check.
 * @prop: Property to check.
 *
581 582
 * Check whether plane supports a given property.
 *
583 584 585 586 587 588 589 590
 * Returns: True if the property is supported, otherwise false.
 */
static inline bool
igt_plane_has_prop(igt_plane_t *plane, enum igt_atomic_plane_properties prop)
{
	return plane->props[prop];
}

591 592
uint64_t igt_plane_get_prop(igt_plane_t *plane, enum igt_atomic_plane_properties prop);

593 594 595 596 597 598 599 600 601 602 603 604 605 606
#define igt_plane_is_prop_changed(plane, prop) \
	(!!((plane)->changed & (1 << (prop))))

#define igt_plane_set_prop_changed(plane, prop) \
	(plane)->changed |= 1 << (prop)

#define igt_plane_clear_prop_changed(plane, prop) \
	(plane)->changed &= ~(1 << (prop))

#define igt_plane_set_prop_value(plane, prop, value) \
	do { \
		plane->values[prop] = value; \
		igt_plane_set_prop_changed(plane, prop); \
	} while (0)
607

608 609 610 611 612 613 614 615
extern bool igt_plane_try_prop_enum(igt_plane_t *plane,
				    enum igt_atomic_plane_properties prop,
				    const char *val);

extern void igt_plane_set_prop_enum(igt_plane_t *plane,
				    enum igt_atomic_plane_properties prop,
				    const char *val);

616 617 618 619
extern void igt_plane_replace_prop_blob(igt_plane_t *plane,
					enum igt_atomic_plane_properties prop,
					const void *ptr, size_t length);

620
/**
621
 * igt_output_has_prop:
622 623 624
 * @output: Output to check.
 * @prop: Property to check.
 *
625 626
 * Check whether output supports a given property.
 *
627 628 629 630 631 632 633 634
 * Returns: True if the property is supported, otherwise false.
 */
static inline bool
igt_output_has_prop(igt_output_t *output, enum igt_atomic_connector_properties prop)
{
	return output->props[prop];
}

635 636
uint64_t igt_output_get_prop(igt_output_t *output, enum igt_atomic_connector_properties prop);

637 638 639 640 641 642 643 644 645 646 647 648 649
#define igt_output_is_prop_changed(output, prop) \
	(!!((output)->changed & (1 << (prop))))
#define igt_output_set_prop_changed(output, prop) \
	(output)->changed |= 1 << (prop)

#define igt_output_clear_prop_changed(output, prop) \
	(output)->changed &= ~(1 << (prop))

#define igt_output_set_prop_value(output, prop, value) \
	do { \
		(output)->values[prop] = (value); \
		igt_output_set_prop_changed(output, prop); \
	} while (0)
650

651 652 653 654 655 656 657 658
extern bool igt_output_try_prop_enum(igt_output_t *output,
				     enum igt_atomic_connector_properties prop,
				     const char *val);

extern void igt_output_set_prop_enum(igt_output_t *output,
				     enum igt_atomic_connector_properties prop,
				     const char *val);

659 660 661
extern void igt_output_replace_prop_blob(igt_output_t *output,
					 enum igt_atomic_connector_properties prop,
					 const void *ptr, size_t length);
662
/**
663
 * igt_pipe_obj_has_prop:
664 665 666
 * @pipe: Pipe to check.
 * @prop: Property to check.
 *
667 668
 * Check whether pipe supports a given property.
 *
669 670 671 672 673 674 675 676
 * Returns: True if the property is supported, otherwise false.
 */
static inline bool
igt_pipe_obj_has_prop(igt_pipe_t *pipe, enum igt_atomic_crtc_properties prop)
{
	return pipe->props[prop];
}

677 678 679
uint64_t igt_pipe_obj_get_prop(igt_pipe_t *pipe, enum igt_atomic_crtc_properties prop);

/**
680
 * igt_pipe_get_prop:
681 682 683 684
 * @display: Pointer to display.
 * @pipe: Target pipe.
 * @prop: Property to return.
 *
685 686
 * Return current value on a pipe for a given property.
 *
687 688 689 690 691 692 693 694 695 696 697
 * Returns: The value the property is set to, if this
 * is a blob, the blob id is returned. This can be passed
 * to drmModeGetPropertyBlob() to get the contents of the blob.
 */
static inline uint64_t
igt_pipe_get_prop(igt_display_t *display, enum pipe pipe,
		  enum igt_atomic_crtc_properties prop)
{
	return igt_pipe_obj_get_prop(&display->pipes[pipe], prop);
}

698
/**
699
 * igt_pipe_has_prop:
700 701 702 703
 * @display: Pointer to display.
 * @pipe: Pipe to check.
 * @prop: Property to check.
 *
704 705
 * Check whether pipe supports a given property.
 *
706 707 708 709
 * Returns: True if the property is supported, otherwise false.
 */
static inline bool
igt_pipe_has_prop(igt_display_t *display, enum pipe pipe,
710
		  enum igt_atomic_crtc_properties prop)
711 712 713 714
{
	return display->pipes[pipe].props[prop];
}

715 716
#define igt_pipe_obj_is_prop_changed(pipe_obj, prop) \
	(!!((pipe_obj)->changed & (1 << (prop))))
717

718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741
#define igt_pipe_is_prop_changed(display, pipe, prop) \
	igt_pipe_obj_is_prop_changed(&(display)->pipes[(pipe)], prop)

#define igt_pipe_obj_set_prop_changed(pipe_obj, prop) \
	(pipe_obj)->changed |= 1 << (prop)

#define igt_pipe_set_prop_changed(display, pipe, prop) \
	igt_pipe_obj_set_prop_changed(&(display)->pipes[(pipe)], prop)

#define igt_pipe_obj_clear_prop_changed(pipe_obj, prop) \
	(pipe_obj)->changed &= ~(1 << (prop))

#define igt_pipe_clear_prop_changed(display, pipe, prop) \
	igt_pipe_obj_clear_prop_changed(&(display)->pipes[(pipe)], prop)

#define igt_pipe_obj_set_prop_value(pipe_obj, prop, value) \
	do { \
		(pipe_obj)->values[prop] = (value); \
		igt_pipe_obj_set_prop_changed(pipe_obj, prop); \
	} while (0)

#define igt_pipe_set_prop_value(display, pipe, prop, value) \
	igt_pipe_obj_set_prop_value(&(display)->pipes[(pipe)], prop, value)

742 743 744 745 746 747 748 749 750 751 752 753 754 755
extern bool igt_pipe_obj_try_prop_enum(igt_pipe_t *pipe,
				       enum igt_atomic_crtc_properties prop,
				       const char *val);

extern void igt_pipe_obj_set_prop_enum(igt_pipe_t *pipe,
				       enum igt_atomic_crtc_properties prop,
				       const char *val);

#define igt_pipe_try_prop_enum(display, pipe, prop, val) \
	igt_pipe_obj_try_prop_enum(&(display)->pipes[(pipe)], prop, val)

#define igt_pipe_set_prop_enum(display, pipe, prop, val) \
	igt_pipe_obj_set_prop_enum(&(display)->pipes[(pipe)], prop, val)

756
extern void igt_pipe_obj_replace_prop_blob(igt_pipe_t *pipe,
757 758 759 760 761 762
					   enum igt_atomic_crtc_properties prop,
					   const void *ptr, size_t length);

#define igt_pipe_replace_prop_blob(display, pipe, prop, ptr, length) \
	igt_pipe_obj_replace_prop_blob(&(display)->pipes[(pipe)], prop, ptr, length)

763
void igt_pipe_refresh(igt_display_t *display, enum pipe pipe, bool force);
764

765
void igt_enable_connectors(int drm_fd);
766 767
void igt_reset_connectors(void);

768 769
uint32_t kmstest_get_vbl_flag(uint32_t pipe_id);

770 771 772 773 774 775
const struct edid *igt_kms_get_base_edid(void);
const struct edid *igt_kms_get_alt_edid(void);
const struct edid *igt_kms_get_hdmi_audio_edid(void);
const struct edid *igt_kms_get_dp_audio_edid(void);
const struct edid *igt_kms_get_4k_edid(void);
const struct edid *igt_kms_get_3d_edid(void);
Thomas Wood's avatar
Thomas Wood committed
776

777 778 779
struct udev_monitor *igt_watch_hotplug(void);
bool igt_hotplug_detected(struct udev_monitor *mon,
			  int timeout_secs);
780 781
bool igt_lease_change_detected(struct udev_monitor *mon,
			       int timeout_secs);
782 783
bool igt_connector_event_detected(struct udev_monitor *mon, uint32_t conn_id,
				  uint32_t prop_id, int timeout_msecs);
784 785
void igt_flush_hotplugs(struct udev_monitor *mon);
void igt_cleanup_hotplug(struct udev_monitor *mon);
Thomas Wood's avatar
Thomas Wood committed
786

787 788 789
bool igt_display_has_format_mod(igt_display_t *display, uint32_t format, uint64_t modifier);
bool igt_plane_has_format_mod(igt_plane_t *plane, uint32_t format, uint64_t modifier);

790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849
/**
 * igt_vblank_after_eq:
 * @a: First vblank sequence number.
 * @b: Second vblank sequence number.
 *
 * Compare vblank sequence numbers,
 * handling wraparound correctly.
 *
 * Returns: @a >= @b
 */
static inline bool igt_vblank_after_eq(uint32_t a, uint32_t b)
{
	return (int32_t)(a - b) >= 0;
}

/**
 * igt_vblank_before_eq:
 * @a: First vblank sequence number.
 * @b: Second vblank sequence number.
 *
 * Compare vblank sequence numbers,
 * handling wraparound correctly.
 *
 * Returns: @a <= @b
 */
static inline bool igt_vblank_before_eq(uint32_t a, uint32_t b)
{
	return igt_vblank_after_eq(b, a);
}

/**
 * igt_vblank_after:
 * @a: First vblank sequence number.
 * @b: Second vblank sequence number.
 *
 * Compare vblank sequence numbers,
 * handling wraparound correctly.
 *
 * Returns: @a > @b
 */
static inline bool igt_vblank_after(uint32_t a, uint32_t b)
{
	return (int32_t)(b - a) < 0;
}

/**
 * igt_vblank_before:
 * @a: First vblank sequence number.
 * @b: Second vblank sequence number.
 *
 * Compare vblank sequence numbers,
 * handling wraparound correctly.
 *
 * Returns: @a < @b
 */
static inline bool igt_vblank_before(uint32_t a, uint32_t b)
{
	return igt_vblank_after(b, a);
}

850 851 852
void igt_parse_connector_tile_blob(drmModePropertyBlobPtr blob,
		igt_tile_info_t *tile);

853 854
int igt_connector_sysfs_open(int drm_fd,
			     drmModeConnector *connector);
855
uint32_t igt_reduce_format(uint32_t format);
856

857
#endif /* __IGT_KMS_H__ */