Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[deliverable/linux.git] / include / drm / drm_crtc.h
1 /*
2 * Copyright © 2006 Keith Packard
3 * Copyright © 2007-2008 Dave Airlie
4 * Copyright © 2007-2008 Intel Corporation
5 * Jesse Barnes <jesse.barnes@intel.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25 #ifndef __DRM_CRTC_H__
26 #define __DRM_CRTC_H__
27
28 #include <linux/i2c.h>
29 #include <linux/spinlock.h>
30 #include <linux/types.h>
31 #include <linux/idr.h>
32 #include <linux/fb.h>
33 #include <linux/hdmi.h>
34 #include <linux/media-bus-format.h>
35 #include <uapi/drm/drm_mode.h>
36 #include <uapi/drm/drm_fourcc.h>
37 #include <drm/drm_modeset_lock.h>
38
39 struct drm_device;
40 struct drm_mode_set;
41 struct drm_framebuffer;
42 struct drm_object_properties;
43 struct drm_file;
44 struct drm_clip_rect;
45 struct device_node;
46 struct fence;
47 struct edid;
48
49 struct drm_mode_object {
50 uint32_t id;
51 uint32_t type;
52 struct drm_object_properties *properties;
53 struct kref refcount;
54 void (*free_cb)(struct kref *kref);
55 };
56
57 #define DRM_OBJECT_MAX_PROPERTY 24
58 struct drm_object_properties {
59 int count, atomic_count;
60 /* NOTE: if we ever start dynamically destroying properties (ie.
61 * not at drm_mode_config_cleanup() time), then we'd have to do
62 * a better job of detaching property from mode objects to avoid
63 * dangling property pointers:
64 */
65 struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY];
66 /* do not read/write values directly, but use drm_object_property_get_value()
67 * and drm_object_property_set_value():
68 */
69 uint64_t values[DRM_OBJECT_MAX_PROPERTY];
70 };
71
72 static inline int64_t U642I64(uint64_t val)
73 {
74 return (int64_t)*((int64_t *)&val);
75 }
76 static inline uint64_t I642U64(int64_t val)
77 {
78 return (uint64_t)*((uint64_t *)&val);
79 }
80
81 /*
82 * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the
83 * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and
84 * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation
85 */
86 #define DRM_ROTATE_MASK 0x0f
87 #define DRM_ROTATE_0 0
88 #define DRM_ROTATE_90 1
89 #define DRM_ROTATE_180 2
90 #define DRM_ROTATE_270 3
91 #define DRM_REFLECT_MASK (~DRM_ROTATE_MASK)
92 #define DRM_REFLECT_X 4
93 #define DRM_REFLECT_Y 5
94
95 enum drm_connector_force {
96 DRM_FORCE_UNSPECIFIED,
97 DRM_FORCE_OFF,
98 DRM_FORCE_ON, /* force on analog part normally */
99 DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
100 };
101
102 #include <drm/drm_modes.h>
103
104 enum drm_connector_status {
105 connector_status_connected = 1,
106 connector_status_disconnected = 2,
107 connector_status_unknown = 3,
108 };
109
110 enum subpixel_order {
111 SubPixelUnknown = 0,
112 SubPixelHorizontalRGB,
113 SubPixelHorizontalBGR,
114 SubPixelVerticalRGB,
115 SubPixelVerticalBGR,
116 SubPixelNone,
117 };
118
119 #define DRM_COLOR_FORMAT_RGB444 (1<<0)
120 #define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
121 #define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
122
123 #define DRM_BUS_FLAG_DE_LOW (1<<0)
124 #define DRM_BUS_FLAG_DE_HIGH (1<<1)
125 /* drive data on pos. edge */
126 #define DRM_BUS_FLAG_PIXDATA_POSEDGE (1<<2)
127 /* drive data on neg. edge */
128 #define DRM_BUS_FLAG_PIXDATA_NEGEDGE (1<<3)
129
130 /*
131 * Describes a given display (e.g. CRT or flat panel) and its limitations.
132 */
133 struct drm_display_info {
134 char name[DRM_DISPLAY_INFO_LEN];
135
136 /* Physical size */
137 unsigned int width_mm;
138 unsigned int height_mm;
139
140 /* Clock limits FIXME: storage format */
141 unsigned int min_vfreq, max_vfreq;
142 unsigned int min_hfreq, max_hfreq;
143 unsigned int pixel_clock;
144 unsigned int bpc;
145
146 enum subpixel_order subpixel_order;
147 u32 color_formats;
148
149 const u32 *bus_formats;
150 unsigned int num_bus_formats;
151 u32 bus_flags;
152
153 /* Mask of supported hdmi deep color modes */
154 u8 edid_hdmi_dc_modes;
155
156 u8 cea_rev;
157 };
158
159 /* data corresponds to displayid vend/prod/serial */
160 struct drm_tile_group {
161 struct kref refcount;
162 struct drm_device *dev;
163 int id;
164 u8 group_data[8];
165 };
166
167 /**
168 * struct drm_framebuffer_funcs - framebuffer hooks
169 */
170 struct drm_framebuffer_funcs {
171 /**
172 * @destroy:
173 *
174 * Clean up framebuffer resources, specifically also unreference the
175 * backing storage. The core guarantees to call this function for every
176 * framebuffer successfully created by ->fb_create() in
177 * &drm_mode_config_funcs. Drivers must also call
178 * drm_framebuffer_cleanup() to release DRM core resources for this
179 * framebuffer.
180 */
181 void (*destroy)(struct drm_framebuffer *framebuffer);
182
183 /**
184 * @create_handle:
185 *
186 * Create a buffer handle in the driver-specific buffer manager (either
187 * GEM or TTM) valid for the passed-in struct &drm_file. This is used by
188 * the core to implement the GETFB IOCTL, which returns (for
189 * sufficiently priviledged user) also a native buffer handle. This can
190 * be used for seamless transitions between modesetting clients by
191 * copying the current screen contents to a private buffer and blending
192 * between that and the new contents.
193 *
194 * GEM based drivers should call drm_gem_handle_create() to create the
195 * handle.
196 *
197 * RETURNS:
198 *
199 * 0 on success or a negative error code on failure.
200 */
201 int (*create_handle)(struct drm_framebuffer *fb,
202 struct drm_file *file_priv,
203 unsigned int *handle);
204 /**
205 * @dirty:
206 *
207 * Optional callback for the dirty fb IOCTL.
208 *
209 * Userspace can notify the driver via this callback that an area of the
210 * framebuffer has changed and should be flushed to the display
211 * hardware. This can also be used internally, e.g. by the fbdev
212 * emulation, though that's not the case currently.
213 *
214 * See documentation in drm_mode.h for the struct drm_mode_fb_dirty_cmd
215 * for more information as all the semantics and arguments have a one to
216 * one mapping on this function.
217 *
218 * RETURNS:
219 *
220 * 0 on success or a negative error code on failure.
221 */
222 int (*dirty)(struct drm_framebuffer *framebuffer,
223 struct drm_file *file_priv, unsigned flags,
224 unsigned color, struct drm_clip_rect *clips,
225 unsigned num_clips);
226 };
227
228 struct drm_framebuffer {
229 struct drm_device *dev;
230 /*
231 * Note that the fb is refcounted for the benefit of driver internals,
232 * for example some hw, disabling a CRTC/plane is asynchronous, and
233 * scanout does not actually complete until the next vblank. So some
234 * cleanup (like releasing the reference(s) on the backing GEM bo(s))
235 * should be deferred. In cases like this, the driver would like to
236 * hold a ref to the fb even though it has already been removed from
237 * userspace perspective.
238 * The refcount is stored inside the mode object.
239 */
240 /*
241 * Place on the dev->mode_config.fb_list, access protected by
242 * dev->mode_config.fb_lock.
243 */
244 struct list_head head;
245 struct drm_mode_object base;
246 const struct drm_framebuffer_funcs *funcs;
247 unsigned int pitches[4];
248 unsigned int offsets[4];
249 uint64_t modifier[4];
250 unsigned int width;
251 unsigned int height;
252 /* depth can be 15 or 16 */
253 unsigned int depth;
254 int bits_per_pixel;
255 int flags;
256 uint32_t pixel_format; /* fourcc format */
257 int hot_x;
258 int hot_y;
259 struct list_head filp_head;
260 };
261
262 struct drm_property_blob {
263 struct drm_mode_object base;
264 struct drm_device *dev;
265 struct list_head head_global;
266 struct list_head head_file;
267 size_t length;
268 unsigned char data[];
269 };
270
271 struct drm_property_enum {
272 uint64_t value;
273 struct list_head head;
274 char name[DRM_PROP_NAME_LEN];
275 };
276
277 struct drm_property {
278 struct list_head head;
279 struct drm_mode_object base;
280 uint32_t flags;
281 char name[DRM_PROP_NAME_LEN];
282 uint32_t num_values;
283 uint64_t *values;
284 struct drm_device *dev;
285
286 struct list_head enum_list;
287 };
288
289 struct drm_crtc;
290 struct drm_connector;
291 struct drm_encoder;
292 struct drm_pending_vblank_event;
293 struct drm_plane;
294 struct drm_bridge;
295 struct drm_atomic_state;
296
297 struct drm_crtc_helper_funcs;
298 struct drm_encoder_helper_funcs;
299 struct drm_connector_helper_funcs;
300 struct drm_plane_helper_funcs;
301
302 /**
303 * struct drm_crtc_state - mutable CRTC state
304 * @crtc: backpointer to the CRTC
305 * @enable: whether the CRTC should be enabled, gates all other state
306 * @active: whether the CRTC is actively displaying (used for DPMS)
307 * @planes_changed: planes on this crtc are updated
308 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
309 * @active_changed: crtc_state->active has been toggled.
310 * @connectors_changed: connectors to this crtc have been updated
311 * @color_mgmt_changed: color management properties have changed (degamma or
312 * gamma LUT or CSC matrix)
313 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
314 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
315 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
316 * @last_vblank_count: for helpers and drivers to capture the vblank of the
317 * update to ensure framebuffer cleanup isn't done too early
318 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
319 * @mode: current mode timings
320 * @mode_blob: &drm_property_blob for @mode
321 * @degamma_lut: Lookup table for converting framebuffer pixel data
322 * before apply the conversion matrix
323 * @ctm: Transformation matrix
324 * @gamma_lut: Lookup table for converting pixel data after the
325 * conversion matrix
326 * @event: optional pointer to a DRM event to signal upon completion of the
327 * state update
328 * @state: backpointer to global drm_atomic_state
329 *
330 * Note that the distinction between @enable and @active is rather subtile:
331 * Flipping @active while @enable is set without changing anything else may
332 * never return in a failure from the ->atomic_check callback. Userspace assumes
333 * that a DPMS On will always succeed. In other words: @enable controls resource
334 * assignment, @active controls the actual hardware state.
335 */
336 struct drm_crtc_state {
337 struct drm_crtc *crtc;
338
339 bool enable;
340 bool active;
341
342 /* computed state bits used by helpers and drivers */
343 bool planes_changed : 1;
344 bool mode_changed : 1;
345 bool active_changed : 1;
346 bool connectors_changed : 1;
347 bool color_mgmt_changed : 1;
348
349 /* attached planes bitmask:
350 * WARNING: transitional helpers do not maintain plane_mask so
351 * drivers not converted over to atomic helpers should not rely
352 * on plane_mask being accurate!
353 */
354 u32 plane_mask;
355
356 u32 connector_mask;
357 u32 encoder_mask;
358
359 /* last_vblank_count: for vblank waits before cleanup */
360 u32 last_vblank_count;
361
362 /* adjusted_mode: for use by helpers and drivers */
363 struct drm_display_mode adjusted_mode;
364
365 struct drm_display_mode mode;
366
367 /* blob property to expose current mode to atomic userspace */
368 struct drm_property_blob *mode_blob;
369
370 /* blob property to expose color management to userspace */
371 struct drm_property_blob *degamma_lut;
372 struct drm_property_blob *ctm;
373 struct drm_property_blob *gamma_lut;
374
375 struct drm_pending_vblank_event *event;
376
377 struct drm_atomic_state *state;
378 };
379
380 /**
381 * struct drm_crtc_funcs - control CRTCs for a given device
382 *
383 * The drm_crtc_funcs structure is the central CRTC management structure
384 * in the DRM. Each CRTC controls one or more connectors (note that the name
385 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
386 * connectors, not just CRTs).
387 *
388 * Each driver is responsible for filling out this structure at startup time,
389 * in addition to providing other modesetting features, like i2c and DDC
390 * bus accessors.
391 */
392 struct drm_crtc_funcs {
393 /**
394 * @reset:
395 *
396 * Reset CRTC hardware and software state to off. This function isn't
397 * called by the core directly, only through drm_mode_config_reset().
398 * It's not a helper hook only for historical reasons.
399 *
400 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
401 * atomic state using this hook.
402 */
403 void (*reset)(struct drm_crtc *crtc);
404
405 /**
406 * @cursor_set:
407 *
408 * Update the cursor image. The cursor position is relative to the CRTC
409 * and can be partially or fully outside of the visible area.
410 *
411 * Note that contrary to all other KMS functions the legacy cursor entry
412 * points don't take a framebuffer object, but instead take directly a
413 * raw buffer object id from the driver's buffer manager (which is
414 * either GEM or TTM for current drivers).
415 *
416 * This entry point is deprecated, drivers should instead implement
417 * universal plane support and register a proper cursor plane using
418 * drm_crtc_init_with_planes().
419 *
420 * This callback is optional
421 *
422 * RETURNS:
423 *
424 * 0 on success or a negative error code on failure.
425 */
426 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
427 uint32_t handle, uint32_t width, uint32_t height);
428
429 /**
430 * @cursor_set2:
431 *
432 * Update the cursor image, including hotspot information. The hotspot
433 * must not affect the cursor position in CRTC coordinates, but is only
434 * meant as a hint for virtualized display hardware to coordinate the
435 * guests and hosts cursor position. The cursor hotspot is relative to
436 * the cursor image. Otherwise this works exactly like @cursor_set.
437 *
438 * This entry point is deprecated, drivers should instead implement
439 * universal plane support and register a proper cursor plane using
440 * drm_crtc_init_with_planes().
441 *
442 * This callback is optional.
443 *
444 * RETURNS:
445 *
446 * 0 on success or a negative error code on failure.
447 */
448 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
449 uint32_t handle, uint32_t width, uint32_t height,
450 int32_t hot_x, int32_t hot_y);
451
452 /**
453 * @cursor_move:
454 *
455 * Update the cursor position. The cursor does not need to be visible
456 * when this hook is called.
457 *
458 * This entry point is deprecated, drivers should instead implement
459 * universal plane support and register a proper cursor plane using
460 * drm_crtc_init_with_planes().
461 *
462 * This callback is optional.
463 *
464 * RETURNS:
465 *
466 * 0 on success or a negative error code on failure.
467 */
468 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
469
470 /**
471 * @gamma_set:
472 *
473 * Set gamma on the CRTC.
474 *
475 * This callback is optional.
476 *
477 * NOTE:
478 *
479 * Drivers that support gamma tables and also fbdev emulation through
480 * the provided helper library need to take care to fill out the gamma
481 * hooks for both. Currently there's a bit an unfortunate duplication
482 * going on, which should eventually be unified to just one set of
483 * hooks.
484 */
485 int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
486 uint32_t size);
487
488 /**
489 * @destroy:
490 *
491 * Clean up plane resources. This is only called at driver unload time
492 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
493 * in DRM.
494 */
495 void (*destroy)(struct drm_crtc *crtc);
496
497 /**
498 * @set_config:
499 *
500 * This is the main legacy entry point to change the modeset state on a
501 * CRTC. All the details of the desired configuration are passed in a
502 * struct &drm_mode_set - see there for details.
503 *
504 * Drivers implementing atomic modeset should use
505 * drm_atomic_helper_set_config() to implement this hook.
506 *
507 * RETURNS:
508 *
509 * 0 on success or a negative error code on failure.
510 */
511 int (*set_config)(struct drm_mode_set *set);
512
513 /**
514 * @page_flip:
515 *
516 * Legacy entry point to schedule a flip to the given framebuffer.
517 *
518 * Page flipping is a synchronization mechanism that replaces the frame
519 * buffer being scanned out by the CRTC with a new frame buffer during
520 * vertical blanking, avoiding tearing (except when requested otherwise
521 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
522 * requests a page flip the DRM core verifies that the new frame buffer
523 * is large enough to be scanned out by the CRTC in the currently
524 * configured mode and then calls the CRTC ->page_flip() operation with a
525 * pointer to the new frame buffer.
526 *
527 * The driver must wait for any pending rendering to the new framebuffer
528 * to complete before executing the flip. It should also wait for any
529 * pending rendering from other drivers if the underlying buffer is a
530 * shared dma-buf.
531 *
532 * An application can request to be notified when the page flip has
533 * completed. The drm core will supply a struct &drm_event in the event
534 * parameter in this case. This can be handled by the
535 * drm_crtc_send_vblank_event() function, which the driver should call on
536 * the provided event upon completion of the flip. Note that if
537 * the driver supports vblank signalling and timestamping the vblank
538 * counters and timestamps must agree with the ones returned from page
539 * flip events. With the current vblank helper infrastructure this can
540 * be achieved by holding a vblank reference while the page flip is
541 * pending, acquired through drm_crtc_vblank_get() and released with
542 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
543 * counter and timestamp tracking though, e.g. if they have accurate
544 * timestamp registers in hardware.
545 *
546 * FIXME:
547 *
548 * Up to that point drivers need to manage events themselves and can use
549 * even->base.list freely for that. Specifically they need to ensure
550 * that they don't send out page flip (or vblank) events for which the
551 * corresponding drm file has been closed already. The drm core
552 * unfortunately does not (yet) take care of that. Therefore drivers
553 * currently must clean up and release pending events in their
554 * ->preclose driver function.
555 *
556 * This callback is optional.
557 *
558 * NOTE:
559 *
560 * Very early versions of the KMS ABI mandated that the driver must
561 * block (but not reject) any rendering to the old framebuffer until the
562 * flip operation has completed and the old framebuffer is no longer
563 * visible. This requirement has been lifted, and userspace is instead
564 * expected to request delivery of an event and wait with recycling old
565 * buffers until such has been received.
566 *
567 * RETURNS:
568 *
569 * 0 on success or a negative error code on failure. Note that if a
570 * ->page_flip() operation is already pending the callback should return
571 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
572 * or just runtime disabled through DPMS respectively the new atomic
573 * "ACTIVE" state) should result in an -EINVAL error code. Note that
574 * drm_atomic_helper_page_flip() checks this already for atomic drivers.
575 */
576 int (*page_flip)(struct drm_crtc *crtc,
577 struct drm_framebuffer *fb,
578 struct drm_pending_vblank_event *event,
579 uint32_t flags);
580
581 /**
582 * @set_property:
583 *
584 * This is the legacy entry point to update a property attached to the
585 * CRTC.
586 *
587 * Drivers implementing atomic modeset should use
588 * drm_atomic_helper_crtc_set_property() to implement this hook.
589 *
590 * This callback is optional if the driver does not support any legacy
591 * driver-private properties.
592 *
593 * RETURNS:
594 *
595 * 0 on success or a negative error code on failure.
596 */
597 int (*set_property)(struct drm_crtc *crtc,
598 struct drm_property *property, uint64_t val);
599
600 /**
601 * @atomic_duplicate_state:
602 *
603 * Duplicate the current atomic state for this CRTC and return it.
604 * The core and helpers gurantee that any atomic state duplicated with
605 * this hook and still owned by the caller (i.e. not transferred to the
606 * driver by calling ->atomic_commit() from struct
607 * &drm_mode_config_funcs) will be cleaned up by calling the
608 * @atomic_destroy_state hook in this structure.
609 *
610 * Atomic drivers which don't subclass struct &drm_crtc should use
611 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
612 * state structure to extend it with driver-private state should use
613 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
614 * duplicated in a consistent fashion across drivers.
615 *
616 * It is an error to call this hook before crtc->state has been
617 * initialized correctly.
618 *
619 * NOTE:
620 *
621 * If the duplicate state references refcounted resources this hook must
622 * acquire a reference for each of them. The driver must release these
623 * references again in @atomic_destroy_state.
624 *
625 * RETURNS:
626 *
627 * Duplicated atomic state or NULL when the allocation failed.
628 */
629 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
630
631 /**
632 * @atomic_destroy_state:
633 *
634 * Destroy a state duplicated with @atomic_duplicate_state and release
635 * or unreference all resources it references
636 */
637 void (*atomic_destroy_state)(struct drm_crtc *crtc,
638 struct drm_crtc_state *state);
639
640 /**
641 * @atomic_set_property:
642 *
643 * Decode a driver-private property value and store the decoded value
644 * into the passed-in state structure. Since the atomic core decodes all
645 * standardized properties (even for extensions beyond the core set of
646 * properties which might not be implemented by all drivers) this
647 * requires drivers to subclass the state structure.
648 *
649 * Such driver-private properties should really only be implemented for
650 * truly hardware/vendor specific state. Instead it is preferred to
651 * standardize atomic extension and decode the properties used to expose
652 * such an extension in the core.
653 *
654 * Do not call this function directly, use
655 * drm_atomic_crtc_set_property() instead.
656 *
657 * This callback is optional if the driver does not support any
658 * driver-private atomic properties.
659 *
660 * NOTE:
661 *
662 * This function is called in the state assembly phase of atomic
663 * modesets, which can be aborted for any reason (including on
664 * userspace's request to just check whether a configuration would be
665 * possible). Drivers MUST NOT touch any persistent state (hardware or
666 * software) or data structures except the passed in @state parameter.
667 *
668 * Also since userspace controls in which order properties are set this
669 * function must not do any input validation (since the state update is
670 * incomplete and hence likely inconsistent). Instead any such input
671 * validation must be done in the various atomic_check callbacks.
672 *
673 * RETURNS:
674 *
675 * 0 if the property has been found, -EINVAL if the property isn't
676 * implemented by the driver (which should never happen, the core only
677 * asks for properties attached to this CRTC). No other validation is
678 * allowed by the driver. The core already checks that the property
679 * value is within the range (integer, valid enum value, ...) the driver
680 * set when registering the property.
681 */
682 int (*atomic_set_property)(struct drm_crtc *crtc,
683 struct drm_crtc_state *state,
684 struct drm_property *property,
685 uint64_t val);
686 /**
687 * @atomic_get_property:
688 *
689 * Reads out the decoded driver-private property. This is used to
690 * implement the GETCRTC IOCTL.
691 *
692 * Do not call this function directly, use
693 * drm_atomic_crtc_get_property() instead.
694 *
695 * This callback is optional if the driver does not support any
696 * driver-private atomic properties.
697 *
698 * RETURNS:
699 *
700 * 0 on success, -EINVAL if the property isn't implemented by the
701 * driver (which should never happen, the core only asks for
702 * properties attached to this CRTC).
703 */
704 int (*atomic_get_property)(struct drm_crtc *crtc,
705 const struct drm_crtc_state *state,
706 struct drm_property *property,
707 uint64_t *val);
708
709 /**
710 * @late_register:
711 *
712 * This optional hook can be used to register additional userspace
713 * interfaces attached to the crtc like debugfs interfaces.
714 * It is called late in the driver load sequence from drm_dev_register().
715 * Everything added from this callback should be unregistered in
716 * the early_unregister callback.
717 *
718 * Returns:
719 *
720 * 0 on success, or a negative error code on failure.
721 */
722 int (*late_register)(struct drm_crtc *crtc);
723
724 /**
725 * @early_unregister:
726 *
727 * This optional hook should be used to unregister the additional
728 * userspace interfaces attached to the crtc from
729 * late_unregister(). It is called from drm_dev_unregister(),
730 * early in the driver unload sequence to disable userspace access
731 * before data structures are torndown.
732 */
733 void (*early_unregister)(struct drm_crtc *crtc);
734 };
735
736 /**
737 * struct drm_crtc - central CRTC control structure
738 * @dev: parent DRM device
739 * @port: OF node used by drm_of_find_possible_crtcs()
740 * @head: list management
741 * @name: human readable name, can be overwritten by the driver
742 * @mutex: per-CRTC locking
743 * @base: base KMS object for ID tracking etc.
744 * @primary: primary plane for this CRTC
745 * @cursor: cursor plane for this CRTC
746 * @cursor_x: current x position of the cursor, used for universal cursor planes
747 * @cursor_y: current y position of the cursor, used for universal cursor planes
748 * @enabled: is this CRTC enabled?
749 * @mode: current mode timings
750 * @hwmode: mode timings as programmed to hw regs
751 * @x: x position on screen
752 * @y: y position on screen
753 * @funcs: CRTC control functions
754 * @gamma_size: size of gamma ramp
755 * @gamma_store: gamma ramp values
756 * @helper_private: mid-layer private data
757 * @properties: property tracking for this CRTC
758 *
759 * Each CRTC may have one or more connectors associated with it. This structure
760 * allows the CRTC to be controlled.
761 */
762 struct drm_crtc {
763 struct drm_device *dev;
764 struct device_node *port;
765 struct list_head head;
766
767 char *name;
768
769 /**
770 * @mutex:
771 *
772 * This provides a read lock for the overall crtc state (mode, dpms
773 * state, ...) and a write lock for everything which can be update
774 * without a full modeset (fb, cursor data, crtc properties ...). Full
775 * modeset also need to grab dev->mode_config.connection_mutex.
776 */
777 struct drm_modeset_lock mutex;
778
779 struct drm_mode_object base;
780
781 /* primary and cursor planes for CRTC */
782 struct drm_plane *primary;
783 struct drm_plane *cursor;
784
785 /**
786 * @index: Position inside the mode_config.list, can be used as an array
787 * index. It is invariant over the lifetime of the CRTC.
788 */
789 unsigned index;
790
791 /* position of cursor plane on crtc */
792 int cursor_x;
793 int cursor_y;
794
795 bool enabled;
796
797 /* Requested mode from modesetting. */
798 struct drm_display_mode mode;
799
800 /* Programmed mode in hw, after adjustments for encoders,
801 * crtc, panel scaling etc. Needed for timestamping etc.
802 */
803 struct drm_display_mode hwmode;
804
805 int x, y;
806 const struct drm_crtc_funcs *funcs;
807
808 /* Legacy FB CRTC gamma size for reporting to userspace */
809 uint32_t gamma_size;
810 uint16_t *gamma_store;
811
812 /* if you are using the helper */
813 const struct drm_crtc_helper_funcs *helper_private;
814
815 struct drm_object_properties properties;
816
817 /**
818 * @state:
819 *
820 * Current atomic state for this CRTC.
821 */
822 struct drm_crtc_state *state;
823
824 /**
825 * @commit_list:
826 *
827 * List of &drm_crtc_commit structures tracking pending commits.
828 * Protected by @commit_lock. This list doesn't hold its own full
829 * reference, but burrows it from the ongoing commit. Commit entries
830 * must be removed from this list once the commit is fully completed,
831 * but before it's correspoding &drm_atomic_state gets destroyed.
832 */
833 struct list_head commit_list;
834
835 /**
836 * @commit_lock:
837 *
838 * Spinlock to protect @commit_list.
839 */
840 spinlock_t commit_lock;
841
842 /**
843 * @acquire_ctx:
844 *
845 * Per-CRTC implicit acquire context used by atomic drivers for legacy
846 * IOCTLs, so that atomic drivers can get at the locking acquire
847 * context.
848 */
849 struct drm_modeset_acquire_ctx *acquire_ctx;
850 };
851
852 /**
853 * struct drm_connector_state - mutable connector state
854 * @connector: backpointer to the connector
855 * @crtc: CRTC to connect connector to, NULL if disabled
856 * @best_encoder: can be used by helpers and drivers to select the encoder
857 * @state: backpointer to global drm_atomic_state
858 */
859 struct drm_connector_state {
860 struct drm_connector *connector;
861
862 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_connector() */
863
864 struct drm_encoder *best_encoder;
865
866 struct drm_atomic_state *state;
867 };
868
869 /**
870 * struct drm_connector_funcs - control connectors on a given device
871 *
872 * Each CRTC may have one or more connectors attached to it. The functions
873 * below allow the core DRM code to control connectors, enumerate available modes,
874 * etc.
875 */
876 struct drm_connector_funcs {
877 /**
878 * @dpms:
879 *
880 * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
881 * is exposed as a standard property on the connector, but diverted to
882 * this callback in the drm core. Note that atomic drivers don't
883 * implement the 4 level DPMS support on the connector any more, but
884 * instead only have an on/off "ACTIVE" property on the CRTC object.
885 *
886 * Drivers implementing atomic modeset should use
887 * drm_atomic_helper_connector_dpms() to implement this hook.
888 *
889 * RETURNS:
890 *
891 * 0 on success or a negative error code on failure.
892 */
893 int (*dpms)(struct drm_connector *connector, int mode);
894
895 /**
896 * @reset:
897 *
898 * Reset connector hardware and software state to off. This function isn't
899 * called by the core directly, only through drm_mode_config_reset().
900 * It's not a helper hook only for historical reasons.
901 *
902 * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
903 * atomic state using this hook.
904 */
905 void (*reset)(struct drm_connector *connector);
906
907 /**
908 * @detect:
909 *
910 * Check to see if anything is attached to the connector. The parameter
911 * force is set to false whilst polling, true when checking the
912 * connector due to a user request. force can be used by the driver to
913 * avoid expensive, destructive operations during automated probing.
914 *
915 * FIXME:
916 *
917 * Note that this hook is only called by the probe helper. It's not in
918 * the helper library vtable purely for historical reasons. The only DRM
919 * core entry point to probe connector state is @fill_modes.
920 *
921 * RETURNS:
922 *
923 * drm_connector_status indicating the connector's status.
924 */
925 enum drm_connector_status (*detect)(struct drm_connector *connector,
926 bool force);
927
928 /**
929 * @force:
930 *
931 * This function is called to update internal encoder state when the
932 * connector is forced to a certain state by userspace, either through
933 * the sysfs interfaces or on the kernel cmdline. In that case the
934 * @detect callback isn't called.
935 *
936 * FIXME:
937 *
938 * Note that this hook is only called by the probe helper. It's not in
939 * the helper library vtable purely for historical reasons. The only DRM
940 * core entry point to probe connector state is @fill_modes.
941 */
942 void (*force)(struct drm_connector *connector);
943
944 /**
945 * @fill_modes:
946 *
947 * Entry point for output detection and basic mode validation. The
948 * driver should reprobe the output if needed (e.g. when hotplug
949 * handling is unreliable), add all detected modes to connector->modes
950 * and filter out any the device can't support in any configuration. It
951 * also needs to filter out any modes wider or higher than the
952 * parameters max_width and max_height indicate.
953 *
954 * The drivers must also prune any modes no longer valid from
955 * connector->modes. Furthermore it must update connector->status and
956 * connector->edid. If no EDID has been received for this output
957 * connector->edid must be NULL.
958 *
959 * Drivers using the probe helpers should use
960 * drm_helper_probe_single_connector_modes() or
961 * drm_helper_probe_single_connector_modes_nomerge() to implement this
962 * function.
963 *
964 * RETURNS:
965 *
966 * The number of modes detected and filled into connector->modes.
967 */
968 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
969
970 /**
971 * @set_property:
972 *
973 * This is the legacy entry point to update a property attached to the
974 * connector.
975 *
976 * Drivers implementing atomic modeset should use
977 * drm_atomic_helper_connector_set_property() to implement this hook.
978 *
979 * This callback is optional if the driver does not support any legacy
980 * driver-private properties.
981 *
982 * RETURNS:
983 *
984 * 0 on success or a negative error code on failure.
985 */
986 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
987 uint64_t val);
988
989 /**
990 * @late_register:
991 *
992 * This optional hook can be used to register additional userspace
993 * interfaces attached to the connector, light backlight control, i2c,
994 * DP aux or similar interfaces. It is called late in the driver load
995 * sequence from drm_connector_register() when registering all the
996 * core drm connector interfaces. Everything added from this callback
997 * should be unregistered in the early_unregister callback.
998 *
999 * Returns:
1000 *
1001 * 0 on success, or a negative error code on failure.
1002 */
1003 int (*late_register)(struct drm_connector *connector);
1004
1005 /**
1006 * @early_unregister:
1007 *
1008 * This optional hook should be used to unregister the additional
1009 * userspace interfaces attached to the connector from
1010 * late_unregister(). It is called from drm_connector_unregister(),
1011 * early in the driver unload sequence to disable userspace access
1012 * before data structures are torndown.
1013 */
1014 void (*early_unregister)(struct drm_connector *connector);
1015
1016 /**
1017 * @destroy:
1018 *
1019 * Clean up connector resources. This is called at driver unload time
1020 * through drm_mode_config_cleanup(). It can also be called at runtime
1021 * when a connector is being hot-unplugged for drivers that support
1022 * connector hotplugging (e.g. DisplayPort MST).
1023 */
1024 void (*destroy)(struct drm_connector *connector);
1025
1026 /**
1027 * @atomic_duplicate_state:
1028 *
1029 * Duplicate the current atomic state for this connector and return it.
1030 * The core and helpers gurantee that any atomic state duplicated with
1031 * this hook and still owned by the caller (i.e. not transferred to the
1032 * driver by calling ->atomic_commit() from struct
1033 * &drm_mode_config_funcs) will be cleaned up by calling the
1034 * @atomic_destroy_state hook in this structure.
1035 *
1036 * Atomic drivers which don't subclass struct &drm_connector_state should use
1037 * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
1038 * state structure to extend it with driver-private state should use
1039 * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
1040 * duplicated in a consistent fashion across drivers.
1041 *
1042 * It is an error to call this hook before connector->state has been
1043 * initialized correctly.
1044 *
1045 * NOTE:
1046 *
1047 * If the duplicate state references refcounted resources this hook must
1048 * acquire a reference for each of them. The driver must release these
1049 * references again in @atomic_destroy_state.
1050 *
1051 * RETURNS:
1052 *
1053 * Duplicated atomic state or NULL when the allocation failed.
1054 */
1055 struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
1056
1057 /**
1058 * @atomic_destroy_state:
1059 *
1060 * Destroy a state duplicated with @atomic_duplicate_state and release
1061 * or unreference all resources it references
1062 */
1063 void (*atomic_destroy_state)(struct drm_connector *connector,
1064 struct drm_connector_state *state);
1065
1066 /**
1067 * @atomic_set_property:
1068 *
1069 * Decode a driver-private property value and store the decoded value
1070 * into the passed-in state structure. Since the atomic core decodes all
1071 * standardized properties (even for extensions beyond the core set of
1072 * properties which might not be implemented by all drivers) this
1073 * requires drivers to subclass the state structure.
1074 *
1075 * Such driver-private properties should really only be implemented for
1076 * truly hardware/vendor specific state. Instead it is preferred to
1077 * standardize atomic extension and decode the properties used to expose
1078 * such an extension in the core.
1079 *
1080 * Do not call this function directly, use
1081 * drm_atomic_connector_set_property() instead.
1082 *
1083 * This callback is optional if the driver does not support any
1084 * driver-private atomic properties.
1085 *
1086 * NOTE:
1087 *
1088 * This function is called in the state assembly phase of atomic
1089 * modesets, which can be aborted for any reason (including on
1090 * userspace's request to just check whether a configuration would be
1091 * possible). Drivers MUST NOT touch any persistent state (hardware or
1092 * software) or data structures except the passed in @state parameter.
1093 *
1094 * Also since userspace controls in which order properties are set this
1095 * function must not do any input validation (since the state update is
1096 * incomplete and hence likely inconsistent). Instead any such input
1097 * validation must be done in the various atomic_check callbacks.
1098 *
1099 * RETURNS:
1100 *
1101 * 0 if the property has been found, -EINVAL if the property isn't
1102 * implemented by the driver (which shouldn't ever happen, the core only
1103 * asks for properties attached to this connector). No other validation
1104 * is allowed by the driver. The core already checks that the property
1105 * value is within the range (integer, valid enum value, ...) the driver
1106 * set when registering the property.
1107 */
1108 int (*atomic_set_property)(struct drm_connector *connector,
1109 struct drm_connector_state *state,
1110 struct drm_property *property,
1111 uint64_t val);
1112
1113 /**
1114 * @atomic_get_property:
1115 *
1116 * Reads out the decoded driver-private property. This is used to
1117 * implement the GETCONNECTOR IOCTL.
1118 *
1119 * Do not call this function directly, use
1120 * drm_atomic_connector_get_property() instead.
1121 *
1122 * This callback is optional if the driver does not support any
1123 * driver-private atomic properties.
1124 *
1125 * RETURNS:
1126 *
1127 * 0 on success, -EINVAL if the property isn't implemented by the
1128 * driver (which shouldn't ever happen, the core only asks for
1129 * properties attached to this connector).
1130 */
1131 int (*atomic_get_property)(struct drm_connector *connector,
1132 const struct drm_connector_state *state,
1133 struct drm_property *property,
1134 uint64_t *val);
1135 };
1136
1137 /**
1138 * struct drm_encoder_funcs - encoder controls
1139 *
1140 * Encoders sit between CRTCs and connectors.
1141 */
1142 struct drm_encoder_funcs {
1143 /**
1144 * @reset:
1145 *
1146 * Reset encoder hardware and software state to off. This function isn't
1147 * called by the core directly, only through drm_mode_config_reset().
1148 * It's not a helper hook only for historical reasons.
1149 */
1150 void (*reset)(struct drm_encoder *encoder);
1151
1152 /**
1153 * @destroy:
1154 *
1155 * Clean up encoder resources. This is only called at driver unload time
1156 * through drm_mode_config_cleanup() since an encoder cannot be
1157 * hotplugged in DRM.
1158 */
1159 void (*destroy)(struct drm_encoder *encoder);
1160
1161 /**
1162 * @late_register:
1163 *
1164 * This optional hook can be used to register additional userspace
1165 * interfaces attached to the encoder like debugfs interfaces.
1166 * It is called late in the driver load sequence from drm_dev_register().
1167 * Everything added from this callback should be unregistered in
1168 * the early_unregister callback.
1169 *
1170 * Returns:
1171 *
1172 * 0 on success, or a negative error code on failure.
1173 */
1174 int (*late_register)(struct drm_encoder *encoder);
1175
1176 /**
1177 * @early_unregister:
1178 *
1179 * This optional hook should be used to unregister the additional
1180 * userspace interfaces attached to the encoder from
1181 * late_unregister(). It is called from drm_dev_unregister(),
1182 * early in the driver unload sequence to disable userspace access
1183 * before data structures are torndown.
1184 */
1185 void (*early_unregister)(struct drm_encoder *encoder);
1186 };
1187
1188 #define DRM_CONNECTOR_MAX_ENCODER 3
1189
1190 /**
1191 * struct drm_encoder - central DRM encoder structure
1192 * @dev: parent DRM device
1193 * @head: list management
1194 * @base: base KMS object
1195 * @name: human readable name, can be overwritten by the driver
1196 * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
1197 * @possible_crtcs: bitmask of potential CRTC bindings
1198 * @possible_clones: bitmask of potential sibling encoders for cloning
1199 * @crtc: currently bound CRTC
1200 * @bridge: bridge associated to the encoder
1201 * @funcs: control functions
1202 * @helper_private: mid-layer private data
1203 *
1204 * CRTCs drive pixels to encoders, which convert them into signals
1205 * appropriate for a given connector or set of connectors.
1206 */
1207 struct drm_encoder {
1208 struct drm_device *dev;
1209 struct list_head head;
1210
1211 struct drm_mode_object base;
1212 char *name;
1213 int encoder_type;
1214
1215 /**
1216 * @index: Position inside the mode_config.list, can be used as an array
1217 * index. It is invariant over the lifetime of the encoder.
1218 */
1219 unsigned index;
1220
1221 uint32_t possible_crtcs;
1222 uint32_t possible_clones;
1223
1224 struct drm_crtc *crtc;
1225 struct drm_bridge *bridge;
1226 const struct drm_encoder_funcs *funcs;
1227 const struct drm_encoder_helper_funcs *helper_private;
1228 };
1229
1230 /* should we poll this connector for connects and disconnects */
1231 /* hot plug detectable */
1232 #define DRM_CONNECTOR_POLL_HPD (1 << 0)
1233 /* poll for connections */
1234 #define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
1235 /* can cleanly poll for disconnections without flickering the screen */
1236 /* DACs should rarely do this without a lot of testing */
1237 #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
1238
1239 #define MAX_ELD_BYTES 128
1240
1241 /**
1242 * struct drm_connector - central DRM connector control structure
1243 * @dev: parent DRM device
1244 * @kdev: kernel device for sysfs attributes
1245 * @attr: sysfs attributes
1246 * @head: list management
1247 * @base: base KMS object
1248 * @name: human readable name, can be overwritten by the driver
1249 * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
1250 * @connector_type_id: index into connector type enum
1251 * @interlace_allowed: can this connector handle interlaced modes?
1252 * @doublescan_allowed: can this connector handle doublescan?
1253 * @stereo_allowed: can this connector handle stereo modes?
1254 * @registered: is this connector exposed (registered) with userspace?
1255 * @modes: modes available on this connector (from fill_modes() + user)
1256 * @status: one of the drm_connector_status enums (connected, not, or unknown)
1257 * @probed_modes: list of modes derived directly from the display
1258 * @display_info: information about attached display (e.g. from EDID)
1259 * @funcs: connector control functions
1260 * @edid_blob_ptr: DRM property containing EDID if present
1261 * @properties: property tracking for this connector
1262 * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
1263 * @dpms: current dpms state
1264 * @helper_private: mid-layer private data
1265 * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
1266 * @force: a %DRM_FORCE_<foo> state for forced mode sets
1267 * @override_edid: has the EDID been overwritten through debugfs for testing?
1268 * @encoder_ids: valid encoders for this connector
1269 * @encoder: encoder driving this connector, if any
1270 * @eld: EDID-like data, if present
1271 * @dvi_dual: dual link DVI, if found
1272 * @max_tmds_clock: max clock rate, if found
1273 * @latency_present: AV delay info from ELD, if found
1274 * @video_latency: video latency info from ELD, if found
1275 * @audio_latency: audio latency info from ELD, if found
1276 * @null_edid_counter: track sinks that give us all zeros for the EDID
1277 * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
1278 * @edid_corrupt: indicates whether the last read EDID was corrupt
1279 * @debugfs_entry: debugfs directory for this connector
1280 * @state: current atomic state for this connector
1281 * @has_tile: is this connector connected to a tiled monitor
1282 * @tile_group: tile group for the connected monitor
1283 * @tile_is_single_monitor: whether the tile is one monitor housing
1284 * @num_h_tile: number of horizontal tiles in the tile group
1285 * @num_v_tile: number of vertical tiles in the tile group
1286 * @tile_h_loc: horizontal location of this tile
1287 * @tile_v_loc: vertical location of this tile
1288 * @tile_h_size: horizontal size of this tile.
1289 * @tile_v_size: vertical size of this tile.
1290 *
1291 * Each connector may be connected to one or more CRTCs, or may be clonable by
1292 * another connector if they can share a CRTC. Each connector also has a specific
1293 * position in the broader display (referred to as a 'screen' though it could
1294 * span multiple monitors).
1295 */
1296 struct drm_connector {
1297 struct drm_device *dev;
1298 struct device *kdev;
1299 struct device_attribute *attr;
1300 struct list_head head;
1301
1302 struct drm_mode_object base;
1303
1304 char *name;
1305
1306 /**
1307 * @index: Compacted connector index, which matches the position inside
1308 * the mode_config.list for drivers not supporting hot-add/removing. Can
1309 * be used as an array index. It is invariant over the lifetime of the
1310 * connector.
1311 */
1312 unsigned index;
1313
1314 int connector_type;
1315 int connector_type_id;
1316 bool interlace_allowed;
1317 bool doublescan_allowed;
1318 bool stereo_allowed;
1319 bool registered;
1320 struct list_head modes; /* list of modes on this connector */
1321
1322 enum drm_connector_status status;
1323
1324 /* these are modes added by probing with DDC or the BIOS */
1325 struct list_head probed_modes;
1326
1327 struct drm_display_info display_info;
1328 const struct drm_connector_funcs *funcs;
1329
1330 struct drm_property_blob *edid_blob_ptr;
1331 struct drm_object_properties properties;
1332
1333 /**
1334 * @path_blob_ptr:
1335 *
1336 * DRM blob property data for the DP MST path property.
1337 */
1338 struct drm_property_blob *path_blob_ptr;
1339
1340 /**
1341 * @tile_blob_ptr:
1342 *
1343 * DRM blob property data for the tile property (used mostly by DP MST).
1344 * This is meant for screens which are driven through separate display
1345 * pipelines represented by &drm_crtc, which might not be running with
1346 * genlocked clocks. For tiled panels which are genlocked, like
1347 * dual-link LVDS or dual-link DSI, the driver should try to not expose
1348 * the tiling and virtualize both &drm_crtc and &drm_plane if needed.
1349 */
1350 struct drm_property_blob *tile_blob_ptr;
1351
1352 uint8_t polled; /* DRM_CONNECTOR_POLL_* */
1353
1354 /* requested DPMS state */
1355 int dpms;
1356
1357 const struct drm_connector_helper_funcs *helper_private;
1358
1359 /* forced on connector */
1360 struct drm_cmdline_mode cmdline_mode;
1361 enum drm_connector_force force;
1362 bool override_edid;
1363 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
1364 struct drm_encoder *encoder; /* currently active encoder */
1365
1366 /* EDID bits */
1367 uint8_t eld[MAX_ELD_BYTES];
1368 bool dvi_dual;
1369 int max_tmds_clock; /* in MHz */
1370 bool latency_present[2];
1371 int video_latency[2]; /* [0]: progressive, [1]: interlaced */
1372 int audio_latency[2];
1373 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
1374 unsigned bad_edid_counter;
1375
1376 /* Flag for raw EDID header corruption - used in Displayport
1377 * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
1378 */
1379 bool edid_corrupt;
1380
1381 struct dentry *debugfs_entry;
1382
1383 struct drm_connector_state *state;
1384
1385 /* DisplayID bits */
1386 bool has_tile;
1387 struct drm_tile_group *tile_group;
1388 bool tile_is_single_monitor;
1389
1390 uint8_t num_h_tile, num_v_tile;
1391 uint8_t tile_h_loc, tile_v_loc;
1392 uint16_t tile_h_size, tile_v_size;
1393 };
1394
1395 /**
1396 * struct drm_plane_state - mutable plane state
1397 * @plane: backpointer to the plane
1398 * @crtc: currently bound CRTC, NULL if disabled
1399 * @fb: currently bound framebuffer
1400 * @fence: optional fence to wait for before scanning out @fb
1401 * @crtc_x: left position of visible portion of plane on crtc
1402 * @crtc_y: upper position of visible portion of plane on crtc
1403 * @crtc_w: width of visible portion of plane on crtc
1404 * @crtc_h: height of visible portion of plane on crtc
1405 * @src_x: left position of visible portion of plane within
1406 * plane (in 16.16)
1407 * @src_y: upper position of visible portion of plane within
1408 * plane (in 16.16)
1409 * @src_w: width of visible portion of plane (in 16.16)
1410 * @src_h: height of visible portion of plane (in 16.16)
1411 * @rotation: rotation of the plane
1412 * @state: backpointer to global drm_atomic_state
1413 */
1414 struct drm_plane_state {
1415 struct drm_plane *plane;
1416
1417 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
1418 struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
1419 struct fence *fence;
1420
1421 /* Signed dest location allows it to be partially off screen */
1422 int32_t crtc_x, crtc_y;
1423 uint32_t crtc_w, crtc_h;
1424
1425 /* Source values are 16.16 fixed point */
1426 uint32_t src_x, src_y;
1427 uint32_t src_h, src_w;
1428
1429 /* Plane rotation */
1430 unsigned int rotation;
1431
1432 struct drm_atomic_state *state;
1433 };
1434
1435
1436 /**
1437 * struct drm_plane_funcs - driver plane control functions
1438 */
1439 struct drm_plane_funcs {
1440 /**
1441 * @update_plane:
1442 *
1443 * This is the legacy entry point to enable and configure the plane for
1444 * the given CRTC and framebuffer. It is never called to disable the
1445 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
1446 *
1447 * The source rectangle in frame buffer memory coordinates is given by
1448 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
1449 * values). Devices that don't support subpixel plane coordinates can
1450 * ignore the fractional part.
1451 *
1452 * The destination rectangle in CRTC coordinates is given by the
1453 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
1454 * Devices scale the source rectangle to the destination rectangle. If
1455 * scaling is not supported, and the source rectangle size doesn't match
1456 * the destination rectangle size, the driver must return a
1457 * -<errorname>EINVAL</errorname> error.
1458 *
1459 * Drivers implementing atomic modeset should use
1460 * drm_atomic_helper_update_plane() to implement this hook.
1461 *
1462 * RETURNS:
1463 *
1464 * 0 on success or a negative error code on failure.
1465 */
1466 int (*update_plane)(struct drm_plane *plane,
1467 struct drm_crtc *crtc, struct drm_framebuffer *fb,
1468 int crtc_x, int crtc_y,
1469 unsigned int crtc_w, unsigned int crtc_h,
1470 uint32_t src_x, uint32_t src_y,
1471 uint32_t src_w, uint32_t src_h);
1472
1473 /**
1474 * @disable_plane:
1475 *
1476 * This is the legacy entry point to disable the plane. The DRM core
1477 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
1478 * with the frame buffer ID set to 0. Disabled planes must not be
1479 * processed by the CRTC.
1480 *
1481 * Drivers implementing atomic modeset should use
1482 * drm_atomic_helper_disable_plane() to implement this hook.
1483 *
1484 * RETURNS:
1485 *
1486 * 0 on success or a negative error code on failure.
1487 */
1488 int (*disable_plane)(struct drm_plane *plane);
1489
1490 /**
1491 * @destroy:
1492 *
1493 * Clean up plane resources. This is only called at driver unload time
1494 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
1495 * in DRM.
1496 */
1497 void (*destroy)(struct drm_plane *plane);
1498
1499 /**
1500 * @reset:
1501 *
1502 * Reset plane hardware and software state to off. This function isn't
1503 * called by the core directly, only through drm_mode_config_reset().
1504 * It's not a helper hook only for historical reasons.
1505 *
1506 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
1507 * atomic state using this hook.
1508 */
1509 void (*reset)(struct drm_plane *plane);
1510
1511 /**
1512 * @set_property:
1513 *
1514 * This is the legacy entry point to update a property attached to the
1515 * plane.
1516 *
1517 * Drivers implementing atomic modeset should use
1518 * drm_atomic_helper_plane_set_property() to implement this hook.
1519 *
1520 * This callback is optional if the driver does not support any legacy
1521 * driver-private properties.
1522 *
1523 * RETURNS:
1524 *
1525 * 0 on success or a negative error code on failure.
1526 */
1527 int (*set_property)(struct drm_plane *plane,
1528 struct drm_property *property, uint64_t val);
1529
1530 /**
1531 * @atomic_duplicate_state:
1532 *
1533 * Duplicate the current atomic state for this plane and return it.
1534 * The core and helpers gurantee that any atomic state duplicated with
1535 * this hook and still owned by the caller (i.e. not transferred to the
1536 * driver by calling ->atomic_commit() from struct
1537 * &drm_mode_config_funcs) will be cleaned up by calling the
1538 * @atomic_destroy_state hook in this structure.
1539 *
1540 * Atomic drivers which don't subclass struct &drm_plane_state should use
1541 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
1542 * state structure to extend it with driver-private state should use
1543 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
1544 * duplicated in a consistent fashion across drivers.
1545 *
1546 * It is an error to call this hook before plane->state has been
1547 * initialized correctly.
1548 *
1549 * NOTE:
1550 *
1551 * If the duplicate state references refcounted resources this hook must
1552 * acquire a reference for each of them. The driver must release these
1553 * references again in @atomic_destroy_state.
1554 *
1555 * RETURNS:
1556 *
1557 * Duplicated atomic state or NULL when the allocation failed.
1558 */
1559 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
1560
1561 /**
1562 * @atomic_destroy_state:
1563 *
1564 * Destroy a state duplicated with @atomic_duplicate_state and release
1565 * or unreference all resources it references
1566 */
1567 void (*atomic_destroy_state)(struct drm_plane *plane,
1568 struct drm_plane_state *state);
1569
1570 /**
1571 * @atomic_set_property:
1572 *
1573 * Decode a driver-private property value and store the decoded value
1574 * into the passed-in state structure. Since the atomic core decodes all
1575 * standardized properties (even for extensions beyond the core set of
1576 * properties which might not be implemented by all drivers) this
1577 * requires drivers to subclass the state structure.
1578 *
1579 * Such driver-private properties should really only be implemented for
1580 * truly hardware/vendor specific state. Instead it is preferred to
1581 * standardize atomic extension and decode the properties used to expose
1582 * such an extension in the core.
1583 *
1584 * Do not call this function directly, use
1585 * drm_atomic_plane_set_property() instead.
1586 *
1587 * This callback is optional if the driver does not support any
1588 * driver-private atomic properties.
1589 *
1590 * NOTE:
1591 *
1592 * This function is called in the state assembly phase of atomic
1593 * modesets, which can be aborted for any reason (including on
1594 * userspace's request to just check whether a configuration would be
1595 * possible). Drivers MUST NOT touch any persistent state (hardware or
1596 * software) or data structures except the passed in @state parameter.
1597 *
1598 * Also since userspace controls in which order properties are set this
1599 * function must not do any input validation (since the state update is
1600 * incomplete and hence likely inconsistent). Instead any such input
1601 * validation must be done in the various atomic_check callbacks.
1602 *
1603 * RETURNS:
1604 *
1605 * 0 if the property has been found, -EINVAL if the property isn't
1606 * implemented by the driver (which shouldn't ever happen, the core only
1607 * asks for properties attached to this plane). No other validation is
1608 * allowed by the driver. The core already checks that the property
1609 * value is within the range (integer, valid enum value, ...) the driver
1610 * set when registering the property.
1611 */
1612 int (*atomic_set_property)(struct drm_plane *plane,
1613 struct drm_plane_state *state,
1614 struct drm_property *property,
1615 uint64_t val);
1616
1617 /**
1618 * @atomic_get_property:
1619 *
1620 * Reads out the decoded driver-private property. This is used to
1621 * implement the GETPLANE IOCTL.
1622 *
1623 * Do not call this function directly, use
1624 * drm_atomic_plane_get_property() instead.
1625 *
1626 * This callback is optional if the driver does not support any
1627 * driver-private atomic properties.
1628 *
1629 * RETURNS:
1630 *
1631 * 0 on success, -EINVAL if the property isn't implemented by the
1632 * driver (which should never happen, the core only asks for
1633 * properties attached to this plane).
1634 */
1635 int (*atomic_get_property)(struct drm_plane *plane,
1636 const struct drm_plane_state *state,
1637 struct drm_property *property,
1638 uint64_t *val);
1639 /**
1640 * @late_register:
1641 *
1642 * This optional hook can be used to register additional userspace
1643 * interfaces attached to the plane like debugfs interfaces.
1644 * It is called late in the driver load sequence from drm_dev_register().
1645 * Everything added from this callback should be unregistered in
1646 * the early_unregister callback.
1647 *
1648 * Returns:
1649 *
1650 * 0 on success, or a negative error code on failure.
1651 */
1652 int (*late_register)(struct drm_plane *plane);
1653
1654 /**
1655 * @early_unregister:
1656 *
1657 * This optional hook should be used to unregister the additional
1658 * userspace interfaces attached to the plane from
1659 * late_unregister(). It is called from drm_dev_unregister(),
1660 * early in the driver unload sequence to disable userspace access
1661 * before data structures are torndown.
1662 */
1663 void (*early_unregister)(struct drm_plane *plane);
1664 };
1665
1666 enum drm_plane_type {
1667 DRM_PLANE_TYPE_OVERLAY,
1668 DRM_PLANE_TYPE_PRIMARY,
1669 DRM_PLANE_TYPE_CURSOR,
1670 };
1671
1672
1673 /**
1674 * struct drm_plane - central DRM plane control structure
1675 * @dev: DRM device this plane belongs to
1676 * @head: for list management
1677 * @name: human readable name, can be overwritten by the driver
1678 * @base: base mode object
1679 * @possible_crtcs: pipes this plane can be bound to
1680 * @format_types: array of formats supported by this plane
1681 * @format_count: number of formats supported
1682 * @format_default: driver hasn't supplied supported formats for the plane
1683 * @crtc: currently bound CRTC
1684 * @fb: currently bound fb
1685 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
1686 * drm_mode_set_config_internal() to implement correct refcounting.
1687 * @funcs: helper functions
1688 * @properties: property tracking for this plane
1689 * @type: type of plane (overlay, primary, cursor)
1690 * @state: current atomic state for this plane
1691 * @helper_private: mid-layer private data
1692 */
1693 struct drm_plane {
1694 struct drm_device *dev;
1695 struct list_head head;
1696
1697 char *name;
1698
1699 /**
1700 * @mutex:
1701 *
1702 * Protects modeset plane state, together with the mutex of &drm_crtc
1703 * this plane is linked to (when active, getting actived or getting
1704 * disabled).
1705 */
1706 struct drm_modeset_lock mutex;
1707
1708 struct drm_mode_object base;
1709
1710 uint32_t possible_crtcs;
1711 uint32_t *format_types;
1712 unsigned int format_count;
1713 bool format_default;
1714
1715 struct drm_crtc *crtc;
1716 struct drm_framebuffer *fb;
1717
1718 struct drm_framebuffer *old_fb;
1719
1720 const struct drm_plane_funcs *funcs;
1721
1722 struct drm_object_properties properties;
1723
1724 enum drm_plane_type type;
1725
1726 /**
1727 * @index: Position inside the mode_config.list, can be used as an array
1728 * index. It is invariant over the lifetime of the plane.
1729 */
1730 unsigned index;
1731
1732 const struct drm_plane_helper_funcs *helper_private;
1733
1734 struct drm_plane_state *state;
1735 };
1736
1737 /**
1738 * struct drm_bridge_funcs - drm_bridge control functions
1739 * @attach: Called during drm_bridge_attach
1740 */
1741 struct drm_bridge_funcs {
1742 int (*attach)(struct drm_bridge *bridge);
1743
1744 /**
1745 * @mode_fixup:
1746 *
1747 * This callback is used to validate and adjust a mode. The paramater
1748 * mode is the display mode that should be fed to the next element in
1749 * the display chain, either the final &drm_connector or the next
1750 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
1751 * requires. It can be modified by this callback and does not need to
1752 * match mode.
1753 *
1754 * This is the only hook that allows a bridge to reject a modeset. If
1755 * this function passes all other callbacks must succeed for this
1756 * configuration.
1757 *
1758 * NOTE:
1759 *
1760 * This function is called in the check phase of atomic modesets, which
1761 * can be aborted for any reason (including on userspace's request to
1762 * just check whether a configuration would be possible). Drivers MUST
1763 * NOT touch any persistent state (hardware or software) or data
1764 * structures except the passed in @state parameter.
1765 *
1766 * RETURNS:
1767 *
1768 * True if an acceptable configuration is possible, false if the modeset
1769 * operation should be rejected.
1770 */
1771 bool (*mode_fixup)(struct drm_bridge *bridge,
1772 const struct drm_display_mode *mode,
1773 struct drm_display_mode *adjusted_mode);
1774 /**
1775 * @disable:
1776 *
1777 * This callback should disable the bridge. It is called right before
1778 * the preceding element in the display pipe is disabled. If the
1779 * preceding element is a bridge this means it's called before that
1780 * bridge's ->disable() function. If the preceding element is a
1781 * &drm_encoder it's called right before the encoder's ->disable(),
1782 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1783 *
1784 * The bridge can assume that the display pipe (i.e. clocks and timing
1785 * signals) feeding it is still running when this callback is called.
1786 *
1787 * The disable callback is optional.
1788 */
1789 void (*disable)(struct drm_bridge *bridge);
1790
1791 /**
1792 * @post_disable:
1793 *
1794 * This callback should disable the bridge. It is called right after
1795 * the preceding element in the display pipe is disabled. If the
1796 * preceding element is a bridge this means it's called after that
1797 * bridge's ->post_disable() function. If the preceding element is a
1798 * &drm_encoder it's called right after the encoder's ->disable(),
1799 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1800 *
1801 * The bridge must assume that the display pipe (i.e. clocks and timing
1802 * singals) feeding it is no longer running when this callback is
1803 * called.
1804 *
1805 * The post_disable callback is optional.
1806 */
1807 void (*post_disable)(struct drm_bridge *bridge);
1808
1809 /**
1810 * @mode_set:
1811 *
1812 * This callback should set the given mode on the bridge. It is called
1813 * after the ->mode_set() callback for the preceding element in the
1814 * display pipeline has been called already. The display pipe (i.e.
1815 * clocks and timing signals) is off when this function is called.
1816 */
1817 void (*mode_set)(struct drm_bridge *bridge,
1818 struct drm_display_mode *mode,
1819 struct drm_display_mode *adjusted_mode);
1820 /**
1821 * @pre_enable:
1822 *
1823 * This callback should enable the bridge. It is called right before
1824 * the preceding element in the display pipe is enabled. If the
1825 * preceding element is a bridge this means it's called before that
1826 * bridge's ->pre_enable() function. If the preceding element is a
1827 * &drm_encoder it's called right before the encoder's ->enable(),
1828 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1829 *
1830 * The display pipe (i.e. clocks and timing signals) feeding this bridge
1831 * will not yet be running when this callback is called. The bridge must
1832 * not enable the display link feeding the next bridge in the chain (if
1833 * there is one) when this callback is called.
1834 *
1835 * The pre_enable callback is optional.
1836 */
1837 void (*pre_enable)(struct drm_bridge *bridge);
1838
1839 /**
1840 * @enable:
1841 *
1842 * This callback should enable the bridge. It is called right after
1843 * the preceding element in the display pipe is enabled. If the
1844 * preceding element is a bridge this means it's called after that
1845 * bridge's ->enable() function. If the preceding element is a
1846 * &drm_encoder it's called right after the encoder's ->enable(),
1847 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1848 *
1849 * The bridge can assume that the display pipe (i.e. clocks and timing
1850 * signals) feeding it is running when this callback is called. This
1851 * callback must enable the display link feeding the next bridge in the
1852 * chain if there is one.
1853 *
1854 * The enable callback is optional.
1855 */
1856 void (*enable)(struct drm_bridge *bridge);
1857 };
1858
1859 /**
1860 * struct drm_bridge - central DRM bridge control structure
1861 * @dev: DRM device this bridge belongs to
1862 * @encoder: encoder to which this bridge is connected
1863 * @next: the next bridge in the encoder chain
1864 * @of_node: device node pointer to the bridge
1865 * @list: to keep track of all added bridges
1866 * @funcs: control functions
1867 * @driver_private: pointer to the bridge driver's internal context
1868 */
1869 struct drm_bridge {
1870 struct drm_device *dev;
1871 struct drm_encoder *encoder;
1872 struct drm_bridge *next;
1873 #ifdef CONFIG_OF
1874 struct device_node *of_node;
1875 #endif
1876 struct list_head list;
1877
1878 const struct drm_bridge_funcs *funcs;
1879 void *driver_private;
1880 };
1881
1882 /**
1883 * struct drm_crtc_commit - track modeset commits on a CRTC
1884 *
1885 * This structure is used to track pending modeset changes and atomic commit on
1886 * a per-CRTC basis. Since updating the list should never block this structure
1887 * is reference counted to allow waiters to safely wait on an event to complete,
1888 * without holding any locks.
1889 *
1890 * It has 3 different events in total to allow a fine-grained synchronization
1891 * between outstanding updates::
1892 *
1893 * atomic commit thread hardware
1894 *
1895 * write new state into hardware ----> ...
1896 * signal hw_done
1897 * switch to new state on next
1898 * ... v/hblank
1899 *
1900 * wait for buffers to show up ...
1901 *
1902 * ... send completion irq
1903 * irq handler signals flip_done
1904 * cleanup old buffers
1905 *
1906 * signal cleanup_done
1907 *
1908 * wait for flip_done <----
1909 * clean up atomic state
1910 *
1911 * The important bit to know is that cleanup_done is the terminal event, but the
1912 * ordering between flip_done and hw_done is entirely up to the specific driver
1913 * and modeset state change.
1914 *
1915 * For an implementation of how to use this look at
1916 * drm_atomic_helper_setup_commit() from the atomic helper library.
1917 */
1918 struct drm_crtc_commit {
1919 /**
1920 * @crtc:
1921 *
1922 * DRM CRTC for this commit.
1923 */
1924 struct drm_crtc *crtc;
1925
1926 /**
1927 * @ref:
1928 *
1929 * Reference count for this structure. Needed to allow blocking on
1930 * completions without the risk of the completion disappearing
1931 * meanwhile.
1932 */
1933 struct kref ref;
1934
1935 /**
1936 * @flip_done:
1937 *
1938 * Will be signaled when the hardware has flipped to the new set of
1939 * buffers. Signals at the same time as when the drm event for this
1940 * commit is sent to userspace, or when an out-fence is singalled. Note
1941 * that for most hardware, in most cases this happens after @hw_done is
1942 * signalled.
1943 */
1944 struct completion flip_done;
1945
1946 /**
1947 * @hw_done:
1948 *
1949 * Will be signalled when all hw register changes for this commit have
1950 * been written out. Especially when disabling a pipe this can be much
1951 * later than than @flip_done, since that can signal already when the
1952 * screen goes black, whereas to fully shut down a pipe more register
1953 * I/O is required.
1954 *
1955 * Note that this does not need to include separately reference-counted
1956 * resources like backing storage buffer pinning, or runtime pm
1957 * management.
1958 */
1959 struct completion hw_done;
1960
1961 /**
1962 * @cleanup_done:
1963 *
1964 * Will be signalled after old buffers have been cleaned up by calling
1965 * drm_atomic_helper_cleanup_planes(). Since this can only happen after
1966 * a vblank wait completed it might be a bit later. This completion is
1967 * useful to throttle updates and avoid hardware updates getting ahead
1968 * of the buffer cleanup too much.
1969 */
1970 struct completion cleanup_done;
1971
1972 /**
1973 * @commit_entry:
1974 *
1975 * Entry on the per-CRTC commit_list. Protected by crtc->commit_lock.
1976 */
1977 struct list_head commit_entry;
1978
1979 /**
1980 * @event:
1981 *
1982 * &drm_pending_vblank_event pointer to clean up private events.
1983 */
1984 struct drm_pending_vblank_event *event;
1985 };
1986
1987 struct __drm_planes_state {
1988 struct drm_plane *ptr;
1989 struct drm_plane_state *state;
1990 };
1991
1992 struct __drm_crtcs_state {
1993 struct drm_crtc *ptr;
1994 struct drm_crtc_state *state;
1995 struct drm_crtc_commit *commit;
1996 };
1997
1998 struct __drm_connnectors_state {
1999 struct drm_connector *ptr;
2000 struct drm_connector_state *state;
2001 };
2002
2003 /**
2004 * struct drm_atomic_state - the global state object for atomic updates
2005 * @dev: parent DRM device
2006 * @allow_modeset: allow full modeset
2007 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
2008 * @legacy_set_config: Disable conflicting encoders instead of failing with -EINVAL.
2009 * @planes: pointer to array of structures with per-plane data
2010 * @crtcs: pointer to array of CRTC pointers
2011 * @num_connector: size of the @connectors and @connector_states arrays
2012 * @connectors: pointer to array of structures with per-connector data
2013 * @acquire_ctx: acquire context for this atomic modeset state update
2014 */
2015 struct drm_atomic_state {
2016 struct drm_device *dev;
2017 bool allow_modeset : 1;
2018 bool legacy_cursor_update : 1;
2019 bool legacy_set_config : 1;
2020 struct __drm_planes_state *planes;
2021 struct __drm_crtcs_state *crtcs;
2022 int num_connector;
2023 struct __drm_connnectors_state *connectors;
2024
2025 struct drm_modeset_acquire_ctx *acquire_ctx;
2026
2027 /**
2028 * @commit_work:
2029 *
2030 * Work item which can be used by the driver or helpers to execute the
2031 * commit without blocking.
2032 */
2033 struct work_struct commit_work;
2034 };
2035
2036
2037 /**
2038 * struct drm_mode_set - new values for a CRTC config change
2039 * @fb: framebuffer to use for new config
2040 * @crtc: CRTC whose configuration we're about to change
2041 * @mode: mode timings to use
2042 * @x: position of this CRTC relative to @fb
2043 * @y: position of this CRTC relative to @fb
2044 * @connectors: array of connectors to drive with this CRTC if possible
2045 * @num_connectors: size of @connectors array
2046 *
2047 * Represents a single crtc the connectors that it drives with what mode
2048 * and from which framebuffer it scans out from.
2049 *
2050 * This is used to set modes.
2051 */
2052 struct drm_mode_set {
2053 struct drm_framebuffer *fb;
2054 struct drm_crtc *crtc;
2055 struct drm_display_mode *mode;
2056
2057 uint32_t x;
2058 uint32_t y;
2059
2060 struct drm_connector **connectors;
2061 size_t num_connectors;
2062 };
2063
2064 /**
2065 * struct drm_mode_config_funcs - basic driver provided mode setting functions
2066 *
2067 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
2068 * involve drivers.
2069 */
2070 struct drm_mode_config_funcs {
2071 /**
2072 * @fb_create:
2073 *
2074 * Create a new framebuffer object. The core does basic checks on the
2075 * requested metadata, but most of that is left to the driver. See
2076 * struct &drm_mode_fb_cmd2 for details.
2077 *
2078 * If the parameters are deemed valid and the backing storage objects in
2079 * the underlying memory manager all exist, then the driver allocates
2080 * a new &drm_framebuffer structure, subclassed to contain
2081 * driver-specific information (like the internal native buffer object
2082 * references). It also needs to fill out all relevant metadata, which
2083 * should be done by calling drm_helper_mode_fill_fb_struct().
2084 *
2085 * The initialization is finalized by calling drm_framebuffer_init(),
2086 * which registers the framebuffer and makes it accessible to other
2087 * threads.
2088 *
2089 * RETURNS:
2090 *
2091 * A new framebuffer with an initial reference count of 1 or a negative
2092 * error code encoded with ERR_PTR().
2093 */
2094 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
2095 struct drm_file *file_priv,
2096 const struct drm_mode_fb_cmd2 *mode_cmd);
2097
2098 /**
2099 * @output_poll_changed:
2100 *
2101 * Callback used by helpers to inform the driver of output configuration
2102 * changes.
2103 *
2104 * Drivers implementing fbdev emulation with the helpers can call
2105 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
2106 * helper of output changes.
2107 *
2108 * FIXME:
2109 *
2110 * Except that there's no vtable for device-level helper callbacks
2111 * there's no reason this is a core function.
2112 */
2113 void (*output_poll_changed)(struct drm_device *dev);
2114
2115 /**
2116 * @atomic_check:
2117 *
2118 * This is the only hook to validate an atomic modeset update. This
2119 * function must reject any modeset and state changes which the hardware
2120 * or driver doesn't support. This includes but is of course not limited
2121 * to:
2122 *
2123 * - Checking that the modes, framebuffers, scaling and placement
2124 * requirements and so on are within the limits of the hardware.
2125 *
2126 * - Checking that any hidden shared resources are not oversubscribed.
2127 * This can be shared PLLs, shared lanes, overall memory bandwidth,
2128 * display fifo space (where shared between planes or maybe even
2129 * CRTCs).
2130 *
2131 * - Checking that virtualized resources exported to userspace are not
2132 * oversubscribed. For various reasons it can make sense to expose
2133 * more planes, crtcs or encoders than which are physically there. One
2134 * example is dual-pipe operations (which generally should be hidden
2135 * from userspace if when lockstepped in hardware, exposed otherwise),
2136 * where a plane might need 1 hardware plane (if it's just on one
2137 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
2138 * shared a hardware plane with a 2nd plane (if there's a compatible
2139 * plane requested on the area handled by the other pipe).
2140 *
2141 * - Check that any transitional state is possible and that if
2142 * requested, the update can indeed be done in the vblank period
2143 * without temporarily disabling some functions.
2144 *
2145 * - Check any other constraints the driver or hardware might have.
2146 *
2147 * - This callback also needs to correctly fill out the &drm_crtc_state
2148 * in this update to make sure that drm_atomic_crtc_needs_modeset()
2149 * reflects the nature of the possible update and returns true if and
2150 * only if the update cannot be applied without tearing within one
2151 * vblank on that CRTC. The core uses that information to reject
2152 * updates which require a full modeset (i.e. blanking the screen, or
2153 * at least pausing updates for a substantial amount of time) if
2154 * userspace has disallowed that in its request.
2155 *
2156 * - The driver also does not need to repeat basic input validation
2157 * like done for the corresponding legacy entry points. The core does
2158 * that before calling this hook.
2159 *
2160 * See the documentation of @atomic_commit for an exhaustive list of
2161 * error conditions which don't have to be checked at the
2162 * ->atomic_check() stage?
2163 *
2164 * See the documentation for struct &drm_atomic_state for how exactly
2165 * an atomic modeset update is described.
2166 *
2167 * Drivers using the atomic helpers can implement this hook using
2168 * drm_atomic_helper_check(), or one of the exported sub-functions of
2169 * it.
2170 *
2171 * RETURNS:
2172 *
2173 * 0 on success or one of the below negative error codes:
2174 *
2175 * - -EINVAL, if any of the above constraints are violated.
2176 *
2177 * - -EDEADLK, when returned from an attempt to acquire an additional
2178 * &drm_modeset_lock through drm_modeset_lock().
2179 *
2180 * - -ENOMEM, if allocating additional state sub-structures failed due
2181 * to lack of memory.
2182 *
2183 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
2184 * This can either be due to a pending signal, or because the driver
2185 * needs to completely bail out to recover from an exceptional
2186 * situation like a GPU hang. From a userspace point all errors are
2187 * treated equally.
2188 */
2189 int (*atomic_check)(struct drm_device *dev,
2190 struct drm_atomic_state *state);
2191
2192 /**
2193 * @atomic_commit:
2194 *
2195 * This is the only hook to commit an atomic modeset update. The core
2196 * guarantees that @atomic_check has been called successfully before
2197 * calling this function, and that nothing has been changed in the
2198 * interim.
2199 *
2200 * See the documentation for struct &drm_atomic_state for how exactly
2201 * an atomic modeset update is described.
2202 *
2203 * Drivers using the atomic helpers can implement this hook using
2204 * drm_atomic_helper_commit(), or one of the exported sub-functions of
2205 * it.
2206 *
2207 * Nonblocking commits (as indicated with the nonblock parameter) must
2208 * do any preparatory work which might result in an unsuccessful commit
2209 * in the context of this callback. The only exceptions are hardware
2210 * errors resulting in -EIO. But even in that case the driver must
2211 * ensure that the display pipe is at least running, to avoid
2212 * compositors crashing when pageflips don't work. Anything else,
2213 * specifically committing the update to the hardware, should be done
2214 * without blocking the caller. For updates which do not require a
2215 * modeset this must be guaranteed.
2216 *
2217 * The driver must wait for any pending rendering to the new
2218 * framebuffers to complete before executing the flip. It should also
2219 * wait for any pending rendering from other drivers if the underlying
2220 * buffer is a shared dma-buf. Nonblocking commits must not wait for
2221 * rendering in the context of this callback.
2222 *
2223 * An application can request to be notified when the atomic commit has
2224 * completed. These events are per-CRTC and can be distinguished by the
2225 * CRTC index supplied in &drm_event to userspace.
2226 *
2227 * The drm core will supply a struct &drm_event in the event
2228 * member of each CRTC's &drm_crtc_state structure. This can be handled by the
2229 * drm_crtc_send_vblank_event() function, which the driver should call on
2230 * the provided event upon completion of the atomic commit. Note that if
2231 * the driver supports vblank signalling and timestamping the vblank
2232 * counters and timestamps must agree with the ones returned from page
2233 * flip events. With the current vblank helper infrastructure this can
2234 * be achieved by holding a vblank reference while the page flip is
2235 * pending, acquired through drm_crtc_vblank_get() and released with
2236 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
2237 * counter and timestamp tracking though, e.g. if they have accurate
2238 * timestamp registers in hardware.
2239 *
2240 * NOTE:
2241 *
2242 * Drivers are not allowed to shut down any display pipe successfully
2243 * enabled through an atomic commit on their own. Doing so can result in
2244 * compositors crashing if a page flip is suddenly rejected because the
2245 * pipe is off.
2246 *
2247 * RETURNS:
2248 *
2249 * 0 on success or one of the below negative error codes:
2250 *
2251 * - -EBUSY, if a nonblocking updated is requested and there is
2252 * an earlier updated pending. Drivers are allowed to support a queue
2253 * of outstanding updates, but currently no driver supports that.
2254 * Note that drivers must wait for preceding updates to complete if a
2255 * synchronous update is requested, they are not allowed to fail the
2256 * commit in that case.
2257 *
2258 * - -ENOMEM, if the driver failed to allocate memory. Specifically
2259 * this can happen when trying to pin framebuffers, which must only
2260 * be done when committing the state.
2261 *
2262 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
2263 * that the driver has run out of vram, iommu space or similar GPU
2264 * address space needed for framebuffer.
2265 *
2266 * - -EIO, if the hardware completely died.
2267 *
2268 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
2269 * This can either be due to a pending signal, or because the driver
2270 * needs to completely bail out to recover from an exceptional
2271 * situation like a GPU hang. From a userspace point of view all errors are
2272 * treated equally.
2273 *
2274 * This list is exhaustive. Specifically this hook is not allowed to
2275 * return -EINVAL (any invalid requests should be caught in
2276 * @atomic_check) or -EDEADLK (this function must not acquire
2277 * additional modeset locks).
2278 */
2279 int (*atomic_commit)(struct drm_device *dev,
2280 struct drm_atomic_state *state,
2281 bool nonblock);
2282
2283 /**
2284 * @atomic_state_alloc:
2285 *
2286 * This optional hook can be used by drivers that want to subclass struct
2287 * &drm_atomic_state to be able to track their own driver-private global
2288 * state easily. If this hook is implemented, drivers must also
2289 * implement @atomic_state_clear and @atomic_state_free.
2290 *
2291 * RETURNS:
2292 *
2293 * A new &drm_atomic_state on success or NULL on failure.
2294 */
2295 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
2296
2297 /**
2298 * @atomic_state_clear:
2299 *
2300 * This hook must clear any driver private state duplicated into the
2301 * passed-in &drm_atomic_state. This hook is called when the caller
2302 * encountered a &drm_modeset_lock deadlock and needs to drop all
2303 * already acquired locks as part of the deadlock avoidance dance
2304 * implemented in drm_modeset_lock_backoff().
2305 *
2306 * Any duplicated state must be invalidated since a concurrent atomic
2307 * update might change it, and the drm atomic interfaces always apply
2308 * updates as relative changes to the current state.
2309 *
2310 * Drivers that implement this must call drm_atomic_state_default_clear()
2311 * to clear common state.
2312 */
2313 void (*atomic_state_clear)(struct drm_atomic_state *state);
2314
2315 /**
2316 * @atomic_state_free:
2317 *
2318 * This hook needs driver private resources and the &drm_atomic_state
2319 * itself. Note that the core first calls drm_atomic_state_clear() to
2320 * avoid code duplicate between the clear and free hooks.
2321 *
2322 * Drivers that implement this must call drm_atomic_state_default_free()
2323 * to release common resources.
2324 */
2325 void (*atomic_state_free)(struct drm_atomic_state *state);
2326 };
2327
2328 /**
2329 * struct drm_mode_config - Mode configuration control structure
2330 * @mutex: mutex protecting KMS related lists and structures
2331 * @connection_mutex: ww mutex protecting connector state and routing
2332 * @acquire_ctx: global implicit acquire context used by atomic drivers for
2333 * legacy IOCTLs
2334 * @fb_lock: mutex to protect fb state and lists
2335 * @num_fb: number of fbs available
2336 * @fb_list: list of framebuffers available
2337 * @num_encoder: number of encoders on this device
2338 * @encoder_list: list of encoder objects
2339 * @num_overlay_plane: number of overlay planes on this device
2340 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
2341 * @plane_list: list of plane objects
2342 * @num_crtc: number of CRTCs on this device
2343 * @crtc_list: list of CRTC objects
2344 * @property_list: list of property objects
2345 * @min_width: minimum pixel width on this device
2346 * @min_height: minimum pixel height on this device
2347 * @max_width: maximum pixel width on this device
2348 * @max_height: maximum pixel height on this device
2349 * @funcs: core driver provided mode setting functions
2350 * @fb_base: base address of the framebuffer
2351 * @poll_enabled: track polling support for this device
2352 * @poll_running: track polling status for this device
2353 * @delayed_event: track delayed poll uevent deliver for this device
2354 * @output_poll_work: delayed work for polling in process context
2355 * @property_blob_list: list of all the blob property objects
2356 * @blob_lock: mutex for blob property allocation and management
2357 * @*_property: core property tracking
2358 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
2359 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
2360 * @cursor_width: hint to userspace for max cursor width
2361 * @cursor_height: hint to userspace for max cursor height
2362 * @helper_private: mid-layer private data
2363 *
2364 * Core mode resource tracking structure. All CRTC, encoders, and connectors
2365 * enumerated by the driver are added here, as are global properties. Some
2366 * global restrictions are also here, e.g. dimension restrictions.
2367 */
2368 struct drm_mode_config {
2369 struct mutex mutex; /* protects configuration (mode lists etc.) */
2370 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
2371 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
2372
2373 /**
2374 * @idr_mutex:
2375 *
2376 * Mutex for KMS ID allocation and management. Protects both @crtc_idr
2377 * and @tile_idr.
2378 */
2379 struct mutex idr_mutex;
2380
2381 /**
2382 * @crtc_idr:
2383 *
2384 * Main KMS ID tracking object. Use this idr for all IDs, fb, crtc,
2385 * connector, modes - just makes life easier to have only one.
2386 */
2387 struct idr crtc_idr;
2388
2389 /**
2390 * @tile_idr:
2391 *
2392 * Use this idr for allocating new IDs for tiled sinks like use in some
2393 * high-res DP MST screens.
2394 */
2395 struct idr tile_idr;
2396
2397 struct mutex fb_lock; /* proctects global and per-file fb lists */
2398 int num_fb;
2399 struct list_head fb_list;
2400
2401 /**
2402 * @num_connector: Number of connectors on this device.
2403 */
2404 int num_connector;
2405 /**
2406 * @connector_ida: ID allocator for connector indices.
2407 */
2408 struct ida connector_ida;
2409 /**
2410 * @connector_list: List of connector objects.
2411 */
2412 struct list_head connector_list;
2413 int num_encoder;
2414 struct list_head encoder_list;
2415
2416 /*
2417 * Track # of overlay planes separately from # of total planes. By
2418 * default we only advertise overlay planes to userspace; if userspace
2419 * sets the "universal plane" capability bit, we'll go ahead and
2420 * expose all planes.
2421 */
2422 int num_overlay_plane;
2423 int num_total_plane;
2424 struct list_head plane_list;
2425
2426 int num_crtc;
2427 struct list_head crtc_list;
2428
2429 struct list_head property_list;
2430
2431 int min_width, min_height;
2432 int max_width, max_height;
2433 const struct drm_mode_config_funcs *funcs;
2434 resource_size_t fb_base;
2435
2436 /* output poll support */
2437 bool poll_enabled;
2438 bool poll_running;
2439 bool delayed_event;
2440 struct delayed_work output_poll_work;
2441
2442 struct mutex blob_lock;
2443
2444 /* pointers to standard properties */
2445 struct list_head property_blob_list;
2446 /**
2447 * @edid_property: Default connector property to hold the EDID of the
2448 * currently connected sink, if any.
2449 */
2450 struct drm_property *edid_property;
2451 /**
2452 * @dpms_property: Default connector property to control the
2453 * connector's DPMS state.
2454 */
2455 struct drm_property *dpms_property;
2456 /**
2457 * @path_property: Default connector property to hold the DP MST path
2458 * for the port.
2459 */
2460 struct drm_property *path_property;
2461 /**
2462 * @tile_property: Default connector property to store the tile
2463 * position of a tiled screen, for sinks which need to be driven with
2464 * multiple CRTCs.
2465 */
2466 struct drm_property *tile_property;
2467 /**
2468 * @plane_type_property: Default plane property to differentiate
2469 * CURSOR, PRIMARY and OVERLAY legacy uses of planes.
2470 */
2471 struct drm_property *plane_type_property;
2472 /**
2473 * @rotation_property: Optional property for planes or CRTCs to specifiy
2474 * rotation.
2475 */
2476 struct drm_property *rotation_property;
2477 /**
2478 * @prop_src_x: Default atomic plane property for the plane source
2479 * position in the connected &drm_framebuffer.
2480 */
2481 struct drm_property *prop_src_x;
2482 /**
2483 * @prop_src_y: Default atomic plane property for the plane source
2484 * position in the connected &drm_framebuffer.
2485 */
2486 struct drm_property *prop_src_y;
2487 /**
2488 * @prop_src_w: Default atomic plane property for the plane source
2489 * position in the connected &drm_framebuffer.
2490 */
2491 struct drm_property *prop_src_w;
2492 /**
2493 * @prop_src_h: Default atomic plane property for the plane source
2494 * position in the connected &drm_framebuffer.
2495 */
2496 struct drm_property *prop_src_h;
2497 /**
2498 * @prop_crtc_x: Default atomic plane property for the plane destination
2499 * position in the &drm_crtc is is being shown on.
2500 */
2501 struct drm_property *prop_crtc_x;
2502 /**
2503 * @prop_crtc_y: Default atomic plane property for the plane destination
2504 * position in the &drm_crtc is is being shown on.
2505 */
2506 struct drm_property *prop_crtc_y;
2507 /**
2508 * @prop_crtc_w: Default atomic plane property for the plane destination
2509 * position in the &drm_crtc is is being shown on.
2510 */
2511 struct drm_property *prop_crtc_w;
2512 /**
2513 * @prop_crtc_h: Default atomic plane property for the plane destination
2514 * position in the &drm_crtc is is being shown on.
2515 */
2516 struct drm_property *prop_crtc_h;
2517 /**
2518 * @prop_fb_id: Default atomic plane property to specify the
2519 * &drm_framebuffer.
2520 */
2521 struct drm_property *prop_fb_id;
2522 /**
2523 * @prop_crtc_id: Default atomic plane property to specify the
2524 * &drm_crtc.
2525 */
2526 struct drm_property *prop_crtc_id;
2527 /**
2528 * @prop_active: Default atomic CRTC property to control the active
2529 * state, which is the simplified implementation for DPMS in atomic
2530 * drivers.
2531 */
2532 struct drm_property *prop_active;
2533 /**
2534 * @prop_mode_id: Default atomic CRTC property to set the mode for a
2535 * CRTC. A 0 mode implies that the CRTC is entirely disabled - all
2536 * connectors must be of and active must be set to disabled, too.
2537 */
2538 struct drm_property *prop_mode_id;
2539
2540 /**
2541 * @dvi_i_subconnector_property: Optional DVI-I property to
2542 * differentiate between analog or digital mode.
2543 */
2544 struct drm_property *dvi_i_subconnector_property;
2545 /**
2546 * @dvi_i_select_subconnector_property: Optional DVI-I property to
2547 * select between analog or digital mode.
2548 */
2549 struct drm_property *dvi_i_select_subconnector_property;
2550
2551 /**
2552 * @tv_subconnector_property: Optional TV property to differentiate
2553 * between different TV connector types.
2554 */
2555 struct drm_property *tv_subconnector_property;
2556 /**
2557 * @tv_select_subconnector_property: Optional TV property to select
2558 * between different TV connector types.
2559 */
2560 struct drm_property *tv_select_subconnector_property;
2561 /**
2562 * @tv_mode_property: Optional TV property to select
2563 * the output TV mode.
2564 */
2565 struct drm_property *tv_mode_property;
2566 /**
2567 * @tv_left_margin_property: Optional TV property to set the left
2568 * margin.
2569 */
2570 struct drm_property *tv_left_margin_property;
2571 /**
2572 * @tv_right_margin_property: Optional TV property to set the right
2573 * margin.
2574 */
2575 struct drm_property *tv_right_margin_property;
2576 /**
2577 * @tv_top_margin_property: Optional TV property to set the right
2578 * margin.
2579 */
2580 struct drm_property *tv_top_margin_property;
2581 /**
2582 * @tv_bottom_margin_property: Optional TV property to set the right
2583 * margin.
2584 */
2585 struct drm_property *tv_bottom_margin_property;
2586 /**
2587 * @tv_brightness_property: Optional TV property to set the
2588 * brightness.
2589 */
2590 struct drm_property *tv_brightness_property;
2591 /**
2592 * @tv_contrast_property: Optional TV property to set the
2593 * contrast.
2594 */
2595 struct drm_property *tv_contrast_property;
2596 /**
2597 * @tv_flicker_reduction_property: Optional TV property to control the
2598 * flicker reduction mode.
2599 */
2600 struct drm_property *tv_flicker_reduction_property;
2601 /**
2602 * @tv_overscan_property: Optional TV property to control the overscan
2603 * setting.
2604 */
2605 struct drm_property *tv_overscan_property;
2606 /**
2607 * @tv_saturation_property: Optional TV property to set the
2608 * saturation.
2609 */
2610 struct drm_property *tv_saturation_property;
2611 /**
2612 * @tv_hue_property: Optional TV property to set the hue.
2613 */
2614 struct drm_property *tv_hue_property;
2615
2616 /**
2617 * @scaling_mode_property: Optional connector property to control the
2618 * upscaling, mostly used for built-in panels.
2619 */
2620 struct drm_property *scaling_mode_property;
2621 /**
2622 * @aspect_ratio_property: Optional connector property to control the
2623 * HDMI infoframe aspect ratio setting.
2624 */
2625 struct drm_property *aspect_ratio_property;
2626 /**
2627 * @dirty_info_property: Optional connector property to give userspace a
2628 * hint that the DIRTY_FB ioctl should be used.
2629 */
2630 struct drm_property *dirty_info_property;
2631
2632 /**
2633 * @degamma_lut_property: Optional CRTC property to set the LUT used to
2634 * convert the framebuffer's colors to linear gamma.
2635 */
2636 struct drm_property *degamma_lut_property;
2637 /**
2638 * @degamma_lut_size_property: Optional CRTC property for the size of
2639 * the degamma LUT as supported by the driver (read-only).
2640 */
2641 struct drm_property *degamma_lut_size_property;
2642 /**
2643 * @ctm_property: Optional CRTC property to set the
2644 * matrix used to convert colors after the lookup in the
2645 * degamma LUT.
2646 */
2647 struct drm_property *ctm_property;
2648 /**
2649 * @gamma_lut_property: Optional CRTC property to set the LUT used to
2650 * convert the colors, after the CTM matrix, to the gamma space of the
2651 * connected screen.
2652 */
2653 struct drm_property *gamma_lut_property;
2654 /**
2655 * @gamma_lut_size_property: Optional CRTC property for the size of the
2656 * gamma LUT as supported by the driver (read-only).
2657 */
2658 struct drm_property *gamma_lut_size_property;
2659
2660 /**
2661 * @suggested_x_property: Optional connector property with a hint for
2662 * the position of the output on the host's screen.
2663 */
2664 struct drm_property *suggested_x_property;
2665 /**
2666 * @suggested_y_property: Optional connector property with a hint for
2667 * the position of the output on the host's screen.
2668 */
2669 struct drm_property *suggested_y_property;
2670
2671 /* dumb ioctl parameters */
2672 uint32_t preferred_depth, prefer_shadow;
2673
2674 /**
2675 * @async_page_flip: Does this device support async flips on the primary
2676 * plane?
2677 */
2678 bool async_page_flip;
2679
2680 /**
2681 * @allow_fb_modifiers:
2682 *
2683 * Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call.
2684 */
2685 bool allow_fb_modifiers;
2686
2687 /* cursor size */
2688 uint32_t cursor_width, cursor_height;
2689
2690 struct drm_mode_config_helper_funcs *helper_private;
2691 };
2692
2693 /**
2694 * drm_for_each_plane_mask - iterate over planes specified by bitmask
2695 * @plane: the loop cursor
2696 * @dev: the DRM device
2697 * @plane_mask: bitmask of plane indices
2698 *
2699 * Iterate over all planes specified by bitmask.
2700 */
2701 #define drm_for_each_plane_mask(plane, dev, plane_mask) \
2702 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
2703 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
2704
2705 /**
2706 * drm_for_each_encoder_mask - iterate over encoders specified by bitmask
2707 * @encoder: the loop cursor
2708 * @dev: the DRM device
2709 * @encoder_mask: bitmask of encoder indices
2710 *
2711 * Iterate over all encoders specified by bitmask.
2712 */
2713 #define drm_for_each_encoder_mask(encoder, dev, encoder_mask) \
2714 list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, head) \
2715 for_each_if ((encoder_mask) & (1 << drm_encoder_index(encoder)))
2716
2717 #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
2718 #define obj_to_connector(x) container_of(x, struct drm_connector, base)
2719 #define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
2720 #define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
2721 #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
2722 #define obj_to_property(x) container_of(x, struct drm_property, base)
2723 #define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
2724 #define obj_to_plane(x) container_of(x, struct drm_plane, base)
2725
2726 struct drm_prop_enum_list {
2727 int type;
2728 char *name;
2729 };
2730
2731 extern __printf(6, 7)
2732 int drm_crtc_init_with_planes(struct drm_device *dev,
2733 struct drm_crtc *crtc,
2734 struct drm_plane *primary,
2735 struct drm_plane *cursor,
2736 const struct drm_crtc_funcs *funcs,
2737 const char *name, ...);
2738 extern void drm_crtc_cleanup(struct drm_crtc *crtc);
2739
2740 /**
2741 * drm_crtc_index - find the index of a registered CRTC
2742 * @crtc: CRTC to find index for
2743 *
2744 * Given a registered CRTC, return the index of that CRTC within a DRM
2745 * device's list of CRTCs.
2746 */
2747 static inline unsigned int drm_crtc_index(struct drm_crtc *crtc)
2748 {
2749 return crtc->index;
2750 }
2751
2752 /**
2753 * drm_crtc_mask - find the mask of a registered CRTC
2754 * @crtc: CRTC to find mask for
2755 *
2756 * Given a registered CRTC, return the mask bit of that CRTC for an
2757 * encoder's possible_crtcs field.
2758 */
2759 static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
2760 {
2761 return 1 << drm_crtc_index(crtc);
2762 }
2763
2764 int drm_connector_init(struct drm_device *dev,
2765 struct drm_connector *connector,
2766 const struct drm_connector_funcs *funcs,
2767 int connector_type);
2768 int drm_connector_register(struct drm_connector *connector);
2769 void drm_connector_unregister(struct drm_connector *connector);
2770
2771 extern void drm_connector_cleanup(struct drm_connector *connector);
2772 static inline unsigned drm_connector_index(struct drm_connector *connector)
2773 {
2774 return connector->index;
2775 }
2776
2777 extern __printf(5, 6)
2778 int drm_encoder_init(struct drm_device *dev,
2779 struct drm_encoder *encoder,
2780 const struct drm_encoder_funcs *funcs,
2781 int encoder_type, const char *name, ...);
2782
2783 /**
2784 * drm_encoder_index - find the index of a registered encoder
2785 * @encoder: encoder to find index for
2786 *
2787 * Given a registered encoder, return the index of that encoder within a DRM
2788 * device's list of encoders.
2789 */
2790 static inline unsigned int drm_encoder_index(struct drm_encoder *encoder)
2791 {
2792 return encoder->index;
2793 }
2794
2795 /**
2796 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
2797 * @encoder: encoder to test
2798 * @crtc: crtc to test
2799 *
2800 * Return false if @encoder can't be driven by @crtc, true otherwise.
2801 */
2802 static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
2803 struct drm_crtc *crtc)
2804 {
2805 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
2806 }
2807
2808 extern __printf(8, 9)
2809 int drm_universal_plane_init(struct drm_device *dev,
2810 struct drm_plane *plane,
2811 unsigned long possible_crtcs,
2812 const struct drm_plane_funcs *funcs,
2813 const uint32_t *formats,
2814 unsigned int format_count,
2815 enum drm_plane_type type,
2816 const char *name, ...);
2817 extern int drm_plane_init(struct drm_device *dev,
2818 struct drm_plane *plane,
2819 unsigned long possible_crtcs,
2820 const struct drm_plane_funcs *funcs,
2821 const uint32_t *formats, unsigned int format_count,
2822 bool is_primary);
2823 extern void drm_plane_cleanup(struct drm_plane *plane);
2824
2825 /**
2826 * drm_plane_index - find the index of a registered plane
2827 * @plane: plane to find index for
2828 *
2829 * Given a registered plane, return the index of that plane within a DRM
2830 * device's list of planes.
2831 */
2832 static inline unsigned int drm_plane_index(struct drm_plane *plane)
2833 {
2834 return plane->index;
2835 }
2836 extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
2837 extern void drm_plane_force_disable(struct drm_plane *plane);
2838 extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
2839 int *hdisplay, int *vdisplay);
2840 extern int drm_crtc_force_disable(struct drm_crtc *crtc);
2841 extern int drm_crtc_force_disable_all(struct drm_device *dev);
2842
2843 extern void drm_encoder_cleanup(struct drm_encoder *encoder);
2844
2845 extern const char *drm_get_connector_status_name(enum drm_connector_status status);
2846 extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
2847 extern const char *drm_get_dpms_name(int val);
2848 extern const char *drm_get_dvi_i_subconnector_name(int val);
2849 extern const char *drm_get_dvi_i_select_name(int val);
2850 extern const char *drm_get_tv_subconnector_name(int val);
2851 extern const char *drm_get_tv_select_name(int val);
2852 extern void drm_mode_config_init(struct drm_device *dev);
2853 extern void drm_mode_config_reset(struct drm_device *dev);
2854 extern void drm_mode_config_cleanup(struct drm_device *dev);
2855
2856 extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
2857 const char *path);
2858 int drm_mode_connector_set_tile_property(struct drm_connector *connector);
2859 extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
2860 const struct edid *edid);
2861
2862 extern int drm_display_info_set_bus_formats(struct drm_display_info *info,
2863 const u32 *formats,
2864 unsigned int num_formats);
2865
2866 static inline bool drm_property_type_is(struct drm_property *property,
2867 uint32_t type)
2868 {
2869 /* instanceof for props.. handles extended type vs original types: */
2870 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2871 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
2872 return property->flags & type;
2873 }
2874
2875 extern int drm_object_property_set_value(struct drm_mode_object *obj,
2876 struct drm_property *property,
2877 uint64_t val);
2878 extern int drm_object_property_get_value(struct drm_mode_object *obj,
2879 struct drm_property *property,
2880 uint64_t *value);
2881 extern int drm_framebuffer_init(struct drm_device *dev,
2882 struct drm_framebuffer *fb,
2883 const struct drm_framebuffer_funcs *funcs);
2884 extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
2885 uint32_t id);
2886 extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
2887 extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
2888 extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
2889
2890 extern void drm_object_attach_property(struct drm_mode_object *obj,
2891 struct drm_property *property,
2892 uint64_t init_val);
2893 extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
2894 const char *name, int num_values);
2895 extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
2896 const char *name,
2897 const struct drm_prop_enum_list *props,
2898 int num_values);
2899 struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
2900 int flags, const char *name,
2901 const struct drm_prop_enum_list *props,
2902 int num_props,
2903 uint64_t supported_bits);
2904 struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
2905 const char *name,
2906 uint64_t min, uint64_t max);
2907 struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
2908 int flags, const char *name,
2909 int64_t min, int64_t max);
2910 struct drm_property *drm_property_create_object(struct drm_device *dev,
2911 int flags, const char *name, uint32_t type);
2912 struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags,
2913 const char *name);
2914 struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
2915 size_t length,
2916 const void *data);
2917 struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
2918 uint32_t id);
2919 struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
2920 void drm_property_unreference_blob(struct drm_property_blob *blob);
2921 extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
2922 extern int drm_property_add_enum(struct drm_property *property, int index,
2923 uint64_t value, const char *name);
2924 extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
2925 extern int drm_mode_create_tv_properties(struct drm_device *dev,
2926 unsigned int num_modes,
2927 const char * const modes[]);
2928 extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
2929 extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
2930 extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
2931 extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
2932
2933 extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
2934 struct drm_encoder *encoder);
2935 extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
2936 int gamma_size);
2937
2938 extern int drm_mode_set_config_internal(struct drm_mode_set *set);
2939
2940 extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
2941
2942 extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2943 char topology[8]);
2944 extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2945 char topology[8]);
2946 extern void drm_mode_put_tile_group(struct drm_device *dev,
2947 struct drm_tile_group *tg);
2948
2949 extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
2950 struct drm_property *property,
2951 uint64_t value);
2952
2953 extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
2954 unsigned int supported_rotations);
2955 extern unsigned int drm_rotation_simplify(unsigned int rotation,
2956 unsigned int supported_rotations);
2957 extern void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
2958 uint degamma_lut_size,
2959 bool has_ctm,
2960 uint gamma_lut_size);
2961 /* Helpers */
2962 struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
2963 uint32_t id, uint32_t type);
2964 void drm_mode_object_reference(struct drm_mode_object *obj);
2965 void drm_mode_object_unreference(struct drm_mode_object *obj);
2966
2967 static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
2968 uint32_t id)
2969 {
2970 struct drm_mode_object *mo;
2971 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
2972 return mo ? obj_to_plane(mo) : NULL;
2973 }
2974
2975 static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
2976 uint32_t id)
2977 {
2978 struct drm_mode_object *mo;
2979 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
2980 return mo ? obj_to_crtc(mo) : NULL;
2981 }
2982
2983 static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
2984 uint32_t id)
2985 {
2986 struct drm_mode_object *mo;
2987 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
2988 return mo ? obj_to_encoder(mo) : NULL;
2989 }
2990
2991 /**
2992 * drm_connector_lookup - lookup connector object
2993 * @dev: DRM device
2994 * @id: connector object id
2995 *
2996 * This function looks up the connector object specified by id
2997 * add takes a reference to it.
2998 */
2999 static inline struct drm_connector *drm_connector_lookup(struct drm_device *dev,
3000 uint32_t id)
3001 {
3002 struct drm_mode_object *mo;
3003 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
3004 return mo ? obj_to_connector(mo) : NULL;
3005 }
3006
3007 static inline struct drm_property *drm_property_find(struct drm_device *dev,
3008 uint32_t id)
3009 {
3010 struct drm_mode_object *mo;
3011 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
3012 return mo ? obj_to_property(mo) : NULL;
3013 }
3014
3015 /*
3016 * Extract a degamma/gamma LUT value provided by user and round it to the
3017 * precision supported by the hardware.
3018 */
3019 static inline uint32_t drm_color_lut_extract(uint32_t user_input,
3020 uint32_t bit_precision)
3021 {
3022 uint32_t val = user_input;
3023 uint32_t max = 0xffff >> (16 - bit_precision);
3024
3025 /* Round only if we're not using full precision. */
3026 if (bit_precision < 16) {
3027 val += 1UL << (16 - bit_precision - 1);
3028 val >>= 16 - bit_precision;
3029 }
3030
3031 return clamp_val(val, 0, max);
3032 }
3033
3034 /**
3035 * drm_framebuffer_reference - incr the fb refcnt
3036 * @fb: framebuffer
3037 *
3038 * This functions increments the fb's refcount.
3039 */
3040 static inline void drm_framebuffer_reference(struct drm_framebuffer *fb)
3041 {
3042 drm_mode_object_reference(&fb->base);
3043 }
3044
3045 /**
3046 * drm_framebuffer_unreference - unref a framebuffer
3047 * @fb: framebuffer to unref
3048 *
3049 * This functions decrements the fb's refcount and frees it if it drops to zero.
3050 */
3051 static inline void drm_framebuffer_unreference(struct drm_framebuffer *fb)
3052 {
3053 drm_mode_object_unreference(&fb->base);
3054 }
3055
3056 /**
3057 * drm_framebuffer_read_refcount - read the framebuffer reference count.
3058 * @fb: framebuffer
3059 *
3060 * This functions returns the framebuffer's reference count.
3061 */
3062 static inline uint32_t drm_framebuffer_read_refcount(struct drm_framebuffer *fb)
3063 {
3064 return atomic_read(&fb->base.refcount.refcount);
3065 }
3066
3067 /**
3068 * drm_connector_reference - incr the connector refcnt
3069 * @connector: connector
3070 *
3071 * This function increments the connector's refcount.
3072 */
3073 static inline void drm_connector_reference(struct drm_connector *connector)
3074 {
3075 drm_mode_object_reference(&connector->base);
3076 }
3077
3078 /**
3079 * drm_connector_unreference - unref a connector
3080 * @connector: connector to unref
3081 *
3082 * This function decrements the connector's refcount and frees it if it drops to zero.
3083 */
3084 static inline void drm_connector_unreference(struct drm_connector *connector)
3085 {
3086 drm_mode_object_unreference(&connector->base);
3087 }
3088
3089 /* Plane list iterator for legacy (overlay only) planes. */
3090 #define drm_for_each_legacy_plane(plane, dev) \
3091 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
3092 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
3093
3094 #define drm_for_each_plane(plane, dev) \
3095 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
3096
3097 #define drm_for_each_crtc(crtc, dev) \
3098 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
3099
3100 static inline void
3101 assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
3102 {
3103 /*
3104 * The connector hotadd/remove code currently grabs both locks when
3105 * updating lists. Hence readers need only hold either of them to be
3106 * safe and the check amounts to
3107 *
3108 * WARN_ON(not_holding(A) && not_holding(B)).
3109 */
3110 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
3111 !drm_modeset_is_locked(&mode_config->connection_mutex));
3112 }
3113
3114 #define drm_for_each_connector(connector, dev) \
3115 for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \
3116 connector = list_first_entry(&(dev)->mode_config.connector_list, \
3117 struct drm_connector, head); \
3118 &connector->head != (&(dev)->mode_config.connector_list); \
3119 connector = list_next_entry(connector, head))
3120
3121 #define drm_for_each_encoder(encoder, dev) \
3122 list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
3123
3124 #define drm_for_each_fb(fb, dev) \
3125 for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \
3126 fb = list_first_entry(&(dev)->mode_config.fb_list, \
3127 struct drm_framebuffer, head); \
3128 &fb->head != (&(dev)->mode_config.fb_list); \
3129 fb = list_next_entry(fb, head))
3130
3131 /* drm_edid.c */
3132 bool drm_probe_ddc(struct i2c_adapter *adapter);
3133 struct edid *drm_get_edid(struct drm_connector *connector,
3134 struct i2c_adapter *adapter);
3135 struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
3136 struct i2c_adapter *adapter);
3137 struct edid *drm_edid_duplicate(const struct edid *edid);
3138 int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
3139
3140 u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
3141 enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
3142 bool drm_detect_hdmi_monitor(struct edid *edid);
3143 bool drm_detect_monitor_audio(struct edid *edid);
3144 bool drm_rgb_quant_range_selectable(struct edid *edid);
3145 int drm_add_modes_noedid(struct drm_connector *connector,
3146 int hdisplay, int vdisplay);
3147 void drm_set_preferred_mode(struct drm_connector *connector,
3148 int hpref, int vpref);
3149
3150 int drm_edid_header_is_valid(const u8 *raw_edid);
3151 bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
3152 bool *edid_corrupt);
3153 bool drm_edid_is_valid(struct edid *edid);
3154 void drm_edid_get_monitor_name(struct edid *edid, char *name,
3155 int buflen);
3156 struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
3157 int hsize, int vsize, int fresh,
3158 bool rb);
3159
3160 /* drm_bridge.c */
3161 extern int drm_bridge_add(struct drm_bridge *bridge);
3162 extern void drm_bridge_remove(struct drm_bridge *bridge);
3163 extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
3164 extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
3165
3166 bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
3167 const struct drm_display_mode *mode,
3168 struct drm_display_mode *adjusted_mode);
3169 void drm_bridge_disable(struct drm_bridge *bridge);
3170 void drm_bridge_post_disable(struct drm_bridge *bridge);
3171 void drm_bridge_mode_set(struct drm_bridge *bridge,
3172 struct drm_display_mode *mode,
3173 struct drm_display_mode *adjusted_mode);
3174 void drm_bridge_pre_enable(struct drm_bridge *bridge);
3175 void drm_bridge_enable(struct drm_bridge *bridge);
3176
3177 #endif /* __DRM_CRTC_H__ */
This page took 0.163711 seconds and 6 git commands to generate.