Mode Setting Helper Functions

The DRM subsystem aims for a strong separation between core code and helperlibraries. Core code takes care of general setup and teardown and decodinguserspace requests to kernel internal objects. Everything else is handled by alarge set of helper libraries, which can be combined freely to pick and choosefor each driver what fits, and avoid shared code where special behaviour isneeded.

This distinction between core code and helpers is especially strong in themodesetting code, where there’s a shared userspace ABI for all drivers. This isin contrast to the render side, where pretty much everything (with very fewexceptions) can be considered optional helper code.

There are a few areas these helpers can grouped into:

  • Helpers to implement modesetting. The important ones here are the atomichelpers. Old drivers still often use the legacy CRTC helpers. They both sharethe same set of common helper vtables. For really simple drivers (anythingthat would have been a great fit in the deprecated fbdev subsystem) there’salso the simple display pipe helpers.

  • There’s a big pile of helpers for handling outputs. First the generic bridgehelpers for handling encoder and transcoder IP blocks. Second the panel helpersfor handling panel-related information and logic. Plus then a big set ofhelpers for the various sink standards (DisplayPort, HDMI, MIPI DSI). Finallythere’s also generic helpers for handling output probing, and for dealing withEDIDs.

  • The last group of helpers concerns itself with the frontend side of a displaypipeline: Planes, handling rectangles for visibility checking and scissoring,flip queues and assorted bits.

Modeset Helper Reference for Common Vtables

The DRM mode setting helper functions are common code for drivers to use ifthey wish. Drivers are not forced to use this code in theirimplementations but it would be useful if the code they do use at leastprovides a consistent interface and operation to userspace. Therefore it ishighly recommended to use the provided helpers as much as possible.

Because there is only one pointer per modeset object to hold a vfunc tablefor helper libraries they are by necessity shared among the differenthelpers.

To make this clear all the helper vtables are pulled together in this location here.

structdrm_crtc_helper_funcs

helper operations for CRTCs

Definition:

struct drm_crtc_helper_funcs {    void (*dpms)(struct drm_crtc *crtc, int mode);    void (*prepare)(struct drm_crtc *crtc);    void (*commit)(struct drm_crtc *crtc);    enum drm_mode_status (*mode_valid)(struct drm_crtc *crtc, const struct drm_display_mode *mode);    bool (*mode_fixup)(struct drm_crtc *crtc, const struct drm_display_mode *mode, struct drm_display_mode *adjusted_mode);    int (*mode_set)(struct drm_crtc *crtc, struct drm_display_mode *mode, struct drm_display_mode *adjusted_mode, int x, int y, struct drm_framebuffer *old_fb);    void (*mode_set_nofb)(struct drm_crtc *crtc);    int (*mode_set_base)(struct drm_crtc *crtc, int x, int y, struct drm_framebuffer *old_fb);    void (*disable)(struct drm_crtc *crtc);    int (*atomic_check)(struct drm_crtc *crtc, struct drm_atomic_state *state);    void (*atomic_begin)(struct drm_crtc *crtc, struct drm_atomic_state *state);    void (*atomic_flush)(struct drm_crtc *crtc, struct drm_atomic_state *state);    void (*atomic_enable)(struct drm_crtc *crtc, struct drm_atomic_state *state);    void (*atomic_disable)(struct drm_crtc *crtc, struct drm_atomic_state *state);    bool (*get_scanout_position)(struct drm_crtc *crtc, bool in_vblank_irq, int *vpos, int *hpos, ktime_t *stime, ktime_t *etime, const struct drm_display_mode *mode);    bool (*handle_vblank_timeout)(struct drm_crtc *crtc);};

Members

dpms

Callback to control power levels on the CRTC. If the mode passed inis unsupported, the provider must use the next lowest power level.This is used by the legacy CRTC helpers to implement DPMSfunctionality indrm_helper_connector_dpms().

This callback is also used to disable a CRTC by calling it withDRM_MODE_DPMS_OFF if thedisable hook isn’t used.

This callback is used by the legacy CRTC helpers. Atomic helpersalso support using this hook for enabling and disabling a CRTC tofacilitate transitions to atomic, but it is deprecated. Insteadatomic_enable andatomic_disable should be used.

prepare

This callback should prepare the CRTC for a subsequent modeset, whichin practice means the driver should disable the CRTC if it isrunning. Most drivers ended up implementing this by calling theirdpms hook with DRM_MODE_DPMS_OFF.

This callback is used by the legacy CRTC helpers. Atomic helpersalso support using this hook for disabling a CRTC to facilitatetransitions to atomic, but it is deprecated. Insteadatomic_disableshould be used.

commit

This callback should commit the new mode on the CRTC after a modeset,which in practice means the driver should enable the CRTC. Mostdrivers ended up implementing this by calling theirdpms hook withDRM_MODE_DPMS_ON.

This callback is used by the legacy CRTC helpers. Atomic helpersalso support using this hook for enabling a CRTC to facilitatetransitions to atomic, but it is deprecated. Insteadatomic_enableshould be used.

mode_valid

This callback is used to check if a specific mode is valid in thiscrtc. This should be implemented if the crtc has some sort ofrestriction in the modes it can display. For example, a given crtcmay be responsible to set a clock value. If the clock can notproduce all the values for the available modes then this callbackcan be used to restrict the number of modes to only the ones thatcan be displayed.

This hook is used by the probe helpers to filter the mode list indrm_helper_probe_single_connector_modes(), and it is used by theatomic helpers to validate modes supplied by userspace indrm_atomic_helper_check_modeset().

This function is optional.

NOTE:

Since this function is both called from the check phase of an atomiccommit, and the mode validation in the probe paths it is not allowedto look at anything else but the passed-in mode, and validate itagainst configuration-invariant hardware constraints. Any furtherlimits which depend upon the configuration can only be checked inmode_fixup oratomic_check.

RETURNS:

drm_mode_status Enum

mode_fixup

This callback is used to validate a mode. The parameter mode is thedisplay mode that userspace requested, adjusted_mode is the mode theencoders need to be fed with. Note that this is the inverse semanticsof the meaning for thedrm_encoder anddrm_bridge_funcs.mode_fixupvfunc. If the CRTC cannot support the requested conversion from modeto adjusted_mode it should reject the modeset. See alsodrm_crtc_state.adjusted_mode for more details.

This function is used by both legacy CRTC helpers and atomic helpers.With atomic helpers it is optional.

NOTE:

This function is called in the check phase of atomic modesets, whichcan be aborted for any reason (including on userspace’s request tojust check whether a configuration would be possible). Atomic driversMUST NOT touch any persistent state (hardware or software) or datastructures except the passed in adjusted_mode parameter.

This is in contrast to the legacy CRTC helpers where this wasallowed.

Atomic drivers which need to inspect and adjust more state shouldinstead use theatomic_check callback, but note that they’re notperfectly equivalent:mode_valid is called fromdrm_atomic_helper_check_modeset(), butatomic_check is called fromdrm_atomic_helper_check_planes(), because originally it was meant forplane update checks only.

Also beware that userspace can request its own custom modes, neithercore nor helpers filter modes to the list of probe modes reported bythe GETCONNECTOR IOCTL and stored indrm_connector.modes. To ensurethat modes are filtered consistently put any CRTC constraints andlimits checks intomode_valid.

RETURNS:

True if an acceptable configuration is possible, false if the modesetoperation should be rejected.

mode_set

This callback is used by the legacy CRTC helpers to set a new mode,position and framebuffer. Since it ties the primary plane to everymode change it is incompatible with universal plane support. Andsince it can’t update other planes it’s incompatible with atomicmodeset support.

This callback is only used by CRTC helpers and deprecated.

RETURNS:

0 on success or a negative error code on failure.

mode_set_nofb

This callback is used to update the display mode of a CRTC withoutchanging anything of the primary plane configuration. This fits therequirement of atomic and hence is used by the atomic helpers.

Note that the display pipe is completely off when this function iscalled. Atomic drivers which need hardware to be running before theyprogram the new display mode (e.g. because they implement runtime PM)should not use this hook. This is because the helper library callsthis hook only once per mode change and not every time the displaypipeline is suspended using either DPMS or the new “ACTIVE” property.Which means register values set in this callback might get reset whenthe CRTC is suspended, but not restored. Such drivers should insteadmove all their CRTC setup into theatomic_enable callback.

This callback is optional.

mode_set_base

This callback is used by the legacy CRTC helpers to set a newframebuffer and scanout position. It is optional and used as anoptimized fast-path instead of a full mode set operation with all theresulting flickering. If it is not presentdrm_crtc_helper_set_config() will fall back to a full modeset, usingthemode_set callback. Since it can’t update other planes it’sincompatible with atomic modeset support.

This callback is only used by the CRTC helpers and deprecated.

RETURNS:

0 on success or a negative error code on failure.

disable

This callback should be used to disable the CRTC. With the atomicdrivers it is called after all encoders connected to this CRTC havebeen shut off already using their owndrm_encoder_helper_funcs.disable hook. If that sequence is toosimple drivers can just add their own hooks and call it from thisCRTC callback here by looping over all encoders connected to it usingfor_each_encoder_on_crtc().

This hook is used both by legacy CRTC helpers and atomic helpers.Atomic drivers don’t need to implement it if there’s no need todisable anything at the CRTC level. To ensure that runtime PMhandling (using either DPMS or the new “ACTIVE” property) worksdisable must be the inverse ofatomic_enable for atomic drivers.Atomic drivers should consider to useatomic_disable instead ofthis one.

NOTE:

With legacy CRTC helpers there’s a big semantic difference betweendisable and other hooks (likeprepare ordpms) used to shut down aCRTC:disable is only called when also logically disabling thedisplay pipeline and needs to release any resources acquired inmode_set (like shared PLLs, or again release pinned framebuffers).

Thereforedisable must be the inverse ofmode_set pluscommit fordrivers still using legacy CRTC helpers, which is different from therules under atomic.

atomic_check

Drivers should check plane-update related CRTC constraints in thishook. They can also check mode related limitations but need to beaware of the calling order, since this hook is used bydrm_atomic_helper_check_planes() whereas the preparations needed tocheck output routing and the display mode is done indrm_atomic_helper_check_modeset(). Therefore drivers that want tocheck output routing and display mode constraints in this callbackmust ensure thatdrm_atomic_helper_check_modeset() has been calledbeforehand. This is calling order used by the default helperimplementation indrm_atomic_helper_check().

When usingdrm_atomic_helper_check_planes() this hook is calledafter thedrm_plane_helper_funcs.atomic_check hook for planes, whichallows drivers to assign shared resources requested by planes in thiscallback here. For more complicated dependencies the driver can callthe provided check helpers multiple times until the computed statehas a final configuration and everything has been checked.

This function is also allowed to inspect any other object’s state andcan add more state objects to the atomic commit if needed. Care mustbe taken though to ensure that state check and compute functions forthese added states are all called, and derived state in other objectsall updated. Again the recommendation is to just call check helpersuntil a maximal configuration is reached.

This callback is used by the atomic modeset helpers, but it isoptional.

NOTE:

This function is called in the check phase of an atomic update. Thedriver is not allowed to change anything outside of the free-standingstate object passed-in.

Also beware that userspace can request its own custom modes, neithercore nor helpers filter modes to the list of probe modes reported bythe GETCONNECTOR IOCTL and stored indrm_connector.modes. To ensurethat modes are filtered consistently put any CRTC constraints andlimits checks intomode_valid.

RETURNS:

0 on success, -EINVAL if the state or the transition can’t besupported, -ENOMEM on memory allocation failure and -EDEADLK if anattempt to obtain another state object ran into adrm_modeset_lockdeadlock.

atomic_begin

Drivers should prepare for an atomic update of multiple planes ona CRTC in this hook. Depending upon hardware this might be vblankevasion, blocking updates by setting bits or doing preparatory workfor e.g. manual update display.

This hook is called before any plane commit functions are called.

Note that the power state of the display pipe when this function iscalled depends upon the exact helpers and calling sequence the driverhas picked. Seedrm_atomic_helper_commit_planes() for a discussion ofthe tradeoffs and variants of plane commit helpers.

This callback is used by the atomic modeset helpers, but it isoptional.

atomic_flush

Drivers should finalize an atomic update of multiple planes ona CRTC in this hook. Depending upon hardware this might includechecking that vblank evasion was successful, unblocking updates bysetting bits or setting the GO bit to flush out all updates.

Simple hardware or hardware with special requirements can commit andflush out all updates for all planes from this hook and forgo all theother commit hooks for plane updates.

This hook is called after any plane commit functions are called.

Note that the power state of the display pipe when this function iscalled depends upon the exact helpers and calling sequence the driverhas picked. Seedrm_atomic_helper_commit_planes() for a discussion ofthe tradeoffs and variants of plane commit helpers.

This callback is used by the atomic modeset helpers, but it isoptional.

atomic_enable

This callback should be used to enable the CRTC. With the atomicdrivers it is called before all encoders connected to this CRTC areenabled through the encoder’s owndrm_encoder_helper_funcs.enablehook. If that sequence is too simple drivers can just add their ownhooks and call it from this CRTC callback here by looping over allencoders connected to it usingfor_each_encoder_on_crtc().

This hook is used only by atomic helpers, for symmetry withatomic_disable. Atomic drivers don’t need to implement it if there’sno need to enable anything at the CRTC level. To ensure that runtimePM handling (using either DPMS or the new “ACTIVE” property) worksatomic_enable must be the inverse ofatomic_disable for atomicdrivers.

This function is optional.

atomic_disable

This callback should be used to disable the CRTC. With the atomicdrivers it is called after all encoders connected to this CRTC havebeen shut off already using their owndrm_encoder_helper_funcs.disable hook. If that sequence is toosimple drivers can just add their own hooks and call it from thisCRTC callback here by looping over all encoders connected to it usingfor_each_encoder_on_crtc().

This hook is used only by atomic helpers. Atomic drivers don’tneed to implement it if there’s no need to disable anything at theCRTC level.

This function is optional.

get_scanout_position

Called by vblank timestamping code.

Returns the current display scanout position from a CRTC and anoptional accuratektime_get() timestamp of when the position wasmeasured. Note that this is a helper callback which is only usedif a driver usesdrm_crtc_vblank_helper_get_vblank_timestamp()for thedrm_crtc_funcs.get_vblank_timestamp callback.

Parameters:

crtc:

The CRTC.

in_vblank_irq:

True when called fromdrm_crtc_handle_vblank(). Some driversneed to apply some workarounds for gpu-specific vblank irqquirks if the flag is set.

vpos:

Target location for current vertical scanout position.

hpos:

Target location for current horizontal scanout position.

stime:

Target location for timestamp taken immediately beforescanout position query. Can be NULL to skip timestamp.

etime:

Target location for timestamp taken immediately afterscanout position query. Can be NULL to skip timestamp.

mode:

Current display timings.

Returns vpos as a positive number while in active scanout area.Returns vpos as a negative number inside vblank, counting the numberof scanlines to go until end of vblank, e.g., -1 means “one scanlineuntil start of active scanout / end of vblank.”

Returns:

True on success, false if a reliable scanout position counter couldnot be read out.

handle_vblank_timeout

Handles timeouts of the vblank timer.

Called by CRTC’s the vblank timer on each timeout. Semantics isequivalient todrm_crtc_handle_vblank(). Implementations shouldinvokedrm_crtc_handle_vblank() as part of processing the timeout.

This callback is optional. If unset, the vblank timer invokesdrm_crtc_handle_vblank() directly.

Description

These hooks are used by the legacy CRTC helpers and the new atomicmodesetting helpers.

voiddrm_crtc_helper_add(structdrm_crtc*crtc,conststructdrm_crtc_helper_funcs*funcs)

sets the helper vtable for a crtc

Parameters

structdrm_crtc*crtc

DRM CRTC

conststructdrm_crtc_helper_funcs*funcs

helper vtable to set forcrtc

structdrm_encoder_helper_funcs

helper operations for encoders

Definition:

struct drm_encoder_helper_funcs {    void (*dpms)(struct drm_encoder *encoder, int mode);    enum drm_mode_status (*mode_valid)(struct drm_encoder *crtc, const struct drm_display_mode *mode);    bool (*mode_fixup)(struct drm_encoder *encoder, const struct drm_display_mode *mode, struct drm_display_mode *adjusted_mode);    void (*prepare)(struct drm_encoder *encoder);    void (*commit)(struct drm_encoder *encoder);    void (*mode_set)(struct drm_encoder *encoder, struct drm_display_mode *mode, struct drm_display_mode *adjusted_mode);    void (*atomic_mode_set)(struct drm_encoder *encoder, struct drm_crtc_state *crtc_state, struct drm_connector_state *conn_state);    enum drm_connector_status (*detect)(struct drm_encoder *encoder, struct drm_connector *connector);    void (*atomic_disable)(struct drm_encoder *encoder, struct drm_atomic_state *state);    void (*atomic_enable)(struct drm_encoder *encoder, struct drm_atomic_state *state);    void (*disable)(struct drm_encoder *encoder);    void (*enable)(struct drm_encoder *encoder);    int (*atomic_check)(struct drm_encoder *encoder, struct drm_crtc_state *crtc_state, struct drm_connector_state *conn_state);};

Members

dpms

Callback to control power levels on the encoder. If the mode passed inis unsupported, the provider must use the next lowest power level.This is used by the legacy encoder helpers to implement DPMSfunctionality indrm_helper_connector_dpms().

This callback is also used to disable an encoder by calling it withDRM_MODE_DPMS_OFF if thedisable hook isn’t used.

This callback is used by the legacy CRTC helpers. Atomic helpersalso support using this hook for enabling and disabling an encoder tofacilitate transitions to atomic, but it is deprecated. Insteadenable anddisable should be used.

mode_valid

This callback is used to check if a specific mode is valid in thisencoder. This should be implemented if the encoder has some sortof restriction in the modes it can display. For example, a givenencoder may be responsible to set a clock value. If the clock cannot produce all the values for the available modes then this callbackcan be used to restrict the number of modes to only the ones thatcan be displayed.

This hook is used by the probe helpers to filter the mode list indrm_helper_probe_single_connector_modes(), and it is used by theatomic helpers to validate modes supplied by userspace indrm_atomic_helper_check_modeset().

This function is optional.

NOTE:

Since this function is both called from the check phase of an atomiccommit, and the mode validation in the probe paths it is not allowedto look at anything else but the passed-in mode, and validate itagainst configuration-invariant hardware constraints. Any furtherlimits which depend upon the configuration can only be checked inmode_fixup oratomic_check.

RETURNS:

drm_mode_status Enum

mode_fixup

This callback is used to validate and adjust a mode. The parametermode is the display mode that should be fed to the next element inthe display chain, either the finaldrm_connector or adrm_bridge.The parameter adjusted_mode is the input mode the encoder requires. Itcan be modified by this callback and does not need to match mode. Seealsodrm_crtc_state.adjusted_mode for more details.

This function is used by both legacy CRTC helpers and atomic helpers.This hook is optional.

NOTE:

This function is called in the check phase of atomic modesets, whichcan be aborted for any reason (including on userspace’s request tojust check whether a configuration would be possible). Atomic driversMUST NOT touch any persistent state (hardware or software) or datastructures except the passed in adjusted_mode parameter.

This is in contrast to the legacy CRTC helpers where this wasallowed.

Atomic drivers which need to inspect and adjust more state shouldinstead use theatomic_check callback. Ifatomic_check is used,this hook isn’t called sinceatomic_check allows a strict supersetof the functionality ofmode_fixup.

Also beware that userspace can request its own custom modes, neithercore nor helpers filter modes to the list of probe modes reported bythe GETCONNECTOR IOCTL and stored indrm_connector.modes. To ensurethat modes are filtered consistently put any encoder constraints andlimits checks intomode_valid.

RETURNS:

True if an acceptable configuration is possible, false if the modesetoperation should be rejected.

prepare

This callback should prepare the encoder for a subsequent modeset,which in practice means the driver should disable the encoder if itis running. Most drivers ended up implementing this by calling theirdpms hook with DRM_MODE_DPMS_OFF.

This callback is used by the legacy CRTC helpers. Atomic helpersalso support using this hook for disabling an encoder to facilitatetransitions to atomic, but it is deprecated. Insteaddisable shouldbe used.

commit

This callback should commit the new mode on the encoder after a modeset,which in practice means the driver should enable the encoder. Mostdrivers ended up implementing this by calling theirdpms hook withDRM_MODE_DPMS_ON.

This callback is used by the legacy CRTC helpers. Atomic helpersalso support using this hook for enabling an encoder to facilitatetransitions to atomic, but it is deprecated. Insteadenable shouldbe used.

mode_set

This callback is used to update the display mode of an encoder.

Note that the display pipe is completely off when this function iscalled. Drivers which need hardware to be running before they programthe new display mode (because they implement runtime PM) should notuse this hook, because the helper library calls it only once and notevery time the display pipeline is suspend using either DPMS or thenew “ACTIVE” property. Such drivers should instead move all theirencoder setup into theenable callback.

This callback is used both by the legacy CRTC helpers and the atomicmodeset helpers. It is optional in the atomic helpers.

NOTE:

If the driver uses the atomic modeset helpers and needs to inspectthe connector state or connector display info during mode setting,atomic_mode_set can be used instead.

atomic_mode_set

This callback is used to update the display mode of an encoder.

Note that the display pipe is completely off when this function iscalled. Drivers which need hardware to be running before they programthe new display mode (because they implement runtime PM) should notuse this hook, because the helper library calls it only once and notevery time the display pipeline is suspended using either DPMS or thenew “ACTIVE” property. Such drivers should instead move all theirencoder setup into theenable callback.

This callback is used by the atomic modeset helpers in place of themode_set callback, if set by the driver. It is optional and shouldbe used instead ofmode_set if the driver needs to inspect theconnector state or display info, since there is no direct way togo from the encoder to the current connector.

detect

This callback can be used by drivers who want to do detection on theencoder object instead of in connector functions.

It is not used by any helper and therefore has purely driver-specificsemantics. New drivers shouldn’t use this and instead just implementtheir own private callbacks.

FIXME:

This should just be converted into a pile of driver vfuncs.Currently radeon, amdgpu and nouveau are using it.

atomic_disable

This callback should be used to disable the encoder. With the atomicdrivers it is called before this encoder’s CRTC has been shut offusing their owndrm_crtc_helper_funcs.atomic_disable hook. If thatsequence is too simple drivers can just add their own driver privateencoder hooks and call them from CRTC’s callback by looping over allencoders connected to it usingfor_each_encoder_on_crtc().

This callback is a variant ofdisable that provides the atomic stateto the driver. Ifatomic_disable is implemented,disable is notcalled by the helpers.

This hook is only used by atomic helpers. Atomic drivers don’t needto implement it if there’s no need to disable anything at the encoderlevel. To ensure that runtime PM handling (using either DPMS or thenew “ACTIVE” property) worksatomic_disable must be the inverse ofatomic_enable.

atomic_enable

This callback should be used to enable the encoder. It is calledafter this encoder’s CRTC has been enabled using their owndrm_crtc_helper_funcs.atomic_enable hook. If that sequence istoo simple drivers can just add their own driver private encoderhooks and call them from CRTC’s callback by looping over all encodersconnected to it usingfor_each_encoder_on_crtc().

This callback is a variant ofenable that provides the atomic stateto the driver. Ifatomic_enable is implemented,enable is notcalled by the helpers.

This hook is only used by atomic helpers, it is the opposite ofatomic_disable. Atomic drivers don’t need to implement it if there’sno need to enable anything at the encoder level. To ensure thatruntime PM handling worksatomic_enable must be the inverse ofatomic_disable.

disable

This callback should be used to disable the encoder. With the atomicdrivers it is called before this encoder’s CRTC has been shut offusing their owndrm_crtc_helper_funcs.disable hook. If thatsequence is too simple drivers can just add their own driver privateencoder hooks and call them from CRTC’s callback by looping over allencoders connected to it usingfor_each_encoder_on_crtc().

This hook is used both by legacy CRTC helpers and atomic helpers.Atomic drivers don’t need to implement it if there’s no need todisable anything at the encoder level. To ensure that runtime PMhandling (using either DPMS or the new “ACTIVE” property) worksdisable must be the inverse ofenable for atomic drivers.

For atomic drivers also consideratomic_disable and save yourselffrom having to read the NOTE below!

NOTE:

With legacy CRTC helpers there’s a big semantic difference betweendisable and other hooks (likeprepare ordpms) used to shut down aencoder:disable is only called when also logically disabling thedisplay pipeline and needs to release any resources acquired inmode_set (like shared PLLs, or again release pinned framebuffers).

Thereforedisable must be the inverse ofmode_set pluscommit fordrivers still using legacy CRTC helpers, which is different from therules under atomic.

enable

This callback should be used to enable the encoder. With the atomicdrivers it is called after this encoder’s CRTC has been enabled usingtheir owndrm_crtc_helper_funcs.enable hook. If that sequence istoo simple drivers can just add their own driver private encoderhooks and call them from CRTC’s callback by looping over all encodersconnected to it usingfor_each_encoder_on_crtc().

This hook is only used by atomic helpers, it is the opposite ofdisable. Atomic drivers don’t need to implement it if there’s noneed to enable anything at the encoder level. To ensure thatruntime PM handling (using either DPMS or the new “ACTIVE” property)worksenable must be the inverse ofdisable for atomic drivers.

atomic_check

This callback is used to validate encoder state for atomic drivers.Since the encoder is the object connecting the CRTC and connector itgets passed both states, to be able to validate interactions andupdate the CRTC to match what the encoder needs for the requestedconnector.

Since this provides a strict superset of the functionality ofmode_fixup (the requested and adjusted modes are both availablethrough the passed instructdrm_crtc_state)mode_fixup is notcalled whenatomic_check is implemented.

This function is used by the atomic helpers, but it is optional.

NOTE:

This function is called in the check phase of an atomic update. Thedriver is not allowed to change anything outside of the free-standingstate objects passed-in or assembled in the overalldrm_atomic_stateupdate tracking structure.

Also beware that userspace can request its own custom modes, neithercore nor helpers filter modes to the list of probe modes reported bythe GETCONNECTOR IOCTL and stored indrm_connector.modes. To ensurethat modes are filtered consistently put any encoder constraints andlimits checks intomode_valid.

RETURNS:

0 on success, -EINVAL if the state or the transition can’t besupported, -ENOMEM on memory allocation failure and -EDEADLK if anattempt to obtain another state object ran into adrm_modeset_lockdeadlock.

Description

These hooks are used by the legacy CRTC helpers and the new atomicmodesetting helpers.

voiddrm_encoder_helper_add(structdrm_encoder*encoder,conststructdrm_encoder_helper_funcs*funcs)

sets the helper vtable for an encoder

Parameters

structdrm_encoder*encoder

DRM encoder

conststructdrm_encoder_helper_funcs*funcs

helper vtable to set forencoder

structdrm_connector_helper_funcs

helper operations for connectors

Definition:

struct drm_connector_helper_funcs {    int (*get_modes)(struct drm_connector *connector);    int (*detect_ctx)(struct drm_connector *connector, struct drm_modeset_acquire_ctx *ctx, bool force);    enum drm_mode_status (*mode_valid)(struct drm_connector *connector, const struct drm_display_mode *mode);    int (*mode_valid_ctx)(struct drm_connector *connector, const struct drm_display_mode *mode, struct drm_modeset_acquire_ctx *ctx, enum drm_mode_status *status);    struct drm_encoder *(*best_encoder)(struct drm_connector *connector);    struct drm_encoder *(*atomic_best_encoder)(struct drm_connector *connector, struct drm_atomic_state *state);    int (*atomic_check)(struct drm_connector *connector, struct drm_atomic_state *state);    void (*atomic_commit)(struct drm_connector *connector, struct drm_atomic_state *state);    int (*prepare_writeback_job)(struct drm_writeback_connector *connector, struct drm_writeback_job *job);    void (*cleanup_writeback_job)(struct drm_writeback_connector *connector, struct drm_writeback_job *job);    void (*enable_hpd)(struct drm_connector *connector);    void (*disable_hpd)(struct drm_connector *connector);};

Members

get_modes

This function should fill in all modes currently valid for the sinkinto thedrm_connector.probed_modes list. It should also update theEDID property by callingdrm_connector_update_edid_property().

The usual way to implement this is to cache the EDID retrieved in theprobe callback somewhere in the driver-private connector structure.In this function drivers then parse the modes in the EDID and addthem by callingdrm_add_edid_modes(). But connectors that drive afixed panel can also manually add specific modes usingdrm_mode_probed_add(). Drivers which manually add modes should alsomake sure that thedrm_connector.display_info,drm_connector.width_mm anddrm_connector.height_mm fields arefilled in.

Note that the caller function will automatically add standard VESADMT modes up to 1024x768 if the .get_modes() helper operation returnsno mode and if the connector status is connector_status_connected orconnector_status_unknown. There is no need to calldrm_add_modes_noedid() manually in that case.

Virtual drivers that just want some standard VESA mode with a givenresolution can calldrm_add_modes_noedid(), and mark the preferredone usingdrm_set_preferred_mode().

This function is only called after thedetect hook has indicatedthat a sink is connected and when the EDID isn’t overridden throughsysfs or the kernel commandline.

This callback is used by the probe helpers in e.g.drm_helper_probe_single_connector_modes().

To avoid races with concurrent connector state updates, the helperlibraries always call this with thedrm_mode_config.connection_mutexheld. Because of this it’s safe to inspectdrm_connector->state.

RETURNS:

The number of modes added by callingdrm_mode_probed_add(). Return 0on failures (no modes) instead of negative error codes.

detect_ctx

Check 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.

This is the atomic version ofdrm_connector_funcs.detect.

To avoid races against concurrent connector state updates, thehelper libraries always call this with ctx set to a valid context,anddrm_mode_config.connection_mutex will always be locked withthe ctx parameter set to this ctx. This allows taking additionallocks as required.

RETURNS:

drm_connector_status indicating the connector’s status,or the error code returned bydrm_modeset_lock(), -EDEADLK.

mode_valid

Callback to validate a mode for a connector, irrespective of thespecific display configuration.

This callback is used by the probe helpers to filter the mode list(which is usually derived from the EDID data block from the sink).See e.g.drm_helper_probe_single_connector_modes().

This function is optional.

NOTE:

This only filters the mode list supplied to userspace in theGETCONNECTOR IOCTL. Compared todrm_encoder_helper_funcs.mode_valid,drm_crtc_helper_funcs.mode_valid anddrm_bridge_funcs.mode_valid,which are also called by the atomic helpers fromdrm_atomic_helper_check_modeset(). This allows userspace to force andignore sink constraint (like the pixel clock limits in the screen’sEDID), which is useful for e.g. testing, or working around a brokenEDID. Any source hardware constraint (which always need to beenforced) therefore should be checked in one of the above callbacks,and not this one here.

To avoid races with concurrent connector state updates, the helperlibraries always call this with thedrm_mode_config.connection_mutexheld. Because of this it’s safe to inspectdrm_connector->state.

RETURNS:

Eitherdrm_mode_status.MODE_OK or one of the failure reasons inenumdrm_mode_status.

mode_valid_ctx

Callback to validate a mode for a connector, irrespective of thespecific display configuration.

This callback is used by the probe helpers to filter the mode list(which is usually derived from the EDID data block from the sink).See e.g.drm_helper_probe_single_connector_modes().

This function is optional, and is the atomic version ofdrm_connector_helper_funcs.mode_valid.

To allow for accessing the atomic state of modesetting objects, thehelper libraries always call this with ctx set to a valid context,anddrm_mode_config.connection_mutex will always be locked withthe ctx parameter set toctx. This allows for taking additionallocks as required.

Even though additional locks may be acquired, this callback isstill expected not to take any constraints into account which wouldbe influenced by the currently set display state - such constraintsshould be handled in the driver’s atomic check. For example, if aconnector shares display bandwidth with other connectors then itwould be ok to validate the minimum bandwidth requirement of a modeagainst the maximum possible bandwidth of the connector. But itwouldn’t be ok to take the current bandwidth usage of otherconnectors into account, as this would change depending on thedisplay state.

Returns:0 ifdrm_connector_helper_funcs.mode_valid_ctx succeeded and wrotetheenumdrm_mode_status value tostatus, or a negative errorcode otherwise.

best_encoder

This function should select the best encoder for the given connector.

This function is used by both the atomic helpers (in thedrm_atomic_helper_check_modeset() function) and in the legacy CRTChelpers.

NOTE:

In atomic drivers this function is called in the check phase of anatomic update. The driver is not allowed to change or inspectanything outside of arguments passed-in. Atomic drivers which need toinspect dynamic configuration state should instead useatomic_best_encoder.

You can leave this function to NULL if the connector is onlyattached to a single encoder. In this case, the core will calldrm_connector_get_single_encoder() for you.

RETURNS:

Encoder that should be used for the given connector and connectorstate, or NULL if no suitable encoder exists. Note that the helperswill ensure that encoders aren’t used twice, drivers should not checkfor this.

atomic_best_encoder

This is the atomic version ofbest_encoder for atomic drivers whichneed to select the best encoder depending upon the desiredconfiguration and can’t select it statically.

This function is used bydrm_atomic_helper_check_modeset().If it is not implemented, the core will fallback tobest_encoder(ordrm_connector_get_single_encoder() ifbest_encoder is NULL).

NOTE:

This function is called in the check phase of an atomic update. Thedriver is not allowed to change anything outside of thedrm_atomic_state update tracking structure passed in.

RETURNS:

Encoder that should be used for the given connector and connectorstate, or NULL if no suitable encoder exists. Note that the helperswill ensure that encoders aren’t used twice, drivers should not checkfor this.

atomic_check

This hook is used to validate connector state. This function iscalled fromdrm_atomic_helper_check_modeset, and is called whena connector property is set, or a modeset on the crtc is forced.

Becausedrm_atomic_helper_check_modeset may be called multiple times,this function should handle being called multiple times as well.

This function is also allowed to inspect any other object’s state andcan add more state objects to the atomic commit if needed. Care mustbe taken though to ensure that state check and compute functions forthese added states are all called, and derived state in other objectsall updated. Again the recommendation is to just call check helpersuntil a maximal configuration is reached.

NOTE:

This function is called in the check phase of an atomic update. Thedriver is not allowed to change anything outside of the free-standingstate objects passed-in or assembled in the overalldrm_atomic_stateupdate tracking structure.

RETURNS:

0 on success, -EINVAL if the state or the transition can’t besupported, -ENOMEM on memory allocation failure and -EDEADLK if anattempt to obtain another state object ran into adrm_modeset_lockdeadlock.

atomic_commit

This hook is to be used by drivers implementing writeback connectorsthat need a point when to commit the writeback job to the hardware.The writeback_job to commit is available in the new connector state,indrm_connector_state.writeback_job.

This hook is optional.

This callback is used by the atomic modeset helpers.

prepare_writeback_job

As writeback jobs contain a framebuffer, drivers may need toprepare and clean them up the same way they can prepare andclean up framebuffers for planes. This optional connector operationis used to support the preparation of writeback jobs. The jobprepare operation is called fromdrm_atomic_helper_prepare_planes()for structdrm_writeback_connector connectors only.

This operation is optional.

This callback is used by the atomic modeset helpers.

cleanup_writeback_job

This optional connector operation is used to support thecleanup of writeback jobs. The job cleanup operation is calledfrom the existingdrm_writeback_cleanup_job() function, invokedboth when destroying the job as part of an aborted commit, or whenthe job completes.

This operation is optional.

This callback is used by the atomic modeset helpers.

enable_hpd

Enable hot-plug detection for the connector.

This operation is optional.

This callback is used by thedrm_kms_helper_poll_enable() helpers.

This operation does not need to perform any hpd state tracking asthe DRM core handles that maintenance and ensures the calls to enableand disable hpd are balanced.

disable_hpd

Disable hot-plug detection for the connector.

This operation is optional.

This callback is used by thedrm_kms_helper_poll_disable() helpers.

This operation does not need to perform any hpd state tracking asthe DRM core handles that maintenance and ensures the calls to enableand disable hpd are balanced.

Description

These functions are used by the atomic and legacy modeset helpers and by theprobe helpers.

voiddrm_connector_helper_add(structdrm_connector*connector,conststructdrm_connector_helper_funcs*funcs)

sets the helper vtable for a connector

Parameters

structdrm_connector*connector

DRM connector

conststructdrm_connector_helper_funcs*funcs

helper vtable to set forconnector

structdrm_plane_helper_funcs

helper operations for planes

Definition:

struct drm_plane_helper_funcs {    int (*prepare_fb)(struct drm_plane *plane, struct drm_plane_state *new_state);    void (*cleanup_fb)(struct drm_plane *plane, struct drm_plane_state *old_state);    int (*begin_fb_access)(struct drm_plane *plane, struct drm_plane_state *new_plane_state);    void (*end_fb_access)(struct drm_plane *plane, struct drm_plane_state *new_plane_state);    int (*atomic_check)(struct drm_plane *plane, struct drm_atomic_state *state);    void (*atomic_update)(struct drm_plane *plane, struct drm_atomic_state *state);    void (*atomic_enable)(struct drm_plane *plane, struct drm_atomic_state *state);    void (*atomic_disable)(struct drm_plane *plane, struct drm_atomic_state *state);    int (*atomic_async_check)(struct drm_plane *plane, struct drm_atomic_state *state, bool flip);    void (*atomic_async_update)(struct drm_plane *plane, struct drm_atomic_state *state);    int (*get_scanout_buffer)(struct drm_plane *plane, struct drm_scanout_buffer *sb);    void (*panic_flush)(struct drm_plane *plane);};

Members

prepare_fb

This hook is to prepare a framebuffer for scanout by e.g. pinningits backing storage or relocating it into a contiguous block ofVRAM. Other possible preparatory work includes flushing caches.

This function must not block for outstanding rendering, since it iscalled in the context of the atomic IOCTL even for async commits tobe able to return any errors to userspace. Instead the recommendedway is to fill out thedrm_plane_state.fence of the passed-indrm_plane_state. If the driver doesn’t support native fences thenequivalent functionality should be implemented through privatemembers in the plane structure.

For GEM drivers who neither have aprepare_fb norcleanup_fb hooksetdrm_gem_plane_helper_prepare_fb() is called automatically toimplement this. Other drivers which need additional plane processingcan calldrm_gem_plane_helper_prepare_fb() from theirprepare_fbhook.

The resources acquired inprepare_fb persist after the end ofthe atomic commit. Resources that can be release at the commit’s endshould be acquired inbegin_fb_access and released inend_fb_access.For example, a GEM buffer’s pin operation belongs intoprepare_fb tokeep the buffer pinned after the commit. But a vmap operation forshadow-plane helpers belongs intobegin_fb_access, so that atomichelpers remove the mapping at the end of the commit.

The helpers will callcleanup_fb with matching arguments for everysuccessful call to this hook.

This callback is used by the atomic modeset helpers, but it isoptional. Seebegin_fb_access for preparing per-commit resources.

RETURNS:

0 on success or one of the following negative error codes allowed bythedrm_mode_config_funcs.atomic_commit vfunc. When using helpersthis callback is the only one which can fail an atomic commit,everything else must complete successfully.

cleanup_fb

This hook is called to clean up any resources allocated for the givenframebuffer and plane configuration inprepare_fb.

This callback is used by the atomic modeset helpers, but it isoptional.

begin_fb_access

This hook prepares the plane for access during an atomic commit.In contrast toprepare_fb, resources acquired inbegin_fb_access,are released at the end of the atomic commit inend_fb_access.

For example, with shadow-plane helpers, the GEM buffer’s vmapoperation belongs intobegin_fb_access, so that the buffer’smemory will be unmapped at the end of the commit inend_fb_access.But a GEM buffer’s pin operation belongs intoprepare_fbto keep the buffer pinned after the commit.

The callback is used by the atomic modeset helpers, but it is optional.Seeend_fb_cleanup for undoing the effects ofbegin_fb_access andprepare_fb for acquiring resources until the next pageflip.

Returns:0 on success, or a negative errno code otherwise.

end_fb_access

This hook cleans up resources allocated bybegin_fb_access. It it calledat the end of a commit for the new plane state.

atomic_check

Drivers should check plane specific constraints in this hook.

When usingdrm_atomic_helper_check_planes() plane’satomic_checkhooks are called before the ones for CRTCs, which allows drivers torequest shared resources that the CRTC controls here. For morecomplicated dependencies the driver can call the provided check helpersmultiple times until the computed state has a final configuration andeverything has been checked.

This function is also allowed to inspect any other object’s state andcan add more state objects to the atomic commit if needed. Care mustbe taken though to ensure that state check and compute functions forthese added states are all called, and derived state in other objectsall updated. Again the recommendation is to just call check helpersuntil a maximal configuration is reached.

This callback is used by the atomic modeset helpers, but it isoptional.

NOTE:

This function is called in the check phase of an atomic update. Thedriver is not allowed to change anything outside of thedrm_atomic_state update tracking structure.

RETURNS:

0 on success, -EINVAL if the state or the transition can’t besupported, -ENOMEM on memory allocation failure and -EDEADLK if anattempt to obtain another state object ran into adrm_modeset_lockdeadlock.

atomic_update

Drivers should use this function to update the plane state. Thishook is called in-between thedrm_crtc_helper_funcs.atomic_begin anddrm_crtc_helper_funcs.atomic_flush callbacks.

Note that the power state of the display pipe when this function iscalled depends upon the exact helpers and calling sequence the driverhas picked. Seedrm_atomic_helper_commit_planes() for a discussion ofthe tradeoffs and variants of plane commit helpers.

This callback is used by the atomic modeset helpers, but it is optional.

atomic_enable

Drivers should use this function to unconditionally enable a plane.This hook is called in-between thedrm_crtc_helper_funcs.atomic_beginand drm_crtc_helper_funcs.atomic_flush callbacks. It is called afteratomic_update, which will be called for all enabled planes. Driversthat useatomic_enable should set up a plane inatomic_update andafterwards enable the plane inatomic_enable. If a plane needs to beenabled before installing the scanout buffer, drivers can still doso inatomic_update.

Note that the power state of the display pipe when this function iscalled depends upon the exact helpers and calling sequence the driverhas picked. Seedrm_atomic_helper_commit_planes() for a discussion ofthe tradeoffs and variants of plane commit helpers.

This callback is used by the atomic modeset helpers, but it isoptional. If implemented,atomic_enable should be the inverse ofatomic_disable. Drivers that don’t want to use either can stillimplement the complete plane update inatomic_update.

atomic_disable

Drivers should use this function to unconditionally disable a plane.This hook is called in-between thedrm_crtc_helper_funcs.atomic_begin anddrm_crtc_helper_funcs.atomic_flush callbacks. It is an alternative toatomic_update, which will be called for disabling planes, too, iftheatomic_disable hook isn’t implemented.

This hook is also useful to disable planes in preparation of a modeset,by callingdrm_atomic_helper_disable_planes_on_crtc() from thedrm_crtc_helper_funcs.disable hook.

Note that the power state of the display pipe when this function iscalled depends upon the exact helpers and calling sequence the driverhas picked. Seedrm_atomic_helper_commit_planes() for a discussion ofthe tradeoffs and variants of plane commit helpers.

This callback is used by the atomic modeset helpers, but it isoptional. It’s intended to reverse the effects ofatomic_enable.

atomic_async_check

Drivers should set this function pointer to check if the plane’satomic state can be updated in a async fashion. Here async means“not vblank synchronized”.

This hook is called bydrm_atomic_async_check() to establish if agiven update can be committed asynchronously, that is, if it canjump ahead of the state currently queued for update.

This function is also used bydrm_atomic_set_property() to determineif the plane can be flipped in async. The flip flag is used todistinguish if the function is used for just the plane state or for aflip.

RETURNS:

Return 0 on success and any error returned indicates that the updatecan not be applied in asynchronous manner.

atomic_async_update

Drivers should set this function pointer to perform asynchronousupdates of planes, that is, jump ahead of the currently queuedstate and update the plane. Here async means “not vblanksynchronized”.

This hook is called bydrm_atomic_helper_async_commit().

An async update will happen on legacy cursor updates. An asyncupdate won’t happen if there is an outstanding commit modifyingthe same plane.

When doing async_update drivers shouldn’t replace thedrm_plane_state but update the current one with the new planeconfigurations in the new plane_state.

Drivers should also swap the framebuffers between current planestate (drm_plane.state) and new_state.This is required since cleanup for async commits is performed onthe new state, rather than old state like for traditional commits.Since we want to give up the reference on the current (old) fbinstead of our brand new one, swap them in the driver during theasync commit.

FIXME:
  • It only works for single plane updates

  • Async Pageflips are not supported yet

  • Some hw might still scan out the old buffer until the nextvblank, however we let go of the fb references as soon aswe run this hook. For now drivers must implement their own workersfor deferring if needed, until a common solution is created.

get_scanout_buffer

Get the current scanout buffer, to display a message with drm_panic.The driver should do the minimum changes to provide a buffer,that can be used to display the panic screen. Currently only linearbuffers are supported. Non-linear buffer support is on the TODO list.The devicedev.mode_config.panic_lock is taken before calling thisfunction, so you can safely access theplane.stateIt is called from a panic callback, and must follow its restrictions.Please look the documentation atdrm_panic_trylock() for an in-depthdiscussions of what’s safe and what is not allowed.It’s a best effort mode, so it’s expected that in some complex casesthe panic screen won’t be displayed.The returneddrm_scanout_buffer.map must be valid if no error code isreturned.

Return:0 on success, negative errno on failure.

panic_flush

It is used by drm_panic, and is called after the panic screen isdrawn to the scanout buffer. In this function, the drivercan send additional commands to the hardware, to make the scanoutbuffer visible.It is only called ifget_scanout_buffer() returned successfully, andthedev.mode_config.panic_lock is held during the entire sequence.It is called from a panic callback, and must follow its restrictions.Please look the documentation atdrm_panic_trylock() for an in-depthdiscussions of what’s safe and what is not allowed.

Description

These functions are used by the atomic helpers.

voiddrm_plane_helper_add(structdrm_plane*plane,conststructdrm_plane_helper_funcs*funcs)

sets the helper vtable for a plane

Parameters

structdrm_plane*plane

DRM plane

conststructdrm_plane_helper_funcs*funcs

helper vtable to set forplane

structdrm_mode_config_helper_funcs

global modeset helper operations

Definition:

struct drm_mode_config_helper_funcs {    void (*atomic_commit_tail)(struct drm_atomic_state *state);    int (*atomic_commit_setup)(struct drm_atomic_state *state);};

Members

atomic_commit_tail

This hook is used by the defaultatomic_commit() hook implemented indrm_atomic_helper_commit() together with the nonblocking commithelpers (seedrm_atomic_helper_setup_commit() for a starting point)to implement blocking and nonblocking commits easily. It is not usedby the atomic helpers

This function is called when the new atomic state has already beenswapped into the various state pointers. The passed in statetherefore contains copies of the old/previous state. This hook shouldcommit the new state into hardware. Note that the helpers havealready waited for preceding atomic commits and fences, but driverscan add more waiting calls at the start of their implementation, e.g.to wait for driver-internal request for implicit syncing, beforestarting to commit the update to the hardware.

After the atomic update is committed to the hardware this hook needsto calldrm_atomic_helper_commit_hw_done(). Then wait for the updateto be executed by the hardware, for example usingdrm_atomic_helper_wait_for_vblanks() ordrm_atomic_helper_wait_for_flip_done(), and then clean up the oldframebuffers usingdrm_atomic_helper_cleanup_planes().

When disabling a CRTC this hook _must_ stall for the commit tocomplete. Vblank waits don’t work on disabled CRTC, hence the corecan’t take care of this. And it also can’t rely on the vblank event,since that can be signalled already when the screen shows black,which can happen much earlier than the last hardware access needed toshut off the display pipeline completely.

This hook is optional, the default implementation isdrm_atomic_helper_commit_tail().

atomic_commit_setup

This hook is used by the defaultatomic_commit() hook implemented indrm_atomic_helper_commit() together with the nonblocking helpers (seedrm_atomic_helper_setup_commit()) to extend the DRM commit setup. Itis not used by the atomic helpers.

This function is called at the end ofdrm_atomic_helper_setup_commit(), so once the commit has beenproperly setup across the generic DRM object states. It allowsdrivers to do some additional commit tracking that isn’t related to aCRTC, plane or connector, tracked in adrm_private_obj structure.

Note that the documentation ofdrm_private_obj has more details onhow one should implement this.

This hook is optional.

Description

These helper functions are used by the atomic helpers.

Atomic Modeset Helper Functions Reference

Overview

This helper library provides implementations of check and commit functions ontop of the CRTC modeset helper callbacks and the plane helper callbacks. Italso provides convenience implementations for the atomic state handlingcallbacks for drivers which don’t need to subclass the drm core structures toadd their own additional internal state.

This library also provides default implementations for the check callback indrm_atomic_helper_check() and for the commit callback withdrm_atomic_helper_commit(). But the individual stages and callbacks areexposed to allow drivers to mix and match and e.g. use the plane helpers onlytogether with a driver private modeset implementation.

This library also provides implementations for all the legacy driverinterfaces on top of the atomic interface. Seedrm_atomic_helper_set_config(),drm_atomic_helper_disable_plane(), and the various functions to implementset_property callbacks. New drivers must not implement these functionsthemselves but must use the provided helpers.

The atomic helper uses the same function table structures as all othermodesetting helpers. See the documentation forstructdrm_crtc_helper_funcs,structdrm_encoder_helper_funcs andstructdrm_connector_helper_funcs. Italso shares thestructdrm_plane_helper_funcs function table with the planehelpers.

Implementing Asynchronous Atomic Commit

Nonblocking atomic commits should use structdrm_crtc_commit to sequencedifferent operations against each another. Locks, especially structdrm_modeset_lock, should not be held in worker threads or any otherasynchronous context used to commit the hardware state.

drm_atomic_helper_commit() implements the recommended sequence fornonblocking commits, usingdrm_atomic_helper_setup_commit() internally:

1. Rundrm_atomic_helper_prepare_planes(). Since this can fail and weneed to propagate out of memory/VRAM errors to userspace, it must be calledsynchronously.

2. Synchronize with any outstanding nonblocking commit worker threads whichmight be affected by the new state update. This is handled bydrm_atomic_helper_setup_commit().

Asynchronous workers need to have sufficient parallelism to be able to rundifferent atomic commits on different CRTCs in parallel. The simplest way toachieve this is by running them on thesystem_dfl_wq work queue. Notethat drivers are not required to split up atomic commits and run anindividual commit in parallel - userspace is supposed to do that if it cares.But it might be beneficial to do that for modesets, since those necessarilymust be done as one global operation, and enabling or disabling a CRTC cantake a long time. But even that is not required.

IMPORTANT: Adrm_atomic_state update for multiple CRTCs is sequencedagainst all CRTCs therein. Therefore for atomic state updates which only flipplanes the driver must not get the structdrm_crtc_state of unrelated CRTCsin its atomic check code: This would prevent committing of atomic updates tomultiple CRTCs in parallel. In general, adding additional state structuresshould be avoided as much as possible, because this reduces parallelism in(nonblocking) commits, both due to locking and due to commit sequencingrequirements.

3. The software state is updated synchronously withdrm_atomic_helper_swap_state(). Doing this under the protection of all modesetlocks means concurrent callers never see inconsistent state. Note that commitworkers do not hold any locks; their access is only coordinated throughordering. If workers would access state only through the pointers in thefree-standing state objects (currently not the case for any driver) then evenmultiple pending commits could be in-flight at the same time.

4. Schedule a work item to do all subsequent steps, using the split-outcommit helpers: a) pre-plane commit b) plane commit c) post-plane commit andthen cleaning up the framebuffers after the old framebuffer is no longerbeing displayed. The scheduled work should synchronize against other workersusing thedrm_crtc_commit infrastructure as needed. Seedrm_atomic_helper_setup_commit() for more details.

Helper Functions Reference

drm_atomic_crtc_for_each_plane

drm_atomic_crtc_for_each_plane(plane,crtc)

iterate over planes currently attached to CRTC

Parameters

plane

the loop cursor

crtc

the CRTC whose planes are iterated

Description

This iterates over the current state, useful (for example) when applyingatomic state after it has been checked and swapped. To iterate over theplanes whichwill be attached (more useful in code called fromdrm_mode_config_funcs.atomic_check) seedrm_atomic_crtc_state_for_each_plane().

drm_atomic_crtc_state_for_each_plane

drm_atomic_crtc_state_for_each_plane(plane,crtc_state)

iterate over attached planes in new state

Parameters

plane

the loop cursor

crtc_state

the incoming CRTC state

Description

Similar todrm_crtc_for_each_plane(), but iterates the planes that will beattached if the specified state is applied. Useful during for examplein code called fromdrm_mode_config_funcs.atomic_check operations, tovalidate the incoming state.

drm_atomic_crtc_state_for_each_plane_state

drm_atomic_crtc_state_for_each_plane_state(plane,plane_state,crtc_state)

iterate over attached planes in new state

Parameters

plane

the loop cursor

plane_state

loop cursor for the plane’s state, must be const

crtc_state

the incoming CRTC state

Description

Similar todrm_crtc_for_each_plane(), but iterates the planes that will beattached if the specified state is applied. Useful during for examplein code called fromdrm_mode_config_funcs.atomic_check operations, tovalidate the incoming state.

Compared to justdrm_atomic_crtc_state_for_each_plane() this also fills in aconst plane_state. This is useful when a driver just wants to peek at otheractive planes on this CRTC, but does not need to change it.

booldrm_atomic_plane_enabling(structdrm_plane_state*old_plane_state,structdrm_plane_state*new_plane_state)

check whether a plane is being enabled

Parameters

structdrm_plane_state*old_plane_state

old atomic plane state

structdrm_plane_state*new_plane_state

new atomic plane state

Description

Checks the atomic state of a plane to determine whether it’s being enabledor not. This also WARNs if it detects an invalid state (both CRTC and FBneed to either both be NULL or both be non-NULL).

Return

True if the plane is being enabled, false otherwise.

booldrm_atomic_plane_disabling(structdrm_plane_state*old_plane_state,structdrm_plane_state*new_plane_state)

check whether a plane is being disabled

Parameters

structdrm_plane_state*old_plane_state

old atomic plane state

structdrm_plane_state*new_plane_state

new atomic plane state

Description

Checks the atomic state of a plane to determine whether it’s being disabledor not. This also WARNs if it detects an invalid state (both CRTC and FBneed to either both be NULL or both be non-NULL).

Return

True if the plane is being disabled, false otherwise.

intdrm_atomic_helper_check_modeset(structdrm_device*dev,structdrm_atomic_state*state)

validate state object for modeset changes

Parameters

structdrm_device*dev

DRM device

structdrm_atomic_state*state

the driver state object

Description

Check the state object to see if the requested state is physically possible.This does all the CRTC and connector related computations for an atomicupdate and adds any additional connectors needed for full modesets. It callsthe various per-object callbacks in the follow order:

  1. drm_connector_helper_funcs.atomic_best_encoder for determining the new encoder.

  2. drm_connector_helper_funcs.atomic_check to validate the connector state.

  3. If it’s determined a modeset is needed then all connectors on the affectedCRTC are added anddrm_connector_helper_funcs.atomic_check is run on them.

  4. drm_encoder_helper_funcs.mode_valid,drm_bridge_funcs.mode_valid anddrm_crtc_helper_funcs.mode_valid are called on the affected components.

  5. drm_bridge_funcs.mode_fixup is called on all encoder bridges.

  6. drm_encoder_helper_funcs.atomic_check is called to validate any encoder state.This function is only called when the encoder will be part of a configured CRTC,it must not be used for implementing connector property validation.If this function is NULL,drm_atomic_encoder_helper_funcs.mode_fixup is calledinstead.

  7. drm_crtc_helper_funcs.mode_fixup is called last, to fix up the mode with CRTC constraints.

drm_crtc_state.mode_changed is set when the input mode is changed.drm_crtc_state.connectors_changed is set when a connector is added orremoved from the CRTC.drm_crtc_state.active_changed is set whendrm_crtc_state.active changes, which is used for DPMS.drm_crtc_state.no_vblank is set from the result ofdrm_dev_has_vblank().See also:drm_atomic_crtc_needs_modeset()

IMPORTANT:

Drivers which setdrm_crtc_state.mode_changed (e.g. in theirdrm_plane_helper_funcs.atomic_check hooks if a plane update can’t be donewithout a full modeset) _must_ call this function after that change. It ispermitted to call this function multiple times for the same update, e.g.when thedrm_crtc_helper_funcs.atomic_check functions depend upon theadjusted dotclock for fifo space allocation and watermark computation.

Return

Zero for success or -errno

intdrm_atomic_helper_check_wb_connector_state(structdrm_connector*connector,structdrm_atomic_state*state)

Check writeback connector state

Parameters

structdrm_connector*connector

corresponding connector

structdrm_atomic_state*state

the driver state object

Description

Checks if the writeback connector state is valid, and returns an error if itisn’t.

Return

Zero for success or -errno

intdrm_atomic_helper_check_plane_state(structdrm_plane_state*plane_state,conststructdrm_crtc_state*crtc_state,intmin_scale,intmax_scale,boolcan_position,boolcan_update_disabled)

Check plane state for validity

Parameters

structdrm_plane_state*plane_state

plane state to check

conststructdrm_crtc_state*crtc_state

CRTC state to check

intmin_scale

minimumsrc:dest scaling factor in 16.16 fixed point

intmax_scale

maximumsrc:dest scaling factor in 16.16 fixed point

boolcan_position

is it legal to position the plane such that itdoesn’t cover the entire CRTC? This will generallyonly be false for primary planes.

boolcan_update_disabled

can the plane be updated while the CRTCis disabled?

Description

Checks that a desired plane update is valid, and updates variousbits of derived state (clipped coordinates etc.). Drivers that providetheir own plane handling rather than helper-provided implementations maystill wish to call this function to avoid duplication of error checkingcode.

Return

Zero if update appears valid, error code on failure

intdrm_atomic_helper_check_crtc_primary_plane(structdrm_crtc_state*crtc_state)

Check CRTC state for primary plane

Parameters

structdrm_crtc_state*crtc_state

CRTC state to check

Description

Checks that a CRTC has at least one primary plane attached to it, which isa requirement on some hardware. Note that this only involves the CRTC sideof the test. To test if the primary plane is visible or if it can be updatedwithout the CRTC being enabled, usedrm_atomic_helper_check_plane_state() inthe plane’s atomic check.

Return

0 if a primary plane is attached to the CRTC, or an error code otherwise

intdrm_atomic_helper_check_planes(structdrm_device*dev,structdrm_atomic_state*state)

validate state object for planes changes

Parameters

structdrm_device*dev

DRM device

structdrm_atomic_state*state

the driver state object

Description

Check the state object to see if the requested state is physically possible.This does all the plane update related checks using by calling into thedrm_crtc_helper_funcs.atomic_check anddrm_plane_helper_funcs.atomic_checkhooks provided by the driver.

It also setsdrm_crtc_state.planes_changed to indicate that a CRTC hasupdated planes.

Return

Zero for success or -errno

intdrm_atomic_helper_check(structdrm_device*dev,structdrm_atomic_state*state)

validate state object

Parameters

structdrm_device*dev

DRM device

structdrm_atomic_state*state

the driver state object

Description

Check the state object to see if the requested state is physically possible.Only CRTCs and planes have check callbacks, so for any additional (global)checking that a driver needs it can simply wrap that around this function.Drivers without such needs can directly use this as theirdrm_mode_config_funcs.atomic_check callback.

This just wraps the two parts of the state checking for planes and modesetstate in the default order: First it callsdrm_atomic_helper_check_modeset()and thendrm_atomic_helper_check_planes(). The assumption is that thedrm_plane_helper_funcs.atomic_check anddrm_crtc_helper_funcs.atomic_checkfunctions depend upon an updated adjusted_mode.clock to e.g. properly computewatermarks.

Note that zpos normalization will add all enable planes to the state whichmight not desired for some drivers.For example enable/disable of a cursor plane which have fixed zpos valuewould trigger all other enabled planes to be forced to the state change.

IMPORTANT:

As this function callsdrm_atomic_helper_check_modeset() internally, itsrestrictions also apply:Drivers which setdrm_crtc_state.mode_changed (e.g. in theirdrm_plane_helper_funcs.atomic_check hooks if a plane update can’t be donewithout a full modeset) _must_ calldrm_atomic_helper_check_modeset()function again after that change.

Return

Zero for success or -errno

voiddrm_atomic_helper_commit_encoder_bridge_disable(structdrm_device*dev,structdrm_atomic_state*state)

disable bridges and encoder

Parameters

structdrm_device*dev

DRM device

structdrm_atomic_state*state

the driver state object

Description

Loops over all connectors in the current state and if the CRTC needsit, disables the bridge chain all the way, then disables the encoderafterwards.

voiddrm_atomic_helper_commit_crtc_disable(structdrm_device*dev,structdrm_atomic_state*state)

disable CRTSs

Parameters

structdrm_device*dev

DRM device

structdrm_atomic_state*state

the driver state object

Description

Loops over all CRTCs in the current state and if the CRTC needsit, disables it.

voiddrm_atomic_helper_commit_encoder_bridge_post_disable(structdrm_device*dev,structdrm_atomic_state*state)

post-disable encoder bridges

Parameters

structdrm_device*dev

DRM device

structdrm_atomic_state*state

the driver state object

Description

Loops over all connectors in the current state and if the CRTC needsit, post-disables all encoder bridges.

voiddrm_atomic_helper_update_legacy_modeset_state(structdrm_device*dev,structdrm_atomic_state*state)

update legacy modeset state

Parameters

structdrm_device*dev

DRM device

structdrm_atomic_state*state

atomic state object being committed

Description

This function updates all the various legacy modeset state pointers inconnectors, encoders and CRTCs.

Drivers can use this for building their own atomic commit if they don’t havea pure helper-based modeset implementation.

Since these updates are not synchronized with lockings, only code pathscalled fromdrm_mode_config_helper_funcs.atomic_commit_tail can look at thelegacy state filled out by this helper. Defacto this means this helper andthe legacy state pointers are only really useful for transitioning anexisting driver to the atomic world.

voiddrm_atomic_helper_calc_timestamping_constants(structdrm_atomic_state*state)

update vblank timestamping constants

Parameters

structdrm_atomic_state*state

atomic state object

Description

Updates the timestamping constants used for precise vblank timestampsby callingdrm_calc_timestamping_constants() for all enabled crtcs instate.

voiddrm_atomic_helper_commit_crtc_set_mode(structdrm_device*dev,structdrm_atomic_state*state)

set the new mode

Parameters

structdrm_device*dev

DRM device

structdrm_atomic_state*state

the driver state object

Description

Loops over all connectors in the current state and if the mode haschanged, change the mode of the CRTC, then call down the bridgechain and change the mode in all bridges as well.

voiddrm_atomic_helper_commit_modeset_disables(structdrm_device*dev,structdrm_atomic_state*state)

modeset commit to disable outputs

Parameters

structdrm_device*dev

DRM device

structdrm_atomic_state*state

atomic state object being committed

Description

This function shuts down all the outputs that need to be shut down andprepares them (if required) with the new mode.

For compatibility with legacy CRTC helpers this should be called beforedrm_atomic_helper_commit_planes(), which is what the default commit functiondoes. But drivers with different needs can group the modeset commits togetherand do the plane commits at the end. This is useful for drivers doing runtimePM since planes updates then only happen when the CRTC is actually enabled.

voiddrm_atomic_helper_commit_writebacks(structdrm_device*dev,structdrm_atomic_state*state)

issue writebacks

Parameters

structdrm_device*dev

DRM device

structdrm_atomic_state*state

atomic state object being committed

Description

This loops over the connectors, checks if the new state requiresa writeback job to be issued and in that case issues an atomiccommit on each connector.

voiddrm_atomic_helper_commit_encoder_bridge_pre_enable(structdrm_device*dev,structdrm_atomic_state*state)

pre-enable bridges

Parameters

structdrm_device*dev

DRM device

structdrm_atomic_state*state

atomic state object being committed

Description

This loops over the connectors and if the CRTC needs it, pre-enablesthe entire bridge chain.

voiddrm_atomic_helper_commit_crtc_enable(structdrm_device*dev,structdrm_atomic_state*state)

enables the CRTCs

Parameters

structdrm_device*dev

DRM device

structdrm_atomic_state*state

atomic state object being committed

Description

This loops over CRTCs in the new state, and of the CRTC needsit, enables it.

voiddrm_atomic_helper_commit_encoder_bridge_enable(structdrm_device*dev,structdrm_atomic_state*state)

enables the bridges

Parameters

structdrm_device*dev

DRM device

structdrm_atomic_state*state

atomic state object being committed

Description

This loops over all connectors in the new state, and of the CRTC needsit, enables the entire bridge chain.

voiddrm_atomic_helper_commit_modeset_enables(structdrm_device*dev,structdrm_atomic_state*state)

modeset commit to enable outputs

Parameters

structdrm_device*dev

DRM device

structdrm_atomic_state*state

atomic state object being committed

Description

This function enables all the outputs with the new configuration which had tobe turned off for the update.

For compatibility with legacy CRTC helpers this should be called afterdrm_atomic_helper_commit_planes(), which is what the default commit functiondoes. But drivers with different needs can group the modeset commits togetherand do the plane commits at the end. This is useful for drivers doing runtimePM since planes updates then only happen when the CRTC is actually enabled.

intdrm_atomic_helper_wait_for_fences(structdrm_device*dev,structdrm_atomic_state*state,boolpre_swap)

wait for fences stashed in plane state

Parameters

structdrm_device*dev

DRM device

structdrm_atomic_state*state

atomic state object with old state structures

boolpre_swap

If true, do an interruptible wait, andstate is the new state.Otherwisestate is the old state.

Description

For implicit sync, driver should fish the exclusive fence out from theincoming fb’s and stash it in the drm_plane_state. This is called afterdrm_atomic_helper_swap_state() so it uses the current plane state (andjust uses the atomic state to find the changed planes)

Note thatpre_swap is needed since the point where we block for fences movesaround depending upon whether an atomic commit is blocking ornon-blocking. For non-blocking commit all waiting needs to happen afterdrm_atomic_helper_swap_state() is called, but for blocking commits we wantto waitbefore we do anything that can’t be easily rolled back. That isbefore we calldrm_atomic_helper_swap_state().

Returns zero if success or < 0 ifdma_fence_wait() fails.

voiddrm_atomic_helper_wait_for_vblanks(structdrm_device*dev,structdrm_atomic_state*state)

wait for vblank on CRTCs

Parameters

structdrm_device*dev

DRM device

structdrm_atomic_state*state

atomic state object being committed

Description

Helper to, after atomic commit, wait for vblanks on all affectedCRTCs (ie. before cleaning up old framebuffers usingdrm_atomic_helper_cleanup_planes()). It will only wait on CRTCs where theframebuffers have actually changed to optimize for the legacy cursor andplane update use-case.

Drivers using the nonblocking commit tracking support initialized by callingdrm_atomic_helper_setup_commit() should look atdrm_atomic_helper_wait_for_flip_done() as an alternative.

voiddrm_atomic_helper_wait_for_flip_done(structdrm_device*dev,structdrm_atomic_state*state)

wait for all page flips to be done

Parameters

structdrm_device*dev

DRM device

structdrm_atomic_state*state

atomic state object being committed

Description

Helper to, after atomic commit, wait for page flips on all affectedcrtcs (ie. before cleaning up old framebuffers usingdrm_atomic_helper_cleanup_planes()). Compared todrm_atomic_helper_wait_for_vblanks() this waits for the completion on allCRTCs, assuming that cursors-only updates are signalling their completionimmediately (or using a different path).

This requires that drivers use the nonblocking commit tracking supportinitialized usingdrm_atomic_helper_setup_commit().

voiddrm_atomic_helper_commit_tail(structdrm_atomic_state*state)

commit atomic update to hardware

Parameters

structdrm_atomic_state*state

atomic state object being committed

Description

This is the default implementation for thedrm_mode_config_helper_funcs.atomic_commit_tail hook, for driversthat do not support runtime_pm or do not need the CRTC to beenabled to perform a commit. Otherwise, seedrm_atomic_helper_commit_tail_rpm().

Note that the default ordering of how the various stages are called is tomatch the legacy modeset helper library closest.

voiddrm_atomic_helper_commit_tail_rpm(structdrm_atomic_state*state)

commit atomic update to hardware

Parameters

structdrm_atomic_state*state

new modeset state to be committed

Description

This is an alternative implementation for thedrm_mode_config_helper_funcs.atomic_commit_tail hook, for driversthat support runtime_pm or need the CRTC to be enabled to perform acommit. Otherwise, one should use the default implementationdrm_atomic_helper_commit_tail().

intdrm_atomic_helper_async_check(structdrm_device*dev,structdrm_atomic_state*state)

check if state can be committed asynchronously

Parameters

structdrm_device*dev

DRM device

structdrm_atomic_state*state

the driver state object

Description

This helper will check if it is possible to commit the state asynchronously.Async commits are not supposed to swap the states like normal sync commitsbut just do in-place changes on the current state.

It will return 0 if the commit can happen in an asynchronous fashion or errorif not. Note that error just mean it can’t be committed asynchronously, if itfails the commit should be treated like a normal synchronous commit.

voiddrm_atomic_helper_async_commit(structdrm_device*dev,structdrm_atomic_state*state)

commit state asynchronously

Parameters

structdrm_device*dev

DRM device

structdrm_atomic_state*state

the driver state object

Description

This function commits a state asynchronously, i.e., not vblanksynchronized. It should be used on a state only whendrm_atomic_async_check() succeeds. Async commits are not supposed to swapthe states like normal sync commits, but just do in-place changes on thecurrent state.

TODO: Implement full swap instead of doing in-place changes.

intdrm_atomic_helper_commit(structdrm_device*dev,structdrm_atomic_state*state,boolnonblock)

commit validated state object

Parameters

structdrm_device*dev

DRM device

structdrm_atomic_state*state

the driver state object

boolnonblock

whether nonblocking behavior is requested.

Description

This function commits a withdrm_atomic_helper_check() pre-validated stateobject. This can still fail when e.g. the framebuffer reservation fails. Thisfunction implements nonblocking commits, usingdrm_atomic_helper_setup_commit() and related functions.

Committing the actual hardware state is done through thedrm_mode_config_helper_funcs.atomic_commit_tail callback, or its defaultimplementationdrm_atomic_helper_commit_tail().

Return

Zero for success or -errno.

intdrm_atomic_helper_setup_commit(structdrm_atomic_state*state,boolnonblock)

setup possibly nonblocking commit

Parameters

structdrm_atomic_state*state

new modeset state to be committed

boolnonblock

whether nonblocking behavior is requested.

Description

This function preparesstate to be used by the atomic helper’s support fornonblocking commits. Drivers using the nonblocking commit infrastructureshould always call this function from theirdrm_mode_config_funcs.atomic_commit hook.

Drivers that need to extend the commit setup to private objects can use thedrm_mode_config_helper_funcs.atomic_commit_setup hook.

To be able to use this support drivers need to use a few more helperfunctions.drm_atomic_helper_wait_for_dependencies() must be called beforeactually committing the hardware state, and for nonblocking commits this callmust be placed in the async worker. See alsodrm_atomic_helper_swap_state()and its stall parameter, for when a driver’s commit hooks look at thedrm_crtc.state,drm_plane.state ordrm_connector.state pointer directly.

Completion of the hardware commit step must be signalled usingdrm_atomic_helper_commit_hw_done(). After this step the driver is not allowedto read or change any permanent software or hardware modeset state. The onlyexception is state protected by other means thandrm_modeset_lock locks.Only the free standingstate with pointers to the old state structures canbe inspected, e.g. to clean up old buffers usingdrm_atomic_helper_cleanup_planes().

At the very end, before cleaning upstate drivers must calldrm_atomic_helper_commit_cleanup_done().

This is all implemented by indrm_atomic_helper_commit(), giving drivers acomplete and easy-to-use default implementation of theatomic_commit() hook.

The tracking of asynchronously executed and still pending commits is doneusing the core structuredrm_crtc_commit.

By default there’s no need to clean up resources allocated by this functionexplicitly:drm_atomic_state_default_clear() will take care of thatautomatically.

Return

0 on success. -EBUSY when userspace schedules nonblocking commits too fast,-ENOMEM on allocation failures and -EINTR when a signal is pending.

voiddrm_atomic_helper_wait_for_dependencies(structdrm_atomic_state*state)

wait for required preceding commits

Parameters

structdrm_atomic_state*state

atomic state object being committed

Description

This function waits for all preceding commits that touch the same CRTC asstate to both be committed to the hardware (as signalled bydrm_atomic_helper_commit_hw_done()) and executed by the hardware (as signalledby callingdrm_crtc_send_vblank_event() on thedrm_crtc_state.event).

This is part of the atomic helper support for nonblocking commits, seedrm_atomic_helper_setup_commit() for an overview.

voiddrm_atomic_helper_fake_vblank(structdrm_atomic_state*state)

fake VBLANK events if needed

Parameters

structdrm_atomic_state*state

atomic state object being committed

Description

This function walks all CRTCs and fakes VBLANK events on those withdrm_crtc_state.no_vblank set to true anddrm_crtc_state.event != NULL.The primary use of this function is writeback connectors working in oneshotmode and faking VBLANK events. In this case they only fake the VBLANK eventwhen a job is queued, and any change to the pipeline that does not touch theconnector is leading to timeouts when callingdrm_atomic_helper_wait_for_vblanks() ordrm_atomic_helper_wait_for_flip_done(). In addition to writebackconnectors, this function can also fake VBLANK events for CRTCs withoutVBLANK interrupt.

This is part of the atomic helper support for nonblocking commits, seedrm_atomic_helper_setup_commit() for an overview.

voiddrm_atomic_helper_commit_hw_done(structdrm_atomic_state*state)

setup possible nonblocking commit

Parameters

structdrm_atomic_state*state

atomic state object being committed

Description

This function is used to signal completion of the hardware commit step. Afterthis step the driver is not allowed to read or change any permanent softwareor hardware modeset state. The only exception is state protected by othermeans thandrm_modeset_lock locks.

Drivers should try to postpone any expensive or delayed cleanup work afterthis function is called.

This is part of the atomic helper support for nonblocking commits, seedrm_atomic_helper_setup_commit() for an overview.

voiddrm_atomic_helper_commit_cleanup_done(structdrm_atomic_state*state)

signal completion of commit

Parameters

structdrm_atomic_state*state

atomic state object being committed

Description

This signals completion of the atomic updatestate, including anycleanup work. If used, it must be called right before callingdrm_atomic_state_put().

This is part of the atomic helper support for nonblocking commits, seedrm_atomic_helper_setup_commit() for an overview.

intdrm_atomic_helper_prepare_planes(structdrm_device*dev,structdrm_atomic_state*state)

prepare plane resources before commit

Parameters

structdrm_device*dev

DRM device

structdrm_atomic_state*state

atomic state object with new state structures

Description

This function prepares plane state, specifically framebuffers, for the newconfiguration, by callingdrm_plane_helper_funcs.prepare_fb. If any failureis encountered this function will calldrm_plane_helper_funcs.cleanup_fb onany already successfully prepared framebuffer.

Return

0 on success, negative error code on failure.

voiddrm_atomic_helper_unprepare_planes(structdrm_device*dev,structdrm_atomic_state*state)

release plane resources on aborts

Parameters

structdrm_device*dev

DRM device

structdrm_atomic_state*state

atomic state object with old state structures

Description

This function cleans up plane state, specifically framebuffers, from theatomic state. It undoes the effects ofdrm_atomic_helper_prepare_planes()when aborting an atomic commit. For cleaning up after a successful commitusedrm_atomic_helper_cleanup_planes().

voiddrm_atomic_helper_commit_planes(structdrm_device*dev,structdrm_atomic_state*state,uint32_tflags)

commit plane state

Parameters

structdrm_device*dev

DRM device

structdrm_atomic_state*state

atomic state object being committed

uint32_tflags

flags for committing plane state

Description

This function commits the new plane state using the plane and atomic helperfunctions for planes and CRTCs. It assumes that the atomic state has alreadybeen pushed into the relevant object state pointers, since this step can nolonger fail.

It still requires the global state objectstate to know which planes andcrtcs need to be updated though.

Note that this function does all plane updates across all CRTCs in one step.If the hardware can’t support this approach look atdrm_atomic_helper_commit_planes_on_crtc() instead.

Plane parameters can be updated by applications while the associated CRTC isdisabled. The DRM/KMS core will store the parameters in the plane state,which will be available to the driver when the CRTC is turned on. As a resultmost drivers don’t need to be immediately notified of plane updates for adisabled CRTC.

Unless otherwise needed, drivers are advised to set the ACTIVE_ONLY flag inflags in order not to receive plane update notifications related to adisabled CRTC. This avoids the need to manually ignore plane updates indriver code when the driver and/or hardware can’t or just don’t need to dealwith updates on disabled CRTCs, for example when supporting runtime PM.

Drivers may set the NO_DISABLE_AFTER_MODESET flag inflags if the relevantdisplay controllers require to disable a CRTC’s planes when the CRTC isdisabled. This function would skip thedrm_plane_helper_funcs.atomic_disablecall for a plane if the CRTC of the old plane state needs a modesettingoperation. Of course, the drivers need to disable the planes in their CRTCdisable callbacks since no one else would do that.

Thedrm_atomic_helper_commit() default implementation doesn’t set theACTIVE_ONLY flag to most closely match the behaviour of the legacy helpers.This should not be copied blindly by drivers.

voiddrm_atomic_helper_commit_planes_on_crtc(structdrm_crtc_state*old_crtc_state)

commit plane state for a CRTC

Parameters

structdrm_crtc_state*old_crtc_state

atomic state object with the old CRTC state

Description

This function commits the new plane state using the plane and atomic helperfunctions for planes on the specific CRTC. It assumes that the atomic statehas already been pushed into the relevant object state pointers, since thisstep can no longer fail.

This function is useful when plane updates should be done CRTC-by-CRTCinstead of one global step likedrm_atomic_helper_commit_planes() does.

This function can only be savely used when planes are not allowed to movebetween different CRTCs because this function doesn’t handle inter-CRTCdependencies. Callers need to ensure that either no such dependencies exist,resolve them through ordering of commit calls or through some other means.

voiddrm_atomic_helper_disable_planes_on_crtc(structdrm_crtc_state*old_crtc_state,boolatomic)

helper to disable CRTC’s planes

Parameters

structdrm_crtc_state*old_crtc_state

atomic state object with the old CRTC state

boolatomic

if set, synchronize with CRTC’s atomic_begin/flush hooks

Description

Disables all planes associated with the given CRTC. This can beused for instance in the CRTC helper atomic_disable callback to disableall planes.

If the atomic-parameter is set the function calls the CRTC’satomic_begin hook before and atomic_flush hook after disabling theplanes.

It is a bug to call this function without having implemented thedrm_plane_helper_funcs.atomic_disable plane hook.

voiddrm_atomic_helper_cleanup_planes(structdrm_device*dev,structdrm_atomic_state*state)

cleanup plane resources after commit

Parameters

structdrm_device*dev

DRM device

structdrm_atomic_state*state

atomic state object being committed

Description

This function cleans up plane state, specifically framebuffers, from the oldconfiguration. Hence the old configuration must be perserved instate tobe able to call this function.

This function may not be called on the new state when the atomic updatefails at any point after callingdrm_atomic_helper_prepare_planes(). Usedrm_atomic_helper_unprepare_planes() in this case.

intdrm_atomic_helper_swap_state(structdrm_atomic_state*state,boolstall)

store atomic state into current sw state

Parameters

structdrm_atomic_state*state

atomic state

boolstall

stall for preceding commits

Description

This function stores the atomic state into the current state pointers in alldriver objects. It should be called after all failing steps have been doneand succeeded, but before the actual hardware state is committed.

For cleanup and error recovery the current state for all changed objects willbe swapped intostate.

With that sequence it fits perfectly into the plane prepare/cleanup sequence:

  1. Calldrm_atomic_helper_prepare_planes() with the staged atomic state.

  2. Do any other steps that might fail.

  3. Put the staged state into the current state pointers with this function.

  4. Actually commit the hardware state.

5. Calldrm_atomic_helper_cleanup_planes() withstate, which since step 3contains the old state. Also do any other cleanup required with that state.

stall must be set when nonblocking commits for this driver directly accessthedrm_plane.state,drm_crtc.state ordrm_connector.state pointer. Withthe current atomic helpers this is almost always the case, since the helpersdon’t pass the right state structures to the callbacks.

Return

Returns 0 on success. Can return -ERESTARTSYS whenstall is true and thewaiting for the previous commits has been interrupted.

intdrm_atomic_helper_update_plane(structdrm_plane*plane,structdrm_crtc*crtc,structdrm_framebuffer*fb,intcrtc_x,intcrtc_y,unsignedintcrtc_w,unsignedintcrtc_h,uint32_tsrc_x,uint32_tsrc_y,uint32_tsrc_w,uint32_tsrc_h,structdrm_modeset_acquire_ctx*ctx)

Helper for primary plane update using atomic

Parameters

structdrm_plane*plane

plane object to update

structdrm_crtc*crtc

owning CRTC of owning plane

structdrm_framebuffer*fb

framebuffer to flip onto plane

intcrtc_x

x offset of primary plane oncrtc

intcrtc_y

y offset of primary plane oncrtc

unsignedintcrtc_w

width of primary plane rectangle oncrtc

unsignedintcrtc_h

height of primary plane rectangle oncrtc

uint32_tsrc_x

x offset offb for panning

uint32_tsrc_y

y offset offb for panning

uint32_tsrc_w

width of source rectangle infb

uint32_tsrc_h

height of source rectangle infb

structdrm_modeset_acquire_ctx*ctx

lock acquire context

Description

Provides a default plane update handler using the atomic driver interface.

Return

Zero on success, error code on failure

intdrm_atomic_helper_disable_plane(structdrm_plane*plane,structdrm_modeset_acquire_ctx*ctx)

Helper for primary plane disable using atomic

Parameters

structdrm_plane*plane

plane to disable

structdrm_modeset_acquire_ctx*ctx

lock acquire context

Description

Provides a default plane disable handler using the atomic driver interface.

Return

Zero on success, error code on failure

intdrm_atomic_helper_set_config(structdrm_mode_set*set,structdrm_modeset_acquire_ctx*ctx)

set a new config from userspace

Parameters

structdrm_mode_set*set

mode set configuration

structdrm_modeset_acquire_ctx*ctx

lock acquisition context

Description

Provides a default CRTC set_config handler using the atomic driver interface.

NOTE

For backwards compatibility with old userspace this automaticallyresets the “link-status” property to GOOD, to force any linkre-training. The SETCRTC ioctl does not define whether an update doesneed a full modeset or just a plane update, hence we’re allowed to dothat. See alsodrm_connector_set_link_status_property().

Return

Returns 0 on success, negative errno numbers on failure.

intdrm_atomic_helper_disable_all(structdrm_device*dev,structdrm_modeset_acquire_ctx*ctx)

disable all currently active outputs

Parameters

structdrm_device*dev

DRM device

structdrm_modeset_acquire_ctx*ctx

lock acquisition context

Description

Loops through all connectors, finding those that aren’t turned off and thenturns them off by setting their DPMS mode to OFF and deactivating the CRTCthat they are connected to.

This is used for example in suspend/resume to disable all currently activefunctions when suspending. If you just want to shut down everything at e.g.driver unload, look atdrm_atomic_helper_shutdown().

Note that if callers haven’t already acquired all modeset locks this mightreturn -EDEADLK, which must be handled by callingdrm_modeset_backoff().

See also:drm_atomic_helper_suspend(),drm_atomic_helper_resume() anddrm_atomic_helper_shutdown().

Return

0 on success or a negative error code on failure.

intdrm_atomic_helper_reset_crtc(structdrm_crtc*crtc,structdrm_modeset_acquire_ctx*ctx)

reset the active outputs of a CRTC

Parameters

structdrm_crtc*crtc

DRM CRTC

structdrm_modeset_acquire_ctx*ctx

lock acquisition context

Description

Reset the active outputs by indicating that connectors have changed.This implies a reset of all active components available between the CRTC andconnectors.

A variant of this function exists withdrm_bridge_helper_reset_crtc(), dedicated to bridges.

NOTE

This relies on resettingdrm_crtc_state.connectors_changed.For drivers which optimize out unnecessary modesets this will result ina no-op commit, achieving nothing.

Return

0 on success or a negative error code on failure.

voiddrm_atomic_helper_shutdown(structdrm_device*dev)

shutdown all CRTC

Parameters

structdrm_device*dev

DRM device

Description

This shuts down all CRTC, which is useful for driver unloading. Shutdown onsuspend should instead be handled withdrm_atomic_helper_suspend(), sincethat also takes a snapshot of the modeset state to be restored on resume.

This is just a convenience wrapper arounddrm_atomic_helper_disable_all(),and it is the atomic version ofdrm_helper_force_disable_all().

structdrm_atomic_state*drm_atomic_helper_duplicate_state(structdrm_device*dev,structdrm_modeset_acquire_ctx*ctx)

duplicate an atomic state object

Parameters

structdrm_device*dev

DRM device

structdrm_modeset_acquire_ctx*ctx

lock acquisition context

Description

Makes a copy of the current atomic state by looping over all objects andduplicating their respective states. This is used for example by suspend/resume support code to save the state prior to suspend such that it canbe restored upon resume.

Note that this treats atomic state as persistent between save and restore.Drivers must make sure that this is possible and won’t result in confusionor erroneous behaviour.

Note that if callers haven’t already acquired all modeset locks this mightreturn -EDEADLK, which must be handled by callingdrm_modeset_backoff().

See also:drm_atomic_helper_suspend(),drm_atomic_helper_resume()

Return

A pointer to the copy of the atomic state object on success or anERR_PTR()-encoded error code on failure.

structdrm_atomic_state*drm_atomic_helper_suspend(structdrm_device*dev)

subsystem-level suspend helper

Parameters

structdrm_device*dev

DRM device

Description

Duplicates the current atomic state, disables all active outputs and thenreturns a pointer to the original atomic state to the caller. Drivers canpass this pointer to thedrm_atomic_helper_resume() helper upon resume torestore the output configuration that was active at the time the systementered suspend.

Note that it is potentially unsafe to use this. The atomic state objectreturned by this function is assumed to be persistent. Drivers must ensurethat this holds true. Before calling this function, drivers must make sureto suspend fbdev emulation so that nothing can be using the device.

See also:drm_atomic_helper_duplicate_state(),drm_atomic_helper_disable_all(),drm_atomic_helper_resume(),drm_atomic_helper_commit_duplicated_state()

Return

A pointer to a copy of the state before suspend on success or anERR_PTR()-encoded error code on failure. Drivers should store the returned atomicstate object and pass it to thedrm_atomic_helper_resume() helper uponresume.

intdrm_atomic_helper_commit_duplicated_state(structdrm_atomic_state*state,structdrm_modeset_acquire_ctx*ctx)

commit duplicated state

Parameters

structdrm_atomic_state*state

duplicated atomic state to commit

structdrm_modeset_acquire_ctx*ctx

pointer to acquire_ctx to use for commit.

Description

The state returned bydrm_atomic_helper_duplicate_state() anddrm_atomic_helper_suspend() is partially invalid, and needs tobe fixed up before commit.

See also:drm_atomic_helper_suspend()

Return

0 on success or a negative error code on failure.

intdrm_atomic_helper_resume(structdrm_device*dev,structdrm_atomic_state*state)

subsystem-level resume helper

Parameters

structdrm_device*dev

DRM device

structdrm_atomic_state*state

atomic state to resume to

Description

Callsdrm_mode_config_reset() to synchronize hardware and software states,grabs all modeset locks and commits the atomic state object. This can beused in conjunction with thedrm_atomic_helper_suspend() helper toimplement suspend/resume for drivers that support atomic mode-setting.

See also:drm_atomic_helper_suspend()

Return

0 on success or a negative error code on failure.

intdrm_atomic_helper_page_flip(structdrm_crtc*crtc,structdrm_framebuffer*fb,structdrm_pending_vblank_event*event,uint32_tflags,structdrm_modeset_acquire_ctx*ctx)

execute a legacy page flip

Parameters

structdrm_crtc*crtc

DRM CRTC

structdrm_framebuffer*fb

DRM framebuffer

structdrm_pending_vblank_event*event

optional DRM event to signal upon completion

uint32_tflags

flip flags for non-vblank sync’ed updates

structdrm_modeset_acquire_ctx*ctx

lock acquisition context

Description

Provides a defaultdrm_crtc_funcs.page_flip implementationusing the atomic driver interface.

See also:drm_atomic_helper_page_flip_target()

Return

Returns 0 on success, negative errno numbers on failure.

intdrm_atomic_helper_page_flip_target(structdrm_crtc*crtc,structdrm_framebuffer*fb,structdrm_pending_vblank_event*event,uint32_tflags,uint32_ttarget,structdrm_modeset_acquire_ctx*ctx)

do page flip on target vblank period.

Parameters

structdrm_crtc*crtc

DRM CRTC

structdrm_framebuffer*fb

DRM framebuffer

structdrm_pending_vblank_event*event

optional DRM event to signal upon completion

uint32_tflags

flip flags for non-vblank sync’ed updates

uint32_ttarget

specifying the target vblank period when the flip to take effect

structdrm_modeset_acquire_ctx*ctx

lock acquisition context

Description

Provides a defaultdrm_crtc_funcs.page_flip_target implementation.Similar todrm_atomic_helper_page_flip() with extra parameter to specifytarget vblank period to flip.

Return

Returns 0 on success, negative errno numbers on failure.

u32*drm_atomic_helper_bridge_propagate_bus_fmt(structdrm_bridge*bridge,structdrm_bridge_state*bridge_state,structdrm_crtc_state*crtc_state,structdrm_connector_state*conn_state,u32output_fmt,unsignedint*num_input_fmts)

Propagate output format to the input end of a bridge

Parameters

structdrm_bridge*bridge

bridge control structure

structdrm_bridge_state*bridge_state

new bridge state

structdrm_crtc_state*crtc_state

new CRTC state

structdrm_connector_state*conn_state

new connector state

u32output_fmt

tested output bus format

unsignedint*num_input_fmts

will contain the size of the returned array

Description

This helper is a pluggable implementation of thedrm_bridge_funcs.atomic_get_input_bus_fmts operation for bridges that don’tmodify the bus configuration between their input and their output. Itreturns an array of input formats with a single element set tooutput_fmt.

Return

a valid format array of sizenum_input_fmts, or NULL if the allocationfailed

Atomic State Reset and Initialization

Both the drm core and the atomic helpers assume that there is always the fulland correct atomic software state for all connectors, CRTCs and planesavailable. Which is a bit a problem on driver load and also after systemsuspend. One way to solve this is to have a hardware state read-outinfrastructure which reconstructs the full software state (e.g. the i915driver).

The simpler solution is to just reset the software state to everything off,which is easiest to do by callingdrm_mode_config_reset(). To facilitate thisthe atomic helpers provide default reset implementations for all hooks.

On the upside the precise state tracking of atomic simplifies system suspendand resume a lot. For drivers usingdrm_mode_config_reset() a complete recipeis implemented indrm_atomic_helper_suspend() anddrm_atomic_helper_resume().For other drivers the building blocks are split out, see the documentationfor these functions.

Atomic State Helper Reference

void__drm_atomic_helper_crtc_state_reset(structdrm_crtc_state*crtc_state,structdrm_crtc*crtc)

reset the CRTC state

Parameters

structdrm_crtc_state*crtc_state

atomic CRTC state, must not be NULL

structdrm_crtc*crtc

CRTC object, must not be NULL

Description

Initializes the newly allocatedcrtc_state with defaultvalues. This is useful for drivers that subclass the CRTC state.

void__drm_atomic_helper_crtc_reset(structdrm_crtc*crtc,structdrm_crtc_state*crtc_state)

reset state on CRTC

Parameters

structdrm_crtc*crtc

drm CRTC

structdrm_crtc_state*crtc_state

CRTC state to assign

Description

Initializes the newly allocatedcrtc_state and assigns it tothedrm_crtc->state pointer ofcrtc, usually required wheninitializing the drivers or when called from thedrm_crtc_funcs.resethook.

This is useful for drivers that subclass the CRTC state.

voiddrm_atomic_helper_crtc_reset(structdrm_crtc*crtc)

defaultdrm_crtc_funcs.reset hook for CRTCs

Parameters

structdrm_crtc*crtc

drm CRTC

Description

Resets the atomic state forcrtc by freeing the state pointer (which mightbe NULL, e.g. at driver load time) and allocating a new empty state object.

void__drm_atomic_helper_crtc_duplicate_state(structdrm_crtc*crtc,structdrm_crtc_state*state)

copy atomic CRTC state

Parameters

structdrm_crtc*crtc

CRTC object

structdrm_crtc_state*state

atomic CRTC state

Description

Copies atomic state from a CRTC’s current state and resets inferred values.This is useful for drivers that subclass the CRTC state.

structdrm_crtc_state*drm_atomic_helper_crtc_duplicate_state(structdrm_crtc*crtc)

default state duplicate hook

Parameters

structdrm_crtc*crtc

drm CRTC

Description

Default CRTC state duplicate hook for drivers which don’t have their ownsubclassed CRTC state structure.

void__drm_atomic_helper_crtc_destroy_state(structdrm_crtc_state*state)

release CRTC state

Parameters

structdrm_crtc_state*state

CRTC state object to release

Description

Releases all resources stored in the CRTC state without actually freeingthe memory of the CRTC state. This is useful for drivers that subclass theCRTC state.

voiddrm_atomic_helper_crtc_destroy_state(structdrm_crtc*crtc,structdrm_crtc_state*state)

default state destroy hook

Parameters

structdrm_crtc*crtc

drm CRTC

structdrm_crtc_state*state

CRTC state object to release

Description

Default CRTC state destroy hook for drivers which don’t have their ownsubclassed CRTC state structure.

void__drm_atomic_helper_plane_state_reset(structdrm_plane_state*plane_state,structdrm_plane*plane)

resets plane state to default values

Parameters

structdrm_plane_state*plane_state

atomic plane state, must not be NULL

structdrm_plane*plane

plane object, must not be NULL

Description

Initializes the newly allocatedplane_state with defaultvalues. This is useful for drivers that subclass the CRTC state.

void__drm_atomic_helper_plane_reset(structdrm_plane*plane,structdrm_plane_state*plane_state)

reset state on plane

Parameters

structdrm_plane*plane

drm plane

structdrm_plane_state*plane_state

plane state to assign

Description

Initializes the newly allocatedplane_state and assigns it tothedrm_crtc->state pointer ofplane, usually required wheninitializing the drivers or when called from thedrm_plane_funcs.resethook.

This is useful for drivers that subclass the plane state.

voiddrm_atomic_helper_plane_reset(structdrm_plane*plane)

defaultdrm_plane_funcs.reset hook for planes

Parameters

structdrm_plane*plane

drm plane

Description

Resets the atomic state forplane by freeing the state pointer (which mightbe NULL, e.g. at driver load time) and allocating a new empty state object.

void__drm_atomic_helper_plane_duplicate_state(structdrm_plane*plane,structdrm_plane_state*state)

copy atomic plane state

Parameters

structdrm_plane*plane

plane object

structdrm_plane_state*state

atomic plane state

Description

Copies atomic state from a plane’s current state. This is useful fordrivers that subclass the plane state.

structdrm_plane_state*drm_atomic_helper_plane_duplicate_state(structdrm_plane*plane)

default state duplicate hook

Parameters

structdrm_plane*plane

drm plane

Description

Default plane state duplicate hook for drivers which don’t have their ownsubclassed plane state structure.

void__drm_atomic_helper_plane_destroy_state(structdrm_plane_state*state)

release plane state

Parameters

structdrm_plane_state*state

plane state object to release

Description

Releases all resources stored in the plane state without actually freeingthe memory of the plane state. This is useful for drivers that subclass theplane state.

voiddrm_atomic_helper_plane_destroy_state(structdrm_plane*plane,structdrm_plane_state*state)

default state destroy hook

Parameters

structdrm_plane*plane

drm plane

structdrm_plane_state*state

plane state object to release

Description

Default plane state destroy hook for drivers which don’t have their ownsubclassed plane state structure.

void__drm_atomic_helper_connector_state_reset(structdrm_connector_state*conn_state,structdrm_connector*connector)

reset the connector state

Parameters

structdrm_connector_state*conn_state

atomic connector state, must not be NULL

structdrm_connector*connector

connectotr object, must not be NULL

Description

Initializes the newly allocatedconn_state with defaultvalues. This is useful for drivers that subclass the connector state.

void__drm_atomic_helper_connector_reset(structdrm_connector*connector,structdrm_connector_state*conn_state)

reset state on connector

Parameters

structdrm_connector*connector

drm connector

structdrm_connector_state*conn_state

connector state to assign

Description

Initializes the newly allocatedconn_state and assigns it tothedrm_connector->state pointer ofconnector, usually required wheninitializing the drivers or when called from thedrm_connector_funcs.resethook.

This is useful for drivers that subclass the connector state.

voiddrm_atomic_helper_connector_reset(structdrm_connector*connector)

defaultdrm_connector_funcs.reset hook for connectors

Parameters

structdrm_connector*connector

drm connector

Description

Resets the atomic state forconnector by freeing the state pointer (whichmight be NULL, e.g. at driver load time) and allocating a new empty stateobject.

voiddrm_atomic_helper_connector_tv_margins_reset(structdrm_connector*connector)

Resets TV connector properties

Parameters

structdrm_connector*connector

DRM connector

Description

Resets the TV-related properties attached to a connector.

voiddrm_atomic_helper_connector_tv_reset(structdrm_connector*connector)

Resets Analog TV connector properties

Parameters

structdrm_connector*connector

DRM connector

Description

Resets the analog TV properties attached to a connector

intdrm_atomic_helper_connector_tv_check(structdrm_connector*connector,structdrm_atomic_state*state)

Validate an analog TV connector state

Parameters

structdrm_connector*connector

DRM Connector

structdrm_atomic_state*state

the DRM State object

Description

Checks the state object to see if the requested state is valid for ananalog TV connector.

Return

0 for success, a negative error code on error.

void__drm_atomic_helper_connector_duplicate_state(structdrm_connector*connector,structdrm_connector_state*state)

copy atomic connector state

Parameters

structdrm_connector*connector

connector object

structdrm_connector_state*state

atomic connector state

Description

Copies atomic state from a connector’s current state. This is useful fordrivers that subclass the connector state.

structdrm_connector_state*drm_atomic_helper_connector_duplicate_state(structdrm_connector*connector)

default state duplicate hook

Parameters

structdrm_connector*connector

drm connector

Description

Default connector state duplicate hook for drivers which don’t have their ownsubclassed connector state structure.

void__drm_atomic_helper_connector_destroy_state(structdrm_connector_state*state)

release connector state

Parameters

structdrm_connector_state*state

connector state object to release

Description

Releases all resources stored in the connector state without actuallyfreeing the memory of the connector state. This is useful for drivers thatsubclass the connector state.

voiddrm_atomic_helper_connector_destroy_state(structdrm_connector*connector,structdrm_connector_state*state)

default state destroy hook

Parameters

structdrm_connector*connector

drm connector

structdrm_connector_state*state

connector state object to release

Description

Default connector state destroy hook for drivers which don’t have their ownsubclassed connector state structure.

void__drm_atomic_helper_private_obj_create_state(structdrm_private_obj*obj,structdrm_private_state*state)

initializes private object state

Parameters

structdrm_private_obj*obj

private object

structdrm_private_state*state

new state to initialize

Description

Initializes the newly allocatedstate, usually required wheninitializing the drivers.

obj is assumed to be zeroed.

This is useful for drivers that use private states.

void__drm_atomic_helper_private_obj_duplicate_state(structdrm_private_obj*obj,structdrm_private_state*state)

copy atomic private state

Parameters

structdrm_private_obj*obj

CRTC object

structdrm_private_state*state

new private object state

Description

Copies atomic state from a private objects’s current state and resets inferred values.This is useful for drivers that subclass the private state.

void__drm_atomic_helper_bridge_duplicate_state(structdrm_bridge*bridge,structdrm_bridge_state*state)

Copy atomic bridge state

Parameters

structdrm_bridge*bridge

bridge object

structdrm_bridge_state*state

atomic bridge state

Description

Copies atomic state from a bridge’s current state and resets inferred values.This is useful for drivers that subclass the bridge state.

structdrm_bridge_state*drm_atomic_helper_bridge_duplicate_state(structdrm_bridge*bridge)

Duplicate a bridge state object

Parameters

structdrm_bridge*bridge

bridge object

Description

Allocates a new bridge state and initializes it with the current bridgestate values. This helper is meant to be used as a bridgedrm_bridge_funcs.atomic_duplicate_state hook for bridges that don’tsubclass the bridge state.

voiddrm_atomic_helper_bridge_destroy_state(structdrm_bridge*bridge,structdrm_bridge_state*state)

Destroy a bridge state object

Parameters

structdrm_bridge*bridge

the bridge this state refers to

structdrm_bridge_state*state

bridge state to destroy

Description

Destroys a bridge state previously created bydrm_atomic_helper_bridge_reset`()or:c:type:`drm_atomic_helper_bridge_duplicate_state`().Thishelperismeanttobeusedasabridge:c:type:`drm_bridge_funcs.atomic_destroy_state hook for bridgesthat don’t subclass the bridge state.

void__drm_atomic_helper_bridge_reset(structdrm_bridge*bridge,structdrm_bridge_state*state)

Initialize a bridge state to its default

Parameters

structdrm_bridge*bridge

the bridge this state refers to

structdrm_bridge_state*state

bridge state to initialize

Description

Initializes the bridge state to default values. This is meant to be calledby the bridgedrm_bridge_funcs.atomic_reset hook for bridges that subclassthe bridge state.

structdrm_bridge_state*drm_atomic_helper_bridge_reset(structdrm_bridge*bridge)

Allocate and initialize a bridge state to its default

Parameters

structdrm_bridge*bridge

the bridge this state refers to

Description

Allocates the bridge state and initializes it to default values. This helperis meant to be used as a bridgedrm_bridge_funcs.atomic_reset hook forbridges that don’t subclass the bridge state.

GEM Atomic Helper Reference

The GEM atomic helpers library implements generic atomic-commitfunctions for drivers that use GEM objects. Currently, it providessynchronization helpers, and plane state and framebuffer BO mappingsfor planes with shadow buffers.

Before scanout, a plane’s framebuffer needs to be synchronized withpossible writers that draw into the framebuffer. All drivers shouldcalldrm_gem_plane_helper_prepare_fb() from their implementation ofstructdrm_plane_helper.prepare_fb . It sets the plane’s fence fromthe framebuffer so that the DRM core can synchronize access automatically.drm_gem_plane_helper_prepare_fb() can also be used directly asimplementation of prepare_fb.

#include<drm/drm_gem_atomic_helper.h>structdrm_plane_helper_funcsdriver_plane_helper_funcs={...,.prepare_fb=drm_gem_plane_helper_prepare_fb,};

A driver using a shadow buffer copies the content of the shadow buffersinto the HW’s framebuffer memory during an atomic update. This requiresa mapping of the shadow buffer into kernel address space. The mappingscannot be established by commit-tail functions, such as atomic_update,as this would violate locking rules arounddma_buf_vmap().

The helpers for shadow-buffered planes establish and release mappings,and providestructdrm_shadow_plane_state, which stores the plane’s mappingfor commit-tail functions.

Shadow-buffered planes can easily be enabled by using the provided macrosDRM_GEM_SHADOW_PLANE_FUNCS andDRM_GEM_SHADOW_PLANE_HELPER_FUNCS.These macros set up the plane and plane-helper callbacks to point to theshadow-buffer helpers.

#include<drm/drm_gem_atomic_helper.h>structdrm_plane_funcsdriver_plane_funcs={...,DRM_GEM_SHADOW_PLANE_FUNCS,};structdrm_plane_helper_funcsdriver_plane_helper_funcs={...,DRM_GEM_SHADOW_PLANE_HELPER_FUNCS,};

In the driver’s atomic-update function, shadow-buffer mappings are availablefrom the plane state. Useto_drm_shadow_plane_state() to upcast fromstructdrm_plane_state.

voiddriver_plane_atomic_update(structdrm_plane*plane,structdrm_plane_state*old_plane_state){structdrm_plane_state*plane_state=plane->state;structdrm_shadow_plane_state*shadow_plane_state=to_drm_shadow_plane_state(plane_state);// access shadow buffer via shadow_plane_state->map}

A mapping address for each of the framebuffer’s buffer object is stored instructdrm_shadow_plane_state.map. The mappings are valid while the stateis being used.

Drivers that usestructdrm_simple_display_pipe can useDRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS to initialize the rspcallbacks. Access to shadow-buffer mappings is similar to regularatomic_update.

structdrm_simple_display_pipe_funcsdriver_pipe_funcs={...,DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS,};voiddriver_pipe_enable(structdrm_simple_display_pipe*pipe,structdrm_crtc_state*crtc_state,structdrm_plane_state*plane_state){structdrm_shadow_plane_state*shadow_plane_state=to_drm_shadow_plane_state(plane_state);// access shadow buffer via shadow_plane_state->map}
DRM_SHADOW_PLANE_MAX_WIDTH

DRM_SHADOW_PLANE_MAX_WIDTH

Maximum width of a plane’s shadow buffer in pixels

Description

For drivers with shadow planes, the maximum width of the framebuffer isusually independent from hardware limitations. Drivers can initializestructdrm_mode_config.max_width from DRM_SHADOW_PLANE_MAX_WIDTH.

DRM_SHADOW_PLANE_MAX_HEIGHT

DRM_SHADOW_PLANE_MAX_HEIGHT

Maximum height of a plane’s shadow buffer in scanlines

Description

For drivers with shadow planes, the maximum height of the framebuffer isusually independent from hardware limitations. Drivers can initializestructdrm_mode_config.max_height from DRM_SHADOW_PLANE_MAX_HEIGHT.

structdrm_shadow_plane_state

plane state for planes with shadow buffers

Definition:

struct drm_shadow_plane_state {    struct drm_plane_state base;    struct drm_format_conv_state fmtcnv_state;    struct iosys_map map[DRM_FORMAT_MAX_PLANES];    struct iosys_map data[DRM_FORMAT_MAX_PLANES];};

Members

base

plane state

fmtcnv_state

Format-conversion state

Per-plane state for format conversion.Flags for copying shadow buffers into backend storage. Also holdstemporary storage for format conversion.

map

Mappings of the plane’s framebuffer BOs in to kernel address space

The memory mappings stored in map should be established in the plane’sprepare_fb callback and removed in the cleanup_fb callback.

data

Address of each framebuffer BO’s data

The address of the data stored in each mapping. This is differentfor framebuffers with non-zero offset fields.

Description

For planes that use a shadow buffer,structdrm_shadow_plane_stateprovides the regular plane state plus mappings of the shadow bufferinto kernel address space.

structdrm_shadow_plane_state*to_drm_shadow_plane_state(structdrm_plane_state*state)

upcasts fromstructdrm_plane_state

Parameters

structdrm_plane_state*state

the plane state

DRM_GEM_SHADOW_PLANE_FUNCS

DRM_GEM_SHADOW_PLANE_FUNCS

Initializesstructdrm_plane_funcs for shadow-buffered planes

Description

Drivers may use GEM BOs as shadow buffers over the framebuffer memory. Thismacro initializesstructdrm_plane_funcs to use the rsp helper functions.

DRM_GEM_SHADOW_PLANE_HELPER_FUNCS

DRM_GEM_SHADOW_PLANE_HELPER_FUNCS

Initializesstructdrm_plane_helper_funcs for shadow-buffered planes

Description

Drivers may use GEM BOs as shadow buffers over the framebuffer memory. Thismacro initializesstructdrm_plane_helper_funcs to use the rsp helperfunctions.

DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS

DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS

Initializesstructdrm_simple_display_pipe_funcs for shadow-buffered planes

Description

Drivers may use GEM BOs as shadow buffers over the framebuffer memory. Thismacro initializesstructdrm_simple_display_pipe_funcs to use the rsp helperfunctions.

intdrm_gem_plane_helper_prepare_fb(structdrm_plane*plane,structdrm_plane_state*state)

Prepare a GEM backed framebuffer

Parameters

structdrm_plane*plane

Plane

structdrm_plane_state*state

Plane state the fence will be attached to

Description

This function extracts the exclusive fence fromdrm_gem_object.resv andattaches it to plane state for the atomic helper to wait on. This isnecessary to correctly implement implicit synchronization for any buffersshared as a structdma_buf. This function can be used as thedrm_plane_helper_funcs.prepare_fb callback.

There is no need fordrm_plane_helper_funcs.cleanup_fb hook for simpleGEM based framebuffer drivers which have their buffers always pinned inmemory.

This function is the default implementation for GEM drivers ofdrm_plane_helper_funcs.prepare_fb if no callback is provided.

void__drm_gem_duplicate_shadow_plane_state(structdrm_plane*plane,structdrm_shadow_plane_state*new_shadow_plane_state)

duplicates shadow-buffered plane state

Parameters

structdrm_plane*plane

the plane

structdrm_shadow_plane_state*new_shadow_plane_state

the new shadow-buffered plane state

Description

This function duplicates shadow-buffered plane state. This is helpful for driversthat subclassstructdrm_shadow_plane_state.

The function does not duplicate existing mappings of the shadow buffers.Mappings are maintained during the atomic commit by the plane’s prepare_fband cleanup_fb helpers. Seedrm_gem_prepare_shadow_fb() anddrm_gem_cleanup_shadow_fb()for corresponding helpers.

structdrm_plane_state*drm_gem_duplicate_shadow_plane_state(structdrm_plane*plane)

duplicates shadow-buffered plane state

Parameters

structdrm_plane*plane

the plane

Description

This function implements structdrm_plane_funcs.atomic_duplicate_state forshadow-buffered planes. It assumes the existing state to be of typestructdrm_shadow_plane_state and it allocates the new state to be of thistype.

The function does not duplicate existing mappings of the shadow buffers.Mappings are maintained during the atomic commit by the plane’s prepare_fband cleanup_fb helpers. Seedrm_gem_prepare_shadow_fb() anddrm_gem_cleanup_shadow_fb()for corresponding helpers.

Return

A pointer to a new plane state on success, or NULL otherwise.

void__drm_gem_destroy_shadow_plane_state(structdrm_shadow_plane_state*shadow_plane_state)

cleans up shadow-buffered plane state

Parameters

structdrm_shadow_plane_state*shadow_plane_state

the shadow-buffered plane state

Description

This function cleans up shadow-buffered plane state. Helpful for drivers thatsubclassstructdrm_shadow_plane_state.

voiddrm_gem_destroy_shadow_plane_state(structdrm_plane*plane,structdrm_plane_state*plane_state)

deletes shadow-buffered plane state

Parameters

structdrm_plane*plane

the plane

structdrm_plane_state*plane_state

the plane state of typestructdrm_shadow_plane_state

Description

This function implements structdrm_plane_funcs.atomic_destroy_statefor shadow-buffered planes. It expects that mappings of shadow buffershave been released already.

void__drm_gem_reset_shadow_plane(structdrm_plane*plane,structdrm_shadow_plane_state*shadow_plane_state)

resets a shadow-buffered plane

Parameters

structdrm_plane*plane

the plane

structdrm_shadow_plane_state*shadow_plane_state

the shadow-buffered plane state

Description

This function resets state for shadow-buffered planes. Helpfulfor drivers that subclassstructdrm_shadow_plane_state.

voiddrm_gem_reset_shadow_plane(structdrm_plane*plane)

resets a shadow-buffered plane

Parameters

structdrm_plane*plane

the plane

Description

This function implements structdrm_plane_funcs.reset_plane forshadow-buffered planes. It assumes the current plane state to beof typestructdrm_shadow_plane and it allocates the new state ofthis type.

intdrm_gem_begin_shadow_fb_access(structdrm_plane*plane,structdrm_plane_state*plane_state)

prepares shadow framebuffers for CPU access

Parameters

structdrm_plane*plane

the plane

structdrm_plane_state*plane_state

the plane state of typestructdrm_shadow_plane_state

Description

This function implements structdrm_plane_helper_funcs.begin_fb_access. Itmaps all buffer objects of the plane’s framebuffer into kernel addressspace and stores them in structdrm_shadow_plane_state.map. The first databytes are available in structdrm_shadow_plane_state.data.

Seedrm_gem_end_shadow_fb_access() for cleanup.

Return

0 on success, or a negative errno code otherwise.

voiddrm_gem_end_shadow_fb_access(structdrm_plane*plane,structdrm_plane_state*plane_state)

releases shadow framebuffers from CPU access

Parameters

structdrm_plane*plane

the plane

structdrm_plane_state*plane_state

the plane state of typestructdrm_shadow_plane_state

Description

This function implements structdrm_plane_helper_funcs.end_fb_access. Itundoes all effects ofdrm_gem_begin_shadow_fb_access() in reverse order.

Seedrm_gem_begin_shadow_fb_access() for more information.

intdrm_gem_simple_kms_begin_shadow_fb_access(structdrm_simple_display_pipe*pipe,structdrm_plane_state*plane_state)

prepares shadow framebuffers for CPU access

Parameters

structdrm_simple_display_pipe*pipe

the simple display pipe

structdrm_plane_state*plane_state

the plane state of typestructdrm_shadow_plane_state

Description

This function implementsstructdrm_simple_display_funcs.begin_fb_access.

Seedrm_gem_begin_shadow_fb_access() for details anddrm_gem_simple_kms_cleanup_shadow_fb() for cleanup.

Return

0 on success, or a negative errno code otherwise.

voiddrm_gem_simple_kms_end_shadow_fb_access(structdrm_simple_display_pipe*pipe,structdrm_plane_state*plane_state)

releases shadow framebuffers from CPU access

Parameters

structdrm_simple_display_pipe*pipe

the simple display pipe

structdrm_plane_state*plane_state

the plane state of typestructdrm_shadow_plane_state

Description

This function implementsstructdrm_simple_display_funcs.end_fb_access.It undoes all effects ofdrm_gem_simple_kms_begin_shadow_fb_access() inreverse order.

Seedrm_gem_simple_kms_begin_shadow_fb_access().

voiddrm_gem_simple_kms_reset_shadow_plane(structdrm_simple_display_pipe*pipe)

resets a shadow-buffered plane

Parameters

structdrm_simple_display_pipe*pipe

the simple display pipe

Description

This function implementsstructdrm_simple_display_funcs.reset_planefor shadow-buffered planes.

structdrm_plane_state*drm_gem_simple_kms_duplicate_shadow_plane_state(structdrm_simple_display_pipe*pipe)

duplicates shadow-buffered plane state

Parameters

structdrm_simple_display_pipe*pipe

the simple display pipe

Description

This function implementsstructdrm_simple_display_funcs.duplicate_plane_statefor shadow-buffered planes. It does not duplicate existing mappings of the shadowbuffers. Mappings are maintained during the atomic commit by the plane’s prepare_fband cleanup_fb helpers.

Return

A pointer to a new plane state on success, or NULL otherwise.

voiddrm_gem_simple_kms_destroy_shadow_plane_state(structdrm_simple_display_pipe*pipe,structdrm_plane_state*plane_state)

resets shadow-buffered plane state

Parameters

structdrm_simple_display_pipe*pipe

the simple display pipe

structdrm_plane_state*plane_state

the plane state of typestructdrm_shadow_plane_state

Description

This function implementsstructdrm_simple_display_funcs.destroy_plane_statefor shadow-buffered planes. It expects that mappings of shadow buffershave been released already.

VBLANK Helper Reference

The vblank helper library provides functions for supporting verticalblanking in DRM drivers.

For vblank timers, several callback implementations are available.Drivers enable support for vblank timers by setting the vblank callbacksin structdrm_crtc_funcs to the helpers provided by this library. Theinitializer macro DRM_CRTC_VBLANK_TIMER_FUNCS does this conveniently.The driver further has to send the VBLANK event from its atomic_flushcallback and control vblank from the CRTC’s atomic_enable and atomic_disablecallbacks. The callbacks are located in structdrm_crtc_helper_funcs.The vblank helper library provides implementations of these callbacksfor drivers without further requirements. The initializer macroDRM_CRTC_HELPER_VBLANK_FUNCS sets them coveniently.

Once the driver enables vblank support withdrm_vblank_init(), eachCRTC’s vblank timer fires according to the programmed display mode. Bydefault, the vblank timer invokesdrm_crtc_handle_vblank(). Drivers withmore specific requirements can set their own handler function instructdrm_crtc_helper_funcs.handle_vblank_timeout.

DRM_CRTC_HELPER_VBLANK_FUNCS

DRM_CRTC_HELPER_VBLANK_FUNCS

Default implementation for VBLANK helpers

Description

This macro initializes structdrm_crtc_helper_funcs to default helpersfor VBLANK handling.

DRM_CRTC_VBLANK_TIMER_FUNCS

DRM_CRTC_VBLANK_TIMER_FUNCS

Default implementation for VBLANK timers

Description

This macro initializes structdrm_crtc_funcs to default helpers forVBLANK timers.

voiddrm_crtc_vblank_atomic_flush(structdrm_crtc*crtc,structdrm_atomic_state*state)

Implements structdrm_crtc_helper_funcs.atomic_flush

Parameters

structdrm_crtc*crtc

The CRTC

structdrm_atomic_state*state

The atomic state to apply

Description

The helperdrm_crtc_vblank_atomic_flush() implements atomic_flush ofstructdrm_crtc_helper_funcs for CRTCs that only need to send out aVBLANK event.

See also structdrm_crtc_helper_funcs.atomic_flush.

voiddrm_crtc_vblank_atomic_enable(structdrm_crtc*crtc,structdrm_atomic_state*state)

Implements structdrm_crtc_helper_funcs.atomic_enable

Parameters

structdrm_crtc*crtc

The CRTC

structdrm_atomic_state*state

The atomic state

Description

The helperdrm_crtc_vblank_atomic_enable() implements atomic_enableofstructdrm_crtc_helper_funcs for CRTCs the only need to enable VBLANKs.

See also structdrm_crtc_helper_funcs.atomic_enable.

voiddrm_crtc_vblank_atomic_disable(structdrm_crtc*crtc,structdrm_atomic_state*state)

Implements structdrm_crtc_helper_funcs.atomic_disable

Parameters

structdrm_crtc*crtc

The CRTC

structdrm_atomic_state*state

The atomic state

Description

The helperdrm_crtc_vblank_atomic_disable() implements atomic_disableofstructdrm_crtc_helper_funcs for CRTCs the only need to disable VBLANKs.

See also structdrm_crtc_funcs.atomic_disable.

intdrm_crtc_vblank_helper_enable_vblank_timer(structdrm_crtc*crtc)

Implements structdrm_crtc_funcs.enable_vblank

Parameters

structdrm_crtc*crtc

The CRTC

Description

The helperdrm_crtc_vblank_helper_enable_vblank_timer() implementsenable_vblank ofstructdrm_crtc_helper_funcs for CRTCs that requirea VBLANK timer. It sets up the timer on the first invocation. Thestarted timer expires after the current frame duration. See structdrm_vblank_crtc.framedur_ns.

See also structdrm_crtc_helper_funcs.enable_vblank.

Return

0 on success, or a negative errno code otherwise.

voiddrm_crtc_vblank_helper_disable_vblank_timer(structdrm_crtc*crtc)

Implements structdrm_crtc_funcs.disable_vblank

Parameters

structdrm_crtc*crtc

The CRTC

Description

The helperdrm_crtc_vblank_helper_disable_vblank_timer() implementsdisable_vblank ofstructdrm_crtc_funcs for CRTCs that require aVBLANK timer.

See also structdrm_crtc_helper_funcs.disable_vblank.

booldrm_crtc_vblank_helper_get_vblank_timestamp_from_timer(structdrm_crtc*crtc,int*max_error,ktime_t*vblank_time,boolin_vblank_irq)

Implements structdrm_crtc_funcs.get_vblank_timestamp

Parameters

structdrm_crtc*crtc

The CRTC

int*max_error

Maximum acceptable error

ktime_t*vblank_time

Returns the next vblank timestamp

boolin_vblank_irq

True is called fromdrm_crtc_handle_vblank()

Description

The helperdrm_crtc_helper_get_vblank_timestamp_from_timer() implementsget_vblank_timestamp ofstructdrm_crtc_funcs for CRTCs that require aVBLANK timer. It returns the timestamp according to the timer’s expirytime.

See also structdrm_crtc_funcs.get_vblank_timestamp.

Return

True on success, or false otherwise.

Simple KMS Helper Reference

This helper library provides helpers for drivers for simple displayhardware.

drm_simple_display_pipe_init() initializes a simple display pipelinewhich has only one full-screen scanout buffer feeding one output. Thepipeline is represented bystructdrm_simple_display_pipe and bindstogetherdrm_plane,drm_crtc anddrm_encoder structures into one fixedentity. Some flexibility for code reuse is provided through a separatelyallocateddrm_connector object and supporting optionaldrm_bridgeencoder drivers.

Many drivers require only a very simple encoder that fulfills the minimumrequirements of the display pipeline and does not add additionalfunctionality. The functiondrm_simple_encoder_init() provides animplementation of such an encoder.

structdrm_simple_display_pipe_funcs

helper operations for a simple display pipeline

Definition:

struct drm_simple_display_pipe_funcs {    enum drm_mode_status (*mode_valid)(struct drm_simple_display_pipe *pipe, const struct drm_display_mode *mode);    void (*enable)(struct drm_simple_display_pipe *pipe, struct drm_crtc_state *crtc_state, struct drm_plane_state *plane_state);    void (*disable)(struct drm_simple_display_pipe *pipe);    int (*check)(struct drm_simple_display_pipe *pipe, struct drm_plane_state *plane_state, struct drm_crtc_state *crtc_state);    void (*update)(struct drm_simple_display_pipe *pipe, struct drm_plane_state *old_plane_state);    int (*prepare_fb)(struct drm_simple_display_pipe *pipe, struct drm_plane_state *plane_state);    void (*cleanup_fb)(struct drm_simple_display_pipe *pipe, struct drm_plane_state *plane_state);    int (*begin_fb_access)(struct drm_simple_display_pipe *pipe, struct drm_plane_state *new_plane_state);    void (*end_fb_access)(struct drm_simple_display_pipe *pipe, struct drm_plane_state *plane_state);    int (*enable_vblank)(struct drm_simple_display_pipe *pipe);    void (*disable_vblank)(struct drm_simple_display_pipe *pipe);    void (*reset_crtc)(struct drm_simple_display_pipe *pipe);    struct drm_crtc_state * (*duplicate_crtc_state)(struct drm_simple_display_pipe *pipe);    void (*destroy_crtc_state)(struct drm_simple_display_pipe *pipe, struct drm_crtc_state *crtc_state);    void (*reset_plane)(struct drm_simple_display_pipe *pipe);    struct drm_plane_state * (*duplicate_plane_state)(struct drm_simple_display_pipe *pipe);    void (*destroy_plane_state)(struct drm_simple_display_pipe *pipe, struct drm_plane_state *plane_state);};

Members

mode_valid

This callback is used to check if a specific mode is valid in thecrtc used in this simple display pipe. This should be implementedif the display pipe has some sort of restriction in the modesit can display. For example, a given display pipe may be responsibleto set a clock value. If the clock can not produce all the valuesfor the available modes then this callback can be used to restrictthe number of modes to only the ones that can be displayed. Anotherreason can be bandwidth mitigation: the memory port on the displaycontroller can have bandwidth limitations not allowing pixel datato be fetched at any rate.

This hook is used by the probe helpers to filter the mode list indrm_helper_probe_single_connector_modes(), and it is used by theatomic helpers to validate modes supplied by userspace indrm_atomic_helper_check_modeset().

This function is optional.

NOTE:

Since this function is both called from the check phase of an atomiccommit, and the mode validation in the probe paths it is not allowedto look at anything else but the passed-in mode, and validate itagainst configuration-invariant hardware constraints.

RETURNS:

drm_mode_status Enum

enable

This function should be used to enable the pipeline.It is called when the underlying crtc is enabled.This hook is optional.

disable

This function should be used to disable the pipeline.It is called when the underlying crtc is disabled.This hook is optional.

check

This function is called in the check phase of an atomic update,specifically when the underlying plane is checked.The simple display pipeline helpers already check that the plane isnot scaled, fills the entire visible area and is always enabledwhen the crtc is also enabled.This hook is optional.

RETURNS:

0 on success, -EINVAL if the state or the transition can’t besupported, -ENOMEM on memory allocation failure and -EDEADLK if anattempt to obtain another state object ran into adrm_modeset_lockdeadlock.

update

This function is called when the underlying plane state is updated.This hook is optional.

This is the function drivers should submit thedrm_pending_vblank_event from. Using eitherdrm_crtc_arm_vblank_event(), when the driver supports vblankinterrupt handling, ordrm_crtc_send_vblank_event() for morecomplex case. In case the hardware lacks vblank support entirely,drivers can setstructdrm_crtc_state.no_vblank instructdrm_simple_display_pipe_funcs.check and let DRM’satomic helper fake a vblank event.

prepare_fb

Optional, called bydrm_plane_helper_funcs.prepare_fb. Please readthe documentation for thedrm_plane_helper_funcs.prepare_fb hook formore details.

For GEM drivers who neither have aprepare_fb norcleanup_fb hookset,drm_gem_plane_helper_prepare_fb() is called automaticallyto implement this. Other drivers which need additional planeprocessing can calldrm_gem_plane_helper_prepare_fb() fromtheirprepare_fb hook.

cleanup_fb

Optional, called bydrm_plane_helper_funcs.cleanup_fb. Please readthe documentation for thedrm_plane_helper_funcs.cleanup_fb hook formore details.

begin_fb_access

Optional, called bydrm_plane_helper_funcs.begin_fb_access. Please readthe documentation for thedrm_plane_helper_funcs.begin_fb_access hook formore details.

end_fb_access

Optional, called bydrm_plane_helper_funcs.end_fb_access. Please readthe documentation for thedrm_plane_helper_funcs.end_fb_access hook formore details.

enable_vblank

Optional, called bydrm_crtc_funcs.enable_vblank. Please readthe documentation for thedrm_crtc_funcs.enable_vblank hook formore details.

disable_vblank

Optional, called bydrm_crtc_funcs.disable_vblank. Please readthe documentation for thedrm_crtc_funcs.disable_vblank hook formore details.

reset_crtc

Optional, called bydrm_crtc_funcs.reset. Please read thedocumentation for thedrm_crtc_funcs.reset hook for more details.

duplicate_crtc_state

Optional, called bydrm_crtc_funcs.atomic_duplicate_state. Pleaseread the documentation for thedrm_crtc_funcs.atomic_duplicate_statehook for more details.

destroy_crtc_state

Optional, called bydrm_crtc_funcs.atomic_destroy_state. Pleaseread the documentation for thedrm_crtc_funcs.atomic_destroy_statehook for more details.

reset_plane

Optional, called bydrm_plane_funcs.reset. Please read thedocumentation for thedrm_plane_funcs.reset hook for more details.

duplicate_plane_state

Optional, called bydrm_plane_funcs.atomic_duplicate_state. Pleaseread the documentation for thedrm_plane_funcs.atomic_duplicate_statehook for more details.

destroy_plane_state

Optional, called bydrm_plane_funcs.atomic_destroy_state. Pleaseread the documentation for thedrm_plane_funcs.atomic_destroy_statehook for more details.

structdrm_simple_display_pipe

simple display pipeline

Definition:

struct drm_simple_display_pipe {    struct drm_crtc crtc;    struct drm_plane plane;    struct drm_encoder encoder;    struct drm_connector *connector;    const struct drm_simple_display_pipe_funcs *funcs;};

Members

crtc

CRTC control structure

plane

Plane control structure

encoder

Encoder control structure

connector

Connector control structure

funcs

Pipeline control functions (optional)

Description

Simple display pipeline with plane, crtc and encoder collapsed into oneentity. It should be initialized by callingdrm_simple_display_pipe_init().

drmm_simple_encoder_alloc

drmm_simple_encoder_alloc(dev,type,member,encoder_type)

Allocate and initialize an encoder with basic functionality.

Parameters

dev

drm device

type

the type of thestructwhich contains structdrm_encoder

member

the name of thedrm_encoder withintype.

encoder_type

user visible type of the encoder

Description

Allocates and initializes an encoder that has no further functionality.Settings for possible CRTC and clones are left to their initial values.Cleanup is automatically handled through registeringdrm_encoder_cleanup()withdrmm_add_action().

Return

Pointer to new encoder, or ERR_PTR on failure.

intdrm_simple_encoder_init(structdrm_device*dev,structdrm_encoder*encoder,intencoder_type)

Initialize a preallocated encoder with basic functionality.

Parameters

structdrm_device*dev

drm device

structdrm_encoder*encoder

the encoder to initialize

intencoder_type

user visible type of the encoder

Description

Initialises a preallocated encoder that has no further functionality.Settings for possible CRTC and clones are left to their initial values.The encoder will be cleaned up automatically as part of the mode-settingcleanup.

The caller ofdrm_simple_encoder_init() is responsible for freeingthe encoder’s memory after the encoder has been cleaned up. At themoment this only works reliably if the encoder data structure isstored in the device structure. Free the encoder’s memory as part ofthe device release function.

Note

consider usingdrmm_simple_encoder_alloc() instead ofdrm_simple_encoder_init() to let the DRM managed resource infrastructuretake care of cleanup and deallocation.

Return

Zero on success, error code on failure.

intdrm_simple_display_pipe_attach_bridge(structdrm_simple_display_pipe*pipe,structdrm_bridge*bridge)

Attach a bridge to the display pipe

Parameters

structdrm_simple_display_pipe*pipe

simple display pipe object

structdrm_bridge*bridge

bridge to attach

Description

Makes it possible to still use the drm_simple_display_pipe helpers whena DRM bridge has to be used.

Note that you probably want to initialize the pipe by passing a NULLconnector todrm_simple_display_pipe_init().

Return

Zero on success, negative error code on failure.

intdrm_simple_display_pipe_init(structdrm_device*dev,structdrm_simple_display_pipe*pipe,conststructdrm_simple_display_pipe_funcs*funcs,constuint32_t*formats,unsignedintformat_count,constuint64_t*format_modifiers,structdrm_connector*connector)

Initialize a simple display pipeline

Parameters

structdrm_device*dev

DRM device

structdrm_simple_display_pipe*pipe

simple display pipe object to initialize

conststructdrm_simple_display_pipe_funcs*funcs

callbacks for the display pipe (optional)

constuint32_t*formats

array of supported formats (DRM_FORMAT_*)

unsignedintformat_count

number of elements informats

constuint64_t*format_modifiers

array of formats modifiers

structdrm_connector*connector

connector to attach and register (optional)

Description

Sets up a display pipeline which consist of a really simpleplane-crtc-encoder pipe.

If a connector is supplied, the pipe will be coupled with the providedconnector. You may supply a NULL connector when using drm bridges, thathandle connectors themselves (seedrm_simple_display_pipe_attach_bridge()).

Teardown of a simple display pipe is all handled automatically by the drmcore through callingdrm_mode_config_cleanup(). Drivers afterwards need torelease the memory for the structure themselves.

Return

Zero on success, negative error code on failure.

fbdev Helper Functions Reference

The fb helper functions are useful to provide an fbdev on top of a drm kernelmode setting driver. They can be used mostly independently from the crtchelper functions used by many drivers to implement the kernel mode settinginterfaces. Drivers that use one of the shared memory managers, TTM, SHMEM,DMA, should instead use the corresponding fbdev emulation.

For suspend/resume consider usingdrm_mode_config_helper_suspend() anddrm_mode_config_helper_resume() which takes care of fbdev as well.

All other functions exported by the fb helper library can be used toimplement the fbdev driver interface by the driver.

It is possible, though perhaps somewhat tricky, to implement race-freehotplug detection using the fbdev helpers. Thedrm_fb_helper_prepare()helper must be called first to initialize the minimum required to makehotplug detection work. Drivers also need to make sure to properly set upthedrm_mode_config.funcs member. After callingdrm_kms_helper_poll_init()it is safe to enable interrupts and start processing hotplug events. At thesame time, drivers should initialize all modeset objects such as CRTCs,encoders and connectors. To finish up the fbdev helper initialization, thedrm_fb_helper_init() function is called. To probe for all attached displaysand set up an initial configuration using the detected hardware, driversshould calldrm_fb_helper_initial_config().

Ifdrm_framebuffer_funcs.dirty is set, thedrm_fb_helper_{cfb,sys}_{write,fillrect,copyarea,imageblit} functions willaccumulate changes and scheduledrm_fb_helper.dirty_work to run rightaway. This worker then calls thedirty() function ensuring that it willalways run in process context since the fb_*() function could be running inatomic context. Ifdrm_fb_helper_deferred_io() is used as the deferred_iocallback it will also schedule dirty_work with the damage collected from themmap page writes.

structdrm_fb_helper_surface_size

describes fbdev size and scanout surface size

Definition:

struct drm_fb_helper_surface_size {    u32 fb_width;    u32 fb_height;    u32 surface_width;    u32 surface_height;    u32 surface_bpp;    u32 surface_depth;};

Members

fb_width

fbdev width

fb_height

fbdev height

surface_width

scanout buffer width

surface_height

scanout buffer height

surface_bpp

scanout buffer bpp

surface_depth

scanout buffer depth

Description

Note that the scanout surface width/height may be larger than the fbdevwidth/height. In case of multiple displays, the scanout surface is sizedaccording to the largest width/height (so it is large enough for all CRTCsto scanout). But the fbdev width/height is sized to the minimum width/height of all the displays. This ensures that fbcon fits on the smallestof the attached displays. fb_width/fb_height is used bydrm_fb_helper_fill_info() to fill out thefb_info.var structure.

structdrm_fb_helper_funcs

driver callbacks for the fbdev emulation library

Definition:

struct drm_fb_helper_funcs {    int (*fb_dirty)(struct drm_fb_helper *helper, struct drm_clip_rect *clip);    void (*fb_restore)(struct drm_fb_helper *helper);    void (*fb_set_suspend)(struct drm_fb_helper *helper, bool suspend);};

Members

fb_dirty

Driver callback to update the framebuffer memory. If set, fbdevemulation will invoke this callback in regular intervals afterthe framebuffer has been written.

This callback is optional.

Returns:0 on success, or an error code otherwise.

fb_restore

Driver callback to restore internal fbdev state. If set, fbdevemulation will invoke this callback after restoring the displaymode.

Only for i915. Do not use in new code.

TODO: Fix i915 to not require this callback.

fb_set_suspend

Driver callback to suspend or resume, if set, fbdev emulation willinvoke this callback during suspend and resume. Driver should callfb_set_suspend() from their implementation. If not set, fbdevemulation will invokefb_set_suspend() directly.

Only for i915. Do not use in new code.

TODO: Fix i915 to not require this callback.

Description

Driver callbacks used by the fbdev emulation helper library.

structdrm_fb_helper

main structure to emulate fbdev on top of KMS

Definition:

struct drm_fb_helper {    struct drm_client_dev client;    struct drm_client_buffer *buffer;    struct drm_framebuffer *fb;    struct drm_device *dev;    const struct drm_fb_helper_funcs *funcs;    struct fb_info *info;    u32 pseudo_palette[17];    struct drm_clip_rect damage_clip;    spinlock_t damage_lock;    struct work_struct damage_work;    struct work_struct resume_work;    struct mutex lock;    bool delayed_hotplug;    bool deferred_setup;    int preferred_bpp;#ifdef CONFIG_FB_DEFERRED_IO;    struct fb_deferred_io fbdefio;#endif;};

Members

client

DRM client used by the generic fbdev emulation.

buffer

Framebuffer used by the generic fbdev emulation.

fb

Scanout framebuffer object

dev

DRM device

funcs

driver callbacks for fb helper

info

emulated fbdev device info struct

pseudo_palette

fake palette of 16 colors

damage_clip

clip rectangle used with deferred_io to accumulate damage tothe screen buffer

damage_lock

spinlock protectingdamage_clip

damage_work

worker used to flush the framebuffer

resume_work

worker used during resume if the console lock is already taken

lock

Top-level FBDEV helper lock. This protects all internal datastructures and lists, such asconnector_info andcrtc_info.

FIXME: fbdev emulation locking is a mess and long term we want toprotect all helper internal state with this lock as well as reducecore KMS locking as much as possible.

delayed_hotplug

A hotplug was received while fbdev wasn’t in control of the DRMdevice, i.e. another KMS master was active. The output configurationneeds to be reprobe when fbdev is in control again.

deferred_setup

If no outputs are connected (disconnected or unknown) the FB helpercode will defer setup until at least one of the outputs shows up.This field keeps track of the status so that setup can be retriedat every hotplug event until it succeeds eventually.

Protected bylock.

preferred_bpp

Temporary storage for the driver’s preferred BPP setting passed toFB helper initialization. This needs to be tracked so that deferredFB helper setup can pass this on.

See also:deferred_setup

fbdefio

Temporary storage for the driver’s FB deferred I/O handler. If thedriver uses the DRM fbdev emulation layer, this is set by the coreto a generic deferred I/O handler if a driver is preferring to usea shadow buffer.

Description

This is the main structure used by the fbdev helpers. Drivers supportingfbdev emulation should embedded this into their overall driver structure.Drivers must also fill out astructdrm_fb_helper_funcs with a fewoperations.

DRM_FB_HELPER_DEFAULT_OPS

DRM_FB_HELPER_DEFAULT_OPS

helper define for drm drivers

Description

Helper define to register default implementations of drm_fb_helperfunctions. To be used instructfb_ops of drm drivers.

intdrm_fb_helper_restore_fbdev_mode_unlocked(structdrm_fb_helper*fb_helper,boolforce)

restore fbdev configuration

Parameters

structdrm_fb_helper*fb_helper

driver-allocated fbdev helper, can be NULL

boolforce

ignore present DRM master

Description

This helper should be called from fbdev emulation’sdrm_client_funcs.restorecallback. It ensures that the user isn’t greeted with a black screen when theuserspace compositor releases the display device.

Return

0 on success, or a negative errno code otherwise.

intdrm_fb_helper_blank(intblank,structfb_info*info)

implementation forfb_ops.fb_blank

Parameters

intblank

desired blanking state

structfb_info*info

fbdev registered by the helper

voiddrm_fb_helper_prepare(structdrm_device*dev,structdrm_fb_helper*helper,unsignedintpreferred_bpp,conststructdrm_fb_helper_funcs*funcs)

setup a drm_fb_helper structure

Parameters

structdrm_device*dev

DRM device

structdrm_fb_helper*helper

driver-allocated fbdev helper structure to set up

unsignedintpreferred_bpp

Preferred bits per pixel for the device.

conststructdrm_fb_helper_funcs*funcs

pointer to structure of functions associate with this helper

Description

Sets up the bare minimum to make the framebuffer helper usable. This isuseful to implement race-free initialization of the polling helpers.

voiddrm_fb_helper_unprepare(structdrm_fb_helper*fb_helper)

clean up a drm_fb_helper structure

Parameters

structdrm_fb_helper*fb_helper

driver-allocated fbdev helper structure to set up

Description

Cleans up the framebuffer helper. Inverse ofdrm_fb_helper_prepare().

intdrm_fb_helper_init(structdrm_device*dev,structdrm_fb_helper*fb_helper)

initialize astructdrm_fb_helper

Parameters

structdrm_device*dev

drm device

structdrm_fb_helper*fb_helper

driver-allocated fbdev helper structure to initialize

Description

This allocates the structures for the fbdev helper with the given limits.Note that this won’t yet touch the hardware (through the driver interfaces)nor register the fbdev. This is only done indrm_fb_helper_initial_config()to allow driver writes more control over the exact init sequence.

Drivers must calldrm_fb_helper_prepare() before calling this function.

Return

Zero if everything went ok, nonzero otherwise.

voiddrm_fb_helper_unregister_info(structdrm_fb_helper*fb_helper)

unregister fb_info framebuffer device

Parameters

structdrm_fb_helper*fb_helper

driver-allocated fbdev helper, must not be NULL

Description

A wrapper around unregister_framebuffer, to release the fb_infoframebuffer device. This must be called before releasing all resources forfb_helper by callingdrm_fb_helper_fini().

voiddrm_fb_helper_fini(structdrm_fb_helper*fb_helper)

finialize astructdrm_fb_helper

Parameters

structdrm_fb_helper*fb_helper

driver-allocated fbdev helper, can be NULL

Description

This cleans up all remaining resources associated withfb_helper.

voiddrm_fb_helper_deferred_io(structfb_info*info,structlist_head*pagereflist)

fbdev deferred_io callback function

Parameters

structfb_info*info

fb_infostructpointer

structlist_head*pagereflist

list of mmap framebuffer pages that have to be flushed

Description

This function is used as thefb_deferred_io.deferred_iocallback function for flushing the fbdev mmap writes.

voiddrm_fb_helper_set_suspend(structdrm_fb_helper*fb_helper,boolsuspend)

wrapper around fb_set_suspend

Parameters

structdrm_fb_helper*fb_helper

driver-allocated fbdev helper, can be NULL

boolsuspend

whether to suspend or resume

Description

A wrapper around fb_set_suspend implemented by fbdev core.Usedrm_fb_helper_set_suspend_unlocked() if you don’t need to takethe lock yourself

voiddrm_fb_helper_set_suspend_unlocked(structdrm_fb_helper*fb_helper,boolsuspend)

wrapper around fb_set_suspend that also takes the console lock

Parameters

structdrm_fb_helper*fb_helper

driver-allocated fbdev helper, can be NULL

boolsuspend

whether to suspend or resume

Description

A wrapper aroundfb_set_suspend() that takes the console lock. If the lockisn’t available on resume, a worker is tasked with waiting for the lockto become available. The console lock can be pretty contented on resumedue to all the printk activity.

This function can be called multiple times with the same state sincefb_info.state is checked to see if fbdev is running or not before locking.

Usedrm_fb_helper_set_suspend() if you need to take the lock yourself.

intdrm_fb_helper_setcmap(structfb_cmap*cmap,structfb_info*info)

implementation forfb_ops.fb_setcmap

Parameters

structfb_cmap*cmap

cmap to set

structfb_info*info

fbdev registered by the helper

intdrm_fb_helper_ioctl(structfb_info*info,unsignedintcmd,unsignedlongarg)

legacy ioctl implementation

Parameters

structfb_info*info

fbdev registered by the helper

unsignedintcmd

ioctl command

unsignedlongarg

ioctl argument

Description

A helper to implement the standard fbdev ioctl. OnlyFBIO_WAITFORVSYNC is implemented for now.

intdrm_fb_helper_check_var(structfb_var_screeninfo*var,structfb_info*info)

implementation forfb_ops.fb_check_var

Parameters

structfb_var_screeninfo*var

screeninfo to check

structfb_info*info

fbdev registered by the helper

intdrm_fb_helper_set_par(structfb_info*info)

implementation forfb_ops.fb_set_par

Parameters

structfb_info*info

fbdev registered by the helper

Description

This will let fbcon do the mode init and is called at initialization time bythe fbdev core when registering the driver, and later on through the hotplugcallback.

intdrm_fb_helper_pan_display(structfb_var_screeninfo*var,structfb_info*info)

implementation forfb_ops.fb_pan_display

Parameters

structfb_var_screeninfo*var

updated screen information

structfb_info*info

fbdev registered by the helper

voiddrm_fb_helper_fill_info(structfb_info*info,structdrm_fb_helper*fb_helper,structdrm_fb_helper_surface_size*sizes)

initializes fbdev information

Parameters

structfb_info*info

fbdev instance to set up

structdrm_fb_helper*fb_helper

fb helper instance to use as template

structdrm_fb_helper_surface_size*sizes

describes fbdev size and scanout surface size

Description

Sets up the variable and fixed fbdev metainformation from the given fb helperinstance and the drm framebuffer allocated indrm_fb_helper.fb.

Drivers should call this (or their equivalent setup code) from theirdrm_driver.fbdev_probe callback after having allocated the fbdevbacking storage framebuffer.

intdrm_fb_helper_initial_config(structdrm_fb_helper*fb_helper)

setup a sane initial connector configuration

Parameters

structdrm_fb_helper*fb_helper

fb_helper device struct

Description

Scans the CRTCs and connectors and tries to put together an initial setup.At the moment, this is a cloned configuration across all heads witha new framebuffer object as the backing store.

Note that this also registers the fbdev and so allows userspace to call intothe driver through the fbdev interfaces.

This function will call down into thedrm_driver.fbdev_probe callbackto let the driver allocate and initialize the fbdev info structure and thedrm framebuffer used to back the fbdev.drm_fb_helper_fill_info() is providedas a helper to setup simple default values for the fbdev info structure.

HANG DEBUGGING:

When you have fbcon support built-in or already loaded, this function will doa full modeset to setup the fbdev console. Due to locking misdesign in theVT/fbdev subsystem that entire modeset sequence has to be done while holdingconsole_lock. Until console_unlock is called no dmesg lines will be sent outto consoles, not even serial console. This means when your driver crashes,you will see absolutely nothing else but a system stuck in this function,with no further output. Any kind ofprintk() you place within your own driveror in the drm core modeset code will also never show up.

Standard debug practice is to run the fbcon setup without taking theconsole_lock as a hack, to be able to see backtraces and crashes on theserial line. This can be done by setting the fb.lockless_register_fb=1 kernelcmdline option.

The other option is to just disable fbdev emulation since very likely thefirst modeset from userspace will crash in the same way, and is even easierto debug. This can be done by setting the drm_kms_helper.fbdev_emulation=0kernel cmdline option.

Return

Zero if everything went ok, nonzero otherwise.

intdrm_fb_helper_hotplug_event(structdrm_fb_helper*fb_helper)

respond to a hotplug notification by probing all the outputs attached to the fb

Parameters

structdrm_fb_helper*fb_helper

driver-allocated fbdev helper, can be NULL

Description

Scan the connectors attached to the fb_helper and try to put together asetup after notification of a change in output configuration.

Called at runtime, takes the mode config locks to be able to check/change themodeset configuration. Must be run from process context (which usually meanseither the output polling work or a work item launched from the driver’shotplug interrupt).

Note that drivers may call this even before callingdrm_fb_helper_initial_config but only after drm_fb_helper_init. This allowsfor a race-free fbcon setup and will make sure that the fbdev emulation willnot miss any hotplug events.

Return

0 on success and a non-zero error code otherwise.

format Helper Functions Reference

voiddrm_format_conv_state_init(structdrm_format_conv_state*state)

Initialize format-conversion state

Parameters

structdrm_format_conv_state*state

The state to initialize

Description

Clears all fields instructdrm_format_conv_state. The state willbe empty with no preallocated resources.

voiddrm_format_conv_state_copy(structdrm_format_conv_state*state,conststructdrm_format_conv_state*old_state)

Copy format-conversion state

Parameters

structdrm_format_conv_state*state

Destination state

conststructdrm_format_conv_state*old_state

Source state

Description

Copies format-conversion state fromold_state tostate; except fortemporary storage.

void*drm_format_conv_state_reserve(structdrm_format_conv_state*state,size_tnew_size,gfp_tflags)

Allocates storage for format conversion

Parameters

structdrm_format_conv_state*state

The format-conversion state

size_tnew_size

The minimum allocation size

gfp_tflags

Flags forkmalloc()

Description

Allocates at leastnew_size bytes and returns a pointer to the memoryrange. After calling this function, previously returned memory blocksare invalid. It’s best to collect all memory requirements of a formatconversion and call this function once to allocate the range.

Return

A pointer to the allocated memory range, or NULL otherwise.

voiddrm_format_conv_state_release(structdrm_format_conv_state*state)

Releases an format-conversion storage

Parameters

structdrm_format_conv_state*state

The format-conversion state

Description

Releases the memory range references by the format-conversion state.After this call, all pointers to the memory are invalid. Preferdrm_format_conv_state_init() for cleaning up and unloading a driver.

unsignedintdrm_fb_clip_offset(unsignedintpitch,conststructdrm_format_info*format,conststructdrm_rect*clip)

Returns the clipping rectangles byte-offset in a framebuffer

Parameters

unsignedintpitch

Framebuffer line pitch in byte

conststructdrm_format_info*format

Framebuffer format

conststructdrm_rect*clip

Clip rectangle

Return

The byte offset of the clip rectangle’s top-left corner within the framebuffer.

voiddrm_fb_memcpy(structiosys_map*dst,constunsignedint*dst_pitch,conststructiosys_map*src,conststructdrm_framebuffer*fb,conststructdrm_rect*clip)

Copy clip buffer

Parameters

structiosys_map*dst

Array of destination buffers

constunsignedint*dst_pitch

Array of numbers of bytes between the start of two consecutive scanlineswithindst; can be NULL if scanlines are stored next to each other.

conststructiosys_map*src

Array of source buffers

conststructdrm_framebuffer*fb

DRM framebuffer

conststructdrm_rect*clip

Clip rectangle area to copy

Description

This function copies parts of a framebuffer to display memory. Destination andframebuffer formats must match. No conversion takes place. The parametersdst,dst_pitch andsrc refer to arrays. Each array must have at least as many entriesas there are planes infb’s format. Each entry stores the value for the format’srespective color plane at the same index.

This function does not apply clipping ondst (i.e. the destination is at thetop-left corner).

voiddrm_fb_swab(structiosys_map*dst,constunsignedint*dst_pitch,conststructiosys_map*src,conststructdrm_framebuffer*fb,conststructdrm_rect*clip,boolcached,structdrm_format_conv_state*state)

Swap bytes into clip buffer

Parameters

structiosys_map*dst

Array of destination buffers

constunsignedint*dst_pitch

Array of numbers of bytes between the start of two consecutive scanlineswithindst; can be NULL if scanlines are stored next to each other.

conststructiosys_map*src

Array of source buffers

conststructdrm_framebuffer*fb

DRM framebuffer

conststructdrm_rect*clip

Clip rectangle area to copy

boolcached

Source buffer is mapped cached (eg. not write-combined)

structdrm_format_conv_state*state

Transform and conversion state

Description

This function copies parts of a framebuffer to display memory and swaps per-pixelbytes during the process. Destination and framebuffer formats must match. Theparametersdst,dst_pitch andsrc refer to arrays. Each array must have atleast as many entries as there are planes infb’s format. Each entry stores thevalue for the format’s respective color plane at the same index. Ifcached isfalse a temporary buffer is used to cache one pixel line at a time to speed upslow uncached reads.

This function does not apply clipping ondst (i.e. the destination is at thetop-left corner).

voiddrm_fb_xrgb8888_to_rgb332(structiosys_map*dst,constunsignedint*dst_pitch,conststructiosys_map*src,conststructdrm_framebuffer*fb,conststructdrm_rect*clip,structdrm_format_conv_state*state)

Convert XRGB8888 to RGB332 clip buffer

Parameters

structiosys_map*dst

Array of RGB332 destination buffers

constunsignedint*dst_pitch

Array of numbers of bytes between the start of two consecutive scanlineswithindst; can be NULL if scanlines are stored next to each other.

conststructiosys_map*src

Array of XRGB8888 source buffers

conststructdrm_framebuffer*fb

DRM framebuffer

conststructdrm_rect*clip

Clip rectangle area to copy

structdrm_format_conv_state*state

Transform and conversion state

Description

This function copies parts of a framebuffer to display memory and converts thecolor format during the process. Destination and framebuffer formats must match. Theparametersdst,dst_pitch andsrc refer to arrays. Each array must have atleast as many entries as there are planes infb’s format. Each entry stores thevalue for the format’s respective color plane at the same index.

This function does not apply clipping ondst (i.e. the destination is at thetop-left corner).

Drivers can use this function for RGB332 devices that don’t support XRGB8888 natively.

voiddrm_fb_xrgb8888_to_rgb565(structiosys_map*dst,constunsignedint*dst_pitch,conststructiosys_map*src,conststructdrm_framebuffer*fb,conststructdrm_rect*clip,structdrm_format_conv_state*state)

Convert XRGB8888 to RGB565 clip buffer

Parameters

structiosys_map*dst

Array of RGB565 destination buffers

constunsignedint*dst_pitch

Array of numbers of bytes between the start of two consecutive scanlineswithindst; can be NULL if scanlines are stored next to each other.

conststructiosys_map*src

Array of XRGB8888 source buffer

conststructdrm_framebuffer*fb

DRM framebuffer

conststructdrm_rect*clip

Clip rectangle area to copy

structdrm_format_conv_state*state

Transform and conversion state

Description

This function copies parts of a framebuffer to display memory and converts thecolor format during the process. Destination and framebuffer formats must match. Theparametersdst,dst_pitch andsrc refer to arrays. Each array must have atleast as many entries as there are planes infb’s format. Each entry stores thevalue for the format’s respective color plane at the same index.

This function does not apply clipping ondst (i.e. the destination is at thetop-left corner).

Drivers can use this function for RGB565 devices that don’t support XRGB8888 natively.

voiddrm_fb_xrgb8888_to_rgb565be(structiosys_map*dst,constunsignedint*dst_pitch,conststructiosys_map*src,conststructdrm_framebuffer*fb,conststructdrm_rect*clip,structdrm_format_conv_state*state)

Convert XRGB8888 to RGB565|DRM_FORMAT_BIG_ENDIAN clip buffer

Parameters

structiosys_map*dst

Array of RGB565BE destination buffers

constunsignedint*dst_pitch

Array of numbers of bytes between the start of two consecutive scanlineswithindst; can be NULL if scanlines are stored next to each other.

conststructiosys_map*src

Array of XRGB8888 source buffer

conststructdrm_framebuffer*fb

DRM framebuffer

conststructdrm_rect*clip

Clip rectangle area to copy

structdrm_format_conv_state*state

Transform and conversion state

Description

This function copies parts of a framebuffer to display memory and converts thecolor format during the process. Destination and framebuffer formats must match. Theparametersdst,dst_pitch andsrc refer to arrays. Each array must have atleast as many entries as there are planes infb’s format. Each entry stores thevalue for the format’s respective color plane at the same index.

This function does not apply clipping ondst (i.e. the destination is at thetop-left corner).

Drivers can use this function for RGB565BE devices that don’t support XRGB8888 natively.

voiddrm_fb_xrgb8888_to_xrgb1555(structiosys_map*dst,constunsignedint*dst_pitch,conststructiosys_map*src,conststructdrm_framebuffer*fb,conststructdrm_rect*clip,structdrm_format_conv_state*state)

Convert XRGB8888 to XRGB1555 clip buffer

Parameters

structiosys_map*dst

Array of XRGB1555 destination buffers

constunsignedint*dst_pitch

Array of numbers of bytes between the start of two consecutive scanlineswithindst; can be NULL if scanlines are stored next to each other.

conststructiosys_map*src

Array of XRGB8888 source buffer

conststructdrm_framebuffer*fb

DRM framebuffer

conststructdrm_rect*clip

Clip rectangle area to copy

structdrm_format_conv_state*state

Transform and conversion state

Description

This function copies parts of a framebuffer to display memory and convertsthe color format during the process. The parametersdst,dst_pitch andsrc refer to arrays. Each array must have at least as many entries asthere are planes infb’s format. Each entry stores the value for theformat’s respective color plane at the same index.

This function does not apply clipping ondst (i.e. the destination is at thetop-left corner).

Drivers can use this function for XRGB1555 devices that don’t supportXRGB8888 natively.

voiddrm_fb_xrgb8888_to_argb1555(structiosys_map*dst,constunsignedint*dst_pitch,conststructiosys_map*src,conststructdrm_framebuffer*fb,conststructdrm_rect*clip,structdrm_format_conv_state*state)

Convert XRGB8888 to ARGB1555 clip buffer

Parameters

structiosys_map*dst

Array of ARGB1555 destination buffers

constunsignedint*dst_pitch

Array of numbers of bytes between the start of two consecutive scanlineswithindst; can be NULL if scanlines are stored next to each other.

conststructiosys_map*src

Array of XRGB8888 source buffer

conststructdrm_framebuffer*fb

DRM framebuffer

conststructdrm_rect*clip

Clip rectangle area to copy

structdrm_format_conv_state*state

Transform and conversion state

Description

This function copies parts of a framebuffer to display memory and convertsthe color format during the process. The parametersdst,dst_pitch andsrc refer to arrays. Each array must have at least as many entries asthere are planes infb’s format. Each entry stores the value for theformat’s respective color plane at the same index.

This function does not apply clipping ondst (i.e. the destination is at thetop-left corner).

Drivers can use this function for ARGB1555 devices that don’t supportXRGB8888 natively. It sets an opaque alpha channel as part of the conversion.

voiddrm_fb_xrgb8888_to_rgba5551(structiosys_map*dst,constunsignedint*dst_pitch,conststructiosys_map*src,conststructdrm_framebuffer*fb,conststructdrm_rect*clip,structdrm_format_conv_state*state)

Convert XRGB8888 to RGBA5551 clip buffer

Parameters

structiosys_map*dst

Array of RGBA5551 destination buffers

constunsignedint*dst_pitch

Array of numbers of bytes between the start of two consecutive scanlineswithindst; can be NULL if scanlines are stored next to each other.

conststructiosys_map*src

Array of XRGB8888 source buffer

conststructdrm_framebuffer*fb

DRM framebuffer

conststructdrm_rect*clip

Clip rectangle area to copy

structdrm_format_conv_state*state

Transform and conversion state

Description

This function copies parts of a framebuffer to display memory and convertsthe color format during the process. The parametersdst,dst_pitch andsrc refer to arrays. Each array must have at least as many entries asthere are planes infb’s format. Each entry stores the value for theformat’s respective color plane at the same index.

This function does not apply clipping ondst (i.e. the destination is at thetop-left corner).

Drivers can use this function for RGBA5551 devices that don’t supportXRGB8888 natively. It sets an opaque alpha channel as part of the conversion.

voiddrm_fb_xrgb8888_to_rgb888(structiosys_map*dst,constunsignedint*dst_pitch,conststructiosys_map*src,conststructdrm_framebuffer*fb,conststructdrm_rect*clip,structdrm_format_conv_state*state)

Convert XRGB8888 to RGB888 clip buffer

Parameters

structiosys_map*dst

Array of RGB888 destination buffers

constunsignedint*dst_pitch

Array of numbers of bytes between the start of two consecutive scanlineswithindst; can be NULL if scanlines are stored next to each other.

conststructiosys_map*src

Array of XRGB8888 source buffers

conststructdrm_framebuffer*fb

DRM framebuffer

conststructdrm_rect*clip

Clip rectangle area to copy

structdrm_format_conv_state*state

Transform and conversion state

Description

This function copies parts of a framebuffer to display memory and converts thecolor format during the process. Destination and framebuffer formats must match. Theparametersdst,dst_pitch andsrc refer to arrays. Each array must have atleast as many entries as there are planes infb’s format. Each entry stores thevalue for the format’s respective color plane at the same index.

This function does not apply clipping ondst (i.e. the destination is at thetop-left corner).

Drivers can use this function for RGB888 devices that don’t nativelysupport XRGB8888.

voiddrm_fb_xrgb8888_to_bgr888(structiosys_map*dst,constunsignedint*dst_pitch,conststructiosys_map*src,conststructdrm_framebuffer*fb,conststructdrm_rect*clip,structdrm_format_conv_state*state)

Convert XRGB8888 to BGR888 clip buffer

Parameters

structiosys_map*dst

Array of BGR888 destination buffers

constunsignedint*dst_pitch

Array of numbers of bytes between the start of two consecutive scanlineswithindst; can be NULL if scanlines are stored next to each other.

conststructiosys_map*src

Array of XRGB8888 source buffers

conststructdrm_framebuffer*fb

DRM framebuffer

conststructdrm_rect*clip

Clip rectangle area to copy

structdrm_format_conv_state*state

Transform and conversion state

Description

This function copies parts of a framebuffer to display memory and converts thecolor format during the process. Destination and framebuffer formats must match. Theparametersdst,dst_pitch andsrc refer to arrays. Each array must have atleast as many entries as there are planes infb’s format. Each entry stores thevalue for the format’s respective color plane at the same index.

This function does not apply clipping ondst (i.e. the destination is at thetop-left corner).

Drivers can use this function for BGR888 devices that don’t nativelysupport XRGB8888.

voiddrm_fb_xrgb8888_to_argb8888(structiosys_map*dst,constunsignedint*dst_pitch,conststructiosys_map*src,conststructdrm_framebuffer*fb,conststructdrm_rect*clip,structdrm_format_conv_state*state)

Convert XRGB8888 to ARGB8888 clip buffer

Parameters

structiosys_map*dst

Array of ARGB8888 destination buffers

constunsignedint*dst_pitch

Array of numbers of bytes between the start of two consecutive scanlineswithindst; can be NULL if scanlines are stored next to each other.

conststructiosys_map*src

Array of XRGB8888 source buffer

conststructdrm_framebuffer*fb

DRM framebuffer

conststructdrm_rect*clip

Clip rectangle area to copy

structdrm_format_conv_state*state

Transform and conversion state

Description

This function copies parts of a framebuffer to display memory and converts thecolor format during the process. The parametersdst,dst_pitch andsrc referto arrays. Each array must have at least as many entries as there are planes infb’s format. Each entry stores the value for the format’s respective color planeat the same index.

This function does not apply clipping ondst (i.e. the destination is at thetop-left corner).

Drivers can use this function for ARGB8888 devices that don’t support XRGB8888natively. It sets an opaque alpha channel as part of the conversion.

voiddrm_fb_xrgb8888_to_abgr8888(structiosys_map*dst,constunsignedint*dst_pitch,conststructiosys_map*src,conststructdrm_framebuffer*fb,conststructdrm_rect*clip,structdrm_format_conv_state*state)

Convert XRGB8888 to ABGR8888 clip buffer

Parameters

structiosys_map*dst

Array of ABGR8888 destination buffers

constunsignedint*dst_pitch

Array of numbers of bytes between the start of two consecutive scanlineswithindst; can be NULL if scanlines are stored next to each other.

conststructiosys_map*src

Array of XRGB8888 source buffer

conststructdrm_framebuffer*fb

DRM framebuffer

conststructdrm_rect*clip

Clip rectangle area to copy

structdrm_format_conv_state*state

Transform and conversion state

Description

This function copies parts of a framebuffer to display memory and converts thecolor format during the process. The parametersdst,dst_pitch andsrc referto arrays. Each array must have at least as many entries as there are planes infb’s format. Each entry stores the value for the format’s respective color planeat the same index.

This function does not apply clipping ondst (i.e. the destination is at thetop-left corner).

Drivers can use this function for ABGR8888 devices that don’t support XRGB8888natively. It sets an opaque alpha channel as part of the conversion.

voiddrm_fb_xrgb8888_to_xbgr8888(structiosys_map*dst,constunsignedint*dst_pitch,conststructiosys_map*src,conststructdrm_framebuffer*fb,conststructdrm_rect*clip,structdrm_format_conv_state*state)

Convert XRGB8888 to XBGR8888 clip buffer

Parameters

structiosys_map*dst

Array of XBGR8888 destination buffers

constunsignedint*dst_pitch

Array of numbers of bytes between the start of two consecutive scanlineswithindst; can be NULL if scanlines are stored next to each other.

conststructiosys_map*src

Array of XRGB8888 source buffer

conststructdrm_framebuffer*fb

DRM framebuffer

conststructdrm_rect*clip

Clip rectangle area to copy

structdrm_format_conv_state*state

Transform and conversion state

Description

This function copies parts of a framebuffer to display memory and converts thecolor format during the process. The parametersdst,dst_pitch andsrc referto arrays. Each array must have at least as many entries as there are planes infb’s format. Each entry stores the value for the format’s respective color planeat the same index.

This function does not apply clipping ondst (i.e. the destination is at thetop-left corner).

Drivers can use this function for XBGR8888 devices that don’t support XRGB8888natively.

voiddrm_fb_xrgb8888_to_bgrx8888(structiosys_map*dst,constunsignedint*dst_pitch,conststructiosys_map*src,conststructdrm_framebuffer*fb,conststructdrm_rect*clip,structdrm_format_conv_state*state)

Convert XRGB8888 to BGRX8888 clip buffer

Parameters

structiosys_map*dst

Array of BGRX8888 destination buffers

constunsignedint*dst_pitch

Array of numbers of bytes between the start of two consecutive scanlineswithindst; can be NULL if scanlines are stored next to each other.

conststructiosys_map*src

Array of XRGB8888 source buffer

conststructdrm_framebuffer*fb

DRM framebuffer

conststructdrm_rect*clip

Clip rectangle area to copy

structdrm_format_conv_state*state

Transform and conversion state

Description

This function copies parts of a framebuffer to display memory and converts thecolor format during the process. The parametersdst,dst_pitch andsrc referto arrays. Each array must have at least as many entries as there are planes infb’s format. Each entry stores the value for the format’s respective color planeat the same index.

This function does not apply clipping ondst (i.e. the destination is at thetop-left corner).

Drivers can use this function for BGRX8888 devices that don’t support XRGB8888natively.

voiddrm_fb_xrgb8888_to_xrgb2101010(structiosys_map*dst,constunsignedint*dst_pitch,conststructiosys_map*src,conststructdrm_framebuffer*fb,conststructdrm_rect*clip,structdrm_format_conv_state*state)

Convert XRGB8888 to XRGB2101010 clip buffer

Parameters

structiosys_map*dst

Array of XRGB2101010 destination buffers

constunsignedint*dst_pitch

Array of numbers of bytes between the start of two consecutive scanlineswithindst; can be NULL if scanlines are stored next to each other.

conststructiosys_map*src

Array of XRGB8888 source buffers

conststructdrm_framebuffer*fb

DRM framebuffer

conststructdrm_rect*clip

Clip rectangle area to copy

structdrm_format_conv_state*state

Transform and conversion state

Description

This function copies parts of a framebuffer to display memory and converts thecolor format during the process. Destination and framebuffer formats must match. Theparametersdst,dst_pitch andsrc refer to arrays. Each array must have atleast as many entries as there are planes infb’s format. Each entry stores thevalue for the format’s respective color plane at the same index.

This function does not apply clipping ondst (i.e. the destination is at thetop-left corner).

Drivers can use this function for XRGB2101010 devices that don’t support XRGB8888natively.

voiddrm_fb_xrgb8888_to_argb2101010(structiosys_map*dst,constunsignedint*dst_pitch,conststructiosys_map*src,conststructdrm_framebuffer*fb,conststructdrm_rect*clip,structdrm_format_conv_state*state)

Convert XRGB8888 to ARGB2101010 clip buffer

Parameters

structiosys_map*dst

Array of ARGB2101010 destination buffers

constunsignedint*dst_pitch

Array of numbers of bytes between the start of two consecutive scanlineswithindst; can be NULL if scanlines are stored next to each other.

conststructiosys_map*src

Array of XRGB8888 source buffers

conststructdrm_framebuffer*fb

DRM framebuffer

conststructdrm_rect*clip

Clip rectangle area to copy

structdrm_format_conv_state*state

Transform and conversion state

Description

This function copies parts of a framebuffer to display memory and convertsthe color format during the process. The parametersdst,dst_pitch andsrc refer to arrays. Each array must have at least as many entries asthere are planes infb’s format. Each entry stores the value for theformat’s respective color plane at the same index.

This function does not apply clipping ondst (i.e. the destination is at thetop-left corner).

Drivers can use this function for ARGB2101010 devices that don’t support XRGB8888natively.

voiddrm_fb_xrgb8888_to_gray8(structiosys_map*dst,constunsignedint*dst_pitch,conststructiosys_map*src,conststructdrm_framebuffer*fb,conststructdrm_rect*clip,structdrm_format_conv_state*state)

Convert XRGB8888 to grayscale

Parameters

structiosys_map*dst

Array of 8-bit grayscale destination buffers

constunsignedint*dst_pitch

Array of numbers of bytes between the start of two consecutive scanlineswithindst; can be NULL if scanlines are stored next to each other.

conststructiosys_map*src

Array of XRGB8888 source buffers

conststructdrm_framebuffer*fb

DRM framebuffer

conststructdrm_rect*clip

Clip rectangle area to copy

structdrm_format_conv_state*state

Transform and conversion state

Description

This function copies parts of a framebuffer to display memory and converts thecolor format during the process. Destination and framebuffer formats must match. Theparametersdst,dst_pitch andsrc refer to arrays. Each array must have atleast as many entries as there are planes infb’s format. Each entry stores thevalue for the format’s respective color plane at the same index.

This function does not apply clipping ondst (i.e. the destination is at thetop-left corner).

DRM doesn’t have native monochrome or grayscale support. Drivers can use thisfunction for grayscale devices that don’t support XRGB8888 natively.Suchdrivers can announce the commonly supported XR24 format to userspace and usethis function to convert to the native format. Monochrome drivers will use themost significant bit, where 1 means foreground color and 0 background color.ITU BT.601 is being used for the RGB -> luma (brightness) conversion.

voiddrm_fb_argb8888_to_argb4444(structiosys_map*dst,constunsignedint*dst_pitch,conststructiosys_map*src,conststructdrm_framebuffer*fb,conststructdrm_rect*clip,structdrm_format_conv_state*state)

Convert ARGB8888 to ARGB4444 clip buffer

Parameters

structiosys_map*dst

Array of ARGB4444 destination buffers

constunsignedint*dst_pitch

Array of numbers of bytes between the start of two consecutive scanlineswithindst; can be NULL if scanlines are stored next to each other.

conststructiosys_map*src

Array of ARGB8888 source buffer

conststructdrm_framebuffer*fb

DRM framebuffer

conststructdrm_rect*clip

Clip rectangle area to copy

structdrm_format_conv_state*state

Transform and conversion state

Description

This function copies parts of a framebuffer to display memory and convertsthe color format during the process. The parametersdst,dst_pitch andsrc refer to arrays. Each array must have at least as many entries asthere are planes infb’s format. Each entry stores the value for theformat’s respective color plane at the same index.

This function does not apply clipping ondst (i.e. the destination is at thetop-left corner).

Drivers can use this function for ARGB4444 devices that don’t supportARGB8888 natively.

voiddrm_fb_xrgb8888_to_mono(structiosys_map*dst,constunsignedint*dst_pitch,conststructiosys_map*src,conststructdrm_framebuffer*fb,conststructdrm_rect*clip,structdrm_format_conv_state*state)

Convert XRGB8888 to monochrome

Parameters

structiosys_map*dst

Array of monochrome destination buffers (0=black, 1=white)

constunsignedint*dst_pitch

Array of numbers of bytes between the start of two consecutive scanlineswithindst; can be NULL if scanlines are stored next to each other.

conststructiosys_map*src

Array of XRGB8888 source buffers

conststructdrm_framebuffer*fb

DRM framebuffer

conststructdrm_rect*clip

Clip rectangle area to copy

structdrm_format_conv_state*state

Transform and conversion state

Description

This function copies parts of a framebuffer to display memory and converts thecolor format during the process. Destination and framebuffer formats must match. Theparametersdst,dst_pitch andsrc refer to arrays. Each array must have atleast as many entries as there are planes infb’s format. Each entry stores thevalue for the format’s respective color plane at the same index.

This function does not apply clipping ondst (i.e. the destination is at thetop-left corner). The first pixel (upper left corner of the clip rectangle) willbe converted and copied to the first bit (LSB) in the first byte of the monochromedestination buffer. If the caller requires that the first pixel in a byte mustbe located at an x-coordinate that is a multiple of 8, then the caller must takecare itself of supplying a suitable clip rectangle.

DRM doesn’t have native monochrome support. Drivers can use this function formonochrome devices that don’t support XRGB8888 natively. Such drivers canannounce the commonly supported XR24 format to userspace and use this functionto convert to the native format.

This function usesdrm_fb_xrgb8888_to_gray8() to convert to grayscale andthen the result is converted from grayscale to monochrome.

voiddrm_fb_xrgb8888_to_gray2(structiosys_map*dst,constunsignedint*dst_pitch,conststructiosys_map*src,conststructdrm_framebuffer*fb,conststructdrm_rect*clip,structdrm_format_conv_state*state)

Convert XRGB8888 to gray2

Parameters

structiosys_map*dst

Array of gray2 destination buffer

constunsignedint*dst_pitch

Array of numbers of bytes between the start of two consecutive scanlineswithindst; can be NULL if scanlines are stored next to each other.

conststructiosys_map*src

Array of XRGB8888 source buffers

conststructdrm_framebuffer*fb

DRM framebuffer

conststructdrm_rect*clip

Clip rectangle area to copy

structdrm_format_conv_state*state

Transform and conversion state

Description

This function copies parts of a framebuffer to display memory and converts thecolor format during the process. Destination and framebuffer formats must match. Theparametersdst,dst_pitch andsrc refer to arrays. Each array must have atleast as many entries as there are planes infb’s format. Each entry stores thevalue for the format’s respective color plane at the same index.

This function does not apply clipping ondst (i.e. the destination is at thetop-left corner). The first pixel (upper left corner of the clip rectangle) willbe converted and copied to the two first bits (LSB) in the first byte of the gray2destination buffer. If the caller requires that the first pixel in a byte mustbe located at an x-coordinate that is a multiple of 8, then the caller must takecare itself of supplying a suitable clip rectangle.

DRM doesn’t have native gray2 support. Drivers can use this function forgray2 devices that don’t support XRGB8888 natively. Such drivers canannounce the commonly supported XR24 format to userspace and use this functionto convert to the native format.

Framebuffer DMA Helper Functions Reference

Provides helper functions for creating a DMA-contiguous framebuffer.

Depending on the platform, the buffers may be physically non-contiguous andmapped through an IOMMU or a similar mechanism, or allocated fromphysically-contiguous memory (using, for instance, CMA or a pool of memoryreserved at early boot). This is handled behind the scenes by the DMA mappingAPI.

drm_gem_fb_create() is used in thedrm_mode_config_funcs.fb_createcallback function to create a DMA-contiguous framebuffer.

structdrm_gem_dma_object*drm_fb_dma_get_gem_obj(structdrm_framebuffer*fb,unsignedintplane)

Get DMA GEM object for framebuffer

Parameters

structdrm_framebuffer*fb

The framebuffer

unsignedintplane

Which plane

Description

Return the DMA GEM object for given framebuffer.

This function will usually be called from the CRTC callback functions.

dma_addr_tdrm_fb_dma_get_gem_addr(structdrm_framebuffer*fb,structdrm_plane_state*state,unsignedintplane)

Get DMA (bus) address for framebuffer, for pixel formats where values are grouped in blocks this will get you the beginning of the block

Parameters

structdrm_framebuffer*fb

The framebuffer

structdrm_plane_state*state

Which state of drm plane

unsignedintplane

Which planeReturn the DMA GEM address for given framebuffer.

Description

This function will usually be called from the PLANE callback functions.

voiddrm_fb_dma_sync_non_coherent(structdrm_device*drm,structdrm_plane_state*old_state,structdrm_plane_state*state)

Sync GEM object to non-coherent backing memory

Parameters

structdrm_device*drm

DRM device

structdrm_plane_state*old_state

Old plane state

structdrm_plane_state*state

New plane state

Description

This function can be used by drivers that use damage clips and haveDMA GEM objects backed by non-coherent memory. Calling this functionin a plane’s .atomic_update ensures that all the data in the backingmemory have been written to RAM.

intdrm_fb_dma_get_scanout_buffer(structdrm_plane*plane,structdrm_scanout_buffer*sb)

Provide a scanout buffer in case of panic

Parameters

structdrm_plane*plane

DRM primary plane

structdrm_scanout_buffer*sb

scanout buffer for the panic handler

Return

0 or negative error code

Description

Genericget_scanout_buffer() implementation, for drivers that uses thedrm_fb_dma_helper. It won’t call vmap in the panic context, so the drivershould make sure the primary plane is vmapped, otherwise the panic screenwon’t get displayed.

Framebuffer GEM Helper Reference

This library provides helpers for drivers that don’t subclassdrm_framebuffer and usedrm_gem_object for their backing storage.

Drivers without additional needs to validate framebuffers can simply usedrm_gem_fb_create() and everything is wired up automatically. Other driverscan use all parts independently.

structdrm_gem_object*drm_gem_fb_get_obj(structdrm_framebuffer*fb,unsignedintplane)

Get GEM object backing the framebuffer

Parameters

structdrm_framebuffer*fb

Framebuffer

unsignedintplane

Plane index

Description

No additional reference is taken beyond the one that thedrm_frambufferalready holds.

Return

Pointer todrm_gem_object for the given framebuffer and plane index or NULLif it does not exist.

voiddrm_gem_fb_destroy(structdrm_framebuffer*fb)

Free GEM backed framebuffer

Parameters

structdrm_framebuffer*fb

Framebuffer

Description

Frees a GEM backed framebuffer with its backing buffer(s) and the structureitself. Drivers can use this as theirdrm_framebuffer_funcs->destroycallback.

intdrm_gem_fb_create_handle(structdrm_framebuffer*fb,structdrm_file*file,unsignedint*handle)

Create handle for GEM backed framebuffer

Parameters

structdrm_framebuffer*fb

Framebuffer

structdrm_file*file

DRM file to register the handle for

unsignedint*handle

Pointer to return the created handle

Description

This function creates a handle for the GEM object backing the framebuffer.Drivers can use this as theirdrm_framebuffer_funcs->create_handlecallback. The GETFB IOCTL calls into this callback.

Return

0 on success or a negative error code on failure.

intdrm_gem_fb_init_with_funcs(structdrm_device*dev,structdrm_framebuffer*fb,structdrm_file*file,conststructdrm_format_info*info,conststructdrm_mode_fb_cmd2*mode_cmd,conststructdrm_framebuffer_funcs*funcs)

Helper function for implementingdrm_mode_config_funcs.fb_create callback in cases when the driver allocates a subclass ofstructdrm_framebuffer

Parameters

structdrm_device*dev

DRM device

structdrm_framebuffer*fb

framebuffer object

structdrm_file*file

DRM file that holds the GEM handle(s) backing the framebuffer

conststructdrm_format_info*info

pixel format information

conststructdrm_mode_fb_cmd2*mode_cmd

Metadata from the userspace framebuffer creation request

conststructdrm_framebuffer_funcs*funcs

vtable to be used for the new framebuffer object

Description

This function can be used to setdrm_framebuffer_funcs for drivers that needcustom framebuffer callbacks. Usedrm_gem_fb_create() if you don’t need tochangedrm_framebuffer_funcs. The function does buffer size validation.The buffer size validation is for a general case, though, so users shouldpay attention to the checks being appropriate for them or, at least,non-conflicting.

Return

Zero or a negative error code.

structdrm_framebuffer*drm_gem_fb_create_with_funcs(structdrm_device*dev,structdrm_file*file,conststructdrm_format_info*info,conststructdrm_mode_fb_cmd2*mode_cmd,conststructdrm_framebuffer_funcs*funcs)

Helper function for thedrm_mode_config_funcs.fb_create callback

Parameters

structdrm_device*dev

DRM device

structdrm_file*file

DRM file that holds the GEM handle(s) backing the framebuffer

conststructdrm_format_info*info

pixel format information

conststructdrm_mode_fb_cmd2*mode_cmd

Metadata from the userspace framebuffer creation request

conststructdrm_framebuffer_funcs*funcs

vtable to be used for the new framebuffer object

Description

This function can be used to setdrm_framebuffer_funcs for drivers that needcustom framebuffer callbacks. Usedrm_gem_fb_create() if you don’t need tochangedrm_framebuffer_funcs. The function does buffer size validation.

Return

Pointer to adrm_framebuffer on success or an error pointer on failure.

structdrm_framebuffer*drm_gem_fb_create(structdrm_device*dev,structdrm_file*file,conststructdrm_format_info*info,conststructdrm_mode_fb_cmd2*mode_cmd)

Helper function for thedrm_mode_config_funcs.fb_create callback

Parameters

structdrm_device*dev

DRM device

structdrm_file*file

DRM file that holds the GEM handle(s) backing the framebuffer

conststructdrm_format_info*info

pixel format information

conststructdrm_mode_fb_cmd2*mode_cmd

Metadata from the userspace framebuffer creation request

Description

This function creates a new framebuffer object described bydrm_mode_fb_cmd2. This description includes handles for the buffer(s)backing the framebuffer.

If your hardware has special alignment or pitch requirements these should bechecked before calling this function. The function does buffer sizevalidation. Usedrm_gem_fb_create_with_dirty() if you need framebufferflushing.

Drivers can use this as theirdrm_mode_config_funcs.fb_create callback.The ADDFB2 IOCTL calls into this callback.

Return

Pointer to adrm_framebuffer on success or an error pointer on failure.

structdrm_framebuffer*drm_gem_fb_create_with_dirty(structdrm_device*dev,structdrm_file*file,conststructdrm_format_info*info,conststructdrm_mode_fb_cmd2*mode_cmd)

Helper function for thedrm_mode_config_funcs.fb_create callback

Parameters

structdrm_device*dev

DRM device

structdrm_file*file

DRM file that holds the GEM handle(s) backing the framebuffer

conststructdrm_format_info*info

pixel format information

conststructdrm_mode_fb_cmd2*mode_cmd

Metadata from the userspace framebuffer creation request

Description

This function creates a new framebuffer object described bydrm_mode_fb_cmd2. This description includes handles for the buffer(s)backing the framebuffer.drm_atomic_helper_dirtyfb() is used for the dirtycallback giving framebuffer flushing through the atomic machinery. Usedrm_gem_fb_create() if you don’t need the dirty callback.The function does buffer size validation.

Drivers should also calldrm_plane_enable_fb_damage_clips() on all planesto enable userspace to use damage clips also with the ATOMIC IOCTL.

Drivers can use this as theirdrm_mode_config_funcs.fb_create callback.The ADDFB2 IOCTL calls into this callback.

Return

Pointer to adrm_framebuffer on success or an error pointer on failure.

intdrm_gem_fb_vmap(structdrm_framebuffer*fb,structiosys_map*map,structiosys_map*data)

maps all framebuffer BOs into kernel address space

Parameters

structdrm_framebuffer*fb

the framebuffer

structiosys_map*map

returns the mapping’s address for each BO

structiosys_map*data

returns the data address for each BO, can be NULL

Description

This function maps all buffer objects of the given framebuffer intokernel address space and stores them instructiosys_map. If themapping operation fails for one of the BOs, the function unmaps thealready established mappings automatically.

Callers that want to access a BO’s stored data should passdata.The argument returns the addresses of the data stored in each BO. Thisis different frommap if the framebuffer’s offsets field is non-zero.

Both,map anddata, must each refer to arrays with at leastfb->format->num_planes elements.

Seedrm_gem_fb_vunmap() for unmapping.

Return

0 on success, or a negative errno code otherwise.

voiddrm_gem_fb_vunmap(structdrm_framebuffer*fb,structiosys_map*map)

unmaps framebuffer BOs from kernel address space

Parameters

structdrm_framebuffer*fb

the framebuffer

structiosys_map*map

mapping addresses as returned bydrm_gem_fb_vmap()

Description

This function unmaps all buffer objects of the given framebuffer.

Seedrm_gem_fb_vmap() for more information.

intdrm_gem_fb_begin_cpu_access(structdrm_framebuffer*fb,enumdma_data_directiondir)

prepares GEM buffer objects for CPU access

Parameters

structdrm_framebuffer*fb

the framebuffer

enumdma_data_directiondir

access mode

Description

Prepares a framebuffer’s GEM buffer objects for CPU access. This functionmust be called before accessing the BO data within the kernel. For importedBOs, the function callsdma_buf_begin_cpu_access().

Seedrm_gem_fb_end_cpu_access() for signalling the end of CPU access.

Return

0 on success, or a negative errno code otherwise.

voiddrm_gem_fb_end_cpu_access(structdrm_framebuffer*fb,enumdma_data_directiondir)

signals end of CPU access to GEM buffer objects

Parameters

structdrm_framebuffer*fb

the framebuffer

enumdma_data_directiondir

access mode

Description

Signals the end of CPU access to the given framebuffer’s GEM buffer objects. Thisfunction must be paired with a corresponding call todrm_gem_fb_begin_cpu_access().For imported BOs, the function callsdma_buf_end_cpu_access().

See alsodrm_gem_fb_begin_cpu_access().

intdrm_gem_fb_afbc_init(structdrm_device*dev,conststructdrm_format_info*info,conststructdrm_mode_fb_cmd2*mode_cmd,structdrm_afbc_framebuffer*afbc_fb)

Helper function for drivers using afbc to fill and validate all the afbc-specificstructdrm_afbc_framebuffer members

Parameters

structdrm_device*dev

DRM device

conststructdrm_format_info*info

pixel format information

conststructdrm_mode_fb_cmd2*mode_cmd

Metadata from the userspace framebuffer creation request

structdrm_afbc_framebuffer*afbc_fb

afbc framebuffer

Description

This function can be used by drivers which support afbc to completethe preparation ofstructdrm_afbc_framebuffer. It must be called afterallocating the saidstructand callingdrm_gem_fb_init_with_funcs().It is caller’s responsibility to put afbc_fb->base.obj objects in casethe call is unsuccessful.

Return

Zero on success or a negative error value on failure.

Bridges

Overview

structdrm_bridge represents a device that hangs on to an encoder. These arehandy when a regulardrm_encoder entity isn’t enough to represent the entireencoder chain.

A bridge is always attached to a singledrm_encoder at a time, but can beeither connected to it directly, or through a chain of bridges:

[ CRTC ---> ] Encoder ---> Bridge A ---> Bridge B

Here, the output of the encoder feeds to bridge A, and that furthers feeds tobridge B. Bridge chains can be arbitrarily long, and shall be fully linear:Chaining multiple bridges to the output of a bridge, or the same bridge tothe output of different bridges, is not supported.

drm_bridge, likedrm_panel, aren’tdrm_mode_object entities like planes,CRTCs, encoders or connectors and hence are not visible to userspace. Theyjust provide additional hooks to get the desired output at the end of theencoder chain.

Display Driver Integration

Display drivers are responsible for linking encoders with the first bridgein the chains. This is done by acquiring the appropriate bridge withdevm_drm_of_get_bridge(). Once acquired, the bridge shall be attached to theencoder with a call todrm_bridge_attach().

Bridges are responsible for linking themselves with the next bridge in thechain, if any. This is done the same way as for encoders, with the call todrm_bridge_attach() occurring in thedrm_bridge_funcs.attach operation.

Once these links are created, the bridges can participate along with encoderfunctions to perform mode validation and fixup (throughdrm_bridge_chain_mode_valid() anddrm_atomic_bridge_chain_check()), modesetting (throughdrm_bridge_chain_mode_set()), enable (throughdrm_atomic_bridge_chain_pre_enable() anddrm_atomic_bridge_chain_enable())and disable (throughdrm_atomic_bridge_chain_disable() anddrm_atomic_bridge_chain_post_disable()). Those functions call thecorresponding operations provided indrm_bridge_funcs in sequence for allbridges in the chain.

For display drivers that use the atomic helpersdrm_atomic_helper_check_modeset(),drm_atomic_helper_commit_modeset_enables() anddrm_atomic_helper_commit_modeset_disables() (either directly in hand-rolledcommit check and commit tail handlers, or through the higher-leveldrm_atomic_helper_check() anddrm_atomic_helper_commit_tail() ordrm_atomic_helper_commit_tail_rpm() helpers), this is done transparently andrequires no intervention from the driver. For other drivers, the relevantDRM bridge chain functions shall be called manually.

Bridges also participate in implementing thedrm_connector at the end ofthe bridge chain. Display drivers may use thedrm_bridge_connector_init()helper to create thedrm_connector, or implement it manually on top of theconnector-related operations exposed by the bridge (see the overviewdocumentation of bridge operations for more details).

Special Care with MIPI-DSI bridges

The interaction between the bridges and other frameworks involved inthe probing of the upstream driver and the bridge driver can bechallenging. Indeed, there’s multiple cases that needs to beconsidered:

  • The upstream driver doesn’t use the component framework and isn’t aMIPI-DSI host. In this case, the bridge driver will probe at somepoint and the upstream driver should try to probe again by returningEPROBE_DEFER as long as the bridge driver hasn’t probed.

  • The upstream driver doesn’t use the component framework, but is aMIPI-DSI host. The bridge device uses the MIPI-DCS commands to becontrolled. In this case, the bridge device is a child of thedisplay device and when it will probe it’s assured that the displaydevice (and MIPI-DSI host) is present. The upstream driver will beassured that the bridge driver is connected between themipi_dsi_host_ops.attach andmipi_dsi_host_ops.detach operations.Therefore, it must runmipi_dsi_host_register() in its probefunction, and then rundrm_bridge_attach() in itsmipi_dsi_host_ops.attach hook.

  • The upstream driver uses the component framework and is a MIPI-DSIhost. The bridge device uses the MIPI-DCS commands to becontrolled. This is the same situation than above, and can runmipi_dsi_host_register() in either its probe or bind hooks.

  • The upstream driver uses the component framework and is a MIPI-DSIhost. The bridge device uses a separate bus (such as I2C) to becontrolled. In this case, there’s no correlation between the probeof the bridge and upstream drivers, so care must be taken to avoidan endless EPROBE_DEFER loop, with each driver waiting for theother to probe.

The ideal pattern to cover the last item (and all the others in theMIPI-DSI host driver case) is to split the operations like this:

  • The MIPI-DSI host driver must runmipi_dsi_host_register() in itsprobe hook. It will make sure that the MIPI-DSI host sticks around,and that the driver’s bind can be called.

  • In its probe hook, the bridge driver must try to find its MIPI-DSIhost, register as a MIPI-DSI device and attach the MIPI-DSI deviceto its host. The bridge driver is now functional.

  • In itsstructmipi_dsi_host_ops.attach hook, the MIPI-DSI host cannow add its component. Its bind hook will now be called and sincethe bridge driver is attached and registered, we can now look forand attach it.

At this point, we’re now certain that both the upstream driver andthe bridge driver are functional and we can’t have a deadlock-likesituation when probing.

Bridge Operations

Bridge drivers expose operations through thedrm_bridge_funcs structure.The DRM internals (atomic and CRTC helpers) use the helpers defined indrm_bridge.c to call bridge operations. Those operations are divided inthree big categories to support different parts of the bridge usage.

  • The encoder-related operations support control of the bridges in thechain, and are roughly counterparts to thedrm_encoder_helper_funcsoperations. They are used by the legacy CRTC and the atomic modesethelpers to perform mode validation, fixup and setting, and enable anddisable the bridge automatically.

    The enable and disable operations are split indrm_bridge_funcs.pre_enable,drm_bridge_funcs.enable,drm_bridge_funcs.disable anddrm_bridge_funcs.post_disable to providefiner-grained control.

    Bridge drivers may implement the legacy version of those operations, orthe atomic version (prefixed with atomic_), in which case they shall alsoimplement the atomic state bookkeeping operations(drm_bridge_funcs.atomic_duplicate_state,drm_bridge_funcs.atomic_destroy_state anddrm_bridge_funcs.reset).Mixing atomic and non-atomic versions of the operations is not supported.

  • The bus format negotiation operationsdrm_bridge_funcs.atomic_get_output_bus_fmts anddrm_bridge_funcs.atomic_get_input_bus_fmts allow bridge drivers tonegotiate the formats transmitted between bridges in the chain whenmultiple formats are supported. Negotiation for formats is performedtransparently for display drivers by the atomic modeset helpers. Onlyatomic versions of those operations exist, bridge drivers that need toimplement them shall thus also implement the atomic version of theencoder-related operations. This feature is not supported by the legacyCRTC helpers.

  • The connector-related operations support implementing adrm_connectorbased on a chain of bridges. DRM bridges traditionally create adrm_connector for bridges meant to be used at the end of the chain. Thisputs additional burden on bridge drivers, especially for bridges that maybe used in the middle of a chain or at the end of it. Furthermore, itrequires all operations of thedrm_connector to be handled by a singlebridge, which doesn’t always match the hardware architecture.

    To simplify bridge drivers and make the connector implementation moreflexible, a new model allows bridges to unconditionally skip creation ofdrm_connector and instead exposedrm_bridge_funcs operations to supportan externally-implementeddrm_connector. Those operations aredrm_bridge_funcs.detect,drm_bridge_funcs.get_modes,drm_bridge_funcs.get_edid,drm_bridge_funcs.hpd_notify,drm_bridge_funcs.hpd_enable anddrm_bridge_funcs.hpd_disable. Whenimplemented, display drivers shall create adrm_connector instance foreach chain of bridges, and implement those connector instances based onthe bridge connector operations.

    Bridge drivers shall implement the connector-related operations for allthe features that the bridge hardware support. For instance, if a bridgesupports reading EDID, thedrm_bridge_funcs.get_edid shall beimplemented. This however doesn’t mean that the DDC lines are wired to thebridge on a particular platform, as they could also be connected to an I2Ccontroller of the SoC. Support for the connector-related operations on therunning platform is reported through thedrm_bridge.ops flags. Bridgedrivers shall detect which operations they can support on the platform(usually this information is provided by ACPI or DT), and set thedrm_bridge.ops flags for all supported operations. A flag shall only beset if the correspondingdrm_bridge_funcs operation is implemented, butan implemented operation doesn’t necessarily imply that the correspondingflag will be set. Display drivers shall use thedrm_bridge.ops flags todecide which bridge to delegate a connector operation to. This mechanismallows providing a single static constdrm_bridge_funcs instance inbridge drivers, improving security by storing function pointers inread-only memory.

    In order to ease transition, bridge drivers may support both the old andnew models by making connector creation optional and implementing theconnected-related bridge operations. Connector creation is then controlledby the flags argument to thedrm_bridge_attach() function. Display driversthat support the new model and create connectors themselves shall set theDRM_BRIDGE_ATTACH_NO_CONNECTOR flag, and bridge drivers shall then skipconnector creation. For intermediate bridges in the chain, the flag shallbe passed to thedrm_bridge_attach() call for the downstream bridge.Bridge drivers that implement the new model only shall return an errorfrom theirdrm_bridge_funcs.attach handler when theDRM_BRIDGE_ATTACH_NO_CONNECTOR flag is not set. New display driversshould use the new model, and convert the bridge drivers they use ifneeded, in order to gradually transition to the new model.

Bridge Connector Helper

The DRM bridge connector helper object provides a DRM connectorimplementation that wraps a chain ofstructdrm_bridge. The connectoroperations are fully implemented based on the operations of the bridges inthe chain, and don’t require any intervention from the display controllerdriver at runtime.

To use the helper, display controller drivers create a bridge connector witha call todrm_bridge_connector_init(). This associates the newly createdconnector with the chain of bridges passed to the function and registers itwith the DRM device. At that point the connector becomes fully usable, nofurther operation is needed.

The DRM bridge connector operations are implemented based on the operationsprovided by the bridges in the chain. Each connector operation is delegatedto the bridge closest to the connector (at the end of the chain) thatprovides the relevant functionality.

To make use of this helper, all bridges in the chain shall report bridgeoperation flags (drm_bridge->ops) and bridge output type(drm_bridge->type), as well as the DRM_BRIDGE_ATTACH_NO_CONNECTOR attachflag (none of the bridges shall create a DRM connector directly).

Bridge Helper Reference

enumdrm_bridge_attach_flags

Flags fordrm_bridge_funcs.attach

Constants

DRM_BRIDGE_ATTACH_NO_CONNECTOR

When this flag is set the bridgeshall not create a drm_connector.

structdrm_bridge_funcs

drm_bridge control functions

Definition:

struct drm_bridge_funcs {    int (*attach)(struct drm_bridge *bridge, struct drm_encoder *encoder, enum drm_bridge_attach_flags flags);    void (*destroy)(struct drm_bridge *bridge);    void (*detach)(struct drm_bridge *bridge);    enum drm_mode_status (*mode_valid)(struct drm_bridge *bridge, const struct drm_display_info *info, const struct drm_display_mode *mode);    bool (*mode_fixup)(struct drm_bridge *bridge, const struct drm_display_mode *mode, struct drm_display_mode *adjusted_mode);    void (*disable)(struct drm_bridge *bridge);    void (*post_disable)(struct drm_bridge *bridge);    void (*mode_set)(struct drm_bridge *bridge, const struct drm_display_mode *mode, const struct drm_display_mode *adjusted_mode);    void (*pre_enable)(struct drm_bridge *bridge);    void (*enable)(struct drm_bridge *bridge);    void (*atomic_pre_enable)(struct drm_bridge *bridge, struct drm_atomic_state *state);    void (*atomic_enable)(struct drm_bridge *bridge, struct drm_atomic_state *state);    void (*atomic_disable)(struct drm_bridge *bridge, struct drm_atomic_state *state);    void (*atomic_post_disable)(struct drm_bridge *bridge, struct drm_atomic_state *state);    struct drm_bridge_state *(*atomic_duplicate_state)(struct drm_bridge *bridge);    void (*atomic_destroy_state)(struct drm_bridge *bridge, struct drm_bridge_state *state);    u32 *(*atomic_get_output_bus_fmts)(struct drm_bridge *bridge, struct drm_bridge_state *bridge_state, struct drm_crtc_state *crtc_state, struct drm_connector_state *conn_state, unsigned int *num_output_fmts);    u32 *(*atomic_get_input_bus_fmts)(struct drm_bridge *bridge, struct drm_bridge_state *bridge_state, struct drm_crtc_state *crtc_state, struct drm_connector_state *conn_state, u32 output_fmt, unsigned int *num_input_fmts);    int (*atomic_check)(struct drm_bridge *bridge, struct drm_bridge_state *bridge_state, struct drm_crtc_state *crtc_state, struct drm_connector_state *conn_state);    struct drm_bridge_state *(*atomic_reset)(struct drm_bridge *bridge);    enum drm_connector_status (*detect)(struct drm_bridge *bridge, struct drm_connector *connector);    int (*get_modes)(struct drm_bridge *bridge, struct drm_connector *connector);    const struct drm_edid *(*edid_read)(struct drm_bridge *bridge, struct drm_connector *connector);    void (*hpd_notify)(struct drm_bridge *bridge, struct drm_connector *connector, enum drm_connector_status status);    void (*hpd_enable)(struct drm_bridge *bridge);    void (*hpd_disable)(struct drm_bridge *bridge);    enum drm_mode_status (*hdmi_tmds_char_rate_valid)(const struct drm_bridge *bridge, const struct drm_display_mode *mode, unsigned long long tmds_rate);    int (*hdmi_clear_avi_infoframe)(struct drm_bridge *bridge);    int (*hdmi_write_avi_infoframe)(struct drm_bridge *bridge, const u8 *buffer, size_t len);    int (*hdmi_clear_hdmi_infoframe)(struct drm_bridge *bridge);    int (*hdmi_write_hdmi_infoframe)(struct drm_bridge *bridge, const u8 *buffer, size_t len);    int (*hdmi_clear_hdr_drm_infoframe)(struct drm_bridge *bridge);    int (*hdmi_write_hdr_drm_infoframe)(struct drm_bridge *bridge, const u8 *buffer, size_t len);    int (*hdmi_clear_spd_infoframe)(struct drm_bridge *bridge);    int (*hdmi_write_spd_infoframe)(struct drm_bridge *bridge, const u8 *buffer, size_t len);    int (*hdmi_clear_audio_infoframe)(struct drm_bridge *bridge);    int (*hdmi_write_audio_infoframe)(struct drm_bridge *bridge, const u8 *buffer, size_t len);    int (*hdmi_audio_startup)(struct drm_bridge *bridge, struct drm_connector *connector);    int (*hdmi_audio_prepare)(struct drm_bridge *bridge, struct drm_connector *connector, struct hdmi_codec_daifmt *fmt, struct hdmi_codec_params *hparms);    void (*hdmi_audio_shutdown)(struct drm_bridge *bridge, struct drm_connector *connector);    int (*hdmi_audio_mute_stream)(struct drm_bridge *bridge, struct drm_connector *connector, bool enable, int direction);    int (*hdmi_cec_init)(struct drm_bridge *bridge, struct drm_connector *connector);    int (*hdmi_cec_enable)(struct drm_bridge *bridge, bool enable);    int (*hdmi_cec_log_addr)(struct drm_bridge *bridge, u8 logical_addr);    int (*hdmi_cec_transmit)(struct drm_bridge *bridge, u8 attempts, u32 signal_free_time, struct cec_msg *msg);    int (*dp_audio_startup)(struct drm_bridge *bridge, struct drm_connector *connector);    int (*dp_audio_prepare)(struct drm_bridge *bridge, struct drm_connector *connector, struct hdmi_codec_daifmt *fmt, struct hdmi_codec_params *hparms);    void (*dp_audio_shutdown)(struct drm_bridge *bridge, struct drm_connector *connector);    int (*dp_audio_mute_stream)(struct drm_bridge *bridge, struct drm_connector *connector, bool enable, int direction);    void (*debugfs_init)(struct drm_bridge *bridge, struct dentry *root);};

Members

attach

This callback is invoked whenever our bridge is being attached to adrm_encoder. The flags argument tunes the behaviour of the attachoperation (see DRM_BRIDGE_ATTACH_*).

Theattach callback is optional.

RETURNS:

Zero on success, error code on failure.

destroy

This callback is invoked when the bridge is about to bedeallocated.

Thedestroy callback is optional.

detach

This callback is invoked whenever our bridge is being detached from adrm_encoder.

Thedetach callback is optional.

mode_valid

This callback is used to check if a specific mode is valid in thisbridge. This should be implemented if the bridge has some sort ofrestriction in the modes it can display. For example, a given bridgemay be responsible to set a clock value. If the clock can notproduce all the values for the available modes then this callbackcan be used to restrict the number of modes to only the ones thatcan be displayed.

This hook is used by the probe helpers to filter the mode list indrm_helper_probe_single_connector_modes(), and it is used by theatomic helpers to validate modes supplied by userspace indrm_atomic_helper_check_modeset().

Themode_valid callback is optional.

NOTE:

Since this function is both called from the check phase of an atomiccommit, and the mode validation in the probe paths it is not allowedto look at anything else but the passed-in mode, and validate itagainst configuration-invariant hardware constraints. Any furtherlimits which depend upon the configuration can only be checked inmode_fixup.

RETURNS:

drm_mode_status Enum

mode_fixup

This callback is used to validate and adjust a mode. The parametermode is the display mode that should be fed to the next element inthe display chain, either the finaldrm_connector or the nextdrm_bridge. The parameter adjusted_mode is the input mode the bridgerequires. It can be modified by this callback and does not need tomatch mode. See alsodrm_crtc_state.adjusted_mode for more details.

This is the only hook that allows a bridge to reject a modeset. Ifthis function passes all other callbacks must succeed for thisconfiguration.

The mode_fixup callback is optional.drm_bridge_funcs.mode_fixup()is not called whendrm_bridge_funcs.atomic_check() is implemented,so only one of them should be provided.

NOTE:

This function is called in the check phase of atomic modesets, whichcan be aborted for any reason (including on userspace’s request tojust check whether a configuration would be possible). Drivers MUSTNOT touch any persistent state (hardware or software) or datastructures except the passed instate parameter.

Also beware that userspace can request its own custom modes, neithercore nor helpers filter modes to the list of probe modes reported bythe GETCONNECTOR IOCTL and stored indrm_connector.modes. To ensurethat modes are filtered consistently put any bridge constraints andlimits checks intomode_valid.

RETURNS:

True if an acceptable configuration is possible, false if the modesetoperation should be rejected.

disable

This callback should disable the bridge. It is called right beforethe preceding element in the display pipe is disabled. If thepreceding element is a bridge this means it’s called before thatbridge’sdisable vfunc. If the preceding element is adrm_encoderit’s called right before thedrm_encoder_helper_funcs.disable,drm_encoder_helper_funcs.prepare ordrm_encoder_helper_funcs.dpmshook.

The bridge can assume that the display pipe (i.e. clocks and timingsignals) feeding it is still running when this callback is called.

Thedisable callback is optional.

NOTE:

This is deprecated, do not use!New drivers shall usedrm_bridge_funcs.atomic_disable.

post_disable

This callback should disable the bridge. It is called right after thepreceding element in the display pipe is disabled. If the precedingelement is a bridge this means it’s called after that bridge’spost_disable function. If the preceding element is adrm_encoderit’s called right after the encoder’sdrm_encoder_helper_funcs.disable,drm_encoder_helper_funcs.prepareordrm_encoder_helper_funcs.dpms hook.

The bridge must assume that the display pipe (i.e. clocks and timingsignals) feeding it is no longer running when this callback iscalled.

Thepost_disable callback is optional.

NOTE:

This is deprecated, do not use!New drivers shall usedrm_bridge_funcs.atomic_post_disable.

mode_set

This callback should set the given mode on the bridge. It is calledafter themode_set callback for the preceding element in the displaypipeline has been called already. If the bridge is the first elementthen this would bedrm_encoder_helper_funcs.mode_set. The displaypipe (i.e. clocks and timing signals) is off when this function iscalled.

The adjusted_mode parameter is the mode output by the CRTC for thefirst bridge in the chain. It can be different from the modeparameter that contains the desired mode for the connector at the endof the bridges chain, for instance when the first bridge in the chainperforms scaling. The adjusted mode is mostly useful for the firstbridge in the chain and is likely irrelevant for the other bridges.

For atomic drivers the adjusted_mode is the mode stored indrm_crtc_state.adjusted_mode.

NOTE:

This is deprecated, do not use!New drivers shall set their mode in thedrm_bridge_funcs.atomic_enable operation.

pre_enable

This callback should enable the bridge. It is called right beforethe preceding element in the display pipe is enabled. If thepreceding element is a bridge this means it’s called before thatbridge’spre_enable function. If the preceding element is adrm_encoder it’s called right before the encoder’sdrm_encoder_helper_funcs.enable,drm_encoder_helper_funcs.commit ordrm_encoder_helper_funcs.dpms hook.

The display pipe (i.e. clocks and timing signals) feeding this bridgewill not yet be running when this callback is called. The bridge mustnot enable the display link feeding the next bridge in the chain (ifthere is one) when this callback is called.

Thepre_enable callback is optional.

NOTE:

This is deprecated, do not use!New drivers shall usedrm_bridge_funcs.atomic_pre_enable.

enable

This callback should enable the bridge. It is called right afterthe preceding element in the display pipe is enabled. If thepreceding element is a bridge this means it’s called after thatbridge’senable function. If the preceding element is adrm_encoder it’s called right after the encoder’sdrm_encoder_helper_funcs.enable,drm_encoder_helper_funcs.commit ordrm_encoder_helper_funcs.dpms hook.

The bridge can assume that the display pipe (i.e. clocks and timingsignals) feeding it is running when this callback is called. Thiscallback must enable the display link feeding the next bridge in thechain if there is one.

Theenable callback is optional.

NOTE:

This is deprecated, do not use!New drivers shall usedrm_bridge_funcs.atomic_enable.

atomic_pre_enable

This callback should enable the bridge. It is called right beforethe preceding element in the display pipe is enabled. If thepreceding element is a bridge this means it’s called before thatbridge’satomic_pre_enable orpre_enable function. If the precedingelement is adrm_encoder it’s called right before the encoder’sdrm_encoder_helper_funcs.atomic_enable hook.

The display pipe (i.e. clocks and timing signals) feeding this bridgewill not yet be running when this callback is called. The bridge mustnot enable the display link feeding the next bridge in the chain (ifthere is one) when this callback is called.

Theatomic_pre_enable callback is optional.

atomic_enable

This callback should enable the bridge. It is called right afterthe preceding element in the display pipe is enabled. If thepreceding element is a bridge this means it’s called after thatbridge’satomic_enable orenable function. If the preceding elementis adrm_encoder it’s called right after the encoder’sdrm_encoder_helper_funcs.atomic_enable hook.

The bridge can assume that the display pipe (i.e. clocks and timingsignals) feeding it is running when this callback is called. Thiscallback must enable the display link feeding the next bridge in thechain if there is one.

Theatomic_enable callback is optional.

atomic_disable

This callback should disable the bridge. It is called right beforethe preceding element in the display pipe is disabled. If thepreceding element is a bridge this means it’s called before thatbridge’satomic_disable ordisable vfunc. If the preceding elementis adrm_encoder it’s called right before thedrm_encoder_helper_funcs.atomic_disable hook.

The bridge can assume that the display pipe (i.e. clocks and timingsignals) feeding it is still running when this callback is called.

Theatomic_disable callback is optional.

atomic_post_disable

This callback should disable the bridge. It is called right after thepreceding element in the display pipe is disabled. If the precedingelement is a bridge this means it’s called after that bridge’satomic_post_disable orpost_disable function. If the precedingelement is adrm_encoder it’s called right after the encoder’sdrm_encoder_helper_funcs.atomic_disable hook.

The bridge must assume that the display pipe (i.e. clocks and timingsignals) feeding it is no longer running when this callback iscalled.

Theatomic_post_disable callback is optional.

atomic_duplicate_state

Duplicate the current bridge state object (which is guaranteed to benon-NULL).

The atomic_duplicate_state hook is mandatory if the bridgeimplements any of the atomic hooks, and should be left unassignedotherwise. For bridges that don’t subclassdrm_bridge_state, thedrm_atomic_helper_bridge_duplicate_state() helper function shall beused to implement this hook.

RETURNS:A valid drm_bridge_state object or NULL if the allocation fails.

atomic_destroy_state

Destroy a bridge state object previously allocated bydrm_bridge_funcs.atomic_duplicate_state().

The atomic_destroy_state hook is mandatory if the bridge implementsany of the atomic hooks, and should be left unassigned otherwise.For bridges that don’t subclassdrm_bridge_state, thedrm_atomic_helper_bridge_destroy_state() helper function shall beused to implement this hook.

atomic_get_output_bus_fmts

Return the supported bus formats on the output end of a bridge.The returned array must be allocated withkmalloc() and will befreed by the caller. If the allocation fails, NULL should bereturned. num_output_fmts must be set to the returned array size.Formats listed in the returned array should be listed in decreasingpreference order (the core will try all formats until it finds onethat works).

This method is only called on the last element of the bridge chainas part of the bus format negotiation process that happens indrm_atomic_bridge_chain_select_bus_fmts`().Thismethodisoptional.Whennotimplemented,thecorewillfallbackto:c:type:`drm_connector.display_info.bus_formats[0] ifdrm_connector.display_info.num_bus_formats > 0,or to MEDIA_BUS_FMT_FIXED otherwise.

atomic_get_input_bus_fmts

Return the supported bus formats on the input end of a bridge fora specific output bus format.

The returned array must be allocated withkmalloc() and will befreed by the caller. If the allocation fails, NULL should bereturned. num_input_fmts must be set to the returned array size.Formats listed in the returned array should be listed in decreasingpreference order (the core will try all formats until it finds onethat works). When the format is not supported NULL should bereturned and num_input_fmts should be set to 0.

This method is called on all elements of the bridge chain as part ofthe bus format negotiation process that happens indrm_atomic_bridge_chain_select_bus_fmts().This method is optional. When not implemented, the core will bypassbus format negotiation on this element of the bridge withoutfailing, and the previous element in the chain will be passedMEDIA_BUS_FMT_FIXED as its output bus format.

Bridge drivers that need to support being linked to bridges that arenot supporting bus format negotiation should handle theoutput_fmt == MEDIA_BUS_FMT_FIXED case appropriately, by selecting asensible default value or extracting this information from somewhereelse (FW property,drm_display_mode,drm_display_info, ...)

Note: Even if input format selection on the first bridge has noimpact on the negotiation process (bus format negotiation stops oncewe reach the first element of the chain), drivers are expected toreturn accurate input formats as the input format may be used toconfigure the CRTC output appropriately.

atomic_check

This method is responsible for checking bridge state correctness.It can also check the state of the surrounding components in chainto make sure the whole pipeline can work properly.

drm_bridge_funcs.atomic_check() hooks are called in reverseorder (from the last to the first bridge).

This method is optional.drm_bridge_funcs.mode_fixup() is notcalled whendrm_bridge_funcs.atomic_check() is implemented, so onlyone of them should be provided.

If drivers need to tweakdrm_bridge_state.input_bus_cfg.flags ordrm_bridge_state.output_bus_cfg.flags it should happen inthis function. By default thedrm_bridge_state.output_bus_cfg.flagsfield is set to the next bridgedrm_bridge_state.input_bus_cfg.flags value ordrm_connector.display_info.bus_flags if the bridge is the lastelement in the chain.

RETURNS:zero if the check passed, a negative error code otherwise.

atomic_reset

Reset the bridge to a predefined state (or retrieve its currentstate) and return adrm_bridge_state object matching this state.This function is called at attach time.

The atomic_reset hook is mandatory if the bridge implements any ofthe atomic hooks, and should be left unassigned otherwise. Forbridges that don’t subclassdrm_bridge_state, thedrm_atomic_helper_bridge_reset() helper function shall be used toimplement this hook.

Note that theatomic_reset() semantics is not exactly matching thereset() semantics found on other components (connector, plane, ...).

  1. The reset operation happens when the bridge is attached, not whendrm_mode_config_reset() is called

  2. It’s meant to be used exclusively on bridges that have beenconverted to the ATOMIC API

RETURNS:A valid drm_bridge_state object in case of success, anERR_PTR()giving the reason of the failure otherwise.

detect

Check if anything is attached to the bridge output.

This callback is optional, if not implemented the bridge will beconsidered as always having a component attached to its output.Bridges that implement this callback shall set theDRM_BRIDGE_OP_DETECT flag in theirdrm_bridge->ops.

RETURNS:

drm_connector_status indicating the bridge output status.

get_modes

Fill all modes currently valid for the sink into thedrm_connectorwithdrm_mode_probed_add().

Theget_modes callback is mostly intended to support non-probeabledisplays such as many fixed panels. Bridges that support readingEDID shall leaveget_modes unimplemented and implement thedrm_bridge_funcs->edid_read callback instead.

This callback is optional. Bridges that implement it shall set theDRM_BRIDGE_OP_MODES flag in theirdrm_bridge->ops.

The connector parameter shall be used for the sole purpose offilling modes, and shall not be stored internally by bridge driversfor future usage.

RETURNS:

The number of modes added by callingdrm_mode_probed_add().

edid_read

Read the EDID data of the connected display.

Theedid_read callback is the preferred way of reporting modeinformation for a display connected to the bridge output. Bridgesthat support reading EDID shall implement this callback and leavetheget_modes callback unimplemented.

The caller of this operation shall first verify the outputconnection status and refrain from reading EDID from a disconnectedoutput.

This callback is optional. Bridges that implement it shall set theDRM_BRIDGE_OP_EDID flag in theirdrm_bridge->ops.

The connector parameter shall be used for the sole purpose of EDIDretrieval, and shall not be stored internally by bridge drivers forfuture usage.

RETURNS:

An edid structure newly allocated withdrm_edid_alloc() or returnedfromdrm_edid_read() family of functions on success, or NULLotherwise. The caller is responsible for freeing the returned edidstructure withdrm_edid_free().

hpd_notify

Notify the bridge of hot plug detection.

This callback is optional, it may be implemented by bridges thatneed to be notified of display connection or disconnection forinternal reasons. One use case is to reset the internal state of CECcontrollers for HDMI bridges.

hpd_enable

Enable hot plug detection. From now on the bridge shall calldrm_bridge_hpd_notify() each time a change is detected in the outputconnection status, until hot plug detection gets disabled withhpd_disable.

This callback is optional and shall only be implemented by bridgesthat support hot-plug notification without polling. Bridges thatimplement it shall also implement thehpd_disable callback and setthe DRM_BRIDGE_OP_HPD flag in theirdrm_bridge->ops.

hpd_disable

Disable hot plug detection. Once this function returns the bridgeshall not calldrm_bridge_hpd_notify() when a change in the outputconnection status occurs.

This callback is optional and shall only be implemented by bridgesthat support hot-plug notification without polling. Bridges thatimplement it shall also implement thehpd_enable callback and setthe DRM_BRIDGE_OP_HPD flag in theirdrm_bridge->ops.

hdmi_tmds_char_rate_valid

Check whether a particular TMDS character rate is supported by thedriver.

This callback is optional and should only be implemented by thebridges that take part in the HDMI connector implementation. Bridgesthat implement it shall set the DRM_BRIDGE_OP_HDMI flag in theirdrm_bridge->ops.

Returns:

Eitherdrm_mode_status.MODE_OK or one of the failure reasonsinenumdrm_mode_status.

hdmi_clear_avi_infoframe

This callback clears the infoframes in the hardware during commit.

This callback is optional but it must be implemented by bridges thatset the DRM_BRIDGE_OP_HDMI flag in theirdrm_bridge->ops.

hdmi_write_avi_infoframe

Program the infoframe into the hardware.

This callback is optional but it must be implemented by bridges thatset the DRM_BRIDGE_OP_HDMI flag in theirdrm_bridge->ops.

hdmi_clear_hdmi_infoframe

This callback clears the infoframes in the hardware during commit.

This callback is optional but it must be implemented by bridges thatset the DRM_BRIDGE_OP_HDMI flag in theirdrm_bridge->ops.

hdmi_write_hdmi_infoframe

Program the infoframe into the hardware.

This callback is optional but it must be implemented by bridges thatset the DRM_BRIDGE_OP_HDMI flag in theirdrm_bridge->ops.

hdmi_clear_hdr_drm_infoframe

This callback clears the infoframes in the hardware during commit.

This callback is optional but it must be implemented by bridges thatset the DRM_BRIDGE_OP_HDMI_HDR_DRM_INFOFRAME flag in theirdrm_bridge->ops.

hdmi_write_hdr_drm_infoframe

Program the infoframe into the hardware.

This callback is optional but it must be implemented by bridges thatset the DRM_BRIDGE_OP_HDMI_HDR_DRM_INFOFRAME flag in theirdrm_bridge->ops.

hdmi_clear_spd_infoframe

This callback clears the infoframes in the hardware during commit.

This callback is optional but it must be implemented by bridges thatset the DRM_BRIDGE_OP_HDMI_SPD_INFOFRAME flag in theirdrm_bridge->ops.

hdmi_write_spd_infoframe

Program the infoframe into the hardware.

This callback is optional but it must be implemented by bridges thatset the DRM_BRIDGE_OP_HDMI_SPD_INFOFRAME flag in theirdrm_bridge->ops.

hdmi_clear_audio_infoframe

This callback clears the infoframes in the hardware during commit.

This callback is optional but it must be implemented by bridges thatset the DRM_BRIDGE_OP_HDMI_AUDIO flag in theirdrm_bridge->ops.

hdmi_write_audio_infoframe

Program the infoframe into the hardware.

This callback is optional but it must be implemented by bridges thatset the DRM_BRIDGE_OP_HDMI_AUDIO flag in theirdrm_bridge->ops.

hdmi_audio_startup

Called when ASoC starts an audio stream setup.

This callback is optional, it can be implemented by bridges thatset theDRM_BRIDGE_OP_HDMI_AUDIO flag in theirdrm_bridge->ops.

Returns:0 on success, a negative error code otherwise

hdmi_audio_prepare

Configures HDMI-encoder for audio stream. Can be called multipletimes for each setup.

This callback is optional but it must be implemented by bridges thatset theDRM_BRIDGE_OP_HDMI_AUDIO flag in theirdrm_bridge->ops.

Returns:0 on success, a negative error code otherwise

hdmi_audio_shutdown

Shut down the audio stream.

This callback is optional but it must be implemented by bridges thatset theDRM_BRIDGE_OP_HDMI_AUDIO flag in theirdrm_bridge->ops.

Returns:0 on success, a negative error code otherwise

hdmi_audio_mute_stream

Mute/unmute HDMI audio stream.

This callback is optional, it can be implemented by bridges thatset theDRM_BRIDGE_OP_HDMI_AUDIO flag in theirdrm_bridge->ops.

Returns:0 on success, a negative error code otherwise

hdmi_cec_init

Initialize CEC part of the bridge.

This callback is optional, it can be implemented by bridges thatset theDRM_BRIDGE_OP_HDMI_CEC_ADAPTER flag in theirdrm_bridge->ops.

Returns:0 on success, a negative error code otherwise

hdmi_cec_enable

Enable or disable the CEC adapter inside the bridge.

This callback is optional, it can be implemented by bridges thatset theDRM_BRIDGE_OP_HDMI_CEC_ADAPTER flag in theirdrm_bridge->ops.

Returns:0 on success, a negative error code otherwise

hdmi_cec_log_addr

Set the logical address of the CEC adapter inside the bridge.

This callback is optional, it can be implemented by bridges thatset theDRM_BRIDGE_OP_HDMI_CEC_ADAPTER flag in theirdrm_bridge->ops.

Returns:0 on success, a negative error code otherwise

hdmi_cec_transmit

Transmit the message using the CEC adapter inside the bridge.

This callback is optional, it can be implemented by bridges thatset theDRM_BRIDGE_OP_HDMI_CEC_ADAPTER flag in theirdrm_bridge->ops.

Returns:0 on success, a negative error code otherwise

dp_audio_startup

Called when ASoC starts a DisplayPort audio stream setup.

This callback is optional, it can be implemented by bridges thatset theDRM_BRIDGE_OP_DP_AUDIO flag in theirdrm_bridge->ops.

Returns:0 on success, a negative error code otherwise

dp_audio_prepare

Configures DisplayPort audio stream. Can be called multipletimes for each setup.

This callback is optional but it must be implemented by bridges thatset theDRM_BRIDGE_OP_DP_AUDIO flag in theirdrm_bridge->ops.

Returns:0 on success, a negative error code otherwise

dp_audio_shutdown

Shut down the DisplayPort audio stream.

This callback is optional but it must be implemented by bridges thatset theDRM_BRIDGE_OP_DP_AUDIO flag in theirdrm_bridge->ops.

Returns:0 on success, a negative error code otherwise

dp_audio_mute_stream

Mute/unmute DisplayPort audio stream.

This callback is optional, it can be implemented by bridges thatset theDRM_BRIDGE_OP_DP_AUDIO flag in theirdrm_bridge->ops.

Returns:0 on success, a negative error code otherwise

debugfs_init

Allows bridges to create bridge-specific debugfs files.

structdrm_bridge_timings

timing information for the bridge

Definition:

struct drm_bridge_timings {    u32 input_bus_flags;    u32 setup_time_ps;    u32 hold_time_ps;    bool dual_link;};

Members

input_bus_flags

Tells what additional settings for the pixel data on the busthis bridge requires (like pixel signal polarity). See alsodrm_display_info->bus_flags.

setup_time_ps

Defines the time in picoseconds the input data lines must bestable before the clock edge.

hold_time_ps

Defines the time in picoseconds taken for the bridge to sample theinput signal after the clock edge.

dual_link

True if the bus operates in dual-link mode. The exact meaning isdependent on the bus type. For LVDS buses, this indicates that even-and odd-numbered pixels are received on separate links.

enumdrm_bridge_ops

Bitmask of operations supported by the bridge

Constants

DRM_BRIDGE_OP_DETECT

The bridge can detect displays connected toits output. Bridges that set this flag shall implement thedrm_bridge_funcs->detect callback.

DRM_BRIDGE_OP_EDID

The bridge can retrieve the EDID of the displayconnected to its output. Bridges that set this flag shall implementthedrm_bridge_funcs->edid_read callback.

DRM_BRIDGE_OP_HPD

The bridge can detect hot-plug and hot-unplugwithout requiring polling. Bridges that set this flag shallimplement thedrm_bridge_funcs->hpd_enable anddrm_bridge_funcs->hpd_disable callbacks if they support enablingand disabling hot-plug detection dynamically.

DRM_BRIDGE_OP_MODES

The bridge can retrieve the modes supportedby the display at its output. This does not include reading EDIDwhich is separately covered byDRM_BRIDGE_OP_EDID. Bridges that setthis flag shall implement thedrm_bridge_funcs->get_modes callback.

DRM_BRIDGE_OP_HDMI

The bridge provides HDMI connector operations,including infoframes support. Bridges that set this flag mustprovide HDMI-related information and implement thedrm_bridge_funcs->clear_avi_infoframe,drm_bridge_funcs->write_avi_infoframe,drm_bridge_funcs->clear_hdmi_infoframe anddrm_bridge_funcs->write_hdmi_infoframe callbacks.

Note: currently there can be at most one bridge in a chain that setsthis bit. This is to simplify corresponding glue code in connectordrivers.

DRM_BRIDGE_OP_HDMI_AUDIO

The bridge provides HDMI audio operations.Bridges that set this flag must implement thedrm_bridge_funcs->hdmi_audio_prepare anddrm_bridge_funcs->hdmi_audio_shutdown callbacks.If the bridge implementsDRM_BRIDGE_OP_HDMI, it also must implementdrm_bridge_funcs->hdmi_write_audio_infoframe anddrm_bridge_funcs->hdmi_cleaer_audio_infoframe callbacks.

Note: currently there can be at most one bridge in a chain that setsthis bit. This is to simplify corresponding glue code in connectordrivers. Also it is not possible to have a bridge in the chain thatsetsDRM_BRIDGE_OP_DP_AUDIO if there is a bridge that sets thisflag.

DRM_BRIDGE_OP_DP_AUDIO

The bridge provides DisplayPort audio operations.Bridges that set this flag must implement thedrm_bridge_funcs->dp_audio_prepare anddrm_bridge_funcs->dp_audio_shutdown callbacks.

Note: currently there can be at most one bridge in a chain that setsthis bit. This is to simplify corresponding glue code in connectordrivers. Also it is not possible to have a bridge in the chain thatsetsDRM_BRIDGE_OP_HDMI_AUDIO if there is a bridge that sets thisflag.

DRM_BRIDGE_OP_HDMI_CEC_NOTIFIER

The bridge requires CEC notifierto be present.

DRM_BRIDGE_OP_HDMI_CEC_ADAPTER

The bridge requires CEC adapterto be present.

DRM_BRIDGE_OP_HDMI_HDR_DRM_INFOFRAME

The bridge supportsdrm_bridge_funcs->hdmi_write_hdr_drm_infoframe anddrm_bridge_funcs->hdmi_clear_hdr_drm_infoframe callbacks.

DRM_BRIDGE_OP_HDMI_SPD_INFOFRAME

The bridge supportsdrm_bridge_funcs->hdmi_write_spd_infoframe anddrm_bridge_funcs->hdmi_clear_spd_infoframe callbacks.

structdrm_bridge

central DRM bridge control structure

Definition:

struct drm_bridge {    struct drm_private_obj base;    struct drm_device *dev;    struct drm_encoder *encoder;    struct list_head chain_node;    struct device_node *of_node;    struct list_head list;    const struct drm_bridge_timings *timings;    const struct drm_bridge_funcs *funcs;    void *container;    struct kref refcount;    bool unplugged;    void *driver_private;    enum drm_bridge_ops ops;    int type;    bool interlace_allowed;    bool ycbcr_420_allowed;    bool pre_enable_prev_first;    bool support_hdcp;    struct i2c_adapter *ddc;    const char *vendor;    const char *product;    unsigned int supported_formats;    unsigned int max_bpc;    struct device *hdmi_cec_dev;    struct device *hdmi_audio_dev;    int hdmi_audio_max_i2s_playback_channels;    u64 hdmi_audio_i2s_formats;    unsigned int hdmi_audio_spdif_playback : 1;    int hdmi_audio_dai_port;    const char *hdmi_cec_adapter_name;    u8 hdmi_cec_available_las;    struct mutex hpd_mutex;    void (*hpd_cb)(void *data, enum drm_connector_status status);    void *hpd_data;    struct drm_bridge *next_bridge;};

Members

base

inherit fromdrm_private_object

dev

DRM device this bridge belongs to

encoder

encoder to which this bridge is connected

chain_node

used to form a bridge chain

of_node

device node pointer to the bridge

list

to keep track of all added bridges

timings

the timing specification for the bridge, if any (may be NULL)

funcs

control functions

container

Pointer to the private driverstructembedding thisstruct drm_bridge.

refcount

reference count of users referencing this bridge.

unplugged

Flag to tell if the bridge has been unplugged.Seedrm_bridge_enter() anddrm_bridge_unplug().

driver_private

pointer to the bridge driver’s internal context

ops

bitmask of operations supported by the bridge

type

Type of the connection at the bridge output(DRM_MODE_CONNECTOR_*). For bridges at the end of this chain thisidentifies the type of connected display.

interlace_allowed

Indicate that the bridge can handle interlacedmodes.

ycbcr_420_allowed

Indicate that the bridge can handle YCbCr 420output.

pre_enable_prev_first

The bridge requires that the prevbridgepre_enable function is called before itspre_enable,and conversely for post_disable. This is most frequently arequirement for DSI devices which need the host to be initialisedbefore the peripheral.

support_hdcp

Indicate that the bridge supports HDCP.

ddc

Associated I2C adapter for DDC access, if any.

vendor

Vendor of the product to be used for the SPD InfoFramegeneration. This is required ifDRM_BRIDGE_OP_HDMI is set.

product

Name of the product to be used for the SPD InfoFramegeneration. This is required ifDRM_BRIDGE_OP_HDMI is set.

supported_formats

Bitmask ofhdmi_colorspace listing supportedoutput formats. This is only relevant ifDRM_BRIDGE_OP_HDMI is set.

max_bpc

Maximum bits per char the HDMI bridge supports. Allowedvalues are 8, 10 and 12. This is only relevant ifDRM_BRIDGE_OP_HDMI is set.

hdmi_cec_dev

device to be used as a containing device for CECfunctions.

hdmi_audio_dev

device to be used as a parent for the HDMI Codec ifeither ofDRM_BRIDGE_OP_HDMI_AUDIO orDRM_BRIDGE_OP_DP_AUDIO is set.

hdmi_audio_max_i2s_playback_channels

maximum number of playbackI2S channels for theDRM_BRIDGE_OP_HDMI_AUDIO orDRM_BRIDGE_OP_DP_AUDIO.

hdmi_audio_i2s_formats

supported I2S formats, optional. Thedefault is to allow all formats supported by the corresponding I2Sbus driver. This is only used for bridges settingDRM_BRIDGE_OP_HDMI_AUDIO orDRM_BRIDGE_OP_DP_AUDIO.

hdmi_audio_spdif_playback

set if this bridge has S/PDIF playbackport forDRM_BRIDGE_OP_HDMI_AUDIO orDRM_BRIDGE_OP_DP_AUDIO.

hdmi_audio_dai_port

sound DAI port for either ofDRM_BRIDGE_OP_HDMI_AUDIO andDRM_BRIDGE_OP_DP_AUDIO, -1 if it isnot used.

hdmi_cec_adapter_name

the name of the adapter to register

hdmi_cec_available_las

number of logical addresses, CEC_MAX_LOG_ADDRS if unset

hpd_mutex

Protects thehpd_cb andhpd_data fields.

hpd_cb

Hot plug detection callback, registered withdrm_bridge_hpd_enable().

hpd_data

Private data passed to the Hot plug detection callbackhpd_cb.

next_bridge

Pointer to the following bridge, automatically putwhen this bridge is freed (i.e. at destroy time). This is fordrivers needing to store a pointer to the next bridge in thechain, and ensures any code still holding a reference to thisbridge after its removal cannot use-after-free the nextbridge. Any other bridge pointers stored by the driver must beput in the .destroy callback by driver code.

devm_drm_bridge_alloc

devm_drm_bridge_alloc(dev,type,member,funcs)

Allocate and initialize a bridge

Parameters

dev

structdevice of the bridge device

type

the type of thestructwhich contains structdrm_bridge

member

the name of thedrm_bridge withintype

funcs

callbacks for this bridge

Description

The reference count of the returned bridge is initialized to 1. Thisreference will be automatically dropped via devm (by callingdrm_bridge_put()) whendev is removed.

Return

Pointer to new bridge, or ERR_PTR on failure.

structdrm_bridge_state*drm_bridge_get_current_state(structdrm_bridge*bridge)

Get the current bridge state

Parameters

structdrm_bridge*bridge

bridge object

Description

This function must be called with the modeset lock held.

The current bridge state, or NULL if there is none.

structdrm_bridge*drm_bridge_get_next_bridge(structdrm_bridge*bridge)

Get the next bridge in the chain

Parameters

structdrm_bridge*bridge

bridge object

Description

The caller is responsible of having a reference tobridge viadrm_bridge_get() or equivalent. This function leaves the refcount ofbridge unmodified.

The refcount of the returned bridge is incremented. Usedrm_bridge_put()when done with it.

Return

the next bridge in the chain afterbridge, or NULL ifbridge is the last.

structdrm_bridge*drm_bridge_get_prev_bridge(structdrm_bridge*bridge)

Get the previous bridge in the chain

Parameters

structdrm_bridge*bridge

bridge object

Description

The caller is responsible of having a reference tobridge viadrm_bridge_get() or equivalent. This function leaves the refcount ofbridge unmodified.

The refcount of the returned bridge is incremented. Usedrm_bridge_put()when done with it.

Return

the previous bridge in the chain, or NULL ifbridge is the first.

structdrm_bridge*drm_bridge_chain_get_first_bridge(structdrm_encoder*encoder)

Get the first bridge in the chain

Parameters

structdrm_encoder*encoder

encoder object

Description

The refcount of the returned bridge is incremented. Usedrm_bridge_put()when done with it.

Return

the first bridge in the chain, or NULL ifencoder has no bridge attachedto it.

structdrm_bridge*drm_bridge_chain_get_last_bridge(structdrm_encoder*encoder)

Get the last bridge in the chain

Parameters

structdrm_encoder*encoder

encoder object

Description

The refcount of the returned bridge is incremented. Usedrm_bridge_put()when done with it.

Return

the last bridge in the chain, or NULL ifencoder has no bridge attachedto it.

structdrm_bridge*drm_bridge_get_next_bridge_and_put(structdrm_bridge*bridge)

Get the next bridge in the chain and put the previous

Parameters

structdrm_bridge*bridge

bridge object

Description

Same asdrm_bridge_get_next_bridge() but additionally puts thebridge.

Return

the next bridge in the chain afterbridge, or NULL ifbridge is the last.

drm_for_each_bridge_in_chain_scoped

drm_for_each_bridge_in_chain_scoped(encoder,bridge)

iterate over all bridges attached to an encoder

Parameters

encoder

the encoder to iterate bridges on

bridge

a bridge pointer updated to point to the current bridge at eachiteration

Description

Iterate over all bridges present in the bridge chain attached toencoder.

Automatically gets/puts the bridge reference while iterating, and putsthe reference even if returning or breaking in the middle of the loop.

drm_for_each_bridge_in_chain_from

drm_for_each_bridge_in_chain_from(first_bridge,bridge)

iterate over all bridges starting from the given bridge

Parameters

first_bridge

the bridge to start from

bridge

a bridge pointer updated to point to the current bridge at eachiteration

Description

Iterate over all bridges in the encoder chain starting fromfirst_bridge, included.

Automatically gets/puts the bridge reference while iterating, and putsthe reference even if returning or breaking in the middle of the loop.

booldrm_bridge_enter(structdrm_bridge*bridge,int*idx)

Enter DRM bridge critical section

Parameters

structdrm_bridge*bridge

DRM bridge

int*idx

Pointer to index that will be passed to the matchingdrm_bridge_exit()

Description

This function marks and protects the beginning of a section that should notbe entered after the bridge has been unplugged. The section end is markedwithdrm_bridge_exit(). Calls to this function can be nested.

Return

True if it is OK to enter the section, false otherwise.

voiddrm_bridge_exit(intidx)

Exit DRM bridge critical section

Parameters

intidx

index returned bydrm_bridge_enter()

Description

This function marks the end of a section that should not be entered afterthe bridge has been unplugged.

voiddrm_bridge_unplug(structdrm_bridge*bridge)

declare a DRM bridge was unplugged and remove it

Parameters

structdrm_bridge*bridge

DRM bridge

Description

This tells the bridge has been physically unplugged and no operations ondevice resources must be done anymore. Entry-points can usedrm_bridge_enter() anddrm_bridge_exit() to protect device resources ina race free manner.

Also unregisters the bridge.

structdrm_bridge*drm_bridge_get(structdrm_bridge*bridge)

Acquire a bridge reference

Parameters

structdrm_bridge*bridge

DRM bridge

Description

This function increments the bridge’s refcount.

Return

Pointer tobridge.

voiddrm_bridge_put(structdrm_bridge*bridge)

Release a bridge reference

Parameters

structdrm_bridge*bridge

DRM bridge

Description

This function decrements the bridge’s reference count and frees theobject if the reference count drops to zero.

voiddrm_bridge_add(structdrm_bridge*bridge)

register a bridge

Parameters

structdrm_bridge*bridge

bridge control structure

Description

Add the given bridge to the global list of bridges, where they can befound by users viaof_drm_find_and_get_bridge().

The bridge to be added must have been allocated bydevm_drm_bridge_alloc().

intdevm_drm_bridge_add(structdevice*dev,structdrm_bridge*bridge)

devm managed version ofdrm_bridge_add()

Parameters

structdevice*dev

device to tie the bridge lifetime to

structdrm_bridge*bridge

bridge control structure

Description

This is the managed version ofdrm_bridge_add() which automaticallycallsdrm_bridge_remove() whendev is unbound.

Return

0 if no error or negative error code.

voiddrm_bridge_remove(structdrm_bridge*bridge)

unregister a bridge

Parameters

structdrm_bridge*bridge

bridge control structure

Description

Remove the given bridge from the global list of registered bridges, soit won’t be found by users viaof_drm_find_and_get_bridge(), and add itto the lingering bridge list, to keep track of it until its allocatedmemory is eventually freed.

intdrm_bridge_attach(structdrm_encoder*encoder,structdrm_bridge*bridge,structdrm_bridge*previous,enumdrm_bridge_attach_flagsflags)

attach the bridge to an encoder’s chain

Parameters

structdrm_encoder*encoder

DRM encoder

structdrm_bridge*bridge

bridge to attach

structdrm_bridge*previous

previous bridge in the chain (optional)

enumdrm_bridge_attach_flagsflags

DRM_BRIDGE_ATTACH_* flags

Description

Called by a kms driver to link the bridge to an encoder’s chain. The previousargument specifies the previous bridge in the chain. If NULL, the bridge islinked directly at the encoder’s output. Otherwise it is linked at theprevious bridge’s output.

If non-NULL the previous bridge must be already attached by a call to thisfunction.

The bridge to be attached must have been previously added bydrm_bridge_add().

Note that bridges attached to encoders are auto-detached during encodercleanup indrm_encoder_cleanup(), sodrm_bridge_attach() should generallynot be balanced with adrm_bridge_detach() in driver code.

Return

Zero on success, error code on failure

enumdrm_mode_statusdrm_bridge_chain_mode_valid(structdrm_bridge*bridge,conststructdrm_display_info*info,conststructdrm_display_mode*mode)

validate the mode against all bridges in the encoder chain.

Parameters

structdrm_bridge*bridge

bridge control structure

conststructdrm_display_info*info

display info against which the mode shall be validated

conststructdrm_display_mode*mode

desired mode to be validated

Description

Callsdrm_bridge_funcs.mode_valid for all the bridges in the encoderchain, starting from the first bridge to the last. If at least one bridgedoes not accept the mode the function returns the error code.

Note

the bridge passed should be the one closest to the encoder.

Return

MODE_OK on success, drm_mode_status Enum error code on failure

voiddrm_bridge_chain_mode_set(structdrm_bridge*bridge,conststructdrm_display_mode*mode,conststructdrm_display_mode*adjusted_mode)

set proposed mode for all bridges in the encoder chain

Parameters

structdrm_bridge*bridge

bridge control structure

conststructdrm_display_mode*mode

desired mode to be set for the encoder chain

conststructdrm_display_mode*adjusted_mode

updated mode that works for this encoder chain

Description

Callsdrm_bridge_funcs.mode_set op for all the bridges in theencoder chain, starting from the first bridge to the last.

Note

the bridge passed should be the one closest to the encoder

voiddrm_atomic_bridge_chain_disable(structdrm_bridge*bridge,structdrm_atomic_state*state)

disables all bridges in the encoder chain

Parameters

structdrm_bridge*bridge

bridge control structure

structdrm_atomic_state*state

atomic state being committed

Description

Callsdrm_bridge_funcs.atomic_disable (falls back ondrm_bridge_funcs.disable) op for all the bridges in the encoder chain,starting from the last bridge to the first. These are called before callingdrm_encoder_helper_funcs.atomic_disable

Note

the bridge passed should be the one closest to the encoder

voiddrm_atomic_bridge_chain_post_disable(structdrm_bridge*bridge,structdrm_atomic_state*state)

cleans up after disabling all bridges in the encoder chain

Parameters

structdrm_bridge*bridge

bridge control structure

structdrm_atomic_state*state

atomic state being committed

Description

Callsdrm_bridge_funcs.atomic_post_disable (falls back ondrm_bridge_funcs.post_disable) op for all the bridges in the encoder chain,starting from the first bridge to the last. These are called after completingdrm_encoder_helper_funcs.atomic_disable

If a bridge setspre_enable_prev_first, then thepost_disable for thatbridge will be called before the previous one to reverse thepre_enablecalling direction.

Example

Bridge A ---> Bridge B ---> Bridge C ---> Bridge D ---> Bridge E

With pre_enable_prev_first flag enable in Bridge B, D, E then the resultingpost_disable order would be,Bridge B, Bridge A, Bridge E, Bridge D, Bridge C.

Note

the bridge passed should be the one closest to the encoder

voiddrm_atomic_bridge_chain_pre_enable(structdrm_bridge*bridge,structdrm_atomic_state*state)

prepares for enabling all bridges in the encoder chain

Parameters

structdrm_bridge*bridge

bridge control structure

structdrm_atomic_state*state

atomic state being committed

Description

Callsdrm_bridge_funcs.atomic_pre_enable (falls back ondrm_bridge_funcs.pre_enable) op for all the bridges in the encoder chain,starting from the last bridge to the first. These are called before callingdrm_encoder_helper_funcs.atomic_enable

If a bridge setspre_enable_prev_first, then the pre_enable for theprev bridge will be called before pre_enable of this bridge.

Example

Bridge A ---> Bridge B ---> Bridge C ---> Bridge D ---> Bridge E

With pre_enable_prev_first flag enable in Bridge B, D, E then the resultingpre_enable order would be,Bridge C, Bridge D, Bridge E, Bridge A, Bridge B.

Note

the bridge passed should be the one closest to the encoder

voiddrm_atomic_bridge_chain_enable(structdrm_bridge*bridge,structdrm_atomic_state*state)

enables all bridges in the encoder chain

Parameters

structdrm_bridge*bridge

bridge control structure

structdrm_atomic_state*state

atomic state being committed

Description

Callsdrm_bridge_funcs.atomic_enable (falls back ondrm_bridge_funcs.enable) op for all the bridges in the encoder chain,starting from the first bridge to the last. These are called after completingdrm_encoder_helper_funcs.atomic_enable

Note

the bridge passed should be the one closest to the encoder

intdrm_atomic_bridge_chain_check(structdrm_bridge*bridge,structdrm_crtc_state*crtc_state,structdrm_connector_state*conn_state)

Do an atomic check on the bridge chain

Parameters

structdrm_bridge*bridge

bridge control structure

structdrm_crtc_state*crtc_state

new CRTC state

structdrm_connector_state*conn_state

new connector state

Description

First trigger a bus format negotiation before callingdrm_bridge_funcs.atomic_check() (falls back ondrm_bridge_funcs.mode_fixup()) op for all the bridges in the encoder chain,starting from the last bridge to the first. These are called before callingdrm_encoder_helper_funcs.atomic_check()

Return

0 on success, a negative error code on failure

enumdrm_connector_statusdrm_bridge_detect(structdrm_bridge*bridge,structdrm_connector*connector)

check if anything is attached to the bridge output

Parameters

structdrm_bridge*bridge

bridge control structure

structdrm_connector*connector

attached connector

Description

If the bridge supports output detection, as reported by theDRM_BRIDGE_OP_DETECT bridge ops flag, calldrm_bridge_funcs.detect for thebridge and return the connection status. Otherwise returnconnector_status_unknown.

Return

The detection status on success, or connector_status_unknown if the bridgedoesn’t support output detection.

intdrm_bridge_get_modes(structdrm_bridge*bridge,structdrm_connector*connector)

fill all modes currently valid for the sink into theconnector

Parameters

structdrm_bridge*bridge

bridge control structure

structdrm_connector*connector

the connector to fill with modes

Description

If the bridge supports output modes retrieval, as reported by theDRM_BRIDGE_OP_MODES bridge ops flag, calldrm_bridge_funcs.get_modes tofill the connector with all valid modes and return the number of modesadded. Otherwise return 0.

Return

The number of modes added to the connector.

conststructdrm_edid*drm_bridge_edid_read(structdrm_bridge*bridge,structdrm_connector*connector)

read the EDID data of the connected display

Parameters

structdrm_bridge*bridge

bridge control structure

structdrm_connector*connector

the connector to read EDID for

Description

If the bridge supports output EDID retrieval, as reported by theDRM_BRIDGE_OP_EDID bridge ops flag, calldrm_bridge_funcs.edid_read to getthe EDID and return it. Otherwise return NULL.

Return

The retrieved EDID on success, or NULL otherwise.

voiddrm_bridge_hpd_enable(structdrm_bridge*bridge,void(*cb)(void*data,enumdrm_connector_statusstatus),void*data)

enable hot plug detection for the bridge

Parameters

structdrm_bridge*bridge

bridge control structure

void(*cb)(void*data,enumdrm_connector_statusstatus)

hot-plug detection callback

void*data

data to be passed to the hot-plug detection callback

Description

Calldrm_bridge_funcs.hpd_enable if implemented and register the givencbanddata as hot plug notification callback. From now on thecb will becalled withdata when an output status change is detected by the bridge,until hot plug notification gets disabled withdrm_bridge_hpd_disable().

Hot plug detection is supported only if the DRM_BRIDGE_OP_HPD flag is set inbridge->ops. This function shall not be called when the flag is not set.

Only one hot plug detection callback can be registered at a time, it is anerror to call this function when hot plug detection is already enabled forthe bridge.

voiddrm_bridge_hpd_disable(structdrm_bridge*bridge)

disable hot plug detection for the bridge

Parameters

structdrm_bridge*bridge

bridge control structure

Description

Calldrm_bridge_funcs.hpd_disable if implemented and unregister the hotplug detection callback previously registered withdrm_bridge_hpd_enable().Once this function returns the callback will not be called by the bridgewhen an output status change occurs.

Hot plug detection is supported only if the DRM_BRIDGE_OP_HPD flag is set inbridge->ops. This function shall not be called when the flag is not set.

voiddrm_bridge_hpd_notify(structdrm_bridge*bridge,enumdrm_connector_statusstatus)

notify hot plug detection events

Parameters

structdrm_bridge*bridge

bridge control structure

enumdrm_connector_statusstatus

output connection status

Description

Bridge drivers shall call this function to report hot plug events when theydetect a change in the output status, when hot plug detection has beenenabled bydrm_bridge_hpd_enable().

This function shall be called in a context that can sleep.

structdrm_bridge*of_drm_find_and_get_bridge(structdevice_node*np)

find the bridge corresponding to the device node in the global bridge list

Parameters

structdevice_node*np

device node

Description

The refcount of the returned bridge is incremented. Usedrm_bridge_put()when done with it.

Return

drm_bridge controlstructon success, NULL on failure

structdrm_bridge*of_drm_find_bridge(structdevice_node*np)

find the bridge corresponding to the device node in the global bridge list

Parameters

structdevice_node*np

device node

Description

This function is deprecated. Convert toof_drm_find_and_get_bridge()instead for proper refcounting.

The bridge returned by this function is not refcounted. This isdangerous because the bridge might be deallocated even before the callerhas a chance to use it. To use this function you have to do one of:

Return

drm_bridge controlstructon success, NULL on failure

voiddevm_drm_put_bridge(structdevice*dev,structdrm_bridge*bridge)

Release a bridge reference obtained via devm

Parameters

structdevice*dev

device that got the bridge via devm

structdrm_bridge*bridge

pointer to astructdrm_bridge obtained via devm

Description

Same asdrm_bridge_put() for bridge pointers obtained via devm functionssuch asdevm_drm_bridge_alloc().

This function is a temporary workaround and MUST NOT be used. Manualhandling of bridge lifetime is inherently unsafe.

MIPI-DSI bridge operation

DSI host interfaces are expected to be implemented as bridges rather thanencoders, however there are a few aspects of their operation that need tobe defined in order to provide a consistent interface.

A DSI host should keep the PHY powered down until the pre_enable operation iscalled. All lanes are in an undefined idle state up to this point, and itmust not be assumed that it is LP-11.pre_enable should initialise the PHY, set the data lanes to LP-11, and theclock lane to either LP-11 or HS depending on the mode_flagMIPI_DSI_CLOCK_NON_CONTINUOUS.

Ordinarily the downstream bridge DSI peripheral pre_enable will have beencalled before the DSI host. If the DSI peripheral requires LP-11 and/orthe clock lane to be in HS mode prior to pre_enable, then it can set thepre_enable_prev_first flag to request the pre_enable (andpost_disable) order to be altered to enable the DSI host first.

Either the CRTC being enabled, or the DSI host enable operation should switchthe host to actively transmitting video on the data lanes.

The reverse also applies. The DSI host disable operation or stopping the CRTCshould stop transmitting video, and the data lanes should return to the LP-11state. The DSI hostpost_disable operation should disable the PHY.If thepre_enable_prev_first flag is set, then the DSI peripheral’sbridgepost_disable will be called before the DSI host’s post_disable.

Whilst it is valid to callhost_transfer prior to pre_enable or afterpost_disable, the exact state of the lanes is undefined at this point. TheDSI host should initialise the interface, transmit the data, and then disablethe interface again.

Ultra Low Power State (ULPS) is not explicitly supported by DRM. Ifimplemented, it therefore needs to be handled entirely within the DSI Hostdriver.

Bridge Connector Helper Reference

structdrm_connector*drm_bridge_connector_init(structdrm_device*drm,structdrm_encoder*encoder)

Initialise a connector for a chain of bridges

Parameters

structdrm_device*drm

the DRM device

structdrm_encoder*encoder

the encoder where the bridge chain starts

Description

Allocate, initialise and register adrm_bridge_connector with thedrmdevice. The connector is associated with a chain of bridges that starts attheencoder. All bridges in the chain shall report bridge operation flags(drm_bridge->ops) and bridge output type (drm_bridge->type), and none ofthem may create a DRM connector directly.

Returns a pointer to the new connector on success, or a negative errorpointer otherwise.

Panel-Bridge Helper Reference

booldrm_bridge_is_panel(conststructdrm_bridge*bridge)

Checks if a drm_bridge is a panel_bridge.

Parameters

conststructdrm_bridge*bridge

The drm_bridge to be checked.

Description

Returns true if the bridge is a panel bridge, or false otherwise.

structdrm_bridge*drm_panel_bridge_add(structdrm_panel*panel)

Creates adrm_bridge anddrm_connector that just calls the appropriate functions fromdrm_panel.

Parameters

structdrm_panel*panel

The drm_panel being wrapped. Must be non-NULL.

Description

For drivers converting from directly using drm_panel: The expectedusage pattern is that during either encoder module probe or DSIhost attach, a drm_panel will be looked up throughdrm_of_find_panel_or_bridge().drm_panel_bridge_add() is used towrap that panel in the new bridge, and the result can then bepassed todrm_bridge_attach(). Thedrm_panel_prepare() and relatedfunctions can be dropped from the encoder driver (they’re nowcalled by the KMS helpers before calling into the encoder), alongwith connector creation. When done with the bridge (afterdrm_mode_config_cleanup() if the bridge has already been attached), thendrm_panel_bridge_remove() to free it.

The connector type is set topanel->connector_type, which must be set to aknown type. Calling this function with a panel whose connector type isDRM_MODE_CONNECTOR_Unknown will return ERR_PTR(-EINVAL).

Seedevm_drm_panel_bridge_add() for an automatically managed version of thisfunction.

structdrm_bridge*drm_panel_bridge_add_typed(structdrm_panel*panel,u32connector_type)

Creates adrm_bridge anddrm_connector with an explicit connector type.

Parameters

structdrm_panel*panel

The drm_panel being wrapped. Must be non-NULL.

u32connector_type

The connector type (DRM_MODE_CONNECTOR_*)

Description

This is just likedrm_panel_bridge_add(), but forces the connector type toconnector_type instead of infering it from the panel.

This function is deprecated and should not be used in new drivers. Usedrm_panel_bridge_add() instead, and fix panel drivers as necessary if theydon’t report a connector type.

voiddrm_panel_bridge_remove(structdrm_bridge*bridge)

Unregisters and frees a drm_bridge created bydrm_panel_bridge_add().

Parameters

structdrm_bridge*bridge

The drm_bridge being freed.

intdrm_panel_bridge_set_orientation(structdrm_connector*connector,structdrm_bridge*bridge)

Set the connector’s panel orientation from the bridge that can be transformed to panel bridge.

Parameters

structdrm_connector*connector

The connector to be set panel orientation.

structdrm_bridge*bridge

The drm_bridge to be transformed to panel bridge.

Description

Returns 0 on success, negative errno on failure.

structdrm_bridge*devm_drm_panel_bridge_add(structdevice*dev,structdrm_panel*panel)

Creates a manageddrm_bridge anddrm_connector that just calls the appropriate functions fromdrm_panel.

Parameters

structdevice*dev

device to tie the bridge lifetime to

structdrm_panel*panel

The drm_panel being wrapped. Must be non-NULL.

Description

This is the managed version ofdrm_panel_bridge_add() which automaticallycallsdrm_panel_bridge_remove() whendev is unbound.

structdrm_bridge*devm_drm_panel_bridge_add_typed(structdevice*dev,structdrm_panel*panel,u32connector_type)

Creates a manageddrm_bridge anddrm_connector with an explicit connector type.

Parameters

structdevice*dev

device to tie the bridge lifetime to

structdrm_panel*panel

The drm_panel being wrapped. Must be non-NULL.

u32connector_type

The connector type (DRM_MODE_CONNECTOR_*)

Description

This is just likedevm_drm_panel_bridge_add(), but forces the connector typetoconnector_type instead of infering it from the panel.

This function is deprecated and should not be used in new drivers. Usedevm_drm_panel_bridge_add() instead, and fix panel drivers as necessary ifthey don’t report a connector type.

structdrm_bridge*drmm_panel_bridge_add(structdrm_device*drm,structdrm_panel*panel)

Creates a DRM-manageddrm_bridge anddrm_connector that just calls the appropriate functions fromdrm_panel.

Parameters

structdrm_device*drm

DRM device to tie the bridge lifetime to

structdrm_panel*panel

The drm_panel being wrapped. Must be non-NULL.

Description

This is the DRM-managed version ofdrm_panel_bridge_add() whichautomatically callsdrm_panel_bridge_remove() whendev is cleanedup.

structdrm_connector*drm_panel_bridge_connector(structdrm_bridge*bridge)

return the connector for the panel bridge

Parameters

structdrm_bridge*bridge

The drm_bridge.

Description

drm_panel_bridge creates the connector.This function gives external access to the connector.

Return

Pointer to drm_connector

structdrm_bridge*devm_drm_of_get_bridge(structdevice*dev,structdevice_node*np,u32port,u32endpoint)

Return next bridge in the chain

Parameters

structdevice*dev

device to tie the bridge lifetime to

structdevice_node*np

device tree node containing encoder output ports

u32port

port in the device tree node

u32endpoint

endpoint in the device tree node

Description

Given a DT node’s port and endpoint number, finds the connected nodeand returns the associated bridge if any, or creates and returns adrm panel bridge instance if a panel is connected.

Returns a pointer to the bridge if successful, or an error pointerotherwise.

structdrm_bridge*drmm_of_get_bridge(structdrm_device*drm,structdevice_node*np,u32port,u32endpoint)

Return next bridge in the chain

Parameters

structdrm_device*drm

device to tie the bridge lifetime to

structdevice_node*np

device tree node containing encoder output ports

u32port

port in the device tree node

u32endpoint

endpoint in the device tree node

Description

Given a DT node’s port and endpoint number, finds the connected nodeand returns the associated bridge if any, or creates and returns adrm panel bridge instance if a panel is connected.

Returns a drmm managed pointer to the bridge if successful, or an errorpointer otherwise.

Panel Helper Reference

The DRM panel helpers allow drivers to register panel objects with acentral registry and provide functions to retrieve those panels in displaydrivers.

For easy integration into drivers using thedrm_bridge infrastructure pleasetake look atdrm_panel_bridge_add() anddevm_drm_panel_bridge_add().

structdrm_panel_funcs

perform operations on a given panel

Definition:

struct drm_panel_funcs {    int (*prepare)(struct drm_panel *panel);    int (*enable)(struct drm_panel *panel);    int (*disable)(struct drm_panel *panel);    int (*unprepare)(struct drm_panel *panel);    int (*get_modes)(struct drm_panel *panel, struct drm_connector *connector);    enum drm_panel_orientation (*get_orientation)(struct drm_panel *panel);    int (*get_timings)(struct drm_panel *panel, unsigned int num_timings, struct display_timing *timings);    void (*debugfs_init)(struct drm_panel *panel, struct dentry *root);};

Members

prepare

Turn on panel and perform set up.

This function is optional.

enable

Enable panel (turn on back light, etc.).

This function is optional.

disable

Disable panel (turn off back light, etc.).

This function is optional.

unprepare

Turn off panel.

This function is optional.

get_modes

Add modes to the connector that the panel is attached toand returns the number of modes added.

This function is mandatory.

get_orientation

Return the panel orientation set by device tree or EDID.

This function is optional.

get_timings

Copy display timings into the provided array and returnthe number of display timings available.

This function is optional.

debugfs_init

Allows panels to create panels-specific debugfs files.

Description

The .prepare() function is typically called before the display controllerstarts to transmit video data. Panel drivers can use this to turn the panelon and wait for it to become ready. If additional configuration is required(via a control bus such as I2C, SPI or DSI for example) this is a good timeto do that.

After the display controller has started transmitting video data, it’s safeto call the .enable() function. This will typically enable the backlight tomake the image on screen visible. Some panels require a certain amount oftime or frames before the image is displayed. This function is responsiblefor taking this into account before enabling the backlight to avoid visualglitches.

Before stopping video transmission from the display controller it can benecessary to turn off the panel to avoid visual glitches. This is done inthe .disable() function. Analogously to .enable() this typically involvesturning off the backlight and waiting for some time to make sure no imageis visible on the panel. It is then safe for the display controller tocease transmission of video data.

To save power when no video data is transmitted, a driver can power downthe panel. This is the job of the .unprepare() function.

Backlight can be handled automatically if configured usingdrm_panel_of_backlight() ordrm_panel_dp_aux_backlight(). Then the driverdoes not need to implement the functionality to enable/disable backlight.

structdrm_panel

DRM panel object

Definition:

struct drm_panel {    struct device *dev;    struct backlight_device *backlight;    const struct drm_panel_funcs *funcs;    int connector_type;    struct list_head list;    struct list_head followers;    struct mutex follower_lock;    bool prepare_prev_first;    bool prepared;    bool enabled;    void *container;    struct kref refcount;};

Members

dev

Parent device of the panel.

backlight

Backlight device, used to turn on backlight after the calltoenable(), and to turn off backlight before the call todisable().backlight is set bydrm_panel_of_backlight() ordrm_panel_dp_aux_backlight() and drivers shall not assign it.

funcs

Operations that can be performed on the panel.

connector_type

Type of the panel as a DRM_MODE_CONNECTOR_* value. This is used toinitialise the drm_connector corresponding to the panel with thecorrect connector type.

list

Panel entry in registry.

followers

A list ofstructdrm_panel_follower dependent on this panel.

follower_lock

Lock for followers list.

prepare_prev_first

The previous controller should be prepared first, before the preparefor the panel is called. This is largely required for DSI panelswhere the DSI host controller should be initialised to LP-11 beforethe panel is powered up.

prepared

If true then the panel has been prepared.

enabled

If true then the panel has been enabled.

container

Pointer to the private driverstructembedding thisstruct drm_panel.

refcount

reference count of users referencing this panel.

devm_drm_panel_alloc

devm_drm_panel_alloc(dev,type,member,funcs,connector_type)

Allocate and initialize a refcounted panel.

Parameters

dev

structdevice of the panel device

type

the type of thestructwhich contains structdrm_panel

member

the name of thedrm_panel withintype

funcs

callbacks for this panel

connector_type

the connector type (DRM_MODE_CONNECTOR_*) corresponding tothe panel interface

Description

The reference count of the returned panel is initialized to 1. Thisreference will be automatically dropped via devm (by callingdrm_panel_put()) whendev is removed.

Return

Pointer to container structure embedding the panel, ERR_PTR on failure.

voiddrm_panel_init(structdrm_panel*panel,structdevice*dev,conststructdrm_panel_funcs*funcs,intconnector_type)

initialize a panel

Parameters

structdrm_panel*panel

DRM panel

structdevice*dev

parent device of the panel

conststructdrm_panel_funcs*funcs

panel operations

intconnector_type

the connector type (DRM_MODE_CONNECTOR_*) corresponding tothe panel interface (must NOT be DRM_MODE_CONNECTOR_Unknown)

Description

Initialize the panel structure for subsequent registration withdrm_panel_add().

voiddrm_panel_add(structdrm_panel*panel)

add a panel to the global registry

Parameters

structdrm_panel*panel

panel to add

Description

Add a panel to the global registry so that it can be lookedup by display drivers. The panel to be added must have beenallocated bydevm_drm_panel_alloc().

voiddrm_panel_remove(structdrm_panel*panel)

remove a panel from the global registry

Parameters

structdrm_panel*panel

DRM panel

Description

Removes a panel from the global registry.

voiddrm_panel_prepare(structdrm_panel*panel)

power on a panel

Parameters

structdrm_panel*panel

DRM panel

Description

Calling this function will enable power and deassert any reset signals tothe panel. After this has completed it is possible to communicate with anyintegrated circuitry via a command bus. This function cannot fail (as it iscalled from the pre_enable call chain). There will always be a call todrm_panel_disable() afterwards.

voiddrm_panel_unprepare(structdrm_panel*panel)

power off a panel

Parameters

structdrm_panel*panel

DRM panel

Description

Calling this function will completely power off a panel (assert the panel’sreset, turn off power supplies, ...). After this function has completed, itis usually no longer possible to communicate with the panel until anothercall todrm_panel_prepare().

voiddrm_panel_enable(structdrm_panel*panel)

enable a panel

Parameters

structdrm_panel*panel

DRM panel

Description

Calling this function will cause the panel display drivers to be turned onand the backlight to be enabled. Content will be visible on screen afterthis call completes. This function cannot fail (as it is called from theenable call chain). There will always be a call todrm_panel_disable()afterwards.

voiddrm_panel_disable(structdrm_panel*panel)

disable a panel

Parameters

structdrm_panel*panel

DRM panel

Description

This will typically turn off the panel’s backlight or disable the displaydrivers. For smart panels it should still be possible to communicate withthe integrated circuitry via any command bus after this call.

intdrm_panel_get_modes(structdrm_panel*panel,structdrm_connector*connector)

probe the available display modes of a panel

Parameters

structdrm_panel*panel

DRM panel

structdrm_connector*connector

DRM connector

Description

The modes probed from the panel are automatically added to the connectorthat the panel is attached to.

Return

The number of modes available from the panel on success, or 0 onfailure (no modes).

structdrm_panel*drm_panel_get(structdrm_panel*panel)

Acquire a panel reference

Parameters

structdrm_panel*panel

DRM panel

Description

This function increments the panel’s refcount.

Return

Pointer topanel

voiddrm_panel_put(structdrm_panel*panel)

Release a panel reference

Parameters

structdrm_panel*panel

DRM panel

Description

This function decrements the panel’s reference count and frees theobject if the reference count drops to zero.

structdrm_panel*of_drm_find_panel(conststructdevice_node*np)

look up a panel using a device tree node

Parameters

conststructdevice_node*np

device tree node of the panel

Description

Searches the set of registered panels for one that matches the given devicetree node. If a matching panel is found, return a pointer to it.

Possible error codes returned by this function:

  • EPROBE_DEFER: the panel device has not been probed yet, and the callershould retry later

  • ENODEV: the device is not available (status != “okay” or “ok”)

Return

A pointer to the panel registered for the specified device treenode or anERR_PTR() if no panel matching the device tree node can be found.

intof_drm_get_panel_orientation(conststructdevice_node*np,enumdrm_panel_orientation*orientation)

look up the orientation of the panel through the “rotation” binding from a device tree node

Parameters

conststructdevice_node*np

device tree node of the panel

enumdrm_panel_orientation*orientation

orientationenumto be filled in

Description

Looks up the rotation of a panel in the device tree. The orientation of thepanel is expressed as a property name “rotation” in the device tree. Therotation in the device tree is counter clockwise.

Return

0 when a valid rotation value (0, 90, 180, or 270) is read or therotation property doesn’t exist. Return a negative error code on failure.

booldrm_is_panel_follower(structdevice*dev)

Check if the device is a panel follower

Parameters

structdevice*dev

The ‘structdevice’ to check

Description

This checks to see if a device needs to be power sequenced together witha panel using the panel follower API.

The “panel” property of the follower points to the panel to be followed.

Return

true if we should be power sequenced with a panel; false otherwise.

intdrm_panel_add_follower(structdevice*follower_dev,structdrm_panel_follower*follower)

Register something to follow panel state.

Parameters

structdevice*follower_dev

The ‘structdevice’ for the follower.

structdrm_panel_follower*follower

The panel follower descriptor for the follower.

Description

A panel follower is called right after preparing/enabling the panel and rightbefore unpreparing/disabling the panel. It’s primary intention is to power onan associated touchscreen, though it could be used for any similar devices.Multiple devices are allowed the follow the same panel.

If a follower is added to a panel that’s already been prepared/enabled, thefollower’s prepared/enabled callback is called right away.

The “panel” property of the follower points to the panel to be followed.

Return

0 or an error code. Note that -ENODEV means that we detected thatfollower_dev is not actually following a panel. The caller maychoose to ignore this return value if following a panel is optional.

voiddrm_panel_remove_follower(structdrm_panel_follower*follower)

Reversedrm_panel_add_follower().

Parameters

structdrm_panel_follower*follower

The panel follower descriptor for the follower.

Description

Undodrm_panel_add_follower(). This includes calling the follower’sunpreparing/disabling function if we’re removed from a panel that’s currentlyprepared/enabled.

Return

0 or an error code.

intdevm_drm_panel_add_follower(structdevice*follower_dev,structdrm_panel_follower*follower)

devm version ofdrm_panel_add_follower()

Parameters

structdevice*follower_dev

The ‘structdevice’ for the follower.

structdrm_panel_follower*follower

The panel follower descriptor for the follower.

Description

Handles callingdrm_panel_remove_follower() using devm on the follower_dev.

Return

0 or an error code.

intdrm_panel_of_backlight(structdrm_panel*panel)

use backlight device node for backlight

Parameters

structdrm_panel*panel

DRM panel

Description

Use this function to enable backlight handling if your paneluses device tree and has a backlight phandle.

When the panel is enabled backlight will be enabled after asuccessful call todrm_panel_funcs.enable()

When the panel is disabled backlight will be disabled before thecall todrm_panel_funcs.disable().

A typical implementation for a panel driver supporting device treewill call this function at probe time. Backlight will then be handledtransparently without requiring any intervention from the driver.drm_panel_of_backlight() must be called after the call todrm_panel_init().

Return

0 on success or a negative error code on failure.

intdrm_get_panel_orientation_quirk(intwidth,intheight)

Check for panel orientation quirks

Parameters

intwidth

width in pixels of the panel

intheight

height in pixels of the panel

Description

This function checks for platform specific (e.g. DMI based) quirksproviding info on panel_orientation for systems where this cannot beprobed from the hard-/firm-ware. To avoid false-positive this functiontakes the panel resolution as argument and checks that against theresolution expected by the quirk-table entry.

Note this function is also used outside of the drm-subsys, by for examplethe efifb code. Because of this this function gets compiled into its ownkernel-module when built as a module.

Return

A DRM_MODE_PANEL_ORIENTATION_* value if there is a quirk for this system,or DRM_MODE_PANEL_ORIENTATION_UNKNOWN if there is no quirk.

conststructdrm_panel_backlight_quirk*drm_get_panel_backlight_quirk(conststructdrm_edid*edid)

Get backlight quirks for a panel

Parameters

conststructdrm_edid*edid

EDID of the panel to check

Description

This function checks for platform specific (e.g. DMI based) quirksproviding info on the minimum backlight brightness for systems where thiscannot be probed correctly from the hard-/firm-ware and other sources.

Return

a drm_panel_backlight_quirk struct if a quirk was found, otherwise anerror pointer.

Panel Self Refresh Helper Reference

This helper library provides an easy way for drivers to leverage the atomicframework to implement panel self refresh (SR) support. Drivers areresponsible for initializing and cleaning up the SR helpers on load/unload(seedrm_self_refresh_helper_init/drm_self_refresh_helper_cleanup).The connector is responsible for settingdrm_connector_state.self_refresh_aware to true at runtime if it is SR-aware(meaning it knows how to initiate self refresh on the panel).

Once a crtc has enabled SR usingdrm_self_refresh_helper_init, thehelpers will monitor activity and call back into the driver to enable/disableSR as appropriate. The best way to think about this is that it’s a DPMSon/off request withdrm_crtc_state.self_refresh_active set in crtc statethat tells you to disable/enable SR on the panel instead of power-cycling it.

During SR, drivers may choose to fully disable their crtc/encoder/bridgehardware (in which case no driver changes are necessary), or they can inspectdrm_crtc_state.self_refresh_active if they want to enter low power modewithout full disable (in case full disable/enable is too slow).

SR will be deactivated if there are any atomic updates affecting thepipe that is in SR mode. If a crtc is driving multiple connectors, allconnectors must be SR aware and all will enter/exit SR mode at the same time.

If the crtc and connector are SR aware, but the panel connected does notsupport it (or is otherwise unable to enter SR), the driver should failatomic_check whendrm_crtc_state.self_refresh_active is true.

voiddrm_self_refresh_helper_update_avg_times(structdrm_atomic_state*state,unsignedintcommit_time_ms,unsignedintnew_self_refresh_mask)

Updates a crtc’s SR time averages

Parameters

structdrm_atomic_state*state

the state which has just been applied to hardware

unsignedintcommit_time_ms

the amount of time in ms that this commit took to complete

unsignedintnew_self_refresh_mask

bitmask of crtc’s that have self_refresh_active innew state

Description

Called afterdrm_mode_config_funcs.atomic_commit_tail, this function willupdate the average entry/exit self refresh times on self refresh transitions.These averages will be used when calculating how long to delay beforeentering self refresh mode after activity.

voiddrm_self_refresh_helper_alter_state(structdrm_atomic_state*state)

Alters the atomic state for SR exit

Parameters

structdrm_atomic_state*state

the state currently being checked

Description

Called at the end of atomic check. This function checks the state for flagsincompatible with self refresh exit and changes them. This is a bitdisingenuous since userspace is expecting one thing and we’re giving itanother. However in order to keep self refresh entirely hidden fromuserspace, this is required.

At the end, we queue up the self refresh entry work so we can enter PSR afterthe desired delay.

intdrm_self_refresh_helper_init(structdrm_crtc*crtc)

Initializes self refresh helpers for a crtc

Parameters

structdrm_crtc*crtc

the crtc which supports self refresh supported displays

Description

Returns zero if successful or -errno on failure

voiddrm_self_refresh_helper_cleanup(structdrm_crtc*crtc)

Cleans up self refresh helpers for a crtc

Parameters

structdrm_crtc*crtc

the crtc to cleanup

HDMI Atomic State Helpers

Overview

These functions contain an implementation of the HDMI specificationin the form of KMS helpers.

It contains TMDS character rate computation, automatic selection ofoutput formats, infoframes generation, etc.

Infoframes Compliance

Drivers using the helpers will expose the various infoframesgenerated according to the HDMI specification in debugfs.

Compliance can then be tested usingedid-decode from thev4l-utils project(https://git.linuxtv.org/v4l-utils.git/). A sample run would look like:

# edid-decode \-I/sys/kernel/debug/dri/1/HDMI-A-1/infoframes/audio\-I/sys/kernel/debug/dri/1/HDMI-A-1/infoframes/avi\-I/sys/kernel/debug/dri/1/HDMI-A-1/infoframes/hdmi\-I/sys/kernel/debug/dri/1/HDMI-A-1/infoframes/hdr_drm\-I/sys/kernel/debug/dri/1/HDMI-A-1/infoframes/spd\/sys/class/drm/card1-HDMI-A-1/edid\-cedid-decode(hex):00ffffffffffff001e6df45b1eef060007200103802f3478ea2405af4f42ab250f5054210800d1c0614045400101010101010101010198d00040a140d4b030203a00d10b1200001a000000fd003b3d1eb231000a202020202020000000fc004c472053445148440a20202020000000ff003230374e54524c44433433300a014602034272230907074d0103049012131f225d5e5f6061830100006d030c001000b83c20006001020367d85dc401788003e30f0018e2006ae305c000e6060501525251115d00a0a04029b030203a00d10b1200001a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000c3----------------Block0,BaseEDID:EDIDStructureVersion&Revision:1.3Vendor&ProductIdentification:Manufacturer:GSMModel:23540SerialNumber:454430(0x0006ef1e)Madein:week7of2022BasicDisplayParameters&Features:DigitaldisplayMaximumimagesize:47cmx52cmGamma:2.20DPMSlevels:StandbySuspendOffRGBcolordisplayFirstdetailedtimingisthepreferredtimingColorCharacteristics:Red:0.6835,0.3105Green:0.2587,0.6679Blue:0.1445,0.0585White:0.3134,0.3291EstablishedTimingsI&II:DMT0x04:640x48059.940476Hz4:331.469kHz25.175000MHzDMT0x09:800x60060.316541Hz4:337.879kHz40.000000MHzDMT0x10:1024x76860.003840Hz4:348.363kHz65.000000MHzStandardTimings:DMT0x52:1920x108060.000000Hz16:967.500kHz148.500000MHzDMT0x10:1024x76860.003840Hz4:348.363kHz65.000000MHzDMT0x09:800x60060.316541Hz4:337.879kHz40.000000MHzDetailedTimingDescriptors:DTD1:2560x288059.966580Hz8:9185.417kHz534.000000MHz(465mmx523mm)Hfront48Hsync32Hback240HpolPVfront3Vsync10Vback199VpolNDisplayRangeLimits:Monitorranges(GTF):59-61HzV,30-178kHzH,maxdotclock490MHzDisplayProductName:'LG SDQHD'DisplayProductSerialNumber:'207NTRLDC430'Extensionblocks:1Checksum:0x46----------------Block1,CTA-861ExtensionBlock:Revision:3BasicaudiosupportSupportsYCbCr4:4:4SupportsYCbCr4:2:2Nativedetailedmodes:2AudioDataBlock:LinearPCM:Maxchannels:2Supportedsamplerates(kHz):4844.132Supportedsamplesizes(bits):242016VideoDataBlock:VIC1:640x48059.940476Hz4:331.469kHz25.175000MHzVIC3:720x48059.940060Hz16:931.469kHz27.000000MHzVIC4:1280x72060.000000Hz16:945.000kHz74.250000MHzVIC16:1920x108060.000000Hz16:967.500kHz148.500000MHz(native)VIC18:720x57650.000000Hz16:931.250kHz27.000000MHzVIC19:1280x72050.000000Hz16:937.500kHz74.250000MHzVIC31:1920x108050.000000Hz16:956.250kHz148.500000MHzVIC34:1920x108030.000000Hz16:933.750kHz74.250000MHzVIC93:3840x216024.000000Hz16:954.000kHz297.000000MHzVIC94:3840x216025.000000Hz16:956.250kHz297.000000MHzVIC95:3840x216030.000000Hz16:967.500kHz297.000000MHzVIC96:3840x216050.000000Hz16:9112.500kHz594.000000MHzVIC97:3840x216060.000000Hz16:9135.000kHz594.000000MHzSpeakerAllocationDataBlock:FL/FR-FrontLeft/RightVendor-SpecificDataBlock(HDMI),OUI00-0C-03:Sourcephysicaladdress:1.0.0.0Supports_AIDC_36bitDC_30bitDC_Y444MaximumTMDSclock:300MHzExtendedHDMIvideodetails:HDMIVICs:HDMIVIC1:3840x216030.000000Hz16:967.500kHz297.000000MHzHDMIVIC2:3840x216025.000000Hz16:956.250kHz297.000000MHzHDMIVIC3:3840x216024.000000Hz16:954.000kHz297.000000MHzVendor-SpecificDataBlock(HDMIForum),OUIC4-5D-D8:Version:1MaximumTMDSCharacterRate:600MHzSCDCPresentSupports12-bits/componentDeepColor4:2:0PixelEncodingSupports10-bits/componentDeepColor4:2:0PixelEncodingYCbCr4:2:0CapabilityMapDataBlock:VIC96:3840x216050.000000Hz16:9112.500kHz594.000000MHzVIC97:3840x216060.000000Hz16:9135.000kHz594.000000MHzVideoCapabilityDataBlock:YCbCrquantization:NoDataRGBquantization:Selectable(viaAVIQ)PTscanbehavior:AlwaysUnderscannedITscanbehavior:AlwaysUnderscannedCEscanbehavior:AlwaysUnderscannedColorimetryDataBlock:BT2020YCCBT2020RGBHDRStaticMetadataDataBlock:Electroopticaltransferfunctions:Traditionalgamma-SDRluminancerangeSMPTEST2084Supportedstaticmetadatadescriptors:Staticmetadatatype1Desiredcontentmaxluminance:82(295.365cd/m^2)Desiredcontentmaxframe-averageluminance:82(295.365cd/m^2)Desiredcontentminluminance:81(0.298cd/m^2)DetailedTimingDescriptors:DTD2:2560x288029.986961Hz8:987.592kHz238.250000MHz(465mmx523mm)Hfront48Hsync32Hback80HpolPVfront3Vsync10Vback28VpolNChecksum:0xc3UnusedspaceinExtensionBlock:43bytes----------------edid-decode1.29.0-5346edid-decodeSHA:c363e9aa6d702025-03-1111:41:18Warnings:Block1,CTA-861ExtensionBlock:ITVideoFormatsareoverscannedbydefault,butnormallythisshouldbeunderscanned.VideoDataBlock:VIC1andthefirstDTDarenotidentical.Isthisintended?VideoDataBlock:AllVICsareinascendingorder,andthefirst(preferred)VIC<=4,isthatintended?VideoCapabilityDataBlock:SetSelectableYCbCrQuantizationtoavoidinteropissues.VideoCapabilityDataBlock:S_PTisequaltoS_ITandS_CE,soshouldbesetto0instead.ColorimetryDataBlock:SetthesRGBcolorimetrybittoavoidinteropissues.DisplayProductSerialNumberisset,sotheSerialNumberintheBaseEDIDshouldbe0.EDID:BaseEDID:SometimingsareoutofrangeoftheMonitorRanges:VerticalFreq:24.000-60.317Hz(Monitor:59.000-61.000Hz)HorizontalFreq:31.250-185.416kHz(Monitor:30.000-178.000kHz)MaximumClock:594.000MHz(Monitor:490.000MHz)Failures:Block1,CTA-861ExtensionBlock:VideoCapabilityDataBlock:ITvideoformatsarealwaysunderscanned,butbit7ofByte3oftheCTA-861Extensionheaderissettooverscanned.EDID:CTA-861:Nativeprogressivetimingsareamixofseveralresolutions.EDIDconformity:FAIL================InfoFrameof'/sys/kernel/debug/dri/1/HDMI-A-1/infoframes/audio'wasempty.================edid-decodeInfoFrame(hex):82020d3112280400000000000000000000----------------HDMIInfoFrameChecksum:0x31AVIInfoFrameVersion:2Length:13Y:ColorComponentSampleFormat:RGBA:ActiveFormatInformationPresent:YesB:BarDataPresent:BarDatanotpresentS:ScanInformation:ComposedforanunderscanneddisplayC:Colorimetry:NoDataM:PictureAspectRatio:16:9R:ActivePortionAspectRatio:8ITC:ITContent:NoDataEC:ExtendedColorimetry:xvYCC601Q:RGBQuantizationRange:LimitedRangeSC:Non-UniformPictureScaling:NoKnownnon-uniformscalingYQ:YCCQuantizationRange:LimitedRangeCN:ITContentType:GraphicsPR:PixelDataRepetitionCount:0LineNumberofEndofTopBar:0LineNumberofStartofBottomBar:0PixelNumberofEndofLeftBar:0PixelNumberofStartofRightBar:0----------------AVIInfoFrameconformity:PASS================edid-decodeInfoFrame(hex):81010549030c002001----------------HDMIInfoFrameChecksum:0x49Vendor-SpecificInfoFrame(HDMI),OUI00-0C-03Version:1Length:5HDMIVideoFormat:HDMI_VICispresentHDMIVIC1:3840x216030.000000Hz16:967.500kHz297.000000MHz----------------Vendor-SpecificInfoFrame(HDMI),OUI00-0C-03conformity:PASS================InfoFrameof'/sys/kernel/debug/dri/1/HDMI-A-1/infoframes/hdr_drm'wasempty.================edid-decodeInfoFrame(hex):8301199342726f6164636f6d566964656f636f72650000000000000009----------------HDMIInfoFrameChecksum:0x93SourceProductDescriptionInfoFrameVersion:1Length:25VendorName:'Broadcom'ProductDescription:'Videocore'SourceInformation:PCgeneral----------------SourceProductDescriptionInfoFrameconformity:PASS

Testing

The helpers have unit testing and can be tested using kunit with:

$./tools/testing/kunit/kunit.pyrun\--kunitconfig=drivers/gpu/drm/tests\drm_atomic_helper_connector_hdmi_*

Functions Reference

void__drm_atomic_helper_connector_hdmi_reset(structdrm_connector*connector,structdrm_connector_state*new_conn_state)

Initializes all HDMIdrm_connector_state resources

Parameters

structdrm_connector*connector

DRM connector

structdrm_connector_state*new_conn_state

connector state to reset

Description

Initializes all HDMI resources from adrm_connector_state withoutactually allocating it. This is useful for HDMI drivers, incombination with__drm_atomic_helper_connector_reset() ordrm_atomic_helper_connector_reset().

intdrm_atomic_helper_connector_hdmi_check(structdrm_connector*connector,structdrm_atomic_state*state)

Helper to check HDMI connector atomic state

Parameters

structdrm_connector*connector

DRM Connector

structdrm_atomic_state*state

the DRM State object

Description

Provides a default connector state check handler for HDMI connectors.Checks that a desired connector update is valid, and updates variousfields of derived state.

Return

Zero on success, or an errno code otherwise.

enumdrm_mode_statusdrm_hdmi_connector_mode_valid(structdrm_connector*connector,conststructdrm_display_mode*mode)

Check if mode is valid for HDMI connector

Parameters

structdrm_connector*connector

DRM connector to validate the mode

conststructdrm_display_mode*mode

Display mode to validate

Description

Generic .mode_valid implementation for HDMI connectors.

intdrm_atomic_helper_connector_hdmi_update_infoframes(structdrm_connector*connector,structdrm_atomic_state*state)

Update the Infoframes

Parameters

structdrm_connector*connector

A pointer to the HDMI connector

structdrm_atomic_state*state

The HDMI connector state to generate the infoframe from

Description

This function is meant for HDMI connector drivers to write theirinfoframes. It will typically be used in adrm_connector_helper_funcs.atomic_enable implementation.

Return

Zero on success, error code on failure.

intdrm_atomic_helper_connector_hdmi_update_audio_infoframe(structdrm_connector*connector,structhdmi_audio_infoframe*frame)

Update the Audio Infoframe

Parameters

structdrm_connector*connector

A pointer to the HDMI connector

structhdmi_audio_infoframe*frame

A pointer to the audio infoframe to write

Description

This function is meant for HDMI connector drivers to update theiraudio infoframe. It will typically be used in one of the ALSA hooks(most likely prepare).

Return

Zero on success, error code on failure.

intdrm_atomic_helper_connector_hdmi_clear_audio_infoframe(structdrm_connector*connector)

Stop sending the Audio Infoframe

Parameters

structdrm_connector*connector

A pointer to the HDMI connector

Description

This function is meant for HDMI connector drivers to stop sending theiraudio infoframe. It will typically be used in one of the ALSA hooks(most likely shutdown).

Return

Zero on success, error code on failure.

voiddrm_atomic_helper_connector_hdmi_hotplug(structdrm_connector*connector,enumdrm_connector_statusstatus)

Handle the hotplug event for the HDMI connector

Parameters

structdrm_connector*connector

A pointer to the HDMI connector

enumdrm_connector_statusstatus

Connection status

Description

This function should be called as a part of the .detect() / .detect_ctx()callbacks for all status changes.

voiddrm_atomic_helper_connector_hdmi_force(structdrm_connector*connector)

HDMI Connector implementation of the force callback

Parameters

structdrm_connector*connector

A pointer to the HDMI connector

Description

This function implements the .force() callback for the HDMI connectors. Itcan either be used directly as the callback or should be called from withinthe .force() callback implementation to maintain the HDMI-specificconnector’s data.

HDCP Helper Functions Reference

intdrm_hdcp_check_ksvs_revoked(structdrm_device*drm_dev,u8*ksvs,u32ksv_count)

Check the revoked status of the IDs

Parameters

structdrm_device*drm_dev

drm_device for which HDCP revocation check is requested

u8*ksvs

List of KSVs (HDCP receiver IDs)

u32ksv_count

KSV count passed in throughksvs

Description

This function reads the HDCP System renewability Message(SRM Table)from userspace as a firmware and parses it for the revoked HDCPKSVs(Receiver IDs) detected by DCP LLC. Once the revoked KSVs are known,revoked state of the KSVs in the list passed in by display drivers aredecided and response is sent.

SRM should be presented in the name of “display_hdcp_srm.bin”.

Format of the SRM table, that userspace needs to write into the binary file,is defined at:1. Renewability chapter on 55th page of HDCP 1.4 specificationhttps://www.digital-cp.com/sites/default/files/specifications/HDCP``20Specification````20Rev1_4_Secure``.pdf2. Renewability chapter on 63rd page of HDCP 2.2 specificationhttps://www.digital-cp.com/sites/default/files/specifications/HDCP``20on````20HDMI````20Specification````20Rev2_2_Final1``.pdf

Return

Count of the revoked KSVs or -ve error number in case of the failure.

intdrm_connector_attach_content_protection_property(structdrm_connector*connector,boolhdcp_content_type)

attach content protection property

Parameters

structdrm_connector*connector

connector to attach CP property on.

boolhdcp_content_type

is HDCP Content Type property needed for connector

Description

This is used to add support for content protection on select connectors.Content Protection is intentionally vague to allow for different underlyingtechnologies, however it is most implemented by HDCP.

When hdcp_content_type is trueenumproperty called HDCP Content Type iscreated (if it is not already) and attached to the connector.

This property is used for sending the protected content’s stream typefrom userspace to kernel on selected connectors. Protected content providerwill decide their type of their content and declare the same to kernel.

Content type will be used during the HDCP 2.2 authentication.Content type will be set todrm_connector_state.hdcp_content_type.

The content protection will be set todrm_connector_state.content_protection

When kernel triggered content protection state change like DESIRED->ENABLEDand ENABLED->DESIRED, will usedrm_hdcp_update_content_protection() to updatethe content protection state of a connector.

Return

Zero on success, negative errno on failure.

voiddrm_hdcp_update_content_protection(structdrm_connector*connector,u64val)

Updates the content protection state of a connector

Parameters

structdrm_connector*connector

drm_connector on which content protection state needs an update

u64val

New state of the content protection property

Description

This function can be used by display drivers, to update the kernel triggeredcontent protection state changes of a drm_connector such as DESIRED->ENABLEDand ENABLED->DESIRED. No uevent for DESIRED->UNDESIRED or ENABLED->UNDESIRED,as userspace is triggering such state change and kernel performs it withoutfail.This function update the new state of the property into the connector’sstate and generate an uevent to notify the userspace.

Display Port Helper Functions Reference

These functions contain some common logic and helpers at various abstractionlevels to deal with Display Port sink devices and related things like DP auxchannel transfers, EDID reading over DP aux channels, decoding certain DPCDblocks, ...

The DisplayPort AUX channel is an abstraction to allow generic, driver-independent access to AUX functionality. Drivers can take advantage ofthis by filling in the fields of the drm_dp_aux structure.

Transactions are described using a hardware-independent drm_dp_aux_msgstructure, which is passed into a driver’s .transfer() implementation.Both native and I2C-over-AUX transactions are supported.

structdp_sdp_header

DP secondary data packet header

Definition:

struct dp_sdp_header {    u8 HB0;    u8 HB1;    u8 HB2;    u8 HB3;};

Members

HB0

Secondary Data Packet ID

HB1

Secondary Data Packet Type

HB2

Secondary Data Packet Specific header, Byte 0

HB3

Secondary Data packet Specific header, Byte 1

structdp_sdp

DP secondary data packet

Definition:

struct dp_sdp {    struct dp_sdp_header sdp_header;    u8 db[32];};

Members

sdp_header

DP secondary data packet header

db

DP secondaray data packet data blocksVSC SDP Payload for PSRdb[0]: Stereo Interfacedb[1]: 0 - PSR State; 1 - Update RFB; 2 - CRC Validdb[2]: CRC value bits 7:0 of the R or Cr componentdb[3]: CRC value bits 15:8 of the R or Cr componentdb[4]: CRC value bits 7:0 of the G or Y componentdb[5]: CRC value bits 15:8 of the G or Y componentdb[6]: CRC value bits 7:0 of the B or Cb componentdb[7]: CRC value bits 15:8 of the B or Cb componentdb[8] - db[31]: ReservedVSC SDP Payload for Pixel Encoding/Colorimetry Formatdb[0] - db[15]: Reserveddb[16]: Pixel Encoding and Colorimetry Formatsdb[17]: Dynamic Range and Component Bit Depthdb[18]: Content Typedb[19] - db[31]: Reserved

enumdp_pixelformat

drm DP Pixel encoding formats

Constants

DP_PIXELFORMAT_RGB

RGB pixel encoding format

DP_PIXELFORMAT_YUV444

YCbCr 4:4:4 pixel encoding format

DP_PIXELFORMAT_YUV422

YCbCr 4:2:2 pixel encoding format

DP_PIXELFORMAT_YUV420

YCbCr 4:2:0 pixel encoding format

DP_PIXELFORMAT_Y_ONLY

Y Only pixel encoding format

DP_PIXELFORMAT_RAW

RAW pixel encoding format

DP_PIXELFORMAT_RESERVED

Reserved pixel encoding format

Description

Thisenumis used to indicate DP VSC SDP Pixel encoding formats.It is based on DP 1.4 spec [Table 2-117: VSC SDP Payload for DB16 throughDB18]

enumdp_colorimetry

drm DP Colorimetry formats

Constants

DP_COLORIMETRY_DEFAULT

sRGB (IEC 61966-2-1) orITU-R BT.601 colorimetry format

DP_COLORIMETRY_RGB_WIDE_FIXED

RGB wide gamut fixed point colorimetry format

DP_COLORIMETRY_BT709_YCC

ITU-R BT.709 colorimetry format

DP_COLORIMETRY_RGB_WIDE_FLOAT

RGB wide gamut floating point(scRGB (IEC 61966-2-2)) colorimetry format

DP_COLORIMETRY_XVYCC_601

xvYCC601 colorimetry format

DP_COLORIMETRY_OPRGB

OpRGB colorimetry format

DP_COLORIMETRY_XVYCC_709

xvYCC709 colorimetry format

DP_COLORIMETRY_DCI_P3_RGB

DCI-P3 (SMPTE RP 431-2) colorimetry format

DP_COLORIMETRY_SYCC_601

sYCC601 colorimetry format

DP_COLORIMETRY_RGB_CUSTOM

RGB Custom Color Profile colorimetry format

DP_COLORIMETRY_OPYCC_601

opYCC601 colorimetry format

DP_COLORIMETRY_BT2020_RGB

ITU-R BT.2020 R’ G’ B’ colorimetry format

DP_COLORIMETRY_BT2020_CYCC

ITU-R BT.2020 Y’c C’bc C’rc colorimetry format

DP_COLORIMETRY_BT2020_YCC

ITU-R BT.2020 Y’ C’b C’r colorimetry format

Description

Thisenumis used to indicate DP VSC SDP Colorimetry formats.It is based on DP 1.4 spec [Table 2-117: VSC SDP Payload for DB16 throughDB18] and a name ofenummember followsenumdrm_colorimetry definition.

enumdp_dynamic_range

drm DP Dynamic Range

Constants

DP_DYNAMIC_RANGE_VESA

VESA range

DP_DYNAMIC_RANGE_CTA

CTA range

Description

Thisenumis used to indicate DP VSC SDP Dynamic Range.It is based on DP 1.4 spec [Table 2-117: VSC SDP Payload for DB16 throughDB18]

enumdp_content_type

drm DP Content Type

Constants

DP_CONTENT_TYPE_NOT_DEFINED

Not defined type

DP_CONTENT_TYPE_GRAPHICS

Graphics type

DP_CONTENT_TYPE_PHOTO

Photo type

DP_CONTENT_TYPE_VIDEO

Video type

DP_CONTENT_TYPE_GAME

Game type

Description

Thisenumis used to indicate DP VSC SDP Content Types.It is based on DP 1.4 spec [Table 2-117: VSC SDP Payload for DB16 throughDB18]CTA-861-G defines content types and expected processing by a sink device

structdrm_dp_vsc_sdp

drm DP VSC SDP

Definition:

struct drm_dp_vsc_sdp {    unsigned char sdp_type;    unsigned char revision;    unsigned char length;    enum dp_pixelformat pixelformat;    enum dp_colorimetry colorimetry;    int bpc;    enum dp_dynamic_range dynamic_range;    enum dp_content_type content_type;};

Members

sdp_type

secondary-data packet type

revision

revision number

length

number of valid data bytes

pixelformat

pixel encoding format

colorimetry

colorimetry format

bpc

bit per color

dynamic_range

dynamic range information

content_type

CTA-861-G defines content types and expected processing by a sink device

Description

This structure represents a DP VSC SDP of drmIt is based on DP 1.4 spec [Table 2-116: VSC SDP Header Bytes] and[Table 2-117: VSC SDP Payload for DB16 through DB18]

structdrm_dp_as_sdp

drm DP Adaptive Sync SDP

Definition:

struct drm_dp_as_sdp {    unsigned char sdp_type;    unsigned char revision;    unsigned char length;    int vtotal;    int target_rr;    int duration_incr_ms;    int duration_decr_ms;    bool target_rr_divider;    enum operation_mode mode;};

Members

sdp_type

Secondary-data packet type

revision

Revision Number

length

Number of valid data bytes

vtotal

Minimum Vertical Vtotal

target_rr

Target Refresh

duration_incr_ms

Successive frame duration increase

duration_decr_ms

Successive frame duration decrease

target_rr_divider

Target refresh rate divider

mode

Adaptive Sync Operation Mode

Description

This structure represents a DP AS SDP of drmIt is based on DP 2.1 spec [Table 2-126: Adaptive-Sync SDP Header Bytes] and[Table 2-127: Adaptive-Sync SDP Payload for DB0 through DB8]

booldrm_dp_dsc_sink_supports_format(constu8dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE],u8output_format)

check if sink supports DSC with given output format

Parameters

constu8dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE]

DSC-capability DPCDs of the sink

u8output_format

output_format which is to be checked

Description

Returns true if the sink supports DSC with the given output_format, false otherwise.

booldrm_edp_backlight_supported(constu8edp_dpcd[EDP_DISPLAY_CTL_CAP_SIZE])

Check an eDP DPCD for VESA backlight support

Parameters

constu8edp_dpcd[EDP_DISPLAY_CTL_CAP_SIZE]

The DPCD to check

Description

Note that currently this function will returnfalse for panels which support various DPCDbacklight features but which require the brightness be set through PWM, and don’t support settingthe brightness level via the DPCD.

Return

True ifedp_dpcd indicates that VESA backlight controls are supported,falseotherwise

booldrm_dp_is_uhbr_rate(intlink_rate)

Determine if a link rate is UHBR

Parameters

intlink_rate

link rate in 10kbits/s units

Description

Determine if the provided link rate is an UHBR rate.

Return

True iflink_rate is an UHBR rate.

structdrm_dp_aux_msg

DisplayPort AUX channel transaction

Definition:

struct drm_dp_aux_msg {    unsigned int address;    u8 request;    u8 reply;    void *buffer;    size_t size;};

Members

address

address of the (first) register to access

request

contains the type of transaction (see DP_AUX_* macros)

reply

upon completion, contains the reply type of the transaction

buffer

pointer to a transmission or reception buffer

size

size ofbuffer

structdrm_dp_aux_cec

DisplayPort CEC-Tunneling-over-AUX

Definition:

struct drm_dp_aux_cec {    struct mutex lock;    struct cec_adapter *adap;    struct drm_connector *connector;    struct delayed_work unregister_work;};

Members

lock

mutex protecting this struct

adap

the CEC adapter for CEC-Tunneling-over-AUX support.

connector

the connector this CEC adapter is associated with

unregister_work

unregister the CEC adapter

structdrm_dp_aux

DisplayPort AUX channel

Definition:

struct drm_dp_aux {    const char *name;    struct i2c_adapter ddc;    struct device *dev;    struct drm_device *drm_dev;    struct drm_crtc *crtc;    struct mutex hw_mutex;    struct work_struct crc_work;    u8 crc_count;    ssize_t (*transfer)(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg);    int (*wait_hpd_asserted)(struct drm_dp_aux *aux, unsigned long wait_us);    unsigned i2c_nack_count;    unsigned i2c_defer_count;    struct drm_dp_aux_cec cec;    bool is_remote;    bool powered_down;    bool no_zero_sized;    bool dpcd_probe_disabled;};

Members

name

user-visible name of this AUX channel and theI2C-over-AUX adapter.

It’s also used to specify the name of the I2C adapter. If settoNULL,dev_name() ofdev will be used.

ddc

I2C adapter that can be used for I2C-over-AUXcommunication

dev

pointer tostructdevice that is the parent for thisAUX channel.

drm_dev

pointer to thedrm_device that owns this AUX channel.Beware, this may beNULL beforedrm_dp_aux_register() has beencalled.

It should be set to thedrm_device that will be using this AUXchannel as early as possible. For many graphics drivers this shouldhappen beforedrm_dp_aux_init(), however it’s perfectly fine to setthis field later so long as it’s assigned before callingdrm_dp_aux_register().

crtc

backpointer to the crtc that is currently using thisAUX channel

hw_mutex

internal mutex used for locking transfers.

Note that if the underlying hardware is shared among multiplechannels, the driver needs to do additional locking toprevent concurrent access.

crc_work

worker that captures CRCs for each frame

crc_count

counter of captured frame CRCs

transfer

transfers a message representing a single AUXtransaction.

This is a hardware-specific implementation of howtransactions are executed that the drivers must provide.

A pointer to adrm_dp_aux_msg structure describing thetransaction is passed into this function. Upon success, theimplementation should return the number of payload bytes thatwere transferred, or a negative error-code on failure.

Helpers will propagate these errors, with the exception ofthe-EBUSY error, which causes a transaction to be retried.On a short, helpers will return-EPROTO to make it simplerto check for failure.

Thetransfer() function must only modify the reply field ofthedrm_dp_aux_msg structure. The retry logic and i2chelpers assume this is the case.

Also note that this callback can be called no matter thestatedev is in and also no matter what state the panel isin. It’s expected:

  • If thedev providing the AUX bus is currently unpowered thenit will power itself up for the transfer.

  • If we’re on eDP (using a drm_panel) and the panel is not in astate where it can respond (it’s not powered or it’s in alow power state) then this function may return an error, butnot crash. It’s up to the caller of this code to make sure thatthe panel is powered on if getting an error back is not OK. If adrm_panel driver is initiating a DP AUX transfer it may poweritself up however it wants. All other code should ensure thatthepre_enable() bridge chain (which eventually calls thedrm_panel prepare function) has powered the panel.

wait_hpd_asserted

wait for HPD to be asserted

This is mainly useful for eDP panels drivers to wait for an eDPpanel to finish powering on. It is optional for DP AUX controllersto implement this function. It is required for DP AUX endpoints(panel drivers) to call this function after powering up but beforedoing AUX transfers unless the DP AUX endpoint driver knows thatwe’re not using the AUX controller’s HPD. One example of the paneldriver not needing to call this is if HPD is hooked up to a GPIOthat the panel driver can read directly.

If a DP AUX controller does not implement this function then itmay still support eDP panels that use the AUX controller’s built-inHPD signal by implementing a long wait for HPD in thetransfer()callback, though this is deprecated.

This function will efficiently wait for the HPD signal to beasserted. Thewait_us parameter that is passed in says that weknow that the HPD signal is expected to be asserted withinwait_usmicroseconds. This function could wait for longer thanwait_us ifthe logic in the DP controller has a long debouncing time. Theimportant thing is that if this function returns success that theDP controller is ready to send AUX transactions.

This function returns 0 if HPD was asserted or -ETIMEDOUT if timeexpired and HPD wasn’t asserted. This function should not printtimeout errors to the log.

The semantics of this function are designed to match thereadx_poll_timeout() function. That means await_us of 0 meansto wait forever. Likereadx_poll_timeout(), this function may sleep.

NOTE: this function specifically reports the state of the HPD pinthat’s associated with the DP AUX channel. This is different fromthe HPD concept in much of the rest of DRM which is more aboutphysical presence of a display. For eDP, for instance, a display isassumed always present even if the HPD pin is deasserted.

i2c_nack_count

Counts I2C NACKs, used for DP validation.

i2c_defer_count

Counts I2C DEFERs, used for DP validation.

cec

structcontaining fields used for CEC-Tunneling-over-AUX.

is_remote

Is this AUX CH actually using sideband messaging.

powered_down

If true then the remote endpoint is powered down.

no_zero_sized

If the hw can’t use zero sized transfers (NVIDIA)

dpcd_probe_disabled

If probing before a DPCD access is disabled.

Description

An AUX channel can also be used to transport I2C messages to a sink. Atypical application of that is to access an EDID that’s present in the sinkdevice. Thetransfer() function can also be used to execute suchtransactions. Thedrm_dp_aux_register() function registers an I2C adapterthat can be passed todrm_probe_ddc(). Upon removal, drivers should calldrm_dp_aux_unregister() to remove the I2C adapter. The I2C adapter uses longtransfers by default; if a partial response is received, the adapter willdrop down to the size given by the partial response for this transactiononly.

ssize_tdrm_dp_dpcd_readb(structdrm_dp_aux*aux,unsignedintoffset,u8*valuep)

read a single byte from the DPCD

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

unsignedintoffset

address of the register to read

u8*valuep

location where the value of the register will be stored

Description

Returns the number of bytes transferred (1) on success, or a negativeerror code on failure. In most of the cases you should be usingdrm_dp_dpcd_read_byte() instead.

intdrm_dp_dpcd_read_data(structdrm_dp_aux*aux,unsignedintoffset,void*buffer,size_tsize)

read a series of bytes from the DPCD

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel (SST or MST)

unsignedintoffset

address of the (first) register to read

void*buffer

buffer to store the register values

size_tsize

number of bytes inbuffer

Description

Returns zero (0) on success, or a negative errorcode on failure. -EIO is returned if the request was NAKed by the sink orif the retry count was exceeded. If not all bytes were transferred, thisfunction returns -EPROTO. Errors from the underlying AUX channel transferfunction, with the exception of -EBUSY (which causes the transaction tobe retried), are propagated to the caller.

intdrm_dp_dpcd_write_data(structdrm_dp_aux*aux,unsignedintoffset,void*buffer,size_tsize)

write a series of bytes to the DPCD

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel (SST or MST)

unsignedintoffset

address of the (first) register to write

void*buffer

buffer containing the values to write

size_tsize

number of bytes inbuffer

Description

Returns zero (0) on success, or a negative errorcode on failure. -EIO is returned if the request was NAKed by the sink orif the retry count was exceeded. If not all bytes were transferred, thisfunction returns -EPROTO. Errors from the underlying AUX channel transferfunction, with the exception of -EBUSY (which causes the transaction tobe retried), are propagated to the caller.

ssize_tdrm_dp_dpcd_writeb(structdrm_dp_aux*aux,unsignedintoffset,u8value)

write a single byte to the DPCD

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

unsignedintoffset

address of the register to write

u8value

value to write to the register

Description

Returns the number of bytes transferred (1) on success, or a negativeerror code on failure. In most of the cases you should be usingdrm_dp_dpcd_write_byte() instead.

intdrm_dp_dpcd_read_byte(structdrm_dp_aux*aux,unsignedintoffset,u8*valuep)

read a single byte from the DPCD

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

unsignedintoffset

address of the register to read

u8*valuep

location where the value of the register will be stored

Description

Returns zero (0) on success, or a negative error code on failure.

intdrm_dp_dpcd_write_byte(structdrm_dp_aux*aux,unsignedintoffset,u8value)

write a single byte to the DPCD

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

unsignedintoffset

address of the register to write

u8value

value to write to the register

Description

Returns zero (0) on success, or a negative error code on failure.

structdrm_dp_desc

DP branch/sink device descriptor

Definition:

struct drm_dp_desc {    struct drm_dp_dpcd_ident ident;    u32 quirks;};

Members

ident

DP device identification from DPCD 0x400 (sink) or 0x500 (branch).

quirks

Quirks; usedrm_dp_has_quirk() to query for the quirks.

enumdrm_dp_quirk

Display Port sink/branch device specific quirks

Constants

DP_DPCD_QUIRK_CONSTANT_N

The device requires main link attributes Mvid and Nvid to be limitedto 16 bits. So will give a constant value (0x8000) for compatability.

DP_DPCD_QUIRK_NO_PSR

The device does not support PSR even if reports that it supports ordriver still need to implement proper handling for such device.

DP_DPCD_QUIRK_NO_SINK_COUNT

The device does not set SINK_COUNT to a non-zero value.The driver should ignore SINK_COUNT during detection. Note thatdrm_dp_read_sink_count_cap() automatically checks for this quirk.

DP_DPCD_QUIRK_DSC_WITHOUT_VIRTUAL_DPCD

The device supports MST DSC despite not supporting Virtual DPCD.The DSC caps can be read from the physical aux instead.

DP_DPCD_QUIRK_CAN_DO_MAX_LINK_RATE_3_24_GBPS

The device supports a link rate of 3.24 Gbps (multiplier 0xc) despitethe DP_MAX_LINK_RATE register reporting a lower max multiplier.

DP_DPCD_QUIRK_HBLANK_EXPANSION_REQUIRES_DSC

The device applies HBLANK expansion for some modes, but thisrequires enabling DSC.

DP_DPCD_QUIRK_DSC_THROUGHPUT_BPP_LIMIT

The device doesn’t support DSC decompression at the maximum DSCpixel throughput and compressed bpp it indicates via its DPCD DSCcapabilities. The compressed bpp must be limited above a devicespecific DSC pixel throughput.

Description

Display Port sink and branch devices in the wild have a variety of bugs, tryto collect them here. The quirks are shared, but it’s up to the drivers toimplement workarounds for them.

booldrm_dp_has_quirk(conststructdrm_dp_desc*desc,enumdrm_dp_quirkquirk)

does the DP device have a specific quirk

Parameters

conststructdrm_dp_desc*desc

Device descriptor filled bydrm_dp_read_desc()

enumdrm_dp_quirkquirk

Quirk to query for

Description

Return true if DP device identified bydesc hasquirk.

structdrm_edp_backlight_info

Probed eDP backlight info struct

Definition:

struct drm_edp_backlight_info {    u8 pwmgen_bit_count;    u8 pwm_freq_pre_divider;    u32 max;    bool lsb_reg_used : 1;    bool aux_enable : 1;    bool aux_set : 1;    bool luminance_set : 1;};

Members

pwmgen_bit_count

The pwmgen bit count

pwm_freq_pre_divider

The PWM frequency pre-divider value being used for this backlight, if any

max

The maximum backlight level that may be set

lsb_reg_used

Do we also write values to the DP_EDP_BACKLIGHT_BRIGHTNESS_LSB register?

aux_enable

Does the panel support the AUX enable cap?

aux_set

Does the panel support setting the brightness through AUX?

luminance_set

Does the panel support setting the brightness through AUX using luminance values?

Description

This structure contains various data about an eDP backlight, which can be populated by usingdrm_edp_backlight_init().

structdrm_dp_phy_test_params

DP Phy Compliance parameters

Definition:

struct drm_dp_phy_test_params {    int link_rate;    u8 num_lanes;    u8 phy_pattern;    u8 hbr2_reset[2];    u8 custom80[10];    bool enhanced_frame_cap;};

Members

link_rate

Requested Link rate from DPCD 0x219

num_lanes

Number of lanes requested by sing through DPCD 0x220

phy_pattern

DP Phy test pattern from DPCD 0x248

hbr2_reset

DP HBR2_COMPLIANCE_SCRAMBLER_RESET from DCPD 0x24A and 0x24B

custom80

DP Test_80BIT_CUSTOM_PATTERN from DPCDs 0x250 through 0x259

enhanced_frame_cap

flag for enhanced frame capability.

constchar*drm_dp_phy_name(enumdrm_dp_phydp_phy)

Get the name of the given DP PHY

Parameters

enumdrm_dp_phydp_phy

The DP PHY identifier

Description

Given thedp_phy, get a user friendly name of the DP PHY, either “DPRX” or“LTTPR <N>”, or “<INVALID DP PHY>” on errors. The returned string is alwaysnon-NULL and valid.

Return

Name of the DP PHY.

voiddrm_dp_lttpr_wake_timeout_setup(structdrm_dp_aux*aux,booltransparent_mode)

Grant extended time for sink to wake up

Parameters

structdrm_dp_aux*aux

The DP AUX channel to use

booltransparent_mode

This is true if lttpr is in transparent mode

Description

This function checks if the sink needs any extended wake time, if it doesit grants this request. Post this setup the source device can keep tryingthe Aux transaction till the granted wake timeout.If this function is not called all Aux transactions are expected to takea default of 1ms before they throw an error.

intdrm_dp_dpcd_probe(structdrm_dp_aux*aux,unsignedintoffset)

probe a given DPCD address with a 1-byte read access

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel (SST)

unsignedintoffset

address of the register to probe

Description

Probe the provided DPCD address by reading 1 byte from it. The function canbe used to trigger some side-effect the read access has, like waking up thesink, without the need for the read-out value.

Returns 0 if the read access suceeded, or a negative error code on failure.

voiddrm_dp_dpcd_set_powered(structdrm_dp_aux*aux,boolpowered)

Set whether the DP device is powered

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel; for convenience it’s OK to pass NULL hereand the function will be a no-op.

boolpowered

true if powered; false if not

Description

If the endpoint device on the DP AUX bus is known to be powered downthen this function can be called to make future transfers fail immediatelyinstead of needing to time out.

If this function is never called then a device defaults to being powered.

voiddrm_dp_dpcd_set_probe(structdrm_dp_aux*aux,boolenable)

Set whether a probing before DPCD access is done

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

boolenable

Enable the probing if required

ssize_tdrm_dp_dpcd_read(structdrm_dp_aux*aux,unsignedintoffset,void*buffer,size_tsize)

read a series of bytes from the DPCD

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel (SST or MST)

unsignedintoffset

address of the (first) register to read

void*buffer

buffer to store the register values

size_tsize

number of bytes inbuffer

Description

Returns the number of bytes transferred on success, or a negative errorcode on failure. -EIO is returned if the request was NAKed by the sink orif the retry count was exceeded. If not all bytes were transferred, thisfunction returns -EPROTO. Errors from the underlying AUX channel transferfunction, with the exception of -EBUSY (which causes the transaction tobe retried), are propagated to the caller.

In most of the cases you want to usedrm_dp_dpcd_read_data() instead.

ssize_tdrm_dp_dpcd_write(structdrm_dp_aux*aux,unsignedintoffset,void*buffer,size_tsize)

write a series of bytes to the DPCD

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel (SST or MST)

unsignedintoffset

address of the (first) register to write

void*buffer

buffer containing the values to write

size_tsize

number of bytes inbuffer

Description

Returns the number of bytes transferred on success, or a negative errorcode on failure. -EIO is returned if the request was NAKed by the sink orif the retry count was exceeded. If not all bytes were transferred, thisfunction returns -EPROTO. Errors from the underlying AUX channel transferfunction, with the exception of -EBUSY (which causes the transaction tobe retried), are propagated to the caller.

In most of the cases you want to usedrm_dp_dpcd_write_data() instead.

intdrm_dp_dpcd_read_link_status(structdrm_dp_aux*aux,u8status[DP_LINK_STATUS_SIZE])

read DPCD link status (bytes 0x202-0x207)

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

u8status[DP_LINK_STATUS_SIZE]

buffer to store the link status in (must be at least 6 bytes)

Description

Returns a negative error code on failure or 0 on success.

intdrm_dp_dpcd_read_phy_link_status(structdrm_dp_aux*aux,enumdrm_dp_phydp_phy,u8link_status[DP_LINK_STATUS_SIZE])

get the link status information for a DP PHY

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

enumdrm_dp_phydp_phy

the DP PHY to get the link status for

u8link_status[DP_LINK_STATUS_SIZE]

buffer to return the status in

Description

Fetch the AUX DPCD registers for the DPRX or an LTTPR PHY link status. Thelayout of the returnedlink_status matches the DPCD register layout of theDPRX PHY link status.

Returns 0 if the information was read successfully or a negative error codeon failure.

intdrm_dp_link_power_up(structdrm_dp_aux*aux,unsignedcharrevision)

power up a DisplayPort link

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

unsignedcharrevision

DPCD revision supported on the link

Description

Returns 0 on success or a negative error code on failure.

intdrm_dp_link_power_down(structdrm_dp_aux*aux,unsignedcharrevision)

power down a DisplayPort link

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

unsignedcharrevision

DPCD revision supported on the link

Description

Returns 0 on success or a negative error code on failure.

intdrm_dp_dpcd_write_payload(structdrm_dp_aux*aux,intvcpid,u8start_time_slot,u8time_slot_count)

Write Virtual Channel information to payload table

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

intvcpid

Virtual Channel Payload ID

u8start_time_slot

Starting time slot

u8time_slot_count

Time slot count

Description

Write the Virtual Channel payload allocation table, checking the payloadupdate status and retrying as necessary.

Return

0 on success, negative error otherwise

intdrm_dp_dpcd_clear_payload(structdrm_dp_aux*aux)

Clear the entire VC Payload ID table

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

Description

Clear the entire VC Payload ID table.

Return

0 on success, negative error code on errors.

intdrm_dp_dpcd_poll_act_handled(structdrm_dp_aux*aux,inttimeout_ms)

Poll for ACT handled status

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

inttimeout_ms

Timeout in ms

Description

Try waiting for the sink to finish updating its payload table by polling forthe ACT handled bit of DP_PAYLOAD_TABLE_UPDATE_STATUS for up totimeout_msmilliseconds, defaulting to 3000 ms if 0.

Return

0 if the ACT was handled in time, negative error code on failure.

booldrm_dp_downstream_is_type(constu8dpcd[DP_RECEIVER_CAP_SIZE],constu8port_cap[4],u8type)

is the downstream facing port of certain type?

Parameters

constu8dpcd[DP_RECEIVER_CAP_SIZE]

DisplayPort configuration data

constu8port_cap[4]

port capabilities

u8type

port type to be checked. Can be:DP_DS_PORT_TYPE_DP,DP_DS_PORT_TYPE_VGA,DP_DS_PORT_TYPE_DVI,DP_DS_PORT_TYPE_HDMI,DP_DS_PORT_TYPE_NON_EDID,DP_DS_PORT_TYPE_DP_DUALMODE orDP_DS_PORT_TYPE_WIRELESS.

Description

Caveat: Only works with DPCD 1.1+ port caps.

Return

whether the downstream facing port matches the type.

booldrm_dp_downstream_is_tmds(constu8dpcd[DP_RECEIVER_CAP_SIZE],constu8port_cap[4],conststructdrm_edid*drm_edid)

is the downstream facing port TMDS?

Parameters

constu8dpcd[DP_RECEIVER_CAP_SIZE]

DisplayPort configuration data

constu8port_cap[4]

port capabilities

conststructdrm_edid*drm_edid

EDID

Return

whether the downstream facing port is TMDS (HDMI/DVI).

booldrm_dp_send_real_edid_checksum(structdrm_dp_aux*aux,u8real_edid_checksum)

send back real edid checksum value

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

u8real_edid_checksum

real edid checksum for the last block

Return

True on success

intdrm_dp_read_dpcd_caps(structdrm_dp_aux*aux,u8dpcd[DP_RECEIVER_CAP_SIZE])

read DPCD caps and extended DPCD caps if available

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

u8dpcd[DP_RECEIVER_CAP_SIZE]

Buffer to store the resulting DPCD in

Description

Attempts to read the base DPCD caps foraux. Additionally, this functionchecks for and reads the extended DPRX caps (DP_DP13_DPCD_REV) ifpresent.

Return

0 if the DPCD was read successfully, negative error codeotherwise.

intdrm_dp_read_downstream_info(structdrm_dp_aux*aux,constu8dpcd[DP_RECEIVER_CAP_SIZE],u8downstream_ports[DP_MAX_DOWNSTREAM_PORTS])

read DPCD downstream port info if available

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

constu8dpcd[DP_RECEIVER_CAP_SIZE]

A cached copy of the port’s DPCD

u8downstream_ports[DP_MAX_DOWNSTREAM_PORTS]

buffer to store the downstream port info in

Description

See also:drm_dp_downstream_max_clock()drm_dp_downstream_max_bpc()

Return

0 if either the downstream port info was read successfully orthere was no downstream info to read, or a negative error code otherwise.

intdrm_dp_downstream_max_dotclock(constu8dpcd[DP_RECEIVER_CAP_SIZE],constu8port_cap[4])

extract downstream facing port max dot clock

Parameters

constu8dpcd[DP_RECEIVER_CAP_SIZE]

DisplayPort configuration data

constu8port_cap[4]

port capabilities

Return

Downstream facing port max dot clock in kHz on success,or 0 if max clock not defined

intdrm_dp_downstream_max_tmds_clock(constu8dpcd[DP_RECEIVER_CAP_SIZE],constu8port_cap[4],conststructdrm_edid*drm_edid)

extract downstream facing port max TMDS clock

Parameters

constu8dpcd[DP_RECEIVER_CAP_SIZE]

DisplayPort configuration data

constu8port_cap[4]

port capabilities

conststructdrm_edid*drm_edid

EDID

Return

HDMI/DVI downstream facing port max TMDS clock in kHz on success,or 0 if max TMDS clock not defined

intdrm_dp_downstream_min_tmds_clock(constu8dpcd[DP_RECEIVER_CAP_SIZE],constu8port_cap[4],conststructdrm_edid*drm_edid)

extract downstream facing port min TMDS clock

Parameters

constu8dpcd[DP_RECEIVER_CAP_SIZE]

DisplayPort configuration data

constu8port_cap[4]

port capabilities

conststructdrm_edid*drm_edid

EDID

Return

HDMI/DVI downstream facing port min TMDS clock in kHz on success,or 0 if max TMDS clock not defined

intdrm_dp_downstream_max_bpc(constu8dpcd[DP_RECEIVER_CAP_SIZE],constu8port_cap[4],conststructdrm_edid*drm_edid)

extract downstream facing port max bits per component

Parameters

constu8dpcd[DP_RECEIVER_CAP_SIZE]

DisplayPort configuration data

constu8port_cap[4]

downstream facing port capabilities

conststructdrm_edid*drm_edid

EDID

Return

Max bpc on success or 0 if max bpc not defined

booldrm_dp_downstream_420_passthrough(constu8dpcd[DP_RECEIVER_CAP_SIZE],constu8port_cap[4])

determine downstream facing port YCbCr 4:2:0 pass-through capability

Parameters

constu8dpcd[DP_RECEIVER_CAP_SIZE]

DisplayPort configuration data

constu8port_cap[4]

downstream facing port capabilities

Return

whether the downstream facing port can pass through YCbCr 4:2:0

booldrm_dp_downstream_444_to_420_conversion(constu8dpcd[DP_RECEIVER_CAP_SIZE],constu8port_cap[4])

determine downstream facing port YCbCr 4:4:4->4:2:0 conversion capability

Parameters

constu8dpcd[DP_RECEIVER_CAP_SIZE]

DisplayPort configuration data

constu8port_cap[4]

downstream facing port capabilities

Return

whether the downstream facing port can convert YCbCr 4:4:4 to 4:2:0

booldrm_dp_downstream_rgb_to_ycbcr_conversion(constu8dpcd[DP_RECEIVER_CAP_SIZE],constu8port_cap[4],u8color_spc)

determine downstream facing port RGB->YCbCr conversion capability

Parameters

constu8dpcd[DP_RECEIVER_CAP_SIZE]

DisplayPort configuration data

constu8port_cap[4]

downstream facing port capabilities

u8color_spc

Colorspace for which conversion cap is sought

Return

whether the downstream facing port can convert RGB->YCbCr for a givencolorspace.

structdrm_display_mode*drm_dp_downstream_mode(structdrm_device*dev,constu8dpcd[DP_RECEIVER_CAP_SIZE],constu8port_cap[4])

return a mode for downstream facing port

Parameters

structdrm_device*dev

DRM device

constu8dpcd[DP_RECEIVER_CAP_SIZE]

DisplayPort configuration data

constu8port_cap[4]

port capabilities

Description

Provides a suitable mode for downstream facing ports without EDID.

Return

A new drm_display_mode on success or NULL on failure

intdrm_dp_downstream_id(structdrm_dp_aux*aux,charid[6])

identify branch device

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

charid[6]

DisplayPort branch device id

Description

Returns branch device id on success or NULL on failure

voiddrm_dp_downstream_debug(structseq_file*m,constu8dpcd[DP_RECEIVER_CAP_SIZE],constu8port_cap[4],conststructdrm_edid*drm_edid,structdrm_dp_aux*aux)

debug DP branch devices

Parameters

structseq_file*m

pointer for debugfs file

constu8dpcd[DP_RECEIVER_CAP_SIZE]

DisplayPort configuration data

constu8port_cap[4]

port capabilities

conststructdrm_edid*drm_edid

EDID

structdrm_dp_aux*aux

DisplayPort AUX channel

enumdrm_mode_subconnectordrm_dp_subconnector_type(constu8dpcd[DP_RECEIVER_CAP_SIZE],constu8port_cap[4])

get DP branch device type

Parameters

constu8dpcd[DP_RECEIVER_CAP_SIZE]

DisplayPort configuration data

constu8port_cap[4]

port capabilities

voiddrm_dp_set_subconnector_property(structdrm_connector*connector,enumdrm_connector_statusstatus,constu8*dpcd,constu8port_cap[4])

set subconnector for DP connector

Parameters

structdrm_connector*connector

connector to set property on

enumdrm_connector_statusstatus

connector status

constu8*dpcd

DisplayPort configuration data

constu8port_cap[4]

port capabilities

Description

Called by a driver on every detect event.

booldrm_dp_read_sink_count_cap(structdrm_connector*connector,constu8dpcd[DP_RECEIVER_CAP_SIZE],conststructdrm_dp_desc*desc)

Check whether a given connector has a valid sink count

Parameters

structdrm_connector*connector

The DRM connector to check

constu8dpcd[DP_RECEIVER_CAP_SIZE]

A cached copy of the connector’s DPCD RX capabilities

conststructdrm_dp_desc*desc

A cached copy of the connector’s DP descriptor

Description

See also:drm_dp_read_sink_count()

Return

True if the (e)DP connector has a valid sink count that shouldbe probed,false otherwise.

intdrm_dp_read_sink_count(structdrm_dp_aux*aux)

Retrieve the sink count for a given sink

Parameters

structdrm_dp_aux*aux

The DP AUX channel to use

Description

See also:drm_dp_read_sink_count_cap()

Return

The current sink count reported byaux, or a negative error codeotherwise.

voiddrm_dp_remote_aux_init(structdrm_dp_aux*aux)

minimally initialise a remote aux channel

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

Description

Used for remote aux channel in general. Merely initialize the crc workstruct.

voiddrm_dp_aux_init(structdrm_dp_aux*aux)

minimally initialise an aux channel

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

Description

If you need to use the drm_dp_aux’s i2c adapter prior to registering it withthe outside world, calldrm_dp_aux_init() first. For drivers which aregrandparents to their AUX adapters (e.g. the AUX adapter is parented by adrm_connector), you must still calldrm_dp_aux_register() once the connectorhas been registered to allow userspace access to the auxiliary DP channel.Likewise, for such drivers you should also assigndrm_dp_aux.drm_dev asearly as possible so that thedrm_device that corresponds to the AUX adaptermay be mentioned in debugging output from the DRM DP helpers.

For devices which use a separate platform device for their AUX adapters, thismay be called as early as required by the driver.

intdrm_dp_aux_register(structdrm_dp_aux*aux)

initialise and register aux channel

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

Description

Automatically callsdrm_dp_aux_init() if this hasn’t been done yet. Thisshould only be called once the parent ofaux,drm_dp_aux.dev, isinitialized. For devices which are grandparents of their AUX channels,drm_dp_aux.dev will typically be thedrm_connectordevice whichcorresponds toaux. For these devices, it’s advised to calldrm_dp_aux_register() indrm_connector_funcs.late_register, and likewise tocalldrm_dp_aux_unregister() indrm_connector_funcs.early_unregister.Functions which don’t follow this will likely Oops whenCONFIG_DRM_DISPLAY_DP_AUX_CHARDEV is enabled.

For devices where the AUX channel is a device that exists independently ofthedrm_device that uses it, such as SoCs and bridge devices, it isrecommended to calldrm_dp_aux_register() after adrm_device has beenassigned todrm_dp_aux.drm_dev, and likewise to calldrm_dp_aux_unregister() once thedrm_device should no longer be associatedwith the AUX channel (e.g. on bridge detach).

Drivers which need to use the aux channel before either of the two pointsmentioned above need to calldrm_dp_aux_init() in order to use the AUXchannel before registration.

Returns 0 on success or a negative error code on failure.

voiddrm_dp_aux_unregister(structdrm_dp_aux*aux)

unregister an AUX adapter

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

intdrm_dp_psr_setup_time(constu8psr_cap[EDP_PSR_RECEIVER_CAP_SIZE])

PSR setup in time usec

Parameters

constu8psr_cap[EDP_PSR_RECEIVER_CAP_SIZE]

PSR capabilities from DPCD

Return

PSR setup time for the panel in microseconds, negativeerror code on failure.

intdrm_dp_start_crc(structdrm_dp_aux*aux,structdrm_crtc*crtc)

start capture of frame CRCs

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

structdrm_crtc*crtc

CRTC displaying the frames whose CRCs are to be captured

Description

Returns 0 on success or a negative error code on failure.

intdrm_dp_stop_crc(structdrm_dp_aux*aux)

stop capture of frame CRCs

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

Description

Returns 0 on success or a negative error code on failure.

intdrm_dp_read_desc(structdrm_dp_aux*aux,structdrm_dp_desc*desc,boolis_branch)

read sink/branch descriptor from DPCD

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

structdrm_dp_desc*desc

Device descriptor to fill from DPCD

boolis_branch

true for branch devices, false for sink devices

Description

Read DPCD 0x400 (sink) or 0x500 (branch) intodesc. Also debug log theidentification.

Returns 0 on success or a negative error code on failure.

intdrm_dp_dump_lttpr_desc(structdrm_dp_aux*aux,enumdrm_dp_phydp_phy)

read and dump the DPCD descriptor for an LTTPR PHY

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

enumdrm_dp_phydp_phy

LTTPR PHY instance

Description

Read the DPCD LTTPR PHY descriptor fordp_phy and print a debug messagewith its details to dmesg.

Returns 0 on success or a negative error code on failure.

u8drm_dp_dsc_sink_bpp_incr(constu8dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE])

Get bits per pixel increment

Parameters

constu8dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE]

DSC capabilities from DPCD

Description

Returns the bpp precision supported by the DP sink.

u32drm_dp_dsc_slice_count_to_mask(intslice_count)

Convert a slice count to a slice count mask

Parameters

intslice_count

slice count

Description

Convertslice_count to a slice count mask.

Returns the slice count mask.

u32drm_dp_dsc_sink_slice_count_mask(constu8dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE],boolis_edp)

Get the mask of valid DSC sink slice counts

Parameters

constu8dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE]

the sink’s DSC DPCD capabilities

boolis_edp

true for an eDP sink

Description

Get the mask of supported slice counts from the sink’s DSC DPCD register.

Return

Mask of slice counts supported by the DSC sink:- > 0: bit#0,1,3,5..,23 set if the sink supports 1,2,4,6..,24 slices- 0: if the sink doesn’t support any slices

u8drm_dp_dsc_sink_max_slice_count(constu8dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE],boolis_edp)

Get the max slice count supported by the DSC sink.

Parameters

constu8dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE]

DSC capabilities from DPCD

boolis_edp

true if its eDP, false for DP

Description

Read the slice capabilities DPCD register from DSC sink to getthe maximum slice count supported. This is used to populatethe DSC parameters in thestructdrm_dsc_config by the driver.Driver creates an infoframe using these parameters to populatestructdrm_dsc_pps_infoframe. These are sent to the sink using DSCinfoframe using the helper functiondrm_dsc_pps_infoframe_pack()

Return

Maximum slice count supported by DSC sink or 0 its invalid

u8drm_dp_dsc_sink_line_buf_depth(constu8dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE])

Get the line buffer depth in bits

Parameters

constu8dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE]

DSC capabilities from DPCD

Description

Read the DSC DPCD register to parse the line buffer depth in bits which isnumber of bits of precision within the decoder line buffer supported bythe DSC sink. This is used to populate the DSC parameters in thestructdrm_dsc_config by the driver.Driver creates an infoframe using these parameters to populatestructdrm_dsc_pps_infoframe. These are sent to the sink using DSCinfoframe using the helper functiondrm_dsc_pps_infoframe_pack()

Return

Line buffer depth supported by DSC panel or 0 its invalid

intdrm_dp_dsc_sink_supported_input_bpcs(constu8dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE],u8dsc_bpc[3])

Get all the input bits per component values supported by the DSC sink.

Parameters

constu8dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE]

DSC capabilities from DPCD

u8dsc_bpc[3]

An array to be filled by this helper with supportedinput bpcs.

Description

Read the DSC DPCD from the sink device to parse the supported bits percomponent values. This is used to populate the DSC parametersin thestructdrm_dsc_config by the driver.Driver creates an infoframe using these parameters to populatestructdrm_dsc_pps_infoframe. These are sent to the sink using DSCinfoframe using the helper functiondrm_dsc_pps_infoframe_pack()

Return

Number of input BPC values parsed from the DPCD

intdrm_dp_dsc_sink_max_slice_throughput(constu8dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE],intpeak_pixel_rate,boolis_rgb_yuv444)

Get a DSC sink’s maximum pixel throughput per slice

Parameters

constu8dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE]

DSC sink’s capabilities from DPCD

intpeak_pixel_rate

Cumulative peak pixel rate in kHz

boolis_rgb_yuv444

The mode is either RGB or YUV444

Description

Return the DSC sink device’s maximum pixel throughput per slice, based onthe device’sdsc_dpcd capabilities, thepeak_pixel_rate of the transferredstream(s) and whether the output formatis_rgb_yuv444 or yuv422/yuv420.

Note thatpeak_pixel_rate is the total pixel rate transferred to the sameDSC/display sink. For instance to calculate a tile’s slice count of an MSTmulti-tiled display sink (not considering here the requiredrounding/alignment of slice count):

@peak_pixel_rate = tile_pixel_rate * tile_counttotal_slice_count = @peak_pixel_rate / drm_dp_dsc_sink_max_slice_throughput(@peak_pixel_rate)tile_slice_count = total_slice_count / tile_count

Return

The maximum pixel throughput per slice supported by the DSC sink devicein kPixels/sec.

intdrm_dp_dsc_branch_max_overall_throughput(constu8dsc_branch_dpcd[DP_DSC_BRANCH_CAP_SIZE],boolis_rgb_yuv444)

Branch device’s max overall DSC pixel throughput

Parameters

constu8dsc_branch_dpcd[DP_DSC_BRANCH_CAP_SIZE]

DSC branch capabilities from DPCD

boolis_rgb_yuv444

The mode is either RGB or YUV444

Description

Return the branch device’s maximum overall DSC pixel throughput, based onthe device’s DPCD DSC branch capabilities, and whether the outputformatis_rgb_yuv444 or yuv422/yuv420.

Return

  • 0: The maximum overall throughput capability is not indicated by

    the device separately and it must be determined from the per-slicemax throughput (seedrm_dp_dsc_branch_slice_max_throughput())and the maximum slice count supported by the device.

  • > 0: The maximum overall DSC pixel throughput supported by the branch

    device in kPixels/sec.

intdrm_dp_dsc_branch_max_line_width(constu8dsc_branch_dpcd[DP_DSC_BRANCH_CAP_SIZE])

Branch device’s max DSC line width

Parameters

constu8dsc_branch_dpcd[DP_DSC_BRANCH_CAP_SIZE]

DSC branch capabilities from DPCD

Description

Return the branch device’s maximum overall DSC line width, based onthe device’sdsc_branch_dpcd capabilities.

Return

  • 0: The maximum line width is not indicated by the device

    separately and it must be determined from the maximumslice count and slice-width supported by the device.

  • -EINVAL: The device indicates an invalid maximum line width

    (< 5120 pixels).

  • >= 5120: The maximum line width in pixels.

intdrm_dp_read_lttpr_common_caps(structdrm_dp_aux*aux,constu8dpcd[DP_RECEIVER_CAP_SIZE],u8caps[DP_LTTPR_COMMON_CAP_SIZE])

read the LTTPR common capabilities

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

constu8dpcd[DP_RECEIVER_CAP_SIZE]

DisplayPort configuration data

u8caps[DP_LTTPR_COMMON_CAP_SIZE]

buffer to return the capability info in

Description

Read capabilities common to all LTTPRs.

Returns 0 on success or a negative error code on failure.

intdrm_dp_read_lttpr_phy_caps(structdrm_dp_aux*aux,constu8dpcd[DP_RECEIVER_CAP_SIZE],enumdrm_dp_phydp_phy,u8caps[DP_LTTPR_PHY_CAP_SIZE])

read the capabilities for a given LTTPR PHY

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

constu8dpcd[DP_RECEIVER_CAP_SIZE]

DisplayPort configuration data

enumdrm_dp_phydp_phy

LTTPR PHY to read the capabilities for

u8caps[DP_LTTPR_PHY_CAP_SIZE]

buffer to return the capability info in

Description

Read the capabilities for the given LTTPR PHY.

Returns 0 on success or a negative error code on failure.

intdrm_dp_lttpr_count(constu8caps[DP_LTTPR_COMMON_CAP_SIZE])

get the number of detected LTTPRs

Parameters

constu8caps[DP_LTTPR_COMMON_CAP_SIZE]

LTTPR common capabilities

Description

Get the number of detected LTTPRs from the LTTPR common capabilities info.

Return

-ERANGE if more than supported number (8) of LTTPRs are detected-EINVAL if the DP_PHY_REPEATER_CNT register contains an invalid valueotherwise the number of detected LTTPRs

intdrm_dp_lttpr_max_link_rate(constu8caps[DP_LTTPR_COMMON_CAP_SIZE])

get the maximum link rate supported by all LTTPRs

Parameters

constu8caps[DP_LTTPR_COMMON_CAP_SIZE]

LTTPR common capabilities

Description

Returns the maximum link rate supported by all detected LTTPRs.

intdrm_dp_lttpr_set_transparent_mode(structdrm_dp_aux*aux,boolenable)

set the LTTPR in transparent mode

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

boolenable

Enable or disable transparent mode

Return

0 on success or a negative error code on failure.

intdrm_dp_lttpr_init(structdrm_dp_aux*aux,intlttpr_count)

init LTTPR transparency mode according to DP standard

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

intlttpr_count

Number of LTTPRs. Between 0 and 8, according to DP standard.Negative error code for any non-valid number.Seedrm_dp_lttpr_count().

Return

0 on success or a negative error code on failure.

intdrm_dp_lttpr_max_lane_count(constu8caps[DP_LTTPR_COMMON_CAP_SIZE])

get the maximum lane count supported by all LTTPRs

Parameters

constu8caps[DP_LTTPR_COMMON_CAP_SIZE]

LTTPR common capabilities

Description

Returns the maximum lane count supported by all detected LTTPRs.

booldrm_dp_lttpr_voltage_swing_level_3_supported(constu8caps[DP_LTTPR_PHY_CAP_SIZE])

check for LTTPR vswing3 support

Parameters

constu8caps[DP_LTTPR_PHY_CAP_SIZE]

LTTPR PHY capabilities

Description

Returns true if thecaps for an LTTPR TX PHY indicate support forvoltage swing level 3.

booldrm_dp_lttpr_pre_emphasis_level_3_supported(constu8caps[DP_LTTPR_PHY_CAP_SIZE])

check for LTTPR preemph3 support

Parameters

constu8caps[DP_LTTPR_PHY_CAP_SIZE]

LTTPR PHY capabilities

Description

Returns true if thecaps for an LTTPR TX PHY indicate support forpre-emphasis level 3.

intdrm_dp_get_phy_test_pattern(structdrm_dp_aux*aux,structdrm_dp_phy_test_params*data)

get the requested pattern from the sink.

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

structdrm_dp_phy_test_params*data

DP phy compliance test parameters.

Description

Returns 0 on success or a negative error code on failure.

intdrm_dp_set_phy_test_pattern(structdrm_dp_aux*aux,structdrm_dp_phy_test_params*data,u8dp_rev)

set the pattern to the sink.

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

structdrm_dp_phy_test_params*data

DP phy compliance test parameters.

u8dp_rev

DP revision to use for compliance testing

Description

Returns 0 on success or a negative error code on failure.

booldrm_dp_as_sdp_supported(structdrm_dp_aux*aux,constu8dpcd[DP_RECEIVER_CAP_SIZE])

check if adaptive sync sdp is supported

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

constu8dpcd[DP_RECEIVER_CAP_SIZE]

DisplayPort configuration data

Description

Returns true if adaptive sync sdp is supported, else returns false

booldrm_dp_vsc_sdp_supported(structdrm_dp_aux*aux,constu8dpcd[DP_RECEIVER_CAP_SIZE])

check if vsc sdp is supported

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

constu8dpcd[DP_RECEIVER_CAP_SIZE]

DisplayPort configuration data

Description

Returns true if vsc sdp is supported, else returns false

ssize_tdrm_dp_vsc_sdp_pack(conststructdrm_dp_vsc_sdp*vsc,structdp_sdp*sdp)

pack a given vsc sdp into generic dp_sdp

Parameters

conststructdrm_dp_vsc_sdp*vsc

vsc sdp initialized according to its purpose as defined intable 2-118 - table 2-120 in DP 1.4a specification

structdp_sdp*sdp

valid handle to the generic dp_sdp which will be packed

Description

Returns length of sdp on success and error code on failure

intdrm_dp_get_pcon_max_frl_bw(constu8dpcd[DP_RECEIVER_CAP_SIZE],constu8port_cap[4])

maximum frl supported by PCON

Parameters

constu8dpcd[DP_RECEIVER_CAP_SIZE]

DisplayPort configuration data

constu8port_cap[4]

port capabilities

Description

Returns maximum frl bandwidth supported by PCON in GBPS,returns 0 if not supported.

intdrm_dp_pcon_frl_prepare(structdrm_dp_aux*aux,boolenable_frl_ready_hpd)

Prepare PCON for FRL.

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

boolenable_frl_ready_hpd

Configure DP_PCON_ENABLE_HPD_READY.

Description

Returns 0 if success, else returns negative error code.

booldrm_dp_pcon_is_frl_ready(structdrm_dp_aux*aux)

Is PCON ready for FRL

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

Description

Returns true if success, else returns false.

intdrm_dp_pcon_frl_configure_1(structdrm_dp_aux*aux,intmax_frl_gbps,u8frl_mode)

Set HDMI LINK Configuration-Step1

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

intmax_frl_gbps

maximum frl bw to be configured between PCON and HDMI sink

u8frl_mode

FRL Training mode, it can be either Concurrent or Sequential.In Concurrent Mode, the FRL link bring up can be done along withDP Link training. In Sequential mode, the FRL link bring up is done prior tothe DP Link training.

Description

Returns 0 if success, else returns negative error code.

intdrm_dp_pcon_frl_configure_2(structdrm_dp_aux*aux,intmax_frl_mask,u8frl_type)

Set HDMI Link configuration Step-2

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

intmax_frl_mask

Max FRL BW to be tried by the PCON with HDMI Sink

u8frl_type

FRL training type, can be Extended, or Normal.In Normal FRL training, the PCON tries each frl bw from the max_frl_maskstarting from min, and stops when link training is successful. In ExtendedFRL training, all frl bw selected in the mask are trained by the PCON.

Description

Returns 0 if success, else returns negative error code.

intdrm_dp_pcon_reset_frl_config(structdrm_dp_aux*aux)

Re-Set HDMI Link configuration.

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

Description

Returns 0 if success, else returns negative error code.

intdrm_dp_pcon_frl_enable(structdrm_dp_aux*aux)

Enable HDMI link through FRL

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

Description

Returns 0 if success, else returns negative error code.

booldrm_dp_pcon_hdmi_link_active(structdrm_dp_aux*aux)

check if the PCON HDMI LINK status is active.

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

Description

Returns true if link is active else returns false.

intdrm_dp_pcon_hdmi_link_mode(structdrm_dp_aux*aux,u8*frl_trained_mask)

get the PCON HDMI LINK MODE

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

u8*frl_trained_mask

pointer to store bitmask of the trained bw configuration.Valid only if the MODE returned is FRL. For Normal Link training modeonly 1 of the bits will be set, but in case of Extended mode, more thanone bits can be set.

Description

Returns the link mode : TMDS or FRL on success, else returns negative errorcode.

voiddrm_dp_pcon_hdmi_frl_link_error_count(structdrm_dp_aux*aux,structdrm_connector*connector)

print the error count per lane during link failure between PCON and HDMI sink

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

structdrm_connector*connector

DRM connectorcode.

intdrm_dp_pcon_pps_default(structdrm_dp_aux*aux)

Let PCON fill the default pps parameters for DSC1.2 between PCON & HDMI2.1 sink

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

Description

Returns 0 on success, else returns negative error code.

intdrm_dp_pcon_pps_override_buf(structdrm_dp_aux*aux,u8pps_buf[128])

Configure PPS encoder override buffer for HDMI sink

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

u8pps_buf[128]

128 bytes to be written into PPS buffer for HDMI sink by PCON.

Description

Returns 0 on success, else returns negative error code.

intdrm_edp_backlight_set_level(structdrm_dp_aux*aux,conststructdrm_edp_backlight_info*bl,u32level)

Set the backlight level of an eDP panel via AUX

Parameters

structdrm_dp_aux*aux

The DP AUX channel to use

conststructdrm_edp_backlight_info*bl

Backlight capability info fromdrm_edp_backlight_init()

u32level

The brightness level to set

Description

Sets the brightness level of an eDP panel’s backlight. Note that the panel’s backlight mustalready have been enabled by the driver by callingdrm_edp_backlight_enable().

Return

0 on success, negative error code on failure

intdrm_edp_backlight_enable(structdrm_dp_aux*aux,conststructdrm_edp_backlight_info*bl,constu32level)

Enable an eDP panel’s backlight using DPCD

Parameters

structdrm_dp_aux*aux

The DP AUX channel to use

conststructdrm_edp_backlight_info*bl

Backlight capability info fromdrm_edp_backlight_init()

constu32level

The initial backlight level to set via AUX, if there is one

Description

This function handles enabling DPCD backlight controls on a panel over DPCD, while additionallyrestoring any important backlight state such as the given backlight level, the brightness bytecount, backlight frequency, etc.

Note that certain panels do not support being enabled or disabled via DPCD, but instead requirethat the driver handle enabling/disabling the panel through implementation-specific means usingthe EDP_BL_PWR GPIO. For such panels,drm_edp_backlight_info.aux_enable will be set tofalse,this function becomes a no-op, and the driver is expected to handle powering the panel on usingthe EDP_BL_PWR GPIO.

Return

0 on success, negative error code on failure.

intdrm_edp_backlight_disable(structdrm_dp_aux*aux,conststructdrm_edp_backlight_info*bl)

Disable an eDP backlight using DPCD, if supported

Parameters

structdrm_dp_aux*aux

The DP AUX channel to use

conststructdrm_edp_backlight_info*bl

Backlight capability info fromdrm_edp_backlight_init()

Description

This function handles disabling DPCD backlight controls on a panel over AUX.

Note that certain panels do not support being enabled or disabled via DPCD, but instead requirethat the driver handle enabling/disabling the panel through implementation-specific means usingthe EDP_BL_PWR GPIO. For such panels,drm_edp_backlight_info.aux_enable will be set tofalse,this function becomes a no-op, and the driver is expected to handle powering the panel off usingthe EDP_BL_PWR GPIO.

Return

0 on success or no-op, negative error code on failure.

intdrm_edp_backlight_init(structdrm_dp_aux*aux,structdrm_edp_backlight_info*bl,u32max_luminance,u16driver_pwm_freq_hz,constu8edp_dpcd[EDP_DISPLAY_CTL_CAP_SIZE],u32*current_level,u8*current_mode,boolneed_luminance)

Probe a display panel’s TCON using the standard VESA eDP backlight interface.

Parameters

structdrm_dp_aux*aux

The DP aux device to use for probing

structdrm_edp_backlight_info*bl

Thedrm_edp_backlight_infostructto fill out with information on the backlight

u32max_luminance

max luminance when need luminance is set as true

u16driver_pwm_freq_hz

Optional PWM frequency from the driver in hz

constu8edp_dpcd[EDP_DISPLAY_CTL_CAP_SIZE]

A cached copy of the eDP DPCD

u32*current_level

Where to store the probed brightness level, if any

u8*current_mode

Where to store the currently set backlight control mode

boolneed_luminance

Tells us if a we want to manipulate backlight using luminance values

Description

Initializes adrm_edp_backlight_infostructby probingaux for it’s backlight capabilities,along with also probing the current and maximum supported brightness levels.

Ifdriver_pwm_freq_hz is non-zero, this will be used as the backlight frequency. Otherwise, thedefault frequency from the panel is used.

Return

0 on success, negative error code on failure.

intdrm_panel_dp_aux_backlight(structdrm_panel*panel,structdrm_dp_aux*aux)

create and use DP AUX backlight

Parameters

structdrm_panel*panel

DRM panel

structdrm_dp_aux*aux

The DP AUX channel to use

Description

Use this function to create and handle backlight if your panelsupports backlight control over DP AUX channel using DPCDregisters as per VESA’s standard backlight control interface.

When the panel is enabled backlight will be enabled after asuccessful call todrm_panel_funcs.enable()

When the panel is disabled backlight will be disabled before thecall todrm_panel_funcs.disable().

A typical implementation for a panel driver supporting backlightcontrol over DP AUX will call this function at probe time.Backlight will then be handled transparently without requiringany intervention from the driver.

drm_panel_dp_aux_backlight() must be called after the call todrm_panel_init().

Return

0 on success or a negative error code on failure.

intdrm_dp_link_symbol_cycles(intlane_count,intpixels,intdsc_slice_count,intbpp_x16,intsymbol_size,boolis_mst)

calculate the link symbol count with/without dsc

Parameters

intlane_count

DP link lane count

intpixels

number of pixels in a scanline

intdsc_slice_count

number of slices for DSC or ‘0’ for non-DSC

intbpp_x16

bits per pixel in .4 binary fixed format

intsymbol_size

DP symbol size

boolis_mst

true for MST andfalse for SST

Description

Calculate the link symbol cycles for both DSC (dsc_slice_count !=0) andnon-DSC case (dsc_slice_count == 0) and return the count.

intdrm_dp_bw_overhead(intlane_count,inthactive,intdsc_slice_count,intbpp_x16,unsignedlongflags)

Calculate the BW overhead of a DP link stream

Parameters

intlane_count

DP link lane count

inthactive

pixel count of the active period in one scanline of the stream

intdsc_slice_count

number of slices for DSC or ‘0’ for non-DSC

intbpp_x16

bits per pixel in .4 binary fixed point

unsignedlongflags

DRM_DP_OVERHEAD_x flags

Description

Calculate the BW allocation overhead of a DP link stream, dependingon the link’s-lane_count- SST/MST mode (flags /DRM_DP_OVERHEAD_MST)- symbol size (flags /DRM_DP_OVERHEAD_UHBR)- FEC mode (flags /DRM_DP_OVERHEAD_FEC)- SSC/REF_CLK mode (flags /DRM_DP_OVERHEAD_SSC_REF_CLK)as well as the stream’s-hactive timing-bpp_x16 color depth- compression mode (dsc_slice_count != 0)Note that this overhead doesn’t account for the 8b/10b, 128b/132bchannel coding efficiency, for that seedrm_dp_link_bw_channel_coding_efficiency().

Returns the overhead as 100% + overhead% in 1ppm units.

intdrm_dp_bw_channel_coding_efficiency(boolis_uhbr)

Get a DP link’s channel coding efficiency

Parameters

boolis_uhbr

Whether the link has a 128b/132b channel coding

Description

Return the channel coding efficiency of the given DP link type, which iseither 8b/10b or 128b/132b (aka UHBR). The corresponding overhead includesthe 8b -> 10b, 128b -> 132b pixel data to link symbol conversion overheadand for 128b/132b any link or PHY level control symbol insertion overhead(LLCP, FEC, PHY sync, see DP Standard v2.1 3.5.2.18). For 8b/10b thecorresponding FEC overhead is BW allocation specific, included in the valuereturned bydrm_dp_bw_overhead().

Returns the efficiency in the 100%/coding-overhead% ratio in1ppm units.

intdrm_dp_max_dprx_data_rate(intmax_link_rate,intmax_lanes)

Get the max data bandwidth of a DPRX sink

Parameters

intmax_link_rate

max DPRX link rate in 10kbps units

intmax_lanes

max DPRX lane count

Description

Given a link rate and lanes, get the data bandwidth.

Data bandwidth is the actual payload rate, which depends on the databandwidth efficiency and the link rate.

Note that protocol layers above the DPRX link level considered here canfurther limit the maximum data rate. Such layers are the MST topology (withlimits on the link between the source and first branch device as well as onthe whole MST path until the DPRX link) and (Thunderbolt) DP tunnels -which in turn can encapsulate an MST link with its own limit - with eachSST or MST encapsulated tunnel sharing the BW of a tunnel group.

Returns the maximum data rate in kBps units.

Display Port CEC Helper Functions Reference

These functions take care of supporting the CEC-Tunneling-over-AUXfeature of DisplayPort-to-HDMI adapters.

voiddrm_dp_cec_irq(structdrm_dp_aux*aux)

handle CEC interrupt, if any

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

Description

Should be called when handling an IRQ_HPD request. If CEC-tunneling-over-AUXis present, then it will check for a CEC_IRQ and handle it accordingly.

voiddrm_dp_cec_register_connector(structdrm_dp_aux*aux,structdrm_connector*connector)

register a new connector

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

structdrm_connector*connector

drm connector

Description

A new connector was registered with associated CEC adapter name andCEC adapter parent device. After registering the name and parentdrm_dp_cec_set_edid() is called to check if the connector supportsCEC and to register a CEC adapter if that is the case.

voiddrm_dp_cec_unregister_connector(structdrm_dp_aux*aux)

unregister the CEC adapter, if any

Parameters

structdrm_dp_aux*aux

DisplayPort AUX channel

Display Port Dual Mode Adaptor Helper Functions Reference

Helper functions to deal with DP dual mode (aka. DP++) adaptors.

Type 1:Adaptor registers (if any) and the sink DDC bus may be accessed via I2C.

Type 2:Adaptor registers and sink DDC bus can be accessed either via I2C orI2C-over-AUX. Source devices may choose to implement either of theseaccess methods.

enumdrm_lspcon_mode

Constants

DRM_LSPCON_MODE_INVALID

No LSPCON.

DRM_LSPCON_MODE_LS

Level shifter mode of LSPCONwhich drives DP++ to HDMI 1.4 conversion.

DRM_LSPCON_MODE_PCON

Protocol converter mode of LSPCONwhich drives DP++ to HDMI 2.0 active conversion.

enumdrm_dp_dual_mode_type

Type of the DP dual mode adaptor

Constants

DRM_DP_DUAL_MODE_NONE

No DP dual mode adaptor

DRM_DP_DUAL_MODE_UNKNOWN

Could be either none or type 1 DVI adaptor

DRM_DP_DUAL_MODE_TYPE1_DVI

Type 1 DVI adaptor

DRM_DP_DUAL_MODE_TYPE1_HDMI

Type 1 HDMI adaptor

DRM_DP_DUAL_MODE_TYPE2_DVI

Type 2 DVI adaptor

DRM_DP_DUAL_MODE_TYPE2_HDMI

Type 2 HDMI adaptor

DRM_DP_DUAL_MODE_LSPCON

Level shifter / protocol converter

ssize_tdrm_dp_dual_mode_read(structi2c_adapter*adapter,u8offset,void*buffer,size_tsize)

Read from the DP dual mode adaptor register(s)

Parameters

structi2c_adapter*adapter

I2C adapter for the DDC bus

u8offset

register offset

void*buffer

buffer for return data

size_tsize

size of the buffer

Description

Readssize bytes from the DP dual mode adaptor registersstarting atoffset.

Return

0 on success, negative error code on failure

ssize_tdrm_dp_dual_mode_write(structi2c_adapter*adapter,u8offset,constvoid*buffer,size_tsize)

Write to the DP dual mode adaptor register(s)

Parameters

structi2c_adapter*adapter

I2C adapter for the DDC bus

u8offset

register offset

constvoid*buffer

buffer for write data

size_tsize

size of the buffer

Description

Writessize bytes to the DP dual mode adaptor registersstarting atoffset.

Return

0 on success, negative error code on failure

enumdrm_dp_dual_mode_typedrm_dp_dual_mode_detect(conststructdrm_device*dev,structi2c_adapter*adapter)

Identify the DP dual mode adaptor

Parameters

conststructdrm_device*dev

drm_device to use

structi2c_adapter*adapter

I2C adapter for the DDC bus

Description

Attempt to identify the type of the DP dual mode adaptor used.

Note that when the answer isDRM_DP_DUAL_MODE_UNKNOWN it’s notcertain whether we’re dealing with a native HDMI port ora type 1 DVI dual mode adaptor. The driver will have to usesome other hardware/driver specific mechanism to make thatdistinction.

Return

The type of the DP dual mode adaptor used

intdrm_dp_dual_mode_max_tmds_clock(conststructdrm_device*dev,enumdrm_dp_dual_mode_typetype,structi2c_adapter*adapter)

Max TMDS clock for DP dual mode adaptor

Parameters

conststructdrm_device*dev

drm_device to use

enumdrm_dp_dual_mode_typetype

DP dual mode adaptor type

structi2c_adapter*adapter

I2C adapter for the DDC bus

Description

Determine the max TMDS clock the adaptor supports based on thetype of the dual mode adaptor and the DP_DUAL_MODE_MAX_TMDS_CLOCKregister (on type2 adaptors). As some type 1 adaptors haveproblems with registers (see comments indrm_dp_dual_mode_detect())we don’t read the register on those, instead we simply assumea 165 MHz limit based on the specification.

Return

Maximum supported TMDS clock rate for the DP dual mode adaptor in kHz.

intdrm_dp_dual_mode_get_tmds_output(conststructdrm_device*dev,enumdrm_dp_dual_mode_typetype,structi2c_adapter*adapter,bool*enabled)

Get the state of the TMDS output buffers in the DP dual mode adaptor

Parameters

conststructdrm_device*dev

drm_device to use

enumdrm_dp_dual_mode_typetype

DP dual mode adaptor type

structi2c_adapter*adapter

I2C adapter for the DDC bus

bool*enabled

current state of the TMDS output buffers

Description

Get the state of the TMDS output buffers in the adaptor. Fortype2 adaptors this is queried from the DP_DUAL_MODE_TMDS_OENregister. As some type 1 adaptors have problems with registers(see comments indrm_dp_dual_mode_detect()) we don’t read theregister on those, instead we simply assume that the buffersare always enabled.

Return

0 on success, negative error code on failure

intdrm_dp_dual_mode_set_tmds_output(conststructdrm_device*dev,enumdrm_dp_dual_mode_typetype,structi2c_adapter*adapter,boolenable)

Enable/disable TMDS output buffers in the DP dual mode adaptor

Parameters

conststructdrm_device*dev

drm_device to use

enumdrm_dp_dual_mode_typetype

DP dual mode adaptor type

structi2c_adapter*adapter

I2C adapter for the DDC bus

boolenable

enable (as opposed to disable) the TMDS output buffers

Description

Set the state of the TMDS output buffers in the adaptor. Fortype2 this is set via the DP_DUAL_MODE_TMDS_OEN register.Type1 adaptors do not support any register writes.

Return

0 on success, negative error code on failure

constchar*drm_dp_get_dual_mode_type_name(enumdrm_dp_dual_mode_typetype)

Get the name of the DP dual mode adaptor type as a string

Parameters

enumdrm_dp_dual_mode_typetype

DP dual mode adaptor type

Return

String representation of the DP dual mode adaptor type

intdrm_lspcon_get_mode(conststructdrm_device*dev,structi2c_adapter*adapter,enumdrm_lspcon_mode*mode)

Get LSPCON’s current mode of operation by reading offset (0x80, 0x41)

Parameters

conststructdrm_device*dev

drm_device to use

structi2c_adapter*adapter

I2C-over-aux adapter

enumdrm_lspcon_mode*mode

current lspcon mode of operation output variable

Return

0 on success, sets the current_mode value to appropriate mode-error on failure

intdrm_lspcon_set_mode(conststructdrm_device*dev,structi2c_adapter*adapter,enumdrm_lspcon_modemode,inttime_out)

Change LSPCON’s mode of operation by writing offset (0x80, 0x40)

Parameters

conststructdrm_device*dev

drm_device to use

structi2c_adapter*adapter

I2C-over-aux adapter

enumdrm_lspcon_modemode

required mode of operation

inttime_out

LSPCON mode change settle timeout

Return

0 on success, -error on failure/timeout

Display Port MST Helpers

Overview

These functions contain parts of the DisplayPort 1.2a MultiStream Transportprotocol. The helpers contain a topology manager and bandwidth manager.The helpers encapsulate the sending and received of sideband msgs.

Topology refcount overview

The refcounting schemes forstructdrm_dp_mst_branch andstructdrm_dp_mst_port are somewhat unusual. Both ports and branch devices havetwo different kinds of refcounts: topology refcounts, and malloc refcounts.

Topology refcounts are not exposed to drivers, and are handled internallyby the DP MST helpers. The helpers use them in order to prevent thein-memory topology state from being changed in the middle of criticaloperations like changing the internal state of payload allocations. Thismeans each branch and port will be considered to be connected to the restof the topology until its topology refcount reaches zero. Additionally,for ports this means that their associatedstructdrm_connector will stayregistered with userspace until the port’s refcount reaches 0.

Malloc refcount overview

Malloc references are used to keep astructdrm_dp_mst_port orstructdrm_dp_mst_branch allocated even after all of its topology references havebeen dropped, so that the driver or MST helpers can safely access eachbranch’s last known state before it was disconnected from the topology.When the malloc refcount of a port or branch reaches 0, the memoryallocation containing thestructdrm_dp_mst_branch orstructdrm_dp_mst_port respectively will be freed.

Forstructdrm_dp_mst_branch, malloc refcounts are not currently exposedto drivers. As of writing this documentation, there are no drivers thathave a usecase for accessingstructdrm_dp_mst_branch outside of the MSThelpers. Exposing this API to drivers in a race-free manner would take moretweaking of the refcounting scheme, however patches are welcome providedthere is a legitimate driver usecase for this.

Refcount relationships in a topology

Let’s take a look at why the relationship between topology and mallocrefcounts is designed the way it is.

digraphT{/*Makesureourpayloadsarealwaysdrawnbelowthedrivernode*/subgraphcluster_driver{fillcolor=grey;style=filled;driver->{payload1,payload2}[dir=none];}/*Drivermallocreferences*/edge[style=dashed];driver->port1;driver->port2;driver->port3:e;driver->port4;payload1:s->port1:e;payload2:s->port3:e;edge[style=""];subgraphcluster_topology{label="Topology Manager";labelloc=bottom;/*Topologyreferences*/mstb1->{port1,port2};port1->mstb2;port2->mstb3->{port3,port4};port3->mstb4;/*Mallocreferences*/edge[style=dashed;dir=back];mstb1->{port1,port2};port1->mstb2;port2->mstb3->{port3,port4};port3->mstb4;}driver[label="DRM driver";style=filled;shape=box;fillcolor=lightblue];payload1[label="Payload #1";style=filled;shape=box;fillcolor=lightblue];payload2[label="Payload #2";style=filled;shape=box;fillcolor=lightblue];mstb1[label="MSTB #1";style=filled;fillcolor=palegreen;shape=oval];mstb2[label="MSTB #2";style=filled;fillcolor=palegreen;shape=oval];mstb3[label="MSTB #3";style=filled;fillcolor=palegreen;shape=oval];mstb4[label="MSTB #4";style=filled;fillcolor=palegreen;shape=oval];port1[label="Port #1";shape=oval];port2[label="Port #2";shape=oval];port3[label="Port #3";shape=oval];port4[label="Port #4";shape=oval];}

An example of topology and malloc refs in a DP MST topology with twoactive payloads. Topology refcount increments are indicated by solidlines, and malloc refcount increments are indicated by dashed lines.Each starts from the branch which incremented the refcount, and ends atthe branch to which the refcount belongs to, i.e. the arrow points thesame way as the C pointers used to reference a structure.

As you can see in the above figure, every branch increments the topologyrefcount of its children, and increments the malloc refcount of itsparent. Additionally, every payload increments the malloc refcount of itsassigned port by 1.

So, what would happen if MSTB #3 from the above figure was unplugged fromthe system, but the driver hadn’t yet removed payload #2 from port #3? Thetopology would start to look like the figure below.

digraphT{/*Makesureourpayloadsarealwaysdrawnbelowthedrivernode*/subgraphcluster_driver{fillcolor=grey;style=filled;driver->{payload1,payload2}[dir=none];}/*Drivermallocreferences*/edge[style=dashed];driver->port1;driver->port2;driver->port3:e;driver->port4[color=red];payload1:s->port1:e;payload2:s->port3:e;edge[style=""];subgraphcluster_topology{label="Topology Manager";labelloc=bottom;/*Topologyreferences*/mstb1->{port1,port2};port1->mstb2;edge[color=red];port2->mstb3->{port3,port4};port3->mstb4;edge[color=""];/*Mallocreferences*/edge[style=dashed;dir=back];mstb1->{port1,port2};port1->mstb2;port2->mstb3->port3;edge[color=red];mstb3->port4;port3->mstb4;}mstb1[label="MSTB #1";style=filled;fillcolor=palegreen];mstb2[label="MSTB #2";style=filled;fillcolor=palegreen];mstb3[label="MSTB #3";style=filled;fillcolor=palegreen];mstb4[label="MSTB #4";style=filled;fillcolor=grey];port1[label="Port #1"];port2[label="Port #2"];port3[label="Port #3"];port4[label="Port #4";style=filled;fillcolor=grey];driver[label="DRM driver";style=filled;shape=box;fillcolor=lightblue];payload1[label="Payload #1";style=filled;shape=box;fillcolor=lightblue];payload2[label="Payload #2";style=filled;shape=box;fillcolor=lightblue];}

Ports and branch devices which have been released from memory arecolored grey, and references which have been removed are colored red.

Whenever a port or branch device’s topology refcount reaches zero, it willdecrement the topology refcounts of all its children, the malloc refcountof its parent, and finally its own malloc refcount. For MSTB #4 and port#4, this means they both have been disconnected from the topology and freedfrom memory. But, because payload #2 is still holding a reference to port#3, port #3 is removed from the topology but itsstructdrm_dp_mst_portis still accessible from memory. This also means port #3 has not yetdecremented the malloc refcount of MSTB #3, so itsstructdrm_dp_mst_branch will also stay allocated in memory until port #3’smalloc refcount reaches 0.

This relationship is necessary because in order to release payload #2, weneed to be able to figure out the last relative of port #3 that’s stillconnected to the topology. In this case, we would travel up the topology asshown below.

digraphT{/*Makesureourpayloadsarealwaysdrawnbelowthedrivernode*/subgraphcluster_driver{fillcolor=grey;style=filled;edge[dir=none];driver->payload1;driver->payload2[penwidth=3];edge[dir=""];}/*Drivermallocreferences*/edge[style=dashed];driver->port1;driver->port2;driver->port3:e;driver->port4[color=grey];payload1:s->port1:e;payload2:s->port3:e[penwidth=3];edge[style=""];subgraphcluster_topology{label="Topology Manager";labelloc=bottom;/*Topologyreferences*/mstb1->{port1,port2};port1->mstb2;edge[color=grey];port2->mstb3->{port3,port4};port3->mstb4;edge[color=""];/*Mallocreferences*/edge[style=dashed;dir=back];mstb1->{port1,port2};port1->mstb2;port2->mstb3[penwidth=3];mstb3->port3[penwidth=3];edge[color=grey];mstb3->port4;port3->mstb4;}mstb1[label="MSTB #1";style=filled;fillcolor=palegreen];mstb2[label="MSTB #2";style=filled;fillcolor=palegreen];mstb3[label="MSTB #3";style=filled;fillcolor=palegreen;penwidth=3];mstb4[label="MSTB #4";style=filled;fillcolor=grey];port1[label="Port #1"];port2[label="Port #2";penwidth=5];port3[label="Port #3";penwidth=3];port4[label="Port #4";style=filled;fillcolor=grey];driver[label="DRM driver";style=filled;shape=box;fillcolor=lightblue];payload1[label="Payload #1";style=filled;shape=box;fillcolor=lightblue];payload2[label="Payload #2";style=filled;shape=box;fillcolor=lightblue;penwidth=3];}

And finally, remove payload #2 by communicating with port #2 throughsideband transactions.

Functions Reference

structdrm_dp_mst_port

MST port

Definition:

struct drm_dp_mst_port {    struct kref topology_kref;    struct kref malloc_kref;#if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS);    struct drm_dp_mst_topology_ref_history topology_ref_history;#endif;    u8 port_num;    bool input;    bool mcs;    bool ddps;    u8 pdt;    bool ldps;    u8 dpcd_rev;    u8 num_sdp_streams;    u8 num_sdp_stream_sinks;    uint16_t full_pbn;    struct list_head next;    struct drm_dp_mst_branch *mstb;    struct drm_dp_aux aux;    struct drm_dp_aux *passthrough_aux;    struct drm_dp_mst_branch *parent;    struct drm_connector *connector;    struct drm_dp_mst_topology_mgr *mgr;    const struct drm_edid *cached_edid;    bool fec_capable;};

Members

topology_kref

refcount for this port’s lifetime in the topology,only the DP MST helpers should need to touch this

malloc_kref

refcount for the memory allocation containing thisstructure. Seedrm_dp_mst_get_port_malloc() anddrm_dp_mst_put_port_malloc().

topology_ref_history

A history of each topologyreference/dereference. See CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS.

port_num

port number

input

if this port is an input port. Protected bydrm_dp_mst_topology_mgr.base.lock.

mcs

message capability status - DP 1.2 spec. Protected bydrm_dp_mst_topology_mgr.base.lock.

ddps

DisplayPort Device Plug Status - DP 1.2. Protected bydrm_dp_mst_topology_mgr.base.lock.

pdt

Peer Device Type. Protected bydrm_dp_mst_topology_mgr.base.lock.

ldps

Legacy Device Plug Status. Protected bydrm_dp_mst_topology_mgr.base.lock.

dpcd_rev

DPCD revision of device on this port. Protected bydrm_dp_mst_topology_mgr.base.lock.

num_sdp_streams

Number of simultaneous streams. Protected bydrm_dp_mst_topology_mgr.base.lock.

num_sdp_stream_sinks

Number of stream sinks. Protected bydrm_dp_mst_topology_mgr.base.lock.

full_pbn

Max possible bandwidth for this port. Protected bydrm_dp_mst_topology_mgr.base.lock.

next

link to next port on this branch device

mstb

the branch device connected to this port, if there is one.This should be considered protected for reading bydrm_dp_mst_topology_mgr.lock. There are two exceptions to this:drm_dp_mst_topology_mgr.up_req_work anddrm_dp_mst_topology_mgr.work, which do not grabdrm_dp_mst_topology_mgr.lock during reads but are the onlyupdaters of this list and are protected from writing concurrentlybydrm_dp_mst_topology_mgr.probe_lock.

aux

i2c aux transport to talk to device connected to this port, protectedbydrm_dp_mst_topology_mgr.base.lock.

passthrough_aux

parent aux to which DSC pass-through requests should besent, only set if DSC pass-through is possible.

parent

branch device parent of this port

connector

DRM connector this port is connected to. Protected bydrm_dp_mst_topology_mgr.base.lock.

mgr

topology manager this port lives under.

cached_edid

for DP logical ports - make tiling work by ensuringthat the EDID for all connectors is read immediately.

fec_capable

bool indicating if FEC can be supported up to thatpoint in the MST topology.

Description

This structure represents an MST port endpoint on a device somewherein the MST topology.

structdrm_dp_mst_branch

MST branch device.

Definition:

struct drm_dp_mst_branch {    struct kref topology_kref;    struct kref malloc_kref;#if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS);    struct drm_dp_mst_topology_ref_history topology_ref_history;#endif;    struct list_head destroy_next;    u8 rad[8];    u8 lct;    int num_ports;    struct list_head ports;    struct drm_dp_mst_port *port_parent;    struct drm_dp_mst_topology_mgr *mgr;    bool link_address_sent;    guid_t guid;};

Members

topology_kref

refcount for this branch device’s lifetime in thetopology, only the DP MST helpers should need to touch this

malloc_kref

refcount for the memory allocation containing thisstructure. Seedrm_dp_mst_get_mstb_malloc() anddrm_dp_mst_put_mstb_malloc().

topology_ref_history

A history of each topologyreference/dereference. See CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS.

destroy_next

linked-list entry used bydrm_dp_delayed_destroy_work()

rad

Relative Address of the MST branch.Fordrm_dp_mst_topology_mgr.mst_primary, it’s rad[8] are all 0,unset and unused. For MST branches connected after mst_primary,in each element of rad[] the nibbles are ordered by the mostsignifcant 4 bits first and the least significant 4 bits second.

lct

Link count total to talk to this branch device.

num_ports

number of ports on the branch.

ports

the list of ports on this branch device. This should beconsidered protected for reading bydrm_dp_mst_topology_mgr.lock.There are two exceptions to this:drm_dp_mst_topology_mgr.up_req_work anddrm_dp_mst_topology_mgr.work, which do not grabdrm_dp_mst_topology_mgr.lock during reads but are the onlyupdaters of this list and are protected from updating the listconcurrently bydrm_dp_mst_topology_mgr.probe_lock

port_parent

pointer to the port parent, NULL if toplevel.

mgr

topology manager for this branch device.

link_address_sent

if a link address message has been sent to this device yet.

guid

guid for DP 1.2 branch device. port under this branch can beidentified by port #.

Description

This structure represents an MST branch device, there is oneprimary branch device at the root, along with any other branches connectedto downstream port of parent branches.

structdrm_dp_mst_atomic_payload

Atomic state struct for an MST payload

Definition:

struct drm_dp_mst_atomic_payload {    struct drm_dp_mst_port *port;    s8 vc_start_slot;    u8 vcpi;    int time_slots;    int pbn;    bool delete : 1;    bool dsc_enabled : 1;    enum drm_dp_mst_payload_allocation payload_allocation_status;    struct list_head next;};

Members

port

The MST port assigned to this payload

vc_start_slot

The time slot that this payload starts on. Because payload start slotscan’t be determined ahead of time, the contents of this value are UNDEFINED at atomiccheck time. This shouldn’t usually matter, as the start slot should never be relevant foratomic state computations.

Since this value is determined at commit time instead of check time, this value isprotected by the MST helpers ensuring that async commits operating on the given topologynever run in parallel. In the event that a driver does need to read this value (e.g. toinform hardware of the starting timeslot for a payload), the driver may either:

If neither of the two above solutions suffice (e.g. the driver needs to read the startslot in the middle of an atomic commit without waiting for some reason), then driversshould cache this value themselves after changing payloads.

vcpi

The Virtual Channel Payload Identifier

time_slots

The number of timeslots allocated to this payload from the source DP Tx tothe immediate downstream DP Rx

pbn

The payload bandwidth for this payload

delete

Whether or not we intend to delete this payload during this atomic commit

dsc_enabled

Whether or not this payload has DSC enabled

payload_allocation_status

The allocation status of this payload

next

The list node for this payload

Description

The primary atomic state structure for a given MST payload. Stores information like currentbandwidth allocation, intended action for this payload, etc.

structdrm_dp_mst_topology_state

DisplayPort MST topology atomic state

Definition:

struct drm_dp_mst_topology_state {    struct drm_private_state base;    struct drm_dp_mst_topology_mgr *mgr;    u32 pending_crtc_mask;    struct drm_crtc_commit **commit_deps;    size_t num_commit_deps;    u32 payload_mask;    struct list_head payloads;    u8 total_avail_slots;    u8 start_slot;    fixed20_12 pbn_div;};

Members

base

Base private state for atomic

mgr

The topology manager

pending_crtc_mask

A bitmask of all CRTCs this topology state touches, drivers maymodify this to add additional dependencies if needed.

commit_deps

A list of all CRTC commits affecting this topology, this field isn’tpopulated untildrm_dp_mst_atomic_wait_for_dependencies() is called.

num_commit_deps

The number of CRTC commits incommit_deps

payload_mask

A bitmask of allocated VCPIs, used for VCPI assignments

payloads

The list of payloads being created/destroyed in this state

total_avail_slots

The total number of slots this topology can handle (63 or 64)

start_slot

The first usable time slot in this topology (1 or 0)

pbn_div

The current PBN divisor for this topology. The driver is expected to fill thisout itself.

Description

Thisstructrepresents the atomic state of the toplevel DisplayPort MST manager

structdrm_dp_mst_topology_mgr

DisplayPort MST manager

Definition:

struct drm_dp_mst_topology_mgr {    struct drm_private_obj base;    struct drm_device *dev;    const struct drm_dp_mst_topology_cbs *cbs;    int max_dpcd_transaction_bytes;    struct drm_dp_aux *aux;    int max_payloads;    int conn_base_id;    struct drm_dp_sideband_msg_rx up_req_recv;    struct drm_dp_sideband_msg_rx down_rep_recv;    struct mutex lock;    struct mutex probe_lock;    bool mst_state : 1;    bool payload_id_table_cleared : 1;    bool reset_rx_state : 1;    u8 payload_count;    u8 next_start_slot;    struct drm_dp_mst_branch *mst_primary;    u8 dpcd[DP_RECEIVER_CAP_SIZE];    u8 sink_count;    const struct drm_private_state_funcs *funcs;    struct mutex qlock;    struct list_head tx_msg_downq;    wait_queue_head_t tx_waitq;    struct work_struct work;    struct work_struct tx_work;    struct list_head destroy_port_list;    struct list_head destroy_branch_device_list;    struct mutex delayed_destroy_lock;    struct workqueue_struct *delayed_destroy_wq;    struct work_struct delayed_destroy_work;    struct list_head up_req_list;    struct mutex up_req_lock;    struct work_struct up_req_work;#if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS);    struct mutex topology_ref_history_lock;#endif;};

Members

base

Base private object for atomic

dev

device pointer for adding i2c devices etc.

cbs

callbacks for connector addition and destruction.

max_dpcd_transaction_bytes

maximum number of bytes to read/writein one go.

aux

AUX channel for the DP MST connector this topolgy mgr iscontrolling.

max_payloads

maximum number of payloads the GPU can generate.

conn_base_id

DRM connector ID this mgr is connected to. Only usedto build the MST connector path value.

up_req_recv

Message receiver state for up requests.

down_rep_recv

Message receiver state for replies to downrequests.

lock

protectsmst_state,mst_primary,dpcd, andpayload_id_table_cleared.

probe_lock

Preventswork andup_req_work, the only writers ofdrm_dp_mst_port.mstb anddrm_dp_mst_branch.ports, from racingwhile they update the topology.

mst_state

If this manager is enabled for an MST capable port. Falseif no MST sink/branch devices is connected.

payload_id_table_cleared

Whether or not we’ve cleared the payloadID table formst_primary. Protected bylock.

reset_rx_state

The down request’s reply and up request messagereceiver state must be reset, after the topology manager gotremoved. Protected bylock.

payload_count

The number of currently active payloads in hardware. This value is onlyintended to be used internally by MST helpers for payload tracking, and is only safe toread/write from the atomic commit (not check) context.

next_start_slot

The starting timeslot to use for new VC payloads. This value is usedinternally by MST helpers for payload tracking, and is only safe to read/write from theatomic commit (not check) context.

mst_primary

Pointer to the primary/first branch device.

dpcd

Cache of DPCD for primary port.

sink_count

Sink count from DEVICE_SERVICE_IRQ_VECTOR_ESI0.

funcs

Atomic helper callbacks

qlock

protectstx_msg_downq anddrm_dp_sideband_msg_tx.state

tx_msg_downq

List of pending down requests

tx_waitq

Wait to queue stall for the tx worker.

work

Probe work.

tx_work

Sideband transmit worker. This can nest within the mainwork worker for each transactionwork launches.

destroy_port_list

List of to be destroyed connectors.

destroy_branch_device_list

List of to be destroyed branchdevices.

delayed_destroy_lock

Protectsdestroy_port_list anddestroy_branch_device_list.

delayed_destroy_wq

Workqueue used for delayed_destroy_work items.A dedicated WQ makes it possible to drain any requeued work itemson it.

delayed_destroy_work

Work item to destroy MST port and branchdevices, needed to avoid locking inversion.

up_req_list

List of pending up requests from the topology thatneed to be processed, in chronological order.

up_req_lock

Protectsup_req_list

up_req_work

Work item to process up requests received from thetopology. Needed to avoid blocking hotplug handling and sidebandtransmissions.

topology_ref_history_lock

protectsdrm_dp_mst_port.topology_ref_history anddrm_dp_mst_branch.topology_ref_history.

Description

Thisstructrepresents the toplevel displayport MST topology manager.There should be one instance of this for every MST capable DP connectoron the GPU.

enumdrm_dp_mst_mode

sink’s MST mode capability

Constants

DRM_DP_SST

The sink does not support MST nor single stream sidebandmessaging.

DRM_DP_MST

Sink supports MST, more than one stream and singlestream sideband messaging.

DRM_DP_SST_SIDEBAND_MSG

Sink supports only one stream and singlestream sideband messaging.

bool__drm_dp_mst_state_iter_get(structdrm_atomic_state*state,structdrm_dp_mst_topology_mgr**mgr,structdrm_dp_mst_topology_state**old_state,structdrm_dp_mst_topology_state**new_state,inti)

private atomic state iterator function for macro-internal use

Parameters

structdrm_atomic_state*state

structdrm_atomic_state pointer

structdrm_dp_mst_topology_mgr**mgr

pointer to thestructdrm_dp_mst_topology_mgr iteration cursor

structdrm_dp_mst_topology_state**old_state

optional pointer to the oldstructdrm_dp_mst_topology_stateiteration cursor

structdrm_dp_mst_topology_state**new_state

optional pointer to the newstructdrm_dp_mst_topology_stateiteration cursor

inti

int iteration cursor, for macro-internal use

Description

Used byfor_each_oldnew_mst_mgr_in_state(),for_each_old_mst_mgr_in_state(), andfor_each_new_mst_mgr_in_state(). Don’tcall this directly.

Return

True if the currentstructdrm_private_obj is astructdrm_dp_mst_topology_mgr, false otherwise.

for_each_oldnew_mst_mgr_in_state

for_each_oldnew_mst_mgr_in_state(__state,mgr,old_state,new_state,__i)

iterate over all DP MST topology managers in an atomic update

Parameters

__state

structdrm_atomic_state pointer

mgr

structdrm_dp_mst_topology_mgr iteration cursor

old_state

structdrm_dp_mst_topology_state iteration cursor for the oldstate

new_state

structdrm_dp_mst_topology_state iteration cursor for the newstate

__i

int iteration cursor, for macro-internal use

Description

This iterates over all DRM DP MST topology managers in an atomic update,tracking both old and new state. This is useful in places where the statedelta needs to be considered, for example in atomic check functions.

for_each_old_mst_mgr_in_state

for_each_old_mst_mgr_in_state(__state,mgr,old_state,__i)

iterate over all DP MST topology managers in an atomic update

Parameters

__state

structdrm_atomic_state pointer

mgr

structdrm_dp_mst_topology_mgr iteration cursor

old_state

structdrm_dp_mst_topology_state iteration cursor for the oldstate

__i

int iteration cursor, for macro-internal use

Description

This iterates over all DRM DP MST topology managers in an atomic update,tracking only the old state. This is useful in disable functions, where weneed the old state the hardware is still in.

for_each_new_mst_mgr_in_state

for_each_new_mst_mgr_in_state(__state,mgr,new_state,__i)

iterate over all DP MST topology managers in an atomic update

Parameters

__state

structdrm_atomic_state pointer

mgr

structdrm_dp_mst_topology_mgr iteration cursor

new_state

structdrm_dp_mst_topology_state iteration cursor for the newstate

__i

int iteration cursor, for macro-internal use

Description

This iterates over all DRM DP MST topology managers in an atomic update,tracking only the new state. This is useful in enable functions, where weneed the new state the hardware should be in when the atomic commitoperation has completed.

voiddrm_dp_mst_get_port_malloc(structdrm_dp_mst_port*port)

Increment the malloc refcount of an MST port

Parameters

structdrm_dp_mst_port*port

Thestructdrm_dp_mst_port to increment the malloc refcount of

Description

Incrementsdrm_dp_mst_port.malloc_kref. Whendrm_dp_mst_port.malloc_krefreaches 0, the memory allocation forport will be released andport mayno longer be used.

Becauseport could potentially be freed at any time by the DP MST helpersifdrm_dp_mst_port.malloc_kref reaches 0, including during a call to thisfunction, drivers that which to make use ofstructdrm_dp_mst_port shouldensure that they grab at least one main malloc reference to their MST portsindrm_dp_mst_topology_cbs.add_connector. This callback is called beforethere is any chance fordrm_dp_mst_port.malloc_kref to reach 0.

See also:drm_dp_mst_put_port_malloc()

voiddrm_dp_mst_put_port_malloc(structdrm_dp_mst_port*port)

Decrement the malloc refcount of an MST port

Parameters

structdrm_dp_mst_port*port

Thestructdrm_dp_mst_port to decrement the malloc refcount of

Description

Decrementsdrm_dp_mst_port.malloc_kref. Whendrm_dp_mst_port.malloc_krefreaches 0, the memory allocation forport will be released andport mayno longer be used.

See also:drm_dp_mst_get_port_malloc()

intdrm_dp_mst_connector_late_register(structdrm_connector*connector,structdrm_dp_mst_port*port)

Late MST connector registration

Parameters

structdrm_connector*connector

The MST connector

structdrm_dp_mst_port*port

The MST port for this connector

Description

Helper to register the remote aux device for this MST port. Drivers shouldcall this from their mst connector’s late_register hook to enable MST auxdevices.

Return

0 on success, negative error code on failure.

voiddrm_dp_mst_connector_early_unregister(structdrm_connector*connector,structdrm_dp_mst_port*port)

Early MST connector unregistration

Parameters

structdrm_connector*connector

The MST connector

structdrm_dp_mst_port*port

The MST port for this connector

Description

Helper to unregister the remote aux device for this MST port, registered bydrm_dp_mst_connector_late_register(). Drivers should call this from their mstconnector’s early_unregister hook.

intdrm_dp_add_payload_part1(structdrm_dp_mst_topology_mgr*mgr,structdrm_dp_mst_topology_state*mst_state,structdrm_dp_mst_atomic_payload*payload)

Execute payload update part 1

Parameters

structdrm_dp_mst_topology_mgr*mgr

Manager to use.

structdrm_dp_mst_topology_state*mst_state

The MST atomic state

structdrm_dp_mst_atomic_payload*payload

The payload to write

Description

Determines the starting time slot for the given payload, and programs the VCPI for this payloadinto the DPCD of DPRX. After calling this, the driver should generate ACT and payload packets.

Return

0 on success, error code on failure.

voiddrm_dp_remove_payload_part1(structdrm_dp_mst_topology_mgr*mgr,structdrm_dp_mst_topology_state*mst_state,structdrm_dp_mst_atomic_payload*payload)

Remove an MST payload along the virtual channel

Parameters

structdrm_dp_mst_topology_mgr*mgr

Manager to use.

structdrm_dp_mst_topology_state*mst_state

The MST atomic state

structdrm_dp_mst_atomic_payload*payload

The payload to remove

Description

Removes a payload along the virtual channel if it was successfully allocated.After calling this, the driver should set HW to generate ACT and then switch to newpayload allocation state.

voiddrm_dp_remove_payload_part2(structdrm_dp_mst_topology_mgr*mgr,structdrm_dp_mst_topology_state*mst_state,conststructdrm_dp_mst_atomic_payload*old_payload,structdrm_dp_mst_atomic_payload*new_payload)

Remove an MST payload locally

Parameters

structdrm_dp_mst_topology_mgr*mgr

Manager to use.

structdrm_dp_mst_topology_state*mst_state

The MST atomic state

conststructdrm_dp_mst_atomic_payload*old_payload

The payload with its old state

structdrm_dp_mst_atomic_payload*new_payload

The payload with its latest state

Description

Updates the starting time slots of all other payloads which would have been shifted towardsthe start of the payload ID table as a result of removing a payload. Driver should call thisfunction whenever it removes a payload in its HW. It’s independent to the result of payloadallocation/deallocation at branch devices along the virtual channel.

intdrm_dp_add_payload_part2(structdrm_dp_mst_topology_mgr*mgr,structdrm_dp_mst_atomic_payload*payload)

Execute payload update part 2

Parameters

structdrm_dp_mst_topology_mgr*mgr

Manager to use.

structdrm_dp_mst_atomic_payload*payload

The payload to update

Description

Ifpayload was successfully assigned a starting time slot bydrm_dp_add_payload_part1(), thisfunction will send the sideband messages to finish allocating this payload.

Return

0 on success, negative error code on failure.

fixed20_12drm_dp_get_vc_payload_bw(intlink_rate,intlink_lane_count)

get the VC payload BW for an MTP link

Parameters

intlink_rate

link rate in 10kbits/s units

intlink_lane_count

lane count

Description

Calculate the total bandwidth of a MultiStream Transport link. The returnedvalue is in units of PBNs/(timeslots/1 MTP). This value can be used toconvert the number of PBNs required for a given stream to the number oftimeslots this stream requires in each MTP.

Returns the BW / timeslot value in 20.12 fixed point format.

enumdrm_dp_mst_modedrm_dp_read_mst_cap(structdrm_dp_aux*aux,constu8dpcd[DP_RECEIVER_CAP_SIZE])

Read the sink’s MST mode capability

Parameters

structdrm_dp_aux*aux

The DP AUX channel to use

constu8dpcd[DP_RECEIVER_CAP_SIZE]

A cached copy of the DPCD capabilities for this sink

Return

enumdrm_dp_mst_mode to indicate MST mode capability

intdrm_dp_mst_topology_mgr_set_mst(structdrm_dp_mst_topology_mgr*mgr,boolmst_state)

Set the MST state for a topology manager

Parameters

structdrm_dp_mst_topology_mgr*mgr

manager to set state for

boolmst_state

true to enable MST on this connector - false to disable.

Description

This is called by the driver when it detects an MST capable device pluggedinto a DP MST capable port, or when a DP MST capable device is unplugged.

voiddrm_dp_mst_topology_queue_probe(structdrm_dp_mst_topology_mgr*mgr)

Queue a topology probe

Parameters

structdrm_dp_mst_topology_mgr*mgr

manager to probe

Description

Queue a work to probe the MST topology. Driver’s should call this only tosync the topology’s HW->SW state after the MST link’s parameters havechanged in a way the state could’ve become out-of-sync. This is the casefor instance when the link rate between the source and first downstreambranch device has switched between UHBR and non-UHBR rates. Except of thosecases - for instance when a sink gets plugged/unplugged to a port - the SWstate will get updated automatically via MST UP message notifications.

voiddrm_dp_mst_topology_mgr_suspend(structdrm_dp_mst_topology_mgr*mgr)

suspend the MST manager

Parameters

structdrm_dp_mst_topology_mgr*mgr

manager to suspend

Description

This function tells the MST device that we can’t handle UP messagesanymore. This should stop it from sending any since we are suspended.

intdrm_dp_mst_topology_mgr_resume(structdrm_dp_mst_topology_mgr*mgr,boolsync)

resume the MST manager

Parameters

structdrm_dp_mst_topology_mgr*mgr

manager to resume

boolsync

whether or not to perform topology reprobing synchronously

Description

This will fetch DPCD and see if the device is still there,if it is, it will rewrite the MSTM control bits, and return.

If the device fails this returns -1, and the driver should doa full MST reprobe, in case we were undocked.

During system resume (where it is assumed that the driver will be callingdrm_atomic_helper_resume()) this function should be called beforehand withsync set to true. In contexts like runtime resume where the driver is notexpected to be callingdrm_atomic_helper_resume(), this function should becalled withsync set to false in order to avoid deadlocking.

Return

-1 if the MST topology was removed while we were suspended, 0otherwise.

intdrm_dp_mst_hpd_irq_handle_event(structdrm_dp_mst_topology_mgr*mgr,constu8*esi,u8*ack,bool*handled)

MST hotplug IRQ handle MST event

Parameters

structdrm_dp_mst_topology_mgr*mgr

manager to notify irq for.

constu8*esi

4 bytes from SINK_COUNT_ESI

u8*ack

4 bytes used to ack events starting from SINK_COUNT_ESI

bool*handled

whether the hpd interrupt was consumed or not

Description

This should be called from the driver when it detects a HPD IRQ,along with the value of the DEVICE_SERVICE_IRQ_VECTOR_ESI0. Thetopology manager will process the sideband messages receivedas indicated in the DEVICE_SERVICE_IRQ_VECTOR_ESI0 and set thecorresponding flags that Driver has to ack the DP receiver later.

Note that driver shall also calldrm_dp_mst_hpd_irq_send_new_request() if the ‘handled’ is setafter calling this function, to try to kick off a new request inthe queue if the previous message transaction is completed.

See also:drm_dp_mst_hpd_irq_send_new_request()

voiddrm_dp_mst_hpd_irq_send_new_request(structdrm_dp_mst_topology_mgr*mgr)

MST hotplug IRQ kick off new request

Parameters

structdrm_dp_mst_topology_mgr*mgr

manager to notify irq for.

Description

This should be called from the driver when mst irq event is handledand acked. Note that new down request should only be sent whenprevious message transaction is completed. Source is not supposed to generateinterleaved message transactions.

intdrm_dp_mst_detect_port(structdrm_connector*connector,structdrm_modeset_acquire_ctx*ctx,structdrm_dp_mst_topology_mgr*mgr,structdrm_dp_mst_port*port)

get connection status for an MST port

Parameters

structdrm_connector*connector

DRM connector for this port

structdrm_modeset_acquire_ctx*ctx

The acquisition context to use for grabbing locks

structdrm_dp_mst_topology_mgr*mgr

manager for this port

structdrm_dp_mst_port*port

pointer to a port

Description

This returns the current connection state for a port.

conststructdrm_edid*drm_dp_mst_edid_read(structdrm_connector*connector,structdrm_dp_mst_topology_mgr*mgr,structdrm_dp_mst_port*port)

get EDID for an MST port

Parameters

structdrm_connector*connector

toplevel connector to get EDID for

structdrm_dp_mst_topology_mgr*mgr

manager for this port

structdrm_dp_mst_port*port

unverified pointer to a port.

Description

This returns an EDID for the port connected to a connector,It validates the pointer still exists so the caller doesn’t require areference.

structedid*drm_dp_mst_get_edid(structdrm_connector*connector,structdrm_dp_mst_topology_mgr*mgr,structdrm_dp_mst_port*port)

get EDID for an MST port

Parameters

structdrm_connector*connector

toplevel connector to get EDID for

structdrm_dp_mst_topology_mgr*mgr

manager for this port

structdrm_dp_mst_port*port

unverified pointer to a port.

Description

This function is deprecated; please usedrm_dp_mst_edid_read() instead.

This returns an EDID for the port connected to a connector,It validates the pointer still exists so the caller doesn’t require areference.

intdrm_dp_atomic_find_time_slots(structdrm_atomic_state*state,structdrm_dp_mst_topology_mgr*mgr,structdrm_dp_mst_port*port,intpbn)

Find and add time slots to the state

Parameters

structdrm_atomic_state*state

global atomic state

structdrm_dp_mst_topology_mgr*mgr

MST topology manager for the port

structdrm_dp_mst_port*port

port to find time slots for

intpbn

bandwidth required for the mode in PBN

Description

Allocates time slots toport, replacing any previous time slot allocations it mayhave had. Any atomic drivers which support MST must call this function intheirdrm_encoder_helper_funcs.atomic_check() callback unconditionally tochange the current time slot allocation for the new state, and ensure the MSTatomic state is added whenever the state of payloads in the topology changes.

Allocations set by this function are not checked against the bandwidthrestraints ofmgr until the driver callsdrm_dp_mst_atomic_check().

Additionally, it is OK to call this function multiple times on the sameport as needed. It is not OK however, to call this function anddrm_dp_atomic_release_time_slots() in the same atomic check phase.

See also:drm_dp_atomic_release_time_slots()drm_dp_mst_atomic_check()

Return

Total slots in the atomic state assigned for this port, or a negative errorcode if the port no longer exists

intdrm_dp_atomic_release_time_slots(structdrm_atomic_state*state,structdrm_dp_mst_topology_mgr*mgr,structdrm_dp_mst_port*port)

Release allocated time slots

Parameters

structdrm_atomic_state*state

global atomic state

structdrm_dp_mst_topology_mgr*mgr

MST topology manager for the port

structdrm_dp_mst_port*port

The port to release the time slots from

Description

Releases any time slots that have been allocated to a port in the atomicstate. Any atomic drivers which support MST must call this functionunconditionally in theirdrm_connector_helper_funcs.atomic_check() callback.This helper will check whether time slots would be released by the new state andrespond accordingly, along with ensuring the MST state is always added to theatomic state whenever a new state would modify the state of payloads on thetopology.

It is OK to call this even ifport has been removed from the system.Additionally, it is OK to call this function multiple times on the sameport as needed. It is not OK however, to call this function anddrm_dp_atomic_find_time_slots() on the sameport in a single atomic checkphase.

See also:drm_dp_atomic_find_time_slots()drm_dp_mst_atomic_check()

Return

0 on success, negative error code otherwise

intdrm_dp_mst_atomic_setup_commit(structdrm_atomic_state*state)

setup_commit hook for MST helpers

Parameters

structdrm_atomic_state*state

global atomic state

Description

This function saves all of thedrm_crtc_commit structs in an atomic state that touch any CRTCscurrently assigned to an MST topology. Drivers must call this hook from theirdrm_mode_config_helper_funcs.atomic_commit_setup hook.

Return

0 if all CRTC commits were retrieved successfully, negative error code otherwise

voiddrm_dp_mst_atomic_wait_for_dependencies(structdrm_atomic_state*state)

Wait for all pending commits on MST topologies, prepare new MST state for commit

Parameters

structdrm_atomic_state*state

global atomic state

Description

Goes through any MST topologies in this atomic state, and waits for any pending commits whichtouched CRTCs that were/are on an MST topology to be programmed to hardware and flipped to beforereturning. This is to prevent multiple non-blocking commits affecting an MST topology from racingwith eachother by forcing them to be executed sequentially in situations where the only resourcesthe modeset objects in these commits share are an MST topology.

This function also prepares the new MST state for commit by performing some state preparationwhich can’t be done until this point, such as reading back the final VC start slots (which aredetermined at commit-time) from the previous state.

All MST drivers must call this function after callingdrm_atomic_helper_wait_for_dependencies(),or whatever their equivalent of that is.

intdrm_dp_mst_root_conn_atomic_check(structdrm_connector_state*new_conn_state,structdrm_dp_mst_topology_mgr*mgr)

Serialize CRTC commits on MST-capable connectors operating in SST mode

Parameters

structdrm_connector_state*new_conn_state

The new connector state of thedrm_connector

structdrm_dp_mst_topology_mgr*mgr

The MST topology manager for thedrm_connector

Description

Since MST uses fakedrm_encoder structs, the generic atomic modesetting code isn’t able toserialize non-blocking commits happening on the real DP connector of an MST topology switchinginto/away from MST mode - as the CRTC on the real DP connector and the CRTCs on the connector’sMST topology will never share the samedrm_encoder.

This function takes care of this serialization issue, by checking a root MST connector’s atomicstate to determine if it is about to have a modeset - and then pulling in the MST topology stateif so, along with adding any relevant CRTCs todrm_dp_mst_topology_state.pending_crtc_mask.

Drivers implementing MST must call this function from thedrm_connector_helper_funcs.atomic_check hook of any physical DPdrm_connector capable ofdriving MST sinks.

Return

0 on success, negative error code otherwise

voiddrm_dp_mst_update_slots(structdrm_dp_mst_topology_state*mst_state,uint8_tlink_encoding_cap)

updates the slot info depending on the DP ecoding format

Parameters

structdrm_dp_mst_topology_state*mst_state

mst_state to update

uint8_tlink_encoding_cap

the ecoding format on the link

intdrm_dp_check_act_status(structdrm_dp_mst_topology_mgr*mgr)

Polls for ACT handled status.

Parameters

structdrm_dp_mst_topology_mgr*mgr

manager to use

Description

Tries waiting for the MST hub to finish updating it’s payload table bypolling for the ACT handled bit for up to 3 seconds (yes-some hubs reallytake that long).

Return

0 if the ACT was handled in time, negative error code on failure.

intdrm_dp_calc_pbn_mode(intclock,intbpp)

Calculate the PBN for a mode.

Parameters

intclock

dot clock

intbpp

bpp as .4 binary fixed point

Description

This uses the formula in the spec to calculate the PBN value for a mode.

voiddrm_dp_mst_dump_topology(structseq_file*m,structdrm_dp_mst_topology_mgr*mgr)

dump topology to seq file.

Parameters

structseq_file*m

seq_file to dump output to

structdrm_dp_mst_topology_mgr*mgr

manager to dump current topology for.

Description

helper to dump MST topology to a seq file for debugfs.

booldrm_dp_mst_port_downstream_of_parent(structdrm_dp_mst_topology_mgr*mgr,structdrm_dp_mst_port*port,structdrm_dp_mst_port*parent)

check if a port is downstream of a parent port

Parameters

structdrm_dp_mst_topology_mgr*mgr

MST topology manager

structdrm_dp_mst_port*port

the port being looked up

structdrm_dp_mst_port*parent

the parent port

Description

The function returnstrue ifport is downstream ofparent. Ifparent isNULL - denoting the root port - the function returnstrue ifport is inmgr’s topology.

intdrm_dp_mst_add_affected_dsc_crtcs(structdrm_atomic_state*state,structdrm_dp_mst_topology_mgr*mgr)

Parameters

structdrm_atomic_state*state

Pointer to the newstructdrm_dp_mst_topology_state

structdrm_dp_mst_topology_mgr*mgr

MST topology manager

Description

Whenever there is a change in mst topologyDSC configuration would have to be recalculatedtherefore we need to trigger modeset on all affectedCRTCs in that topology

See also:drm_dp_mst_atomic_enable_dsc()

intdrm_dp_mst_atomic_enable_dsc(structdrm_atomic_state*state,structdrm_dp_mst_port*port,intpbn,boolenable)

Set DSC Enable Flag to On/Off

Parameters

structdrm_atomic_state*state

Pointer to the new drm_atomic_state

structdrm_dp_mst_port*port

Pointer to the affected MST Port

intpbn

Newly recalculated bw required for link with DSC enabled

boolenable

Boolean flag to enable or disable DSC on the port

Description

This function enables DSC on the given Portby recalculating its vcpi from pbn providedand sets dsc_enable flag to keep track of whichports have DSC enabled

intdrm_dp_mst_atomic_check_mgr(structdrm_atomic_state*state,structdrm_dp_mst_topology_mgr*mgr,structdrm_dp_mst_topology_state*mst_state,structdrm_dp_mst_port**failing_port)

Check the atomic state of an MST topology manager

Parameters

structdrm_atomic_state*state

The global atomic state

structdrm_dp_mst_topology_mgr*mgr

Manager to check

structdrm_dp_mst_topology_state*mst_state

The MST atomic state formgr

structdrm_dp_mst_port**failing_port

Returns the port with a BW limitation

Description

Checks the given MST manager’s topology state for an atomic update to ensurethat it’s valid. This includes checking whether there’s enough bandwidth tosupport the new timeslot allocations in the atomic update.

Any atomic drivers supporting DP MST must make sure to call this orthedrm_dp_mst_atomic_check() function after checking the rest of their statein theirdrm_mode_config_funcs.atomic_check() callback.

See also:drm_dp_mst_atomic_check()drm_dp_atomic_find_time_slots()drm_dp_atomic_release_time_slots()

  • The non-root port where a BW limit check failedwith all the ports downstream offailing_port passingthe BW limit check.The returned port pointer is valid until at leastone payload downstream of it exists.

  • NULL if the BW limit check failed at the root portwith all the ports downstream of the root port passingthe BW limit check.

  • -EINVAL, if the new state is invalid, because the root port hastoo many payloads.

Return

  • 0 if the new state is valid

  • -ENOSPC, if the new state is invalid, because of BW limitation

    failing_port is set to:

intdrm_dp_mst_atomic_check(structdrm_atomic_state*state)

Check that the new state of an MST topology in an atomic update is valid

Parameters

structdrm_atomic_state*state

Pointer to the newstructdrm_dp_mst_topology_state

Description

Checks the given topology state for an atomic update to ensure that it’svalid, callingdrm_dp_mst_atomic_check_mgr() for all MST manager in theatomic state. This includes checking whether there’s enough bandwidth tosupport the new timeslot allocations in the atomic update.

Any atomic drivers supporting DP MST must make sure to call this afterchecking the rest of their state in theirdrm_mode_config_funcs.atomic_check() callback.

See also:drm_dp_mst_atomic_check_mgr()drm_dp_atomic_find_time_slots()drm_dp_atomic_release_time_slots()

Return

0 if the new state is valid, negative error code otherwise.

structdrm_dp_mst_topology_state*drm_atomic_get_mst_topology_state(structdrm_atomic_state*state,structdrm_dp_mst_topology_mgr*mgr)

get MST topology state

Parameters

structdrm_atomic_state*state

global atomic state

structdrm_dp_mst_topology_mgr*mgr

MST topology manager, also the private object in this case

Description

This function wrapsdrm_atomic_get_priv_obj_state() passing in the MST atomicstate vtable so that the private object state returned is that of a MSTtopology object.

Return

The MST topology state or error pointer.

structdrm_dp_mst_topology_state*drm_atomic_get_old_mst_topology_state(structdrm_atomic_state*state,structdrm_dp_mst_topology_mgr*mgr)

get old MST topology state in atomic state, if any

Parameters

structdrm_atomic_state*state

global atomic state

structdrm_dp_mst_topology_mgr*mgr

MST topology manager, also the private object in this case

Description

This function wrapsdrm_atomic_get_old_private_obj_state() passing in the MST atomicstate vtable so that the private object state returned is that of a MSTtopology object.

Return

The old MST topology state, or NULL if there’s no topology state for this MST mgrin the global atomic state

structdrm_dp_mst_topology_state*drm_atomic_get_new_mst_topology_state(structdrm_atomic_state*state,structdrm_dp_mst_topology_mgr*mgr)

get new MST topology state in atomic state, if any

Parameters

structdrm_atomic_state*state

global atomic state

structdrm_dp_mst_topology_mgr*mgr

MST topology manager, also the private object in this case

Description

This function wrapsdrm_atomic_get_new_private_obj_state() passing in the MST atomicstate vtable so that the private object state returned is that of a MSTtopology object.

Return

The new MST topology state, or NULL if there’s no topology state for this MST mgrin the global atomic state

intdrm_dp_mst_topology_mgr_init(structdrm_dp_mst_topology_mgr*mgr,structdrm_device*dev,structdrm_dp_aux*aux,intmax_dpcd_transaction_bytes,intmax_payloads,intconn_base_id)

initialise a topology manager

Parameters

structdrm_dp_mst_topology_mgr*mgr

managerstructto initialise

structdrm_device*dev

device providing this structure - for i2c addition.

structdrm_dp_aux*aux

DP helper aux channel to talk to this device

intmax_dpcd_transaction_bytes

hw specific DPCD transaction limit

intmax_payloads

maximum number of payloads this GPU can source

intconn_base_id

the connector object ID the MST device is connected to.

Description

Return 0 for success, or negative error code on failure

voiddrm_dp_mst_topology_mgr_destroy(structdrm_dp_mst_topology_mgr*mgr)

destroy topology manager.

Parameters

structdrm_dp_mst_topology_mgr*mgr

manager to destroy

structdrm_dp_aux*drm_dp_mst_aux_for_parent(structdrm_dp_mst_port*port)

Get the AUX device for an MST port’s parent

Parameters

structdrm_dp_mst_port*port

MST port whose parent’s AUX device is returned

Description

Return the AUX device forport’s parent or NULL if port’s parent is theroot port.

structdrm_dp_aux*drm_dp_mst_dsc_aux_for_port(structdrm_dp_mst_port*port)

Find the correct aux for DSC

Parameters

structdrm_dp_mst_port*port

The port to check. A leaf of the MST tree with an attached display.

Description

Depending on the situation, DSC may be enabled via the endpoint aux,the immediately upstream aux, or the connector’s physical aux.

This is both the correct aux to read DSC_CAPABILITY and thecorrect aux to write DSC_ENABLED.

This operation can be expensive (up to four aux reads), sothe caller should cache the return.

Return

NULL if DSC cannot be enabled on this port, otherwise the aux device

Topology Lifetime Internals

These functions aren’t exported to drivers, but are documented here to help makethe MST topology helpers easier to understand

voiddrm_dp_mst_get_mstb_malloc(structdrm_dp_mst_branch*mstb)

Increment the malloc refcount of a branch device

Parameters

structdrm_dp_mst_branch*mstb

Thestructdrm_dp_mst_branch to increment the malloc refcount of

Description

Incrementsdrm_dp_mst_branch.malloc_kref. Whendrm_dp_mst_branch.malloc_kref reaches 0, the memory allocation formstbwill be released andmstb may no longer be used.

See also:drm_dp_mst_put_mstb_malloc()

voiddrm_dp_mst_put_mstb_malloc(structdrm_dp_mst_branch*mstb)

Decrement the malloc refcount of a branch device

Parameters

structdrm_dp_mst_branch*mstb

Thestructdrm_dp_mst_branch to decrement the malloc refcount of

Description

Decrementsdrm_dp_mst_branch.malloc_kref. Whendrm_dp_mst_branch.malloc_kref reaches 0, the memory allocation formstbwill be released andmstb may no longer be used.

See also:drm_dp_mst_get_mstb_malloc()

intdrm_dp_mst_topology_try_get_mstb(structdrm_dp_mst_branch*mstb)

Increment the topology refcount of a branch device unless it’s zero

Parameters

structdrm_dp_mst_branch*mstb

structdrm_dp_mst_branch to increment the topology refcount of

Description

Attempts to grab a topology reference tomstb, if it hasn’t yet beenremoved from the topology (e.g.drm_dp_mst_branch.topology_kref hasreached 0). Holding a topology reference implies that a malloc referencewill be held tomstb as long as the user holds the topology reference.

Care should be taken to ensure that the user has at least one mallocreference tomstb. If you already have a topology reference tomstb, youshould usedrm_dp_mst_topology_get_mstb() instead.

See also:drm_dp_mst_topology_get_mstb()drm_dp_mst_topology_put_mstb()

Return

  • 1: A topology reference was grabbed successfully

  • 0:port is no longer in the topology, no reference was grabbed

voiddrm_dp_mst_topology_get_mstb(structdrm_dp_mst_branch*mstb)

Increment the topology refcount of a branch device

Parameters

structdrm_dp_mst_branch*mstb

Thestructdrm_dp_mst_branch to increment the topology refcount of

Description

Incrementsdrm_dp_mst_branch.topology_refcount without checking whether ornot it’s already reached 0. This is only valid to use in scenarios whereyou are already guaranteed to have at least one active topology referencetomstb. Otherwise,drm_dp_mst_topology_try_get_mstb() must be used.

See also:drm_dp_mst_topology_try_get_mstb()drm_dp_mst_topology_put_mstb()

voiddrm_dp_mst_topology_put_mstb(structdrm_dp_mst_branch*mstb)

release a topology reference to a branch device

Parameters

structdrm_dp_mst_branch*mstb

Thestructdrm_dp_mst_branch to release the topology reference from

Description

Releases a topology reference frommstb by decrementingdrm_dp_mst_branch.topology_kref.

See also:drm_dp_mst_topology_try_get_mstb()drm_dp_mst_topology_get_mstb()

intdrm_dp_mst_topology_try_get_port(structdrm_dp_mst_port*port)

Increment the topology refcount of a port unless it’s zero

Parameters

structdrm_dp_mst_port*port

structdrm_dp_mst_port to increment the topology refcount of

Description

Attempts to grab a topology reference toport, if it hasn’t yet beenremoved from the topology (e.g.drm_dp_mst_port.topology_kref has reached0). Holding a topology reference implies that a malloc reference will beheld toport as long as the user holds the topology reference.

Care should be taken to ensure that the user has at least one mallocreference toport. If you already have a topology reference toport, youshould usedrm_dp_mst_topology_get_port() instead.

See also:drm_dp_mst_topology_get_port()drm_dp_mst_topology_put_port()

Return

  • 1: A topology reference was grabbed successfully

  • 0:port is no longer in the topology, no reference was grabbed

voiddrm_dp_mst_topology_get_port(structdrm_dp_mst_port*port)

Increment the topology refcount of a port

Parameters

structdrm_dp_mst_port*port

Thestructdrm_dp_mst_port to increment the topology refcount of

Description

Incrementsdrm_dp_mst_port.topology_refcount without checking whether ornot it’s already reached 0. This is only valid to use in scenarios whereyou are already guaranteed to have at least one active topology referencetoport. Otherwise,drm_dp_mst_topology_try_get_port() must be used.

See also:drm_dp_mst_topology_try_get_port()drm_dp_mst_topology_put_port()

voiddrm_dp_mst_topology_put_port(structdrm_dp_mst_port*port)

release a topology reference to a port

Parameters

structdrm_dp_mst_port*port

Thestructdrm_dp_mst_port to release the topology reference from

Description

Releases a topology reference fromport by decrementingdrm_dp_mst_port.topology_kref.

See also:drm_dp_mst_topology_try_get_port()drm_dp_mst_topology_get_port()

MIPI DBI Helper Functions Reference

This library provides helpers for MIPI Display Bus Interface (DBI)compatible display controllers.

Many controllers for tiny lcd displays are MIPI compliant and can use thislibrary. If a controller uses registers 0x2A and 0x2B to set the area toupdate and uses register 0x2C to write to frame memory, it is most likelyMIPI compliant.

Only MIPI Type 1 displays are supported since a full frame memory is needed.

There are 3 MIPI DBI implementation types:

  1. Motorola 6800 type parallel bus

  2. Intel 8080 type parallel bus

  3. SPI type with 3 options:

    1. 9-bit with the Data/Command signal as the ninth bit

    2. Same as above except it’s sent as 16 bits

    3. 8-bit with the Data/Command signal as a separate D/CX pin

Currently mipi_dbi only supports Type C options 1 and 3 withmipi_dbi_spi_init().

structmipi_dbi

MIPI DBI interface

Definition:

struct mipi_dbi {    struct mutex cmdlock;    int (*command)(struct mipi_dbi *dbi, u8 *cmd, u8 *param, size_t num);    const u8 *read_commands;    bool swap_bytes;    struct gpio_desc *reset;    struct spi_device *spi;    unsigned int write_memory_bpw;    struct gpio_desc *dc;    void *tx_buf9;    size_t tx_buf9_len;};

Members

cmdlock

Command lock

command

Bus specific callback executing commands.

read_commands
Array of read commands terminated by a zero entry.

Reading is disabled if this is NULL.

swap_bytes

Swap bytes in buffer before transfer

reset

Optional reset gpio

spi

SPI device

write_memory_bpw

Bits per word used on a MIPI_DCS_WRITE_MEMORY_START transfer

dc

Optional D/C gpio.

tx_buf9

Buffer used for Option 1 9-bit conversion

tx_buf9_len

Size of tx_buf9.

structmipi_dbi_dev

MIPI DBI device

Definition:

struct mipi_dbi_dev {    struct drm_device drm;    struct drm_simple_display_pipe pipe;    struct drm_connector connector;    struct drm_display_mode mode;    u32 pixel_format;    u16 *tx_buf;    unsigned int rotation;    unsigned int left_offset;    unsigned int top_offset;    struct backlight_device *backlight;    struct regulator *regulator;    struct regulator *io_regulator;    struct mipi_dbi dbi;    void *driver_private;};

Members

drm

DRM device

pipe

Display pipe structure

connector

Connector

mode

Fixed display mode

pixel_format

Native pixel format (DRM_FORMAT_*)

tx_buf

Buffer used for transfer (copy clip rect area)

rotation

initial rotation in degrees Counter Clock Wise

left_offset
Horizontal offset of the display relative to the

controller’s driver array

top_offset
Vertical offset of the display relative to the

controller’s driver array

backlight

backlight device (optional)

regulator

power regulator (Vdd) (optional)

io_regulator

I/O power regulator (Vddi) (optional)

dbi

MIPI DBI interface

driver_private
Driver private data.

Necessary for drivers with private data sincedevm_drm_dev_alloc()can’t allocate structures that embed a structure which then againembeds drm_device.

mipi_dbi_command

mipi_dbi_command(dbi,cmd,seq...)

MIPI DCS command with optional parameter(s)

Parameters

dbi

MIPI DBI structure

cmd

Command

seq...

Optional parameter(s)

Description

Send MIPI DCS command to the controller. Usemipi_dbi_command_read() forget/read.

Return

Zero on success, negative error code on failure.

DRM_MIPI_DBI_SIMPLE_DISPLAY_PIPE_FUNCS

DRM_MIPI_DBI_SIMPLE_DISPLAY_PIPE_FUNCS(enable_)

Initializesstructdrm_simple_display_pipe_funcs for MIPI-DBI devices

Parameters

enable_

Enable-callback implementation

Description

This macro initializesstructdrm_simple_display_pipe_funcs with defaultvalues for MIPI-DBI-based devices. The only callback that depends on thehardware isenable, for which the driver has to provide an implementation.MIPI-based drivers are encouraged to use this macro for initialization.

intmipi_dbi_command_read(structmipi_dbi*dbi,u8cmd,u8*val)

MIPI DCS read command

Parameters

structmipi_dbi*dbi

MIPI DBI structure

u8cmd

Command

u8*val

Value read

Description

Send MIPI DCS read command to the controller.

Return

Zero on success, negative error code on failure.

intmipi_dbi_command_buf(structmipi_dbi*dbi,u8cmd,u8*data,size_tlen)

MIPI DCS command with parameter(s) in an array

Parameters

structmipi_dbi*dbi

MIPI DBI structure

u8cmd

Command

u8*data

Parameter buffer

size_tlen

Buffer length

Return

Zero on success, negative error code on failure.

intmipi_dbi_buf_copy(void*dst,structiosys_map*src,structdrm_framebuffer*fb,structdrm_rect*clip,boolswap,structdrm_format_conv_state*fmtcnv_state)

Copy a framebuffer, transforming it if necessary

Parameters

void*dst

The destination buffer

structiosys_map*src

The source buffer

structdrm_framebuffer*fb

The source framebuffer

structdrm_rect*clip

Clipping rectangle of the area to be copied

boolswap

When true, swap MSB/LSB of 16-bit values

structdrm_format_conv_state*fmtcnv_state

Format-conversion state

Return

Zero on success, negative error code on failure.

enumdrm_mode_statusmipi_dbi_pipe_mode_valid(structdrm_simple_display_pipe*pipe,conststructdrm_display_mode*mode)

MIPI DBI mode-valid helper

Parameters

structdrm_simple_display_pipe*pipe

Simple display pipe

conststructdrm_display_mode*mode

The mode to test

Description

This function validates a given display mode against the MIPI DBI’s hardwaredisplay. Drivers can use this as theirdrm_simple_display_pipe_funcs->mode_validcallback.

voidmipi_dbi_pipe_update(structdrm_simple_display_pipe*pipe,structdrm_plane_state*old_state)

Display pipe update helper

Parameters

structdrm_simple_display_pipe*pipe

Simple display pipe

structdrm_plane_state*old_state

Old plane state

Description

This function handles framebuffer flushing and vblank events. Drivers can usethis as theirdrm_simple_display_pipe_funcs->update callback.

voidmipi_dbi_enable_flush(structmipi_dbi_dev*dbidev,structdrm_crtc_state*crtc_state,structdrm_plane_state*plane_state)

MIPI DBI enable helper

Parameters

structmipi_dbi_dev*dbidev

MIPI DBI device structure

structdrm_crtc_state*crtc_state

CRTC state

structdrm_plane_state*plane_state

Plane state

Description

Flushes the whole framebuffer and enables the backlight. Drivers can use thisin theirdrm_simple_display_pipe_funcs->enable callback.

Note

Drivers which don’t usemipi_dbi_pipe_update() because they have customframebuffer flushing, can’t use this function since they both use the sameflushing code.

voidmipi_dbi_pipe_disable(structdrm_simple_display_pipe*pipe)

MIPI DBI pipe disable helper

Parameters

structdrm_simple_display_pipe*pipe

Display pipe

Description

This function disables backlight if present, if not the display memory isblanked. The regulator is disabled if in use. Drivers can use this as theirdrm_simple_display_pipe_funcs->disable callback.

intmipi_dbi_pipe_begin_fb_access(structdrm_simple_display_pipe*pipe,structdrm_plane_state*plane_state)

MIPI DBI pipe begin-access helper

Parameters

structdrm_simple_display_pipe*pipe

Display pipe

structdrm_plane_state*plane_state

Plane state

Description

This function implements structdrm_simple_display_funcs.begin_fb_access.

Seedrm_gem_begin_shadow_fb_access() for details andmipi_dbi_pipe_cleanup_fb()for cleanup.

Return

0 on success, or a negative errno code otherwise.

voidmipi_dbi_pipe_end_fb_access(structdrm_simple_display_pipe*pipe,structdrm_plane_state*plane_state)

MIPI DBI pipe end-access helper

Parameters

structdrm_simple_display_pipe*pipe

Display pipe

structdrm_plane_state*plane_state

Plane state

Description

This function implements structdrm_simple_display_funcs.end_fb_access.

Seemipi_dbi_pipe_begin_fb_access().

voidmipi_dbi_pipe_reset_plane(structdrm_simple_display_pipe*pipe)

MIPI DBI plane-reset helper

Parameters

structdrm_simple_display_pipe*pipe

Display pipe

Description

This function implements structdrm_simple_display_funcs.reset_planefor MIPI DBI planes.

structdrm_plane_state*mipi_dbi_pipe_duplicate_plane_state(structdrm_simple_display_pipe*pipe)

duplicates MIPI DBI plane state

Parameters

structdrm_simple_display_pipe*pipe

Display pipe

Description

This function implements structdrm_simple_display_funcs.duplicate_plane_statefor MIPI DBI planes.

Seedrm_gem_duplicate_shadow_plane_state() for additional details.

Return

A pointer to a new plane state on success, or NULL otherwise.

voidmipi_dbi_pipe_destroy_plane_state(structdrm_simple_display_pipe*pipe,structdrm_plane_state*plane_state)

cleans up MIPI DBI plane state

Parameters

structdrm_simple_display_pipe*pipe

Display pipe

structdrm_plane_state*plane_state

Plane state

Description

This function implementsstructdrm_simple_display_funcs.destroy_plane_statefor MIPI DBI planes.

Seedrm_gem_destroy_shadow_plane_state() for additional details.

intmipi_dbi_dev_init_with_formats(structmipi_dbi_dev*dbidev,conststructdrm_simple_display_pipe_funcs*funcs,constuint32_t*formats,unsignedintformat_count,conststructdrm_display_mode*mode,unsignedintrotation,size_ttx_buf_size)

MIPI DBI device initialization with custom formats

Parameters

structmipi_dbi_dev*dbidev

MIPI DBI device structure to initialize

conststructdrm_simple_display_pipe_funcs*funcs

Display pipe functions

constuint32_t*formats

Array of supported formats (DRM_FORMAT_*).

unsignedintformat_count

Number of elements informats

conststructdrm_display_mode*mode

Display mode

unsignedintrotation

Initial rotation in degrees Counter Clock Wise

size_ttx_buf_size

Allocate a transmit buffer of this size.

Description

This function sets up adrm_simple_display_pipe with adrm_connector thathas one fixeddrm_display_mode which is rotated according torotation.This mode is used to set the mode config min/max width/height properties.

Usemipi_dbi_dev_init() if you want native RGB565 and emulated XRGB8888 format.

Note

Some of the helper functions expects RGB565 to be the default format and thetransmit buffer sized to fit that.

Return

Zero on success, negative error code on failure.

intmipi_dbi_dev_init(structmipi_dbi_dev*dbidev,conststructdrm_simple_display_pipe_funcs*funcs,conststructdrm_display_mode*mode,unsignedintrotation)

MIPI DBI device initialization

Parameters

structmipi_dbi_dev*dbidev

MIPI DBI device structure to initialize

conststructdrm_simple_display_pipe_funcs*funcs

Display pipe functions

conststructdrm_display_mode*mode

Display mode

unsignedintrotation

Initial rotation in degrees Counter Clock Wise

Description

This function sets up adrm_simple_display_pipe with adrm_connector thathas one fixeddrm_display_mode which is rotated according torotation.This mode is used to set the mode config min/max width/height properties.Additionallymipi_dbi.tx_buf is allocated.

Supported formats: Native RGB565 and emulated XRGB8888.

Return

Zero on success, negative error code on failure.

voidmipi_dbi_hw_reset(structmipi_dbi*dbi)

Hardware reset of controller

Parameters

structmipi_dbi*dbi

MIPI DBI structure

Description

Reset controller if themipi_dbi->reset gpio is set.

boolmipi_dbi_display_is_on(structmipi_dbi*dbi)

Check if display is on

Parameters

structmipi_dbi*dbi

MIPI DBI structure

Description

This function checks the Power Mode register (if readable) to see ifdisplay output is turned on. This can be used to see if the bootloaderhas already turned on the display avoiding flicker when the pipeline isenabled.

Return

true if the display can be verified to be on, false otherwise.

intmipi_dbi_poweron_reset(structmipi_dbi_dev*dbidev)

MIPI DBI poweron and reset

Parameters

structmipi_dbi_dev*dbidev

MIPI DBI device structure

Description

This function enables the regulator if used and does a hardware and softwarereset.

Return

Zero on success, or a negative error code.

intmipi_dbi_poweron_conditional_reset(structmipi_dbi_dev*dbidev)

MIPI DBI poweron and conditional reset

Parameters

structmipi_dbi_dev*dbidev

MIPI DBI device structure

Description

This function enables the regulator if used and if the display is off, itdoes a hardware and software reset. Ifmipi_dbi_display_is_on() determinesthat the display is on, no reset is performed.

Return

Zero if the controller was reset, 1 if the display was already on, or anegative error code.

u32mipi_dbi_spi_cmd_max_speed(structspi_device*spi,size_tlen)

get the maximum SPI bus speed

Parameters

structspi_device*spi

SPI device

size_tlen

The transfer buffer length.

Description

Many controllers have a max speed of 10MHz, but can be pushed way beyondthat. Increase reliability by running pixel data at max speed and the restat 10MHz, preventing transfer glitches from messing up the init settings.

intmipi_dbi_spi_init(structspi_device*spi,structmipi_dbi*dbi,structgpio_desc*dc)

Initialize MIPI DBI SPI interface

Parameters

structspi_device*spi

SPI device

structmipi_dbi*dbi

MIPI DBI structure to initialize

structgpio_desc*dc

D/C gpio (optional)

Description

This function setsmipi_dbi->command, enablesmipi_dbi->read_commands for theusual read commands. It should be followed by a call tomipi_dbi_dev_init() ora driver-specific init.

Ifdc is set, a Type C Option 3 interface is assumed, if notType C Option 1.

If the command isMIPI_DCS_WRITE_MEMORY_START and the pixel format is RGB565, endianness hasto be taken into account. The MIPI DBI serial interface is big endian and framebuffers areassumed stored in memory as little endian (DRM_FORMAT_BIG_ENDIAN is not supported).

This is how endianness is handled:

Option 1 (D/C as a bit): The buffer is sent on the wire byte by byte so the 16-bit buffer is

byteswapped before transfer.

Option 3 (D/C as a gpio): If the SPI controller supports 16 bits per word the buffer can be

sent as-is. If not the caller is responsible for swapping the bytesbefore callingmipi_dbi_command_buf() and the buffer is sent 8 bpw.

This handling is optimised forDRM_FORMAT_RGB565 framebuffers.

If the interface is Option 1 and the SPI controller doesn’t support 9 bits per word,the buffer is sent as 9x 8-bit words, padded with MIPI DCS no-op commands if necessary.

Return

Zero on success, negative error code on failure.

intmipi_dbi_spi_transfer(structspi_device*spi,u32speed_hz,u8bpw,constvoid*buf,size_tlen)

SPI transfer helper

Parameters

structspi_device*spi

SPI device

u32speed_hz

Override speed (optional)

u8bpw

Bits per word

constvoid*buf

Buffer to transfer

size_tlen

Buffer length

Description

This SPI transfer helper breaks up the transfer ofbuf into chunks whichthe SPI controller driver can handle. The SPI bus must be locked whencalling this.

Return

Zero on success, negative error code on failure.

voidmipi_dbi_debugfs_init(structdrm_minor*minor)

Create debugfs entries

Parameters

structdrm_minor*minor

DRM minor

Description

This function creates a ‘command’ debugfs file for sending commands to thecontroller or getting the read command values.Drivers can use this as theirdrm_driver->debugfs_init callback.

MIPI DSI Helper Functions Reference

These functions contain some common logic and helpers to deal with MIPI DSIperipherals.

Helpers are provided for a number of standard MIPI DSI command as well as asubset of the MIPI DCS command set.

structmipi_dsi_msg

read/write DSI buffer

Definition:

struct mipi_dsi_msg {    u8 channel;    u8 type;    u16 flags;    size_t tx_len;    const void *tx_buf;    size_t rx_len;    void *rx_buf;};

Members

channel

virtual channel id

type

payload data type

flags

flags controlling this message transmission

tx_len

length oftx_buf

tx_buf

data to be written

rx_len

length ofrx_buf

rx_buf

data to be read, or NULL

structmipi_dsi_packet

represents a MIPI DSI packet in protocol format

Definition:

struct mipi_dsi_packet {    size_t size;    u8 header[4];    size_t payload_length;    const u8 *payload;};

Members

size

size (in bytes) of the packet

header

the four bytes that make up the header (Data ID, Word Count orPacket Data, and ECC)

payload_length

number of bytes in the payload

payload

a pointer to a buffer containing the payload, if any

structmipi_dsi_host_ops

DSI bus operations

Definition:

struct mipi_dsi_host_ops {    int (*attach)(struct mipi_dsi_host *host, struct mipi_dsi_device *dsi);    int (*detach)(struct mipi_dsi_host *host, struct mipi_dsi_device *dsi);    ssize_t (*transfer)(struct mipi_dsi_host *host, const struct mipi_dsi_msg *msg);};

Members

attach

attach DSI device to DSI host

detach

detach DSI device from DSI host

transfer

transmit a DSI packet

Description

DSI packets transmitted by .transfer() are passed in as mipi_dsi_msgstructures. This structure contains information about the type of packetbeing transmitted as well as the transmit and receive buffers. When anerror is encountered during transmission, this function will return anegative error code. On success it shall return the number of bytestransmitted for write packets or the number of bytes received for readpackets.

Note that typically DSI packet transmission is atomic, so the .transfer()function will seldomly return anything other than the number of bytescontained in the transmit buffer on success.

Also note that those callbacks can be called no matter the state thehost is in. Drivers that need the underlying device to be powered toperform these operations will first need to make sure it’s beenproperly enabled.

structmipi_dsi_host

DSI host device

Definition:

struct mipi_dsi_host {    struct device *dev;    const struct mipi_dsi_host_ops *ops;    struct list_head list;};

Members

dev

driver model device node for this DSI host

ops

DSI host operations

list

list management

structmipi_dsi_device_info

template for creating a mipi_dsi_device

Definition:

struct mipi_dsi_device_info {    char type[DSI_DEV_NAME_SIZE];    u32 channel;    struct device_node *node;};

Members

type

DSI peripheral chip type

channel

DSI virtual channel assigned to peripheral

node

pointer to OF device node or NULL

Description

This is populated and passed to mipi_dsi_device_new to create a newDSI device

structmipi_dsi_device

DSI peripheral device

Definition:

struct mipi_dsi_device {    struct mipi_dsi_host *host;    struct device dev;    bool attached;    char name[DSI_DEV_NAME_SIZE];    unsigned int channel;    unsigned int lanes;    enum mipi_dsi_pixel_format format;    unsigned long mode_flags;    unsigned long hs_rate;    unsigned long lp_rate;    struct drm_dsc_config *dsc;};

Members

host

DSI host for this peripheral

dev

driver model device node for this peripheral

attached

the DSI device has been successfully attached

name

DSI peripheral chip type

channel

virtual channel assigned to the peripheral

lanes

number of active data lanes

format

pixel format for video mode

mode_flags

DSI operation mode related flags

hs_rate

maximum lane frequency for high speed mode in hertz, this shouldbe set to the real limits of the hardware, zero is only accepted forlegacy drivers

lp_rate

maximum lane frequency for low power mode in hertz, this shouldbe set to the real limits of the hardware, zero is only accepted forlegacy drivers

dsc

panel/bridge DSC pps payload to be sent

structmipi_dsi_multi_context

Context to call multiple MIPI DSI funcs in a row

Definition:

struct mipi_dsi_multi_context {    struct mipi_dsi_device *dsi;    int accum_err;};

Members

dsi

Pointer to the MIPI DSI device

accum_err

Storage for the accumulated error over the multiple calls

Init to 0. If a function encounters an error then the error codewill be stored here. If you call a function and this points to anon-zero value then the function will be a noop. This allows callinga function many times in a row and just checking the error at theend to see if any of them failed.

intmipi_dsi_pixel_format_to_bpp(enummipi_dsi_pixel_formatfmt)

obtain the number of bits per pixel for any given pixel format defined by the MIPI DSI specification

Parameters

enummipi_dsi_pixel_formatfmt

MIPI DSI pixel format

Return

The number of bits per pixel of the given pixel format.

enummipi_dsi_dcs_tear_mode

Tearing Effect Output Line mode

Constants

MIPI_DSI_DCS_TEAR_MODE_VBLANK

the TE output line consists of V-Blankinginformation only

MIPI_DSI_DCS_TEAR_MODE_VHBLANK

the TE output line consists of bothV-Blanking and H-Blanking information

mipi_dsi_generic_write_seq_multi

mipi_dsi_generic_write_seq_multi(ctx,seq...)

transmit data using a generic write packet

Parameters

ctx

Context for multiple DSI transactions

seq...

buffer containing the payload

Description

This macro will print errors for you and error handling is optimized forcallers that call this multiple times in a row.

mipi_dsi_generic_write_var_seq_multi

mipi_dsi_generic_write_var_seq_multi(ctx,seq...)

transmit non-constant data using a generic write packet

Parameters

ctx

Context for multiple DSI transactions

seq...

buffer containing the payload

Description

This macro will print errors for you and error handling is optimized forcallers that call this multiple times in a row.

mipi_dsi_dcs_write_seq_multi

mipi_dsi_dcs_write_seq_multi(ctx,cmd,seq...)

transmit a DCS command with payload

Parameters

ctx

Context for multiple DSI transactions

cmd

Command

seq...

buffer containing data to be transmitted

Description

This macro will print errors for you and error handling is optimized forcallers that call this multiple times in a row.

mipi_dsi_dcs_write_var_seq_multi

mipi_dsi_dcs_write_var_seq_multi(ctx,cmd,seq...)

transmit a DCS command with non-constant payload

Parameters

ctx

Context for multiple DSI transactions

cmd

Command

seq...

buffer containing data to be transmitted

Description

This macro will print errors for you and error handling is optimized forcallers that call this multiple times in a row.

mipi_dsi_dual

mipi_dsi_dual(_func,_ctx,_dsi1,_dsi2,...)

send the same MIPI DSI command to two interfaces

Parameters

_func

MIPI DSI function to pass context and arguments into

_ctx

Context for multiple DSI transactions

_dsi1

First DSI interface to act as recipient of the MIPI DSI command

_dsi2

Second DSI interface to act as recipient of the MIPI DSI command

...

Arguments to pass to MIPI DSI function or macro

Description

This macro will send the specified MIPI DSI command twice, once per each ofthe two interfaces supplied. This is useful for reducing duplication of codein panel drivers which use two parallel serial interfaces.

Note that the _func parameter cannot accept a macro such asmipi_dsi_generic_write_multi() ormipi_dsi_dcs_write_buffer_multi(). Seemipi_dsi_dual_generic_write_multi() andmipi_dsi_dual_dcs_write_buffer_multi() instead.

WARNING: This macro reuses the _func argument and the optional trailingarguments twice each, which may cause unintended side effects. For example,adding the postfix increment ++ operator to one of the arguments to bepassed to _func will cause the variable to be incremented twice instead ofonce and the variable will be its original value + 1 when sent to _dsi2.

mipi_dsi_dual_generic_write_seq_multi

mipi_dsi_dual_generic_write_seq_multi(_ctx,_dsi1,_dsi2,_seq...)

transmit data using a generic write packet to two dsi interfaces, one after the other

Parameters

_ctx

Context for multiple DSI transactions

_dsi1

First DSI interface to act as recipient of packet

_dsi2

Second DSI interface to act as recipient of packet

_seq...

buffer containing the payload

Description

This macro will send the specified generic packet twice, once per each ofthe two interfaces supplied. This is useful for reducing duplication of codein panel drivers which use two parallel serial interfaces.

Note that if an error occurs while transmitting the packet to the first DSIinterface, the packet will not be sent to the second DSI interface.

This macro will print errors for you and error handling is optimized forcallers that call this multiple times in a row.

mipi_dsi_dual_dcs_write_seq_multi

mipi_dsi_dual_dcs_write_seq_multi(_ctx,_dsi1,_dsi2,_cmd,_seq...)

transmit a DCS command with payload to two dsi interfaces, one after the other

Parameters

_ctx

Context for multiple DSI transactions

_dsi1

First DSI interface to act as recipient of packet

_dsi2

Second DSI interface to act as recipient of packet

_cmd

Command

_seq...

buffer containing the payload

Description

This macro will send the specified DCS command with payload twice, once pereach of the two interfaces supplied. This is useful for reducing duplicationof code in panel drivers which use two parallel serial interfaces.

Note that if an error occurs while transmitting the payload to the first DSIinterface, the payload will not be sent to the second DSI interface.

This macro will print errors for you and error handling is optimized forcallers that call this multiple times in a row.

structmipi_dsi_driver

DSI driver

Definition:

struct mipi_dsi_driver {    struct device_driver driver;    int(*probe)(struct mipi_dsi_device *dsi);    void (*remove)(struct mipi_dsi_device *dsi);    void (*shutdown)(struct mipi_dsi_device *dsi);};

Members

driver

device driver model driver

probe

callback for device binding

remove

callback for device unbinding

shutdown

called at shutdown time to quiesce the device

structmipi_dsi_device*of_find_mipi_dsi_device_by_node(structdevice_node*np)

find the MIPI DSI device matching a device tree node

Parameters

structdevice_node*np

device tree node

Return

A pointer to the MIPI DSI device corresponding tonp or NULL if nosuch device exists (or has not been registered yet).

structmipi_dsi_device*mipi_dsi_device_register_full(structmipi_dsi_host*host,conststructmipi_dsi_device_info*info)

create a MIPI DSI device

Parameters

structmipi_dsi_host*host

DSI host to which this device is connected

conststructmipi_dsi_device_info*info

pointer to template containing DSI device information

Description

Create a MIPI DSI device by using the device information provided bymipi_dsi_device_info template

Return

A pointer to the newly created MIPI DSI device, or, a pointer encodedwith an error

voidmipi_dsi_device_unregister(structmipi_dsi_device*dsi)

unregister MIPI DSI device

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

structmipi_dsi_device*devm_mipi_dsi_device_register_full(structdevice*dev,structmipi_dsi_host*host,conststructmipi_dsi_device_info*info)

create a managed MIPI DSI device

Parameters

structdevice*dev

device to tie the MIPI-DSI device lifetime to

structmipi_dsi_host*host

DSI host to which this device is connected

conststructmipi_dsi_device_info*info

pointer to template containing DSI device information

Description

Create a MIPI DSI device by using the device information provided bymipi_dsi_device_info template

This is the managed version ofmipi_dsi_device_register_full() whichautomatically callsmipi_dsi_device_unregister() whendev isunbound.

Return

A pointer to the newly created MIPI DSI device, or, a pointer encodedwith an error

structmipi_dsi_host*of_find_mipi_dsi_host_by_node(structdevice_node*node)

find the MIPI DSI host matching a device tree node

Parameters

structdevice_node*node

device tree node

Return

A pointer to the MIPI DSI host corresponding tonode or NULL if nosuch device exists (or has not been registered yet).

intmipi_dsi_attach(structmipi_dsi_device*dsi)

attach a DSI device to its DSI host

Parameters

structmipi_dsi_device*dsi

DSI peripheral

intmipi_dsi_detach(structmipi_dsi_device*dsi)

detach a DSI device from its DSI host

Parameters

structmipi_dsi_device*dsi

DSI peripheral

intdevm_mipi_dsi_attach(structdevice*dev,structmipi_dsi_device*dsi)

Attach a MIPI-DSI device to its DSI Host

Parameters

structdevice*dev

device to tie the MIPI-DSI device attachment lifetime to

structmipi_dsi_device*dsi

DSI peripheral

Description

This is the managed version ofmipi_dsi_attach() which automaticallycallsmipi_dsi_detach() whendev is unbound.

Return

0 on success, a negative error code on failure.

boolmipi_dsi_packet_format_is_short(u8type)

check if a packet is of the short format

Parameters

u8type

MIPI DSI data type of the packet

Return

true if the packet for the given data type is a short packet, falseotherwise.

boolmipi_dsi_packet_format_is_long(u8type)

check if a packet is of the long format

Parameters

u8type

MIPI DSI data type of the packet

Return

true if the packet for the given data type is a long packet, falseotherwise.

intmipi_dsi_create_packet(structmipi_dsi_packet*packet,conststructmipi_dsi_msg*msg)

create a packet from a message according to the DSI protocol

Parameters

structmipi_dsi_packet*packet

pointer to a DSI packet structure

conststructmipi_dsi_msg*msg

message to translate into a packet

Return

0 on success or a negative error code on failure.

intmipi_dsi_shutdown_peripheral(structmipi_dsi_device*dsi)

sends a Shutdown Peripheral command

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

Return

0 on success or a negative error code on failure.

intmipi_dsi_turn_on_peripheral(structmipi_dsi_device*dsi)

sends a Turn On Peripheral command

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

Description

This function is deprecated. Usemipi_dsi_turn_on_peripheral_multi() instead.

Return

0 on success or a negative error code on failure.

intmipi_dsi_compression_mode_ext(structmipi_dsi_device*dsi,boolenable,enummipi_dsi_compression_algoalgo,unsignedintpps_selector)

enable/disable DSC on the peripheral

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

boolenable

Whether to enable or disable the DSC

enummipi_dsi_compression_algoalgo

Selected compression algorithm

unsignedintpps_selector

Select PPS from the table of pre-stored or uploaded PPS entries

Description

Enable or disable Display Stream Compression on the peripheral.This function is deprecated. Usemipi_dsi_compression_mode_ext_multi() instead.

Return

0 on success or a negative error code on failure.

intmipi_dsi_compression_mode(structmipi_dsi_device*dsi,boolenable)

enable/disable DSC on the peripheral

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

boolenable

Whether to enable or disable the DSC

Description

Enable or disable Display Stream Compression on the peripheral using thedefault Picture Parameter Set and VESA DSC 1.1 algorithm.

Return

0 on success or a negative error code on failure.

intmipi_dsi_picture_parameter_set(structmipi_dsi_device*dsi,conststructdrm_dsc_picture_parameter_set*pps)

transmit the DSC PPS to the peripheral

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

conststructdrm_dsc_picture_parameter_set*pps

VESA DSC 1.1 Picture Parameter Set

Description

Transmit the VESA DSC 1.1 Picture Parameter Set to the peripheral.This function is deprecated. Usemipi_dsi_picture_parameter_set_multi() instead.

Return

0 on success or a negative error code on failure.

ssize_tmipi_dsi_generic_write(structmipi_dsi_device*dsi,constvoid*payload,size_tsize)

transmit data using a generic write packet

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

constvoid*payload

buffer containing the payload

size_tsize

size of payload buffer

Description

This function will automatically choose the right data type depending onthe payload length.

Return

The number of bytes transmitted on success or a negative error codeon failure.

voidmipi_dsi_generic_write_multi(structmipi_dsi_multi_context*ctx,constvoid*payload,size_tsize)

mipi_dsi_generic_write() w/ accum_err

Parameters

structmipi_dsi_multi_context*ctx

Context for multiple DSI transactions

constvoid*payload

buffer containing the payload

size_tsize

size of payload buffer

Description

A wrapper aroundmipi_dsi_generic_write() that deals with errors in a waythat makes it convenient to make several calls in a row.

voidmipi_dsi_dual_generic_write_multi(structmipi_dsi_multi_context*ctx,structmipi_dsi_device*dsi1,structmipi_dsi_device*dsi2,constvoid*payload,size_tsize)

mipi_dsi_generic_write_multi() for two dsi channels, one after the other

Parameters

structmipi_dsi_multi_context*ctx

Context for multiple DSI transactions

structmipi_dsi_device*dsi1

First dsi channel to write buffer to

structmipi_dsi_device*dsi2

Second dsi channel to write buffer to

constvoid*payload

Buffer containing the payload

size_tsize

Size of payload buffer

Description

A wrapper aroundmipi_dsi_generic_write_multi() that allows the user toconveniently write to two dsi channels, one after the other.

ssize_tmipi_dsi_generic_read(structmipi_dsi_device*dsi,constvoid*params,size_tnum_params,void*data,size_tsize)

receive data using a generic read packet

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

constvoid*params

buffer containing the request parameters

size_tnum_params

number of request parameters

void*data

buffer in which to return the received data

size_tsize

size of receive buffer

Description

This function will automatically choose the right data type depending onthe number of parameters passed in.

Return

The number of bytes successfully read or a negative error code onfailure.

u32drm_mipi_dsi_get_input_bus_fmt(enummipi_dsi_pixel_formatdsi_format)

Get the required MEDIA_BUS_FMT_* based input pixel format for a given DSI output pixel format

Parameters

enummipi_dsi_pixel_formatdsi_format

pixel format that a DSI host needs to output

Description

Various DSI hosts can use this function during theirdrm_bridge_funcs.atomic_get_input_bus_fmts operation to ascertainthe MEDIA_BUS_FMT_* pixel format required as input.

Return

a 32-bit MEDIA_BUS_FMT_* value on success or 0 in case of failure.

ssize_tmipi_dsi_dcs_write_buffer(structmipi_dsi_device*dsi,constvoid*data,size_tlen)

transmit a DCS command with payload

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

constvoid*data

buffer containing data to be transmitted

size_tlen

size of transmission buffer

Description

This function will automatically choose the right data type depending onthe command payload length.

Return

The number of bytes successfully transmitted or a negative errorcode on failure.

intmipi_dsi_dcs_write_buffer_chatty(structmipi_dsi_device*dsi,constvoid*data,size_tlen)

mipi_dsi_dcs_write_buffer() w/ an error log

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

constvoid*data

buffer containing data to be transmitted

size_tlen

size of transmission buffer

Description

Likemipi_dsi_dcs_write_buffer() but includes adev_err()call for you and returns 0 upon success, not the number of bytes sent.

Return

0 on success or a negative error code on failure.

voidmipi_dsi_dcs_write_buffer_multi(structmipi_dsi_multi_context*ctx,constvoid*data,size_tlen)

mipi_dsi_dcs_write_buffer_chatty() w/ accum_err

Parameters

structmipi_dsi_multi_context*ctx

Context for multiple DSI transactions

constvoid*data

buffer containing data to be transmitted

size_tlen

size of transmission buffer

Description

Likemipi_dsi_dcs_write_buffer_chatty() but deals with errors in a way thatmakes it convenient to make several calls in a row.

voidmipi_dsi_dual_dcs_write_buffer_multi(structmipi_dsi_multi_context*ctx,structmipi_dsi_device*dsi1,structmipi_dsi_device*dsi2,constvoid*data,size_tlen)

mipi_dsi_dcs_write_buffer_multi() for two dsi channels, one after the other

Parameters

structmipi_dsi_multi_context*ctx

Context for multiple DSI transactions

structmipi_dsi_device*dsi1

First dsi channel to write buffer to

structmipi_dsi_device*dsi2

Second dsi channel to write buffer to

constvoid*data

Buffer containing data to be transmitted

size_tlen

Size of transmission buffer

Description

A wrapper aroundmipi_dsi_dcs_write_buffer_multi() that allows the user toconveniently write to two dsi channels, one after the other.

ssize_tmipi_dsi_dcs_write(structmipi_dsi_device*dsi,u8cmd,constvoid*data,size_tlen)

send DCS write command

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

u8cmd

DCS command

constvoid*data

buffer containing the command payload

size_tlen

command payload length

Description

This function will automatically choose the right data type depending onthe command payload length.

Return

The number of bytes successfully transmitted or a negative errorcode on failure.

ssize_tmipi_dsi_dcs_read(structmipi_dsi_device*dsi,u8cmd,void*data,size_tlen)

send DCS read request command

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

u8cmd

DCS command

void*data

buffer in which to receive data

size_tlen

size of receive buffer

Return

The number of bytes read or a negative error code on failure.

voidmipi_dsi_dcs_read_multi(structmipi_dsi_multi_context*ctx,u8cmd,void*data,size_tlen)

mipi_dsi_dcs_read() w/ accum_err

Parameters

structmipi_dsi_multi_context*ctx

Context for multiple DSI transactions

u8cmd

DCS command

void*data

buffer in which to receive data

size_tlen

size of receive buffer

Description

Likemipi_dsi_dcs_read() but deals with errors in a way that makes itconvenient to make several calls in a row.

intmipi_dsi_dcs_nop(structmipi_dsi_device*dsi)

send DCS nop packet

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

Description

This function is deprecated. Usemipi_dsi_dcs_nop_multi() instead.

Return

0 on success or a negative error code on failure.

intmipi_dsi_dcs_soft_reset(structmipi_dsi_device*dsi)

perform a software reset of the display module

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

Description

This function is deprecated. Usemipi_dsi_dcs_soft_reset_multi() instead.

Return

0 on success or a negative error code on failure.

intmipi_dsi_dcs_get_power_mode(structmipi_dsi_device*dsi,u8*mode)

query the display module’s current power mode

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

u8*mode

return location for the current power mode

Return

0 on success or a negative error code on failure.

intmipi_dsi_dcs_get_pixel_format(structmipi_dsi_device*dsi,u8*format)

gets the pixel format for the RGB image data used by the interface

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

u8*format

return location for the pixel format

Return

0 on success or a negative error code on failure.

intmipi_dsi_dcs_enter_sleep_mode(structmipi_dsi_device*dsi)

disable all unnecessary blocks inside the display module except interface communication

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

Description

This function is deprecated. Usemipi_dsi_dcs_enter_sleep_mode_multi() instead.

Return

0 on success or a negative error code on failure.

intmipi_dsi_dcs_exit_sleep_mode(structmipi_dsi_device*dsi)

enable all blocks inside the display module

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

Description

This function is deprecated. Usemipi_dsi_dcs_exit_sleep_mode_multi() instead.

Return

0 on success or a negative error code on failure.

intmipi_dsi_dcs_set_display_off(structmipi_dsi_device*dsi)

stop displaying the image data on the display device

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

Description

This function is deprecated. Usemipi_dsi_dcs_set_display_off_multi() instead.

Return

0 on success or a negative error code on failure.

intmipi_dsi_dcs_set_display_on(structmipi_dsi_device*dsi)

start displaying the image data on the display device

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

Description

This function is deprecated. Usemipi_dsi_dcs_set_display_on_multi() instead.

Return

0 on success or a negative error code on failure

intmipi_dsi_dcs_set_column_address(structmipi_dsi_device*dsi,u16start,u16end)

define the column extent of the frame memory accessed by the host processor

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

u16start

first column of frame memory

u16end

last column of frame memory

Description

This function is deprecated. Usemipi_dsi_dcs_set_column_address_multi()instead.

Return

0 on success or a negative error code on failure.

intmipi_dsi_dcs_set_page_address(structmipi_dsi_device*dsi,u16start,u16end)

define the page extent of the frame memory accessed by the host processor

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

u16start

first page of frame memory

u16end

last page of frame memory

Description

This function is deprecated. Usemipi_dsi_dcs_set_page_address_multi()instead.

Return

0 on success or a negative error code on failure.

intmipi_dsi_dcs_set_tear_on(structmipi_dsi_device*dsi,enummipi_dsi_dcs_tear_modemode)

turn on the display module’s Tearing Effect output signal on the TE signal line.

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

enummipi_dsi_dcs_tear_modemode

the Tearing Effect Output Line mode

Description

This function is deprecated. Usemipi_dsi_dcs_set_tear_on_multi() instead.

Return

0 on success or a negative error code on failure

intmipi_dsi_dcs_set_pixel_format(structmipi_dsi_device*dsi,u8format)

sets the pixel format for the RGB image data used by the interface

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

u8format

pixel format

Description

This function is deprecated. Usemipi_dsi_dcs_set_pixel_format_multi()instead.

Return

0 on success or a negative error code on failure.

intmipi_dsi_dcs_set_tear_scanline(structmipi_dsi_device*dsi,u16scanline)

set the scanline to use as trigger for the Tearing Effect output signal of the display module

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

u16scanline

scanline to use as trigger

Description

This function is deprecated. Usemipi_dsi_dcs_set_tear_scanline_multi()instead.

Return

0 on success or a negative error code on failure

intmipi_dsi_dcs_set_display_brightness(structmipi_dsi_device*dsi,u16brightness)

sets the brightness value of the display

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

u16brightness

brightness value

Description

This function is deprecated. Usemipi_dsi_dcs_set_display_brightness_multi()instead.

Return

0 on success or a negative error code on failure.

intmipi_dsi_dcs_get_display_brightness(structmipi_dsi_device*dsi,u16*brightness)

gets the current brightness value of the display

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

u16*brightness

brightness value

Return

0 on success or a negative error code on failure.

intmipi_dsi_dcs_set_display_brightness_large(structmipi_dsi_device*dsi,u16brightness)

sets the 16-bit brightness value of the display

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

u16brightness

brightness value

Return

0 on success or a negative error code on failure.

intmipi_dsi_dcs_get_display_brightness_large(structmipi_dsi_device*dsi,u16*brightness)

gets the current 16-bit brightness value of the display

Parameters

structmipi_dsi_device*dsi

DSI peripheral device

u16*brightness

brightness value

Return

0 on success or a negative error code on failure.

voidmipi_dsi_picture_parameter_set_multi(structmipi_dsi_multi_context*ctx,conststructdrm_dsc_picture_parameter_set*pps)

transmit the DSC PPS to the peripheral

Parameters

structmipi_dsi_multi_context*ctx

Context for multiple DSI transactions

conststructdrm_dsc_picture_parameter_set*pps

VESA DSC 1.1 Picture Parameter Set

Description

Likemipi_dsi_picture_parameter_set() but deals with errors in a way thatmakes it convenient to make several calls in a row.

voidmipi_dsi_compression_mode_ext_multi(structmipi_dsi_multi_context*ctx,boolenable,enummipi_dsi_compression_algoalgo,unsignedintpps_selector)

enable/disable DSC on the peripheral

Parameters

structmipi_dsi_multi_context*ctx

Context for multiple DSI transactions

boolenable

Whether to enable or disable the DSC

enummipi_dsi_compression_algoalgo

Selected compression algorithm

unsignedintpps_selector

Select PPS from the table of pre-stored or uploaded PPS entries

Description

Likemipi_dsi_compression_mode_ext() but deals with errors in a way thatmakes it convenient to make several calls in a row.

voidmipi_dsi_compression_mode_multi(structmipi_dsi_multi_context*ctx,boolenable)

enable/disable DSC on the peripheral

Parameters

structmipi_dsi_multi_context*ctx

Context for multiple DSI transactions

boolenable

Whether to enable or disable the DSC

Description

Enable or disable Display Stream Compression on the peripheral using thedefault Picture Parameter Set and VESA DSC 1.1 algorithm.

voidmipi_dsi_dcs_nop_multi(structmipi_dsi_multi_context*ctx)

send DCS NOP packet

Parameters

structmipi_dsi_multi_context*ctx

Context for multiple DSI transactions

Description

Likemipi_dsi_dcs_nop() but deals with errors in a way thatmakes it convenient to make several calls in a row.

voidmipi_dsi_dcs_enter_sleep_mode_multi(structmipi_dsi_multi_context*ctx)

send DCS ENTER_SLEEP_MODE packet

Parameters

structmipi_dsi_multi_context*ctx

Context for multiple DSI transactions

Description

Likemipi_dsi_dcs_enter_sleep_mode() but deals with errors in a way thatmakes it convenient to make several calls in a row.

voidmipi_dsi_dcs_exit_sleep_mode_multi(structmipi_dsi_multi_context*ctx)

send DCS EXIT_SLEEP_MODE packet

Parameters

structmipi_dsi_multi_context*ctx

Context for multiple DSI transactions

Description

Likemipi_dsi_dcs_exit_sleep_mode() but deals with errors in a way thatmakes it convenient to make several calls in a row.

voidmipi_dsi_dcs_set_display_off_multi(structmipi_dsi_multi_context*ctx)

send DCS SET_DISPLAY_OFF packet

Parameters

structmipi_dsi_multi_context*ctx

Context for multiple DSI transactions

Description

Likemipi_dsi_dcs_set_display_off() but deals with errors in a way thatmakes it convenient to make several calls in a row.

voidmipi_dsi_dcs_set_display_on_multi(structmipi_dsi_multi_context*ctx)

send DCS SET_DISPLAY_ON packet

Parameters

structmipi_dsi_multi_context*ctx

Context for multiple DSI transactions

Description

Likemipi_dsi_dcs_set_display_on() but deals with errors in a way thatmakes it convenient to make several calls in a row.

voidmipi_dsi_dcs_set_tear_on_multi(structmipi_dsi_multi_context*ctx,enummipi_dsi_dcs_tear_modemode)

send DCS SET_TEAR_ON packet

Parameters

structmipi_dsi_multi_context*ctx

Context for multiple DSI transactions

enummipi_dsi_dcs_tear_modemode

the Tearing Effect Output Line mode

Description

Likemipi_dsi_dcs_set_tear_on() but deals with errors in a way thatmakes it convenient to make several calls in a row.

voidmipi_dsi_turn_on_peripheral_multi(structmipi_dsi_multi_context*ctx)

sends a Turn On Peripheral command

Parameters

structmipi_dsi_multi_context*ctx

Context for multiple DSI transactions

Description

Likemipi_dsi_turn_on_peripheral() but deals with errors in a way thatmakes it convenient to make several calls in a row.

voidmipi_dsi_dcs_set_tear_off_multi(structmipi_dsi_multi_context*ctx)

turn off the display module’s Tearing Effect output signal on the TE signal line

Parameters

structmipi_dsi_multi_context*ctx

Context for multiple DSI transactions

voidmipi_dsi_dcs_soft_reset_multi(structmipi_dsi_multi_context*ctx)

perform a software reset of the display module

Parameters

structmipi_dsi_multi_context*ctx

Context for multiple DSI transactions

Description

Likemipi_dsi_dcs_soft_reset() but deals with errors in a way thatmakes it convenient to make several calls in a row.

voidmipi_dsi_dcs_set_display_brightness_multi(structmipi_dsi_multi_context*ctx,u16brightness)

sets the brightness value of the display

Parameters

structmipi_dsi_multi_context*ctx

Context for multiple DSI transactions

u16brightness

brightness value

Description

Likemipi_dsi_dcs_set_display_brightness() but deals with errors in a way thatmakes it convenient to make several calls in a row.

voidmipi_dsi_dcs_set_pixel_format_multi(structmipi_dsi_multi_context*ctx,u8format)

sets the pixel format for the RGB image data used by the interface

Parameters

structmipi_dsi_multi_context*ctx

Context for multiple DSI transactions

u8format

pixel format

Description

Likemipi_dsi_dcs_set_pixel_format() but deals with errors in a way thatmakes it convenient to make several calls in a row.

voidmipi_dsi_dcs_set_column_address_multi(structmipi_dsi_multi_context*ctx,u16start,u16end)

define the column extent of the frame memory accessed by the host processor

Parameters

structmipi_dsi_multi_context*ctx

Context for multiple DSI transactions

u16start

first column of frame memory

u16end

last column of frame memory

Description

Likemipi_dsi_dcs_set_column_address() but deals with errors in a way thatmakes it convenient to make several calls in a row.

voidmipi_dsi_dcs_set_page_address_multi(structmipi_dsi_multi_context*ctx,u16start,u16end)

define the page extent of the frame memory accessed by the host processor

Parameters

structmipi_dsi_multi_context*ctx

Context for multiple DSI transactions

u16start

first page of frame memory

u16end

last page of frame memory

Description

Likemipi_dsi_dcs_set_page_address() but deals with errors in a way thatmakes it convenient to make several calls in a row.

voidmipi_dsi_dcs_set_tear_scanline_multi(structmipi_dsi_multi_context*ctx,u16scanline)

set the scanline to use as trigger for the Tearing Effect output signal of the display module

Parameters

structmipi_dsi_multi_context*ctx

Context for multiple DSI transactions

u16scanline

scanline to use as trigger

Description

Likemipi_dsi_dcs_set_tear_scanline() but deals with errors in a way thatmakes it convenient to make several calls in a row.

intmipi_dsi_driver_register_full(structmipi_dsi_driver*drv,structmodule*owner)

register a driver for DSI devices

Parameters

structmipi_dsi_driver*drv

DSI driver structure

structmodule*owner

owner module

Return

0 on success or a negative error code on failure.

voidmipi_dsi_driver_unregister(structmipi_dsi_driver*drv)

unregister a driver for DSI devices

Parameters

structmipi_dsi_driver*drv

DSI driver structure

Return

0 on success or a negative error code on failure.

Display Stream Compression Helper Functions Reference

VESA specification for DP 1.4 adds a new feature called Display StreamCompression (DSC) used to compress the pixel bits before sending it onDP/eDP/MIPI DSI interface. DSC is required to be enabled so that the existingdisplay interfaces can support high resolutions at higher frames rates uisngthe maximum available link capacity of these interfaces.

These functions contain some common logic and helpers to deal with VESADisplay Stream Compression standard required for DSC on Display Port/eDP orMIPI display interfaces.

structdrm_dsc_rc_range_parameters

DSC Rate Control range parameters

Definition:

struct drm_dsc_rc_range_parameters {    u8 range_min_qp;    u8 range_max_qp;    u8 range_bpg_offset;};

Members

range_min_qp

Min Quantization Parameters allowed for this range

range_max_qp

Max Quantization Parameters allowed for this range

range_bpg_offset

Bits/group offset to apply to target for this group

Description

This defines different rate control parameters used by the DSC engineto compress the frame.

structdrm_dsc_config

Parameters required to configure DSC

Definition:

struct drm_dsc_config {    u8 line_buf_depth;    u8 bits_per_component;    bool convert_rgb;    u8 slice_count;    u16 slice_width;    u16 slice_height;    bool simple_422;    u16 pic_width;    u16 pic_height;    u8 rc_tgt_offset_high;    u8 rc_tgt_offset_low;    u16 bits_per_pixel;    u8 rc_edge_factor;    u8 rc_quant_incr_limit1;    u8 rc_quant_incr_limit0;    u16 initial_xmit_delay;    u16 initial_dec_delay;    bool block_pred_enable;    u8 first_line_bpg_offset;    u16 initial_offset;    u16 rc_buf_thresh[DSC_NUM_BUF_RANGES - 1];    struct drm_dsc_rc_range_parameters rc_range_params[DSC_NUM_BUF_RANGES];    u16 rc_model_size;    u8 flatness_min_qp;    u8 flatness_max_qp;    u8 initial_scale_value;    u16 scale_decrement_interval;    u16 scale_increment_interval;    u16 nfl_bpg_offset;    u16 slice_bpg_offset;    u16 final_offset;    bool vbr_enable;    u8 mux_word_size;    u16 slice_chunk_size;    u16 rc_bits;    u8 dsc_version_minor;    u8 dsc_version_major;    bool native_422;    bool native_420;    u8 second_line_bpg_offset;    u16 nsl_bpg_offset;    u16 second_line_offset_adj;};

Members

line_buf_depth

Bits per component for previous reconstructed line buffer

bits_per_component

Bits per component to code (8/10/12)

convert_rgb

Flag to indicate if RGB - YCoCg conversion is neededTrue if RGB input, False if YCoCg input

slice_count

Number fo slices per line used by the DSC encoder

slice_width

Width of each slice in pixels

slice_height

Slice height in pixels

simple_422

True if simple 4_2_2 mode is enabled else False

pic_width

Width of the input display frame in pixels

pic_height

Vertical height of the input display frame

rc_tgt_offset_high

Offset to bits/group used by RC to determine QP adjustment

rc_tgt_offset_low

Offset to bits/group used by RC to determine QP adjustment

bits_per_pixel

Target bits per pixel with 4 fractional bits, bits_per_pixel << 4

rc_edge_factor

Factor to determine if an edge is present based on the bits produced

rc_quant_incr_limit1

Slow down incrementing once the range reaches this value

rc_quant_incr_limit0

Slow down incrementing once the range reaches this value

initial_xmit_delay

Number of pixels to delay the initial transmission

initial_dec_delay

Initial decoder delay, number of pixel times that the decoderaccumulates data in its rate buffer before starting to decodeand output pixels.

block_pred_enable

True if block prediction is used to code any groups within thepicture. False if BP not used

first_line_bpg_offset

Number of additional bits allocated for each group on the firstline of slice.

initial_offset

Value to use for RC model offset at slice start

rc_buf_thresh

Thresholds defining each of the buffer ranges

rc_range_params

Parameters for each of the RC ranges defined instructdrm_dsc_rc_range_parameters

rc_model_size

Total size of RC model

flatness_min_qp

Minimum QP where flatness information is sent

flatness_max_qp

Maximum QP where flatness information is sent

initial_scale_value

Initial value for the scale factor

scale_decrement_interval

Specifies number of group times between decrementing the scale factorat beginning of a slice.

scale_increment_interval

Number of group times between incrementing the scale factor valueused at the beginning of a slice.

nfl_bpg_offset

Non first line BPG offset to be used

slice_bpg_offset

BPG offset used to enforce slice bit

final_offset

Final RC linear transformation offset value

vbr_enable

True if VBR mode is enabled, false if disabled

mux_word_size

Mux word size (in bits) for SSM mode

slice_chunk_size

The (max) size in bytes of the “chunks” that are used in slicemultiplexing.

rc_bits

Rate control buffer size in bits

dsc_version_minor

DSC minor version

dsc_version_major

DSC major version

native_422

True if Native 4:2:2 supported, else false

native_420

True if Native 4:2:0 supported else false.

second_line_bpg_offset

Additional bits/grp for seconnd line of slice for native 4:2:0

nsl_bpg_offset

Num of bits deallocated for each grp that is not in second line ofslice

second_line_offset_adj

Offset adjustment for second line in Native 4:2:0 mode

Description

Driver populates this structure with all the parameters requiredto configure the display stream compression on the source.

structdrm_dsc_picture_parameter_set

Represents 128 bytes of Picture Parameter Set

Definition:

struct drm_dsc_picture_parameter_set {    u8 dsc_version;    u8 pps_identifier;    u8 pps_reserved;    u8 pps_3;    u8 pps_4;    u8 bits_per_pixel_low;    __be16 pic_height;    __be16 pic_width;    __be16 slice_height;    __be16 slice_width;    __be16 chunk_size;    u8 initial_xmit_delay_high;    u8 initial_xmit_delay_low;    __be16 initial_dec_delay;    u8 pps20_reserved;    u8 initial_scale_value;    __be16 scale_increment_interval;    u8 scale_decrement_interval_high;    u8 scale_decrement_interval_low;    u8 pps26_reserved;    u8 first_line_bpg_offset;    __be16 nfl_bpg_offset;    __be16 slice_bpg_offset;    __be16 initial_offset;    __be16 final_offset;    u8 flatness_min_qp;    u8 flatness_max_qp;    __be16 rc_model_size;    u8 rc_edge_factor;    u8 rc_quant_incr_limit0;    u8 rc_quant_incr_limit1;    u8 rc_tgt_offset;    u8 rc_buf_thresh[DSC_NUM_BUF_RANGES - 1];    __be16 rc_range_parameters[DSC_NUM_BUF_RANGES];    u8 native_422_420;    u8 second_line_bpg_offset;    __be16 nsl_bpg_offset;    __be16 second_line_offset_adj;    u32 pps_long_94_reserved;    u32 pps_long_98_reserved;    u32 pps_long_102_reserved;    u32 pps_long_106_reserved;    u32 pps_long_110_reserved;    u32 pps_long_114_reserved;    u32 pps_long_118_reserved;    u32 pps_long_122_reserved;    __be16 pps_short_126_reserved;};

Members

dsc_version

PPS0[3:0] - dsc_version_minor: Contains Minor version of DSCPPS0[7:4] - dsc_version_major: Contains major version of DSC

pps_identifier

PPS1[7:0] - Application specific identifier that can beused to differentiate between different PPS tables.

pps_reserved

PPS2[7:0]- RESERVED Byte

pps_3

PPS3[3:0] - linebuf_depth: Contains linebuffer bit depth used togenerate the bitstream. (0x0 - 16 bits for DSC 1.2, 0x8 - 8 bits,0xA - 10 bits, 0xB - 11 bits, 0xC - 12 bits, 0xD - 13 bits,0xE - 14 bits for DSC1.2, 0xF - 14 bits for DSC 1.2.PPS3[7:4] - bits_per_component: Bits per component for the originalpixels of the encoded picture.0x0 = 16bpc (allowed only when dsc_version_minor = 0x2)0x8 = 8bpc, 0xA = 10bpc, 0xC = 12bpc, 0xE = 14bpc (alsoallowed only when dsc_minor_version = 0x2)

pps_4

PPS4[1:0] -These are the most significant 2 bits ofcompressed BPP bits_per_pixel[9:0] syntax element.PPS4[2] - vbr_enable: 0 = VBR disabled, 1 = VBR enabledPPS4[3] - simple_422: Indicates if decoder drops samples toreconstruct the 4:2:2 picture.PPS4[4] - Convert_rgb: Indicates if DSC color space conversion isactive.PPS4[5] - blobk_pred_enable: Indicates if BP is used to code anygroups in picturePPS4[7:6] - Reseved bits

bits_per_pixel_low

PPS5[7:0] - This indicates the lower significant 8 bits ofthe compressed BPP bits_per_pixel[9:0] element.

pic_height

PPS6[7:0], PPS7[7:0] -pic_height: Specifies the number of pixel rowswithin the raster.

pic_width

PPS8[7:0], PPS9[7:0] - pic_width: Number of pixel columns withinthe raster.

slice_height

PPS10[7:0], PPS11[7:0] - Slice height in units of pixels.

slice_width

PPS12[7:0], PPS13[7:0] - Slice width in terms of pixels.

chunk_size

PPS14[7:0], PPS15[7:0] - Size in units of bytes of the chunksthat are used for slice multiplexing.

initial_xmit_delay_high

PPS16[1:0] - Most Significant two bits of initial transmission delay.It specifies the number of pixel times that the encoder waits beforetransmitting data from its rate buffer.PPS16[7:2] - Reserved

initial_xmit_delay_low

PPS17[7:0] - Least significant 8 bits of initial transmission delay.

initial_dec_delay

PPS18[7:0], PPS19[7:0] - Initial decoding delay which is the numberof pixel times that the decoder accumulates data in its rate bufferbefore starting to decode and output pixels.

pps20_reserved

PPS20[7:0] - Reserved

initial_scale_value

PPS21[5:0] - Initial rcXformScale factor used at beginningof a slice.PPS21[7:6] - Reserved

scale_increment_interval

PPS22[7:0], PPS23[7:0] - Number of group times between incrementingthe rcXformScale factor at end of a slice.

scale_decrement_interval_high

PPS24[3:0] - Higher 4 bits indicating number of group times betweendecrementing the rcXformScale factor at beginning of a slice.PPS24[7:4] - Reserved

scale_decrement_interval_low

PPS25[7:0] - Lower 8 bits of scale decrement interval

pps26_reserved

PPS26[7:0]

first_line_bpg_offset

PPS27[4:0] - Number of additional bits that are allocatedfor each group on first line of a slice.PPS27[7:5] - Reserved

nfl_bpg_offset

PPS28[7:0], PPS29[7:0] - Number of bits including frac bitsdeallocated for each group for groups after the first line of slice.

slice_bpg_offset

PPS30, PPS31[7:0] - Number of bits that are deallocated for eachgroup to enforce the slice constraint.

initial_offset

PPS32,33[7:0] - Initial value for rcXformOffset

final_offset

PPS34,35[7:0] - Maximum end-of-slice value for rcXformOffset

flatness_min_qp

PPS36[4:0] - Minimum QP at which flatness is signaled andflatness QP adjustment is made.PPS36[7:5] - Reserved

flatness_max_qp

PPS37[4:0] - Max QP at which flatness is signalled andthe flatness adjustment is made.PPS37[7:5] - Reserved

rc_model_size

PPS38,39[7:0] - Number of bits within RC Model.

rc_edge_factor

PPS40[3:0] - Ratio of current activity vs, previousactivity to determine presence of edge.PPS40[7:4] - Reserved

rc_quant_incr_limit0

PPS41[4:0] - QP threshold used in short term RCPPS41[7:5] - Reserved

rc_quant_incr_limit1

PPS42[4:0] - QP threshold used in short term RCPPS42[7:5] - Reserved

rc_tgt_offset

PPS43[3:0] - Lower end of the variability range around the targetbits per group that is allowed by short term RC.PPS43[7:4]- Upper end of the variability range around the targetbits per group that i allowed by short term rc.

rc_buf_thresh

PPS44[7:0] - PPS57[7:0] - Specifies the thresholds in RC model forthe 15 ranges defined by 14 thresholds.

rc_range_parameters

PPS58[7:0] - PPS87[7:0]Parameters that correspond to each of the 15 ranges.

native_422_420

PPS88[0] - 0 = Native 4:2:2 not used1 = Native 4:2:2 usedPPS88[1] - 0 = Native 4:2:0 not use1 = Native 4:2:0 usedPPS88[7:2] - Reserved 6 bits

second_line_bpg_offset

PPS89[4:0] - Additional bits/group budget for thesecond line of a slice in Native 4:2:0 mode.Set to 0 if DSC minor version is 1 or native420 is 0.PPS89[7:5] - Reserved

nsl_bpg_offset

PPS90[7:0], PPS91[7:0] - Number of bits that are deallocatedfor each group that is not in the second line of a slice.

second_line_offset_adj

PPS92[7:0], PPS93[7:0] - Used as offset adjustment for the secondline in Native 4:2:0 mode.

pps_long_94_reserved

PPS 94, 95, 96, 97 - Reserved

pps_long_98_reserved

PPS 98, 99, 100, 101 - Reserved

pps_long_102_reserved

PPS 102, 103, 104, 105 - Reserved

pps_long_106_reserved

PPS 106, 107, 108, 109 - reserved

pps_long_110_reserved

PPS 110, 111, 112, 113 - reserved

pps_long_114_reserved

PPS 114 - 117 - reserved

pps_long_118_reserved

PPS 118 - 121 - reserved

pps_long_122_reserved

PPS 122- 125 - reserved

pps_short_126_reserved

PPS 126, 127 - reserved

Description

The VESA DSC standard defines picture parameter set (PPS) which displaystream compression encoders must communicate to decoders.The PPS is encapsulated in 128 bytes (PPS 0 through PPS 127). The fields inthis structure are as per Table 4.1 in Vesa DSC specification v1.1/v1.2.The PPS fields that span over more than a byte should be stored in Big Endianformat.

structdrm_dsc_pps_infoframe

DSC infoframe carrying the Picture Parameter Set Metadata

Definition:

struct drm_dsc_pps_infoframe {    struct dp_sdp_header pps_header;    struct drm_dsc_picture_parameter_set pps_payload;};

Members

pps_header

Header for PPS as per DP SDP header format of typestructdp_sdp_header

pps_payload

PPS payload fields as per DSC specification Table 4-1as represented instructdrm_dsc_picture_parameter_set

Description

This structure represents the DSC PPS infoframe required to send the PictureParameter Set metadata required before enabling VESA Display StreamCompression. This is based on the DP Secondary Data Packet structure andcomprises of SDP Header as definedstructdp_sdp_header in drm_dp_helper.hand PPS payload defined instructdrm_dsc_picture_parameter_set.

voiddrm_dsc_dp_pps_header_init(structdp_sdp_header*pps_header)

Initializes the PPS Header for DisplayPort as per the DP 1.4 spec.

Parameters

structdp_sdp_header*pps_header

Secondary data packet header for DSC PictureParameter Set as defined instructdp_sdp_header

Description

DP 1.4 spec defines the secondary data packet for sending thepicture parameter infoframes from the source to the sink.This function populates the SDP header defined instructdp_sdp_header.

intdrm_dsc_dp_rc_buffer_size(u8rc_buffer_block_size,u8rc_buffer_size)

get rc buffer size in bytes

Parameters

u8rc_buffer_block_size

block size code, according to DPCD offset 62h

u8rc_buffer_size

number of blocks - 1, according to DPCD offset 63h

Return

buffer size in bytes, or 0 on invalid input

voiddrm_dsc_pps_payload_pack(structdrm_dsc_picture_parameter_set*pps_payload,conststructdrm_dsc_config*dsc_cfg)

Populates the DSC PPS

Parameters

structdrm_dsc_picture_parameter_set*pps_payload

Bitwise struct for DSC Picture Parameter Set. This is definedbystructdrm_dsc_picture_parameter_set

conststructdrm_dsc_config*dsc_cfg

DSC Configuration data filled by driver as defined bystructdrm_dsc_config

Description

DSC source device sends a picture parameter set (PPS) containing theinformation required by the sink to decode the compressed frame. Driverpopulates the DSC PPSstructusing the DSC configuration parameters inthe order expected by the DSC Display Sink device. For the DSC, the sinkdevice expects the PPS payload in big endian format for fieldsthat span more than 1 byte.

voiddrm_dsc_set_const_params(structdrm_dsc_config*vdsc_cfg)

Set DSC parameters considered typically constant across operation modes

Parameters

structdrm_dsc_config*vdsc_cfg

DSC Configuration data partially filled by driver

voiddrm_dsc_set_rc_buf_thresh(structdrm_dsc_config*vdsc_cfg)

Set thresholds for the RC model in accordance with the DSC 1.2 specification.

Parameters

structdrm_dsc_config*vdsc_cfg

DSC Configuration data partially filled by driver

intdrm_dsc_setup_rc_params(structdrm_dsc_config*vdsc_cfg,enumdrm_dsc_params_typetype)

Set parameters and limits for RC model in accordance with the DSC 1.1 or 1.2 specification and DSC C Model Required bits_per_pixel and bits_per_component to be set before calling this function.

Parameters

structdrm_dsc_config*vdsc_cfg

DSC Configuration data partially filled by driver

enumdrm_dsc_params_typetype

operating mode and standard to follow

Return

0 or -error code in case of an error

intdrm_dsc_compute_rc_parameters(structdrm_dsc_config*vdsc_cfg)

Write rate control parameters to the dsc configuration defined instructdrm_dsc_config in accordance with the DSC 1.2 specification. Some configuration fields must be present beforehand.

Parameters

structdrm_dsc_config*vdsc_cfg

DSC Configuration data partially filled by driver

u32drm_dsc_get_bpp_int(conststructdrm_dsc_config*vdsc_cfg)

Get integer bits per pixel value for the given DRM DSC config

Parameters

conststructdrm_dsc_config*vdsc_cfg

Pointer to DRM DSC config struct

Return

Integer BPP value

u8drm_dsc_initial_scale_value(conststructdrm_dsc_config*dsc)

Calculate the initial scale value for the given DSC config

Parameters

conststructdrm_dsc_config*dsc

Pointer to DRM DSC config struct

Return

Calculated initial scale value

u32drm_dsc_flatness_det_thresh(conststructdrm_dsc_config*dsc)

Calculate the flatness_det_thresh for the given DSC config

Parameters

conststructdrm_dsc_config*dsc

Pointer to DRM DSC config struct

Return

Calculated flatness det thresh value

voiddrm_dsc_dump_config(structdrm_printer*p,intindent,conststructdrm_dsc_config*cfg)

Dump the provided DSC configuration

Parameters

structdrm_printer*p

The printer used for output

intindent

Tab indentation level (max 5)

conststructdrm_dsc_config*cfg

DSC configuration to print

Description

Print the provided DSC configuration incfg.

Output Probing Helper Functions Reference

This library provides some helper code for output probing. It provides animplementation of the coredrm_connector_funcs.fill_modes interface withdrm_helper_probe_single_connector_modes().

It also provides support for polling connectors with a work item and forgeneric hotplug interrupt handling where the driver doesn’t or cannot keeptrack of a per-connector hpd interrupt.

This helper library can be used independently of the modeset helper library.Drivers can also overwrite different parts e.g. use their own hotplughandling code to avoid probing unrelated outputs.

The probe helpers share the function table structures with other displayhelper libraries. Seestructdrm_connector_helper_funcs for the details.

voiddrm_kms_helper_poll_enable(structdrm_device*dev)

re-enable output polling.

Parameters

structdrm_device*dev

drm_device

Description

This function re-enables the output polling work, after it has beentemporarily disabled usingdrm_kms_helper_poll_disable(), for example oversuspend/resume.

Drivers can call this helper from their device resume implementation. It isnot an error to call this even when output polling isn’t enabled.

If device polling was never initialized before, this call will trigger awarning and return.

Note that calls to enable and disable polling must be strictly ordered, whichis automatically the case when they’re only call from suspend/resumecallbacks.

voiddrm_kms_helper_poll_reschedule(structdrm_device*dev)

reschedule the output polling work

Parameters

structdrm_device*dev

drm_device

Description

This function reschedules the output polling work, after polling for aconnector has been enabled.

Drivers must call this helper after enabling polling for a connector bysettingDRM_CONNECTOR_POLL_CONNECT /DRM_CONNECTOR_POLL_DISCONNECT flagsin drm_connector::polled. Note that after disabling polling by clearing theseflags for a connector will stop the output polling work automatically ifthe polling is disabled for all other connectors as well.

The function can be called only after polling has been enabled by callingdrm_kms_helper_poll_init() /drm_kms_helper_poll_enable().

intdrm_helper_probe_detect(structdrm_connector*connector,structdrm_modeset_acquire_ctx*ctx,boolforce)

probe connector status

Parameters

structdrm_connector*connector

connector to probe

structdrm_modeset_acquire_ctx*ctx

acquire_ctx, or NULL to let this function handle locking.

boolforce

Whether destructive probe operations should be performed.

Description

This function calls the detect callbacks of the connector.This function returnsdrm_connector_status, orifctx is set, it might also return -EDEADLK.

intdrm_helper_probe_single_connector_modes(structdrm_connector*connector,uint32_tmaxX,uint32_tmaxY)

get complete set of display modes

Parameters

structdrm_connector*connector

connector to probe

uint32_tmaxX

max width for modes

uint32_tmaxY

max height for modes

Description

Based on the helper callbacks implemented byconnector in structdrm_connector_helper_funcs try to detect all valid modes. Modes will firstbe added to the connector’s probed_modes list, then culled (based on validityand themaxX,maxY parameters) and put into the normal modes list.

Intended to be used as a generic implementation of thedrm_connector_funcs.fill_modes() vfunc for drivers that use the CRTC helpersfor output mode filtering and detection.

The basic procedure is as follows

  1. All modes currently on the connector’s modes list are marked as stale

  2. New modes are added to the connector’s probed_modes list withdrm_mode_probed_add(). New modes start their life with status as OK.Modes are added from a single source using the following priority order.

    Finally modes specified via the kernel command line (video=...) areadded in addition to what the earlier probes produced(drm_helper_probe_add_cmdline_mode()). These modes are generatedusing the VESA GTF/CVT formulas.

  3. Modes are moved from the probed_modes list to the modes list. Potentialduplicates are merged together (seedrm_connector_list_update()).After this step the probed_modes list will be empty again.

  4. Any non-stale mode on the modes list then undergoes validation

  5. Any mode whose status is not OK is pruned from the connector’s modes list,accompanied by a debug message indicating the reason for the mode’srejection (seedrm_mode_prune_invalid()).

Return

The number of modes found onconnector.

voiddrm_kms_helper_hotplug_event(structdrm_device*dev)

fire off KMS hotplug events

Parameters

structdrm_device*dev

drm_device whose connector state changed

Description

This function fires off the uevent for userspace and also calls theclient hotplug function, which is most commonly used to inform the fbdevemulation code and allow it to update the fbcon output configuration.

Drivers should call this from their hotplug handling code when a change isdetected. Note that this function does not do any output detection of itsown, likedrm_helper_hpd_irq_event() does - this is assumed to be done by thedriver already.

This function must be called from process context with no modesetting locks held.

If only a single connector has changed, consider callingdrm_kms_helper_connector_hotplug_event() instead.

voiddrm_kms_helper_connector_hotplug_event(structdrm_connector*connector)

fire off a KMS connector hotplug event

Parameters

structdrm_connector*connector

drm_connector which has changed

Description

This is the same asdrm_kms_helper_hotplug_event(), except it fires a morefine-grained uevent for a single connector.

booldrm_kms_helper_is_poll_worker(void)

iscurrent task an output poll worker?

Parameters

void

no arguments

Description

Determine ifcurrent task is an output poll worker. This can be usedto select distinct code paths for output polling versus other contexts.

One use case is to avoid a deadlock between the output poll worker andthe autosuspend worker wherein the latter waits for polling to finishupon callingdrm_kms_helper_poll_disable(), while the former waits forruntime suspend to finish upon callingpm_runtime_get_sync() in aconnector ->detect hook.

voiddrm_kms_helper_poll_disable(structdrm_device*dev)

disable output polling

Parameters

structdrm_device*dev

drm_device

Description

This function disables the output polling work.

Drivers can call this helper from their device suspend implementation. It isnot an error to call this even when output polling isn’t enabled or alreadydisabled. Polling is re-enabled by callingdrm_kms_helper_poll_enable().

If however, the polling was never initialized, this call will trigger awarning and return.

Note that calls to enable and disable polling must be strictly ordered, whichis automatically the case when they’re only call from suspend/resumecallbacks.

voiddrm_kms_helper_poll_init(structdrm_device*dev)

initialize and enable output polling

Parameters

structdrm_device*dev

drm_device

Description

This function initializes and then also enables output polling support fordev. Drivers which do not have reliable hotplug support in hardware can usethis helper infrastructure to regularly poll such connectors for changes intheir connection state.

Drivers can control which connectors are polled by setting theDRM_CONNECTOR_POLL_CONNECT and DRM_CONNECTOR_POLL_DISCONNECT flags. Onconnectors where probing live outputs can result in visual distortion driversshould not set the DRM_CONNECTOR_POLL_DISCONNECT flag to avoid this.Connectors which have no flag or only DRM_CONNECTOR_POLL_HPD set arecompletely ignored by the polling logic.

Note that a connector can be both polled and probed from the hotplug handler,in case the hotplug interrupt is known to be unreliable.

voiddrm_kms_helper_poll_fini(structdrm_device*dev)

disable output polling and clean it up

Parameters

structdrm_device*dev

drm_device

voiddrmm_kms_helper_poll_init(structdrm_device*dev)

initialize and enable output polling

Parameters

structdrm_device*dev

drm_device

Description

This function initializes and then also enables output polling support fordev similar todrm_kms_helper_poll_init(). Polling will automatically becleaned up when the DRM device goes away.

Seedrm_kms_helper_poll_init() for more information.

booldrm_connector_helper_hpd_irq_event(structdrm_connector*connector)

hotplug processing

Parameters

structdrm_connector*connector

drm_connector

Description

Drivers can use this helper function to run a detect cycle on a connectorwhich has the DRM_CONNECTOR_POLL_HPD flag set in itspolled member.

This helper function is useful for drivers which can track hotpluginterrupts for a single connector. Drivers that want to send ahotplug event for all connectors or can’t track hotplug interruptsper connector need to usedrm_helper_hpd_irq_event().

This function must be called from process context with no modesetting locks held.

Note that a connector can be both polled and probed from the hotplughandler, in case the hotplug interrupt is known to be unreliable.

Return

A boolean indicating whether the connector status changed or not

booldrm_helper_hpd_irq_event(structdrm_device*dev)

hotplug processing

Parameters

structdrm_device*dev

drm_device

Description

Drivers can use this helper function to run a detect cycle on all connectorswhich have the DRM_CONNECTOR_POLL_HPD flag set in theirpolled member. Allother connectors are ignored, which is useful to avoid reprobing fixedpanels.

This helper function is useful for drivers which can’t or don’t track hotpluginterrupts for each connector.

Drivers which support hotplug interrupts for each connector individually andwhich have a more fine-grained detect logic can usedrm_connector_helper_hpd_irq_event(). Alternatively, they should bypass thiscode and directly calldrm_kms_helper_hotplug_event() in case the connectorstate changed.

This function must be called from process context with no modesetting locks held.

Note that a connector can be both polled and probed from the hotplug handler,in case the hotplug interrupt is known to be unreliable.

Return

A boolean indicating whether the connector status changed or not

enumdrm_mode_statusdrm_crtc_helper_mode_valid_fixed(structdrm_crtc*crtc,conststructdrm_display_mode*mode,conststructdrm_display_mode*fixed_mode)

Validates a display mode

Parameters

structdrm_crtc*crtc

the crtc

conststructdrm_display_mode*mode

the mode to validate

conststructdrm_display_mode*fixed_mode

the display hardware’s mode

Return

MODE_OK on success, or another mode-status code otherwise.

intdrm_connector_helper_get_modes_fixed(structdrm_connector*connector,conststructdrm_display_mode*fixed_mode)

Duplicates a display mode for a connector

Parameters

structdrm_connector*connector

the connector

conststructdrm_display_mode*fixed_mode

the display hardware’s mode

Description

This function duplicates a display modes for a connector. Drivers for hardwarethat only supports a single fixed mode can use this function in their connector’sget_modes helper.

Return

The number of created modes.

intdrm_connector_helper_get_modes(structdrm_connector*connector)

Read EDID and update connector.

Parameters

structdrm_connector*connector

The connector

Description

Read the EDID usingdrm_edid_read() (which requires that connector->ddc isset), and update the connector using the EDID.

This can be used as the “default” connector helper .get_modes() hook if thedriver does not need any special processing. This is sets the example whatcustom .get_modes() hooks should do regarding EDID read and connector update.

Return

Number of modes.

intdrm_connector_helper_tv_get_modes(structdrm_connector*connector)

Fills the modes availables to a TV connector

Parameters

structdrm_connector*connector

The connector

Description

Fills the available modes for a TV connector based on the supportedTV modes, and the default mode expressed by the kernel command line.

This can be used as the default TV connector helper .get_modes() hookif the driver does not need any special processing.

Return

The number of modes added to the connector.

intdrm_connector_helper_detect_from_ddc(structdrm_connector*connector,structdrm_modeset_acquire_ctx*ctx,boolforce)

Read EDID and detect connector status.

Parameters

structdrm_connector*connector

The connector

structdrm_modeset_acquire_ctx*ctx

Acquire context

boolforce

Perform screen-destructive operations, if necessary

Description

Detects the connector status by reading the EDID usingdrm_probe_ddc(),which requires connector->ddc to be set. Returns connector_status_connectedon success or connector_status_disconnected on failure.

Return

The connector status as defined byenumdrm_connector_status.

EDID Helper Functions Reference

constchar*drm_edid_decode_mfg_id(u16mfg_id,charvend[4])

Decode the manufacturer ID

Parameters

u16mfg_id

The manufacturer ID

charvend[4]

A 4-byte buffer to store the 3-letter vendor string plus a ‘0’termination

drm_edid_encode_panel_id

drm_edid_encode_panel_id(vend_chr_0,vend_chr_1,vend_chr_2,product_id)

Encode an ID for matching againstdrm_edid_get_panel_id()

Parameters

vend_chr_0

First character of the vendor string.

vend_chr_1

Second character of the vendor string.

vend_chr_2

Third character of the vendor string.

product_id

The 16-bit product ID.

Description

This is a macro so that it can be calculated at compile time and usedas an initializer.

For instance:

drm_edid_encode_panel_id(‘B’, ‘O’, ‘E’, 0x2d08) => 0x09e52d08

Return

a 32-bit ID per panel.

voiddrm_edid_decode_panel_id(u32panel_id,charvend[4],u16*product_id)

Decode a panel ID fromdrm_edid_encode_panel_id()

Parameters

u32panel_id

The panel ID to decode.

charvend[4]

A 4-byte buffer to store the 3-letter vendor string plus a ‘0’termination

u16*product_id

The product ID will be returned here.

Description

For instance, after:

drm_edid_decode_panel_id(0x09e52d08, vend,product_id)

These will be true:

vend[0] = ‘B’vend[1] = ‘O’vend[2] = ‘E’vend[3] = ‘0’product_id = 0x2d08

intdrm_edid_header_is_valid(constvoid*_edid)

sanity check the header of the base EDID block

Parameters

constvoid*_edid

pointer to raw base EDID block

Description

Sanity check the header of the base EDID block.

Return

8 if the header is perfect, down to 0 if it’s totally wrong.

booldrm_edid_is_valid(structedid*edid)

sanity check EDID data

Parameters

structedid*edid

EDID data

Description

Sanity-check an entire EDID record (including extensions)

Return

True if the EDID data is valid, false otherwise.

booldrm_edid_valid(conststructdrm_edid*drm_edid)

sanity check EDID data

Parameters

conststructdrm_edid*drm_edid

EDID data

Description

Sanity check an EDID. Cross check block count against allocated size andchecksum the blocks.

Return

True if the EDID data is valid, false otherwise.

intdrm_edid_override_connector_update(structdrm_connector*connector)

add modes from override/firmware EDID

Parameters

structdrm_connector*connector

connector we’re probing

Description

Add modes from the override/firmware EDID, if available. Only to be used fromdrm_helper_probe_single_connector_modes() as a fallback for when DDC probefailed duringdrm_get_edid() and caused the override/firmware EDID to beskipped.

Return

The number of modes added or 0 if we couldn’t find any.

conststructedid*drm_edid_raw(conststructdrm_edid*drm_edid)

Get a pointer to the raw EDID data.

Parameters

conststructdrm_edid*drm_edid

drm_edid container

Description

Get a pointer to the raw EDID data.

This is for transition only. Avoid using this like the plague.

Return

Pointer to raw EDID data.

conststructdrm_edid*drm_edid_alloc(constvoid*edid,size_tsize)

Allocate a new drm_edid container

Parameters

constvoid*edid

Pointer to raw EDID data

size_tsize

Size of memory allocated for EDID

Description

Allocate a new drm_edid container. Do not calculate edid size from edid, passthe actual size that has been allocated for the data. There is no validationof the raw EDID data against the size, but at least the EDID base block mustfit in the buffer.

The returned pointer must be freed usingdrm_edid_free().

Return

drm_edid container, or NULL on errors

conststructdrm_edid*drm_edid_dup(conststructdrm_edid*drm_edid)

Duplicate a drm_edid container

Parameters

conststructdrm_edid*drm_edid

EDID to duplicate

Description

The returned pointer must be freed usingdrm_edid_free().

Return

drm_edid container copy, or NULL on errors

voiddrm_edid_free(conststructdrm_edid*drm_edid)

Free the drm_edid container

Parameters

conststructdrm_edid*drm_edid

EDID to free

booldrm_probe_ddc(structi2c_adapter*adapter)

probe DDC presence

Parameters

structi2c_adapter*adapter

I2C adapter to probe

Return

True on success, false on failure.

structedid*drm_get_edid(structdrm_connector*connector,structi2c_adapter*adapter)

get EDID data, if available

Parameters

structdrm_connector*connector

connector we’re probing

structi2c_adapter*adapter

I2C adapter to use for DDC

Description

Poke the given I2C channel to grab EDID data if possible. If found,attach it to the connector.

Return

Pointer to valid EDID or NULL if we couldn’t find any.

conststructdrm_edid*drm_edid_read_custom(structdrm_connector*connector,read_block_fnread_block,void*context)

Read EDID data using given EDID block read function

Parameters

structdrm_connector*connector

Connector to use

read_block_fnread_block

EDID block read function

void*context

Private data passed to the block read function

Description

When the I2C adapter connected to the DDC bus is hidden behind a device thatexposes a different interface to read EDID blocks this function can be usedto get EDID data using a custom block read function.

As in the general case the DDC bus is accessible by the kernel at the I2Clevel, drivers must make all reasonable efforts to expose it as an I2Cadapter and usedrm_edid_read() ordrm_edid_read_ddc() instead of abusingthis function.

The EDID may be overridden using debugfs override_edid or firmware EDID(drm_edid_load_firmware() and drm.edid_firmware parameter), in this priorityorder. Having either of them bypasses actual EDID reads.

The returned pointer must be freed usingdrm_edid_free().

Return

Pointer to EDID, or NULL if probe/read failed.

conststructdrm_edid*drm_edid_read_ddc(structdrm_connector*connector,structi2c_adapter*adapter)

Read EDID data using given I2C adapter

Parameters

structdrm_connector*connector

Connector to use

structi2c_adapter*adapter

I2C adapter to use for DDC

Description

Read EDID using the given I2C adapter.

The EDID may be overridden using debugfs override_edid or firmware EDID(drm_edid_load_firmware() and drm.edid_firmware parameter), in this priorityorder. Having either of them bypasses actual EDID reads.

Prefer initializing connector->ddc withdrm_connector_init_with_ddc() andusingdrm_edid_read() instead of this function.

The returned pointer must be freed usingdrm_edid_free().

Return

Pointer to EDID, or NULL if probe/read failed.

conststructdrm_edid*drm_edid_read(structdrm_connector*connector)

Read EDID data using connector’s I2C adapter

Parameters

structdrm_connector*connector

Connector to use

Description

Read EDID using the connector’s I2C adapter.

The EDID may be overridden using debugfs override_edid or firmware EDID(drm_edid_load_firmware() and drm.edid_firmware parameter), in this priorityorder. Having either of them bypasses actual EDID reads.

The returned pointer must be freed usingdrm_edid_free().

Return

Pointer to EDID, or NULL if probe/read failed.

voiddrm_edid_get_product_id(conststructdrm_edid*drm_edid,structdrm_edid_product_id*id)

Get the vendor and product identification

Parameters

conststructdrm_edid*drm_edid

EDID

structdrm_edid_product_id*id

Where to place the product id

voiddrm_edid_print_product_id(structdrm_printer*p,conststructdrm_edid_product_id*id,boolraw)

Print decoded product id to printer

Parameters

structdrm_printer*p

drm printer

conststructdrm_edid_product_id*id

EDID product id

boolraw

If true, also print the raw hex

Description

See VESA E-EDID 1.4 section 3.4.

u32drm_edid_get_panel_id(conststructdrm_edid*drm_edid)

Get a panel’s ID from EDID

Parameters

conststructdrm_edid*drm_edid

EDID that contains panel ID.

Description

This function uses the first block of the EDID of a panel and (assumingthat the EDID is valid) extracts the ID out of it. The ID is a 32-bit value(16 bits of manufacturer ID and 16 bits of per-manufacturer ID) that’ssupposed to be different for each different modem of panel.

Return

A 32-bit ID that should be different for each make/model of panel.See the functionsdrm_edid_encode_panel_id() anddrm_edid_decode_panel_id() for some details on the structure of thisID. Return 0 if the EDID size is less than a base block.

conststructdrm_edid*drm_edid_read_base_block(structi2c_adapter*adapter)

Get a panel’s EDID base block

Parameters

structi2c_adapter*adapter

I2C adapter to use for DDC

Description

This function returns the drm_edid containing the first block of the EDID ofa panel.

This function is intended to be used during early probing on devices wheremore than one panel might be present. Because of its intended use it mustassume that the EDID of the panel is correct, at least as far as the baseblock is concerned (in other words, we don’t process any overrides here).

Caller should calldrm_edid_free() after use.

NOTE

it’s expected that this function anddrm_do_get_edid() will bothbe read the EDID, but there is no caching between them. Since we’re onlyreading the first block, hopefully this extra overhead won’t be too big.

WARNING: Only use this function when the connector is unknown. For example,during the early probe of panel. The EDID read from the function is temporaryand should be replaced by the full EDID returned from other drm_edid_read.

Return

Pointer to allocated EDID base block, or NULL on any failure.

structedid*drm_get_edid_switcheroo(structdrm_connector*connector,structi2c_adapter*adapter)

get EDID data for a vga_switcheroo output

Parameters

structdrm_connector*connector

connector we’re probing

structi2c_adapter*adapter

I2C adapter to use for DDC

Description

Wrapper arounddrm_get_edid() for laptops with dual GPUs using one set ofoutputs. The wrapper adds the requisite vga_switcheroo calls to temporarilyswitch DDC to the GPU which is retrieving EDID.

Return

Pointer to valid EDID orNULL if we couldn’t find any.

conststructdrm_edid*drm_edid_read_switcheroo(structdrm_connector*connector,structi2c_adapter*adapter)

get EDID data for a vga_switcheroo output

Parameters

structdrm_connector*connector

connector we’re probing

structi2c_adapter*adapter

I2C adapter to use for DDC

Description

Wrapper arounddrm_edid_read_ddc() for laptops with dual GPUs using one setof outputs. The wrapper adds the requisite vga_switcheroo calls totemporarily switch DDC to the GPU which is retrieving EDID.

Return

Pointer to valid EDID orNULL if we couldn’t find any.

structedid*drm_edid_duplicate(conststructedid*edid)

duplicate an EDID and the extensions

Parameters

conststructedid*edid

EDID to duplicate

Return

Pointer to duplicated EDID or NULL on allocation failure.

u8drm_match_cea_mode(conststructdrm_display_mode*to_match)

look for a CEA mode matching given mode

Parameters

conststructdrm_display_mode*to_match

display mode

Return

The CEA Video ID (VIC) of the mode or 0 if it isn’t a CEA-861mode.

structdrm_display_mode*drm_display_mode_from_cea_vic(structdrm_device*dev,u8video_code)

return a mode for CEA VIC

Parameters

structdrm_device*dev

DRM device

u8video_code

CEA VIC of the mode

Description

Creates a new mode matching the specified CEA VIC.

Return

A new drm_display_mode on success or NULL on failure

booldrm_edid_match(conststructdrm_edid*drm_edid,conststructdrm_edid_ident*ident)

match drm_edid with given identity

Parameters

conststructdrm_edid*drm_edid

EDID

conststructdrm_edid_ident*ident

the EDID identity to match with

Description

Check if the EDID matches with the given identity.

Return

True if the given identity matched with EDID, false otherwise.

voiddrm_edid_get_monitor_name(conststructedid*edid,char*name,intbufsize)

fetch the monitor name from the edid

Parameters

conststructedid*edid

monitor EDID information

char*name

pointer to a character array to hold the name of the monitor

intbufsize

The size of the name buffer (should be at least 14 chars.)

intdrm_edid_to_sad(conststructedid*edid,structcea_sad**sads)

extracts SADs from EDID

Parameters

conststructedid*edid

EDID to parse

structcea_sad**sads

pointer that will be set to the extracted SADs

Description

Looks for CEA EDID block and extracts SADs (Short Audio Descriptors) from it.

Note

The returned pointer needs to be freed usingkfree().

Return

The number of found SADs or negative number on error.

intdrm_edid_to_speaker_allocation(conststructedid*edid,u8**sadb)

extracts Speaker Allocation Data Blocks from EDID

Parameters

conststructedid*edid

EDID to parse

u8**sadb

pointer to the speaker block

Description

Looks for CEA EDID block and extracts the Speaker Allocation Data Block from it.

Note

The returned pointer needs to be freed usingkfree().

Return

The number of found Speaker Allocation Blocks or negative number onerror.

intdrm_av_sync_delay(structdrm_connector*connector,conststructdrm_display_mode*mode)

compute the HDMI/DP sink audio-video sync delay

Parameters

structdrm_connector*connector

connector associated with the HDMI/DP sink

conststructdrm_display_mode*mode

the display mode

Return

The HDMI/DP sink’s audio-video sync delay in milliseconds or 0 ifthe sink doesn’t support audio or video.

booldrm_detect_hdmi_monitor(conststructedid*edid)

detect whether monitor is HDMI

Parameters

conststructedid*edid

monitor EDID information

Description

Parse the CEA extension according to CEA-861-B.

Drivers that have added the modes parsed from EDID to drm_display_infoshould usedrm_display_info.is_hdmi instead of calling this function.

Return

True if the monitor is HDMI, false if not or unknown.

booldrm_detect_monitor_audio(conststructedid*edid)

check monitor audio capability

Parameters

conststructedid*edid

EDID block to scan

Description

Monitor should have CEA extension block.If monitor has ‘basic audio’, but no CEA audio blocks, it’s ‘basicaudio’ only. If there is any audio extension block and supportedaudio format, assume at least ‘basic audio’ support, even if ‘basicaudio’ is not defined in EDID.

Return

True if the monitor supports audio, false otherwise.

enumhdmi_quantization_rangedrm_default_rgb_quant_range(conststructdrm_display_mode*mode)

default RGB quantization range

Parameters

conststructdrm_display_mode*mode

display mode

Description

Determine the default RGB quantization range for the mode,as specified in CEA-861.

Return

The default RGB quantization range for the mode

intdrm_edid_connector_update(structdrm_connector*connector,conststructdrm_edid*drm_edid)

Update connector information from EDID

Parameters

structdrm_connector*connector

Connector

conststructdrm_edid*drm_edid

EDID

Description

Update the connector display info, ELD, HDR metadata, relevant properties,etc. from the passed in EDID.

If EDID is NULL, reset the information.

Must be called before callingdrm_edid_connector_add_modes().

Return

0 on success, negative error on errors.

intdrm_edid_connector_add_modes(structdrm_connector*connector)

Update probed modes from the EDID property

Parameters

structdrm_connector*connector

Connector

Description

Add the modes from the previously updated EDID property to the connectorprobed modes list.

drm_edid_connector_update() must have been called before this to update theEDID property.

Return

The number of modes added, or 0 if we couldn’t find any.

intdrm_connector_update_edid_property(structdrm_connector*connector,conststructedid*edid)

update the edid property of a connector

Parameters

structdrm_connector*connector

drm connector

conststructedid*edid

new value of the edid property

Description

This function creates a new blob modeset object and assigns its id to theconnector’s edid property.Since we also parse tile information from EDID’s displayID block, we alsoset the connector’s tile property here. Seedrm_connector_set_tile_property()for more details.

This function is deprecated. Usedrm_edid_connector_update() instead.

Return

Zero on success, negative errno on failure.

intdrm_add_edid_modes(structdrm_connector*connector,structedid*edid)

add modes from EDID data, if available

Parameters

structdrm_connector*connector

connector we’re probing

structedid*edid

EDID data

Description

Add the specified modes to the connector’s mode list. Also fills out thedrm_display_info structure and ELD inconnector with any information whichcan be derived from the edid.

This function is deprecated. Usedrm_edid_connector_add_modes() instead.

Return

The number of modes added or 0 if we couldn’t find any.

intdrm_add_modes_noedid(structdrm_connector*connector,unsignedinthdisplay,unsignedintvdisplay)

add modes for the connectors without EDID

Parameters

structdrm_connector*connector

connector we’re probing

unsignedinthdisplay

the horizontal display limit

unsignedintvdisplay

the vertical display limit

Description

Add the specified modes to the connector’s mode list. Only when thehdisplay/vdisplay is not beyond the given limit, it will be added.

Return

The number of modes added or 0 if we couldn’t find any.

intdrm_hdmi_avi_infoframe_from_display_mode(structhdmi_avi_infoframe*frame,conststructdrm_connector*connector,conststructdrm_display_mode*mode)

fill an HDMI AVI infoframe with data from a DRM display mode

Parameters

structhdmi_avi_infoframe*frame

HDMI AVI infoframe

conststructdrm_connector*connector

the connector

conststructdrm_display_mode*mode

DRM display mode

Return

0 on success or a negative error code on failure.

voiddrm_hdmi_avi_infoframe_quant_range(structhdmi_avi_infoframe*frame,conststructdrm_connector*connector,conststructdrm_display_mode*mode,enumhdmi_quantization_rangergb_quant_range)

fill the HDMI AVI infoframe quantization range information

Parameters

structhdmi_avi_infoframe*frame

HDMI AVI infoframe

conststructdrm_connector*connector

the connector

conststructdrm_display_mode*mode

DRM display mode

enumhdmi_quantization_rangergb_quant_range

RGB quantization range (Q)

intdrm_hdmi_vendor_infoframe_from_display_mode(structhdmi_vendor_infoframe*frame,conststructdrm_connector*connector,conststructdrm_display_mode*mode)

fill an HDMI infoframe with data from a DRM display mode

Parameters

structhdmi_vendor_infoframe*frame

HDMI vendor infoframe

conststructdrm_connector*connector

the connector

conststructdrm_display_mode*mode

DRM display mode

Description

Note that there’s is a need to send HDMI vendor infoframes only when using a4k or stereoscopic 3D mode. So when giving any other mode as input thisfunction will return -EINVAL, error that can be safely ignored.

Return

0 on success or a negative error code on failure.

booldrm_edid_is_digital(conststructdrm_edid*drm_edid)

is digital?

Parameters

conststructdrm_edid*drm_edid

The EDID

Description

Return true if input is digital.

intdrm_eld_mnl(constu8*eld)

Get ELD monitor name length in bytes.

Parameters

constu8*eld

pointer to an eld memory structure with mnl set

constu8*drm_eld_sad(constu8*eld)

Get ELD SAD structures.

Parameters

constu8*eld

pointer to an eld memory structure with sad_count set

intdrm_eld_sad_count(constu8*eld)

Get ELD SAD count.

Parameters

constu8*eld

pointer to an eld memory structure with sad_count set

intdrm_eld_calc_baseline_block_size(constu8*eld)

Calculate baseline block size in bytes

Parameters

constu8*eld

pointer to an eld memory structure with mnl and sad_count set

Description

This is a helper for determining the payload size of the baseline block, inbytes, for e.g. setting the Baseline_ELD_Len field in the ELD header block.

intdrm_eld_size(constu8*eld)

Get ELD size in bytes

Parameters

constu8*eld

pointer to a complete eld memory structure

Description

The returned value does not include the vendor block. It’s vendor specific,and comprises of the remaining bytes in the ELD memory buffer afterdrm_eld_size() bytes of header and baseline block.

The returned value is guaranteed to be a multiple of 4.

u8drm_eld_get_spk_alloc(constu8*eld)

Get speaker allocation

Parameters

constu8*eld

pointer to an ELD memory structure

Description

The returned value is the speakers mask. User has to useDRM_ELD_SPEAKERfield definitions to identify speakers.

u8drm_eld_get_conn_type(constu8*eld)

Get device type hdmi/dp connected

Parameters

constu8*eld

pointer to an ELD memory structure

Description

The caller need to useDRM_ELD_CONN_TYPE_HDMI orDRM_ELD_CONN_TYPE_DP toidentify the display type connected.

intdrm_eld_sad_get(constu8*eld,intsad_index,structcea_sad*cta_sad)

get SAD from ELD tostructcea_sad

Parameters

constu8*eld

ELD buffer

intsad_index

SAD index

structcea_sad*cta_sad

destinationstructcea_sad

Return

0 on success, or negative on errors

intdrm_eld_sad_set(u8*eld,intsad_index,conststructcea_sad*cta_sad)

set SAD to ELD fromstructcea_sad

Parameters

u8*eld

ELD buffer

intsad_index

SAD index

conststructcea_sad*cta_sad

sourcestructcea_sad

Return

0 on success, or negative on errors

SCDC Helper Functions Reference

Status and Control Data Channel (SCDC) is a mechanism introduced by theHDMI 2.0 specification. It is a point-to-point protocol that allows theHDMI source and HDMI sink to exchange data. The same I2C interface thatis used to access EDID serves as the transport mechanism for SCDC.

Note: The SCDC status is going to be lost when the display isdisconnected. This can happen physically when the user disconnectsthe cable, but also when a display is switched on (such as waking upa TV).

This is further complicated by the fact that, upon a disconnection /reconnection, KMS won’t change the mode on its own. This means thatone can’t just rely on setting the SCDC status on enable, but alsohas to track the connector status changes using interrupts andrestore the SCDC status. The typical solution for this is to trigger anempty modeset in drm_connector_helper_funcs.detect_ctx(), like what vc4 doesinvc4_hdmi_reset_link().

intdrm_scdc_readb(structi2c_adapter*adapter,u8offset,u8*value)

read a single byte from SCDC

Parameters

structi2c_adapter*adapter

I2C adapter

u8offset

offset of register to read

u8*value

return location for the register value

Description

Reads a single byte from SCDC. This is a convenience wrapper around thedrm_scdc_read() function.

Return

0 on success or a negative error code on failure.

intdrm_scdc_writeb(structi2c_adapter*adapter,u8offset,u8value)

write a single byte to SCDC

Parameters

structi2c_adapter*adapter

I2C adapter

u8offset

offset of register to read

u8value

return location for the register value

Description

Writes a single byte to SCDC. This is a convenience wrapper around thedrm_scdc_write() function.

Return

0 on success or a negative error code on failure.

ssize_tdrm_scdc_read(structi2c_adapter*adapter,u8offset,void*buffer,size_tsize)

read a block of data from SCDC

Parameters

structi2c_adapter*adapter

I2C controller

u8offset

start offset of block to read

void*buffer

return location for the block to read

size_tsize

size of the block to read

Description

Reads a block of data from SCDC, starting at a given offset.

Return

0 on success, negative error code on failure.

ssize_tdrm_scdc_write(structi2c_adapter*adapter,u8offset,constvoid*buffer,size_tsize)

write a block of data to SCDC

Parameters

structi2c_adapter*adapter

I2C controller

u8offset

start offset of block to write

constvoid*buffer

block of data to write

size_tsize

size of the block to write

Description

Writes a block of data to SCDC, starting at a given offset.

Return

0 on success, negative error code on failure.

booldrm_scdc_get_scrambling_status(structdrm_connector*connector)

what is status of scrambling?

Parameters

structdrm_connector*connector

connector

Description

Reads the scrambler status over SCDC, and checks thescrambling status.

Return

True if the scrambling is enabled, false otherwise.

booldrm_scdc_set_scrambling(structdrm_connector*connector,boolenable)

enable scrambling

Parameters

structdrm_connector*connector

connector

boolenable

bool to indicate if scrambling is to be enabled/disabled

Description

Writes the TMDS config register over SCDC channel, and:enables scrambling when enable = 1disables scrambling when enable = 0

Return

True if scrambling is set/reset successfully, false otherwise.

booldrm_scdc_set_high_tmds_clock_ratio(structdrm_connector*connector,boolset)

set TMDS clock ratio

Parameters

structdrm_connector*connector

connector

boolset

ret or reset the high clock ratio

Description

TMDS clock ratio calculations go like this:

TMDS character = 10 bit TMDS encoded value

TMDS character rate = The rate at which TMDS characters aretransmitted (Mcsc)

TMDS bit rate = 10x TMDS character rate

As per the spec:

TMDS clock rate for pixel clock < 340 MHz = 1x the characterrate = 1/10 pixel clock rate

TMDS clock rate for pixel clock > 340 MHz = 0.25x the characterrate = 1/40 pixel clock rate

Writes to the TMDS config register over SCDC channel, and:

sets TMDS clock ratio to 1/40 when set = 1

sets TMDS clock ratio to 1/10 when set = 0

Return

True if write is successful, false otherwise.

HDMI Infoframes Helper Reference

Strictly speaking this is not a DRM helper library but generally usableby any driver interfacing with HDMI outputs like v4l or alsa drivers.But it nicely fits into the overall topic of mode setting helperlibraries and hence is also included here.

structhdr_sink_metadata

HDR sink metadata

Definition:

struct hdr_sink_metadata {    __u32 metadata_type;    union {        struct hdr_static_metadata hdmi_type1;    };};

Members

metadata_type

Static_Metadata_Descriptor_ID.

{unnamed_union}

anonymous

hdmi_type1

HDR Metadata Infoframe.

Description

Metadata Information read from Sink’s EDID

unionhdmi_infoframe

overallunionof all abstract infoframe representations

Definition:

union hdmi_infoframe {    struct hdmi_any_infoframe any;    struct hdmi_avi_infoframe avi;    struct hdmi_spd_infoframe spd;    union hdmi_vendor_any_infoframe vendor;    struct hdmi_audio_infoframe audio;    struct hdmi_drm_infoframe drm;};

Members

any

generic infoframe

avi

avi infoframe

spd

spd infoframe

vendor

unionof all vendor infoframes

audio

audio infoframe

drm

Dynamic Range and Mastering infoframe

Description

This is used by the generic pack function. This works since all infoframeshave the same header which also indicates which type of infoframe should bepacked.

voidhdmi_avi_infoframe_init(structhdmi_avi_infoframe*frame)

initialize an HDMI AVI infoframe

Parameters

structhdmi_avi_infoframe*frame

HDMI AVI infoframe

inthdmi_avi_infoframe_check(structhdmi_avi_infoframe*frame)

check a HDMI AVI infoframe

Parameters

structhdmi_avi_infoframe*frame

HDMI AVI infoframe

Description

Validates that the infoframe is consistent and updates derived fields(eg. length) based on other fields.

Returns 0 on success or a negative error code on failure.

ssize_thdmi_avi_infoframe_pack_only(conststructhdmi_avi_infoframe*frame,void*buffer,size_tsize)

write HDMI AVI infoframe to binary buffer

Parameters

conststructhdmi_avi_infoframe*frame

HDMI AVI infoframe

void*buffer

destination buffer

size_tsize

size of buffer

Description

Packs the information contained in theframe structure into a binaryrepresentation that can be written into the corresponding controllerregisters. Also computes the checksum as required by section 5.3.5 ofthe HDMI 1.4 specification.

Returns the number of bytes packed into the binary buffer or a negativeerror code on failure.

ssize_thdmi_avi_infoframe_pack(structhdmi_avi_infoframe*frame,void*buffer,size_tsize)

check a HDMI AVI infoframe, and write it to binary buffer

Parameters

structhdmi_avi_infoframe*frame

HDMI AVI infoframe

void*buffer

destination buffer

size_tsize

size of buffer

Description

Validates that the infoframe is consistent and updates derived fields(eg. length) based on other fields, after which it packs the informationcontained in theframe structure into a binary representation thatcan be written into the corresponding controller registers. This functionalso computes the checksum as required by section 5.3.5 of the HDMI 1.4specification.

Returns the number of bytes packed into the binary buffer or a negativeerror code on failure.

inthdmi_spd_infoframe_init(structhdmi_spd_infoframe*frame,constchar*vendor,constchar*product)

initialize an HDMI SPD infoframe

Parameters

structhdmi_spd_infoframe*frame

HDMI SPD infoframe

constchar*vendor

vendor string

constchar*product

product string

Description

Returns 0 on success or a negative error code on failure.

inthdmi_spd_infoframe_check(structhdmi_spd_infoframe*frame)

check a HDMI SPD infoframe

Parameters

structhdmi_spd_infoframe*frame

HDMI SPD infoframe

Description

Validates that the infoframe is consistent and updates derived fields(eg. length) based on other fields.

Returns 0 on success or a negative error code on failure.

ssize_thdmi_spd_infoframe_pack_only(conststructhdmi_spd_infoframe*frame,void*buffer,size_tsize)

write HDMI SPD infoframe to binary buffer

Parameters

conststructhdmi_spd_infoframe*frame

HDMI SPD infoframe

void*buffer

destination buffer

size_tsize

size of buffer

Description

Packs the information contained in theframe structure into a binaryrepresentation that can be written into the corresponding controllerregisters. Also computes the checksum as required by section 5.3.5 ofthe HDMI 1.4 specification.

Returns the number of bytes packed into the binary buffer or a negativeerror code on failure.

ssize_thdmi_spd_infoframe_pack(structhdmi_spd_infoframe*frame,void*buffer,size_tsize)

check a HDMI SPD infoframe, and write it to binary buffer

Parameters

structhdmi_spd_infoframe*frame

HDMI SPD infoframe

void*buffer

destination buffer

size_tsize

size of buffer

Description

Validates that the infoframe is consistent and updates derived fields(eg. length) based on other fields, after which it packs the informationcontained in theframe structure into a binary representation thatcan be written into the corresponding controller registers. This functionalso computes the checksum as required by section 5.3.5 of the HDMI 1.4specification.

Returns the number of bytes packed into the binary buffer or a negativeerror code on failure.

inthdmi_audio_infoframe_init(structhdmi_audio_infoframe*frame)

initialize an HDMI audio infoframe

Parameters

structhdmi_audio_infoframe*frame

HDMI audio infoframe

Description

Returns 0 on success or a negative error code on failure.

inthdmi_audio_infoframe_check(conststructhdmi_audio_infoframe*frame)

check a HDMI audio infoframe

Parameters

conststructhdmi_audio_infoframe*frame

HDMI audio infoframe

Description

Validates that the infoframe is consistent and updates derived fields(eg. length) based on other fields.

Returns 0 on success or a negative error code on failure.

ssize_thdmi_audio_infoframe_pack_only(conststructhdmi_audio_infoframe*frame,void*buffer,size_tsize)

write HDMI audio infoframe to binary buffer

Parameters

conststructhdmi_audio_infoframe*frame

HDMI audio infoframe

void*buffer

destination buffer

size_tsize

size of buffer

Description

Packs the information contained in theframe structure into a binaryrepresentation that can be written into the corresponding controllerregisters. Also computes the checksum as required by section 5.3.5 ofthe HDMI 1.4 specification.

Returns the number of bytes packed into the binary buffer or a negativeerror code on failure.

ssize_thdmi_audio_infoframe_pack(structhdmi_audio_infoframe*frame,void*buffer,size_tsize)

check a HDMI Audio infoframe, and write it to binary buffer

Parameters

structhdmi_audio_infoframe*frame

HDMI Audio infoframe

void*buffer

destination buffer

size_tsize

size of buffer

Description

Validates that the infoframe is consistent and updates derived fields(eg. length) based on other fields, after which it packs the informationcontained in theframe structure into a binary representation thatcan be written into the corresponding controller registers. This functionalso computes the checksum as required by section 5.3.5 of the HDMI 1.4specification.

Returns the number of bytes packed into the binary buffer or a negativeerror code on failure.

ssize_thdmi_audio_infoframe_pack_for_dp(conststructhdmi_audio_infoframe*frame,structdp_sdp*sdp,u8dp_version)

Pack a HDMI Audio infoframe for DisplayPort

Parameters

conststructhdmi_audio_infoframe*frame

HDMI Audio infoframe

structdp_sdp*sdp

Secondary data packet for DisplayPort.

u8dp_version

DisplayPort version to be encoded in the header

Description

Packs a HDMI Audio Infoframe to be sent over DisplayPort. This functionfills the secondary data packet to be used for DisplayPort.

Return

Number of total written bytes or a negative errno on failure.

inthdmi_vendor_infoframe_init(structhdmi_vendor_infoframe*frame)

initialize an HDMI vendor infoframe

Parameters

structhdmi_vendor_infoframe*frame

HDMI vendor infoframe

Description

Returns 0 on success or a negative error code on failure.

inthdmi_vendor_infoframe_check(structhdmi_vendor_infoframe*frame)

check a HDMI vendor infoframe

Parameters

structhdmi_vendor_infoframe*frame

HDMI infoframe

Description

Validates that the infoframe is consistent and updates derived fields(eg. length) based on other fields.

Returns 0 on success or a negative error code on failure.

ssize_thdmi_vendor_infoframe_pack_only(conststructhdmi_vendor_infoframe*frame,void*buffer,size_tsize)

write a HDMI vendor infoframe to binary buffer

Parameters

conststructhdmi_vendor_infoframe*frame

HDMI infoframe

void*buffer

destination buffer

size_tsize

size of buffer

Description

Packs the information contained in theframe structure into a binaryrepresentation that can be written into the corresponding controllerregisters. Also computes the checksum as required by section 5.3.5 ofthe HDMI 1.4 specification.

Returns the number of bytes packed into the binary buffer or a negativeerror code on failure.

ssize_thdmi_vendor_infoframe_pack(structhdmi_vendor_infoframe*frame,void*buffer,size_tsize)

check a HDMI Vendor infoframe, and write it to binary buffer

Parameters

structhdmi_vendor_infoframe*frame

HDMI Vendor infoframe

void*buffer

destination buffer

size_tsize

size of buffer

Description

Validates that the infoframe is consistent and updates derived fields(eg. length) based on other fields, after which it packs the informationcontained in theframe structure into a binary representation thatcan be written into the corresponding controller registers. This functionalso computes the checksum as required by section 5.3.5 of the HDMI 1.4specification.

Returns the number of bytes packed into the binary buffer or a negativeerror code on failure.

inthdmi_drm_infoframe_init(structhdmi_drm_infoframe*frame)

initialize an HDMI Dynaminc Range and mastering infoframe

Parameters

structhdmi_drm_infoframe*frame

HDMI DRM infoframe

Description

Returns 0 on success or a negative error code on failure.

inthdmi_drm_infoframe_check(structhdmi_drm_infoframe*frame)

check a HDMI DRM infoframe

Parameters

structhdmi_drm_infoframe*frame

HDMI DRM infoframe

Description

Validates that the infoframe is consistent.Returns 0 on success or a negative error code on failure.

ssize_thdmi_drm_infoframe_pack_only(conststructhdmi_drm_infoframe*frame,void*buffer,size_tsize)

write HDMI DRM infoframe to binary buffer

Parameters

conststructhdmi_drm_infoframe*frame

HDMI DRM infoframe

void*buffer

destination buffer

size_tsize

size of buffer

Description

Packs the information contained in theframe structure into a binaryrepresentation that can be written into the corresponding controllerregisters. Also computes the checksum as required by section 5.3.5 ofthe HDMI 1.4 specification.

Returns the number of bytes packed into the binary buffer or a negativeerror code on failure.

ssize_thdmi_drm_infoframe_pack(structhdmi_drm_infoframe*frame,void*buffer,size_tsize)

check a HDMI DRM infoframe, and write it to binary buffer

Parameters

structhdmi_drm_infoframe*frame

HDMI DRM infoframe

void*buffer

destination buffer

size_tsize

size of buffer

Description

Validates that the infoframe is consistent and updates derived fields(eg. length) based on other fields, after which it packs the informationcontained in theframe structure into a binary representation thatcan be written into the corresponding controller registers. This functionalso computes the checksum as required by section 5.3.5 of the HDMI 1.4specification.

Returns the number of bytes packed into the binary buffer or a negativeerror code on failure.

ssize_thdmi_infoframe_pack_only(constunionhdmi_infoframe*frame,void*buffer,size_tsize)

write a HDMI infoframe to binary buffer

Parameters

constunionhdmi_infoframe*frame

HDMI infoframe

void*buffer

destination buffer

size_tsize

size of buffer

Description

Packs the information contained in theframe structure into a binaryrepresentation that can be written into the corresponding controllerregisters. Also computes the checksum as required by section 5.3.5 ofthe HDMI 1.4 specification.

Returns the number of bytes packed into the binary buffer or a negativeerror code on failure.

ssize_thdmi_infoframe_pack(unionhdmi_infoframe*frame,void*buffer,size_tsize)

check a HDMI infoframe, and write it to binary buffer

Parameters

unionhdmi_infoframe*frame

HDMI infoframe

void*buffer

destination buffer

size_tsize

size of buffer

Description

Validates that the infoframe is consistent and updates derived fields(eg. length) based on other fields, after which it packs the informationcontained in theframe structure into a binary representation thatcan be written into the corresponding controller registers. This functionalso computes the checksum as required by section 5.3.5 of the HDMI 1.4specification.

Returns the number of bytes packed into the binary buffer or a negativeerror code on failure.

voidhdmi_infoframe_log(constchar*level,structdevice*dev,constunionhdmi_infoframe*frame)

log info of HDMI infoframe

Parameters

constchar*level

logging level

structdevice*dev

device

constunionhdmi_infoframe*frame

HDMI infoframe

inthdmi_drm_infoframe_unpack_only(structhdmi_drm_infoframe*frame,constvoid*buffer,size_tsize)

unpack binary buffer of CTA-861-G DRM infoframe DataBytes to a HDMI DRM infoframe

Parameters

structhdmi_drm_infoframe*frame

HDMI DRM infoframe

constvoid*buffer

source buffer

size_tsize

size of buffer

Description

Unpacks CTA-861-G DRM infoframe DataBytes contained in the binarybufferinto a structuredframe of the HDMI Dynamic Range and Mastering (DRM)infoframe.

Returns 0 on success or a negative error code on failure.

inthdmi_infoframe_unpack(unionhdmi_infoframe*frame,constvoid*buffer,size_tsize)

unpack binary buffer to a HDMI infoframe

Parameters

unionhdmi_infoframe*frame

HDMI infoframe

constvoid*buffer

source buffer

size_tsize

size of buffer

Description

Unpacks the information contained in binary bufferbuffer into a structuredframe of a HDMI infoframe.Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4specification.

Returns 0 on success or a negative error code on failure.

Rectangle Utilities Reference

Utility functions to help manage rectangular areas forclipping, scaling, etc. calculations.

structdrm_rect

two dimensional rectangle

Definition:

struct drm_rect {    int x1, y1, x2, y2;};

Members

x1

horizontal starting coordinate (inclusive)

y1

vertical starting coordinate (inclusive)

x2

horizontal ending coordinate (exclusive)

y2

vertical ending coordinate (exclusive)

Description

Note that this must match the layout ofstructdrm_mode_rect or the damagehelpers likedrm_atomic_helper_damage_iter_init() break.

DRM_RECT_INIT

DRM_RECT_INIT(x,y,w,h)

initialize a rectangle from x/y/w/h

Parameters

x

x coordinate

y

y coordinate

w

width

h

height

Return

A new rectangle of the specified size.

DRM_RECT_FMT

DRM_RECT_FMT

printf string forstructdrm_rect

DRM_RECT_ARG

DRM_RECT_ARG(r)

printf arguments forstructdrm_rect

Parameters

r

rectangle struct

DRM_RECT_FP_FMT

DRM_RECT_FP_FMT

printf string forstructdrm_rect in 16.16 fixed point

DRM_RECT_FP_ARG

DRM_RECT_FP_ARG(r)

printf arguments forstructdrm_rect in 16.16 fixed point

Parameters

r

rectangle struct

Description

This is useful for e.g. printing plane source rectangles, which are in 16.16fixed point.

voiddrm_rect_init(structdrm_rect*r,intx,inty,intwidth,intheight)

initialize the rectangle from x/y/w/h

Parameters

structdrm_rect*r

rectangle

intx

x coordinate

inty

y coordinate

intwidth

width

intheight

height

voiddrm_rect_adjust_size(structdrm_rect*r,intdw,intdh)

adjust the size of the rectangle

Parameters

structdrm_rect*r

rectangle to be adjusted

intdw

horizontal adjustment

intdh

vertical adjustment

Description

Change the size of rectangler bydw in the horizontal direction,and bydh in the vertical direction, while keeping the centerofr stationary.

Positivedw anddh increase the size, negative values decrease it.

voiddrm_rect_translate(structdrm_rect*r,intdx,intdy)

translate the rectangle

Parameters

structdrm_rect*r

rectangle to be translated

intdx

horizontal translation

intdy

vertical translation

Description

Move rectangler bydx in the horizontal direction,and bydy in the vertical direction.

voiddrm_rect_translate_to(structdrm_rect*r,intx,inty)

translate the rectangle to an absolute position

Parameters

structdrm_rect*r

rectangle to be translated

intx

horizontal position

inty

vertical position

Description

Move rectangler tox in the horizontal direction,and toy in the vertical direction.

voiddrm_rect_downscale(structdrm_rect*r,inthorz,intvert)

downscale a rectangle

Parameters

structdrm_rect*r

rectangle to be downscaled

inthorz

horizontal downscale factor

intvert

vertical downscale factor

Description

Divide the coordinates of rectangler byhorz andvert.

intdrm_rect_width(conststructdrm_rect*r)

determine the rectangle width

Parameters

conststructdrm_rect*r

rectangle whose width is returned

Return

The width of the rectangle.

intdrm_rect_height(conststructdrm_rect*r)

determine the rectangle height

Parameters

conststructdrm_rect*r

rectangle whose height is returned

Return

The height of the rectangle.

booldrm_rect_visible(conststructdrm_rect*r)

determine if the rectangle is visible

Parameters

conststructdrm_rect*r

rectangle whose visibility is returned

Return

true if the rectangle is visible,false otherwise.

booldrm_rect_equals(conststructdrm_rect*r1,conststructdrm_rect*r2)

determine if two rectangles are equal

Parameters

conststructdrm_rect*r1

first rectangle

conststructdrm_rect*r2

second rectangle

Return

true if the rectangles are equal,false otherwise.

voiddrm_rect_fp_to_int(structdrm_rect*dst,conststructdrm_rect*src)

Convert a rect in 16.16 fixed point form to int form.

Parameters

structdrm_rect*dst

rect to be stored the converted value

conststructdrm_rect*src

rect in 16.16 fixed point form

booldrm_rect_overlap(conststructdrm_rect*a,conststructdrm_rect*b)

Check if two rectangles overlap

Parameters

conststructdrm_rect*a

first rectangle

conststructdrm_rect*b

second rectangle

Return

true if the rectangles overlap,false otherwise.

booldrm_rect_intersect(structdrm_rect*r1,conststructdrm_rect*r2)

intersect two rectangles

Parameters

structdrm_rect*r1

first rectangle

conststructdrm_rect*r2

second rectangle

Description

Calculate the intersection of rectanglesr1 andr2.r1 will be overwritten with the intersection.

Return

true if rectangler1 is still visible after the operation,false otherwise.

booldrm_rect_clip_scaled(structdrm_rect*src,structdrm_rect*dst,conststructdrm_rect*clip)

perform a scaled clip operation

Parameters

structdrm_rect*src

source window rectangle

structdrm_rect*dst

destination window rectangle

conststructdrm_rect*clip

clip rectangle

Description

Clip rectangledst by rectangleclip. Clip rectanglesrc bythe corresponding amounts, retaining the vertical and horizontal scalingfactors fromsrc todst.

Return

true if rectangledst is still visible after being clipped,false otherwise.

intdrm_rect_calc_hscale(conststructdrm_rect*src,conststructdrm_rect*dst,intmin_hscale,intmax_hscale)

calculate the horizontal scaling factor

Parameters

conststructdrm_rect*src

source window rectangle

conststructdrm_rect*dst

destination window rectangle

intmin_hscale

minimum allowed horizontal scaling factor

intmax_hscale

maximum allowed horizontal scaling factor

Description

Calculate the horizontal scaling factor as(src width) / (dst width).

If the scale is below 1 << 16, round down. If the scale is above1 << 16, round up. This will calculate the scale with the mostpessimistic limit calculation.

Return

The horizontal scaling factor, or errno of out of limits.

intdrm_rect_calc_vscale(conststructdrm_rect*src,conststructdrm_rect*dst,intmin_vscale,intmax_vscale)

calculate the vertical scaling factor

Parameters

conststructdrm_rect*src

source window rectangle

conststructdrm_rect*dst

destination window rectangle

intmin_vscale

minimum allowed vertical scaling factor

intmax_vscale

maximum allowed vertical scaling factor

Description

Calculate the vertical scaling factor as(src height) / (dst height).

If the scale is below 1 << 16, round down. If the scale is above1 << 16, round up. This will calculate the scale with the mostpessimistic limit calculation.

Return

The vertical scaling factor, or errno of out of limits.

voiddrm_rect_debug_print(constchar*prefix,conststructdrm_rect*r,boolfixed_point)

print the rectangle information

Parameters

constchar*prefix

prefix string

conststructdrm_rect*r

rectangle to print

boolfixed_point

rectangle is in 16.16 fixed point format

voiddrm_rect_rotate(structdrm_rect*r,intwidth,intheight,unsignedintrotation)

Rotate the rectangle

Parameters

structdrm_rect*r

rectangle to be rotated

intwidth

Width of the coordinate space

intheight

Height of the coordinate space

unsignedintrotation

Transformation to be applied

Description

Applyrotation to the coordinates of rectangler.

width andheight combined withrotation definethe location of the new origin.

width correcsponds to the horizontal andheightto the vertical axis of the untransformed coordinatespace.

voiddrm_rect_rotate_inv(structdrm_rect*r,intwidth,intheight,unsignedintrotation)

Inverse rotate the rectangle

Parameters

structdrm_rect*r

rectangle to be rotated

intwidth

Width of the coordinate space

intheight

Height of the coordinate space

unsignedintrotation

Transformation whose inverse is to be applied

Description

Apply the inverse ofrotation to the coordinatesof rectangler.

width andheight combined withrotation definethe location of the new origin.

width correcsponds to the horizontal andheightto the vertical axis of the original untransformedcoordinate space, so that you never have to flipthem when doing a rotatation and its inverse.That is, if you do

drm_rect_rotate(&r, width, height, rotation);drm_rect_rotate_inv(&r, width, height, rotation);

you will always get back the original rectangle.

Flip-work Helper Reference

Utility to queue up work to run from work-queue context after flip/vblank.Typically this can be used to defer unref of framebuffer’s, cursorbo’s, etc until after vblank. The APIs are all thread-safe. Moreover,drm_flip_work_commit() can be called in atomic context.

structdrm_flip_work

flip work queue

Definition:

struct drm_flip_work {    const char *name;    drm_flip_func_t func;    struct work_struct worker;    struct list_head queued;    struct list_head commited;    spinlock_t lock;};

Members

name

debug name

func

callback fxn called for each committed item

worker

worker which callsfunc

queued

queued tasks

commited

commited tasks

lock

lock to access queued and commited lists

voiddrm_flip_work_queue(structdrm_flip_work*work,void*val)

queue work

Parameters

structdrm_flip_work*work

the flip-work

void*val

the value to queue

Description

Queues work, that will later be run (passed back to drm_flip_func_tfunc) on a work queue afterdrm_flip_work_commit() is called.

voiddrm_flip_work_commit(structdrm_flip_work*work,structworkqueue_struct*wq)

commit queued work

Parameters

structdrm_flip_work*work

the flip-work

structworkqueue_struct*wq

the work-queue to run the queued work on

Description

Trigger work previously queued bydrm_flip_work_queue() to runon a workqueue. The typical usage would be to queue work (viadrm_flip_work_queue()) at any point (from vblank irq and/orprior), and then from vblank irq commit the queued work.

voiddrm_flip_work_init(structdrm_flip_work*work,constchar*name,drm_flip_func_tfunc)

initialize flip-work

Parameters

structdrm_flip_work*work

the flip-work to initialize

constchar*name

debug name

drm_flip_func_tfunc

the callback work function

Description

Initializes/allocates resources for the flip-work

voiddrm_flip_work_cleanup(structdrm_flip_work*work)

cleans up flip-work

Parameters

structdrm_flip_work*work

the flip-work to cleanup

Description

Destroy resources allocated for the flip-work

Auxiliary Modeset Helpers

This helper library contains various one-off functions which don’t really fitanywhere else in the DRM modeset helper library.

voiddrm_helper_move_panel_connectors_to_head(structdrm_device*dev)

move panels to the front in the connector list

Parameters

structdrm_device*dev

drm device to operate on

Description

Some userspace presumes that the first connected connector is the maindisplay, where it’s supposed to display e.g. the login screen. Forlaptops, this should be the main panel. Use this function to sort all(eDP/LVDS/DSI) panels to the front of the connector list, instead ofpainstakingly trying to initialize them in the right order.

voiddrm_helper_mode_fill_fb_struct(structdrm_device*dev,structdrm_framebuffer*fb,conststructdrm_format_info*info,conststructdrm_mode_fb_cmd2*mode_cmd)

fill out framebuffer metadata

Parameters

structdrm_device*dev

DRM device

structdrm_framebuffer*fb

drm_framebuffer object to fill out

conststructdrm_format_info*info

pixel format information

conststructdrm_mode_fb_cmd2*mode_cmd

metadata from the userspace fb creation request

Description

This helper can be used in a drivers fb_create callback to pre-fill the fb’smetadata fields.

intdrm_crtc_init(structdrm_device*dev,structdrm_crtc*crtc,conststructdrm_crtc_funcs*funcs)

Legacy CRTC initialization function

Parameters

structdrm_device*dev

DRM device

structdrm_crtc*crtc

CRTC object to init

conststructdrm_crtc_funcs*funcs

callbacks for the new CRTC

Description

Initialize a CRTC object with a default helper-provided primary plane and nocursor plane.

Note that we make some assumptions about hardware limitations that may not betrue for all hardware:

  1. Primary plane cannot be repositioned.

  2. Primary plane cannot be scaled.

  3. Primary plane must cover the entire CRTC.

  4. Subpixel positioning is not supported.

  5. The primary plane must always be on if the CRTC is enabled.

This is purely a backwards compatibility helper for old drivers. Driversshould instead implement their own primary plane. Atomic drivers must do so.Drivers with the above hardware restriction can look into usingstructdrm_simple_display_pipe, which encapsulates the above limitations into a niceinterface.

Return

Zero on success, error code on failure.

intdrm_mode_config_helper_suspend(structdrm_device*dev)

Modeset suspend helper

Parameters

structdrm_device*dev

DRM device

Description

This helper function takes care of suspending the modeset side. It disablesoutput polling if initialized, suspends fbdev if used and finally callsdrm_atomic_helper_suspend().If suspending fails, fbdev and polling is re-enabled.

See also:drm_kms_helper_poll_disable() anddrm_client_dev_suspend().

Return

Zero on success, negative error code on error.

intdrm_mode_config_helper_resume(structdrm_device*dev)

Modeset resume helper

Parameters

structdrm_device*dev

DRM device

Description

This helper function takes care of resuming the modeset side. It callsdrm_atomic_helper_resume(), resumes fbdev if used and enables output pollingif initiaized.

See also:drm_client_dev_resume() anddrm_kms_helper_poll_enable().

Return

Zero on success, negative error code on error.

OF/DT Helpers

A set of helper functions to aid DRM drivers in parsing standard DTproperties.

uint32_tdrm_of_crtc_port_mask(structdrm_device*dev,structdevice_node*port)

find the mask of a registered CRTC by port OF node

Parameters

structdrm_device*dev

DRM device

structdevice_node*port

port OF node

Description

Given a port OF node, return the possible mask of the correspondingCRTC within a device’s list of CRTCs. Returns zero if not found.

uint32_tdrm_of_find_possible_crtcs(structdrm_device*dev,structdevice_node*port)

find the possible CRTCs for an encoder port

Parameters

structdrm_device*dev

DRM device

structdevice_node*port

encoder port to scan for endpoints

Description

Scan all endpoints attached to a port, locate their attached CRTCs,and generate the DRM mask of CRTCs which may be attached to thisencoder.

Seehttps://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/graph.yamlfor the bindings.

voiddrm_of_component_match_add(structdevice*master,structcomponent_match**matchptr,int(*compare)(structdevice*,void*),structdevice_node*node)

Add a component helper OF node match rule

Parameters

structdevice*master

master device

structcomponent_match**matchptr

component match pointer

int(*compare)(structdevice*,void*)

compare function used for matching component

structdevice_node*node

of_node

intdrm_of_component_probe(structdevice*dev,int(*compare_of)(structdevice*,void*),conststructcomponent_master_ops*m_ops)

Generic probe function for a component based master

Parameters

structdevice*dev

master device containing the OF node

int(*compare_of)(structdevice*,void*)

compare function used for matching components

conststructcomponent_master_ops*m_ops

component master ops to be used

Description

Parse the platform device OF node and bind all the components associatedwith the master. Interface ports are added before the encoders in order tosatisfy their .bind requirements

Seehttps://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/graph.yamlfor the bindings.

Returns zero if successful, or one of the standard error codes if it fails.

intdrm_of_find_panel_or_bridge(conststructdevice_node*np,intport,intendpoint,structdrm_panel**panel,structdrm_bridge**bridge)

return connected panel or bridge device

Parameters

conststructdevice_node*np

device tree node containing encoder output ports

intport

port in the device tree node

intendpoint

endpoint in the device tree node

structdrm_panel**panel

pointer to hold returned drm_panel

structdrm_bridge**bridge

pointer to hold returned drm_bridge

Description

Given a DT node’s port and endpoint number, find the connected node andreturn either the associatedstructdrm_panel or drm_bridge device. Eitherpanel orbridge must not be NULL.

This function is deprecated and should not be used in new drivers. Usedevm_drm_of_get_bridge() instead.

Returns zero if successful, or one of the standard error codes if it fails.

intdrm_of_lvds_get_dual_link_pixel_order(conststructdevice_node*port1,conststructdevice_node*port2)

Get LVDS dual-link source pixel order

Parameters

conststructdevice_node*port1

First DT port node of the Dual-link LVDS source

conststructdevice_node*port2

Second DT port node of the Dual-link LVDS source

Description

An LVDS dual-link connection is made of two links, with even pixelstransitting on one link, and odd pixels on the other link. This functionreturns, for two ports of an LVDS dual-link source, which port shall transmitthe even and odd pixels, based on the requirements of the connected sink.

The pixel order is determined from the dual-lvds-even-pixels anddual-lvds-odd-pixels properties in the sink’s DT port nodes. If thoseproperties are not present, or if their usage is not valid, this functionreturns -EINVAL.

If either port is not connected, this function returns -EPIPE.

port1 andport2 are typically DT sibling nodes, but may have differentparents when, for instance, two separate LVDS encoders carry the even and oddpixels.

Return

  • DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS -port1 carries even pixels andport2carries odd pixels

  • DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS -port1 carries odd pixels andport2carries even pixels

  • -EINVAL -port1 andport2 are not connected to a dual-link LVDS sink, orthe sink configuration is invalid

  • -EPIPE - whenport1 orport2 are not connected

intdrm_of_lvds_get_dual_link_pixel_order_sink(structdevice_node*port1,structdevice_node*port2)

Get LVDS dual-link sink pixel order

Parameters

structdevice_node*port1

First DT port node of the Dual-link LVDS sink

structdevice_node*port2

Second DT port node of the Dual-link LVDS sink

Description

An LVDS dual-link connection is made of two links, with even pixelstransitting on one link, and odd pixels on the other link. This functionreturns, for two ports of an LVDS dual-link sink, which port shall transmitthe even and odd pixels, based on the requirements of the sink.

The pixel order is determined from the dual-lvds-even-pixels anddual-lvds-odd-pixels properties in the sink’s DT port nodes. If thoseproperties are not present, or if their usage is not valid, this functionreturns -EINVAL.

If either port is not connected, this function returns -EPIPE.

port1 andport2 are typically DT sibling nodes, but may have differentparents when, for instance, two separate LVDS decoders receive the even andodd pixels.

Return

  • DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS -port1 receives even pixels andport2receives odd pixels

  • DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS -port1 receives odd pixels andport2receives even pixels

  • -EINVAL -port1 orport2 are NULL

  • -EPIPE - whenport1 orport2 are not connected

intdrm_of_lvds_get_data_mapping(conststructdevice_node*port)

Get LVDS data mapping

Parameters

conststructdevice_node*port

DT port node of the LVDS source or sink

Description

Convert DT “data-mapping” property string value into media bus format value.

Return

  • MEDIA_BUS_FMT_RGB666_1X7X3_SPWG - data-mapping is “jeida-18”

  • MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA - data-mapping is “jeida-24”

  • MEDIA_BUS_FMT_RGB101010_1X7X5_JEIDA - data-mapping is “jeida-30”

  • MEDIA_BUS_FMT_RGB888_1X7X4_SPWG - data-mapping is “vesa-24”

  • MEDIA_BUS_FMT_RGB101010_1X7X5_SPWG - data-mapping is “vesa-30”

  • -EINVAL - the “data-mapping” property is unsupported

  • -ENODEV - the “data-mapping” property is missing

intdrm_of_get_data_lanes_count(conststructdevice_node*endpoint,constunsignedintmin,constunsignedintmax)

Get DSI/(e)DP data lane count

Parameters

conststructdevice_node*endpoint

DT endpoint node of the DSI/(e)DP source or sink

constunsignedintmin

minimum supported number of data lanes

constunsignedintmax

maximum supported number of data lanes

Description

Count DT “data-lanes” property elements and check for validity.

Return

  • min..max - positive integer count of “data-lanes” elements

  • -ve - the “data-lanes” property is missing or invalid

  • -EINVAL - the “data-lanes” property is unsupported

intdrm_of_get_data_lanes_count_ep(conststructdevice_node*port,intport_reg,intreg,constunsignedintmin,constunsignedintmax)

Get DSI/(e)DP data lane count by endpoint

Parameters

conststructdevice_node*port

DT port node of the DSI/(e)DP source or sink

intport_reg

identifier (value of reg property) of the parent port node

intreg

identifier (value of reg property) of the endpoint node

constunsignedintmin

minimum supported number of data lanes

constunsignedintmax

maximum supported number of data lanes

Description

Count DT “data-lanes” property elements and check for validity.This variant uses endpoint specifier.

Return

  • min..max - positive integer count of “data-lanes” elements

  • -EINVAL - the “data-mapping” property is unsupported

  • -ENODEV - the “data-mapping” property is missing

structmipi_dsi_host*drm_of_get_dsi_bus(structdevice*dev)

find the DSI bus for a given device

Parameters

structdevice*dev

parent device of display (SPI, I2C)

Description

Gets parent DSI bus for a DSI device controlled through a bus otherthan MIPI-DCS (SPI, I2C, etc.) using the Device Tree.

This function assumes that the device’s port**0** is the DSI input.

Returns pointer to mipi_dsi_host if successful, -EINVAL if therequest is unsupported, -EPROBE_DEFER if the DSI host is found butnot available, or -ENODEV otherwise.

Legacy Plane Helper Reference

This helper library contains helpers to implement primary plane support ontop of the normal CRTC configuration interface.Since the legacydrm_mode_config_funcs.set_config interface ties the primaryplane together with the CRTC state this does not allow userspace to disablethe primary plane itself. The default primary plane only expose XRBG8888 andARGB8888 as valid pixel formats for the attached framebuffer.

Drivers are highly recommended to implement proper support for primaryplanes, and newly merged drivers must not rely upon these transitionalhelpers.

The plane helpers share the function table structures with other helpers,specifically also the atomic helpers. Seestructdrm_plane_helper_funcs forthe details.

intdrm_plane_helper_update_primary(structdrm_plane*plane,structdrm_crtc*crtc,structdrm_framebuffer*fb,intcrtc_x,intcrtc_y,unsignedintcrtc_w,unsignedintcrtc_h,uint32_tsrc_x,uint32_tsrc_y,uint32_tsrc_w,uint32_tsrc_h,structdrm_modeset_acquire_ctx*ctx)

Helper for updating primary planes

Parameters

structdrm_plane*plane

plane to update

structdrm_crtc*crtc

the plane’s new CRTC

structdrm_framebuffer*fb

the plane’s new framebuffer

intcrtc_x

x coordinate within CRTC

intcrtc_y

y coordinate within CRTC

unsignedintcrtc_w

width coordinate within CRTC

unsignedintcrtc_h

height coordinate within CRTC

uint32_tsrc_x

x coordinate within source

uint32_tsrc_y

y coordinate within source

uint32_tsrc_w

width coordinate within source

uint32_tsrc_h

height coordinate within source

structdrm_modeset_acquire_ctx*ctx

modeset locking context

Description

This helper validates the given parameters and updates the primary plane.

This function is only useful for non-atomic modesetting. Don’t useit in new drivers.

Return

Zero on success, or an errno code otherwise.

intdrm_plane_helper_disable_primary(structdrm_plane*plane,structdrm_modeset_acquire_ctx*ctx)

Helper for disabling primary planes

Parameters

structdrm_plane*plane

plane to disable

structdrm_modeset_acquire_ctx*ctx

modeset locking context

Description

This helper returns an error when trying to disable the primaryplane.

This function is only useful for non-atomic modesetting. Don’t useit in new drivers.

Return

An errno code.

voiddrm_plane_helper_destroy(structdrm_plane*plane)

Helper for primary plane destruction

Parameters

structdrm_plane*plane

plane to destroy

Description

Provides a default plane destroy handler for primary planes. This handleris called during CRTC destruction. We disable the primary plane, removeit from the DRM plane list, and deallocate the plane structure.

Legacy CRTC/Modeset Helper Functions Reference

The CRTC modeset helper library provides a default set_config implementationindrm_crtc_helper_set_config(). Plus a few other convenience functions usingthe same callbacks which drivers can use to e.g. restore the modesetconfiguration on resume withdrm_helper_resume_force_mode().

Note that this helper library doesn’t track the current power state of CRTCsand encoders. It can call callbacks likedrm_encoder_helper_funcs.dpms eventhough the hardware is already in the desired state. This deficiency has beenfixed in the atomic helpers.

The driver callbacks are mostly compatible with the atomic modeset helpers,except for the handling of the primary plane: Atomic helpers require that theprimary plane is implemented as a real standalone plane and not directly tiedto the CRTC state. For easier transition this library provides functions toimplement the old semantics required by the CRTC helpers using the new planeand atomic helper callbacks.

Drivers are strongly urged to convert to the atomic helpers (by way of firstconverting to the plane helpers). New drivers must not use these functionsbut need to implement the atomic interface instead, potentially using theatomic helpers for that.

These legacy modeset helpers use the same function table structures asall other modesetting helpers. See the documentation for structdrm_crtc_helper_funcs,structdrm_encoder_helper_funcs and structdrm_connector_helper_funcs.

booldrm_helper_encoder_in_use(structdrm_encoder*encoder)

check if a given encoder is in use

Parameters

structdrm_encoder*encoder

encoder to check

Description

Checks whetherencoder is with the current mode setting output configurationin use by any connector. This doesn’t mean that it is actually enabled sincethe DPMS state is tracked separately.

Return

True ifencoder is used, false otherwise.

booldrm_helper_crtc_in_use(structdrm_crtc*crtc)

check if a given CRTC is in a mode_config

Parameters

structdrm_crtc*crtc

CRTC to check

Description

Checks whethercrtc is with the current mode setting output configurationin use by any connector. This doesn’t mean that it is actually enabled sincethe DPMS state is tracked separately.

Return

True ifcrtc is used, false otherwise.

voiddrm_helper_disable_unused_functions(structdrm_device*dev)

disable unused objects

Parameters

structdrm_device*dev

DRM device

Description

This function walks through the entire mode setting configuration ofdev. Itwill remove any CRTC links of unused encoders and encoder links ofdisconnected connectors. Then it will disable all unused encoders and CRTCseither by calling their disable callback if available or by calling theirdpms callback with DRM_MODE_DPMS_OFF.

NOTE

This function is part of the legacy modeset helper library and will causemajor confusion with atomic drivers. This is because atomic helpers guaranteeto never call ->disable() hooks on a disabled function, or ->enable() hookson an enabled functions.drm_helper_disable_unused_functions() on the otherhand throws such guarantees into the wind and calls disable hooksunconditionally on unused functions.

booldrm_crtc_helper_set_mode(structdrm_crtc*crtc,structdrm_display_mode*mode,intx,inty,structdrm_framebuffer*old_fb)

internal helper to set a mode

Parameters

structdrm_crtc*crtc

CRTC to program

structdrm_display_mode*mode

mode to use

intx

horizontal offset into the surface

inty

vertical offset into the surface

structdrm_framebuffer*old_fb

old framebuffer, for cleanup

Description

Try to setmode oncrtc. Givecrtc and its associated connectors a chanceto fixup or reject the mode prior to trying to set it. This is an internalhelper that drivers could e.g. use to update properties that require theentire output pipe to be disabled and re-enabled in a new configuration. Forexample for changing whether audio is enabled on a hdmi link or for changingpanel fitter or dither attributes. It is also called by thedrm_crtc_helper_set_config() helper function to drive the mode settingsequence.

Return

True if the mode was set successfully, false otherwise.

intdrm_crtc_helper_atomic_check(structdrm_crtc*crtc,structdrm_atomic_state*state)

Helper to check CRTC atomic-state

Parameters

structdrm_crtc*crtc

CRTC to check

structdrm_atomic_state*state

atomic state object

Description

Provides a default CRTC-state check handler for CRTCs that only haveone primary plane attached to it. This is often the case for the CRTCof simple framebuffers.

Return

Zero on success, or an errno code otherwise.

intdrm_crtc_helper_set_config(structdrm_mode_set*set,structdrm_modeset_acquire_ctx*ctx)

set a new config from userspace

Parameters

structdrm_mode_set*set

mode set configuration

structdrm_modeset_acquire_ctx*ctx

lock acquire context, not used here

Description

Thedrm_crtc_helper_set_config() helper function implements the ofdrm_crtc_funcs.set_config callback for drivers using the legacy CRTChelpers.

It first tries to locate the best encoder for each connector by calling theconnectordrm_connector_helper_funcs.best_encoder helper operation.

After locating the appropriate encoders, the helper function will call themode_fixup encoder and CRTC helper operations to adjust the requested mode,or reject it completely in which case an error will be returned to theapplication. If the new configuration after mode adjustment is identical tothe current configuration the helper function will return without performingany other operation.

If the adjusted mode is identical to the current mode but changes to theframe buffer need to be applied, thedrm_crtc_helper_set_config() functionwill call the CRTCdrm_crtc_helper_funcs.mode_set_base helper operation.

If the adjusted mode differs from the current mode, or if the->mode_set_base() helper operation is not provided, the helper functionperforms a full mode set sequence by calling the ->prepare(), ->mode_set()and ->commit() CRTC and encoder helper operations, in that order.Alternatively it can also use the dpms and disable helper operations. Fordetails seestructdrm_crtc_helper_funcs and structdrm_encoder_helper_funcs.

This function is deprecated. New drivers must implement atomic modesetsupport, for which this function is unsuitable. Instead drivers should usedrm_atomic_helper_set_config().

Return

Returns 0 on success, negative errno numbers on failure.

intdrm_helper_connector_dpms(structdrm_connector*connector,intmode)

connector dpms helper implementation

Parameters

structdrm_connector*connector

affected connector

intmode

DPMS mode

Description

Thedrm_helper_connector_dpms() helper function implements thedrm_connector_funcs.dpms callback for drivers using the legacy CRTChelpers.

This is the main helper function provided by the CRTC helper framework forimplementing the DPMS connector attribute. It computes the new desired DPMSstate for all encoders and CRTCs in the output mesh and calls thedrm_crtc_helper_funcs.dpms anddrm_encoder_helper_funcs.dpms callbacksprovided by the driver.

This function is deprecated. New drivers must implement atomic modesetsupport, where DPMS is handled in the DRM core.

Return

Always returns 0.

voiddrm_helper_resume_force_mode(structdrm_device*dev)

force-restore mode setting configuration

Parameters

structdrm_device*dev

drm_device which should be restored

Description

Drivers which use the mode setting helpers can use this function toforce-restore the mode setting configuration e.g. on resume or when somethingelse might have trampled over the hw state (like some overzealous old BIOSentended to do).

This helper doesn’t provide a error return value since restoring the oldconfig should never fail due to resource allocation issues since the driverhas successfully set the restored configuration already. Hence this shouldboil down to the equivalent of a few dpms on calls, which also don’t providean error code.

Drivers where simply restoring an old configuration again might fail (e.g.due to slight differences in allocating shared resources when theconfiguration is restored in a different order than when userspace set it up)need to use their own restore logic.

This function is deprecated. New drivers should implement atomic mode-setting and use the atomic suspend/resume helpers.

See also:drm_atomic_helper_suspend(),drm_atomic_helper_resume()

intdrm_helper_force_disable_all(structdrm_device*dev)

Forcibly turn off all enabled CRTCs

Parameters

structdrm_device*dev

DRM device whose CRTCs to turn off

Description

Drivers may want to call this on unload to ensure that all displays areunlit and the GPU is in a consistent, low power state. Takes modeset locks.

Note

This should only be used by non-atomic legacy drivers. For an atomicversion look atdrm_atomic_helper_shutdown().

Return

Zero on success, error code on failure.

Privacy-screen class

This class allows non KMS drivers, from e.g. drivers/platform/x86 toregister a privacy-screen device, which the KMS drivers can then useto implement the standard privacy-screen properties, seeStandard Connector Properties.

KMS drivers using a privacy-screen class device are advised to use thedrm_connector_attach_privacy_screen_provider() anddrm_connector_update_privacy_screen() helpers for dealing with this.

structdrm_privacy_screen_ops

drm_privacy_screen operations

Definition:

struct drm_privacy_screen_ops {    int (*set_sw_state)(struct drm_privacy_screen *priv, enum drm_privacy_screen_status sw_state);    void (*get_hw_state)(struct drm_privacy_screen *priv);};

Members

set_sw_state

Called to request a change of the privacy-screenstate. The privacy-screen class code contains a check to avoid thisgetting called when the hw_state reports the state is locked.It is the driver’s responsibility to update sw_state and hw_state.This is always called with the drm_privacy_screen’s lock held.

get_hw_state

Called to request that the driver gets the currentprivacy-screen state from the hardware and then updates sw_state andhw_state accordingly. This will be called by the core just beforethe privacy-screen is registered in sysfs.

Description

Defines the operations which the privacy-screen class code may call.These functions should be implemented by the privacy-screen driver.

structdrm_privacy_screen

central privacy-screen structure

Definition:

struct drm_privacy_screen {    struct device dev;    struct mutex lock;    struct list_head list;    struct blocking_notifier_head notifier_head;    const struct drm_privacy_screen_ops *ops;    enum drm_privacy_screen_status sw_state;    enum drm_privacy_screen_status hw_state;    void *drvdata;};

Members

dev

device used to register the privacy-screen in sysfs.

lock

mutex protection all fields in this struct.

list

privacy-screen devices list list-entry.

notifier_head

privacy-screen notifier head.

ops

structdrm_privacy_screen_ops for this privacy-screen.This is NULL if the driver has unregistered the privacy-screen.

sw_state

The privacy-screen’s software state, seeStandard Connector Propertiesfor more info.

hw_state

The privacy-screen’s hardware state, seeStandard Connector Propertiesfor more info.

drvdata

Private data owned by the privacy screen provider

Description

Central privacy-screen structure, this contains thestructdevice usedto register the screen in sysfs, the screen’s state, ops, etc.

structdrm_privacy_screen_lookup

static privacy-screen lookup list entry

Definition:

struct drm_privacy_screen_lookup {    struct list_head list;    const char *dev_id;    const char *con_id;    const char *provider;};

Members

list

Lookup list list-entry.

dev_id

Consumer device name or NULL to match all devices.

con_id

Consumer connector name or NULL to match all connectors.

provider

dev_name() of the privacy_screen provider.

Description

Used for the static lookup-list for mapping privacy-screen consumerdev-connector pairs to a privacy-screen provider.

voiddrm_privacy_screen_lookup_add(structdrm_privacy_screen_lookup*lookup)

add an entry to the static privacy-screen lookup list

Parameters

structdrm_privacy_screen_lookup*lookup

lookup list entry to add

Description

Add an entry to the static privacy-screen lookup list. Note thestructlist_head which is part of thestructdrm_privacy_screen_lookupgets added to a list owned by the privacy-screen core. So the passed instructdrm_privacy_screen_lookup must not be free-ed until it is removedfrom the lookup list by callingdrm_privacy_screen_lookup_remove().

voiddrm_privacy_screen_lookup_remove(structdrm_privacy_screen_lookup*lookup)

remove an entry to the static privacy-screen lookup list

Parameters

structdrm_privacy_screen_lookup*lookup

lookup list entry to remove

Description

Remove an entry previously added withdrm_privacy_screen_lookup_add()from the static privacy-screen lookup list.

structdrm_privacy_screen*drm_privacy_screen_get(structdevice*dev,constchar*con_id)

get a privacy-screen provider

Parameters

structdevice*dev

consumer-device for which to get a privacy-screen provider

constchar*con_id

(video)connector name for which to get a privacy-screen provider

Description

Get a privacy-screen provider for a privacy-screen attached to thedisplay described by thedev andcon_id parameters.

Return

  • A pointer to astructdrm_privacy_screen on success.

  • ERR_PTR(-ENODEV) if no matching privacy-screen is found

  • ERR_PTR(-EPROBE_DEFER) if there is a matching privacy-screen,

    but it has not been registered yet.

voiddrm_privacy_screen_put(structdrm_privacy_screen*priv)

release a privacy-screen reference

Parameters

structdrm_privacy_screen*priv

privacy screen reference to release

Description

Release a privacy-screen provider reference gotten throughdrm_privacy_screen_get(). May be called with a NULL or ERR_PTR,in which case it is a no-op.

intdrm_privacy_screen_set_sw_state(structdrm_privacy_screen*priv,enumdrm_privacy_screen_statussw_state)

set a privacy-screen’s sw-state

Parameters

structdrm_privacy_screen*priv

privacy screen to set the sw-state for

enumdrm_privacy_screen_statussw_state

new sw-state value to set

Description

Set the sw-state of a privacy screen. If the privacy-screen is notin a locked hw-state, then the actual and hw-state of the privacy-screenwill be immediately updated to the new value. If the privacy-screen isin a locked hw-state, then the new sw-state will be remembered as therequested state to put the privacy-screen in when it becomes unlocked.

Return

0 on success, negative error code on failure.

voiddrm_privacy_screen_get_state(structdrm_privacy_screen*priv,enumdrm_privacy_screen_status*sw_state_ret,enumdrm_privacy_screen_status*hw_state_ret)

get privacy-screen’s current state

Parameters

structdrm_privacy_screen*priv

privacy screen to get the state for

enumdrm_privacy_screen_status*sw_state_ret

address where to store the privacy-screens current sw-state

enumdrm_privacy_screen_status*hw_state_ret

address where to store the privacy-screens current hw-state

Description

Get the current state of a privacy-screen, both the sw-state and thehw-state.

intdrm_privacy_screen_register_notifier(structdrm_privacy_screen*priv,structnotifier_block*nb)

register a notifier

Parameters

structdrm_privacy_screen*priv

Privacy screen to register the notifier with

structnotifier_block*nb

Notifier-block for the notifier to register

Description

Register a notifier with the privacy-screen to be notified of changes madeto the privacy-screen state from outside of the privacy-screen class.E.g. the state may be changed by the hardware itself in response to ahotkey press.

The notifier is called with no locks held. The new hw_state and sw_statecan be retrieved using thedrm_privacy_screen_get_state() function.A pointer to the drm_privacy_screen’sstructis passed as thevoid*dataargument of the notifier_block’s notifier_call.

The notifier will NOT be called when changes are made throughdrm_privacy_screen_set_sw_state(). It is only called for external changes.

Return

0 on success, negative error code on failure.

intdrm_privacy_screen_unregister_notifier(structdrm_privacy_screen*priv,structnotifier_block*nb)

unregister a notifier

Parameters

structdrm_privacy_screen*priv

Privacy screen to register the notifier with

structnotifier_block*nb

Notifier-block for the notifier to register

Description

Unregister a notifier registered withdrm_privacy_screen_register_notifier().

Return

0 on success, negative error code on failure.

structdrm_privacy_screen*drm_privacy_screen_register(structdevice*parent,conststructdrm_privacy_screen_ops*ops,void*data)

register a privacy-screen

Parameters

structdevice*parent

parent-device for the privacy-screen

conststructdrm_privacy_screen_ops*ops

structdrm_privacy_screen_ops pointer with ops for the privacy-screen

void*data

Private data owned by the privacy screen provider

Description

Create and register a privacy-screen.

Return

  • A pointer to the created privacy-screen on success.

  • An ERR_PTR(errno) on failure.

voiddrm_privacy_screen_unregister(structdrm_privacy_screen*priv)

unregister privacy-screen

Parameters

structdrm_privacy_screen*priv

privacy-screen to unregister

Description

Unregister a privacy-screen registered withdrm_privacy_screen_register().May be called with a NULL or ERR_PTR, in which case it is a no-op.

voiddrm_privacy_screen_call_notifier_chain(structdrm_privacy_screen*priv)

notify consumers of state change

Parameters

structdrm_privacy_screen*priv

Privacy screen to register the notifier with

Description

A privacy-screen provider driver can call this functions upon externalchanges to the privacy-screen state. E.g. the state may be changed by thehardware itself in response to a hotkey press.This function must be called without holding the privacy-screen lock.the driver must update sw_state and hw_state to reflect the new state beforecalling this function.The expected behavior from the driver upon receiving an external statechange event is: 1. Take the lock; 2. Update sw_state and hw_state;3. Release the lock. 4. Calldrm_privacy_screen_call_notifier_chain().