Path: blob/master/drivers/gpu/drm/drm_atomic_state_helper.c
26428 views
/*1* Copyright (C) 2018 Intel Corp.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice shall be included in11* all copies or substantial portions of the Software.12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL16* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR17* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,18* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR19* OTHER DEALINGS IN THE SOFTWARE.20*21* Authors:22* Rob Clark <[email protected]>23* Daniel Vetter <[email protected]>24*/2526#include <drm/drm_atomic.h>27#include <drm/drm_atomic_state_helper.h>28#include <drm/drm_blend.h>29#include <drm/drm_bridge.h>30#include <drm/drm_connector.h>31#include <drm/drm_crtc.h>32#include <drm/drm_device.h>33#include <drm/drm_framebuffer.h>34#include <drm/drm_plane.h>35#include <drm/drm_print.h>36#include <drm/drm_vblank.h>37#include <drm/drm_writeback.h>3839#include <linux/export.h>40#include <linux/slab.h>41#include <linux/dma-fence.h>4243/**44* DOC: atomic state reset and initialization45*46* Both the drm core and the atomic helpers assume that there is always the full47* and correct atomic software state for all connectors, CRTCs and planes48* available. Which is a bit a problem on driver load and also after system49* suspend. One way to solve this is to have a hardware state read-out50* infrastructure which reconstructs the full software state (e.g. the i91551* driver).52*53* The simpler solution is to just reset the software state to everything off,54* which is easiest to do by calling drm_mode_config_reset(). To facilitate this55* the atomic helpers provide default reset implementations for all hooks.56*57* On the upside the precise state tracking of atomic simplifies system suspend58* and resume a lot. For drivers using drm_mode_config_reset() a complete recipe59* is implemented in drm_atomic_helper_suspend() and drm_atomic_helper_resume().60* For other drivers the building blocks are split out, see the documentation61* for these functions.62*/6364/**65* __drm_atomic_helper_crtc_state_reset - reset the CRTC state66* @crtc_state: atomic CRTC state, must not be NULL67* @crtc: CRTC object, must not be NULL68*69* Initializes the newly allocated @crtc_state with default70* values. This is useful for drivers that subclass the CRTC state.71*/72void73__drm_atomic_helper_crtc_state_reset(struct drm_crtc_state *crtc_state,74struct drm_crtc *crtc)75{76crtc_state->crtc = crtc;77}78EXPORT_SYMBOL(__drm_atomic_helper_crtc_state_reset);7980/**81* __drm_atomic_helper_crtc_reset - reset state on CRTC82* @crtc: drm CRTC83* @crtc_state: CRTC state to assign84*85* Initializes the newly allocated @crtc_state and assigns it to86* the &drm_crtc->state pointer of @crtc, usually required when87* initializing the drivers or when called from the &drm_crtc_funcs.reset88* hook.89*90* This is useful for drivers that subclass the CRTC state.91*/92void93__drm_atomic_helper_crtc_reset(struct drm_crtc *crtc,94struct drm_crtc_state *crtc_state)95{96if (crtc_state)97__drm_atomic_helper_crtc_state_reset(crtc_state, crtc);9899if (drm_dev_has_vblank(crtc->dev))100drm_crtc_vblank_reset(crtc);101102crtc->state = crtc_state;103}104EXPORT_SYMBOL(__drm_atomic_helper_crtc_reset);105106/**107* drm_atomic_helper_crtc_reset - default &drm_crtc_funcs.reset hook for CRTCs108* @crtc: drm CRTC109*110* Resets the atomic state for @crtc by freeing the state pointer (which might111* be NULL, e.g. at driver load time) and allocating a new empty state object.112*/113void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc)114{115struct drm_crtc_state *crtc_state =116kzalloc(sizeof(*crtc->state), GFP_KERNEL);117118if (crtc->state)119crtc->funcs->atomic_destroy_state(crtc, crtc->state);120121__drm_atomic_helper_crtc_reset(crtc, crtc_state);122}123EXPORT_SYMBOL(drm_atomic_helper_crtc_reset);124125/**126* __drm_atomic_helper_crtc_duplicate_state - copy atomic CRTC state127* @crtc: CRTC object128* @state: atomic CRTC state129*130* Copies atomic state from a CRTC's current state and resets inferred values.131* This is useful for drivers that subclass the CRTC state.132*/133void __drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc,134struct drm_crtc_state *state)135{136memcpy(state, crtc->state, sizeof(*state));137138if (state->mode_blob)139drm_property_blob_get(state->mode_blob);140if (state->degamma_lut)141drm_property_blob_get(state->degamma_lut);142if (state->ctm)143drm_property_blob_get(state->ctm);144if (state->gamma_lut)145drm_property_blob_get(state->gamma_lut);146state->mode_changed = false;147state->active_changed = false;148state->planes_changed = false;149state->connectors_changed = false;150state->color_mgmt_changed = false;151state->zpos_changed = false;152state->commit = NULL;153state->event = NULL;154state->async_flip = false;155156/* Self refresh should be canceled when a new update is available */157state->active = drm_atomic_crtc_effectively_active(state);158state->self_refresh_active = false;159}160EXPORT_SYMBOL(__drm_atomic_helper_crtc_duplicate_state);161162/**163* drm_atomic_helper_crtc_duplicate_state - default state duplicate hook164* @crtc: drm CRTC165*166* Default CRTC state duplicate hook for drivers which don't have their own167* subclassed CRTC state structure.168*/169struct drm_crtc_state *170drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc)171{172struct drm_crtc_state *state;173174if (WARN_ON(!crtc->state))175return NULL;176177state = kmalloc(sizeof(*state), GFP_KERNEL);178if (state)179__drm_atomic_helper_crtc_duplicate_state(crtc, state);180181return state;182}183EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state);184185/**186* __drm_atomic_helper_crtc_destroy_state - release CRTC state187* @state: CRTC state object to release188*189* Releases all resources stored in the CRTC state without actually freeing190* the memory of the CRTC state. This is useful for drivers that subclass the191* CRTC state.192*/193void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state)194{195if (state->commit) {196/*197* In the event that a non-blocking commit returns198* -ERESTARTSYS before the commit_tail work is queued, we will199* have an extra reference to the commit object. Release it, if200* the event has not been consumed by the worker.201*202* state->event may be freed, so we can't directly look at203* state->event->base.completion.204*/205if (state->event && state->commit->abort_completion)206drm_crtc_commit_put(state->commit);207208kfree(state->commit->event);209state->commit->event = NULL;210211drm_crtc_commit_put(state->commit);212}213214drm_property_blob_put(state->mode_blob);215drm_property_blob_put(state->degamma_lut);216drm_property_blob_put(state->ctm);217drm_property_blob_put(state->gamma_lut);218}219EXPORT_SYMBOL(__drm_atomic_helper_crtc_destroy_state);220221/**222* drm_atomic_helper_crtc_destroy_state - default state destroy hook223* @crtc: drm CRTC224* @state: CRTC state object to release225*226* Default CRTC state destroy hook for drivers which don't have their own227* subclassed CRTC state structure.228*/229void drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc,230struct drm_crtc_state *state)231{232__drm_atomic_helper_crtc_destroy_state(state);233kfree(state);234}235EXPORT_SYMBOL(drm_atomic_helper_crtc_destroy_state);236237/**238* __drm_atomic_helper_plane_state_reset - resets plane state to default values239* @plane_state: atomic plane state, must not be NULL240* @plane: plane object, must not be NULL241*242* Initializes the newly allocated @plane_state with default243* values. This is useful for drivers that subclass the CRTC state.244*/245void __drm_atomic_helper_plane_state_reset(struct drm_plane_state *plane_state,246struct drm_plane *plane)247{248u64 val;249250plane_state->plane = plane;251plane_state->rotation = DRM_MODE_ROTATE_0;252253plane_state->alpha = DRM_BLEND_ALPHA_OPAQUE;254plane_state->pixel_blend_mode = DRM_MODE_BLEND_PREMULTI;255256if (plane->color_encoding_property) {257if (!drm_object_property_get_default_value(&plane->base,258plane->color_encoding_property,259&val))260plane_state->color_encoding = val;261}262263if (plane->color_range_property) {264if (!drm_object_property_get_default_value(&plane->base,265plane->color_range_property,266&val))267plane_state->color_range = val;268}269270if (plane->zpos_property) {271if (!drm_object_property_get_default_value(&plane->base,272plane->zpos_property,273&val)) {274plane_state->zpos = val;275plane_state->normalized_zpos = val;276}277}278279if (plane->hotspot_x_property) {280if (!drm_object_property_get_default_value(&plane->base,281plane->hotspot_x_property,282&val))283plane_state->hotspot_x = val;284}285286if (plane->hotspot_y_property) {287if (!drm_object_property_get_default_value(&plane->base,288plane->hotspot_y_property,289&val))290plane_state->hotspot_y = val;291}292}293EXPORT_SYMBOL(__drm_atomic_helper_plane_state_reset);294295/**296* __drm_atomic_helper_plane_reset - reset state on plane297* @plane: drm plane298* @plane_state: plane state to assign299*300* Initializes the newly allocated @plane_state and assigns it to301* the &drm_crtc->state pointer of @plane, usually required when302* initializing the drivers or when called from the &drm_plane_funcs.reset303* hook.304*305* This is useful for drivers that subclass the plane state.306*/307void __drm_atomic_helper_plane_reset(struct drm_plane *plane,308struct drm_plane_state *plane_state)309{310if (plane_state)311__drm_atomic_helper_plane_state_reset(plane_state, plane);312313plane->state = plane_state;314}315EXPORT_SYMBOL(__drm_atomic_helper_plane_reset);316317/**318* drm_atomic_helper_plane_reset - default &drm_plane_funcs.reset hook for planes319* @plane: drm plane320*321* Resets the atomic state for @plane by freeing the state pointer (which might322* be NULL, e.g. at driver load time) and allocating a new empty state object.323*/324void drm_atomic_helper_plane_reset(struct drm_plane *plane)325{326if (plane->state)327__drm_atomic_helper_plane_destroy_state(plane->state);328329kfree(plane->state);330plane->state = kzalloc(sizeof(*plane->state), GFP_KERNEL);331if (plane->state)332__drm_atomic_helper_plane_reset(plane, plane->state);333}334EXPORT_SYMBOL(drm_atomic_helper_plane_reset);335336/**337* __drm_atomic_helper_plane_duplicate_state - copy atomic plane state338* @plane: plane object339* @state: atomic plane state340*341* Copies atomic state from a plane's current state. This is useful for342* drivers that subclass the plane state.343*/344void __drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane,345struct drm_plane_state *state)346{347memcpy(state, plane->state, sizeof(*state));348349if (state->fb)350drm_framebuffer_get(state->fb);351352state->fence = NULL;353state->commit = NULL;354state->fb_damage_clips = NULL;355state->color_mgmt_changed = false;356}357EXPORT_SYMBOL(__drm_atomic_helper_plane_duplicate_state);358359/**360* drm_atomic_helper_plane_duplicate_state - default state duplicate hook361* @plane: drm plane362*363* Default plane state duplicate hook for drivers which don't have their own364* subclassed plane state structure.365*/366struct drm_plane_state *367drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane)368{369struct drm_plane_state *state;370371if (WARN_ON(!plane->state))372return NULL;373374state = kmalloc(sizeof(*state), GFP_KERNEL);375if (state)376__drm_atomic_helper_plane_duplicate_state(plane, state);377378return state;379}380EXPORT_SYMBOL(drm_atomic_helper_plane_duplicate_state);381382/**383* __drm_atomic_helper_plane_destroy_state - release plane state384* @state: plane state object to release385*386* Releases all resources stored in the plane state without actually freeing387* the memory of the plane state. This is useful for drivers that subclass the388* plane state.389*/390void __drm_atomic_helper_plane_destroy_state(struct drm_plane_state *state)391{392if (state->fb)393drm_framebuffer_put(state->fb);394395if (state->fence)396dma_fence_put(state->fence);397398if (state->commit)399drm_crtc_commit_put(state->commit);400401drm_property_blob_put(state->fb_damage_clips);402}403EXPORT_SYMBOL(__drm_atomic_helper_plane_destroy_state);404405/**406* drm_atomic_helper_plane_destroy_state - default state destroy hook407* @plane: drm plane408* @state: plane state object to release409*410* Default plane state destroy hook for drivers which don't have their own411* subclassed plane state structure.412*/413void drm_atomic_helper_plane_destroy_state(struct drm_plane *plane,414struct drm_plane_state *state)415{416__drm_atomic_helper_plane_destroy_state(state);417kfree(state);418}419EXPORT_SYMBOL(drm_atomic_helper_plane_destroy_state);420421/**422* __drm_atomic_helper_connector_state_reset - reset the connector state423* @conn_state: atomic connector state, must not be NULL424* @connector: connectotr object, must not be NULL425*426* Initializes the newly allocated @conn_state with default427* values. This is useful for drivers that subclass the connector state.428*/429void430__drm_atomic_helper_connector_state_reset(struct drm_connector_state *conn_state,431struct drm_connector *connector)432{433conn_state->connector = connector;434}435EXPORT_SYMBOL(__drm_atomic_helper_connector_state_reset);436437/**438* __drm_atomic_helper_connector_reset - reset state on connector439* @connector: drm connector440* @conn_state: connector state to assign441*442* Initializes the newly allocated @conn_state and assigns it to443* the &drm_connector->state pointer of @connector, usually required when444* initializing the drivers or when called from the &drm_connector_funcs.reset445* hook.446*447* This is useful for drivers that subclass the connector state.448*/449void450__drm_atomic_helper_connector_reset(struct drm_connector *connector,451struct drm_connector_state *conn_state)452{453if (conn_state)454__drm_atomic_helper_connector_state_reset(conn_state, connector);455456connector->state = conn_state;457}458EXPORT_SYMBOL(__drm_atomic_helper_connector_reset);459460/**461* drm_atomic_helper_connector_reset - default &drm_connector_funcs.reset hook for connectors462* @connector: drm connector463*464* Resets the atomic state for @connector by freeing the state pointer (which465* might be NULL, e.g. at driver load time) and allocating a new empty state466* object.467*/468void drm_atomic_helper_connector_reset(struct drm_connector *connector)469{470struct drm_connector_state *conn_state =471kzalloc(sizeof(*conn_state), GFP_KERNEL);472473if (connector->state)474__drm_atomic_helper_connector_destroy_state(connector->state);475476kfree(connector->state);477__drm_atomic_helper_connector_reset(connector, conn_state);478}479EXPORT_SYMBOL(drm_atomic_helper_connector_reset);480481/**482* drm_atomic_helper_connector_tv_margins_reset - Resets TV connector properties483* @connector: DRM connector484*485* Resets the TV-related properties attached to a connector.486*/487void drm_atomic_helper_connector_tv_margins_reset(struct drm_connector *connector)488{489struct drm_cmdline_mode *cmdline = &connector->cmdline_mode;490struct drm_connector_state *state = connector->state;491492state->tv.margins.left = cmdline->tv_margins.left;493state->tv.margins.right = cmdline->tv_margins.right;494state->tv.margins.top = cmdline->tv_margins.top;495state->tv.margins.bottom = cmdline->tv_margins.bottom;496}497EXPORT_SYMBOL(drm_atomic_helper_connector_tv_margins_reset);498499/**500* drm_atomic_helper_connector_tv_reset - Resets Analog TV connector properties501* @connector: DRM connector502*503* Resets the analog TV properties attached to a connector504*/505void drm_atomic_helper_connector_tv_reset(struct drm_connector *connector)506{507struct drm_device *dev = connector->dev;508struct drm_cmdline_mode *cmdline = &connector->cmdline_mode;509struct drm_connector_state *state = connector->state;510struct drm_property *prop;511uint64_t val;512513prop = dev->mode_config.tv_mode_property;514if (prop)515if (!drm_object_property_get_default_value(&connector->base,516prop, &val))517state->tv.mode = val;518519if (cmdline->tv_mode_specified)520state->tv.mode = cmdline->tv_mode;521522prop = dev->mode_config.tv_select_subconnector_property;523if (prop)524if (!drm_object_property_get_default_value(&connector->base,525prop, &val))526state->tv.select_subconnector = val;527528prop = dev->mode_config.tv_subconnector_property;529if (prop)530if (!drm_object_property_get_default_value(&connector->base,531prop, &val))532state->tv.subconnector = val;533534prop = dev->mode_config.tv_brightness_property;535if (prop)536if (!drm_object_property_get_default_value(&connector->base,537prop, &val))538state->tv.brightness = val;539540prop = dev->mode_config.tv_contrast_property;541if (prop)542if (!drm_object_property_get_default_value(&connector->base,543prop, &val))544state->tv.contrast = val;545546prop = dev->mode_config.tv_flicker_reduction_property;547if (prop)548if (!drm_object_property_get_default_value(&connector->base,549prop, &val))550state->tv.flicker_reduction = val;551552prop = dev->mode_config.tv_overscan_property;553if (prop)554if (!drm_object_property_get_default_value(&connector->base,555prop, &val))556state->tv.overscan = val;557558prop = dev->mode_config.tv_saturation_property;559if (prop)560if (!drm_object_property_get_default_value(&connector->base,561prop, &val))562state->tv.saturation = val;563564prop = dev->mode_config.tv_hue_property;565if (prop)566if (!drm_object_property_get_default_value(&connector->base,567prop, &val))568state->tv.hue = val;569570drm_atomic_helper_connector_tv_margins_reset(connector);571}572EXPORT_SYMBOL(drm_atomic_helper_connector_tv_reset);573574/**575* drm_atomic_helper_connector_tv_check - Validate an analog TV connector state576* @connector: DRM Connector577* @state: the DRM State object578*579* Checks the state object to see if the requested state is valid for an580* analog TV connector.581*582* Return:583* %0 for success, a negative error code on error.584*/585int drm_atomic_helper_connector_tv_check(struct drm_connector *connector,586struct drm_atomic_state *state)587{588struct drm_connector_state *old_conn_state =589drm_atomic_get_old_connector_state(state, connector);590struct drm_connector_state *new_conn_state =591drm_atomic_get_new_connector_state(state, connector);592struct drm_crtc_state *crtc_state;593struct drm_crtc *crtc;594595crtc = new_conn_state->crtc;596if (!crtc)597return 0;598599crtc_state = drm_atomic_get_new_crtc_state(state, crtc);600if (!crtc_state)601return -EINVAL;602603if (old_conn_state->tv.mode != new_conn_state->tv.mode)604crtc_state->mode_changed = true;605606if (old_conn_state->tv.margins.left != new_conn_state->tv.margins.left ||607old_conn_state->tv.margins.right != new_conn_state->tv.margins.right ||608old_conn_state->tv.margins.top != new_conn_state->tv.margins.top ||609old_conn_state->tv.margins.bottom != new_conn_state->tv.margins.bottom ||610old_conn_state->tv.mode != new_conn_state->tv.mode ||611old_conn_state->tv.brightness != new_conn_state->tv.brightness ||612old_conn_state->tv.contrast != new_conn_state->tv.contrast ||613old_conn_state->tv.flicker_reduction != new_conn_state->tv.flicker_reduction ||614old_conn_state->tv.overscan != new_conn_state->tv.overscan ||615old_conn_state->tv.saturation != new_conn_state->tv.saturation ||616old_conn_state->tv.hue != new_conn_state->tv.hue)617crtc_state->connectors_changed = true;618619return 0;620}621EXPORT_SYMBOL(drm_atomic_helper_connector_tv_check);622623/**624* __drm_atomic_helper_connector_duplicate_state - copy atomic connector state625* @connector: connector object626* @state: atomic connector state627*628* Copies atomic state from a connector's current state. This is useful for629* drivers that subclass the connector state.630*/631void632__drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector,633struct drm_connector_state *state)634{635memcpy(state, connector->state, sizeof(*state));636if (state->crtc)637drm_connector_get(connector);638state->commit = NULL;639640if (state->hdr_output_metadata)641drm_property_blob_get(state->hdr_output_metadata);642643/* Don't copy over a writeback job, they are used only once */644state->writeback_job = NULL;645}646EXPORT_SYMBOL(__drm_atomic_helper_connector_duplicate_state);647648/**649* drm_atomic_helper_connector_duplicate_state - default state duplicate hook650* @connector: drm connector651*652* Default connector state duplicate hook for drivers which don't have their own653* subclassed connector state structure.654*/655struct drm_connector_state *656drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector)657{658struct drm_connector_state *state;659660if (WARN_ON(!connector->state))661return NULL;662663state = kmalloc(sizeof(*state), GFP_KERNEL);664if (state)665__drm_atomic_helper_connector_duplicate_state(connector, state);666667return state;668}669EXPORT_SYMBOL(drm_atomic_helper_connector_duplicate_state);670671/**672* __drm_atomic_helper_connector_destroy_state - release connector state673* @state: connector state object to release674*675* Releases all resources stored in the connector state without actually676* freeing the memory of the connector state. This is useful for drivers that677* subclass the connector state.678*/679void680__drm_atomic_helper_connector_destroy_state(struct drm_connector_state *state)681{682if (state->crtc)683drm_connector_put(state->connector);684685if (state->commit)686drm_crtc_commit_put(state->commit);687688if (state->writeback_job)689drm_writeback_cleanup_job(state->writeback_job);690691drm_property_blob_put(state->hdr_output_metadata);692}693EXPORT_SYMBOL(__drm_atomic_helper_connector_destroy_state);694695/**696* drm_atomic_helper_connector_destroy_state - default state destroy hook697* @connector: drm connector698* @state: connector state object to release699*700* Default connector state destroy hook for drivers which don't have their own701* subclassed connector state structure.702*/703void drm_atomic_helper_connector_destroy_state(struct drm_connector *connector,704struct drm_connector_state *state)705{706__drm_atomic_helper_connector_destroy_state(state);707kfree(state);708}709EXPORT_SYMBOL(drm_atomic_helper_connector_destroy_state);710711/**712* __drm_atomic_helper_private_obj_duplicate_state - copy atomic private state713* @obj: CRTC object714* @state: new private object state715*716* Copies atomic state from a private objects's current state and resets inferred values.717* This is useful for drivers that subclass the private state.718*/719void __drm_atomic_helper_private_obj_duplicate_state(struct drm_private_obj *obj,720struct drm_private_state *state)721{722memcpy(state, obj->state, sizeof(*state));723}724EXPORT_SYMBOL(__drm_atomic_helper_private_obj_duplicate_state);725726/**727* __drm_atomic_helper_bridge_duplicate_state() - Copy atomic bridge state728* @bridge: bridge object729* @state: atomic bridge state730*731* Copies atomic state from a bridge's current state and resets inferred values.732* This is useful for drivers that subclass the bridge state.733*/734void __drm_atomic_helper_bridge_duplicate_state(struct drm_bridge *bridge,735struct drm_bridge_state *state)736{737__drm_atomic_helper_private_obj_duplicate_state(&bridge->base,738&state->base);739state->bridge = bridge;740}741EXPORT_SYMBOL(__drm_atomic_helper_bridge_duplicate_state);742743/**744* drm_atomic_helper_bridge_duplicate_state() - Duplicate a bridge state object745* @bridge: bridge object746*747* Allocates a new bridge state and initializes it with the current bridge748* state values. This helper is meant to be used as a bridge749* &drm_bridge_funcs.atomic_duplicate_state hook for bridges that don't750* subclass the bridge state.751*/752struct drm_bridge_state *753drm_atomic_helper_bridge_duplicate_state(struct drm_bridge *bridge)754{755struct drm_bridge_state *new;756757if (WARN_ON(!bridge->base.state))758return NULL;759760new = kzalloc(sizeof(*new), GFP_KERNEL);761if (new)762__drm_atomic_helper_bridge_duplicate_state(bridge, new);763764return new;765}766EXPORT_SYMBOL(drm_atomic_helper_bridge_duplicate_state);767768/**769* drm_atomic_helper_bridge_destroy_state() - Destroy a bridge state object770* @bridge: the bridge this state refers to771* @state: bridge state to destroy772*773* Destroys a bridge state previously created by774* &drm_atomic_helper_bridge_reset() or775* &drm_atomic_helper_bridge_duplicate_state(). This helper is meant to be776* used as a bridge &drm_bridge_funcs.atomic_destroy_state hook for bridges777* that don't subclass the bridge state.778*/779void drm_atomic_helper_bridge_destroy_state(struct drm_bridge *bridge,780struct drm_bridge_state *state)781{782kfree(state);783}784EXPORT_SYMBOL(drm_atomic_helper_bridge_destroy_state);785786/**787* __drm_atomic_helper_bridge_reset() - Initialize a bridge state to its788* default789* @bridge: the bridge this state refers to790* @state: bridge state to initialize791*792* Initializes the bridge state to default values. This is meant to be called793* by the bridge &drm_bridge_funcs.atomic_reset hook for bridges that subclass794* the bridge state.795*/796void __drm_atomic_helper_bridge_reset(struct drm_bridge *bridge,797struct drm_bridge_state *state)798{799memset(state, 0, sizeof(*state));800state->bridge = bridge;801}802EXPORT_SYMBOL(__drm_atomic_helper_bridge_reset);803804/**805* drm_atomic_helper_bridge_reset() - Allocate and initialize a bridge state806* to its default807* @bridge: the bridge this state refers to808*809* Allocates the bridge state and initializes it to default values. This helper810* is meant to be used as a bridge &drm_bridge_funcs.atomic_reset hook for811* bridges that don't subclass the bridge state.812*/813struct drm_bridge_state *814drm_atomic_helper_bridge_reset(struct drm_bridge *bridge)815{816struct drm_bridge_state *bridge_state;817818bridge_state = kzalloc(sizeof(*bridge_state), GFP_KERNEL);819if (!bridge_state)820return ERR_PTR(-ENOMEM);821822__drm_atomic_helper_bridge_reset(bridge, bridge_state);823return bridge_state;824}825EXPORT_SYMBOL(drm_atomic_helper_bridge_reset);826827828