aboutsummaryrefslogtreecommitdiffstats
path: root/meta-amd-bsp/recipes-kernel/linux/linux-yocto-4.14.71/0146-drm-amd-display-Use-pflip-prepare-and-submit-parts-v.patch
blob: 0f387b5168d859abc3c0cbe64a280f3f20f62197 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
From 1459df7b197737022408e6348d800db2b6ce09cf Mon Sep 17 00:00:00 2001
From: Andrey Grodzovsky <Andrey.Grodzovsky@amd.com>
Date: Wed, 9 Nov 2016 05:41:51 -0500
Subject: [PATCH 0146/4131] drm/amd/display: Use pflip prepare and submit parts
 (v2)

Use new functions so flip failures can be gracefully handled

v2:
Avoid -EINVAL returned from amdgpu_crtc_prepare_flip in some
error cases, it is not allowed according to expected
return values for atomic_commit hook.

Signed-off-by: Andrey Grodzovsky <Andrey.Grodzovsky@amd.com>
Acked-by: Harry Wentland <Harry.Wentland@amd.com>
Reviewed-by: Andrey Grodzovsky <Andrey.Grodzovsky@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 .../drm/amd/display/amdgpu_dm/amdgpu_dm_types.c    | 96 +++++++++++++++++++---
 1 file changed, 83 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_types.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_types.c
