aboutsummaryrefslogtreecommitdiffstats
path: root/meta-amd-bsp/recipes-kernel/linux/linux-yocto-4.14.71/2320-drm-amd-display-Refactor-atomic-check.patch
blob: c48308c530453f510cb2fa9867ed53554fd89574 (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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
From e1ea26640715bd15a1452b2568aa76fe7371c805 Mon Sep 17 00:00:00 2001
From: Andrey Grodzovsky <Andrey.Grodzovsky@amd.com>
Date: Fri, 18 Aug 2017 10:52:20 -0400
Subject: [PATCH 2320/4131] drm/amd/display: Refactor atomic check.

Split into update crtcs and update plane functions.

Signed-off-by: Andrey Grodzovsky <Andrey.Grodzovsky@amd.com>
Reviewed-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 | 453 ++++++++++++----------
 1 file changed, 257 insertions(+), 196 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 9e01146..7d6f48b 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -1673,12 +1673,6 @@ static bool modeset_required(struct drm_crtc_state *crtc_state,
 			     struct dc_stream_state *new_stream,
 			     struct dc_stream_state *old_stream)
 {
-	if (dc_is_stream_unchanged(new_stream, old_stream)) {
-		crtc_state->mode_changed = false;
-		DRM_DEBUG_KMS("Mode change not required, setting mode_changed to %d",
-			      crtc_state->mode_changed);
-	}
-
 	if (!drm_atomic_crtc_needs_modeset(crtc_state))
 		return false;
 
@@ -4129,9 +4123,7 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,
 			continue;
 		}
 
-		if (!fb || !crtc || pcrtc != crtc || !crtc->state->active ||
-				(!crtc->state->planes_changed &&
-						!pcrtc->state->color_mgmt_changed))
+		if (!fb || !crtc || pcrtc != crtc || !crtc->state->active)
 			continue;
 
 		pflip_needed = !state->allow_modeset;
@@ -4614,91 +4606,77 @@ static int do_aquire_global_lock(
 	return ret < 0 ? ret : 0;
 }
 
-int amdgpu_dm_atomic_check(struct drm_device *dev,
-			struct drm_atomic_state *state)
+static int dm_update_crtcs_state(
+		struct dc *dc,
+		struct drm_atomic_state *state,
+		bool enable,
+		bool *lock_and_validation_needed)
 {
 	struct drm_crtc *crtc;
 	struct drm_crtc_state *crtc_state;
-	struct drm_plane *plane;
-	struct drm_plane_state *plane_state;
-	int i, j;
-	int ret;
-	struct amdgpu_device *adev = dev->dev_private;
-	struct dc *dc = adev->dm.dc;
-	struct drm_connector *connector;
-	struct drm_connector_state *conn_state;
+	int i;
 	struct dm_crtc_state *old_acrtc_state, *new_acrtc_state;
 	struct dm_atomic_state *dm_state = to_dm_atomic_state(state);
-	bool pflip_needed  = !state->allow_modeset;
-
-	/*
-	 * This bool will be set for true for any modeset/reset
-	 * or plane update which implies non fast surface update.
-	 */
-	bool lock_and_validation_needed = false;
+	int ret = 0;
 
-	ret = drm_atomic_helper_check_modeset(dev, state);
+	/*TODO Move this code into dm_crtc_atomic_check once we get rid of dc_validation_set */
+	/* update changed items */
+	for_each_crtc_in_state(state, crtc, crtc_state, i) {
+		struct amdgpu_crtc *acrtc = NULL;
+		struct amdgpu_connector *aconnector = NULL;
+		struct dc_stream_state *new_stream = NULL;
+		struct drm_connector_state *conn_state = NULL;
+		struct dm_connector_state *dm_conn_state = NULL;
 
-	if (ret) {
-		DRM_ERROR("Atomic state validation failed with error :%d !\n", ret);
-		return ret;
-	}
 
-	/* Remove exiting planes if they are disabled or their CRTC is updated */
-	for_each_crtc_in_state(state, crtc, crtc_state, i) {
+		old_acrtc_state = to_dm_crtc_state(crtc->state);
 		new_acrtc_state = to_dm_crtc_state(crtc_state);
+		acrtc = to_amdgpu_crtc(crtc);
 
-		if (pflip_needed)
-			continue;
+		aconnector = amdgpu_dm_find_first_crct_matching_connector(state, crtc, true);
 
-		for_each_plane_in_state(state, plane, plane_state, j) {
-			struct drm_crtc *plane_crtc = plane_state->crtc;
-			struct dm_plane_state *dm_plane_state = to_dm_plane_state(plane_state);
+		/* TODO This hack should go away */
+		if (aconnector && aconnector->dc_sink) {
+			conn_state = drm_atomic_get_connector_state(state,
+								    &aconnector->base);
 
-			if (plane->type == DRM_PLANE_TYPE_CURSOR)
-				continue;
-
-			if (crtc != plane_crtc || !dm_plane_state->dc_state)
-				continue;
+			if (IS_ERR(conn_state)) {
+				ret = PTR_ERR_OR_ZERO(conn_state);
+				break;
+			}
 
-			WARN_ON(!new_acrtc_state->stream);
+			dm_conn_state = to_dm_connector_state(conn_state);
 
-			if (drm_atomic_plane_disabling(plane->state, plane_state) ||
-					drm_atomic_crtc_needs_modeset(crtc_state)) {
-				if (!dc_remove_plane_from_context(
-						dc,
-						new_acrtc_state->stream,
-						dm_plane_state->dc_state,
-						dm_state->context)) {
+			new_stream = create_stream_for_sink(aconnector,
+							    &crtc_state->mode,
+							    dm_conn_state);
 
-					ret = EINVAL;
-					goto fail;
-				}
+			/*
+			 * we can have no stream on ACTION_SET if a display
+			 * was disconnected during S3, in this case it not and
+			 * error, the OS will be updated after detection, and
+			 * do the right thing on next atomic commit
+			 */
 
+			if (!new_stream) {
+				DRM_DEBUG_KMS("%s: Failed to create new stream for crtc %d\n",
+						__func__, acrtc->base.base.id);
+				break;
 			}
+		}
 
-			dc_plane_state_release(dm_plane_state->dc_state);
-			dm_plane_state->dc_state = NULL;
+		if (dc_is_stream_unchanged(new_stream,
+				old_acrtc_state->stream)) {
 
-			DRM_DEBUG_KMS("Disabling DRM plane: %d on DRM crtc %d\n",
-					plane->base.id, crtc->base.id);
-		}
-	}
+				crtc_state->mode_changed = false;
 
-	/*TODO Move this code into dm_crtc_atomic_check once we get rid of dc_validation_set */
-	/* update changed items */
-	for_each_crtc_in_state(state, crtc, crtc_state, i) {
-		struct amdgpu_crtc *acrtc = NULL;
-		struct amdgpu_connector *aconnector = NULL;
-		struct dc_stream_state *new_stream = NULL;
-		struct drm_connector_state *conn_state = NULL;
-		struct dm_connector_state *dm_conn_state = NULL;
+				DRM_DEBUG_KMS("Mode change not required, setting mode_changed to %d",
+					      crtc_state->mode_changed);
+		}
 
-		old_acrtc_state = to_dm_crtc_state(crtc->state);
-		new_acrtc_state = to_dm_crtc_state(crtc_state);
-		acrtc = to_amdgpu_crtc(crtc);
 
-		aconnector = amdgpu_dm_find_first_crct_matching_connector(state, crtc, true);
+		if (!drm_atomic_crtc_needs_modeset(crtc_state))
+				continue;
 
 #if !defined(OS_NAME_RHEL_7_2)
 		DRM_DEBUG_KMS(
@@ -4714,109 +4692,252 @@ int amdgpu_dm_atomic_check(struct drm_device *dev,
 			crtc_state->connectors_changed);
 #endif
 
-		if (modereset_required(crtc_state)) {
+		/* Remove stream for any changed/disabled CRTC */
+		if (!enable) {
+
+			if (!old_acrtc_state->stream)
+				continue;
+
+			DRM_DEBUG_KMS("Disabling DRM crtc: %d\n",
+					crtc->base.id);
 
 			/* i.e. reset mode */
-			if (new_acrtc_state->stream) {
+			if (!dc_remove_stream_from_ctx(
+					dc,
+					dm_state->context,
+					old_acrtc_state->stream)) {
+				ret = -EINVAL;
+				break;
+			}
+
+			dc_stream_release(old_acrtc_state->stream);
+			new_acrtc_state->stream = NULL;
+
+			*lock_and_validation_needed = true;
+
+		} else {/* Add stream for any updated/enabled CRTC */
+
+			if (modereset_required(crtc_state))
+				continue;
+
+			if (modeset_required(crtc_state, new_stream,
+					     old_acrtc_state->stream)) {
+
+				WARN_ON(new_acrtc_state->stream);
+
+				new_acrtc_state->stream = new_stream;
+				dc_stream_retain(new_stream);
+
+				DRM_DEBUG_KMS("Enabling DRM crtc: %d\n",
+							crtc->base.id);
 
-				if (!dc_remove_stream_from_ctx(
+				if (!dc_add_stream_to_ctx(
 						dc,
 						dm_state->context,
 						new_acrtc_state->stream)) {
 					ret = -EINVAL;
-					goto fail;
+					break;
 				}
 
-				dc_stream_release(new_acrtc_state->stream);
-				new_acrtc_state->stream = NULL;
-
-				lock_and_validation_needed = true;
+				*lock_and_validation_needed = true;
 			}
+		}
 
-		} else {
+		/* Release extra reference */
+		if (new_stream)
+			 dc_stream_release(new_stream);
+	}
 
-			if (aconnector) {
-				conn_state = drm_atomic_get_connector_state(state,
-									    &aconnector->base);
+	return ret;
+}
 
-				if (IS_ERR(conn_state)) {
-					ret = PTR_ERR_OR_ZERO(conn_state);
-					goto fail;
-				}
+static int dm_update_planes_state(
+		struct dc *dc,
+		struct drm_atomic_state *state,
+		bool enable,
+		bool *lock_and_validation_needed)
+{
+	struct drm_crtc *new_plane_crtc, *old_plane_crtc;
+	struct drm_crtc_state *new_crtc_state;
+	struct drm_plane *plane;
+	struct drm_plane_state *old_plane_state, *new_plane_state;
+	struct dm_crtc_state *new_acrtc_state, *old_acrtc_state;
+	struct dm_atomic_state *dm_state = to_dm_atomic_state(state);
+	struct dm_plane_state *new_dm_plane_state, *old_dm_plane_state;
+	int i ;
+	/* TODO return page_flip_needed() function */
+	bool pflip_needed  = !state->allow_modeset;
+	int ret = 0;
 
-				dm_conn_state = to_dm_connector_state(conn_state);
+	if (pflip_needed)
+		return ret;
 
-				new_stream = create_stream_for_sink(aconnector,
-								    &crtc_state->mode,
-								    dm_conn_state);
+	/* Add new planes */
+	for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i) {
+		new_plane_crtc = new_plane_state->crtc;
+		old_plane_crtc = old_plane_state->crtc;
+		new_dm_plane_state = to_dm_plane_state(new_plane_state);
+		old_dm_plane_state = to_dm_plane_state(old_plane_state);
+
+		/*TODO Implement atomic check for cursor plane */
+		if (plane->type == DRM_PLANE_TYPE_CURSOR)
+			continue;
 
-				/*
-				 * we can have no stream on ACTION_SET if a display
-				 * was disconnected during S3, in this case it not and
-				 * error, the OS will be updated after detection, and
-				 * do the right thing on next atomic commit
-				 */
+		/* Remove any changed/removed planes */
+		if (!enable) {
 
-				if (!new_stream) {
-					DRM_DEBUG_KMS("%s: Failed to create new stream for crtc %d\n",
-							__func__, acrtc->base.base.id);
-					break;
-				}
+			if (!old_plane_crtc)
+				continue;
+
+			old_acrtc_state = to_dm_crtc_state(
+					drm_atomic_get_old_crtc_state(
+							state,
+							old_plane_crtc));
+
+			if (!old_acrtc_state->stream)
+				continue;
+
+			DRM_DEBUG_KMS("Disabling DRM plane: %d on DRM crtc %d\n",
+					plane->base.id, old_plane_crtc->base.id);
 
+			if (!dc_remove_plane_from_context(
+					dc,
+					old_acrtc_state->stream,
+					old_dm_plane_state->dc_state,
+					dm_state->context)) {
 
+				ret = EINVAL;
+				return ret;
 			}
 
-			if (modeset_required(crtc_state, new_stream,
-					     old_acrtc_state->stream)) {
 
-				if (new_acrtc_state->stream) {
+			dc_plane_state_release(old_dm_plane_state->dc_state);
+			new_dm_plane_state->dc_state = NULL;
 
-					if (!dc_remove_stream_from_ctx(
-							dc,
-							dm_state->context,
-							new_acrtc_state->stream)) {
-						ret = -EINVAL;
-						goto fail;
-					}
+			*lock_and_validation_needed = true;
 
+		} else { /* Add new planes */
 
-					dc_stream_release(new_acrtc_state->stream);
-				}
+			if (drm_atomic_plane_disabling(plane->state, new_plane_state))
+				continue;
 
-				new_acrtc_state->stream = new_stream;
+			if (!new_plane_crtc)
+				continue;
 
-				if (!dc_add_stream_to_ctx(
-						dc,
-						dm_state->context,
-						new_acrtc_state->stream)) {
-					ret = -EINVAL;
-					goto fail;
-				}
+			new_crtc_state = drm_atomic_get_new_crtc_state(state, new_plane_crtc);
+			new_acrtc_state = to_dm_crtc_state(new_crtc_state);
 
-				lock_and_validation_needed = true;
-			} else {
-				/*
-				 * The new stream is unused, so we release it
-				 */
-				if (new_stream)
-					dc_stream_release(new_stream);
+			if (!new_acrtc_state->stream)
+				continue;
+
+
+			WARN_ON(new_dm_plane_state->dc_state);
+
+			new_dm_plane_state->dc_state = dc_create_plane_state(dc);
+
+			DRM_DEBUG_KMS("Enabling DRM plane: %d on DRM crtc %d\n",
+					plane->base.id, new_plane_crtc->base.id);
+
+			if (!new_dm_plane_state->dc_state) {
+				ret = -EINVAL;
+				return ret;
+			}
+
+			ret = fill_plane_attributes(
+				new_plane_crtc->dev->dev_private,
+				new_dm_plane_state->dc_state,
+				new_plane_state,
+				new_crtc_state,
+				false);
+			if (ret)
+				return ret;
+
+
+			if (!dc_add_plane_to_context(
+					dc,
+					new_acrtc_state->stream,
+					new_dm_plane_state->dc_state,
+					dm_state->context)) {
 
+				ret = -EINVAL;
+				return ret;
 			}
+
+			*lock_and_validation_needed = true;
 		}
+	}
 
 
-		/*
-		 * Hack: Commit needs planes right now, specifically for gamma
-		 * TODO rework commit to check CRTC for gamma change
-		 */
-		if (crtc_state->color_mgmt_changed) {
+	return ret;
+}
+
+int amdgpu_dm_atomic_check(struct drm_device *dev,
+			struct drm_atomic_state *state)
+{
+	int i;
+	int ret;
+	struct amdgpu_device *adev = dev->dev_private;
+	struct dc *dc = adev->dm.dc;
+	struct dm_atomic_state *dm_state = to_dm_atomic_state(state);
+	struct drm_connector *connector;
+	struct drm_connector_state *conn_state;
+	struct drm_crtc *crtc;
+	struct drm_crtc_state *crtc_state;
+
+	/*
+	 * This bool will be set for true for any modeset/reset
+	 * or plane update which implies non fast surface update.
+	 */
+	bool lock_and_validation_needed = false;
+
+	ret = drm_atomic_helper_check_modeset(dev, state);
 
+	if (ret) {
+		DRM_ERROR("Atomic state validation failed with error :%d !\n", ret);
+		return ret;
+	}
+
+	/*
+	 * Hack: Commit needs planes right now, specifically for gamma
+	 * TODO rework commit to check CRTC for gamma change
+	 */
+	for_each_crtc_in_state(state, crtc, crtc_state, i) {
+		if (crtc_state->color_mgmt_changed) {
 			ret = drm_atomic_add_affected_planes(state, crtc);
 			if (ret)
 				goto fail;
 		}
 	}
 
+	/* Remove exiting planes if they are modified */
+	ret = dm_update_planes_state(dc, state, false, &lock_and_validation_needed);
+	if (ret) {
+		goto fail;
+	}
+
+	/* Disable all crtcs which require disable */
+	ret = dm_update_crtcs_state(dc, state, false, &lock_and_validation_needed);
+	if (ret) {
+		goto fail;
+	}
+
+	/* Enable all crtcs which require enable */
+	ret = dm_update_crtcs_state(dc, state, true, &lock_and_validation_needed);
+	if (ret) {
+		goto fail;
+	}
+
+	/* Add new/modified planes */
+	ret = dm_update_planes_state(dc, state, true, &lock_and_validation_needed);
+	if (ret) {
+		goto fail;
+	}
+
+	 /* Run this here since we want to validate the streams we created */
+	 ret = drm_atomic_helper_check_planes(dev, state);
+	 if (ret)
+		 goto fail;
+
 	/* Check scaling and undersacn changes*/
 	/*TODO Removed scaling changes validation due to inability to commit
 	 * new stream into context w\o causing full reset. Need to
@@ -4841,66 +4962,6 @@ int amdgpu_dm_atomic_check(struct drm_device *dev,
 		lock_and_validation_needed = true;
 	}
 
-	/* Add new planes */
-	for_each_crtc_in_state(state, crtc, crtc_state, i) {
-		new_acrtc_state = to_dm_crtc_state(crtc_state);
-
-		if (pflip_needed)
-			continue;
-
-		for_each_plane_in_state(state, plane, plane_state, j) {
-			struct drm_crtc *plane_crtc = plane_state->crtc;
-			struct dm_plane_state *dm_plane_state = to_dm_plane_state(plane_state);
-
-			/*TODO Implement atomic check for cursor plane */
-			if (plane->type == DRM_PLANE_TYPE_CURSOR)
-				continue;
-
-			if (crtc != plane_crtc)
-				continue;
-
-			if (!drm_atomic_plane_disabling(plane->state, plane_state)) {
-				struct dc_plane_state *dc_plane_state;
-
-				WARN_ON(!new_acrtc_state->stream);
-
-				dc_plane_state = dc_create_plane_state(dc);
-
-				WARN_ON(dm_plane_state->dc_state);
-
-				dm_plane_state->dc_state = dc_plane_state;
-
-				ret = fill_plane_attributes(
-					plane_crtc->dev->dev_private,
-					dc_plane_state,
-					plane_state,
-					crtc_state,
-					false);
-				if (ret)
-					goto fail;
-
-
-				if (!dc_add_plane_to_context(
-						dc,
-						new_acrtc_state->stream,
-						dc_plane_state,
-						dm_state->context)) {
-
-					ret = EINVAL;
-					goto fail;
-				}
-
-
-				lock_and_validation_needed = true;
-			}
-		}
-	}
-
-	/* Run this here since we want to validate the streams we created */
-	ret = drm_atomic_helper_check_planes(dev, state);
-	if (ret)
-		goto fail;
-
 	/*
 	 * For full updates case when
 	 * removing/adding/updating  streams on once CRTC while flipping
@@ -4933,7 +4994,7 @@ int amdgpu_dm_atomic_check(struct drm_device *dev,
 	else if (ret == -EINTR || ret == -EAGAIN || ret == -ERESTARTSYS)
 		DRM_DEBUG_KMS("Atomic check stopped due to to signal.\n");
 	else
-		DRM_ERROR("Atomic check failed with err: %d .\n", ret);
+		DRM_ERROR("Atomic check failed with err: %d \n", ret);
 
 	return ret;
 }
-- 
2.7.4