forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/gpu/drm/drm_plane.c
....@@ -20,8 +20,17 @@
2020 * OF THIS SOFTWARE.
2121 */
2222
23
-#include <drm/drmP.h>
23
+#include <linux/slab.h>
24
+#include <linux/uaccess.h>
25
+
2426 #include <drm/drm_plane.h>
27
+#include <drm/drm_drv.h>
28
+#include <drm/drm_print.h>
29
+#include <drm/drm_framebuffer.h>
30
+#include <drm/drm_file.h>
31
+#include <drm/drm_crtc.h>
32
+#include <drm/drm_fourcc.h>
33
+#include <drm/drm_vblank.h>
2534
2635 #include "drm_crtc_internal.h"
2736
....@@ -177,6 +186,13 @@
177186 if (WARN_ON(config->num_total_plane >= 32))
178187 return -EINVAL;
179188
189
+ /*
190
+ * First driver to need more than 64 formats needs to fix this. Each
191
+ * format is encoded as a bit and the current code only supports a u64.
192
+ */
193
+ if (WARN_ON(format_count > 64))
194
+ return -EINVAL;
195
+
180196 WARN_ON(drm_drv_uses_atomic_modeset(dev) &&
181197 (!funcs->atomic_destroy_state ||
182198 !funcs->atomic_duplicate_state));
....@@ -198,15 +214,9 @@
198214 return -ENOMEM;
199215 }
200216
201
- /*
202
- * First driver to need more than 64 formats needs to fix this. Each
203
- * format is encoded as a bit and the current code only supports a u64.
204
- */
205
- if (WARN_ON(format_count > 64))
206
- return -EINVAL;
207
-
208217 if (format_modifiers) {
209218 const uint64_t *temp_modifiers = format_modifiers;
219
+
210220 while (*temp_modifiers++ != DRM_FORMAT_MOD_INVALID)
211221 format_modifier_count++;
212222 }
....@@ -280,6 +290,8 @@
280290
281291 int drm_plane_register_all(struct drm_device *dev)
282292 {
293
+ unsigned int num_planes = 0;
294
+ unsigned int num_zpos = 0;
283295 struct drm_plane *plane;
284296 int ret = 0;
285297
....@@ -288,7 +300,14 @@
288300 ret = plane->funcs->late_register(plane);
289301 if (ret)
290302 return ret;
303
+
304
+ if (plane->zpos_property)
305
+ num_zpos++;
306
+ num_planes++;
291307 }
308
+
309
+ drm_WARN(dev, num_zpos && num_planes != num_zpos,
310
+ "Mixing planes with and without zpos property is invalid\n");
292311
293312 return 0;
294313 }
....@@ -466,15 +485,13 @@
466485 struct drm_file *file_priv)
467486 {
468487 struct drm_mode_get_plane_res *plane_resp = data;
469
- struct drm_mode_config *config;
470488 struct drm_plane *plane;
471489 uint32_t __user *plane_ptr;
472490 int count = 0;
473491
474492 if (!drm_core_check_feature(dev, DRIVER_MODESET))
475
- return -EINVAL;
493
+ return -EOPNOTSUPP;
476494
477
- config = &dev->mode_config;
478495 plane_ptr = u64_to_user_ptr(plane_resp->plane_id_ptr);
479496
480497 /*
....@@ -510,7 +527,7 @@
510527 uint32_t __user *format_ptr;
511528
512529 if (!drm_core_check_feature(dev, DRIVER_MODESET))
513
- return -EINVAL;
530
+ return -EOPNOTSUPP;
514531
515532 plane = drm_plane_find(dev, file_priv, plane_resp->plane_id);
516533 if (!plane)
....@@ -632,6 +649,29 @@
632649 return 0;
633650 }
634651
652
+/**
653
+ * drm_any_plane_has_format - Check whether any plane supports this format and modifier combination
654
+ * @dev: DRM device
655
+ * @format: pixel format (DRM_FORMAT_*)
656
+ * @modifier: data layout modifier
657
+ *
658
+ * Returns:
659
+ * Whether at least one plane supports the specified format and modifier combination.
660
+ */
661
+bool drm_any_plane_has_format(struct drm_device *dev,
662
+ u32 format, u64 modifier)
663
+{
664
+ struct drm_plane *plane;
665
+
666
+ drm_for_each_plane(plane, dev) {
667
+ if (drm_plane_check_pixel_format(plane, format, modifier) == 0)
668
+ return true;
669
+ }
670
+
671
+ return false;
672
+}
673
+EXPORT_SYMBOL(drm_any_plane_has_format);
674
+
635675 /*
636676 * __setplane_internal - setplane handler for internal callers
637677 *
....@@ -740,11 +780,8 @@
740780 struct drm_modeset_acquire_ctx ctx;
741781 int ret;
742782
743
- drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
744
-retry:
745
- ret = drm_modeset_lock_all_ctx(plane->dev, &ctx);
746
- if (ret)
747
- goto fail;
783
+ DRM_MODESET_LOCK_ALL_BEGIN(plane->dev, ctx,
784
+ DRM_MODESET_ACQUIRE_INTERRUPTIBLE, ret);
748785
749786 if (drm_drv_uses_atomic_modeset(plane->dev))
750787 ret = __setplane_atomic(plane, crtc, fb,
....@@ -755,14 +792,7 @@
755792 crtc_x, crtc_y, crtc_w, crtc_h,
756793 src_x, src_y, src_w, src_h, &ctx);
757794
758
-fail:
759
- if (ret == -EDEADLK) {
760
- ret = drm_modeset_backoff(&ctx);
761
- if (!ret)
762
- goto retry;
763
- }
764
- drm_modeset_drop_locks(&ctx);
765
- drm_modeset_acquire_fini(&ctx);
795
+ DRM_MODESET_LOCK_ALL_END(plane->dev, ctx, ret);
766796
767797 return ret;
768798 }
....@@ -777,7 +807,7 @@
777807 int ret;
778808
779809 if (!drm_core_check_feature(dev, DRIVER_MODESET))
780
- return -EINVAL;
810
+ return -EOPNOTSUPP;
781811
782812 /*
783813 * First, find the plane, crtc, and fb objects. If not available,
....@@ -915,7 +945,7 @@
915945 int ret = 0;
916946
917947 if (!drm_core_check_feature(dev, DRIVER_MODESET))
918
- return -EINVAL;
948
+ return -EOPNOTSUPP;
919949
920950 if (!req->flags || (~DRM_MODE_CURSOR_FLAGS & req->flags))
921951 return -EINVAL;
....@@ -1024,7 +1054,7 @@
10241054 int ret = -EINVAL;
10251055
10261056 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1027
- return -EINVAL;
1057
+ return -EOPNOTSUPP;
10281058
10291059 if (page_flip->flags & ~DRM_MODE_PAGE_FLIP_FLAGS)
10301060 return -EINVAL;