forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/gpu/drm/drm_mode_config.c
....@@ -20,9 +20,15 @@
2020 * OF THIS SOFTWARE.
2121 */
2222
23
+#include <linux/uaccess.h>
24
+
25
+#include <drm/drm_drv.h>
2326 #include <drm/drm_encoder.h>
27
+#include <drm/drm_file.h>
28
+#include <drm/drm_managed.h>
2429 #include <drm/drm_mode_config.h>
25
-#include <drm/drmP.h>
30
+#include <drm/drm_print.h>
31
+#include <linux/dma-resv.h>
2632
2733 #include "drm_crtc_internal.h"
2834 #include "drm_internal.h"
....@@ -97,8 +103,7 @@
97103 struct drm_connector_list_iter conn_iter;
98104
99105 if (!drm_core_check_feature(dev, DRIVER_MODESET))
100
- return -EINVAL;
101
-
106
+ return -EOPNOTSUPP;
102107
103108 mutex_lock(&file_priv->fbs_lock);
104109 count = 0;
....@@ -298,6 +303,13 @@
298303 return -ENOMEM;
299304 dev->mode_config.prop_crtc_id = prop;
300305
306
+ prop = drm_property_create(dev,
307
+ DRM_MODE_PROP_ATOMIC | DRM_MODE_PROP_BLOB,
308
+ "FB_DAMAGE_CLIPS", 0);
309
+ if (!prop)
310
+ return -ENOMEM;
311
+ dev->mode_config.prop_fb_damage_clips = prop;
312
+
301313 prop = drm_property_create_bool(dev, DRM_MODE_PROP_ATOMIC,
302314 "ACTIVE");
303315 if (!prop)
....@@ -310,6 +322,12 @@
310322 if (!prop)
311323 return -ENOMEM;
312324 dev->mode_config.prop_mode_id = prop;
325
+
326
+ prop = drm_property_create_bool(dev, 0,
327
+ "VRR_ENABLED");
328
+ if (!prop)
329
+ return -ENOMEM;
330
+ dev->mode_config.prop_vrr_enabled = prop;
313331
314332 prop = drm_property_create(dev,
315333 DRM_MODE_PROP_BLOB,
....@@ -346,6 +364,7 @@
346364 return -ENOMEM;
347365 dev->mode_config.gamma_lut_size_property = prop;
348366
367
+#if defined(CONFIG_ROCKCHIP_DRM_CUBIC_LUT)
349368 prop = drm_property_create(dev,
350369 DRM_MODE_PROP_BLOB,
351370 "CUBIC_LUT", 0);
....@@ -359,6 +378,7 @@
359378 if (!prop)
360379 return -ENOMEM;
361380 dev->mode_config.cubic_lut_size_property = prop;
381
+#endif
362382
363383 prop = drm_property_create(dev,
364384 DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_BLOB,
....@@ -370,8 +390,14 @@
370390 return 0;
371391 }
372392
393
+static void drm_mode_config_init_release(struct drm_device *dev, void *ptr)
394
+{
395
+ drm_mode_config_cleanup(dev);
396
+}
397
+
373398 /**
374
- * drm_mode_config_init - initialize DRM mode_configuration structure
399
+ * drmm_mode_config_init - managed DRM mode_configuration structure
400
+ * initialization
375401 * @dev: DRM device
376402 *
377403 * Initialize @dev's mode_config structure, used for tracking the graphics
....@@ -381,8 +407,12 @@
381407 * problem, since this should happen single threaded at init time. It is the
382408 * driver's problem to ensure this guarantee.
383409 *
410
+ * Cleanup is automatically handled through registering drm_mode_config_cleanup
411
+ * with drmm_add_action().
412
+ *
413
+ * Returns: 0 on success, negative error value on failure.
384414 */
385
-void drm_mode_config_init(struct drm_device *dev)
415
+int drmm_mode_config_init(struct drm_device *dev)
386416 {
387417 mutex_init(&dev->mode_config.mutex);
388418 drm_modeset_lock_init(&dev->mode_config.connection_mutex);
....@@ -396,7 +426,8 @@
396426 INIT_LIST_HEAD(&dev->mode_config.property_list);
397427 INIT_LIST_HEAD(&dev->mode_config.property_blob_list);
398428 INIT_LIST_HEAD(&dev->mode_config.plane_list);
399
- idr_init(&dev->mode_config.crtc_idr);
429
+ INIT_LIST_HEAD(&dev->mode_config.privobj_list);
430
+ idr_init(&dev->mode_config.object_idr);
400431 idr_init(&dev->mode_config.tile_idr);
401432 ida_init(&dev->mode_config.connector_ida);
402433 spin_lock_init(&dev->mode_config.connector_list_lock);
....@@ -412,8 +443,38 @@
412443 dev->mode_config.num_crtc = 0;
413444 dev->mode_config.num_encoder = 0;
414445 dev->mode_config.num_total_plane = 0;
446
+
447
+ if (IS_ENABLED(CONFIG_LOCKDEP)) {
448
+ struct drm_modeset_acquire_ctx modeset_ctx;
449
+ struct ww_acquire_ctx resv_ctx;
450
+ struct dma_resv resv;
451
+ int ret;
452
+
453
+ dma_resv_init(&resv);
454
+
455
+ drm_modeset_acquire_init(&modeset_ctx, 0);
456
+ ret = drm_modeset_lock(&dev->mode_config.connection_mutex,
457
+ &modeset_ctx);
458
+ if (ret == -EDEADLK)
459
+ ret = drm_modeset_backoff(&modeset_ctx);
460
+
461
+ ww_acquire_init(&resv_ctx, &reservation_ww_class);
462
+ ret = dma_resv_lock(&resv, &resv_ctx);
463
+ if (ret == -EDEADLK)
464
+ dma_resv_lock_slow(&resv, &resv_ctx);
465
+
466
+ dma_resv_unlock(&resv);
467
+ ww_acquire_fini(&resv_ctx);
468
+
469
+ drm_modeset_drop_locks(&modeset_ctx);
470
+ drm_modeset_acquire_fini(&modeset_ctx);
471
+ dma_resv_fini(&resv);
472
+ }
473
+
474
+ return drmm_add_action_or_reset(dev, drm_mode_config_init_release,
475
+ NULL);
415476 }
416
-EXPORT_SYMBOL(drm_mode_config_init);
477
+EXPORT_SYMBOL(drmm_mode_config_init);
417478
418479 /**
419480 * drm_mode_config_cleanup - free up DRM mode_config info
....@@ -426,7 +487,8 @@
426487 * teardown time, no locking is required. It's the driver's job to ensure that
427488 * this guarantee actually holds true.
428489 *
429
- * FIXME: cleanup any dangling user buffer objects too
490
+ * FIXME: With the managed drmm_mode_config_init() it is no longer necessary for
491
+ * drivers to explicitly call this function.
430492 */
431493 void drm_mode_config_cleanup(struct drm_device *dev)
432494 {
....@@ -492,6 +554,7 @@
492554 WARN_ON(!list_empty(&dev->mode_config.fb_list));
493555 list_for_each_entry_safe(fb, fbt, &dev->mode_config.fb_list, head) {
494556 struct drm_printer p = drm_debug_printer("[leaked fb]");
557
+
495558 drm_printf(&p, "framebuffer[%u]:\n", fb->base.id);
496559 drm_framebuffer_print_info(&p, 1, fb);
497560 drm_framebuffer_free(&fb->base.refcount);
....@@ -499,7 +562,94 @@
499562
500563 ida_destroy(&dev->mode_config.connector_ida);
501564 idr_destroy(&dev->mode_config.tile_idr);
502
- idr_destroy(&dev->mode_config.crtc_idr);
565
+ idr_destroy(&dev->mode_config.object_idr);
503566 drm_modeset_lock_fini(&dev->mode_config.connection_mutex);
504567 }
505568 EXPORT_SYMBOL(drm_mode_config_cleanup);
569
+
570
+static u32 full_encoder_mask(struct drm_device *dev)
571
+{
572
+ struct drm_encoder *encoder;
573
+ u32 encoder_mask = 0;
574
+
575
+ drm_for_each_encoder(encoder, dev)
576
+ encoder_mask |= drm_encoder_mask(encoder);
577
+
578
+ return encoder_mask;
579
+}
580
+
581
+/*
582
+ * For some reason we want the encoder itself included in
583
+ * possible_clones. Make life easy for drivers by allowing them
584
+ * to leave possible_clones unset if no cloning is possible.
585
+ */
586
+static void fixup_encoder_possible_clones(struct drm_encoder *encoder)
587
+{
588
+ if (encoder->possible_clones == 0)
589
+ encoder->possible_clones = drm_encoder_mask(encoder);
590
+}
591
+
592
+static void validate_encoder_possible_clones(struct drm_encoder *encoder)
593
+{
594
+ struct drm_device *dev = encoder->dev;
595
+ u32 encoder_mask = full_encoder_mask(dev);
596
+ struct drm_encoder *other;
597
+
598
+ drm_for_each_encoder(other, dev) {
599
+ WARN(!!(encoder->possible_clones & drm_encoder_mask(other)) !=
600
+ !!(other->possible_clones & drm_encoder_mask(encoder)),
601
+ "possible_clones mismatch: "
602
+ "[ENCODER:%d:%s] mask=0x%x possible_clones=0x%x vs. "
603
+ "[ENCODER:%d:%s] mask=0x%x possible_clones=0x%x\n",
604
+ encoder->base.id, encoder->name,
605
+ drm_encoder_mask(encoder), encoder->possible_clones,
606
+ other->base.id, other->name,
607
+ drm_encoder_mask(other), other->possible_clones);
608
+ }
609
+
610
+ WARN((encoder->possible_clones & drm_encoder_mask(encoder)) == 0 ||
611
+ (encoder->possible_clones & ~encoder_mask) != 0,
612
+ "Bogus possible_clones: "
613
+ "[ENCODER:%d:%s] possible_clones=0x%x (full encoder mask=0x%x)\n",
614
+ encoder->base.id, encoder->name,
615
+ encoder->possible_clones, encoder_mask);
616
+}
617
+
618
+static u32 full_crtc_mask(struct drm_device *dev)
619
+{
620
+ struct drm_crtc *crtc;
621
+ u32 crtc_mask = 0;
622
+
623
+ drm_for_each_crtc(crtc, dev)
624
+ crtc_mask |= drm_crtc_mask(crtc);
625
+
626
+ return crtc_mask;
627
+}
628
+
629
+static void validate_encoder_possible_crtcs(struct drm_encoder *encoder)
630
+{
631
+ u32 crtc_mask = full_crtc_mask(encoder->dev);
632
+
633
+ WARN((encoder->possible_crtcs & crtc_mask) == 0 ||
634
+ (encoder->possible_crtcs & ~crtc_mask) != 0,
635
+ "Bogus possible_crtcs: "
636
+ "[ENCODER:%d:%s] possible_crtcs=0x%x (full crtc mask=0x%x)\n",
637
+ encoder->base.id, encoder->name,
638
+ encoder->possible_crtcs, crtc_mask);
639
+}
640
+
641
+void drm_mode_config_validate(struct drm_device *dev)
642
+{
643
+ struct drm_encoder *encoder;
644
+
645
+ if (!drm_core_check_feature(dev, DRIVER_MODESET))
646
+ return;
647
+
648
+ drm_for_each_encoder(encoder, dev)
649
+ fixup_encoder_possible_clones(encoder);
650
+
651
+ drm_for_each_encoder(encoder, dev) {
652
+ validate_encoder_possible_clones(encoder);
653
+ validate_encoder_possible_crtcs(encoder);
654
+ }
655
+}