drm_plane.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992
  1. /*
  2. * Copyright (c) 2016 Intel Corporation
  3. *
  4. * Permission to use, copy, modify, distribute, and sell this software and its
  5. * documentation for any purpose is hereby granted without fee, provided that
  6. * the above copyright notice appear in all copies and that both that copyright
  7. * notice and this permission notice appear in supporting documentation, and
  8. * that the name of the copyright holders not be used in advertising or
  9. * publicity pertaining to distribution of the software without specific,
  10. * written prior permission. The copyright holders make no representations
  11. * about the suitability of this software for any purpose. It is provided "as
  12. * is" without express or implied warranty.
  13. *
  14. * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  16. * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  19. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  20. * OF THIS SOFTWARE.
  21. */
  22. #ifndef __DRM_PLANE_H__
  23. #define __DRM_PLANE_H__
  24. #include <linux/list.h>
  25. #include <linux/ctype.h>
  26. #include <linux/kmsg_dump.h>
  27. #include <drm/drm_mode_object.h>
  28. #include <drm/drm_color_mgmt.h>
  29. #include <drm/drm_rect.h>
  30. #include <drm/drm_modeset_lock.h>
  31. #include <drm/drm_util.h>
  32. struct drm_crtc;
  33. struct drm_plane_size_hint;
  34. struct drm_printer;
  35. struct drm_modeset_acquire_ctx;
  36. enum drm_scaling_filter {
  37. DRM_SCALING_FILTER_DEFAULT,
  38. DRM_SCALING_FILTER_NEAREST_NEIGHBOR,
  39. };
  40. /**
  41. * struct drm_plane_state - mutable plane state
  42. *
  43. * Please note that the destination coordinates @crtc_x, @crtc_y, @crtc_h and
  44. * @crtc_w and the source coordinates @src_x, @src_y, @src_h and @src_w are the
  45. * raw coordinates provided by userspace. Drivers should use
  46. * drm_atomic_helper_check_plane_state() and only use the derived rectangles in
  47. * @src and @dst to program the hardware.
  48. */
  49. struct drm_plane_state {
  50. /** @plane: backpointer to the plane */
  51. struct drm_plane *plane;
  52. /**
  53. * @crtc:
  54. *
  55. * Currently bound CRTC, NULL if disabled. Do not write this directly,
  56. * use drm_atomic_set_crtc_for_plane()
  57. */
  58. struct drm_crtc *crtc;
  59. /**
  60. * @fb:
  61. *
  62. * Currently bound framebuffer. Do not write this directly, use
  63. * drm_atomic_set_fb_for_plane()
  64. */
  65. struct drm_framebuffer *fb;
  66. /**
  67. * @fence:
  68. *
  69. * Optional fence to wait for before scanning out @fb. The core atomic
  70. * code will set this when userspace is using explicit fencing. Do not
  71. * write this field directly for a driver's implicit fence.
  72. *
  73. * Drivers should store any implicit fence in this from their
  74. * &drm_plane_helper_funcs.prepare_fb callback. See
  75. * drm_gem_plane_helper_prepare_fb() for a suitable helper.
  76. */
  77. struct dma_fence *fence;
  78. /**
  79. * @crtc_x:
  80. *
  81. * Left position of visible portion of plane on crtc, signed dest
  82. * location allows it to be partially off screen.
  83. */
  84. int32_t crtc_x;
  85. /**
  86. * @crtc_y:
  87. *
  88. * Upper position of visible portion of plane on crtc, signed dest
  89. * location allows it to be partially off screen.
  90. */
  91. int32_t crtc_y;
  92. /** @crtc_w: width of visible portion of plane on crtc */
  93. /** @crtc_h: height of visible portion of plane on crtc */
  94. uint32_t crtc_w, crtc_h;
  95. /**
  96. * @src_x: left position of visible portion of plane within plane (in
  97. * 16.16 fixed point).
  98. */
  99. uint32_t src_x;
  100. /**
  101. * @src_y: upper position of visible portion of plane within plane (in
  102. * 16.16 fixed point).
  103. */
  104. uint32_t src_y;
  105. /** @src_w: width of visible portion of plane (in 16.16) */
  106. /** @src_h: height of visible portion of plane (in 16.16) */
  107. uint32_t src_h, src_w;
  108. /** @hotspot_x: x offset to mouse cursor hotspot */
  109. /** @hotspot_y: y offset to mouse cursor hotspot */
  110. int32_t hotspot_x, hotspot_y;
  111. /**
  112. * @alpha:
  113. * Opacity of the plane with 0 as completely transparent and 0xffff as
  114. * completely opaque. See drm_plane_create_alpha_property() for more
  115. * details.
  116. */
  117. u16 alpha;
  118. /**
  119. * @pixel_blend_mode:
  120. * The alpha blending equation selection, describing how the pixels from
  121. * the current plane are composited with the background. Value can be
  122. * one of DRM_MODE_BLEND_*
  123. */
  124. uint16_t pixel_blend_mode;
  125. /**
  126. * @rotation:
  127. * Rotation of the plane. See drm_plane_create_rotation_property() for
  128. * more details.
  129. */
  130. unsigned int rotation;
  131. /**
  132. * @zpos:
  133. * Priority of the given plane on crtc (optional).
  134. *
  135. * User-space may set mutable zpos properties so that multiple active
  136. * planes on the same CRTC have identical zpos values. This is a
  137. * user-space bug, but drivers can solve the conflict by comparing the
  138. * plane object IDs; the plane with a higher ID is stacked on top of a
  139. * plane with a lower ID.
  140. *
  141. * See drm_plane_create_zpos_property() and
  142. * drm_plane_create_zpos_immutable_property() for more details.
  143. */
  144. unsigned int zpos;
  145. /**
  146. * @normalized_zpos:
  147. * Normalized value of zpos: unique, range from 0 to N-1 where N is the
  148. * number of active planes for given crtc. Note that the driver must set
  149. * &drm_mode_config.normalize_zpos or call drm_atomic_normalize_zpos() to
  150. * update this before it can be trusted.
  151. */
  152. unsigned int normalized_zpos;
  153. /**
  154. * @color_encoding:
  155. *
  156. * Color encoding for non RGB formats
  157. */
  158. enum drm_color_encoding color_encoding;
  159. /**
  160. * @color_range:
  161. *
  162. * Color range for non RGB formats
  163. */
  164. enum drm_color_range color_range;
  165. /**
  166. * @fb_damage_clips:
  167. *
  168. * Blob representing damage (area in plane framebuffer that changed
  169. * since last plane update) as an array of &drm_mode_rect in framebuffer
  170. * coodinates of the attached framebuffer. Note that unlike plane src,
  171. * damage clips are not in 16.16 fixed point.
  172. *
  173. * See drm_plane_get_damage_clips() and
  174. * drm_plane_get_damage_clips_count() for accessing these.
  175. */
  176. struct drm_property_blob *fb_damage_clips;
  177. /**
  178. * @ignore_damage_clips:
  179. *
  180. * Set by drivers to indicate the drm_atomic_helper_damage_iter_init()
  181. * helper that the @fb_damage_clips blob property should be ignored.
  182. *
  183. * See :ref:`damage_tracking_properties` for more information.
  184. */
  185. bool ignore_damage_clips;
  186. /**
  187. * @src:
  188. *
  189. * source coordinates of the plane (in 16.16).
  190. *
  191. * When using drm_atomic_helper_check_plane_state(),
  192. * the coordinates are clipped, but the driver may choose
  193. * to use unclipped coordinates instead when the hardware
  194. * performs the clipping automatically.
  195. */
  196. /**
  197. * @dst:
  198. *
  199. * clipped destination coordinates of the plane.
  200. *
  201. * When using drm_atomic_helper_check_plane_state(),
  202. * the coordinates are clipped, but the driver may choose
  203. * to use unclipped coordinates instead when the hardware
  204. * performs the clipping automatically.
  205. */
  206. struct drm_rect src, dst;
  207. /**
  208. * @visible:
  209. *
  210. * Visibility of the plane. This can be false even if fb!=NULL and
  211. * crtc!=NULL, due to clipping.
  212. */
  213. bool visible;
  214. /**
  215. * @scaling_filter:
  216. *
  217. * Scaling filter to be applied
  218. */
  219. enum drm_scaling_filter scaling_filter;
  220. /**
  221. * @commit: Tracks the pending commit to prevent use-after-free conditions,
  222. * and for async plane updates.
  223. *
  224. * May be NULL.
  225. */
  226. struct drm_crtc_commit *commit;
  227. /** @state: backpointer to global drm_atomic_state */
  228. struct drm_atomic_state *state;
  229. /**
  230. * @color_mgmt_changed: Color management properties have changed. Used
  231. * by the atomic helpers and drivers to steer the atomic commit control
  232. * flow.
  233. */
  234. bool color_mgmt_changed : 1;
  235. };
  236. static inline struct drm_rect
  237. drm_plane_state_src(const struct drm_plane_state *state)
  238. {
  239. struct drm_rect src = {
  240. .x1 = state->src_x,
  241. .y1 = state->src_y,
  242. .x2 = state->src_x + state->src_w,
  243. .y2 = state->src_y + state->src_h,
  244. };
  245. return src;
  246. }
  247. static inline struct drm_rect
  248. drm_plane_state_dest(const struct drm_plane_state *state)
  249. {
  250. struct drm_rect dest = {
  251. .x1 = state->crtc_x,
  252. .y1 = state->crtc_y,
  253. .x2 = state->crtc_x + state->crtc_w,
  254. .y2 = state->crtc_y + state->crtc_h,
  255. };
  256. return dest;
  257. }
  258. /**
  259. * struct drm_plane_funcs - driver plane control functions
  260. */
  261. struct drm_plane_funcs {
  262. /**
  263. * @update_plane:
  264. *
  265. * This is the legacy entry point to enable and configure the plane for
  266. * the given CRTC and framebuffer. It is never called to disable the
  267. * plane, i.e. the passed-in crtc and fb paramters are never NULL.
  268. *
  269. * The source rectangle in frame buffer memory coordinates is given by
  270. * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
  271. * values). Devices that don't support subpixel plane coordinates can
  272. * ignore the fractional part.
  273. *
  274. * The destination rectangle in CRTC coordinates is given by the
  275. * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
  276. * Devices scale the source rectangle to the destination rectangle. If
  277. * scaling is not supported, and the source rectangle size doesn't match
  278. * the destination rectangle size, the driver must return a
  279. * -<errorname>EINVAL</errorname> error.
  280. *
  281. * Drivers implementing atomic modeset should use
  282. * drm_atomic_helper_update_plane() to implement this hook.
  283. *
  284. * RETURNS:
  285. *
  286. * 0 on success or a negative error code on failure.
  287. */
  288. int (*update_plane)(struct drm_plane *plane,
  289. struct drm_crtc *crtc, struct drm_framebuffer *fb,
  290. int crtc_x, int crtc_y,
  291. unsigned int crtc_w, unsigned int crtc_h,
  292. uint32_t src_x, uint32_t src_y,
  293. uint32_t src_w, uint32_t src_h,
  294. struct drm_modeset_acquire_ctx *ctx);
  295. /**
  296. * @disable_plane:
  297. *
  298. * This is the legacy entry point to disable the plane. The DRM core
  299. * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
  300. * with the frame buffer ID set to 0. Disabled planes must not be
  301. * processed by the CRTC.
  302. *
  303. * Drivers implementing atomic modeset should use
  304. * drm_atomic_helper_disable_plane() to implement this hook.
  305. *
  306. * RETURNS:
  307. *
  308. * 0 on success or a negative error code on failure.
  309. */
  310. int (*disable_plane)(struct drm_plane *plane,
  311. struct drm_modeset_acquire_ctx *ctx);
  312. /**
  313. * @destroy:
  314. *
  315. * Clean up plane resources. This is only called at driver unload time
  316. * through drm_mode_config_cleanup() since a plane cannot be hotplugged
  317. * in DRM.
  318. */
  319. void (*destroy)(struct drm_plane *plane);
  320. /**
  321. * @reset:
  322. *
  323. * Reset plane hardware and software state to off. This function isn't
  324. * called by the core directly, only through drm_mode_config_reset().
  325. * It's not a helper hook only for historical reasons.
  326. *
  327. * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
  328. * atomic state using this hook.
  329. */
  330. void (*reset)(struct drm_plane *plane);
  331. /**
  332. * @set_property:
  333. *
  334. * This is the legacy entry point to update a property attached to the
  335. * plane.
  336. *
  337. * This callback is optional if the driver does not support any legacy
  338. * driver-private properties. For atomic drivers it is not used because
  339. * property handling is done entirely in the DRM core.
  340. *
  341. * RETURNS:
  342. *
  343. * 0 on success or a negative error code on failure.
  344. */
  345. int (*set_property)(struct drm_plane *plane,
  346. struct drm_property *property, uint64_t val);
  347. /**
  348. * @atomic_duplicate_state:
  349. *
  350. * Duplicate the current atomic state for this plane and return it.
  351. * The core and helpers guarantee that any atomic state duplicated with
  352. * this hook and still owned by the caller (i.e. not transferred to the
  353. * driver by calling &drm_mode_config_funcs.atomic_commit) will be
  354. * cleaned up by calling the @atomic_destroy_state hook in this
  355. * structure.
  356. *
  357. * This callback is mandatory for atomic drivers.
  358. *
  359. * Atomic drivers which don't subclass &struct drm_plane_state should use
  360. * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
  361. * state structure to extend it with driver-private state should use
  362. * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
  363. * duplicated in a consistent fashion across drivers.
  364. *
  365. * It is an error to call this hook before &drm_plane.state has been
  366. * initialized correctly.
  367. *
  368. * NOTE:
  369. *
  370. * If the duplicate state references refcounted resources this hook must
  371. * acquire a reference for each of them. The driver must release these
  372. * references again in @atomic_destroy_state.
  373. *
  374. * RETURNS:
  375. *
  376. * Duplicated atomic state or NULL when the allocation failed.
  377. */
  378. struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
  379. /**
  380. * @atomic_destroy_state:
  381. *
  382. * Destroy a state duplicated with @atomic_duplicate_state and release
  383. * or unreference all resources it references
  384. *
  385. * This callback is mandatory for atomic drivers.
  386. */
  387. void (*atomic_destroy_state)(struct drm_plane *plane,
  388. struct drm_plane_state *state);
  389. /**
  390. * @atomic_set_property:
  391. *
  392. * Decode a driver-private property value and store the decoded value
  393. * into the passed-in state structure. Since the atomic core decodes all
  394. * standardized properties (even for extensions beyond the core set of
  395. * properties which might not be implemented by all drivers) this
  396. * requires drivers to subclass the state structure.
  397. *
  398. * Such driver-private properties should really only be implemented for
  399. * truly hardware/vendor specific state. Instead it is preferred to
  400. * standardize atomic extension and decode the properties used to expose
  401. * such an extension in the core.
  402. *
  403. * Do not call this function directly, use
  404. * drm_atomic_plane_set_property() instead.
  405. *
  406. * This callback is optional if the driver does not support any
  407. * driver-private atomic properties.
  408. *
  409. * NOTE:
  410. *
  411. * This function is called in the state assembly phase of atomic
  412. * modesets, which can be aborted for any reason (including on
  413. * userspace's request to just check whether a configuration would be
  414. * possible). Drivers MUST NOT touch any persistent state (hardware or
  415. * software) or data structures except the passed in @state parameter.
  416. *
  417. * Also since userspace controls in which order properties are set this
  418. * function must not do any input validation (since the state update is
  419. * incomplete and hence likely inconsistent). Instead any such input
  420. * validation must be done in the various atomic_check callbacks.
  421. *
  422. * RETURNS:
  423. *
  424. * 0 if the property has been found, -EINVAL if the property isn't
  425. * implemented by the driver (which shouldn't ever happen, the core only
  426. * asks for properties attached to this plane). No other validation is
  427. * allowed by the driver. The core already checks that the property
  428. * value is within the range (integer, valid enum value, ...) the driver
  429. * set when registering the property.
  430. */
  431. int (*atomic_set_property)(struct drm_plane *plane,
  432. struct drm_plane_state *state,
  433. struct drm_property *property,
  434. uint64_t val);
  435. /**
  436. * @atomic_get_property:
  437. *
  438. * Reads out the decoded driver-private property. This is used to
  439. * implement the GETPLANE IOCTL.
  440. *
  441. * Do not call this function directly, use
  442. * drm_atomic_plane_get_property() instead.
  443. *
  444. * This callback is optional if the driver does not support any
  445. * driver-private atomic properties.
  446. *
  447. * RETURNS:
  448. *
  449. * 0 on success, -EINVAL if the property isn't implemented by the
  450. * driver (which should never happen, the core only asks for
  451. * properties attached to this plane).
  452. */
  453. int (*atomic_get_property)(struct drm_plane *plane,
  454. const struct drm_plane_state *state,
  455. struct drm_property *property,
  456. uint64_t *val);
  457. /**
  458. * @late_register:
  459. *
  460. * This optional hook can be used to register additional userspace
  461. * interfaces attached to the plane like debugfs interfaces.
  462. * It is called late in the driver load sequence from drm_dev_register().
  463. * Everything added from this callback should be unregistered in
  464. * the early_unregister callback.
  465. *
  466. * Returns:
  467. *
  468. * 0 on success, or a negative error code on failure.
  469. */
  470. int (*late_register)(struct drm_plane *plane);
  471. /**
  472. * @early_unregister:
  473. *
  474. * This optional hook should be used to unregister the additional
  475. * userspace interfaces attached to the plane from
  476. * @late_register. It is called from drm_dev_unregister(),
  477. * early in the driver unload sequence to disable userspace access
  478. * before data structures are torndown.
  479. */
  480. void (*early_unregister)(struct drm_plane *plane);
  481. /**
  482. * @atomic_print_state:
  483. *
  484. * If driver subclasses &struct drm_plane_state, it should implement
  485. * this optional hook for printing additional driver specific state.
  486. *
  487. * Do not call this directly, use drm_atomic_plane_print_state()
  488. * instead.
  489. */
  490. void (*atomic_print_state)(struct drm_printer *p,
  491. const struct drm_plane_state *state);
  492. /**
  493. * @format_mod_supported:
  494. *
  495. * This optional hook is used for the DRM to determine if the given
  496. * format/modifier combination is valid for the plane. This allows the
  497. * DRM to generate the correct format bitmask (which formats apply to
  498. * which modifier), and to validate modifiers at atomic_check time.
  499. *
  500. * If not present, then any modifier in the plane's modifier
  501. * list is allowed with any of the plane's formats.
  502. *
  503. * Returns:
  504. *
  505. * True if the given modifier is valid for that format on the plane.
  506. * False otherwise.
  507. */
  508. bool (*format_mod_supported)(struct drm_plane *plane, uint32_t format,
  509. uint64_t modifier);
  510. };
  511. /**
  512. * enum drm_plane_type - uapi plane type enumeration
  513. *
  514. * For historical reasons not all planes are made the same. This enumeration is
  515. * used to tell the different types of planes apart to implement the different
  516. * uapi semantics for them. For userspace which is universal plane aware and
  517. * which is using that atomic IOCTL there's no difference between these planes
  518. * (beyong what the driver and hardware can support of course).
  519. *
  520. * For compatibility with legacy userspace, only overlay planes are made
  521. * available to userspace by default. Userspace clients may set the
  522. * &DRM_CLIENT_CAP_UNIVERSAL_PLANES client capability bit to indicate that they
  523. * wish to receive a universal plane list containing all plane types. See also
  524. * drm_for_each_legacy_plane().
  525. *
  526. * In addition to setting each plane's type, drivers need to setup the
  527. * &drm_crtc.primary and optionally &drm_crtc.cursor pointers for legacy
  528. * IOCTLs. See drm_crtc_init_with_planes().
  529. *
  530. * WARNING: The values of this enum is UABI since they're exposed in the "type"
  531. * property.
  532. */
  533. enum drm_plane_type {
  534. /**
  535. * @DRM_PLANE_TYPE_OVERLAY:
  536. *
  537. * Overlay planes represent all non-primary, non-cursor planes. Some
  538. * drivers refer to these types of planes as "sprites" internally.
  539. */
  540. DRM_PLANE_TYPE_OVERLAY,
  541. /**
  542. * @DRM_PLANE_TYPE_PRIMARY:
  543. *
  544. * A primary plane attached to a CRTC is the most likely to be able to
  545. * light up the CRTC when no scaling/cropping is used and the plane
  546. * covers the whole CRTC.
  547. */
  548. DRM_PLANE_TYPE_PRIMARY,
  549. /**
  550. * @DRM_PLANE_TYPE_CURSOR:
  551. *
  552. * A cursor plane attached to a CRTC is more likely to be able to be
  553. * enabled when no scaling/cropping is used and the framebuffer has the
  554. * size indicated by &drm_mode_config.cursor_width and
  555. * &drm_mode_config.cursor_height. Additionally, if the driver doesn't
  556. * support modifiers, the framebuffer should have a linear layout.
  557. */
  558. DRM_PLANE_TYPE_CURSOR,
  559. };
  560. /**
  561. * struct drm_plane - central DRM plane control structure
  562. *
  563. * Planes represent the scanout hardware of a display block. They receive their
  564. * input data from a &drm_framebuffer and feed it to a &drm_crtc. Planes control
  565. * the color conversion, see `Plane Composition Properties`_ for more details,
  566. * and are also involved in the color conversion of input pixels, see `Color
  567. * Management Properties`_ for details on that.
  568. */
  569. struct drm_plane {
  570. /** @dev: DRM device this plane belongs to */
  571. struct drm_device *dev;
  572. /**
  573. * @head:
  574. *
  575. * List of all planes on @dev, linked from &drm_mode_config.plane_list.
  576. * Invariant over the lifetime of @dev and therefore does not need
  577. * locking.
  578. */
  579. struct list_head head;
  580. /** @name: human readable name, can be overwritten by the driver */
  581. char *name;
  582. /**
  583. * @mutex:
  584. *
  585. * Protects modeset plane state, together with the &drm_crtc.mutex of
  586. * CRTC this plane is linked to (when active, getting activated or
  587. * getting disabled).
  588. *
  589. * For atomic drivers specifically this protects @state.
  590. */
  591. struct drm_modeset_lock mutex;
  592. /** @base: base mode object */
  593. struct drm_mode_object base;
  594. /**
  595. * @possible_crtcs: pipes this plane can be bound to constructed from
  596. * drm_crtc_mask()
  597. */
  598. uint32_t possible_crtcs;
  599. /** @format_types: array of formats supported by this plane */
  600. uint32_t *format_types;
  601. /** @format_count: Size of the array pointed at by @format_types. */
  602. unsigned int format_count;
  603. /**
  604. * @format_default: driver hasn't supplied supported formats for the
  605. * plane. Used by the non-atomic driver compatibility wrapper only.
  606. */
  607. bool format_default;
  608. /** @modifiers: array of modifiers supported by this plane */
  609. uint64_t *modifiers;
  610. /** @modifier_count: Size of the array pointed at by @modifier_count. */
  611. unsigned int modifier_count;
  612. /**
  613. * @crtc:
  614. *
  615. * Currently bound CRTC, only meaningful for non-atomic drivers. For
  616. * atomic drivers this is forced to be NULL, atomic drivers should
  617. * instead check &drm_plane_state.crtc.
  618. */
  619. struct drm_crtc *crtc;
  620. /**
  621. * @fb:
  622. *
  623. * Currently bound framebuffer, only meaningful for non-atomic drivers.
  624. * For atomic drivers this is forced to be NULL, atomic drivers should
  625. * instead check &drm_plane_state.fb.
  626. */
  627. struct drm_framebuffer *fb;
  628. /**
  629. * @old_fb:
  630. *
  631. * Temporary tracking of the old fb while a modeset is ongoing. Only
  632. * used by non-atomic drivers, forced to be NULL for atomic drivers.
  633. */
  634. struct drm_framebuffer *old_fb;
  635. /** @funcs: plane control functions */
  636. const struct drm_plane_funcs *funcs;
  637. /** @properties: property tracking for this plane */
  638. struct drm_object_properties properties;
  639. /** @type: Type of plane, see &enum drm_plane_type for details. */
  640. enum drm_plane_type type;
  641. /**
  642. * @index: Position inside the mode_config.list, can be used as an array
  643. * index. It is invariant over the lifetime of the plane.
  644. */
  645. unsigned index;
  646. /** @helper_private: mid-layer private data */
  647. const struct drm_plane_helper_funcs *helper_private;
  648. /**
  649. * @state:
  650. *
  651. * Current atomic state for this plane.
  652. *
  653. * This is protected by @mutex. Note that nonblocking atomic commits
  654. * access the current plane state without taking locks. Either by going
  655. * through the &struct drm_atomic_state pointers, see
  656. * for_each_oldnew_plane_in_state(), for_each_old_plane_in_state() and
  657. * for_each_new_plane_in_state(). Or through careful ordering of atomic
  658. * commit operations as implemented in the atomic helpers, see
  659. * &struct drm_crtc_commit.
  660. */
  661. struct drm_plane_state *state;
  662. /**
  663. * @alpha_property:
  664. * Optional alpha property for this plane. See
  665. * drm_plane_create_alpha_property().
  666. */
  667. struct drm_property *alpha_property;
  668. /**
  669. * @zpos_property:
  670. * Optional zpos property for this plane. See
  671. * drm_plane_create_zpos_property().
  672. */
  673. struct drm_property *zpos_property;
  674. /**
  675. * @rotation_property:
  676. * Optional rotation property for this plane. See
  677. * drm_plane_create_rotation_property().
  678. */
  679. struct drm_property *rotation_property;
  680. /**
  681. * @blend_mode_property:
  682. * Optional "pixel blend mode" enum property for this plane.
  683. * Blend mode property represents the alpha blending equation selection,
  684. * describing how the pixels from the current plane are composited with
  685. * the background.
  686. */
  687. struct drm_property *blend_mode_property;
  688. /**
  689. * @color_encoding_property:
  690. *
  691. * Optional "COLOR_ENCODING" enum property for specifying
  692. * color encoding for non RGB formats.
  693. * See drm_plane_create_color_properties().
  694. */
  695. struct drm_property *color_encoding_property;
  696. /**
  697. * @color_range_property:
  698. *
  699. * Optional "COLOR_RANGE" enum property for specifying
  700. * color range for non RGB formats.
  701. * See drm_plane_create_color_properties().
  702. */
  703. struct drm_property *color_range_property;
  704. /**
  705. * @scaling_filter_property: property to apply a particular filter while
  706. * scaling.
  707. */
  708. struct drm_property *scaling_filter_property;
  709. /**
  710. * @hotspot_x_property: property to set mouse hotspot x offset.
  711. */
  712. struct drm_property *hotspot_x_property;
  713. /**
  714. * @hotspot_y_property: property to set mouse hotspot y offset.
  715. */
  716. struct drm_property *hotspot_y_property;
  717. /**
  718. * @kmsg_panic: Used to register a panic notifier for this plane
  719. */
  720. struct kmsg_dumper kmsg_panic;
  721. };
  722. #define obj_to_plane(x) container_of(x, struct drm_plane, base)
  723. __printf(9, 10)
  724. int drm_universal_plane_init(struct drm_device *dev,
  725. struct drm_plane *plane,
  726. uint32_t possible_crtcs,
  727. const struct drm_plane_funcs *funcs,
  728. const uint32_t *formats,
  729. unsigned int format_count,
  730. const uint64_t *format_modifiers,
  731. enum drm_plane_type type,
  732. const char *name, ...);
  733. void drm_plane_cleanup(struct drm_plane *plane);
  734. __printf(10, 11)
  735. void *__drmm_universal_plane_alloc(struct drm_device *dev,
  736. size_t size, size_t offset,
  737. uint32_t possible_crtcs,
  738. const struct drm_plane_funcs *funcs,
  739. const uint32_t *formats,
  740. unsigned int format_count,
  741. const uint64_t *format_modifiers,
  742. enum drm_plane_type plane_type,
  743. const char *name, ...);
  744. /**
  745. * drmm_universal_plane_alloc - Allocate and initialize an universal plane object
  746. * @dev: DRM device
  747. * @type: the type of the struct which contains struct &drm_plane
  748. * @member: the name of the &drm_plane within @type
  749. * @possible_crtcs: bitmask of possible CRTCs
  750. * @funcs: callbacks for the new plane
  751. * @formats: array of supported formats (DRM_FORMAT\_\*)
  752. * @format_count: number of elements in @formats
  753. * @format_modifiers: array of struct drm_format modifiers terminated by
  754. * DRM_FORMAT_MOD_INVALID
  755. * @plane_type: type of plane (overlay, primary, cursor)
  756. * @name: printf style format string for the plane name, or NULL for default name
  757. *
  758. * Allocates and initializes a plane object of type @type. Cleanup is
  759. * automatically handled through registering drm_plane_cleanup() with
  760. * drmm_add_action().
  761. *
  762. * The @drm_plane_funcs.destroy hook must be NULL.
  763. *
  764. * Drivers that only support the DRM_FORMAT_MOD_LINEAR modifier support may set
  765. * @format_modifiers to NULL. The plane will advertise the linear modifier.
  766. *
  767. * Returns:
  768. * Pointer to new plane, or ERR_PTR on failure.
  769. */
  770. #define drmm_universal_plane_alloc(dev, type, member, possible_crtcs, funcs, formats, \
  771. format_count, format_modifiers, plane_type, name, ...) \
  772. ((type *)__drmm_universal_plane_alloc(dev, sizeof(type), \
  773. offsetof(type, member), \
  774. possible_crtcs, funcs, formats, \
  775. format_count, format_modifiers, \
  776. plane_type, name, ##__VA_ARGS__))
  777. __printf(10, 11)
  778. void *__drm_universal_plane_alloc(struct drm_device *dev,
  779. size_t size, size_t offset,
  780. uint32_t possible_crtcs,
  781. const struct drm_plane_funcs *funcs,
  782. const uint32_t *formats,
  783. unsigned int format_count,
  784. const uint64_t *format_modifiers,
  785. enum drm_plane_type plane_type,
  786. const char *name, ...);
  787. /**
  788. * drm_universal_plane_alloc() - Allocate and initialize an universal plane object
  789. * @dev: DRM device
  790. * @type: the type of the struct which contains struct &drm_plane
  791. * @member: the name of the &drm_plane within @type
  792. * @possible_crtcs: bitmask of possible CRTCs
  793. * @funcs: callbacks for the new plane
  794. * @formats: array of supported formats (DRM_FORMAT\_\*)
  795. * @format_count: number of elements in @formats
  796. * @format_modifiers: array of struct drm_format modifiers terminated by
  797. * DRM_FORMAT_MOD_INVALID
  798. * @plane_type: type of plane (overlay, primary, cursor)
  799. * @name: printf style format string for the plane name, or NULL for default name
  800. *
  801. * Allocates and initializes a plane object of type @type. The caller
  802. * is responsible for releasing the allocated memory with kfree().
  803. *
  804. * Drivers are encouraged to use drmm_universal_plane_alloc() instead.
  805. *
  806. * Drivers that only support the DRM_FORMAT_MOD_LINEAR modifier support may set
  807. * @format_modifiers to NULL. The plane will advertise the linear modifier.
  808. *
  809. * Returns:
  810. * Pointer to new plane, or ERR_PTR on failure.
  811. */
  812. #define drm_universal_plane_alloc(dev, type, member, possible_crtcs, funcs, formats, \
  813. format_count, format_modifiers, plane_type, name, ...) \
  814. ((type *)__drm_universal_plane_alloc(dev, sizeof(type), \
  815. offsetof(type, member), \
  816. possible_crtcs, funcs, formats, \
  817. format_count, format_modifiers, \
  818. plane_type, name, ##__VA_ARGS__))
  819. /**
  820. * drm_plane_index - find the index of a registered plane
  821. * @plane: plane to find index for
  822. *
  823. * Given a registered plane, return the index of that plane within a DRM
  824. * device's list of planes.
  825. */
  826. static inline unsigned int drm_plane_index(const struct drm_plane *plane)
  827. {
  828. return plane->index;
  829. }
  830. /**
  831. * drm_plane_mask - find the mask of a registered plane
  832. * @plane: plane to find mask for
  833. */
  834. static inline u32 drm_plane_mask(const struct drm_plane *plane)
  835. {
  836. return 1 << drm_plane_index(plane);
  837. }
  838. struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
  839. void drm_plane_force_disable(struct drm_plane *plane);
  840. int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
  841. struct drm_property *property,
  842. uint64_t value);
  843. /**
  844. * drm_plane_find - find a &drm_plane
  845. * @dev: DRM device
  846. * @file_priv: drm file to check for lease against.
  847. * @id: plane id
  848. *
  849. * Returns the plane with @id, NULL if it doesn't exist. Simple wrapper around
  850. * drm_mode_object_find().
  851. */
  852. static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
  853. struct drm_file *file_priv,
  854. uint32_t id)
  855. {
  856. struct drm_mode_object *mo;
  857. mo = drm_mode_object_find(dev, file_priv, id, DRM_MODE_OBJECT_PLANE);
  858. return mo ? obj_to_plane(mo) : NULL;
  859. }
  860. /**
  861. * drm_for_each_plane_mask - iterate over planes specified by bitmask
  862. * @plane: the loop cursor
  863. * @dev: the DRM device
  864. * @plane_mask: bitmask of plane indices
  865. *
  866. * Iterate over all planes specified by bitmask.
  867. */
  868. #define drm_for_each_plane_mask(plane, dev, plane_mask) \
  869. list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
  870. for_each_if ((plane_mask) & drm_plane_mask(plane))
  871. /**
  872. * drm_for_each_legacy_plane - iterate over all planes for legacy userspace
  873. * @plane: the loop cursor
  874. * @dev: the DRM device
  875. *
  876. * Iterate over all legacy planes of @dev, excluding primary and cursor planes.
  877. * This is useful for implementing userspace apis when userspace is not
  878. * universal plane aware. See also &enum drm_plane_type.
  879. */
  880. #define drm_for_each_legacy_plane(plane, dev) \
  881. list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
  882. for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
  883. /**
  884. * drm_for_each_plane - iterate over all planes
  885. * @plane: the loop cursor
  886. * @dev: the DRM device
  887. *
  888. * Iterate over all planes of @dev, include primary and cursor planes.
  889. */
  890. #define drm_for_each_plane(plane, dev) \
  891. list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
  892. bool drm_plane_has_format(struct drm_plane *plane,
  893. u32 format, u64 modifier);
  894. bool drm_any_plane_has_format(struct drm_device *dev,
  895. u32 format, u64 modifier);
  896. void drm_plane_enable_fb_damage_clips(struct drm_plane *plane);
  897. unsigned int
  898. drm_plane_get_damage_clips_count(const struct drm_plane_state *state);
  899. struct drm_mode_rect *
  900. drm_plane_get_damage_clips(const struct drm_plane_state *state);
  901. int drm_plane_create_scaling_filter_property(struct drm_plane *plane,
  902. unsigned int supported_filters);
  903. int drm_plane_add_size_hints_property(struct drm_plane *plane,
  904. const struct drm_plane_size_hint *hints,
  905. int num_hints);
  906. #endif