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