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>
33 #include <linux/hdmi.h>
34 #include <uapi/drm/drm_mode.h>
35 #include <uapi/drm/drm_fourcc.h>
36 #include <drm/drm_modeset_lock.h>
40 struct drm_framebuffer;
41 struct drm_object_properties;
47 #define DRM_MODE_OBJECT_CRTC 0xcccccccc
48 #define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0
49 #define DRM_MODE_OBJECT_ENCODER 0xe0e0e0e0
50 #define DRM_MODE_OBJECT_MODE 0xdededede
51 #define DRM_MODE_OBJECT_PROPERTY 0xb0b0b0b0
52 #define DRM_MODE_OBJECT_FB 0xfbfbfbfb
53 #define DRM_MODE_OBJECT_BLOB 0xbbbbbbbb
54 #define DRM_MODE_OBJECT_PLANE 0xeeeeeeee
55 #define DRM_MODE_OBJECT_BRIDGE 0xbdbdbdbd
56 #define DRM_MODE_OBJECT_ANY 0
58 struct drm_mode_object {
61 struct drm_object_properties *properties;
64 #define DRM_OBJECT_MAX_PROPERTY 24
65 struct drm_object_properties {
67 /* NOTE: if we ever start dynamically destroying properties (ie.
68 * not at drm_mode_config_cleanup() time), then we'd have to do
69 * a better job of detaching property from mode objects to avoid
70 * dangling property pointers:
72 struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY];
73 uint64_t values[DRM_OBJECT_MAX_PROPERTY];
76 static inline int64_t U642I64(uint64_t val)
78 return (int64_t)*((int64_t *)&val);
80 static inline uint64_t I642U64(int64_t val)
82 return (uint64_t)*((uint64_t *)&val);
85 /* rotation property bits */
86 #define DRM_ROTATE_0 0
87 #define DRM_ROTATE_90 1
88 #define DRM_ROTATE_180 2
89 #define DRM_ROTATE_270 3
90 #define DRM_REFLECT_X 4
91 #define DRM_REFLECT_Y 5
93 enum drm_connector_force {
94 DRM_FORCE_UNSPECIFIED,
96 DRM_FORCE_ON, /* force on analog part normally */
97 DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
100 #include <drm/drm_modes.h>
102 enum drm_connector_status {
103 connector_status_connected = 1,
104 connector_status_disconnected = 2,
105 connector_status_unknown = 3,
108 enum subpixel_order {
110 SubPixelHorizontalRGB,
111 SubPixelHorizontalBGR,
117 #define DRM_COLOR_FORMAT_RGB444 (1<<0)
118 #define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
119 #define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
121 * Describes a given display (e.g. CRT or flat panel) and its limitations.
123 struct drm_display_info {
124 char name[DRM_DISPLAY_INFO_LEN];
127 unsigned int width_mm;
128 unsigned int height_mm;
130 /* Clock limits FIXME: storage format */
131 unsigned int min_vfreq, max_vfreq;
132 unsigned int min_hfreq, max_hfreq;
133 unsigned int pixel_clock;
136 enum subpixel_order subpixel_order;
139 /* Mask of supported hdmi deep color modes */
140 u8 edid_hdmi_dc_modes;
145 /* data corresponds to displayid vend/prod/serial */
146 struct drm_tile_group {
147 struct kref refcount;
148 struct drm_device *dev;
153 struct drm_framebuffer_funcs {
154 /* note: use drm_framebuffer_remove() */
155 void (*destroy)(struct drm_framebuffer *framebuffer);
156 int (*create_handle)(struct drm_framebuffer *fb,
157 struct drm_file *file_priv,
158 unsigned int *handle);
160 * Optional callback for the dirty fb ioctl.
162 * Userspace can notify the driver via this callback
163 * that a area of the framebuffer has changed and should
164 * be flushed to the display hardware.
166 * See documentation in drm_mode.h for the struct
167 * drm_mode_fb_dirty_cmd for more information as all
168 * the semantics and arguments have a one to one mapping
171 int (*dirty)(struct drm_framebuffer *framebuffer,
172 struct drm_file *file_priv, unsigned flags,
173 unsigned color, struct drm_clip_rect *clips,
177 struct drm_framebuffer {
178 struct drm_device *dev;
180 * Note that the fb is refcounted for the benefit of driver internals,
181 * for example some hw, disabling a CRTC/plane is asynchronous, and
182 * scanout does not actually complete until the next vblank. So some
183 * cleanup (like releasing the reference(s) on the backing GEM bo(s))
184 * should be deferred. In cases like this, the driver would like to
185 * hold a ref to the fb even though it has already been removed from
186 * userspace perspective.
188 struct kref refcount;
190 * Place on the dev->mode_config.fb_list, access protected by
191 * dev->mode_config.fb_lock.
193 struct list_head head;
194 struct drm_mode_object base;
195 const struct drm_framebuffer_funcs *funcs;
196 unsigned int pitches[4];
197 unsigned int offsets[4];
200 /* depth can be 15 or 16 */
204 uint32_t pixel_format; /* fourcc format */
205 struct list_head filp_head;
206 /* if you are using the helper */
207 void *helper_private;
210 struct drm_property_blob {
211 struct drm_mode_object base;
212 struct list_head head;
214 unsigned char data[];
217 struct drm_property_enum {
219 struct list_head head;
220 char name[DRM_PROP_NAME_LEN];
223 struct drm_property {
224 struct list_head head;
225 struct drm_mode_object base;
227 char name[DRM_PROP_NAME_LEN];
230 struct drm_device *dev;
232 struct list_head enum_list;
236 struct drm_connector;
238 struct drm_pending_vblank_event;
241 struct drm_atomic_state;
244 * struct drm_crtc_state - mutable CRTC state
245 * @crtc: backpointer to the CRTC
246 * @enable: whether the CRTC should be enabled, gates all other state
247 * @active: whether the CRTC is actively displaying (used for DPMS)
248 * @mode_changed: for use by helpers and drivers when computing state updates
249 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
250 * @last_vblank_count: for helpers and drivers to capture the vblank of the
251 * update to ensure framebuffer cleanup isn't done too early
252 * @planes_changed: for use by helpers and drivers when computing state updates
253 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
254 * @mode: current mode timings
255 * @event: optional pointer to a DRM event to signal upon completion of the
257 * @state: backpointer to global drm_atomic_state
259 * Note that the distinction between @enable and @active is rather subtile:
260 * Flipping @active while @enable is set without changing anything else may
261 * never return in a failure from the ->atomic_check callback. Userspace assumes
262 * that a DPMS On will always succeed. In other words: @enable controls resource
263 * assignment, @active controls the actual hardware state.
265 struct drm_crtc_state {
266 struct drm_crtc *crtc;
271 /* computed state bits used by helpers and drivers */
272 bool planes_changed : 1;
273 bool mode_changed : 1;
275 /* attached planes bitmask:
276 * WARNING: transitional helpers do not maintain plane_mask so
277 * drivers not converted over to atomic helpers should not rely
278 * on plane_mask being accurate!
282 /* last_vblank_count: for vblank waits before cleanup */
283 u32 last_vblank_count;
285 /* adjusted_mode: for use by helpers and drivers */
286 struct drm_display_mode adjusted_mode;
288 struct drm_display_mode mode;
290 struct drm_pending_vblank_event *event;
292 struct drm_atomic_state *state;
296 * struct drm_crtc_funcs - control CRTCs for a given device
297 * @save: save CRTC state
298 * @restore: restore CRTC state
299 * @reset: reset CRTC after state has been invalidated (e.g. resume)
300 * @cursor_set: setup the cursor
301 * @cursor_set2: setup the cursor with hotspot, superseeds @cursor_set if set
302 * @cursor_move: move the cursor
303 * @gamma_set: specify color ramp for CRTC
304 * @destroy: deinit and free object
305 * @set_property: called when a property is changed
306 * @set_config: apply a new CRTC configuration
307 * @page_flip: initiate a page flip
308 * @atomic_duplicate_state: duplicate the atomic state for this CRTC
309 * @atomic_destroy_state: destroy an atomic state for this CRTC
310 * @atomic_set_property: set a property on an atomic state for this CRTC
312 * The drm_crtc_funcs structure is the central CRTC management structure
313 * in the DRM. Each CRTC controls one or more connectors (note that the name
314 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
315 * connectors, not just CRTs).
317 * Each driver is responsible for filling out this structure at startup time,
318 * in addition to providing other modesetting features, like i2c and DDC
321 struct drm_crtc_funcs {
322 /* Save CRTC state */
323 void (*save)(struct drm_crtc *crtc); /* suspend? */
324 /* Restore CRTC state */
325 void (*restore)(struct drm_crtc *crtc); /* resume? */
326 /* Reset CRTC state */
327 void (*reset)(struct drm_crtc *crtc);
329 /* cursor controls */
330 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
331 uint32_t handle, uint32_t width, uint32_t height);
332 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
333 uint32_t handle, uint32_t width, uint32_t height,
334 int32_t hot_x, int32_t hot_y);
335 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
337 /* Set gamma on the CRTC */
338 void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
339 uint32_t start, uint32_t size);
340 /* Object destroy routine */
341 void (*destroy)(struct drm_crtc *crtc);
343 int (*set_config)(struct drm_mode_set *set);
346 * Flip to the given framebuffer. This implements the page
347 * flip ioctl described in drm_mode.h, specifically, the
348 * implementation must return immediately and block all
349 * rendering to the current fb until the flip has completed.
350 * If userspace set the event flag in the ioctl, the event
351 * argument will point to an event to send back when the flip
352 * completes, otherwise it will be NULL.
354 int (*page_flip)(struct drm_crtc *crtc,
355 struct drm_framebuffer *fb,
356 struct drm_pending_vblank_event *event,
359 int (*set_property)(struct drm_crtc *crtc,
360 struct drm_property *property, uint64_t val);
362 /* atomic update handling */
363 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
364 void (*atomic_destroy_state)(struct drm_crtc *crtc,
365 struct drm_crtc_state *state);
366 int (*atomic_set_property)(struct drm_crtc *crtc,
367 struct drm_crtc_state *state,
368 struct drm_property *property,
373 * struct drm_crtc - central CRTC control structure
374 * @dev: parent DRM device
375 * @port: OF node used by drm_of_find_possible_crtcs()
376 * @head: list management
377 * @mutex: per-CRTC locking
378 * @base: base KMS object for ID tracking etc.
379 * @primary: primary plane for this CRTC
380 * @cursor: cursor plane for this CRTC
381 * @cursor_x: current x position of the cursor, used for universal cursor planes
382 * @cursor_y: current y position of the cursor, used for universal cursor planes
383 * @enabled: is this CRTC enabled?
384 * @mode: current mode timings
385 * @hwmode: mode timings as programmed to hw regs
386 * @invert_dimensions: for purposes of error checking crtc vs fb sizes,
387 * invert the width/height of the crtc. This is used if the driver
388 * is performing 90 or 270 degree rotated scanout
389 * @x: x position on screen
390 * @y: y position on screen
391 * @funcs: CRTC control functions
392 * @gamma_size: size of gamma ramp
393 * @gamma_store: gamma ramp values
394 * @framedur_ns: precise frame timing
395 * @linedur_ns: precise line timing
396 * @pixeldur_ns: precise pixel timing
397 * @helper_private: mid-layer private data
398 * @properties: property tracking for this CRTC
399 * @state: current atomic state for this CRTC
400 * @acquire_ctx: per-CRTC implicit acquire context used by atomic drivers for
403 * Each CRTC may have one or more connectors associated with it. This structure
404 * allows the CRTC to be controlled.
407 struct drm_device *dev;
408 struct device_node *port;
409 struct list_head head;
414 * This provides a read lock for the overall crtc state (mode, dpms
415 * state, ...) and a write lock for everything which can be update
416 * without a full modeset (fb, cursor data, ...)
418 struct drm_modeset_lock mutex;
420 struct drm_mode_object base;
422 /* primary and cursor planes for CRTC */
423 struct drm_plane *primary;
424 struct drm_plane *cursor;
426 /* position of cursor plane on crtc */
432 /* Requested mode from modesetting. */
433 struct drm_display_mode mode;
435 /* Programmed mode in hw, after adjustments for encoders,
436 * crtc, panel scaling etc. Needed for timestamping etc.
438 struct drm_display_mode hwmode;
440 bool invert_dimensions;
443 const struct drm_crtc_funcs *funcs;
445 /* CRTC gamma size for reporting to userspace */
447 uint16_t *gamma_store;
449 /* Constants needed for precise vblank and swap timestamping. */
450 int framedur_ns, linedur_ns, pixeldur_ns;
452 /* if you are using the helper */
453 void *helper_private;
455 struct drm_object_properties properties;
457 struct drm_crtc_state *state;
460 * For legacy crtc ioctls so that atomic drivers can get at the locking
463 struct drm_modeset_acquire_ctx *acquire_ctx;
467 * struct drm_connector_state - mutable connector state
468 * @connector: backpointer to the connector
469 * @crtc: CRTC to connect connector to, NULL if disabled
470 * @best_encoder: can be used by helpers and drivers to select the encoder
471 * @state: backpointer to global drm_atomic_state
473 struct drm_connector_state {
474 struct drm_connector *connector;
476 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_connector() */
478 struct drm_encoder *best_encoder;
480 struct drm_atomic_state *state;
484 * struct drm_connector_funcs - control connectors on a given device
485 * @dpms: set power state (see drm_crtc_funcs above)
486 * @save: save connector state
487 * @restore: restore connector state
488 * @reset: reset connector after state has been invalidated (e.g. resume)
489 * @detect: is this connector active?
490 * @fill_modes: fill mode list for this connector
491 * @set_property: property for this connector may need an update
492 * @destroy: make object go away
493 * @force: notify the driver that the connector is forced on
494 * @atomic_duplicate_state: duplicate the atomic state for this connector
495 * @atomic_destroy_state: destroy an atomic state for this connector
496 * @atomic_set_property: set a property on an atomic state for this connector
498 * Each CRTC may have one or more connectors attached to it. The functions
499 * below allow the core DRM code to control connectors, enumerate available modes,
502 struct drm_connector_funcs {
503 void (*dpms)(struct drm_connector *connector, int mode);
504 void (*save)(struct drm_connector *connector);
505 void (*restore)(struct drm_connector *connector);
506 void (*reset)(struct drm_connector *connector);
508 /* Check to see if anything is attached to the connector.
509 * @force is set to false whilst polling, true when checking the
510 * connector due to user request. @force can be used by the driver
511 * to avoid expensive, destructive operations during automated
514 enum drm_connector_status (*detect)(struct drm_connector *connector,
516 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
517 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
519 void (*destroy)(struct drm_connector *connector);
520 void (*force)(struct drm_connector *connector);
522 /* atomic update handling */
523 struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
524 void (*atomic_destroy_state)(struct drm_connector *connector,
525 struct drm_connector_state *state);
526 int (*atomic_set_property)(struct drm_connector *connector,
527 struct drm_connector_state *state,
528 struct drm_property *property,
533 * struct drm_encoder_funcs - encoder controls
534 * @reset: reset state (e.g. at init or resume time)
535 * @destroy: cleanup and free associated data
537 * Encoders sit between CRTCs and connectors.
539 struct drm_encoder_funcs {
540 void (*reset)(struct drm_encoder *encoder);
541 void (*destroy)(struct drm_encoder *encoder);
544 #define DRM_CONNECTOR_MAX_ENCODER 3
547 * struct drm_encoder - central DRM encoder structure
548 * @dev: parent DRM device
549 * @head: list management
550 * @base: base KMS object
551 * @name: encoder name
552 * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
553 * @possible_crtcs: bitmask of potential CRTC bindings
554 * @possible_clones: bitmask of potential sibling encoders for cloning
555 * @crtc: currently bound CRTC
556 * @bridge: bridge associated to the encoder
557 * @funcs: control functions
558 * @helper_private: mid-layer private data
560 * CRTCs drive pixels to encoders, which convert them into signals
561 * appropriate for a given connector or set of connectors.
564 struct drm_device *dev;
565 struct list_head head;
567 struct drm_mode_object base;
570 uint32_t possible_crtcs;
571 uint32_t possible_clones;
573 struct drm_crtc *crtc;
574 struct drm_bridge *bridge;
575 const struct drm_encoder_funcs *funcs;
576 void *helper_private;
579 /* should we poll this connector for connects and disconnects */
580 /* hot plug detectable */
581 #define DRM_CONNECTOR_POLL_HPD (1 << 0)
582 /* poll for connections */
583 #define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
584 /* can cleanly poll for disconnections without flickering the screen */
585 /* DACs should rarely do this without a lot of testing */
586 #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
588 #define MAX_ELD_BYTES 128
591 * struct drm_connector - central DRM connector control structure
592 * @dev: parent DRM device
593 * @kdev: kernel device for sysfs attributes
594 * @attr: sysfs attributes
595 * @head: list management
596 * @base: base KMS object
597 * @name: connector name
598 * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
599 * @connector_type_id: index into connector type enum
600 * @interlace_allowed: can this connector handle interlaced modes?
601 * @doublescan_allowed: can this connector handle doublescan?
602 * @stereo_allowed: can this connector handle stereo modes?
603 * @modes: modes available on this connector (from fill_modes() + user)
604 * @status: one of the drm_connector_status enums (connected, not, or unknown)
605 * @probed_modes: list of modes derived directly from the display
606 * @display_info: information about attached display (e.g. from EDID)
607 * @funcs: connector control functions
608 * @edid_blob_ptr: DRM property containing EDID if present
609 * @properties: property tracking for this connector
610 * @path_blob_ptr: DRM blob property data for the DP MST path property
611 * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
612 * @dpms: current dpms state
613 * @helper_private: mid-layer private data
614 * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
615 * @force: a %DRM_FORCE_<foo> state for forced mode sets
616 * @override_edid: has the EDID been overwritten through debugfs for testing?
617 * @encoder_ids: valid encoders for this connector
618 * @encoder: encoder driving this connector, if any
619 * @eld: EDID-like data, if present
620 * @dvi_dual: dual link DVI, if found
621 * @max_tmds_clock: max clock rate, if found
622 * @latency_present: AV delay info from ELD, if found
623 * @video_latency: video latency info from ELD, if found
624 * @audio_latency: audio latency info from ELD, if found
625 * @null_edid_counter: track sinks that give us all zeros for the EDID
626 * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
627 * @debugfs_entry: debugfs directory for this connector
628 * @state: current atomic state for this connector
629 * @has_tile: is this connector connected to a tiled monitor
630 * @tile_group: tile group for the connected monitor
631 * @tile_is_single_monitor: whether the tile is one monitor housing
632 * @num_h_tile: number of horizontal tiles in the tile group
633 * @num_v_tile: number of vertical tiles in the tile group
634 * @tile_h_loc: horizontal location of this tile
635 * @tile_v_loc: vertical location of this tile
636 * @tile_h_size: horizontal size of this tile.
637 * @tile_v_size: vertical size of this tile.
639 * Each connector may be connected to one or more CRTCs, or may be clonable by
640 * another connector if they can share a CRTC. Each connector also has a specific
641 * position in the broader display (referred to as a 'screen' though it could
642 * span multiple monitors).
644 struct drm_connector {
645 struct drm_device *dev;
647 struct device_attribute *attr;
648 struct list_head head;
650 struct drm_mode_object base;
654 int connector_type_id;
655 bool interlace_allowed;
656 bool doublescan_allowed;
658 struct list_head modes; /* list of modes on this connector */
660 enum drm_connector_status status;
662 /* these are modes added by probing with DDC or the BIOS */
663 struct list_head probed_modes;
665 struct drm_display_info display_info;
666 const struct drm_connector_funcs *funcs;
668 struct drm_property_blob *edid_blob_ptr;
669 struct drm_object_properties properties;
671 struct drm_property_blob *path_blob_ptr;
673 struct drm_property_blob *tile_blob_ptr;
675 uint8_t polled; /* DRM_CONNECTOR_POLL_* */
677 /* requested DPMS state */
680 void *helper_private;
682 /* forced on connector */
683 struct drm_cmdline_mode cmdline_mode;
684 enum drm_connector_force force;
686 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
687 struct drm_encoder *encoder; /* currently active encoder */
690 uint8_t eld[MAX_ELD_BYTES];
692 int max_tmds_clock; /* in MHz */
693 bool latency_present[2];
694 int video_latency[2]; /* [0]: progressive, [1]: interlaced */
695 int audio_latency[2];
696 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
697 unsigned bad_edid_counter;
699 struct dentry *debugfs_entry;
701 struct drm_connector_state *state;
705 struct drm_tile_group *tile_group;
706 bool tile_is_single_monitor;
708 uint8_t num_h_tile, num_v_tile;
709 uint8_t tile_h_loc, tile_v_loc;
710 uint16_t tile_h_size, tile_v_size;
714 * struct drm_plane_state - mutable plane state
715 * @plane: backpointer to the plane
716 * @crtc: currently bound CRTC, NULL if disabled
717 * @fb: currently bound framebuffer
718 * @fence: optional fence to wait for before scanning out @fb
719 * @crtc_x: left position of visible portion of plane on crtc
720 * @crtc_y: upper position of visible portion of plane on crtc
721 * @crtc_w: width of visible portion of plane on crtc
722 * @crtc_h: height of visible portion of plane on crtc
723 * @src_x: left position of visible portion of plane within
725 * @src_y: upper position of visible portion of plane within
727 * @src_w: width of visible portion of plane (in 16.16)
728 * @src_h: height of visible portion of plane (in 16.16)
729 * @state: backpointer to global drm_atomic_state
731 struct drm_plane_state {
732 struct drm_plane *plane;
734 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
735 struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
738 /* Signed dest location allows it to be partially off screen */
739 int32_t crtc_x, crtc_y;
740 uint32_t crtc_w, crtc_h;
742 /* Source values are 16.16 fixed point */
743 uint32_t src_x, src_y;
744 uint32_t src_h, src_w;
746 struct drm_atomic_state *state;
751 * struct drm_plane_funcs - driver plane control functions
752 * @update_plane: update the plane configuration
753 * @disable_plane: shut down the plane
754 * @destroy: clean up plane resources
755 * @reset: reset plane after state has been invalidated (e.g. resume)
756 * @set_property: called when a property is changed
757 * @atomic_duplicate_state: duplicate the atomic state for this plane
758 * @atomic_destroy_state: destroy an atomic state for this plane
759 * @atomic_set_property: set a property on an atomic state for this plane
761 struct drm_plane_funcs {
762 int (*update_plane)(struct drm_plane *plane,
763 struct drm_crtc *crtc, struct drm_framebuffer *fb,
764 int crtc_x, int crtc_y,
765 unsigned int crtc_w, unsigned int crtc_h,
766 uint32_t src_x, uint32_t src_y,
767 uint32_t src_w, uint32_t src_h);
768 int (*disable_plane)(struct drm_plane *plane);
769 void (*destroy)(struct drm_plane *plane);
770 void (*reset)(struct drm_plane *plane);
772 int (*set_property)(struct drm_plane *plane,
773 struct drm_property *property, uint64_t val);
775 /* atomic update handling */
776 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
777 void (*atomic_destroy_state)(struct drm_plane *plane,
778 struct drm_plane_state *state);
779 int (*atomic_set_property)(struct drm_plane *plane,
780 struct drm_plane_state *state,
781 struct drm_property *property,
785 enum drm_plane_type {
786 DRM_PLANE_TYPE_OVERLAY,
787 DRM_PLANE_TYPE_PRIMARY,
788 DRM_PLANE_TYPE_CURSOR,
792 * struct drm_plane - central DRM plane control structure
793 * @dev: DRM device this plane belongs to
794 * @head: for list management
795 * @base: base mode object
796 * @possible_crtcs: pipes this plane can be bound to
797 * @format_types: array of formats supported by this plane
798 * @format_count: number of formats supported
799 * @crtc: currently bound CRTC
800 * @fb: currently bound fb
801 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
802 * drm_mode_set_config_internal() to implement correct refcounting.
803 * @funcs: helper functions
804 * @properties: property tracking for this plane
805 * @type: type of plane (overlay, primary, cursor)
806 * @state: current atomic state for this plane
809 struct drm_device *dev;
810 struct list_head head;
812 struct drm_modeset_lock mutex;
814 struct drm_mode_object base;
816 uint32_t possible_crtcs;
817 uint32_t *format_types;
818 uint32_t format_count;
820 struct drm_crtc *crtc;
821 struct drm_framebuffer *fb;
823 struct drm_framebuffer *old_fb;
825 const struct drm_plane_funcs *funcs;
827 struct drm_object_properties properties;
829 enum drm_plane_type type;
831 void *helper_private;
833 struct drm_plane_state *state;
837 * struct drm_bridge_funcs - drm_bridge control functions
838 * @mode_fixup: Try to fixup (or reject entirely) proposed mode for this bridge
839 * @disable: Called right before encoder prepare, disables the bridge
840 * @post_disable: Called right after encoder prepare, for lockstepped disable
841 * @mode_set: Set this mode to the bridge
842 * @pre_enable: Called right before encoder commit, for lockstepped commit
843 * @enable: Called right after encoder commit, enables the bridge
844 * @destroy: make object go away
846 struct drm_bridge_funcs {
847 bool (*mode_fixup)(struct drm_bridge *bridge,
848 const struct drm_display_mode *mode,
849 struct drm_display_mode *adjusted_mode);
850 void (*disable)(struct drm_bridge *bridge);
851 void (*post_disable)(struct drm_bridge *bridge);
852 void (*mode_set)(struct drm_bridge *bridge,
853 struct drm_display_mode *mode,
854 struct drm_display_mode *adjusted_mode);
855 void (*pre_enable)(struct drm_bridge *bridge);
856 void (*enable)(struct drm_bridge *bridge);
857 void (*destroy)(struct drm_bridge *bridge);
861 * struct drm_bridge - central DRM bridge control structure
862 * @dev: DRM device this bridge belongs to
863 * @head: list management
864 * @base: base mode object
865 * @funcs: control functions
866 * @driver_private: pointer to the bridge driver's internal context
869 struct drm_device *dev;
870 struct list_head head;
872 struct drm_mode_object base;
874 const struct drm_bridge_funcs *funcs;
875 void *driver_private;
879 * struct struct drm_atomic_state - the global state object for atomic updates
880 * @dev: parent DRM device
881 * @flags: state flags like async update
882 * @planes: pointer to array of plane pointers
883 * @plane_states: pointer to array of plane states pointers
884 * @crtcs: pointer to array of CRTC pointers
885 * @crtc_states: pointer to array of CRTC states pointers
886 * @num_connector: size of the @connectors and @connector_states arrays
887 * @connectors: pointer to array of connector pointers
888 * @connector_states: pointer to array of connector states pointers
889 * @acquire_ctx: acquire context for this atomic modeset state update
891 struct drm_atomic_state {
892 struct drm_device *dev;
894 struct drm_plane **planes;
895 struct drm_plane_state **plane_states;
896 struct drm_crtc **crtcs;
897 struct drm_crtc_state **crtc_states;
899 struct drm_connector **connectors;
900 struct drm_connector_state **connector_states;
902 struct drm_modeset_acquire_ctx *acquire_ctx;
907 * struct drm_mode_set - new values for a CRTC config change
908 * @fb: framebuffer to use for new config
909 * @crtc: CRTC whose configuration we're about to change
910 * @mode: mode timings to use
911 * @x: position of this CRTC relative to @fb
912 * @y: position of this CRTC relative to @fb
913 * @connectors: array of connectors to drive with this CRTC if possible
914 * @num_connectors: size of @connectors array
916 * Represents a single crtc the connectors that it drives with what mode
917 * and from which framebuffer it scans out from.
919 * This is used to set modes.
921 struct drm_mode_set {
922 struct drm_framebuffer *fb;
923 struct drm_crtc *crtc;
924 struct drm_display_mode *mode;
929 struct drm_connector **connectors;
930 size_t num_connectors;
934 * struct drm_mode_config_funcs - basic driver provided mode setting functions
935 * @fb_create: create a new framebuffer object
936 * @output_poll_changed: function to handle output configuration changes
937 * @atomic_check: check whether a give atomic state update is possible
938 * @atomic_commit: commit an atomic state update previously verified with
941 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
944 struct drm_mode_config_funcs {
945 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
946 struct drm_file *file_priv,
947 struct drm_mode_fb_cmd2 *mode_cmd);
948 void (*output_poll_changed)(struct drm_device *dev);
950 int (*atomic_check)(struct drm_device *dev,
951 struct drm_atomic_state *a);
952 int (*atomic_commit)(struct drm_device *dev,
953 struct drm_atomic_state *a,
958 * struct drm_mode_group - group of mode setting resources for potential sub-grouping
959 * @num_crtcs: CRTC count
960 * @num_encoders: encoder count
961 * @num_connectors: connector count
962 * @num_bridges: bridge count
963 * @id_list: list of KMS object IDs in this group
965 * Currently this simply tracks the global mode setting state. But in the
966 * future it could allow groups of objects to be set aside into independent
967 * control groups for use by different user level processes (e.g. two X servers
968 * running simultaneously on different heads, each with their own mode
969 * configuration and freedom of mode setting).
971 struct drm_mode_group {
973 uint32_t num_encoders;
974 uint32_t num_connectors;
975 uint32_t num_bridges;
977 /* list of object IDs for this group */
982 * struct drm_mode_config - Mode configuration control structure
983 * @mutex: mutex protecting KMS related lists and structures
984 * @connection_mutex: ww mutex protecting connector state and routing
985 * @acquire_ctx: global implicit acquire context used by atomic drivers for
987 * @idr_mutex: mutex for KMS ID allocation and management
988 * @crtc_idr: main KMS ID tracking object
989 * @fb_lock: mutex to protect fb state and lists
990 * @num_fb: number of fbs available
991 * @fb_list: list of framebuffers available
992 * @num_connector: number of connectors on this device
993 * @connector_list: list of connector objects
994 * @num_bridge: number of bridges on this device
995 * @bridge_list: list of bridge objects
996 * @num_encoder: number of encoders on this device
997 * @encoder_list: list of encoder objects
998 * @num_overlay_plane: number of overlay planes on this device
999 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
1000 * @plane_list: list of plane objects
1001 * @num_crtc: number of CRTCs on this device
1002 * @crtc_list: list of CRTC objects
1003 * @property_list: list of property objects
1004 * @min_width: minimum pixel width on this device
1005 * @min_height: minimum pixel height on this device
1006 * @max_width: maximum pixel width on this device
1007 * @max_height: maximum pixel height on this device
1008 * @funcs: core driver provided mode setting functions
1009 * @fb_base: base address of the framebuffer
1010 * @poll_enabled: track polling support for this device
1011 * @poll_running: track polling status for this device
1012 * @output_poll_work: delayed work for polling in process context
1013 * @property_blob_list: list of all the blob property objects
1014 * @*_property: core property tracking
1015 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
1016 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
1017 * @async_page_flip: does this device support async flips on the primary plane?
1018 * @cursor_width: hint to userspace for max cursor width
1019 * @cursor_height: hint to userspace for max cursor height
1021 * Core mode resource tracking structure. All CRTC, encoders, and connectors
1022 * enumerated by the driver are added here, as are global properties. Some
1023 * global restrictions are also here, e.g. dimension restrictions.
1025 struct drm_mode_config {
1026 struct mutex mutex; /* protects configuration (mode lists etc.) */
1027 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
1028 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
1029 struct mutex idr_mutex; /* for IDR management */
1030 struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
1031 struct idr tile_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
1032 /* this is limited to one for now */
1034 struct mutex fb_lock; /* proctects global and per-file fb lists */
1036 struct list_head fb_list;
1039 struct list_head connector_list;
1041 struct list_head bridge_list;
1043 struct list_head encoder_list;
1046 * Track # of overlay planes separately from # of total planes. By
1047 * default we only advertise overlay planes to userspace; if userspace
1048 * sets the "universal plane" capability bit, we'll go ahead and
1049 * expose all planes.
1051 int num_overlay_plane;
1052 int num_total_plane;
1053 struct list_head plane_list;
1056 struct list_head crtc_list;
1058 struct list_head property_list;
1060 int min_width, min_height;
1061 int max_width, max_height;
1062 const struct drm_mode_config_funcs *funcs;
1063 resource_size_t fb_base;
1065 /* output poll support */
1068 struct delayed_work output_poll_work;
1070 /* pointers to standard properties */
1071 struct list_head property_blob_list;
1072 struct drm_property *edid_property;
1073 struct drm_property *dpms_property;
1074 struct drm_property *path_property;
1075 struct drm_property *tile_property;
1076 struct drm_property *plane_type_property;
1077 struct drm_property *rotation_property;
1079 /* DVI-I properties */
1080 struct drm_property *dvi_i_subconnector_property;
1081 struct drm_property *dvi_i_select_subconnector_property;
1084 struct drm_property *tv_subconnector_property;
1085 struct drm_property *tv_select_subconnector_property;
1086 struct drm_property *tv_mode_property;
1087 struct drm_property *tv_left_margin_property;
1088 struct drm_property *tv_right_margin_property;
1089 struct drm_property *tv_top_margin_property;
1090 struct drm_property *tv_bottom_margin_property;
1091 struct drm_property *tv_brightness_property;
1092 struct drm_property *tv_contrast_property;
1093 struct drm_property *tv_flicker_reduction_property;
1094 struct drm_property *tv_overscan_property;
1095 struct drm_property *tv_saturation_property;
1096 struct drm_property *tv_hue_property;
1098 /* Optional properties */
1099 struct drm_property *scaling_mode_property;
1100 struct drm_property *aspect_ratio_property;
1101 struct drm_property *dirty_info_property;
1103 /* properties for virtual machine layout */
1104 struct drm_property *suggested_x_property;
1105 struct drm_property *suggested_y_property;
1107 /* dumb ioctl parameters */
1108 uint32_t preferred_depth, prefer_shadow;
1110 /* whether async page flip is supported or not */
1111 bool async_page_flip;
1114 uint32_t cursor_width, cursor_height;
1118 * drm_for_each_plane_mask - iterate over planes specified by bitmask
1119 * @plane: the loop cursor
1120 * @dev: the DRM device
1121 * @plane_mask: bitmask of plane indices
1123 * Iterate over all planes specified by bitmask.
1125 #define drm_for_each_plane_mask(plane, dev, plane_mask) \
1126 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
1127 if ((plane_mask) & (1 << drm_plane_index(plane)))
1130 #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
1131 #define obj_to_connector(x) container_of(x, struct drm_connector, base)
1132 #define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
1133 #define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
1134 #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
1135 #define obj_to_property(x) container_of(x, struct drm_property, base)
1136 #define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
1137 #define obj_to_plane(x) container_of(x, struct drm_plane, base)
1139 struct drm_prop_enum_list {
1144 extern int drm_crtc_init_with_planes(struct drm_device *dev,
1145 struct drm_crtc *crtc,
1146 struct drm_plane *primary,
1147 struct drm_plane *cursor,
1148 const struct drm_crtc_funcs *funcs);
1149 extern void drm_crtc_cleanup(struct drm_crtc *crtc);
1150 extern unsigned int drm_crtc_index(struct drm_crtc *crtc);
1153 * drm_crtc_mask - find the mask of a registered CRTC
1154 * @crtc: CRTC to find mask for
1156 * Given a registered CRTC, return the mask bit of that CRTC for an
1157 * encoder's possible_crtcs field.
1159 static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
1161 return 1 << drm_crtc_index(crtc);
1164 extern void drm_connector_ida_init(void);
1165 extern void drm_connector_ida_destroy(void);
1166 extern int drm_connector_init(struct drm_device *dev,
1167 struct drm_connector *connector,
1168 const struct drm_connector_funcs *funcs,
1169 int connector_type);
1170 int drm_connector_register(struct drm_connector *connector);
1171 void drm_connector_unregister(struct drm_connector *connector);
1173 extern void drm_connector_cleanup(struct drm_connector *connector);
1174 extern unsigned int drm_connector_index(struct drm_connector *connector);
1175 /* helper to unplug all connectors from sysfs for device */
1176 extern void drm_connector_unplug_all(struct drm_device *dev);
1178 extern int drm_bridge_init(struct drm_device *dev, struct drm_bridge *bridge,
1179 const struct drm_bridge_funcs *funcs);
1180 extern void drm_bridge_cleanup(struct drm_bridge *bridge);
1182 extern int drm_encoder_init(struct drm_device *dev,
1183 struct drm_encoder *encoder,
1184 const struct drm_encoder_funcs *funcs,
1188 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
1189 * @encoder: encoder to test
1190 * @crtc: crtc to test
1192 * Return false if @encoder can't be driven by @crtc, true otherwise.
1194 static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
1195 struct drm_crtc *crtc)
1197 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
1200 extern int drm_universal_plane_init(struct drm_device *dev,
1201 struct drm_plane *plane,
1202 unsigned long possible_crtcs,
1203 const struct drm_plane_funcs *funcs,
1204 const uint32_t *formats,
1205 uint32_t format_count,
1206 enum drm_plane_type type);
1207 extern int drm_plane_init(struct drm_device *dev,
1208 struct drm_plane *plane,
1209 unsigned long possible_crtcs,
1210 const struct drm_plane_funcs *funcs,
1211 const uint32_t *formats, uint32_t format_count,
1213 extern void drm_plane_cleanup(struct drm_plane *plane);
1214 extern unsigned int drm_plane_index(struct drm_plane *plane);
1215 extern void drm_plane_force_disable(struct drm_plane *plane);
1216 extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,
1218 const struct drm_display_mode *mode,
1219 const struct drm_framebuffer *fb);
1221 extern void drm_encoder_cleanup(struct drm_encoder *encoder);
1223 extern const char *drm_get_connector_status_name(enum drm_connector_status status);
1224 extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
1225 extern const char *drm_get_dpms_name(int val);
1226 extern const char *drm_get_dvi_i_subconnector_name(int val);
1227 extern const char *drm_get_dvi_i_select_name(int val);
1228 extern const char *drm_get_tv_subconnector_name(int val);
1229 extern const char *drm_get_tv_select_name(int val);
1230 extern void drm_fb_release(struct drm_file *file_priv);
1231 extern int drm_mode_group_init_legacy_group(struct drm_device *dev, struct drm_mode_group *group);
1232 extern void drm_mode_group_destroy(struct drm_mode_group *group);
1233 extern void drm_reinit_primary_mode_group(struct drm_device *dev);
1234 extern bool drm_probe_ddc(struct i2c_adapter *adapter);
1235 extern struct edid *drm_get_edid(struct drm_connector *connector,
1236 struct i2c_adapter *adapter);
1237 extern struct edid *drm_edid_duplicate(const struct edid *edid);
1238 extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
1239 extern void drm_mode_config_init(struct drm_device *dev);
1240 extern void drm_mode_config_reset(struct drm_device *dev);
1241 extern void drm_mode_config_cleanup(struct drm_device *dev);
1243 extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
1245 int drm_mode_connector_set_tile_property(struct drm_connector *connector);
1246 extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
1247 const struct edid *edid);
1249 static inline bool drm_property_type_is(struct drm_property *property,
1252 /* instanceof for props.. handles extended type vs original types: */
1253 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
1254 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
1255 return property->flags & type;
1258 static inline bool drm_property_type_valid(struct drm_property *property)
1260 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
1261 return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
1262 return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
1265 extern int drm_object_property_set_value(struct drm_mode_object *obj,
1266 struct drm_property *property,
1268 extern int drm_object_property_get_value(struct drm_mode_object *obj,
1269 struct drm_property *property,
1271 extern int drm_framebuffer_init(struct drm_device *dev,
1272 struct drm_framebuffer *fb,
1273 const struct drm_framebuffer_funcs *funcs);
1274 extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
1276 extern void drm_framebuffer_unreference(struct drm_framebuffer *fb);
1277 extern void drm_framebuffer_reference(struct drm_framebuffer *fb);
1278 extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
1279 extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
1280 extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
1282 extern void drm_object_attach_property(struct drm_mode_object *obj,
1283 struct drm_property *property,
1285 extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
1286 const char *name, int num_values);
1287 extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
1289 const struct drm_prop_enum_list *props,
1291 struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
1292 int flags, const char *name,
1293 const struct drm_prop_enum_list *props,
1295 uint64_t supported_bits);
1296 struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
1298 uint64_t min, uint64_t max);
1299 struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
1300 int flags, const char *name,
1301 int64_t min, int64_t max);
1302 struct drm_property *drm_property_create_object(struct drm_device *dev,
1303 int flags, const char *name, uint32_t type);
1304 extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
1305 extern int drm_property_add_enum(struct drm_property *property, int index,
1306 uint64_t value, const char *name);
1307 extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
1308 extern int drm_mode_create_tv_properties(struct drm_device *dev,
1309 unsigned int num_modes,
1311 extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
1312 extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
1313 extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
1314 extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
1316 extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
1317 struct drm_encoder *encoder);
1318 extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
1320 extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
1321 uint32_t id, uint32_t type);
1324 extern int drm_mode_getresources(struct drm_device *dev,
1325 void *data, struct drm_file *file_priv);
1326 extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
1327 struct drm_file *file_priv);
1328 extern int drm_mode_getcrtc(struct drm_device *dev,
1329 void *data, struct drm_file *file_priv);
1330 extern int drm_mode_getconnector(struct drm_device *dev,
1331 void *data, struct drm_file *file_priv);
1332 extern int drm_mode_set_config_internal(struct drm_mode_set *set);
1333 extern int drm_mode_setcrtc(struct drm_device *dev,
1334 void *data, struct drm_file *file_priv);
1335 extern int drm_mode_getplane(struct drm_device *dev,
1336 void *data, struct drm_file *file_priv);
1337 extern int drm_mode_setplane(struct drm_device *dev,
1338 void *data, struct drm_file *file_priv);
1339 extern int drm_mode_cursor_ioctl(struct drm_device *dev,
1340 void *data, struct drm_file *file_priv);
1341 extern int drm_mode_cursor2_ioctl(struct drm_device *dev,
1342 void *data, struct drm_file *file_priv);
1343 extern int drm_mode_addfb(struct drm_device *dev,
1344 void *data, struct drm_file *file_priv);
1345 extern int drm_mode_addfb2(struct drm_device *dev,
1346 void *data, struct drm_file *file_priv);
1347 extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
1348 extern int drm_mode_rmfb(struct drm_device *dev,
1349 void *data, struct drm_file *file_priv);
1350 extern int drm_mode_getfb(struct drm_device *dev,
1351 void *data, struct drm_file *file_priv);
1352 extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
1353 void *data, struct drm_file *file_priv);
1355 extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
1356 void *data, struct drm_file *file_priv);
1357 extern int drm_mode_getblob_ioctl(struct drm_device *dev,
1358 void *data, struct drm_file *file_priv);
1359 extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
1360 void *data, struct drm_file *file_priv);
1361 extern int drm_mode_getencoder(struct drm_device *dev,
1362 void *data, struct drm_file *file_priv);
1363 extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
1364 void *data, struct drm_file *file_priv);
1365 extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
1366 void *data, struct drm_file *file_priv);
1367 extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
1368 extern enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
1369 extern bool drm_detect_hdmi_monitor(struct edid *edid);
1370 extern bool drm_detect_monitor_audio(struct edid *edid);
1371 extern bool drm_rgb_quant_range_selectable(struct edid *edid);
1372 extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
1373 void *data, struct drm_file *file_priv);
1374 extern int drm_add_modes_noedid(struct drm_connector *connector,
1375 int hdisplay, int vdisplay);
1376 extern void drm_set_preferred_mode(struct drm_connector *connector,
1377 int hpref, int vpref);
1379 extern int drm_edid_header_is_valid(const u8 *raw_edid);
1380 extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid);
1381 extern bool drm_edid_is_valid(struct edid *edid);
1383 extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
1385 extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
1387 extern void drm_mode_put_tile_group(struct drm_device *dev,
1388 struct drm_tile_group *tg);
1389 struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
1390 int hsize, int vsize, int fresh,
1393 extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
1394 void *data, struct drm_file *file_priv);
1395 extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
1396 void *data, struct drm_file *file_priv);
1397 extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
1398 void *data, struct drm_file *file_priv);
1399 extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
1400 struct drm_file *file_priv);
1401 extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
1402 struct drm_file *file_priv);
1403 extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
1404 struct drm_property *property,
1407 extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
1409 extern int drm_format_num_planes(uint32_t format);
1410 extern int drm_format_plane_cpp(uint32_t format, int plane);
1411 extern int drm_format_horz_chroma_subsampling(uint32_t format);
1412 extern int drm_format_vert_chroma_subsampling(uint32_t format);
1413 extern const char *drm_get_format_name(uint32_t format);
1414 extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
1415 unsigned int supported_rotations);
1416 extern unsigned int drm_rotation_simplify(unsigned int rotation,
1417 unsigned int supported_rotations);
1421 static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
1424 struct drm_mode_object *mo;
1425 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
1426 return mo ? obj_to_plane(mo) : NULL;
1429 static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
1432 struct drm_mode_object *mo;
1433 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
1434 return mo ? obj_to_crtc(mo) : NULL;
1437 static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
1440 struct drm_mode_object *mo;
1441 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
1442 return mo ? obj_to_encoder(mo) : NULL;
1445 static inline struct drm_connector *drm_connector_find(struct drm_device *dev,
1448 struct drm_mode_object *mo;
1449 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
1450 return mo ? obj_to_connector(mo) : NULL;
1453 static inline struct drm_property *drm_property_find(struct drm_device *dev,
1456 struct drm_mode_object *mo;
1457 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
1458 return mo ? obj_to_property(mo) : NULL;
1461 static inline struct drm_property_blob *
1462 drm_property_blob_find(struct drm_device *dev, uint32_t id)
1464 struct drm_mode_object *mo;
1465 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_BLOB);
1466 return mo ? obj_to_blob(mo) : NULL;
1469 /* Plane list iterator for legacy (overlay only) planes. */
1470 #define drm_for_each_legacy_plane(plane, planelist) \
1471 list_for_each_entry(plane, planelist, head) \
1472 if (plane->type == DRM_PLANE_TYPE_OVERLAY)
1474 #endif /* __DRM_CRTC_H__ */