![]() |
|
|||
0001 /* 0002 * Copyright © 2006 Keith Packard 0003 * Copyright © 2007-2008 Dave Airlie 0004 * Copyright © 2007-2008 Intel Corporation 0005 * Jesse Barnes <jesse.barnes@intel.com> 0006 * Copyright © 2011-2013 Intel Corporation 0007 * Copyright © 2015 Intel Corporation 0008 * Daniel Vetter <daniel.vetter@ffwll.ch> 0009 * 0010 * Permission is hereby granted, free of charge, to any person obtaining a 0011 * copy of this software and associated documentation files (the "Software"), 0012 * to deal in the Software without restriction, including without limitation 0013 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 0014 * and/or sell copies of the Software, and to permit persons to whom the 0015 * Software is furnished to do so, subject to the following conditions: 0016 * 0017 * The above copyright notice and this permission notice shall be included in 0018 * all copies or substantial portions of the Software. 0019 * 0020 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0021 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0022 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 0023 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 0024 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 0025 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 0026 * OTHER DEALINGS IN THE SOFTWARE. 0027 */ 0028 0029 #ifndef __DRM_MODESET_HELPER_VTABLES_H__ 0030 #define __DRM_MODESET_HELPER_VTABLES_H__ 0031 0032 #include <drm/drm_crtc.h> 0033 #include <drm/drm_encoder.h> 0034 0035 /** 0036 * DOC: overview 0037 * 0038 * The DRM mode setting helper functions are common code for drivers to use if 0039 * they wish. Drivers are not forced to use this code in their 0040 * implementations but it would be useful if the code they do use at least 0041 * provides a consistent interface and operation to userspace. Therefore it is 0042 * highly recommended to use the provided helpers as much as possible. 0043 * 0044 * Because there is only one pointer per modeset object to hold a vfunc table 0045 * for helper libraries they are by necessity shared among the different 0046 * helpers. 0047 * 0048 * To make this clear all the helper vtables are pulled together in this location here. 0049 */ 0050 0051 enum mode_set_atomic; 0052 struct drm_writeback_connector; 0053 struct drm_writeback_job; 0054 0055 /** 0056 * struct drm_crtc_helper_funcs - helper operations for CRTCs 0057 * 0058 * These hooks are used by the legacy CRTC helpers, the transitional plane 0059 * helpers and the new atomic modesetting helpers. 0060 */ 0061 struct drm_crtc_helper_funcs { 0062 /** 0063 * @dpms: 0064 * 0065 * Callback to control power levels on the CRTC. If the mode passed in 0066 * is unsupported, the provider must use the next lowest power level. 0067 * This is used by the legacy CRTC helpers to implement DPMS 0068 * functionality in drm_helper_connector_dpms(). 0069 * 0070 * This callback is also used to disable a CRTC by calling it with 0071 * DRM_MODE_DPMS_OFF if the @disable hook isn't used. 0072 * 0073 * This callback is used by the legacy CRTC helpers. Atomic helpers 0074 * also support using this hook for enabling and disabling a CRTC to 0075 * facilitate transitions to atomic, but it is deprecated. Instead 0076 * @atomic_enable and @atomic_disable should be used. 0077 */ 0078 void (*dpms)(struct drm_crtc *crtc, int mode); 0079 0080 /** 0081 * @prepare: 0082 * 0083 * This callback should prepare the CRTC for a subsequent modeset, which 0084 * in practice means the driver should disable the CRTC if it is 0085 * running. Most drivers ended up implementing this by calling their 0086 * @dpms hook with DRM_MODE_DPMS_OFF. 0087 * 0088 * This callback is used by the legacy CRTC helpers. Atomic helpers 0089 * also support using this hook for disabling a CRTC to facilitate 0090 * transitions to atomic, but it is deprecated. Instead @atomic_disable 0091 * should be used. 0092 */ 0093 void (*prepare)(struct drm_crtc *crtc); 0094 0095 /** 0096 * @commit: 0097 * 0098 * This callback should commit the new mode on the CRTC after a modeset, 0099 * which in practice means the driver should enable the CRTC. Most 0100 * drivers ended up implementing this by calling their @dpms hook with 0101 * DRM_MODE_DPMS_ON. 0102 * 0103 * This callback is used by the legacy CRTC helpers. Atomic helpers 0104 * also support using this hook for enabling a CRTC to facilitate 0105 * transitions to atomic, but it is deprecated. Instead @atomic_enable 0106 * should be used. 0107 */ 0108 void (*commit)(struct drm_crtc *crtc); 0109 0110 /** 0111 * @mode_valid: 0112 * 0113 * This callback is used to check if a specific mode is valid in this 0114 * crtc. This should be implemented if the crtc has some sort of 0115 * restriction in the modes it can display. For example, a given crtc 0116 * may be responsible to set a clock value. If the clock can not 0117 * produce all the values for the available modes then this callback 0118 * can be used to restrict the number of modes to only the ones that 0119 * can be displayed. 0120 * 0121 * This hook is used by the probe helpers to filter the mode list in 0122 * drm_helper_probe_single_connector_modes(), and it is used by the 0123 * atomic helpers to validate modes supplied by userspace in 0124 * drm_atomic_helper_check_modeset(). 0125 * 0126 * This function is optional. 0127 * 0128 * NOTE: 0129 * 0130 * Since this function is both called from the check phase of an atomic 0131 * commit, and the mode validation in the probe paths it is not allowed 0132 * to look at anything else but the passed-in mode, and validate it 0133 * against configuration-invariant hardward constraints. Any further 0134 * limits which depend upon the configuration can only be checked in 0135 * @mode_fixup or @atomic_check. 0136 * 0137 * RETURNS: 0138 * 0139 * drm_mode_status Enum 0140 */ 0141 enum drm_mode_status (*mode_valid)(struct drm_crtc *crtc, 0142 const struct drm_display_mode *mode); 0143 0144 /** 0145 * @mode_fixup: 0146 * 0147 * This callback is used to validate a mode. The parameter mode is the 0148 * display mode that userspace requested, adjusted_mode is the mode the 0149 * encoders need to be fed with. Note that this is the inverse semantics 0150 * of the meaning for the &drm_encoder and &drm_bridge_funcs.mode_fixup 0151 * vfunc. If the CRTC cannot support the requested conversion from mode 0152 * to adjusted_mode it should reject the modeset. See also 0153 * &drm_crtc_state.adjusted_mode for more details. 0154 * 0155 * This function is used by both legacy CRTC helpers and atomic helpers. 0156 * With atomic helpers it is optional. 0157 * 0158 * NOTE: 0159 * 0160 * This function is called in the check phase of atomic modesets, which 0161 * can be aborted for any reason (including on userspace's request to 0162 * just check whether a configuration would be possible). Atomic drivers 0163 * MUST NOT touch any persistent state (hardware or software) or data 0164 * structures except the passed in adjusted_mode parameter. 0165 * 0166 * This is in contrast to the legacy CRTC helpers where this was 0167 * allowed. 0168 * 0169 * Atomic drivers which need to inspect and adjust more state should 0170 * instead use the @atomic_check callback, but note that they're not 0171 * perfectly equivalent: @mode_valid is called from 0172 * drm_atomic_helper_check_modeset(), but @atomic_check is called from 0173 * drm_atomic_helper_check_planes(), because originally it was meant for 0174 * plane update checks only. 0175 * 0176 * Also beware that userspace can request its own custom modes, neither 0177 * core nor helpers filter modes to the list of probe modes reported by 0178 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure 0179 * that modes are filtered consistently put any CRTC constraints and 0180 * limits checks into @mode_valid. 0181 * 0182 * RETURNS: 0183 * 0184 * True if an acceptable configuration is possible, false if the modeset 0185 * operation should be rejected. 0186 */ 0187 bool (*mode_fixup)(struct drm_crtc *crtc, 0188 const struct drm_display_mode *mode, 0189 struct drm_display_mode *adjusted_mode); 0190 0191 /** 0192 * @mode_set: 0193 * 0194 * This callback is used by the legacy CRTC helpers to set a new mode, 0195 * position and framebuffer. Since it ties the primary plane to every 0196 * mode change it is incompatible with universal plane support. And 0197 * since it can't update other planes it's incompatible with atomic 0198 * modeset support. 0199 * 0200 * This callback is only used by CRTC helpers and deprecated. 0201 * 0202 * RETURNS: 0203 * 0204 * 0 on success or a negative error code on failure. 0205 */ 0206 int (*mode_set)(struct drm_crtc *crtc, struct drm_display_mode *mode, 0207 struct drm_display_mode *adjusted_mode, int x, int y, 0208 struct drm_framebuffer *old_fb); 0209 0210 /** 0211 * @mode_set_nofb: 0212 * 0213 * This callback is used to update the display mode of a CRTC without 0214 * changing anything of the primary plane configuration. This fits the 0215 * requirement of atomic and hence is used by the atomic helpers. It is 0216 * also used by the transitional plane helpers to implement a 0217 * @mode_set hook in drm_helper_crtc_mode_set(). 0218 * 0219 * Note that the display pipe is completely off when this function is 0220 * called. Atomic drivers which need hardware to be running before they 0221 * program the new display mode (e.g. because they implement runtime PM) 0222 * should not use this hook. This is because the helper library calls 0223 * this hook only once per mode change and not every time the display 0224 * pipeline is suspended using either DPMS or the new "ACTIVE" property. 0225 * Which means register values set in this callback might get reset when 0226 * the CRTC is suspended, but not restored. Such drivers should instead 0227 * move all their CRTC setup into the @atomic_enable callback. 0228 * 0229 * This callback is optional. 0230 */ 0231 void (*mode_set_nofb)(struct drm_crtc *crtc); 0232 0233 /** 0234 * @mode_set_base: 0235 * 0236 * This callback is used by the legacy CRTC helpers to set a new 0237 * framebuffer and scanout position. It is optional and used as an 0238 * optimized fast-path instead of a full mode set operation with all the 0239 * resulting flickering. If it is not present 0240 * drm_crtc_helper_set_config() will fall back to a full modeset, using 0241 * the @mode_set callback. Since it can't update other planes it's 0242 * incompatible with atomic modeset support. 0243 * 0244 * This callback is only used by the CRTC helpers and deprecated. 0245 * 0246 * RETURNS: 0247 * 0248 * 0 on success or a negative error code on failure. 0249 */ 0250 int (*mode_set_base)(struct drm_crtc *crtc, int x, int y, 0251 struct drm_framebuffer *old_fb); 0252 0253 /** 0254 * @mode_set_base_atomic: 0255 * 0256 * This callback is used by the fbdev helpers to set a new framebuffer 0257 * and scanout without sleeping, i.e. from an atomic calling context. It 0258 * is only used to implement kgdb support. 0259 * 0260 * This callback is optional and only needed for kgdb support in the fbdev 0261 * helpers. 0262 * 0263 * RETURNS: 0264 * 0265 * 0 on success or a negative error code on failure. 0266 */ 0267 int (*mode_set_base_atomic)(struct drm_crtc *crtc, 0268 struct drm_framebuffer *fb, int x, int y, 0269 enum mode_set_atomic); 0270 0271 /** 0272 * @disable: 0273 * 0274 * This callback should be used to disable the CRTC. With the atomic 0275 * drivers it is called after all encoders connected to this CRTC have 0276 * been shut off already using their own 0277 * &drm_encoder_helper_funcs.disable hook. If that sequence is too 0278 * simple drivers can just add their own hooks and call it from this 0279 * CRTC callback here by looping over all encoders connected to it using 0280 * for_each_encoder_on_crtc(). 0281 * 0282 * This hook is used both by legacy CRTC helpers and atomic helpers. 0283 * Atomic drivers don't need to implement it if there's no need to 0284 * disable anything at the CRTC level. To ensure that runtime PM 0285 * handling (using either DPMS or the new "ACTIVE" property) works 0286 * @disable must be the inverse of @atomic_enable for atomic drivers. 0287 * Atomic drivers should consider to use @atomic_disable instead of 0288 * this one. 0289 * 0290 * NOTE: 0291 * 0292 * With legacy CRTC helpers there's a big semantic difference between 0293 * @disable and other hooks (like @prepare or @dpms) used to shut down a 0294 * CRTC: @disable is only called when also logically disabling the 0295 * display pipeline and needs to release any resources acquired in 0296 * @mode_set (like shared PLLs, or again release pinned framebuffers). 0297 * 0298 * Therefore @disable must be the inverse of @mode_set plus @commit for 0299 * drivers still using legacy CRTC helpers, which is different from the 0300 * rules under atomic. 0301 */ 0302 void (*disable)(struct drm_crtc *crtc); 0303 0304 /** 0305 * @atomic_check: 0306 * 0307 * Drivers should check plane-update related CRTC constraints in this 0308 * hook. They can also check mode related limitations but need to be 0309 * aware of the calling order, since this hook is used by 0310 * drm_atomic_helper_check_planes() whereas the preparations needed to 0311 * check output routing and the display mode is done in 0312 * drm_atomic_helper_check_modeset(). Therefore drivers that want to 0313 * check output routing and display mode constraints in this callback 0314 * must ensure that drm_atomic_helper_check_modeset() has been called 0315 * beforehand. This is calling order used by the default helper 0316 * implementation in drm_atomic_helper_check(). 0317 * 0318 * When using drm_atomic_helper_check_planes() this hook is called 0319 * after the &drm_plane_helper_funcs.atomic_check hook for planes, which 0320 * allows drivers to assign shared resources requested by planes in this 0321 * callback here. For more complicated dependencies the driver can call 0322 * the provided check helpers multiple times until the computed state 0323 * has a final configuration and everything has been checked. 0324 * 0325 * This function is also allowed to inspect any other object's state and 0326 * can add more state objects to the atomic commit if needed. Care must 0327 * be taken though to ensure that state check and compute functions for 0328 * these added states are all called, and derived state in other objects 0329 * all updated. Again the recommendation is to just call check helpers 0330 * until a maximal configuration is reached. 0331 * 0332 * This callback is used by the atomic modeset helpers and by the 0333 * transitional plane helpers, but it is optional. 0334 * 0335 * NOTE: 0336 * 0337 * This function is called in the check phase of an atomic update. The 0338 * driver is not allowed to change anything outside of the free-standing 0339 * state object passed-in. 0340 * 0341 * Also beware that userspace can request its own custom modes, neither 0342 * core nor helpers filter modes to the list of probe modes reported by 0343 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure 0344 * that modes are filtered consistently put any CRTC constraints and 0345 * limits checks into @mode_valid. 0346 * 0347 * RETURNS: 0348 * 0349 * 0 on success, -EINVAL if the state or the transition can't be 0350 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an 0351 * attempt to obtain another state object ran into a &drm_modeset_lock 0352 * deadlock. 0353 */ 0354 int (*atomic_check)(struct drm_crtc *crtc, 0355 struct drm_atomic_state *state); 0356 0357 /** 0358 * @atomic_begin: 0359 * 0360 * Drivers should prepare for an atomic update of multiple planes on 0361 * a CRTC in this hook. Depending upon hardware this might be vblank 0362 * evasion, blocking updates by setting bits or doing preparatory work 0363 * for e.g. manual update display. 0364 * 0365 * This hook is called before any plane commit functions are called. 0366 * 0367 * Note that the power state of the display pipe when this function is 0368 * called depends upon the exact helpers and calling sequence the driver 0369 * has picked. See drm_atomic_helper_commit_planes() for a discussion of 0370 * the tradeoffs and variants of plane commit helpers. 0371 * 0372 * This callback is used by the atomic modeset helpers and by the 0373 * transitional plane helpers, but it is optional. 0374 */ 0375 void (*atomic_begin)(struct drm_crtc *crtc, 0376 struct drm_atomic_state *state); 0377 /** 0378 * @atomic_flush: 0379 * 0380 * Drivers should finalize an atomic update of multiple planes on 0381 * a CRTC in this hook. Depending upon hardware this might include 0382 * checking that vblank evasion was successful, unblocking updates by 0383 * setting bits or setting the GO bit to flush out all updates. 0384 * 0385 * Simple hardware or hardware with special requirements can commit and 0386 * flush out all updates for all planes from this hook and forgo all the 0387 * other commit hooks for plane updates. 0388 * 0389 * This hook is called after any plane commit functions are called. 0390 * 0391 * Note that the power state of the display pipe when this function is 0392 * called depends upon the exact helpers and calling sequence the driver 0393 * has picked. See drm_atomic_helper_commit_planes() for a discussion of 0394 * the tradeoffs and variants of plane commit helpers. 0395 * 0396 * This callback is used by the atomic modeset helpers and by the 0397 * transitional plane helpers, but it is optional. 0398 */ 0399 void (*atomic_flush)(struct drm_crtc *crtc, 0400 struct drm_atomic_state *state); 0401 0402 /** 0403 * @atomic_enable: 0404 * 0405 * This callback should be used to enable the CRTC. With the atomic 0406 * drivers it is called before all encoders connected to this CRTC are 0407 * enabled through the encoder's own &drm_encoder_helper_funcs.enable 0408 * hook. If that sequence is too simple drivers can just add their own 0409 * hooks and call it from this CRTC callback here by looping over all 0410 * encoders connected to it using for_each_encoder_on_crtc(). 0411 * 0412 * This hook is used only by atomic helpers, for symmetry with 0413 * @atomic_disable. Atomic drivers don't need to implement it if there's 0414 * no need to enable anything at the CRTC level. To ensure that runtime 0415 * PM handling (using either DPMS or the new "ACTIVE" property) works 0416 * @atomic_enable must be the inverse of @atomic_disable for atomic 0417 * drivers. 0418 * 0419 * This function is optional. 0420 */ 0421 void (*atomic_enable)(struct drm_crtc *crtc, 0422 struct drm_atomic_state *state); 0423 0424 /** 0425 * @atomic_disable: 0426 * 0427 * This callback should be used to disable the CRTC. With the atomic 0428 * drivers it is called after all encoders connected to this CRTC have 0429 * been shut off already using their own 0430 * &drm_encoder_helper_funcs.disable hook. If that sequence is too 0431 * simple drivers can just add their own hooks and call it from this 0432 * CRTC callback here by looping over all encoders connected to it using 0433 * for_each_encoder_on_crtc(). 0434 * 0435 * This hook is used only by atomic helpers. Atomic drivers don't 0436 * need to implement it if there's no need to disable anything at the 0437 * CRTC level. 0438 * 0439 * This function is optional. 0440 */ 0441 void (*atomic_disable)(struct drm_crtc *crtc, 0442 struct drm_atomic_state *state); 0443 0444 /** 0445 * @get_scanout_position: 0446 * 0447 * Called by vblank timestamping code. 0448 * 0449 * Returns the current display scanout position from a CRTC and an 0450 * optional accurate ktime_get() timestamp of when the position was 0451 * measured. Note that this is a helper callback which is only used 0452 * if a driver uses drm_crtc_vblank_helper_get_vblank_timestamp() 0453 * for the @drm_crtc_funcs.get_vblank_timestamp callback. 0454 * 0455 * Parameters: 0456 * 0457 * crtc: 0458 * The CRTC. 0459 * in_vblank_irq: 0460 * True when called from drm_crtc_handle_vblank(). Some drivers 0461 * need to apply some workarounds for gpu-specific vblank irq 0462 * quirks if the flag is set. 0463 * vpos: 0464 * Target location for current vertical scanout position. 0465 * hpos: 0466 * Target location for current horizontal scanout position. 0467 * stime: 0468 * Target location for timestamp taken immediately before 0469 * scanout position query. Can be NULL to skip timestamp. 0470 * etime: 0471 * Target location for timestamp taken immediately after 0472 * scanout position query. Can be NULL to skip timestamp. 0473 * mode: 0474 * Current display timings. 0475 * 0476 * Returns vpos as a positive number while in active scanout area. 0477 * Returns vpos as a negative number inside vblank, counting the number 0478 * of scanlines to go until end of vblank, e.g., -1 means "one scanline 0479 * until start of active scanout / end of vblank." 0480 * 0481 * Returns: 0482 * 0483 * True on success, false if a reliable scanout position counter could 0484 * not be read out. 0485 */ 0486 bool (*get_scanout_position)(struct drm_crtc *crtc, 0487 bool in_vblank_irq, int *vpos, int *hpos, 0488 ktime_t *stime, ktime_t *etime, 0489 const struct drm_display_mode *mode); 0490 }; 0491 0492 /** 0493 * drm_crtc_helper_add - sets the helper vtable for a crtc 0494 * @crtc: DRM CRTC 0495 * @funcs: helper vtable to set for @crtc 0496 */ 0497 static inline void drm_crtc_helper_add(struct drm_crtc *crtc, 0498 const struct drm_crtc_helper_funcs *funcs) 0499 { 0500 crtc->helper_private = funcs; 0501 } 0502 0503 /** 0504 * struct drm_encoder_helper_funcs - helper operations for encoders 0505 * 0506 * These hooks are used by the legacy CRTC helpers, the transitional plane 0507 * helpers and the new atomic modesetting helpers. 0508 */ 0509 struct drm_encoder_helper_funcs { 0510 /** 0511 * @dpms: 0512 * 0513 * Callback to control power levels on the encoder. If the mode passed in 0514 * is unsupported, the provider must use the next lowest power level. 0515 * This is used by the legacy encoder helpers to implement DPMS 0516 * functionality in drm_helper_connector_dpms(). 0517 * 0518 * This callback is also used to disable an encoder by calling it with 0519 * DRM_MODE_DPMS_OFF if the @disable hook isn't used. 0520 * 0521 * This callback is used by the legacy CRTC helpers. Atomic helpers 0522 * also support using this hook for enabling and disabling an encoder to 0523 * facilitate transitions to atomic, but it is deprecated. Instead 0524 * @enable and @disable should be used. 0525 */ 0526 void (*dpms)(struct drm_encoder *encoder, int mode); 0527 0528 /** 0529 * @mode_valid: 0530 * 0531 * This callback is used to check if a specific mode is valid in this 0532 * encoder. This should be implemented if the encoder has some sort 0533 * of restriction in the modes it can display. For example, a given 0534 * encoder may be responsible to set a clock value. If the clock can 0535 * not produce all the values for the available modes then this callback 0536 * can be used to restrict the number of modes to only the ones that 0537 * can be displayed. 0538 * 0539 * This hook is used by the probe helpers to filter the mode list in 0540 * drm_helper_probe_single_connector_modes(), and it is used by the 0541 * atomic helpers to validate modes supplied by userspace in 0542 * drm_atomic_helper_check_modeset(). 0543 * 0544 * This function is optional. 0545 * 0546 * NOTE: 0547 * 0548 * Since this function is both called from the check phase of an atomic 0549 * commit, and the mode validation in the probe paths it is not allowed 0550 * to look at anything else but the passed-in mode, and validate it 0551 * against configuration-invariant hardward constraints. Any further 0552 * limits which depend upon the configuration can only be checked in 0553 * @mode_fixup or @atomic_check. 0554 * 0555 * RETURNS: 0556 * 0557 * drm_mode_status Enum 0558 */ 0559 enum drm_mode_status (*mode_valid)(struct drm_encoder *crtc, 0560 const struct drm_display_mode *mode); 0561 0562 /** 0563 * @mode_fixup: 0564 * 0565 * This callback is used to validate and adjust a mode. The parameter 0566 * mode is the display mode that should be fed to the next element in 0567 * the display chain, either the final &drm_connector or a &drm_bridge. 0568 * The parameter adjusted_mode is the input mode the encoder requires. It 0569 * can be modified by this callback and does not need to match mode. See 0570 * also &drm_crtc_state.adjusted_mode for more details. 0571 * 0572 * This function is used by both legacy CRTC helpers and atomic helpers. 0573 * This hook is optional. 0574 * 0575 * NOTE: 0576 * 0577 * This function is called in the check phase of atomic modesets, which 0578 * can be aborted for any reason (including on userspace's request to 0579 * just check whether a configuration would be possible). Atomic drivers 0580 * MUST NOT touch any persistent state (hardware or software) or data 0581 * structures except the passed in adjusted_mode parameter. 0582 * 0583 * This is in contrast to the legacy CRTC helpers where this was 0584 * allowed. 0585 * 0586 * Atomic drivers which need to inspect and adjust more state should 0587 * instead use the @atomic_check callback. If @atomic_check is used, 0588 * this hook isn't called since @atomic_check allows a strict superset 0589 * of the functionality of @mode_fixup. 0590 * 0591 * Also beware that userspace can request its own custom modes, neither 0592 * core nor helpers filter modes to the list of probe modes reported by 0593 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure 0594 * that modes are filtered consistently put any encoder constraints and 0595 * limits checks into @mode_valid. 0596 * 0597 * RETURNS: 0598 * 0599 * True if an acceptable configuration is possible, false if the modeset 0600 * operation should be rejected. 0601 */ 0602 bool (*mode_fixup)(struct drm_encoder *encoder, 0603 const struct drm_display_mode *mode, 0604 struct drm_display_mode *adjusted_mode); 0605 0606 /** 0607 * @prepare: 0608 * 0609 * This callback should prepare the encoder for a subsequent modeset, 0610 * which in practice means the driver should disable the encoder if it 0611 * is running. Most drivers ended up implementing this by calling their 0612 * @dpms hook with DRM_MODE_DPMS_OFF. 0613 * 0614 * This callback is used by the legacy CRTC helpers. Atomic helpers 0615 * also support using this hook for disabling an encoder to facilitate 0616 * transitions to atomic, but it is deprecated. Instead @disable should 0617 * be used. 0618 */ 0619 void (*prepare)(struct drm_encoder *encoder); 0620 0621 /** 0622 * @commit: 0623 * 0624 * This callback should commit the new mode on the encoder after a modeset, 0625 * which in practice means the driver should enable the encoder. Most 0626 * drivers ended up implementing this by calling their @dpms hook with 0627 * DRM_MODE_DPMS_ON. 0628 * 0629 * This callback is used by the legacy CRTC helpers. Atomic helpers 0630 * also support using this hook for enabling an encoder to facilitate 0631 * transitions to atomic, but it is deprecated. Instead @enable should 0632 * be used. 0633 */ 0634 void (*commit)(struct drm_encoder *encoder); 0635 0636 /** 0637 * @mode_set: 0638 * 0639 * This callback is used to update the display mode of an encoder. 0640 * 0641 * Note that the display pipe is completely off when this function is 0642 * called. Drivers which need hardware to be running before they program 0643 * the new display mode (because they implement runtime PM) should not 0644 * use this hook, because the helper library calls it only once and not 0645 * every time the display pipeline is suspend using either DPMS or the 0646 * new "ACTIVE" property. Such drivers should instead move all their 0647 * encoder setup into the @enable callback. 0648 * 0649 * This callback is used both by the legacy CRTC helpers and the atomic 0650 * modeset helpers. It is optional in the atomic helpers. 0651 * 0652 * NOTE: 0653 * 0654 * If the driver uses the atomic modeset helpers and needs to inspect 0655 * the connector state or connector display info during mode setting, 0656 * @atomic_mode_set can be used instead. 0657 */ 0658 void (*mode_set)(struct drm_encoder *encoder, 0659 struct drm_display_mode *mode, 0660 struct drm_display_mode *adjusted_mode); 0661 0662 /** 0663 * @atomic_mode_set: 0664 * 0665 * This callback is used to update the display mode of an encoder. 0666 * 0667 * Note that the display pipe is completely off when this function is 0668 * called. Drivers which need hardware to be running before they program 0669 * the new display mode (because they implement runtime PM) should not 0670 * use this hook, because the helper library calls it only once and not 0671 * every time the display pipeline is suspended using either DPMS or the 0672 * new "ACTIVE" property. Such drivers should instead move all their 0673 * encoder setup into the @enable callback. 0674 * 0675 * This callback is used by the atomic modeset helpers in place of the 0676 * @mode_set callback, if set by the driver. It is optional and should 0677 * be used instead of @mode_set if the driver needs to inspect the 0678 * connector state or display info, since there is no direct way to 0679 * go from the encoder to the current connector. 0680 */ 0681 void (*atomic_mode_set)(struct drm_encoder *encoder, 0682 struct drm_crtc_state *crtc_state, 0683 struct drm_connector_state *conn_state); 0684 0685 /** 0686 * @detect: 0687 * 0688 * This callback can be used by drivers who want to do detection on the 0689 * encoder object instead of in connector functions. 0690 * 0691 * It is not used by any helper and therefore has purely driver-specific 0692 * semantics. New drivers shouldn't use this and instead just implement 0693 * their own private callbacks. 0694 * 0695 * FIXME: 0696 * 0697 * This should just be converted into a pile of driver vfuncs. 0698 * Currently radeon, amdgpu and nouveau are using it. 0699 */ 0700 enum drm_connector_status (*detect)(struct drm_encoder *encoder, 0701 struct drm_connector *connector); 0702 0703 /** 0704 * @atomic_disable: 0705 * 0706 * This callback should be used to disable the encoder. With the atomic 0707 * drivers it is called before this encoder's CRTC has been shut off 0708 * using their own &drm_crtc_helper_funcs.atomic_disable hook. If that 0709 * sequence is too simple drivers can just add their own driver private 0710 * encoder hooks and call them from CRTC's callback by looping over all 0711 * encoders connected to it using for_each_encoder_on_crtc(). 0712 * 0713 * This callback is a variant of @disable that provides the atomic state 0714 * to the driver. If @atomic_disable is implemented, @disable is not 0715 * called by the helpers. 0716 * 0717 * This hook is only used by atomic helpers. Atomic drivers don't need 0718 * to implement it if there's no need to disable anything at the encoder 0719 * level. To ensure that runtime PM handling (using either DPMS or the 0720 * new "ACTIVE" property) works @atomic_disable must be the inverse of 0721 * @atomic_enable. 0722 */ 0723 void (*atomic_disable)(struct drm_encoder *encoder, 0724 struct drm_atomic_state *state); 0725 0726 /** 0727 * @atomic_enable: 0728 * 0729 * This callback should be used to enable the encoder. It is called 0730 * after this encoder's CRTC has been enabled using their own 0731 * &drm_crtc_helper_funcs.atomic_enable hook. If that sequence is 0732 * too simple drivers can just add their own driver private encoder 0733 * hooks and call them from CRTC's callback by looping over all encoders 0734 * connected to it using for_each_encoder_on_crtc(). 0735 * 0736 * This callback is a variant of @enable that provides the atomic state 0737 * to the driver. If @atomic_enable is implemented, @enable is not 0738 * called by the helpers. 0739 * 0740 * This hook is only used by atomic helpers, it is the opposite of 0741 * @atomic_disable. Atomic drivers don't need to implement it if there's 0742 * no need to enable anything at the encoder level. To ensure that 0743 * runtime PM handling works @atomic_enable must be the inverse of 0744 * @atomic_disable. 0745 */ 0746 void (*atomic_enable)(struct drm_encoder *encoder, 0747 struct drm_atomic_state *state); 0748 0749 /** 0750 * @disable: 0751 * 0752 * This callback should be used to disable the encoder. With the atomic 0753 * drivers it is called before this encoder's CRTC has been shut off 0754 * using their own &drm_crtc_helper_funcs.disable hook. If that 0755 * sequence is too simple drivers can just add their own driver private 0756 * encoder hooks and call them from CRTC's callback by looping over all 0757 * encoders connected to it using for_each_encoder_on_crtc(). 0758 * 0759 * This hook is used both by legacy CRTC helpers and atomic helpers. 0760 * Atomic drivers don't need to implement it if there's no need to 0761 * disable anything at the encoder level. To ensure that runtime PM 0762 * handling (using either DPMS or the new "ACTIVE" property) works 0763 * @disable must be the inverse of @enable for atomic drivers. 0764 * 0765 * For atomic drivers also consider @atomic_disable and save yourself 0766 * from having to read the NOTE below! 0767 * 0768 * NOTE: 0769 * 0770 * With legacy CRTC helpers there's a big semantic difference between 0771 * @disable and other hooks (like @prepare or @dpms) used to shut down a 0772 * encoder: @disable is only called when also logically disabling the 0773 * display pipeline and needs to release any resources acquired in 0774 * @mode_set (like shared PLLs, or again release pinned framebuffers). 0775 * 0776 * Therefore @disable must be the inverse of @mode_set plus @commit for 0777 * drivers still using legacy CRTC helpers, which is different from the 0778 * rules under atomic. 0779 */ 0780 void (*disable)(struct drm_encoder *encoder); 0781 0782 /** 0783 * @enable: 0784 * 0785 * This callback should be used to enable the encoder. With the atomic 0786 * drivers it is called after this encoder's CRTC has been enabled using 0787 * their own &drm_crtc_helper_funcs.enable hook. If that sequence is 0788 * too simple drivers can just add their own driver private encoder 0789 * hooks and call them from CRTC's callback by looping over all encoders 0790 * connected to it using for_each_encoder_on_crtc(). 0791 * 0792 * This hook is only used by atomic helpers, it is the opposite of 0793 * @disable. Atomic drivers don't need to implement it if there's no 0794 * need to enable anything at the encoder level. To ensure that 0795 * runtime PM handling (using either DPMS or the new "ACTIVE" property) 0796 * works @enable must be the inverse of @disable for atomic drivers. 0797 */ 0798 void (*enable)(struct drm_encoder *encoder); 0799 0800 /** 0801 * @atomic_check: 0802 * 0803 * This callback is used to validate encoder state for atomic drivers. 0804 * Since the encoder is the object connecting the CRTC and connector it 0805 * gets passed both states, to be able to validate interactions and 0806 * update the CRTC to match what the encoder needs for the requested 0807 * connector. 0808 * 0809 * Since this provides a strict superset of the functionality of 0810 * @mode_fixup (the requested and adjusted modes are both available 0811 * through the passed in &struct drm_crtc_state) @mode_fixup is not 0812 * called when @atomic_check is implemented. 0813 * 0814 * This function is used by the atomic helpers, but it is optional. 0815 * 0816 * NOTE: 0817 * 0818 * This function is called in the check phase of an atomic update. The 0819 * driver is not allowed to change anything outside of the free-standing 0820 * state objects passed-in or assembled in the overall &drm_atomic_state 0821 * update tracking structure. 0822 * 0823 * Also beware that userspace can request its own custom modes, neither 0824 * core nor helpers filter modes to the list of probe modes reported by 0825 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure 0826 * that modes are filtered consistently put any encoder constraints and 0827 * limits checks into @mode_valid. 0828 * 0829 * RETURNS: 0830 * 0831 * 0 on success, -EINVAL if the state or the transition can't be 0832 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an 0833 * attempt to obtain another state object ran into a &drm_modeset_lock 0834 * deadlock. 0835 */ 0836 int (*atomic_check)(struct drm_encoder *encoder, 0837 struct drm_crtc_state *crtc_state, 0838 struct drm_connector_state *conn_state); 0839 }; 0840 0841 /** 0842 * drm_encoder_helper_add - sets the helper vtable for an encoder 0843 * @encoder: DRM encoder 0844 * @funcs: helper vtable to set for @encoder 0845 */ 0846 static inline void drm_encoder_helper_add(struct drm_encoder *encoder, 0847 const struct drm_encoder_helper_funcs *funcs) 0848 { 0849 encoder->helper_private = funcs; 0850 } 0851 0852 /** 0853 * struct drm_connector_helper_funcs - helper operations for connectors 0854 * 0855 * These functions are used by the atomic and legacy modeset helpers and by the 0856 * probe helpers. 0857 */ 0858 struct drm_connector_helper_funcs { 0859 /** 0860 * @get_modes: 0861 * 0862 * This function should fill in all modes currently valid for the sink 0863 * into the &drm_connector.probed_modes list. It should also update the 0864 * EDID property by calling drm_connector_update_edid_property(). 0865 * 0866 * The usual way to implement this is to cache the EDID retrieved in the 0867 * probe callback somewhere in the driver-private connector structure. 0868 * In this function drivers then parse the modes in the EDID and add 0869 * them by calling drm_add_edid_modes(). But connectors that drive a 0870 * fixed panel can also manually add specific modes using 0871 * drm_mode_probed_add(). Drivers which manually add modes should also 0872 * make sure that the &drm_connector.display_info, 0873 * &drm_connector.width_mm and &drm_connector.height_mm fields are 0874 * filled in. 0875 * 0876 * Note that the caller function will automatically add standard VESA 0877 * DMT modes up to 1024x768 if the .get_modes() helper operation returns 0878 * no mode and if the connector status is connector_status_connected or 0879 * connector_status_unknown. There is no need to call 0880 * drm_add_modes_noedid() manually in that case. 0881 * 0882 * Virtual drivers that just want some standard VESA mode with a given 0883 * resolution can call drm_add_modes_noedid(), and mark the preferred 0884 * one using drm_set_preferred_mode(). 0885 * 0886 * This function is only called after the @detect hook has indicated 0887 * that a sink is connected and when the EDID isn't overridden through 0888 * sysfs or the kernel commandline. 0889 * 0890 * This callback is used by the probe helpers in e.g. 0891 * drm_helper_probe_single_connector_modes(). 0892 * 0893 * To avoid races with concurrent connector state updates, the helper 0894 * libraries always call this with the &drm_mode_config.connection_mutex 0895 * held. Because of this it's safe to inspect &drm_connector->state. 0896 * 0897 * RETURNS: 0898 * 0899 * The number of modes added by calling drm_mode_probed_add(). 0900 */ 0901 int (*get_modes)(struct drm_connector *connector); 0902 0903 /** 0904 * @detect_ctx: 0905 * 0906 * Check to see if anything is attached to the connector. The parameter 0907 * force is set to false whilst polling, true when checking the 0908 * connector due to a user request. force can be used by the driver to 0909 * avoid expensive, destructive operations during automated probing. 0910 * 0911 * This callback is optional, if not implemented the connector will be 0912 * considered as always being attached. 0913 * 0914 * This is the atomic version of &drm_connector_funcs.detect. 0915 * 0916 * To avoid races against concurrent connector state updates, the 0917 * helper libraries always call this with ctx set to a valid context, 0918 * and &drm_mode_config.connection_mutex will always be locked with 0919 * the ctx parameter set to this ctx. This allows taking additional 0920 * locks as required. 0921 * 0922 * RETURNS: 0923 * 0924 * &drm_connector_status indicating the connector's status, 0925 * or the error code returned by drm_modeset_lock(), -EDEADLK. 0926 */ 0927 int (*detect_ctx)(struct drm_connector *connector, 0928 struct drm_modeset_acquire_ctx *ctx, 0929 bool force); 0930 0931 /** 0932 * @mode_valid: 0933 * 0934 * Callback to validate a mode for a connector, irrespective of the 0935 * specific display configuration. 0936 * 0937 * This callback is used by the probe helpers to filter the mode list 0938 * (which is usually derived from the EDID data block from the sink). 0939 * See e.g. drm_helper_probe_single_connector_modes(). 0940 * 0941 * This function is optional. 0942 * 0943 * NOTE: 0944 * 0945 * This only filters the mode list supplied to userspace in the 0946 * GETCONNECTOR IOCTL. Compared to &drm_encoder_helper_funcs.mode_valid, 0947 * &drm_crtc_helper_funcs.mode_valid and &drm_bridge_funcs.mode_valid, 0948 * which are also called by the atomic helpers from 0949 * drm_atomic_helper_check_modeset(). This allows userspace to force and 0950 * ignore sink constraint (like the pixel clock limits in the screen's 0951 * EDID), which is useful for e.g. testing, or working around a broken 0952 * EDID. Any source hardware constraint (which always need to be 0953 * enforced) therefore should be checked in one of the above callbacks, 0954 * and not this one here. 0955 * 0956 * To avoid races with concurrent connector state updates, the helper 0957 * libraries always call this with the &drm_mode_config.connection_mutex 0958 * held. Because of this it's safe to inspect &drm_connector->state. 0959 * 0960 * RETURNS: 0961 * 0962 * Either &drm_mode_status.MODE_OK or one of the failure reasons in &enum 0963 * drm_mode_status. 0964 */ 0965 enum drm_mode_status (*mode_valid)(struct drm_connector *connector, 0966 struct drm_display_mode *mode); 0967 0968 /** 0969 * @mode_valid_ctx: 0970 * 0971 * Callback to validate a mode for a connector, irrespective of the 0972 * specific display configuration. 0973 * 0974 * This callback is used by the probe helpers to filter the mode list 0975 * (which is usually derived from the EDID data block from the sink). 0976 * See e.g. drm_helper_probe_single_connector_modes(). 0977 * 0978 * This function is optional, and is the atomic version of 0979 * &drm_connector_helper_funcs.mode_valid. 0980 * 0981 * To allow for accessing the atomic state of modesetting objects, the 0982 * helper libraries always call this with ctx set to a valid context, 0983 * and &drm_mode_config.connection_mutex will always be locked with 0984 * the ctx parameter set to @ctx. This allows for taking additional 0985 * locks as required. 0986 * 0987 * Even though additional locks may be acquired, this callback is 0988 * still expected not to take any constraints into account which would 0989 * be influenced by the currently set display state - such constraints 0990 * should be handled in the driver's atomic check. For example, if a 0991 * connector shares display bandwidth with other connectors then it 0992 * would be ok to validate the minimum bandwidth requirement of a mode 0993 * against the maximum possible bandwidth of the connector. But it 0994 * wouldn't be ok to take the current bandwidth usage of other 0995 * connectors into account, as this would change depending on the 0996 * display state. 0997 * 0998 * Returns: 0999 * 0 if &drm_connector_helper_funcs.mode_valid_ctx succeeded and wrote 1000 * the &enum drm_mode_status value to @status, or a negative error 1001 * code otherwise. 1002 * 1003 */ 1004 int (*mode_valid_ctx)(struct drm_connector *connector, 1005 struct drm_display_mode *mode, 1006 struct drm_modeset_acquire_ctx *ctx, 1007 enum drm_mode_status *status); 1008 1009 /** 1010 * @best_encoder: 1011 * 1012 * This function should select the best encoder for the given connector. 1013 * 1014 * This function is used by both the atomic helpers (in the 1015 * drm_atomic_helper_check_modeset() function) and in the legacy CRTC 1016 * helpers. 1017 * 1018 * NOTE: 1019 * 1020 * In atomic drivers this function is called in the check phase of an 1021 * atomic update. The driver is not allowed to change or inspect 1022 * anything outside of arguments passed-in. Atomic drivers which need to 1023 * inspect dynamic configuration state should instead use 1024 * @atomic_best_encoder. 1025 * 1026 * You can leave this function to NULL if the connector is only 1027 * attached to a single encoder. In this case, the core will call 1028 * drm_connector_get_single_encoder() for you. 1029 * 1030 * RETURNS: 1031 * 1032 * Encoder that should be used for the given connector and connector 1033 * state, or NULL if no suitable encoder exists. Note that the helpers 1034 * will ensure that encoders aren't used twice, drivers should not check 1035 * for this. 1036 */ 1037 struct drm_encoder *(*best_encoder)(struct drm_connector *connector); 1038 1039 /** 1040 * @atomic_best_encoder: 1041 * 1042 * This is the atomic version of @best_encoder for atomic drivers which 1043 * need to select the best encoder depending upon the desired 1044 * configuration and can't select it statically. 1045 * 1046 * This function is used by drm_atomic_helper_check_modeset(). 1047 * If it is not implemented, the core will fallback to @best_encoder 1048 * (or drm_connector_get_single_encoder() if @best_encoder is NULL). 1049 * 1050 * NOTE: 1051 * 1052 * This function is called in the check phase of an atomic update. The 1053 * driver is not allowed to change anything outside of the 1054 * &drm_atomic_state update tracking structure passed in. 1055 * 1056 * RETURNS: 1057 * 1058 * Encoder that should be used for the given connector and connector 1059 * state, or NULL if no suitable encoder exists. Note that the helpers 1060 * will ensure that encoders aren't used twice, drivers should not check 1061 * for this. 1062 */ 1063 struct drm_encoder *(*atomic_best_encoder)(struct drm_connector *connector, 1064 struct drm_atomic_state *state); 1065 1066 /** 1067 * @atomic_check: 1068 * 1069 * This hook is used to validate connector state. This function is 1070 * called from &drm_atomic_helper_check_modeset, and is called when 1071 * a connector property is set, or a modeset on the crtc is forced. 1072 * 1073 * Because &drm_atomic_helper_check_modeset may be called multiple times, 1074 * this function should handle being called multiple times as well. 1075 * 1076 * This function is also allowed to inspect any other object's state and 1077 * can add more state objects to the atomic commit if needed. Care must 1078 * be taken though to ensure that state check and compute functions for 1079 * these added states are all called, and derived state in other objects 1080 * all updated. Again the recommendation is to just call check helpers 1081 * until a maximal configuration is reached. 1082 * 1083 * NOTE: 1084 * 1085 * This function is called in the check phase of an atomic update. The 1086 * driver is not allowed to change anything outside of the free-standing 1087 * state objects passed-in or assembled in the overall &drm_atomic_state 1088 * update tracking structure. 1089 * 1090 * RETURNS: 1091 * 1092 * 0 on success, -EINVAL if the state or the transition can't be 1093 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an 1094 * attempt to obtain another state object ran into a &drm_modeset_lock 1095 * deadlock. 1096 */ 1097 int (*atomic_check)(struct drm_connector *connector, 1098 struct drm_atomic_state *state); 1099 1100 /** 1101 * @atomic_commit: 1102 * 1103 * This hook is to be used by drivers implementing writeback connectors 1104 * that need a point when to commit the writeback job to the hardware. 1105 * The writeback_job to commit is available in the new connector state, 1106 * in &drm_connector_state.writeback_job. 1107 * 1108 * This hook is optional. 1109 * 1110 * This callback is used by the atomic modeset helpers. 1111 */ 1112 void (*atomic_commit)(struct drm_connector *connector, 1113 struct drm_atomic_state *state); 1114 1115 /** 1116 * @prepare_writeback_job: 1117 * 1118 * As writeback jobs contain a framebuffer, drivers may need to 1119 * prepare and clean them up the same way they can prepare and 1120 * clean up framebuffers for planes. This optional connector operation 1121 * is used to support the preparation of writeback jobs. The job 1122 * prepare operation is called from drm_atomic_helper_prepare_planes() 1123 * for struct &drm_writeback_connector connectors only. 1124 * 1125 * This operation is optional. 1126 * 1127 * This callback is used by the atomic modeset helpers. 1128 */ 1129 int (*prepare_writeback_job)(struct drm_writeback_connector *connector, 1130 struct drm_writeback_job *job); 1131 /** 1132 * @cleanup_writeback_job: 1133 * 1134 * This optional connector operation is used to support the 1135 * cleanup of writeback jobs. The job cleanup operation is called 1136 * from the existing drm_writeback_cleanup_job() function, invoked 1137 * both when destroying the job as part of an aborted commit, or when 1138 * the job completes. 1139 * 1140 * This operation is optional. 1141 * 1142 * This callback is used by the atomic modeset helpers. 1143 */ 1144 void (*cleanup_writeback_job)(struct drm_writeback_connector *connector, 1145 struct drm_writeback_job *job); 1146 }; 1147 1148 /** 1149 * drm_connector_helper_add - sets the helper vtable for a connector 1150 * @connector: DRM connector 1151 * @funcs: helper vtable to set for @connector 1152 */ 1153 static inline void drm_connector_helper_add(struct drm_connector *connector, 1154 const struct drm_connector_helper_funcs *funcs) 1155 { 1156 connector->helper_private = funcs; 1157 } 1158 1159 /** 1160 * struct drm_plane_helper_funcs - helper operations for planes 1161 * 1162 * These functions are used by the atomic helpers and by the transitional plane 1163 * helpers. 1164 */ 1165 struct drm_plane_helper_funcs { 1166 /** 1167 * @prepare_fb: 1168 * 1169 * This hook is to prepare a framebuffer for scanout by e.g. pinning 1170 * its backing storage or relocating it into a contiguous block of 1171 * VRAM. Other possible preparatory work includes flushing caches. 1172 * 1173 * This function must not block for outstanding rendering, since it is 1174 * called in the context of the atomic IOCTL even for async commits to 1175 * be able to return any errors to userspace. Instead the recommended 1176 * way is to fill out the &drm_plane_state.fence of the passed-in 1177 * &drm_plane_state. If the driver doesn't support native fences then 1178 * equivalent functionality should be implemented through private 1179 * members in the plane structure. 1180 * 1181 * For GEM drivers who neither have a @prepare_fb nor @cleanup_fb hook 1182 * set drm_gem_plane_helper_prepare_fb() is called automatically to 1183 * implement this. Other drivers which need additional plane processing 1184 * can call drm_gem_plane_helper_prepare_fb() from their @prepare_fb 1185 * hook. 1186 * 1187 * The helpers will call @cleanup_fb with matching arguments for every 1188 * successful call to this hook. 1189 * 1190 * This callback is used by the atomic modeset helpers and by the 1191 * transitional plane helpers, but it is optional. 1192 * 1193 * RETURNS: 1194 * 1195 * 0 on success or one of the following negative error codes allowed by 1196 * the &drm_mode_config_funcs.atomic_commit vfunc. When using helpers 1197 * this callback is the only one which can fail an atomic commit, 1198 * everything else must complete successfully. 1199 */ 1200 int (*prepare_fb)(struct drm_plane *plane, 1201 struct drm_plane_state *new_state); 1202 /** 1203 * @cleanup_fb: 1204 * 1205 * This hook is called to clean up any resources allocated for the given 1206 * framebuffer and plane configuration in @prepare_fb. 1207 * 1208 * This callback is used by the atomic modeset helpers and by the 1209 * transitional plane helpers, but it is optional. 1210 */ 1211 void (*cleanup_fb)(struct drm_plane *plane, 1212 struct drm_plane_state *old_state); 1213 1214 /** 1215 * @atomic_check: 1216 * 1217 * Drivers should check plane specific constraints in this hook. 1218 * 1219 * When using drm_atomic_helper_check_planes() plane's @atomic_check 1220 * hooks are called before the ones for CRTCs, which allows drivers to 1221 * request shared resources that the CRTC controls here. For more 1222 * complicated dependencies the driver can call the provided check helpers 1223 * multiple times until the computed state has a final configuration and 1224 * everything has been checked. 1225 * 1226 * This function is also allowed to inspect any other object's state and 1227 * can add more state objects to the atomic commit if needed. Care must 1228 * be taken though to ensure that state check and compute functions for 1229 * these added states are all called, and derived state in other objects 1230 * all updated. Again the recommendation is to just call check helpers 1231 * until a maximal configuration is reached. 1232 * 1233 * This callback is used by the atomic modeset helpers and by the 1234 * transitional plane helpers, but it is optional. 1235 * 1236 * NOTE: 1237 * 1238 * This function is called in the check phase of an atomic update. The 1239 * driver is not allowed to change anything outside of the 1240 * &drm_atomic_state update tracking structure. 1241 * 1242 * RETURNS: 1243 * 1244 * 0 on success, -EINVAL if the state or the transition can't be 1245 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an 1246 * attempt to obtain another state object ran into a &drm_modeset_lock 1247 * deadlock. 1248 */ 1249 int (*atomic_check)(struct drm_plane *plane, 1250 struct drm_atomic_state *state); 1251 1252 /** 1253 * @atomic_update: 1254 * 1255 * Drivers should use this function to update the plane state. This 1256 * hook is called in-between the &drm_crtc_helper_funcs.atomic_begin and 1257 * drm_crtc_helper_funcs.atomic_flush callbacks. 1258 * 1259 * Note that the power state of the display pipe when this function is 1260 * called depends upon the exact helpers and calling sequence the driver 1261 * has picked. See drm_atomic_helper_commit_planes() for a discussion of 1262 * the tradeoffs and variants of plane commit helpers. 1263 * 1264 * This callback is used by the atomic modeset helpers and by the 1265 * transitional plane helpers, but it is optional. 1266 */ 1267 void (*atomic_update)(struct drm_plane *plane, 1268 struct drm_atomic_state *state); 1269 /** 1270 * @atomic_disable: 1271 * 1272 * Drivers should use this function to unconditionally disable a plane. 1273 * This hook is called in-between the 1274 * &drm_crtc_helper_funcs.atomic_begin and 1275 * drm_crtc_helper_funcs.atomic_flush callbacks. It is an alternative to 1276 * @atomic_update, which will be called for disabling planes, too, if 1277 * the @atomic_disable hook isn't implemented. 1278 * 1279 * This hook is also useful to disable planes in preparation of a modeset, 1280 * by calling drm_atomic_helper_disable_planes_on_crtc() from the 1281 * &drm_crtc_helper_funcs.disable hook. 1282 * 1283 * Note that the power state of the display pipe when this function is 1284 * called depends upon the exact helpers and calling sequence the driver 1285 * has picked. See drm_atomic_helper_commit_planes() for a discussion of 1286 * the tradeoffs and variants of plane commit helpers. 1287 * 1288 * This callback is used by the atomic modeset helpers and by the 1289 * transitional plane helpers, but it is optional. 1290 */ 1291 void (*atomic_disable)(struct drm_plane *plane, 1292 struct drm_atomic_state *state); 1293 1294 /** 1295 * @atomic_async_check: 1296 * 1297 * Drivers should set this function pointer to check if the plane's 1298 * atomic state can be updated in a async fashion. Here async means 1299 * "not vblank synchronized". 1300 * 1301 * This hook is called by drm_atomic_async_check() to establish if a 1302 * given update can be committed asynchronously, that is, if it can 1303 * jump ahead of the state currently queued for update. 1304 * 1305 * RETURNS: 1306 * 1307 * Return 0 on success and any error returned indicates that the update 1308 * can not be applied in asynchronous manner. 1309 */ 1310 int (*atomic_async_check)(struct drm_plane *plane, 1311 struct drm_atomic_state *state); 1312 1313 /** 1314 * @atomic_async_update: 1315 * 1316 * Drivers should set this function pointer to perform asynchronous 1317 * updates of planes, that is, jump ahead of the currently queued 1318 * state and update the plane. Here async means "not vblank 1319 * synchronized". 1320 * 1321 * This hook is called by drm_atomic_helper_async_commit(). 1322 * 1323 * An async update will happen on legacy cursor updates. An async 1324 * update won't happen if there is an outstanding commit modifying 1325 * the same plane. 1326 * 1327 * When doing async_update drivers shouldn't replace the 1328 * &drm_plane_state but update the current one with the new plane 1329 * configurations in the new plane_state. 1330 * 1331 * Drivers should also swap the framebuffers between current plane 1332 * state (&drm_plane.state) and new_state. 1333 * This is required since cleanup for async commits is performed on 1334 * the new state, rather than old state like for traditional commits. 1335 * Since we want to give up the reference on the current (old) fb 1336 * instead of our brand new one, swap them in the driver during the 1337 * async commit. 1338 * 1339 * FIXME: 1340 * - It only works for single plane updates 1341 * - Async Pageflips are not supported yet 1342 * - Some hw might still scan out the old buffer until the next 1343 * vblank, however we let go of the fb references as soon as 1344 * we run this hook. For now drivers must implement their own workers 1345 * for deferring if needed, until a common solution is created. 1346 */ 1347 void (*atomic_async_update)(struct drm_plane *plane, 1348 struct drm_atomic_state *state); 1349 }; 1350 1351 /** 1352 * drm_plane_helper_add - sets the helper vtable for a plane 1353 * @plane: DRM plane 1354 * @funcs: helper vtable to set for @plane 1355 */ 1356 static inline void drm_plane_helper_add(struct drm_plane *plane, 1357 const struct drm_plane_helper_funcs *funcs) 1358 { 1359 plane->helper_private = funcs; 1360 } 1361 1362 /** 1363 * struct drm_mode_config_helper_funcs - global modeset helper operations 1364 * 1365 * These helper functions are used by the atomic helpers. 1366 */ 1367 struct drm_mode_config_helper_funcs { 1368 /** 1369 * @atomic_commit_tail: 1370 * 1371 * This hook is used by the default atomic_commit() hook implemented in 1372 * drm_atomic_helper_commit() together with the nonblocking commit 1373 * helpers (see drm_atomic_helper_setup_commit() for a starting point) 1374 * to implement blocking and nonblocking commits easily. It is not used 1375 * by the atomic helpers 1376 * 1377 * This function is called when the new atomic state has already been 1378 * swapped into the various state pointers. The passed in state 1379 * therefore contains copies of the old/previous state. This hook should 1380 * commit the new state into hardware. Note that the helpers have 1381 * already waited for preceeding atomic commits and fences, but drivers 1382 * can add more waiting calls at the start of their implementation, e.g. 1383 * to wait for driver-internal request for implicit syncing, before 1384 * starting to commit the update to the hardware. 1385 * 1386 * After the atomic update is committed to the hardware this hook needs 1387 * to call drm_atomic_helper_commit_hw_done(). Then wait for the update 1388 * to be executed by the hardware, for example using 1389 * drm_atomic_helper_wait_for_vblanks() or 1390 * drm_atomic_helper_wait_for_flip_done(), and then clean up the old 1391 * framebuffers using drm_atomic_helper_cleanup_planes(). 1392 * 1393 * When disabling a CRTC this hook _must_ stall for the commit to 1394 * complete. Vblank waits don't work on disabled CRTC, hence the core 1395 * can't take care of this. And it also can't rely on the vblank event, 1396 * since that can be signalled already when the screen shows black, 1397 * which can happen much earlier than the last hardware access needed to 1398 * shut off the display pipeline completely. 1399 * 1400 * This hook is optional, the default implementation is 1401 * drm_atomic_helper_commit_tail(). 1402 */ 1403 void (*atomic_commit_tail)(struct drm_atomic_state *state); 1404 1405 /** 1406 * @atomic_commit_setup: 1407 * 1408 * This hook is used by the default atomic_commit() hook implemented in 1409 * drm_atomic_helper_commit() together with the nonblocking helpers (see 1410 * drm_atomic_helper_setup_commit()) to extend the DRM commit setup. It 1411 * is not used by the atomic helpers. 1412 * 1413 * This function is called at the end of 1414 * drm_atomic_helper_setup_commit(), so once the commit has been 1415 * properly setup across the generic DRM object states. It allows 1416 * drivers to do some additional commit tracking that isn't related to a 1417 * CRTC, plane or connector, tracked in a &drm_private_obj structure. 1418 * 1419 * Note that the documentation of &drm_private_obj has more details on 1420 * how one should implement this. 1421 * 1422 * This hook is optional. 1423 */ 1424 int (*atomic_commit_setup)(struct drm_atomic_state *state); 1425 }; 1426 1427 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |