drm_crtc.h 45 KB

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