drm_plane.h 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028
  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. * @color_pipeline:
  222. *
  223. * The first colorop of the active color pipeline, or NULL, if no
  224. * color pipeline is active.
  225. */
  226. struct drm_colorop *color_pipeline;
  227. /**
  228. * @commit: Tracks the pending commit to prevent use-after-free conditions,
  229. * and for async plane updates.
  230. *
  231. * May be NULL.
  232. */
  233. struct drm_crtc_commit *commit;
  234. /** @state: backpointer to global drm_atomic_state */
  235. struct drm_atomic_state *state;
  236. /**
  237. * @color_mgmt_changed: Color management properties have changed. Used
  238. * by the atomic helpers and drivers to steer the atomic commit control
  239. * flow.
  240. */
  241. bool color_mgmt_changed : 1;
  242. };
  243. static inline struct drm_rect
  244. drm_plane_state_src(const struct drm_plane_state *state)
  245. {
  246. struct drm_rect src = {
  247. .x1 = state->src_x,
  248. .y1 = state->src_y,
  249. .x2 = state->src_x + state->src_w,
  250. .y2 = state->src_y + state->src_h,
  251. };
  252. return src;
  253. }
  254. static inline struct drm_rect
  255. drm_plane_state_dest(const struct drm_plane_state *state)
  256. {
  257. struct drm_rect dest = {
  258. .x1 = state->crtc_x,
  259. .y1 = state->crtc_y,
  260. .x2 = state->crtc_x + state->crtc_w,
  261. .y2 = state->crtc_y + state->crtc_h,
  262. };
  263. return dest;
  264. }
  265. /**
  266. * struct drm_plane_funcs - driver plane control functions
  267. */
  268. struct drm_plane_funcs {
  269. /**
  270. * @update_plane:
  271. *
  272. * This is the legacy entry point to enable and configure the plane for
  273. * the given CRTC and framebuffer. It is never called to disable the
  274. * plane, i.e. the passed-in crtc and fb paramters are never NULL.
  275. *
  276. * The source rectangle in frame buffer memory coordinates is given by
  277. * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
  278. * values). Devices that don't support subpixel plane coordinates can
  279. * ignore the fractional part.
  280. *
  281. * The destination rectangle in CRTC coordinates is given by the
  282. * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
  283. * Devices scale the source rectangle to the destination rectangle. If
  284. * scaling is not supported, and the source rectangle size doesn't match
  285. * the destination rectangle size, the driver must return a
  286. * -<errorname>EINVAL</errorname> error.
  287. *
  288. * Drivers implementing atomic modeset should use
  289. * drm_atomic_helper_update_plane() to implement this hook.
  290. *
  291. * RETURNS:
  292. *
  293. * 0 on success or a negative error code on failure.
  294. */
  295. int (*update_plane)(struct drm_plane *plane,
  296. struct drm_crtc *crtc, struct drm_framebuffer *fb,
  297. int crtc_x, int crtc_y,
  298. unsigned int crtc_w, unsigned int crtc_h,
  299. uint32_t src_x, uint32_t src_y,
  300. uint32_t src_w, uint32_t src_h,
  301. struct drm_modeset_acquire_ctx *ctx);
  302. /**
  303. * @disable_plane:
  304. *
  305. * This is the legacy entry point to disable the plane. The DRM core
  306. * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
  307. * with the frame buffer ID set to 0. Disabled planes must not be
  308. * processed by the CRTC.
  309. *
  310. * Drivers implementing atomic modeset should use
  311. * drm_atomic_helper_disable_plane() to implement this hook.
  312. *
  313. * RETURNS:
  314. *
  315. * 0 on success or a negative error code on failure.
  316. */
  317. int (*disable_plane)(struct drm_plane *plane,
  318. struct drm_modeset_acquire_ctx *ctx);
  319. /**
  320. * @destroy:
  321. *
  322. * Clean up plane resources. This is only called at driver unload time
  323. * through drm_mode_config_cleanup() since a plane cannot be hotplugged
  324. * in DRM.
  325. */
  326. void (*destroy)(struct drm_plane *plane);
  327. /**
  328. * @reset:
  329. *
  330. * Reset plane hardware and software state to off. This function isn't
  331. * called by the core directly, only through drm_mode_config_reset().
  332. * It's not a helper hook only for historical reasons.
  333. *
  334. * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
  335. * atomic state using this hook.
  336. */
  337. void (*reset)(struct drm_plane *plane);
  338. /**
  339. * @set_property:
  340. *
  341. * This is the legacy entry point to update a property attached to the
  342. * plane.
  343. *
  344. * This callback is optional if the driver does not support any legacy
  345. * driver-private properties. For atomic drivers it is not used because
  346. * property handling is done entirely in the DRM core.
  347. *
  348. * RETURNS:
  349. *
  350. * 0 on success or a negative error code on failure.
  351. */
  352. int (*set_property)(struct drm_plane *plane,
  353. struct drm_property *property, uint64_t val);
  354. /**
  355. * @atomic_duplicate_state:
  356. *
  357. * Duplicate the current atomic state for this plane and return it.
  358. * The core and helpers guarantee that any atomic state duplicated with
  359. * this hook and still owned by the caller (i.e. not transferred to the
  360. * driver by calling &drm_mode_config_funcs.atomic_commit) will be
  361. * cleaned up by calling the @atomic_destroy_state hook in this
  362. * structure.
  363. *
  364. * This callback is mandatory for atomic drivers.
  365. *
  366. * Atomic drivers which don't subclass &struct drm_plane_state should use
  367. * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
  368. * state structure to extend it with driver-private state should use
  369. * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
  370. * duplicated in a consistent fashion across drivers.
  371. *
  372. * It is an error to call this hook before &drm_plane.state has been
  373. * initialized correctly.
  374. *
  375. * NOTE:
  376. *
  377. * If the duplicate state references refcounted resources this hook must
  378. * acquire a reference for each of them. The driver must release these
  379. * references again in @atomic_destroy_state.
  380. *
  381. * RETURNS:
  382. *
  383. * Duplicated atomic state or NULL when the allocation failed.
  384. */
  385. struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
  386. /**
  387. * @atomic_destroy_state:
  388. *
  389. * Destroy a state duplicated with @atomic_duplicate_state and release
  390. * or unreference all resources it references
  391. *
  392. * This callback is mandatory for atomic drivers.
  393. */
  394. void (*atomic_destroy_state)(struct drm_plane *plane,
  395. struct drm_plane_state *state);
  396. /**
  397. * @atomic_set_property:
  398. *
  399. * Decode a driver-private property value and store the decoded value
  400. * into the passed-in state structure. Since the atomic core decodes all
  401. * standardized properties (even for extensions beyond the core set of
  402. * properties which might not be implemented by all drivers) this
  403. * requires drivers to subclass the state structure.
  404. *
  405. * Such driver-private properties should really only be implemented for
  406. * truly hardware/vendor specific state. Instead it is preferred to
  407. * standardize atomic extension and decode the properties used to expose
  408. * such an extension in the core.
  409. *
  410. * Do not call this function directly, use
  411. * drm_atomic_plane_set_property() instead.
  412. *
  413. * This callback is optional if the driver does not support any
  414. * driver-private atomic properties.
  415. *
  416. * NOTE:
  417. *
  418. * This function is called in the state assembly phase of atomic
  419. * modesets, which can be aborted for any reason (including on
  420. * userspace's request to just check whether a configuration would be
  421. * possible). Drivers MUST NOT touch any persistent state (hardware or
  422. * software) or data structures except the passed in @state parameter.
  423. *
  424. * Also since userspace controls in which order properties are set this
  425. * function must not do any input validation (since the state update is
  426. * incomplete and hence likely inconsistent). Instead any such input
  427. * validation must be done in the various atomic_check callbacks.
  428. *
  429. * RETURNS:
  430. *
  431. * 0 if the property has been found, -EINVAL if the property isn't
  432. * implemented by the driver (which shouldn't ever happen, the core only
  433. * asks for properties attached to this plane). No other validation is
  434. * allowed by the driver. The core already checks that the property
  435. * value is within the range (integer, valid enum value, ...) the driver
  436. * set when registering the property.
  437. */
  438. int (*atomic_set_property)(struct drm_plane *plane,
  439. struct drm_plane_state *state,
  440. struct drm_property *property,
  441. uint64_t val);
  442. /**
  443. * @atomic_get_property:
  444. *
  445. * Reads out the decoded driver-private property. This is used to
  446. * implement the GETPLANE IOCTL.
  447. *
  448. * Do not call this function directly, use
  449. * drm_atomic_plane_get_property() instead.
  450. *
  451. * This callback is optional if the driver does not support any
  452. * driver-private atomic properties.
  453. *
  454. * RETURNS:
  455. *
  456. * 0 on success, -EINVAL if the property isn't implemented by the
  457. * driver (which should never happen, the core only asks for
  458. * properties attached to this plane).
  459. */
  460. int (*atomic_get_property)(struct drm_plane *plane,
  461. const struct drm_plane_state *state,
  462. struct drm_property *property,
  463. uint64_t *val);
  464. /**
  465. * @late_register:
  466. *
  467. * This optional hook can be used to register additional userspace
  468. * interfaces attached to the plane like debugfs interfaces.
  469. * It is called late in the driver load sequence from drm_dev_register().
  470. * Everything added from this callback should be unregistered in
  471. * the early_unregister callback.
  472. *
  473. * Returns:
  474. *
  475. * 0 on success, or a negative error code on failure.
  476. */
  477. int (*late_register)(struct drm_plane *plane);
  478. /**
  479. * @early_unregister:
  480. *
  481. * This optional hook should be used to unregister the additional
  482. * userspace interfaces attached to the plane from
  483. * @late_register. It is called from drm_dev_unregister(),
  484. * early in the driver unload sequence to disable userspace access
  485. * before data structures are torndown.
  486. */
  487. void (*early_unregister)(struct drm_plane *plane);
  488. /**
  489. * @atomic_print_state:
  490. *
  491. * If driver subclasses &struct drm_plane_state, it should implement
  492. * this optional hook for printing additional driver specific state.
  493. *
  494. * Do not call this directly, use drm_atomic_plane_print_state()
  495. * instead.
  496. */
  497. void (*atomic_print_state)(struct drm_printer *p,
  498. const struct drm_plane_state *state);
  499. /**
  500. * @format_mod_supported:
  501. *
  502. * This optional hook is used for the DRM to determine if the given
  503. * format/modifier combination is valid for the plane. This allows the
  504. * DRM to generate the correct format bitmask (which formats apply to
  505. * which modifier), and to validate modifiers at atomic_check time.
  506. *
  507. * If not present, then any modifier in the plane's modifier
  508. * list is allowed with any of the plane's formats.
  509. *
  510. * Returns:
  511. *
  512. * True if the given modifier is valid for that format on the plane.
  513. * False otherwise.
  514. */
  515. bool (*format_mod_supported)(struct drm_plane *plane, uint32_t format,
  516. uint64_t modifier);
  517. /**
  518. * @format_mod_supported_async:
  519. *
  520. * This optional hook is used for the DRM to determine if for
  521. * asynchronous flip the given format/modifier combination is valid for
  522. * the plane. This allows the DRM to generate the correct format
  523. * bitmask (which formats apply to which modifier), and to validate
  524. * modifiers at atomic_check time.
  525. *
  526. * Returns:
  527. *
  528. * True if the given modifier is valid for that format on the plane.
  529. * False otherwise.
  530. */
  531. bool (*format_mod_supported_async)(struct drm_plane *plane,
  532. u32 format, u64 modifier);
  533. };
  534. /**
  535. * enum drm_plane_type - uapi plane type enumeration
  536. *
  537. * For historical reasons not all planes are made the same. This enumeration is
  538. * used to tell the different types of planes apart to implement the different
  539. * uapi semantics for them. For userspace which is universal plane aware and
  540. * which is using that atomic IOCTL there's no difference between these planes
  541. * (beyong what the driver and hardware can support of course).
  542. *
  543. * For compatibility with legacy userspace, only overlay planes are made
  544. * available to userspace by default. Userspace clients may set the
  545. * &DRM_CLIENT_CAP_UNIVERSAL_PLANES client capability bit to indicate that they
  546. * wish to receive a universal plane list containing all plane types. See also
  547. * drm_for_each_legacy_plane().
  548. *
  549. * In addition to setting each plane's type, drivers need to setup the
  550. * &drm_crtc.primary and optionally &drm_crtc.cursor pointers for legacy
  551. * IOCTLs. See drm_crtc_init_with_planes().
  552. *
  553. * WARNING: The values of this enum is UABI since they're exposed in the "type"
  554. * property.
  555. */
  556. enum drm_plane_type {
  557. /**
  558. * @DRM_PLANE_TYPE_OVERLAY:
  559. *
  560. * Overlay planes represent all non-primary, non-cursor planes. Some
  561. * drivers refer to these types of planes as "sprites" internally.
  562. */
  563. DRM_PLANE_TYPE_OVERLAY,
  564. /**
  565. * @DRM_PLANE_TYPE_PRIMARY:
  566. *
  567. * A primary plane attached to a CRTC is the most likely to be able to
  568. * light up the CRTC when no scaling/cropping is used and the plane
  569. * covers the whole CRTC.
  570. */
  571. DRM_PLANE_TYPE_PRIMARY,
  572. /**
  573. * @DRM_PLANE_TYPE_CURSOR:
  574. *
  575. * A cursor plane attached to a CRTC is more likely to be able to be
  576. * enabled when no scaling/cropping is used and the framebuffer has the
  577. * size indicated by &drm_mode_config.cursor_width and
  578. * &drm_mode_config.cursor_height. Additionally, if the driver doesn't
  579. * support modifiers, the framebuffer should have a linear layout.
  580. */
  581. DRM_PLANE_TYPE_CURSOR,
  582. };
  583. /**
  584. * struct drm_plane - central DRM plane control structure
  585. *
  586. * Planes represent the scanout hardware of a display block. They receive their
  587. * input data from a &drm_framebuffer and feed it to a &drm_crtc. Planes control
  588. * the color conversion, see `Plane Composition Properties`_ for more details,
  589. * and are also involved in the color conversion of input pixels, see `Color
  590. * Management Properties`_ for details on that.
  591. */
  592. struct drm_plane {
  593. /** @dev: DRM device this plane belongs to */
  594. struct drm_device *dev;
  595. /**
  596. * @head:
  597. *
  598. * List of all planes on @dev, linked from &drm_mode_config.plane_list.
  599. * Invariant over the lifetime of @dev and therefore does not need
  600. * locking.
  601. */
  602. struct list_head head;
  603. /** @name: human readable name, can be overwritten by the driver */
  604. char *name;
  605. /**
  606. * @mutex:
  607. *
  608. * Protects modeset plane state, together with the &drm_crtc.mutex of
  609. * CRTC this plane is linked to (when active, getting activated or
  610. * getting disabled).
  611. *
  612. * For atomic drivers specifically this protects @state.
  613. */
  614. struct drm_modeset_lock mutex;
  615. /** @base: base mode object */
  616. struct drm_mode_object base;
  617. /**
  618. * @possible_crtcs: pipes this plane can be bound to constructed from
  619. * drm_crtc_mask()
  620. */
  621. uint32_t possible_crtcs;
  622. /** @format_types: array of formats supported by this plane */
  623. uint32_t *format_types;
  624. /** @format_count: Size of the array pointed at by @format_types. */
  625. unsigned int format_count;
  626. /**
  627. * @format_default: driver hasn't supplied supported formats for the
  628. * plane. Used by the non-atomic driver compatibility wrapper only.
  629. */
  630. bool format_default;
  631. /** @modifiers: array of modifiers supported by this plane */
  632. uint64_t *modifiers;
  633. /** @modifier_count: Size of the array pointed at by @modifier_count. */
  634. unsigned int modifier_count;
  635. /**
  636. * @crtc:
  637. *
  638. * Currently bound CRTC, only meaningful for non-atomic drivers. For
  639. * atomic drivers this is forced to be NULL, atomic drivers should
  640. * instead check &drm_plane_state.crtc.
  641. */
  642. struct drm_crtc *crtc;
  643. /**
  644. * @fb:
  645. *
  646. * Currently bound framebuffer, only meaningful for non-atomic drivers.
  647. * For atomic drivers this is forced to be NULL, atomic drivers should
  648. * instead check &drm_plane_state.fb.
  649. */
  650. struct drm_framebuffer *fb;
  651. /**
  652. * @old_fb:
  653. *
  654. * Temporary tracking of the old fb while a modeset is ongoing. Only
  655. * used by non-atomic drivers, forced to be NULL for atomic drivers.
  656. */
  657. struct drm_framebuffer *old_fb;
  658. /** @funcs: plane control functions */
  659. const struct drm_plane_funcs *funcs;
  660. /** @properties: property tracking for this plane */
  661. struct drm_object_properties properties;
  662. /** @type: Type of plane, see &enum drm_plane_type for details. */
  663. enum drm_plane_type type;
  664. /**
  665. * @index: Position inside the mode_config.list, can be used as an array
  666. * index. It is invariant over the lifetime of the plane.
  667. */
  668. unsigned index;
  669. /** @helper_private: mid-layer private data */
  670. const struct drm_plane_helper_funcs *helper_private;
  671. /**
  672. * @state:
  673. *
  674. * Current atomic state for this plane.
  675. *
  676. * This is protected by @mutex. Note that nonblocking atomic commits
  677. * access the current plane state without taking locks. Either by going
  678. * through the &struct drm_atomic_state pointers, see
  679. * for_each_oldnew_plane_in_state(), for_each_old_plane_in_state() and
  680. * for_each_new_plane_in_state(). Or through careful ordering of atomic
  681. * commit operations as implemented in the atomic helpers, see
  682. * &struct drm_crtc_commit.
  683. */
  684. struct drm_plane_state *state;
  685. /**
  686. * @alpha_property:
  687. * Optional alpha property for this plane. See
  688. * drm_plane_create_alpha_property().
  689. */
  690. struct drm_property *alpha_property;
  691. /**
  692. * @zpos_property:
  693. * Optional zpos property for this plane. See
  694. * drm_plane_create_zpos_property().
  695. */
  696. struct drm_property *zpos_property;
  697. /**
  698. * @rotation_property:
  699. * Optional rotation property for this plane. See
  700. * drm_plane_create_rotation_property().
  701. */
  702. struct drm_property *rotation_property;
  703. /**
  704. * @blend_mode_property:
  705. * Optional "pixel blend mode" enum property for this plane.
  706. * Blend mode property represents the alpha blending equation selection,
  707. * describing how the pixels from the current plane are composited with
  708. * the background.
  709. */
  710. struct drm_property *blend_mode_property;
  711. /**
  712. * @color_encoding_property:
  713. *
  714. * Optional "COLOR_ENCODING" enum property for specifying
  715. * color encoding for non RGB formats.
  716. * See drm_plane_create_color_properties().
  717. */
  718. struct drm_property *color_encoding_property;
  719. /**
  720. * @color_range_property:
  721. *
  722. * Optional "COLOR_RANGE" enum property for specifying
  723. * color range for non RGB formats.
  724. * See drm_plane_create_color_properties().
  725. */
  726. struct drm_property *color_range_property;
  727. /**
  728. * @color_pipeline_property:
  729. *
  730. * Optional "COLOR_PIPELINE" enum property for specifying
  731. * a color pipeline to use on the plane.
  732. */
  733. struct drm_property *color_pipeline_property;
  734. /**
  735. * @scaling_filter_property: property to apply a particular filter while
  736. * scaling.
  737. */
  738. struct drm_property *scaling_filter_property;
  739. /**
  740. * @hotspot_x_property: property to set mouse hotspot x offset.
  741. */
  742. struct drm_property *hotspot_x_property;
  743. /**
  744. * @hotspot_y_property: property to set mouse hotspot y offset.
  745. */
  746. struct drm_property *hotspot_y_property;
  747. /**
  748. * @kmsg_panic: Used to register a panic notifier for this plane
  749. */
  750. struct kmsg_dumper kmsg_panic;
  751. };
  752. #define obj_to_plane(x) container_of(x, struct drm_plane, base)
  753. __printf(9, 10)
  754. int drm_universal_plane_init(struct drm_device *dev,
  755. struct drm_plane *plane,
  756. uint32_t possible_crtcs,
  757. const struct drm_plane_funcs *funcs,
  758. const uint32_t *formats,
  759. unsigned int format_count,
  760. const uint64_t *format_modifiers,
  761. enum drm_plane_type type,
  762. const char *name, ...);
  763. void drm_plane_cleanup(struct drm_plane *plane);
  764. __printf(10, 11)
  765. void *__drmm_universal_plane_alloc(struct drm_device *dev,
  766. size_t size, size_t offset,
  767. uint32_t possible_crtcs,
  768. const struct drm_plane_funcs *funcs,
  769. const uint32_t *formats,
  770. unsigned int format_count,
  771. const uint64_t *format_modifiers,
  772. enum drm_plane_type plane_type,
  773. const char *name, ...);
  774. /**
  775. * drmm_universal_plane_alloc - Allocate and initialize an universal plane object
  776. * @dev: DRM device
  777. * @type: the type of the struct which contains struct &drm_plane
  778. * @member: the name of the &drm_plane within @type
  779. * @possible_crtcs: bitmask of possible CRTCs
  780. * @funcs: callbacks for the new plane
  781. * @formats: array of supported formats (DRM_FORMAT\_\*)
  782. * @format_count: number of elements in @formats
  783. * @format_modifiers: array of struct drm_format modifiers terminated by
  784. * DRM_FORMAT_MOD_INVALID
  785. * @plane_type: type of plane (overlay, primary, cursor)
  786. * @name: printf style format string for the plane name, or NULL for default name
  787. *
  788. * Allocates and initializes a plane object of type @type. Cleanup is
  789. * automatically handled through registering drm_plane_cleanup() with
  790. * drmm_add_action().
  791. *
  792. * The @drm_plane_funcs.destroy hook must be NULL.
  793. *
  794. * Drivers that only support the DRM_FORMAT_MOD_LINEAR modifier support may set
  795. * @format_modifiers to NULL. The plane will advertise the linear modifier.
  796. *
  797. * Returns:
  798. * Pointer to new plane, or ERR_PTR on failure.
  799. */
  800. #define drmm_universal_plane_alloc(dev, type, member, possible_crtcs, funcs, formats, \
  801. format_count, format_modifiers, plane_type, name, ...) \
  802. ((type *)__drmm_universal_plane_alloc(dev, sizeof(type), \
  803. offsetof(type, member), \
  804. possible_crtcs, funcs, formats, \
  805. format_count, format_modifiers, \
  806. plane_type, name, ##__VA_ARGS__))
  807. __printf(10, 11)
  808. void *__drm_universal_plane_alloc(struct drm_device *dev,
  809. size_t size, size_t offset,
  810. uint32_t possible_crtcs,
  811. const struct drm_plane_funcs *funcs,
  812. const uint32_t *formats,
  813. unsigned int format_count,
  814. const uint64_t *format_modifiers,
  815. enum drm_plane_type plane_type,
  816. const char *name, ...);
  817. /**
  818. * drm_universal_plane_alloc() - Allocate and initialize an universal plane object
  819. * @dev: DRM device
  820. * @type: the type of the struct which contains struct &drm_plane
  821. * @member: the name of the &drm_plane within @type
  822. * @possible_crtcs: bitmask of possible CRTCs
  823. * @funcs: callbacks for the new plane
  824. * @formats: array of supported formats (DRM_FORMAT\_\*)
  825. * @format_count: number of elements in @formats
  826. * @format_modifiers: array of struct drm_format modifiers terminated by
  827. * DRM_FORMAT_MOD_INVALID
  828. * @plane_type: type of plane (overlay, primary, cursor)
  829. * @name: printf style format string for the plane name, or NULL for default name
  830. *
  831. * Allocates and initializes a plane object of type @type. The caller
  832. * is responsible for releasing the allocated memory with kfree().
  833. *
  834. * Drivers are encouraged to use drmm_universal_plane_alloc() instead.
  835. *
  836. * Drivers that only support the DRM_FORMAT_MOD_LINEAR modifier support may set
  837. * @format_modifiers to NULL. The plane will advertise the linear modifier.
  838. *
  839. * Returns:
  840. * Pointer to new plane, or ERR_PTR on failure.
  841. */
  842. #define drm_universal_plane_alloc(dev, type, member, possible_crtcs, funcs, formats, \
  843. format_count, format_modifiers, plane_type, name, ...) \
  844. ((type *)__drm_universal_plane_alloc(dev, sizeof(type), \
  845. offsetof(type, member), \
  846. possible_crtcs, funcs, formats, \
  847. format_count, format_modifiers, \
  848. plane_type, name, ##__VA_ARGS__))
  849. /**
  850. * drm_plane_index - find the index of a registered plane
  851. * @plane: plane to find index for
  852. *
  853. * Given a registered plane, return the index of that plane within a DRM
  854. * device's list of planes.
  855. */
  856. static inline unsigned int drm_plane_index(const struct drm_plane *plane)
  857. {
  858. return plane->index;
  859. }
  860. /**
  861. * drm_plane_mask - find the mask of a registered plane
  862. * @plane: plane to find mask for
  863. */
  864. static inline u32 drm_plane_mask(const struct drm_plane *plane)
  865. {
  866. return 1 << drm_plane_index(plane);
  867. }
  868. struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
  869. void drm_plane_force_disable(struct drm_plane *plane);
  870. int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
  871. struct drm_property *property,
  872. uint64_t value);
  873. /**
  874. * drm_plane_find - find a &drm_plane
  875. * @dev: DRM device
  876. * @file_priv: drm file to check for lease against.
  877. * @id: plane id
  878. *
  879. * Returns the plane with @id, NULL if it doesn't exist. Simple wrapper around
  880. * drm_mode_object_find().
  881. */
  882. static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
  883. struct drm_file *file_priv,
  884. uint32_t id)
  885. {
  886. struct drm_mode_object *mo;
  887. mo = drm_mode_object_find(dev, file_priv, id, DRM_MODE_OBJECT_PLANE);
  888. return mo ? obj_to_plane(mo) : NULL;
  889. }
  890. /**
  891. * drm_for_each_plane_mask - iterate over planes specified by bitmask
  892. * @plane: the loop cursor
  893. * @dev: the DRM device
  894. * @plane_mask: bitmask of plane indices
  895. *
  896. * Iterate over all planes specified by bitmask.
  897. */
  898. #define drm_for_each_plane_mask(plane, dev, plane_mask) \
  899. list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
  900. for_each_if ((plane_mask) & drm_plane_mask(plane))
  901. /**
  902. * drm_for_each_legacy_plane - iterate over all planes for legacy userspace
  903. * @plane: the loop cursor
  904. * @dev: the DRM device
  905. *
  906. * Iterate over all legacy planes of @dev, excluding primary and cursor planes.
  907. * This is useful for implementing userspace apis when userspace is not
  908. * universal plane aware. See also &enum drm_plane_type.
  909. */
  910. #define drm_for_each_legacy_plane(plane, dev) \
  911. list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
  912. for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
  913. /**
  914. * drm_for_each_plane - iterate over all planes
  915. * @plane: the loop cursor
  916. * @dev: the DRM device
  917. *
  918. * Iterate over all planes of @dev, include primary and cursor planes.
  919. */
  920. #define drm_for_each_plane(plane, dev) \
  921. list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
  922. bool drm_plane_has_format(struct drm_plane *plane,
  923. u32 format, u64 modifier);
  924. bool drm_any_plane_has_format(struct drm_device *dev,
  925. u32 format, u64 modifier);
  926. void drm_plane_enable_fb_damage_clips(struct drm_plane *plane);
  927. unsigned int
  928. drm_plane_get_damage_clips_count(const struct drm_plane_state *state);
  929. struct drm_mode_rect *
  930. drm_plane_get_damage_clips(const struct drm_plane_state *state);
  931. int drm_plane_create_scaling_filter_property(struct drm_plane *plane,
  932. unsigned int supported_filters);
  933. int drm_plane_add_size_hints_property(struct drm_plane *plane,
  934. const struct drm_plane_size_hint *hints,
  935. int num_hints);
  936. int drm_plane_create_color_pipeline_property(struct drm_plane *plane,
  937. const struct drm_prop_enum_list *pipelines,
  938. int num_pipelines);
  939. #endif