blob: 8dc118c961b787636530b382cc85ebe4b81289bd [file] [log] [blame]
Oscar Mateo37f26d12013-11-12 11:50:38 +00001/*
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 *
Daniel Vetter57d7db82014-03-26 09:06:11 +010023 * Authors:
24 * Daniel Vetter <daniel.vetter@ffwll.ch>
25 * Damien Lespiau <damien.lespiau@intel.com>
Oscar Mateo37f26d12013-11-12 11:50:38 +000026 */
27
28#ifndef __IGT_KMS_H__
29#define __IGT_KMS_H__
30
Damien Lespiau3670d6d2014-01-27 16:25:43 +000031#include <stdbool.h>
Daniel Vetter6cfcd712014-03-22 20:07:35 +010032#include <stdint.h>
Thomas Woodd96490a2014-06-16 16:21:35 +010033#include <stddef.h>
Daniel Vetter3f560382017-08-14 11:32:07 +020034#include <assert.h>
Oscar Mateo37f26d12013-11-12 11:50:38 +000035
Daniel Vetter254f19b2014-03-22 21:29:01 +010036#include <xf86drmMode.h>
37
Daniel Vetter9a15b5a2014-08-12 11:13:03 +020038#include "igt_fb.h"
Tvrtko Ursuline36091d2015-03-03 14:11:01 +000039#include "ioctl_wrappers.h"
Daniel Vetter9a15b5a2014-08-12 11:13:03 +020040
Daniel Vetter33f08842014-08-12 11:23:09 +020041/* Low-level helpers with kmstest_ prefix */
42
Maarten Lankhorst2d672a12016-07-27 15:33:12 +020043/**
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.
Leo (Sunpeng) Lidf682172017-06-09 17:13:04 -040050 * ... and so on.
51 * @IGT_MAX_PIPES: Max number of pipes allowed.
Maarten Lankhorst2d672a12016-07-27 15:33:12 +020052 */
Daniel Vetter64401f52014-03-26 10:19:42 +010053enum pipe {
Maarten Lankhorst0794ebe2016-06-30 07:43:36 +020054 PIPE_NONE = -1,
55 PIPE_ANY = PIPE_NONE,
Daniel Vetter64401f52014-03-26 10:19:42 +010056 PIPE_A = 0,
57 PIPE_B,
58 PIPE_C,
Leo (Sunpeng) Li597cae92017-06-09 17:08:53 -040059 PIPE_D,
60 PIPE_E,
61 PIPE_F,
Leo (Sunpeng) Lidf682172017-06-09 17:13:04 -040062 IGT_MAX_PIPES
Daniel Vetter64401f52014-03-26 10:19:42 +010063};
Daniel Vetterdd8fba42014-08-12 11:00:37 +020064const char *kmstest_pipe_name(enum pipe pipe);
Mika Kahola12e34d82016-11-23 11:19:37 +020065int kmstest_pipe_to_index(char pipe);
Robert Foss36656232017-01-18 12:28:45 -050066const char *kmstest_plane_type_name(int plane_type);
Daniel Vetter64401f52014-03-26 10:19:42 +010067
68enum port {
69 PORT_A = 0,
70 PORT_B,
71 PORT_C,
72 PORT_D,
73 PORT_E,
74 I915_MAX_PORTS
75};
Daniel Vetter27a19de2014-08-12 11:04:49 +020076
77/**
78 * kmstest_port_name:
79 * @port: display plane
80 *
Thomas Wood519f3772014-09-26 14:24:52 +010081 * Returns: String representing @port, e.g. "A".
Daniel Vetter27a19de2014-08-12 11:04:49 +020082 */
83#define kmstest_port_name(port) ((port) + 'A')
Daniel Vetter64401f52014-03-26 10:19:42 +010084
Daniel Vetter9a15b5a2014-08-12 11:13:03 +020085const char *kmstest_encoder_type_str(int type);
Daniel Vetter9a15b5a2014-08-12 11:13:03 +020086const char *kmstest_connector_status_str(int status);
Daniel Vetter9a15b5a2014-08-12 11:13:03 +020087const char *kmstest_connector_type_str(int type);
Damien Lespiau3670d6d2014-01-27 16:25:43 +000088
Daniel Vetter3b39bff2014-08-12 11:31:44 +020089void kmstest_dump_mode(drmModeModeInfo *mode);
90
91int kmstest_get_pipe_from_crtc_id(int fd, int crtc_id);
92void kmstest_set_vt_graphics_mode(void);
Thomas Woodfcb324c2014-08-14 13:59:02 +010093void kmstest_restore_vt_mode(void);
Daniel Vetter3b39bff2014-08-12 11:31:44 +020094
Mayuresh Gharpure0e2e8802016-03-11 13:55:29 +053095enum igt_atomic_crtc_properties {
96 IGT_CRTC_BACKGROUND = 0,
Lionel Landwerlin17166252016-03-18 17:33:01 +000097 IGT_CRTC_CTM,
98 IGT_CRTC_DEGAMMA_LUT,
99 IGT_CRTC_GAMMA_LUT,
Maarten Lankhorstc7d4dab2016-06-30 12:33:47 +0200100 IGT_CRTC_MODE_ID,
101 IGT_CRTC_ACTIVE,
Gustavo Padovan513846b2016-06-20 10:24:08 -0400102 IGT_CRTC_OUT_FENCE_PTR,
Mayuresh Gharpure0e2e8802016-03-11 13:55:29 +0530103 IGT_NUM_CRTC_PROPS
104};
105
Gustavo Padovane707ace2016-10-26 12:14:43 +0000106/**
107 * igt_crtc_prop_names
108 *
109 * igt_crtc_prop_names contains a list of crtc property names,
110 * as indexed by the igt_atomic_crtc_properties enum.
111 */
112extern const char *igt_crtc_prop_names[];
113
Mayuresh Gharpure0e2e8802016-03-11 13:55:29 +0530114enum igt_atomic_connector_properties {
115 IGT_CONNECTOR_SCALING_MODE = 0,
Maarten Lankhorstc7d4dab2016-06-30 12:33:47 +0200116 IGT_CONNECTOR_CRTC_ID,
Maarten Lankhorstbbc0b3c2017-08-02 11:57:32 +0200117 IGT_CONNECTOR_DPMS,
Mayuresh Gharpure0e2e8802016-03-11 13:55:29 +0530118 IGT_NUM_CONNECTOR_PROPS
119};
120
Gustavo Padovane707ace2016-10-26 12:14:43 +0000121/**
122 * igt_connector_prop_names
123 *
124 * igt_connector_prop_names contains a list of crtc property names,
125 * as indexed by the igt_atomic_connector_properties enum.
126 */
127extern const char *igt_connector_prop_names[];
128
Oscar Mateo37f26d12013-11-12 11:50:38 +0000129struct kmstest_connector_config {
130 drmModeCrtc *crtc;
131 drmModeConnector *connector;
132 drmModeEncoder *encoder;
133 drmModeModeInfo default_mode;
Mayuresh Gharpure0e2e8802016-03-11 13:55:29 +0530134 uint64_t connector_scaling_mode;
Maarten Lankhorst0404de42016-06-29 15:56:28 +0200135 bool connector_scaling_mode_changed;
Maarten Lankhorstc7d4dab2016-06-30 12:33:47 +0200136 bool pipe_changed;
Mayuresh Gharpure0e2e8802016-03-11 13:55:29 +0530137 uint32_t atomic_props_connector[IGT_NUM_CONNECTOR_PROPS];
Oscar Mateo37f26d12013-11-12 11:50:38 +0000138 int pipe;
Maarten Lankhorstbe131262016-06-13 15:27:22 +0200139 unsigned valid_crtc_idx_mask;
Oscar Mateo37f26d12013-11-12 11:50:38 +0000140};
141
Mika Kahola12e34d82016-11-23 11:19:37 +0200142struct kmstest_plane {
143 int id;
Robert Fossfdced482017-01-18 11:25:39 -0500144 int index;
Robert Foss9de63592017-01-18 12:12:54 -0500145 int type;
Mika Kahola12e34d82016-11-23 11:19:37 +0200146 int pos_x;
147 int pos_y;
148 int width;
149 int height;
150};
151
152struct kmstest_crtc {
153 int id;
154 int pipe;
155 bool active;
156 int width;
157 int height;
Robert Foss260df252017-01-18 11:26:12 -0500158 int n_planes;
159 struct kmstest_plane *planes;
Mika Kahola12e34d82016-11-23 11:19:37 +0200160};
161
Thomas Wood37ffb222014-05-16 17:22:46 +0100162/**
163 * kmstest_force_connector_state:
164 * @FORCE_CONNECTOR_UNSPECIFIED: Unspecified
165 * @FORCE_CONNECTOR_ON: On
166 * @FORCE_CONNECTOR_DIGITAL: Digital
167 * @FORCE_CONNECTOR_OFF: Off
168 */
169enum kmstest_force_connector_state {
170 FORCE_CONNECTOR_UNSPECIFIED,
171 FORCE_CONNECTOR_ON,
172 FORCE_CONNECTOR_DIGITAL,
173 FORCE_CONNECTOR_OFF
174};
175
Lyude3bd89da2017-01-05 13:01:18 -0500176/**
177 * kmstest_broadcast_rgb_mode:
178 * @BROADCAST_RGB_AUTO: Choose the color range to use automatically
179 * @BROADCAST_RGB_FULL: Force the connector to use full color range
180 * @BROADCAST_RGB_16_235: Force the connector to use a limited 16:235 color
181 * range
182 */
183enum kmstest_broadcast_rgb_mode {
184 BROADCAST_RGB_AUTO = 0,
185 BROADCAST_RGB_FULL,
186 BROADCAST_RGB_16_235
187};
188
189
Daniel Vetter3b39bff2014-08-12 11:31:44 +0200190bool kmstest_force_connector(int fd, drmModeConnector *connector,
191 enum kmstest_force_connector_state state);
Thomas Wooda124b1a2014-07-30 11:10:49 +0100192void kmstest_edid_add_3d(const unsigned char *edid, size_t length, unsigned char *new_edid_ptr[], size_t *new_length);
Abdiel Janulgue3cfa6a92017-03-27 12:47:08 +0300193void kmstest_edid_add_4k(const unsigned char *edid, size_t length, unsigned char *new_edid_ptr[], size_t *new_length);
194void kmstest_edid_add_audio(const unsigned char *edid, size_t length, unsigned char *new_edid_ptr[], size_t *new_length);
Daniel Vetter3b39bff2014-08-12 11:31:44 +0200195void kmstest_force_edid(int drm_fd, drmModeConnector *connector,
196 const unsigned char *edid, size_t length);
Thomas Wood13cd79c2014-05-27 14:47:25 +0100197
Daniel Vetter81dfcab2014-08-12 11:56:41 +0200198bool kmstest_get_connector_default_mode(int drm_fd, drmModeConnector *connector,
199 drmModeModeInfo *mode);
Daniel Vetter1cad8342014-08-12 11:57:32 +0200200bool kmstest_get_connector_config(int drm_fd, uint32_t connector_id,
201 unsigned long crtc_idx_mask,
202 struct kmstest_connector_config *config);
Jesse Barnese28acef2016-01-14 14:03:53 -0800203bool kmstest_probe_connector_config(int drm_fd, uint32_t connector_id,
204 unsigned long crtc_idx_mask,
205 struct kmstest_connector_config *config);
Oscar Mateo37f26d12013-11-12 11:50:38 +0000206void kmstest_free_connector_config(struct kmstest_connector_config *config);
207
Daniel Vetter29ee36f2014-04-24 23:33:09 +0200208void kmstest_set_connector_dpms(int fd, drmModeConnector *connector, int mode);
Lyude3bd89da2017-01-05 13:01:18 -0500209bool kmstest_set_connector_broadcast_rgb(int fd, drmModeConnector *connector,
210 enum kmstest_broadcast_rgb_mode mode);
Paulo Zanoni4924b782014-08-06 12:14:56 -0300211bool kmstest_get_property(int drm_fd, uint32_t object_id, uint32_t object_type,
212 const char *name, uint32_t *prop_id, uint64_t *value,
213 drmModePropertyPtr *prop);
Paulo Zanonid5236562014-08-06 14:31:53 -0300214void kmstest_unset_all_crtcs(int drm_fd, drmModeResPtr resources);
Paulo Zanonic6279ec2016-02-26 08:54:57 -0300215int kmstest_get_crtc_idx(drmModeRes *res, uint32_t crtc_id);
Paulo Zanonid8bf28f2016-02-26 11:27:20 -0300216uint32_t kmstest_find_crtc_for_connector(int fd, drmModeRes *res,
217 drmModeConnector *connector,
218 uint32_t crtc_blacklist_idx_mask);
Oscar Mateo37f26d12013-11-12 11:50:38 +0000219
Tomeu Vizosodc84e7d2016-03-02 13:39:44 +0100220uint32_t kmstest_dumb_create(int fd, int width, int height, int bpp,
221 unsigned *stride, unsigned *size);
222
Tomeu Vizosofb66a5d2016-03-07 16:37:36 +0100223void *kmstest_dumb_map_buffer(int fd, uint32_t handle, uint64_t size,
224 unsigned prot);
Mika Kahola12e34d82016-11-23 11:19:37 +0200225unsigned int kmstest_get_vblank(int fd, int pipe, unsigned int flags);
Chris Wilson83884e92017-03-21 17:16:03 +0000226void kmstest_get_crtc(int fd, enum pipe pipe, struct kmstest_crtc *crtc);
227void igt_assert_plane_visible(int fd, enum pipe pipe, bool visibility);
Tomeu Vizosofb66a5d2016-03-07 16:37:36 +0100228
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000229/*
230 * A small modeset API
231 */
232
Daniel Vetter33f08842014-08-12 11:23:09 +0200233/* High-level kms api with igt_ prefix */
Maarten Lankhorst2d672a12016-07-27 15:33:12 +0200234
235/**
236 * igt_commit_style:
237 * @COMMIT_LEGACY: Changes will be committed using the legacy API.
238 * @COMMIT_UNIVERSAL: Changes will be committed with the universal plane API, no modesets are allowed.
239 * @COMMIT_ATOMIC: Changes will be committed using the atomic API.
240 */
Daniel Vetter9a15b5a2014-08-12 11:13:03 +0200241enum igt_commit_style {
242 COMMIT_LEGACY = 0,
243 COMMIT_UNIVERSAL,
Mayuresh Gharpure0e2e8802016-03-11 13:55:29 +0530244 COMMIT_ATOMIC,
Daniel Vetter9a15b5a2014-08-12 11:13:03 +0200245};
246
Mayuresh Gharpure0e2e8802016-03-11 13:55:29 +0530247enum igt_atomic_plane_properties {
248 IGT_PLANE_SRC_X = 0,
249 IGT_PLANE_SRC_Y,
250 IGT_PLANE_SRC_W,
251 IGT_PLANE_SRC_H,
252
253 IGT_PLANE_CRTC_X,
254 IGT_PLANE_CRTC_Y,
255 IGT_PLANE_CRTC_W,
256 IGT_PLANE_CRTC_H,
257
258 IGT_PLANE_FB_ID,
259 IGT_PLANE_CRTC_ID,
Robert Foss221848d2016-06-20 10:24:08 -0400260 IGT_PLANE_IN_FENCE_FD,
Mayuresh Gharpure0e2e8802016-03-11 13:55:29 +0530261 IGT_PLANE_TYPE,
262 IGT_PLANE_ROTATION,
263 IGT_NUM_PLANE_PROPS
264};
265
Gustavo Padovane707ace2016-10-26 12:14:43 +0000266/**
267 * igt_plane_prop_names
268 *
269 * igt_plane_prop_names contains a list of crtc property names,
270 * as indexed by the igt_atomic_plane_properties enum.
271 */
272extern const char *igt_plane_prop_names[];
Mayuresh Gharpure0e2e8802016-03-11 13:55:29 +0530273
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000274typedef struct igt_display igt_display_t;
275typedef struct igt_pipe igt_pipe_t;
Damien Lespiau5ec399b2014-02-05 16:36:51 +0000276typedef uint32_t igt_fixed_t; /* 16.16 fixed point */
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000277
Daniel Vetter9a15b5a2014-08-12 11:13:03 +0200278typedef enum {
279 /* this maps to the kernel API */
280 IGT_ROTATION_0 = 1 << 0,
281 IGT_ROTATION_90 = 1 << 1,
282 IGT_ROTATION_180 = 1 << 2,
283 IGT_ROTATION_270 = 1 << 3,
284} igt_rotation_t;
285
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000286typedef struct {
Thomas Wood52a3a2e2014-06-09 17:23:21 +0100287 /*< private >*/
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000288 igt_pipe_t *pipe;
289 int index;
Damien Lespiaub2eb4852014-07-08 15:23:05 +0100290 /* capabilities */
Robert Foss36656232017-01-18 12:28:45 -0500291 int type;
Damien Lespiaub2eb4852014-07-08 15:23:05 +0100292 /* state tracking */
Damien Lespiauf0e0b2a2014-02-06 17:54:33 +0000293 unsigned int fb_changed : 1;
Damien Lespiau5ec399b2014-02-05 16:36:51 +0000294 unsigned int position_changed : 1;
Damien Lespiau068efd82014-07-08 16:02:05 +0100295 unsigned int rotation_changed : 1;
chandra kondurua26f9f92015-03-30 13:52:04 -0700296 unsigned int size_changed : 1;
Damien Lespiauf0e0b2a2014-02-06 17:54:33 +0000297 /*
298 * drm_plane can be NULL for primary and cursor planes (when not
299 * using the atomic modeset API)
300 */
301 drmModePlane *drm_plane;
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100302 struct igt_fb *fb;
Damien Lespiaub2eb4852014-07-08 15:23:05 +0100303
304 uint32_t rotation_property;
305
Damien Lespiau5ec399b2014-02-05 16:36:51 +0000306 /* position within pipe_src_w x pipe_src_h */
307 int crtc_x, crtc_y;
Ville Syrjälä7b767542014-09-12 20:18:04 +0300308 /* size within pipe_src_w x pipe_src_h */
309 int crtc_w, crtc_h;
Lionel Landwerlincd8da3f2016-04-05 14:13:53 +0100310
311 /* position within the framebuffer */
312 uint32_t src_x;
313 uint32_t src_y;
314 /* size within the framebuffer*/
315 uint32_t src_w;
316 uint32_t src_h;
317
Damien Lespiau068efd82014-07-08 16:02:05 +0100318 igt_rotation_t rotation;
Robert Foss221848d2016-06-20 10:24:08 -0400319
320 /* in fence fd */
321 int fence_fd;
Mayuresh Gharpure0e2e8802016-03-11 13:55:29 +0530322 uint32_t atomic_props_plane[IGT_NUM_PLANE_PROPS];
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000323} igt_plane_t;
324
325struct igt_pipe {
326 igt_display_t *display;
327 enum pipe pipe;
Robert Foss36656232017-01-18 12:28:45 -0500328
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000329 int n_planes;
Robert Foss36656232017-01-18 12:28:45 -0500330 int plane_cursor;
331 int plane_primary;
332 igt_plane_t *planes;
Maarten Lankhorst9f45ea12016-06-30 10:24:28 +0200333
334 uint32_t atomic_props_crtc[IGT_NUM_CRTC_PROPS];
335
chandra konduruace42082015-03-30 13:44:32 -0700336 uint64_t background; /* Background color MSB BGR 16bpc LSB */
337 uint32_t background_changed : 1;
338 uint32_t background_property;
Lionel Landwerlin17166252016-03-18 17:33:01 +0000339
340 uint64_t degamma_blob;
341 uint32_t degamma_property;
342 uint64_t ctm_blob;
343 uint32_t ctm_property;
344 uint64_t gamma_blob;
345 uint32_t gamma_property;
346 uint32_t color_mgmt_changed : 1;
347
Lionel Landwerlin59b54872016-03-18 17:33:00 +0000348 uint32_t crtc_id;
Maarten Lankhorstc7d4dab2016-06-30 12:33:47 +0200349
350 uint64_t mode_blob;
351 bool mode_changed;
Gustavo Padovan513846b2016-06-20 10:24:08 -0400352
353 int32_t out_fence_fd;
354 bool out_fence_requested;
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000355};
356
357typedef struct {
Thomas Wood52a3a2e2014-06-09 17:23:21 +0100358 /*< private >*/
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000359 igt_display_t *display;
360 uint32_t id; /* KMS id */
361 struct kmstest_connector_config config;
362 char *name;
Maarten Lankhorstba237f92017-01-10 10:50:50 +0100363 bool force_reprobe;
Maarten Lankhorst76c7a712017-09-27 12:25:37 +0200364 enum pipe pending_pipe;
Ander Conselvan de Oliveira9aeff2b2015-03-30 10:03:00 +0300365 bool use_override_mode;
366 drmModeModeInfo override_mode;
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000367} igt_output_t;
368
369struct igt_display {
370 int drm_fd;
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000371 int log_shift;
372 int n_pipes;
373 int n_outputs;
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000374 igt_output_t *outputs;
Lyude3ccce992016-12-12 13:25:39 -0500375 igt_pipe_t *pipes;
Lyude80baeb02016-12-07 19:02:04 -0500376 bool has_cursor_plane;
Mayuresh Gharpure0e2e8802016-03-11 13:55:29 +0530377 bool is_atomic;
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000378};
379
380void igt_display_init(igt_display_t *display, int drm_fd);
381void igt_display_fini(igt_display_t *display);
Matt Roper1c255472014-06-30 16:44:24 -0700382int igt_display_commit2(igt_display_t *display, enum igt_commit_style s);
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000383int igt_display_commit(igt_display_t *display);
Maarten Lankhorst826150f2016-07-05 14:52:20 +0200384int igt_display_try_commit_atomic(igt_display_t *display, uint32_t flags, void *user_data);
385void igt_display_commit_atomic(igt_display_t *display, uint32_t flags, void *user_data);
Matt Roper82bc03f2014-06-30 16:44:25 -0700386int igt_display_try_commit2(igt_display_t *display, enum igt_commit_style s);
Damien Lespiau72e9a6c2014-02-04 14:59:39 +0000387int igt_display_get_n_pipes(igt_display_t *display);
Maarten Lankhorst0b8933d2017-06-12 11:03:22 +0200388void igt_display_require_output(igt_display_t *display);
389void igt_display_require_output_on_pipe(igt_display_t *display, enum pipe pipe);
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000390
391const char *igt_output_name(igt_output_t *output);
392drmModeModeInfo *igt_output_get_mode(igt_output_t *output);
Ander Conselvan de Oliveira9aeff2b2015-03-30 10:03:00 +0300393void igt_output_override_mode(igt_output_t *output, drmModeModeInfo *mode);
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000394void igt_output_set_pipe(igt_output_t *output, enum pipe pipe);
Maarten Lankhorst826150f2016-07-05 14:52:20 +0200395void igt_output_set_scaling_mode(igt_output_t *output, uint64_t scaling_mode);
Robert Foss36656232017-01-18 12:28:45 -0500396igt_plane_t *igt_output_get_plane(igt_output_t *output, int plane_idx);
397igt_plane_t *igt_output_get_plane_type(igt_output_t *output, int plane_type);
Lyude528cdaf2016-12-29 19:25:31 -0500398igt_output_t *igt_output_from_connector(igt_display_t *display,
Robert Foss36656232017-01-18 12:28:45 -0500399 drmModeConnector *connector);
400igt_plane_t *igt_pipe_get_plane_type(igt_pipe_t *pipe, int plane_type);
Lionel Landwerlin17166252016-03-18 17:33:01 +0000401bool igt_pipe_get_property(igt_pipe_t *pipe, const char *name,
402 uint32_t *prop_id, uint64_t *value,
403 drmModePropertyPtr *prop);
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000404
Damien Lespiaub2eb4852014-07-08 15:23:05 +0100405static inline bool igt_plane_supports_rotation(igt_plane_t *plane)
406{
407 return plane->rotation_property != 0;
408}
Gustavo Padovan513846b2016-06-20 10:24:08 -0400409void igt_pipe_request_out_fence(igt_pipe_t *pipe);
Lionel Landwerlin17166252016-03-18 17:33:01 +0000410void igt_pipe_set_degamma_lut(igt_pipe_t *pipe, void *ptr, size_t length);
411void igt_pipe_set_ctm_matrix(igt_pipe_t *pipe, void *ptr, size_t length);
412void igt_pipe_set_gamma_lut(igt_pipe_t *pipe, void *ptr, size_t length);
413
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100414void igt_plane_set_fb(igt_plane_t *plane, struct igt_fb *fb);
Robert Foss221848d2016-06-20 10:24:08 -0400415void igt_plane_set_fence_fd(igt_plane_t *plane, int fence_fd);
Damien Lespiau5ec399b2014-02-05 16:36:51 +0000416void igt_plane_set_position(igt_plane_t *plane, int x, int y);
Ville Syrjälä7b767542014-09-12 20:18:04 +0300417void igt_plane_set_size(igt_plane_t *plane, int w, int h);
Damien Lespiau068efd82014-07-08 16:02:05 +0100418void igt_plane_set_rotation(igt_plane_t *plane, igt_rotation_t rotation);
chandra konduruace42082015-03-30 13:44:32 -0700419void igt_crtc_set_background(igt_pipe_t *pipe, uint64_t background);
chandra kondurua26f9f92015-03-30 13:52:04 -0700420void igt_fb_set_position(struct igt_fb *fb, igt_plane_t *plane,
421 uint32_t x, uint32_t y);
422void igt_fb_set_size(struct igt_fb *fb, igt_plane_t *plane,
423 uint32_t w, uint32_t h);
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000424
Daniel Vetter64401f52014-03-26 10:19:42 +0100425void igt_wait_for_vblank(int drm_fd, enum pipe pipe);
Chris Wilson2c64f112017-03-13 15:58:26 +0000426void igt_wait_for_vblank_count(int drm_fd, enum pipe pipe, int count);
Daniel Vetter64401f52014-03-26 10:19:42 +0100427
Maarten Lankhorst5a636682016-06-30 09:18:49 +0200428static inline bool igt_output_is_connected(igt_output_t *output)
429{
430 /* Something went wrong during probe? */
431 if (!output->config.connector)
432 return false;
433
434 if (output->config.connector->connection == DRM_MODE_CONNECTED)
435 return true;
436
437 return false;
438}
439
Maarten Lankhorst2d672a12016-07-27 15:33:12 +0200440/**
441 * igt_pipe_connector_valid:
442 * @pipe: pipe to check.
443 * @output: #igt_output_t to check.
444 *
445 * Checks whether the given pipe and output can be used together.
446 */
447#define igt_pipe_connector_valid(pipe, output) \
448 (igt_output_is_connected((output)) && \
449 (output->config.valid_crtc_idx_mask & (1 << (pipe))))
Maarten Lankhorstbe131262016-06-13 15:27:22 +0200450
451#define for_each_if(condition) if (!(condition)) {} else
452
Maarten Lankhorst2d672a12016-07-27 15:33:12 +0200453/**
454 * for_each_connected_output:
455 * @display: a pointer to an #igt_display_t structure
456 * @output: The output to iterate.
457 *
458 * This for loop iterates over all outputs.
459 */
Damien Lespiau992bd5d2014-02-04 12:06:57 +0000460#define for_each_connected_output(display, output) \
Daniel Vetter3f560382017-08-14 11:32:07 +0200461 for (int i__ = 0; assert(igt_can_fail()), i__ < (display)->n_outputs; i__++) \
Maarten Lankhorst5a636682016-06-30 09:18:49 +0200462 for_each_if (((output = &(display)->outputs[i__]), \
463 igt_output_is_connected(output)))
Damien Lespiau992bd5d2014-02-04 12:06:57 +0000464
Maarten Lankhorst2d672a12016-07-27 15:33:12 +0200465/**
466 * for_each_pipe:
Daniel Vetter229d7d22017-08-14 11:32:05 +0200467 * @pipe: The pipe to iterate.
468 *
469 * This for loop iterates over all pipes supported by IGT libraries.
470 *
471 * This should be used to enumerate per-pipe subtests since it has no runtime
472 * depencies.
473 */
474#define for_each_pipe_static(pipe) \
475 for (pipe = 0; pipe < IGT_MAX_PIPES; pipe++)
476
477/**
478 * for_each_pipe:
Maarten Lankhorst2d672a12016-07-27 15:33:12 +0200479 * @display: a pointer to an #igt_display_t structure
480 * @pipe: The pipe to iterate.
481 *
482 * This for loop iterates over all pipes.
Daniel Vetter229d7d22017-08-14 11:32:05 +0200483 *
484 * Note that this cannot be used to enumerate per-pipe subtest names since it
485 * depends upon runtime probing of the actual kms driver that is being tested.
486 * Used #for_each_pipe_static instead.
Maarten Lankhorst2d672a12016-07-27 15:33:12 +0200487 */
Damien Lespiau753352c2014-07-08 18:43:22 +0100488#define for_each_pipe(display, pipe) \
Daniel Vetter3f560382017-08-14 11:32:07 +0200489 for (pipe = 0; assert(igt_can_fail()), pipe < igt_display_get_n_pipes(display); pipe++)
Damien Lespiau753352c2014-07-08 18:43:22 +0100490
Maarten Lankhorst2d672a12016-07-27 15:33:12 +0200491/**
492 * for_each_pipe_with_valid_output:
493 * @display: a pointer to an #igt_display_t structure
494 * @pipe: The pipe for which this @pipe / @output combination is valid.
495 * @output: The output for which this @pipe / @output combination is valid.
496 *
497 * This for loop is called over all connected outputs. This function
498 * will try every combination of @pipe and @output.
499 */
Maarten Lankhorstbe131262016-06-13 15:27:22 +0200500#define for_each_pipe_with_valid_output(display, pipe, output) \
501 for (int con__ = pipe = 0; \
Daniel Vetter3f560382017-08-14 11:32:07 +0200502 assert(igt_can_fail()), pipe < igt_display_get_n_pipes((display)) && con__ < (display)->n_outputs; \
Maarten Lankhorstbe131262016-06-13 15:27:22 +0200503 con__ = (con__ + 1 < (display)->n_outputs) ? con__ + 1 : (pipe = pipe + 1, 0)) \
504 for_each_if (((output = &(display)->outputs[con__]), \
505 igt_pipe_connector_valid(pipe, output)))
506
Maarten Lankhorst2d672a12016-07-27 15:33:12 +0200507/**
508 * for_each_valid_output_on_pipe:
509 * @display: a pointer to an #igt_display_t structure
510 * @pipe: Pipe to enumerate valid outputs over
511 * @output: The enumerated output.
512 *
513 * This for loop is called over all connected @output that can be used
514 * on this @pipe . If there are no valid outputs for this pipe, nothing
515 * happens.
516 */
Maarten Lankhorstbe131262016-06-13 15:27:22 +0200517#define for_each_valid_output_on_pipe(display, pipe, output) \
Maarten Lankhorst0404de42016-06-29 15:56:28 +0200518 for_each_connected_output(display, output) \
Maarten Lankhorstbe131262016-06-13 15:27:22 +0200519 for_each_if (igt_pipe_connector_valid(pipe, output))
520
Ville Syrjälä2b74b2b2015-03-27 20:51:46 +0200521#define for_each_plane_on_pipe(display, pipe, plane) \
Daniel Vetter3f560382017-08-14 11:32:07 +0200522 for (int j__ = 0; assert(igt_can_fail()), (plane) = &(display)->pipes[(pipe)].planes[j__], \
Mayuresh Gharpure0e2e8802016-03-11 13:55:29 +0530523 j__ < (display)->pipes[(pipe)].n_planes; j__++)
Ville Syrjälä2b74b2b2015-03-27 20:51:46 +0200524
Damien Lespiau5ec399b2014-02-05 16:36:51 +0000525#define IGT_FIXED(i,f) ((i) << 16 | (f))
526
Mayuresh Gharpure0e2e8802016-03-11 13:55:29 +0530527/**
528 * igt_atomic_populate_plane_req:
529 * @req: A pointer to drmModeAtomicReq
530 * @plane: A pointer igt_plane_t
531 * @prop: one of igt_atomic_plane_properties
532 * @value: the value to add
533 */
534#define igt_atomic_populate_plane_req(req, plane, prop, value) \
535 igt_assert_lt(0, drmModeAtomicAddProperty(req, plane->drm_plane->plane_id,\
536 plane->atomic_props_plane[prop], value))
537
538/**
539 * igt_atomic_populate_crtc_req:
540 * @req: A pointer to drmModeAtomicReq
Maarten Lankhorst9f45ea12016-06-30 10:24:28 +0200541 * @pipe: A pointer igt_pipe_t
Mayuresh Gharpure0e2e8802016-03-11 13:55:29 +0530542 * @prop: one of igt_atomic_crtc_properties
543 * @value: the value to add
544 */
Maarten Lankhorst9f45ea12016-06-30 10:24:28 +0200545#define igt_atomic_populate_crtc_req(req, pipe, prop, value) \
546 igt_assert_lt(0, drmModeAtomicAddProperty(req, pipe->crtc_id,\
547 pipe->atomic_props_crtc[prop], value))
Mayuresh Gharpure0e2e8802016-03-11 13:55:29 +0530548/**
549 * igt_atomic_populate_connector_req:
550 * @req: A pointer to drmModeAtomicReq
551 * @output: A pointer igt_output_t
552 * @prop: one of igt_atomic_connector_properties
553 * @value: the value to add
554 */
555#define igt_atomic_populate_connector_req(req, output, prop, value) \
556 igt_assert_lt(0, drmModeAtomicAddProperty(req, output->config.connector->connector_id,\
557 output->config.atomic_props_connector[prop], value))
558
Maarten Lankhorst7df7e3b2017-09-21 12:53:27 +0200559/*
560 * igt_pipe_refresh:
561 * @display: a pointer to an #igt_display_t structure
562 * @pipe: Pipe to refresh
563 * @force: Should be set to true if mode_blob is no longer considered
564 * to be valid, for example after doing an atomic commit during fork or closing display fd.
565 *
566 * Requests the pipe to be part of the state on next update.
567 * This is useful when state may have been out of sync after
568 * a fork, or we just want to be sure the pipe is included
569 * in the next commit.
570 */
571static inline void
572igt_pipe_refresh(igt_display_t *display, enum pipe pipe, bool force)
573{
574 if (force)
575 display->pipes[pipe].mode_blob = 0;
576
577 display->pipes[pipe].mode_changed = true;
578}
579
Thomas Woodb6ed9fb2014-05-28 14:06:01 +0100580void igt_enable_connectors(void);
581void igt_reset_connectors(void);
582
Marius Vlad7ead45c2016-07-04 16:52:46 +0300583uint32_t kmstest_get_vbl_flag(uint32_t pipe_id);
584
Thomas Wood8d82e5b2014-10-08 16:16:39 +0100585#define EDID_LENGTH 128
Thomas Wood273a06d2014-10-08 14:11:30 +0100586const unsigned char* igt_kms_get_base_edid(void);
Ville Syrjälä870548b2015-12-04 15:49:30 +0200587const unsigned char* igt_kms_get_alt_edid(void);
Thomas Wood273a06d2014-10-08 14:11:30 +0100588
Lyude6adb7b32016-11-17 10:06:09 -0500589#ifdef HAVE_UDEV
590struct udev_monitor *igt_watch_hotplug(void);
591bool igt_hotplug_detected(struct udev_monitor *mon,
592 int timeout_secs);
593void igt_flush_hotplugs(struct udev_monitor *mon);
594void igt_cleanup_hotplug(struct udev_monitor *mon);
595#endif
Thomas Wood273a06d2014-10-08 14:11:30 +0100596
Oscar Mateo37f26d12013-11-12 11:50:38 +0000597#endif /* __IGT_KMS_H__ */