lib/igt_kms: Clean up the other _name functions/macros
[platform/upstream/intel-gpu-tools.git] / lib / igt_kms.h
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
35 #include <xf86drmMode.h>
36
37 enum pipe {
38         PIPE_A = 0,
39         PIPE_B,
40         PIPE_C,
41         I915_MAX_PIPES
42 };
43 const char *kmstest_pipe_name(enum pipe pipe);
44
45 /* We namespace this enum to not conflict with the Android i915_drm.h */
46 enum igt_plane {
47         IGT_PLANE_1 = 0,
48         IGT_PLANE_PRIMARY = IGT_PLANE_1,
49         IGT_PLANE_2,
50         IGT_PLANE_3,
51         IGT_PLANE_CURSOR,
52 };
53
54 const char *kmstest_plane_name(enum igt_plane plane);
55
56 enum port {
57         PORT_A = 0,
58         PORT_B,
59         PORT_C,
60         PORT_D,
61         PORT_E,
62         I915_MAX_PORTS
63 };
64
65 /**
66  * kmstest_port_name:
67  * @port: display plane
68  *
69  * Returns: String represnting @port, e.g. "A".
70  */
71 #define kmstest_port_name(port) ((port) + 'A')
72
73 enum igt_commit_style {
74         COMMIT_LEGACY = 0,
75         COMMIT_UNIVERSAL,
76         /* We'll add atomic here eventually. */
77 };
78
79 typedef enum {
80         /* this maps to the kernel API */
81         IGT_ROTATION_0   = 1 << 0,
82         IGT_ROTATION_90  = 1 << 1,
83         IGT_ROTATION_180 = 1 << 2,
84         IGT_ROTATION_270 = 1 << 3,
85 } igt_rotation_t;
86
87 #include "igt_fb.h"
88
89 struct kmstest_connector_config {
90         drmModeCrtc *crtc;
91         drmModeConnector *connector;
92         drmModeEncoder *encoder;
93         drmModeModeInfo default_mode;
94         int crtc_idx;
95         int pipe;
96 };
97
98 /**
99  * kmstest_force_connector_state:
100  * @FORCE_CONNECTOR_UNSPECIFIED: Unspecified
101  * @FORCE_CONNECTOR_ON: On
102  * @FORCE_CONNECTOR_DIGITAL: Digital
103  * @FORCE_CONNECTOR_OFF: Off
104  */
105 enum kmstest_force_connector_state {
106         FORCE_CONNECTOR_UNSPECIFIED,
107         FORCE_CONNECTOR_ON,
108         FORCE_CONNECTOR_DIGITAL,
109         FORCE_CONNECTOR_OFF
110 };
111
112
113 /**
114  * kmstest_generic_edid:
115  * @EDID_XGA: 1024x768
116  * @EDID_SXGA: 1280x1024
117  * @EDID_UXGA: 1600x1200
118  * @EDID_WSXGA: 1680x1050
119  * @EDID_FHD: 1920x1080
120  * @MAX_EDIDS: Size of #generic_edid array
121  */
122 enum kmstest_generic_edid {
123         EDID_XGA,   /* 1024x768 */
124         EDID_SXGA,  /* 1280x1024 */
125         EDID_UXGA,  /* 1600x1200 */
126         EDID_WSXGA, /* 1680x1050 */
127         EDID_FHD,   /* 1920x1080 */
128
129         MAX_EDIDS
130 };
131
132
133 int kmstest_get_connector_default_mode(int drm_fd, drmModeConnector *connector,
134                                       drmModeModeInfo *mode);
135 int kmstest_get_connector_config(int drm_fd, uint32_t connector_id,
136                                  unsigned long crtc_idx_mask,
137                                  struct kmstest_connector_config *config);
138 bool kmstest_force_connector(int fd, drmModeConnector *connector,
139                              enum kmstest_force_connector_state state);
140 void kmstest_force_edid(int drm_fd, drmModeConnector *connector,
141                         const unsigned char *edid, size_t length);
142 void kmstest_free_connector_config(struct kmstest_connector_config *config);
143
144 void kmstest_dump_mode(drmModeModeInfo *mode);
145 int kmstest_get_pipe_from_crtc_id(int fd, int crtc_id);
146 const char *kmstest_encoder_type_str(int type);
147 const char *kmstest_connector_status_str(int type);
148 const char *kmstest_connector_type_str(int type);
149 void kmstest_set_connector_dpms(int fd, drmModeConnector *connector, int mode);
150 bool kmstest_get_property(int drm_fd, uint32_t object_id, uint32_t object_type,
151                           const char *name, uint32_t *prop_id, uint64_t *value,
152                           drmModePropertyPtr *prop);
153 void kmstest_unset_all_crtcs(int drm_fd, drmModeResPtr resources);
154
155 /*
156  * A small modeset API
157  */
158
159 typedef struct igt_display igt_display_t;
160 typedef struct igt_pipe igt_pipe_t;
161 typedef uint32_t igt_fixed_t;                   /* 16.16 fixed point */
162
163 typedef struct {
164         /*< private >*/
165         igt_pipe_t *pipe;
166         int index;
167         /* capabilities */
168         unsigned int is_primary       : 1;
169         unsigned int is_cursor        : 1;
170         /* state tracking */
171         unsigned int fb_changed       : 1;
172         unsigned int position_changed : 1;
173         unsigned int panning_changed  : 1;
174         unsigned int rotation_changed : 1;
175         /*
176          * drm_plane can be NULL for primary and cursor planes (when not
177          * using the atomic modeset API)
178          */
179         drmModePlane *drm_plane;
180         struct igt_fb *fb;
181
182         uint32_t rotation_property;
183
184         /* position within pipe_src_w x pipe_src_h */
185         int crtc_x, crtc_y;
186         /* panning offset within the fb */
187         unsigned int pan_x, pan_y;
188         igt_rotation_t rotation;
189 } igt_plane_t;
190
191 struct igt_pipe {
192         igt_display_t *display;
193         enum pipe pipe;
194         bool enabled;
195 #define IGT_MAX_PLANES  4
196         int n_planes;
197         igt_plane_t planes[IGT_MAX_PLANES];
198 };
199
200 typedef struct {
201         /*< private >*/
202         igt_display_t *display;
203         uint32_t id;                                    /* KMS id */
204         struct kmstest_connector_config config;
205         char *name;
206         bool valid;
207         unsigned long pending_crtc_idx_mask;
208 } igt_output_t;
209
210 struct igt_display {
211         int drm_fd;
212         int log_shift;
213         int n_pipes;
214         int n_outputs;
215         unsigned long pipes_in_use;
216         igt_output_t *outputs;
217         igt_pipe_t pipes[I915_MAX_PIPES];
218         bool has_universal_planes;
219 };
220
221 /* set vt into graphics mode, required to prevent fbcon from interfering */
222 void igt_set_vt_graphics_mode(void);
223
224 void igt_display_init(igt_display_t *display, int drm_fd);
225 void igt_display_fini(igt_display_t *display);
226 int  igt_display_commit2(igt_display_t *display, enum igt_commit_style s);
227 int  igt_display_commit(igt_display_t *display);
228 int  igt_display_try_commit2(igt_display_t *display, enum igt_commit_style s);
229 int  igt_display_get_n_pipes(igt_display_t *display);
230
231 const char *igt_output_name(igt_output_t *output);
232 drmModeModeInfo *igt_output_get_mode(igt_output_t *output);
233 void igt_output_set_pipe(igt_output_t *output, enum pipe pipe);
234 igt_plane_t *igt_output_get_plane(igt_output_t *output, enum igt_plane plane);
235
236 static inline bool igt_plane_supports_rotation(igt_plane_t *plane)
237 {
238         return plane->rotation_property != 0;
239 }
240
241 void igt_plane_set_fb(igt_plane_t *plane, struct igt_fb *fb);
242 void igt_plane_set_position(igt_plane_t *plane, int x, int y);
243 void igt_plane_set_panning(igt_plane_t *plane, int x, int y);
244 void igt_plane_set_rotation(igt_plane_t *plane, igt_rotation_t rotation);
245
246 void igt_wait_for_vblank(int drm_fd, enum pipe pipe);
247
248 #define for_each_connected_output(display, output)              \
249         for (int i__ = 0;  i__ < (display)->n_outputs; i__++)   \
250                 if ((output = &(display)->outputs[i__]), output->valid)
251
252 #define for_each_pipe(display, pipe)                                    \
253         for (pipe = 0; pipe < igt_display_get_n_pipes(display); pipe++) \
254
255 /*
256  * Can be used with igt_output_set_pipe() to mean we don't care about the pipe
257  * that should drive this output
258  */
259 #define PIPE_ANY        (-1)
260
261 #define IGT_FIXED(i,f)  ((i) << 16 | (f))
262
263 void igt_enable_connectors(void);
264 void igt_reset_connectors(void);
265
266 #endif /* __IGT_KMS_H__ */
267