xref: /linux/drivers/gpu/drm/msm/msm_atomic.c (revision b8d312aa075f33282565467662c4628dae0a2aff)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (C) 2014 Red Hat
4  * Author: Rob Clark <robdclark@gmail.com>
5  */
6 
7 #include <drm/drm_atomic_uapi.h>
8 #include <drm/drm_gem_framebuffer_helper.h>
9 
10 #include "msm_drv.h"
11 #include "msm_gem.h"
12 #include "msm_kms.h"
13 
14 static void msm_atomic_wait_for_commit_done(struct drm_device *dev,
15 		struct drm_atomic_state *old_state)
16 {
17 	struct drm_crtc *crtc;
18 	struct drm_crtc_state *new_crtc_state;
19 	struct msm_drm_private *priv = old_state->dev->dev_private;
20 	struct msm_kms *kms = priv->kms;
21 	int i;
22 
23 	for_each_new_crtc_in_state(old_state, crtc, new_crtc_state, i) {
24 		if (!new_crtc_state->active)
25 			continue;
26 
27 		if (drm_crtc_vblank_get(crtc))
28 			continue;
29 
30 		kms->funcs->wait_for_crtc_commit_done(kms, crtc);
31 
32 		drm_crtc_vblank_put(crtc);
33 	}
34 }
35 
36 int msm_atomic_prepare_fb(struct drm_plane *plane,
37 			  struct drm_plane_state *new_state)
38 {
39 	struct msm_drm_private *priv = plane->dev->dev_private;
40 	struct msm_kms *kms = priv->kms;
41 
42 	if (!new_state->fb)
43 		return 0;
44 
45 	drm_gem_fb_prepare_fb(plane, new_state);
46 
47 	return msm_framebuffer_prepare(new_state->fb, kms->aspace);
48 }
49 
50 void msm_atomic_commit_tail(struct drm_atomic_state *state)
51 {
52 	struct drm_device *dev = state->dev;
53 	struct msm_drm_private *priv = dev->dev_private;
54 	struct msm_kms *kms = priv->kms;
55 
56 	kms->funcs->prepare_commit(kms, state);
57 
58 	drm_atomic_helper_commit_modeset_disables(dev, state);
59 
60 	drm_atomic_helper_commit_planes(dev, state, 0);
61 
62 	drm_atomic_helper_commit_modeset_enables(dev, state);
63 
64 	if (kms->funcs->commit) {
65 		DRM_DEBUG_ATOMIC("triggering commit\n");
66 		kms->funcs->commit(kms, state);
67 	}
68 
69 	if (!state->legacy_cursor_update)
70 		msm_atomic_wait_for_commit_done(dev, state);
71 
72 	kms->funcs->complete_commit(kms, state);
73 
74 	drm_atomic_helper_commit_hw_done(state);
75 
76 	drm_atomic_helper_cleanup_planes(dev, state);
77 }
78