aboutsummaryrefslogtreecommitdiffstats
path: root/meta-amd-bsp/recipes-kernel/linux/linux-yocto-4.14.71/0732-drm-amd-display-Clean-up-cursor-code.patch
blob: bd038211e7cf354c61c1af99bc851b5e96105b1f (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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
From 4f58082aaa5f35ce2d7150443b6f82743afbab8e Mon Sep 17 00:00:00 2001
From: Harry Wentland <harry.wentland@amd.com>
Date: Mon, 31 Jul 2017 16:32:18 -0400
Subject: [PATCH 0732/4131] drm/amd/display: Clean up cursor code

This will also fix disappearing cursor after resume.

With this change we'll set cursor attributes, as well as
cursor position on every update. The impact is minor.

These are sample logs that show timestamps at beginning
and end of atomic_check, commit_tail, handle_cursor_update,
and before and after cursor_attribute and cursor_position
calls:

[   66.800353] hwhw: begin of check
[   66.800377] hwhw: end of check
[   66.800428] hwhw: begin of commit_tail
[   66.800441] hwhw: begin of cursor
[   66.800449] hwhw: begin of cursor_attr
[   66.800468] hwhw: end of cursor_attr
[   66.800484] hwhw: end of cursor_positionr
[   66.800501] hwhw: end of commit_tail
[   66.807139] hwhw: begin of check
[   66.807160] hwhw: end of check
[   66.807206] hwhw: begin of commit_tail
[   66.807217] hwhw: begin of cursor
[   66.807225] hwhw: begin of cursor_attr
[   66.807357] hwhw: end of cursor_attr
[   66.807374] hwhw: end of cursor_positionr
[   66.807392] hwhw: end of commit_tail

Signed-off-by: Harry Wentland <harry.wentland@amd.com>
Reviewed-by: Andrey Grodzovsky <Andrey.Grodzovsky@amd.com>
Acked-by: Harry Wentland <Harry.Wentland@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 283 +++++++---------------
 1 file changed, 92 insertions(+), 191 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index d81c0a0..031f31c 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -1652,178 +1652,6 @@ static const struct drm_encoder_funcs amdgpu_dm_encoder_funcs = {
 	.destroy = amdgpu_dm_encoder_destroy,
 };
 
-static void dm_set_cursor(
-	struct amdgpu_crtc *amdgpu_crtc,
-	uint64_t gpu_addr,
-	uint32_t width,
-	uint32_t height)
-{
-	struct dc_cursor_attributes attributes;
-	struct dc_cursor_position position;
-	struct drm_crtc *crtc = &amdgpu_crtc->base;
-	int x, y;
-	int xorigin = 0, yorigin = 0;
-	struct dm_crtc_state *acrtc_state = to_dm_crtc_state(crtc->state);
-
-	amdgpu_crtc->cursor_width = width;
-	amdgpu_crtc->cursor_height = height;
-
-	attributes.address.high_part = upper_32_bits(gpu_addr);
-	attributes.address.low_part  = lower_32_bits(gpu_addr);
-	attributes.width             = width;
-	attributes.height            = height;
-	attributes.color_format      = CURSOR_MODE_COLOR_PRE_MULTIPLIED_ALPHA;
-	attributes.rotation_angle    = 0;
-	attributes.attribute_flags.value = 0;
-
-	attributes.pitch = attributes.width;
-
-	x = amdgpu_crtc->cursor_x;
-	y = amdgpu_crtc->cursor_y;
-
-	/* avivo cursor are offset into the total surface */
-	x += crtc->primary->state->src_x >> 16;
-	y += crtc->primary->state->src_y >> 16;
-
-	if (x < 0) {
-		xorigin = min(-x, amdgpu_crtc->max_cursor_width - 1);
-		x = 0;
-	}
-	if (y < 0) {
-		yorigin = min(-y, amdgpu_crtc->max_cursor_height - 1);
-		y = 0;
-	}
-
-	position.enable = true;
-	position.x = x;
-	position.y = y;
-
-	position.x_hotspot = xorigin;
-	position.y_hotspot = yorigin;
-
-	if (!dc_stream_set_cursor_attributes(
-				acrtc_state->stream,
-				&attributes)) {
-		DRM_ERROR("DC failed to set cursor attributes\n");
-	}
-
-	if (!dc_stream_set_cursor_position(
-				acrtc_state->stream,
-				&position)) {
-		DRM_ERROR("DC failed to set cursor position\n");
-	}
-}
-
-static int dm_crtc_cursor_set(
-	struct drm_crtc *crtc,
-	uint64_t address,
-	uint32_t width,
-	uint32_t height)
-{
-	struct dc_cursor_position position;
-	struct dm_crtc_state *acrtc_state = to_dm_crtc_state(crtc->state);
-
-	int ret;
-
-	struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
-	ret = EINVAL;
-
-	DRM_DEBUG_KMS("%s: crtc_id=%d with size %d to %d \n",
-		      __func__,
-		      amdgpu_crtc->crtc_id,
-		      width,
-		      height);
-
-	if (!address) {
-		/* turn off cursor */
-		position.enable = false;
-		position.x = 0;
-		position.y = 0;
-
-		if (acrtc_state->stream) {
-			/*set cursor visible false*/
-			dc_stream_set_cursor_position(
-				acrtc_state->stream,
-				&position);
-		}
-		goto release;
-
-	}
-
-	if ((width > amdgpu_crtc->max_cursor_width) ||
-		(height > amdgpu_crtc->max_cursor_height)) {
-		DRM_ERROR(
-			"%s: bad cursor width or height %d x %d\n",
-			__func__,
-			width,
-			height);
-		goto release;
-	}
-
-	/*program new cursor bo to hardware*/
-	dm_set_cursor(amdgpu_crtc, address, width, height);
-
-release:
-	return ret;
-
-}
-
-static int dm_crtc_cursor_move(struct drm_crtc *crtc,
-				     int x, int y)
-{
-	struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
-	int xorigin = 0, yorigin = 0;
-	struct dc_cursor_position position;
-	struct dm_crtc_state *acrtc_state = to_dm_crtc_state(crtc->state);
-
-	amdgpu_crtc->cursor_x = x;
-	amdgpu_crtc->cursor_y = y;
-
-	/* avivo cursor are offset into the total surface */
-	x += crtc->primary->state->src_x >> 16;
-	y += crtc->primary->state->src_y >> 16;
-
-	/*
-	 * TODO: for cursor debugging unguard the following
-	 */
-#if 0
-	DRM_DEBUG_KMS(
-		"%s: x %d y %d c->x %d c->y %d\n",
-		__func__,
-		x,
-		y,
-		crtc->x,
-		crtc->y);
-#endif
-
-	if (x < 0) {
-		xorigin = min(-x, amdgpu_crtc->max_cursor_width - 1);
-		x = 0;
-	}
-	if (y < 0) {
-		yorigin = min(-y, amdgpu_crtc->max_cursor_height - 1);
-		y = 0;
-	}
-
-	position.enable = true;
-	position.x = x;
-	position.y = y;
-
-	position.x_hotspot = xorigin;
-	position.y_hotspot = yorigin;
-
-	if (acrtc_state->stream) {
-		if (!dc_stream_set_cursor_position(
-					acrtc_state->stream,
-					&position)) {
-			DRM_ERROR("DC failed to set cursor position\n");
-			return -EINVAL;
-		}
-	}
-
-	return 0;
-}
-
 static bool fill_rects_from_plane_state(
 	const struct drm_plane_state *state,
 	struct dc_plane_state *plane_state)
@@ -3940,34 +3768,107 @@ static void remove_stream(
 	acrtc->enabled = false;
 }
 
+int get_cursor_position(struct drm_plane *plane, struct drm_crtc *crtc,
+			 struct dc_cursor_position *position)
+{
+	struct amdgpu_crtc *amdgpu_crtc = amdgpu_crtc = to_amdgpu_crtc(crtc);
+	int x, y;
+	int xorigin = 0, yorigin = 0;
+
+	if (!crtc || !plane->state->fb) {
+		position->enable = false;
+		position->x = 0;
+		position->y = 0;
+		return 0;
+	}
+
+	if ((plane->state->crtc_w > amdgpu_crtc->max_cursor_width) ||
+	    (plane->state->crtc_h > amdgpu_crtc->max_cursor_height)) {
+		DRM_ERROR("%s: bad cursor width or height %d x %d\n",
+			  __func__,
+			  plane->state->crtc_w,
+			  plane->state->crtc_h);
+		return -EINVAL;
+	}
+
+	x = plane->state->crtc_x;
+	y = plane->state->crtc_y;
+	/* avivo cursor are offset into the total surface */
+	x += crtc->primary->state->src_x >> 16;
+	y += crtc->primary->state->src_y >> 16;
+	if (x < 0) {
+		xorigin = min(-x, amdgpu_crtc->max_cursor_width - 1);
+		x = 0;
+	}
+	if (y < 0) {
+		yorigin = min(-y, amdgpu_crtc->max_cursor_height - 1);
+		y = 0;
+	}
+	position->enable = true;
+	position->x = x;
+	position->y = y;
+	position->x_hotspot = xorigin;
+	position->y_hotspot = yorigin;
+
+	return 0;
+}
+
 static void handle_cursor_update(
 		struct drm_plane *plane,
 		struct drm_plane_state *old_plane_state)
 {
+	struct amdgpu_framebuffer *afb = to_amdgpu_framebuffer(plane->state->fb);
+	struct drm_crtc *crtc = afb ? plane->state->crtc : old_plane_state->crtc;
+	struct dm_crtc_state *crtc_state = crtc ? to_dm_crtc_state(crtc->state) : NULL;
+	struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
+	uint64_t address = afb ? afb->address : 0;
+	struct dc_cursor_position position;
+	struct dc_cursor_attributes attributes;
+	int ret;
+
 	if (!plane->state->fb && !old_plane_state->fb)
 		return;
 
-	/* Check if it's a cursor on/off update or just cursor move*/
-	if (plane->state->fb == old_plane_state->fb)
-		dm_crtc_cursor_move(
-				plane->state->crtc,
-				plane->state->crtc_x,
-				plane->state->crtc_y);
-	else {
-		struct amdgpu_framebuffer *afb =
-				to_amdgpu_framebuffer(plane->state->fb);
-		dm_crtc_cursor_set(
-				(!!plane->state->fb) ?
-						plane->state->crtc :
-						old_plane_state->crtc,
-				(!!plane->state->fb) ?
-						afb->address :
-						0,
-				plane->state->crtc_w,
-				plane->state->crtc_h);
+	DRM_DEBUG_KMS("%s: crtc_id=%d with size %d to %d\n",
+		      __func__,
+		      amdgpu_crtc->crtc_id,
+		      plane->state->crtc_w,
+		      plane->state->crtc_h);
+
+	ret = get_cursor_position(plane, crtc, &position);
+	if (ret)
+		return;
+
+	if (!position.enable) {
+		/* turn off cursor */
+		if (crtc_state && crtc_state->stream)
+			dc_stream_set_cursor_position(crtc_state->stream,
+						      &position);
+		return;
 	}
-}
 
+	amdgpu_crtc->cursor_width = plane->state->crtc_w;
+	amdgpu_crtc->cursor_height = plane->state->crtc_h;
+
+	attributes.address.high_part = upper_32_bits(address);
+	attributes.address.low_part  = lower_32_bits(address);
+	attributes.width             = plane->state->crtc_w;
+	attributes.height            = plane->state->crtc_h;
+	attributes.color_format      = CURSOR_MODE_COLOR_PRE_MULTIPLIED_ALPHA;
+	attributes.rotation_angle    = 0;
+	attributes.attribute_flags.value = 0;
+
+	attributes.pitch = attributes.width;
+
+	if (!dc_stream_set_cursor_attributes(crtc_state->stream,
+					     &attributes))
+		DRM_ERROR("DC failed to set cursor attributes\n");
+
+	if (crtc_state->stream)
+		if (!dc_stream_set_cursor_position(crtc_state->stream,
+						   &position))
+			DRM_ERROR("DC failed to set cursor position\n");
+}
 
 static void prepare_flip_isr(struct amdgpu_crtc *acrtc)
 {
-- 
2.7.4