drm_atomic.h 32 KB

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