drm_atomic_state_helper.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. /*
  2. * Copyright (C) 2018 Intel Corp.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors:
  23. * Rob Clark <robdclark@gmail.com>
  24. * Daniel Vetter <daniel.vetter@ffwll.ch>
  25. */
  26. #include <drm/drm_atomic.h>
  27. #include <drm/drm_atomic_state_helper.h>
  28. #include <drm/drm_bridge.h>
  29. #include <drm/drm_connector.h>
  30. #include <drm/drm_crtc.h>
  31. #include <drm/drm_device.h>
  32. #include <drm/drm_plane.h>
  33. #include <drm/drm_print.h>
  34. #include <drm/drm_vblank.h>
  35. #include <drm/drm_writeback.h>
  36. #include <linux/slab.h>
  37. #include <linux/dma-fence.h>
  38. /**
  39. * DOC: atomic state reset and initialization
  40. *
  41. * Both the drm core and the atomic helpers assume that there is always the full
  42. * and correct atomic software state for all connectors, CRTCs and planes
  43. * available. Which is a bit a problem on driver load and also after system
  44. * suspend. One way to solve this is to have a hardware state read-out
  45. * infrastructure which reconstructs the full software state (e.g. the i915
  46. * driver).
  47. *
  48. * The simpler solution is to just reset the software state to everything off,
  49. * which is easiest to do by calling drm_mode_config_reset(). To facilitate this
  50. * the atomic helpers provide default reset implementations for all hooks.
  51. *
  52. * On the upside the precise state tracking of atomic simplifies system suspend
  53. * and resume a lot. For drivers using drm_mode_config_reset() a complete recipe
  54. * is implemented in drm_atomic_helper_suspend() and drm_atomic_helper_resume().
  55. * For other drivers the building blocks are split out, see the documentation
  56. * for these functions.
  57. */
  58. /**
  59. * __drm_atomic_helper_crtc_state_reset - reset the CRTC state
  60. * @crtc_state: atomic CRTC state, must not be NULL
  61. * @crtc: CRTC object, must not be NULL
  62. *
  63. * Initializes the newly allocated @crtc_state with default
  64. * values. This is useful for drivers that subclass the CRTC state.
  65. */
  66. void
  67. __drm_atomic_helper_crtc_state_reset(struct drm_crtc_state *crtc_state,
  68. struct drm_crtc *crtc)
  69. {
  70. crtc_state->crtc = crtc;
  71. }
  72. EXPORT_SYMBOL(__drm_atomic_helper_crtc_state_reset);
  73. /**
  74. * __drm_atomic_helper_crtc_reset - reset state on CRTC
  75. * @crtc: drm CRTC
  76. * @crtc_state: CRTC state to assign
  77. *
  78. * Initializes the newly allocated @crtc_state and assigns it to
  79. * the &drm_crtc->state pointer of @crtc, usually required when
  80. * initializing the drivers or when called from the &drm_crtc_funcs.reset
  81. * hook.
  82. *
  83. * This is useful for drivers that subclass the CRTC state.
  84. */
  85. void
  86. __drm_atomic_helper_crtc_reset(struct drm_crtc *crtc,
  87. struct drm_crtc_state *crtc_state)
  88. {
  89. if (crtc_state)
  90. __drm_atomic_helper_crtc_state_reset(crtc_state, crtc);
  91. if (drm_dev_has_vblank(crtc->dev))
  92. drm_crtc_vblank_reset(crtc);
  93. crtc->state = crtc_state;
  94. }
  95. EXPORT_SYMBOL(__drm_atomic_helper_crtc_reset);
  96. /**
  97. * drm_atomic_helper_crtc_reset - default &drm_crtc_funcs.reset hook for CRTCs
  98. * @crtc: drm CRTC
  99. *
  100. * Resets the atomic state for @crtc by freeing the state pointer (which might
  101. * be NULL, e.g. at driver load time) and allocating a new empty state object.
  102. */
  103. void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc)
  104. {
  105. struct drm_crtc_state *crtc_state =
  106. kzalloc(sizeof(*crtc->state), GFP_KERNEL);
  107. if (crtc->state)
  108. crtc->funcs->atomic_destroy_state(crtc, crtc->state);
  109. __drm_atomic_helper_crtc_reset(crtc, crtc_state);
  110. }
  111. EXPORT_SYMBOL(drm_atomic_helper_crtc_reset);
  112. /**
  113. * __drm_atomic_helper_crtc_duplicate_state - copy atomic CRTC state
  114. * @crtc: CRTC object
  115. * @state: atomic CRTC state
  116. *
  117. * Copies atomic state from a CRTC's current state and resets inferred values.
  118. * This is useful for drivers that subclass the CRTC state.
  119. */
  120. void __drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc,
  121. struct drm_crtc_state *state)
  122. {
  123. memcpy(state, crtc->state, sizeof(*state));
  124. if (state->mode_blob)
  125. drm_property_blob_get(state->mode_blob);
  126. if (state->degamma_lut)
  127. drm_property_blob_get(state->degamma_lut);
  128. if (state->ctm)
  129. drm_property_blob_get(state->ctm);
  130. if (state->gamma_lut)
  131. drm_property_blob_get(state->gamma_lut);
  132. state->mode_changed = false;
  133. state->active_changed = false;
  134. state->planes_changed = false;
  135. state->connectors_changed = false;
  136. state->color_mgmt_changed = false;
  137. state->zpos_changed = false;
  138. state->commit = NULL;
  139. state->event = NULL;
  140. state->async_flip = false;
  141. /* Self refresh should be canceled when a new update is available */
  142. state->active = drm_atomic_crtc_effectively_active(state);
  143. state->self_refresh_active = false;
  144. }
  145. EXPORT_SYMBOL(__drm_atomic_helper_crtc_duplicate_state);
  146. /**
  147. * drm_atomic_helper_crtc_duplicate_state - default state duplicate hook
  148. * @crtc: drm CRTC
  149. *
  150. * Default CRTC state duplicate hook for drivers which don't have their own
  151. * subclassed CRTC state structure.
  152. */
  153. struct drm_crtc_state *
  154. drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc)
  155. {
  156. struct drm_crtc_state *state;
  157. if (WARN_ON(!crtc->state))
  158. return NULL;
  159. state = kmalloc(sizeof(*state), GFP_KERNEL);
  160. if (state)
  161. __drm_atomic_helper_crtc_duplicate_state(crtc, state);
  162. return state;
  163. }
  164. EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state);
  165. /**
  166. * __drm_atomic_helper_crtc_destroy_state - release CRTC state
  167. * @state: CRTC state object to release
  168. *
  169. * Releases all resources stored in the CRTC state without actually freeing
  170. * the memory of the CRTC state. This is useful for drivers that subclass the
  171. * CRTC state.
  172. */
  173. void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state)
  174. {
  175. if (state->commit) {
  176. /*
  177. * In the event that a non-blocking commit returns
  178. * -ERESTARTSYS before the commit_tail work is queued, we will
  179. * have an extra reference to the commit object. Release it, if
  180. * the event has not been consumed by the worker.
  181. *
  182. * state->event may be freed, so we can't directly look at
  183. * state->event->base.completion.
  184. */
  185. if (state->event && state->commit->abort_completion)
  186. drm_crtc_commit_put(state->commit);
  187. kfree(state->commit->event);
  188. state->commit->event = NULL;
  189. drm_crtc_commit_put(state->commit);
  190. }
  191. drm_property_blob_put(state->mode_blob);
  192. drm_property_blob_put(state->degamma_lut);
  193. drm_property_blob_put(state->ctm);
  194. drm_property_blob_put(state->gamma_lut);
  195. }
  196. EXPORT_SYMBOL(__drm_atomic_helper_crtc_destroy_state);
  197. /**
  198. * drm_atomic_helper_crtc_destroy_state - default state destroy hook
  199. * @crtc: drm CRTC
  200. * @state: CRTC state object to release
  201. *
  202. * Default CRTC state destroy hook for drivers which don't have their own
  203. * subclassed CRTC state structure.
  204. */
  205. void drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc,
  206. struct drm_crtc_state *state)
  207. {
  208. __drm_atomic_helper_crtc_destroy_state(state);
  209. kfree(state);
  210. }
  211. EXPORT_SYMBOL(drm_atomic_helper_crtc_destroy_state);
  212. /**
  213. * __drm_atomic_helper_plane_state_reset - resets plane state to default values
  214. * @plane_state: atomic plane state, must not be NULL
  215. * @plane: plane object, must not be NULL
  216. *
  217. * Initializes the newly allocated @plane_state with default
  218. * values. This is useful for drivers that subclass the CRTC state.
  219. */
  220. void __drm_atomic_helper_plane_state_reset(struct drm_plane_state *plane_state,
  221. struct drm_plane *plane)
  222. {
  223. plane_state->plane = plane;
  224. plane_state->rotation = DRM_MODE_ROTATE_0;
  225. plane_state->alpha = DRM_BLEND_ALPHA_OPAQUE;
  226. plane_state->pixel_blend_mode = DRM_MODE_BLEND_PREMULTI;
  227. }
  228. EXPORT_SYMBOL(__drm_atomic_helper_plane_state_reset);
  229. /**
  230. * __drm_atomic_helper_plane_reset - reset state on plane
  231. * @plane: drm plane
  232. * @plane_state: plane state to assign
  233. *
  234. * Initializes the newly allocated @plane_state and assigns it to
  235. * the &drm_crtc->state pointer of @plane, usually required when
  236. * initializing the drivers or when called from the &drm_plane_funcs.reset
  237. * hook.
  238. *
  239. * This is useful for drivers that subclass the plane state.
  240. */
  241. void __drm_atomic_helper_plane_reset(struct drm_plane *plane,
  242. struct drm_plane_state *plane_state)
  243. {
  244. if (plane_state)
  245. __drm_atomic_helper_plane_state_reset(plane_state, plane);
  246. plane->state = plane_state;
  247. }
  248. EXPORT_SYMBOL(__drm_atomic_helper_plane_reset);
  249. /**
  250. * drm_atomic_helper_plane_reset - default &drm_plane_funcs.reset hook for planes
  251. * @plane: drm plane
  252. *
  253. * Resets the atomic state for @plane by freeing the state pointer (which might
  254. * be NULL, e.g. at driver load time) and allocating a new empty state object.
  255. */
  256. void drm_atomic_helper_plane_reset(struct drm_plane *plane)
  257. {
  258. if (plane->state)
  259. __drm_atomic_helper_plane_destroy_state(plane->state);
  260. kfree(plane->state);
  261. plane->state = kzalloc(sizeof(*plane->state), GFP_KERNEL);
  262. if (plane->state)
  263. __drm_atomic_helper_plane_reset(plane, plane->state);
  264. }
  265. EXPORT_SYMBOL(drm_atomic_helper_plane_reset);
  266. /**
  267. * __drm_atomic_helper_plane_duplicate_state - copy atomic plane state
  268. * @plane: plane object
  269. * @state: atomic plane state
  270. *
  271. * Copies atomic state from a plane's current state. This is useful for
  272. * drivers that subclass the plane state.
  273. */
  274. void __drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane,
  275. struct drm_plane_state *state)
  276. {
  277. memcpy(state, plane->state, sizeof(*state));
  278. if (state->fb)
  279. drm_framebuffer_get(state->fb);
  280. state->fence = NULL;
  281. state->commit = NULL;
  282. state->fb_damage_clips = NULL;
  283. }
  284. EXPORT_SYMBOL(__drm_atomic_helper_plane_duplicate_state);
  285. /**
  286. * drm_atomic_helper_plane_duplicate_state - default state duplicate hook
  287. * @plane: drm plane
  288. *
  289. * Default plane state duplicate hook for drivers which don't have their own
  290. * subclassed plane state structure.
  291. */
  292. struct drm_plane_state *
  293. drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane)
  294. {
  295. struct drm_plane_state *state;
  296. if (WARN_ON(!plane->state))
  297. return NULL;
  298. state = kmalloc(sizeof(*state), GFP_KERNEL);
  299. if (state)
  300. __drm_atomic_helper_plane_duplicate_state(plane, state);
  301. return state;
  302. }
  303. EXPORT_SYMBOL(drm_atomic_helper_plane_duplicate_state);
  304. /**
  305. * __drm_atomic_helper_plane_destroy_state - release plane state
  306. * @state: plane state object to release
  307. *
  308. * Releases all resources stored in the plane state without actually freeing
  309. * the memory of the plane state. This is useful for drivers that subclass the
  310. * plane state.
  311. */
  312. void __drm_atomic_helper_plane_destroy_state(struct drm_plane_state *state)
  313. {
  314. if (state->fb)
  315. drm_framebuffer_put(state->fb);
  316. if (state->fence)
  317. dma_fence_put(state->fence);
  318. if (state->commit)
  319. drm_crtc_commit_put(state->commit);
  320. drm_property_blob_put(state->fb_damage_clips);
  321. }
  322. EXPORT_SYMBOL(__drm_atomic_helper_plane_destroy_state);
  323. /**
  324. * drm_atomic_helper_plane_destroy_state - default state destroy hook
  325. * @plane: drm plane
  326. * @state: plane state object to release
  327. *
  328. * Default plane state destroy hook for drivers which don't have their own
  329. * subclassed plane state structure.
  330. */
  331. void drm_atomic_helper_plane_destroy_state(struct drm_plane *plane,
  332. struct drm_plane_state *state)
  333. {
  334. __drm_atomic_helper_plane_destroy_state(state);
  335. kfree(state);
  336. }
  337. EXPORT_SYMBOL(drm_atomic_helper_plane_destroy_state);
  338. /**
  339. * __drm_atomic_helper_connector_state_reset - reset the connector state
  340. * @conn_state: atomic connector state, must not be NULL
  341. * @connector: connectotr object, must not be NULL
  342. *
  343. * Initializes the newly allocated @conn_state with default
  344. * values. This is useful for drivers that subclass the connector state.
  345. */
  346. void
  347. __drm_atomic_helper_connector_state_reset(struct drm_connector_state *conn_state,
  348. struct drm_connector *connector)
  349. {
  350. conn_state->connector = connector;
  351. }
  352. EXPORT_SYMBOL(__drm_atomic_helper_connector_state_reset);
  353. /**
  354. * __drm_atomic_helper_connector_reset - reset state on connector
  355. * @connector: drm connector
  356. * @conn_state: connector state to assign
  357. *
  358. * Initializes the newly allocated @conn_state and assigns it to
  359. * the &drm_connector->state pointer of @connector, usually required when
  360. * initializing the drivers or when called from the &drm_connector_funcs.reset
  361. * hook.
  362. *
  363. * This is useful for drivers that subclass the connector state.
  364. */
  365. void
  366. __drm_atomic_helper_connector_reset(struct drm_connector *connector,
  367. struct drm_connector_state *conn_state)
  368. {
  369. if (conn_state)
  370. __drm_atomic_helper_connector_state_reset(conn_state, connector);
  371. connector->state = conn_state;
  372. }
  373. EXPORT_SYMBOL(__drm_atomic_helper_connector_reset);
  374. /**
  375. * drm_atomic_helper_connector_reset - default &drm_connector_funcs.reset hook for connectors
  376. * @connector: drm connector
  377. *
  378. * Resets the atomic state for @connector by freeing the state pointer (which
  379. * might be NULL, e.g. at driver load time) and allocating a new empty state
  380. * object.
  381. */
  382. void drm_atomic_helper_connector_reset(struct drm_connector *connector)
  383. {
  384. struct drm_connector_state *conn_state =
  385. kzalloc(sizeof(*conn_state), GFP_KERNEL);
  386. if (connector->state)
  387. __drm_atomic_helper_connector_destroy_state(connector->state);
  388. kfree(connector->state);
  389. __drm_atomic_helper_connector_reset(connector, conn_state);
  390. }
  391. EXPORT_SYMBOL(drm_atomic_helper_connector_reset);
  392. /**
  393. * drm_atomic_helper_connector_tv_reset - Resets TV connector properties
  394. * @connector: DRM connector
  395. *
  396. * Resets the TV-related properties attached to a connector.
  397. */
  398. void drm_atomic_helper_connector_tv_reset(struct drm_connector *connector)
  399. {
  400. struct drm_cmdline_mode *cmdline = &connector->cmdline_mode;
  401. struct drm_connector_state *state = connector->state;
  402. state->tv.margins.left = cmdline->tv_margins.left;
  403. state->tv.margins.right = cmdline->tv_margins.right;
  404. state->tv.margins.top = cmdline->tv_margins.top;
  405. state->tv.margins.bottom = cmdline->tv_margins.bottom;
  406. }
  407. EXPORT_SYMBOL(drm_atomic_helper_connector_tv_reset);
  408. /**
  409. * __drm_atomic_helper_connector_duplicate_state - copy atomic connector state
  410. * @connector: connector object
  411. * @state: atomic connector state
  412. *
  413. * Copies atomic state from a connector's current state. This is useful for
  414. * drivers that subclass the connector state.
  415. */
  416. void
  417. __drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector,
  418. struct drm_connector_state *state)
  419. {
  420. memcpy(state, connector->state, sizeof(*state));
  421. if (state->crtc)
  422. drm_connector_get(connector);
  423. state->commit = NULL;
  424. if (state->hdr_output_metadata)
  425. drm_property_blob_get(state->hdr_output_metadata);
  426. /* Don't copy over a writeback job, they are used only once */
  427. state->writeback_job = NULL;
  428. }
  429. EXPORT_SYMBOL(__drm_atomic_helper_connector_duplicate_state);
  430. /**
  431. * drm_atomic_helper_connector_duplicate_state - default state duplicate hook
  432. * @connector: drm connector
  433. *
  434. * Default connector state duplicate hook for drivers which don't have their own
  435. * subclassed connector state structure.
  436. */
  437. struct drm_connector_state *
  438. drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector)
  439. {
  440. struct drm_connector_state *state;
  441. if (WARN_ON(!connector->state))
  442. return NULL;
  443. state = kmalloc(sizeof(*state), GFP_KERNEL);
  444. if (state)
  445. __drm_atomic_helper_connector_duplicate_state(connector, state);
  446. return state;
  447. }
  448. EXPORT_SYMBOL(drm_atomic_helper_connector_duplicate_state);
  449. /**
  450. * __drm_atomic_helper_connector_destroy_state - release connector state
  451. * @state: connector state object to release
  452. *
  453. * Releases all resources stored in the connector state without actually
  454. * freeing the memory of the connector state. This is useful for drivers that
  455. * subclass the connector state.
  456. */
  457. void
  458. __drm_atomic_helper_connector_destroy_state(struct drm_connector_state *state)
  459. {
  460. if (state->crtc)
  461. drm_connector_put(state->connector);
  462. if (state->commit)
  463. drm_crtc_commit_put(state->commit);
  464. if (state->writeback_job)
  465. drm_writeback_cleanup_job(state->writeback_job);
  466. drm_property_blob_put(state->hdr_output_metadata);
  467. }
  468. EXPORT_SYMBOL(__drm_atomic_helper_connector_destroy_state);
  469. /**
  470. * drm_atomic_helper_connector_destroy_state - default state destroy hook
  471. * @connector: drm connector
  472. * @state: connector state object to release
  473. *
  474. * Default connector state destroy hook for drivers which don't have their own
  475. * subclassed connector state structure.
  476. */
  477. void drm_atomic_helper_connector_destroy_state(struct drm_connector *connector,
  478. struct drm_connector_state *state)
  479. {
  480. __drm_atomic_helper_connector_destroy_state(state);
  481. kfree(state);
  482. }
  483. EXPORT_SYMBOL(drm_atomic_helper_connector_destroy_state);
  484. /**
  485. * __drm_atomic_helper_private_duplicate_state - copy atomic private state
  486. * @obj: CRTC object
  487. * @state: new private object state
  488. *
  489. * Copies atomic state from a private objects's current state and resets inferred values.
  490. * This is useful for drivers that subclass the private state.
  491. */
  492. void __drm_atomic_helper_private_obj_duplicate_state(struct drm_private_obj *obj,
  493. struct drm_private_state *state)
  494. {
  495. memcpy(state, obj->state, sizeof(*state));
  496. }
  497. EXPORT_SYMBOL(__drm_atomic_helper_private_obj_duplicate_state);
  498. /**
  499. * __drm_atomic_helper_bridge_duplicate_state() - Copy atomic bridge state
  500. * @bridge: bridge object
  501. * @state: atomic bridge state
  502. *
  503. * Copies atomic state from a bridge's current state and resets inferred values.
  504. * This is useful for drivers that subclass the bridge state.
  505. */
  506. void __drm_atomic_helper_bridge_duplicate_state(struct drm_bridge *bridge,
  507. struct drm_bridge_state *state)
  508. {
  509. __drm_atomic_helper_private_obj_duplicate_state(&bridge->base,
  510. &state->base);
  511. state->bridge = bridge;
  512. }
  513. EXPORT_SYMBOL(__drm_atomic_helper_bridge_duplicate_state);
  514. /**
  515. * drm_atomic_helper_bridge_duplicate_state() - Duplicate a bridge state object
  516. * @bridge: bridge object
  517. *
  518. * Allocates a new bridge state and initializes it with the current bridge
  519. * state values. This helper is meant to be used as a bridge
  520. * &drm_bridge_funcs.atomic_duplicate_state hook for bridges that don't
  521. * subclass the bridge state.
  522. */
  523. struct drm_bridge_state *
  524. drm_atomic_helper_bridge_duplicate_state(struct drm_bridge *bridge)
  525. {
  526. struct drm_bridge_state *new;
  527. if (WARN_ON(!bridge->base.state))
  528. return NULL;
  529. new = kzalloc(sizeof(*new), GFP_KERNEL);
  530. if (new)
  531. __drm_atomic_helper_bridge_duplicate_state(bridge, new);
  532. return new;
  533. }
  534. EXPORT_SYMBOL(drm_atomic_helper_bridge_duplicate_state);
  535. /**
  536. * drm_atomic_helper_bridge_destroy_state() - Destroy a bridge state object
  537. * @bridge: the bridge this state refers to
  538. * @state: bridge state to destroy
  539. *
  540. * Destroys a bridge state previously created by
  541. * &drm_atomic_helper_bridge_reset() or
  542. * &drm_atomic_helper_bridge_duplicate_state(). This helper is meant to be
  543. * used as a bridge &drm_bridge_funcs.atomic_destroy_state hook for bridges
  544. * that don't subclass the bridge state.
  545. */
  546. void drm_atomic_helper_bridge_destroy_state(struct drm_bridge *bridge,
  547. struct drm_bridge_state *state)
  548. {
  549. kfree(state);
  550. }
  551. EXPORT_SYMBOL(drm_atomic_helper_bridge_destroy_state);
  552. /**
  553. * __drm_atomic_helper_bridge_reset() - Initialize a bridge state to its
  554. * default
  555. * @bridge: the bridge this state refers to
  556. * @state: bridge state to initialize
  557. *
  558. * Initializes the bridge state to default values. This is meant to be called
  559. * by the bridge &drm_bridge_funcs.atomic_reset hook for bridges that subclass
  560. * the bridge state.
  561. */
  562. void __drm_atomic_helper_bridge_reset(struct drm_bridge *bridge,
  563. struct drm_bridge_state *state)
  564. {
  565. memset(state, 0, sizeof(*state));
  566. state->bridge = bridge;
  567. }
  568. EXPORT_SYMBOL(__drm_atomic_helper_bridge_reset);
  569. /**
  570. * drm_atomic_helper_bridge_reset() - Allocate and initialize a bridge state
  571. * to its default
  572. * @bridge: the bridge this state refers to
  573. *
  574. * Allocates the bridge state and initializes it to default values. This helper
  575. * is meant to be used as a bridge &drm_bridge_funcs.atomic_reset hook for
  576. * bridges that don't subclass the bridge state.
  577. */
  578. struct drm_bridge_state *
  579. drm_atomic_helper_bridge_reset(struct drm_bridge *bridge)
  580. {
  581. struct drm_bridge_state *bridge_state;
  582. bridge_state = kzalloc(sizeof(*bridge_state), GFP_KERNEL);
  583. if (!bridge_state)
  584. return ERR_PTR(-ENOMEM);
  585. __drm_atomic_helper_bridge_reset(bridge, bridge_state);
  586. return bridge_state;
  587. }
  588. EXPORT_SYMBOL(drm_atomic_helper_bridge_reset);