aboutsummaryrefslogtreecommitdiffstats
path: root/common/recipes-kernel/linux/files/0571-drm-amd-dal-fix-hotplug-of-HDMI-display-with-DP-MST.patch
blob: 4d17abb40c81c96c64c96e08477f1a6c66f78e42 (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
From 3c7852bb487f519596c4ac96c4a5c40fd2e66984 Mon Sep 17 00:00:00 2001
From: Mykola Lysenko <Mykola.Lysenko@amd.com>
Date: Thu, 3 Dec 2015 19:17:12 +0800
Subject: [PATCH 0571/1110] drm/amd/dal: fix hotplug of HDMI display with DP
 MST

Segfault happens in the following case:
we are about to get set mode for connector who's only
possible crtc (in encoder crtc mask) is already used by
MST connector, that is why DRM will try to
re-assing crtcs in order to make configuration
supported. For our implementation we need to make all
encoders support all crtcs (added function to initilize mask properly),
then this issue will never arise again.

Added sanity check for non NULL connector state. This check
should be needed when used with actual drm_atomic_commit ioctl in future.

Signed-off-by: Harry Wentland <harry.wentland@amd.com>
Acked-by: Harry Wentland <harry.wentland@amd.com>
---
 .../drm/amd/dal/amdgpu_dm/amdgpu_dm_mst_types.c    | 16 +---
 .../gpu/drm/amd/dal/amdgpu_dm/amdgpu_dm_types.c    | 86 ++++++++++++++++------
 .../gpu/drm/amd/dal/amdgpu_dm/amdgpu_dm_types.h    |  2 +
 3 files changed, 65 insertions(+), 39 deletions(-)

diff --git a/drivers/gpu/drm/amd/dal/amdgpu_dm/amdgpu_dm_mst_types.c b/drivers/gpu/drm/amd/dal/amdgpu_dm/amdgpu_dm_mst_types.c
index 86c17e6..9e41114 100644
--- a/drivers/gpu/drm/amd/dal/amdgpu_dm/amdgpu_dm_mst_types.c
+++ b/drivers/gpu/drm/amd/dal/amdgpu_dm/amdgpu_dm_mst_types.c
@@ -228,21 +228,7 @@ dm_dp_create_fake_mst_encoder(struct amdgpu_connector *connector)
 		return NULL;
 
 	encoder = &amdgpu_encoder->base;
-	switch (adev->mode_info.num_crtc) {
-	case 1:
-		encoder->possible_crtcs = 0x1;
-		break;
-	case 2:
-	default:
-		encoder->possible_crtcs = 0x3;
-		break;
-	case 4:
-		encoder->possible_crtcs = 0xf;
-		break;
-	case 6:
-		encoder->possible_crtcs = 0x3f;
-		break;
-	}
+	encoder->possible_crtcs = amdgpu_dm_get_encoder_crtc_mask(adev);
 
 	drm_encoder_init(
 		dev,
diff --git a/drivers/gpu/drm/amd/dal/amdgpu_dm/amdgpu_dm_types.c b/drivers/gpu/drm/amd/dal/amdgpu_dm/amdgpu_dm_types.c
index 3b64ffe..6dc7ead 100644
--- a/drivers/gpu/drm/amd/dal/amdgpu_dm/amdgpu_dm_types.c
+++ b/drivers/gpu/drm/amd/dal/amdgpu_dm/amdgpu_dm_types.c
@@ -1860,19 +1860,40 @@ int amdgpu_dm_connector_init(
 	return 0;
 }
 
+int amdgpu_dm_get_encoder_crtc_mask(struct amdgpu_device *adev)
+{
+	switch (adev->mode_info.num_crtc) {
+	case 1:
+		return 0x1;
+	case 2:
+		return 0x3;
+	case 3:
+		return 0x7;
+	case 4:
+		return 0xf;
+	case 5:
+		return 0x1f;
+	case 6:
+	default:
+		return 0x3f;
+	}
+}
+
 int amdgpu_dm_encoder_init(
 	struct drm_device *dev,
 	struct amdgpu_encoder *aencoder,
 	uint32_t link_index,
 	struct amdgpu_crtc *acrtc)
 {
+	struct amdgpu_device *adev = dev->dev_private;
+
 	int res = drm_encoder_init(dev,
 				   &aencoder->base,
 				   &amdgpu_dm_encoder_funcs,
 				   DRM_MODE_ENCODER_TMDS,
 				   NULL);
 
-	aencoder->base.possible_crtcs = 1 << link_index;
+	aencoder->base.possible_crtcs = amdgpu_dm_get_encoder_crtc_mask(adev);
 
 	if (!res)
 		aencoder->encoder_id = link_index;
@@ -2204,32 +2225,49 @@ int amdgpu_dm_atomic_commit(
 		struct drm_crtc *crtc = plane_state->crtc;
 		struct drm_framebuffer *fb = plane_state->fb;
 		struct drm_connector *connector;
+		struct dm_connector_state *dm_state = NULL;
 
-		if (fb && crtc && crtc->state->planes_changed) {
-			struct dm_connector_state *dm_state = NULL;
-
-			if (page_flip_needed(
-				plane_state,
-				old_plane_state))
-				amdgpu_crtc_page_flip(
-					crtc,
-					fb,
-					crtc->state->event,
-					0);
-			else {
-				list_for_each_entry(connector,
-						&dev->mode_config.connector_list, head)	{
-					if (connector->state->crtc == crtc) {
-						dm_state = to_dm_connector_state(connector->state);
-						break;
-					}
-				}
+		if (!fb || !crtc || !crtc->state->planes_changed)
+			continue;
 
-				dm_dc_surface_commit(
-					dm->dc,
-					crtc,
-					dm_state);
+		if (page_flip_needed(
+			plane_state,
+			old_plane_state))
+			amdgpu_crtc_page_flip(
+				crtc,
+				fb,
+				crtc->state->event,
+				0);
+		else {
+			list_for_each_entry(connector,
+				&dev->mode_config.connector_list, head)	{
+				if (connector->state->crtc == crtc) {
+					dm_state = to_dm_connector_state(connector->state);
+					break;
+				}
 			}
+
+			/*
+			 * This situation happens in the following case:
+			 * we are about to get set mode for connector who's only
+			 * possible crtc (in encoder crtc mask) is used by
+			 * another connector, that is why it will try to
+			 * re-assing crtcs in order to make configuration
+			 * supported. For our implementation we need to make all
+			 * encoders support all crtcs, then this issue will
+			 * never arise again. But to guard code from this issue
+			 * check is left.
+			 *
+			 * Also it should be needed when used with actual
+			 * drm_atomic_commit ioctl in future
+			 */
+			if (!dm_state)
+				continue;
+
+			dm_dc_surface_commit(
+				dm->dc,
+				crtc,
+				dm_state);
 		}
 	}
 
diff --git a/drivers/gpu/drm/amd/dal/amdgpu_dm/amdgpu_dm_types.h b/drivers/gpu/drm/amd/dal/amdgpu_dm/amdgpu_dm_types.h
index 0df4636..0639732 100644
--- a/drivers/gpu/drm/amd/dal/amdgpu_dm/amdgpu_dm_types.h
+++ b/drivers/gpu/drm/amd/dal/amdgpu_dm/amdgpu_dm_types.h
@@ -83,6 +83,8 @@ int amdgpu_dm_connector_atomic_set_property(
 	struct drm_property *property,
 	uint64_t val);
 
+int amdgpu_dm_get_encoder_crtc_mask(struct amdgpu_device *adev);
+
 extern const struct drm_encoder_helper_funcs amdgpu_dm_encoder_helper_funcs;
 
 #endif		/* __AMDGPU_DM_TYPES_H__ */
-- 
2.7.4