e88bfc6be86d3db1307e0343e1a10e6a285c97fe
[oweals/openwrt.git] /
1 From df276f0a5aa865c7926d9d148605d1a59d1d4fbb Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Thu, 25 Jul 2019 17:27:44 +0100
4 Subject: [PATCH] drm/vc4: Resolve the vblank warnings on mode
5  switching
6
7 The details over when and how a driver is to service the
8 vblank events are sketchy, and the fkms driver was triggering
9 a kernel warning every time the crtc was enabled or disabled.
10
11 Copy the event handling as used by the vc4-kms driver slightly
12 more closely, and we avoid the warnings.
13
14 https://github.com/raspberrypi/linux/issues/3020
15
16 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
17 ---
18  drivers/gpu/drm/vc4/vc4_firmware_kms.c | 48 ++++++++++++++++++--------
19  1 file changed, 33 insertions(+), 15 deletions(-)
20
21 --- a/drivers/gpu/drm/vc4/vc4_firmware_kms.c
22 +++ b/drivers/gpu/drm/vc4/vc4_firmware_kms.c
23 @@ -933,6 +933,7 @@ static void vc4_crtc_mode_set_nofb(struc
24  
25  static void vc4_crtc_disable(struct drm_crtc *crtc, struct drm_crtc_state *old_state)
26  {
27 +       struct drm_device *dev = crtc->dev;
28         struct drm_plane *plane;
29  
30         DRM_DEBUG_KMS("[CRTC:%d] vblanks off.\n",
31 @@ -948,6 +949,35 @@ static void vc4_crtc_disable(struct drm_
32  
33         drm_atomic_crtc_for_each_plane(plane, crtc)
34                 vc4_plane_atomic_disable(plane, plane->state);
35 +
36 +       /*
37 +        * Make sure we issue a vblank event after disabling the CRTC if
38 +        * someone was waiting it.
39 +        */
40 +       if (crtc->state->event) {
41 +               unsigned long flags;
42 +
43 +               spin_lock_irqsave(&dev->event_lock, flags);
44 +               drm_crtc_send_vblank_event(crtc, crtc->state->event);
45 +               crtc->state->event = NULL;
46 +               spin_unlock_irqrestore(&dev->event_lock, flags);
47 +       }
48 +}
49 +
50 +static void vc4_crtc_consume_event(struct drm_crtc *crtc)
51 +{
52 +       struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc);
53 +       struct drm_device *dev = crtc->dev;
54 +       unsigned long flags;
55 +
56 +       crtc->state->event->pipe = drm_crtc_index(crtc);
57 +
58 +       WARN_ON(drm_crtc_vblank_get(crtc) != 0);
59 +
60 +       spin_lock_irqsave(&dev->event_lock, flags);
61 +       vc4_crtc->event = crtc->state->event;
62 +       crtc->state->event = NULL;
63 +       spin_unlock_irqrestore(&dev->event_lock, flags);
64  }
65  
66  static void vc4_crtc_enable(struct drm_crtc *crtc, struct drm_crtc_state *old_state)
67 @@ -957,6 +987,7 @@ static void vc4_crtc_enable(struct drm_c
68         DRM_DEBUG_KMS("[CRTC:%d] vblanks on.\n",
69                       crtc->base.id);
70         drm_crtc_vblank_on(crtc);
71 +       vc4_crtc_consume_event(crtc);
72  
73         /* Unblank the planes (if they're supposed to be displayed). */
74         drm_atomic_crtc_for_each_plane(plane, crtc)
75 @@ -1028,23 +1059,10 @@ static int vc4_crtc_atomic_check(struct
76  static void vc4_crtc_atomic_flush(struct drm_crtc *crtc,
77                                   struct drm_crtc_state *old_state)
78  {
79 -       struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc);
80 -       struct drm_device *dev = crtc->dev;
81 -
82         DRM_DEBUG_KMS("[CRTC:%d] crtc_atomic_flush.\n",
83                       crtc->base.id);
84 -       if (crtc->state->event) {
85 -               unsigned long flags;
86 -
87 -               crtc->state->event->pipe = drm_crtc_index(crtc);
88 -
89 -               WARN_ON(drm_crtc_vblank_get(crtc) != 0);
90 -
91 -               spin_lock_irqsave(&dev->event_lock, flags);
92 -               vc4_crtc->event = crtc->state->event;
93 -               crtc->state->event = NULL;
94 -               spin_unlock_irqrestore(&dev->event_lock, flags);
95 -       }
96 +       if (crtc->state->active && old_state->active && crtc->state->event)
97 +               vc4_crtc_consume_event(crtc);
98  }
99  
100  static void vc4_crtc_handle_page_flip(struct vc4_crtc *vc4_crtc)