index 123dc94..a5e3a708 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_types.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_types.c
@@ -1646,6 +1646,7 @@ static void clear_unrelated_fields(struct drm_plane_state *state)
 static bool page_flip_needed(
 	const struct drm_plane_state *new_state,
 	const struct drm_plane_state *old_state,
+	struct drm_pending_vblank_event *event,
 	bool commit_surface_required)
 {
 	struct drm_plane_state old_state_tmp;
@@ -1675,7 +1676,7 @@ static bool page_flip_needed(
 	old_state_tmp = *old_state;
 	new_state_tmp = *new_state;
 
-	if (!new_state->crtc->state->event)
+	if (!event)
 		return false;
 
 	amdgpu_fb_old = to_amdgpu_framebuffer(old_state->fb);
@@ -2484,17 +2485,21 @@ int amdgpu_dm_atomic_commit(
 	struct amdgpu_device *adev = dev->dev_private;
 	struct amdgpu_display_manager *dm = &adev->dm;
 	struct drm_plane *plane;
+	struct drm_plane_state *new_plane_state;
 	struct drm_plane_state *old_plane_state;
 	uint32_t i;
 	int32_t ret = 0;
 	uint32_t commit_streams_count = 0;
 	uint32_t new_crtcs_count = 0;
+	uint32_t flip_crtcs_count = 0;
 	struct drm_crtc *crtc;
 	struct drm_crtc_state *old_crtc_state;
-
 	const struct dc_stream *commit_streams[MAX_STREAMS];
 	struct amdgpu_crtc *new_crtcs[MAX_STREAMS];
 	const struct dc_stream *new_stream;
+	struct drm_crtc *flip_crtcs[MAX_STREAMS];
+	struct amdgpu_flip_work *work[MAX_STREAMS] = {0};
+	struct amdgpu_bo *new_abo[MAX_STREAMS] = {0};
 
 	/* In this step all new fb would be pinned */
 
@@ -2510,6 +2515,61 @@ int amdgpu_dm_atomic_commit(
 			return ret;
 	}
 
+	/* Page flip if needed */
+	for_each_plane_in_state(state, plane, new_plane_state, i) {
+		struct drm_plane_state *old_plane_state = plane->state;
+		struct drm_crtc *crtc = new_plane_state->crtc;
+		struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
+		struct drm_framebuffer *fb = new_plane_state->fb;
+		struct drm_crtc_state *crtc_state;
+
+		if (!fb || !crtc)
+			continue;
+
+		crtc_state = drm_atomic_get_crtc_state(state, crtc);
+
+		if (!crtc_state->planes_changed || !crtc_state->active)
+			continue;
+
+		if (page_flip_needed(
+				new_plane_state,
+				old_plane_state,
+				crtc_state->event,
+				false)) {
+			ret = amdgpu_crtc_prepare_flip(crtc,
+							fb,
+							crtc_state->event,
+							acrtc->flip_flags,
+							drm_crtc_vblank_count(crtc),
+							&work[flip_crtcs_count],
+							&new_abo[flip_crtcs_count]);
+
+			if (ret) {
+				/* According to atomic_commit hook API, EINVAL is not allowed */
+				if (unlikely(ret == -EINVAL))
+					ret = -ENOMEM;
+
+				DRM_ERROR("Atomic commit: Flip for  crtc id %d: [%p], "
+									"failed, errno = %d\n",
+									acrtc->crtc_id,
+									acrtc,
+									ret);
+				/* cleanup all flip configurations which
+				 * succeeded in this commit
+				 */
+				for (i = 0; i < flip_crtcs_count; i++)
+					amdgpu_crtc_cleanup_flip_ctx(
+							work[i],
+							new_abo[i]);
+
+				return ret;
+			}
+
+			flip_crtcs[flip_crtcs_count] = crtc;
+			flip_crtcs_count++;
+		}
+	}
+
 	/*
 	 * This is the point of no return - everything below never fails except
 	 * when the hw goes bonghits. Which means we can commit the new state on
@@ -2698,7 +2758,10 @@ int amdgpu_dm_atomic_commit(
 		 * 1. This commit is not a page flip.
 		 * 2. This commit is a page flip, and streams are created.
 		 */
-		if (!page_flip_needed(plane_state, old_plane_state, true) ||
+		if (!page_flip_needed(
+				plane_state,
+				old_plane_state,
+				crtc->state->event, true) ||
 				action == DM_COMMIT_ACTION_DPMS_ON ||
 				action == DM_COMMIT_ACTION_SET) {
 			list_for_each_entry(connector,
@@ -2754,7 +2817,8 @@ int amdgpu_dm_atomic_commit(
 
 	}
 
-	/* Page flip if needed */
+	/* Do actual flip */
+	flip_crtcs_count = 0;
 	for_each_plane_in_state(state, plane, old_plane_state, i) {
 		struct drm_plane_state *plane_state = plane->state;
 		struct drm_crtc *crtc = plane_state->crtc;
@@ -2765,16 +2829,19 @@ int amdgpu_dm_atomic_commit(
 			!crtc->state->active)
 			continue;
 
-		if (page_flip_needed(plane_state, old_plane_state, false)) {
-			ret = amdgpu_crtc_page_flip_target(crtc,
-							   fb,
-							   crtc->state->event,
-							   acrtc->flip_flags,
-							   drm_crtc_vblank_count(crtc));
+		if (page_flip_needed(
+				plane_state,
+				old_plane_state,
+				crtc->state->event,
+				false)) {
+				amdgpu_crtc_submit_flip(
+							crtc,
+						    fb,
+						    work[flip_crtcs_count],
+						    new_abo[i]);
+				 flip_crtcs_count++;
 			/*clean up the flags for next usage*/
 			acrtc->flip_flags = 0;
-			if (ret)
-				return ret;
 		}
 	}
 
@@ -3126,6 +3193,8 @@ int amdgpu_dm_atomic_check(struct drm_device *dev,
 			struct drm_connector *connector;
 			struct dm_connector_state *dm_state = NULL;
 			enum dm_commit_action action;
+			struct drm_crtc_state *crtc_state;
+
 
 			if (!fb || !crtc || crtc_set[i] != crtc ||
 				!crtc->state->planes_changed || !crtc->state->active)
@@ -3137,8 +3206,9 @@ int amdgpu_dm_atomic_check(struct drm_device *dev,
 			 * 1. This commit is not a page flip.
 			 * 2. This commit is a page flip, and streams are created.
 			 */
+			crtc_state = drm_atomic_get_crtc_state(state, crtc);
 			if (!page_flip_needed(plane_state, old_plane_state,
-					      true) ||
+					crtc_state->event, true) ||
 					action == DM_COMMIT_ACTION_DPMS_ON ||
 					action == DM_COMMIT_ACTION_SET) {
 				struct dc_surface *surface;
-- 
2.7.4