/*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 : 1;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* @event:321*322* Optional pointer to a DRM event to signal upon completion of the323* state update. The driver must send out the event when the atomic324* commit operation completes. There are two cases:325*326* - The event is for a CRTC which is being disabled through this327* atomic commit. In that case the event can be send out any time328* after the hardware has stopped scanning out the current329* framebuffers. It should contain the timestamp and counter for the330* last vblank before the display pipeline was shut off. The simplest331* way to achieve that is calling drm_crtc_send_vblank_event()332* somewhen after drm_crtc_vblank_off() has been called.333*334* - For a CRTC which is enabled at the end of the commit (even when it335* undergoes an full modeset) the vblank timestamp and counter must336* be for the vblank right before the first frame that scans out the337* new set of buffers. Again the event can only be sent out after the338* hardware has stopped scanning out the old buffers.339*340* - Events for disabled CRTCs are not allowed, and drivers can ignore341* that case.342*343* For very simple hardware without VBLANK interrupt, enabling344* &struct drm_crtc_state.no_vblank makes DRM's atomic commit helpers345* send a fake VBLANK event at the end of the display update after all346* hardware changes have been applied. See347* drm_atomic_helper_fake_vblank().348*349* For more complex hardware this350* can be handled by the drm_crtc_send_vblank_event() function,351* which the driver should call on the provided event upon completion of352* the atomic commit. Note that if the driver supports vblank signalling353* and timestamping the vblank counters and timestamps must agree with354* the ones returned from page flip events. With the current vblank355* helper infrastructure this can be achieved by holding a vblank356* reference while the page flip is pending, acquired through357* drm_crtc_vblank_get() and released with drm_crtc_vblank_put().358* Drivers are free to implement their own vblank counter and timestamp359* tracking though, e.g. if they have accurate timestamp registers in360* hardware.361*362* For hardware which supports some means to synchronize vblank363* interrupt delivery with committing display state there's also364* drm_crtc_arm_vblank_event(). See the documentation of that function365* for a detailed discussion of the constraints it needs to be used366* safely.367*368* If the device can't notify of flip completion in a race-free way369* at all, then the event should be armed just after the page flip is370* committed. In the worst case the driver will send the event to371* userspace one frame too late. This doesn't allow for a real atomic372* update, but it should avoid tearing.373*/374struct drm_pending_vblank_event *event;375376/**377* @commit:378*379* This tracks how the commit for this update proceeds through the380* various phases. This is never cleared, except when we destroy the381* state, so that subsequent commits can synchronize with previous ones.382*/383struct drm_crtc_commit *commit;384385/** @state: backpointer to global drm_atomic_state */386struct drm_atomic_state *state;387};388389/**390* struct drm_crtc_funcs - control CRTCs for a given device391*392* The drm_crtc_funcs structure is the central CRTC management structure393* in the DRM. Each CRTC controls one or more connectors (note that the name394* CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.395* connectors, not just CRTs).396*397* Each driver is responsible for filling out this structure at startup time,398* in addition to providing other modesetting features, like i2c and DDC399* bus accessors.400*/401struct drm_crtc_funcs {402/**403* @reset:404*405* Reset CRTC hardware and software state to off. This function isn't406* called by the core directly, only through drm_mode_config_reset().407* It's not a helper hook only for historical reasons.408*409* Atomic drivers can use drm_atomic_helper_crtc_reset() to reset410* atomic state using this hook.411*/412void (*reset)(struct drm_crtc *crtc);413414/**415* @cursor_set:416*417* Update the cursor image. The cursor position is relative to the CRTC418* and can be partially or fully outside of the visible area.419*420* Note that contrary to all other KMS functions the legacy cursor entry421* points don't take a framebuffer object, but instead take directly a422* raw buffer object id from the driver's buffer manager (which is423* either GEM or TTM for current drivers).424*425* This entry point is deprecated, drivers should instead implement426* universal plane support and register a proper cursor plane using427* drm_crtc_init_with_planes().428*429* This callback is optional430*431* RETURNS:432*433* 0 on success or a negative error code on failure.434*/435int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,436uint32_t handle, uint32_t width, uint32_t height);437438/**439* @cursor_set2:440*441* Update the cursor image, including hotspot information. The hotspot442* must not affect the cursor position in CRTC coordinates, but is only443* meant as a hint for virtualized display hardware to coordinate the444* guests and hosts cursor position. The cursor hotspot is relative to445* the cursor image. Otherwise this works exactly like @cursor_set.446*447* This entry point is deprecated, drivers should instead implement448* universal plane support and register a proper cursor plane using449* drm_crtc_init_with_planes().450*451* This callback is optional.452*453* RETURNS:454*455* 0 on success or a negative error code on failure.456*/457int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,458uint32_t handle, uint32_t width, uint32_t height,459int32_t hot_x, int32_t hot_y);460461/**462* @cursor_move:463*464* Update the cursor position. The cursor does not need to be visible465* when this hook is called.466*467* This entry point is deprecated, drivers should instead implement468* universal plane support and register a proper cursor plane using469* drm_crtc_init_with_planes().470*471* This callback is optional.472*473* RETURNS:474*475* 0 on success or a negative error code on failure.476*/477int (*cursor_move)(struct drm_crtc *crtc, int x, int y);478479/**480* @gamma_set:481*482* Set gamma on the CRTC.483*484* This callback is optional.485*486* Atomic drivers who want to support gamma tables should implement the487* atomic color management support, enabled by calling488* drm_crtc_enable_color_mgmt(), which then supports the legacy gamma489* interface through the drm_atomic_helper_legacy_gamma_set()490* compatibility implementation.491*/492int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,493uint32_t size,494struct drm_modeset_acquire_ctx *ctx);495496/**497* @destroy:498*499* Clean up CRTC resources. This is only called at driver unload time500* through drm_mode_config_cleanup() since a CRTC cannot be hotplugged501* in DRM.502*/503void (*destroy)(struct drm_crtc *crtc);504505/**506* @set_config:507*508* This is the main legacy entry point to change the modeset state on a509* CRTC. All the details of the desired configuration are passed in a510* &struct drm_mode_set - see there for details.511*512* Drivers implementing atomic modeset should use513* drm_atomic_helper_set_config() to implement this hook.514*515* RETURNS:516*517* 0 on success or a negative error code on failure.518*/519int (*set_config)(struct drm_mode_set *set,520struct drm_modeset_acquire_ctx *ctx);521522/**523* @page_flip:524*525* Legacy entry point to schedule a flip to the given framebuffer.526*527* Page flipping is a synchronization mechanism that replaces the frame528* buffer being scanned out by the CRTC with a new frame buffer during529* vertical blanking, avoiding tearing (except when requested otherwise530* through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application531* requests a page flip the DRM core verifies that the new frame buffer532* is large enough to be scanned out by the CRTC in the currently533* configured mode and then calls this hook with a pointer to the new534* frame buffer.535*536* The driver must wait for any pending rendering to the new framebuffer537* to complete before executing the flip. It should also wait for any538* pending rendering from other drivers if the underlying buffer is a539* shared dma-buf.540*541* An application can request to be notified when the page flip has542* completed. The drm core will supply a &struct drm_event in the event543* parameter in this case. This can be handled by the544* drm_crtc_send_vblank_event() function, which the driver should call on545* the provided event upon completion of the flip. Note that if546* the driver supports vblank signalling and timestamping the vblank547* counters and timestamps must agree with the ones returned from page548* flip events. With the current vblank helper infrastructure this can549* be achieved by holding a vblank reference while the page flip is550* pending, acquired through drm_crtc_vblank_get() and released with551* drm_crtc_vblank_put(). Drivers are free to implement their own vblank552* counter and timestamp tracking though, e.g. if they have accurate553* timestamp registers in hardware.554*555* This callback is optional.556*557* NOTE:558*559* Very early versions of the KMS ABI mandated that the driver must560* block (but not reject) any rendering to the old framebuffer until the561* flip operation has completed and the old framebuffer is no longer562* visible. This requirement has been lifted, and userspace is instead563* expected to request delivery of an event and wait with recycling old564* buffers until such has been received.565*566* RETURNS:567*568* 0 on success or a negative error code on failure. Note that if a569* page flip operation is already pending the callback should return570* -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode571* or just runtime disabled through DPMS respectively the new atomic572* "ACTIVE" state) should result in an -EINVAL error code. Note that573* drm_atomic_helper_page_flip() checks this already for atomic drivers.574*/575int (*page_flip)(struct drm_crtc *crtc,576struct drm_framebuffer *fb,577struct drm_pending_vblank_event *event,578uint32_t flags,579struct drm_modeset_acquire_ctx *ctx);580581/**582* @page_flip_target:583*584* Same as @page_flip but with an additional parameter specifying the585* absolute target vertical blank period (as reported by586* drm_crtc_vblank_count()) when the flip should take effect.587*588* Note that the core code calls drm_crtc_vblank_get before this entry589* point, and will call drm_crtc_vblank_put if this entry point returns590* any non-0 error code. It's the driver's responsibility to call591* drm_crtc_vblank_put after this entry point returns 0, typically when592* the flip completes.593*/594int (*page_flip_target)(struct drm_crtc *crtc,595struct drm_framebuffer *fb,596struct drm_pending_vblank_event *event,597uint32_t flags, uint32_t target,598struct drm_modeset_acquire_ctx *ctx);599600/**601* @set_property:602*603* This is the legacy entry point to update a property attached to the604* CRTC.605*606* This callback is optional if the driver does not support any legacy607* driver-private properties. For atomic drivers it is not used because608* property handling is done entirely in the DRM core.609*610* RETURNS:611*612* 0 on success or a negative error code on failure.613*/614int (*set_property)(struct drm_crtc *crtc,615struct drm_property *property, uint64_t val);616617/**618* @atomic_duplicate_state:619*620* Duplicate the current atomic state for this CRTC and return it.621* The core and helpers guarantee that any atomic state duplicated with622* this hook and still owned by the caller (i.e. not transferred to the623* driver by calling &drm_mode_config_funcs.atomic_commit) will be624* cleaned up by calling the @atomic_destroy_state hook in this625* structure.626*627* This callback is mandatory for atomic drivers.628*629* Atomic drivers which don't subclass &struct drm_crtc_state should use630* drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the631* state structure to extend it with driver-private state should use632* __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is633* duplicated in a consistent fashion across drivers.634*635* It is an error to call this hook before &drm_crtc.state has been636* initialized correctly.637*638* NOTE:639*640* If the duplicate state references refcounted resources this hook must641* acquire a reference for each of them. The driver must release these642* references again in @atomic_destroy_state.643*644* RETURNS:645*646* Duplicated atomic state or NULL when the allocation failed.647*/648struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);649650/**651* @atomic_destroy_state:652*653* Destroy a state duplicated with @atomic_duplicate_state and release654* or unreference all resources it references655*656* This callback is mandatory for atomic drivers.657*/658void (*atomic_destroy_state)(struct drm_crtc *crtc,659struct drm_crtc_state *state);660661/**662* @atomic_set_property:663*664* Decode a driver-private property value and store the decoded value665* into the passed-in state structure. Since the atomic core decodes all666* standardized properties (even for extensions beyond the core set of667* properties which might not be implemented by all drivers) this668* requires drivers to subclass the state structure.669*670* Such driver-private properties should really only be implemented for671* truly hardware/vendor specific state. Instead it is preferred to672* standardize atomic extension and decode the properties used to expose673* such an extension in the core.674*675* Do not call this function directly, use676* drm_atomic_crtc_set_property() instead.677*678* This callback is optional if the driver does not support any679* driver-private atomic properties.680*681* NOTE:682*683* This function is called in the state assembly phase of atomic684* modesets, which can be aborted for any reason (including on685* userspace's request to just check whether a configuration would be686* possible). Drivers MUST NOT touch any persistent state (hardware or687* software) or data structures except the passed in @state parameter.688*689* Also since userspace controls in which order properties are set this690* function must not do any input validation (since the state update is691* incomplete and hence likely inconsistent). Instead any such input692* validation must be done in the various atomic_check callbacks.693*694* RETURNS:695*696* 0 if the property has been found, -EINVAL if the property isn't697* implemented by the driver (which should never happen, the core only698* asks for properties attached to this CRTC). No other validation is699* allowed by the driver. The core already checks that the property700* value is within the range (integer, valid enum value, ...) the driver701* set when registering the property.702*/703int (*atomic_set_property)(struct drm_crtc *crtc,704struct drm_crtc_state *state,705struct drm_property *property,706uint64_t val);707/**708* @atomic_get_property:709*710* Reads out the decoded driver-private property. This is used to711* implement the GETCRTC IOCTL.712*713* Do not call this function directly, use714* drm_atomic_crtc_get_property() instead.715*716* This callback is optional if the driver does not support any717* driver-private atomic properties.718*719* RETURNS:720*721* 0 on success, -EINVAL if the property isn't implemented by the722* driver (which should never happen, the core only asks for723* properties attached to this CRTC).724*/725int (*atomic_get_property)(struct drm_crtc *crtc,726const struct drm_crtc_state *state,727struct drm_property *property,728uint64_t *val);729730/**731* @late_register:732*733* This optional hook can be used to register additional userspace734* interfaces attached to the crtc like debugfs interfaces.735* It is called late in the driver load sequence from drm_dev_register().736* Everything added from this callback should be unregistered in737* the early_unregister callback.738*739* Returns:740*741* 0 on success, or a negative error code on failure.742*/743int (*late_register)(struct drm_crtc *crtc);744745/**746* @early_unregister:747*748* This optional hook should be used to unregister the additional749* userspace interfaces attached to the crtc from750* @late_register. It is called from drm_dev_unregister(),751* early in the driver unload sequence to disable userspace access752* before data structures are torndown.753*/754void (*early_unregister)(struct drm_crtc *crtc);755756/**757* @set_crc_source:758*759* Changes the source of CRC checksums of frames at the request of760* userspace, typically for testing purposes. The sources available are761* specific of each driver and a %NULL value indicates that CRC762* generation is to be switched off.763*764* When CRC generation is enabled, the driver should call765* drm_crtc_add_crc_entry() at each frame, providing any information766* that characterizes the frame contents in the crcN arguments, as767* provided from the configured source. Drivers must accept an "auto"768* source name that will select a default source for this CRTC.769*770* This may trigger an atomic modeset commit if necessary, to enable CRC771* generation.772*773* Note that "auto" can depend upon the current modeset configuration,774* e.g. it could pick an encoder or output specific CRC sampling point.775*776* This callback is optional if the driver does not support any CRC777* generation functionality.778*779* RETURNS:780*781* 0 on success or a negative error code on failure.782*/783int (*set_crc_source)(struct drm_crtc *crtc, const char *source);784785/**786* @verify_crc_source:787*788* verifies the source of CRC checksums of frames before setting the789* source for CRC and during crc open. Source parameter can be NULL790* while disabling crc source.791*792* This callback is optional if the driver does not support any CRC793* generation functionality.794*795* RETURNS:796*797* 0 on success or a negative error code on failure.798*/799int (*verify_crc_source)(struct drm_crtc *crtc, const char *source,800size_t *values_cnt);801/**802* @get_crc_sources:803*804* Driver callback for getting a list of all the available sources for805* CRC generation. This callback depends upon verify_crc_source, So806* verify_crc_source callback should be implemented before implementing807* this. Driver can pass full list of available crc sources, this808* callback does the verification on each crc-source before passing it809* to userspace.810*811* This callback is optional if the driver does not support exporting of812* possible CRC sources list.813*814* RETURNS:815*816* a constant character pointer to the list of all the available CRC817* sources. On failure driver should return NULL. count should be818* updated with number of sources in list. if zero we don't process any819* source from the list.820*/821const char *const *(*get_crc_sources)(struct drm_crtc *crtc,822size_t *count);823824/**825* @atomic_print_state:826*827* If driver subclasses &struct drm_crtc_state, it should implement828* this optional hook for printing additional driver specific state.829*830* Do not call this directly, use drm_atomic_crtc_print_state()831* instead.832*/833void (*atomic_print_state)(struct drm_printer *p,834const struct drm_crtc_state *state);835836/**837* @get_vblank_counter:838*839* Driver callback for fetching a raw hardware vblank counter for the840* CRTC. It's meant to be used by new drivers as the replacement of841* &drm_driver.get_vblank_counter hook.842*843* This callback is optional. If a device doesn't have a hardware844* counter, the driver can simply leave the hook as NULL. The DRM core845* will account for missed vblank events while interrupts where disabled846* based on system timestamps.847*848* Wraparound handling and loss of events due to modesetting is dealt849* with in the DRM core code, as long as drivers call850* drm_crtc_vblank_off() and drm_crtc_vblank_on() when disabling or851* enabling a CRTC.852*853* See also &drm_device.vblank_disable_immediate and854* &drm_device.max_vblank_count.855*856* Returns:857*858* Raw vblank counter value.859*/860u32 (*get_vblank_counter)(struct drm_crtc *crtc);861862/**863* @enable_vblank:864*865* Enable vblank interrupts for the CRTC. It's meant to be used by866* new drivers as the replacement of &drm_driver.enable_vblank hook.867*868* Returns:869*870* Zero on success, appropriate errno if the vblank interrupt cannot871* be enabled.872*/873int (*enable_vblank)(struct drm_crtc *crtc);874875/**876* @disable_vblank:877*878* Disable vblank interrupts for the CRTC. It's meant to be used by879* new drivers as the replacement of &drm_driver.disable_vblank hook.880*/881void (*disable_vblank)(struct drm_crtc *crtc);882883/**884* @get_vblank_timestamp:885*886* Called by drm_get_last_vbltimestamp(). Should return a precise887* timestamp when the most recent vblank interval ended or will end.888*889* Specifically, the timestamp in @vblank_time should correspond as890* closely as possible to the time when the first video scanline of891* the video frame after the end of vblank will start scanning out,892* the time immediately after end of the vblank interval. If the893* @crtc is currently inside vblank, this will be a time in the future.894* If the @crtc is currently scanning out a frame, this will be the895* past start time of the current scanout. This is meant to adhere896* to the OpenML OML_sync_control extension specification.897*898* Parameters:899*900* crtc:901* CRTC for which timestamp should be returned.902* max_error:903* Maximum allowable timestamp error in nanoseconds.904* Implementation should strive to provide timestamp905* with an error of at most max_error nanoseconds.906* Returns true upper bound on error for timestamp.907* vblank_time:908* Target location for returned vblank timestamp.909* in_vblank_irq:910* True when called from drm_crtc_handle_vblank(). Some drivers911* need to apply some workarounds for gpu-specific vblank irq quirks912* if flag is set.913*914* Returns:915*916* True on success, false on failure, which means the core should917* fallback to a simple timestamp taken in drm_crtc_handle_vblank().918*/919bool (*get_vblank_timestamp)(struct drm_crtc *crtc,920int *max_error,921ktime_t *vblank_time,922bool in_vblank_irq);923};924925/**926* struct drm_crtc - central CRTC control structure927*928* Each CRTC may have one or more connectors associated with it. This structure929* allows the CRTC to be controlled.930*/931struct drm_crtc {932/** @dev: parent DRM device */933struct drm_device *dev;934/** @port: OF node used by drm_of_find_possible_crtcs(). */935struct device_node *port;936/**937* @head:938*939* List of all CRTCs on @dev, linked from &drm_mode_config.crtc_list.940* Invariant over the lifetime of @dev and therefore does not need941* locking.942*/943struct list_head head;944945/** @name: human readable name, can be overwritten by the driver */946char *name;947948/**949* @mutex:950*951* This provides a read lock for the overall CRTC state (mode, dpms952* state, ...) and a write lock for everything which can be update953* without a full modeset (fb, cursor data, CRTC properties ...). A full954* modeset also need to grab &drm_mode_config.connection_mutex.955*956* For atomic drivers specifically this protects @state.957*/958struct drm_modeset_lock mutex;959960/** @base: base KMS object for ID tracking etc. */961struct drm_mode_object base;962963/**964* @primary:965* Primary plane for this CRTC. Note that this is only966* relevant for legacy IOCTL, it specifies the plane implicitly used by967* the SETCRTC and PAGE_FLIP IOCTLs. It does not have any significance968* beyond that.969*/970struct drm_plane *primary;971972/**973* @cursor:974* Cursor plane for this CRTC. Note that this is only relevant for975* legacy IOCTL, it specifies the plane implicitly used by the SETCURSOR976* and SETCURSOR2 IOCTLs. It does not have any significance977* beyond that.978*/979struct drm_plane *cursor;980981/**982* @index: Position inside the mode_config.list, can be used as an array983* index. It is invariant over the lifetime of the CRTC.984*/985unsigned index;986987/**988* @cursor_x: Current x position of the cursor, used for universal989* cursor planes because the SETCURSOR IOCTL only can update the990* framebuffer without supplying the coordinates. Drivers should not use991* this directly, atomic drivers should look at &drm_plane_state.crtc_x992* of the cursor plane instead.993*/994int cursor_x;995/**996* @cursor_y: Current y position of the cursor, used for universal997* cursor planes because the SETCURSOR IOCTL only can update the998* framebuffer without supplying the coordinates. Drivers should not use999* this directly, atomic drivers should look at &drm_plane_state.crtc_y1000* of the cursor plane instead.1001*/1002int cursor_y;10031004/**1005* @enabled:1006*1007* Is this CRTC enabled? Should only be used by legacy drivers, atomic1008* drivers should instead consult &drm_crtc_state.enable and1009* &drm_crtc_state.active. Atomic drivers can update this by calling1010* drm_atomic_helper_update_legacy_modeset_state().1011*/1012bool enabled;10131014/**1015* @mode:1016*1017* Current mode timings. Should only be used by legacy drivers, atomic1018* drivers should instead consult &drm_crtc_state.mode. Atomic drivers1019* can update this by calling1020* drm_atomic_helper_update_legacy_modeset_state().1021*/1022struct drm_display_mode mode;10231024/**1025* @hwmode:1026*1027* Programmed mode in hw, after adjustments for encoders, crtc, panel1028* scaling etc. Should only be used by legacy drivers, for high1029* precision vblank timestamps in1030* drm_crtc_vblank_helper_get_vblank_timestamp().1031*1032* Note that atomic drivers should not use this, but instead use1033* &drm_crtc_state.adjusted_mode. And for high-precision timestamps1034* drm_crtc_vblank_helper_get_vblank_timestamp() used1035* &drm_vblank_crtc.hwmode,1036* which is filled out by calling drm_calc_timestamping_constants().1037*/1038struct drm_display_mode hwmode;10391040/**1041* @x:1042* x position on screen. Should only be used by legacy drivers, atomic1043* drivers should look at &drm_plane_state.crtc_x of the primary plane1044* instead. Updated by calling1045* drm_atomic_helper_update_legacy_modeset_state().1046*/1047int x;1048/**1049* @y:1050* y position on screen. Should only be used by legacy drivers, atomic1051* drivers should look at &drm_plane_state.crtc_y of the primary plane1052* instead. Updated by calling1053* drm_atomic_helper_update_legacy_modeset_state().1054*/1055int y;10561057/** @funcs: CRTC control functions */1058const struct drm_crtc_funcs *funcs;10591060/**1061* @gamma_size: Size of legacy gamma ramp reported to userspace. Set up1062* by calling drm_mode_crtc_set_gamma_size().1063*1064* Note that atomic drivers need to instead use1065* &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().1066*/1067uint32_t gamma_size;10681069/**1070* @gamma_store: Gamma ramp values used by the legacy SETGAMMA and1071* GETGAMMA IOCTls. Set up by calling drm_mode_crtc_set_gamma_size().1072*1073* Note that atomic drivers need to instead use1074* &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().1075*/1076uint16_t *gamma_store;10771078/** @helper_private: mid-layer private data */1079const struct drm_crtc_helper_funcs *helper_private;10801081/** @properties: property tracking for this CRTC */1082struct drm_object_properties properties;10831084/**1085* @scaling_filter_property: property to apply a particular filter while1086* scaling.1087*/1088struct drm_property *scaling_filter_property;10891090/**1091* @state:1092*1093* Current atomic state for this CRTC.1094*1095* This is protected by @mutex. Note that nonblocking atomic commits1096* access the current CRTC state without taking locks. Either by going1097* through the &struct drm_atomic_state pointers, see1098* for_each_oldnew_crtc_in_state(), for_each_old_crtc_in_state() and1099* for_each_new_crtc_in_state(). Or through careful ordering of atomic1100* commit operations as implemented in the atomic helpers, see1101* &struct drm_crtc_commit.1102*/1103struct drm_crtc_state *state;11041105/**1106* @commit_list:1107*1108* List of &drm_crtc_commit structures tracking pending commits.1109* Protected by @commit_lock. This list holds its own full reference,1110* as does the ongoing commit.1111*1112* "Note that the commit for a state change is also tracked in1113* &drm_crtc_state.commit. For accessing the immediately preceding1114* commit in an atomic update it is recommended to just use that1115* pointer in the old CRTC state, since accessing that doesn't need1116* any locking or list-walking. @commit_list should only be used to1117* stall for framebuffer cleanup that's signalled through1118* &drm_crtc_commit.cleanup_done."1119*/1120struct list_head commit_list;11211122/**1123* @commit_lock:1124*1125* Spinlock to protect @commit_list.1126*/1127spinlock_t commit_lock;11281129/**1130* @debugfs_entry:1131*1132* Debugfs directory for this CRTC.1133*/1134struct dentry *debugfs_entry;11351136/**1137* @crc:1138*1139* Configuration settings of CRC capture.1140*/1141struct drm_crtc_crc crc;11421143/**1144* @fence_context:1145*1146* timeline context used for fence operations.1147*/1148unsigned int fence_context;11491150/**1151* @fence_lock:1152*1153* spinlock to protect the fences in the fence_context.1154*/1155spinlock_t fence_lock;1156/**1157* @fence_seqno:1158*1159* Seqno variable used as monotonic counter for the fences1160* created on the CRTC's timeline.1161*/1162unsigned long fence_seqno;11631164/**1165* @timeline_name:1166*1167* The name of the CRTC's fence timeline.1168*/1169char timeline_name[32];11701171/**1172* @self_refresh_data: Holds the state for the self refresh helpers1173*1174* Initialized via drm_self_refresh_helper_init().1175*/1176struct drm_self_refresh_data *self_refresh_data;1177};11781179/**1180* struct drm_mode_set - new values for a CRTC config change1181* @fb: framebuffer to use for new config1182* @crtc: CRTC whose configuration we're about to change1183* @mode: mode timings to use1184* @x: position of this CRTC relative to @fb1185* @y: position of this CRTC relative to @fb1186* @connectors: array of connectors to drive with this CRTC if possible1187* @num_connectors: size of @connectors array1188*1189* This represents a modeset configuration for the legacy SETCRTC ioctl and is1190* also used internally. Atomic drivers instead use &drm_atomic_state.1191*/1192struct drm_mode_set {1193struct drm_framebuffer *fb;1194struct drm_crtc *crtc;1195struct drm_display_mode *mode;11961197uint32_t x;1198uint32_t y;11991200struct drm_connector **connectors;1201size_t num_connectors;1202};12031204#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)12051206__printf(6, 7)1207int drm_crtc_init_with_planes(struct drm_device *dev,1208struct drm_crtc *crtc,1209struct drm_plane *primary,1210struct drm_plane *cursor,1211const struct drm_crtc_funcs *funcs,1212const char *name, ...);12131214__printf(6, 7)1215int drmm_crtc_init_with_planes(struct drm_device *dev,1216struct drm_crtc *crtc,1217struct drm_plane *primary,1218struct drm_plane *cursor,1219const struct drm_crtc_funcs *funcs,1220const char *name, ...);12211222void drm_crtc_cleanup(struct drm_crtc *crtc);12231224__printf(7, 8)1225void *__drmm_crtc_alloc_with_planes(struct drm_device *dev,1226size_t size, size_t offset,1227struct drm_plane *primary,1228struct drm_plane *cursor,1229const struct drm_crtc_funcs *funcs,1230const char *name, ...);12311232/**1233* drmm_crtc_alloc_with_planes - Allocate and initialize a new CRTC object with1234* specified primary and cursor planes.1235* @dev: DRM device1236* @type: the type of the struct which contains struct &drm_crtc1237* @member: the name of the &drm_crtc within @type.1238* @primary: Primary plane for CRTC1239* @cursor: Cursor plane for CRTC1240* @funcs: callbacks for the new CRTC1241* @name: printf style format string for the CRTC name, or NULL for default name1242*1243* Allocates and initializes a new crtc object. Cleanup is automatically1244* handled through registering drmm_crtc_cleanup() with drmm_add_action().1245*1246* The @drm_crtc_funcs.destroy hook must be NULL.1247*1248* Returns:1249* Pointer to new crtc, or ERR_PTR on failure.1250*/1251#define drmm_crtc_alloc_with_planes(dev, type, member, primary, cursor, funcs, name, ...) \1252((type *)__drmm_crtc_alloc_with_planes(dev, sizeof(type), \1253offsetof(type, member), \1254primary, cursor, funcs, \1255name, ##__VA_ARGS__))12561257/**1258* drm_crtc_index - find the index of a registered CRTC1259* @crtc: CRTC to find index for1260*1261* Given a registered CRTC, return the index of that CRTC within a DRM1262* device's list of CRTCs.1263*/1264static inline unsigned int drm_crtc_index(const struct drm_crtc *crtc)1265{1266return crtc->index;1267}12681269/**1270* drm_crtc_mask - find the mask of a registered CRTC1271* @crtc: CRTC to find mask for1272*1273* Given a registered CRTC, return the mask bit of that CRTC for the1274* &drm_encoder.possible_crtcs and &drm_plane.possible_crtcs fields.1275*/1276static inline uint32_t drm_crtc_mask(const struct drm_crtc *crtc)1277{1278return 1 << drm_crtc_index(crtc);1279}12801281int drm_mode_set_config_internal(struct drm_mode_set *set);1282struct drm_crtc *drm_crtc_from_index(struct drm_device *dev, int idx);12831284/**1285* drm_crtc_find - look up a CRTC object from its ID1286* @dev: DRM device1287* @file_priv: drm file to check for lease against.1288* @id: &drm_mode_object ID1289*1290* This can be used to look up a CRTC from its userspace ID. Only used by1291* drivers for legacy IOCTLs and interface, nowadays extensions to the KMS1292* userspace interface should be done using &drm_property.1293*/1294static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,1295struct drm_file *file_priv,1296uint32_t id)1297{1298struct drm_mode_object *mo;1299mo = drm_mode_object_find(dev, file_priv, id, DRM_MODE_OBJECT_CRTC);1300return mo ? obj_to_crtc(mo) : NULL;1301}13021303/**1304* drm_for_each_crtc - iterate over all CRTCs1305* @crtc: a &struct drm_crtc as the loop cursor1306* @dev: the &struct drm_device1307*1308* Iterate over all CRTCs of @dev.1309*/1310#define drm_for_each_crtc(crtc, dev) \1311list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)13121313/**1314* drm_for_each_crtc_reverse - iterate over all CRTCs in reverse order1315* @crtc: a &struct drm_crtc as the loop cursor1316* @dev: the &struct drm_device1317*1318* Iterate over all CRTCs of @dev.1319*/1320#define drm_for_each_crtc_reverse(crtc, dev) \1321list_for_each_entry_reverse(crtc, &(dev)->mode_config.crtc_list, head)13221323int drm_crtc_create_scaling_filter_property(struct drm_crtc *crtc,1324unsigned int supported_filters);1325bool drm_crtc_in_clone_mode(struct drm_crtc_state *crtc_state);1326#endif /* __DRM_CRTC_H__ */132713281329