drm_atomic.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898
  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. struct drm_private_obj;
  145. struct drm_private_state;
  146. /**
  147. * struct drm_private_state_funcs - atomic state functions for private objects
  148. *
  149. * These hooks are used by atomic helpers to create, swap and destroy states of
  150. * private objects. The structure itself is used as a vtable to identify the
  151. * associated private object type. Each private object type that needs to be
  152. * added to the atomic states is expected to have an implementation of these
  153. * hooks and pass a pointer to it's drm_private_state_funcs struct to
  154. * drm_atomic_get_private_obj_state().
  155. */
  156. struct drm_private_state_funcs {
  157. /**
  158. * @atomic_duplicate_state:
  159. *
  160. * Duplicate the current state of the private object and return it. It
  161. * is an error to call this before obj->state has been initialized.
  162. *
  163. * RETURNS:
  164. *
  165. * Duplicated atomic state or NULL when obj->state is not
  166. * initialized or allocation failed.
  167. */
  168. struct drm_private_state *(*atomic_duplicate_state)(struct drm_private_obj *obj);
  169. /**
  170. * @atomic_destroy_state:
  171. *
  172. * Frees the private object state created with @atomic_duplicate_state.
  173. */
  174. void (*atomic_destroy_state)(struct drm_private_obj *obj,
  175. struct drm_private_state *state);
  176. };
  177. struct drm_private_obj {
  178. struct drm_private_state *state;
  179. const struct drm_private_state_funcs *funcs;
  180. };
  181. struct drm_private_state {
  182. struct drm_atomic_state *state;
  183. };
  184. struct __drm_private_objs_state {
  185. struct drm_private_obj *ptr;
  186. struct drm_private_state *state, *old_state, *new_state;
  187. };
  188. /**
  189. * struct drm_atomic_state - the global state object for atomic updates
  190. * @ref: count of all references to this state (will not be freed until zero)
  191. * @dev: parent DRM device
  192. * @allow_modeset: allow full modeset
  193. * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
  194. * @async_update: hint for asynchronous plane update
  195. * @planes: pointer to array of structures with per-plane data
  196. * @crtcs: pointer to array of CRTC pointers
  197. * @num_connector: size of the @connectors and @connector_states arrays
  198. * @connectors: pointer to array of structures with per-connector data
  199. * @num_private_objs: size of the @private_objs array
  200. * @private_objs: pointer to array of private object pointers
  201. * @acquire_ctx: acquire context for this atomic modeset state update
  202. */
  203. struct drm_atomic_state {
  204. struct kref ref;
  205. struct drm_device *dev;
  206. bool allow_modeset : 1;
  207. bool legacy_cursor_update : 1;
  208. bool async_update : 1;
  209. struct __drm_planes_state *planes;
  210. struct __drm_crtcs_state *crtcs;
  211. int num_connector;
  212. struct __drm_connnectors_state *connectors;
  213. int num_private_objs;
  214. struct __drm_private_objs_state *private_objs;
  215. struct drm_modeset_acquire_ctx *acquire_ctx;
  216. /**
  217. * @commit_work:
  218. *
  219. * Work item which can be used by the driver or helpers to execute the
  220. * commit without blocking.
  221. */
  222. struct work_struct commit_work;
  223. };
  224. void __drm_crtc_commit_free(struct kref *kref);
  225. /**
  226. * drm_crtc_commit_get - acquire a reference to the CRTC commit
  227. * @commit: CRTC commit
  228. *
  229. * Increases the reference of @commit.
  230. */
  231. static inline void drm_crtc_commit_get(struct drm_crtc_commit *commit)
  232. {
  233. kref_get(&commit->ref);
  234. }
  235. /**
  236. * drm_crtc_commit_put - release a reference to the CRTC commmit
  237. * @commit: CRTC commit
  238. *
  239. * This releases a reference to @commit which is freed after removing the
  240. * final reference. No locking required and callable from any context.
  241. */
  242. static inline void drm_crtc_commit_put(struct drm_crtc_commit *commit)
  243. {
  244. kref_put(&commit->ref, __drm_crtc_commit_free);
  245. }
  246. struct drm_atomic_state * __must_check
  247. drm_atomic_state_alloc(struct drm_device *dev);
  248. void drm_atomic_state_clear(struct drm_atomic_state *state);
  249. /**
  250. * drm_atomic_state_get - acquire a reference to the atomic state
  251. * @state: The atomic state
  252. *
  253. * Returns a new reference to the @state
  254. */
  255. static inline struct drm_atomic_state *
  256. drm_atomic_state_get(struct drm_atomic_state *state)
  257. {
  258. kref_get(&state->ref);
  259. return state;
  260. }
  261. void __drm_atomic_state_free(struct kref *ref);
  262. /**
  263. * drm_atomic_state_put - release a reference to the atomic state
  264. * @state: The atomic state
  265. *
  266. * This releases a reference to @state which is freed after removing the
  267. * final reference. No locking required and callable from any context.
  268. */
  269. static inline void drm_atomic_state_put(struct drm_atomic_state *state)
  270. {
  271. kref_put(&state->ref, __drm_atomic_state_free);
  272. }
  273. int __must_check
  274. drm_atomic_state_init(struct drm_device *dev, struct drm_atomic_state *state);
  275. void drm_atomic_state_default_clear(struct drm_atomic_state *state);
  276. void drm_atomic_state_default_release(struct drm_atomic_state *state);
  277. struct drm_crtc_state * __must_check
  278. drm_atomic_get_crtc_state(struct drm_atomic_state *state,
  279. struct drm_crtc *crtc);
  280. int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
  281. struct drm_crtc_state *state, struct drm_property *property,
  282. uint64_t val);
  283. struct drm_plane_state * __must_check
  284. drm_atomic_get_plane_state(struct drm_atomic_state *state,
  285. struct drm_plane *plane);
  286. struct drm_connector_state * __must_check
  287. drm_atomic_get_connector_state(struct drm_atomic_state *state,
  288. struct drm_connector *connector);
  289. void drm_atomic_private_obj_init(struct drm_private_obj *obj,
  290. struct drm_private_state *state,
  291. const struct drm_private_state_funcs *funcs);
  292. void drm_atomic_private_obj_fini(struct drm_private_obj *obj);
  293. struct drm_private_state * __must_check
  294. drm_atomic_get_private_obj_state(struct drm_atomic_state *state,
  295. struct drm_private_obj *obj);
  296. /**
  297. * drm_atomic_get_existing_crtc_state - get crtc state, if it exists
  298. * @state: global atomic state object
  299. * @crtc: crtc to grab
  300. *
  301. * This function returns the crtc state for the given crtc, or NULL
  302. * if the crtc is not part of the global atomic state.
  303. *
  304. * This function is deprecated, @drm_atomic_get_old_crtc_state or
  305. * @drm_atomic_get_new_crtc_state should be used instead.
  306. */
  307. static inline struct drm_crtc_state *
  308. drm_atomic_get_existing_crtc_state(struct drm_atomic_state *state,
  309. struct drm_crtc *crtc)
  310. {
  311. return state->crtcs[drm_crtc_index(crtc)].state;
  312. }
  313. /**
  314. * drm_atomic_get_old_crtc_state - get old crtc state, if it exists
  315. * @state: global atomic state object
  316. * @crtc: crtc to grab
  317. *
  318. * This function returns the old crtc state for the given crtc, or
  319. * NULL if the crtc is not part of the global atomic state.
  320. */
  321. static inline struct drm_crtc_state *
  322. drm_atomic_get_old_crtc_state(struct drm_atomic_state *state,
  323. struct drm_crtc *crtc)
  324. {
  325. return state->crtcs[drm_crtc_index(crtc)].old_state;
  326. }
  327. /**
  328. * drm_atomic_get_new_crtc_state - get new crtc state, if it exists
  329. * @state: global atomic state object
  330. * @crtc: crtc to grab
  331. *
  332. * This function returns the new crtc state for the given crtc, or
  333. * NULL if the crtc is not part of the global atomic state.
  334. */
  335. static inline struct drm_crtc_state *
  336. drm_atomic_get_new_crtc_state(struct drm_atomic_state *state,
  337. struct drm_crtc *crtc)
  338. {
  339. return state->crtcs[drm_crtc_index(crtc)].new_state;
  340. }
  341. /**
  342. * drm_atomic_get_existing_plane_state - get plane state, if it exists
  343. * @state: global atomic state object
  344. * @plane: plane to grab
  345. *
  346. * This function returns the plane state for the given plane, or NULL
  347. * if the plane is not part of the global atomic state.
  348. *
  349. * This function is deprecated, @drm_atomic_get_old_plane_state or
  350. * @drm_atomic_get_new_plane_state should be used instead.
  351. */
  352. static inline struct drm_plane_state *
  353. drm_atomic_get_existing_plane_state(struct drm_atomic_state *state,
  354. struct drm_plane *plane)
  355. {
  356. return state->planes[drm_plane_index(plane)].state;
  357. }
  358. /**
  359. * drm_atomic_get_old_plane_state - get plane state, if it exists
  360. * @state: global atomic state object
  361. * @plane: plane to grab
  362. *
  363. * This function returns the old plane state for the given plane, or
  364. * NULL if the plane is not part of the global atomic state.
  365. */
  366. static inline struct drm_plane_state *
  367. drm_atomic_get_old_plane_state(struct drm_atomic_state *state,
  368. struct drm_plane *plane)
  369. {
  370. return state->planes[drm_plane_index(plane)].old_state;
  371. }
  372. /**
  373. * drm_atomic_get_new_plane_state - get plane state, if it exists
  374. * @state: global atomic state object
  375. * @plane: plane to grab
  376. *
  377. * This function returns the new plane state for the given plane, or
  378. * NULL if the plane is not part of the global atomic state.
  379. */
  380. static inline struct drm_plane_state *
  381. drm_atomic_get_new_plane_state(struct drm_atomic_state *state,
  382. struct drm_plane *plane)
  383. {
  384. return state->planes[drm_plane_index(plane)].new_state;
  385. }
  386. /**
  387. * drm_atomic_get_existing_connector_state - get connector state, if it exists
  388. * @state: global atomic state object
  389. * @connector: connector to grab
  390. *
  391. * This function returns the connector state for the given connector,
  392. * or NULL if the connector is not part of the global atomic state.
  393. *
  394. * This function is deprecated, @drm_atomic_get_old_connector_state or
  395. * @drm_atomic_get_new_connector_state should be used instead.
  396. */
  397. static inline struct drm_connector_state *
  398. drm_atomic_get_existing_connector_state(struct drm_atomic_state *state,
  399. struct drm_connector *connector)
  400. {
  401. int index = drm_connector_index(connector);
  402. if (index >= state->num_connector)
  403. return NULL;
  404. return state->connectors[index].state;
  405. }
  406. /**
  407. * drm_atomic_get_old_connector_state - get connector state, if it exists
  408. * @state: global atomic state object
  409. * @connector: connector to grab
  410. *
  411. * This function returns the old connector state for the given connector,
  412. * or NULL if the connector is not part of the global atomic state.
  413. */
  414. static inline struct drm_connector_state *
  415. drm_atomic_get_old_connector_state(struct drm_atomic_state *state,
  416. struct drm_connector *connector)
  417. {
  418. int index = drm_connector_index(connector);
  419. if (index >= state->num_connector)
  420. return NULL;
  421. return state->connectors[index].old_state;
  422. }
  423. /**
  424. * drm_atomic_get_new_connector_state - get connector state, if it exists
  425. * @state: global atomic state object
  426. * @connector: connector to grab
  427. *
  428. * This function returns the new connector state for the given connector,
  429. * or NULL if the connector is not part of the global atomic state.
  430. */
  431. static inline struct drm_connector_state *
  432. drm_atomic_get_new_connector_state(struct drm_atomic_state *state,
  433. struct drm_connector *connector)
  434. {
  435. int index = drm_connector_index(connector);
  436. if (index >= state->num_connector)
  437. return NULL;
  438. return state->connectors[index].new_state;
  439. }
  440. /**
  441. * __drm_atomic_get_current_plane_state - get current plane state
  442. * @state: global atomic state object
  443. * @plane: plane to grab
  444. *
  445. * This function returns the plane state for the given plane, either from
  446. * @state, or if the plane isn't part of the atomic state update, from @plane.
  447. * This is useful in atomic check callbacks, when drivers need to peek at, but
  448. * not change, state of other planes, since it avoids threading an error code
  449. * back up the call chain.
  450. *
  451. * WARNING:
  452. *
  453. * Note that this function is in general unsafe since it doesn't check for the
  454. * required locking for access state structures. Drivers must ensure that it is
  455. * safe to access the returned state structure through other means. One common
  456. * example is when planes are fixed to a single CRTC, and the driver knows that
  457. * the CRTC lock is held already. In that case holding the CRTC lock gives a
  458. * read-lock on all planes connected to that CRTC. But if planes can be
  459. * reassigned things get more tricky. In that case it's better to use
  460. * drm_atomic_get_plane_state and wire up full error handling.
  461. *
  462. * Returns:
  463. *
  464. * Read-only pointer to the current plane state.
  465. */
  466. static inline const struct drm_plane_state *
  467. __drm_atomic_get_current_plane_state(struct drm_atomic_state *state,
  468. struct drm_plane *plane)
  469. {
  470. if (state->planes[drm_plane_index(plane)].state)
  471. return state->planes[drm_plane_index(plane)].state;
  472. return plane->state;
  473. }
  474. int __must_check
  475. drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state,
  476. const struct drm_display_mode *mode);
  477. int __must_check
  478. drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state,
  479. struct drm_property_blob *blob);
  480. int __must_check
  481. drm_atomic_set_crtc_for_plane(struct drm_plane_state *plane_state,
  482. struct drm_crtc *crtc);
  483. void drm_atomic_set_fb_for_plane(struct drm_plane_state *plane_state,
  484. struct drm_framebuffer *fb);
  485. void drm_atomic_set_fence_for_plane(struct drm_plane_state *plane_state,
  486. struct dma_fence *fence);
  487. int __must_check
  488. drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state,
  489. struct drm_crtc *crtc);
  490. int __must_check
  491. drm_atomic_add_affected_connectors(struct drm_atomic_state *state,
  492. struct drm_crtc *crtc);
  493. int __must_check
  494. drm_atomic_add_affected_planes(struct drm_atomic_state *state,
  495. struct drm_crtc *crtc);
  496. void
  497. drm_atomic_clean_old_fb(struct drm_device *dev, unsigned plane_mask, int ret);
  498. int __must_check drm_atomic_check_only(struct drm_atomic_state *state);
  499. int __must_check drm_atomic_commit(struct drm_atomic_state *state);
  500. int __must_check drm_atomic_nonblocking_commit(struct drm_atomic_state *state);
  501. void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
  502. /**
  503. * for_each_connector_in_state - iterate over all connectors in an atomic update
  504. * @__state: &struct drm_atomic_state pointer
  505. * @connector: &struct drm_connector iteration cursor
  506. * @connector_state: &struct drm_connector_state iteration cursor
  507. * @__i: int iteration cursor, for macro-internal use
  508. *
  509. * This iterates over all connectors in an atomic update. Note that before the
  510. * software state is committed (by calling drm_atomic_helper_swap_state(), this
  511. * points to the new state, while afterwards it points to the old state. Due to
  512. * this tricky confusion this macro is deprecated.
  513. *
  514. * FIXME:
  515. *
  516. * Replace all usage of this with one of the explicit iterators below and then
  517. * remove this macro.
  518. */
  519. #define for_each_connector_in_state(__state, connector, connector_state, __i) \
  520. for ((__i) = 0; \
  521. (__i) < (__state)->num_connector && \
  522. ((connector) = (__state)->connectors[__i].ptr, \
  523. (connector_state) = (__state)->connectors[__i].state, 1); \
  524. (__i)++) \
  525. for_each_if (connector)
  526. /**
  527. * for_each_oldnew_connector_in_state - iterate over all connectors in an atomic update
  528. * @__state: &struct drm_atomic_state pointer
  529. * @connector: &struct drm_connector iteration cursor
  530. * @old_connector_state: &struct drm_connector_state iteration cursor for the
  531. * old state
  532. * @new_connector_state: &struct drm_connector_state iteration cursor for the
  533. * new state
  534. * @__i: int iteration cursor, for macro-internal use
  535. *
  536. * This iterates over all connectors in an atomic update, tracking both old and
  537. * new state. This is useful in places where the state delta needs to be
  538. * considered, for example in atomic check functions.
  539. */
  540. #define for_each_oldnew_connector_in_state(__state, connector, old_connector_state, new_connector_state, __i) \
  541. for ((__i) = 0; \
  542. (__i) < (__state)->num_connector && \
  543. ((connector) = (__state)->connectors[__i].ptr, \
  544. (old_connector_state) = (__state)->connectors[__i].old_state, \
  545. (new_connector_state) = (__state)->connectors[__i].new_state, 1); \
  546. (__i)++) \
  547. for_each_if (connector)
  548. /**
  549. * for_each_old_connector_in_state - iterate over all connectors in an atomic update
  550. * @__state: &struct drm_atomic_state pointer
  551. * @connector: &struct drm_connector iteration cursor
  552. * @old_connector_state: &struct drm_connector_state iteration cursor for the
  553. * old state
  554. * @__i: int iteration cursor, for macro-internal use
  555. *
  556. * This iterates over all connectors in an atomic update, tracking only the old
  557. * state. This is useful in disable functions, where we need the old state the
  558. * hardware is still in.
  559. */
  560. #define for_each_old_connector_in_state(__state, connector, old_connector_state, __i) \
  561. for ((__i) = 0; \
  562. (__i) < (__state)->num_connector && \
  563. ((connector) = (__state)->connectors[__i].ptr, \
  564. (old_connector_state) = (__state)->connectors[__i].old_state, 1); \
  565. (__i)++) \
  566. for_each_if (connector)
  567. /**
  568. * for_each_new_connector_in_state - iterate over all connectors in an atomic update
  569. * @__state: &struct drm_atomic_state pointer
  570. * @connector: &struct drm_connector iteration cursor
  571. * @new_connector_state: &struct drm_connector_state iteration cursor for the
  572. * new state
  573. * @__i: int iteration cursor, for macro-internal use
  574. *
  575. * This iterates over all connectors in an atomic update, tracking only the new
  576. * state. This is useful in enable functions, where we need the new state the
  577. * hardware should be in when the atomic commit operation has completed.
  578. */
  579. #define for_each_new_connector_in_state(__state, connector, new_connector_state, __i) \
  580. for ((__i) = 0; \
  581. (__i) < (__state)->num_connector && \
  582. ((connector) = (__state)->connectors[__i].ptr, \
  583. (new_connector_state) = (__state)->connectors[__i].new_state, 1); \
  584. (__i)++) \
  585. for_each_if (connector)
  586. /**
  587. * for_each_crtc_in_state - iterate over all connectors in an atomic update
  588. * @__state: &struct drm_atomic_state pointer
  589. * @crtc: &struct drm_crtc iteration cursor
  590. * @crtc_state: &struct drm_crtc_state iteration cursor
  591. * @__i: int iteration cursor, for macro-internal use
  592. *
  593. * This iterates over all CRTCs in an atomic update. Note that before the
  594. * software state is committed (by calling drm_atomic_helper_swap_state(), this
  595. * points to the new state, while afterwards it points to the old state. Due to
  596. * this tricky confusion this macro is deprecated.
  597. *
  598. * FIXME:
  599. *
  600. * Replace all usage of this with one of the explicit iterators below and then
  601. * remove this macro.
  602. */
  603. #define for_each_crtc_in_state(__state, crtc, crtc_state, __i) \
  604. for ((__i) = 0; \
  605. (__i) < (__state)->dev->mode_config.num_crtc && \
  606. ((crtc) = (__state)->crtcs[__i].ptr, \
  607. (crtc_state) = (__state)->crtcs[__i].state, 1); \
  608. (__i)++) \
  609. for_each_if (crtc_state)
  610. /**
  611. * for_each_oldnew_crtc_in_state - iterate over all CRTCs in an atomic update
  612. * @__state: &struct drm_atomic_state pointer
  613. * @crtc: &struct drm_crtc iteration cursor
  614. * @old_crtc_state: &struct drm_crtc_state iteration cursor for the old state
  615. * @new_crtc_state: &struct drm_crtc_state iteration cursor for the new state
  616. * @__i: int iteration cursor, for macro-internal use
  617. *
  618. * This iterates over all CRTCs in an atomic update, tracking both old and
  619. * new state. This is useful in places where the state delta needs to be
  620. * considered, for example in atomic check functions.
  621. */
  622. #define for_each_oldnew_crtc_in_state(__state, crtc, old_crtc_state, new_crtc_state, __i) \
  623. for ((__i) = 0; \
  624. (__i) < (__state)->dev->mode_config.num_crtc && \
  625. ((crtc) = (__state)->crtcs[__i].ptr, \
  626. (old_crtc_state) = (__state)->crtcs[__i].old_state, \
  627. (new_crtc_state) = (__state)->crtcs[__i].new_state, 1); \
  628. (__i)++) \
  629. for_each_if (crtc)
  630. /**
  631. * for_each_old_crtc_in_state - iterate over all CRTCs in an atomic update
  632. * @__state: &struct drm_atomic_state pointer
  633. * @crtc: &struct drm_crtc iteration cursor
  634. * @old_crtc_state: &struct drm_crtc_state iteration cursor for the old state
  635. * @__i: int iteration cursor, for macro-internal use
  636. *
  637. * This iterates over all CRTCs in an atomic update, tracking only the old
  638. * state. This is useful in disable functions, where we need the old state the
  639. * hardware is still in.
  640. */
  641. #define for_each_old_crtc_in_state(__state, crtc, old_crtc_state, __i) \
  642. for ((__i) = 0; \
  643. (__i) < (__state)->dev->mode_config.num_crtc && \
  644. ((crtc) = (__state)->crtcs[__i].ptr, \
  645. (old_crtc_state) = (__state)->crtcs[__i].old_state, 1); \
  646. (__i)++) \
  647. for_each_if (crtc)
  648. /**
  649. * for_each_new_crtc_in_state - iterate over all CRTCs in an atomic update
  650. * @__state: &struct drm_atomic_state pointer
  651. * @crtc: &struct drm_crtc iteration cursor
  652. * @new_crtc_state: &struct drm_crtc_state iteration cursor for the new state
  653. * @__i: int iteration cursor, for macro-internal use
  654. *
  655. * This iterates over all CRTCs in an atomic update, tracking only the new
  656. * state. This is useful in enable functions, where we need the new state the
  657. * hardware should be in when the atomic commit operation has completed.
  658. */
  659. #define for_each_new_crtc_in_state(__state, crtc, new_crtc_state, __i) \
  660. for ((__i) = 0; \
  661. (__i) < (__state)->dev->mode_config.num_crtc && \
  662. ((crtc) = (__state)->crtcs[__i].ptr, \
  663. (new_crtc_state) = (__state)->crtcs[__i].new_state, 1); \
  664. (__i)++) \
  665. for_each_if (crtc)
  666. /**
  667. * for_each_plane_in_state - iterate over all planes in an atomic update
  668. * @__state: &struct drm_atomic_state pointer
  669. * @plane: &struct drm_plane iteration cursor
  670. * @plane_state: &struct drm_plane_state iteration cursor
  671. * @__i: int iteration cursor, for macro-internal use
  672. *
  673. * This iterates over all planes in an atomic update. Note that before the
  674. * software state is committed (by calling drm_atomic_helper_swap_state(), this
  675. * points to the new state, while afterwards it points to the old state. Due to
  676. * this tricky confusion this macro is deprecated.
  677. *
  678. * FIXME:
  679. *
  680. * Replace all usage of this with one of the explicit iterators below and then
  681. * remove this macro.
  682. */
  683. #define for_each_plane_in_state(__state, plane, plane_state, __i) \
  684. for ((__i) = 0; \
  685. (__i) < (__state)->dev->mode_config.num_total_plane && \
  686. ((plane) = (__state)->planes[__i].ptr, \
  687. (plane_state) = (__state)->planes[__i].state, 1); \
  688. (__i)++) \
  689. for_each_if (plane_state)
  690. /**
  691. * for_each_oldnew_plane_in_state - iterate over all planes in an atomic update
  692. * @__state: &struct drm_atomic_state pointer
  693. * @plane: &struct drm_plane iteration cursor
  694. * @old_plane_state: &struct drm_plane_state iteration cursor for the old state
  695. * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
  696. * @__i: int iteration cursor, for macro-internal use
  697. *
  698. * This iterates over all planes in an atomic update, tracking both old and
  699. * new state. This is useful in places where the state delta needs to be
  700. * considered, for example in atomic check functions.
  701. */
  702. #define for_each_oldnew_plane_in_state(__state, plane, old_plane_state, new_plane_state, __i) \
  703. for ((__i) = 0; \
  704. (__i) < (__state)->dev->mode_config.num_total_plane && \
  705. ((plane) = (__state)->planes[__i].ptr, \
  706. (old_plane_state) = (__state)->planes[__i].old_state, \
  707. (new_plane_state) = (__state)->planes[__i].new_state, 1); \
  708. (__i)++) \
  709. for_each_if (plane)
  710. /**
  711. * for_each_old_plane_in_state - iterate over all planes in an atomic update
  712. * @__state: &struct drm_atomic_state pointer
  713. * @plane: &struct drm_plane iteration cursor
  714. * @old_plane_state: &struct drm_plane_state iteration cursor for the old state
  715. * @__i: int iteration cursor, for macro-internal use
  716. *
  717. * This iterates over all planes in an atomic update, tracking only the old
  718. * state. This is useful in disable functions, where we need the old state the
  719. * hardware is still in.
  720. */
  721. #define for_each_old_plane_in_state(__state, plane, old_plane_state, __i) \
  722. for ((__i) = 0; \
  723. (__i) < (__state)->dev->mode_config.num_total_plane && \
  724. ((plane) = (__state)->planes[__i].ptr, \
  725. (old_plane_state) = (__state)->planes[__i].old_state, 1); \
  726. (__i)++) \
  727. for_each_if (plane)
  728. /**
  729. * for_each_new_plane_in_state - iterate over all planes in an atomic update
  730. * @__state: &struct drm_atomic_state pointer
  731. * @plane: &struct drm_plane iteration cursor
  732. * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
  733. * @__i: int iteration cursor, for macro-internal use
  734. *
  735. * This iterates over all planes in an atomic update, tracking only the new
  736. * state. This is useful in enable functions, where we need the new state the
  737. * hardware should be in when the atomic commit operation has completed.
  738. */
  739. #define for_each_new_plane_in_state(__state, plane, new_plane_state, __i) \
  740. for ((__i) = 0; \
  741. (__i) < (__state)->dev->mode_config.num_total_plane && \
  742. ((plane) = (__state)->planes[__i].ptr, \
  743. (new_plane_state) = (__state)->planes[__i].new_state, 1); \
  744. (__i)++) \
  745. for_each_if (plane)
  746. /**
  747. * for_each_oldnew_private_obj_in_state - iterate over all private objects in an atomic update
  748. * @__state: &struct drm_atomic_state pointer
  749. * @obj: &struct drm_private_obj iteration cursor
  750. * @old_obj_state: &struct drm_private_state iteration cursor for the old state
  751. * @new_obj_state: &struct drm_private_state iteration cursor for the new state
  752. * @__i: int iteration cursor, for macro-internal use
  753. *
  754. * This iterates over all private objects in an atomic update, tracking both
  755. * old and new state. This is useful in places where the state delta needs
  756. * to be considered, for example in atomic check functions.
  757. */
  758. #define for_each_oldnew_private_obj_in_state(__state, obj, old_obj_state, new_obj_state, __i) \
  759. for ((__i) = 0; \
  760. (__i) < (__state)->num_private_objs && \
  761. ((obj) = (__state)->private_objs[__i].ptr, \
  762. (old_obj_state) = (__state)->private_objs[__i].old_state, \
  763. (new_obj_state) = (__state)->private_objs[__i].new_state, 1); \
  764. (__i)++) \
  765. for_each_if (obj)
  766. /**
  767. * for_each_old_private_obj_in_state - iterate over all private objects in an atomic update
  768. * @__state: &struct drm_atomic_state pointer
  769. * @obj: &struct drm_private_obj iteration cursor
  770. * @old_obj_state: &struct drm_private_state iteration cursor for the old state
  771. * @__i: int iteration cursor, for macro-internal use
  772. *
  773. * This iterates over all private objects in an atomic update, tracking only
  774. * the old state. This is useful in disable functions, where we need the old
  775. * state the hardware is still in.
  776. */
  777. #define for_each_old_private_obj_in_state(__state, obj, old_obj_state, __i) \
  778. for ((__i) = 0; \
  779. (__i) < (__state)->num_private_objs && \
  780. ((obj) = (__state)->private_objs[__i].ptr, \
  781. (old_obj_state) = (__state)->private_objs[__i].old_state, 1); \
  782. (__i)++) \
  783. for_each_if (obj)
  784. /**
  785. * for_each_new_private_obj_in_state - iterate over all private objects in an atomic update
  786. * @__state: &struct drm_atomic_state pointer
  787. * @obj: &struct drm_private_obj iteration cursor
  788. * @new_obj_state: &struct drm_private_state iteration cursor for the new state
  789. * @__i: int iteration cursor, for macro-internal use
  790. *
  791. * This iterates over all private objects in an atomic update, tracking only
  792. * the new state. This is useful in enable functions, where we need the new state the
  793. * hardware should be in when the atomic commit operation has completed.
  794. */
  795. #define for_each_new_private_obj_in_state(__state, obj, new_obj_state, __i) \
  796. for ((__i) = 0; \
  797. (__i) < (__state)->num_private_objs && \
  798. ((obj) = (__state)->private_objs[__i].ptr, \
  799. (new_obj_state) = (__state)->private_objs[__i].new_state, 1); \
  800. (__i)++) \
  801. for_each_if (obj)
  802. /**
  803. * drm_atomic_crtc_needs_modeset - compute combined modeset need
  804. * @state: &drm_crtc_state for the CRTC
  805. *
  806. * To give drivers flexibility &struct drm_crtc_state has 3 booleans to track
  807. * whether the state CRTC changed enough to need a full modeset cycle:
  808. * mode_changed, active_changed and connectors_changed. This helper simply
  809. * combines these three to compute the overall need for a modeset for @state.
  810. *
  811. * The atomic helper code sets these booleans, but drivers can and should
  812. * change them appropriately to accurately represent whether a modeset is
  813. * really needed. In general, drivers should avoid full modesets whenever
  814. * possible.
  815. *
  816. * For example if the CRTC mode has changed, and the hardware is able to enact
  817. * the requested mode change without going through a full modeset, the driver
  818. * should clear mode_changed in its &drm_mode_config_funcs.atomic_check
  819. * implementation.
  820. */
  821. static inline bool
  822. drm_atomic_crtc_needs_modeset(const struct drm_crtc_state *state)
  823. {
  824. return state->mode_changed || state->active_changed ||
  825. state->connectors_changed;
  826. }
  827. #endif /* DRM_ATOMIC_H_ */