drm_atomic.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. /*
  2. * Copyright (C) 2014 Red Hat
  3. * Copyright (C) 2014 Intel Corp.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  19. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  20. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. * OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Rob Clark <robdclark@gmail.com>
  25. * Daniel Vetter <daniel.vetter@ffwll.ch>
  26. */
  27. #include <drm/drmP.h>
  28. #include <drm/drm_atomic.h>
  29. #include <drm/drm_plane_helper.h>
  30. static void kfree_state(struct drm_atomic_state *state)
  31. {
  32. kfree(state->connectors);
  33. kfree(state->connector_states);
  34. kfree(state->crtcs);
  35. kfree(state->crtc_states);
  36. kfree(state->planes);
  37. kfree(state->plane_states);
  38. kfree(state);
  39. }
  40. /**
  41. * drm_atomic_state_alloc - allocate atomic state
  42. * @dev: DRM device
  43. *
  44. * This allocates an empty atomic state to track updates.
  45. */
  46. struct drm_atomic_state *
  47. drm_atomic_state_alloc(struct drm_device *dev)
  48. {
  49. struct drm_atomic_state *state;
  50. state = kzalloc(sizeof(*state), GFP_KERNEL);
  51. if (!state)
  52. return NULL;
  53. state->num_connector = ACCESS_ONCE(dev->mode_config.num_connector);
  54. state->crtcs = kcalloc(dev->mode_config.num_crtc,
  55. sizeof(*state->crtcs), GFP_KERNEL);
  56. if (!state->crtcs)
  57. goto fail;
  58. state->crtc_states = kcalloc(dev->mode_config.num_crtc,
  59. sizeof(*state->crtc_states), GFP_KERNEL);
  60. if (!state->crtc_states)
  61. goto fail;
  62. state->planes = kcalloc(dev->mode_config.num_total_plane,
  63. sizeof(*state->planes), GFP_KERNEL);
  64. if (!state->planes)
  65. goto fail;
  66. state->plane_states = kcalloc(dev->mode_config.num_total_plane,
  67. sizeof(*state->plane_states), GFP_KERNEL);
  68. if (!state->plane_states)
  69. goto fail;
  70. state->connectors = kcalloc(state->num_connector,
  71. sizeof(*state->connectors),
  72. GFP_KERNEL);
  73. if (!state->connectors)
  74. goto fail;
  75. state->connector_states = kcalloc(state->num_connector,
  76. sizeof(*state->connector_states),
  77. GFP_KERNEL);
  78. if (!state->connector_states)
  79. goto fail;
  80. state->dev = dev;
  81. DRM_DEBUG_KMS("Allocate atomic state %p\n", state);
  82. return state;
  83. fail:
  84. kfree_state(state);
  85. return NULL;
  86. }
  87. EXPORT_SYMBOL(drm_atomic_state_alloc);
  88. /**
  89. * drm_atomic_state_clear - clear state object
  90. * @state: atomic state
  91. *
  92. * When the w/w mutex algorithm detects a deadlock we need to back off and drop
  93. * all locks. So someone else could sneak in and change the current modeset
  94. * configuration. Which means that all the state assembled in @state is no
  95. * longer an atomic update to the current state, but to some arbitrary earlier
  96. * state. Which could break assumptions the driver's ->atomic_check likely
  97. * relies on.
  98. *
  99. * Hence we must clear all cached state and completely start over, using this
  100. * function.
  101. */
  102. void drm_atomic_state_clear(struct drm_atomic_state *state)
  103. {
  104. struct drm_device *dev = state->dev;
  105. struct drm_mode_config *config = &dev->mode_config;
  106. int i;
  107. DRM_DEBUG_KMS("Clearing atomic state %p\n", state);
  108. for (i = 0; i < state->num_connector; i++) {
  109. struct drm_connector *connector = state->connectors[i];
  110. if (!connector)
  111. continue;
  112. WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
  113. connector->funcs->atomic_destroy_state(connector,
  114. state->connector_states[i]);
  115. }
  116. for (i = 0; i < config->num_crtc; i++) {
  117. struct drm_crtc *crtc = state->crtcs[i];
  118. if (!crtc)
  119. continue;
  120. crtc->funcs->atomic_destroy_state(crtc,
  121. state->crtc_states[i]);
  122. }
  123. for (i = 0; i < config->num_total_plane; i++) {
  124. struct drm_plane *plane = state->planes[i];
  125. if (!plane)
  126. continue;
  127. plane->funcs->atomic_destroy_state(plane,
  128. state->plane_states[i]);
  129. }
  130. }
  131. EXPORT_SYMBOL(drm_atomic_state_clear);
  132. /**
  133. * drm_atomic_state_free - free all memory for an atomic state
  134. * @state: atomic state to deallocate
  135. *
  136. * This frees all memory associated with an atomic state, including all the
  137. * per-object state for planes, crtcs and connectors.
  138. */
  139. void drm_atomic_state_free(struct drm_atomic_state *state)
  140. {
  141. drm_atomic_state_clear(state);
  142. DRM_DEBUG_KMS("Freeing atomic state %p\n", state);
  143. kfree_state(state);
  144. }
  145. EXPORT_SYMBOL(drm_atomic_state_free);
  146. /**
  147. * drm_atomic_get_crtc_state - get crtc state
  148. * @state: global atomic state object
  149. * @crtc: crtc to get state object for
  150. *
  151. * This function returns the crtc state for the given crtc, allocating it if
  152. * needed. It will also grab the relevant crtc lock to make sure that the state
  153. * is consistent.
  154. *
  155. * Returns:
  156. *
  157. * Either the allocated state or the error code encoded into the pointer. When
  158. * the error is EDEADLK then the w/w mutex code has detected a deadlock and the
  159. * entire atomic sequence must be restarted. All other errors are fatal.
  160. */
  161. struct drm_crtc_state *
  162. drm_atomic_get_crtc_state(struct drm_atomic_state *state,
  163. struct drm_crtc *crtc)
  164. {
  165. int ret, index;
  166. struct drm_crtc_state *crtc_state;
  167. index = drm_crtc_index(crtc);
  168. if (state->crtc_states[index])
  169. return state->crtc_states[index];
  170. ret = drm_modeset_lock(&crtc->mutex, state->acquire_ctx);
  171. if (ret)
  172. return ERR_PTR(ret);
  173. crtc_state = crtc->funcs->atomic_duplicate_state(crtc);
  174. if (!crtc_state)
  175. return ERR_PTR(-ENOMEM);
  176. state->crtc_states[index] = crtc_state;
  177. state->crtcs[index] = crtc;
  178. crtc_state->state = state;
  179. DRM_DEBUG_KMS("Added [CRTC:%d] %p state to %p\n",
  180. crtc->base.id, crtc_state, state);
  181. return crtc_state;
  182. }
  183. EXPORT_SYMBOL(drm_atomic_get_crtc_state);
  184. /**
  185. * drm_atomic_get_plane_state - get plane state
  186. * @state: global atomic state object
  187. * @plane: plane to get state object for
  188. *
  189. * This function returns the plane state for the given plane, allocating it if
  190. * needed. It will also grab the relevant plane lock to make sure that the state
  191. * is consistent.
  192. *
  193. * Returns:
  194. *
  195. * Either the allocated state or the error code encoded into the pointer. When
  196. * the error is EDEADLK then the w/w mutex code has detected a deadlock and the
  197. * entire atomic sequence must be restarted. All other errors are fatal.
  198. */
  199. struct drm_plane_state *
  200. drm_atomic_get_plane_state(struct drm_atomic_state *state,
  201. struct drm_plane *plane)
  202. {
  203. int ret, index;
  204. struct drm_plane_state *plane_state;
  205. index = drm_plane_index(plane);
  206. if (state->plane_states[index])
  207. return state->plane_states[index];
  208. ret = drm_modeset_lock(&plane->mutex, state->acquire_ctx);
  209. if (ret)
  210. return ERR_PTR(ret);
  211. plane_state = plane->funcs->atomic_duplicate_state(plane);
  212. if (!plane_state)
  213. return ERR_PTR(-ENOMEM);
  214. state->plane_states[index] = plane_state;
  215. state->planes[index] = plane;
  216. plane_state->state = state;
  217. DRM_DEBUG_KMS("Added [PLANE:%d] %p state to %p\n",
  218. plane->base.id, plane_state, state);
  219. if (plane_state->crtc) {
  220. struct drm_crtc_state *crtc_state;
  221. crtc_state = drm_atomic_get_crtc_state(state,
  222. plane_state->crtc);
  223. if (IS_ERR(crtc_state))
  224. return ERR_CAST(crtc_state);
  225. }
  226. return plane_state;
  227. }
  228. EXPORT_SYMBOL(drm_atomic_get_plane_state);
  229. /**
  230. * drm_atomic_get_connector_state - get connector state
  231. * @state: global atomic state object
  232. * @connector: connector to get state object for
  233. *
  234. * This function returns the connector state for the given connector,
  235. * allocating it if needed. It will also grab the relevant connector lock to
  236. * make sure that the state is consistent.
  237. *
  238. * Returns:
  239. *
  240. * Either the allocated state or the error code encoded into the pointer. When
  241. * the error is EDEADLK then the w/w mutex code has detected a deadlock and the
  242. * entire atomic sequence must be restarted. All other errors are fatal.
  243. */
  244. struct drm_connector_state *
  245. drm_atomic_get_connector_state(struct drm_atomic_state *state,
  246. struct drm_connector *connector)
  247. {
  248. int ret, index;
  249. struct drm_mode_config *config = &connector->dev->mode_config;
  250. struct drm_connector_state *connector_state;
  251. ret = drm_modeset_lock(&config->connection_mutex, state->acquire_ctx);
  252. if (ret)
  253. return ERR_PTR(ret);
  254. index = drm_connector_index(connector);
  255. /*
  256. * Construction of atomic state updates can race with a connector
  257. * hot-add which might overflow. In this case flip the table and just
  258. * restart the entire ioctl - no one is fast enough to livelock a cpu
  259. * with physical hotplug events anyway.
  260. *
  261. * Note that we only grab the indexes once we have the right lock to
  262. * prevent hotplug/unplugging of connectors. So removal is no problem,
  263. * at most the array is a bit too large.
  264. */
  265. if (index >= state->num_connector) {
  266. DRM_DEBUG_KMS("Hot-added connector would overflow state array, restarting\n");
  267. return ERR_PTR(-EAGAIN);
  268. }
  269. if (state->connector_states[index])
  270. return state->connector_states[index];
  271. connector_state = connector->funcs->atomic_duplicate_state(connector);
  272. if (!connector_state)
  273. return ERR_PTR(-ENOMEM);
  274. state->connector_states[index] = connector_state;
  275. state->connectors[index] = connector;
  276. connector_state->state = state;
  277. DRM_DEBUG_KMS("Added [CONNECTOR:%d] %p state to %p\n",
  278. connector->base.id, connector_state, state);
  279. if (connector_state->crtc) {
  280. struct drm_crtc_state *crtc_state;
  281. crtc_state = drm_atomic_get_crtc_state(state,
  282. connector_state->crtc);
  283. if (IS_ERR(crtc_state))
  284. return ERR_CAST(crtc_state);
  285. }
  286. return connector_state;
  287. }
  288. EXPORT_SYMBOL(drm_atomic_get_connector_state);
  289. /**
  290. * drm_atomic_set_crtc_for_plane - set crtc for plane
  291. * @state: the incoming atomic state
  292. * @plane: the plane whose incoming state to update
  293. * @crtc: crtc to use for the plane
  294. *
  295. * Changing the assigned crtc for a plane requires us to grab the lock and state
  296. * for the new crtc, as needed. This function takes care of all these details
  297. * besides updating the pointer in the state object itself.
  298. *
  299. * Returns:
  300. * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK
  301. * then the w/w mutex code has detected a deadlock and the entire atomic
  302. * sequence must be restarted. All other errors are fatal.
  303. */
  304. int
  305. drm_atomic_set_crtc_for_plane(struct drm_atomic_state *state,
  306. struct drm_plane *plane, struct drm_crtc *crtc)
  307. {
  308. struct drm_plane_state *plane_state =
  309. drm_atomic_get_plane_state(state, plane);
  310. struct drm_crtc_state *crtc_state;
  311. if (WARN_ON(IS_ERR(plane_state)))
  312. return PTR_ERR(plane_state);
  313. if (plane_state->crtc) {
  314. crtc_state = drm_atomic_get_crtc_state(plane_state->state,
  315. plane_state->crtc);
  316. if (WARN_ON(IS_ERR(crtc_state)))
  317. return PTR_ERR(crtc_state);
  318. crtc_state->plane_mask &= ~(1 << drm_plane_index(plane));
  319. }
  320. plane_state->crtc = crtc;
  321. if (crtc) {
  322. crtc_state = drm_atomic_get_crtc_state(plane_state->state,
  323. crtc);
  324. if (IS_ERR(crtc_state))
  325. return PTR_ERR(crtc_state);
  326. crtc_state->plane_mask |= (1 << drm_plane_index(plane));
  327. }
  328. if (crtc)
  329. DRM_DEBUG_KMS("Link plane state %p to [CRTC:%d]\n",
  330. plane_state, crtc->base.id);
  331. else
  332. DRM_DEBUG_KMS("Link plane state %p to [NOCRTC]\n", plane_state);
  333. return 0;
  334. }
  335. EXPORT_SYMBOL(drm_atomic_set_crtc_for_plane);
  336. /**
  337. * drm_atomic_set_fb_for_plane - set crtc for plane
  338. * @plane_state: atomic state object for the plane
  339. * @fb: fb to use for the plane
  340. *
  341. * Changing the assigned framebuffer for a plane requires us to grab a reference
  342. * to the new fb and drop the reference to the old fb, if there is one. This
  343. * function takes care of all these details besides updating the pointer in the
  344. * state object itself.
  345. */
  346. void
  347. drm_atomic_set_fb_for_plane(struct drm_plane_state *plane_state,
  348. struct drm_framebuffer *fb)
  349. {
  350. if (plane_state->fb)
  351. drm_framebuffer_unreference(plane_state->fb);
  352. if (fb)
  353. drm_framebuffer_reference(fb);
  354. plane_state->fb = fb;
  355. if (fb)
  356. DRM_DEBUG_KMS("Set [FB:%d] for plane state %p\n",
  357. fb->base.id, plane_state);
  358. else
  359. DRM_DEBUG_KMS("Set [NOFB] for plane state %p\n", plane_state);
  360. }
  361. EXPORT_SYMBOL(drm_atomic_set_fb_for_plane);
  362. /**
  363. * drm_atomic_set_crtc_for_connector - set crtc for connector
  364. * @conn_state: atomic state object for the connector
  365. * @crtc: crtc to use for the connector
  366. *
  367. * Changing the assigned crtc for a connector requires us to grab the lock and
  368. * state for the new crtc, as needed. This function takes care of all these
  369. * details besides updating the pointer in the state object itself.
  370. *
  371. * Returns:
  372. * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK
  373. * then the w/w mutex code has detected a deadlock and the entire atomic
  374. * sequence must be restarted. All other errors are fatal.
  375. */
  376. int
  377. drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state,
  378. struct drm_crtc *crtc)
  379. {
  380. struct drm_crtc_state *crtc_state;
  381. if (crtc) {
  382. crtc_state = drm_atomic_get_crtc_state(conn_state->state, crtc);
  383. if (IS_ERR(crtc_state))
  384. return PTR_ERR(crtc_state);
  385. }
  386. conn_state->crtc = crtc;
  387. if (crtc)
  388. DRM_DEBUG_KMS("Link connector state %p to [CRTC:%d]\n",
  389. conn_state, crtc->base.id);
  390. else
  391. DRM_DEBUG_KMS("Link connector state %p to [NOCRTC]\n",
  392. conn_state);
  393. return 0;
  394. }
  395. EXPORT_SYMBOL(drm_atomic_set_crtc_for_connector);
  396. /**
  397. * drm_atomic_add_affected_connectors - add connectors for crtc
  398. * @state: atomic state
  399. * @crtc: DRM crtc
  400. *
  401. * This function walks the current configuration and adds all connectors
  402. * currently using @crtc to the atomic configuration @state. Note that this
  403. * function must acquire the connection mutex. This can potentially cause
  404. * unneeded seralization if the update is just for the planes on one crtc. Hence
  405. * drivers and helpers should only call this when really needed (e.g. when a
  406. * full modeset needs to happen due to some change).
  407. *
  408. * Returns:
  409. * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK
  410. * then the w/w mutex code has detected a deadlock and the entire atomic
  411. * sequence must be restarted. All other errors are fatal.
  412. */
  413. int
  414. drm_atomic_add_affected_connectors(struct drm_atomic_state *state,
  415. struct drm_crtc *crtc)
  416. {
  417. struct drm_mode_config *config = &state->dev->mode_config;
  418. struct drm_connector *connector;
  419. struct drm_connector_state *conn_state;
  420. int ret;
  421. ret = drm_modeset_lock(&config->connection_mutex, state->acquire_ctx);
  422. if (ret)
  423. return ret;
  424. DRM_DEBUG_KMS("Adding all current connectors for [CRTC:%d] to %p\n",
  425. crtc->base.id, state);
  426. /*
  427. * Changed connectors are already in @state, so only need to look at the
  428. * current configuration.
  429. */
  430. list_for_each_entry(connector, &config->connector_list, head) {
  431. if (connector->state->crtc != crtc)
  432. continue;
  433. conn_state = drm_atomic_get_connector_state(state, connector);
  434. if (IS_ERR(conn_state))
  435. return PTR_ERR(conn_state);
  436. }
  437. return 0;
  438. }
  439. EXPORT_SYMBOL(drm_atomic_add_affected_connectors);
  440. /**
  441. * drm_atomic_connectors_for_crtc - count number of connected outputs
  442. * @state: atomic state
  443. * @crtc: DRM crtc
  444. *
  445. * This function counts all connectors which will be connected to @crtc
  446. * according to @state. Useful to recompute the enable state for @crtc.
  447. */
  448. int
  449. drm_atomic_connectors_for_crtc(struct drm_atomic_state *state,
  450. struct drm_crtc *crtc)
  451. {
  452. int i, num_connected_connectors = 0;
  453. for (i = 0; i < state->num_connector; i++) {
  454. struct drm_connector_state *conn_state;
  455. conn_state = state->connector_states[i];
  456. if (conn_state && conn_state->crtc == crtc)
  457. num_connected_connectors++;
  458. }
  459. DRM_DEBUG_KMS("State %p has %i connectors for [CRTC:%d]\n",
  460. state, num_connected_connectors, crtc->base.id);
  461. return num_connected_connectors;
  462. }
  463. EXPORT_SYMBOL(drm_atomic_connectors_for_crtc);
  464. /**
  465. * drm_atomic_legacy_backoff - locking backoff for legacy ioctls
  466. * @state: atomic state
  467. *
  468. * This function should be used by legacy entry points which don't understand
  469. * -EDEADLK semantics. For simplicity this one will grab all modeset locks after
  470. * the slowpath completed.
  471. */
  472. void drm_atomic_legacy_backoff(struct drm_atomic_state *state)
  473. {
  474. int ret;
  475. retry:
  476. drm_modeset_backoff(state->acquire_ctx);
  477. ret = drm_modeset_lock(&state->dev->mode_config.connection_mutex,
  478. state->acquire_ctx);
  479. if (ret)
  480. goto retry;
  481. ret = drm_modeset_lock_all_crtcs(state->dev,
  482. state->acquire_ctx);
  483. if (ret)
  484. goto retry;
  485. }
  486. EXPORT_SYMBOL(drm_atomic_legacy_backoff);
  487. /**
  488. * drm_atomic_check_only - check whether a given config would work
  489. * @state: atomic configuration to check
  490. *
  491. * Note that this function can return -EDEADLK if the driver needed to acquire
  492. * more locks but encountered a deadlock. The caller must then do the usual w/w
  493. * backoff dance and restart. All other errors are fatal.
  494. *
  495. * Returns:
  496. * 0 on success, negative error code on failure.
  497. */
  498. int drm_atomic_check_only(struct drm_atomic_state *state)
  499. {
  500. struct drm_mode_config *config = &state->dev->mode_config;
  501. DRM_DEBUG_KMS("checking %p\n", state);
  502. if (config->funcs->atomic_check)
  503. return config->funcs->atomic_check(state->dev, state);
  504. else
  505. return 0;
  506. }
  507. EXPORT_SYMBOL(drm_atomic_check_only);
  508. /**
  509. * drm_atomic_commit - commit configuration atomically
  510. * @state: atomic configuration to check
  511. *
  512. * Note that this function can return -EDEADLK if the driver needed to acquire
  513. * more locks but encountered a deadlock. The caller must then do the usual w/w
  514. * backoff dance and restart. All other errors are fatal.
  515. *
  516. * Also note that on successful execution ownership of @state is transferred
  517. * from the caller of this function to the function itself. The caller must not
  518. * free or in any other way access @state. If the function fails then the caller
  519. * must clean up @state itself.
  520. *
  521. * Returns:
  522. * 0 on success, negative error code on failure.
  523. */
  524. int drm_atomic_commit(struct drm_atomic_state *state)
  525. {
  526. struct drm_mode_config *config = &state->dev->mode_config;
  527. int ret;
  528. ret = drm_atomic_check_only(state);
  529. if (ret)
  530. return ret;
  531. DRM_DEBUG_KMS("commiting %p\n", state);
  532. return config->funcs->atomic_commit(state->dev, state, false);
  533. }
  534. EXPORT_SYMBOL(drm_atomic_commit);
  535. /**
  536. * drm_atomic_async_commit - atomic&async configuration commit
  537. * @state: atomic configuration to check
  538. *
  539. * Note that this function can return -EDEADLK if the driver needed to acquire
  540. * more locks but encountered a deadlock. The caller must then do the usual w/w
  541. * backoff dance and restart. All other errors are fatal.
  542. *
  543. * Also note that on successful execution ownership of @state is transferred
  544. * from the caller of this function to the function itself. The caller must not
  545. * free or in any other way access @state. If the function fails then the caller
  546. * must clean up @state itself.
  547. *
  548. * Returns:
  549. * 0 on success, negative error code on failure.
  550. */
  551. int drm_atomic_async_commit(struct drm_atomic_state *state)
  552. {
  553. struct drm_mode_config *config = &state->dev->mode_config;
  554. int ret;
  555. ret = drm_atomic_check_only(state);
  556. if (ret)
  557. return ret;
  558. DRM_DEBUG_KMS("commiting %p asynchronously\n", state);
  559. return config->funcs->atomic_commit(state->dev, state, true);
  560. }
  561. EXPORT_SYMBOL(drm_atomic_async_commit);