/*1* Copyright © 2006 Keith Packard2* Copyright © 2007-2008 Dave Airlie3* Copyright © 2007-2008 Intel Corporation4* Jesse Barnes <[email protected]>5*6* Permission is hereby granted, free of charge, to any person obtaining a7* copy of this software and associated documentation files (the "Software"),8* to deal in the Software without restriction, including without limitation9* the rights to use, copy, modify, merge, publish, distribute, sublicense,10* and/or sell copies of the Software, and to permit persons to whom the11* Software is furnished to do so, subject to the following conditions:12*13* The above copyright notice and this permission notice shall be included in14* all copies or substantial portions of the Software.15*16* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR17* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,18* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL19* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR20* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,21* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR22* OTHER DEALINGS IN THE SOFTWARE.23*/24#ifndef __DRM_CRTC_H__25#define __DRM_CRTC_H__2627#include <linux/spinlock.h>28#include <linux/types.h>29#include <drm/drm_modeset_lock.h>30#include <drm/drm_mode_object.h>31#include <drm/drm_modes.h>32#include <drm/drm_device.h>33#include <drm/drm_plane.h>34#include <drm/drm_debugfs_crc.h>35#include <drm/drm_mode_config.h>3637struct drm_connector;38struct drm_device;39struct drm_framebuffer;40struct drm_mode_set;41struct drm_file;42struct drm_printer;43struct drm_self_refresh_data;44struct device_node;45struct edid;4647static inline int64_t U642I64(uint64_t val)48{49return (int64_t)*((int64_t *)&val);50}51static inline uint64_t I642U64(int64_t val)52{53return (uint64_t)*((uint64_t *)&val);54}5556struct drm_crtc;57struct drm_pending_vblank_event;58struct drm_plane;59struct drm_bridge;60struct drm_atomic_state;6162struct drm_crtc_helper_funcs;63struct drm_plane_helper_funcs;6465/**66* struct drm_crtc_state - mutable CRTC state67*68* Note that the distinction between @enable and @active is rather subtle:69* Flipping @active while @enable is set without changing anything else may70* never return in a failure from the &drm_mode_config_funcs.atomic_check71* callback. Userspace assumes that a DPMS On will always succeed. In other72* words: @enable controls resource assignment, @active controls the actual73* hardware state.74*75* The three booleans active_changed, connectors_changed and mode_changed are76* intended to indicate whether a full modeset is needed, rather than strictly77* describing what has changed in a commit. See also:78* drm_atomic_crtc_needs_modeset()79*/80struct drm_crtc_state {81/** @crtc: backpointer to the CRTC */82struct drm_crtc *crtc;8384/**85* @enable: Whether the CRTC should be enabled, gates all other state.86* This controls reservations of shared resources. Actual hardware state87* is controlled by @active.88*/89bool enable;9091/**92* @active: Whether the CRTC is actively displaying (used for DPMS).93* Implies that @enable is set. The driver must not release any shared94* resources if @active is set to false but @enable still true, because95* userspace expects that a DPMS ON always succeeds.96*97* Hence drivers must not consult @active in their various98* &drm_mode_config_funcs.atomic_check callback to reject an atomic99* commit. They can consult it to aid in the computation of derived100* hardware state, since even in the DPMS OFF state the display hardware101* should be as much powered down as when the CRTC is completely102* disabled through setting @enable to false.103*/104bool active;105106/**107* @planes_changed: Planes on this crtc are updated. Used by the atomic108* helpers and drivers to steer the atomic commit control flow.109*/110bool planes_changed : 1;111112/**113* @mode_changed: @mode or @enable has been changed. Used by the atomic114* helpers and drivers to steer the atomic commit control flow. See also115* drm_atomic_crtc_needs_modeset().116*117* Drivers are supposed to set this for any CRTC state changes that118* require a full modeset. They can also reset it to false if e.g. a119* @mode change can be done without a full modeset by only changing120* scaler settings.121*/122bool mode_changed : 1;123124/**125* @active_changed: @active has been toggled. Used by the atomic126* helpers and drivers to steer the atomic commit control flow. See also127* drm_atomic_crtc_needs_modeset().128*/129bool active_changed : 1;130131/**132* @connectors_changed: Connectors to this crtc have been updated,133* either in their state or routing. Used by the atomic134* helpers and drivers to steer the atomic commit control flow. See also135* drm_atomic_crtc_needs_modeset().136*137* Drivers are supposed to set this as-needed from their own atomic138* check code, e.g. from &drm_encoder_helper_funcs.atomic_check139*/140bool connectors_changed : 1;141/**142* @zpos_changed: zpos values of planes on this crtc have been updated.143* Used by the atomic helpers and drivers to steer the atomic commit144* control flow.145*/146bool zpos_changed : 1;147/**148* @color_mgmt_changed: Color management properties have changed149* (@gamma_lut, @degamma_lut or @ctm). Used by the atomic helpers and150* drivers to steer the atomic commit control flow.151*/152bool color_mgmt_changed : 1;153154/**155* @no_vblank:156*157* Reflects the ability of a CRTC to send VBLANK events. This state158* usually depends on the pipeline configuration. If set to true, DRM159* atomic helpers will send out a fake VBLANK event during display160* updates after all hardware changes have been committed. This is161* implemented in drm_atomic_helper_fake_vblank().162*163* One usage is for drivers and/or hardware without support for VBLANK164* interrupts. Such drivers typically do not initialize vblanking165* (i.e., call drm_vblank_init() with the number of CRTCs). For CRTCs166* without initialized vblanking, this field is set to true in167* drm_atomic_helper_check_modeset(), and a fake VBLANK event will be168* send out on each update of the display pipeline by169* drm_atomic_helper_fake_vblank().170*171* Another usage is CRTCs feeding a writeback connector operating in172* oneshot mode. In this case the fake VBLANK event is only generated173* when a job is queued to the writeback connector, and we want the174* core to fake VBLANK events when this part of the pipeline hasn't175* changed but others had or when the CRTC and connectors are being176* disabled.177*178* __drm_atomic_helper_crtc_duplicate_state() will not reset the value179* from the current state, the CRTC driver is then responsible for180* updating this field when needed.181*182* Note that the combination of &drm_crtc_state.event == NULL and183* &drm_crtc_state.no_blank == true is valid and usually used when the184* writeback connector attached to the CRTC has a new job queued. In185* this case the driver will send the VBLANK event on its own when the186* writeback job is complete.187*/188bool no_vblank;189190/**191* @plane_mask: Bitmask of drm_plane_mask(plane) of planes attached to192* this CRTC.193*/194u32 plane_mask;195196/**197* @connector_mask: Bitmask of drm_connector_mask(connector) of198* connectors attached to this CRTC.199*/200u32 connector_mask;201202/**203* @encoder_mask: Bitmask of drm_encoder_mask(encoder) of encoders204* attached to this CRTC.205*/206u32 encoder_mask;207208/**209* @adjusted_mode:210*211* Internal display timings which can be used by the driver to handle212* differences between the mode requested by userspace in @mode and what213* is actually programmed into the hardware.214*215* For drivers using &drm_bridge, this stores hardware display timings216* used between the CRTC and the first bridge. For other drivers, the217* meaning of the adjusted_mode field is purely driver implementation218* defined information, and will usually be used to store the hardware219* display timings used between the CRTC and encoder blocks.220*/221struct drm_display_mode adjusted_mode;222223/**224* @mode:225*226* Display timings requested by userspace. The driver should try to227* match the refresh rate as close as possible (but note that it's228* undefined what exactly is close enough, e.g. some of the HDMI modes229* only differ in less than 1% of the refresh rate). The active width230* and height as observed by userspace for positioning planes must match231* exactly.232*233* For external connectors where the sink isn't fixed (like with a234* built-in panel), this mode here should match the physical mode on the235* wire to the last details (i.e. including sync polarities and236* everything).237*/238struct drm_display_mode mode;239240/**241* @mode_blob: &drm_property_blob for @mode, for exposing the mode to242* atomic userspace.243*/244struct drm_property_blob *mode_blob;245246/**247* @degamma_lut:248*249* Lookup table for converting framebuffer pixel data before apply the250* color conversion matrix @ctm. See drm_crtc_enable_color_mgmt(). The251* blob (if not NULL) is an array of &struct drm_color_lut.252*/253struct drm_property_blob *degamma_lut;254255/**256* @ctm:257*258* Color transformation matrix. See drm_crtc_enable_color_mgmt(). The259* blob (if not NULL) is a &struct drm_color_ctm.260*/261struct drm_property_blob *ctm;262263/**264* @gamma_lut:265*266* Lookup table for converting pixel data after the color conversion267* matrix @ctm. See drm_crtc_enable_color_mgmt(). The blob (if not268* NULL) is an array of &struct drm_color_lut.269*270* Note that for mostly historical reasons stemming from Xorg heritage,271* this is also used to store the color map (also sometimes color lut,272* CLUT or color palette) for indexed formats like DRM_FORMAT_C8.273*/274struct drm_property_blob *gamma_lut;275276/**277* @target_vblank:278*279* Target vertical blank period when a page flip280* should take effect.281*/282u32 target_vblank;283284/**285* @async_flip:286*287* This is set when DRM_MODE_PAGE_FLIP_ASYNC is set in the legacy288* PAGE_FLIP IOCTL. It's not wired up for the atomic IOCTL itself yet.289*/290bool async_flip;291292/**293* @vrr_enabled:294*295* Indicates if variable refresh rate should be enabled for the CRTC.296* Support for the requested vrr state will depend on driver and297* hardware capabiltiy - lacking support is not treated as failure.298*/299bool vrr_enabled;300301/**302* @self_refresh_active:303*304* Used by the self refresh helpers to denote when a self refresh305* transition is occurring. This will be set on enable/disable callbacks306* when self refresh is being enabled or disabled. In some cases, it may307* not be desirable to fully shut off the crtc during self refresh.308* CRTC's can inspect this flag and determine the best course of action.309*/310bool self_refresh_active;311312/**313* @scaling_filter:314*315* Scaling filter to be applied316*/317enum drm_scaling_filter scaling_filter;318319/**320* @sharpness_strength:321*322* Used by the user to set the sharpness intensity.323* The value ranges from 0-255.324* Default value is 0 which disable the sharpness feature.325* Any value greater than 0 enables sharpening with the326* specified strength.327*/328u8 sharpness_strength;329330/**331* @event:332*333* Optional pointer to a DRM event to signal upon completion of the334* state update. The driver must send out the event when the atomic335* commit operation completes. There are two cases:336*337* - The event is for a CRTC which is being disabled through this338* atomic commit. In that case the event can be send out any time339* after the hardware has stopped scanning out the current340* framebuffers. It should contain the timestamp and counter for the341* last vblank before the display pipeline was shut off. The simplest342* way to achieve that is calling drm_crtc_send_vblank_event()343* somewhen after drm_crtc_vblank_off() has been called.344*345* - For a CRTC which is enabled at the end of the commit (even when it346* undergoes an full modeset) the vblank timestamp and counter must347* be for the vblank right before the first frame that scans out the348* new set of buffers. Again the event can only be sent out after the349* hardware has stopped scanning out the old buffers.350*351* - Events for disabled CRTCs are not allowed, and drivers can ignore352* that case.353*354* For very simple hardware without VBLANK interrupt, enabling355* &struct drm_crtc_state.no_vblank makes DRM's atomic commit helpers356* send a fake VBLANK event at the end of the display update after all357* hardware changes have been applied. See358* drm_atomic_helper_fake_vblank().359*360* For more complex hardware this361* can be handled by the drm_crtc_send_vblank_event() function,362* which the driver should call on the provided event upon completion of363* the atomic commit. Note that if the driver supports vblank signalling364* and timestamping the vblank counters and timestamps must agree with365* the ones returned from page flip events. With the current vblank366* helper infrastructure this can be achieved by holding a vblank367* reference while the page flip is pending, acquired through368* drm_crtc_vblank_get() and released with drm_crtc_vblank_put().369* Drivers are free to implement their own vblank counter and timestamp370* tracking though, e.g. if they have accurate timestamp registers in371* hardware.372*373* For hardware which supports some means to synchronize vblank374* interrupt delivery with committing display state there's also375* drm_crtc_arm_vblank_event(). See the documentation of that function376* for a detailed discussion of the constraints it needs to be used377* safely.378*379* If the device can't notify of flip completion in a race-free way380* at all, then the event should be armed just after the page flip is381* committed. In the worst case the driver will send the event to382* userspace one frame too late. This doesn't allow for a real atomic383* update, but it should avoid tearing.384*/385struct drm_pending_vblank_event *event;386387/**388* @commit:389*390* This tracks how the commit for this update proceeds through the391* various phases. This is never cleared, except when we destroy the392* state, so that subsequent commits can synchronize with previous ones.393*/394struct drm_crtc_commit *commit;395396/** @state: backpointer to global drm_atomic_state */397struct drm_atomic_state *state;398};399400/**401* struct drm_crtc_funcs - control CRTCs for a given device402*403* The drm_crtc_funcs structure is the central CRTC management structure404* in the DRM. Each CRTC controls one or more connectors (note that the name405* CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.406* connectors, not just CRTs).407*408* Each driver is responsible for filling out this structure at startup time,409* in addition to providing other modesetting features, like i2c and DDC410* bus accessors.411*/412struct drm_crtc_funcs {413/**414* @reset:415*416* Reset CRTC hardware and software state to off. This function isn't417* called by the core directly, only through drm_mode_config_reset().418* It's not a helper hook only for historical reasons.419*420* Atomic drivers can use drm_atomic_helper_crtc_reset() to reset421* atomic state using this hook.422*/423void (*reset)(struct drm_crtc *crtc);424425/**426* @cursor_set:427*428* Update the cursor image. The cursor position is relative to the CRTC429* and can be partially or fully outside of the visible area.430*431* Note that contrary to all other KMS functions the legacy cursor entry432* points don't take a framebuffer object, but instead take directly a433* raw buffer object id from the driver's buffer manager (which is434* either GEM or TTM for current drivers).435*436* This entry point is deprecated, drivers should instead implement437* universal plane support and register a proper cursor plane using438* drm_crtc_init_with_planes().439*440* This callback is optional441*442* RETURNS:443*444* 0 on success or a negative error code on failure.445*/446int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,447uint32_t handle, uint32_t width, uint32_t height);448449/**450* @cursor_set2:451*452* Update the cursor image, including hotspot information. The hotspot453* must not affect the cursor position in CRTC coordinates, but is only454* meant as a hint for virtualized display hardware to coordinate the455* guests and hosts cursor position. The cursor hotspot is relative to456* the cursor image. Otherwise this works exactly like @cursor_set.457*458* This entry point is deprecated, drivers should instead implement459* universal plane support and register a proper cursor plane using460* drm_crtc_init_with_planes().461*462* This callback is optional.463*464* RETURNS:465*466* 0 on success or a negative error code on failure.467*/468int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,469uint32_t handle, uint32_t width, uint32_t height,470int32_t hot_x, int32_t hot_y);471472/**473* @cursor_move:474*475* Update the cursor position. The cursor does not need to be visible476* when this hook is called.477*478* This entry point is deprecated, drivers should instead implement479* universal plane support and register a proper cursor plane using480* drm_crtc_init_with_planes().481*482* This callback is optional.483*484* RETURNS:485*486* 0 on success or a negative error code on failure.487*/488int (*cursor_move)(struct drm_crtc *crtc, int x, int y);489490/**491* @gamma_set:492*493* Set gamma on the CRTC.494*495* This callback is optional.496*497* Atomic drivers who want to support gamma tables should implement the498* atomic color management support, enabled by calling499* drm_crtc_enable_color_mgmt(), which then supports the legacy gamma500* interface through the drm_atomic_helper_legacy_gamma_set()501* compatibility implementation.502*/503int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,504uint32_t size,505struct drm_modeset_acquire_ctx *ctx);506507/**508* @destroy:509*510* Clean up CRTC resources. This is only called at driver unload time511* through drm_mode_config_cleanup() since a CRTC cannot be hotplugged512* in DRM.513*/514void (*destroy)(struct drm_crtc *crtc);515516/**517* @set_config:518*519* This is the main legacy entry point to change the modeset state on a520* CRTC. All the details of the desired configuration are passed in a521* &struct drm_mode_set - see there for details.522*523* Drivers implementing atomic modeset should use524* drm_atomic_helper_set_config() to implement this hook.525*526* RETURNS:527*528* 0 on success or a negative error code on failure.529*/530int (*set_config)(struct drm_mode_set *set,531struct drm_modeset_acquire_ctx *ctx);532533/**534* @page_flip:535*536* Legacy entry point to schedule a flip to the given framebuffer.537*538* Page flipping is a synchronization mechanism that replaces the frame539* buffer being scanned out by the CRTC with a new frame buffer during540* vertical blanking, avoiding tearing (except when requested otherwise541* through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application542* requests a page flip the DRM core verifies that the new frame buffer543* is large enough to be scanned out by the CRTC in the currently544* configured mode and then calls this hook with a pointer to the new545* frame buffer.546*547* The driver must wait for any pending rendering to the new framebuffer548* to complete before executing the flip. It should also wait for any549* pending rendering from other drivers if the underlying buffer is a550* shared dma-buf.551*552* An application can request to be notified when the page flip has553* completed. The drm core will supply a &struct drm_event in the event554* parameter in this case. This can be handled by the555* drm_crtc_send_vblank_event() function, which the driver should call on556* the provided event upon completion of the flip. Note that if557* the driver supports vblank signalling and timestamping the vblank558* counters and timestamps must agree with the ones returned from page559* flip events. With the current vblank helper infrastructure this can560* be achieved by holding a vblank reference while the page flip is561* pending, acquired through drm_crtc_vblank_get() and released with562* drm_crtc_vblank_put(). Drivers are free to implement their own vblank563* counter and timestamp tracking though, e.g. if they have accurate564* timestamp registers in hardware.565*566* This callback is optional.567*568* NOTE:569*570* Very early versions of the KMS ABI mandated that the driver must571* block (but not reject) any rendering to the old framebuffer until the572* flip operation has completed and the old framebuffer is no longer573* visible. This requirement has been lifted, and userspace is instead574* expected to request delivery of an event and wait with recycling old575* buffers until such has been received.576*577* RETURNS:578*579* 0 on success or a negative error code on failure. Note that if a580* page flip operation is already pending the callback should return581* -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode582* or just runtime disabled through DPMS respectively the new atomic583* "ACTIVE" state) should result in an -EINVAL error code. Note that584* drm_atomic_helper_page_flip() checks this already for atomic drivers.585*/586int (*page_flip)(struct drm_crtc *crtc,587struct drm_framebuffer *fb,588struct drm_pending_vblank_event *event,589uint32_t flags,590struct drm_modeset_acquire_ctx *ctx);591592/**593* @page_flip_target:594*595* Same as @page_flip but with an additional parameter specifying the596* absolute target vertical blank period (as reported by597* drm_crtc_vblank_count()) when the flip should take effect.598*599* Note that the core code calls drm_crtc_vblank_get before this entry600* point, and will call drm_crtc_vblank_put if this entry point returns601* any non-0 error code. It's the driver's responsibility to call602* drm_crtc_vblank_put after this entry point returns 0, typically when603* the flip completes.604*/605int (*page_flip_target)(struct drm_crtc *crtc,606struct drm_framebuffer *fb,607struct drm_pending_vblank_event *event,608uint32_t flags, uint32_t target,609struct drm_modeset_acquire_ctx *ctx);610611/**612* @set_property:613*614* This is the legacy entry point to update a property attached to the615* CRTC.616*617* This callback is optional if the driver does not support any legacy618* driver-private properties. For atomic drivers it is not used because619* property handling is done entirely in the DRM core.620*621* RETURNS:622*623* 0 on success or a negative error code on failure.624*/625int (*set_property)(struct drm_crtc *crtc,626struct drm_property *property, uint64_t val);627628/**629* @atomic_duplicate_state:630*631* Duplicate the current atomic state for this CRTC and return it.632* The core and helpers guarantee that any atomic state duplicated with633* this hook and still owned by the caller (i.e. not transferred to the634* driver by calling &drm_mode_config_funcs.atomic_commit) will be635* cleaned up by calling the @atomic_destroy_state hook in this636* structure.637*638* This callback is mandatory for atomic drivers.639*640* Atomic drivers which don't subclass &struct drm_crtc_state should use641* drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the642* state structure to extend it with driver-private state should use643* __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is644* duplicated in a consistent fashion across drivers.645*646* It is an error to call this hook before &drm_crtc.state has been647* initialized correctly.648*649* NOTE:650*651* If the duplicate state references refcounted resources this hook must652* acquire a reference for each of them. The driver must release these653* references again in @atomic_destroy_state.654*655* RETURNS:656*657* Duplicated atomic state or NULL when the allocation failed.658*/659struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);660661/**662* @atomic_destroy_state:663*664* Destroy a state duplicated with @atomic_duplicate_state and release665* or unreference all resources it references666*667* This callback is mandatory for atomic drivers.668*/669void (*atomic_destroy_state)(struct drm_crtc *crtc,670struct drm_crtc_state *state);671672/**673* @atomic_set_property:674*675* Decode a driver-private property value and store the decoded value676* into the passed-in state structure. Since the atomic core decodes all677* standardized properties (even for extensions beyond the core set of678* properties which might not be implemented by all drivers) this679* requires drivers to subclass the state structure.680*681* Such driver-private properties should really only be implemented for682* truly hardware/vendor specific state. Instead it is preferred to683* standardize atomic extension and decode the properties used to expose684* such an extension in the core.685*686* Do not call this function directly, use687* drm_atomic_crtc_set_property() instead.688*689* This callback is optional if the driver does not support any690* driver-private atomic properties.691*692* NOTE:693*694* This function is called in the state assembly phase of atomic695* modesets, which can be aborted for any reason (including on696* userspace's request to just check whether a configuration would be697* possible). Drivers MUST NOT touch any persistent state (hardware or698* software) or data structures except the passed in @state parameter.699*700* Also since userspace controls in which order properties are set this701* function must not do any input validation (since the state update is702* incomplete and hence likely inconsistent). Instead any such input703* validation must be done in the various atomic_check callbacks.704*705* RETURNS:706*707* 0 if the property has been found, -EINVAL if the property isn't708* implemented by the driver (which should never happen, the core only709* asks for properties attached to this CRTC). No other validation is710* allowed by the driver. The core already checks that the property711* value is within the range (integer, valid enum value, ...) the driver712* set when registering the property.713*/714int (*atomic_set_property)(struct drm_crtc *crtc,715struct drm_crtc_state *state,716struct drm_property *property,717uint64_t val);718/**719* @atomic_get_property:720*721* Reads out the decoded driver-private property. This is used to722* implement the GETCRTC IOCTL.723*724* Do not call this function directly, use725* drm_atomic_crtc_get_property() instead.726*727* This callback is optional if the driver does not support any728* driver-private atomic properties.729*730* RETURNS:731*732* 0 on success, -EINVAL if the property isn't implemented by the733* driver (which should never happen, the core only asks for734* properties attached to this CRTC).735*/736int (*atomic_get_property)(struct drm_crtc *crtc,737const struct drm_crtc_state *state,738struct drm_property *property,739uint64_t *val);740741/**742* @late_register:743*744* This optional hook can be used to register additional userspace745* interfaces attached to the crtc like debugfs interfaces.746* It is called late in the driver load sequence from drm_dev_register().747* Everything added from this callback should be unregistered in748* the early_unregister callback.749*750* Returns:751*752* 0 on success, or a negative error code on failure.753*/754int (*late_register)(struct drm_crtc *crtc);755756/**757* @early_unregister:758*759* This optional hook should be used to unregister the additional760* userspace interfaces attached to the crtc from761* @late_register. It is called from drm_dev_unregister(),762* early in the driver unload sequence to disable userspace access763* before data structures are torndown.764*/765void (*early_unregister)(struct drm_crtc *crtc);766767/**768* @set_crc_source:769*770* Changes the source of CRC checksums of frames at the request of771* userspace, typically for testing purposes. The sources available are772* specific of each driver and a %NULL value indicates that CRC773* generation is to be switched off.774*775* When CRC generation is enabled, the driver should call776* drm_crtc_add_crc_entry() at each frame, providing any information777* that characterizes the frame contents in the crcN arguments, as778* provided from the configured source. Drivers must accept an "auto"779* source name that will select a default source for this CRTC.780*781* This may trigger an atomic modeset commit if necessary, to enable CRC782* generation.783*784* Note that "auto" can depend upon the current modeset configuration,785* e.g. it could pick an encoder or output specific CRC sampling point.786*787* This callback is optional if the driver does not support any CRC788* generation functionality.789*790* RETURNS:791*792* 0 on success or a negative error code on failure.793*/794int (*set_crc_source)(struct drm_crtc *crtc, const char *source);795796/**797* @verify_crc_source:798*799* verifies the source of CRC checksums of frames before setting the800* source for CRC and during crc open. Source parameter can be NULL801* while disabling crc source.802*803* This callback is optional if the driver does not support any CRC804* generation functionality.805*806* RETURNS:807*808* 0 on success or a negative error code on failure.809*/810int (*verify_crc_source)(struct drm_crtc *crtc, const char *source,811size_t *values_cnt);812/**813* @get_crc_sources:814*815* Driver callback for getting a list of all the available sources for816* CRC generation. This callback depends upon verify_crc_source, So817* verify_crc_source callback should be implemented before implementing818* this. Driver can pass full list of available crc sources, this819* callback does the verification on each crc-source before passing it820* to userspace.821*822* This callback is optional if the driver does not support exporting of823* possible CRC sources list.824*825* RETURNS:826*827* a constant character pointer to the list of all the available CRC828* sources. On failure driver should return NULL. count should be829* updated with number of sources in list. if zero we don't process any830* source from the list.831*/832const char *const *(*get_crc_sources)(struct drm_crtc *crtc,833size_t *count);834835/**836* @atomic_print_state:837*838* If driver subclasses &struct drm_crtc_state, it should implement839* this optional hook for printing additional driver specific state.840*841* Do not call this directly, use drm_atomic_crtc_print_state()842* instead.843*/844void (*atomic_print_state)(struct drm_printer *p,845const struct drm_crtc_state *state);846847/**848* @get_vblank_counter:849*850* Driver callback for fetching a raw hardware vblank counter for the851* CRTC. It's meant to be used by new drivers as the replacement of852* &drm_driver.get_vblank_counter hook.853*854* This callback is optional. If a device doesn't have a hardware855* counter, the driver can simply leave the hook as NULL. The DRM core856* will account for missed vblank events while interrupts where disabled857* based on system timestamps.858*859* Wraparound handling and loss of events due to modesetting is dealt860* with in the DRM core code, as long as drivers call861* drm_crtc_vblank_off() and drm_crtc_vblank_on() when disabling or862* enabling a CRTC.863*864* See also &drm_device.vblank_disable_immediate and865* &drm_device.max_vblank_count.866*867* Returns:868*869* Raw vblank counter value.870*/871u32 (*get_vblank_counter)(struct drm_crtc *crtc);872873/**874* @enable_vblank:875*876* Enable vblank interrupts for the CRTC. It's meant to be used by877* new drivers as the replacement of &drm_driver.enable_vblank hook.878*879* Returns:880*881* Zero on success, appropriate errno if the vblank interrupt cannot882* be enabled.883*/884int (*enable_vblank)(struct drm_crtc *crtc);885886/**887* @disable_vblank:888*889* Disable vblank interrupts for the CRTC. It's meant to be used by890* new drivers as the replacement of &drm_driver.disable_vblank hook.891*/892void (*disable_vblank)(struct drm_crtc *crtc);893894/**895* @get_vblank_timestamp:896*897* Called by drm_get_last_vbltimestamp(). Should return a precise898* timestamp when the most recent vblank interval ended or will end.899*900* Specifically, the timestamp in @vblank_time should correspond as901* closely as possible to the time when the first video scanline of902* the video frame after the end of vblank will start scanning out,903* the time immediately after end of the vblank interval. If the904* @crtc is currently inside vblank, this will be a time in the future.905* If the @crtc is currently scanning out a frame, this will be the906* past start time of the current scanout. This is meant to adhere907* to the OpenML OML_sync_control extension specification.908*909* Parameters:910*911* crtc:912* CRTC for which timestamp should be returned.913* max_error:914* Maximum allowable timestamp error in nanoseconds.915* Implementation should strive to provide timestamp916* with an error of at most max_error nanoseconds.917* Returns true upper bound on error for timestamp.918* vblank_time:919* Target location for returned vblank timestamp.920* in_vblank_irq:921* True when called from drm_crtc_handle_vblank(). Some drivers922* need to apply some workarounds for gpu-specific vblank irq quirks923* if flag is set.924*925* Returns:926*927* True on success, false on failure, which means the core should928* fallback to a simple timestamp taken in drm_crtc_handle_vblank().929*/930bool (*get_vblank_timestamp)(struct drm_crtc *crtc,931int *max_error,932ktime_t *vblank_time,933bool in_vblank_irq);934};935936/**937* struct drm_crtc - central CRTC control structure938*939* Each CRTC may have one or more connectors associated with it. This structure940* allows the CRTC to be controlled.941*/942struct drm_crtc {943/** @dev: parent DRM device */944struct drm_device *dev;945/** @port: OF node used by drm_of_find_possible_crtcs(). */946struct device_node *port;947/**948* @head:949*950* List of all CRTCs on @dev, linked from &drm_mode_config.crtc_list.951* Invariant over the lifetime of @dev and therefore does not need952* locking.953*/954struct list_head head;955956/** @name: human readable name, can be overwritten by the driver */957char *name;958959/**960* @mutex:961*962* This provides a read lock for the overall CRTC state (mode, dpms963* state, ...) and a write lock for everything which can be update964* without a full modeset (fb, cursor data, CRTC properties ...). A full965* modeset also need to grab &drm_mode_config.connection_mutex.966*967* For atomic drivers specifically this protects @state.968*/969struct drm_modeset_lock mutex;970971/** @base: base KMS object for ID tracking etc. */972struct drm_mode_object base;973974/**975* @primary:976* Primary plane for this CRTC. Note that this is only977* relevant for legacy IOCTL, it specifies the plane implicitly used by978* the SETCRTC and PAGE_FLIP IOCTLs. It does not have any significance979* beyond that.980*/981struct drm_plane *primary;982983/**984* @cursor:985* Cursor plane for this CRTC. Note that this is only relevant for986* legacy IOCTL, it specifies the plane implicitly used by the SETCURSOR987* and SETCURSOR2 IOCTLs. It does not have any significance988* beyond that.989*/990struct drm_plane *cursor;991992/**993* @index: Position inside the mode_config.list, can be used as an array994* index. It is invariant over the lifetime of the CRTC.995*/996unsigned index;997998/**999* @cursor_x: Current x position of the cursor, used for universal1000* cursor planes because the SETCURSOR IOCTL only can update the1001* framebuffer without supplying the coordinates. Drivers should not use1002* this directly, atomic drivers should look at &drm_plane_state.crtc_x1003* of the cursor plane instead.1004*/1005int cursor_x;1006/**1007* @cursor_y: Current y position of the cursor, used for universal1008* cursor planes because the SETCURSOR IOCTL only can update the1009* framebuffer without supplying the coordinates. Drivers should not use1010* this directly, atomic drivers should look at &drm_plane_state.crtc_y1011* of the cursor plane instead.1012*/1013int cursor_y;10141015/**1016* @enabled:1017*1018* Is this CRTC enabled? Should only be used by legacy drivers, atomic1019* drivers should instead consult &drm_crtc_state.enable and1020* &drm_crtc_state.active. Atomic drivers can update this by calling1021* drm_atomic_helper_update_legacy_modeset_state().1022*/1023bool enabled;10241025/**1026* @mode:1027*1028* Current mode timings. Should only be used by legacy drivers, atomic1029* drivers should instead consult &drm_crtc_state.mode. Atomic drivers1030* can update this by calling1031* drm_atomic_helper_update_legacy_modeset_state().1032*/1033struct drm_display_mode mode;10341035/**1036* @hwmode:1037*1038* Programmed mode in hw, after adjustments for encoders, crtc, panel1039* scaling etc. Should only be used by legacy drivers, for high1040* precision vblank timestamps in1041* drm_crtc_vblank_helper_get_vblank_timestamp().1042*1043* Note that atomic drivers should not use this, but instead use1044* &drm_crtc_state.adjusted_mode. And for high-precision timestamps1045* drm_crtc_vblank_helper_get_vblank_timestamp() used1046* &drm_vblank_crtc.hwmode,1047* which is filled out by calling drm_calc_timestamping_constants().1048*/1049struct drm_display_mode hwmode;10501051/**1052* @x:1053* x position on screen. Should only be used by legacy drivers, atomic1054* drivers should look at &drm_plane_state.crtc_x of the primary plane1055* instead. Updated by calling1056* drm_atomic_helper_update_legacy_modeset_state().1057*/1058int x;1059/**1060* @y:1061* y position on screen. Should only be used by legacy drivers, atomic1062* drivers should look at &drm_plane_state.crtc_y of the primary plane1063* instead. Updated by calling1064* drm_atomic_helper_update_legacy_modeset_state().1065*/1066int y;10671068/** @funcs: CRTC control functions */1069const struct drm_crtc_funcs *funcs;10701071/**1072* @gamma_size: Size of legacy gamma ramp reported to userspace. Set up1073* by calling drm_mode_crtc_set_gamma_size().1074*1075* Note that atomic drivers need to instead use1076* &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().1077*/1078uint32_t gamma_size;10791080/**1081* @gamma_store: Gamma ramp values used by the legacy SETGAMMA and1082* GETGAMMA IOCTls. Set up by calling drm_mode_crtc_set_gamma_size().1083*1084* Note that atomic drivers need to instead use1085* &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().1086*/1087uint16_t *gamma_store;10881089/** @helper_private: mid-layer private data */1090const struct drm_crtc_helper_funcs *helper_private;10911092/** @properties: property tracking for this CRTC */1093struct drm_object_properties properties;10941095/**1096* @scaling_filter_property: property to apply a particular filter while1097* scaling.1098*/1099struct drm_property *scaling_filter_property;11001101/**1102* @sharpness_strength_property: property to apply1103* the intensity of the sharpness requested.1104*/1105struct drm_property *sharpness_strength_property;11061107/**1108* @state:1109*1110* Current atomic state for this CRTC.1111*1112* This is protected by @mutex. Note that nonblocking atomic commits1113* access the current CRTC state without taking locks. Either by going1114* through the &struct drm_atomic_state pointers, see1115* for_each_oldnew_crtc_in_state(), for_each_old_crtc_in_state() and1116* for_each_new_crtc_in_state(). Or through careful ordering of atomic1117* commit operations as implemented in the atomic helpers, see1118* &struct drm_crtc_commit.1119*/1120struct drm_crtc_state *state;11211122/**1123* @commit_list:1124*1125* List of &drm_crtc_commit structures tracking pending commits.1126* Protected by @commit_lock. This list holds its own full reference,1127* as does the ongoing commit.1128*1129* "Note that the commit for a state change is also tracked in1130* &drm_crtc_state.commit. For accessing the immediately preceding1131* commit in an atomic update it is recommended to just use that1132* pointer in the old CRTC state, since accessing that doesn't need1133* any locking or list-walking. @commit_list should only be used to1134* stall for framebuffer cleanup that's signalled through1135* &drm_crtc_commit.cleanup_done."1136*/1137struct list_head commit_list;11381139/**1140* @commit_lock:1141*1142* Spinlock to protect @commit_list.1143*/1144spinlock_t commit_lock;11451146/**1147* @debugfs_entry:1148*1149* Debugfs directory for this CRTC.1150*/1151struct dentry *debugfs_entry;11521153/**1154* @crc:1155*1156* Configuration settings of CRC capture.1157*/1158struct drm_crtc_crc crc;11591160/**1161* @fence_context:1162*1163* timeline context used for fence operations.1164*/1165unsigned int fence_context;11661167/**1168* @fence_lock:1169*1170* spinlock to protect the fences in the fence_context.1171*/1172spinlock_t fence_lock;1173/**1174* @fence_seqno:1175*1176* Seqno variable used as monotonic counter for the fences1177* created on the CRTC's timeline.1178*/1179unsigned long fence_seqno;11801181/**1182* @timeline_name:1183*1184* The name of the CRTC's fence timeline.1185*/1186char timeline_name[32];11871188/**1189* @self_refresh_data: Holds the state for the self refresh helpers1190*1191* Initialized via drm_self_refresh_helper_init().1192*/1193struct drm_self_refresh_data *self_refresh_data;1194};11951196/**1197* struct drm_mode_set - new values for a CRTC config change1198* @fb: framebuffer to use for new config1199* @crtc: CRTC whose configuration we're about to change1200* @mode: mode timings to use1201* @x: position of this CRTC relative to @fb1202* @y: position of this CRTC relative to @fb1203* @connectors: array of connectors to drive with this CRTC if possible1204* @num_connectors: size of @connectors array1205*1206* This represents a modeset configuration for the legacy SETCRTC ioctl and is1207* also used internally. Atomic drivers instead use &drm_atomic_state.1208*/1209struct drm_mode_set {1210struct drm_framebuffer *fb;1211struct drm_crtc *crtc;1212struct drm_display_mode *mode;12131214uint32_t x;1215uint32_t y;12161217struct drm_connector **connectors;1218size_t num_connectors;1219};12201221#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)12221223__printf(6, 7)1224int drm_crtc_init_with_planes(struct drm_device *dev,1225struct drm_crtc *crtc,1226struct drm_plane *primary,1227struct drm_plane *cursor,1228const struct drm_crtc_funcs *funcs,1229const char *name, ...);12301231__printf(6, 7)1232int drmm_crtc_init_with_planes(struct drm_device *dev,1233struct drm_crtc *crtc,1234struct drm_plane *primary,1235struct drm_plane *cursor,1236const struct drm_crtc_funcs *funcs,1237const char *name, ...);12381239void drm_crtc_cleanup(struct drm_crtc *crtc);12401241__printf(7, 8)1242void *__drmm_crtc_alloc_with_planes(struct drm_device *dev,1243size_t size, size_t offset,1244struct drm_plane *primary,1245struct drm_plane *cursor,1246const struct drm_crtc_funcs *funcs,1247const char *name, ...);12481249/**1250* drmm_crtc_alloc_with_planes - Allocate and initialize a new CRTC object with1251* specified primary and cursor planes.1252* @dev: DRM device1253* @type: the type of the struct which contains struct &drm_crtc1254* @member: the name of the &drm_crtc within @type.1255* @primary: Primary plane for CRTC1256* @cursor: Cursor plane for CRTC1257* @funcs: callbacks for the new CRTC1258* @name: printf style format string for the CRTC name, or NULL for default name1259*1260* Allocates and initializes a new crtc object. Cleanup is automatically1261* handled through registering drmm_crtc_cleanup() with drmm_add_action().1262*1263* The @drm_crtc_funcs.destroy hook must be NULL.1264*1265* Returns:1266* Pointer to new crtc, or ERR_PTR on failure.1267*/1268#define drmm_crtc_alloc_with_planes(dev, type, member, primary, cursor, funcs, name, ...) \1269((type *)__drmm_crtc_alloc_with_planes(dev, sizeof(type), \1270offsetof(type, member), \1271primary, cursor, funcs, \1272name, ##__VA_ARGS__))12731274/**1275* drm_crtc_index - find the index of a registered CRTC1276* @crtc: CRTC to find index for1277*1278* Given a registered CRTC, return the index of that CRTC within a DRM1279* device's list of CRTCs.1280*/1281static inline unsigned int drm_crtc_index(const struct drm_crtc *crtc)1282{1283return crtc->index;1284}12851286/**1287* drm_crtc_mask - find the mask of a registered CRTC1288* @crtc: CRTC to find mask for1289*1290* Given a registered CRTC, return the mask bit of that CRTC for the1291* &drm_encoder.possible_crtcs and &drm_plane.possible_crtcs fields.1292*/1293static inline uint32_t drm_crtc_mask(const struct drm_crtc *crtc)1294{1295return 1 << drm_crtc_index(crtc);1296}12971298int drm_mode_set_config_internal(struct drm_mode_set *set);1299struct drm_crtc *drm_crtc_from_index(struct drm_device *dev, int idx);13001301/**1302* drm_crtc_find - look up a CRTC object from its ID1303* @dev: DRM device1304* @file_priv: drm file to check for lease against.1305* @id: &drm_mode_object ID1306*1307* This can be used to look up a CRTC from its userspace ID. Only used by1308* drivers for legacy IOCTLs and interface, nowadays extensions to the KMS1309* userspace interface should be done using &drm_property.1310*/1311static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,1312struct drm_file *file_priv,1313uint32_t id)1314{1315struct drm_mode_object *mo;1316mo = drm_mode_object_find(dev, file_priv, id, DRM_MODE_OBJECT_CRTC);1317return mo ? obj_to_crtc(mo) : NULL;1318}13191320/**1321* drm_for_each_crtc - iterate over all CRTCs1322* @crtc: a &struct drm_crtc as the loop cursor1323* @dev: the &struct drm_device1324*1325* Iterate over all CRTCs of @dev.1326*/1327#define drm_for_each_crtc(crtc, dev) \1328list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)13291330/**1331* drm_for_each_crtc_reverse - iterate over all CRTCs in reverse order1332* @crtc: a &struct drm_crtc as the loop cursor1333* @dev: the &struct drm_device1334*1335* Iterate over all CRTCs of @dev.1336*/1337#define drm_for_each_crtc_reverse(crtc, dev) \1338list_for_each_entry_reverse(crtc, &(dev)->mode_config.crtc_list, head)13391340int drm_crtc_create_scaling_filter_property(struct drm_crtc *crtc,1341unsigned int supported_filters);1342bool drm_crtc_in_clone_mode(struct drm_crtc_state *crtc_state);1343int drm_crtc_create_sharpness_strength_property(struct drm_crtc *crtc);1344#endif /* __DRM_CRTC_H__ */134513461347