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