drm_atomic.h 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364
  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. #include <drm/drm_util.h>
  31. /**
  32. * struct drm_crtc_commit - track modeset commits on a CRTC
  33. *
  34. * This structure is used to track pending modeset changes and atomic commit on
  35. * a per-CRTC basis. Since updating the list should never block, this structure
  36. * is reference counted to allow waiters to safely wait on an event to complete,
  37. * without holding any locks.
  38. *
  39. * It has 3 different events in total to allow a fine-grained synchronization
  40. * between outstanding updates::
  41. *
  42. * atomic commit thread hardware
  43. *
  44. * write new state into hardware ----> ...
  45. * signal hw_done
  46. * switch to new state on next
  47. * ... v/hblank
  48. *
  49. * wait for buffers to show up ...
  50. *
  51. * ... send completion irq
  52. * irq handler signals flip_done
  53. * cleanup old buffers
  54. *
  55. * signal cleanup_done
  56. *
  57. * wait for flip_done <----
  58. * clean up atomic state
  59. *
  60. * The important bit to know is that &cleanup_done is the terminal event, but the
  61. * ordering between &flip_done and &hw_done is entirely up to the specific driver
  62. * and modeset state change.
  63. *
  64. * For an implementation of how to use this look at
  65. * drm_atomic_helper_setup_commit() from the atomic helper library.
  66. *
  67. * See also drm_crtc_commit_wait().
  68. */
  69. struct drm_crtc_commit {
  70. /**
  71. * @crtc:
  72. *
  73. * DRM CRTC for this commit.
  74. */
  75. struct drm_crtc *crtc;
  76. /**
  77. * @ref:
  78. *
  79. * Reference count for this structure. Needed to allow blocking on
  80. * completions without the risk of the completion disappearing
  81. * meanwhile.
  82. */
  83. struct kref ref;
  84. /**
  85. * @flip_done:
  86. *
  87. * Will be signaled when the hardware has flipped to the new set of
  88. * buffers. Signals at the same time as when the drm event for this
  89. * commit is sent to userspace, or when an out-fence is singalled. Note
  90. * that for most hardware, in most cases this happens after @hw_done is
  91. * signalled.
  92. *
  93. * Completion of this stage is signalled implicitly by calling
  94. * drm_crtc_send_vblank_event() on &drm_crtc_state.event.
  95. */
  96. struct completion flip_done;
  97. /**
  98. * @hw_done:
  99. *
  100. * Will be signalled when all hw register changes for this commit have
  101. * been written out. Especially when disabling a pipe this can be much
  102. * later than @flip_done, since that can signal already when the
  103. * screen goes black, whereas to fully shut down a pipe more register
  104. * I/O is required.
  105. *
  106. * Note that this does not need to include separately reference-counted
  107. * resources like backing storage buffer pinning, or runtime pm
  108. * management.
  109. *
  110. * Drivers should call drm_atomic_helper_commit_hw_done() to signal
  111. * completion of this stage.
  112. */
  113. struct completion hw_done;
  114. /**
  115. * @cleanup_done:
  116. *
  117. * Will be signalled after old buffers have been cleaned up by calling
  118. * drm_atomic_helper_cleanup_planes(). Since this can only happen after
  119. * a vblank wait completed it might be a bit later. This completion is
  120. * useful to throttle updates and avoid hardware updates getting ahead
  121. * of the buffer cleanup too much.
  122. *
  123. * Drivers should call drm_atomic_helper_commit_cleanup_done() to signal
  124. * completion of this stage.
  125. */
  126. struct completion cleanup_done;
  127. /**
  128. * @commit_entry:
  129. *
  130. * Entry on the per-CRTC &drm_crtc.commit_list. Protected by
  131. * $drm_crtc.commit_lock.
  132. */
  133. struct list_head commit_entry;
  134. /**
  135. * @event:
  136. *
  137. * &drm_pending_vblank_event pointer to clean up private events.
  138. */
  139. struct drm_pending_vblank_event *event;
  140. /**
  141. * @abort_completion:
  142. *
  143. * A flag that's set after drm_atomic_helper_setup_commit() takes a
  144. * second reference for the completion of $drm_crtc_state.event. It's
  145. * used by the free code to remove the second reference if commit fails.
  146. */
  147. bool abort_completion;
  148. };
  149. struct __drm_colorops_state {
  150. struct drm_colorop *ptr;
  151. struct drm_colorop_state *state, *old_state, *new_state;
  152. };
  153. struct __drm_planes_state {
  154. struct drm_plane *ptr;
  155. /**
  156. * @state_to_destroy:
  157. *
  158. * Used to track the @drm_plane_state we will need to free when
  159. * tearing down the associated &drm_atomic_state in
  160. * $drm_mode_config_funcs.atomic_state_clear or
  161. * drm_atomic_state_default_clear().
  162. *
  163. * Before a commit, and the call to
  164. * drm_atomic_helper_swap_state() in particular, it points to
  165. * the same state than @new_state. After a commit, it points to
  166. * the same state than @old_state.
  167. */
  168. struct drm_plane_state *state_to_destroy;
  169. struct drm_plane_state *old_state, *new_state;
  170. };
  171. struct __drm_crtcs_state {
  172. struct drm_crtc *ptr;
  173. /**
  174. * @state_to_destroy:
  175. *
  176. * Used to track the @drm_crtc_state we will need to free when
  177. * tearing down the associated &drm_atomic_state in
  178. * $drm_mode_config_funcs.atomic_state_clear or
  179. * drm_atomic_state_default_clear().
  180. *
  181. * Before a commit, and the call to
  182. * drm_atomic_helper_swap_state() in particular, it points to
  183. * the same state than @new_state. After a commit, it points to
  184. * the same state than @old_state.
  185. */
  186. struct drm_crtc_state *state_to_destroy;
  187. struct drm_crtc_state *old_state, *new_state;
  188. /**
  189. * @commit:
  190. *
  191. * A reference to the CRTC commit object that is kept for use by
  192. * drm_atomic_helper_wait_for_flip_done() after
  193. * drm_atomic_helper_commit_hw_done() is called. This ensures that a
  194. * concurrent commit won't free a commit object that is still in use.
  195. */
  196. struct drm_crtc_commit *commit;
  197. s32 __user *out_fence_ptr;
  198. u64 last_vblank_count;
  199. };
  200. struct __drm_connnectors_state {
  201. struct drm_connector *ptr;
  202. /**
  203. * @state_to_destroy:
  204. *
  205. * Used to track the @drm_connector_state we will need to free
  206. * when tearing down the associated &drm_atomic_state in
  207. * $drm_mode_config_funcs.atomic_state_clear or
  208. * drm_atomic_state_default_clear().
  209. *
  210. * Before a commit, and the call to
  211. * drm_atomic_helper_swap_state() in particular, it points to
  212. * the same state than @new_state. After a commit, it points to
  213. * the same state than @old_state.
  214. */
  215. struct drm_connector_state *state_to_destroy;
  216. struct drm_connector_state *old_state, *new_state;
  217. /**
  218. * @out_fence_ptr:
  219. *
  220. * User-provided pointer which the kernel uses to return a sync_file
  221. * file descriptor. Used by writeback connectors to signal completion of
  222. * the writeback.
  223. */
  224. s32 __user *out_fence_ptr;
  225. };
  226. struct drm_private_obj;
  227. struct drm_private_state;
  228. /**
  229. * struct drm_private_state_funcs - atomic state functions for private objects
  230. *
  231. * These hooks are used by atomic helpers to create, swap and destroy states of
  232. * private objects. The structure itself is used as a vtable to identify the
  233. * associated private object type. Each private object type that needs to be
  234. * added to the atomic states is expected to have an implementation of these
  235. * hooks and pass a pointer to its drm_private_state_funcs struct to
  236. * drm_atomic_get_private_obj_state().
  237. */
  238. struct drm_private_state_funcs {
  239. /**
  240. * @atomic_duplicate_state:
  241. *
  242. * Duplicate the current state of the private object and return it. It
  243. * is an error to call this before obj->state has been initialized.
  244. *
  245. * RETURNS:
  246. *
  247. * Duplicated atomic state or NULL when obj->state is not
  248. * initialized or allocation failed.
  249. */
  250. struct drm_private_state *(*atomic_duplicate_state)(struct drm_private_obj *obj);
  251. /**
  252. * @atomic_destroy_state:
  253. *
  254. * Frees the private object state created with @atomic_duplicate_state.
  255. */
  256. void (*atomic_destroy_state)(struct drm_private_obj *obj,
  257. struct drm_private_state *state);
  258. /**
  259. * @atomic_print_state:
  260. *
  261. * If driver subclasses &struct drm_private_state, it should implement
  262. * this optional hook for printing additional driver specific state.
  263. *
  264. * Do not call this directly, use drm_atomic_private_obj_print_state()
  265. * instead.
  266. */
  267. void (*atomic_print_state)(struct drm_printer *p,
  268. const struct drm_private_state *state);
  269. };
  270. /**
  271. * struct drm_private_obj - base struct for driver private atomic object
  272. *
  273. * A driver private object is initialized by calling
  274. * drm_atomic_private_obj_init() and cleaned up by calling
  275. * drm_atomic_private_obj_fini().
  276. *
  277. * Currently only tracks the state update functions and the opaque driver
  278. * private state itself, but in the future might also track which
  279. * &drm_modeset_lock is required to duplicate and update this object's state.
  280. *
  281. * All private objects must be initialized before the DRM device they are
  282. * attached to is registered to the DRM subsystem (call to drm_dev_register())
  283. * and should stay around until this DRM device is unregistered (call to
  284. * drm_dev_unregister()). In other words, private objects lifetime is tied
  285. * to the DRM device lifetime. This implies that:
  286. *
  287. * 1/ all calls to drm_atomic_private_obj_init() must be done before calling
  288. * drm_dev_register()
  289. * 2/ all calls to drm_atomic_private_obj_fini() must be done after calling
  290. * drm_dev_unregister()
  291. *
  292. * If that private object is used to store a state shared by multiple
  293. * CRTCs, proper care must be taken to ensure that non-blocking commits are
  294. * properly ordered to avoid a use-after-free issue.
  295. *
  296. * Indeed, assuming a sequence of two non-blocking &drm_atomic_commit on two
  297. * different &drm_crtc using different &drm_plane and &drm_connector, so with no
  298. * resources shared, there's no guarantee on which commit is going to happen
  299. * first. However, the second &drm_atomic_commit will consider the first
  300. * &drm_private_obj its old state, and will be in charge of freeing it whenever
  301. * the second &drm_atomic_commit is done.
  302. *
  303. * If the first &drm_atomic_commit happens after it, it will consider its
  304. * &drm_private_obj the new state and will be likely to access it, resulting in
  305. * an access to a freed memory region. Drivers should store (and get a reference
  306. * to) the &drm_crtc_commit structure in our private state in
  307. * &drm_mode_config_helper_funcs.atomic_commit_setup, and then wait for that
  308. * commit to complete as the first step of
  309. * &drm_mode_config_helper_funcs.atomic_commit_tail, similar to
  310. * drm_atomic_helper_wait_for_dependencies().
  311. */
  312. struct drm_private_obj {
  313. /**
  314. * @dev: parent DRM device
  315. */
  316. struct drm_device *dev;
  317. /**
  318. * @head: List entry used to attach a private object to a &drm_device
  319. * (queued to &drm_mode_config.privobj_list).
  320. */
  321. struct list_head head;
  322. /**
  323. * @lock: Modeset lock to protect the state object.
  324. */
  325. struct drm_modeset_lock lock;
  326. /**
  327. * @state: Current atomic state for this driver private object.
  328. */
  329. struct drm_private_state *state;
  330. /**
  331. * @funcs:
  332. *
  333. * Functions to manipulate the state of this driver private object, see
  334. * &drm_private_state_funcs.
  335. */
  336. const struct drm_private_state_funcs *funcs;
  337. };
  338. /**
  339. * drm_for_each_privobj() - private object iterator
  340. *
  341. * @privobj: pointer to the current private object. Updated after each
  342. * iteration
  343. * @dev: the DRM device we want get private objects from
  344. *
  345. * Allows one to iterate over all private objects attached to @dev
  346. */
  347. #define drm_for_each_privobj(privobj, dev) \
  348. list_for_each_entry(privobj, &(dev)->mode_config.privobj_list, head)
  349. /**
  350. * struct drm_private_state - base struct for driver private object state
  351. *
  352. * Currently only contains a backpointer to the overall atomic update,
  353. * and the relevant private object but in the future also might hold
  354. * synchronization information similar to e.g. &drm_crtc.commit.
  355. */
  356. struct drm_private_state {
  357. /**
  358. * @state: backpointer to global drm_atomic_state
  359. */
  360. struct drm_atomic_state *state;
  361. /**
  362. * @obj: backpointer to the private object
  363. */
  364. struct drm_private_obj *obj;
  365. };
  366. struct __drm_private_objs_state {
  367. struct drm_private_obj *ptr;
  368. /**
  369. * @state_to_destroy:
  370. *
  371. * Used to track the @drm_private_state we will need to free
  372. * when tearing down the associated &drm_atomic_state in
  373. * $drm_mode_config_funcs.atomic_state_clear or
  374. * drm_atomic_state_default_clear().
  375. *
  376. * Before a commit, and the call to
  377. * drm_atomic_helper_swap_state() in particular, it points to
  378. * the same state than @new_state. After a commit, it points to
  379. * the same state than @old_state.
  380. */
  381. struct drm_private_state *state_to_destroy;
  382. struct drm_private_state *old_state, *new_state;
  383. };
  384. /**
  385. * struct drm_atomic_state - Atomic commit structure
  386. *
  387. * This structure is the kernel counterpart of @drm_mode_atomic and represents
  388. * an atomic commit that transitions from an old to a new display state. It
  389. * contains all the objects affected by the atomic commit and both the new
  390. * state structures and pointers to the old state structures for
  391. * these.
  392. *
  393. * States are added to an atomic update by calling drm_atomic_get_crtc_state(),
  394. * drm_atomic_get_plane_state(), drm_atomic_get_connector_state(), or for
  395. * private state structures, drm_atomic_get_private_obj_state().
  396. *
  397. * NOTE: struct drm_atomic_state first started as a single collection of
  398. * entities state pointers (drm_plane_state, drm_crtc_state, etc.).
  399. *
  400. * At atomic_check time, you could get the state about to be committed
  401. * from drm_atomic_state, and the one currently running from the
  402. * entities state pointer (drm_crtc.state, for example). After the call
  403. * to drm_atomic_helper_swap_state(), the entities state pointer would
  404. * contain the state previously checked, and the drm_atomic_state
  405. * structure the old state.
  406. *
  407. * Over time, and in order to avoid confusion, drm_atomic_state has
  408. * grown to have both the old state (ie, the state we replace) and the
  409. * new state (ie, the state we want to apply). Those names are stable
  410. * during the commit process, which makes it easier to reason about.
  411. *
  412. * You can still find some traces of that evolution through some hooks
  413. * or callbacks taking a drm_atomic_state parameter called names like
  414. * "old_state". This doesn't necessarily mean that the previous
  415. * drm_atomic_state is passed, but rather that this used to be the state
  416. * collection we were replacing after drm_atomic_helper_swap_state(),
  417. * but the variable name was never updated.
  418. *
  419. * Some atomic operations implementations followed a similar process. We
  420. * first started to pass the entity state only. However, it was pretty
  421. * cumbersome for drivers, and especially CRTCs, to retrieve the states
  422. * of other components. Thus, we switched to passing the whole
  423. * drm_atomic_state as a parameter to those operations. Similarly, the
  424. * transition isn't complete yet, and one might still find atomic
  425. * operations taking a drm_atomic_state pointer, or a component state
  426. * pointer. The former is the preferred form.
  427. */
  428. struct drm_atomic_state {
  429. /**
  430. * @ref:
  431. *
  432. * Count of all references to this update (will not be freed until zero).
  433. */
  434. struct kref ref;
  435. /**
  436. * @dev: Parent DRM Device.
  437. */
  438. struct drm_device *dev;
  439. /**
  440. * @allow_modeset:
  441. *
  442. * Allow full modeset. This is used by the ATOMIC IOCTL handler to
  443. * implement the DRM_MODE_ATOMIC_ALLOW_MODESET flag. Drivers should
  444. * generally not consult this flag, but instead look at the output of
  445. * drm_atomic_crtc_needs_modeset(). The detailed rules are:
  446. *
  447. * - Drivers must not consult @allow_modeset in the atomic commit path.
  448. * Use drm_atomic_crtc_needs_modeset() instead.
  449. *
  450. * - Drivers must consult @allow_modeset before adding unrelated struct
  451. * drm_crtc_state to this commit by calling
  452. * drm_atomic_get_crtc_state(). See also the warning in the
  453. * documentation for that function.
  454. *
  455. * - Drivers must never change this flag, it is under the exclusive
  456. * control of userspace.
  457. *
  458. * - Drivers may consult @allow_modeset in the atomic check path, if
  459. * they have the choice between an optimal hardware configuration
  460. * which requires a modeset, and a less optimal configuration which
  461. * can be committed without a modeset. An example would be suboptimal
  462. * scanout FIFO allocation resulting in increased idle power
  463. * consumption. This allows userspace to avoid flickering and delays
  464. * for the normal composition loop at reasonable cost.
  465. */
  466. bool allow_modeset : 1;
  467. /**
  468. * @legacy_cursor_update:
  469. *
  470. * Hint to enforce legacy cursor IOCTL semantics.
  471. *
  472. * WARNING: This is thoroughly broken and pretty much impossible to
  473. * implement correctly. Drivers must ignore this and should instead
  474. * implement &drm_plane_helper_funcs.atomic_async_check and
  475. * &drm_plane_helper_funcs.atomic_async_commit hooks. New users of this
  476. * flag are not allowed.
  477. */
  478. bool legacy_cursor_update : 1;
  479. /**
  480. * @async_update: hint for asynchronous plane update
  481. */
  482. bool async_update : 1;
  483. /**
  484. * @duplicated:
  485. *
  486. * Indicates whether or not this atomic state was duplicated using
  487. * drm_atomic_helper_duplicate_state(). Drivers and atomic helpers
  488. * should use this to fixup normal inconsistencies in duplicated
  489. * states.
  490. */
  491. bool duplicated : 1;
  492. /**
  493. * @checked:
  494. *
  495. * Indicates the state has been checked and thus must no longer
  496. * be mutated. For internal use only, do not consult from drivers.
  497. */
  498. bool checked : 1;
  499. /**
  500. * @plane_color_pipeline:
  501. *
  502. * Indicates whether this atomic state originated with a client that
  503. * set the DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE.
  504. *
  505. * Drivers and helper functions should use this to ignore legacy
  506. * properties that are incompatible with the drm_plane COLOR_PIPELINE
  507. * behavior, such as:
  508. *
  509. * - COLOR_RANGE
  510. * - COLOR_ENCODING
  511. *
  512. * or any other driver-specific properties that might affect pixel
  513. * values.
  514. */
  515. bool plane_color_pipeline : 1;
  516. /**
  517. * @colorops:
  518. *
  519. * Pointer to array of @drm_colorop and @drm_colorop_state part of this
  520. * update.
  521. */
  522. struct __drm_colorops_state *colorops;
  523. /**
  524. * @planes:
  525. *
  526. * Pointer to array of @drm_plane and @drm_plane_state part of this
  527. * update.
  528. */
  529. struct __drm_planes_state *planes;
  530. /**
  531. * @crtcs:
  532. *
  533. * Pointer to array of @drm_crtc and @drm_crtc_state part of this
  534. * update.
  535. */
  536. struct __drm_crtcs_state *crtcs;
  537. /**
  538. * @num_connector: size of the @connectors array
  539. */
  540. int num_connector;
  541. /**
  542. * @connectors:
  543. *
  544. * Pointer to array of @drm_connector and @drm_connector_state part of
  545. * this update.
  546. */
  547. struct __drm_connnectors_state *connectors;
  548. /**
  549. * @num_private_objs: size of the @private_objs array
  550. */
  551. int num_private_objs;
  552. /**
  553. * @private_objs:
  554. *
  555. * Pointer to array of @drm_private_obj and @drm_private_obj_state part
  556. * of this update.
  557. */
  558. struct __drm_private_objs_state *private_objs;
  559. /**
  560. * @acquire_ctx: acquire context for this atomic modeset state update
  561. */
  562. struct drm_modeset_acquire_ctx *acquire_ctx;
  563. /**
  564. * @fake_commit:
  565. *
  566. * Used for signaling unbound planes/connectors.
  567. * When a connector or plane is not bound to any CRTC, it's still important
  568. * to preserve linearity to prevent the atomic states from being freed too early.
  569. *
  570. * This commit (if set) is not bound to any CRTC, but will be completed when
  571. * drm_atomic_helper_commit_hw_done() is called.
  572. */
  573. struct drm_crtc_commit *fake_commit;
  574. /**
  575. * @commit_work:
  576. *
  577. * Work item which can be used by the driver or helpers to execute the
  578. * commit without blocking.
  579. */
  580. struct work_struct commit_work;
  581. };
  582. void __drm_crtc_commit_free(struct kref *kref);
  583. /**
  584. * drm_crtc_commit_get - acquire a reference to the CRTC commit
  585. * @commit: CRTC commit
  586. *
  587. * Increases the reference of @commit.
  588. *
  589. * Returns:
  590. * The pointer to @commit, with reference increased.
  591. */
  592. static inline struct drm_crtc_commit *drm_crtc_commit_get(struct drm_crtc_commit *commit)
  593. {
  594. kref_get(&commit->ref);
  595. return commit;
  596. }
  597. /**
  598. * drm_crtc_commit_put - release a reference to the CRTC commmit
  599. * @commit: CRTC commit
  600. *
  601. * This releases a reference to @commit which is freed after removing the
  602. * final reference. No locking required and callable from any context.
  603. */
  604. static inline void drm_crtc_commit_put(struct drm_crtc_commit *commit)
  605. {
  606. kref_put(&commit->ref, __drm_crtc_commit_free);
  607. }
  608. int drm_crtc_commit_wait(struct drm_crtc_commit *commit);
  609. struct drm_atomic_state * __must_check
  610. drm_atomic_state_alloc(struct drm_device *dev);
  611. void drm_atomic_state_clear(struct drm_atomic_state *state);
  612. /**
  613. * drm_atomic_state_get - acquire a reference to the atomic state
  614. * @state: The atomic state
  615. *
  616. * Returns a new reference to the @state
  617. */
  618. static inline struct drm_atomic_state *
  619. drm_atomic_state_get(struct drm_atomic_state *state)
  620. {
  621. kref_get(&state->ref);
  622. return state;
  623. }
  624. void __drm_atomic_state_free(struct kref *ref);
  625. /**
  626. * drm_atomic_state_put - release a reference to the atomic state
  627. * @state: The atomic state
  628. *
  629. * This releases a reference to @state which is freed after removing the
  630. * final reference. No locking required and callable from any context.
  631. */
  632. static inline void drm_atomic_state_put(struct drm_atomic_state *state)
  633. {
  634. kref_put(&state->ref, __drm_atomic_state_free);
  635. }
  636. int __must_check
  637. drm_atomic_state_init(struct drm_device *dev, struct drm_atomic_state *state);
  638. void drm_atomic_state_default_clear(struct drm_atomic_state *state);
  639. void drm_atomic_state_default_release(struct drm_atomic_state *state);
  640. struct drm_crtc_state * __must_check
  641. drm_atomic_get_crtc_state(struct drm_atomic_state *state,
  642. struct drm_crtc *crtc);
  643. struct drm_plane_state * __must_check
  644. drm_atomic_get_plane_state(struct drm_atomic_state *state,
  645. struct drm_plane *plane);
  646. struct drm_colorop_state *
  647. drm_atomic_get_colorop_state(struct drm_atomic_state *state,
  648. struct drm_colorop *colorop);
  649. struct drm_colorop_state *
  650. drm_atomic_get_old_colorop_state(struct drm_atomic_state *state,
  651. struct drm_colorop *colorop);
  652. struct drm_colorop_state *
  653. drm_atomic_get_new_colorop_state(struct drm_atomic_state *state,
  654. struct drm_colorop *colorop);
  655. struct drm_connector_state * __must_check
  656. drm_atomic_get_connector_state(struct drm_atomic_state *state,
  657. struct drm_connector *connector);
  658. void drm_atomic_private_obj_init(struct drm_device *dev,
  659. struct drm_private_obj *obj,
  660. struct drm_private_state *state,
  661. const struct drm_private_state_funcs *funcs);
  662. void drm_atomic_private_obj_fini(struct drm_private_obj *obj);
  663. struct drm_private_state * __must_check
  664. drm_atomic_get_private_obj_state(struct drm_atomic_state *state,
  665. struct drm_private_obj *obj);
  666. struct drm_private_state *
  667. drm_atomic_get_old_private_obj_state(const struct drm_atomic_state *state,
  668. struct drm_private_obj *obj);
  669. struct drm_private_state *
  670. drm_atomic_get_new_private_obj_state(const struct drm_atomic_state *state,
  671. struct drm_private_obj *obj);
  672. struct drm_connector *
  673. drm_atomic_get_old_connector_for_encoder(const struct drm_atomic_state *state,
  674. struct drm_encoder *encoder);
  675. struct drm_connector *
  676. drm_atomic_get_new_connector_for_encoder(const struct drm_atomic_state *state,
  677. struct drm_encoder *encoder);
  678. struct drm_connector *
  679. drm_atomic_get_connector_for_encoder(const struct drm_encoder *encoder,
  680. struct drm_modeset_acquire_ctx *ctx);
  681. struct drm_crtc *
  682. drm_atomic_get_old_crtc_for_encoder(struct drm_atomic_state *state,
  683. struct drm_encoder *encoder);
  684. struct drm_crtc *
  685. drm_atomic_get_new_crtc_for_encoder(struct drm_atomic_state *state,
  686. struct drm_encoder *encoder);
  687. /**
  688. * drm_atomic_get_old_crtc_state - get old CRTC state, if it exists
  689. * @state: global atomic state object
  690. * @crtc: CRTC to grab
  691. *
  692. * This function returns the old CRTC state for the given CRTC, or
  693. * NULL if the CRTC is not part of the global atomic state.
  694. */
  695. static inline struct drm_crtc_state *
  696. drm_atomic_get_old_crtc_state(const struct drm_atomic_state *state,
  697. struct drm_crtc *crtc)
  698. {
  699. return state->crtcs[drm_crtc_index(crtc)].old_state;
  700. }
  701. /**
  702. * drm_atomic_get_new_crtc_state - get new CRTC state, if it exists
  703. * @state: global atomic state object
  704. * @crtc: CRTC to grab
  705. *
  706. * This function returns the new CRTC state for the given CRTC, or
  707. * NULL if the CRTC is not part of the global atomic state.
  708. */
  709. static inline struct drm_crtc_state *
  710. drm_atomic_get_new_crtc_state(const struct drm_atomic_state *state,
  711. struct drm_crtc *crtc)
  712. {
  713. return state->crtcs[drm_crtc_index(crtc)].new_state;
  714. }
  715. /**
  716. * drm_atomic_get_old_plane_state - get plane state, if it exists
  717. * @state: global atomic state object
  718. * @plane: plane to grab
  719. *
  720. * This function returns the old plane state for the given plane, or
  721. * NULL if the plane is not part of the global atomic state.
  722. */
  723. static inline struct drm_plane_state *
  724. drm_atomic_get_old_plane_state(const struct drm_atomic_state *state,
  725. struct drm_plane *plane)
  726. {
  727. return state->planes[drm_plane_index(plane)].old_state;
  728. }
  729. /**
  730. * drm_atomic_get_new_plane_state - get plane state, if it exists
  731. * @state: global atomic state object
  732. * @plane: plane to grab
  733. *
  734. * This function returns the new plane state for the given plane, or
  735. * NULL if the plane is not part of the global atomic state.
  736. */
  737. static inline struct drm_plane_state *
  738. drm_atomic_get_new_plane_state(const struct drm_atomic_state *state,
  739. struct drm_plane *plane)
  740. {
  741. return state->planes[drm_plane_index(plane)].new_state;
  742. }
  743. /**
  744. * drm_atomic_get_old_connector_state - get connector state, if it exists
  745. * @state: global atomic state object
  746. * @connector: connector to grab
  747. *
  748. * This function returns the old connector state for the given connector,
  749. * or NULL if the connector is not part of the global atomic state.
  750. */
  751. static inline struct drm_connector_state *
  752. drm_atomic_get_old_connector_state(const struct drm_atomic_state *state,
  753. struct drm_connector *connector)
  754. {
  755. int index = drm_connector_index(connector);
  756. if (index >= state->num_connector)
  757. return NULL;
  758. return state->connectors[index].old_state;
  759. }
  760. /**
  761. * drm_atomic_get_new_connector_state - get connector state, if it exists
  762. * @state: global atomic state object
  763. * @connector: connector to grab
  764. *
  765. * This function returns the new connector state for the given connector,
  766. * or NULL if the connector is not part of the global atomic state.
  767. */
  768. static inline struct drm_connector_state *
  769. drm_atomic_get_new_connector_state(const struct drm_atomic_state *state,
  770. struct drm_connector *connector)
  771. {
  772. int index = drm_connector_index(connector);
  773. if (index >= state->num_connector)
  774. return NULL;
  775. return state->connectors[index].new_state;
  776. }
  777. /**
  778. * __drm_atomic_get_current_plane_state - get current plane state
  779. * @state: global atomic state object
  780. * @plane: plane to grab
  781. *
  782. * This function returns the plane state for the given plane, either the
  783. * new plane state from @state, or if the plane isn't part of the atomic
  784. * state update, from @plane. This is useful in atomic check callbacks,
  785. * when drivers need to peek at, but not change, state of other planes,
  786. * since it avoids threading an error code back up the call chain.
  787. *
  788. * WARNING:
  789. *
  790. * Note that this function is in general unsafe since it doesn't check for the
  791. * required locking for access state structures. Drivers must ensure that it is
  792. * safe to access the returned state structure through other means. One common
  793. * example is when planes are fixed to a single CRTC, and the driver knows that
  794. * the CRTC lock is held already. In that case holding the CRTC lock gives a
  795. * read-lock on all planes connected to that CRTC. But if planes can be
  796. * reassigned things get more tricky. In that case it's better to use
  797. * drm_atomic_get_plane_state and wire up full error handling.
  798. *
  799. * Returns:
  800. *
  801. * Read-only pointer to the current plane state.
  802. */
  803. static inline const struct drm_plane_state *
  804. __drm_atomic_get_current_plane_state(const struct drm_atomic_state *state,
  805. struct drm_plane *plane)
  806. {
  807. struct drm_plane_state *plane_state;
  808. plane_state = drm_atomic_get_new_plane_state(state, plane);
  809. if (plane_state)
  810. return plane_state;
  811. /*
  812. * If the plane isn't part of the state, fallback to the currently active one.
  813. */
  814. return plane->state;
  815. }
  816. int __must_check
  817. drm_atomic_add_encoder_bridges(struct drm_atomic_state *state,
  818. struct drm_encoder *encoder);
  819. int __must_check
  820. drm_atomic_add_affected_connectors(struct drm_atomic_state *state,
  821. struct drm_crtc *crtc);
  822. int __must_check
  823. drm_atomic_add_affected_planes(struct drm_atomic_state *state,
  824. struct drm_crtc *crtc);
  825. int __must_check
  826. drm_atomic_add_affected_colorops(struct drm_atomic_state *state,
  827. struct drm_plane *plane);
  828. int __must_check drm_atomic_check_only(struct drm_atomic_state *state);
  829. int __must_check drm_atomic_commit(struct drm_atomic_state *state);
  830. int __must_check drm_atomic_nonblocking_commit(struct drm_atomic_state *state);
  831. void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
  832. /**
  833. * for_each_oldnew_connector_in_state - iterate over all connectors in an atomic update
  834. * @__state: &struct drm_atomic_state pointer
  835. * @connector: &struct drm_connector iteration cursor
  836. * @old_connector_state: &struct drm_connector_state iteration cursor for the
  837. * old state
  838. * @new_connector_state: &struct drm_connector_state iteration cursor for the
  839. * new state
  840. * @__i: int iteration cursor, for macro-internal use
  841. *
  842. * This iterates over all connectors in an atomic update, tracking both old and
  843. * new state. This is useful in places where the state delta needs to be
  844. * considered, for example in atomic check functions.
  845. */
  846. #define for_each_oldnew_connector_in_state(__state, connector, old_connector_state, new_connector_state, __i) \
  847. for ((__i) = 0; \
  848. (__i) < (__state)->num_connector; \
  849. (__i)++) \
  850. for_each_if ((__state)->connectors[__i].ptr && \
  851. ((connector) = (__state)->connectors[__i].ptr, \
  852. (void)(connector) /* Only to avoid unused-but-set-variable warning */, \
  853. (old_connector_state) = (__state)->connectors[__i].old_state, \
  854. (new_connector_state) = (__state)->connectors[__i].new_state, 1))
  855. /**
  856. * for_each_old_connector_in_state - iterate over all connectors in an atomic update
  857. * @__state: &struct drm_atomic_state pointer
  858. * @connector: &struct drm_connector iteration cursor
  859. * @old_connector_state: &struct drm_connector_state iteration cursor for the
  860. * old state
  861. * @__i: int iteration cursor, for macro-internal use
  862. *
  863. * This iterates over all connectors in an atomic update, tracking only the old
  864. * state. This is useful in disable functions, where we need the old state the
  865. * hardware is still in.
  866. */
  867. #define for_each_old_connector_in_state(__state, connector, old_connector_state, __i) \
  868. for ((__i) = 0; \
  869. (__i) < (__state)->num_connector; \
  870. (__i)++) \
  871. for_each_if ((__state)->connectors[__i].ptr && \
  872. ((connector) = (__state)->connectors[__i].ptr, \
  873. (void)(connector) /* Only to avoid unused-but-set-variable warning */, \
  874. (old_connector_state) = (__state)->connectors[__i].old_state, 1))
  875. /**
  876. * for_each_new_connector_in_state - iterate over all connectors in an atomic update
  877. * @__state: &struct drm_atomic_state pointer
  878. * @connector: &struct drm_connector iteration cursor
  879. * @new_connector_state: &struct drm_connector_state iteration cursor for the
  880. * new state
  881. * @__i: int iteration cursor, for macro-internal use
  882. *
  883. * This iterates over all connectors in an atomic update, tracking only the new
  884. * state. This is useful in enable functions, where we need the new state the
  885. * hardware should be in when the atomic commit operation has completed.
  886. */
  887. #define for_each_new_connector_in_state(__state, connector, new_connector_state, __i) \
  888. for ((__i) = 0; \
  889. (__i) < (__state)->num_connector; \
  890. (__i)++) \
  891. for_each_if ((__state)->connectors[__i].ptr && \
  892. ((connector) = (__state)->connectors[__i].ptr, \
  893. (void)(connector) /* Only to avoid unused-but-set-variable warning */, \
  894. (new_connector_state) = (__state)->connectors[__i].new_state, \
  895. (void)(new_connector_state) /* Only to avoid unused-but-set-variable warning */, 1))
  896. /**
  897. * for_each_oldnew_crtc_in_state - iterate over all CRTCs in an atomic update
  898. * @__state: &struct drm_atomic_state pointer
  899. * @crtc: &struct drm_crtc iteration cursor
  900. * @old_crtc_state: &struct drm_crtc_state iteration cursor for the old state
  901. * @new_crtc_state: &struct drm_crtc_state iteration cursor for the new state
  902. * @__i: int iteration cursor, for macro-internal use
  903. *
  904. * This iterates over all CRTCs in an atomic update, tracking both old and
  905. * new state. This is useful in places where the state delta needs to be
  906. * considered, for example in atomic check functions.
  907. */
  908. #define for_each_oldnew_crtc_in_state(__state, crtc, old_crtc_state, new_crtc_state, __i) \
  909. for ((__i) = 0; \
  910. (__i) < (__state)->dev->mode_config.num_crtc; \
  911. (__i)++) \
  912. for_each_if ((__state)->crtcs[__i].ptr && \
  913. ((crtc) = (__state)->crtcs[__i].ptr, \
  914. (void)(crtc) /* Only to avoid unused-but-set-variable warning */, \
  915. (old_crtc_state) = (__state)->crtcs[__i].old_state, \
  916. (void)(old_crtc_state) /* Only to avoid unused-but-set-variable warning */, \
  917. (new_crtc_state) = (__state)->crtcs[__i].new_state, \
  918. (void)(new_crtc_state) /* Only to avoid unused-but-set-variable warning */, 1))
  919. /**
  920. * for_each_old_crtc_in_state - iterate over all CRTCs in an atomic update
  921. * @__state: &struct drm_atomic_state pointer
  922. * @crtc: &struct drm_crtc iteration cursor
  923. * @old_crtc_state: &struct drm_crtc_state iteration cursor for the old state
  924. * @__i: int iteration cursor, for macro-internal use
  925. *
  926. * This iterates over all CRTCs in an atomic update, tracking only the old
  927. * state. This is useful in disable functions, where we need the old state the
  928. * hardware is still in.
  929. */
  930. #define for_each_old_crtc_in_state(__state, crtc, old_crtc_state, __i) \
  931. for ((__i) = 0; \
  932. (__i) < (__state)->dev->mode_config.num_crtc; \
  933. (__i)++) \
  934. for_each_if ((__state)->crtcs[__i].ptr && \
  935. ((crtc) = (__state)->crtcs[__i].ptr, \
  936. (void)(crtc) /* Only to avoid unused-but-set-variable warning */, \
  937. (old_crtc_state) = (__state)->crtcs[__i].old_state, 1))
  938. /**
  939. * for_each_new_crtc_in_state - iterate over all CRTCs in an atomic update
  940. * @__state: &struct drm_atomic_state pointer
  941. * @crtc: &struct drm_crtc iteration cursor
  942. * @new_crtc_state: &struct drm_crtc_state iteration cursor for the new state
  943. * @__i: int iteration cursor, for macro-internal use
  944. *
  945. * This iterates over all CRTCs in an atomic update, tracking only the new
  946. * state. This is useful in enable functions, where we need the new state the
  947. * hardware should be in when the atomic commit operation has completed.
  948. */
  949. #define for_each_new_crtc_in_state(__state, crtc, new_crtc_state, __i) \
  950. for ((__i) = 0; \
  951. (__i) < (__state)->dev->mode_config.num_crtc; \
  952. (__i)++) \
  953. for_each_if ((__state)->crtcs[__i].ptr && \
  954. ((crtc) = (__state)->crtcs[__i].ptr, \
  955. (void)(crtc) /* Only to avoid unused-but-set-variable warning */, \
  956. (new_crtc_state) = (__state)->crtcs[__i].new_state, \
  957. (void)(new_crtc_state) /* Only to avoid unused-but-set-variable warning */, 1))
  958. /**
  959. * for_each_oldnew_colorop_in_state - iterate over all colorops in an atomic update
  960. * @__state: &struct drm_atomic_state pointer
  961. * @colorop: &struct drm_colorop iteration cursor
  962. * @old_colorop_state: &struct drm_colorop_state iteration cursor for the old state
  963. * @new_colorop_state: &struct drm_colorop_state iteration cursor for the new state
  964. * @__i: int iteration cursor, for macro-internal use
  965. *
  966. * This iterates over all colorops in an atomic update, tracking both old and
  967. * new state. This is useful in places where the state delta needs to be
  968. * considered, for example in atomic check functions.
  969. */
  970. #define for_each_oldnew_colorop_in_state(__state, colorop, old_colorop_state, \
  971. new_colorop_state, __i) \
  972. for ((__i) = 0; \
  973. (__i) < (__state)->dev->mode_config.num_colorop; \
  974. (__i)++) \
  975. for_each_if ((__state)->colorops[__i].ptr && \
  976. ((colorop) = (__state)->colorops[__i].ptr, \
  977. (void)(colorop) /* Only to avoid unused-but-set-variable warning */, \
  978. (old_colorop_state) = (__state)->colorops[__i].old_state,\
  979. (new_colorop_state) = (__state)->colorops[__i].new_state, 1))
  980. /**
  981. * for_each_new_colorop_in_state - iterate over all colorops in an atomic update
  982. * @__state: &struct drm_atomic_state pointer
  983. * @colorop: &struct drm_colorop iteration cursor
  984. * @new_colorop_state: &struct drm_colorop_state iteration cursor for the new state
  985. * @__i: int iteration cursor, for macro-internal use
  986. *
  987. * This iterates over all colorops in an atomic update, tracking new state. This is
  988. * useful in places where the state delta needs to be considered, for example in
  989. * atomic check functions.
  990. */
  991. #define for_each_new_colorop_in_state(__state, colorop, new_colorop_state, __i) \
  992. for ((__i) = 0; \
  993. (__i) < (__state)->dev->mode_config.num_colorop; \
  994. (__i)++) \
  995. for_each_if ((__state)->colorops[__i].ptr && \
  996. ((colorop) = (__state)->colorops[__i].ptr, \
  997. (void)(colorop) /* Only to avoid unused-but-set-variable warning */, \
  998. (new_colorop_state) = (__state)->colorops[__i].new_state, 1))
  999. /**
  1000. * for_each_oldnew_plane_in_state - iterate over all planes in an atomic update
  1001. * @__state: &struct drm_atomic_state pointer
  1002. * @plane: &struct drm_plane iteration cursor
  1003. * @old_plane_state: &struct drm_plane_state iteration cursor for the old state
  1004. * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
  1005. * @__i: int iteration cursor, for macro-internal use
  1006. *
  1007. * This iterates over all planes in an atomic update, tracking both old and
  1008. * new state. This is useful in places where the state delta needs to be
  1009. * considered, for example in atomic check functions.
  1010. */
  1011. #define for_each_oldnew_plane_in_state(__state, plane, old_plane_state, new_plane_state, __i) \
  1012. for ((__i) = 0; \
  1013. (__i) < (__state)->dev->mode_config.num_total_plane; \
  1014. (__i)++) \
  1015. for_each_if ((__state)->planes[__i].ptr && \
  1016. ((plane) = (__state)->planes[__i].ptr, \
  1017. (void)(plane) /* Only to avoid unused-but-set-variable warning */, \
  1018. (old_plane_state) = (__state)->planes[__i].old_state,\
  1019. (new_plane_state) = (__state)->planes[__i].new_state, 1))
  1020. /**
  1021. * for_each_oldnew_plane_in_state_reverse - iterate over all planes in an atomic
  1022. * update in reverse order
  1023. * @__state: &struct drm_atomic_state pointer
  1024. * @plane: &struct drm_plane iteration cursor
  1025. * @old_plane_state: &struct drm_plane_state iteration cursor for the old state
  1026. * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
  1027. * @__i: int iteration cursor, for macro-internal use
  1028. *
  1029. * This iterates over all planes in an atomic update in reverse order,
  1030. * tracking both old and new state. This is useful in places where the
  1031. * state delta needs to be considered, for example in atomic check functions.
  1032. */
  1033. #define for_each_oldnew_plane_in_state_reverse(__state, plane, old_plane_state, new_plane_state, __i) \
  1034. for ((__i) = ((__state)->dev->mode_config.num_total_plane - 1); \
  1035. (__i) >= 0; \
  1036. (__i)--) \
  1037. for_each_if ((__state)->planes[__i].ptr && \
  1038. ((plane) = (__state)->planes[__i].ptr, \
  1039. (old_plane_state) = (__state)->planes[__i].old_state,\
  1040. (new_plane_state) = (__state)->planes[__i].new_state, 1))
  1041. /**
  1042. * for_each_new_plane_in_state_reverse - other than only tracking new state,
  1043. * it's the same as for_each_oldnew_plane_in_state_reverse
  1044. * @__state: &struct drm_atomic_state pointer
  1045. * @plane: &struct drm_plane iteration cursor
  1046. * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
  1047. * @__i: int iteration cursor, for macro-internal use
  1048. */
  1049. #define for_each_new_plane_in_state_reverse(__state, plane, new_plane_state, __i) \
  1050. for ((__i) = ((__state)->dev->mode_config.num_total_plane - 1); \
  1051. (__i) >= 0; \
  1052. (__i)--) \
  1053. for_each_if ((__state)->planes[__i].ptr && \
  1054. ((plane) = (__state)->planes[__i].ptr, \
  1055. (new_plane_state) = (__state)->planes[__i].new_state, 1))
  1056. /**
  1057. * for_each_old_plane_in_state - iterate over all planes in an atomic update
  1058. * @__state: &struct drm_atomic_state pointer
  1059. * @plane: &struct drm_plane iteration cursor
  1060. * @old_plane_state: &struct drm_plane_state iteration cursor for the old state
  1061. * @__i: int iteration cursor, for macro-internal use
  1062. *
  1063. * This iterates over all planes in an atomic update, tracking only the old
  1064. * state. This is useful in disable functions, where we need the old state the
  1065. * hardware is still in.
  1066. */
  1067. #define for_each_old_plane_in_state(__state, plane, old_plane_state, __i) \
  1068. for ((__i) = 0; \
  1069. (__i) < (__state)->dev->mode_config.num_total_plane; \
  1070. (__i)++) \
  1071. for_each_if ((__state)->planes[__i].ptr && \
  1072. ((plane) = (__state)->planes[__i].ptr, \
  1073. (old_plane_state) = (__state)->planes[__i].old_state, 1))
  1074. /**
  1075. * for_each_new_plane_in_state - iterate over all planes in an atomic update
  1076. * @__state: &struct drm_atomic_state pointer
  1077. * @plane: &struct drm_plane iteration cursor
  1078. * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
  1079. * @__i: int iteration cursor, for macro-internal use
  1080. *
  1081. * This iterates over all planes in an atomic update, tracking only the new
  1082. * state. This is useful in enable functions, where we need the new state the
  1083. * hardware should be in when the atomic commit operation has completed.
  1084. */
  1085. #define for_each_new_plane_in_state(__state, plane, new_plane_state, __i) \
  1086. for ((__i) = 0; \
  1087. (__i) < (__state)->dev->mode_config.num_total_plane; \
  1088. (__i)++) \
  1089. for_each_if ((__state)->planes[__i].ptr && \
  1090. ((plane) = (__state)->planes[__i].ptr, \
  1091. (void)(plane) /* Only to avoid unused-but-set-variable warning */, \
  1092. (new_plane_state) = (__state)->planes[__i].new_state, \
  1093. (void)(new_plane_state) /* Only to avoid unused-but-set-variable warning */, 1))
  1094. /**
  1095. * for_each_oldnew_private_obj_in_state - iterate over all private objects in an atomic update
  1096. * @__state: &struct drm_atomic_state pointer
  1097. * @obj: &struct drm_private_obj iteration cursor
  1098. * @old_obj_state: &struct drm_private_state iteration cursor for the old state
  1099. * @new_obj_state: &struct drm_private_state iteration cursor for the new state
  1100. * @__i: int iteration cursor, for macro-internal use
  1101. *
  1102. * This iterates over all private objects in an atomic update, tracking both
  1103. * old and new state. This is useful in places where the state delta needs
  1104. * to be considered, for example in atomic check functions.
  1105. */
  1106. #define for_each_oldnew_private_obj_in_state(__state, obj, old_obj_state, new_obj_state, __i) \
  1107. for ((__i) = 0; \
  1108. (__i) < (__state)->num_private_objs && \
  1109. ((obj) = (__state)->private_objs[__i].ptr, \
  1110. (old_obj_state) = (__state)->private_objs[__i].old_state, \
  1111. (new_obj_state) = (__state)->private_objs[__i].new_state, 1); \
  1112. (__i)++)
  1113. /**
  1114. * for_each_old_private_obj_in_state - iterate over all private objects in an atomic update
  1115. * @__state: &struct drm_atomic_state pointer
  1116. * @obj: &struct drm_private_obj iteration cursor
  1117. * @old_obj_state: &struct drm_private_state iteration cursor for the old state
  1118. * @__i: int iteration cursor, for macro-internal use
  1119. *
  1120. * This iterates over all private objects in an atomic update, tracking only
  1121. * the old state. This is useful in disable functions, where we need the old
  1122. * state the hardware is still in.
  1123. */
  1124. #define for_each_old_private_obj_in_state(__state, obj, old_obj_state, __i) \
  1125. for ((__i) = 0; \
  1126. (__i) < (__state)->num_private_objs && \
  1127. ((obj) = (__state)->private_objs[__i].ptr, \
  1128. (old_obj_state) = (__state)->private_objs[__i].old_state, 1); \
  1129. (__i)++)
  1130. /**
  1131. * for_each_new_private_obj_in_state - iterate over all private objects in an atomic update
  1132. * @__state: &struct drm_atomic_state pointer
  1133. * @obj: &struct drm_private_obj iteration cursor
  1134. * @new_obj_state: &struct drm_private_state iteration cursor for the new state
  1135. * @__i: int iteration cursor, for macro-internal use
  1136. *
  1137. * This iterates over all private objects in an atomic update, tracking only
  1138. * the new state. This is useful in enable functions, where we need the new state the
  1139. * hardware should be in when the atomic commit operation has completed.
  1140. */
  1141. #define for_each_new_private_obj_in_state(__state, obj, new_obj_state, __i) \
  1142. for ((__i) = 0; \
  1143. (__i) < (__state)->num_private_objs && \
  1144. ((obj) = (__state)->private_objs[__i].ptr, \
  1145. (void)(obj) /* Only to avoid unused-but-set-variable warning */, \
  1146. (new_obj_state) = (__state)->private_objs[__i].new_state, 1); \
  1147. (__i)++)
  1148. /**
  1149. * drm_atomic_crtc_needs_modeset - compute combined modeset need
  1150. * @state: &drm_crtc_state for the CRTC
  1151. *
  1152. * To give drivers flexibility &struct drm_crtc_state has 3 booleans to track
  1153. * whether the state CRTC changed enough to need a full modeset cycle:
  1154. * mode_changed, active_changed and connectors_changed. This helper simply
  1155. * combines these three to compute the overall need for a modeset for @state.
  1156. *
  1157. * The atomic helper code sets these booleans, but drivers can and should
  1158. * change them appropriately to accurately represent whether a modeset is
  1159. * really needed. In general, drivers should avoid full modesets whenever
  1160. * possible.
  1161. *
  1162. * For example if the CRTC mode has changed, and the hardware is able to enact
  1163. * the requested mode change without going through a full modeset, the driver
  1164. * should clear mode_changed in its &drm_mode_config_funcs.atomic_check
  1165. * implementation.
  1166. */
  1167. static inline bool
  1168. drm_atomic_crtc_needs_modeset(const struct drm_crtc_state *state)
  1169. {
  1170. return state->mode_changed || state->active_changed ||
  1171. state->connectors_changed;
  1172. }
  1173. /**
  1174. * drm_atomic_crtc_effectively_active - compute whether CRTC is actually active
  1175. * @state: &drm_crtc_state for the CRTC
  1176. *
  1177. * When in self refresh mode, the crtc_state->active value will be false, since
  1178. * the CRTC is off. However in some cases we're interested in whether the CRTC
  1179. * is active, or effectively active (ie: it's connected to an active display).
  1180. * In these cases, use this function instead of just checking active.
  1181. */
  1182. static inline bool
  1183. drm_atomic_crtc_effectively_active(const struct drm_crtc_state *state)
  1184. {
  1185. return state->active || state->self_refresh_active;
  1186. }
  1187. /**
  1188. * struct drm_bus_cfg - bus configuration
  1189. *
  1190. * This structure stores the configuration of a physical bus between two
  1191. * components in an output pipeline, usually between two bridges, an encoder
  1192. * and a bridge, or a bridge and a connector.
  1193. *
  1194. * The bus configuration is stored in &drm_bridge_state separately for the
  1195. * input and output buses, as seen from the point of view of each bridge. The
  1196. * bus configuration of a bridge output is usually identical to the
  1197. * configuration of the next bridge's input, but may differ if the signals are
  1198. * modified between the two bridges, for instance by an inverter on the board.
  1199. * The input and output configurations of a bridge may differ if the bridge
  1200. * modifies the signals internally, for instance by performing format
  1201. * conversion, or modifying signals polarities.
  1202. */
  1203. struct drm_bus_cfg {
  1204. /**
  1205. * @format: format used on this bus (one of the MEDIA_BUS_FMT_* format)
  1206. *
  1207. * This field should not be directly modified by drivers
  1208. * (drm_atomic_bridge_chain_select_bus_fmts() takes care of the bus
  1209. * format negotiation).
  1210. */
  1211. u32 format;
  1212. /**
  1213. * @flags: DRM_BUS_* flags used on this bus
  1214. */
  1215. u32 flags;
  1216. };
  1217. /**
  1218. * struct drm_bridge_state - Atomic bridge state object
  1219. */
  1220. struct drm_bridge_state {
  1221. /**
  1222. * @base: inherit from &drm_private_state
  1223. */
  1224. struct drm_private_state base;
  1225. /**
  1226. * @bridge: the bridge this state refers to
  1227. */
  1228. struct drm_bridge *bridge;
  1229. /**
  1230. * @input_bus_cfg: input bus configuration
  1231. */
  1232. struct drm_bus_cfg input_bus_cfg;
  1233. /**
  1234. * @output_bus_cfg: output bus configuration
  1235. */
  1236. struct drm_bus_cfg output_bus_cfg;
  1237. };
  1238. static inline struct drm_bridge_state *
  1239. drm_priv_to_bridge_state(struct drm_private_state *priv)
  1240. {
  1241. return container_of(priv, struct drm_bridge_state, base);
  1242. }
  1243. struct drm_bridge_state *
  1244. drm_atomic_get_bridge_state(struct drm_atomic_state *state,
  1245. struct drm_bridge *bridge);
  1246. struct drm_bridge_state *
  1247. drm_atomic_get_old_bridge_state(const struct drm_atomic_state *state,
  1248. struct drm_bridge *bridge);
  1249. struct drm_bridge_state *
  1250. drm_atomic_get_new_bridge_state(const struct drm_atomic_state *state,
  1251. struct drm_bridge *bridge);
  1252. #endif /* DRM_ATOMIC_H_ */