Kernel Mode Setting (KMS)¶
Drivers must initialize the mode setting core by callingdrmm_mode_config_init() on the DRM device. The functioninitializes thestructdrm_devicemode_config field and never fails. Once done, mode configuration mustbe setup by initializing the following fields.
int min_width, min_height; int max_width, max_height;Minimum and maximum width and height of the frame buffers in pixelunits.
structdrm_mode_config_funcs*funcs;Mode setting functions.
Overview¶
digraph "KMS" { node [shape=box] subgraph cluster_static { style=dashed label="Static Objects" node [bgcolor=grey style=filled] "drm_plane A" -> "drm_crtc" "drm_plane B" -> "drm_crtc" "drm_crtc" -> "drm_encoder A" "drm_crtc" -> "drm_encoder B" } subgraph cluster_user_created { style=dashed label="Userspace-Created" node [shape=oval] "drm_framebuffer 1" -> "drm_plane A" "drm_framebuffer 2" -> "drm_plane B" } subgraph cluster_connector { style=dashed label="Hotpluggable" "drm_encoder A" -> "drm_connector A" "drm_encoder B" -> "drm_connector B" }}KMS Display Pipeline Overview¶
The basic object structure KMS presents to userspace is fairly simple.Framebuffers (represented bystructdrm_framebuffer,seeFrame Buffer Abstraction) feed into planes. Planes are represented bystructdrm_plane, seePlane Abstraction for moredetails. One or more (or even no) planes feed their pixel data into a CRTC(represented bystructdrm_crtc, seeCRTC Abstraction)for blending. The precise blending step is explained in more detail inPlaneComposition Properties and related chapters.
For the output routing the first step is encoders (represented bystructdrm_encoder, seeEncoder Abstraction). Thoseare really just internal artifacts of the helper libraries used to implement KMSdrivers. Besides that they make it unnecessarily more complicated for userspaceto figure out which connections between a CRTC and a connector are possible, andwhat kind of cloning is supported, they serve no purpose in the userspace API.Unfortunately encoders have been exposed to userspace, hence can’t remove themat this point. Furthermore the exposed restrictions are often wrongly set bydrivers, and in many cases not powerful enough to express the real restrictions.A CRTC can be connected to multiple encoders, and for an active CRTC there mustbe at least one encoder.
The final, and real, endpoint in the display chain is the connector (representedbystructdrm_connector, seeConnectorAbstraction). Connectors can have different possible encoders, but the kerneldriver selects which encoder to use for each connector. The use case is DVI,which could switch between an analog and a digital encoder. Encoders can alsodrive multiple different connectors. There is exactly one active connector forevery active encoder.
Internally the output pipeline is a bit more complex and matches today’shardware more closely:
digraph "Output Pipeline" { node [shape=box] subgraph { "drm_crtc" [bgcolor=grey style=filled] } subgraph cluster_internal { style=dashed label="Internal Pipeline" { node [bgcolor=grey style=filled] "drm_encoder A"; "drm_encoder B"; "drm_encoder C"; } { node [bgcolor=grey style=filled] "drm_encoder B" -> "drm_bridge B" "drm_encoder C" -> "drm_bridge C1" "drm_bridge C1" -> "drm_bridge C2"; } } "drm_crtc" -> "drm_encoder A" "drm_crtc" -> "drm_encoder B" "drm_crtc" -> "drm_encoder C" subgraph cluster_output { style=dashed label="Outputs" "drm_encoder A" -> "drm_connector A"; "drm_bridge B" -> "drm_connector B"; "drm_bridge C2" -> "drm_connector C"; "drm_panel" }}KMS Output Pipeline¶
Internally two additional helper objects come into play. First, to be able toshare code for encoders (sometimes on the same SoC, sometimes off-chip) one ormoreBridges (represented bystructdrm_bridge) can be linked to an encoder. This link is static and cannot bechanged, which means the cross-bar (if there is any) needs to be mapped betweenthe CRTC and any encoders. Often for drivers with bridges there’s no code leftat the encoder level. Atomic drivers can leave out all the encoder callbacks toessentially only leave a dummy routing object behind, which is needed forbackwards compatibility since encoders are exposed to userspace.
The second object is for panels, represented bystructdrm_panel, seePanel Helper Reference. Panels do not have a fixed bindingpoint, but are generally linked to the driver private structure that embedsstructdrm_connector.
Note that currently the bridge chaining and interactions with connectors andpanels are still in-flux and not really fully sorted out yet.
KMS Core Structures and Functions¶
- structdrm_mode_config_funcs¶
basic driver provided mode setting functions
Definition:
struct drm_mode_config_funcs { struct drm_framebuffer *(*fb_create)(struct drm_device *dev, struct drm_file *file_priv, const struct drm_format_info *info, const struct drm_mode_fb_cmd2 *mode_cmd); const struct drm_format_info *(*get_format_info)(u32 pixel_format, u64 modifier); enum drm_mode_status (*mode_valid)(struct drm_device *dev, const struct drm_display_mode *mode); int (*atomic_check)(struct drm_device *dev, struct drm_atomic_state *state); int (*atomic_commit)(struct drm_device *dev, struct drm_atomic_state *state, bool nonblock); struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev); void (*atomic_state_clear)(struct drm_atomic_state *state); void (*atomic_state_free)(struct drm_atomic_state *state);};Members
fb_createCreate a new framebuffer object. The core does basic checks on therequested metadata, but most of that is left to the driver. See
structdrm_mode_fb_cmd2for details.To validate the pixel format and modifier drivers can use
drm_any_plane_has_format()to make sure at least one plane supportsthe requested values. Note that the driver must first determine theactual modifier used if the request doesn’t have it specified,ie. when (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) == 0.IMPORTANT: These implied modifiers for legacy userspace must bestored in struct
drm_framebuffer, including all relevant metadatalikedrm_framebuffer.pitchesanddrm_framebuffer.offsetsif themodifier enables additional planes beyond the fourcc pixel formatcode. This is required by the GETFB2 ioctl.If the parameters are deemed valid and the backing storage objects inthe underlying memory manager all exist, then the driver allocatesa new
drm_framebufferstructure, subclassed to containdriver-specific information (like the internal native buffer objectreferences). It also needs to fill out all relevant metadata, whichshould be done by callingdrm_helper_mode_fill_fb_struct().The initialization is finalized by calling
drm_framebuffer_init(),which registers the framebuffer and makes it accessible to otherthreads.RETURNS:
A new framebuffer with an initial reference count of 1 or a negativeerror code encoded with
ERR_PTR().get_format_infoAllows a driver to return custom format information for specialfb layouts (eg. ones with auxiliary compression control planes).
RETURNS:
The format information specific to the given fb metadata, orNULL if none is found.
mode_validDevice specific validation of display modes. Can be used to rejectmodes that can never be supported. Only device wide constraints canbe checked here. crtc/encoder/bridge/connector specific constraintsshould be checked in the .
mode_valid()hook for each specific object.atomic_checkThis is the only hook to validate an atomic modeset update. Thisfunction must reject any modeset and state changes which the hardwareor driver doesn’t support. This includes but is of course not limitedto:
Checking that the modes, framebuffers, scaling and placementrequirements and so on are within the limits of the hardware.
Checking that any hidden shared resources are not oversubscribed.This can be shared PLLs, shared lanes, overall memory bandwidth,display fifo space (where shared between planes or maybe evenCRTCs).
Checking that virtualized resources exported to userspace are notoversubscribed. For various reasons it can make sense to exposemore planes, crtcs or encoders than which are physically there. Oneexample is dual-pipe operations (which generally should be hiddenfrom userspace if when lockstepped in hardware, exposed otherwise),where a plane might need 1 hardware plane (if it’s just on onepipe), 2 hardware planes (when it spans both pipes) or maybe evenshared a hardware plane with a 2nd plane (if there’s a compatibleplane requested on the area handled by the other pipe).
Check that any transitional state is possible and that ifrequested, the update can indeed be done in the vblank periodwithout temporarily disabling some functions.
Check any other constraints the driver or hardware might have.
This callback also needs to correctly fill out the
drm_crtc_statein this update to make sure thatdrm_atomic_crtc_needs_modeset()reflects the nature of the possible update and returns true if andonly if the update cannot be applied without tearing within onevblank on that CRTC. The core uses that information to rejectupdates which require a full modeset (i.e. blanking the screen, orat least pausing updates for a substantial amount of time) ifuserspace has disallowed that in its request.The driver also does not need to repeat basic input validationlike done for the corresponding legacy entry points. The core doesthat before calling this hook.
See the documentation ofatomic_commit for an exhaustive list oferror conditions which don’t have to be checked at the in thiscallback.
See the documentation for
structdrm_atomic_statefor how exactlyan atomic modeset update is described.Drivers using the atomic helpers can implement this hook using
drm_atomic_helper_check(), or one of the exported sub-functions ofit.RETURNS:
0 on success or one of the below negative error codes:
-EINVAL, if any of the above constraints are violated.
-EDEADLK, when returned from an attempt to acquire an additional
drm_modeset_lockthroughdrm_modeset_lock().-ENOMEM, if allocating additional state sub-structures failed dueto lack of memory.
-EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.This can either be due to a pending signal, or because the driverneeds to completely bail out to recover from an exceptionalsituation like a GPU hang. From a userspace point all errors aretreated equally.
atomic_commitThis is the only hook to commit an atomic modeset update. The coreguarantees thatatomic_check has been called successfully beforecalling this function, and that nothing has been changed in theinterim.
See the documentation for
structdrm_atomic_statefor how exactlyan atomic modeset update is described.Drivers using the atomic helpers can implement this hook using
drm_atomic_helper_commit(), or one of the exported sub-functions ofit.Nonblocking commits (as indicated with the nonblock parameter) mustdo any preparatory work which might result in an unsuccessful commitin the context of this callback. The only exceptions are hardwareerrors resulting in -EIO. But even in that case the driver mustensure that the display pipe is at least running, to avoidcompositors crashing when pageflips don’t work. Anything else,specifically committing the update to the hardware, should be donewithout blocking the caller. For updates which do not require amodeset this must be guaranteed.
The driver must wait for any pending rendering to the newframebuffers to complete before executing the flip. It should alsowait for any pending rendering from other drivers if the underlyingbuffer is a shared dma-buf. Nonblocking commits must not wait forrendering in the context of this callback.
An application can request to be notified when the atomic commit hascompleted. These events are per-CRTC and can be distinguished by theCRTC index supplied in
drm_eventto userspace.The drm core will supply a
structdrm_eventin each CRTC’sdrm_crtc_state.event. See the documentation fordrm_crtc_state.eventfor more details about the precise semantics ofthis event.NOTE:
Drivers are not allowed to shut down any display pipe successfullyenabled through an atomic commit on their own. Doing so can result incompositors crashing if a page flip is suddenly rejected because thepipe is off.
RETURNS:
0 on success or one of the below negative error codes:
-EBUSY, if a nonblocking updated is requested and there isan earlier updated pending. Drivers are allowed to support a queueof outstanding updates, but currently no driver supports that.Note that drivers must wait for preceding updates to complete if asynchronous update is requested, they are not allowed to fail thecommit in that case.
-ENOMEM, if the driver failed to allocate memory. Specificallythis can happen when trying to pin framebuffers, which must onlybe done when committing the state.
-ENOSPC, as a refinement of the more generic -ENOMEM to indicatethat the driver has run out of vram, iommu space or similar GPUaddress space needed for framebuffer.
-EIO, if the hardware completely died.
-EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.This can either be due to a pending signal, or because the driverneeds to completely bail out to recover from an exceptionalsituation like a GPU hang. From a userspace point of view all errors aretreated equally.
This list is exhaustive. Specifically this hook is not allowed toreturn -EINVAL (any invalid requests should be caught inatomic_check) or -EDEADLK (this function must not acquireadditional modeset locks).
atomic_state_allocThis optional hook can be used by drivers that want to subclass struct
drm_atomic_stateto be able to track their own driver-private globalstate easily. If this hook is implemented, drivers must alsoimplementatomic_state_clear andatomic_state_free.Subclassing of
drm_atomic_stateis deprecated in favour of usingdrm_private_stateanddrm_private_obj.RETURNS:
A new
drm_atomic_stateon success or NULL on failure.atomic_state_clearThis hook must clear any driver private state duplicated into thepassed-in
drm_atomic_state. This hook is called when the callerencountered adrm_modeset_lockdeadlock and needs to drop allalready acquired locks as part of the deadlock avoidance danceimplemented indrm_modeset_backoff().Any duplicated state must be invalidated since a concurrent atomicupdate might change it, and the drm atomic interfaces always applyupdates as relative changes to the current state.
Drivers that implement this must call
drm_atomic_state_default_clear()to clear common state.Subclassing of
drm_atomic_stateis deprecated in favour of usingdrm_private_stateanddrm_private_obj.atomic_state_freeThis hook needs driver private resources and the
drm_atomic_stateitself. Note that the core first callsdrm_atomic_state_clear()toavoid code duplicate between the clear and free hooks.Drivers that implement this must call
drm_atomic_state_default_release()to release common resources.Subclassing of
drm_atomic_stateis deprecated in favour of usingdrm_private_stateanddrm_private_obj.
Description
Some global (i.e. not per-CRTC, connector, etc) mode setting functions thatinvolve drivers.
- structdrm_mode_config¶
Mode configuration control structure
Definition:
struct drm_mode_config { struct mutex mutex; struct drm_modeset_lock connection_mutex; struct drm_modeset_acquire_ctx *acquire_ctx; struct mutex idr_mutex; struct idr object_idr; struct idr tile_idr; struct mutex fb_lock; int num_fb; struct list_head fb_list; spinlock_t connector_list_lock; int num_connector; struct ida connector_ida; struct list_head connector_list; struct llist_head connector_free_list; struct work_struct connector_free_work; int num_encoder; struct list_head encoder_list; int num_total_plane; struct list_head plane_list; struct raw_spinlock panic_lock; int num_colorop; struct list_head colorop_list; int num_crtc; struct list_head crtc_list; struct list_head property_list; struct list_head privobj_list; unsigned int min_width, min_height; unsigned int max_width, max_height; const struct drm_mode_config_funcs *funcs; bool poll_enabled; bool poll_running; bool delayed_event; struct delayed_work output_poll_work; struct mutex blob_lock; struct list_head property_blob_list; struct drm_property *edid_property; struct drm_property *dpms_property; struct drm_property *path_property; struct drm_property *tile_property; struct drm_property *panel_type_property; struct drm_property *link_status_property; struct drm_property *plane_type_property; struct drm_property *prop_src_x; struct drm_property *prop_src_y; struct drm_property *prop_src_w; struct drm_property *prop_src_h; struct drm_property *prop_crtc_x; struct drm_property *prop_crtc_y; struct drm_property *prop_crtc_w; struct drm_property *prop_crtc_h; struct drm_property *prop_fb_id; struct drm_property *prop_in_fence_fd; struct drm_property *prop_out_fence_ptr; struct drm_property *prop_crtc_id; struct drm_property *prop_fb_damage_clips; struct drm_property *prop_active; struct drm_property *prop_mode_id; struct drm_property *prop_vrr_enabled; struct drm_property *dvi_i_subconnector_property; struct drm_property *dvi_i_select_subconnector_property; struct drm_property *dp_subconnector_property; struct drm_property *tv_subconnector_property; struct drm_property *tv_select_subconnector_property; struct drm_property *legacy_tv_mode_property; struct drm_property *tv_mode_property; struct drm_property *tv_left_margin_property; struct drm_property *tv_right_margin_property; struct drm_property *tv_top_margin_property; struct drm_property *tv_bottom_margin_property; struct drm_property *tv_brightness_property; struct drm_property *tv_contrast_property; struct drm_property *tv_flicker_reduction_property; struct drm_property *tv_overscan_property; struct drm_property *tv_saturation_property; struct drm_property *tv_hue_property; struct drm_property *scaling_mode_property; struct drm_property *aspect_ratio_property; struct drm_property *content_type_property; struct drm_property *degamma_lut_property; struct drm_property *degamma_lut_size_property; struct drm_property *ctm_property; struct drm_property *gamma_lut_property; struct drm_property *gamma_lut_size_property; struct drm_property *suggested_x_property; struct drm_property *suggested_y_property; struct drm_property *non_desktop_property; struct drm_property *panel_orientation_property; struct drm_property *writeback_fb_id_property; struct drm_property *writeback_pixel_formats_property; struct drm_property *writeback_out_fence_ptr_property; struct drm_property *hdr_output_metadata_property; struct drm_property *content_protection_property; struct drm_property *hdcp_content_type_property; uint32_t preferred_depth, prefer_shadow; bool quirk_addfb_prefer_xbgr_30bpp; bool quirk_addfb_prefer_host_byte_order; bool async_page_flip; bool fb_modifiers_not_supported; bool normalize_zpos; struct drm_property *modifiers_property; struct drm_property *async_modifiers_property; struct drm_property *size_hints_property; uint32_t cursor_width, cursor_height; struct drm_atomic_state *suspend_state; const struct drm_mode_config_helper_funcs *helper_private;};Members
mutexThis is the big scary modeset BKL which protects everything thatisn’t protect otherwise. Scope is unclear and fuzzy, try to removeanything from under its protection and move it into more well-scopedlocks.
The one important thing this protects is the use ofacquire_ctx.
connection_mutexThis protects connector state and the connector to encoder to CRTCrouting chain.
For atomic drivers specifically this protects
drm_connector.state.acquire_ctxGlobal implicit acquire context used by atomic drivers for legacyIOCTLs. Deprecated, since implicit locking contexts make itimpossible to use driver-private
structdrm_modeset_lock. Users ofthis must holdmutex.idr_mutexMutex for KMS ID allocation and management. Protects bothobject_idrandtile_idr.
object_idrMain KMS ID tracking object. Use this idr for all IDs, fb, crtc,connector, modes - just makes life easier to have only one.
tile_idrUse this idr for allocating new IDs for tiled sinks like use in somehigh-res DP MST screens.
fb_lockMutex to protect fb the globalfb_list andnum_fb.
num_fbNumber of entries onfb_list.
fb_listList of all
structdrm_framebuffer.connector_list_lockProtectsnum_connector andconnector_list andconnector_free_list.
num_connectorNumber of connectors on this device. Protected byconnector_list_lock.
connector_idaID allocator for connector indices.
connector_listList of connector objects linked with
drm_connector.head. Protectedbyconnector_list_lock. Only usedrm_for_each_connector_iter()andstructdrm_connector_list_iterto walk this list.connector_free_listList of connector objects linked with
drm_connector.free_head.Protected byconnector_list_lock. Used bydrm_for_each_connector_iter()andstructdrm_connector_list_iterto savely free connectors usingconnector_free_work.connector_free_workWork to clean upconnector_free_list.
num_encoderNumber of encoders on this device. This is invariant over thelifetime of a device and hence doesn’t need any locks.
encoder_listList of encoder objects linked with
drm_encoder.head. This isinvariant over the lifetime of a device and hence doesn’t need anylocks.num_total_planeNumber of universal (i.e. with primary/curso) planes on this device.This is invariant over the lifetime of a device and hence doesn’tneed any locks.
plane_listList of plane objects linked with
drm_plane.head. This is invariantover the lifetime of a device and hence doesn’t need any locks.panic_lockRaw spinlock used to protect critical sections of code that accessthe display hardware or modeset software state, which the panicprinting code must be protected against. See
drm_panic_trylock(),drm_panic_lock()anddrm_panic_unlock().num_coloropNumber of colorop objects on this device.This is invariant over the lifetime of a device and hence doesn’tneed any locks.
colorop_listList of colorop objects linked with
drm_colorop.head. This isinvariant over the lifetime of a device and hence doesn’t need anylocks.num_crtcNumber of CRTCs on this device linked with
drm_crtc.head. This is invariant over the lifetimeof a device and hence doesn’t need any locks.crtc_listList of CRTC objects linked with
drm_crtc.head. This is invariantover the lifetime of a device and hence doesn’t need any locks.property_listList of property type objects linked with
drm_property.head. This isinvariant over the lifetime of a device and hence doesn’t need anylocks.privobj_listList of private objects linked with
drm_private_obj.head. This isinvariant over the lifetime of a device and hence doesn’t need anylocks.min_widthminimum fb pixel width on this device
min_heightminimum fb pixel height on this device
max_widthmaximum fb pixel width on this device
max_heightmaximum fb pixel height on this device
funcscore driver provided mode setting functions
poll_enabledtrack polling support for this device
poll_runningtrack polling status for this device
delayed_eventtrack delayed poll uevent deliver for this device
output_poll_workdelayed work for polling in process context
blob_lockMutex for blob property allocation and management, protectsproperty_blob_list and
drm_file.blobs.property_blob_listList of all the blob property objects linked with
drm_property_blob.head. Protected byblob_lock.edid_propertyDefault connector property to hold the EDID of thecurrently connected sink, if any.
dpms_propertyDefault connector property to control theconnector’s DPMS state.
path_propertyDefault connector property to hold the DP MST pathfor the port.
tile_propertyDefault connector property to store the tileposition of a tiled screen, for sinks which need to be driven withmultiple CRTCs.
panel_type_propertyDefault connector property for panel type
link_status_propertyDefault connector property for link statusof a connector
plane_type_propertyDefault plane property to differentiateCURSOR, PRIMARY and OVERLAY legacy uses of planes.
prop_src_xDefault atomic plane property for the plane sourceposition in the connected
drm_framebuffer.prop_src_yDefault atomic plane property for the plane sourceposition in the connected
drm_framebuffer.prop_src_wDefault atomic plane property for the plane sourceposition in the connected
drm_framebuffer.prop_src_hDefault atomic plane property for the plane sourceposition in the connected
drm_framebuffer.prop_crtc_xDefault atomic plane property for the plane destinationposition in the
drm_crtcis being shown on.prop_crtc_yDefault atomic plane property for the plane destinationposition in the
drm_crtcis being shown on.prop_crtc_wDefault atomic plane property for the plane destinationposition in the
drm_crtcis being shown on.prop_crtc_hDefault atomic plane property for the plane destinationposition in the
drm_crtcis being shown on.prop_fb_idDefault atomic plane property to specify the
drm_framebuffer.prop_in_fence_fdSync File fd representing the incoming fencesfor a Plane.
prop_out_fence_ptrSync File fd pointer representing theoutgoing fences for a CRTC. Userspace should provide a pointer to avalue of type s32, and then cast that pointer to u64.
prop_crtc_idDefault atomic plane property to specify the
drm_crtc.prop_fb_damage_clipsOptional plane property to mark damagedregions on the plane in framebuffer coordinates of the framebufferattached to the plane.
The layout of blob data is simply an array of
drm_mode_rect. Unlikeplane src coordinates, damage clips are not in 16.16 fixed point.prop_activeDefault atomic CRTC property to control the activestate, which is the simplified implementation for DPMS in atomicdrivers.
prop_mode_idDefault atomic CRTC property to set the mode for aCRTC. A 0 mode implies that the CRTC is entirely disabled - allconnectors must be of and active must be set to disabled, too.
prop_vrr_enabledDefault atomic CRTC property to indicatewhether variable refresh rate should be enabled on the CRTC.
dvi_i_subconnector_propertyOptional DVI-I property todifferentiate between analog or digital mode.
dvi_i_select_subconnector_propertyOptional DVI-I property toselect between analog or digital mode.
dp_subconnector_propertyOptional DP property to differentiatebetween different DP downstream port types.
tv_subconnector_propertyOptional TV property to differentiatebetween different TV connector types.
tv_select_subconnector_propertyOptional TV property to selectbetween different TV connector types.
legacy_tv_mode_propertyOptional TV property to selectthe output TV mode.
Superseded bytv_mode_property
tv_mode_propertyOptional TV property to select the TVstandard output on the connector.
tv_left_margin_propertyOptional TV property to set the leftmargin (expressed in pixels).
tv_right_margin_propertyOptional TV property to set the rightmargin (expressed in pixels).
tv_top_margin_propertyOptional TV property to set the rightmargin (expressed in pixels).
tv_bottom_margin_propertyOptional TV property to set the rightmargin (expressed in pixels).
tv_brightness_propertyOptional TV property to set thebrightness.
tv_contrast_propertyOptional TV property to set thecontrast.
tv_flicker_reduction_propertyOptional TV property to control theflicker reduction mode.
tv_overscan_propertyOptional TV property to control the overscansetting.
tv_saturation_propertyOptional TV property to set thesaturation.
tv_hue_propertyOptional TV property to set the hue.
scaling_mode_propertyOptional connector property to control theupscaling, mostly used for built-in panels.
aspect_ratio_propertyOptional connector property to control theHDMI infoframe aspect ratio setting.
content_type_propertyOptional connector property to control theHDMI infoframe content type setting.
degamma_lut_propertyOptional CRTC property to set the LUT used toconvert the framebuffer’s colors to linear gamma.
degamma_lut_size_propertyOptional CRTC property for the size ofthe degamma LUT as supported by the driver (read-only).
ctm_propertyOptional CRTC property to set thematrix used to convert colors after the lookup in thedegamma LUT.
gamma_lut_propertyOptional CRTC property to set the LUT used toconvert the colors, after the CTM matrix, to the gamma space of theconnected screen.
gamma_lut_size_propertyOptional CRTC property for the size of thegamma LUT as supported by the driver (read-only).
suggested_x_propertyOptional connector property with a hint forthe position of the output on the host’s screen.
suggested_y_propertyOptional connector property with a hint forthe position of the output on the host’s screen.
non_desktop_propertyOptional connector property with a hintthat device isn’t a standard display, and the console/desktop,should not be displayed on it.
panel_orientation_propertyOptional connector property indicatinghow the lcd-panel is mounted inside the casing (e.g. normal orupside-down).
writeback_fb_id_propertyProperty for writeback connectors, storingthe ID of the output framebuffer.See also:
drm_writeback_connector_init()writeback_pixel_formats_propertyProperty for writeback connectors,storing an array of the supported pixel formats for the writebackengine (read-only).See also:
drm_writeback_connector_init()writeback_out_fence_ptr_propertyProperty for writeback connectors,fd pointer representing the outgoing fences for a writebackconnector. Userspace should provide a pointer to a value of type s32,and then cast that pointer to u64.See also:
drm_writeback_connector_init()hdr_output_metadata_propertyConnector property containing hdrmetatada. This will be provided by userspace compositors basedon HDR content
content_protection_propertyDRM ENUM property for contentprotection. See
drm_connector_attach_content_protection_property().hdcp_content_type_propertyDRM ENUM property for type ofProtected Content.
preferred_depthpreferred RBG pixel depth, used by fb helpers
prefer_shadowhint to userspace to prefer shadow-fb rendering
quirk_addfb_prefer_xbgr_30bppSpecial hack for legacy ADDFB to keep nouveau userspace happy. Shouldonly ever be set by the nouveau kernel driver.
quirk_addfb_prefer_host_byte_orderWhen set to true
drm_mode_addfb()will pick host byte orderpixel_format when callingdrm_mode_addfb2(). This is howdrm_mode_addfb()should have worked from day one. Itdidn’t though, so we ended up with quirks in both kerneland userspace drivers to deal with the broken behavior.Simply fixingdrm_mode_addfb()unconditionally would breakthese drivers, so add a quirk bit here to allow driversopt-in.async_page_flipDoes this device support async flips on the primaryplane?
fb_modifiers_not_supportedWhen this flag is set, the DRM device will not expose modifiersupport to userspace. This is only used by legacy drivers that inferthe buffer layout through heuristics without using modifiers. Newdrivers shall not set fhis flag.
normalize_zposIf true the drm core will call
drm_atomic_normalize_zpos()as part ofatomic mode checking fromdrm_atomic_helper_check()modifiers_propertyPlane property to list support modifier/formatcombination.
async_modifiers_propertyPlane property to list support modifier/formatcombination for asynchronous flips.
size_hints_propertyPlane SIZE_HINTS property.
cursor_widthhint to userspace for max cursor width
cursor_heighthint to userspace for max cursor height
suspend_stateAtomic state when suspended.Set by
drm_mode_config_helper_suspend()and cleared bydrm_mode_config_helper_resume().helper_privatemid-layer private data
Description
Core mode resource tracking structure. All CRTC, encoders, and connectorsenumerated by the driver are added here, as are global properties. Someglobal restrictions are also here, e.g. dimension restrictions.
Framebuffer sizes refer to the virtual screen that can be displayed bythe CRTC. This can be different from the physical resolution programmed.The minimum width and height, stored inmin_width andmin_height,describe the smallest size of the framebuffer. It correlates to theminimum programmable resolution.The maximum width, stored inmax_width, is typically limited by themaximum pitch between two adjacent scanlines. The maximum height, storedinmax_height, is usually only limited by the amount of addressable videomemory. For hardware that has no real maximum, drivers should pick areasonable default.
See alsoDRM_SHADOW_PLANE_MAX_WIDTH andDRM_SHADOW_PLANE_MAX_HEIGHT.
- intdrm_mode_config_init(structdrm_device*dev)¶
DRM mode_configuration structure initialization
Parameters
structdrm_device*devDRM device
Description
This is the unmanaged version ofdrmm_mode_config_init() for drivers whichstill explicitly calldrm_mode_config_cleanup().
FIXME: This function is deprecated and drivers should be converted over todrmm_mode_config_init().
- voiddrm_mode_config_reset(structdrm_device*dev)¶
call ->reset callbacks
Parameters
structdrm_device*devdrm device
Description
This functions calls all the crtc’s, encoder’s and connector’s ->resetcallback. Drivers can use this in e.g. their driver load or resume code toreset hardware and software state.
- intdrmm_mode_config_init(structdrm_device*dev)¶
managed DRM mode_configuration structure initialization
Parameters
structdrm_device*devDRM device
Description
Initializedev’s mode_config structure, used for tracking the graphicsconfiguration ofdev.
Since this initializes the modeset locks, no locking is possible. Which is noproblem, since this should happen single threaded at init time. It is thedriver’s problem to ensure this guarantee.
Cleanup is automatically handled through registering drm_mode_config_cleanupwithdrmm_add_action().
Return
0 on success, negative error value on failure.
- voiddrm_mode_config_cleanup(structdrm_device*dev)¶
free up DRM mode_config info
Parameters
structdrm_device*devDRM device
Description
Free up all the connectors and CRTCs associated with this DRM device, thenfree up the framebuffers and associated buffer objects.
Note that since this /should/ happen single-threaded at driver/deviceteardown time, no locking is required. It’s the driver’s job to ensure thatthis guarantee actually holds true.
FIXME: With the manageddrmm_mode_config_init() it is no longer necessary fordrivers to explicitly call this function.
Modeset Base Object Abstraction¶
digraph { node [shape=box] "drm_property A" -> "drm_mode_object A" "drm_property A" -> "drm_mode_object B" "drm_property B" -> "drm_mode_object A"}Mode Objects and Properties¶
The base structure for all KMS objects isstructdrm_mode_object. One of the base services it provides is tracking properties,which are especially important for the atomic IOCTL (seeAtomic ModeSetting). The somewhat surprising part here is that properties are notdirectly instantiated on each object, but free-standing mode objects themselves,represented bystructdrm_property, which only specifythe type and value range of a property. Any given property can be attachedmultiple times to different objects usingdrm_object_attach_property().
- structdrm_mode_object¶
base structure for modeset objects
Definition:
struct drm_mode_object { uint32_t id; uint32_t type; struct drm_object_properties *properties; struct kref refcount; void (*free_cb)(struct kref *kref);};Members
iduserspace visible identifier
typetype of the object, one of DRM_MODE_OBJECT_*
propertiesproperties attached to this object, including values
refcountreference count for objects with dynamic lifetime
free_cbfree function callback, only set for objects with dynamic lifetime
Description
Base structure for modeset objects visible to userspace. Objects can belooked up usingdrm_mode_object_find(). Besides basic uapi interfaceproperties likeid andtype it provides two services:
It tracks attached properties and their values. This is used by
drm_crtc,drm_planeanddrm_connector. Properties are attached by callingdrm_object_attach_property()before the object is visible to userspace.For objects with dynamic lifetimes (as indicated by a non-NULLfree_cb) itprovides reference counting through
drm_mode_object_get()anddrm_mode_object_put(). This is used bydrm_framebuffer,drm_connectoranddrm_property_blob. These objects provide specialized referencecounting wrappers.
- structdrm_object_properties¶
property tracking for
drm_mode_object
Definition:
struct drm_object_properties { int count; struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY]; uint64_t values[DRM_OBJECT_MAX_PROPERTY];};Members
countnumber of valid properties, must be less than or equal toDRM_OBJECT_MAX_PROPERTY.
propertiesArray of pointers to
drm_property.NOTE: if we ever start dynamically destroying properties (ie.not at
drm_mode_config_cleanup()time), then we’d have to doa better job of detaching property from mode objects to avoiddangling property pointers:valuesArray to store the property values, matchingproperties. Donot read/write values directly, but use
drm_object_property_get_value()anddrm_object_property_set_value().Note that atomic drivers do not store mutable properties in thisarray, but only the decoded values in the corresponding statestructure. The decoding is done using the
drm_crtc.atomic_get_propertyanddrm_crtc.atomic_set_propertyhooks forstructdrm_crtc. Forstructdrm_planethe hooks aredrm_plane_funcs.atomic_get_propertyanddrm_plane_funcs.atomic_set_property. And forstructdrm_connectorthe hooks aredrm_connector_funcs.atomic_get_propertyanddrm_connector_funcs.atomic_set_property.Hence atomic drivers should not use
drm_object_property_set_value()anddrm_object_property_get_value()on mutable objects, i.e. thosewithout the DRM_MODE_PROP_IMMUTABLE flag set.For atomic drivers the default value of properties is stored in thisarray, so drm_object_property_get_default_value can be used toretrieve it.
- structdrm_mode_object*drm_mode_object_find(structdrm_device*dev,structdrm_file*file_priv,uint32_tid,uint32_ttype)¶
look up a drm object with static lifetime
Parameters
structdrm_device*devdrm device
structdrm_file*file_privdrm file
uint32_tidid of the mode object
uint32_ttypetype of the mode object
Description
This function is used to look up a modeset object. It will acquire areference for reference counted objects. This reference must be dropped againby callinddrm_mode_object_put().
- voiddrm_mode_object_put(structdrm_mode_object*obj)¶
release a mode object reference
Parameters
structdrm_mode_object*objDRM mode object
Description
This function decrements the object’s refcount if it is a refcounted modesetobject. It is a no-op on any other object. This is used to drop referencesacquired withdrm_mode_object_get().
- voiddrm_mode_object_get(structdrm_mode_object*obj)¶
acquire a mode object reference
Parameters
structdrm_mode_object*objDRM mode object
Description
This function increments the object’s refcount if it is a refcounted modesetobject. It is a no-op on any other object. References should be dropped againby callingdrm_mode_object_put().
- voiddrm_object_attach_property(structdrm_mode_object*obj,structdrm_property*property,uint64_tinit_val)¶
attach a property to a modeset object
Parameters
structdrm_mode_object*objdrm modeset object
structdrm_property*propertyproperty to attach
uint64_tinit_valinitial value of the property
Description
This attaches the given property to the modeset object with the given initialvalue. Currently this function cannot fail since the properties are stored ina statically sized array.
Note that all properties must be attached before the object itself isregistered and accessible from userspace.
- intdrm_object_property_set_value(structdrm_mode_object*obj,structdrm_property*property,uint64_tval)¶
set the value of a property
Parameters
structdrm_mode_object*objdrm mode object to set property value for
structdrm_property*propertyproperty to set
uint64_tvalvalue the property should be set to
Description
This function sets a given property on a given object. This function onlychanges the software state of the property, it does not call into thedriver’s ->set_property callback.
Note that atomic drivers should not have any need to call this, the core willensure consistency of values reported back to userspace through theappropriate ->atomic_get_property callback. Only legacy drivers should callthis function to update the tracked value (after clamping and otherrestrictions have been applied).
Return
Zero on success, error code on failure.
- intdrm_object_property_get_value(structdrm_mode_object*obj,structdrm_property*property,uint64_t*val)¶
retrieve the value of a property
Parameters
structdrm_mode_object*objdrm mode object to get property value from
structdrm_property*propertyproperty to retrieve
uint64_t*valstorage for the property value
Description
This function retrieves the softare state of the given property for the givenproperty. Since there is no driver callback to retrieve the current propertyvalue this might be out of sync with the hardware, depending upon the driverand property.
Atomic drivers should never call this function directly, the core will readout property values through the various ->atomic_get_property callbacks.
Return
Zero on success, error code on failure.
- intdrm_object_property_get_default_value(structdrm_mode_object*obj,structdrm_property*property,uint64_t*val)¶
retrieve the default value of a property when in atomic mode.
Parameters
structdrm_mode_object*objdrm mode object to get property value from
structdrm_property*propertyproperty to retrieve
uint64_t*valstorage for the property value
Description
This function retrieves the default state of the given property as passed into drm_object_attach_property
Only atomic drivers should call this function directly, as for non-atomicdrivers it will return the current value.
Return
Zero on success, error code on failure.
- intdrm_object_immutable_property_get_value(structdrm_mode_object*obj,structdrm_property*property,uint64_t*val)¶
retrieve the value of a property
Parameters
structdrm_mode_object*objdrm mode object to get property value from
structdrm_property*propertyproperty to retrieve
uint64_t*valstorage for the property value
Description
This function retrieves the software state of the given immutable propertyfor the given mode object.
This function can be called by both atomic and non-atomic drivers.
Return
Zero on success, error code on failure.
Atomic Mode Setting¶
digraph { node [shape=box] subgraph cluster_state { style=dashed label="Free-standing state" "drm_atomic_state" -> "duplicated drm_plane_state A" "drm_atomic_state" -> "duplicated drm_plane_state B" "drm_atomic_state" -> "duplicated drm_crtc_state" "drm_atomic_state" -> "duplicated drm_connector_state" "drm_atomic_state" -> "duplicated driver private state" } subgraph cluster_current { style=dashed label="Current state" "drm_device" -> "drm_plane A" "drm_device" -> "drm_plane B" "drm_device" -> "drm_crtc" "drm_device" -> "drm_connector" "drm_device" -> "driver private object" "drm_plane A" -> "drm_plane_state A" "drm_plane B" -> "drm_plane_state B" "drm_crtc" -> "drm_crtc_state" "drm_connector" -> "drm_connector_state" "driver private object" -> "driver private state" } "drm_atomic_state" -> "drm_device" [label="atomic_commit"] "duplicated drm_plane_state A" -> "drm_device"[style=invis]}Mode Objects and Properties¶
Atomic provides transactional modeset (including planes) updates, but abit differently from the usual transactional approach of try-commit androllback:
Firstly, no hardware changes are allowed when the commit would fail. Thisallows us to implement the DRM_MODE_ATOMIC_TEST_ONLY mode, which allowsuserspace to explore whether certain configurations would work or not.
This would still allow setting and rollback of just the software state,simplifying conversion of existing drivers. But auditing drivers forcorrectness of the atomic_check code becomes really hard with that: Rollingback changes in data structures all over the place is hard to get right.
Lastly, for backwards compatibility and to support all use-cases, atomicupdates need to be incremental and be able to execute in parallel. Hardwaredoesn’t always allow it, but where possible plane updates on different CRTCsshould not interfere, and not get stalled due to output routing changing ondifferent CRTCs.
Taken all together there’s two consequences for the atomic design:
The overall state is split up into per-object state structures:
structdrm_plane_statefor planes,structdrm_crtc_statefor CRTCs andstructdrm_connector_statefor connectors. These are the onlyobjects with userspace-visible and settable state. For internal state driverscan subclass these structures through embedding, or add entirely new statestructures for their globally shared hardware functions, seestructdrm_private_state.An atomic update is assembled and validated as an entirely free-standing pileof structures within the
drm_atomic_statecontainer. Driver private state structures are also tracked in the samestructure; see the next chapter. Only when a state is committed is it appliedto the driver and modeset objects. This way rolling back an update boils downto releasing memory and unreferencing objects like framebuffers.
Locking of atomic state structures is internally usingstructdrm_modeset_lock. As a general rule the locking shouldn’t beexposed to drivers, instead the right locks should be automatically acquired byany function that duplicates or peeks into a state, like e.g.drm_atomic_get_crtc_state(). Locking only protects the software datastructure, ordering of committing state changes to hardware is sequenced usingstructdrm_crtc_commit.
Read on in this chapter, and also inAtomic Modeset Helper Functions Reference for more detailedcoverage of specific topics.
Handling Driver Private State¶
Very often the DRM objects exposed to userspace in the atomic modeset api(drm_connector,drm_crtc anddrm_plane) do not map neatly to theunderlying hardware. Especially for any kind of shared resources (e.g. sharedclocks, scaler units, bandwidth and fifo limits shared among a group ofplanes or CRTCs, and so on) it makes sense to model these as independentobjects. Drivers then need to do similar state tracking and commit ordering forsuch private (since not exposed to userspace) objects as the atomic core andhelpers already provide for connectors, planes and CRTCs.
To make this easier on drivers the atomic core provides some support to trackdriver private state objects using structdrm_private_obj, with theassociated state structdrm_private_state.
Similar to userspace-exposed objects, private state structures can beacquired by callingdrm_atomic_get_private_obj_state(). This also takes careof locking, hence drivers should not have a need to calldrm_modeset_lock()directly. Sequence of the actual hardware state commit is not handled,drivers might need to keep track ofstructdrm_crtc_commit within subclassedstructure ofdrm_private_state as necessary, e.g. similar todrm_plane_state.commit. See alsodrm_atomic_state.fake_commit.
All private state structures contained in adrm_atomic_state update can beiterated usingfor_each_oldnew_private_obj_in_state(),for_each_new_private_obj_in_state() andfor_each_old_private_obj_in_state().Drivers are recommended to wrap these for each type of driver private stateobject they have, filtering ondrm_private_obj.funcs usingfor_each_if(), atleast if they want to iterate over all objects of a given type.
An earlier way to handle driver private state was by subclassing structdrm_atomic_state. But since that encourages non-standard ways to implementthe check/commit split atomic requires (by using e.g. “check and rollback orcommit instead” of “duplicate state, check, then either commit or releaseduplicated state) it is deprecated in favour of usingdrm_private_state.
Atomic Mode Setting Function Reference¶
- structdrm_crtc_commit¶
track modeset commits on a CRTC
Definition:
struct drm_crtc_commit { struct drm_crtc *crtc; struct kref ref; struct completion flip_done; struct completion hw_done; struct completion cleanup_done; struct list_head commit_entry; struct drm_pending_vblank_event *event; bool abort_completion;};Members
crtcDRM CRTC for this commit.
refReference count for this structure. Needed to allow blocking oncompletions without the risk of the completion disappearingmeanwhile.
flip_doneWill be signaled when the hardware has flipped to the new set ofbuffers. Signals at the same time as when the drm event for thiscommit is sent to userspace, or when an out-fence is singalled. Notethat for most hardware, in most cases this happens afterhw_done issignalled.
Completion of this stage is signalled implicitly by calling
drm_crtc_send_vblank_event()ondrm_crtc_state.event.hw_doneWill be signalled when all hw register changes for this commit havebeen written out. Especially when disabling a pipe this can be muchlater thanflip_done, since that can signal already when thescreen goes black, whereas to fully shut down a pipe more registerI/O is required.
Note that this does not need to include separately reference-countedresources like backing storage buffer pinning, or runtime pmmanagement.
Drivers should call
drm_atomic_helper_commit_hw_done()to signalcompletion of this stage.cleanup_doneWill be signalled after old buffers have been cleaned up by calling
drm_atomic_helper_cleanup_planes(). Since this can only happen aftera vblank wait completed it might be a bit later. This completion isuseful to throttle updates and avoid hardware updates getting aheadof the buffer cleanup too much.Drivers should call
drm_atomic_helper_commit_cleanup_done()to signalcompletion of this stage.commit_entryEntry on the per-CRTC
drm_crtc.commit_list. Protected by$drm_crtc.commit_lock.eventdrm_pending_vblank_eventpointer to clean up private events.abort_completionA flag that’s set after
drm_atomic_helper_setup_commit()takes asecond reference for the completion of $drm_crtc_state.event. It’sused by the free code to remove the second reference if commit fails.
Description
This structure is used to track pending modeset changes and atomic commit ona per-CRTC basis. Since updating the list should never block, this structureis reference counted to allow waiters to safely wait on an event to complete,without holding any locks.
It has 3 different events in total to allow a fine-grained synchronizationbetween outstanding updates:
atomic commit thread hardwarewrite new state into hardware ----> ...signal hw_done switch to new state on next... v/hblankwait for buffers to show up ...... send completion irq irq handler signals flip_donecleanup old bufferssignal cleanup_donewait for flip_done <----clean up atomic state
The important bit to know is thatcleanup_done is the terminal event, but theordering betweenflip_done andhw_done is entirely up to the specific driverand modeset state change.
For an implementation of how to use this look atdrm_atomic_helper_setup_commit() from the atomic helper library.
See alsodrm_crtc_commit_wait().
- structdrm_private_state_funcs¶
atomic state functions for private objects
Definition:
struct drm_private_state_funcs { struct drm_private_state *(*atomic_create_state)(struct drm_private_obj *obj); struct drm_private_state *(*atomic_duplicate_state)(struct drm_private_obj *obj); void (*atomic_destroy_state)(struct drm_private_obj *obj, struct drm_private_state *state); void (*atomic_print_state)(struct drm_printer *p, const struct drm_private_state *state);};Members
atomic_create_stateAllocates a pristine, initialized, state for the privateobject and returns it.
RETURNS:
A new, pristine, private state instance or an error pointeron failure.
atomic_duplicate_stateDuplicate the current state of the private object and return it. Itis an error to call this before obj->state has been initialized.
RETURNS:
Duplicated atomic state or NULL when obj->state is notinitialized or allocation failed.
atomic_destroy_stateFrees the private object state created withatomic_duplicate_state.
atomic_print_stateIf driver subclasses
structdrm_private_state, it should implementthis optional hook for printing additional driver specific state.Do not call this directly, use
drm_atomic_private_obj_print_state()instead.
Description
These hooks are used by atomic helpers to create, swap and destroy states ofprivate objects. The structure itself is used as a vtable to identify theassociated private object type. Each private object type that needs to beadded to the atomic states is expected to have an implementation of thesehooks and pass a pointer to its drm_private_state_funcsstructtodrm_atomic_get_private_obj_state().
- structdrm_private_obj¶
base struct for driver private atomic object
Definition:
struct drm_private_obj { struct drm_device *dev; struct list_head head; struct drm_modeset_lock lock; struct drm_private_state *state; const struct drm_private_state_funcs *funcs;};Members
devparent DRM device
headList entry used to attach a private object to a
drm_device(queued todrm_mode_config.privobj_list).lockModeset lock to protect the state object.
stateCurrent atomic state for this driver private object.
funcsFunctions to manipulate the state of this driver private object, see
drm_private_state_funcs.
Description
A driver private object is initialized by callingdrm_atomic_private_obj_init() and cleaned up by callingdrm_atomic_private_obj_fini().
Currently only tracks the state update functions and the opaque driverprivate state itself, but in the future might also track whichdrm_modeset_lock is required to duplicate and update this object’s state.
All private objects must be initialized before the DRM device they areattached to is registered to the DRM subsystem (call todrm_dev_register())and should stay around until this DRM device is unregistered (call todrm_dev_unregister()). In other words, private objects lifetime is tiedto the DRM device lifetime. This implies that:
- 1/ all calls to drm_atomic_private_obj_init() must be done before calling
- 2/ all calls to drm_atomic_private_obj_fini() must be done after calling
If that private object is used to store a state shared by multipleCRTCs, proper care must be taken to ensure that non-blocking commits areproperly ordered to avoid a use-after-free issue.
Indeed, assuming a sequence of two non-blockingdrm_atomic_commit on twodifferentdrm_crtc using differentdrm_plane anddrm_connector, so with noresources shared, there’s no guarantee on which commit is going to happenfirst. However, the seconddrm_atomic_commit will consider the firstdrm_private_obj its old state, and will be in charge of freeing it wheneverthe seconddrm_atomic_commit is done.
If the firstdrm_atomic_commit happens after it, it will consider itsdrm_private_obj the new state and will be likely to access it, resulting inan access to a freed memory region. Drivers should store (and get a referenceto) thedrm_crtc_commit structure in our private state indrm_mode_config_helper_funcs.atomic_commit_setup, and then wait for thatcommit to complete as the first step ofdrm_mode_config_helper_funcs.atomic_commit_tail, similar todrm_atomic_helper_wait_for_dependencies().
- drm_for_each_privobj¶
drm_for_each_privobj(privobj,dev)
private object iterator
Parameters
privobjpointer to the current private object. Updated after eachiteration
devthe DRM device we want get private objects from
Description
Allows one to iterate over all private objects attached todev
- structdrm_private_state¶
base struct for driver private object state
Definition:
struct drm_private_state { struct drm_atomic_state *state; struct drm_private_obj *obj;};Members
statebackpointer to global drm_atomic_state
objbackpointer to the private object
Description
Currently only contains a backpointer to the overall atomic update,and the relevant private object but in the future also might holdsynchronization information similar to e.g.drm_crtc.commit.
- structdrm_atomic_state¶
Atomic commit structure
Definition:
struct drm_atomic_state { struct kref ref; struct drm_device *dev; bool allow_modeset : 1; bool legacy_cursor_update : 1; bool async_update : 1; bool duplicated : 1; bool checked : 1; bool plane_color_pipeline : 1; struct __drm_colorops_state *colorops; struct __drm_planes_state *planes; struct __drm_crtcs_state *crtcs; int num_connector; struct __drm_connnectors_state *connectors; int num_private_objs; struct __drm_private_objs_state *private_objs; struct drm_modeset_acquire_ctx *acquire_ctx; struct drm_crtc_commit *fake_commit; struct work_struct commit_work;};Members
refCount of all references to this update (will not be freed until zero).
devParent DRM Device.
allow_modesetAllow full modeset. This is used by the ATOMIC IOCTL handler toimplement the DRM_MODE_ATOMIC_ALLOW_MODESET flag. Drivers shouldgenerally not consult this flag, but instead look at the output of
drm_atomic_crtc_needs_modeset(). The detailed rules are:Drivers must not consultallow_modeset in the atomic commit path.Use
drm_atomic_crtc_needs_modeset()instead.Drivers must consultallow_modeset before adding unrelated
structdrm_crtc_stateto this commit by callingdrm_atomic_get_crtc_state(). See also the warning in thedocumentation for that function.Drivers must never change this flag, it is under the exclusivecontrol of userspace.
Drivers may consultallow_modeset in the atomic check path, ifthey have the choice between an optimal hardware configurationwhich requires a modeset, and a less optimal configuration whichcan be committed without a modeset. An example would be suboptimalscanout FIFO allocation resulting in increased idle powerconsumption. This allows userspace to avoid flickering and delaysfor the normal composition loop at reasonable cost.
legacy_cursor_updateHint to enforce legacy cursor IOCTL semantics.
WARNING: This is thoroughly broken and pretty much impossible toimplement correctly. Drivers must ignore this and should insteadimplement
drm_plane_helper_funcs.atomic_async_checkanddrm_plane_helper_funcs.atomic_async_commithooks. New users of thisflag are not allowed.async_updatehint for asynchronous plane update
duplicatedIndicates whether or not this atomic state was duplicated using
drm_atomic_helper_duplicate_state(). Drivers and atomic helpersshould use this to fixup normal inconsistencies in duplicatedstates.checkedIndicates the state has been checked and thus must no longerbe mutated. For internal use only, do not consult from drivers.
plane_color_pipelineIndicates whether this atomic state originated with a client thatset the DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE.
Drivers and helper functions should use this to ignore legacyproperties that are incompatible with the drm_plane COLOR_PIPELINEbehavior, such as:
COLOR_RANGE
COLOR_ENCODING
or any other driver-specific properties that might affect pixelvalues.
coloropsPointer to array ofdrm_colorop anddrm_colorop_state part of thisupdate.
planesPointer to array ofdrm_plane anddrm_plane_state part of thisupdate.
crtcsPointer to array ofdrm_crtc anddrm_crtc_state part of thisupdate.
num_connectorsize of theconnectors array
connectorsPointer to array ofdrm_connector anddrm_connector_state part ofthis update.
num_private_objssize of theprivate_objs array
private_objsPointer to array ofdrm_private_obj anddrm_private_obj_state partof this update.
acquire_ctxacquire context for this atomic modeset state update
fake_commitUsed for signaling unbound planes/connectors.When a connector or plane is not bound to any CRTC, it’s still importantto preserve linearity to prevent the atomic states from being freed too early.
This commit (if set) is not bound to any CRTC, but will be completed when
drm_atomic_helper_commit_hw_done()is called.commit_workWork item which can be used by the driver or helpers to execute thecommit without blocking.
Description
This structure is the kernel counterpart ofdrm_mode_atomic and representsan atomic commit that transitions from an old to a new display state. Itcontains all the objects affected by the atomic commit and both the newstate structures and pointers to the old state structures forthese.
States are added to an atomic update by callingdrm_atomic_get_crtc_state(),drm_atomic_get_plane_state(),drm_atomic_get_connector_state(), or forprivate state structures,drm_atomic_get_private_obj_state().
NOTE
structdrm_atomic_state first started as a single collection ofentities state pointers (drm_plane_state, drm_crtc_state, etc.).
At atomic_check time, you could get the state about to be committedfrom drm_atomic_state, and the one currently running from theentities state pointer (drm_crtc.state, for example). After the calltodrm_atomic_helper_swap_state(), the entities state pointer wouldcontain the state previously checked, and the drm_atomic_statestructure the old state.
Over time, and in order to avoid confusion, drm_atomic_state hasgrown to have both the old state (ie, the state we replace) and thenew state (ie, the state we want to apply). Those names are stableduring the commit process, which makes it easier to reason about.
You can still find some traces of that evolution through some hooksor callbacks taking a drm_atomic_state parameter called names like“old_state”. This doesn’t necessarily mean that the previousdrm_atomic_state is passed, but rather that this used to be the statecollection we were replacing afterdrm_atomic_helper_swap_state(),but the variable name was never updated.
Some atomic operations implementations followed a similar process. Wefirst started to pass the entity state only. However, it was prettycumbersome for drivers, and especially CRTCs, to retrieve the statesof other components. Thus, we switched to passing the wholedrm_atomic_state as a parameter to those operations. Similarly, thetransition isn’t complete yet, and one might still find atomicoperations taking a drm_atomic_state pointer, or a component statepointer. The former is the preferred form.
- structdrm_crtc_commit*drm_crtc_commit_get(structdrm_crtc_commit*commit)¶
acquire a reference to the CRTC commit
Parameters
structdrm_crtc_commit*commitCRTC commit
Description
Increases the reference ofcommit.
Return
The pointer tocommit, with reference increased.
- voiddrm_crtc_commit_put(structdrm_crtc_commit*commit)¶
release a reference to the CRTC commmit
Parameters
structdrm_crtc_commit*commitCRTC commit
Description
This releases a reference tocommit which is freed after removing thefinal reference. No locking required and callable from any context.
- structdrm_atomic_state*drm_atomic_state_get(structdrm_atomic_state*state)¶
acquire a reference to the atomic state
Parameters
structdrm_atomic_state*stateThe atomic state
Description
Returns a new reference to thestate
- voiddrm_atomic_state_put(structdrm_atomic_state*state)¶
release a reference to the atomic state
Parameters
structdrm_atomic_state*stateThe atomic state
Description
This releases a reference tostate which is freed after removing thefinal reference. No locking required and callable from any context.
- structdrm_crtc_state*drm_atomic_get_old_crtc_state(conststructdrm_atomic_state*state,structdrm_crtc*crtc)¶
get old CRTC state, if it exists
Parameters
conststructdrm_atomic_state*stateglobal atomic state object
structdrm_crtc*crtcCRTC to grab
Description
This function returns the old CRTC state for the given CRTC, orNULL if the CRTC is not part of the global atomic state.
- structdrm_crtc_state*drm_atomic_get_new_crtc_state(conststructdrm_atomic_state*state,structdrm_crtc*crtc)¶
get new CRTC state, if it exists
Parameters
conststructdrm_atomic_state*stateglobal atomic state object
structdrm_crtc*crtcCRTC to grab
Description
This function returns the new CRTC state for the given CRTC, orNULL if the CRTC is not part of the global atomic state.
- structdrm_plane_state*drm_atomic_get_old_plane_state(conststructdrm_atomic_state*state,structdrm_plane*plane)¶
get plane state, if it exists
Parameters
conststructdrm_atomic_state*stateglobal atomic state object
structdrm_plane*planeplane to grab
Description
This function returns the old plane state for the given plane, orNULL if the plane is not part of the global atomic state.
- structdrm_plane_state*drm_atomic_get_new_plane_state(conststructdrm_atomic_state*state,structdrm_plane*plane)¶
get plane state, if it exists
Parameters
conststructdrm_atomic_state*stateglobal atomic state object
structdrm_plane*planeplane to grab
Description
This function returns the new plane state for the given plane, orNULL if the plane is not part of the global atomic state.
- structdrm_connector_state*drm_atomic_get_old_connector_state(conststructdrm_atomic_state*state,structdrm_connector*connector)¶
get connector state, if it exists
Parameters
conststructdrm_atomic_state*stateglobal atomic state object
structdrm_connector*connectorconnector to grab
Description
This function returns the old connector state for the given connector,or NULL if the connector is not part of the global atomic state.
- structdrm_connector_state*drm_atomic_get_new_connector_state(conststructdrm_atomic_state*state,structdrm_connector*connector)¶
get connector state, if it exists
Parameters
conststructdrm_atomic_state*stateglobal atomic state object
structdrm_connector*connectorconnector to grab
Description
This function returns the new connector state for the given connector,or NULL if the connector is not part of the global atomic state.
- conststructdrm_plane_state*__drm_atomic_get_current_plane_state(conststructdrm_atomic_state*state,structdrm_plane*plane)¶
get current plane state
Parameters
conststructdrm_atomic_state*stateglobal atomic state object
structdrm_plane*planeplane to grab
Description
This function returns the plane state for the given plane, either thenew plane state fromstate, or if the plane isn’t part of the atomicstate update, fromplane. This is useful in atomic check callbacks,when drivers need to peek at, but not change, state of other planes,since it avoids threading an error code back up the call chain.
WARNING:
Note that this function is in general unsafe since it doesn’t check for therequired locking for access state structures. Drivers must ensure that it issafe to access the returned state structure through other means. One commonexample is when planes are fixed to a single CRTC, and the driver knows thatthe CRTC lock is held already. In that case holding the CRTC lock gives aread-lock on all planes connected to that CRTC. But if planes can bereassigned things get more tricky. In that case it’s better to usedrm_atomic_get_plane_state and wire up full error handling.
Read-only pointer to the current plane state.
- for_each_oldnew_connector_in_state¶
for_each_oldnew_connector_in_state(__state,connector,old_connector_state,new_connector_state,__i)
iterate over all connectors in an atomic update
Parameters
__statestructdrm_atomic_statepointerconnectorstructdrm_connectoriteration cursorold_connector_statestructdrm_connector_stateiteration cursor for theold statenew_connector_statestructdrm_connector_stateiteration cursor for thenew state__iint iteration cursor, for macro-internal use
Description
This iterates over all connectors in an atomic update, tracking both old andnew state. This is useful in places where the state delta needs to beconsidered, for example in atomic check functions.
- for_each_old_connector_in_state¶
for_each_old_connector_in_state(__state,connector,old_connector_state,__i)
iterate over all connectors in an atomic update
Parameters
__statestructdrm_atomic_statepointerconnectorstructdrm_connectoriteration cursorold_connector_statestructdrm_connector_stateiteration cursor for theold state__iint iteration cursor, for macro-internal use
Description
This iterates over all connectors in an atomic update, tracking only the oldstate. This is useful in disable functions, where we need the old state thehardware is still in.
- for_each_new_connector_in_state¶
for_each_new_connector_in_state(__state,connector,new_connector_state,__i)
iterate over all connectors in an atomic update
Parameters
__statestructdrm_atomic_statepointerconnectorstructdrm_connectoriteration cursornew_connector_statestructdrm_connector_stateiteration cursor for thenew state__iint iteration cursor, for macro-internal use
Description
This iterates over all connectors in an atomic update, tracking only the newstate. This is useful in enable functions, where we need the new state thehardware should be in when the atomic commit operation has completed.
- for_each_oldnew_crtc_in_state¶
for_each_oldnew_crtc_in_state(__state,crtc,old_crtc_state,new_crtc_state,__i)
iterate over all CRTCs in an atomic update
Parameters
__statestructdrm_atomic_statepointercrtcstructdrm_crtciteration cursorold_crtc_statestructdrm_crtc_stateiteration cursor for the old statenew_crtc_statestructdrm_crtc_stateiteration cursor for the new state__iint iteration cursor, for macro-internal use
Description
This iterates over all CRTCs in an atomic update, tracking both old andnew state. This is useful in places where the state delta needs to beconsidered, for example in atomic check functions.
- for_each_old_crtc_in_state¶
for_each_old_crtc_in_state(__state,crtc,old_crtc_state,__i)
iterate over all CRTCs in an atomic update
Parameters
__statestructdrm_atomic_statepointercrtcstructdrm_crtciteration cursorold_crtc_statestructdrm_crtc_stateiteration cursor for the old state__iint iteration cursor, for macro-internal use
Description
This iterates over all CRTCs in an atomic update, tracking only the oldstate. This is useful in disable functions, where we need the old state thehardware is still in.
- for_each_new_crtc_in_state¶
for_each_new_crtc_in_state(__state,crtc,new_crtc_state,__i)
iterate over all CRTCs in an atomic update
Parameters
__statestructdrm_atomic_statepointercrtcstructdrm_crtciteration cursornew_crtc_statestructdrm_crtc_stateiteration cursor for the new state__iint iteration cursor, for macro-internal use
Description
This iterates over all CRTCs in an atomic update, tracking only the newstate. This is useful in enable functions, where we need the new state thehardware should be in when the atomic commit operation has completed.
- for_each_oldnew_colorop_in_state¶
for_each_oldnew_colorop_in_state(__state,colorop,old_colorop_state,new_colorop_state,__i)
iterate over all colorops in an atomic update
Parameters
__statestructdrm_atomic_statepointercoloropstructdrm_coloropiteration cursorold_colorop_statestructdrm_colorop_stateiteration cursor for the old statenew_colorop_statestructdrm_colorop_stateiteration cursor for the new state__iint iteration cursor, for macro-internal use
Description
This iterates over all colorops in an atomic update, tracking both old andnew state. This is useful in places where the state delta needs to beconsidered, for example in atomic check functions.
- for_each_new_colorop_in_state¶
for_each_new_colorop_in_state(__state,colorop,new_colorop_state,__i)
iterate over all colorops in an atomic update
Parameters
__statestructdrm_atomic_statepointercoloropstructdrm_coloropiteration cursornew_colorop_statestructdrm_colorop_stateiteration cursor for the new state__iint iteration cursor, for macro-internal use
Description
This iterates over all colorops in an atomic update, tracking new state. This isuseful in places where the state delta needs to be considered, for example inatomic check functions.
- for_each_oldnew_plane_in_state¶
for_each_oldnew_plane_in_state(__state,plane,old_plane_state,new_plane_state,__i)
iterate over all planes in an atomic update
Parameters
__statestructdrm_atomic_statepointerplanestructdrm_planeiteration cursorold_plane_statestructdrm_plane_stateiteration cursor for the old statenew_plane_statestructdrm_plane_stateiteration cursor for the new state__iint iteration cursor, for macro-internal use
Description
This iterates over all planes in an atomic update, tracking both old andnew state. This is useful in places where the state delta needs to beconsidered, for example in atomic check functions.
- for_each_oldnew_plane_in_state_reverse¶
for_each_oldnew_plane_in_state_reverse(__state,plane,old_plane_state,new_plane_state,__i)
iterate over all planes in an atomic update in reverse order
Parameters
__statestructdrm_atomic_statepointerplanestructdrm_planeiteration cursorold_plane_statestructdrm_plane_stateiteration cursor for the old statenew_plane_statestructdrm_plane_stateiteration cursor for the new state__iint iteration cursor, for macro-internal use
Description
This iterates over all planes in an atomic update in reverse order,tracking both old and new state. This is useful in places where thestate delta needs to be considered, for example in atomic check functions.
- for_each_new_plane_in_state_reverse¶
for_each_new_plane_in_state_reverse(__state,plane,new_plane_state,__i)
other than only tracking new state, it’s the same as for_each_oldnew_plane_in_state_reverse
Parameters
__statestructdrm_atomic_statepointerplanestructdrm_planeiteration cursornew_plane_statestructdrm_plane_stateiteration cursor for the new state__iint iteration cursor, for macro-internal use
- for_each_old_plane_in_state¶
for_each_old_plane_in_state(__state,plane,old_plane_state,__i)
iterate over all planes in an atomic update
Parameters
__statestructdrm_atomic_statepointerplanestructdrm_planeiteration cursorold_plane_statestructdrm_plane_stateiteration cursor for the old state__iint iteration cursor, for macro-internal use
Description
This iterates over all planes in an atomic update, tracking only the oldstate. This is useful in disable functions, where we need the old state thehardware is still in.
- for_each_new_plane_in_state¶
for_each_new_plane_in_state(__state,plane,new_plane_state,__i)
iterate over all planes in an atomic update
Parameters
__statestructdrm_atomic_statepointerplanestructdrm_planeiteration cursornew_plane_statestructdrm_plane_stateiteration cursor for the new state__iint iteration cursor, for macro-internal use
Description
This iterates over all planes in an atomic update, tracking only the newstate. This is useful in enable functions, where we need the new state thehardware should be in when the atomic commit operation has completed.
- for_each_oldnew_private_obj_in_state¶
for_each_oldnew_private_obj_in_state(__state,obj,old_obj_state,new_obj_state,__i)
iterate over all private objects in an atomic update
Parameters
__statestructdrm_atomic_statepointerobjstructdrm_private_objiteration cursorold_obj_statestructdrm_private_stateiteration cursor for the old statenew_obj_statestructdrm_private_stateiteration cursor for the new state__iint iteration cursor, for macro-internal use
Description
This iterates over all private objects in an atomic update, tracking bothold and new state. This is useful in places where the state delta needsto be considered, for example in atomic check functions.
- for_each_old_private_obj_in_state¶
for_each_old_private_obj_in_state(__state,obj,old_obj_state,__i)
iterate over all private objects in an atomic update
Parameters
__statestructdrm_atomic_statepointerobjstructdrm_private_objiteration cursorold_obj_statestructdrm_private_stateiteration cursor for the old state__iint iteration cursor, for macro-internal use
Description
This iterates over all private objects in an atomic update, tracking onlythe old state. This is useful in disable functions, where we need the oldstate the hardware is still in.
- for_each_new_private_obj_in_state¶
for_each_new_private_obj_in_state(__state,obj,new_obj_state,__i)
iterate over all private objects in an atomic update
Parameters
__statestructdrm_atomic_statepointerobjstructdrm_private_objiteration cursornew_obj_statestructdrm_private_stateiteration cursor for the new state__iint iteration cursor, for macro-internal use
Description
This iterates over all private objects in an atomic update, tracking onlythe new state. This is useful in enable functions, where we need the new state thehardware should be in when the atomic commit operation has completed.
- booldrm_atomic_crtc_needs_modeset(conststructdrm_crtc_state*state)¶
compute combined modeset need
Parameters
conststructdrm_crtc_state*statedrm_crtc_statefor the CRTC
Description
To give drivers flexibilitystructdrm_crtc_state has 3 booleans to trackwhether the state CRTC changed enough to need a full modeset cycle:mode_changed, active_changed and connectors_changed. This helper simplycombines these three to compute the overall need for a modeset forstate.
The atomic helper code sets these booleans, but drivers can and shouldchange them appropriately to accurately represent whether a modeset isreally needed. In general, drivers should avoid full modesets wheneverpossible.
For example if the CRTC mode has changed, and the hardware is able to enactthe requested mode change without going through a full modeset, the drivershould clear mode_changed in itsdrm_mode_config_funcs.atomic_checkimplementation.
- booldrm_atomic_crtc_effectively_active(conststructdrm_crtc_state*state)¶
compute whether CRTC is actually active
Parameters
conststructdrm_crtc_state*statedrm_crtc_statefor the CRTC
Description
When in self refresh mode, the crtc_state->active value will be false, sincethe CRTC is off. However in some cases we’re interested in whether the CRTCis active, or effectively active (ie: it’s connected to an active display).In these cases, use this function instead of just checking active.
- structdrm_bus_cfg¶
bus configuration
Definition:
struct drm_bus_cfg { u32 format; u32 flags;};Members
formatformat used on this bus (one of the MEDIA_BUS_FMT_* format)
This field should not be directly modified by drivers(
drm_atomic_bridge_chain_select_bus_fmts()takes care of the busformat negotiation).flagsDRM_BUS_* flags used on this bus
Description
This structure stores the configuration of a physical bus between twocomponents in an output pipeline, usually between two bridges, an encoderand a bridge, or a bridge and a connector.
The bus configuration is stored indrm_bridge_state separately for theinput and output buses, as seen from the point of view of each bridge. Thebus configuration of a bridge output is usually identical to theconfiguration of the next bridge’s input, but may differ if the signals aremodified between the two bridges, for instance by an inverter on the board.The input and output configurations of a bridge may differ if the bridgemodifies the signals internally, for instance by performing formatconversion, or modifying signals polarities.
- structdrm_bridge_state¶
Atomic bridge state object
Definition:
struct drm_bridge_state { struct drm_private_state base; struct drm_bridge *bridge; struct drm_bus_cfg input_bus_cfg; struct drm_bus_cfg output_bus_cfg;};Members
baseinherit from
drm_private_statebridgethe bridge this state refers to
input_bus_cfginput bus configuration
output_bus_cfgoutput bus configuration
- intdrm_crtc_commit_wait(structdrm_crtc_commit*commit)¶
Waits for a commit to complete
Parameters
structdrm_crtc_commit*commitdrm_crtc_committo wait for
Description
Waits for a givendrm_crtc_commit to be programmed into thehardware and flipped to.
Return
0 on success, a negative error code otherwise.
- voiddrm_atomic_state_default_release(structdrm_atomic_state*state)¶
release memory initialized by drm_atomic_state_init
Parameters
structdrm_atomic_state*stateatomic state
Description
Free all the memory allocated by drm_atomic_state_init.This should only be used by drivers which are still subclassingdrm_atomic_state and haven’t switched todrm_private_state yet.
- intdrm_atomic_state_init(structdrm_device*dev,structdrm_atomic_state*state)¶
init new atomic state
Parameters
structdrm_device*devDRM device
structdrm_atomic_state*stateatomic state
Description
Default implementation for filling in a new atomic state.This should only be used by drivers which are still subclassingdrm_atomic_state and haven’t switched todrm_private_state yet.
- structdrm_atomic_state*drm_atomic_state_alloc(structdrm_device*dev)¶
allocate atomic state
Parameters
structdrm_device*devDRM device
Description
This allocates an empty atomic state to track updates.
- voiddrm_atomic_state_default_clear(structdrm_atomic_state*state)¶
clear base atomic state
Parameters
structdrm_atomic_state*stateatomic state
Description
Default implementation for clearing atomic state.This should only be used by drivers which are still subclassingdrm_atomic_state and haven’t switched todrm_private_state yet.
- voiddrm_atomic_state_clear(structdrm_atomic_state*state)¶
clear state object
Parameters
structdrm_atomic_state*stateatomic state
Description
When the w/w mutex algorithm detects a deadlock we need to back off and dropall locks. So someone else could sneak in and change the current modesetconfiguration. Which means that all the state assembled instate is nolonger an atomic update to the current state, but to some arbitrary earlierstate. Which could break assumptions the driver’sdrm_mode_config_funcs.atomic_check likely relies on.
Hence we must clear all cached state and completely start over, using thisfunction.
- void__drm_atomic_state_free(structkref*ref)¶
free all memory for an atomic state
Parameters
structkref*refThis atomic state to deallocate
Description
This frees all memory associated with an atomic state, including all theper-object state for planes, CRTCs and connectors.
- structdrm_crtc_state*drm_atomic_get_crtc_state(structdrm_atomic_state*state,structdrm_crtc*crtc)¶
get CRTC state
Parameters
structdrm_atomic_state*stateglobal atomic state object
structdrm_crtc*crtcCRTC to get state object for
Description
This function returns the CRTC state for the given CRTC, allocating it ifneeded. It will also grab the relevant CRTC lock to make sure that the stateis consistent.
WARNING: Drivers may only add new CRTC states to astate ifdrm_atomic_state.allow_modeset is set, or if it’s a driver-internal commitnot created by userspace through an IOCTL call.
Return
Either the allocated state or the error code encoded into the pointer. Whenthe error is EDEADLK then the w/w mutex code has detected a deadlock and theentire atomic sequence must be restarted. All other errors are fatal.
- structdrm_plane_state*drm_atomic_get_plane_state(structdrm_atomic_state*state,structdrm_plane*plane)¶
get plane state
Parameters
structdrm_atomic_state*stateglobal atomic state object
structdrm_plane*planeplane to get state object for
Description
This function returns the plane state for the given plane, allocating it ifneeded. It will also grab the relevant plane lock to make sure that the stateis consistent.
Return
Either the allocated state or the error code encoded into the pointer. Whenthe error is EDEADLK then the w/w mutex code has detected a deadlock and theentire atomic sequence must be restarted. All other errors are fatal.
- structdrm_colorop_state*drm_atomic_get_colorop_state(structdrm_atomic_state*state,structdrm_colorop*colorop)¶
get colorop state
Parameters
structdrm_atomic_state*stateglobal atomic state object
structdrm_colorop*coloropcolorop to get state object for
Description
This function returns the colorop state for the given colorop, allocating itif needed. It will also grab the relevant plane lock to make sure that thestate is consistent.
Either the allocated state or the error code encoded into the pointer. Whenthe error is EDEADLK then the w/w mutex code has detected a deadlock and theentire atomic sequence must be restarted. All other errors are fatal.
- structdrm_colorop_state*drm_atomic_get_old_colorop_state(structdrm_atomic_state*state,structdrm_colorop*colorop)¶
get colorop state, if it exists
Parameters
structdrm_atomic_state*stateglobal atomic state object
structdrm_colorop*coloropcolorop to grab
Description
This function returns the old colorop state for the given colorop, orNULL if the colorop is not part of the global atomic state.
- structdrm_colorop_state*drm_atomic_get_new_colorop_state(structdrm_atomic_state*state,structdrm_colorop*colorop)¶
get colorop state, if it exists
Parameters
structdrm_atomic_state*stateglobal atomic state object
structdrm_colorop*coloropcolorop to grab
Description
This function returns the new colorop state for the given colorop, orNULL if the colorop is not part of the global atomic state.
- intdrm_atomic_private_obj_init(structdrm_device*dev,structdrm_private_obj*obj,structdrm_private_state*state,conststructdrm_private_state_funcs*funcs)¶
initialize private object
Parameters
structdrm_device*devDRM device this object will be attached to
structdrm_private_obj*objprivate object
structdrm_private_state*stateinitial private object state
conststructdrm_private_state_funcs*funcspointer to the
structoffunction pointers that identify the objecttype
Description
Initialize the private object, which can be embedded into anydriver private object that needs its own atomic state.
Return
Zero on success, error code on failure
- voiddrm_atomic_private_obj_fini(structdrm_private_obj*obj)¶
finalize private object
Parameters
structdrm_private_obj*objprivate object
Description
Finalize the private object.
- structdrm_private_state*drm_atomic_get_private_obj_state(structdrm_atomic_state*state,structdrm_private_obj*obj)¶
get private object state
Parameters
structdrm_atomic_state*stateglobal atomic state
structdrm_private_obj*objprivate object to get the state for
Description
This function returns the private object state for the given private object,allocating the state if needed. It will also grab the relevant privateobject lock to make sure that the state is consistent.
Return
Either the allocated state or the error code encoded into a pointer.
- structdrm_private_state*drm_atomic_get_old_private_obj_state(conststructdrm_atomic_state*state,structdrm_private_obj*obj)¶
Parameters
conststructdrm_atomic_state*stateglobal atomic state object
structdrm_private_obj*objprivate_obj to grab
Description
This function returns the old private object state for the given private_obj,or NULL if the private_obj is not part of the global atomic state.
- structdrm_private_state*drm_atomic_get_new_private_obj_state(conststructdrm_atomic_state*state,structdrm_private_obj*obj)¶
Parameters
conststructdrm_atomic_state*stateglobal atomic state object
structdrm_private_obj*objprivate_obj to grab
Description
This function returns the new private object state for the given private_obj,or NULL if the private_obj is not part of the global atomic state.
- structdrm_connector*drm_atomic_get_old_connector_for_encoder(conststructdrm_atomic_state*state,structdrm_encoder*encoder)¶
Get old connector for an encoder
Parameters
conststructdrm_atomic_state*stateAtomic state
structdrm_encoder*encoderThe encoder to fetch the connector state for
Description
This function finds and returns the connector that was connected toencoderas specified by thestate.
If there is no connector instate which previously hadencoder connected toit, this function will return NULL. While this may seem like an invalid usecase, it is sometimes useful to differentiate commits which had no priorconnectors attached toencoder vs ones that did (and to inspect theirstate). This is especially true in enable hooks because the pipeline haschanged.
If you don’t have access to the atomic state, seedrm_atomic_get_connector_for_encoder().
Return
The old connector connected toencoder, or NULL if the encoder isnot connected.
- structdrm_connector*drm_atomic_get_new_connector_for_encoder(conststructdrm_atomic_state*state,structdrm_encoder*encoder)¶
Get new connector for an encoder
Parameters
conststructdrm_atomic_state*stateAtomic state
structdrm_encoder*encoderThe encoder to fetch the connector state for
Description
This function finds and returns the connector that will be connected toencoder as specified by thestate.
If there is no connector instate which will haveencoder connected to it,this function will return NULL. While this may seem like an invalid use case,it is sometimes useful to differentiate commits which have no connectorsattached toencoder vs ones that do (and to inspect their state). This isespecially true in disable hooks because the pipeline will change.
If you don’t have access to the atomic state, seedrm_atomic_get_connector_for_encoder().
Return
The new connector connected toencoder, or NULL if the encoder isnot connected.
- structdrm_connector*drm_atomic_get_connector_for_encoder(conststructdrm_encoder*encoder,structdrm_modeset_acquire_ctx*ctx)¶
Get connector currently assigned to an encoder
Parameters
conststructdrm_encoder*encoderThe encoder to find the connector of
structdrm_modeset_acquire_ctx*ctxModeset locking context
Description
This function finds and returns the connector currently assigned toanencoder.
It is similar to thedrm_atomic_get_old_connector_for_encoder() anddrm_atomic_get_new_connector_for_encoder() helpers, but doesn’trequire access to the atomic state. If you have access to it, preferusing these. This helper is typically useful in situations where youdon’t have access to the atomic state, like detect, link repair,threaded interrupt handlers, or hooks from other frameworks (ALSA,CEC, etc.).
Return
The connector connected toencoder, or an error pointer otherwise.When the error is EDEADLK, a deadlock has been detected and thesequence must be restarted.
- structdrm_crtc*drm_atomic_get_old_crtc_for_encoder(structdrm_atomic_state*state,structdrm_encoder*encoder)¶
Get old crtc for an encoder
Parameters
structdrm_atomic_state*stateAtomic state
structdrm_encoder*encoderThe encoder to fetch the crtc state for
Description
This function finds and returns the crtc that was connected toencoderas specified by thestate.
Return
The old crtc connected toencoder, or NULL if the encoder isnot connected.
- structdrm_crtc*drm_atomic_get_new_crtc_for_encoder(structdrm_atomic_state*state,structdrm_encoder*encoder)¶
Get new crtc for an encoder
Parameters
structdrm_atomic_state*stateAtomic state
structdrm_encoder*encoderThe encoder to fetch the crtc state for
Description
This function finds and returns the crtc that will be connected toencoderas specified by thestate.
Return
The new crtc connected toencoder, or NULL if the encoder isnot connected.
- structdrm_connector_state*drm_atomic_get_connector_state(structdrm_atomic_state*state,structdrm_connector*connector)¶
get connector state
Parameters
structdrm_atomic_state*stateglobal atomic state object
structdrm_connector*connectorconnector to get state object for
Description
This function returns the connector state for the given connector,allocating it if needed. It will also grab the relevant connector lock tomake sure that the state is consistent.
Return
Either the allocated state or the error code encoded into the pointer. Whenthe error is EDEADLK then the w/w mutex code has detected a deadlock and theentire atomic sequence must be restarted. All other errors are fatal.
- structdrm_bridge_state*drm_atomic_get_bridge_state(structdrm_atomic_state*state,structdrm_bridge*bridge)¶
get bridge state
Parameters
structdrm_atomic_state*stateglobal atomic state object
structdrm_bridge*bridgebridge to get state object for
Description
This function returns the bridge state for the given bridge, allocating itif needed. It will also grab the relevant bridge lock to make sure that thestate is consistent.
Return
Either the allocated state or the error code encoded into the pointer. Whenthe error is EDEADLK then the w/w mutex code has detected a deadlock and theentire atomic sequence must be restarted.
- structdrm_bridge_state*drm_atomic_get_old_bridge_state(conststructdrm_atomic_state*state,structdrm_bridge*bridge)¶
get old bridge state, if it exists
Parameters
conststructdrm_atomic_state*stateglobal atomic state object
structdrm_bridge*bridgebridge to grab
Description
This function returns the old bridge state for the given bridge, or NULL ifthe bridge is not part of the global atomic state.
- structdrm_bridge_state*drm_atomic_get_new_bridge_state(conststructdrm_atomic_state*state,structdrm_bridge*bridge)¶
get new bridge state, if it exists
Parameters
conststructdrm_atomic_state*stateglobal atomic state object
structdrm_bridge*bridgebridge to grab
Description
This function returns the new bridge state for the given bridge, or NULL ifthe bridge is not part of the global atomic state.
- intdrm_atomic_add_encoder_bridges(structdrm_atomic_state*state,structdrm_encoder*encoder)¶
add bridges attached to an encoder
Parameters
structdrm_atomic_state*stateatomic state
structdrm_encoder*encoderDRM encoder
Description
This function adds all bridges attached toencoder. This is needed to addbridge states tostate and make them available whendrm_bridge_funcs.atomic_check(),drm_bridge_funcs.atomic_pre_enable(),drm_bridge_funcs.atomic_enable(),drm_bridge_funcs.atomic_disable_post_disable() are called.
Return
0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLKthen the w/w mutex code has detected a deadlock and the entire atomicsequence must be restarted. All other errors are fatal.
- intdrm_atomic_add_affected_connectors(structdrm_atomic_state*state,structdrm_crtc*crtc)¶
add connectors for CRTC
Parameters
structdrm_atomic_state*stateatomic state
structdrm_crtc*crtcDRM CRTC
Description
This function walks the current configuration and adds all connectorscurrently usingcrtc to the atomic configurationstate. Note that thisfunction must acquire the connection mutex. This can potentially causeunneeded serialization if the update is just for the planes on one CRTC. Hencedrivers and helpers should only call this when really needed (e.g. when afull modeset needs to happen due to some change).
Return
0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLKthen the w/w mutex code has detected a deadlock and the entire atomicsequence must be restarted. All other errors are fatal.
- intdrm_atomic_add_affected_planes(structdrm_atomic_state*state,structdrm_crtc*crtc)¶
add planes for CRTC
Parameters
structdrm_atomic_state*stateatomic state
structdrm_crtc*crtcDRM CRTC
Description
This function walks the current configuration and adds all planescurrently used bycrtc to the atomic configurationstate. This is usefulwhen an atomic commit also needs to check all currently enabled plane oncrtc, e.g. when changing the mode. It’s also useful when re-enabling a CRTCto avoid special code to force-enable all planes.
Since acquiring a plane state will always also acquire the w/w mutex of thecurrent CRTC for that plane (if there is any) adding all the plane states fora CRTC will not reduce parallelism of atomic updates.
Return
0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLKthen the w/w mutex code has detected a deadlock and the entire atomicsequence must be restarted. All other errors are fatal.
- intdrm_atomic_add_affected_colorops(structdrm_atomic_state*state,structdrm_plane*plane)¶
add colorops for plane
Parameters
structdrm_atomic_state*stateatomic state
structdrm_plane*planeDRM plane
Description
This function walks the current configuration and adds all coloropscurrently used byplane to the atomic configurationstate. This is usefulwhen an atomic commit also needs to check all currently enabled colorop onplane, e.g. when changing the mode. It’s also useful when re-enabling a planeto avoid special code to force-enable all colorops.
Since acquiring a colorop state will always also acquire the w/w mutex of thecurrent plane for that colorop (if there is any) adding all the colorop states fora plane will not reduce parallelism of atomic updates.
Return
0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLKthen the w/w mutex code has detected a deadlock and the entire atomicsequence must be restarted. All other errors are fatal.
- intdrm_atomic_check_only(structdrm_atomic_state*state)¶
check whether a given config would work
Parameters
structdrm_atomic_state*stateatomic configuration to check
Description
Note that this function can return -EDEADLK if the driver needed to acquiremore locks but encountered a deadlock. The caller must then do the usual w/wbackoff dance and restart. All other errors are fatal.
Return
0 on success, negative error code on failure.
- intdrm_atomic_commit(structdrm_atomic_state*state)¶
commit configuration atomically
Parameters
structdrm_atomic_state*stateatomic configuration to check
Description
Note that this function can return -EDEADLK if the driver needed to acquiremore locks but encountered a deadlock. The caller must then do the usual w/wbackoff dance and restart. All other errors are fatal.
This function will take its own reference onstate.Callers should always release their reference withdrm_atomic_state_put().
Return
0 on success, negative error code on failure.
- intdrm_atomic_nonblocking_commit(structdrm_atomic_state*state)¶
atomic nonblocking commit
Parameters
structdrm_atomic_state*stateatomic configuration to check
Description
Note that this function can return -EDEADLK if the driver needed to acquiremore locks but encountered a deadlock. The caller must then do the usual w/wbackoff dance and restart. All other errors are fatal.
This function will take its own reference onstate.Callers should always release their reference withdrm_atomic_state_put().
Return
0 on success, negative error code on failure.
- voiddrm_atomic_print_new_state(conststructdrm_atomic_state*state,structdrm_printer*p)¶
prints drm atomic state
Parameters
conststructdrm_atomic_state*stateatomic configuration to check
structdrm_printer*pdrm printer
Description
This functions prints the drm atomic state snapshot using the drm printerwhich is passed to it. This snapshot can be used for debugging purposes.
Note that this function looks into the new state objects and hence its notsafe to be used after the call todrm_atomic_helper_commit_hw_done().
- voiddrm_state_dump(structdrm_device*dev,structdrm_printer*p)¶
dump entire device atomic state
Parameters
structdrm_device*devthe drm device
structdrm_printer*pwhere to print the state to
Description
Just for debugging. Drivers might want an option to dump stateto dmesg in case of error irq’s. (Hint, you probably want toratelimit this!)
The caller must wrap thisdrm_modeset_lock_all_ctx() anddrm_modeset_drop_locks(). If this is called from error irq handler, it shouldnot be enabled by default - if you are debugging errors you mightnot care that this is racey, but calling this without all modeset locks heldis inherently unsafe.
Atomic Mode Setting IOCTL and UAPI Functions¶
This file contains the marshalling and demarshalling glue for the atomic UAPIin all its forms: The monster ATOMIC IOCTL itself, code for GET_PROPERTY andSET_PROPERTY IOCTLs. Plus interface functions for compatibility helpers anddrivers which have special needs to construct their own atomic updates, e.g.for load detect or similar.
- intdrm_atomic_set_mode_for_crtc(structdrm_crtc_state*state,conststructdrm_display_mode*mode)¶
set mode for CRTC
Parameters
structdrm_crtc_state*statethe CRTC whose incoming state to update
conststructdrm_display_mode*modekernel-internal mode to use for the CRTC, or NULL to disable
Description
Set a mode (originating from the kernel) on the desired CRTC state and updatethe enable property.
Return
Zero on success, error code on failure. Cannot return -EDEADLK.
- intdrm_atomic_set_mode_prop_for_crtc(structdrm_crtc_state*state,structdrm_property_blob*blob)¶
set mode for CRTC
Parameters
structdrm_crtc_state*statethe CRTC whose incoming state to update
structdrm_property_blob*blobpointer to blob property to use for mode
Description
Set a mode (originating from a blob property) on the desired CRTC state.This function will take a reference on the blob property for the CRTC state,and release the reference held on the state’s existing mode property, if anywas set.
Return
Zero on success, error code on failure. Cannot return -EDEADLK.
- intdrm_atomic_set_crtc_for_plane(structdrm_plane_state*plane_state,structdrm_crtc*crtc)¶
set CRTC for plane
Parameters
structdrm_plane_state*plane_statethe plane whose incoming state to update
structdrm_crtc*crtcCRTC to use for the plane
Description
Changing the assigned CRTC for a plane requires us to grab the lock and statefor the new CRTC, as needed. This function takes care of all these detailsbesides updating the pointer in the state object itself.
Return
0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLKthen the w/w mutex code has detected a deadlock and the entire atomicsequence must be restarted. All other errors are fatal.
- voiddrm_atomic_set_fb_for_plane(structdrm_plane_state*plane_state,structdrm_framebuffer*fb)¶
set framebuffer for plane
Parameters
structdrm_plane_state*plane_stateatomic state object for the plane
structdrm_framebuffer*fbfb to use for the plane
Description
Changing the assigned framebuffer for a plane requires us to grab a referenceto the new fb and drop the reference to the old fb, if there is one. Thisfunction takes care of all these details besides updating the pointer in thestate object itself.
- voiddrm_atomic_set_colorop_for_plane(structdrm_plane_state*plane_state,structdrm_colorop*colorop)¶
set colorop for plane
Parameters
structdrm_plane_state*plane_stateatomic state object for the plane
structdrm_colorop*coloropcolorop to use for the plane
Description
Helper function to select the color pipeline on a plane by settingit to the first drm_colorop element of the pipeline.
- intdrm_atomic_set_crtc_for_connector(structdrm_connector_state*conn_state,structdrm_crtc*crtc)¶
set CRTC for connector
Parameters
structdrm_connector_state*conn_stateatomic state object for the connector
structdrm_crtc*crtcCRTC to use for the connector
Description
Changing the assigned CRTC for a connector requires us to grab the lock andstate for the new CRTC, as needed. This function takes care of all thesedetails besides updating the pointer in the state object itself.
Return
0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLKthen the w/w mutex code has detected a deadlock and the entire atomicsequence must be restarted. All other errors are fatal.
CRTC Abstraction¶
A CRTC represents the overall display pipeline. It receives pixel data fromdrm_plane and blends them together. Thedrm_display_mode is also attachedto the CRTC, specifying display timings. On the output side the data is fedto one or moredrm_encoder, which are then each connected to onedrm_connector.
To create a CRTC, a KMS driver allocates and zeroes an instance ofstructdrm_crtc (possibly as part of a larger structure) and registers itwith a call todrm_crtc_init_with_planes().
The CRTC is also the entry point for legacy modeset operations (seedrm_crtc_funcs.set_config), legacy plane operations (seedrm_crtc_funcs.page_flip anddrm_crtc_funcs.cursor_set2), and other legacyoperations likedrm_crtc_funcs.gamma_set. For atomic drivers all thesefeatures are controlled throughdrm_property anddrm_mode_config_funcs.atomic_check.
CRTC Functions Reference¶
- structdrm_crtc_state¶
mutable CRTC state
Definition:
struct drm_crtc_state { struct drm_crtc *crtc; bool enable; bool active; bool planes_changed : 1; bool mode_changed : 1; bool active_changed : 1; bool connectors_changed : 1; bool zpos_changed : 1; bool color_mgmt_changed : 1; bool no_vblank; u32 plane_mask; u32 connector_mask; u32 encoder_mask; struct drm_display_mode adjusted_mode; struct drm_display_mode mode; struct drm_property_blob *mode_blob; struct drm_property_blob *degamma_lut; struct drm_property_blob *ctm; struct drm_property_blob *gamma_lut; u32 target_vblank; bool async_flip; bool vrr_enabled; bool self_refresh_active; enum drm_scaling_filter scaling_filter; u8 sharpness_strength; struct drm_pending_vblank_event *event; struct drm_crtc_commit *commit; struct drm_atomic_state *state;};Members
crtcbackpointer to the CRTC
enableWhether the CRTC should be enabled, gates all other state.This controls reservations of shared resources. Actual hardware stateis controlled byactive.
activeWhether the CRTC is actively displaying (used for DPMS).Implies thatenable is set. The driver must not release any sharedresources ifactive is set to false butenable still true, becauseuserspace expects that a DPMS ON always succeeds.
Hence drivers must not consultactive in their various
drm_mode_config_funcs.atomic_checkcallback to reject an atomiccommit. They can consult it to aid in the computation of derivedhardware state, since even in the DPMS OFF state the display hardwareshould be as much powered down as when the CRTC is completelydisabled through settingenable to false.planes_changedPlanes on this crtc are updated. Used by the atomichelpers and drivers to steer the atomic commit control flow.
mode_changedmode orenable has been changed. Used by the atomichelpers and drivers to steer the atomic commit control flow. See also
drm_atomic_crtc_needs_modeset().Drivers are supposed to set this for any CRTC state changes thatrequire a full modeset. They can also reset it to false if e.g. amode change can be done without a full modeset by only changingscaler settings.
active_changedactive has been toggled. Used by the atomichelpers and drivers to steer the atomic commit control flow. See also
drm_atomic_crtc_needs_modeset().connectors_changedConnectors to this crtc have been updated,either in their state or routing. Used by the atomichelpers and drivers to steer the atomic commit control flow. See also
drm_atomic_crtc_needs_modeset().Drivers are supposed to set this as-needed from their own atomiccheck code, e.g. from
drm_encoder_helper_funcs.atomic_checkzpos_changedzpos values of planes on this crtc have been updated.Used by the atomic helpers and drivers to steer the atomic commitcontrol flow.
color_mgmt_changedColor management properties have changed(gamma_lut,degamma_lut orctm). Used by the atomic helpers anddrivers to steer the atomic commit control flow.
no_vblankReflects the ability of a CRTC to send VBLANK events. This stateusually depends on the pipeline configuration. If set to true, DRMatomic helpers will send out a fake VBLANK event during displayupdates after all hardware changes have been committed. This isimplemented in
drm_atomic_helper_fake_vblank().One usage is for drivers and/or hardware without support for VBLANKinterrupts. Such drivers typically do not initialize vblanking(i.e., call
drm_vblank_init()with the number of CRTCs). For CRTCswithout initialized vblanking, this field is set to true indrm_atomic_helper_check_modeset(), and a fake VBLANK event will besend out on each update of the display pipeline bydrm_atomic_helper_fake_vblank().Another usage is CRTCs feeding a writeback connector operating inoneshot mode. In this case the fake VBLANK event is only generatedwhen a job is queued to the writeback connector, and we want thecore to fake VBLANK events when this part of the pipeline hasn’tchanged but others had or when the CRTC and connectors are beingdisabled.
__drm_atomic_helper_crtc_duplicate_state()will not reset the valuefrom the current state, the CRTC driver is then responsible forupdating this field when needed.Note that the combination of
drm_crtc_state.event== NULL anddrm_crtc_state.no_blank== true is valid and usually used when thewriteback connector attached to the CRTC has a new job queued. Inthis case the driver will send the VBLANK event on its own when thewriteback job is complete.plane_maskBitmask of drm_plane_mask(plane) of planes attached tothis CRTC.
connector_maskBitmask of drm_connector_mask(connector) ofconnectors attached to this CRTC.
encoder_maskBitmask of drm_encoder_mask(encoder) of encodersattached to this CRTC.
adjusted_modeInternal display timings which can be used by the driver to handledifferences between the mode requested by userspace inmode and whatis actually programmed into the hardware.
For drivers using
drm_bridge, this stores hardware display timingsused between the CRTC and the first bridge. For other drivers, themeaning of the adjusted_mode field is purely driver implementationdefined information, and will usually be used to store the hardwaredisplay timings used between the CRTC and encoder blocks.modeDisplay timings requested by userspace. The driver should try tomatch the refresh rate as close as possible (but note that it’sundefined what exactly is close enough, e.g. some of the HDMI modesonly differ in less than 1% of the refresh rate). The active widthand height as observed by userspace for positioning planes must matchexactly.
For external connectors where the sink isn’t fixed (like with abuilt-in panel), this mode here should match the physical mode on thewire to the last details (i.e. including sync polarities andeverything).
mode_blobdrm_property_blobformode, for exposing the mode toatomic userspace.degamma_lutLookup table for converting framebuffer pixel data before apply thecolor conversion matrixctm. See
drm_crtc_enable_color_mgmt(). Theblob (if not NULL) is an array ofstructdrm_color_lut.ctmColor transformation matrix. See
drm_crtc_enable_color_mgmt(). Theblob (if not NULL) is astructdrm_color_ctm.gamma_lutLookup table for converting pixel data after the color conversionmatrixctm. See
drm_crtc_enable_color_mgmt(). The blob (if notNULL) is an array ofstructdrm_color_lut.Note that for mostly historical reasons stemming from Xorg heritage,this is also used to store the color map (also sometimes color lut,CLUT or color palette) for indexed formats like DRM_FORMAT_C8.
target_vblankTarget vertical blank period when a page flipshould take effect.
async_flipThis is set when DRM_MODE_PAGE_FLIP_ASYNC is set in the legacyPAGE_FLIP IOCTL. It’s not wired up for the atomic IOCTL itself yet.
vrr_enabledIndicates if variable refresh rate should be enabled for the CRTC.Support for the requested vrr state will depend on driver andhardware capabiltiy - lacking support is not treated as failure.
self_refresh_activeUsed by the self refresh helpers to denote when a self refreshtransition is occurring. This will be set on enable/disable callbackswhen self refresh is being enabled or disabled. In some cases, it maynot be desirable to fully shut off the crtc during self refresh.CRTC’s can inspect this flag and determine the best course of action.
scaling_filterScaling filter to be applied
sharpness_strengthUsed by the user to set the sharpness intensity.The value ranges from 0-255.Default value is 0 which disable the sharpness feature.Any value greater than 0 enables sharpening with thespecified strength.
eventOptional pointer to a DRM event to signal upon completion of thestate update. The driver must send out the event when the atomiccommit operation completes. There are two cases:
The event is for a CRTC which is being disabled through thisatomic commit. In that case the event can be send out any timeafter the hardware has stopped scanning out the currentframebuffers. It should contain the timestamp and counter for thelast vblank before the display pipeline was shut off. The simplestway to achieve that is calling
drm_crtc_send_vblank_event()somewhen afterdrm_crtc_vblank_off()has been called.For a CRTC which is enabled at the end of the commit (even when itundergoes an full modeset) the vblank timestamp and counter mustbe for the vblank right before the first frame that scans out thenew set of buffers. Again the event can only be sent out after thehardware has stopped scanning out the old buffers.
Events for disabled CRTCs are not allowed, and drivers can ignorethat case.
For very simple hardware without VBLANK interrupt, enabling
structdrm_crtc_state.no_vblank makes DRM’s atomic commit helperssend a fake VBLANK event at the end of the display update after allhardware changes have been applied. Seedrm_atomic_helper_fake_vblank().For more complex hardware thiscan be handled by the
drm_crtc_send_vblank_event()function,which the driver should call on the provided event upon completion ofthe atomic commit. Note that if the driver supports vblank signallingand timestamping the vblank counters and timestamps must agree withthe ones returned from page flip events. With the current vblankhelper infrastructure this can be achieved by holding a vblankreference while the page flip is pending, acquired throughdrm_crtc_vblank_get()and released withdrm_crtc_vblank_put().Drivers are free to implement their own vblank counter and timestamptracking though, e.g. if they have accurate timestamp registers inhardware.For hardware which supports some means to synchronize vblankinterrupt delivery with committing display state there’s also
drm_crtc_arm_vblank_event(). See the documentation of that functionfor a detailed discussion of the constraints it needs to be usedsafely.If the device can’t notify of flip completion in a race-free wayat all, then the event should be armed just after the page flip iscommitted. In the worst case the driver will send the event touserspace one frame too late. This doesn’t allow for a real atomicupdate, but it should avoid tearing.
commitThis tracks how the commit for this update proceeds through thevarious phases. This is never cleared, except when we destroy thestate, so that subsequent commits can synchronize with previous ones.
statebackpointer to global drm_atomic_state
Description
Note that the distinction betweenenable andactive is rather subtle:Flippingactive whileenable is set without changing anything else maynever return in a failure from thedrm_mode_config_funcs.atomic_checkcallback. Userspace assumes that a DPMS On will always succeed. In otherwords:enable controls resource assignment,active controls the actualhardware state.
The three booleans active_changed, connectors_changed and mode_changed areintended to indicate whether a full modeset is needed, rather than strictlydescribing what has changed in a commit. See also:drm_atomic_crtc_needs_modeset()
- structdrm_crtc_funcs¶
control CRTCs for a given device
Definition:
struct drm_crtc_funcs { void (*reset)(struct drm_crtc *crtc); int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv, uint32_t handle, uint32_t width, uint32_t height); int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv, uint32_t handle, uint32_t width, uint32_t height, int32_t hot_x, int32_t hot_y); int (*cursor_move)(struct drm_crtc *crtc, int x, int y); int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b, uint32_t size, struct drm_modeset_acquire_ctx *ctx); void (*destroy)(struct drm_crtc *crtc); int (*set_config)(struct drm_mode_set *set, struct drm_modeset_acquire_ctx *ctx); int (*page_flip)(struct drm_crtc *crtc, struct drm_framebuffer *fb, struct drm_pending_vblank_event *event, uint32_t flags, struct drm_modeset_acquire_ctx *ctx); int (*page_flip_target)(struct drm_crtc *crtc, struct drm_framebuffer *fb, struct drm_pending_vblank_event *event, uint32_t flags, uint32_t target, struct drm_modeset_acquire_ctx *ctx); int (*set_property)(struct drm_crtc *crtc, struct drm_property *property, uint64_t val); struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc); void (*atomic_destroy_state)(struct drm_crtc *crtc, struct drm_crtc_state *state); int (*atomic_set_property)(struct drm_crtc *crtc, struct drm_crtc_state *state, struct drm_property *property, uint64_t val); int (*atomic_get_property)(struct drm_crtc *crtc, const struct drm_crtc_state *state, struct drm_property *property, uint64_t *val); int (*late_register)(struct drm_crtc *crtc); void (*early_unregister)(struct drm_crtc *crtc); int (*set_crc_source)(struct drm_crtc *crtc, const char *source); int (*verify_crc_source)(struct drm_crtc *crtc, const char *source, size_t *values_cnt); const char *const *(*get_crc_sources)(struct drm_crtc *crtc, size_t *count); void (*atomic_print_state)(struct drm_printer *p, const struct drm_crtc_state *state); u32 (*get_vblank_counter)(struct drm_crtc *crtc); int (*enable_vblank)(struct drm_crtc *crtc); void (*disable_vblank)(struct drm_crtc *crtc); bool (*get_vblank_timestamp)(struct drm_crtc *crtc, int *max_error, ktime_t *vblank_time, bool in_vblank_irq);};Members
resetReset CRTC hardware and software state to off. This function isn’tcalled by the core directly, only through
drm_mode_config_reset().It’s not a helper hook only for historical reasons.Atomic drivers can use
drm_atomic_helper_crtc_reset()to resetatomic state using this hook.cursor_setUpdate the cursor image. The cursor position is relative to the CRTCand can be partially or fully outside of the visible area.
Note that contrary to all other KMS functions the legacy cursor entrypoints don’t take a framebuffer object, but instead take directly araw buffer object id from the driver’s buffer manager (which iseither GEM or TTM for current drivers).
This entry point is deprecated, drivers should instead implementuniversal plane support and register a proper cursor plane using
drm_crtc_init_with_planes().This callback is optional
RETURNS:
0 on success or a negative error code on failure.
cursor_set2Update the cursor image, including hotspot information. The hotspotmust not affect the cursor position in CRTC coordinates, but is onlymeant as a hint for virtualized display hardware to coordinate theguests and hosts cursor position. The cursor hotspot is relative tothe cursor image. Otherwise this works exactly likecursor_set.
This entry point is deprecated, drivers should instead implementuniversal plane support and register a proper cursor plane using
drm_crtc_init_with_planes().This callback is optional.
RETURNS:
0 on success or a negative error code on failure.
cursor_moveUpdate the cursor position. The cursor does not need to be visiblewhen this hook is called.
This entry point is deprecated, drivers should instead implementuniversal plane support and register a proper cursor plane using
drm_crtc_init_with_planes().This callback is optional.
RETURNS:
0 on success or a negative error code on failure.
gamma_setSet gamma on the CRTC.
This callback is optional.
Atomic drivers who want to support gamma tables should implement theatomic color management support, enabled by calling
drm_crtc_enable_color_mgmt(), which then supports the legacy gammainterface through thedrm_atomic_helper_legacy_gamma_set()compatibility implementation.destroyClean up CRTC resources. This is only called at driver unload timethrough
drm_mode_config_cleanup()since a CRTC cannot be hotpluggedin DRM.set_configThis is the main legacy entry point to change the modeset state on aCRTC. All the details of the desired configuration are passed in a
structdrm_mode_set- see there for details.Drivers implementing atomic modeset should use
drm_atomic_helper_set_config()to implement this hook.RETURNS:
0 on success or a negative error code on failure.
page_flipLegacy entry point to schedule a flip to the given framebuffer.
Page flipping is a synchronization mechanism that replaces the framebuffer being scanned out by the CRTC with a new frame buffer duringvertical blanking, avoiding tearing (except when requested otherwisethrough the DRM_MODE_PAGE_FLIP_ASYNC flag). When an applicationrequests a page flip the DRM core verifies that the new frame bufferis large enough to be scanned out by the CRTC in the currentlyconfigured mode and then calls this hook with a pointer to the newframe buffer.
The driver must wait for any pending rendering to the new framebufferto complete before executing the flip. It should also wait for anypending rendering from other drivers if the underlying buffer is ashared dma-buf.
An application can request to be notified when the page flip hascompleted. The drm core will supply a
structdrm_eventin the eventparameter in this case. This can be handled by thedrm_crtc_send_vblank_event()function, which the driver should call onthe provided event upon completion of the flip. Note that ifthe driver supports vblank signalling and timestamping the vblankcounters and timestamps must agree with the ones returned from pageflip events. With the current vblank helper infrastructure this canbe achieved by holding a vblank reference while the page flip ispending, acquired throughdrm_crtc_vblank_get()and released withdrm_crtc_vblank_put(). Drivers are free to implement their own vblankcounter and timestamp tracking though, e.g. if they have accuratetimestamp registers in hardware.This callback is optional.
NOTE:
Very early versions of the KMS ABI mandated that the driver mustblock (but not reject) any rendering to the old framebuffer until theflip operation has completed and the old framebuffer is no longervisible. This requirement has been lifted, and userspace is insteadexpected to request delivery of an event and wait with recycling oldbuffers until such has been received.
RETURNS:
0 on success or a negative error code on failure. Note that if apage flip operation is already pending the callback should return-EBUSY. Pageflips on a disabled CRTC (either by setting a NULL modeor just runtime disabled through DPMS respectively the new atomic“ACTIVE” state) should result in an -EINVAL error code. Note that
drm_atomic_helper_page_flip()checks this already for atomic drivers.page_flip_targetSame aspage_flip but with an additional parameter specifying theabsolute target vertical blank period (as reported by
drm_crtc_vblank_count()) when the flip should take effect.Note that the core code calls drm_crtc_vblank_get before this entrypoint, and will call drm_crtc_vblank_put if this entry point returnsany non-0 error code. It’s the driver’s responsibility to calldrm_crtc_vblank_put after this entry point returns 0, typically whenthe flip completes.
set_propertyThis is the legacy entry point to update a property attached to theCRTC.
This callback is optional if the driver does not support any legacydriver-private properties. For atomic drivers it is not used becauseproperty handling is done entirely in the DRM core.
RETURNS:
0 on success or a negative error code on failure.
atomic_duplicate_stateDuplicate the current atomic state for this CRTC and return it.The core and helpers guarantee that any atomic state duplicated withthis hook and still owned by the caller (i.e. not transferred to thedriver by calling
drm_mode_config_funcs.atomic_commit) will becleaned up by calling theatomic_destroy_state hook in thisstructure.This callback is mandatory for atomic drivers.
Atomic drivers which don’t subclass
structdrm_crtc_stateshould usedrm_atomic_helper_crtc_duplicate_state(). Drivers that subclass thestate structure to extend it with driver-private state should use__drm_atomic_helper_crtc_duplicate_state()to make sure shared state isduplicated in a consistent fashion across drivers.It is an error to call this hook before
drm_crtc.statehas beeninitialized correctly.NOTE:
If the duplicate state references refcounted resources this hook mustacquire a reference for each of them. The driver must release thesereferences again inatomic_destroy_state.
RETURNS:
Duplicated atomic state or NULL when the allocation failed.
atomic_destroy_stateDestroy a state duplicated withatomic_duplicate_state and releaseor unreference all resources it references
This callback is mandatory for atomic drivers.
atomic_set_propertyDecode a driver-private property value and store the decoded valueinto the passed-in state structure. Since the atomic core decodes allstandardized properties (even for extensions beyond the core set ofproperties which might not be implemented by all drivers) thisrequires drivers to subclass the state structure.
Such driver-private properties should really only be implemented fortruly hardware/vendor specific state. Instead it is preferred tostandardize atomic extension and decode the properties used to exposesuch an extension in the core.
Do not call this function directly, use
drm_atomic_crtc_set_property()instead.This callback is optional if the driver does not support anydriver-private atomic properties.
NOTE:
This function is called in the state assembly phase of atomicmodesets, which can be aborted for any reason (including onuserspace’s request to just check whether a configuration would bepossible). Drivers MUST NOT touch any persistent state (hardware orsoftware) or data structures except the passed instate parameter.
Also since userspace controls in which order properties are set thisfunction must not do any input validation (since the state update isincomplete and hence likely inconsistent). Instead any such inputvalidation must be done in the various atomic_check callbacks.
RETURNS:
0 if the property has been found, -EINVAL if the property isn’timplemented by the driver (which should never happen, the core onlyasks for properties attached to this CRTC). No other validation isallowed by the driver. The core already checks that the propertyvalue is within the range (integer, valid
enumvalue, ...) the driverset when registering the property.atomic_get_propertyReads out the decoded driver-private property. This is used toimplement the GETCRTC IOCTL.
Do not call this function directly, use
drm_atomic_crtc_get_property()instead.This callback is optional if the driver does not support anydriver-private atomic properties.
RETURNS:
0 on success, -EINVAL if the property isn’t implemented by thedriver (which should never happen, the core only asks forproperties attached to this CRTC).
late_registerThis optional hook can be used to register additional userspaceinterfaces attached to the crtc like debugfs interfaces.It is called late in the driver load sequence from
drm_dev_register().Everything added from this callback should be unregistered inthe early_unregister callback.Returns:
0 on success, or a negative error code on failure.
early_unregisterThis optional hook should be used to unregister the additionaluserspace interfaces attached to the crtc fromlate_register. It is called from
drm_dev_unregister(),early in the driver unload sequence to disable userspace accessbefore data structures are torndown.set_crc_sourceChanges the source of CRC checksums of frames at the request ofuserspace, typically for testing purposes. The sources available arespecific of each driver and a
NULLvalue indicates that CRCgeneration is to be switched off.When CRC generation is enabled, the driver should call
drm_crtc_add_crc_entry()at each frame, providing any informationthat characterizes the frame contents in the crcN arguments, asprovided from the configured source. Drivers must accept an “auto”source name that will select a default source for this CRTC.This may trigger an atomic modeset commit if necessary, to enable CRCgeneration.
Note that “auto” can depend upon the current modeset configuration,e.g. it could pick an encoder or output specific CRC sampling point.
This callback is optional if the driver does not support any CRCgeneration functionality.
RETURNS:
0 on success or a negative error code on failure.
verify_crc_sourceverifies the source of CRC checksums of frames before setting thesource for CRC and during crc open. Source parameter can be NULLwhile disabling crc source.
This callback is optional if the driver does not support any CRCgeneration functionality.
RETURNS:
0 on success or a negative error code on failure.
get_crc_sourcesDriver callback for getting a list of all the available sources forCRC generation. This callback depends upon verify_crc_source, Soverify_crc_source callback should be implemented before implementingthis. Driver can pass full list of available crc sources, thiscallback does the verification on each crc-source before passing itto userspace.
This callback is optional if the driver does not support exporting ofpossible CRC sources list.
RETURNS:
a constant character pointer to the list of all the available CRCsources. On failure driver should return NULL. count should beupdated with number of sources in list. if zero we don’t process anysource from the list.
atomic_print_stateIf driver subclasses
structdrm_crtc_state, it should implementthis optional hook for printing additional driver specific state.Do not call this directly, use
drm_atomic_crtc_print_state()instead.get_vblank_counterDriver callback for fetching a raw hardware vblank counter for theCRTC. It’s meant to be used by new drivers as the replacement of
drm_driver.get_vblank_counterhook.This callback is optional. If a device doesn’t have a hardwarecounter, the driver can simply leave the hook as NULL. The DRM corewill account for missed vblank events while interrupts where disabledbased on system timestamps.
Wraparound handling and loss of events due to modesetting is dealtwith in the DRM core code, as long as drivers call
drm_crtc_vblank_off()anddrm_crtc_vblank_on()when disabling orenabling a CRTC.See also
drm_device.vblank_disable_immediateanddrm_device.max_vblank_count.Returns:
Raw vblank counter value.
enable_vblankEnable vblank interrupts for the CRTC. It’s meant to be used bynew drivers as the replacement of
drm_driver.enable_vblankhook.Returns:
Zero on success, appropriate errno if the vblank interrupt cannotbe enabled.
disable_vblankDisable vblank interrupts for the CRTC. It’s meant to be used bynew drivers as the replacement of
drm_driver.disable_vblankhook.get_vblank_timestampCalled by
drm_get_last_vbltimestamp(). Should return a precisetimestamp when the most recent vblank interval ended or will end.Specifically, the timestamp invblank_time should correspond asclosely as possible to the time when the first video scanline ofthe video frame after the end of vblank will start scanning out,the time immediately after end of the vblank interval. If thecrtc is currently inside vblank, this will be a time in the future.If thecrtc is currently scanning out a frame, this will be thepast start time of the current scanout. This is meant to adhereto the OpenML OML_sync_control extension specification.
Parameters:
- crtc:
CRTC for which timestamp should be returned.
- max_error:
Maximum allowable timestamp error in nanoseconds.Implementation should strive to provide timestampwith an error of at most max_error nanoseconds.Returns true upper bound on error for timestamp.
- vblank_time:
Target location for returned vblank timestamp.
- in_vblank_irq:
True when called from
drm_crtc_handle_vblank(). Some driversneed to apply some workarounds for gpu-specific vblank irq quirksif flag is set.
Returns:
True on success, false on failure, which means the core shouldfallback to a simple timestamp taken in
drm_crtc_handle_vblank().
Description
The drm_crtc_funcs structure is the central CRTC management structurein the DRM. Each CRTC controls one or more connectors (note that the nameCRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.connectors, not just CRTs).
Each driver is responsible for filling out this structure at startup time,in addition to providing other modesetting features, like i2c and DDCbus accessors.
- structdrm_crtc¶
central CRTC control structure
Definition:
struct drm_crtc { struct drm_device *dev; struct device_node *port; struct list_head head; char *name; struct drm_modeset_lock mutex; struct drm_mode_object base; struct drm_plane *primary; struct drm_plane *cursor; unsigned index; int cursor_x; int cursor_y; bool enabled; struct drm_display_mode mode; struct drm_display_mode hwmode; int x; int y; const struct drm_crtc_funcs *funcs; uint32_t gamma_size; uint16_t *gamma_store; const struct drm_crtc_helper_funcs *helper_private; struct drm_object_properties properties; struct drm_property *scaling_filter_property; struct drm_property *sharpness_strength_property; struct drm_crtc_state *state; struct list_head commit_list; spinlock_t commit_lock; struct dentry *debugfs_entry; struct drm_crtc_crc crc; unsigned int fence_context; spinlock_t fence_lock; unsigned long fence_seqno; char timeline_name[32]; struct drm_self_refresh_data *self_refresh_data;};Members
devparent DRM device
portOF node used by
drm_of_find_possible_crtcs().headList of all CRTCs ondev, linked from
drm_mode_config.crtc_list.Invariant over the lifetime ofdev and therefore does not needlocking.namehuman readable name, can be overwritten by the driver
mutexThis provides a read lock for the overall CRTC state (mode, dpmsstate, ...) and a write lock for everything which can be updatewithout a full modeset (fb, cursor data, CRTC properties ...). A fullmodeset also need to grab
drm_mode_config.connection_mutex.For atomic drivers specifically this protectsstate.
basebase KMS object for ID tracking etc.
primaryPrimary plane for this CRTC. Note that this is onlyrelevant for legacy IOCTL, it specifies the plane implicitly used bythe SETCRTC and PAGE_FLIP IOCTLs. It does not have any significancebeyond that.
cursorCursor plane for this CRTC. Note that this is only relevant forlegacy IOCTL, it specifies the plane implicitly used by the SETCURSORand SETCURSOR2 IOCTLs. It does not have any significancebeyond that.
indexPosition inside the mode_config.list, can be used as an arrayindex. It is invariant over the lifetime of the CRTC.
cursor_xCurrent x position of the cursor, used for universalcursor planes because the SETCURSOR IOCTL only can update theframebuffer without supplying the coordinates. Drivers should not usethis directly, atomic drivers should look at
drm_plane_state.crtc_xof the cursor plane instead.cursor_yCurrent y position of the cursor, used for universalcursor planes because the SETCURSOR IOCTL only can update theframebuffer without supplying the coordinates. Drivers should not usethis directly, atomic drivers should look at
drm_plane_state.crtc_yof the cursor plane instead.enabledIs this CRTC enabled? Should only be used by legacy drivers, atomicdrivers should instead consult
drm_crtc_state.enableanddrm_crtc_state.active. Atomic drivers can update this by callingdrm_atomic_helper_update_legacy_modeset_state().modeCurrent mode timings. Should only be used by legacy drivers, atomicdrivers should instead consult
drm_crtc_state.mode. Atomic driverscan update this by callingdrm_atomic_helper_update_legacy_modeset_state().hwmodeProgrammed mode in hw, after adjustments for encoders, crtc, panelscaling etc. Should only be used by legacy drivers, for highprecision vblank timestamps in
drm_crtc_vblank_helper_get_vblank_timestamp().Note that atomic drivers should not use this, but instead use
drm_crtc_state.adjusted_mode. And for high-precision timestampsdrm_crtc_vblank_helper_get_vblank_timestamp()useddrm_vblank_crtc.hwmode,which is filled out by callingdrm_calc_timestamping_constants().xx position on screen. Should only be used by legacy drivers, atomicdrivers should look at
drm_plane_state.crtc_xof the primary planeinstead. Updated by callingdrm_atomic_helper_update_legacy_modeset_state().yy position on screen. Should only be used by legacy drivers, atomicdrivers should look at
drm_plane_state.crtc_yof the primary planeinstead. Updated by callingdrm_atomic_helper_update_legacy_modeset_state().funcsCRTC control functions
gamma_sizeSize of legacy gamma ramp reported to userspace. Set upby calling
drm_mode_crtc_set_gamma_size().Note that atomic drivers need to instead use
drm_crtc_state.gamma_lut. Seedrm_crtc_enable_color_mgmt().gamma_storeGamma ramp values used by the legacy SETGAMMA andGETGAMMA IOCTls. Set up by calling
drm_mode_crtc_set_gamma_size().Note that atomic drivers need to instead use
drm_crtc_state.gamma_lut. Seedrm_crtc_enable_color_mgmt().helper_privatemid-layer private data
propertiesproperty tracking for this CRTC
scaling_filter_propertyproperty to apply a particular filter whilescaling.
sharpness_strength_propertyproperty to applythe intensity of the sharpness requested.
stateCurrent atomic state for this CRTC.
This is protected bymutex. Note that nonblocking atomic commitsaccess the current CRTC state without taking locks. Either by goingthrough the
structdrm_atomic_statepointers, seefor_each_oldnew_crtc_in_state(),for_each_old_crtc_in_state()andfor_each_new_crtc_in_state(). Or through careful ordering of atomiccommit operations as implemented in the atomic helpers, seestructdrm_crtc_commit.commit_listList of
drm_crtc_commitstructures tracking pending commits.Protected bycommit_lock. This list holds its own full reference,as does the ongoing commit.“Note that the commit for a state change is also tracked in
drm_crtc_state.commit. For accessing the immediately precedingcommit in an atomic update it is recommended to just use thatpointer in the old CRTC state, since accessing that doesn’t needany locking or list-walking.commit_list should only be used tostall for framebuffer cleanup that’s signalled throughdrm_crtc_commit.cleanup_done.”commit_lockSpinlock to protectcommit_list.
debugfs_entryDebugfs directory for this CRTC.
crcConfiguration settings of CRC capture.
fence_contexttimeline context used for fence operations.
fence_lockspinlock to protect the fences in the fence_context.
fence_seqnoSeqno variable used as monotonic counter for the fencescreated on the CRTC’s timeline.
timeline_nameThe name of the CRTC’s fence timeline.
self_refresh_dataHolds the state for the self refresh helpers
Initialized via
drm_self_refresh_helper_init().
Description
Each CRTC may have one or more connectors associated with it. This structureallows the CRTC to be controlled.
- structdrm_mode_set¶
new values for a CRTC config change
Definition:
struct drm_mode_set { struct drm_framebuffer *fb; struct drm_crtc *crtc; struct drm_display_mode *mode; uint32_t x; uint32_t y; struct drm_connector **connectors; size_t num_connectors;};Members
fbframebuffer to use for new config
crtcCRTC whose configuration we’re about to change
modemode timings to use
xposition of this CRTC relative tofb
yposition of this CRTC relative tofb
connectorsarray of connectors to drive with this CRTC if possible
num_connectorssize ofconnectors array
Description
This represents a modeset configuration for the legacy SETCRTC ioctl and isalso used internally. Atomic drivers instead usedrm_atomic_state.
- drmm_crtc_alloc_with_planes¶
drmm_crtc_alloc_with_planes(dev,type,member,primary,cursor,funcs,name,...)
Allocate and initialize a new CRTC object with specified primary and cursor planes.
Parameters
devDRM device
typethe type of the
structwhichcontains structdrm_crtcmemberthe name of the
drm_crtcwithintype.primaryPrimary plane for CRTC
cursorCursor plane for CRTC
funcscallbacks for the new CRTC
nameprintf style format string for the CRTC name, or NULL for default name
...variable arguments
Description
Allocates and initializes a new crtc object. Cleanup is automaticallyhandled through registeringdrmm_crtc_cleanup() withdrmm_add_action().
Thedrm_crtc_funcs.destroy hook must be NULL.
Return
Pointer to new crtc, or ERR_PTR on failure.
Parameters
conststructdrm_crtc*crtcCRTC to find index for
Description
Given a registered CRTC, return the index of that CRTC within a DRMdevice’s list of CRTCs.
Parameters
conststructdrm_crtc*crtcCRTC to find mask for
Description
Given a registered CRTC, return the mask bit of that CRTC for thedrm_encoder.possible_crtcs anddrm_plane.possible_crtcs fields.
- structdrm_crtc*drm_crtc_find(structdrm_device*dev,structdrm_file*file_priv,uint32_tid)¶
look up a CRTC object from its ID
Parameters
structdrm_device*devDRM device
structdrm_file*file_privdrm file to check for lease against.
uint32_tid
Description
This can be used to look up a CRTC from its userspace ID. Only used bydrivers for legacy IOCTLs and interface, nowadays extensions to the KMSuserspace interface should be done usingdrm_property.
- drm_for_each_crtc¶
drm_for_each_crtc(crtc,dev)
iterate over all CRTCs
- drm_for_each_crtc_reverse¶
drm_for_each_crtc_reverse(crtc,dev)
iterate over all CRTCs in reverse order
- structdrm_crtc*drm_crtc_from_index(structdrm_device*dev,intidx)¶
find the registered CRTC at an index
Parameters
structdrm_device*devDRM device
intidxindex of registered CRTC to find for
Description
Given a CRTC index, return the registered CRTC from DRM device’slist of CRTCs with matching index. This is the inverse ofdrm_crtc_index().It’s useful in the vblank callbacks (likedrm_driver.enable_vblank ordrm_driver.disable_vblank), since that still deals with indices insteadof pointers tostructdrm_crtc.”
- intdrm_crtc_init_with_planes(structdrm_device*dev,structdrm_crtc*crtc,structdrm_plane*primary,structdrm_plane*cursor,conststructdrm_crtc_funcs*funcs,constchar*name,...)¶
Initialise a new CRTC object with specified primary and cursor planes.
Parameters
structdrm_device*devDRM device
structdrm_crtc*crtcCRTC object to init
structdrm_plane*primaryPrimary plane for CRTC
structdrm_plane*cursorCursor plane for CRTC
conststructdrm_crtc_funcs*funcscallbacks for the new CRTC
constchar*nameprintf style format string for the CRTC name, or NULL for default name
...variable arguments
Description
Inits a new object created as base part of a driver crtc object. Driversshould use this function instead ofdrm_crtc_init(), which is only providedfor backwards compatibility with drivers which do not yet support universalplanes). For really simple hardware which has only 1 plane look atdrm_simple_display_pipe_init() instead.Thedrm_crtc_funcs.destroy hook should calldrm_crtc_cleanup() andkfree()the crtc structure. The crtc structure should not be allocated withdevm_kzalloc().
Theprimary andcursor planes are only relevant for legacy uAPI, seedrm_crtc.primary anddrm_crtc.cursor.
Note
consider usingdrmm_crtc_alloc_with_planes() ordrmm_crtc_init_with_planes() instead ofdrm_crtc_init_with_planes()to let the DRM managed resource infrastructure take care of cleanupand deallocation.
Return
Zero on success, error code on failure.
- intdrmm_crtc_init_with_planes(structdrm_device*dev,structdrm_crtc*crtc,structdrm_plane*primary,structdrm_plane*cursor,conststructdrm_crtc_funcs*funcs,constchar*name,...)¶
Initialise a new CRTC object with specified primary and cursor planes.
Parameters
structdrm_device*devDRM device
structdrm_crtc*crtcCRTC object to init
structdrm_plane*primaryPrimary plane for CRTC
structdrm_plane*cursorCursor plane for CRTC
conststructdrm_crtc_funcs*funcscallbacks for the new CRTC
constchar*nameprintf style format string for the CRTC name, or NULL for default name
...variable arguments
Description
Inits a new object created as base part of a driver crtc object. Driversshould use this function instead ofdrm_crtc_init(), which is only providedfor backwards compatibility with drivers which do not yet support universalplanes). For really simple hardware which has only 1 plane look atdrm_simple_display_pipe_init() instead.
Cleanup is automatically handled through registeringdrmm_crtc_cleanup() withdrmm_add_action(). The crtc structure shouldbe allocated withdrmm_kzalloc().
Thedrm_crtc_funcs.destroy hook must be NULL.
Theprimary andcursor planes are only relevant for legacy uAPI, seedrm_crtc.primary anddrm_crtc.cursor.
Return
Zero on success, error code on failure.
Parameters
structdrm_crtc*crtcCRTC to cleanup
Description
This function cleans upcrtc and removes it from the DRM mode settingcore. Note that the function doesnot free the crtc structure itself,this is the responsibility of the caller.
- intdrm_mode_set_config_internal(structdrm_mode_set*set)¶
helper to call
drm_mode_config_funcs.set_config
Parameters
structdrm_mode_set*setmodeset config to set
Description
This is a little helper to wrap internal calls to thedrm_mode_config_funcs.set_config driver interface. The only thing it adds iscorrect refcounting dance.
This should only be used by non-atomic legacy drivers.
Return
Zero on success, negative errno on failure.
- intdrm_crtc_check_viewport(conststructdrm_crtc*crtc,intx,inty,conststructdrm_display_mode*mode,conststructdrm_framebuffer*fb)¶
Checks that a framebuffer is big enough for the CRTC viewport
Parameters
conststructdrm_crtc*crtcCRTC that framebuffer will be displayed on
intxx panning
intyy panning
conststructdrm_display_mode*modemode that framebuffer will be displayed under
conststructdrm_framebuffer*fbframebuffer to check size of
- intdrm_crtc_create_scaling_filter_property(structdrm_crtc*crtc,unsignedintsupported_filters)¶
create a new scaling filter property
Parameters
structdrm_crtc*crtcdrm CRTC
unsignedintsupported_filtersbitmask of supported scaling filters, must includeBIT(DRM_SCALING_FILTER_DEFAULT).
Description
This function lets driver to enable the scaling filter property on a givenCRTC.
Return
Zero for success or -errno
- booldrm_crtc_in_clone_mode(structdrm_crtc_state*crtc_state)¶
check if the given CRTC state is in clone mode
Parameters
structdrm_crtc_state*crtc_stateCRTC state to check
Description
This function determines if the given CRTC state is being cloned by multipleencoders.
Return
True if the CRTC state is in clone mode. False otherwise
Color Management Functions Reference¶
- u64drm_color_ctm_s31_32_to_qm_n(u64user_input,u32m,u32n)¶
Parameters
u64user_inputinput value
u32mnumber of integer bits, only support m <= 32, include the sign-bit
u32nnumber of fractional bits, only support n <= 32
Description
Convert and clamp S31.32 sign-magnitude to Qm.n (signed 2’s complement).The sign-bit BIT(m+n-1) and above are 0 for positive value and 1 for negativethe range of value is [-2^(m-1), 2^(m-1) - 2^-n]
For exampleA Q3.12 format number:- required bit: 3 + 12 = 15bits- range: [-2^2, 2^2 - 2^−15]
NOTE
- the m can be zero if all bit_precision are used to present fractional
bits like Q0.32
- voiddrm_crtc_enable_color_mgmt(structdrm_crtc*crtc,uintdegamma_lut_size,boolhas_ctm,uintgamma_lut_size)¶
enable color management properties
Parameters
structdrm_crtc*crtcDRM CRTC
uintdegamma_lut_sizethe size of the degamma lut (before CSC)
boolhas_ctmwhether to attach ctm_property for CSC matrix
uintgamma_lut_sizethe size of the gamma lut (after CSC)
Description
This function lets the driver enable the color correctionproperties on a CRTC. This includes 3 degamma, csc and gammaproperties that userspace can set and 2 size properties to informthe userspace of the lut sizes. Each of the properties areoptional. The gamma and degamma properties are only attached iftheir size is not 0 and ctm_property is only attached if has_ctm istrue.
Parameters
structdrm_crtc*crtcCRTC to set the gamma table size for
intgamma_sizesize of the gamma table
Description
Drivers which support gamma tables should set this to the supported gammatable size when initializing the CRTC. Currently the drm core only supports afixed gamma table size.
Return
Zero on success, negative errno on failure.
- intdrm_plane_create_color_properties(structdrm_plane*plane,u32supported_encodings,u32supported_ranges,enumdrm_color_encodingdefault_encoding,enumdrm_color_rangedefault_range)¶
color encoding related plane properties
Parameters
structdrm_plane*planeplane object
u32supported_encodingsbitfield indicating supported color encodings
u32supported_rangesbitfileld indicating supported color ranges
enumdrm_color_encodingdefault_encodingdefault color encoding
enumdrm_color_rangedefault_rangedefault color range
Description
Create and attach plane specific COLOR_ENCODING and COLOR_RANGEproperties toplane. The supported encodings and ranges shouldbe provided in supported_encodings and supported_ranges bitmasks.Each bit set in the bitmask indicates that its number asenumvalue is supported.
- intdrm_color_lut_check(conststructdrm_property_blob*lut,u32tests)¶
check validity of lookup table
Parameters
conststructdrm_property_blob*lutproperty blob containing LUT to check
u32testsbitmask of tests to run
Description
Helper to check whether a userspace-provided lookup table is valid andsatisfies hardware requirements. Drivers pass a bitmask indicating which ofthe tests indrm_color_lut_tests should be performed.
Returns 0 on success, -EINVAL on failure.
- voiddrm_crtc_load_gamma_888(structdrm_crtc*crtc,conststructdrm_color_lut*lut,drm_crtc_set_lut_funcset_gamma)¶
Programs gamma ramp for RGB888-like formats
Parameters
structdrm_crtc*crtcThe displaying CRTC
conststructdrm_color_lut*lutThe gamma ramp to program
drm_crtc_set_lut_funcset_gammaCallback for programming the hardware gamma LUT
Description
Programs the gamma ramp specified inlut to hardware. The input gammaramp must have 256 entries per color component.
- voiddrm_crtc_load_gamma_565_from_888(structdrm_crtc*crtc,conststructdrm_color_lut*lut,drm_crtc_set_lut_funcset_gamma)¶
Programs gamma ramp for RGB565-like formats
Parameters
structdrm_crtc*crtcThe displaying CRTC
conststructdrm_color_lut*lutThe gamma ramp to program
drm_crtc_set_lut_funcset_gammaCallback for programming the hardware gamma LUT
Description
Programs the gamma ramp specified inlut to hardware. The input gammaramp must have 256 entries per color component. The helper interpolatesthe individual color components to reduce the number of entries to 5/6/5.
- voiddrm_crtc_load_gamma_555_from_888(structdrm_crtc*crtc,conststructdrm_color_lut*lut,drm_crtc_set_lut_funcset_gamma)¶
Programs gamma ramp for RGB555-like formats
Parameters
structdrm_crtc*crtcThe displaying CRTC
conststructdrm_color_lut*lutThe gamma ramp to program
drm_crtc_set_lut_funcset_gammaCallback for programming the hardware gamma LUT
Description
Programs the gamma ramp specified inlut to hardware. The input gammaramp must have 256 entries per color component. The helper interpolatesthe individual color components to reduce the number of entries to 5/5/5.
- voiddrm_crtc_fill_gamma_888(structdrm_crtc*crtc,drm_crtc_set_lut_funcset_gamma)¶
Programs a default gamma ramp for RGB888-like formats
Parameters
structdrm_crtc*crtcThe displaying CRTC
drm_crtc_set_lut_funcset_gammaCallback for programming the hardware gamma LUT
Description
Programs a default gamma ramp to hardware.
- voiddrm_crtc_fill_gamma_565(structdrm_crtc*crtc,drm_crtc_set_lut_funcset_gamma)¶
Programs a default gamma ramp for RGB565-like formats
Parameters
structdrm_crtc*crtcThe displaying CRTC
drm_crtc_set_lut_funcset_gammaCallback for programming the hardware gamma LUT
Description
Programs a default gamma ramp to hardware.
- voiddrm_crtc_fill_gamma_555(structdrm_crtc*crtc,drm_crtc_set_lut_funcset_gamma)¶
Programs a default gamma ramp for RGB555-like formats
Parameters
structdrm_crtc*crtcThe displaying CRTC
drm_crtc_set_lut_funcset_gammaCallback for programming the hardware gamma LUT
Description
Programs a default gamma ramp to hardware.
- voiddrm_crtc_load_palette_8(structdrm_crtc*crtc,conststructdrm_color_lut*lut,drm_crtc_set_lut_funcset_palette)¶
Programs palette for C8-like formats
Parameters
structdrm_crtc*crtcThe displaying CRTC
conststructdrm_color_lut*lutThe palette to program
drm_crtc_set_lut_funcset_paletteCallback for programming the hardware palette
Description
Programs the palette specified inlut to hardware. The input palettemust have 256 entries per color component.
- voiddrm_crtc_fill_palette_332(structdrm_crtc*crtc,drm_crtc_set_lut_funcset_palette)¶
Programs a default palette for R332-like formats
Parameters
structdrm_crtc*crtcThe displaying CRTC
drm_crtc_set_lut_funcset_paletteCallback for programming the hardware gamma LUT
Description
Programs an RGB332 palette to hardware.
- voiddrm_crtc_fill_palette_8(structdrm_crtc*crtc,drm_crtc_set_lut_funcset_palette)¶
Programs a default palette for C8-like formats
Parameters
structdrm_crtc*crtcThe displaying CRTC
drm_crtc_set_lut_funcset_paletteCallback for programming the hardware gamma LUT
Description
Programs a default palette to hardware.
- intdrm_color_lut32_check(conststructdrm_property_blob*lut,u32tests)¶
check validity of extended lookup table
Parameters
conststructdrm_property_blob*lutproperty blob containing extended LUT to check
u32testsbitmask of tests to run
Description
Helper to check whether a userspace-provided extended lookup table is valid andsatisfies hardware requirements. Drivers pass a bitmask indicating which ofthe tests indrm_color_lut_tests should be performed.
Returns 0 on success, -EINVAL on failure.
- u32drm_color_lut_extract(u32user_input,intbit_precision)¶
clamp and round LUT entries
Parameters
u32user_inputinput value
intbit_precisionnumber of bits the hw LUT supports
Description
Extract a degamma/gamma LUT value provided by user (in the form ofdrm_color_lut entries) and round it to the precision supported by thehardware, following OpenGL int<->float conversion rules(see eg. OpenGL 4.6 specification - 2.3.5 Fixed-Point Data Conversions).
- u32drm_color_lut32_extract(u32user_input,intbit_precision)¶
clamp and round LUT entries
Parameters
u32user_inputinput value
intbit_precisionnumber of bits the hw LUT supports
Description
Extract U0.bit_precision from a U0.32 LUT value.
- intdrm_color_lut_size(conststructdrm_property_blob*blob)¶
calculate the number of entries in the LUT
Parameters
conststructdrm_property_blob*blobblob containing the LUT
Return
The number of entries in the color LUT stored inblob.
- intdrm_color_lut32_size(conststructdrm_property_blob*blob)¶
calculate the number of entries in the extended LUT
Parameters
conststructdrm_property_blob*blobblob containing the LUT
Return
The number of entries in the color LUT stored inblob.
- enumdrm_color_lut_tests¶
hw-specific LUT tests to perform
Constants
DRM_COLOR_LUT_EQUAL_CHANNELSChecks whether the entries of a LUT all have equal values for thered, green, and blue channels. Intended for hardware that onlyaccepts a single value per LUT entry and assumes that value appliesto all three color components.
DRM_COLOR_LUT_NON_DECREASINGChecks whether the entries of a LUT are always flat or increasing(never decreasing).
Description
Thedrm_color_lut_check() function takes a bitmask of the values here todetermine which tests to apply to a userspace-provided LUT.
Frame Buffer Abstraction¶
Frame buffers are abstract memory objects that provide a source of pixels toscanout to a CRTC. Applications explicitly request the creation of framebuffers through the DRM_IOCTL_MODE_ADDFB(2) ioctls and receive an opaquehandle that can be passed to the KMS CRTC control, plane configuration andpage flip functions.
Frame buffers rely on the underlying memory manager for allocating backingstorage. When creating a frame buffer applications pass a memory handle(or a list of memory handles for multi-planar formats) through thestructdrm_mode_fb_cmd2 argument. For drivers using GEM as their userspacebuffer management interface this would be a GEM handle. Drivers are howeverfree to use their own backing storage object handles, e.g. vmwgfx directlyexposes special TTM handles to userspace and so expects TTM handles in thecreate ioctl and not GEM handles.
Framebuffers are tracked withstructdrm_framebuffer. They are publishedusingdrm_framebuffer_init() - after calling that function userspace can useand access the framebuffer object. The helper functiondrm_helper_mode_fill_fb_struct() can be used to pre-fill the requiredmetadata fields.
The lifetime of a drm framebuffer is controlled with a reference count,drivers can grab additional references withdrm_framebuffer_get() and dropthem again withdrm_framebuffer_put(). For driver-private framebuffers forwhich the last reference is never dropped (e.g. for the fbdev framebufferwhen the structstructdrm_framebuffer is embedded into the fbdev helperstruct) drivers can manually clean up a framebuffer at module unload timewithdrm_framebuffer_unregister_private(). But doing this is notrecommended, and it’s better to have a normal free-standingstructdrm_framebuffer.
Frame Buffer Functions Reference¶
- structdrm_framebuffer_funcs¶
framebuffer hooks
Definition:
struct drm_framebuffer_funcs { void (*destroy)(struct drm_framebuffer *framebuffer); int (*create_handle)(struct drm_framebuffer *fb, struct drm_file *file_priv, unsigned int *handle); int (*dirty)(struct drm_framebuffer *framebuffer, struct drm_file *file_priv, unsigned flags, unsigned color, struct drm_clip_rect *clips, unsigned num_clips);};Members
destroyClean up framebuffer resources, specifically also unreference thebacking storage. The core guarantees to call this function for everyframebuffer successfully created by calling
drm_mode_config_funcs.fb_create. Drivers must also calldrm_framebuffer_cleanup()to release DRM core resources for thisframebuffer.create_handleCreate a buffer handle in the driver-specific buffer manager (eitherGEM or TTM) valid for the passed-in
structdrm_file. This is used bythe core to implement the GETFB IOCTL, which returns (forsufficiently priviledged user) also a native buffer handle. This canbe used for seamless transitions between modesetting clients bycopying the current screen contents to a private buffer and blendingbetween that and the new contents.GEM based drivers should call
drm_gem_handle_create()to create thehandle.RETURNS:
0 on success or a negative error code on failure.
dirtyOptional callback for the dirty fb IOCTL.
Userspace can notify the driver via this callback that an area of theframebuffer has changed and should be flushed to the displayhardware. This can also be used internally, e.g. by the fbdevemulation, though that’s not the case currently.
See documentation in drm_mode.h for the
structdrm_mode_fb_dirty_cmdfor more information as all the semantics and arguments have a one toone mapping on this function.Atomic drivers should use
drm_atomic_helper_dirtyfb()to implementthis hook.RETURNS:
0 on success or a negative error code on failure.
- structdrm_framebuffer¶
frame buffer object
Definition:
struct drm_framebuffer { struct drm_device *dev; struct list_head head; struct drm_mode_object base; char comm[TASK_COMM_LEN]; const struct drm_format_info *format; const struct drm_framebuffer_funcs *funcs; unsigned int pitches[DRM_FORMAT_MAX_PLANES]; unsigned int offsets[DRM_FORMAT_MAX_PLANES]; uint64_t modifier; unsigned int width; unsigned int height; int flags; unsigned int internal_flags; struct list_head filp_head; struct drm_gem_object *obj[DRM_FORMAT_MAX_PLANES];};Members
devDRM device this framebuffer belongs to
headPlace on the
drm_mode_config.fb_list, access protected bydrm_mode_config.fb_lock.basebase modeset object structure, contains the reference count.
commName of the process allocating the fb, used for fb dumping.
formatframebuffer format information
funcsframebuffer vfunc table
pitchesLine stride per buffer. For userspace created object thisis copied from drm_mode_fb_cmd2.
offsetsOffset from buffer start to the actual pixel data in bytes,per buffer. For userspace created object this is copied fromdrm_mode_fb_cmd2.
Note that this is a linear offset and does not take into accounttiling or buffer layout permodifier. It is meant to be used whenthe actual pixel data for this framebuffer plane starts at an offset,e.g. when multiple planes are allocated within the same backingstorage buffer object. For tiled layouts this generally means itsoffsets must at least be tile-size aligned, but hardware often hasstricter requirements.
This should not be used to specifiy x/y pixel offsets into the bufferdata (even for linear buffers). Specifying an x/y pixel offset isinstead done through the source rectangle in
structdrm_plane_state.modifierData layout modifier. This is used to describetiling, or also special layouts (like compression) of auxiliarybuffers. For userspace created object this is copied fromdrm_mode_fb_cmd2.
widthLogical width of the visible area of the framebuffer, inpixels.
heightLogical height of the visible area of the framebuffer, inpixels.
flagsFramebuffer flags like DRM_MODE_FB_INTERLACED orDRM_MODE_FB_MODIFIERS.
internal_flagsFramebuffer flags like DRM_FRAMEBUFFER_HAS_HANDLE_REF.
filp_headPlaced on
drm_file.fbs, protected bydrm_file.fbs_lock.objGEM objects backing the framebuffer, one per plane (optional).
This is used by the GEM framebuffer helpers, see e.g.
drm_gem_fb_create().
Description
Note that the fb is refcounted for the benefit of driver internals,for example some hw, disabling a CRTC/plane is asynchronous, andscanout does not actually complete until the next vblank. So somecleanup (like releasing the reference(s) on the backing GEM bo(s))should be deferred. In cases like this, the driver would like tohold a ref to the fb even though it has already been removed fromuserspace perspective. Seedrm_framebuffer_get() anddrm_framebuffer_put().
The refcount is stored inside the mode objectbase.
- voiddrm_framebuffer_get(structdrm_framebuffer*fb)¶
acquire a framebuffer reference
Parameters
structdrm_framebuffer*fbDRM framebuffer
Description
This function increments the framebuffer’s reference count.
- voiddrm_framebuffer_put(structdrm_framebuffer*fb)¶
release a framebuffer reference
Parameters
structdrm_framebuffer*fbDRM framebuffer
Description
This function decrements the framebuffer’s reference count and frees theframebuffer if the reference count drops to zero.
- uint32_tdrm_framebuffer_read_refcount(conststructdrm_framebuffer*fb)¶
read the framebuffer reference count.
Parameters
conststructdrm_framebuffer*fbframebuffer
Description
This functions returns the framebuffer’s reference count.
- voiddrm_framebuffer_assign(structdrm_framebuffer**p,structdrm_framebuffer*fb)¶
store a reference to the fb
Parameters
structdrm_framebuffer**plocation to store framebuffer
structdrm_framebuffer*fbnew framebuffer (maybe NULL)
Description
This functions sets the location to store a reference to the framebuffer,unreferencing the framebuffer that was previously stored in that location.
- structdrm_afbc_framebuffer¶
a special afbc frame buffer object
Definition:
struct drm_afbc_framebuffer { struct drm_framebuffer base; u32 block_width; u32 block_height; u32 aligned_width; u32 aligned_height; u32 offset; u32 afbc_size;};Members
basebase framebuffer structure.
block_widthwidth of a single afbc block
block_heightheight of a single afbc block
aligned_widthaligned frame buffer width
aligned_heightaligned frame buffer height
offsetoffset of the first afbc header
afbc_sizeminimum size of afbc buffer
Description
A derived class ofstructdrm_framebuffer, dedicated for afbc use cases.
- intdrm_framebuffer_init(structdrm_device*dev,structdrm_framebuffer*fb,conststructdrm_framebuffer_funcs*funcs)¶
initialize a framebuffer
Parameters
structdrm_device*devDRM device
structdrm_framebuffer*fbframebuffer to be initialized
conststructdrm_framebuffer_funcs*funcs... with these functions
Description
Allocates an ID for the framebuffer’s parent mode object, sets its modefunctions & device file and adds it to the master fd list.
IMPORTANT:This functions publishes the fb and makes it available for concurrent accessby other users. Which means by this point the fb _must_ be fully set up -since all the fb attributes are invariant over its lifetime, no furtherlocking but only correct reference counting is required.
Return
Zero on success, error code on failure.
- structdrm_framebuffer*drm_framebuffer_lookup(structdrm_device*dev,structdrm_file*file_priv,uint32_tid)¶
look up a drm framebuffer and grab a reference
Parameters
structdrm_device*devdrm device
structdrm_file*file_privdrm file to check for lease against.
uint32_tidid of the fb object
Description
If successful, this grabs an additional reference to the framebuffer -callers need to make sure to eventually unreference the returned framebufferagain, usingdrm_framebuffer_put().
- voiddrm_framebuffer_unregister_private(structdrm_framebuffer*fb)¶
unregister a private fb from the lookup idr
Parameters
structdrm_framebuffer*fbfb to unregister
Description
Drivers need to call this when cleaning up driver-private framebuffers, e.g.those used for fbdev. Note that the caller must hold a reference of its own,i.e. the object may not be destroyed through this call (since it’ll lead to alocking inversion).
NOTE
This function is deprecated. For driver-private framebuffers it is notrecommended to embed a framebufferstructinfo fbdev struct, instead, aframebuffer pointer is preferred anddrm_framebuffer_put() should be calledwhen the framebuffer is to be cleaned up.
- voiddrm_framebuffer_cleanup(structdrm_framebuffer*fb)¶
remove a framebuffer object
Parameters
structdrm_framebuffer*fbframebuffer to remove
Description
Cleanup framebuffer. This function is intended to be used from the driversdrm_framebuffer_funcs.destroy callback. It can also be used to clean updriver private framebuffers embedded into a larger structure.
Note that this function does not remove the fb from active usage - if it isstill used anywhere, hilarity can ensue since userspace could call getfb onthe id and get back -EINVAL. Obviously no concern at driver unload time.
Also, the framebuffer will not be removed from the lookup idr - foruser-created framebuffers this will happen in the rmfb ioctl. Fordriver-private objects (e.g. for fbdev) drivers need to explicitly calldrm_framebuffer_unregister_private.
- voiddrm_framebuffer_remove(structdrm_framebuffer*fb)¶
remove and unreference a framebuffer object
Parameters
structdrm_framebuffer*fbframebuffer to remove
Description
Scans all the CRTCs and planes indev’s mode_config. If they’reusingfb, removes it, setting it to NULL. Then drops the reference to thepassed-in framebuffer. Might take the modeset locks.
Note that this function optimizes the cleanup away if the caller holds thelast reference to the framebuffer. It is also guaranteed to not take themodeset locks in this case.
DRM Format Handling¶
In the DRM subsystem, framebuffer pixel formats are described using thefourcc codes defined ininclude/uapi/drm/drm_fourcc.h. In addition to thefourcc code, a Format Modifier may optionally be provided, in order tofurther describe the buffer’s format - for example tiling or compression.
Format Modifiers¶
Format modifiers are used in conjunction with a fourcc code, forming aunique fourcc:modifier pair. This format:modifier pair must fully define theformat and data layout of the buffer, and should be the only way to describethat particular buffer.
Having multiple fourcc:modifier pairs which describe the same layout shouldbe avoided, as such aliases run the risk of different drivers exposingdifferent names for the same data format, forcing userspace to understandthat they are aliases.
Format modifiers may change any property of the buffer, including the numberof planes and/or the required allocation size. Format modifiers arevendor-namespaced, and as such the relationship between a fourcc code and amodifier is specific to the modifier being used. For example, some modifiersmay preserve meaning - such as number of planes - from the fourcc code,whereas others may not.
Modifiers must uniquely encode buffer layout. In other words, a buffer mustmatch only a single modifier. A modifier must not be a subset of layouts ofanother modifier. For instance, it’s incorrect to encode pitch alignment ina modifier: a buffer may match a 64-pixel aligned modifier and a 32-pixelaligned modifier. That said, modifiers can have implicit minimalrequirements.
For modifiers where the combination of fourcc code and modifier can alias,a canonical pair needs to be defined and used by all drivers. Preferredcombinations are also encouraged where all combinations might lead toconfusion and unnecessarily reduced interoperability. An example for thelatter is AFBC, where the ABGR layouts are preferred over ARGB layouts.
There are two kinds of modifier users:
Kernel and user-space drivers: for drivers it’s important that modifiersdon’t alias, otherwise two drivers might support the same format but usedifferent aliases, preventing them from sharing buffers in an efficientformat.
Higher-level programs interfacing with KMS/GBM/EGL/Vulkan/etc: these userssee modifiers as opaque tokens they can check for equality and intersect.These users mustn’t need to know to reason about the modifier value(i.e. they are not expected to extract information out of the modifier).
Vendors should document their modifier usage in as much detail aspossible, to ensure maximum compatibility across devices, drivers andapplications.
The authoritative list of format modifier codes is found ininclude/uapi/drm/drm_fourcc.h
Open Source User Waiver¶
Because this is the authoritative source for pixel formats and modifiersreferenced by GL, Vulkan extensions and other standards and hence used bothby open source and closed source driver stacks, the usual requirement for anupstream in-kernel or open source userspace user does not apply.
To ensure, as much as feasible, compatibility across stacks and avoidconfusion with incompatible enumerations stakeholders for all relevant driverstacks should approve additions.
Format Functions Reference¶
- DRM_FORMAT_MAX_PLANES¶
DRM_FORMAT_MAX_PLANES
maximum number of planes a DRM format can have
- structdrm_format_info¶
information about a DRM format
Definition:
struct drm_format_info { u32 format; u8 depth; u8 num_planes; union { u8 cpp[DRM_FORMAT_MAX_PLANES]; u8 char_per_block[DRM_FORMAT_MAX_PLANES]; }; u8 block_w[DRM_FORMAT_MAX_PLANES]; u8 block_h[DRM_FORMAT_MAX_PLANES]; u8 hsub; u8 vsub; bool has_alpha; bool is_yuv; bool is_color_indexed;};Members
format4CC format identifier (DRM_FORMAT_*)
depthColor depth (number of bits per pixel excluding padding bits),valid for a subset of RGB formats only. This is a legacy field, donot use in new code and set to 0 for new formats.
num_planesNumber of color planes (1 to 3)
{unnamed_union}anonymous
cppNumber of bytes per pixel (per plane), this is aliased withchar_per_block. It is deprecated in favour of using thetripletchar_per_block,block_w,block_h for betterdescribing the pixel format.
char_per_blockNumber of bytes per block (per plane), where blocks aredefined as a rectangle of pixels which are stored next toeach other in a byte aligned memory region. Together withblock_w andblock_h this is used to properly describe tilesin tiled formats or to describe groups of pixels in packedformats for which the memory needed for a single pixel is notbyte aligned.
cpp has been kept for historical reasons because there area lot of places in drivers where it’s used. In drm core forgeneric code paths the preferred way is to usechar_per_block,
drm_format_info_block_width()anddrm_format_info_block_height()which allows handling bothblock and non-block formats in the same way.For formats that are intended to be used only with non-linearmodifiers bothcpp andchar_per_block must be 0 in thegeneric format table. Drivers could supply accurateinformation from their drm_mode_config.get_format_info hookif they want the core to be validating the pitch.
block_wBlock width in pixels, this is intended to be accessed through
drm_format_info_block_width()block_hBlock height in pixels, this is intended to be accessed through
drm_format_info_block_height()hsubHorizontal chroma subsampling factor
vsubVertical chroma subsampling factor
has_alphaDoes the format embeds an alpha component?
is_yuvIs it a YUV format?
is_color_indexedIs it a color-indexed format?
- booldrm_format_info_is_yuv_packed(conststructdrm_format_info*info)¶
check that the format info matches a YUV format with data laid in a single plane
Parameters
conststructdrm_format_info*infoformat info
Return
A boolean indicating whether the format info matches a packed YUV format.
- booldrm_format_info_is_yuv_semiplanar(conststructdrm_format_info*info)¶
check that the format info matches a YUV format with data laid in two planes (luminance and chrominance)
Parameters
conststructdrm_format_info*infoformat info
Return
A boolean indicating whether the format info matches a semiplanar YUV format.
- booldrm_format_info_is_yuv_planar(conststructdrm_format_info*info)¶
check that the format info matches a YUV format with data laid in three planes (one for each YUV component)
Parameters
conststructdrm_format_info*infoformat info
Return
A boolean indicating whether the format info matches a planar YUV format.
- booldrm_format_info_is_yuv_sampling_410(conststructdrm_format_info*info)¶
check that the format info matches a YUV format with 4:1:0 sub-sampling
Parameters
conststructdrm_format_info*infoformat info
Return
A boolean indicating whether the format info matches a YUV format with 4:1:0sub-sampling.
- booldrm_format_info_is_yuv_sampling_411(conststructdrm_format_info*info)¶
check that the format info matches a YUV format with 4:1:1 sub-sampling
Parameters
conststructdrm_format_info*infoformat info
Return
A boolean indicating whether the format info matches a YUV format with 4:1:1sub-sampling.
- booldrm_format_info_is_yuv_sampling_420(conststructdrm_format_info*info)¶
check that the format info matches a YUV format with 4:2:0 sub-sampling
Parameters
conststructdrm_format_info*infoformat info
Return
A boolean indicating whether the format info matches a YUV format with 4:2:0sub-sampling.
- booldrm_format_info_is_yuv_sampling_422(conststructdrm_format_info*info)¶
check that the format info matches a YUV format with 4:2:2 sub-sampling
Parameters
conststructdrm_format_info*infoformat info
Return
A boolean indicating whether the format info matches a YUV format with 4:2:2sub-sampling.
- booldrm_format_info_is_yuv_sampling_444(conststructdrm_format_info*info)¶
check that the format info matches a YUV format with 4:4:4 sub-sampling
Parameters
conststructdrm_format_info*infoformat info
Return
A boolean indicating whether the format info matches a YUV format with 4:4:4sub-sampling.
- intdrm_format_info_plane_width(conststructdrm_format_info*info,intwidth,intplane)¶
width of the plane given the first plane
Parameters
conststructdrm_format_info*infopixel format info
intwidthwidth of the first plane
intplaneplane index
Return
The width ofplane, given that the width of the first plane iswidth.
- intdrm_format_info_plane_height(conststructdrm_format_info*info,intheight,intplane)¶
height of the plane given the first plane
Parameters
conststructdrm_format_info*infopixel format info
intheightheight of the first plane
intplaneplane index
Return
The height ofplane, given that the height of the first plane isheight.
- uint32_tdrm_mode_legacy_fb_format(uint32_tbpp,uint32_tdepth)¶
compute drm fourcc code from legacy description
Parameters
uint32_tbppbits per pixels
uint32_tdepthbit depth per pixel
Description
Computes a drm fourcc pixel format code for the givenbpp/depth values.
- uint32_tdrm_driver_legacy_fb_format(structdrm_device*dev,uint32_tbpp,uint32_tdepth)¶
compute drm fourcc code from legacy description
Parameters
structdrm_device*devDRM device
uint32_tbppbits per pixels
uint32_tdepthbit depth per pixel
Description
Computes a drm fourcc pixel format code for the givenbpp/depth values.Unlikedrm_mode_legacy_fb_format() this looks at the drivers mode_config,and depending on thedrm_mode_config.quirk_addfb_prefer_host_byte_order flagit returns little endian byte order or host byte order framebuffer formats.
- uint32_tdrm_driver_color_mode_format(structdrm_device*dev,unsignedintcolor_mode)¶
Compute DRM 4CC code from color mode
Parameters
structdrm_device*devDRM device
unsignedintcolor_modecommand-line color mode
Description
Computes a DRM 4CC pixel format code for the given color mode usingdrm_driver_color_mode(). The color mode is in the format used and thekernel command line. It specifies the number of bits per pixeland color depth in a single value.
Useful in fbdev emulation code, since that deals in those values. Thehelper does not consider YUV or other complicated formats. This meansonly legacy formats are supported (fmt->depth is a legacy field), butthe framebuffer emulation can only deal with such formats, specificallyRGB/BGA formats.
- conststructdrm_format_info*drm_format_info(u32format)
query information for a given format
Parameters
u32formatpixel format (DRM_FORMAT_*)
Description
The caller should only pass a supported pixel format to this function.Unsupported pixel formats will generate a warning in the kernel log.
Return
The instance ofstructdrm_format_info that describes the pixel format, orNULL if the format is unsupported.
- conststructdrm_format_info*drm_get_format_info(structdrm_device*dev,u32pixel_format,u64modifier)¶
query information for a given framebuffer configuration
Parameters
structdrm_device*devDRM device
u32pixel_formatpixel format (DRM_FORMAT_*)
u64modifiermodifier
Return
The instance ofstructdrm_format_info that describes the pixel format, orNULL if the format is unsupported.
- unsignedintdrm_format_info_block_width(conststructdrm_format_info*info,intplane)¶
width in pixels of block.
Parameters
conststructdrm_format_info*infopixel format info
intplaneplane index
Return
The width in pixels of a block, depending on the plane index.
- unsignedintdrm_format_info_block_height(conststructdrm_format_info*info,intplane)¶
height in pixels of a block
Parameters
conststructdrm_format_info*infopixel format info
intplaneplane index
Return
The height in pixels of a block, depending on the plane index.
- unsignedintdrm_format_info_bpp(conststructdrm_format_info*info,intplane)¶
number of bits per pixel
Parameters
conststructdrm_format_info*infopixel format info
intplaneplane index
Return
The actual number of bits per pixel, depending on the plane index.
- uint64_tdrm_format_info_min_pitch(conststructdrm_format_info*info,intplane,unsignedintbuffer_width)¶
computes the minimum required pitch in bytes
Parameters
conststructdrm_format_info*infopixel format info
intplaneplane index
unsignedintbuffer_widthbuffer width in pixels
Return
The minimum required pitch in bytes for a buffer by taking into considerationthe pixel format information and the buffer width.
Dumb Buffer Objects¶
The KMS API doesn’t standardize backing storage object creation and leaves itto driver-specific ioctls. Furthermore actually creating a buffer object evenfor GEM-based drivers is done through a driver-specific ioctl - GEM only hasa common userspace interface for sharing and destroying objects. While not anissue for full-fledged graphics stacks that include device-specific userspacecomponents (in libdrm for instance), this limit makes DRM-based early bootgraphics unnecessarily complex.
Dumb objects partly alleviate the problem by providing a standard API tocreate dumb buffers suitable for scanout, which can then be used to createKMS frame buffers.
To support dumb objects drivers must implement thedrm_driver.dumb_createanddrm_driver.dumb_map_offset operations (the latter defaults todrm_gem_dumb_map_offset() if not set). Drivers that don’t use GEM handlesadditionally need to implement thedrm_driver.dumb_destroy operation. Seethe callbacks for further details.
Note that dumb objects may not be used for gpu acceleration, as has beenattempted on some ARM embedded platforms. Such drivers really must havea hardware-specific ioctl to allocate suitable buffer objects.
Plane Abstraction¶
A plane represents an image source that can be blended with or overlaid ontop of a CRTC during the scanout process. Planes take their input data from adrm_framebuffer object. The plane itself specifies the cropping and scalingof that image, and where it is placed on the visible area of a displaypipeline, represented bydrm_crtc. A plane can also have additionalproperties that specify how the pixels are positioned and blended, likerotation or Z-position. All these properties are stored indrm_plane_state.
Unless explicitly specified (via CRTC property or otherwise), the active areaof a CRTC will be black by default. This means portions of the active areawhich are not covered by a plane will be black, and alpha blending of anyplanes with the CRTC background will blend with black at the lowest zpos.
To create a plane, a KMS drivers allocates and zeroes an instances ofstructdrm_plane (possibly as part of a larger structure) and registers itwith a call todrm_universal_plane_init().
Each plane has a type, seeenumdrm_plane_type. A plane can be compatiblewith multiple CRTCs, seedrm_plane.possible_crtcs.
Each CRTC must have a unique primary plane userspace can attach to enablethe CRTC. In other words, userspace must be able to attach a differentprimary plane to each CRTC at the same time. Primary planes can still becompatible with multiple CRTCs. There must be exactly as many primary planesas there are CRTCs.
Legacy uAPI doesn’t expose the primary and cursor planes directly. DRM corerelies on the driver to set the primary and optionally the cursor plane usedfor legacy IOCTLs. This is done by callingdrm_crtc_init_with_planes(). Alldrivers must provide one primary plane per CRTC to avoid surprising legacyuserspace too much.
Plane Functions Reference¶
- structdrm_plane_state¶
mutable plane state
Definition:
struct drm_plane_state { struct drm_plane *plane; struct drm_crtc *crtc; struct drm_framebuffer *fb; struct dma_fence *fence; int32_t crtc_x; int32_t crtc_y; uint32_t crtc_w, crtc_h; uint32_t src_x; uint32_t src_y; uint32_t src_h, src_w; int32_t hotspot_x, hotspot_y; u16 alpha; uint16_t pixel_blend_mode; unsigned int rotation; unsigned int zpos; unsigned int normalized_zpos; enum drm_color_encoding color_encoding; enum drm_color_range color_range; struct drm_property_blob *fb_damage_clips; bool ignore_damage_clips; struct drm_rect src, dst; bool visible; enum drm_scaling_filter scaling_filter; struct drm_colorop *color_pipeline; struct drm_crtc_commit *commit; struct drm_atomic_state *state; bool color_mgmt_changed : 1;};Members
planebackpointer to the plane
crtcCurrently bound CRTC, NULL if disabled. Do not write this directly,use
drm_atomic_set_crtc_for_plane()fbCurrently bound framebuffer. Do not write this directly, use
drm_atomic_set_fb_for_plane()fenceOptional fence to wait for before scanning outfb. The core atomiccode will set this when userspace is using explicit fencing. Do notwrite this field directly for a driver’s implicit fence.
Drivers should store any implicit fence in this from their
drm_plane_helper_funcs.prepare_fbcallback. Seedrm_gem_plane_helper_prepare_fb()for a suitable helper.crtc_xLeft position of visible portion of plane on crtc, signed destlocation allows it to be partially off screen.
crtc_yUpper position of visible portion of plane on crtc, signed destlocation allows it to be partially off screen.
crtc_wwidth of visible portion of plane on crtc
crtc_hheight of visible portion of plane on crtc
src_xleft position of visible portion of plane within plane (in16.16 fixed point).
src_yupper position of visible portion of plane within plane (in16.16 fixed point).
src_hheight of visible portion of plane (in 16.16)
src_wwidth of visible portion of plane (in 16.16)
hotspot_xx offset to mouse cursor hotspot
hotspot_yy offset to mouse cursor hotspot
alphaOpacity of the plane with 0 as completely transparent and 0xffff ascompletely opaque. See
drm_plane_create_alpha_property()for moredetails.pixel_blend_modeThe alpha blending equation selection, describing how the pixels fromthe current plane are composited with the background. Value can beone of DRM_MODE_BLEND_*
rotationRotation of the plane. See
drm_plane_create_rotation_property()formore details.zposPriority of the given plane on crtc (optional).
User-space may set mutable zpos properties so that multiple activeplanes on the same CRTC have identical zpos values. This is auser-space bug, but drivers can solve the conflict by comparing theplane object IDs; the plane with a higher ID is stacked on top of aplane with a lower ID.
See
drm_plane_create_zpos_property()anddrm_plane_create_zpos_immutable_property()for more details.normalized_zposNormalized value of zpos: unique, range from 0 to N-1 where N is thenumber of active planes for given crtc. Note that the driver must set
drm_mode_config.normalize_zposor calldrm_atomic_normalize_zpos()toupdate this before it can be trusted.color_encodingColor encoding for non RGB formats
color_rangeColor range for non RGB formats
fb_damage_clipsBlob representing damage (area in plane framebuffer that changedsince last plane update) as an array of
drm_mode_rectin framebuffercoodinates of the attached framebuffer. Note that unlike plane src,damage clips are not in 16.16 fixed point.See
drm_plane_get_damage_clips()anddrm_plane_get_damage_clips_count()for accessing these.ignore_damage_clipsSet by drivers to indicate the
drm_atomic_helper_damage_iter_init()helper that thefb_damage_clips blob property should be ignored.SeeDamage Tracking Properties for more information.
srcsource coordinates of the plane (in 16.16).
When using
drm_atomic_helper_check_plane_state(),the coordinates are clipped, but the driver may chooseto use unclipped coordinates instead when the hardwareperforms the clipping automatically.dstclipped destination coordinates of the plane.
When using
drm_atomic_helper_check_plane_state(),the coordinates are clipped, but the driver may chooseto use unclipped coordinates instead when the hardwareperforms the clipping automatically.visibleVisibility of the plane. This can be false even if fb!=NULL andcrtc!=NULL, due to clipping.
scaling_filterScaling filter to be applied
color_pipelineThe first colorop of the active color pipeline, or NULL, if nocolor pipeline is active.
commitTracks the pending commit to prevent use-after-free conditions,and for async plane updates.
May be NULL.
statebackpointer to global drm_atomic_state
color_mgmt_changedColor management properties have changed. Usedby the atomic helpers and drivers to steer the atomic commit controlflow.
Description
Please note that the destination coordinatescrtc_x,crtc_y,crtc_h andcrtc_w and the source coordinatessrc_x,src_y,src_h andsrc_w are theraw coordinates provided by userspace. Drivers should usedrm_atomic_helper_check_plane_state() and only use the derived rectangles insrc anddst to program the hardware.
- structdrm_plane_funcs¶
driver plane control functions
Definition:
struct drm_plane_funcs { int (*update_plane)(struct drm_plane *plane, struct drm_crtc *crtc, struct drm_framebuffer *fb, int crtc_x, int crtc_y, unsigned int crtc_w, unsigned int crtc_h, uint32_t src_x, uint32_t src_y, uint32_t src_w, uint32_t src_h, struct drm_modeset_acquire_ctx *ctx); int (*disable_plane)(struct drm_plane *plane, struct drm_modeset_acquire_ctx *ctx); void (*destroy)(struct drm_plane *plane); void (*reset)(struct drm_plane *plane); int (*set_property)(struct drm_plane *plane, struct drm_property *property, uint64_t val); struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane); void (*atomic_destroy_state)(struct drm_plane *plane, struct drm_plane_state *state); int (*atomic_set_property)(struct drm_plane *plane, struct drm_plane_state *state, struct drm_property *property, uint64_t val); int (*atomic_get_property)(struct drm_plane *plane, const struct drm_plane_state *state, struct drm_property *property, uint64_t *val); int (*late_register)(struct drm_plane *plane); void (*early_unregister)(struct drm_plane *plane); void (*atomic_print_state)(struct drm_printer *p, const struct drm_plane_state *state); bool (*format_mod_supported)(struct drm_plane *plane, uint32_t format, uint64_t modifier); bool (*format_mod_supported_async)(struct drm_plane *plane, u32 format, u64 modifier);};Members
update_planeThis is the legacy entry point to enable and configure the plane forthe given CRTC and framebuffer. It is never called to disable theplane, i.e. the passed-in crtc and fb paramters are never NULL.
The source rectangle in frame buffer memory coordinates is given bythe src_x, src_y, src_w and src_h parameters (as 16.16 fixed pointvalues). Devices that don’t support subpixel plane coordinates canignore the fractional part.
The destination rectangle in CRTC coordinates is given by thecrtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).Devices scale the source rectangle to the destination rectangle. Ifscaling is not supported, and the source rectangle size doesn’t matchthe destination rectangle size, the driver must return a-<errorname>EINVAL</errorname> error.
Drivers implementing atomic modeset should use
drm_atomic_helper_update_plane()to implement this hook.RETURNS:
0 on success or a negative error code on failure.
disable_planeThis is the legacy entry point to disable the plane. The DRM corecalls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL callwith the frame buffer ID set to 0. Disabled planes must not beprocessed by the CRTC.
Drivers implementing atomic modeset should use
drm_atomic_helper_disable_plane()to implement this hook.RETURNS:
0 on success or a negative error code on failure.
destroyClean up plane resources. This is only called at driver unload timethrough
drm_mode_config_cleanup()since a plane cannot be hotpluggedin DRM.resetReset plane hardware and software state to off. This function isn’tcalled by the core directly, only through
drm_mode_config_reset().It’s not a helper hook only for historical reasons.Atomic drivers can use
drm_atomic_helper_plane_reset()to resetatomic state using this hook.set_propertyThis is the legacy entry point to update a property attached to theplane.
This callback is optional if the driver does not support any legacydriver-private properties. For atomic drivers it is not used becauseproperty handling is done entirely in the DRM core.
RETURNS:
0 on success or a negative error code on failure.
atomic_duplicate_stateDuplicate the current atomic state for this plane and return it.The core and helpers guarantee that any atomic state duplicated withthis hook and still owned by the caller (i.e. not transferred to thedriver by calling
drm_mode_config_funcs.atomic_commit) will becleaned up by calling theatomic_destroy_state hook in thisstructure.This callback is mandatory for atomic drivers.
Atomic drivers which don’t subclass
structdrm_plane_stateshould usedrm_atomic_helper_plane_duplicate_state(). Drivers that subclass thestate structure to extend it with driver-private state should use__drm_atomic_helper_plane_duplicate_state()to make sure shared state isduplicated in a consistent fashion across drivers.It is an error to call this hook before
drm_plane.statehas beeninitialized correctly.NOTE:
If the duplicate state references refcounted resources this hook mustacquire a reference for each of them. The driver must release thesereferences again inatomic_destroy_state.
RETURNS:
Duplicated atomic state or NULL when the allocation failed.
atomic_destroy_stateDestroy a state duplicated withatomic_duplicate_state and releaseor unreference all resources it references
This callback is mandatory for atomic drivers.
atomic_set_propertyDecode a driver-private property value and store the decoded valueinto the passed-in state structure. Since the atomic core decodes allstandardized properties (even for extensions beyond the core set ofproperties which might not be implemented by all drivers) thisrequires drivers to subclass the state structure.
Such driver-private properties should really only be implemented fortruly hardware/vendor specific state. Instead it is preferred tostandardize atomic extension and decode the properties used to exposesuch an extension in the core.
Do not call this function directly, use
drm_atomic_plane_set_property()instead.This callback is optional if the driver does not support anydriver-private atomic properties.
NOTE:
This function is called in the state assembly phase of atomicmodesets, which can be aborted for any reason (including onuserspace’s request to just check whether a configuration would bepossible). Drivers MUST NOT touch any persistent state (hardware orsoftware) or data structures except the passed instate parameter.
Also since userspace controls in which order properties are set thisfunction must not do any input validation (since the state update isincomplete and hence likely inconsistent). Instead any such inputvalidation must be done in the various atomic_check callbacks.
RETURNS:
0 if the property has been found, -EINVAL if the property isn’timplemented by the driver (which shouldn’t ever happen, the core onlyasks for properties attached to this plane). No other validation isallowed by the driver. The core already checks that the propertyvalue is within the range (integer, valid
enumvalue, ...) the driverset when registering the property.atomic_get_propertyReads out the decoded driver-private property. This is used toimplement the GETPLANE IOCTL.
Do not call this function directly, use
drm_atomic_plane_get_property()instead.This callback is optional if the driver does not support anydriver-private atomic properties.
RETURNS:
0 on success, -EINVAL if the property isn’t implemented by thedriver (which should never happen, the core only asks forproperties attached to this plane).
late_registerThis optional hook can be used to register additional userspaceinterfaces attached to the plane like debugfs interfaces.It is called late in the driver load sequence from
drm_dev_register().Everything added from this callback should be unregistered inthe early_unregister callback.Returns:
0 on success, or a negative error code on failure.
early_unregisterThis optional hook should be used to unregister the additionaluserspace interfaces attached to the plane fromlate_register. It is called from
drm_dev_unregister(),early in the driver unload sequence to disable userspace accessbefore data structures are torndown.atomic_print_stateIf driver subclasses
structdrm_plane_state, it should implementthis optional hook for printing additional driver specific state.Do not call this directly, use
drm_atomic_plane_print_state()instead.format_mod_supportedThis optional hook is used for the DRM to determine if the givenformat/modifier combination is valid for the plane. This allows theDRM to generate the correct format bitmask (which formats apply towhich modifier), and to validate modifiers at atomic_check time.
If not present, then any modifier in the plane’s modifierlist is allowed with any of the plane’s formats.
Returns:
True if the given modifier is valid for that format on the plane.False otherwise.
format_mod_supported_asyncThis optional hook is used for the DRM to determine if forasynchronous flip the given format/modifier combination is valid forthe plane. This allows the DRM to generate the correct formatbitmask (which formats apply to which modifier), and to validatemodifiers at atomic_check time.
Returns:
True if the given modifier is valid for that format on the plane.False otherwise.
- enumdrm_plane_type¶
uapi plane type enumeration
Constants
DRM_PLANE_TYPE_OVERLAYOverlay planes represent all non-primary, non-cursor planes. Somedrivers refer to these types of planes as “sprites” internally.
DRM_PLANE_TYPE_PRIMARYA primary plane attached to a CRTC is the most likely to be able tolight up the CRTC when no scaling/cropping is used and the planecovers the whole CRTC.
DRM_PLANE_TYPE_CURSORA cursor plane attached to a CRTC is more likely to be able to beenabled when no scaling/cropping is used and the framebuffer has thesize indicated by
drm_mode_config.cursor_widthanddrm_mode_config.cursor_height. Additionally, if the driver doesn’tsupport modifiers, the framebuffer should have a linear layout.
Description
For historical reasons not all planes are made the same. This enumeration isused to tell the different types of planes apart to implement the differentuapi semantics for them. For userspace which is universal plane aware andwhich is using that atomic IOCTL there’s no difference between these planes(beyong what the driver and hardware can support of course).
For compatibility with legacy userspace, only overlay planes are madeavailable to userspace by default. Userspace clients may set theDRM_CLIENT_CAP_UNIVERSAL_PLANES client capability bit to indicate that theywish to receive a universal plane list containing all plane types. See alsodrm_for_each_legacy_plane().
In addition to setting each plane’s type, drivers need to setup thedrm_crtc.primary and optionallydrm_crtc.cursor pointers for legacyIOCTLs. Seedrm_crtc_init_with_planes().
WARNING: The values of thisenumis UABI since they’re exposed in the “type”property.
- structdrm_plane¶
central DRM plane control structure
Definition:
struct drm_plane { struct drm_device *dev; struct list_head head; char *name; struct drm_modeset_lock mutex; struct drm_mode_object base; uint32_t possible_crtcs; uint32_t *format_types; unsigned int format_count; bool format_default; uint64_t *modifiers; unsigned int modifier_count; struct drm_crtc *crtc; struct drm_framebuffer *fb; struct drm_framebuffer *old_fb; const struct drm_plane_funcs *funcs; struct drm_object_properties properties; enum drm_plane_type type; unsigned index; const struct drm_plane_helper_funcs *helper_private; struct drm_plane_state *state; struct drm_property *alpha_property; struct drm_property *zpos_property; struct drm_property *rotation_property; struct drm_property *blend_mode_property; struct drm_property *color_encoding_property; struct drm_property *color_range_property; struct drm_property *color_pipeline_property; struct drm_property *scaling_filter_property; struct drm_property *hotspot_x_property; struct drm_property *hotspot_y_property; struct kmsg_dumper kmsg_panic;};Members
devDRM device this plane belongs to
headList of all planes ondev, linked from
drm_mode_config.plane_list.Invariant over the lifetime ofdev and therefore does not needlocking.namehuman readable name, can be overwritten by the driver
mutexProtects modeset plane state, together with the
drm_crtc.mutexofCRTC this plane is linked to (when active, getting activated orgetting disabled).For atomic drivers specifically this protectsstate.
basebase mode object
possible_crtcspipes this plane can be bound to constructed from
drm_crtc_mask()format_typesarray of formats supported by this plane
format_countSize of the array pointed at byformat_types.
format_defaultdriver hasn’t supplied supported formats for theplane. Used by the non-atomic driver compatibility wrapper only.
modifiersarray of modifiers supported by this plane
modifier_countSize of the array pointed at bymodifier_count.
crtcCurrently bound CRTC, only meaningful for non-atomic drivers. Foratomic drivers this is forced to be NULL, atomic drivers shouldinstead check
drm_plane_state.crtc.fbCurrently bound framebuffer, only meaningful for non-atomic drivers.For atomic drivers this is forced to be NULL, atomic drivers shouldinstead check
drm_plane_state.fb.old_fbTemporary tracking of the old fb while a modeset is ongoing. Onlyused by non-atomic drivers, forced to be NULL for atomic drivers.
funcsplane control functions
propertiesproperty tracking for this plane
typeType of plane, see
enumdrm_plane_typefor details.indexPosition inside the mode_config.list, can be used as an arrayindex. It is invariant over the lifetime of the plane.
helper_privatemid-layer private data
stateCurrent atomic state for this plane.
This is protected bymutex. Note that nonblocking atomic commitsaccess the current plane state without taking locks. Either by goingthrough the
structdrm_atomic_statepointers, seefor_each_oldnew_plane_in_state(),for_each_old_plane_in_state()andfor_each_new_plane_in_state(). Or through careful ordering of atomiccommit operations as implemented in the atomic helpers, seestructdrm_crtc_commit.alpha_propertyOptional alpha property for this plane. See
drm_plane_create_alpha_property().zpos_propertyOptional zpos property for this plane. See
drm_plane_create_zpos_property().rotation_propertyOptional rotation property for this plane. See
drm_plane_create_rotation_property().blend_mode_propertyOptional “pixel blend mode”
enumpropertyfor this plane.Blend mode property represents the alpha blending equation selection,describing how the pixels from the current plane are composited withthe background.color_encoding_propertyOptional “COLOR_ENCODING”
enumpropertyfor specifyingcolor encoding for non RGB formats.Seedrm_plane_create_color_properties().color_range_propertyOptional “COLOR_RANGE”
enumpropertyfor specifyingcolor range for non RGB formats.Seedrm_plane_create_color_properties().color_pipeline_propertyOptional “COLOR_PIPELINE”
enumpropertyfor specifyinga color pipeline to use on the plane.scaling_filter_propertyproperty to apply a particular filter whilescaling.
hotspot_x_propertyproperty to set mouse hotspot x offset.
hotspot_y_propertyproperty to set mouse hotspot y offset.
kmsg_panicUsed to register a panic notifier for this plane
Description
Planes represent the scanout hardware of a display block. They receive theirinput data from adrm_framebuffer and feed it to adrm_crtc. Planes controlthe color conversion, seePlane Composition Properties for more details,and are also involved in the color conversion of input pixels, seeColorManagement Properties for details on that.
- drmm_universal_plane_alloc¶
drmm_universal_plane_alloc(dev,type,member,possible_crtcs,funcs,formats,format_count,format_modifiers,plane_type,name,...)
Allocate and initialize an universal plane object
Parameters
devDRM device
typethe type of the
structwhichcontains structdrm_planememberthe name of the
drm_planewithintypepossible_crtcsbitmask of possible CRTCs
funcscallbacks for the new plane
formatsarray of supported formats (DRM_FORMAT_*)
format_countnumber of elements informats
format_modifiersarray of
structdrm_formatmodifiers terminated byDRM_FORMAT_MOD_INVALIDplane_typetype of plane (overlay, primary, cursor)
nameprintf style format string for the plane name, or NULL for default name
...variable arguments
Description
Allocates and initializes a plane object of typetype. Cleanup isautomatically handled through registeringdrm_plane_cleanup() withdrmm_add_action().
Thedrm_plane_funcs.destroy hook must be NULL.
Drivers that only support the DRM_FORMAT_MOD_LINEAR modifier support may setformat_modifiers to NULL. The plane will advertise the linear modifier.
Return
Pointer to new plane, or ERR_PTR on failure.
- drm_universal_plane_alloc¶
drm_universal_plane_alloc(dev,type,member,possible_crtcs,funcs,formats,format_count,format_modifiers,plane_type,name,...)
Allocate and initialize an universal plane object
Parameters
devDRM device
typethe type of the
structwhichcontains structdrm_planememberthe name of the
drm_planewithintypepossible_crtcsbitmask of possible CRTCs
funcscallbacks for the new plane
formatsarray of supported formats (DRM_FORMAT_*)
format_countnumber of elements informats
format_modifiersarray of
structdrm_formatmodifiers terminated byDRM_FORMAT_MOD_INVALIDplane_typetype of plane (overlay, primary, cursor)
nameprintf style format string for the plane name, or NULL for default name
...variable arguments
Description
Allocates and initializes a plane object of typetype. The calleris responsible for releasing the allocated memory withkfree().
Drivers are encouraged to usedrmm_universal_plane_alloc() instead.
Drivers that only support the DRM_FORMAT_MOD_LINEAR modifier support may setformat_modifiers to NULL. The plane will advertise the linear modifier.
Return
Pointer to new plane, or ERR_PTR on failure.
Parameters
conststructdrm_plane*planeplane to find index for
Description
Given a registered plane, return the index of that plane within a DRMdevice’s list of planes.
Parameters
conststructdrm_plane*planeplane to find mask for
- structdrm_plane*drm_plane_find(structdrm_device*dev,structdrm_file*file_priv,uint32_tid)¶
find a
drm_plane
Parameters
structdrm_device*devDRM device
structdrm_file*file_privdrm file to check for lease against.
uint32_tidplane id
Description
Returns the plane withid, NULL if it doesn’t exist. Simple wrapper arounddrm_mode_object_find().
- drm_for_each_plane_mask¶
drm_for_each_plane_mask(plane,dev,plane_mask)
iterate over planes specified by bitmask
Parameters
planethe loop cursor
devthe DRM device
plane_maskbitmask of plane indices
Description
Iterate over all planes specified by bitmask.
- drm_for_each_legacy_plane¶
drm_for_each_legacy_plane(plane,dev)
iterate over all planes for legacy userspace
Parameters
planethe loop cursor
devthe DRM device
Description
Iterate over all legacy planes ofdev, excluding primary and cursor planes.This is useful for implementing userspace apis when userspace is notuniversal plane aware. See alsoenumdrm_plane_type.
- drm_for_each_plane¶
drm_for_each_plane(plane,dev)
iterate over all planes
Parameters
planethe loop cursor
devthe DRM device
Description
Iterate over all planes ofdev, include primary and cursor planes.
- intdrm_universal_plane_init(structdrm_device*dev,structdrm_plane*plane,uint32_tpossible_crtcs,conststructdrm_plane_funcs*funcs,constuint32_t*formats,unsignedintformat_count,constuint64_t*format_modifiers,enumdrm_plane_typetype,constchar*name,...)¶
Initialize a new universal plane object
Parameters
structdrm_device*devDRM device
structdrm_plane*planeplane object to init
uint32_tpossible_crtcsbitmask of possible CRTCs
conststructdrm_plane_funcs*funcscallbacks for the new plane
constuint32_t*formatsarray of supported formats (DRM_FORMAT_*)
unsignedintformat_countnumber of elements informats
constuint64_t*format_modifiersarray of
structdrm_formatmodifiers terminated byDRM_FORMAT_MOD_INVALIDenumdrm_plane_typetypetype of plane (overlay, primary, cursor)
constchar*nameprintf style format string for the plane name, or NULL for default name
...variable arguments
Description
Initializes a plane object of typetype. Thedrm_plane_funcs.destroy hookshould calldrm_plane_cleanup() andkfree() the plane structure. The planestructure should not be allocated withdevm_kzalloc().
Note
consider usingdrmm_universal_plane_alloc() instead ofdrm_universal_plane_init() to let the DRM managed resource infrastructuretake care of cleanup and deallocation.
Drivers that only support the DRM_FORMAT_MOD_LINEAR modifier support may setformat_modifiers to NULL. The plane will advertise the linear modifier.
Return
Zero on success, error code on failure.
Parameters
structdrm_plane*planeplane to cleanup
Description
This function cleans upplane and removes it from the DRM mode settingcore. Note that the function doesnot free the plane structure itself,this is the responsibility of the caller.
- structdrm_plane*drm_plane_from_index(structdrm_device*dev,intidx)¶
find the registered plane at an index
Parameters
structdrm_device*devDRM device
intidxindex of registered plane to find for
Description
Given a plane index, return the registered plane from DRM device’slist of planes with matching index. This is the inverse ofdrm_plane_index().
Parameters
structdrm_plane*planeplane to disable
Description
Forces the plane to be disabled.
Used when the plane’s current framebuffer is destroyed,and when restoring fbdev mode.
Note that this function is not suitable for atomic drivers, since it doesn’twire through the lock acquisition context properly and hence can’t handleretries or driver private locks. You probably want to usedrm_atomic_helper_disable_plane() ordrm_atomic_helper_disable_planes_on_crtc() instead.
- intdrm_mode_plane_set_obj_prop(structdrm_plane*plane,structdrm_property*property,uint64_tvalue)¶
set the value of a property
Parameters
structdrm_plane*planedrm plane object to set property value for
structdrm_property*propertyproperty to set
uint64_tvaluevalue the property should be set to
Description
This functions sets a given property on a given plane object. This functioncalls the driver’s ->set_property callback and changes the software state ofthe property if the callback succeeds.
Return
Zero on success, error code on failure.
- booldrm_plane_has_format(structdrm_plane*plane,u32format,u64modifier)¶
Check whether the plane supports this format and modifier combination
Parameters
structdrm_plane*planedrm plane
u32formatpixel format (DRM_FORMAT_*)
u64modifierdata layout modifier
Return
Whether the plane supports the specified format and modifier combination.
- booldrm_any_plane_has_format(structdrm_device*dev,u32format,u64modifier)¶
Check whether any plane supports this format and modifier combination
Parameters
structdrm_device*devDRM device
u32formatpixel format (DRM_FORMAT_*)
u64modifierdata layout modifier
Return
Whether at least one plane supports the specified format and modifier combination.
Parameters
structdrm_plane*planePlane on which to enable damage clips property.
Description
This function lets driver to enable the damage clips property on a plane.
- unsignedintdrm_plane_get_damage_clips_count(conststructdrm_plane_state*state)¶
Returns damage clips count.
Parameters
conststructdrm_plane_state*statePlane state.
Description
Simple helper to get the number ofdrm_mode_rect clips set by user-spaceduring plane update.
Return
Number of clips in plane fb_damage_clips blob property.
- structdrm_mode_rect*drm_plane_get_damage_clips(conststructdrm_plane_state*state)¶
Returns damage clips.
Parameters
conststructdrm_plane_state*statePlane state.
Description
Note that this function returns uapi typedrm_mode_rect. Drivers might wantto use the helper functionsdrm_atomic_helper_damage_iter_init() anddrm_atomic_helper_damage_iter_next() ordrm_atomic_helper_damage_merged() ifthe driver can only handle a single damage region at most.
Return
Damage clips in plane fb_damage_clips blob property.
- intdrm_plane_create_scaling_filter_property(structdrm_plane*plane,unsignedintsupported_filters)¶
create a new scaling filter property
Parameters
structdrm_plane*planedrm plane
unsignedintsupported_filtersbitmask of supported scaling filters, must includeBIT(DRM_SCALING_FILTER_DEFAULT).
Description
This function lets driver to enable the scaling filter property on a givenplane.
Return
Zero for success or -errno
- intdrm_plane_add_size_hints_property(structdrm_plane*plane,conststructdrm_plane_size_hint*hints,intnum_hints)¶
create a size hints property
Parameters
structdrm_plane*planedrm plane
conststructdrm_plane_size_hint*hintssize hints
intnum_hintsnumber of size hints
Description
Create a size hints property for the plane.
Return
Zero for success or -errno
- intdrm_plane_create_color_pipeline_property(structdrm_plane*plane,conststructdrm_prop_enum_list*pipelines,intnum_pipelines)¶
create a new color pipeline property
Parameters
structdrm_plane*planedrm plane
conststructdrm_prop_enum_list*pipelineslist of pipelines
intnum_pipelinesnumber of pipelines
Description
Create the COLOR_PIPELINE plane property to specific color pipelines onthe plane.
Return
Zero for success or -errno
Plane Composition Functions Reference¶
Parameters
structdrm_plane*planedrm plane
Description
This function creates a generic, mutable, alpha property and enables supportfor it in the DRM core. It is attached toplane.
The alpha property will be allowed to be within the bounds of 0(transparent) to 0xffff (opaque).
Return
0 on success, negative error code on failure.
- intdrm_plane_create_rotation_property(structdrm_plane*plane,unsignedintrotation,unsignedintsupported_rotations)¶
create a new rotation property
Parameters
structdrm_plane*planedrm plane
unsignedintrotationinitial value of the rotation property
unsignedintsupported_rotationsbitmask of supported rotations and reflections
Description
This creates a new property with the selected support for transformations.
Since a rotation by 180° degress is the same as reflecting both along the xand the y axis the rotation property is somewhat redundant. Drivers can usedrm_rotation_simplify() to normalize values of this property.
The property exposed to userspace is a bitmask property (seedrm_property_create_bitmask()) called “rotation” and has the followingbitmask enumaration values:
- DRM_MODE_ROTATE_0:
“rotate-0”
- DRM_MODE_ROTATE_90:
“rotate-90”
- DRM_MODE_ROTATE_180:
“rotate-180”
- DRM_MODE_ROTATE_270:
“rotate-270”
- DRM_MODE_REFLECT_X:
“reflect-x”
- DRM_MODE_REFLECT_Y:
“reflect-y”
Rotation is the specified amount in degrees in counter clockwise direction,the X and Y axis are within the source rectangle, i.e. the X/Y axis beforerotation. After reflection, the rotation is applied to the image sampled fromthe source rectangle, before scaling it to fit the destination rectangle.
- unsignedintdrm_rotation_simplify(unsignedintrotation,unsignedintsupported_rotations)¶
Try to simplify the rotation
Parameters
unsignedintrotationRotation to be simplified
unsignedintsupported_rotationsSupported rotations
Description
Attempt to simplify the rotation to a form that is supported.Eg. if the hardware supports everything except DRM_MODE_REFLECT_Xone could call this function like this:
- drm_rotation_simplify(rotation, DRM_MODE_ROTATE_0 |
DRM_MODE_ROTATE_90 | DRM_MODE_ROTATE_180 |DRM_MODE_ROTATE_270 | DRM_MODE_REFLECT_Y);
to eliminate the DRM_MODE_REFLECT_X flag. Depending on what kind oftransforms the hardware supports, this function may notbe able to produce a supported transform, so the caller shouldcheck the result afterwards.
- intdrm_plane_create_zpos_property(structdrm_plane*plane,unsignedintzpos,unsignedintmin,unsignedintmax)¶
create mutable zpos property
Parameters
structdrm_plane*planedrm plane
unsignedintzposinitial value of zpos property
unsignedintminminimal possible value of zpos property
unsignedintmaxmaximal possible value of zpos property
Description
This function initializes generic mutable zpos property and enables supportfor it in drm core. Drivers can then attach this property to planes to enablesupport for configurable planes arrangement during blending operation.Drivers that attach a mutable zpos property to any plane should call thedrm_atomic_normalize_zpos() helper during their implementation ofdrm_mode_config_funcs.atomic_check(), which will update the normalized zposvalues and store them indrm_plane_state.normalized_zpos. Usually minshould be set to 0 and max to maximal number of planes for given crtc - 1.
If zpos of some planes cannot be changed (like fixed background orcursor/topmost planes), drivers shall adjust the min/max values and assignthose planes immutable zpos properties with lower or higher values (for moreinformation, seedrm_plane_create_zpos_immutable_property() function). In suchcase drivers shall also assign proper initial zpos values for all planes initsplane_reset() callback, so the planes will be always sorted properly.
See alsodrm_atomic_normalize_zpos().
The property exposed to userspace is called “zpos”.
Return
Zero on success, negative errno on failure.
- intdrm_plane_create_zpos_immutable_property(structdrm_plane*plane,unsignedintzpos)¶
create immuttable zpos property
Parameters
structdrm_plane*planedrm plane
unsignedintzposvalue of zpos property
Description
This function initializes generic immutable zpos property and enablessupport for it in drm core. Using this property driver lets userspaceto get the arrangement of the planes for blending operation and notifiesit that the hardware (or driver) doesn’t support changing of the planes’order. For mutable zpos seedrm_plane_create_zpos_property().
The property exposed to userspace is called “zpos”.
Return
Zero on success, negative errno on failure.
- intdrm_atomic_normalize_zpos(structdrm_device*dev,structdrm_atomic_state*state)¶
calculate normalized zpos values for all crtcs
Parameters
structdrm_device*devDRM device
structdrm_atomic_state*stateatomic state of DRM device
Description
This function calculates normalized zpos value for all modified planes inthe provided atomic state of DRM device.
For every CRTC this function checks new states of all planes assigned toit and calculates normalized zpos value for these planes. Planes are comparedfirst by their zpos values, then by plane id (if zpos is equal). The planewith lowest zpos value is at the bottom. Thedrm_plane_state.normalized_zposis then filled with unique values from 0 to number of active planes in crtcminus one.
RETURNSZero for success or -errno
- intdrm_plane_create_blend_mode_property(structdrm_plane*plane,unsignedintsupported_modes)¶
create a new blend mode property
Parameters
structdrm_plane*planedrm plane
unsignedintsupported_modesbitmask of supported modes, must includeBIT(DRM_MODE_BLEND_PREMULTI). Current DRM assumption isthat alpha is premultiplied, and old userspace can break ifthe property defaults to anything else.
Description
This creates a new property describing the blend mode.
The property exposed to userspace is an enumeration property (seedrm_property_create_enum()) called “pixel blend mode” and has thefollowing enumeration values:
- “None”:
Blend formula that ignores the pixel alpha.
- “Pre-multiplied”:
Blend formula that assumes the pixel color values have been alreadypre-multiplied with the alpha channel values.
- “Coverage”:
Blend formula that assumes the pixel color values have not beenpre-multiplied and will do so when blending them to the background colorvalues.
Return
Zero for success or -errno
Plane Damage Tracking Functions Reference¶
- voiddrm_atomic_helper_check_plane_damage(structdrm_atomic_state*state,structdrm_plane_state*plane_state)¶
Verify plane damage on atomic_check.
Parameters
structdrm_atomic_state*stateThe driver state object.
structdrm_plane_state*plane_statePlane state for which to verify damage.
Description
This helper function makes sure that damage from plane state is discardedfor full modeset. If there are more reasons a driver would want to do a fullplane update rather than processing individual damage regions, then thosecases should be taken care of here.
Note thatdrm_plane_state.fb_damage_clips == NULL in plane state means thatfull plane update should happen. It also ensure helper iterator will returndrm_plane_state.src as damage.
- intdrm_atomic_helper_dirtyfb(structdrm_framebuffer*fb,structdrm_file*file_priv,unsignedintflags,unsignedintcolor,structdrm_clip_rect*clips,unsignedintnum_clips)¶
Helper for dirtyfb.
Parameters
structdrm_framebuffer*fbDRM framebuffer.
structdrm_file*file_privDrm file for the ioctl call.
unsignedintflagsDirty fb annotate flags.
unsignedintcolorColor for annotate fill.
structdrm_clip_rect*clipsDirty region.
unsignedintnum_clipsCount of clip in clips.
Description
A helper to implementdrm_framebuffer_funcs.dirty using damage interfaceduring plane update. If num_clips is 0 then this helper will do a full planeupdate. This is the same behaviour expected by DIRTFB IOCTL.
Note that this helper is blocking implementation. This is what currentdrivers and userspace expect in their DIRTYFB IOCTL implementation, as a wayto rate-limit userspace and make sure its rendering doesn’t get ahead ofuploading new data too much.
Return
Zero on success, negative errno on failure.
- voiddrm_atomic_helper_damage_iter_init(structdrm_atomic_helper_damage_iter*iter,conststructdrm_plane_state*old_state,conststructdrm_plane_state*state)¶
Initialize the damage iterator.
Parameters
structdrm_atomic_helper_damage_iter*iterThe iterator to initialize.
conststructdrm_plane_state*old_stateOld plane state for validation.
conststructdrm_plane_state*statePlane state from which to iterate the damage clips.
Description
Initialize an iterator, which clips plane damagedrm_plane_state.fb_damage_clips to planedrm_plane_state.src. This iteratorreturns full plane src in case damage is not present because eitheruser-space didn’t sent or driver discarded it (it want to do full planeupdate). Currently this iterator returns full plane src in case plane srcchanged but that can be changed in future to return damage.
For the case when plane is not visible or plane update should not happen thefirst call to iter_next will return false. Note that this helper use clippeddrm_plane_state.src, so driver calling this helper should have calleddrm_atomic_helper_check_plane_state() earlier.
- booldrm_atomic_helper_damage_iter_next(structdrm_atomic_helper_damage_iter*iter,structdrm_rect*rect)¶
Advance the damage iterator.
Parameters
structdrm_atomic_helper_damage_iter*iterThe iterator to advance.
structdrm_rect*rectReturn a rectangle in fb coordinate clipped to plane src.
Description
Since plane src is in 16.16 fixed point and damage clips are whole number,this iterator round off clips that intersect with plane src. Round down forx1/y1 and round up for x2/y2 for the intersected coordinate. Similar roundingoff for full plane src, in case it’s returned as damage. This iterator willskip damage clips outside of plane src.
If the first call to iterator next returns false then it means no need toupdate the plane.
Return
True if the output is valid, false if reached the end.
- booldrm_atomic_helper_damage_merged(conststructdrm_plane_state*old_state,conststructdrm_plane_state*state,structdrm_rect*rect)¶
Merged plane damage
Parameters
conststructdrm_plane_state*old_stateOld plane state for validation.
conststructdrm_plane_state*statePlane state from which to iterate the damage clips.
structdrm_rect*rectReturns the merged damage rectangle
Description
This function merges any valid plane damage clips into one rectangle andreturns it inrect.
For details see:drm_atomic_helper_damage_iter_init() anddrm_atomic_helper_damage_iter_next().
Return
True if there is valid plane damage otherwise false.
- drm_atomic_for_each_plane_damage¶
drm_atomic_for_each_plane_damage(iter,rect)
Iterator macro for plane damage.
Parameters
iterThe iterator to advance.
rectReturn a rectangle in fb coordinate clipped to plane src.
Description
Note that if the first call to iterator macro return false then no need to doplane update. Iterator will return full plane src when damage is not passedby user-space.
- structdrm_atomic_helper_damage_iter¶
Closure structure for damage iterator.
Definition:
struct drm_atomic_helper_damage_iter {};Members
Description
This structure tracks state needed to walk the list of plane damage clips.
Plane Panic Feature¶
To enable DRM panic for a driver, the primary plane must implement adrm_plane_helper_funcs.get_scanout_buffer helper function. It is thenautomatically registered to the drm panic handler.When a panic occurs, thedrm_plane_helper_funcs.get_scanout_buffer will becalled, and the driver can provide a framebuffer so the panic handler candraw the panic screen on it. Currently only linear buffer and a few colorformats are supported.Optionally the driver can also provide adrm_plane_helper_funcs.panic_flushcallback, that will be called after that, to send additional commands to thehardware to make the scanout buffer visible.
Plane Panic Functions Reference¶
- structdrm_scanout_buffer¶
DRM scanout buffer
Definition:
struct drm_scanout_buffer { const struct drm_format_info *format; struct iosys_map map[DRM_FORMAT_MAX_PLANES]; struct page **pages; unsigned int width; unsigned int height; unsigned int pitch[DRM_FORMAT_MAX_PLANES]; void (*set_pixel)(struct drm_scanout_buffer *sb, unsigned int x, unsigned int y, u32 color); void *private;};Members
formatdrm format of the scanout buffer.
mapVirtual address of the scanout buffer, either in memory or iomem.The scanout buffer should be in linear format, and can be directlysent to the display hardware. Tearing is not an issue for the panicscreen.
pagesOptional, if the scanout buffer is not mapped, set this fieldto the array of pages of the scanout buffer. The panic code will use
kmap_local_page_try_from_panic()to map one page at a time to writeall the pixels. This array shouldn’t be allocated from theget_scanoutbuffer()callback.The scanout buffer should be in linear format.widthWidth of the scanout buffer, in pixels.
heightHeight of the scanout buffer, in pixels.
pitchLength in bytes between the start of two consecutive lines.
set_pixelOptional function, to set a pixel color on theframebuffer. It allows to handle special tiling format inside thedriver. It takes precedence over themap andpages fields.
privateprivate pointer that you can use in the callbacks
set_pixel()
Description
This structure holds the information necessary for drm_panic to draw thepanic screen, and display it.
- drm_panic_trylock¶
drm_panic_trylock(dev,flags)
try to enter the panic printing critical section
Parameters
devflagsunsigned long irq flags you need to pass to the
unlock()counterpart
Description
This function must be called by any panic printing code. The panic printingattempt must be aborted if the trylock fails.
Panic printing code can make the following assumptions while holding thepanic lock:
Anything protected by
drm_panic_lock()anddrm_panic_unlock()pairs is safeto access.Furthermore the panic printing code only registers in
drm_dev_unregister()and gets removed indrm_dev_unregister(). This allows the panic code tosafely access any state which is invariant in between these two functioncalls, like the list of planesdrm_mode_config.plane_listor most of thestructdrm_planestructure.
Specifically thanks to the protection around plane updates indrm_atomic_helper_swap_state() the following additional guarantees hold:
It is safe to deference the drm_plane.state pointer.
Anything in
structdrm_plane_stateor the driver’s subclass thereof whichstays invariant after the atomic check code has finished is safe to access.Specifically this includes the reference counted pointers to framebufferand buffer objects.Anything set up by
drm_plane_helper_funcs.fb_prepareand cleaned updrm_plane_helper_funcs.fb_cleanupis safe to access, as long as it staysinvariant between these two calls. This also means that for drivers usingdynamic buffer management the framebuffer is pinned, and therefer allrelevant datastructures can be accessed without taking any further locks(which would be impossible in panic context anyway).Importantly, software and hardware state set up by
drm_plane_helper_funcs.begin_fb_accessanddrm_plane_helper_funcs.end_fb_accessis not safe to access.
Drivers must not make any assumptions about the actual state of the hardware,unless they explicitly protected these hardware access withdrm_panic_lock()anddrm_panic_unlock().
Return
0 when failing to acquire the raw spinlock, nonzero on success.
- drm_panic_lock¶
drm_panic_lock(dev,flags)
protect panic printing relevant state
Parameters
devflagsunsigned long irq flags you need to pass to the
unlock()counterpart
Description
This function must be called to protect software and hardware state that thepanic printing code must be able to rely on. The protected sections must beas small as possible. It uses the irqsave/irqrestore variant, and can becalled from irq handler. Examples include:
Access to peek/poke or other similar registers, if that is the way thedriver prints the pixels into the scanout buffer at panic time.
Updates to pointers like
drm_plane.state, allowing the panic handler tosafely deference these. This is done indrm_atomic_helper_swap_state().An state that isn’t invariant and that the driver must be able to accessduring panic printing.
- drm_panic_unlock¶
drm_panic_unlock(dev,flags)
end of the panic printing critical section
Parameters
devflagsirq flags that were returned when acquiring the lock
Description
Unlocks the raw spinlock acquired by eitherdrm_panic_lock() ordrm_panic_trylock().
- booldrm_panic_is_enabled(structdrm_device*dev)¶
Parameters
structdrm_device*devthe drm device that may supports drm_panic
Description
returns true if the drm device supports drm_panic
Colorop Abstraction¶
When userspace signals theDRM_CLIENT_CAP_PLANE_COLOR_PIPELINE itshould use the COLOR_PIPELINE plane property and associated coloropsfor any color operation on thedrm_plane. Setting of all old colorproperties, such as COLOR_ENCODING and COLOR_RANGE, will be rejectedand the values of the properties will be ignored.
Colorops are only advertised and valid for atomic drivers and atomicuserspace that signals theDRM_CLIENT_CAP_PLANE_COLOR_PIPELINEclient cap.
A colorop represents a single color operation. Colorops are chainedvia the NEXT property and make up color pipelines. Color pipelinesare advertised and selected via the COLOR_PIPELINEdrm_planeproperty.
A colorop will be of a certain type, advertised by the read-only TYPEproperty. Each type of colorop will advertise a different set ofproperties and is programmed in a different manner. Types can beenumerated 1D curves, 1D LUTs, 3D LUTs, matrices, etc. See thedrm_colorop_type documentation for information on each type.
If a colorop advertises the BYPASS property it can be bypassed.
Information about colorop and color pipeline design decisions can befound atLinux Color Pipeline API, but note that this document willgrow stale over time.
Colorop Functions Reference¶
- enumdrm_colorop_curve_1d_type¶
type of 1D curve
Constants
DRM_COLOROP_1D_CURVE_SRGB_EOTFenumstring“sRGB EOTF”sRGB piece-wise electro-optical transfer function. Transfercharacteristics as defined by IEC 61966-2-1 sRGB. Equivalentto H.273 TransferCharacteristics code point 13 withMatrixCoefficients set to 0.
DRM_COLOROP_1D_CURVE_SRGB_INV_EOTFenumstring“sRGB Inverse EOTF”The inverse of
DRM_COLOROP_1D_CURVE_SRGB_EOTFDRM_COLOROP_1D_CURVE_PQ_125_EOTFenumstring“PQ 125 EOTF”The PQ transfer function, scaled by 125.0f, so that 10,000nits correspond to 125.0f.
Transfer characteristics of the PQ function as defined bySMPTE ST 2084 (2014) for 10-, 12-, 14-, and 16-bit systemsand Rec. ITU-R BT.2100-2 perceptual quantization (PQ) system,represented by H.273 TransferCharacteristics code point 16.
DRM_COLOROP_1D_CURVE_PQ_125_INV_EOTFenumstring“PQ 125 Inverse EOTF”The inverse of DRM_COLOROP_1D_CURVE_PQ_125_EOTF.
DRM_COLOROP_1D_CURVE_BT2020_INV_OETFenumstring“BT.2020 Inverse OETF”The inverse of
DRM_COLOROP_1D_CURVE_BT2020_OETFDRM_COLOROP_1D_CURVE_BT2020_OETFenumstring“BT.2020 OETF”The BT.2020/BT.709 transfer function. The BT.709 and BT.2020transfer functions are the same, the only difference is thatBT.2020 is defined with more precision for 10 and 12-bitencodings.
DRM_COLOROP_1D_CURVE_GAMMA22enumstring“Gamma 2.2”A gamma 2.2 power function. This applies a power curve withgamma value of 2.2 to the input values.
DRM_COLOROP_1D_CURVE_GAMMA22_INVenumstring“Gamma 2.2 Inverse”The inverse of
DRM_COLOROP_1D_CURVE_GAMMA22DRM_COLOROP_1D_CURVE_COUNTenumvaluedenoting the size of the enum
Description
Describes a 1D curve to be applied by the DRM_COLOROP_1D_CURVE colorop.
- structdrm_colorop_state¶
mutable colorop state
Definition:
struct drm_colorop_state { struct drm_colorop *colorop; bool bypass; enum drm_colorop_curve_1d_type curve_1d_type; uint64_t multiplier; struct drm_property_blob *data; struct drm_atomic_state *state;};Members
coloropbackpointer to the colorop
bypassWhen the property BYPASS exists on this colorop, this storesthe requested bypass state: true if colorop shall be bypassed,false if colorop is enabled.
curve_1d_typeType of 1D curve.
multiplierMultiplier to ‘gain’ the plane. Format is S31.32 sign-magnitude.
dataData blob for any TYPE that requires such a blob. Theinterpretation of the blob is TYPE-specific.
See the
drm_colorop_typedocumentation for how blob is laidout.statebackpointer to global drm_atomic_state
- structdrm_colorop_funcs¶
driver colorop control functions
Definition:
struct drm_colorop_funcs { void (*destroy)(struct drm_colorop *colorop);};Members
destroyClean up colorop resources. This is called at driver unload timethrough
drm_mode_config_cleanup()
- structdrm_colorop¶
DRM color operation control structure
Definition:
struct drm_colorop { struct drm_device *dev; struct list_head head; unsigned int index; struct drm_mode_object base; struct drm_plane *plane; struct drm_colorop_state *state; struct drm_object_properties properties; enum drm_colorop_type type; struct drm_colorop *next; struct drm_property *type_property; struct drm_property *bypass_property; uint32_t size; enum drm_colorop_lut1d_interpolation_type lut1d_interpolation; enum drm_colorop_lut3d_interpolation_type lut3d_interpolation; struct drm_property *lut1d_interpolation_property; struct drm_property *curve_1d_type_property; struct drm_property *multiplier_property; struct drm_property *size_property; struct drm_property *lut3d_interpolation_property; struct drm_property *data_property; struct drm_property *next_property; const struct drm_colorop_funcs *funcs;};Members
devparent DRM device
headList of all colorops ondev, linked from
drm_mode_config.colorop_list.Invariant over the lifetime ofdev and therefore does not needlocking.indexPosition inside the mode_config.list, can be used as an arrayindex. It is invariant over the lifetime of the colorop.
basebase mode object
planeThe plane on which the colorop sits. A drm_colorop is always uniqueto a plane.
stateCurrent atomic state for this colorop.
This is protected bymutex. Note that nonblocking atomic commitsaccess the current colorop state without taking locks.
propertiesproperty tracking for this colorop
typeRead-onlyType of color operation
nextRead-onlyPointer to next drm_colorop in pipeline
type_propertyRead-only “TYPE” property for specifying the type ofthis color operation. The type is
enumdrm_colorop_type.bypass_propertyBoolean property to control enablement of the coloroperation. Only present if DRM_COLOROP_FLAG_ALLOW_BYPASSflag is set. When present, setting bypass to “true” shallalways be supported to allow compositors to quickly fallback to alternate methods of color processing. This isimportant since setting color operations can fail due tounique HW constraints.
sizeNumber of entries of the custom LUT. This should be read-only.
lut1d_interpolationRead-onlyInterpolation for DRM_COLOROP_1D_LUT
lut3d_interpolationRead-onlyInterpolation for DRM_COLOROP_3D_LUT
lut1d_interpolation_propertyRead-only property for DRM_COLOROP_1D_LUT interpolation
curve_1d_type_propertySub-type for DRM_COLOROP_1D_CURVE type.
multiplier_propertyMultiplier property for plane gain
size_propertySize property for custom LUT from userspace.
lut3d_interpolation_propertyRead-only property for DRM_COLOROP_3D_LUT interpolation
data_propertyblob property for any TYPE that requires a blob of data,such as 1DLUT, CTM, 3DLUT, etc.
The way this blob is interpreted depends on the TYPE ofthis
next_propertyRead-only property to next colorop in the pipeline
funcscolorop control functions
Description
A colorop represents one color operation. They can be chained viathe ‘next’ pointer to build a color pipeline.
Since colorops cannot stand-alone and are used to describe coloropoperations on a plane they don’t have their own locking mechanism butare locked and programmed along with their associateddrm_plane.
- structdrm_colorop*drm_colorop_find(structdrm_device*dev,structdrm_file*file_priv,uint32_tid)¶
look up a Colorop object from its ID
Parameters
structdrm_device*devDRM device
structdrm_file*file_privdrm file to check for lease against.
uint32_tid
Description
This can be used to look up a Colorop from its userspace ID. Only used bydrivers for legacy IOCTLs and interface, nowadays extensions to the KMSuserspace interface should be done usingdrm_property.
- voiddrm_colorop_reset(structdrm_colorop*colorop)¶
reset colorop atomic state
Parameters
structdrm_colorop*coloropdrm colorop
Description
Resets the atomic state forcolorop by freeing the state pointer (which mightbe NULL, e.g. at driver load time) and allocating a new empty state object.
- unsignedintdrm_colorop_index(conststructdrm_colorop*colorop)¶
find the index of a registered colorop
Parameters
conststructdrm_colorop*coloropcolorop to find index for
Description
Given a registered colorop, return the index of that colorop within a DRMdevice’s list of colorops.
- constchar*drm_get_colorop_type_name(enumdrm_colorop_typetype)¶
return a string for colorop type
Parameters
enumdrm_colorop_typetypecolorop type to compute name of
Description
In contrast to the other drm_get_*_name functions this one here returns aconst pointer and hence is threadsafe.
- constchar*drm_get_colorop_curve_1d_type_name(enumdrm_colorop_curve_1d_typetype)¶
return a string for 1D curve type
Parameters
enumdrm_colorop_curve_1d_typetype1d curve type to compute name of
Description
In contrast to the other drm_get_*_name functions this one here returns aconst pointer and hence is threadsafe.
- voiddrm_colorop_cleanup(structdrm_colorop*colorop)¶
Cleanup a drm_colorop object in color_pipeline
Parameters
structdrm_colorop*coloropThe drm_colorop object to be cleaned
- voiddrm_colorop_destroy(structdrm_colorop*colorop)¶
destroy colorop
Parameters
structdrm_colorop*coloropdrm colorop
Description
Destroyscolorop by performing common DRM cleanup and freeing thecolorop object. This can be used by drivers if they do notrequire any driver-specific teardown.
- voiddrm_colorop_pipeline_destroy(structdrm_device*dev)¶
Helper for color pipeline destruction
Parameters
structdrm_device*devThe drm_device containing the drm_planes with the color_pipelines
Description
Provides a default color pipeline destroy handler for drm_device.
- intdrm_plane_colorop_curve_1d_init(structdrm_device*dev,structdrm_colorop*colorop,structdrm_plane*plane,conststructdrm_colorop_funcs*funcs,u64supported_tfs,uint32_tflags)¶
Initialize a DRM_COLOROP_1D_CURVE
Parameters
structdrm_device*devDRM device
structdrm_colorop*coloropThe drm_colorop object to initialize
structdrm_plane*planeThe associated drm_plane
conststructdrm_colorop_funcs*funcscontrol functions for the new colorop
u64supported_tfsA bitfield of supported drm_plane_colorop_curve_1d_init
enumvalues,created using BIT(curve_type) and combined with the OR ‘|’operator.uint32_tflagsbitmask of misc, see DRM_COLOROP_FLAG_* defines.return zero on success, -E value on failure
- intdrm_plane_colorop_curve_1d_lut_init(structdrm_device*dev,structdrm_colorop*colorop,structdrm_plane*plane,conststructdrm_colorop_funcs*funcs,uint32_tlut_size,enumdrm_colorop_lut1d_interpolation_typeinterpolation,uint32_tflags)¶
Initialize a DRM_COLOROP_1D_LUT
Parameters
structdrm_device*devDRM device
structdrm_colorop*coloropThe drm_colorop object to initialize
structdrm_plane*planeThe associated drm_plane
conststructdrm_colorop_funcs*funcscontrol functions for new colorop
uint32_tlut_sizeLUT size supported by driver
enumdrm_colorop_lut1d_interpolation_typeinterpolation1D LUT interpolation type
uint32_tflagsbitmask of misc, see DRM_COLOROP_FLAG_* defines.return zero on success, -E value on failure
- intdrm_plane_colorop_mult_init(structdrm_device*dev,structdrm_colorop*colorop,structdrm_plane*plane,conststructdrm_colorop_funcs*funcs,uint32_tflags)¶
Initialize a DRM_COLOROP_MULTIPLIER
Parameters
structdrm_device*devDRM device
structdrm_colorop*coloropThe drm_colorop object to initialize
structdrm_plane*planeThe associated drm_plane
conststructdrm_colorop_funcs*funcscontrol functions for the new colorop
uint32_tflagsbitmask of misc, see DRM_COLOROP_FLAG_* defines.return zero on success, -E value on failure
- voiddrm_colorop_set_next_property(structdrm_colorop*colorop,structdrm_colorop*next)¶
sets the next pointer
Parameters
structdrm_colorop*coloropdrm colorop
structdrm_colorop*nextnext colorop
Description
Should be used when constructing the color pipeline
Display Modes Function Reference¶
- enumdrm_mode_status¶
hardware support status of a mode
Constants
MODE_OKMode OK
MODE_HSYNChsync out of range
MODE_VSYNCvsync out of range
MODE_H_ILLEGALmode has illegal horizontal timings
MODE_V_ILLEGALmode has illegal vertical timings
MODE_BAD_WIDTHrequires an unsupported linepitch
MODE_NOMODEno mode with a matching name
MODE_NO_INTERLACEinterlaced mode not supported
MODE_NO_DBLESCANdoublescan mode not supported
MODE_NO_VSCANmultiscan mode not supported
MODE_MEMinsufficient video memory
MODE_VIRTUAL_Xmode width too large for specified virtual size
MODE_VIRTUAL_Ymode height too large for specified virtual size
MODE_MEM_VIRTinsufficient video memory given virtual size
MODE_NOCLOCKno fixed clock available
MODE_CLOCK_HIGHclock required is too high
MODE_CLOCK_LOWclock required is too low
MODE_CLOCK_RANGEclock/mode isn’t in a ClockRange
MODE_BAD_HVALUEhorizontal timing was out of range
MODE_BAD_VVALUEvertical timing was out of range
MODE_BAD_VSCANVScan value out of range
MODE_HSYNC_NARROWhorizontal sync too narrow
MODE_HSYNC_WIDEhorizontal sync too wide
MODE_HBLANK_NARROWhorizontal blanking too narrow
MODE_HBLANK_WIDEhorizontal blanking too wide
MODE_VSYNC_NARROWvertical sync too narrow
MODE_VSYNC_WIDEvertical sync too wide
MODE_VBLANK_NARROWvertical blanking too narrow
MODE_VBLANK_WIDEvertical blanking too wide
MODE_PANELexceeds panel dimensions
MODE_INTERLACE_WIDTHwidth too large for interlaced mode
MODE_ONE_WIDTHonly one width is supported
MODE_ONE_HEIGHTonly one height is supported
MODE_ONE_SIZEonly one resolution is supported
MODE_NO_REDUCEDmonitor doesn’t accept reduced blanking
MODE_NO_STEREOstereo modes not supported
MODE_NO_420ycbcr 420 modes not supported
MODE_STALEmode has become stale
MODE_BADunspecified reason
MODE_ERRORerror condition
Description
Thisenumis used to filter out modes not supported by the driver/hardwarecombination.
- DRM_MODE_RES_MM¶
DRM_MODE_RES_MM(res,dpi)
Calculates the display size from resolution and DPI
Parameters
resThe resolution in pixel
dpiThe number of dots per inch
- DRM_MODE_INIT¶
DRM_MODE_INIT(hz,hd,vd,hd_mm,vd_mm)
Initialize display mode
Parameters
hzVertical refresh rate in Hertz
hdHorizontal resolution, width
vdVertical resolution, height
hd_mmDisplay width in millimeters
vd_mmDisplay height in millimeters
Description
This macro initializes adrm_display_mode that contains information aboutrefresh rate, resolution and physical size.
- DRM_SIMPLE_MODE¶
DRM_SIMPLE_MODE(hd,vd,hd_mm,vd_mm)
Simple display mode
Parameters
hdHorizontal resolution, width
vdVertical resolution, height
hd_mmDisplay width in millimeters
vd_mmDisplay height in millimeters
Description
This macro initializes adrm_display_mode that only contains info aboutresolution and physical size.
- structdrm_display_mode¶
DRM kernel-internal display mode structure
Definition:
struct drm_display_mode { int clock; u16 hdisplay; u16 hsync_start; u16 hsync_end; u16 htotal; u16 hskew; u16 vdisplay; u16 vsync_start; u16 vsync_end; u16 vtotal; u16 vscan; u32 flags; int crtc_clock; u16 crtc_hdisplay; u16 crtc_hblank_start; u16 crtc_hblank_end; u16 crtc_hsync_start; u16 crtc_hsync_end; u16 crtc_htotal; u16 crtc_hskew; u16 crtc_vdisplay; u16 crtc_vblank_start; u16 crtc_vblank_end; u16 crtc_vsync_start; u16 crtc_vsync_end; u16 crtc_vtotal; u16 width_mm; u16 height_mm; u8 type; bool expose_to_userspace; struct list_head head; char name[DRM_DISPLAY_MODE_LEN]; enum drm_mode_status status; enum hdmi_picture_aspect picture_aspect_ratio;};Members
clockPixel clock in kHz.
hdisplayhorizontal display size
hsync_starthorizontal sync start
hsync_endhorizontal sync end
htotalhorizontal total size
hskewhorizontal skew?!
vdisplayvertical display size
vsync_startvertical sync start
vsync_endvertical sync end
vtotalvertical total size
vscanvertical scan?!
flagsSync and timing flags:
DRM_MODE_FLAG_PHSYNC: horizontal sync is active high.
DRM_MODE_FLAG_NHSYNC: horizontal sync is active low.
DRM_MODE_FLAG_PVSYNC: vertical sync is active high.
DRM_MODE_FLAG_NVSYNC: vertical sync is active low.
DRM_MODE_FLAG_INTERLACE: mode is interlaced.
DRM_MODE_FLAG_DBLSCAN: mode uses doublescan.
DRM_MODE_FLAG_CSYNC: mode uses composite sync.
DRM_MODE_FLAG_PCSYNC: composite sync is active high.
DRM_MODE_FLAG_NCSYNC: composite sync is active low.
DRM_MODE_FLAG_HSKEW: hskew provided (not used?).
DRM_MODE_FLAG_BCAST: <deprecated>
DRM_MODE_FLAG_PIXMUX: <deprecated>
DRM_MODE_FLAG_DBLCLK: double-clocked mode.
DRM_MODE_FLAG_CLKDIV2: half-clocked mode.
Additionally there’s flags to specify how 3D modes are packed:
DRM_MODE_FLAG_3D_NONE: normal, non-3D mode.
DRM_MODE_FLAG_3D_FRAME_PACKING: 2 full frames for left and right.
DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE: interleaved like fields.
DRM_MODE_FLAG_3D_LINE_ALTERNATIVE: interleaved lines.
DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL: side-by-side full frames.
DRM_MODE_FLAG_3D_L_DEPTH: ?
DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH: ?
DRM_MODE_FLAG_3D_TOP_AND_BOTTOM: frame split into top and bottomparts.
DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF: frame split into left andright parts.
crtc_clockActual pixel or dot clock in the hardware. This differs from thelogicalclock when e.g. using interlacing, double-clocking, stereomodes or other fancy stuff that changes the timings and signalsactually sent over the wire.
This is again in kHz.
Note that with digital outputs like HDMI or DP there’s usually amassive confusion between the dot clock and the signal clock at thebit encoding level. Especially when a 8b/10b encoding is used and thedifference is exactly a factor of 10.
crtc_hdisplayhardware mode horizontal display size
crtc_hblank_starthardware mode horizontal blank start
crtc_hblank_endhardware mode horizontal blank end
crtc_hsync_starthardware mode horizontal sync start
crtc_hsync_endhardware mode horizontal sync end
crtc_htotalhardware mode horizontal total size
crtc_hskewhardware mode horizontal skew?!
crtc_vdisplayhardware mode vertical display size
crtc_vblank_starthardware mode vertical blank start
crtc_vblank_endhardware mode vertical blank end
crtc_vsync_starthardware mode vertical sync start
crtc_vsync_endhardware mode vertical sync end
crtc_vtotalhardware mode vertical total size
width_mmAddressable size of the output in mm, projectors should set this to0.
height_mmAddressable size of the output in mm, projectors should set this to0.
typeA bitmask of flags, mostly about the source of a mode. Possible flagsare:
DRM_MODE_TYPE_PREFERRED: Preferred mode, usually the nativeresolution of an LCD panel. There should only be one preferredmode per connector at any given time.
DRM_MODE_TYPE_DRIVER: Mode created by the driver, which is all ofthem really. Drivers must set this bit for all modes they createand expose to userspace.
DRM_MODE_TYPE_USERDEF: Mode defined or selected via the kernelcommand line.
Plus a big list of flags which shouldn’t be used at all, but arestill around since these flags are also used in the userspace ABI.We no longer accept modes with these types though:
DRM_MODE_TYPE_BUILTIN: Meant for hard-coded modes, unused.Use DRM_MODE_TYPE_DRIVER instead.
DRM_MODE_TYPE_DEFAULT: Again a leftover, useDRM_MODE_TYPE_PREFERRED instead.
DRM_MODE_TYPE_CLOCK_C and DRM_MODE_TYPE_CRTC_C: Define leftoverswhich are stuck around for hysterical raisins only. No one has anidea what they were meant for. Don’t use.
expose_to_userspaceIndicates whether the mode is to be exposed to the userspace.This is to maintain a set of exposed modes while preparinguser-mode’s list in drm_mode_getconnector ioctl. The purpose ofthis only lies in the ioctl function, and is not to be usedoutside the function.
headstructlist_headfor mode lists.nameHuman-readable name of the mode, filled out with
drm_mode_set_name().statusStatus of the mode, used to filter out modes not supported by thehardware. See enum
drm_mode_status.picture_aspect_ratioField for setting the HDMI picture aspect ratio of a mode.
Description
This is the kernel API display mode information structure. For theuser-space version seestructdrm_mode_modeinfo.
The horizontal and vertical timings are defined per the following diagram.
Active Front Sync Back Region Porch Porch<-----------------------><----------------><-------------><--------------> //////////////////////| ////////////////////// |////////////////////// |.................. ................ _______________<----- [hv]display -----><------------- [hv]sync_start ------------><--------------------- [hv]sync_end ---------------------><-------------------------------- [hv]total ----------------------------->*
This structure contains two copies of timings. First are the plain timings,which specify the logical mode, as it would be for a progressive 1:1 scanoutat the refresh rate userspace can observe through vblank timestamps. Thenthere’s the hardware timings, which are corrected for interlacing,double-clocking and similar things. They are provided as a convenience, andcan be appropriately computed usingdrm_mode_set_crtcinfo().
For printing you can useDRM_MODE_FMT andDRM_MODE_ARG().
- DRM_MODE_FMT¶
DRM_MODE_FMT
printf string for
structdrm_display_mode
- DRM_MODE_ARG¶
DRM_MODE_ARG(m)
printf arguments for
structdrm_display_mode
Parameters
mdisplay mode
- booldrm_mode_is_stereo(conststructdrm_display_mode*mode)¶
check for stereo mode flags
Parameters
conststructdrm_display_mode*modedrm_display_mode to check
Return
True if the mode is one of the stereo modes (like side-by-side), false ifnot.
- voiddrm_mode_debug_printmodeline(conststructdrm_display_mode*mode)¶
print a mode to dmesg
Parameters
conststructdrm_display_mode*modemode to print
Description
Describemode using DRM_DEBUG.
- structdrm_display_mode*drm_mode_create(structdrm_device*dev)¶
create a new display mode
Parameters
structdrm_device*devDRM device
Description
Create a new, cleared drm_display_mode with kzalloc, allocate an ID for itand return it.
Return
Pointer to new mode on success, NULL on error.
- voiddrm_mode_destroy(structdrm_device*dev,structdrm_display_mode*mode)¶
remove a mode
Parameters
structdrm_device*devDRM device
structdrm_display_mode*modemode to remove
Description
Releasemode’s unique ID, then free itmode structure itself using kfree.
- voiddrm_mode_probed_add(structdrm_connector*connector,structdrm_display_mode*mode)¶
add a mode to a connector’s probed_mode list
Parameters
structdrm_connector*connectorconnector the new mode
structdrm_display_mode*modemode data
Description
Addmode toconnector’s probed_mode list for later use. This list shouldthen in a second step get filtered and all the modes actually supported bythe hardware moved to theconnector’s modes list.
- structdrm_display_mode*drm_analog_tv_mode(structdrm_device*dev,enumdrm_connector_tv_modetv_mode,unsignedlongpixel_clock_hz,unsignedinthdisplay,unsignedintvdisplay,boolinterlace)¶
create a display mode for an analog TV
Parameters
structdrm_device*devdrm device
enumdrm_connector_tv_modetv_modeTV Mode standard to create a mode for. See DRM_MODE_TV_MODE_*.
unsignedlongpixel_clock_hzPixel Clock Frequency, in Hertz
unsignedinthdisplayhdisplay size
unsignedintvdisplayvdisplay size
boolinterlacewhether to compute an interlaced mode
Description
This function creates astructdrm_display_mode instance suited foran analog TV output, for one of the usual analog TV modes. Wherethis is DRM_MODE_TV_MODE_MONOCHROME, a 625-line mode will be created.
Note thathdisplay is larger than the usual constraints for the PALand NTSC timings, and we’ll choose to ignore most timings constraintsto reach those resolutions.
Return
A pointer to the mode, allocated withdrm_mode_create(). Returns NULLon error.
- structdrm_display_mode*drm_cvt_mode(structdrm_device*dev,inthdisplay,intvdisplay,intvrefresh,boolreduced,boolinterlaced,boolmargins)¶
create a modeline based on the CVT algorithm
Parameters
structdrm_device*devdrm device
inthdisplayhdisplay size
intvdisplayvdisplay size
intvrefreshvrefresh rate
boolreducedwhether to use reduced blanking
boolinterlacedwhether to compute an interlaced mode
boolmarginswhether to add margins (borders)
Description
This function is called to generate the modeline based on CVT algorithmaccording to the hdisplay, vdisplay, vrefresh.It is based from the VESA(TM) Coordinated Video Timing Generator byGraham Loveridge April 9, 2003 available athttp://www.elo.utfsm.cl/~elo212/docs/CVTd6r1.xls
And it is copied from xf86CVTmode in xserver/hw/xfree86/modes/xf86cvt.c.What I have done is to translate it by using integer calculation.
Return
The modeline based on the CVT algorithm stored in a drm_display_mode object.The display mode object is allocated withdrm_mode_create(). Returns NULLwhen no mode could be allocated.
- structdrm_display_mode*drm_gtf_mode_complex(structdrm_device*dev,inthdisplay,intvdisplay,intvrefresh,boolinterlaced,intmargins,intGTF_M,intGTF_2C,intGTF_K,intGTF_2J)¶
create the modeline based on the full GTF algorithm
Parameters
structdrm_device*devdrm device
inthdisplayhdisplay size
intvdisplayvdisplay size
intvrefreshvrefresh rate.
boolinterlacedwhether to compute an interlaced mode
intmarginsdesired margin (borders) size
intGTF_Mextended GTF formula parameters
intGTF_2Cextended GTF formula parameters
intGTF_Kextended GTF formula parameters
intGTF_2Jextended GTF formula parameters
Description
GTF feature blocks specify C and J in multiples of 0.5, so we pass themin here multiplied by two. For a C of 40, pass in 80.
Return
The modeline based on the full GTF algorithm stored in a drm_display_mode object.The display mode object is allocated withdrm_mode_create(). Returns NULLwhen no mode could be allocated.
- structdrm_display_mode*drm_gtf_mode(structdrm_device*dev,inthdisplay,intvdisplay,intvrefresh,boolinterlaced,intmargins)¶
create the modeline based on the GTF algorithm
Parameters
structdrm_device*devdrm device
inthdisplayhdisplay size
intvdisplayvdisplay size
intvrefreshvrefresh rate.
boolinterlacedwhether to compute an interlaced mode
intmarginsdesired margin (borders) size
Description
return the modeline based on GTF algorithm
This function is to create the modeline based on the GTF algorithm.Generalized Timing Formula is derived from:
GTF Spreadsheet by Andy Morrish (1/5/97)available athttps://www.vesa.org
And it is copied from the file of xserver/hw/xfree86/modes/xf86gtf.c.What I have done is to translate it by using integer calculation.I also refer to the function of fb_get_mode in the file ofdrivers/video/fbmon.c
Standard GTF parameters:
M = 600C = 40K = 128J = 20
Return
The modeline based on the GTF algorithm stored in a drm_display_mode object.The display mode object is allocated withdrm_mode_create(). Returns NULLwhen no mode could be allocated.
- voiddrm_display_mode_from_videomode(conststructvideomode*vm,structdrm_display_mode*dmode)¶
fill indmode usingvm,
Parameters
conststructvideomode*vmvideomode structure to use as source
structdrm_display_mode*dmodedrm_display_mode structure to use as destination
Description
Fills outdmode using the display mode specified invm.
- voiddrm_display_mode_to_videomode(conststructdrm_display_mode*dmode,structvideomode*vm)¶
fill invm usingdmode,
Parameters
conststructdrm_display_mode*dmodedrm_display_mode structure to use as source
structvideomode*vmvideomode structure to use as destination
Description
Fills outvm using the display mode specified indmode.
- voiddrm_bus_flags_from_videomode(conststructvideomode*vm,u32*bus_flags)¶
extract information about pixelclk and DE polarity from videomode and store it in a separate variable
Parameters
conststructvideomode*vmvideomode structure to use
u32*bus_flagsinformation about pixelclk, sync and DE polarity will be storedhere
Description
Sets DRM_BUS_FLAG_DE_(LOW|HIGH), DRM_BUS_FLAG_PIXDATA_DRIVE_(POS|NEG)EDGEand DISPLAY_FLAGS_SYNC_(POS|NEG)EDGE inbus_flags according to DISPLAY_FLAGSfound invm
- intof_get_drm_display_mode(structdevice_node*np,structdrm_display_mode*dmode,u32*bus_flags,intindex)¶
get a drm_display_mode from devicetree
Parameters
structdevice_node*npdevice_node with the timing specification
structdrm_display_mode*dmodewill be set to the return value
u32*bus_flagsinformation about pixelclk, sync and DE polarity
intindexindex into the list of display timings in devicetree
Description
This function is expensive and should only be used, if only one mode is to beread from DT. To get multiple modes start with of_get_display_timings andwork with that instead.
Return
0 on success, a negative errno code when no of videomode node was found.
- intof_get_drm_panel_display_mode(structdevice_node*np,structdrm_display_mode*dmode,u32*bus_flags)¶
get a panel-timing drm_display_mode from devicetree
Parameters
structdevice_node*npdevice_node with the panel-timing specification
structdrm_display_mode*dmodewill be set to the return value
u32*bus_flagsinformation about pixelclk, sync and DE polarity
Description
The mandatory Device Tree properties width-mm and height-mmare read and set on the display mode.
Return
Zero on success, negative error code on failure.
- voiddrm_mode_set_name(structdrm_display_mode*mode)¶
set the name on a mode
Parameters
structdrm_display_mode*modename will be set in this mode
Description
Set the name ofmode to a standard format which is <hdisplay>x<vdisplay>with an optional ‘i’ suffix for interlaced modes.
- intdrm_mode_vrefresh(conststructdrm_display_mode*mode)¶
get the vrefresh of a mode
Parameters
conststructdrm_display_mode*modemode
Return
modes’s vrefresh rate in Hz, rounded to the nearest integer.
- voiddrm_mode_get_hv_timing(conststructdrm_display_mode*mode,int*hdisplay,int*vdisplay)¶
Fetches hdisplay/vdisplay for given mode
Parameters
conststructdrm_display_mode*modemode to query
int*hdisplayhdisplay value to fill in
int*vdisplayvdisplay value to fill in
Description
The vdisplay value will be doubled if the specified mode is a stereo mode ofthe appropriate layout.
- voiddrm_mode_set_crtcinfo(structdrm_display_mode*p,intadjust_flags)¶
set CRTC modesetting timing parameters
Parameters
structdrm_display_mode*pmode
intadjust_flagsa combination of adjustment flags
Description
Setup the CRTC modesetting timing parameters forp, adjusting if necessary.
The CRTC_INTERLACE_HALVE_V flag can be used to halve vertical timings ofinterlaced modes.
The CRTC_STEREO_DOUBLE flag can be used to compute the timings forbuffers containing two eyes (only adjust the timings when needed, eg. for“frame packing” or “side by side full”).
The CRTC_NO_DBLSCAN and CRTC_NO_VSCAN flags request that adjustmentnotbe performed for doublescan and vscan > 1 modes respectively.
- voiddrm_mode_copy(structdrm_display_mode*dst,conststructdrm_display_mode*src)¶
copy the mode
Parameters
structdrm_display_mode*dstmode to overwrite
conststructdrm_display_mode*srcmode to copy
Description
Copy an existing mode into another mode, preserving thelist head of the destination mode.
- voiddrm_mode_init(structdrm_display_mode*dst,conststructdrm_display_mode*src)¶
initialize the mode from another mode
Parameters
structdrm_display_mode*dstmode to overwrite
conststructdrm_display_mode*srcmode to copy
Description
Copy an existing mode into another mode, zeroing thelist head of the destination mode. Typically usedto guarantee the list head is not left with stackgarbage in on-stack modes.
- structdrm_display_mode*drm_mode_duplicate(structdrm_device*dev,conststructdrm_display_mode*mode)¶
allocate and duplicate an existing mode
Parameters
structdrm_device*devdrm_device to allocate the duplicated mode for
conststructdrm_display_mode*modemode to duplicate
Description
Just allocate a new mode, copy the existing mode into it, and returna pointer to it. Used to create new instances of established modes.
Return
Pointer to duplicated mode on success, NULL on error.
- booldrm_mode_match(conststructdrm_display_mode*mode1,conststructdrm_display_mode*mode2,unsignedintmatch_flags)¶
test modes for (partial) equality
Parameters
conststructdrm_display_mode*mode1first mode
conststructdrm_display_mode*mode2second mode
unsignedintmatch_flagswhich parts need to match (DRM_MODE_MATCH_*)
Description
Check to see ifmode1 andmode2 are equivalent.
Return
True if the modes are (partially) equal, false otherwise.
- booldrm_mode_equal(conststructdrm_display_mode*mode1,conststructdrm_display_mode*mode2)¶
test modes for equality
Parameters
conststructdrm_display_mode*mode1first mode
conststructdrm_display_mode*mode2second mode
Description
Check to see ifmode1 andmode2 are equivalent.
Return
True if the modes are equal, false otherwise.
- booldrm_mode_equal_no_clocks(conststructdrm_display_mode*mode1,conststructdrm_display_mode*mode2)¶
test modes for equality
Parameters
conststructdrm_display_mode*mode1first mode
conststructdrm_display_mode*mode2second mode
Description
Check to see ifmode1 andmode2 are equivalent, butdon’t check the pixel clocks.
Return
True if the modes are equal, false otherwise.
- booldrm_mode_equal_no_clocks_no_stereo(conststructdrm_display_mode*mode1,conststructdrm_display_mode*mode2)¶
test modes for equality
Parameters
conststructdrm_display_mode*mode1first mode
conststructdrm_display_mode*mode2second mode
Description
Check to see ifmode1 andmode2 are equivalent, butdon’t check the pixel clocks nor the stereo layout.
Return
True if the modes are equal, false otherwise.
- enumdrm_mode_statusdrm_mode_validate_driver(structdrm_device*dev,conststructdrm_display_mode*mode)¶
make sure the mode is somewhat sane
Parameters
structdrm_device*devdrm device
conststructdrm_display_mode*modemode to check
Description
First do basic validation on the mode, and then allow the driverto check for device/driver specific limitations via the optionaldrm_mode_config_helper_funcs.mode_valid hook.
Return
The mode status
- enumdrm_mode_statusdrm_mode_validate_size(conststructdrm_display_mode*mode,intmaxX,intmaxY)¶
make sure modes adhere to size constraints
Parameters
conststructdrm_display_mode*modemode to check
intmaxXmaximum width
intmaxYmaximum height
Description
This function is a helper which can be used to validate modes against sizelimitations of the DRM device/connector. If a mode is too big its statusmember is updated with the appropriate validation failure code. The listitself is not changed.
Return
The mode status
- enumdrm_mode_statusdrm_mode_validate_ycbcr420(conststructdrm_display_mode*mode,structdrm_connector*connector)¶
add ‘ycbcr420-only’ modes only when allowed
Parameters
conststructdrm_display_mode*modemode to check
structdrm_connector*connectordrm connector under action
Description
This function is a helper which can be used to filter out any YCBCR420only mode, when the source doesn’t support it.
Return
The mode status
- voiddrm_mode_prune_invalid(structdrm_device*dev,structlist_head*mode_list,boolverbose)¶
remove invalid modes from mode list
Parameters
structdrm_device*devDRM device
structlist_head*mode_listlist of modes to check
boolverbosebe verbose about it
Description
This helper function can be used to prune a display mode list aftervalidation has been completed. All modes whose status is not MODE_OK will beremoved from the list, and ifverbose the status code and mode name is alsoprinted to dmesg.
- voiddrm_mode_sort(structlist_head*mode_list)¶
sort mode list
Parameters
structlist_head*mode_listlist of drm_display_mode structures to sort
Description
Sortmode_list by favorability, moving good modes to the head of the list.
- voiddrm_connector_list_update(structdrm_connector*connector)¶
update the mode list for the connector
Parameters
structdrm_connector*connectorthe connector to update
Description
This moves the modes from theconnector probed_modes listto the actual mode list. It compares the probed mode against the currentlist and only adds different/new modes.
This is just a helper functions doesn’t validate any modes itself and alsodoesn’t prune any invalid modes. Callers need to do that themselves.
- booldrm_mode_parse_command_line_for_connector(constchar*mode_option,conststructdrm_connector*connector,structdrm_cmdline_mode*mode)¶
parse command line modeline for connector
Parameters
constchar*mode_optionoptional per connector mode option
conststructdrm_connector*connectorconnector to parse modeline for
structdrm_cmdline_mode*modepreallocated drm_cmdline_mode structure to fill out
Description
This parsesmode_option command line modeline for modes and options toconfigure the connector.
This uses the same parameters as the fb modedb.c, except for an extraforce-enable, force-enable-digital and force-disable bit at the end:
<xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m][eDd]
Additionals options can be provided following the mode, using a comma toseparate each option. Valid options can be found inmodedb default video mode support.
The intermediate drm_cmdline_mode structure is required to store additionaloptions from the command line modline like the force-enable/disable flag.
Return
True if a valid modeline has been parsed, false otherwise.
- structdrm_display_mode*drm_mode_create_from_cmdline_mode(structdrm_device*dev,structdrm_cmdline_mode*cmd)¶
convert a command line modeline into a DRM display mode
Parameters
structdrm_device*devDRM device to create the new mode for
structdrm_cmdline_mode*cmdinput command line modeline
Return
Pointer to converted mode on success, NULL on error.
- booldrm_mode_is_420_only(conststructdrm_display_info*display,conststructdrm_display_mode*mode)¶
if a given videomode can be only supported in YCBCR420 output format
Parameters
conststructdrm_display_info*displaydisplay under action
conststructdrm_display_mode*modevideo mode to be tested.
Return
true if the mode can be supported in YCBCR420 formatfalse if not.
- booldrm_mode_is_420_also(conststructdrm_display_info*display,conststructdrm_display_mode*mode)¶
if a given videomode can be supported in YCBCR420 output format also (along with RGB/YCBCR444/422)
Parameters
conststructdrm_display_info*displaydisplay under action.
conststructdrm_display_mode*modevideo mode to be tested.
Return
true if the mode can be support YCBCR420 formatfalse if not.
- booldrm_mode_is_420(conststructdrm_display_info*display,conststructdrm_display_mode*mode)¶
if a given videomode can be supported in YCBCR420 output format
Parameters
conststructdrm_display_info*displaydisplay under action.
conststructdrm_display_mode*modevideo mode to be tested.
Return
true if the mode can be supported in YCBCR420 formatfalse if not.
- voiddrm_set_preferred_mode(structdrm_connector*connector,inthpref,intvpref)¶
Sets the preferred mode of a connector
Parameters
structdrm_connector*connectorconnector whose mode list should be processed
inthprefhorizontal resolution of preferred mode
intvprefvertical resolution of preferred mode
Description
Marks a mode as preferred if it matches the resolution specified byhprefandvpref.
Connector Abstraction¶
In DRM connectors are the general abstraction for display sinks, and includealso fixed panels or anything else that can display pixels in some form. Asopposed to all other KMS objects representing hardware (like CRTC, encoder orplane abstractions) connectors can be hotplugged and unplugged at runtime.Hence they are reference-counted usingdrm_connector_get() anddrm_connector_put().
KMS driver must create, initialize, register and attach at astructdrm_connector for each such sink. The instance is created as other KMSobjects and initialized by setting the following fields. The connector isinitialized with a call todrm_connector_init() with a pointer to thestructdrm_connector_funcs and a connector type, and then exposed touserspace with a call todrm_connector_register().
Connectors must be attached to an encoder to be used. For devices that mapconnectors to encoders 1:1, the connector should be attached atinitialization time with a call todrm_connector_attach_encoder(). Thedriver must also set thedrm_connector.encoder field to point to theattached encoder.
For connectors which are not fixed (like built-in panels) the driver needs tosupport hotplug notifications. The simplest way to do that is by using theprobe helpers, seedrm_kms_helper_poll_init() for connectors which don’t havehardware support for hotplug interrupts. Connectors with hardware hotplugsupport can instead use e.g.drm_helper_hpd_irq_event().
Connector Functions Reference¶
- enumdrm_connector_status¶
status for a
drm_connector
Constants
connector_status_connectedThe connector is definitely connected toa sink device, and can be enabled.
connector_status_disconnectedThe connector isn’t connected to asink device which can be autodetect. For digital outputs like DP orHDMI (which can be realiable probed) this means there’s reallynothing there. It is driver-dependent whether a connector with thisstatus can be lit up or not.
connector_status_unknownThe connector’s status could not bereliably detected. This happens when probing would either causeflicker (like load-detection when the connector is in use), or when ahardware resource isn’t available (like when load-detection needs afree CRTC). It should be possible to light up the connector with oneof the listed fallback modes. For default configuration userspaceshould only try to light up connectors with unknown status whenthere’s not connector withconnector_status_connected.
Description
Thisenumis used to track the connector status. There are no separate#defines for the uapi!
- enumdrm_connector_registration_state¶
userspace registration status for a
drm_connector
Constants
DRM_CONNECTOR_INITIALIZINGThe connector has just been created,but has yet to be exposed to userspace. There should be noadditional restrictions to how the state of this connector may bemodified.
DRM_CONNECTOR_REGISTEREDThe connector has been fully initializedand registered with sysfs, as such it has been exposed touserspace. There should be no additional restrictions to how thestate of this connector may be modified.
DRM_CONNECTOR_UNREGISTEREDThe connector has either been exposedto userspace and has since been unregistered and removed fromuserspace, or the connector was unregistered before it had a chanceto be exposed to userspace (e.g. still in theDRM_CONNECTOR_INITIALIZING state). When a connector isunregistered, there are additional restrictions to how its statemay be modified:
An unregistered connector may only have its DPMS changed fromOn->Off. Once DPMS is changed to Off, it may not be switched backto On.
Modesets are not allowed on unregistered connectors, unless theywould result in disabling its assigned CRTCs. This meansdisabling a CRTC on an unregistered connector is OK, but enablingone is not.
Removing a CRTC from an unregistered connector is OK, but newCRTCs may never be assigned to an unregistered connector.
Description
Thisenumis used to track the status of initializing a connector andregistering it with userspace, so that DRM can prevent bogus modesets onconnectors that no longer exist.
- enumdrm_connector_tv_mode¶
Analog TV output mode
Constants
DRM_MODE_TV_MODE_NTSCCCIR System M (aka 525-lines)together with the NTSC Color Encoding.
DRM_MODE_TV_MODE_NTSC_443Variant ofDRM_MODE_TV_MODE_NTSC. Uses a color subcarrier frequencyof 4.43 MHz.
DRM_MODE_TV_MODE_NTSC_JVariant ofDRM_MODE_TV_MODE_NTSCused in Japan. Uses a black level equals to the blankinglevel.
DRM_MODE_TV_MODE_PALCCIR System B together with the PALcolor system.
DRM_MODE_TV_MODE_PAL_MCCIR System M (aka 525-lines)together with the PAL color encoding
DRM_MODE_TV_MODE_PAL_NCCIR System N together with the PALcolor encoding. It uses 625 lines, but has a color subcarrierfrequency of 3.58MHz, the SECAM color space, and narrowerchannels compared to most of the other PAL variants.
DRM_MODE_TV_MODE_SECAMCCIR System B together with theSECAM color system.
DRM_MODE_TV_MODE_MONOCHROMEUse timings appropriate tothe DRM mode, including equalizing pulses for a 525-lineor 625-line mode, with no pedestal or color encoding.
DRM_MODE_TV_MODE_MAXNumber of analog TV output modes.
Internal implementation detail; this is not uABI.
Description
Thisenumis used to indicate the TV output mode used on an analog TVconnector.
WARNING: The values of thisenumis uABI since they’re exposed in the“TV mode” connector property.
- structdrm_scrambling¶
sink’s scrambling support.
Definition:
struct drm_scrambling { bool supported; bool low_rates;};Members
supportedscrambling supported for rates > 340 Mhz.
low_ratesscrambling supported for rates <= 340 Mhz.
- structdrm_hdmi_dsc_cap¶
DSC capabilities of HDMI sink
Definition:
struct drm_hdmi_dsc_cap { bool v_1p2; bool native_420; bool all_bpp; u8 bpc_supported; u8 max_slices; int clk_per_slice; u8 max_lanes; u8 max_frl_rate_per_lane; u8 total_chunk_kbytes;};Members
v_1p2flag for dsc1.2 version support by sink
native_420Does sink support DSC with 4:2:0 compression
all_bppDoes sink support all bpp with 4:4:4: or 4:2:2compressed formats
bpc_supportedcompressed bpc supported by sink : 10, 12 or 16 bpc
max_slicesmaximum number of Horizontal slices supported by
clk_per_slicemax pixel clock in MHz supported per slice
max_lanesdsc max lanes supported for Fixed rate Link training
max_frl_rate_per_lanemaximum frl rate with DSC per lane
total_chunk_kbytesmax size of chunks in KBs supported per line
Description
Describes the DSC support provided by HDMI 2.1 sink.The information is fetched fom additional HFVSDB blocks definedfor HDMI 2.1.
- structdrm_hdmi_info¶
runtime information about the connected HDMI sink
Definition:
struct drm_hdmi_info { struct drm_scdc scdc; unsigned long y420_vdb_modes[BITS_TO_LONGS(256)]; unsigned long y420_cmdb_modes[BITS_TO_LONGS(256)]; u8 y420_dc_modes; u8 max_frl_rate_per_lane; u8 max_lanes; struct drm_hdmi_dsc_cap dsc_cap;};Members
scdcsink’s scdc support and capabilities
y420_vdb_modesbitmap of modes which can support ycbcr420output only (not normal RGB/YCBCR444/422 outputs). The max VICdefined by the CEA-861-G spec is 219, so the size is 256 bits to mapup to 256 VICs.
y420_cmdb_modesbitmap of modes which can support ycbcr420output also, along with normal HDMI outputs. The max VIC defined bythe CEA-861-G spec is 219, so the size is 256 bits to map up to 256VICs.
y420_dc_modesbitmap of deep color support index
max_frl_rate_per_lanesupport fixed rate link
max_lanessupported by sink
dsc_capDSC capabilities of the sink
Description
Describes if a given display supports advanced HDMI 2.0 features.This information is available in CEA-861-F extension blocks (like HF-VSDB).
- enumdrm_link_status¶
connector’s link_status property value
Constants
DRM_LINK_STATUS_GOODDP Link is Good as a result of successfullink training
DRM_LINK_STATUS_BADDP Link is BAD as a result of link trainingfailure
Description
Thisenumis used as the connector’s link status property value.It is set to the values defined in uapi.
- enumdrm_panel_orientation¶
panel_orientation info for
drm_display_info
Constants
DRM_MODE_PANEL_ORIENTATION_UNKNOWNThe drm driver has not provided anypanel orientation information (normalfor non panels) in this case the “panelorientation” connector prop will not beattached.
DRM_MODE_PANEL_ORIENTATION_NORMALThe top side of the panel matches thetop side of the device’s casing.
DRM_MODE_PANEL_ORIENTATION_BOTTOM_UPThe top side of the panel matches thebottom side of the device’s casing, iowthe panel is mounted upside-down.
DRM_MODE_PANEL_ORIENTATION_LEFT_UPThe left side of the panel matches thetop side of the device’s casing.
DRM_MODE_PANEL_ORIENTATION_RIGHT_UPThe right side of the panel matches thetop side of the device’s casing.
Description
Thisenumis used to track the (LCD) panel orientation. There are noseparate #defines for the uapi!
- enumdrm_hdmi_broadcast_rgb¶
Broadcast RGB Selection for an HDMIdrm_connector
Constants
DRM_HDMI_BROADCAST_RGB_AUTOThe RGB range is selectedautomatically based on the mode.
DRM_HDMI_BROADCAST_RGB_FULLFull range RGB is forced.
DRM_HDMI_BROADCAST_RGB_LIMITEDLimited range RGB is forced.
- structdrm_monitor_range_info¶
Panel’s Monitor range in EDID for
drm_display_info
Definition:
struct drm_monitor_range_info { u16 min_vfreq; u16 max_vfreq;};Members
min_vfreqThis is the min supported refresh rate in Hz fromEDID’s detailed monitor range.
max_vfreqThis is the max supported refresh rate in Hz fromEDID’s detailed monitor range
Description
Thisstructis used to store a frequency range supported by panelas parsed from EDID’s detailed monitor range descriptor block.
- structdrm_luminance_range_info¶
Panel’s luminance range for
drm_display_info. Calculated using data in EDID
Definition:
struct drm_luminance_range_info { u32 min_luminance; u32 max_luminance;};Members
min_luminanceThis is the min supported luminance value
max_luminanceThis is the max supported luminance value
Description
Thisstructis used to store a luminance range supported by panelas calculated using data from EDID’s static hdr metadata.
- enumdrm_privacy_screen_status¶
privacy screen status
Constants
PRIVACY_SCREEN_DISABLEDThe privacy-screen on the panel is disabled
PRIVACY_SCREEN_ENABLEDThe privacy-screen on the panel is enabled
PRIVACY_SCREEN_DISABLED_LOCKEDThe privacy-screen on the panel is disabled and locked (cannot be changed)
PRIVACY_SCREEN_ENABLED_LOCKEDThe privacy-screen on the panel is enabled and locked (cannot be changed)
Description
Thisenumis used to track and control the state of the integrated privacyscreen present on some display panels, via the “privacy-screen sw-state”and “privacy-screen hw-state” properties. Note the _LOCKEDenumvaluesare only valid for the “privacy-screen hw-state” property.
- enumdrm_colorspace¶
color space
Constants
DRM_MODE_COLORIMETRY_DEFAULTDriver specific behavior.
DRM_MODE_COLORIMETRY_NO_DATADriver specific behavior.
DRM_MODE_COLORIMETRY_SMPTE_170M_YCC(HDMI)SMPTE ST 170M colorimetry format
DRM_MODE_COLORIMETRY_BT709_YCC(HDMI, DP)ITU-R BT.709 colorimetry format
DRM_MODE_COLORIMETRY_XVYCC_601(HDMI, DP)xvYCC601 colorimetry format
DRM_MODE_COLORIMETRY_XVYCC_709(HDMI, DP)xvYCC709 colorimetry format
DRM_MODE_COLORIMETRY_SYCC_601(HDMI, DP)sYCC601 colorimetry format
DRM_MODE_COLORIMETRY_OPYCC_601(HDMI, DP)opYCC601 colorimetry format
DRM_MODE_COLORIMETRY_OPRGB(HDMI, DP)opRGB colorimetry format
DRM_MODE_COLORIMETRY_BT2020_CYCC(HDMI, DP)ITU-R BT.2020 Y’c C’bc C’rc (constant luminance) colorimetry format
DRM_MODE_COLORIMETRY_BT2020_RGB(HDMI, DP)ITU-R BT.2020 R’ G’ B’ colorimetry format
DRM_MODE_COLORIMETRY_BT2020_YCC(HDMI, DP)ITU-R BT.2020 Y’ C’b C’r colorimetry format
DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65(HDMI)SMPTE ST 2113 P3D65 colorimetry format
DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER(HDMI)SMPTE ST 2113 P3DCI colorimetry format
DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED(DP)RGB wide gamut fixed point colorimetry format
DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT(DP)RGB wide gamut floating point(scRGB (IEC 61966-2-2)) colorimetry format
DRM_MODE_COLORIMETRY_BT601_YCC(DP)ITU-R BT.601 colorimetry formatThe DP spec does not say whether this is the 525 or the 625line version.
DRM_MODE_COLORIMETRY_COUNTNot a valid value; merely used four counting
Description
Thisenumis a consolidated colorimetry list supported by HDMI andDP protocol standard. The respective connectors will registera property with the subset of this list (supported by thatrespective protocol). Userspace will set the colorspace througha colorspace property which will be created and exposed touserspace.
DP definitions come from the DP v2.0 specHDMI definitions come from the CTA-861-H spec
- enumdrm_bus_flags¶
bus_flags info for
drm_display_info
Constants
DRM_BUS_FLAG_DE_LOWThe Data Enable signal is active low
DRM_BUS_FLAG_DE_HIGHThe Data Enable signal is active high
DRM_BUS_FLAG_PIXDATA_DRIVE_POSEDGEData is driven on the rising edge of the pixel clock
DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGEData is driven on the falling edge of the pixel clock
DRM_BUS_FLAG_PIXDATA_SAMPLE_POSEDGEData is sampled on the rising edge of the pixel clock
DRM_BUS_FLAG_PIXDATA_SAMPLE_NEGEDGEData is sampled on the falling edge of the pixel clock
DRM_BUS_FLAG_DATA_MSB_TO_LSBData is transmitted MSB to LSB on the bus
DRM_BUS_FLAG_DATA_LSB_TO_MSBData is transmitted LSB to MSB on the bus
DRM_BUS_FLAG_SYNC_DRIVE_POSEDGESync signals are driven on the rising edge of the pixel clock
DRM_BUS_FLAG_SYNC_DRIVE_NEGEDGESync signals are driven on the falling edge of the pixel clock
DRM_BUS_FLAG_SYNC_SAMPLE_POSEDGESync signals are sampled on the rising edge of the pixel clock
DRM_BUS_FLAG_SYNC_SAMPLE_NEGEDGESync signals are sampled on the falling edge of the pixel clock
DRM_BUS_FLAG_SHARP_SIGNALSSet if the Sharp-specific signals (SPL, CLS, PS, REV) must be used
Description
Thisenumdefines signal polarities and clock edge information for signals ona bus as bitmask flags.
The clock edge information is conveyed by two sets of symbols,DRM_BUS_FLAGS_*_DRIVE_* and DRM_BUS_FLAGS_*_SAMPLE_*. When thisenumisused to describe a bus from the point of view of the transmitter, the*_DRIVE_* flags should be used. When used from the point of view of thereceiver, the *_SAMPLE_* flags should be used. The *_DRIVE_* and*_SAMPLE_* flags alias each other, with the *_SAMPLE_POSEDGE and*_SAMPLE_NEGEDGE flags being equal to *_DRIVE_NEGEDGE and *_DRIVE_POSEDGErespectively. This simplifies code as signals are usually sampled on theopposite edge of the driving edge. Transmitters and receivers may howeverneed to take other signal timings into account to convert between drivingand sample edges.
- structdrm_display_info¶
runtime data about the connected sink
Definition:
struct drm_display_info { unsigned int width_mm; unsigned int height_mm; unsigned int bpc; enum subpixel_order subpixel_order;#define DRM_COLOR_FORMAT_RGB444 (1<<0);#define DRM_COLOR_FORMAT_YCBCR444 (1<<1);#define DRM_COLOR_FORMAT_YCBCR422 (1<<2);#define DRM_COLOR_FORMAT_YCBCR420 (1<<3); int panel_orientation; u32 color_formats; const u32 *bus_formats; unsigned int num_bus_formats; u32 bus_flags; int max_tmds_clock; bool dvi_dual; bool is_hdmi; bool has_audio; bool has_hdmi_infoframe; bool rgb_quant_range_selectable; u8 edid_hdmi_rgb444_dc_modes; u8 edid_hdmi_ycbcr444_dc_modes; u8 cea_rev; struct drm_hdmi_info hdmi; struct hdr_sink_metadata hdr_sink_metadata; bool non_desktop; struct drm_monitor_range_info monitor_range; struct drm_luminance_range_info luminance_range; u8 mso_stream_count; u8 mso_pixel_overlap; u32 max_dsc_bpp; u8 *vics; int vics_len; u32 quirks; u16 source_physical_address;};Members
width_mmPhysical width in mm.
height_mmPhysical height in mm.
bpcMaximum bits per color channel. Used by HDMI and DP outputs.
subpixel_orderSubpixel order of LCD panels.
panel_orientationRead only connector property for built-in panels,indicating the orientation of the panel vs the device’s casing.
drm_connector_init()sets this to DRM_MODE_PANEL_ORIENTATION_UNKNOWN.When not UNKNOWN this gets used by the drm_fb_helpers to rotate thefb to compensate and gets exported as prop to userspace.color_formatsHDMI Color formats, selects between RGB and YCrCbmodes. Used DRM_COLOR_FORMAT_ defines, which are _not_ the same onesas used to describe the pixel format in framebuffers, and also don’tmatch the formats inbus_formats which are shared with v4l.
bus_formatsPixel data format on the wire, somewhat redundant withcolor_formats. Array of sizenum_bus_formats encoded usingMEDIA_BUS_FMT_ defines shared with v4l and media drivers.
num_bus_formatsSize ofbus_formats array.
bus_flagsAdditional information (like pixel signal polarity) forthe pixel data on the bus, using
enumdrm_bus_flagsvaluesDRM_BUS_FLAGS_.max_tmds_clockMaximum TMDS clock rate supported by thesink in kHz. 0 means undefined.
dvi_dualDual-link DVI sink?
is_hdmiTrue if the sink is an HDMI device.
This field shall be used instead of calling
drm_detect_hdmi_monitor()when possible.has_audioTrue if the sink supports audio.
This field shall be used instead of calling
drm_detect_monitor_audio()when possible.has_hdmi_infoframeDoes the sink support the HDMI infoframe?
rgb_quant_range_selectableDoes the sink support selectingthe RGB quantization range?
edid_hdmi_rgb444_dc_modesMask of supported hdmi deep color modesin RGB 4:4:4. Even more stuff redundant withbus_formats.
edid_hdmi_ycbcr444_dc_modesMask of supported hdmi deep colormodes in YCbCr 4:4:4. Even more stuff redundant withbus_formats.
cea_revCEA revision of the HDMI sink.
hdmiadvance features of a HDMI sink.
hdr_sink_metadataHDR Metadata Information read from sink
non_desktopNon desktop display (HMD).
monitor_rangeFrequency range supported by monitor range descriptor
luminance_rangeLuminance range supported by panel
mso_stream_counteDP Multi-SST Operation (MSO) stream count fromthe DisplayID VESA vendor block. 0 for conventional Single-StreamTransport (SST), or 2 or 4 MSO streams.
mso_pixel_overlapeDP MSO segment pixel overlap, 0-8 pixels.
max_dsc_bppMaximum DSC target bitrate, if it is set to 0 themonitor’s default value is used instead.
vicsArray of vics_len VICs. Internal to EDID parsing.
vics_lenNumber of elements in vics. Internal to EDID parsing.
quirksEDID based quirks. DRM core and drivers can query thedrm_edid_quirk quirks using
drm_edid_has_quirk(), the rest ofthe quirks also tracked here are internal to EDID parsing.source_physical_addressSource Physical Address from HDMIVendor-Specific Data Block, for CEC usage.
Defaults to CEC_PHYS_ADDR_INVALID (0xffff).
Description
Describes a given display (e.g. CRT or flat panel) and its limitations. Forfixed display sinks like built-in panels there’s not much difference betweenthis andstructdrm_connector. But for sinks with a real cable thisstructure is meant to describe all the things at the other end of the cable.
For sinks which provide an EDID this can be filled out by callingdrm_add_edid_modes().
- structdrm_connector_tv_margins¶
TV connector related margins
Definition:
struct drm_connector_tv_margins { unsigned int bottom; unsigned int left; unsigned int right; unsigned int top;};Members
bottomBottom margin in pixels.
leftLeft margin in pixels.
rightRight margin in pixels.
topTop margin in pixels.
Description
Describes the margins in pixels to put around the image on TVconnectors to deal with overscan.
- structdrm_tv_connector_state¶
TV connector related states
Definition:
struct drm_tv_connector_state { enum drm_mode_subconnector select_subconnector; enum drm_mode_subconnector subconnector; struct drm_connector_tv_margins margins; unsigned int legacy_mode; unsigned int mode; unsigned int brightness; unsigned int contrast; unsigned int flicker_reduction; unsigned int overscan; unsigned int saturation; unsigned int hue;};Members
select_subconnectorselected subconnector
subconnectordetected subconnector
marginsTV margins
legacy_modeLegacy TV mode, driver specific value
modeTV mode
brightnessbrightness in percent
contrastcontrast in percent
flicker_reductionflicker reduction in percent
overscanoverscan in percent
saturationsaturation in percent
huehue in percent
- structdrm_connector_hdmi_infoframe¶
HDMI Infoframe container
Definition:
struct drm_connector_hdmi_infoframe { union hdmi_infoframe data; bool set;};Members
dataHDMI Infoframe structure
setIs the content ofdata valid?
- structdrm_connector_state¶
mutable connector state
Definition:
struct drm_connector_state { struct drm_connector *connector; struct drm_crtc *crtc; struct drm_encoder *best_encoder; enum drm_link_status link_status; struct drm_atomic_state *state; struct drm_crtc_commit *commit; struct drm_tv_connector_state tv; bool self_refresh_aware; enum hdmi_picture_aspect picture_aspect_ratio; unsigned int content_type; unsigned int hdcp_content_type; unsigned int scaling_mode; unsigned int content_protection; enum drm_colorspace colorspace; struct drm_writeback_job *writeback_job; u8 max_requested_bpc; u8 max_bpc; enum drm_privacy_screen_status privacy_screen_sw_state; struct drm_property_blob *hdr_output_metadata; struct drm_connector_hdmi_state hdmi;};Members
connectorbackpointer to the connector
crtcCRTC to connect connector to, NULL if disabled.
Do not change this directly, use
drm_atomic_set_crtc_for_connector()instead.best_encoderUsed by the atomic helpers to select the encoder, through the
drm_connector_helper_funcs.atomic_best_encoderordrm_connector_helper_funcs.best_encodercallbacks.This is also used in the atomic helpers to map encoders to theircurrent and previous connectors, see
drm_atomic_get_old_connector_for_encoder()anddrm_atomic_get_new_connector_for_encoder().NOTE: Atomic drivers must fill this out (either themselves or throughhelpers), for otherwise the GETCONNECTOR and GETENCODER IOCTLs willnot return correct data to userspace.
link_statusConnector link_status to keep track of whether link isGOOD or BAD to notify userspace if retraining is necessary.
statebackpointer to global drm_atomic_state
commitTracks the pending commit to prevent use-after-free conditions.
Is only set whencrtc is NULL.
tvTV connector state
self_refresh_awareThis tracks whether a connector is aware of the self refresh state.It should be set to true for those connector implementations whichunderstand the self refresh state. This is needed since the crtcregisters the self refresh helpers and it doesn’t know if theconnectors downstream have implemented self refresh entry/exit.
Drivers should set this to true in atomic_check if they know how tohandle self_refresh requests.
picture_aspect_ratioConnector property to control theHDMI infoframe aspect ratio setting.
The
DRM_MODE_PICTURE_ASPECT_* values much match thevalues forenumhdmi_picture_aspectcontent_typeConnector property to control theHDMI infoframe content type setting.The
DRM_MODE_CONTENT_TYPE_* values muchmatch the values.hdcp_content_typeConnector property to pass the type ofprotected content. This is most commonly used for HDCP.
scaling_modeConnector property to control theupscaling, mostly used for built-in panels.
content_protectionConnector property to request contentprotection. This is most commonly used for HDCP.
colorspaceState variable for Connector property to requestcolorspace change on Sink. This is most commonly used to switchto wider color gamuts like BT2020.
writeback_jobWriteback job for writeback connectors
Holds the framebuffer and out-fence for a writeback connector. Asthe writeback completion may be asynchronous to the normal commitcycle, the writeback job lifetime is managed separately from thenormal atomic state by this object.
See also:
drm_writeback_queue_job()anddrm_writeback_signal_completion()max_requested_bpcConnector property to limit the maximum bitdepth of the pixels.
max_bpcConnector max_bpc based on the requested max_bpc propertyand the connector bpc limitations obtained from edid.
privacy_screen_sw_statehdr_output_metadataDRM blob property for HDR output metadata
hdmiHDMI-related variable and properties. Filled by
drm_atomic_helper_connector_hdmi_check().
- structdrm_connector_cec_funcs¶
drm_hdmi_connector control functions
Definition:
struct drm_connector_cec_funcs { void (*phys_addr_invalidate)(struct drm_connector *connector); void (*phys_addr_set)(struct drm_connector *connector, u16 addr);};Members
phys_addr_invalidatemark CEC physical address as invalid
The callback to mark CEC physical address as invalid, abstractingthe operation.
phys_addr_setset CEC physical address
The callback to set CEC physical address, abstracting the operation.
- structdrm_connector_infoframe_funcs¶
InfoFrame-related functions
Definition:
struct drm_connector_infoframe_funcs { int (*clear_infoframe)(struct drm_connector *connector); int (*write_infoframe)(struct drm_connector *connector, const u8 *buffer, size_t len);};Members
clear_infoframeThis callback is invoked throughdrm_atomic_helper_connector_hdmi_update_infoframes during acommit to clear the infoframes into the hardware. It will becalled once for each frame type to be disabled.
Theclear_infoframe callback is mandatory for AVI and HDMI-VSInfoFrame types.
Returns:0 on success, a negative error code otherwise
write_infoframeThis callback is invoked throughdrm_atomic_helper_connector_hdmi_update_infoframes during acommit to program the infoframes into the hardware. It willbe called for every updated infoframe type.
Thewrite_infoframe callback is mandatory for AVI and HDMI-VSInfoFrame types.
Returns:0 on success, a negative error code otherwise
- structdrm_connector_hdmi_funcs¶
drm_hdmi_connector control functions
Definition:
struct drm_connector_hdmi_funcs { enum drm_mode_status (*tmds_char_rate_valid)(const struct drm_connector *connector, const struct drm_display_mode *mode, unsigned long long tmds_rate); const struct drm_edid *(*read_edid)(struct drm_connector *connector); struct drm_connector_infoframe_funcs avi; struct drm_connector_infoframe_funcs hdmi; struct drm_connector_infoframe_funcs audio; struct drm_connector_infoframe_funcs hdr_drm; struct drm_connector_infoframe_funcs spd;};Members
tmds_char_rate_validThis callback is invoked at atomic_check time to figure outwhether a particular TMDS character rate is supported by thedriver.
Thetmds_char_rate_valid callback is optional.
Returns:
Either
drm_mode_status.MODE_OKor one of the failure reasonsinenumdrm_mode_status.read_edidThis callback is used by the framework as a replacement for readingthe EDID from connector->ddc. It is still recommended to provideconnector->ddc instead of implementing this callback. Returned EDIDshould be freed via the
drm_edid_free().Theread_edid callback is optional.
Returns:Valid EDID on success, NULL in case of failure.
aviSet of callbacks for handling the AVI InfoFrame. These callbacks aremandatory.
hdmiSet of callbacks for handling the HDMI Vendor-Specific InfoFrame.These callbacks are mandatory.
audioSet of callbacks for handling the Audio InfoFrame. These callbacksare optional, but they are required for drivers which use
drm_atomic_helper_connector_hdmi_update_audio_infoframe().hdr_drmSet of callbacks for handling the HDR DRM InfoFrame. These callbacksare mandatory if HDR output is to be supported.
spdSet of callbacks for handling the SPD InfoFrame. These callbacks areoptional.
- structdrm_connector_funcs¶
control connectors on a given device
Definition:
struct drm_connector_funcs { int (*dpms)(struct drm_connector *connector, int mode); void (*reset)(struct drm_connector *connector); enum drm_connector_status (*detect)(struct drm_connector *connector, bool force); void (*force)(struct drm_connector *connector); int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height); int (*set_property)(struct drm_connector *connector, struct drm_property *property, uint64_t val); int (*late_register)(struct drm_connector *connector); void (*early_unregister)(struct drm_connector *connector); void (*destroy)(struct drm_connector *connector); struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector); void (*atomic_destroy_state)(struct drm_connector *connector, struct drm_connector_state *state); int (*atomic_set_property)(struct drm_connector *connector, struct drm_connector_state *state, struct drm_property *property, uint64_t val); int (*atomic_get_property)(struct drm_connector *connector, const struct drm_connector_state *state, struct drm_property *property, uint64_t *val); void (*atomic_print_state)(struct drm_printer *p, const struct drm_connector_state *state); void (*oob_hotplug_event)(struct drm_connector *connector, enum drm_connector_status status); void (*debugfs_init)(struct drm_connector *connector, struct dentry *root);};Members
dpmsLegacy entry point to set the per-connector DPMS state. Legacy DPMSis exposed as a standard property on the connector, but diverted tothis callback in the drm core. Note that atomic drivers don’timplement the 4 level DPMS support on the connector any more, butinstead only have an on/off “ACTIVE” property on the CRTC object.
This hook is not used by atomic drivers, remapping of the legacy DPMSproperty is entirely handled in the DRM core.
RETURNS:
0 on success or a negative error code on failure.
resetReset connector hardware and software state to off. This function isn’tcalled by the core directly, only through
drm_mode_config_reset().It’s not a helper hook only for historical reasons.Atomic drivers can use
drm_atomic_helper_connector_reset()to resetatomic state using this hook.detectCheck to see if anything is attached to the connector. The parameterforce is set to false whilst polling, true when checking theconnector due to a user request. force can be used by the driver toavoid expensive, destructive operations during automated probing.
This callback is optional, if not implemented the connector will beconsidered as always being attached.
FIXME:
Note that this hook is only called by the probe helper. It’s not inthe helper library vtable purely for historical reasons. The only DRMcore entry point to probe connector state isfill_modes.
Note that the helper library will already hold
drm_mode_config.connection_mutex. Drivers which need to grab additionallocks to avoid races with concurrent modeset changes need to usedrm_connector_helper_funcs.detect_ctxinstead.Also note that this callback can be called no matter thestate the connector is in. Drivers that need the underlyingdevice to be powered to perform the detection will first needto make sure it’s been properly enabled.
RETURNS:
drm_connector_status indicating the connector’s status.
forceThis function is called to update internal encoder state when theconnector is forced to a certain state by userspace, either throughthe sysfs interfaces or on the kernel cmdline. In that case thedetect callback isn’t called.
FIXME:
Note that this hook is only called by the probe helper. It’s not inthe helper library vtable purely for historical reasons. The only DRMcore entry point to probe connector state isfill_modes.
fill_modesEntry point for output detection and basic mode validation. Thedriver should reprobe the output if needed (e.g. when hotplughandling is unreliable), add all detected modes to
drm_connector.modesand filter out any the device can’t support in any configuration. Italso needs to filter out any modes wider or higher than theparameters max_width and max_height indicate.The drivers must also prune any modes no longer valid from
drm_connector.modes. Furthermore it must updatedrm_connector.statusanddrm_connector.edid. If no EDID has beenreceived for this output connector->edid must be NULL.Drivers using the probe helpers should use
drm_helper_probe_single_connector_modes()to implement thisfunction.RETURNS:
The number of modes detected and filled into
drm_connector.modes.set_propertyThis is the legacy entry point to update a property attached to theconnector.
This callback is optional if the driver does not support any legacydriver-private properties. For atomic drivers it is not used becauseproperty handling is done entirely in the DRM core.
RETURNS:
0 on success or a negative error code on failure.
late_registerThis optional hook can be used to register additional userspaceinterfaces attached to the connector, light backlight control, i2c,DP aux or similar interfaces. It is called late in the driver loadsequence from
drm_connector_register()when registering all thecore drm connector interfaces. Everything added from this callbackshould be unregistered in the early_unregister callback.This is called while holding
drm_connector.mutex.Returns:
0 on success, or a negative error code on failure.
early_unregisterThis optional hook should be used to unregister the additionaluserspace interfaces attached to the connector from
late_register(). It is called fromdrm_connector_unregister(),early in the driver unload sequence to disable userspace accessbefore data structures are torndown.This is called while holding
drm_connector.mutex.destroyClean up connector resources. This is called at driver unload timethrough
drm_mode_config_cleanup(). It can also be called at runtimewhen a connector is being hot-unplugged for drivers that supportconnector hotplugging (e.g. DisplayPort MST).atomic_duplicate_stateDuplicate the current atomic state for this connector and return it.The core and helpers guarantee that any atomic state duplicated withthis hook and still owned by the caller (i.e. not transferred to thedriver by calling
drm_mode_config_funcs.atomic_commit) will becleaned up by calling theatomic_destroy_state hook in thisstructure.This callback is mandatory for atomic drivers.
Atomic drivers which don’t subclass
structdrm_connector_stateshould usedrm_atomic_helper_connector_duplicate_state(). Drivers that subclass thestate structure to extend it with driver-private state should use__drm_atomic_helper_connector_duplicate_state()to make sure shared state isduplicated in a consistent fashion across drivers.It is an error to call this hook before
drm_connector.statehas beeninitialized correctly.NOTE:
If the duplicate state references refcounted resources this hook mustacquire a reference for each of them. The driver must release thesereferences again inatomic_destroy_state.
RETURNS:
Duplicated atomic state or NULL when the allocation failed.
atomic_destroy_stateDestroy a state duplicated withatomic_duplicate_state and releaseor unreference all resources it references
This callback is mandatory for atomic drivers.
atomic_set_propertyDecode a driver-private property value and store the decoded valueinto the passed-in state structure. Since the atomic core decodes allstandardized properties (even for extensions beyond the core set ofproperties which might not be implemented by all drivers) thisrequires drivers to subclass the state structure.
Such driver-private properties should really only be implemented fortruly hardware/vendor specific state. Instead it is preferred tostandardize atomic extension and decode the properties used to exposesuch an extension in the core.
Do not call this function directly, use
drm_atomic_connector_set_property()instead.This callback is optional if the driver does not support anydriver-private atomic properties.
NOTE:
This function is called in the state assembly phase of atomicmodesets, which can be aborted for any reason (including onuserspace’s request to just check whether a configuration would bepossible). Drivers MUST NOT touch any persistent state (hardware orsoftware) or data structures except the passed instate parameter.
Also since userspace controls in which order properties are set thisfunction must not do any input validation (since the state update isincomplete and hence likely inconsistent). Instead any such inputvalidation must be done in the various atomic_check callbacks.
RETURNS:
0 if the property has been found, -EINVAL if the property isn’timplemented by the driver (which shouldn’t ever happen, the core onlyasks for properties attached to this connector). No other validationis allowed by the driver. The core already checks that the propertyvalue is within the range (integer, valid
enumvalue, ...) the driverset when registering the property.atomic_get_propertyReads out the decoded driver-private property. This is used toimplement the GETCONNECTOR IOCTL.
Do not call this function directly, use
drm_atomic_connector_get_property()instead.This callback is optional if the driver does not support anydriver-private atomic properties.
RETURNS:
0 on success, -EINVAL if the property isn’t implemented by thedriver (which shouldn’t ever happen, the core only asks forproperties attached to this connector).
atomic_print_stateIf driver subclasses
structdrm_connector_state, it should implementthis optional hook for printing additional driver specific state.Do not call this directly, use
drm_atomic_connector_print_state()instead.oob_hotplug_eventThis will get called when a hotplug-event for a drm-connectorhas been received from a source outside the display driver / device.
debugfs_initAllows connectors to create connector-specific debugfs files.
Description
Each CRTC may have one or more connectors attached to it. The functionsbelow allow the core DRM code to control connectors, enumerate available modes,etc.
- structdrm_cmdline_mode¶
DRM Mode passed through the kernel command-line
Definition:
struct drm_cmdline_mode { char name[DRM_DISPLAY_MODE_LEN]; bool specified; bool refresh_specified; bool bpp_specified; unsigned int pixel_clock; int xres; int yres; int bpp; int refresh; bool rb; bool interlace; bool cvt; bool margins; enum drm_connector_force force; unsigned int rotation_reflection; enum drm_panel_orientation panel_orientation; struct drm_connector_tv_margins tv_margins; enum drm_connector_tv_mode tv_mode; bool tv_mode_specified;};Members
nameName of the mode.
specifiedHas a mode been read from the command-line?
refresh_specifiedDid the mode have a preferred refresh rate?
bpp_specifiedDid the mode have a preferred BPP?
pixel_clockPixel Clock in kHz. Optional.
xresActive resolution on the X axis, in pixels.
yresActive resolution on the Y axis, in pixels.
bppBits per pixels for the mode.
refreshRefresh rate, in Hertz.
rbDo we need to use reduced blanking?
interlaceThe mode is interlaced.
cvtThe timings will be calculated using the VESA CoordinatedVideo Timings instead of looking up the mode from a table.
marginsAdd margins to the mode calculation (1.8% of xres roundeddown to 8 pixels and 1.8% of yres).
forceIgnore the hotplug state of the connector, and force itsstate to one of the DRM_FORCE_* values.
rotation_reflectionInitial rotation and reflection of the mode setup from thecommand line. See DRM_MODE_ROTATE_* andDRM_MODE_REFLECT_*. The only rotations supported areDRM_MODE_ROTATE_0 and DRM_MODE_ROTATE_180.
panel_orientationdrm-connector “panel orientation” property override value,DRM_MODE_PANEL_ORIENTATION_UNKNOWN if not set.
tv_marginsTV margins to apply to the mode.
tv_modeTV mode standard. See DRM_MODE_TV_MODE_*.
tv_mode_specifiedDid the mode have a preferred TV mode?
Description
Each connector can have an initial mode with additional optionspassed through the kernel command line. This structure allows toexpress those parameters and will be filled by the command-lineparser.
- structdrm_connector_hdmi_audio¶
DRM gemeric HDMI Codec-related structure
Definition:
struct drm_connector_hdmi_audio { const struct drm_connector_hdmi_audio_funcs *funcs; struct platform_device *codec_pdev; struct mutex lock; void (*plugged_cb)(struct device *dev, bool plugged); struct device *plugged_cb_dev; bool last_state; int dai_port;};Members
funcsImplementation of the HDMI codec functionality to be used by the DRMHDMI Codec framework.
codec_pdevPlatform device created to hold the HDMI Codec. It will beautomatically unregistered during
drm_connector_cleanup().lockMutex to protectlast_state,plugged_cb andplugged_cb_dev.
plugged_cbCallback to be called when the HDMI sink get plugged to or unpluggedfrom this connector. This is assigned by the framework whenrequested by the ASoC code.
plugged_cb_devThe data for
plugged_cb(). It is being provided by the ASoC.last_stateLast plugged state recored by the framework. It is used to correctlyreport the state to
plugged_cb().dai_portThe port in DT that is used for the Codec DAI.
Description
HDMI drivers usually incorporate a HDMI Codec. This structure expresses thegeneric HDMI Codec as used by the DRM HDMI Codec framework.
- structdrm_connector_cec¶
DRM Connector CEC-related structure
Definition:
struct drm_connector_cec { struct mutex mutex; const struct drm_connector_cec_funcs *funcs; void *data;};Members
mutexprotects all fields in this structure.
funcsCEC Control Functions
dataCEC implementation-specific data
- structdrm_connector¶
central DRM connector control structure
Definition:
struct drm_connector { struct drm_device *dev; struct device *kdev; struct device_attribute *attr; struct fwnode_handle *fwnode; struct list_head head; struct list_head global_connector_list_entry; struct drm_mode_object base; char *name; struct mutex mutex; unsigned index; int connector_type; int connector_type_id; bool interlace_allowed; bool doublescan_allowed; bool stereo_allowed; bool ycbcr_420_allowed; enum drm_connector_registration_state registration_state; struct list_head modes; enum drm_connector_status status; struct list_head probed_modes; struct drm_display_info display_info; const struct drm_connector_funcs *funcs; struct drm_property_blob *edid_blob_ptr; struct drm_object_properties properties; struct drm_property *scaling_mode_property; struct drm_property *vrr_capable_property; struct drm_property *colorspace_property; struct drm_property_blob *path_blob_ptr; unsigned int max_bpc; struct drm_property *max_bpc_property; struct drm_privacy_screen *privacy_screen; struct notifier_block privacy_screen_notifier; struct drm_property *privacy_screen_sw_state_property; struct drm_property *privacy_screen_hw_state_property; struct drm_property *broadcast_rgb_property;#define DRM_CONNECTOR_POLL_HPD (1 << 0);#define DRM_CONNECTOR_POLL_CONNECT (1 << 1);#define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2); uint8_t polled; int dpms; const struct drm_connector_helper_funcs *helper_private; struct drm_cmdline_mode cmdline_mode; enum drm_connector_force force; const struct drm_edid *edid_override; struct mutex edid_override_mutex; u64 epoch_counter; u32 possible_encoders; struct drm_encoder *encoder;#define MAX_ELD_BYTES 128; uint8_t eld[MAX_ELD_BYTES]; struct mutex eld_mutex; bool latency_present[2]; int video_latency[2]; int audio_latency[2]; struct i2c_adapter *ddc; int null_edid_counter; unsigned bad_edid_counter; bool edid_corrupt; u8 real_edid_checksum; struct dentry *debugfs_entry; struct drm_connector_state *state; struct drm_property_blob *tile_blob_ptr; bool has_tile; struct drm_tile_group *tile_group; bool tile_is_single_monitor; uint8_t num_h_tile, num_v_tile; uint8_t tile_h_loc, tile_v_loc; uint16_t tile_h_size, tile_v_size; struct llist_node free_node; struct drm_connector_hdmi hdmi; struct drm_connector_hdmi_audio hdmi_audio; struct drm_connector_cec cec;};Members
devparent DRM device
kdevkernel device for sysfs attributes
attrsysfs attributes
fwnodeassociated fwnode supplied by platform firmware
Drivers can set this to associate a fwnode with a connector, driversare expected to get a reference on the fwnode when setting this.
drm_connector_cleanup()will callfwnode_handle_put()on this.headList of all connectors on adev, linked from
drm_mode_config.connector_list. Protected bydrm_mode_config.connector_list_lock, but please only usedrm_connector_list_iterto walk this list.global_connector_list_entryConnector entry in the global connector-list, used by
drm_connector_find_by_fwnode().basebase KMS object
namehuman readable name, can be overwritten by the driver
mutexLock for general connector state, but currently only protectsregistered. Most of the connector state is still protected by
drm_mode_config.mutex.indexCompacted connector index, which matches the position insidethe mode_config.list for drivers not supporting hot-add/removing. Canbe used as an array index. It is invariant over the lifetime of theconnector.
connector_typeone of the DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
connector_type_idindex into connector type enum
interlace_allowedCan this connector handle interlaced modes? Only used by
drm_helper_probe_single_connector_modes()for mode filtering.doublescan_allowedCan this connector handle doublescan? Only used by
drm_helper_probe_single_connector_modes()for mode filtering.stereo_allowedCan this connector handle stereo modes? Only used by
drm_helper_probe_single_connector_modes()for mode filtering.ycbcr_420_allowedThis bool indicates if this connector iscapable of handling YCBCR 420 output. While parsing the EDIDblocks it’s very helpful to know if the source is capable ofhandling YCBCR 420 outputs.
registration_stateIs this connector initializing, exposed(registered) with userspace, or unregistered?
Protected bymutex.
modesModes available on this connector (from
fill_modes()+ user).Protected bydrm_mode_config.mutex.statusOne of the drm_connector_status enums (connected, not, or unknown).Protected by
drm_mode_config.mutex.probed_modesThese are modes added by probing with DDC or the BIOS, beforefiltering is applied. Used by the probe helpers. Protected by
drm_mode_config.mutex.display_infoDisplay information is filled from EDID informationwhen a display is detected. For non hot-pluggable displays such asflat panels in embedded systems, the driver should initialize the
drm_display_info.width_mmanddrm_display_info.height_mmfieldswith the physical size of the display.Protected by
drm_mode_config.mutex.funcsconnector control functions
edid_blob_ptrDRM property containing EDID if present. Protected by
drm_mode_config.mutex.This must be updated only by calling
drm_edid_connector_update()ordrm_connector_update_edid_property().This must not be used by drivers directly.
propertiesproperty tracking for this connector
scaling_mode_propertyOptional atomic property to control theupscaling. See
drm_connector_attach_content_protection_property().vrr_capable_propertyOptional property to help userspacequery hardware support for variable refresh rate on a connector.connector. Drivers can add the property to a connector bycalling
drm_connector_attach_vrr_capable_property().This should be updated only by calling
drm_connector_set_vrr_capable_property().colorspace_propertyConnector property to set the suitablecolorspace supported by the sink.
path_blob_ptrDRM blob property data for the DP MST path property. This should onlybe updated by calling
drm_connector_set_path_property().max_bpcMaximum bits per color channel the connector supports.
max_bpc_propertyDefault connector property for the max bpc to bedriven out of the connector.
privacy_screendrm_privacy_screen for this connector, or NULL.
privacy_screen_notifierprivacy-screen notifier_block
privacy_screen_sw_state_propertyOptional atomic property for theconnector to control the integrated privacy screen.
privacy_screen_hw_state_propertyOptional atomic property for theconnector to report the actual integrated privacy screen state.
broadcast_rgb_propertyConnector property to set theBroadcast RGB selection to output with.
polledConnector polling mode, a combination of
- DRM_CONNECTOR_POLL_HPD
The connector generates hotplug events and doesn’t need to beperiodically polled. The CONNECT and DISCONNECT flags must notbe set together with the HPD flag.
- DRM_CONNECTOR_POLL_CONNECT
Periodically poll the connector for connection.
- DRM_CONNECTOR_POLL_DISCONNECT
Periodically poll the connector for disconnection, withoutcausing flickering even when the connector is in use. DACs shouldrarely do this without a lot of testing.
Set to 0 for connectors that don’t support connection statusdiscovery.
dpmsCurrent dpms state. For legacy drivers the
drm_connector_funcs.dpmscallback must update this. For atomicdrivers, this is handled by the core atomic code, and drivers mustonly takedrm_crtc_state.activeinto account.helper_privatemid-layer private data
cmdline_modemode line parsed from the kernel cmdline for this connector
forcea DRM_FORCE_<foo> state for forced mode sets
edid_overrideOverride EDID set via debugfs.
Do not modify or access outside of the drm_edid_override_* family offunctions.
edid_override_mutexProtect access to edid_override.
epoch_counterused to detect any other changes in connector, besides status
possible_encodersBit mask of encoders that can drive thisconnector,
drm_encoder_index()determines the index into the bitfieldand the bits are set withdrm_connector_attach_encoder().encoderCurrently bound encoder driving this connector, if any.Only really meaningful for non-atomic drivers. Atomic drivers shouldinstead look at
drm_connector_state.best_encoder, and in case theyneed the CRTC driving this output,drm_connector_state.crtc.eldEDID-like data, if present, protected byeld_mutex
eld_mutexprotection for concurrenct access toeld
latency_presentAV delay info from ELD, if found
video_latencyVideo latency info from ELD, if found.[0]: progressive, [1]: interlaced
audio_latencyaudio latency info from ELD, if found[0]: progressive, [1]: interlaced
ddcassociated ddc adapter.A connector usually has its associated ddc adapter. If a driver usesthis field, then an appropriate symbolic link is created in connectorsysfs directory to make it easy for the user to tell which i2cadapter is for a particular display.
The field should be set by calling
drm_connector_init_with_ddc().null_edid_countertrack sinks that give us all zeros for the EDID.Needed to workaround some HW bugs where we get all 0s
bad_edid_countertrack sinks that give us an EDID with invalid checksum
edid_corruptIndicates whether the last read EDID was corrupt. Usedin Displayport compliance testing - Displayport Link CTS Core 1.2rev1.1 4.2.2.6
real_edid_checksumreal edid checksum for corrupted edid block.Required in Displayport 1.4 compliance testingrev1.1 4.2.2.6
debugfs_entrydebugfs directory for this connector
stateCurrent atomic state for this connector.
This is protected by
drm_mode_config.connection_mutex. Note thatnonblocking atomic commits access the current connector state withouttaking locks. Either by going through thestructdrm_atomic_statepointers, seefor_each_oldnew_connector_in_state(),for_each_old_connector_in_state()andfor_each_new_connector_in_state(). Or through careful ordering ofatomic commit operations as implemented in the atomic helpers, seestructdrm_crtc_commit.tile_blob_ptrDRM blob property data for the tile property (used mostly by DP MST).This is meant for screens which are driven through separate displaypipelines represented by
drm_crtc, which might not be running withgenlocked clocks. For tiled panels which are genlocked, likedual-link LVDS or dual-link DSI, the driver should try to not exposethe tiling and virtualize bothdrm_crtcanddrm_planeif needed.This should only be updated by calling
drm_connector_set_tile_property().has_tileis this connector connected to a tiled monitor
tile_grouptile group for the connected monitor
tile_is_single_monitorwhether the tile is one monitor housing
num_h_tilenumber of horizontal tiles in the tile group
num_v_tilenumber of vertical tiles in the tile group
tile_h_lochorizontal location of this tile
tile_v_locvertical location of this tile
tile_h_sizehorizontal size of this tile.
tile_v_sizevertical size of this tile.
free_nodeList used only by
drm_connector_list_iterto be able to clean up aconnector from any context, in conjunction withdrm_mode_config.connector_free_work.hdmiHDMI-related variable and properties.
hdmi_audioHDMI codec properties and non-DRM state.
cecCEC-related data.
Description
Each connector may be connected to one or more CRTCs, or may be clonable byanother connector if they can share a CRTC. Each connector also has a specificposition in the broader display (referred to as a ‘screen’ though it couldspan multiple monitors).
- structdrm_connector*drm_connector_lookup(structdrm_device*dev,structdrm_file*file_priv,uint32_tid)¶
lookup connector object
Parameters
structdrm_device*devDRM device
structdrm_file*file_privdrm file to check for lease against.
uint32_tidconnector object id
Description
This function looks up the connector object specified by idadd takes a reference to it.
- voiddrm_connector_get(structdrm_connector*connector)¶
acquire a connector reference
Parameters
structdrm_connector*connectorDRM connector
Description
This function increments the connector’s refcount.
- voiddrm_connector_put(structdrm_connector*connector)¶
release a connector reference
Parameters
structdrm_connector*connectorDRM connector
Description
This function decrements the connector’s reference count and frees theobject if the reference count drops to zero.
- booldrm_connector_is_unregistered(structdrm_connector*connector)¶
has the connector been unregistered from userspace?
Parameters
structdrm_connector*connectorDRM connector
Description
Checks whether or notconnector has been unregistered from userspace.
Return
True if the connector was unregistered, false if the connector isregistered or has not yet been registered with userspace.
- structdrm_tile_group¶
Tile group metadata
Definition:
struct drm_tile_group { struct kref refcount; struct drm_device *dev; int id; u8 group_data[8];};Members
refcountreference count
devDRM device
idtile group id exposed to userspace
group_dataSink-private data identifying this group
Description
group_data corresponds to displayid vend/prod/serial for external screenswith an EDID.
- structdrm_connector_list_iter¶
connector_list iterator
Definition:
struct drm_connector_list_iter {};Members
Description
This iterator tracks state needed to be able to walk the connector_listwithinstructdrm_mode_config. Only use together withdrm_connector_list_iter_begin(),drm_connector_list_iter_end() anddrm_connector_list_iter_next() respectively the convenience macrodrm_for_each_connector_iter().
Note that the return value ofdrm_connector_list_iter_next() is only validup to the nextdrm_connector_list_iter_next() ordrm_connector_list_iter_end() call. If you want to use the connector later,then you need to grab your own reference first usingdrm_connector_get().
- drm_for_each_connector_iter¶
drm_for_each_connector_iter(connector,iter)
connector_list iterator macro
Parameters
connectorstructdrm_connectorpointer used as cursoriter
Description
Note thatconnector is only valid within the list body, if you want to useconnector after callingdrm_connector_list_iter_end() then you need to grabyour own reference first usingdrm_connector_get().
- drm_connector_for_each_possible_encoder¶
drm_connector_for_each_possible_encoder(connector,encoder)
iterate connector’s possible encoders
Parameters
connectorstructdrm_connectorpointerencoderstructdrm_encoderpointer used as cursor
- constchar*drm_get_connector_type_name(unsignedinttype)¶
return a string for connector type
Parameters
unsignedinttypeThe connector type (DRM_MODE_CONNECTOR_*)
Return
the name of the connector type, or NULL if the type is not valid.
- intdrm_connector_init(structdrm_device*dev,structdrm_connector*connector,conststructdrm_connector_funcs*funcs,intconnector_type)¶
Init a preallocated connector
Parameters
structdrm_device*devDRM device
structdrm_connector*connectorthe connector to init
conststructdrm_connector_funcs*funcscallbacks for this connector
intconnector_typeuser visible type of the connector
Description
Initialises a preallocated connector. Connectors should besubclassed as part of driver connector objects.
At driver unload time the driver’sdrm_connector_funcs.destroy hookshould calldrm_connector_cleanup() and free the connector structure.The connector structure should not be allocated withdevm_kzalloc().
Note
consider usingdrmm_connector_init() instead ofdrm_connector_init() to let the DRM managed resource infrastructuretake care of cleanup and deallocation.
Return
Zero on success, error code on failure.
- intdrm_connector_dynamic_init(structdrm_device*dev,structdrm_connector*connector,conststructdrm_connector_funcs*funcs,intconnector_type,structi2c_adapter*ddc)¶
Init a preallocated dynamic connector
Parameters
structdrm_device*devDRM device
structdrm_connector*connectorthe connector to init
conststructdrm_connector_funcs*funcscallbacks for this connector
intconnector_typeuser visible type of the connector
structi2c_adapter*ddcpointer to the associated ddc adapter
Description
Initialises a preallocated dynamic connector. Connectors should besubclassed as part of driver connector objects. The connectorstructure should not be allocated withdevm_kzalloc().
Drivers should call this for dynamic connectors which can be hotpluggedafterdrm_dev_register() has been called already, e.g. DP MST connectors.For all other - static - connectors, drivers should call one of thedrm_connector_init*()/drmm_connector_init*() functions.
After calling this function the drivers must calldrm_connector_dynamic_register().
To remove the connector the driver must calldrm_connector_unregister()followed bydrm_connector_put(). Putting the last reference will call thedriver’sdrm_connector_funcs.destroy hook, which in turn must calldrm_connector_cleanup() and free the connector structure.
Return
Zero on success, error code on failure.
- intdrm_connector_init_with_ddc(structdrm_device*dev,structdrm_connector*connector,conststructdrm_connector_funcs*funcs,intconnector_type,structi2c_adapter*ddc)¶
Init a preallocated connector
Parameters
structdrm_device*devDRM device
structdrm_connector*connectorthe connector to init
conststructdrm_connector_funcs*funcscallbacks for this connector
intconnector_typeuser visible type of the connector
structi2c_adapter*ddcpointer to the associated ddc adapter
Description
Initialises a preallocated connector. Connectors should besubclassed as part of driver connector objects.
At driver unload time the driver’sdrm_connector_funcs.destroy hookshould calldrm_connector_cleanup() and free the connector structure.The connector structure should not be allocated withdevm_kzalloc().
Ensures that the ddc field of the connector is correctly set.
Note
consider usingdrmm_connector_init() instead ofdrm_connector_init_with_ddc() to let the DRM managed resourceinfrastructure take care of cleanup and deallocation.
Return
Zero on success, error code on failure.
- intdrmm_connector_init(structdrm_device*dev,structdrm_connector*connector,conststructdrm_connector_funcs*funcs,intconnector_type,structi2c_adapter*ddc)¶
Init a preallocated connector
Parameters
structdrm_device*devDRM device
structdrm_connector*connectorthe connector to init
conststructdrm_connector_funcs*funcscallbacks for this connector
intconnector_typeuser visible type of the connector
structi2c_adapter*ddcoptional pointer to the associated ddc adapter
Description
Initialises a preallocated connector. Connectors should besubclassed as part of driver connector objects.
Cleanup is automatically handled with a call todrm_connector_cleanup() in a DRM-managed action.
The connector structure should be allocated withdrmm_kzalloc().
Thedrm_connector_funcs.destroy hook must be NULL.
Return
Zero on success, error code on failure.
- intdrmm_connector_hdmi_init(structdrm_device*dev,structdrm_connector*connector,constchar*vendor,constchar*product,conststructdrm_connector_funcs*funcs,conststructdrm_connector_hdmi_funcs*hdmi_funcs,intconnector_type,structi2c_adapter*ddc,unsignedlongsupported_formats,unsignedintmax_bpc)¶
Init a preallocated HDMI connector
Parameters
structdrm_device*devDRM device
structdrm_connector*connectorA pointer to the HDMI connector to init
constchar*vendorHDMI Controller Vendor name
constchar*productHDMI Controller Product name
conststructdrm_connector_funcs*funcscallbacks for this connector
conststructdrm_connector_hdmi_funcs*hdmi_funcsHDMI-related callbacks for this connector
intconnector_typeuser visible type of the connector
structi2c_adapter*ddcoptional pointer to the associated ddc adapter
unsignedlongsupported_formatsBitmask ofhdmi_colorspace listing supported output formats
unsignedintmax_bpcMaximum bits per char the HDMI connector supports
Description
Initialises a preallocated HDMI connector. Connectors can besubclassed as part of driver connector objects.
Cleanup is automatically handled with a call todrm_connector_cleanup() in a DRM-managed action.
The connector structure should be allocated withdrmm_kzalloc().
Thedrm_connector_funcs.destroy hook must be NULL.
Return
Zero on success, error code on failure.
- voiddrm_connector_attach_edid_property(structdrm_connector*connector)¶
attach edid property.
Parameters
structdrm_connector*connectorthe connector
Description
Some connector types like DRM_MODE_CONNECTOR_VIRTUAL do not get aedid property attached by default. This function can be used toexplicitly enable the edid property in these cases.
- intdrm_connector_attach_encoder(structdrm_connector*connector,structdrm_encoder*encoder)¶
attach a connector to an encoder
Parameters
structdrm_connector*connectorconnector to attach
structdrm_encoder*encoderencoder to attachconnector to
Description
This function links up a connector to an encoder. Note that the routingrestrictions between encoders and crtcs are exposed to userspace through thepossible_clones and possible_crtcs bitmasks.
Return
Zero on success, negative errno on failure.
- booldrm_connector_has_possible_encoder(structdrm_connector*connector,structdrm_encoder*encoder)¶
check if the connector and encoder are associated with each other
Parameters
structdrm_connector*connectorthe connector
structdrm_encoder*encoderthe encoder
Return
True ifencoder is one of the possible encoders forconnector.
- voiddrm_connector_cec_phys_addr_invalidate(structdrm_connector*connector)¶
invalidate CEC physical address
Parameters
structdrm_connector*connectorconnector undergoing CEC operation
Description
Invalidated CEC physical address set for this DRM connector.
- voiddrm_connector_cec_phys_addr_set(structdrm_connector*connector)¶
propagate CEC physical address
Parameters
structdrm_connector*connectorconnector undergoing CEC operation
Description
Propagate CEC physical address from the display_info to this DRM connector.
- voiddrm_connector_cleanup(structdrm_connector*connector)¶
cleans up an initialised connector
Parameters
structdrm_connector*connectorconnector to cleanup
Description
Cleans up the connector but doesn’t free the object.
- intdrm_connector_register(structdrm_connector*connector)¶
register a connector
Parameters
structdrm_connector*connectorthe connector to register
Description
Register userspace interfaces for a connector. Drivers shouldn’t call thisfunction. Static connectors will be registered automatically by DRM corefromdrm_dev_register(), dynamic connectors (MST) should be registered bydrivers callingdrm_connector_dynamic_register().
When the connector is no longer available, callers must calldrm_connector_unregister().
Note
Existing uses of this function in drivers should be a nop already andare scheduled to be removed.
Return
Zero on success, error code on failure.
- intdrm_connector_dynamic_register(structdrm_connector*connector)¶
register a dynamic connector
Parameters
structdrm_connector*connectorthe connector to register
Description
Register userspace interfaces for a connector. Only call this for connectorsinitialized by callingdrm_connector_dynamic_init(). All other connectorswill be registered automatically when callingdrm_dev_register().
When the connector is no longer available the driver must calldrm_connector_unregister().
Return
Zero on success, error code on failure.
- voiddrm_connector_unregister(structdrm_connector*connector)¶
unregister a connector
Parameters
structdrm_connector*connectorthe connector to unregister
Description
Unregister userspace interfaces for a connector. Drivers should call thisfor dynamic connectors (MST) only, which were registered explicitly bycallingdrm_connector_dynamic_register(). All other - static - connectorswill be unregistered automatically by DRM core and drivers shouldn’t callthis function for those.
Note
Existing uses of this function in drivers for static connectorsshould be a nop already and are scheduled to be removed.
- constchar*drm_get_connector_status_name(enumdrm_connector_statusstatus)¶
return a string for connector status
Parameters
enumdrm_connector_statusstatusconnector status to compute name of
Description
In contrast to the other drm_get_*_name functions this one here returns aconst pointer and hence is threadsafe.
Return
connector status string
- voiddrm_connector_list_iter_begin(structdrm_device*dev,structdrm_connector_list_iter*iter)¶
initialize a connector_list iterator
Parameters
structdrm_device*devDRM device
structdrm_connector_list_iter*iterconnector_list iterator
Description
Setsiter up to walk thedrm_mode_config.connector_list ofdev.itermust always be cleaned up again by callingdrm_connector_list_iter_end().Iteration itself happens usingdrm_connector_list_iter_next() ordrm_for_each_connector_iter().
- structdrm_connector*drm_connector_list_iter_next(structdrm_connector_list_iter*iter)¶
return next connector
Parameters
structdrm_connector_list_iter*iterconnector_list iterator
Return
the next connector foriter, or NULL when the list walk hascompleted.
- voiddrm_connector_list_iter_end(structdrm_connector_list_iter*iter)¶
tear down a connector_list iterator
Parameters
structdrm_connector_list_iter*iterconnector_list iterator
Description
Tears downiter and releases any resources (likedrm_connector references)acquired while walking the list. This must always be called, both when theiteration completes fully or when it was aborted without walking the entirelist.
- constchar*drm_get_subpixel_order_name(enumsubpixel_orderorder)¶
return a string for a given subpixel enum
Parameters
enumsubpixel_orderorderenumofsubpixel_order
Description
Note you could abuse this and return something out of bounds, but thatwould be a caller error. No unscrubbed user data should make it here.
Return
string describing an enumerated subpixel property
- intdrm_display_info_set_bus_formats(structdrm_display_info*info,constu32*formats,unsignedintnum_formats)¶
set the supported bus formats
Parameters
structdrm_display_info*infodisplay info to store bus formats in
constu32*formatsarray containing the supported bus formats
unsignedintnum_formatsthe number of entries in the fmts array
Description
Store the supported bus formats in display info structure.See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h fora full list of available formats.
Return
0 on success or a negative error code on failure.
- intdrm_get_tv_mode_from_name(constchar*name,size_tlen)¶
Translates a TV mode name into its
enumvalue
Parameters
constchar*nameTV Mode name we want to convert
size_tlenLength ofname
Description
Translatesname into anenumdrm_connector_tv_mode.
Return
theenumvalue on success, a negative errno otherwise.
- intdrm_mode_create_dvi_i_properties(structdrm_device*dev)¶
create DVI-I specific connector properties
Parameters
structdrm_device*devDRM device
Description
Called by a driver the first time a DVI-I connector is made.
Return
0
- voiddrm_connector_attach_dp_subconnector_property(structdrm_connector*connector)¶
create subconnector property for DP
Parameters
structdrm_connector*connectordrm_connector to attach property
Description
Called by a driver when DP connector is created.
- intdrm_connector_attach_content_type_property(structdrm_connector*connector)¶
attach content-type property
Parameters
structdrm_connector*connectorconnector to attach content type property on.
Description
Called by a driver the first time a HDMI connector is made.
Return
0
- voiddrm_connector_attach_tv_margin_properties(structdrm_connector*connector)¶
attach TV connector margin properties
Parameters
structdrm_connector*connectorDRM connector
Description
Called by a driver when it needs to attach TV margin props to a connector.Typically used on SDTV and HDMI connectors.
- intdrm_mode_create_tv_margin_properties(structdrm_device*dev)¶
create TV connector margin properties
Parameters
structdrm_device*devDRM device
Description
Called by a driver’s HDMI connector initialization routine, this functioncreates the TV margin properties for a given device. No need to call thisfunction for an SDTV connector, it’s already called fromdrm_mode_create_tv_properties_legacy().
Return
0 on success or a negative error code on failure.
- intdrm_mode_create_tv_properties_legacy(structdrm_device*dev,unsignedintnum_modes,constchar*constmodes[])¶
create TV specific connector properties
Parameters
structdrm_device*devDRM device
unsignedintnum_modesnumber of different TV formats (modes) supported
constchar*constmodes[]array of pointers to strings containing name of each format
Description
Called by a driver’s TV initialization routine, this function createsthe TV specific connector properties for a given device. Caller isresponsible for allocating a list of format names and passing them tothis routine.
NOTE
This functions registers the deprecated “mode” connectorproperty to select the analog TV mode (ie, NTSC, PAL, etc.). Newdrivers must usedrm_mode_create_tv_properties() instead.
Return
0 on success or a negative error code on failure.
- intdrm_mode_create_tv_properties(structdrm_device*dev,unsignedintsupported_tv_modes)¶
create TV specific connector properties
Parameters
structdrm_device*devDRM device
unsignedintsupported_tv_modesBitmask of TV modes supported (See DRM_MODE_TV_MODE_*)
Description
Called by a driver’s TV initialization routine, this function createsthe TV specific connector properties for a given device.
Return
0 on success or a negative error code on failure.
- intdrm_mode_create_scaling_mode_property(structdrm_device*dev)¶
create scaling mode property
Parameters
structdrm_device*devDRM device
Description
Called by a driver the first time it’s needed, must be attached to desiredconnectors.
Atomic drivers should usedrm_connector_attach_scaling_mode_property()instead to correctly assigndrm_connector_state.scaling_modein the atomic state.
Return
0
- intdrm_connector_attach_vrr_capable_property(structdrm_connector*connector)¶
creates the vrr_capable property
Parameters
structdrm_connector*connectorconnector to create the vrr_capable property on.
Description
This is used by atomic drivers to add support for queryingvariable refresh rate capability for a connector.
Return
Zero on success, negative errno on failure.
- intdrm_connector_attach_scaling_mode_property(structdrm_connector*connector,u32scaling_mode_mask)¶
attach atomic scaling mode property
Parameters
structdrm_connector*connectorconnector to attach scaling mode property on.
u32scaling_mode_maskor’ed mask of BIT(
DRM_MODE_SCALE_*).
Description
This is used to add support for scaling mode to atomic drivers.The scaling mode will be set todrm_connector_state.scaling_modeand can be used fromdrm_connector_helper_funcs->atomic_check for validation.
This is the atomic version ofdrm_mode_create_scaling_mode_property().
Return
Zero on success, negative errno on failure.
- intdrm_mode_create_aspect_ratio_property(structdrm_device*dev)¶
create aspect ratio property
Parameters
structdrm_device*devDRM device
Description
Called by a driver the first time it’s needed, must be attached to desiredconnectors.
Return
Zero on success, negative errno on failure.
- intdrm_mode_create_hdmi_colorspace_property(structdrm_connector*connector,u32supported_colorspaces)¶
create hdmi colorspace property
Parameters
structdrm_connector*connectorconnector to create the Colorspace property on.
u32supported_colorspacesbitmap of supported color spaces
Description
Called by a driver the first time it’s needed, must be attached to desiredHDMI connectors.
Return
Zero on success, negative errno on failure.
- intdrm_mode_create_dp_colorspace_property(structdrm_connector*connector,u32supported_colorspaces)¶
create dp colorspace property
Parameters
structdrm_connector*connectorconnector to create the Colorspace property on.
u32supported_colorspacesbitmap of supported color spaces
Description
Called by a driver the first time it’s needed, must be attached to desiredDP connectors.
Return
Zero on success, negative errno on failure.
- intdrm_mode_create_content_type_property(structdrm_device*dev)¶
create content type property
Parameters
structdrm_device*devDRM device
Description
Called by a driver the first time it’s needed, must be attached to desiredconnectors.
Return
Zero on success, negative errno on failure.
- intdrm_mode_create_suggested_offset_properties(structdrm_device*dev)¶
create suggests offset properties
Parameters
structdrm_device*devDRM device
Description
Create the suggested x/y offset property for connectors.
Return
0 on success or a negative error code on failure.
- intdrm_connector_set_path_property(structdrm_connector*connector,constchar*path)¶
set tile property on connector
Parameters
structdrm_connector*connectorconnector to set property on.
constchar*pathpath to use for property; must not be NULL.
Description
This creates a property to expose to userspace to specify aconnector path. This is mainly used for DisplayPort MST whereconnectors have a topology and we want to allow userspace to givethem more meaningful names.
Return
Zero on success, negative errno on failure.
- intdrm_connector_set_tile_property(structdrm_connector*connector)¶
set tile property on connector
Parameters
structdrm_connector*connectorconnector to set property on.
Description
This looks up the tile information for a connector, and creates aproperty for userspace to parse if it exists. The property is ofthe form of 8 integers using ‘:’ as a separator.This is used for dual port tiled displays with DisplayPort SSTor DisplayPort MST connectors.
Return
Zero on success, errno on failure.
- voiddrm_connector_set_link_status_property(structdrm_connector*connector,uint64_tlink_status)¶
Set link status property of a connector
Parameters
structdrm_connector*connectordrm connector
uint64_tlink_statusnew value of link status property (0: Good, 1: Bad)
Description
In usual working scenario, this link status property will always be set to“GOOD”. If something fails during or after a mode set, the kernel drivermay set this link status property to “BAD”. The caller then needs to send ahotplug uevent for userspace to re-check the valid modes throughGET_CONNECTOR_IOCTL and retry modeset.
Note
Drivers cannot rely on userspace to support this property andissue a modeset. As such, they may choose to handle issues (likere-training a link) without userspace’s intervention.
The reason for adding this property is to handle link training failures, butit is not limited to DP or link training. For example, if we implementasynchronous setcrtc, this property can be used to report any failures in that.
- intdrm_connector_attach_max_bpc_property(structdrm_connector*connector,intmin,intmax)¶
attach “max bpc” property
Parameters
structdrm_connector*connectorconnector to attach max bpc property on.
intminThe minimum bit depth supported by the connector.
intmaxThe maximum bit depth supported by the connector.
Description
This is used to add support for limiting the bit depth on a connector.
Return
Zero on success, negative errno on failure.
- intdrm_connector_attach_hdr_output_metadata_property(structdrm_connector*connector)¶
attach “HDR_OUTPUT_METADA” property
Parameters
structdrm_connector*connectorconnector to attach the property on.
Description
This is used to allow the userspace to send HDR Metadata to thedriver.
Return
Zero on success, negative errno on failure.
- intdrm_connector_attach_broadcast_rgb_property(structdrm_connector*connector)¶
attach “Broadcast RGB” property
Parameters
structdrm_connector*connectorconnector to attach the property on.
Description
This is used to add support for forcing the RGB range on a connector
Return
Zero on success, negative errno on failure.
- intdrm_connector_attach_colorspace_property(structdrm_connector*connector)¶
attach “Colorspace” property
Parameters
structdrm_connector*connectorconnector to attach the property on.
Description
This is used to allow the userspace to signal the output colorspaceto the driver.
Return
Zero on success, negative errno on failure.
- booldrm_connector_atomic_hdr_metadata_equal(structdrm_connector_state*old_state,structdrm_connector_state*new_state)¶
checks if the hdr metadata changed
Parameters
structdrm_connector_state*old_stateold connector state to compare
structdrm_connector_state*new_statenew connector state to compare
Description
This is used by HDR-enabled drivers to test whether the HDR metadatahave changed between two different connector state (and thus probablyrequires a full blown mode change).
Return
True if the metadata are equal, False otherwise
- voiddrm_connector_set_vrr_capable_property(structdrm_connector*connector,boolcapable)¶
sets the variable refresh rate capable property for a connector
Parameters
structdrm_connector*connectordrm connector
boolcapableTrue if the connector is variable refresh rate capable
Description
Should be used by atomic drivers to update the indicated support forvariable refresh rate over a connector.
- intdrm_connector_set_panel_orientation(structdrm_connector*connector,enumdrm_panel_orientationpanel_orientation)¶
sets the connector’s panel_orientation
Parameters
structdrm_connector*connectorconnector for which to set the panel-orientation property.
enumdrm_panel_orientationpanel_orientationdrm_panel_orientation value to set
Description
This function sets the connector’s panel_orientation and attachesa “panel orientation” property to the connector.
Calling this function on a connector where the panel_orientation hasalready been set is a no-op (e.g. the orientation has been overridden witha kernel commandline option).
It is allowed to call this function with a panel_orientation ofDRM_MODE_PANEL_ORIENTATION_UNKNOWN, in which case it is a no-op.
The function shouldn’t be called in panel after drm is registered (i.e.drm_dev_register() is called in drm).
Return
Zero on success, negative errno on failure.
- intdrm_connector_set_panel_orientation_with_quirk(structdrm_connector*connector,enumdrm_panel_orientationpanel_orientation,intwidth,intheight)¶
set the connector’s panel_orientation after checking for quirks
Parameters
structdrm_connector*connectorconnector for which to init the panel-orientation property.
enumdrm_panel_orientationpanel_orientationdrm_panel_orientation value to set
intwidthwidth in pixels of the panel, used for panel quirk detection
intheightheight in pixels of the panel, used for panel quirk detection
Description
Likedrm_connector_set_panel_orientation(), but with a check for platformspecific (e.g. DMI based) quirks overriding the passed in panel_orientation.
Return
Zero on success, negative errno on failure.
- intdrm_connector_set_orientation_from_panel(structdrm_connector*connector,structdrm_panel*panel)¶
set the connector’s panel_orientation from panel’s callback.
Parameters
structdrm_connector*connectorconnector for which to init the panel-orientation property.
structdrm_panel*panelpanel that can provide orientation information.
Description
Drm drivers should call this function beforedrm_dev_register().Orientation is obtained from panel’s .get_orientation() callback.
Return
Zero on success, negative errno on failure.
- voiddrm_connector_create_privacy_screen_properties(structdrm_connector*connector)¶
create the drm connecter’s privacy-screen properties.
Parameters
structdrm_connector*connectorconnector for which to create the privacy-screen properties
Description
This function creates the “privacy-screen sw-state” and “privacy-screenhw-state” properties for the connector. They are not attached.
- voiddrm_connector_attach_privacy_screen_properties(structdrm_connector*connector)¶
attach the drm connecter’s privacy-screen properties.
Parameters
structdrm_connector*connectorconnector on which to attach the privacy-screen properties
Description
This function attaches the “privacy-screen sw-state” and “privacy-screenhw-state” properties to the connector. The initial state of both is setto “Disabled”.
- voiddrm_connector_attach_privacy_screen_provider(structdrm_connector*connector,structdrm_privacy_screen*priv)¶
attach a privacy-screen to the connector
Parameters
structdrm_connector*connectorconnector to attach the privacy-screen to
structdrm_privacy_screen*privdrm_privacy_screen to attach
Description
Create and attach the standard privacy-screen properties and registera generic notifier for generating sysfs-connector-status-eventson external changes to the privacy-screen status.This function takes ownership of the passed in drm_privacy_screen and willcalldrm_privacy_screen_put() on it when the connector is destroyed.
- voiddrm_connector_update_privacy_screen(conststructdrm_connector_state*connector_state)¶
update connector’s privacy-screen sw-state
Parameters
conststructdrm_connector_state*connector_stateconnector-state to update the privacy-screen for
Description
This function callsdrm_privacy_screen_set_sw_state() on the connector’sprivacy-screen.
If the connector has no privacy-screen, then this is a no-op.
- voiddrm_connector_oob_hotplug_event(structfwnode_handle*connector_fwnode,enumdrm_connector_statusstatus)¶
Report out-of-band hotplug event to connector
Parameters
structfwnode_handle*connector_fwnodefwnode_handle to report the event on
enumdrm_connector_statusstatushot plug detect logical state
Description
On some hardware a hotplug event notification may come from outside the displaydriver / device. An example of this is some USB Type-C setups where the hardwaremuxes the DisplayPort data and aux-lines but does not pass the altmode HPDstatus bit to the GPU’s DP HPD pin.
This function can be used to report these out-of-band events after obtaininga drm_connector reference through callingdrm_connector_find_by_fwnode().
- voiddrm_mode_put_tile_group(structdrm_device*dev,structdrm_tile_group*tg)¶
drop a reference to a tile group.
Parameters
structdrm_device*devDRM device
structdrm_tile_group*tgtile group to drop reference to.
Description
drop reference to tile group and free if 0.
- structdrm_tile_group*drm_mode_get_tile_group(structdrm_device*dev,constchartopology[8])¶
get a reference to an existing tile group
Parameters
structdrm_device*devDRM device
constchartopology[8]8-bytes unique per monitor.
Description
Use the unique bytes to get a reference to an existing tile group.
Return
tile group or NULL if not found.
- structdrm_tile_group*drm_mode_create_tile_group(structdrm_device*dev,constchartopology[8])¶
create a tile group from a displayid description
Parameters
structdrm_device*devDRM device
constchartopology[8]8-bytes unique per monitor.
Description
Create a tile group for the unique monitor, and get a uniqueidentifier for the tile group.
Return
new tile group or NULL.
- voiddrm_connector_attach_panel_type_property(structdrm_connector*connector)¶
attaches panel type property
Parameters
structdrm_connector*connectorconnector to attach the property on.
Description
This is used to add support for panel type detection.
Writeback Connectors¶
Writeback connectors are used to expose hardware which can write the outputfrom a CRTC to a memory buffer. They are used and act similarly to othertypes of connectors, with some important differences:
Writeback connectors don’t provide a way to output visually to the user.
Writeback connectors are visible to userspace only when the client setsDRM_CLIENT_CAP_WRITEBACK_CONNECTORS.
Writeback connectors don’t have EDID.
A framebuffer may only be attached to a writeback connector when theconnector is attached to a CRTC. The WRITEBACK_FB_ID property which sets theframebuffer applies only to a single commit (see below). A framebuffer maynot be attached while the CRTC is off.
Unlike with planes, when a writeback framebuffer is removed by userspace DRMmakes no attempt to remove it from active use by the connector. This isbecause no method is provided to abort a writeback operation, and in anycase making a new commit whilst a writeback is ongoing is undefined (seeWRITEBACK_OUT_FENCE_PTR below). As soon as the current writeback is finished,the framebuffer will automatically no longer be in active use. As it willalso have already been removed from the framebuffer list, there will be noway for any userspace application to retrieve a reference to it in theintervening period.
Writeback connectors have some additional properties, which userspacecan use to query and control them:
- “WRITEBACK_FB_ID”:
Write-only object property storing a DRM_MODE_OBJECT_FB: it stores theframebuffer to be written by the writeback connector. This property issimilar to the FB_ID property on planes, but will always read as zeroand is not preserved across commits.Userspace must set this property to an output buffer every time itwishes the buffer to get filled.
- “WRITEBACK_PIXEL_FORMATS”:
Immutable blob property to store the supported pixel formats table. Thedata is an array of u32 DRM_FORMAT_* fourcc values.Userspace can use this blob to find out what pixel formats are supportedby the connector’s writeback engine.
- “WRITEBACK_OUT_FENCE_PTR”:
Userspace can use this property to provide a pointer for the kernel tofill with a sync_file file descriptor, which will signal once thewriteback is finished. The value should be the address of a 32-bitsigned integer, cast to a u64.Userspace should wait for this fence to signal before making anothercommit affecting any of the same CRTCs, Planes or Connectors.Failure to do so will result in undefined behaviour.For this reason it is strongly recommended that all userspaceapplications making use of writeback connectorsalways retrieve anout-fence for the commit and use it appropriately.From userspace, this property will always read as zero.
- structdrm_writeback_connector¶
DRM writeback connector
Definition:
struct drm_writeback_connector { struct drm_connector base; struct drm_encoder encoder; struct drm_property_blob *pixel_formats_blob_ptr; spinlock_t job_lock; struct list_head job_queue; unsigned int fence_context; spinlock_t fence_lock; unsigned long fence_seqno; char timeline_name[32];};Members
basebase drm_connector object
encoderInternal encoder used by the connector to fulfillthe DRM framework requirements. The users of thedrm_writeback_connector control the behaviour of theencoderby passing theenc_funcs parameter to
drm_writeback_connector_init()function.For users ofdrm_writeback_connector_init_with_encoder(), this fieldis not valid as the encoder is managed within their drivers.pixel_formats_blob_ptrDRM blob property data for the pixel formats list on writebackconnectorsSee also
drm_writeback_connector_init()job_lockProtects job_queue
job_queueHolds a list of a connector’s writeback jobs; the last item is themost recent. The first item may be either waiting for the hardwareto begin writing, or currently being written.
See also:
drm_writeback_queue_job()anddrm_writeback_signal_completion()fence_contexttimeline context used for fence operations.
fence_lockspinlock to protect the fences in the fence_context.
fence_seqnoSeqno variable used as monotonic counter for the fencescreated on the connector’s timeline.
timeline_nameThe name of the connector’s fence timeline.
- structdrm_writeback_job¶
DRM writeback job
Definition:
struct drm_writeback_job { struct drm_writeback_connector *connector; bool prepared; struct work_struct cleanup_work; struct list_head list_entry; struct drm_framebuffer *fb; struct dma_fence *out_fence; void *priv;};Members
connectorBack-pointer to the writeback connector associated with the job
preparedSet when the job has been prepared with
drm_writeback_prepare_job()cleanup_workUsed to allow drm_writeback_signal_completion to defer dropping theframebuffer reference to a workqueue
list_entryList item for the writeback connector’sjob_queue
fbFramebuffer to be written to by the writeback connector. Do not setdirectly, use
drm_writeback_set_fb()out_fenceFence which will signal once the writeback has completed
privDriver-private data
- intdrm_writeback_connector_init(structdrm_device*dev,structdrm_writeback_connector*wb_connector,conststructdrm_connector_funcs*con_funcs,conststructdrm_encoder_helper_funcs*enc_helper_funcs,constu32*formats,intn_formats,u32possible_crtcs)¶
Initialize a writeback connector and its properties
Parameters
structdrm_device*devDRM device
structdrm_writeback_connector*wb_connectorWriteback connector to initialize
conststructdrm_connector_funcs*con_funcsConnector funcs vtable
conststructdrm_encoder_helper_funcs*enc_helper_funcsEncoder helper funcs vtable to be used by the internal encoder
constu32*formatsArray of supported pixel formats for the writeback engine
intn_formatsLength of the formats array
u32possible_crtcspossible crtcs for the internal writeback encoder
Description
This function creates the writeback-connector-specific properties if theyhave not been already created, initializes the connector astype DRM_MODE_CONNECTOR_WRITEBACK, and correctly initializes the propertyvalues. It will also create an internal encoder associated with thedrm_writeback_connector and set it to use theenc_helper_funcs vtable forthe encoder helper.
Drivers should always use this function instead ofdrm_connector_init() toset up writeback connectors.
Return
0 on success, or a negative error code
- intdrm_writeback_connector_init_with_encoder(structdrm_device*dev,structdrm_writeback_connector*wb_connector,structdrm_encoder*enc,conststructdrm_connector_funcs*con_funcs,constu32*formats,intn_formats)¶
Initialize a writeback connector with a custom encoder
Parameters
structdrm_device*devDRM device
structdrm_writeback_connector*wb_connectorWriteback connector to initialize
structdrm_encoder*enchandle to the already initialized drm encoder
conststructdrm_connector_funcs*con_funcsConnector funcs vtable
constu32*formatsArray of supported pixel formats for the writeback engine
intn_formatsLength of the formats array
Description
This function creates the writeback-connector-specific properties if theyhave not been already created, initializes the connector astype DRM_MODE_CONNECTOR_WRITEBACK, and correctly initializes the propertyvalues.
This function assumes that the drm_writeback_connector’s encoder has already beencreated and initialized before invoking this function.
In addition, this function also assumes that callers of this API will manageassigning the encoder helper functions, possible_crtcs and any other encoderspecific operation.
Drivers should always use this function instead ofdrm_connector_init() toset up writeback connectors if they want to manage themselves the lifetime of theassociated encoder.
Return
0 on success, or a negative error code
- intdrmm_writeback_connector_init(structdrm_device*dev,structdrm_writeback_connector*wb_connector,conststructdrm_connector_funcs*con_funcs,structdrm_encoder*enc,constu32*formats,intn_formats)¶
Initialize a writeback connector with a custom encoder
Parameters
structdrm_device*devDRM device
structdrm_writeback_connector*wb_connectorWriteback connector to initialize
conststructdrm_connector_funcs*con_funcsConnector funcs vtable
structdrm_encoder*encEncoder to connect this writeback connector
constu32*formatsArray of supported pixel formats for the writeback engine
intn_formatsLength of the formats array
Description
This function initialize a writeback connector and register its cleanup.
This function creates the writeback-connector-specific properties if theyhave not been already created, initializes the connector astype DRM_MODE_CONNECTOR_WRITEBACK, and correctly initializes the propertyvalues.
Return
0 on success, or a negative error code
- voiddrm_writeback_queue_job(structdrm_writeback_connector*wb_connector,structdrm_connector_state*conn_state)¶
Queue a writeback job for later signalling
Parameters
structdrm_writeback_connector*wb_connectorThe writeback connector to queue a job on
structdrm_connector_state*conn_stateThe connector state containing the job to queue
Description
This function adds the job contained inconn_state to the job_queue for awriteback connector. It takes ownership of the writeback job and sets theconn_state->writeback_job to NULL, and so no access to the job may beperformed by the caller after this function returns.
Drivers must ensure that for a given writeback connector, jobs are queued inexactly the same order as they will be completed by the hardware (andsignaled via drm_writeback_signal_completion).
For every call todrm_writeback_queue_job() there must be exactly one call todrm_writeback_signal_completion()
See also:drm_writeback_signal_completion()
- voiddrm_writeback_signal_completion(structdrm_writeback_connector*wb_connector,intstatus)¶
Signal the completion of a writeback job
Parameters
structdrm_writeback_connector*wb_connectorThe writeback connector whose job is complete
intstatusStatus code to set in the writeback out_fence (0 for success)
Description
Drivers should call this to signal the completion of a previously queuedwriteback job. It should be called as soon as possible after the hardwarehas finished writing, and may be called from interrupt context.It is the driver’s responsibility to ensure that for a given connector, thehardware completes writeback jobs in the same order as they are queued.
Unless the driver is holding its own reference to the framebuffer, it mustnot be accessed after calling this function.
See also:drm_writeback_queue_job()
Encoder Abstraction¶
Encoders represent the connecting element between the CRTC (as the overallpixel pipeline, represented bystructdrm_crtc) and the connectors (as thegeneric sink entity, represented bystructdrm_connector). An encoder takespixel data from a CRTC and converts it to a format suitable for any attachedconnector. Encoders are objects exposed to userspace, originally to allowuserspace to infer cloning and connector/CRTC restrictions. Unfortunatelyalmost all drivers get this wrong, making the uabi pretty much useless. Ontop of that the exposed restrictions are too simple for today’s hardware, andthe recommended way to infer restrictions is by using theDRM_MODE_ATOMIC_TEST_ONLY flag for the atomic IOCTL.
Otherwise encoders aren’t used in the uapi at all (any modeset request fromuserspace directly connects a connector with a CRTC), drivers are thereforefree to use them however they wish. Modeset helper libraries make strong useof encoders to facilitate code sharing. But for more complex settings it isusually better to move shared code into a separatedrm_bridge. Compared toencoders, bridges also have the benefit of being purely an internalabstraction since they are not exposed to userspace at all.
Encoders are initialized withdrm_encoder_init() and cleaned up usingdrm_encoder_cleanup().
Encoder Functions Reference¶
- structdrm_encoder_funcs¶
encoder controls
Definition:
struct drm_encoder_funcs { void (*reset)(struct drm_encoder *encoder); void (*destroy)(struct drm_encoder *encoder); int (*late_register)(struct drm_encoder *encoder); void (*early_unregister)(struct drm_encoder *encoder); void (*debugfs_init)(struct drm_encoder *encoder, struct dentry *root);};Members
resetReset encoder hardware and software state to off. This function isn’tcalled by the core directly, only through
drm_mode_config_reset().It’s not a helper hook only for historical reasons.destroyClean up encoder resources. This is only called at driver unload timethrough
drm_mode_config_cleanup()since an encoder cannot behotplugged in DRM.late_registerThis optional hook can be used to register additional userspaceinterfaces attached to the encoder.It is called late in the driver load sequence from
drm_dev_register().Everything added from this callback should be unregistered inthe early_unregister callback.Returns:
0 on success, or a negative error code on failure.
early_unregisterThis optional hook should be used to unregister the additionaluserspace interfaces attached to the encoder fromlate_register. It is called from
drm_dev_unregister(),early in the driver unload sequence to disable userspace accessbefore data structures are torndown.debugfs_initAllows encoders to create encoder-specific debugfs files.
Description
Encoders sit between CRTCs and connectors.
- structdrm_encoder¶
central DRM encoder structure
Definition:
struct drm_encoder { struct drm_device *dev; struct list_head head; struct drm_mode_object base; char *name; int encoder_type; unsigned index; uint32_t possible_crtcs; uint32_t possible_clones; struct drm_crtc *crtc; struct list_head bridge_chain; const struct drm_encoder_funcs *funcs; const struct drm_encoder_helper_funcs *helper_private; struct dentry *debugfs_entry;};Members
devparent DRM device
headlist management
basebase KMS object
namehuman readable name, can be overwritten by the driver
encoder_typeOne of the DRM_MODE_ENCODER_<foo> types in drm_mode.h. The followingencoder types are defined thus far:
DRM_MODE_ENCODER_DAC for VGA and analog on DVI-I/DVI-A.
DRM_MODE_ENCODER_TMDS for DVI, HDMI and (embedded) DisplayPort.
DRM_MODE_ENCODER_LVDS for display panels, or in general any panelwith a proprietary parallel connector.
DRM_MODE_ENCODER_TVDAC for TV output (Composite, S-Video,Component, SCART).
DRM_MODE_ENCODER_VIRTUAL for virtual machine displays
DRM_MODE_ENCODER_DSI for panels connected using the DSI serial bus.
DRM_MODE_ENCODER_DPI for panels connected using the DPI parallelbus.
DRM_MODE_ENCODER_DPMST for special fake encoders used to allowmutliple DP MST streams to share one physical encoder.
indexPosition inside the mode_config.list, can be used as an arrayindex. It is invariant over the lifetime of the encoder.
possible_crtcsBitmask of potential CRTC bindings, using
drm_crtc_index()as the index into the bitfield. The driver must setthe bits for alldrm_crtcobjects this encoder can be connected tobefore callingdrm_dev_register().You will get a WARN if you get this wrong in the driver.
Note that since CRTC objects can’t be hotplugged the assigned indicesare stable and hence known before registering all objects.
possible_clonesBitmask of potential sibling encoders for cloning,using
drm_encoder_index()as the index into the bitfield. The drivermust set the bits for alldrm_encoderobjects which can clone adrm_crtctogether with this encoder before callingdrm_dev_register(). Drivers should set the bit representing theencoder itself, too. Cloning bits should be set such that when twoencoders can be used in a cloned configuration, they both should haveeach another bits set.As an exception to the above rule if the driver doesn’t implementany cloning it can leavepossible_clones set to 0. The core willautomagically fix this up by setting the bit for the encoder itself.
You will get a WARN if you get this wrong in the driver.
Note that since encoder objects can’t be hotplugged the assigned indicesare stable and hence known before registering all objects.
crtcCurrently bound CRTC, only really meaningful for non-atomicdrivers. Atomic drivers should instead check
drm_connector_state.crtc.bridge_chainBridges attached to this encoder. Drivers shall notaccess this field directly.
funcscontrol functions, can be NULL for simple managed encoders
helper_privatemid-layer private data
debugfs_entryDebugfs directory for this CRTC.
Description
CRTCs drive pixels to encoders, which convert them into signalsappropriate for a given connector or set of connectors.
- drmm_encoder_alloc¶
drmm_encoder_alloc(dev,type,member,funcs,encoder_type,name,...)
Allocate and initialize an encoder
Parameters
devdrm device
typethe type of the
structwhichcontains structdrm_encodermemberthe name of the
drm_encoderwithintypefuncscallbacks for this encoder (optional)
encoder_typeuser visible type of the encoder
nameprintf style format string for the encoder name, or NULL for default name
...variable arguments
Description
Allocates and initializes an encoder. Encoder should be subclassed as part ofdriver encoder objects. Cleanup is automatically handled through registeringdrm_encoder_cleanup() withdrmm_add_action().
Thedrm_encoder_funcs.destroy hook must be NULL.
Return
Pointer to new encoder, or ERR_PTR on failure.
- drmm_plain_encoder_alloc¶
drmm_plain_encoder_alloc(dev,funcs,encoder_type,name,...)
Allocate and initialize an encoder
Parameters
devdrm device
funcscallbacks for this encoder (optional)
encoder_typeuser visible type of the encoder
nameprintf style format string for the encoder name, or NULL for default name
...variable arguments
Description
This is a simplified version ofdrmm_encoder_alloc(), which only allocatesand returns astructdrm_encoder instance, with no subclassing.
Return
Pointer to the new drm_encoder struct, or ERR_PTR on failure.
- unsignedintdrm_encoder_index(conststructdrm_encoder*encoder)¶
find the index of a registered encoder
Parameters
conststructdrm_encoder*encoderencoder to find index for
Description
Given a registered encoder, return the index of that encoder within a DRMdevice’s list of encoders.
- u32drm_encoder_mask(conststructdrm_encoder*encoder)¶
find the mask of a registered encoder
Parameters
conststructdrm_encoder*encoderencoder to find mask for
Description
Given a registered encoder, return the mask bit of that encoder for anencoder’s possible_clones field.
- booldrm_encoder_crtc_ok(structdrm_encoder*encoder,structdrm_crtc*crtc)¶
can a given crtc drive a given encoder?
Parameters
structdrm_encoder*encoderencoder to test
structdrm_crtc*crtccrtc to test
Description
Returns false ifencoder can’t be driven bycrtc, true otherwise.
- structdrm_encoder*drm_encoder_find(structdrm_device*dev,structdrm_file*file_priv,uint32_tid)¶
find a
drm_encoder
Parameters
structdrm_device*devDRM device
structdrm_file*file_privdrm file to check for lease against.
uint32_tidencoder id
Description
Returns the encoder withid, NULL if it doesn’t exist. Simple wrapper arounddrm_mode_object_find().
- drm_for_each_encoder_mask¶
drm_for_each_encoder_mask(encoder,dev,encoder_mask)
iterate over encoders specified by bitmask
Parameters
encoderthe loop cursor
devthe DRM device
encoder_maskbitmask of encoder indices
Description
Iterate over all encoders specified by bitmask.
- drm_for_each_encoder¶
drm_for_each_encoder(encoder,dev)
iterate over all encoders
Parameters
encoderthe loop cursor
devthe DRM device
Description
Iterate over all encoders ofdev.
- intdrm_encoder_init(structdrm_device*dev,structdrm_encoder*encoder,conststructdrm_encoder_funcs*funcs,intencoder_type,constchar*name,...)¶
Init a preallocated encoder
Parameters
structdrm_device*devdrm device
structdrm_encoder*encoderthe encoder to init
conststructdrm_encoder_funcs*funcscallbacks for this encoder
intencoder_typeuser visible type of the encoder
constchar*nameprintf style format string for the encoder name, or NULL for default name
...variable arguments
Description
Initializes a preallocated encoder. Encoder should be subclassed as part ofdriver encoder objects. At driver unload time the driver’sdrm_encoder_funcs.destroy hook should calldrm_encoder_cleanup() andkfree()the encoder structure. The encoder structure should not be allocated withdevm_kzalloc().
Note
consider usingdrmm_encoder_alloc() ordrmm_encoder_init()instead ofdrm_encoder_init() to let the DRM managed resourceinfrastructure take care of cleanup and deallocation.
Return
Zero on success, error code on failure.
- voiddrm_encoder_cleanup(structdrm_encoder*encoder)¶
cleans up an initialised encoder
Parameters
structdrm_encoder*encoderencoder to cleanup
Description
Cleans up the encoder but doesn’t free the object.
- intdrmm_encoder_init(structdrm_device*dev,structdrm_encoder*encoder,conststructdrm_encoder_funcs*funcs,intencoder_type,constchar*name,...)¶
Initialize a preallocated encoder
Parameters
structdrm_device*devdrm device
structdrm_encoder*encoderthe encoder to init
conststructdrm_encoder_funcs*funcscallbacks for this encoder (optional)
intencoder_typeuser visible type of the encoder
constchar*nameprintf style format string for the encoder name, or NULL for default name
...variable arguments
Description
Initializes a preallocated encoder. Encoder should be subclassed aspart of driver encoder objects. Cleanup is automatically handledthrough registeringdrm_encoder_cleanup() withdrmm_add_action(). Theencoder structure should be allocated withdrmm_kzalloc().
Thedrm_encoder_funcs.destroy hook must be NULL.
Return
Zero on success, error code on failure.
KMS Locking¶
As KMS moves toward more fine grained locking, and atomic ioctl whereuserspace can indirectly control locking order, it becomes necessaryto useww_mutex and acquire-contexts to avoid deadlocks. But becausethe locking is more distributed around the driver code, we want a bitof extra utility/tracking out of our acquire-ctx. This is providedbystructdrm_modeset_lock andstructdrm_modeset_acquire_ctx.
For basic principles ofww_mutex, see:Wound/Wait Deadlock-Proof Mutex Design
The basic usage pattern is to:
drm_modeset_acquire_init(ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE)retry:foreach (lock in random_ordered_set_of_locks) { ret = drm_modeset_lock(lock, ctx) if (ret == -EDEADLK) { ret = drm_modeset_backoff(ctx); if (!ret) goto retry; } if (ret) goto out;}... do stuff ...out:drm_modeset_drop_locks(ctx);drm_modeset_acquire_fini(ctx);For convenience this control flow is implemented inDRM_MODESET_LOCK_ALL_BEGIN() andDRM_MODESET_LOCK_ALL_END() for the casewhere all modeset locks need to be taken throughdrm_modeset_lock_all_ctx().
If all that is needed is a single modeset lock, then thestructdrm_modeset_acquire_ctx is not needed and the locking can be simplifiedby passing a NULL instead of ctx in thedrm_modeset_lock() call orcallingdrm_modeset_lock_single_interruptible(). To unlock afterwardscalldrm_modeset_unlock().
On top of these per-object locks usingww_mutex there’s also an overalldrm_mode_config.mutex, for protecting everything else. Mostly this meansprobe state of connectors, and preventing hotplug add/removal of connectors.
Finally there’s a bunch of dedicated locks to protect drm core internallists and lookup data structures.
- structdrm_modeset_acquire_ctx¶
locking context (see ww_acquire_ctx)
Definition:
struct drm_modeset_acquire_ctx { struct ww_acquire_ctx ww_ctx; struct drm_modeset_lock *contended; depot_stack_handle_t stack_depot; struct list_head locked; bool trylock_only; bool interruptible;};Members
ww_ctxbase acquire ctx
contendedused internally for -EDEADLK handling
stack_depotused internally for contention debugging
lockedlist of held locks
trylock_onlytrylock mode used in atomic contexts/panic notifiers
interruptiblewhether interruptible locking should be used.
Description
Each thread competing for a set of locks must use one acquirectx. And if any lock fxn returns -EDEADLK, it must backoff andretry.
- structdrm_modeset_lock¶
used for locking modeset resources.
Definition:
struct drm_modeset_lock { struct ww_mutex mutex; struct list_head head;};Members
mutexresource locking
headused to hold its place on
drm_atomi_state.lockedlist whenpart of an atomic update
Description
Used for locking CRTCs and other modeset resources.
- voiddrm_modeset_lock_fini(structdrm_modeset_lock*lock)¶
cleanup lock
Parameters
structdrm_modeset_lock*locklock to cleanup
- booldrm_modeset_is_locked(structdrm_modeset_lock*lock)¶
equivalent to
mutex_is_locked()
Parameters
structdrm_modeset_lock*locklock to check
- voiddrm_modeset_lock_assert_held(structdrm_modeset_lock*lock)¶
equivalent to
lockdep_assert_held()
Parameters
structdrm_modeset_lock*locklock to check
- DRM_MODESET_LOCK_ALL_BEGIN¶
DRM_MODESET_LOCK_ALL_BEGIN(dev,ctx,flags,ret)
Helper to acquire modeset locks
Parameters
devdrm device
ctxlocal modeset acquire context, will be dereferenced
flagsDRM_MODESET_ACQUIRE_* flags to pass to
drm_modeset_acquire_init()retlocal ret/err/etc variable to track error status
Description
Use these macros to simplify grabbing all modeset locks using a localcontext. This has the advantage of reducing boilerplate, but also properlychecking return values where appropriate.
Any code run between BEGIN and END will be holding the modeset locks.
This must be paired withDRM_MODESET_LOCK_ALL_END(). We will jump back andforth between the labels on deadlock and error conditions.
Drivers can acquire additional modeset locks. If any lock acquisitionfails, the control flow needs to jump toDRM_MODESET_LOCK_ALL_END() withtheret parameter containing the return value ofdrm_modeset_lock().
Return
The only possible value of ret immediately afterDRM_MODESET_LOCK_ALL_BEGIN()is 0, so no error checking is necessary
- DRM_MODESET_LOCK_ALL_END¶
DRM_MODESET_LOCK_ALL_END(dev,ctx,ret)
Helper to release and cleanup modeset locks
Parameters
devdrm device
ctxlocal modeset acquire context, will be dereferenced
retlocal ret/err/etc variable to track error status
Description
The other side ofDRM_MODESET_LOCK_ALL_BEGIN(). It will bounce back to BEGINif ret is -EDEADLK.
It’s important that you use the same ret variable for begin and end sodeadlock conditions are properly handled.
Return
ret will be untouched unless it is -EDEADLK on entry. That means that if yousuccessfully acquire the locks, ret will be whatever your code sets it to. Ifthere is a deadlock or other failure with acquire or backoff, ret will be setto that failure. In both of these cases the code between BEGIN/END will notbe run, so the failure will reflect the inability to grab the locks.
- voiddrm_modeset_lock_all(structdrm_device*dev)¶
take all modeset locks
Parameters
structdrm_device*devDRM device
Description
This function takes all modeset locks, suitable where a more fine-grainedscheme isn’t (yet) implemented. Locks must be dropped by calling thedrm_modeset_unlock_all() function.
This function is deprecated. It allocates a lock acquisition context andstores it indrm_device.mode_config. This facilitate conversion ofexisting code because it removes the need to manually deal with theacquisition context, but it is also brittle because the context is globaland care must be taken not to nest calls. New code should use thedrm_modeset_lock_all_ctx() function and pass in the context explicitly.
- voiddrm_modeset_unlock_all(structdrm_device*dev)¶
drop all modeset locks
Parameters
structdrm_device*devDRM device
Description
This function drops all modeset locks taken by a previous call to thedrm_modeset_lock_all() function.
This function is deprecated. It uses the lock acquisition context storedindrm_device.mode_config. This facilitates conversion of existingcode because it removes the need to manually deal with the acquisitioncontext, but it is also brittle because the context is global and care mustbe taken not to nest calls. New code should pass the acquisition contextdirectly to thedrm_modeset_drop_locks() function.
- voiddrm_warn_on_modeset_not_all_locked(structdrm_device*dev)¶
check that all modeset locks are locked
Parameters
structdrm_device*devdevice
Description
Useful as a debug assert.
- voiddrm_modeset_acquire_init(structdrm_modeset_acquire_ctx*ctx,uint32_tflags)¶
initialize acquire context
Parameters
structdrm_modeset_acquire_ctx*ctxthe acquire context
uint32_tflags0 or
DRM_MODESET_ACQUIRE_INTERRUPTIBLE
Description
When passingDRM_MODESET_ACQUIRE_INTERRUPTIBLE toflags,all calls todrm_modeset_lock() will perform an interruptiblewait.
- voiddrm_modeset_acquire_fini(structdrm_modeset_acquire_ctx*ctx)¶
cleanup acquire context
Parameters
structdrm_modeset_acquire_ctx*ctxthe acquire context
- voiddrm_modeset_drop_locks(structdrm_modeset_acquire_ctx*ctx)¶
drop all locks
Parameters
structdrm_modeset_acquire_ctx*ctxthe acquire context
Description
Drop all locks currently held against this acquire context.
- intdrm_modeset_backoff(structdrm_modeset_acquire_ctx*ctx)¶
deadlock avoidance backoff
Parameters
structdrm_modeset_acquire_ctx*ctxthe acquire context
Description
If deadlock is detected (ie.drm_modeset_lock() returns -EDEADLK),you must call this function to drop all currently held locks andblock until the contended lock becomes available.
This function returns 0 on success, or -ERESTARTSYS if this contextis initialized withDRM_MODESET_ACQUIRE_INTERRUPTIBLE and thewait has been interrupted.
- voiddrm_modeset_lock_init(structdrm_modeset_lock*lock)¶
initialize lock
Parameters
structdrm_modeset_lock*locklock to init
- intdrm_modeset_lock(structdrm_modeset_lock*lock,structdrm_modeset_acquire_ctx*ctx)
take modeset lock
Parameters
structdrm_modeset_lock*locklock to take
structdrm_modeset_acquire_ctx*ctxacquire ctx
Description
Ifctx is not NULL, then its ww acquire context is used and thelock will be tracked by the context and can be released by callingdrm_modeset_drop_locks(). If -EDEADLK is returned, this means adeadlock scenario has been detected and it is an error to attemptto take any more locks without first callingdrm_modeset_backoff().
If thectx is not NULL and initialized withDRM_MODESET_ACQUIRE_INTERRUPTIBLE, this function will fail with-ERESTARTSYS when interrupted.
Ifctx is NULL then the function call behaves like a normal,uninterruptible non-nestingmutex_lock() call.
- intdrm_modeset_lock_single_interruptible(structdrm_modeset_lock*lock)¶
take a single modeset lock
Parameters
structdrm_modeset_lock*locklock to take
Description
This function behaves asdrm_modeset_lock() with a NULL context,but performs interruptible waits.
This function returns 0 on success, or -ERESTARTSYS when interrupted.
- voiddrm_modeset_unlock(structdrm_modeset_lock*lock)¶
drop modeset lock
Parameters
structdrm_modeset_lock*locklock to release
- intdrm_modeset_lock_all_ctx(structdrm_device*dev,structdrm_modeset_acquire_ctx*ctx)¶
take all modeset locks
Parameters
structdrm_device*devDRM device
structdrm_modeset_acquire_ctx*ctxlock acquisition context
Description
This function takes all modeset locks, suitable where a more fine-grainedscheme isn’t (yet) implemented.
Unlikedrm_modeset_lock_all(), it doesn’t take thedrm_mode_config.mutexsince that lock isn’t required for modeset state changes. Callers whichneed to grab that lock too need to do so outside of the acquire contextctx.
Locks acquired with this function should be released by calling thedrm_modeset_drop_locks() function onctx.
See also:DRM_MODESET_LOCK_ALL_BEGIN() andDRM_MODESET_LOCK_ALL_END()
Return
0 on success or a negative error-code on failure.
KMS Properties¶
This section of the documentation is primarily aimed at user-space developers.For the driver APIs, see the other sections.
Requirements¶
KMS drivers might need to add extra properties to support new features. Eachnew property introduced in a driver needs to meet a few requirements, inaddition to the one mentioned above:
It must be standardized, documenting:
The full, exact, name string;
If the property is an enum, all the valid value name strings;
What values are accepted, and what these values mean;
What the property does and how it can be used;
How the property might interact with other, existing properties.
It must provide a generic helper in the core code to register thatproperty on the object it attaches to.
Its content must be decoded by the core and provided in the object’sassociated state structure. That includes anything drivers might wantto precompute, like
structdrm_clip_rectfor planes.Its initial state must match the behavior prior to the propertyintroduction. This might be a fixed value matching what the hardwaredoes, or it may be inherited from the state the firmware left thesystem in during boot.
An IGT test must be submitted where reasonable.
For historical reasons, non-standard, driver-specific properties exist. If a KMSdriver wants to add support for one of those properties, the requirements fornew properties apply where possible. Additionally, the documented behavior mustmatch the de facto semantics of the existing property to ensure compatibility.Developers of the driver that first added the property should help with thosetasks and must ACK the documented behavior if possible.
Property Types and Blob Property Support¶
Properties as represented bydrm_property are used to extend the modesetinterface exposed to userspace. For the atomic modeset IOCTL properties areeven the only way to transport metadata about the desired new modesetconfiguration from userspace to the kernel. Properties have a well-definedvalue range, which is enforced by the drm core. See the documentation of theflags member ofstructdrm_property for an overview of the differentproperty types and ranges.
Properties don’t store the current value directly, but need to beinstantiated by attaching them to adrm_mode_object withdrm_object_attach_property().
Property values are only 64bit. To support bigger piles of data (like gammatables, color correction matrices or large structures) a property can insteadpoint at adrm_property_blob with that additional data.
Properties are defined by their symbolic name, userspace must keep aper-object mapping from those names to the property ID used in the atomicIOCTL and in the get/set property IOCTL.
- structdrm_property_enum¶
symbolic values for enumerations
Definition:
struct drm_property_enum { uint64_t value; struct list_head head; char name[DRM_PROP_NAME_LEN];};Members
valuenumeric property value for this
enumentryIf the property has the type
DRM_MODE_PROP_BITMASK,value stores abitshift, not a bitmask. In other words, theenumentryis enabledif the bit numbervalue is set in the property’s value. Thisenumentryhas the bitmask1<<value.headlist of
enumvalues, linked todrm_property.enum_listnamesymbolic name for the enum
Description
For enumeration and bitmask properties this structure stores the symbolicdecoding for each value. This is used for example for the rotation property.
- structdrm_property¶
modeset object property
Definition:
struct drm_property { struct list_head head; struct drm_mode_object base; uint32_t flags; char name[DRM_PROP_NAME_LEN]; uint32_t num_values; uint64_t *values; struct drm_device *dev; struct list_head enum_list;};Members
headper-device list of properties, for cleanup.
basebase KMS object
flagsProperty flags and type. A property needs to be one of the followingtypes:
- DRM_MODE_PROP_RANGE
Range properties report their minimum and maximum admissible unsigned values.The KMS core verifies that values set by application fit in thatrange. The range is unsigned. Range properties are created using
drm_property_create_range().- DRM_MODE_PROP_SIGNED_RANGE
Range properties report their minimum and maximum admissible unsigned values.The KMS core verifies that values set by application fit in thatrange. The range is signed. Range properties are created using
drm_property_create_signed_range().- DRM_MODE_PROP_ENUM
Enumerated properties take a numerical value that ranges from 0 tothe number of enumerated values defined by the property minus one,and associate a free-formed string name to each value. Applicationscan retrieve the list of defined value-name pairs and use thenumerical value to get and set property instance values. Enumproperties are created using
drm_property_create_enum().- DRM_MODE_PROP_BITMASK
Bitmask properties are enumeration properties that additionallyrestrict all enumerated values to the 0..63 range. Bitmask propertyinstance values combine one or more of the enumerated bits definedby the property. Bitmask properties are created using
drm_property_create_bitmask().- DRM_MODE_PROP_OBJECT
Object properties are used to link modeset objects. This is usedextensively in the atomic support to create the display pipeline,by linking
drm_framebuffertodrm_plane,drm_planetodrm_crtcanddrm_connectortodrm_crtc. An object property canonly link to a specific type ofdrm_mode_object, this limit isenforced by the core. Object properties are created usingdrm_property_create_object().Object properties work like blob properties, but in a moregeneral fashion. They are limited to atomic drivers and must havethe DRM_MODE_PROP_ATOMIC flag set.
- DRM_MODE_PROP_BLOB
Blob properties store a binary blob without any format restriction.The binary blobs are created as KMS standalone objects, and blobproperty instance values store the ID of their associated blobobject. Blob properties are created by calling
drm_property_create()with DRM_MODE_PROP_BLOB as the type.Actual blob objects to contain blob data are created using
drm_property_create_blob(), or through the corresponding IOCTL.Besides the built-in limit to only accept blob objects blobproperties work exactly like object properties. The only reasonsblob properties exist is backwards compatibility with existinguserspace.
In addition a property can have any combination of the below flags:
- DRM_MODE_PROP_ATOMIC
Set for properties which encode atomic modeset state. Suchproperties are not exposed to legacy userspace.
- DRM_MODE_PROP_IMMUTABLE
Set for properties whose values cannot be changed byuserspace. The kernel is allowed to update the value of theseproperties. This is generally used to expose probe state touserspace, e.g. the EDID, or the connector path property on DPMST sinks. Kernel can update the value of an immutable propertyby calling
drm_object_property_set_value().
namesymbolic name of the properties
num_valuessize of thevalues array.
valuesArray with limits and values for the property. Theinterpretation of these limits is dependent upon the type perflags.
devDRM device
enum_listList of
drm_prop_enum_liststructures with the symbolic names forenumandbitmask values.
Description
This structure represent a modeset object property. It combines both the nameof the property with the set of permissible values. This means that when adriver wants to use a property with the same name on different objects, butwith different value ranges, then it must create property for each one. Anexample would be rotation ofdrm_plane, when e.g. the primary plane cannotbe rotated. But if both the name and the value range match, then the sameproperty structure can be instantiated multiple times for the same object.Userspace must be able to cope with this and cannot assume that the samesymbolic property will have the same modeset object ID on all modesetobjects.
Properties are created by one of the special functions, as explained indetail in theflags structure member.
To actually expose a property it must be attached to each object usingdrm_object_attach_property(). Currently properties can only be attached todrm_connector,drm_crtc anddrm_plane.
Properties are also used as the generic metadatatransport for the atomicIOCTL. Everything that was set directly in structures in the legacy modesetIOCTLs (like the plane source or destination windows, or e.g. the links tothe CRTC) is exposed as a property with the DRM_MODE_PROP_ATOMIC flag set.
- structdrm_property_blob¶
Blob data for
drm_property
Definition:
struct drm_property_blob { struct drm_mode_object base; struct drm_device *dev; struct list_head head_global; struct list_head head_file; size_t length; void *data;};Members
basebase KMS object
devDRM device
head_globalentry on the global blob list in
drm_mode_config.property_blob_list.head_fileentry on the per-file blob list in
drm_file.blobslist.lengthsize of the blob in bytes, invariant over the lifetime of the object
dataactual data, embedded at the end of this structure
Description
Blobs are used to store bigger values than what fits directly into the 64bits available for adrm_property.
Blobs are reference counted usingdrm_property_blob_get() anddrm_property_blob_put(). They are created usingdrm_property_create_blob().
- booldrm_property_type_is(structdrm_property*property,uint32_ttype)¶
check the type of a property
Parameters
structdrm_property*propertyproperty to check
uint32_ttypeproperty type to compare with
Description
This is a helper function becauase the uapi encoding of property types isa bit special for historical reasons.
- structdrm_property*drm_property_find(structdrm_device*dev,structdrm_file*file_priv,uint32_tid)¶
find property object
Parameters
structdrm_device*devDRM device
structdrm_file*file_privdrm file to check for lease against.
uint32_tidproperty object id
Description
This function looks up the property object specified by id and returns it.
- structdrm_property*drm_property_create(structdrm_device*dev,u32flags,constchar*name,intnum_values)¶
create a new property type
Parameters
structdrm_device*devdrm device
u32flagsflags specifying the property type
constchar*namename of the property
intnum_valuesnumber of pre-defined values
Description
This creates a new generic drm property which can then be attached to a drmobject withdrm_object_attach_property(). The returned property object mustbe freed withdrm_property_destroy(), which is done automatically whencallingdrm_mode_config_cleanup().
Return
A pointer to the newly created property on success, NULL on failure.
- structdrm_property*drm_property_create_enum(structdrm_device*dev,u32flags,constchar*name,conststructdrm_prop_enum_list*props,intnum_values)¶
create a new enumeration property type
Parameters
structdrm_device*devdrm device
u32flagsflags specifying the property type
constchar*namename of the property
conststructdrm_prop_enum_list*propsenumeration lists with property values
intnum_valuesnumber of pre-defined values
Description
This creates a new generic drm property which can then be attached to a drmobject withdrm_object_attach_property(). The returned property object mustbe freed withdrm_property_destroy(), which is done automatically whencallingdrm_mode_config_cleanup().
Userspace is only allowed to set one of the predefined values for enumerationproperties.
Return
A pointer to the newly created property on success, NULL on failure.
- structdrm_property*drm_property_create_bitmask(structdrm_device*dev,u32flags,constchar*name,conststructdrm_prop_enum_list*props,intnum_props,uint64_tsupported_bits)¶
create a new bitmask property type
Parameters
structdrm_device*devdrm device
u32flagsflags specifying the property type
constchar*namename of the property
conststructdrm_prop_enum_list*propsenumeration lists with property bitflags
intnum_propssize of theprops array
uint64_tsupported_bitsbitmask of all supported enumeration values
Description
This creates a new bitmask drm property which can then be attached to a drmobject withdrm_object_attach_property(). The returned property object mustbe freed withdrm_property_destroy(), which is done automatically whencallingdrm_mode_config_cleanup().
Compared to plain enumeration properties userspace is allowed to set anyor’ed together combination of the predefined property bitflag values
Return
A pointer to the newly created property on success, NULL on failure.
- structdrm_property*drm_property_create_range(structdrm_device*dev,u32flags,constchar*name,uint64_tmin,uint64_tmax)¶
create a new unsigned ranged property type
Parameters
structdrm_device*devdrm device
u32flagsflags specifying the property type
constchar*namename of the property
uint64_tminminimum value of the property
uint64_tmaxmaximum value of the property
Description
This creates a new generic drm property which can then be attached to a drmobject withdrm_object_attach_property(). The returned property object mustbe freed withdrm_property_destroy(), which is done automatically whencallingdrm_mode_config_cleanup().
Userspace is allowed to set any unsigned integer value in the (min, max)range inclusive.
Return
A pointer to the newly created property on success, NULL on failure.
- structdrm_property*drm_property_create_signed_range(structdrm_device*dev,u32flags,constchar*name,int64_tmin,int64_tmax)¶
create a new signed ranged property type
Parameters
structdrm_device*devdrm device
u32flagsflags specifying the property type
constchar*namename of the property
int64_tminminimum value of the property
int64_tmaxmaximum value of the property
Description
This creates a new generic drm property which can then be attached to a drmobject withdrm_object_attach_property(). The returned property object mustbe freed withdrm_property_destroy(), which is done automatically whencallingdrm_mode_config_cleanup().
Userspace is allowed to set any signed integer value in the (min, max)range inclusive.
Return
A pointer to the newly created property on success, NULL on failure.
- structdrm_property*drm_property_create_object(structdrm_device*dev,u32flags,constchar*name,uint32_ttype)¶
create a new object property type
Parameters
structdrm_device*devdrm device
u32flagsflags specifying the property type
constchar*namename of the property
uint32_ttypeobject type from DRM_MODE_OBJECT_* defines
Description
This creates a new generic drm property which can then be attached to a drmobject withdrm_object_attach_property(). The returned property object mustbe freed withdrm_property_destroy(), which is done automatically whencallingdrm_mode_config_cleanup().
Userspace is only allowed to set this to any property value of the giventype. Only useful for atomic properties, which is enforced.
Return
A pointer to the newly created property on success, NULL on failure.
- structdrm_property*drm_property_create_bool(structdrm_device*dev,u32flags,constchar*name)¶
create a new boolean property type
Parameters
structdrm_device*devdrm device
u32flagsflags specifying the property type
constchar*namename of the property
Description
This creates a new generic drm property which can then be attached to a drmobject withdrm_object_attach_property(). The returned property object mustbe freed withdrm_property_destroy(), which is done automatically whencallingdrm_mode_config_cleanup().
This is implemented as a ranged property with only {0, 1} as valid values.
Return
A pointer to the newly created property on success, NULL on failure.
- intdrm_property_add_enum(structdrm_property*property,uint64_tvalue,constchar*name)¶
add a possible value to an enumeration property
Parameters
structdrm_property*propertyenumeration property to change
uint64_tvaluevalue of the new enumeration
constchar*namesymbolic name of the new enumeration
Description
This functions adds enumerations to a property.
It’s use is deprecated, drivers should use one of the more specific helpersto directly create the property with all enumerations already attached.
Return
Zero on success, error code on failure.
- voiddrm_property_destroy(structdrm_device*dev,structdrm_property*property)¶
destroy a drm property
Parameters
structdrm_device*devdrm device
structdrm_property*propertyproperty to destroy
Description
This function frees a property including any attached resources likeenumeration values.
- structdrm_property_blob*drm_property_create_blob(structdrm_device*dev,size_tlength,constvoid*data)¶
Create new blob property
Parameters
structdrm_device*devDRM device to create property for
size_tlengthLength to allocate for blob data
constvoid*dataIf specified, copies data into blob
Description
Creates a new blob property for a specified DRM device, optionallycopying data. Note that blob properties are meant to be invariant, hence thedata must be filled out before the blob is used as the value of any property.
Return
New blob property with a single reference on success, or an ERR_PTRvalue on failure.
- voiddrm_property_blob_put(structdrm_property_blob*blob)¶
release a blob property reference
Parameters
structdrm_property_blob*blobDRM blob property
Description
Releases a reference to a blob property. May free the object.
- structdrm_property_blob*drm_property_blob_get(structdrm_property_blob*blob)¶
acquire blob property reference
Parameters
structdrm_property_blob*blobDRM blob property
Description
Acquires a reference to an existing blob property. Returnsblob, whichallows this to be used as a shorthand in assignments.
- structdrm_property_blob*drm_property_lookup_blob(structdrm_device*dev,uint32_tid)¶
look up a blob property and take a reference
Parameters
structdrm_device*devdrm device
uint32_tidid of the blob property
Description
If successful, this takes an additional reference to the blob property.callers need to make sure to eventually unreferenced the returned propertyagain, usingdrm_property_blob_put().
Return
NULL on failure, pointer to the blob on success.
- intdrm_property_replace_global_blob(structdrm_device*dev,structdrm_property_blob**replace,size_tlength,constvoid*data,structdrm_mode_object*obj_holds_id,structdrm_property*prop_holds_id)¶
replace existing blob property
Parameters
structdrm_device*devdrm device
structdrm_property_blob**replacelocation of blob property pointer to be replaced
size_tlengthlength of data for new blob, or 0 for no data
constvoid*datacontent for new blob, or NULL for no data
structdrm_mode_object*obj_holds_idoptional object for property holding blob ID
structdrm_property*prop_holds_idoptional property holding blob IDreturn 0 on success or error on failure
Description
This function will replace a global property in the blob list, optionallyupdating a property which holds the ID of that property.
If length is 0 or data is NULL, no new blob will be created, and the holdingproperty, if specified, will be set to 0.
Access to the replace pointer is assumed to be protected by the caller, e.g.by holding the relevant modesetting object lock for its parent.
For example, a drm_connector has a ‘PATH’ property, which contains the IDof a blob property with the value of the MST path information. Calling thisfunction with replace pointing to the connector’s path_blob_ptr, length anddata set for the new path information, obj_holds_id set to the connector’sbase object, and prop_holds_id set to the path property name, will performa completely atomic update. The access to path_blob_ptr is protected by thecaller holding a lock on the connector.
- booldrm_property_replace_blob(structdrm_property_blob**blob,structdrm_property_blob*new_blob)¶
replace a blob property
Parameters
structdrm_property_blob**bloba pointer to the member blob to be replaced
structdrm_property_blob*new_blobthe new blob to replace with
Return
true if the blob was in fact replaced.
- intdrm_property_replace_blob_from_id(structdrm_device*dev,structdrm_property_blob**blob,uint64_tblob_id,ssize_tmax_size,ssize_texpected_size,ssize_texpected_elem_size,bool*replaced)¶
replace a blob property taking a reference
Parameters
structdrm_device*devDRM device
structdrm_property_blob**bloba pointer to the member blob to be replaced
uint64_tblob_idthe id of the new blob to replace with
ssize_tmax_sizethe maximum size of the blob property for variable-size blobs
ssize_texpected_sizeexpected size of the blob property
ssize_texpected_elem_sizeexpected size of an element in the blob property
bool*replacedif the blob was in fact replaced
Description
Look up the new blob from id, take its reference, check expected sizes ofthe blob and its element and replace the old blob by the new one. Advertiseif the replacement operation was successful.
Return
true if the blob was in fact replaced. -EINVAL if the new blob wasnot found or sizes don’t match.
Standard Connector Properties¶
DRM connectors have a few standardized properties:
- EDID:
Blob property which contains the current EDID read from the sink. Thisis useful to parse sink identification information like vendor, modeland serial. Drivers should update this property by calling
drm_connector_update_edid_property(), usually after having parsedthe EDID usingdrm_add_edid_modes(). Userspace cannot change thisproperty.User-space should not parse the EDID to obtain information exposed viaother KMS properties (because the kernel might apply limits, quirks orfixups to the EDID). For instance, user-space should not try to parsemode lists from the EDID.
- DPMS:
Legacy property for setting the power state of the connector. For atomicdrivers this is only provided for backwards compatibility with existingdrivers, it remaps to controlling the “ACTIVE” property on the CRTC theconnector is linked to. Drivers should never set this property directly,it is handled by the DRM core by calling the
drm_connector_funcs.dpmscallback. For atomic drivers the remapping to the “ACTIVE” property isimplemented in the DRM core.On atomic drivers any DPMS setproperty ioctl where the value does notchange is completely skipped, otherwise a full atomic commit will occur.On legacy drivers the exact behavior is driver specific.
Note that this property cannot be set through the MODE_ATOMIC ioctl,userspace must use “ACTIVE” on the CRTC instead.
WARNING:
For userspace also running on legacy drivers the “DPMS” semantics are alot more complicated. First, userspace cannot rely on the “DPMS” valuereturned by the GETCONNECTOR actually reflecting reality, because manydrivers fail to update it. For atomic drivers this is taken care of in
drm_atomic_helper_update_legacy_modeset_state().The second issue is that the DPMS state is only well-defined when theconnector is connected to a CRTC. In atomic the DRM core enforces that“ACTIVE” is off in such a case, no such checks exists for “DPMS”.
Finally, when enabling an output using the legacy SETCONFIG ioctl then“DPMS” is forced to ON. But see above, that might not be reflected inthe software value on legacy drivers.
Summarizing: Only set “DPMS” when the connector is known to be enabled,assume that a successful SETCONFIG call also sets “DPMS” to on, andnever read back the value of “DPMS” because it can be incorrect.
- panel_type:
Immutable
enumpropertyto indicate the type of connected panel.Possible values are “unknown” (default) and “OLED”.- PATH:
Connector path property to identify how this sink is physicallyconnected. Used by DP MST. This should be set by calling
drm_connector_set_path_property(), in the case of DP MST with thepath property the MST manager created. Userspace cannot change thisproperty.In the case of DP MST, the property has the format
mst:<parent>-<ports>where<parent>is the KMS object ID of theparent connector and<ports>is a hyphen-separated list of DP MSTport numbers. Note, KMS object IDs are not guaranteed to be stableacross reboots.- TILE:
Connector tile group property to indicate how a set of DRM connectorcompose together into one logical screen. This is used by both high-resexternal screens (often only using a single cable, but exposing multipleDP MST sinks), or high-res integrated panels (like dual-link DSI) whichare not gen-locked. Note that for tiled panels which are genlocked, likedual-link LVDS or dual-link DSI, the driver should try to not expose thetiling and virtualise both
drm_crtcanddrm_planeif needed. Driversshould update this value usingdrm_connector_set_tile_property().Userspace cannot change this property.- link-status:
Connector link-status property to indicate the status of link. Thedefault value of link-status is “GOOD”. If something fails during orafter modeset, the kernel driver may set this to “BAD” and issue ahotplug uevent. Drivers should update this value using
drm_connector_set_link_status_property().When user-space receives the hotplug uevent and detects a “BAD”link-status, the sink doesn’t receive pixels anymore (e.g. the screenbecomes completely black). The list of available modes may havechanged. User-space is expected to pick a new mode if the current onehas disappeared and perform a new modeset with link-status set to“GOOD” to re-enable the connector.
If multiple connectors share the same CRTC and one of them gets a “BAD”link-status, the other are unaffected (ie. the sinks still continue toreceive pixels).
When user-space performs an atomic commit on a connector with a “BAD”link-status without resetting the property to “GOOD”, the sink maystill not receive pixels. When user-space performs an atomic commitwhich resets the link-status property to “GOOD” without theALLOW_MODESET flag set, it might fail because a modeset is required.
User-space can only change link-status to “GOOD”, changing it to “BAD”is a no-op.
For backwards compatibility with non-atomic userspace the kerneltries to automatically set the link-status back to “GOOD” in theSETCRTC IOCTL. This might fail if the mode is no longer valid, similarto how it might fail if a different screen has been connected in theinterim.
- non_desktop:
Indicates the output should be ignored for purposes of displaying astandard desktop environment or console. This is most likely becausethe output device is not rectilinear.
- Content Protection:
This property is used by userspace to request the kernel protect futurecontent communicated over the link. When requested, kernel will applythe appropriate means of protection (most often HDCP), and use theproperty to tell userspace the protection is active.
Drivers can set this up by calling
drm_connector_attach_content_protection_property()on initialization.The value of this property can be one of the following:
- DRM_MODE_CONTENT_PROTECTION_UNDESIRED = 0
The link is not protected, content is transmitted in the clear.
- DRM_MODE_CONTENT_PROTECTION_DESIRED = 1
Userspace has requested content protection, but the link is notcurrently protected. When in this state, kernel should enableContent Protection as soon as possible.
- DRM_MODE_CONTENT_PROTECTION_ENABLED = 2
Userspace has requested content protection, and the link isprotected. Only the driver can set the property to this value.If userspace attempts to set to ENABLED, kernel will return-EINVAL.
A few guidelines:
DESIRED state should be preserved until userspace de-asserts it bysetting the property to UNDESIRED. This means ENABLED should onlytransition to UNDESIRED when the user explicitly requests it.
If the state is DESIRED, kernel should attempt to re-authenticate thelink whenever possible. This includes across disable/enable, dpms,hotplug, downstream device changes, link status failures, etc..
Kernel sends uevent with the connector id and property id throughdrm_hdcp_update_content_protection, upon below kernel triggeredscenarios:
DESIRED -> ENABLED (authentication success)
ENABLED -> DESIRED (termination of authentication)
Please note no uevents for userspace triggered property state changes,which can’t fail such as
DESIRED/ENABLED -> UNDESIRED
UNDESIRED -> DESIRED
Userspace is responsible for polling the property or listen to ueventsto determine when the value transitions from ENABLED to DESIRED.This signifies the link is no longer protected and userspace shouldtake appropriate action (whatever that might be).
- HDCP Content Type:
This Enum property is used by the userspace to declare the content typeof the display stream, to kernel. Here display stream stands for anydisplay content that userspace intended to display through HDCPencryption.
Content Type of a stream is decided by the owner of the stream, as“HDCP Type0” or “HDCP Type1”.
- The value of the property can be one of the below:
“HDCP Type0”: DRM_MODE_HDCP_CONTENT_TYPE0 = 0
“HDCP Type1”: DRM_MODE_HDCP_CONTENT_TYPE1 = 1
When kernel starts the HDCP authentication (see “Content Protection”for details), it uses the content type in “HDCP Content Type”for performing the HDCP authentication with the display sink.
Please note in HDCP spec versions, a link can be authenticated withHDCP 2.2 for Content Type 0/Content Type 1. Where as a link can beauthenticated with HDCP1.4 only for Content Type 0(though it is implicitin nature. As there is no reference for Content Type in HDCP1.4).
HDCP2.2 authentication protocol itself takes the “Content Type” as aparameter, which is a input for the DP HDCP2.2 encryption algo.
In case of Type 0 content protection request, kernel driver can chooseeither of HDCP spec versions 1.4 and 2.2. When HDCP2.2 is used for“HDCP Type 0”, a HDCP 2.2 capable repeater in the downstream can sendthat content to a HDCP 1.4 authenticated HDCP sink (Type0 link).But if the content is classified as “HDCP Type 1”, above mentionedHDCP 2.2 repeater wont send the content to the HDCP sink as it can’tauthenticate the HDCP1.4 capable sink for “HDCP Type 1”.
Please note userspace can be ignorant of the HDCP versions used by thekernel driver to achieve the “HDCP Content Type”.
At current scenario, classifying a content as Type 1 ensures that thecontent will be displayed only through the HDCP2.2 encrypted link.
Note that the HDCP Content Type property is introduced at HDCP 2.2, anddefaults to type 0. It is only exposed by drivers supporting HDCP 2.2(hence supporting Type 0 and Type 1). Based on how next versions ofHDCP specs are defined content Type could be used for higher versionstoo.
If content type is changed when “Content Protection” is not UNDESIRED,then kernel will disable the HDCP and re-enable with new type in thesame atomic commit. And when “Content Protection” is ENABLED, it meansthat link is HDCP authenticated and encrypted, for the transmission ofthe Type of stream mentioned at “HDCP Content Type”.
- HDR_OUTPUT_METADATA:
Connector property to enable userspace to send HDR Metadata todriver. This metadata is based on the composition and blendingpolicies decided by user, taking into account the hardware andsink capabilities. The driver gets this metadata and creates aDynamic Range and Mastering Infoframe (DRM) in case of HDMI,SDP packet (Non-audio INFOFRAME SDP v1.3) for DP. This is thensent to sink. This notifies the sink of the upcoming frame’s ColorEncoding and Luminance parameters.
Userspace first need to detect the HDR capabilities of sink byreading and parsing the EDID. Details of HDR metadata for HDMIare added in CTA 861.G spec. For DP , its defined in VESA DPStandard v1.4. It needs to then get the metadata informationof the video/game/app content which are encoded in HDR (basicallyusing HDR transfer functions). With this information it needs todecide on a blending policy and compose the relevantlayers/overlays into a common format. Once this blending is done,userspace will be aware of the metadata of the composed frame tobe send to sink. It then uses this property to communicate thismetadata to driver which then make a Infoframe packet and sendsto sink based on the type of encoder connected.
- Userspace will be responsible to do Tone mapping operation in case:
Some layers are HDR and others are SDR
HDR layers luminance is not same as sink
It will even need to do colorspace conversion and get all layersto one common colorspace for blending. It can use either GL, Mediaor display engine to get this done based on the capabilities of theassociated hardware.
Driver expects metadata to be put in
structhdr_output_metadatastructure from userspace. This is received as blob and stored indrm_connector_state.hdr_output_metadata. It parses EDID and saves thesink metadata instructhdr_sink_metadata, asdrm_connector.display_info.hdr_sink_metadata. Driver usesdrm_hdmi_infoframe_set_hdr_metadata()helper to set the HDR metadata,hdmi_drm_infoframe_pack()to pack the infoframe as per spec, in case ofHDMI encoder.- max bpc:
This range property is used by userspace to limit the bit depth. Whenused the driver would limit the bpc in accordance with the valid rangesupported by the hardware and sink. Drivers to use the function
drm_connector_attach_max_bpc_property()to create and attach theproperty to the connector during initialization.
Connectors also have one standardized atomic property:
- CRTC_ID:
Mode object ID of the
drm_crtcthis connector should be connected to.
Connectors for LCD panels may also have one standardized property:
- panel orientation:
On some devices the LCD panel is mounted in the casing in such a waythat the up/top side of the panel does not match with the top side ofthe device. Userspace can use this property to check for this.Note that input coordinates from touchscreens (input devices withINPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panelcoordinates, so if userspace rotates the picture to adjust forthe orientation it must also apply the same transformation to thetouchscreen input coordinates. This property is initialized by calling
drm_connector_set_panel_orientation()ordrm_connector_set_panel_orientation_with_quirk()- scaling mode:
This property defines how a non-native mode is upscaled to the nativemode of an LCD panel:
- None:
No upscaling happens, scaling is left to the panel. Not alldrivers expose this mode.
- Full:
The output is upscaled to the full resolution of the panel,ignoring the aspect ratio.
- Center:
No upscaling happens, the output is centered within the nativeresolution the panel.
- Full aspect:
The output is upscaled to maximize either the width or heightwhile retaining the aspect ratio.
This property should be set up by calling
drm_connector_attach_scaling_mode_property(). Note that driverscan also expose this property to external outputs, in which case theymust support “None”, which should be the default (since external screenshave a built-in scaler).- subconnector:
This property is used by DVI-I, TVout and DisplayPort to indicate differentconnector subtypes. Enum values more or less match with those from mainconnector types.For DVI-I and TVout there is also a matching property “select subconnector”allowing to switch between signal types.DP subconnector corresponds to a downstream port.
- privacy-screen sw-state, privacy-screen hw-state:
These 2 optional properties can be used to query the state of theelectronic privacy screen that is available on some displays; and insome cases also control the state. If a driver implements theseproperties then both properties must be present.
“privacy-screen hw-state” is read-only and reflects the actual stateof the privacy-screen, possible values: “Enabled”, “Disabled,“Enabled-locked”, “Disabled-locked”. The locked states indicatethat the state cannot be changed through the DRM API. E.g. theremight be devices where the firmware-setup options, or a hardwareslider-switch, offer always on / off modes.
“privacy-screen sw-state” can be set to change the privacy-screen statewhen not locked. In this case the driver must update the hw-stateproperty to reflect the new state on completion of the commit of thesw-state property. Setting the sw-state property when the hw-state islocked must be interpreted by the driver as a request to change thestate to the set state when the hw-state becomes unlocked. E.g. if“privacy-screen hw-state” is “Enabled-locked” and the sw-stategets set to “Disabled” followed by the user unlocking the state bychanging the slider-switch position, then the driver must set thestate to “Disabled” upon receiving the unlock event.
In some cases the privacy-screen’s actual state might change outside ofcontrol of the DRM code. E.g. there might be a firmware handled hotkeywhich toggles the actual state, or the actual state might be changedthrough another userspace API such as writing /proc/acpi/ibm/lcdshadow.In this case the driver must update both the hw-state and the sw-stateto reflect the new value, overwriting any pending state requests in thesw-state. Any pending sw-state requests are thus discarded.
Note that the ability for the state to change outside of control ofthe DRM master process means that userspace must not cache the valueof the sw-state. Caching the sw-state value and including it in lateratomic commits may lead to overriding a state change done through e.g.a firmware handled hotkey. Therefor userspace must not include theprivacy-screen sw-state in an atomic commit unless it wants to changeits value.
- left margin, right margin, top margin, bottom margin:
Add margins to the connector’s viewport. This is typically used tomitigate overscan on TVs.
The value is the size in pixels of the black border which will beadded. The attached CRTC’s content will be scaled to fill the wholearea inside the margin.
The margins configuration might be sent to the sink, e.g. via HDMI AVIInfoFrames.
Drivers can set up these properties by calling
drm_mode_create_tv_margin_properties().- Colorspace:
This property is used to inform the driver about the color encodinguser space configured the pixel operation properties to produce.The variants set the colorimetry, transfer characteristics, and whichYCbCr conversion should be used when necessary.The transfer characteristics from HDR_OUTPUT_METADATA takes precedenceover this property.User space always configures the pixel operation properties to producefull quantization range data (see the Broadcast RGB property).
Drivers inform the sink about what colorimetry, transfercharacteristics, YCbCr conversion, and quantization range to expect(this can depend on the output mode, output format and otherproperties). Drivers also convert the user space provided data to whatthe sink expects.
User space has to check if the sink supports all of the possiblecolorimetries that the driver is allowed to pick by parsing the EDID.
For historical reasons this property exposes a number of variants whichresult in undefined behavior.
- Default:
The behavior is driver-specific.
BT2020_RGB:
- BT2020_YCC:
User space configures the pixel operation properties to produceRGB content with Rec. ITU-R BT.2020 colorimetry, Rec.ITU-R BT.2020 (Table 4, RGB) transfer characteristics and fullquantization range.User space can use the HDR_OUTPUT_METADATA property to set thetransfer characteristics to PQ (Rec. ITU-R BT.2100 Table 4) orHLG (Rec. ITU-R BT.2100 Table 5) in which case, user spaceconfigures pixel operation properties to produce content withthe respective transfer characteristics.User space has to make sure the sink supports Rec.ITU-R BT.2020 R’G’B’ and Rec. ITU-R BT.2020 Y’C’BC’Rcolorimetry.Drivers can configure the sink to use an RGB format, tell thesink to expect Rec. ITU-R BT.2020 R’G’B’ colorimetry and convertto the appropriate quantization range.Drivers can configure the sink to use a YCbCr format, tell thesink to expect Rec. ITU-R BT.2020 Y’C’BC’R colorimetry, convertto YCbCr using the Rec. ITU-R BT.2020 non-constant luminanceconversion matrix and convert to the appropriate quantizationrange.The variants BT2020_RGB and BT2020_YCC are equivalent and thedriver chooses between RGB and YCbCr on its own.
SMPTE_170M_YCC:BT709_YCC:XVYCC_601:XVYCC_709:SYCC_601:opYCC_601:opRGB:BT2020_CYCC:DCI-P3_RGB_D65:DCI-P3_RGB_Theater:RGB_WIDE_FIXED:RGB_WIDE_FLOAT:
- BT601_YCC:
The behavior is undefined.
Because between HDMI and DP have different colorspaces,drm_mode_create_hdmi_colorspace_property() is used for HDMI connector anddrm_mode_create_dp_colorspace_property() is used for DP connector.
HDMI Specific Connector Properties¶
- Broadcast RGB (HDMI specific)
Indicates the Quantization Range (Full vs Limited) used. The colorprocessing pipeline will be adjusted to match the value of theproperty, and the Infoframes will be generated and sent accordingly.
This property is only relevant if the HDMI output format is RGB. Ifit’s one of the YCbCr variant, it will be ignored.
The CRTC attached to the connector must be configured by user-space toalways produce full-range pixels.
The value of this property can be one of the following:
- Automatic:
The quantization range is selected automatically based on themode according to the HDMI specifications (HDMI 1.4b - Section6.6 - Video Quantization Ranges).
- Full:
Full quantization range is forced.
- Limited 16:235:
Limited quantization range is forced. Unlike the name suggests,this works for any number of bits-per-component.
Property values other than Automatic can result in colors being off (iflimited is selected but the display expects full), or a black screen(if full is selected but the display expects limited).
Drivers can set up this property by calling
drm_connector_attach_broadcast_rgb_property().- content type (HDMI specific):
Indicates content type setting to be used in HDMI infoframes to indicatecontent type for the external device, so that it adjusts its displaysettings accordingly.
The value of this property can be one of the following:
- No Data:
Content type is unknown
- Graphics:
Content type is graphics
- Photo:
Content type is photo
- Cinema:
Content type is cinema
- Game:
Content type is game
The meaning of each content type is defined in CTA-861-G table 15.
Drivers can set up this property by calling
drm_connector_attach_content_type_property(). Decoding toinfoframe values is done throughdrm_hdmi_avi_infoframe_content_type().
Analog TV Specific Connector Properties¶
- TV Mode:
Indicates the TV Mode used on an analog TV connector. The valueof this property can be one of the following:
- NTSC:
TV Mode is CCIR System M (aka 525-lines) together withthe NTSC Color Encoding.
NTSC-443:
TV Mode is CCIR System M (aka 525-lines) together withthe NTSC Color Encoding, but with a color subcarrierfrequency of 4.43MHz
NTSC-J:
TV Mode is CCIR System M (aka 525-lines) together withthe NTSC Color Encoding, but with a black level equal tothe blanking level.
PAL:
TV Mode is CCIR System B (aka 625-lines) together withthe PAL Color Encoding.
PAL-M:
TV Mode is CCIR System M (aka 525-lines) together withthe PAL Color Encoding.
PAL-N:
TV Mode is CCIR System N together with the PAL ColorEncoding, a color subcarrier frequency of 3.58MHz, theSECAM color space, and narrower channels than other PALvariants.
SECAM:
TV Mode is CCIR System B (aka 625-lines) together withthe SECAM Color Encoding.
Mono:
Use timings appropriate to the DRM mode, includingequalizing pulses for a 525-line or 625-line mode,with no pedestal or color encoding.
Drivers can set up this property by calling
drm_mode_create_tv_properties().
Standard CRTC Properties¶
DRM CRTCs have a few standardized properties:
- ACTIVE:
Atomic property for setting the power state of the CRTC. When set to 1the CRTC will actively display content. When set to 0 the CRTC will bepowered off. There is no expectation that user-space will reset CRTCresources like the mode and planes when setting ACTIVE to 0.
User-space can rely on an ACTIVE change to 1 to never fail an atomictest as long as no other property has changed. If a change to ACTIVEfails an atomic test, this is a driver bug. For this reason settingACTIVE to 0 must not release internal resources (like reserved memorybandwidth or clock generators).
Note that the legacy DPMS property on connectors is internally routedto control this property for atomic drivers.
- MODE_ID:
Atomic property for setting the CRTC display timings. The value is theID of a blob containing the DRM mode info. To disable the CRTC,user-space must set this property to 0.
Setting MODE_ID to 0 will release reserved resources for the CRTC.
- SCALING_FILTER:
Atomic property for setting the scaling filter for CRTC scaler
The value of this property can be one of the following:
- Default:
Driver’s default scaling filter
- Nearest Neighbor:
Nearest Neighbor scaling filter
- SHARPNESS_STRENGTH:
Atomic property for setting the sharpness strength/intensity by userspace.
The value of this property is set as an integer value rangingfrom 0 - 255 where:
0: Sharpness feature is disabled(default value).
1: Minimum sharpness.
255: Maximum sharpness.
User can gradually increase or decrease the sharpness level and canset the optimum value depending on content.This value will be passed to kernel through the UAPI.The setting of this property does not require modeset.The sharpness effect takes place post blending on the final composed output.If the feature is disabled, the content remains same without any sharpening effectand when this feature is applied, it enhances the clarity of the content.
Standard Plane Properties¶
DRM planes have a few standardized properties:
- type:
Immutable property describing the type of the plane.
For user-space which has enabled the
DRM_CLIENT_CAP_ATOMICcapability,the plane type is just a hint and is mostly superseded by atomictest-only commits. The type hint can still be used to come up moreeasily with a plane configuration accepted by the driver.The value of this property can be one of the following:
- “Primary”:
To light up a CRTC, attaching a primary plane is the most likely towork if it covers the whole CRTC and doesn’t have scaling orcropping set up.
Drivers may support more features for the primary plane, user-spacecan find out with test-only atomic commits.
Some primary planes are implicitly used by the kernel in the legacyIOCTLs
DRM_IOCTL_MODE_SETCRTCandDRM_IOCTL_MODE_PAGE_FLIP.Therefore user-space must not mix explicit usage of any primaryplane (e.g. through an atomic commit) with these legacy IOCTLs.- “Cursor”:
To enable this plane, using a framebuffer configured without scalingor cropping and with the following properties is the most likely towork:
If the driver provides the capabilities
DRM_CAP_CURSOR_WIDTHandDRM_CAP_CURSOR_HEIGHT, create the framebuffer with this size.Otherwise, create a framebuffer with the size 64x64.If the driver doesn’t support modifiers, create a framebuffer witha linear layout. Otherwise, use the IN_FORMATS plane property.
Drivers may support more features for the cursor plane, user-spacecan find out with test-only atomic commits.
Some cursor planes are implicitly used by the kernel in the legacyIOCTLs
DRM_IOCTL_MODE_CURSORandDRM_IOCTL_MODE_CURSOR2.Therefore user-space must not mix explicit usage of any cursorplane (e.g. through an atomic commit) with these legacy IOCTLs.Some drivers may support cursors even if no cursor plane is exposed.In this case, the legacy cursor IOCTLs can be used to configure thecursor.
- “Overlay”:
Neither primary nor cursor.
Overlay planes are the only planes exposed when the
DRM_CLIENT_CAP_UNIVERSAL_PLANEScapability is disabled.
- IN_FORMATS:
Blob property which contains the set of buffer format and modifierpairs supported by this plane. The blob is a
structdrm_format_modifier_blob. Without this property the plane doesn’tsupport buffers with modifiers. Userspace cannot change this property.Note that userspace can check the
DRM_CAP_ADDFB2_MODIFIERSdrivercapability for general modifier support. If this flag is set then everyplane will have the IN_FORMATS property, even when it only supportsDRM_FORMAT_MOD_LINEAR. Before linux kernel release v5.1 there have beenvarious bugs in this area with inconsistencies between the capabilityflag and per-plane properties.- IN_FORMATS_ASYNC:
Blob property which contains the set of buffer format and modifierpairs supported by this plane for asynchronous flips. The blob is a
structdrm_format_modifier_blob. Userspace cannot change this property. This is anoptional property and if not present then user should expect a failure inatomic ioctl when the modifier/format is not supported by that plane underasynchronous flip.- SIZE_HINTS:
Blob property which contains the set of recommended plane sizewhich can used for simple “cursor like” use cases (eg. no scaling).Using these hints frees userspace from extensive probing ofsupported plane sizes through atomic/setcursor ioctls.
The blob contains an array of
structdrm_plane_size_hint, inorder of preference. For optimal usage userspace should pickthe first size that satisfies its own requirements.Drivers should only attach this property to planes thatsupport a very limited set of sizes.
Note that property value 0 (ie. no blob) is reserved for potentialfuture use. Current userspace is expected to ignore the propertyif the value is 0, and fall back to some other means (eg.
DRM_CAP_CURSOR_WIDTHandDRM_CAP_CURSOR_HEIGHT) to determinethe appropriate plane size to use.
Plane Composition Properties¶
The basic plane composition model supported by standard plane properties onlyhas a source rectangle (in logical pixels within thedrm_framebuffer), withsub-pixel accuracy, which is scaled up to a pixel-aligned destinationrectangle in the visible area of adrm_crtc. The visible area of a CRTC isdefined by the horizontal and vertical visible pixels (stored inhdisplayandvdisplay) of the requested mode (stored indrm_crtc_state.mode). Thesetwo rectangles are both stored in thedrm_plane_state.
For the atomic ioctl the following standard (atomic) properties on the plane objectencode the basic plane composition model:
- SRC_X:
X coordinate offset for the source rectangle within the
drm_framebuffer, in 16.16 fixed point. Must be positive.- SRC_Y:
Y coordinate offset for the source rectangle within the
drm_framebuffer, in 16.16 fixed point. Must be positive.- SRC_W:
Width for the source rectangle within the
drm_framebuffer, in 16.16fixed point. SRC_X plus SRC_W must be within the width of the sourceframebuffer. Must be positive.- SRC_H:
Height for the source rectangle within the
drm_framebuffer, in 16.16fixed point. SRC_Y plus SRC_H must be within the height of the sourceframebuffer. Must be positive.- CRTC_X:
X coordinate offset for the destination rectangle. Can be negative.
- CRTC_Y:
Y coordinate offset for the destination rectangle. Can be negative.
- CRTC_W:
Width for the destination rectangle. CRTC_X plus CRTC_W can extend pastthe currently visible horizontal area of the
drm_crtc.- CRTC_H:
Height for the destination rectangle. CRTC_Y plus CRTC_H can extend pastthe currently visible vertical area of the
drm_crtc.- FB_ID:
Mode object ID of the
drm_framebufferthis plane should scan out.When a KMS client is performing front-buffer rendering, it should setFB_ID to the same front-buffer FB on each atomic commit. This impliesto the driver that it needs to re-read the same FB again. Otherwisedrivers which do not employ continuously repeated scanout cycles mightnot update the screen.
- CRTC_ID:
Mode object ID of the
drm_crtcthis plane should be connected to.
Note that the source rectangle must fully lie within the bounds of thedrm_framebuffer. The destination rectangle can lie outside of the visiblearea of the current mode of the CRTC. It must be appropriately clipped by thedriver, which can be done by callingdrm_plane_helper_check_update(). Driversare also allowed to round the subpixel sampling positions appropriately, butonly to the next full pixel. No pixel outside of the source rectangle mayever be sampled, which is important when applying more sophisticatedfiltering than just a bilinear one when scaling. The filtering mode whenscaling is unspecified.
On top of this basic transformation additional properties can be exposed bythe driver:
- alpha:
Alpha is setup with
drm_plane_create_alpha_property(). It controls theplane-wide opacity, from transparent (0) to opaque (0xffff). It can becombined with pixel alpha.The pixel values in the framebuffers are expected to not bepre-multiplied by the global alpha associated to the plane.- rotation:
Rotation is set up with
drm_plane_create_rotation_property(). It adds arotation and reflection step between the source and destination rectangles.Without this property the rectangle is only scaled, but not rotated orreflected.Possbile values:
- “rotate-<degrees>”:
Signals that a drm plane is rotated <degrees> degrees in counterclockwise direction.
- “reflect-<axis>”:
Signals that the contents of a drm plane is reflected along the<axis> axis, in the same way as mirroring.
reflect-x:
|o | | o|| | -> | || v| |v |
reflect-y:
|o | | ^|| | -> | || v| |o |
- zpos:
Z position is set up with
drm_plane_create_zpos_immutable_property()anddrm_plane_create_zpos_property(). It controls the visibility of overlappingplanes. Without this property the primary plane is always below the cursorplane, and ordering between all other planes is undefined. The positiveZ axis points towards the user, i.e. planes with lower Z position valuesare underneath planes with higher Z position values. Two planes with thesame Z position value have undefined ordering. Note that the Z positionvalue can also be immutable, to inform userspace about the hard-codedstacking of planes, seedrm_plane_create_zpos_immutable_property(). Ifany plane has a zpos property (either mutable or immutable), then allplanes shall have a zpos property.- pixel blend mode:
Pixel blend mode is set up with
drm_plane_create_blend_mode_property().It adds a blend mode for alpha blending equation selection, describinghow the pixels from the current plane are composited with thebackground.Three alpha blending equations are defined:
- “None”:
Blend formula that ignores the pixel alpha:
out.rgb = plane_alpha * fg.rgb + (1 - plane_alpha) * bg.rgb
- “Pre-multiplied”:
Blend formula that assumes the pixel color valueshave been already pre-multiplied with the alphachannel values:
out.rgb = plane_alpha * fg.rgb + (1 - (plane_alpha * fg.alpha)) * bg.rgb
- “Coverage”:
Blend formula that assumes the pixel color values have notbeen pre-multiplied and will do so when blending them to thebackground color values:
out.rgb = plane_alpha * fg.alpha * fg.rgb + (1 - (plane_alpha * fg.alpha)) * bg.rgb
Using the following symbols:
- “fg.rgb”:
Each of the RGB component values from the plane’s pixel
- “fg.alpha”:
Alpha component value from the plane’s pixel. If the plane’spixel format has no alpha component, then this is assumed to be1.0. In these cases, this property has no effect, as all threeequations become equivalent.
- “bg.rgb”:
Each of the RGB component values from the background
- “plane_alpha”:
Plane alpha value set by the plane “alpha” property. If theplane does not expose the “alpha” property, then this isassumed to be 1.0
Note that all the property extensions described here apply either to theplane or the CRTC (e.g. for the background color, which currently is notexposed and assumed to be black).
- SCALING_FILTER:
Indicates scaling filter to be used for plane scaler
The value of this property can be one of the following:
- Default:
Driver’s default scaling filter
- Nearest Neighbor:
Nearest Neighbor scaling filter
Drivers can set up this property for a plane by callingdrm_plane_create_scaling_filter_property
Damage Tracking Properties¶
FB_DAMAGE_CLIPS is an optional plane property which provides a means tospecify a list of damage rectangles on a plane in framebuffer coordinates ofthe framebuffer attached to the plane. In current context damage is the areaof plane framebuffer that has changed since last plane update (also calledpage-flip), irrespective of whether currently attached framebuffer is same asframebuffer attached during last plane update or not.
FB_DAMAGE_CLIPS is a hint to kernel which could be helpful for some driversto optimize internally especially for virtual devices where each framebufferchange needs to be transmitted over network, usb, etc.
Since FB_DAMAGE_CLIPS is a hint so it is an optional property. User-space canignore damage clips property and in that case driver will do a full planeupdate. In case damage clips are provided then it is guaranteed that the areainside damage clips will be updated to plane. For efficiency driver can dofull update or can update more than specified in damage clips. Since driveris free to read more, user-space must always render the entire visibleframebuffer. Otherwise there can be corruptions. Also, if a user-spaceprovides damage clips which doesn’t encompass the actual damage toframebuffer (since last plane update) can result in incorrect rendering.
FB_DAMAGE_CLIPS is a blob property with the layout of blob data is simply anarray ofdrm_mode_rect. Unlike planedrm_plane_state.src coordinates,damage clips are not in 16.16 fixed point. Similar to plane src inframebuffer, damage clips cannot be negative. In damage clip, x1/y1 areinclusive and x2/y2 are exclusive. While kernel does not error for overlappeddamage clips, it is strongly discouraged.
Drivers that are interested in damage interface for plane should enableFB_DAMAGE_CLIPS property by callingdrm_plane_enable_fb_damage_clips().Drivers implementing damage can usedrm_atomic_helper_damage_iter_init() anddrm_atomic_helper_damage_iter_next() helper iterator function to get damagerectangles clipped todrm_plane_state.src.
Note that there are two types of damage handling: frame damage and bufferdamage, the type of damage handling implemented depends on a driver’s uploadtarget. Drivers implementing a per-plane or per-CRTC upload target need tohandle frame damage, while drivers implementing a per-buffer upload targetneed to handle buffer damage.
The existing damage helpers only support the frame damage type, there is nobuffer age support or similar damage accumulation algorithm implemented yet.
Only drivers handling frame damage can use the mentioned damage helpers toiterate over the damaged regions. Drivers that handle buffer damage, must setdrm_plane_state.ignore_damage_clips fordrm_atomic_helper_damage_iter_init()to know that damage clips should be ignored and returndrm_plane_state.srcas the damage rectangle, to force a full plane update.
Drivers with a per-buffer upload target could compare thedrm_plane_state.fbof the old and new plane states to determine if the framebuffer attached to aplane has changed or not since the last plane update. Ifdrm_plane_state.fbhas changed, thendrm_plane_state.ignore_damage_clips must be set to true.
That is because drivers with a per-plane upload target, expect the backingstorage buffer to not change for a given plane. If the upload buffer changesbetween page flips, the new upload buffer has to be updated as a whole. Thiscan be improved in the future if support for frame damage is added to the DRMdamage helpers, similarly to how user-space already handle this case as it isexplained in the following documents:
Color Management Properties¶
Color management or color space adjustments is supported through a set of 5properties on thedrm_crtc object. They are set up by callingdrm_crtc_enable_color_mgmt().
- “DEGAMMA_LUT”:
Blob property to set the degamma lookup table (LUT) mapping pixel datafrom the framebuffer before it is given to the transformation matrix.The data is interpreted as an array of
structdrm_color_lutelements.Hardware might choose not to use the full precision of the LUT elementsnor use all the elements of the LUT (for example the hardware mightchoose to interpolate between LUT[0] and LUT[4]).Setting this to NULL (blob property value set to 0) means alinear/pass-thru gamma table should be used. This is generally thedriver boot-up state too. Drivers can access this blob through
drm_crtc_state.degamma_lut.- “DEGAMMA_LUT_SIZE”:
Unsinged range property to give the size of the lookup table to be seton the DEGAMMA_LUT property (the size depends on the underlyinghardware). If drivers support multiple LUT sizes then they shouldpublish the largest size, and sub-sample smaller sized LUTs (e.g. forsplit-gamma modes) appropriately.
- “CTM”:
Blob property to set the current transformation matrix (CTM) apply topixel data after the lookup through the degamma LUT and before thelookup through the gamma LUT. The data is interpreted as a struct
drm_color_ctm.Setting this to NULL (blob property value set to 0) means aunit/pass-thru matrix should be used. This is generally the driverboot-up state too. Drivers can access the blob for the color conversionmatrix through
drm_crtc_state.ctm.- “GAMMA_LUT”:
Blob property to set the gamma lookup table (LUT) mapping pixel dataafter the transformation matrix to data sent to the connector. Thedata is interpreted as an array of
structdrm_color_lutelements.Hardware might choose not to use the full precision of the LUT elementsnor use all the elements of the LUT (for example the hardware mightchoose to interpolate between LUT[0] and LUT[4]).Setting this to NULL (blob property value set to 0) means alinear/pass-thru gamma table should be used. This is generally thedriver boot-up state too. Drivers can access this blob through
drm_crtc_state.gamma_lut.Note that for mostly historical reasons stemming from Xorg heritage,this is also used to store the color map (also sometimes color lut, CLUTor color palette) for indexed formats like DRM_FORMAT_C8.
- “GAMMA_LUT_SIZE”:
Unsigned range property to give the size of the lookup table to be seton the GAMMA_LUT property (the size depends on the underlying hardware).If drivers support multiple LUT sizes then they should publish thelargest size, and sub-sample smaller sized LUTs (e.g. for split-gammamodes) appropriately.
There is also support for a legacy gamma table, which is set up by callingdrm_mode_crtc_set_gamma_size(). The DRM core will then alias the legacy gammaramp with “GAMMA_LUT” or, if that is unavailable, “DEGAMMA_LUT”.
Support for different non RGB color encodings is controlled throughdrm_plane specific COLOR_ENCODING and COLOR_RANGE properties. Theyare set up by callingdrm_plane_create_color_properties().
- “COLOR_ENCODING”:
Optional plane
enumpropertyto support different non RGBcolor encodings. The driver can provide a subset of standardenumvaluessupported by the DRM plane.- “COLOR_RANGE”:
Optional plane
enumpropertyto support different non RGBcolor parameter ranges. The driver can provide a subset ofstandardenumvaluessupported by the DRM plane.
Tile Group Property¶
Tile groups are used to represent tiled monitors with a unique integeridentifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle,we store this in a tile group, so we have a common identifier for all tilesin a monitor group. The property is called “TILE”. Drivers can manage tilegroups usingdrm_mode_create_tile_group(),drm_mode_put_tile_group() anddrm_mode_get_tile_group(). But this is only needed for internal panels wherethe tile group information is exposed through a non-standard way.
Explicit Fencing Properties¶
Explicit fencing allows userspace to control the buffer synchronizationbetween devices. A Fence or a group of fences are transferred to/fromuserspace using Sync File fds and there are two DRM properties for that.IN_FENCE_FD on each DRM Plane to send fences to the kernel andOUT_FENCE_PTR on each DRM CRTC to receive fences from the kernel.
As a contrast, with implicit fencing the kernel keeps track of anyongoing rendering, and automatically ensures that the atomic update waitsfor any pending rendering to complete. This is usually tracked instructdma_resv which can also contain mandatory kernel fences. Implicit syncingis how Linux traditionally worked (e.g. DRI2/3 on X.org), whereas explicitfencing is what Android wants.
- “IN_FENCE_FD”:
Use this property to pass a fence that DRM should wait on beforeproceeding with the Atomic Commit request and show the framebuffer forthe plane on the screen. The fence can be either a normal fence or amerged one, the sync_file framework will handle both cases and use afence_array if a merged fence is received. Passing -1 here means nofences to wait on.
If the Atomic Commit request has the DRM_MODE_ATOMIC_TEST_ONLY flagit will only check if the Sync File is a valid one.
On the driver side the fence is stored on thefence parameter of
structdrm_plane_state. Drivers which also support implicit fencingshould extract the implicit fence usingdrm_gem_plane_helper_prepare_fb(),to make sure there’s consistent behaviour between drivers in precedenceof implicit vs. explicit fencing.- “OUT_FENCE_PTR”:
Use this property to pass a file descriptor pointer to DRM. Once theAtomic Commit request call returns OUT_FENCE_PTR will be filled withthe file descriptor number of a Sync File. This Sync File contains theCRTC fence that will be signaled when all framebuffers present on theAtomic Commit * request for that given CRTC are scanned out on thescreen.
The Atomic Commit request fails if a invalid pointer is passed. If theAtomic Commit request fails for any other reason the out fence fdreturned will be -1. On a Atomic Commit with theDRM_MODE_ATOMIC_TEST_ONLY flag the out fence will also be set to -1.
Note that out-fences don’t have a special interface to drivers and areinternally represented by a
structdrm_pending_vblank_eventin structdrm_crtc_state, which is also used by the nonblocking atomic commithelpers and for the DRM event handling for existing userspace.
Variable Refresh Properties¶
Variable refresh rate capable displays can dynamically adjust theirrefresh rate by extending the duration of their vertical front porchuntil page flip or timeout occurs. This can reduce or remove stutteringand latency in scenarios where the page flip does not align with thevblank interval.
An example scenario would be an application flipping at a constant rateof 48Hz on a 60Hz display. The page flip will frequently miss the vblankinterval and the same contents will be displayed twice. This can beobserved as stuttering for content with motion.
If variable refresh rate was active on a display that supported avariable refresh range from 35Hz to 60Hz no stuttering would be observablefor the example scenario. The minimum supported variable refresh rate of35Hz is below the page flip frequency and the vertical front porch canbe extended until the page flip occurs. The vblank interval will bedirectly aligned to the page flip rate.
Not all userspace content is suitable for use with variable refresh rate.Large and frequent changes in vertical front porch duration may worsenperceived stuttering for input sensitive applications.
Panel brightness will also vary with vertical front porch duration. Somepanels may have noticeable differences in brightness between the minimumvertical front porch duration and the maximum vertical front porch duration.Large and frequent changes in vertical front porch duration may produceobservable flickering for such panels.
Userspace control for variable refresh rate is supported via propertieson thedrm_connector anddrm_crtc objects.
- “vrr_capable”:
Optional
drm_connectorboolean property that drivers should attachwithdrm_connector_attach_vrr_capable_property()on connectors thatcould support variable refresh rates. Drivers should update theproperty value by callingdrm_connector_set_vrr_capable_property().Absence of the property should indicate absence of support.
- “VRR_ENABLED”:
Default
drm_crtcboolean property that notifies the driver that thecontent on the CRTC is suitable for variable refresh rate presentation.The driver will take this property as a hint to enable variablerefresh rate support if the receiver supports it, ie. if the“vrr_capable” property is true on thedrm_connectorobject. Thevertical front porch duration will be extended until page-flip ortimeout when enabled.The minimum vertical front porch duration is defined as the verticalfront porch duration for the current mode.
The maximum vertical front porch duration is greater than or equal tothe minimum vertical front porch duration. The duration is derivedfrom the minimum supported variable refresh rate for the connector.
The driver may place further restrictions within these minimumand maximum bounds.
Cursor Hotspot Properties¶
HOTSPOT_X: property to set mouse hotspot x offset.HOTSPOT_Y: property to set mouse hotspot y offset.
When the plane is being used as a cursor image to display a mouse pointer,the “hotspot” is the offset within the cursor image where mouse eventsare expected to go.
Positive values move the hotspot from the top-left corner of the cursorplane towards the right and bottom.
Most display drivers do not need this information because thehotspot is not actually connected to anything visible on screen.However, this is necessary for display drivers like the para-virtualizeddrivers (eg qxl, vbox, virtio, vmwgfx), that are attached to a user consolewith a mouse pointer. Since these consoles are often being remoted over anetwork, they would otherwise have to wait to display the pointer movement tothe user until a full network round-trip has occurred. New mouse events haveto be sent from the user’s console, over the network to the virtual inputdevices, forwarded to the desktop for processing, and then the cursor plane’sposition can be updated and sent back to the user’s console over the network.Instead, with the hotspot information, the console can anticipate the newlocation, and draw the mouse cursor there before the confirmation comes in.To do that correctly, the user’s console must be able predict how thedesktop will process mouse events, which normally requires the desktop’smouse topology information, ie where each CRTC sits in the mouse coordinatespace. This is typically sent to the para-virtualized drivers using somedriver-specific method, and the driver then forwards it to the console byway of the virtual display device or hypervisor.
The assumption is generally made that there is only one cursor plane beingused this way at a time, and that the desktop is feeding all mouse devicesinto the same global pointer. Para-virtualized drivers that require thisshould only be exposing a single cursor plane, or find some other wayto coordinate with a userspace desktop that supports multiple pointers.If the hotspot properties are set, the cursor plane is therefore assumed to beused only for displaying a mouse cursor image, and the position of the combinedcursor plane + offset can therefore be used for coordinating with input from amouse device.
The cursor will then be drawn either at the location of the plane in the CRTCconsole, or as a free-floating cursor plane on the user’s consolecorresponding to their desktop mouse position.
DRM clients which would like to work correctly on drivers which exposehotspot properties should advertise DRM_CLIENT_CAP_CURSOR_PLANE_HOTSPOT.Setting this property on drivers which do not special casecursor planes will return EOPNOTSUPP, which can be used by userspace togauge requirements of the hardware/drivers they’re running on. AdvertisingDRM_CLIENT_CAP_CURSOR_PLANE_HOTSPOT implies that the userspace client will becorrectly setting the hotspot properties.
Existing KMS Properties¶
The following table gives description of drm properties exposed by variousmodules/drivers. Because this table is very unwieldy, do not add any newproperties here. Instead document them in a section above.
Owner Module/Drivers | Group | Property Name | Type | Property Values | Object attached | Description/Restrictions |
|---|---|---|---|---|---|---|
DVI-I | “subconnector” | ENUM | { “Unknown”, “DVI-D”, “DVI-A” } | Connector | TBD | |
“select subconnector” | ENUM | { “Automatic”, “DVI-D”, “DVI-A” } | Connector | TBD | ||
TV | “subconnector” | ENUM | { “Unknown”, “Composite”, “SVIDEO”, “Component”, “SCART” } | Connector | TBD | |
“select subconnector” | ENUM | { “Automatic”, “Composite”, “SVIDEO”, “Component”, “SCART” } | Connector | TBD | ||
“mode” | ENUM | { “NTSC_M”, “NTSC_J”, “NTSC_443”, “PAL_B” } etc. | Connector | TBD | ||
“left margin” | RANGE | Min=0, Max=100 | Connector | TBD | ||
“right margin” | RANGE | Min=0, Max=100 | Connector | TBD | ||
“top margin” | RANGE | Min=0, Max=100 | Connector | TBD | ||
“bottom margin” | RANGE | Min=0, Max=100 | Connector | TBD | ||
“brightness” | RANGE | Min=0, Max=100 | Connector | TBD | ||
“contrast” | RANGE | Min=0, Max=100 | Connector | TBD | ||
“flicker reduction” | RANGE | Min=0, Max=100 | Connector | TBD | ||
“overscan” | RANGE | Min=0, Max=100 | Connector | TBD | ||
“saturation” | RANGE | Min=0, Max=100 | Connector | TBD | ||
“hue” | RANGE | Min=0, Max=100 | Connector | TBD | ||
Virtual GPU | “suggested X” | RANGE | Min=0, Max=0xffffffff | Connector | property to suggest an X offset for a connector | |
“suggested Y” | RANGE | Min=0, Max=0xffffffff | Connector | property to suggest an Y offset for a connector | ||
Optional | “aspect ratio” | ENUM | { “None”, “4:3”, “16:9” } | Connector | TDB | |
“audio” | ENUM | { “force-dvi”, “off”, “auto”, “on” } | Connector | TBD | ||
SDVO-TV | “mode” | ENUM | { “NTSC_M”, “NTSC_J”, “NTSC_443”, “PAL_B” } etc. | Connector | TBD | |
“left_margin” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“right_margin” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“top_margin” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“bottom_margin” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“hpos” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“vpos” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“contrast” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“saturation” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“hue” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“sharpness” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“flicker_filter” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“flicker_filter_adaptive” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“flicker_filter_2d” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“tv_chroma_filter” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“tv_luma_filter” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“dot_crawl” | RANGE | Min=0, Max=1 | Connector | TBD | ||
SDVO-TV/LVDS | “brightness” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | |
CDV gma-500 | Generic | “Broadcast RGB” | ENUM | { “Full”, “Limited 16:235” } | Connector | TBD |
Poulsbo | Generic | “backlight” | RANGE | Min=0, Max=100 | Connector | TBD |
SDVO-TV | “mode” | ENUM | { “NTSC_M”, “NTSC_J”, “NTSC_443”, “PAL_B” } etc. | Connector | TBD | |
“left_margin” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“right_margin” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“top_margin” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“bottom_margin” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“hpos” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“vpos” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“contrast” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“saturation” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“hue” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“sharpness” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“flicker_filter” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“flicker_filter_adaptive” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“flicker_filter_2d” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“tv_chroma_filter” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“tv_luma_filter” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | ||
“dot_crawl” | RANGE | Min=0, Max=1 | Connector | TBD | ||
SDVO-TV/LVDS | “brightness” | RANGE | Min=0, Max= SDVO dependent | Connector | TBD | |
armada | CRTC | “CSC_YUV” | ENUM | { “Auto” , “CCIR601”, “CCIR709” } | CRTC | TBD |
“CSC_RGB” | ENUM | { “Auto”, “Computer system”, “Studio” } | CRTC | TBD | ||
Overlay | “colorkey” | RANGE | Min=0, Max=0xffffff | Plane | TBD | |
“colorkey_min” | RANGE | Min=0, Max=0xffffff | Plane | TBD | ||
“colorkey_max” | RANGE | Min=0, Max=0xffffff | Plane | TBD | ||
“colorkey_val” | RANGE | Min=0, Max=0xffffff | Plane | TBD | ||
“colorkey_alpha” | RANGE | Min=0, Max=0xffffff | Plane | TBD | ||
“colorkey_mode” | ENUM | { “disabled”, “Y component”, “U component” , “V component”, “RGB”, “R component”, “G component”, “B component” } | Plane | TBD | ||
“brightness” | RANGE | Min=0, Max=256 + 255 | Plane | TBD | ||
“contrast” | RANGE | Min=0, Max=0x7fff | Plane | TBD | ||
“saturation” | RANGE | Min=0, Max=0x7fff | Plane | TBD | ||
exynos | CRTC | “mode” | ENUM | { “normal”, “blank” } | CRTC | TBD |
i2c/ch7006_drv | Generic | “scale” | RANGE | Min=0, Max=2 | Connector | TBD |
TV | “mode” | ENUM | { “PAL”, “PAL-M”,”PAL-N”}, ”PAL-Nc” , “PAL-60”, “NTSC-M”, “NTSC-J” } | Connector | TBD | |
nouveau | NV10 Overlay | “colorkey” | RANGE | Min=0, Max=0x01ffffff | Plane | TBD |
“contrast” | RANGE | Min=0, Max=8192-1 | Plane | TBD | ||
“brightness” | RANGE | Min=0, Max=1024 | Plane | TBD | ||
“hue” | RANGE | Min=0, Max=359 | Plane | TBD | ||
“saturation” | RANGE | Min=0, Max=8192-1 | Plane | TBD | ||
“iturbt_709” | RANGE | Min=0, Max=1 | Plane | TBD | ||
Nv04 Overlay | “colorkey” | RANGE | Min=0, Max=0x01ffffff | Plane | TBD | |
“brightness” | RANGE | Min=0, Max=1024 | Plane | TBD | ||
Display | “dithering mode” | ENUM | { “auto”, “off”, “on” } | Connector | TBD | |
“dithering depth” | ENUM | { “auto”, “off”, “on”, “static 2x2”, “dynamic 2x2”, “temporal” } | Connector | TBD | ||
“underscan” | ENUM | { “auto”, “6 bpc”, “8 bpc” } | Connector | TBD | ||
“underscan hborder” | RANGE | Min=0, Max=128 | Connector | TBD | ||
“underscan vborder” | RANGE | Min=0, Max=128 | Connector | TBD | ||
“vibrant hue” | RANGE | Min=0, Max=180 | Connector | TBD | ||
“color vibrance” | RANGE | Min=0, Max=200 | Connector | TBD | ||
omap | Generic | “zorder” | RANGE | Min=0, Max=3 | CRTC, Plane | TBD |
qxl | Generic | “hotplug_mode_update” | RANGE | Min=0, Max=1 | Connector | TBD |
radeon | DVI-I | “coherent” | RANGE | Min=0, Max=1 | Connector | TBD |
DAC enable load detect | “load detection” | RANGE | Min=0, Max=1 | Connector | TBD | |
TV Standard | “tv standard” | ENUM | { “ntsc”, “pal”, “pal-m”, “pal-60”, “ntsc-j” , “scart-pal”, “pal-cn”, “secam” } | Connector | TBD | |
legacy TMDS PLL detect | “tmds_pll” | ENUM | { “driver”, “bios” } | TBD | ||
Underscan | “underscan” | ENUM | { “off”, “on”, “auto” } | Connector | TBD | |
“underscan hborder” | RANGE | Min=0, Max=128 | Connector | TBD | ||
“underscan vborder” | RANGE | Min=0, Max=128 | Connector | TBD | ||
Audio | “audio” | ENUM | { “off”, “on”, “auto” } | Connector | TBD | |
FMT Dithering | “dither” | ENUM | { “off”, “on” } | Connector | TBD | |
“colorkey” | RANGE | Min=0, Max=0x01ffffff | Plane | TBD |
Vertical Blanking¶
From the computer’s perspective, every time the monitor displaysa new frame the scanout engine has “scanned out” the display imagefrom top to bottom, one row of pixels at a time. The current rowof pixels is referred to as the current scanline.
In addition to the display’s visible area, there’s usually a couple ofextra scanlines which aren’t actually displayed on the screen.These extra scanlines don’t contain image data and are occasionally usedfor features like audio and infoframes. The region made up of thesescanlines is referred to as the vertical blanking region, or vblank forshort.
For historical reference, the vertical blanking period was designed togive the electron gun (on CRTs) enough time to move back to the top ofthe screen to start scanning out the next frame. Similar for horizontalblanking periods. They were designed to give the electron gun enoughtime to move back to the other side of the screen to start scanning thenext scanline.
physical → ⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽top of | |display | | | New frame | | | |↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓| |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| ← Scanline, |↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓| updates the | | frame as it | | travels down | | ("scan out") | Old frame | | | | | | | | | physical | | bottom ofvertical |⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽| ← displayblanking ┆xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx┆region → ┆xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx┆ ┆xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx┆start of → ⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽new frame“Physical top of display” is the reference point for the high-precision/corrected timestamp.
On a lot of display hardware, programming needs to take effect during thevertical blanking period so that settings like gamma, the image bufferbuffer to be scanned out, etc. can safely be changed without showingany visual artifacts on the screen. In some unforgiving hardware, some ofthis programming has to both start and end in the same vblank. To helpwith the timing of the hardware programming, an interrupt is usuallyavailable to notify the driver when it can start the updating of registers.The interrupt is in this context named the vblank interrupt.
The vblank interrupt may be fired at different points depending on thehardware. Some hardware implementations will fire the interrupt when thenew frame start, other implementations will fire the interrupt at differentpoints in time.
Vertical blanking plays a major role in graphics rendering. To achievetear-free display, users must synchronize page flips and/or rendering tovertical blanking. The DRM API offers ioctls to perform page flipssynchronized to vertical blanking and wait for vertical blanking.
The DRM core handles most of the vertical blanking management logic, whichinvolves filtering out spurious interrupts, keeping race-free blankingcounters, coping with counter wrap-around and resets and keeping use counts.It relies on the driver to generate vertical blanking interrupts andoptionally provide a hardware vertical blanking counter.
Drivers must initialize the vertical blanking handling core with a call todrm_vblank_init(). Minimally, a driver needs to implementdrm_crtc_funcs.enable_vblank anddrm_crtc_funcs.disable_vblank plus calldrm_crtc_handle_vblank() in its vblank interrupt handler for working vblanksupport.
Vertical blanking interrupts can be enabled by the DRM core or by driversthemselves (for instance to handle page flipping operations). The DRM coremaintains a vertical blanking use count to ensure that the interrupts are notdisabled while a user still needs them. To increment the use count, driverscalldrm_crtc_vblank_get() and release the vblank reference again withdrm_crtc_vblank_put(). In between these two calls vblank interrupts areguaranteed to be enabled.
On many hardware disabling the vblank interrupt cannot be done in a race-freemanner, seedrm_vblank_crtc_config.disable_immediate anddrm_driver.max_vblank_count. In that case the vblank core only disables thevblanks after a timer has expired, which can be configured through thevblankoffdelay module parameter.
Drivers for hardware without support for vertical-blanking interrupts canuse DRM vblank timers to send vblank events at the rate of the currentdisplay mode’s refresh. While not synchronized to the hardware’svertical-blanking regions, the timer helps DRM clients and compositors toadapt their update cycle to the display output. Drivers should set upvblanking as usual, but calldrm_crtc_vblank_start_timer() anddrm_crtc_vblank_cancel_timer() as part of their atomic mode setting.See also DRM vblank helpers for more information.
Drivers without support for vertical-blanking interrupts nor timers mustnot calldrm_vblank_init(). For these drivers, atomic helpers willautomatically generate fake vblank events as part of the display update.This functionality also can be controlled by the driver by enabling anddisablingstructdrm_crtc_state.no_vblank.
Vertical Blanking and Interrupt Handling Functions Reference¶
- structdrm_pending_vblank_event¶
pending vblank event tracking
Definition:
struct drm_pending_vblank_event { struct drm_pending_event base; unsigned int pipe; u64 sequence; union { struct drm_event base; struct drm_event_vblank vbl; struct drm_event_crtc_sequence seq; } event;};Members
baseBase structure for tracking pending DRM events.
pipedrm_crtc_index()of thedrm_crtcthis event is for.sequenceframe event should be triggered at
eventActual event which will be sent to userspace.
event.baseDRM event base class.
event.vblEvent payload for vblank events, requested througheither the MODE_PAGE_FLIP or MODE_ATOMIC IOCTL. Alsogenerated by the legacy WAIT_VBLANK IOCTL, but new userspaceshould use MODE_QUEUE_SEQUENCE and
event.seqinstead.event.seqEvent payload for the MODE_QUEUEU_SEQUENCE IOCTL.
- structdrm_vblank_crtc_config¶
vblank configuration for a CRTC
Definition:
struct drm_vblank_crtc_config { int offdelay_ms; bool disable_immediate;};Members
offdelay_msVblank off delay in ms, used to determine how long
drm_vblank_crtc.disable_timerwaits before disabling.Defaults to the value of drm_vblank_offdelay in
drm_crtc_vblank_on().disable_immediateSee
drm_device.vblank_disable_immediatefor the exact semantics of immediate vblank disabling.Additionally, this tracks the disable immediate value per crtc, justin case it needs to differ from the default value for a given device.
Defaults to the value of
drm_device.vblank_disable_immediateindrm_crtc_vblank_on().
- structdrm_vblank_crtc_timer¶
vblank timer for a CRTC
Definition:
struct drm_vblank_crtc_timer { struct hrtimer timer; spinlock_t interval_lock; ktime_t interval; struct drm_crtc *crtc;};Members
timerThe vblank’s high-resolution timer
interval_lockProtectsinterval
intervalDuration between two vblanks
crtcThe timer’s CRTC
- structdrm_vblank_crtc¶
vblank tracking for a CRTC
Definition:
struct drm_vblank_crtc { struct drm_device *dev; wait_queue_head_t queue; struct timer_list disable_timer; seqlock_t seqlock; atomic64_t count; ktime_t time; atomic_t refcount; u32 last; u32 max_vblank_count; unsigned int inmodeset; unsigned int pipe; int framedur_ns; int linedur_ns; struct drm_display_mode hwmode; struct drm_vblank_crtc_config config; bool enabled; struct kthread_worker *worker; struct list_head pending_work; wait_queue_head_t work_wait_queue; struct drm_vblank_crtc_timer vblank_timer;};Members
devPointer to the
drm_device.queueWait queue for vblank waiters.
disable_timerDisable timer for the delayed vblank disablinghysteresis logic. Vblank disabling is controlled through
drm_vblank_crtc_config.offdelay_msand the setting of thedrm_device.max_vblank_countvalue.seqlockProtect vblank count and time.
countCurrent software vblank counter.
Note that for a given vblank counter value
drm_crtc_handle_vblank()anddrm_crtc_vblank_count()ordrm_crtc_vblank_count_and_time()provide a barrier: Any writes done before callingdrm_crtc_handle_vblank()will be visible to callers of the laterfunctions, iff the vblank count is the same or a later one.IMPORTANT: This guarantee requires barriers, therefor never accessthis field directly. Use
drm_crtc_vblank_count()instead.timeVblank timestamp corresponding tocount.
refcountNumber of users/waiters of the vblank interrupt. Only whenthis refcount reaches 0 can the hardware interrupt be disabled usingdisable_timer.
lastProtected by
drm_device.vbl_lock, used for wraparound handling.max_vblank_countMaximum value of the vblank registers for this crtc. This value +1will result in a wrap-around of the vblank register. It is usedby the vblank core to handle wrap-arounds.
If set to zero the vblank core will try to guess the elapsed vblanksbetween times when the vblank interrupt is disabled throughhigh-precision timestamps. That approach is suffering from smallraces and imprecision over longer time periods, hence exposing ahardware vblank counter is always recommended.
This is the runtime configurable per-crtc maximum set through
drm_crtc_set_max_vblank_count(). If this is used the drivermust leave the device widedrm_device.max_vblank_countat zero.If non-zero,
drm_crtc_funcs.get_vblank_countermust be set.inmodesetTracks whether the vblank is disabled due to a modeset.For legacy driver bit 2 additionally tracks whether an additionaltemporary vblank reference has been acquired to paper over thehardware counter resetting/jumping. KMS drivers should instead justcall
drm_crtc_vblank_off()anddrm_crtc_vblank_on(), which explicitlysave and restore the vblank count.pipedrm_crtc_index()of thedrm_crtccorresponding to thisstructure.framedur_nsFrame/Field duration in ns, used by
drm_crtc_vblank_helper_get_vblank_timestamp()and computed bydrm_calc_timestamping_constants().linedur_nsLine duration in ns, used by
drm_crtc_vblank_helper_get_vblank_timestamp()and computed bydrm_calc_timestamping_constants().hwmodeCache of the current hardware display mode. Only valid whenenabledis set. This is used by helpers like
drm_crtc_vblank_helper_get_vblank_timestamp(). We can’t just accessthe hardware mode by e.g. looking atdrm_crtc_state.adjusted_mode,because that one is really hard to get from interrupt context.configStores vblank configuration values for a given CRTC.Also, see
drm_crtc_vblank_on_config().enabledTracks the enabling state of the corresponding
drm_crtctoavoid double-disabling and hence corrupting saved state. Needed bydrivers not using atomic KMS, since those might go through their CRTCdisabling functions multiple times.workerThe
kthread_workerused for executing vblank works.pending_workA list of scheduled
drm_vblank_workitems that arewaiting for a future vblank.work_wait_queueThe wait queue used for signaling that a
drm_vblank_workitem has either finished executing, or wascancelled.vblank_timerHolds the state of the vblank timer
Description
This structure tracks the vblank state for one CRTC.
Note that for historical reasons - the vblank handling code is still sharedwith legacy/non-kms drivers - this is a free-standing structure not directlyconnected tostructdrm_crtc. But all public interface functions are takingastructdrm_crtc to hide this implementation detail.
Parameters
structdrm_crtc*crtcwhich counter to retrieve
Description
This function is similar todrm_crtc_vblank_count() but this functioninterpolates to handle a race with vblank interrupts using the high precisiontimestamping support.
This is mostly useful for hardware that can obtain the scanout position, butdoesn’t have a hardware frame counter.
- intdrm_vblank_init(structdrm_device*dev,unsignedintnum_crtcs)¶
initialize vblank support
Parameters
structdrm_device*devDRM device
unsignedintnum_crtcsnumber of CRTCs supported bydev
Description
This function initializes vblank support fornum_crtcs display pipelines.Cleanup is handled automatically through a cleanup function added withdrmm_add_action_or_reset().
Return
Zero on success or a negative error code on failure.
- booldrm_dev_has_vblank(conststructdrm_device*dev)¶
test if vblanking has been initialized for a device
Parameters
conststructdrm_device*devthe device
Description
Drivers may call this function to test if vblank support isinitialized for a device. For most hardware this means that vblankingcan also be enabled.
Atomic helpers use this function to initializedrm_crtc_state.no_vblank. See alsodrm_atomic_helper_check_modeset().
Return
True if vblanking has been initialized for the given device, falseotherwise.
Parameters
structdrm_crtc*crtcwhich CRTC’s vblank waitqueue to retrieve
Description
This function returns a pointer to the vblank waitqueue for the CRTC.Drivers can use this to implement vblank waits usingwait_event() and relatedfunctions.
- voiddrm_calc_timestamping_constants(structdrm_crtc*crtc,conststructdrm_display_mode*mode)¶
calculate vblank timestamp constants
Parameters
structdrm_crtc*crtcdrm_crtc whose timestamp constants should be updated.
conststructdrm_display_mode*modedisplay mode containing the scanout timings
Description
Calculate and store various constants which are later needed by vblank andswap-completion timestamping, e.g, bydrm_crtc_vblank_helper_get_vblank_timestamp(). They are derived fromCRTC’s true scanout timing, so they take things like panel scaling orother adjustments into account.
- booldrm_crtc_vblank_helper_get_vblank_timestamp_internal(structdrm_crtc*crtc,int*max_error,ktime_t*vblank_time,boolin_vblank_irq,drm_vblank_get_scanout_position_funcget_scanout_position)¶
precise vblank timestamp helper
Parameters
structdrm_crtc*crtcCRTC whose vblank timestamp to retrieve
int*max_errorDesired maximum allowable error in timestamps (nanosecs)On return contains true maximum error of timestamp
ktime_t*vblank_timePointer to time which should receive the timestamp
boolin_vblank_irqTrue when called from
drm_crtc_handle_vblank(). Some driversneed to apply some workarounds for gpu-specific vblank irq quirksif flag is set.drm_vblank_get_scanout_position_funcget_scanout_positionCallback function to retrieve the scanout position. Seestruct drm_crtc_helper_funcs.get_scanout_position.
Description
Implements calculation of exact vblank timestamps from given drm_display_modetimings and current video scanout position of a CRTC.
The current implementation only handles standard video modes. For double scanand interlaced modes the driver is supposed to adjust the hardware mode(taken fromdrm_crtc_state.adjusted mode for atomic modeset drivers) tomatch the scanout position reported.
Note that atomic drivers must calldrm_calc_timestamping_constants() beforeenabling a CRTC. The atomic helpers already take care of that indrm_atomic_helper_calc_timestamping_constants().
Return
Returns true on success, and false on failure, i.e. when no accuratetimestamp could be acquired.
- booldrm_crtc_vblank_helper_get_vblank_timestamp(structdrm_crtc*crtc,int*max_error,ktime_t*vblank_time,boolin_vblank_irq)¶
precise vblank timestamp helper
Parameters
structdrm_crtc*crtcCRTC whose vblank timestamp to retrieve
int*max_errorDesired maximum allowable error in timestamps (nanosecs)On return contains true maximum error of timestamp
ktime_t*vblank_timePointer to time which should receive the timestamp
boolin_vblank_irqTrue when called from
drm_crtc_handle_vblank(). Some driversneed to apply some workarounds for gpu-specific vblank irq quirksif flag is set.
Description
Implements calculation of exact vblank timestamps from given drm_display_modetimings and current video scanout position of a CRTC. This can be directlyused as thedrm_crtc_funcs.get_vblank_timestamp implementation of a kmsdriver ifdrm_crtc_helper_funcs.get_scanout_position is implemented.
The current implementation only handles standard video modes. For double scanand interlaced modes the driver is supposed to adjust the hardware mode(taken fromdrm_crtc_state.adjusted mode for atomic modeset drivers) tomatch the scanout position reported.
Note that atomic drivers must calldrm_calc_timestamping_constants() beforeenabling a CRTC. The atomic helpers already take care of that indrm_atomic_helper_calc_timestamping_constants().
Return
Returns true on success, and false on failure, i.e. when no accuratetimestamp could be acquired.
Parameters
structdrm_crtc*crtcwhich counter to retrieve
Description
Fetches the “cooked” vblank count value that represents the number ofvblank events since the system was booted, including lost events due tomodesetting activity. Note that this timer isn’t correct against a racingvblank interrupt (since it only reports the software vblank counter), seedrm_crtc_accurate_vblank_count() for such use-cases.
Note that for a given vblank counter valuedrm_crtc_handle_vblank()anddrm_crtc_vblank_count() ordrm_crtc_vblank_count_and_time()provide a barrier: Any writes done before callingdrm_crtc_handle_vblank() will be visible to callers of the laterfunctions, if the vblank count is the same or a later one.
See alsodrm_vblank_crtc.count.
Return
The software vblank counter.
- u64drm_crtc_vblank_count_and_time(structdrm_crtc*crtc,ktime_t*vblanktime)¶
retrieve “cooked” vblank counter value and the system timestamp corresponding to that vblank counter value
Parameters
structdrm_crtc*crtcwhich counter to retrieve
ktime_t*vblanktimePointer to time to receive the vblank timestamp.
Description
Fetches the “cooked” vblank count value that represents the number ofvblank events since the system was booted, including lost events due tomodesetting activity. Returns corresponding system timestamp of the timeof the vblank interval that corresponds to the current vblank counter value.
Note that for a given vblank counter valuedrm_crtc_handle_vblank()anddrm_crtc_vblank_count() ordrm_crtc_vblank_count_and_time()provide a barrier: Any writes done before callingdrm_crtc_handle_vblank() will be visible to callers of the laterfunctions, if the vblank count is the same or a later one.
See alsodrm_vblank_crtc.count.
- intdrm_crtc_next_vblank_start(structdrm_crtc*crtc,ktime_t*vblanktime)¶
calculate the time of the next vblank
Parameters
structdrm_crtc*crtcthe crtc for which to calculate next vblank time
ktime_t*vblanktimepointer to time to receive the next vblank timestamp.
Description
Calculate the expected time of the start of the next vblank period,based on time of previous vblank and frame duration
- voiddrm_crtc_arm_vblank_event(structdrm_crtc*crtc,structdrm_pending_vblank_event*e)¶
arm vblank event after pageflip
Parameters
structdrm_crtc*crtcthe source CRTC of the vblank event
structdrm_pending_vblank_event*ethe event to send
Description
A lot of drivers need to generate vblank events for the very next vblankinterrupt. For example when the page flip interrupt happens when the pageflip gets armed, but not when it actually executes within the next vblankperiod. This helper function implements exactly the required vblank armingbehaviour.
NOTE
Drivers using this to send out thedrm_crtc_state.event as part of anatomic commit must ensure that the next vblank happens at exactly the sametime as the atomic commit is committed to the hardware. This function itselfdoesnot protect against the next vblank interrupt racing with either thisfunction call or the atomic commit operation. A possible sequence could be:
Driver commits new hardware state into vblank-synchronized registers.
A vblank happens, committing the hardware state. Also the correspondingvblank interrupt is fired off and fully processed by the interrupthandler.
The atomic commit operation proceeds to call
drm_crtc_arm_vblank_event().The event is only send out for the next vblank, which is wrong.
An equivalent race can happen when the driver callsdrm_crtc_arm_vblank_event() before writing out the new hardware state.
The only way to make this work safely is to prevent the vblank from firing(and the hardware from committing anything else) until the entire atomiccommit sequence has run to completion. If the hardware does not have such afeature (e.g. using a “go” bit), then it is unsafe to use this functions.Instead drivers need to manually send out the event from their interrupthandler by callingdrm_crtc_send_vblank_event() and make sure that there’s nopossible race with the hardware committing the atomic update.
Caller must hold a vblank reference for the evente acquired by adrm_crtc_vblank_get(), which will be dropped when the next vblank arrives.
- voiddrm_crtc_send_vblank_event(structdrm_crtc*crtc,structdrm_pending_vblank_event*e)¶
helper to send vblank event after pageflip
Parameters
structdrm_crtc*crtcthe source CRTC of the vblank event
structdrm_pending_vblank_event*ethe event to send
Description
Updates sequence # and timestamp on event for the most recently processedvblank, and sends it to userspace. Caller must hold event lock.
Seedrm_crtc_arm_vblank_event() for a helper which can be used in certainsituation, especially to send out events for atomic commit operations.
Parameters
structdrm_crtc*crtcwhich CRTC to own
Description
Acquire a reference count on vblank events to avoid having them disabledwhile in use.
Return
Zero on success or a negative error code on failure.
Parameters
structdrm_crtc*crtcwhich counter to give up
Description
Release ownership of a given vblank counter, turning off interruptsif possible. Disable interrupts afterdrm_vblank_crtc_config.offdelay_msmilliseconds.
Parameters
structdrm_crtc*crtcDRM crtc
Description
This waits for one vblank to pass oncrtc, using the irq driver interfaces.It is a failure to call this when the vblank irq forcrtc is disabled, e.g.due to lack of driver support or because the crtc is off.
Return
0 on success, negative error on failures.
Parameters
structdrm_crtc*crtcCRTC in question
Description
Drivers can use this function to shut down the vblank interrupt handling whendisabling a crtc. This function ensures that the latest vblank frame count isstored so that drm_vblank_on can restore it again.
Drivers must use this function when the hardware vblank counter can getreset, e.g. when suspending or disabling thecrtc in general.
Parameters
structdrm_crtc*crtcCRTC in question
Description
Drivers can use this function to reset the vblank state to off at load time.Drivers should use this together with thedrm_crtc_vblank_off() anddrm_crtc_vblank_on() functions. The difference compared todrm_crtc_vblank_off() is that this function doesn’t save the vblank counterand hence doesn’t need to call any driver hooks.
This is useful for recovering driver state e.g. on driver load, or on resume.
- voiddrm_crtc_set_max_vblank_count(structdrm_crtc*crtc,u32max_vblank_count)¶
configure the hw max vblank counter value
Parameters
structdrm_crtc*crtcCRTC in question
u32max_vblank_countmax hardware vblank counter value
Description
Update the maximum hardware vblank counter value forcrtcat runtime. Useful for hardware where the operation of thehardware vblank counter depends on the currently activedisplay configuration.
For example, if the hardware vblank counter does not workwhen a specific connector is active the maximum can be setto zero. And when that specific connector isn’t active themaximum can again be set to the appropriate non-zero value.
If used, must be called beforedrm_vblank_on().
- voiddrm_crtc_vblank_on_config(structdrm_crtc*crtc,conststructdrm_vblank_crtc_config*config)¶
enable vblank events on a CRTC with custom configuration options
Parameters
structdrm_crtc*crtcCRTC in question
conststructdrm_vblank_crtc_config*configVblank configuration value
Description
Seedrm_crtc_vblank_on(). In addition, this function allows you to provide acustom vblank configuration for a given CRTC.
Note thatconfig is copied, the pointer does not need to stay valid beyondthis function call. For details of the parameters seestructdrm_vblank_crtc_config.
Parameters
structdrm_crtc*crtcCRTC in question
Description
This functions restores the vblank interrupt state captured withdrm_crtc_vblank_off() again and is generally called when enablingcrtc. Notethat calls todrm_crtc_vblank_on() anddrm_crtc_vblank_off() can beunbalanced and so can also be unconditionally called in driver load code toreflect the current hardware state of the crtc.
Note that unlike indrm_crtc_vblank_on_config(), default values are used.
Parameters
structdrm_crtc*crtcCRTC in question
Description
Power manamement features can cause frame counter resets between vblankdisable and enable. Drivers can use this function in theirdrm_crtc_funcs.enable_vblank implementation to estimate missed vblanks sincethe lastdrm_crtc_funcs.disable_vblank using timestamps and update thevblank counter.
Note that drivers must have race-free high-precision timestamping support,i.e.drm_crtc_funcs.get_vblank_timestamp must be hooked up anddrm_vblank_crtc_config.disable_immediate must be set to indicate thetime-stamping functions are race-free against vblank hardware counterincrements.
- booldrm_handle_vblank(structdrm_device*dev,unsignedintpipe)¶
handle a vblank event
Parameters
structdrm_device*devDRM device
unsignedintpipeindex of CRTC where this event occurred
Description
Drivers should call this routine in their vblank interrupt handlers toupdate the vblank counter and send any signals that may be pending.
This is the legacy version ofdrm_crtc_handle_vblank().
Parameters
structdrm_crtc*crtcwhere this event occurred
Description
Drivers should call this routine in their vblank interrupt handlers toupdate the vblank counter and send any signals that may be pending.
This is the native KMS version ofdrm_handle_vblank().
Note that for a given vblank counter valuedrm_crtc_handle_vblank()anddrm_crtc_vblank_count() ordrm_crtc_vblank_count_and_time()provide a barrier: Any writes done before callingdrm_crtc_handle_vblank() will be visible to callers of the laterfunctions, if the vblank count is the same or a later one.
See alsodrm_vblank_crtc.count.
Return
True if the event was successfully handled, false on failure.
Parameters
structdrm_crtc*crtcthe CRTC
Description
Drivers should call this function from their CRTC’s enable_vblankfunction to start a vblank timer. The timer will fire after the durationof a full frame.drm_crtc_vblank_cancel_timer() disables a running timer.
Return
0 on success, or a negative errno code otherwise.
Parameters
structdrm_crtc*crtcthe CRTC
Description
Drivers should call this function from their CRTC’s disable_vblankfunction to stop a vblank timer.
- voiddrm_crtc_vblank_get_vblank_timeout(structdrm_crtc*crtc,ktime_t*vblank_time)¶
Returns the vblank timeout
Parameters
structdrm_crtc*crtcThe CRTC
ktime_t*vblank_timeReturns the next vblank timestamp
Description
The helperdrm_crtc_vblank_get_vblank_timeout() returns the next vblanktimestamp of the CRTC’s vblank timer according to the timer’s expirytime.
Vertical Blank Work¶
Many DRM drivers need to program hardware in a time-sensitive manner, manytimes with a deadline of starting and finishing within a certain region ofthe scanout. Most of the time the safest way to accomplish this is tosimply do said time-sensitive programming in the driver’s IRQ handler,which allows drivers to avoid being preempted during these criticalregions. Or even better, the hardware may even handle applying suchtime-critical programming independently of the CPU.
While there’s a decent amount of hardware that’s designed so that the CPUdoesn’t need to be concerned with extremely time-sensitive programming,there’s a few situations where it can’t be helped. Some unforgivinghardware may require that certain time-sensitive programming be handledcompletely by the CPU, and said programming may even take too long tohandle in an IRQ handler. Another such situation would be where the driverneeds to perform a task that needs to complete within a specific scanoutperiod, but might possibly block and thus cannot be handled in an IRQcontext. Both of these situations can’t be solved perfectly in Linux sincewe’re not a realtime kernel, and thus the scheduler may cause us to missour deadline if it decides to preempt us. But for some drivers, it’s goodenough if we can lower our chance of being preempted to an absoluteminimum.
This is wheredrm_vblank_work comes in.drm_vblank_work provides a simplegeneric delayed work implementation which delays work execution until aparticular vblank has passed, and then executes the work at realtimepriority. This provides the best possible chance at performingtime-sensitive hardware programming on time, even when the system is underheavy load.drm_vblank_work also supports rescheduling, so that selfre-arming work items can be easily implemented.
Vertical Blank Work Functions Reference¶
- structdrm_vblank_work¶
A delayed work item which delays until a target vblank passes, and then executes at realtime priority outside of IRQ context.
Definition:
struct drm_vblank_work { struct kthread_work base; struct drm_vblank_crtc *vblank; u64 count; int cancelling; struct list_head node;};Members
baseThe base
kthread_workitem which will be executed bydrm_vblank_crtc.worker. Drivers should not interact with thisdirectly, and instead rely ondrm_vblank_work_init()to initializethis.vblankA pointer to
drm_vblank_crtcthis work item belongs to.countThe target vblank this work will execute on. Drivers shouldnot modify this value directly, and instead use
drm_vblank_work_schedule()cancellingThe number of
drm_vblank_work_cancel_sync()calls thatare currently running. A work item cannot be rescheduled until allcalls have finished.nodeThe position of this work item in
drm_vblank_crtc.pending_work.
Description
See also:drm_vblank_work_schedule()drm_vblank_work_init()drm_vblank_work_cancel_sync()drm_vblank_work_flush()drm_vblank_work_flush_all()
- to_drm_vblank_work¶
to_drm_vblank_work(_work)
Retrieve the respective
drm_vblank_workitem from akthread_work
Parameters
_workThe
kthread_workembedded inside adrm_vblank_work
- intdrm_vblank_work_schedule(structdrm_vblank_work*work,u64count,boolnextonmiss)¶
schedule a vblank work
Parameters
structdrm_vblank_work*workvblank work to schedule
u64counttarget vblank count
boolnextonmissdefer until the next vblank if target vblank was missed
Description
Schedulework for execution once the crtc vblank count reachescount.
If the crtc vblank count has already reachedcount andnextonmiss isfalse the work starts to execute immediately.
If the crtc vblank count has already reachedcount andnextonmiss istrue the work is deferred until the next vblank (as ifcount has beenspecified as crtc vblank count + 1).
Ifwork is already scheduled, this function will reschedule said workusing the newcount. This can be used for self-rearming work items.
Return
1 ifwork was successfully (re)scheduled,0 if it was either alreadyscheduled or cancelled, or a negative error code on failure.
- booldrm_vblank_work_cancel_sync(structdrm_vblank_work*work)¶
cancel a vblank work and wait for it to finish executing
Parameters
structdrm_vblank_work*workvblank work to cancel
Description
Cancel an already scheduled vblank work and wait for itsexecution to finish.
On return,work is guaranteed to no longer be scheduled or running, evenif it’s self-arming.
Return
True if the work was cancelled before it started to execute,falseotherwise.
- voiddrm_vblank_work_flush(structdrm_vblank_work*work)¶
wait for a scheduled vblank work to finish executing
Parameters
structdrm_vblank_work*workvblank work to flush
Description
Wait untilwork has finished executing once.
Parameters
structdrm_crtc*crtccrtc for which vblank work to flush
Description
Wait until all currently queued vblank work oncrtchas finished executing once.
- voiddrm_vblank_work_init(structdrm_vblank_work*work,structdrm_crtc*crtc,void(*func)(structkthread_work*work))¶
initialize a vblank work item
Parameters
structdrm_vblank_work*workvblank work item
structdrm_crtc*crtcCRTC whose vblank will trigger the work execution
void(*func)(structkthread_work*work)work function to be executed
Description
Initialize a vblank work item for a specific crtc.