drm_crtc.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  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. * @target_vblank:
  138. *
  139. * Target vertical blank period when a page flip
  140. * should take effect.
  141. */
  142. u32 target_vblank;
  143. /**
  144. * @event:
  145. *
  146. * Optional pointer to a DRM event to signal upon completion of the
  147. * state update. The driver must send out the event when the atomic
  148. * commit operation completes. There are two cases:
  149. *
  150. * - The event is for a CRTC which is being disabled through this
  151. * atomic commit. In that case the event can be send out any time
  152. * after the hardware has stopped scanning out the current
  153. * framebuffers. It should contain the timestamp and counter for the
  154. * last vblank before the display pipeline was shut off.
  155. *
  156. * - For a CRTC which is enabled at the end of the commit (even when it
  157. * undergoes an full modeset) the vblank timestamp and counter must
  158. * be for the vblank right before the first frame that scans out the
  159. * new set of buffers. Again the event can only be sent out after the
  160. * hardware has stopped scanning out the old buffers.
  161. *
  162. * - Events for disabled CRTCs are not allowed, and drivers can ignore
  163. * that case.
  164. *
  165. * This can be handled by the drm_crtc_send_vblank_event() function,
  166. * which the driver should call on the provided event upon completion of
  167. * the atomic commit. Note that if the driver supports vblank signalling
  168. * and timestamping the vblank counters and timestamps must agree with
  169. * the ones returned from page flip events. With the current vblank
  170. * helper infrastructure this can be achieved by holding a vblank
  171. * reference while the page flip is pending, acquired through
  172. * drm_crtc_vblank_get() and released with drm_crtc_vblank_put().
  173. * Drivers are free to implement their own vblank counter and timestamp
  174. * tracking though, e.g. if they have accurate timestamp registers in
  175. * hardware.
  176. *
  177. * For hardware which supports some means to synchronize vblank
  178. * interrupt delivery with committing display state there's also
  179. * drm_crtc_arm_vblank_event(). See the documentation of that function
  180. * for a detailed discussion of the constraints it needs to be used
  181. * safely.
  182. */
  183. struct drm_pending_vblank_event *event;
  184. struct drm_atomic_state *state;
  185. };
  186. /**
  187. * struct drm_crtc_funcs - control CRTCs for a given device
  188. *
  189. * The drm_crtc_funcs structure is the central CRTC management structure
  190. * in the DRM. Each CRTC controls one or more connectors (note that the name
  191. * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
  192. * connectors, not just CRTs).
  193. *
  194. * Each driver is responsible for filling out this structure at startup time,
  195. * in addition to providing other modesetting features, like i2c and DDC
  196. * bus accessors.
  197. */
  198. struct drm_crtc_funcs {
  199. /**
  200. * @reset:
  201. *
  202. * Reset CRTC hardware and software state to off. This function isn't
  203. * called by the core directly, only through drm_mode_config_reset().
  204. * It's not a helper hook only for historical reasons.
  205. *
  206. * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
  207. * atomic state using this hook.
  208. */
  209. void (*reset)(struct drm_crtc *crtc);
  210. /**
  211. * @cursor_set:
  212. *
  213. * Update the cursor image. The cursor position is relative to the CRTC
  214. * and can be partially or fully outside of the visible area.
  215. *
  216. * Note that contrary to all other KMS functions the legacy cursor entry
  217. * points don't take a framebuffer object, but instead take directly a
  218. * raw buffer object id from the driver's buffer manager (which is
  219. * either GEM or TTM for current drivers).
  220. *
  221. * This entry point is deprecated, drivers should instead implement
  222. * universal plane support and register a proper cursor plane using
  223. * drm_crtc_init_with_planes().
  224. *
  225. * This callback is optional
  226. *
  227. * RETURNS:
  228. *
  229. * 0 on success or a negative error code on failure.
  230. */
  231. int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
  232. uint32_t handle, uint32_t width, uint32_t height);
  233. /**
  234. * @cursor_set2:
  235. *
  236. * Update the cursor image, including hotspot information. The hotspot
  237. * must not affect the cursor position in CRTC coordinates, but is only
  238. * meant as a hint for virtualized display hardware to coordinate the
  239. * guests and hosts cursor position. The cursor hotspot is relative to
  240. * the cursor image. Otherwise this works exactly like @cursor_set.
  241. *
  242. * This entry point is deprecated, drivers should instead implement
  243. * universal plane support and register a proper cursor plane using
  244. * drm_crtc_init_with_planes().
  245. *
  246. * This callback is optional.
  247. *
  248. * RETURNS:
  249. *
  250. * 0 on success or a negative error code on failure.
  251. */
  252. int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
  253. uint32_t handle, uint32_t width, uint32_t height,
  254. int32_t hot_x, int32_t hot_y);
  255. /**
  256. * @cursor_move:
  257. *
  258. * Update the cursor position. The cursor does not need to be visible
  259. * when this hook is called.
  260. *
  261. * This entry point is deprecated, drivers should instead implement
  262. * universal plane support and register a proper cursor plane using
  263. * drm_crtc_init_with_planes().
  264. *
  265. * This callback is optional.
  266. *
  267. * RETURNS:
  268. *
  269. * 0 on success or a negative error code on failure.
  270. */
  271. int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
  272. /**
  273. * @gamma_set:
  274. *
  275. * Set gamma on the CRTC.
  276. *
  277. * This callback is optional.
  278. *
  279. * NOTE:
  280. *
  281. * Drivers that support gamma tables and also fbdev emulation through
  282. * the provided helper library need to take care to fill out the gamma
  283. * hooks for both. Currently there's a bit an unfortunate duplication
  284. * going on, which should eventually be unified to just one set of
  285. * hooks.
  286. */
  287. int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
  288. uint32_t size);
  289. /**
  290. * @destroy:
  291. *
  292. * Clean up plane resources. This is only called at driver unload time
  293. * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
  294. * in DRM.
  295. */
  296. void (*destroy)(struct drm_crtc *crtc);
  297. /**
  298. * @set_config:
  299. *
  300. * This is the main legacy entry point to change the modeset state on a
  301. * CRTC. All the details of the desired configuration are passed in a
  302. * &struct drm_mode_set - see there for details.
  303. *
  304. * Drivers implementing atomic modeset should use
  305. * drm_atomic_helper_set_config() to implement this hook.
  306. *
  307. * RETURNS:
  308. *
  309. * 0 on success or a negative error code on failure.
  310. */
  311. int (*set_config)(struct drm_mode_set *set);
  312. /**
  313. * @page_flip:
  314. *
  315. * Legacy entry point to schedule a flip to the given framebuffer.
  316. *
  317. * Page flipping is a synchronization mechanism that replaces the frame
  318. * buffer being scanned out by the CRTC with a new frame buffer during
  319. * vertical blanking, avoiding tearing (except when requested otherwise
  320. * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
  321. * requests a page flip the DRM core verifies that the new frame buffer
  322. * is large enough to be scanned out by the CRTC in the currently
  323. * configured mode and then calls the CRTC ->page_flip() operation with a
  324. * pointer to the new frame buffer.
  325. *
  326. * The driver must wait for any pending rendering to the new framebuffer
  327. * to complete before executing the flip. It should also wait for any
  328. * pending rendering from other drivers if the underlying buffer is a
  329. * shared dma-buf.
  330. *
  331. * An application can request to be notified when the page flip has
  332. * completed. The drm core will supply a &struct drm_event in the event
  333. * parameter in this case. This can be handled by the
  334. * drm_crtc_send_vblank_event() function, which the driver should call on
  335. * the provided event upon completion of the flip. Note that if
  336. * the driver supports vblank signalling and timestamping the vblank
  337. * counters and timestamps must agree with the ones returned from page
  338. * flip events. With the current vblank helper infrastructure this can
  339. * be achieved by holding a vblank reference while the page flip is
  340. * pending, acquired through drm_crtc_vblank_get() and released with
  341. * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
  342. * counter and timestamp tracking though, e.g. if they have accurate
  343. * timestamp registers in hardware.
  344. *
  345. * This callback is optional.
  346. *
  347. * NOTE:
  348. *
  349. * Very early versions of the KMS ABI mandated that the driver must
  350. * block (but not reject) any rendering to the old framebuffer until the
  351. * flip operation has completed and the old framebuffer is no longer
  352. * visible. This requirement has been lifted, and userspace is instead
  353. * expected to request delivery of an event and wait with recycling old
  354. * buffers until such has been received.
  355. *
  356. * RETURNS:
  357. *
  358. * 0 on success or a negative error code on failure. Note that if a
  359. * ->page_flip() operation is already pending the callback should return
  360. * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
  361. * or just runtime disabled through DPMS respectively the new atomic
  362. * "ACTIVE" state) should result in an -EINVAL error code. Note that
  363. * drm_atomic_helper_page_flip() checks this already for atomic drivers.
  364. */
  365. int (*page_flip)(struct drm_crtc *crtc,
  366. struct drm_framebuffer *fb,
  367. struct drm_pending_vblank_event *event,
  368. uint32_t flags);
  369. /**
  370. * @page_flip_target:
  371. *
  372. * Same as @page_flip but with an additional parameter specifying the
  373. * absolute target vertical blank period (as reported by
  374. * drm_crtc_vblank_count()) when the flip should take effect.
  375. *
  376. * Note that the core code calls drm_crtc_vblank_get before this entry
  377. * point, and will call drm_crtc_vblank_put if this entry point returns
  378. * any non-0 error code. It's the driver's responsibility to call
  379. * drm_crtc_vblank_put after this entry point returns 0, typically when
  380. * the flip completes.
  381. */
  382. int (*page_flip_target)(struct drm_crtc *crtc,
  383. struct drm_framebuffer *fb,
  384. struct drm_pending_vblank_event *event,
  385. uint32_t flags, uint32_t target);
  386. /**
  387. * @set_property:
  388. *
  389. * This is the legacy entry point to update a property attached to the
  390. * CRTC.
  391. *
  392. * Drivers implementing atomic modeset should use
  393. * drm_atomic_helper_crtc_set_property() to implement this hook.
  394. *
  395. * This callback is optional if the driver does not support any legacy
  396. * driver-private properties.
  397. *
  398. * RETURNS:
  399. *
  400. * 0 on success or a negative error code on failure.
  401. */
  402. int (*set_property)(struct drm_crtc *crtc,
  403. struct drm_property *property, uint64_t val);
  404. /**
  405. * @atomic_duplicate_state:
  406. *
  407. * Duplicate the current atomic state for this CRTC and return it.
  408. * The core and helpers gurantee that any atomic state duplicated with
  409. * this hook and still owned by the caller (i.e. not transferred to the
  410. * driver by calling ->atomic_commit() from struct
  411. * &drm_mode_config_funcs) will be cleaned up by calling the
  412. * @atomic_destroy_state hook in this structure.
  413. *
  414. * Atomic drivers which don't subclass &struct drm_crtc should use
  415. * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
  416. * state structure to extend it with driver-private state should use
  417. * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
  418. * duplicated in a consistent fashion across drivers.
  419. *
  420. * It is an error to call this hook before crtc->state has been
  421. * initialized correctly.
  422. *
  423. * NOTE:
  424. *
  425. * If the duplicate state references refcounted resources this hook must
  426. * acquire a reference for each of them. The driver must release these
  427. * references again in @atomic_destroy_state.
  428. *
  429. * RETURNS:
  430. *
  431. * Duplicated atomic state or NULL when the allocation failed.
  432. */
  433. struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
  434. /**
  435. * @atomic_destroy_state:
  436. *
  437. * Destroy a state duplicated with @atomic_duplicate_state and release
  438. * or unreference all resources it references
  439. */
  440. void (*atomic_destroy_state)(struct drm_crtc *crtc,
  441. struct drm_crtc_state *state);
  442. /**
  443. * @atomic_set_property:
  444. *
  445. * Decode a driver-private property value and store the decoded value
  446. * into the passed-in state structure. Since the atomic core decodes all
  447. * standardized properties (even for extensions beyond the core set of
  448. * properties which might not be implemented by all drivers) this
  449. * requires drivers to subclass the state structure.
  450. *
  451. * Such driver-private properties should really only be implemented for
  452. * truly hardware/vendor specific state. Instead it is preferred to
  453. * standardize atomic extension and decode the properties used to expose
  454. * such an extension in the core.
  455. *
  456. * Do not call this function directly, use
  457. * drm_atomic_crtc_set_property() instead.
  458. *
  459. * This callback is optional if the driver does not support any
  460. * driver-private atomic properties.
  461. *
  462. * NOTE:
  463. *
  464. * This function is called in the state assembly phase of atomic
  465. * modesets, which can be aborted for any reason (including on
  466. * userspace's request to just check whether a configuration would be
  467. * possible). Drivers MUST NOT touch any persistent state (hardware or
  468. * software) or data structures except the passed in @state parameter.
  469. *
  470. * Also since userspace controls in which order properties are set this
  471. * function must not do any input validation (since the state update is
  472. * incomplete and hence likely inconsistent). Instead any such input
  473. * validation must be done in the various atomic_check callbacks.
  474. *
  475. * RETURNS:
  476. *
  477. * 0 if the property has been found, -EINVAL if the property isn't
  478. * implemented by the driver (which should never happen, the core only
  479. * asks for properties attached to this CRTC). No other validation is
  480. * allowed by the driver. The core already checks that the property
  481. * value is within the range (integer, valid enum value, ...) the driver
  482. * set when registering the property.
  483. */
  484. int (*atomic_set_property)(struct drm_crtc *crtc,
  485. struct drm_crtc_state *state,
  486. struct drm_property *property,
  487. uint64_t val);
  488. /**
  489. * @atomic_get_property:
  490. *
  491. * Reads out the decoded driver-private property. This is used to
  492. * implement the GETCRTC IOCTL.
  493. *
  494. * Do not call this function directly, use
  495. * drm_atomic_crtc_get_property() instead.
  496. *
  497. * This callback is optional if the driver does not support any
  498. * driver-private atomic properties.
  499. *
  500. * RETURNS:
  501. *
  502. * 0 on success, -EINVAL if the property isn't implemented by the
  503. * driver (which should never happen, the core only asks for
  504. * properties attached to this CRTC).
  505. */
  506. int (*atomic_get_property)(struct drm_crtc *crtc,
  507. const struct drm_crtc_state *state,
  508. struct drm_property *property,
  509. uint64_t *val);
  510. /**
  511. * @late_register:
  512. *
  513. * This optional hook can be used to register additional userspace
  514. * interfaces attached to the crtc like debugfs interfaces.
  515. * It is called late in the driver load sequence from drm_dev_register().
  516. * Everything added from this callback should be unregistered in
  517. * the early_unregister callback.
  518. *
  519. * Returns:
  520. *
  521. * 0 on success, or a negative error code on failure.
  522. */
  523. int (*late_register)(struct drm_crtc *crtc);
  524. /**
  525. * @early_unregister:
  526. *
  527. * This optional hook should be used to unregister the additional
  528. * userspace interfaces attached to the crtc from
  529. * late_unregister(). It is called from drm_dev_unregister(),
  530. * early in the driver unload sequence to disable userspace access
  531. * before data structures are torndown.
  532. */
  533. void (*early_unregister)(struct drm_crtc *crtc);
  534. /**
  535. * @set_crc_source:
  536. *
  537. * Changes the source of CRC checksums of frames at the request of
  538. * userspace, typically for testing purposes. The sources available are
  539. * specific of each driver and a %NULL value indicates that CRC
  540. * generation is to be switched off.
  541. *
  542. * When CRC generation is enabled, the driver should call
  543. * drm_crtc_add_crc_entry() at each frame, providing any information
  544. * that characterizes the frame contents in the crcN arguments, as
  545. * provided from the configured source. Drivers must accept a "auto"
  546. * source name that will select a default source for this CRTC.
  547. *
  548. * This callback is optional if the driver does not support any CRC
  549. * generation functionality.
  550. *
  551. * RETURNS:
  552. *
  553. * 0 on success or a negative error code on failure.
  554. */
  555. int (*set_crc_source)(struct drm_crtc *crtc, const char *source,
  556. size_t *values_cnt);
  557. /**
  558. * @atomic_print_state:
  559. *
  560. * If driver subclasses &struct drm_crtc_state, it should implement
  561. * this optional hook for printing additional driver specific state.
  562. *
  563. * Do not call this directly, use drm_atomic_crtc_print_state()
  564. * instead.
  565. */
  566. void (*atomic_print_state)(struct drm_printer *p,
  567. const struct drm_crtc_state *state);
  568. };
  569. /**
  570. * struct drm_crtc - central CRTC control structure
  571. * @dev: parent DRM device
  572. * @port: OF node used by drm_of_find_possible_crtcs()
  573. * @head: list management
  574. * @name: human readable name, can be overwritten by the driver
  575. * @mutex: per-CRTC locking
  576. * @base: base KMS object for ID tracking etc.
  577. * @primary: primary plane for this CRTC
  578. * @cursor: cursor plane for this CRTC
  579. * @cursor_x: current x position of the cursor, used for universal cursor planes
  580. * @cursor_y: current y position of the cursor, used for universal cursor planes
  581. * @enabled: is this CRTC enabled?
  582. * @mode: current mode timings
  583. * @hwmode: mode timings as programmed to hw regs
  584. * @x: x position on screen
  585. * @y: y position on screen
  586. * @funcs: CRTC control functions
  587. * @gamma_size: size of gamma ramp
  588. * @gamma_store: gamma ramp values
  589. * @helper_private: mid-layer private data
  590. * @properties: property tracking for this CRTC
  591. *
  592. * Each CRTC may have one or more connectors associated with it. This structure
  593. * allows the CRTC to be controlled.
  594. */
  595. struct drm_crtc {
  596. struct drm_device *dev;
  597. struct device_node *port;
  598. struct list_head head;
  599. char *name;
  600. /**
  601. * @mutex:
  602. *
  603. * This provides a read lock for the overall crtc state (mode, dpms
  604. * state, ...) and a write lock for everything which can be update
  605. * without a full modeset (fb, cursor data, crtc properties ...). Full
  606. * modeset also need to grab dev->mode_config.connection_mutex.
  607. */
  608. struct drm_modeset_lock mutex;
  609. struct drm_mode_object base;
  610. /* primary and cursor planes for CRTC */
  611. struct drm_plane *primary;
  612. struct drm_plane *cursor;
  613. /**
  614. * @index: Position inside the mode_config.list, can be used as an array
  615. * index. It is invariant over the lifetime of the CRTC.
  616. */
  617. unsigned index;
  618. /* position of cursor plane on crtc */
  619. int cursor_x;
  620. int cursor_y;
  621. bool enabled;
  622. /* Requested mode from modesetting. */
  623. struct drm_display_mode mode;
  624. /* Programmed mode in hw, after adjustments for encoders,
  625. * crtc, panel scaling etc. Needed for timestamping etc.
  626. */
  627. struct drm_display_mode hwmode;
  628. int x, y;
  629. const struct drm_crtc_funcs *funcs;
  630. /* Legacy FB CRTC gamma size for reporting to userspace */
  631. uint32_t gamma_size;
  632. uint16_t *gamma_store;
  633. /* if you are using the helper */
  634. const struct drm_crtc_helper_funcs *helper_private;
  635. struct drm_object_properties properties;
  636. /**
  637. * @state:
  638. *
  639. * Current atomic state for this CRTC.
  640. */
  641. struct drm_crtc_state *state;
  642. /**
  643. * @commit_list:
  644. *
  645. * List of &drm_crtc_commit structures tracking pending commits.
  646. * Protected by @commit_lock. This list doesn't hold its own full
  647. * reference, but burrows it from the ongoing commit. Commit entries
  648. * must be removed from this list once the commit is fully completed,
  649. * but before it's correspoding &drm_atomic_state gets destroyed.
  650. */
  651. struct list_head commit_list;
  652. /**
  653. * @commit_lock:
  654. *
  655. * Spinlock to protect @commit_list.
  656. */
  657. spinlock_t commit_lock;
  658. /**
  659. * @acquire_ctx:
  660. *
  661. * Per-CRTC implicit acquire context used by atomic drivers for legacy
  662. * IOCTLs, so that atomic drivers can get at the locking acquire
  663. * context.
  664. */
  665. struct drm_modeset_acquire_ctx *acquire_ctx;
  666. #ifdef CONFIG_DEBUG_FS
  667. /**
  668. * @debugfs_entry:
  669. *
  670. * Debugfs directory for this CRTC.
  671. */
  672. struct dentry *debugfs_entry;
  673. /**
  674. * @crc:
  675. *
  676. * Configuration settings of CRC capture.
  677. */
  678. struct drm_crtc_crc crc;
  679. #endif
  680. /**
  681. * @fence_context:
  682. *
  683. * timeline context used for fence operations.
  684. */
  685. unsigned int fence_context;
  686. /**
  687. * @fence_lock:
  688. *
  689. * spinlock to protect the fences in the fence_context.
  690. */
  691. spinlock_t fence_lock;
  692. /**
  693. * @fence_seqno:
  694. *
  695. * Seqno variable used as monotonic counter for the fences
  696. * created on the CRTC's timeline.
  697. */
  698. unsigned long fence_seqno;
  699. /**
  700. * @timeline_name:
  701. *
  702. * The name of the CRTC's fence timeline.
  703. */
  704. char timeline_name[32];
  705. };
  706. /**
  707. * struct drm_mode_set - new values for a CRTC config change
  708. * @fb: framebuffer to use for new config
  709. * @crtc: CRTC whose configuration we're about to change
  710. * @mode: mode timings to use
  711. * @x: position of this CRTC relative to @fb
  712. * @y: position of this CRTC relative to @fb
  713. * @connectors: array of connectors to drive with this CRTC if possible
  714. * @num_connectors: size of @connectors array
  715. *
  716. * Represents a single crtc the connectors that it drives with what mode
  717. * and from which framebuffer it scans out from.
  718. *
  719. * This is used to set modes.
  720. */
  721. struct drm_mode_set {
  722. struct drm_framebuffer *fb;
  723. struct drm_crtc *crtc;
  724. struct drm_display_mode *mode;
  725. uint32_t x;
  726. uint32_t y;
  727. struct drm_connector **connectors;
  728. size_t num_connectors;
  729. };
  730. #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
  731. __printf(6, 7)
  732. int drm_crtc_init_with_planes(struct drm_device *dev,
  733. struct drm_crtc *crtc,
  734. struct drm_plane *primary,
  735. struct drm_plane *cursor,
  736. const struct drm_crtc_funcs *funcs,
  737. const char *name, ...);
  738. void drm_crtc_cleanup(struct drm_crtc *crtc);
  739. /**
  740. * drm_crtc_index - find the index of a registered CRTC
  741. * @crtc: CRTC to find index for
  742. *
  743. * Given a registered CRTC, return the index of that CRTC within a DRM
  744. * device's list of CRTCs.
  745. */
  746. static inline unsigned int drm_crtc_index(const struct drm_crtc *crtc)
  747. {
  748. return crtc->index;
  749. }
  750. /**
  751. * drm_crtc_mask - find the mask of a registered CRTC
  752. * @crtc: CRTC to find mask for
  753. *
  754. * Given a registered CRTC, return the mask bit of that CRTC for an
  755. * encoder's possible_crtcs field.
  756. */
  757. static inline uint32_t drm_crtc_mask(const struct drm_crtc *crtc)
  758. {
  759. return 1 << drm_crtc_index(crtc);
  760. }
  761. void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
  762. int *hdisplay, int *vdisplay);
  763. int drm_crtc_force_disable(struct drm_crtc *crtc);
  764. int drm_crtc_force_disable_all(struct drm_device *dev);
  765. int drm_mode_set_config_internal(struct drm_mode_set *set);
  766. struct drm_crtc *drm_crtc_from_index(struct drm_device *dev, int idx);
  767. /* Helpers */
  768. static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
  769. uint32_t id)
  770. {
  771. struct drm_mode_object *mo;
  772. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
  773. return mo ? obj_to_crtc(mo) : NULL;
  774. }
  775. #define drm_for_each_crtc(crtc, dev) \
  776. list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
  777. #endif /* __DRM_CRTC_H__ */