acpi, nfit: fix health event notification
[linux/fpc-iii.git] / include / drm / drm_crtc.h
blob0aa292526567abd211b688641178af5ce5bff8a0
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>
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:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
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.
25 #ifndef __DRM_CRTC_H__
26 #define __DRM_CRTC_H__
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 #include <drm/drm_rect.h>
39 #include <drm/drm_mode_object.h>
40 #include <drm/drm_framebuffer.h>
41 #include <drm/drm_modes.h>
42 #include <drm/drm_connector.h>
43 #include <drm/drm_encoder.h>
44 #include <drm/drm_property.h>
45 #include <drm/drm_bridge.h>
46 #include <drm/drm_edid.h>
47 #include <drm/drm_plane.h>
48 #include <drm/drm_blend.h>
49 #include <drm/drm_color_mgmt.h>
51 struct drm_device;
52 struct drm_mode_set;
53 struct drm_file;
54 struct drm_clip_rect;
55 struct device_node;
56 struct fence;
57 struct edid;
59 static inline int64_t U642I64(uint64_t val)
61 return (int64_t)*((int64_t *)&val);
63 static inline uint64_t I642U64(int64_t val)
65 return (uint64_t)*((uint64_t *)&val);
68 /* data corresponds to displayid vend/prod/serial */
69 struct drm_tile_group {
70 struct kref refcount;
71 struct drm_device *dev;
72 int id;
73 u8 group_data[8];
76 struct drm_crtc;
77 struct drm_encoder;
78 struct drm_pending_vblank_event;
79 struct drm_plane;
80 struct drm_bridge;
81 struct drm_atomic_state;
83 struct drm_crtc_helper_funcs;
84 struct drm_encoder_helper_funcs;
85 struct drm_plane_helper_funcs;
87 /**
88 * struct drm_crtc_state - mutable CRTC state
89 * @crtc: backpointer to the CRTC
90 * @enable: whether the CRTC should be enabled, gates all other state
91 * @active: whether the CRTC is actively displaying (used for DPMS)
92 * @planes_changed: planes on this crtc are updated
93 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
94 * @active_changed: crtc_state->active has been toggled.
95 * @connectors_changed: connectors to this crtc have been updated
96 * @zpos_changed: zpos values of planes on this crtc have been updated
97 * @color_mgmt_changed: color management properties have changed (degamma or
98 * gamma LUT or CSC matrix)
99 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
100 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
101 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
102 * @last_vblank_count: for helpers and drivers to capture the vblank of the
103 * update to ensure framebuffer cleanup isn't done too early
104 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
105 * @mode: current mode timings
106 * @mode_blob: &drm_property_blob for @mode
107 * @degamma_lut: Lookup table for converting framebuffer pixel data
108 * before apply the conversion matrix
109 * @ctm: Transformation matrix
110 * @gamma_lut: Lookup table for converting pixel data after the
111 * conversion matrix
112 * @state: backpointer to global drm_atomic_state
114 * Note that the distinction between @enable and @active is rather subtile:
115 * Flipping @active while @enable is set without changing anything else may
116 * never return in a failure from the ->atomic_check callback. Userspace assumes
117 * that a DPMS On will always succeed. In other words: @enable controls resource
118 * assignment, @active controls the actual hardware state.
120 struct drm_crtc_state {
121 struct drm_crtc *crtc;
123 bool enable;
124 bool active;
126 /* computed state bits used by helpers and drivers */
127 bool planes_changed : 1;
128 bool mode_changed : 1;
129 bool active_changed : 1;
130 bool connectors_changed : 1;
131 bool zpos_changed : 1;
132 bool color_mgmt_changed : 1;
134 /* attached planes bitmask:
135 * WARNING: transitional helpers do not maintain plane_mask so
136 * drivers not converted over to atomic helpers should not rely
137 * on plane_mask being accurate!
139 u32 plane_mask;
141 u32 connector_mask;
142 u32 encoder_mask;
144 /* last_vblank_count: for vblank waits before cleanup */
145 u32 last_vblank_count;
147 /* adjusted_mode: for use by helpers and drivers */
148 struct drm_display_mode adjusted_mode;
150 struct drm_display_mode mode;
152 /* blob property to expose current mode to atomic userspace */
153 struct drm_property_blob *mode_blob;
155 /* blob property to expose color management to userspace */
156 struct drm_property_blob *degamma_lut;
157 struct drm_property_blob *ctm;
158 struct drm_property_blob *gamma_lut;
161 * @event:
163 * Optional pointer to a DRM event to signal upon completion of the
164 * state update. The driver must send out the event when the atomic
165 * commit operation completes. There are two cases:
167 * - The event is for a CRTC which is being disabled through this
168 * atomic commit. In that case the event can be send out any time
169 * after the hardware has stopped scanning out the current
170 * framebuffers. It should contain the timestamp and counter for the
171 * last vblank before the display pipeline was shut off.
173 * - For a CRTC which is enabled at the end of the commit (even when it
174 * undergoes an full modeset) the vblank timestamp and counter must
175 * be for the vblank right before the first frame that scans out the
176 * new set of buffers. Again the event can only be sent out after the
177 * hardware has stopped scanning out the old buffers.
179 * - Events for disabled CRTCs are not allowed, and drivers can ignore
180 * that case.
182 * This can be handled by the drm_crtc_send_vblank_event() function,
183 * which the driver should call on the provided event upon completion of
184 * the atomic commit. Note that if the driver supports vblank signalling
185 * and timestamping the vblank counters and timestamps must agree with
186 * the ones returned from page flip events. With the current vblank
187 * helper infrastructure this can be achieved by holding a vblank
188 * reference while the page flip is pending, acquired through
189 * drm_crtc_vblank_get() and released with drm_crtc_vblank_put().
190 * Drivers are free to implement their own vblank counter and timestamp
191 * tracking though, e.g. if they have accurate timestamp registers in
192 * hardware.
194 * For hardware which supports some means to synchronize vblank
195 * interrupt delivery with committing display state there's also
196 * drm_crtc_arm_vblank_event(). See the documentation of that function
197 * for a detailed discussion of the constraints it needs to be used
198 * safely.
200 struct drm_pending_vblank_event *event;
202 struct drm_atomic_state *state;
206 * struct drm_crtc_funcs - control CRTCs for a given device
208 * The drm_crtc_funcs structure is the central CRTC management structure
209 * in the DRM. Each CRTC controls one or more connectors (note that the name
210 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
211 * connectors, not just CRTs).
213 * Each driver is responsible for filling out this structure at startup time,
214 * in addition to providing other modesetting features, like i2c and DDC
215 * bus accessors.
217 struct drm_crtc_funcs {
219 * @reset:
221 * Reset CRTC hardware and software state to off. This function isn't
222 * called by the core directly, only through drm_mode_config_reset().
223 * It's not a helper hook only for historical reasons.
225 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
226 * atomic state using this hook.
228 void (*reset)(struct drm_crtc *crtc);
231 * @cursor_set:
233 * Update the cursor image. The cursor position is relative to the CRTC
234 * and can be partially or fully outside of the visible area.
236 * Note that contrary to all other KMS functions the legacy cursor entry
237 * points don't take a framebuffer object, but instead take directly a
238 * raw buffer object id from the driver's buffer manager (which is
239 * either GEM or TTM for current drivers).
241 * This entry point is deprecated, drivers should instead implement
242 * universal plane support and register a proper cursor plane using
243 * drm_crtc_init_with_planes().
245 * This callback is optional
247 * RETURNS:
249 * 0 on success or a negative error code on failure.
251 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
252 uint32_t handle, uint32_t width, uint32_t height);
255 * @cursor_set2:
257 * Update the cursor image, including hotspot information. The hotspot
258 * must not affect the cursor position in CRTC coordinates, but is only
259 * meant as a hint for virtualized display hardware to coordinate the
260 * guests and hosts cursor position. The cursor hotspot is relative to
261 * the cursor image. Otherwise this works exactly like @cursor_set.
263 * This entry point is deprecated, drivers should instead implement
264 * universal plane support and register a proper cursor plane using
265 * drm_crtc_init_with_planes().
267 * This callback is optional.
269 * RETURNS:
271 * 0 on success or a negative error code on failure.
273 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
274 uint32_t handle, uint32_t width, uint32_t height,
275 int32_t hot_x, int32_t hot_y);
278 * @cursor_move:
280 * Update the cursor position. The cursor does not need to be visible
281 * when this hook is called.
283 * This entry point is deprecated, drivers should instead implement
284 * universal plane support and register a proper cursor plane using
285 * drm_crtc_init_with_planes().
287 * This callback is optional.
289 * RETURNS:
291 * 0 on success or a negative error code on failure.
293 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
296 * @gamma_set:
298 * Set gamma on the CRTC.
300 * This callback is optional.
302 * NOTE:
304 * Drivers that support gamma tables and also fbdev emulation through
305 * the provided helper library need to take care to fill out the gamma
306 * hooks for both. Currently there's a bit an unfortunate duplication
307 * going on, which should eventually be unified to just one set of
308 * hooks.
310 int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
311 uint32_t size);
314 * @destroy:
316 * Clean up plane resources. This is only called at driver unload time
317 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
318 * in DRM.
320 void (*destroy)(struct drm_crtc *crtc);
323 * @set_config:
325 * This is the main legacy entry point to change the modeset state on a
326 * CRTC. All the details of the desired configuration are passed in a
327 * struct &drm_mode_set - see there for details.
329 * Drivers implementing atomic modeset should use
330 * drm_atomic_helper_set_config() to implement this hook.
332 * RETURNS:
334 * 0 on success or a negative error code on failure.
336 int (*set_config)(struct drm_mode_set *set);
339 * @page_flip:
341 * Legacy entry point to schedule a flip to the given framebuffer.
343 * Page flipping is a synchronization mechanism that replaces the frame
344 * buffer being scanned out by the CRTC with a new frame buffer during
345 * vertical blanking, avoiding tearing (except when requested otherwise
346 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
347 * requests a page flip the DRM core verifies that the new frame buffer
348 * is large enough to be scanned out by the CRTC in the currently
349 * configured mode and then calls the CRTC ->page_flip() operation with a
350 * pointer to the new frame buffer.
352 * The driver must wait for any pending rendering to the new framebuffer
353 * to complete before executing the flip. It should also wait for any
354 * pending rendering from other drivers if the underlying buffer is a
355 * shared dma-buf.
357 * An application can request to be notified when the page flip has
358 * completed. The drm core will supply a struct &drm_event in the event
359 * parameter in this case. This can be handled by the
360 * drm_crtc_send_vblank_event() function, which the driver should call on
361 * the provided event upon completion of the flip. Note that if
362 * the driver supports vblank signalling and timestamping the vblank
363 * counters and timestamps must agree with the ones returned from page
364 * flip events. With the current vblank helper infrastructure this can
365 * be achieved by holding a vblank reference while the page flip is
366 * pending, acquired through drm_crtc_vblank_get() and released with
367 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
368 * counter and timestamp tracking though, e.g. if they have accurate
369 * timestamp registers in hardware.
371 * This callback is optional.
373 * NOTE:
375 * Very early versions of the KMS ABI mandated that the driver must
376 * block (but not reject) any rendering to the old framebuffer until the
377 * flip operation has completed and the old framebuffer is no longer
378 * visible. This requirement has been lifted, and userspace is instead
379 * expected to request delivery of an event and wait with recycling old
380 * buffers until such has been received.
382 * RETURNS:
384 * 0 on success or a negative error code on failure. Note that if a
385 * ->page_flip() operation is already pending the callback should return
386 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
387 * or just runtime disabled through DPMS respectively the new atomic
388 * "ACTIVE" state) should result in an -EINVAL error code. Note that
389 * drm_atomic_helper_page_flip() checks this already for atomic drivers.
391 int (*page_flip)(struct drm_crtc *crtc,
392 struct drm_framebuffer *fb,
393 struct drm_pending_vblank_event *event,
394 uint32_t flags);
397 * @page_flip_target:
399 * Same as @page_flip but with an additional parameter specifying the
400 * absolute target vertical blank period (as reported by
401 * drm_crtc_vblank_count()) when the flip should take effect.
403 * Note that the core code calls drm_crtc_vblank_get before this entry
404 * point, and will call drm_crtc_vblank_put if this entry point returns
405 * any non-0 error code. It's the driver's responsibility to call
406 * drm_crtc_vblank_put after this entry point returns 0, typically when
407 * the flip completes.
409 int (*page_flip_target)(struct drm_crtc *crtc,
410 struct drm_framebuffer *fb,
411 struct drm_pending_vblank_event *event,
412 uint32_t flags, uint32_t target);
415 * @set_property:
417 * This is the legacy entry point to update a property attached to the
418 * CRTC.
420 * Drivers implementing atomic modeset should use
421 * drm_atomic_helper_crtc_set_property() to implement this hook.
423 * This callback is optional if the driver does not support any legacy
424 * driver-private properties.
426 * RETURNS:
428 * 0 on success or a negative error code on failure.
430 int (*set_property)(struct drm_crtc *crtc,
431 struct drm_property *property, uint64_t val);
434 * @atomic_duplicate_state:
436 * Duplicate the current atomic state for this CRTC and return it.
437 * The core and helpers gurantee that any atomic state duplicated with
438 * this hook and still owned by the caller (i.e. not transferred to the
439 * driver by calling ->atomic_commit() from struct
440 * &drm_mode_config_funcs) will be cleaned up by calling the
441 * @atomic_destroy_state hook in this structure.
443 * Atomic drivers which don't subclass struct &drm_crtc should use
444 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
445 * state structure to extend it with driver-private state should use
446 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
447 * duplicated in a consistent fashion across drivers.
449 * It is an error to call this hook before crtc->state has been
450 * initialized correctly.
452 * NOTE:
454 * If the duplicate state references refcounted resources this hook must
455 * acquire a reference for each of them. The driver must release these
456 * references again in @atomic_destroy_state.
458 * RETURNS:
460 * Duplicated atomic state or NULL when the allocation failed.
462 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
465 * @atomic_destroy_state:
467 * Destroy a state duplicated with @atomic_duplicate_state and release
468 * or unreference all resources it references
470 void (*atomic_destroy_state)(struct drm_crtc *crtc,
471 struct drm_crtc_state *state);
474 * @atomic_set_property:
476 * Decode a driver-private property value and store the decoded value
477 * into the passed-in state structure. Since the atomic core decodes all
478 * standardized properties (even for extensions beyond the core set of
479 * properties which might not be implemented by all drivers) this
480 * requires drivers to subclass the state structure.
482 * Such driver-private properties should really only be implemented for
483 * truly hardware/vendor specific state. Instead it is preferred to
484 * standardize atomic extension and decode the properties used to expose
485 * such an extension in the core.
487 * Do not call this function directly, use
488 * drm_atomic_crtc_set_property() instead.
490 * This callback is optional if the driver does not support any
491 * driver-private atomic properties.
493 * NOTE:
495 * This function is called in the state assembly phase of atomic
496 * modesets, which can be aborted for any reason (including on
497 * userspace's request to just check whether a configuration would be
498 * possible). Drivers MUST NOT touch any persistent state (hardware or
499 * software) or data structures except the passed in @state parameter.
501 * Also since userspace controls in which order properties are set this
502 * function must not do any input validation (since the state update is
503 * incomplete and hence likely inconsistent). Instead any such input
504 * validation must be done in the various atomic_check callbacks.
506 * RETURNS:
508 * 0 if the property has been found, -EINVAL if the property isn't
509 * implemented by the driver (which should never happen, the core only
510 * asks for properties attached to this CRTC). No other validation is
511 * allowed by the driver. The core already checks that the property
512 * value is within the range (integer, valid enum value, ...) the driver
513 * set when registering the property.
515 int (*atomic_set_property)(struct drm_crtc *crtc,
516 struct drm_crtc_state *state,
517 struct drm_property *property,
518 uint64_t val);
520 * @atomic_get_property:
522 * Reads out the decoded driver-private property. This is used to
523 * implement the GETCRTC IOCTL.
525 * Do not call this function directly, use
526 * drm_atomic_crtc_get_property() instead.
528 * This callback is optional if the driver does not support any
529 * driver-private atomic properties.
531 * RETURNS:
533 * 0 on success, -EINVAL if the property isn't implemented by the
534 * driver (which should never happen, the core only asks for
535 * properties attached to this CRTC).
537 int (*atomic_get_property)(struct drm_crtc *crtc,
538 const struct drm_crtc_state *state,
539 struct drm_property *property,
540 uint64_t *val);
543 * @late_register:
545 * This optional hook can be used to register additional userspace
546 * interfaces attached to the crtc like debugfs interfaces.
547 * It is called late in the driver load sequence from drm_dev_register().
548 * Everything added from this callback should be unregistered in
549 * the early_unregister callback.
551 * Returns:
553 * 0 on success, or a negative error code on failure.
555 int (*late_register)(struct drm_crtc *crtc);
558 * @early_unregister:
560 * This optional hook should be used to unregister the additional
561 * userspace interfaces attached to the crtc from
562 * late_unregister(). It is called from drm_dev_unregister(),
563 * early in the driver unload sequence to disable userspace access
564 * before data structures are torndown.
566 void (*early_unregister)(struct drm_crtc *crtc);
570 * struct drm_crtc - central CRTC control structure
571 * @dev: parent DRM device
572 * @port: OF node used by drm_of_find_possible_crtcs()
573 * @head: list management
574 * @name: human readable name, can be overwritten by the driver
575 * @mutex: per-CRTC locking
576 * @base: base KMS object for ID tracking etc.
577 * @primary: primary plane for this CRTC
578 * @cursor: cursor plane for this CRTC
579 * @cursor_x: current x position of the cursor, used for universal cursor planes
580 * @cursor_y: current y position of the cursor, used for universal cursor planes
581 * @enabled: is this CRTC enabled?
582 * @mode: current mode timings
583 * @hwmode: mode timings as programmed to hw regs
584 * @x: x position on screen
585 * @y: y position on screen
586 * @funcs: CRTC control functions
587 * @gamma_size: size of gamma ramp
588 * @gamma_store: gamma ramp values
589 * @helper_private: mid-layer private data
590 * @properties: property tracking for this CRTC
592 * Each CRTC may have one or more connectors associated with it. This structure
593 * allows the CRTC to be controlled.
595 struct drm_crtc {
596 struct drm_device *dev;
597 struct device_node *port;
598 struct list_head head;
600 char *name;
603 * @mutex:
605 * This provides a read lock for the overall crtc state (mode, dpms
606 * state, ...) and a write lock for everything which can be update
607 * without a full modeset (fb, cursor data, crtc properties ...). Full
608 * modeset also need to grab dev->mode_config.connection_mutex.
610 struct drm_modeset_lock mutex;
612 struct drm_mode_object base;
614 /* primary and cursor planes for CRTC */
615 struct drm_plane *primary;
616 struct drm_plane *cursor;
619 * @index: Position inside the mode_config.list, can be used as an array
620 * index. It is invariant over the lifetime of the CRTC.
622 unsigned index;
624 /* position of cursor plane on crtc */
625 int cursor_x;
626 int cursor_y;
628 bool enabled;
630 /* Requested mode from modesetting. */
631 struct drm_display_mode mode;
633 /* Programmed mode in hw, after adjustments for encoders,
634 * crtc, panel scaling etc. Needed for timestamping etc.
636 struct drm_display_mode hwmode;
638 int x, y;
639 const struct drm_crtc_funcs *funcs;
641 /* Legacy FB CRTC gamma size for reporting to userspace */
642 uint32_t gamma_size;
643 uint16_t *gamma_store;
645 /* if you are using the helper */
646 const struct drm_crtc_helper_funcs *helper_private;
648 struct drm_object_properties properties;
651 * @state:
653 * Current atomic state for this CRTC.
655 struct drm_crtc_state *state;
658 * @commit_list:
660 * List of &drm_crtc_commit structures tracking pending commits.
661 * Protected by @commit_lock. This list doesn't hold its own full
662 * reference, but burrows it from the ongoing commit. Commit entries
663 * must be removed from this list once the commit is fully completed,
664 * but before it's correspoding &drm_atomic_state gets destroyed.
666 struct list_head commit_list;
669 * @commit_lock:
671 * Spinlock to protect @commit_list.
673 spinlock_t commit_lock;
676 * @acquire_ctx:
678 * Per-CRTC implicit acquire context used by atomic drivers for legacy
679 * IOCTLs, so that atomic drivers can get at the locking acquire
680 * context.
682 struct drm_modeset_acquire_ctx *acquire_ctx;
686 * struct drm_mode_set - new values for a CRTC config change
687 * @fb: framebuffer to use for new config
688 * @crtc: CRTC whose configuration we're about to change
689 * @mode: mode timings to use
690 * @x: position of this CRTC relative to @fb
691 * @y: position of this CRTC relative to @fb
692 * @connectors: array of connectors to drive with this CRTC if possible
693 * @num_connectors: size of @connectors array
695 * Represents a single crtc the connectors that it drives with what mode
696 * and from which framebuffer it scans out from.
698 * This is used to set modes.
700 struct drm_mode_set {
701 struct drm_framebuffer *fb;
702 struct drm_crtc *crtc;
703 struct drm_display_mode *mode;
705 uint32_t x;
706 uint32_t y;
708 struct drm_connector **connectors;
709 size_t num_connectors;
713 * struct drm_mode_config_funcs - basic driver provided mode setting functions
715 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
716 * involve drivers.
718 struct drm_mode_config_funcs {
720 * @fb_create:
722 * Create a new framebuffer object. The core does basic checks on the
723 * requested metadata, but most of that is left to the driver. See
724 * struct &drm_mode_fb_cmd2 for details.
726 * If the parameters are deemed valid and the backing storage objects in
727 * the underlying memory manager all exist, then the driver allocates
728 * a new &drm_framebuffer structure, subclassed to contain
729 * driver-specific information (like the internal native buffer object
730 * references). It also needs to fill out all relevant metadata, which
731 * should be done by calling drm_helper_mode_fill_fb_struct().
733 * The initialization is finalized by calling drm_framebuffer_init(),
734 * which registers the framebuffer and makes it accessible to other
735 * threads.
737 * RETURNS:
739 * A new framebuffer with an initial reference count of 1 or a negative
740 * error code encoded with ERR_PTR().
742 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
743 struct drm_file *file_priv,
744 const struct drm_mode_fb_cmd2 *mode_cmd);
747 * @output_poll_changed:
749 * Callback used by helpers to inform the driver of output configuration
750 * changes.
752 * Drivers implementing fbdev emulation with the helpers can call
753 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
754 * helper of output changes.
756 * FIXME:
758 * Except that there's no vtable for device-level helper callbacks
759 * there's no reason this is a core function.
761 void (*output_poll_changed)(struct drm_device *dev);
764 * @atomic_check:
766 * This is the only hook to validate an atomic modeset update. This
767 * function must reject any modeset and state changes which the hardware
768 * or driver doesn't support. This includes but is of course not limited
769 * to:
771 * - Checking that the modes, framebuffers, scaling and placement
772 * requirements and so on are within the limits of the hardware.
774 * - Checking that any hidden shared resources are not oversubscribed.
775 * This can be shared PLLs, shared lanes, overall memory bandwidth,
776 * display fifo space (where shared between planes or maybe even
777 * CRTCs).
779 * - Checking that virtualized resources exported to userspace are not
780 * oversubscribed. For various reasons it can make sense to expose
781 * more planes, crtcs or encoders than which are physically there. One
782 * example is dual-pipe operations (which generally should be hidden
783 * from userspace if when lockstepped in hardware, exposed otherwise),
784 * where a plane might need 1 hardware plane (if it's just on one
785 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
786 * shared a hardware plane with a 2nd plane (if there's a compatible
787 * plane requested on the area handled by the other pipe).
789 * - Check that any transitional state is possible and that if
790 * requested, the update can indeed be done in the vblank period
791 * without temporarily disabling some functions.
793 * - Check any other constraints the driver or hardware might have.
795 * - This callback also needs to correctly fill out the &drm_crtc_state
796 * in this update to make sure that drm_atomic_crtc_needs_modeset()
797 * reflects the nature of the possible update and returns true if and
798 * only if the update cannot be applied without tearing within one
799 * vblank on that CRTC. The core uses that information to reject
800 * updates which require a full modeset (i.e. blanking the screen, or
801 * at least pausing updates for a substantial amount of time) if
802 * userspace has disallowed that in its request.
804 * - The driver also does not need to repeat basic input validation
805 * like done for the corresponding legacy entry points. The core does
806 * that before calling this hook.
808 * See the documentation of @atomic_commit for an exhaustive list of
809 * error conditions which don't have to be checked at the
810 * ->atomic_check() stage?
812 * See the documentation for struct &drm_atomic_state for how exactly
813 * an atomic modeset update is described.
815 * Drivers using the atomic helpers can implement this hook using
816 * drm_atomic_helper_check(), or one of the exported sub-functions of
817 * it.
819 * RETURNS:
821 * 0 on success or one of the below negative error codes:
823 * - -EINVAL, if any of the above constraints are violated.
825 * - -EDEADLK, when returned from an attempt to acquire an additional
826 * &drm_modeset_lock through drm_modeset_lock().
828 * - -ENOMEM, if allocating additional state sub-structures failed due
829 * to lack of memory.
831 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
832 * This can either be due to a pending signal, or because the driver
833 * needs to completely bail out to recover from an exceptional
834 * situation like a GPU hang. From a userspace point all errors are
835 * treated equally.
837 int (*atomic_check)(struct drm_device *dev,
838 struct drm_atomic_state *state);
841 * @atomic_commit:
843 * This is the only hook to commit an atomic modeset update. The core
844 * guarantees that @atomic_check has been called successfully before
845 * calling this function, and that nothing has been changed in the
846 * interim.
848 * See the documentation for struct &drm_atomic_state for how exactly
849 * an atomic modeset update is described.
851 * Drivers using the atomic helpers can implement this hook using
852 * drm_atomic_helper_commit(), or one of the exported sub-functions of
853 * it.
855 * Nonblocking commits (as indicated with the nonblock parameter) must
856 * do any preparatory work which might result in an unsuccessful commit
857 * in the context of this callback. The only exceptions are hardware
858 * errors resulting in -EIO. But even in that case the driver must
859 * ensure that the display pipe is at least running, to avoid
860 * compositors crashing when pageflips don't work. Anything else,
861 * specifically committing the update to the hardware, should be done
862 * without blocking the caller. For updates which do not require a
863 * modeset this must be guaranteed.
865 * The driver must wait for any pending rendering to the new
866 * framebuffers to complete before executing the flip. It should also
867 * wait for any pending rendering from other drivers if the underlying
868 * buffer is a shared dma-buf. Nonblocking commits must not wait for
869 * rendering in the context of this callback.
871 * An application can request to be notified when the atomic commit has
872 * completed. These events are per-CRTC and can be distinguished by the
873 * CRTC index supplied in &drm_event to userspace.
875 * The drm core will supply a struct &drm_event in the event
876 * member of each CRTC's &drm_crtc_state structure. See the
877 * documentation for &drm_crtc_state for more details about the precise
878 * semantics of this event.
880 * NOTE:
882 * Drivers are not allowed to shut down any display pipe successfully
883 * enabled through an atomic commit on their own. Doing so can result in
884 * compositors crashing if a page flip is suddenly rejected because the
885 * pipe is off.
887 * RETURNS:
889 * 0 on success or one of the below negative error codes:
891 * - -EBUSY, if a nonblocking updated is requested and there is
892 * an earlier updated pending. Drivers are allowed to support a queue
893 * of outstanding updates, but currently no driver supports that.
894 * Note that drivers must wait for preceding updates to complete if a
895 * synchronous update is requested, they are not allowed to fail the
896 * commit in that case.
898 * - -ENOMEM, if the driver failed to allocate memory. Specifically
899 * this can happen when trying to pin framebuffers, which must only
900 * be done when committing the state.
902 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
903 * that the driver has run out of vram, iommu space or similar GPU
904 * address space needed for framebuffer.
906 * - -EIO, if the hardware completely died.
908 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
909 * This can either be due to a pending signal, or because the driver
910 * needs to completely bail out to recover from an exceptional
911 * situation like a GPU hang. From a userspace point of view all errors are
912 * treated equally.
914 * This list is exhaustive. Specifically this hook is not allowed to
915 * return -EINVAL (any invalid requests should be caught in
916 * @atomic_check) or -EDEADLK (this function must not acquire
917 * additional modeset locks).
919 int (*atomic_commit)(struct drm_device *dev,
920 struct drm_atomic_state *state,
921 bool nonblock);
924 * @atomic_state_alloc:
926 * This optional hook can be used by drivers that want to subclass struct
927 * &drm_atomic_state to be able to track their own driver-private global
928 * state easily. If this hook is implemented, drivers must also
929 * implement @atomic_state_clear and @atomic_state_free.
931 * RETURNS:
933 * A new &drm_atomic_state on success or NULL on failure.
935 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
938 * @atomic_state_clear:
940 * This hook must clear any driver private state duplicated into the
941 * passed-in &drm_atomic_state. This hook is called when the caller
942 * encountered a &drm_modeset_lock deadlock and needs to drop all
943 * already acquired locks as part of the deadlock avoidance dance
944 * implemented in drm_modeset_lock_backoff().
946 * Any duplicated state must be invalidated since a concurrent atomic
947 * update might change it, and the drm atomic interfaces always apply
948 * updates as relative changes to the current state.
950 * Drivers that implement this must call drm_atomic_state_default_clear()
951 * to clear common state.
953 void (*atomic_state_clear)(struct drm_atomic_state *state);
956 * @atomic_state_free:
958 * This hook needs driver private resources and the &drm_atomic_state
959 * itself. Note that the core first calls drm_atomic_state_clear() to
960 * avoid code duplicate between the clear and free hooks.
962 * Drivers that implement this must call drm_atomic_state_default_free()
963 * to release common resources.
965 void (*atomic_state_free)(struct drm_atomic_state *state);
969 * struct drm_mode_config - Mode configuration control structure
970 * @mutex: mutex protecting KMS related lists and structures
971 * @connection_mutex: ww mutex protecting connector state and routing
972 * @acquire_ctx: global implicit acquire context used by atomic drivers for
973 * legacy IOCTLs
974 * @fb_lock: mutex to protect fb state and lists
975 * @num_fb: number of fbs available
976 * @fb_list: list of framebuffers available
977 * @num_encoder: number of encoders on this device
978 * @encoder_list: list of encoder objects
979 * @num_overlay_plane: number of overlay planes on this device
980 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
981 * @plane_list: list of plane objects
982 * @num_crtc: number of CRTCs on this device
983 * @crtc_list: list of CRTC objects
984 * @property_list: list of property objects
985 * @min_width: minimum pixel width on this device
986 * @min_height: minimum pixel height on this device
987 * @max_width: maximum pixel width on this device
988 * @max_height: maximum pixel height on this device
989 * @funcs: core driver provided mode setting functions
990 * @fb_base: base address of the framebuffer
991 * @poll_enabled: track polling support for this device
992 * @poll_running: track polling status for this device
993 * @delayed_event: track delayed poll uevent deliver for this device
994 * @output_poll_work: delayed work for polling in process context
995 * @property_blob_list: list of all the blob property objects
996 * @blob_lock: mutex for blob property allocation and management
997 * @*_property: core property tracking
998 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
999 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
1000 * @cursor_width: hint to userspace for max cursor width
1001 * @cursor_height: hint to userspace for max cursor height
1002 * @helper_private: mid-layer private data
1004 * Core mode resource tracking structure. All CRTC, encoders, and connectors
1005 * enumerated by the driver are added here, as are global properties. Some
1006 * global restrictions are also here, e.g. dimension restrictions.
1008 struct drm_mode_config {
1009 struct mutex mutex; /* protects configuration (mode lists etc.) */
1010 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
1011 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
1014 * @idr_mutex:
1016 * Mutex for KMS ID allocation and management. Protects both @crtc_idr
1017 * and @tile_idr.
1019 struct mutex idr_mutex;
1022 * @crtc_idr:
1024 * Main KMS ID tracking object. Use this idr for all IDs, fb, crtc,
1025 * connector, modes - just makes life easier to have only one.
1027 struct idr crtc_idr;
1030 * @tile_idr:
1032 * Use this idr for allocating new IDs for tiled sinks like use in some
1033 * high-res DP MST screens.
1035 struct idr tile_idr;
1037 struct mutex fb_lock; /* proctects global and per-file fb lists */
1038 int num_fb;
1039 struct list_head fb_list;
1042 * @num_connector: Number of connectors on this device.
1044 int num_connector;
1046 * @connector_ida: ID allocator for connector indices.
1048 struct ida connector_ida;
1050 * @connector_list: List of connector objects.
1052 struct list_head connector_list;
1053 int num_encoder;
1054 struct list_head encoder_list;
1057 * Track # of overlay planes separately from # of total planes. By
1058 * default we only advertise overlay planes to userspace; if userspace
1059 * sets the "universal plane" capability bit, we'll go ahead and
1060 * expose all planes.
1062 int num_overlay_plane;
1063 int num_total_plane;
1064 struct list_head plane_list;
1066 int num_crtc;
1067 struct list_head crtc_list;
1069 struct list_head property_list;
1071 int min_width, min_height;
1072 int max_width, max_height;
1073 const struct drm_mode_config_funcs *funcs;
1074 resource_size_t fb_base;
1076 /* output poll support */
1077 bool poll_enabled;
1078 bool poll_running;
1079 bool delayed_event;
1080 struct delayed_work output_poll_work;
1082 struct mutex blob_lock;
1084 /* pointers to standard properties */
1085 struct list_head property_blob_list;
1087 * @edid_property: Default connector property to hold the EDID of the
1088 * currently connected sink, if any.
1090 struct drm_property *edid_property;
1092 * @dpms_property: Default connector property to control the
1093 * connector's DPMS state.
1095 struct drm_property *dpms_property;
1097 * @path_property: Default connector property to hold the DP MST path
1098 * for the port.
1100 struct drm_property *path_property;
1102 * @tile_property: Default connector property to store the tile
1103 * position of a tiled screen, for sinks which need to be driven with
1104 * multiple CRTCs.
1106 struct drm_property *tile_property;
1108 * @plane_type_property: Default plane property to differentiate
1109 * CURSOR, PRIMARY and OVERLAY legacy uses of planes.
1111 struct drm_property *plane_type_property;
1113 * @rotation_property: Optional property for planes or CRTCs to specifiy
1114 * rotation.
1116 struct drm_property *rotation_property;
1118 * @prop_src_x: Default atomic plane property for the plane source
1119 * position in the connected &drm_framebuffer.
1121 struct drm_property *prop_src_x;
1123 * @prop_src_y: Default atomic plane property for the plane source
1124 * position in the connected &drm_framebuffer.
1126 struct drm_property *prop_src_y;
1128 * @prop_src_w: Default atomic plane property for the plane source
1129 * position in the connected &drm_framebuffer.
1131 struct drm_property *prop_src_w;
1133 * @prop_src_h: Default atomic plane property for the plane source
1134 * position in the connected &drm_framebuffer.
1136 struct drm_property *prop_src_h;
1138 * @prop_crtc_x: Default atomic plane property for the plane destination
1139 * position in the &drm_crtc is is being shown on.
1141 struct drm_property *prop_crtc_x;
1143 * @prop_crtc_y: Default atomic plane property for the plane destination
1144 * position in the &drm_crtc is is being shown on.
1146 struct drm_property *prop_crtc_y;
1148 * @prop_crtc_w: Default atomic plane property for the plane destination
1149 * position in the &drm_crtc is is being shown on.
1151 struct drm_property *prop_crtc_w;
1153 * @prop_crtc_h: Default atomic plane property for the plane destination
1154 * position in the &drm_crtc is is being shown on.
1156 struct drm_property *prop_crtc_h;
1158 * @prop_fb_id: Default atomic plane property to specify the
1159 * &drm_framebuffer.
1161 struct drm_property *prop_fb_id;
1163 * @prop_crtc_id: Default atomic plane property to specify the
1164 * &drm_crtc.
1166 struct drm_property *prop_crtc_id;
1168 * @prop_active: Default atomic CRTC property to control the active
1169 * state, which is the simplified implementation for DPMS in atomic
1170 * drivers.
1172 struct drm_property *prop_active;
1174 * @prop_mode_id: Default atomic CRTC property to set the mode for a
1175 * CRTC. A 0 mode implies that the CRTC is entirely disabled - all
1176 * connectors must be of and active must be set to disabled, too.
1178 struct drm_property *prop_mode_id;
1181 * @dvi_i_subconnector_property: Optional DVI-I property to
1182 * differentiate between analog or digital mode.
1184 struct drm_property *dvi_i_subconnector_property;
1186 * @dvi_i_select_subconnector_property: Optional DVI-I property to
1187 * select between analog or digital mode.
1189 struct drm_property *dvi_i_select_subconnector_property;
1192 * @tv_subconnector_property: Optional TV property to differentiate
1193 * between different TV connector types.
1195 struct drm_property *tv_subconnector_property;
1197 * @tv_select_subconnector_property: Optional TV property to select
1198 * between different TV connector types.
1200 struct drm_property *tv_select_subconnector_property;
1202 * @tv_mode_property: Optional TV property to select
1203 * the output TV mode.
1205 struct drm_property *tv_mode_property;
1207 * @tv_left_margin_property: Optional TV property to set the left
1208 * margin.
1210 struct drm_property *tv_left_margin_property;
1212 * @tv_right_margin_property: Optional TV property to set the right
1213 * margin.
1215 struct drm_property *tv_right_margin_property;
1217 * @tv_top_margin_property: Optional TV property to set the right
1218 * margin.
1220 struct drm_property *tv_top_margin_property;
1222 * @tv_bottom_margin_property: Optional TV property to set the right
1223 * margin.
1225 struct drm_property *tv_bottom_margin_property;
1227 * @tv_brightness_property: Optional TV property to set the
1228 * brightness.
1230 struct drm_property *tv_brightness_property;
1232 * @tv_contrast_property: Optional TV property to set the
1233 * contrast.
1235 struct drm_property *tv_contrast_property;
1237 * @tv_flicker_reduction_property: Optional TV property to control the
1238 * flicker reduction mode.
1240 struct drm_property *tv_flicker_reduction_property;
1242 * @tv_overscan_property: Optional TV property to control the overscan
1243 * setting.
1245 struct drm_property *tv_overscan_property;
1247 * @tv_saturation_property: Optional TV property to set the
1248 * saturation.
1250 struct drm_property *tv_saturation_property;
1252 * @tv_hue_property: Optional TV property to set the hue.
1254 struct drm_property *tv_hue_property;
1257 * @scaling_mode_property: Optional connector property to control the
1258 * upscaling, mostly used for built-in panels.
1260 struct drm_property *scaling_mode_property;
1262 * @aspect_ratio_property: Optional connector property to control the
1263 * HDMI infoframe aspect ratio setting.
1265 struct drm_property *aspect_ratio_property;
1267 * @degamma_lut_property: Optional CRTC property to set the LUT used to
1268 * convert the framebuffer's colors to linear gamma.
1270 struct drm_property *degamma_lut_property;
1272 * @degamma_lut_size_property: Optional CRTC property for the size of
1273 * the degamma LUT as supported by the driver (read-only).
1275 struct drm_property *degamma_lut_size_property;
1277 * @ctm_property: Optional CRTC property to set the
1278 * matrix used to convert colors after the lookup in the
1279 * degamma LUT.
1281 struct drm_property *ctm_property;
1283 * @gamma_lut_property: Optional CRTC property to set the LUT used to
1284 * convert the colors, after the CTM matrix, to the gamma space of the
1285 * connected screen.
1287 struct drm_property *gamma_lut_property;
1289 * @gamma_lut_size_property: Optional CRTC property for the size of the
1290 * gamma LUT as supported by the driver (read-only).
1292 struct drm_property *gamma_lut_size_property;
1295 * @suggested_x_property: Optional connector property with a hint for
1296 * the position of the output on the host's screen.
1298 struct drm_property *suggested_x_property;
1300 * @suggested_y_property: Optional connector property with a hint for
1301 * the position of the output on the host's screen.
1303 struct drm_property *suggested_y_property;
1305 /* dumb ioctl parameters */
1306 uint32_t preferred_depth, prefer_shadow;
1309 * @async_page_flip: Does this device support async flips on the primary
1310 * plane?
1312 bool async_page_flip;
1315 * @allow_fb_modifiers:
1317 * Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call.
1319 bool allow_fb_modifiers;
1321 /* cursor size */
1322 uint32_t cursor_width, cursor_height;
1324 struct drm_mode_config_helper_funcs *helper_private;
1327 #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
1329 extern __printf(6, 7)
1330 int drm_crtc_init_with_planes(struct drm_device *dev,
1331 struct drm_crtc *crtc,
1332 struct drm_plane *primary,
1333 struct drm_plane *cursor,
1334 const struct drm_crtc_funcs *funcs,
1335 const char *name, ...);
1336 extern void drm_crtc_cleanup(struct drm_crtc *crtc);
1339 * drm_crtc_index - find the index of a registered CRTC
1340 * @crtc: CRTC to find index for
1342 * Given a registered CRTC, return the index of that CRTC within a DRM
1343 * device's list of CRTCs.
1345 static inline unsigned int drm_crtc_index(const struct drm_crtc *crtc)
1347 return crtc->index;
1351 * drm_crtc_mask - find the mask of a registered CRTC
1352 * @crtc: CRTC to find mask for
1354 * Given a registered CRTC, return the mask bit of that CRTC for an
1355 * encoder's possible_crtcs field.
1357 static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
1359 return 1 << drm_crtc_index(crtc);
1362 extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
1363 int *hdisplay, int *vdisplay);
1364 extern int drm_crtc_force_disable(struct drm_crtc *crtc);
1365 extern int drm_crtc_force_disable_all(struct drm_device *dev);
1367 extern void drm_mode_config_init(struct drm_device *dev);
1368 extern void drm_mode_config_reset(struct drm_device *dev);
1369 extern void drm_mode_config_cleanup(struct drm_device *dev);
1371 extern int drm_mode_set_config_internal(struct drm_mode_set *set);
1373 extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
1374 char topology[8]);
1375 extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
1376 char topology[8]);
1377 extern void drm_mode_put_tile_group(struct drm_device *dev,
1378 struct drm_tile_group *tg);
1380 /* Helpers */
1381 static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
1382 uint32_t id)
1384 struct drm_mode_object *mo;
1385 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
1386 return mo ? obj_to_crtc(mo) : NULL;
1389 #define drm_for_each_crtc(crtc, dev) \
1390 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
1392 static inline void
1393 assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
1396 * The connector hotadd/remove code currently grabs both locks when
1397 * updating lists. Hence readers need only hold either of them to be
1398 * safe and the check amounts to
1400 * WARN_ON(not_holding(A) && not_holding(B)).
1402 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
1403 !drm_modeset_is_locked(&mode_config->connection_mutex));
1406 #endif /* __DRM_CRTC_H__ */