drm_crtc.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  1. /*
  2. * Copyright © 2006 Keith Packard
  3. * Copyright © 2007-2008 Dave Airlie
  4. * Copyright © 2007-2008 Intel Corporation
  5. * Jesse Barnes <jesse.barnes@intel.com>
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  21. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  22. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  23. * OTHER DEALINGS IN THE SOFTWARE.
  24. */
  25. #ifndef __DRM_CRTC_H__
  26. #define __DRM_CRTC_H__
  27. #include <linux/i2c.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/types.h>
  30. #include <linux/fb.h>
  31. #include <linux/hdmi.h>
  32. #include <linux/media-bus-format.h>
  33. #include <uapi/drm/drm_mode.h>
  34. #include <uapi/drm/drm_fourcc.h>
  35. #include <drm/drm_modeset_lock.h>
  36. #include <drm/drm_rect.h>
  37. #include <drm/drm_mode_object.h>
  38. #include <drm/drm_framebuffer.h>
  39. #include <drm/drm_modes.h>
  40. #include <drm/drm_connector.h>
  41. #include <drm/drm_property.h>
  42. #include <drm/drm_bridge.h>
  43. #include <drm/drm_edid.h>
  44. #include <drm/drm_plane.h>
  45. #include <drm/drm_blend.h>
  46. #include <drm/drm_color_mgmt.h>
  47. #include <drm/drm_debugfs_crc.h>
  48. #include <drm/drm_mode_config.h>
  49. struct drm_device;
  50. struct drm_mode_set;
  51. struct drm_file;
  52. struct drm_clip_rect;
  53. struct drm_printer;
  54. struct device_node;
  55. struct dma_fence;
  56. struct edid;
  57. static inline int64_t U642I64(uint64_t val)
  58. {
  59. return (int64_t)*((int64_t *)&val);
  60. }
  61. static inline uint64_t I642U64(int64_t val)
  62. {
  63. return (uint64_t)*((uint64_t *)&val);
  64. }
  65. struct drm_crtc;
  66. struct drm_pending_vblank_event;
  67. struct drm_plane;
  68. struct drm_bridge;
  69. struct drm_atomic_state;
  70. struct drm_crtc_helper_funcs;
  71. struct drm_plane_helper_funcs;
  72. /**
  73. * struct drm_crtc_state - mutable CRTC state
  74. * @crtc: backpointer to the CRTC
  75. * @enable: whether the CRTC should be enabled, gates all other state
  76. * @active: whether the CRTC is actively displaying (used for DPMS)
  77. * @planes_changed: planes on this crtc are updated
  78. * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
  79. * @active_changed: crtc_state->active has been toggled.
  80. * @connectors_changed: connectors to this crtc have been updated
  81. * @zpos_changed: zpos values of planes on this crtc have been updated
  82. * @color_mgmt_changed: color management properties have changed (degamma or
  83. * gamma LUT or CSC matrix)
  84. * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
  85. * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
  86. * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
  87. * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
  88. * @mode: current mode timings
  89. * @mode_blob: &drm_property_blob for @mode
  90. * @degamma_lut: Lookup table for converting framebuffer pixel data
  91. * before apply the conversion matrix
  92. * @ctm: Transformation matrix
  93. * @gamma_lut: Lookup table for converting pixel data after the
  94. * conversion matrix
  95. * @state: backpointer to global drm_atomic_state
  96. *
  97. * Note that the distinction between @enable and @active is rather subtile:
  98. * Flipping @active while @enable is set without changing anything else may
  99. * never return in a failure from the ->atomic_check callback. Userspace assumes
  100. * that a DPMS On will always succeed. In other words: @enable controls resource
  101. * assignment, @active controls the actual hardware state.
  102. *
  103. * The three booleans active_changed, connectors_changed and mode_changed are
  104. * intended to indicate whether a full modeset is needed, rather than strictly
  105. * describing what has changed in a commit.
  106. * See also: drm_atomic_crtc_needs_modeset()
  107. */
  108. struct drm_crtc_state {
  109. struct drm_crtc *crtc;
  110. bool enable;
  111. bool active;
  112. /* computed state bits used by helpers and drivers */
  113. bool planes_changed : 1;
  114. bool mode_changed : 1;
  115. bool active_changed : 1;
  116. bool connectors_changed : 1;
  117. bool zpos_changed : 1;
  118. bool color_mgmt_changed : 1;
  119. /* attached planes bitmask:
  120. * WARNING: transitional helpers do not maintain plane_mask so
  121. * drivers not converted over to atomic helpers should not rely
  122. * on plane_mask being accurate!
  123. */
  124. u32 plane_mask;
  125. u32 connector_mask;
  126. u32 encoder_mask;
  127. /* adjusted_mode: for use by helpers and drivers */
  128. struct drm_display_mode adjusted_mode;
  129. struct drm_display_mode mode;
  130. /* blob property to expose current mode to atomic userspace */
  131. struct drm_property_blob *mode_blob;
  132. /* blob property to expose color management to userspace */
  133. struct drm_property_blob *degamma_lut;
  134. struct drm_property_blob *ctm;
  135. struct drm_property_blob *gamma_lut;
  136. /**
  137. * @event:
  138. *
  139. * Optional pointer to a DRM event to signal upon completion of the
  140. * state update. The driver must send out the event when the atomic
  141. * commit operation completes. There are two cases:
  142. *
  143. * - The event is for a CRTC which is being disabled through this
  144. * atomic commit. In that case the event can be send out any time
  145. * after the hardware has stopped scanning out the current
  146. * framebuffers. It should contain the timestamp and counter for the
  147. * last vblank before the display pipeline was shut off.
  148. *
  149. * - For a CRTC which is enabled at the end of the commit (even when it
  150. * undergoes an full modeset) the vblank timestamp and counter must
  151. * be for the vblank right before the first frame that scans out the
  152. * new set of buffers. Again the event can only be sent out after the
  153. * hardware has stopped scanning out the old buffers.
  154. *
  155. * - Events for disabled CRTCs are not allowed, and drivers can ignore
  156. * that case.
  157. *
  158. * This can be handled by the drm_crtc_send_vblank_event() function,
  159. * which the driver should call on the provided event upon completion of
  160. * the atomic commit. Note that if the driver supports vblank signalling
  161. * and timestamping the vblank counters and timestamps must agree with
  162. * the ones returned from page flip events. With the current vblank
  163. * helper infrastructure this can be achieved by holding a vblank
  164. * reference while the page flip is pending, acquired through
  165. * drm_crtc_vblank_get() and released with drm_crtc_vblank_put().
  166. * Drivers are free to implement their own vblank counter and timestamp
  167. * tracking though, e.g. if they have accurate timestamp registers in
  168. * hardware.
  169. *
  170. * For hardware which supports some means to synchronize vblank
  171. * interrupt delivery with committing display state there's also
  172. * drm_crtc_arm_vblank_event(). See the documentation of that function
  173. * for a detailed discussion of the constraints it needs to be used
  174. * safely.
  175. */
  176. struct drm_pending_vblank_event *event;
  177. struct drm_atomic_state *state;
  178. };
  179. /**
  180. * struct drm_crtc_funcs - control CRTCs for a given device
  181. *
  182. * The drm_crtc_funcs structure is the central CRTC management structure
  183. * in the DRM. Each CRTC controls one or more connectors (note that the name
  184. * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
  185. * connectors, not just CRTs).
  186. *
  187. * Each driver is responsible for filling out this structure at startup time,
  188. * in addition to providing other modesetting features, like i2c and DDC
  189. * bus accessors.
  190. */
  191. struct drm_crtc_funcs {
  192. /**
  193. * @reset:
  194. *
  195. * Reset CRTC hardware and software state to off. This function isn't
  196. * called by the core directly, only through drm_mode_config_reset().
  197. * It's not a helper hook only for historical reasons.
  198. *
  199. * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
  200. * atomic state using this hook.
  201. */
  202. void (*reset)(struct drm_crtc *crtc);
  203. /**
  204. * @cursor_set:
  205. *
  206. * Update the cursor image. The cursor position is relative to the CRTC
  207. * and can be partially or fully outside of the visible area.
  208. *
  209. * Note that contrary to all other KMS functions the legacy cursor entry
  210. * points don't take a framebuffer object, but instead take directly a
  211. * raw buffer object id from the driver's buffer manager (which is
  212. * either GEM or TTM for current drivers).
  213. *
  214. * This entry point is deprecated, drivers should instead implement
  215. * universal plane support and register a proper cursor plane using
  216. * drm_crtc_init_with_planes().
  217. *
  218. * This callback is optional
  219. *
  220. * RETURNS:
  221. *
  222. * 0 on success or a negative error code on failure.
  223. */
  224. int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
  225. uint32_t handle, uint32_t width, uint32_t height);
  226. /**
  227. * @cursor_set2:
  228. *
  229. * Update the cursor image, including hotspot information. The hotspot
  230. * must not affect the cursor position in CRTC coordinates, but is only
  231. * meant as a hint for virtualized display hardware to coordinate the
  232. * guests and hosts cursor position. The cursor hotspot is relative to
  233. * the cursor image. Otherwise this works exactly like @cursor_set.
  234. *
  235. * This entry point is deprecated, drivers should instead implement
  236. * universal plane support and register a proper cursor plane using
  237. * drm_crtc_init_with_planes().
  238. *
  239. * This callback is optional.
  240. *
  241. * RETURNS:
  242. *
  243. * 0 on success or a negative error code on failure.
  244. */
  245. int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
  246. uint32_t handle, uint32_t width, uint32_t height,
  247. int32_t hot_x, int32_t hot_y);
  248. /**
  249. * @cursor_move:
  250. *
  251. * Update the cursor position. The cursor does not need to be visible
  252. * when this hook is called.
  253. *
  254. * This entry point is deprecated, drivers should instead implement
  255. * universal plane support and register a proper cursor plane using
  256. * drm_crtc_init_with_planes().
  257. *
  258. * This callback is optional.
  259. *
  260. * RETURNS:
  261. *
  262. * 0 on success or a negative error code on failure.
  263. */
  264. int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
  265. /**
  266. * @gamma_set:
  267. *
  268. * Set gamma on the CRTC.
  269. *
  270. * This callback is optional.
  271. *
  272. * NOTE:
  273. *
  274. * Drivers that support gamma tables and also fbdev emulation through
  275. * the provided helper library need to take care to fill out the gamma
  276. * hooks for both. Currently there's a bit an unfortunate duplication
  277. * going on, which should eventually be unified to just one set of
  278. * hooks.
  279. */
  280. int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
  281. uint32_t size);
  282. /**
  283. * @destroy:
  284. *
  285. * Clean up plane resources. This is only called at driver unload time
  286. * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
  287. * in DRM.
  288. */
  289. void (*destroy)(struct drm_crtc *crtc);
  290. /**
  291. * @set_config:
  292. *
  293. * This is the main legacy entry point to change the modeset state on a
  294. * CRTC. All the details of the desired configuration are passed in a
  295. * &struct drm_mode_set - see there for details.
  296. *
  297. * Drivers implementing atomic modeset should use
  298. * drm_atomic_helper_set_config() to implement this hook.
  299. *
  300. * RETURNS:
  301. *
  302. * 0 on success or a negative error code on failure.
  303. */
  304. int (*set_config)(struct drm_mode_set *set);
  305. /**
  306. * @page_flip:
  307. *
  308. * Legacy entry point to schedule a flip to the given framebuffer.
  309. *
  310. * Page flipping is a synchronization mechanism that replaces the frame
  311. * buffer being scanned out by the CRTC with a new frame buffer during
  312. * vertical blanking, avoiding tearing (except when requested otherwise
  313. * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
  314. * requests a page flip the DRM core verifies that the new frame buffer
  315. * is large enough to be scanned out by the CRTC in the currently
  316. * configured mode and then calls the CRTC ->page_flip() operation with a
  317. * pointer to the new frame buffer.
  318. *
  319. * The driver must wait for any pending rendering to the new framebuffer
  320. * to complete before executing the flip. It should also wait for any
  321. * pending rendering from other drivers if the underlying buffer is a
  322. * shared dma-buf.
  323. *
  324. * An application can request to be notified when the page flip has
  325. * completed. The drm core will supply a &struct drm_event in the event
  326. * parameter in this case. This can be handled by the
  327. * drm_crtc_send_vblank_event() function, which the driver should call on
  328. * the provided event upon completion of the flip. Note that if
  329. * the driver supports vblank signalling and timestamping the vblank
  330. * counters and timestamps must agree with the ones returned from page
  331. * flip events. With the current vblank helper infrastructure this can
  332. * be achieved by holding a vblank reference while the page flip is
  333. * pending, acquired through drm_crtc_vblank_get() and released with
  334. * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
  335. * counter and timestamp tracking though, e.g. if they have accurate
  336. * timestamp registers in hardware.
  337. *
  338. * This callback is optional.
  339. *
  340. * NOTE:
  341. *
  342. * Very early versions of the KMS ABI mandated that the driver must
  343. * block (but not reject) any rendering to the old framebuffer until the
  344. * flip operation has completed and the old framebuffer is no longer
  345. * visible. This requirement has been lifted, and userspace is instead
  346. * expected to request delivery of an event and wait with recycling old
  347. * buffers until such has been received.
  348. *
  349. * RETURNS:
  350. *
  351. * 0 on success or a negative error code on failure. Note that if a
  352. * ->page_flip() operation is already pending the callback should return
  353. * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
  354. * or just runtime disabled through DPMS respectively the new atomic
  355. * "ACTIVE" state) should result in an -EINVAL error code. Note that
  356. * drm_atomic_helper_page_flip() checks this already for atomic drivers.
  357. */
  358. int (*page_flip)(struct drm_crtc *crtc,
  359. struct drm_framebuffer *fb,
  360. struct drm_pending_vblank_event *event,
  361. uint32_t flags);
  362. /**
  363. * @page_flip_target:
  364. *
  365. * Same as @page_flip but with an additional parameter specifying the
  366. * absolute target vertical blank period (as reported by
  367. * drm_crtc_vblank_count()) when the flip should take effect.
  368. *
  369. * Note that the core code calls drm_crtc_vblank_get before this entry
  370. * point, and will call drm_crtc_vblank_put if this entry point returns
  371. * any non-0 error code. It's the driver's responsibility to call
  372. * drm_crtc_vblank_put after this entry point returns 0, typically when
  373. * the flip completes.
  374. */
  375. int (*page_flip_target)(struct drm_crtc *crtc,
  376. struct drm_framebuffer *fb,
  377. struct drm_pending_vblank_event *event,
  378. uint32_t flags, uint32_t target);
  379. /**
  380. * @set_property:
  381. *
  382. * This is the legacy entry point to update a property attached to the
  383. * CRTC.
  384. *
  385. * Drivers implementing atomic modeset should use
  386. * drm_atomic_helper_crtc_set_property() to implement this hook.
  387. *
  388. * This callback is optional if the driver does not support any legacy
  389. * driver-private properties.
  390. *
  391. * RETURNS:
  392. *
  393. * 0 on success or a negative error code on failure.
  394. */
  395. int (*set_property)(struct drm_crtc *crtc,
  396. struct drm_property *property, uint64_t val);
  397. /**
  398. * @atomic_duplicate_state:
  399. *
  400. * Duplicate the current atomic state for this CRTC and return it.
  401. * The core and helpers gurantee that any atomic state duplicated with
  402. * this hook and still owned by the caller (i.e. not transferred to the
  403. * driver by calling ->atomic_commit() from struct
  404. * &drm_mode_config_funcs) will be cleaned up by calling the
  405. * @atomic_destroy_state hook in this structure.
  406. *
  407. * Atomic drivers which don't subclass &struct drm_crtc should use
  408. * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
  409. * state structure to extend it with driver-private state should use
  410. * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
  411. * duplicated in a consistent fashion across drivers.
  412. *
  413. * It is an error to call this hook before crtc->state has been
  414. * initialized correctly.
  415. *
  416. * NOTE:
  417. *
  418. * If the duplicate state references refcounted resources this hook must
  419. * acquire a reference for each of them. The driver must release these
  420. * references again in @atomic_destroy_state.
  421. *
  422. * RETURNS:
  423. *
  424. * Duplicated atomic state or NULL when the allocation failed.
  425. */
  426. struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
  427. /**
  428. * @atomic_destroy_state:
  429. *
  430. * Destroy a state duplicated with @atomic_duplicate_state and release
  431. * or unreference all resources it references
  432. */
  433. void (*atomic_destroy_state)(struct drm_crtc *crtc,
  434. struct drm_crtc_state *state);
  435. /**
  436. * @atomic_set_property:
  437. *
  438. * Decode a driver-private property value and store the decoded value
  439. * into the passed-in state structure. Since the atomic core decodes all
  440. * standardized properties (even for extensions beyond the core set of
  441. * properties which might not be implemented by all drivers) this
  442. * requires drivers to subclass the state structure.
  443. *
  444. * Such driver-private properties should really only be implemented for
  445. * truly hardware/vendor specific state. Instead it is preferred to
  446. * standardize atomic extension and decode the properties used to expose
  447. * such an extension in the core.
  448. *
  449. * Do not call this function directly, use
  450. * drm_atomic_crtc_set_property() instead.
  451. *
  452. * This callback is optional if the driver does not support any
  453. * driver-private atomic properties.
  454. *
  455. * NOTE:
  456. *
  457. * This function is called in the state assembly phase of atomic
  458. * modesets, which can be aborted for any reason (including on
  459. * userspace's request to just check whether a configuration would be
  460. * possible). Drivers MUST NOT touch any persistent state (hardware or
  461. * software) or data structures except the passed in @state parameter.
  462. *
  463. * Also since userspace controls in which order properties are set this
  464. * function must not do any input validation (since the state update is
  465. * incomplete and hence likely inconsistent). Instead any such input
  466. * validation must be done in the various atomic_check callbacks.
  467. *
  468. * RETURNS:
  469. *
  470. * 0 if the property has been found, -EINVAL if the property isn't
  471. * implemented by the driver (which should never happen, the core only
  472. * asks for properties attached to this CRTC). No other validation is
  473. * allowed by the driver. The core already checks that the property
  474. * value is within the range (integer, valid enum value, ...) the driver
  475. * set when registering the property.
  476. */
  477. int (*atomic_set_property)(struct drm_crtc *crtc,
  478. struct drm_crtc_state *state,
  479. struct drm_property *property,
  480. uint64_t val);
  481. /**
  482. * @atomic_get_property:
  483. *
  484. * Reads out the decoded driver-private property. This is used to
  485. * implement the GETCRTC IOCTL.
  486. *
  487. * Do not call this function directly, use
  488. * drm_atomic_crtc_get_property() instead.
  489. *
  490. * This callback is optional if the driver does not support any
  491. * driver-private atomic properties.
  492. *
  493. * RETURNS:
  494. *
  495. * 0 on success, -EINVAL if the property isn't implemented by the
  496. * driver (which should never happen, the core only asks for
  497. * properties attached to this CRTC).
  498. */
  499. int (*atomic_get_property)(struct drm_crtc *crtc,
  500. const struct drm_crtc_state *state,
  501. struct drm_property *property,
  502. uint64_t *val);
  503. /**
  504. * @late_register:
  505. *
  506. * This optional hook can be used to register additional userspace
  507. * interfaces attached to the crtc like debugfs interfaces.
  508. * It is called late in the driver load sequence from drm_dev_register().
  509. * Everything added from this callback should be unregistered in
  510. * the early_unregister callback.
  511. *
  512. * Returns:
  513. *
  514. * 0 on success, or a negative error code on failure.
  515. */
  516. int (*late_register)(struct drm_crtc *crtc);
  517. /**
  518. * @early_unregister:
  519. *
  520. * This optional hook should be used to unregister the additional
  521. * userspace interfaces attached to the crtc from
  522. * late_unregister(). It is called from drm_dev_unregister(),
  523. * early in the driver unload sequence to disable userspace access
  524. * before data structures are torndown.
  525. */
  526. void (*early_unregister)(struct drm_crtc *crtc);
  527. /**
  528. * @set_crc_source:
  529. *
  530. * Changes the source of CRC checksums of frames at the request of
  531. * userspace, typically for testing purposes. The sources available are
  532. * specific of each driver and a %NULL value indicates that CRC
  533. * generation is to be switched off.
  534. *
  535. * When CRC generation is enabled, the driver should call
  536. * drm_crtc_add_crc_entry() at each frame, providing any information
  537. * that characterizes the frame contents in the crcN arguments, as
  538. * provided from the configured source. Drivers must accept a "auto"
  539. * source name that will select a default source for this CRTC.
  540. *
  541. * This callback is optional if the driver does not support any CRC
  542. * generation functionality.
  543. *
  544. * RETURNS:
  545. *
  546. * 0 on success or a negative error code on failure.
  547. */
  548. int (*set_crc_source)(struct drm_crtc *crtc, const char *source,
  549. size_t *values_cnt);
  550. /**
  551. * @atomic_print_state:
  552. *
  553. * If driver subclasses &struct drm_crtc_state, it should implement
  554. * this optional hook for printing additional driver specific state.
  555. *
  556. * Do not call this directly, use drm_atomic_crtc_print_state()
  557. * instead.
  558. */
  559. void (*atomic_print_state)(struct drm_printer *p,
  560. const struct drm_crtc_state *state);
  561. };
  562. /**
  563. * struct drm_crtc - central CRTC control structure
  564. * @dev: parent DRM device
  565. * @port: OF node used by drm_of_find_possible_crtcs()
  566. * @head: list management
  567. * @name: human readable name, can be overwritten by the driver
  568. * @mutex: per-CRTC locking
  569. * @base: base KMS object for ID tracking etc.
  570. * @primary: primary plane for this CRTC
  571. * @cursor: cursor plane for this CRTC
  572. * @cursor_x: current x position of the cursor, used for universal cursor planes
  573. * @cursor_y: current y position of the cursor, used for universal cursor planes
  574. * @enabled: is this CRTC enabled?
  575. * @mode: current mode timings
  576. * @hwmode: mode timings as programmed to hw regs
  577. * @x: x position on screen
  578. * @y: y position on screen
  579. * @funcs: CRTC control functions
  580. * @gamma_size: size of gamma ramp
  581. * @gamma_store: gamma ramp values
  582. * @helper_private: mid-layer private data
  583. * @properties: property tracking for this CRTC
  584. *
  585. * Each CRTC may have one or more connectors associated with it. This structure
  586. * allows the CRTC to be controlled.
  587. */
  588. struct drm_crtc {
  589. struct drm_device *dev;
  590. struct device_node *port;
  591. struct list_head head;
  592. char *name;
  593. /**
  594. * @mutex:
  595. *
  596. * This provides a read lock for the overall crtc state (mode, dpms
  597. * state, ...) and a write lock for everything which can be update
  598. * without a full modeset (fb, cursor data, crtc properties ...). Full
  599. * modeset also need to grab dev->mode_config.connection_mutex.
  600. */
  601. struct drm_modeset_lock mutex;
  602. struct drm_mode_object base;
  603. /* primary and cursor planes for CRTC */
  604. struct drm_plane *primary;
  605. struct drm_plane *cursor;
  606. /**
  607. * @index: Position inside the mode_config.list, can be used as an array
  608. * index. It is invariant over the lifetime of the CRTC.
  609. */
  610. unsigned index;
  611. /* position of cursor plane on crtc */
  612. int cursor_x;
  613. int cursor_y;
  614. bool enabled;
  615. /* Requested mode from modesetting. */
  616. struct drm_display_mode mode;
  617. /* Programmed mode in hw, after adjustments for encoders,
  618. * crtc, panel scaling etc. Needed for timestamping etc.
  619. */
  620. struct drm_display_mode hwmode;
  621. int x, y;
  622. const struct drm_crtc_funcs *funcs;
  623. /* Legacy FB CRTC gamma size for reporting to userspace */
  624. uint32_t gamma_size;
  625. uint16_t *gamma_store;
  626. /* if you are using the helper */
  627. const struct drm_crtc_helper_funcs *helper_private;
  628. struct drm_object_properties properties;
  629. /**
  630. * @state:
  631. *
  632. * Current atomic state for this CRTC.
  633. */
  634. struct drm_crtc_state *state;
  635. /**
  636. * @commit_list:
  637. *
  638. * List of &drm_crtc_commit structures tracking pending commits.
  639. * Protected by @commit_lock. This list doesn't hold its own full
  640. * reference, but burrows it from the ongoing commit. Commit entries
  641. * must be removed from this list once the commit is fully completed,
  642. * but before it's correspoding &drm_atomic_state gets destroyed.
  643. */
  644. struct list_head commit_list;
  645. /**
  646. * @commit_lock:
  647. *
  648. * Spinlock to protect @commit_list.
  649. */
  650. spinlock_t commit_lock;
  651. /**
  652. * @acquire_ctx:
  653. *
  654. * Per-CRTC implicit acquire context used by atomic drivers for legacy
  655. * IOCTLs, so that atomic drivers can get at the locking acquire
  656. * context.
  657. */
  658. struct drm_modeset_acquire_ctx *acquire_ctx;
  659. #ifdef CONFIG_DEBUG_FS
  660. /**
  661. * @debugfs_entry:
  662. *
  663. * Debugfs directory for this CRTC.
  664. */
  665. struct dentry *debugfs_entry;
  666. /**
  667. * @crc:
  668. *
  669. * Configuration settings of CRC capture.
  670. */
  671. struct drm_crtc_crc crc;
  672. #endif
  673. /**
  674. * @fence_context:
  675. *
  676. * timeline context used for fence operations.
  677. */
  678. unsigned int fence_context;
  679. /**
  680. * @fence_lock:
  681. *
  682. * spinlock to protect the fences in the fence_context.
  683. */
  684. spinlock_t fence_lock;
  685. /**
  686. * @fence_seqno:
  687. *
  688. * Seqno variable used as monotonic counter for the fences
  689. * created on the CRTC's timeline.
  690. */
  691. unsigned long fence_seqno;
  692. /**
  693. * @timeline_name:
  694. *
  695. * The name of the CRTC's fence timeline.
  696. */
  697. char timeline_name[32];
  698. };
  699. /**
  700. * struct drm_mode_set - new values for a CRTC config change
  701. * @fb: framebuffer to use for new config
  702. * @crtc: CRTC whose configuration we're about to change
  703. * @mode: mode timings to use
  704. * @x: position of this CRTC relative to @fb
  705. * @y: position of this CRTC relative to @fb
  706. * @connectors: array of connectors to drive with this CRTC if possible
  707. * @num_connectors: size of @connectors array
  708. *
  709. * Represents a single crtc the connectors that it drives with what mode
  710. * and from which framebuffer it scans out from.
  711. *
  712. * This is used to set modes.
  713. */
  714. struct drm_mode_set {
  715. struct drm_framebuffer *fb;
  716. struct drm_crtc *crtc;
  717. struct drm_display_mode *mode;
  718. uint32_t x;
  719. uint32_t y;
  720. struct drm_connector **connectors;
  721. size_t num_connectors;
  722. };
  723. #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
  724. __printf(6, 7)
  725. int drm_crtc_init_with_planes(struct drm_device *dev,
  726. struct drm_crtc *crtc,
  727. struct drm_plane *primary,
  728. struct drm_plane *cursor,
  729. const struct drm_crtc_funcs *funcs,
  730. const char *name, ...);
  731. void drm_crtc_cleanup(struct drm_crtc *crtc);
  732. /**
  733. * drm_crtc_index - find the index of a registered CRTC
  734. * @crtc: CRTC to find index for
  735. *
  736. * Given a registered CRTC, return the index of that CRTC within a DRM
  737. * device's list of CRTCs.
  738. */
  739. static inline unsigned int drm_crtc_index(const struct drm_crtc *crtc)
  740. {
  741. return crtc->index;
  742. }
  743. /**
  744. * drm_crtc_mask - find the mask of a registered CRTC
  745. * @crtc: CRTC to find mask for
  746. *
  747. * Given a registered CRTC, return the mask bit of that CRTC for an
  748. * encoder's possible_crtcs field.
  749. */
  750. static inline uint32_t drm_crtc_mask(const struct drm_crtc *crtc)
  751. {
  752. return 1 << drm_crtc_index(crtc);
  753. }
  754. void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
  755. int *hdisplay, int *vdisplay);
  756. int drm_crtc_force_disable(struct drm_crtc *crtc);
  757. int drm_crtc_force_disable_all(struct drm_device *dev);
  758. int drm_mode_set_config_internal(struct drm_mode_set *set);
  759. struct drm_crtc *drm_crtc_from_index(struct drm_device *dev, int idx);
  760. /* Helpers */
  761. static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
  762. uint32_t id)
  763. {
  764. struct drm_mode_object *mo;
  765. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
  766. return mo ? obj_to_crtc(mo) : NULL;
  767. }
  768. #define drm_for_each_crtc(crtc, dev) \
  769. list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
  770. static inline void
  771. assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
  772. {
  773. /*
  774. * The connector hotadd/remove code currently grabs both locks when
  775. * updating lists. Hence readers need only hold either of them to be
  776. * safe and the check amounts to
  777. *
  778. * WARN_ON(not_holding(A) && not_holding(B)).
  779. */
  780. WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
  781. !drm_modeset_is_locked(&mode_config->connection_mutex));
  782. }
  783. #endif /* __DRM_CRTC_H__ */