drm_crtc.h 30 KB

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