]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - include/drm/drm_crtc.h
Merge tag 'nfs-rdma-4.5-1' of git://git.linux-nfs.org/projects/anna/nfs-rdma
[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 void (*disable)(struct drm_bridge *bridge);
1586
1587 /**
1588 * @post_disable:
1589 *
1590 * This callback should disable the bridge. It is called right after
1591 * the preceding element in the display pipe is disabled. If the
1592 * preceding element is a bridge this means it's called after that
1593 * bridge's ->post_disable() function. If the preceding element is a
1594 * &drm_encoder it's called right after the encoder's ->disable(),
1595 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1596 *
1597 * The bridge must assume that the display pipe (i.e. clocks and timing
1598 * singals) feeding it is no longer running when this callback is
1599 * called.
1600 */
1601 void (*post_disable)(struct drm_bridge *bridge);
1602
1603 /**
1604 * @mode_set:
1605 *
1606 * This callback should set the given mode on the bridge. It is called
1607 * after the ->mode_set() callback for the preceding element in the
1608 * display pipeline has been called already. The display pipe (i.e.
1609 * clocks and timing signals) is off when this function is called.
1610 */
1611 void (*mode_set)(struct drm_bridge *bridge,
1612 struct drm_display_mode *mode,
1613 struct drm_display_mode *adjusted_mode);
1614 /**
1615 * @pre_enable:
1616 *
1617 * This callback should enable the bridge. It is called right before
1618 * the preceding element in the display pipe is enabled. If the
1619 * preceding element is a bridge this means it's called before that
1620 * bridge's ->pre_enable() function. If the preceding element is a
1621 * &drm_encoder it's called right before the encoder's ->enable(),
1622 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1623 *
1624 * The display pipe (i.e. clocks and timing signals) feeding this bridge
1625 * will not yet be running when this callback is called. The bridge must
1626 * not enable the display link feeding the next bridge in the chain (if
1627 * there is one) when this callback is called.
1628 */
1629 void (*pre_enable)(struct drm_bridge *bridge);
1630
1631 /**
1632 * @enable:
1633 *
1634 * This callback should enable the bridge. It is called right after
1635 * the preceding element in the display pipe is enabled. If the
1636 * preceding element is a bridge this means it's called after that
1637 * bridge's ->enable() function. If the preceding element is a
1638 * &drm_encoder it's called right after the encoder's ->enable(),
1639 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1640 *
1641 * The bridge can assume that the display pipe (i.e. clocks and timing
1642 * signals) feeding it is running when this callback is called. This
1643 * callback must enable the display link feeding the next bridge in the
1644 * chain if there is one.
1645 */
1646 void (*enable)(struct drm_bridge *bridge);
1647 };
1648
1649 /**
1650 * struct drm_bridge - central DRM bridge control structure
1651 * @dev: DRM device this bridge belongs to
1652 * @encoder: encoder to which this bridge is connected
1653 * @next: the next bridge in the encoder chain
1654 * @of_node: device node pointer to the bridge
1655 * @list: to keep track of all added bridges
1656 * @funcs: control functions
1657 * @driver_private: pointer to the bridge driver's internal context
1658 */
1659 struct drm_bridge {
1660 struct drm_device *dev;
1661 struct drm_encoder *encoder;
1662 struct drm_bridge *next;
1663 #ifdef CONFIG_OF
1664 struct device_node *of_node;
1665 #endif
1666 struct list_head list;
1667
1668 const struct drm_bridge_funcs *funcs;
1669 void *driver_private;
1670 };
1671
1672 /**
1673 * struct drm_atomic_state - the global state object for atomic updates
1674 * @dev: parent DRM device
1675 * @allow_modeset: allow full modeset
1676 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
1677 * @planes: pointer to array of plane pointers
1678 * @plane_states: pointer to array of plane states pointers
1679 * @crtcs: pointer to array of CRTC pointers
1680 * @crtc_states: pointer to array of CRTC states pointers
1681 * @num_connector: size of the @connectors and @connector_states arrays
1682 * @connectors: pointer to array of connector pointers
1683 * @connector_states: pointer to array of connector states pointers
1684 * @acquire_ctx: acquire context for this atomic modeset state update
1685 */
1686 struct drm_atomic_state {
1687 struct drm_device *dev;
1688 bool allow_modeset : 1;
1689 bool legacy_cursor_update : 1;
1690 struct drm_plane **planes;
1691 struct drm_plane_state **plane_states;
1692 struct drm_crtc **crtcs;
1693 struct drm_crtc_state **crtc_states;
1694 int num_connector;
1695 struct drm_connector **connectors;
1696 struct drm_connector_state **connector_states;
1697
1698 struct drm_modeset_acquire_ctx *acquire_ctx;
1699 };
1700
1701
1702 /**
1703 * struct drm_mode_set - new values for a CRTC config change
1704 * @fb: framebuffer to use for new config
1705 * @crtc: CRTC whose configuration we're about to change
1706 * @mode: mode timings to use
1707 * @x: position of this CRTC relative to @fb
1708 * @y: position of this CRTC relative to @fb
1709 * @connectors: array of connectors to drive with this CRTC if possible
1710 * @num_connectors: size of @connectors array
1711 *
1712 * Represents a single crtc the connectors that it drives with what mode
1713 * and from which framebuffer it scans out from.
1714 *
1715 * This is used to set modes.
1716 */
1717 struct drm_mode_set {
1718 struct drm_framebuffer *fb;
1719 struct drm_crtc *crtc;
1720 struct drm_display_mode *mode;
1721
1722 uint32_t x;
1723 uint32_t y;
1724
1725 struct drm_connector **connectors;
1726 size_t num_connectors;
1727 };
1728
1729 /**
1730 * struct drm_mode_config_funcs - basic driver provided mode setting functions
1731 *
1732 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
1733 * involve drivers.
1734 */
1735 struct drm_mode_config_funcs {
1736 /**
1737 * @fb_create:
1738 *
1739 * Create a new framebuffer object. The core does basic checks on the
1740 * requested metadata, but most of that is left to the driver. See
1741 * struct &drm_mode_fb_cmd2 for details.
1742 *
1743 * If the parameters are deemed valid and the backing storage objects in
1744 * the underlying memory manager all exist, then the driver allocates
1745 * a new &drm_framebuffer structure, subclassed to contain
1746 * driver-specific information (like the internal native buffer object
1747 * references). It also needs to fill out all relevant metadata, which
1748 * should be done by calling drm_helper_mode_fill_fb_struct().
1749 *
1750 * The initialization is finalized by calling drm_framebuffer_init(),
1751 * which registers the framebuffer and makes it accessible to other
1752 * threads.
1753 *
1754 * RETURNS:
1755 *
1756 * A new framebuffer with an initial reference count of 1 or a negative
1757 * error code encoded with ERR_PTR().
1758 */
1759 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
1760 struct drm_file *file_priv,
1761 const struct drm_mode_fb_cmd2 *mode_cmd);
1762
1763 /**
1764 * @output_poll_changed:
1765 *
1766 * Callback used by helpers to inform the driver of output configuration
1767 * changes.
1768 *
1769 * Drivers implementing fbdev emulation with the helpers can call
1770 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
1771 * helper of output changes.
1772 *
1773 * FIXME:
1774 *
1775 * Except that there's no vtable for device-level helper callbacks
1776 * there's no reason this is a core function.
1777 */
1778 void (*output_poll_changed)(struct drm_device *dev);
1779
1780 /**
1781 * @atomic_check:
1782 *
1783 * This is the only hook to validate an atomic modeset update. This
1784 * function must reject any modeset and state changes which the hardware
1785 * or driver doesn't support. This includes but is of course not limited
1786 * to:
1787 *
1788 * - Checking that the modes, framebuffers, scaling and placement
1789 * requirements and so on are within the limits of the hardware.
1790 *
1791 * - Checking that any hidden shared resources are not oversubscribed.
1792 * This can be shared PLLs, shared lanes, overall memory bandwidth,
1793 * display fifo space (where shared between planes or maybe even
1794 * CRTCs).
1795 *
1796 * - Checking that virtualized resources exported to userspace are not
1797 * oversubscribed. For various reasons it can make sense to expose
1798 * more planes, crtcs or encoders than which are physically there. One
1799 * example is dual-pipe operations (which generally should be hidden
1800 * from userspace if when lockstepped in hardware, exposed otherwise),
1801 * where a plane might need 1 hardware plane (if it's just on one
1802 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
1803 * shared a hardware plane with a 2nd plane (if there's a compatible
1804 * plane requested on the area handled by the other pipe).
1805 *
1806 * - Check that any transitional state is possible and that if
1807 * requested, the update can indeed be done in the vblank period
1808 * without temporarily disabling some functions.
1809 *
1810 * - Check any other constraints the driver or hardware might have.
1811 *
1812 * - This callback also needs to correctly fill out the &drm_crtc_state
1813 * in this update to make sure that drm_atomic_crtc_needs_modeset()
1814 * reflects the nature of the possible update and returns true if and
1815 * only if the update cannot be applied without tearing within one
1816 * vblank on that CRTC. The core uses that information to reject
1817 * updates which require a full modeset (i.e. blanking the screen, or
1818 * at least pausing updates for a substantial amount of time) if
1819 * userspace has disallowed that in its request.
1820 *
1821 * - The driver also does not need to repeat basic input validation
1822 * like done for the corresponding legacy entry points. The core does
1823 * that before calling this hook.
1824 *
1825 * See the documentation of @atomic_commit for an exhaustive list of
1826 * error conditions which don't have to be checked at the
1827 * ->atomic_check() stage?
1828 *
1829 * See the documentation for struct &drm_atomic_state for how exactly
1830 * an atomic modeset update is described.
1831 *
1832 * Drivers using the atomic helpers can implement this hook using
1833 * drm_atomic_helper_check(), or one of the exported sub-functions of
1834 * it.
1835 *
1836 * RETURNS:
1837 *
1838 * 0 on success or one of the below negative error codes:
1839 *
1840 * - -EINVAL, if any of the above constraints are violated.
1841 *
1842 * - -EDEADLK, when returned from an attempt to acquire an additional
1843 * &drm_modeset_lock through drm_modeset_lock().
1844 *
1845 * - -ENOMEM, if allocating additional state sub-structures failed due
1846 * to lack of memory.
1847 *
1848 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1849 * This can either be due to a pending signal, or because the driver
1850 * needs to completely bail out to recover from an exceptional
1851 * situation like a GPU hang. From a userspace point all errors are
1852 * treated equally.
1853 */
1854 int (*atomic_check)(struct drm_device *dev,
1855 struct drm_atomic_state *state);
1856
1857 /**
1858 * @atomic_commit:
1859 *
1860 * This is the only hook to commit an atomic modeset update. The core
1861 * guarantees that @atomic_check has been called successfully before
1862 * calling this function, and that nothing has been changed in the
1863 * interim.
1864 *
1865 * See the documentation for struct &drm_atomic_state for how exactly
1866 * an atomic modeset update is described.
1867 *
1868 * Drivers using the atomic helpers can implement this hook using
1869 * drm_atomic_helper_commit(), or one of the exported sub-functions of
1870 * it.
1871 *
1872 * Asynchronous commits (as indicated with the async parameter) must
1873 * do any preparatory work which might result in an unsuccessful commit
1874 * in the context of this callback. The only exceptions are hardware
1875 * errors resulting in -EIO. But even in that case the driver must
1876 * ensure that the display pipe is at least running, to avoid
1877 * compositors crashing when pageflips don't work. Anything else,
1878 * specifically committing the update to the hardware, should be done
1879 * without blocking the caller. For updates which do not require a
1880 * modeset this must be guaranteed.
1881 *
1882 * The driver must wait for any pending rendering to the new
1883 * framebuffers to complete before executing the flip. It should also
1884 * wait for any pending rendering from other drivers if the underlying
1885 * buffer is a shared dma-buf. Asynchronous commits must not wait for
1886 * rendering in the context of this callback.
1887 *
1888 * An application can request to be notified when the atomic commit has
1889 * completed. These events are per-CRTC and can be distinguished by the
1890 * CRTC index supplied in &drm_event to userspace.
1891 *
1892 * The drm core will supply a struct &drm_event in the event
1893 * member of each CRTC's &drm_crtc_state structure. This can be handled by the
1894 * drm_crtc_send_vblank_event() function, which the driver should call on
1895 * the provided event upon completion of the atomic commit. Note that if
1896 * the driver supports vblank signalling and timestamping the vblank
1897 * counters and timestamps must agree with the ones returned from page
1898 * flip events. With the current vblank helper infrastructure this can
1899 * be achieved by holding a vblank reference while the page flip is
1900 * pending, acquired through drm_crtc_vblank_get() and released with
1901 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
1902 * counter and timestamp tracking though, e.g. if they have accurate
1903 * timestamp registers in hardware.
1904 *
1905 * NOTE:
1906 *
1907 * Drivers are not allowed to shut down any display pipe successfully
1908 * enabled through an atomic commit on their own. Doing so can result in
1909 * compositors crashing if a page flip is suddenly rejected because the
1910 * pipe is off.
1911 *
1912 * RETURNS:
1913 *
1914 * 0 on success or one of the below negative error codes:
1915 *
1916 * - -EBUSY, if an asynchronous updated is requested and there is
1917 * an earlier updated pending. Drivers are allowed to support a queue
1918 * of outstanding updates, but currently no driver supports that.
1919 * Note that drivers must wait for preceding updates to complete if a
1920 * synchronous update is requested, they are not allowed to fail the
1921 * commit in that case.
1922 *
1923 * - -ENOMEM, if the driver failed to allocate memory. Specifically
1924 * this can happen when trying to pin framebuffers, which must only
1925 * be done when committing the state.
1926 *
1927 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
1928 * that the driver has run out of vram, iommu space or similar GPU
1929 * address space needed for framebuffer.
1930 *
1931 * - -EIO, if the hardware completely died.
1932 *
1933 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1934 * This can either be due to a pending signal, or because the driver
1935 * needs to completely bail out to recover from an exceptional
1936 * situation like a GPU hang. From a userspace point of view all errors are
1937 * treated equally.
1938 *
1939 * This list is exhaustive. Specifically this hook is not allowed to
1940 * return -EINVAL (any invalid requests should be caught in
1941 * @atomic_check) or -EDEADLK (this function must not acquire
1942 * additional modeset locks).
1943 */
1944 int (*atomic_commit)(struct drm_device *dev,
1945 struct drm_atomic_state *state,
1946 bool async);
1947
1948 /**
1949 * @atomic_state_alloc:
1950 *
1951 * This optional hook can be used by drivers that want to subclass struct
1952 * &drm_atomic_state to be able to track their own driver-private global
1953 * state easily. If this hook is implemented, drivers must also
1954 * implement @atomic_state_clear and @atomic_state_free.
1955 *
1956 * RETURNS:
1957 *
1958 * A new &drm_atomic_state on success or NULL on failure.
1959 */
1960 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
1961
1962 /**
1963 * @atomic_state_clear:
1964 *
1965 * This hook must clear any driver private state duplicated into the
1966 * passed-in &drm_atomic_state. This hook is called when the caller
1967 * encountered a &drm_modeset_lock deadlock and needs to drop all
1968 * already acquired locks as part of the deadlock avoidance dance
1969 * implemented in drm_modeset_lock_backoff().
1970 *
1971 * Any duplicated state must be invalidated since a concurrent atomic
1972 * update might change it, and the drm atomic interfaces always apply
1973 * updates as relative changes to the current state.
1974 *
1975 * Drivers that implement this must call drm_atomic_state_default_clear()
1976 * to clear common state.
1977 */
1978 void (*atomic_state_clear)(struct drm_atomic_state *state);
1979
1980 /**
1981 * @atomic_state_free:
1982 *
1983 * This hook needs driver private resources and the &drm_atomic_state
1984 * itself. Note that the core first calls drm_atomic_state_clear() to
1985 * avoid code duplicate between the clear and free hooks.
1986 *
1987 * Drivers that implement this must call drm_atomic_state_default_free()
1988 * to release common resources.
1989 */
1990 void (*atomic_state_free)(struct drm_atomic_state *state);
1991 };
1992
1993 /**
1994 * struct drm_mode_config - Mode configuration control structure
1995 * @mutex: mutex protecting KMS related lists and structures
1996 * @connection_mutex: ww mutex protecting connector state and routing
1997 * @acquire_ctx: global implicit acquire context used by atomic drivers for
1998 * legacy IOCTLs
1999 * @idr_mutex: mutex for KMS ID allocation and management
2000 * @crtc_idr: main KMS ID tracking object
2001 * @fb_lock: mutex to protect fb state and lists
2002 * @num_fb: number of fbs available
2003 * @fb_list: list of framebuffers available
2004 * @num_connector: number of connectors on this device
2005 * @connector_list: list of connector objects
2006 * @num_encoder: number of encoders on this device
2007 * @encoder_list: list of encoder objects
2008 * @num_overlay_plane: number of overlay planes on this device
2009 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
2010 * @plane_list: list of plane objects
2011 * @num_crtc: number of CRTCs on this device
2012 * @crtc_list: list of CRTC objects
2013 * @property_list: list of property objects
2014 * @min_width: minimum pixel width on this device
2015 * @min_height: minimum pixel height on this device
2016 * @max_width: maximum pixel width on this device
2017 * @max_height: maximum pixel height on this device
2018 * @funcs: core driver provided mode setting functions
2019 * @fb_base: base address of the framebuffer
2020 * @poll_enabled: track polling support for this device
2021 * @poll_running: track polling status for this device
2022 * @output_poll_work: delayed work for polling in process context
2023 * @property_blob_list: list of all the blob property objects
2024 * @blob_lock: mutex for blob property allocation and management
2025 * @*_property: core property tracking
2026 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
2027 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
2028 * @async_page_flip: does this device support async flips on the primary plane?
2029 * @cursor_width: hint to userspace for max cursor width
2030 * @cursor_height: hint to userspace for max cursor height
2031 *
2032 * Core mode resource tracking structure. All CRTC, encoders, and connectors
2033 * enumerated by the driver are added here, as are global properties. Some
2034 * global restrictions are also here, e.g. dimension restrictions.
2035 */
2036 struct drm_mode_config {
2037 struct mutex mutex; /* protects configuration (mode lists etc.) */
2038 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
2039 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
2040 struct mutex idr_mutex; /* for IDR management */
2041 struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
2042 struct idr tile_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
2043 /* this is limited to one for now */
2044
2045 struct mutex fb_lock; /* proctects global and per-file fb lists */
2046 int num_fb;
2047 struct list_head fb_list;
2048
2049 int num_connector;
2050 struct list_head connector_list;
2051 int num_encoder;
2052 struct list_head encoder_list;
2053
2054 /*
2055 * Track # of overlay planes separately from # of total planes. By
2056 * default we only advertise overlay planes to userspace; if userspace
2057 * sets the "universal plane" capability bit, we'll go ahead and
2058 * expose all planes.
2059 */
2060 int num_overlay_plane;
2061 int num_total_plane;
2062 struct list_head plane_list;
2063
2064 int num_crtc;
2065 struct list_head crtc_list;
2066
2067 struct list_head property_list;
2068
2069 int min_width, min_height;
2070 int max_width, max_height;
2071 const struct drm_mode_config_funcs *funcs;
2072 resource_size_t fb_base;
2073
2074 /* output poll support */
2075 bool poll_enabled;
2076 bool poll_running;
2077 bool delayed_event;
2078 struct delayed_work output_poll_work;
2079
2080 struct mutex blob_lock;
2081
2082 /* pointers to standard properties */
2083 struct list_head property_blob_list;
2084 struct drm_property *edid_property;
2085 struct drm_property *dpms_property;
2086 struct drm_property *path_property;
2087 struct drm_property *tile_property;
2088 struct drm_property *plane_type_property;
2089 struct drm_property *rotation_property;
2090 struct drm_property *prop_src_x;
2091 struct drm_property *prop_src_y;
2092 struct drm_property *prop_src_w;
2093 struct drm_property *prop_src_h;
2094 struct drm_property *prop_crtc_x;
2095 struct drm_property *prop_crtc_y;
2096 struct drm_property *prop_crtc_w;
2097 struct drm_property *prop_crtc_h;
2098 struct drm_property *prop_fb_id;
2099 struct drm_property *prop_crtc_id;
2100 struct drm_property *prop_active;
2101 struct drm_property *prop_mode_id;
2102
2103 /* DVI-I properties */
2104 struct drm_property *dvi_i_subconnector_property;
2105 struct drm_property *dvi_i_select_subconnector_property;
2106
2107 /* TV properties */
2108 struct drm_property *tv_subconnector_property;
2109 struct drm_property *tv_select_subconnector_property;
2110 struct drm_property *tv_mode_property;
2111 struct drm_property *tv_left_margin_property;
2112 struct drm_property *tv_right_margin_property;
2113 struct drm_property *tv_top_margin_property;
2114 struct drm_property *tv_bottom_margin_property;
2115 struct drm_property *tv_brightness_property;
2116 struct drm_property *tv_contrast_property;
2117 struct drm_property *tv_flicker_reduction_property;
2118 struct drm_property *tv_overscan_property;
2119 struct drm_property *tv_saturation_property;
2120 struct drm_property *tv_hue_property;
2121
2122 /* Optional properties */
2123 struct drm_property *scaling_mode_property;
2124 struct drm_property *aspect_ratio_property;
2125 struct drm_property *dirty_info_property;
2126
2127 /* properties for virtual machine layout */
2128 struct drm_property *suggested_x_property;
2129 struct drm_property *suggested_y_property;
2130
2131 /* dumb ioctl parameters */
2132 uint32_t preferred_depth, prefer_shadow;
2133
2134 /* whether async page flip is supported or not */
2135 bool async_page_flip;
2136
2137 /* whether the driver supports fb modifiers */
2138 bool allow_fb_modifiers;
2139
2140 /* cursor size */
2141 uint32_t cursor_width, cursor_height;
2142 };
2143
2144 /**
2145 * drm_for_each_plane_mask - iterate over planes specified by bitmask
2146 * @plane: the loop cursor
2147 * @dev: the DRM device
2148 * @plane_mask: bitmask of plane indices
2149 *
2150 * Iterate over all planes specified by bitmask.
2151 */
2152 #define drm_for_each_plane_mask(plane, dev, plane_mask) \
2153 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
2154 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
2155
2156
2157 #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
2158 #define obj_to_connector(x) container_of(x, struct drm_connector, base)
2159 #define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
2160 #define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
2161 #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
2162 #define obj_to_property(x) container_of(x, struct drm_property, base)
2163 #define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
2164 #define obj_to_plane(x) container_of(x, struct drm_plane, base)
2165
2166 struct drm_prop_enum_list {
2167 int type;
2168 char *name;
2169 };
2170
2171 extern __printf(6, 7)
2172 int drm_crtc_init_with_planes(struct drm_device *dev,
2173 struct drm_crtc *crtc,
2174 struct drm_plane *primary,
2175 struct drm_plane *cursor,
2176 const struct drm_crtc_funcs *funcs,
2177 const char *name, ...);
2178 extern void drm_crtc_cleanup(struct drm_crtc *crtc);
2179 extern unsigned int drm_crtc_index(struct drm_crtc *crtc);
2180
2181 /**
2182 * drm_crtc_mask - find the mask of a registered CRTC
2183 * @crtc: CRTC to find mask for
2184 *
2185 * Given a registered CRTC, return the mask bit of that CRTC for an
2186 * encoder's possible_crtcs field.
2187 */
2188 static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
2189 {
2190 return 1 << drm_crtc_index(crtc);
2191 }
2192
2193 extern void drm_connector_ida_init(void);
2194 extern void drm_connector_ida_destroy(void);
2195 extern int drm_connector_init(struct drm_device *dev,
2196 struct drm_connector *connector,
2197 const struct drm_connector_funcs *funcs,
2198 int connector_type);
2199 int drm_connector_register(struct drm_connector *connector);
2200 void drm_connector_unregister(struct drm_connector *connector);
2201
2202 extern void drm_connector_cleanup(struct drm_connector *connector);
2203 extern unsigned int drm_connector_index(struct drm_connector *connector);
2204 /* helper to unplug all connectors from sysfs for device */
2205 extern void drm_connector_unplug_all(struct drm_device *dev);
2206
2207 extern int drm_bridge_add(struct drm_bridge *bridge);
2208 extern void drm_bridge_remove(struct drm_bridge *bridge);
2209 extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
2210 extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
2211
2212 bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
2213 const struct drm_display_mode *mode,
2214 struct drm_display_mode *adjusted_mode);
2215 void drm_bridge_disable(struct drm_bridge *bridge);
2216 void drm_bridge_post_disable(struct drm_bridge *bridge);
2217 void drm_bridge_mode_set(struct drm_bridge *bridge,
2218 struct drm_display_mode *mode,
2219 struct drm_display_mode *adjusted_mode);
2220 void drm_bridge_pre_enable(struct drm_bridge *bridge);
2221 void drm_bridge_enable(struct drm_bridge *bridge);
2222
2223 extern __printf(5, 6)
2224 int drm_encoder_init(struct drm_device *dev,
2225 struct drm_encoder *encoder,
2226 const struct drm_encoder_funcs *funcs,
2227 int encoder_type, const char *name, ...);
2228
2229 /**
2230 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
2231 * @encoder: encoder to test
2232 * @crtc: crtc to test
2233 *
2234 * Return false if @encoder can't be driven by @crtc, true otherwise.
2235 */
2236 static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
2237 struct drm_crtc *crtc)
2238 {
2239 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
2240 }
2241
2242 extern __printf(8, 9)
2243 int drm_universal_plane_init(struct drm_device *dev,
2244 struct drm_plane *plane,
2245 unsigned long possible_crtcs,
2246 const struct drm_plane_funcs *funcs,
2247 const uint32_t *formats,
2248 unsigned int format_count,
2249 enum drm_plane_type type,
2250 const char *name, ...);
2251 extern int drm_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, unsigned int format_count,
2256 bool is_primary);
2257 extern void drm_plane_cleanup(struct drm_plane *plane);
2258 extern unsigned int drm_plane_index(struct drm_plane *plane);
2259 extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
2260 extern void drm_plane_force_disable(struct drm_plane *plane);
2261 extern int drm_plane_check_pixel_format(const struct drm_plane *plane,
2262 u32 format);
2263 extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
2264 int *hdisplay, int *vdisplay);
2265 extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,
2266 int x, int y,
2267 const struct drm_display_mode *mode,
2268 const struct drm_framebuffer *fb);
2269
2270 extern void drm_encoder_cleanup(struct drm_encoder *encoder);
2271
2272 extern const char *drm_get_connector_status_name(enum drm_connector_status status);
2273 extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
2274 extern const char *drm_get_dpms_name(int val);
2275 extern const char *drm_get_dvi_i_subconnector_name(int val);
2276 extern const char *drm_get_dvi_i_select_name(int val);
2277 extern const char *drm_get_tv_subconnector_name(int val);
2278 extern const char *drm_get_tv_select_name(int val);
2279 extern void drm_fb_release(struct drm_file *file_priv);
2280 extern void drm_property_destroy_user_blobs(struct drm_device *dev,
2281 struct drm_file *file_priv);
2282 extern bool drm_probe_ddc(struct i2c_adapter *adapter);
2283 extern struct edid *drm_get_edid(struct drm_connector *connector,
2284 struct i2c_adapter *adapter);
2285 extern struct edid *drm_edid_duplicate(const struct edid *edid);
2286 extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
2287 extern void drm_mode_config_init(struct drm_device *dev);
2288 extern void drm_mode_config_reset(struct drm_device *dev);
2289 extern void drm_mode_config_cleanup(struct drm_device *dev);
2290
2291 extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
2292 const char *path);
2293 int drm_mode_connector_set_tile_property(struct drm_connector *connector);
2294 extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
2295 const struct edid *edid);
2296
2297 extern int drm_display_info_set_bus_formats(struct drm_display_info *info,
2298 const u32 *formats,
2299 unsigned int num_formats);
2300
2301 static inline bool drm_property_type_is(struct drm_property *property,
2302 uint32_t type)
2303 {
2304 /* instanceof for props.. handles extended type vs original types: */
2305 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2306 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
2307 return property->flags & type;
2308 }
2309
2310 static inline bool drm_property_type_valid(struct drm_property *property)
2311 {
2312 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2313 return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
2314 return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
2315 }
2316
2317 extern int drm_object_property_set_value(struct drm_mode_object *obj,
2318 struct drm_property *property,
2319 uint64_t val);
2320 extern int drm_object_property_get_value(struct drm_mode_object *obj,
2321 struct drm_property *property,
2322 uint64_t *value);
2323 extern int drm_framebuffer_init(struct drm_device *dev,
2324 struct drm_framebuffer *fb,
2325 const struct drm_framebuffer_funcs *funcs);
2326 extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
2327 uint32_t id);
2328 extern void drm_framebuffer_unreference(struct drm_framebuffer *fb);
2329 extern void drm_framebuffer_reference(struct drm_framebuffer *fb);
2330 extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
2331 extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
2332 extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
2333
2334 extern void drm_object_attach_property(struct drm_mode_object *obj,
2335 struct drm_property *property,
2336 uint64_t init_val);
2337 extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
2338 const char *name, int num_values);
2339 extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
2340 const char *name,
2341 const struct drm_prop_enum_list *props,
2342 int num_values);
2343 struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
2344 int flags, const char *name,
2345 const struct drm_prop_enum_list *props,
2346 int num_props,
2347 uint64_t supported_bits);
2348 struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
2349 const char *name,
2350 uint64_t min, uint64_t max);
2351 struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
2352 int flags, const char *name,
2353 int64_t min, int64_t max);
2354 struct drm_property *drm_property_create_object(struct drm_device *dev,
2355 int flags, const char *name, uint32_t type);
2356 struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags,
2357 const char *name);
2358 struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
2359 size_t length,
2360 const void *data);
2361 struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
2362 uint32_t id);
2363 struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
2364 void drm_property_unreference_blob(struct drm_property_blob *blob);
2365 extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
2366 extern int drm_property_add_enum(struct drm_property *property, int index,
2367 uint64_t value, const char *name);
2368 extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
2369 extern int drm_mode_create_tv_properties(struct drm_device *dev,
2370 unsigned int num_modes,
2371 const char * const modes[]);
2372 extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
2373 extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
2374 extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
2375 extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
2376 extern bool drm_property_change_valid_get(struct drm_property *property,
2377 uint64_t value, struct drm_mode_object **ref);
2378 extern void drm_property_change_valid_put(struct drm_property *property,
2379 struct drm_mode_object *ref);
2380
2381 extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
2382 struct drm_encoder *encoder);
2383 extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
2384 int gamma_size);
2385 extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
2386 uint32_t id, uint32_t type);
2387
2388 /* IOCTLs */
2389 extern int drm_mode_getresources(struct drm_device *dev,
2390 void *data, struct drm_file *file_priv);
2391 extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
2392 struct drm_file *file_priv);
2393 extern int drm_mode_getcrtc(struct drm_device *dev,
2394 void *data, struct drm_file *file_priv);
2395 extern int drm_mode_getconnector(struct drm_device *dev,
2396 void *data, struct drm_file *file_priv);
2397 extern int drm_mode_set_config_internal(struct drm_mode_set *set);
2398 extern int drm_mode_setcrtc(struct drm_device *dev,
2399 void *data, struct drm_file *file_priv);
2400 extern int drm_mode_getplane(struct drm_device *dev,
2401 void *data, struct drm_file *file_priv);
2402 extern int drm_mode_setplane(struct drm_device *dev,
2403 void *data, struct drm_file *file_priv);
2404 extern int drm_mode_cursor_ioctl(struct drm_device *dev,
2405 void *data, struct drm_file *file_priv);
2406 extern int drm_mode_cursor2_ioctl(struct drm_device *dev,
2407 void *data, struct drm_file *file_priv);
2408 extern int drm_mode_addfb(struct drm_device *dev,
2409 void *data, struct drm_file *file_priv);
2410 extern int drm_mode_addfb2(struct drm_device *dev,
2411 void *data, struct drm_file *file_priv);
2412 extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
2413 extern int drm_mode_rmfb(struct drm_device *dev,
2414 void *data, struct drm_file *file_priv);
2415 extern int drm_mode_getfb(struct drm_device *dev,
2416 void *data, struct drm_file *file_priv);
2417 extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
2418 void *data, struct drm_file *file_priv);
2419
2420 extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
2421 void *data, struct drm_file *file_priv);
2422 extern int drm_mode_getblob_ioctl(struct drm_device *dev,
2423 void *data, struct drm_file *file_priv);
2424 extern int drm_mode_createblob_ioctl(struct drm_device *dev,
2425 void *data, struct drm_file *file_priv);
2426 extern int drm_mode_destroyblob_ioctl(struct drm_device *dev,
2427 void *data, struct drm_file *file_priv);
2428 extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
2429 void *data, struct drm_file *file_priv);
2430 extern int drm_mode_getencoder(struct drm_device *dev,
2431 void *data, struct drm_file *file_priv);
2432 extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
2433 void *data, struct drm_file *file_priv);
2434 extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
2435 void *data, struct drm_file *file_priv);
2436 extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
2437 extern enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
2438 extern bool drm_detect_hdmi_monitor(struct edid *edid);
2439 extern bool drm_detect_monitor_audio(struct edid *edid);
2440 extern bool drm_rgb_quant_range_selectable(struct edid *edid);
2441 extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
2442 void *data, struct drm_file *file_priv);
2443 extern int drm_add_modes_noedid(struct drm_connector *connector,
2444 int hdisplay, int vdisplay);
2445 extern void drm_set_preferred_mode(struct drm_connector *connector,
2446 int hpref, int vpref);
2447
2448 extern int drm_edid_header_is_valid(const u8 *raw_edid);
2449 extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
2450 bool *edid_corrupt);
2451 extern bool drm_edid_is_valid(struct edid *edid);
2452
2453 extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2454 char topology[8]);
2455 extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2456 char topology[8]);
2457 extern void drm_mode_put_tile_group(struct drm_device *dev,
2458 struct drm_tile_group *tg);
2459 struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
2460 int hsize, int vsize, int fresh,
2461 bool rb);
2462
2463 extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
2464 void *data, struct drm_file *file_priv);
2465 extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
2466 void *data, struct drm_file *file_priv);
2467 extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
2468 void *data, struct drm_file *file_priv);
2469 extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
2470 struct drm_file *file_priv);
2471 extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
2472 struct drm_file *file_priv);
2473 extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
2474 struct drm_property *property,
2475 uint64_t value);
2476 extern int drm_mode_atomic_ioctl(struct drm_device *dev,
2477 void *data, struct drm_file *file_priv);
2478
2479 extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
2480 int *bpp);
2481 extern int drm_format_num_planes(uint32_t format);
2482 extern int drm_format_plane_cpp(uint32_t format, int plane);
2483 extern int drm_format_horz_chroma_subsampling(uint32_t format);
2484 extern int drm_format_vert_chroma_subsampling(uint32_t format);
2485 extern const char *drm_get_format_name(uint32_t format);
2486 extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
2487 unsigned int supported_rotations);
2488 extern unsigned int drm_rotation_simplify(unsigned int rotation,
2489 unsigned int supported_rotations);
2490
2491 /* Helpers */
2492
2493 static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
2494 uint32_t id)
2495 {
2496 struct drm_mode_object *mo;
2497 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
2498 return mo ? obj_to_plane(mo) : NULL;
2499 }
2500
2501 static inline struct drm_crtc *drm_crtc_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_CRTC);
2506 return mo ? obj_to_crtc(mo) : NULL;
2507 }
2508
2509 static inline struct drm_encoder *drm_encoder_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_ENCODER);
2514 return mo ? obj_to_encoder(mo) : NULL;
2515 }
2516
2517 static inline struct drm_connector *drm_connector_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_CONNECTOR);
2522 return mo ? obj_to_connector(mo) : NULL;
2523 }
2524
2525 static inline struct drm_property *drm_property_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_PROPERTY);
2530 return mo ? obj_to_property(mo) : NULL;
2531 }
2532
2533 /* Plane list iterator for legacy (overlay only) planes. */
2534 #define drm_for_each_legacy_plane(plane, dev) \
2535 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
2536 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
2537
2538 #define drm_for_each_plane(plane, dev) \
2539 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
2540
2541 #define drm_for_each_crtc(crtc, dev) \
2542 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
2543
2544 static inline void
2545 assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
2546 {
2547 /*
2548 * The connector hotadd/remove code currently grabs both locks when
2549 * updating lists. Hence readers need only hold either of them to be
2550 * safe and the check amounts to
2551 *
2552 * WARN_ON(not_holding(A) && not_holding(B)).
2553 */
2554 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
2555 !drm_modeset_is_locked(&mode_config->connection_mutex));
2556 }
2557
2558 #define drm_for_each_connector(connector, dev) \
2559 for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \
2560 connector = list_first_entry(&(dev)->mode_config.connector_list, \
2561 struct drm_connector, head); \
2562 &connector->head != (&(dev)->mode_config.connector_list); \
2563 connector = list_next_entry(connector, head))
2564
2565 #define drm_for_each_encoder(encoder, dev) \
2566 list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
2567
2568 #define drm_for_each_fb(fb, dev) \
2569 for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \
2570 fb = list_first_entry(&(dev)->mode_config.fb_list, \
2571 struct drm_framebuffer, head); \
2572 &fb->head != (&(dev)->mode_config.fb_list); \
2573 fb = list_next_entry(fb, head))
2574
2575 #endif /* __DRM_CRTC_H__ */