]>
Commit | Line | Data |
---|---|---|
79e53945 JB |
1 | /* |
2 | * Copyright © 2006-2007 Intel Corporation | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining a | |
5 | * copy of this software and associated documentation files (the "Software"), | |
6 | * to deal in the Software without restriction, including without limitation | |
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
8 | * and/or sell copies of the Software, and to permit persons to whom the | |
9 | * Software is furnished to do so, subject to the following conditions: | |
10 | * | |
11 | * The above copyright notice and this permission notice (including the next | |
12 | * paragraph) shall be included in all copies or substantial portions of the | |
13 | * Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
21 | * DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | * Authors: | |
24 | * Eric Anholt <eric@anholt.net> | |
25 | */ | |
26 | ||
618563e3 | 27 | #include <linux/dmi.h> |
c1c7af60 JB |
28 | #include <linux/module.h> |
29 | #include <linux/input.h> | |
79e53945 | 30 | #include <linux/i2c.h> |
7662c8bd | 31 | #include <linux/kernel.h> |
5a0e3ad6 | 32 | #include <linux/slab.h> |
9cce37f4 | 33 | #include <linux/vgaarb.h> |
e0dac65e | 34 | #include <drm/drm_edid.h> |
760285e7 | 35 | #include <drm/drmP.h> |
79e53945 | 36 | #include "intel_drv.h" |
760285e7 | 37 | #include <drm/i915_drm.h> |
79e53945 | 38 | #include "i915_drv.h" |
e5510fac | 39 | #include "i915_trace.h" |
319c1d42 | 40 | #include <drm/drm_atomic.h> |
c196e1d6 | 41 | #include <drm/drm_atomic_helper.h> |
760285e7 DH |
42 | #include <drm/drm_dp_helper.h> |
43 | #include <drm/drm_crtc_helper.h> | |
465c120c MR |
44 | #include <drm/drm_plane_helper.h> |
45 | #include <drm/drm_rect.h> | |
c0f372b3 | 46 | #include <linux/dma_remapping.h> |
79e53945 | 47 | |
465c120c | 48 | /* Primary plane formats for gen <= 3 */ |
568db4f2 | 49 | static const uint32_t i8xx_primary_formats[] = { |
67fe7dc5 DL |
50 | DRM_FORMAT_C8, |
51 | DRM_FORMAT_RGB565, | |
465c120c | 52 | DRM_FORMAT_XRGB1555, |
67fe7dc5 | 53 | DRM_FORMAT_XRGB8888, |
465c120c MR |
54 | }; |
55 | ||
56 | /* Primary plane formats for gen >= 4 */ | |
568db4f2 | 57 | static const uint32_t i965_primary_formats[] = { |
6c0fd451 DL |
58 | DRM_FORMAT_C8, |
59 | DRM_FORMAT_RGB565, | |
60 | DRM_FORMAT_XRGB8888, | |
61 | DRM_FORMAT_XBGR8888, | |
62 | DRM_FORMAT_XRGB2101010, | |
63 | DRM_FORMAT_XBGR2101010, | |
64 | }; | |
65 | ||
66 | static const uint32_t skl_primary_formats[] = { | |
67fe7dc5 DL |
67 | DRM_FORMAT_C8, |
68 | DRM_FORMAT_RGB565, | |
69 | DRM_FORMAT_XRGB8888, | |
465c120c | 70 | DRM_FORMAT_XBGR8888, |
67fe7dc5 | 71 | DRM_FORMAT_ARGB8888, |
465c120c MR |
72 | DRM_FORMAT_ABGR8888, |
73 | DRM_FORMAT_XRGB2101010, | |
465c120c | 74 | DRM_FORMAT_XBGR2101010, |
465c120c MR |
75 | }; |
76 | ||
3d7d6510 MR |
77 | /* Cursor formats */ |
78 | static const uint32_t intel_cursor_formats[] = { | |
79 | DRM_FORMAT_ARGB8888, | |
80 | }; | |
81 | ||
6b383a7f | 82 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on); |
79e53945 | 83 | |
f1f644dc | 84 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 85 | struct intel_crtc_state *pipe_config); |
18442d08 | 86 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
5cec258b | 87 | struct intel_crtc_state *pipe_config); |
f1f644dc | 88 | |
568c634a | 89 | static int intel_set_mode(struct drm_atomic_state *state); |
eb1bfe80 JB |
90 | static int intel_framebuffer_init(struct drm_device *dev, |
91 | struct intel_framebuffer *ifb, | |
92 | struct drm_mode_fb_cmd2 *mode_cmd, | |
93 | struct drm_i915_gem_object *obj); | |
5b18e57c DV |
94 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc); |
95 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc); | |
29407aab | 96 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
f769cd24 VK |
97 | struct intel_link_m_n *m_n, |
98 | struct intel_link_m_n *m2_n2); | |
29407aab | 99 | static void ironlake_set_pipeconf(struct drm_crtc *crtc); |
229fca97 DV |
100 | static void haswell_set_pipeconf(struct drm_crtc *crtc); |
101 | static void intel_set_pipe_csc(struct drm_crtc *crtc); | |
d288f65f | 102 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 103 | const struct intel_crtc_state *pipe_config); |
d288f65f | 104 | static void chv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 105 | const struct intel_crtc_state *pipe_config); |
ea2c67bb MR |
106 | static void intel_begin_crtc_commit(struct drm_crtc *crtc); |
107 | static void intel_finish_crtc_commit(struct drm_crtc *crtc); | |
549e2bfb CK |
108 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
109 | struct intel_crtc_state *crtc_state); | |
5ab7b0b7 ID |
110 | static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state, |
111 | int num_connectors); | |
ce22dba9 ML |
112 | static void intel_crtc_enable_planes(struct drm_crtc *crtc); |
113 | static void intel_crtc_disable_planes(struct drm_crtc *crtc); | |
e7457a9a | 114 | |
0e32b39c DA |
115 | static struct intel_encoder *intel_find_encoder(struct intel_connector *connector, int pipe) |
116 | { | |
117 | if (!connector->mst_port) | |
118 | return connector->encoder; | |
119 | else | |
120 | return &connector->mst_port->mst_encoders[pipe]->base; | |
121 | } | |
122 | ||
79e53945 | 123 | typedef struct { |
0206e353 | 124 | int min, max; |
79e53945 JB |
125 | } intel_range_t; |
126 | ||
127 | typedef struct { | |
0206e353 AJ |
128 | int dot_limit; |
129 | int p2_slow, p2_fast; | |
79e53945 JB |
130 | } intel_p2_t; |
131 | ||
d4906093 ML |
132 | typedef struct intel_limit intel_limit_t; |
133 | struct intel_limit { | |
0206e353 AJ |
134 | intel_range_t dot, vco, n, m, m1, m2, p, p1; |
135 | intel_p2_t p2; | |
d4906093 | 136 | }; |
79e53945 | 137 | |
d2acd215 DV |
138 | int |
139 | intel_pch_rawclk(struct drm_device *dev) | |
140 | { | |
141 | struct drm_i915_private *dev_priv = dev->dev_private; | |
142 | ||
143 | WARN_ON(!HAS_PCH_SPLIT(dev)); | |
144 | ||
145 | return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK; | |
146 | } | |
147 | ||
021357ac CW |
148 | static inline u32 /* units of 100MHz */ |
149 | intel_fdi_link_freq(struct drm_device *dev) | |
150 | { | |
8b99e68c CW |
151 | if (IS_GEN5(dev)) { |
152 | struct drm_i915_private *dev_priv = dev->dev_private; | |
153 | return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2; | |
154 | } else | |
155 | return 27; | |
021357ac CW |
156 | } |
157 | ||
5d536e28 | 158 | static const intel_limit_t intel_limits_i8xx_dac = { |
0206e353 | 159 | .dot = { .min = 25000, .max = 350000 }, |
9c333719 | 160 | .vco = { .min = 908000, .max = 1512000 }, |
91dbe5fb | 161 | .n = { .min = 2, .max = 16 }, |
0206e353 AJ |
162 | .m = { .min = 96, .max = 140 }, |
163 | .m1 = { .min = 18, .max = 26 }, | |
164 | .m2 = { .min = 6, .max = 16 }, | |
165 | .p = { .min = 4, .max = 128 }, | |
166 | .p1 = { .min = 2, .max = 33 }, | |
273e27ca EA |
167 | .p2 = { .dot_limit = 165000, |
168 | .p2_slow = 4, .p2_fast = 2 }, | |
e4b36699 KP |
169 | }; |
170 | ||
5d536e28 DV |
171 | static const intel_limit_t intel_limits_i8xx_dvo = { |
172 | .dot = { .min = 25000, .max = 350000 }, | |
9c333719 | 173 | .vco = { .min = 908000, .max = 1512000 }, |
91dbe5fb | 174 | .n = { .min = 2, .max = 16 }, |
5d536e28 DV |
175 | .m = { .min = 96, .max = 140 }, |
176 | .m1 = { .min = 18, .max = 26 }, | |
177 | .m2 = { .min = 6, .max = 16 }, | |
178 | .p = { .min = 4, .max = 128 }, | |
179 | .p1 = { .min = 2, .max = 33 }, | |
180 | .p2 = { .dot_limit = 165000, | |
181 | .p2_slow = 4, .p2_fast = 4 }, | |
182 | }; | |
183 | ||
e4b36699 | 184 | static const intel_limit_t intel_limits_i8xx_lvds = { |
0206e353 | 185 | .dot = { .min = 25000, .max = 350000 }, |
9c333719 | 186 | .vco = { .min = 908000, .max = 1512000 }, |
91dbe5fb | 187 | .n = { .min = 2, .max = 16 }, |
0206e353 AJ |
188 | .m = { .min = 96, .max = 140 }, |
189 | .m1 = { .min = 18, .max = 26 }, | |
190 | .m2 = { .min = 6, .max = 16 }, | |
191 | .p = { .min = 4, .max = 128 }, | |
192 | .p1 = { .min = 1, .max = 6 }, | |
273e27ca EA |
193 | .p2 = { .dot_limit = 165000, |
194 | .p2_slow = 14, .p2_fast = 7 }, | |
e4b36699 | 195 | }; |
273e27ca | 196 | |
e4b36699 | 197 | static const intel_limit_t intel_limits_i9xx_sdvo = { |
0206e353 AJ |
198 | .dot = { .min = 20000, .max = 400000 }, |
199 | .vco = { .min = 1400000, .max = 2800000 }, | |
200 | .n = { .min = 1, .max = 6 }, | |
201 | .m = { .min = 70, .max = 120 }, | |
4f7dfb67 PJ |
202 | .m1 = { .min = 8, .max = 18 }, |
203 | .m2 = { .min = 3, .max = 7 }, | |
0206e353 AJ |
204 | .p = { .min = 5, .max = 80 }, |
205 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
206 | .p2 = { .dot_limit = 200000, |
207 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
208 | }; |
209 | ||
210 | static const intel_limit_t intel_limits_i9xx_lvds = { | |
0206e353 AJ |
211 | .dot = { .min = 20000, .max = 400000 }, |
212 | .vco = { .min = 1400000, .max = 2800000 }, | |
213 | .n = { .min = 1, .max = 6 }, | |
214 | .m = { .min = 70, .max = 120 }, | |
53a7d2d1 PJ |
215 | .m1 = { .min = 8, .max = 18 }, |
216 | .m2 = { .min = 3, .max = 7 }, | |
0206e353 AJ |
217 | .p = { .min = 7, .max = 98 }, |
218 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
219 | .p2 = { .dot_limit = 112000, |
220 | .p2_slow = 14, .p2_fast = 7 }, | |
e4b36699 KP |
221 | }; |
222 | ||
273e27ca | 223 | |
e4b36699 | 224 | static const intel_limit_t intel_limits_g4x_sdvo = { |
273e27ca EA |
225 | .dot = { .min = 25000, .max = 270000 }, |
226 | .vco = { .min = 1750000, .max = 3500000}, | |
227 | .n = { .min = 1, .max = 4 }, | |
228 | .m = { .min = 104, .max = 138 }, | |
229 | .m1 = { .min = 17, .max = 23 }, | |
230 | .m2 = { .min = 5, .max = 11 }, | |
231 | .p = { .min = 10, .max = 30 }, | |
232 | .p1 = { .min = 1, .max = 3}, | |
233 | .p2 = { .dot_limit = 270000, | |
234 | .p2_slow = 10, | |
235 | .p2_fast = 10 | |
044c7c41 | 236 | }, |
e4b36699 KP |
237 | }; |
238 | ||
239 | static const intel_limit_t intel_limits_g4x_hdmi = { | |
273e27ca EA |
240 | .dot = { .min = 22000, .max = 400000 }, |
241 | .vco = { .min = 1750000, .max = 3500000}, | |
242 | .n = { .min = 1, .max = 4 }, | |
243 | .m = { .min = 104, .max = 138 }, | |
244 | .m1 = { .min = 16, .max = 23 }, | |
245 | .m2 = { .min = 5, .max = 11 }, | |
246 | .p = { .min = 5, .max = 80 }, | |
247 | .p1 = { .min = 1, .max = 8}, | |
248 | .p2 = { .dot_limit = 165000, | |
249 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
250 | }; |
251 | ||
252 | static const intel_limit_t intel_limits_g4x_single_channel_lvds = { | |
273e27ca EA |
253 | .dot = { .min = 20000, .max = 115000 }, |
254 | .vco = { .min = 1750000, .max = 3500000 }, | |
255 | .n = { .min = 1, .max = 3 }, | |
256 | .m = { .min = 104, .max = 138 }, | |
257 | .m1 = { .min = 17, .max = 23 }, | |
258 | .m2 = { .min = 5, .max = 11 }, | |
259 | .p = { .min = 28, .max = 112 }, | |
260 | .p1 = { .min = 2, .max = 8 }, | |
261 | .p2 = { .dot_limit = 0, | |
262 | .p2_slow = 14, .p2_fast = 14 | |
044c7c41 | 263 | }, |
e4b36699 KP |
264 | }; |
265 | ||
266 | static const intel_limit_t intel_limits_g4x_dual_channel_lvds = { | |
273e27ca EA |
267 | .dot = { .min = 80000, .max = 224000 }, |
268 | .vco = { .min = 1750000, .max = 3500000 }, | |
269 | .n = { .min = 1, .max = 3 }, | |
270 | .m = { .min = 104, .max = 138 }, | |
271 | .m1 = { .min = 17, .max = 23 }, | |
272 | .m2 = { .min = 5, .max = 11 }, | |
273 | .p = { .min = 14, .max = 42 }, | |
274 | .p1 = { .min = 2, .max = 6 }, | |
275 | .p2 = { .dot_limit = 0, | |
276 | .p2_slow = 7, .p2_fast = 7 | |
044c7c41 | 277 | }, |
e4b36699 KP |
278 | }; |
279 | ||
f2b115e6 | 280 | static const intel_limit_t intel_limits_pineview_sdvo = { |
0206e353 AJ |
281 | .dot = { .min = 20000, .max = 400000}, |
282 | .vco = { .min = 1700000, .max = 3500000 }, | |
273e27ca | 283 | /* Pineview's Ncounter is a ring counter */ |
0206e353 AJ |
284 | .n = { .min = 3, .max = 6 }, |
285 | .m = { .min = 2, .max = 256 }, | |
273e27ca | 286 | /* Pineview only has one combined m divider, which we treat as m2. */ |
0206e353 AJ |
287 | .m1 = { .min = 0, .max = 0 }, |
288 | .m2 = { .min = 0, .max = 254 }, | |
289 | .p = { .min = 5, .max = 80 }, | |
290 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
291 | .p2 = { .dot_limit = 200000, |
292 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
293 | }; |
294 | ||
f2b115e6 | 295 | static const intel_limit_t intel_limits_pineview_lvds = { |
0206e353 AJ |
296 | .dot = { .min = 20000, .max = 400000 }, |
297 | .vco = { .min = 1700000, .max = 3500000 }, | |
298 | .n = { .min = 3, .max = 6 }, | |
299 | .m = { .min = 2, .max = 256 }, | |
300 | .m1 = { .min = 0, .max = 0 }, | |
301 | .m2 = { .min = 0, .max = 254 }, | |
302 | .p = { .min = 7, .max = 112 }, | |
303 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
304 | .p2 = { .dot_limit = 112000, |
305 | .p2_slow = 14, .p2_fast = 14 }, | |
e4b36699 KP |
306 | }; |
307 | ||
273e27ca EA |
308 | /* Ironlake / Sandybridge |
309 | * | |
310 | * We calculate clock using (register_value + 2) for N/M1/M2, so here | |
311 | * the range value for them is (actual_value - 2). | |
312 | */ | |
b91ad0ec | 313 | static const intel_limit_t intel_limits_ironlake_dac = { |
273e27ca EA |
314 | .dot = { .min = 25000, .max = 350000 }, |
315 | .vco = { .min = 1760000, .max = 3510000 }, | |
316 | .n = { .min = 1, .max = 5 }, | |
317 | .m = { .min = 79, .max = 127 }, | |
318 | .m1 = { .min = 12, .max = 22 }, | |
319 | .m2 = { .min = 5, .max = 9 }, | |
320 | .p = { .min = 5, .max = 80 }, | |
321 | .p1 = { .min = 1, .max = 8 }, | |
322 | .p2 = { .dot_limit = 225000, | |
323 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
324 | }; |
325 | ||
b91ad0ec | 326 | static const intel_limit_t intel_limits_ironlake_single_lvds = { |
273e27ca EA |
327 | .dot = { .min = 25000, .max = 350000 }, |
328 | .vco = { .min = 1760000, .max = 3510000 }, | |
329 | .n = { .min = 1, .max = 3 }, | |
330 | .m = { .min = 79, .max = 118 }, | |
331 | .m1 = { .min = 12, .max = 22 }, | |
332 | .m2 = { .min = 5, .max = 9 }, | |
333 | .p = { .min = 28, .max = 112 }, | |
334 | .p1 = { .min = 2, .max = 8 }, | |
335 | .p2 = { .dot_limit = 225000, | |
336 | .p2_slow = 14, .p2_fast = 14 }, | |
b91ad0ec ZW |
337 | }; |
338 | ||
339 | static const intel_limit_t intel_limits_ironlake_dual_lvds = { | |
273e27ca EA |
340 | .dot = { .min = 25000, .max = 350000 }, |
341 | .vco = { .min = 1760000, .max = 3510000 }, | |
342 | .n = { .min = 1, .max = 3 }, | |
343 | .m = { .min = 79, .max = 127 }, | |
344 | .m1 = { .min = 12, .max = 22 }, | |
345 | .m2 = { .min = 5, .max = 9 }, | |
346 | .p = { .min = 14, .max = 56 }, | |
347 | .p1 = { .min = 2, .max = 8 }, | |
348 | .p2 = { .dot_limit = 225000, | |
349 | .p2_slow = 7, .p2_fast = 7 }, | |
b91ad0ec ZW |
350 | }; |
351 | ||
273e27ca | 352 | /* LVDS 100mhz refclk limits. */ |
b91ad0ec | 353 | static const intel_limit_t intel_limits_ironlake_single_lvds_100m = { |
273e27ca EA |
354 | .dot = { .min = 25000, .max = 350000 }, |
355 | .vco = { .min = 1760000, .max = 3510000 }, | |
356 | .n = { .min = 1, .max = 2 }, | |
357 | .m = { .min = 79, .max = 126 }, | |
358 | .m1 = { .min = 12, .max = 22 }, | |
359 | .m2 = { .min = 5, .max = 9 }, | |
360 | .p = { .min = 28, .max = 112 }, | |
0206e353 | 361 | .p1 = { .min = 2, .max = 8 }, |
273e27ca EA |
362 | .p2 = { .dot_limit = 225000, |
363 | .p2_slow = 14, .p2_fast = 14 }, | |
b91ad0ec ZW |
364 | }; |
365 | ||
366 | static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = { | |
273e27ca EA |
367 | .dot = { .min = 25000, .max = 350000 }, |
368 | .vco = { .min = 1760000, .max = 3510000 }, | |
369 | .n = { .min = 1, .max = 3 }, | |
370 | .m = { .min = 79, .max = 126 }, | |
371 | .m1 = { .min = 12, .max = 22 }, | |
372 | .m2 = { .min = 5, .max = 9 }, | |
373 | .p = { .min = 14, .max = 42 }, | |
0206e353 | 374 | .p1 = { .min = 2, .max = 6 }, |
273e27ca EA |
375 | .p2 = { .dot_limit = 225000, |
376 | .p2_slow = 7, .p2_fast = 7 }, | |
4547668a ZY |
377 | }; |
378 | ||
dc730512 | 379 | static const intel_limit_t intel_limits_vlv = { |
f01b7962 VS |
380 | /* |
381 | * These are the data rate limits (measured in fast clocks) | |
382 | * since those are the strictest limits we have. The fast | |
383 | * clock and actual rate limits are more relaxed, so checking | |
384 | * them would make no difference. | |
385 | */ | |
386 | .dot = { .min = 25000 * 5, .max = 270000 * 5 }, | |
75e53986 | 387 | .vco = { .min = 4000000, .max = 6000000 }, |
a0c4da24 | 388 | .n = { .min = 1, .max = 7 }, |
a0c4da24 JB |
389 | .m1 = { .min = 2, .max = 3 }, |
390 | .m2 = { .min = 11, .max = 156 }, | |
b99ab663 | 391 | .p1 = { .min = 2, .max = 3 }, |
5fdc9c49 | 392 | .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */ |
a0c4da24 JB |
393 | }; |
394 | ||
ef9348c8 CML |
395 | static const intel_limit_t intel_limits_chv = { |
396 | /* | |
397 | * These are the data rate limits (measured in fast clocks) | |
398 | * since those are the strictest limits we have. The fast | |
399 | * clock and actual rate limits are more relaxed, so checking | |
400 | * them would make no difference. | |
401 | */ | |
402 | .dot = { .min = 25000 * 5, .max = 540000 * 5}, | |
17fe1021 | 403 | .vco = { .min = 4800000, .max = 6480000 }, |
ef9348c8 CML |
404 | .n = { .min = 1, .max = 1 }, |
405 | .m1 = { .min = 2, .max = 2 }, | |
406 | .m2 = { .min = 24 << 22, .max = 175 << 22 }, | |
407 | .p1 = { .min = 2, .max = 4 }, | |
408 | .p2 = { .p2_slow = 1, .p2_fast = 14 }, | |
409 | }; | |
410 | ||
5ab7b0b7 ID |
411 | static const intel_limit_t intel_limits_bxt = { |
412 | /* FIXME: find real dot limits */ | |
413 | .dot = { .min = 0, .max = INT_MAX }, | |
414 | .vco = { .min = 4800000, .max = 6480000 }, | |
415 | .n = { .min = 1, .max = 1 }, | |
416 | .m1 = { .min = 2, .max = 2 }, | |
417 | /* FIXME: find real m2 limits */ | |
418 | .m2 = { .min = 2 << 22, .max = 255 << 22 }, | |
419 | .p1 = { .min = 2, .max = 4 }, | |
420 | .p2 = { .p2_slow = 1, .p2_fast = 20 }, | |
421 | }; | |
422 | ||
6b4bf1c4 VS |
423 | static void vlv_clock(int refclk, intel_clock_t *clock) |
424 | { | |
425 | clock->m = clock->m1 * clock->m2; | |
426 | clock->p = clock->p1 * clock->p2; | |
ed5ca77e VS |
427 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
428 | return; | |
fb03ac01 VS |
429 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
430 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
6b4bf1c4 VS |
431 | } |
432 | ||
cdba954e ACO |
433 | static bool |
434 | needs_modeset(struct drm_crtc_state *state) | |
435 | { | |
436 | return state->mode_changed || state->active_changed; | |
437 | } | |
438 | ||
e0638cdf PZ |
439 | /** |
440 | * Returns whether any output on the specified pipe is of the specified type | |
441 | */ | |
4093561b | 442 | bool intel_pipe_has_type(struct intel_crtc *crtc, enum intel_output_type type) |
e0638cdf | 443 | { |
409ee761 | 444 | struct drm_device *dev = crtc->base.dev; |
e0638cdf PZ |
445 | struct intel_encoder *encoder; |
446 | ||
409ee761 | 447 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
e0638cdf PZ |
448 | if (encoder->type == type) |
449 | return true; | |
450 | ||
451 | return false; | |
452 | } | |
453 | ||
d0737e1d ACO |
454 | /** |
455 | * Returns whether any output on the specified pipe will have the specified | |
456 | * type after a staged modeset is complete, i.e., the same as | |
457 | * intel_pipe_has_type() but looking at encoder->new_crtc instead of | |
458 | * encoder->crtc. | |
459 | */ | |
a93e255f ACO |
460 | static bool intel_pipe_will_have_type(const struct intel_crtc_state *crtc_state, |
461 | int type) | |
d0737e1d | 462 | { |
a93e255f | 463 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 464 | struct drm_connector *connector; |
a93e255f | 465 | struct drm_connector_state *connector_state; |
d0737e1d | 466 | struct intel_encoder *encoder; |
a93e255f ACO |
467 | int i, num_connectors = 0; |
468 | ||
da3ced29 | 469 | for_each_connector_in_state(state, connector, connector_state, i) { |
a93e255f ACO |
470 | if (connector_state->crtc != crtc_state->base.crtc) |
471 | continue; | |
472 | ||
473 | num_connectors++; | |
d0737e1d | 474 | |
a93e255f ACO |
475 | encoder = to_intel_encoder(connector_state->best_encoder); |
476 | if (encoder->type == type) | |
d0737e1d | 477 | return true; |
a93e255f ACO |
478 | } |
479 | ||
480 | WARN_ON(num_connectors == 0); | |
d0737e1d ACO |
481 | |
482 | return false; | |
483 | } | |
484 | ||
a93e255f ACO |
485 | static const intel_limit_t * |
486 | intel_ironlake_limit(struct intel_crtc_state *crtc_state, int refclk) | |
2c07245f | 487 | { |
a93e255f | 488 | struct drm_device *dev = crtc_state->base.crtc->dev; |
2c07245f | 489 | const intel_limit_t *limit; |
b91ad0ec | 490 | |
a93e255f | 491 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
1974cad0 | 492 | if (intel_is_dual_link_lvds(dev)) { |
1b894b59 | 493 | if (refclk == 100000) |
b91ad0ec ZW |
494 | limit = &intel_limits_ironlake_dual_lvds_100m; |
495 | else | |
496 | limit = &intel_limits_ironlake_dual_lvds; | |
497 | } else { | |
1b894b59 | 498 | if (refclk == 100000) |
b91ad0ec ZW |
499 | limit = &intel_limits_ironlake_single_lvds_100m; |
500 | else | |
501 | limit = &intel_limits_ironlake_single_lvds; | |
502 | } | |
c6bb3538 | 503 | } else |
b91ad0ec | 504 | limit = &intel_limits_ironlake_dac; |
2c07245f ZW |
505 | |
506 | return limit; | |
507 | } | |
508 | ||
a93e255f ACO |
509 | static const intel_limit_t * |
510 | intel_g4x_limit(struct intel_crtc_state *crtc_state) | |
044c7c41 | 511 | { |
a93e255f | 512 | struct drm_device *dev = crtc_state->base.crtc->dev; |
044c7c41 ML |
513 | const intel_limit_t *limit; |
514 | ||
a93e255f | 515 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
1974cad0 | 516 | if (intel_is_dual_link_lvds(dev)) |
e4b36699 | 517 | limit = &intel_limits_g4x_dual_channel_lvds; |
044c7c41 | 518 | else |
e4b36699 | 519 | limit = &intel_limits_g4x_single_channel_lvds; |
a93e255f ACO |
520 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI) || |
521 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_ANALOG)) { | |
e4b36699 | 522 | limit = &intel_limits_g4x_hdmi; |
a93e255f | 523 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO)) { |
e4b36699 | 524 | limit = &intel_limits_g4x_sdvo; |
044c7c41 | 525 | } else /* The option is for other outputs */ |
e4b36699 | 526 | limit = &intel_limits_i9xx_sdvo; |
044c7c41 ML |
527 | |
528 | return limit; | |
529 | } | |
530 | ||
a93e255f ACO |
531 | static const intel_limit_t * |
532 | intel_limit(struct intel_crtc_state *crtc_state, int refclk) | |
79e53945 | 533 | { |
a93e255f | 534 | struct drm_device *dev = crtc_state->base.crtc->dev; |
79e53945 JB |
535 | const intel_limit_t *limit; |
536 | ||
5ab7b0b7 ID |
537 | if (IS_BROXTON(dev)) |
538 | limit = &intel_limits_bxt; | |
539 | else if (HAS_PCH_SPLIT(dev)) | |
a93e255f | 540 | limit = intel_ironlake_limit(crtc_state, refclk); |
2c07245f | 541 | else if (IS_G4X(dev)) { |
a93e255f | 542 | limit = intel_g4x_limit(crtc_state); |
f2b115e6 | 543 | } else if (IS_PINEVIEW(dev)) { |
a93e255f | 544 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
f2b115e6 | 545 | limit = &intel_limits_pineview_lvds; |
2177832f | 546 | else |
f2b115e6 | 547 | limit = &intel_limits_pineview_sdvo; |
ef9348c8 CML |
548 | } else if (IS_CHERRYVIEW(dev)) { |
549 | limit = &intel_limits_chv; | |
a0c4da24 | 550 | } else if (IS_VALLEYVIEW(dev)) { |
dc730512 | 551 | limit = &intel_limits_vlv; |
a6c45cf0 | 552 | } else if (!IS_GEN2(dev)) { |
a93e255f | 553 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
a6c45cf0 CW |
554 | limit = &intel_limits_i9xx_lvds; |
555 | else | |
556 | limit = &intel_limits_i9xx_sdvo; | |
79e53945 | 557 | } else { |
a93e255f | 558 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
e4b36699 | 559 | limit = &intel_limits_i8xx_lvds; |
a93e255f | 560 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) |
e4b36699 | 561 | limit = &intel_limits_i8xx_dvo; |
5d536e28 DV |
562 | else |
563 | limit = &intel_limits_i8xx_dac; | |
79e53945 JB |
564 | } |
565 | return limit; | |
566 | } | |
567 | ||
f2b115e6 AJ |
568 | /* m1 is reserved as 0 in Pineview, n is a ring counter */ |
569 | static void pineview_clock(int refclk, intel_clock_t *clock) | |
79e53945 | 570 | { |
2177832f SL |
571 | clock->m = clock->m2 + 2; |
572 | clock->p = clock->p1 * clock->p2; | |
ed5ca77e VS |
573 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
574 | return; | |
fb03ac01 VS |
575 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
576 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
2177832f SL |
577 | } |
578 | ||
7429e9d4 DV |
579 | static uint32_t i9xx_dpll_compute_m(struct dpll *dpll) |
580 | { | |
581 | return 5 * (dpll->m1 + 2) + (dpll->m2 + 2); | |
582 | } | |
583 | ||
ac58c3f0 | 584 | static void i9xx_clock(int refclk, intel_clock_t *clock) |
2177832f | 585 | { |
7429e9d4 | 586 | clock->m = i9xx_dpll_compute_m(clock); |
79e53945 | 587 | clock->p = clock->p1 * clock->p2; |
ed5ca77e VS |
588 | if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) |
589 | return; | |
fb03ac01 VS |
590 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2); |
591 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
79e53945 JB |
592 | } |
593 | ||
ef9348c8 CML |
594 | static void chv_clock(int refclk, intel_clock_t *clock) |
595 | { | |
596 | clock->m = clock->m1 * clock->m2; | |
597 | clock->p = clock->p1 * clock->p2; | |
598 | if (WARN_ON(clock->n == 0 || clock->p == 0)) | |
599 | return; | |
600 | clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m, | |
601 | clock->n << 22); | |
602 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
603 | } | |
604 | ||
7c04d1d9 | 605 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
79e53945 JB |
606 | /** |
607 | * Returns whether the given set of divisors are valid for a given refclk with | |
608 | * the given connectors. | |
609 | */ | |
610 | ||
1b894b59 CW |
611 | static bool intel_PLL_is_valid(struct drm_device *dev, |
612 | const intel_limit_t *limit, | |
613 | const intel_clock_t *clock) | |
79e53945 | 614 | { |
f01b7962 VS |
615 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
616 | INTELPllInvalid("n out of range\n"); | |
79e53945 | 617 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
0206e353 | 618 | INTELPllInvalid("p1 out of range\n"); |
79e53945 | 619 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
0206e353 | 620 | INTELPllInvalid("m2 out of range\n"); |
79e53945 | 621 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
0206e353 | 622 | INTELPllInvalid("m1 out of range\n"); |
f01b7962 | 623 | |
5ab7b0b7 | 624 | if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev) && !IS_BROXTON(dev)) |
f01b7962 VS |
625 | if (clock->m1 <= clock->m2) |
626 | INTELPllInvalid("m1 <= m2\n"); | |
627 | ||
5ab7b0b7 | 628 | if (!IS_VALLEYVIEW(dev) && !IS_BROXTON(dev)) { |
f01b7962 VS |
629 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
630 | INTELPllInvalid("p out of range\n"); | |
631 | if (clock->m < limit->m.min || limit->m.max < clock->m) | |
632 | INTELPllInvalid("m out of range\n"); | |
633 | } | |
634 | ||
79e53945 | 635 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
0206e353 | 636 | INTELPllInvalid("vco out of range\n"); |
79e53945 JB |
637 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
638 | * connector, etc., rather than just a single range. | |
639 | */ | |
640 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) | |
0206e353 | 641 | INTELPllInvalid("dot out of range\n"); |
79e53945 JB |
642 | |
643 | return true; | |
644 | } | |
645 | ||
d4906093 | 646 | static bool |
a93e255f ACO |
647 | i9xx_find_best_dpll(const intel_limit_t *limit, |
648 | struct intel_crtc_state *crtc_state, | |
cec2f356 SP |
649 | int target, int refclk, intel_clock_t *match_clock, |
650 | intel_clock_t *best_clock) | |
79e53945 | 651 | { |
a93e255f | 652 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
a919ff14 | 653 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 654 | intel_clock_t clock; |
79e53945 JB |
655 | int err = target; |
656 | ||
a93e255f | 657 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
79e53945 | 658 | /* |
a210b028 DV |
659 | * For LVDS just rely on its current settings for dual-channel. |
660 | * We haven't figured out how to reliably set up different | |
661 | * single/dual channel state, if we even can. | |
79e53945 | 662 | */ |
1974cad0 | 663 | if (intel_is_dual_link_lvds(dev)) |
79e53945 JB |
664 | clock.p2 = limit->p2.p2_fast; |
665 | else | |
666 | clock.p2 = limit->p2.p2_slow; | |
667 | } else { | |
668 | if (target < limit->p2.dot_limit) | |
669 | clock.p2 = limit->p2.p2_slow; | |
670 | else | |
671 | clock.p2 = limit->p2.p2_fast; | |
672 | } | |
673 | ||
0206e353 | 674 | memset(best_clock, 0, sizeof(*best_clock)); |
79e53945 | 675 | |
42158660 ZY |
676 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
677 | clock.m1++) { | |
678 | for (clock.m2 = limit->m2.min; | |
679 | clock.m2 <= limit->m2.max; clock.m2++) { | |
c0efc387 | 680 | if (clock.m2 >= clock.m1) |
42158660 ZY |
681 | break; |
682 | for (clock.n = limit->n.min; | |
683 | clock.n <= limit->n.max; clock.n++) { | |
684 | for (clock.p1 = limit->p1.min; | |
685 | clock.p1 <= limit->p1.max; clock.p1++) { | |
79e53945 JB |
686 | int this_err; |
687 | ||
ac58c3f0 DV |
688 | i9xx_clock(refclk, &clock); |
689 | if (!intel_PLL_is_valid(dev, limit, | |
690 | &clock)) | |
691 | continue; | |
692 | if (match_clock && | |
693 | clock.p != match_clock->p) | |
694 | continue; | |
695 | ||
696 | this_err = abs(clock.dot - target); | |
697 | if (this_err < err) { | |
698 | *best_clock = clock; | |
699 | err = this_err; | |
700 | } | |
701 | } | |
702 | } | |
703 | } | |
704 | } | |
705 | ||
706 | return (err != target); | |
707 | } | |
708 | ||
709 | static bool | |
a93e255f ACO |
710 | pnv_find_best_dpll(const intel_limit_t *limit, |
711 | struct intel_crtc_state *crtc_state, | |
ee9300bb DV |
712 | int target, int refclk, intel_clock_t *match_clock, |
713 | intel_clock_t *best_clock) | |
79e53945 | 714 | { |
a93e255f | 715 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
a919ff14 | 716 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 717 | intel_clock_t clock; |
79e53945 JB |
718 | int err = target; |
719 | ||
a93e255f | 720 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
79e53945 | 721 | /* |
a210b028 DV |
722 | * For LVDS just rely on its current settings for dual-channel. |
723 | * We haven't figured out how to reliably set up different | |
724 | * single/dual channel state, if we even can. | |
79e53945 | 725 | */ |
1974cad0 | 726 | if (intel_is_dual_link_lvds(dev)) |
79e53945 JB |
727 | clock.p2 = limit->p2.p2_fast; |
728 | else | |
729 | clock.p2 = limit->p2.p2_slow; | |
730 | } else { | |
731 | if (target < limit->p2.dot_limit) | |
732 | clock.p2 = limit->p2.p2_slow; | |
733 | else | |
734 | clock.p2 = limit->p2.p2_fast; | |
735 | } | |
736 | ||
0206e353 | 737 | memset(best_clock, 0, sizeof(*best_clock)); |
79e53945 | 738 | |
42158660 ZY |
739 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
740 | clock.m1++) { | |
741 | for (clock.m2 = limit->m2.min; | |
742 | clock.m2 <= limit->m2.max; clock.m2++) { | |
42158660 ZY |
743 | for (clock.n = limit->n.min; |
744 | clock.n <= limit->n.max; clock.n++) { | |
745 | for (clock.p1 = limit->p1.min; | |
746 | clock.p1 <= limit->p1.max; clock.p1++) { | |
79e53945 JB |
747 | int this_err; |
748 | ||
ac58c3f0 | 749 | pineview_clock(refclk, &clock); |
1b894b59 CW |
750 | if (!intel_PLL_is_valid(dev, limit, |
751 | &clock)) | |
79e53945 | 752 | continue; |
cec2f356 SP |
753 | if (match_clock && |
754 | clock.p != match_clock->p) | |
755 | continue; | |
79e53945 JB |
756 | |
757 | this_err = abs(clock.dot - target); | |
758 | if (this_err < err) { | |
759 | *best_clock = clock; | |
760 | err = this_err; | |
761 | } | |
762 | } | |
763 | } | |
764 | } | |
765 | } | |
766 | ||
767 | return (err != target); | |
768 | } | |
769 | ||
d4906093 | 770 | static bool |
a93e255f ACO |
771 | g4x_find_best_dpll(const intel_limit_t *limit, |
772 | struct intel_crtc_state *crtc_state, | |
ee9300bb DV |
773 | int target, int refclk, intel_clock_t *match_clock, |
774 | intel_clock_t *best_clock) | |
d4906093 | 775 | { |
a93e255f | 776 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
a919ff14 | 777 | struct drm_device *dev = crtc->base.dev; |
d4906093 ML |
778 | intel_clock_t clock; |
779 | int max_n; | |
780 | bool found; | |
6ba770dc AJ |
781 | /* approximately equals target * 0.00585 */ |
782 | int err_most = (target >> 8) + (target >> 9); | |
d4906093 ML |
783 | found = false; |
784 | ||
a93e255f | 785 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
1974cad0 | 786 | if (intel_is_dual_link_lvds(dev)) |
d4906093 ML |
787 | clock.p2 = limit->p2.p2_fast; |
788 | else | |
789 | clock.p2 = limit->p2.p2_slow; | |
790 | } else { | |
791 | if (target < limit->p2.dot_limit) | |
792 | clock.p2 = limit->p2.p2_slow; | |
793 | else | |
794 | clock.p2 = limit->p2.p2_fast; | |
795 | } | |
796 | ||
797 | memset(best_clock, 0, sizeof(*best_clock)); | |
798 | max_n = limit->n.max; | |
f77f13e2 | 799 | /* based on hardware requirement, prefer smaller n to precision */ |
d4906093 | 800 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
f77f13e2 | 801 | /* based on hardware requirement, prefere larger m1,m2 */ |
d4906093 ML |
802 | for (clock.m1 = limit->m1.max; |
803 | clock.m1 >= limit->m1.min; clock.m1--) { | |
804 | for (clock.m2 = limit->m2.max; | |
805 | clock.m2 >= limit->m2.min; clock.m2--) { | |
806 | for (clock.p1 = limit->p1.max; | |
807 | clock.p1 >= limit->p1.min; clock.p1--) { | |
808 | int this_err; | |
809 | ||
ac58c3f0 | 810 | i9xx_clock(refclk, &clock); |
1b894b59 CW |
811 | if (!intel_PLL_is_valid(dev, limit, |
812 | &clock)) | |
d4906093 | 813 | continue; |
1b894b59 CW |
814 | |
815 | this_err = abs(clock.dot - target); | |
d4906093 ML |
816 | if (this_err < err_most) { |
817 | *best_clock = clock; | |
818 | err_most = this_err; | |
819 | max_n = clock.n; | |
820 | found = true; | |
821 | } | |
822 | } | |
823 | } | |
824 | } | |
825 | } | |
2c07245f ZW |
826 | return found; |
827 | } | |
828 | ||
d5dd62bd ID |
829 | /* |
830 | * Check if the calculated PLL configuration is more optimal compared to the | |
831 | * best configuration and error found so far. Return the calculated error. | |
832 | */ | |
833 | static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq, | |
834 | const intel_clock_t *calculated_clock, | |
835 | const intel_clock_t *best_clock, | |
836 | unsigned int best_error_ppm, | |
837 | unsigned int *error_ppm) | |
838 | { | |
9ca3ba01 ID |
839 | /* |
840 | * For CHV ignore the error and consider only the P value. | |
841 | * Prefer a bigger P value based on HW requirements. | |
842 | */ | |
843 | if (IS_CHERRYVIEW(dev)) { | |
844 | *error_ppm = 0; | |
845 | ||
846 | return calculated_clock->p > best_clock->p; | |
847 | } | |
848 | ||
24be4e46 ID |
849 | if (WARN_ON_ONCE(!target_freq)) |
850 | return false; | |
851 | ||
d5dd62bd ID |
852 | *error_ppm = div_u64(1000000ULL * |
853 | abs(target_freq - calculated_clock->dot), | |
854 | target_freq); | |
855 | /* | |
856 | * Prefer a better P value over a better (smaller) error if the error | |
857 | * is small. Ensure this preference for future configurations too by | |
858 | * setting the error to 0. | |
859 | */ | |
860 | if (*error_ppm < 100 && calculated_clock->p > best_clock->p) { | |
861 | *error_ppm = 0; | |
862 | ||
863 | return true; | |
864 | } | |
865 | ||
866 | return *error_ppm + 10 < best_error_ppm; | |
867 | } | |
868 | ||
a0c4da24 | 869 | static bool |
a93e255f ACO |
870 | vlv_find_best_dpll(const intel_limit_t *limit, |
871 | struct intel_crtc_state *crtc_state, | |
ee9300bb DV |
872 | int target, int refclk, intel_clock_t *match_clock, |
873 | intel_clock_t *best_clock) | |
a0c4da24 | 874 | { |
a93e255f | 875 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
a919ff14 | 876 | struct drm_device *dev = crtc->base.dev; |
6b4bf1c4 | 877 | intel_clock_t clock; |
69e4f900 | 878 | unsigned int bestppm = 1000000; |
27e639bf VS |
879 | /* min update 19.2 MHz */ |
880 | int max_n = min(limit->n.max, refclk / 19200); | |
49e497ef | 881 | bool found = false; |
a0c4da24 | 882 | |
6b4bf1c4 VS |
883 | target *= 5; /* fast clock */ |
884 | ||
885 | memset(best_clock, 0, sizeof(*best_clock)); | |
a0c4da24 JB |
886 | |
887 | /* based on hardware requirement, prefer smaller n to precision */ | |
27e639bf | 888 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
811bbf05 | 889 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
889059d8 | 890 | for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow; |
c1a9ae43 | 891 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
6b4bf1c4 | 892 | clock.p = clock.p1 * clock.p2; |
a0c4da24 | 893 | /* based on hardware requirement, prefer bigger m1,m2 values */ |
6b4bf1c4 | 894 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) { |
d5dd62bd | 895 | unsigned int ppm; |
69e4f900 | 896 | |
6b4bf1c4 VS |
897 | clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n, |
898 | refclk * clock.m1); | |
899 | ||
900 | vlv_clock(refclk, &clock); | |
43b0ac53 | 901 | |
f01b7962 VS |
902 | if (!intel_PLL_is_valid(dev, limit, |
903 | &clock)) | |
43b0ac53 VS |
904 | continue; |
905 | ||
d5dd62bd ID |
906 | if (!vlv_PLL_is_optimal(dev, target, |
907 | &clock, | |
908 | best_clock, | |
909 | bestppm, &ppm)) | |
910 | continue; | |
6b4bf1c4 | 911 | |
d5dd62bd ID |
912 | *best_clock = clock; |
913 | bestppm = ppm; | |
914 | found = true; | |
a0c4da24 JB |
915 | } |
916 | } | |
917 | } | |
918 | } | |
a0c4da24 | 919 | |
49e497ef | 920 | return found; |
a0c4da24 | 921 | } |
a4fc5ed6 | 922 | |
ef9348c8 | 923 | static bool |
a93e255f ACO |
924 | chv_find_best_dpll(const intel_limit_t *limit, |
925 | struct intel_crtc_state *crtc_state, | |
ef9348c8 CML |
926 | int target, int refclk, intel_clock_t *match_clock, |
927 | intel_clock_t *best_clock) | |
928 | { | |
a93e255f | 929 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
a919ff14 | 930 | struct drm_device *dev = crtc->base.dev; |
9ca3ba01 | 931 | unsigned int best_error_ppm; |
ef9348c8 CML |
932 | intel_clock_t clock; |
933 | uint64_t m2; | |
934 | int found = false; | |
935 | ||
936 | memset(best_clock, 0, sizeof(*best_clock)); | |
9ca3ba01 | 937 | best_error_ppm = 1000000; |
ef9348c8 CML |
938 | |
939 | /* | |
940 | * Based on hardware doc, the n always set to 1, and m1 always | |
941 | * set to 2. If requires to support 200Mhz refclk, we need to | |
942 | * revisit this because n may not 1 anymore. | |
943 | */ | |
944 | clock.n = 1, clock.m1 = 2; | |
945 | target *= 5; /* fast clock */ | |
946 | ||
947 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { | |
948 | for (clock.p2 = limit->p2.p2_fast; | |
949 | clock.p2 >= limit->p2.p2_slow; | |
950 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { | |
9ca3ba01 | 951 | unsigned int error_ppm; |
ef9348c8 CML |
952 | |
953 | clock.p = clock.p1 * clock.p2; | |
954 | ||
955 | m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p * | |
956 | clock.n) << 22, refclk * clock.m1); | |
957 | ||
958 | if (m2 > INT_MAX/clock.m1) | |
959 | continue; | |
960 | ||
961 | clock.m2 = m2; | |
962 | ||
963 | chv_clock(refclk, &clock); | |
964 | ||
965 | if (!intel_PLL_is_valid(dev, limit, &clock)) | |
966 | continue; | |
967 | ||
9ca3ba01 ID |
968 | if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock, |
969 | best_error_ppm, &error_ppm)) | |
970 | continue; | |
971 | ||
972 | *best_clock = clock; | |
973 | best_error_ppm = error_ppm; | |
974 | found = true; | |
ef9348c8 CML |
975 | } |
976 | } | |
977 | ||
978 | return found; | |
979 | } | |
980 | ||
5ab7b0b7 ID |
981 | bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock, |
982 | intel_clock_t *best_clock) | |
983 | { | |
984 | int refclk = i9xx_get_refclk(crtc_state, 0); | |
985 | ||
986 | return chv_find_best_dpll(intel_limit(crtc_state, refclk), crtc_state, | |
987 | target_clock, refclk, NULL, best_clock); | |
988 | } | |
989 | ||
20ddf665 VS |
990 | bool intel_crtc_active(struct drm_crtc *crtc) |
991 | { | |
992 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
993 | ||
994 | /* Be paranoid as we can arrive here with only partial | |
995 | * state retrieved from the hardware during setup. | |
996 | * | |
241bfc38 | 997 | * We can ditch the adjusted_mode.crtc_clock check as soon |
20ddf665 VS |
998 | * as Haswell has gained clock readout/fastboot support. |
999 | * | |
66e514c1 | 1000 | * We can ditch the crtc->primary->fb check as soon as we can |
20ddf665 | 1001 | * properly reconstruct framebuffers. |
c3d1f436 MR |
1002 | * |
1003 | * FIXME: The intel_crtc->active here should be switched to | |
1004 | * crtc->state->active once we have proper CRTC states wired up | |
1005 | * for atomic. | |
20ddf665 | 1006 | */ |
c3d1f436 | 1007 | return intel_crtc->active && crtc->primary->state->fb && |
6e3c9717 | 1008 | intel_crtc->config->base.adjusted_mode.crtc_clock; |
20ddf665 VS |
1009 | } |
1010 | ||
a5c961d1 PZ |
1011 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, |
1012 | enum pipe pipe) | |
1013 | { | |
1014 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
1015 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
1016 | ||
6e3c9717 | 1017 | return intel_crtc->config->cpu_transcoder; |
a5c961d1 PZ |
1018 | } |
1019 | ||
fbf49ea2 VS |
1020 | static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe) |
1021 | { | |
1022 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1023 | u32 reg = PIPEDSL(pipe); | |
1024 | u32 line1, line2; | |
1025 | u32 line_mask; | |
1026 | ||
1027 | if (IS_GEN2(dev)) | |
1028 | line_mask = DSL_LINEMASK_GEN2; | |
1029 | else | |
1030 | line_mask = DSL_LINEMASK_GEN3; | |
1031 | ||
1032 | line1 = I915_READ(reg) & line_mask; | |
1033 | mdelay(5); | |
1034 | line2 = I915_READ(reg) & line_mask; | |
1035 | ||
1036 | return line1 == line2; | |
1037 | } | |
1038 | ||
ab7ad7f6 KP |
1039 | /* |
1040 | * intel_wait_for_pipe_off - wait for pipe to turn off | |
575f7ab7 | 1041 | * @crtc: crtc whose pipe to wait for |
9d0498a2 JB |
1042 | * |
1043 | * After disabling a pipe, we can't wait for vblank in the usual way, | |
1044 | * spinning on the vblank interrupt status bit, since we won't actually | |
1045 | * see an interrupt when the pipe is disabled. | |
1046 | * | |
ab7ad7f6 KP |
1047 | * On Gen4 and above: |
1048 | * wait for the pipe register state bit to turn off | |
1049 | * | |
1050 | * Otherwise: | |
1051 | * wait for the display line value to settle (it usually | |
1052 | * ends up stopping at the start of the next frame). | |
58e10eb9 | 1053 | * |
9d0498a2 | 1054 | */ |
575f7ab7 | 1055 | static void intel_wait_for_pipe_off(struct intel_crtc *crtc) |
9d0498a2 | 1056 | { |
575f7ab7 | 1057 | struct drm_device *dev = crtc->base.dev; |
9d0498a2 | 1058 | struct drm_i915_private *dev_priv = dev->dev_private; |
6e3c9717 | 1059 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
575f7ab7 | 1060 | enum pipe pipe = crtc->pipe; |
ab7ad7f6 KP |
1061 | |
1062 | if (INTEL_INFO(dev)->gen >= 4) { | |
702e7a56 | 1063 | int reg = PIPECONF(cpu_transcoder); |
ab7ad7f6 KP |
1064 | |
1065 | /* Wait for the Pipe State to go off */ | |
58e10eb9 CW |
1066 | if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0, |
1067 | 100)) | |
284637d9 | 1068 | WARN(1, "pipe_off wait timed out\n"); |
ab7ad7f6 | 1069 | } else { |
ab7ad7f6 | 1070 | /* Wait for the display line to settle */ |
fbf49ea2 | 1071 | if (wait_for(pipe_dsl_stopped(dev, pipe), 100)) |
284637d9 | 1072 | WARN(1, "pipe_off wait timed out\n"); |
ab7ad7f6 | 1073 | } |
79e53945 JB |
1074 | } |
1075 | ||
b0ea7d37 DL |
1076 | /* |
1077 | * ibx_digital_port_connected - is the specified port connected? | |
1078 | * @dev_priv: i915 private structure | |
1079 | * @port: the port to test | |
1080 | * | |
1081 | * Returns true if @port is connected, false otherwise. | |
1082 | */ | |
1083 | bool ibx_digital_port_connected(struct drm_i915_private *dev_priv, | |
1084 | struct intel_digital_port *port) | |
1085 | { | |
1086 | u32 bit; | |
1087 | ||
c36346e3 | 1088 | if (HAS_PCH_IBX(dev_priv->dev)) { |
eba905b2 | 1089 | switch (port->port) { |
c36346e3 DL |
1090 | case PORT_B: |
1091 | bit = SDE_PORTB_HOTPLUG; | |
1092 | break; | |
1093 | case PORT_C: | |
1094 | bit = SDE_PORTC_HOTPLUG; | |
1095 | break; | |
1096 | case PORT_D: | |
1097 | bit = SDE_PORTD_HOTPLUG; | |
1098 | break; | |
1099 | default: | |
1100 | return true; | |
1101 | } | |
1102 | } else { | |
eba905b2 | 1103 | switch (port->port) { |
c36346e3 DL |
1104 | case PORT_B: |
1105 | bit = SDE_PORTB_HOTPLUG_CPT; | |
1106 | break; | |
1107 | case PORT_C: | |
1108 | bit = SDE_PORTC_HOTPLUG_CPT; | |
1109 | break; | |
1110 | case PORT_D: | |
1111 | bit = SDE_PORTD_HOTPLUG_CPT; | |
1112 | break; | |
1113 | default: | |
1114 | return true; | |
1115 | } | |
b0ea7d37 DL |
1116 | } |
1117 | ||
1118 | return I915_READ(SDEISR) & bit; | |
1119 | } | |
1120 | ||
b24e7179 JB |
1121 | static const char *state_string(bool enabled) |
1122 | { | |
1123 | return enabled ? "on" : "off"; | |
1124 | } | |
1125 | ||
1126 | /* Only for pre-ILK configs */ | |
55607e8a DV |
1127 | void assert_pll(struct drm_i915_private *dev_priv, |
1128 | enum pipe pipe, bool state) | |
b24e7179 JB |
1129 | { |
1130 | int reg; | |
1131 | u32 val; | |
1132 | bool cur_state; | |
1133 | ||
1134 | reg = DPLL(pipe); | |
1135 | val = I915_READ(reg); | |
1136 | cur_state = !!(val & DPLL_VCO_ENABLE); | |
e2c719b7 | 1137 | I915_STATE_WARN(cur_state != state, |
b24e7179 JB |
1138 | "PLL state assertion failure (expected %s, current %s)\n", |
1139 | state_string(state), state_string(cur_state)); | |
1140 | } | |
b24e7179 | 1141 | |
23538ef1 JN |
1142 | /* XXX: the dsi pll is shared between MIPI DSI ports */ |
1143 | static void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state) | |
1144 | { | |
1145 | u32 val; | |
1146 | bool cur_state; | |
1147 | ||
a580516d | 1148 | mutex_lock(&dev_priv->sb_lock); |
23538ef1 | 1149 | val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); |
a580516d | 1150 | mutex_unlock(&dev_priv->sb_lock); |
23538ef1 JN |
1151 | |
1152 | cur_state = val & DSI_PLL_VCO_EN; | |
e2c719b7 | 1153 | I915_STATE_WARN(cur_state != state, |
23538ef1 JN |
1154 | "DSI PLL state assertion failure (expected %s, current %s)\n", |
1155 | state_string(state), state_string(cur_state)); | |
1156 | } | |
1157 | #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true) | |
1158 | #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false) | |
1159 | ||
55607e8a | 1160 | struct intel_shared_dpll * |
e2b78267 DV |
1161 | intel_crtc_to_shared_dpll(struct intel_crtc *crtc) |
1162 | { | |
1163 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; | |
1164 | ||
6e3c9717 | 1165 | if (crtc->config->shared_dpll < 0) |
e2b78267 DV |
1166 | return NULL; |
1167 | ||
6e3c9717 | 1168 | return &dev_priv->shared_dplls[crtc->config->shared_dpll]; |
e2b78267 DV |
1169 | } |
1170 | ||
040484af | 1171 | /* For ILK+ */ |
55607e8a DV |
1172 | void assert_shared_dpll(struct drm_i915_private *dev_priv, |
1173 | struct intel_shared_dpll *pll, | |
1174 | bool state) | |
040484af | 1175 | { |
040484af | 1176 | bool cur_state; |
5358901f | 1177 | struct intel_dpll_hw_state hw_state; |
040484af | 1178 | |
92b27b08 | 1179 | if (WARN (!pll, |
46edb027 | 1180 | "asserting DPLL %s with no DPLL\n", state_string(state))) |
ee7b9f93 | 1181 | return; |
ee7b9f93 | 1182 | |
5358901f | 1183 | cur_state = pll->get_hw_state(dev_priv, pll, &hw_state); |
e2c719b7 | 1184 | I915_STATE_WARN(cur_state != state, |
5358901f DV |
1185 | "%s assertion failure (expected %s, current %s)\n", |
1186 | pll->name, state_string(state), state_string(cur_state)); | |
040484af | 1187 | } |
040484af JB |
1188 | |
1189 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, | |
1190 | enum pipe pipe, bool state) | |
1191 | { | |
1192 | int reg; | |
1193 | u32 val; | |
1194 | bool cur_state; | |
ad80a810 PZ |
1195 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
1196 | pipe); | |
040484af | 1197 | |
affa9354 PZ |
1198 | if (HAS_DDI(dev_priv->dev)) { |
1199 | /* DDI does not have a specific FDI_TX register */ | |
ad80a810 | 1200 | reg = TRANS_DDI_FUNC_CTL(cpu_transcoder); |
bf507ef7 | 1201 | val = I915_READ(reg); |
ad80a810 | 1202 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
bf507ef7 ED |
1203 | } else { |
1204 | reg = FDI_TX_CTL(pipe); | |
1205 | val = I915_READ(reg); | |
1206 | cur_state = !!(val & FDI_TX_ENABLE); | |
1207 | } | |
e2c719b7 | 1208 | I915_STATE_WARN(cur_state != state, |
040484af JB |
1209 | "FDI TX state assertion failure (expected %s, current %s)\n", |
1210 | state_string(state), state_string(cur_state)); | |
1211 | } | |
1212 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) | |
1213 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) | |
1214 | ||
1215 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, | |
1216 | enum pipe pipe, bool state) | |
1217 | { | |
1218 | int reg; | |
1219 | u32 val; | |
1220 | bool cur_state; | |
1221 | ||
d63fa0dc PZ |
1222 | reg = FDI_RX_CTL(pipe); |
1223 | val = I915_READ(reg); | |
1224 | cur_state = !!(val & FDI_RX_ENABLE); | |
e2c719b7 | 1225 | I915_STATE_WARN(cur_state != state, |
040484af JB |
1226 | "FDI RX state assertion failure (expected %s, current %s)\n", |
1227 | state_string(state), state_string(cur_state)); | |
1228 | } | |
1229 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) | |
1230 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) | |
1231 | ||
1232 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, | |
1233 | enum pipe pipe) | |
1234 | { | |
1235 | int reg; | |
1236 | u32 val; | |
1237 | ||
1238 | /* ILK FDI PLL is always enabled */ | |
3d13ef2e | 1239 | if (INTEL_INFO(dev_priv->dev)->gen == 5) |
040484af JB |
1240 | return; |
1241 | ||
bf507ef7 | 1242 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
affa9354 | 1243 | if (HAS_DDI(dev_priv->dev)) |
bf507ef7 ED |
1244 | return; |
1245 | ||
040484af JB |
1246 | reg = FDI_TX_CTL(pipe); |
1247 | val = I915_READ(reg); | |
e2c719b7 | 1248 | I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n"); |
040484af JB |
1249 | } |
1250 | ||
55607e8a DV |
1251 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, |
1252 | enum pipe pipe, bool state) | |
040484af JB |
1253 | { |
1254 | int reg; | |
1255 | u32 val; | |
55607e8a | 1256 | bool cur_state; |
040484af JB |
1257 | |
1258 | reg = FDI_RX_CTL(pipe); | |
1259 | val = I915_READ(reg); | |
55607e8a | 1260 | cur_state = !!(val & FDI_RX_PLL_ENABLE); |
e2c719b7 | 1261 | I915_STATE_WARN(cur_state != state, |
55607e8a DV |
1262 | "FDI RX PLL assertion failure (expected %s, current %s)\n", |
1263 | state_string(state), state_string(cur_state)); | |
040484af JB |
1264 | } |
1265 | ||
b680c37a DV |
1266 | void assert_panel_unlocked(struct drm_i915_private *dev_priv, |
1267 | enum pipe pipe) | |
ea0760cf | 1268 | { |
bedd4dba JN |
1269 | struct drm_device *dev = dev_priv->dev; |
1270 | int pp_reg; | |
ea0760cf JB |
1271 | u32 val; |
1272 | enum pipe panel_pipe = PIPE_A; | |
0de3b485 | 1273 | bool locked = true; |
ea0760cf | 1274 | |
bedd4dba JN |
1275 | if (WARN_ON(HAS_DDI(dev))) |
1276 | return; | |
1277 | ||
1278 | if (HAS_PCH_SPLIT(dev)) { | |
1279 | u32 port_sel; | |
1280 | ||
ea0760cf | 1281 | pp_reg = PCH_PP_CONTROL; |
bedd4dba JN |
1282 | port_sel = I915_READ(PCH_PP_ON_DELAYS) & PANEL_PORT_SELECT_MASK; |
1283 | ||
1284 | if (port_sel == PANEL_PORT_SELECT_LVDS && | |
1285 | I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT) | |
1286 | panel_pipe = PIPE_B; | |
1287 | /* XXX: else fix for eDP */ | |
1288 | } else if (IS_VALLEYVIEW(dev)) { | |
1289 | /* presumably write lock depends on pipe, not port select */ | |
1290 | pp_reg = VLV_PIPE_PP_CONTROL(pipe); | |
1291 | panel_pipe = pipe; | |
ea0760cf JB |
1292 | } else { |
1293 | pp_reg = PP_CONTROL; | |
bedd4dba JN |
1294 | if (I915_READ(LVDS) & LVDS_PIPEB_SELECT) |
1295 | panel_pipe = PIPE_B; | |
ea0760cf JB |
1296 | } |
1297 | ||
1298 | val = I915_READ(pp_reg); | |
1299 | if (!(val & PANEL_POWER_ON) || | |
ec49ba2d | 1300 | ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) |
ea0760cf JB |
1301 | locked = false; |
1302 | ||
e2c719b7 | 1303 | I915_STATE_WARN(panel_pipe == pipe && locked, |
ea0760cf | 1304 | "panel assertion failure, pipe %c regs locked\n", |
9db4a9c7 | 1305 | pipe_name(pipe)); |
ea0760cf JB |
1306 | } |
1307 | ||
93ce0ba6 JN |
1308 | static void assert_cursor(struct drm_i915_private *dev_priv, |
1309 | enum pipe pipe, bool state) | |
1310 | { | |
1311 | struct drm_device *dev = dev_priv->dev; | |
1312 | bool cur_state; | |
1313 | ||
d9d82081 | 1314 | if (IS_845G(dev) || IS_I865G(dev)) |
93ce0ba6 | 1315 | cur_state = I915_READ(_CURACNTR) & CURSOR_ENABLE; |
d9d82081 | 1316 | else |
5efb3e28 | 1317 | cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE; |
93ce0ba6 | 1318 | |
e2c719b7 | 1319 | I915_STATE_WARN(cur_state != state, |
93ce0ba6 JN |
1320 | "cursor on pipe %c assertion failure (expected %s, current %s)\n", |
1321 | pipe_name(pipe), state_string(state), state_string(cur_state)); | |
1322 | } | |
1323 | #define assert_cursor_enabled(d, p) assert_cursor(d, p, true) | |
1324 | #define assert_cursor_disabled(d, p) assert_cursor(d, p, false) | |
1325 | ||
b840d907 JB |
1326 | void assert_pipe(struct drm_i915_private *dev_priv, |
1327 | enum pipe pipe, bool state) | |
b24e7179 JB |
1328 | { |
1329 | int reg; | |
1330 | u32 val; | |
63d7bbe9 | 1331 | bool cur_state; |
702e7a56 PZ |
1332 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
1333 | pipe); | |
b24e7179 | 1334 | |
b6b5d049 VS |
1335 | /* if we need the pipe quirk it must be always on */ |
1336 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || | |
1337 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
8e636784 DV |
1338 | state = true; |
1339 | ||
f458ebbc | 1340 | if (!intel_display_power_is_enabled(dev_priv, |
b97186f0 | 1341 | POWER_DOMAIN_TRANSCODER(cpu_transcoder))) { |
69310161 PZ |
1342 | cur_state = false; |
1343 | } else { | |
1344 | reg = PIPECONF(cpu_transcoder); | |
1345 | val = I915_READ(reg); | |
1346 | cur_state = !!(val & PIPECONF_ENABLE); | |
1347 | } | |
1348 | ||
e2c719b7 | 1349 | I915_STATE_WARN(cur_state != state, |
63d7bbe9 | 1350 | "pipe %c assertion failure (expected %s, current %s)\n", |
9db4a9c7 | 1351 | pipe_name(pipe), state_string(state), state_string(cur_state)); |
b24e7179 JB |
1352 | } |
1353 | ||
931872fc CW |
1354 | static void assert_plane(struct drm_i915_private *dev_priv, |
1355 | enum plane plane, bool state) | |
b24e7179 JB |
1356 | { |
1357 | int reg; | |
1358 | u32 val; | |
931872fc | 1359 | bool cur_state; |
b24e7179 JB |
1360 | |
1361 | reg = DSPCNTR(plane); | |
1362 | val = I915_READ(reg); | |
931872fc | 1363 | cur_state = !!(val & DISPLAY_PLANE_ENABLE); |
e2c719b7 | 1364 | I915_STATE_WARN(cur_state != state, |
931872fc CW |
1365 | "plane %c assertion failure (expected %s, current %s)\n", |
1366 | plane_name(plane), state_string(state), state_string(cur_state)); | |
b24e7179 JB |
1367 | } |
1368 | ||
931872fc CW |
1369 | #define assert_plane_enabled(d, p) assert_plane(d, p, true) |
1370 | #define assert_plane_disabled(d, p) assert_plane(d, p, false) | |
1371 | ||
b24e7179 JB |
1372 | static void assert_planes_disabled(struct drm_i915_private *dev_priv, |
1373 | enum pipe pipe) | |
1374 | { | |
653e1026 | 1375 | struct drm_device *dev = dev_priv->dev; |
b24e7179 JB |
1376 | int reg, i; |
1377 | u32 val; | |
1378 | int cur_pipe; | |
1379 | ||
653e1026 VS |
1380 | /* Primary planes are fixed to pipes on gen4+ */ |
1381 | if (INTEL_INFO(dev)->gen >= 4) { | |
28c05794 AJ |
1382 | reg = DSPCNTR(pipe); |
1383 | val = I915_READ(reg); | |
e2c719b7 | 1384 | I915_STATE_WARN(val & DISPLAY_PLANE_ENABLE, |
28c05794 AJ |
1385 | "plane %c assertion failure, should be disabled but not\n", |
1386 | plane_name(pipe)); | |
19ec1358 | 1387 | return; |
28c05794 | 1388 | } |
19ec1358 | 1389 | |
b24e7179 | 1390 | /* Need to check both planes against the pipe */ |
055e393f | 1391 | for_each_pipe(dev_priv, i) { |
b24e7179 JB |
1392 | reg = DSPCNTR(i); |
1393 | val = I915_READ(reg); | |
1394 | cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> | |
1395 | DISPPLANE_SEL_PIPE_SHIFT; | |
e2c719b7 | 1396 | I915_STATE_WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe, |
9db4a9c7 JB |
1397 | "plane %c assertion failure, should be off on pipe %c but is still active\n", |
1398 | plane_name(i), pipe_name(pipe)); | |
b24e7179 JB |
1399 | } |
1400 | } | |
1401 | ||
19332d7a JB |
1402 | static void assert_sprites_disabled(struct drm_i915_private *dev_priv, |
1403 | enum pipe pipe) | |
1404 | { | |
20674eef | 1405 | struct drm_device *dev = dev_priv->dev; |
1fe47785 | 1406 | int reg, sprite; |
19332d7a JB |
1407 | u32 val; |
1408 | ||
7feb8b88 | 1409 | if (INTEL_INFO(dev)->gen >= 9) { |
3bdcfc0c | 1410 | for_each_sprite(dev_priv, pipe, sprite) { |
7feb8b88 | 1411 | val = I915_READ(PLANE_CTL(pipe, sprite)); |
e2c719b7 | 1412 | I915_STATE_WARN(val & PLANE_CTL_ENABLE, |
7feb8b88 DL |
1413 | "plane %d assertion failure, should be off on pipe %c but is still active\n", |
1414 | sprite, pipe_name(pipe)); | |
1415 | } | |
1416 | } else if (IS_VALLEYVIEW(dev)) { | |
3bdcfc0c | 1417 | for_each_sprite(dev_priv, pipe, sprite) { |
1fe47785 | 1418 | reg = SPCNTR(pipe, sprite); |
20674eef | 1419 | val = I915_READ(reg); |
e2c719b7 | 1420 | I915_STATE_WARN(val & SP_ENABLE, |
20674eef | 1421 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
1fe47785 | 1422 | sprite_name(pipe, sprite), pipe_name(pipe)); |
20674eef VS |
1423 | } |
1424 | } else if (INTEL_INFO(dev)->gen >= 7) { | |
1425 | reg = SPRCTL(pipe); | |
19332d7a | 1426 | val = I915_READ(reg); |
e2c719b7 | 1427 | I915_STATE_WARN(val & SPRITE_ENABLE, |
06da8da2 | 1428 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
20674eef VS |
1429 | plane_name(pipe), pipe_name(pipe)); |
1430 | } else if (INTEL_INFO(dev)->gen >= 5) { | |
1431 | reg = DVSCNTR(pipe); | |
19332d7a | 1432 | val = I915_READ(reg); |
e2c719b7 | 1433 | I915_STATE_WARN(val & DVS_ENABLE, |
06da8da2 | 1434 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
20674eef | 1435 | plane_name(pipe), pipe_name(pipe)); |
19332d7a JB |
1436 | } |
1437 | } | |
1438 | ||
08c71e5e VS |
1439 | static void assert_vblank_disabled(struct drm_crtc *crtc) |
1440 | { | |
e2c719b7 | 1441 | if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0)) |
08c71e5e VS |
1442 | drm_crtc_vblank_put(crtc); |
1443 | } | |
1444 | ||
89eff4be | 1445 | static void ibx_assert_pch_refclk_enabled(struct drm_i915_private *dev_priv) |
92f2584a JB |
1446 | { |
1447 | u32 val; | |
1448 | bool enabled; | |
1449 | ||
e2c719b7 | 1450 | I915_STATE_WARN_ON(!(HAS_PCH_IBX(dev_priv->dev) || HAS_PCH_CPT(dev_priv->dev))); |
9d82aa17 | 1451 | |
92f2584a JB |
1452 | val = I915_READ(PCH_DREF_CONTROL); |
1453 | enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK | | |
1454 | DREF_SUPERSPREAD_SOURCE_MASK)); | |
e2c719b7 | 1455 | I915_STATE_WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n"); |
92f2584a JB |
1456 | } |
1457 | ||
ab9412ba DV |
1458 | static void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, |
1459 | enum pipe pipe) | |
92f2584a JB |
1460 | { |
1461 | int reg; | |
1462 | u32 val; | |
1463 | bool enabled; | |
1464 | ||
ab9412ba | 1465 | reg = PCH_TRANSCONF(pipe); |
92f2584a JB |
1466 | val = I915_READ(reg); |
1467 | enabled = !!(val & TRANS_ENABLE); | |
e2c719b7 | 1468 | I915_STATE_WARN(enabled, |
9db4a9c7 JB |
1469 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
1470 | pipe_name(pipe)); | |
92f2584a JB |
1471 | } |
1472 | ||
4e634389 KP |
1473 | static bool dp_pipe_enabled(struct drm_i915_private *dev_priv, |
1474 | enum pipe pipe, u32 port_sel, u32 val) | |
f0575e92 KP |
1475 | { |
1476 | if ((val & DP_PORT_EN) == 0) | |
1477 | return false; | |
1478 | ||
1479 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
1480 | u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe); | |
1481 | u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg); | |
1482 | if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel) | |
1483 | return false; | |
44f37d1f CML |
1484 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
1485 | if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe)) | |
1486 | return false; | |
f0575e92 KP |
1487 | } else { |
1488 | if ((val & DP_PIPE_MASK) != (pipe << 30)) | |
1489 | return false; | |
1490 | } | |
1491 | return true; | |
1492 | } | |
1493 | ||
1519b995 KP |
1494 | static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv, |
1495 | enum pipe pipe, u32 val) | |
1496 | { | |
dc0fa718 | 1497 | if ((val & SDVO_ENABLE) == 0) |
1519b995 KP |
1498 | return false; |
1499 | ||
1500 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
dc0fa718 | 1501 | if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe)) |
1519b995 | 1502 | return false; |
44f37d1f CML |
1503 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
1504 | if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe)) | |
1505 | return false; | |
1519b995 | 1506 | } else { |
dc0fa718 | 1507 | if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe)) |
1519b995 KP |
1508 | return false; |
1509 | } | |
1510 | return true; | |
1511 | } | |
1512 | ||
1513 | static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv, | |
1514 | enum pipe pipe, u32 val) | |
1515 | { | |
1516 | if ((val & LVDS_PORT_EN) == 0) | |
1517 | return false; | |
1518 | ||
1519 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
1520 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) | |
1521 | return false; | |
1522 | } else { | |
1523 | if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe)) | |
1524 | return false; | |
1525 | } | |
1526 | return true; | |
1527 | } | |
1528 | ||
1529 | static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv, | |
1530 | enum pipe pipe, u32 val) | |
1531 | { | |
1532 | if ((val & ADPA_DAC_ENABLE) == 0) | |
1533 | return false; | |
1534 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
1535 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) | |
1536 | return false; | |
1537 | } else { | |
1538 | if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe)) | |
1539 | return false; | |
1540 | } | |
1541 | return true; | |
1542 | } | |
1543 | ||
291906f1 | 1544 | static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv, |
f0575e92 | 1545 | enum pipe pipe, int reg, u32 port_sel) |
291906f1 | 1546 | { |
47a05eca | 1547 | u32 val = I915_READ(reg); |
e2c719b7 | 1548 | I915_STATE_WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val), |
291906f1 | 1549 | "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1550 | reg, pipe_name(pipe)); |
de9a35ab | 1551 | |
e2c719b7 | 1552 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0 |
75c5da27 | 1553 | && (val & DP_PIPEB_SELECT), |
de9a35ab | 1554 | "IBX PCH dp port still using transcoder B\n"); |
291906f1 JB |
1555 | } |
1556 | ||
1557 | static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv, | |
1558 | enum pipe pipe, int reg) | |
1559 | { | |
47a05eca | 1560 | u32 val = I915_READ(reg); |
e2c719b7 | 1561 | I915_STATE_WARN(hdmi_pipe_enabled(dev_priv, pipe, val), |
23c99e77 | 1562 | "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1563 | reg, pipe_name(pipe)); |
de9a35ab | 1564 | |
e2c719b7 | 1565 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_ENABLE) == 0 |
75c5da27 | 1566 | && (val & SDVO_PIPE_B_SELECT), |
de9a35ab | 1567 | "IBX PCH hdmi port still using transcoder B\n"); |
291906f1 JB |
1568 | } |
1569 | ||
1570 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, | |
1571 | enum pipe pipe) | |
1572 | { | |
1573 | int reg; | |
1574 | u32 val; | |
291906f1 | 1575 | |
f0575e92 KP |
1576 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B); |
1577 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C); | |
1578 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D); | |
291906f1 JB |
1579 | |
1580 | reg = PCH_ADPA; | |
1581 | val = I915_READ(reg); | |
e2c719b7 | 1582 | I915_STATE_WARN(adpa_pipe_enabled(dev_priv, pipe, val), |
291906f1 | 1583 | "PCH VGA enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1584 | pipe_name(pipe)); |
291906f1 JB |
1585 | |
1586 | reg = PCH_LVDS; | |
1587 | val = I915_READ(reg); | |
e2c719b7 | 1588 | I915_STATE_WARN(lvds_pipe_enabled(dev_priv, pipe, val), |
291906f1 | 1589 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1590 | pipe_name(pipe)); |
291906f1 | 1591 | |
e2debe91 PZ |
1592 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB); |
1593 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC); | |
1594 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID); | |
291906f1 JB |
1595 | } |
1596 | ||
40e9cf64 JB |
1597 | static void intel_init_dpio(struct drm_device *dev) |
1598 | { | |
1599 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1600 | ||
1601 | if (!IS_VALLEYVIEW(dev)) | |
1602 | return; | |
1603 | ||
a09caddd CML |
1604 | /* |
1605 | * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C), | |
1606 | * CHV x1 PHY (DP/HDMI D) | |
1607 | * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C) | |
1608 | */ | |
1609 | if (IS_CHERRYVIEW(dev)) { | |
1610 | DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO_2; | |
1611 | DPIO_PHY_IOSF_PORT(DPIO_PHY1) = IOSF_PORT_DPIO; | |
1612 | } else { | |
1613 | DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO; | |
1614 | } | |
5382f5f3 JB |
1615 | } |
1616 | ||
d288f65f | 1617 | static void vlv_enable_pll(struct intel_crtc *crtc, |
5cec258b | 1618 | const struct intel_crtc_state *pipe_config) |
87442f73 | 1619 | { |
426115cf DV |
1620 | struct drm_device *dev = crtc->base.dev; |
1621 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1622 | int reg = DPLL(crtc->pipe); | |
d288f65f | 1623 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
87442f73 | 1624 | |
426115cf | 1625 | assert_pipe_disabled(dev_priv, crtc->pipe); |
87442f73 DV |
1626 | |
1627 | /* No really, not for ILK+ */ | |
1628 | BUG_ON(!IS_VALLEYVIEW(dev_priv->dev)); | |
1629 | ||
1630 | /* PLL is protected by panel, make sure we can write it */ | |
6a9e7363 | 1631 | if (IS_MOBILE(dev_priv->dev)) |
426115cf | 1632 | assert_panel_unlocked(dev_priv, crtc->pipe); |
87442f73 | 1633 | |
426115cf DV |
1634 | I915_WRITE(reg, dpll); |
1635 | POSTING_READ(reg); | |
1636 | udelay(150); | |
1637 | ||
1638 | if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) | |
1639 | DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe); | |
1640 | ||
d288f65f | 1641 | I915_WRITE(DPLL_MD(crtc->pipe), pipe_config->dpll_hw_state.dpll_md); |
426115cf | 1642 | POSTING_READ(DPLL_MD(crtc->pipe)); |
87442f73 DV |
1643 | |
1644 | /* We do this three times for luck */ | |
426115cf | 1645 | I915_WRITE(reg, dpll); |
87442f73 DV |
1646 | POSTING_READ(reg); |
1647 | udelay(150); /* wait for warmup */ | |
426115cf | 1648 | I915_WRITE(reg, dpll); |
87442f73 DV |
1649 | POSTING_READ(reg); |
1650 | udelay(150); /* wait for warmup */ | |
426115cf | 1651 | I915_WRITE(reg, dpll); |
87442f73 DV |
1652 | POSTING_READ(reg); |
1653 | udelay(150); /* wait for warmup */ | |
1654 | } | |
1655 | ||
d288f65f | 1656 | static void chv_enable_pll(struct intel_crtc *crtc, |
5cec258b | 1657 | const struct intel_crtc_state *pipe_config) |
9d556c99 CML |
1658 | { |
1659 | struct drm_device *dev = crtc->base.dev; | |
1660 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1661 | int pipe = crtc->pipe; | |
1662 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
9d556c99 CML |
1663 | u32 tmp; |
1664 | ||
1665 | assert_pipe_disabled(dev_priv, crtc->pipe); | |
1666 | ||
1667 | BUG_ON(!IS_CHERRYVIEW(dev_priv->dev)); | |
1668 | ||
a580516d | 1669 | mutex_lock(&dev_priv->sb_lock); |
9d556c99 CML |
1670 | |
1671 | /* Enable back the 10bit clock to display controller */ | |
1672 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); | |
1673 | tmp |= DPIO_DCLKP_EN; | |
1674 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp); | |
1675 | ||
54433e91 VS |
1676 | mutex_unlock(&dev_priv->sb_lock); |
1677 | ||
9d556c99 CML |
1678 | /* |
1679 | * Need to wait > 100ns between dclkp clock enable bit and PLL enable. | |
1680 | */ | |
1681 | udelay(1); | |
1682 | ||
1683 | /* Enable PLL */ | |
d288f65f | 1684 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
9d556c99 CML |
1685 | |
1686 | /* Check PLL is locked */ | |
a11b0703 | 1687 | if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) |
9d556c99 CML |
1688 | DRM_ERROR("PLL %d failed to lock\n", pipe); |
1689 | ||
a11b0703 | 1690 | /* not sure when this should be written */ |
d288f65f | 1691 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
a11b0703 | 1692 | POSTING_READ(DPLL_MD(pipe)); |
9d556c99 CML |
1693 | } |
1694 | ||
1c4e0274 VS |
1695 | static int intel_num_dvo_pipes(struct drm_device *dev) |
1696 | { | |
1697 | struct intel_crtc *crtc; | |
1698 | int count = 0; | |
1699 | ||
1700 | for_each_intel_crtc(dev, crtc) | |
3538b9df | 1701 | count += crtc->base.state->active && |
409ee761 | 1702 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO); |
1c4e0274 VS |
1703 | |
1704 | return count; | |
1705 | } | |
1706 | ||
66e3d5c0 | 1707 | static void i9xx_enable_pll(struct intel_crtc *crtc) |
63d7bbe9 | 1708 | { |
66e3d5c0 DV |
1709 | struct drm_device *dev = crtc->base.dev; |
1710 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1711 | int reg = DPLL(crtc->pipe); | |
6e3c9717 | 1712 | u32 dpll = crtc->config->dpll_hw_state.dpll; |
63d7bbe9 | 1713 | |
66e3d5c0 | 1714 | assert_pipe_disabled(dev_priv, crtc->pipe); |
58c6eaa2 | 1715 | |
63d7bbe9 | 1716 | /* No really, not for ILK+ */ |
3d13ef2e | 1717 | BUG_ON(INTEL_INFO(dev)->gen >= 5); |
63d7bbe9 JB |
1718 | |
1719 | /* PLL is protected by panel, make sure we can write it */ | |
66e3d5c0 DV |
1720 | if (IS_MOBILE(dev) && !IS_I830(dev)) |
1721 | assert_panel_unlocked(dev_priv, crtc->pipe); | |
63d7bbe9 | 1722 | |
1c4e0274 VS |
1723 | /* Enable DVO 2x clock on both PLLs if necessary */ |
1724 | if (IS_I830(dev) && intel_num_dvo_pipes(dev) > 0) { | |
1725 | /* | |
1726 | * It appears to be important that we don't enable this | |
1727 | * for the current pipe before otherwise configuring the | |
1728 | * PLL. No idea how this should be handled if multiple | |
1729 | * DVO outputs are enabled simultaneosly. | |
1730 | */ | |
1731 | dpll |= DPLL_DVO_2X_MODE; | |
1732 | I915_WRITE(DPLL(!crtc->pipe), | |
1733 | I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE); | |
1734 | } | |
66e3d5c0 DV |
1735 | |
1736 | /* Wait for the clocks to stabilize. */ | |
1737 | POSTING_READ(reg); | |
1738 | udelay(150); | |
1739 | ||
1740 | if (INTEL_INFO(dev)->gen >= 4) { | |
1741 | I915_WRITE(DPLL_MD(crtc->pipe), | |
6e3c9717 | 1742 | crtc->config->dpll_hw_state.dpll_md); |
66e3d5c0 DV |
1743 | } else { |
1744 | /* The pixel multiplier can only be updated once the | |
1745 | * DPLL is enabled and the clocks are stable. | |
1746 | * | |
1747 | * So write it again. | |
1748 | */ | |
1749 | I915_WRITE(reg, dpll); | |
1750 | } | |
63d7bbe9 JB |
1751 | |
1752 | /* We do this three times for luck */ | |
66e3d5c0 | 1753 | I915_WRITE(reg, dpll); |
63d7bbe9 JB |
1754 | POSTING_READ(reg); |
1755 | udelay(150); /* wait for warmup */ | |
66e3d5c0 | 1756 | I915_WRITE(reg, dpll); |
63d7bbe9 JB |
1757 | POSTING_READ(reg); |
1758 | udelay(150); /* wait for warmup */ | |
66e3d5c0 | 1759 | I915_WRITE(reg, dpll); |
63d7bbe9 JB |
1760 | POSTING_READ(reg); |
1761 | udelay(150); /* wait for warmup */ | |
1762 | } | |
1763 | ||
1764 | /** | |
50b44a44 | 1765 | * i9xx_disable_pll - disable a PLL |
63d7bbe9 JB |
1766 | * @dev_priv: i915 private structure |
1767 | * @pipe: pipe PLL to disable | |
1768 | * | |
1769 | * Disable the PLL for @pipe, making sure the pipe is off first. | |
1770 | * | |
1771 | * Note! This is for pre-ILK only. | |
1772 | */ | |
1c4e0274 | 1773 | static void i9xx_disable_pll(struct intel_crtc *crtc) |
63d7bbe9 | 1774 | { |
1c4e0274 VS |
1775 | struct drm_device *dev = crtc->base.dev; |
1776 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1777 | enum pipe pipe = crtc->pipe; | |
1778 | ||
1779 | /* Disable DVO 2x clock on both PLLs if necessary */ | |
1780 | if (IS_I830(dev) && | |
409ee761 | 1781 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO) && |
3538b9df | 1782 | !intel_num_dvo_pipes(dev)) { |
1c4e0274 VS |
1783 | I915_WRITE(DPLL(PIPE_B), |
1784 | I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE); | |
1785 | I915_WRITE(DPLL(PIPE_A), | |
1786 | I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE); | |
1787 | } | |
1788 | ||
b6b5d049 VS |
1789 | /* Don't disable pipe or pipe PLLs if needed */ |
1790 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || | |
1791 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
63d7bbe9 JB |
1792 | return; |
1793 | ||
1794 | /* Make sure the pipe isn't still relying on us */ | |
1795 | assert_pipe_disabled(dev_priv, pipe); | |
1796 | ||
50b44a44 DV |
1797 | I915_WRITE(DPLL(pipe), 0); |
1798 | POSTING_READ(DPLL(pipe)); | |
63d7bbe9 JB |
1799 | } |
1800 | ||
f6071166 JB |
1801 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
1802 | { | |
1803 | u32 val = 0; | |
1804 | ||
1805 | /* Make sure the pipe isn't still relying on us */ | |
1806 | assert_pipe_disabled(dev_priv, pipe); | |
1807 | ||
e5cbfbfb ID |
1808 | /* |
1809 | * Leave integrated clock source and reference clock enabled for pipe B. | |
1810 | * The latter is needed for VGA hotplug / manual detection. | |
1811 | */ | |
f6071166 | 1812 | if (pipe == PIPE_B) |
e5cbfbfb | 1813 | val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REFA_CLK_ENABLE_VLV; |
f6071166 JB |
1814 | I915_WRITE(DPLL(pipe), val); |
1815 | POSTING_READ(DPLL(pipe)); | |
076ed3b2 CML |
1816 | |
1817 | } | |
1818 | ||
1819 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) | |
1820 | { | |
d752048d | 1821 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
076ed3b2 CML |
1822 | u32 val; |
1823 | ||
a11b0703 VS |
1824 | /* Make sure the pipe isn't still relying on us */ |
1825 | assert_pipe_disabled(dev_priv, pipe); | |
076ed3b2 | 1826 | |
a11b0703 | 1827 | /* Set PLL en = 0 */ |
d17ec4ce | 1828 | val = DPLL_SSC_REF_CLOCK_CHV | DPLL_REFA_CLK_ENABLE_VLV; |
a11b0703 VS |
1829 | if (pipe != PIPE_A) |
1830 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
1831 | I915_WRITE(DPLL(pipe), val); | |
1832 | POSTING_READ(DPLL(pipe)); | |
d752048d | 1833 | |
a580516d | 1834 | mutex_lock(&dev_priv->sb_lock); |
d752048d VS |
1835 | |
1836 | /* Disable 10bit clock to display controller */ | |
1837 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); | |
1838 | val &= ~DPIO_DCLKP_EN; | |
1839 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); | |
1840 | ||
61407f6d VS |
1841 | /* disable left/right clock distribution */ |
1842 | if (pipe != PIPE_B) { | |
1843 | val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0); | |
1844 | val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK); | |
1845 | vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val); | |
1846 | } else { | |
1847 | val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1); | |
1848 | val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK); | |
1849 | vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val); | |
1850 | } | |
1851 | ||
a580516d | 1852 | mutex_unlock(&dev_priv->sb_lock); |
f6071166 JB |
1853 | } |
1854 | ||
e4607fcf | 1855 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, |
9b6de0a1 VS |
1856 | struct intel_digital_port *dport, |
1857 | unsigned int expected_mask) | |
89b667f8 JB |
1858 | { |
1859 | u32 port_mask; | |
00fc31b7 | 1860 | int dpll_reg; |
89b667f8 | 1861 | |
e4607fcf CML |
1862 | switch (dport->port) { |
1863 | case PORT_B: | |
89b667f8 | 1864 | port_mask = DPLL_PORTB_READY_MASK; |
00fc31b7 | 1865 | dpll_reg = DPLL(0); |
e4607fcf CML |
1866 | break; |
1867 | case PORT_C: | |
89b667f8 | 1868 | port_mask = DPLL_PORTC_READY_MASK; |
00fc31b7 | 1869 | dpll_reg = DPLL(0); |
9b6de0a1 | 1870 | expected_mask <<= 4; |
00fc31b7 CML |
1871 | break; |
1872 | case PORT_D: | |
1873 | port_mask = DPLL_PORTD_READY_MASK; | |
1874 | dpll_reg = DPIO_PHY_STATUS; | |
e4607fcf CML |
1875 | break; |
1876 | default: | |
1877 | BUG(); | |
1878 | } | |
89b667f8 | 1879 | |
9b6de0a1 VS |
1880 | if (wait_for((I915_READ(dpll_reg) & port_mask) == expected_mask, 1000)) |
1881 | WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n", | |
1882 | port_name(dport->port), I915_READ(dpll_reg) & port_mask, expected_mask); | |
89b667f8 JB |
1883 | } |
1884 | ||
b14b1055 DV |
1885 | static void intel_prepare_shared_dpll(struct intel_crtc *crtc) |
1886 | { | |
1887 | struct drm_device *dev = crtc->base.dev; | |
1888 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1889 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); | |
1890 | ||
be19f0ff CW |
1891 | if (WARN_ON(pll == NULL)) |
1892 | return; | |
1893 | ||
3e369b76 | 1894 | WARN_ON(!pll->config.crtc_mask); |
b14b1055 DV |
1895 | if (pll->active == 0) { |
1896 | DRM_DEBUG_DRIVER("setting up %s\n", pll->name); | |
1897 | WARN_ON(pll->on); | |
1898 | assert_shared_dpll_disabled(dev_priv, pll); | |
1899 | ||
1900 | pll->mode_set(dev_priv, pll); | |
1901 | } | |
1902 | } | |
1903 | ||
92f2584a | 1904 | /** |
85b3894f | 1905 | * intel_enable_shared_dpll - enable PCH PLL |
92f2584a JB |
1906 | * @dev_priv: i915 private structure |
1907 | * @pipe: pipe PLL to enable | |
1908 | * | |
1909 | * The PCH PLL needs to be enabled before the PCH transcoder, since it | |
1910 | * drives the transcoder clock. | |
1911 | */ | |
85b3894f | 1912 | static void intel_enable_shared_dpll(struct intel_crtc *crtc) |
92f2584a | 1913 | { |
3d13ef2e DL |
1914 | struct drm_device *dev = crtc->base.dev; |
1915 | struct drm_i915_private *dev_priv = dev->dev_private; | |
e2b78267 | 1916 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
92f2584a | 1917 | |
87a875bb | 1918 | if (WARN_ON(pll == NULL)) |
48da64a8 CW |
1919 | return; |
1920 | ||
3e369b76 | 1921 | if (WARN_ON(pll->config.crtc_mask == 0)) |
48da64a8 | 1922 | return; |
ee7b9f93 | 1923 | |
74dd6928 | 1924 | DRM_DEBUG_KMS("enable %s (active %d, on? %d) for crtc %d\n", |
46edb027 | 1925 | pll->name, pll->active, pll->on, |
e2b78267 | 1926 | crtc->base.base.id); |
92f2584a | 1927 | |
cdbd2316 DV |
1928 | if (pll->active++) { |
1929 | WARN_ON(!pll->on); | |
e9d6944e | 1930 | assert_shared_dpll_enabled(dev_priv, pll); |
ee7b9f93 JB |
1931 | return; |
1932 | } | |
f4a091c7 | 1933 | WARN_ON(pll->on); |
ee7b9f93 | 1934 | |
bd2bb1b9 PZ |
1935 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
1936 | ||
46edb027 | 1937 | DRM_DEBUG_KMS("enabling %s\n", pll->name); |
e7b903d2 | 1938 | pll->enable(dev_priv, pll); |
ee7b9f93 | 1939 | pll->on = true; |
92f2584a JB |
1940 | } |
1941 | ||
f6daaec2 | 1942 | static void intel_disable_shared_dpll(struct intel_crtc *crtc) |
92f2584a | 1943 | { |
3d13ef2e DL |
1944 | struct drm_device *dev = crtc->base.dev; |
1945 | struct drm_i915_private *dev_priv = dev->dev_private; | |
e2b78267 | 1946 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
4c609cb8 | 1947 | |
92f2584a | 1948 | /* PCH only available on ILK+ */ |
3d13ef2e | 1949 | BUG_ON(INTEL_INFO(dev)->gen < 5); |
87a875bb | 1950 | if (WARN_ON(pll == NULL)) |
ee7b9f93 | 1951 | return; |
92f2584a | 1952 | |
3e369b76 | 1953 | if (WARN_ON(pll->config.crtc_mask == 0)) |
48da64a8 | 1954 | return; |
7a419866 | 1955 | |
46edb027 DV |
1956 | DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n", |
1957 | pll->name, pll->active, pll->on, | |
e2b78267 | 1958 | crtc->base.base.id); |
7a419866 | 1959 | |
48da64a8 | 1960 | if (WARN_ON(pll->active == 0)) { |
e9d6944e | 1961 | assert_shared_dpll_disabled(dev_priv, pll); |
48da64a8 CW |
1962 | return; |
1963 | } | |
1964 | ||
e9d6944e | 1965 | assert_shared_dpll_enabled(dev_priv, pll); |
f4a091c7 | 1966 | WARN_ON(!pll->on); |
cdbd2316 | 1967 | if (--pll->active) |
7a419866 | 1968 | return; |
ee7b9f93 | 1969 | |
46edb027 | 1970 | DRM_DEBUG_KMS("disabling %s\n", pll->name); |
e7b903d2 | 1971 | pll->disable(dev_priv, pll); |
ee7b9f93 | 1972 | pll->on = false; |
bd2bb1b9 PZ |
1973 | |
1974 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); | |
92f2584a JB |
1975 | } |
1976 | ||
b8a4f404 PZ |
1977 | static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
1978 | enum pipe pipe) | |
040484af | 1979 | { |
23670b32 | 1980 | struct drm_device *dev = dev_priv->dev; |
7c26e5c6 | 1981 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
e2b78267 | 1982 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
23670b32 | 1983 | uint32_t reg, val, pipeconf_val; |
040484af JB |
1984 | |
1985 | /* PCH only available on ILK+ */ | |
55522f37 | 1986 | BUG_ON(!HAS_PCH_SPLIT(dev)); |
040484af JB |
1987 | |
1988 | /* Make sure PCH DPLL is enabled */ | |
e72f9fbf | 1989 | assert_shared_dpll_enabled(dev_priv, |
e9d6944e | 1990 | intel_crtc_to_shared_dpll(intel_crtc)); |
040484af JB |
1991 | |
1992 | /* FDI must be feeding us bits for PCH ports */ | |
1993 | assert_fdi_tx_enabled(dev_priv, pipe); | |
1994 | assert_fdi_rx_enabled(dev_priv, pipe); | |
1995 | ||
23670b32 DV |
1996 | if (HAS_PCH_CPT(dev)) { |
1997 | /* Workaround: Set the timing override bit before enabling the | |
1998 | * pch transcoder. */ | |
1999 | reg = TRANS_CHICKEN2(pipe); | |
2000 | val = I915_READ(reg); | |
2001 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; | |
2002 | I915_WRITE(reg, val); | |
59c859d6 | 2003 | } |
23670b32 | 2004 | |
ab9412ba | 2005 | reg = PCH_TRANSCONF(pipe); |
040484af | 2006 | val = I915_READ(reg); |
5f7f726d | 2007 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
e9bcff5c JB |
2008 | |
2009 | if (HAS_PCH_IBX(dev_priv->dev)) { | |
2010 | /* | |
c5de7c6f VS |
2011 | * Make the BPC in transcoder be consistent with |
2012 | * that in pipeconf reg. For HDMI we must use 8bpc | |
2013 | * here for both 8bpc and 12bpc. | |
e9bcff5c | 2014 | */ |
dfd07d72 | 2015 | val &= ~PIPECONF_BPC_MASK; |
c5de7c6f VS |
2016 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_HDMI)) |
2017 | val |= PIPECONF_8BPC; | |
2018 | else | |
2019 | val |= pipeconf_val & PIPECONF_BPC_MASK; | |
e9bcff5c | 2020 | } |
5f7f726d PZ |
2021 | |
2022 | val &= ~TRANS_INTERLACE_MASK; | |
2023 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) | |
7c26e5c6 | 2024 | if (HAS_PCH_IBX(dev_priv->dev) && |
409ee761 | 2025 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
7c26e5c6 PZ |
2026 | val |= TRANS_LEGACY_INTERLACED_ILK; |
2027 | else | |
2028 | val |= TRANS_INTERLACED; | |
5f7f726d PZ |
2029 | else |
2030 | val |= TRANS_PROGRESSIVE; | |
2031 | ||
040484af JB |
2032 | I915_WRITE(reg, val | TRANS_ENABLE); |
2033 | if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100)) | |
4bb6f1f3 | 2034 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
040484af JB |
2035 | } |
2036 | ||
8fb033d7 | 2037 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
937bb610 | 2038 | enum transcoder cpu_transcoder) |
040484af | 2039 | { |
8fb033d7 | 2040 | u32 val, pipeconf_val; |
8fb033d7 PZ |
2041 | |
2042 | /* PCH only available on ILK+ */ | |
55522f37 | 2043 | BUG_ON(!HAS_PCH_SPLIT(dev_priv->dev)); |
8fb033d7 | 2044 | |
8fb033d7 | 2045 | /* FDI must be feeding us bits for PCH ports */ |
1a240d4d | 2046 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
937bb610 | 2047 | assert_fdi_rx_enabled(dev_priv, TRANSCODER_A); |
8fb033d7 | 2048 | |
223a6fdf PZ |
2049 | /* Workaround: set timing override bit. */ |
2050 | val = I915_READ(_TRANSA_CHICKEN2); | |
23670b32 | 2051 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
223a6fdf PZ |
2052 | I915_WRITE(_TRANSA_CHICKEN2, val); |
2053 | ||
25f3ef11 | 2054 | val = TRANS_ENABLE; |
937bb610 | 2055 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
8fb033d7 | 2056 | |
9a76b1c6 PZ |
2057 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
2058 | PIPECONF_INTERLACED_ILK) | |
a35f2679 | 2059 | val |= TRANS_INTERLACED; |
8fb033d7 PZ |
2060 | else |
2061 | val |= TRANS_PROGRESSIVE; | |
2062 | ||
ab9412ba DV |
2063 | I915_WRITE(LPT_TRANSCONF, val); |
2064 | if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100)) | |
937bb610 | 2065 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
8fb033d7 PZ |
2066 | } |
2067 | ||
b8a4f404 PZ |
2068 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
2069 | enum pipe pipe) | |
040484af | 2070 | { |
23670b32 DV |
2071 | struct drm_device *dev = dev_priv->dev; |
2072 | uint32_t reg, val; | |
040484af JB |
2073 | |
2074 | /* FDI relies on the transcoder */ | |
2075 | assert_fdi_tx_disabled(dev_priv, pipe); | |
2076 | assert_fdi_rx_disabled(dev_priv, pipe); | |
2077 | ||
291906f1 JB |
2078 | /* Ports must be off as well */ |
2079 | assert_pch_ports_disabled(dev_priv, pipe); | |
2080 | ||
ab9412ba | 2081 | reg = PCH_TRANSCONF(pipe); |
040484af JB |
2082 | val = I915_READ(reg); |
2083 | val &= ~TRANS_ENABLE; | |
2084 | I915_WRITE(reg, val); | |
2085 | /* wait for PCH transcoder off, transcoder state */ | |
2086 | if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50)) | |
4bb6f1f3 | 2087 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
23670b32 DV |
2088 | |
2089 | if (!HAS_PCH_IBX(dev)) { | |
2090 | /* Workaround: Clear the timing override chicken bit again. */ | |
2091 | reg = TRANS_CHICKEN2(pipe); | |
2092 | val = I915_READ(reg); | |
2093 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; | |
2094 | I915_WRITE(reg, val); | |
2095 | } | |
040484af JB |
2096 | } |
2097 | ||
ab4d966c | 2098 | static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
8fb033d7 | 2099 | { |
8fb033d7 PZ |
2100 | u32 val; |
2101 | ||
ab9412ba | 2102 | val = I915_READ(LPT_TRANSCONF); |
8fb033d7 | 2103 | val &= ~TRANS_ENABLE; |
ab9412ba | 2104 | I915_WRITE(LPT_TRANSCONF, val); |
8fb033d7 | 2105 | /* wait for PCH transcoder off, transcoder state */ |
ab9412ba | 2106 | if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50)) |
8a52fd9f | 2107 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
223a6fdf PZ |
2108 | |
2109 | /* Workaround: clear timing override bit. */ | |
2110 | val = I915_READ(_TRANSA_CHICKEN2); | |
23670b32 | 2111 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
223a6fdf | 2112 | I915_WRITE(_TRANSA_CHICKEN2, val); |
040484af JB |
2113 | } |
2114 | ||
b24e7179 | 2115 | /** |
309cfea8 | 2116 | * intel_enable_pipe - enable a pipe, asserting requirements |
0372264a | 2117 | * @crtc: crtc responsible for the pipe |
b24e7179 | 2118 | * |
0372264a | 2119 | * Enable @crtc's pipe, making sure that various hardware specific requirements |
b24e7179 | 2120 | * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc. |
b24e7179 | 2121 | */ |
e1fdc473 | 2122 | static void intel_enable_pipe(struct intel_crtc *crtc) |
b24e7179 | 2123 | { |
0372264a PZ |
2124 | struct drm_device *dev = crtc->base.dev; |
2125 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2126 | enum pipe pipe = crtc->pipe; | |
702e7a56 PZ |
2127 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
2128 | pipe); | |
1a240d4d | 2129 | enum pipe pch_transcoder; |
b24e7179 JB |
2130 | int reg; |
2131 | u32 val; | |
2132 | ||
58c6eaa2 | 2133 | assert_planes_disabled(dev_priv, pipe); |
93ce0ba6 | 2134 | assert_cursor_disabled(dev_priv, pipe); |
58c6eaa2 DV |
2135 | assert_sprites_disabled(dev_priv, pipe); |
2136 | ||
681e5811 | 2137 | if (HAS_PCH_LPT(dev_priv->dev)) |
cc391bbb PZ |
2138 | pch_transcoder = TRANSCODER_A; |
2139 | else | |
2140 | pch_transcoder = pipe; | |
2141 | ||
b24e7179 JB |
2142 | /* |
2143 | * A pipe without a PLL won't actually be able to drive bits from | |
2144 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't | |
2145 | * need the check. | |
2146 | */ | |
50360403 | 2147 | if (HAS_GMCH_DISPLAY(dev_priv->dev)) |
409ee761 | 2148 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI)) |
23538ef1 JN |
2149 | assert_dsi_pll_enabled(dev_priv); |
2150 | else | |
2151 | assert_pll_enabled(dev_priv, pipe); | |
040484af | 2152 | else { |
6e3c9717 | 2153 | if (crtc->config->has_pch_encoder) { |
040484af | 2154 | /* if driving the PCH, we need FDI enabled */ |
cc391bbb | 2155 | assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder); |
1a240d4d DV |
2156 | assert_fdi_tx_pll_enabled(dev_priv, |
2157 | (enum pipe) cpu_transcoder); | |
040484af JB |
2158 | } |
2159 | /* FIXME: assert CPU port conditions for SNB+ */ | |
2160 | } | |
b24e7179 | 2161 | |
702e7a56 | 2162 | reg = PIPECONF(cpu_transcoder); |
b24e7179 | 2163 | val = I915_READ(reg); |
7ad25d48 | 2164 | if (val & PIPECONF_ENABLE) { |
b6b5d049 VS |
2165 | WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
2166 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))); | |
00d70b15 | 2167 | return; |
7ad25d48 | 2168 | } |
00d70b15 CW |
2169 | |
2170 | I915_WRITE(reg, val | PIPECONF_ENABLE); | |
851855d8 | 2171 | POSTING_READ(reg); |
b24e7179 JB |
2172 | } |
2173 | ||
2174 | /** | |
309cfea8 | 2175 | * intel_disable_pipe - disable a pipe, asserting requirements |
575f7ab7 | 2176 | * @crtc: crtc whose pipes is to be disabled |
b24e7179 | 2177 | * |
575f7ab7 VS |
2178 | * Disable the pipe of @crtc, making sure that various hardware |
2179 | * specific requirements are met, if applicable, e.g. plane | |
2180 | * disabled, panel fitter off, etc. | |
b24e7179 JB |
2181 | * |
2182 | * Will wait until the pipe has shut down before returning. | |
2183 | */ | |
575f7ab7 | 2184 | static void intel_disable_pipe(struct intel_crtc *crtc) |
b24e7179 | 2185 | { |
575f7ab7 | 2186 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
6e3c9717 | 2187 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
575f7ab7 | 2188 | enum pipe pipe = crtc->pipe; |
b24e7179 JB |
2189 | int reg; |
2190 | u32 val; | |
2191 | ||
2192 | /* | |
2193 | * Make sure planes won't keep trying to pump pixels to us, | |
2194 | * or we might hang the display. | |
2195 | */ | |
2196 | assert_planes_disabled(dev_priv, pipe); | |
93ce0ba6 | 2197 | assert_cursor_disabled(dev_priv, pipe); |
19332d7a | 2198 | assert_sprites_disabled(dev_priv, pipe); |
b24e7179 | 2199 | |
702e7a56 | 2200 | reg = PIPECONF(cpu_transcoder); |
b24e7179 | 2201 | val = I915_READ(reg); |
00d70b15 CW |
2202 | if ((val & PIPECONF_ENABLE) == 0) |
2203 | return; | |
2204 | ||
67adc644 VS |
2205 | /* |
2206 | * Double wide has implications for planes | |
2207 | * so best keep it disabled when not needed. | |
2208 | */ | |
6e3c9717 | 2209 | if (crtc->config->double_wide) |
67adc644 VS |
2210 | val &= ~PIPECONF_DOUBLE_WIDE; |
2211 | ||
2212 | /* Don't disable pipe or pipe PLLs if needed */ | |
b6b5d049 VS |
2213 | if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) && |
2214 | !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
67adc644 VS |
2215 | val &= ~PIPECONF_ENABLE; |
2216 | ||
2217 | I915_WRITE(reg, val); | |
2218 | if ((val & PIPECONF_ENABLE) == 0) | |
2219 | intel_wait_for_pipe_off(crtc); | |
b24e7179 JB |
2220 | } |
2221 | ||
2222 | /** | |
262ca2b0 | 2223 | * intel_enable_primary_hw_plane - enable the primary plane on a given pipe |
fdd508a6 VS |
2224 | * @plane: plane to be enabled |
2225 | * @crtc: crtc for the plane | |
b24e7179 | 2226 | * |
fdd508a6 | 2227 | * Enable @plane on @crtc, making sure that the pipe is running first. |
b24e7179 | 2228 | */ |
fdd508a6 VS |
2229 | static void intel_enable_primary_hw_plane(struct drm_plane *plane, |
2230 | struct drm_crtc *crtc) | |
b24e7179 | 2231 | { |
fdd508a6 VS |
2232 | struct drm_device *dev = plane->dev; |
2233 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2234 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
b24e7179 JB |
2235 | |
2236 | /* If the pipe isn't enabled, we can't pump pixels and may hang */ | |
fdd508a6 | 2237 | assert_pipe_enabled(dev_priv, intel_crtc->pipe); |
b70709a6 | 2238 | to_intel_plane_state(plane->state)->visible = true; |
939c2fe8 | 2239 | |
fdd508a6 VS |
2240 | dev_priv->display.update_primary_plane(crtc, plane->fb, |
2241 | crtc->x, crtc->y); | |
b24e7179 JB |
2242 | } |
2243 | ||
693db184 CW |
2244 | static bool need_vtd_wa(struct drm_device *dev) |
2245 | { | |
2246 | #ifdef CONFIG_INTEL_IOMMU | |
2247 | if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped) | |
2248 | return true; | |
2249 | #endif | |
2250 | return false; | |
2251 | } | |
2252 | ||
50470bb0 | 2253 | unsigned int |
6761dd31 TU |
2254 | intel_tile_height(struct drm_device *dev, uint32_t pixel_format, |
2255 | uint64_t fb_format_modifier) | |
a57ce0b2 | 2256 | { |
6761dd31 TU |
2257 | unsigned int tile_height; |
2258 | uint32_t pixel_bytes; | |
a57ce0b2 | 2259 | |
b5d0e9bf DL |
2260 | switch (fb_format_modifier) { |
2261 | case DRM_FORMAT_MOD_NONE: | |
2262 | tile_height = 1; | |
2263 | break; | |
2264 | case I915_FORMAT_MOD_X_TILED: | |
2265 | tile_height = IS_GEN2(dev) ? 16 : 8; | |
2266 | break; | |
2267 | case I915_FORMAT_MOD_Y_TILED: | |
2268 | tile_height = 32; | |
2269 | break; | |
2270 | case I915_FORMAT_MOD_Yf_TILED: | |
6761dd31 TU |
2271 | pixel_bytes = drm_format_plane_cpp(pixel_format, 0); |
2272 | switch (pixel_bytes) { | |
b5d0e9bf | 2273 | default: |
6761dd31 | 2274 | case 1: |
b5d0e9bf DL |
2275 | tile_height = 64; |
2276 | break; | |
6761dd31 TU |
2277 | case 2: |
2278 | case 4: | |
b5d0e9bf DL |
2279 | tile_height = 32; |
2280 | break; | |
6761dd31 | 2281 | case 8: |
b5d0e9bf DL |
2282 | tile_height = 16; |
2283 | break; | |
6761dd31 | 2284 | case 16: |
b5d0e9bf DL |
2285 | WARN_ONCE(1, |
2286 | "128-bit pixels are not supported for display!"); | |
2287 | tile_height = 16; | |
2288 | break; | |
2289 | } | |
2290 | break; | |
2291 | default: | |
2292 | MISSING_CASE(fb_format_modifier); | |
2293 | tile_height = 1; | |
2294 | break; | |
2295 | } | |
091df6cb | 2296 | |
6761dd31 TU |
2297 | return tile_height; |
2298 | } | |
2299 | ||
2300 | unsigned int | |
2301 | intel_fb_align_height(struct drm_device *dev, unsigned int height, | |
2302 | uint32_t pixel_format, uint64_t fb_format_modifier) | |
2303 | { | |
2304 | return ALIGN(height, intel_tile_height(dev, pixel_format, | |
2305 | fb_format_modifier)); | |
a57ce0b2 JB |
2306 | } |
2307 | ||
f64b98cd TU |
2308 | static int |
2309 | intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, struct drm_framebuffer *fb, | |
2310 | const struct drm_plane_state *plane_state) | |
2311 | { | |
50470bb0 | 2312 | struct intel_rotation_info *info = &view->rotation_info; |
50470bb0 | 2313 | |
f64b98cd TU |
2314 | *view = i915_ggtt_view_normal; |
2315 | ||
50470bb0 TU |
2316 | if (!plane_state) |
2317 | return 0; | |
2318 | ||
121920fa | 2319 | if (!intel_rotation_90_or_270(plane_state->rotation)) |
50470bb0 TU |
2320 | return 0; |
2321 | ||
9abc4648 | 2322 | *view = i915_ggtt_view_rotated; |
50470bb0 TU |
2323 | |
2324 | info->height = fb->height; | |
2325 | info->pixel_format = fb->pixel_format; | |
2326 | info->pitch = fb->pitches[0]; | |
2327 | info->fb_modifier = fb->modifier[0]; | |
2328 | ||
f64b98cd TU |
2329 | return 0; |
2330 | } | |
2331 | ||
4e9a86b6 VS |
2332 | static unsigned int intel_linear_alignment(struct drm_i915_private *dev_priv) |
2333 | { | |
2334 | if (INTEL_INFO(dev_priv)->gen >= 9) | |
2335 | return 256 * 1024; | |
985b8bb4 VS |
2336 | else if (IS_BROADWATER(dev_priv) || IS_CRESTLINE(dev_priv) || |
2337 | IS_VALLEYVIEW(dev_priv)) | |
4e9a86b6 VS |
2338 | return 128 * 1024; |
2339 | else if (INTEL_INFO(dev_priv)->gen >= 4) | |
2340 | return 4 * 1024; | |
2341 | else | |
44c5905e | 2342 | return 0; |
4e9a86b6 VS |
2343 | } |
2344 | ||
127bd2ac | 2345 | int |
850c4cdc TU |
2346 | intel_pin_and_fence_fb_obj(struct drm_plane *plane, |
2347 | struct drm_framebuffer *fb, | |
82bc3b2d | 2348 | const struct drm_plane_state *plane_state, |
a4872ba6 | 2349 | struct intel_engine_cs *pipelined) |
6b95a207 | 2350 | { |
850c4cdc | 2351 | struct drm_device *dev = fb->dev; |
ce453d81 | 2352 | struct drm_i915_private *dev_priv = dev->dev_private; |
850c4cdc | 2353 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
f64b98cd | 2354 | struct i915_ggtt_view view; |
6b95a207 KH |
2355 | u32 alignment; |
2356 | int ret; | |
2357 | ||
ebcdd39e MR |
2358 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
2359 | ||
7b911adc TU |
2360 | switch (fb->modifier[0]) { |
2361 | case DRM_FORMAT_MOD_NONE: | |
4e9a86b6 | 2362 | alignment = intel_linear_alignment(dev_priv); |
6b95a207 | 2363 | break; |
7b911adc | 2364 | case I915_FORMAT_MOD_X_TILED: |
1fada4cc DL |
2365 | if (INTEL_INFO(dev)->gen >= 9) |
2366 | alignment = 256 * 1024; | |
2367 | else { | |
2368 | /* pin() will align the object as required by fence */ | |
2369 | alignment = 0; | |
2370 | } | |
6b95a207 | 2371 | break; |
7b911adc | 2372 | case I915_FORMAT_MOD_Y_TILED: |
1327b9a1 DL |
2373 | case I915_FORMAT_MOD_Yf_TILED: |
2374 | if (WARN_ONCE(INTEL_INFO(dev)->gen < 9, | |
2375 | "Y tiling bo slipped through, driver bug!\n")) | |
2376 | return -EINVAL; | |
2377 | alignment = 1 * 1024 * 1024; | |
2378 | break; | |
6b95a207 | 2379 | default: |
7b911adc TU |
2380 | MISSING_CASE(fb->modifier[0]); |
2381 | return -EINVAL; | |
6b95a207 KH |
2382 | } |
2383 | ||
f64b98cd TU |
2384 | ret = intel_fill_fb_ggtt_view(&view, fb, plane_state); |
2385 | if (ret) | |
2386 | return ret; | |
2387 | ||
693db184 CW |
2388 | /* Note that the w/a also requires 64 PTE of padding following the |
2389 | * bo. We currently fill all unused PTE with the shadow page and so | |
2390 | * we should always have valid PTE following the scanout preventing | |
2391 | * the VT-d warning. | |
2392 | */ | |
2393 | if (need_vtd_wa(dev) && alignment < 256 * 1024) | |
2394 | alignment = 256 * 1024; | |
2395 | ||
d6dd6843 PZ |
2396 | /* |
2397 | * Global gtt pte registers are special registers which actually forward | |
2398 | * writes to a chunk of system memory. Which means that there is no risk | |
2399 | * that the register values disappear as soon as we call | |
2400 | * intel_runtime_pm_put(), so it is correct to wrap only the | |
2401 | * pin/unpin/fence and not more. | |
2402 | */ | |
2403 | intel_runtime_pm_get(dev_priv); | |
2404 | ||
ce453d81 | 2405 | dev_priv->mm.interruptible = false; |
e6617330 | 2406 | ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined, |
f64b98cd | 2407 | &view); |
48b956c5 | 2408 | if (ret) |
ce453d81 | 2409 | goto err_interruptible; |
6b95a207 KH |
2410 | |
2411 | /* Install a fence for tiled scan-out. Pre-i965 always needs a | |
2412 | * fence, whereas 965+ only requires a fence if using | |
2413 | * framebuffer compression. For simplicity, we always install | |
2414 | * a fence as the cost is not that onerous. | |
2415 | */ | |
06d98131 | 2416 | ret = i915_gem_object_get_fence(obj); |
9a5a53b3 CW |
2417 | if (ret) |
2418 | goto err_unpin; | |
1690e1eb | 2419 | |
9a5a53b3 | 2420 | i915_gem_object_pin_fence(obj); |
6b95a207 | 2421 | |
ce453d81 | 2422 | dev_priv->mm.interruptible = true; |
d6dd6843 | 2423 | intel_runtime_pm_put(dev_priv); |
6b95a207 | 2424 | return 0; |
48b956c5 CW |
2425 | |
2426 | err_unpin: | |
f64b98cd | 2427 | i915_gem_object_unpin_from_display_plane(obj, &view); |
ce453d81 CW |
2428 | err_interruptible: |
2429 | dev_priv->mm.interruptible = true; | |
d6dd6843 | 2430 | intel_runtime_pm_put(dev_priv); |
48b956c5 | 2431 | return ret; |
6b95a207 KH |
2432 | } |
2433 | ||
82bc3b2d TU |
2434 | static void intel_unpin_fb_obj(struct drm_framebuffer *fb, |
2435 | const struct drm_plane_state *plane_state) | |
1690e1eb | 2436 | { |
82bc3b2d | 2437 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
f64b98cd TU |
2438 | struct i915_ggtt_view view; |
2439 | int ret; | |
82bc3b2d | 2440 | |
ebcdd39e MR |
2441 | WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex)); |
2442 | ||
f64b98cd TU |
2443 | ret = intel_fill_fb_ggtt_view(&view, fb, plane_state); |
2444 | WARN_ONCE(ret, "Couldn't get view from plane state!"); | |
2445 | ||
1690e1eb | 2446 | i915_gem_object_unpin_fence(obj); |
f64b98cd | 2447 | i915_gem_object_unpin_from_display_plane(obj, &view); |
1690e1eb CW |
2448 | } |
2449 | ||
c2c75131 DV |
2450 | /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel |
2451 | * is assumed to be a power-of-two. */ | |
4e9a86b6 VS |
2452 | unsigned long intel_gen4_compute_page_offset(struct drm_i915_private *dev_priv, |
2453 | int *x, int *y, | |
bc752862 CW |
2454 | unsigned int tiling_mode, |
2455 | unsigned int cpp, | |
2456 | unsigned int pitch) | |
c2c75131 | 2457 | { |
bc752862 CW |
2458 | if (tiling_mode != I915_TILING_NONE) { |
2459 | unsigned int tile_rows, tiles; | |
c2c75131 | 2460 | |
bc752862 CW |
2461 | tile_rows = *y / 8; |
2462 | *y %= 8; | |
c2c75131 | 2463 | |
bc752862 CW |
2464 | tiles = *x / (512/cpp); |
2465 | *x %= 512/cpp; | |
2466 | ||
2467 | return tile_rows * pitch * 8 + tiles * 4096; | |
2468 | } else { | |
4e9a86b6 | 2469 | unsigned int alignment = intel_linear_alignment(dev_priv) - 1; |
bc752862 CW |
2470 | unsigned int offset; |
2471 | ||
2472 | offset = *y * pitch + *x * cpp; | |
4e9a86b6 VS |
2473 | *y = (offset & alignment) / pitch; |
2474 | *x = ((offset & alignment) - *y * pitch) / cpp; | |
2475 | return offset & ~alignment; | |
bc752862 | 2476 | } |
c2c75131 DV |
2477 | } |
2478 | ||
b35d63fa | 2479 | static int i9xx_format_to_fourcc(int format) |
46f297fb JB |
2480 | { |
2481 | switch (format) { | |
2482 | case DISPPLANE_8BPP: | |
2483 | return DRM_FORMAT_C8; | |
2484 | case DISPPLANE_BGRX555: | |
2485 | return DRM_FORMAT_XRGB1555; | |
2486 | case DISPPLANE_BGRX565: | |
2487 | return DRM_FORMAT_RGB565; | |
2488 | default: | |
2489 | case DISPPLANE_BGRX888: | |
2490 | return DRM_FORMAT_XRGB8888; | |
2491 | case DISPPLANE_RGBX888: | |
2492 | return DRM_FORMAT_XBGR8888; | |
2493 | case DISPPLANE_BGRX101010: | |
2494 | return DRM_FORMAT_XRGB2101010; | |
2495 | case DISPPLANE_RGBX101010: | |
2496 | return DRM_FORMAT_XBGR2101010; | |
2497 | } | |
2498 | } | |
2499 | ||
bc8d7dff DL |
2500 | static int skl_format_to_fourcc(int format, bool rgb_order, bool alpha) |
2501 | { | |
2502 | switch (format) { | |
2503 | case PLANE_CTL_FORMAT_RGB_565: | |
2504 | return DRM_FORMAT_RGB565; | |
2505 | default: | |
2506 | case PLANE_CTL_FORMAT_XRGB_8888: | |
2507 | if (rgb_order) { | |
2508 | if (alpha) | |
2509 | return DRM_FORMAT_ABGR8888; | |
2510 | else | |
2511 | return DRM_FORMAT_XBGR8888; | |
2512 | } else { | |
2513 | if (alpha) | |
2514 | return DRM_FORMAT_ARGB8888; | |
2515 | else | |
2516 | return DRM_FORMAT_XRGB8888; | |
2517 | } | |
2518 | case PLANE_CTL_FORMAT_XRGB_2101010: | |
2519 | if (rgb_order) | |
2520 | return DRM_FORMAT_XBGR2101010; | |
2521 | else | |
2522 | return DRM_FORMAT_XRGB2101010; | |
2523 | } | |
2524 | } | |
2525 | ||
5724dbd1 | 2526 | static bool |
f6936e29 DV |
2527 | intel_alloc_initial_plane_obj(struct intel_crtc *crtc, |
2528 | struct intel_initial_plane_config *plane_config) | |
46f297fb JB |
2529 | { |
2530 | struct drm_device *dev = crtc->base.dev; | |
2531 | struct drm_i915_gem_object *obj = NULL; | |
2532 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; | |
2d14030b | 2533 | struct drm_framebuffer *fb = &plane_config->fb->base; |
f37b5c2b DV |
2534 | u32 base_aligned = round_down(plane_config->base, PAGE_SIZE); |
2535 | u32 size_aligned = round_up(plane_config->base + plane_config->size, | |
2536 | PAGE_SIZE); | |
2537 | ||
2538 | size_aligned -= base_aligned; | |
46f297fb | 2539 | |
ff2652ea CW |
2540 | if (plane_config->size == 0) |
2541 | return false; | |
2542 | ||
f37b5c2b DV |
2543 | obj = i915_gem_object_create_stolen_for_preallocated(dev, |
2544 | base_aligned, | |
2545 | base_aligned, | |
2546 | size_aligned); | |
46f297fb | 2547 | if (!obj) |
484b41dd | 2548 | return false; |
46f297fb | 2549 | |
49af449b DL |
2550 | obj->tiling_mode = plane_config->tiling; |
2551 | if (obj->tiling_mode == I915_TILING_X) | |
6bf129df | 2552 | obj->stride = fb->pitches[0]; |
46f297fb | 2553 | |
6bf129df DL |
2554 | mode_cmd.pixel_format = fb->pixel_format; |
2555 | mode_cmd.width = fb->width; | |
2556 | mode_cmd.height = fb->height; | |
2557 | mode_cmd.pitches[0] = fb->pitches[0]; | |
18c5247e DV |
2558 | mode_cmd.modifier[0] = fb->modifier[0]; |
2559 | mode_cmd.flags = DRM_MODE_FB_MODIFIERS; | |
46f297fb JB |
2560 | |
2561 | mutex_lock(&dev->struct_mutex); | |
6bf129df | 2562 | if (intel_framebuffer_init(dev, to_intel_framebuffer(fb), |
484b41dd | 2563 | &mode_cmd, obj)) { |
46f297fb JB |
2564 | DRM_DEBUG_KMS("intel fb init failed\n"); |
2565 | goto out_unref_obj; | |
2566 | } | |
46f297fb | 2567 | mutex_unlock(&dev->struct_mutex); |
484b41dd | 2568 | |
f6936e29 | 2569 | DRM_DEBUG_KMS("initial plane fb obj %p\n", obj); |
484b41dd | 2570 | return true; |
46f297fb JB |
2571 | |
2572 | out_unref_obj: | |
2573 | drm_gem_object_unreference(&obj->base); | |
2574 | mutex_unlock(&dev->struct_mutex); | |
484b41dd JB |
2575 | return false; |
2576 | } | |
2577 | ||
afd65eb4 MR |
2578 | /* Update plane->state->fb to match plane->fb after driver-internal updates */ |
2579 | static void | |
2580 | update_state_fb(struct drm_plane *plane) | |
2581 | { | |
2582 | if (plane->fb == plane->state->fb) | |
2583 | return; | |
2584 | ||
2585 | if (plane->state->fb) | |
2586 | drm_framebuffer_unreference(plane->state->fb); | |
2587 | plane->state->fb = plane->fb; | |
2588 | if (plane->state->fb) | |
2589 | drm_framebuffer_reference(plane->state->fb); | |
2590 | } | |
2591 | ||
5724dbd1 | 2592 | static void |
f6936e29 DV |
2593 | intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, |
2594 | struct intel_initial_plane_config *plane_config) | |
484b41dd JB |
2595 | { |
2596 | struct drm_device *dev = intel_crtc->base.dev; | |
d9ceb816 | 2597 | struct drm_i915_private *dev_priv = dev->dev_private; |
484b41dd JB |
2598 | struct drm_crtc *c; |
2599 | struct intel_crtc *i; | |
2ff8fde1 | 2600 | struct drm_i915_gem_object *obj; |
88595ac9 DV |
2601 | struct drm_plane *primary = intel_crtc->base.primary; |
2602 | struct drm_framebuffer *fb; | |
484b41dd | 2603 | |
2d14030b | 2604 | if (!plane_config->fb) |
484b41dd JB |
2605 | return; |
2606 | ||
f6936e29 | 2607 | if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) { |
88595ac9 DV |
2608 | fb = &plane_config->fb->base; |
2609 | goto valid_fb; | |
f55548b5 | 2610 | } |
484b41dd | 2611 | |
2d14030b | 2612 | kfree(plane_config->fb); |
484b41dd JB |
2613 | |
2614 | /* | |
2615 | * Failed to alloc the obj, check to see if we should share | |
2616 | * an fb with another CRTC instead | |
2617 | */ | |
70e1e0ec | 2618 | for_each_crtc(dev, c) { |
484b41dd JB |
2619 | i = to_intel_crtc(c); |
2620 | ||
2621 | if (c == &intel_crtc->base) | |
2622 | continue; | |
2623 | ||
2ff8fde1 MR |
2624 | if (!i->active) |
2625 | continue; | |
2626 | ||
88595ac9 DV |
2627 | fb = c->primary->fb; |
2628 | if (!fb) | |
484b41dd JB |
2629 | continue; |
2630 | ||
88595ac9 | 2631 | obj = intel_fb_obj(fb); |
2ff8fde1 | 2632 | if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) { |
88595ac9 DV |
2633 | drm_framebuffer_reference(fb); |
2634 | goto valid_fb; | |
484b41dd JB |
2635 | } |
2636 | } | |
88595ac9 DV |
2637 | |
2638 | return; | |
2639 | ||
2640 | valid_fb: | |
2641 | obj = intel_fb_obj(fb); | |
2642 | if (obj->tiling_mode != I915_TILING_NONE) | |
2643 | dev_priv->preserve_bios_swizzle = true; | |
2644 | ||
2645 | primary->fb = fb; | |
36750f28 | 2646 | primary->crtc = primary->state->crtc = &intel_crtc->base; |
88595ac9 | 2647 | update_state_fb(primary); |
36750f28 | 2648 | intel_crtc->base.state->plane_mask |= (1 << drm_plane_index(primary)); |
88595ac9 | 2649 | obj->frontbuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe); |
46f297fb JB |
2650 | } |
2651 | ||
29b9bde6 DV |
2652 | static void i9xx_update_primary_plane(struct drm_crtc *crtc, |
2653 | struct drm_framebuffer *fb, | |
2654 | int x, int y) | |
81255565 JB |
2655 | { |
2656 | struct drm_device *dev = crtc->dev; | |
2657 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2658 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
b70709a6 ML |
2659 | struct drm_plane *primary = crtc->primary; |
2660 | bool visible = to_intel_plane_state(primary->state)->visible; | |
c9ba6fad | 2661 | struct drm_i915_gem_object *obj; |
81255565 | 2662 | int plane = intel_crtc->plane; |
e506a0c6 | 2663 | unsigned long linear_offset; |
81255565 | 2664 | u32 dspcntr; |
f45651ba | 2665 | u32 reg = DSPCNTR(plane); |
48404c1e | 2666 | int pixel_size; |
f45651ba | 2667 | |
b70709a6 | 2668 | if (!visible || !fb) { |
fdd508a6 VS |
2669 | I915_WRITE(reg, 0); |
2670 | if (INTEL_INFO(dev)->gen >= 4) | |
2671 | I915_WRITE(DSPSURF(plane), 0); | |
2672 | else | |
2673 | I915_WRITE(DSPADDR(plane), 0); | |
2674 | POSTING_READ(reg); | |
2675 | return; | |
2676 | } | |
2677 | ||
c9ba6fad VS |
2678 | obj = intel_fb_obj(fb); |
2679 | if (WARN_ON(obj == NULL)) | |
2680 | return; | |
2681 | ||
2682 | pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); | |
2683 | ||
f45651ba VS |
2684 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
2685 | ||
fdd508a6 | 2686 | dspcntr |= DISPLAY_PLANE_ENABLE; |
f45651ba VS |
2687 | |
2688 | if (INTEL_INFO(dev)->gen < 4) { | |
2689 | if (intel_crtc->pipe == PIPE_B) | |
2690 | dspcntr |= DISPPLANE_SEL_PIPE_B; | |
2691 | ||
2692 | /* pipesrc and dspsize control the size that is scaled from, | |
2693 | * which should always be the user's requested size. | |
2694 | */ | |
2695 | I915_WRITE(DSPSIZE(plane), | |
6e3c9717 ACO |
2696 | ((intel_crtc->config->pipe_src_h - 1) << 16) | |
2697 | (intel_crtc->config->pipe_src_w - 1)); | |
f45651ba | 2698 | I915_WRITE(DSPPOS(plane), 0); |
c14b0485 VS |
2699 | } else if (IS_CHERRYVIEW(dev) && plane == PLANE_B) { |
2700 | I915_WRITE(PRIMSIZE(plane), | |
6e3c9717 ACO |
2701 | ((intel_crtc->config->pipe_src_h - 1) << 16) | |
2702 | (intel_crtc->config->pipe_src_w - 1)); | |
c14b0485 VS |
2703 | I915_WRITE(PRIMPOS(plane), 0); |
2704 | I915_WRITE(PRIMCNSTALPHA(plane), 0); | |
f45651ba | 2705 | } |
81255565 | 2706 | |
57779d06 VS |
2707 | switch (fb->pixel_format) { |
2708 | case DRM_FORMAT_C8: | |
81255565 JB |
2709 | dspcntr |= DISPPLANE_8BPP; |
2710 | break; | |
57779d06 | 2711 | case DRM_FORMAT_XRGB1555: |
57779d06 | 2712 | dspcntr |= DISPPLANE_BGRX555; |
81255565 | 2713 | break; |
57779d06 VS |
2714 | case DRM_FORMAT_RGB565: |
2715 | dspcntr |= DISPPLANE_BGRX565; | |
2716 | break; | |
2717 | case DRM_FORMAT_XRGB8888: | |
57779d06 VS |
2718 | dspcntr |= DISPPLANE_BGRX888; |
2719 | break; | |
2720 | case DRM_FORMAT_XBGR8888: | |
57779d06 VS |
2721 | dspcntr |= DISPPLANE_RGBX888; |
2722 | break; | |
2723 | case DRM_FORMAT_XRGB2101010: | |
57779d06 VS |
2724 | dspcntr |= DISPPLANE_BGRX101010; |
2725 | break; | |
2726 | case DRM_FORMAT_XBGR2101010: | |
57779d06 | 2727 | dspcntr |= DISPPLANE_RGBX101010; |
81255565 JB |
2728 | break; |
2729 | default: | |
baba133a | 2730 | BUG(); |
81255565 | 2731 | } |
57779d06 | 2732 | |
f45651ba VS |
2733 | if (INTEL_INFO(dev)->gen >= 4 && |
2734 | obj->tiling_mode != I915_TILING_NONE) | |
2735 | dspcntr |= DISPPLANE_TILED; | |
81255565 | 2736 | |
de1aa629 VS |
2737 | if (IS_G4X(dev)) |
2738 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; | |
2739 | ||
b9897127 | 2740 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
81255565 | 2741 | |
c2c75131 DV |
2742 | if (INTEL_INFO(dev)->gen >= 4) { |
2743 | intel_crtc->dspaddr_offset = | |
4e9a86b6 VS |
2744 | intel_gen4_compute_page_offset(dev_priv, |
2745 | &x, &y, obj->tiling_mode, | |
b9897127 | 2746 | pixel_size, |
bc752862 | 2747 | fb->pitches[0]); |
c2c75131 DV |
2748 | linear_offset -= intel_crtc->dspaddr_offset; |
2749 | } else { | |
e506a0c6 | 2750 | intel_crtc->dspaddr_offset = linear_offset; |
c2c75131 | 2751 | } |
e506a0c6 | 2752 | |
8e7d688b | 2753 | if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) { |
48404c1e SJ |
2754 | dspcntr |= DISPPLANE_ROTATE_180; |
2755 | ||
6e3c9717 ACO |
2756 | x += (intel_crtc->config->pipe_src_w - 1); |
2757 | y += (intel_crtc->config->pipe_src_h - 1); | |
48404c1e SJ |
2758 | |
2759 | /* Finding the last pixel of the last line of the display | |
2760 | data and adding to linear_offset*/ | |
2761 | linear_offset += | |
6e3c9717 ACO |
2762 | (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] + |
2763 | (intel_crtc->config->pipe_src_w - 1) * pixel_size; | |
48404c1e SJ |
2764 | } |
2765 | ||
2766 | I915_WRITE(reg, dspcntr); | |
2767 | ||
01f2c773 | 2768 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
a6c45cf0 | 2769 | if (INTEL_INFO(dev)->gen >= 4) { |
85ba7b7d DV |
2770 | I915_WRITE(DSPSURF(plane), |
2771 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); | |
5eddb70b | 2772 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
e506a0c6 | 2773 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
5eddb70b | 2774 | } else |
f343c5f6 | 2775 | I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset); |
5eddb70b | 2776 | POSTING_READ(reg); |
17638cd6 JB |
2777 | } |
2778 | ||
29b9bde6 DV |
2779 | static void ironlake_update_primary_plane(struct drm_crtc *crtc, |
2780 | struct drm_framebuffer *fb, | |
2781 | int x, int y) | |
17638cd6 JB |
2782 | { |
2783 | struct drm_device *dev = crtc->dev; | |
2784 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2785 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
b70709a6 ML |
2786 | struct drm_plane *primary = crtc->primary; |
2787 | bool visible = to_intel_plane_state(primary->state)->visible; | |
c9ba6fad | 2788 | struct drm_i915_gem_object *obj; |
17638cd6 | 2789 | int plane = intel_crtc->plane; |
e506a0c6 | 2790 | unsigned long linear_offset; |
17638cd6 | 2791 | u32 dspcntr; |
f45651ba | 2792 | u32 reg = DSPCNTR(plane); |
48404c1e | 2793 | int pixel_size; |
f45651ba | 2794 | |
b70709a6 | 2795 | if (!visible || !fb) { |
fdd508a6 VS |
2796 | I915_WRITE(reg, 0); |
2797 | I915_WRITE(DSPSURF(plane), 0); | |
2798 | POSTING_READ(reg); | |
2799 | return; | |
2800 | } | |
2801 | ||
c9ba6fad VS |
2802 | obj = intel_fb_obj(fb); |
2803 | if (WARN_ON(obj == NULL)) | |
2804 | return; | |
2805 | ||
2806 | pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); | |
2807 | ||
f45651ba VS |
2808 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
2809 | ||
fdd508a6 | 2810 | dspcntr |= DISPLAY_PLANE_ENABLE; |
f45651ba VS |
2811 | |
2812 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) | |
2813 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; | |
17638cd6 | 2814 | |
57779d06 VS |
2815 | switch (fb->pixel_format) { |
2816 | case DRM_FORMAT_C8: | |
17638cd6 JB |
2817 | dspcntr |= DISPPLANE_8BPP; |
2818 | break; | |
57779d06 VS |
2819 | case DRM_FORMAT_RGB565: |
2820 | dspcntr |= DISPPLANE_BGRX565; | |
17638cd6 | 2821 | break; |
57779d06 | 2822 | case DRM_FORMAT_XRGB8888: |
57779d06 VS |
2823 | dspcntr |= DISPPLANE_BGRX888; |
2824 | break; | |
2825 | case DRM_FORMAT_XBGR8888: | |
57779d06 VS |
2826 | dspcntr |= DISPPLANE_RGBX888; |
2827 | break; | |
2828 | case DRM_FORMAT_XRGB2101010: | |
57779d06 VS |
2829 | dspcntr |= DISPPLANE_BGRX101010; |
2830 | break; | |
2831 | case DRM_FORMAT_XBGR2101010: | |
57779d06 | 2832 | dspcntr |= DISPPLANE_RGBX101010; |
17638cd6 JB |
2833 | break; |
2834 | default: | |
baba133a | 2835 | BUG(); |
17638cd6 JB |
2836 | } |
2837 | ||
2838 | if (obj->tiling_mode != I915_TILING_NONE) | |
2839 | dspcntr |= DISPPLANE_TILED; | |
17638cd6 | 2840 | |
f45651ba | 2841 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) |
1f5d76db | 2842 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
17638cd6 | 2843 | |
b9897127 | 2844 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
c2c75131 | 2845 | intel_crtc->dspaddr_offset = |
4e9a86b6 VS |
2846 | intel_gen4_compute_page_offset(dev_priv, |
2847 | &x, &y, obj->tiling_mode, | |
b9897127 | 2848 | pixel_size, |
bc752862 | 2849 | fb->pitches[0]); |
c2c75131 | 2850 | linear_offset -= intel_crtc->dspaddr_offset; |
8e7d688b | 2851 | if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) { |
48404c1e SJ |
2852 | dspcntr |= DISPPLANE_ROTATE_180; |
2853 | ||
2854 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) { | |
6e3c9717 ACO |
2855 | x += (intel_crtc->config->pipe_src_w - 1); |
2856 | y += (intel_crtc->config->pipe_src_h - 1); | |
48404c1e SJ |
2857 | |
2858 | /* Finding the last pixel of the last line of the display | |
2859 | data and adding to linear_offset*/ | |
2860 | linear_offset += | |
6e3c9717 ACO |
2861 | (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] + |
2862 | (intel_crtc->config->pipe_src_w - 1) * pixel_size; | |
48404c1e SJ |
2863 | } |
2864 | } | |
2865 | ||
2866 | I915_WRITE(reg, dspcntr); | |
17638cd6 | 2867 | |
01f2c773 | 2868 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
85ba7b7d DV |
2869 | I915_WRITE(DSPSURF(plane), |
2870 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); | |
b3dc685e | 2871 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
bc1c91eb DL |
2872 | I915_WRITE(DSPOFFSET(plane), (y << 16) | x); |
2873 | } else { | |
2874 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); | |
2875 | I915_WRITE(DSPLINOFF(plane), linear_offset); | |
2876 | } | |
17638cd6 | 2877 | POSTING_READ(reg); |
17638cd6 JB |
2878 | } |
2879 | ||
b321803d DL |
2880 | u32 intel_fb_stride_alignment(struct drm_device *dev, uint64_t fb_modifier, |
2881 | uint32_t pixel_format) | |
2882 | { | |
2883 | u32 bits_per_pixel = drm_format_plane_cpp(pixel_format, 0) * 8; | |
2884 | ||
2885 | /* | |
2886 | * The stride is either expressed as a multiple of 64 bytes | |
2887 | * chunks for linear buffers or in number of tiles for tiled | |
2888 | * buffers. | |
2889 | */ | |
2890 | switch (fb_modifier) { | |
2891 | case DRM_FORMAT_MOD_NONE: | |
2892 | return 64; | |
2893 | case I915_FORMAT_MOD_X_TILED: | |
2894 | if (INTEL_INFO(dev)->gen == 2) | |
2895 | return 128; | |
2896 | return 512; | |
2897 | case I915_FORMAT_MOD_Y_TILED: | |
2898 | /* No need to check for old gens and Y tiling since this is | |
2899 | * about the display engine and those will be blocked before | |
2900 | * we get here. | |
2901 | */ | |
2902 | return 128; | |
2903 | case I915_FORMAT_MOD_Yf_TILED: | |
2904 | if (bits_per_pixel == 8) | |
2905 | return 64; | |
2906 | else | |
2907 | return 128; | |
2908 | default: | |
2909 | MISSING_CASE(fb_modifier); | |
2910 | return 64; | |
2911 | } | |
2912 | } | |
2913 | ||
121920fa TU |
2914 | unsigned long intel_plane_obj_offset(struct intel_plane *intel_plane, |
2915 | struct drm_i915_gem_object *obj) | |
2916 | { | |
9abc4648 | 2917 | const struct i915_ggtt_view *view = &i915_ggtt_view_normal; |
121920fa TU |
2918 | |
2919 | if (intel_rotation_90_or_270(intel_plane->base.state->rotation)) | |
9abc4648 | 2920 | view = &i915_ggtt_view_rotated; |
121920fa TU |
2921 | |
2922 | return i915_gem_obj_ggtt_offset_view(obj, view); | |
2923 | } | |
2924 | ||
a1b2278e CK |
2925 | /* |
2926 | * This function detaches (aka. unbinds) unused scalers in hardware | |
2927 | */ | |
2928 | void skl_detach_scalers(struct intel_crtc *intel_crtc) | |
2929 | { | |
2930 | struct drm_device *dev; | |
2931 | struct drm_i915_private *dev_priv; | |
2932 | struct intel_crtc_scaler_state *scaler_state; | |
2933 | int i; | |
2934 | ||
2935 | if (!intel_crtc || !intel_crtc->config) | |
2936 | return; | |
2937 | ||
2938 | dev = intel_crtc->base.dev; | |
2939 | dev_priv = dev->dev_private; | |
2940 | scaler_state = &intel_crtc->config->scaler_state; | |
2941 | ||
2942 | /* loop through and disable scalers that aren't in use */ | |
2943 | for (i = 0; i < intel_crtc->num_scalers; i++) { | |
2944 | if (!scaler_state->scalers[i].in_use) { | |
2945 | I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, i), 0); | |
2946 | I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, i), 0); | |
2947 | I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, i), 0); | |
2948 | DRM_DEBUG_KMS("CRTC:%d Disabled scaler id %u.%u\n", | |
2949 | intel_crtc->base.base.id, intel_crtc->pipe, i); | |
2950 | } | |
2951 | } | |
2952 | } | |
2953 | ||
6156a456 | 2954 | u32 skl_plane_ctl_format(uint32_t pixel_format) |
70d21f0e | 2955 | { |
6156a456 | 2956 | switch (pixel_format) { |
d161cf7a | 2957 | case DRM_FORMAT_C8: |
c34ce3d1 | 2958 | return PLANE_CTL_FORMAT_INDEXED; |
70d21f0e | 2959 | case DRM_FORMAT_RGB565: |
c34ce3d1 | 2960 | return PLANE_CTL_FORMAT_RGB_565; |
70d21f0e | 2961 | case DRM_FORMAT_XBGR8888: |
c34ce3d1 | 2962 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX; |
6156a456 | 2963 | case DRM_FORMAT_XRGB8888: |
c34ce3d1 | 2964 | return PLANE_CTL_FORMAT_XRGB_8888; |
6156a456 CK |
2965 | /* |
2966 | * XXX: For ARBG/ABGR formats we default to expecting scanout buffers | |
2967 | * to be already pre-multiplied. We need to add a knob (or a different | |
2968 | * DRM_FORMAT) for user-space to configure that. | |
2969 | */ | |
f75fb42a | 2970 | case DRM_FORMAT_ABGR8888: |
c34ce3d1 | 2971 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX | |
6156a456 | 2972 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
6156a456 | 2973 | case DRM_FORMAT_ARGB8888: |
c34ce3d1 | 2974 | return PLANE_CTL_FORMAT_XRGB_8888 | |
6156a456 | 2975 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
70d21f0e | 2976 | case DRM_FORMAT_XRGB2101010: |
c34ce3d1 | 2977 | return PLANE_CTL_FORMAT_XRGB_2101010; |
70d21f0e | 2978 | case DRM_FORMAT_XBGR2101010: |
c34ce3d1 | 2979 | return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010; |
6156a456 | 2980 | case DRM_FORMAT_YUYV: |
c34ce3d1 | 2981 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV; |
6156a456 | 2982 | case DRM_FORMAT_YVYU: |
c34ce3d1 | 2983 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU; |
6156a456 | 2984 | case DRM_FORMAT_UYVY: |
c34ce3d1 | 2985 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY; |
6156a456 | 2986 | case DRM_FORMAT_VYUY: |
c34ce3d1 | 2987 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY; |
70d21f0e | 2988 | default: |
4249eeef | 2989 | MISSING_CASE(pixel_format); |
70d21f0e | 2990 | } |
8cfcba41 | 2991 | |
c34ce3d1 | 2992 | return 0; |
6156a456 | 2993 | } |
70d21f0e | 2994 | |
6156a456 CK |
2995 | u32 skl_plane_ctl_tiling(uint64_t fb_modifier) |
2996 | { | |
6156a456 | 2997 | switch (fb_modifier) { |
30af77c4 | 2998 | case DRM_FORMAT_MOD_NONE: |
70d21f0e | 2999 | break; |
30af77c4 | 3000 | case I915_FORMAT_MOD_X_TILED: |
c34ce3d1 | 3001 | return PLANE_CTL_TILED_X; |
b321803d | 3002 | case I915_FORMAT_MOD_Y_TILED: |
c34ce3d1 | 3003 | return PLANE_CTL_TILED_Y; |
b321803d | 3004 | case I915_FORMAT_MOD_Yf_TILED: |
c34ce3d1 | 3005 | return PLANE_CTL_TILED_YF; |
70d21f0e | 3006 | default: |
6156a456 | 3007 | MISSING_CASE(fb_modifier); |
70d21f0e | 3008 | } |
8cfcba41 | 3009 | |
c34ce3d1 | 3010 | return 0; |
6156a456 | 3011 | } |
70d21f0e | 3012 | |
6156a456 CK |
3013 | u32 skl_plane_ctl_rotation(unsigned int rotation) |
3014 | { | |
3b7a5119 | 3015 | switch (rotation) { |
6156a456 CK |
3016 | case BIT(DRM_ROTATE_0): |
3017 | break; | |
1e8df167 SJ |
3018 | /* |
3019 | * DRM_ROTATE_ is counter clockwise to stay compatible with Xrandr | |
3020 | * while i915 HW rotation is clockwise, thats why this swapping. | |
3021 | */ | |
3b7a5119 | 3022 | case BIT(DRM_ROTATE_90): |
1e8df167 | 3023 | return PLANE_CTL_ROTATE_270; |
3b7a5119 | 3024 | case BIT(DRM_ROTATE_180): |
c34ce3d1 | 3025 | return PLANE_CTL_ROTATE_180; |
3b7a5119 | 3026 | case BIT(DRM_ROTATE_270): |
1e8df167 | 3027 | return PLANE_CTL_ROTATE_90; |
6156a456 CK |
3028 | default: |
3029 | MISSING_CASE(rotation); | |
3030 | } | |
3031 | ||
c34ce3d1 | 3032 | return 0; |
6156a456 CK |
3033 | } |
3034 | ||
3035 | static void skylake_update_primary_plane(struct drm_crtc *crtc, | |
3036 | struct drm_framebuffer *fb, | |
3037 | int x, int y) | |
3038 | { | |
3039 | struct drm_device *dev = crtc->dev; | |
3040 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3041 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
b70709a6 ML |
3042 | struct drm_plane *plane = crtc->primary; |
3043 | bool visible = to_intel_plane_state(plane->state)->visible; | |
6156a456 CK |
3044 | struct drm_i915_gem_object *obj; |
3045 | int pipe = intel_crtc->pipe; | |
3046 | u32 plane_ctl, stride_div, stride; | |
3047 | u32 tile_height, plane_offset, plane_size; | |
3048 | unsigned int rotation; | |
3049 | int x_offset, y_offset; | |
3050 | unsigned long surf_addr; | |
6156a456 CK |
3051 | struct intel_crtc_state *crtc_state = intel_crtc->config; |
3052 | struct intel_plane_state *plane_state; | |
3053 | int src_x = 0, src_y = 0, src_w = 0, src_h = 0; | |
3054 | int dst_x = 0, dst_y = 0, dst_w = 0, dst_h = 0; | |
3055 | int scaler_id = -1; | |
3056 | ||
6156a456 CK |
3057 | plane_state = to_intel_plane_state(plane->state); |
3058 | ||
b70709a6 | 3059 | if (!visible || !fb) { |
6156a456 CK |
3060 | I915_WRITE(PLANE_CTL(pipe, 0), 0); |
3061 | I915_WRITE(PLANE_SURF(pipe, 0), 0); | |
3062 | POSTING_READ(PLANE_CTL(pipe, 0)); | |
3063 | return; | |
3b7a5119 | 3064 | } |
70d21f0e | 3065 | |
6156a456 CK |
3066 | plane_ctl = PLANE_CTL_ENABLE | |
3067 | PLANE_CTL_PIPE_GAMMA_ENABLE | | |
3068 | PLANE_CTL_PIPE_CSC_ENABLE; | |
3069 | ||
3070 | plane_ctl |= skl_plane_ctl_format(fb->pixel_format); | |
3071 | plane_ctl |= skl_plane_ctl_tiling(fb->modifier[0]); | |
3072 | plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE; | |
3073 | ||
3074 | rotation = plane->state->rotation; | |
3075 | plane_ctl |= skl_plane_ctl_rotation(rotation); | |
3076 | ||
b321803d DL |
3077 | obj = intel_fb_obj(fb); |
3078 | stride_div = intel_fb_stride_alignment(dev, fb->modifier[0], | |
3079 | fb->pixel_format); | |
3b7a5119 SJ |
3080 | surf_addr = intel_plane_obj_offset(to_intel_plane(plane), obj); |
3081 | ||
6156a456 CK |
3082 | /* |
3083 | * FIXME: intel_plane_state->src, dst aren't set when transitional | |
3084 | * update_plane helpers are called from legacy paths. | |
3085 | * Once full atomic crtc is available, below check can be avoided. | |
3086 | */ | |
3087 | if (drm_rect_width(&plane_state->src)) { | |
3088 | scaler_id = plane_state->scaler_id; | |
3089 | src_x = plane_state->src.x1 >> 16; | |
3090 | src_y = plane_state->src.y1 >> 16; | |
3091 | src_w = drm_rect_width(&plane_state->src) >> 16; | |
3092 | src_h = drm_rect_height(&plane_state->src) >> 16; | |
3093 | dst_x = plane_state->dst.x1; | |
3094 | dst_y = plane_state->dst.y1; | |
3095 | dst_w = drm_rect_width(&plane_state->dst); | |
3096 | dst_h = drm_rect_height(&plane_state->dst); | |
3097 | ||
3098 | WARN_ON(x != src_x || y != src_y); | |
3099 | } else { | |
3100 | src_w = intel_crtc->config->pipe_src_w; | |
3101 | src_h = intel_crtc->config->pipe_src_h; | |
3102 | } | |
3103 | ||
3b7a5119 SJ |
3104 | if (intel_rotation_90_or_270(rotation)) { |
3105 | /* stride = Surface height in tiles */ | |
2614f17d | 3106 | tile_height = intel_tile_height(dev, fb->pixel_format, |
3b7a5119 SJ |
3107 | fb->modifier[0]); |
3108 | stride = DIV_ROUND_UP(fb->height, tile_height); | |
6156a456 | 3109 | x_offset = stride * tile_height - y - src_h; |
3b7a5119 | 3110 | y_offset = x; |
6156a456 | 3111 | plane_size = (src_w - 1) << 16 | (src_h - 1); |
3b7a5119 SJ |
3112 | } else { |
3113 | stride = fb->pitches[0] / stride_div; | |
3114 | x_offset = x; | |
3115 | y_offset = y; | |
6156a456 | 3116 | plane_size = (src_h - 1) << 16 | (src_w - 1); |
3b7a5119 SJ |
3117 | } |
3118 | plane_offset = y_offset << 16 | x_offset; | |
b321803d | 3119 | |
70d21f0e | 3120 | I915_WRITE(PLANE_CTL(pipe, 0), plane_ctl); |
3b7a5119 SJ |
3121 | I915_WRITE(PLANE_OFFSET(pipe, 0), plane_offset); |
3122 | I915_WRITE(PLANE_SIZE(pipe, 0), plane_size); | |
3123 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); | |
6156a456 CK |
3124 | |
3125 | if (scaler_id >= 0) { | |
3126 | uint32_t ps_ctrl = 0; | |
3127 | ||
3128 | WARN_ON(!dst_w || !dst_h); | |
3129 | ps_ctrl = PS_SCALER_EN | PS_PLANE_SEL(0) | | |
3130 | crtc_state->scaler_state.scalers[scaler_id].mode; | |
3131 | I915_WRITE(SKL_PS_CTRL(pipe, scaler_id), ps_ctrl); | |
3132 | I915_WRITE(SKL_PS_PWR_GATE(pipe, scaler_id), 0); | |
3133 | I915_WRITE(SKL_PS_WIN_POS(pipe, scaler_id), (dst_x << 16) | dst_y); | |
3134 | I915_WRITE(SKL_PS_WIN_SZ(pipe, scaler_id), (dst_w << 16) | dst_h); | |
3135 | I915_WRITE(PLANE_POS(pipe, 0), 0); | |
3136 | } else { | |
3137 | I915_WRITE(PLANE_POS(pipe, 0), (dst_y << 16) | dst_x); | |
3138 | } | |
3139 | ||
121920fa | 3140 | I915_WRITE(PLANE_SURF(pipe, 0), surf_addr); |
70d21f0e DL |
3141 | |
3142 | POSTING_READ(PLANE_SURF(pipe, 0)); | |
3143 | } | |
3144 | ||
17638cd6 JB |
3145 | /* Assume fb object is pinned & idle & fenced and just update base pointers */ |
3146 | static int | |
3147 | intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, | |
3148 | int x, int y, enum mode_set_atomic state) | |
3149 | { | |
3150 | struct drm_device *dev = crtc->dev; | |
3151 | struct drm_i915_private *dev_priv = dev->dev_private; | |
17638cd6 | 3152 | |
6b8e6ed0 CW |
3153 | if (dev_priv->display.disable_fbc) |
3154 | dev_priv->display.disable_fbc(dev); | |
81255565 | 3155 | |
29b9bde6 DV |
3156 | dev_priv->display.update_primary_plane(crtc, fb, x, y); |
3157 | ||
3158 | return 0; | |
81255565 JB |
3159 | } |
3160 | ||
7514747d | 3161 | static void intel_complete_page_flips(struct drm_device *dev) |
96a02917 | 3162 | { |
96a02917 VS |
3163 | struct drm_crtc *crtc; |
3164 | ||
70e1e0ec | 3165 | for_each_crtc(dev, crtc) { |
96a02917 VS |
3166 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
3167 | enum plane plane = intel_crtc->plane; | |
3168 | ||
3169 | intel_prepare_page_flip(dev, plane); | |
3170 | intel_finish_page_flip_plane(dev, plane); | |
3171 | } | |
7514747d VS |
3172 | } |
3173 | ||
3174 | static void intel_update_primary_planes(struct drm_device *dev) | |
3175 | { | |
3176 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3177 | struct drm_crtc *crtc; | |
96a02917 | 3178 | |
70e1e0ec | 3179 | for_each_crtc(dev, crtc) { |
96a02917 VS |
3180 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
3181 | ||
51fd371b | 3182 | drm_modeset_lock(&crtc->mutex, NULL); |
947fdaad CW |
3183 | /* |
3184 | * FIXME: Once we have proper support for primary planes (and | |
3185 | * disabling them without disabling the entire crtc) allow again | |
66e514c1 | 3186 | * a NULL crtc->primary->fb. |
947fdaad | 3187 | */ |
f4510a27 | 3188 | if (intel_crtc->active && crtc->primary->fb) |
262ca2b0 | 3189 | dev_priv->display.update_primary_plane(crtc, |
66e514c1 | 3190 | crtc->primary->fb, |
262ca2b0 MR |
3191 | crtc->x, |
3192 | crtc->y); | |
51fd371b | 3193 | drm_modeset_unlock(&crtc->mutex); |
96a02917 VS |
3194 | } |
3195 | } | |
3196 | ||
7514747d VS |
3197 | void intel_prepare_reset(struct drm_device *dev) |
3198 | { | |
3199 | /* no reset support for gen2 */ | |
3200 | if (IS_GEN2(dev)) | |
3201 | return; | |
3202 | ||
3203 | /* reset doesn't touch the display */ | |
3204 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) | |
3205 | return; | |
3206 | ||
3207 | drm_modeset_lock_all(dev); | |
f98ce92f VS |
3208 | /* |
3209 | * Disabling the crtcs gracefully seems nicer. Also the | |
3210 | * g33 docs say we should at least disable all the planes. | |
3211 | */ | |
6b72d486 | 3212 | intel_display_suspend(dev); |
7514747d VS |
3213 | } |
3214 | ||
3215 | void intel_finish_reset(struct drm_device *dev) | |
3216 | { | |
3217 | struct drm_i915_private *dev_priv = to_i915(dev); | |
3218 | ||
3219 | /* | |
3220 | * Flips in the rings will be nuked by the reset, | |
3221 | * so complete all pending flips so that user space | |
3222 | * will get its events and not get stuck. | |
3223 | */ | |
3224 | intel_complete_page_flips(dev); | |
3225 | ||
3226 | /* no reset support for gen2 */ | |
3227 | if (IS_GEN2(dev)) | |
3228 | return; | |
3229 | ||
3230 | /* reset doesn't touch the display */ | |
3231 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) { | |
3232 | /* | |
3233 | * Flips in the rings have been nuked by the reset, | |
3234 | * so update the base address of all primary | |
3235 | * planes to the the last fb to make sure we're | |
3236 | * showing the correct fb after a reset. | |
3237 | */ | |
3238 | intel_update_primary_planes(dev); | |
3239 | return; | |
3240 | } | |
3241 | ||
3242 | /* | |
3243 | * The display has been reset as well, | |
3244 | * so need a full re-initialization. | |
3245 | */ | |
3246 | intel_runtime_pm_disable_interrupts(dev_priv); | |
3247 | intel_runtime_pm_enable_interrupts(dev_priv); | |
3248 | ||
3249 | intel_modeset_init_hw(dev); | |
3250 | ||
3251 | spin_lock_irq(&dev_priv->irq_lock); | |
3252 | if (dev_priv->display.hpd_irq_setup) | |
3253 | dev_priv->display.hpd_irq_setup(dev); | |
3254 | spin_unlock_irq(&dev_priv->irq_lock); | |
3255 | ||
3256 | intel_modeset_setup_hw_state(dev, true); | |
3257 | ||
3258 | intel_hpd_init(dev_priv); | |
3259 | ||
3260 | drm_modeset_unlock_all(dev); | |
3261 | } | |
3262 | ||
2e2f351d | 3263 | static void |
14667a4b CW |
3264 | intel_finish_fb(struct drm_framebuffer *old_fb) |
3265 | { | |
2ff8fde1 | 3266 | struct drm_i915_gem_object *obj = intel_fb_obj(old_fb); |
2e2f351d | 3267 | struct drm_i915_private *dev_priv = to_i915(obj->base.dev); |
14667a4b CW |
3268 | bool was_interruptible = dev_priv->mm.interruptible; |
3269 | int ret; | |
3270 | ||
14667a4b CW |
3271 | /* Big Hammer, we also need to ensure that any pending |
3272 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the | |
3273 | * current scanout is retired before unpinning the old | |
2e2f351d CW |
3274 | * framebuffer. Note that we rely on userspace rendering |
3275 | * into the buffer attached to the pipe they are waiting | |
3276 | * on. If not, userspace generates a GPU hang with IPEHR | |
3277 | * point to the MI_WAIT_FOR_EVENT. | |
14667a4b CW |
3278 | * |
3279 | * This should only fail upon a hung GPU, in which case we | |
3280 | * can safely continue. | |
3281 | */ | |
3282 | dev_priv->mm.interruptible = false; | |
2e2f351d | 3283 | ret = i915_gem_object_wait_rendering(obj, true); |
14667a4b CW |
3284 | dev_priv->mm.interruptible = was_interruptible; |
3285 | ||
2e2f351d | 3286 | WARN_ON(ret); |
14667a4b CW |
3287 | } |
3288 | ||
7d5e3799 CW |
3289 | static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) |
3290 | { | |
3291 | struct drm_device *dev = crtc->dev; | |
3292 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3293 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
7d5e3799 CW |
3294 | bool pending; |
3295 | ||
3296 | if (i915_reset_in_progress(&dev_priv->gpu_error) || | |
3297 | intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) | |
3298 | return false; | |
3299 | ||
5e2d7afc | 3300 | spin_lock_irq(&dev->event_lock); |
7d5e3799 | 3301 | pending = to_intel_crtc(crtc)->unpin_work != NULL; |
5e2d7afc | 3302 | spin_unlock_irq(&dev->event_lock); |
7d5e3799 CW |
3303 | |
3304 | return pending; | |
3305 | } | |
3306 | ||
e30e8f75 GP |
3307 | static void intel_update_pipe_size(struct intel_crtc *crtc) |
3308 | { | |
3309 | struct drm_device *dev = crtc->base.dev; | |
3310 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3311 | const struct drm_display_mode *adjusted_mode; | |
3312 | ||
3313 | if (!i915.fastboot) | |
3314 | return; | |
3315 | ||
3316 | /* | |
3317 | * Update pipe size and adjust fitter if needed: the reason for this is | |
3318 | * that in compute_mode_changes we check the native mode (not the pfit | |
3319 | * mode) to see if we can flip rather than do a full mode set. In the | |
3320 | * fastboot case, we'll flip, but if we don't update the pipesrc and | |
3321 | * pfit state, we'll end up with a big fb scanned out into the wrong | |
3322 | * sized surface. | |
3323 | * | |
3324 | * To fix this properly, we need to hoist the checks up into | |
3325 | * compute_mode_changes (or above), check the actual pfit state and | |
3326 | * whether the platform allows pfit disable with pipe active, and only | |
3327 | * then update the pipesrc and pfit state, even on the flip path. | |
3328 | */ | |
3329 | ||
6e3c9717 | 3330 | adjusted_mode = &crtc->config->base.adjusted_mode; |
e30e8f75 GP |
3331 | |
3332 | I915_WRITE(PIPESRC(crtc->pipe), | |
3333 | ((adjusted_mode->crtc_hdisplay - 1) << 16) | | |
3334 | (adjusted_mode->crtc_vdisplay - 1)); | |
6e3c9717 | 3335 | if (!crtc->config->pch_pfit.enabled && |
409ee761 ACO |
3336 | (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) || |
3337 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) { | |
e30e8f75 GP |
3338 | I915_WRITE(PF_CTL(crtc->pipe), 0); |
3339 | I915_WRITE(PF_WIN_POS(crtc->pipe), 0); | |
3340 | I915_WRITE(PF_WIN_SZ(crtc->pipe), 0); | |
3341 | } | |
6e3c9717 ACO |
3342 | crtc->config->pipe_src_w = adjusted_mode->crtc_hdisplay; |
3343 | crtc->config->pipe_src_h = adjusted_mode->crtc_vdisplay; | |
e30e8f75 GP |
3344 | } |
3345 | ||
5e84e1a4 ZW |
3346 | static void intel_fdi_normal_train(struct drm_crtc *crtc) |
3347 | { | |
3348 | struct drm_device *dev = crtc->dev; | |
3349 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3350 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3351 | int pipe = intel_crtc->pipe; | |
3352 | u32 reg, temp; | |
3353 | ||
3354 | /* enable normal train */ | |
3355 | reg = FDI_TX_CTL(pipe); | |
3356 | temp = I915_READ(reg); | |
61e499bf | 3357 | if (IS_IVYBRIDGE(dev)) { |
357555c0 JB |
3358 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
3359 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; | |
61e499bf KP |
3360 | } else { |
3361 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3362 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; | |
357555c0 | 3363 | } |
5e84e1a4 ZW |
3364 | I915_WRITE(reg, temp); |
3365 | ||
3366 | reg = FDI_RX_CTL(pipe); | |
3367 | temp = I915_READ(reg); | |
3368 | if (HAS_PCH_CPT(dev)) { | |
3369 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3370 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; | |
3371 | } else { | |
3372 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3373 | temp |= FDI_LINK_TRAIN_NONE; | |
3374 | } | |
3375 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); | |
3376 | ||
3377 | /* wait one idle pattern time */ | |
3378 | POSTING_READ(reg); | |
3379 | udelay(1000); | |
357555c0 JB |
3380 | |
3381 | /* IVB wants error correction enabled */ | |
3382 | if (IS_IVYBRIDGE(dev)) | |
3383 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | | |
3384 | FDI_FE_ERRC_ENABLE); | |
5e84e1a4 ZW |
3385 | } |
3386 | ||
8db9d77b ZW |
3387 | /* The FDI link training functions for ILK/Ibexpeak. */ |
3388 | static void ironlake_fdi_link_train(struct drm_crtc *crtc) | |
3389 | { | |
3390 | struct drm_device *dev = crtc->dev; | |
3391 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3392 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3393 | int pipe = intel_crtc->pipe; | |
5eddb70b | 3394 | u32 reg, temp, tries; |
8db9d77b | 3395 | |
1c8562f6 | 3396 | /* FDI needs bits from pipe first */ |
0fc932b8 | 3397 | assert_pipe_enabled(dev_priv, pipe); |
0fc932b8 | 3398 | |
e1a44743 AJ |
3399 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
3400 | for train result */ | |
5eddb70b CW |
3401 | reg = FDI_RX_IMR(pipe); |
3402 | temp = I915_READ(reg); | |
e1a44743 AJ |
3403 | temp &= ~FDI_RX_SYMBOL_LOCK; |
3404 | temp &= ~FDI_RX_BIT_LOCK; | |
5eddb70b CW |
3405 | I915_WRITE(reg, temp); |
3406 | I915_READ(reg); | |
e1a44743 AJ |
3407 | udelay(150); |
3408 | ||
8db9d77b | 3409 | /* enable CPU FDI TX and PCH FDI RX */ |
5eddb70b CW |
3410 | reg = FDI_TX_CTL(pipe); |
3411 | temp = I915_READ(reg); | |
627eb5a3 | 3412 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
6e3c9717 | 3413 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
8db9d77b ZW |
3414 | temp &= ~FDI_LINK_TRAIN_NONE; |
3415 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
5eddb70b | 3416 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
8db9d77b | 3417 | |
5eddb70b CW |
3418 | reg = FDI_RX_CTL(pipe); |
3419 | temp = I915_READ(reg); | |
8db9d77b ZW |
3420 | temp &= ~FDI_LINK_TRAIN_NONE; |
3421 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
5eddb70b CW |
3422 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
3423 | ||
3424 | POSTING_READ(reg); | |
8db9d77b ZW |
3425 | udelay(150); |
3426 | ||
5b2adf89 | 3427 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
8f5718a6 DV |
3428 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
3429 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | | |
3430 | FDI_RX_PHASE_SYNC_POINTER_EN); | |
5b2adf89 | 3431 | |
5eddb70b | 3432 | reg = FDI_RX_IIR(pipe); |
e1a44743 | 3433 | for (tries = 0; tries < 5; tries++) { |
5eddb70b | 3434 | temp = I915_READ(reg); |
8db9d77b ZW |
3435 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
3436 | ||
3437 | if ((temp & FDI_RX_BIT_LOCK)) { | |
3438 | DRM_DEBUG_KMS("FDI train 1 done.\n"); | |
5eddb70b | 3439 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
8db9d77b ZW |
3440 | break; |
3441 | } | |
8db9d77b | 3442 | } |
e1a44743 | 3443 | if (tries == 5) |
5eddb70b | 3444 | DRM_ERROR("FDI train 1 fail!\n"); |
8db9d77b ZW |
3445 | |
3446 | /* Train 2 */ | |
5eddb70b CW |
3447 | reg = FDI_TX_CTL(pipe); |
3448 | temp = I915_READ(reg); | |
8db9d77b ZW |
3449 | temp &= ~FDI_LINK_TRAIN_NONE; |
3450 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
5eddb70b | 3451 | I915_WRITE(reg, temp); |
8db9d77b | 3452 | |
5eddb70b CW |
3453 | reg = FDI_RX_CTL(pipe); |
3454 | temp = I915_READ(reg); | |
8db9d77b ZW |
3455 | temp &= ~FDI_LINK_TRAIN_NONE; |
3456 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
5eddb70b | 3457 | I915_WRITE(reg, temp); |
8db9d77b | 3458 | |
5eddb70b CW |
3459 | POSTING_READ(reg); |
3460 | udelay(150); | |
8db9d77b | 3461 | |
5eddb70b | 3462 | reg = FDI_RX_IIR(pipe); |
e1a44743 | 3463 | for (tries = 0; tries < 5; tries++) { |
5eddb70b | 3464 | temp = I915_READ(reg); |
8db9d77b ZW |
3465 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
3466 | ||
3467 | if (temp & FDI_RX_SYMBOL_LOCK) { | |
5eddb70b | 3468 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
8db9d77b ZW |
3469 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
3470 | break; | |
3471 | } | |
8db9d77b | 3472 | } |
e1a44743 | 3473 | if (tries == 5) |
5eddb70b | 3474 | DRM_ERROR("FDI train 2 fail!\n"); |
8db9d77b ZW |
3475 | |
3476 | DRM_DEBUG_KMS("FDI train done\n"); | |
5c5313c8 | 3477 | |
8db9d77b ZW |
3478 | } |
3479 | ||
0206e353 | 3480 | static const int snb_b_fdi_train_param[] = { |
8db9d77b ZW |
3481 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
3482 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, | |
3483 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, | |
3484 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, | |
3485 | }; | |
3486 | ||
3487 | /* The FDI link training functions for SNB/Cougarpoint. */ | |
3488 | static void gen6_fdi_link_train(struct drm_crtc *crtc) | |
3489 | { | |
3490 | struct drm_device *dev = crtc->dev; | |
3491 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3492 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3493 | int pipe = intel_crtc->pipe; | |
fa37d39e | 3494 | u32 reg, temp, i, retry; |
8db9d77b | 3495 | |
e1a44743 AJ |
3496 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
3497 | for train result */ | |
5eddb70b CW |
3498 | reg = FDI_RX_IMR(pipe); |
3499 | temp = I915_READ(reg); | |
e1a44743 AJ |
3500 | temp &= ~FDI_RX_SYMBOL_LOCK; |
3501 | temp &= ~FDI_RX_BIT_LOCK; | |
5eddb70b CW |
3502 | I915_WRITE(reg, temp); |
3503 | ||
3504 | POSTING_READ(reg); | |
e1a44743 AJ |
3505 | udelay(150); |
3506 | ||
8db9d77b | 3507 | /* enable CPU FDI TX and PCH FDI RX */ |
5eddb70b CW |
3508 | reg = FDI_TX_CTL(pipe); |
3509 | temp = I915_READ(reg); | |
627eb5a3 | 3510 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
6e3c9717 | 3511 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
8db9d77b ZW |
3512 | temp &= ~FDI_LINK_TRAIN_NONE; |
3513 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3514 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; | |
3515 | /* SNB-B */ | |
3516 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; | |
5eddb70b | 3517 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
8db9d77b | 3518 | |
d74cf324 DV |
3519 | I915_WRITE(FDI_RX_MISC(pipe), |
3520 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); | |
3521 | ||
5eddb70b CW |
3522 | reg = FDI_RX_CTL(pipe); |
3523 | temp = I915_READ(reg); | |
8db9d77b ZW |
3524 | if (HAS_PCH_CPT(dev)) { |
3525 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3526 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; | |
3527 | } else { | |
3528 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3529 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3530 | } | |
5eddb70b CW |
3531 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
3532 | ||
3533 | POSTING_READ(reg); | |
8db9d77b ZW |
3534 | udelay(150); |
3535 | ||
0206e353 | 3536 | for (i = 0; i < 4; i++) { |
5eddb70b CW |
3537 | reg = FDI_TX_CTL(pipe); |
3538 | temp = I915_READ(reg); | |
8db9d77b ZW |
3539 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
3540 | temp |= snb_b_fdi_train_param[i]; | |
5eddb70b CW |
3541 | I915_WRITE(reg, temp); |
3542 | ||
3543 | POSTING_READ(reg); | |
8db9d77b ZW |
3544 | udelay(500); |
3545 | ||
fa37d39e SP |
3546 | for (retry = 0; retry < 5; retry++) { |
3547 | reg = FDI_RX_IIR(pipe); | |
3548 | temp = I915_READ(reg); | |
3549 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
3550 | if (temp & FDI_RX_BIT_LOCK) { | |
3551 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); | |
3552 | DRM_DEBUG_KMS("FDI train 1 done.\n"); | |
3553 | break; | |
3554 | } | |
3555 | udelay(50); | |
8db9d77b | 3556 | } |
fa37d39e SP |
3557 | if (retry < 5) |
3558 | break; | |
8db9d77b ZW |
3559 | } |
3560 | if (i == 4) | |
5eddb70b | 3561 | DRM_ERROR("FDI train 1 fail!\n"); |
8db9d77b ZW |
3562 | |
3563 | /* Train 2 */ | |
5eddb70b CW |
3564 | reg = FDI_TX_CTL(pipe); |
3565 | temp = I915_READ(reg); | |
8db9d77b ZW |
3566 | temp &= ~FDI_LINK_TRAIN_NONE; |
3567 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
3568 | if (IS_GEN6(dev)) { | |
3569 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; | |
3570 | /* SNB-B */ | |
3571 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; | |
3572 | } | |
5eddb70b | 3573 | I915_WRITE(reg, temp); |
8db9d77b | 3574 | |
5eddb70b CW |
3575 | reg = FDI_RX_CTL(pipe); |
3576 | temp = I915_READ(reg); | |
8db9d77b ZW |
3577 | if (HAS_PCH_CPT(dev)) { |
3578 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3579 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; | |
3580 | } else { | |
3581 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3582 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
3583 | } | |
5eddb70b CW |
3584 | I915_WRITE(reg, temp); |
3585 | ||
3586 | POSTING_READ(reg); | |
8db9d77b ZW |
3587 | udelay(150); |
3588 | ||
0206e353 | 3589 | for (i = 0; i < 4; i++) { |
5eddb70b CW |
3590 | reg = FDI_TX_CTL(pipe); |
3591 | temp = I915_READ(reg); | |
8db9d77b ZW |
3592 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
3593 | temp |= snb_b_fdi_train_param[i]; | |
5eddb70b CW |
3594 | I915_WRITE(reg, temp); |
3595 | ||
3596 | POSTING_READ(reg); | |
8db9d77b ZW |
3597 | udelay(500); |
3598 | ||
fa37d39e SP |
3599 | for (retry = 0; retry < 5; retry++) { |
3600 | reg = FDI_RX_IIR(pipe); | |
3601 | temp = I915_READ(reg); | |
3602 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
3603 | if (temp & FDI_RX_SYMBOL_LOCK) { | |
3604 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); | |
3605 | DRM_DEBUG_KMS("FDI train 2 done.\n"); | |
3606 | break; | |
3607 | } | |
3608 | udelay(50); | |
8db9d77b | 3609 | } |
fa37d39e SP |
3610 | if (retry < 5) |
3611 | break; | |
8db9d77b ZW |
3612 | } |
3613 | if (i == 4) | |
5eddb70b | 3614 | DRM_ERROR("FDI train 2 fail!\n"); |
8db9d77b ZW |
3615 | |
3616 | DRM_DEBUG_KMS("FDI train done.\n"); | |
3617 | } | |
3618 | ||
357555c0 JB |
3619 | /* Manual link training for Ivy Bridge A0 parts */ |
3620 | static void ivb_manual_fdi_link_train(struct drm_crtc *crtc) | |
3621 | { | |
3622 | struct drm_device *dev = crtc->dev; | |
3623 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3624 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3625 | int pipe = intel_crtc->pipe; | |
139ccd3f | 3626 | u32 reg, temp, i, j; |
357555c0 JB |
3627 | |
3628 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit | |
3629 | for train result */ | |
3630 | reg = FDI_RX_IMR(pipe); | |
3631 | temp = I915_READ(reg); | |
3632 | temp &= ~FDI_RX_SYMBOL_LOCK; | |
3633 | temp &= ~FDI_RX_BIT_LOCK; | |
3634 | I915_WRITE(reg, temp); | |
3635 | ||
3636 | POSTING_READ(reg); | |
3637 | udelay(150); | |
3638 | ||
01a415fd DV |
3639 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
3640 | I915_READ(FDI_RX_IIR(pipe))); | |
3641 | ||
139ccd3f JB |
3642 | /* Try each vswing and preemphasis setting twice before moving on */ |
3643 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { | |
3644 | /* disable first in case we need to retry */ | |
3645 | reg = FDI_TX_CTL(pipe); | |
3646 | temp = I915_READ(reg); | |
3647 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); | |
3648 | temp &= ~FDI_TX_ENABLE; | |
3649 | I915_WRITE(reg, temp); | |
357555c0 | 3650 | |
139ccd3f JB |
3651 | reg = FDI_RX_CTL(pipe); |
3652 | temp = I915_READ(reg); | |
3653 | temp &= ~FDI_LINK_TRAIN_AUTO; | |
3654 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3655 | temp &= ~FDI_RX_ENABLE; | |
3656 | I915_WRITE(reg, temp); | |
357555c0 | 3657 | |
139ccd3f | 3658 | /* enable CPU FDI TX and PCH FDI RX */ |
357555c0 JB |
3659 | reg = FDI_TX_CTL(pipe); |
3660 | temp = I915_READ(reg); | |
139ccd3f | 3661 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
6e3c9717 | 3662 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
139ccd3f | 3663 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
357555c0 | 3664 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
139ccd3f JB |
3665 | temp |= snb_b_fdi_train_param[j/2]; |
3666 | temp |= FDI_COMPOSITE_SYNC; | |
3667 | I915_WRITE(reg, temp | FDI_TX_ENABLE); | |
357555c0 | 3668 | |
139ccd3f JB |
3669 | I915_WRITE(FDI_RX_MISC(pipe), |
3670 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); | |
357555c0 | 3671 | |
139ccd3f | 3672 | reg = FDI_RX_CTL(pipe); |
357555c0 | 3673 | temp = I915_READ(reg); |
139ccd3f JB |
3674 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
3675 | temp |= FDI_COMPOSITE_SYNC; | |
3676 | I915_WRITE(reg, temp | FDI_RX_ENABLE); | |
357555c0 | 3677 | |
139ccd3f JB |
3678 | POSTING_READ(reg); |
3679 | udelay(1); /* should be 0.5us */ | |
357555c0 | 3680 | |
139ccd3f JB |
3681 | for (i = 0; i < 4; i++) { |
3682 | reg = FDI_RX_IIR(pipe); | |
3683 | temp = I915_READ(reg); | |
3684 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
357555c0 | 3685 | |
139ccd3f JB |
3686 | if (temp & FDI_RX_BIT_LOCK || |
3687 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { | |
3688 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); | |
3689 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", | |
3690 | i); | |
3691 | break; | |
3692 | } | |
3693 | udelay(1); /* should be 0.5us */ | |
3694 | } | |
3695 | if (i == 4) { | |
3696 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); | |
3697 | continue; | |
3698 | } | |
357555c0 | 3699 | |
139ccd3f | 3700 | /* Train 2 */ |
357555c0 JB |
3701 | reg = FDI_TX_CTL(pipe); |
3702 | temp = I915_READ(reg); | |
139ccd3f JB |
3703 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
3704 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; | |
3705 | I915_WRITE(reg, temp); | |
3706 | ||
3707 | reg = FDI_RX_CTL(pipe); | |
3708 | temp = I915_READ(reg); | |
3709 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3710 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; | |
357555c0 JB |
3711 | I915_WRITE(reg, temp); |
3712 | ||
3713 | POSTING_READ(reg); | |
139ccd3f | 3714 | udelay(2); /* should be 1.5us */ |
357555c0 | 3715 | |
139ccd3f JB |
3716 | for (i = 0; i < 4; i++) { |
3717 | reg = FDI_RX_IIR(pipe); | |
3718 | temp = I915_READ(reg); | |
3719 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
357555c0 | 3720 | |
139ccd3f JB |
3721 | if (temp & FDI_RX_SYMBOL_LOCK || |
3722 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { | |
3723 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); | |
3724 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", | |
3725 | i); | |
3726 | goto train_done; | |
3727 | } | |
3728 | udelay(2); /* should be 1.5us */ | |
357555c0 | 3729 | } |
139ccd3f JB |
3730 | if (i == 4) |
3731 | DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2); | |
357555c0 | 3732 | } |
357555c0 | 3733 | |
139ccd3f | 3734 | train_done: |
357555c0 JB |
3735 | DRM_DEBUG_KMS("FDI train done.\n"); |
3736 | } | |
3737 | ||
88cefb6c | 3738 | static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc) |
2c07245f | 3739 | { |
88cefb6c | 3740 | struct drm_device *dev = intel_crtc->base.dev; |
2c07245f | 3741 | struct drm_i915_private *dev_priv = dev->dev_private; |
2c07245f | 3742 | int pipe = intel_crtc->pipe; |
5eddb70b | 3743 | u32 reg, temp; |
79e53945 | 3744 | |
c64e311e | 3745 | |
c98e9dcf | 3746 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
5eddb70b CW |
3747 | reg = FDI_RX_CTL(pipe); |
3748 | temp = I915_READ(reg); | |
627eb5a3 | 3749 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
6e3c9717 | 3750 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
dfd07d72 | 3751 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
5eddb70b CW |
3752 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
3753 | ||
3754 | POSTING_READ(reg); | |
c98e9dcf JB |
3755 | udelay(200); |
3756 | ||
3757 | /* Switch from Rawclk to PCDclk */ | |
5eddb70b CW |
3758 | temp = I915_READ(reg); |
3759 | I915_WRITE(reg, temp | FDI_PCDCLK); | |
3760 | ||
3761 | POSTING_READ(reg); | |
c98e9dcf JB |
3762 | udelay(200); |
3763 | ||
20749730 PZ |
3764 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
3765 | reg = FDI_TX_CTL(pipe); | |
3766 | temp = I915_READ(reg); | |
3767 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { | |
3768 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); | |
5eddb70b | 3769 | |
20749730 PZ |
3770 | POSTING_READ(reg); |
3771 | udelay(100); | |
6be4a607 | 3772 | } |
0e23b99d JB |
3773 | } |
3774 | ||
88cefb6c DV |
3775 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
3776 | { | |
3777 | struct drm_device *dev = intel_crtc->base.dev; | |
3778 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3779 | int pipe = intel_crtc->pipe; | |
3780 | u32 reg, temp; | |
3781 | ||
3782 | /* Switch from PCDclk to Rawclk */ | |
3783 | reg = FDI_RX_CTL(pipe); | |
3784 | temp = I915_READ(reg); | |
3785 | I915_WRITE(reg, temp & ~FDI_PCDCLK); | |
3786 | ||
3787 | /* Disable CPU FDI TX PLL */ | |
3788 | reg = FDI_TX_CTL(pipe); | |
3789 | temp = I915_READ(reg); | |
3790 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); | |
3791 | ||
3792 | POSTING_READ(reg); | |
3793 | udelay(100); | |
3794 | ||
3795 | reg = FDI_RX_CTL(pipe); | |
3796 | temp = I915_READ(reg); | |
3797 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); | |
3798 | ||
3799 | /* Wait for the clocks to turn off. */ | |
3800 | POSTING_READ(reg); | |
3801 | udelay(100); | |
3802 | } | |
3803 | ||
0fc932b8 JB |
3804 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
3805 | { | |
3806 | struct drm_device *dev = crtc->dev; | |
3807 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3808 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3809 | int pipe = intel_crtc->pipe; | |
3810 | u32 reg, temp; | |
3811 | ||
3812 | /* disable CPU FDI tx and PCH FDI rx */ | |
3813 | reg = FDI_TX_CTL(pipe); | |
3814 | temp = I915_READ(reg); | |
3815 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); | |
3816 | POSTING_READ(reg); | |
3817 | ||
3818 | reg = FDI_RX_CTL(pipe); | |
3819 | temp = I915_READ(reg); | |
3820 | temp &= ~(0x7 << 16); | |
dfd07d72 | 3821 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
0fc932b8 JB |
3822 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
3823 | ||
3824 | POSTING_READ(reg); | |
3825 | udelay(100); | |
3826 | ||
3827 | /* Ironlake workaround, disable clock pointer after downing FDI */ | |
eba905b2 | 3828 | if (HAS_PCH_IBX(dev)) |
6f06ce18 | 3829 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
0fc932b8 JB |
3830 | |
3831 | /* still set train pattern 1 */ | |
3832 | reg = FDI_TX_CTL(pipe); | |
3833 | temp = I915_READ(reg); | |
3834 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3835 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3836 | I915_WRITE(reg, temp); | |
3837 | ||
3838 | reg = FDI_RX_CTL(pipe); | |
3839 | temp = I915_READ(reg); | |
3840 | if (HAS_PCH_CPT(dev)) { | |
3841 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3842 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; | |
3843 | } else { | |
3844 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3845 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3846 | } | |
3847 | /* BPC in FDI rx is consistent with that in PIPECONF */ | |
3848 | temp &= ~(0x07 << 16); | |
dfd07d72 | 3849 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
0fc932b8 JB |
3850 | I915_WRITE(reg, temp); |
3851 | ||
3852 | POSTING_READ(reg); | |
3853 | udelay(100); | |
3854 | } | |
3855 | ||
5dce5b93 CW |
3856 | bool intel_has_pending_fb_unpin(struct drm_device *dev) |
3857 | { | |
3858 | struct intel_crtc *crtc; | |
3859 | ||
3860 | /* Note that we don't need to be called with mode_config.lock here | |
3861 | * as our list of CRTC objects is static for the lifetime of the | |
3862 | * device and so cannot disappear as we iterate. Similarly, we can | |
3863 | * happily treat the predicates as racy, atomic checks as userspace | |
3864 | * cannot claim and pin a new fb without at least acquring the | |
3865 | * struct_mutex and so serialising with us. | |
3866 | */ | |
d3fcc808 | 3867 | for_each_intel_crtc(dev, crtc) { |
5dce5b93 CW |
3868 | if (atomic_read(&crtc->unpin_work_count) == 0) |
3869 | continue; | |
3870 | ||
3871 | if (crtc->unpin_work) | |
3872 | intel_wait_for_vblank(dev, crtc->pipe); | |
3873 | ||
3874 | return true; | |
3875 | } | |
3876 | ||
3877 | return false; | |
3878 | } | |
3879 | ||
d6bbafa1 CW |
3880 | static void page_flip_completed(struct intel_crtc *intel_crtc) |
3881 | { | |
3882 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); | |
3883 | struct intel_unpin_work *work = intel_crtc->unpin_work; | |
3884 | ||
3885 | /* ensure that the unpin work is consistent wrt ->pending. */ | |
3886 | smp_rmb(); | |
3887 | intel_crtc->unpin_work = NULL; | |
3888 | ||
3889 | if (work->event) | |
3890 | drm_send_vblank_event(intel_crtc->base.dev, | |
3891 | intel_crtc->pipe, | |
3892 | work->event); | |
3893 | ||
3894 | drm_crtc_vblank_put(&intel_crtc->base); | |
3895 | ||
3896 | wake_up_all(&dev_priv->pending_flip_queue); | |
3897 | queue_work(dev_priv->wq, &work->work); | |
3898 | ||
3899 | trace_i915_flip_complete(intel_crtc->plane, | |
3900 | work->pending_flip_obj); | |
3901 | } | |
3902 | ||
46a55d30 | 3903 | void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc) |
e6c3a2a6 | 3904 | { |
0f91128d | 3905 | struct drm_device *dev = crtc->dev; |
5bb61643 | 3906 | struct drm_i915_private *dev_priv = dev->dev_private; |
e6c3a2a6 | 3907 | |
2c10d571 | 3908 | WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue)); |
9c787942 CW |
3909 | if (WARN_ON(wait_event_timeout(dev_priv->pending_flip_queue, |
3910 | !intel_crtc_has_pending_flip(crtc), | |
3911 | 60*HZ) == 0)) { | |
3912 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
2c10d571 | 3913 | |
5e2d7afc | 3914 | spin_lock_irq(&dev->event_lock); |
9c787942 CW |
3915 | if (intel_crtc->unpin_work) { |
3916 | WARN_ONCE(1, "Removing stuck page flip\n"); | |
3917 | page_flip_completed(intel_crtc); | |
3918 | } | |
5e2d7afc | 3919 | spin_unlock_irq(&dev->event_lock); |
9c787942 | 3920 | } |
5bb61643 | 3921 | |
975d568a CW |
3922 | if (crtc->primary->fb) { |
3923 | mutex_lock(&dev->struct_mutex); | |
3924 | intel_finish_fb(crtc->primary->fb); | |
3925 | mutex_unlock(&dev->struct_mutex); | |
3926 | } | |
e6c3a2a6 CW |
3927 | } |
3928 | ||
e615efe4 ED |
3929 | /* Program iCLKIP clock to the desired frequency */ |
3930 | static void lpt_program_iclkip(struct drm_crtc *crtc) | |
3931 | { | |
3932 | struct drm_device *dev = crtc->dev; | |
3933 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6e3c9717 | 3934 | int clock = to_intel_crtc(crtc)->config->base.adjusted_mode.crtc_clock; |
e615efe4 ED |
3935 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
3936 | u32 temp; | |
3937 | ||
a580516d | 3938 | mutex_lock(&dev_priv->sb_lock); |
09153000 | 3939 | |
e615efe4 ED |
3940 | /* It is necessary to ungate the pixclk gate prior to programming |
3941 | * the divisors, and gate it back when it is done. | |
3942 | */ | |
3943 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); | |
3944 | ||
3945 | /* Disable SSCCTL */ | |
3946 | intel_sbi_write(dev_priv, SBI_SSCCTL6, | |
988d6ee8 PZ |
3947 | intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) | |
3948 | SBI_SSCCTL_DISABLE, | |
3949 | SBI_ICLK); | |
e615efe4 ED |
3950 | |
3951 | /* 20MHz is a corner case which is out of range for the 7-bit divisor */ | |
12d7ceed | 3952 | if (clock == 20000) { |
e615efe4 ED |
3953 | auxdiv = 1; |
3954 | divsel = 0x41; | |
3955 | phaseinc = 0x20; | |
3956 | } else { | |
3957 | /* The iCLK virtual clock root frequency is in MHz, | |
241bfc38 DL |
3958 | * but the adjusted_mode->crtc_clock in in KHz. To get the |
3959 | * divisors, it is necessary to divide one by another, so we | |
e615efe4 ED |
3960 | * convert the virtual clock precision to KHz here for higher |
3961 | * precision. | |
3962 | */ | |
3963 | u32 iclk_virtual_root_freq = 172800 * 1000; | |
3964 | u32 iclk_pi_range = 64; | |
3965 | u32 desired_divisor, msb_divisor_value, pi_value; | |
3966 | ||
12d7ceed | 3967 | desired_divisor = (iclk_virtual_root_freq / clock); |
e615efe4 ED |
3968 | msb_divisor_value = desired_divisor / iclk_pi_range; |
3969 | pi_value = desired_divisor % iclk_pi_range; | |
3970 | ||
3971 | auxdiv = 0; | |
3972 | divsel = msb_divisor_value - 2; | |
3973 | phaseinc = pi_value; | |
3974 | } | |
3975 | ||
3976 | /* This should not happen with any sane values */ | |
3977 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & | |
3978 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); | |
3979 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & | |
3980 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); | |
3981 | ||
3982 | DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n", | |
12d7ceed | 3983 | clock, |
e615efe4 ED |
3984 | auxdiv, |
3985 | divsel, | |
3986 | phasedir, | |
3987 | phaseinc); | |
3988 | ||
3989 | /* Program SSCDIVINTPHASE6 */ | |
988d6ee8 | 3990 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
e615efe4 ED |
3991 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
3992 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); | |
3993 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; | |
3994 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); | |
3995 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); | |
3996 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; | |
988d6ee8 | 3997 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
e615efe4 ED |
3998 | |
3999 | /* Program SSCAUXDIV */ | |
988d6ee8 | 4000 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
e615efe4 ED |
4001 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
4002 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); | |
988d6ee8 | 4003 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
e615efe4 ED |
4004 | |
4005 | /* Enable modulator and associated divider */ | |
988d6ee8 | 4006 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
e615efe4 | 4007 | temp &= ~SBI_SSCCTL_DISABLE; |
988d6ee8 | 4008 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
e615efe4 ED |
4009 | |
4010 | /* Wait for initialization time */ | |
4011 | udelay(24); | |
4012 | ||
4013 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); | |
09153000 | 4014 | |
a580516d | 4015 | mutex_unlock(&dev_priv->sb_lock); |
e615efe4 ED |
4016 | } |
4017 | ||
275f01b2 DV |
4018 | static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc, |
4019 | enum pipe pch_transcoder) | |
4020 | { | |
4021 | struct drm_device *dev = crtc->base.dev; | |
4022 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6e3c9717 | 4023 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
275f01b2 DV |
4024 | |
4025 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), | |
4026 | I915_READ(HTOTAL(cpu_transcoder))); | |
4027 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), | |
4028 | I915_READ(HBLANK(cpu_transcoder))); | |
4029 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), | |
4030 | I915_READ(HSYNC(cpu_transcoder))); | |
4031 | ||
4032 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), | |
4033 | I915_READ(VTOTAL(cpu_transcoder))); | |
4034 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), | |
4035 | I915_READ(VBLANK(cpu_transcoder))); | |
4036 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), | |
4037 | I915_READ(VSYNC(cpu_transcoder))); | |
4038 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), | |
4039 | I915_READ(VSYNCSHIFT(cpu_transcoder))); | |
4040 | } | |
4041 | ||
003632d9 | 4042 | static void cpt_set_fdi_bc_bifurcation(struct drm_device *dev, bool enable) |
1fbc0d78 DV |
4043 | { |
4044 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4045 | uint32_t temp; | |
4046 | ||
4047 | temp = I915_READ(SOUTH_CHICKEN1); | |
003632d9 | 4048 | if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable) |
1fbc0d78 DV |
4049 | return; |
4050 | ||
4051 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); | |
4052 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); | |
4053 | ||
003632d9 ACO |
4054 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
4055 | if (enable) | |
4056 | temp |= FDI_BC_BIFURCATION_SELECT; | |
4057 | ||
4058 | DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis"); | |
1fbc0d78 DV |
4059 | I915_WRITE(SOUTH_CHICKEN1, temp); |
4060 | POSTING_READ(SOUTH_CHICKEN1); | |
4061 | } | |
4062 | ||
4063 | static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc) | |
4064 | { | |
4065 | struct drm_device *dev = intel_crtc->base.dev; | |
1fbc0d78 DV |
4066 | |
4067 | switch (intel_crtc->pipe) { | |
4068 | case PIPE_A: | |
4069 | break; | |
4070 | case PIPE_B: | |
6e3c9717 | 4071 | if (intel_crtc->config->fdi_lanes > 2) |
003632d9 | 4072 | cpt_set_fdi_bc_bifurcation(dev, false); |
1fbc0d78 | 4073 | else |
003632d9 | 4074 | cpt_set_fdi_bc_bifurcation(dev, true); |
1fbc0d78 DV |
4075 | |
4076 | break; | |
4077 | case PIPE_C: | |
003632d9 | 4078 | cpt_set_fdi_bc_bifurcation(dev, true); |
1fbc0d78 DV |
4079 | |
4080 | break; | |
4081 | default: | |
4082 | BUG(); | |
4083 | } | |
4084 | } | |
4085 | ||
f67a559d JB |
4086 | /* |
4087 | * Enable PCH resources required for PCH ports: | |
4088 | * - PCH PLLs | |
4089 | * - FDI training & RX/TX | |
4090 | * - update transcoder timings | |
4091 | * - DP transcoding bits | |
4092 | * - transcoder | |
4093 | */ | |
4094 | static void ironlake_pch_enable(struct drm_crtc *crtc) | |
0e23b99d JB |
4095 | { |
4096 | struct drm_device *dev = crtc->dev; | |
4097 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4098 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4099 | int pipe = intel_crtc->pipe; | |
ee7b9f93 | 4100 | u32 reg, temp; |
2c07245f | 4101 | |
ab9412ba | 4102 | assert_pch_transcoder_disabled(dev_priv, pipe); |
e7e164db | 4103 | |
1fbc0d78 DV |
4104 | if (IS_IVYBRIDGE(dev)) |
4105 | ivybridge_update_fdi_bc_bifurcation(intel_crtc); | |
4106 | ||
cd986abb DV |
4107 | /* Write the TU size bits before fdi link training, so that error |
4108 | * detection works. */ | |
4109 | I915_WRITE(FDI_RX_TUSIZE1(pipe), | |
4110 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); | |
4111 | ||
c98e9dcf | 4112 | /* For PCH output, training FDI link */ |
674cf967 | 4113 | dev_priv->display.fdi_link_train(crtc); |
2c07245f | 4114 | |
3ad8a208 DV |
4115 | /* We need to program the right clock selection before writing the pixel |
4116 | * mutliplier into the DPLL. */ | |
303b81e0 | 4117 | if (HAS_PCH_CPT(dev)) { |
ee7b9f93 | 4118 | u32 sel; |
4b645f14 | 4119 | |
c98e9dcf | 4120 | temp = I915_READ(PCH_DPLL_SEL); |
11887397 DV |
4121 | temp |= TRANS_DPLL_ENABLE(pipe); |
4122 | sel = TRANS_DPLLB_SEL(pipe); | |
6e3c9717 | 4123 | if (intel_crtc->config->shared_dpll == DPLL_ID_PCH_PLL_B) |
ee7b9f93 JB |
4124 | temp |= sel; |
4125 | else | |
4126 | temp &= ~sel; | |
c98e9dcf | 4127 | I915_WRITE(PCH_DPLL_SEL, temp); |
c98e9dcf | 4128 | } |
5eddb70b | 4129 | |
3ad8a208 DV |
4130 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
4131 | * transcoder, and we actually should do this to not upset any PCH | |
4132 | * transcoder that already use the clock when we share it. | |
4133 | * | |
4134 | * Note that enable_shared_dpll tries to do the right thing, but | |
4135 | * get_shared_dpll unconditionally resets the pll - we need that to have | |
4136 | * the right LVDS enable sequence. */ | |
85b3894f | 4137 | intel_enable_shared_dpll(intel_crtc); |
3ad8a208 | 4138 | |
d9b6cb56 JB |
4139 | /* set transcoder timing, panel must allow it */ |
4140 | assert_panel_unlocked(dev_priv, pipe); | |
275f01b2 | 4141 | ironlake_pch_transcoder_set_timings(intel_crtc, pipe); |
8db9d77b | 4142 | |
303b81e0 | 4143 | intel_fdi_normal_train(crtc); |
5e84e1a4 | 4144 | |
c98e9dcf | 4145 | /* For PCH DP, enable TRANS_DP_CTL */ |
6e3c9717 | 4146 | if (HAS_PCH_CPT(dev) && intel_crtc->config->has_dp_encoder) { |
dfd07d72 | 4147 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
5eddb70b CW |
4148 | reg = TRANS_DP_CTL(pipe); |
4149 | temp = I915_READ(reg); | |
4150 | temp &= ~(TRANS_DP_PORT_SEL_MASK | | |
220cad3c EA |
4151 | TRANS_DP_SYNC_MASK | |
4152 | TRANS_DP_BPC_MASK); | |
e3ef4479 | 4153 | temp |= TRANS_DP_OUTPUT_ENABLE; |
9325c9f0 | 4154 | temp |= bpc << 9; /* same format but at 11:9 */ |
c98e9dcf JB |
4155 | |
4156 | if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC) | |
5eddb70b | 4157 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
c98e9dcf | 4158 | if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC) |
5eddb70b | 4159 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
c98e9dcf JB |
4160 | |
4161 | switch (intel_trans_dp_port_sel(crtc)) { | |
4162 | case PCH_DP_B: | |
5eddb70b | 4163 | temp |= TRANS_DP_PORT_SEL_B; |
c98e9dcf JB |
4164 | break; |
4165 | case PCH_DP_C: | |
5eddb70b | 4166 | temp |= TRANS_DP_PORT_SEL_C; |
c98e9dcf JB |
4167 | break; |
4168 | case PCH_DP_D: | |
5eddb70b | 4169 | temp |= TRANS_DP_PORT_SEL_D; |
c98e9dcf JB |
4170 | break; |
4171 | default: | |
e95d41e1 | 4172 | BUG(); |
32f9d658 | 4173 | } |
2c07245f | 4174 | |
5eddb70b | 4175 | I915_WRITE(reg, temp); |
6be4a607 | 4176 | } |
b52eb4dc | 4177 | |
b8a4f404 | 4178 | ironlake_enable_pch_transcoder(dev_priv, pipe); |
f67a559d JB |
4179 | } |
4180 | ||
1507e5bd PZ |
4181 | static void lpt_pch_enable(struct drm_crtc *crtc) |
4182 | { | |
4183 | struct drm_device *dev = crtc->dev; | |
4184 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4185 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6e3c9717 | 4186 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
1507e5bd | 4187 | |
ab9412ba | 4188 | assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A); |
1507e5bd | 4189 | |
8c52b5e8 | 4190 | lpt_program_iclkip(crtc); |
1507e5bd | 4191 | |
0540e488 | 4192 | /* Set transcoder timing. */ |
275f01b2 | 4193 | ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A); |
1507e5bd | 4194 | |
937bb610 | 4195 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
f67a559d JB |
4196 | } |
4197 | ||
190f68c5 ACO |
4198 | struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc, |
4199 | struct intel_crtc_state *crtc_state) | |
ee7b9f93 | 4200 | { |
e2b78267 | 4201 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
8bd31e67 | 4202 | struct intel_shared_dpll *pll; |
de419ab6 | 4203 | struct intel_shared_dpll_config *shared_dpll; |
e2b78267 | 4204 | enum intel_dpll_id i; |
ee7b9f93 | 4205 | |
de419ab6 ML |
4206 | shared_dpll = intel_atomic_get_shared_dpll_state(crtc_state->base.state); |
4207 | ||
98b6bd99 DV |
4208 | if (HAS_PCH_IBX(dev_priv->dev)) { |
4209 | /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */ | |
d94ab068 | 4210 | i = (enum intel_dpll_id) crtc->pipe; |
e72f9fbf | 4211 | pll = &dev_priv->shared_dplls[i]; |
98b6bd99 | 4212 | |
46edb027 DV |
4213 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", |
4214 | crtc->base.base.id, pll->name); | |
98b6bd99 | 4215 | |
de419ab6 | 4216 | WARN_ON(shared_dpll[i].crtc_mask); |
f2a69f44 | 4217 | |
98b6bd99 DV |
4218 | goto found; |
4219 | } | |
4220 | ||
bcddf610 S |
4221 | if (IS_BROXTON(dev_priv->dev)) { |
4222 | /* PLL is attached to port in bxt */ | |
4223 | struct intel_encoder *encoder; | |
4224 | struct intel_digital_port *intel_dig_port; | |
4225 | ||
4226 | encoder = intel_ddi_get_crtc_new_encoder(crtc_state); | |
4227 | if (WARN_ON(!encoder)) | |
4228 | return NULL; | |
4229 | ||
4230 | intel_dig_port = enc_to_dig_port(&encoder->base); | |
4231 | /* 1:1 mapping between ports and PLLs */ | |
4232 | i = (enum intel_dpll_id)intel_dig_port->port; | |
4233 | pll = &dev_priv->shared_dplls[i]; | |
4234 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", | |
4235 | crtc->base.base.id, pll->name); | |
de419ab6 | 4236 | WARN_ON(shared_dpll[i].crtc_mask); |
bcddf610 S |
4237 | |
4238 | goto found; | |
4239 | } | |
4240 | ||
e72f9fbf DV |
4241 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
4242 | pll = &dev_priv->shared_dplls[i]; | |
ee7b9f93 JB |
4243 | |
4244 | /* Only want to check enabled timings first */ | |
de419ab6 | 4245 | if (shared_dpll[i].crtc_mask == 0) |
ee7b9f93 JB |
4246 | continue; |
4247 | ||
190f68c5 | 4248 | if (memcmp(&crtc_state->dpll_hw_state, |
de419ab6 ML |
4249 | &shared_dpll[i].hw_state, |
4250 | sizeof(crtc_state->dpll_hw_state)) == 0) { | |
8bd31e67 | 4251 | DRM_DEBUG_KMS("CRTC:%d sharing existing %s (crtc mask 0x%08x, ative %d)\n", |
1e6f2ddc | 4252 | crtc->base.base.id, pll->name, |
de419ab6 | 4253 | shared_dpll[i].crtc_mask, |
8bd31e67 | 4254 | pll->active); |
ee7b9f93 JB |
4255 | goto found; |
4256 | } | |
4257 | } | |
4258 | ||
4259 | /* Ok no matching timings, maybe there's a free one? */ | |
e72f9fbf DV |
4260 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
4261 | pll = &dev_priv->shared_dplls[i]; | |
de419ab6 | 4262 | if (shared_dpll[i].crtc_mask == 0) { |
46edb027 DV |
4263 | DRM_DEBUG_KMS("CRTC:%d allocated %s\n", |
4264 | crtc->base.base.id, pll->name); | |
ee7b9f93 JB |
4265 | goto found; |
4266 | } | |
4267 | } | |
4268 | ||
4269 | return NULL; | |
4270 | ||
4271 | found: | |
de419ab6 ML |
4272 | if (shared_dpll[i].crtc_mask == 0) |
4273 | shared_dpll[i].hw_state = | |
4274 | crtc_state->dpll_hw_state; | |
f2a69f44 | 4275 | |
190f68c5 | 4276 | crtc_state->shared_dpll = i; |
46edb027 DV |
4277 | DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name, |
4278 | pipe_name(crtc->pipe)); | |
ee7b9f93 | 4279 | |
de419ab6 | 4280 | shared_dpll[i].crtc_mask |= 1 << crtc->pipe; |
e04c7350 | 4281 | |
ee7b9f93 JB |
4282 | return pll; |
4283 | } | |
4284 | ||
de419ab6 | 4285 | static void intel_shared_dpll_commit(struct drm_atomic_state *state) |
8bd31e67 | 4286 | { |
de419ab6 ML |
4287 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
4288 | struct intel_shared_dpll_config *shared_dpll; | |
8bd31e67 ACO |
4289 | struct intel_shared_dpll *pll; |
4290 | enum intel_dpll_id i; | |
4291 | ||
de419ab6 ML |
4292 | if (!to_intel_atomic_state(state)->dpll_set) |
4293 | return; | |
8bd31e67 | 4294 | |
de419ab6 | 4295 | shared_dpll = to_intel_atomic_state(state)->shared_dpll; |
8bd31e67 ACO |
4296 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
4297 | pll = &dev_priv->shared_dplls[i]; | |
de419ab6 | 4298 | pll->config = shared_dpll[i]; |
8bd31e67 ACO |
4299 | } |
4300 | } | |
4301 | ||
a1520318 | 4302 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
d4270e57 JB |
4303 | { |
4304 | struct drm_i915_private *dev_priv = dev->dev_private; | |
23670b32 | 4305 | int dslreg = PIPEDSL(pipe); |
d4270e57 JB |
4306 | u32 temp; |
4307 | ||
4308 | temp = I915_READ(dslreg); | |
4309 | udelay(500); | |
4310 | if (wait_for(I915_READ(dslreg) != temp, 5)) { | |
d4270e57 | 4311 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
84f44ce7 | 4312 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
d4270e57 JB |
4313 | } |
4314 | } | |
4315 | ||
a1b2278e CK |
4316 | /** |
4317 | * skl_update_scaler_users - Stages update to crtc's scaler state | |
4318 | * @intel_crtc: crtc | |
4319 | * @crtc_state: crtc_state | |
4320 | * @plane: plane (NULL indicates crtc is requesting update) | |
4321 | * @plane_state: plane's state | |
4322 | * @force_detach: request unconditional detachment of scaler | |
4323 | * | |
4324 | * This function updates scaler state for requested plane or crtc. | |
4325 | * To request scaler usage update for a plane, caller shall pass plane pointer. | |
4326 | * To request scaler usage update for crtc, caller shall pass plane pointer | |
4327 | * as NULL. | |
4328 | * | |
4329 | * Return | |
4330 | * 0 - scaler_usage updated successfully | |
4331 | * error - requested scaling cannot be supported or other error condition | |
4332 | */ | |
4333 | int | |
4334 | skl_update_scaler_users( | |
4335 | struct intel_crtc *intel_crtc, struct intel_crtc_state *crtc_state, | |
4336 | struct intel_plane *intel_plane, struct intel_plane_state *plane_state, | |
4337 | int force_detach) | |
4338 | { | |
4339 | int need_scaling; | |
4340 | int idx; | |
4341 | int src_w, src_h, dst_w, dst_h; | |
4342 | int *scaler_id; | |
4343 | struct drm_framebuffer *fb; | |
4344 | struct intel_crtc_scaler_state *scaler_state; | |
6156a456 | 4345 | unsigned int rotation; |
a1b2278e CK |
4346 | |
4347 | if (!intel_crtc || !crtc_state) | |
4348 | return 0; | |
4349 | ||
4350 | scaler_state = &crtc_state->scaler_state; | |
4351 | ||
4352 | idx = intel_plane ? drm_plane_index(&intel_plane->base) : SKL_CRTC_INDEX; | |
4353 | fb = intel_plane ? plane_state->base.fb : NULL; | |
4354 | ||
4355 | if (intel_plane) { | |
4356 | src_w = drm_rect_width(&plane_state->src) >> 16; | |
4357 | src_h = drm_rect_height(&plane_state->src) >> 16; | |
4358 | dst_w = drm_rect_width(&plane_state->dst); | |
4359 | dst_h = drm_rect_height(&plane_state->dst); | |
4360 | scaler_id = &plane_state->scaler_id; | |
6156a456 | 4361 | rotation = plane_state->base.rotation; |
a1b2278e CK |
4362 | } else { |
4363 | struct drm_display_mode *adjusted_mode = | |
4364 | &crtc_state->base.adjusted_mode; | |
4365 | src_w = crtc_state->pipe_src_w; | |
4366 | src_h = crtc_state->pipe_src_h; | |
4367 | dst_w = adjusted_mode->hdisplay; | |
4368 | dst_h = adjusted_mode->vdisplay; | |
4369 | scaler_id = &scaler_state->scaler_id; | |
6156a456 | 4370 | rotation = DRM_ROTATE_0; |
a1b2278e | 4371 | } |
6156a456 CK |
4372 | |
4373 | need_scaling = intel_rotation_90_or_270(rotation) ? | |
4374 | (src_h != dst_w || src_w != dst_h): | |
4375 | (src_w != dst_w || src_h != dst_h); | |
a1b2278e CK |
4376 | |
4377 | /* | |
4378 | * if plane is being disabled or scaler is no more required or force detach | |
4379 | * - free scaler binded to this plane/crtc | |
4380 | * - in order to do this, update crtc->scaler_usage | |
4381 | * | |
4382 | * Here scaler state in crtc_state is set free so that | |
4383 | * scaler can be assigned to other user. Actual register | |
4384 | * update to free the scaler is done in plane/panel-fit programming. | |
4385 | * For this purpose crtc/plane_state->scaler_id isn't reset here. | |
4386 | */ | |
4387 | if (force_detach || !need_scaling || (intel_plane && | |
4388 | (!fb || !plane_state->visible))) { | |
4389 | if (*scaler_id >= 0) { | |
4390 | scaler_state->scaler_users &= ~(1 << idx); | |
4391 | scaler_state->scalers[*scaler_id].in_use = 0; | |
4392 | ||
4393 | DRM_DEBUG_KMS("Staged freeing scaler id %d.%d from %s:%d " | |
4394 | "crtc_state = %p scaler_users = 0x%x\n", | |
4395 | intel_crtc->pipe, *scaler_id, intel_plane ? "PLANE" : "CRTC", | |
4396 | intel_plane ? intel_plane->base.base.id : | |
4397 | intel_crtc->base.base.id, crtc_state, | |
4398 | scaler_state->scaler_users); | |
4399 | *scaler_id = -1; | |
4400 | } | |
4401 | return 0; | |
4402 | } | |
4403 | ||
4404 | /* range checks */ | |
4405 | if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H || | |
4406 | dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H || | |
4407 | ||
4408 | src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H || | |
4409 | dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H) { | |
4410 | DRM_DEBUG_KMS("%s:%d scaler_user index %u.%u: src %ux%u dst %ux%u " | |
4411 | "size is out of scaler range\n", | |
4412 | intel_plane ? "PLANE" : "CRTC", | |
4413 | intel_plane ? intel_plane->base.base.id : intel_crtc->base.base.id, | |
4414 | intel_crtc->pipe, idx, src_w, src_h, dst_w, dst_h); | |
4415 | return -EINVAL; | |
4416 | } | |
4417 | ||
4418 | /* check colorkey */ | |
225c228a CK |
4419 | if (WARN_ON(intel_plane && |
4420 | intel_plane->ckey.flags != I915_SET_COLORKEY_NONE)) { | |
4421 | DRM_DEBUG_KMS("PLANE:%d scaling %ux%u->%ux%u not allowed with colorkey", | |
4422 | intel_plane->base.base.id, src_w, src_h, dst_w, dst_h); | |
a1b2278e CK |
4423 | return -EINVAL; |
4424 | } | |
4425 | ||
4426 | /* Check src format */ | |
4427 | if (intel_plane) { | |
4428 | switch (fb->pixel_format) { | |
4429 | case DRM_FORMAT_RGB565: | |
4430 | case DRM_FORMAT_XBGR8888: | |
4431 | case DRM_FORMAT_XRGB8888: | |
4432 | case DRM_FORMAT_ABGR8888: | |
4433 | case DRM_FORMAT_ARGB8888: | |
4434 | case DRM_FORMAT_XRGB2101010: | |
a1b2278e | 4435 | case DRM_FORMAT_XBGR2101010: |
a1b2278e CK |
4436 | case DRM_FORMAT_YUYV: |
4437 | case DRM_FORMAT_YVYU: | |
4438 | case DRM_FORMAT_UYVY: | |
4439 | case DRM_FORMAT_VYUY: | |
4440 | break; | |
4441 | default: | |
4442 | DRM_DEBUG_KMS("PLANE:%d FB:%d unsupported scaling format 0x%x\n", | |
4443 | intel_plane->base.base.id, fb->base.id, fb->pixel_format); | |
4444 | return -EINVAL; | |
4445 | } | |
4446 | } | |
4447 | ||
4448 | /* mark this plane as a scaler user in crtc_state */ | |
4449 | scaler_state->scaler_users |= (1 << idx); | |
4450 | DRM_DEBUG_KMS("%s:%d staged scaling request for %ux%u->%ux%u " | |
4451 | "crtc_state = %p scaler_users = 0x%x\n", | |
4452 | intel_plane ? "PLANE" : "CRTC", | |
4453 | intel_plane ? intel_plane->base.base.id : intel_crtc->base.base.id, | |
4454 | src_w, src_h, dst_w, dst_h, crtc_state, scaler_state->scaler_users); | |
4455 | return 0; | |
4456 | } | |
4457 | ||
4458 | static void skylake_pfit_update(struct intel_crtc *crtc, int enable) | |
bd2e244f JB |
4459 | { |
4460 | struct drm_device *dev = crtc->base.dev; | |
4461 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4462 | int pipe = crtc->pipe; | |
a1b2278e CK |
4463 | struct intel_crtc_scaler_state *scaler_state = |
4464 | &crtc->config->scaler_state; | |
4465 | ||
4466 | DRM_DEBUG_KMS("for crtc_state = %p\n", crtc->config); | |
4467 | ||
4468 | /* To update pfit, first update scaler state */ | |
4469 | skl_update_scaler_users(crtc, crtc->config, NULL, NULL, !enable); | |
4470 | intel_atomic_setup_scalers(crtc->base.dev, crtc, crtc->config); | |
4471 | skl_detach_scalers(crtc); | |
4472 | if (!enable) | |
4473 | return; | |
bd2e244f | 4474 | |
6e3c9717 | 4475 | if (crtc->config->pch_pfit.enabled) { |
a1b2278e CK |
4476 | int id; |
4477 | ||
4478 | if (WARN_ON(crtc->config->scaler_state.scaler_id < 0)) { | |
4479 | DRM_ERROR("Requesting pfit without getting a scaler first\n"); | |
4480 | return; | |
4481 | } | |
4482 | ||
4483 | id = scaler_state->scaler_id; | |
4484 | I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN | | |
4485 | PS_FILTER_MEDIUM | scaler_state->scalers[id].mode); | |
4486 | I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc->config->pch_pfit.pos); | |
4487 | I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc->config->pch_pfit.size); | |
4488 | ||
4489 | DRM_DEBUG_KMS("for crtc_state = %p scaler_id = %d\n", crtc->config, id); | |
bd2e244f JB |
4490 | } |
4491 | } | |
4492 | ||
b074cec8 JB |
4493 | static void ironlake_pfit_enable(struct intel_crtc *crtc) |
4494 | { | |
4495 | struct drm_device *dev = crtc->base.dev; | |
4496 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4497 | int pipe = crtc->pipe; | |
4498 | ||
6e3c9717 | 4499 | if (crtc->config->pch_pfit.enabled) { |
b074cec8 JB |
4500 | /* Force use of hard-coded filter coefficients |
4501 | * as some pre-programmed values are broken, | |
4502 | * e.g. x201. | |
4503 | */ | |
4504 | if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) | |
4505 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | | |
4506 | PF_PIPE_SEL_IVB(pipe)); | |
4507 | else | |
4508 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3); | |
6e3c9717 ACO |
4509 | I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos); |
4510 | I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size); | |
d4270e57 JB |
4511 | } |
4512 | } | |
4513 | ||
4a3b8769 | 4514 | static void intel_enable_sprite_planes(struct drm_crtc *crtc) |
bb53d4ae VS |
4515 | { |
4516 | struct drm_device *dev = crtc->dev; | |
4517 | enum pipe pipe = to_intel_crtc(crtc)->pipe; | |
af2b653b | 4518 | struct drm_plane *plane; |
bb53d4ae VS |
4519 | struct intel_plane *intel_plane; |
4520 | ||
af2b653b MR |
4521 | drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) { |
4522 | intel_plane = to_intel_plane(plane); | |
bb53d4ae VS |
4523 | if (intel_plane->pipe == pipe) |
4524 | intel_plane_restore(&intel_plane->base); | |
af2b653b | 4525 | } |
bb53d4ae VS |
4526 | } |
4527 | ||
20bc8673 | 4528 | void hsw_enable_ips(struct intel_crtc *crtc) |
d77e4531 | 4529 | { |
cea165c3 VS |
4530 | struct drm_device *dev = crtc->base.dev; |
4531 | struct drm_i915_private *dev_priv = dev->dev_private; | |
d77e4531 | 4532 | |
6e3c9717 | 4533 | if (!crtc->config->ips_enabled) |
d77e4531 PZ |
4534 | return; |
4535 | ||
cea165c3 VS |
4536 | /* We can only enable IPS after we enable a plane and wait for a vblank */ |
4537 | intel_wait_for_vblank(dev, crtc->pipe); | |
4538 | ||
d77e4531 | 4539 | assert_plane_enabled(dev_priv, crtc->plane); |
cea165c3 | 4540 | if (IS_BROADWELL(dev)) { |
2a114cc1 BW |
4541 | mutex_lock(&dev_priv->rps.hw_lock); |
4542 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000)); | |
4543 | mutex_unlock(&dev_priv->rps.hw_lock); | |
4544 | /* Quoting Art Runyan: "its not safe to expect any particular | |
4545 | * value in IPS_CTL bit 31 after enabling IPS through the | |
e59150dc JB |
4546 | * mailbox." Moreover, the mailbox may return a bogus state, |
4547 | * so we need to just enable it and continue on. | |
2a114cc1 BW |
4548 | */ |
4549 | } else { | |
4550 | I915_WRITE(IPS_CTL, IPS_ENABLE); | |
4551 | /* The bit only becomes 1 in the next vblank, so this wait here | |
4552 | * is essentially intel_wait_for_vblank. If we don't have this | |
4553 | * and don't wait for vblanks until the end of crtc_enable, then | |
4554 | * the HW state readout code will complain that the expected | |
4555 | * IPS_CTL value is not the one we read. */ | |
4556 | if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50)) | |
4557 | DRM_ERROR("Timed out waiting for IPS enable\n"); | |
4558 | } | |
d77e4531 PZ |
4559 | } |
4560 | ||
20bc8673 | 4561 | void hsw_disable_ips(struct intel_crtc *crtc) |
d77e4531 PZ |
4562 | { |
4563 | struct drm_device *dev = crtc->base.dev; | |
4564 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4565 | ||
6e3c9717 | 4566 | if (!crtc->config->ips_enabled) |
d77e4531 PZ |
4567 | return; |
4568 | ||
4569 | assert_plane_enabled(dev_priv, crtc->plane); | |
23d0b130 | 4570 | if (IS_BROADWELL(dev)) { |
2a114cc1 BW |
4571 | mutex_lock(&dev_priv->rps.hw_lock); |
4572 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); | |
4573 | mutex_unlock(&dev_priv->rps.hw_lock); | |
23d0b130 BW |
4574 | /* wait for pcode to finish disabling IPS, which may take up to 42ms */ |
4575 | if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42)) | |
4576 | DRM_ERROR("Timed out waiting for IPS disable\n"); | |
e59150dc | 4577 | } else { |
2a114cc1 | 4578 | I915_WRITE(IPS_CTL, 0); |
e59150dc JB |
4579 | POSTING_READ(IPS_CTL); |
4580 | } | |
d77e4531 PZ |
4581 | |
4582 | /* We need to wait for a vblank before we can disable the plane. */ | |
4583 | intel_wait_for_vblank(dev, crtc->pipe); | |
4584 | } | |
4585 | ||
4586 | /** Loads the palette/gamma unit for the CRTC with the prepared values */ | |
4587 | static void intel_crtc_load_lut(struct drm_crtc *crtc) | |
4588 | { | |
4589 | struct drm_device *dev = crtc->dev; | |
4590 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4591 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4592 | enum pipe pipe = intel_crtc->pipe; | |
4593 | int palreg = PALETTE(pipe); | |
4594 | int i; | |
4595 | bool reenable_ips = false; | |
4596 | ||
4597 | /* The clocks have to be on to load the palette. */ | |
53d9f4e9 | 4598 | if (!crtc->state->active) |
d77e4531 PZ |
4599 | return; |
4600 | ||
50360403 | 4601 | if (HAS_GMCH_DISPLAY(dev_priv->dev)) { |
409ee761 | 4602 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) |
d77e4531 PZ |
4603 | assert_dsi_pll_enabled(dev_priv); |
4604 | else | |
4605 | assert_pll_enabled(dev_priv, pipe); | |
4606 | } | |
4607 | ||
4608 | /* use legacy palette for Ironlake */ | |
7a1db49a | 4609 | if (!HAS_GMCH_DISPLAY(dev)) |
d77e4531 PZ |
4610 | palreg = LGC_PALETTE(pipe); |
4611 | ||
4612 | /* Workaround : Do not read or write the pipe palette/gamma data while | |
4613 | * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled. | |
4614 | */ | |
6e3c9717 | 4615 | if (IS_HASWELL(dev) && intel_crtc->config->ips_enabled && |
d77e4531 PZ |
4616 | ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) == |
4617 | GAMMA_MODE_MODE_SPLIT)) { | |
4618 | hsw_disable_ips(intel_crtc); | |
4619 | reenable_ips = true; | |
4620 | } | |
4621 | ||
4622 | for (i = 0; i < 256; i++) { | |
4623 | I915_WRITE(palreg + 4 * i, | |
4624 | (intel_crtc->lut_r[i] << 16) | | |
4625 | (intel_crtc->lut_g[i] << 8) | | |
4626 | intel_crtc->lut_b[i]); | |
4627 | } | |
4628 | ||
4629 | if (reenable_ips) | |
4630 | hsw_enable_ips(intel_crtc); | |
4631 | } | |
4632 | ||
7cac945f | 4633 | static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc) |
d3eedb1a | 4634 | { |
7cac945f | 4635 | if (intel_crtc->overlay) { |
d3eedb1a VS |
4636 | struct drm_device *dev = intel_crtc->base.dev; |
4637 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4638 | ||
4639 | mutex_lock(&dev->struct_mutex); | |
4640 | dev_priv->mm.interruptible = false; | |
4641 | (void) intel_overlay_switch_off(intel_crtc->overlay); | |
4642 | dev_priv->mm.interruptible = true; | |
4643 | mutex_unlock(&dev->struct_mutex); | |
4644 | } | |
4645 | ||
4646 | /* Let userspace switch the overlay on again. In most cases userspace | |
4647 | * has to recompute where to put it anyway. | |
4648 | */ | |
4649 | } | |
4650 | ||
87d4300a ML |
4651 | /** |
4652 | * intel_post_enable_primary - Perform operations after enabling primary plane | |
4653 | * @crtc: the CRTC whose primary plane was just enabled | |
4654 | * | |
4655 | * Performs potentially sleeping operations that must be done after the primary | |
4656 | * plane is enabled, such as updating FBC and IPS. Note that this may be | |
4657 | * called due to an explicit primary plane update, or due to an implicit | |
4658 | * re-enable that is caused when a sprite plane is updated to no longer | |
4659 | * completely hide the primary plane. | |
4660 | */ | |
4661 | static void | |
4662 | intel_post_enable_primary(struct drm_crtc *crtc) | |
a5c4d7bc VS |
4663 | { |
4664 | struct drm_device *dev = crtc->dev; | |
87d4300a | 4665 | struct drm_i915_private *dev_priv = dev->dev_private; |
a5c4d7bc VS |
4666 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
4667 | int pipe = intel_crtc->pipe; | |
a5c4d7bc | 4668 | |
87d4300a ML |
4669 | /* |
4670 | * BDW signals flip done immediately if the plane | |
4671 | * is disabled, even if the plane enable is already | |
4672 | * armed to occur at the next vblank :( | |
4673 | */ | |
4674 | if (IS_BROADWELL(dev)) | |
4675 | intel_wait_for_vblank(dev, pipe); | |
a5c4d7bc | 4676 | |
87d4300a ML |
4677 | /* |
4678 | * FIXME IPS should be fine as long as one plane is | |
4679 | * enabled, but in practice it seems to have problems | |
4680 | * when going from primary only to sprite only and vice | |
4681 | * versa. | |
4682 | */ | |
a5c4d7bc VS |
4683 | hsw_enable_ips(intel_crtc); |
4684 | ||
4685 | mutex_lock(&dev->struct_mutex); | |
7ff0ebcc | 4686 | intel_fbc_update(dev); |
a5c4d7bc | 4687 | mutex_unlock(&dev->struct_mutex); |
f99d7069 DV |
4688 | |
4689 | /* | |
87d4300a ML |
4690 | * Gen2 reports pipe underruns whenever all planes are disabled. |
4691 | * So don't enable underrun reporting before at least some planes | |
4692 | * are enabled. | |
4693 | * FIXME: Need to fix the logic to work when we turn off all planes | |
4694 | * but leave the pipe running. | |
f99d7069 | 4695 | */ |
87d4300a ML |
4696 | if (IS_GEN2(dev)) |
4697 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); | |
4698 | ||
4699 | /* Underruns don't raise interrupts, so check manually. */ | |
4700 | if (HAS_GMCH_DISPLAY(dev)) | |
4701 | i9xx_check_fifo_underruns(dev_priv); | |
a5c4d7bc VS |
4702 | } |
4703 | ||
87d4300a ML |
4704 | /** |
4705 | * intel_pre_disable_primary - Perform operations before disabling primary plane | |
4706 | * @crtc: the CRTC whose primary plane is to be disabled | |
4707 | * | |
4708 | * Performs potentially sleeping operations that must be done before the | |
4709 | * primary plane is disabled, such as updating FBC and IPS. Note that this may | |
4710 | * be called due to an explicit primary plane update, or due to an implicit | |
4711 | * disable that is caused when a sprite plane completely hides the primary | |
4712 | * plane. | |
4713 | */ | |
4714 | static void | |
4715 | intel_pre_disable_primary(struct drm_crtc *crtc) | |
a5c4d7bc VS |
4716 | { |
4717 | struct drm_device *dev = crtc->dev; | |
4718 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4719 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4720 | int pipe = intel_crtc->pipe; | |
a5c4d7bc | 4721 | |
87d4300a ML |
4722 | /* |
4723 | * Gen2 reports pipe underruns whenever all planes are disabled. | |
4724 | * So diasble underrun reporting before all the planes get disabled. | |
4725 | * FIXME: Need to fix the logic to work when we turn off all planes | |
4726 | * but leave the pipe running. | |
4727 | */ | |
4728 | if (IS_GEN2(dev)) | |
4729 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
a5c4d7bc | 4730 | |
87d4300a ML |
4731 | /* |
4732 | * Vblank time updates from the shadow to live plane control register | |
4733 | * are blocked if the memory self-refresh mode is active at that | |
4734 | * moment. So to make sure the plane gets truly disabled, disable | |
4735 | * first the self-refresh mode. The self-refresh enable bit in turn | |
4736 | * will be checked/applied by the HW only at the next frame start | |
4737 | * event which is after the vblank start event, so we need to have a | |
4738 | * wait-for-vblank between disabling the plane and the pipe. | |
4739 | */ | |
4740 | if (HAS_GMCH_DISPLAY(dev)) | |
4741 | intel_set_memory_cxsr(dev_priv, false); | |
4742 | ||
4743 | mutex_lock(&dev->struct_mutex); | |
e35fef21 | 4744 | if (dev_priv->fbc.crtc == intel_crtc) |
7ff0ebcc | 4745 | intel_fbc_disable(dev); |
87d4300a | 4746 | mutex_unlock(&dev->struct_mutex); |
a5c4d7bc | 4747 | |
87d4300a ML |
4748 | /* |
4749 | * FIXME IPS should be fine as long as one plane is | |
4750 | * enabled, but in practice it seems to have problems | |
4751 | * when going from primary only to sprite only and vice | |
4752 | * versa. | |
4753 | */ | |
a5c4d7bc | 4754 | hsw_disable_ips(intel_crtc); |
87d4300a ML |
4755 | } |
4756 | ||
4757 | static void intel_crtc_enable_planes(struct drm_crtc *crtc) | |
4758 | { | |
2d847d45 RV |
4759 | struct drm_device *dev = crtc->dev; |
4760 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4761 | int pipe = intel_crtc->pipe; | |
4762 | ||
87d4300a ML |
4763 | intel_enable_primary_hw_plane(crtc->primary, crtc); |
4764 | intel_enable_sprite_planes(crtc); | |
c0165304 ML |
4765 | if (to_intel_plane_state(crtc->cursor->state)->visible) |
4766 | intel_crtc_update_cursor(crtc, true); | |
87d4300a ML |
4767 | |
4768 | intel_post_enable_primary(crtc); | |
2d847d45 RV |
4769 | |
4770 | /* | |
4771 | * FIXME: Once we grow proper nuclear flip support out of this we need | |
4772 | * to compute the mask of flip planes precisely. For the time being | |
4773 | * consider this a flip to a NULL plane. | |
4774 | */ | |
4775 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); | |
87d4300a ML |
4776 | } |
4777 | ||
4778 | static void intel_crtc_disable_planes(struct drm_crtc *crtc) | |
4779 | { | |
4780 | struct drm_device *dev = crtc->dev; | |
4781 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4782 | struct intel_plane *intel_plane; | |
4783 | int pipe = intel_crtc->pipe; | |
4784 | ||
4785 | intel_crtc_wait_for_pending_flips(crtc); | |
4786 | ||
4787 | intel_pre_disable_primary(crtc); | |
a5c4d7bc | 4788 | |
7cac945f | 4789 | intel_crtc_dpms_overlay_disable(intel_crtc); |
27321ae8 ML |
4790 | for_each_intel_plane(dev, intel_plane) { |
4791 | if (intel_plane->pipe == pipe) { | |
4792 | struct drm_crtc *from = intel_plane->base.crtc; | |
4793 | ||
4794 | intel_plane->disable_plane(&intel_plane->base, | |
4795 | from ?: crtc, true); | |
4796 | } | |
4797 | } | |
f98551ae | 4798 | |
f99d7069 DV |
4799 | /* |
4800 | * FIXME: Once we grow proper nuclear flip support out of this we need | |
4801 | * to compute the mask of flip planes precisely. For the time being | |
4802 | * consider this a flip to a NULL plane. | |
4803 | */ | |
4804 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); | |
a5c4d7bc VS |
4805 | } |
4806 | ||
f67a559d JB |
4807 | static void ironlake_crtc_enable(struct drm_crtc *crtc) |
4808 | { | |
4809 | struct drm_device *dev = crtc->dev; | |
4810 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4811 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 4812 | struct intel_encoder *encoder; |
f67a559d | 4813 | int pipe = intel_crtc->pipe; |
f67a559d | 4814 | |
53d9f4e9 | 4815 | if (WARN_ON(intel_crtc->active)) |
f67a559d JB |
4816 | return; |
4817 | ||
6e3c9717 | 4818 | if (intel_crtc->config->has_pch_encoder) |
b14b1055 DV |
4819 | intel_prepare_shared_dpll(intel_crtc); |
4820 | ||
6e3c9717 | 4821 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 4822 | intel_dp_set_m_n(intel_crtc, M1_N1); |
29407aab DV |
4823 | |
4824 | intel_set_pipe_timings(intel_crtc); | |
4825 | ||
6e3c9717 | 4826 | if (intel_crtc->config->has_pch_encoder) { |
29407aab | 4827 | intel_cpu_transcoder_set_m_n(intel_crtc, |
6e3c9717 | 4828 | &intel_crtc->config->fdi_m_n, NULL); |
29407aab DV |
4829 | } |
4830 | ||
4831 | ironlake_set_pipeconf(crtc); | |
4832 | ||
f67a559d | 4833 | intel_crtc->active = true; |
8664281b | 4834 | |
a72e4c9f DV |
4835 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4836 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); | |
8664281b | 4837 | |
f6736a1a | 4838 | for_each_encoder_on_crtc(dev, crtc, encoder) |
952735ee DV |
4839 | if (encoder->pre_enable) |
4840 | encoder->pre_enable(encoder); | |
f67a559d | 4841 | |
6e3c9717 | 4842 | if (intel_crtc->config->has_pch_encoder) { |
fff367c7 DV |
4843 | /* Note: FDI PLL enabling _must_ be done before we enable the |
4844 | * cpu pipes, hence this is separate from all the other fdi/pch | |
4845 | * enabling. */ | |
88cefb6c | 4846 | ironlake_fdi_pll_enable(intel_crtc); |
46b6f814 DV |
4847 | } else { |
4848 | assert_fdi_tx_disabled(dev_priv, pipe); | |
4849 | assert_fdi_rx_disabled(dev_priv, pipe); | |
4850 | } | |
f67a559d | 4851 | |
b074cec8 | 4852 | ironlake_pfit_enable(intel_crtc); |
f67a559d | 4853 | |
9c54c0dd JB |
4854 | /* |
4855 | * On ILK+ LUT must be loaded before the pipe is running but with | |
4856 | * clocks enabled | |
4857 | */ | |
4858 | intel_crtc_load_lut(crtc); | |
4859 | ||
f37fcc2a | 4860 | intel_update_watermarks(crtc); |
e1fdc473 | 4861 | intel_enable_pipe(intel_crtc); |
f67a559d | 4862 | |
6e3c9717 | 4863 | if (intel_crtc->config->has_pch_encoder) |
f67a559d | 4864 | ironlake_pch_enable(crtc); |
c98e9dcf | 4865 | |
f9b61ff6 DV |
4866 | assert_vblank_disabled(crtc); |
4867 | drm_crtc_vblank_on(crtc); | |
4868 | ||
fa5c73b1 DV |
4869 | for_each_encoder_on_crtc(dev, crtc, encoder) |
4870 | encoder->enable(encoder); | |
61b77ddd DV |
4871 | |
4872 | if (HAS_PCH_CPT(dev)) | |
a1520318 | 4873 | cpt_verify_modeset(dev, intel_crtc->pipe); |
6be4a607 JB |
4874 | } |
4875 | ||
42db64ef PZ |
4876 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
4877 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) | |
4878 | { | |
f5adf94e | 4879 | return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A; |
42db64ef PZ |
4880 | } |
4881 | ||
4f771f10 PZ |
4882 | static void haswell_crtc_enable(struct drm_crtc *crtc) |
4883 | { | |
4884 | struct drm_device *dev = crtc->dev; | |
4885 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4886 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4887 | struct intel_encoder *encoder; | |
99d736a2 ML |
4888 | int pipe = intel_crtc->pipe, hsw_workaround_pipe; |
4889 | struct intel_crtc_state *pipe_config = | |
4890 | to_intel_crtc_state(crtc->state); | |
4f771f10 | 4891 | |
53d9f4e9 | 4892 | if (WARN_ON(intel_crtc->active)) |
4f771f10 PZ |
4893 | return; |
4894 | ||
df8ad70c DV |
4895 | if (intel_crtc_to_shared_dpll(intel_crtc)) |
4896 | intel_enable_shared_dpll(intel_crtc); | |
4897 | ||
6e3c9717 | 4898 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 4899 | intel_dp_set_m_n(intel_crtc, M1_N1); |
229fca97 DV |
4900 | |
4901 | intel_set_pipe_timings(intel_crtc); | |
4902 | ||
6e3c9717 ACO |
4903 | if (intel_crtc->config->cpu_transcoder != TRANSCODER_EDP) { |
4904 | I915_WRITE(PIPE_MULT(intel_crtc->config->cpu_transcoder), | |
4905 | intel_crtc->config->pixel_multiplier - 1); | |
ebb69c95 CT |
4906 | } |
4907 | ||
6e3c9717 | 4908 | if (intel_crtc->config->has_pch_encoder) { |
229fca97 | 4909 | intel_cpu_transcoder_set_m_n(intel_crtc, |
6e3c9717 | 4910 | &intel_crtc->config->fdi_m_n, NULL); |
229fca97 DV |
4911 | } |
4912 | ||
4913 | haswell_set_pipeconf(crtc); | |
4914 | ||
4915 | intel_set_pipe_csc(crtc); | |
4916 | ||
4f771f10 | 4917 | intel_crtc->active = true; |
8664281b | 4918 | |
a72e4c9f | 4919 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4f771f10 PZ |
4920 | for_each_encoder_on_crtc(dev, crtc, encoder) |
4921 | if (encoder->pre_enable) | |
4922 | encoder->pre_enable(encoder); | |
4923 | ||
6e3c9717 | 4924 | if (intel_crtc->config->has_pch_encoder) { |
a72e4c9f DV |
4925 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
4926 | true); | |
4fe9467d ID |
4927 | dev_priv->display.fdi_link_train(crtc); |
4928 | } | |
4929 | ||
1f544388 | 4930 | intel_ddi_enable_pipe_clock(intel_crtc); |
4f771f10 | 4931 | |
ff6d9f55 | 4932 | if (INTEL_INFO(dev)->gen == 9) |
a1b2278e | 4933 | skylake_pfit_update(intel_crtc, 1); |
ff6d9f55 | 4934 | else if (INTEL_INFO(dev)->gen < 9) |
bd2e244f | 4935 | ironlake_pfit_enable(intel_crtc); |
ff6d9f55 JB |
4936 | else |
4937 | MISSING_CASE(INTEL_INFO(dev)->gen); | |
4f771f10 PZ |
4938 | |
4939 | /* | |
4940 | * On ILK+ LUT must be loaded before the pipe is running but with | |
4941 | * clocks enabled | |
4942 | */ | |
4943 | intel_crtc_load_lut(crtc); | |
4944 | ||
1f544388 | 4945 | intel_ddi_set_pipe_settings(crtc); |
8228c251 | 4946 | intel_ddi_enable_transcoder_func(crtc); |
4f771f10 | 4947 | |
f37fcc2a | 4948 | intel_update_watermarks(crtc); |
e1fdc473 | 4949 | intel_enable_pipe(intel_crtc); |
42db64ef | 4950 | |
6e3c9717 | 4951 | if (intel_crtc->config->has_pch_encoder) |
1507e5bd | 4952 | lpt_pch_enable(crtc); |
4f771f10 | 4953 | |
6e3c9717 | 4954 | if (intel_crtc->config->dp_encoder_is_mst) |
0e32b39c DA |
4955 | intel_ddi_set_vc_payload_alloc(crtc, true); |
4956 | ||
f9b61ff6 DV |
4957 | assert_vblank_disabled(crtc); |
4958 | drm_crtc_vblank_on(crtc); | |
4959 | ||
8807e55b | 4960 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
4f771f10 | 4961 | encoder->enable(encoder); |
8807e55b JN |
4962 | intel_opregion_notify_encoder(encoder, true); |
4963 | } | |
4f771f10 | 4964 | |
e4916946 PZ |
4965 | /* If we change the relative order between pipe/planes enabling, we need |
4966 | * to change the workaround. */ | |
99d736a2 ML |
4967 | hsw_workaround_pipe = pipe_config->hsw_workaround_pipe; |
4968 | if (IS_HASWELL(dev) && hsw_workaround_pipe != INVALID_PIPE) { | |
4969 | intel_wait_for_vblank(dev, hsw_workaround_pipe); | |
4970 | intel_wait_for_vblank(dev, hsw_workaround_pipe); | |
4971 | } | |
4f771f10 PZ |
4972 | } |
4973 | ||
3f8dce3a DV |
4974 | static void ironlake_pfit_disable(struct intel_crtc *crtc) |
4975 | { | |
4976 | struct drm_device *dev = crtc->base.dev; | |
4977 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4978 | int pipe = crtc->pipe; | |
4979 | ||
4980 | /* To avoid upsetting the power well on haswell only disable the pfit if | |
4981 | * it's in use. The hw state code will make sure we get this right. */ | |
6e3c9717 | 4982 | if (crtc->config->pch_pfit.enabled) { |
3f8dce3a DV |
4983 | I915_WRITE(PF_CTL(pipe), 0); |
4984 | I915_WRITE(PF_WIN_POS(pipe), 0); | |
4985 | I915_WRITE(PF_WIN_SZ(pipe), 0); | |
4986 | } | |
4987 | } | |
4988 | ||
6be4a607 JB |
4989 | static void ironlake_crtc_disable(struct drm_crtc *crtc) |
4990 | { | |
4991 | struct drm_device *dev = crtc->dev; | |
4992 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4993 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 4994 | struct intel_encoder *encoder; |
6be4a607 | 4995 | int pipe = intel_crtc->pipe; |
5eddb70b | 4996 | u32 reg, temp; |
b52eb4dc | 4997 | |
53d9f4e9 | 4998 | if (WARN_ON(!intel_crtc->active)) |
f7abfe8b CW |
4999 | return; |
5000 | ||
ea9d758d DV |
5001 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5002 | encoder->disable(encoder); | |
5003 | ||
f9b61ff6 DV |
5004 | drm_crtc_vblank_off(crtc); |
5005 | assert_vblank_disabled(crtc); | |
5006 | ||
6e3c9717 | 5007 | if (intel_crtc->config->has_pch_encoder) |
a72e4c9f | 5008 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
d925c59a | 5009 | |
575f7ab7 | 5010 | intel_disable_pipe(intel_crtc); |
32f9d658 | 5011 | |
3f8dce3a | 5012 | ironlake_pfit_disable(intel_crtc); |
2c07245f | 5013 | |
5a74f70a VS |
5014 | if (intel_crtc->config->has_pch_encoder) |
5015 | ironlake_fdi_disable(crtc); | |
5016 | ||
bf49ec8c DV |
5017 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5018 | if (encoder->post_disable) | |
5019 | encoder->post_disable(encoder); | |
2c07245f | 5020 | |
6e3c9717 | 5021 | if (intel_crtc->config->has_pch_encoder) { |
d925c59a | 5022 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
6be4a607 | 5023 | |
d925c59a DV |
5024 | if (HAS_PCH_CPT(dev)) { |
5025 | /* disable TRANS_DP_CTL */ | |
5026 | reg = TRANS_DP_CTL(pipe); | |
5027 | temp = I915_READ(reg); | |
5028 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | | |
5029 | TRANS_DP_PORT_SEL_MASK); | |
5030 | temp |= TRANS_DP_PORT_SEL_NONE; | |
5031 | I915_WRITE(reg, temp); | |
5032 | ||
5033 | /* disable DPLL_SEL */ | |
5034 | temp = I915_READ(PCH_DPLL_SEL); | |
11887397 | 5035 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
d925c59a | 5036 | I915_WRITE(PCH_DPLL_SEL, temp); |
9db4a9c7 | 5037 | } |
e3421a18 | 5038 | |
d925c59a | 5039 | /* disable PCH DPLL */ |
e72f9fbf | 5040 | intel_disable_shared_dpll(intel_crtc); |
8db9d77b | 5041 | |
d925c59a DV |
5042 | ironlake_fdi_pll_disable(intel_crtc); |
5043 | } | |
6b383a7f | 5044 | |
f7abfe8b | 5045 | intel_crtc->active = false; |
46ba614c | 5046 | intel_update_watermarks(crtc); |
d1ebd816 BW |
5047 | |
5048 | mutex_lock(&dev->struct_mutex); | |
7ff0ebcc | 5049 | intel_fbc_update(dev); |
d1ebd816 | 5050 | mutex_unlock(&dev->struct_mutex); |
6be4a607 | 5051 | } |
1b3c7a47 | 5052 | |
4f771f10 | 5053 | static void haswell_crtc_disable(struct drm_crtc *crtc) |
ee7b9f93 | 5054 | { |
4f771f10 PZ |
5055 | struct drm_device *dev = crtc->dev; |
5056 | struct drm_i915_private *dev_priv = dev->dev_private; | |
ee7b9f93 | 5057 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
4f771f10 | 5058 | struct intel_encoder *encoder; |
6e3c9717 | 5059 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
ee7b9f93 | 5060 | |
53d9f4e9 | 5061 | if (WARN_ON(!intel_crtc->active)) |
4f771f10 PZ |
5062 | return; |
5063 | ||
8807e55b JN |
5064 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
5065 | intel_opregion_notify_encoder(encoder, false); | |
4f771f10 | 5066 | encoder->disable(encoder); |
8807e55b | 5067 | } |
4f771f10 | 5068 | |
f9b61ff6 DV |
5069 | drm_crtc_vblank_off(crtc); |
5070 | assert_vblank_disabled(crtc); | |
5071 | ||
6e3c9717 | 5072 | if (intel_crtc->config->has_pch_encoder) |
a72e4c9f DV |
5073 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
5074 | false); | |
575f7ab7 | 5075 | intel_disable_pipe(intel_crtc); |
4f771f10 | 5076 | |
6e3c9717 | 5077 | if (intel_crtc->config->dp_encoder_is_mst) |
a4bf214f VS |
5078 | intel_ddi_set_vc_payload_alloc(crtc, false); |
5079 | ||
ad80a810 | 5080 | intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder); |
4f771f10 | 5081 | |
ff6d9f55 | 5082 | if (INTEL_INFO(dev)->gen == 9) |
a1b2278e | 5083 | skylake_pfit_update(intel_crtc, 0); |
ff6d9f55 | 5084 | else if (INTEL_INFO(dev)->gen < 9) |
bd2e244f | 5085 | ironlake_pfit_disable(intel_crtc); |
ff6d9f55 JB |
5086 | else |
5087 | MISSING_CASE(INTEL_INFO(dev)->gen); | |
4f771f10 | 5088 | |
1f544388 | 5089 | intel_ddi_disable_pipe_clock(intel_crtc); |
4f771f10 | 5090 | |
6e3c9717 | 5091 | if (intel_crtc->config->has_pch_encoder) { |
ab4d966c | 5092 | lpt_disable_pch_transcoder(dev_priv); |
1ad960f2 | 5093 | intel_ddi_fdi_disable(crtc); |
83616634 | 5094 | } |
4f771f10 | 5095 | |
97b040aa ID |
5096 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5097 | if (encoder->post_disable) | |
5098 | encoder->post_disable(encoder); | |
5099 | ||
4f771f10 | 5100 | intel_crtc->active = false; |
46ba614c | 5101 | intel_update_watermarks(crtc); |
4f771f10 PZ |
5102 | |
5103 | mutex_lock(&dev->struct_mutex); | |
7ff0ebcc | 5104 | intel_fbc_update(dev); |
4f771f10 | 5105 | mutex_unlock(&dev->struct_mutex); |
df8ad70c DV |
5106 | |
5107 | if (intel_crtc_to_shared_dpll(intel_crtc)) | |
5108 | intel_disable_shared_dpll(intel_crtc); | |
4f771f10 PZ |
5109 | } |
5110 | ||
2dd24552 JB |
5111 | static void i9xx_pfit_enable(struct intel_crtc *crtc) |
5112 | { | |
5113 | struct drm_device *dev = crtc->base.dev; | |
5114 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6e3c9717 | 5115 | struct intel_crtc_state *pipe_config = crtc->config; |
2dd24552 | 5116 | |
681a8504 | 5117 | if (!pipe_config->gmch_pfit.control) |
2dd24552 JB |
5118 | return; |
5119 | ||
2dd24552 | 5120 | /* |
c0b03411 DV |
5121 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
5122 | * according to register description and PRM. | |
2dd24552 | 5123 | */ |
c0b03411 DV |
5124 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
5125 | assert_pipe_disabled(dev_priv, crtc->pipe); | |
2dd24552 | 5126 | |
b074cec8 JB |
5127 | I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios); |
5128 | I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control); | |
5a80c45c DV |
5129 | |
5130 | /* Border color in case we don't scale up to the full screen. Black by | |
5131 | * default, change to something else for debugging. */ | |
5132 | I915_WRITE(BCLRPAT(crtc->pipe), 0); | |
2dd24552 JB |
5133 | } |
5134 | ||
d05410f9 DA |
5135 | static enum intel_display_power_domain port_to_power_domain(enum port port) |
5136 | { | |
5137 | switch (port) { | |
5138 | case PORT_A: | |
5139 | return POWER_DOMAIN_PORT_DDI_A_4_LANES; | |
5140 | case PORT_B: | |
5141 | return POWER_DOMAIN_PORT_DDI_B_4_LANES; | |
5142 | case PORT_C: | |
5143 | return POWER_DOMAIN_PORT_DDI_C_4_LANES; | |
5144 | case PORT_D: | |
5145 | return POWER_DOMAIN_PORT_DDI_D_4_LANES; | |
5146 | default: | |
5147 | WARN_ON_ONCE(1); | |
5148 | return POWER_DOMAIN_PORT_OTHER; | |
5149 | } | |
5150 | } | |
5151 | ||
77d22dca ID |
5152 | #define for_each_power_domain(domain, mask) \ |
5153 | for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \ | |
5154 | if ((1 << (domain)) & (mask)) | |
5155 | ||
319be8ae ID |
5156 | enum intel_display_power_domain |
5157 | intel_display_port_power_domain(struct intel_encoder *intel_encoder) | |
5158 | { | |
5159 | struct drm_device *dev = intel_encoder->base.dev; | |
5160 | struct intel_digital_port *intel_dig_port; | |
5161 | ||
5162 | switch (intel_encoder->type) { | |
5163 | case INTEL_OUTPUT_UNKNOWN: | |
5164 | /* Only DDI platforms should ever use this output type */ | |
5165 | WARN_ON_ONCE(!HAS_DDI(dev)); | |
5166 | case INTEL_OUTPUT_DISPLAYPORT: | |
5167 | case INTEL_OUTPUT_HDMI: | |
5168 | case INTEL_OUTPUT_EDP: | |
5169 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); | |
d05410f9 | 5170 | return port_to_power_domain(intel_dig_port->port); |
0e32b39c DA |
5171 | case INTEL_OUTPUT_DP_MST: |
5172 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; | |
5173 | return port_to_power_domain(intel_dig_port->port); | |
319be8ae ID |
5174 | case INTEL_OUTPUT_ANALOG: |
5175 | return POWER_DOMAIN_PORT_CRT; | |
5176 | case INTEL_OUTPUT_DSI: | |
5177 | return POWER_DOMAIN_PORT_DSI; | |
5178 | default: | |
5179 | return POWER_DOMAIN_PORT_OTHER; | |
5180 | } | |
5181 | } | |
5182 | ||
5183 | static unsigned long get_crtc_power_domains(struct drm_crtc *crtc) | |
77d22dca | 5184 | { |
319be8ae ID |
5185 | struct drm_device *dev = crtc->dev; |
5186 | struct intel_encoder *intel_encoder; | |
5187 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
5188 | enum pipe pipe = intel_crtc->pipe; | |
77d22dca ID |
5189 | unsigned long mask; |
5190 | enum transcoder transcoder; | |
5191 | ||
5192 | transcoder = intel_pipe_to_cpu_transcoder(dev->dev_private, pipe); | |
5193 | ||
5194 | mask = BIT(POWER_DOMAIN_PIPE(pipe)); | |
5195 | mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder)); | |
6e3c9717 ACO |
5196 | if (intel_crtc->config->pch_pfit.enabled || |
5197 | intel_crtc->config->pch_pfit.force_thru) | |
77d22dca ID |
5198 | mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
5199 | ||
319be8ae ID |
5200 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) |
5201 | mask |= BIT(intel_display_port_power_domain(intel_encoder)); | |
5202 | ||
77d22dca ID |
5203 | return mask; |
5204 | } | |
5205 | ||
679dacd4 | 5206 | static void modeset_update_crtc_power_domains(struct drm_atomic_state *state) |
77d22dca | 5207 | { |
679dacd4 | 5208 | struct drm_device *dev = state->dev; |
77d22dca ID |
5209 | struct drm_i915_private *dev_priv = dev->dev_private; |
5210 | unsigned long pipe_domains[I915_MAX_PIPES] = { 0, }; | |
5211 | struct intel_crtc *crtc; | |
5212 | ||
5213 | /* | |
5214 | * First get all needed power domains, then put all unneeded, to avoid | |
5215 | * any unnecessary toggling of the power wells. | |
5216 | */ | |
d3fcc808 | 5217 | for_each_intel_crtc(dev, crtc) { |
77d22dca ID |
5218 | enum intel_display_power_domain domain; |
5219 | ||
83d65738 | 5220 | if (!crtc->base.state->enable) |
77d22dca ID |
5221 | continue; |
5222 | ||
319be8ae | 5223 | pipe_domains[crtc->pipe] = get_crtc_power_domains(&crtc->base); |
77d22dca ID |
5224 | |
5225 | for_each_power_domain(domain, pipe_domains[crtc->pipe]) | |
5226 | intel_display_power_get(dev_priv, domain); | |
5227 | } | |
5228 | ||
50f6e502 | 5229 | if (dev_priv->display.modeset_global_resources) |
679dacd4 | 5230 | dev_priv->display.modeset_global_resources(state); |
50f6e502 | 5231 | |
d3fcc808 | 5232 | for_each_intel_crtc(dev, crtc) { |
77d22dca ID |
5233 | enum intel_display_power_domain domain; |
5234 | ||
5235 | for_each_power_domain(domain, crtc->enabled_power_domains) | |
5236 | intel_display_power_put(dev_priv, domain); | |
5237 | ||
5238 | crtc->enabled_power_domains = pipe_domains[crtc->pipe]; | |
5239 | } | |
5240 | ||
5241 | intel_display_set_init_power(dev_priv, false); | |
5242 | } | |
5243 | ||
560a7ae4 DL |
5244 | static void intel_update_max_cdclk(struct drm_device *dev) |
5245 | { | |
5246 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5247 | ||
5248 | if (IS_SKYLAKE(dev)) { | |
5249 | u32 limit = I915_READ(SKL_DFSM) & SKL_DFSM_CDCLK_LIMIT_MASK; | |
5250 | ||
5251 | if (limit == SKL_DFSM_CDCLK_LIMIT_675) | |
5252 | dev_priv->max_cdclk_freq = 675000; | |
5253 | else if (limit == SKL_DFSM_CDCLK_LIMIT_540) | |
5254 | dev_priv->max_cdclk_freq = 540000; | |
5255 | else if (limit == SKL_DFSM_CDCLK_LIMIT_450) | |
5256 | dev_priv->max_cdclk_freq = 450000; | |
5257 | else | |
5258 | dev_priv->max_cdclk_freq = 337500; | |
5259 | } else if (IS_BROADWELL(dev)) { | |
5260 | /* | |
5261 | * FIXME with extra cooling we can allow | |
5262 | * 540 MHz for ULX and 675 Mhz for ULT. | |
5263 | * How can we know if extra cooling is | |
5264 | * available? PCI ID, VTB, something else? | |
5265 | */ | |
5266 | if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
5267 | dev_priv->max_cdclk_freq = 450000; | |
5268 | else if (IS_BDW_ULX(dev)) | |
5269 | dev_priv->max_cdclk_freq = 450000; | |
5270 | else if (IS_BDW_ULT(dev)) | |
5271 | dev_priv->max_cdclk_freq = 540000; | |
5272 | else | |
5273 | dev_priv->max_cdclk_freq = 675000; | |
0904deaf MK |
5274 | } else if (IS_CHERRYVIEW(dev)) { |
5275 | dev_priv->max_cdclk_freq = 320000; | |
560a7ae4 DL |
5276 | } else if (IS_VALLEYVIEW(dev)) { |
5277 | dev_priv->max_cdclk_freq = 400000; | |
5278 | } else { | |
5279 | /* otherwise assume cdclk is fixed */ | |
5280 | dev_priv->max_cdclk_freq = dev_priv->cdclk_freq; | |
5281 | } | |
5282 | ||
5283 | DRM_DEBUG_DRIVER("Max CD clock rate: %d kHz\n", | |
5284 | dev_priv->max_cdclk_freq); | |
5285 | } | |
5286 | ||
5287 | static void intel_update_cdclk(struct drm_device *dev) | |
5288 | { | |
5289 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5290 | ||
5291 | dev_priv->cdclk_freq = dev_priv->display.get_display_clock_speed(dev); | |
5292 | DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n", | |
5293 | dev_priv->cdclk_freq); | |
5294 | ||
5295 | /* | |
5296 | * Program the gmbus_freq based on the cdclk frequency. | |
5297 | * BSpec erroneously claims we should aim for 4MHz, but | |
5298 | * in fact 1MHz is the correct frequency. | |
5299 | */ | |
5300 | if (IS_VALLEYVIEW(dev)) { | |
5301 | /* | |
5302 | * Program the gmbus_freq based on the cdclk frequency. | |
5303 | * BSpec erroneously claims we should aim for 4MHz, but | |
5304 | * in fact 1MHz is the correct frequency. | |
5305 | */ | |
5306 | I915_WRITE(GMBUSFREQ_VLV, DIV_ROUND_UP(dev_priv->cdclk_freq, 1000)); | |
5307 | } | |
5308 | ||
5309 | if (dev_priv->max_cdclk_freq == 0) | |
5310 | intel_update_max_cdclk(dev); | |
5311 | } | |
5312 | ||
70d0c574 | 5313 | static void broxton_set_cdclk(struct drm_device *dev, int frequency) |
f8437dd1 VK |
5314 | { |
5315 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5316 | uint32_t divider; | |
5317 | uint32_t ratio; | |
5318 | uint32_t current_freq; | |
5319 | int ret; | |
5320 | ||
5321 | /* frequency = 19.2MHz * ratio / 2 / div{1,1.5,2,4} */ | |
5322 | switch (frequency) { | |
5323 | case 144000: | |
5324 | divider = BXT_CDCLK_CD2X_DIV_SEL_4; | |
5325 | ratio = BXT_DE_PLL_RATIO(60); | |
5326 | break; | |
5327 | case 288000: | |
5328 | divider = BXT_CDCLK_CD2X_DIV_SEL_2; | |
5329 | ratio = BXT_DE_PLL_RATIO(60); | |
5330 | break; | |
5331 | case 384000: | |
5332 | divider = BXT_CDCLK_CD2X_DIV_SEL_1_5; | |
5333 | ratio = BXT_DE_PLL_RATIO(60); | |
5334 | break; | |
5335 | case 576000: | |
5336 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; | |
5337 | ratio = BXT_DE_PLL_RATIO(60); | |
5338 | break; | |
5339 | case 624000: | |
5340 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; | |
5341 | ratio = BXT_DE_PLL_RATIO(65); | |
5342 | break; | |
5343 | case 19200: | |
5344 | /* | |
5345 | * Bypass frequency with DE PLL disabled. Init ratio, divider | |
5346 | * to suppress GCC warning. | |
5347 | */ | |
5348 | ratio = 0; | |
5349 | divider = 0; | |
5350 | break; | |
5351 | default: | |
5352 | DRM_ERROR("unsupported CDCLK freq %d", frequency); | |
5353 | ||
5354 | return; | |
5355 | } | |
5356 | ||
5357 | mutex_lock(&dev_priv->rps.hw_lock); | |
5358 | /* Inform power controller of upcoming frequency change */ | |
5359 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, | |
5360 | 0x80000000); | |
5361 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5362 | ||
5363 | if (ret) { | |
5364 | DRM_ERROR("PCode CDCLK freq change notify failed (err %d, freq %d)\n", | |
5365 | ret, frequency); | |
5366 | return; | |
5367 | } | |
5368 | ||
5369 | current_freq = I915_READ(CDCLK_CTL) & CDCLK_FREQ_DECIMAL_MASK; | |
5370 | /* convert from .1 fixpoint MHz with -1MHz offset to kHz */ | |
5371 | current_freq = current_freq * 500 + 1000; | |
5372 | ||
5373 | /* | |
5374 | * DE PLL has to be disabled when | |
5375 | * - setting to 19.2MHz (bypass, PLL isn't used) | |
5376 | * - before setting to 624MHz (PLL needs toggling) | |
5377 | * - before setting to any frequency from 624MHz (PLL needs toggling) | |
5378 | */ | |
5379 | if (frequency == 19200 || frequency == 624000 || | |
5380 | current_freq == 624000) { | |
5381 | I915_WRITE(BXT_DE_PLL_ENABLE, ~BXT_DE_PLL_PLL_ENABLE); | |
5382 | /* Timeout 200us */ | |
5383 | if (wait_for(!(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK), | |
5384 | 1)) | |
5385 | DRM_ERROR("timout waiting for DE PLL unlock\n"); | |
5386 | } | |
5387 | ||
5388 | if (frequency != 19200) { | |
5389 | uint32_t val; | |
5390 | ||
5391 | val = I915_READ(BXT_DE_PLL_CTL); | |
5392 | val &= ~BXT_DE_PLL_RATIO_MASK; | |
5393 | val |= ratio; | |
5394 | I915_WRITE(BXT_DE_PLL_CTL, val); | |
5395 | ||
5396 | I915_WRITE(BXT_DE_PLL_ENABLE, BXT_DE_PLL_PLL_ENABLE); | |
5397 | /* Timeout 200us */ | |
5398 | if (wait_for(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK, 1)) | |
5399 | DRM_ERROR("timeout waiting for DE PLL lock\n"); | |
5400 | ||
5401 | val = I915_READ(CDCLK_CTL); | |
5402 | val &= ~BXT_CDCLK_CD2X_DIV_SEL_MASK; | |
5403 | val |= divider; | |
5404 | /* | |
5405 | * Disable SSA Precharge when CD clock frequency < 500 MHz, | |
5406 | * enable otherwise. | |
5407 | */ | |
5408 | val &= ~BXT_CDCLK_SSA_PRECHARGE_ENABLE; | |
5409 | if (frequency >= 500000) | |
5410 | val |= BXT_CDCLK_SSA_PRECHARGE_ENABLE; | |
5411 | ||
5412 | val &= ~CDCLK_FREQ_DECIMAL_MASK; | |
5413 | /* convert from kHz to .1 fixpoint MHz with -1MHz offset */ | |
5414 | val |= (frequency - 1000) / 500; | |
5415 | I915_WRITE(CDCLK_CTL, val); | |
5416 | } | |
5417 | ||
5418 | mutex_lock(&dev_priv->rps.hw_lock); | |
5419 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, | |
5420 | DIV_ROUND_UP(frequency, 25000)); | |
5421 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5422 | ||
5423 | if (ret) { | |
5424 | DRM_ERROR("PCode CDCLK freq set failed, (err %d, freq %d)\n", | |
5425 | ret, frequency); | |
5426 | return; | |
5427 | } | |
5428 | ||
a47871bd | 5429 | intel_update_cdclk(dev); |
f8437dd1 VK |
5430 | } |
5431 | ||
5432 | void broxton_init_cdclk(struct drm_device *dev) | |
5433 | { | |
5434 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5435 | uint32_t val; | |
5436 | ||
5437 | /* | |
5438 | * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT | |
5439 | * or else the reset will hang because there is no PCH to respond. | |
5440 | * Move the handshake programming to initialization sequence. | |
5441 | * Previously was left up to BIOS. | |
5442 | */ | |
5443 | val = I915_READ(HSW_NDE_RSTWRN_OPT); | |
5444 | val &= ~RESET_PCH_HANDSHAKE_ENABLE; | |
5445 | I915_WRITE(HSW_NDE_RSTWRN_OPT, val); | |
5446 | ||
5447 | /* Enable PG1 for cdclk */ | |
5448 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); | |
5449 | ||
5450 | /* check if cd clock is enabled */ | |
5451 | if (I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_PLL_ENABLE) { | |
5452 | DRM_DEBUG_KMS("Display already initialized\n"); | |
5453 | return; | |
5454 | } | |
5455 | ||
5456 | /* | |
5457 | * FIXME: | |
5458 | * - The initial CDCLK needs to be read from VBT. | |
5459 | * Need to make this change after VBT has changes for BXT. | |
5460 | * - check if setting the max (or any) cdclk freq is really necessary | |
5461 | * here, it belongs to modeset time | |
5462 | */ | |
5463 | broxton_set_cdclk(dev, 624000); | |
5464 | ||
5465 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); | |
22e02c0b VS |
5466 | POSTING_READ(DBUF_CTL); |
5467 | ||
f8437dd1 VK |
5468 | udelay(10); |
5469 | ||
5470 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) | |
5471 | DRM_ERROR("DBuf power enable timeout!\n"); | |
5472 | } | |
5473 | ||
5474 | void broxton_uninit_cdclk(struct drm_device *dev) | |
5475 | { | |
5476 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5477 | ||
5478 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST); | |
22e02c0b VS |
5479 | POSTING_READ(DBUF_CTL); |
5480 | ||
f8437dd1 VK |
5481 | udelay(10); |
5482 | ||
5483 | if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE) | |
5484 | DRM_ERROR("DBuf power disable timeout!\n"); | |
5485 | ||
5486 | /* Set minimum (bypass) frequency, in effect turning off the DE PLL */ | |
5487 | broxton_set_cdclk(dev, 19200); | |
5488 | ||
5489 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); | |
5490 | } | |
5491 | ||
5d96d8af DL |
5492 | static const struct skl_cdclk_entry { |
5493 | unsigned int freq; | |
5494 | unsigned int vco; | |
5495 | } skl_cdclk_frequencies[] = { | |
5496 | { .freq = 308570, .vco = 8640 }, | |
5497 | { .freq = 337500, .vco = 8100 }, | |
5498 | { .freq = 432000, .vco = 8640 }, | |
5499 | { .freq = 450000, .vco = 8100 }, | |
5500 | { .freq = 540000, .vco = 8100 }, | |
5501 | { .freq = 617140, .vco = 8640 }, | |
5502 | { .freq = 675000, .vco = 8100 }, | |
5503 | }; | |
5504 | ||
5505 | static unsigned int skl_cdclk_decimal(unsigned int freq) | |
5506 | { | |
5507 | return (freq - 1000) / 500; | |
5508 | } | |
5509 | ||
5510 | static unsigned int skl_cdclk_get_vco(unsigned int freq) | |
5511 | { | |
5512 | unsigned int i; | |
5513 | ||
5514 | for (i = 0; i < ARRAY_SIZE(skl_cdclk_frequencies); i++) { | |
5515 | const struct skl_cdclk_entry *e = &skl_cdclk_frequencies[i]; | |
5516 | ||
5517 | if (e->freq == freq) | |
5518 | return e->vco; | |
5519 | } | |
5520 | ||
5521 | return 8100; | |
5522 | } | |
5523 | ||
5524 | static void | |
5525 | skl_dpll0_enable(struct drm_i915_private *dev_priv, unsigned int required_vco) | |
5526 | { | |
5527 | unsigned int min_freq; | |
5528 | u32 val; | |
5529 | ||
5530 | /* select the minimum CDCLK before enabling DPLL 0 */ | |
5531 | val = I915_READ(CDCLK_CTL); | |
5532 | val &= ~CDCLK_FREQ_SEL_MASK | ~CDCLK_FREQ_DECIMAL_MASK; | |
5533 | val |= CDCLK_FREQ_337_308; | |
5534 | ||
5535 | if (required_vco == 8640) | |
5536 | min_freq = 308570; | |
5537 | else | |
5538 | min_freq = 337500; | |
5539 | ||
5540 | val = CDCLK_FREQ_337_308 | skl_cdclk_decimal(min_freq); | |
5541 | ||
5542 | I915_WRITE(CDCLK_CTL, val); | |
5543 | POSTING_READ(CDCLK_CTL); | |
5544 | ||
5545 | /* | |
5546 | * We always enable DPLL0 with the lowest link rate possible, but still | |
5547 | * taking into account the VCO required to operate the eDP panel at the | |
5548 | * desired frequency. The usual DP link rates operate with a VCO of | |
5549 | * 8100 while the eDP 1.4 alternate link rates need a VCO of 8640. | |
5550 | * The modeset code is responsible for the selection of the exact link | |
5551 | * rate later on, with the constraint of choosing a frequency that | |
5552 | * works with required_vco. | |
5553 | */ | |
5554 | val = I915_READ(DPLL_CTRL1); | |
5555 | ||
5556 | val &= ~(DPLL_CTRL1_HDMI_MODE(SKL_DPLL0) | DPLL_CTRL1_SSC(SKL_DPLL0) | | |
5557 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)); | |
5558 | val |= DPLL_CTRL1_OVERRIDE(SKL_DPLL0); | |
5559 | if (required_vco == 8640) | |
5560 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080, | |
5561 | SKL_DPLL0); | |
5562 | else | |
5563 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810, | |
5564 | SKL_DPLL0); | |
5565 | ||
5566 | I915_WRITE(DPLL_CTRL1, val); | |
5567 | POSTING_READ(DPLL_CTRL1); | |
5568 | ||
5569 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) | LCPLL_PLL_ENABLE); | |
5570 | ||
5571 | if (wait_for(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK, 5)) | |
5572 | DRM_ERROR("DPLL0 not locked\n"); | |
5573 | } | |
5574 | ||
5575 | static bool skl_cdclk_pcu_ready(struct drm_i915_private *dev_priv) | |
5576 | { | |
5577 | int ret; | |
5578 | u32 val; | |
5579 | ||
5580 | /* inform PCU we want to change CDCLK */ | |
5581 | val = SKL_CDCLK_PREPARE_FOR_CHANGE; | |
5582 | mutex_lock(&dev_priv->rps.hw_lock); | |
5583 | ret = sandybridge_pcode_read(dev_priv, SKL_PCODE_CDCLK_CONTROL, &val); | |
5584 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5585 | ||
5586 | return ret == 0 && (val & SKL_CDCLK_READY_FOR_CHANGE); | |
5587 | } | |
5588 | ||
5589 | static bool skl_cdclk_wait_for_pcu_ready(struct drm_i915_private *dev_priv) | |
5590 | { | |
5591 | unsigned int i; | |
5592 | ||
5593 | for (i = 0; i < 15; i++) { | |
5594 | if (skl_cdclk_pcu_ready(dev_priv)) | |
5595 | return true; | |
5596 | udelay(10); | |
5597 | } | |
5598 | ||
5599 | return false; | |
5600 | } | |
5601 | ||
5602 | static void skl_set_cdclk(struct drm_i915_private *dev_priv, unsigned int freq) | |
5603 | { | |
560a7ae4 | 5604 | struct drm_device *dev = dev_priv->dev; |
5d96d8af DL |
5605 | u32 freq_select, pcu_ack; |
5606 | ||
5607 | DRM_DEBUG_DRIVER("Changing CDCLK to %dKHz\n", freq); | |
5608 | ||
5609 | if (!skl_cdclk_wait_for_pcu_ready(dev_priv)) { | |
5610 | DRM_ERROR("failed to inform PCU about cdclk change\n"); | |
5611 | return; | |
5612 | } | |
5613 | ||
5614 | /* set CDCLK_CTL */ | |
5615 | switch(freq) { | |
5616 | case 450000: | |
5617 | case 432000: | |
5618 | freq_select = CDCLK_FREQ_450_432; | |
5619 | pcu_ack = 1; | |
5620 | break; | |
5621 | case 540000: | |
5622 | freq_select = CDCLK_FREQ_540; | |
5623 | pcu_ack = 2; | |
5624 | break; | |
5625 | case 308570: | |
5626 | case 337500: | |
5627 | default: | |
5628 | freq_select = CDCLK_FREQ_337_308; | |
5629 | pcu_ack = 0; | |
5630 | break; | |
5631 | case 617140: | |
5632 | case 675000: | |
5633 | freq_select = CDCLK_FREQ_675_617; | |
5634 | pcu_ack = 3; | |
5635 | break; | |
5636 | } | |
5637 | ||
5638 | I915_WRITE(CDCLK_CTL, freq_select | skl_cdclk_decimal(freq)); | |
5639 | POSTING_READ(CDCLK_CTL); | |
5640 | ||
5641 | /* inform PCU of the change */ | |
5642 | mutex_lock(&dev_priv->rps.hw_lock); | |
5643 | sandybridge_pcode_write(dev_priv, SKL_PCODE_CDCLK_CONTROL, pcu_ack); | |
5644 | mutex_unlock(&dev_priv->rps.hw_lock); | |
560a7ae4 DL |
5645 | |
5646 | intel_update_cdclk(dev); | |
5d96d8af DL |
5647 | } |
5648 | ||
5649 | void skl_uninit_cdclk(struct drm_i915_private *dev_priv) | |
5650 | { | |
5651 | /* disable DBUF power */ | |
5652 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST); | |
5653 | POSTING_READ(DBUF_CTL); | |
5654 | ||
5655 | udelay(10); | |
5656 | ||
5657 | if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE) | |
5658 | DRM_ERROR("DBuf power disable timeout\n"); | |
5659 | ||
5660 | /* disable DPLL0 */ | |
5661 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) & ~LCPLL_PLL_ENABLE); | |
5662 | if (wait_for(!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK), 1)) | |
5663 | DRM_ERROR("Couldn't disable DPLL0\n"); | |
5664 | ||
5665 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); | |
5666 | } | |
5667 | ||
5668 | void skl_init_cdclk(struct drm_i915_private *dev_priv) | |
5669 | { | |
5670 | u32 val; | |
5671 | unsigned int required_vco; | |
5672 | ||
5673 | /* enable PCH reset handshake */ | |
5674 | val = I915_READ(HSW_NDE_RSTWRN_OPT); | |
5675 | I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE); | |
5676 | ||
5677 | /* enable PG1 and Misc I/O */ | |
5678 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); | |
5679 | ||
5680 | /* DPLL0 already enabed !? */ | |
5681 | if (I915_READ(LCPLL1_CTL) & LCPLL_PLL_ENABLE) { | |
5682 | DRM_DEBUG_DRIVER("DPLL0 already running\n"); | |
5683 | return; | |
5684 | } | |
5685 | ||
5686 | /* enable DPLL0 */ | |
5687 | required_vco = skl_cdclk_get_vco(dev_priv->skl_boot_cdclk); | |
5688 | skl_dpll0_enable(dev_priv, required_vco); | |
5689 | ||
5690 | /* set CDCLK to the frequency the BIOS chose */ | |
5691 | skl_set_cdclk(dev_priv, dev_priv->skl_boot_cdclk); | |
5692 | ||
5693 | /* enable DBUF power */ | |
5694 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); | |
5695 | POSTING_READ(DBUF_CTL); | |
5696 | ||
5697 | udelay(10); | |
5698 | ||
5699 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) | |
5700 | DRM_ERROR("DBuf power enable timeout\n"); | |
5701 | } | |
5702 | ||
dfcab17e | 5703 | /* returns HPLL frequency in kHz */ |
f8bf63fd | 5704 | static int valleyview_get_vco(struct drm_i915_private *dev_priv) |
30a970c6 | 5705 | { |
586f49dc | 5706 | int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; |
30a970c6 | 5707 | |
586f49dc | 5708 | /* Obtain SKU information */ |
a580516d | 5709 | mutex_lock(&dev_priv->sb_lock); |
586f49dc JB |
5710 | hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & |
5711 | CCK_FUSE_HPLL_FREQ_MASK; | |
a580516d | 5712 | mutex_unlock(&dev_priv->sb_lock); |
30a970c6 | 5713 | |
dfcab17e | 5714 | return vco_freq[hpll_freq] * 1000; |
30a970c6 JB |
5715 | } |
5716 | ||
5717 | /* Adjust CDclk dividers to allow high res or save power if possible */ | |
5718 | static void valleyview_set_cdclk(struct drm_device *dev, int cdclk) | |
5719 | { | |
5720 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5721 | u32 val, cmd; | |
5722 | ||
164dfd28 VK |
5723 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
5724 | != dev_priv->cdclk_freq); | |
d60c4473 | 5725 | |
dfcab17e | 5726 | if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */ |
30a970c6 | 5727 | cmd = 2; |
dfcab17e | 5728 | else if (cdclk == 266667) |
30a970c6 JB |
5729 | cmd = 1; |
5730 | else | |
5731 | cmd = 0; | |
5732 | ||
5733 | mutex_lock(&dev_priv->rps.hw_lock); | |
5734 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); | |
5735 | val &= ~DSPFREQGUAR_MASK; | |
5736 | val |= (cmd << DSPFREQGUAR_SHIFT); | |
5737 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); | |
5738 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & | |
5739 | DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT), | |
5740 | 50)) { | |
5741 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
5742 | } | |
5743 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5744 | ||
54433e91 VS |
5745 | mutex_lock(&dev_priv->sb_lock); |
5746 | ||
dfcab17e | 5747 | if (cdclk == 400000) { |
6bcda4f0 | 5748 | u32 divider; |
30a970c6 | 5749 | |
6bcda4f0 | 5750 | divider = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
30a970c6 | 5751 | |
30a970c6 JB |
5752 | /* adjust cdclk divider */ |
5753 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); | |
9cf33db5 | 5754 | val &= ~DISPLAY_FREQUENCY_VALUES; |
30a970c6 JB |
5755 | val |= divider; |
5756 | vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val); | |
a877e801 VS |
5757 | |
5758 | if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) & | |
5759 | DISPLAY_FREQUENCY_STATUS) == (divider << DISPLAY_FREQUENCY_STATUS_SHIFT), | |
5760 | 50)) | |
5761 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
30a970c6 JB |
5762 | } |
5763 | ||
30a970c6 JB |
5764 | /* adjust self-refresh exit latency value */ |
5765 | val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC); | |
5766 | val &= ~0x7f; | |
5767 | ||
5768 | /* | |
5769 | * For high bandwidth configs, we set a higher latency in the bunit | |
5770 | * so that the core display fetch happens in time to avoid underruns. | |
5771 | */ | |
dfcab17e | 5772 | if (cdclk == 400000) |
30a970c6 JB |
5773 | val |= 4500 / 250; /* 4.5 usec */ |
5774 | else | |
5775 | val |= 3000 / 250; /* 3.0 usec */ | |
5776 | vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val); | |
54433e91 | 5777 | |
a580516d | 5778 | mutex_unlock(&dev_priv->sb_lock); |
30a970c6 | 5779 | |
b6283055 | 5780 | intel_update_cdclk(dev); |
30a970c6 JB |
5781 | } |
5782 | ||
383c5a6a VS |
5783 | static void cherryview_set_cdclk(struct drm_device *dev, int cdclk) |
5784 | { | |
5785 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5786 | u32 val, cmd; | |
5787 | ||
164dfd28 VK |
5788 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
5789 | != dev_priv->cdclk_freq); | |
383c5a6a VS |
5790 | |
5791 | switch (cdclk) { | |
383c5a6a VS |
5792 | case 333333: |
5793 | case 320000: | |
383c5a6a | 5794 | case 266667: |
383c5a6a | 5795 | case 200000: |
383c5a6a VS |
5796 | break; |
5797 | default: | |
5f77eeb0 | 5798 | MISSING_CASE(cdclk); |
383c5a6a VS |
5799 | return; |
5800 | } | |
5801 | ||
9d0d3fda VS |
5802 | /* |
5803 | * Specs are full of misinformation, but testing on actual | |
5804 | * hardware has shown that we just need to write the desired | |
5805 | * CCK divider into the Punit register. | |
5806 | */ | |
5807 | cmd = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; | |
5808 | ||
383c5a6a VS |
5809 | mutex_lock(&dev_priv->rps.hw_lock); |
5810 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); | |
5811 | val &= ~DSPFREQGUAR_MASK_CHV; | |
5812 | val |= (cmd << DSPFREQGUAR_SHIFT_CHV); | |
5813 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); | |
5814 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & | |
5815 | DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV), | |
5816 | 50)) { | |
5817 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
5818 | } | |
5819 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5820 | ||
b6283055 | 5821 | intel_update_cdclk(dev); |
383c5a6a VS |
5822 | } |
5823 | ||
30a970c6 JB |
5824 | static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv, |
5825 | int max_pixclk) | |
5826 | { | |
6bcda4f0 | 5827 | int freq_320 = (dev_priv->hpll_freq << 1) % 320000 != 0 ? 333333 : 320000; |
6cca3195 | 5828 | int limit = IS_CHERRYVIEW(dev_priv) ? 95 : 90; |
29dc7ef3 | 5829 | |
30a970c6 JB |
5830 | /* |
5831 | * Really only a few cases to deal with, as only 4 CDclks are supported: | |
5832 | * 200MHz | |
5833 | * 267MHz | |
29dc7ef3 | 5834 | * 320/333MHz (depends on HPLL freq) |
6cca3195 VS |
5835 | * 400MHz (VLV only) |
5836 | * So we check to see whether we're above 90% (VLV) or 95% (CHV) | |
5837 | * of the lower bin and adjust if needed. | |
e37c67a1 VS |
5838 | * |
5839 | * We seem to get an unstable or solid color picture at 200MHz. | |
5840 | * Not sure what's wrong. For now use 200MHz only when all pipes | |
5841 | * are off. | |
30a970c6 | 5842 | */ |
6cca3195 VS |
5843 | if (!IS_CHERRYVIEW(dev_priv) && |
5844 | max_pixclk > freq_320*limit/100) | |
dfcab17e | 5845 | return 400000; |
6cca3195 | 5846 | else if (max_pixclk > 266667*limit/100) |
29dc7ef3 | 5847 | return freq_320; |
e37c67a1 | 5848 | else if (max_pixclk > 0) |
dfcab17e | 5849 | return 266667; |
e37c67a1 VS |
5850 | else |
5851 | return 200000; | |
30a970c6 JB |
5852 | } |
5853 | ||
f8437dd1 VK |
5854 | static int broxton_calc_cdclk(struct drm_i915_private *dev_priv, |
5855 | int max_pixclk) | |
5856 | { | |
5857 | /* | |
5858 | * FIXME: | |
5859 | * - remove the guardband, it's not needed on BXT | |
5860 | * - set 19.2MHz bypass frequency if there are no active pipes | |
5861 | */ | |
5862 | if (max_pixclk > 576000*9/10) | |
5863 | return 624000; | |
5864 | else if (max_pixclk > 384000*9/10) | |
5865 | return 576000; | |
5866 | else if (max_pixclk > 288000*9/10) | |
5867 | return 384000; | |
5868 | else if (max_pixclk > 144000*9/10) | |
5869 | return 288000; | |
5870 | else | |
5871 | return 144000; | |
5872 | } | |
5873 | ||
a821fc46 ACO |
5874 | /* Compute the max pixel clock for new configuration. Uses atomic state if |
5875 | * that's non-NULL, look at current state otherwise. */ | |
5876 | static int intel_mode_max_pixclk(struct drm_device *dev, | |
5877 | struct drm_atomic_state *state) | |
30a970c6 | 5878 | { |
30a970c6 | 5879 | struct intel_crtc *intel_crtc; |
304603f4 | 5880 | struct intel_crtc_state *crtc_state; |
30a970c6 JB |
5881 | int max_pixclk = 0; |
5882 | ||
d3fcc808 | 5883 | for_each_intel_crtc(dev, intel_crtc) { |
a821fc46 ACO |
5884 | if (state) |
5885 | crtc_state = | |
5886 | intel_atomic_get_crtc_state(state, intel_crtc); | |
5887 | else | |
5888 | crtc_state = intel_crtc->config; | |
304603f4 ACO |
5889 | if (IS_ERR(crtc_state)) |
5890 | return PTR_ERR(crtc_state); | |
5891 | ||
5892 | if (!crtc_state->base.enable) | |
5893 | continue; | |
5894 | ||
5895 | max_pixclk = max(max_pixclk, | |
5896 | crtc_state->base.adjusted_mode.crtc_clock); | |
30a970c6 JB |
5897 | } |
5898 | ||
5899 | return max_pixclk; | |
5900 | } | |
5901 | ||
0a9ab303 | 5902 | static int valleyview_modeset_global_pipes(struct drm_atomic_state *state) |
30a970c6 | 5903 | { |
304603f4 | 5904 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
0a9ab303 ACO |
5905 | struct drm_crtc *crtc; |
5906 | struct drm_crtc_state *crtc_state; | |
a821fc46 | 5907 | int max_pixclk = intel_mode_max_pixclk(state->dev, state); |
85a96e7a | 5908 | int cdclk, ret = 0; |
30a970c6 | 5909 | |
304603f4 ACO |
5910 | if (max_pixclk < 0) |
5911 | return max_pixclk; | |
30a970c6 | 5912 | |
f8437dd1 VK |
5913 | if (IS_VALLEYVIEW(dev_priv)) |
5914 | cdclk = valleyview_calc_cdclk(dev_priv, max_pixclk); | |
5915 | else | |
5916 | cdclk = broxton_calc_cdclk(dev_priv, max_pixclk); | |
5917 | ||
5918 | if (cdclk == dev_priv->cdclk_freq) | |
304603f4 | 5919 | return 0; |
30a970c6 | 5920 | |
0a9ab303 ACO |
5921 | /* add all active pipes to the state */ |
5922 | for_each_crtc(state->dev, crtc) { | |
0a9ab303 ACO |
5923 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
5924 | if (IS_ERR(crtc_state)) | |
5925 | return PTR_ERR(crtc_state); | |
0a9ab303 | 5926 | |
85a96e7a ML |
5927 | if (!crtc_state->active || needs_modeset(crtc_state)) |
5928 | continue; | |
304603f4 | 5929 | |
85a96e7a ML |
5930 | crtc_state->mode_changed = true; |
5931 | ||
5932 | ret = drm_atomic_add_affected_connectors(state, crtc); | |
5933 | if (ret) | |
5934 | break; | |
5935 | ||
5936 | ret = drm_atomic_add_affected_planes(state, crtc); | |
5937 | if (ret) | |
5938 | break; | |
5939 | } | |
5940 | ||
5941 | return ret; | |
30a970c6 JB |
5942 | } |
5943 | ||
1e69cd74 VS |
5944 | static void vlv_program_pfi_credits(struct drm_i915_private *dev_priv) |
5945 | { | |
5946 | unsigned int credits, default_credits; | |
5947 | ||
5948 | if (IS_CHERRYVIEW(dev_priv)) | |
5949 | default_credits = PFI_CREDIT(12); | |
5950 | else | |
5951 | default_credits = PFI_CREDIT(8); | |
5952 | ||
164dfd28 | 5953 | if (DIV_ROUND_CLOSEST(dev_priv->cdclk_freq, 1000) >= dev_priv->rps.cz_freq) { |
1e69cd74 VS |
5954 | /* CHV suggested value is 31 or 63 */ |
5955 | if (IS_CHERRYVIEW(dev_priv)) | |
fcc0008f | 5956 | credits = PFI_CREDIT_63; |
1e69cd74 VS |
5957 | else |
5958 | credits = PFI_CREDIT(15); | |
5959 | } else { | |
5960 | credits = default_credits; | |
5961 | } | |
5962 | ||
5963 | /* | |
5964 | * WA - write default credits before re-programming | |
5965 | * FIXME: should we also set the resend bit here? | |
5966 | */ | |
5967 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | | |
5968 | default_credits); | |
5969 | ||
5970 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | | |
5971 | credits | PFI_CREDIT_RESEND); | |
5972 | ||
5973 | /* | |
5974 | * FIXME is this guaranteed to clear | |
5975 | * immediately or should we poll for it? | |
5976 | */ | |
5977 | WARN_ON(I915_READ(GCI_CONTROL) & PFI_CREDIT_RESEND); | |
5978 | } | |
5979 | ||
a821fc46 | 5980 | static void valleyview_modeset_global_resources(struct drm_atomic_state *old_state) |
30a970c6 | 5981 | { |
a821fc46 | 5982 | struct drm_device *dev = old_state->dev; |
30a970c6 | 5983 | struct drm_i915_private *dev_priv = dev->dev_private; |
a821fc46 | 5984 | int max_pixclk = intel_mode_max_pixclk(dev, NULL); |
304603f4 ACO |
5985 | int req_cdclk; |
5986 | ||
a821fc46 ACO |
5987 | /* The path in intel_mode_max_pixclk() with a NULL atomic state should |
5988 | * never fail. */ | |
304603f4 ACO |
5989 | if (WARN_ON(max_pixclk < 0)) |
5990 | return; | |
30a970c6 | 5991 | |
304603f4 | 5992 | req_cdclk = valleyview_calc_cdclk(dev_priv, max_pixclk); |
30a970c6 | 5993 | |
164dfd28 | 5994 | if (req_cdclk != dev_priv->cdclk_freq) { |
738c05c0 ID |
5995 | /* |
5996 | * FIXME: We can end up here with all power domains off, yet | |
5997 | * with a CDCLK frequency other than the minimum. To account | |
5998 | * for this take the PIPE-A power domain, which covers the HW | |
5999 | * blocks needed for the following programming. This can be | |
6000 | * removed once it's guaranteed that we get here either with | |
6001 | * the minimum CDCLK set, or the required power domains | |
6002 | * enabled. | |
6003 | */ | |
6004 | intel_display_power_get(dev_priv, POWER_DOMAIN_PIPE_A); | |
6005 | ||
383c5a6a VS |
6006 | if (IS_CHERRYVIEW(dev)) |
6007 | cherryview_set_cdclk(dev, req_cdclk); | |
6008 | else | |
6009 | valleyview_set_cdclk(dev, req_cdclk); | |
738c05c0 | 6010 | |
1e69cd74 VS |
6011 | vlv_program_pfi_credits(dev_priv); |
6012 | ||
738c05c0 | 6013 | intel_display_power_put(dev_priv, POWER_DOMAIN_PIPE_A); |
383c5a6a | 6014 | } |
30a970c6 JB |
6015 | } |
6016 | ||
89b667f8 JB |
6017 | static void valleyview_crtc_enable(struct drm_crtc *crtc) |
6018 | { | |
6019 | struct drm_device *dev = crtc->dev; | |
a72e4c9f | 6020 | struct drm_i915_private *dev_priv = to_i915(dev); |
89b667f8 JB |
6021 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
6022 | struct intel_encoder *encoder; | |
6023 | int pipe = intel_crtc->pipe; | |
23538ef1 | 6024 | bool is_dsi; |
89b667f8 | 6025 | |
53d9f4e9 | 6026 | if (WARN_ON(intel_crtc->active)) |
89b667f8 JB |
6027 | return; |
6028 | ||
409ee761 | 6029 | is_dsi = intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI); |
8525a235 | 6030 | |
1ae0d137 VS |
6031 | if (!is_dsi) { |
6032 | if (IS_CHERRYVIEW(dev)) | |
6e3c9717 | 6033 | chv_prepare_pll(intel_crtc, intel_crtc->config); |
1ae0d137 | 6034 | else |
6e3c9717 | 6035 | vlv_prepare_pll(intel_crtc, intel_crtc->config); |
1ae0d137 | 6036 | } |
5b18e57c | 6037 | |
6e3c9717 | 6038 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 6039 | intel_dp_set_m_n(intel_crtc, M1_N1); |
5b18e57c DV |
6040 | |
6041 | intel_set_pipe_timings(intel_crtc); | |
6042 | ||
c14b0485 VS |
6043 | if (IS_CHERRYVIEW(dev) && pipe == PIPE_B) { |
6044 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6045 | ||
6046 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); | |
6047 | I915_WRITE(CHV_CANVAS(pipe), 0); | |
6048 | } | |
6049 | ||
5b18e57c DV |
6050 | i9xx_set_pipeconf(intel_crtc); |
6051 | ||
89b667f8 | 6052 | intel_crtc->active = true; |
89b667f8 | 6053 | |
a72e4c9f | 6054 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4a3436e8 | 6055 | |
89b667f8 JB |
6056 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6057 | if (encoder->pre_pll_enable) | |
6058 | encoder->pre_pll_enable(encoder); | |
6059 | ||
9d556c99 CML |
6060 | if (!is_dsi) { |
6061 | if (IS_CHERRYVIEW(dev)) | |
6e3c9717 | 6062 | chv_enable_pll(intel_crtc, intel_crtc->config); |
9d556c99 | 6063 | else |
6e3c9717 | 6064 | vlv_enable_pll(intel_crtc, intel_crtc->config); |
9d556c99 | 6065 | } |
89b667f8 JB |
6066 | |
6067 | for_each_encoder_on_crtc(dev, crtc, encoder) | |
6068 | if (encoder->pre_enable) | |
6069 | encoder->pre_enable(encoder); | |
6070 | ||
2dd24552 JB |
6071 | i9xx_pfit_enable(intel_crtc); |
6072 | ||
63cbb074 VS |
6073 | intel_crtc_load_lut(crtc); |
6074 | ||
f37fcc2a | 6075 | intel_update_watermarks(crtc); |
e1fdc473 | 6076 | intel_enable_pipe(intel_crtc); |
be6a6f8e | 6077 | |
4b3a9526 VS |
6078 | assert_vblank_disabled(crtc); |
6079 | drm_crtc_vblank_on(crtc); | |
6080 | ||
f9b61ff6 DV |
6081 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6082 | encoder->enable(encoder); | |
89b667f8 JB |
6083 | } |
6084 | ||
f13c2ef3 DV |
6085 | static void i9xx_set_pll_dividers(struct intel_crtc *crtc) |
6086 | { | |
6087 | struct drm_device *dev = crtc->base.dev; | |
6088 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6089 | ||
6e3c9717 ACO |
6090 | I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0); |
6091 | I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1); | |
f13c2ef3 DV |
6092 | } |
6093 | ||
0b8765c6 | 6094 | static void i9xx_crtc_enable(struct drm_crtc *crtc) |
79e53945 JB |
6095 | { |
6096 | struct drm_device *dev = crtc->dev; | |
a72e4c9f | 6097 | struct drm_i915_private *dev_priv = to_i915(dev); |
79e53945 | 6098 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
ef9c3aee | 6099 | struct intel_encoder *encoder; |
79e53945 | 6100 | int pipe = intel_crtc->pipe; |
79e53945 | 6101 | |
53d9f4e9 | 6102 | if (WARN_ON(intel_crtc->active)) |
f7abfe8b CW |
6103 | return; |
6104 | ||
f13c2ef3 DV |
6105 | i9xx_set_pll_dividers(intel_crtc); |
6106 | ||
6e3c9717 | 6107 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 6108 | intel_dp_set_m_n(intel_crtc, M1_N1); |
5b18e57c DV |
6109 | |
6110 | intel_set_pipe_timings(intel_crtc); | |
6111 | ||
5b18e57c DV |
6112 | i9xx_set_pipeconf(intel_crtc); |
6113 | ||
f7abfe8b | 6114 | intel_crtc->active = true; |
6b383a7f | 6115 | |
4a3436e8 | 6116 | if (!IS_GEN2(dev)) |
a72e4c9f | 6117 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4a3436e8 | 6118 | |
9d6d9f19 MK |
6119 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6120 | if (encoder->pre_enable) | |
6121 | encoder->pre_enable(encoder); | |
6122 | ||
f6736a1a DV |
6123 | i9xx_enable_pll(intel_crtc); |
6124 | ||
2dd24552 JB |
6125 | i9xx_pfit_enable(intel_crtc); |
6126 | ||
63cbb074 VS |
6127 | intel_crtc_load_lut(crtc); |
6128 | ||
f37fcc2a | 6129 | intel_update_watermarks(crtc); |
e1fdc473 | 6130 | intel_enable_pipe(intel_crtc); |
be6a6f8e | 6131 | |
4b3a9526 VS |
6132 | assert_vblank_disabled(crtc); |
6133 | drm_crtc_vblank_on(crtc); | |
6134 | ||
f9b61ff6 DV |
6135 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6136 | encoder->enable(encoder); | |
0b8765c6 | 6137 | } |
79e53945 | 6138 | |
87476d63 DV |
6139 | static void i9xx_pfit_disable(struct intel_crtc *crtc) |
6140 | { | |
6141 | struct drm_device *dev = crtc->base.dev; | |
6142 | struct drm_i915_private *dev_priv = dev->dev_private; | |
87476d63 | 6143 | |
6e3c9717 | 6144 | if (!crtc->config->gmch_pfit.control) |
328d8e82 | 6145 | return; |
87476d63 | 6146 | |
328d8e82 | 6147 | assert_pipe_disabled(dev_priv, crtc->pipe); |
87476d63 | 6148 | |
328d8e82 DV |
6149 | DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", |
6150 | I915_READ(PFIT_CONTROL)); | |
6151 | I915_WRITE(PFIT_CONTROL, 0); | |
87476d63 DV |
6152 | } |
6153 | ||
0b8765c6 JB |
6154 | static void i9xx_crtc_disable(struct drm_crtc *crtc) |
6155 | { | |
6156 | struct drm_device *dev = crtc->dev; | |
6157 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6158 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 6159 | struct intel_encoder *encoder; |
0b8765c6 | 6160 | int pipe = intel_crtc->pipe; |
ef9c3aee | 6161 | |
53d9f4e9 | 6162 | if (WARN_ON(!intel_crtc->active)) |
f7abfe8b CW |
6163 | return; |
6164 | ||
6304cd91 VS |
6165 | /* |
6166 | * On gen2 planes are double buffered but the pipe isn't, so we must | |
6167 | * wait for planes to fully turn off before disabling the pipe. | |
564ed191 ID |
6168 | * We also need to wait on all gmch platforms because of the |
6169 | * self-refresh mode constraint explained above. | |
6304cd91 | 6170 | */ |
564ed191 | 6171 | intel_wait_for_vblank(dev, pipe); |
6304cd91 | 6172 | |
4b3a9526 VS |
6173 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6174 | encoder->disable(encoder); | |
6175 | ||
f9b61ff6 DV |
6176 | drm_crtc_vblank_off(crtc); |
6177 | assert_vblank_disabled(crtc); | |
6178 | ||
575f7ab7 | 6179 | intel_disable_pipe(intel_crtc); |
24a1f16d | 6180 | |
87476d63 | 6181 | i9xx_pfit_disable(intel_crtc); |
24a1f16d | 6182 | |
89b667f8 JB |
6183 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6184 | if (encoder->post_disable) | |
6185 | encoder->post_disable(encoder); | |
6186 | ||
409ee761 | 6187 | if (!intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) { |
076ed3b2 CML |
6188 | if (IS_CHERRYVIEW(dev)) |
6189 | chv_disable_pll(dev_priv, pipe); | |
6190 | else if (IS_VALLEYVIEW(dev)) | |
6191 | vlv_disable_pll(dev_priv, pipe); | |
6192 | else | |
1c4e0274 | 6193 | i9xx_disable_pll(intel_crtc); |
076ed3b2 | 6194 | } |
0b8765c6 | 6195 | |
4a3436e8 | 6196 | if (!IS_GEN2(dev)) |
a72e4c9f | 6197 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
4a3436e8 | 6198 | |
f7abfe8b | 6199 | intel_crtc->active = false; |
46ba614c | 6200 | intel_update_watermarks(crtc); |
f37fcc2a | 6201 | |
efa9624e | 6202 | mutex_lock(&dev->struct_mutex); |
7ff0ebcc | 6203 | intel_fbc_update(dev); |
efa9624e | 6204 | mutex_unlock(&dev->struct_mutex); |
0b8765c6 JB |
6205 | } |
6206 | ||
b17d48e2 ML |
6207 | static void intel_crtc_disable_noatomic(struct drm_crtc *crtc) |
6208 | { | |
6209 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6210 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); | |
6211 | enum intel_display_power_domain domain; | |
6212 | unsigned long domains; | |
6213 | ||
6214 | if (!intel_crtc->active) | |
6215 | return; | |
6216 | ||
6217 | intel_crtc_disable_planes(crtc); | |
6218 | dev_priv->display.crtc_disable(crtc); | |
6219 | ||
6220 | domains = intel_crtc->enabled_power_domains; | |
6221 | for_each_power_domain(domain, domains) | |
6222 | intel_display_power_put(dev_priv, domain); | |
6223 | intel_crtc->enabled_power_domains = 0; | |
6224 | } | |
6225 | ||
6b72d486 ML |
6226 | /* |
6227 | * turn all crtc's off, but do not adjust state | |
6228 | * This has to be paired with a call to intel_modeset_setup_hw_state. | |
6229 | */ | |
9716c691 | 6230 | void intel_display_suspend(struct drm_device *dev) |
ee7b9f93 | 6231 | { |
6b72d486 ML |
6232 | struct drm_crtc *crtc; |
6233 | ||
b17d48e2 ML |
6234 | for_each_crtc(dev, crtc) |
6235 | intel_crtc_disable_noatomic(crtc); | |
ee7b9f93 JB |
6236 | } |
6237 | ||
b04c5bd6 | 6238 | /* Master function to enable/disable CRTC and corresponding power wells */ |
5da76e94 | 6239 | int intel_crtc_control(struct drm_crtc *crtc, bool enable) |
976f8a20 DV |
6240 | { |
6241 | struct drm_device *dev = crtc->dev; | |
5da76e94 ML |
6242 | struct drm_mode_config *config = &dev->mode_config; |
6243 | struct drm_modeset_acquire_ctx *ctx = config->acquire_ctx; | |
0e572fe7 | 6244 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
5da76e94 ML |
6245 | struct intel_crtc_state *pipe_config; |
6246 | struct drm_atomic_state *state; | |
6247 | int ret; | |
976f8a20 | 6248 | |
1b509259 | 6249 | if (enable == intel_crtc->active) |
5da76e94 | 6250 | return 0; |
0e572fe7 | 6251 | |
1b509259 | 6252 | if (enable && !crtc->state->enable) |
5da76e94 | 6253 | return 0; |
1b509259 | 6254 | |
5da76e94 ML |
6255 | /* this function should be called with drm_modeset_lock_all for now */ |
6256 | if (WARN_ON(!ctx)) | |
6257 | return -EIO; | |
6258 | lockdep_assert_held(&ctx->ww_ctx); | |
1b509259 | 6259 | |
5da76e94 ML |
6260 | state = drm_atomic_state_alloc(dev); |
6261 | if (WARN_ON(!state)) | |
6262 | return -ENOMEM; | |
1b509259 | 6263 | |
5da76e94 ML |
6264 | state->acquire_ctx = ctx; |
6265 | state->allow_modeset = true; | |
6266 | ||
6267 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); | |
6268 | if (IS_ERR(pipe_config)) { | |
6269 | ret = PTR_ERR(pipe_config); | |
6270 | goto err; | |
0e572fe7 | 6271 | } |
5da76e94 ML |
6272 | pipe_config->base.active = enable; |
6273 | ||
6274 | ret = intel_set_mode(state); | |
6275 | if (!ret) | |
6276 | return ret; | |
6277 | ||
6278 | err: | |
6279 | DRM_ERROR("Updating crtc active failed with %i\n", ret); | |
6280 | drm_atomic_state_free(state); | |
6281 | return ret; | |
b04c5bd6 BF |
6282 | } |
6283 | ||
6284 | /** | |
6285 | * Sets the power management mode of the pipe and plane. | |
6286 | */ | |
6287 | void intel_crtc_update_dpms(struct drm_crtc *crtc) | |
6288 | { | |
6289 | struct drm_device *dev = crtc->dev; | |
6290 | struct intel_encoder *intel_encoder; | |
6291 | bool enable = false; | |
6292 | ||
6293 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) | |
6294 | enable |= intel_encoder->connectors_active; | |
6295 | ||
6296 | intel_crtc_control(crtc, enable); | |
cdd59983 CW |
6297 | } |
6298 | ||
ea5b213a | 6299 | void intel_encoder_destroy(struct drm_encoder *encoder) |
7e7d76c3 | 6300 | { |
4ef69c7a | 6301 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
ea5b213a | 6302 | |
ea5b213a CW |
6303 | drm_encoder_cleanup(encoder); |
6304 | kfree(intel_encoder); | |
7e7d76c3 JB |
6305 | } |
6306 | ||
9237329d | 6307 | /* Simple dpms helper for encoders with just one connector, no cloning and only |
5ab432ef DV |
6308 | * one kind of off state. It clamps all !ON modes to fully OFF and changes the |
6309 | * state of the entire output pipe. */ | |
9237329d | 6310 | static void intel_encoder_dpms(struct intel_encoder *encoder, int mode) |
7e7d76c3 | 6311 | { |
5ab432ef DV |
6312 | if (mode == DRM_MODE_DPMS_ON) { |
6313 | encoder->connectors_active = true; | |
6314 | ||
b2cabb0e | 6315 | intel_crtc_update_dpms(encoder->base.crtc); |
5ab432ef DV |
6316 | } else { |
6317 | encoder->connectors_active = false; | |
6318 | ||
b2cabb0e | 6319 | intel_crtc_update_dpms(encoder->base.crtc); |
5ab432ef | 6320 | } |
79e53945 JB |
6321 | } |
6322 | ||
0a91ca29 DV |
6323 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
6324 | * internal consistency). */ | |
b980514c | 6325 | static void intel_connector_check_state(struct intel_connector *connector) |
79e53945 | 6326 | { |
0a91ca29 DV |
6327 | if (connector->get_hw_state(connector)) { |
6328 | struct intel_encoder *encoder = connector->encoder; | |
6329 | struct drm_crtc *crtc; | |
6330 | bool encoder_enabled; | |
6331 | enum pipe pipe; | |
6332 | ||
6333 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", | |
6334 | connector->base.base.id, | |
c23cc417 | 6335 | connector->base.name); |
0a91ca29 | 6336 | |
0e32b39c DA |
6337 | /* there is no real hw state for MST connectors */ |
6338 | if (connector->mst_port) | |
6339 | return; | |
6340 | ||
e2c719b7 | 6341 | I915_STATE_WARN(connector->base.dpms == DRM_MODE_DPMS_OFF, |
0a91ca29 | 6342 | "wrong connector dpms state\n"); |
e2c719b7 | 6343 | I915_STATE_WARN(connector->base.encoder != &encoder->base, |
0a91ca29 | 6344 | "active connector not linked to encoder\n"); |
0a91ca29 | 6345 | |
36cd7444 | 6346 | if (encoder) { |
e2c719b7 | 6347 | I915_STATE_WARN(!encoder->connectors_active, |
36cd7444 DA |
6348 | "encoder->connectors_active not set\n"); |
6349 | ||
6350 | encoder_enabled = encoder->get_hw_state(encoder, &pipe); | |
e2c719b7 RC |
6351 | I915_STATE_WARN(!encoder_enabled, "encoder not enabled\n"); |
6352 | if (I915_STATE_WARN_ON(!encoder->base.crtc)) | |
36cd7444 | 6353 | return; |
0a91ca29 | 6354 | |
36cd7444 | 6355 | crtc = encoder->base.crtc; |
0a91ca29 | 6356 | |
83d65738 MR |
6357 | I915_STATE_WARN(!crtc->state->enable, |
6358 | "crtc not enabled\n"); | |
e2c719b7 RC |
6359 | I915_STATE_WARN(!to_intel_crtc(crtc)->active, "crtc not active\n"); |
6360 | I915_STATE_WARN(pipe != to_intel_crtc(crtc)->pipe, | |
36cd7444 DA |
6361 | "encoder active on the wrong pipe\n"); |
6362 | } | |
0a91ca29 | 6363 | } |
79e53945 JB |
6364 | } |
6365 | ||
08d9bc92 ACO |
6366 | int intel_connector_init(struct intel_connector *connector) |
6367 | { | |
6368 | struct drm_connector_state *connector_state; | |
6369 | ||
6370 | connector_state = kzalloc(sizeof *connector_state, GFP_KERNEL); | |
6371 | if (!connector_state) | |
6372 | return -ENOMEM; | |
6373 | ||
6374 | connector->base.state = connector_state; | |
6375 | return 0; | |
6376 | } | |
6377 | ||
6378 | struct intel_connector *intel_connector_alloc(void) | |
6379 | { | |
6380 | struct intel_connector *connector; | |
6381 | ||
6382 | connector = kzalloc(sizeof *connector, GFP_KERNEL); | |
6383 | if (!connector) | |
6384 | return NULL; | |
6385 | ||
6386 | if (intel_connector_init(connector) < 0) { | |
6387 | kfree(connector); | |
6388 | return NULL; | |
6389 | } | |
6390 | ||
6391 | return connector; | |
6392 | } | |
6393 | ||
5ab432ef DV |
6394 | /* Even simpler default implementation, if there's really no special case to |
6395 | * consider. */ | |
6396 | void intel_connector_dpms(struct drm_connector *connector, int mode) | |
79e53945 | 6397 | { |
5ab432ef DV |
6398 | /* All the simple cases only support two dpms states. */ |
6399 | if (mode != DRM_MODE_DPMS_ON) | |
6400 | mode = DRM_MODE_DPMS_OFF; | |
d4270e57 | 6401 | |
5ab432ef DV |
6402 | if (mode == connector->dpms) |
6403 | return; | |
6404 | ||
6405 | connector->dpms = mode; | |
6406 | ||
6407 | /* Only need to change hw state when actually enabled */ | |
c9976dcf CW |
6408 | if (connector->encoder) |
6409 | intel_encoder_dpms(to_intel_encoder(connector->encoder), mode); | |
0a91ca29 | 6410 | |
b980514c | 6411 | intel_modeset_check_state(connector->dev); |
79e53945 JB |
6412 | } |
6413 | ||
f0947c37 DV |
6414 | /* Simple connector->get_hw_state implementation for encoders that support only |
6415 | * one connector and no cloning and hence the encoder state determines the state | |
6416 | * of the connector. */ | |
6417 | bool intel_connector_get_hw_state(struct intel_connector *connector) | |
ea5b213a | 6418 | { |
24929352 | 6419 | enum pipe pipe = 0; |
f0947c37 | 6420 | struct intel_encoder *encoder = connector->encoder; |
ea5b213a | 6421 | |
f0947c37 | 6422 | return encoder->get_hw_state(encoder, &pipe); |
ea5b213a CW |
6423 | } |
6424 | ||
6d293983 | 6425 | static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state) |
d272ddfa | 6426 | { |
6d293983 ACO |
6427 | if (crtc_state->base.enable && crtc_state->has_pch_encoder) |
6428 | return crtc_state->fdi_lanes; | |
d272ddfa VS |
6429 | |
6430 | return 0; | |
6431 | } | |
6432 | ||
6d293983 | 6433 | static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe, |
5cec258b | 6434 | struct intel_crtc_state *pipe_config) |
1857e1da | 6435 | { |
6d293983 ACO |
6436 | struct drm_atomic_state *state = pipe_config->base.state; |
6437 | struct intel_crtc *other_crtc; | |
6438 | struct intel_crtc_state *other_crtc_state; | |
6439 | ||
1857e1da DV |
6440 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
6441 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6442 | if (pipe_config->fdi_lanes > 4) { | |
6443 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", | |
6444 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6445 | return -EINVAL; |
1857e1da DV |
6446 | } |
6447 | ||
bafb6553 | 6448 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
1857e1da DV |
6449 | if (pipe_config->fdi_lanes > 2) { |
6450 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", | |
6451 | pipe_config->fdi_lanes); | |
6d293983 | 6452 | return -EINVAL; |
1857e1da | 6453 | } else { |
6d293983 | 6454 | return 0; |
1857e1da DV |
6455 | } |
6456 | } | |
6457 | ||
6458 | if (INTEL_INFO(dev)->num_pipes == 2) | |
6d293983 | 6459 | return 0; |
1857e1da DV |
6460 | |
6461 | /* Ivybridge 3 pipe is really complicated */ | |
6462 | switch (pipe) { | |
6463 | case PIPE_A: | |
6d293983 | 6464 | return 0; |
1857e1da | 6465 | case PIPE_B: |
6d293983 ACO |
6466 | if (pipe_config->fdi_lanes <= 2) |
6467 | return 0; | |
6468 | ||
6469 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_C)); | |
6470 | other_crtc_state = | |
6471 | intel_atomic_get_crtc_state(state, other_crtc); | |
6472 | if (IS_ERR(other_crtc_state)) | |
6473 | return PTR_ERR(other_crtc_state); | |
6474 | ||
6475 | if (pipe_required_fdi_lanes(other_crtc_state) > 0) { | |
1857e1da DV |
6476 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
6477 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6478 | return -EINVAL; |
1857e1da | 6479 | } |
6d293983 | 6480 | return 0; |
1857e1da | 6481 | case PIPE_C: |
251cc67c VS |
6482 | if (pipe_config->fdi_lanes > 2) { |
6483 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", | |
6484 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6485 | return -EINVAL; |
251cc67c | 6486 | } |
6d293983 ACO |
6487 | |
6488 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_B)); | |
6489 | other_crtc_state = | |
6490 | intel_atomic_get_crtc_state(state, other_crtc); | |
6491 | if (IS_ERR(other_crtc_state)) | |
6492 | return PTR_ERR(other_crtc_state); | |
6493 | ||
6494 | if (pipe_required_fdi_lanes(other_crtc_state) > 2) { | |
1857e1da | 6495 | DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n"); |
6d293983 | 6496 | return -EINVAL; |
1857e1da | 6497 | } |
6d293983 | 6498 | return 0; |
1857e1da DV |
6499 | default: |
6500 | BUG(); | |
6501 | } | |
6502 | } | |
6503 | ||
e29c22c0 DV |
6504 | #define RETRY 1 |
6505 | static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc, | |
5cec258b | 6506 | struct intel_crtc_state *pipe_config) |
877d48d5 | 6507 | { |
1857e1da | 6508 | struct drm_device *dev = intel_crtc->base.dev; |
2d112de7 | 6509 | struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
6d293983 ACO |
6510 | int lane, link_bw, fdi_dotclock, ret; |
6511 | bool needs_recompute = false; | |
877d48d5 | 6512 | |
e29c22c0 | 6513 | retry: |
877d48d5 DV |
6514 | /* FDI is a binary signal running at ~2.7GHz, encoding |
6515 | * each output octet as 10 bits. The actual frequency | |
6516 | * is stored as a divider into a 100MHz clock, and the | |
6517 | * mode pixel clock is stored in units of 1KHz. | |
6518 | * Hence the bw of each lane in terms of the mode signal | |
6519 | * is: | |
6520 | */ | |
6521 | link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10; | |
6522 | ||
241bfc38 | 6523 | fdi_dotclock = adjusted_mode->crtc_clock; |
877d48d5 | 6524 | |
2bd89a07 | 6525 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
877d48d5 DV |
6526 | pipe_config->pipe_bpp); |
6527 | ||
6528 | pipe_config->fdi_lanes = lane; | |
6529 | ||
2bd89a07 | 6530 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
877d48d5 | 6531 | link_bw, &pipe_config->fdi_m_n); |
1857e1da | 6532 | |
6d293983 ACO |
6533 | ret = ironlake_check_fdi_lanes(intel_crtc->base.dev, |
6534 | intel_crtc->pipe, pipe_config); | |
6535 | if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) { | |
e29c22c0 DV |
6536 | pipe_config->pipe_bpp -= 2*3; |
6537 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", | |
6538 | pipe_config->pipe_bpp); | |
6539 | needs_recompute = true; | |
6540 | pipe_config->bw_constrained = true; | |
6541 | ||
6542 | goto retry; | |
6543 | } | |
6544 | ||
6545 | if (needs_recompute) | |
6546 | return RETRY; | |
6547 | ||
6d293983 | 6548 | return ret; |
877d48d5 DV |
6549 | } |
6550 | ||
8cfb3407 VS |
6551 | static bool pipe_config_supports_ips(struct drm_i915_private *dev_priv, |
6552 | struct intel_crtc_state *pipe_config) | |
6553 | { | |
6554 | if (pipe_config->pipe_bpp > 24) | |
6555 | return false; | |
6556 | ||
6557 | /* HSW can handle pixel rate up to cdclk? */ | |
6558 | if (IS_HASWELL(dev_priv->dev)) | |
6559 | return true; | |
6560 | ||
6561 | /* | |
b432e5cf VS |
6562 | * We compare against max which means we must take |
6563 | * the increased cdclk requirement into account when | |
6564 | * calculating the new cdclk. | |
6565 | * | |
6566 | * Should measure whether using a lower cdclk w/o IPS | |
8cfb3407 VS |
6567 | */ |
6568 | return ilk_pipe_pixel_rate(pipe_config) <= | |
6569 | dev_priv->max_cdclk_freq * 95 / 100; | |
6570 | } | |
6571 | ||
42db64ef | 6572 | static void hsw_compute_ips_config(struct intel_crtc *crtc, |
5cec258b | 6573 | struct intel_crtc_state *pipe_config) |
42db64ef | 6574 | { |
8cfb3407 VS |
6575 | struct drm_device *dev = crtc->base.dev; |
6576 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6577 | ||
d330a953 | 6578 | pipe_config->ips_enabled = i915.enable_ips && |
8cfb3407 VS |
6579 | hsw_crtc_supports_ips(crtc) && |
6580 | pipe_config_supports_ips(dev_priv, pipe_config); | |
42db64ef PZ |
6581 | } |
6582 | ||
a43f6e0f | 6583 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
5cec258b | 6584 | struct intel_crtc_state *pipe_config) |
79e53945 | 6585 | { |
a43f6e0f | 6586 | struct drm_device *dev = crtc->base.dev; |
8bd31e67 | 6587 | struct drm_i915_private *dev_priv = dev->dev_private; |
2d112de7 | 6588 | struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
89749350 | 6589 | |
ad3a4479 | 6590 | /* FIXME should check pixel clock limits on all platforms */ |
cf532bb2 | 6591 | if (INTEL_INFO(dev)->gen < 4) { |
44913155 | 6592 | int clock_limit = dev_priv->max_cdclk_freq; |
cf532bb2 VS |
6593 | |
6594 | /* | |
6595 | * Enable pixel doubling when the dot clock | |
6596 | * is > 90% of the (display) core speed. | |
6597 | * | |
b397c96b VS |
6598 | * GDG double wide on either pipe, |
6599 | * otherwise pipe A only. | |
cf532bb2 | 6600 | */ |
b397c96b | 6601 | if ((crtc->pipe == PIPE_A || IS_I915G(dev)) && |
241bfc38 | 6602 | adjusted_mode->crtc_clock > clock_limit * 9 / 10) { |
ad3a4479 | 6603 | clock_limit *= 2; |
cf532bb2 | 6604 | pipe_config->double_wide = true; |
ad3a4479 VS |
6605 | } |
6606 | ||
241bfc38 | 6607 | if (adjusted_mode->crtc_clock > clock_limit * 9 / 10) |
e29c22c0 | 6608 | return -EINVAL; |
2c07245f | 6609 | } |
89749350 | 6610 | |
1d1d0e27 VS |
6611 | /* |
6612 | * Pipe horizontal size must be even in: | |
6613 | * - DVO ganged mode | |
6614 | * - LVDS dual channel mode | |
6615 | * - Double wide pipe | |
6616 | */ | |
a93e255f | 6617 | if ((intel_pipe_will_have_type(pipe_config, INTEL_OUTPUT_LVDS) && |
1d1d0e27 VS |
6618 | intel_is_dual_link_lvds(dev)) || pipe_config->double_wide) |
6619 | pipe_config->pipe_src_w &= ~1; | |
6620 | ||
8693a824 DL |
6621 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
6622 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. | |
44f46b42 CW |
6623 | */ |
6624 | if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) && | |
6625 | adjusted_mode->hsync_start == adjusted_mode->hdisplay) | |
e29c22c0 | 6626 | return -EINVAL; |
44f46b42 | 6627 | |
f5adf94e | 6628 | if (HAS_IPS(dev)) |
a43f6e0f DV |
6629 | hsw_compute_ips_config(crtc, pipe_config); |
6630 | ||
877d48d5 | 6631 | if (pipe_config->has_pch_encoder) |
a43f6e0f | 6632 | return ironlake_fdi_compute_config(crtc, pipe_config); |
877d48d5 | 6633 | |
cf5a15be | 6634 | return 0; |
79e53945 JB |
6635 | } |
6636 | ||
1652d19e VS |
6637 | static int skylake_get_display_clock_speed(struct drm_device *dev) |
6638 | { | |
6639 | struct drm_i915_private *dev_priv = to_i915(dev); | |
6640 | uint32_t lcpll1 = I915_READ(LCPLL1_CTL); | |
6641 | uint32_t cdctl = I915_READ(CDCLK_CTL); | |
6642 | uint32_t linkrate; | |
6643 | ||
414355a7 | 6644 | if (!(lcpll1 & LCPLL_PLL_ENABLE)) |
1652d19e | 6645 | return 24000; /* 24MHz is the cd freq with NSSC ref */ |
1652d19e VS |
6646 | |
6647 | if ((cdctl & CDCLK_FREQ_SEL_MASK) == CDCLK_FREQ_540) | |
6648 | return 540000; | |
6649 | ||
6650 | linkrate = (I915_READ(DPLL_CTRL1) & | |
71cd8423 | 6651 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)) >> 1; |
1652d19e | 6652 | |
71cd8423 DL |
6653 | if (linkrate == DPLL_CTRL1_LINK_RATE_2160 || |
6654 | linkrate == DPLL_CTRL1_LINK_RATE_1080) { | |
1652d19e VS |
6655 | /* vco 8640 */ |
6656 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { | |
6657 | case CDCLK_FREQ_450_432: | |
6658 | return 432000; | |
6659 | case CDCLK_FREQ_337_308: | |
6660 | return 308570; | |
6661 | case CDCLK_FREQ_675_617: | |
6662 | return 617140; | |
6663 | default: | |
6664 | WARN(1, "Unknown cd freq selection\n"); | |
6665 | } | |
6666 | } else { | |
6667 | /* vco 8100 */ | |
6668 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { | |
6669 | case CDCLK_FREQ_450_432: | |
6670 | return 450000; | |
6671 | case CDCLK_FREQ_337_308: | |
6672 | return 337500; | |
6673 | case CDCLK_FREQ_675_617: | |
6674 | return 675000; | |
6675 | default: | |
6676 | WARN(1, "Unknown cd freq selection\n"); | |
6677 | } | |
6678 | } | |
6679 | ||
6680 | /* error case, do as if DPLL0 isn't enabled */ | |
6681 | return 24000; | |
6682 | } | |
6683 | ||
6684 | static int broadwell_get_display_clock_speed(struct drm_device *dev) | |
6685 | { | |
6686 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6687 | uint32_t lcpll = I915_READ(LCPLL_CTL); | |
6688 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; | |
6689 | ||
6690 | if (lcpll & LCPLL_CD_SOURCE_FCLK) | |
6691 | return 800000; | |
6692 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
6693 | return 450000; | |
6694 | else if (freq == LCPLL_CLK_FREQ_450) | |
6695 | return 450000; | |
6696 | else if (freq == LCPLL_CLK_FREQ_54O_BDW) | |
6697 | return 540000; | |
6698 | else if (freq == LCPLL_CLK_FREQ_337_5_BDW) | |
6699 | return 337500; | |
6700 | else | |
6701 | return 675000; | |
6702 | } | |
6703 | ||
6704 | static int haswell_get_display_clock_speed(struct drm_device *dev) | |
6705 | { | |
6706 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6707 | uint32_t lcpll = I915_READ(LCPLL_CTL); | |
6708 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; | |
6709 | ||
6710 | if (lcpll & LCPLL_CD_SOURCE_FCLK) | |
6711 | return 800000; | |
6712 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
6713 | return 450000; | |
6714 | else if (freq == LCPLL_CLK_FREQ_450) | |
6715 | return 450000; | |
6716 | else if (IS_HSW_ULT(dev)) | |
6717 | return 337500; | |
6718 | else | |
6719 | return 540000; | |
79e53945 JB |
6720 | } |
6721 | ||
25eb05fc JB |
6722 | static int valleyview_get_display_clock_speed(struct drm_device *dev) |
6723 | { | |
d197b7d3 | 6724 | struct drm_i915_private *dev_priv = dev->dev_private; |
d197b7d3 VS |
6725 | u32 val; |
6726 | int divider; | |
6727 | ||
6bcda4f0 VS |
6728 | if (dev_priv->hpll_freq == 0) |
6729 | dev_priv->hpll_freq = valleyview_get_vco(dev_priv); | |
6730 | ||
a580516d | 6731 | mutex_lock(&dev_priv->sb_lock); |
d197b7d3 | 6732 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); |
a580516d | 6733 | mutex_unlock(&dev_priv->sb_lock); |
d197b7d3 VS |
6734 | |
6735 | divider = val & DISPLAY_FREQUENCY_VALUES; | |
6736 | ||
7d007f40 VS |
6737 | WARN((val & DISPLAY_FREQUENCY_STATUS) != |
6738 | (divider << DISPLAY_FREQUENCY_STATUS_SHIFT), | |
6739 | "cdclk change in progress\n"); | |
6740 | ||
6bcda4f0 | 6741 | return DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, divider + 1); |
25eb05fc JB |
6742 | } |
6743 | ||
b37a6434 VS |
6744 | static int ilk_get_display_clock_speed(struct drm_device *dev) |
6745 | { | |
6746 | return 450000; | |
6747 | } | |
6748 | ||
e70236a8 JB |
6749 | static int i945_get_display_clock_speed(struct drm_device *dev) |
6750 | { | |
6751 | return 400000; | |
6752 | } | |
79e53945 | 6753 | |
e70236a8 | 6754 | static int i915_get_display_clock_speed(struct drm_device *dev) |
79e53945 | 6755 | { |
e907f170 | 6756 | return 333333; |
e70236a8 | 6757 | } |
79e53945 | 6758 | |
e70236a8 JB |
6759 | static int i9xx_misc_get_display_clock_speed(struct drm_device *dev) |
6760 | { | |
6761 | return 200000; | |
6762 | } | |
79e53945 | 6763 | |
257a7ffc DV |
6764 | static int pnv_get_display_clock_speed(struct drm_device *dev) |
6765 | { | |
6766 | u16 gcfgc = 0; | |
6767 | ||
6768 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); | |
6769 | ||
6770 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { | |
6771 | case GC_DISPLAY_CLOCK_267_MHZ_PNV: | |
e907f170 | 6772 | return 266667; |
257a7ffc | 6773 | case GC_DISPLAY_CLOCK_333_MHZ_PNV: |
e907f170 | 6774 | return 333333; |
257a7ffc | 6775 | case GC_DISPLAY_CLOCK_444_MHZ_PNV: |
e907f170 | 6776 | return 444444; |
257a7ffc DV |
6777 | case GC_DISPLAY_CLOCK_200_MHZ_PNV: |
6778 | return 200000; | |
6779 | default: | |
6780 | DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc); | |
6781 | case GC_DISPLAY_CLOCK_133_MHZ_PNV: | |
e907f170 | 6782 | return 133333; |
257a7ffc | 6783 | case GC_DISPLAY_CLOCK_167_MHZ_PNV: |
e907f170 | 6784 | return 166667; |
257a7ffc DV |
6785 | } |
6786 | } | |
6787 | ||
e70236a8 JB |
6788 | static int i915gm_get_display_clock_speed(struct drm_device *dev) |
6789 | { | |
6790 | u16 gcfgc = 0; | |
79e53945 | 6791 | |
e70236a8 JB |
6792 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
6793 | ||
6794 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) | |
e907f170 | 6795 | return 133333; |
e70236a8 JB |
6796 | else { |
6797 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { | |
6798 | case GC_DISPLAY_CLOCK_333_MHZ: | |
e907f170 | 6799 | return 333333; |
e70236a8 JB |
6800 | default: |
6801 | case GC_DISPLAY_CLOCK_190_200_MHZ: | |
6802 | return 190000; | |
79e53945 | 6803 | } |
e70236a8 JB |
6804 | } |
6805 | } | |
6806 | ||
6807 | static int i865_get_display_clock_speed(struct drm_device *dev) | |
6808 | { | |
e907f170 | 6809 | return 266667; |
e70236a8 JB |
6810 | } |
6811 | ||
1b1d2716 | 6812 | static int i85x_get_display_clock_speed(struct drm_device *dev) |
e70236a8 JB |
6813 | { |
6814 | u16 hpllcc = 0; | |
1b1d2716 | 6815 | |
65cd2b3f VS |
6816 | /* |
6817 | * 852GM/852GMV only supports 133 MHz and the HPLLCC | |
6818 | * encoding is different :( | |
6819 | * FIXME is this the right way to detect 852GM/852GMV? | |
6820 | */ | |
6821 | if (dev->pdev->revision == 0x1) | |
6822 | return 133333; | |
6823 | ||
1b1d2716 VS |
6824 | pci_bus_read_config_word(dev->pdev->bus, |
6825 | PCI_DEVFN(0, 3), HPLLCC, &hpllcc); | |
6826 | ||
e70236a8 JB |
6827 | /* Assume that the hardware is in the high speed state. This |
6828 | * should be the default. | |
6829 | */ | |
6830 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { | |
6831 | case GC_CLOCK_133_200: | |
1b1d2716 | 6832 | case GC_CLOCK_133_200_2: |
e70236a8 JB |
6833 | case GC_CLOCK_100_200: |
6834 | return 200000; | |
6835 | case GC_CLOCK_166_250: | |
6836 | return 250000; | |
6837 | case GC_CLOCK_100_133: | |
e907f170 | 6838 | return 133333; |
1b1d2716 VS |
6839 | case GC_CLOCK_133_266: |
6840 | case GC_CLOCK_133_266_2: | |
6841 | case GC_CLOCK_166_266: | |
6842 | return 266667; | |
e70236a8 | 6843 | } |
79e53945 | 6844 | |
e70236a8 JB |
6845 | /* Shouldn't happen */ |
6846 | return 0; | |
6847 | } | |
79e53945 | 6848 | |
e70236a8 JB |
6849 | static int i830_get_display_clock_speed(struct drm_device *dev) |
6850 | { | |
e907f170 | 6851 | return 133333; |
79e53945 JB |
6852 | } |
6853 | ||
34edce2f VS |
6854 | static unsigned int intel_hpll_vco(struct drm_device *dev) |
6855 | { | |
6856 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6857 | static const unsigned int blb_vco[8] = { | |
6858 | [0] = 3200000, | |
6859 | [1] = 4000000, | |
6860 | [2] = 5333333, | |
6861 | [3] = 4800000, | |
6862 | [4] = 6400000, | |
6863 | }; | |
6864 | static const unsigned int pnv_vco[8] = { | |
6865 | [0] = 3200000, | |
6866 | [1] = 4000000, | |
6867 | [2] = 5333333, | |
6868 | [3] = 4800000, | |
6869 | [4] = 2666667, | |
6870 | }; | |
6871 | static const unsigned int cl_vco[8] = { | |
6872 | [0] = 3200000, | |
6873 | [1] = 4000000, | |
6874 | [2] = 5333333, | |
6875 | [3] = 6400000, | |
6876 | [4] = 3333333, | |
6877 | [5] = 3566667, | |
6878 | [6] = 4266667, | |
6879 | }; | |
6880 | static const unsigned int elk_vco[8] = { | |
6881 | [0] = 3200000, | |
6882 | [1] = 4000000, | |
6883 | [2] = 5333333, | |
6884 | [3] = 4800000, | |
6885 | }; | |
6886 | static const unsigned int ctg_vco[8] = { | |
6887 | [0] = 3200000, | |
6888 | [1] = 4000000, | |
6889 | [2] = 5333333, | |
6890 | [3] = 6400000, | |
6891 | [4] = 2666667, | |
6892 | [5] = 4266667, | |
6893 | }; | |
6894 | const unsigned int *vco_table; | |
6895 | unsigned int vco; | |
6896 | uint8_t tmp = 0; | |
6897 | ||
6898 | /* FIXME other chipsets? */ | |
6899 | if (IS_GM45(dev)) | |
6900 | vco_table = ctg_vco; | |
6901 | else if (IS_G4X(dev)) | |
6902 | vco_table = elk_vco; | |
6903 | else if (IS_CRESTLINE(dev)) | |
6904 | vco_table = cl_vco; | |
6905 | else if (IS_PINEVIEW(dev)) | |
6906 | vco_table = pnv_vco; | |
6907 | else if (IS_G33(dev)) | |
6908 | vco_table = blb_vco; | |
6909 | else | |
6910 | return 0; | |
6911 | ||
6912 | tmp = I915_READ(IS_MOBILE(dev) ? HPLLVCO_MOBILE : HPLLVCO); | |
6913 | ||
6914 | vco = vco_table[tmp & 0x7]; | |
6915 | if (vco == 0) | |
6916 | DRM_ERROR("Bad HPLL VCO (HPLLVCO=0x%02x)\n", tmp); | |
6917 | else | |
6918 | DRM_DEBUG_KMS("HPLL VCO %u kHz\n", vco); | |
6919 | ||
6920 | return vco; | |
6921 | } | |
6922 | ||
6923 | static int gm45_get_display_clock_speed(struct drm_device *dev) | |
6924 | { | |
6925 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
6926 | uint16_t tmp = 0; | |
6927 | ||
6928 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
6929 | ||
6930 | cdclk_sel = (tmp >> 12) & 0x1; | |
6931 | ||
6932 | switch (vco) { | |
6933 | case 2666667: | |
6934 | case 4000000: | |
6935 | case 5333333: | |
6936 | return cdclk_sel ? 333333 : 222222; | |
6937 | case 3200000: | |
6938 | return cdclk_sel ? 320000 : 228571; | |
6939 | default: | |
6940 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u, CFGC=0x%04x\n", vco, tmp); | |
6941 | return 222222; | |
6942 | } | |
6943 | } | |
6944 | ||
6945 | static int i965gm_get_display_clock_speed(struct drm_device *dev) | |
6946 | { | |
6947 | static const uint8_t div_3200[] = { 16, 10, 8 }; | |
6948 | static const uint8_t div_4000[] = { 20, 12, 10 }; | |
6949 | static const uint8_t div_5333[] = { 24, 16, 14 }; | |
6950 | const uint8_t *div_table; | |
6951 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
6952 | uint16_t tmp = 0; | |
6953 | ||
6954 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
6955 | ||
6956 | cdclk_sel = ((tmp >> 8) & 0x1f) - 1; | |
6957 | ||
6958 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) | |
6959 | goto fail; | |
6960 | ||
6961 | switch (vco) { | |
6962 | case 3200000: | |
6963 | div_table = div_3200; | |
6964 | break; | |
6965 | case 4000000: | |
6966 | div_table = div_4000; | |
6967 | break; | |
6968 | case 5333333: | |
6969 | div_table = div_5333; | |
6970 | break; | |
6971 | default: | |
6972 | goto fail; | |
6973 | } | |
6974 | ||
6975 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); | |
6976 | ||
caf4e252 | 6977 | fail: |
34edce2f VS |
6978 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%04x\n", vco, tmp); |
6979 | return 200000; | |
6980 | } | |
6981 | ||
6982 | static int g33_get_display_clock_speed(struct drm_device *dev) | |
6983 | { | |
6984 | static const uint8_t div_3200[] = { 12, 10, 8, 7, 5, 16 }; | |
6985 | static const uint8_t div_4000[] = { 14, 12, 10, 8, 6, 20 }; | |
6986 | static const uint8_t div_4800[] = { 20, 14, 12, 10, 8, 24 }; | |
6987 | static const uint8_t div_5333[] = { 20, 16, 12, 12, 8, 28 }; | |
6988 | const uint8_t *div_table; | |
6989 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
6990 | uint16_t tmp = 0; | |
6991 | ||
6992 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
6993 | ||
6994 | cdclk_sel = (tmp >> 4) & 0x7; | |
6995 | ||
6996 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) | |
6997 | goto fail; | |
6998 | ||
6999 | switch (vco) { | |
7000 | case 3200000: | |
7001 | div_table = div_3200; | |
7002 | break; | |
7003 | case 4000000: | |
7004 | div_table = div_4000; | |
7005 | break; | |
7006 | case 4800000: | |
7007 | div_table = div_4800; | |
7008 | break; | |
7009 | case 5333333: | |
7010 | div_table = div_5333; | |
7011 | break; | |
7012 | default: | |
7013 | goto fail; | |
7014 | } | |
7015 | ||
7016 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); | |
7017 | ||
caf4e252 | 7018 | fail: |
34edce2f VS |
7019 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%08x\n", vco, tmp); |
7020 | return 190476; | |
7021 | } | |
7022 | ||
2c07245f | 7023 | static void |
a65851af | 7024 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
2c07245f | 7025 | { |
a65851af VS |
7026 | while (*num > DATA_LINK_M_N_MASK || |
7027 | *den > DATA_LINK_M_N_MASK) { | |
2c07245f ZW |
7028 | *num >>= 1; |
7029 | *den >>= 1; | |
7030 | } | |
7031 | } | |
7032 | ||
a65851af VS |
7033 | static void compute_m_n(unsigned int m, unsigned int n, |
7034 | uint32_t *ret_m, uint32_t *ret_n) | |
7035 | { | |
7036 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); | |
7037 | *ret_m = div_u64((uint64_t) m * *ret_n, n); | |
7038 | intel_reduce_m_n_ratio(ret_m, ret_n); | |
7039 | } | |
7040 | ||
e69d0bc1 DV |
7041 | void |
7042 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, | |
7043 | int pixel_clock, int link_clock, | |
7044 | struct intel_link_m_n *m_n) | |
2c07245f | 7045 | { |
e69d0bc1 | 7046 | m_n->tu = 64; |
a65851af VS |
7047 | |
7048 | compute_m_n(bits_per_pixel * pixel_clock, | |
7049 | link_clock * nlanes * 8, | |
7050 | &m_n->gmch_m, &m_n->gmch_n); | |
7051 | ||
7052 | compute_m_n(pixel_clock, link_clock, | |
7053 | &m_n->link_m, &m_n->link_n); | |
2c07245f ZW |
7054 | } |
7055 | ||
a7615030 CW |
7056 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
7057 | { | |
d330a953 JN |
7058 | if (i915.panel_use_ssc >= 0) |
7059 | return i915.panel_use_ssc != 0; | |
41aa3448 | 7060 | return dev_priv->vbt.lvds_use_ssc |
435793df | 7061 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
a7615030 CW |
7062 | } |
7063 | ||
a93e255f ACO |
7064 | static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state, |
7065 | int num_connectors) | |
c65d77d8 | 7066 | { |
a93e255f | 7067 | struct drm_device *dev = crtc_state->base.crtc->dev; |
c65d77d8 JB |
7068 | struct drm_i915_private *dev_priv = dev->dev_private; |
7069 | int refclk; | |
7070 | ||
a93e255f ACO |
7071 | WARN_ON(!crtc_state->base.state); |
7072 | ||
5ab7b0b7 | 7073 | if (IS_VALLEYVIEW(dev) || IS_BROXTON(dev)) { |
9a0ea498 | 7074 | refclk = 100000; |
a93e255f | 7075 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
c65d77d8 | 7076 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) { |
e91e941b VS |
7077 | refclk = dev_priv->vbt.lvds_ssc_freq; |
7078 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); | |
c65d77d8 JB |
7079 | } else if (!IS_GEN2(dev)) { |
7080 | refclk = 96000; | |
7081 | } else { | |
7082 | refclk = 48000; | |
7083 | } | |
7084 | ||
7085 | return refclk; | |
7086 | } | |
7087 | ||
7429e9d4 | 7088 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
c65d77d8 | 7089 | { |
7df00d7a | 7090 | return (1 << dpll->n) << 16 | dpll->m2; |
7429e9d4 | 7091 | } |
f47709a9 | 7092 | |
7429e9d4 DV |
7093 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
7094 | { | |
7095 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; | |
c65d77d8 JB |
7096 | } |
7097 | ||
f47709a9 | 7098 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
190f68c5 | 7099 | struct intel_crtc_state *crtc_state, |
a7516a05 JB |
7100 | intel_clock_t *reduced_clock) |
7101 | { | |
f47709a9 | 7102 | struct drm_device *dev = crtc->base.dev; |
a7516a05 JB |
7103 | u32 fp, fp2 = 0; |
7104 | ||
7105 | if (IS_PINEVIEW(dev)) { | |
190f68c5 | 7106 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
a7516a05 | 7107 | if (reduced_clock) |
7429e9d4 | 7108 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
a7516a05 | 7109 | } else { |
190f68c5 | 7110 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
a7516a05 | 7111 | if (reduced_clock) |
7429e9d4 | 7112 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
a7516a05 JB |
7113 | } |
7114 | ||
190f68c5 | 7115 | crtc_state->dpll_hw_state.fp0 = fp; |
a7516a05 | 7116 | |
f47709a9 | 7117 | crtc->lowfreq_avail = false; |
a93e255f | 7118 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
ab585dea | 7119 | reduced_clock) { |
190f68c5 | 7120 | crtc_state->dpll_hw_state.fp1 = fp2; |
f47709a9 | 7121 | crtc->lowfreq_avail = true; |
a7516a05 | 7122 | } else { |
190f68c5 | 7123 | crtc_state->dpll_hw_state.fp1 = fp; |
a7516a05 JB |
7124 | } |
7125 | } | |
7126 | ||
5e69f97f CML |
7127 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
7128 | pipe) | |
89b667f8 JB |
7129 | { |
7130 | u32 reg_val; | |
7131 | ||
7132 | /* | |
7133 | * PLLB opamp always calibrates to max value of 0x3f, force enable it | |
7134 | * and set it to a reasonable value instead. | |
7135 | */ | |
ab3c759a | 7136 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
89b667f8 JB |
7137 | reg_val &= 0xffffff00; |
7138 | reg_val |= 0x00000030; | |
ab3c759a | 7139 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
89b667f8 | 7140 | |
ab3c759a | 7141 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
89b667f8 JB |
7142 | reg_val &= 0x8cffffff; |
7143 | reg_val = 0x8c000000; | |
ab3c759a | 7144 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
89b667f8 | 7145 | |
ab3c759a | 7146 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
89b667f8 | 7147 | reg_val &= 0xffffff00; |
ab3c759a | 7148 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
89b667f8 | 7149 | |
ab3c759a | 7150 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
89b667f8 JB |
7151 | reg_val &= 0x00ffffff; |
7152 | reg_val |= 0xb0000000; | |
ab3c759a | 7153 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
89b667f8 JB |
7154 | } |
7155 | ||
b551842d DV |
7156 | static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc, |
7157 | struct intel_link_m_n *m_n) | |
7158 | { | |
7159 | struct drm_device *dev = crtc->base.dev; | |
7160 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7161 | int pipe = crtc->pipe; | |
7162 | ||
e3b95f1e DV |
7163 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
7164 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); | |
7165 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); | |
7166 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); | |
b551842d DV |
7167 | } |
7168 | ||
7169 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, | |
f769cd24 VK |
7170 | struct intel_link_m_n *m_n, |
7171 | struct intel_link_m_n *m2_n2) | |
b551842d DV |
7172 | { |
7173 | struct drm_device *dev = crtc->base.dev; | |
7174 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7175 | int pipe = crtc->pipe; | |
6e3c9717 | 7176 | enum transcoder transcoder = crtc->config->cpu_transcoder; |
b551842d DV |
7177 | |
7178 | if (INTEL_INFO(dev)->gen >= 5) { | |
7179 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); | |
7180 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); | |
7181 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); | |
7182 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); | |
f769cd24 VK |
7183 | /* M2_N2 registers to be set only for gen < 8 (M2_N2 available |
7184 | * for gen < 8) and if DRRS is supported (to make sure the | |
7185 | * registers are not unnecessarily accessed). | |
7186 | */ | |
44395bfe | 7187 | if (m2_n2 && (IS_CHERRYVIEW(dev) || INTEL_INFO(dev)->gen < 8) && |
6e3c9717 | 7188 | crtc->config->has_drrs) { |
f769cd24 VK |
7189 | I915_WRITE(PIPE_DATA_M2(transcoder), |
7190 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); | |
7191 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); | |
7192 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); | |
7193 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); | |
7194 | } | |
b551842d | 7195 | } else { |
e3b95f1e DV |
7196 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
7197 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); | |
7198 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); | |
7199 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); | |
b551842d DV |
7200 | } |
7201 | } | |
7202 | ||
fe3cd48d | 7203 | void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n) |
03afc4a2 | 7204 | { |
fe3cd48d R |
7205 | struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL; |
7206 | ||
7207 | if (m_n == M1_N1) { | |
7208 | dp_m_n = &crtc->config->dp_m_n; | |
7209 | dp_m2_n2 = &crtc->config->dp_m2_n2; | |
7210 | } else if (m_n == M2_N2) { | |
7211 | ||
7212 | /* | |
7213 | * M2_N2 registers are not supported. Hence m2_n2 divider value | |
7214 | * needs to be programmed into M1_N1. | |
7215 | */ | |
7216 | dp_m_n = &crtc->config->dp_m2_n2; | |
7217 | } else { | |
7218 | DRM_ERROR("Unsupported divider value\n"); | |
7219 | return; | |
7220 | } | |
7221 | ||
6e3c9717 ACO |
7222 | if (crtc->config->has_pch_encoder) |
7223 | intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n); | |
03afc4a2 | 7224 | else |
fe3cd48d | 7225 | intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2); |
03afc4a2 DV |
7226 | } |
7227 | ||
d288f65f | 7228 | static void vlv_update_pll(struct intel_crtc *crtc, |
5cec258b | 7229 | struct intel_crtc_state *pipe_config) |
bdd4b6a6 DV |
7230 | { |
7231 | u32 dpll, dpll_md; | |
7232 | ||
7233 | /* | |
7234 | * Enable DPIO clock input. We should never disable the reference | |
7235 | * clock for pipe B, since VGA hotplug / manual detection depends | |
7236 | * on it. | |
7237 | */ | |
7238 | dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REFA_CLK_ENABLE_VLV | | |
7239 | DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_CLOCK_VLV; | |
7240 | /* We should never disable this, set it here for state tracking */ | |
7241 | if (crtc->pipe == PIPE_B) | |
7242 | dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
7243 | dpll |= DPLL_VCO_ENABLE; | |
d288f65f | 7244 | pipe_config->dpll_hw_state.dpll = dpll; |
bdd4b6a6 | 7245 | |
d288f65f | 7246 | dpll_md = (pipe_config->pixel_multiplier - 1) |
bdd4b6a6 | 7247 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
d288f65f | 7248 | pipe_config->dpll_hw_state.dpll_md = dpll_md; |
bdd4b6a6 DV |
7249 | } |
7250 | ||
d288f65f | 7251 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 7252 | const struct intel_crtc_state *pipe_config) |
a0c4da24 | 7253 | { |
f47709a9 | 7254 | struct drm_device *dev = crtc->base.dev; |
a0c4da24 | 7255 | struct drm_i915_private *dev_priv = dev->dev_private; |
f47709a9 | 7256 | int pipe = crtc->pipe; |
bdd4b6a6 | 7257 | u32 mdiv; |
a0c4da24 | 7258 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
bdd4b6a6 | 7259 | u32 coreclk, reg_val; |
a0c4da24 | 7260 | |
a580516d | 7261 | mutex_lock(&dev_priv->sb_lock); |
09153000 | 7262 | |
d288f65f VS |
7263 | bestn = pipe_config->dpll.n; |
7264 | bestm1 = pipe_config->dpll.m1; | |
7265 | bestm2 = pipe_config->dpll.m2; | |
7266 | bestp1 = pipe_config->dpll.p1; | |
7267 | bestp2 = pipe_config->dpll.p2; | |
a0c4da24 | 7268 | |
89b667f8 JB |
7269 | /* See eDP HDMI DPIO driver vbios notes doc */ |
7270 | ||
7271 | /* PLL B needs special handling */ | |
bdd4b6a6 | 7272 | if (pipe == PIPE_B) |
5e69f97f | 7273 | vlv_pllb_recal_opamp(dev_priv, pipe); |
89b667f8 JB |
7274 | |
7275 | /* Set up Tx target for periodic Rcomp update */ | |
ab3c759a | 7276 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
89b667f8 JB |
7277 | |
7278 | /* Disable target IRef on PLL */ | |
ab3c759a | 7279 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
89b667f8 | 7280 | reg_val &= 0x00ffffff; |
ab3c759a | 7281 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
89b667f8 JB |
7282 | |
7283 | /* Disable fast lock */ | |
ab3c759a | 7284 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
89b667f8 JB |
7285 | |
7286 | /* Set idtafcrecal before PLL is enabled */ | |
a0c4da24 JB |
7287 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
7288 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); | |
7289 | mdiv |= ((bestn << DPIO_N_SHIFT)); | |
a0c4da24 | 7290 | mdiv |= (1 << DPIO_K_SHIFT); |
7df5080b JB |
7291 | |
7292 | /* | |
7293 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, | |
7294 | * but we don't support that). | |
7295 | * Note: don't use the DAC post divider as it seems unstable. | |
7296 | */ | |
7297 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); | |
ab3c759a | 7298 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
a0c4da24 | 7299 | |
a0c4da24 | 7300 | mdiv |= DPIO_ENABLE_CALIBRATION; |
ab3c759a | 7301 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
a0c4da24 | 7302 | |
89b667f8 | 7303 | /* Set HBR and RBR LPF coefficients */ |
d288f65f | 7304 | if (pipe_config->port_clock == 162000 || |
409ee761 ACO |
7305 | intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG) || |
7306 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) | |
ab3c759a | 7307 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
885b0120 | 7308 | 0x009f0003); |
89b667f8 | 7309 | else |
ab3c759a | 7310 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
89b667f8 JB |
7311 | 0x00d0000f); |
7312 | ||
681a8504 | 7313 | if (pipe_config->has_dp_encoder) { |
89b667f8 | 7314 | /* Use SSC source */ |
bdd4b6a6 | 7315 | if (pipe == PIPE_A) |
ab3c759a | 7316 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7317 | 0x0df40000); |
7318 | else | |
ab3c759a | 7319 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7320 | 0x0df70000); |
7321 | } else { /* HDMI or VGA */ | |
7322 | /* Use bend source */ | |
bdd4b6a6 | 7323 | if (pipe == PIPE_A) |
ab3c759a | 7324 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7325 | 0x0df70000); |
7326 | else | |
ab3c759a | 7327 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7328 | 0x0df40000); |
7329 | } | |
a0c4da24 | 7330 | |
ab3c759a | 7331 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
89b667f8 | 7332 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
409ee761 ACO |
7333 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || |
7334 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) | |
89b667f8 | 7335 | coreclk |= 0x01000000; |
ab3c759a | 7336 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
a0c4da24 | 7337 | |
ab3c759a | 7338 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
a580516d | 7339 | mutex_unlock(&dev_priv->sb_lock); |
a0c4da24 JB |
7340 | } |
7341 | ||
d288f65f | 7342 | static void chv_update_pll(struct intel_crtc *crtc, |
5cec258b | 7343 | struct intel_crtc_state *pipe_config) |
1ae0d137 | 7344 | { |
d288f65f | 7345 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLOCK_CHV | |
1ae0d137 VS |
7346 | DPLL_REFA_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS | |
7347 | DPLL_VCO_ENABLE; | |
7348 | if (crtc->pipe != PIPE_A) | |
d288f65f | 7349 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
1ae0d137 | 7350 | |
d288f65f VS |
7351 | pipe_config->dpll_hw_state.dpll_md = |
7352 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; | |
1ae0d137 VS |
7353 | } |
7354 | ||
d288f65f | 7355 | static void chv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 7356 | const struct intel_crtc_state *pipe_config) |
9d556c99 CML |
7357 | { |
7358 | struct drm_device *dev = crtc->base.dev; | |
7359 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7360 | int pipe = crtc->pipe; | |
7361 | int dpll_reg = DPLL(crtc->pipe); | |
7362 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
9cbe40c1 | 7363 | u32 loopfilter, tribuf_calcntr; |
9d556c99 | 7364 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
a945ce7e | 7365 | u32 dpio_val; |
9cbe40c1 | 7366 | int vco; |
9d556c99 | 7367 | |
d288f65f VS |
7368 | bestn = pipe_config->dpll.n; |
7369 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; | |
7370 | bestm1 = pipe_config->dpll.m1; | |
7371 | bestm2 = pipe_config->dpll.m2 >> 22; | |
7372 | bestp1 = pipe_config->dpll.p1; | |
7373 | bestp2 = pipe_config->dpll.p2; | |
9cbe40c1 | 7374 | vco = pipe_config->dpll.vco; |
a945ce7e | 7375 | dpio_val = 0; |
9cbe40c1 | 7376 | loopfilter = 0; |
9d556c99 CML |
7377 | |
7378 | /* | |
7379 | * Enable Refclk and SSC | |
7380 | */ | |
a11b0703 | 7381 | I915_WRITE(dpll_reg, |
d288f65f | 7382 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
a11b0703 | 7383 | |
a580516d | 7384 | mutex_lock(&dev_priv->sb_lock); |
9d556c99 | 7385 | |
9d556c99 CML |
7386 | /* p1 and p2 divider */ |
7387 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), | |
7388 | 5 << DPIO_CHV_S1_DIV_SHIFT | | |
7389 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | | |
7390 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | | |
7391 | 1 << DPIO_CHV_K_DIV_SHIFT); | |
7392 | ||
7393 | /* Feedback post-divider - m2 */ | |
7394 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); | |
7395 | ||
7396 | /* Feedback refclk divider - n and m1 */ | |
7397 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), | |
7398 | DPIO_CHV_M1_DIV_BY_2 | | |
7399 | 1 << DPIO_CHV_N_DIV_SHIFT); | |
7400 | ||
7401 | /* M2 fraction division */ | |
a945ce7e VP |
7402 | if (bestm2_frac) |
7403 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac); | |
9d556c99 CML |
7404 | |
7405 | /* M2 fraction division enable */ | |
a945ce7e VP |
7406 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
7407 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); | |
7408 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); | |
7409 | if (bestm2_frac) | |
7410 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; | |
7411 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val); | |
9d556c99 | 7412 | |
de3a0fde VP |
7413 | /* Program digital lock detect threshold */ |
7414 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); | |
7415 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | | |
7416 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); | |
7417 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); | |
7418 | if (!bestm2_frac) | |
7419 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; | |
7420 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); | |
7421 | ||
9d556c99 | 7422 | /* Loop filter */ |
9cbe40c1 VP |
7423 | if (vco == 5400000) { |
7424 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7425 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); | |
7426 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7427 | tribuf_calcntr = 0x9; | |
7428 | } else if (vco <= 6200000) { | |
7429 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7430 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); | |
7431 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7432 | tribuf_calcntr = 0x9; | |
7433 | } else if (vco <= 6480000) { | |
7434 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7435 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); | |
7436 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7437 | tribuf_calcntr = 0x8; | |
7438 | } else { | |
7439 | /* Not supported. Apply the same limits as in the max case */ | |
7440 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7441 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); | |
7442 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7443 | tribuf_calcntr = 0; | |
7444 | } | |
9d556c99 CML |
7445 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
7446 | ||
968040b2 | 7447 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
9cbe40c1 VP |
7448 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
7449 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); | |
7450 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); | |
7451 | ||
9d556c99 CML |
7452 | /* AFC Recal */ |
7453 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), | |
7454 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | | |
7455 | DPIO_AFC_RECAL); | |
7456 | ||
a580516d | 7457 | mutex_unlock(&dev_priv->sb_lock); |
9d556c99 CML |
7458 | } |
7459 | ||
d288f65f VS |
7460 | /** |
7461 | * vlv_force_pll_on - forcibly enable just the PLL | |
7462 | * @dev_priv: i915 private structure | |
7463 | * @pipe: pipe PLL to enable | |
7464 | * @dpll: PLL configuration | |
7465 | * | |
7466 | * Enable the PLL for @pipe using the supplied @dpll config. To be used | |
7467 | * in cases where we need the PLL enabled even when @pipe is not going to | |
7468 | * be enabled. | |
7469 | */ | |
7470 | void vlv_force_pll_on(struct drm_device *dev, enum pipe pipe, | |
7471 | const struct dpll *dpll) | |
7472 | { | |
7473 | struct intel_crtc *crtc = | |
7474 | to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe)); | |
5cec258b | 7475 | struct intel_crtc_state pipe_config = { |
a93e255f | 7476 | .base.crtc = &crtc->base, |
d288f65f VS |
7477 | .pixel_multiplier = 1, |
7478 | .dpll = *dpll, | |
7479 | }; | |
7480 | ||
7481 | if (IS_CHERRYVIEW(dev)) { | |
7482 | chv_update_pll(crtc, &pipe_config); | |
7483 | chv_prepare_pll(crtc, &pipe_config); | |
7484 | chv_enable_pll(crtc, &pipe_config); | |
7485 | } else { | |
7486 | vlv_update_pll(crtc, &pipe_config); | |
7487 | vlv_prepare_pll(crtc, &pipe_config); | |
7488 | vlv_enable_pll(crtc, &pipe_config); | |
7489 | } | |
7490 | } | |
7491 | ||
7492 | /** | |
7493 | * vlv_force_pll_off - forcibly disable just the PLL | |
7494 | * @dev_priv: i915 private structure | |
7495 | * @pipe: pipe PLL to disable | |
7496 | * | |
7497 | * Disable the PLL for @pipe. To be used in cases where we need | |
7498 | * the PLL enabled even when @pipe is not going to be enabled. | |
7499 | */ | |
7500 | void vlv_force_pll_off(struct drm_device *dev, enum pipe pipe) | |
7501 | { | |
7502 | if (IS_CHERRYVIEW(dev)) | |
7503 | chv_disable_pll(to_i915(dev), pipe); | |
7504 | else | |
7505 | vlv_disable_pll(to_i915(dev), pipe); | |
7506 | } | |
7507 | ||
f47709a9 | 7508 | static void i9xx_update_pll(struct intel_crtc *crtc, |
190f68c5 | 7509 | struct intel_crtc_state *crtc_state, |
f47709a9 | 7510 | intel_clock_t *reduced_clock, |
eb1cbe48 DV |
7511 | int num_connectors) |
7512 | { | |
f47709a9 | 7513 | struct drm_device *dev = crtc->base.dev; |
eb1cbe48 | 7514 | struct drm_i915_private *dev_priv = dev->dev_private; |
eb1cbe48 DV |
7515 | u32 dpll; |
7516 | bool is_sdvo; | |
190f68c5 | 7517 | struct dpll *clock = &crtc_state->dpll; |
eb1cbe48 | 7518 | |
190f68c5 | 7519 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
2a8f64ca | 7520 | |
a93e255f ACO |
7521 | is_sdvo = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO) || |
7522 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI); | |
eb1cbe48 DV |
7523 | |
7524 | dpll = DPLL_VGA_MODE_DIS; | |
7525 | ||
a93e255f | 7526 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
eb1cbe48 DV |
7527 | dpll |= DPLLB_MODE_LVDS; |
7528 | else | |
7529 | dpll |= DPLLB_MODE_DAC_SERIAL; | |
6cc5f341 | 7530 | |
ef1b460d | 7531 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
190f68c5 | 7532 | dpll |= (crtc_state->pixel_multiplier - 1) |
198a037f | 7533 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
eb1cbe48 | 7534 | } |
198a037f DV |
7535 | |
7536 | if (is_sdvo) | |
4a33e48d | 7537 | dpll |= DPLL_SDVO_HIGH_SPEED; |
198a037f | 7538 | |
190f68c5 | 7539 | if (crtc_state->has_dp_encoder) |
4a33e48d | 7540 | dpll |= DPLL_SDVO_HIGH_SPEED; |
eb1cbe48 DV |
7541 | |
7542 | /* compute bitmask from p1 value */ | |
7543 | if (IS_PINEVIEW(dev)) | |
7544 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; | |
7545 | else { | |
7546 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
7547 | if (IS_G4X(dev) && reduced_clock) | |
7548 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; | |
7549 | } | |
7550 | switch (clock->p2) { | |
7551 | case 5: | |
7552 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; | |
7553 | break; | |
7554 | case 7: | |
7555 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; | |
7556 | break; | |
7557 | case 10: | |
7558 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; | |
7559 | break; | |
7560 | case 14: | |
7561 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; | |
7562 | break; | |
7563 | } | |
7564 | if (INTEL_INFO(dev)->gen >= 4) | |
7565 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); | |
7566 | ||
190f68c5 | 7567 | if (crtc_state->sdvo_tv_clock) |
eb1cbe48 | 7568 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
a93e255f | 7569 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
eb1cbe48 DV |
7570 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
7571 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; | |
7572 | else | |
7573 | dpll |= PLL_REF_INPUT_DREFCLK; | |
7574 | ||
7575 | dpll |= DPLL_VCO_ENABLE; | |
190f68c5 | 7576 | crtc_state->dpll_hw_state.dpll = dpll; |
8bcc2795 | 7577 | |
eb1cbe48 | 7578 | if (INTEL_INFO(dev)->gen >= 4) { |
190f68c5 | 7579 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
ef1b460d | 7580 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
190f68c5 | 7581 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
eb1cbe48 DV |
7582 | } |
7583 | } | |
7584 | ||
f47709a9 | 7585 | static void i8xx_update_pll(struct intel_crtc *crtc, |
190f68c5 | 7586 | struct intel_crtc_state *crtc_state, |
f47709a9 | 7587 | intel_clock_t *reduced_clock, |
eb1cbe48 DV |
7588 | int num_connectors) |
7589 | { | |
f47709a9 | 7590 | struct drm_device *dev = crtc->base.dev; |
eb1cbe48 | 7591 | struct drm_i915_private *dev_priv = dev->dev_private; |
eb1cbe48 | 7592 | u32 dpll; |
190f68c5 | 7593 | struct dpll *clock = &crtc_state->dpll; |
eb1cbe48 | 7594 | |
190f68c5 | 7595 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
2a8f64ca | 7596 | |
eb1cbe48 DV |
7597 | dpll = DPLL_VGA_MODE_DIS; |
7598 | ||
a93e255f | 7599 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
eb1cbe48 DV |
7600 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
7601 | } else { | |
7602 | if (clock->p1 == 2) | |
7603 | dpll |= PLL_P1_DIVIDE_BY_TWO; | |
7604 | else | |
7605 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
7606 | if (clock->p2 == 4) | |
7607 | dpll |= PLL_P2_DIVIDE_BY_4; | |
7608 | } | |
7609 | ||
a93e255f | 7610 | if (!IS_I830(dev) && intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) |
4a33e48d DV |
7611 | dpll |= DPLL_DVO_2X_MODE; |
7612 | ||
a93e255f | 7613 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
eb1cbe48 DV |
7614 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
7615 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; | |
7616 | else | |
7617 | dpll |= PLL_REF_INPUT_DREFCLK; | |
7618 | ||
7619 | dpll |= DPLL_VCO_ENABLE; | |
190f68c5 | 7620 | crtc_state->dpll_hw_state.dpll = dpll; |
eb1cbe48 DV |
7621 | } |
7622 | ||
8a654f3b | 7623 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc) |
b0e77b9c PZ |
7624 | { |
7625 | struct drm_device *dev = intel_crtc->base.dev; | |
7626 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7627 | enum pipe pipe = intel_crtc->pipe; | |
6e3c9717 | 7628 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
8a654f3b | 7629 | struct drm_display_mode *adjusted_mode = |
6e3c9717 | 7630 | &intel_crtc->config->base.adjusted_mode; |
1caea6e9 VS |
7631 | uint32_t crtc_vtotal, crtc_vblank_end; |
7632 | int vsyncshift = 0; | |
4d8a62ea DV |
7633 | |
7634 | /* We need to be careful not to changed the adjusted mode, for otherwise | |
7635 | * the hw state checker will get angry at the mismatch. */ | |
7636 | crtc_vtotal = adjusted_mode->crtc_vtotal; | |
7637 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; | |
b0e77b9c | 7638 | |
609aeaca | 7639 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
b0e77b9c | 7640 | /* the chip adds 2 halflines automatically */ |
4d8a62ea DV |
7641 | crtc_vtotal -= 1; |
7642 | crtc_vblank_end -= 1; | |
609aeaca | 7643 | |
409ee761 | 7644 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
609aeaca VS |
7645 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
7646 | else | |
7647 | vsyncshift = adjusted_mode->crtc_hsync_start - | |
7648 | adjusted_mode->crtc_htotal / 2; | |
1caea6e9 VS |
7649 | if (vsyncshift < 0) |
7650 | vsyncshift += adjusted_mode->crtc_htotal; | |
b0e77b9c PZ |
7651 | } |
7652 | ||
7653 | if (INTEL_INFO(dev)->gen > 3) | |
fe2b8f9d | 7654 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
b0e77b9c | 7655 | |
fe2b8f9d | 7656 | I915_WRITE(HTOTAL(cpu_transcoder), |
b0e77b9c PZ |
7657 | (adjusted_mode->crtc_hdisplay - 1) | |
7658 | ((adjusted_mode->crtc_htotal - 1) << 16)); | |
fe2b8f9d | 7659 | I915_WRITE(HBLANK(cpu_transcoder), |
b0e77b9c PZ |
7660 | (adjusted_mode->crtc_hblank_start - 1) | |
7661 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); | |
fe2b8f9d | 7662 | I915_WRITE(HSYNC(cpu_transcoder), |
b0e77b9c PZ |
7663 | (adjusted_mode->crtc_hsync_start - 1) | |
7664 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); | |
7665 | ||
fe2b8f9d | 7666 | I915_WRITE(VTOTAL(cpu_transcoder), |
b0e77b9c | 7667 | (adjusted_mode->crtc_vdisplay - 1) | |
4d8a62ea | 7668 | ((crtc_vtotal - 1) << 16)); |
fe2b8f9d | 7669 | I915_WRITE(VBLANK(cpu_transcoder), |
b0e77b9c | 7670 | (adjusted_mode->crtc_vblank_start - 1) | |
4d8a62ea | 7671 | ((crtc_vblank_end - 1) << 16)); |
fe2b8f9d | 7672 | I915_WRITE(VSYNC(cpu_transcoder), |
b0e77b9c PZ |
7673 | (adjusted_mode->crtc_vsync_start - 1) | |
7674 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); | |
7675 | ||
b5e508d4 PZ |
7676 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
7677 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is | |
7678 | * documented on the DDI_FUNC_CTL register description, EDP Input Select | |
7679 | * bits. */ | |
7680 | if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP && | |
7681 | (pipe == PIPE_B || pipe == PIPE_C)) | |
7682 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); | |
7683 | ||
b0e77b9c PZ |
7684 | /* pipesrc controls the size that is scaled from, which should |
7685 | * always be the user's requested size. | |
7686 | */ | |
7687 | I915_WRITE(PIPESRC(pipe), | |
6e3c9717 ACO |
7688 | ((intel_crtc->config->pipe_src_w - 1) << 16) | |
7689 | (intel_crtc->config->pipe_src_h - 1)); | |
b0e77b9c PZ |
7690 | } |
7691 | ||
1bd1bd80 | 7692 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
5cec258b | 7693 | struct intel_crtc_state *pipe_config) |
1bd1bd80 DV |
7694 | { |
7695 | struct drm_device *dev = crtc->base.dev; | |
7696 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7697 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; | |
7698 | uint32_t tmp; | |
7699 | ||
7700 | tmp = I915_READ(HTOTAL(cpu_transcoder)); | |
2d112de7 ACO |
7701 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
7702 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7703 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
2d112de7 ACO |
7704 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
7705 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7706 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
2d112de7 ACO |
7707 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
7708 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 DV |
7709 | |
7710 | tmp = I915_READ(VTOTAL(cpu_transcoder)); | |
2d112de7 ACO |
7711 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
7712 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7713 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
2d112de7 ACO |
7714 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
7715 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7716 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
2d112de7 ACO |
7717 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
7718 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 DV |
7719 | |
7720 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { | |
2d112de7 ACO |
7721 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
7722 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; | |
7723 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; | |
1bd1bd80 DV |
7724 | } |
7725 | ||
7726 | tmp = I915_READ(PIPESRC(crtc->pipe)); | |
37327abd VS |
7727 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
7728 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; | |
7729 | ||
2d112de7 ACO |
7730 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
7731 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; | |
1bd1bd80 DV |
7732 | } |
7733 | ||
f6a83288 | 7734 | void intel_mode_from_pipe_config(struct drm_display_mode *mode, |
5cec258b | 7735 | struct intel_crtc_state *pipe_config) |
babea61d | 7736 | { |
2d112de7 ACO |
7737 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
7738 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; | |
7739 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; | |
7740 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; | |
babea61d | 7741 | |
2d112de7 ACO |
7742 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
7743 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; | |
7744 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; | |
7745 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; | |
babea61d | 7746 | |
2d112de7 | 7747 | mode->flags = pipe_config->base.adjusted_mode.flags; |
babea61d | 7748 | |
2d112de7 ACO |
7749 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
7750 | mode->flags |= pipe_config->base.adjusted_mode.flags; | |
babea61d JB |
7751 | } |
7752 | ||
84b046f3 DV |
7753 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc) |
7754 | { | |
7755 | struct drm_device *dev = intel_crtc->base.dev; | |
7756 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7757 | uint32_t pipeconf; | |
7758 | ||
9f11a9e4 | 7759 | pipeconf = 0; |
84b046f3 | 7760 | |
b6b5d049 VS |
7761 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
7762 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
7763 | pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE; | |
67c72a12 | 7764 | |
6e3c9717 | 7765 | if (intel_crtc->config->double_wide) |
cf532bb2 | 7766 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
84b046f3 | 7767 | |
ff9ce46e DV |
7768 | /* only g4x and later have fancy bpc/dither controls */ |
7769 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { | |
ff9ce46e | 7770 | /* Bspec claims that we can't use dithering for 30bpp pipes. */ |
6e3c9717 | 7771 | if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30) |
ff9ce46e | 7772 | pipeconf |= PIPECONF_DITHER_EN | |
84b046f3 | 7773 | PIPECONF_DITHER_TYPE_SP; |
84b046f3 | 7774 | |
6e3c9717 | 7775 | switch (intel_crtc->config->pipe_bpp) { |
ff9ce46e DV |
7776 | case 18: |
7777 | pipeconf |= PIPECONF_6BPC; | |
7778 | break; | |
7779 | case 24: | |
7780 | pipeconf |= PIPECONF_8BPC; | |
7781 | break; | |
7782 | case 30: | |
7783 | pipeconf |= PIPECONF_10BPC; | |
7784 | break; | |
7785 | default: | |
7786 | /* Case prevented by intel_choose_pipe_bpp_dither. */ | |
7787 | BUG(); | |
84b046f3 DV |
7788 | } |
7789 | } | |
7790 | ||
7791 | if (HAS_PIPE_CXSR(dev)) { | |
7792 | if (intel_crtc->lowfreq_avail) { | |
7793 | DRM_DEBUG_KMS("enabling CxSR downclocking\n"); | |
7794 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; | |
7795 | } else { | |
7796 | DRM_DEBUG_KMS("disabling CxSR downclocking\n"); | |
84b046f3 DV |
7797 | } |
7798 | } | |
7799 | ||
6e3c9717 | 7800 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { |
efc2cfff | 7801 | if (INTEL_INFO(dev)->gen < 4 || |
409ee761 | 7802 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
efc2cfff VS |
7803 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
7804 | else | |
7805 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; | |
7806 | } else | |
84b046f3 DV |
7807 | pipeconf |= PIPECONF_PROGRESSIVE; |
7808 | ||
6e3c9717 | 7809 | if (IS_VALLEYVIEW(dev) && intel_crtc->config->limited_color_range) |
9f11a9e4 | 7810 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
9c8e09b7 | 7811 | |
84b046f3 DV |
7812 | I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf); |
7813 | POSTING_READ(PIPECONF(intel_crtc->pipe)); | |
7814 | } | |
7815 | ||
190f68c5 ACO |
7816 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
7817 | struct intel_crtc_state *crtc_state) | |
79e53945 | 7818 | { |
c7653199 | 7819 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 7820 | struct drm_i915_private *dev_priv = dev->dev_private; |
c751ce4f | 7821 | int refclk, num_connectors = 0; |
652c393a | 7822 | intel_clock_t clock, reduced_clock; |
a16af721 | 7823 | bool ok, has_reduced_clock = false; |
e9fd1c02 | 7824 | bool is_lvds = false, is_dsi = false; |
5eddb70b | 7825 | struct intel_encoder *encoder; |
d4906093 | 7826 | const intel_limit_t *limit; |
55bb9992 | 7827 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 7828 | struct drm_connector *connector; |
55bb9992 ACO |
7829 | struct drm_connector_state *connector_state; |
7830 | int i; | |
79e53945 | 7831 | |
dd3cd74a ACO |
7832 | memset(&crtc_state->dpll_hw_state, 0, |
7833 | sizeof(crtc_state->dpll_hw_state)); | |
7834 | ||
da3ced29 | 7835 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
7836 | if (connector_state->crtc != &crtc->base) |
7837 | continue; | |
7838 | ||
7839 | encoder = to_intel_encoder(connector_state->best_encoder); | |
7840 | ||
5eddb70b | 7841 | switch (encoder->type) { |
79e53945 JB |
7842 | case INTEL_OUTPUT_LVDS: |
7843 | is_lvds = true; | |
7844 | break; | |
e9fd1c02 JN |
7845 | case INTEL_OUTPUT_DSI: |
7846 | is_dsi = true; | |
7847 | break; | |
6847d71b PZ |
7848 | default: |
7849 | break; | |
79e53945 | 7850 | } |
43565a06 | 7851 | |
c751ce4f | 7852 | num_connectors++; |
79e53945 JB |
7853 | } |
7854 | ||
f2335330 | 7855 | if (is_dsi) |
5b18e57c | 7856 | return 0; |
f2335330 | 7857 | |
190f68c5 | 7858 | if (!crtc_state->clock_set) { |
a93e255f | 7859 | refclk = i9xx_get_refclk(crtc_state, num_connectors); |
79e53945 | 7860 | |
e9fd1c02 JN |
7861 | /* |
7862 | * Returns a set of divisors for the desired target clock with | |
7863 | * the given refclk, or FALSE. The returned values represent | |
7864 | * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + | |
7865 | * 2) / p1 / p2. | |
7866 | */ | |
a93e255f ACO |
7867 | limit = intel_limit(crtc_state, refclk); |
7868 | ok = dev_priv->display.find_dpll(limit, crtc_state, | |
190f68c5 | 7869 | crtc_state->port_clock, |
e9fd1c02 | 7870 | refclk, NULL, &clock); |
f2335330 | 7871 | if (!ok) { |
e9fd1c02 JN |
7872 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
7873 | return -EINVAL; | |
7874 | } | |
79e53945 | 7875 | |
f2335330 JN |
7876 | if (is_lvds && dev_priv->lvds_downclock_avail) { |
7877 | /* | |
7878 | * Ensure we match the reduced clock's P to the target | |
7879 | * clock. If the clocks don't match, we can't switch | |
7880 | * the display clock by using the FP0/FP1. In such case | |
7881 | * we will disable the LVDS downclock feature. | |
7882 | */ | |
7883 | has_reduced_clock = | |
a93e255f | 7884 | dev_priv->display.find_dpll(limit, crtc_state, |
f2335330 JN |
7885 | dev_priv->lvds_downclock, |
7886 | refclk, &clock, | |
7887 | &reduced_clock); | |
7888 | } | |
7889 | /* Compat-code for transition, will disappear. */ | |
190f68c5 ACO |
7890 | crtc_state->dpll.n = clock.n; |
7891 | crtc_state->dpll.m1 = clock.m1; | |
7892 | crtc_state->dpll.m2 = clock.m2; | |
7893 | crtc_state->dpll.p1 = clock.p1; | |
7894 | crtc_state->dpll.p2 = clock.p2; | |
f47709a9 | 7895 | } |
7026d4ac | 7896 | |
e9fd1c02 | 7897 | if (IS_GEN2(dev)) { |
190f68c5 | 7898 | i8xx_update_pll(crtc, crtc_state, |
2a8f64ca VP |
7899 | has_reduced_clock ? &reduced_clock : NULL, |
7900 | num_connectors); | |
9d556c99 | 7901 | } else if (IS_CHERRYVIEW(dev)) { |
190f68c5 | 7902 | chv_update_pll(crtc, crtc_state); |
e9fd1c02 | 7903 | } else if (IS_VALLEYVIEW(dev)) { |
190f68c5 | 7904 | vlv_update_pll(crtc, crtc_state); |
e9fd1c02 | 7905 | } else { |
190f68c5 | 7906 | i9xx_update_pll(crtc, crtc_state, |
eb1cbe48 | 7907 | has_reduced_clock ? &reduced_clock : NULL, |
eba905b2 | 7908 | num_connectors); |
e9fd1c02 | 7909 | } |
79e53945 | 7910 | |
c8f7a0db | 7911 | return 0; |
f564048e EA |
7912 | } |
7913 | ||
2fa2fe9a | 7914 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 7915 | struct intel_crtc_state *pipe_config) |
2fa2fe9a DV |
7916 | { |
7917 | struct drm_device *dev = crtc->base.dev; | |
7918 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7919 | uint32_t tmp; | |
7920 | ||
dc9e7dec VS |
7921 | if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev))) |
7922 | return; | |
7923 | ||
2fa2fe9a | 7924 | tmp = I915_READ(PFIT_CONTROL); |
06922821 DV |
7925 | if (!(tmp & PFIT_ENABLE)) |
7926 | return; | |
2fa2fe9a | 7927 | |
06922821 | 7928 | /* Check whether the pfit is attached to our pipe. */ |
2fa2fe9a DV |
7929 | if (INTEL_INFO(dev)->gen < 4) { |
7930 | if (crtc->pipe != PIPE_B) | |
7931 | return; | |
2fa2fe9a DV |
7932 | } else { |
7933 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) | |
7934 | return; | |
7935 | } | |
7936 | ||
06922821 | 7937 | pipe_config->gmch_pfit.control = tmp; |
2fa2fe9a DV |
7938 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
7939 | if (INTEL_INFO(dev)->gen < 5) | |
7940 | pipe_config->gmch_pfit.lvds_border_bits = | |
7941 | I915_READ(LVDS) & LVDS_BORDER_ENABLE; | |
7942 | } | |
7943 | ||
acbec814 | 7944 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 7945 | struct intel_crtc_state *pipe_config) |
acbec814 JB |
7946 | { |
7947 | struct drm_device *dev = crtc->base.dev; | |
7948 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7949 | int pipe = pipe_config->cpu_transcoder; | |
7950 | intel_clock_t clock; | |
7951 | u32 mdiv; | |
662c6ecb | 7952 | int refclk = 100000; |
acbec814 | 7953 | |
f573de5a SK |
7954 | /* In case of MIPI DPLL will not even be used */ |
7955 | if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)) | |
7956 | return; | |
7957 | ||
a580516d | 7958 | mutex_lock(&dev_priv->sb_lock); |
ab3c759a | 7959 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
a580516d | 7960 | mutex_unlock(&dev_priv->sb_lock); |
acbec814 JB |
7961 | |
7962 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; | |
7963 | clock.m2 = mdiv & DPIO_M2DIV_MASK; | |
7964 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; | |
7965 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; | |
7966 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; | |
7967 | ||
f646628b | 7968 | vlv_clock(refclk, &clock); |
acbec814 | 7969 | |
f646628b VS |
7970 | /* clock.dot is the fast clock */ |
7971 | pipe_config->port_clock = clock.dot / 5; | |
acbec814 JB |
7972 | } |
7973 | ||
5724dbd1 DL |
7974 | static void |
7975 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, | |
7976 | struct intel_initial_plane_config *plane_config) | |
1ad292b5 JB |
7977 | { |
7978 | struct drm_device *dev = crtc->base.dev; | |
7979 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7980 | u32 val, base, offset; | |
7981 | int pipe = crtc->pipe, plane = crtc->plane; | |
7982 | int fourcc, pixel_format; | |
6761dd31 | 7983 | unsigned int aligned_height; |
b113d5ee | 7984 | struct drm_framebuffer *fb; |
1b842c89 | 7985 | struct intel_framebuffer *intel_fb; |
1ad292b5 | 7986 | |
42a7b088 DL |
7987 | val = I915_READ(DSPCNTR(plane)); |
7988 | if (!(val & DISPLAY_PLANE_ENABLE)) | |
7989 | return; | |
7990 | ||
d9806c9f | 7991 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 7992 | if (!intel_fb) { |
1ad292b5 JB |
7993 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
7994 | return; | |
7995 | } | |
7996 | ||
1b842c89 DL |
7997 | fb = &intel_fb->base; |
7998 | ||
18c5247e DV |
7999 | if (INTEL_INFO(dev)->gen >= 4) { |
8000 | if (val & DISPPLANE_TILED) { | |
49af449b | 8001 | plane_config->tiling = I915_TILING_X; |
18c5247e DV |
8002 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
8003 | } | |
8004 | } | |
1ad292b5 JB |
8005 | |
8006 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; | |
b35d63fa | 8007 | fourcc = i9xx_format_to_fourcc(pixel_format); |
b113d5ee DL |
8008 | fb->pixel_format = fourcc; |
8009 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
1ad292b5 JB |
8010 | |
8011 | if (INTEL_INFO(dev)->gen >= 4) { | |
49af449b | 8012 | if (plane_config->tiling) |
1ad292b5 JB |
8013 | offset = I915_READ(DSPTILEOFF(plane)); |
8014 | else | |
8015 | offset = I915_READ(DSPLINOFF(plane)); | |
8016 | base = I915_READ(DSPSURF(plane)) & 0xfffff000; | |
8017 | } else { | |
8018 | base = I915_READ(DSPADDR(plane)); | |
8019 | } | |
8020 | plane_config->base = base; | |
8021 | ||
8022 | val = I915_READ(PIPESRC(pipe)); | |
b113d5ee DL |
8023 | fb->width = ((val >> 16) & 0xfff) + 1; |
8024 | fb->height = ((val >> 0) & 0xfff) + 1; | |
1ad292b5 JB |
8025 | |
8026 | val = I915_READ(DSPSTRIDE(pipe)); | |
b113d5ee | 8027 | fb->pitches[0] = val & 0xffffffc0; |
1ad292b5 | 8028 | |
b113d5ee | 8029 | aligned_height = intel_fb_align_height(dev, fb->height, |
091df6cb DV |
8030 | fb->pixel_format, |
8031 | fb->modifier[0]); | |
1ad292b5 | 8032 | |
f37b5c2b | 8033 | plane_config->size = fb->pitches[0] * aligned_height; |
1ad292b5 | 8034 | |
2844a921 DL |
8035 | DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
8036 | pipe_name(pipe), plane, fb->width, fb->height, | |
8037 | fb->bits_per_pixel, base, fb->pitches[0], | |
8038 | plane_config->size); | |
1ad292b5 | 8039 | |
2d14030b | 8040 | plane_config->fb = intel_fb; |
1ad292b5 JB |
8041 | } |
8042 | ||
70b23a98 | 8043 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 8044 | struct intel_crtc_state *pipe_config) |
70b23a98 VS |
8045 | { |
8046 | struct drm_device *dev = crtc->base.dev; | |
8047 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8048 | int pipe = pipe_config->cpu_transcoder; | |
8049 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
8050 | intel_clock_t clock; | |
8051 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2; | |
8052 | int refclk = 100000; | |
8053 | ||
a580516d | 8054 | mutex_lock(&dev_priv->sb_lock); |
70b23a98 VS |
8055 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
8056 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); | |
8057 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); | |
8058 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); | |
a580516d | 8059 | mutex_unlock(&dev_priv->sb_lock); |
70b23a98 VS |
8060 | |
8061 | clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0; | |
8062 | clock.m2 = ((pll_dw0 & 0xff) << 22) | (pll_dw2 & 0x3fffff); | |
8063 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; | |
8064 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; | |
8065 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; | |
8066 | ||
8067 | chv_clock(refclk, &clock); | |
8068 | ||
8069 | /* clock.dot is the fast clock */ | |
8070 | pipe_config->port_clock = clock.dot / 5; | |
8071 | } | |
8072 | ||
0e8ffe1b | 8073 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 8074 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
8075 | { |
8076 | struct drm_device *dev = crtc->base.dev; | |
8077 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8078 | uint32_t tmp; | |
8079 | ||
f458ebbc DV |
8080 | if (!intel_display_power_is_enabled(dev_priv, |
8081 | POWER_DOMAIN_PIPE(crtc->pipe))) | |
b5482bd0 ID |
8082 | return false; |
8083 | ||
e143a21c | 8084 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 | 8085 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
eccb140b | 8086 | |
0e8ffe1b DV |
8087 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
8088 | if (!(tmp & PIPECONF_ENABLE)) | |
8089 | return false; | |
8090 | ||
42571aef VS |
8091 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { |
8092 | switch (tmp & PIPECONF_BPC_MASK) { | |
8093 | case PIPECONF_6BPC: | |
8094 | pipe_config->pipe_bpp = 18; | |
8095 | break; | |
8096 | case PIPECONF_8BPC: | |
8097 | pipe_config->pipe_bpp = 24; | |
8098 | break; | |
8099 | case PIPECONF_10BPC: | |
8100 | pipe_config->pipe_bpp = 30; | |
8101 | break; | |
8102 | default: | |
8103 | break; | |
8104 | } | |
8105 | } | |
8106 | ||
b5a9fa09 DV |
8107 | if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
8108 | pipe_config->limited_color_range = true; | |
8109 | ||
282740f7 VS |
8110 | if (INTEL_INFO(dev)->gen < 4) |
8111 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; | |
8112 | ||
1bd1bd80 DV |
8113 | intel_get_pipe_timings(crtc, pipe_config); |
8114 | ||
2fa2fe9a DV |
8115 | i9xx_get_pfit_config(crtc, pipe_config); |
8116 | ||
6c49f241 DV |
8117 | if (INTEL_INFO(dev)->gen >= 4) { |
8118 | tmp = I915_READ(DPLL_MD(crtc->pipe)); | |
8119 | pipe_config->pixel_multiplier = | |
8120 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) | |
8121 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; | |
8bcc2795 | 8122 | pipe_config->dpll_hw_state.dpll_md = tmp; |
6c49f241 DV |
8123 | } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
8124 | tmp = I915_READ(DPLL(crtc->pipe)); | |
8125 | pipe_config->pixel_multiplier = | |
8126 | ((tmp & SDVO_MULTIPLIER_MASK) | |
8127 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; | |
8128 | } else { | |
8129 | /* Note that on i915G/GM the pixel multiplier is in the sdvo | |
8130 | * port and will be fixed up in the encoder->get_config | |
8131 | * function. */ | |
8132 | pipe_config->pixel_multiplier = 1; | |
8133 | } | |
8bcc2795 DV |
8134 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
8135 | if (!IS_VALLEYVIEW(dev)) { | |
1c4e0274 VS |
8136 | /* |
8137 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs | |
8138 | * on 830. Filter it out here so that we don't | |
8139 | * report errors due to that. | |
8140 | */ | |
8141 | if (IS_I830(dev)) | |
8142 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; | |
8143 | ||
8bcc2795 DV |
8144 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
8145 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); | |
165e901c VS |
8146 | } else { |
8147 | /* Mask out read-only status bits. */ | |
8148 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | | |
8149 | DPLL_PORTC_READY_MASK | | |
8150 | DPLL_PORTB_READY_MASK); | |
8bcc2795 | 8151 | } |
6c49f241 | 8152 | |
70b23a98 VS |
8153 | if (IS_CHERRYVIEW(dev)) |
8154 | chv_crtc_clock_get(crtc, pipe_config); | |
8155 | else if (IS_VALLEYVIEW(dev)) | |
acbec814 JB |
8156 | vlv_crtc_clock_get(crtc, pipe_config); |
8157 | else | |
8158 | i9xx_crtc_clock_get(crtc, pipe_config); | |
18442d08 | 8159 | |
0e8ffe1b DV |
8160 | return true; |
8161 | } | |
8162 | ||
dde86e2d | 8163 | static void ironlake_init_pch_refclk(struct drm_device *dev) |
13d83a67 JB |
8164 | { |
8165 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13d83a67 | 8166 | struct intel_encoder *encoder; |
74cfd7ac | 8167 | u32 val, final; |
13d83a67 | 8168 | bool has_lvds = false; |
199e5d79 | 8169 | bool has_cpu_edp = false; |
199e5d79 | 8170 | bool has_panel = false; |
99eb6a01 KP |
8171 | bool has_ck505 = false; |
8172 | bool can_ssc = false; | |
13d83a67 JB |
8173 | |
8174 | /* We need to take the global config into account */ | |
b2784e15 | 8175 | for_each_intel_encoder(dev, encoder) { |
199e5d79 KP |
8176 | switch (encoder->type) { |
8177 | case INTEL_OUTPUT_LVDS: | |
8178 | has_panel = true; | |
8179 | has_lvds = true; | |
8180 | break; | |
8181 | case INTEL_OUTPUT_EDP: | |
8182 | has_panel = true; | |
2de6905f | 8183 | if (enc_to_dig_port(&encoder->base)->port == PORT_A) |
199e5d79 KP |
8184 | has_cpu_edp = true; |
8185 | break; | |
6847d71b PZ |
8186 | default: |
8187 | break; | |
13d83a67 JB |
8188 | } |
8189 | } | |
8190 | ||
99eb6a01 | 8191 | if (HAS_PCH_IBX(dev)) { |
41aa3448 | 8192 | has_ck505 = dev_priv->vbt.display_clock_mode; |
99eb6a01 KP |
8193 | can_ssc = has_ck505; |
8194 | } else { | |
8195 | has_ck505 = false; | |
8196 | can_ssc = true; | |
8197 | } | |
8198 | ||
2de6905f ID |
8199 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n", |
8200 | has_panel, has_lvds, has_ck505); | |
13d83a67 JB |
8201 | |
8202 | /* Ironlake: try to setup display ref clock before DPLL | |
8203 | * enabling. This is only under driver's control after | |
8204 | * PCH B stepping, previous chipset stepping should be | |
8205 | * ignoring this setting. | |
8206 | */ | |
74cfd7ac CW |
8207 | val = I915_READ(PCH_DREF_CONTROL); |
8208 | ||
8209 | /* As we must carefully and slowly disable/enable each source in turn, | |
8210 | * compute the final state we want first and check if we need to | |
8211 | * make any changes at all. | |
8212 | */ | |
8213 | final = val; | |
8214 | final &= ~DREF_NONSPREAD_SOURCE_MASK; | |
8215 | if (has_ck505) | |
8216 | final |= DREF_NONSPREAD_CK505_ENABLE; | |
8217 | else | |
8218 | final |= DREF_NONSPREAD_SOURCE_ENABLE; | |
8219 | ||
8220 | final &= ~DREF_SSC_SOURCE_MASK; | |
8221 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; | |
8222 | final &= ~DREF_SSC1_ENABLE; | |
8223 | ||
8224 | if (has_panel) { | |
8225 | final |= DREF_SSC_SOURCE_ENABLE; | |
8226 | ||
8227 | if (intel_panel_use_ssc(dev_priv) && can_ssc) | |
8228 | final |= DREF_SSC1_ENABLE; | |
8229 | ||
8230 | if (has_cpu_edp) { | |
8231 | if (intel_panel_use_ssc(dev_priv) && can_ssc) | |
8232 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; | |
8233 | else | |
8234 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; | |
8235 | } else | |
8236 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; | |
8237 | } else { | |
8238 | final |= DREF_SSC_SOURCE_DISABLE; | |
8239 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; | |
8240 | } | |
8241 | ||
8242 | if (final == val) | |
8243 | return; | |
8244 | ||
13d83a67 | 8245 | /* Always enable nonspread source */ |
74cfd7ac | 8246 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
13d83a67 | 8247 | |
99eb6a01 | 8248 | if (has_ck505) |
74cfd7ac | 8249 | val |= DREF_NONSPREAD_CK505_ENABLE; |
99eb6a01 | 8250 | else |
74cfd7ac | 8251 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
13d83a67 | 8252 | |
199e5d79 | 8253 | if (has_panel) { |
74cfd7ac CW |
8254 | val &= ~DREF_SSC_SOURCE_MASK; |
8255 | val |= DREF_SSC_SOURCE_ENABLE; | |
13d83a67 | 8256 | |
199e5d79 | 8257 | /* SSC must be turned on before enabling the CPU output */ |
99eb6a01 | 8258 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
199e5d79 | 8259 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
74cfd7ac | 8260 | val |= DREF_SSC1_ENABLE; |
e77166b5 | 8261 | } else |
74cfd7ac | 8262 | val &= ~DREF_SSC1_ENABLE; |
199e5d79 KP |
8263 | |
8264 | /* Get SSC going before enabling the outputs */ | |
74cfd7ac | 8265 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8266 | POSTING_READ(PCH_DREF_CONTROL); |
8267 | udelay(200); | |
8268 | ||
74cfd7ac | 8269 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
13d83a67 JB |
8270 | |
8271 | /* Enable CPU source on CPU attached eDP */ | |
199e5d79 | 8272 | if (has_cpu_edp) { |
99eb6a01 | 8273 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
199e5d79 | 8274 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
74cfd7ac | 8275 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
eba905b2 | 8276 | } else |
74cfd7ac | 8277 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
199e5d79 | 8278 | } else |
74cfd7ac | 8279 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
199e5d79 | 8280 | |
74cfd7ac | 8281 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8282 | POSTING_READ(PCH_DREF_CONTROL); |
8283 | udelay(200); | |
8284 | } else { | |
8285 | DRM_DEBUG_KMS("Disabling SSC entirely\n"); | |
8286 | ||
74cfd7ac | 8287 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
199e5d79 KP |
8288 | |
8289 | /* Turn off CPU output */ | |
74cfd7ac | 8290 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
199e5d79 | 8291 | |
74cfd7ac | 8292 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8293 | POSTING_READ(PCH_DREF_CONTROL); |
8294 | udelay(200); | |
8295 | ||
8296 | /* Turn off the SSC source */ | |
74cfd7ac CW |
8297 | val &= ~DREF_SSC_SOURCE_MASK; |
8298 | val |= DREF_SSC_SOURCE_DISABLE; | |
199e5d79 KP |
8299 | |
8300 | /* Turn off SSC1 */ | |
74cfd7ac | 8301 | val &= ~DREF_SSC1_ENABLE; |
199e5d79 | 8302 | |
74cfd7ac | 8303 | I915_WRITE(PCH_DREF_CONTROL, val); |
13d83a67 JB |
8304 | POSTING_READ(PCH_DREF_CONTROL); |
8305 | udelay(200); | |
8306 | } | |
74cfd7ac CW |
8307 | |
8308 | BUG_ON(val != final); | |
13d83a67 JB |
8309 | } |
8310 | ||
f31f2d55 | 8311 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
dde86e2d | 8312 | { |
f31f2d55 | 8313 | uint32_t tmp; |
dde86e2d | 8314 | |
0ff066a9 PZ |
8315 | tmp = I915_READ(SOUTH_CHICKEN2); |
8316 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; | |
8317 | I915_WRITE(SOUTH_CHICKEN2, tmp); | |
dde86e2d | 8318 | |
0ff066a9 PZ |
8319 | if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) & |
8320 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) | |
8321 | DRM_ERROR("FDI mPHY reset assert timeout\n"); | |
dde86e2d | 8322 | |
0ff066a9 PZ |
8323 | tmp = I915_READ(SOUTH_CHICKEN2); |
8324 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; | |
8325 | I915_WRITE(SOUTH_CHICKEN2, tmp); | |
dde86e2d | 8326 | |
0ff066a9 PZ |
8327 | if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) & |
8328 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) | |
8329 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); | |
f31f2d55 PZ |
8330 | } |
8331 | ||
8332 | /* WaMPhyProgramming:hsw */ | |
8333 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) | |
8334 | { | |
8335 | uint32_t tmp; | |
dde86e2d PZ |
8336 | |
8337 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); | |
8338 | tmp &= ~(0xFF << 24); | |
8339 | tmp |= (0x12 << 24); | |
8340 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); | |
8341 | ||
dde86e2d PZ |
8342 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
8343 | tmp |= (1 << 11); | |
8344 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); | |
8345 | ||
8346 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); | |
8347 | tmp |= (1 << 11); | |
8348 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); | |
8349 | ||
dde86e2d PZ |
8350 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
8351 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); | |
8352 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); | |
8353 | ||
8354 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); | |
8355 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); | |
8356 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); | |
8357 | ||
0ff066a9 PZ |
8358 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
8359 | tmp &= ~(7 << 13); | |
8360 | tmp |= (5 << 13); | |
8361 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); | |
dde86e2d | 8362 | |
0ff066a9 PZ |
8363 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
8364 | tmp &= ~(7 << 13); | |
8365 | tmp |= (5 << 13); | |
8366 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); | |
dde86e2d PZ |
8367 | |
8368 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); | |
8369 | tmp &= ~0xFF; | |
8370 | tmp |= 0x1C; | |
8371 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); | |
8372 | ||
8373 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); | |
8374 | tmp &= ~0xFF; | |
8375 | tmp |= 0x1C; | |
8376 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); | |
8377 | ||
8378 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); | |
8379 | tmp &= ~(0xFF << 16); | |
8380 | tmp |= (0x1C << 16); | |
8381 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); | |
8382 | ||
8383 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); | |
8384 | tmp &= ~(0xFF << 16); | |
8385 | tmp |= (0x1C << 16); | |
8386 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); | |
8387 | ||
0ff066a9 PZ |
8388 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
8389 | tmp |= (1 << 27); | |
8390 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); | |
dde86e2d | 8391 | |
0ff066a9 PZ |
8392 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
8393 | tmp |= (1 << 27); | |
8394 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); | |
dde86e2d | 8395 | |
0ff066a9 PZ |
8396 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
8397 | tmp &= ~(0xF << 28); | |
8398 | tmp |= (4 << 28); | |
8399 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); | |
dde86e2d | 8400 | |
0ff066a9 PZ |
8401 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
8402 | tmp &= ~(0xF << 28); | |
8403 | tmp |= (4 << 28); | |
8404 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); | |
f31f2d55 PZ |
8405 | } |
8406 | ||
2fa86a1f PZ |
8407 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
8408 | * Programming" based on the parameters passed: | |
8409 | * - Sequence to enable CLKOUT_DP | |
8410 | * - Sequence to enable CLKOUT_DP without spread | |
8411 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O | |
8412 | */ | |
8413 | static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread, | |
8414 | bool with_fdi) | |
f31f2d55 PZ |
8415 | { |
8416 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2fa86a1f PZ |
8417 | uint32_t reg, tmp; |
8418 | ||
8419 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) | |
8420 | with_spread = true; | |
8421 | if (WARN(dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE && | |
8422 | with_fdi, "LP PCH doesn't have FDI\n")) | |
8423 | with_fdi = false; | |
f31f2d55 | 8424 | |
a580516d | 8425 | mutex_lock(&dev_priv->sb_lock); |
f31f2d55 PZ |
8426 | |
8427 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8428 | tmp &= ~SBI_SSCCTL_DISABLE; | |
8429 | tmp |= SBI_SSCCTL_PATHALT; | |
8430 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8431 | ||
8432 | udelay(24); | |
8433 | ||
2fa86a1f PZ |
8434 | if (with_spread) { |
8435 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8436 | tmp &= ~SBI_SSCCTL_PATHALT; | |
8437 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
f31f2d55 | 8438 | |
2fa86a1f PZ |
8439 | if (with_fdi) { |
8440 | lpt_reset_fdi_mphy(dev_priv); | |
8441 | lpt_program_fdi_mphy(dev_priv); | |
8442 | } | |
8443 | } | |
dde86e2d | 8444 | |
2fa86a1f PZ |
8445 | reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ? |
8446 | SBI_GEN0 : SBI_DBUFF0; | |
8447 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); | |
8448 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; | |
8449 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); | |
c00db246 | 8450 | |
a580516d | 8451 | mutex_unlock(&dev_priv->sb_lock); |
dde86e2d PZ |
8452 | } |
8453 | ||
47701c3b PZ |
8454 | /* Sequence to disable CLKOUT_DP */ |
8455 | static void lpt_disable_clkout_dp(struct drm_device *dev) | |
8456 | { | |
8457 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8458 | uint32_t reg, tmp; | |
8459 | ||
a580516d | 8460 | mutex_lock(&dev_priv->sb_lock); |
47701c3b PZ |
8461 | |
8462 | reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ? | |
8463 | SBI_GEN0 : SBI_DBUFF0; | |
8464 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); | |
8465 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; | |
8466 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); | |
8467 | ||
8468 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8469 | if (!(tmp & SBI_SSCCTL_DISABLE)) { | |
8470 | if (!(tmp & SBI_SSCCTL_PATHALT)) { | |
8471 | tmp |= SBI_SSCCTL_PATHALT; | |
8472 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8473 | udelay(32); | |
8474 | } | |
8475 | tmp |= SBI_SSCCTL_DISABLE; | |
8476 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8477 | } | |
8478 | ||
a580516d | 8479 | mutex_unlock(&dev_priv->sb_lock); |
47701c3b PZ |
8480 | } |
8481 | ||
bf8fa3d3 PZ |
8482 | static void lpt_init_pch_refclk(struct drm_device *dev) |
8483 | { | |
bf8fa3d3 PZ |
8484 | struct intel_encoder *encoder; |
8485 | bool has_vga = false; | |
8486 | ||
b2784e15 | 8487 | for_each_intel_encoder(dev, encoder) { |
bf8fa3d3 PZ |
8488 | switch (encoder->type) { |
8489 | case INTEL_OUTPUT_ANALOG: | |
8490 | has_vga = true; | |
8491 | break; | |
6847d71b PZ |
8492 | default: |
8493 | break; | |
bf8fa3d3 PZ |
8494 | } |
8495 | } | |
8496 | ||
47701c3b PZ |
8497 | if (has_vga) |
8498 | lpt_enable_clkout_dp(dev, true, true); | |
8499 | else | |
8500 | lpt_disable_clkout_dp(dev); | |
bf8fa3d3 PZ |
8501 | } |
8502 | ||
dde86e2d PZ |
8503 | /* |
8504 | * Initialize reference clocks when the driver loads | |
8505 | */ | |
8506 | void intel_init_pch_refclk(struct drm_device *dev) | |
8507 | { | |
8508 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) | |
8509 | ironlake_init_pch_refclk(dev); | |
8510 | else if (HAS_PCH_LPT(dev)) | |
8511 | lpt_init_pch_refclk(dev); | |
8512 | } | |
8513 | ||
55bb9992 | 8514 | static int ironlake_get_refclk(struct intel_crtc_state *crtc_state) |
d9d444cb | 8515 | { |
55bb9992 | 8516 | struct drm_device *dev = crtc_state->base.crtc->dev; |
d9d444cb | 8517 | struct drm_i915_private *dev_priv = dev->dev_private; |
55bb9992 | 8518 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 8519 | struct drm_connector *connector; |
55bb9992 | 8520 | struct drm_connector_state *connector_state; |
d9d444cb | 8521 | struct intel_encoder *encoder; |
55bb9992 | 8522 | int num_connectors = 0, i; |
d9d444cb JB |
8523 | bool is_lvds = false; |
8524 | ||
da3ced29 | 8525 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
8526 | if (connector_state->crtc != crtc_state->base.crtc) |
8527 | continue; | |
8528 | ||
8529 | encoder = to_intel_encoder(connector_state->best_encoder); | |
8530 | ||
d9d444cb JB |
8531 | switch (encoder->type) { |
8532 | case INTEL_OUTPUT_LVDS: | |
8533 | is_lvds = true; | |
8534 | break; | |
6847d71b PZ |
8535 | default: |
8536 | break; | |
d9d444cb JB |
8537 | } |
8538 | num_connectors++; | |
8539 | } | |
8540 | ||
8541 | if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) { | |
e91e941b | 8542 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
41aa3448 | 8543 | dev_priv->vbt.lvds_ssc_freq); |
e91e941b | 8544 | return dev_priv->vbt.lvds_ssc_freq; |
d9d444cb JB |
8545 | } |
8546 | ||
8547 | return 120000; | |
8548 | } | |
8549 | ||
6ff93609 | 8550 | static void ironlake_set_pipeconf(struct drm_crtc *crtc) |
79e53945 | 8551 | { |
c8203565 | 8552 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
79e53945 JB |
8553 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8554 | int pipe = intel_crtc->pipe; | |
c8203565 PZ |
8555 | uint32_t val; |
8556 | ||
78114071 | 8557 | val = 0; |
c8203565 | 8558 | |
6e3c9717 | 8559 | switch (intel_crtc->config->pipe_bpp) { |
c8203565 | 8560 | case 18: |
dfd07d72 | 8561 | val |= PIPECONF_6BPC; |
c8203565 PZ |
8562 | break; |
8563 | case 24: | |
dfd07d72 | 8564 | val |= PIPECONF_8BPC; |
c8203565 PZ |
8565 | break; |
8566 | case 30: | |
dfd07d72 | 8567 | val |= PIPECONF_10BPC; |
c8203565 PZ |
8568 | break; |
8569 | case 36: | |
dfd07d72 | 8570 | val |= PIPECONF_12BPC; |
c8203565 PZ |
8571 | break; |
8572 | default: | |
cc769b62 PZ |
8573 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
8574 | BUG(); | |
c8203565 PZ |
8575 | } |
8576 | ||
6e3c9717 | 8577 | if (intel_crtc->config->dither) |
c8203565 PZ |
8578 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
8579 | ||
6e3c9717 | 8580 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
c8203565 PZ |
8581 | val |= PIPECONF_INTERLACED_ILK; |
8582 | else | |
8583 | val |= PIPECONF_PROGRESSIVE; | |
8584 | ||
6e3c9717 | 8585 | if (intel_crtc->config->limited_color_range) |
3685a8f3 | 8586 | val |= PIPECONF_COLOR_RANGE_SELECT; |
3685a8f3 | 8587 | |
c8203565 PZ |
8588 | I915_WRITE(PIPECONF(pipe), val); |
8589 | POSTING_READ(PIPECONF(pipe)); | |
8590 | } | |
8591 | ||
86d3efce VS |
8592 | /* |
8593 | * Set up the pipe CSC unit. | |
8594 | * | |
8595 | * Currently only full range RGB to limited range RGB conversion | |
8596 | * is supported, but eventually this should handle various | |
8597 | * RGB<->YCbCr scenarios as well. | |
8598 | */ | |
50f3b016 | 8599 | static void intel_set_pipe_csc(struct drm_crtc *crtc) |
86d3efce VS |
8600 | { |
8601 | struct drm_device *dev = crtc->dev; | |
8602 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8603 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
8604 | int pipe = intel_crtc->pipe; | |
8605 | uint16_t coeff = 0x7800; /* 1.0 */ | |
8606 | ||
8607 | /* | |
8608 | * TODO: Check what kind of values actually come out of the pipe | |
8609 | * with these coeff/postoff values and adjust to get the best | |
8610 | * accuracy. Perhaps we even need to take the bpc value into | |
8611 | * consideration. | |
8612 | */ | |
8613 | ||
6e3c9717 | 8614 | if (intel_crtc->config->limited_color_range) |
86d3efce VS |
8615 | coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */ |
8616 | ||
8617 | /* | |
8618 | * GY/GU and RY/RU should be the other way around according | |
8619 | * to BSpec, but reality doesn't agree. Just set them up in | |
8620 | * a way that results in the correct picture. | |
8621 | */ | |
8622 | I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16); | |
8623 | I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0); | |
8624 | ||
8625 | I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff); | |
8626 | I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0); | |
8627 | ||
8628 | I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0); | |
8629 | I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16); | |
8630 | ||
8631 | I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0); | |
8632 | I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0); | |
8633 | I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0); | |
8634 | ||
8635 | if (INTEL_INFO(dev)->gen > 6) { | |
8636 | uint16_t postoff = 0; | |
8637 | ||
6e3c9717 | 8638 | if (intel_crtc->config->limited_color_range) |
32cf0cb0 | 8639 | postoff = (16 * (1 << 12) / 255) & 0x1fff; |
86d3efce VS |
8640 | |
8641 | I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff); | |
8642 | I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff); | |
8643 | I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff); | |
8644 | ||
8645 | I915_WRITE(PIPE_CSC_MODE(pipe), 0); | |
8646 | } else { | |
8647 | uint32_t mode = CSC_MODE_YUV_TO_RGB; | |
8648 | ||
6e3c9717 | 8649 | if (intel_crtc->config->limited_color_range) |
86d3efce VS |
8650 | mode |= CSC_BLACK_SCREEN_OFFSET; |
8651 | ||
8652 | I915_WRITE(PIPE_CSC_MODE(pipe), mode); | |
8653 | } | |
8654 | } | |
8655 | ||
6ff93609 | 8656 | static void haswell_set_pipeconf(struct drm_crtc *crtc) |
ee2b0b38 | 8657 | { |
756f85cf PZ |
8658 | struct drm_device *dev = crtc->dev; |
8659 | struct drm_i915_private *dev_priv = dev->dev_private; | |
ee2b0b38 | 8660 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
756f85cf | 8661 | enum pipe pipe = intel_crtc->pipe; |
6e3c9717 | 8662 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
ee2b0b38 PZ |
8663 | uint32_t val; |
8664 | ||
3eff4faa | 8665 | val = 0; |
ee2b0b38 | 8666 | |
6e3c9717 | 8667 | if (IS_HASWELL(dev) && intel_crtc->config->dither) |
ee2b0b38 PZ |
8668 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
8669 | ||
6e3c9717 | 8670 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
ee2b0b38 PZ |
8671 | val |= PIPECONF_INTERLACED_ILK; |
8672 | else | |
8673 | val |= PIPECONF_PROGRESSIVE; | |
8674 | ||
702e7a56 PZ |
8675 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
8676 | POSTING_READ(PIPECONF(cpu_transcoder)); | |
3eff4faa DV |
8677 | |
8678 | I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT); | |
8679 | POSTING_READ(GAMMA_MODE(intel_crtc->pipe)); | |
756f85cf | 8680 | |
3cdf122c | 8681 | if (IS_BROADWELL(dev) || INTEL_INFO(dev)->gen >= 9) { |
756f85cf PZ |
8682 | val = 0; |
8683 | ||
6e3c9717 | 8684 | switch (intel_crtc->config->pipe_bpp) { |
756f85cf PZ |
8685 | case 18: |
8686 | val |= PIPEMISC_DITHER_6_BPC; | |
8687 | break; | |
8688 | case 24: | |
8689 | val |= PIPEMISC_DITHER_8_BPC; | |
8690 | break; | |
8691 | case 30: | |
8692 | val |= PIPEMISC_DITHER_10_BPC; | |
8693 | break; | |
8694 | case 36: | |
8695 | val |= PIPEMISC_DITHER_12_BPC; | |
8696 | break; | |
8697 | default: | |
8698 | /* Case prevented by pipe_config_set_bpp. */ | |
8699 | BUG(); | |
8700 | } | |
8701 | ||
6e3c9717 | 8702 | if (intel_crtc->config->dither) |
756f85cf PZ |
8703 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
8704 | ||
8705 | I915_WRITE(PIPEMISC(pipe), val); | |
8706 | } | |
ee2b0b38 PZ |
8707 | } |
8708 | ||
6591c6e4 | 8709 | static bool ironlake_compute_clocks(struct drm_crtc *crtc, |
190f68c5 | 8710 | struct intel_crtc_state *crtc_state, |
6591c6e4 PZ |
8711 | intel_clock_t *clock, |
8712 | bool *has_reduced_clock, | |
8713 | intel_clock_t *reduced_clock) | |
8714 | { | |
8715 | struct drm_device *dev = crtc->dev; | |
8716 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6591c6e4 | 8717 | int refclk; |
d4906093 | 8718 | const intel_limit_t *limit; |
a16af721 | 8719 | bool ret, is_lvds = false; |
79e53945 | 8720 | |
a93e255f | 8721 | is_lvds = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS); |
79e53945 | 8722 | |
55bb9992 | 8723 | refclk = ironlake_get_refclk(crtc_state); |
79e53945 | 8724 | |
d4906093 ML |
8725 | /* |
8726 | * Returns a set of divisors for the desired target clock with the given | |
8727 | * refclk, or FALSE. The returned values represent the clock equation: | |
8728 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. | |
8729 | */ | |
a93e255f ACO |
8730 | limit = intel_limit(crtc_state, refclk); |
8731 | ret = dev_priv->display.find_dpll(limit, crtc_state, | |
190f68c5 | 8732 | crtc_state->port_clock, |
ee9300bb | 8733 | refclk, NULL, clock); |
6591c6e4 PZ |
8734 | if (!ret) |
8735 | return false; | |
cda4b7d3 | 8736 | |
ddc9003c | 8737 | if (is_lvds && dev_priv->lvds_downclock_avail) { |
cec2f356 SP |
8738 | /* |
8739 | * Ensure we match the reduced clock's P to the target clock. | |
8740 | * If the clocks don't match, we can't switch the display clock | |
8741 | * by using the FP0/FP1. In such case we will disable the LVDS | |
8742 | * downclock feature. | |
8743 | */ | |
ee9300bb | 8744 | *has_reduced_clock = |
a93e255f | 8745 | dev_priv->display.find_dpll(limit, crtc_state, |
ee9300bb DV |
8746 | dev_priv->lvds_downclock, |
8747 | refclk, clock, | |
8748 | reduced_clock); | |
652c393a | 8749 | } |
61e9653f | 8750 | |
6591c6e4 PZ |
8751 | return true; |
8752 | } | |
8753 | ||
d4b1931c PZ |
8754 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
8755 | { | |
8756 | /* | |
8757 | * Account for spread spectrum to avoid | |
8758 | * oversubscribing the link. Max center spread | |
8759 | * is 2.5%; use 5% for safety's sake. | |
8760 | */ | |
8761 | u32 bps = target_clock * bpp * 21 / 20; | |
619d4d04 | 8762 | return DIV_ROUND_UP(bps, link_bw * 8); |
d4b1931c PZ |
8763 | } |
8764 | ||
7429e9d4 | 8765 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
6cf86a5e | 8766 | { |
7429e9d4 | 8767 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
f48d8f23 PZ |
8768 | } |
8769 | ||
de13a2e3 | 8770 | static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc, |
190f68c5 | 8771 | struct intel_crtc_state *crtc_state, |
7429e9d4 | 8772 | u32 *fp, |
9a7c7890 | 8773 | intel_clock_t *reduced_clock, u32 *fp2) |
79e53945 | 8774 | { |
de13a2e3 | 8775 | struct drm_crtc *crtc = &intel_crtc->base; |
79e53945 JB |
8776 | struct drm_device *dev = crtc->dev; |
8777 | struct drm_i915_private *dev_priv = dev->dev_private; | |
55bb9992 | 8778 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 8779 | struct drm_connector *connector; |
55bb9992 ACO |
8780 | struct drm_connector_state *connector_state; |
8781 | struct intel_encoder *encoder; | |
de13a2e3 | 8782 | uint32_t dpll; |
55bb9992 | 8783 | int factor, num_connectors = 0, i; |
09ede541 | 8784 | bool is_lvds = false, is_sdvo = false; |
79e53945 | 8785 | |
da3ced29 | 8786 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
8787 | if (connector_state->crtc != crtc_state->base.crtc) |
8788 | continue; | |
8789 | ||
8790 | encoder = to_intel_encoder(connector_state->best_encoder); | |
8791 | ||
8792 | switch (encoder->type) { | |
79e53945 JB |
8793 | case INTEL_OUTPUT_LVDS: |
8794 | is_lvds = true; | |
8795 | break; | |
8796 | case INTEL_OUTPUT_SDVO: | |
7d57382e | 8797 | case INTEL_OUTPUT_HDMI: |
79e53945 | 8798 | is_sdvo = true; |
79e53945 | 8799 | break; |
6847d71b PZ |
8800 | default: |
8801 | break; | |
79e53945 | 8802 | } |
43565a06 | 8803 | |
c751ce4f | 8804 | num_connectors++; |
79e53945 | 8805 | } |
79e53945 | 8806 | |
c1858123 | 8807 | /* Enable autotuning of the PLL clock (if permissible) */ |
8febb297 EA |
8808 | factor = 21; |
8809 | if (is_lvds) { | |
8810 | if ((intel_panel_use_ssc(dev_priv) && | |
e91e941b | 8811 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
f0b44056 | 8812 | (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev))) |
8febb297 | 8813 | factor = 25; |
190f68c5 | 8814 | } else if (crtc_state->sdvo_tv_clock) |
8febb297 | 8815 | factor = 20; |
c1858123 | 8816 | |
190f68c5 | 8817 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
7d0ac5b7 | 8818 | *fp |= FP_CB_TUNE; |
2c07245f | 8819 | |
9a7c7890 DV |
8820 | if (fp2 && (reduced_clock->m < factor * reduced_clock->n)) |
8821 | *fp2 |= FP_CB_TUNE; | |
8822 | ||
5eddb70b | 8823 | dpll = 0; |
2c07245f | 8824 | |
a07d6787 EA |
8825 | if (is_lvds) |
8826 | dpll |= DPLLB_MODE_LVDS; | |
8827 | else | |
8828 | dpll |= DPLLB_MODE_DAC_SERIAL; | |
198a037f | 8829 | |
190f68c5 | 8830 | dpll |= (crtc_state->pixel_multiplier - 1) |
ef1b460d | 8831 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
198a037f DV |
8832 | |
8833 | if (is_sdvo) | |
4a33e48d | 8834 | dpll |= DPLL_SDVO_HIGH_SPEED; |
190f68c5 | 8835 | if (crtc_state->has_dp_encoder) |
4a33e48d | 8836 | dpll |= DPLL_SDVO_HIGH_SPEED; |
79e53945 | 8837 | |
a07d6787 | 8838 | /* compute bitmask from p1 value */ |
190f68c5 | 8839 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
a07d6787 | 8840 | /* also FPA1 */ |
190f68c5 | 8841 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
a07d6787 | 8842 | |
190f68c5 | 8843 | switch (crtc_state->dpll.p2) { |
a07d6787 EA |
8844 | case 5: |
8845 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; | |
8846 | break; | |
8847 | case 7: | |
8848 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; | |
8849 | break; | |
8850 | case 10: | |
8851 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; | |
8852 | break; | |
8853 | case 14: | |
8854 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; | |
8855 | break; | |
79e53945 JB |
8856 | } |
8857 | ||
b4c09f3b | 8858 | if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
43565a06 | 8859 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
79e53945 JB |
8860 | else |
8861 | dpll |= PLL_REF_INPUT_DREFCLK; | |
8862 | ||
959e16d6 | 8863 | return dpll | DPLL_VCO_ENABLE; |
de13a2e3 PZ |
8864 | } |
8865 | ||
190f68c5 ACO |
8866 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
8867 | struct intel_crtc_state *crtc_state) | |
de13a2e3 | 8868 | { |
c7653199 | 8869 | struct drm_device *dev = crtc->base.dev; |
de13a2e3 | 8870 | intel_clock_t clock, reduced_clock; |
cbbab5bd | 8871 | u32 dpll = 0, fp = 0, fp2 = 0; |
e2f12b07 | 8872 | bool ok, has_reduced_clock = false; |
8b47047b | 8873 | bool is_lvds = false; |
e2b78267 | 8874 | struct intel_shared_dpll *pll; |
de13a2e3 | 8875 | |
dd3cd74a ACO |
8876 | memset(&crtc_state->dpll_hw_state, 0, |
8877 | sizeof(crtc_state->dpll_hw_state)); | |
8878 | ||
409ee761 | 8879 | is_lvds = intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS); |
79e53945 | 8880 | |
5dc5298b PZ |
8881 | WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)), |
8882 | "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev)); | |
a07d6787 | 8883 | |
190f68c5 | 8884 | ok = ironlake_compute_clocks(&crtc->base, crtc_state, &clock, |
de13a2e3 | 8885 | &has_reduced_clock, &reduced_clock); |
190f68c5 | 8886 | if (!ok && !crtc_state->clock_set) { |
de13a2e3 PZ |
8887 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
8888 | return -EINVAL; | |
79e53945 | 8889 | } |
f47709a9 | 8890 | /* Compat-code for transition, will disappear. */ |
190f68c5 ACO |
8891 | if (!crtc_state->clock_set) { |
8892 | crtc_state->dpll.n = clock.n; | |
8893 | crtc_state->dpll.m1 = clock.m1; | |
8894 | crtc_state->dpll.m2 = clock.m2; | |
8895 | crtc_state->dpll.p1 = clock.p1; | |
8896 | crtc_state->dpll.p2 = clock.p2; | |
f47709a9 | 8897 | } |
79e53945 | 8898 | |
5dc5298b | 8899 | /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */ |
190f68c5 ACO |
8900 | if (crtc_state->has_pch_encoder) { |
8901 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); | |
cbbab5bd | 8902 | if (has_reduced_clock) |
7429e9d4 | 8903 | fp2 = i9xx_dpll_compute_fp(&reduced_clock); |
cbbab5bd | 8904 | |
190f68c5 | 8905 | dpll = ironlake_compute_dpll(crtc, crtc_state, |
cbbab5bd DV |
8906 | &fp, &reduced_clock, |
8907 | has_reduced_clock ? &fp2 : NULL); | |
8908 | ||
190f68c5 ACO |
8909 | crtc_state->dpll_hw_state.dpll = dpll; |
8910 | crtc_state->dpll_hw_state.fp0 = fp; | |
66e985c0 | 8911 | if (has_reduced_clock) |
190f68c5 | 8912 | crtc_state->dpll_hw_state.fp1 = fp2; |
66e985c0 | 8913 | else |
190f68c5 | 8914 | crtc_state->dpll_hw_state.fp1 = fp; |
66e985c0 | 8915 | |
190f68c5 | 8916 | pll = intel_get_shared_dpll(crtc, crtc_state); |
ee7b9f93 | 8917 | if (pll == NULL) { |
84f44ce7 | 8918 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", |
c7653199 | 8919 | pipe_name(crtc->pipe)); |
4b645f14 JB |
8920 | return -EINVAL; |
8921 | } | |
3fb37703 | 8922 | } |
79e53945 | 8923 | |
ab585dea | 8924 | if (is_lvds && has_reduced_clock) |
c7653199 | 8925 | crtc->lowfreq_avail = true; |
bcd644e0 | 8926 | else |
c7653199 | 8927 | crtc->lowfreq_avail = false; |
e2b78267 | 8928 | |
c8f7a0db | 8929 | return 0; |
79e53945 JB |
8930 | } |
8931 | ||
eb14cb74 VS |
8932 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
8933 | struct intel_link_m_n *m_n) | |
8934 | { | |
8935 | struct drm_device *dev = crtc->base.dev; | |
8936 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8937 | enum pipe pipe = crtc->pipe; | |
8938 | ||
8939 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); | |
8940 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); | |
8941 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) | |
8942 | & ~TU_SIZE_MASK; | |
8943 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); | |
8944 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) | |
8945 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
8946 | } | |
8947 | ||
8948 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, | |
8949 | enum transcoder transcoder, | |
b95af8be VK |
8950 | struct intel_link_m_n *m_n, |
8951 | struct intel_link_m_n *m2_n2) | |
72419203 DV |
8952 | { |
8953 | struct drm_device *dev = crtc->base.dev; | |
8954 | struct drm_i915_private *dev_priv = dev->dev_private; | |
eb14cb74 | 8955 | enum pipe pipe = crtc->pipe; |
72419203 | 8956 | |
eb14cb74 VS |
8957 | if (INTEL_INFO(dev)->gen >= 5) { |
8958 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); | |
8959 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); | |
8960 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) | |
8961 | & ~TU_SIZE_MASK; | |
8962 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); | |
8963 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) | |
8964 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
b95af8be VK |
8965 | /* Read M2_N2 registers only for gen < 8 (M2_N2 available for |
8966 | * gen < 8) and if DRRS is supported (to make sure the | |
8967 | * registers are not unnecessarily read). | |
8968 | */ | |
8969 | if (m2_n2 && INTEL_INFO(dev)->gen < 8 && | |
6e3c9717 | 8970 | crtc->config->has_drrs) { |
b95af8be VK |
8971 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
8972 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); | |
8973 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) | |
8974 | & ~TU_SIZE_MASK; | |
8975 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); | |
8976 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) | |
8977 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
8978 | } | |
eb14cb74 VS |
8979 | } else { |
8980 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); | |
8981 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); | |
8982 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) | |
8983 | & ~TU_SIZE_MASK; | |
8984 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); | |
8985 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) | |
8986 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
8987 | } | |
8988 | } | |
8989 | ||
8990 | void intel_dp_get_m_n(struct intel_crtc *crtc, | |
5cec258b | 8991 | struct intel_crtc_state *pipe_config) |
eb14cb74 | 8992 | { |
681a8504 | 8993 | if (pipe_config->has_pch_encoder) |
eb14cb74 VS |
8994 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
8995 | else | |
8996 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, | |
b95af8be VK |
8997 | &pipe_config->dp_m_n, |
8998 | &pipe_config->dp_m2_n2); | |
eb14cb74 | 8999 | } |
72419203 | 9000 | |
eb14cb74 | 9001 | static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc, |
5cec258b | 9002 | struct intel_crtc_state *pipe_config) |
eb14cb74 VS |
9003 | { |
9004 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, | |
b95af8be | 9005 | &pipe_config->fdi_m_n, NULL); |
72419203 DV |
9006 | } |
9007 | ||
bd2e244f | 9008 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 9009 | struct intel_crtc_state *pipe_config) |
bd2e244f JB |
9010 | { |
9011 | struct drm_device *dev = crtc->base.dev; | |
9012 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a1b2278e CK |
9013 | struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state; |
9014 | uint32_t ps_ctrl = 0; | |
9015 | int id = -1; | |
9016 | int i; | |
bd2e244f | 9017 | |
a1b2278e CK |
9018 | /* find scaler attached to this pipe */ |
9019 | for (i = 0; i < crtc->num_scalers; i++) { | |
9020 | ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i)); | |
9021 | if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) { | |
9022 | id = i; | |
9023 | pipe_config->pch_pfit.enabled = true; | |
9024 | pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i)); | |
9025 | pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i)); | |
9026 | break; | |
9027 | } | |
9028 | } | |
bd2e244f | 9029 | |
a1b2278e CK |
9030 | scaler_state->scaler_id = id; |
9031 | if (id >= 0) { | |
9032 | scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX); | |
9033 | } else { | |
9034 | scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX); | |
bd2e244f JB |
9035 | } |
9036 | } | |
9037 | ||
5724dbd1 DL |
9038 | static void |
9039 | skylake_get_initial_plane_config(struct intel_crtc *crtc, | |
9040 | struct intel_initial_plane_config *plane_config) | |
bc8d7dff DL |
9041 | { |
9042 | struct drm_device *dev = crtc->base.dev; | |
9043 | struct drm_i915_private *dev_priv = dev->dev_private; | |
40f46283 | 9044 | u32 val, base, offset, stride_mult, tiling; |
bc8d7dff DL |
9045 | int pipe = crtc->pipe; |
9046 | int fourcc, pixel_format; | |
6761dd31 | 9047 | unsigned int aligned_height; |
bc8d7dff | 9048 | struct drm_framebuffer *fb; |
1b842c89 | 9049 | struct intel_framebuffer *intel_fb; |
bc8d7dff | 9050 | |
d9806c9f | 9051 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 9052 | if (!intel_fb) { |
bc8d7dff DL |
9053 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
9054 | return; | |
9055 | } | |
9056 | ||
1b842c89 DL |
9057 | fb = &intel_fb->base; |
9058 | ||
bc8d7dff | 9059 | val = I915_READ(PLANE_CTL(pipe, 0)); |
42a7b088 DL |
9060 | if (!(val & PLANE_CTL_ENABLE)) |
9061 | goto error; | |
9062 | ||
bc8d7dff DL |
9063 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
9064 | fourcc = skl_format_to_fourcc(pixel_format, | |
9065 | val & PLANE_CTL_ORDER_RGBX, | |
9066 | val & PLANE_CTL_ALPHA_MASK); | |
9067 | fb->pixel_format = fourcc; | |
9068 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
9069 | ||
40f46283 DL |
9070 | tiling = val & PLANE_CTL_TILED_MASK; |
9071 | switch (tiling) { | |
9072 | case PLANE_CTL_TILED_LINEAR: | |
9073 | fb->modifier[0] = DRM_FORMAT_MOD_NONE; | |
9074 | break; | |
9075 | case PLANE_CTL_TILED_X: | |
9076 | plane_config->tiling = I915_TILING_X; | |
9077 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; | |
9078 | break; | |
9079 | case PLANE_CTL_TILED_Y: | |
9080 | fb->modifier[0] = I915_FORMAT_MOD_Y_TILED; | |
9081 | break; | |
9082 | case PLANE_CTL_TILED_YF: | |
9083 | fb->modifier[0] = I915_FORMAT_MOD_Yf_TILED; | |
9084 | break; | |
9085 | default: | |
9086 | MISSING_CASE(tiling); | |
9087 | goto error; | |
9088 | } | |
9089 | ||
bc8d7dff DL |
9090 | base = I915_READ(PLANE_SURF(pipe, 0)) & 0xfffff000; |
9091 | plane_config->base = base; | |
9092 | ||
9093 | offset = I915_READ(PLANE_OFFSET(pipe, 0)); | |
9094 | ||
9095 | val = I915_READ(PLANE_SIZE(pipe, 0)); | |
9096 | fb->height = ((val >> 16) & 0xfff) + 1; | |
9097 | fb->width = ((val >> 0) & 0x1fff) + 1; | |
9098 | ||
9099 | val = I915_READ(PLANE_STRIDE(pipe, 0)); | |
40f46283 DL |
9100 | stride_mult = intel_fb_stride_alignment(dev, fb->modifier[0], |
9101 | fb->pixel_format); | |
bc8d7dff DL |
9102 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
9103 | ||
9104 | aligned_height = intel_fb_align_height(dev, fb->height, | |
091df6cb DV |
9105 | fb->pixel_format, |
9106 | fb->modifier[0]); | |
bc8d7dff | 9107 | |
f37b5c2b | 9108 | plane_config->size = fb->pitches[0] * aligned_height; |
bc8d7dff DL |
9109 | |
9110 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", | |
9111 | pipe_name(pipe), fb->width, fb->height, | |
9112 | fb->bits_per_pixel, base, fb->pitches[0], | |
9113 | plane_config->size); | |
9114 | ||
2d14030b | 9115 | plane_config->fb = intel_fb; |
bc8d7dff DL |
9116 | return; |
9117 | ||
9118 | error: | |
9119 | kfree(fb); | |
9120 | } | |
9121 | ||
2fa2fe9a | 9122 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 9123 | struct intel_crtc_state *pipe_config) |
2fa2fe9a DV |
9124 | { |
9125 | struct drm_device *dev = crtc->base.dev; | |
9126 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9127 | uint32_t tmp; | |
9128 | ||
9129 | tmp = I915_READ(PF_CTL(crtc->pipe)); | |
9130 | ||
9131 | if (tmp & PF_ENABLE) { | |
fd4daa9c | 9132 | pipe_config->pch_pfit.enabled = true; |
2fa2fe9a DV |
9133 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
9134 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); | |
cb8b2a30 DV |
9135 | |
9136 | /* We currently do not free assignements of panel fitters on | |
9137 | * ivb/hsw (since we don't use the higher upscaling modes which | |
9138 | * differentiates them) so just WARN about this case for now. */ | |
9139 | if (IS_GEN7(dev)) { | |
9140 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != | |
9141 | PF_PIPE_SEL_IVB(crtc->pipe)); | |
9142 | } | |
2fa2fe9a | 9143 | } |
79e53945 JB |
9144 | } |
9145 | ||
5724dbd1 DL |
9146 | static void |
9147 | ironlake_get_initial_plane_config(struct intel_crtc *crtc, | |
9148 | struct intel_initial_plane_config *plane_config) | |
4c6baa59 JB |
9149 | { |
9150 | struct drm_device *dev = crtc->base.dev; | |
9151 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9152 | u32 val, base, offset; | |
aeee5a49 | 9153 | int pipe = crtc->pipe; |
4c6baa59 | 9154 | int fourcc, pixel_format; |
6761dd31 | 9155 | unsigned int aligned_height; |
b113d5ee | 9156 | struct drm_framebuffer *fb; |
1b842c89 | 9157 | struct intel_framebuffer *intel_fb; |
4c6baa59 | 9158 | |
42a7b088 DL |
9159 | val = I915_READ(DSPCNTR(pipe)); |
9160 | if (!(val & DISPLAY_PLANE_ENABLE)) | |
9161 | return; | |
9162 | ||
d9806c9f | 9163 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 9164 | if (!intel_fb) { |
4c6baa59 JB |
9165 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
9166 | return; | |
9167 | } | |
9168 | ||
1b842c89 DL |
9169 | fb = &intel_fb->base; |
9170 | ||
18c5247e DV |
9171 | if (INTEL_INFO(dev)->gen >= 4) { |
9172 | if (val & DISPPLANE_TILED) { | |
49af449b | 9173 | plane_config->tiling = I915_TILING_X; |
18c5247e DV |
9174 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
9175 | } | |
9176 | } | |
4c6baa59 JB |
9177 | |
9178 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; | |
b35d63fa | 9179 | fourcc = i9xx_format_to_fourcc(pixel_format); |
b113d5ee DL |
9180 | fb->pixel_format = fourcc; |
9181 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
4c6baa59 | 9182 | |
aeee5a49 | 9183 | base = I915_READ(DSPSURF(pipe)) & 0xfffff000; |
4c6baa59 | 9184 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
aeee5a49 | 9185 | offset = I915_READ(DSPOFFSET(pipe)); |
4c6baa59 | 9186 | } else { |
49af449b | 9187 | if (plane_config->tiling) |
aeee5a49 | 9188 | offset = I915_READ(DSPTILEOFF(pipe)); |
4c6baa59 | 9189 | else |
aeee5a49 | 9190 | offset = I915_READ(DSPLINOFF(pipe)); |
4c6baa59 JB |
9191 | } |
9192 | plane_config->base = base; | |
9193 | ||
9194 | val = I915_READ(PIPESRC(pipe)); | |
b113d5ee DL |
9195 | fb->width = ((val >> 16) & 0xfff) + 1; |
9196 | fb->height = ((val >> 0) & 0xfff) + 1; | |
4c6baa59 JB |
9197 | |
9198 | val = I915_READ(DSPSTRIDE(pipe)); | |
b113d5ee | 9199 | fb->pitches[0] = val & 0xffffffc0; |
4c6baa59 | 9200 | |
b113d5ee | 9201 | aligned_height = intel_fb_align_height(dev, fb->height, |
091df6cb DV |
9202 | fb->pixel_format, |
9203 | fb->modifier[0]); | |
4c6baa59 | 9204 | |
f37b5c2b | 9205 | plane_config->size = fb->pitches[0] * aligned_height; |
4c6baa59 | 9206 | |
2844a921 DL |
9207 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
9208 | pipe_name(pipe), fb->width, fb->height, | |
9209 | fb->bits_per_pixel, base, fb->pitches[0], | |
9210 | plane_config->size); | |
b113d5ee | 9211 | |
2d14030b | 9212 | plane_config->fb = intel_fb; |
4c6baa59 JB |
9213 | } |
9214 | ||
0e8ffe1b | 9215 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 9216 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
9217 | { |
9218 | struct drm_device *dev = crtc->base.dev; | |
9219 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9220 | uint32_t tmp; | |
9221 | ||
f458ebbc DV |
9222 | if (!intel_display_power_is_enabled(dev_priv, |
9223 | POWER_DOMAIN_PIPE(crtc->pipe))) | |
930e8c9e PZ |
9224 | return false; |
9225 | ||
e143a21c | 9226 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 | 9227 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
eccb140b | 9228 | |
0e8ffe1b DV |
9229 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
9230 | if (!(tmp & PIPECONF_ENABLE)) | |
9231 | return false; | |
9232 | ||
42571aef VS |
9233 | switch (tmp & PIPECONF_BPC_MASK) { |
9234 | case PIPECONF_6BPC: | |
9235 | pipe_config->pipe_bpp = 18; | |
9236 | break; | |
9237 | case PIPECONF_8BPC: | |
9238 | pipe_config->pipe_bpp = 24; | |
9239 | break; | |
9240 | case PIPECONF_10BPC: | |
9241 | pipe_config->pipe_bpp = 30; | |
9242 | break; | |
9243 | case PIPECONF_12BPC: | |
9244 | pipe_config->pipe_bpp = 36; | |
9245 | break; | |
9246 | default: | |
9247 | break; | |
9248 | } | |
9249 | ||
b5a9fa09 DV |
9250 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
9251 | pipe_config->limited_color_range = true; | |
9252 | ||
ab9412ba | 9253 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
66e985c0 DV |
9254 | struct intel_shared_dpll *pll; |
9255 | ||
88adfff1 DV |
9256 | pipe_config->has_pch_encoder = true; |
9257 | ||
627eb5a3 DV |
9258 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
9259 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> | |
9260 | FDI_DP_PORT_WIDTH_SHIFT) + 1; | |
72419203 DV |
9261 | |
9262 | ironlake_get_fdi_m_n_config(crtc, pipe_config); | |
6c49f241 | 9263 | |
c0d43d62 | 9264 | if (HAS_PCH_IBX(dev_priv->dev)) { |
d94ab068 DV |
9265 | pipe_config->shared_dpll = |
9266 | (enum intel_dpll_id) crtc->pipe; | |
c0d43d62 DV |
9267 | } else { |
9268 | tmp = I915_READ(PCH_DPLL_SEL); | |
9269 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) | |
9270 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B; | |
9271 | else | |
9272 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A; | |
9273 | } | |
66e985c0 DV |
9274 | |
9275 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; | |
9276 | ||
9277 | WARN_ON(!pll->get_hw_state(dev_priv, pll, | |
9278 | &pipe_config->dpll_hw_state)); | |
c93f54cf DV |
9279 | |
9280 | tmp = pipe_config->dpll_hw_state.dpll; | |
9281 | pipe_config->pixel_multiplier = | |
9282 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) | |
9283 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; | |
18442d08 VS |
9284 | |
9285 | ironlake_pch_clock_get(crtc, pipe_config); | |
6c49f241 DV |
9286 | } else { |
9287 | pipe_config->pixel_multiplier = 1; | |
627eb5a3 DV |
9288 | } |
9289 | ||
1bd1bd80 DV |
9290 | intel_get_pipe_timings(crtc, pipe_config); |
9291 | ||
2fa2fe9a DV |
9292 | ironlake_get_pfit_config(crtc, pipe_config); |
9293 | ||
0e8ffe1b DV |
9294 | return true; |
9295 | } | |
9296 | ||
be256dc7 PZ |
9297 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
9298 | { | |
9299 | struct drm_device *dev = dev_priv->dev; | |
be256dc7 | 9300 | struct intel_crtc *crtc; |
be256dc7 | 9301 | |
d3fcc808 | 9302 | for_each_intel_crtc(dev, crtc) |
e2c719b7 | 9303 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
be256dc7 PZ |
9304 | pipe_name(crtc->pipe)); |
9305 | ||
e2c719b7 RC |
9306 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n"); |
9307 | I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n"); | |
9308 | I915_STATE_WARN(I915_READ(WRPLL_CTL1) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); | |
9309 | I915_STATE_WARN(I915_READ(WRPLL_CTL2) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n"); | |
9310 | I915_STATE_WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n"); | |
9311 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, | |
be256dc7 | 9312 | "CPU PWM1 enabled\n"); |
c5107b87 | 9313 | if (IS_HASWELL(dev)) |
e2c719b7 | 9314 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
c5107b87 | 9315 | "CPU PWM2 enabled\n"); |
e2c719b7 | 9316 | I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE, |
be256dc7 | 9317 | "PCH PWM1 enabled\n"); |
e2c719b7 | 9318 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
be256dc7 | 9319 | "Utility pin enabled\n"); |
e2c719b7 | 9320 | I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n"); |
be256dc7 | 9321 | |
9926ada1 PZ |
9322 | /* |
9323 | * In theory we can still leave IRQs enabled, as long as only the HPD | |
9324 | * interrupts remain enabled. We used to check for that, but since it's | |
9325 | * gen-specific and since we only disable LCPLL after we fully disable | |
9326 | * the interrupts, the check below should be enough. | |
9327 | */ | |
e2c719b7 | 9328 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
be256dc7 PZ |
9329 | } |
9330 | ||
9ccd5aeb PZ |
9331 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) |
9332 | { | |
9333 | struct drm_device *dev = dev_priv->dev; | |
9334 | ||
9335 | if (IS_HASWELL(dev)) | |
9336 | return I915_READ(D_COMP_HSW); | |
9337 | else | |
9338 | return I915_READ(D_COMP_BDW); | |
9339 | } | |
9340 | ||
3c4c9b81 PZ |
9341 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) |
9342 | { | |
9343 | struct drm_device *dev = dev_priv->dev; | |
9344 | ||
9345 | if (IS_HASWELL(dev)) { | |
9346 | mutex_lock(&dev_priv->rps.hw_lock); | |
9347 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, | |
9348 | val)) | |
f475dadf | 9349 | DRM_ERROR("Failed to write to D_COMP\n"); |
3c4c9b81 PZ |
9350 | mutex_unlock(&dev_priv->rps.hw_lock); |
9351 | } else { | |
9ccd5aeb PZ |
9352 | I915_WRITE(D_COMP_BDW, val); |
9353 | POSTING_READ(D_COMP_BDW); | |
3c4c9b81 | 9354 | } |
be256dc7 PZ |
9355 | } |
9356 | ||
9357 | /* | |
9358 | * This function implements pieces of two sequences from BSpec: | |
9359 | * - Sequence for display software to disable LCPLL | |
9360 | * - Sequence for display software to allow package C8+ | |
9361 | * The steps implemented here are just the steps that actually touch the LCPLL | |
9362 | * register. Callers should take care of disabling all the display engine | |
9363 | * functions, doing the mode unset, fixing interrupts, etc. | |
9364 | */ | |
6ff58d53 PZ |
9365 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
9366 | bool switch_to_fclk, bool allow_power_down) | |
be256dc7 PZ |
9367 | { |
9368 | uint32_t val; | |
9369 | ||
9370 | assert_can_disable_lcpll(dev_priv); | |
9371 | ||
9372 | val = I915_READ(LCPLL_CTL); | |
9373 | ||
9374 | if (switch_to_fclk) { | |
9375 | val |= LCPLL_CD_SOURCE_FCLK; | |
9376 | I915_WRITE(LCPLL_CTL, val); | |
9377 | ||
9378 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & | |
9379 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) | |
9380 | DRM_ERROR("Switching to FCLK failed\n"); | |
9381 | ||
9382 | val = I915_READ(LCPLL_CTL); | |
9383 | } | |
9384 | ||
9385 | val |= LCPLL_PLL_DISABLE; | |
9386 | I915_WRITE(LCPLL_CTL, val); | |
9387 | POSTING_READ(LCPLL_CTL); | |
9388 | ||
9389 | if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1)) | |
9390 | DRM_ERROR("LCPLL still locked\n"); | |
9391 | ||
9ccd5aeb | 9392 | val = hsw_read_dcomp(dev_priv); |
be256dc7 | 9393 | val |= D_COMP_COMP_DISABLE; |
3c4c9b81 | 9394 | hsw_write_dcomp(dev_priv, val); |
be256dc7 PZ |
9395 | ndelay(100); |
9396 | ||
9ccd5aeb PZ |
9397 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
9398 | 1)) | |
be256dc7 PZ |
9399 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
9400 | ||
9401 | if (allow_power_down) { | |
9402 | val = I915_READ(LCPLL_CTL); | |
9403 | val |= LCPLL_POWER_DOWN_ALLOW; | |
9404 | I915_WRITE(LCPLL_CTL, val); | |
9405 | POSTING_READ(LCPLL_CTL); | |
9406 | } | |
9407 | } | |
9408 | ||
9409 | /* | |
9410 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL | |
9411 | * source. | |
9412 | */ | |
6ff58d53 | 9413 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
be256dc7 PZ |
9414 | { |
9415 | uint32_t val; | |
9416 | ||
9417 | val = I915_READ(LCPLL_CTL); | |
9418 | ||
9419 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | | |
9420 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) | |
9421 | return; | |
9422 | ||
a8a8bd54 PZ |
9423 | /* |
9424 | * Make sure we're not on PC8 state before disabling PC8, otherwise | |
9425 | * we'll hang the machine. To prevent PC8 state, just enable force_wake. | |
a8a8bd54 | 9426 | */ |
59bad947 | 9427 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
215733fa | 9428 | |
be256dc7 PZ |
9429 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
9430 | val &= ~LCPLL_POWER_DOWN_ALLOW; | |
9431 | I915_WRITE(LCPLL_CTL, val); | |
35d8f2eb | 9432 | POSTING_READ(LCPLL_CTL); |
be256dc7 PZ |
9433 | } |
9434 | ||
9ccd5aeb | 9435 | val = hsw_read_dcomp(dev_priv); |
be256dc7 PZ |
9436 | val |= D_COMP_COMP_FORCE; |
9437 | val &= ~D_COMP_COMP_DISABLE; | |
3c4c9b81 | 9438 | hsw_write_dcomp(dev_priv, val); |
be256dc7 PZ |
9439 | |
9440 | val = I915_READ(LCPLL_CTL); | |
9441 | val &= ~LCPLL_PLL_DISABLE; | |
9442 | I915_WRITE(LCPLL_CTL, val); | |
9443 | ||
9444 | if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5)) | |
9445 | DRM_ERROR("LCPLL not locked yet\n"); | |
9446 | ||
9447 | if (val & LCPLL_CD_SOURCE_FCLK) { | |
9448 | val = I915_READ(LCPLL_CTL); | |
9449 | val &= ~LCPLL_CD_SOURCE_FCLK; | |
9450 | I915_WRITE(LCPLL_CTL, val); | |
9451 | ||
9452 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & | |
9453 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) | |
9454 | DRM_ERROR("Switching back to LCPLL failed\n"); | |
9455 | } | |
215733fa | 9456 | |
59bad947 | 9457 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
b6283055 | 9458 | intel_update_cdclk(dev_priv->dev); |
be256dc7 PZ |
9459 | } |
9460 | ||
765dab67 PZ |
9461 | /* |
9462 | * Package states C8 and deeper are really deep PC states that can only be | |
9463 | * reached when all the devices on the system allow it, so even if the graphics | |
9464 | * device allows PC8+, it doesn't mean the system will actually get to these | |
9465 | * states. Our driver only allows PC8+ when going into runtime PM. | |
9466 | * | |
9467 | * The requirements for PC8+ are that all the outputs are disabled, the power | |
9468 | * well is disabled and most interrupts are disabled, and these are also | |
9469 | * requirements for runtime PM. When these conditions are met, we manually do | |
9470 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk | |
9471 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard | |
9472 | * hang the machine. | |
9473 | * | |
9474 | * When we really reach PC8 or deeper states (not just when we allow it) we lose | |
9475 | * the state of some registers, so when we come back from PC8+ we need to | |
9476 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't | |
9477 | * need to take care of the registers kept by RC6. Notice that this happens even | |
9478 | * if we don't put the device in PCI D3 state (which is what currently happens | |
9479 | * because of the runtime PM support). | |
9480 | * | |
9481 | * For more, read "Display Sequences for Package C8" on the hardware | |
9482 | * documentation. | |
9483 | */ | |
a14cb6fc | 9484 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
c67a470b | 9485 | { |
c67a470b PZ |
9486 | struct drm_device *dev = dev_priv->dev; |
9487 | uint32_t val; | |
9488 | ||
c67a470b PZ |
9489 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
9490 | ||
c67a470b PZ |
9491 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
9492 | val = I915_READ(SOUTH_DSPCLK_GATE_D); | |
9493 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; | |
9494 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); | |
9495 | } | |
9496 | ||
9497 | lpt_disable_clkout_dp(dev); | |
c67a470b PZ |
9498 | hsw_disable_lcpll(dev_priv, true, true); |
9499 | } | |
9500 | ||
a14cb6fc | 9501 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
c67a470b PZ |
9502 | { |
9503 | struct drm_device *dev = dev_priv->dev; | |
9504 | uint32_t val; | |
9505 | ||
c67a470b PZ |
9506 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
9507 | ||
9508 | hsw_restore_lcpll(dev_priv); | |
c67a470b PZ |
9509 | lpt_init_pch_refclk(dev); |
9510 | ||
9511 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { | |
9512 | val = I915_READ(SOUTH_DSPCLK_GATE_D); | |
9513 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; | |
9514 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); | |
9515 | } | |
9516 | ||
9517 | intel_prepare_ddi(dev); | |
c67a470b PZ |
9518 | } |
9519 | ||
a821fc46 | 9520 | static void broxton_modeset_global_resources(struct drm_atomic_state *old_state) |
f8437dd1 | 9521 | { |
a821fc46 | 9522 | struct drm_device *dev = old_state->dev; |
f8437dd1 | 9523 | struct drm_i915_private *dev_priv = dev->dev_private; |
a821fc46 | 9524 | int max_pixclk = intel_mode_max_pixclk(dev, NULL); |
f8437dd1 VK |
9525 | int req_cdclk; |
9526 | ||
9527 | /* see the comment in valleyview_modeset_global_resources */ | |
9528 | if (WARN_ON(max_pixclk < 0)) | |
9529 | return; | |
9530 | ||
9531 | req_cdclk = broxton_calc_cdclk(dev_priv, max_pixclk); | |
9532 | ||
9533 | if (req_cdclk != dev_priv->cdclk_freq) | |
9534 | broxton_set_cdclk(dev, req_cdclk); | |
9535 | } | |
9536 | ||
b432e5cf VS |
9537 | /* compute the max rate for new configuration */ |
9538 | static int ilk_max_pixel_rate(struct drm_i915_private *dev_priv) | |
9539 | { | |
9540 | struct drm_device *dev = dev_priv->dev; | |
9541 | struct intel_crtc *intel_crtc; | |
9542 | struct drm_crtc *crtc; | |
9543 | int max_pixel_rate = 0; | |
9544 | int pixel_rate; | |
9545 | ||
9546 | for_each_crtc(dev, crtc) { | |
9547 | if (!crtc->state->enable) | |
9548 | continue; | |
9549 | ||
9550 | intel_crtc = to_intel_crtc(crtc); | |
9551 | pixel_rate = ilk_pipe_pixel_rate(intel_crtc->config); | |
9552 | ||
9553 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ | |
9554 | if (IS_BROADWELL(dev) && intel_crtc->config->ips_enabled) | |
9555 | pixel_rate = DIV_ROUND_UP(pixel_rate * 100, 95); | |
9556 | ||
9557 | max_pixel_rate = max(max_pixel_rate, pixel_rate); | |
9558 | } | |
9559 | ||
9560 | return max_pixel_rate; | |
9561 | } | |
9562 | ||
9563 | static void broadwell_set_cdclk(struct drm_device *dev, int cdclk) | |
9564 | { | |
9565 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9566 | uint32_t val, data; | |
9567 | int ret; | |
9568 | ||
9569 | if (WARN((I915_READ(LCPLL_CTL) & | |
9570 | (LCPLL_PLL_DISABLE | LCPLL_PLL_LOCK | | |
9571 | LCPLL_CD_CLOCK_DISABLE | LCPLL_ROOT_CD_CLOCK_DISABLE | | |
9572 | LCPLL_CD2X_CLOCK_DISABLE | LCPLL_POWER_DOWN_ALLOW | | |
9573 | LCPLL_CD_SOURCE_FCLK)) != LCPLL_PLL_LOCK, | |
9574 | "trying to change cdclk frequency with cdclk not enabled\n")) | |
9575 | return; | |
9576 | ||
9577 | mutex_lock(&dev_priv->rps.hw_lock); | |
9578 | ret = sandybridge_pcode_write(dev_priv, | |
9579 | BDW_PCODE_DISPLAY_FREQ_CHANGE_REQ, 0x0); | |
9580 | mutex_unlock(&dev_priv->rps.hw_lock); | |
9581 | if (ret) { | |
9582 | DRM_ERROR("failed to inform pcode about cdclk change\n"); | |
9583 | return; | |
9584 | } | |
9585 | ||
9586 | val = I915_READ(LCPLL_CTL); | |
9587 | val |= LCPLL_CD_SOURCE_FCLK; | |
9588 | I915_WRITE(LCPLL_CTL, val); | |
9589 | ||
9590 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & | |
9591 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) | |
9592 | DRM_ERROR("Switching to FCLK failed\n"); | |
9593 | ||
9594 | val = I915_READ(LCPLL_CTL); | |
9595 | val &= ~LCPLL_CLK_FREQ_MASK; | |
9596 | ||
9597 | switch (cdclk) { | |
9598 | case 450000: | |
9599 | val |= LCPLL_CLK_FREQ_450; | |
9600 | data = 0; | |
9601 | break; | |
9602 | case 540000: | |
9603 | val |= LCPLL_CLK_FREQ_54O_BDW; | |
9604 | data = 1; | |
9605 | break; | |
9606 | case 337500: | |
9607 | val |= LCPLL_CLK_FREQ_337_5_BDW; | |
9608 | data = 2; | |
9609 | break; | |
9610 | case 675000: | |
9611 | val |= LCPLL_CLK_FREQ_675_BDW; | |
9612 | data = 3; | |
9613 | break; | |
9614 | default: | |
9615 | WARN(1, "invalid cdclk frequency\n"); | |
9616 | return; | |
9617 | } | |
9618 | ||
9619 | I915_WRITE(LCPLL_CTL, val); | |
9620 | ||
9621 | val = I915_READ(LCPLL_CTL); | |
9622 | val &= ~LCPLL_CD_SOURCE_FCLK; | |
9623 | I915_WRITE(LCPLL_CTL, val); | |
9624 | ||
9625 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & | |
9626 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) | |
9627 | DRM_ERROR("Switching back to LCPLL failed\n"); | |
9628 | ||
9629 | mutex_lock(&dev_priv->rps.hw_lock); | |
9630 | sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, data); | |
9631 | mutex_unlock(&dev_priv->rps.hw_lock); | |
9632 | ||
9633 | intel_update_cdclk(dev); | |
9634 | ||
9635 | WARN(cdclk != dev_priv->cdclk_freq, | |
9636 | "cdclk requested %d kHz but got %d kHz\n", | |
9637 | cdclk, dev_priv->cdclk_freq); | |
9638 | } | |
9639 | ||
9640 | static int broadwell_calc_cdclk(struct drm_i915_private *dev_priv, | |
9641 | int max_pixel_rate) | |
9642 | { | |
9643 | int cdclk; | |
9644 | ||
9645 | /* | |
9646 | * FIXME should also account for plane ratio | |
9647 | * once 64bpp pixel formats are supported. | |
9648 | */ | |
9649 | if (max_pixel_rate > 540000) | |
9650 | cdclk = 675000; | |
9651 | else if (max_pixel_rate > 450000) | |
9652 | cdclk = 540000; | |
9653 | else if (max_pixel_rate > 337500) | |
9654 | cdclk = 450000; | |
9655 | else | |
9656 | cdclk = 337500; | |
9657 | ||
9658 | /* | |
9659 | * FIXME move the cdclk caclulation to | |
9660 | * compute_config() so we can fail gracegully. | |
9661 | */ | |
9662 | if (cdclk > dev_priv->max_cdclk_freq) { | |
9663 | DRM_ERROR("requested cdclk (%d kHz) exceeds max (%d kHz)\n", | |
9664 | cdclk, dev_priv->max_cdclk_freq); | |
9665 | cdclk = dev_priv->max_cdclk_freq; | |
9666 | } | |
9667 | ||
9668 | return cdclk; | |
9669 | } | |
9670 | ||
9671 | static int broadwell_modeset_global_pipes(struct drm_atomic_state *state) | |
9672 | { | |
9673 | struct drm_i915_private *dev_priv = to_i915(state->dev); | |
9674 | struct drm_crtc *crtc; | |
9675 | struct drm_crtc_state *crtc_state; | |
9676 | int max_pixclk = ilk_max_pixel_rate(dev_priv); | |
9677 | int cdclk, i; | |
9678 | ||
9679 | cdclk = broadwell_calc_cdclk(dev_priv, max_pixclk); | |
9680 | ||
9681 | if (cdclk == dev_priv->cdclk_freq) | |
9682 | return 0; | |
9683 | ||
9684 | /* add all active pipes to the state */ | |
9685 | for_each_crtc(state->dev, crtc) { | |
9686 | if (!crtc->state->enable) | |
9687 | continue; | |
9688 | ||
9689 | crtc_state = drm_atomic_get_crtc_state(state, crtc); | |
9690 | if (IS_ERR(crtc_state)) | |
9691 | return PTR_ERR(crtc_state); | |
9692 | } | |
9693 | ||
9694 | /* disable/enable all currently active pipes while we change cdclk */ | |
9695 | for_each_crtc_in_state(state, crtc, crtc_state, i) | |
9696 | if (crtc_state->enable) | |
9697 | crtc_state->mode_changed = true; | |
9698 | ||
9699 | return 0; | |
9700 | } | |
9701 | ||
9702 | static void broadwell_modeset_global_resources(struct drm_atomic_state *state) | |
9703 | { | |
9704 | struct drm_device *dev = state->dev; | |
9705 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9706 | int max_pixel_rate = ilk_max_pixel_rate(dev_priv); | |
9707 | int req_cdclk = broadwell_calc_cdclk(dev_priv, max_pixel_rate); | |
9708 | ||
9709 | if (req_cdclk != dev_priv->cdclk_freq) | |
9710 | broadwell_set_cdclk(dev, req_cdclk); | |
9711 | } | |
9712 | ||
190f68c5 ACO |
9713 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
9714 | struct intel_crtc_state *crtc_state) | |
09b4ddf9 | 9715 | { |
190f68c5 | 9716 | if (!intel_ddi_pll_select(crtc, crtc_state)) |
6441ab5f | 9717 | return -EINVAL; |
716c2e55 | 9718 | |
c7653199 | 9719 | crtc->lowfreq_avail = false; |
644cef34 | 9720 | |
c8f7a0db | 9721 | return 0; |
79e53945 JB |
9722 | } |
9723 | ||
3760b59c S |
9724 | static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv, |
9725 | enum port port, | |
9726 | struct intel_crtc_state *pipe_config) | |
9727 | { | |
9728 | switch (port) { | |
9729 | case PORT_A: | |
9730 | pipe_config->ddi_pll_sel = SKL_DPLL0; | |
9731 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; | |
9732 | break; | |
9733 | case PORT_B: | |
9734 | pipe_config->ddi_pll_sel = SKL_DPLL1; | |
9735 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; | |
9736 | break; | |
9737 | case PORT_C: | |
9738 | pipe_config->ddi_pll_sel = SKL_DPLL2; | |
9739 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; | |
9740 | break; | |
9741 | default: | |
9742 | DRM_ERROR("Incorrect port type\n"); | |
9743 | } | |
9744 | } | |
9745 | ||
96b7dfb7 S |
9746 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
9747 | enum port port, | |
5cec258b | 9748 | struct intel_crtc_state *pipe_config) |
96b7dfb7 | 9749 | { |
3148ade7 | 9750 | u32 temp, dpll_ctl1; |
96b7dfb7 S |
9751 | |
9752 | temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port); | |
9753 | pipe_config->ddi_pll_sel = temp >> (port * 3 + 1); | |
9754 | ||
9755 | switch (pipe_config->ddi_pll_sel) { | |
3148ade7 DL |
9756 | case SKL_DPLL0: |
9757 | /* | |
9758 | * On SKL the eDP DPLL (DPLL0 as we don't use SSC) is not part | |
9759 | * of the shared DPLL framework and thus needs to be read out | |
9760 | * separately | |
9761 | */ | |
9762 | dpll_ctl1 = I915_READ(DPLL_CTRL1); | |
9763 | pipe_config->dpll_hw_state.ctrl1 = dpll_ctl1 & 0x3f; | |
9764 | break; | |
96b7dfb7 S |
9765 | case SKL_DPLL1: |
9766 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; | |
9767 | break; | |
9768 | case SKL_DPLL2: | |
9769 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; | |
9770 | break; | |
9771 | case SKL_DPLL3: | |
9772 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; | |
9773 | break; | |
96b7dfb7 S |
9774 | } |
9775 | } | |
9776 | ||
7d2c8175 DL |
9777 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
9778 | enum port port, | |
5cec258b | 9779 | struct intel_crtc_state *pipe_config) |
7d2c8175 DL |
9780 | { |
9781 | pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); | |
9782 | ||
9783 | switch (pipe_config->ddi_pll_sel) { | |
9784 | case PORT_CLK_SEL_WRPLL1: | |
9785 | pipe_config->shared_dpll = DPLL_ID_WRPLL1; | |
9786 | break; | |
9787 | case PORT_CLK_SEL_WRPLL2: | |
9788 | pipe_config->shared_dpll = DPLL_ID_WRPLL2; | |
9789 | break; | |
9790 | } | |
9791 | } | |
9792 | ||
26804afd | 9793 | static void haswell_get_ddi_port_state(struct intel_crtc *crtc, |
5cec258b | 9794 | struct intel_crtc_state *pipe_config) |
26804afd DV |
9795 | { |
9796 | struct drm_device *dev = crtc->base.dev; | |
9797 | struct drm_i915_private *dev_priv = dev->dev_private; | |
d452c5b6 | 9798 | struct intel_shared_dpll *pll; |
26804afd DV |
9799 | enum port port; |
9800 | uint32_t tmp; | |
9801 | ||
9802 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); | |
9803 | ||
9804 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; | |
9805 | ||
96b7dfb7 S |
9806 | if (IS_SKYLAKE(dev)) |
9807 | skylake_get_ddi_pll(dev_priv, port, pipe_config); | |
3760b59c S |
9808 | else if (IS_BROXTON(dev)) |
9809 | bxt_get_ddi_pll(dev_priv, port, pipe_config); | |
96b7dfb7 S |
9810 | else |
9811 | haswell_get_ddi_pll(dev_priv, port, pipe_config); | |
9cd86933 | 9812 | |
d452c5b6 DV |
9813 | if (pipe_config->shared_dpll >= 0) { |
9814 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; | |
9815 | ||
9816 | WARN_ON(!pll->get_hw_state(dev_priv, pll, | |
9817 | &pipe_config->dpll_hw_state)); | |
9818 | } | |
9819 | ||
26804afd DV |
9820 | /* |
9821 | * Haswell has only FDI/PCH transcoder A. It is which is connected to | |
9822 | * DDI E. So just check whether this pipe is wired to DDI E and whether | |
9823 | * the PCH transcoder is on. | |
9824 | */ | |
ca370455 DL |
9825 | if (INTEL_INFO(dev)->gen < 9 && |
9826 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { | |
26804afd DV |
9827 | pipe_config->has_pch_encoder = true; |
9828 | ||
9829 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); | |
9830 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> | |
9831 | FDI_DP_PORT_WIDTH_SHIFT) + 1; | |
9832 | ||
9833 | ironlake_get_fdi_m_n_config(crtc, pipe_config); | |
9834 | } | |
9835 | } | |
9836 | ||
0e8ffe1b | 9837 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 9838 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
9839 | { |
9840 | struct drm_device *dev = crtc->base.dev; | |
9841 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2fa2fe9a | 9842 | enum intel_display_power_domain pfit_domain; |
0e8ffe1b DV |
9843 | uint32_t tmp; |
9844 | ||
f458ebbc | 9845 | if (!intel_display_power_is_enabled(dev_priv, |
b5482bd0 ID |
9846 | POWER_DOMAIN_PIPE(crtc->pipe))) |
9847 | return false; | |
9848 | ||
e143a21c | 9849 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 DV |
9850 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
9851 | ||
eccb140b DV |
9852 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
9853 | if (tmp & TRANS_DDI_FUNC_ENABLE) { | |
9854 | enum pipe trans_edp_pipe; | |
9855 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { | |
9856 | default: | |
9857 | WARN(1, "unknown pipe linked to edp transcoder\n"); | |
9858 | case TRANS_DDI_EDP_INPUT_A_ONOFF: | |
9859 | case TRANS_DDI_EDP_INPUT_A_ON: | |
9860 | trans_edp_pipe = PIPE_A; | |
9861 | break; | |
9862 | case TRANS_DDI_EDP_INPUT_B_ONOFF: | |
9863 | trans_edp_pipe = PIPE_B; | |
9864 | break; | |
9865 | case TRANS_DDI_EDP_INPUT_C_ONOFF: | |
9866 | trans_edp_pipe = PIPE_C; | |
9867 | break; | |
9868 | } | |
9869 | ||
9870 | if (trans_edp_pipe == crtc->pipe) | |
9871 | pipe_config->cpu_transcoder = TRANSCODER_EDP; | |
9872 | } | |
9873 | ||
f458ebbc | 9874 | if (!intel_display_power_is_enabled(dev_priv, |
eccb140b | 9875 | POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder))) |
2bfce950 PZ |
9876 | return false; |
9877 | ||
eccb140b | 9878 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
0e8ffe1b DV |
9879 | if (!(tmp & PIPECONF_ENABLE)) |
9880 | return false; | |
9881 | ||
26804afd | 9882 | haswell_get_ddi_port_state(crtc, pipe_config); |
627eb5a3 | 9883 | |
1bd1bd80 DV |
9884 | intel_get_pipe_timings(crtc, pipe_config); |
9885 | ||
a1b2278e CK |
9886 | if (INTEL_INFO(dev)->gen >= 9) { |
9887 | skl_init_scalers(dev, crtc, pipe_config); | |
9888 | } | |
9889 | ||
2fa2fe9a | 9890 | pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
af99ceda CK |
9891 | |
9892 | if (INTEL_INFO(dev)->gen >= 9) { | |
9893 | pipe_config->scaler_state.scaler_id = -1; | |
9894 | pipe_config->scaler_state.scaler_users &= ~(1 << SKL_CRTC_INDEX); | |
9895 | } | |
9896 | ||
bd2e244f | 9897 | if (intel_display_power_is_enabled(dev_priv, pfit_domain)) { |
ff6d9f55 | 9898 | if (INTEL_INFO(dev)->gen == 9) |
bd2e244f | 9899 | skylake_get_pfit_config(crtc, pipe_config); |
ff6d9f55 | 9900 | else if (INTEL_INFO(dev)->gen < 9) |
bd2e244f | 9901 | ironlake_get_pfit_config(crtc, pipe_config); |
ff6d9f55 JB |
9902 | else |
9903 | MISSING_CASE(INTEL_INFO(dev)->gen); | |
bd2e244f | 9904 | } |
88adfff1 | 9905 | |
e59150dc JB |
9906 | if (IS_HASWELL(dev)) |
9907 | pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) && | |
9908 | (I915_READ(IPS_CTL) & IPS_ENABLE); | |
42db64ef | 9909 | |
ebb69c95 CT |
9910 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP) { |
9911 | pipe_config->pixel_multiplier = | |
9912 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; | |
9913 | } else { | |
9914 | pipe_config->pixel_multiplier = 1; | |
9915 | } | |
6c49f241 | 9916 | |
0e8ffe1b DV |
9917 | return true; |
9918 | } | |
9919 | ||
560b85bb CW |
9920 | static void i845_update_cursor(struct drm_crtc *crtc, u32 base) |
9921 | { | |
9922 | struct drm_device *dev = crtc->dev; | |
9923 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9924 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
dc41c154 | 9925 | uint32_t cntl = 0, size = 0; |
560b85bb | 9926 | |
dc41c154 | 9927 | if (base) { |
3dd512fb MR |
9928 | unsigned int width = intel_crtc->base.cursor->state->crtc_w; |
9929 | unsigned int height = intel_crtc->base.cursor->state->crtc_h; | |
dc41c154 VS |
9930 | unsigned int stride = roundup_pow_of_two(width) * 4; |
9931 | ||
9932 | switch (stride) { | |
9933 | default: | |
9934 | WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n", | |
9935 | width, stride); | |
9936 | stride = 256; | |
9937 | /* fallthrough */ | |
9938 | case 256: | |
9939 | case 512: | |
9940 | case 1024: | |
9941 | case 2048: | |
9942 | break; | |
4b0e333e CW |
9943 | } |
9944 | ||
dc41c154 VS |
9945 | cntl |= CURSOR_ENABLE | |
9946 | CURSOR_GAMMA_ENABLE | | |
9947 | CURSOR_FORMAT_ARGB | | |
9948 | CURSOR_STRIDE(stride); | |
9949 | ||
9950 | size = (height << 12) | width; | |
4b0e333e | 9951 | } |
560b85bb | 9952 | |
dc41c154 VS |
9953 | if (intel_crtc->cursor_cntl != 0 && |
9954 | (intel_crtc->cursor_base != base || | |
9955 | intel_crtc->cursor_size != size || | |
9956 | intel_crtc->cursor_cntl != cntl)) { | |
9957 | /* On these chipsets we can only modify the base/size/stride | |
9958 | * whilst the cursor is disabled. | |
9959 | */ | |
9960 | I915_WRITE(_CURACNTR, 0); | |
4b0e333e | 9961 | POSTING_READ(_CURACNTR); |
dc41c154 | 9962 | intel_crtc->cursor_cntl = 0; |
4b0e333e | 9963 | } |
560b85bb | 9964 | |
99d1f387 | 9965 | if (intel_crtc->cursor_base != base) { |
9db4a9c7 | 9966 | I915_WRITE(_CURABASE, base); |
99d1f387 VS |
9967 | intel_crtc->cursor_base = base; |
9968 | } | |
4726e0b0 | 9969 | |
dc41c154 VS |
9970 | if (intel_crtc->cursor_size != size) { |
9971 | I915_WRITE(CURSIZE, size); | |
9972 | intel_crtc->cursor_size = size; | |
4b0e333e | 9973 | } |
560b85bb | 9974 | |
4b0e333e | 9975 | if (intel_crtc->cursor_cntl != cntl) { |
4b0e333e CW |
9976 | I915_WRITE(_CURACNTR, cntl); |
9977 | POSTING_READ(_CURACNTR); | |
4b0e333e | 9978 | intel_crtc->cursor_cntl = cntl; |
560b85bb | 9979 | } |
560b85bb CW |
9980 | } |
9981 | ||
560b85bb | 9982 | static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base) |
65a21cd6 JB |
9983 | { |
9984 | struct drm_device *dev = crtc->dev; | |
9985 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9986 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
9987 | int pipe = intel_crtc->pipe; | |
4b0e333e CW |
9988 | uint32_t cntl; |
9989 | ||
9990 | cntl = 0; | |
9991 | if (base) { | |
9992 | cntl = MCURSOR_GAMMA_ENABLE; | |
3dd512fb | 9993 | switch (intel_crtc->base.cursor->state->crtc_w) { |
4726e0b0 SK |
9994 | case 64: |
9995 | cntl |= CURSOR_MODE_64_ARGB_AX; | |
9996 | break; | |
9997 | case 128: | |
9998 | cntl |= CURSOR_MODE_128_ARGB_AX; | |
9999 | break; | |
10000 | case 256: | |
10001 | cntl |= CURSOR_MODE_256_ARGB_AX; | |
10002 | break; | |
10003 | default: | |
3dd512fb | 10004 | MISSING_CASE(intel_crtc->base.cursor->state->crtc_w); |
4726e0b0 | 10005 | return; |
65a21cd6 | 10006 | } |
4b0e333e | 10007 | cntl |= pipe << 28; /* Connect to correct pipe */ |
47bf17a7 VS |
10008 | |
10009 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) | |
10010 | cntl |= CURSOR_PIPE_CSC_ENABLE; | |
4b0e333e | 10011 | } |
65a21cd6 | 10012 | |
8e7d688b | 10013 | if (crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) |
4398ad45 VS |
10014 | cntl |= CURSOR_ROTATE_180; |
10015 | ||
4b0e333e CW |
10016 | if (intel_crtc->cursor_cntl != cntl) { |
10017 | I915_WRITE(CURCNTR(pipe), cntl); | |
10018 | POSTING_READ(CURCNTR(pipe)); | |
10019 | intel_crtc->cursor_cntl = cntl; | |
65a21cd6 | 10020 | } |
4b0e333e | 10021 | |
65a21cd6 | 10022 | /* and commit changes on next vblank */ |
5efb3e28 VS |
10023 | I915_WRITE(CURBASE(pipe), base); |
10024 | POSTING_READ(CURBASE(pipe)); | |
99d1f387 VS |
10025 | |
10026 | intel_crtc->cursor_base = base; | |
65a21cd6 JB |
10027 | } |
10028 | ||
cda4b7d3 | 10029 | /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */ |
6b383a7f CW |
10030 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, |
10031 | bool on) | |
cda4b7d3 CW |
10032 | { |
10033 | struct drm_device *dev = crtc->dev; | |
10034 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10035 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10036 | int pipe = intel_crtc->pipe; | |
3d7d6510 MR |
10037 | int x = crtc->cursor_x; |
10038 | int y = crtc->cursor_y; | |
d6e4db15 | 10039 | u32 base = 0, pos = 0; |
cda4b7d3 | 10040 | |
d6e4db15 | 10041 | if (on) |
cda4b7d3 | 10042 | base = intel_crtc->cursor_addr; |
cda4b7d3 | 10043 | |
6e3c9717 | 10044 | if (x >= intel_crtc->config->pipe_src_w) |
d6e4db15 VS |
10045 | base = 0; |
10046 | ||
6e3c9717 | 10047 | if (y >= intel_crtc->config->pipe_src_h) |
cda4b7d3 CW |
10048 | base = 0; |
10049 | ||
10050 | if (x < 0) { | |
3dd512fb | 10051 | if (x + intel_crtc->base.cursor->state->crtc_w <= 0) |
cda4b7d3 CW |
10052 | base = 0; |
10053 | ||
10054 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; | |
10055 | x = -x; | |
10056 | } | |
10057 | pos |= x << CURSOR_X_SHIFT; | |
10058 | ||
10059 | if (y < 0) { | |
3dd512fb | 10060 | if (y + intel_crtc->base.cursor->state->crtc_h <= 0) |
cda4b7d3 CW |
10061 | base = 0; |
10062 | ||
10063 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; | |
10064 | y = -y; | |
10065 | } | |
10066 | pos |= y << CURSOR_Y_SHIFT; | |
10067 | ||
4b0e333e | 10068 | if (base == 0 && intel_crtc->cursor_base == 0) |
cda4b7d3 CW |
10069 | return; |
10070 | ||
5efb3e28 VS |
10071 | I915_WRITE(CURPOS(pipe), pos); |
10072 | ||
4398ad45 VS |
10073 | /* ILK+ do this automagically */ |
10074 | if (HAS_GMCH_DISPLAY(dev) && | |
8e7d688b | 10075 | crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) { |
3dd512fb MR |
10076 | base += (intel_crtc->base.cursor->state->crtc_h * |
10077 | intel_crtc->base.cursor->state->crtc_w - 1) * 4; | |
4398ad45 VS |
10078 | } |
10079 | ||
8ac54669 | 10080 | if (IS_845G(dev) || IS_I865G(dev)) |
5efb3e28 VS |
10081 | i845_update_cursor(crtc, base); |
10082 | else | |
10083 | i9xx_update_cursor(crtc, base); | |
cda4b7d3 CW |
10084 | } |
10085 | ||
dc41c154 VS |
10086 | static bool cursor_size_ok(struct drm_device *dev, |
10087 | uint32_t width, uint32_t height) | |
10088 | { | |
10089 | if (width == 0 || height == 0) | |
10090 | return false; | |
10091 | ||
10092 | /* | |
10093 | * 845g/865g are special in that they are only limited by | |
10094 | * the width of their cursors, the height is arbitrary up to | |
10095 | * the precision of the register. Everything else requires | |
10096 | * square cursors, limited to a few power-of-two sizes. | |
10097 | */ | |
10098 | if (IS_845G(dev) || IS_I865G(dev)) { | |
10099 | if ((width & 63) != 0) | |
10100 | return false; | |
10101 | ||
10102 | if (width > (IS_845G(dev) ? 64 : 512)) | |
10103 | return false; | |
10104 | ||
10105 | if (height > 1023) | |
10106 | return false; | |
10107 | } else { | |
10108 | switch (width | height) { | |
10109 | case 256: | |
10110 | case 128: | |
10111 | if (IS_GEN2(dev)) | |
10112 | return false; | |
10113 | case 64: | |
10114 | break; | |
10115 | default: | |
10116 | return false; | |
10117 | } | |
10118 | } | |
10119 | ||
10120 | return true; | |
10121 | } | |
10122 | ||
79e53945 | 10123 | static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, |
7203425a | 10124 | u16 *blue, uint32_t start, uint32_t size) |
79e53945 | 10125 | { |
7203425a | 10126 | int end = (start + size > 256) ? 256 : start + size, i; |
79e53945 | 10127 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
79e53945 | 10128 | |
7203425a | 10129 | for (i = start; i < end; i++) { |
79e53945 JB |
10130 | intel_crtc->lut_r[i] = red[i] >> 8; |
10131 | intel_crtc->lut_g[i] = green[i] >> 8; | |
10132 | intel_crtc->lut_b[i] = blue[i] >> 8; | |
10133 | } | |
10134 | ||
10135 | intel_crtc_load_lut(crtc); | |
10136 | } | |
10137 | ||
79e53945 JB |
10138 | /* VESA 640x480x72Hz mode to set on the pipe */ |
10139 | static struct drm_display_mode load_detect_mode = { | |
10140 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, | |
10141 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), | |
10142 | }; | |
10143 | ||
a8bb6818 DV |
10144 | struct drm_framebuffer * |
10145 | __intel_framebuffer_create(struct drm_device *dev, | |
10146 | struct drm_mode_fb_cmd2 *mode_cmd, | |
10147 | struct drm_i915_gem_object *obj) | |
d2dff872 CW |
10148 | { |
10149 | struct intel_framebuffer *intel_fb; | |
10150 | int ret; | |
10151 | ||
10152 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); | |
10153 | if (!intel_fb) { | |
6ccb81f2 | 10154 | drm_gem_object_unreference(&obj->base); |
d2dff872 CW |
10155 | return ERR_PTR(-ENOMEM); |
10156 | } | |
10157 | ||
10158 | ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj); | |
dd4916c5 DV |
10159 | if (ret) |
10160 | goto err; | |
d2dff872 CW |
10161 | |
10162 | return &intel_fb->base; | |
dd4916c5 | 10163 | err: |
6ccb81f2 | 10164 | drm_gem_object_unreference(&obj->base); |
dd4916c5 DV |
10165 | kfree(intel_fb); |
10166 | ||
10167 | return ERR_PTR(ret); | |
d2dff872 CW |
10168 | } |
10169 | ||
b5ea642a | 10170 | static struct drm_framebuffer * |
a8bb6818 DV |
10171 | intel_framebuffer_create(struct drm_device *dev, |
10172 | struct drm_mode_fb_cmd2 *mode_cmd, | |
10173 | struct drm_i915_gem_object *obj) | |
10174 | { | |
10175 | struct drm_framebuffer *fb; | |
10176 | int ret; | |
10177 | ||
10178 | ret = i915_mutex_lock_interruptible(dev); | |
10179 | if (ret) | |
10180 | return ERR_PTR(ret); | |
10181 | fb = __intel_framebuffer_create(dev, mode_cmd, obj); | |
10182 | mutex_unlock(&dev->struct_mutex); | |
10183 | ||
10184 | return fb; | |
10185 | } | |
10186 | ||
d2dff872 CW |
10187 | static u32 |
10188 | intel_framebuffer_pitch_for_width(int width, int bpp) | |
10189 | { | |
10190 | u32 pitch = DIV_ROUND_UP(width * bpp, 8); | |
10191 | return ALIGN(pitch, 64); | |
10192 | } | |
10193 | ||
10194 | static u32 | |
10195 | intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp) | |
10196 | { | |
10197 | u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp); | |
1267a26b | 10198 | return PAGE_ALIGN(pitch * mode->vdisplay); |
d2dff872 CW |
10199 | } |
10200 | ||
10201 | static struct drm_framebuffer * | |
10202 | intel_framebuffer_create_for_mode(struct drm_device *dev, | |
10203 | struct drm_display_mode *mode, | |
10204 | int depth, int bpp) | |
10205 | { | |
10206 | struct drm_i915_gem_object *obj; | |
0fed39bd | 10207 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
d2dff872 CW |
10208 | |
10209 | obj = i915_gem_alloc_object(dev, | |
10210 | intel_framebuffer_size_for_mode(mode, bpp)); | |
10211 | if (obj == NULL) | |
10212 | return ERR_PTR(-ENOMEM); | |
10213 | ||
10214 | mode_cmd.width = mode->hdisplay; | |
10215 | mode_cmd.height = mode->vdisplay; | |
308e5bcb JB |
10216 | mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width, |
10217 | bpp); | |
5ca0c34a | 10218 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); |
d2dff872 CW |
10219 | |
10220 | return intel_framebuffer_create(dev, &mode_cmd, obj); | |
10221 | } | |
10222 | ||
10223 | static struct drm_framebuffer * | |
10224 | mode_fits_in_fbdev(struct drm_device *dev, | |
10225 | struct drm_display_mode *mode) | |
10226 | { | |
4520f53a | 10227 | #ifdef CONFIG_DRM_I915_FBDEV |
d2dff872 CW |
10228 | struct drm_i915_private *dev_priv = dev->dev_private; |
10229 | struct drm_i915_gem_object *obj; | |
10230 | struct drm_framebuffer *fb; | |
10231 | ||
4c0e5528 | 10232 | if (!dev_priv->fbdev) |
d2dff872 CW |
10233 | return NULL; |
10234 | ||
4c0e5528 | 10235 | if (!dev_priv->fbdev->fb) |
d2dff872 CW |
10236 | return NULL; |
10237 | ||
4c0e5528 DV |
10238 | obj = dev_priv->fbdev->fb->obj; |
10239 | BUG_ON(!obj); | |
10240 | ||
8bcd4553 | 10241 | fb = &dev_priv->fbdev->fb->base; |
01f2c773 VS |
10242 | if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay, |
10243 | fb->bits_per_pixel)) | |
d2dff872 CW |
10244 | return NULL; |
10245 | ||
01f2c773 | 10246 | if (obj->base.size < mode->vdisplay * fb->pitches[0]) |
d2dff872 CW |
10247 | return NULL; |
10248 | ||
10249 | return fb; | |
4520f53a DV |
10250 | #else |
10251 | return NULL; | |
10252 | #endif | |
d2dff872 CW |
10253 | } |
10254 | ||
d3a40d1b ACO |
10255 | static int intel_modeset_setup_plane_state(struct drm_atomic_state *state, |
10256 | struct drm_crtc *crtc, | |
10257 | struct drm_display_mode *mode, | |
10258 | struct drm_framebuffer *fb, | |
10259 | int x, int y) | |
10260 | { | |
10261 | struct drm_plane_state *plane_state; | |
10262 | int hdisplay, vdisplay; | |
10263 | int ret; | |
10264 | ||
10265 | plane_state = drm_atomic_get_plane_state(state, crtc->primary); | |
10266 | if (IS_ERR(plane_state)) | |
10267 | return PTR_ERR(plane_state); | |
10268 | ||
10269 | if (mode) | |
10270 | drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay); | |
10271 | else | |
10272 | hdisplay = vdisplay = 0; | |
10273 | ||
10274 | ret = drm_atomic_set_crtc_for_plane(plane_state, fb ? crtc : NULL); | |
10275 | if (ret) | |
10276 | return ret; | |
10277 | drm_atomic_set_fb_for_plane(plane_state, fb); | |
10278 | plane_state->crtc_x = 0; | |
10279 | plane_state->crtc_y = 0; | |
10280 | plane_state->crtc_w = hdisplay; | |
10281 | plane_state->crtc_h = vdisplay; | |
10282 | plane_state->src_x = x << 16; | |
10283 | plane_state->src_y = y << 16; | |
10284 | plane_state->src_w = hdisplay << 16; | |
10285 | plane_state->src_h = vdisplay << 16; | |
10286 | ||
10287 | return 0; | |
10288 | } | |
10289 | ||
d2434ab7 | 10290 | bool intel_get_load_detect_pipe(struct drm_connector *connector, |
7173188d | 10291 | struct drm_display_mode *mode, |
51fd371b RC |
10292 | struct intel_load_detect_pipe *old, |
10293 | struct drm_modeset_acquire_ctx *ctx) | |
79e53945 JB |
10294 | { |
10295 | struct intel_crtc *intel_crtc; | |
d2434ab7 DV |
10296 | struct intel_encoder *intel_encoder = |
10297 | intel_attached_encoder(connector); | |
79e53945 | 10298 | struct drm_crtc *possible_crtc; |
4ef69c7a | 10299 | struct drm_encoder *encoder = &intel_encoder->base; |
79e53945 JB |
10300 | struct drm_crtc *crtc = NULL; |
10301 | struct drm_device *dev = encoder->dev; | |
94352cf9 | 10302 | struct drm_framebuffer *fb; |
51fd371b | 10303 | struct drm_mode_config *config = &dev->mode_config; |
83a57153 | 10304 | struct drm_atomic_state *state = NULL; |
944b0c76 | 10305 | struct drm_connector_state *connector_state; |
4be07317 | 10306 | struct intel_crtc_state *crtc_state; |
51fd371b | 10307 | int ret, i = -1; |
79e53945 | 10308 | |
d2dff872 | 10309 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
c23cc417 | 10310 | connector->base.id, connector->name, |
8e329a03 | 10311 | encoder->base.id, encoder->name); |
d2dff872 | 10312 | |
51fd371b RC |
10313 | retry: |
10314 | ret = drm_modeset_lock(&config->connection_mutex, ctx); | |
10315 | if (ret) | |
10316 | goto fail_unlock; | |
6e9f798d | 10317 | |
79e53945 JB |
10318 | /* |
10319 | * Algorithm gets a little messy: | |
7a5e4805 | 10320 | * |
79e53945 JB |
10321 | * - if the connector already has an assigned crtc, use it (but make |
10322 | * sure it's on first) | |
7a5e4805 | 10323 | * |
79e53945 JB |
10324 | * - try to find the first unused crtc that can drive this connector, |
10325 | * and use that if we find one | |
79e53945 JB |
10326 | */ |
10327 | ||
10328 | /* See if we already have a CRTC for this connector */ | |
10329 | if (encoder->crtc) { | |
10330 | crtc = encoder->crtc; | |
8261b191 | 10331 | |
51fd371b | 10332 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
4d02e2de DV |
10333 | if (ret) |
10334 | goto fail_unlock; | |
10335 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); | |
51fd371b RC |
10336 | if (ret) |
10337 | goto fail_unlock; | |
7b24056b | 10338 | |
24218aac | 10339 | old->dpms_mode = connector->dpms; |
8261b191 CW |
10340 | old->load_detect_temp = false; |
10341 | ||
10342 | /* Make sure the crtc and connector are running */ | |
24218aac DV |
10343 | if (connector->dpms != DRM_MODE_DPMS_ON) |
10344 | connector->funcs->dpms(connector, DRM_MODE_DPMS_ON); | |
8261b191 | 10345 | |
7173188d | 10346 | return true; |
79e53945 JB |
10347 | } |
10348 | ||
10349 | /* Find an unused one (if possible) */ | |
70e1e0ec | 10350 | for_each_crtc(dev, possible_crtc) { |
79e53945 JB |
10351 | i++; |
10352 | if (!(encoder->possible_crtcs & (1 << i))) | |
10353 | continue; | |
83d65738 | 10354 | if (possible_crtc->state->enable) |
a459249c VS |
10355 | continue; |
10356 | /* This can occur when applying the pipe A quirk on resume. */ | |
10357 | if (to_intel_crtc(possible_crtc)->new_enabled) | |
10358 | continue; | |
10359 | ||
10360 | crtc = possible_crtc; | |
10361 | break; | |
79e53945 JB |
10362 | } |
10363 | ||
10364 | /* | |
10365 | * If we didn't find an unused CRTC, don't use any. | |
10366 | */ | |
10367 | if (!crtc) { | |
7173188d | 10368 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
51fd371b | 10369 | goto fail_unlock; |
79e53945 JB |
10370 | } |
10371 | ||
51fd371b RC |
10372 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
10373 | if (ret) | |
4d02e2de DV |
10374 | goto fail_unlock; |
10375 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); | |
10376 | if (ret) | |
51fd371b | 10377 | goto fail_unlock; |
fc303101 DV |
10378 | intel_encoder->new_crtc = to_intel_crtc(crtc); |
10379 | to_intel_connector(connector)->new_encoder = intel_encoder; | |
79e53945 JB |
10380 | |
10381 | intel_crtc = to_intel_crtc(crtc); | |
412b61d8 | 10382 | intel_crtc->new_enabled = true; |
24218aac | 10383 | old->dpms_mode = connector->dpms; |
8261b191 | 10384 | old->load_detect_temp = true; |
d2dff872 | 10385 | old->release_fb = NULL; |
79e53945 | 10386 | |
83a57153 ACO |
10387 | state = drm_atomic_state_alloc(dev); |
10388 | if (!state) | |
10389 | return false; | |
10390 | ||
10391 | state->acquire_ctx = ctx; | |
10392 | ||
944b0c76 ACO |
10393 | connector_state = drm_atomic_get_connector_state(state, connector); |
10394 | if (IS_ERR(connector_state)) { | |
10395 | ret = PTR_ERR(connector_state); | |
10396 | goto fail; | |
10397 | } | |
10398 | ||
10399 | connector_state->crtc = crtc; | |
10400 | connector_state->best_encoder = &intel_encoder->base; | |
10401 | ||
4be07317 ACO |
10402 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
10403 | if (IS_ERR(crtc_state)) { | |
10404 | ret = PTR_ERR(crtc_state); | |
10405 | goto fail; | |
10406 | } | |
10407 | ||
49d6fa21 | 10408 | crtc_state->base.active = crtc_state->base.enable = true; |
4be07317 | 10409 | |
6492711d CW |
10410 | if (!mode) |
10411 | mode = &load_detect_mode; | |
79e53945 | 10412 | |
d2dff872 CW |
10413 | /* We need a framebuffer large enough to accommodate all accesses |
10414 | * that the plane may generate whilst we perform load detection. | |
10415 | * We can not rely on the fbcon either being present (we get called | |
10416 | * during its initialisation to detect all boot displays, or it may | |
10417 | * not even exist) or that it is large enough to satisfy the | |
10418 | * requested mode. | |
10419 | */ | |
94352cf9 DV |
10420 | fb = mode_fits_in_fbdev(dev, mode); |
10421 | if (fb == NULL) { | |
d2dff872 | 10422 | DRM_DEBUG_KMS("creating tmp fb for load-detection\n"); |
94352cf9 DV |
10423 | fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32); |
10424 | old->release_fb = fb; | |
d2dff872 CW |
10425 | } else |
10426 | DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); | |
94352cf9 | 10427 | if (IS_ERR(fb)) { |
d2dff872 | 10428 | DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); |
412b61d8 | 10429 | goto fail; |
79e53945 | 10430 | } |
79e53945 | 10431 | |
d3a40d1b ACO |
10432 | ret = intel_modeset_setup_plane_state(state, crtc, mode, fb, 0, 0); |
10433 | if (ret) | |
10434 | goto fail; | |
10435 | ||
8c7b5ccb ACO |
10436 | drm_mode_copy(&crtc_state->base.mode, mode); |
10437 | ||
568c634a | 10438 | if (intel_set_mode(state)) { |
6492711d | 10439 | DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); |
d2dff872 CW |
10440 | if (old->release_fb) |
10441 | old->release_fb->funcs->destroy(old->release_fb); | |
412b61d8 | 10442 | goto fail; |
79e53945 | 10443 | } |
9128b040 | 10444 | crtc->primary->crtc = crtc; |
7173188d | 10445 | |
79e53945 | 10446 | /* let the connector get through one full cycle before testing */ |
9d0498a2 | 10447 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
7173188d | 10448 | return true; |
412b61d8 VS |
10449 | |
10450 | fail: | |
83d65738 | 10451 | intel_crtc->new_enabled = crtc->state->enable; |
51fd371b | 10452 | fail_unlock: |
e5d958ef ACO |
10453 | drm_atomic_state_free(state); |
10454 | state = NULL; | |
83a57153 | 10455 | |
51fd371b RC |
10456 | if (ret == -EDEADLK) { |
10457 | drm_modeset_backoff(ctx); | |
10458 | goto retry; | |
10459 | } | |
10460 | ||
412b61d8 | 10461 | return false; |
79e53945 JB |
10462 | } |
10463 | ||
d2434ab7 | 10464 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
49172fee ACO |
10465 | struct intel_load_detect_pipe *old, |
10466 | struct drm_modeset_acquire_ctx *ctx) | |
79e53945 | 10467 | { |
83a57153 | 10468 | struct drm_device *dev = connector->dev; |
d2434ab7 DV |
10469 | struct intel_encoder *intel_encoder = |
10470 | intel_attached_encoder(connector); | |
4ef69c7a | 10471 | struct drm_encoder *encoder = &intel_encoder->base; |
7b24056b | 10472 | struct drm_crtc *crtc = encoder->crtc; |
412b61d8 | 10473 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
83a57153 | 10474 | struct drm_atomic_state *state; |
944b0c76 | 10475 | struct drm_connector_state *connector_state; |
4be07317 | 10476 | struct intel_crtc_state *crtc_state; |
d3a40d1b | 10477 | int ret; |
79e53945 | 10478 | |
d2dff872 | 10479 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
c23cc417 | 10480 | connector->base.id, connector->name, |
8e329a03 | 10481 | encoder->base.id, encoder->name); |
d2dff872 | 10482 | |
8261b191 | 10483 | if (old->load_detect_temp) { |
83a57153 | 10484 | state = drm_atomic_state_alloc(dev); |
944b0c76 ACO |
10485 | if (!state) |
10486 | goto fail; | |
83a57153 ACO |
10487 | |
10488 | state->acquire_ctx = ctx; | |
10489 | ||
944b0c76 ACO |
10490 | connector_state = drm_atomic_get_connector_state(state, connector); |
10491 | if (IS_ERR(connector_state)) | |
10492 | goto fail; | |
10493 | ||
4be07317 ACO |
10494 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
10495 | if (IS_ERR(crtc_state)) | |
10496 | goto fail; | |
10497 | ||
fc303101 DV |
10498 | to_intel_connector(connector)->new_encoder = NULL; |
10499 | intel_encoder->new_crtc = NULL; | |
412b61d8 | 10500 | intel_crtc->new_enabled = false; |
944b0c76 ACO |
10501 | |
10502 | connector_state->best_encoder = NULL; | |
10503 | connector_state->crtc = NULL; | |
10504 | ||
49d6fa21 | 10505 | crtc_state->base.enable = crtc_state->base.active = false; |
4be07317 | 10506 | |
d3a40d1b ACO |
10507 | ret = intel_modeset_setup_plane_state(state, crtc, NULL, NULL, |
10508 | 0, 0); | |
10509 | if (ret) | |
10510 | goto fail; | |
10511 | ||
568c634a | 10512 | ret = intel_set_mode(state); |
2bfb4627 ACO |
10513 | if (ret) |
10514 | goto fail; | |
d2dff872 | 10515 | |
36206361 DV |
10516 | if (old->release_fb) { |
10517 | drm_framebuffer_unregister_private(old->release_fb); | |
10518 | drm_framebuffer_unreference(old->release_fb); | |
10519 | } | |
d2dff872 | 10520 | |
0622a53c | 10521 | return; |
79e53945 JB |
10522 | } |
10523 | ||
c751ce4f | 10524 | /* Switch crtc and encoder back off if necessary */ |
24218aac DV |
10525 | if (old->dpms_mode != DRM_MODE_DPMS_ON) |
10526 | connector->funcs->dpms(connector, old->dpms_mode); | |
944b0c76 ACO |
10527 | |
10528 | return; | |
10529 | fail: | |
10530 | DRM_DEBUG_KMS("Couldn't release load detect pipe.\n"); | |
10531 | drm_atomic_state_free(state); | |
79e53945 JB |
10532 | } |
10533 | ||
da4a1efa | 10534 | static int i9xx_pll_refclk(struct drm_device *dev, |
5cec258b | 10535 | const struct intel_crtc_state *pipe_config) |
da4a1efa VS |
10536 | { |
10537 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10538 | u32 dpll = pipe_config->dpll_hw_state.dpll; | |
10539 | ||
10540 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) | |
e91e941b | 10541 | return dev_priv->vbt.lvds_ssc_freq; |
da4a1efa VS |
10542 | else if (HAS_PCH_SPLIT(dev)) |
10543 | return 120000; | |
10544 | else if (!IS_GEN2(dev)) | |
10545 | return 96000; | |
10546 | else | |
10547 | return 48000; | |
10548 | } | |
10549 | ||
79e53945 | 10550 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
f1f644dc | 10551 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 10552 | struct intel_crtc_state *pipe_config) |
79e53945 | 10553 | { |
f1f644dc | 10554 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 10555 | struct drm_i915_private *dev_priv = dev->dev_private; |
f1f644dc | 10556 | int pipe = pipe_config->cpu_transcoder; |
293623f7 | 10557 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
79e53945 JB |
10558 | u32 fp; |
10559 | intel_clock_t clock; | |
da4a1efa | 10560 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
79e53945 JB |
10561 | |
10562 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) | |
293623f7 | 10563 | fp = pipe_config->dpll_hw_state.fp0; |
79e53945 | 10564 | else |
293623f7 | 10565 | fp = pipe_config->dpll_hw_state.fp1; |
79e53945 JB |
10566 | |
10567 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; | |
f2b115e6 AJ |
10568 | if (IS_PINEVIEW(dev)) { |
10569 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; | |
10570 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
2177832f SL |
10571 | } else { |
10572 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; | |
10573 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
10574 | } | |
10575 | ||
a6c45cf0 | 10576 | if (!IS_GEN2(dev)) { |
f2b115e6 AJ |
10577 | if (IS_PINEVIEW(dev)) |
10578 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> | |
10579 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); | |
2177832f SL |
10580 | else |
10581 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> | |
79e53945 JB |
10582 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
10583 | ||
10584 | switch (dpll & DPLL_MODE_MASK) { | |
10585 | case DPLLB_MODE_DAC_SERIAL: | |
10586 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? | |
10587 | 5 : 10; | |
10588 | break; | |
10589 | case DPLLB_MODE_LVDS: | |
10590 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? | |
10591 | 7 : 14; | |
10592 | break; | |
10593 | default: | |
28c97730 | 10594 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
79e53945 | 10595 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
f1f644dc | 10596 | return; |
79e53945 JB |
10597 | } |
10598 | ||
ac58c3f0 | 10599 | if (IS_PINEVIEW(dev)) |
da4a1efa | 10600 | pineview_clock(refclk, &clock); |
ac58c3f0 | 10601 | else |
da4a1efa | 10602 | i9xx_clock(refclk, &clock); |
79e53945 | 10603 | } else { |
0fb58223 | 10604 | u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS); |
b1c560d1 | 10605 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
79e53945 JB |
10606 | |
10607 | if (is_lvds) { | |
10608 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> | |
10609 | DPLL_FPA01_P1_POST_DIV_SHIFT); | |
b1c560d1 VS |
10610 | |
10611 | if (lvds & LVDS_CLKB_POWER_UP) | |
10612 | clock.p2 = 7; | |
10613 | else | |
10614 | clock.p2 = 14; | |
79e53945 JB |
10615 | } else { |
10616 | if (dpll & PLL_P1_DIVIDE_BY_TWO) | |
10617 | clock.p1 = 2; | |
10618 | else { | |
10619 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> | |
10620 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; | |
10621 | } | |
10622 | if (dpll & PLL_P2_DIVIDE_BY_4) | |
10623 | clock.p2 = 4; | |
10624 | else | |
10625 | clock.p2 = 2; | |
79e53945 | 10626 | } |
da4a1efa VS |
10627 | |
10628 | i9xx_clock(refclk, &clock); | |
79e53945 JB |
10629 | } |
10630 | ||
18442d08 VS |
10631 | /* |
10632 | * This value includes pixel_multiplier. We will use | |
241bfc38 | 10633 | * port_clock to compute adjusted_mode.crtc_clock in the |
18442d08 VS |
10634 | * encoder's get_config() function. |
10635 | */ | |
10636 | pipe_config->port_clock = clock.dot; | |
f1f644dc JB |
10637 | } |
10638 | ||
6878da05 VS |
10639 | int intel_dotclock_calculate(int link_freq, |
10640 | const struct intel_link_m_n *m_n) | |
f1f644dc | 10641 | { |
f1f644dc JB |
10642 | /* |
10643 | * The calculation for the data clock is: | |
1041a02f | 10644 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
f1f644dc | 10645 | * But we want to avoid losing precison if possible, so: |
1041a02f | 10646 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
f1f644dc JB |
10647 | * |
10648 | * and the link clock is simpler: | |
1041a02f | 10649 | * link_clock = (m * link_clock) / n |
f1f644dc JB |
10650 | */ |
10651 | ||
6878da05 VS |
10652 | if (!m_n->link_n) |
10653 | return 0; | |
f1f644dc | 10654 | |
6878da05 VS |
10655 | return div_u64((u64)m_n->link_m * link_freq, m_n->link_n); |
10656 | } | |
f1f644dc | 10657 | |
18442d08 | 10658 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
5cec258b | 10659 | struct intel_crtc_state *pipe_config) |
6878da05 VS |
10660 | { |
10661 | struct drm_device *dev = crtc->base.dev; | |
79e53945 | 10662 | |
18442d08 VS |
10663 | /* read out port_clock from the DPLL */ |
10664 | i9xx_crtc_clock_get(crtc, pipe_config); | |
f1f644dc | 10665 | |
f1f644dc | 10666 | /* |
18442d08 | 10667 | * This value does not include pixel_multiplier. |
241bfc38 | 10668 | * We will check that port_clock and adjusted_mode.crtc_clock |
18442d08 VS |
10669 | * agree once we know their relationship in the encoder's |
10670 | * get_config() function. | |
79e53945 | 10671 | */ |
2d112de7 | 10672 | pipe_config->base.adjusted_mode.crtc_clock = |
18442d08 VS |
10673 | intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000, |
10674 | &pipe_config->fdi_m_n); | |
79e53945 JB |
10675 | } |
10676 | ||
10677 | /** Returns the currently programmed mode of the given pipe. */ | |
10678 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, | |
10679 | struct drm_crtc *crtc) | |
10680 | { | |
548f245b | 10681 | struct drm_i915_private *dev_priv = dev->dev_private; |
79e53945 | 10682 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
6e3c9717 | 10683 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
79e53945 | 10684 | struct drm_display_mode *mode; |
5cec258b | 10685 | struct intel_crtc_state pipe_config; |
fe2b8f9d PZ |
10686 | int htot = I915_READ(HTOTAL(cpu_transcoder)); |
10687 | int hsync = I915_READ(HSYNC(cpu_transcoder)); | |
10688 | int vtot = I915_READ(VTOTAL(cpu_transcoder)); | |
10689 | int vsync = I915_READ(VSYNC(cpu_transcoder)); | |
293623f7 | 10690 | enum pipe pipe = intel_crtc->pipe; |
79e53945 JB |
10691 | |
10692 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); | |
10693 | if (!mode) | |
10694 | return NULL; | |
10695 | ||
f1f644dc JB |
10696 | /* |
10697 | * Construct a pipe_config sufficient for getting the clock info | |
10698 | * back out of crtc_clock_get. | |
10699 | * | |
10700 | * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need | |
10701 | * to use a real value here instead. | |
10702 | */ | |
293623f7 | 10703 | pipe_config.cpu_transcoder = (enum transcoder) pipe; |
f1f644dc | 10704 | pipe_config.pixel_multiplier = 1; |
293623f7 VS |
10705 | pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe)); |
10706 | pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe)); | |
10707 | pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe)); | |
f1f644dc JB |
10708 | i9xx_crtc_clock_get(intel_crtc, &pipe_config); |
10709 | ||
773ae034 | 10710 | mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier; |
79e53945 JB |
10711 | mode->hdisplay = (htot & 0xffff) + 1; |
10712 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; | |
10713 | mode->hsync_start = (hsync & 0xffff) + 1; | |
10714 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; | |
10715 | mode->vdisplay = (vtot & 0xffff) + 1; | |
10716 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; | |
10717 | mode->vsync_start = (vsync & 0xffff) + 1; | |
10718 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; | |
10719 | ||
10720 | drm_mode_set_name(mode); | |
79e53945 JB |
10721 | |
10722 | return mode; | |
10723 | } | |
10724 | ||
652c393a JB |
10725 | static void intel_decrease_pllclock(struct drm_crtc *crtc) |
10726 | { | |
10727 | struct drm_device *dev = crtc->dev; | |
fbee40df | 10728 | struct drm_i915_private *dev_priv = dev->dev_private; |
652c393a | 10729 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
652c393a | 10730 | |
baff296c | 10731 | if (!HAS_GMCH_DISPLAY(dev)) |
652c393a JB |
10732 | return; |
10733 | ||
10734 | if (!dev_priv->lvds_downclock_avail) | |
10735 | return; | |
10736 | ||
10737 | /* | |
10738 | * Since this is called by a timer, we should never get here in | |
10739 | * the manual case. | |
10740 | */ | |
10741 | if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) { | |
dc257cf1 DV |
10742 | int pipe = intel_crtc->pipe; |
10743 | int dpll_reg = DPLL(pipe); | |
10744 | int dpll; | |
f6e5b160 | 10745 | |
44d98a61 | 10746 | DRM_DEBUG_DRIVER("downclocking LVDS\n"); |
652c393a | 10747 | |
8ac5a6d5 | 10748 | assert_panel_unlocked(dev_priv, pipe); |
652c393a | 10749 | |
dc257cf1 | 10750 | dpll = I915_READ(dpll_reg); |
652c393a JB |
10751 | dpll |= DISPLAY_RATE_SELECT_FPA1; |
10752 | I915_WRITE(dpll_reg, dpll); | |
9d0498a2 | 10753 | intel_wait_for_vblank(dev, pipe); |
652c393a JB |
10754 | dpll = I915_READ(dpll_reg); |
10755 | if (!(dpll & DISPLAY_RATE_SELECT_FPA1)) | |
44d98a61 | 10756 | DRM_DEBUG_DRIVER("failed to downclock LVDS!\n"); |
652c393a JB |
10757 | } |
10758 | ||
10759 | } | |
10760 | ||
f047e395 CW |
10761 | void intel_mark_busy(struct drm_device *dev) |
10762 | { | |
c67a470b PZ |
10763 | struct drm_i915_private *dev_priv = dev->dev_private; |
10764 | ||
f62a0076 CW |
10765 | if (dev_priv->mm.busy) |
10766 | return; | |
10767 | ||
43694d69 | 10768 | intel_runtime_pm_get(dev_priv); |
c67a470b | 10769 | i915_update_gfx_val(dev_priv); |
43cf3bf0 CW |
10770 | if (INTEL_INFO(dev)->gen >= 6) |
10771 | gen6_rps_busy(dev_priv); | |
f62a0076 | 10772 | dev_priv->mm.busy = true; |
f047e395 CW |
10773 | } |
10774 | ||
10775 | void intel_mark_idle(struct drm_device *dev) | |
652c393a | 10776 | { |
c67a470b | 10777 | struct drm_i915_private *dev_priv = dev->dev_private; |
652c393a | 10778 | struct drm_crtc *crtc; |
652c393a | 10779 | |
f62a0076 CW |
10780 | if (!dev_priv->mm.busy) |
10781 | return; | |
10782 | ||
10783 | dev_priv->mm.busy = false; | |
10784 | ||
70e1e0ec | 10785 | for_each_crtc(dev, crtc) { |
f4510a27 | 10786 | if (!crtc->primary->fb) |
652c393a JB |
10787 | continue; |
10788 | ||
725a5b54 | 10789 | intel_decrease_pllclock(crtc); |
652c393a | 10790 | } |
b29c19b6 | 10791 | |
3d13ef2e | 10792 | if (INTEL_INFO(dev)->gen >= 6) |
b29c19b6 | 10793 | gen6_rps_idle(dev->dev_private); |
bb4cdd53 | 10794 | |
43694d69 | 10795 | intel_runtime_pm_put(dev_priv); |
652c393a JB |
10796 | } |
10797 | ||
79e53945 JB |
10798 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
10799 | { | |
10800 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
67e77c5a DV |
10801 | struct drm_device *dev = crtc->dev; |
10802 | struct intel_unpin_work *work; | |
67e77c5a | 10803 | |
5e2d7afc | 10804 | spin_lock_irq(&dev->event_lock); |
67e77c5a DV |
10805 | work = intel_crtc->unpin_work; |
10806 | intel_crtc->unpin_work = NULL; | |
5e2d7afc | 10807 | spin_unlock_irq(&dev->event_lock); |
67e77c5a DV |
10808 | |
10809 | if (work) { | |
10810 | cancel_work_sync(&work->work); | |
10811 | kfree(work); | |
10812 | } | |
79e53945 JB |
10813 | |
10814 | drm_crtc_cleanup(crtc); | |
67e77c5a | 10815 | |
79e53945 JB |
10816 | kfree(intel_crtc); |
10817 | } | |
10818 | ||
6b95a207 KH |
10819 | static void intel_unpin_work_fn(struct work_struct *__work) |
10820 | { | |
10821 | struct intel_unpin_work *work = | |
10822 | container_of(__work, struct intel_unpin_work, work); | |
b4a98e57 | 10823 | struct drm_device *dev = work->crtc->dev; |
f99d7069 | 10824 | enum pipe pipe = to_intel_crtc(work->crtc)->pipe; |
6b95a207 | 10825 | |
b4a98e57 | 10826 | mutex_lock(&dev->struct_mutex); |
82bc3b2d | 10827 | intel_unpin_fb_obj(work->old_fb, work->crtc->primary->state); |
05394f39 | 10828 | drm_gem_object_unreference(&work->pending_flip_obj->base); |
d9e86c0e | 10829 | |
7ff0ebcc | 10830 | intel_fbc_update(dev); |
f06cc1b9 JH |
10831 | |
10832 | if (work->flip_queued_req) | |
146d84f0 | 10833 | i915_gem_request_assign(&work->flip_queued_req, NULL); |
b4a98e57 CW |
10834 | mutex_unlock(&dev->struct_mutex); |
10835 | ||
f99d7069 | 10836 | intel_frontbuffer_flip_complete(dev, INTEL_FRONTBUFFER_PRIMARY(pipe)); |
89ed88ba | 10837 | drm_framebuffer_unreference(work->old_fb); |
f99d7069 | 10838 | |
b4a98e57 CW |
10839 | BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0); |
10840 | atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count); | |
10841 | ||
6b95a207 KH |
10842 | kfree(work); |
10843 | } | |
10844 | ||
1afe3e9d | 10845 | static void do_intel_finish_page_flip(struct drm_device *dev, |
49b14a5c | 10846 | struct drm_crtc *crtc) |
6b95a207 | 10847 | { |
6b95a207 KH |
10848 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
10849 | struct intel_unpin_work *work; | |
6b95a207 KH |
10850 | unsigned long flags; |
10851 | ||
10852 | /* Ignore early vblank irqs */ | |
10853 | if (intel_crtc == NULL) | |
10854 | return; | |
10855 | ||
f326038a DV |
10856 | /* |
10857 | * This is called both by irq handlers and the reset code (to complete | |
10858 | * lost pageflips) so needs the full irqsave spinlocks. | |
10859 | */ | |
6b95a207 KH |
10860 | spin_lock_irqsave(&dev->event_lock, flags); |
10861 | work = intel_crtc->unpin_work; | |
e7d841ca CW |
10862 | |
10863 | /* Ensure we don't miss a work->pending update ... */ | |
10864 | smp_rmb(); | |
10865 | ||
10866 | if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) { | |
6b95a207 KH |
10867 | spin_unlock_irqrestore(&dev->event_lock, flags); |
10868 | return; | |
10869 | } | |
10870 | ||
d6bbafa1 | 10871 | page_flip_completed(intel_crtc); |
0af7e4df | 10872 | |
6b95a207 | 10873 | spin_unlock_irqrestore(&dev->event_lock, flags); |
6b95a207 KH |
10874 | } |
10875 | ||
1afe3e9d JB |
10876 | void intel_finish_page_flip(struct drm_device *dev, int pipe) |
10877 | { | |
fbee40df | 10878 | struct drm_i915_private *dev_priv = dev->dev_private; |
1afe3e9d JB |
10879 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
10880 | ||
49b14a5c | 10881 | do_intel_finish_page_flip(dev, crtc); |
1afe3e9d JB |
10882 | } |
10883 | ||
10884 | void intel_finish_page_flip_plane(struct drm_device *dev, int plane) | |
10885 | { | |
fbee40df | 10886 | struct drm_i915_private *dev_priv = dev->dev_private; |
1afe3e9d JB |
10887 | struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane]; |
10888 | ||
49b14a5c | 10889 | do_intel_finish_page_flip(dev, crtc); |
1afe3e9d JB |
10890 | } |
10891 | ||
75f7f3ec VS |
10892 | /* Is 'a' after or equal to 'b'? */ |
10893 | static bool g4x_flip_count_after_eq(u32 a, u32 b) | |
10894 | { | |
10895 | return !((a - b) & 0x80000000); | |
10896 | } | |
10897 | ||
10898 | static bool page_flip_finished(struct intel_crtc *crtc) | |
10899 | { | |
10900 | struct drm_device *dev = crtc->base.dev; | |
10901 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10902 | ||
bdfa7542 VS |
10903 | if (i915_reset_in_progress(&dev_priv->gpu_error) || |
10904 | crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) | |
10905 | return true; | |
10906 | ||
75f7f3ec VS |
10907 | /* |
10908 | * The relevant registers doen't exist on pre-ctg. | |
10909 | * As the flip done interrupt doesn't trigger for mmio | |
10910 | * flips on gmch platforms, a flip count check isn't | |
10911 | * really needed there. But since ctg has the registers, | |
10912 | * include it in the check anyway. | |
10913 | */ | |
10914 | if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev)) | |
10915 | return true; | |
10916 | ||
10917 | /* | |
10918 | * A DSPSURFLIVE check isn't enough in case the mmio and CS flips | |
10919 | * used the same base address. In that case the mmio flip might | |
10920 | * have completed, but the CS hasn't even executed the flip yet. | |
10921 | * | |
10922 | * A flip count check isn't enough as the CS might have updated | |
10923 | * the base address just after start of vblank, but before we | |
10924 | * managed to process the interrupt. This means we'd complete the | |
10925 | * CS flip too soon. | |
10926 | * | |
10927 | * Combining both checks should get us a good enough result. It may | |
10928 | * still happen that the CS flip has been executed, but has not | |
10929 | * yet actually completed. But in case the base address is the same | |
10930 | * anyway, we don't really care. | |
10931 | */ | |
10932 | return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) == | |
10933 | crtc->unpin_work->gtt_offset && | |
10934 | g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc->pipe)), | |
10935 | crtc->unpin_work->flip_count); | |
10936 | } | |
10937 | ||
6b95a207 KH |
10938 | void intel_prepare_page_flip(struct drm_device *dev, int plane) |
10939 | { | |
fbee40df | 10940 | struct drm_i915_private *dev_priv = dev->dev_private; |
6b95a207 KH |
10941 | struct intel_crtc *intel_crtc = |
10942 | to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]); | |
10943 | unsigned long flags; | |
10944 | ||
f326038a DV |
10945 | |
10946 | /* | |
10947 | * This is called both by irq handlers and the reset code (to complete | |
10948 | * lost pageflips) so needs the full irqsave spinlocks. | |
10949 | * | |
10950 | * NB: An MMIO update of the plane base pointer will also | |
e7d841ca CW |
10951 | * generate a page-flip completion irq, i.e. every modeset |
10952 | * is also accompanied by a spurious intel_prepare_page_flip(). | |
10953 | */ | |
6b95a207 | 10954 | spin_lock_irqsave(&dev->event_lock, flags); |
75f7f3ec | 10955 | if (intel_crtc->unpin_work && page_flip_finished(intel_crtc)) |
e7d841ca | 10956 | atomic_inc_not_zero(&intel_crtc->unpin_work->pending); |
6b95a207 KH |
10957 | spin_unlock_irqrestore(&dev->event_lock, flags); |
10958 | } | |
10959 | ||
eba905b2 | 10960 | static inline void intel_mark_page_flip_active(struct intel_crtc *intel_crtc) |
e7d841ca CW |
10961 | { |
10962 | /* Ensure that the work item is consistent when activating it ... */ | |
10963 | smp_wmb(); | |
10964 | atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING); | |
10965 | /* and that it is marked active as soon as the irq could fire. */ | |
10966 | smp_wmb(); | |
10967 | } | |
10968 | ||
8c9f3aaf JB |
10969 | static int intel_gen2_queue_flip(struct drm_device *dev, |
10970 | struct drm_crtc *crtc, | |
10971 | struct drm_framebuffer *fb, | |
ed8d1975 | 10972 | struct drm_i915_gem_object *obj, |
a4872ba6 | 10973 | struct intel_engine_cs *ring, |
ed8d1975 | 10974 | uint32_t flags) |
8c9f3aaf | 10975 | { |
8c9f3aaf | 10976 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8c9f3aaf JB |
10977 | u32 flip_mask; |
10978 | int ret; | |
10979 | ||
6d90c952 | 10980 | ret = intel_ring_begin(ring, 6); |
8c9f3aaf | 10981 | if (ret) |
4fa62c89 | 10982 | return ret; |
8c9f3aaf JB |
10983 | |
10984 | /* Can't queue multiple flips, so wait for the previous | |
10985 | * one to finish before executing the next. | |
10986 | */ | |
10987 | if (intel_crtc->plane) | |
10988 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; | |
10989 | else | |
10990 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; | |
6d90c952 DV |
10991 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
10992 | intel_ring_emit(ring, MI_NOOP); | |
10993 | intel_ring_emit(ring, MI_DISPLAY_FLIP | | |
10994 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
10995 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 10996 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
6d90c952 | 10997 | intel_ring_emit(ring, 0); /* aux display base address, unused */ |
e7d841ca CW |
10998 | |
10999 | intel_mark_page_flip_active(intel_crtc); | |
09246732 | 11000 | __intel_ring_advance(ring); |
83d4092b | 11001 | return 0; |
8c9f3aaf JB |
11002 | } |
11003 | ||
11004 | static int intel_gen3_queue_flip(struct drm_device *dev, | |
11005 | struct drm_crtc *crtc, | |
11006 | struct drm_framebuffer *fb, | |
ed8d1975 | 11007 | struct drm_i915_gem_object *obj, |
a4872ba6 | 11008 | struct intel_engine_cs *ring, |
ed8d1975 | 11009 | uint32_t flags) |
8c9f3aaf | 11010 | { |
8c9f3aaf | 11011 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8c9f3aaf JB |
11012 | u32 flip_mask; |
11013 | int ret; | |
11014 | ||
6d90c952 | 11015 | ret = intel_ring_begin(ring, 6); |
8c9f3aaf | 11016 | if (ret) |
4fa62c89 | 11017 | return ret; |
8c9f3aaf JB |
11018 | |
11019 | if (intel_crtc->plane) | |
11020 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; | |
11021 | else | |
11022 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; | |
6d90c952 DV |
11023 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
11024 | intel_ring_emit(ring, MI_NOOP); | |
11025 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | | |
11026 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
11027 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 11028 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
6d90c952 DV |
11029 | intel_ring_emit(ring, MI_NOOP); |
11030 | ||
e7d841ca | 11031 | intel_mark_page_flip_active(intel_crtc); |
09246732 | 11032 | __intel_ring_advance(ring); |
83d4092b | 11033 | return 0; |
8c9f3aaf JB |
11034 | } |
11035 | ||
11036 | static int intel_gen4_queue_flip(struct drm_device *dev, | |
11037 | struct drm_crtc *crtc, | |
11038 | struct drm_framebuffer *fb, | |
ed8d1975 | 11039 | struct drm_i915_gem_object *obj, |
a4872ba6 | 11040 | struct intel_engine_cs *ring, |
ed8d1975 | 11041 | uint32_t flags) |
8c9f3aaf JB |
11042 | { |
11043 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11044 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11045 | uint32_t pf, pipesrc; | |
11046 | int ret; | |
11047 | ||
6d90c952 | 11048 | ret = intel_ring_begin(ring, 4); |
8c9f3aaf | 11049 | if (ret) |
4fa62c89 | 11050 | return ret; |
8c9f3aaf JB |
11051 | |
11052 | /* i965+ uses the linear or tiled offsets from the | |
11053 | * Display Registers (which do not change across a page-flip) | |
11054 | * so we need only reprogram the base address. | |
11055 | */ | |
6d90c952 DV |
11056 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
11057 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
11058 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 11059 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset | |
c2c75131 | 11060 | obj->tiling_mode); |
8c9f3aaf JB |
11061 | |
11062 | /* XXX Enabling the panel-fitter across page-flip is so far | |
11063 | * untested on non-native modes, so ignore it for now. | |
11064 | * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE; | |
11065 | */ | |
11066 | pf = 0; | |
11067 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; | |
6d90c952 | 11068 | intel_ring_emit(ring, pf | pipesrc); |
e7d841ca CW |
11069 | |
11070 | intel_mark_page_flip_active(intel_crtc); | |
09246732 | 11071 | __intel_ring_advance(ring); |
83d4092b | 11072 | return 0; |
8c9f3aaf JB |
11073 | } |
11074 | ||
11075 | static int intel_gen6_queue_flip(struct drm_device *dev, | |
11076 | struct drm_crtc *crtc, | |
11077 | struct drm_framebuffer *fb, | |
ed8d1975 | 11078 | struct drm_i915_gem_object *obj, |
a4872ba6 | 11079 | struct intel_engine_cs *ring, |
ed8d1975 | 11080 | uint32_t flags) |
8c9f3aaf JB |
11081 | { |
11082 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11083 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11084 | uint32_t pf, pipesrc; | |
11085 | int ret; | |
11086 | ||
6d90c952 | 11087 | ret = intel_ring_begin(ring, 4); |
8c9f3aaf | 11088 | if (ret) |
4fa62c89 | 11089 | return ret; |
8c9f3aaf | 11090 | |
6d90c952 DV |
11091 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
11092 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
11093 | intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode); | |
75f7f3ec | 11094 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
8c9f3aaf | 11095 | |
dc257cf1 DV |
11096 | /* Contrary to the suggestions in the documentation, |
11097 | * "Enable Panel Fitter" does not seem to be required when page | |
11098 | * flipping with a non-native mode, and worse causes a normal | |
11099 | * modeset to fail. | |
11100 | * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE; | |
11101 | */ | |
11102 | pf = 0; | |
8c9f3aaf | 11103 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
6d90c952 | 11104 | intel_ring_emit(ring, pf | pipesrc); |
e7d841ca CW |
11105 | |
11106 | intel_mark_page_flip_active(intel_crtc); | |
09246732 | 11107 | __intel_ring_advance(ring); |
83d4092b | 11108 | return 0; |
8c9f3aaf JB |
11109 | } |
11110 | ||
7c9017e5 JB |
11111 | static int intel_gen7_queue_flip(struct drm_device *dev, |
11112 | struct drm_crtc *crtc, | |
11113 | struct drm_framebuffer *fb, | |
ed8d1975 | 11114 | struct drm_i915_gem_object *obj, |
a4872ba6 | 11115 | struct intel_engine_cs *ring, |
ed8d1975 | 11116 | uint32_t flags) |
7c9017e5 | 11117 | { |
7c9017e5 | 11118 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
cb05d8de | 11119 | uint32_t plane_bit = 0; |
ffe74d75 CW |
11120 | int len, ret; |
11121 | ||
eba905b2 | 11122 | switch (intel_crtc->plane) { |
cb05d8de DV |
11123 | case PLANE_A: |
11124 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A; | |
11125 | break; | |
11126 | case PLANE_B: | |
11127 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B; | |
11128 | break; | |
11129 | case PLANE_C: | |
11130 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C; | |
11131 | break; | |
11132 | default: | |
11133 | WARN_ONCE(1, "unknown plane in flip command\n"); | |
4fa62c89 | 11134 | return -ENODEV; |
cb05d8de DV |
11135 | } |
11136 | ||
ffe74d75 | 11137 | len = 4; |
f476828a | 11138 | if (ring->id == RCS) { |
ffe74d75 | 11139 | len += 6; |
f476828a DL |
11140 | /* |
11141 | * On Gen 8, SRM is now taking an extra dword to accommodate | |
11142 | * 48bits addresses, and we need a NOOP for the batch size to | |
11143 | * stay even. | |
11144 | */ | |
11145 | if (IS_GEN8(dev)) | |
11146 | len += 2; | |
11147 | } | |
ffe74d75 | 11148 | |
f66fab8e VS |
11149 | /* |
11150 | * BSpec MI_DISPLAY_FLIP for IVB: | |
11151 | * "The full packet must be contained within the same cache line." | |
11152 | * | |
11153 | * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same | |
11154 | * cacheline, if we ever start emitting more commands before | |
11155 | * the MI_DISPLAY_FLIP we may need to first emit everything else, | |
11156 | * then do the cacheline alignment, and finally emit the | |
11157 | * MI_DISPLAY_FLIP. | |
11158 | */ | |
11159 | ret = intel_ring_cacheline_align(ring); | |
11160 | if (ret) | |
4fa62c89 | 11161 | return ret; |
f66fab8e | 11162 | |
ffe74d75 | 11163 | ret = intel_ring_begin(ring, len); |
7c9017e5 | 11164 | if (ret) |
4fa62c89 | 11165 | return ret; |
7c9017e5 | 11166 | |
ffe74d75 CW |
11167 | /* Unmask the flip-done completion message. Note that the bspec says that |
11168 | * we should do this for both the BCS and RCS, and that we must not unmask | |
11169 | * more than one flip event at any time (or ensure that one flip message | |
11170 | * can be sent by waiting for flip-done prior to queueing new flips). | |
11171 | * Experimentation says that BCS works despite DERRMR masking all | |
11172 | * flip-done completion events and that unmasking all planes at once | |
11173 | * for the RCS also doesn't appear to drop events. Setting the DERRMR | |
11174 | * to zero does lead to lockups within MI_DISPLAY_FLIP. | |
11175 | */ | |
11176 | if (ring->id == RCS) { | |
11177 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); | |
11178 | intel_ring_emit(ring, DERRMR); | |
11179 | intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE | | |
11180 | DERRMR_PIPEB_PRI_FLIP_DONE | | |
11181 | DERRMR_PIPEC_PRI_FLIP_DONE)); | |
f476828a DL |
11182 | if (IS_GEN8(dev)) |
11183 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8(1) | | |
11184 | MI_SRM_LRM_GLOBAL_GTT); | |
11185 | else | |
11186 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM(1) | | |
11187 | MI_SRM_LRM_GLOBAL_GTT); | |
ffe74d75 CW |
11188 | intel_ring_emit(ring, DERRMR); |
11189 | intel_ring_emit(ring, ring->scratch.gtt_offset + 256); | |
f476828a DL |
11190 | if (IS_GEN8(dev)) { |
11191 | intel_ring_emit(ring, 0); | |
11192 | intel_ring_emit(ring, MI_NOOP); | |
11193 | } | |
ffe74d75 CW |
11194 | } |
11195 | ||
cb05d8de | 11196 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit); |
01f2c773 | 11197 | intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode)); |
75f7f3ec | 11198 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
7c9017e5 | 11199 | intel_ring_emit(ring, (MI_NOOP)); |
e7d841ca CW |
11200 | |
11201 | intel_mark_page_flip_active(intel_crtc); | |
09246732 | 11202 | __intel_ring_advance(ring); |
83d4092b | 11203 | return 0; |
7c9017e5 JB |
11204 | } |
11205 | ||
84c33a64 SG |
11206 | static bool use_mmio_flip(struct intel_engine_cs *ring, |
11207 | struct drm_i915_gem_object *obj) | |
11208 | { | |
11209 | /* | |
11210 | * This is not being used for older platforms, because | |
11211 | * non-availability of flip done interrupt forces us to use | |
11212 | * CS flips. Older platforms derive flip done using some clever | |
11213 | * tricks involving the flip_pending status bits and vblank irqs. | |
11214 | * So using MMIO flips there would disrupt this mechanism. | |
11215 | */ | |
11216 | ||
8e09bf83 CW |
11217 | if (ring == NULL) |
11218 | return true; | |
11219 | ||
84c33a64 SG |
11220 | if (INTEL_INFO(ring->dev)->gen < 5) |
11221 | return false; | |
11222 | ||
11223 | if (i915.use_mmio_flip < 0) | |
11224 | return false; | |
11225 | else if (i915.use_mmio_flip > 0) | |
11226 | return true; | |
14bf993e OM |
11227 | else if (i915.enable_execlists) |
11228 | return true; | |
84c33a64 | 11229 | else |
b4716185 | 11230 | return ring != i915_gem_request_get_ring(obj->last_write_req); |
84c33a64 SG |
11231 | } |
11232 | ||
ff944564 DL |
11233 | static void skl_do_mmio_flip(struct intel_crtc *intel_crtc) |
11234 | { | |
11235 | struct drm_device *dev = intel_crtc->base.dev; | |
11236 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11237 | struct drm_framebuffer *fb = intel_crtc->base.primary->fb; | |
ff944564 DL |
11238 | const enum pipe pipe = intel_crtc->pipe; |
11239 | u32 ctl, stride; | |
11240 | ||
11241 | ctl = I915_READ(PLANE_CTL(pipe, 0)); | |
11242 | ctl &= ~PLANE_CTL_TILED_MASK; | |
2ebef630 TU |
11243 | switch (fb->modifier[0]) { |
11244 | case DRM_FORMAT_MOD_NONE: | |
11245 | break; | |
11246 | case I915_FORMAT_MOD_X_TILED: | |
ff944564 | 11247 | ctl |= PLANE_CTL_TILED_X; |
2ebef630 TU |
11248 | break; |
11249 | case I915_FORMAT_MOD_Y_TILED: | |
11250 | ctl |= PLANE_CTL_TILED_Y; | |
11251 | break; | |
11252 | case I915_FORMAT_MOD_Yf_TILED: | |
11253 | ctl |= PLANE_CTL_TILED_YF; | |
11254 | break; | |
11255 | default: | |
11256 | MISSING_CASE(fb->modifier[0]); | |
11257 | } | |
ff944564 DL |
11258 | |
11259 | /* | |
11260 | * The stride is either expressed as a multiple of 64 bytes chunks for | |
11261 | * linear buffers or in number of tiles for tiled buffers. | |
11262 | */ | |
2ebef630 TU |
11263 | stride = fb->pitches[0] / |
11264 | intel_fb_stride_alignment(dev, fb->modifier[0], | |
11265 | fb->pixel_format); | |
ff944564 DL |
11266 | |
11267 | /* | |
11268 | * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on | |
11269 | * PLANE_SURF updates, the update is then guaranteed to be atomic. | |
11270 | */ | |
11271 | I915_WRITE(PLANE_CTL(pipe, 0), ctl); | |
11272 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); | |
11273 | ||
11274 | I915_WRITE(PLANE_SURF(pipe, 0), intel_crtc->unpin_work->gtt_offset); | |
11275 | POSTING_READ(PLANE_SURF(pipe, 0)); | |
11276 | } | |
11277 | ||
11278 | static void ilk_do_mmio_flip(struct intel_crtc *intel_crtc) | |
84c33a64 SG |
11279 | { |
11280 | struct drm_device *dev = intel_crtc->base.dev; | |
11281 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11282 | struct intel_framebuffer *intel_fb = | |
11283 | to_intel_framebuffer(intel_crtc->base.primary->fb); | |
11284 | struct drm_i915_gem_object *obj = intel_fb->obj; | |
11285 | u32 dspcntr; | |
11286 | u32 reg; | |
11287 | ||
84c33a64 SG |
11288 | reg = DSPCNTR(intel_crtc->plane); |
11289 | dspcntr = I915_READ(reg); | |
11290 | ||
c5d97472 DL |
11291 | if (obj->tiling_mode != I915_TILING_NONE) |
11292 | dspcntr |= DISPPLANE_TILED; | |
11293 | else | |
11294 | dspcntr &= ~DISPPLANE_TILED; | |
11295 | ||
84c33a64 SG |
11296 | I915_WRITE(reg, dspcntr); |
11297 | ||
11298 | I915_WRITE(DSPSURF(intel_crtc->plane), | |
11299 | intel_crtc->unpin_work->gtt_offset); | |
11300 | POSTING_READ(DSPSURF(intel_crtc->plane)); | |
84c33a64 | 11301 | |
ff944564 DL |
11302 | } |
11303 | ||
11304 | /* | |
11305 | * XXX: This is the temporary way to update the plane registers until we get | |
11306 | * around to using the usual plane update functions for MMIO flips | |
11307 | */ | |
11308 | static void intel_do_mmio_flip(struct intel_crtc *intel_crtc) | |
11309 | { | |
11310 | struct drm_device *dev = intel_crtc->base.dev; | |
11311 | bool atomic_update; | |
11312 | u32 start_vbl_count; | |
11313 | ||
11314 | intel_mark_page_flip_active(intel_crtc); | |
11315 | ||
11316 | atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count); | |
11317 | ||
11318 | if (INTEL_INFO(dev)->gen >= 9) | |
11319 | skl_do_mmio_flip(intel_crtc); | |
11320 | else | |
11321 | /* use_mmio_flip() retricts MMIO flips to ilk+ */ | |
11322 | ilk_do_mmio_flip(intel_crtc); | |
11323 | ||
9362c7c5 ACO |
11324 | if (atomic_update) |
11325 | intel_pipe_update_end(intel_crtc, start_vbl_count); | |
84c33a64 SG |
11326 | } |
11327 | ||
9362c7c5 | 11328 | static void intel_mmio_flip_work_func(struct work_struct *work) |
84c33a64 | 11329 | { |
b2cfe0ab CW |
11330 | struct intel_mmio_flip *mmio_flip = |
11331 | container_of(work, struct intel_mmio_flip, work); | |
84c33a64 | 11332 | |
eed29a5b DV |
11333 | if (mmio_flip->req) |
11334 | WARN_ON(__i915_wait_request(mmio_flip->req, | |
b2cfe0ab | 11335 | mmio_flip->crtc->reset_counter, |
bcafc4e3 CW |
11336 | false, NULL, |
11337 | &mmio_flip->i915->rps.mmioflips)); | |
84c33a64 | 11338 | |
b2cfe0ab CW |
11339 | intel_do_mmio_flip(mmio_flip->crtc); |
11340 | ||
eed29a5b | 11341 | i915_gem_request_unreference__unlocked(mmio_flip->req); |
b2cfe0ab | 11342 | kfree(mmio_flip); |
84c33a64 SG |
11343 | } |
11344 | ||
11345 | static int intel_queue_mmio_flip(struct drm_device *dev, | |
11346 | struct drm_crtc *crtc, | |
11347 | struct drm_framebuffer *fb, | |
11348 | struct drm_i915_gem_object *obj, | |
11349 | struct intel_engine_cs *ring, | |
11350 | uint32_t flags) | |
11351 | { | |
b2cfe0ab CW |
11352 | struct intel_mmio_flip *mmio_flip; |
11353 | ||
11354 | mmio_flip = kmalloc(sizeof(*mmio_flip), GFP_KERNEL); | |
11355 | if (mmio_flip == NULL) | |
11356 | return -ENOMEM; | |
84c33a64 | 11357 | |
bcafc4e3 | 11358 | mmio_flip->i915 = to_i915(dev); |
eed29a5b | 11359 | mmio_flip->req = i915_gem_request_reference(obj->last_write_req); |
b2cfe0ab | 11360 | mmio_flip->crtc = to_intel_crtc(crtc); |
536f5b5e | 11361 | |
b2cfe0ab CW |
11362 | INIT_WORK(&mmio_flip->work, intel_mmio_flip_work_func); |
11363 | schedule_work(&mmio_flip->work); | |
84c33a64 | 11364 | |
84c33a64 SG |
11365 | return 0; |
11366 | } | |
11367 | ||
8c9f3aaf JB |
11368 | static int intel_default_queue_flip(struct drm_device *dev, |
11369 | struct drm_crtc *crtc, | |
11370 | struct drm_framebuffer *fb, | |
ed8d1975 | 11371 | struct drm_i915_gem_object *obj, |
a4872ba6 | 11372 | struct intel_engine_cs *ring, |
ed8d1975 | 11373 | uint32_t flags) |
8c9f3aaf JB |
11374 | { |
11375 | return -ENODEV; | |
11376 | } | |
11377 | ||
d6bbafa1 CW |
11378 | static bool __intel_pageflip_stall_check(struct drm_device *dev, |
11379 | struct drm_crtc *crtc) | |
11380 | { | |
11381 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11382 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11383 | struct intel_unpin_work *work = intel_crtc->unpin_work; | |
11384 | u32 addr; | |
11385 | ||
11386 | if (atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE) | |
11387 | return true; | |
11388 | ||
11389 | if (!work->enable_stall_check) | |
11390 | return false; | |
11391 | ||
11392 | if (work->flip_ready_vblank == 0) { | |
3a8a946e DV |
11393 | if (work->flip_queued_req && |
11394 | !i915_gem_request_completed(work->flip_queued_req, true)) | |
d6bbafa1 CW |
11395 | return false; |
11396 | ||
1e3feefd | 11397 | work->flip_ready_vblank = drm_crtc_vblank_count(crtc); |
d6bbafa1 CW |
11398 | } |
11399 | ||
1e3feefd | 11400 | if (drm_crtc_vblank_count(crtc) - work->flip_ready_vblank < 3) |
d6bbafa1 CW |
11401 | return false; |
11402 | ||
11403 | /* Potential stall - if we see that the flip has happened, | |
11404 | * assume a missed interrupt. */ | |
11405 | if (INTEL_INFO(dev)->gen >= 4) | |
11406 | addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane))); | |
11407 | else | |
11408 | addr = I915_READ(DSPADDR(intel_crtc->plane)); | |
11409 | ||
11410 | /* There is a potential issue here with a false positive after a flip | |
11411 | * to the same address. We could address this by checking for a | |
11412 | * non-incrementing frame counter. | |
11413 | */ | |
11414 | return addr == work->gtt_offset; | |
11415 | } | |
11416 | ||
11417 | void intel_check_page_flip(struct drm_device *dev, int pipe) | |
11418 | { | |
11419 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11420 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
11421 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6ad790c0 | 11422 | struct intel_unpin_work *work; |
f326038a | 11423 | |
6c51d46f | 11424 | WARN_ON(!in_interrupt()); |
d6bbafa1 CW |
11425 | |
11426 | if (crtc == NULL) | |
11427 | return; | |
11428 | ||
f326038a | 11429 | spin_lock(&dev->event_lock); |
6ad790c0 CW |
11430 | work = intel_crtc->unpin_work; |
11431 | if (work != NULL && __intel_pageflip_stall_check(dev, crtc)) { | |
d6bbafa1 | 11432 | WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n", |
6ad790c0 | 11433 | work->flip_queued_vblank, drm_vblank_count(dev, pipe)); |
d6bbafa1 | 11434 | page_flip_completed(intel_crtc); |
6ad790c0 | 11435 | work = NULL; |
d6bbafa1 | 11436 | } |
6ad790c0 CW |
11437 | if (work != NULL && |
11438 | drm_vblank_count(dev, pipe) - work->flip_queued_vblank > 1) | |
11439 | intel_queue_rps_boost_for_request(dev, work->flip_queued_req); | |
f326038a | 11440 | spin_unlock(&dev->event_lock); |
d6bbafa1 CW |
11441 | } |
11442 | ||
6b95a207 KH |
11443 | static int intel_crtc_page_flip(struct drm_crtc *crtc, |
11444 | struct drm_framebuffer *fb, | |
ed8d1975 KP |
11445 | struct drm_pending_vblank_event *event, |
11446 | uint32_t page_flip_flags) | |
6b95a207 KH |
11447 | { |
11448 | struct drm_device *dev = crtc->dev; | |
11449 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f4510a27 | 11450 | struct drm_framebuffer *old_fb = crtc->primary->fb; |
2ff8fde1 | 11451 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
6b95a207 | 11452 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
455a6808 | 11453 | struct drm_plane *primary = crtc->primary; |
a071fa00 | 11454 | enum pipe pipe = intel_crtc->pipe; |
6b95a207 | 11455 | struct intel_unpin_work *work; |
a4872ba6 | 11456 | struct intel_engine_cs *ring; |
cf5d8a46 | 11457 | bool mmio_flip; |
52e68630 | 11458 | int ret; |
6b95a207 | 11459 | |
2ff8fde1 MR |
11460 | /* |
11461 | * drm_mode_page_flip_ioctl() should already catch this, but double | |
11462 | * check to be safe. In the future we may enable pageflipping from | |
11463 | * a disabled primary plane. | |
11464 | */ | |
11465 | if (WARN_ON(intel_fb_obj(old_fb) == NULL)) | |
11466 | return -EBUSY; | |
11467 | ||
e6a595d2 | 11468 | /* Can't change pixel format via MI display flips. */ |
f4510a27 | 11469 | if (fb->pixel_format != crtc->primary->fb->pixel_format) |
e6a595d2 VS |
11470 | return -EINVAL; |
11471 | ||
11472 | /* | |
11473 | * TILEOFF/LINOFF registers can't be changed via MI display flips. | |
11474 | * Note that pitch changes could also affect these register. | |
11475 | */ | |
11476 | if (INTEL_INFO(dev)->gen > 3 && | |
f4510a27 MR |
11477 | (fb->offsets[0] != crtc->primary->fb->offsets[0] || |
11478 | fb->pitches[0] != crtc->primary->fb->pitches[0])) | |
e6a595d2 VS |
11479 | return -EINVAL; |
11480 | ||
f900db47 CW |
11481 | if (i915_terminally_wedged(&dev_priv->gpu_error)) |
11482 | goto out_hang; | |
11483 | ||
b14c5679 | 11484 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
6b95a207 KH |
11485 | if (work == NULL) |
11486 | return -ENOMEM; | |
11487 | ||
6b95a207 | 11488 | work->event = event; |
b4a98e57 | 11489 | work->crtc = crtc; |
ab8d6675 | 11490 | work->old_fb = old_fb; |
6b95a207 KH |
11491 | INIT_WORK(&work->work, intel_unpin_work_fn); |
11492 | ||
87b6b101 | 11493 | ret = drm_crtc_vblank_get(crtc); |
7317c75e JB |
11494 | if (ret) |
11495 | goto free_work; | |
11496 | ||
6b95a207 | 11497 | /* We borrow the event spin lock for protecting unpin_work */ |
5e2d7afc | 11498 | spin_lock_irq(&dev->event_lock); |
6b95a207 | 11499 | if (intel_crtc->unpin_work) { |
d6bbafa1 CW |
11500 | /* Before declaring the flip queue wedged, check if |
11501 | * the hardware completed the operation behind our backs. | |
11502 | */ | |
11503 | if (__intel_pageflip_stall_check(dev, crtc)) { | |
11504 | DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n"); | |
11505 | page_flip_completed(intel_crtc); | |
11506 | } else { | |
11507 | DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); | |
5e2d7afc | 11508 | spin_unlock_irq(&dev->event_lock); |
468f0b44 | 11509 | |
d6bbafa1 CW |
11510 | drm_crtc_vblank_put(crtc); |
11511 | kfree(work); | |
11512 | return -EBUSY; | |
11513 | } | |
6b95a207 KH |
11514 | } |
11515 | intel_crtc->unpin_work = work; | |
5e2d7afc | 11516 | spin_unlock_irq(&dev->event_lock); |
6b95a207 | 11517 | |
b4a98e57 CW |
11518 | if (atomic_read(&intel_crtc->unpin_work_count) >= 2) |
11519 | flush_workqueue(dev_priv->wq); | |
11520 | ||
75dfca80 | 11521 | /* Reference the objects for the scheduled work. */ |
ab8d6675 | 11522 | drm_framebuffer_reference(work->old_fb); |
05394f39 | 11523 | drm_gem_object_reference(&obj->base); |
6b95a207 | 11524 | |
f4510a27 | 11525 | crtc->primary->fb = fb; |
afd65eb4 | 11526 | update_state_fb(crtc->primary); |
1ed1f968 | 11527 | |
e1f99ce6 | 11528 | work->pending_flip_obj = obj; |
e1f99ce6 | 11529 | |
89ed88ba CW |
11530 | ret = i915_mutex_lock_interruptible(dev); |
11531 | if (ret) | |
11532 | goto cleanup; | |
11533 | ||
b4a98e57 | 11534 | atomic_inc(&intel_crtc->unpin_work_count); |
10d83730 | 11535 | intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); |
e1f99ce6 | 11536 | |
75f7f3ec | 11537 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
a071fa00 | 11538 | work->flip_count = I915_READ(PIPE_FLIPCOUNT_GM45(pipe)) + 1; |
75f7f3ec | 11539 | |
4fa62c89 VS |
11540 | if (IS_VALLEYVIEW(dev)) { |
11541 | ring = &dev_priv->ring[BCS]; | |
ab8d6675 | 11542 | if (obj->tiling_mode != intel_fb_obj(work->old_fb)->tiling_mode) |
8e09bf83 CW |
11543 | /* vlv: DISPLAY_FLIP fails to change tiling */ |
11544 | ring = NULL; | |
48bf5b2d | 11545 | } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) { |
2a92d5bc | 11546 | ring = &dev_priv->ring[BCS]; |
4fa62c89 | 11547 | } else if (INTEL_INFO(dev)->gen >= 7) { |
b4716185 | 11548 | ring = i915_gem_request_get_ring(obj->last_write_req); |
4fa62c89 VS |
11549 | if (ring == NULL || ring->id != RCS) |
11550 | ring = &dev_priv->ring[BCS]; | |
11551 | } else { | |
11552 | ring = &dev_priv->ring[RCS]; | |
11553 | } | |
11554 | ||
cf5d8a46 CW |
11555 | mmio_flip = use_mmio_flip(ring, obj); |
11556 | ||
11557 | /* When using CS flips, we want to emit semaphores between rings. | |
11558 | * However, when using mmio flips we will create a task to do the | |
11559 | * synchronisation, so all we want here is to pin the framebuffer | |
11560 | * into the display plane and skip any waits. | |
11561 | */ | |
82bc3b2d | 11562 | ret = intel_pin_and_fence_fb_obj(crtc->primary, fb, |
cf5d8a46 | 11563 | crtc->primary->state, |
b4716185 | 11564 | mmio_flip ? i915_gem_request_get_ring(obj->last_write_req) : ring); |
8c9f3aaf JB |
11565 | if (ret) |
11566 | goto cleanup_pending; | |
6b95a207 | 11567 | |
121920fa TU |
11568 | work->gtt_offset = intel_plane_obj_offset(to_intel_plane(primary), obj) |
11569 | + intel_crtc->dspaddr_offset; | |
4fa62c89 | 11570 | |
cf5d8a46 | 11571 | if (mmio_flip) { |
84c33a64 SG |
11572 | ret = intel_queue_mmio_flip(dev, crtc, fb, obj, ring, |
11573 | page_flip_flags); | |
d6bbafa1 CW |
11574 | if (ret) |
11575 | goto cleanup_unpin; | |
11576 | ||
f06cc1b9 JH |
11577 | i915_gem_request_assign(&work->flip_queued_req, |
11578 | obj->last_write_req); | |
d6bbafa1 | 11579 | } else { |
d94b5030 CW |
11580 | if (obj->last_write_req) { |
11581 | ret = i915_gem_check_olr(obj->last_write_req); | |
11582 | if (ret) | |
11583 | goto cleanup_unpin; | |
11584 | } | |
11585 | ||
84c33a64 | 11586 | ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, ring, |
d6bbafa1 CW |
11587 | page_flip_flags); |
11588 | if (ret) | |
11589 | goto cleanup_unpin; | |
11590 | ||
f06cc1b9 JH |
11591 | i915_gem_request_assign(&work->flip_queued_req, |
11592 | intel_ring_get_request(ring)); | |
d6bbafa1 CW |
11593 | } |
11594 | ||
1e3feefd | 11595 | work->flip_queued_vblank = drm_crtc_vblank_count(crtc); |
d6bbafa1 | 11596 | work->enable_stall_check = true; |
4fa62c89 | 11597 | |
ab8d6675 | 11598 | i915_gem_track_fb(intel_fb_obj(work->old_fb), obj, |
a071fa00 DV |
11599 | INTEL_FRONTBUFFER_PRIMARY(pipe)); |
11600 | ||
7ff0ebcc | 11601 | intel_fbc_disable(dev); |
f99d7069 | 11602 | intel_frontbuffer_flip_prepare(dev, INTEL_FRONTBUFFER_PRIMARY(pipe)); |
6b95a207 KH |
11603 | mutex_unlock(&dev->struct_mutex); |
11604 | ||
e5510fac JB |
11605 | trace_i915_flip_request(intel_crtc->plane, obj); |
11606 | ||
6b95a207 | 11607 | return 0; |
96b099fd | 11608 | |
4fa62c89 | 11609 | cleanup_unpin: |
82bc3b2d | 11610 | intel_unpin_fb_obj(fb, crtc->primary->state); |
8c9f3aaf | 11611 | cleanup_pending: |
b4a98e57 | 11612 | atomic_dec(&intel_crtc->unpin_work_count); |
89ed88ba CW |
11613 | mutex_unlock(&dev->struct_mutex); |
11614 | cleanup: | |
f4510a27 | 11615 | crtc->primary->fb = old_fb; |
afd65eb4 | 11616 | update_state_fb(crtc->primary); |
89ed88ba CW |
11617 | |
11618 | drm_gem_object_unreference_unlocked(&obj->base); | |
ab8d6675 | 11619 | drm_framebuffer_unreference(work->old_fb); |
96b099fd | 11620 | |
5e2d7afc | 11621 | spin_lock_irq(&dev->event_lock); |
96b099fd | 11622 | intel_crtc->unpin_work = NULL; |
5e2d7afc | 11623 | spin_unlock_irq(&dev->event_lock); |
96b099fd | 11624 | |
87b6b101 | 11625 | drm_crtc_vblank_put(crtc); |
7317c75e | 11626 | free_work: |
96b099fd CW |
11627 | kfree(work); |
11628 | ||
f900db47 | 11629 | if (ret == -EIO) { |
02e0efb5 ML |
11630 | struct drm_atomic_state *state; |
11631 | struct drm_plane_state *plane_state; | |
11632 | ||
f900db47 | 11633 | out_hang: |
02e0efb5 ML |
11634 | state = drm_atomic_state_alloc(dev); |
11635 | if (!state) | |
11636 | return -ENOMEM; | |
11637 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); | |
11638 | ||
11639 | retry: | |
11640 | plane_state = drm_atomic_get_plane_state(state, primary); | |
11641 | ret = PTR_ERR_OR_ZERO(plane_state); | |
11642 | if (!ret) { | |
11643 | drm_atomic_set_fb_for_plane(plane_state, fb); | |
11644 | ||
11645 | ret = drm_atomic_set_crtc_for_plane(plane_state, crtc); | |
11646 | if (!ret) | |
11647 | ret = drm_atomic_commit(state); | |
11648 | } | |
11649 | ||
11650 | if (ret == -EDEADLK) { | |
11651 | drm_modeset_backoff(state->acquire_ctx); | |
11652 | drm_atomic_state_clear(state); | |
11653 | goto retry; | |
11654 | } | |
11655 | ||
11656 | if (ret) | |
11657 | drm_atomic_state_free(state); | |
11658 | ||
f0d3dad3 | 11659 | if (ret == 0 && event) { |
5e2d7afc | 11660 | spin_lock_irq(&dev->event_lock); |
a071fa00 | 11661 | drm_send_vblank_event(dev, pipe, event); |
5e2d7afc | 11662 | spin_unlock_irq(&dev->event_lock); |
f0d3dad3 | 11663 | } |
f900db47 | 11664 | } |
96b099fd | 11665 | return ret; |
6b95a207 KH |
11666 | } |
11667 | ||
6d3a1ce7 ML |
11668 | static bool encoders_cloneable(const struct intel_encoder *a, |
11669 | const struct intel_encoder *b) | |
11670 | { | |
11671 | /* masks could be asymmetric, so check both ways */ | |
11672 | return a == b || (a->cloneable & (1 << b->type) && | |
11673 | b->cloneable & (1 << a->type)); | |
11674 | } | |
11675 | ||
11676 | static bool check_single_encoder_cloning(struct drm_atomic_state *state, | |
11677 | struct intel_crtc *crtc, | |
11678 | struct intel_encoder *encoder) | |
11679 | { | |
11680 | struct intel_encoder *source_encoder; | |
11681 | struct drm_connector *connector; | |
11682 | struct drm_connector_state *connector_state; | |
11683 | int i; | |
11684 | ||
11685 | for_each_connector_in_state(state, connector, connector_state, i) { | |
11686 | if (connector_state->crtc != &crtc->base) | |
11687 | continue; | |
11688 | ||
11689 | source_encoder = | |
11690 | to_intel_encoder(connector_state->best_encoder); | |
11691 | if (!encoders_cloneable(encoder, source_encoder)) | |
11692 | return false; | |
11693 | } | |
11694 | ||
11695 | return true; | |
11696 | } | |
11697 | ||
11698 | static bool check_encoder_cloning(struct drm_atomic_state *state, | |
11699 | struct intel_crtc *crtc) | |
11700 | { | |
11701 | struct intel_encoder *encoder; | |
11702 | struct drm_connector *connector; | |
11703 | struct drm_connector_state *connector_state; | |
11704 | int i; | |
11705 | ||
11706 | for_each_connector_in_state(state, connector, connector_state, i) { | |
11707 | if (connector_state->crtc != &crtc->base) | |
11708 | continue; | |
11709 | ||
11710 | encoder = to_intel_encoder(connector_state->best_encoder); | |
11711 | if (!check_single_encoder_cloning(state, crtc, encoder)) | |
11712 | return false; | |
11713 | } | |
11714 | ||
11715 | return true; | |
11716 | } | |
11717 | ||
11718 | static int intel_crtc_atomic_check(struct drm_crtc *crtc, | |
11719 | struct drm_crtc_state *crtc_state) | |
11720 | { | |
cf5a15be | 11721 | struct drm_device *dev = crtc->dev; |
6d3a1ce7 | 11722 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
cf5a15be ML |
11723 | struct intel_crtc_state *pipe_config = |
11724 | to_intel_crtc_state(crtc_state); | |
6d3a1ce7 ML |
11725 | struct drm_atomic_state *state = crtc_state->state; |
11726 | int idx = crtc->base.id; | |
11727 | bool mode_changed = needs_modeset(crtc_state); | |
11728 | ||
11729 | if (mode_changed && !check_encoder_cloning(state, intel_crtc)) { | |
11730 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); | |
11731 | return -EINVAL; | |
11732 | } | |
11733 | ||
11734 | I915_STATE_WARN(crtc->state->active != intel_crtc->active, | |
11735 | "[CRTC:%i] mismatch between state->active(%i) and crtc->active(%i)\n", | |
11736 | idx, crtc->state->active, intel_crtc->active); | |
11737 | ||
cf5a15be | 11738 | return intel_atomic_setup_scalers(dev, intel_crtc, pipe_config); |
6d3a1ce7 ML |
11739 | } |
11740 | ||
65b38e0d | 11741 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { |
f6e5b160 CW |
11742 | .mode_set_base_atomic = intel_pipe_set_base_atomic, |
11743 | .load_lut = intel_crtc_load_lut, | |
ea2c67bb MR |
11744 | .atomic_begin = intel_begin_crtc_commit, |
11745 | .atomic_flush = intel_finish_crtc_commit, | |
6d3a1ce7 | 11746 | .atomic_check = intel_crtc_atomic_check, |
f6e5b160 CW |
11747 | }; |
11748 | ||
9a935856 DV |
11749 | /** |
11750 | * intel_modeset_update_staged_output_state | |
11751 | * | |
11752 | * Updates the staged output configuration state, e.g. after we've read out the | |
11753 | * current hw state. | |
11754 | */ | |
11755 | static void intel_modeset_update_staged_output_state(struct drm_device *dev) | |
f6e5b160 | 11756 | { |
7668851f | 11757 | struct intel_crtc *crtc; |
9a935856 DV |
11758 | struct intel_encoder *encoder; |
11759 | struct intel_connector *connector; | |
f6e5b160 | 11760 | |
3a3371ff | 11761 | for_each_intel_connector(dev, connector) { |
9a935856 DV |
11762 | connector->new_encoder = |
11763 | to_intel_encoder(connector->base.encoder); | |
11764 | } | |
f6e5b160 | 11765 | |
b2784e15 | 11766 | for_each_intel_encoder(dev, encoder) { |
9a935856 DV |
11767 | encoder->new_crtc = |
11768 | to_intel_crtc(encoder->base.crtc); | |
11769 | } | |
7668851f | 11770 | |
d3fcc808 | 11771 | for_each_intel_crtc(dev, crtc) { |
83d65738 | 11772 | crtc->new_enabled = crtc->base.state->enable; |
7668851f | 11773 | } |
f6e5b160 CW |
11774 | } |
11775 | ||
d29b2f9d ACO |
11776 | /* Transitional helper to copy current connector/encoder state to |
11777 | * connector->state. This is needed so that code that is partially | |
11778 | * converted to atomic does the right thing. | |
11779 | */ | |
11780 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) | |
11781 | { | |
11782 | struct intel_connector *connector; | |
11783 | ||
11784 | for_each_intel_connector(dev, connector) { | |
11785 | if (connector->base.encoder) { | |
11786 | connector->base.state->best_encoder = | |
11787 | connector->base.encoder; | |
11788 | connector->base.state->crtc = | |
11789 | connector->base.encoder->crtc; | |
11790 | } else { | |
11791 | connector->base.state->best_encoder = NULL; | |
11792 | connector->base.state->crtc = NULL; | |
11793 | } | |
11794 | } | |
11795 | } | |
11796 | ||
050f7aeb | 11797 | static void |
eba905b2 | 11798 | connected_sink_compute_bpp(struct intel_connector *connector, |
5cec258b | 11799 | struct intel_crtc_state *pipe_config) |
050f7aeb DV |
11800 | { |
11801 | int bpp = pipe_config->pipe_bpp; | |
11802 | ||
11803 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n", | |
11804 | connector->base.base.id, | |
c23cc417 | 11805 | connector->base.name); |
050f7aeb DV |
11806 | |
11807 | /* Don't use an invalid EDID bpc value */ | |
11808 | if (connector->base.display_info.bpc && | |
11809 | connector->base.display_info.bpc * 3 < bpp) { | |
11810 | DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n", | |
11811 | bpp, connector->base.display_info.bpc*3); | |
11812 | pipe_config->pipe_bpp = connector->base.display_info.bpc*3; | |
11813 | } | |
11814 | ||
11815 | /* Clamp bpp to 8 on screens without EDID 1.4 */ | |
11816 | if (connector->base.display_info.bpc == 0 && bpp > 24) { | |
11817 | DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n", | |
11818 | bpp); | |
11819 | pipe_config->pipe_bpp = 24; | |
11820 | } | |
11821 | } | |
11822 | ||
4e53c2e0 | 11823 | static int |
050f7aeb | 11824 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
5cec258b | 11825 | struct intel_crtc_state *pipe_config) |
4e53c2e0 | 11826 | { |
050f7aeb | 11827 | struct drm_device *dev = crtc->base.dev; |
1486017f | 11828 | struct drm_atomic_state *state; |
da3ced29 ACO |
11829 | struct drm_connector *connector; |
11830 | struct drm_connector_state *connector_state; | |
1486017f | 11831 | int bpp, i; |
4e53c2e0 | 11832 | |
d328c9d7 | 11833 | if ((IS_G4X(dev) || IS_VALLEYVIEW(dev))) |
4e53c2e0 | 11834 | bpp = 10*3; |
d328c9d7 DV |
11835 | else if (INTEL_INFO(dev)->gen >= 5) |
11836 | bpp = 12*3; | |
11837 | else | |
11838 | bpp = 8*3; | |
11839 | ||
4e53c2e0 | 11840 | |
4e53c2e0 DV |
11841 | pipe_config->pipe_bpp = bpp; |
11842 | ||
1486017f ACO |
11843 | state = pipe_config->base.state; |
11844 | ||
4e53c2e0 | 11845 | /* Clamp display bpp to EDID value */ |
da3ced29 ACO |
11846 | for_each_connector_in_state(state, connector, connector_state, i) { |
11847 | if (connector_state->crtc != &crtc->base) | |
4e53c2e0 DV |
11848 | continue; |
11849 | ||
da3ced29 ACO |
11850 | connected_sink_compute_bpp(to_intel_connector(connector), |
11851 | pipe_config); | |
4e53c2e0 DV |
11852 | } |
11853 | ||
11854 | return bpp; | |
11855 | } | |
11856 | ||
644db711 DV |
11857 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
11858 | { | |
11859 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " | |
11860 | "type: 0x%x flags: 0x%x\n", | |
1342830c | 11861 | mode->crtc_clock, |
644db711 DV |
11862 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
11863 | mode->crtc_hsync_end, mode->crtc_htotal, | |
11864 | mode->crtc_vdisplay, mode->crtc_vsync_start, | |
11865 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); | |
11866 | } | |
11867 | ||
c0b03411 | 11868 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
5cec258b | 11869 | struct intel_crtc_state *pipe_config, |
c0b03411 DV |
11870 | const char *context) |
11871 | { | |
6a60cd87 CK |
11872 | struct drm_device *dev = crtc->base.dev; |
11873 | struct drm_plane *plane; | |
11874 | struct intel_plane *intel_plane; | |
11875 | struct intel_plane_state *state; | |
11876 | struct drm_framebuffer *fb; | |
11877 | ||
11878 | DRM_DEBUG_KMS("[CRTC:%d]%s config %p for pipe %c\n", crtc->base.base.id, | |
11879 | context, pipe_config, pipe_name(crtc->pipe)); | |
c0b03411 DV |
11880 | |
11881 | DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder)); | |
11882 | DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n", | |
11883 | pipe_config->pipe_bpp, pipe_config->dither); | |
11884 | DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", | |
11885 | pipe_config->has_pch_encoder, | |
11886 | pipe_config->fdi_lanes, | |
11887 | pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n, | |
11888 | pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n, | |
11889 | pipe_config->fdi_m_n.tu); | |
eb14cb74 VS |
11890 | DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
11891 | pipe_config->has_dp_encoder, | |
11892 | pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n, | |
11893 | pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n, | |
11894 | pipe_config->dp_m_n.tu); | |
b95af8be VK |
11895 | |
11896 | DRM_DEBUG_KMS("dp: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n", | |
11897 | pipe_config->has_dp_encoder, | |
11898 | pipe_config->dp_m2_n2.gmch_m, | |
11899 | pipe_config->dp_m2_n2.gmch_n, | |
11900 | pipe_config->dp_m2_n2.link_m, | |
11901 | pipe_config->dp_m2_n2.link_n, | |
11902 | pipe_config->dp_m2_n2.tu); | |
11903 | ||
55072d19 DV |
11904 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
11905 | pipe_config->has_audio, | |
11906 | pipe_config->has_infoframe); | |
11907 | ||
c0b03411 | 11908 | DRM_DEBUG_KMS("requested mode:\n"); |
2d112de7 | 11909 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
c0b03411 | 11910 | DRM_DEBUG_KMS("adjusted mode:\n"); |
2d112de7 ACO |
11911 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
11912 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); | |
d71b8d4a | 11913 | DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock); |
37327abd VS |
11914 | DRM_DEBUG_KMS("pipe src size: %dx%d\n", |
11915 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); | |
0ec463d3 TU |
11916 | DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n", |
11917 | crtc->num_scalers, | |
11918 | pipe_config->scaler_state.scaler_users, | |
11919 | pipe_config->scaler_state.scaler_id); | |
c0b03411 DV |
11920 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
11921 | pipe_config->gmch_pfit.control, | |
11922 | pipe_config->gmch_pfit.pgm_ratios, | |
11923 | pipe_config->gmch_pfit.lvds_border_bits); | |
fd4daa9c | 11924 | DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n", |
c0b03411 | 11925 | pipe_config->pch_pfit.pos, |
fd4daa9c CW |
11926 | pipe_config->pch_pfit.size, |
11927 | pipe_config->pch_pfit.enabled ? "enabled" : "disabled"); | |
42db64ef | 11928 | DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled); |
cf532bb2 | 11929 | DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide); |
6a60cd87 | 11930 | |
415ff0f6 TU |
11931 | if (IS_BROXTON(dev)) { |
11932 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: ebb0: 0x%x, " | |
11933 | "pll0: 0x%x, pll1: 0x%x, pll2: 0x%x, pll3: 0x%x, " | |
11934 | "pll6: 0x%x, pll8: 0x%x, pcsdw12: 0x%x\n", | |
11935 | pipe_config->ddi_pll_sel, | |
11936 | pipe_config->dpll_hw_state.ebb0, | |
11937 | pipe_config->dpll_hw_state.pll0, | |
11938 | pipe_config->dpll_hw_state.pll1, | |
11939 | pipe_config->dpll_hw_state.pll2, | |
11940 | pipe_config->dpll_hw_state.pll3, | |
11941 | pipe_config->dpll_hw_state.pll6, | |
11942 | pipe_config->dpll_hw_state.pll8, | |
11943 | pipe_config->dpll_hw_state.pcsdw12); | |
11944 | } else if (IS_SKYLAKE(dev)) { | |
11945 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: " | |
11946 | "ctrl1: 0x%x, cfgcr1: 0x%x, cfgcr2: 0x%x\n", | |
11947 | pipe_config->ddi_pll_sel, | |
11948 | pipe_config->dpll_hw_state.ctrl1, | |
11949 | pipe_config->dpll_hw_state.cfgcr1, | |
11950 | pipe_config->dpll_hw_state.cfgcr2); | |
11951 | } else if (HAS_DDI(dev)) { | |
11952 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: wrpll: 0x%x\n", | |
11953 | pipe_config->ddi_pll_sel, | |
11954 | pipe_config->dpll_hw_state.wrpll); | |
11955 | } else { | |
11956 | DRM_DEBUG_KMS("dpll_hw_state: dpll: 0x%x, dpll_md: 0x%x, " | |
11957 | "fp0: 0x%x, fp1: 0x%x\n", | |
11958 | pipe_config->dpll_hw_state.dpll, | |
11959 | pipe_config->dpll_hw_state.dpll_md, | |
11960 | pipe_config->dpll_hw_state.fp0, | |
11961 | pipe_config->dpll_hw_state.fp1); | |
11962 | } | |
11963 | ||
6a60cd87 CK |
11964 | DRM_DEBUG_KMS("planes on this crtc\n"); |
11965 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { | |
11966 | intel_plane = to_intel_plane(plane); | |
11967 | if (intel_plane->pipe != crtc->pipe) | |
11968 | continue; | |
11969 | ||
11970 | state = to_intel_plane_state(plane->state); | |
11971 | fb = state->base.fb; | |
11972 | if (!fb) { | |
11973 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d " | |
11974 | "disabled, scaler_id = %d\n", | |
11975 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", | |
11976 | plane->base.id, intel_plane->pipe, | |
11977 | (crtc->base.primary == plane) ? 0 : intel_plane->plane + 1, | |
11978 | drm_plane_index(plane), state->scaler_id); | |
11979 | continue; | |
11980 | } | |
11981 | ||
11982 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d enabled", | |
11983 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", | |
11984 | plane->base.id, intel_plane->pipe, | |
11985 | crtc->base.primary == plane ? 0 : intel_plane->plane + 1, | |
11986 | drm_plane_index(plane)); | |
11987 | DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = 0x%x", | |
11988 | fb->base.id, fb->width, fb->height, fb->pixel_format); | |
11989 | DRM_DEBUG_KMS("\tscaler:%d src (%u, %u) %ux%u dst (%u, %u) %ux%u\n", | |
11990 | state->scaler_id, | |
11991 | state->src.x1 >> 16, state->src.y1 >> 16, | |
11992 | drm_rect_width(&state->src) >> 16, | |
11993 | drm_rect_height(&state->src) >> 16, | |
11994 | state->dst.x1, state->dst.y1, | |
11995 | drm_rect_width(&state->dst), drm_rect_height(&state->dst)); | |
11996 | } | |
c0b03411 DV |
11997 | } |
11998 | ||
5448a00d | 11999 | static bool check_digital_port_conflicts(struct drm_atomic_state *state) |
00f0b378 | 12000 | { |
5448a00d ACO |
12001 | struct drm_device *dev = state->dev; |
12002 | struct intel_encoder *encoder; | |
da3ced29 | 12003 | struct drm_connector *connector; |
5448a00d | 12004 | struct drm_connector_state *connector_state; |
00f0b378 | 12005 | unsigned int used_ports = 0; |
5448a00d | 12006 | int i; |
00f0b378 VS |
12007 | |
12008 | /* | |
12009 | * Walk the connector list instead of the encoder | |
12010 | * list to detect the problem on ddi platforms | |
12011 | * where there's just one encoder per digital port. | |
12012 | */ | |
da3ced29 | 12013 | for_each_connector_in_state(state, connector, connector_state, i) { |
5448a00d | 12014 | if (!connector_state->best_encoder) |
00f0b378 VS |
12015 | continue; |
12016 | ||
5448a00d ACO |
12017 | encoder = to_intel_encoder(connector_state->best_encoder); |
12018 | ||
12019 | WARN_ON(!connector_state->crtc); | |
00f0b378 VS |
12020 | |
12021 | switch (encoder->type) { | |
12022 | unsigned int port_mask; | |
12023 | case INTEL_OUTPUT_UNKNOWN: | |
12024 | if (WARN_ON(!HAS_DDI(dev))) | |
12025 | break; | |
12026 | case INTEL_OUTPUT_DISPLAYPORT: | |
12027 | case INTEL_OUTPUT_HDMI: | |
12028 | case INTEL_OUTPUT_EDP: | |
12029 | port_mask = 1 << enc_to_dig_port(&encoder->base)->port; | |
12030 | ||
12031 | /* the same port mustn't appear more than once */ | |
12032 | if (used_ports & port_mask) | |
12033 | return false; | |
12034 | ||
12035 | used_ports |= port_mask; | |
12036 | default: | |
12037 | break; | |
12038 | } | |
12039 | } | |
12040 | ||
12041 | return true; | |
12042 | } | |
12043 | ||
83a57153 ACO |
12044 | static void |
12045 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) | |
12046 | { | |
12047 | struct drm_crtc_state tmp_state; | |
663a3640 | 12048 | struct intel_crtc_scaler_state scaler_state; |
4978cc93 ACO |
12049 | struct intel_dpll_hw_state dpll_hw_state; |
12050 | enum intel_dpll_id shared_dpll; | |
8504c74c | 12051 | uint32_t ddi_pll_sel; |
83a57153 | 12052 | |
7546a384 ACO |
12053 | /* FIXME: before the switch to atomic started, a new pipe_config was |
12054 | * kzalloc'd. Code that depends on any field being zero should be | |
12055 | * fixed, so that the crtc_state can be safely duplicated. For now, | |
12056 | * only fields that are know to not cause problems are preserved. */ | |
12057 | ||
83a57153 | 12058 | tmp_state = crtc_state->base; |
663a3640 | 12059 | scaler_state = crtc_state->scaler_state; |
4978cc93 ACO |
12060 | shared_dpll = crtc_state->shared_dpll; |
12061 | dpll_hw_state = crtc_state->dpll_hw_state; | |
8504c74c | 12062 | ddi_pll_sel = crtc_state->ddi_pll_sel; |
4978cc93 | 12063 | |
83a57153 | 12064 | memset(crtc_state, 0, sizeof *crtc_state); |
4978cc93 | 12065 | |
83a57153 | 12066 | crtc_state->base = tmp_state; |
663a3640 | 12067 | crtc_state->scaler_state = scaler_state; |
4978cc93 ACO |
12068 | crtc_state->shared_dpll = shared_dpll; |
12069 | crtc_state->dpll_hw_state = dpll_hw_state; | |
8504c74c | 12070 | crtc_state->ddi_pll_sel = ddi_pll_sel; |
83a57153 ACO |
12071 | } |
12072 | ||
548ee15b | 12073 | static int |
b8cecdf5 | 12074 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
b359283a | 12075 | struct intel_crtc_state *pipe_config) |
ee7b9f93 | 12076 | { |
b359283a | 12077 | struct drm_atomic_state *state = pipe_config->base.state; |
7758a113 | 12078 | struct intel_encoder *encoder; |
da3ced29 | 12079 | struct drm_connector *connector; |
0b901879 | 12080 | struct drm_connector_state *connector_state; |
d328c9d7 | 12081 | int base_bpp, ret = -EINVAL; |
0b901879 | 12082 | int i; |
e29c22c0 | 12083 | bool retry = true; |
ee7b9f93 | 12084 | |
83a57153 | 12085 | clear_intel_crtc_state(pipe_config); |
7758a113 | 12086 | |
e143a21c DV |
12087 | pipe_config->cpu_transcoder = |
12088 | (enum transcoder) to_intel_crtc(crtc)->pipe; | |
b8cecdf5 | 12089 | |
2960bc9c ID |
12090 | /* |
12091 | * Sanitize sync polarity flags based on requested ones. If neither | |
12092 | * positive or negative polarity is requested, treat this as meaning | |
12093 | * negative polarity. | |
12094 | */ | |
2d112de7 | 12095 | if (!(pipe_config->base.adjusted_mode.flags & |
2960bc9c | 12096 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
2d112de7 | 12097 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
2960bc9c | 12098 | |
2d112de7 | 12099 | if (!(pipe_config->base.adjusted_mode.flags & |
2960bc9c | 12100 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
2d112de7 | 12101 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
2960bc9c | 12102 | |
050f7aeb DV |
12103 | /* Compute a starting value for pipe_config->pipe_bpp taking the source |
12104 | * plane pixel format and any sink constraints into account. Returns the | |
12105 | * source plane bpp so that dithering can be selected on mismatches | |
12106 | * after encoders and crtc also have had their say. */ | |
d328c9d7 DV |
12107 | base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
12108 | pipe_config); | |
12109 | if (base_bpp < 0) | |
4e53c2e0 DV |
12110 | goto fail; |
12111 | ||
e41a56be VS |
12112 | /* |
12113 | * Determine the real pipe dimensions. Note that stereo modes can | |
12114 | * increase the actual pipe size due to the frame doubling and | |
12115 | * insertion of additional space for blanks between the frame. This | |
12116 | * is stored in the crtc timings. We use the requested mode to do this | |
12117 | * computation to clearly distinguish it from the adjusted mode, which | |
12118 | * can be changed by the connectors in the below retry loop. | |
12119 | */ | |
2d112de7 | 12120 | drm_crtc_get_hv_timing(&pipe_config->base.mode, |
ecb7e16b GP |
12121 | &pipe_config->pipe_src_w, |
12122 | &pipe_config->pipe_src_h); | |
e41a56be | 12123 | |
e29c22c0 | 12124 | encoder_retry: |
ef1b460d | 12125 | /* Ensure the port clock defaults are reset when retrying. */ |
ff9a6750 | 12126 | pipe_config->port_clock = 0; |
ef1b460d | 12127 | pipe_config->pixel_multiplier = 1; |
ff9a6750 | 12128 | |
135c81b8 | 12129 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
2d112de7 ACO |
12130 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
12131 | CRTC_STEREO_DOUBLE); | |
135c81b8 | 12132 | |
7758a113 DV |
12133 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
12134 | * adjust it according to limitations or connector properties, and also | |
12135 | * a chance to reject the mode entirely. | |
47f1c6c9 | 12136 | */ |
da3ced29 | 12137 | for_each_connector_in_state(state, connector, connector_state, i) { |
0b901879 | 12138 | if (connector_state->crtc != crtc) |
7758a113 | 12139 | continue; |
7ae89233 | 12140 | |
0b901879 ACO |
12141 | encoder = to_intel_encoder(connector_state->best_encoder); |
12142 | ||
efea6e8e DV |
12143 | if (!(encoder->compute_config(encoder, pipe_config))) { |
12144 | DRM_DEBUG_KMS("Encoder config failure\n"); | |
7758a113 DV |
12145 | goto fail; |
12146 | } | |
ee7b9f93 | 12147 | } |
47f1c6c9 | 12148 | |
ff9a6750 DV |
12149 | /* Set default port clock if not overwritten by the encoder. Needs to be |
12150 | * done afterwards in case the encoder adjusts the mode. */ | |
12151 | if (!pipe_config->port_clock) | |
2d112de7 | 12152 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
241bfc38 | 12153 | * pipe_config->pixel_multiplier; |
ff9a6750 | 12154 | |
a43f6e0f | 12155 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
e29c22c0 | 12156 | if (ret < 0) { |
7758a113 DV |
12157 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
12158 | goto fail; | |
ee7b9f93 | 12159 | } |
e29c22c0 DV |
12160 | |
12161 | if (ret == RETRY) { | |
12162 | if (WARN(!retry, "loop in pipe configuration computation\n")) { | |
12163 | ret = -EINVAL; | |
12164 | goto fail; | |
12165 | } | |
12166 | ||
12167 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); | |
12168 | retry = false; | |
12169 | goto encoder_retry; | |
12170 | } | |
12171 | ||
d328c9d7 | 12172 | pipe_config->dither = pipe_config->pipe_bpp != base_bpp; |
4e53c2e0 | 12173 | DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n", |
d328c9d7 | 12174 | base_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
4e53c2e0 | 12175 | |
cdba954e ACO |
12176 | /* Check if we need to force a modeset */ |
12177 | if (pipe_config->has_audio != | |
85a96e7a | 12178 | to_intel_crtc_state(crtc->state)->has_audio) { |
cdba954e | 12179 | pipe_config->base.mode_changed = true; |
85a96e7a ML |
12180 | ret = drm_atomic_add_affected_planes(state, crtc); |
12181 | } | |
cdba954e ACO |
12182 | |
12183 | /* | |
12184 | * Note we have an issue here with infoframes: current code | |
12185 | * only updates them on the full mode set path per hw | |
12186 | * requirements. So here we should be checking for any | |
12187 | * required changes and forcing a mode set. | |
12188 | */ | |
7758a113 | 12189 | fail: |
548ee15b | 12190 | return ret; |
ee7b9f93 | 12191 | } |
47f1c6c9 | 12192 | |
ea9d758d | 12193 | static bool intel_crtc_in_use(struct drm_crtc *crtc) |
f6e5b160 | 12194 | { |
ea9d758d | 12195 | struct drm_encoder *encoder; |
f6e5b160 | 12196 | struct drm_device *dev = crtc->dev; |
f6e5b160 | 12197 | |
ea9d758d DV |
12198 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) |
12199 | if (encoder->crtc == crtc) | |
12200 | return true; | |
12201 | ||
12202 | return false; | |
12203 | } | |
12204 | ||
12205 | static void | |
0a9ab303 | 12206 | intel_modeset_update_state(struct drm_atomic_state *state) |
ea9d758d | 12207 | { |
0a9ab303 | 12208 | struct drm_device *dev = state->dev; |
ea9d758d | 12209 | struct intel_encoder *intel_encoder; |
0a9ab303 ACO |
12210 | struct drm_crtc *crtc; |
12211 | struct drm_crtc_state *crtc_state; | |
ea9d758d DV |
12212 | struct drm_connector *connector; |
12213 | ||
de419ab6 | 12214 | intel_shared_dpll_commit(state); |
ba41c0de | 12215 | |
b2784e15 | 12216 | for_each_intel_encoder(dev, intel_encoder) { |
ea9d758d DV |
12217 | if (!intel_encoder->base.crtc) |
12218 | continue; | |
12219 | ||
69024de8 ML |
12220 | crtc = intel_encoder->base.crtc; |
12221 | crtc_state = drm_atomic_get_existing_crtc_state(state, crtc); | |
12222 | if (!crtc_state || !needs_modeset(crtc->state)) | |
12223 | continue; | |
ea9d758d | 12224 | |
69024de8 | 12225 | intel_encoder->connectors_active = false; |
ea9d758d DV |
12226 | } |
12227 | ||
3cb480bc | 12228 | drm_atomic_helper_update_legacy_modeset_state(state->dev, state); |
f7217905 | 12229 | intel_modeset_update_staged_output_state(state->dev); |
ea9d758d | 12230 | |
7668851f | 12231 | /* Double check state. */ |
0a9ab303 ACO |
12232 | for_each_crtc(dev, crtc) { |
12233 | WARN_ON(crtc->state->enable != intel_crtc_in_use(crtc)); | |
3cb480bc ML |
12234 | |
12235 | to_intel_crtc(crtc)->config = to_intel_crtc_state(crtc->state); | |
fc467a22 ML |
12236 | |
12237 | /* Update hwmode for vblank functions */ | |
12238 | if (crtc->state->active) | |
12239 | crtc->hwmode = crtc->state->adjusted_mode; | |
12240 | else | |
12241 | crtc->hwmode.crtc_clock = 0; | |
ea9d758d DV |
12242 | } |
12243 | ||
12244 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { | |
12245 | if (!connector->encoder || !connector->encoder->crtc) | |
12246 | continue; | |
12247 | ||
69024de8 ML |
12248 | crtc = connector->encoder->crtc; |
12249 | crtc_state = drm_atomic_get_existing_crtc_state(state, crtc); | |
12250 | if (!crtc_state || !needs_modeset(crtc->state)) | |
12251 | continue; | |
ea9d758d | 12252 | |
53d9f4e9 | 12253 | if (crtc->state->active) { |
69024de8 ML |
12254 | struct drm_property *dpms_property = |
12255 | dev->mode_config.dpms_property; | |
68d34720 | 12256 | |
69024de8 ML |
12257 | connector->dpms = DRM_MODE_DPMS_ON; |
12258 | drm_object_property_set_value(&connector->base, dpms_property, DRM_MODE_DPMS_ON); | |
ea9d758d | 12259 | |
69024de8 ML |
12260 | intel_encoder = to_intel_encoder(connector->encoder); |
12261 | intel_encoder->connectors_active = true; | |
12262 | } else | |
12263 | connector->dpms = DRM_MODE_DPMS_OFF; | |
ea9d758d | 12264 | } |
ea9d758d DV |
12265 | } |
12266 | ||
3bd26263 | 12267 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
f1f644dc | 12268 | { |
3bd26263 | 12269 | int diff; |
f1f644dc JB |
12270 | |
12271 | if (clock1 == clock2) | |
12272 | return true; | |
12273 | ||
12274 | if (!clock1 || !clock2) | |
12275 | return false; | |
12276 | ||
12277 | diff = abs(clock1 - clock2); | |
12278 | ||
12279 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) | |
12280 | return true; | |
12281 | ||
12282 | return false; | |
12283 | } | |
12284 | ||
25c5b266 DV |
12285 | #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \ |
12286 | list_for_each_entry((intel_crtc), \ | |
12287 | &(dev)->mode_config.crtc_list, \ | |
12288 | base.head) \ | |
0973f18f | 12289 | if (mask & (1 <<(intel_crtc)->pipe)) |
25c5b266 | 12290 | |
0e8ffe1b | 12291 | static bool |
2fa2fe9a | 12292 | intel_pipe_config_compare(struct drm_device *dev, |
5cec258b ACO |
12293 | struct intel_crtc_state *current_config, |
12294 | struct intel_crtc_state *pipe_config) | |
0e8ffe1b | 12295 | { |
66e985c0 DV |
12296 | #define PIPE_CONF_CHECK_X(name) \ |
12297 | if (current_config->name != pipe_config->name) { \ | |
12298 | DRM_ERROR("mismatch in " #name " " \ | |
12299 | "(expected 0x%08x, found 0x%08x)\n", \ | |
12300 | current_config->name, \ | |
12301 | pipe_config->name); \ | |
12302 | return false; \ | |
12303 | } | |
12304 | ||
08a24034 DV |
12305 | #define PIPE_CONF_CHECK_I(name) \ |
12306 | if (current_config->name != pipe_config->name) { \ | |
12307 | DRM_ERROR("mismatch in " #name " " \ | |
12308 | "(expected %i, found %i)\n", \ | |
12309 | current_config->name, \ | |
12310 | pipe_config->name); \ | |
12311 | return false; \ | |
88adfff1 DV |
12312 | } |
12313 | ||
b95af8be VK |
12314 | /* This is required for BDW+ where there is only one set of registers for |
12315 | * switching between high and low RR. | |
12316 | * This macro can be used whenever a comparison has to be made between one | |
12317 | * hw state and multiple sw state variables. | |
12318 | */ | |
12319 | #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \ | |
12320 | if ((current_config->name != pipe_config->name) && \ | |
12321 | (current_config->alt_name != pipe_config->name)) { \ | |
12322 | DRM_ERROR("mismatch in " #name " " \ | |
12323 | "(expected %i or %i, found %i)\n", \ | |
12324 | current_config->name, \ | |
12325 | current_config->alt_name, \ | |
12326 | pipe_config->name); \ | |
12327 | return false; \ | |
12328 | } | |
12329 | ||
1bd1bd80 DV |
12330 | #define PIPE_CONF_CHECK_FLAGS(name, mask) \ |
12331 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ | |
6f02488e | 12332 | DRM_ERROR("mismatch in " #name "(" #mask ") " \ |
1bd1bd80 DV |
12333 | "(expected %i, found %i)\n", \ |
12334 | current_config->name & (mask), \ | |
12335 | pipe_config->name & (mask)); \ | |
12336 | return false; \ | |
12337 | } | |
12338 | ||
5e550656 VS |
12339 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \ |
12340 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ | |
12341 | DRM_ERROR("mismatch in " #name " " \ | |
12342 | "(expected %i, found %i)\n", \ | |
12343 | current_config->name, \ | |
12344 | pipe_config->name); \ | |
12345 | return false; \ | |
12346 | } | |
12347 | ||
bb760063 DV |
12348 | #define PIPE_CONF_QUIRK(quirk) \ |
12349 | ((current_config->quirks | pipe_config->quirks) & (quirk)) | |
12350 | ||
eccb140b DV |
12351 | PIPE_CONF_CHECK_I(cpu_transcoder); |
12352 | ||
08a24034 DV |
12353 | PIPE_CONF_CHECK_I(has_pch_encoder); |
12354 | PIPE_CONF_CHECK_I(fdi_lanes); | |
72419203 DV |
12355 | PIPE_CONF_CHECK_I(fdi_m_n.gmch_m); |
12356 | PIPE_CONF_CHECK_I(fdi_m_n.gmch_n); | |
12357 | PIPE_CONF_CHECK_I(fdi_m_n.link_m); | |
12358 | PIPE_CONF_CHECK_I(fdi_m_n.link_n); | |
12359 | PIPE_CONF_CHECK_I(fdi_m_n.tu); | |
08a24034 | 12360 | |
eb14cb74 | 12361 | PIPE_CONF_CHECK_I(has_dp_encoder); |
b95af8be VK |
12362 | |
12363 | if (INTEL_INFO(dev)->gen < 8) { | |
12364 | PIPE_CONF_CHECK_I(dp_m_n.gmch_m); | |
12365 | PIPE_CONF_CHECK_I(dp_m_n.gmch_n); | |
12366 | PIPE_CONF_CHECK_I(dp_m_n.link_m); | |
12367 | PIPE_CONF_CHECK_I(dp_m_n.link_n); | |
12368 | PIPE_CONF_CHECK_I(dp_m_n.tu); | |
12369 | ||
12370 | if (current_config->has_drrs) { | |
12371 | PIPE_CONF_CHECK_I(dp_m2_n2.gmch_m); | |
12372 | PIPE_CONF_CHECK_I(dp_m2_n2.gmch_n); | |
12373 | PIPE_CONF_CHECK_I(dp_m2_n2.link_m); | |
12374 | PIPE_CONF_CHECK_I(dp_m2_n2.link_n); | |
12375 | PIPE_CONF_CHECK_I(dp_m2_n2.tu); | |
12376 | } | |
12377 | } else { | |
12378 | PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_m, dp_m2_n2.gmch_m); | |
12379 | PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_n, dp_m2_n2.gmch_n); | |
12380 | PIPE_CONF_CHECK_I_ALT(dp_m_n.link_m, dp_m2_n2.link_m); | |
12381 | PIPE_CONF_CHECK_I_ALT(dp_m_n.link_n, dp_m2_n2.link_n); | |
12382 | PIPE_CONF_CHECK_I_ALT(dp_m_n.tu, dp_m2_n2.tu); | |
12383 | } | |
eb14cb74 | 12384 | |
2d112de7 ACO |
12385 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
12386 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); | |
12387 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); | |
12388 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); | |
12389 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); | |
12390 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); | |
1bd1bd80 | 12391 | |
2d112de7 ACO |
12392 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
12393 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); | |
12394 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); | |
12395 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); | |
12396 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); | |
12397 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); | |
1bd1bd80 | 12398 | |
c93f54cf | 12399 | PIPE_CONF_CHECK_I(pixel_multiplier); |
6897b4b5 | 12400 | PIPE_CONF_CHECK_I(has_hdmi_sink); |
b5a9fa09 DV |
12401 | if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) || |
12402 | IS_VALLEYVIEW(dev)) | |
12403 | PIPE_CONF_CHECK_I(limited_color_range); | |
e43823ec | 12404 | PIPE_CONF_CHECK_I(has_infoframe); |
6c49f241 | 12405 | |
9ed109a7 DV |
12406 | PIPE_CONF_CHECK_I(has_audio); |
12407 | ||
2d112de7 | 12408 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
1bd1bd80 DV |
12409 | DRM_MODE_FLAG_INTERLACE); |
12410 | ||
bb760063 | 12411 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
2d112de7 | 12412 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12413 | DRM_MODE_FLAG_PHSYNC); |
2d112de7 | 12414 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12415 | DRM_MODE_FLAG_NHSYNC); |
2d112de7 | 12416 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12417 | DRM_MODE_FLAG_PVSYNC); |
2d112de7 | 12418 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 DV |
12419 | DRM_MODE_FLAG_NVSYNC); |
12420 | } | |
045ac3b5 | 12421 | |
37327abd VS |
12422 | PIPE_CONF_CHECK_I(pipe_src_w); |
12423 | PIPE_CONF_CHECK_I(pipe_src_h); | |
1bd1bd80 | 12424 | |
9953599b DV |
12425 | /* |
12426 | * FIXME: BIOS likes to set up a cloned config with lvds+external | |
12427 | * screen. Since we don't yet re-compute the pipe config when moving | |
12428 | * just the lvds port away to another pipe the sw tracking won't match. | |
12429 | * | |
12430 | * Proper atomic modesets with recomputed global state will fix this. | |
12431 | * Until then just don't check gmch state for inherited modes. | |
12432 | */ | |
12433 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE)) { | |
12434 | PIPE_CONF_CHECK_I(gmch_pfit.control); | |
12435 | /* pfit ratios are autocomputed by the hw on gen4+ */ | |
12436 | if (INTEL_INFO(dev)->gen < 4) | |
12437 | PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios); | |
12438 | PIPE_CONF_CHECK_I(gmch_pfit.lvds_border_bits); | |
12439 | } | |
12440 | ||
fd4daa9c CW |
12441 | PIPE_CONF_CHECK_I(pch_pfit.enabled); |
12442 | if (current_config->pch_pfit.enabled) { | |
12443 | PIPE_CONF_CHECK_I(pch_pfit.pos); | |
12444 | PIPE_CONF_CHECK_I(pch_pfit.size); | |
12445 | } | |
2fa2fe9a | 12446 | |
a1b2278e CK |
12447 | PIPE_CONF_CHECK_I(scaler_state.scaler_id); |
12448 | ||
e59150dc JB |
12449 | /* BDW+ don't expose a synchronous way to read the state */ |
12450 | if (IS_HASWELL(dev)) | |
12451 | PIPE_CONF_CHECK_I(ips_enabled); | |
42db64ef | 12452 | |
282740f7 VS |
12453 | PIPE_CONF_CHECK_I(double_wide); |
12454 | ||
26804afd DV |
12455 | PIPE_CONF_CHECK_X(ddi_pll_sel); |
12456 | ||
c0d43d62 | 12457 | PIPE_CONF_CHECK_I(shared_dpll); |
66e985c0 | 12458 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
8bcc2795 | 12459 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
66e985c0 DV |
12460 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
12461 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); | |
d452c5b6 | 12462 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
3f4cd19f DL |
12463 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
12464 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); | |
12465 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); | |
c0d43d62 | 12466 | |
42571aef VS |
12467 | if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) |
12468 | PIPE_CONF_CHECK_I(pipe_bpp); | |
12469 | ||
2d112de7 | 12470 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
a9a7e98a | 12471 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
5e550656 | 12472 | |
66e985c0 | 12473 | #undef PIPE_CONF_CHECK_X |
08a24034 | 12474 | #undef PIPE_CONF_CHECK_I |
b95af8be | 12475 | #undef PIPE_CONF_CHECK_I_ALT |
1bd1bd80 | 12476 | #undef PIPE_CONF_CHECK_FLAGS |
5e550656 | 12477 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
bb760063 | 12478 | #undef PIPE_CONF_QUIRK |
88adfff1 | 12479 | |
0e8ffe1b DV |
12480 | return true; |
12481 | } | |
12482 | ||
08db6652 DL |
12483 | static void check_wm_state(struct drm_device *dev) |
12484 | { | |
12485 | struct drm_i915_private *dev_priv = dev->dev_private; | |
12486 | struct skl_ddb_allocation hw_ddb, *sw_ddb; | |
12487 | struct intel_crtc *intel_crtc; | |
12488 | int plane; | |
12489 | ||
12490 | if (INTEL_INFO(dev)->gen < 9) | |
12491 | return; | |
12492 | ||
12493 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); | |
12494 | sw_ddb = &dev_priv->wm.skl_hw.ddb; | |
12495 | ||
12496 | for_each_intel_crtc(dev, intel_crtc) { | |
12497 | struct skl_ddb_entry *hw_entry, *sw_entry; | |
12498 | const enum pipe pipe = intel_crtc->pipe; | |
12499 | ||
12500 | if (!intel_crtc->active) | |
12501 | continue; | |
12502 | ||
12503 | /* planes */ | |
dd740780 | 12504 | for_each_plane(dev_priv, pipe, plane) { |
08db6652 DL |
12505 | hw_entry = &hw_ddb.plane[pipe][plane]; |
12506 | sw_entry = &sw_ddb->plane[pipe][plane]; | |
12507 | ||
12508 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) | |
12509 | continue; | |
12510 | ||
12511 | DRM_ERROR("mismatch in DDB state pipe %c plane %d " | |
12512 | "(expected (%u,%u), found (%u,%u))\n", | |
12513 | pipe_name(pipe), plane + 1, | |
12514 | sw_entry->start, sw_entry->end, | |
12515 | hw_entry->start, hw_entry->end); | |
12516 | } | |
12517 | ||
12518 | /* cursor */ | |
12519 | hw_entry = &hw_ddb.cursor[pipe]; | |
12520 | sw_entry = &sw_ddb->cursor[pipe]; | |
12521 | ||
12522 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) | |
12523 | continue; | |
12524 | ||
12525 | DRM_ERROR("mismatch in DDB state pipe %c cursor " | |
12526 | "(expected (%u,%u), found (%u,%u))\n", | |
12527 | pipe_name(pipe), | |
12528 | sw_entry->start, sw_entry->end, | |
12529 | hw_entry->start, hw_entry->end); | |
12530 | } | |
12531 | } | |
12532 | ||
91d1b4bd DV |
12533 | static void |
12534 | check_connector_state(struct drm_device *dev) | |
8af6cf88 | 12535 | { |
8af6cf88 DV |
12536 | struct intel_connector *connector; |
12537 | ||
3a3371ff | 12538 | for_each_intel_connector(dev, connector) { |
8af6cf88 DV |
12539 | /* This also checks the encoder/connector hw state with the |
12540 | * ->get_hw_state callbacks. */ | |
12541 | intel_connector_check_state(connector); | |
12542 | ||
e2c719b7 | 12543 | I915_STATE_WARN(&connector->new_encoder->base != connector->base.encoder, |
8af6cf88 DV |
12544 | "connector's staged encoder doesn't match current encoder\n"); |
12545 | } | |
91d1b4bd DV |
12546 | } |
12547 | ||
12548 | static void | |
12549 | check_encoder_state(struct drm_device *dev) | |
12550 | { | |
12551 | struct intel_encoder *encoder; | |
12552 | struct intel_connector *connector; | |
8af6cf88 | 12553 | |
b2784e15 | 12554 | for_each_intel_encoder(dev, encoder) { |
8af6cf88 DV |
12555 | bool enabled = false; |
12556 | bool active = false; | |
12557 | enum pipe pipe, tracked_pipe; | |
12558 | ||
12559 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", | |
12560 | encoder->base.base.id, | |
8e329a03 | 12561 | encoder->base.name); |
8af6cf88 | 12562 | |
e2c719b7 | 12563 | I915_STATE_WARN(&encoder->new_crtc->base != encoder->base.crtc, |
8af6cf88 | 12564 | "encoder's stage crtc doesn't match current crtc\n"); |
e2c719b7 | 12565 | I915_STATE_WARN(encoder->connectors_active && !encoder->base.crtc, |
8af6cf88 DV |
12566 | "encoder's active_connectors set, but no crtc\n"); |
12567 | ||
3a3371ff | 12568 | for_each_intel_connector(dev, connector) { |
8af6cf88 DV |
12569 | if (connector->base.encoder != &encoder->base) |
12570 | continue; | |
12571 | enabled = true; | |
12572 | if (connector->base.dpms != DRM_MODE_DPMS_OFF) | |
12573 | active = true; | |
12574 | } | |
0e32b39c DA |
12575 | /* |
12576 | * for MST connectors if we unplug the connector is gone | |
12577 | * away but the encoder is still connected to a crtc | |
12578 | * until a modeset happens in response to the hotplug. | |
12579 | */ | |
12580 | if (!enabled && encoder->base.encoder_type == DRM_MODE_ENCODER_DPMST) | |
12581 | continue; | |
12582 | ||
e2c719b7 | 12583 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
8af6cf88 DV |
12584 | "encoder's enabled state mismatch " |
12585 | "(expected %i, found %i)\n", | |
12586 | !!encoder->base.crtc, enabled); | |
e2c719b7 | 12587 | I915_STATE_WARN(active && !encoder->base.crtc, |
8af6cf88 DV |
12588 | "active encoder with no crtc\n"); |
12589 | ||
e2c719b7 | 12590 | I915_STATE_WARN(encoder->connectors_active != active, |
8af6cf88 DV |
12591 | "encoder's computed active state doesn't match tracked active state " |
12592 | "(expected %i, found %i)\n", active, encoder->connectors_active); | |
12593 | ||
12594 | active = encoder->get_hw_state(encoder, &pipe); | |
e2c719b7 | 12595 | I915_STATE_WARN(active != encoder->connectors_active, |
8af6cf88 DV |
12596 | "encoder's hw state doesn't match sw tracking " |
12597 | "(expected %i, found %i)\n", | |
12598 | encoder->connectors_active, active); | |
12599 | ||
12600 | if (!encoder->base.crtc) | |
12601 | continue; | |
12602 | ||
12603 | tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe; | |
e2c719b7 | 12604 | I915_STATE_WARN(active && pipe != tracked_pipe, |
8af6cf88 DV |
12605 | "active encoder's pipe doesn't match" |
12606 | "(expected %i, found %i)\n", | |
12607 | tracked_pipe, pipe); | |
12608 | ||
12609 | } | |
91d1b4bd DV |
12610 | } |
12611 | ||
12612 | static void | |
12613 | check_crtc_state(struct drm_device *dev) | |
12614 | { | |
fbee40df | 12615 | struct drm_i915_private *dev_priv = dev->dev_private; |
91d1b4bd DV |
12616 | struct intel_crtc *crtc; |
12617 | struct intel_encoder *encoder; | |
5cec258b | 12618 | struct intel_crtc_state pipe_config; |
8af6cf88 | 12619 | |
d3fcc808 | 12620 | for_each_intel_crtc(dev, crtc) { |
8af6cf88 DV |
12621 | bool enabled = false; |
12622 | bool active = false; | |
12623 | ||
045ac3b5 JB |
12624 | memset(&pipe_config, 0, sizeof(pipe_config)); |
12625 | ||
8af6cf88 DV |
12626 | DRM_DEBUG_KMS("[CRTC:%d]\n", |
12627 | crtc->base.base.id); | |
12628 | ||
83d65738 | 12629 | I915_STATE_WARN(crtc->active && !crtc->base.state->enable, |
8af6cf88 DV |
12630 | "active crtc, but not enabled in sw tracking\n"); |
12631 | ||
b2784e15 | 12632 | for_each_intel_encoder(dev, encoder) { |
8af6cf88 DV |
12633 | if (encoder->base.crtc != &crtc->base) |
12634 | continue; | |
12635 | enabled = true; | |
12636 | if (encoder->connectors_active) | |
12637 | active = true; | |
12638 | } | |
6c49f241 | 12639 | |
e2c719b7 | 12640 | I915_STATE_WARN(active != crtc->active, |
8af6cf88 DV |
12641 | "crtc's computed active state doesn't match tracked active state " |
12642 | "(expected %i, found %i)\n", active, crtc->active); | |
83d65738 | 12643 | I915_STATE_WARN(enabled != crtc->base.state->enable, |
8af6cf88 | 12644 | "crtc's computed enabled state doesn't match tracked enabled state " |
83d65738 MR |
12645 | "(expected %i, found %i)\n", enabled, |
12646 | crtc->base.state->enable); | |
8af6cf88 | 12647 | |
0e8ffe1b DV |
12648 | active = dev_priv->display.get_pipe_config(crtc, |
12649 | &pipe_config); | |
d62cf62a | 12650 | |
b6b5d049 VS |
12651 | /* hw state is inconsistent with the pipe quirk */ |
12652 | if ((crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || | |
12653 | (crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
d62cf62a DV |
12654 | active = crtc->active; |
12655 | ||
b2784e15 | 12656 | for_each_intel_encoder(dev, encoder) { |
3eaba51c | 12657 | enum pipe pipe; |
6c49f241 DV |
12658 | if (encoder->base.crtc != &crtc->base) |
12659 | continue; | |
1d37b689 | 12660 | if (encoder->get_hw_state(encoder, &pipe)) |
6c49f241 DV |
12661 | encoder->get_config(encoder, &pipe_config); |
12662 | } | |
12663 | ||
e2c719b7 | 12664 | I915_STATE_WARN(crtc->active != active, |
0e8ffe1b DV |
12665 | "crtc active state doesn't match with hw state " |
12666 | "(expected %i, found %i)\n", crtc->active, active); | |
12667 | ||
53d9f4e9 ML |
12668 | I915_STATE_WARN(crtc->active != crtc->base.state->active, |
12669 | "transitional active state does not match atomic hw state " | |
12670 | "(expected %i, found %i)\n", crtc->base.state->active, crtc->active); | |
12671 | ||
c0b03411 | 12672 | if (active && |
6e3c9717 | 12673 | !intel_pipe_config_compare(dev, crtc->config, &pipe_config)) { |
e2c719b7 | 12674 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); |
c0b03411 DV |
12675 | intel_dump_pipe_config(crtc, &pipe_config, |
12676 | "[hw state]"); | |
6e3c9717 | 12677 | intel_dump_pipe_config(crtc, crtc->config, |
c0b03411 DV |
12678 | "[sw state]"); |
12679 | } | |
8af6cf88 DV |
12680 | } |
12681 | } | |
12682 | ||
91d1b4bd DV |
12683 | static void |
12684 | check_shared_dpll_state(struct drm_device *dev) | |
12685 | { | |
fbee40df | 12686 | struct drm_i915_private *dev_priv = dev->dev_private; |
91d1b4bd DV |
12687 | struct intel_crtc *crtc; |
12688 | struct intel_dpll_hw_state dpll_hw_state; | |
12689 | int i; | |
5358901f DV |
12690 | |
12691 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { | |
12692 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
12693 | int enabled_crtcs = 0, active_crtcs = 0; | |
12694 | bool active; | |
12695 | ||
12696 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); | |
12697 | ||
12698 | DRM_DEBUG_KMS("%s\n", pll->name); | |
12699 | ||
12700 | active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state); | |
12701 | ||
e2c719b7 | 12702 | I915_STATE_WARN(pll->active > hweight32(pll->config.crtc_mask), |
5358901f | 12703 | "more active pll users than references: %i vs %i\n", |
3e369b76 | 12704 | pll->active, hweight32(pll->config.crtc_mask)); |
e2c719b7 | 12705 | I915_STATE_WARN(pll->active && !pll->on, |
5358901f | 12706 | "pll in active use but not on in sw tracking\n"); |
e2c719b7 | 12707 | I915_STATE_WARN(pll->on && !pll->active, |
35c95375 | 12708 | "pll in on but not on in use in sw tracking\n"); |
e2c719b7 | 12709 | I915_STATE_WARN(pll->on != active, |
5358901f DV |
12710 | "pll on state mismatch (expected %i, found %i)\n", |
12711 | pll->on, active); | |
12712 | ||
d3fcc808 | 12713 | for_each_intel_crtc(dev, crtc) { |
83d65738 | 12714 | if (crtc->base.state->enable && intel_crtc_to_shared_dpll(crtc) == pll) |
5358901f DV |
12715 | enabled_crtcs++; |
12716 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) | |
12717 | active_crtcs++; | |
12718 | } | |
e2c719b7 | 12719 | I915_STATE_WARN(pll->active != active_crtcs, |
5358901f DV |
12720 | "pll active crtcs mismatch (expected %i, found %i)\n", |
12721 | pll->active, active_crtcs); | |
e2c719b7 | 12722 | I915_STATE_WARN(hweight32(pll->config.crtc_mask) != enabled_crtcs, |
5358901f | 12723 | "pll enabled crtcs mismatch (expected %i, found %i)\n", |
3e369b76 | 12724 | hweight32(pll->config.crtc_mask), enabled_crtcs); |
66e985c0 | 12725 | |
e2c719b7 | 12726 | I915_STATE_WARN(pll->on && memcmp(&pll->config.hw_state, &dpll_hw_state, |
66e985c0 DV |
12727 | sizeof(dpll_hw_state)), |
12728 | "pll hw state mismatch\n"); | |
5358901f | 12729 | } |
8af6cf88 DV |
12730 | } |
12731 | ||
91d1b4bd DV |
12732 | void |
12733 | intel_modeset_check_state(struct drm_device *dev) | |
12734 | { | |
08db6652 | 12735 | check_wm_state(dev); |
91d1b4bd DV |
12736 | check_connector_state(dev); |
12737 | check_encoder_state(dev); | |
12738 | check_crtc_state(dev); | |
12739 | check_shared_dpll_state(dev); | |
12740 | } | |
12741 | ||
5cec258b | 12742 | void ironlake_check_encoder_dotclock(const struct intel_crtc_state *pipe_config, |
18442d08 VS |
12743 | int dotclock) |
12744 | { | |
12745 | /* | |
12746 | * FDI already provided one idea for the dotclock. | |
12747 | * Yell if the encoder disagrees. | |
12748 | */ | |
2d112de7 | 12749 | WARN(!intel_fuzzy_clock_check(pipe_config->base.adjusted_mode.crtc_clock, dotclock), |
18442d08 | 12750 | "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", |
2d112de7 | 12751 | pipe_config->base.adjusted_mode.crtc_clock, dotclock); |
18442d08 VS |
12752 | } |
12753 | ||
80715b2f VS |
12754 | static void update_scanline_offset(struct intel_crtc *crtc) |
12755 | { | |
12756 | struct drm_device *dev = crtc->base.dev; | |
12757 | ||
12758 | /* | |
12759 | * The scanline counter increments at the leading edge of hsync. | |
12760 | * | |
12761 | * On most platforms it starts counting from vtotal-1 on the | |
12762 | * first active line. That means the scanline counter value is | |
12763 | * always one less than what we would expect. Ie. just after | |
12764 | * start of vblank, which also occurs at start of hsync (on the | |
12765 | * last active line), the scanline counter will read vblank_start-1. | |
12766 | * | |
12767 | * On gen2 the scanline counter starts counting from 1 instead | |
12768 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 | |
12769 | * to keep the value positive), instead of adding one. | |
12770 | * | |
12771 | * On HSW+ the behaviour of the scanline counter depends on the output | |
12772 | * type. For DP ports it behaves like most other platforms, but on HDMI | |
12773 | * there's an extra 1 line difference. So we need to add two instead of | |
12774 | * one to the value. | |
12775 | */ | |
12776 | if (IS_GEN2(dev)) { | |
6e3c9717 | 12777 | const struct drm_display_mode *mode = &crtc->config->base.adjusted_mode; |
80715b2f VS |
12778 | int vtotal; |
12779 | ||
12780 | vtotal = mode->crtc_vtotal; | |
12781 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) | |
12782 | vtotal /= 2; | |
12783 | ||
12784 | crtc->scanline_offset = vtotal - 1; | |
12785 | } else if (HAS_DDI(dev) && | |
409ee761 | 12786 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) { |
80715b2f VS |
12787 | crtc->scanline_offset = 2; |
12788 | } else | |
12789 | crtc->scanline_offset = 1; | |
12790 | } | |
12791 | ||
c347a676 | 12792 | static int intel_modeset_setup_plls(struct drm_atomic_state *state) |
ed6739ef | 12793 | { |
225da59b | 12794 | struct drm_device *dev = state->dev; |
ed6739ef | 12795 | struct drm_i915_private *dev_priv = to_i915(dev); |
0a9ab303 | 12796 | unsigned clear_pipes = 0; |
ed6739ef | 12797 | struct intel_crtc *intel_crtc; |
0a9ab303 ACO |
12798 | struct intel_crtc_state *intel_crtc_state; |
12799 | struct drm_crtc *crtc; | |
12800 | struct drm_crtc_state *crtc_state; | |
ed6739ef | 12801 | int ret = 0; |
0a9ab303 | 12802 | int i; |
ed6739ef ACO |
12803 | |
12804 | if (!dev_priv->display.crtc_compute_clock) | |
12805 | return 0; | |
12806 | ||
0a9ab303 ACO |
12807 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
12808 | intel_crtc = to_intel_crtc(crtc); | |
4978cc93 | 12809 | intel_crtc_state = to_intel_crtc_state(crtc_state); |
0a9ab303 | 12810 | |
4978cc93 | 12811 | if (needs_modeset(crtc_state)) { |
0a9ab303 | 12812 | clear_pipes |= 1 << intel_crtc->pipe; |
4978cc93 | 12813 | intel_crtc_state->shared_dpll = DPLL_ID_PRIVATE; |
4978cc93 | 12814 | } |
0a9ab303 ACO |
12815 | } |
12816 | ||
de419ab6 ML |
12817 | if (clear_pipes) { |
12818 | struct intel_shared_dpll_config *shared_dpll = | |
12819 | intel_atomic_get_shared_dpll_state(state); | |
12820 | ||
12821 | for (i = 0; i < dev_priv->num_shared_dpll; i++) | |
12822 | shared_dpll[i].crtc_mask &= ~clear_pipes; | |
12823 | } | |
ed6739ef | 12824 | |
0a9ab303 ACO |
12825 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
12826 | if (!needs_modeset(crtc_state) || !crtc_state->enable) | |
225da59b ACO |
12827 | continue; |
12828 | ||
0a9ab303 ACO |
12829 | intel_crtc = to_intel_crtc(crtc); |
12830 | intel_crtc_state = to_intel_crtc_state(crtc_state); | |
12831 | ||
ed6739ef | 12832 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, |
0a9ab303 | 12833 | intel_crtc_state); |
de419ab6 ML |
12834 | if (ret) |
12835 | return ret; | |
ed6739ef ACO |
12836 | } |
12837 | ||
ed6739ef ACO |
12838 | return ret; |
12839 | } | |
12840 | ||
99d736a2 ML |
12841 | /* |
12842 | * This implements the workaround described in the "notes" section of the mode | |
12843 | * set sequence documentation. When going from no pipes or single pipe to | |
12844 | * multiple pipes, and planes are enabled after the pipe, we need to wait at | |
12845 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. | |
12846 | */ | |
12847 | static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state) | |
12848 | { | |
12849 | struct drm_crtc_state *crtc_state; | |
12850 | struct intel_crtc *intel_crtc; | |
12851 | struct drm_crtc *crtc; | |
12852 | struct intel_crtc_state *first_crtc_state = NULL; | |
12853 | struct intel_crtc_state *other_crtc_state = NULL; | |
12854 | enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE; | |
12855 | int i; | |
12856 | ||
12857 | /* look at all crtc's that are going to be enabled in during modeset */ | |
12858 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
12859 | intel_crtc = to_intel_crtc(crtc); | |
12860 | ||
12861 | if (!crtc_state->active || !needs_modeset(crtc_state)) | |
12862 | continue; | |
12863 | ||
12864 | if (first_crtc_state) { | |
12865 | other_crtc_state = to_intel_crtc_state(crtc_state); | |
12866 | break; | |
12867 | } else { | |
12868 | first_crtc_state = to_intel_crtc_state(crtc_state); | |
12869 | first_pipe = intel_crtc->pipe; | |
12870 | } | |
12871 | } | |
12872 | ||
12873 | /* No workaround needed? */ | |
12874 | if (!first_crtc_state) | |
12875 | return 0; | |
12876 | ||
12877 | /* w/a possibly needed, check how many crtc's are already enabled. */ | |
12878 | for_each_intel_crtc(state->dev, intel_crtc) { | |
12879 | struct intel_crtc_state *pipe_config; | |
12880 | ||
12881 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); | |
12882 | if (IS_ERR(pipe_config)) | |
12883 | return PTR_ERR(pipe_config); | |
12884 | ||
12885 | pipe_config->hsw_workaround_pipe = INVALID_PIPE; | |
12886 | ||
12887 | if (!pipe_config->base.active || | |
12888 | needs_modeset(&pipe_config->base)) | |
12889 | continue; | |
12890 | ||
12891 | /* 2 or more enabled crtcs means no need for w/a */ | |
12892 | if (enabled_pipe != INVALID_PIPE) | |
12893 | return 0; | |
12894 | ||
12895 | enabled_pipe = intel_crtc->pipe; | |
12896 | } | |
12897 | ||
12898 | if (enabled_pipe != INVALID_PIPE) | |
12899 | first_crtc_state->hsw_workaround_pipe = enabled_pipe; | |
12900 | else if (other_crtc_state) | |
12901 | other_crtc_state->hsw_workaround_pipe = first_pipe; | |
12902 | ||
12903 | return 0; | |
12904 | } | |
12905 | ||
054518dd | 12906 | /* Code that should eventually be part of atomic_check() */ |
c347a676 | 12907 | static int intel_modeset_checks(struct drm_atomic_state *state) |
054518dd ACO |
12908 | { |
12909 | struct drm_device *dev = state->dev; | |
12910 | int ret; | |
12911 | ||
b359283a ML |
12912 | if (!check_digital_port_conflicts(state)) { |
12913 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); | |
12914 | return -EINVAL; | |
12915 | } | |
12916 | ||
054518dd ACO |
12917 | /* |
12918 | * See if the config requires any additional preparation, e.g. | |
12919 | * to adjust global state with pipes off. We need to do this | |
12920 | * here so we can get the modeset_pipe updated config for the new | |
12921 | * mode set on this crtc. For other crtcs we need to use the | |
12922 | * adjusted_mode bits in the crtc directly. | |
12923 | */ | |
b432e5cf VS |
12924 | if (IS_VALLEYVIEW(dev) || IS_BROXTON(dev) || IS_BROADWELL(dev)) { |
12925 | if (IS_VALLEYVIEW(dev) || IS_BROXTON(dev)) | |
12926 | ret = valleyview_modeset_global_pipes(state); | |
12927 | else | |
12928 | ret = broadwell_modeset_global_pipes(state); | |
12929 | ||
054518dd ACO |
12930 | if (ret) |
12931 | return ret; | |
12932 | } | |
12933 | ||
99d736a2 | 12934 | ret = intel_modeset_setup_plls(state); |
054518dd ACO |
12935 | if (ret) |
12936 | return ret; | |
12937 | ||
99d736a2 ML |
12938 | if (IS_HASWELL(dev)) |
12939 | ret = haswell_mode_set_planes_workaround(state); | |
12940 | ||
12941 | return ret; | |
c347a676 ACO |
12942 | } |
12943 | ||
12944 | static int | |
12945 | intel_modeset_compute_config(struct drm_atomic_state *state) | |
12946 | { | |
12947 | struct drm_crtc *crtc; | |
12948 | struct drm_crtc_state *crtc_state; | |
12949 | int ret, i; | |
12950 | ||
12951 | ret = drm_atomic_helper_check_modeset(state->dev, state); | |
054518dd ACO |
12952 | if (ret) |
12953 | return ret; | |
12954 | ||
c347a676 ACO |
12955 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
12956 | if (!crtc_state->enable && | |
12957 | WARN_ON(crtc_state->active)) | |
12958 | crtc_state->active = false; | |
12959 | ||
12960 | if (!crtc_state->enable) | |
12961 | continue; | |
12962 | ||
b359283a ML |
12963 | if (!needs_modeset(crtc_state)) { |
12964 | ret = drm_atomic_add_affected_connectors(state, crtc); | |
12965 | if (ret) | |
12966 | return ret; | |
12967 | } | |
12968 | ||
12969 | ret = intel_modeset_pipe_config(crtc, | |
12970 | to_intel_crtc_state(crtc_state)); | |
c347a676 ACO |
12971 | if (ret) |
12972 | return ret; | |
12973 | ||
12974 | intel_dump_pipe_config(to_intel_crtc(crtc), | |
12975 | to_intel_crtc_state(crtc_state), | |
12976 | "[modeset]"); | |
12977 | } | |
12978 | ||
12979 | ret = intel_modeset_checks(state); | |
12980 | if (ret) | |
12981 | return ret; | |
12982 | ||
12983 | return drm_atomic_helper_check_planes(state->dev, state); | |
054518dd ACO |
12984 | } |
12985 | ||
c72d969b | 12986 | static int __intel_set_mode(struct drm_atomic_state *state) |
a6778b3c | 12987 | { |
c72d969b | 12988 | struct drm_device *dev = state->dev; |
fbee40df | 12989 | struct drm_i915_private *dev_priv = dev->dev_private; |
0a9ab303 ACO |
12990 | struct drm_crtc *crtc; |
12991 | struct drm_crtc_state *crtc_state; | |
c0c36b94 | 12992 | int ret = 0; |
0a9ab303 | 12993 | int i; |
a6778b3c | 12994 | |
d4afb8cc ACO |
12995 | ret = drm_atomic_helper_prepare_planes(dev, state); |
12996 | if (ret) | |
12997 | return ret; | |
12998 | ||
1c5e19f8 ML |
12999 | drm_atomic_helper_swap_state(dev, state); |
13000 | ||
0a9ab303 | 13001 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
1c5e19f8 | 13002 | if (!needs_modeset(crtc->state) || !crtc_state->active) |
0a9ab303 | 13003 | continue; |
460da916 | 13004 | |
69024de8 ML |
13005 | intel_crtc_disable_planes(crtc); |
13006 | dev_priv->display.crtc_disable(crtc); | |
b8cecdf5 | 13007 | } |
7758a113 | 13008 | |
ea9d758d DV |
13009 | /* Only after disabling all output pipelines that will be changed can we |
13010 | * update the the output configuration. */ | |
0a9ab303 | 13011 | intel_modeset_update_state(state); |
f6e5b160 | 13012 | |
a821fc46 ACO |
13013 | /* The state has been swaped above, so state actually contains the |
13014 | * old state now. */ | |
13015 | ||
304603f4 | 13016 | modeset_update_crtc_power_domains(state); |
47fab737 | 13017 | |
a6778b3c | 13018 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
0a9ab303 | 13019 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
5ac1c4bc ML |
13020 | drm_atomic_helper_commit_planes_on_crtc(crtc_state); |
13021 | ||
53d9f4e9 | 13022 | if (!needs_modeset(crtc->state) || !crtc->state->active) |
0a9ab303 ACO |
13023 | continue; |
13024 | ||
13025 | update_scanline_offset(to_intel_crtc(crtc)); | |
80715b2f | 13026 | |
0a9ab303 ACO |
13027 | dev_priv->display.crtc_enable(crtc); |
13028 | intel_crtc_enable_planes(crtc); | |
80715b2f | 13029 | } |
a6778b3c | 13030 | |
a6778b3c | 13031 | /* FIXME: add subpixel order */ |
83a57153 | 13032 | |
d4afb8cc ACO |
13033 | drm_atomic_helper_cleanup_planes(dev, state); |
13034 | ||
2bfb4627 ACO |
13035 | drm_atomic_state_free(state); |
13036 | ||
9eb45f22 | 13037 | return 0; |
f6e5b160 CW |
13038 | } |
13039 | ||
568c634a | 13040 | static int intel_set_mode_checked(struct drm_atomic_state *state) |
f30da187 | 13041 | { |
568c634a | 13042 | struct drm_device *dev = state->dev; |
f30da187 DV |
13043 | int ret; |
13044 | ||
568c634a | 13045 | ret = __intel_set_mode(state); |
f30da187 | 13046 | if (ret == 0) |
568c634a | 13047 | intel_modeset_check_state(dev); |
f30da187 DV |
13048 | |
13049 | return ret; | |
13050 | } | |
13051 | ||
568c634a | 13052 | static int intel_set_mode(struct drm_atomic_state *state) |
7f27126e | 13053 | { |
568c634a | 13054 | int ret; |
83a57153 | 13055 | |
568c634a | 13056 | ret = intel_modeset_compute_config(state); |
83a57153 | 13057 | if (ret) |
568c634a | 13058 | return ret; |
7f27126e | 13059 | |
568c634a | 13060 | return intel_set_mode_checked(state); |
7f27126e JB |
13061 | } |
13062 | ||
c0c36b94 CW |
13063 | void intel_crtc_restore_mode(struct drm_crtc *crtc) |
13064 | { | |
83a57153 ACO |
13065 | struct drm_device *dev = crtc->dev; |
13066 | struct drm_atomic_state *state; | |
4be07317 | 13067 | struct intel_crtc *intel_crtc; |
83a57153 ACO |
13068 | struct intel_encoder *encoder; |
13069 | struct intel_connector *connector; | |
13070 | struct drm_connector_state *connector_state; | |
4be07317 | 13071 | struct intel_crtc_state *crtc_state; |
2bfb4627 | 13072 | int ret; |
83a57153 ACO |
13073 | |
13074 | state = drm_atomic_state_alloc(dev); | |
13075 | if (!state) { | |
13076 | DRM_DEBUG_KMS("[CRTC:%d] mode restore failed, out of memory", | |
13077 | crtc->base.id); | |
13078 | return; | |
13079 | } | |
13080 | ||
13081 | state->acquire_ctx = dev->mode_config.acquire_ctx; | |
13082 | ||
13083 | /* The force restore path in the HW readout code relies on the staged | |
13084 | * config still keeping the user requested config while the actual | |
13085 | * state has been overwritten by the configuration read from HW. We | |
13086 | * need to copy the staged config to the atomic state, otherwise the | |
13087 | * mode set will just reapply the state the HW is already in. */ | |
13088 | for_each_intel_encoder(dev, encoder) { | |
13089 | if (&encoder->new_crtc->base != crtc) | |
13090 | continue; | |
13091 | ||
13092 | for_each_intel_connector(dev, connector) { | |
13093 | if (connector->new_encoder != encoder) | |
13094 | continue; | |
13095 | ||
13096 | connector_state = drm_atomic_get_connector_state(state, &connector->base); | |
13097 | if (IS_ERR(connector_state)) { | |
13098 | DRM_DEBUG_KMS("Failed to add [CONNECTOR:%d:%s] to state: %ld\n", | |
13099 | connector->base.base.id, | |
13100 | connector->base.name, | |
13101 | PTR_ERR(connector_state)); | |
13102 | continue; | |
13103 | } | |
13104 | ||
13105 | connector_state->crtc = crtc; | |
13106 | connector_state->best_encoder = &encoder->base; | |
13107 | } | |
13108 | } | |
13109 | ||
4be07317 ACO |
13110 | for_each_intel_crtc(dev, intel_crtc) { |
13111 | if (intel_crtc->new_enabled == intel_crtc->base.enabled) | |
13112 | continue; | |
13113 | ||
13114 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); | |
13115 | if (IS_ERR(crtc_state)) { | |
13116 | DRM_DEBUG_KMS("Failed to add [CRTC:%d] to state: %ld\n", | |
13117 | intel_crtc->base.base.id, | |
13118 | PTR_ERR(crtc_state)); | |
13119 | continue; | |
13120 | } | |
13121 | ||
49d6fa21 ML |
13122 | crtc_state->base.active = crtc_state->base.enable = |
13123 | intel_crtc->new_enabled; | |
8c7b5ccb ACO |
13124 | |
13125 | if (&intel_crtc->base == crtc) | |
13126 | drm_mode_copy(&crtc_state->base.mode, &crtc->mode); | |
4be07317 ACO |
13127 | } |
13128 | ||
d3a40d1b ACO |
13129 | intel_modeset_setup_plane_state(state, crtc, &crtc->mode, |
13130 | crtc->primary->fb, crtc->x, crtc->y); | |
13131 | ||
568c634a | 13132 | ret = intel_set_mode(state); |
2bfb4627 ACO |
13133 | if (ret) |
13134 | drm_atomic_state_free(state); | |
c0c36b94 CW |
13135 | } |
13136 | ||
25c5b266 DV |
13137 | #undef for_each_intel_crtc_masked |
13138 | ||
b7885264 ACO |
13139 | static bool intel_connector_in_mode_set(struct intel_connector *connector, |
13140 | struct drm_mode_set *set) | |
13141 | { | |
13142 | int ro; | |
13143 | ||
13144 | for (ro = 0; ro < set->num_connectors; ro++) | |
13145 | if (set->connectors[ro] == &connector->base) | |
13146 | return true; | |
13147 | ||
13148 | return false; | |
13149 | } | |
13150 | ||
2e431051 | 13151 | static int |
9a935856 DV |
13152 | intel_modeset_stage_output_state(struct drm_device *dev, |
13153 | struct drm_mode_set *set, | |
944b0c76 | 13154 | struct drm_atomic_state *state) |
50f56119 | 13155 | { |
9a935856 | 13156 | struct intel_connector *connector; |
d5432a9d | 13157 | struct drm_connector *drm_connector; |
944b0c76 | 13158 | struct drm_connector_state *connector_state; |
d5432a9d ACO |
13159 | struct drm_crtc *crtc; |
13160 | struct drm_crtc_state *crtc_state; | |
13161 | int i, ret; | |
50f56119 | 13162 | |
9abdda74 | 13163 | /* The upper layers ensure that we either disable a crtc or have a list |
9a935856 DV |
13164 | * of connectors. For paranoia, double-check this. */ |
13165 | WARN_ON(!set->fb && (set->num_connectors != 0)); | |
13166 | WARN_ON(set->fb && (set->num_connectors == 0)); | |
13167 | ||
3a3371ff | 13168 | for_each_intel_connector(dev, connector) { |
b7885264 ACO |
13169 | bool in_mode_set = intel_connector_in_mode_set(connector, set); |
13170 | ||
d5432a9d ACO |
13171 | if (!in_mode_set && connector->base.state->crtc != set->crtc) |
13172 | continue; | |
13173 | ||
13174 | connector_state = | |
13175 | drm_atomic_get_connector_state(state, &connector->base); | |
13176 | if (IS_ERR(connector_state)) | |
13177 | return PTR_ERR(connector_state); | |
13178 | ||
b7885264 ACO |
13179 | if (in_mode_set) { |
13180 | int pipe = to_intel_crtc(set->crtc)->pipe; | |
d5432a9d ACO |
13181 | connector_state->best_encoder = |
13182 | &intel_find_encoder(connector, pipe)->base; | |
50f56119 DV |
13183 | } |
13184 | ||
d5432a9d | 13185 | if (connector->base.state->crtc != set->crtc) |
b7885264 ACO |
13186 | continue; |
13187 | ||
9a935856 DV |
13188 | /* If we disable the crtc, disable all its connectors. Also, if |
13189 | * the connector is on the changing crtc but not on the new | |
13190 | * connector list, disable it. */ | |
b7885264 | 13191 | if (!set->fb || !in_mode_set) { |
d5432a9d | 13192 | connector_state->best_encoder = NULL; |
9a935856 DV |
13193 | |
13194 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n", | |
13195 | connector->base.base.id, | |
c23cc417 | 13196 | connector->base.name); |
9a935856 | 13197 | } |
50f56119 | 13198 | } |
9a935856 | 13199 | /* connector->new_encoder is now updated for all connectors. */ |
50f56119 | 13200 | |
d5432a9d ACO |
13201 | for_each_connector_in_state(state, drm_connector, connector_state, i) { |
13202 | connector = to_intel_connector(drm_connector); | |
13203 | ||
13204 | if (!connector_state->best_encoder) { | |
13205 | ret = drm_atomic_set_crtc_for_connector(connector_state, | |
13206 | NULL); | |
13207 | if (ret) | |
13208 | return ret; | |
7668851f | 13209 | |
50f56119 | 13210 | continue; |
d5432a9d | 13211 | } |
50f56119 | 13212 | |
d5432a9d ACO |
13213 | if (intel_connector_in_mode_set(connector, set)) { |
13214 | struct drm_crtc *crtc = connector->base.state->crtc; | |
13215 | ||
13216 | /* If this connector was in a previous crtc, add it | |
13217 | * to the state. We might need to disable it. */ | |
13218 | if (crtc) { | |
13219 | crtc_state = | |
13220 | drm_atomic_get_crtc_state(state, crtc); | |
13221 | if (IS_ERR(crtc_state)) | |
13222 | return PTR_ERR(crtc_state); | |
13223 | } | |
13224 | ||
13225 | ret = drm_atomic_set_crtc_for_connector(connector_state, | |
13226 | set->crtc); | |
13227 | if (ret) | |
13228 | return ret; | |
13229 | } | |
50f56119 DV |
13230 | |
13231 | /* Make sure the new CRTC will work with the encoder */ | |
d5432a9d ACO |
13232 | if (!drm_encoder_crtc_ok(connector_state->best_encoder, |
13233 | connector_state->crtc)) { | |
5e2b584e | 13234 | return -EINVAL; |
50f56119 | 13235 | } |
944b0c76 | 13236 | |
9a935856 DV |
13237 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n", |
13238 | connector->base.base.id, | |
c23cc417 | 13239 | connector->base.name, |
d5432a9d | 13240 | connector_state->crtc->base.id); |
944b0c76 | 13241 | |
d5432a9d ACO |
13242 | if (connector_state->best_encoder != &connector->encoder->base) |
13243 | connector->encoder = | |
13244 | to_intel_encoder(connector_state->best_encoder); | |
0e32b39c | 13245 | } |
7668851f | 13246 | |
d5432a9d | 13247 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
49d6fa21 ML |
13248 | bool has_connectors; |
13249 | ||
d5432a9d ACO |
13250 | ret = drm_atomic_add_affected_connectors(state, crtc); |
13251 | if (ret) | |
13252 | return ret; | |
4be07317 | 13253 | |
49d6fa21 ML |
13254 | has_connectors = !!drm_atomic_connectors_for_crtc(state, crtc); |
13255 | if (has_connectors != crtc_state->enable) | |
13256 | crtc_state->enable = | |
13257 | crtc_state->active = has_connectors; | |
7668851f VS |
13258 | } |
13259 | ||
8c7b5ccb ACO |
13260 | ret = intel_modeset_setup_plane_state(state, set->crtc, set->mode, |
13261 | set->fb, set->x, set->y); | |
13262 | if (ret) | |
13263 | return ret; | |
13264 | ||
13265 | crtc_state = drm_atomic_get_crtc_state(state, set->crtc); | |
13266 | if (IS_ERR(crtc_state)) | |
13267 | return PTR_ERR(crtc_state); | |
13268 | ||
ce52299c MR |
13269 | ret = drm_atomic_set_mode_for_crtc(crtc_state, set->mode); |
13270 | if (ret) | |
13271 | return ret; | |
8c7b5ccb ACO |
13272 | |
13273 | if (set->num_connectors) | |
13274 | crtc_state->active = true; | |
13275 | ||
2e431051 DV |
13276 | return 0; |
13277 | } | |
13278 | ||
13279 | static int intel_crtc_set_config(struct drm_mode_set *set) | |
13280 | { | |
13281 | struct drm_device *dev; | |
83a57153 | 13282 | struct drm_atomic_state *state = NULL; |
2e431051 | 13283 | int ret; |
2e431051 | 13284 | |
8d3e375e DV |
13285 | BUG_ON(!set); |
13286 | BUG_ON(!set->crtc); | |
13287 | BUG_ON(!set->crtc->helper_private); | |
2e431051 | 13288 | |
7e53f3a4 DV |
13289 | /* Enforce sane interface api - has been abused by the fb helper. */ |
13290 | BUG_ON(!set->mode && set->fb); | |
13291 | BUG_ON(set->fb && set->num_connectors == 0); | |
431e50f7 | 13292 | |
2e431051 DV |
13293 | if (set->fb) { |
13294 | DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n", | |
13295 | set->crtc->base.id, set->fb->base.id, | |
13296 | (int)set->num_connectors, set->x, set->y); | |
13297 | } else { | |
13298 | DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id); | |
2e431051 DV |
13299 | } |
13300 | ||
13301 | dev = set->crtc->dev; | |
13302 | ||
83a57153 | 13303 | state = drm_atomic_state_alloc(dev); |
7cbf41d6 ACO |
13304 | if (!state) |
13305 | return -ENOMEM; | |
83a57153 ACO |
13306 | |
13307 | state->acquire_ctx = dev->mode_config.acquire_ctx; | |
13308 | ||
462a425a | 13309 | ret = intel_modeset_stage_output_state(dev, set, state); |
2e431051 | 13310 | if (ret) |
7cbf41d6 | 13311 | goto out; |
2e431051 | 13312 | |
568c634a ACO |
13313 | ret = intel_modeset_compute_config(state); |
13314 | if (ret) | |
7cbf41d6 | 13315 | goto out; |
50f52756 | 13316 | |
1f9954d0 JB |
13317 | intel_update_pipe_size(to_intel_crtc(set->crtc)); |
13318 | ||
568c634a | 13319 | ret = intel_set_mode_checked(state); |
2d05eae1 | 13320 | if (ret) { |
bf67dfeb DV |
13321 | DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n", |
13322 | set->crtc->base.id, ret); | |
2d05eae1 | 13323 | } |
50f56119 | 13324 | |
7cbf41d6 | 13325 | out: |
2bfb4627 ACO |
13326 | if (ret) |
13327 | drm_atomic_state_free(state); | |
50f56119 DV |
13328 | return ret; |
13329 | } | |
f6e5b160 CW |
13330 | |
13331 | static const struct drm_crtc_funcs intel_crtc_funcs = { | |
f6e5b160 | 13332 | .gamma_set = intel_crtc_gamma_set, |
50f56119 | 13333 | .set_config = intel_crtc_set_config, |
f6e5b160 CW |
13334 | .destroy = intel_crtc_destroy, |
13335 | .page_flip = intel_crtc_page_flip, | |
1356837e MR |
13336 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
13337 | .atomic_destroy_state = intel_crtc_destroy_state, | |
f6e5b160 CW |
13338 | }; |
13339 | ||
5358901f DV |
13340 | static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv, |
13341 | struct intel_shared_dpll *pll, | |
13342 | struct intel_dpll_hw_state *hw_state) | |
ee7b9f93 | 13343 | { |
5358901f | 13344 | uint32_t val; |
ee7b9f93 | 13345 | |
f458ebbc | 13346 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS)) |
bd2bb1b9 PZ |
13347 | return false; |
13348 | ||
5358901f | 13349 | val = I915_READ(PCH_DPLL(pll->id)); |
66e985c0 DV |
13350 | hw_state->dpll = val; |
13351 | hw_state->fp0 = I915_READ(PCH_FP0(pll->id)); | |
13352 | hw_state->fp1 = I915_READ(PCH_FP1(pll->id)); | |
5358901f DV |
13353 | |
13354 | return val & DPLL_VCO_ENABLE; | |
13355 | } | |
13356 | ||
15bdd4cf DV |
13357 | static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv, |
13358 | struct intel_shared_dpll *pll) | |
13359 | { | |
3e369b76 ACO |
13360 | I915_WRITE(PCH_FP0(pll->id), pll->config.hw_state.fp0); |
13361 | I915_WRITE(PCH_FP1(pll->id), pll->config.hw_state.fp1); | |
15bdd4cf DV |
13362 | } |
13363 | ||
e7b903d2 DV |
13364 | static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv, |
13365 | struct intel_shared_dpll *pll) | |
13366 | { | |
e7b903d2 | 13367 | /* PCH refclock must be enabled first */ |
89eff4be | 13368 | ibx_assert_pch_refclk_enabled(dev_priv); |
e7b903d2 | 13369 | |
3e369b76 | 13370 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
15bdd4cf DV |
13371 | |
13372 | /* Wait for the clocks to stabilize. */ | |
13373 | POSTING_READ(PCH_DPLL(pll->id)); | |
13374 | udelay(150); | |
13375 | ||
13376 | /* The pixel multiplier can only be updated once the | |
13377 | * DPLL is enabled and the clocks are stable. | |
13378 | * | |
13379 | * So write it again. | |
13380 | */ | |
3e369b76 | 13381 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
15bdd4cf | 13382 | POSTING_READ(PCH_DPLL(pll->id)); |
e7b903d2 DV |
13383 | udelay(200); |
13384 | } | |
13385 | ||
13386 | static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv, | |
13387 | struct intel_shared_dpll *pll) | |
13388 | { | |
13389 | struct drm_device *dev = dev_priv->dev; | |
13390 | struct intel_crtc *crtc; | |
e7b903d2 DV |
13391 | |
13392 | /* Make sure no transcoder isn't still depending on us. */ | |
d3fcc808 | 13393 | for_each_intel_crtc(dev, crtc) { |
e7b903d2 DV |
13394 | if (intel_crtc_to_shared_dpll(crtc) == pll) |
13395 | assert_pch_transcoder_disabled(dev_priv, crtc->pipe); | |
ee7b9f93 JB |
13396 | } |
13397 | ||
15bdd4cf DV |
13398 | I915_WRITE(PCH_DPLL(pll->id), 0); |
13399 | POSTING_READ(PCH_DPLL(pll->id)); | |
e7b903d2 DV |
13400 | udelay(200); |
13401 | } | |
13402 | ||
46edb027 DV |
13403 | static char *ibx_pch_dpll_names[] = { |
13404 | "PCH DPLL A", | |
13405 | "PCH DPLL B", | |
13406 | }; | |
13407 | ||
7c74ade1 | 13408 | static void ibx_pch_dpll_init(struct drm_device *dev) |
ee7b9f93 | 13409 | { |
e7b903d2 | 13410 | struct drm_i915_private *dev_priv = dev->dev_private; |
ee7b9f93 JB |
13411 | int i; |
13412 | ||
7c74ade1 | 13413 | dev_priv->num_shared_dpll = 2; |
ee7b9f93 | 13414 | |
e72f9fbf | 13415 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
46edb027 DV |
13416 | dev_priv->shared_dplls[i].id = i; |
13417 | dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i]; | |
15bdd4cf | 13418 | dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set; |
e7b903d2 DV |
13419 | dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable; |
13420 | dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable; | |
5358901f DV |
13421 | dev_priv->shared_dplls[i].get_hw_state = |
13422 | ibx_pch_dpll_get_hw_state; | |
ee7b9f93 JB |
13423 | } |
13424 | } | |
13425 | ||
7c74ade1 DV |
13426 | static void intel_shared_dpll_init(struct drm_device *dev) |
13427 | { | |
e7b903d2 | 13428 | struct drm_i915_private *dev_priv = dev->dev_private; |
7c74ade1 | 13429 | |
b6283055 VS |
13430 | intel_update_cdclk(dev); |
13431 | ||
9cd86933 DV |
13432 | if (HAS_DDI(dev)) |
13433 | intel_ddi_pll_init(dev); | |
13434 | else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) | |
7c74ade1 DV |
13435 | ibx_pch_dpll_init(dev); |
13436 | else | |
13437 | dev_priv->num_shared_dpll = 0; | |
13438 | ||
13439 | BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS); | |
7c74ade1 DV |
13440 | } |
13441 | ||
1fc0a8f7 TU |
13442 | /** |
13443 | * intel_wm_need_update - Check whether watermarks need updating | |
13444 | * @plane: drm plane | |
13445 | * @state: new plane state | |
13446 | * | |
13447 | * Check current plane state versus the new one to determine whether | |
13448 | * watermarks need to be recalculated. | |
13449 | * | |
13450 | * Returns true or false. | |
13451 | */ | |
13452 | bool intel_wm_need_update(struct drm_plane *plane, | |
13453 | struct drm_plane_state *state) | |
13454 | { | |
13455 | /* Update watermarks on tiling changes. */ | |
13456 | if (!plane->state->fb || !state->fb || | |
13457 | plane->state->fb->modifier[0] != state->fb->modifier[0] || | |
13458 | plane->state->rotation != state->rotation) | |
13459 | return true; | |
13460 | ||
13461 | return false; | |
13462 | } | |
13463 | ||
6beb8c23 MR |
13464 | /** |
13465 | * intel_prepare_plane_fb - Prepare fb for usage on plane | |
13466 | * @plane: drm plane to prepare for | |
13467 | * @fb: framebuffer to prepare for presentation | |
13468 | * | |
13469 | * Prepares a framebuffer for usage on a display plane. Generally this | |
13470 | * involves pinning the underlying object and updating the frontbuffer tracking | |
13471 | * bits. Some older platforms need special physical address handling for | |
13472 | * cursor planes. | |
13473 | * | |
13474 | * Returns 0 on success, negative error code on failure. | |
13475 | */ | |
13476 | int | |
13477 | intel_prepare_plane_fb(struct drm_plane *plane, | |
d136dfee TU |
13478 | struct drm_framebuffer *fb, |
13479 | const struct drm_plane_state *new_state) | |
465c120c MR |
13480 | { |
13481 | struct drm_device *dev = plane->dev; | |
6beb8c23 MR |
13482 | struct intel_plane *intel_plane = to_intel_plane(plane); |
13483 | enum pipe pipe = intel_plane->pipe; | |
13484 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); | |
13485 | struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb); | |
13486 | unsigned frontbuffer_bits = 0; | |
13487 | int ret = 0; | |
465c120c | 13488 | |
ea2c67bb | 13489 | if (!obj) |
465c120c MR |
13490 | return 0; |
13491 | ||
6beb8c23 MR |
13492 | switch (plane->type) { |
13493 | case DRM_PLANE_TYPE_PRIMARY: | |
13494 | frontbuffer_bits = INTEL_FRONTBUFFER_PRIMARY(pipe); | |
13495 | break; | |
13496 | case DRM_PLANE_TYPE_CURSOR: | |
13497 | frontbuffer_bits = INTEL_FRONTBUFFER_CURSOR(pipe); | |
13498 | break; | |
13499 | case DRM_PLANE_TYPE_OVERLAY: | |
13500 | frontbuffer_bits = INTEL_FRONTBUFFER_SPRITE(pipe); | |
13501 | break; | |
13502 | } | |
465c120c | 13503 | |
6beb8c23 | 13504 | mutex_lock(&dev->struct_mutex); |
465c120c | 13505 | |
6beb8c23 MR |
13506 | if (plane->type == DRM_PLANE_TYPE_CURSOR && |
13507 | INTEL_INFO(dev)->cursor_needs_physical) { | |
13508 | int align = IS_I830(dev) ? 16 * 1024 : 256; | |
13509 | ret = i915_gem_object_attach_phys(obj, align); | |
13510 | if (ret) | |
13511 | DRM_DEBUG_KMS("failed to attach phys object\n"); | |
13512 | } else { | |
82bc3b2d | 13513 | ret = intel_pin_and_fence_fb_obj(plane, fb, new_state, NULL); |
6beb8c23 | 13514 | } |
465c120c | 13515 | |
6beb8c23 MR |
13516 | if (ret == 0) |
13517 | i915_gem_track_fb(old_obj, obj, frontbuffer_bits); | |
fdd508a6 | 13518 | |
4c34574f | 13519 | mutex_unlock(&dev->struct_mutex); |
465c120c | 13520 | |
6beb8c23 MR |
13521 | return ret; |
13522 | } | |
13523 | ||
38f3ce3a MR |
13524 | /** |
13525 | * intel_cleanup_plane_fb - Cleans up an fb after plane use | |
13526 | * @plane: drm plane to clean up for | |
13527 | * @fb: old framebuffer that was on plane | |
13528 | * | |
13529 | * Cleans up a framebuffer that has just been removed from a plane. | |
13530 | */ | |
13531 | void | |
13532 | intel_cleanup_plane_fb(struct drm_plane *plane, | |
d136dfee TU |
13533 | struct drm_framebuffer *fb, |
13534 | const struct drm_plane_state *old_state) | |
38f3ce3a MR |
13535 | { |
13536 | struct drm_device *dev = plane->dev; | |
13537 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); | |
13538 | ||
13539 | if (WARN_ON(!obj)) | |
13540 | return; | |
13541 | ||
13542 | if (plane->type != DRM_PLANE_TYPE_CURSOR || | |
13543 | !INTEL_INFO(dev)->cursor_needs_physical) { | |
13544 | mutex_lock(&dev->struct_mutex); | |
82bc3b2d | 13545 | intel_unpin_fb_obj(fb, old_state); |
38f3ce3a MR |
13546 | mutex_unlock(&dev->struct_mutex); |
13547 | } | |
465c120c MR |
13548 | } |
13549 | ||
6156a456 CK |
13550 | int |
13551 | skl_max_scale(struct intel_crtc *intel_crtc, struct intel_crtc_state *crtc_state) | |
13552 | { | |
13553 | int max_scale; | |
13554 | struct drm_device *dev; | |
13555 | struct drm_i915_private *dev_priv; | |
13556 | int crtc_clock, cdclk; | |
13557 | ||
13558 | if (!intel_crtc || !crtc_state) | |
13559 | return DRM_PLANE_HELPER_NO_SCALING; | |
13560 | ||
13561 | dev = intel_crtc->base.dev; | |
13562 | dev_priv = dev->dev_private; | |
13563 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; | |
13564 | cdclk = dev_priv->display.get_display_clock_speed(dev); | |
13565 | ||
13566 | if (!crtc_clock || !cdclk) | |
13567 | return DRM_PLANE_HELPER_NO_SCALING; | |
13568 | ||
13569 | /* | |
13570 | * skl max scale is lower of: | |
13571 | * close to 3 but not 3, -1 is for that purpose | |
13572 | * or | |
13573 | * cdclk/crtc_clock | |
13574 | */ | |
13575 | max_scale = min((1 << 16) * 3 - 1, (1 << 8) * ((cdclk << 8) / crtc_clock)); | |
13576 | ||
13577 | return max_scale; | |
13578 | } | |
13579 | ||
465c120c | 13580 | static int |
3c692a41 GP |
13581 | intel_check_primary_plane(struct drm_plane *plane, |
13582 | struct intel_plane_state *state) | |
13583 | { | |
32b7eeec MR |
13584 | struct drm_device *dev = plane->dev; |
13585 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2b875c22 | 13586 | struct drm_crtc *crtc = state->base.crtc; |
ea2c67bb | 13587 | struct intel_crtc *intel_crtc; |
6156a456 | 13588 | struct intel_crtc_state *crtc_state; |
2b875c22 | 13589 | struct drm_framebuffer *fb = state->base.fb; |
3c692a41 GP |
13590 | struct drm_rect *dest = &state->dst; |
13591 | struct drm_rect *src = &state->src; | |
13592 | const struct drm_rect *clip = &state->clip; | |
d8106366 | 13593 | bool can_position = false; |
6156a456 CK |
13594 | int max_scale = DRM_PLANE_HELPER_NO_SCALING; |
13595 | int min_scale = DRM_PLANE_HELPER_NO_SCALING; | |
465c120c MR |
13596 | int ret; |
13597 | ||
ea2c67bb MR |
13598 | crtc = crtc ? crtc : plane->crtc; |
13599 | intel_crtc = to_intel_crtc(crtc); | |
6156a456 CK |
13600 | crtc_state = state->base.state ? |
13601 | intel_atomic_get_crtc_state(state->base.state, intel_crtc) : NULL; | |
ea2c67bb | 13602 | |
6156a456 | 13603 | if (INTEL_INFO(dev)->gen >= 9) { |
225c228a CK |
13604 | /* use scaler when colorkey is not required */ |
13605 | if (to_intel_plane(plane)->ckey.flags == I915_SET_COLORKEY_NONE) { | |
13606 | min_scale = 1; | |
13607 | max_scale = skl_max_scale(intel_crtc, crtc_state); | |
13608 | } | |
d8106366 | 13609 | can_position = true; |
6156a456 | 13610 | } |
d8106366 | 13611 | |
c59cb179 MR |
13612 | ret = drm_plane_helper_check_update(plane, crtc, fb, |
13613 | src, dest, clip, | |
6156a456 CK |
13614 | min_scale, |
13615 | max_scale, | |
d8106366 SJ |
13616 | can_position, true, |
13617 | &state->visible); | |
c59cb179 MR |
13618 | if (ret) |
13619 | return ret; | |
465c120c | 13620 | |
32b7eeec | 13621 | if (intel_crtc->active) { |
b70709a6 ML |
13622 | struct intel_plane_state *old_state = |
13623 | to_intel_plane_state(plane->state); | |
13624 | ||
32b7eeec MR |
13625 | intel_crtc->atomic.wait_for_flips = true; |
13626 | ||
13627 | /* | |
13628 | * FBC does not work on some platforms for rotated | |
13629 | * planes, so disable it when rotation is not 0 and | |
13630 | * update it when rotation is set back to 0. | |
13631 | * | |
13632 | * FIXME: This is redundant with the fbc update done in | |
13633 | * the primary plane enable function except that that | |
13634 | * one is done too late. We eventually need to unify | |
13635 | * this. | |
13636 | */ | |
b70709a6 | 13637 | if (state->visible && |
32b7eeec | 13638 | INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) && |
e35fef21 | 13639 | dev_priv->fbc.crtc == intel_crtc && |
8e7d688b | 13640 | state->base.rotation != BIT(DRM_ROTATE_0)) { |
32b7eeec MR |
13641 | intel_crtc->atomic.disable_fbc = true; |
13642 | } | |
13643 | ||
b70709a6 | 13644 | if (state->visible && !old_state->visible) { |
32b7eeec MR |
13645 | /* |
13646 | * BDW signals flip done immediately if the plane | |
13647 | * is disabled, even if the plane enable is already | |
13648 | * armed to occur at the next vblank :( | |
13649 | */ | |
b70709a6 | 13650 | if (IS_BROADWELL(dev)) |
32b7eeec | 13651 | intel_crtc->atomic.wait_vblank = true; |
fb9d6cf8 ML |
13652 | |
13653 | if (crtc_state && !needs_modeset(&crtc_state->base)) | |
13654 | intel_crtc->atomic.post_enable_primary = true; | |
32b7eeec MR |
13655 | } |
13656 | ||
fb9d6cf8 ML |
13657 | if (!state->visible && old_state->visible && |
13658 | crtc_state && !needs_modeset(&crtc_state->base)) | |
13659 | intel_crtc->atomic.pre_disable_primary = true; | |
13660 | ||
32b7eeec MR |
13661 | intel_crtc->atomic.fb_bits |= |
13662 | INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe); | |
13663 | ||
13664 | intel_crtc->atomic.update_fbc = true; | |
0fda6568 | 13665 | |
1fc0a8f7 | 13666 | if (intel_wm_need_update(plane, &state->base)) |
0fda6568 | 13667 | intel_crtc->atomic.update_wm = true; |
ccc759dc GP |
13668 | } |
13669 | ||
6156a456 CK |
13670 | if (INTEL_INFO(dev)->gen >= 9) { |
13671 | ret = skl_update_scaler_users(intel_crtc, crtc_state, | |
13672 | to_intel_plane(plane), state, 0); | |
13673 | if (ret) | |
13674 | return ret; | |
13675 | } | |
13676 | ||
14af293f GP |
13677 | return 0; |
13678 | } | |
13679 | ||
13680 | static void | |
13681 | intel_commit_primary_plane(struct drm_plane *plane, | |
13682 | struct intel_plane_state *state) | |
13683 | { | |
2b875c22 MR |
13684 | struct drm_crtc *crtc = state->base.crtc; |
13685 | struct drm_framebuffer *fb = state->base.fb; | |
13686 | struct drm_device *dev = plane->dev; | |
14af293f | 13687 | struct drm_i915_private *dev_priv = dev->dev_private; |
ea2c67bb | 13688 | struct intel_crtc *intel_crtc; |
14af293f GP |
13689 | struct drm_rect *src = &state->src; |
13690 | ||
ea2c67bb MR |
13691 | crtc = crtc ? crtc : plane->crtc; |
13692 | intel_crtc = to_intel_crtc(crtc); | |
cf4c7c12 MR |
13693 | |
13694 | plane->fb = fb; | |
9dc806fc MR |
13695 | crtc->x = src->x1 >> 16; |
13696 | crtc->y = src->y1 >> 16; | |
ccc759dc | 13697 | |
ccc759dc | 13698 | if (intel_crtc->active) { |
27321ae8 | 13699 | if (state->visible) |
ccc759dc GP |
13700 | /* FIXME: kill this fastboot hack */ |
13701 | intel_update_pipe_size(intel_crtc); | |
465c120c | 13702 | |
27321ae8 ML |
13703 | dev_priv->display.update_primary_plane(crtc, plane->fb, |
13704 | crtc->x, crtc->y); | |
ccc759dc | 13705 | } |
465c120c MR |
13706 | } |
13707 | ||
a8ad0d8e ML |
13708 | static void |
13709 | intel_disable_primary_plane(struct drm_plane *plane, | |
13710 | struct drm_crtc *crtc, | |
13711 | bool force) | |
13712 | { | |
13713 | struct drm_device *dev = plane->dev; | |
13714 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13715 | ||
a8ad0d8e ML |
13716 | dev_priv->display.update_primary_plane(crtc, NULL, 0, 0); |
13717 | } | |
13718 | ||
32b7eeec | 13719 | static void intel_begin_crtc_commit(struct drm_crtc *crtc) |
3c692a41 | 13720 | { |
32b7eeec | 13721 | struct drm_device *dev = crtc->dev; |
140fd38d | 13722 | struct drm_i915_private *dev_priv = dev->dev_private; |
3c692a41 | 13723 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
5c2db188 | 13724 | struct drm_crtc_state *crtc_state = intel_crtc->base.state; |
ea2c67bb MR |
13725 | struct intel_plane *intel_plane; |
13726 | struct drm_plane *p; | |
13727 | unsigned fb_bits = 0; | |
13728 | ||
13729 | /* Track fb's for any planes being disabled */ | |
13730 | list_for_each_entry(p, &dev->mode_config.plane_list, head) { | |
13731 | intel_plane = to_intel_plane(p); | |
13732 | ||
13733 | if (intel_crtc->atomic.disabled_planes & | |
13734 | (1 << drm_plane_index(p))) { | |
13735 | switch (p->type) { | |
13736 | case DRM_PLANE_TYPE_PRIMARY: | |
13737 | fb_bits = INTEL_FRONTBUFFER_PRIMARY(intel_plane->pipe); | |
13738 | break; | |
13739 | case DRM_PLANE_TYPE_CURSOR: | |
13740 | fb_bits = INTEL_FRONTBUFFER_CURSOR(intel_plane->pipe); | |
13741 | break; | |
13742 | case DRM_PLANE_TYPE_OVERLAY: | |
13743 | fb_bits = INTEL_FRONTBUFFER_SPRITE(intel_plane->pipe); | |
13744 | break; | |
13745 | } | |
3c692a41 | 13746 | |
ea2c67bb MR |
13747 | mutex_lock(&dev->struct_mutex); |
13748 | i915_gem_track_fb(intel_fb_obj(p->fb), NULL, fb_bits); | |
13749 | mutex_unlock(&dev->struct_mutex); | |
13750 | } | |
13751 | } | |
3c692a41 | 13752 | |
32b7eeec MR |
13753 | if (intel_crtc->atomic.wait_for_flips) |
13754 | intel_crtc_wait_for_pending_flips(crtc); | |
3c692a41 | 13755 | |
32b7eeec MR |
13756 | if (intel_crtc->atomic.disable_fbc) |
13757 | intel_fbc_disable(dev); | |
3c692a41 | 13758 | |
32b7eeec MR |
13759 | if (intel_crtc->atomic.pre_disable_primary) |
13760 | intel_pre_disable_primary(crtc); | |
3c692a41 | 13761 | |
32b7eeec MR |
13762 | if (intel_crtc->atomic.update_wm) |
13763 | intel_update_watermarks(crtc); | |
3c692a41 | 13764 | |
32b7eeec | 13765 | intel_runtime_pm_get(dev_priv); |
3c692a41 | 13766 | |
c34c9ee4 | 13767 | /* Perform vblank evasion around commit operation */ |
5c2db188 | 13768 | if (crtc_state->active && !needs_modeset(crtc_state)) |
c34c9ee4 MR |
13769 | intel_crtc->atomic.evade = |
13770 | intel_pipe_update_start(intel_crtc, | |
13771 | &intel_crtc->atomic.start_vbl_count); | |
32b7eeec MR |
13772 | } |
13773 | ||
13774 | static void intel_finish_crtc_commit(struct drm_crtc *crtc) | |
13775 | { | |
13776 | struct drm_device *dev = crtc->dev; | |
13777 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13778 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
13779 | struct drm_plane *p; | |
13780 | ||
c34c9ee4 MR |
13781 | if (intel_crtc->atomic.evade) |
13782 | intel_pipe_update_end(intel_crtc, | |
13783 | intel_crtc->atomic.start_vbl_count); | |
3c692a41 | 13784 | |
140fd38d | 13785 | intel_runtime_pm_put(dev_priv); |
3c692a41 | 13786 | |
8a8f7f44 | 13787 | if (intel_crtc->atomic.wait_vblank && intel_crtc->active) |
32b7eeec MR |
13788 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
13789 | ||
13790 | intel_frontbuffer_flip(dev, intel_crtc->atomic.fb_bits); | |
13791 | ||
13792 | if (intel_crtc->atomic.update_fbc) { | |
ccc759dc | 13793 | mutex_lock(&dev->struct_mutex); |
7ff0ebcc | 13794 | intel_fbc_update(dev); |
ccc759dc | 13795 | mutex_unlock(&dev->struct_mutex); |
38f3ce3a | 13796 | } |
3c692a41 | 13797 | |
32b7eeec MR |
13798 | if (intel_crtc->atomic.post_enable_primary) |
13799 | intel_post_enable_primary(crtc); | |
3c692a41 | 13800 | |
32b7eeec MR |
13801 | drm_for_each_legacy_plane(p, &dev->mode_config.plane_list) |
13802 | if (intel_crtc->atomic.update_sprite_watermarks & drm_plane_index(p)) | |
13803 | intel_update_sprite_watermarks(p, crtc, 0, 0, 0, | |
13804 | false, false); | |
13805 | ||
13806 | memset(&intel_crtc->atomic, 0, sizeof(intel_crtc->atomic)); | |
3c692a41 GP |
13807 | } |
13808 | ||
cf4c7c12 | 13809 | /** |
4a3b8769 MR |
13810 | * intel_plane_destroy - destroy a plane |
13811 | * @plane: plane to destroy | |
cf4c7c12 | 13812 | * |
4a3b8769 MR |
13813 | * Common destruction function for all types of planes (primary, cursor, |
13814 | * sprite). | |
cf4c7c12 | 13815 | */ |
4a3b8769 | 13816 | void intel_plane_destroy(struct drm_plane *plane) |
465c120c MR |
13817 | { |
13818 | struct intel_plane *intel_plane = to_intel_plane(plane); | |
13819 | drm_plane_cleanup(plane); | |
13820 | kfree(intel_plane); | |
13821 | } | |
13822 | ||
65a3fea0 | 13823 | const struct drm_plane_funcs intel_plane_funcs = { |
70a101f8 MR |
13824 | .update_plane = drm_atomic_helper_update_plane, |
13825 | .disable_plane = drm_atomic_helper_disable_plane, | |
3d7d6510 | 13826 | .destroy = intel_plane_destroy, |
c196e1d6 | 13827 | .set_property = drm_atomic_helper_plane_set_property, |
a98b3431 MR |
13828 | .atomic_get_property = intel_plane_atomic_get_property, |
13829 | .atomic_set_property = intel_plane_atomic_set_property, | |
ea2c67bb MR |
13830 | .atomic_duplicate_state = intel_plane_duplicate_state, |
13831 | .atomic_destroy_state = intel_plane_destroy_state, | |
13832 | ||
465c120c MR |
13833 | }; |
13834 | ||
13835 | static struct drm_plane *intel_primary_plane_create(struct drm_device *dev, | |
13836 | int pipe) | |
13837 | { | |
13838 | struct intel_plane *primary; | |
8e7d688b | 13839 | struct intel_plane_state *state; |
465c120c MR |
13840 | const uint32_t *intel_primary_formats; |
13841 | int num_formats; | |
13842 | ||
13843 | primary = kzalloc(sizeof(*primary), GFP_KERNEL); | |
13844 | if (primary == NULL) | |
13845 | return NULL; | |
13846 | ||
8e7d688b MR |
13847 | state = intel_create_plane_state(&primary->base); |
13848 | if (!state) { | |
ea2c67bb MR |
13849 | kfree(primary); |
13850 | return NULL; | |
13851 | } | |
8e7d688b | 13852 | primary->base.state = &state->base; |
ea2c67bb | 13853 | |
465c120c MR |
13854 | primary->can_scale = false; |
13855 | primary->max_downscale = 1; | |
6156a456 CK |
13856 | if (INTEL_INFO(dev)->gen >= 9) { |
13857 | primary->can_scale = true; | |
af99ceda | 13858 | state->scaler_id = -1; |
6156a456 | 13859 | } |
465c120c MR |
13860 | primary->pipe = pipe; |
13861 | primary->plane = pipe; | |
c59cb179 MR |
13862 | primary->check_plane = intel_check_primary_plane; |
13863 | primary->commit_plane = intel_commit_primary_plane; | |
a8ad0d8e | 13864 | primary->disable_plane = intel_disable_primary_plane; |
08e221fb | 13865 | primary->ckey.flags = I915_SET_COLORKEY_NONE; |
465c120c MR |
13866 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) |
13867 | primary->plane = !pipe; | |
13868 | ||
6c0fd451 DL |
13869 | if (INTEL_INFO(dev)->gen >= 9) { |
13870 | intel_primary_formats = skl_primary_formats; | |
13871 | num_formats = ARRAY_SIZE(skl_primary_formats); | |
13872 | } else if (INTEL_INFO(dev)->gen >= 4) { | |
568db4f2 DL |
13873 | intel_primary_formats = i965_primary_formats; |
13874 | num_formats = ARRAY_SIZE(i965_primary_formats); | |
6c0fd451 DL |
13875 | } else { |
13876 | intel_primary_formats = i8xx_primary_formats; | |
13877 | num_formats = ARRAY_SIZE(i8xx_primary_formats); | |
465c120c MR |
13878 | } |
13879 | ||
13880 | drm_universal_plane_init(dev, &primary->base, 0, | |
65a3fea0 | 13881 | &intel_plane_funcs, |
465c120c MR |
13882 | intel_primary_formats, num_formats, |
13883 | DRM_PLANE_TYPE_PRIMARY); | |
48404c1e | 13884 | |
3b7a5119 SJ |
13885 | if (INTEL_INFO(dev)->gen >= 4) |
13886 | intel_create_rotation_property(dev, primary); | |
48404c1e | 13887 | |
ea2c67bb MR |
13888 | drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs); |
13889 | ||
465c120c MR |
13890 | return &primary->base; |
13891 | } | |
13892 | ||
3b7a5119 SJ |
13893 | void intel_create_rotation_property(struct drm_device *dev, struct intel_plane *plane) |
13894 | { | |
13895 | if (!dev->mode_config.rotation_property) { | |
13896 | unsigned long flags = BIT(DRM_ROTATE_0) | | |
13897 | BIT(DRM_ROTATE_180); | |
13898 | ||
13899 | if (INTEL_INFO(dev)->gen >= 9) | |
13900 | flags |= BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270); | |
13901 | ||
13902 | dev->mode_config.rotation_property = | |
13903 | drm_mode_create_rotation_property(dev, flags); | |
13904 | } | |
13905 | if (dev->mode_config.rotation_property) | |
13906 | drm_object_attach_property(&plane->base.base, | |
13907 | dev->mode_config.rotation_property, | |
13908 | plane->base.state->rotation); | |
13909 | } | |
13910 | ||
3d7d6510 | 13911 | static int |
852e787c GP |
13912 | intel_check_cursor_plane(struct drm_plane *plane, |
13913 | struct intel_plane_state *state) | |
3d7d6510 | 13914 | { |
2b875c22 | 13915 | struct drm_crtc *crtc = state->base.crtc; |
ea2c67bb | 13916 | struct drm_device *dev = plane->dev; |
2b875c22 | 13917 | struct drm_framebuffer *fb = state->base.fb; |
852e787c GP |
13918 | struct drm_rect *dest = &state->dst; |
13919 | struct drm_rect *src = &state->src; | |
13920 | const struct drm_rect *clip = &state->clip; | |
757f9a3e | 13921 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
ea2c67bb | 13922 | struct intel_crtc *intel_crtc; |
757f9a3e GP |
13923 | unsigned stride; |
13924 | int ret; | |
3d7d6510 | 13925 | |
ea2c67bb MR |
13926 | crtc = crtc ? crtc : plane->crtc; |
13927 | intel_crtc = to_intel_crtc(crtc); | |
13928 | ||
757f9a3e | 13929 | ret = drm_plane_helper_check_update(plane, crtc, fb, |
852e787c | 13930 | src, dest, clip, |
3d7d6510 MR |
13931 | DRM_PLANE_HELPER_NO_SCALING, |
13932 | DRM_PLANE_HELPER_NO_SCALING, | |
852e787c | 13933 | true, true, &state->visible); |
757f9a3e GP |
13934 | if (ret) |
13935 | return ret; | |
13936 | ||
13937 | ||
13938 | /* if we want to turn off the cursor ignore width and height */ | |
13939 | if (!obj) | |
32b7eeec | 13940 | goto finish; |
757f9a3e | 13941 | |
757f9a3e | 13942 | /* Check for which cursor types we support */ |
ea2c67bb MR |
13943 | if (!cursor_size_ok(dev, state->base.crtc_w, state->base.crtc_h)) { |
13944 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", | |
13945 | state->base.crtc_w, state->base.crtc_h); | |
757f9a3e GP |
13946 | return -EINVAL; |
13947 | } | |
13948 | ||
ea2c67bb MR |
13949 | stride = roundup_pow_of_two(state->base.crtc_w) * 4; |
13950 | if (obj->base.size < stride * state->base.crtc_h) { | |
757f9a3e GP |
13951 | DRM_DEBUG_KMS("buffer is too small\n"); |
13952 | return -ENOMEM; | |
13953 | } | |
13954 | ||
3a656b54 | 13955 | if (fb->modifier[0] != DRM_FORMAT_MOD_NONE) { |
757f9a3e GP |
13956 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
13957 | ret = -EINVAL; | |
13958 | } | |
757f9a3e | 13959 | |
32b7eeec MR |
13960 | finish: |
13961 | if (intel_crtc->active) { | |
3749f463 | 13962 | if (plane->state->crtc_w != state->base.crtc_w) |
32b7eeec MR |
13963 | intel_crtc->atomic.update_wm = true; |
13964 | ||
13965 | intel_crtc->atomic.fb_bits |= | |
13966 | INTEL_FRONTBUFFER_CURSOR(intel_crtc->pipe); | |
13967 | } | |
13968 | ||
757f9a3e | 13969 | return ret; |
852e787c | 13970 | } |
3d7d6510 | 13971 | |
a8ad0d8e ML |
13972 | static void |
13973 | intel_disable_cursor_plane(struct drm_plane *plane, | |
13974 | struct drm_crtc *crtc, | |
13975 | bool force) | |
13976 | { | |
13977 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
13978 | ||
13979 | if (!force) { | |
13980 | plane->fb = NULL; | |
13981 | intel_crtc->cursor_bo = NULL; | |
13982 | intel_crtc->cursor_addr = 0; | |
13983 | } | |
13984 | ||
13985 | intel_crtc_update_cursor(crtc, false); | |
13986 | } | |
13987 | ||
f4a2cf29 | 13988 | static void |
852e787c GP |
13989 | intel_commit_cursor_plane(struct drm_plane *plane, |
13990 | struct intel_plane_state *state) | |
13991 | { | |
2b875c22 | 13992 | struct drm_crtc *crtc = state->base.crtc; |
ea2c67bb MR |
13993 | struct drm_device *dev = plane->dev; |
13994 | struct intel_crtc *intel_crtc; | |
2b875c22 | 13995 | struct drm_i915_gem_object *obj = intel_fb_obj(state->base.fb); |
a912f12f | 13996 | uint32_t addr; |
852e787c | 13997 | |
ea2c67bb MR |
13998 | crtc = crtc ? crtc : plane->crtc; |
13999 | intel_crtc = to_intel_crtc(crtc); | |
14000 | ||
2b875c22 | 14001 | plane->fb = state->base.fb; |
ea2c67bb MR |
14002 | crtc->cursor_x = state->base.crtc_x; |
14003 | crtc->cursor_y = state->base.crtc_y; | |
14004 | ||
a912f12f GP |
14005 | if (intel_crtc->cursor_bo == obj) |
14006 | goto update; | |
4ed91096 | 14007 | |
f4a2cf29 | 14008 | if (!obj) |
a912f12f | 14009 | addr = 0; |
f4a2cf29 | 14010 | else if (!INTEL_INFO(dev)->cursor_needs_physical) |
a912f12f | 14011 | addr = i915_gem_obj_ggtt_offset(obj); |
f4a2cf29 | 14012 | else |
a912f12f | 14013 | addr = obj->phys_handle->busaddr; |
852e787c | 14014 | |
a912f12f GP |
14015 | intel_crtc->cursor_addr = addr; |
14016 | intel_crtc->cursor_bo = obj; | |
14017 | update: | |
852e787c | 14018 | |
32b7eeec | 14019 | if (intel_crtc->active) |
a912f12f | 14020 | intel_crtc_update_cursor(crtc, state->visible); |
852e787c GP |
14021 | } |
14022 | ||
3d7d6510 MR |
14023 | static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev, |
14024 | int pipe) | |
14025 | { | |
14026 | struct intel_plane *cursor; | |
8e7d688b | 14027 | struct intel_plane_state *state; |
3d7d6510 MR |
14028 | |
14029 | cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); | |
14030 | if (cursor == NULL) | |
14031 | return NULL; | |
14032 | ||
8e7d688b MR |
14033 | state = intel_create_plane_state(&cursor->base); |
14034 | if (!state) { | |
ea2c67bb MR |
14035 | kfree(cursor); |
14036 | return NULL; | |
14037 | } | |
8e7d688b | 14038 | cursor->base.state = &state->base; |
ea2c67bb | 14039 | |
3d7d6510 MR |
14040 | cursor->can_scale = false; |
14041 | cursor->max_downscale = 1; | |
14042 | cursor->pipe = pipe; | |
14043 | cursor->plane = pipe; | |
c59cb179 MR |
14044 | cursor->check_plane = intel_check_cursor_plane; |
14045 | cursor->commit_plane = intel_commit_cursor_plane; | |
a8ad0d8e | 14046 | cursor->disable_plane = intel_disable_cursor_plane; |
3d7d6510 MR |
14047 | |
14048 | drm_universal_plane_init(dev, &cursor->base, 0, | |
65a3fea0 | 14049 | &intel_plane_funcs, |
3d7d6510 MR |
14050 | intel_cursor_formats, |
14051 | ARRAY_SIZE(intel_cursor_formats), | |
14052 | DRM_PLANE_TYPE_CURSOR); | |
4398ad45 VS |
14053 | |
14054 | if (INTEL_INFO(dev)->gen >= 4) { | |
14055 | if (!dev->mode_config.rotation_property) | |
14056 | dev->mode_config.rotation_property = | |
14057 | drm_mode_create_rotation_property(dev, | |
14058 | BIT(DRM_ROTATE_0) | | |
14059 | BIT(DRM_ROTATE_180)); | |
14060 | if (dev->mode_config.rotation_property) | |
14061 | drm_object_attach_property(&cursor->base.base, | |
14062 | dev->mode_config.rotation_property, | |
8e7d688b | 14063 | state->base.rotation); |
4398ad45 VS |
14064 | } |
14065 | ||
af99ceda CK |
14066 | if (INTEL_INFO(dev)->gen >=9) |
14067 | state->scaler_id = -1; | |
14068 | ||
ea2c67bb MR |
14069 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
14070 | ||
3d7d6510 MR |
14071 | return &cursor->base; |
14072 | } | |
14073 | ||
549e2bfb CK |
14074 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
14075 | struct intel_crtc_state *crtc_state) | |
14076 | { | |
14077 | int i; | |
14078 | struct intel_scaler *intel_scaler; | |
14079 | struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state; | |
14080 | ||
14081 | for (i = 0; i < intel_crtc->num_scalers; i++) { | |
14082 | intel_scaler = &scaler_state->scalers[i]; | |
14083 | intel_scaler->in_use = 0; | |
549e2bfb CK |
14084 | intel_scaler->mode = PS_SCALER_MODE_DYN; |
14085 | } | |
14086 | ||
14087 | scaler_state->scaler_id = -1; | |
14088 | } | |
14089 | ||
b358d0a6 | 14090 | static void intel_crtc_init(struct drm_device *dev, int pipe) |
79e53945 | 14091 | { |
fbee40df | 14092 | struct drm_i915_private *dev_priv = dev->dev_private; |
79e53945 | 14093 | struct intel_crtc *intel_crtc; |
f5de6e07 | 14094 | struct intel_crtc_state *crtc_state = NULL; |
3d7d6510 MR |
14095 | struct drm_plane *primary = NULL; |
14096 | struct drm_plane *cursor = NULL; | |
465c120c | 14097 | int i, ret; |
79e53945 | 14098 | |
955382f3 | 14099 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
79e53945 JB |
14100 | if (intel_crtc == NULL) |
14101 | return; | |
14102 | ||
f5de6e07 ACO |
14103 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
14104 | if (!crtc_state) | |
14105 | goto fail; | |
550acefd ACO |
14106 | intel_crtc->config = crtc_state; |
14107 | intel_crtc->base.state = &crtc_state->base; | |
07878248 | 14108 | crtc_state->base.crtc = &intel_crtc->base; |
f5de6e07 | 14109 | |
549e2bfb CK |
14110 | /* initialize shared scalers */ |
14111 | if (INTEL_INFO(dev)->gen >= 9) { | |
14112 | if (pipe == PIPE_C) | |
14113 | intel_crtc->num_scalers = 1; | |
14114 | else | |
14115 | intel_crtc->num_scalers = SKL_NUM_SCALERS; | |
14116 | ||
14117 | skl_init_scalers(dev, intel_crtc, crtc_state); | |
14118 | } | |
14119 | ||
465c120c | 14120 | primary = intel_primary_plane_create(dev, pipe); |
3d7d6510 MR |
14121 | if (!primary) |
14122 | goto fail; | |
14123 | ||
14124 | cursor = intel_cursor_plane_create(dev, pipe); | |
14125 | if (!cursor) | |
14126 | goto fail; | |
14127 | ||
465c120c | 14128 | ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary, |
3d7d6510 MR |
14129 | cursor, &intel_crtc_funcs); |
14130 | if (ret) | |
14131 | goto fail; | |
79e53945 JB |
14132 | |
14133 | drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256); | |
79e53945 JB |
14134 | for (i = 0; i < 256; i++) { |
14135 | intel_crtc->lut_r[i] = i; | |
14136 | intel_crtc->lut_g[i] = i; | |
14137 | intel_crtc->lut_b[i] = i; | |
14138 | } | |
14139 | ||
1f1c2e24 VS |
14140 | /* |
14141 | * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port | |
8c0f92e1 | 14142 | * is hooked to pipe B. Hence we want plane A feeding pipe B. |
1f1c2e24 | 14143 | */ |
80824003 JB |
14144 | intel_crtc->pipe = pipe; |
14145 | intel_crtc->plane = pipe; | |
3a77c4c4 | 14146 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) { |
28c97730 | 14147 | DRM_DEBUG_KMS("swapping pipes & planes for FBC\n"); |
e2e767ab | 14148 | intel_crtc->plane = !pipe; |
80824003 JB |
14149 | } |
14150 | ||
4b0e333e CW |
14151 | intel_crtc->cursor_base = ~0; |
14152 | intel_crtc->cursor_cntl = ~0; | |
dc41c154 | 14153 | intel_crtc->cursor_size = ~0; |
8d7849db | 14154 | |
22fd0fab JB |
14155 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
14156 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); | |
14157 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base; | |
14158 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base; | |
14159 | ||
79e53945 | 14160 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
87b6b101 DV |
14161 | |
14162 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); | |
3d7d6510 MR |
14163 | return; |
14164 | ||
14165 | fail: | |
14166 | if (primary) | |
14167 | drm_plane_cleanup(primary); | |
14168 | if (cursor) | |
14169 | drm_plane_cleanup(cursor); | |
f5de6e07 | 14170 | kfree(crtc_state); |
3d7d6510 | 14171 | kfree(intel_crtc); |
79e53945 JB |
14172 | } |
14173 | ||
752aa88a JB |
14174 | enum pipe intel_get_pipe_from_connector(struct intel_connector *connector) |
14175 | { | |
14176 | struct drm_encoder *encoder = connector->base.encoder; | |
6e9f798d | 14177 | struct drm_device *dev = connector->base.dev; |
752aa88a | 14178 | |
51fd371b | 14179 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
752aa88a | 14180 | |
d3babd3f | 14181 | if (!encoder || WARN_ON(!encoder->crtc)) |
752aa88a JB |
14182 | return INVALID_PIPE; |
14183 | ||
14184 | return to_intel_crtc(encoder->crtc)->pipe; | |
14185 | } | |
14186 | ||
08d7b3d1 | 14187 | int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data, |
05394f39 | 14188 | struct drm_file *file) |
08d7b3d1 | 14189 | { |
08d7b3d1 | 14190 | struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data; |
7707e653 | 14191 | struct drm_crtc *drmmode_crtc; |
c05422d5 | 14192 | struct intel_crtc *crtc; |
08d7b3d1 | 14193 | |
7707e653 | 14194 | drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id); |
08d7b3d1 | 14195 | |
7707e653 | 14196 | if (!drmmode_crtc) { |
08d7b3d1 | 14197 | DRM_ERROR("no such CRTC id\n"); |
3f2c2057 | 14198 | return -ENOENT; |
08d7b3d1 CW |
14199 | } |
14200 | ||
7707e653 | 14201 | crtc = to_intel_crtc(drmmode_crtc); |
c05422d5 | 14202 | pipe_from_crtc_id->pipe = crtc->pipe; |
08d7b3d1 | 14203 | |
c05422d5 | 14204 | return 0; |
08d7b3d1 CW |
14205 | } |
14206 | ||
66a9278e | 14207 | static int intel_encoder_clones(struct intel_encoder *encoder) |
79e53945 | 14208 | { |
66a9278e DV |
14209 | struct drm_device *dev = encoder->base.dev; |
14210 | struct intel_encoder *source_encoder; | |
79e53945 | 14211 | int index_mask = 0; |
79e53945 JB |
14212 | int entry = 0; |
14213 | ||
b2784e15 | 14214 | for_each_intel_encoder(dev, source_encoder) { |
bc079e8b | 14215 | if (encoders_cloneable(encoder, source_encoder)) |
66a9278e DV |
14216 | index_mask |= (1 << entry); |
14217 | ||
79e53945 JB |
14218 | entry++; |
14219 | } | |
4ef69c7a | 14220 | |
79e53945 JB |
14221 | return index_mask; |
14222 | } | |
14223 | ||
4d302442 CW |
14224 | static bool has_edp_a(struct drm_device *dev) |
14225 | { | |
14226 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14227 | ||
14228 | if (!IS_MOBILE(dev)) | |
14229 | return false; | |
14230 | ||
14231 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) | |
14232 | return false; | |
14233 | ||
e3589908 | 14234 | if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE)) |
4d302442 CW |
14235 | return false; |
14236 | ||
14237 | return true; | |
14238 | } | |
14239 | ||
84b4e042 JB |
14240 | static bool intel_crt_present(struct drm_device *dev) |
14241 | { | |
14242 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14243 | ||
884497ed DL |
14244 | if (INTEL_INFO(dev)->gen >= 9) |
14245 | return false; | |
14246 | ||
cf404ce4 | 14247 | if (IS_HSW_ULT(dev) || IS_BDW_ULT(dev)) |
84b4e042 JB |
14248 | return false; |
14249 | ||
14250 | if (IS_CHERRYVIEW(dev)) | |
14251 | return false; | |
14252 | ||
14253 | if (IS_VALLEYVIEW(dev) && !dev_priv->vbt.int_crt_support) | |
14254 | return false; | |
14255 | ||
14256 | return true; | |
14257 | } | |
14258 | ||
79e53945 JB |
14259 | static void intel_setup_outputs(struct drm_device *dev) |
14260 | { | |
725e30ad | 14261 | struct drm_i915_private *dev_priv = dev->dev_private; |
4ef69c7a | 14262 | struct intel_encoder *encoder; |
cb0953d7 | 14263 | bool dpd_is_edp = false; |
79e53945 | 14264 | |
c9093354 | 14265 | intel_lvds_init(dev); |
79e53945 | 14266 | |
84b4e042 | 14267 | if (intel_crt_present(dev)) |
79935fca | 14268 | intel_crt_init(dev); |
cb0953d7 | 14269 | |
c776eb2e VK |
14270 | if (IS_BROXTON(dev)) { |
14271 | /* | |
14272 | * FIXME: Broxton doesn't support port detection via the | |
14273 | * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to | |
14274 | * detect the ports. | |
14275 | */ | |
14276 | intel_ddi_init(dev, PORT_A); | |
14277 | intel_ddi_init(dev, PORT_B); | |
14278 | intel_ddi_init(dev, PORT_C); | |
14279 | } else if (HAS_DDI(dev)) { | |
0e72a5b5 ED |
14280 | int found; |
14281 | ||
de31facd JB |
14282 | /* |
14283 | * Haswell uses DDI functions to detect digital outputs. | |
14284 | * On SKL pre-D0 the strap isn't connected, so we assume | |
14285 | * it's there. | |
14286 | */ | |
0e72a5b5 | 14287 | found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED; |
de31facd JB |
14288 | /* WaIgnoreDDIAStrap: skl */ |
14289 | if (found || | |
14290 | (IS_SKYLAKE(dev) && INTEL_REVID(dev) < SKL_REVID_D0)) | |
0e72a5b5 ED |
14291 | intel_ddi_init(dev, PORT_A); |
14292 | ||
14293 | /* DDI B, C and D detection is indicated by the SFUSE_STRAP | |
14294 | * register */ | |
14295 | found = I915_READ(SFUSE_STRAP); | |
14296 | ||
14297 | if (found & SFUSE_STRAP_DDIB_DETECTED) | |
14298 | intel_ddi_init(dev, PORT_B); | |
14299 | if (found & SFUSE_STRAP_DDIC_DETECTED) | |
14300 | intel_ddi_init(dev, PORT_C); | |
14301 | if (found & SFUSE_STRAP_DDID_DETECTED) | |
14302 | intel_ddi_init(dev, PORT_D); | |
14303 | } else if (HAS_PCH_SPLIT(dev)) { | |
cb0953d7 | 14304 | int found; |
5d8a7752 | 14305 | dpd_is_edp = intel_dp_is_edp(dev, PORT_D); |
270b3042 DV |
14306 | |
14307 | if (has_edp_a(dev)) | |
14308 | intel_dp_init(dev, DP_A, PORT_A); | |
cb0953d7 | 14309 | |
dc0fa718 | 14310 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
461ed3ca | 14311 | /* PCH SDVOB multiplex with HDMIB */ |
eef4eacb | 14312 | found = intel_sdvo_init(dev, PCH_SDVOB, true); |
30ad48b7 | 14313 | if (!found) |
e2debe91 | 14314 | intel_hdmi_init(dev, PCH_HDMIB, PORT_B); |
5eb08b69 | 14315 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
ab9d7c30 | 14316 | intel_dp_init(dev, PCH_DP_B, PORT_B); |
30ad48b7 ZW |
14317 | } |
14318 | ||
dc0fa718 | 14319 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
e2debe91 | 14320 | intel_hdmi_init(dev, PCH_HDMIC, PORT_C); |
30ad48b7 | 14321 | |
dc0fa718 | 14322 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
e2debe91 | 14323 | intel_hdmi_init(dev, PCH_HDMID, PORT_D); |
30ad48b7 | 14324 | |
5eb08b69 | 14325 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
ab9d7c30 | 14326 | intel_dp_init(dev, PCH_DP_C, PORT_C); |
5eb08b69 | 14327 | |
270b3042 | 14328 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
ab9d7c30 | 14329 | intel_dp_init(dev, PCH_DP_D, PORT_D); |
4a87d65d | 14330 | } else if (IS_VALLEYVIEW(dev)) { |
e17ac6db VS |
14331 | /* |
14332 | * The DP_DETECTED bit is the latched state of the DDC | |
14333 | * SDA pin at boot. However since eDP doesn't require DDC | |
14334 | * (no way to plug in a DP->HDMI dongle) the DDC pins for | |
14335 | * eDP ports may have been muxed to an alternate function. | |
14336 | * Thus we can't rely on the DP_DETECTED bit alone to detect | |
14337 | * eDP ports. Consult the VBT as well as DP_DETECTED to | |
14338 | * detect eDP ports. | |
14339 | */ | |
d2182a66 VS |
14340 | if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED && |
14341 | !intel_dp_is_edp(dev, PORT_B)) | |
585a94b8 AB |
14342 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB, |
14343 | PORT_B); | |
e17ac6db VS |
14344 | if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED || |
14345 | intel_dp_is_edp(dev, PORT_B)) | |
14346 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B); | |
585a94b8 | 14347 | |
d2182a66 VS |
14348 | if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIC) & SDVO_DETECTED && |
14349 | !intel_dp_is_edp(dev, PORT_C)) | |
6f6005a5 JB |
14350 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIC, |
14351 | PORT_C); | |
e17ac6db VS |
14352 | if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED || |
14353 | intel_dp_is_edp(dev, PORT_C)) | |
14354 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C); | |
19c03924 | 14355 | |
9418c1f1 | 14356 | if (IS_CHERRYVIEW(dev)) { |
e17ac6db | 14357 | if (I915_READ(VLV_DISPLAY_BASE + CHV_HDMID) & SDVO_DETECTED) |
9418c1f1 VS |
14358 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + CHV_HDMID, |
14359 | PORT_D); | |
e17ac6db VS |
14360 | /* eDP not supported on port D, so don't check VBT */ |
14361 | if (I915_READ(VLV_DISPLAY_BASE + DP_D) & DP_DETECTED) | |
14362 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_D, PORT_D); | |
9418c1f1 VS |
14363 | } |
14364 | ||
3cfca973 | 14365 | intel_dsi_init(dev); |
103a196f | 14366 | } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) { |
27185ae1 | 14367 | bool found = false; |
7d57382e | 14368 | |
e2debe91 | 14369 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
b01f2c3a | 14370 | DRM_DEBUG_KMS("probing SDVOB\n"); |
e2debe91 | 14371 | found = intel_sdvo_init(dev, GEN3_SDVOB, true); |
b01f2c3a JB |
14372 | if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) { |
14373 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); | |
e2debe91 | 14374 | intel_hdmi_init(dev, GEN4_HDMIB, PORT_B); |
b01f2c3a | 14375 | } |
27185ae1 | 14376 | |
e7281eab | 14377 | if (!found && SUPPORTS_INTEGRATED_DP(dev)) |
ab9d7c30 | 14378 | intel_dp_init(dev, DP_B, PORT_B); |
725e30ad | 14379 | } |
13520b05 KH |
14380 | |
14381 | /* Before G4X SDVOC doesn't have its own detect register */ | |
13520b05 | 14382 | |
e2debe91 | 14383 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
b01f2c3a | 14384 | DRM_DEBUG_KMS("probing SDVOC\n"); |
e2debe91 | 14385 | found = intel_sdvo_init(dev, GEN3_SDVOC, false); |
b01f2c3a | 14386 | } |
27185ae1 | 14387 | |
e2debe91 | 14388 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
27185ae1 | 14389 | |
b01f2c3a JB |
14390 | if (SUPPORTS_INTEGRATED_HDMI(dev)) { |
14391 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); | |
e2debe91 | 14392 | intel_hdmi_init(dev, GEN4_HDMIC, PORT_C); |
b01f2c3a | 14393 | } |
e7281eab | 14394 | if (SUPPORTS_INTEGRATED_DP(dev)) |
ab9d7c30 | 14395 | intel_dp_init(dev, DP_C, PORT_C); |
725e30ad | 14396 | } |
27185ae1 | 14397 | |
b01f2c3a | 14398 | if (SUPPORTS_INTEGRATED_DP(dev) && |
e7281eab | 14399 | (I915_READ(DP_D) & DP_DETECTED)) |
ab9d7c30 | 14400 | intel_dp_init(dev, DP_D, PORT_D); |
bad720ff | 14401 | } else if (IS_GEN2(dev)) |
79e53945 JB |
14402 | intel_dvo_init(dev); |
14403 | ||
103a196f | 14404 | if (SUPPORTS_TV(dev)) |
79e53945 JB |
14405 | intel_tv_init(dev); |
14406 | ||
0bc12bcb | 14407 | intel_psr_init(dev); |
7c8f8a70 | 14408 | |
b2784e15 | 14409 | for_each_intel_encoder(dev, encoder) { |
4ef69c7a CW |
14410 | encoder->base.possible_crtcs = encoder->crtc_mask; |
14411 | encoder->base.possible_clones = | |
66a9278e | 14412 | intel_encoder_clones(encoder); |
79e53945 | 14413 | } |
47356eb6 | 14414 | |
dde86e2d | 14415 | intel_init_pch_refclk(dev); |
270b3042 DV |
14416 | |
14417 | drm_helper_move_panel_connectors_to_head(dev); | |
79e53945 JB |
14418 | } |
14419 | ||
14420 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) | |
14421 | { | |
60a5ca01 | 14422 | struct drm_device *dev = fb->dev; |
79e53945 | 14423 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
79e53945 | 14424 | |
ef2d633e | 14425 | drm_framebuffer_cleanup(fb); |
60a5ca01 | 14426 | mutex_lock(&dev->struct_mutex); |
ef2d633e | 14427 | WARN_ON(!intel_fb->obj->framebuffer_references--); |
60a5ca01 VS |
14428 | drm_gem_object_unreference(&intel_fb->obj->base); |
14429 | mutex_unlock(&dev->struct_mutex); | |
79e53945 JB |
14430 | kfree(intel_fb); |
14431 | } | |
14432 | ||
14433 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, | |
05394f39 | 14434 | struct drm_file *file, |
79e53945 JB |
14435 | unsigned int *handle) |
14436 | { | |
14437 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | |
05394f39 | 14438 | struct drm_i915_gem_object *obj = intel_fb->obj; |
79e53945 | 14439 | |
05394f39 | 14440 | return drm_gem_handle_create(file, &obj->base, handle); |
79e53945 JB |
14441 | } |
14442 | ||
14443 | static const struct drm_framebuffer_funcs intel_fb_funcs = { | |
14444 | .destroy = intel_user_framebuffer_destroy, | |
14445 | .create_handle = intel_user_framebuffer_create_handle, | |
14446 | }; | |
14447 | ||
b321803d DL |
14448 | static |
14449 | u32 intel_fb_pitch_limit(struct drm_device *dev, uint64_t fb_modifier, | |
14450 | uint32_t pixel_format) | |
14451 | { | |
14452 | u32 gen = INTEL_INFO(dev)->gen; | |
14453 | ||
14454 | if (gen >= 9) { | |
14455 | /* "The stride in bytes must not exceed the of the size of 8K | |
14456 | * pixels and 32K bytes." | |
14457 | */ | |
14458 | return min(8192*drm_format_plane_cpp(pixel_format, 0), 32768); | |
14459 | } else if (gen >= 5 && !IS_VALLEYVIEW(dev)) { | |
14460 | return 32*1024; | |
14461 | } else if (gen >= 4) { | |
14462 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) | |
14463 | return 16*1024; | |
14464 | else | |
14465 | return 32*1024; | |
14466 | } else if (gen >= 3) { | |
14467 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) | |
14468 | return 8*1024; | |
14469 | else | |
14470 | return 16*1024; | |
14471 | } else { | |
14472 | /* XXX DSPC is limited to 4k tiled */ | |
14473 | return 8*1024; | |
14474 | } | |
14475 | } | |
14476 | ||
b5ea642a DV |
14477 | static int intel_framebuffer_init(struct drm_device *dev, |
14478 | struct intel_framebuffer *intel_fb, | |
14479 | struct drm_mode_fb_cmd2 *mode_cmd, | |
14480 | struct drm_i915_gem_object *obj) | |
79e53945 | 14481 | { |
6761dd31 | 14482 | unsigned int aligned_height; |
79e53945 | 14483 | int ret; |
b321803d | 14484 | u32 pitch_limit, stride_alignment; |
79e53945 | 14485 | |
dd4916c5 DV |
14486 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
14487 | ||
2a80eada DV |
14488 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
14489 | /* Enforce that fb modifier and tiling mode match, but only for | |
14490 | * X-tiled. This is needed for FBC. */ | |
14491 | if (!!(obj->tiling_mode == I915_TILING_X) != | |
14492 | !!(mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED)) { | |
14493 | DRM_DEBUG("tiling_mode doesn't match fb modifier\n"); | |
14494 | return -EINVAL; | |
14495 | } | |
14496 | } else { | |
14497 | if (obj->tiling_mode == I915_TILING_X) | |
14498 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; | |
14499 | else if (obj->tiling_mode == I915_TILING_Y) { | |
14500 | DRM_DEBUG("No Y tiling for legacy addfb\n"); | |
14501 | return -EINVAL; | |
14502 | } | |
14503 | } | |
14504 | ||
9a8f0a12 TU |
14505 | /* Passed in modifier sanity checking. */ |
14506 | switch (mode_cmd->modifier[0]) { | |
14507 | case I915_FORMAT_MOD_Y_TILED: | |
14508 | case I915_FORMAT_MOD_Yf_TILED: | |
14509 | if (INTEL_INFO(dev)->gen < 9) { | |
14510 | DRM_DEBUG("Unsupported tiling 0x%llx!\n", | |
14511 | mode_cmd->modifier[0]); | |
14512 | return -EINVAL; | |
14513 | } | |
14514 | case DRM_FORMAT_MOD_NONE: | |
14515 | case I915_FORMAT_MOD_X_TILED: | |
14516 | break; | |
14517 | default: | |
c0f40428 JB |
14518 | DRM_DEBUG("Unsupported fb modifier 0x%llx!\n", |
14519 | mode_cmd->modifier[0]); | |
57cd6508 | 14520 | return -EINVAL; |
c16ed4be | 14521 | } |
57cd6508 | 14522 | |
b321803d DL |
14523 | stride_alignment = intel_fb_stride_alignment(dev, mode_cmd->modifier[0], |
14524 | mode_cmd->pixel_format); | |
14525 | if (mode_cmd->pitches[0] & (stride_alignment - 1)) { | |
14526 | DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n", | |
14527 | mode_cmd->pitches[0], stride_alignment); | |
57cd6508 | 14528 | return -EINVAL; |
c16ed4be | 14529 | } |
57cd6508 | 14530 | |
b321803d DL |
14531 | pitch_limit = intel_fb_pitch_limit(dev, mode_cmd->modifier[0], |
14532 | mode_cmd->pixel_format); | |
a35cdaa0 | 14533 | if (mode_cmd->pitches[0] > pitch_limit) { |
b321803d DL |
14534 | DRM_DEBUG("%s pitch (%u) must be at less than %d\n", |
14535 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_NONE ? | |
2a80eada | 14536 | "tiled" : "linear", |
a35cdaa0 | 14537 | mode_cmd->pitches[0], pitch_limit); |
5d7bd705 | 14538 | return -EINVAL; |
c16ed4be | 14539 | } |
5d7bd705 | 14540 | |
2a80eada | 14541 | if (mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED && |
c16ed4be CW |
14542 | mode_cmd->pitches[0] != obj->stride) { |
14543 | DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n", | |
14544 | mode_cmd->pitches[0], obj->stride); | |
5d7bd705 | 14545 | return -EINVAL; |
c16ed4be | 14546 | } |
5d7bd705 | 14547 | |
57779d06 | 14548 | /* Reject formats not supported by any plane early. */ |
308e5bcb | 14549 | switch (mode_cmd->pixel_format) { |
57779d06 | 14550 | case DRM_FORMAT_C8: |
04b3924d VS |
14551 | case DRM_FORMAT_RGB565: |
14552 | case DRM_FORMAT_XRGB8888: | |
14553 | case DRM_FORMAT_ARGB8888: | |
57779d06 VS |
14554 | break; |
14555 | case DRM_FORMAT_XRGB1555: | |
c16ed4be | 14556 | if (INTEL_INFO(dev)->gen > 3) { |
4ee62c76 VS |
14557 | DRM_DEBUG("unsupported pixel format: %s\n", |
14558 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14559 | return -EINVAL; |
c16ed4be | 14560 | } |
57779d06 | 14561 | break; |
57779d06 | 14562 | case DRM_FORMAT_ABGR8888: |
6c0fd451 DL |
14563 | if (!IS_VALLEYVIEW(dev) && INTEL_INFO(dev)->gen < 9) { |
14564 | DRM_DEBUG("unsupported pixel format: %s\n", | |
14565 | drm_get_format_name(mode_cmd->pixel_format)); | |
14566 | return -EINVAL; | |
14567 | } | |
14568 | break; | |
14569 | case DRM_FORMAT_XBGR8888: | |
04b3924d | 14570 | case DRM_FORMAT_XRGB2101010: |
57779d06 | 14571 | case DRM_FORMAT_XBGR2101010: |
c16ed4be | 14572 | if (INTEL_INFO(dev)->gen < 4) { |
4ee62c76 VS |
14573 | DRM_DEBUG("unsupported pixel format: %s\n", |
14574 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14575 | return -EINVAL; |
c16ed4be | 14576 | } |
b5626747 | 14577 | break; |
7531208b DL |
14578 | case DRM_FORMAT_ABGR2101010: |
14579 | if (!IS_VALLEYVIEW(dev)) { | |
14580 | DRM_DEBUG("unsupported pixel format: %s\n", | |
14581 | drm_get_format_name(mode_cmd->pixel_format)); | |
14582 | return -EINVAL; | |
14583 | } | |
14584 | break; | |
04b3924d VS |
14585 | case DRM_FORMAT_YUYV: |
14586 | case DRM_FORMAT_UYVY: | |
14587 | case DRM_FORMAT_YVYU: | |
14588 | case DRM_FORMAT_VYUY: | |
c16ed4be | 14589 | if (INTEL_INFO(dev)->gen < 5) { |
4ee62c76 VS |
14590 | DRM_DEBUG("unsupported pixel format: %s\n", |
14591 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14592 | return -EINVAL; |
c16ed4be | 14593 | } |
57cd6508 CW |
14594 | break; |
14595 | default: | |
4ee62c76 VS |
14596 | DRM_DEBUG("unsupported pixel format: %s\n", |
14597 | drm_get_format_name(mode_cmd->pixel_format)); | |
57cd6508 CW |
14598 | return -EINVAL; |
14599 | } | |
14600 | ||
90f9a336 VS |
14601 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
14602 | if (mode_cmd->offsets[0] != 0) | |
14603 | return -EINVAL; | |
14604 | ||
ec2c981e | 14605 | aligned_height = intel_fb_align_height(dev, mode_cmd->height, |
091df6cb DV |
14606 | mode_cmd->pixel_format, |
14607 | mode_cmd->modifier[0]); | |
53155c0a DV |
14608 | /* FIXME drm helper for size checks (especially planar formats)? */ |
14609 | if (obj->base.size < aligned_height * mode_cmd->pitches[0]) | |
14610 | return -EINVAL; | |
14611 | ||
c7d73f6a DV |
14612 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); |
14613 | intel_fb->obj = obj; | |
80075d49 | 14614 | intel_fb->obj->framebuffer_references++; |
c7d73f6a | 14615 | |
79e53945 JB |
14616 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); |
14617 | if (ret) { | |
14618 | DRM_ERROR("framebuffer init failed %d\n", ret); | |
14619 | return ret; | |
14620 | } | |
14621 | ||
79e53945 JB |
14622 | return 0; |
14623 | } | |
14624 | ||
79e53945 JB |
14625 | static struct drm_framebuffer * |
14626 | intel_user_framebuffer_create(struct drm_device *dev, | |
14627 | struct drm_file *filp, | |
308e5bcb | 14628 | struct drm_mode_fb_cmd2 *mode_cmd) |
79e53945 | 14629 | { |
05394f39 | 14630 | struct drm_i915_gem_object *obj; |
79e53945 | 14631 | |
308e5bcb JB |
14632 | obj = to_intel_bo(drm_gem_object_lookup(dev, filp, |
14633 | mode_cmd->handles[0])); | |
c8725226 | 14634 | if (&obj->base == NULL) |
cce13ff7 | 14635 | return ERR_PTR(-ENOENT); |
79e53945 | 14636 | |
d2dff872 | 14637 | return intel_framebuffer_create(dev, mode_cmd, obj); |
79e53945 JB |
14638 | } |
14639 | ||
4520f53a | 14640 | #ifndef CONFIG_DRM_I915_FBDEV |
0632fef6 | 14641 | static inline void intel_fbdev_output_poll_changed(struct drm_device *dev) |
4520f53a DV |
14642 | { |
14643 | } | |
14644 | #endif | |
14645 | ||
79e53945 | 14646 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
79e53945 | 14647 | .fb_create = intel_user_framebuffer_create, |
0632fef6 | 14648 | .output_poll_changed = intel_fbdev_output_poll_changed, |
5ee67f1c MR |
14649 | .atomic_check = intel_atomic_check, |
14650 | .atomic_commit = intel_atomic_commit, | |
de419ab6 ML |
14651 | .atomic_state_alloc = intel_atomic_state_alloc, |
14652 | .atomic_state_clear = intel_atomic_state_clear, | |
79e53945 JB |
14653 | }; |
14654 | ||
e70236a8 JB |
14655 | /* Set up chip specific display functions */ |
14656 | static void intel_init_display(struct drm_device *dev) | |
14657 | { | |
14658 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14659 | ||
ee9300bb DV |
14660 | if (HAS_PCH_SPLIT(dev) || IS_G4X(dev)) |
14661 | dev_priv->display.find_dpll = g4x_find_best_dpll; | |
ef9348c8 CML |
14662 | else if (IS_CHERRYVIEW(dev)) |
14663 | dev_priv->display.find_dpll = chv_find_best_dpll; | |
ee9300bb DV |
14664 | else if (IS_VALLEYVIEW(dev)) |
14665 | dev_priv->display.find_dpll = vlv_find_best_dpll; | |
14666 | else if (IS_PINEVIEW(dev)) | |
14667 | dev_priv->display.find_dpll = pnv_find_best_dpll; | |
14668 | else | |
14669 | dev_priv->display.find_dpll = i9xx_find_best_dpll; | |
14670 | ||
bc8d7dff DL |
14671 | if (INTEL_INFO(dev)->gen >= 9) { |
14672 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; | |
5724dbd1 DL |
14673 | dev_priv->display.get_initial_plane_config = |
14674 | skylake_get_initial_plane_config; | |
bc8d7dff DL |
14675 | dev_priv->display.crtc_compute_clock = |
14676 | haswell_crtc_compute_clock; | |
14677 | dev_priv->display.crtc_enable = haswell_crtc_enable; | |
14678 | dev_priv->display.crtc_disable = haswell_crtc_disable; | |
bc8d7dff DL |
14679 | dev_priv->display.update_primary_plane = |
14680 | skylake_update_primary_plane; | |
14681 | } else if (HAS_DDI(dev)) { | |
0e8ffe1b | 14682 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
5724dbd1 DL |
14683 | dev_priv->display.get_initial_plane_config = |
14684 | ironlake_get_initial_plane_config; | |
797d0259 ACO |
14685 | dev_priv->display.crtc_compute_clock = |
14686 | haswell_crtc_compute_clock; | |
4f771f10 PZ |
14687 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
14688 | dev_priv->display.crtc_disable = haswell_crtc_disable; | |
bc8d7dff DL |
14689 | dev_priv->display.update_primary_plane = |
14690 | ironlake_update_primary_plane; | |
09b4ddf9 | 14691 | } else if (HAS_PCH_SPLIT(dev)) { |
0e8ffe1b | 14692 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
5724dbd1 DL |
14693 | dev_priv->display.get_initial_plane_config = |
14694 | ironlake_get_initial_plane_config; | |
3fb37703 ACO |
14695 | dev_priv->display.crtc_compute_clock = |
14696 | ironlake_crtc_compute_clock; | |
76e5a89c DV |
14697 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
14698 | dev_priv->display.crtc_disable = ironlake_crtc_disable; | |
262ca2b0 MR |
14699 | dev_priv->display.update_primary_plane = |
14700 | ironlake_update_primary_plane; | |
89b667f8 JB |
14701 | } else if (IS_VALLEYVIEW(dev)) { |
14702 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; | |
5724dbd1 DL |
14703 | dev_priv->display.get_initial_plane_config = |
14704 | i9xx_get_initial_plane_config; | |
d6dfee7a | 14705 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
89b667f8 JB |
14706 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
14707 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
262ca2b0 MR |
14708 | dev_priv->display.update_primary_plane = |
14709 | i9xx_update_primary_plane; | |
f564048e | 14710 | } else { |
0e8ffe1b | 14711 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
5724dbd1 DL |
14712 | dev_priv->display.get_initial_plane_config = |
14713 | i9xx_get_initial_plane_config; | |
d6dfee7a | 14714 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
76e5a89c DV |
14715 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
14716 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
262ca2b0 MR |
14717 | dev_priv->display.update_primary_plane = |
14718 | i9xx_update_primary_plane; | |
f564048e | 14719 | } |
e70236a8 | 14720 | |
e70236a8 | 14721 | /* Returns the core display clock speed */ |
1652d19e VS |
14722 | if (IS_SKYLAKE(dev)) |
14723 | dev_priv->display.get_display_clock_speed = | |
14724 | skylake_get_display_clock_speed; | |
14725 | else if (IS_BROADWELL(dev)) | |
14726 | dev_priv->display.get_display_clock_speed = | |
14727 | broadwell_get_display_clock_speed; | |
14728 | else if (IS_HASWELL(dev)) | |
14729 | dev_priv->display.get_display_clock_speed = | |
14730 | haswell_get_display_clock_speed; | |
14731 | else if (IS_VALLEYVIEW(dev)) | |
25eb05fc JB |
14732 | dev_priv->display.get_display_clock_speed = |
14733 | valleyview_get_display_clock_speed; | |
b37a6434 VS |
14734 | else if (IS_GEN5(dev)) |
14735 | dev_priv->display.get_display_clock_speed = | |
14736 | ilk_get_display_clock_speed; | |
a7c66cd8 | 14737 | else if (IS_I945G(dev) || IS_BROADWATER(dev) || |
34edce2f | 14738 | IS_GEN6(dev) || IS_IVYBRIDGE(dev)) |
e70236a8 JB |
14739 | dev_priv->display.get_display_clock_speed = |
14740 | i945_get_display_clock_speed; | |
34edce2f VS |
14741 | else if (IS_GM45(dev)) |
14742 | dev_priv->display.get_display_clock_speed = | |
14743 | gm45_get_display_clock_speed; | |
14744 | else if (IS_CRESTLINE(dev)) | |
14745 | dev_priv->display.get_display_clock_speed = | |
14746 | i965gm_get_display_clock_speed; | |
14747 | else if (IS_PINEVIEW(dev)) | |
14748 | dev_priv->display.get_display_clock_speed = | |
14749 | pnv_get_display_clock_speed; | |
14750 | else if (IS_G33(dev) || IS_G4X(dev)) | |
14751 | dev_priv->display.get_display_clock_speed = | |
14752 | g33_get_display_clock_speed; | |
e70236a8 JB |
14753 | else if (IS_I915G(dev)) |
14754 | dev_priv->display.get_display_clock_speed = | |
14755 | i915_get_display_clock_speed; | |
257a7ffc | 14756 | else if (IS_I945GM(dev) || IS_845G(dev)) |
e70236a8 JB |
14757 | dev_priv->display.get_display_clock_speed = |
14758 | i9xx_misc_get_display_clock_speed; | |
257a7ffc DV |
14759 | else if (IS_PINEVIEW(dev)) |
14760 | dev_priv->display.get_display_clock_speed = | |
14761 | pnv_get_display_clock_speed; | |
e70236a8 JB |
14762 | else if (IS_I915GM(dev)) |
14763 | dev_priv->display.get_display_clock_speed = | |
14764 | i915gm_get_display_clock_speed; | |
14765 | else if (IS_I865G(dev)) | |
14766 | dev_priv->display.get_display_clock_speed = | |
14767 | i865_get_display_clock_speed; | |
f0f8a9ce | 14768 | else if (IS_I85X(dev)) |
e70236a8 | 14769 | dev_priv->display.get_display_clock_speed = |
1b1d2716 | 14770 | i85x_get_display_clock_speed; |
623e01e5 VS |
14771 | else { /* 830 */ |
14772 | WARN(!IS_I830(dev), "Unknown platform. Assuming 133 MHz CDCLK\n"); | |
e70236a8 JB |
14773 | dev_priv->display.get_display_clock_speed = |
14774 | i830_get_display_clock_speed; | |
623e01e5 | 14775 | } |
e70236a8 | 14776 | |
7c10a2b5 | 14777 | if (IS_GEN5(dev)) { |
3bb11b53 | 14778 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
3bb11b53 SJ |
14779 | } else if (IS_GEN6(dev)) { |
14780 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; | |
3bb11b53 SJ |
14781 | } else if (IS_IVYBRIDGE(dev)) { |
14782 | /* FIXME: detect B0+ stepping and use auto training */ | |
14783 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; | |
059b2fe9 | 14784 | } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
3bb11b53 | 14785 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
b432e5cf VS |
14786 | if (IS_BROADWELL(dev)) |
14787 | dev_priv->display.modeset_global_resources = | |
14788 | broadwell_modeset_global_resources; | |
30a970c6 JB |
14789 | } else if (IS_VALLEYVIEW(dev)) { |
14790 | dev_priv->display.modeset_global_resources = | |
14791 | valleyview_modeset_global_resources; | |
f8437dd1 VK |
14792 | } else if (IS_BROXTON(dev)) { |
14793 | dev_priv->display.modeset_global_resources = | |
14794 | broxton_modeset_global_resources; | |
e70236a8 | 14795 | } |
8c9f3aaf | 14796 | |
8c9f3aaf JB |
14797 | switch (INTEL_INFO(dev)->gen) { |
14798 | case 2: | |
14799 | dev_priv->display.queue_flip = intel_gen2_queue_flip; | |
14800 | break; | |
14801 | ||
14802 | case 3: | |
14803 | dev_priv->display.queue_flip = intel_gen3_queue_flip; | |
14804 | break; | |
14805 | ||
14806 | case 4: | |
14807 | case 5: | |
14808 | dev_priv->display.queue_flip = intel_gen4_queue_flip; | |
14809 | break; | |
14810 | ||
14811 | case 6: | |
14812 | dev_priv->display.queue_flip = intel_gen6_queue_flip; | |
14813 | break; | |
7c9017e5 | 14814 | case 7: |
4e0bbc31 | 14815 | case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */ |
7c9017e5 JB |
14816 | dev_priv->display.queue_flip = intel_gen7_queue_flip; |
14817 | break; | |
830c81db | 14818 | case 9: |
ba343e02 TU |
14819 | /* Drop through - unsupported since execlist only. */ |
14820 | default: | |
14821 | /* Default just returns -ENODEV to indicate unsupported */ | |
14822 | dev_priv->display.queue_flip = intel_default_queue_flip; | |
8c9f3aaf | 14823 | } |
7bd688cd JN |
14824 | |
14825 | intel_panel_init_backlight_funcs(dev); | |
e39b999a VS |
14826 | |
14827 | mutex_init(&dev_priv->pps_mutex); | |
e70236a8 JB |
14828 | } |
14829 | ||
b690e96c JB |
14830 | /* |
14831 | * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend, | |
14832 | * resume, or other times. This quirk makes sure that's the case for | |
14833 | * affected systems. | |
14834 | */ | |
0206e353 | 14835 | static void quirk_pipea_force(struct drm_device *dev) |
b690e96c JB |
14836 | { |
14837 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14838 | ||
14839 | dev_priv->quirks |= QUIRK_PIPEA_FORCE; | |
bc0daf48 | 14840 | DRM_INFO("applying pipe a force quirk\n"); |
b690e96c JB |
14841 | } |
14842 | ||
b6b5d049 VS |
14843 | static void quirk_pipeb_force(struct drm_device *dev) |
14844 | { | |
14845 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14846 | ||
14847 | dev_priv->quirks |= QUIRK_PIPEB_FORCE; | |
14848 | DRM_INFO("applying pipe b force quirk\n"); | |
14849 | } | |
14850 | ||
435793df KP |
14851 | /* |
14852 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason | |
14853 | */ | |
14854 | static void quirk_ssc_force_disable(struct drm_device *dev) | |
14855 | { | |
14856 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14857 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; | |
bc0daf48 | 14858 | DRM_INFO("applying lvds SSC disable quirk\n"); |
435793df KP |
14859 | } |
14860 | ||
4dca20ef | 14861 | /* |
5a15ab5b CE |
14862 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight |
14863 | * brightness value | |
4dca20ef CE |
14864 | */ |
14865 | static void quirk_invert_brightness(struct drm_device *dev) | |
14866 | { | |
14867 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14868 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; | |
bc0daf48 | 14869 | DRM_INFO("applying inverted panel brightness quirk\n"); |
435793df KP |
14870 | } |
14871 | ||
9c72cc6f SD |
14872 | /* Some VBT's incorrectly indicate no backlight is present */ |
14873 | static void quirk_backlight_present(struct drm_device *dev) | |
14874 | { | |
14875 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14876 | dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT; | |
14877 | DRM_INFO("applying backlight present quirk\n"); | |
14878 | } | |
14879 | ||
b690e96c JB |
14880 | struct intel_quirk { |
14881 | int device; | |
14882 | int subsystem_vendor; | |
14883 | int subsystem_device; | |
14884 | void (*hook)(struct drm_device *dev); | |
14885 | }; | |
14886 | ||
5f85f176 EE |
14887 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ |
14888 | struct intel_dmi_quirk { | |
14889 | void (*hook)(struct drm_device *dev); | |
14890 | const struct dmi_system_id (*dmi_id_list)[]; | |
14891 | }; | |
14892 | ||
14893 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) | |
14894 | { | |
14895 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); | |
14896 | return 1; | |
14897 | } | |
14898 | ||
14899 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { | |
14900 | { | |
14901 | .dmi_id_list = &(const struct dmi_system_id[]) { | |
14902 | { | |
14903 | .callback = intel_dmi_reverse_brightness, | |
14904 | .ident = "NCR Corporation", | |
14905 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), | |
14906 | DMI_MATCH(DMI_PRODUCT_NAME, ""), | |
14907 | }, | |
14908 | }, | |
14909 | { } /* terminating entry */ | |
14910 | }, | |
14911 | .hook = quirk_invert_brightness, | |
14912 | }, | |
14913 | }; | |
14914 | ||
c43b5634 | 14915 | static struct intel_quirk intel_quirks[] = { |
b690e96c JB |
14916 | /* Toshiba Protege R-205, S-209 needs pipe A force quirk */ |
14917 | { 0x2592, 0x1179, 0x0001, quirk_pipea_force }, | |
14918 | ||
b690e96c JB |
14919 | /* ThinkPad T60 needs pipe A force quirk (bug #16494) */ |
14920 | { 0x2782, 0x17aa, 0x201a, quirk_pipea_force }, | |
14921 | ||
5f080c0f VS |
14922 | /* 830 needs to leave pipe A & dpll A up */ |
14923 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, | |
14924 | ||
b6b5d049 VS |
14925 | /* 830 needs to leave pipe B & dpll B up */ |
14926 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force }, | |
14927 | ||
435793df KP |
14928 | /* Lenovo U160 cannot use SSC on LVDS */ |
14929 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, | |
070d329a MAS |
14930 | |
14931 | /* Sony Vaio Y cannot use SSC on LVDS */ | |
14932 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, | |
5a15ab5b | 14933 | |
be505f64 AH |
14934 | /* Acer Aspire 5734Z must invert backlight brightness */ |
14935 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, | |
14936 | ||
14937 | /* Acer/eMachines G725 */ | |
14938 | { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness }, | |
14939 | ||
14940 | /* Acer/eMachines e725 */ | |
14941 | { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness }, | |
14942 | ||
14943 | /* Acer/Packard Bell NCL20 */ | |
14944 | { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness }, | |
14945 | ||
14946 | /* Acer Aspire 4736Z */ | |
14947 | { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness }, | |
0f540c3a JN |
14948 | |
14949 | /* Acer Aspire 5336 */ | |
14950 | { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness }, | |
2e93a1aa SD |
14951 | |
14952 | /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */ | |
14953 | { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present }, | |
d4967d8c | 14954 | |
dfb3d47b SD |
14955 | /* Acer C720 Chromebook (Core i3 4005U) */ |
14956 | { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present }, | |
14957 | ||
b2a9601c | 14958 | /* Apple Macbook 2,1 (Core 2 T7400) */ |
14959 | { 0x27a2, 0x8086, 0x7270, quirk_backlight_present }, | |
14960 | ||
d4967d8c SD |
14961 | /* Toshiba CB35 Chromebook (Celeron 2955U) */ |
14962 | { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present }, | |
724cb06f SD |
14963 | |
14964 | /* HP Chromebook 14 (Celeron 2955U) */ | |
14965 | { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present }, | |
cf6f0af9 JN |
14966 | |
14967 | /* Dell Chromebook 11 */ | |
14968 | { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present }, | |
b690e96c JB |
14969 | }; |
14970 | ||
14971 | static void intel_init_quirks(struct drm_device *dev) | |
14972 | { | |
14973 | struct pci_dev *d = dev->pdev; | |
14974 | int i; | |
14975 | ||
14976 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { | |
14977 | struct intel_quirk *q = &intel_quirks[i]; | |
14978 | ||
14979 | if (d->device == q->device && | |
14980 | (d->subsystem_vendor == q->subsystem_vendor || | |
14981 | q->subsystem_vendor == PCI_ANY_ID) && | |
14982 | (d->subsystem_device == q->subsystem_device || | |
14983 | q->subsystem_device == PCI_ANY_ID)) | |
14984 | q->hook(dev); | |
14985 | } | |
5f85f176 EE |
14986 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { |
14987 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) | |
14988 | intel_dmi_quirks[i].hook(dev); | |
14989 | } | |
b690e96c JB |
14990 | } |
14991 | ||
9cce37f4 JB |
14992 | /* Disable the VGA plane that we never use */ |
14993 | static void i915_disable_vga(struct drm_device *dev) | |
14994 | { | |
14995 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14996 | u8 sr1; | |
766aa1c4 | 14997 | u32 vga_reg = i915_vgacntrl_reg(dev); |
9cce37f4 | 14998 | |
2b37c616 | 14999 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
9cce37f4 | 15000 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
3fdcf431 | 15001 | outb(SR01, VGA_SR_INDEX); |
9cce37f4 JB |
15002 | sr1 = inb(VGA_SR_DATA); |
15003 | outb(sr1 | 1<<5, VGA_SR_DATA); | |
15004 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); | |
15005 | udelay(300); | |
15006 | ||
01f5a626 | 15007 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
9cce37f4 JB |
15008 | POSTING_READ(vga_reg); |
15009 | } | |
15010 | ||
f817586c DV |
15011 | void intel_modeset_init_hw(struct drm_device *dev) |
15012 | { | |
b6283055 | 15013 | intel_update_cdclk(dev); |
a8f78b58 | 15014 | intel_prepare_ddi(dev); |
f817586c | 15015 | intel_init_clock_gating(dev); |
8090c6b9 | 15016 | intel_enable_gt_powersave(dev); |
f817586c DV |
15017 | } |
15018 | ||
79e53945 JB |
15019 | void intel_modeset_init(struct drm_device *dev) |
15020 | { | |
652c393a | 15021 | struct drm_i915_private *dev_priv = dev->dev_private; |
1fe47785 | 15022 | int sprite, ret; |
8cc87b75 | 15023 | enum pipe pipe; |
46f297fb | 15024 | struct intel_crtc *crtc; |
79e53945 JB |
15025 | |
15026 | drm_mode_config_init(dev); | |
15027 | ||
15028 | dev->mode_config.min_width = 0; | |
15029 | dev->mode_config.min_height = 0; | |
15030 | ||
019d96cb DA |
15031 | dev->mode_config.preferred_depth = 24; |
15032 | dev->mode_config.prefer_shadow = 1; | |
15033 | ||
25bab385 TU |
15034 | dev->mode_config.allow_fb_modifiers = true; |
15035 | ||
e6ecefaa | 15036 | dev->mode_config.funcs = &intel_mode_funcs; |
79e53945 | 15037 | |
b690e96c JB |
15038 | intel_init_quirks(dev); |
15039 | ||
1fa61106 ED |
15040 | intel_init_pm(dev); |
15041 | ||
e3c74757 BW |
15042 | if (INTEL_INFO(dev)->num_pipes == 0) |
15043 | return; | |
15044 | ||
e70236a8 | 15045 | intel_init_display(dev); |
7c10a2b5 | 15046 | intel_init_audio(dev); |
e70236a8 | 15047 | |
a6c45cf0 CW |
15048 | if (IS_GEN2(dev)) { |
15049 | dev->mode_config.max_width = 2048; | |
15050 | dev->mode_config.max_height = 2048; | |
15051 | } else if (IS_GEN3(dev)) { | |
5e4d6fa7 KP |
15052 | dev->mode_config.max_width = 4096; |
15053 | dev->mode_config.max_height = 4096; | |
79e53945 | 15054 | } else { |
a6c45cf0 CW |
15055 | dev->mode_config.max_width = 8192; |
15056 | dev->mode_config.max_height = 8192; | |
79e53945 | 15057 | } |
068be561 | 15058 | |
dc41c154 VS |
15059 | if (IS_845G(dev) || IS_I865G(dev)) { |
15060 | dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512; | |
15061 | dev->mode_config.cursor_height = 1023; | |
15062 | } else if (IS_GEN2(dev)) { | |
068be561 DL |
15063 | dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH; |
15064 | dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT; | |
15065 | } else { | |
15066 | dev->mode_config.cursor_width = MAX_CURSOR_WIDTH; | |
15067 | dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT; | |
15068 | } | |
15069 | ||
5d4545ae | 15070 | dev->mode_config.fb_base = dev_priv->gtt.mappable_base; |
79e53945 | 15071 | |
28c97730 | 15072 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
7eb552ae BW |
15073 | INTEL_INFO(dev)->num_pipes, |
15074 | INTEL_INFO(dev)->num_pipes > 1 ? "s" : ""); | |
79e53945 | 15075 | |
055e393f | 15076 | for_each_pipe(dev_priv, pipe) { |
8cc87b75 | 15077 | intel_crtc_init(dev, pipe); |
3bdcfc0c | 15078 | for_each_sprite(dev_priv, pipe, sprite) { |
1fe47785 | 15079 | ret = intel_plane_init(dev, pipe, sprite); |
7f1f3851 | 15080 | if (ret) |
06da8da2 | 15081 | DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n", |
1fe47785 | 15082 | pipe_name(pipe), sprite_name(pipe, sprite), ret); |
7f1f3851 | 15083 | } |
79e53945 JB |
15084 | } |
15085 | ||
f42bb70d JB |
15086 | intel_init_dpio(dev); |
15087 | ||
e72f9fbf | 15088 | intel_shared_dpll_init(dev); |
ee7b9f93 | 15089 | |
9cce37f4 JB |
15090 | /* Just disable it once at startup */ |
15091 | i915_disable_vga(dev); | |
79e53945 | 15092 | intel_setup_outputs(dev); |
11be49eb CW |
15093 | |
15094 | /* Just in case the BIOS is doing something questionable. */ | |
7ff0ebcc | 15095 | intel_fbc_disable(dev); |
fa9fa083 | 15096 | |
6e9f798d | 15097 | drm_modeset_lock_all(dev); |
fa9fa083 | 15098 | intel_modeset_setup_hw_state(dev, false); |
6e9f798d | 15099 | drm_modeset_unlock_all(dev); |
46f297fb | 15100 | |
d3fcc808 | 15101 | for_each_intel_crtc(dev, crtc) { |
46f297fb JB |
15102 | if (!crtc->active) |
15103 | continue; | |
15104 | ||
46f297fb | 15105 | /* |
46f297fb JB |
15106 | * Note that reserving the BIOS fb up front prevents us |
15107 | * from stuffing other stolen allocations like the ring | |
15108 | * on top. This prevents some ugliness at boot time, and | |
15109 | * can even allow for smooth boot transitions if the BIOS | |
15110 | * fb is large enough for the active pipe configuration. | |
15111 | */ | |
5724dbd1 DL |
15112 | if (dev_priv->display.get_initial_plane_config) { |
15113 | dev_priv->display.get_initial_plane_config(crtc, | |
46f297fb JB |
15114 | &crtc->plane_config); |
15115 | /* | |
15116 | * If the fb is shared between multiple heads, we'll | |
15117 | * just get the first one. | |
15118 | */ | |
f6936e29 | 15119 | intel_find_initial_plane_obj(crtc, &crtc->plane_config); |
46f297fb | 15120 | } |
46f297fb | 15121 | } |
2c7111db CW |
15122 | } |
15123 | ||
7fad798e DV |
15124 | static void intel_enable_pipe_a(struct drm_device *dev) |
15125 | { | |
15126 | struct intel_connector *connector; | |
15127 | struct drm_connector *crt = NULL; | |
15128 | struct intel_load_detect_pipe load_detect_temp; | |
208bf9fd | 15129 | struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx; |
7fad798e DV |
15130 | |
15131 | /* We can't just switch on the pipe A, we need to set things up with a | |
15132 | * proper mode and output configuration. As a gross hack, enable pipe A | |
15133 | * by enabling the load detect pipe once. */ | |
3a3371ff | 15134 | for_each_intel_connector(dev, connector) { |
7fad798e DV |
15135 | if (connector->encoder->type == INTEL_OUTPUT_ANALOG) { |
15136 | crt = &connector->base; | |
15137 | break; | |
15138 | } | |
15139 | } | |
15140 | ||
15141 | if (!crt) | |
15142 | return; | |
15143 | ||
208bf9fd | 15144 | if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, ctx)) |
49172fee | 15145 | intel_release_load_detect_pipe(crt, &load_detect_temp, ctx); |
7fad798e DV |
15146 | } |
15147 | ||
fa555837 DV |
15148 | static bool |
15149 | intel_check_plane_mapping(struct intel_crtc *crtc) | |
15150 | { | |
7eb552ae BW |
15151 | struct drm_device *dev = crtc->base.dev; |
15152 | struct drm_i915_private *dev_priv = dev->dev_private; | |
fa555837 DV |
15153 | u32 reg, val; |
15154 | ||
7eb552ae | 15155 | if (INTEL_INFO(dev)->num_pipes == 1) |
fa555837 DV |
15156 | return true; |
15157 | ||
15158 | reg = DSPCNTR(!crtc->plane); | |
15159 | val = I915_READ(reg); | |
15160 | ||
15161 | if ((val & DISPLAY_PLANE_ENABLE) && | |
15162 | (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe)) | |
15163 | return false; | |
15164 | ||
15165 | return true; | |
15166 | } | |
15167 | ||
24929352 DV |
15168 | static void intel_sanitize_crtc(struct intel_crtc *crtc) |
15169 | { | |
15170 | struct drm_device *dev = crtc->base.dev; | |
15171 | struct drm_i915_private *dev_priv = dev->dev_private; | |
b17d48e2 | 15172 | struct intel_encoder *encoder; |
fa555837 | 15173 | u32 reg; |
b17d48e2 | 15174 | bool enable; |
24929352 | 15175 | |
24929352 | 15176 | /* Clear any frame start delays used for debugging left by the BIOS */ |
6e3c9717 | 15177 | reg = PIPECONF(crtc->config->cpu_transcoder); |
24929352 DV |
15178 | I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
15179 | ||
d3eaf884 | 15180 | /* restore vblank interrupts to correct state */ |
9625604c | 15181 | drm_crtc_vblank_reset(&crtc->base); |
d297e103 VS |
15182 | if (crtc->active) { |
15183 | update_scanline_offset(crtc); | |
9625604c DV |
15184 | drm_crtc_vblank_on(&crtc->base); |
15185 | } | |
d3eaf884 | 15186 | |
24929352 | 15187 | /* We need to sanitize the plane -> pipe mapping first because this will |
fa555837 DV |
15188 | * disable the crtc (and hence change the state) if it is wrong. Note |
15189 | * that gen4+ has a fixed plane -> pipe mapping. */ | |
15190 | if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) { | |
24929352 DV |
15191 | bool plane; |
15192 | ||
24929352 DV |
15193 | DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n", |
15194 | crtc->base.base.id); | |
15195 | ||
15196 | /* Pipe has the wrong plane attached and the plane is active. | |
15197 | * Temporarily change the plane mapping and disable everything | |
15198 | * ... */ | |
15199 | plane = crtc->plane; | |
b70709a6 | 15200 | to_intel_plane_state(crtc->base.primary->state)->visible = true; |
24929352 | 15201 | crtc->plane = !plane; |
b17d48e2 | 15202 | intel_crtc_disable_noatomic(&crtc->base); |
24929352 | 15203 | crtc->plane = plane; |
24929352 | 15204 | } |
24929352 | 15205 | |
7fad798e DV |
15206 | if (dev_priv->quirks & QUIRK_PIPEA_FORCE && |
15207 | crtc->pipe == PIPE_A && !crtc->active) { | |
15208 | /* BIOS forgot to enable pipe A, this mostly happens after | |
15209 | * resume. Force-enable the pipe to fix this, the update_dpms | |
15210 | * call below we restore the pipe to the right state, but leave | |
15211 | * the required bits on. */ | |
15212 | intel_enable_pipe_a(dev); | |
15213 | } | |
15214 | ||
24929352 DV |
15215 | /* Adjust the state of the output pipe according to whether we |
15216 | * have active connectors/encoders. */ | |
b17d48e2 ML |
15217 | enable = false; |
15218 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) | |
15219 | enable |= encoder->connectors_active; | |
24929352 | 15220 | |
b17d48e2 ML |
15221 | if (!enable) |
15222 | intel_crtc_disable_noatomic(&crtc->base); | |
24929352 | 15223 | |
53d9f4e9 | 15224 | if (crtc->active != crtc->base.state->active) { |
24929352 DV |
15225 | |
15226 | /* This can happen either due to bugs in the get_hw_state | |
b17d48e2 ML |
15227 | * functions or because of calls to intel_crtc_disable_noatomic, |
15228 | * or because the pipe is force-enabled due to the | |
24929352 DV |
15229 | * pipe A quirk. */ |
15230 | DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n", | |
15231 | crtc->base.base.id, | |
83d65738 | 15232 | crtc->base.state->enable ? "enabled" : "disabled", |
24929352 DV |
15233 | crtc->active ? "enabled" : "disabled"); |
15234 | ||
83d65738 | 15235 | crtc->base.state->enable = crtc->active; |
49d6fa21 | 15236 | crtc->base.state->active = crtc->active; |
24929352 DV |
15237 | crtc->base.enabled = crtc->active; |
15238 | ||
15239 | /* Because we only establish the connector -> encoder -> | |
15240 | * crtc links if something is active, this means the | |
15241 | * crtc is now deactivated. Break the links. connector | |
15242 | * -> encoder links are only establish when things are | |
15243 | * actually up, hence no need to break them. */ | |
15244 | WARN_ON(crtc->active); | |
15245 | ||
15246 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) { | |
15247 | WARN_ON(encoder->connectors_active); | |
15248 | encoder->base.crtc = NULL; | |
15249 | } | |
15250 | } | |
c5ab3bc0 | 15251 | |
a3ed6aad | 15252 | if (crtc->active || HAS_GMCH_DISPLAY(dev)) { |
4cc31489 DV |
15253 | /* |
15254 | * We start out with underrun reporting disabled to avoid races. | |
15255 | * For correct bookkeeping mark this on active crtcs. | |
15256 | * | |
c5ab3bc0 DV |
15257 | * Also on gmch platforms we dont have any hardware bits to |
15258 | * disable the underrun reporting. Which means we need to start | |
15259 | * out with underrun reporting disabled also on inactive pipes, | |
15260 | * since otherwise we'll complain about the garbage we read when | |
15261 | * e.g. coming up after runtime pm. | |
15262 | * | |
4cc31489 DV |
15263 | * No protection against concurrent access is required - at |
15264 | * worst a fifo underrun happens which also sets this to false. | |
15265 | */ | |
15266 | crtc->cpu_fifo_underrun_disabled = true; | |
15267 | crtc->pch_fifo_underrun_disabled = true; | |
15268 | } | |
24929352 DV |
15269 | } |
15270 | ||
15271 | static void intel_sanitize_encoder(struct intel_encoder *encoder) | |
15272 | { | |
15273 | struct intel_connector *connector; | |
15274 | struct drm_device *dev = encoder->base.dev; | |
15275 | ||
15276 | /* We need to check both for a crtc link (meaning that the | |
15277 | * encoder is active and trying to read from a pipe) and the | |
15278 | * pipe itself being active. */ | |
15279 | bool has_active_crtc = encoder->base.crtc && | |
15280 | to_intel_crtc(encoder->base.crtc)->active; | |
15281 | ||
15282 | if (encoder->connectors_active && !has_active_crtc) { | |
15283 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", | |
15284 | encoder->base.base.id, | |
8e329a03 | 15285 | encoder->base.name); |
24929352 DV |
15286 | |
15287 | /* Connector is active, but has no active pipe. This is | |
15288 | * fallout from our resume register restoring. Disable | |
15289 | * the encoder manually again. */ | |
15290 | if (encoder->base.crtc) { | |
15291 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", | |
15292 | encoder->base.base.id, | |
8e329a03 | 15293 | encoder->base.name); |
24929352 | 15294 | encoder->disable(encoder); |
a62d1497 VS |
15295 | if (encoder->post_disable) |
15296 | encoder->post_disable(encoder); | |
24929352 | 15297 | } |
7f1950fb EE |
15298 | encoder->base.crtc = NULL; |
15299 | encoder->connectors_active = false; | |
24929352 DV |
15300 | |
15301 | /* Inconsistent output/port/pipe state happens presumably due to | |
15302 | * a bug in one of the get_hw_state functions. Or someplace else | |
15303 | * in our code, like the register restore mess on resume. Clamp | |
15304 | * things to off as a safer default. */ | |
3a3371ff | 15305 | for_each_intel_connector(dev, connector) { |
24929352 DV |
15306 | if (connector->encoder != encoder) |
15307 | continue; | |
7f1950fb EE |
15308 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
15309 | connector->base.encoder = NULL; | |
24929352 DV |
15310 | } |
15311 | } | |
15312 | /* Enabled encoders without active connectors will be fixed in | |
15313 | * the crtc fixup. */ | |
15314 | } | |
15315 | ||
04098753 | 15316 | void i915_redisable_vga_power_on(struct drm_device *dev) |
0fde901f KM |
15317 | { |
15318 | struct drm_i915_private *dev_priv = dev->dev_private; | |
766aa1c4 | 15319 | u32 vga_reg = i915_vgacntrl_reg(dev); |
0fde901f | 15320 | |
04098753 ID |
15321 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
15322 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); | |
15323 | i915_disable_vga(dev); | |
15324 | } | |
15325 | } | |
15326 | ||
15327 | void i915_redisable_vga(struct drm_device *dev) | |
15328 | { | |
15329 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15330 | ||
8dc8a27c PZ |
15331 | /* This function can be called both from intel_modeset_setup_hw_state or |
15332 | * at a very early point in our resume sequence, where the power well | |
15333 | * structures are not yet restored. Since this function is at a very | |
15334 | * paranoid "someone might have enabled VGA while we were not looking" | |
15335 | * level, just check if the power well is enabled instead of trying to | |
15336 | * follow the "don't touch the power well if we don't need it" policy | |
15337 | * the rest of the driver uses. */ | |
f458ebbc | 15338 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_VGA)) |
8dc8a27c PZ |
15339 | return; |
15340 | ||
04098753 | 15341 | i915_redisable_vga_power_on(dev); |
0fde901f KM |
15342 | } |
15343 | ||
98ec7739 VS |
15344 | static bool primary_get_hw_state(struct intel_crtc *crtc) |
15345 | { | |
15346 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; | |
15347 | ||
15348 | if (!crtc->active) | |
15349 | return false; | |
15350 | ||
15351 | return I915_READ(DSPCNTR(crtc->plane)) & DISPLAY_PLANE_ENABLE; | |
15352 | } | |
15353 | ||
30e984df | 15354 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
24929352 DV |
15355 | { |
15356 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15357 | enum pipe pipe; | |
24929352 DV |
15358 | struct intel_crtc *crtc; |
15359 | struct intel_encoder *encoder; | |
15360 | struct intel_connector *connector; | |
5358901f | 15361 | int i; |
24929352 | 15362 | |
d3fcc808 | 15363 | for_each_intel_crtc(dev, crtc) { |
b70709a6 ML |
15364 | struct drm_plane *primary = crtc->base.primary; |
15365 | struct intel_plane_state *plane_state; | |
15366 | ||
6e3c9717 | 15367 | memset(crtc->config, 0, sizeof(*crtc->config)); |
f7217905 | 15368 | crtc->config->base.crtc = &crtc->base; |
3b117c8f | 15369 | |
6e3c9717 | 15370 | crtc->config->quirks |= PIPE_CONFIG_QUIRK_INHERITED_MODE; |
9953599b | 15371 | |
0e8ffe1b | 15372 | crtc->active = dev_priv->display.get_pipe_config(crtc, |
6e3c9717 | 15373 | crtc->config); |
24929352 | 15374 | |
83d65738 | 15375 | crtc->base.state->enable = crtc->active; |
49d6fa21 | 15376 | crtc->base.state->active = crtc->active; |
24929352 | 15377 | crtc->base.enabled = crtc->active; |
b8b7fade | 15378 | crtc->base.hwmode = crtc->config->base.adjusted_mode; |
b70709a6 ML |
15379 | |
15380 | plane_state = to_intel_plane_state(primary->state); | |
15381 | plane_state->visible = primary_get_hw_state(crtc); | |
24929352 DV |
15382 | |
15383 | DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n", | |
15384 | crtc->base.base.id, | |
15385 | crtc->active ? "enabled" : "disabled"); | |
15386 | } | |
15387 | ||
5358901f DV |
15388 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
15389 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
15390 | ||
3e369b76 ACO |
15391 | pll->on = pll->get_hw_state(dev_priv, pll, |
15392 | &pll->config.hw_state); | |
5358901f | 15393 | pll->active = 0; |
3e369b76 | 15394 | pll->config.crtc_mask = 0; |
d3fcc808 | 15395 | for_each_intel_crtc(dev, crtc) { |
1e6f2ddc | 15396 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) { |
5358901f | 15397 | pll->active++; |
3e369b76 | 15398 | pll->config.crtc_mask |= 1 << crtc->pipe; |
1e6f2ddc | 15399 | } |
5358901f | 15400 | } |
5358901f | 15401 | |
1e6f2ddc | 15402 | DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n", |
3e369b76 | 15403 | pll->name, pll->config.crtc_mask, pll->on); |
bd2bb1b9 | 15404 | |
3e369b76 | 15405 | if (pll->config.crtc_mask) |
bd2bb1b9 | 15406 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
5358901f DV |
15407 | } |
15408 | ||
b2784e15 | 15409 | for_each_intel_encoder(dev, encoder) { |
24929352 DV |
15410 | pipe = 0; |
15411 | ||
15412 | if (encoder->get_hw_state(encoder, &pipe)) { | |
045ac3b5 JB |
15413 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
15414 | encoder->base.crtc = &crtc->base; | |
6e3c9717 | 15415 | encoder->get_config(encoder, crtc->config); |
24929352 DV |
15416 | } else { |
15417 | encoder->base.crtc = NULL; | |
15418 | } | |
15419 | ||
15420 | encoder->connectors_active = false; | |
6f2bcceb | 15421 | DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n", |
24929352 | 15422 | encoder->base.base.id, |
8e329a03 | 15423 | encoder->base.name, |
24929352 | 15424 | encoder->base.crtc ? "enabled" : "disabled", |
6f2bcceb | 15425 | pipe_name(pipe)); |
24929352 DV |
15426 | } |
15427 | ||
3a3371ff | 15428 | for_each_intel_connector(dev, connector) { |
24929352 DV |
15429 | if (connector->get_hw_state(connector)) { |
15430 | connector->base.dpms = DRM_MODE_DPMS_ON; | |
15431 | connector->encoder->connectors_active = true; | |
15432 | connector->base.encoder = &connector->encoder->base; | |
15433 | } else { | |
15434 | connector->base.dpms = DRM_MODE_DPMS_OFF; | |
15435 | connector->base.encoder = NULL; | |
15436 | } | |
15437 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", | |
15438 | connector->base.base.id, | |
c23cc417 | 15439 | connector->base.name, |
24929352 DV |
15440 | connector->base.encoder ? "enabled" : "disabled"); |
15441 | } | |
30e984df DV |
15442 | } |
15443 | ||
15444 | /* Scan out the current hw modeset state, sanitizes it and maps it into the drm | |
15445 | * and i915 state tracking structures. */ | |
15446 | void intel_modeset_setup_hw_state(struct drm_device *dev, | |
15447 | bool force_restore) | |
15448 | { | |
15449 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15450 | enum pipe pipe; | |
30e984df DV |
15451 | struct intel_crtc *crtc; |
15452 | struct intel_encoder *encoder; | |
35c95375 | 15453 | int i; |
30e984df DV |
15454 | |
15455 | intel_modeset_readout_hw_state(dev); | |
24929352 | 15456 | |
babea61d JB |
15457 | /* |
15458 | * Now that we have the config, copy it to each CRTC struct | |
15459 | * Note that this could go away if we move to using crtc_config | |
15460 | * checking everywhere. | |
15461 | */ | |
d3fcc808 | 15462 | for_each_intel_crtc(dev, crtc) { |
d330a953 | 15463 | if (crtc->active && i915.fastboot) { |
6e3c9717 ACO |
15464 | intel_mode_from_pipe_config(&crtc->base.mode, |
15465 | crtc->config); | |
babea61d JB |
15466 | DRM_DEBUG_KMS("[CRTC:%d] found active mode: ", |
15467 | crtc->base.base.id); | |
15468 | drm_mode_debug_printmodeline(&crtc->base.mode); | |
15469 | } | |
15470 | } | |
15471 | ||
24929352 | 15472 | /* HW state is read out, now we need to sanitize this mess. */ |
b2784e15 | 15473 | for_each_intel_encoder(dev, encoder) { |
24929352 DV |
15474 | intel_sanitize_encoder(encoder); |
15475 | } | |
15476 | ||
055e393f | 15477 | for_each_pipe(dev_priv, pipe) { |
24929352 DV |
15478 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
15479 | intel_sanitize_crtc(crtc); | |
6e3c9717 ACO |
15480 | intel_dump_pipe_config(crtc, crtc->config, |
15481 | "[setup_hw_state]"); | |
24929352 | 15482 | } |
9a935856 | 15483 | |
d29b2f9d ACO |
15484 | intel_modeset_update_connector_atomic_state(dev); |
15485 | ||
35c95375 DV |
15486 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
15487 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
15488 | ||
15489 | if (!pll->on || pll->active) | |
15490 | continue; | |
15491 | ||
15492 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name); | |
15493 | ||
15494 | pll->disable(dev_priv, pll); | |
15495 | pll->on = false; | |
15496 | } | |
15497 | ||
3078999f PB |
15498 | if (IS_GEN9(dev)) |
15499 | skl_wm_get_hw_state(dev); | |
15500 | else if (HAS_PCH_SPLIT(dev)) | |
243e6a44 VS |
15501 | ilk_wm_get_hw_state(dev); |
15502 | ||
45e2b5f6 | 15503 | if (force_restore) { |
7d0bc1ea VS |
15504 | i915_redisable_vga(dev); |
15505 | ||
f30da187 DV |
15506 | /* |
15507 | * We need to use raw interfaces for restoring state to avoid | |
15508 | * checking (bogus) intermediate states. | |
15509 | */ | |
055e393f | 15510 | for_each_pipe(dev_priv, pipe) { |
b5644d05 JB |
15511 | struct drm_crtc *crtc = |
15512 | dev_priv->pipe_to_crtc_mapping[pipe]; | |
f30da187 | 15513 | |
83a57153 | 15514 | intel_crtc_restore_mode(crtc); |
45e2b5f6 DV |
15515 | } |
15516 | } else { | |
15517 | intel_modeset_update_staged_output_state(dev); | |
15518 | } | |
8af6cf88 DV |
15519 | |
15520 | intel_modeset_check_state(dev); | |
2c7111db CW |
15521 | } |
15522 | ||
15523 | void intel_modeset_gem_init(struct drm_device *dev) | |
15524 | { | |
92122789 | 15525 | struct drm_i915_private *dev_priv = dev->dev_private; |
484b41dd | 15526 | struct drm_crtc *c; |
2ff8fde1 | 15527 | struct drm_i915_gem_object *obj; |
e0d6149b | 15528 | int ret; |
484b41dd | 15529 | |
ae48434c ID |
15530 | mutex_lock(&dev->struct_mutex); |
15531 | intel_init_gt_powersave(dev); | |
15532 | mutex_unlock(&dev->struct_mutex); | |
15533 | ||
92122789 JB |
15534 | /* |
15535 | * There may be no VBT; and if the BIOS enabled SSC we can | |
15536 | * just keep using it to avoid unnecessary flicker. Whereas if the | |
15537 | * BIOS isn't using it, don't assume it will work even if the VBT | |
15538 | * indicates as much. | |
15539 | */ | |
15540 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) | |
15541 | dev_priv->vbt.lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & | |
15542 | DREF_SSC1_ENABLE); | |
15543 | ||
1833b134 | 15544 | intel_modeset_init_hw(dev); |
02e792fb DV |
15545 | |
15546 | intel_setup_overlay(dev); | |
484b41dd JB |
15547 | |
15548 | /* | |
15549 | * Make sure any fbs we allocated at startup are properly | |
15550 | * pinned & fenced. When we do the allocation it's too early | |
15551 | * for this. | |
15552 | */ | |
70e1e0ec | 15553 | for_each_crtc(dev, c) { |
2ff8fde1 MR |
15554 | obj = intel_fb_obj(c->primary->fb); |
15555 | if (obj == NULL) | |
484b41dd JB |
15556 | continue; |
15557 | ||
e0d6149b TU |
15558 | mutex_lock(&dev->struct_mutex); |
15559 | ret = intel_pin_and_fence_fb_obj(c->primary, | |
15560 | c->primary->fb, | |
15561 | c->primary->state, | |
15562 | NULL); | |
15563 | mutex_unlock(&dev->struct_mutex); | |
15564 | if (ret) { | |
484b41dd JB |
15565 | DRM_ERROR("failed to pin boot fb on pipe %d\n", |
15566 | to_intel_crtc(c)->pipe); | |
66e514c1 DA |
15567 | drm_framebuffer_unreference(c->primary->fb); |
15568 | c->primary->fb = NULL; | |
36750f28 | 15569 | c->primary->crtc = c->primary->state->crtc = NULL; |
afd65eb4 | 15570 | update_state_fb(c->primary); |
36750f28 | 15571 | c->state->plane_mask &= ~(1 << drm_plane_index(c->primary)); |
484b41dd JB |
15572 | } |
15573 | } | |
0962c3c9 VS |
15574 | |
15575 | intel_backlight_register(dev); | |
79e53945 JB |
15576 | } |
15577 | ||
4932e2c3 ID |
15578 | void intel_connector_unregister(struct intel_connector *intel_connector) |
15579 | { | |
15580 | struct drm_connector *connector = &intel_connector->base; | |
15581 | ||
15582 | intel_panel_destroy_backlight(connector); | |
34ea3d38 | 15583 | drm_connector_unregister(connector); |
4932e2c3 ID |
15584 | } |
15585 | ||
79e53945 JB |
15586 | void intel_modeset_cleanup(struct drm_device *dev) |
15587 | { | |
652c393a | 15588 | struct drm_i915_private *dev_priv = dev->dev_private; |
d9255d57 | 15589 | struct drm_connector *connector; |
652c393a | 15590 | |
2eb5252e ID |
15591 | intel_disable_gt_powersave(dev); |
15592 | ||
0962c3c9 VS |
15593 | intel_backlight_unregister(dev); |
15594 | ||
fd0c0642 DV |
15595 | /* |
15596 | * Interrupts and polling as the first thing to avoid creating havoc. | |
2eb5252e | 15597 | * Too much stuff here (turning of connectors, ...) would |
fd0c0642 DV |
15598 | * experience fancy races otherwise. |
15599 | */ | |
2aeb7d3a | 15600 | intel_irq_uninstall(dev_priv); |
eb21b92b | 15601 | |
fd0c0642 DV |
15602 | /* |
15603 | * Due to the hpd irq storm handling the hotplug work can re-arm the | |
15604 | * poll handlers. Hence disable polling after hpd handling is shut down. | |
15605 | */ | |
f87ea761 | 15606 | drm_kms_helper_poll_fini(dev); |
fd0c0642 | 15607 | |
652c393a JB |
15608 | mutex_lock(&dev->struct_mutex); |
15609 | ||
723bfd70 JB |
15610 | intel_unregister_dsm_handler(); |
15611 | ||
7ff0ebcc | 15612 | intel_fbc_disable(dev); |
e70236a8 | 15613 | |
69341a5e KH |
15614 | mutex_unlock(&dev->struct_mutex); |
15615 | ||
1630fe75 CW |
15616 | /* flush any delayed tasks or pending work */ |
15617 | flush_scheduled_work(); | |
15618 | ||
db31af1d JN |
15619 | /* destroy the backlight and sysfs files before encoders/connectors */ |
15620 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { | |
4932e2c3 ID |
15621 | struct intel_connector *intel_connector; |
15622 | ||
15623 | intel_connector = to_intel_connector(connector); | |
15624 | intel_connector->unregister(intel_connector); | |
db31af1d | 15625 | } |
d9255d57 | 15626 | |
79e53945 | 15627 | drm_mode_config_cleanup(dev); |
4d7bb011 DV |
15628 | |
15629 | intel_cleanup_overlay(dev); | |
ae48434c ID |
15630 | |
15631 | mutex_lock(&dev->struct_mutex); | |
15632 | intel_cleanup_gt_powersave(dev); | |
15633 | mutex_unlock(&dev->struct_mutex); | |
79e53945 JB |
15634 | } |
15635 | ||
f1c79df3 ZW |
15636 | /* |
15637 | * Return which encoder is currently attached for connector. | |
15638 | */ | |
df0e9248 | 15639 | struct drm_encoder *intel_best_encoder(struct drm_connector *connector) |
79e53945 | 15640 | { |
df0e9248 CW |
15641 | return &intel_attached_encoder(connector)->base; |
15642 | } | |
f1c79df3 | 15643 | |
df0e9248 CW |
15644 | void intel_connector_attach_encoder(struct intel_connector *connector, |
15645 | struct intel_encoder *encoder) | |
15646 | { | |
15647 | connector->encoder = encoder; | |
15648 | drm_mode_connector_attach_encoder(&connector->base, | |
15649 | &encoder->base); | |
79e53945 | 15650 | } |
28d52043 DA |
15651 | |
15652 | /* | |
15653 | * set vga decode state - true == enable VGA decode | |
15654 | */ | |
15655 | int intel_modeset_vga_set_state(struct drm_device *dev, bool state) | |
15656 | { | |
15657 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a885b3cc | 15658 | unsigned reg = INTEL_INFO(dev)->gen >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL; |
28d52043 DA |
15659 | u16 gmch_ctrl; |
15660 | ||
75fa041d CW |
15661 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
15662 | DRM_ERROR("failed to read control word\n"); | |
15663 | return -EIO; | |
15664 | } | |
15665 | ||
c0cc8a55 CW |
15666 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
15667 | return 0; | |
15668 | ||
28d52043 DA |
15669 | if (state) |
15670 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; | |
15671 | else | |
15672 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; | |
75fa041d CW |
15673 | |
15674 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { | |
15675 | DRM_ERROR("failed to write control word\n"); | |
15676 | return -EIO; | |
15677 | } | |
15678 | ||
28d52043 DA |
15679 | return 0; |
15680 | } | |
c4a1d9e4 | 15681 | |
c4a1d9e4 | 15682 | struct intel_display_error_state { |
ff57f1b0 PZ |
15683 | |
15684 | u32 power_well_driver; | |
15685 | ||
63b66e5b CW |
15686 | int num_transcoders; |
15687 | ||
c4a1d9e4 CW |
15688 | struct intel_cursor_error_state { |
15689 | u32 control; | |
15690 | u32 position; | |
15691 | u32 base; | |
15692 | u32 size; | |
52331309 | 15693 | } cursor[I915_MAX_PIPES]; |
c4a1d9e4 CW |
15694 | |
15695 | struct intel_pipe_error_state { | |
ddf9c536 | 15696 | bool power_domain_on; |
c4a1d9e4 | 15697 | u32 source; |
f301b1e1 | 15698 | u32 stat; |
52331309 | 15699 | } pipe[I915_MAX_PIPES]; |
c4a1d9e4 CW |
15700 | |
15701 | struct intel_plane_error_state { | |
15702 | u32 control; | |
15703 | u32 stride; | |
15704 | u32 size; | |
15705 | u32 pos; | |
15706 | u32 addr; | |
15707 | u32 surface; | |
15708 | u32 tile_offset; | |
52331309 | 15709 | } plane[I915_MAX_PIPES]; |
63b66e5b CW |
15710 | |
15711 | struct intel_transcoder_error_state { | |
ddf9c536 | 15712 | bool power_domain_on; |
63b66e5b CW |
15713 | enum transcoder cpu_transcoder; |
15714 | ||
15715 | u32 conf; | |
15716 | ||
15717 | u32 htotal; | |
15718 | u32 hblank; | |
15719 | u32 hsync; | |
15720 | u32 vtotal; | |
15721 | u32 vblank; | |
15722 | u32 vsync; | |
15723 | } transcoder[4]; | |
c4a1d9e4 CW |
15724 | }; |
15725 | ||
15726 | struct intel_display_error_state * | |
15727 | intel_display_capture_error_state(struct drm_device *dev) | |
15728 | { | |
fbee40df | 15729 | struct drm_i915_private *dev_priv = dev->dev_private; |
c4a1d9e4 | 15730 | struct intel_display_error_state *error; |
63b66e5b CW |
15731 | int transcoders[] = { |
15732 | TRANSCODER_A, | |
15733 | TRANSCODER_B, | |
15734 | TRANSCODER_C, | |
15735 | TRANSCODER_EDP, | |
15736 | }; | |
c4a1d9e4 CW |
15737 | int i; |
15738 | ||
63b66e5b CW |
15739 | if (INTEL_INFO(dev)->num_pipes == 0) |
15740 | return NULL; | |
15741 | ||
9d1cb914 | 15742 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
c4a1d9e4 CW |
15743 | if (error == NULL) |
15744 | return NULL; | |
15745 | ||
190be112 | 15746 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
ff57f1b0 PZ |
15747 | error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER); |
15748 | ||
055e393f | 15749 | for_each_pipe(dev_priv, i) { |
ddf9c536 | 15750 | error->pipe[i].power_domain_on = |
f458ebbc DV |
15751 | __intel_display_power_is_enabled(dev_priv, |
15752 | POWER_DOMAIN_PIPE(i)); | |
ddf9c536 | 15753 | if (!error->pipe[i].power_domain_on) |
9d1cb914 PZ |
15754 | continue; |
15755 | ||
5efb3e28 VS |
15756 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
15757 | error->cursor[i].position = I915_READ(CURPOS(i)); | |
15758 | error->cursor[i].base = I915_READ(CURBASE(i)); | |
c4a1d9e4 CW |
15759 | |
15760 | error->plane[i].control = I915_READ(DSPCNTR(i)); | |
15761 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); | |
80ca378b | 15762 | if (INTEL_INFO(dev)->gen <= 3) { |
51889b35 | 15763 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
80ca378b PZ |
15764 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
15765 | } | |
ca291363 PZ |
15766 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
15767 | error->plane[i].addr = I915_READ(DSPADDR(i)); | |
c4a1d9e4 CW |
15768 | if (INTEL_INFO(dev)->gen >= 4) { |
15769 | error->plane[i].surface = I915_READ(DSPSURF(i)); | |
15770 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); | |
15771 | } | |
15772 | ||
c4a1d9e4 | 15773 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
f301b1e1 | 15774 | |
3abfce77 | 15775 | if (HAS_GMCH_DISPLAY(dev)) |
f301b1e1 | 15776 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
63b66e5b CW |
15777 | } |
15778 | ||
15779 | error->num_transcoders = INTEL_INFO(dev)->num_pipes; | |
15780 | if (HAS_DDI(dev_priv->dev)) | |
15781 | error->num_transcoders++; /* Account for eDP. */ | |
15782 | ||
15783 | for (i = 0; i < error->num_transcoders; i++) { | |
15784 | enum transcoder cpu_transcoder = transcoders[i]; | |
15785 | ||
ddf9c536 | 15786 | error->transcoder[i].power_domain_on = |
f458ebbc | 15787 | __intel_display_power_is_enabled(dev_priv, |
38cc1daf | 15788 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
ddf9c536 | 15789 | if (!error->transcoder[i].power_domain_on) |
9d1cb914 PZ |
15790 | continue; |
15791 | ||
63b66e5b CW |
15792 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
15793 | ||
15794 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); | |
15795 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); | |
15796 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); | |
15797 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); | |
15798 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); | |
15799 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); | |
15800 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); | |
c4a1d9e4 CW |
15801 | } |
15802 | ||
15803 | return error; | |
15804 | } | |
15805 | ||
edc3d884 MK |
15806 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
15807 | ||
c4a1d9e4 | 15808 | void |
edc3d884 | 15809 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
c4a1d9e4 CW |
15810 | struct drm_device *dev, |
15811 | struct intel_display_error_state *error) | |
15812 | { | |
055e393f | 15813 | struct drm_i915_private *dev_priv = dev->dev_private; |
c4a1d9e4 CW |
15814 | int i; |
15815 | ||
63b66e5b CW |
15816 | if (!error) |
15817 | return; | |
15818 | ||
edc3d884 | 15819 | err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes); |
190be112 | 15820 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
edc3d884 | 15821 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
ff57f1b0 | 15822 | error->power_well_driver); |
055e393f | 15823 | for_each_pipe(dev_priv, i) { |
edc3d884 | 15824 | err_printf(m, "Pipe [%d]:\n", i); |
ddf9c536 ID |
15825 | err_printf(m, " Power: %s\n", |
15826 | error->pipe[i].power_domain_on ? "on" : "off"); | |
edc3d884 | 15827 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
f301b1e1 | 15828 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
edc3d884 MK |
15829 | |
15830 | err_printf(m, "Plane [%d]:\n", i); | |
15831 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); | |
15832 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); | |
80ca378b | 15833 | if (INTEL_INFO(dev)->gen <= 3) { |
edc3d884 MK |
15834 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
15835 | err_printf(m, " POS: %08x\n", error->plane[i].pos); | |
80ca378b | 15836 | } |
4b71a570 | 15837 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
edc3d884 | 15838 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
c4a1d9e4 | 15839 | if (INTEL_INFO(dev)->gen >= 4) { |
edc3d884 MK |
15840 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
15841 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); | |
c4a1d9e4 CW |
15842 | } |
15843 | ||
edc3d884 MK |
15844 | err_printf(m, "Cursor [%d]:\n", i); |
15845 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); | |
15846 | err_printf(m, " POS: %08x\n", error->cursor[i].position); | |
15847 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); | |
c4a1d9e4 | 15848 | } |
63b66e5b CW |
15849 | |
15850 | for (i = 0; i < error->num_transcoders; i++) { | |
1cf84bb6 | 15851 | err_printf(m, "CPU transcoder: %c\n", |
63b66e5b | 15852 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
ddf9c536 ID |
15853 | err_printf(m, " Power: %s\n", |
15854 | error->transcoder[i].power_domain_on ? "on" : "off"); | |
63b66e5b CW |
15855 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
15856 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); | |
15857 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); | |
15858 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); | |
15859 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); | |
15860 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); | |
15861 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); | |
15862 | } | |
c4a1d9e4 | 15863 | } |
e2fcdaa9 VS |
15864 | |
15865 | void intel_modeset_preclose(struct drm_device *dev, struct drm_file *file) | |
15866 | { | |
15867 | struct intel_crtc *crtc; | |
15868 | ||
15869 | for_each_intel_crtc(dev, crtc) { | |
15870 | struct intel_unpin_work *work; | |
e2fcdaa9 | 15871 | |
5e2d7afc | 15872 | spin_lock_irq(&dev->event_lock); |
e2fcdaa9 VS |
15873 | |
15874 | work = crtc->unpin_work; | |
15875 | ||
15876 | if (work && work->event && | |
15877 | work->event->base.file_priv == file) { | |
15878 | kfree(work->event); | |
15879 | work->event = NULL; | |
15880 | } | |
15881 | ||
5e2d7afc | 15882 | spin_unlock_irq(&dev->event_lock); |
e2fcdaa9 VS |
15883 | } |
15884 | } |