drm_plane.h 22 KB

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