drm_atomic.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  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. #ifndef DRM_ATOMIC_H_
  28. #define DRM_ATOMIC_H_
  29. #include <drm/drm_crtc.h>
  30. /**
  31. * struct drm_crtc_commit - track modeset commits on a CRTC
  32. *
  33. * This structure is used to track pending modeset changes and atomic commit on
  34. * a per-CRTC basis. Since updating the list should never block this structure
  35. * is reference counted to allow waiters to safely wait on an event to complete,
  36. * without holding any locks.
  37. *
  38. * It has 3 different events in total to allow a fine-grained synchronization
  39. * between outstanding updates::
  40. *
  41. * atomic commit thread hardware
  42. *
  43. * write new state into hardware ----> ...
  44. * signal hw_done
  45. * switch to new state on next
  46. * ... v/hblank
  47. *
  48. * wait for buffers to show up ...
  49. *
  50. * ... send completion irq
  51. * irq handler signals flip_done
  52. * cleanup old buffers
  53. *
  54. * signal cleanup_done
  55. *
  56. * wait for flip_done <----
  57. * clean up atomic state
  58. *
  59. * The important bit to know is that cleanup_done is the terminal event, but the
  60. * ordering between flip_done and hw_done is entirely up to the specific driver
  61. * and modeset state change.
  62. *
  63. * For an implementation of how to use this look at
  64. * drm_atomic_helper_setup_commit() from the atomic helper library.
  65. */
  66. struct drm_crtc_commit {
  67. /**
  68. * @crtc:
  69. *
  70. * DRM CRTC for this commit.
  71. */
  72. struct drm_crtc *crtc;
  73. /**
  74. * @ref:
  75. *
  76. * Reference count for this structure. Needed to allow blocking on
  77. * completions without the risk of the completion disappearing
  78. * meanwhile.
  79. */
  80. struct kref ref;
  81. /**
  82. * @flip_done:
  83. *
  84. * Will be signaled when the hardware has flipped to the new set of
  85. * buffers. Signals at the same time as when the drm event for this
  86. * commit is sent to userspace, or when an out-fence is singalled. Note
  87. * that for most hardware, in most cases this happens after @hw_done is
  88. * signalled.
  89. */
  90. struct completion flip_done;
  91. /**
  92. * @hw_done:
  93. *
  94. * Will be signalled when all hw register changes for this commit have
  95. * been written out. Especially when disabling a pipe this can be much
  96. * later than than @flip_done, since that can signal already when the
  97. * screen goes black, whereas to fully shut down a pipe more register
  98. * I/O is required.
  99. *
  100. * Note that this does not need to include separately reference-counted
  101. * resources like backing storage buffer pinning, or runtime pm
  102. * management.
  103. */
  104. struct completion hw_done;
  105. /**
  106. * @cleanup_done:
  107. *
  108. * Will be signalled after old buffers have been cleaned up by calling
  109. * drm_atomic_helper_cleanup_planes(). Since this can only happen after
  110. * a vblank wait completed it might be a bit later. This completion is
  111. * useful to throttle updates and avoid hardware updates getting ahead
  112. * of the buffer cleanup too much.
  113. */
  114. struct completion cleanup_done;
  115. /**
  116. * @commit_entry:
  117. *
  118. * Entry on the per-CRTC &drm_crtc.commit_list. Protected by
  119. * $drm_crtc.commit_lock.
  120. */
  121. struct list_head commit_entry;
  122. /**
  123. * @event:
  124. *
  125. * &drm_pending_vblank_event pointer to clean up private events.
  126. */
  127. struct drm_pending_vblank_event *event;
  128. };
  129. struct __drm_planes_state {
  130. struct drm_plane *ptr;
  131. struct drm_plane_state *state, *old_state, *new_state;
  132. };
  133. struct __drm_crtcs_state {
  134. struct drm_crtc *ptr;
  135. struct drm_crtc_state *state, *old_state, *new_state;
  136. struct drm_crtc_commit *commit;
  137. s32 __user *out_fence_ptr;
  138. unsigned last_vblank_count;
  139. };
  140. struct __drm_connnectors_state {
  141. struct drm_connector *ptr;
  142. struct drm_connector_state *state, *old_state, *new_state;
  143. };
  144. /**
  145. * struct drm_atomic_state - the global state object for atomic updates
  146. * @ref: count of all references to this state (will not be freed until zero)
  147. * @dev: parent DRM device
  148. * @allow_modeset: allow full modeset
  149. * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
  150. * @planes: pointer to array of structures with per-plane data
  151. * @crtcs: pointer to array of CRTC pointers
  152. * @num_connector: size of the @connectors and @connector_states arrays
  153. * @connectors: pointer to array of structures with per-connector data
  154. * @acquire_ctx: acquire context for this atomic modeset state update
  155. */
  156. struct drm_atomic_state {
  157. struct kref ref;
  158. struct drm_device *dev;
  159. bool allow_modeset : 1;
  160. bool legacy_cursor_update : 1;
  161. struct __drm_planes_state *planes;
  162. struct __drm_crtcs_state *crtcs;
  163. int num_connector;
  164. struct __drm_connnectors_state *connectors;
  165. struct drm_modeset_acquire_ctx *acquire_ctx;
  166. /**
  167. * @commit_work:
  168. *
  169. * Work item which can be used by the driver or helpers to execute the
  170. * commit without blocking.
  171. */
  172. struct work_struct commit_work;
  173. };
  174. void __drm_crtc_commit_free(struct kref *kref);
  175. /**
  176. * drm_crtc_commit_get - acquire a reference to the CRTC commit
  177. * @commit: CRTC commit
  178. *
  179. * Increases the reference of @commit.
  180. */
  181. static inline void drm_crtc_commit_get(struct drm_crtc_commit *commit)
  182. {
  183. kref_get(&commit->ref);
  184. }
  185. /**
  186. * drm_crtc_commit_put - release a reference to the CRTC commmit
  187. * @commit: CRTC commit
  188. *
  189. * This releases a reference to @commit which is freed after removing the
  190. * final reference. No locking required and callable from any context.
  191. */
  192. static inline void drm_crtc_commit_put(struct drm_crtc_commit *commit)
  193. {
  194. kref_put(&commit->ref, __drm_crtc_commit_free);
  195. }
  196. struct drm_atomic_state * __must_check
  197. drm_atomic_state_alloc(struct drm_device *dev);
  198. void drm_atomic_state_clear(struct drm_atomic_state *state);
  199. /**
  200. * drm_atomic_state_get - acquire a reference to the atomic state
  201. * @state: The atomic state
  202. *
  203. * Returns a new reference to the @state
  204. */
  205. static inline struct drm_atomic_state *
  206. drm_atomic_state_get(struct drm_atomic_state *state)
  207. {
  208. kref_get(&state->ref);
  209. return state;
  210. }
  211. void __drm_atomic_state_free(struct kref *ref);
  212. /**
  213. * drm_atomic_state_put - release a reference to the atomic state
  214. * @state: The atomic state
  215. *
  216. * This releases a reference to @state which is freed after removing the
  217. * final reference. No locking required and callable from any context.
  218. */
  219. static inline void drm_atomic_state_put(struct drm_atomic_state *state)
  220. {
  221. kref_put(&state->ref, __drm_atomic_state_free);
  222. }
  223. int __must_check
  224. drm_atomic_state_init(struct drm_device *dev, struct drm_atomic_state *state);
  225. void drm_atomic_state_default_clear(struct drm_atomic_state *state);
  226. void drm_atomic_state_default_release(struct drm_atomic_state *state);
  227. struct drm_crtc_state * __must_check
  228. drm_atomic_get_crtc_state(struct drm_atomic_state *state,
  229. struct drm_crtc *crtc);
  230. int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
  231. struct drm_crtc_state *state, struct drm_property *property,
  232. uint64_t val);
  233. struct drm_plane_state * __must_check
  234. drm_atomic_get_plane_state(struct drm_atomic_state *state,
  235. struct drm_plane *plane);
  236. int drm_atomic_plane_set_property(struct drm_plane *plane,
  237. struct drm_plane_state *state, struct drm_property *property,
  238. uint64_t val);
  239. struct drm_connector_state * __must_check
  240. drm_atomic_get_connector_state(struct drm_atomic_state *state,
  241. struct drm_connector *connector);
  242. int drm_atomic_connector_set_property(struct drm_connector *connector,
  243. struct drm_connector_state *state, struct drm_property *property,
  244. uint64_t val);
  245. /**
  246. * drm_atomic_get_existing_crtc_state - get crtc state, if it exists
  247. * @state: global atomic state object
  248. * @crtc: crtc to grab
  249. *
  250. * This function returns the crtc state for the given crtc, or NULL
  251. * if the crtc is not part of the global atomic state.
  252. *
  253. * This function is deprecated, @drm_atomic_get_old_crtc_state or
  254. * @drm_atomic_get_new_crtc_state should be used instead.
  255. */
  256. static inline struct drm_crtc_state *
  257. drm_atomic_get_existing_crtc_state(struct drm_atomic_state *state,
  258. struct drm_crtc *crtc)
  259. {
  260. return state->crtcs[drm_crtc_index(crtc)].state;
  261. }
  262. /**
  263. * drm_atomic_get_old_crtc_state - get old crtc state, if it exists
  264. * @state: global atomic state object
  265. * @crtc: crtc to grab
  266. *
  267. * This function returns the old crtc state for the given crtc, or
  268. * NULL if the crtc is not part of the global atomic state.
  269. */
  270. static inline struct drm_crtc_state *
  271. drm_atomic_get_old_crtc_state(struct drm_atomic_state *state,
  272. struct drm_crtc *crtc)
  273. {
  274. return state->crtcs[drm_crtc_index(crtc)].old_state;
  275. }
  276. /**
  277. * drm_atomic_get_new_crtc_state - get new crtc state, if it exists
  278. * @state: global atomic state object
  279. * @crtc: crtc to grab
  280. *
  281. * This function returns the new crtc state for the given crtc, or
  282. * NULL if the crtc is not part of the global atomic state.
  283. */
  284. static inline struct drm_crtc_state *
  285. drm_atomic_get_new_crtc_state(struct drm_atomic_state *state,
  286. struct drm_crtc *crtc)
  287. {
  288. return state->crtcs[drm_crtc_index(crtc)].new_state;
  289. }
  290. /**
  291. * drm_atomic_get_existing_plane_state - get plane state, if it exists
  292. * @state: global atomic state object
  293. * @plane: plane to grab
  294. *
  295. * This function returns the plane state for the given plane, or NULL
  296. * if the plane is not part of the global atomic state.
  297. *
  298. * This function is deprecated, @drm_atomic_get_old_plane_state or
  299. * @drm_atomic_get_new_plane_state should be used instead.
  300. */
  301. static inline struct drm_plane_state *
  302. drm_atomic_get_existing_plane_state(struct drm_atomic_state *state,
  303. struct drm_plane *plane)
  304. {
  305. return state->planes[drm_plane_index(plane)].state;
  306. }
  307. /**
  308. * drm_atomic_get_old_plane_state - get plane state, if it exists
  309. * @state: global atomic state object
  310. * @plane: plane to grab
  311. *
  312. * This function returns the old plane state for the given plane, or
  313. * NULL if the plane is not part of the global atomic state.
  314. */
  315. static inline struct drm_plane_state *
  316. drm_atomic_get_old_plane_state(struct drm_atomic_state *state,
  317. struct drm_plane *plane)
  318. {
  319. return state->planes[drm_plane_index(plane)].old_state;
  320. }
  321. /**
  322. * drm_atomic_get_new_plane_state - get plane state, if it exists
  323. * @state: global atomic state object
  324. * @plane: plane to grab
  325. *
  326. * This function returns the new plane state for the given plane, or
  327. * NULL if the plane is not part of the global atomic state.
  328. */
  329. static inline struct drm_plane_state *
  330. drm_atomic_get_new_plane_state(struct drm_atomic_state *state,
  331. struct drm_plane *plane)
  332. {
  333. return state->planes[drm_plane_index(plane)].new_state;
  334. }
  335. /**
  336. * drm_atomic_get_existing_connector_state - get connector state, if it exists
  337. * @state: global atomic state object
  338. * @connector: connector to grab
  339. *
  340. * This function returns the connector state for the given connector,
  341. * or NULL if the connector is not part of the global atomic state.
  342. *
  343. * This function is deprecated, @drm_atomic_get_old_connector_state or
  344. * @drm_atomic_get_new_connector_state should be used instead.
  345. */
  346. static inline struct drm_connector_state *
  347. drm_atomic_get_existing_connector_state(struct drm_atomic_state *state,
  348. struct drm_connector *connector)
  349. {
  350. int index = drm_connector_index(connector);
  351. if (index >= state->num_connector)
  352. return NULL;
  353. return state->connectors[index].state;
  354. }
  355. /**
  356. * drm_atomic_get_old_connector_state - get connector state, if it exists
  357. * @state: global atomic state object
  358. * @connector: connector to grab
  359. *
  360. * This function returns the old connector state for the given connector,
  361. * or NULL if the connector is not part of the global atomic state.
  362. */
  363. static inline struct drm_connector_state *
  364. drm_atomic_get_old_connector_state(struct drm_atomic_state *state,
  365. struct drm_connector *connector)
  366. {
  367. int index = drm_connector_index(connector);
  368. if (index >= state->num_connector)
  369. return NULL;
  370. return state->connectors[index].old_state;
  371. }
  372. /**
  373. * drm_atomic_get_new_connector_state - get connector state, if it exists
  374. * @state: global atomic state object
  375. * @connector: connector to grab
  376. *
  377. * This function returns the new connector state for the given connector,
  378. * or NULL if the connector is not part of the global atomic state.
  379. */
  380. static inline struct drm_connector_state *
  381. drm_atomic_get_new_connector_state(struct drm_atomic_state *state,
  382. struct drm_connector *connector)
  383. {
  384. int index = drm_connector_index(connector);
  385. if (index >= state->num_connector)
  386. return NULL;
  387. return state->connectors[index].new_state;
  388. }
  389. /**
  390. * __drm_atomic_get_current_plane_state - get current plane state
  391. * @state: global atomic state object
  392. * @plane: plane to grab
  393. *
  394. * This function returns the plane state for the given plane, either from
  395. * @state, or if the plane isn't part of the atomic state update, from @plane.
  396. * This is useful in atomic check callbacks, when drivers need to peek at, but
  397. * not change, state of other planes, since it avoids threading an error code
  398. * back up the call chain.
  399. *
  400. * WARNING:
  401. *
  402. * Note that this function is in general unsafe since it doesn't check for the
  403. * required locking for access state structures. Drivers must ensure that it is
  404. * safe to access the returned state structure through other means. One common
  405. * example is when planes are fixed to a single CRTC, and the driver knows that
  406. * the CRTC lock is held already. In that case holding the CRTC lock gives a
  407. * read-lock on all planes connected to that CRTC. But if planes can be
  408. * reassigned things get more tricky. In that case it's better to use
  409. * drm_atomic_get_plane_state and wire up full error handling.
  410. *
  411. * Returns:
  412. *
  413. * Read-only pointer to the current plane state.
  414. */
  415. static inline const struct drm_plane_state *
  416. __drm_atomic_get_current_plane_state(struct drm_atomic_state *state,
  417. struct drm_plane *plane)
  418. {
  419. if (state->planes[drm_plane_index(plane)].state)
  420. return state->planes[drm_plane_index(plane)].state;
  421. return plane->state;
  422. }
  423. int __must_check
  424. drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state,
  425. struct drm_display_mode *mode);
  426. int __must_check
  427. drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state,
  428. struct drm_property_blob *blob);
  429. int __must_check
  430. drm_atomic_set_crtc_for_plane(struct drm_plane_state *plane_state,
  431. struct drm_crtc *crtc);
  432. void drm_atomic_set_fb_for_plane(struct drm_plane_state *plane_state,
  433. struct drm_framebuffer *fb);
  434. void drm_atomic_set_fence_for_plane(struct drm_plane_state *plane_state,
  435. struct dma_fence *fence);
  436. int __must_check
  437. drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state,
  438. struct drm_crtc *crtc);
  439. int __must_check
  440. drm_atomic_add_affected_connectors(struct drm_atomic_state *state,
  441. struct drm_crtc *crtc);
  442. int __must_check
  443. drm_atomic_add_affected_planes(struct drm_atomic_state *state,
  444. struct drm_crtc *crtc);
  445. void drm_atomic_legacy_backoff(struct drm_atomic_state *state);
  446. void
  447. drm_atomic_clean_old_fb(struct drm_device *dev, unsigned plane_mask, int ret);
  448. int __must_check drm_atomic_check_only(struct drm_atomic_state *state);
  449. int __must_check drm_atomic_commit(struct drm_atomic_state *state);
  450. int __must_check drm_atomic_nonblocking_commit(struct drm_atomic_state *state);
  451. void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
  452. /**
  453. * for_each_connector_in_state - iterate over all connectors in an atomic update
  454. * @__state: &struct drm_atomic_state pointer
  455. * @connector: &struct drm_connector iteration cursor
  456. * @connector_state: &struct drm_connector_state iteration cursor
  457. * @__i: int iteration cursor, for macro-internal use
  458. *
  459. * This iterates over all connectors in an atomic update. Note that before the
  460. * software state is committed (by calling drm_atomic_helper_swap_state(), this
  461. * points to the new state, while afterwards it points to the old state. Due to
  462. * this tricky confusion this macro is deprecated.
  463. *
  464. * FIXME:
  465. *
  466. * Replace all usage of this with one of the explicit iterators below and then
  467. * remove this macro.
  468. */
  469. #define for_each_connector_in_state(__state, connector, connector_state, __i) \
  470. for ((__i) = 0; \
  471. (__i) < (__state)->num_connector && \
  472. ((connector) = (__state)->connectors[__i].ptr, \
  473. (connector_state) = (__state)->connectors[__i].state, 1); \
  474. (__i)++) \
  475. for_each_if (connector)
  476. /**
  477. * for_each_oldnew_connector_in_state - iterate over all connectors in an atomic update
  478. * @__state: &struct drm_atomic_state pointer
  479. * @connector: &struct drm_connector iteration cursor
  480. * @old_connector_state: &struct drm_connector_state iteration cursor for the
  481. * old state
  482. * @new_connector_state: &struct drm_connector_state iteration cursor for the
  483. * new state
  484. * @__i: int iteration cursor, for macro-internal use
  485. *
  486. * This iterates over all connectors in an atomic update, tracking both old and
  487. * new state. This is useful in places where the state delta needs to be
  488. * considered, for example in atomic check functions.
  489. */
  490. #define for_each_oldnew_connector_in_state(__state, connector, old_connector_state, new_connector_state, __i) \
  491. for ((__i) = 0; \
  492. (__i) < (__state)->num_connector && \
  493. ((connector) = (__state)->connectors[__i].ptr, \
  494. (old_connector_state) = (__state)->connectors[__i].old_state, \
  495. (new_connector_state) = (__state)->connectors[__i].new_state, 1); \
  496. (__i)++) \
  497. for_each_if (connector)
  498. /**
  499. * for_each_old_connector_in_state - iterate over all connectors in an atomic update
  500. * @__state: &struct drm_atomic_state pointer
  501. * @connector: &struct drm_connector iteration cursor
  502. * @old_connector_state: &struct drm_connector_state iteration cursor for the
  503. * old state
  504. * @__i: int iteration cursor, for macro-internal use
  505. *
  506. * This iterates over all connectors in an atomic update, tracking only the old
  507. * state. This is useful in disable functions, where we need the old state the
  508. * hardware is still in.
  509. */
  510. #define for_each_old_connector_in_state(__state, connector, old_connector_state, __i) \
  511. for ((__i) = 0; \
  512. (__i) < (__state)->num_connector && \
  513. ((connector) = (__state)->connectors[__i].ptr, \
  514. (old_connector_state) = (__state)->connectors[__i].old_state, 1); \
  515. (__i)++) \
  516. for_each_if (connector)
  517. /**
  518. * for_each_new_connector_in_state - iterate over all connectors in an atomic update
  519. * @__state: &struct drm_atomic_state pointer
  520. * @connector: &struct drm_connector iteration cursor
  521. * @new_connector_state: &struct drm_connector_state iteration cursor for the
  522. * new state
  523. * @__i: int iteration cursor, for macro-internal use
  524. *
  525. * This iterates over all connectors in an atomic update, tracking only the new
  526. * state. This is useful in enable functions, where we need the new state the
  527. * hardware should be in when the atomic commit operation has completed.
  528. */
  529. #define for_each_new_connector_in_state(__state, connector, new_connector_state, __i) \
  530. for ((__i) = 0; \
  531. (__i) < (__state)->num_connector && \
  532. ((connector) = (__state)->connectors[__i].ptr, \
  533. (new_connector_state) = (__state)->connectors[__i].new_state, 1); \
  534. (__i)++) \
  535. for_each_if (connector)
  536. /**
  537. * for_each_crtc_in_state - iterate over all connectors in an atomic update
  538. * @__state: &struct drm_atomic_state pointer
  539. * @crtc: &struct drm_crtc iteration cursor
  540. * @crtc_state: &struct drm_crtc_state iteration cursor
  541. * @__i: int iteration cursor, for macro-internal use
  542. *
  543. * This iterates over all CRTCs in an atomic update. Note that before the
  544. * software state is committed (by calling drm_atomic_helper_swap_state(), this
  545. * points to the new state, while afterwards it points to the old state. Due to
  546. * this tricky confusion this macro is deprecated.
  547. *
  548. * FIXME:
  549. *
  550. * Replace all usage of this with one of the explicit iterators below and then
  551. * remove this macro.
  552. */
  553. #define for_each_crtc_in_state(__state, crtc, crtc_state, __i) \
  554. for ((__i) = 0; \
  555. (__i) < (__state)->dev->mode_config.num_crtc && \
  556. ((crtc) = (__state)->crtcs[__i].ptr, \
  557. (crtc_state) = (__state)->crtcs[__i].state, 1); \
  558. (__i)++) \
  559. for_each_if (crtc_state)
  560. /**
  561. * for_each_oldnew_crtc_in_state - iterate over all CRTCs in an atomic update
  562. * @__state: &struct drm_atomic_state pointer
  563. * @crtc: &struct drm_crtc iteration cursor
  564. * @old_crtc_state: &struct drm_crtc_state iteration cursor for the old state
  565. * @new_crtc_state: &struct drm_crtc_state iteration cursor for the new state
  566. * @__i: int iteration cursor, for macro-internal use
  567. *
  568. * This iterates over all CRTCs in an atomic update, tracking both old and
  569. * new state. This is useful in places where the state delta needs to be
  570. * considered, for example in atomic check functions.
  571. */
  572. #define for_each_oldnew_crtc_in_state(__state, crtc, old_crtc_state, new_crtc_state, __i) \
  573. for ((__i) = 0; \
  574. (__i) < (__state)->dev->mode_config.num_crtc && \
  575. ((crtc) = (__state)->crtcs[__i].ptr, \
  576. (old_crtc_state) = (__state)->crtcs[__i].old_state, \
  577. (new_crtc_state) = (__state)->crtcs[__i].new_state, 1); \
  578. (__i)++) \
  579. for_each_if (crtc)
  580. /**
  581. * for_each_old_crtc_in_state - iterate over all CRTCs in an atomic update
  582. * @__state: &struct drm_atomic_state pointer
  583. * @crtc: &struct drm_crtc iteration cursor
  584. * @old_crtc_state: &struct drm_crtc_state iteration cursor for the old state
  585. * @__i: int iteration cursor, for macro-internal use
  586. *
  587. * This iterates over all CRTCs in an atomic update, tracking only the old
  588. * state. This is useful in disable functions, where we need the old state the
  589. * hardware is still in.
  590. */
  591. #define for_each_old_crtc_in_state(__state, crtc, old_crtc_state, __i) \
  592. for ((__i) = 0; \
  593. (__i) < (__state)->dev->mode_config.num_crtc && \
  594. ((crtc) = (__state)->crtcs[__i].ptr, \
  595. (old_crtc_state) = (__state)->crtcs[__i].old_state, 1); \
  596. (__i)++) \
  597. for_each_if (crtc)
  598. /**
  599. * for_each_new_crtc_in_state - iterate over all CRTCs in an atomic update
  600. * @__state: &struct drm_atomic_state pointer
  601. * @crtc: &struct drm_crtc iteration cursor
  602. * @new_crtc_state: &struct drm_crtc_state iteration cursor for the new state
  603. * @__i: int iteration cursor, for macro-internal use
  604. *
  605. * This iterates over all CRTCs in an atomic update, tracking only the new
  606. * state. This is useful in enable functions, where we need the new state the
  607. * hardware should be in when the atomic commit operation has completed.
  608. */
  609. #define for_each_new_crtc_in_state(__state, crtc, new_crtc_state, __i) \
  610. for ((__i) = 0; \
  611. (__i) < (__state)->dev->mode_config.num_crtc && \
  612. ((crtc) = (__state)->crtcs[__i].ptr, \
  613. (new_crtc_state) = (__state)->crtcs[__i].new_state, 1); \
  614. (__i)++) \
  615. for_each_if (crtc)
  616. /**
  617. * for_each_plane_in_state - iterate over all planes in an atomic update
  618. * @__state: &struct drm_atomic_state pointer
  619. * @plane: &struct drm_plane iteration cursor
  620. * @plane_state: &struct drm_plane_state iteration cursor
  621. * @__i: int iteration cursor, for macro-internal use
  622. *
  623. * This iterates over all planes in an atomic update. Note that before the
  624. * software state is committed (by calling drm_atomic_helper_swap_state(), this
  625. * points to the new state, while afterwards it points to the old state. Due to
  626. * this tricky confusion this macro is deprecated.
  627. *
  628. * FIXME:
  629. *
  630. * Replace all usage of this with one of the explicit iterators below and then
  631. * remove this macro.
  632. */
  633. #define for_each_plane_in_state(__state, plane, plane_state, __i) \
  634. for ((__i) = 0; \
  635. (__i) < (__state)->dev->mode_config.num_total_plane && \
  636. ((plane) = (__state)->planes[__i].ptr, \
  637. (plane_state) = (__state)->planes[__i].state, 1); \
  638. (__i)++) \
  639. for_each_if (plane_state)
  640. /**
  641. * for_each_oldnew_plane_in_state - iterate over all planes in an atomic update
  642. * @__state: &struct drm_atomic_state pointer
  643. * @plane: &struct drm_plane iteration cursor
  644. * @old_plane_state: &struct drm_plane_state iteration cursor for the old state
  645. * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
  646. * @__i: int iteration cursor, for macro-internal use
  647. *
  648. * This iterates over all planes in an atomic update, tracking both old and
  649. * new state. This is useful in places where the state delta needs to be
  650. * considered, for example in atomic check functions.
  651. */
  652. #define for_each_oldnew_plane_in_state(__state, plane, old_plane_state, new_plane_state, __i) \
  653. for ((__i) = 0; \
  654. (__i) < (__state)->dev->mode_config.num_total_plane && \
  655. ((plane) = (__state)->planes[__i].ptr, \
  656. (old_plane_state) = (__state)->planes[__i].old_state, \
  657. (new_plane_state) = (__state)->planes[__i].new_state, 1); \
  658. (__i)++) \
  659. for_each_if (plane)
  660. /**
  661. * for_each_old_plane_in_state - iterate over all planes in an atomic update
  662. * @__state: &struct drm_atomic_state pointer
  663. * @plane: &struct drm_plane iteration cursor
  664. * @old_plane_state: &struct drm_plane_state iteration cursor for the old state
  665. * @__i: int iteration cursor, for macro-internal use
  666. *
  667. * This iterates over all planes in an atomic update, tracking only the old
  668. * state. This is useful in disable functions, where we need the old state the
  669. * hardware is still in.
  670. */
  671. #define for_each_old_plane_in_state(__state, plane, old_plane_state, __i) \
  672. for ((__i) = 0; \
  673. (__i) < (__state)->dev->mode_config.num_total_plane && \
  674. ((plane) = (__state)->planes[__i].ptr, \
  675. (old_plane_state) = (__state)->planes[__i].old_state, 1); \
  676. (__i)++) \
  677. for_each_if (plane)
  678. /**
  679. * for_each_new_plane_in_state - iterate over all planes in an atomic update
  680. * @__state: &struct drm_atomic_state pointer
  681. * @plane: &struct drm_plane iteration cursor
  682. * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
  683. * @__i: int iteration cursor, for macro-internal use
  684. *
  685. * This iterates over all planes in an atomic update, tracking only the new
  686. * state. This is useful in enable functions, where we need the new state the
  687. * hardware should be in when the atomic commit operation has completed.
  688. */
  689. #define for_each_new_plane_in_state(__state, plane, new_plane_state, __i) \
  690. for ((__i) = 0; \
  691. (__i) < (__state)->dev->mode_config.num_total_plane && \
  692. ((plane) = (__state)->planes[__i].ptr, \
  693. (new_plane_state) = (__state)->planes[__i].new_state, 1); \
  694. (__i)++) \
  695. for_each_if (plane)
  696. /**
  697. * drm_atomic_crtc_needs_modeset - compute combined modeset need
  698. * @state: &drm_crtc_state for the CRTC
  699. *
  700. * To give drivers flexibility &struct drm_crtc_state has 3 booleans to track
  701. * whether the state CRTC changed enough to need a full modeset cycle:
  702. * planes_changed, mode_changed and active_changed. This helper simply
  703. * combines these three to compute the overall need for a modeset for @state.
  704. *
  705. * The atomic helper code sets these booleans, but drivers can and should
  706. * change them appropriately to accurately represent whether a modeset is
  707. * really needed. In general, drivers should avoid full modesets whenever
  708. * possible.
  709. *
  710. * For example if the CRTC mode has changed, and the hardware is able to enact
  711. * the requested mode change without going through a full modeset, the driver
  712. * should clear mode_changed in its &drm_mode_config_funcs.atomic_check
  713. * implementation.
  714. */
  715. static inline bool
  716. drm_atomic_crtc_needs_modeset(const struct drm_crtc_state *state)
  717. {
  718. return state->mode_changed || state->active_changed ||
  719. state->connectors_changed;
  720. }
  721. #endif /* DRM_ATOMIC_H_ */