drm_crtc.h 38 KB

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