blob: 4263a0185eca0aa6a1d43b53ab8097aa51493bc5 [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>
Oscar Mateo37f26d12013-11-12 11:50:38 +000034
Daniel Vetter254f19b2014-03-22 21:29:01 +010035#include <xf86drmMode.h>
36
Daniel Vetter9a15b5a2014-08-12 11:13:03 +020037#include "igt_fb.h"
38
Daniel Vetter33f08842014-08-12 11:23:09 +020039/* Low-level helpers with kmstest_ prefix */
40
Daniel Vetter64401f52014-03-26 10:19:42 +010041enum pipe {
42 PIPE_A = 0,
43 PIPE_B,
44 PIPE_C,
45 I915_MAX_PIPES
46};
Daniel Vetterdd8fba42014-08-12 11:00:37 +020047const char *kmstest_pipe_name(enum pipe pipe);
Daniel Vetter64401f52014-03-26 10:19:42 +010048
49/* We namespace this enum to not conflict with the Android i915_drm.h */
50enum igt_plane {
51 IGT_PLANE_1 = 0,
52 IGT_PLANE_PRIMARY = IGT_PLANE_1,
53 IGT_PLANE_2,
54 IGT_PLANE_3,
55 IGT_PLANE_CURSOR,
56};
57
Daniel Vetter27a19de2014-08-12 11:04:49 +020058const char *kmstest_plane_name(enum igt_plane plane);
Daniel Vetter64401f52014-03-26 10:19:42 +010059
60enum port {
61 PORT_A = 0,
62 PORT_B,
63 PORT_C,
64 PORT_D,
65 PORT_E,
66 I915_MAX_PORTS
67};
Daniel Vetter27a19de2014-08-12 11:04:49 +020068
69/**
70 * kmstest_port_name:
71 * @port: display plane
72 *
73 * Returns: String represnting @port, e.g. "A".
74 */
75#define kmstest_port_name(port) ((port) + 'A')
Daniel Vetter64401f52014-03-26 10:19:42 +010076
Daniel Vetter9a15b5a2014-08-12 11:13:03 +020077/**
78 * kmstest_encoder_type_str:
79 * @type: DRM_MODE_ENCODER_* enumeration value
80 *
81 * Returns: A string representing the drm encoder @type.
82 */
83const char *kmstest_encoder_type_str(int type);
Matt Roper1c255472014-06-30 16:44:24 -070084
Daniel Vetter9a15b5a2014-08-12 11:13:03 +020085/**
86 * kmstest_connector_status_str:
87 * @status: DRM_MODE_* connector status value
88 *
89 * Returns: A string representing the drm connector status @status.
90 */
91const char *kmstest_connector_status_str(int status);
Damien Lespiau068efd82014-07-08 16:02:05 +010092
Daniel Vetter9a15b5a2014-08-12 11:13:03 +020093/**
94 * kmstest_connector_type_str:
95 * @type: DRM_MODE_CONNECTOR_* enumeration value
96 *
97 * Returns: A string representing the drm connector @type.
98 */
99const char *kmstest_connector_type_str(int type);
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000100
Daniel Vetter3b39bff2014-08-12 11:31:44 +0200101void kmstest_dump_mode(drmModeModeInfo *mode);
102
103int kmstest_get_pipe_from_crtc_id(int fd, int crtc_id);
104void kmstest_set_vt_graphics_mode(void);
Thomas Woodfcb324c2014-08-14 13:59:02 +0100105void kmstest_restore_vt_mode(void);
Daniel Vetter3b39bff2014-08-12 11:31:44 +0200106
Oscar Mateo37f26d12013-11-12 11:50:38 +0000107struct kmstest_connector_config {
108 drmModeCrtc *crtc;
109 drmModeConnector *connector;
110 drmModeEncoder *encoder;
111 drmModeModeInfo default_mode;
112 int crtc_idx;
113 int pipe;
114};
115
Thomas Wood37ffb222014-05-16 17:22:46 +0100116/**
117 * kmstest_force_connector_state:
118 * @FORCE_CONNECTOR_UNSPECIFIED: Unspecified
119 * @FORCE_CONNECTOR_ON: On
120 * @FORCE_CONNECTOR_DIGITAL: Digital
121 * @FORCE_CONNECTOR_OFF: Off
122 */
123enum kmstest_force_connector_state {
124 FORCE_CONNECTOR_UNSPECIFIED,
125 FORCE_CONNECTOR_ON,
126 FORCE_CONNECTOR_DIGITAL,
127 FORCE_CONNECTOR_OFF
128};
129
Thomas Wood13cd79c2014-05-27 14:47:25 +0100130
131/**
132 * kmstest_generic_edid:
133 * @EDID_XGA: 1024x768
134 * @EDID_SXGA: 1280x1024
135 * @EDID_UXGA: 1600x1200
136 * @EDID_WSXGA: 1680x1050
137 * @EDID_FHD: 1920x1080
138 * @MAX_EDIDS: Size of #generic_edid array
139 */
140enum kmstest_generic_edid {
141 EDID_XGA, /* 1024x768 */
142 EDID_SXGA, /* 1280x1024 */
143 EDID_UXGA, /* 1600x1200 */
144 EDID_WSXGA, /* 1680x1050 */
145 EDID_FHD, /* 1920x1080 */
146
147 MAX_EDIDS
148};
149
Daniel Vetter3b39bff2014-08-12 11:31:44 +0200150bool kmstest_force_connector(int fd, drmModeConnector *connector,
151 enum kmstest_force_connector_state state);
152void kmstest_force_edid(int drm_fd, drmModeConnector *connector,
153 const unsigned char *edid, size_t length);
Thomas Wood13cd79c2014-05-27 14:47:25 +0100154
Daniel Vetter81dfcab2014-08-12 11:56:41 +0200155bool kmstest_get_connector_default_mode(int drm_fd, drmModeConnector *connector,
156 drmModeModeInfo *mode);
Daniel Vetter1cad8342014-08-12 11:57:32 +0200157bool kmstest_get_connector_config(int drm_fd, uint32_t connector_id,
158 unsigned long crtc_idx_mask,
159 struct kmstest_connector_config *config);
Oscar Mateo37f26d12013-11-12 11:50:38 +0000160void kmstest_free_connector_config(struct kmstest_connector_config *config);
161
Daniel Vetter29ee36f2014-04-24 23:33:09 +0200162void kmstest_set_connector_dpms(int fd, drmModeConnector *connector, int mode);
Paulo Zanoni4924b782014-08-06 12:14:56 -0300163bool kmstest_get_property(int drm_fd, uint32_t object_id, uint32_t object_type,
164 const char *name, uint32_t *prop_id, uint64_t *value,
165 drmModePropertyPtr *prop);
Paulo Zanonid5236562014-08-06 14:31:53 -0300166void kmstest_unset_all_crtcs(int drm_fd, drmModeResPtr resources);
Oscar Mateo37f26d12013-11-12 11:50:38 +0000167
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000168/*
169 * A small modeset API
170 */
171
Daniel Vetter33f08842014-08-12 11:23:09 +0200172/* High-level kms api with igt_ prefix */
Daniel Vetter9a15b5a2014-08-12 11:13:03 +0200173enum igt_commit_style {
174 COMMIT_LEGACY = 0,
175 COMMIT_UNIVERSAL,
176 /* We'll add atomic here eventually. */
177};
178
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000179typedef struct igt_display igt_display_t;
180typedef struct igt_pipe igt_pipe_t;
Damien Lespiau5ec399b2014-02-05 16:36:51 +0000181typedef uint32_t igt_fixed_t; /* 16.16 fixed point */
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000182
Daniel Vetter9a15b5a2014-08-12 11:13:03 +0200183typedef enum {
184 /* this maps to the kernel API */
185 IGT_ROTATION_0 = 1 << 0,
186 IGT_ROTATION_90 = 1 << 1,
187 IGT_ROTATION_180 = 1 << 2,
188 IGT_ROTATION_270 = 1 << 3,
189} igt_rotation_t;
190
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000191typedef struct {
Thomas Wood52a3a2e2014-06-09 17:23:21 +0100192 /*< private >*/
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000193 igt_pipe_t *pipe;
194 int index;
Damien Lespiaub2eb4852014-07-08 15:23:05 +0100195 /* capabilities */
Damien Lespiau5ec399b2014-02-05 16:36:51 +0000196 unsigned int is_primary : 1;
197 unsigned int is_cursor : 1;
Damien Lespiaub2eb4852014-07-08 15:23:05 +0100198 /* state tracking */
Damien Lespiauf0e0b2a2014-02-06 17:54:33 +0000199 unsigned int fb_changed : 1;
Damien Lespiau5ec399b2014-02-05 16:36:51 +0000200 unsigned int position_changed : 1;
Yi Sunb5333b42014-05-23 08:28:47 +0800201 unsigned int panning_changed : 1;
Damien Lespiau068efd82014-07-08 16:02:05 +0100202 unsigned int rotation_changed : 1;
Damien Lespiauf0e0b2a2014-02-06 17:54:33 +0000203 /*
204 * drm_plane can be NULL for primary and cursor planes (when not
205 * using the atomic modeset API)
206 */
207 drmModePlane *drm_plane;
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100208 struct igt_fb *fb;
Damien Lespiaub2eb4852014-07-08 15:23:05 +0100209
210 uint32_t rotation_property;
211
Damien Lespiau5ec399b2014-02-05 16:36:51 +0000212 /* position within pipe_src_w x pipe_src_h */
213 int crtc_x, crtc_y;
Yi Sunb5333b42014-05-23 08:28:47 +0800214 /* panning offset within the fb */
215 unsigned int pan_x, pan_y;
Damien Lespiau068efd82014-07-08 16:02:05 +0100216 igt_rotation_t rotation;
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000217} igt_plane_t;
218
219struct igt_pipe {
220 igt_display_t *display;
221 enum pipe pipe;
Matt Roper794a9fd2014-06-30 16:44:26 -0700222 bool enabled;
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000223#define IGT_MAX_PLANES 4
224 int n_planes;
225 igt_plane_t planes[IGT_MAX_PLANES];
226};
227
228typedef struct {
Thomas Wood52a3a2e2014-06-09 17:23:21 +0100229 /*< private >*/
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000230 igt_display_t *display;
231 uint32_t id; /* KMS id */
232 struct kmstest_connector_config config;
233 char *name;
234 bool valid;
235 unsigned long pending_crtc_idx_mask;
236} igt_output_t;
237
238struct igt_display {
239 int drm_fd;
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000240 int log_shift;
241 int n_pipes;
242 int n_outputs;
243 unsigned long pipes_in_use;
244 igt_output_t *outputs;
245 igt_pipe_t pipes[I915_MAX_PIPES];
Matt Roper794a9fd2014-06-30 16:44:26 -0700246 bool has_universal_planes;
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000247};
248
249void igt_display_init(igt_display_t *display, int drm_fd);
250void igt_display_fini(igt_display_t *display);
Matt Roper1c255472014-06-30 16:44:24 -0700251int igt_display_commit2(igt_display_t *display, enum igt_commit_style s);
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000252int igt_display_commit(igt_display_t *display);
Matt Roper82bc03f2014-06-30 16:44:25 -0700253int igt_display_try_commit2(igt_display_t *display, enum igt_commit_style s);
Damien Lespiau72e9a6c2014-02-04 14:59:39 +0000254int igt_display_get_n_pipes(igt_display_t *display);
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000255
256const char *igt_output_name(igt_output_t *output);
257drmModeModeInfo *igt_output_get_mode(igt_output_t *output);
258void igt_output_set_pipe(igt_output_t *output, enum pipe pipe);
Damien Lespiau2043e6b2014-02-11 17:45:48 +0000259igt_plane_t *igt_output_get_plane(igt_output_t *output, enum igt_plane plane);
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000260
Damien Lespiaub2eb4852014-07-08 15:23:05 +0100261static inline bool igt_plane_supports_rotation(igt_plane_t *plane)
262{
263 return plane->rotation_property != 0;
264}
265
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100266void igt_plane_set_fb(igt_plane_t *plane, struct igt_fb *fb);
Damien Lespiau5ec399b2014-02-05 16:36:51 +0000267void igt_plane_set_position(igt_plane_t *plane, int x, int y);
Yi Sunb5333b42014-05-23 08:28:47 +0800268void igt_plane_set_panning(igt_plane_t *plane, int x, int y);
Damien Lespiau068efd82014-07-08 16:02:05 +0100269void igt_plane_set_rotation(igt_plane_t *plane, igt_rotation_t rotation);
Damien Lespiau3670d6d2014-01-27 16:25:43 +0000270
Daniel Vetter64401f52014-03-26 10:19:42 +0100271void igt_wait_for_vblank(int drm_fd, enum pipe pipe);
272
Damien Lespiau992bd5d2014-02-04 12:06:57 +0000273#define for_each_connected_output(display, output) \
274 for (int i__ = 0; i__ < (display)->n_outputs; i__++) \
275 if ((output = &(display)->outputs[i__]), output->valid)
276
Damien Lespiau753352c2014-07-08 18:43:22 +0100277#define for_each_pipe(display, pipe) \
278 for (pipe = 0; pipe < igt_display_get_n_pipes(display); pipe++) \
279
Damien Lespiau09faa452014-02-06 15:45:42 +0000280/*
281 * Can be used with igt_output_set_pipe() to mean we don't care about the pipe
282 * that should drive this output
283 */
284#define PIPE_ANY (-1)
285
Damien Lespiau5ec399b2014-02-05 16:36:51 +0000286#define IGT_FIXED(i,f) ((i) << 16 | (f))
287
Thomas Woodb6ed9fb2014-05-28 14:06:01 +0100288void igt_enable_connectors(void);
289void igt_reset_connectors(void);
290
Oscar Mateo37f26d12013-11-12 11:50:38 +0000291#endif /* __IGT_KMS_H__ */
292