drm_modes.h revision 1.1.1.3 1 /* $NetBSD: drm_modes.h,v 1.1.1.3 2021/12/18 20:15:57 riastradh Exp $ */
2
3 /*
4 * Copyright 2006 Keith Packard
5 * Copyright 2007-2008 Dave Airlie
6 * Copyright 2007-2008 Intel Corporation
7 * Jesse Barnes <jesse.barnes (at) intel.com>
8 * Copyright 2014 Intel Corporation
9 * Daniel Vetter <daniel.vetter (at) ffwll.ch>
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 * OTHER DEALINGS IN THE SOFTWARE.
28 */
29 #ifndef __DRM_MODES_H__
30 #define __DRM_MODES_H__
31
32 #include <linux/hdmi.h>
33
34 #include <drm/drm_mode_object.h>
35 #include <drm/drm_connector.h>
36
37 struct videomode;
38
39 /*
40 * Note on terminology: here, for brevity and convenience, we refer to connector
41 * control chips as 'CRTCs'. They can control any type of connector, VGA, LVDS,
42 * DVI, etc. And 'screen' refers to the whole of the visible display, which
43 * may span multiple monitors (and therefore multiple CRTC and connector
44 * structures).
45 */
46
47 /**
48 * enum drm_mode_status - hardware support status of a mode
49 * @MODE_OK: Mode OK
50 * @MODE_HSYNC: hsync out of range
51 * @MODE_VSYNC: vsync out of range
52 * @MODE_H_ILLEGAL: mode has illegal horizontal timings
53 * @MODE_V_ILLEGAL: mode has illegal horizontal timings
54 * @MODE_BAD_WIDTH: requires an unsupported linepitch
55 * @MODE_NOMODE: no mode with a matching name
56 * @MODE_NO_INTERLACE: interlaced mode not supported
57 * @MODE_NO_DBLESCAN: doublescan mode not supported
58 * @MODE_NO_VSCAN: multiscan mode not supported
59 * @MODE_MEM: insufficient video memory
60 * @MODE_VIRTUAL_X: mode width too large for specified virtual size
61 * @MODE_VIRTUAL_Y: mode height too large for specified virtual size
62 * @MODE_MEM_VIRT: insufficient video memory given virtual size
63 * @MODE_NOCLOCK: no fixed clock available
64 * @MODE_CLOCK_HIGH: clock required is too high
65 * @MODE_CLOCK_LOW: clock required is too low
66 * @MODE_CLOCK_RANGE: clock/mode isn't in a ClockRange
67 * @MODE_BAD_HVALUE: horizontal timing was out of range
68 * @MODE_BAD_VVALUE: vertical timing was out of range
69 * @MODE_BAD_VSCAN: VScan value out of range
70 * @MODE_HSYNC_NARROW: horizontal sync too narrow
71 * @MODE_HSYNC_WIDE: horizontal sync too wide
72 * @MODE_HBLANK_NARROW: horizontal blanking too narrow
73 * @MODE_HBLANK_WIDE: horizontal blanking too wide
74 * @MODE_VSYNC_NARROW: vertical sync too narrow
75 * @MODE_VSYNC_WIDE: vertical sync too wide
76 * @MODE_VBLANK_NARROW: vertical blanking too narrow
77 * @MODE_VBLANK_WIDE: vertical blanking too wide
78 * @MODE_PANEL: exceeds panel dimensions
79 * @MODE_INTERLACE_WIDTH: width too large for interlaced mode
80 * @MODE_ONE_WIDTH: only one width is supported
81 * @MODE_ONE_HEIGHT: only one height is supported
82 * @MODE_ONE_SIZE: only one resolution is supported
83 * @MODE_NO_REDUCED: monitor doesn't accept reduced blanking
84 * @MODE_NO_STEREO: stereo modes not supported
85 * @MODE_NO_420: ycbcr 420 modes not supported
86 * @MODE_STALE: mode has become stale
87 * @MODE_BAD: unspecified reason
88 * @MODE_ERROR: error condition
89 *
90 * This enum is used to filter out modes not supported by the driver/hardware
91 * combination.
92 */
93 enum drm_mode_status {
94 MODE_OK = 0,
95 MODE_HSYNC,
96 MODE_VSYNC,
97 MODE_H_ILLEGAL,
98 MODE_V_ILLEGAL,
99 MODE_BAD_WIDTH,
100 MODE_NOMODE,
101 MODE_NO_INTERLACE,
102 MODE_NO_DBLESCAN,
103 MODE_NO_VSCAN,
104 MODE_MEM,
105 MODE_VIRTUAL_X,
106 MODE_VIRTUAL_Y,
107 MODE_MEM_VIRT,
108 MODE_NOCLOCK,
109 MODE_CLOCK_HIGH,
110 MODE_CLOCK_LOW,
111 MODE_CLOCK_RANGE,
112 MODE_BAD_HVALUE,
113 MODE_BAD_VVALUE,
114 MODE_BAD_VSCAN,
115 MODE_HSYNC_NARROW,
116 MODE_HSYNC_WIDE,
117 MODE_HBLANK_NARROW,
118 MODE_HBLANK_WIDE,
119 MODE_VSYNC_NARROW,
120 MODE_VSYNC_WIDE,
121 MODE_VBLANK_NARROW,
122 MODE_VBLANK_WIDE,
123 MODE_PANEL,
124 MODE_INTERLACE_WIDTH,
125 MODE_ONE_WIDTH,
126 MODE_ONE_HEIGHT,
127 MODE_ONE_SIZE,
128 MODE_NO_REDUCED,
129 MODE_NO_STEREO,
130 MODE_NO_420,
131 MODE_STALE = -3,
132 MODE_BAD = -2,
133 MODE_ERROR = -1
134 };
135
136 #define DRM_MODE(nm, t, c, hd, hss, hse, ht, hsk, vd, vss, vse, vt, vs, f) \
137 .name = nm, .status = 0, .type = (t), .clock = (c), \
138 .hdisplay = (hd), .hsync_start = (hss), .hsync_end = (hse), \
139 .htotal = (ht), .hskew = (hsk), .vdisplay = (vd), \
140 .vsync_start = (vss), .vsync_end = (vse), .vtotal = (vt), \
141 .vscan = (vs), .flags = (f)
142
143 /**
144 * DRM_SIMPLE_MODE - Simple display mode
145 * @hd: Horizontal resolution, width
146 * @vd: Vertical resolution, height
147 * @hd_mm: Display width in millimeters
148 * @vd_mm: Display height in millimeters
149 *
150 * This macro initializes a &drm_display_mode that only contains info about
151 * resolution and physical size.
152 */
153 #define DRM_SIMPLE_MODE(hd, vd, hd_mm, vd_mm) \
154 .type = DRM_MODE_TYPE_DRIVER, .clock = 1 /* pass validation */, \
155 .hdisplay = (hd), .hsync_start = (hd), .hsync_end = (hd), \
156 .htotal = (hd), .vdisplay = (vd), .vsync_start = (vd), \
157 .vsync_end = (vd), .vtotal = (vd), .width_mm = (hd_mm), \
158 .height_mm = (vd_mm)
159
160 #define CRTC_INTERLACE_HALVE_V (1 << 0) /* halve V values for interlacing */
161 #define CRTC_STEREO_DOUBLE (1 << 1) /* adjust timings for stereo modes */
162 #define CRTC_NO_DBLSCAN (1 << 2) /* don't adjust doublescan */
163 #define CRTC_NO_VSCAN (1 << 3) /* don't adjust doublescan */
164 #define CRTC_STEREO_DOUBLE_ONLY (CRTC_STEREO_DOUBLE | CRTC_NO_DBLSCAN | CRTC_NO_VSCAN)
165
166 #define DRM_MODE_FLAG_3D_MAX DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF
167
168 #define DRM_MODE_MATCH_TIMINGS (1 << 0)
169 #define DRM_MODE_MATCH_CLOCK (1 << 1)
170 #define DRM_MODE_MATCH_FLAGS (1 << 2)
171 #define DRM_MODE_MATCH_3D_FLAGS (1 << 3)
172 #define DRM_MODE_MATCH_ASPECT_RATIO (1 << 4)
173
174 /**
175 * struct drm_display_mode - DRM kernel-internal display mode structure
176 * @hdisplay: horizontal display size
177 * @hsync_start: horizontal sync start
178 * @hsync_end: horizontal sync end
179 * @htotal: horizontal total size
180 * @hskew: horizontal skew?!
181 * @vdisplay: vertical display size
182 * @vsync_start: vertical sync start
183 * @vsync_end: vertical sync end
184 * @vtotal: vertical total size
185 * @vscan: vertical scan?!
186 * @crtc_hdisplay: hardware mode horizontal display size
187 * @crtc_hblank_start: hardware mode horizontal blank start
188 * @crtc_hblank_end: hardware mode horizontal blank end
189 * @crtc_hsync_start: hardware mode horizontal sync start
190 * @crtc_hsync_end: hardware mode horizontal sync end
191 * @crtc_htotal: hardware mode horizontal total size
192 * @crtc_hskew: hardware mode horizontal skew?!
193 * @crtc_vdisplay: hardware mode vertical display size
194 * @crtc_vblank_start: hardware mode vertical blank start
195 * @crtc_vblank_end: hardware mode vertical blank end
196 * @crtc_vsync_start: hardware mode vertical sync start
197 * @crtc_vsync_end: hardware mode vertical sync end
198 * @crtc_vtotal: hardware mode vertical total size
199 *
200 * The horizontal and vertical timings are defined per the following diagram.
201 *
202 * ::
203 *
204 *
205 * Active Front Sync Back
206 * Region Porch Porch
207 * <-----------------------><----------------><-------------><-------------->
208 * //////////////////////|
209 * ////////////////////// |
210 * ////////////////////// |.................. ................
211 * _______________
212 * <----- [hv]display ----->
213 * <------------- [hv]sync_start ------------>
214 * <--------------------- [hv]sync_end --------------------->
215 * <-------------------------------- [hv]total ----------------------------->*
216 *
217 * This structure contains two copies of timings. First are the plain timings,
218 * which specify the logical mode, as it would be for a progressive 1:1 scanout
219 * at the refresh rate userspace can observe through vblank timestamps. Then
220 * there's the hardware timings, which are corrected for interlacing,
221 * double-clocking and similar things. They are provided as a convenience, and
222 * can be appropriately computed using drm_mode_set_crtcinfo().
223 *
224 * For printing you can use %DRM_MODE_FMT and DRM_MODE_ARG().
225 */
226 struct drm_display_mode {
227 /**
228 * @head:
229 *
230 * struct list_head for mode lists.
231 */
232 struct list_head head;
233
234 /**
235 * @name:
236 *
237 * Human-readable name of the mode, filled out with drm_mode_set_name().
238 */
239 char name[DRM_DISPLAY_MODE_LEN];
240
241 /**
242 * @status:
243 *
244 * Status of the mode, used to filter out modes not supported by the
245 * hardware. See enum &drm_mode_status.
246 */
247 enum drm_mode_status status;
248
249 /**
250 * @type:
251 *
252 * A bitmask of flags, mostly about the source of a mode. Possible flags
253 * are:
254 *
255 * - DRM_MODE_TYPE_PREFERRED: Preferred mode, usually the native
256 * resolution of an LCD panel. There should only be one preferred
257 * mode per connector at any given time.
258 * - DRM_MODE_TYPE_DRIVER: Mode created by the driver, which is all of
259 * them really. Drivers must set this bit for all modes they create
260 * and expose to userspace.
261 * - DRM_MODE_TYPE_USERDEF: Mode defined via kernel command line
262 *
263 * Plus a big list of flags which shouldn't be used at all, but are
264 * still around since these flags are also used in the userspace ABI.
265 * We no longer accept modes with these types though:
266 *
267 * - DRM_MODE_TYPE_BUILTIN: Meant for hard-coded modes, unused.
268 * Use DRM_MODE_TYPE_DRIVER instead.
269 * - DRM_MODE_TYPE_DEFAULT: Again a leftover, use
270 * DRM_MODE_TYPE_PREFERRED instead.
271 * - DRM_MODE_TYPE_CLOCK_C and DRM_MODE_TYPE_CRTC_C: Define leftovers
272 * which are stuck around for hysterical raisins only. No one has an
273 * idea what they were meant for. Don't use.
274 */
275 unsigned int type;
276
277 /**
278 * @clock:
279 *
280 * Pixel clock in kHz.
281 */
282 int clock; /* in kHz */
283 int hdisplay;
284 int hsync_start;
285 int hsync_end;
286 int htotal;
287 int hskew;
288 int vdisplay;
289 int vsync_start;
290 int vsync_end;
291 int vtotal;
292 int vscan;
293 /**
294 * @flags:
295 *
296 * Sync and timing flags:
297 *
298 * - DRM_MODE_FLAG_PHSYNC: horizontal sync is active high.
299 * - DRM_MODE_FLAG_NHSYNC: horizontal sync is active low.
300 * - DRM_MODE_FLAG_PVSYNC: vertical sync is active high.
301 * - DRM_MODE_FLAG_NVSYNC: vertical sync is active low.
302 * - DRM_MODE_FLAG_INTERLACE: mode is interlaced.
303 * - DRM_MODE_FLAG_DBLSCAN: mode uses doublescan.
304 * - DRM_MODE_FLAG_CSYNC: mode uses composite sync.
305 * - DRM_MODE_FLAG_PCSYNC: composite sync is active high.
306 * - DRM_MODE_FLAG_NCSYNC: composite sync is active low.
307 * - DRM_MODE_FLAG_HSKEW: hskew provided (not used?).
308 * - DRM_MODE_FLAG_BCAST: <deprecated>
309 * - DRM_MODE_FLAG_PIXMUX: <deprecated>
310 * - DRM_MODE_FLAG_DBLCLK: double-clocked mode.
311 * - DRM_MODE_FLAG_CLKDIV2: half-clocked mode.
312 *
313 * Additionally there's flags to specify how 3D modes are packed:
314 *
315 * - DRM_MODE_FLAG_3D_NONE: normal, non-3D mode.
316 * - DRM_MODE_FLAG_3D_FRAME_PACKING: 2 full frames for left and right.
317 * - DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE: interleaved like fields.
318 * - DRM_MODE_FLAG_3D_LINE_ALTERNATIVE: interleaved lines.
319 * - DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL: side-by-side full frames.
320 * - DRM_MODE_FLAG_3D_L_DEPTH: ?
321 * - DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH: ?
322 * - DRM_MODE_FLAG_3D_TOP_AND_BOTTOM: frame split into top and bottom
323 * parts.
324 * - DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF: frame split into left and
325 * right parts.
326 */
327 unsigned int flags;
328
329 /**
330 * @width_mm:
331 *
332 * Addressable size of the output in mm, projectors should set this to
333 * 0.
334 */
335 int width_mm;
336
337 /**
338 * @height_mm:
339 *
340 * Addressable size of the output in mm, projectors should set this to
341 * 0.
342 */
343 int height_mm;
344
345 /**
346 * @crtc_clock:
347 *
348 * Actual pixel or dot clock in the hardware. This differs from the
349 * logical @clock when e.g. using interlacing, double-clocking, stereo
350 * modes or other fancy stuff that changes the timings and signals
351 * actually sent over the wire.
352 *
353 * This is again in kHz.
354 *
355 * Note that with digital outputs like HDMI or DP there's usually a
356 * massive confusion between the dot clock and the signal clock at the
357 * bit encoding level. Especially when a 8b/10b encoding is used and the
358 * difference is exactly a factor of 10.
359 */
360 int crtc_clock;
361 int crtc_hdisplay;
362 int crtc_hblank_start;
363 int crtc_hblank_end;
364 int crtc_hsync_start;
365 int crtc_hsync_end;
366 int crtc_htotal;
367 int crtc_hskew;
368 int crtc_vdisplay;
369 int crtc_vblank_start;
370 int crtc_vblank_end;
371 int crtc_vsync_start;
372 int crtc_vsync_end;
373 int crtc_vtotal;
374
375 /**
376 * @private:
377 *
378 * Pointer for driver private data. This can only be used for mode
379 * objects passed to drivers in modeset operations. It shouldn't be used
380 * by atomic drivers since they can store any additional data by
381 * subclassing state structures.
382 */
383 int *private;
384
385 /**
386 * @private_flags:
387 *
388 * Similar to @private, but just an integer.
389 */
390 int private_flags;
391
392 /**
393 * @vrefresh:
394 *
395 * Vertical refresh rate, for debug output in human readable form. Not
396 * used in a functional way.
397 *
398 * This value is in Hz.
399 */
400 int vrefresh;
401
402 /**
403 * @hsync:
404 *
405 * Horizontal refresh rate, for debug output in human readable form. Not
406 * used in a functional way.
407 *
408 * This value is in kHz.
409 */
410 int hsync;
411
412 /**
413 * @picture_aspect_ratio:
414 *
415 * Field for setting the HDMI picture aspect ratio of a mode.
416 */
417 enum hdmi_picture_aspect picture_aspect_ratio;
418
419 /**
420 * @export_head:
421 *
422 * struct list_head for modes to be exposed to the userspace.
423 * This is to maintain a list of exposed modes while preparing
424 * user-mode's list in drm_mode_getconnector ioctl. The purpose of this
425 * list_head only lies in the ioctl function, and is not expected to be
426 * used outside the function.
427 * Once used, the stale pointers are not reset, but left as it is, to
428 * avoid overhead of protecting it by mode_config.mutex.
429 */
430 struct list_head export_head;
431 };
432
433 /**
434 * DRM_MODE_FMT - printf string for &struct drm_display_mode
435 */
436 #define DRM_MODE_FMT "\"%s\": %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x"
437
438 /**
439 * DRM_MODE_ARG - printf arguments for &struct drm_display_mode
440 * @m: display mode
441 */
442 #define DRM_MODE_ARG(m) \
443 (m)->name, (m)->vrefresh, (m)->clock, \
444 (m)->hdisplay, (m)->hsync_start, (m)->hsync_end, (m)->htotal, \
445 (m)->vdisplay, (m)->vsync_start, (m)->vsync_end, (m)->vtotal, \
446 (m)->type, (m)->flags
447
448 #define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
449
450 /**
451 * drm_mode_is_stereo - check for stereo mode flags
452 * @mode: drm_display_mode to check
453 *
454 * Returns:
455 * True if the mode is one of the stereo modes (like side-by-side), false if
456 * not.
457 */
458 static inline bool drm_mode_is_stereo(const struct drm_display_mode *mode)
459 {
460 return mode->flags & DRM_MODE_FLAG_3D_MASK;
461 }
462
463 struct drm_connector;
464 struct drm_cmdline_mode;
465
466 struct drm_display_mode *drm_mode_create(struct drm_device *dev);
467 void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode);
468 void drm_mode_convert_to_umode(struct drm_mode_modeinfo *out,
469 const struct drm_display_mode *in);
470 int drm_mode_convert_umode(struct drm_device *dev,
471 struct drm_display_mode *out,
472 const struct drm_mode_modeinfo *in);
473 void drm_mode_probed_add(struct drm_connector *connector, struct drm_display_mode *mode);
474 void drm_mode_debug_printmodeline(const struct drm_display_mode *mode);
475 bool drm_mode_is_420_only(const struct drm_display_info *display,
476 const struct drm_display_mode *mode);
477 bool drm_mode_is_420_also(const struct drm_display_info *display,
478 const struct drm_display_mode *mode);
479 bool drm_mode_is_420(const struct drm_display_info *display,
480 const struct drm_display_mode *mode);
481
482 struct drm_display_mode *drm_cvt_mode(struct drm_device *dev,
483 int hdisplay, int vdisplay, int vrefresh,
484 bool reduced, bool interlaced,
485 bool margins);
486 struct drm_display_mode *drm_gtf_mode(struct drm_device *dev,
487 int hdisplay, int vdisplay, int vrefresh,
488 bool interlaced, int margins);
489 struct drm_display_mode *drm_gtf_mode_complex(struct drm_device *dev,
490 int hdisplay, int vdisplay,
491 int vrefresh, bool interlaced,
492 int margins,
493 int GTF_M, int GTF_2C,
494 int GTF_K, int GTF_2J);
495 void drm_display_mode_from_videomode(const struct videomode *vm,
496 struct drm_display_mode *dmode);
497 void drm_display_mode_to_videomode(const struct drm_display_mode *dmode,
498 struct videomode *vm);
499 void drm_bus_flags_from_videomode(const struct videomode *vm, u32 *bus_flags);
500 int of_get_drm_display_mode(struct device_node *np,
501 struct drm_display_mode *dmode, u32 *bus_flags,
502 int index);
503
504 void drm_mode_set_name(struct drm_display_mode *mode);
505 int drm_mode_hsync(const struct drm_display_mode *mode);
506 int drm_mode_vrefresh(const struct drm_display_mode *mode);
507 void drm_mode_get_hv_timing(const struct drm_display_mode *mode,
508 int *hdisplay, int *vdisplay);
509
510 void drm_mode_set_crtcinfo(struct drm_display_mode *p,
511 int adjust_flags);
512 void drm_mode_copy(struct drm_display_mode *dst,
513 const struct drm_display_mode *src);
514 struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
515 const struct drm_display_mode *mode);
516 bool drm_mode_match(const struct drm_display_mode *mode1,
517 const struct drm_display_mode *mode2,
518 unsigned int match_flags);
519 bool drm_mode_equal(const struct drm_display_mode *mode1,
520 const struct drm_display_mode *mode2);
521 bool drm_mode_equal_no_clocks(const struct drm_display_mode *mode1,
522 const struct drm_display_mode *mode2);
523 bool drm_mode_equal_no_clocks_no_stereo(const struct drm_display_mode *mode1,
524 const struct drm_display_mode *mode2);
525
526 /* for use by the crtc helper probe functions */
527 enum drm_mode_status drm_mode_validate_driver(struct drm_device *dev,
528 const struct drm_display_mode *mode);
529 enum drm_mode_status drm_mode_validate_size(const struct drm_display_mode *mode,
530 int maxX, int maxY);
531 enum drm_mode_status
532 drm_mode_validate_ycbcr420(const struct drm_display_mode *mode,
533 struct drm_connector *connector);
534 void drm_mode_prune_invalid(struct drm_device *dev,
535 struct list_head *mode_list, bool verbose);
536 void drm_mode_sort(struct list_head *mode_list);
537 void drm_connector_list_update(struct drm_connector *connector);
538
539 /* parsing cmdline modes */
540 bool
541 drm_mode_parse_command_line_for_connector(const char *mode_option,
542 const struct drm_connector *connector,
543 struct drm_cmdline_mode *mode);
544 struct drm_display_mode *
545 drm_mode_create_from_cmdline_mode(struct drm_device *dev,
546 struct drm_cmdline_mode *cmd);
547
548 #endif /* __DRM_MODES_H__ */
549