xref: /openbmc/linux/drivers/gpu/drm/msm/msm_atomic.c (revision abade675e02e1b73da0c20ffaf08fbe309038298)
1 /*
2  * Copyright (C) 2014 Red Hat
3  * Author: Rob Clark <robdclark@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 as published by
7  * the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <drm/drm_atomic_uapi.h>
19 
20 #include "msm_drv.h"
21 #include "msm_gem.h"
22 #include "msm_kms.h"
23 
24 static void msm_atomic_wait_for_commit_done(struct drm_device *dev,
25 		struct drm_atomic_state *old_state)
26 {
27 	struct drm_crtc *crtc;
28 	struct drm_crtc_state *new_crtc_state;
29 	struct msm_drm_private *priv = old_state->dev->dev_private;
30 	struct msm_kms *kms = priv->kms;
31 	int i;
32 
33 	for_each_new_crtc_in_state(old_state, crtc, new_crtc_state, i) {
34 		if (!new_crtc_state->active)
35 			continue;
36 
37 		if (drm_crtc_vblank_get(crtc))
38 			continue;
39 
40 		kms->funcs->wait_for_crtc_commit_done(kms, crtc);
41 
42 		drm_crtc_vblank_put(crtc);
43 	}
44 }
45 
46 int msm_atomic_prepare_fb(struct drm_plane *plane,
47 			  struct drm_plane_state *new_state)
48 {
49 	struct msm_drm_private *priv = plane->dev->dev_private;
50 	struct msm_kms *kms = priv->kms;
51 	struct drm_gem_object *obj;
52 	struct dma_fence *fence;
53 
54 	if (!new_state->fb)
55 		return 0;
56 
57 	obj = msm_framebuffer_bo(new_state->fb, 0);
58 	fence = reservation_object_get_excl_rcu(obj->resv);
59 
60 	drm_atomic_set_fence_for_plane(new_state, fence);
61 
62 	return msm_framebuffer_prepare(new_state->fb, kms->aspace);
63 }
64 
65 void msm_atomic_commit_tail(struct drm_atomic_state *state)
66 {
67 	struct drm_device *dev = state->dev;
68 	struct msm_drm_private *priv = dev->dev_private;
69 	struct msm_kms *kms = priv->kms;
70 
71 	kms->funcs->prepare_commit(kms, state);
72 
73 	drm_atomic_helper_commit_modeset_disables(dev, state);
74 
75 	drm_atomic_helper_commit_planes(dev, state, 0);
76 
77 	drm_atomic_helper_commit_modeset_enables(dev, state);
78 
79 	if (kms->funcs->commit) {
80 		DRM_DEBUG_ATOMIC("triggering commit\n");
81 		kms->funcs->commit(kms, state);
82 	}
83 
84 	if (!state->legacy_cursor_update)
85 		msm_atomic_wait_for_commit_done(dev, state);
86 
87 	kms->funcs->complete_commit(kms, state);
88 
89 	drm_atomic_helper_commit_hw_done(state);
90 
91 	drm_atomic_helper_cleanup_planes(dev, state);
92 }
93