Oscar Mateo | 37f26d1 | 2013-11-12 11:50:38 +0000 | [diff] [blame] | 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 | * |
Daniel Vetter | 57d7db8 | 2014-03-26 09:06:11 +0100 | [diff] [blame] | 23 | * Authors: |
| 24 | * Daniel Vetter <daniel.vetter@ffwll.ch> |
| 25 | * Damien Lespiau <damien.lespiau@intel.com> |
Oscar Mateo | 37f26d1 | 2013-11-12 11:50:38 +0000 | [diff] [blame] | 26 | */ |
| 27 | |
| 28 | #ifndef __IGT_KMS_H__ |
| 29 | #define __IGT_KMS_H__ |
| 30 | |
Damien Lespiau | 3670d6d | 2014-01-27 16:25:43 +0000 | [diff] [blame] | 31 | #include <stdbool.h> |
Daniel Vetter | 6cfcd71 | 2014-03-22 20:07:35 +0100 | [diff] [blame] | 32 | #include <stdint.h> |
Thomas Wood | d96490a | 2014-06-16 16:21:35 +0100 | [diff] [blame] | 33 | #include <stddef.h> |
Oscar Mateo | 37f26d1 | 2013-11-12 11:50:38 +0000 | [diff] [blame] | 34 | |
Daniel Vetter | 254f19b | 2014-03-22 21:29:01 +0100 | [diff] [blame] | 35 | #include <xf86drmMode.h> |
| 36 | |
Daniel Vetter | 9a15b5a | 2014-08-12 11:13:03 +0200 | [diff] [blame] | 37 | #include "igt_fb.h" |
| 38 | |
Daniel Vetter | 33f0884 | 2014-08-12 11:23:09 +0200 | [diff] [blame] | 39 | /* Low-level helpers with kmstest_ prefix */ |
| 40 | |
Daniel Vetter | 64401f5 | 2014-03-26 10:19:42 +0100 | [diff] [blame] | 41 | enum pipe { |
| 42 | PIPE_A = 0, |
| 43 | PIPE_B, |
| 44 | PIPE_C, |
| 45 | I915_MAX_PIPES |
| 46 | }; |
Daniel Vetter | dd8fba4 | 2014-08-12 11:00:37 +0200 | [diff] [blame] | 47 | const char *kmstest_pipe_name(enum pipe pipe); |
Daniel Vetter | 64401f5 | 2014-03-26 10:19:42 +0100 | [diff] [blame] | 48 | |
| 49 | /* We namespace this enum to not conflict with the Android i915_drm.h */ |
| 50 | enum 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 Vetter | 27a19de | 2014-08-12 11:04:49 +0200 | [diff] [blame] | 58 | const char *kmstest_plane_name(enum igt_plane plane); |
Daniel Vetter | 64401f5 | 2014-03-26 10:19:42 +0100 | [diff] [blame] | 59 | |
| 60 | enum port { |
| 61 | PORT_A = 0, |
| 62 | PORT_B, |
| 63 | PORT_C, |
| 64 | PORT_D, |
| 65 | PORT_E, |
| 66 | I915_MAX_PORTS |
| 67 | }; |
Daniel Vetter | 27a19de | 2014-08-12 11:04:49 +0200 | [diff] [blame] | 68 | |
| 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 Vetter | 64401f5 | 2014-03-26 10:19:42 +0100 | [diff] [blame] | 76 | |
Daniel Vetter | 9a15b5a | 2014-08-12 11:13:03 +0200 | [diff] [blame] | 77 | /** |
| 78 | * kmstest_encoder_type_str: |
| 79 | * @type: DRM_MODE_ENCODER_* enumeration value |
| 80 | * |
| 81 | * Returns: A string representing the drm encoder @type. |
| 82 | */ |
| 83 | const char *kmstest_encoder_type_str(int type); |
Matt Roper | 1c25547 | 2014-06-30 16:44:24 -0700 | [diff] [blame] | 84 | |
Daniel Vetter | 9a15b5a | 2014-08-12 11:13:03 +0200 | [diff] [blame] | 85 | /** |
| 86 | * kmstest_connector_status_str: |
| 87 | * @status: DRM_MODE_* connector status value |
| 88 | * |
| 89 | * Returns: A string representing the drm connector status @status. |
| 90 | */ |
| 91 | const char *kmstest_connector_status_str(int status); |
Damien Lespiau | 068efd8 | 2014-07-08 16:02:05 +0100 | [diff] [blame] | 92 | |
Daniel Vetter | 9a15b5a | 2014-08-12 11:13:03 +0200 | [diff] [blame] | 93 | /** |
| 94 | * kmstest_connector_type_str: |
| 95 | * @type: DRM_MODE_CONNECTOR_* enumeration value |
| 96 | * |
| 97 | * Returns: A string representing the drm connector @type. |
| 98 | */ |
| 99 | const char *kmstest_connector_type_str(int type); |
Damien Lespiau | 3670d6d | 2014-01-27 16:25:43 +0000 | [diff] [blame] | 100 | |
Daniel Vetter | 3b39bff | 2014-08-12 11:31:44 +0200 | [diff] [blame] | 101 | void kmstest_dump_mode(drmModeModeInfo *mode); |
| 102 | |
| 103 | int kmstest_get_pipe_from_crtc_id(int fd, int crtc_id); |
| 104 | void kmstest_set_vt_graphics_mode(void); |
Thomas Wood | fcb324c | 2014-08-14 13:59:02 +0100 | [diff] [blame^] | 105 | void kmstest_restore_vt_mode(void); |
Daniel Vetter | 3b39bff | 2014-08-12 11:31:44 +0200 | [diff] [blame] | 106 | |
Oscar Mateo | 37f26d1 | 2013-11-12 11:50:38 +0000 | [diff] [blame] | 107 | struct 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 Wood | 37ffb22 | 2014-05-16 17:22:46 +0100 | [diff] [blame] | 116 | /** |
| 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 | */ |
| 123 | enum kmstest_force_connector_state { |
| 124 | FORCE_CONNECTOR_UNSPECIFIED, |
| 125 | FORCE_CONNECTOR_ON, |
| 126 | FORCE_CONNECTOR_DIGITAL, |
| 127 | FORCE_CONNECTOR_OFF |
| 128 | }; |
| 129 | |
Thomas Wood | 13cd79c | 2014-05-27 14:47:25 +0100 | [diff] [blame] | 130 | |
| 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 | */ |
| 140 | enum 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 Vetter | 3b39bff | 2014-08-12 11:31:44 +0200 | [diff] [blame] | 150 | bool kmstest_force_connector(int fd, drmModeConnector *connector, |
| 151 | enum kmstest_force_connector_state state); |
| 152 | void kmstest_force_edid(int drm_fd, drmModeConnector *connector, |
| 153 | const unsigned char *edid, size_t length); |
Thomas Wood | 13cd79c | 2014-05-27 14:47:25 +0100 | [diff] [blame] | 154 | |
Daniel Vetter | 81dfcab | 2014-08-12 11:56:41 +0200 | [diff] [blame] | 155 | bool kmstest_get_connector_default_mode(int drm_fd, drmModeConnector *connector, |
| 156 | drmModeModeInfo *mode); |
Daniel Vetter | 1cad834 | 2014-08-12 11:57:32 +0200 | [diff] [blame] | 157 | bool kmstest_get_connector_config(int drm_fd, uint32_t connector_id, |
| 158 | unsigned long crtc_idx_mask, |
| 159 | struct kmstest_connector_config *config); |
Oscar Mateo | 37f26d1 | 2013-11-12 11:50:38 +0000 | [diff] [blame] | 160 | void kmstest_free_connector_config(struct kmstest_connector_config *config); |
| 161 | |
Daniel Vetter | 29ee36f | 2014-04-24 23:33:09 +0200 | [diff] [blame] | 162 | void kmstest_set_connector_dpms(int fd, drmModeConnector *connector, int mode); |
Paulo Zanoni | 4924b78 | 2014-08-06 12:14:56 -0300 | [diff] [blame] | 163 | bool 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 Zanoni | d523656 | 2014-08-06 14:31:53 -0300 | [diff] [blame] | 166 | void kmstest_unset_all_crtcs(int drm_fd, drmModeResPtr resources); |
Oscar Mateo | 37f26d1 | 2013-11-12 11:50:38 +0000 | [diff] [blame] | 167 | |
Damien Lespiau | 3670d6d | 2014-01-27 16:25:43 +0000 | [diff] [blame] | 168 | /* |
| 169 | * A small modeset API |
| 170 | */ |
| 171 | |
Daniel Vetter | 33f0884 | 2014-08-12 11:23:09 +0200 | [diff] [blame] | 172 | /* High-level kms api with igt_ prefix */ |
Daniel Vetter | 9a15b5a | 2014-08-12 11:13:03 +0200 | [diff] [blame] | 173 | enum igt_commit_style { |
| 174 | COMMIT_LEGACY = 0, |
| 175 | COMMIT_UNIVERSAL, |
| 176 | /* We'll add atomic here eventually. */ |
| 177 | }; |
| 178 | |
Damien Lespiau | 3670d6d | 2014-01-27 16:25:43 +0000 | [diff] [blame] | 179 | typedef struct igt_display igt_display_t; |
| 180 | typedef struct igt_pipe igt_pipe_t; |
Damien Lespiau | 5ec399b | 2014-02-05 16:36:51 +0000 | [diff] [blame] | 181 | typedef uint32_t igt_fixed_t; /* 16.16 fixed point */ |
Damien Lespiau | 3670d6d | 2014-01-27 16:25:43 +0000 | [diff] [blame] | 182 | |
Daniel Vetter | 9a15b5a | 2014-08-12 11:13:03 +0200 | [diff] [blame] | 183 | typedef 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 Lespiau | 3670d6d | 2014-01-27 16:25:43 +0000 | [diff] [blame] | 191 | typedef struct { |
Thomas Wood | 52a3a2e | 2014-06-09 17:23:21 +0100 | [diff] [blame] | 192 | /*< private >*/ |
Damien Lespiau | 3670d6d | 2014-01-27 16:25:43 +0000 | [diff] [blame] | 193 | igt_pipe_t *pipe; |
| 194 | int index; |
Damien Lespiau | b2eb485 | 2014-07-08 15:23:05 +0100 | [diff] [blame] | 195 | /* capabilities */ |
Damien Lespiau | 5ec399b | 2014-02-05 16:36:51 +0000 | [diff] [blame] | 196 | unsigned int is_primary : 1; |
| 197 | unsigned int is_cursor : 1; |
Damien Lespiau | b2eb485 | 2014-07-08 15:23:05 +0100 | [diff] [blame] | 198 | /* state tracking */ |
Damien Lespiau | f0e0b2a | 2014-02-06 17:54:33 +0000 | [diff] [blame] | 199 | unsigned int fb_changed : 1; |
Damien Lespiau | 5ec399b | 2014-02-05 16:36:51 +0000 | [diff] [blame] | 200 | unsigned int position_changed : 1; |
Yi Sun | b5333b4 | 2014-05-23 08:28:47 +0800 | [diff] [blame] | 201 | unsigned int panning_changed : 1; |
Damien Lespiau | 068efd8 | 2014-07-08 16:02:05 +0100 | [diff] [blame] | 202 | unsigned int rotation_changed : 1; |
Damien Lespiau | f0e0b2a | 2014-02-06 17:54:33 +0000 | [diff] [blame] | 203 | /* |
| 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 Vetter | 9aea7ae | 2014-03-26 09:18:11 +0100 | [diff] [blame] | 208 | struct igt_fb *fb; |
Damien Lespiau | b2eb485 | 2014-07-08 15:23:05 +0100 | [diff] [blame] | 209 | |
| 210 | uint32_t rotation_property; |
| 211 | |
Damien Lespiau | 5ec399b | 2014-02-05 16:36:51 +0000 | [diff] [blame] | 212 | /* position within pipe_src_w x pipe_src_h */ |
| 213 | int crtc_x, crtc_y; |
Yi Sun | b5333b4 | 2014-05-23 08:28:47 +0800 | [diff] [blame] | 214 | /* panning offset within the fb */ |
| 215 | unsigned int pan_x, pan_y; |
Damien Lespiau | 068efd8 | 2014-07-08 16:02:05 +0100 | [diff] [blame] | 216 | igt_rotation_t rotation; |
Damien Lespiau | 3670d6d | 2014-01-27 16:25:43 +0000 | [diff] [blame] | 217 | } igt_plane_t; |
| 218 | |
| 219 | struct igt_pipe { |
| 220 | igt_display_t *display; |
| 221 | enum pipe pipe; |
Matt Roper | 794a9fd | 2014-06-30 16:44:26 -0700 | [diff] [blame] | 222 | bool enabled; |
Damien Lespiau | 3670d6d | 2014-01-27 16:25:43 +0000 | [diff] [blame] | 223 | #define IGT_MAX_PLANES 4 |
| 224 | int n_planes; |
| 225 | igt_plane_t planes[IGT_MAX_PLANES]; |
| 226 | }; |
| 227 | |
| 228 | typedef struct { |
Thomas Wood | 52a3a2e | 2014-06-09 17:23:21 +0100 | [diff] [blame] | 229 | /*< private >*/ |
Damien Lespiau | 3670d6d | 2014-01-27 16:25:43 +0000 | [diff] [blame] | 230 | 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 | |
| 238 | struct igt_display { |
| 239 | int drm_fd; |
Damien Lespiau | 3670d6d | 2014-01-27 16:25:43 +0000 | [diff] [blame] | 240 | 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 Roper | 794a9fd | 2014-06-30 16:44:26 -0700 | [diff] [blame] | 246 | bool has_universal_planes; |
Damien Lespiau | 3670d6d | 2014-01-27 16:25:43 +0000 | [diff] [blame] | 247 | }; |
| 248 | |
| 249 | void igt_display_init(igt_display_t *display, int drm_fd); |
| 250 | void igt_display_fini(igt_display_t *display); |
Matt Roper | 1c25547 | 2014-06-30 16:44:24 -0700 | [diff] [blame] | 251 | int igt_display_commit2(igt_display_t *display, enum igt_commit_style s); |
Damien Lespiau | 3670d6d | 2014-01-27 16:25:43 +0000 | [diff] [blame] | 252 | int igt_display_commit(igt_display_t *display); |
Matt Roper | 82bc03f | 2014-06-30 16:44:25 -0700 | [diff] [blame] | 253 | int igt_display_try_commit2(igt_display_t *display, enum igt_commit_style s); |
Damien Lespiau | 72e9a6c | 2014-02-04 14:59:39 +0000 | [diff] [blame] | 254 | int igt_display_get_n_pipes(igt_display_t *display); |
Damien Lespiau | 3670d6d | 2014-01-27 16:25:43 +0000 | [diff] [blame] | 255 | |
| 256 | const char *igt_output_name(igt_output_t *output); |
| 257 | drmModeModeInfo *igt_output_get_mode(igt_output_t *output); |
| 258 | void igt_output_set_pipe(igt_output_t *output, enum pipe pipe); |
Damien Lespiau | 2043e6b | 2014-02-11 17:45:48 +0000 | [diff] [blame] | 259 | igt_plane_t *igt_output_get_plane(igt_output_t *output, enum igt_plane plane); |
Damien Lespiau | 3670d6d | 2014-01-27 16:25:43 +0000 | [diff] [blame] | 260 | |
Damien Lespiau | b2eb485 | 2014-07-08 15:23:05 +0100 | [diff] [blame] | 261 | static inline bool igt_plane_supports_rotation(igt_plane_t *plane) |
| 262 | { |
| 263 | return plane->rotation_property != 0; |
| 264 | } |
| 265 | |
Daniel Vetter | 9aea7ae | 2014-03-26 09:18:11 +0100 | [diff] [blame] | 266 | void igt_plane_set_fb(igt_plane_t *plane, struct igt_fb *fb); |
Damien Lespiau | 5ec399b | 2014-02-05 16:36:51 +0000 | [diff] [blame] | 267 | void igt_plane_set_position(igt_plane_t *plane, int x, int y); |
Yi Sun | b5333b4 | 2014-05-23 08:28:47 +0800 | [diff] [blame] | 268 | void igt_plane_set_panning(igt_plane_t *plane, int x, int y); |
Damien Lespiau | 068efd8 | 2014-07-08 16:02:05 +0100 | [diff] [blame] | 269 | void igt_plane_set_rotation(igt_plane_t *plane, igt_rotation_t rotation); |
Damien Lespiau | 3670d6d | 2014-01-27 16:25:43 +0000 | [diff] [blame] | 270 | |
Daniel Vetter | 64401f5 | 2014-03-26 10:19:42 +0100 | [diff] [blame] | 271 | void igt_wait_for_vblank(int drm_fd, enum pipe pipe); |
| 272 | |
Damien Lespiau | 992bd5d | 2014-02-04 12:06:57 +0000 | [diff] [blame] | 273 | #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 Lespiau | 753352c | 2014-07-08 18:43:22 +0100 | [diff] [blame] | 277 | #define for_each_pipe(display, pipe) \ |
| 278 | for (pipe = 0; pipe < igt_display_get_n_pipes(display); pipe++) \ |
| 279 | |
Damien Lespiau | 09faa45 | 2014-02-06 15:45:42 +0000 | [diff] [blame] | 280 | /* |
| 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 Lespiau | 5ec399b | 2014-02-05 16:36:51 +0000 | [diff] [blame] | 286 | #define IGT_FIXED(i,f) ((i) << 16 | (f)) |
| 287 | |
Thomas Wood | b6ed9fb | 2014-05-28 14:06:01 +0100 | [diff] [blame] | 288 | void igt_enable_connectors(void); |
| 289 | void igt_reset_connectors(void); |
| 290 | |
Oscar Mateo | 37f26d1 | 2013-11-12 11:50:38 +0000 | [diff] [blame] | 291 | #endif /* __IGT_KMS_H__ */ |
| 292 | |