drm_plane.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  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 <drm/drm_mode_object.h>
  27. #include <drm/drm_color_mgmt.h>
  28. struct drm_crtc;
  29. struct drm_printer;
  30. struct drm_modeset_acquire_ctx;
  31. /**
  32. * struct drm_plane_state - mutable plane state
  33. *
  34. * Please not that the destination coordinates @crtc_x, @crtc_y, @crtc_h and
  35. * @crtc_w and the source coordinates @src_x, @src_y, @src_h and @src_w are the
  36. * raw coordinates provided by userspace. Drivers should use
  37. * drm_atomic_helper_check_plane_state() and only use the derived rectangles in
  38. * @src and @dst to program the hardware.
  39. */
  40. struct drm_plane_state {
  41. /** @plane: backpointer to the plane */
  42. struct drm_plane *plane;
  43. /**
  44. * @crtc:
  45. *
  46. * Currently bound CRTC, NULL if disabled. Do not this write directly,
  47. * use drm_atomic_set_crtc_for_plane()
  48. */
  49. struct drm_crtc *crtc;
  50. /**
  51. * @fb:
  52. *
  53. * Currently bound framebuffer. Do not write this directly, use
  54. * drm_atomic_set_fb_for_plane()
  55. */
  56. struct drm_framebuffer *fb;
  57. /**
  58. * @fence:
  59. *
  60. * Optional fence to wait for before scanning out @fb. The core atomic
  61. * code will set this when userspace is using explicit fencing. Do not
  62. * write this directly for a driver's implicit fence, use
  63. * drm_atomic_set_fence_for_plane() to ensure that an explicit fence is
  64. * preserved.
  65. *
  66. * Drivers should store any implicit fence in this from their
  67. * &drm_plane_helper_funcs.prepare_fb callback. See drm_gem_fb_prepare_fb()
  68. * and drm_gem_fb_simple_display_pipe_prepare_fb() for suitable helpers.
  69. */
  70. struct dma_fence *fence;
  71. /**
  72. * @crtc_x:
  73. *
  74. * Left position of visible portion of plane on crtc, signed dest
  75. * location allows it to be partially off screen.
  76. */
  77. int32_t crtc_x;
  78. /**
  79. * @crtc_y:
  80. *
  81. * Upper position of visible portion of plane on crtc, signed dest
  82. * location allows it to be partially off screen.
  83. */
  84. int32_t crtc_y;
  85. /** @crtc_w: width of visible portion of plane on crtc */
  86. /** @crtc_h: height of visible portion of plane on crtc */
  87. uint32_t crtc_w, crtc_h;
  88. /**
  89. * @src_x: left position of visible portion of plane within plane (in
  90. * 16.16 fixed point).
  91. */
  92. uint32_t src_x;
  93. /**
  94. * @src_y: upper position of visible portion of plane within plane (in
  95. * 16.16 fixed point).
  96. */
  97. uint32_t src_y;
  98. /** @src_w: width of visible portion of plane (in 16.16) */
  99. /** @src_h: height of visible portion of plane (in 16.16) */
  100. uint32_t src_h, src_w;
  101. /**
  102. * @alpha:
  103. * Opacity of the plane with 0 as completely transparent and 0xffff as
  104. * completely opaque. See drm_plane_create_alpha_property() for more
  105. * details.
  106. */
  107. u16 alpha;
  108. /**
  109. * @rotation:
  110. * Rotation of the plane. See drm_plane_create_rotation_property() for
  111. * more details.
  112. */
  113. unsigned int rotation;
  114. /**
  115. * @zpos:
  116. * Priority of the given plane on crtc (optional).
  117. *
  118. * Note that multiple active planes on the same crtc can have an
  119. * identical zpos value. The rule to solving the conflict is to compare
  120. * the plane object IDs; the plane with a higher ID must be stacked on
  121. * top of a plane with a lower ID.
  122. *
  123. * See drm_plane_create_zpos_property() and
  124. * drm_plane_create_zpos_immutable_property() for more details.
  125. */
  126. unsigned int zpos;
  127. /**
  128. * @normalized_zpos:
  129. * Normalized value of zpos: unique, range from 0 to N-1 where N is the
  130. * number of active planes for given crtc. Note that the driver must set
  131. * &drm_mode_config.normalize_zpos or call drm_atomic_normalize_zpos() to
  132. * update this before it can be trusted.
  133. */
  134. unsigned int normalized_zpos;
  135. /**
  136. * @color_encoding:
  137. *
  138. * Color encoding for non RGB formats
  139. */
  140. enum drm_color_encoding color_encoding;
  141. /**
  142. * @color_range:
  143. *
  144. * Color range for non RGB formats
  145. */
  146. enum drm_color_range color_range;
  147. /** @src: clipped source coordinates of the plane (in 16.16) */
  148. /** @dst: clipped destination coordinates of the plane */
  149. struct drm_rect src, dst;
  150. /**
  151. * @visible:
  152. *
  153. * Visibility of the plane. This can be false even if fb!=NULL and
  154. * crtc!=NULL, due to clipping.
  155. */
  156. bool visible;
  157. /**
  158. * @commit: Tracks the pending commit to prevent use-after-free conditions,
  159. * and for async plane updates.
  160. *
  161. * May be NULL.
  162. */
  163. struct drm_crtc_commit *commit;
  164. /** @state: backpointer to global drm_atomic_state */
  165. struct drm_atomic_state *state;
  166. };
  167. static inline struct drm_rect
  168. drm_plane_state_src(const struct drm_plane_state *state)
  169. {
  170. struct drm_rect src = {
  171. .x1 = state->src_x,
  172. .y1 = state->src_y,
  173. .x2 = state->src_x + state->src_w,
  174. .y2 = state->src_y + state->src_h,
  175. };
  176. return src;
  177. }
  178. static inline struct drm_rect
  179. drm_plane_state_dest(const struct drm_plane_state *state)
  180. {
  181. struct drm_rect dest = {
  182. .x1 = state->crtc_x,
  183. .y1 = state->crtc_y,
  184. .x2 = state->crtc_x + state->crtc_w,
  185. .y2 = state->crtc_y + state->crtc_h,
  186. };
  187. return dest;
  188. }
  189. /**
  190. * struct drm_plane_funcs - driver plane control functions
  191. */
  192. struct drm_plane_funcs {
  193. /**
  194. * @update_plane:
  195. *
  196. * This is the legacy entry point to enable and configure the plane for
  197. * the given CRTC and framebuffer. It is never called to disable the
  198. * plane, i.e. the passed-in crtc and fb paramters are never NULL.
  199. *
  200. * The source rectangle in frame buffer memory coordinates is given by
  201. * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
  202. * values). Devices that don't support subpixel plane coordinates can
  203. * ignore the fractional part.
  204. *
  205. * The destination rectangle in CRTC coordinates is given by the
  206. * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
  207. * Devices scale the source rectangle to the destination rectangle. If
  208. * scaling is not supported, and the source rectangle size doesn't match
  209. * the destination rectangle size, the driver must return a
  210. * -<errorname>EINVAL</errorname> error.
  211. *
  212. * Drivers implementing atomic modeset should use
  213. * drm_atomic_helper_update_plane() to implement this hook.
  214. *
  215. * RETURNS:
  216. *
  217. * 0 on success or a negative error code on failure.
  218. */
  219. int (*update_plane)(struct drm_plane *plane,
  220. struct drm_crtc *crtc, struct drm_framebuffer *fb,
  221. int crtc_x, int crtc_y,
  222. unsigned int crtc_w, unsigned int crtc_h,
  223. uint32_t src_x, uint32_t src_y,
  224. uint32_t src_w, uint32_t src_h,
  225. struct drm_modeset_acquire_ctx *ctx);
  226. /**
  227. * @disable_plane:
  228. *
  229. * This is the legacy entry point to disable the plane. The DRM core
  230. * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
  231. * with the frame buffer ID set to 0. Disabled planes must not be
  232. * processed by the CRTC.
  233. *
  234. * Drivers implementing atomic modeset should use
  235. * drm_atomic_helper_disable_plane() to implement this hook.
  236. *
  237. * RETURNS:
  238. *
  239. * 0 on success or a negative error code on failure.
  240. */
  241. int (*disable_plane)(struct drm_plane *plane,
  242. struct drm_modeset_acquire_ctx *ctx);
  243. /**
  244. * @destroy:
  245. *
  246. * Clean up plane resources. This is only called at driver unload time
  247. * through drm_mode_config_cleanup() since a plane cannot be hotplugged
  248. * in DRM.
  249. */
  250. void (*destroy)(struct drm_plane *plane);
  251. /**
  252. * @reset:
  253. *
  254. * Reset plane hardware and software state to off. This function isn't
  255. * called by the core directly, only through drm_mode_config_reset().
  256. * It's not a helper hook only for historical reasons.
  257. *
  258. * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
  259. * atomic state using this hook.
  260. */
  261. void (*reset)(struct drm_plane *plane);
  262. /**
  263. * @set_property:
  264. *
  265. * This is the legacy entry point to update a property attached to the
  266. * plane.
  267. *
  268. * This callback is optional if the driver does not support any legacy
  269. * driver-private properties. For atomic drivers it is not used because
  270. * property handling is done entirely in the DRM core.
  271. *
  272. * RETURNS:
  273. *
  274. * 0 on success or a negative error code on failure.
  275. */
  276. int (*set_property)(struct drm_plane *plane,
  277. struct drm_property *property, uint64_t val);
  278. /**
  279. * @atomic_duplicate_state:
  280. *
  281. * Duplicate the current atomic state for this plane and return it.
  282. * The core and helpers guarantee that any atomic state duplicated with
  283. * this hook and still owned by the caller (i.e. not transferred to the
  284. * driver by calling &drm_mode_config_funcs.atomic_commit) will be
  285. * cleaned up by calling the @atomic_destroy_state hook in this
  286. * structure.
  287. *
  288. * This callback is mandatory for atomic drivers.
  289. *
  290. * Atomic drivers which don't subclass &struct drm_plane_state should use
  291. * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
  292. * state structure to extend it with driver-private state should use
  293. * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
  294. * duplicated in a consistent fashion across drivers.
  295. *
  296. * It is an error to call this hook before &drm_plane.state has been
  297. * initialized correctly.
  298. *
  299. * NOTE:
  300. *
  301. * If the duplicate state references refcounted resources this hook must
  302. * acquire a reference for each of them. The driver must release these
  303. * references again in @atomic_destroy_state.
  304. *
  305. * RETURNS:
  306. *
  307. * Duplicated atomic state or NULL when the allocation failed.
  308. */
  309. struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
  310. /**
  311. * @atomic_destroy_state:
  312. *
  313. * Destroy a state duplicated with @atomic_duplicate_state and release
  314. * or unreference all resources it references
  315. *
  316. * This callback is mandatory for atomic drivers.
  317. */
  318. void (*atomic_destroy_state)(struct drm_plane *plane,
  319. struct drm_plane_state *state);
  320. /**
  321. * @atomic_set_property:
  322. *
  323. * Decode a driver-private property value and store the decoded value
  324. * into the passed-in state structure. Since the atomic core decodes all
  325. * standardized properties (even for extensions beyond the core set of
  326. * properties which might not be implemented by all drivers) this
  327. * requires drivers to subclass the state structure.
  328. *
  329. * Such driver-private properties should really only be implemented for
  330. * truly hardware/vendor specific state. Instead it is preferred to
  331. * standardize atomic extension and decode the properties used to expose
  332. * such an extension in the core.
  333. *
  334. * Do not call this function directly, use
  335. * drm_atomic_plane_set_property() instead.
  336. *
  337. * This callback is optional if the driver does not support any
  338. * driver-private atomic properties.
  339. *
  340. * NOTE:
  341. *
  342. * This function is called in the state assembly phase of atomic
  343. * modesets, which can be aborted for any reason (including on
  344. * userspace's request to just check whether a configuration would be
  345. * possible). Drivers MUST NOT touch any persistent state (hardware or
  346. * software) or data structures except the passed in @state parameter.
  347. *
  348. * Also since userspace controls in which order properties are set this
  349. * function must not do any input validation (since the state update is
  350. * incomplete and hence likely inconsistent). Instead any such input
  351. * validation must be done in the various atomic_check callbacks.
  352. *
  353. * RETURNS:
  354. *
  355. * 0 if the property has been found, -EINVAL if the property isn't
  356. * implemented by the driver (which shouldn't ever happen, the core only
  357. * asks for properties attached to this plane). No other validation is
  358. * allowed by the driver. The core already checks that the property
  359. * value is within the range (integer, valid enum value, ...) the driver
  360. * set when registering the property.
  361. */
  362. int (*atomic_set_property)(struct drm_plane *plane,
  363. struct drm_plane_state *state,
  364. struct drm_property *property,
  365. uint64_t val);
  366. /**
  367. * @atomic_get_property:
  368. *
  369. * Reads out the decoded driver-private property. This is used to
  370. * implement the GETPLANE IOCTL.
  371. *
  372. * Do not call this function directly, use
  373. * drm_atomic_plane_get_property() instead.
  374. *
  375. * This callback is optional if the driver does not support any
  376. * driver-private atomic properties.
  377. *
  378. * RETURNS:
  379. *
  380. * 0 on success, -EINVAL if the property isn't implemented by the
  381. * driver (which should never happen, the core only asks for
  382. * properties attached to this plane).
  383. */
  384. int (*atomic_get_property)(struct drm_plane *plane,
  385. const struct drm_plane_state *state,
  386. struct drm_property *property,
  387. uint64_t *val);
  388. /**
  389. * @late_register:
  390. *
  391. * This optional hook can be used to register additional userspace
  392. * interfaces attached to the plane like debugfs interfaces.
  393. * It is called late in the driver load sequence from drm_dev_register().
  394. * Everything added from this callback should be unregistered in
  395. * the early_unregister callback.
  396. *
  397. * Returns:
  398. *
  399. * 0 on success, or a negative error code on failure.
  400. */
  401. int (*late_register)(struct drm_plane *plane);
  402. /**
  403. * @early_unregister:
  404. *
  405. * This optional hook should be used to unregister the additional
  406. * userspace interfaces attached to the plane from
  407. * @late_register. It is called from drm_dev_unregister(),
  408. * early in the driver unload sequence to disable userspace access
  409. * before data structures are torndown.
  410. */
  411. void (*early_unregister)(struct drm_plane *plane);
  412. /**
  413. * @atomic_print_state:
  414. *
  415. * If driver subclasses &struct drm_plane_state, it should implement
  416. * this optional hook for printing additional driver specific state.
  417. *
  418. * Do not call this directly, use drm_atomic_plane_print_state()
  419. * instead.
  420. */
  421. void (*atomic_print_state)(struct drm_printer *p,
  422. const struct drm_plane_state *state);
  423. /**
  424. * @format_mod_supported:
  425. *
  426. * This optional hook is used for the DRM to determine if the given
  427. * format/modifier combination is valid for the plane. This allows the
  428. * DRM to generate the correct format bitmask (which formats apply to
  429. * which modifier), and to valdiate modifiers at atomic_check time.
  430. *
  431. * If not present, then any modifier in the plane's modifier
  432. * list is allowed with any of the plane's formats.
  433. *
  434. * Returns:
  435. *
  436. * True if the given modifier is valid for that format on the plane.
  437. * False otherwise.
  438. */
  439. bool (*format_mod_supported)(struct drm_plane *plane, uint32_t format,
  440. uint64_t modifier);
  441. };
  442. /**
  443. * enum drm_plane_type - uapi plane type enumeration
  444. *
  445. * For historical reasons not all planes are made the same. This enumeration is
  446. * used to tell the different types of planes apart to implement the different
  447. * uapi semantics for them. For userspace which is universal plane aware and
  448. * which is using that atomic IOCTL there's no difference between these planes
  449. * (beyong what the driver and hardware can support of course).
  450. *
  451. * For compatibility with legacy userspace, only overlay planes are made
  452. * available to userspace by default. Userspace clients may set the
  453. * DRM_CLIENT_CAP_UNIVERSAL_PLANES client capability bit to indicate that they
  454. * wish to receive a universal plane list containing all plane types. See also
  455. * drm_for_each_legacy_plane().
  456. *
  457. * WARNING: The values of this enum is UABI since they're exposed in the "type"
  458. * property.
  459. */
  460. enum drm_plane_type {
  461. /**
  462. * @DRM_PLANE_TYPE_OVERLAY:
  463. *
  464. * Overlay planes represent all non-primary, non-cursor planes. Some
  465. * drivers refer to these types of planes as "sprites" internally.
  466. */
  467. DRM_PLANE_TYPE_OVERLAY,
  468. /**
  469. * @DRM_PLANE_TYPE_PRIMARY:
  470. *
  471. * Primary planes represent a "main" plane for a CRTC. Primary planes
  472. * are the planes operated upon by CRTC modesetting and flipping
  473. * operations described in the &drm_crtc_funcs.page_flip and
  474. * &drm_crtc_funcs.set_config hooks.
  475. */
  476. DRM_PLANE_TYPE_PRIMARY,
  477. /**
  478. * @DRM_PLANE_TYPE_CURSOR:
  479. *
  480. * Cursor planes represent a "cursor" plane for a CRTC. Cursor planes
  481. * are the planes operated upon by the DRM_IOCTL_MODE_CURSOR and
  482. * DRM_IOCTL_MODE_CURSOR2 IOCTLs.
  483. */
  484. DRM_PLANE_TYPE_CURSOR,
  485. };
  486. /**
  487. * struct drm_plane - central DRM plane control structure
  488. *
  489. * Planes represent the scanout hardware of a display block. They receive their
  490. * input data from a &drm_framebuffer and feed it to a &drm_crtc. Planes control
  491. * the color conversion, see `Plane Composition Properties`_ for more details,
  492. * and are also involved in the color conversion of input pixels, see `Color
  493. * Management Properties`_ for details on that.
  494. */
  495. struct drm_plane {
  496. /** @dev: DRM device this plane belongs to */
  497. struct drm_device *dev;
  498. /**
  499. * @head:
  500. *
  501. * List of all planes on @dev, linked from &drm_mode_config.plane_list.
  502. * Invariant over the lifetime of @dev and therefore does not need
  503. * locking.
  504. */
  505. struct list_head head;
  506. /** @name: human readable name, can be overwritten by the driver */
  507. char *name;
  508. /**
  509. * @mutex:
  510. *
  511. * Protects modeset plane state, together with the &drm_crtc.mutex of
  512. * CRTC this plane is linked to (when active, getting activated or
  513. * getting disabled).
  514. *
  515. * For atomic drivers specifically this protects @state.
  516. */
  517. struct drm_modeset_lock mutex;
  518. /** @base: base mode object */
  519. struct drm_mode_object base;
  520. /**
  521. * @possible_crtcs: pipes this plane can be bound to constructed from
  522. * drm_crtc_mask()
  523. */
  524. uint32_t possible_crtcs;
  525. /** @format_types: array of formats supported by this plane */
  526. uint32_t *format_types;
  527. /** @format_count: Size of the array pointed at by @format_types. */
  528. unsigned int format_count;
  529. /**
  530. * @format_default: driver hasn't supplied supported formats for the
  531. * plane. Used by the drm_plane_init compatibility wrapper only.
  532. */
  533. bool format_default;
  534. /** @modifiers: array of modifiers supported by this plane */
  535. uint64_t *modifiers;
  536. /** @modifier_count: Size of the array pointed at by @modifier_count. */
  537. unsigned int modifier_count;
  538. /**
  539. * @crtc:
  540. *
  541. * Currently bound CRTC, only meaningful for non-atomic drivers. For
  542. * atomic drivers this is forced to be NULL, atomic drivers should
  543. * instead check &drm_plane_state.crtc.
  544. */
  545. struct drm_crtc *crtc;
  546. /**
  547. * @fb:
  548. *
  549. * Currently bound framebuffer, only meaningful for non-atomic drivers.
  550. * For atomic drivers this is forced to be NULL, atomic drivers should
  551. * instead check &drm_plane_state.fb.
  552. */
  553. struct drm_framebuffer *fb;
  554. /**
  555. * @old_fb:
  556. *
  557. * Temporary tracking of the old fb while a modeset is ongoing. Only
  558. * used by non-atomic drivers, forced to be NULL for atomic drivers.
  559. */
  560. struct drm_framebuffer *old_fb;
  561. /** @funcs: plane control functions */
  562. const struct drm_plane_funcs *funcs;
  563. /** @properties: property tracking for this plane */
  564. struct drm_object_properties properties;
  565. /** @type: Type of plane, see &enum drm_plane_type for details. */
  566. enum drm_plane_type type;
  567. /**
  568. * @index: Position inside the mode_config.list, can be used as an array
  569. * index. It is invariant over the lifetime of the plane.
  570. */
  571. unsigned index;
  572. /** @helper_private: mid-layer private data */
  573. const struct drm_plane_helper_funcs *helper_private;
  574. /**
  575. * @state:
  576. *
  577. * Current atomic state for this plane.
  578. *
  579. * This is protected by @mutex. Note that nonblocking atomic commits
  580. * access the current plane state without taking locks. Either by going
  581. * through the &struct drm_atomic_state pointers, see
  582. * for_each_oldnew_plane_in_state(), for_each_old_plane_in_state() and
  583. * for_each_new_plane_in_state(). Or through careful ordering of atomic
  584. * commit operations as implemented in the atomic helpers, see
  585. * &struct drm_crtc_commit.
  586. */
  587. struct drm_plane_state *state;
  588. /**
  589. * @alpha_property:
  590. * Optional alpha property for this plane. See
  591. * drm_plane_create_alpha_property().
  592. */
  593. struct drm_property *alpha_property;
  594. /**
  595. * @zpos_property:
  596. * Optional zpos property for this plane. See
  597. * drm_plane_create_zpos_property().
  598. */
  599. struct drm_property *zpos_property;
  600. /**
  601. * @rotation_property:
  602. * Optional rotation property for this plane. See
  603. * drm_plane_create_rotation_property().
  604. */
  605. struct drm_property *rotation_property;
  606. /**
  607. * @color_encoding_property:
  608. *
  609. * Optional "COLOR_ENCODING" enum property for specifying
  610. * color encoding for non RGB formats.
  611. * See drm_plane_create_color_properties().
  612. */
  613. struct drm_property *color_encoding_property;
  614. /**
  615. * @color_range_property:
  616. *
  617. * Optional "COLOR_RANGE" enum property for specifying
  618. * color range for non RGB formats.
  619. * See drm_plane_create_color_properties().
  620. */
  621. struct drm_property *color_range_property;
  622. };
  623. #define obj_to_plane(x) container_of(x, struct drm_plane, base)
  624. __printf(9, 10)
  625. int drm_universal_plane_init(struct drm_device *dev,
  626. struct drm_plane *plane,
  627. uint32_t possible_crtcs,
  628. const struct drm_plane_funcs *funcs,
  629. const uint32_t *formats,
  630. unsigned int format_count,
  631. const uint64_t *format_modifiers,
  632. enum drm_plane_type type,
  633. const char *name, ...);
  634. int drm_plane_init(struct drm_device *dev,
  635. struct drm_plane *plane,
  636. uint32_t possible_crtcs,
  637. const struct drm_plane_funcs *funcs,
  638. const uint32_t *formats, unsigned int format_count,
  639. bool is_primary);
  640. void drm_plane_cleanup(struct drm_plane *plane);
  641. /**
  642. * drm_plane_index - find the index of a registered plane
  643. * @plane: plane to find index for
  644. *
  645. * Given a registered plane, return the index of that plane within a DRM
  646. * device's list of planes.
  647. */
  648. static inline unsigned int drm_plane_index(const struct drm_plane *plane)
  649. {
  650. return plane->index;
  651. }
  652. /**
  653. * drm_plane_mask - find the mask of a registered plane
  654. * @plane: plane to find mask for
  655. */
  656. static inline u32 drm_plane_mask(const struct drm_plane *plane)
  657. {
  658. return 1 << drm_plane_index(plane);
  659. }
  660. struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
  661. void drm_plane_force_disable(struct drm_plane *plane);
  662. int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
  663. struct drm_property *property,
  664. uint64_t value);
  665. /**
  666. * drm_plane_find - find a &drm_plane
  667. * @dev: DRM device
  668. * @file_priv: drm file to check for lease against.
  669. * @id: plane id
  670. *
  671. * Returns the plane with @id, NULL if it doesn't exist. Simple wrapper around
  672. * drm_mode_object_find().
  673. */
  674. static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
  675. struct drm_file *file_priv,
  676. uint32_t id)
  677. {
  678. struct drm_mode_object *mo;
  679. mo = drm_mode_object_find(dev, file_priv, id, DRM_MODE_OBJECT_PLANE);
  680. return mo ? obj_to_plane(mo) : NULL;
  681. }
  682. /**
  683. * drm_for_each_plane_mask - iterate over planes specified by bitmask
  684. * @plane: the loop cursor
  685. * @dev: the DRM device
  686. * @plane_mask: bitmask of plane indices
  687. *
  688. * Iterate over all planes specified by bitmask.
  689. */
  690. #define drm_for_each_plane_mask(plane, dev, plane_mask) \
  691. list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
  692. for_each_if ((plane_mask) & drm_plane_mask(plane))
  693. /**
  694. * drm_for_each_legacy_plane - iterate over all planes for legacy userspace
  695. * @plane: the loop cursor
  696. * @dev: the DRM device
  697. *
  698. * Iterate over all legacy planes of @dev, excluding primary and cursor planes.
  699. * This is useful for implementing userspace apis when userspace is not
  700. * universal plane aware. See also &enum drm_plane_type.
  701. */
  702. #define drm_for_each_legacy_plane(plane, dev) \
  703. list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
  704. for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
  705. /**
  706. * drm_for_each_plane - iterate over all planes
  707. * @plane: the loop cursor
  708. * @dev: the DRM device
  709. *
  710. * Iterate over all planes of @dev, include primary and cursor planes.
  711. */
  712. #define drm_for_each_plane(plane, dev) \
  713. list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
  714. #endif