drm_crtc.h 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407
  1. /*
  2. * Copyright © 2006 Keith Packard
  3. * Copyright © 2007-2008 Dave Airlie
  4. * Copyright © 2007-2008 Intel Corporation
  5. * Jesse Barnes <jesse.barnes@intel.com>
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  21. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  22. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  23. * OTHER DEALINGS IN THE SOFTWARE.
  24. */
  25. #ifndef __DRM_CRTC_H__
  26. #define __DRM_CRTC_H__
  27. #include <linux/i2c.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/types.h>
  30. #include <linux/idr.h>
  31. #include <linux/fb.h>
  32. #include <linux/hdmi.h>
  33. #include <linux/media-bus-format.h>
  34. #include <uapi/drm/drm_mode.h>
  35. #include <uapi/drm/drm_fourcc.h>
  36. #include <drm/drm_modeset_lock.h>
  37. #include <drm/drm_rect.h>
  38. #include <drm/drm_mode_object.h>
  39. #include <drm/drm_framebuffer.h>
  40. #include <drm/drm_modes.h>
  41. #include <drm/drm_connector.h>
  42. #include <drm/drm_encoder.h>
  43. #include <drm/drm_property.h>
  44. #include <drm/drm_bridge.h>
  45. #include <drm/drm_edid.h>
  46. #include <drm/drm_plane.h>
  47. #include <drm/drm_blend.h>
  48. #include <drm/drm_color_mgmt.h>
  49. struct drm_device;
  50. struct drm_mode_set;
  51. struct drm_file;
  52. struct drm_clip_rect;
  53. struct device_node;
  54. struct fence;
  55. struct edid;
  56. static inline int64_t U642I64(uint64_t val)
  57. {
  58. return (int64_t)*((int64_t *)&val);
  59. }
  60. static inline uint64_t I642U64(int64_t val)
  61. {
  62. return (uint64_t)*((uint64_t *)&val);
  63. }
  64. /* data corresponds to displayid vend/prod/serial */
  65. struct drm_tile_group {
  66. struct kref refcount;
  67. struct drm_device *dev;
  68. int id;
  69. u8 group_data[8];
  70. };
  71. struct drm_crtc;
  72. struct drm_encoder;
  73. struct drm_pending_vblank_event;
  74. struct drm_plane;
  75. struct drm_bridge;
  76. struct drm_atomic_state;
  77. struct drm_crtc_helper_funcs;
  78. struct drm_encoder_helper_funcs;
  79. struct drm_plane_helper_funcs;
  80. /**
  81. * struct drm_crtc_state - mutable CRTC state
  82. * @crtc: backpointer to the CRTC
  83. * @enable: whether the CRTC should be enabled, gates all other state
  84. * @active: whether the CRTC is actively displaying (used for DPMS)
  85. * @planes_changed: planes on this crtc are updated
  86. * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
  87. * @active_changed: crtc_state->active has been toggled.
  88. * @connectors_changed: connectors to this crtc have been updated
  89. * @zpos_changed: zpos values of planes on this crtc have been updated
  90. * @color_mgmt_changed: color management properties have changed (degamma or
  91. * gamma LUT or CSC matrix)
  92. * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
  93. * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
  94. * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
  95. * @last_vblank_count: for helpers and drivers to capture the vblank of the
  96. * update to ensure framebuffer cleanup isn't done too early
  97. * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
  98. * @mode: current mode timings
  99. * @mode_blob: &drm_property_blob for @mode
  100. * @degamma_lut: Lookup table for converting framebuffer pixel data
  101. * before apply the conversion matrix
  102. * @ctm: Transformation matrix
  103. * @gamma_lut: Lookup table for converting pixel data after the
  104. * conversion matrix
  105. * @state: backpointer to global drm_atomic_state
  106. *
  107. * Note that the distinction between @enable and @active is rather subtile:
  108. * Flipping @active while @enable is set without changing anything else may
  109. * never return in a failure from the ->atomic_check callback. Userspace assumes
  110. * that a DPMS On will always succeed. In other words: @enable controls resource
  111. * assignment, @active controls the actual hardware state.
  112. */
  113. struct drm_crtc_state {
  114. struct drm_crtc *crtc;
  115. bool enable;
  116. bool active;
  117. /* computed state bits used by helpers and drivers */
  118. bool planes_changed : 1;
  119. bool mode_changed : 1;
  120. bool active_changed : 1;
  121. bool connectors_changed : 1;
  122. bool zpos_changed : 1;
  123. bool color_mgmt_changed : 1;
  124. /* attached planes bitmask:
  125. * WARNING: transitional helpers do not maintain plane_mask so
  126. * drivers not converted over to atomic helpers should not rely
  127. * on plane_mask being accurate!
  128. */
  129. u32 plane_mask;
  130. u32 connector_mask;
  131. u32 encoder_mask;
  132. /* last_vblank_count: for vblank waits before cleanup */
  133. u32 last_vblank_count;
  134. /* adjusted_mode: for use by helpers and drivers */
  135. struct drm_display_mode adjusted_mode;
  136. struct drm_display_mode mode;
  137. /* blob property to expose current mode to atomic userspace */
  138. struct drm_property_blob *mode_blob;
  139. /* blob property to expose color management to userspace */
  140. struct drm_property_blob *degamma_lut;
  141. struct drm_property_blob *ctm;
  142. struct drm_property_blob *gamma_lut;
  143. /**
  144. * @event:
  145. *
  146. * Optional pointer to a DRM event to signal upon completion of the
  147. * state update. The driver must send out the event when the atomic
  148. * commit operation completes. There are two cases:
  149. *
  150. * - The event is for a CRTC which is being disabled through this
  151. * atomic commit. In that case the event can be send out any time
  152. * after the hardware has stopped scanning out the current
  153. * framebuffers. It should contain the timestamp and counter for the
  154. * last vblank before the display pipeline was shut off.
  155. *
  156. * - For a CRTC which is enabled at the end of the commit (even when it
  157. * undergoes an full modeset) the vblank timestamp and counter must
  158. * be for the vblank right before the first frame that scans out the
  159. * new set of buffers. Again the event can only be sent out after the
  160. * hardware has stopped scanning out the old buffers.
  161. *
  162. * - Events for disabled CRTCs are not allowed, and drivers can ignore
  163. * that case.
  164. *
  165. * This can be handled by the drm_crtc_send_vblank_event() function,
  166. * which the driver should call on the provided event upon completion of
  167. * the atomic commit. Note that if the driver supports vblank signalling
  168. * and timestamping the vblank counters and timestamps must agree with
  169. * the ones returned from page flip events. With the current vblank
  170. * helper infrastructure this can be achieved by holding a vblank
  171. * reference while the page flip is pending, acquired through
  172. * drm_crtc_vblank_get() and released with drm_crtc_vblank_put().
  173. * Drivers are free to implement their own vblank counter and timestamp
  174. * tracking though, e.g. if they have accurate timestamp registers in
  175. * hardware.
  176. *
  177. * For hardware which supports some means to synchronize vblank
  178. * interrupt delivery with committing display state there's also
  179. * drm_crtc_arm_vblank_event(). See the documentation of that function
  180. * for a detailed discussion of the constraints it needs to be used
  181. * safely.
  182. */
  183. struct drm_pending_vblank_event *event;
  184. struct drm_atomic_state *state;
  185. };
  186. /**
  187. * struct drm_crtc_funcs - control CRTCs for a given device
  188. *
  189. * The drm_crtc_funcs structure is the central CRTC management structure
  190. * in the DRM. Each CRTC controls one or more connectors (note that the name
  191. * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
  192. * connectors, not just CRTs).
  193. *
  194. * Each driver is responsible for filling out this structure at startup time,
  195. * in addition to providing other modesetting features, like i2c and DDC
  196. * bus accessors.
  197. */
  198. struct drm_crtc_funcs {
  199. /**
  200. * @reset:
  201. *
  202. * Reset CRTC hardware and software state to off. This function isn't
  203. * called by the core directly, only through drm_mode_config_reset().
  204. * It's not a helper hook only for historical reasons.
  205. *
  206. * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
  207. * atomic state using this hook.
  208. */
  209. void (*reset)(struct drm_crtc *crtc);
  210. /**
  211. * @cursor_set:
  212. *
  213. * Update the cursor image. The cursor position is relative to the CRTC
  214. * and can be partially or fully outside of the visible area.
  215. *
  216. * Note that contrary to all other KMS functions the legacy cursor entry
  217. * points don't take a framebuffer object, but instead take directly a
  218. * raw buffer object id from the driver's buffer manager (which is
  219. * either GEM or TTM for current drivers).
  220. *
  221. * This entry point is deprecated, drivers should instead implement
  222. * universal plane support and register a proper cursor plane using
  223. * drm_crtc_init_with_planes().
  224. *
  225. * This callback is optional
  226. *
  227. * RETURNS:
  228. *
  229. * 0 on success or a negative error code on failure.
  230. */
  231. int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
  232. uint32_t handle, uint32_t width, uint32_t height);
  233. /**
  234. * @cursor_set2:
  235. *
  236. * Update the cursor image, including hotspot information. The hotspot
  237. * must not affect the cursor position in CRTC coordinates, but is only
  238. * meant as a hint for virtualized display hardware to coordinate the
  239. * guests and hosts cursor position. The cursor hotspot is relative to
  240. * the cursor image. Otherwise this works exactly like @cursor_set.
  241. *
  242. * This entry point is deprecated, drivers should instead implement
  243. * universal plane support and register a proper cursor plane using
  244. * drm_crtc_init_with_planes().
  245. *
  246. * This callback is optional.
  247. *
  248. * RETURNS:
  249. *
  250. * 0 on success or a negative error code on failure.
  251. */
  252. int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
  253. uint32_t handle, uint32_t width, uint32_t height,
  254. int32_t hot_x, int32_t hot_y);
  255. /**
  256. * @cursor_move:
  257. *
  258. * Update the cursor position. The cursor does not need to be visible
  259. * when this hook is called.
  260. *
  261. * This entry point is deprecated, drivers should instead implement
  262. * universal plane support and register a proper cursor plane using
  263. * drm_crtc_init_with_planes().
  264. *
  265. * This callback is optional.
  266. *
  267. * RETURNS:
  268. *
  269. * 0 on success or a negative error code on failure.
  270. */
  271. int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
  272. /**
  273. * @gamma_set:
  274. *
  275. * Set gamma on the CRTC.
  276. *
  277. * This callback is optional.
  278. *
  279. * NOTE:
  280. *
  281. * Drivers that support gamma tables and also fbdev emulation through
  282. * the provided helper library need to take care to fill out the gamma
  283. * hooks for both. Currently there's a bit an unfortunate duplication
  284. * going on, which should eventually be unified to just one set of
  285. * hooks.
  286. */
  287. int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
  288. uint32_t size);
  289. /**
  290. * @destroy:
  291. *
  292. * Clean up plane resources. This is only called at driver unload time
  293. * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
  294. * in DRM.
  295. */
  296. void (*destroy)(struct drm_crtc *crtc);
  297. /**
  298. * @set_config:
  299. *
  300. * This is the main legacy entry point to change the modeset state on a
  301. * CRTC. All the details of the desired configuration are passed in a
  302. * struct &drm_mode_set - see there for details.
  303. *
  304. * Drivers implementing atomic modeset should use
  305. * drm_atomic_helper_set_config() to implement this hook.
  306. *
  307. * RETURNS:
  308. *
  309. * 0 on success or a negative error code on failure.
  310. */
  311. int (*set_config)(struct drm_mode_set *set);
  312. /**
  313. * @page_flip:
  314. *
  315. * Legacy entry point to schedule a flip to the given framebuffer.
  316. *
  317. * Page flipping is a synchronization mechanism that replaces the frame
  318. * buffer being scanned out by the CRTC with a new frame buffer during
  319. * vertical blanking, avoiding tearing (except when requested otherwise
  320. * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
  321. * requests a page flip the DRM core verifies that the new frame buffer
  322. * is large enough to be scanned out by the CRTC in the currently
  323. * configured mode and then calls the CRTC ->page_flip() operation with a
  324. * pointer to the new frame buffer.
  325. *
  326. * The driver must wait for any pending rendering to the new framebuffer
  327. * to complete before executing the flip. It should also wait for any
  328. * pending rendering from other drivers if the underlying buffer is a
  329. * shared dma-buf.
  330. *
  331. * An application can request to be notified when the page flip has
  332. * completed. The drm core will supply a struct &drm_event in the event
  333. * parameter in this case. This can be handled by the
  334. * drm_crtc_send_vblank_event() function, which the driver should call on
  335. * the provided event upon completion of the flip. Note that if
  336. * the driver supports vblank signalling and timestamping the vblank
  337. * counters and timestamps must agree with the ones returned from page
  338. * flip events. With the current vblank helper infrastructure this can
  339. * be achieved by holding a vblank reference while the page flip is
  340. * pending, acquired through drm_crtc_vblank_get() and released with
  341. * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
  342. * counter and timestamp tracking though, e.g. if they have accurate
  343. * timestamp registers in hardware.
  344. *
  345. * This callback is optional.
  346. *
  347. * NOTE:
  348. *
  349. * Very early versions of the KMS ABI mandated that the driver must
  350. * block (but not reject) any rendering to the old framebuffer until the
  351. * flip operation has completed and the old framebuffer is no longer
  352. * visible. This requirement has been lifted, and userspace is instead
  353. * expected to request delivery of an event and wait with recycling old
  354. * buffers until such has been received.
  355. *
  356. * RETURNS:
  357. *
  358. * 0 on success or a negative error code on failure. Note that if a
  359. * ->page_flip() operation is already pending the callback should return
  360. * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
  361. * or just runtime disabled through DPMS respectively the new atomic
  362. * "ACTIVE" state) should result in an -EINVAL error code. Note that
  363. * drm_atomic_helper_page_flip() checks this already for atomic drivers.
  364. */
  365. int (*page_flip)(struct drm_crtc *crtc,
  366. struct drm_framebuffer *fb,
  367. struct drm_pending_vblank_event *event,
  368. uint32_t flags);
  369. /**
  370. * @page_flip_target:
  371. *
  372. * Same as @page_flip but with an additional parameter specifying the
  373. * absolute target vertical blank period (as reported by
  374. * drm_crtc_vblank_count()) when the flip should take effect.
  375. *
  376. * Note that the core code calls drm_crtc_vblank_get before this entry
  377. * point, and will call drm_crtc_vblank_put if this entry point returns
  378. * any non-0 error code. It's the driver's responsibility to call
  379. * drm_crtc_vblank_put after this entry point returns 0, typically when
  380. * the flip completes.
  381. */
  382. int (*page_flip_target)(struct drm_crtc *crtc,
  383. struct drm_framebuffer *fb,
  384. struct drm_pending_vblank_event *event,
  385. uint32_t flags, uint32_t target);
  386. /**
  387. * @set_property:
  388. *
  389. * This is the legacy entry point to update a property attached to the
  390. * CRTC.
  391. *
  392. * Drivers implementing atomic modeset should use
  393. * drm_atomic_helper_crtc_set_property() to implement this hook.
  394. *
  395. * This callback is optional if the driver does not support any legacy
  396. * driver-private properties.
  397. *
  398. * RETURNS:
  399. *
  400. * 0 on success or a negative error code on failure.
  401. */
  402. int (*set_property)(struct drm_crtc *crtc,
  403. struct drm_property *property, uint64_t val);
  404. /**
  405. * @atomic_duplicate_state:
  406. *
  407. * Duplicate the current atomic state for this CRTC and return it.
  408. * The core and helpers gurantee that any atomic state duplicated with
  409. * this hook and still owned by the caller (i.e. not transferred to the
  410. * driver by calling ->atomic_commit() from struct
  411. * &drm_mode_config_funcs) will be cleaned up by calling the
  412. * @atomic_destroy_state hook in this structure.
  413. *
  414. * Atomic drivers which don't subclass struct &drm_crtc should use
  415. * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
  416. * state structure to extend it with driver-private state should use
  417. * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
  418. * duplicated in a consistent fashion across drivers.
  419. *
  420. * It is an error to call this hook before crtc->state has been
  421. * initialized correctly.
  422. *
  423. * NOTE:
  424. *
  425. * If the duplicate state references refcounted resources this hook must
  426. * acquire a reference for each of them. The driver must release these
  427. * references again in @atomic_destroy_state.
  428. *
  429. * RETURNS:
  430. *
  431. * Duplicated atomic state or NULL when the allocation failed.
  432. */
  433. struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
  434. /**
  435. * @atomic_destroy_state:
  436. *
  437. * Destroy a state duplicated with @atomic_duplicate_state and release
  438. * or unreference all resources it references
  439. */
  440. void (*atomic_destroy_state)(struct drm_crtc *crtc,
  441. struct drm_crtc_state *state);
  442. /**
  443. * @atomic_set_property:
  444. *
  445. * Decode a driver-private property value and store the decoded value
  446. * into the passed-in state structure. Since the atomic core decodes all
  447. * standardized properties (even for extensions beyond the core set of
  448. * properties which might not be implemented by all drivers) this
  449. * requires drivers to subclass the state structure.
  450. *
  451. * Such driver-private properties should really only be implemented for
  452. * truly hardware/vendor specific state. Instead it is preferred to
  453. * standardize atomic extension and decode the properties used to expose
  454. * such an extension in the core.
  455. *
  456. * Do not call this function directly, use
  457. * drm_atomic_crtc_set_property() instead.
  458. *
  459. * This callback is optional if the driver does not support any
  460. * driver-private atomic properties.
  461. *
  462. * NOTE:
  463. *
  464. * This function is called in the state assembly phase of atomic
  465. * modesets, which can be aborted for any reason (including on
  466. * userspace's request to just check whether a configuration would be
  467. * possible). Drivers MUST NOT touch any persistent state (hardware or
  468. * software) or data structures except the passed in @state parameter.
  469. *
  470. * Also since userspace controls in which order properties are set this
  471. * function must not do any input validation (since the state update is
  472. * incomplete and hence likely inconsistent). Instead any such input
  473. * validation must be done in the various atomic_check callbacks.
  474. *
  475. * RETURNS:
  476. *
  477. * 0 if the property has been found, -EINVAL if the property isn't
  478. * implemented by the driver (which should never happen, the core only
  479. * asks for properties attached to this CRTC). No other validation is
  480. * allowed by the driver. The core already checks that the property
  481. * value is within the range (integer, valid enum value, ...) the driver
  482. * set when registering the property.
  483. */
  484. int (*atomic_set_property)(struct drm_crtc *crtc,
  485. struct drm_crtc_state *state,
  486. struct drm_property *property,
  487. uint64_t val);
  488. /**
  489. * @atomic_get_property:
  490. *
  491. * Reads out the decoded driver-private property. This is used to
  492. * implement the GETCRTC IOCTL.
  493. *
  494. * Do not call this function directly, use
  495. * drm_atomic_crtc_get_property() instead.
  496. *
  497. * This callback is optional if the driver does not support any
  498. * driver-private atomic properties.
  499. *
  500. * RETURNS:
  501. *
  502. * 0 on success, -EINVAL if the property isn't implemented by the
  503. * driver (which should never happen, the core only asks for
  504. * properties attached to this CRTC).
  505. */
  506. int (*atomic_get_property)(struct drm_crtc *crtc,
  507. const struct drm_crtc_state *state,
  508. struct drm_property *property,
  509. uint64_t *val);
  510. /**
  511. * @late_register:
  512. *
  513. * This optional hook can be used to register additional userspace
  514. * interfaces attached to the crtc like debugfs interfaces.
  515. * It is called late in the driver load sequence from drm_dev_register().
  516. * Everything added from this callback should be unregistered in
  517. * the early_unregister callback.
  518. *
  519. * Returns:
  520. *
  521. * 0 on success, or a negative error code on failure.
  522. */
  523. int (*late_register)(struct drm_crtc *crtc);
  524. /**
  525. * @early_unregister:
  526. *
  527. * This optional hook should be used to unregister the additional
  528. * userspace interfaces attached to the crtc from
  529. * late_unregister(). It is called from drm_dev_unregister(),
  530. * early in the driver unload sequence to disable userspace access
  531. * before data structures are torndown.
  532. */
  533. void (*early_unregister)(struct drm_crtc *crtc);
  534. };
  535. /**
  536. * struct drm_crtc - central CRTC control structure
  537. * @dev: parent DRM device
  538. * @port: OF node used by drm_of_find_possible_crtcs()
  539. * @head: list management
  540. * @name: human readable name, can be overwritten by the driver
  541. * @mutex: per-CRTC locking
  542. * @base: base KMS object for ID tracking etc.
  543. * @primary: primary plane for this CRTC
  544. * @cursor: cursor plane for this CRTC
  545. * @cursor_x: current x position of the cursor, used for universal cursor planes
  546. * @cursor_y: current y position of the cursor, used for universal cursor planes
  547. * @enabled: is this CRTC enabled?
  548. * @mode: current mode timings
  549. * @hwmode: mode timings as programmed to hw regs
  550. * @x: x position on screen
  551. * @y: y position on screen
  552. * @funcs: CRTC control functions
  553. * @gamma_size: size of gamma ramp
  554. * @gamma_store: gamma ramp values
  555. * @helper_private: mid-layer private data
  556. * @properties: property tracking for this CRTC
  557. *
  558. * Each CRTC may have one or more connectors associated with it. This structure
  559. * allows the CRTC to be controlled.
  560. */
  561. struct drm_crtc {
  562. struct drm_device *dev;
  563. struct device_node *port;
  564. struct list_head head;
  565. char *name;
  566. /**
  567. * @mutex:
  568. *
  569. * This provides a read lock for the overall crtc state (mode, dpms
  570. * state, ...) and a write lock for everything which can be update
  571. * without a full modeset (fb, cursor data, crtc properties ...). Full
  572. * modeset also need to grab dev->mode_config.connection_mutex.
  573. */
  574. struct drm_modeset_lock mutex;
  575. struct drm_mode_object base;
  576. /* primary and cursor planes for CRTC */
  577. struct drm_plane *primary;
  578. struct drm_plane *cursor;
  579. /**
  580. * @index: Position inside the mode_config.list, can be used as an array
  581. * index. It is invariant over the lifetime of the CRTC.
  582. */
  583. unsigned index;
  584. /* position of cursor plane on crtc */
  585. int cursor_x;
  586. int cursor_y;
  587. bool enabled;
  588. /* Requested mode from modesetting. */
  589. struct drm_display_mode mode;
  590. /* Programmed mode in hw, after adjustments for encoders,
  591. * crtc, panel scaling etc. Needed for timestamping etc.
  592. */
  593. struct drm_display_mode hwmode;
  594. int x, y;
  595. const struct drm_crtc_funcs *funcs;
  596. /* Legacy FB CRTC gamma size for reporting to userspace */
  597. uint32_t gamma_size;
  598. uint16_t *gamma_store;
  599. /* if you are using the helper */
  600. const struct drm_crtc_helper_funcs *helper_private;
  601. struct drm_object_properties properties;
  602. /**
  603. * @state:
  604. *
  605. * Current atomic state for this CRTC.
  606. */
  607. struct drm_crtc_state *state;
  608. /**
  609. * @commit_list:
  610. *
  611. * List of &drm_crtc_commit structures tracking pending commits.
  612. * Protected by @commit_lock. This list doesn't hold its own full
  613. * reference, but burrows it from the ongoing commit. Commit entries
  614. * must be removed from this list once the commit is fully completed,
  615. * but before it's correspoding &drm_atomic_state gets destroyed.
  616. */
  617. struct list_head commit_list;
  618. /**
  619. * @commit_lock:
  620. *
  621. * Spinlock to protect @commit_list.
  622. */
  623. spinlock_t commit_lock;
  624. /**
  625. * @acquire_ctx:
  626. *
  627. * Per-CRTC implicit acquire context used by atomic drivers for legacy
  628. * IOCTLs, so that atomic drivers can get at the locking acquire
  629. * context.
  630. */
  631. struct drm_modeset_acquire_ctx *acquire_ctx;
  632. };
  633. /**
  634. * struct drm_mode_set - new values for a CRTC config change
  635. * @fb: framebuffer to use for new config
  636. * @crtc: CRTC whose configuration we're about to change
  637. * @mode: mode timings to use
  638. * @x: position of this CRTC relative to @fb
  639. * @y: position of this CRTC relative to @fb
  640. * @connectors: array of connectors to drive with this CRTC if possible
  641. * @num_connectors: size of @connectors array
  642. *
  643. * Represents a single crtc the connectors that it drives with what mode
  644. * and from which framebuffer it scans out from.
  645. *
  646. * This is used to set modes.
  647. */
  648. struct drm_mode_set {
  649. struct drm_framebuffer *fb;
  650. struct drm_crtc *crtc;
  651. struct drm_display_mode *mode;
  652. uint32_t x;
  653. uint32_t y;
  654. struct drm_connector **connectors;
  655. size_t num_connectors;
  656. };
  657. /**
  658. * struct drm_mode_config_funcs - basic driver provided mode setting functions
  659. *
  660. * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
  661. * involve drivers.
  662. */
  663. struct drm_mode_config_funcs {
  664. /**
  665. * @fb_create:
  666. *
  667. * Create a new framebuffer object. The core does basic checks on the
  668. * requested metadata, but most of that is left to the driver. See
  669. * struct &drm_mode_fb_cmd2 for details.
  670. *
  671. * If the parameters are deemed valid and the backing storage objects in
  672. * the underlying memory manager all exist, then the driver allocates
  673. * a new &drm_framebuffer structure, subclassed to contain
  674. * driver-specific information (like the internal native buffer object
  675. * references). It also needs to fill out all relevant metadata, which
  676. * should be done by calling drm_helper_mode_fill_fb_struct().
  677. *
  678. * The initialization is finalized by calling drm_framebuffer_init(),
  679. * which registers the framebuffer and makes it accessible to other
  680. * threads.
  681. *
  682. * RETURNS:
  683. *
  684. * A new framebuffer with an initial reference count of 1 or a negative
  685. * error code encoded with ERR_PTR().
  686. */
  687. struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
  688. struct drm_file *file_priv,
  689. const struct drm_mode_fb_cmd2 *mode_cmd);
  690. /**
  691. * @output_poll_changed:
  692. *
  693. * Callback used by helpers to inform the driver of output configuration
  694. * changes.
  695. *
  696. * Drivers implementing fbdev emulation with the helpers can call
  697. * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
  698. * helper of output changes.
  699. *
  700. * FIXME:
  701. *
  702. * Except that there's no vtable for device-level helper callbacks
  703. * there's no reason this is a core function.
  704. */
  705. void (*output_poll_changed)(struct drm_device *dev);
  706. /**
  707. * @atomic_check:
  708. *
  709. * This is the only hook to validate an atomic modeset update. This
  710. * function must reject any modeset and state changes which the hardware
  711. * or driver doesn't support. This includes but is of course not limited
  712. * to:
  713. *
  714. * - Checking that the modes, framebuffers, scaling and placement
  715. * requirements and so on are within the limits of the hardware.
  716. *
  717. * - Checking that any hidden shared resources are not oversubscribed.
  718. * This can be shared PLLs, shared lanes, overall memory bandwidth,
  719. * display fifo space (where shared between planes or maybe even
  720. * CRTCs).
  721. *
  722. * - Checking that virtualized resources exported to userspace are not
  723. * oversubscribed. For various reasons it can make sense to expose
  724. * more planes, crtcs or encoders than which are physically there. One
  725. * example is dual-pipe operations (which generally should be hidden
  726. * from userspace if when lockstepped in hardware, exposed otherwise),
  727. * where a plane might need 1 hardware plane (if it's just on one
  728. * pipe), 2 hardware planes (when it spans both pipes) or maybe even
  729. * shared a hardware plane with a 2nd plane (if there's a compatible
  730. * plane requested on the area handled by the other pipe).
  731. *
  732. * - Check that any transitional state is possible and that if
  733. * requested, the update can indeed be done in the vblank period
  734. * without temporarily disabling some functions.
  735. *
  736. * - Check any other constraints the driver or hardware might have.
  737. *
  738. * - This callback also needs to correctly fill out the &drm_crtc_state
  739. * in this update to make sure that drm_atomic_crtc_needs_modeset()
  740. * reflects the nature of the possible update and returns true if and
  741. * only if the update cannot be applied without tearing within one
  742. * vblank on that CRTC. The core uses that information to reject
  743. * updates which require a full modeset (i.e. blanking the screen, or
  744. * at least pausing updates for a substantial amount of time) if
  745. * userspace has disallowed that in its request.
  746. *
  747. * - The driver also does not need to repeat basic input validation
  748. * like done for the corresponding legacy entry points. The core does
  749. * that before calling this hook.
  750. *
  751. * See the documentation of @atomic_commit for an exhaustive list of
  752. * error conditions which don't have to be checked at the
  753. * ->atomic_check() stage?
  754. *
  755. * See the documentation for struct &drm_atomic_state for how exactly
  756. * an atomic modeset update is described.
  757. *
  758. * Drivers using the atomic helpers can implement this hook using
  759. * drm_atomic_helper_check(), or one of the exported sub-functions of
  760. * it.
  761. *
  762. * RETURNS:
  763. *
  764. * 0 on success or one of the below negative error codes:
  765. *
  766. * - -EINVAL, if any of the above constraints are violated.
  767. *
  768. * - -EDEADLK, when returned from an attempt to acquire an additional
  769. * &drm_modeset_lock through drm_modeset_lock().
  770. *
  771. * - -ENOMEM, if allocating additional state sub-structures failed due
  772. * to lack of memory.
  773. *
  774. * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
  775. * This can either be due to a pending signal, or because the driver
  776. * needs to completely bail out to recover from an exceptional
  777. * situation like a GPU hang. From a userspace point all errors are
  778. * treated equally.
  779. */
  780. int (*atomic_check)(struct drm_device *dev,
  781. struct drm_atomic_state *state);
  782. /**
  783. * @atomic_commit:
  784. *
  785. * This is the only hook to commit an atomic modeset update. The core
  786. * guarantees that @atomic_check has been called successfully before
  787. * calling this function, and that nothing has been changed in the
  788. * interim.
  789. *
  790. * See the documentation for struct &drm_atomic_state for how exactly
  791. * an atomic modeset update is described.
  792. *
  793. * Drivers using the atomic helpers can implement this hook using
  794. * drm_atomic_helper_commit(), or one of the exported sub-functions of
  795. * it.
  796. *
  797. * Nonblocking commits (as indicated with the nonblock parameter) must
  798. * do any preparatory work which might result in an unsuccessful commit
  799. * in the context of this callback. The only exceptions are hardware
  800. * errors resulting in -EIO. But even in that case the driver must
  801. * ensure that the display pipe is at least running, to avoid
  802. * compositors crashing when pageflips don't work. Anything else,
  803. * specifically committing the update to the hardware, should be done
  804. * without blocking the caller. For updates which do not require a
  805. * modeset this must be guaranteed.
  806. *
  807. * The driver must wait for any pending rendering to the new
  808. * framebuffers to complete before executing the flip. It should also
  809. * wait for any pending rendering from other drivers if the underlying
  810. * buffer is a shared dma-buf. Nonblocking commits must not wait for
  811. * rendering in the context of this callback.
  812. *
  813. * An application can request to be notified when the atomic commit has
  814. * completed. These events are per-CRTC and can be distinguished by the
  815. * CRTC index supplied in &drm_event to userspace.
  816. *
  817. * The drm core will supply a struct &drm_event in the event
  818. * member of each CRTC's &drm_crtc_state structure. See the
  819. * documentation for &drm_crtc_state for more details about the precise
  820. * semantics of this event.
  821. *
  822. * NOTE:
  823. *
  824. * Drivers are not allowed to shut down any display pipe successfully
  825. * enabled through an atomic commit on their own. Doing so can result in
  826. * compositors crashing if a page flip is suddenly rejected because the
  827. * pipe is off.
  828. *
  829. * RETURNS:
  830. *
  831. * 0 on success or one of the below negative error codes:
  832. *
  833. * - -EBUSY, if a nonblocking updated is requested and there is
  834. * an earlier updated pending. Drivers are allowed to support a queue
  835. * of outstanding updates, but currently no driver supports that.
  836. * Note that drivers must wait for preceding updates to complete if a
  837. * synchronous update is requested, they are not allowed to fail the
  838. * commit in that case.
  839. *
  840. * - -ENOMEM, if the driver failed to allocate memory. Specifically
  841. * this can happen when trying to pin framebuffers, which must only
  842. * be done when committing the state.
  843. *
  844. * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
  845. * that the driver has run out of vram, iommu space or similar GPU
  846. * address space needed for framebuffer.
  847. *
  848. * - -EIO, if the hardware completely died.
  849. *
  850. * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
  851. * This can either be due to a pending signal, or because the driver
  852. * needs to completely bail out to recover from an exceptional
  853. * situation like a GPU hang. From a userspace point of view all errors are
  854. * treated equally.
  855. *
  856. * This list is exhaustive. Specifically this hook is not allowed to
  857. * return -EINVAL (any invalid requests should be caught in
  858. * @atomic_check) or -EDEADLK (this function must not acquire
  859. * additional modeset locks).
  860. */
  861. int (*atomic_commit)(struct drm_device *dev,
  862. struct drm_atomic_state *state,
  863. bool nonblock);
  864. /**
  865. * @atomic_state_alloc:
  866. *
  867. * This optional hook can be used by drivers that want to subclass struct
  868. * &drm_atomic_state to be able to track their own driver-private global
  869. * state easily. If this hook is implemented, drivers must also
  870. * implement @atomic_state_clear and @atomic_state_free.
  871. *
  872. * RETURNS:
  873. *
  874. * A new &drm_atomic_state on success or NULL on failure.
  875. */
  876. struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
  877. /**
  878. * @atomic_state_clear:
  879. *
  880. * This hook must clear any driver private state duplicated into the
  881. * passed-in &drm_atomic_state. This hook is called when the caller
  882. * encountered a &drm_modeset_lock deadlock and needs to drop all
  883. * already acquired locks as part of the deadlock avoidance dance
  884. * implemented in drm_modeset_lock_backoff().
  885. *
  886. * Any duplicated state must be invalidated since a concurrent atomic
  887. * update might change it, and the drm atomic interfaces always apply
  888. * updates as relative changes to the current state.
  889. *
  890. * Drivers that implement this must call drm_atomic_state_default_clear()
  891. * to clear common state.
  892. */
  893. void (*atomic_state_clear)(struct drm_atomic_state *state);
  894. /**
  895. * @atomic_state_free:
  896. *
  897. * This hook needs driver private resources and the &drm_atomic_state
  898. * itself. Note that the core first calls drm_atomic_state_clear() to
  899. * avoid code duplicate between the clear and free hooks.
  900. *
  901. * Drivers that implement this must call drm_atomic_state_default_free()
  902. * to release common resources.
  903. */
  904. void (*atomic_state_free)(struct drm_atomic_state *state);
  905. };
  906. /**
  907. * struct drm_mode_config - Mode configuration control structure
  908. * @mutex: mutex protecting KMS related lists and structures
  909. * @connection_mutex: ww mutex protecting connector state and routing
  910. * @acquire_ctx: global implicit acquire context used by atomic drivers for
  911. * legacy IOCTLs
  912. * @fb_lock: mutex to protect fb state and lists
  913. * @num_fb: number of fbs available
  914. * @fb_list: list of framebuffers available
  915. * @num_encoder: number of encoders on this device
  916. * @encoder_list: list of encoder objects
  917. * @num_overlay_plane: number of overlay planes on this device
  918. * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
  919. * @plane_list: list of plane objects
  920. * @num_crtc: number of CRTCs on this device
  921. * @crtc_list: list of CRTC objects
  922. * @property_list: list of property objects
  923. * @min_width: minimum pixel width on this device
  924. * @min_height: minimum pixel height on this device
  925. * @max_width: maximum pixel width on this device
  926. * @max_height: maximum pixel height on this device
  927. * @funcs: core driver provided mode setting functions
  928. * @fb_base: base address of the framebuffer
  929. * @poll_enabled: track polling support for this device
  930. * @poll_running: track polling status for this device
  931. * @delayed_event: track delayed poll uevent deliver for this device
  932. * @output_poll_work: delayed work for polling in process context
  933. * @property_blob_list: list of all the blob property objects
  934. * @blob_lock: mutex for blob property allocation and management
  935. * @*_property: core property tracking
  936. * @preferred_depth: preferred RBG pixel depth, used by fb helpers
  937. * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
  938. * @cursor_width: hint to userspace for max cursor width
  939. * @cursor_height: hint to userspace for max cursor height
  940. * @helper_private: mid-layer private data
  941. *
  942. * Core mode resource tracking structure. All CRTC, encoders, and connectors
  943. * enumerated by the driver are added here, as are global properties. Some
  944. * global restrictions are also here, e.g. dimension restrictions.
  945. */
  946. struct drm_mode_config {
  947. struct mutex mutex; /* protects configuration (mode lists etc.) */
  948. struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
  949. struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
  950. /**
  951. * @idr_mutex:
  952. *
  953. * Mutex for KMS ID allocation and management. Protects both @crtc_idr
  954. * and @tile_idr.
  955. */
  956. struct mutex idr_mutex;
  957. /**
  958. * @crtc_idr:
  959. *
  960. * Main KMS ID tracking object. Use this idr for all IDs, fb, crtc,
  961. * connector, modes - just makes life easier to have only one.
  962. */
  963. struct idr crtc_idr;
  964. /**
  965. * @tile_idr:
  966. *
  967. * Use this idr for allocating new IDs for tiled sinks like use in some
  968. * high-res DP MST screens.
  969. */
  970. struct idr tile_idr;
  971. struct mutex fb_lock; /* proctects global and per-file fb lists */
  972. int num_fb;
  973. struct list_head fb_list;
  974. /**
  975. * @num_connector: Number of connectors on this device.
  976. */
  977. int num_connector;
  978. /**
  979. * @connector_ida: ID allocator for connector indices.
  980. */
  981. struct ida connector_ida;
  982. /**
  983. * @connector_list: List of connector objects.
  984. */
  985. struct list_head connector_list;
  986. int num_encoder;
  987. struct list_head encoder_list;
  988. /*
  989. * Track # of overlay planes separately from # of total planes. By
  990. * default we only advertise overlay planes to userspace; if userspace
  991. * sets the "universal plane" capability bit, we'll go ahead and
  992. * expose all planes.
  993. */
  994. int num_overlay_plane;
  995. int num_total_plane;
  996. struct list_head plane_list;
  997. int num_crtc;
  998. struct list_head crtc_list;
  999. struct list_head property_list;
  1000. int min_width, min_height;
  1001. int max_width, max_height;
  1002. const struct drm_mode_config_funcs *funcs;
  1003. resource_size_t fb_base;
  1004. /* output poll support */
  1005. bool poll_enabled;
  1006. bool poll_running;
  1007. bool delayed_event;
  1008. struct delayed_work output_poll_work;
  1009. struct mutex blob_lock;
  1010. /* pointers to standard properties */
  1011. struct list_head property_blob_list;
  1012. /**
  1013. * @edid_property: Default connector property to hold the EDID of the
  1014. * currently connected sink, if any.
  1015. */
  1016. struct drm_property *edid_property;
  1017. /**
  1018. * @dpms_property: Default connector property to control the
  1019. * connector's DPMS state.
  1020. */
  1021. struct drm_property *dpms_property;
  1022. /**
  1023. * @path_property: Default connector property to hold the DP MST path
  1024. * for the port.
  1025. */
  1026. struct drm_property *path_property;
  1027. /**
  1028. * @tile_property: Default connector property to store the tile
  1029. * position of a tiled screen, for sinks which need to be driven with
  1030. * multiple CRTCs.
  1031. */
  1032. struct drm_property *tile_property;
  1033. /**
  1034. * @plane_type_property: Default plane property to differentiate
  1035. * CURSOR, PRIMARY and OVERLAY legacy uses of planes.
  1036. */
  1037. struct drm_property *plane_type_property;
  1038. /**
  1039. * @rotation_property: Optional property for planes or CRTCs to specifiy
  1040. * rotation.
  1041. */
  1042. struct drm_property *rotation_property;
  1043. /**
  1044. * @prop_src_x: Default atomic plane property for the plane source
  1045. * position in the connected &drm_framebuffer.
  1046. */
  1047. struct drm_property *prop_src_x;
  1048. /**
  1049. * @prop_src_y: Default atomic plane property for the plane source
  1050. * position in the connected &drm_framebuffer.
  1051. */
  1052. struct drm_property *prop_src_y;
  1053. /**
  1054. * @prop_src_w: Default atomic plane property for the plane source
  1055. * position in the connected &drm_framebuffer.
  1056. */
  1057. struct drm_property *prop_src_w;
  1058. /**
  1059. * @prop_src_h: Default atomic plane property for the plane source
  1060. * position in the connected &drm_framebuffer.
  1061. */
  1062. struct drm_property *prop_src_h;
  1063. /**
  1064. * @prop_crtc_x: Default atomic plane property for the plane destination
  1065. * position in the &drm_crtc is is being shown on.
  1066. */
  1067. struct drm_property *prop_crtc_x;
  1068. /**
  1069. * @prop_crtc_y: Default atomic plane property for the plane destination
  1070. * position in the &drm_crtc is is being shown on.
  1071. */
  1072. struct drm_property *prop_crtc_y;
  1073. /**
  1074. * @prop_crtc_w: Default atomic plane property for the plane destination
  1075. * position in the &drm_crtc is is being shown on.
  1076. */
  1077. struct drm_property *prop_crtc_w;
  1078. /**
  1079. * @prop_crtc_h: Default atomic plane property for the plane destination
  1080. * position in the &drm_crtc is is being shown on.
  1081. */
  1082. struct drm_property *prop_crtc_h;
  1083. /**
  1084. * @prop_fb_id: Default atomic plane property to specify the
  1085. * &drm_framebuffer.
  1086. */
  1087. struct drm_property *prop_fb_id;
  1088. /**
  1089. * @prop_crtc_id: Default atomic plane property to specify the
  1090. * &drm_crtc.
  1091. */
  1092. struct drm_property *prop_crtc_id;
  1093. /**
  1094. * @prop_active: Default atomic CRTC property to control the active
  1095. * state, which is the simplified implementation for DPMS in atomic
  1096. * drivers.
  1097. */
  1098. struct drm_property *prop_active;
  1099. /**
  1100. * @prop_mode_id: Default atomic CRTC property to set the mode for a
  1101. * CRTC. A 0 mode implies that the CRTC is entirely disabled - all
  1102. * connectors must be of and active must be set to disabled, too.
  1103. */
  1104. struct drm_property *prop_mode_id;
  1105. /**
  1106. * @dvi_i_subconnector_property: Optional DVI-I property to
  1107. * differentiate between analog or digital mode.
  1108. */
  1109. struct drm_property *dvi_i_subconnector_property;
  1110. /**
  1111. * @dvi_i_select_subconnector_property: Optional DVI-I property to
  1112. * select between analog or digital mode.
  1113. */
  1114. struct drm_property *dvi_i_select_subconnector_property;
  1115. /**
  1116. * @tv_subconnector_property: Optional TV property to differentiate
  1117. * between different TV connector types.
  1118. */
  1119. struct drm_property *tv_subconnector_property;
  1120. /**
  1121. * @tv_select_subconnector_property: Optional TV property to select
  1122. * between different TV connector types.
  1123. */
  1124. struct drm_property *tv_select_subconnector_property;
  1125. /**
  1126. * @tv_mode_property: Optional TV property to select
  1127. * the output TV mode.
  1128. */
  1129. struct drm_property *tv_mode_property;
  1130. /**
  1131. * @tv_left_margin_property: Optional TV property to set the left
  1132. * margin.
  1133. */
  1134. struct drm_property *tv_left_margin_property;
  1135. /**
  1136. * @tv_right_margin_property: Optional TV property to set the right
  1137. * margin.
  1138. */
  1139. struct drm_property *tv_right_margin_property;
  1140. /**
  1141. * @tv_top_margin_property: Optional TV property to set the right
  1142. * margin.
  1143. */
  1144. struct drm_property *tv_top_margin_property;
  1145. /**
  1146. * @tv_bottom_margin_property: Optional TV property to set the right
  1147. * margin.
  1148. */
  1149. struct drm_property *tv_bottom_margin_property;
  1150. /**
  1151. * @tv_brightness_property: Optional TV property to set the
  1152. * brightness.
  1153. */
  1154. struct drm_property *tv_brightness_property;
  1155. /**
  1156. * @tv_contrast_property: Optional TV property to set the
  1157. * contrast.
  1158. */
  1159. struct drm_property *tv_contrast_property;
  1160. /**
  1161. * @tv_flicker_reduction_property: Optional TV property to control the
  1162. * flicker reduction mode.
  1163. */
  1164. struct drm_property *tv_flicker_reduction_property;
  1165. /**
  1166. * @tv_overscan_property: Optional TV property to control the overscan
  1167. * setting.
  1168. */
  1169. struct drm_property *tv_overscan_property;
  1170. /**
  1171. * @tv_saturation_property: Optional TV property to set the
  1172. * saturation.
  1173. */
  1174. struct drm_property *tv_saturation_property;
  1175. /**
  1176. * @tv_hue_property: Optional TV property to set the hue.
  1177. */
  1178. struct drm_property *tv_hue_property;
  1179. /**
  1180. * @scaling_mode_property: Optional connector property to control the
  1181. * upscaling, mostly used for built-in panels.
  1182. */
  1183. struct drm_property *scaling_mode_property;
  1184. /**
  1185. * @aspect_ratio_property: Optional connector property to control the
  1186. * HDMI infoframe aspect ratio setting.
  1187. */
  1188. struct drm_property *aspect_ratio_property;
  1189. /**
  1190. * @degamma_lut_property: Optional CRTC property to set the LUT used to
  1191. * convert the framebuffer's colors to linear gamma.
  1192. */
  1193. struct drm_property *degamma_lut_property;
  1194. /**
  1195. * @degamma_lut_size_property: Optional CRTC property for the size of
  1196. * the degamma LUT as supported by the driver (read-only).
  1197. */
  1198. struct drm_property *degamma_lut_size_property;
  1199. /**
  1200. * @ctm_property: Optional CRTC property to set the
  1201. * matrix used to convert colors after the lookup in the
  1202. * degamma LUT.
  1203. */
  1204. struct drm_property *ctm_property;
  1205. /**
  1206. * @gamma_lut_property: Optional CRTC property to set the LUT used to
  1207. * convert the colors, after the CTM matrix, to the gamma space of the
  1208. * connected screen.
  1209. */
  1210. struct drm_property *gamma_lut_property;
  1211. /**
  1212. * @gamma_lut_size_property: Optional CRTC property for the size of the
  1213. * gamma LUT as supported by the driver (read-only).
  1214. */
  1215. struct drm_property *gamma_lut_size_property;
  1216. /**
  1217. * @suggested_x_property: Optional connector property with a hint for
  1218. * the position of the output on the host's screen.
  1219. */
  1220. struct drm_property *suggested_x_property;
  1221. /**
  1222. * @suggested_y_property: Optional connector property with a hint for
  1223. * the position of the output on the host's screen.
  1224. */
  1225. struct drm_property *suggested_y_property;
  1226. /* dumb ioctl parameters */
  1227. uint32_t preferred_depth, prefer_shadow;
  1228. /**
  1229. * @async_page_flip: Does this device support async flips on the primary
  1230. * plane?
  1231. */
  1232. bool async_page_flip;
  1233. /**
  1234. * @allow_fb_modifiers:
  1235. *
  1236. * Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call.
  1237. */
  1238. bool allow_fb_modifiers;
  1239. /* cursor size */
  1240. uint32_t cursor_width, cursor_height;
  1241. struct drm_mode_config_helper_funcs *helper_private;
  1242. };
  1243. #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
  1244. extern __printf(6, 7)
  1245. int drm_crtc_init_with_planes(struct drm_device *dev,
  1246. struct drm_crtc *crtc,
  1247. struct drm_plane *primary,
  1248. struct drm_plane *cursor,
  1249. const struct drm_crtc_funcs *funcs,
  1250. const char *name, ...);
  1251. extern void drm_crtc_cleanup(struct drm_crtc *crtc);
  1252. /**
  1253. * drm_crtc_index - find the index of a registered CRTC
  1254. * @crtc: CRTC to find index for
  1255. *
  1256. * Given a registered CRTC, return the index of that CRTC within a DRM
  1257. * device's list of CRTCs.
  1258. */
  1259. static inline unsigned int drm_crtc_index(const struct drm_crtc *crtc)
  1260. {
  1261. return crtc->index;
  1262. }
  1263. /**
  1264. * drm_crtc_mask - find the mask of a registered CRTC
  1265. * @crtc: CRTC to find mask for
  1266. *
  1267. * Given a registered CRTC, return the mask bit of that CRTC for an
  1268. * encoder's possible_crtcs field.
  1269. */
  1270. static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
  1271. {
  1272. return 1 << drm_crtc_index(crtc);
  1273. }
  1274. extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
  1275. int *hdisplay, int *vdisplay);
  1276. extern int drm_crtc_force_disable(struct drm_crtc *crtc);
  1277. extern int drm_crtc_force_disable_all(struct drm_device *dev);
  1278. extern void drm_mode_config_init(struct drm_device *dev);
  1279. extern void drm_mode_config_reset(struct drm_device *dev);
  1280. extern void drm_mode_config_cleanup(struct drm_device *dev);
  1281. extern int drm_mode_set_config_internal(struct drm_mode_set *set);
  1282. extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
  1283. char topology[8]);
  1284. extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
  1285. char topology[8]);
  1286. extern void drm_mode_put_tile_group(struct drm_device *dev,
  1287. struct drm_tile_group *tg);
  1288. /* Helpers */
  1289. static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
  1290. uint32_t id)
  1291. {
  1292. struct drm_mode_object *mo;
  1293. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
  1294. return mo ? obj_to_crtc(mo) : NULL;
  1295. }
  1296. #define drm_for_each_crtc(crtc, dev) \
  1297. list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
  1298. static inline void
  1299. assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
  1300. {
  1301. /*
  1302. * The connector hotadd/remove code currently grabs both locks when
  1303. * updating lists. Hence readers need only hold either of them to be
  1304. * safe and the check amounts to
  1305. *
  1306. * WARN_ON(not_holding(A) && not_holding(B)).
  1307. */
  1308. WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
  1309. !drm_modeset_is_locked(&mode_config->connection_mutex));
  1310. }
  1311. #endif /* __DRM_CRTC_H__ */