drm_crtc.h 45 KB

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