drm_atomic.h 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  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_planes_state {
  150. struct drm_plane *ptr;
  151. struct drm_plane_state *state, *old_state, *new_state;
  152. };
  153. struct __drm_crtcs_state {
  154. struct drm_crtc *ptr;
  155. struct drm_crtc_state *state, *old_state, *new_state;
  156. /**
  157. * @commit:
  158. *
  159. * A reference to the CRTC commit object that is kept for use by
  160. * drm_atomic_helper_wait_for_flip_done() after
  161. * drm_atomic_helper_commit_hw_done() is called. This ensures that a
  162. * concurrent commit won't free a commit object that is still in use.
  163. */
  164. struct drm_crtc_commit *commit;
  165. s32 __user *out_fence_ptr;
  166. u64 last_vblank_count;
  167. };
  168. struct __drm_connnectors_state {
  169. struct drm_connector *ptr;
  170. struct drm_connector_state *state, *old_state, *new_state;
  171. /**
  172. * @out_fence_ptr:
  173. *
  174. * User-provided pointer which the kernel uses to return a sync_file
  175. * file descriptor. Used by writeback connectors to signal completion of
  176. * the writeback.
  177. */
  178. s32 __user *out_fence_ptr;
  179. };
  180. struct drm_private_obj;
  181. struct drm_private_state;
  182. /**
  183. * struct drm_private_state_funcs - atomic state functions for private objects
  184. *
  185. * These hooks are used by atomic helpers to create, swap and destroy states of
  186. * private objects. The structure itself is used as a vtable to identify the
  187. * associated private object type. Each private object type that needs to be
  188. * added to the atomic states is expected to have an implementation of these
  189. * hooks and pass a pointer to its drm_private_state_funcs struct to
  190. * drm_atomic_get_private_obj_state().
  191. */
  192. struct drm_private_state_funcs {
  193. /**
  194. * @atomic_duplicate_state:
  195. *
  196. * Duplicate the current state of the private object and return it. It
  197. * is an error to call this before obj->state has been initialized.
  198. *
  199. * RETURNS:
  200. *
  201. * Duplicated atomic state or NULL when obj->state is not
  202. * initialized or allocation failed.
  203. */
  204. struct drm_private_state *(*atomic_duplicate_state)(struct drm_private_obj *obj);
  205. /**
  206. * @atomic_destroy_state:
  207. *
  208. * Frees the private object state created with @atomic_duplicate_state.
  209. */
  210. void (*atomic_destroy_state)(struct drm_private_obj *obj,
  211. struct drm_private_state *state);
  212. /**
  213. * @atomic_print_state:
  214. *
  215. * If driver subclasses &struct drm_private_state, it should implement
  216. * this optional hook for printing additional driver specific state.
  217. *
  218. * Do not call this directly, use drm_atomic_private_obj_print_state()
  219. * instead.
  220. */
  221. void (*atomic_print_state)(struct drm_printer *p,
  222. const struct drm_private_state *state);
  223. };
  224. /**
  225. * struct drm_private_obj - base struct for driver private atomic object
  226. *
  227. * A driver private object is initialized by calling
  228. * drm_atomic_private_obj_init() and cleaned up by calling
  229. * drm_atomic_private_obj_fini().
  230. *
  231. * Currently only tracks the state update functions and the opaque driver
  232. * private state itself, but in the future might also track which
  233. * &drm_modeset_lock is required to duplicate and update this object's state.
  234. *
  235. * All private objects must be initialized before the DRM device they are
  236. * attached to is registered to the DRM subsystem (call to drm_dev_register())
  237. * and should stay around until this DRM device is unregistered (call to
  238. * drm_dev_unregister()). In other words, private objects lifetime is tied
  239. * to the DRM device lifetime. This implies that:
  240. *
  241. * 1/ all calls to drm_atomic_private_obj_init() must be done before calling
  242. * drm_dev_register()
  243. * 2/ all calls to drm_atomic_private_obj_fini() must be done after calling
  244. * drm_dev_unregister()
  245. *
  246. * If that private object is used to store a state shared by multiple
  247. * CRTCs, proper care must be taken to ensure that non-blocking commits are
  248. * properly ordered to avoid a use-after-free issue.
  249. *
  250. * Indeed, assuming a sequence of two non-blocking &drm_atomic_commit on two
  251. * different &drm_crtc using different &drm_plane and &drm_connector, so with no
  252. * resources shared, there's no guarantee on which commit is going to happen
  253. * first. However, the second &drm_atomic_commit will consider the first
  254. * &drm_private_obj its old state, and will be in charge of freeing it whenever
  255. * the second &drm_atomic_commit is done.
  256. *
  257. * If the first &drm_atomic_commit happens after it, it will consider its
  258. * &drm_private_obj the new state and will be likely to access it, resulting in
  259. * an access to a freed memory region. Drivers should store (and get a reference
  260. * to) the &drm_crtc_commit structure in our private state in
  261. * &drm_mode_config_helper_funcs.atomic_commit_setup, and then wait for that
  262. * commit to complete as the first step of
  263. * &drm_mode_config_helper_funcs.atomic_commit_tail, similar to
  264. * drm_atomic_helper_wait_for_dependencies().
  265. */
  266. struct drm_private_obj {
  267. /**
  268. * @head: List entry used to attach a private object to a &drm_device
  269. * (queued to &drm_mode_config.privobj_list).
  270. */
  271. struct list_head head;
  272. /**
  273. * @lock: Modeset lock to protect the state object.
  274. */
  275. struct drm_modeset_lock lock;
  276. /**
  277. * @state: Current atomic state for this driver private object.
  278. */
  279. struct drm_private_state *state;
  280. /**
  281. * @funcs:
  282. *
  283. * Functions to manipulate the state of this driver private object, see
  284. * &drm_private_state_funcs.
  285. */
  286. const struct drm_private_state_funcs *funcs;
  287. };
  288. /**
  289. * drm_for_each_privobj() - private object iterator
  290. *
  291. * @privobj: pointer to the current private object. Updated after each
  292. * iteration
  293. * @dev: the DRM device we want get private objects from
  294. *
  295. * Allows one to iterate over all private objects attached to @dev
  296. */
  297. #define drm_for_each_privobj(privobj, dev) \
  298. list_for_each_entry(privobj, &(dev)->mode_config.privobj_list, head)
  299. /**
  300. * struct drm_private_state - base struct for driver private object state
  301. *
  302. * Currently only contains a backpointer to the overall atomic update,
  303. * and the relevant private object but in the future also might hold
  304. * synchronization information similar to e.g. &drm_crtc.commit.
  305. */
  306. struct drm_private_state {
  307. /**
  308. * @state: backpointer to global drm_atomic_state
  309. */
  310. struct drm_atomic_state *state;
  311. /**
  312. * @obj: backpointer to the private object
  313. */
  314. struct drm_private_obj *obj;
  315. };
  316. struct __drm_private_objs_state {
  317. struct drm_private_obj *ptr;
  318. struct drm_private_state *state, *old_state, *new_state;
  319. };
  320. /**
  321. * struct drm_atomic_state - Atomic commit structure
  322. *
  323. * This structure is the kernel counterpart of @drm_mode_atomic and represents
  324. * an atomic commit that transitions from an old to a new display state. It
  325. * contains all the objects affected by the atomic commit and both the new
  326. * state structures and pointers to the old state structures for
  327. * these.
  328. *
  329. * States are added to an atomic update by calling drm_atomic_get_crtc_state(),
  330. * drm_atomic_get_plane_state(), drm_atomic_get_connector_state(), or for
  331. * private state structures, drm_atomic_get_private_obj_state().
  332. */
  333. struct drm_atomic_state {
  334. /**
  335. * @ref:
  336. *
  337. * Count of all references to this update (will not be freed until zero).
  338. */
  339. struct kref ref;
  340. /**
  341. * @dev: Parent DRM Device.
  342. */
  343. struct drm_device *dev;
  344. /**
  345. * @allow_modeset:
  346. *
  347. * Allow full modeset. This is used by the ATOMIC IOCTL handler to
  348. * implement the DRM_MODE_ATOMIC_ALLOW_MODESET flag. Drivers should
  349. * generally not consult this flag, but instead look at the output of
  350. * drm_atomic_crtc_needs_modeset(). The detailed rules are:
  351. *
  352. * - Drivers must not consult @allow_modeset in the atomic commit path.
  353. * Use drm_atomic_crtc_needs_modeset() instead.
  354. *
  355. * - Drivers must consult @allow_modeset before adding unrelated struct
  356. * drm_crtc_state to this commit by calling
  357. * drm_atomic_get_crtc_state(). See also the warning in the
  358. * documentation for that function.
  359. *
  360. * - Drivers must never change this flag, it is under the exclusive
  361. * control of userspace.
  362. *
  363. * - Drivers may consult @allow_modeset in the atomic check path, if
  364. * they have the choice between an optimal hardware configuration
  365. * which requires a modeset, and a less optimal configuration which
  366. * can be committed without a modeset. An example would be suboptimal
  367. * scanout FIFO allocation resulting in increased idle power
  368. * consumption. This allows userspace to avoid flickering and delays
  369. * for the normal composition loop at reasonable cost.
  370. */
  371. bool allow_modeset : 1;
  372. /**
  373. * @legacy_cursor_update:
  374. *
  375. * Hint to enforce legacy cursor IOCTL semantics.
  376. *
  377. * WARNING: This is thoroughly broken and pretty much impossible to
  378. * implement correctly. Drivers must ignore this and should instead
  379. * implement &drm_plane_helper_funcs.atomic_async_check and
  380. * &drm_plane_helper_funcs.atomic_async_commit hooks. New users of this
  381. * flag are not allowed.
  382. */
  383. bool legacy_cursor_update : 1;
  384. /**
  385. * @async_update: hint for asynchronous plane update
  386. */
  387. bool async_update : 1;
  388. /**
  389. * @duplicated:
  390. *
  391. * Indicates whether or not this atomic state was duplicated using
  392. * drm_atomic_helper_duplicate_state(). Drivers and atomic helpers
  393. * should use this to fixup normal inconsistencies in duplicated
  394. * states.
  395. */
  396. bool duplicated : 1;
  397. /**
  398. * @planes:
  399. *
  400. * Pointer to array of @drm_plane and @drm_plane_state part of this
  401. * update.
  402. */
  403. struct __drm_planes_state *planes;
  404. /**
  405. * @crtcs:
  406. *
  407. * Pointer to array of @drm_crtc and @drm_crtc_state part of this
  408. * update.
  409. */
  410. struct __drm_crtcs_state *crtcs;
  411. /**
  412. * @num_connector: size of the @connectors array
  413. */
  414. int num_connector;
  415. /**
  416. * @connectors:
  417. *
  418. * Pointer to array of @drm_connector and @drm_connector_state part of
  419. * this update.
  420. */
  421. struct __drm_connnectors_state *connectors;
  422. /**
  423. * @num_private_objs: size of the @private_objs array
  424. */
  425. int num_private_objs;
  426. /**
  427. * @private_objs:
  428. *
  429. * Pointer to array of @drm_private_obj and @drm_private_obj_state part
  430. * of this update.
  431. */
  432. struct __drm_private_objs_state *private_objs;
  433. /**
  434. * @acquire_ctx: acquire context for this atomic modeset state update
  435. */
  436. struct drm_modeset_acquire_ctx *acquire_ctx;
  437. /**
  438. * @fake_commit:
  439. *
  440. * Used for signaling unbound planes/connectors.
  441. * When a connector or plane is not bound to any CRTC, it's still important
  442. * to preserve linearity to prevent the atomic states from being freed too early.
  443. *
  444. * This commit (if set) is not bound to any CRTC, but will be completed when
  445. * drm_atomic_helper_commit_hw_done() is called.
  446. */
  447. struct drm_crtc_commit *fake_commit;
  448. /**
  449. * @commit_work:
  450. *
  451. * Work item which can be used by the driver or helpers to execute the
  452. * commit without blocking.
  453. */
  454. struct work_struct commit_work;
  455. };
  456. void __drm_crtc_commit_free(struct kref *kref);
  457. /**
  458. * drm_crtc_commit_get - acquire a reference to the CRTC commit
  459. * @commit: CRTC commit
  460. *
  461. * Increases the reference of @commit.
  462. *
  463. * Returns:
  464. * The pointer to @commit, with reference increased.
  465. */
  466. static inline struct drm_crtc_commit *drm_crtc_commit_get(struct drm_crtc_commit *commit)
  467. {
  468. kref_get(&commit->ref);
  469. return commit;
  470. }
  471. /**
  472. * drm_crtc_commit_put - release a reference to the CRTC commmit
  473. * @commit: CRTC commit
  474. *
  475. * This releases a reference to @commit which is freed after removing the
  476. * final reference. No locking required and callable from any context.
  477. */
  478. static inline void drm_crtc_commit_put(struct drm_crtc_commit *commit)
  479. {
  480. kref_put(&commit->ref, __drm_crtc_commit_free);
  481. }
  482. int drm_crtc_commit_wait(struct drm_crtc_commit *commit);
  483. struct drm_atomic_state * __must_check
  484. drm_atomic_state_alloc(struct drm_device *dev);
  485. void drm_atomic_state_clear(struct drm_atomic_state *state);
  486. /**
  487. * drm_atomic_state_get - acquire a reference to the atomic state
  488. * @state: The atomic state
  489. *
  490. * Returns a new reference to the @state
  491. */
  492. static inline struct drm_atomic_state *
  493. drm_atomic_state_get(struct drm_atomic_state *state)
  494. {
  495. kref_get(&state->ref);
  496. return state;
  497. }
  498. void __drm_atomic_state_free(struct kref *ref);
  499. /**
  500. * drm_atomic_state_put - release a reference to the atomic state
  501. * @state: The atomic state
  502. *
  503. * This releases a reference to @state which is freed after removing the
  504. * final reference. No locking required and callable from any context.
  505. */
  506. static inline void drm_atomic_state_put(struct drm_atomic_state *state)
  507. {
  508. kref_put(&state->ref, __drm_atomic_state_free);
  509. }
  510. int __must_check
  511. drm_atomic_state_init(struct drm_device *dev, struct drm_atomic_state *state);
  512. void drm_atomic_state_default_clear(struct drm_atomic_state *state);
  513. void drm_atomic_state_default_release(struct drm_atomic_state *state);
  514. struct drm_crtc_state * __must_check
  515. drm_atomic_get_crtc_state(struct drm_atomic_state *state,
  516. struct drm_crtc *crtc);
  517. struct drm_plane_state * __must_check
  518. drm_atomic_get_plane_state(struct drm_atomic_state *state,
  519. struct drm_plane *plane);
  520. struct drm_connector_state * __must_check
  521. drm_atomic_get_connector_state(struct drm_atomic_state *state,
  522. struct drm_connector *connector);
  523. void drm_atomic_private_obj_init(struct drm_device *dev,
  524. struct drm_private_obj *obj,
  525. struct drm_private_state *state,
  526. const struct drm_private_state_funcs *funcs);
  527. void drm_atomic_private_obj_fini(struct drm_private_obj *obj);
  528. struct drm_private_state * __must_check
  529. drm_atomic_get_private_obj_state(struct drm_atomic_state *state,
  530. struct drm_private_obj *obj);
  531. struct drm_private_state *
  532. drm_atomic_get_old_private_obj_state(const struct drm_atomic_state *state,
  533. struct drm_private_obj *obj);
  534. struct drm_private_state *
  535. drm_atomic_get_new_private_obj_state(const struct drm_atomic_state *state,
  536. struct drm_private_obj *obj);
  537. struct drm_connector *
  538. drm_atomic_get_old_connector_for_encoder(const struct drm_atomic_state *state,
  539. struct drm_encoder *encoder);
  540. struct drm_connector *
  541. drm_atomic_get_new_connector_for_encoder(const struct drm_atomic_state *state,
  542. struct drm_encoder *encoder);
  543. struct drm_crtc *
  544. drm_atomic_get_old_crtc_for_encoder(struct drm_atomic_state *state,
  545. struct drm_encoder *encoder);
  546. struct drm_crtc *
  547. drm_atomic_get_new_crtc_for_encoder(struct drm_atomic_state *state,
  548. struct drm_encoder *encoder);
  549. /**
  550. * drm_atomic_get_existing_crtc_state - get CRTC state, if it exists
  551. * @state: global atomic state object
  552. * @crtc: CRTC to grab
  553. *
  554. * This function returns the CRTC state for the given CRTC, or NULL
  555. * if the CRTC is not part of the global atomic state.
  556. *
  557. * This function is deprecated, @drm_atomic_get_old_crtc_state or
  558. * @drm_atomic_get_new_crtc_state should be used instead.
  559. */
  560. static inline struct drm_crtc_state *
  561. drm_atomic_get_existing_crtc_state(const struct drm_atomic_state *state,
  562. struct drm_crtc *crtc)
  563. {
  564. return state->crtcs[drm_crtc_index(crtc)].state;
  565. }
  566. /**
  567. * drm_atomic_get_old_crtc_state - get old CRTC state, if it exists
  568. * @state: global atomic state object
  569. * @crtc: CRTC to grab
  570. *
  571. * This function returns the old CRTC state for the given CRTC, or
  572. * NULL if the CRTC is not part of the global atomic state.
  573. */
  574. static inline struct drm_crtc_state *
  575. drm_atomic_get_old_crtc_state(const struct drm_atomic_state *state,
  576. struct drm_crtc *crtc)
  577. {
  578. return state->crtcs[drm_crtc_index(crtc)].old_state;
  579. }
  580. /**
  581. * drm_atomic_get_new_crtc_state - get new CRTC state, if it exists
  582. * @state: global atomic state object
  583. * @crtc: CRTC to grab
  584. *
  585. * This function returns the new CRTC state for the given CRTC, or
  586. * NULL if the CRTC is not part of the global atomic state.
  587. */
  588. static inline struct drm_crtc_state *
  589. drm_atomic_get_new_crtc_state(const struct drm_atomic_state *state,
  590. struct drm_crtc *crtc)
  591. {
  592. return state->crtcs[drm_crtc_index(crtc)].new_state;
  593. }
  594. /**
  595. * drm_atomic_get_existing_plane_state - get plane state, if it exists
  596. * @state: global atomic state object
  597. * @plane: plane to grab
  598. *
  599. * This function returns the plane state for the given plane, or NULL
  600. * if the plane is not part of the global atomic state.
  601. *
  602. * This function is deprecated, @drm_atomic_get_old_plane_state or
  603. * @drm_atomic_get_new_plane_state should be used instead.
  604. */
  605. static inline struct drm_plane_state *
  606. drm_atomic_get_existing_plane_state(const struct drm_atomic_state *state,
  607. struct drm_plane *plane)
  608. {
  609. return state->planes[drm_plane_index(plane)].state;
  610. }
  611. /**
  612. * drm_atomic_get_old_plane_state - get plane state, if it exists
  613. * @state: global atomic state object
  614. * @plane: plane to grab
  615. *
  616. * This function returns the old plane state for the given plane, or
  617. * NULL if the plane is not part of the global atomic state.
  618. */
  619. static inline struct drm_plane_state *
  620. drm_atomic_get_old_plane_state(const struct drm_atomic_state *state,
  621. struct drm_plane *plane)
  622. {
  623. return state->planes[drm_plane_index(plane)].old_state;
  624. }
  625. /**
  626. * drm_atomic_get_new_plane_state - get plane state, if it exists
  627. * @state: global atomic state object
  628. * @plane: plane to grab
  629. *
  630. * This function returns the new plane state for the given plane, or
  631. * NULL if the plane is not part of the global atomic state.
  632. */
  633. static inline struct drm_plane_state *
  634. drm_atomic_get_new_plane_state(const struct drm_atomic_state *state,
  635. struct drm_plane *plane)
  636. {
  637. return state->planes[drm_plane_index(plane)].new_state;
  638. }
  639. /**
  640. * drm_atomic_get_existing_connector_state - get connector state, if it exists
  641. * @state: global atomic state object
  642. * @connector: connector to grab
  643. *
  644. * This function returns the connector state for the given connector,
  645. * or NULL if the connector is not part of the global atomic state.
  646. *
  647. * This function is deprecated, @drm_atomic_get_old_connector_state or
  648. * @drm_atomic_get_new_connector_state should be used instead.
  649. */
  650. static inline struct drm_connector_state *
  651. drm_atomic_get_existing_connector_state(const struct drm_atomic_state *state,
  652. struct drm_connector *connector)
  653. {
  654. int index = drm_connector_index(connector);
  655. if (index >= state->num_connector)
  656. return NULL;
  657. return state->connectors[index].state;
  658. }
  659. /**
  660. * drm_atomic_get_old_connector_state - get connector state, if it exists
  661. * @state: global atomic state object
  662. * @connector: connector to grab
  663. *
  664. * This function returns the old connector state for the given connector,
  665. * or NULL if the connector is not part of the global atomic state.
  666. */
  667. static inline struct drm_connector_state *
  668. drm_atomic_get_old_connector_state(const struct drm_atomic_state *state,
  669. struct drm_connector *connector)
  670. {
  671. int index = drm_connector_index(connector);
  672. if (index >= state->num_connector)
  673. return NULL;
  674. return state->connectors[index].old_state;
  675. }
  676. /**
  677. * drm_atomic_get_new_connector_state - get connector state, if it exists
  678. * @state: global atomic state object
  679. * @connector: connector to grab
  680. *
  681. * This function returns the new connector state for the given connector,
  682. * or NULL if the connector is not part of the global atomic state.
  683. */
  684. static inline struct drm_connector_state *
  685. drm_atomic_get_new_connector_state(const struct drm_atomic_state *state,
  686. struct drm_connector *connector)
  687. {
  688. int index = drm_connector_index(connector);
  689. if (index >= state->num_connector)
  690. return NULL;
  691. return state->connectors[index].new_state;
  692. }
  693. /**
  694. * __drm_atomic_get_current_plane_state - get current plane state
  695. * @state: global atomic state object
  696. * @plane: plane to grab
  697. *
  698. * This function returns the plane state for the given plane, either from
  699. * @state, or if the plane isn't part of the atomic state update, from @plane.
  700. * This is useful in atomic check callbacks, when drivers need to peek at, but
  701. * not change, state of other planes, since it avoids threading an error code
  702. * back up the call chain.
  703. *
  704. * WARNING:
  705. *
  706. * Note that this function is in general unsafe since it doesn't check for the
  707. * required locking for access state structures. Drivers must ensure that it is
  708. * safe to access the returned state structure through other means. One common
  709. * example is when planes are fixed to a single CRTC, and the driver knows that
  710. * the CRTC lock is held already. In that case holding the CRTC lock gives a
  711. * read-lock on all planes connected to that CRTC. But if planes can be
  712. * reassigned things get more tricky. In that case it's better to use
  713. * drm_atomic_get_plane_state and wire up full error handling.
  714. *
  715. * Returns:
  716. *
  717. * Read-only pointer to the current plane state.
  718. */
  719. static inline const struct drm_plane_state *
  720. __drm_atomic_get_current_plane_state(const struct drm_atomic_state *state,
  721. struct drm_plane *plane)
  722. {
  723. if (state->planes[drm_plane_index(plane)].state)
  724. return state->planes[drm_plane_index(plane)].state;
  725. return plane->state;
  726. }
  727. int __must_check
  728. drm_atomic_add_encoder_bridges(struct drm_atomic_state *state,
  729. struct drm_encoder *encoder);
  730. int __must_check
  731. drm_atomic_add_affected_connectors(struct drm_atomic_state *state,
  732. struct drm_crtc *crtc);
  733. int __must_check
  734. drm_atomic_add_affected_planes(struct drm_atomic_state *state,
  735. struct drm_crtc *crtc);
  736. int __must_check drm_atomic_check_only(struct drm_atomic_state *state);
  737. int __must_check drm_atomic_commit(struct drm_atomic_state *state);
  738. int __must_check drm_atomic_nonblocking_commit(struct drm_atomic_state *state);
  739. void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
  740. /**
  741. * for_each_oldnew_connector_in_state - iterate over all connectors in an atomic update
  742. * @__state: &struct drm_atomic_state pointer
  743. * @connector: &struct drm_connector iteration cursor
  744. * @old_connector_state: &struct drm_connector_state iteration cursor for the
  745. * old state
  746. * @new_connector_state: &struct drm_connector_state iteration cursor for the
  747. * new state
  748. * @__i: int iteration cursor, for macro-internal use
  749. *
  750. * This iterates over all connectors in an atomic update, tracking both old and
  751. * new state. This is useful in places where the state delta needs to be
  752. * considered, for example in atomic check functions.
  753. */
  754. #define for_each_oldnew_connector_in_state(__state, connector, old_connector_state, new_connector_state, __i) \
  755. for ((__i) = 0; \
  756. (__i) < (__state)->num_connector; \
  757. (__i)++) \
  758. for_each_if ((__state)->connectors[__i].ptr && \
  759. ((connector) = (__state)->connectors[__i].ptr, \
  760. (void)(connector) /* Only to avoid unused-but-set-variable warning */, \
  761. (old_connector_state) = (__state)->connectors[__i].old_state, \
  762. (new_connector_state) = (__state)->connectors[__i].new_state, 1))
  763. /**
  764. * for_each_old_connector_in_state - iterate over all connectors in an atomic update
  765. * @__state: &struct drm_atomic_state pointer
  766. * @connector: &struct drm_connector iteration cursor
  767. * @old_connector_state: &struct drm_connector_state iteration cursor for the
  768. * old state
  769. * @__i: int iteration cursor, for macro-internal use
  770. *
  771. * This iterates over all connectors in an atomic update, tracking only the old
  772. * state. This is useful in disable functions, where we need the old state the
  773. * hardware is still in.
  774. */
  775. #define for_each_old_connector_in_state(__state, connector, old_connector_state, __i) \
  776. for ((__i) = 0; \
  777. (__i) < (__state)->num_connector; \
  778. (__i)++) \
  779. for_each_if ((__state)->connectors[__i].ptr && \
  780. ((connector) = (__state)->connectors[__i].ptr, \
  781. (void)(connector) /* Only to avoid unused-but-set-variable warning */, \
  782. (old_connector_state) = (__state)->connectors[__i].old_state, 1))
  783. /**
  784. * for_each_new_connector_in_state - iterate over all connectors in an atomic update
  785. * @__state: &struct drm_atomic_state pointer
  786. * @connector: &struct drm_connector iteration cursor
  787. * @new_connector_state: &struct drm_connector_state iteration cursor for the
  788. * new state
  789. * @__i: int iteration cursor, for macro-internal use
  790. *
  791. * This iterates over all connectors in an atomic update, tracking only the new
  792. * state. This is useful in enable functions, where we need the new state the
  793. * hardware should be in when the atomic commit operation has completed.
  794. */
  795. #define for_each_new_connector_in_state(__state, connector, new_connector_state, __i) \
  796. for ((__i) = 0; \
  797. (__i) < (__state)->num_connector; \
  798. (__i)++) \
  799. for_each_if ((__state)->connectors[__i].ptr && \
  800. ((connector) = (__state)->connectors[__i].ptr, \
  801. (void)(connector) /* Only to avoid unused-but-set-variable warning */, \
  802. (new_connector_state) = (__state)->connectors[__i].new_state, \
  803. (void)(new_connector_state) /* Only to avoid unused-but-set-variable warning */, 1))
  804. /**
  805. * for_each_oldnew_crtc_in_state - iterate over all CRTCs in an atomic update
  806. * @__state: &struct drm_atomic_state pointer
  807. * @crtc: &struct drm_crtc iteration cursor
  808. * @old_crtc_state: &struct drm_crtc_state iteration cursor for the old state
  809. * @new_crtc_state: &struct drm_crtc_state iteration cursor for the new state
  810. * @__i: int iteration cursor, for macro-internal use
  811. *
  812. * This iterates over all CRTCs in an atomic update, tracking both old and
  813. * new state. This is useful in places where the state delta needs to be
  814. * considered, for example in atomic check functions.
  815. */
  816. #define for_each_oldnew_crtc_in_state(__state, crtc, old_crtc_state, new_crtc_state, __i) \
  817. for ((__i) = 0; \
  818. (__i) < (__state)->dev->mode_config.num_crtc; \
  819. (__i)++) \
  820. for_each_if ((__state)->crtcs[__i].ptr && \
  821. ((crtc) = (__state)->crtcs[__i].ptr, \
  822. (void)(crtc) /* Only to avoid unused-but-set-variable warning */, \
  823. (old_crtc_state) = (__state)->crtcs[__i].old_state, \
  824. (void)(old_crtc_state) /* Only to avoid unused-but-set-variable warning */, \
  825. (new_crtc_state) = (__state)->crtcs[__i].new_state, \
  826. (void)(new_crtc_state) /* Only to avoid unused-but-set-variable warning */, 1))
  827. /**
  828. * for_each_old_crtc_in_state - iterate over all CRTCs in an atomic update
  829. * @__state: &struct drm_atomic_state pointer
  830. * @crtc: &struct drm_crtc iteration cursor
  831. * @old_crtc_state: &struct drm_crtc_state iteration cursor for the old state
  832. * @__i: int iteration cursor, for macro-internal use
  833. *
  834. * This iterates over all CRTCs in an atomic update, tracking only the old
  835. * state. This is useful in disable functions, where we need the old state the
  836. * hardware is still in.
  837. */
  838. #define for_each_old_crtc_in_state(__state, crtc, old_crtc_state, __i) \
  839. for ((__i) = 0; \
  840. (__i) < (__state)->dev->mode_config.num_crtc; \
  841. (__i)++) \
  842. for_each_if ((__state)->crtcs[__i].ptr && \
  843. ((crtc) = (__state)->crtcs[__i].ptr, \
  844. (void)(crtc) /* Only to avoid unused-but-set-variable warning */, \
  845. (old_crtc_state) = (__state)->crtcs[__i].old_state, 1))
  846. /**
  847. * for_each_new_crtc_in_state - iterate over all CRTCs in an atomic update
  848. * @__state: &struct drm_atomic_state pointer
  849. * @crtc: &struct drm_crtc iteration cursor
  850. * @new_crtc_state: &struct drm_crtc_state iteration cursor for the new state
  851. * @__i: int iteration cursor, for macro-internal use
  852. *
  853. * This iterates over all CRTCs in an atomic update, tracking only the new
  854. * state. This is useful in enable functions, where we need the new state the
  855. * hardware should be in when the atomic commit operation has completed.
  856. */
  857. #define for_each_new_crtc_in_state(__state, crtc, new_crtc_state, __i) \
  858. for ((__i) = 0; \
  859. (__i) < (__state)->dev->mode_config.num_crtc; \
  860. (__i)++) \
  861. for_each_if ((__state)->crtcs[__i].ptr && \
  862. ((crtc) = (__state)->crtcs[__i].ptr, \
  863. (void)(crtc) /* Only to avoid unused-but-set-variable warning */, \
  864. (new_crtc_state) = (__state)->crtcs[__i].new_state, \
  865. (void)(new_crtc_state) /* Only to avoid unused-but-set-variable warning */, 1))
  866. /**
  867. * for_each_oldnew_plane_in_state - iterate over all planes in an atomic update
  868. * @__state: &struct drm_atomic_state pointer
  869. * @plane: &struct drm_plane iteration cursor
  870. * @old_plane_state: &struct drm_plane_state iteration cursor for the old state
  871. * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
  872. * @__i: int iteration cursor, for macro-internal use
  873. *
  874. * This iterates over all planes in an atomic update, tracking both old and
  875. * new state. This is useful in places where the state delta needs to be
  876. * considered, for example in atomic check functions.
  877. */
  878. #define for_each_oldnew_plane_in_state(__state, plane, old_plane_state, new_plane_state, __i) \
  879. for ((__i) = 0; \
  880. (__i) < (__state)->dev->mode_config.num_total_plane; \
  881. (__i)++) \
  882. for_each_if ((__state)->planes[__i].ptr && \
  883. ((plane) = (__state)->planes[__i].ptr, \
  884. (void)(plane) /* Only to avoid unused-but-set-variable warning */, \
  885. (old_plane_state) = (__state)->planes[__i].old_state,\
  886. (new_plane_state) = (__state)->planes[__i].new_state, 1))
  887. /**
  888. * for_each_oldnew_plane_in_state_reverse - iterate over all planes in an atomic
  889. * update in reverse order
  890. * @__state: &struct drm_atomic_state pointer
  891. * @plane: &struct drm_plane iteration cursor
  892. * @old_plane_state: &struct drm_plane_state iteration cursor for the old state
  893. * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
  894. * @__i: int iteration cursor, for macro-internal use
  895. *
  896. * This iterates over all planes in an atomic update in reverse order,
  897. * tracking both old and new state. This is useful in places where the
  898. * state delta needs to be considered, for example in atomic check functions.
  899. */
  900. #define for_each_oldnew_plane_in_state_reverse(__state, plane, old_plane_state, new_plane_state, __i) \
  901. for ((__i) = ((__state)->dev->mode_config.num_total_plane - 1); \
  902. (__i) >= 0; \
  903. (__i)--) \
  904. for_each_if ((__state)->planes[__i].ptr && \
  905. ((plane) = (__state)->planes[__i].ptr, \
  906. (old_plane_state) = (__state)->planes[__i].old_state,\
  907. (new_plane_state) = (__state)->planes[__i].new_state, 1))
  908. /**
  909. * for_each_new_plane_in_state_reverse - other than only tracking new state,
  910. * it's the same as for_each_oldnew_plane_in_state_reverse
  911. * @__state: &struct drm_atomic_state pointer
  912. * @plane: &struct drm_plane iteration cursor
  913. * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
  914. * @__i: int iteration cursor, for macro-internal use
  915. */
  916. #define for_each_new_plane_in_state_reverse(__state, plane, new_plane_state, __i) \
  917. for ((__i) = ((__state)->dev->mode_config.num_total_plane - 1); \
  918. (__i) >= 0; \
  919. (__i)--) \
  920. for_each_if ((__state)->planes[__i].ptr && \
  921. ((plane) = (__state)->planes[__i].ptr, \
  922. (new_plane_state) = (__state)->planes[__i].new_state, 1))
  923. /**
  924. * for_each_old_plane_in_state - iterate over all planes in an atomic update
  925. * @__state: &struct drm_atomic_state pointer
  926. * @plane: &struct drm_plane iteration cursor
  927. * @old_plane_state: &struct drm_plane_state iteration cursor for the old state
  928. * @__i: int iteration cursor, for macro-internal use
  929. *
  930. * This iterates over all planes in an atomic update, tracking only the old
  931. * state. This is useful in disable functions, where we need the old state the
  932. * hardware is still in.
  933. */
  934. #define for_each_old_plane_in_state(__state, plane, old_plane_state, __i) \
  935. for ((__i) = 0; \
  936. (__i) < (__state)->dev->mode_config.num_total_plane; \
  937. (__i)++) \
  938. for_each_if ((__state)->planes[__i].ptr && \
  939. ((plane) = (__state)->planes[__i].ptr, \
  940. (old_plane_state) = (__state)->planes[__i].old_state, 1))
  941. /**
  942. * for_each_new_plane_in_state - iterate over all planes in an atomic update
  943. * @__state: &struct drm_atomic_state pointer
  944. * @plane: &struct drm_plane iteration cursor
  945. * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
  946. * @__i: int iteration cursor, for macro-internal use
  947. *
  948. * This iterates over all planes in an atomic update, tracking only the new
  949. * state. This is useful in enable functions, where we need the new state the
  950. * hardware should be in when the atomic commit operation has completed.
  951. */
  952. #define for_each_new_plane_in_state(__state, plane, new_plane_state, __i) \
  953. for ((__i) = 0; \
  954. (__i) < (__state)->dev->mode_config.num_total_plane; \
  955. (__i)++) \
  956. for_each_if ((__state)->planes[__i].ptr && \
  957. ((plane) = (__state)->planes[__i].ptr, \
  958. (void)(plane) /* Only to avoid unused-but-set-variable warning */, \
  959. (new_plane_state) = (__state)->planes[__i].new_state, \
  960. (void)(new_plane_state) /* Only to avoid unused-but-set-variable warning */, 1))
  961. /**
  962. * for_each_oldnew_private_obj_in_state - iterate over all private objects in an atomic update
  963. * @__state: &struct drm_atomic_state pointer
  964. * @obj: &struct drm_private_obj iteration cursor
  965. * @old_obj_state: &struct drm_private_state iteration cursor for the old state
  966. * @new_obj_state: &struct drm_private_state iteration cursor for the new state
  967. * @__i: int iteration cursor, for macro-internal use
  968. *
  969. * This iterates over all private objects in an atomic update, tracking both
  970. * old and new state. This is useful in places where the state delta needs
  971. * to be considered, for example in atomic check functions.
  972. */
  973. #define for_each_oldnew_private_obj_in_state(__state, obj, old_obj_state, new_obj_state, __i) \
  974. for ((__i) = 0; \
  975. (__i) < (__state)->num_private_objs && \
  976. ((obj) = (__state)->private_objs[__i].ptr, \
  977. (old_obj_state) = (__state)->private_objs[__i].old_state, \
  978. (new_obj_state) = (__state)->private_objs[__i].new_state, 1); \
  979. (__i)++)
  980. /**
  981. * for_each_old_private_obj_in_state - iterate over all private objects in an atomic update
  982. * @__state: &struct drm_atomic_state pointer
  983. * @obj: &struct drm_private_obj iteration cursor
  984. * @old_obj_state: &struct drm_private_state iteration cursor for the old state
  985. * @__i: int iteration cursor, for macro-internal use
  986. *
  987. * This iterates over all private objects in an atomic update, tracking only
  988. * the old state. This is useful in disable functions, where we need the old
  989. * state the hardware is still in.
  990. */
  991. #define for_each_old_private_obj_in_state(__state, obj, old_obj_state, __i) \
  992. for ((__i) = 0; \
  993. (__i) < (__state)->num_private_objs && \
  994. ((obj) = (__state)->private_objs[__i].ptr, \
  995. (old_obj_state) = (__state)->private_objs[__i].old_state, 1); \
  996. (__i)++)
  997. /**
  998. * for_each_new_private_obj_in_state - iterate over all private objects in an atomic update
  999. * @__state: &struct drm_atomic_state pointer
  1000. * @obj: &struct drm_private_obj iteration cursor
  1001. * @new_obj_state: &struct drm_private_state iteration cursor for the new state
  1002. * @__i: int iteration cursor, for macro-internal use
  1003. *
  1004. * This iterates over all private objects in an atomic update, tracking only
  1005. * the new state. This is useful in enable functions, where we need the new state the
  1006. * hardware should be in when the atomic commit operation has completed.
  1007. */
  1008. #define for_each_new_private_obj_in_state(__state, obj, new_obj_state, __i) \
  1009. for ((__i) = 0; \
  1010. (__i) < (__state)->num_private_objs && \
  1011. ((obj) = (__state)->private_objs[__i].ptr, \
  1012. (void)(obj) /* Only to avoid unused-but-set-variable warning */, \
  1013. (new_obj_state) = (__state)->private_objs[__i].new_state, 1); \
  1014. (__i)++)
  1015. /**
  1016. * drm_atomic_crtc_needs_modeset - compute combined modeset need
  1017. * @state: &drm_crtc_state for the CRTC
  1018. *
  1019. * To give drivers flexibility &struct drm_crtc_state has 3 booleans to track
  1020. * whether the state CRTC changed enough to need a full modeset cycle:
  1021. * mode_changed, active_changed and connectors_changed. This helper simply
  1022. * combines these three to compute the overall need for a modeset for @state.
  1023. *
  1024. * The atomic helper code sets these booleans, but drivers can and should
  1025. * change them appropriately to accurately represent whether a modeset is
  1026. * really needed. In general, drivers should avoid full modesets whenever
  1027. * possible.
  1028. *
  1029. * For example if the CRTC mode has changed, and the hardware is able to enact
  1030. * the requested mode change without going through a full modeset, the driver
  1031. * should clear mode_changed in its &drm_mode_config_funcs.atomic_check
  1032. * implementation.
  1033. */
  1034. static inline bool
  1035. drm_atomic_crtc_needs_modeset(const struct drm_crtc_state *state)
  1036. {
  1037. return state->mode_changed || state->active_changed ||
  1038. state->connectors_changed;
  1039. }
  1040. /**
  1041. * drm_atomic_crtc_effectively_active - compute whether CRTC is actually active
  1042. * @state: &drm_crtc_state for the CRTC
  1043. *
  1044. * When in self refresh mode, the crtc_state->active value will be false, since
  1045. * the CRTC is off. However in some cases we're interested in whether the CRTC
  1046. * is active, or effectively active (ie: it's connected to an active display).
  1047. * In these cases, use this function instead of just checking active.
  1048. */
  1049. static inline bool
  1050. drm_atomic_crtc_effectively_active(const struct drm_crtc_state *state)
  1051. {
  1052. return state->active || state->self_refresh_active;
  1053. }
  1054. /**
  1055. * struct drm_bus_cfg - bus configuration
  1056. *
  1057. * This structure stores the configuration of a physical bus between two
  1058. * components in an output pipeline, usually between two bridges, an encoder
  1059. * and a bridge, or a bridge and a connector.
  1060. *
  1061. * The bus configuration is stored in &drm_bridge_state separately for the
  1062. * input and output buses, as seen from the point of view of each bridge. The
  1063. * bus configuration of a bridge output is usually identical to the
  1064. * configuration of the next bridge's input, but may differ if the signals are
  1065. * modified between the two bridges, for instance by an inverter on the board.
  1066. * The input and output configurations of a bridge may differ if the bridge
  1067. * modifies the signals internally, for instance by performing format
  1068. * conversion, or modifying signals polarities.
  1069. */
  1070. struct drm_bus_cfg {
  1071. /**
  1072. * @format: format used on this bus (one of the MEDIA_BUS_FMT_* format)
  1073. *
  1074. * This field should not be directly modified by drivers
  1075. * (drm_atomic_bridge_chain_select_bus_fmts() takes care of the bus
  1076. * format negotiation).
  1077. */
  1078. u32 format;
  1079. /**
  1080. * @flags: DRM_BUS_* flags used on this bus
  1081. */
  1082. u32 flags;
  1083. };
  1084. /**
  1085. * struct drm_bridge_state - Atomic bridge state object
  1086. */
  1087. struct drm_bridge_state {
  1088. /**
  1089. * @base: inherit from &drm_private_state
  1090. */
  1091. struct drm_private_state base;
  1092. /**
  1093. * @bridge: the bridge this state refers to
  1094. */
  1095. struct drm_bridge *bridge;
  1096. /**
  1097. * @input_bus_cfg: input bus configuration
  1098. */
  1099. struct drm_bus_cfg input_bus_cfg;
  1100. /**
  1101. * @output_bus_cfg: output bus configuration
  1102. */
  1103. struct drm_bus_cfg output_bus_cfg;
  1104. };
  1105. static inline struct drm_bridge_state *
  1106. drm_priv_to_bridge_state(struct drm_private_state *priv)
  1107. {
  1108. return container_of(priv, struct drm_bridge_state, base);
  1109. }
  1110. struct drm_bridge_state *
  1111. drm_atomic_get_bridge_state(struct drm_atomic_state *state,
  1112. struct drm_bridge *bridge);
  1113. struct drm_bridge_state *
  1114. drm_atomic_get_old_bridge_state(const struct drm_atomic_state *state,
  1115. struct drm_bridge *bridge);
  1116. struct drm_bridge_state *
  1117. drm_atomic_get_new_bridge_state(const struct drm_atomic_state *state,
  1118. struct drm_bridge *bridge);
  1119. #endif /* DRM_ATOMIC_H_ */