drm_plane.c 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795
  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. #include <linux/slab.h>
  23. #include <linux/uaccess.h>
  24. #include <drm/drm_plane.h>
  25. #include <drm/drm_drv.h>
  26. #include <drm/drm_print.h>
  27. #include <drm/drm_framebuffer.h>
  28. #include <drm/drm_file.h>
  29. #include <drm/drm_crtc.h>
  30. #include <drm/drm_fourcc.h>
  31. #include <drm/drm_managed.h>
  32. #include <drm/drm_vblank.h>
  33. #include "drm_crtc_internal.h"
  34. /**
  35. * DOC: overview
  36. *
  37. * A plane represents an image source that can be blended with or overlaid on
  38. * top of a CRTC during the scanout process. Planes take their input data from a
  39. * &drm_framebuffer object. The plane itself specifies the cropping and scaling
  40. * of that image, and where it is placed on the visible area of a display
  41. * pipeline, represented by &drm_crtc. A plane can also have additional
  42. * properties that specify how the pixels are positioned and blended, like
  43. * rotation or Z-position. All these properties are stored in &drm_plane_state.
  44. *
  45. * Unless explicitly specified (via CRTC property or otherwise), the active area
  46. * of a CRTC will be black by default. This means portions of the active area
  47. * which are not covered by a plane will be black, and alpha blending of any
  48. * planes with the CRTC background will blend with black at the lowest zpos.
  49. *
  50. * To create a plane, a KMS drivers allocates and zeroes an instances of
  51. * &struct drm_plane (possibly as part of a larger structure) and registers it
  52. * with a call to drm_universal_plane_init().
  53. *
  54. * Each plane has a type, see enum drm_plane_type. A plane can be compatible
  55. * with multiple CRTCs, see &drm_plane.possible_crtcs.
  56. *
  57. * Each CRTC must have a unique primary plane userspace can attach to enable
  58. * the CRTC. In other words, userspace must be able to attach a different
  59. * primary plane to each CRTC at the same time. Primary planes can still be
  60. * compatible with multiple CRTCs. There must be exactly as many primary planes
  61. * as there are CRTCs.
  62. *
  63. * Legacy uAPI doesn't expose the primary and cursor planes directly. DRM core
  64. * relies on the driver to set the primary and optionally the cursor plane used
  65. * for legacy IOCTLs. This is done by calling drm_crtc_init_with_planes(). All
  66. * drivers must provide one primary plane per CRTC to avoid surprising legacy
  67. * userspace too much.
  68. */
  69. /**
  70. * DOC: standard plane properties
  71. *
  72. * DRM planes have a few standardized properties:
  73. *
  74. * type:
  75. * Immutable property describing the type of the plane.
  76. *
  77. * For user-space which has enabled the &DRM_CLIENT_CAP_ATOMIC capability,
  78. * the plane type is just a hint and is mostly superseded by atomic
  79. * test-only commits. The type hint can still be used to come up more
  80. * easily with a plane configuration accepted by the driver.
  81. *
  82. * The value of this property can be one of the following:
  83. *
  84. * "Primary":
  85. * To light up a CRTC, attaching a primary plane is the most likely to
  86. * work if it covers the whole CRTC and doesn't have scaling or
  87. * cropping set up.
  88. *
  89. * Drivers may support more features for the primary plane, user-space
  90. * can find out with test-only atomic commits.
  91. *
  92. * Some primary planes are implicitly used by the kernel in the legacy
  93. * IOCTLs &DRM_IOCTL_MODE_SETCRTC and &DRM_IOCTL_MODE_PAGE_FLIP.
  94. * Therefore user-space must not mix explicit usage of any primary
  95. * plane (e.g. through an atomic commit) with these legacy IOCTLs.
  96. *
  97. * "Cursor":
  98. * To enable this plane, using a framebuffer configured without scaling
  99. * or cropping and with the following properties is the most likely to
  100. * work:
  101. *
  102. * - If the driver provides the capabilities &DRM_CAP_CURSOR_WIDTH and
  103. * &DRM_CAP_CURSOR_HEIGHT, create the framebuffer with this size.
  104. * Otherwise, create a framebuffer with the size 64x64.
  105. * - If the driver doesn't support modifiers, create a framebuffer with
  106. * a linear layout. Otherwise, use the IN_FORMATS plane property.
  107. *
  108. * Drivers may support more features for the cursor plane, user-space
  109. * can find out with test-only atomic commits.
  110. *
  111. * Some cursor planes are implicitly used by the kernel in the legacy
  112. * IOCTLs &DRM_IOCTL_MODE_CURSOR and &DRM_IOCTL_MODE_CURSOR2.
  113. * Therefore user-space must not mix explicit usage of any cursor
  114. * plane (e.g. through an atomic commit) with these legacy IOCTLs.
  115. *
  116. * Some drivers may support cursors even if no cursor plane is exposed.
  117. * In this case, the legacy cursor IOCTLs can be used to configure the
  118. * cursor.
  119. *
  120. * "Overlay":
  121. * Neither primary nor cursor.
  122. *
  123. * Overlay planes are the only planes exposed when the
  124. * &DRM_CLIENT_CAP_UNIVERSAL_PLANES capability is disabled.
  125. *
  126. * IN_FORMATS:
  127. * Blob property which contains the set of buffer format and modifier
  128. * pairs supported by this plane. The blob is a struct
  129. * drm_format_modifier_blob. Without this property the plane doesn't
  130. * support buffers with modifiers. Userspace cannot change this property.
  131. *
  132. * Note that userspace can check the &DRM_CAP_ADDFB2_MODIFIERS driver
  133. * capability for general modifier support. If this flag is set then every
  134. * plane will have the IN_FORMATS property, even when it only supports
  135. * DRM_FORMAT_MOD_LINEAR. Before linux kernel release v5.1 there have been
  136. * various bugs in this area with inconsistencies between the capability
  137. * flag and per-plane properties.
  138. *
  139. * SIZE_HINTS:
  140. * Blob property which contains the set of recommended plane size
  141. * which can used for simple "cursor like" use cases (eg. no scaling).
  142. * Using these hints frees userspace from extensive probing of
  143. * supported plane sizes through atomic/setcursor ioctls.
  144. *
  145. * The blob contains an array of struct drm_plane_size_hint, in
  146. * order of preference. For optimal usage userspace should pick
  147. * the first size that satisfies its own requirements.
  148. *
  149. * Drivers should only attach this property to planes that
  150. * support a very limited set of sizes.
  151. *
  152. * Note that property value 0 (ie. no blob) is reserved for potential
  153. * future use. Current userspace is expected to ignore the property
  154. * if the value is 0, and fall back to some other means (eg.
  155. * &DRM_CAP_CURSOR_WIDTH and &DRM_CAP_CURSOR_HEIGHT) to determine
  156. * the appropriate plane size to use.
  157. */
  158. static unsigned int drm_num_planes(struct drm_device *dev)
  159. {
  160. unsigned int num = 0;
  161. struct drm_plane *tmp;
  162. drm_for_each_plane(tmp, dev) {
  163. num++;
  164. }
  165. return num;
  166. }
  167. static inline u32 *
  168. formats_ptr(struct drm_format_modifier_blob *blob)
  169. {
  170. return (u32 *)(((char *)blob) + blob->formats_offset);
  171. }
  172. static inline struct drm_format_modifier *
  173. modifiers_ptr(struct drm_format_modifier_blob *blob)
  174. {
  175. return (struct drm_format_modifier *)(((char *)blob) + blob->modifiers_offset);
  176. }
  177. static int create_in_format_blob(struct drm_device *dev, struct drm_plane *plane)
  178. {
  179. const struct drm_mode_config *config = &dev->mode_config;
  180. struct drm_property_blob *blob;
  181. struct drm_format_modifier *mod;
  182. size_t blob_size, formats_size, modifiers_size;
  183. struct drm_format_modifier_blob *blob_data;
  184. unsigned int i, j;
  185. formats_size = sizeof(__u32) * plane->format_count;
  186. if (WARN_ON(!formats_size)) {
  187. /* 0 formats are never expected */
  188. return 0;
  189. }
  190. modifiers_size =
  191. sizeof(struct drm_format_modifier) * plane->modifier_count;
  192. blob_size = sizeof(struct drm_format_modifier_blob);
  193. /* Modifiers offset is a pointer to a struct with a 64 bit field so it
  194. * should be naturally aligned to 8B.
  195. */
  196. BUILD_BUG_ON(sizeof(struct drm_format_modifier_blob) % 8);
  197. blob_size += ALIGN(formats_size, 8);
  198. blob_size += modifiers_size;
  199. blob = drm_property_create_blob(dev, blob_size, NULL);
  200. if (IS_ERR(blob))
  201. return -1;
  202. blob_data = blob->data;
  203. blob_data->version = FORMAT_BLOB_CURRENT;
  204. blob_data->count_formats = plane->format_count;
  205. blob_data->formats_offset = sizeof(struct drm_format_modifier_blob);
  206. blob_data->count_modifiers = plane->modifier_count;
  207. blob_data->modifiers_offset =
  208. ALIGN(blob_data->formats_offset + formats_size, 8);
  209. memcpy(formats_ptr(blob_data), plane->format_types, formats_size);
  210. mod = modifiers_ptr(blob_data);
  211. for (i = 0; i < plane->modifier_count; i++) {
  212. for (j = 0; j < plane->format_count; j++) {
  213. if (!plane->funcs->format_mod_supported ||
  214. plane->funcs->format_mod_supported(plane,
  215. plane->format_types[j],
  216. plane->modifiers[i])) {
  217. mod->formats |= 1ULL << j;
  218. }
  219. }
  220. mod->modifier = plane->modifiers[i];
  221. mod->offset = 0;
  222. mod->pad = 0;
  223. mod++;
  224. }
  225. drm_object_attach_property(&plane->base, config->modifiers_property,
  226. blob->base.id);
  227. return 0;
  228. }
  229. /**
  230. * DOC: hotspot properties
  231. *
  232. * HOTSPOT_X: property to set mouse hotspot x offset.
  233. * HOTSPOT_Y: property to set mouse hotspot y offset.
  234. *
  235. * When the plane is being used as a cursor image to display a mouse pointer,
  236. * the "hotspot" is the offset within the cursor image where mouse events
  237. * are expected to go.
  238. *
  239. * Positive values move the hotspot from the top-left corner of the cursor
  240. * plane towards the right and bottom.
  241. *
  242. * Most display drivers do not need this information because the
  243. * hotspot is not actually connected to anything visible on screen.
  244. * However, this is necessary for display drivers like the para-virtualized
  245. * drivers (eg qxl, vbox, virtio, vmwgfx), that are attached to a user console
  246. * with a mouse pointer. Since these consoles are often being remoted over a
  247. * network, they would otherwise have to wait to display the pointer movement to
  248. * the user until a full network round-trip has occurred. New mouse events have
  249. * to be sent from the user's console, over the network to the virtual input
  250. * devices, forwarded to the desktop for processing, and then the cursor plane's
  251. * position can be updated and sent back to the user's console over the network.
  252. * Instead, with the hotspot information, the console can anticipate the new
  253. * location, and draw the mouse cursor there before the confirmation comes in.
  254. * To do that correctly, the user's console must be able predict how the
  255. * desktop will process mouse events, which normally requires the desktop's
  256. * mouse topology information, ie where each CRTC sits in the mouse coordinate
  257. * space. This is typically sent to the para-virtualized drivers using some
  258. * driver-specific method, and the driver then forwards it to the console by
  259. * way of the virtual display device or hypervisor.
  260. *
  261. * The assumption is generally made that there is only one cursor plane being
  262. * used this way at a time, and that the desktop is feeding all mouse devices
  263. * into the same global pointer. Para-virtualized drivers that require this
  264. * should only be exposing a single cursor plane, or find some other way
  265. * to coordinate with a userspace desktop that supports multiple pointers.
  266. * If the hotspot properties are set, the cursor plane is therefore assumed to be
  267. * used only for displaying a mouse cursor image, and the position of the combined
  268. * cursor plane + offset can therefore be used for coordinating with input from a
  269. * mouse device.
  270. *
  271. * The cursor will then be drawn either at the location of the plane in the CRTC
  272. * console, or as a free-floating cursor plane on the user's console
  273. * corresponding to their desktop mouse position.
  274. *
  275. * DRM clients which would like to work correctly on drivers which expose
  276. * hotspot properties should advertise DRM_CLIENT_CAP_CURSOR_PLANE_HOTSPOT.
  277. * Setting this property on drivers which do not special case
  278. * cursor planes will return EOPNOTSUPP, which can be used by userspace to
  279. * gauge requirements of the hardware/drivers they're running on. Advertising
  280. * DRM_CLIENT_CAP_CURSOR_PLANE_HOTSPOT implies that the userspace client will be
  281. * correctly setting the hotspot properties.
  282. */
  283. /**
  284. * drm_plane_create_hotspot_properties - creates the mouse hotspot
  285. * properties and attaches them to the given cursor plane
  286. *
  287. * @plane: drm cursor plane
  288. *
  289. * This function enables the mouse hotspot property on a given
  290. * cursor plane. Look at the documentation for hotspot properties
  291. * to get a better understanding for what they're used for.
  292. *
  293. * RETURNS:
  294. * Zero for success or -errno
  295. */
  296. static int drm_plane_create_hotspot_properties(struct drm_plane *plane)
  297. {
  298. struct drm_property *prop_x;
  299. struct drm_property *prop_y;
  300. drm_WARN_ON(plane->dev,
  301. !drm_core_check_feature(plane->dev,
  302. DRIVER_CURSOR_HOTSPOT));
  303. prop_x = drm_property_create_signed_range(plane->dev, 0, "HOTSPOT_X",
  304. INT_MIN, INT_MAX);
  305. if (IS_ERR(prop_x))
  306. return PTR_ERR(prop_x);
  307. prop_y = drm_property_create_signed_range(plane->dev, 0, "HOTSPOT_Y",
  308. INT_MIN, INT_MAX);
  309. if (IS_ERR(prop_y)) {
  310. drm_property_destroy(plane->dev, prop_x);
  311. return PTR_ERR(prop_y);
  312. }
  313. drm_object_attach_property(&plane->base, prop_x, 0);
  314. drm_object_attach_property(&plane->base, prop_y, 0);
  315. plane->hotspot_x_property = prop_x;
  316. plane->hotspot_y_property = prop_y;
  317. return 0;
  318. }
  319. __printf(9, 0)
  320. static int __drm_universal_plane_init(struct drm_device *dev,
  321. struct drm_plane *plane,
  322. uint32_t possible_crtcs,
  323. const struct drm_plane_funcs *funcs,
  324. const uint32_t *formats,
  325. unsigned int format_count,
  326. const uint64_t *format_modifiers,
  327. enum drm_plane_type type,
  328. const char *name, va_list ap)
  329. {
  330. struct drm_mode_config *config = &dev->mode_config;
  331. static const uint64_t default_modifiers[] = {
  332. DRM_FORMAT_MOD_LINEAR,
  333. };
  334. unsigned int format_modifier_count = 0;
  335. int ret;
  336. /* plane index is used with 32bit bitmasks */
  337. if (WARN_ON(config->num_total_plane >= 32))
  338. return -EINVAL;
  339. /*
  340. * First driver to need more than 64 formats needs to fix this. Each
  341. * format is encoded as a bit and the current code only supports a u64.
  342. */
  343. if (WARN_ON(format_count > 64))
  344. return -EINVAL;
  345. WARN_ON(drm_drv_uses_atomic_modeset(dev) &&
  346. (!funcs->atomic_destroy_state ||
  347. !funcs->atomic_duplicate_state));
  348. ret = drm_mode_object_add(dev, &plane->base, DRM_MODE_OBJECT_PLANE);
  349. if (ret)
  350. return ret;
  351. drm_modeset_lock_init(&plane->mutex);
  352. plane->base.properties = &plane->properties;
  353. plane->dev = dev;
  354. plane->funcs = funcs;
  355. plane->format_types = kmalloc_array(format_count, sizeof(uint32_t),
  356. GFP_KERNEL);
  357. if (!plane->format_types) {
  358. DRM_DEBUG_KMS("out of memory when allocating plane\n");
  359. drm_mode_object_unregister(dev, &plane->base);
  360. return -ENOMEM;
  361. }
  362. if (format_modifiers) {
  363. const uint64_t *temp_modifiers = format_modifiers;
  364. while (*temp_modifiers++ != DRM_FORMAT_MOD_INVALID)
  365. format_modifier_count++;
  366. } else {
  367. if (!dev->mode_config.fb_modifiers_not_supported) {
  368. format_modifiers = default_modifiers;
  369. format_modifier_count = ARRAY_SIZE(default_modifiers);
  370. }
  371. }
  372. /* autoset the cap and check for consistency across all planes */
  373. drm_WARN_ON(dev, config->fb_modifiers_not_supported &&
  374. format_modifier_count);
  375. plane->modifier_count = format_modifier_count;
  376. plane->modifiers = kmalloc_array(format_modifier_count,
  377. sizeof(format_modifiers[0]),
  378. GFP_KERNEL);
  379. if (format_modifier_count && !plane->modifiers) {
  380. DRM_DEBUG_KMS("out of memory when allocating plane\n");
  381. kfree(plane->format_types);
  382. drm_mode_object_unregister(dev, &plane->base);
  383. return -ENOMEM;
  384. }
  385. if (name) {
  386. plane->name = kvasprintf(GFP_KERNEL, name, ap);
  387. } else {
  388. plane->name = kasprintf(GFP_KERNEL, "plane-%d",
  389. drm_num_planes(dev));
  390. }
  391. if (!plane->name) {
  392. kfree(plane->format_types);
  393. kfree(plane->modifiers);
  394. drm_mode_object_unregister(dev, &plane->base);
  395. return -ENOMEM;
  396. }
  397. memcpy(plane->format_types, formats, format_count * sizeof(uint32_t));
  398. plane->format_count = format_count;
  399. memcpy(plane->modifiers, format_modifiers,
  400. format_modifier_count * sizeof(format_modifiers[0]));
  401. plane->possible_crtcs = possible_crtcs;
  402. plane->type = type;
  403. list_add_tail(&plane->head, &config->plane_list);
  404. plane->index = config->num_total_plane++;
  405. drm_object_attach_property(&plane->base,
  406. config->plane_type_property,
  407. plane->type);
  408. if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
  409. drm_object_attach_property(&plane->base, config->prop_fb_id, 0);
  410. drm_object_attach_property(&plane->base, config->prop_in_fence_fd, -1);
  411. drm_object_attach_property(&plane->base, config->prop_crtc_id, 0);
  412. drm_object_attach_property(&plane->base, config->prop_crtc_x, 0);
  413. drm_object_attach_property(&plane->base, config->prop_crtc_y, 0);
  414. drm_object_attach_property(&plane->base, config->prop_crtc_w, 0);
  415. drm_object_attach_property(&plane->base, config->prop_crtc_h, 0);
  416. drm_object_attach_property(&plane->base, config->prop_src_x, 0);
  417. drm_object_attach_property(&plane->base, config->prop_src_y, 0);
  418. drm_object_attach_property(&plane->base, config->prop_src_w, 0);
  419. drm_object_attach_property(&plane->base, config->prop_src_h, 0);
  420. }
  421. if (drm_core_check_feature(dev, DRIVER_CURSOR_HOTSPOT) &&
  422. type == DRM_PLANE_TYPE_CURSOR) {
  423. drm_plane_create_hotspot_properties(plane);
  424. }
  425. if (format_modifier_count)
  426. create_in_format_blob(dev, plane);
  427. return 0;
  428. }
  429. /**
  430. * drm_universal_plane_init - Initialize a new universal plane object
  431. * @dev: DRM device
  432. * @plane: plane object to init
  433. * @possible_crtcs: bitmask of possible CRTCs
  434. * @funcs: callbacks for the new plane
  435. * @formats: array of supported formats (DRM_FORMAT\_\*)
  436. * @format_count: number of elements in @formats
  437. * @format_modifiers: array of struct drm_format modifiers terminated by
  438. * DRM_FORMAT_MOD_INVALID
  439. * @type: type of plane (overlay, primary, cursor)
  440. * @name: printf style format string for the plane name, or NULL for default name
  441. *
  442. * Initializes a plane object of type @type. The &drm_plane_funcs.destroy hook
  443. * should call drm_plane_cleanup() and kfree() the plane structure. The plane
  444. * structure should not be allocated with devm_kzalloc().
  445. *
  446. * Note: consider using drmm_universal_plane_alloc() instead of
  447. * drm_universal_plane_init() to let the DRM managed resource infrastructure
  448. * take care of cleanup and deallocation.
  449. *
  450. * Drivers that only support the DRM_FORMAT_MOD_LINEAR modifier support may set
  451. * @format_modifiers to NULL. The plane will advertise the linear modifier.
  452. *
  453. * Returns:
  454. * Zero on success, error code on failure.
  455. */
  456. int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane,
  457. uint32_t possible_crtcs,
  458. const struct drm_plane_funcs *funcs,
  459. const uint32_t *formats, unsigned int format_count,
  460. const uint64_t *format_modifiers,
  461. enum drm_plane_type type,
  462. const char *name, ...)
  463. {
  464. va_list ap;
  465. int ret;
  466. WARN_ON(!funcs->destroy);
  467. va_start(ap, name);
  468. ret = __drm_universal_plane_init(dev, plane, possible_crtcs, funcs,
  469. formats, format_count, format_modifiers,
  470. type, name, ap);
  471. va_end(ap);
  472. return ret;
  473. }
  474. EXPORT_SYMBOL(drm_universal_plane_init);
  475. static void drmm_universal_plane_alloc_release(struct drm_device *dev, void *ptr)
  476. {
  477. struct drm_plane *plane = ptr;
  478. if (WARN_ON(!plane->dev))
  479. return;
  480. drm_plane_cleanup(plane);
  481. }
  482. void *__drmm_universal_plane_alloc(struct drm_device *dev, size_t size,
  483. size_t offset, uint32_t possible_crtcs,
  484. const struct drm_plane_funcs *funcs,
  485. const uint32_t *formats, unsigned int format_count,
  486. const uint64_t *format_modifiers,
  487. enum drm_plane_type type,
  488. const char *name, ...)
  489. {
  490. void *container;
  491. struct drm_plane *plane;
  492. va_list ap;
  493. int ret;
  494. if (WARN_ON(!funcs || funcs->destroy))
  495. return ERR_PTR(-EINVAL);
  496. container = drmm_kzalloc(dev, size, GFP_KERNEL);
  497. if (!container)
  498. return ERR_PTR(-ENOMEM);
  499. plane = container + offset;
  500. va_start(ap, name);
  501. ret = __drm_universal_plane_init(dev, plane, possible_crtcs, funcs,
  502. formats, format_count, format_modifiers,
  503. type, name, ap);
  504. va_end(ap);
  505. if (ret)
  506. return ERR_PTR(ret);
  507. ret = drmm_add_action_or_reset(dev, drmm_universal_plane_alloc_release,
  508. plane);
  509. if (ret)
  510. return ERR_PTR(ret);
  511. return container;
  512. }
  513. EXPORT_SYMBOL(__drmm_universal_plane_alloc);
  514. void *__drm_universal_plane_alloc(struct drm_device *dev, size_t size,
  515. size_t offset, uint32_t possible_crtcs,
  516. const struct drm_plane_funcs *funcs,
  517. const uint32_t *formats, unsigned int format_count,
  518. const uint64_t *format_modifiers,
  519. enum drm_plane_type type,
  520. const char *name, ...)
  521. {
  522. void *container;
  523. struct drm_plane *plane;
  524. va_list ap;
  525. int ret;
  526. if (drm_WARN_ON(dev, !funcs))
  527. return ERR_PTR(-EINVAL);
  528. container = kzalloc(size, GFP_KERNEL);
  529. if (!container)
  530. return ERR_PTR(-ENOMEM);
  531. plane = container + offset;
  532. va_start(ap, name);
  533. ret = __drm_universal_plane_init(dev, plane, possible_crtcs, funcs,
  534. formats, format_count, format_modifiers,
  535. type, name, ap);
  536. va_end(ap);
  537. if (ret)
  538. goto err_kfree;
  539. return container;
  540. err_kfree:
  541. kfree(container);
  542. return ERR_PTR(ret);
  543. }
  544. EXPORT_SYMBOL(__drm_universal_plane_alloc);
  545. int drm_plane_register_all(struct drm_device *dev)
  546. {
  547. unsigned int num_planes = 0;
  548. unsigned int num_zpos = 0;
  549. struct drm_plane *plane;
  550. int ret = 0;
  551. drm_for_each_plane(plane, dev) {
  552. if (plane->funcs->late_register)
  553. ret = plane->funcs->late_register(plane);
  554. if (ret)
  555. return ret;
  556. if (plane->zpos_property)
  557. num_zpos++;
  558. num_planes++;
  559. }
  560. drm_WARN(dev, num_zpos && num_planes != num_zpos,
  561. "Mixing planes with and without zpos property is invalid\n");
  562. return 0;
  563. }
  564. void drm_plane_unregister_all(struct drm_device *dev)
  565. {
  566. struct drm_plane *plane;
  567. drm_for_each_plane(plane, dev) {
  568. if (plane->funcs->early_unregister)
  569. plane->funcs->early_unregister(plane);
  570. }
  571. }
  572. /**
  573. * drm_plane_cleanup - Clean up the core plane usage
  574. * @plane: plane to cleanup
  575. *
  576. * This function cleans up @plane and removes it from the DRM mode setting
  577. * core. Note that the function does *not* free the plane structure itself,
  578. * this is the responsibility of the caller.
  579. */
  580. void drm_plane_cleanup(struct drm_plane *plane)
  581. {
  582. struct drm_device *dev = plane->dev;
  583. drm_modeset_lock_fini(&plane->mutex);
  584. kfree(plane->format_types);
  585. kfree(plane->modifiers);
  586. drm_mode_object_unregister(dev, &plane->base);
  587. BUG_ON(list_empty(&plane->head));
  588. /* Note that the plane_list is considered to be static; should we
  589. * remove the drm_plane at runtime we would have to decrement all
  590. * the indices on the drm_plane after us in the plane_list.
  591. */
  592. list_del(&plane->head);
  593. dev->mode_config.num_total_plane--;
  594. WARN_ON(plane->state && !plane->funcs->atomic_destroy_state);
  595. if (plane->state && plane->funcs->atomic_destroy_state)
  596. plane->funcs->atomic_destroy_state(plane, plane->state);
  597. kfree(plane->name);
  598. memset(plane, 0, sizeof(*plane));
  599. }
  600. EXPORT_SYMBOL(drm_plane_cleanup);
  601. /**
  602. * drm_plane_from_index - find the registered plane at an index
  603. * @dev: DRM device
  604. * @idx: index of registered plane to find for
  605. *
  606. * Given a plane index, return the registered plane from DRM device's
  607. * list of planes with matching index. This is the inverse of drm_plane_index().
  608. */
  609. struct drm_plane *
  610. drm_plane_from_index(struct drm_device *dev, int idx)
  611. {
  612. struct drm_plane *plane;
  613. drm_for_each_plane(plane, dev)
  614. if (idx == plane->index)
  615. return plane;
  616. return NULL;
  617. }
  618. EXPORT_SYMBOL(drm_plane_from_index);
  619. /**
  620. * drm_plane_force_disable - Forcibly disable a plane
  621. * @plane: plane to disable
  622. *
  623. * Forces the plane to be disabled.
  624. *
  625. * Used when the plane's current framebuffer is destroyed,
  626. * and when restoring fbdev mode.
  627. *
  628. * Note that this function is not suitable for atomic drivers, since it doesn't
  629. * wire through the lock acquisition context properly and hence can't handle
  630. * retries or driver private locks. You probably want to use
  631. * drm_atomic_helper_disable_plane() or
  632. * drm_atomic_helper_disable_planes_on_crtc() instead.
  633. */
  634. void drm_plane_force_disable(struct drm_plane *plane)
  635. {
  636. int ret;
  637. if (!plane->fb)
  638. return;
  639. WARN_ON(drm_drv_uses_atomic_modeset(plane->dev));
  640. plane->old_fb = plane->fb;
  641. ret = plane->funcs->disable_plane(plane, NULL);
  642. if (ret) {
  643. DRM_ERROR("failed to disable plane with busy fb\n");
  644. plane->old_fb = NULL;
  645. return;
  646. }
  647. /* disconnect the plane from the fb and crtc: */
  648. drm_framebuffer_put(plane->old_fb);
  649. plane->old_fb = NULL;
  650. plane->fb = NULL;
  651. plane->crtc = NULL;
  652. }
  653. EXPORT_SYMBOL(drm_plane_force_disable);
  654. /**
  655. * drm_mode_plane_set_obj_prop - set the value of a property
  656. * @plane: drm plane object to set property value for
  657. * @property: property to set
  658. * @value: value the property should be set to
  659. *
  660. * This functions sets a given property on a given plane object. This function
  661. * calls the driver's ->set_property callback and changes the software state of
  662. * the property if the callback succeeds.
  663. *
  664. * Returns:
  665. * Zero on success, error code on failure.
  666. */
  667. int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
  668. struct drm_property *property,
  669. uint64_t value)
  670. {
  671. int ret = -EINVAL;
  672. struct drm_mode_object *obj = &plane->base;
  673. if (plane->funcs->set_property)
  674. ret = plane->funcs->set_property(plane, property, value);
  675. if (!ret)
  676. drm_object_property_set_value(obj, property, value);
  677. return ret;
  678. }
  679. EXPORT_SYMBOL(drm_mode_plane_set_obj_prop);
  680. int drm_mode_getplane_res(struct drm_device *dev, void *data,
  681. struct drm_file *file_priv)
  682. {
  683. struct drm_mode_get_plane_res *plane_resp = data;
  684. struct drm_plane *plane;
  685. uint32_t __user *plane_ptr;
  686. int count = 0;
  687. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  688. return -EOPNOTSUPP;
  689. plane_ptr = u64_to_user_ptr(plane_resp->plane_id_ptr);
  690. /*
  691. * This ioctl is called twice, once to determine how much space is
  692. * needed, and the 2nd time to fill it.
  693. */
  694. drm_for_each_plane(plane, dev) {
  695. /*
  696. * Unless userspace set the 'universal planes'
  697. * capability bit, only advertise overlays.
  698. */
  699. if (plane->type != DRM_PLANE_TYPE_OVERLAY &&
  700. !file_priv->universal_planes)
  701. continue;
  702. /*
  703. * If we're running on a virtualized driver then,
  704. * unless userspace advertizes support for the
  705. * virtualized cursor plane, disable cursor planes
  706. * because they'll be broken due to missing cursor
  707. * hotspot info.
  708. */
  709. if (plane->type == DRM_PLANE_TYPE_CURSOR &&
  710. drm_core_check_feature(dev, DRIVER_CURSOR_HOTSPOT) &&
  711. file_priv->atomic &&
  712. !file_priv->supports_virtualized_cursor_plane)
  713. continue;
  714. if (drm_lease_held(file_priv, plane->base.id)) {
  715. if (count < plane_resp->count_planes &&
  716. put_user(plane->base.id, plane_ptr + count))
  717. return -EFAULT;
  718. count++;
  719. }
  720. }
  721. plane_resp->count_planes = count;
  722. return 0;
  723. }
  724. int drm_mode_getplane(struct drm_device *dev, void *data,
  725. struct drm_file *file_priv)
  726. {
  727. struct drm_mode_get_plane *plane_resp = data;
  728. struct drm_plane *plane;
  729. uint32_t __user *format_ptr;
  730. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  731. return -EOPNOTSUPP;
  732. plane = drm_plane_find(dev, file_priv, plane_resp->plane_id);
  733. if (!plane)
  734. return -ENOENT;
  735. drm_modeset_lock(&plane->mutex, NULL);
  736. if (plane->state && plane->state->crtc && drm_lease_held(file_priv, plane->state->crtc->base.id))
  737. plane_resp->crtc_id = plane->state->crtc->base.id;
  738. else if (!plane->state && plane->crtc && drm_lease_held(file_priv, plane->crtc->base.id))
  739. plane_resp->crtc_id = plane->crtc->base.id;
  740. else
  741. plane_resp->crtc_id = 0;
  742. if (plane->state && plane->state->fb)
  743. plane_resp->fb_id = plane->state->fb->base.id;
  744. else if (!plane->state && plane->fb)
  745. plane_resp->fb_id = plane->fb->base.id;
  746. else
  747. plane_resp->fb_id = 0;
  748. drm_modeset_unlock(&plane->mutex);
  749. plane_resp->plane_id = plane->base.id;
  750. plane_resp->possible_crtcs = drm_lease_filter_crtcs(file_priv,
  751. plane->possible_crtcs);
  752. plane_resp->gamma_size = 0;
  753. /*
  754. * This ioctl is called twice, once to determine how much space is
  755. * needed, and the 2nd time to fill it.
  756. */
  757. if (plane->format_count &&
  758. (plane_resp->count_format_types >= plane->format_count)) {
  759. format_ptr = (uint32_t __user *)(unsigned long)plane_resp->format_type_ptr;
  760. if (copy_to_user(format_ptr,
  761. plane->format_types,
  762. sizeof(uint32_t) * plane->format_count)) {
  763. return -EFAULT;
  764. }
  765. }
  766. plane_resp->count_format_types = plane->format_count;
  767. return 0;
  768. }
  769. /**
  770. * drm_plane_has_format - Check whether the plane supports this format and modifier combination
  771. * @plane: drm plane
  772. * @format: pixel format (DRM_FORMAT_*)
  773. * @modifier: data layout modifier
  774. *
  775. * Returns:
  776. * Whether the plane supports the specified format and modifier combination.
  777. */
  778. bool drm_plane_has_format(struct drm_plane *plane,
  779. u32 format, u64 modifier)
  780. {
  781. unsigned int i;
  782. for (i = 0; i < plane->format_count; i++) {
  783. if (format == plane->format_types[i])
  784. break;
  785. }
  786. if (i == plane->format_count)
  787. return false;
  788. if (plane->funcs->format_mod_supported) {
  789. if (!plane->funcs->format_mod_supported(plane, format, modifier))
  790. return false;
  791. } else {
  792. if (!plane->modifier_count)
  793. return true;
  794. for (i = 0; i < plane->modifier_count; i++) {
  795. if (modifier == plane->modifiers[i])
  796. break;
  797. }
  798. if (i == plane->modifier_count)
  799. return false;
  800. }
  801. return true;
  802. }
  803. EXPORT_SYMBOL(drm_plane_has_format);
  804. static int __setplane_check(struct drm_plane *plane,
  805. struct drm_crtc *crtc,
  806. struct drm_framebuffer *fb,
  807. int32_t crtc_x, int32_t crtc_y,
  808. uint32_t crtc_w, uint32_t crtc_h,
  809. uint32_t src_x, uint32_t src_y,
  810. uint32_t src_w, uint32_t src_h)
  811. {
  812. int ret;
  813. /* Check whether this plane is usable on this CRTC */
  814. if (!(plane->possible_crtcs & drm_crtc_mask(crtc))) {
  815. DRM_DEBUG_KMS("Invalid crtc for plane\n");
  816. return -EINVAL;
  817. }
  818. /* Check whether this plane supports the fb pixel format. */
  819. if (!drm_plane_has_format(plane, fb->format->format, fb->modifier)) {
  820. DRM_DEBUG_KMS("Invalid pixel format %p4cc, modifier 0x%llx\n",
  821. &fb->format->format, fb->modifier);
  822. return -EINVAL;
  823. }
  824. /* Give drivers some help against integer overflows */
  825. if (crtc_w > INT_MAX ||
  826. crtc_x > INT_MAX - (int32_t) crtc_w ||
  827. crtc_h > INT_MAX ||
  828. crtc_y > INT_MAX - (int32_t) crtc_h) {
  829. DRM_DEBUG_KMS("Invalid CRTC coordinates %ux%u+%d+%d\n",
  830. crtc_w, crtc_h, crtc_x, crtc_y);
  831. return -ERANGE;
  832. }
  833. ret = drm_framebuffer_check_src_coords(src_x, src_y, src_w, src_h, fb);
  834. if (ret)
  835. return ret;
  836. return 0;
  837. }
  838. /**
  839. * drm_any_plane_has_format - Check whether any plane supports this format and modifier combination
  840. * @dev: DRM device
  841. * @format: pixel format (DRM_FORMAT_*)
  842. * @modifier: data layout modifier
  843. *
  844. * Returns:
  845. * Whether at least one plane supports the specified format and modifier combination.
  846. */
  847. bool drm_any_plane_has_format(struct drm_device *dev,
  848. u32 format, u64 modifier)
  849. {
  850. struct drm_plane *plane;
  851. drm_for_each_plane(plane, dev) {
  852. if (drm_plane_has_format(plane, format, modifier))
  853. return true;
  854. }
  855. return false;
  856. }
  857. EXPORT_SYMBOL(drm_any_plane_has_format);
  858. /*
  859. * __setplane_internal - setplane handler for internal callers
  860. *
  861. * This function will take a reference on the new fb for the plane
  862. * on success.
  863. *
  864. * src_{x,y,w,h} are provided in 16.16 fixed point format
  865. */
  866. static int __setplane_internal(struct drm_plane *plane,
  867. struct drm_crtc *crtc,
  868. struct drm_framebuffer *fb,
  869. int32_t crtc_x, int32_t crtc_y,
  870. uint32_t crtc_w, uint32_t crtc_h,
  871. /* src_{x,y,w,h} values are 16.16 fixed point */
  872. uint32_t src_x, uint32_t src_y,
  873. uint32_t src_w, uint32_t src_h,
  874. struct drm_modeset_acquire_ctx *ctx)
  875. {
  876. int ret = 0;
  877. WARN_ON(drm_drv_uses_atomic_modeset(plane->dev));
  878. /* No fb means shut it down */
  879. if (!fb) {
  880. plane->old_fb = plane->fb;
  881. ret = plane->funcs->disable_plane(plane, ctx);
  882. if (!ret) {
  883. plane->crtc = NULL;
  884. plane->fb = NULL;
  885. } else {
  886. plane->old_fb = NULL;
  887. }
  888. goto out;
  889. }
  890. ret = __setplane_check(plane, crtc, fb,
  891. crtc_x, crtc_y, crtc_w, crtc_h,
  892. src_x, src_y, src_w, src_h);
  893. if (ret)
  894. goto out;
  895. plane->old_fb = plane->fb;
  896. ret = plane->funcs->update_plane(plane, crtc, fb,
  897. crtc_x, crtc_y, crtc_w, crtc_h,
  898. src_x, src_y, src_w, src_h, ctx);
  899. if (!ret) {
  900. plane->crtc = crtc;
  901. plane->fb = fb;
  902. drm_framebuffer_get(plane->fb);
  903. } else {
  904. plane->old_fb = NULL;
  905. }
  906. out:
  907. if (plane->old_fb)
  908. drm_framebuffer_put(plane->old_fb);
  909. plane->old_fb = NULL;
  910. return ret;
  911. }
  912. static int __setplane_atomic(struct drm_plane *plane,
  913. struct drm_crtc *crtc,
  914. struct drm_framebuffer *fb,
  915. int32_t crtc_x, int32_t crtc_y,
  916. uint32_t crtc_w, uint32_t crtc_h,
  917. uint32_t src_x, uint32_t src_y,
  918. uint32_t src_w, uint32_t src_h,
  919. struct drm_modeset_acquire_ctx *ctx)
  920. {
  921. int ret;
  922. WARN_ON(!drm_drv_uses_atomic_modeset(plane->dev));
  923. /* No fb means shut it down */
  924. if (!fb)
  925. return plane->funcs->disable_plane(plane, ctx);
  926. /*
  927. * FIXME: This is redundant with drm_atomic_plane_check(),
  928. * but the legacy cursor/"async" .update_plane() tricks
  929. * don't call that so we still need this here. Should remove
  930. * this when all .update_plane() implementations have been
  931. * fixed to call drm_atomic_plane_check().
  932. */
  933. ret = __setplane_check(plane, crtc, fb,
  934. crtc_x, crtc_y, crtc_w, crtc_h,
  935. src_x, src_y, src_w, src_h);
  936. if (ret)
  937. return ret;
  938. return plane->funcs->update_plane(plane, crtc, fb,
  939. crtc_x, crtc_y, crtc_w, crtc_h,
  940. src_x, src_y, src_w, src_h, ctx);
  941. }
  942. static int setplane_internal(struct drm_plane *plane,
  943. struct drm_crtc *crtc,
  944. struct drm_framebuffer *fb,
  945. int32_t crtc_x, int32_t crtc_y,
  946. uint32_t crtc_w, uint32_t crtc_h,
  947. /* src_{x,y,w,h} values are 16.16 fixed point */
  948. uint32_t src_x, uint32_t src_y,
  949. uint32_t src_w, uint32_t src_h)
  950. {
  951. struct drm_modeset_acquire_ctx ctx;
  952. int ret;
  953. DRM_MODESET_LOCK_ALL_BEGIN(plane->dev, ctx,
  954. DRM_MODESET_ACQUIRE_INTERRUPTIBLE, ret);
  955. if (drm_drv_uses_atomic_modeset(plane->dev))
  956. ret = __setplane_atomic(plane, crtc, fb,
  957. crtc_x, crtc_y, crtc_w, crtc_h,
  958. src_x, src_y, src_w, src_h, &ctx);
  959. else
  960. ret = __setplane_internal(plane, crtc, fb,
  961. crtc_x, crtc_y, crtc_w, crtc_h,
  962. src_x, src_y, src_w, src_h, &ctx);
  963. DRM_MODESET_LOCK_ALL_END(plane->dev, ctx, ret);
  964. return ret;
  965. }
  966. int drm_mode_setplane(struct drm_device *dev, void *data,
  967. struct drm_file *file_priv)
  968. {
  969. struct drm_mode_set_plane *plane_req = data;
  970. struct drm_plane *plane;
  971. struct drm_crtc *crtc = NULL;
  972. struct drm_framebuffer *fb = NULL;
  973. int ret;
  974. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  975. return -EOPNOTSUPP;
  976. /*
  977. * First, find the plane, crtc, and fb objects. If not available,
  978. * we don't bother to call the driver.
  979. */
  980. plane = drm_plane_find(dev, file_priv, plane_req->plane_id);
  981. if (!plane) {
  982. DRM_DEBUG_KMS("Unknown plane ID %d\n",
  983. plane_req->plane_id);
  984. return -ENOENT;
  985. }
  986. if (plane_req->fb_id) {
  987. fb = drm_framebuffer_lookup(dev, file_priv, plane_req->fb_id);
  988. if (!fb) {
  989. DRM_DEBUG_KMS("Unknown framebuffer ID %d\n",
  990. plane_req->fb_id);
  991. return -ENOENT;
  992. }
  993. crtc = drm_crtc_find(dev, file_priv, plane_req->crtc_id);
  994. if (!crtc) {
  995. drm_framebuffer_put(fb);
  996. DRM_DEBUG_KMS("Unknown crtc ID %d\n",
  997. plane_req->crtc_id);
  998. return -ENOENT;
  999. }
  1000. }
  1001. ret = setplane_internal(plane, crtc, fb,
  1002. plane_req->crtc_x, plane_req->crtc_y,
  1003. plane_req->crtc_w, plane_req->crtc_h,
  1004. plane_req->src_x, plane_req->src_y,
  1005. plane_req->src_w, plane_req->src_h);
  1006. if (fb)
  1007. drm_framebuffer_put(fb);
  1008. return ret;
  1009. }
  1010. static int drm_mode_cursor_universal(struct drm_crtc *crtc,
  1011. struct drm_mode_cursor2 *req,
  1012. struct drm_file *file_priv,
  1013. struct drm_modeset_acquire_ctx *ctx)
  1014. {
  1015. struct drm_device *dev = crtc->dev;
  1016. struct drm_plane *plane = crtc->cursor;
  1017. struct drm_framebuffer *fb = NULL;
  1018. struct drm_mode_fb_cmd2 fbreq = {
  1019. .width = req->width,
  1020. .height = req->height,
  1021. .pixel_format = DRM_FORMAT_ARGB8888,
  1022. .pitches = { req->width * 4 },
  1023. .handles = { req->handle },
  1024. };
  1025. int32_t crtc_x, crtc_y;
  1026. uint32_t crtc_w = 0, crtc_h = 0;
  1027. uint32_t src_w = 0, src_h = 0;
  1028. int ret = 0;
  1029. BUG_ON(!plane);
  1030. WARN_ON(plane->crtc != crtc && plane->crtc != NULL);
  1031. /*
  1032. * Obtain fb we'll be using (either new or existing) and take an extra
  1033. * reference to it if fb != null. setplane will take care of dropping
  1034. * the reference if the plane update fails.
  1035. */
  1036. if (req->flags & DRM_MODE_CURSOR_BO) {
  1037. if (req->handle) {
  1038. fb = drm_internal_framebuffer_create(dev, &fbreq, file_priv);
  1039. if (IS_ERR(fb)) {
  1040. DRM_DEBUG_KMS("failed to wrap cursor buffer in drm framebuffer\n");
  1041. return PTR_ERR(fb);
  1042. }
  1043. if (plane->hotspot_x_property && plane->state)
  1044. plane->state->hotspot_x = req->hot_x;
  1045. if (plane->hotspot_y_property && plane->state)
  1046. plane->state->hotspot_y = req->hot_y;
  1047. } else {
  1048. fb = NULL;
  1049. }
  1050. } else {
  1051. if (plane->state)
  1052. fb = plane->state->fb;
  1053. else
  1054. fb = plane->fb;
  1055. if (fb)
  1056. drm_framebuffer_get(fb);
  1057. }
  1058. if (req->flags & DRM_MODE_CURSOR_MOVE) {
  1059. crtc_x = req->x;
  1060. crtc_y = req->y;
  1061. } else {
  1062. crtc_x = crtc->cursor_x;
  1063. crtc_y = crtc->cursor_y;
  1064. }
  1065. if (fb) {
  1066. crtc_w = fb->width;
  1067. crtc_h = fb->height;
  1068. src_w = fb->width << 16;
  1069. src_h = fb->height << 16;
  1070. }
  1071. if (drm_drv_uses_atomic_modeset(dev))
  1072. ret = __setplane_atomic(plane, crtc, fb,
  1073. crtc_x, crtc_y, crtc_w, crtc_h,
  1074. 0, 0, src_w, src_h, ctx);
  1075. else
  1076. ret = __setplane_internal(plane, crtc, fb,
  1077. crtc_x, crtc_y, crtc_w, crtc_h,
  1078. 0, 0, src_w, src_h, ctx);
  1079. if (fb)
  1080. drm_framebuffer_put(fb);
  1081. /* Update successful; save new cursor position, if necessary */
  1082. if (ret == 0 && req->flags & DRM_MODE_CURSOR_MOVE) {
  1083. crtc->cursor_x = req->x;
  1084. crtc->cursor_y = req->y;
  1085. }
  1086. return ret;
  1087. }
  1088. static int drm_mode_cursor_common(struct drm_device *dev,
  1089. struct drm_mode_cursor2 *req,
  1090. struct drm_file *file_priv)
  1091. {
  1092. struct drm_crtc *crtc;
  1093. struct drm_modeset_acquire_ctx ctx;
  1094. int ret = 0;
  1095. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  1096. return -EOPNOTSUPP;
  1097. if (!req->flags || (~DRM_MODE_CURSOR_FLAGS & req->flags))
  1098. return -EINVAL;
  1099. crtc = drm_crtc_find(dev, file_priv, req->crtc_id);
  1100. if (!crtc) {
  1101. DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req->crtc_id);
  1102. return -ENOENT;
  1103. }
  1104. drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
  1105. retry:
  1106. ret = drm_modeset_lock(&crtc->mutex, &ctx);
  1107. if (ret)
  1108. goto out;
  1109. /*
  1110. * If this crtc has a universal cursor plane, call that plane's update
  1111. * handler rather than using legacy cursor handlers.
  1112. */
  1113. if (crtc->cursor) {
  1114. ret = drm_modeset_lock(&crtc->cursor->mutex, &ctx);
  1115. if (ret)
  1116. goto out;
  1117. if (!drm_lease_held(file_priv, crtc->cursor->base.id)) {
  1118. ret = -EACCES;
  1119. goto out;
  1120. }
  1121. ret = drm_mode_cursor_universal(crtc, req, file_priv, &ctx);
  1122. goto out;
  1123. }
  1124. if (req->flags & DRM_MODE_CURSOR_BO) {
  1125. if (!crtc->funcs->cursor_set && !crtc->funcs->cursor_set2) {
  1126. ret = -ENXIO;
  1127. goto out;
  1128. }
  1129. /* Turns off the cursor if handle is 0 */
  1130. if (crtc->funcs->cursor_set2)
  1131. ret = crtc->funcs->cursor_set2(crtc, file_priv, req->handle,
  1132. req->width, req->height, req->hot_x, req->hot_y);
  1133. else
  1134. ret = crtc->funcs->cursor_set(crtc, file_priv, req->handle,
  1135. req->width, req->height);
  1136. }
  1137. if (req->flags & DRM_MODE_CURSOR_MOVE) {
  1138. if (crtc->funcs->cursor_move) {
  1139. ret = crtc->funcs->cursor_move(crtc, req->x, req->y);
  1140. } else {
  1141. ret = -EFAULT;
  1142. goto out;
  1143. }
  1144. }
  1145. out:
  1146. if (ret == -EDEADLK) {
  1147. ret = drm_modeset_backoff(&ctx);
  1148. if (!ret)
  1149. goto retry;
  1150. }
  1151. drm_modeset_drop_locks(&ctx);
  1152. drm_modeset_acquire_fini(&ctx);
  1153. return ret;
  1154. }
  1155. int drm_mode_cursor_ioctl(struct drm_device *dev,
  1156. void *data, struct drm_file *file_priv)
  1157. {
  1158. struct drm_mode_cursor *req = data;
  1159. struct drm_mode_cursor2 new_req;
  1160. memcpy(&new_req, req, sizeof(struct drm_mode_cursor));
  1161. new_req.hot_x = new_req.hot_y = 0;
  1162. return drm_mode_cursor_common(dev, &new_req, file_priv);
  1163. }
  1164. /*
  1165. * Set the cursor configuration based on user request. This implements the 2nd
  1166. * version of the cursor ioctl, which allows userspace to additionally specify
  1167. * the hotspot of the pointer.
  1168. */
  1169. int drm_mode_cursor2_ioctl(struct drm_device *dev,
  1170. void *data, struct drm_file *file_priv)
  1171. {
  1172. struct drm_mode_cursor2 *req = data;
  1173. return drm_mode_cursor_common(dev, req, file_priv);
  1174. }
  1175. int drm_mode_page_flip_ioctl(struct drm_device *dev,
  1176. void *data, struct drm_file *file_priv)
  1177. {
  1178. struct drm_mode_crtc_page_flip_target *page_flip = data;
  1179. struct drm_crtc *crtc;
  1180. struct drm_plane *plane;
  1181. struct drm_framebuffer *fb = NULL, *old_fb;
  1182. struct drm_pending_vblank_event *e = NULL;
  1183. u32 target_vblank = page_flip->sequence;
  1184. struct drm_modeset_acquire_ctx ctx;
  1185. int ret = -EINVAL;
  1186. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  1187. return -EOPNOTSUPP;
  1188. if (page_flip->flags & ~DRM_MODE_PAGE_FLIP_FLAGS)
  1189. return -EINVAL;
  1190. if (page_flip->sequence != 0 && !(page_flip->flags & DRM_MODE_PAGE_FLIP_TARGET))
  1191. return -EINVAL;
  1192. /* Only one of the DRM_MODE_PAGE_FLIP_TARGET_ABSOLUTE/RELATIVE flags
  1193. * can be specified
  1194. */
  1195. if ((page_flip->flags & DRM_MODE_PAGE_FLIP_TARGET) == DRM_MODE_PAGE_FLIP_TARGET)
  1196. return -EINVAL;
  1197. if ((page_flip->flags & DRM_MODE_PAGE_FLIP_ASYNC) && !dev->mode_config.async_page_flip)
  1198. return -EINVAL;
  1199. crtc = drm_crtc_find(dev, file_priv, page_flip->crtc_id);
  1200. if (!crtc)
  1201. return -ENOENT;
  1202. plane = crtc->primary;
  1203. if (!drm_lease_held(file_priv, plane->base.id))
  1204. return -EACCES;
  1205. if (crtc->funcs->page_flip_target) {
  1206. u32 current_vblank;
  1207. int r;
  1208. r = drm_crtc_vblank_get(crtc);
  1209. if (r)
  1210. return r;
  1211. current_vblank = (u32)drm_crtc_vblank_count(crtc);
  1212. switch (page_flip->flags & DRM_MODE_PAGE_FLIP_TARGET) {
  1213. case DRM_MODE_PAGE_FLIP_TARGET_ABSOLUTE:
  1214. if ((int)(target_vblank - current_vblank) > 1) {
  1215. DRM_DEBUG("Invalid absolute flip target %u, "
  1216. "must be <= %u\n", target_vblank,
  1217. current_vblank + 1);
  1218. drm_crtc_vblank_put(crtc);
  1219. return -EINVAL;
  1220. }
  1221. break;
  1222. case DRM_MODE_PAGE_FLIP_TARGET_RELATIVE:
  1223. if (target_vblank != 0 && target_vblank != 1) {
  1224. DRM_DEBUG("Invalid relative flip target %u, "
  1225. "must be 0 or 1\n", target_vblank);
  1226. drm_crtc_vblank_put(crtc);
  1227. return -EINVAL;
  1228. }
  1229. target_vblank += current_vblank;
  1230. break;
  1231. default:
  1232. target_vblank = current_vblank +
  1233. !(page_flip->flags & DRM_MODE_PAGE_FLIP_ASYNC);
  1234. break;
  1235. }
  1236. } else if (crtc->funcs->page_flip == NULL ||
  1237. (page_flip->flags & DRM_MODE_PAGE_FLIP_TARGET)) {
  1238. return -EINVAL;
  1239. }
  1240. drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
  1241. retry:
  1242. ret = drm_modeset_lock(&crtc->mutex, &ctx);
  1243. if (ret)
  1244. goto out;
  1245. ret = drm_modeset_lock(&plane->mutex, &ctx);
  1246. if (ret)
  1247. goto out;
  1248. if (plane->state)
  1249. old_fb = plane->state->fb;
  1250. else
  1251. old_fb = plane->fb;
  1252. if (old_fb == NULL) {
  1253. /* The framebuffer is currently unbound, presumably
  1254. * due to a hotplug event, that userspace has not
  1255. * yet discovered.
  1256. */
  1257. ret = -EBUSY;
  1258. goto out;
  1259. }
  1260. fb = drm_framebuffer_lookup(dev, file_priv, page_flip->fb_id);
  1261. if (!fb) {
  1262. ret = -ENOENT;
  1263. goto out;
  1264. }
  1265. if (plane->state) {
  1266. const struct drm_plane_state *state = plane->state;
  1267. ret = drm_framebuffer_check_src_coords(state->src_x,
  1268. state->src_y,
  1269. state->src_w,
  1270. state->src_h,
  1271. fb);
  1272. } else {
  1273. ret = drm_crtc_check_viewport(crtc, crtc->x, crtc->y,
  1274. &crtc->mode, fb);
  1275. }
  1276. if (ret)
  1277. goto out;
  1278. /*
  1279. * Only check the FOURCC format code, excluding modifiers. This is
  1280. * enough for all legacy drivers. Atomic drivers have their own
  1281. * checks in their ->atomic_check implementation, which will
  1282. * return -EINVAL if any hw or driver constraint is violated due
  1283. * to modifier changes.
  1284. */
  1285. if (old_fb->format->format != fb->format->format) {
  1286. DRM_DEBUG_KMS("Page flip is not allowed to change frame buffer format.\n");
  1287. ret = -EINVAL;
  1288. goto out;
  1289. }
  1290. if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) {
  1291. e = kzalloc(sizeof *e, GFP_KERNEL);
  1292. if (!e) {
  1293. ret = -ENOMEM;
  1294. goto out;
  1295. }
  1296. e->event.base.type = DRM_EVENT_FLIP_COMPLETE;
  1297. e->event.base.length = sizeof(e->event);
  1298. e->event.vbl.user_data = page_flip->user_data;
  1299. e->event.vbl.crtc_id = crtc->base.id;
  1300. ret = drm_event_reserve_init(dev, file_priv, &e->base, &e->event.base);
  1301. if (ret) {
  1302. kfree(e);
  1303. e = NULL;
  1304. goto out;
  1305. }
  1306. }
  1307. plane->old_fb = plane->fb;
  1308. if (crtc->funcs->page_flip_target)
  1309. ret = crtc->funcs->page_flip_target(crtc, fb, e,
  1310. page_flip->flags,
  1311. target_vblank,
  1312. &ctx);
  1313. else
  1314. ret = crtc->funcs->page_flip(crtc, fb, e, page_flip->flags,
  1315. &ctx);
  1316. if (ret) {
  1317. if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT)
  1318. drm_event_cancel_free(dev, &e->base);
  1319. /* Keep the old fb, don't unref it. */
  1320. plane->old_fb = NULL;
  1321. } else {
  1322. if (!plane->state) {
  1323. plane->fb = fb;
  1324. drm_framebuffer_get(fb);
  1325. }
  1326. }
  1327. out:
  1328. if (fb)
  1329. drm_framebuffer_put(fb);
  1330. fb = NULL;
  1331. if (plane->old_fb)
  1332. drm_framebuffer_put(plane->old_fb);
  1333. plane->old_fb = NULL;
  1334. if (ret == -EDEADLK) {
  1335. ret = drm_modeset_backoff(&ctx);
  1336. if (!ret)
  1337. goto retry;
  1338. }
  1339. drm_modeset_drop_locks(&ctx);
  1340. drm_modeset_acquire_fini(&ctx);
  1341. if (ret && crtc->funcs->page_flip_target)
  1342. drm_crtc_vblank_put(crtc);
  1343. return ret;
  1344. }
  1345. /**
  1346. * DOC: damage tracking
  1347. *
  1348. * FB_DAMAGE_CLIPS is an optional plane property which provides a means to
  1349. * specify a list of damage rectangles on a plane in framebuffer coordinates of
  1350. * the framebuffer attached to the plane. In current context damage is the area
  1351. * of plane framebuffer that has changed since last plane update (also called
  1352. * page-flip), irrespective of whether currently attached framebuffer is same as
  1353. * framebuffer attached during last plane update or not.
  1354. *
  1355. * FB_DAMAGE_CLIPS is a hint to kernel which could be helpful for some drivers
  1356. * to optimize internally especially for virtual devices where each framebuffer
  1357. * change needs to be transmitted over network, usb, etc.
  1358. *
  1359. * Since FB_DAMAGE_CLIPS is a hint so it is an optional property. User-space can
  1360. * ignore damage clips property and in that case driver will do a full plane
  1361. * update. In case damage clips are provided then it is guaranteed that the area
  1362. * inside damage clips will be updated to plane. For efficiency driver can do
  1363. * full update or can update more than specified in damage clips. Since driver
  1364. * is free to read more, user-space must always render the entire visible
  1365. * framebuffer. Otherwise there can be corruptions. Also, if a user-space
  1366. * provides damage clips which doesn't encompass the actual damage to
  1367. * framebuffer (since last plane update) can result in incorrect rendering.
  1368. *
  1369. * FB_DAMAGE_CLIPS is a blob property with the layout of blob data is simply an
  1370. * array of &drm_mode_rect. Unlike plane &drm_plane_state.src coordinates,
  1371. * damage clips are not in 16.16 fixed point. Similar to plane src in
  1372. * framebuffer, damage clips cannot be negative. In damage clip, x1/y1 are
  1373. * inclusive and x2/y2 are exclusive. While kernel does not error for overlapped
  1374. * damage clips, it is strongly discouraged.
  1375. *
  1376. * Drivers that are interested in damage interface for plane should enable
  1377. * FB_DAMAGE_CLIPS property by calling drm_plane_enable_fb_damage_clips().
  1378. * Drivers implementing damage can use drm_atomic_helper_damage_iter_init() and
  1379. * drm_atomic_helper_damage_iter_next() helper iterator function to get damage
  1380. * rectangles clipped to &drm_plane_state.src.
  1381. *
  1382. * Note that there are two types of damage handling: frame damage and buffer
  1383. * damage, the type of damage handling implemented depends on a driver's upload
  1384. * target. Drivers implementing a per-plane or per-CRTC upload target need to
  1385. * handle frame damage, while drivers implementing a per-buffer upload target
  1386. * need to handle buffer damage.
  1387. *
  1388. * The existing damage helpers only support the frame damage type, there is no
  1389. * buffer age support or similar damage accumulation algorithm implemented yet.
  1390. *
  1391. * Only drivers handling frame damage can use the mentioned damage helpers to
  1392. * iterate over the damaged regions. Drivers that handle buffer damage, must set
  1393. * &drm_plane_state.ignore_damage_clips for drm_atomic_helper_damage_iter_init()
  1394. * to know that damage clips should be ignored and return &drm_plane_state.src
  1395. * as the damage rectangle, to force a full plane update.
  1396. *
  1397. * Drivers with a per-buffer upload target could compare the &drm_plane_state.fb
  1398. * of the old and new plane states to determine if the framebuffer attached to a
  1399. * plane has changed or not since the last plane update. If &drm_plane_state.fb
  1400. * has changed, then &drm_plane_state.ignore_damage_clips must be set to true.
  1401. *
  1402. * That is because drivers with a per-plane upload target, expect the backing
  1403. * storage buffer to not change for a given plane. If the upload buffer changes
  1404. * between page flips, the new upload buffer has to be updated as a whole. This
  1405. * can be improved in the future if support for frame damage is added to the DRM
  1406. * damage helpers, similarly to how user-space already handle this case as it is
  1407. * explained in the following documents:
  1408. *
  1409. * https://registry.khronos.org/EGL/extensions/KHR/EGL_KHR_swap_buffers_with_damage.txt
  1410. * https://emersion.fr/blog/2019/intro-to-damage-tracking/
  1411. */
  1412. /**
  1413. * drm_plane_enable_fb_damage_clips - Enables plane fb damage clips property.
  1414. * @plane: Plane on which to enable damage clips property.
  1415. *
  1416. * This function lets driver to enable the damage clips property on a plane.
  1417. */
  1418. void drm_plane_enable_fb_damage_clips(struct drm_plane *plane)
  1419. {
  1420. struct drm_device *dev = plane->dev;
  1421. struct drm_mode_config *config = &dev->mode_config;
  1422. drm_object_attach_property(&plane->base, config->prop_fb_damage_clips,
  1423. 0);
  1424. }
  1425. EXPORT_SYMBOL(drm_plane_enable_fb_damage_clips);
  1426. /**
  1427. * drm_plane_get_damage_clips_count - Returns damage clips count.
  1428. * @state: Plane state.
  1429. *
  1430. * Simple helper to get the number of &drm_mode_rect clips set by user-space
  1431. * during plane update.
  1432. *
  1433. * Return: Number of clips in plane fb_damage_clips blob property.
  1434. */
  1435. unsigned int
  1436. drm_plane_get_damage_clips_count(const struct drm_plane_state *state)
  1437. {
  1438. return (state && state->fb_damage_clips) ?
  1439. state->fb_damage_clips->length/sizeof(struct drm_mode_rect) : 0;
  1440. }
  1441. EXPORT_SYMBOL(drm_plane_get_damage_clips_count);
  1442. struct drm_mode_rect *
  1443. __drm_plane_get_damage_clips(const struct drm_plane_state *state)
  1444. {
  1445. return (struct drm_mode_rect *)((state && state->fb_damage_clips) ?
  1446. state->fb_damage_clips->data : NULL);
  1447. }
  1448. /**
  1449. * drm_plane_get_damage_clips - Returns damage clips.
  1450. * @state: Plane state.
  1451. *
  1452. * Note that this function returns uapi type &drm_mode_rect. Drivers might want
  1453. * to use the helper functions drm_atomic_helper_damage_iter_init() and
  1454. * drm_atomic_helper_damage_iter_next() or drm_atomic_helper_damage_merged() if
  1455. * the driver can only handle a single damage region at most.
  1456. *
  1457. * Return: Damage clips in plane fb_damage_clips blob property.
  1458. */
  1459. struct drm_mode_rect *
  1460. drm_plane_get_damage_clips(const struct drm_plane_state *state)
  1461. {
  1462. struct drm_device *dev = state->plane->dev;
  1463. struct drm_mode_config *config = &dev->mode_config;
  1464. /* check that drm_plane_enable_fb_damage_clips() was called */
  1465. if (!drm_mode_obj_find_prop_id(&state->plane->base,
  1466. config->prop_fb_damage_clips->base.id))
  1467. drm_warn_once(dev, "drm_plane_enable_fb_damage_clips() not called\n");
  1468. return __drm_plane_get_damage_clips(state);
  1469. }
  1470. EXPORT_SYMBOL(drm_plane_get_damage_clips);
  1471. struct drm_property *
  1472. drm_create_scaling_filter_prop(struct drm_device *dev,
  1473. unsigned int supported_filters)
  1474. {
  1475. struct drm_property *prop;
  1476. static const struct drm_prop_enum_list props[] = {
  1477. { DRM_SCALING_FILTER_DEFAULT, "Default" },
  1478. { DRM_SCALING_FILTER_NEAREST_NEIGHBOR, "Nearest Neighbor" },
  1479. };
  1480. unsigned int valid_mode_mask = BIT(DRM_SCALING_FILTER_DEFAULT) |
  1481. BIT(DRM_SCALING_FILTER_NEAREST_NEIGHBOR);
  1482. int i;
  1483. if (WARN_ON((supported_filters & ~valid_mode_mask) ||
  1484. ((supported_filters & BIT(DRM_SCALING_FILTER_DEFAULT)) == 0)))
  1485. return ERR_PTR(-EINVAL);
  1486. prop = drm_property_create(dev, DRM_MODE_PROP_ENUM,
  1487. "SCALING_FILTER",
  1488. hweight32(supported_filters));
  1489. if (!prop)
  1490. return ERR_PTR(-ENOMEM);
  1491. for (i = 0; i < ARRAY_SIZE(props); i++) {
  1492. int ret;
  1493. if (!(BIT(props[i].type) & supported_filters))
  1494. continue;
  1495. ret = drm_property_add_enum(prop, props[i].type,
  1496. props[i].name);
  1497. if (ret) {
  1498. drm_property_destroy(dev, prop);
  1499. return ERR_PTR(ret);
  1500. }
  1501. }
  1502. return prop;
  1503. }
  1504. /**
  1505. * drm_plane_create_scaling_filter_property - create a new scaling filter
  1506. * property
  1507. *
  1508. * @plane: drm plane
  1509. * @supported_filters: bitmask of supported scaling filters, must include
  1510. * BIT(DRM_SCALING_FILTER_DEFAULT).
  1511. *
  1512. * This function lets driver to enable the scaling filter property on a given
  1513. * plane.
  1514. *
  1515. * RETURNS:
  1516. * Zero for success or -errno
  1517. */
  1518. int drm_plane_create_scaling_filter_property(struct drm_plane *plane,
  1519. unsigned int supported_filters)
  1520. {
  1521. struct drm_property *prop =
  1522. drm_create_scaling_filter_prop(plane->dev, supported_filters);
  1523. if (IS_ERR(prop))
  1524. return PTR_ERR(prop);
  1525. drm_object_attach_property(&plane->base, prop,
  1526. DRM_SCALING_FILTER_DEFAULT);
  1527. plane->scaling_filter_property = prop;
  1528. return 0;
  1529. }
  1530. EXPORT_SYMBOL(drm_plane_create_scaling_filter_property);
  1531. /**
  1532. * drm_plane_add_size_hints_property - create a size hints property
  1533. *
  1534. * @plane: drm plane
  1535. * @hints: size hints
  1536. * @num_hints: number of size hints
  1537. *
  1538. * Create a size hints property for the plane.
  1539. *
  1540. * RETURNS:
  1541. * Zero for success or -errno
  1542. */
  1543. int drm_plane_add_size_hints_property(struct drm_plane *plane,
  1544. const struct drm_plane_size_hint *hints,
  1545. int num_hints)
  1546. {
  1547. struct drm_device *dev = plane->dev;
  1548. struct drm_mode_config *config = &dev->mode_config;
  1549. struct drm_property_blob *blob;
  1550. /* extending to other plane types needs actual thought */
  1551. if (drm_WARN_ON(dev, plane->type != DRM_PLANE_TYPE_CURSOR))
  1552. return -EINVAL;
  1553. blob = drm_property_create_blob(dev,
  1554. array_size(sizeof(hints[0]), num_hints),
  1555. hints);
  1556. if (IS_ERR(blob))
  1557. return PTR_ERR(blob);
  1558. drm_object_attach_property(&plane->base, config->size_hints_property,
  1559. blob->base.id);
  1560. return 0;
  1561. }
  1562. EXPORT_SYMBOL(drm_plane_add_size_hints_property);