aboutsummaryrefslogtreecommitdiffstats
path: root/common/recipes-kernel/linux/files/0679-drm-amd-dal-MST-get-stream-hadle-refact.patch
blob: 6a6c82bf6a1e37c68316bb820a0d259738715da1 (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
From ddd580e8ff564c5d5f0b4fa941f8e64e365ea0d3 Mon Sep 17 00:00:00 2001
From: Hersen Wu <hersenxs.wu@amd.com>
Date: Thu, 7 Jan 2016 15:06:08 -0500
Subject: [PATCH 0679/1110] drm/amd/dal: MST get stream hadle refact

Signed-off-by: Hersen Wu <hersenxs.wu@amd.com>
Acked-by: Jordan Lazare <Jordan.Lazare@amd.com>
---
 .../gpu/drm/amd/dal/amdgpu_dm/amdgpu_dc_helpers.c  |  94 ++++++-------
 drivers/gpu/drm/amd/dal/dc/core/dc_link.c          | 147 +++++++++++++++------
 drivers/gpu/drm/amd/dal/dc/core/dc_link_hwss.c     |  11 +-
 drivers/gpu/drm/amd/dal/dc/dc_helpers.h            |   3 +-
 .../drm/amd/dal/dc/dce110/dce110_hw_sequencer.c    |   2 +
 drivers/gpu/drm/amd/dal/dc/inc/core_types.h        |   7 +-
 .../gpu/drm/amd/dal/include/link_service_types.h   |   1 +
 7 files changed, 167 insertions(+), 98 deletions(-)

diff --git a/drivers/gpu/drm/amd/dal/amdgpu_dm/amdgpu_dc_helpers.c b/drivers/gpu/drm/amd/dal/amdgpu_dm/amdgpu_dc_helpers.c
index 578517f..ff9b5c1 100644
--- a/drivers/gpu/drm/amd/dal/amdgpu_dm/amdgpu_dc_helpers.c
+++ b/drivers/gpu/drm/amd/dal/amdgpu_dm/amdgpu_dc_helpers.c
@@ -160,74 +160,73 @@ static struct amdgpu_connector *get_connector_for_link(
 	return aconnector;
 }
 
-static const struct dc_stream *get_stream_for_vcid(
-		struct drm_device *dev,
-		struct amdgpu_connector *master_port,
-		int vcid)
+const struct dp_mst_stream_allocation *find_stream_with_matching_vcpi(
+	const struct dp_mst_stream_allocation_table *table,
+	uint32_t vcpi)
 {
-	struct drm_connector *connector;
-	struct amdgpu_connector *aconnector;
-	struct drm_crtc *crtc;
-	struct amdgpu_crtc *acrtc;
-	struct dc_target *dc_target;
-
-	list_for_each_entry(
-		connector,
-		&dev->mode_config.connector_list,
-		head) {
-
-		aconnector = to_amdgpu_connector(connector);
-
-		/* Check whether mst connector */
-		if (!aconnector->mst_port)
-			continue;
-
-		/* Check whether same physical connector. */
-		if (master_port != aconnector->mst_port) {
-			continue;
-		}
+	int i;
 
-		if (aconnector->port->vcpi.vcpi == vcid) {
-			crtc = aconnector->base.state->crtc;
-			acrtc = to_amdgpu_crtc(crtc);
-			dc_target = acrtc->target;
-			return dc_target->streams[0];
-		}
+	for (i = 0; i < table->stream_count; i++) {
+		const struct dp_mst_stream_allocation *sa =
+				&table->stream_allocations[i];
+		if (sa->vcp_id == vcpi)
+			return sa;
 	}
 	return NULL;
 }
 
+
 static void get_payload_table(
 		struct drm_device *dev,
 		struct amdgpu_connector *aconnector,
-		struct dp_mst_stream_allocation_table *table)
+		const struct dc_stream *stream,
+		const struct dp_mst_stream_allocation_table *cur_table,
+		struct dp_mst_stream_allocation_table *proposed_table)
 {
 	int i;
-	struct drm_dp_mst_topology_mgr *mst_mgr = &aconnector->mst_port->mst_mgr;
-	struct amdgpu_connector *master_port = aconnector->mst_port;
+	struct drm_dp_mst_topology_mgr *mst_mgr =
+			&aconnector->mst_port->mst_mgr;
 
 	mutex_lock(&mst_mgr->payload_lock);
 
+	proposed_table->stream_count = 0;
+
 	/* number of active streams */
 	for (i = 0; i < mst_mgr->max_payloads; i++) {
 		if (mst_mgr->payloads[i].num_slots == 0)
-			break;
+			break; /* end of vcp_id table */
+
+		ASSERT(mst_mgr->payloads[i].payload_state !=
+				DP_PAYLOAD_DELETE_LOCAL);
 
 		if (mst_mgr->payloads[i].payload_state == DP_PAYLOAD_LOCAL ||
-				mst_mgr->payloads[i].payload_state == DP_PAYLOAD_REMOTE) {
-			table->stream_allocations[i].slot_count = mst_mgr->payloads[i].num_slots;
-			table->stream_allocations[i].stream =
-					get_stream_for_vcid(
-							dev,
-							master_port,
-							mst_mgr->payloads[i].vcpi);
+			mst_mgr->payloads[i].payload_state ==
+					DP_PAYLOAD_REMOTE) {
+
+			const struct dp_mst_stream_allocation *sa_src
+				= find_stream_with_matching_vcpi(
+					cur_table,
+					mst_mgr->proposed_vcpis[i]->vcpi);
+
+			if (sa_src) {
+				proposed_table->stream_allocations[
+					proposed_table->stream_count] = *sa_src;
+				proposed_table->stream_count++;
+			} else {
+				struct dp_mst_stream_allocation *sa =
+					&proposed_table->stream_allocations[
+						proposed_table->stream_count];
+
+				sa->slot_count =
+						mst_mgr->payloads[i].num_slots;
+				sa->stream = stream;
+				sa->vcp_id = mst_mgr->proposed_vcpis[i]->vcpi;
+				proposed_table->stream_count++;
+			}
 		}
 	}
 
-	table->stream_count = i;
-
 	mutex_unlock(&mst_mgr->payload_lock);
-
 }
 
 /*
@@ -236,7 +235,8 @@ static void get_payload_table(
 bool dc_helpers_dp_mst_write_payload_allocation_table(
 		struct dc_context *ctx,
 		const struct dc_stream *stream,
-		struct dp_mst_stream_allocation_table *table,
+		const struct dp_mst_stream_allocation_table *cur_table,
+		struct dp_mst_stream_allocation_table *proposed_table,
 		bool enable)
 {
 	struct amdgpu_device *adev = ctx->driver_context;
@@ -312,7 +312,7 @@ bool dc_helpers_dp_mst_write_payload_allocation_table(
 	 * stream. AMD ASIC stream slot allocation should follow the same
 	 * sequence. copy DRM MST allocation to dc */
 
-	get_payload_table(dev, aconnector, table);
+	get_payload_table(dev, aconnector, stream, cur_table, proposed_table);
 
 	if (ret)
 		return false;
diff --git a/drivers/gpu/drm/amd/dal/dc/core/dc_link.c b/drivers/gpu/drm/amd/dal/dc/core/dc_link.c
index ac6785a..794465e 100644
--- a/drivers/gpu/drm/amd/dal/dc/core/dc_link.c
+++ b/drivers/gpu/drm/amd/dal/dc/core/dc_link.c
@@ -1106,18 +1106,6 @@ static enum dc_status enable_link_dp(struct core_stream *stream)
 static enum dc_status enable_link_dp_mst(struct core_stream *stream)
 {
 	struct core_link *link = stream->sink->link;
-	bool already_enabled = false;
-	int i;
-
-	for (i = 0; i < link->enabled_stream_count; i++) {
-		if (link->enabled_streams[i] == stream)
-			already_enabled = true;
-	}
-
-	if (!already_enabled && link->enabled_stream_count < MAX_SINKS_PER_LINK)
-		link->enabled_streams[link->enabled_stream_count++] = stream;
-	else if (link->enabled_stream_count >= MAX_SINKS_PER_LINK)
-		return DC_ERROR_UNEXPECTED;
 
 	/* sink signal type after MST branch is MST. Multiple MST sinks
 	 * share one link. Link DP PHY is enable or training only once.
@@ -1285,9 +1273,12 @@ void core_link_resume(struct core_link *link)
 
 static struct fixed31_32 get_pbn_per_slot(struct core_stream *stream)
 {
-	struct link_settings *link_settings = &stream->sink->link->cur_link_settings;
-	uint32_t link_rate_in_mbps = link_settings->link_rate * LINK_RATE_REF_FREQ_IN_MHZ;
-	struct fixed31_32 mbps = dal_fixed31_32_from_int(link_rate_in_mbps * link_settings->lane_count);
+	struct link_settings *link_settings =
+			&stream->sink->link->cur_link_settings;
+	uint32_t link_rate_in_mbps =
+			link_settings->link_rate * LINK_RATE_REF_FREQ_IN_MHZ;
+	struct fixed31_32 mbps = dal_fixed31_32_from_int(
+			link_rate_in_mbps * link_settings->lane_count);
 
 	return dal_fixed31_32_div_int(mbps, 54);
 }
@@ -1318,15 +1309,13 @@ static struct fixed31_32 get_pbn_from_timing(struct core_stream *stream)
 
 	/*
 	 * margin 5300ppm + 300ppm ~ 0.6% as per spec, factor is 1.006
-	 *
 	 * The unit of 54/64Mbytes/sec is an arbitrary unit chosen based on
 	 * common multiplier to render an integer PBN for all link rate/lane
 	 * counts combinations
-	 * 	 *
 	 * calculate
-	 * 	peak_kbps *= (1006/1000)
-	 * 	peak_kbps *= (64/54)
-	 * 	peak_kbps *= 8    convert to bytes
+	 * peak_kbps *= (1006/1000)
+	 * peak_kbps *= (64/54)
+	 * peak_kbps *= 8    convert to bytes
 	 */
 
 	numerator = 64 * PEAK_FACTOR_X1000;
@@ -1342,11 +1331,12 @@ static enum dc_status allocate_mst_payload(struct core_stream *stream)
 	struct core_link *link = stream->sink->link;
 	struct link_encoder *link_encoder = link->link_enc;
 	struct stream_encoder *stream_encoder = stream->stream_enc;
-	struct dp_mst_stream_allocation_table table = {0};
+	struct dp_mst_stream_allocation_table proposed_table = {0};
 	struct fixed31_32 avg_time_slots_per_mtp;
 	struct dc *dc = stream->ctx->dc;
 	struct fixed31_32 pbn;
 	struct fixed31_32 pbn_per_slot;
+	uint8_t i;
 
 	/* enable_link_dp_mst already check link->enabled_stream_count
 	 * and stream is in link->stream[]. This is called during set mode,
@@ -1357,22 +1347,53 @@ static enum dc_status allocate_mst_payload(struct core_stream *stream)
 	dc_helpers_dp_mst_write_payload_allocation_table(
 		stream->ctx,
 		&stream->public,
-		&table,
+		&link->stream_alloc_table,
+		&proposed_table,
 		true);
 
+	dal_logger_write(link->ctx->logger,
+			LOG_MAJOR_MST,
+			LOG_MINOR_MST_PROGRAMMING,
+			"%s  "
+			"stream_count: %d: \n ",
+			__func__,
+			proposed_table.stream_count);
+
+	for (i = 0; i < MAX_CONTROLLER_NUM; i++) {
+		dal_logger_write(link->ctx->logger,
+		LOG_MAJOR_MST,
+		LOG_MINOR_MST_PROGRAMMING,
+		"stream[%d]: 0x%x      "
+		"stream[%d].vcp_id: %d      "
+		"stream[%d].slot_count: %d\n",
+		i,
+		proposed_table.stream_allocations[i].stream,
+		i,
+		proposed_table.stream_allocations[i].vcp_id,
+		i,
+		proposed_table.stream_allocations[i].slot_count);
+	}
+
+	ASSERT(proposed_table.stream_count > 0);
+	ASSERT(proposed_table.stream_count -
+			link->stream_alloc_table.stream_count == 1);
+
 	/*
 	 * temporary fix. Unplug of MST chain happened (two displays),
 	 * table is empty on first reset mode, and cause 0 division in
 	 * avg_time_slots_per_mtp calculation
 	 */
 
-	if (table.stream_count == 0)
+	/* to be removed or debugged */
+	if (proposed_table.stream_count == 0)
 		return DC_OK;
 
 	/* program DP source TX for payload */
 	dc->hwss.update_mst_stream_allocation_table(
 		link_encoder,
-		&table);
+		&proposed_table);
+
+	link->stream_alloc_table = proposed_table;
 
 	/* send down message */
 	dc_helpers_dp_mst_poll_for_allocation_change_trigger(
@@ -1384,10 +1405,12 @@ static enum dc_status allocate_mst_payload(struct core_stream *stream)
 			&stream->public,
 			true);
 
+	/* slot X.Y for only current stream */
 	pbn_per_slot = get_pbn_per_slot(stream);
 	pbn = get_pbn_from_timing(stream);
 	avg_time_slots_per_mtp = dal_fixed31_32_div(pbn, pbn_per_slot);
 
+
 	dc->hwss.set_mst_bandwidth(
 		stream_encoder,
 		avg_time_slots_per_mtp);
@@ -1401,10 +1424,10 @@ static enum dc_status deallocate_mst_payload(struct core_stream *stream)
 	struct core_link *link = stream->sink->link;
 	struct link_encoder *link_encoder = link->link_enc;
 	struct stream_encoder *stream_encoder = stream->stream_enc;
-	struct dp_mst_stream_allocation_table table = {0};
+	struct dp_mst_stream_allocation_table proposed_table = {0};
 	struct fixed31_32 avg_time_slots_per_mtp = dal_fixed31_32_from_int(0);
-	uint8_t i;
 	struct dc *dc = stream->ctx->dc;
+	uint8_t i;
 
 	/* deallocate_mst_payload is called before disable link. When mode or
 	 * disable/enable monitor, new stream is created which is not in link
@@ -1412,16 +1435,6 @@ static enum dc_status deallocate_mst_payload(struct core_stream *stream)
 	 * should not done. For new mode set, map_resources will get engine
 	 * for new stream, so stream_enc->id should be validated until here.
 	 */
-	if (link->enabled_stream_count == 0)
-		return DC_OK;
-
-	for (i = 0; i < link->enabled_stream_count; i++) {
-		if (link->enabled_streams[i] == stream)
-			break;
-	}
-	/* stream is not in link stream list */
-	if (i == link->enabled_stream_count)
-		return DC_OK;
 
 	/* slot X.Y */
 	dc->hwss.set_mst_bandwidth(
@@ -1432,12 +1445,41 @@ static enum dc_status deallocate_mst_payload(struct core_stream *stream)
 	dc_helpers_dp_mst_write_payload_allocation_table(
 		stream->ctx,
 		&stream->public,
-		&table,
+		&link->stream_alloc_table,
+		&proposed_table,
 		false);
 
+	dal_logger_write(link->ctx->logger,
+			LOG_MAJOR_MST,
+			LOG_MINOR_MST_PROGRAMMING,
+			"%s"
+			"stream_count: %d: ",
+			__func__,
+			proposed_table.stream_count);
+
+	for (i = 0; i < MAX_CONTROLLER_NUM; i++) {
+		dal_logger_write(link->ctx->logger,
+		LOG_MAJOR_MST,
+		LOG_MINOR_MST_PROGRAMMING,
+		"stream[%d]: 0x%x"
+		"stream[%d].vcp_id: %d"
+		"stream[%d].slot_count: %d",
+		i,
+		proposed_table.stream_allocations[i].stream,
+		i,
+		proposed_table.stream_allocations[i].vcp_id,
+		i,
+		proposed_table.stream_allocations[i].slot_count);
+	}
+
+	ASSERT(link->stream_alloc_table.stream_count -
+			proposed_table.stream_count == 1);
+
 	dc->hwss.update_mst_stream_allocation_table(
 		link_encoder,
-		&table);
+		&proposed_table);
+
+	link->stream_alloc_table = proposed_table;
 
 	dc_helpers_dp_mst_poll_for_allocation_change_trigger(
 			stream->ctx,
@@ -1482,3 +1524,32 @@ void core_link_disable_stream(
 	disable_link(stream);
 
 }
+
+void core_link_update_stream(
+		struct core_link *link,
+		struct core_stream *stream)
+{
+	if (stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
+		uint32_t i;
+
+		for (i = 0; i < link->stream_alloc_table.stream_count; i++) {
+			const struct core_stream *s;
+
+			s = DC_STREAM_TO_CORE(
+				link->stream_alloc_table.
+				stream_allocations[i].stream);
+
+			if (stream->stream_enc == s->stream_enc) {
+			link->stream_alloc_table.stream_allocations[i].stream =
+					&stream->public;
+
+			dal_logger_write(link->ctx->logger,
+					LOG_MAJOR_MST,
+					LOG_MINOR_MST_PROGRAMMING,
+					"%s  ",
+					__func__);
+			break;
+			}
+		}
+	}
+}
diff --git a/drivers/gpu/drm/amd/dal/dc/core/dc_link_hwss.c b/drivers/gpu/drm/amd/dal/dc/core/dc_link_hwss.c
index 1356238..27acac8 100644
--- a/drivers/gpu/drm/amd/dal/dc/core/dc_link_hwss.c
+++ b/drivers/gpu/drm/amd/dal/dc/core/dc_link_hwss.c
@@ -84,17 +84,8 @@ void dp_disable_link_phy(struct core_link *link, enum signal_type signal)
 
 void dp_disable_link_phy_mst(struct core_link *link, struct core_stream *stream)
 {
-	int i, j;
-
-	for (i = 0; i < link->enabled_stream_count; i++) {
-		if (link->enabled_streams[i] == stream) {
-			link->enabled_stream_count--;
-			for (j = i; j < link->enabled_stream_count; j++)
-				link->enabled_streams[j] = link->enabled_streams[j+1];
-		}
-	}
 	/* MST disable link only when no stream use the link */
-	if (link->enabled_stream_count > 0)
+	if (link->stream_alloc_table.stream_count > 0)
 		return;
 
 	dp_disable_link_phy(link, stream->signal);
diff --git a/drivers/gpu/drm/amd/dal/dc/dc_helpers.h b/drivers/gpu/drm/amd/dal/dc/dc_helpers.h
index d96e907..b4c338a 100644
--- a/drivers/gpu/drm/amd/dal/dc/dc_helpers.h
+++ b/drivers/gpu/drm/amd/dal/dc/dc_helpers.h
@@ -44,7 +44,8 @@ enum dc_edid_status dc_helpers_parse_edid_caps(
 bool dc_helpers_dp_mst_write_payload_allocation_table(
 		struct dc_context *ctx,
 		const struct dc_stream *stream,
-		struct dp_mst_stream_allocation_table *table,
+		const struct dp_mst_stream_allocation_table *cur_table,
+		struct dp_mst_stream_allocation_table *proposed_table,
 		bool enable);
 
 /*
diff --git a/drivers/gpu/drm/amd/dal/dc/dce110/dce110_hw_sequencer.c b/drivers/gpu/drm/amd/dal/dc/dce110/dce110_hw_sequencer.c
index 1085137..685301b 100644
--- a/drivers/gpu/drm/amd/dal/dc/dce110/dce110_hw_sequencer.c
+++ b/drivers/gpu/drm/amd/dal/dc/dce110/dce110_hw_sequencer.c
@@ -900,6 +900,8 @@ static enum dc_status apply_single_controller_ctx_to_hw(uint8_t controller_idx,
 
 	if (timing_changed) {
 		core_link_enable_stream(stream->sink->link, stream);
+	} else {
+		core_link_update_stream(stream->sink->link, stream);
 	}
 
 	if (dc_is_dp_signal(stream->signal))
diff --git a/drivers/gpu/drm/amd/dal/dc/inc/core_types.h b/drivers/gpu/drm/amd/dal/dc/inc/core_types.h
index 2b97d4d..5f918c1 100644
--- a/drivers/gpu/drm/amd/dal/dc/inc/core_types.h
+++ b/drivers/gpu/drm/amd/dal/dc/inc/core_types.h
@@ -224,8 +224,7 @@ struct core_link {
 	union dp_wa dp_wa;
 
 	/* MST record stream using this link */
-	const struct core_stream *enabled_streams[MAX_SINKS_PER_LINK];
-	uint8_t enabled_stream_count;
+	struct dp_mst_stream_allocation_table stream_alloc_table;
 };
 
 #define DC_LINK_TO_LINK(dc_link) container_of(dc_link, struct core_link, public)
@@ -248,6 +247,10 @@ void core_link_disable_stream(
 		struct core_link *link,
 		struct core_stream *stream);
 
+void core_link_update_stream(
+		struct core_link *link,
+		struct core_stream *stream);
+
 /********** DAL Core*********************/
 #include "display_clock_interface.h"
 
diff --git a/drivers/gpu/drm/amd/dal/include/link_service_types.h b/drivers/gpu/drm/amd/dal/include/link_service_types.h
index 429d969..573dd5c 100644
--- a/drivers/gpu/drm/amd/dal/include/link_service_types.h
+++ b/drivers/gpu/drm/amd/dal/include/link_service_types.h
@@ -393,6 +393,7 @@ struct mst_device_info {
 struct dp_mst_stream_allocation {
 	/* stream engine id (DIG) */
 	const struct dc_stream *stream;
+	uint32_t vcp_id;
 	/* number of slots required for the DP stream in
 	 * transport packet */
 	uint32_t slot_count;
-- 
2.7.4