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