drm_crtc.h 32 KB

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