]>
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> |
fd8e058a AG |
47 | #include <linux/reservation.h> |
48 | #include <linux/dma-buf.h> | |
79e53945 | 49 | |
465c120c | 50 | /* Primary plane formats for gen <= 3 */ |
568db4f2 | 51 | static const uint32_t i8xx_primary_formats[] = { |
67fe7dc5 DL |
52 | DRM_FORMAT_C8, |
53 | DRM_FORMAT_RGB565, | |
465c120c | 54 | DRM_FORMAT_XRGB1555, |
67fe7dc5 | 55 | DRM_FORMAT_XRGB8888, |
465c120c MR |
56 | }; |
57 | ||
58 | /* Primary plane formats for gen >= 4 */ | |
568db4f2 | 59 | static const uint32_t i965_primary_formats[] = { |
6c0fd451 DL |
60 | DRM_FORMAT_C8, |
61 | DRM_FORMAT_RGB565, | |
62 | DRM_FORMAT_XRGB8888, | |
63 | DRM_FORMAT_XBGR8888, | |
64 | DRM_FORMAT_XRGB2101010, | |
65 | DRM_FORMAT_XBGR2101010, | |
66 | }; | |
67 | ||
68 | static const uint32_t skl_primary_formats[] = { | |
67fe7dc5 DL |
69 | DRM_FORMAT_C8, |
70 | DRM_FORMAT_RGB565, | |
71 | DRM_FORMAT_XRGB8888, | |
465c120c | 72 | DRM_FORMAT_XBGR8888, |
67fe7dc5 | 73 | DRM_FORMAT_ARGB8888, |
465c120c MR |
74 | DRM_FORMAT_ABGR8888, |
75 | DRM_FORMAT_XRGB2101010, | |
465c120c | 76 | DRM_FORMAT_XBGR2101010, |
ea916ea0 KM |
77 | DRM_FORMAT_YUYV, |
78 | DRM_FORMAT_YVYU, | |
79 | DRM_FORMAT_UYVY, | |
80 | DRM_FORMAT_VYUY, | |
465c120c MR |
81 | }; |
82 | ||
3d7d6510 MR |
83 | /* Cursor formats */ |
84 | static const uint32_t intel_cursor_formats[] = { | |
85 | DRM_FORMAT_ARGB8888, | |
86 | }; | |
87 | ||
f1f644dc | 88 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 89 | struct intel_crtc_state *pipe_config); |
18442d08 | 90 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
5cec258b | 91 | struct intel_crtc_state *pipe_config); |
f1f644dc | 92 | |
eb1bfe80 JB |
93 | static int intel_framebuffer_init(struct drm_device *dev, |
94 | struct intel_framebuffer *ifb, | |
95 | struct drm_mode_fb_cmd2 *mode_cmd, | |
96 | struct drm_i915_gem_object *obj); | |
5b18e57c DV |
97 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc); |
98 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc); | |
29407aab | 99 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
f769cd24 VK |
100 | struct intel_link_m_n *m_n, |
101 | struct intel_link_m_n *m2_n2); | |
29407aab | 102 | static void ironlake_set_pipeconf(struct drm_crtc *crtc); |
229fca97 DV |
103 | static void haswell_set_pipeconf(struct drm_crtc *crtc); |
104 | static void intel_set_pipe_csc(struct drm_crtc *crtc); | |
d288f65f | 105 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 106 | const struct intel_crtc_state *pipe_config); |
d288f65f | 107 | static void chv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 108 | const struct intel_crtc_state *pipe_config); |
613d2b27 ML |
109 | static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *); |
110 | static void intel_finish_crtc_commit(struct drm_crtc *, struct drm_crtc_state *); | |
549e2bfb CK |
111 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
112 | struct intel_crtc_state *crtc_state); | |
5ab7b0b7 ID |
113 | static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state, |
114 | int num_connectors); | |
bfd16b2a ML |
115 | static void skylake_pfit_enable(struct intel_crtc *crtc); |
116 | static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force); | |
117 | static void ironlake_pfit_enable(struct intel_crtc *crtc); | |
043e9bda | 118 | static void intel_modeset_setup_hw_state(struct drm_device *dev); |
200757f5 | 119 | static void intel_pre_disable_primary(struct drm_crtc *crtc); |
e7457a9a | 120 | |
79e53945 | 121 | typedef struct { |
0206e353 | 122 | int min, max; |
79e53945 JB |
123 | } intel_range_t; |
124 | ||
125 | typedef struct { | |
0206e353 AJ |
126 | int dot_limit; |
127 | int p2_slow, p2_fast; | |
79e53945 JB |
128 | } intel_p2_t; |
129 | ||
d4906093 ML |
130 | typedef struct intel_limit intel_limit_t; |
131 | struct intel_limit { | |
0206e353 AJ |
132 | intel_range_t dot, vco, n, m, m1, m2, p, p1; |
133 | intel_p2_t p2; | |
d4906093 | 134 | }; |
79e53945 | 135 | |
bfa7df01 VS |
136 | /* returns HPLL frequency in kHz */ |
137 | static int valleyview_get_vco(struct drm_i915_private *dev_priv) | |
138 | { | |
139 | int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; | |
140 | ||
141 | /* Obtain SKU information */ | |
142 | mutex_lock(&dev_priv->sb_lock); | |
143 | hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & | |
144 | CCK_FUSE_HPLL_FREQ_MASK; | |
145 | mutex_unlock(&dev_priv->sb_lock); | |
146 | ||
147 | return vco_freq[hpll_freq] * 1000; | |
148 | } | |
149 | ||
150 | static int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv, | |
151 | const char *name, u32 reg) | |
152 | { | |
153 | u32 val; | |
154 | int divider; | |
155 | ||
156 | if (dev_priv->hpll_freq == 0) | |
157 | dev_priv->hpll_freq = valleyview_get_vco(dev_priv); | |
158 | ||
159 | mutex_lock(&dev_priv->sb_lock); | |
160 | val = vlv_cck_read(dev_priv, reg); | |
161 | mutex_unlock(&dev_priv->sb_lock); | |
162 | ||
163 | divider = val & CCK_FREQUENCY_VALUES; | |
164 | ||
165 | WARN((val & CCK_FREQUENCY_STATUS) != | |
166 | (divider << CCK_FREQUENCY_STATUS_SHIFT), | |
167 | "%s change in progress\n", name); | |
168 | ||
169 | return DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, divider + 1); | |
170 | } | |
171 | ||
d2acd215 DV |
172 | int |
173 | intel_pch_rawclk(struct drm_device *dev) | |
174 | { | |
175 | struct drm_i915_private *dev_priv = dev->dev_private; | |
176 | ||
177 | WARN_ON(!HAS_PCH_SPLIT(dev)); | |
178 | ||
179 | return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK; | |
180 | } | |
181 | ||
79e50a4f JN |
182 | /* hrawclock is 1/4 the FSB frequency */ |
183 | int intel_hrawclk(struct drm_device *dev) | |
184 | { | |
185 | struct drm_i915_private *dev_priv = dev->dev_private; | |
186 | uint32_t clkcfg; | |
187 | ||
188 | /* There is no CLKCFG reg in Valleyview. VLV hrawclk is 200 MHz */ | |
666a4537 | 189 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) |
79e50a4f JN |
190 | return 200; |
191 | ||
192 | clkcfg = I915_READ(CLKCFG); | |
193 | switch (clkcfg & CLKCFG_FSB_MASK) { | |
194 | case CLKCFG_FSB_400: | |
195 | return 100; | |
196 | case CLKCFG_FSB_533: | |
197 | return 133; | |
198 | case CLKCFG_FSB_667: | |
199 | return 166; | |
200 | case CLKCFG_FSB_800: | |
201 | return 200; | |
202 | case CLKCFG_FSB_1067: | |
203 | return 266; | |
204 | case CLKCFG_FSB_1333: | |
205 | return 333; | |
206 | /* these two are just a guess; one of them might be right */ | |
207 | case CLKCFG_FSB_1600: | |
208 | case CLKCFG_FSB_1600_ALT: | |
209 | return 400; | |
210 | default: | |
211 | return 133; | |
212 | } | |
213 | } | |
214 | ||
bfa7df01 VS |
215 | static void intel_update_czclk(struct drm_i915_private *dev_priv) |
216 | { | |
666a4537 | 217 | if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))) |
bfa7df01 VS |
218 | return; |
219 | ||
220 | dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk", | |
221 | CCK_CZ_CLOCK_CONTROL); | |
222 | ||
223 | DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq); | |
224 | } | |
225 | ||
021357ac CW |
226 | static inline u32 /* units of 100MHz */ |
227 | intel_fdi_link_freq(struct drm_device *dev) | |
228 | { | |
8b99e68c CW |
229 | if (IS_GEN5(dev)) { |
230 | struct drm_i915_private *dev_priv = dev->dev_private; | |
231 | return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2; | |
232 | } else | |
233 | return 27; | |
021357ac CW |
234 | } |
235 | ||
5d536e28 | 236 | static const intel_limit_t intel_limits_i8xx_dac = { |
0206e353 | 237 | .dot = { .min = 25000, .max = 350000 }, |
9c333719 | 238 | .vco = { .min = 908000, .max = 1512000 }, |
91dbe5fb | 239 | .n = { .min = 2, .max = 16 }, |
0206e353 AJ |
240 | .m = { .min = 96, .max = 140 }, |
241 | .m1 = { .min = 18, .max = 26 }, | |
242 | .m2 = { .min = 6, .max = 16 }, | |
243 | .p = { .min = 4, .max = 128 }, | |
244 | .p1 = { .min = 2, .max = 33 }, | |
273e27ca EA |
245 | .p2 = { .dot_limit = 165000, |
246 | .p2_slow = 4, .p2_fast = 2 }, | |
e4b36699 KP |
247 | }; |
248 | ||
5d536e28 DV |
249 | static const intel_limit_t intel_limits_i8xx_dvo = { |
250 | .dot = { .min = 25000, .max = 350000 }, | |
9c333719 | 251 | .vco = { .min = 908000, .max = 1512000 }, |
91dbe5fb | 252 | .n = { .min = 2, .max = 16 }, |
5d536e28 DV |
253 | .m = { .min = 96, .max = 140 }, |
254 | .m1 = { .min = 18, .max = 26 }, | |
255 | .m2 = { .min = 6, .max = 16 }, | |
256 | .p = { .min = 4, .max = 128 }, | |
257 | .p1 = { .min = 2, .max = 33 }, | |
258 | .p2 = { .dot_limit = 165000, | |
259 | .p2_slow = 4, .p2_fast = 4 }, | |
260 | }; | |
261 | ||
e4b36699 | 262 | static const intel_limit_t intel_limits_i8xx_lvds = { |
0206e353 | 263 | .dot = { .min = 25000, .max = 350000 }, |
9c333719 | 264 | .vco = { .min = 908000, .max = 1512000 }, |
91dbe5fb | 265 | .n = { .min = 2, .max = 16 }, |
0206e353 AJ |
266 | .m = { .min = 96, .max = 140 }, |
267 | .m1 = { .min = 18, .max = 26 }, | |
268 | .m2 = { .min = 6, .max = 16 }, | |
269 | .p = { .min = 4, .max = 128 }, | |
270 | .p1 = { .min = 1, .max = 6 }, | |
273e27ca EA |
271 | .p2 = { .dot_limit = 165000, |
272 | .p2_slow = 14, .p2_fast = 7 }, | |
e4b36699 | 273 | }; |
273e27ca | 274 | |
e4b36699 | 275 | static const intel_limit_t intel_limits_i9xx_sdvo = { |
0206e353 AJ |
276 | .dot = { .min = 20000, .max = 400000 }, |
277 | .vco = { .min = 1400000, .max = 2800000 }, | |
278 | .n = { .min = 1, .max = 6 }, | |
279 | .m = { .min = 70, .max = 120 }, | |
4f7dfb67 PJ |
280 | .m1 = { .min = 8, .max = 18 }, |
281 | .m2 = { .min = 3, .max = 7 }, | |
0206e353 AJ |
282 | .p = { .min = 5, .max = 80 }, |
283 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
284 | .p2 = { .dot_limit = 200000, |
285 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
286 | }; |
287 | ||
288 | static const intel_limit_t intel_limits_i9xx_lvds = { | |
0206e353 AJ |
289 | .dot = { .min = 20000, .max = 400000 }, |
290 | .vco = { .min = 1400000, .max = 2800000 }, | |
291 | .n = { .min = 1, .max = 6 }, | |
292 | .m = { .min = 70, .max = 120 }, | |
53a7d2d1 PJ |
293 | .m1 = { .min = 8, .max = 18 }, |
294 | .m2 = { .min = 3, .max = 7 }, | |
0206e353 AJ |
295 | .p = { .min = 7, .max = 98 }, |
296 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
297 | .p2 = { .dot_limit = 112000, |
298 | .p2_slow = 14, .p2_fast = 7 }, | |
e4b36699 KP |
299 | }; |
300 | ||
273e27ca | 301 | |
e4b36699 | 302 | static const intel_limit_t intel_limits_g4x_sdvo = { |
273e27ca EA |
303 | .dot = { .min = 25000, .max = 270000 }, |
304 | .vco = { .min = 1750000, .max = 3500000}, | |
305 | .n = { .min = 1, .max = 4 }, | |
306 | .m = { .min = 104, .max = 138 }, | |
307 | .m1 = { .min = 17, .max = 23 }, | |
308 | .m2 = { .min = 5, .max = 11 }, | |
309 | .p = { .min = 10, .max = 30 }, | |
310 | .p1 = { .min = 1, .max = 3}, | |
311 | .p2 = { .dot_limit = 270000, | |
312 | .p2_slow = 10, | |
313 | .p2_fast = 10 | |
044c7c41 | 314 | }, |
e4b36699 KP |
315 | }; |
316 | ||
317 | static const intel_limit_t intel_limits_g4x_hdmi = { | |
273e27ca EA |
318 | .dot = { .min = 22000, .max = 400000 }, |
319 | .vco = { .min = 1750000, .max = 3500000}, | |
320 | .n = { .min = 1, .max = 4 }, | |
321 | .m = { .min = 104, .max = 138 }, | |
322 | .m1 = { .min = 16, .max = 23 }, | |
323 | .m2 = { .min = 5, .max = 11 }, | |
324 | .p = { .min = 5, .max = 80 }, | |
325 | .p1 = { .min = 1, .max = 8}, | |
326 | .p2 = { .dot_limit = 165000, | |
327 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
328 | }; |
329 | ||
330 | static const intel_limit_t intel_limits_g4x_single_channel_lvds = { | |
273e27ca EA |
331 | .dot = { .min = 20000, .max = 115000 }, |
332 | .vco = { .min = 1750000, .max = 3500000 }, | |
333 | .n = { .min = 1, .max = 3 }, | |
334 | .m = { .min = 104, .max = 138 }, | |
335 | .m1 = { .min = 17, .max = 23 }, | |
336 | .m2 = { .min = 5, .max = 11 }, | |
337 | .p = { .min = 28, .max = 112 }, | |
338 | .p1 = { .min = 2, .max = 8 }, | |
339 | .p2 = { .dot_limit = 0, | |
340 | .p2_slow = 14, .p2_fast = 14 | |
044c7c41 | 341 | }, |
e4b36699 KP |
342 | }; |
343 | ||
344 | static const intel_limit_t intel_limits_g4x_dual_channel_lvds = { | |
273e27ca EA |
345 | .dot = { .min = 80000, .max = 224000 }, |
346 | .vco = { .min = 1750000, .max = 3500000 }, | |
347 | .n = { .min = 1, .max = 3 }, | |
348 | .m = { .min = 104, .max = 138 }, | |
349 | .m1 = { .min = 17, .max = 23 }, | |
350 | .m2 = { .min = 5, .max = 11 }, | |
351 | .p = { .min = 14, .max = 42 }, | |
352 | .p1 = { .min = 2, .max = 6 }, | |
353 | .p2 = { .dot_limit = 0, | |
354 | .p2_slow = 7, .p2_fast = 7 | |
044c7c41 | 355 | }, |
e4b36699 KP |
356 | }; |
357 | ||
f2b115e6 | 358 | static const intel_limit_t intel_limits_pineview_sdvo = { |
0206e353 AJ |
359 | .dot = { .min = 20000, .max = 400000}, |
360 | .vco = { .min = 1700000, .max = 3500000 }, | |
273e27ca | 361 | /* Pineview's Ncounter is a ring counter */ |
0206e353 AJ |
362 | .n = { .min = 3, .max = 6 }, |
363 | .m = { .min = 2, .max = 256 }, | |
273e27ca | 364 | /* Pineview only has one combined m divider, which we treat as m2. */ |
0206e353 AJ |
365 | .m1 = { .min = 0, .max = 0 }, |
366 | .m2 = { .min = 0, .max = 254 }, | |
367 | .p = { .min = 5, .max = 80 }, | |
368 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
369 | .p2 = { .dot_limit = 200000, |
370 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
371 | }; |
372 | ||
f2b115e6 | 373 | static const intel_limit_t intel_limits_pineview_lvds = { |
0206e353 AJ |
374 | .dot = { .min = 20000, .max = 400000 }, |
375 | .vco = { .min = 1700000, .max = 3500000 }, | |
376 | .n = { .min = 3, .max = 6 }, | |
377 | .m = { .min = 2, .max = 256 }, | |
378 | .m1 = { .min = 0, .max = 0 }, | |
379 | .m2 = { .min = 0, .max = 254 }, | |
380 | .p = { .min = 7, .max = 112 }, | |
381 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
382 | .p2 = { .dot_limit = 112000, |
383 | .p2_slow = 14, .p2_fast = 14 }, | |
e4b36699 KP |
384 | }; |
385 | ||
273e27ca EA |
386 | /* Ironlake / Sandybridge |
387 | * | |
388 | * We calculate clock using (register_value + 2) for N/M1/M2, so here | |
389 | * the range value for them is (actual_value - 2). | |
390 | */ | |
b91ad0ec | 391 | static const intel_limit_t intel_limits_ironlake_dac = { |
273e27ca EA |
392 | .dot = { .min = 25000, .max = 350000 }, |
393 | .vco = { .min = 1760000, .max = 3510000 }, | |
394 | .n = { .min = 1, .max = 5 }, | |
395 | .m = { .min = 79, .max = 127 }, | |
396 | .m1 = { .min = 12, .max = 22 }, | |
397 | .m2 = { .min = 5, .max = 9 }, | |
398 | .p = { .min = 5, .max = 80 }, | |
399 | .p1 = { .min = 1, .max = 8 }, | |
400 | .p2 = { .dot_limit = 225000, | |
401 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
402 | }; |
403 | ||
b91ad0ec | 404 | static const intel_limit_t intel_limits_ironlake_single_lvds = { |
273e27ca EA |
405 | .dot = { .min = 25000, .max = 350000 }, |
406 | .vco = { .min = 1760000, .max = 3510000 }, | |
407 | .n = { .min = 1, .max = 3 }, | |
408 | .m = { .min = 79, .max = 118 }, | |
409 | .m1 = { .min = 12, .max = 22 }, | |
410 | .m2 = { .min = 5, .max = 9 }, | |
411 | .p = { .min = 28, .max = 112 }, | |
412 | .p1 = { .min = 2, .max = 8 }, | |
413 | .p2 = { .dot_limit = 225000, | |
414 | .p2_slow = 14, .p2_fast = 14 }, | |
b91ad0ec ZW |
415 | }; |
416 | ||
417 | static const intel_limit_t intel_limits_ironlake_dual_lvds = { | |
273e27ca EA |
418 | .dot = { .min = 25000, .max = 350000 }, |
419 | .vco = { .min = 1760000, .max = 3510000 }, | |
420 | .n = { .min = 1, .max = 3 }, | |
421 | .m = { .min = 79, .max = 127 }, | |
422 | .m1 = { .min = 12, .max = 22 }, | |
423 | .m2 = { .min = 5, .max = 9 }, | |
424 | .p = { .min = 14, .max = 56 }, | |
425 | .p1 = { .min = 2, .max = 8 }, | |
426 | .p2 = { .dot_limit = 225000, | |
427 | .p2_slow = 7, .p2_fast = 7 }, | |
b91ad0ec ZW |
428 | }; |
429 | ||
273e27ca | 430 | /* LVDS 100mhz refclk limits. */ |
b91ad0ec | 431 | static const intel_limit_t intel_limits_ironlake_single_lvds_100m = { |
273e27ca EA |
432 | .dot = { .min = 25000, .max = 350000 }, |
433 | .vco = { .min = 1760000, .max = 3510000 }, | |
434 | .n = { .min = 1, .max = 2 }, | |
435 | .m = { .min = 79, .max = 126 }, | |
436 | .m1 = { .min = 12, .max = 22 }, | |
437 | .m2 = { .min = 5, .max = 9 }, | |
438 | .p = { .min = 28, .max = 112 }, | |
0206e353 | 439 | .p1 = { .min = 2, .max = 8 }, |
273e27ca EA |
440 | .p2 = { .dot_limit = 225000, |
441 | .p2_slow = 14, .p2_fast = 14 }, | |
b91ad0ec ZW |
442 | }; |
443 | ||
444 | static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = { | |
273e27ca EA |
445 | .dot = { .min = 25000, .max = 350000 }, |
446 | .vco = { .min = 1760000, .max = 3510000 }, | |
447 | .n = { .min = 1, .max = 3 }, | |
448 | .m = { .min = 79, .max = 126 }, | |
449 | .m1 = { .min = 12, .max = 22 }, | |
450 | .m2 = { .min = 5, .max = 9 }, | |
451 | .p = { .min = 14, .max = 42 }, | |
0206e353 | 452 | .p1 = { .min = 2, .max = 6 }, |
273e27ca EA |
453 | .p2 = { .dot_limit = 225000, |
454 | .p2_slow = 7, .p2_fast = 7 }, | |
4547668a ZY |
455 | }; |
456 | ||
dc730512 | 457 | static const intel_limit_t intel_limits_vlv = { |
f01b7962 VS |
458 | /* |
459 | * These are the data rate limits (measured in fast clocks) | |
460 | * since those are the strictest limits we have. The fast | |
461 | * clock and actual rate limits are more relaxed, so checking | |
462 | * them would make no difference. | |
463 | */ | |
464 | .dot = { .min = 25000 * 5, .max = 270000 * 5 }, | |
75e53986 | 465 | .vco = { .min = 4000000, .max = 6000000 }, |
a0c4da24 | 466 | .n = { .min = 1, .max = 7 }, |
a0c4da24 JB |
467 | .m1 = { .min = 2, .max = 3 }, |
468 | .m2 = { .min = 11, .max = 156 }, | |
b99ab663 | 469 | .p1 = { .min = 2, .max = 3 }, |
5fdc9c49 | 470 | .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */ |
a0c4da24 JB |
471 | }; |
472 | ||
ef9348c8 CML |
473 | static const intel_limit_t intel_limits_chv = { |
474 | /* | |
475 | * These are the data rate limits (measured in fast clocks) | |
476 | * since those are the strictest limits we have. The fast | |
477 | * clock and actual rate limits are more relaxed, so checking | |
478 | * them would make no difference. | |
479 | */ | |
480 | .dot = { .min = 25000 * 5, .max = 540000 * 5}, | |
17fe1021 | 481 | .vco = { .min = 4800000, .max = 6480000 }, |
ef9348c8 CML |
482 | .n = { .min = 1, .max = 1 }, |
483 | .m1 = { .min = 2, .max = 2 }, | |
484 | .m2 = { .min = 24 << 22, .max = 175 << 22 }, | |
485 | .p1 = { .min = 2, .max = 4 }, | |
486 | .p2 = { .p2_slow = 1, .p2_fast = 14 }, | |
487 | }; | |
488 | ||
5ab7b0b7 ID |
489 | static const intel_limit_t intel_limits_bxt = { |
490 | /* FIXME: find real dot limits */ | |
491 | .dot = { .min = 0, .max = INT_MAX }, | |
e6292556 | 492 | .vco = { .min = 4800000, .max = 6700000 }, |
5ab7b0b7 ID |
493 | .n = { .min = 1, .max = 1 }, |
494 | .m1 = { .min = 2, .max = 2 }, | |
495 | /* FIXME: find real m2 limits */ | |
496 | .m2 = { .min = 2 << 22, .max = 255 << 22 }, | |
497 | .p1 = { .min = 2, .max = 4 }, | |
498 | .p2 = { .p2_slow = 1, .p2_fast = 20 }, | |
499 | }; | |
500 | ||
cdba954e ACO |
501 | static bool |
502 | needs_modeset(struct drm_crtc_state *state) | |
503 | { | |
fc596660 | 504 | return drm_atomic_crtc_needs_modeset(state); |
cdba954e ACO |
505 | } |
506 | ||
e0638cdf PZ |
507 | /** |
508 | * Returns whether any output on the specified pipe is of the specified type | |
509 | */ | |
4093561b | 510 | bool intel_pipe_has_type(struct intel_crtc *crtc, enum intel_output_type type) |
e0638cdf | 511 | { |
409ee761 | 512 | struct drm_device *dev = crtc->base.dev; |
e0638cdf PZ |
513 | struct intel_encoder *encoder; |
514 | ||
409ee761 | 515 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
e0638cdf PZ |
516 | if (encoder->type == type) |
517 | return true; | |
518 | ||
519 | return false; | |
520 | } | |
521 | ||
d0737e1d ACO |
522 | /** |
523 | * Returns whether any output on the specified pipe will have the specified | |
524 | * type after a staged modeset is complete, i.e., the same as | |
525 | * intel_pipe_has_type() but looking at encoder->new_crtc instead of | |
526 | * encoder->crtc. | |
527 | */ | |
a93e255f ACO |
528 | static bool intel_pipe_will_have_type(const struct intel_crtc_state *crtc_state, |
529 | int type) | |
d0737e1d | 530 | { |
a93e255f | 531 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 532 | struct drm_connector *connector; |
a93e255f | 533 | struct drm_connector_state *connector_state; |
d0737e1d | 534 | struct intel_encoder *encoder; |
a93e255f ACO |
535 | int i, num_connectors = 0; |
536 | ||
da3ced29 | 537 | for_each_connector_in_state(state, connector, connector_state, i) { |
a93e255f ACO |
538 | if (connector_state->crtc != crtc_state->base.crtc) |
539 | continue; | |
540 | ||
541 | num_connectors++; | |
d0737e1d | 542 | |
a93e255f ACO |
543 | encoder = to_intel_encoder(connector_state->best_encoder); |
544 | if (encoder->type == type) | |
d0737e1d | 545 | return true; |
a93e255f ACO |
546 | } |
547 | ||
548 | WARN_ON(num_connectors == 0); | |
d0737e1d ACO |
549 | |
550 | return false; | |
551 | } | |
552 | ||
a93e255f ACO |
553 | static const intel_limit_t * |
554 | intel_ironlake_limit(struct intel_crtc_state *crtc_state, int refclk) | |
2c07245f | 555 | { |
a93e255f | 556 | struct drm_device *dev = crtc_state->base.crtc->dev; |
2c07245f | 557 | const intel_limit_t *limit; |
b91ad0ec | 558 | |
a93e255f | 559 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
1974cad0 | 560 | if (intel_is_dual_link_lvds(dev)) { |
1b894b59 | 561 | if (refclk == 100000) |
b91ad0ec ZW |
562 | limit = &intel_limits_ironlake_dual_lvds_100m; |
563 | else | |
564 | limit = &intel_limits_ironlake_dual_lvds; | |
565 | } else { | |
1b894b59 | 566 | if (refclk == 100000) |
b91ad0ec ZW |
567 | limit = &intel_limits_ironlake_single_lvds_100m; |
568 | else | |
569 | limit = &intel_limits_ironlake_single_lvds; | |
570 | } | |
c6bb3538 | 571 | } else |
b91ad0ec | 572 | limit = &intel_limits_ironlake_dac; |
2c07245f ZW |
573 | |
574 | return limit; | |
575 | } | |
576 | ||
a93e255f ACO |
577 | static const intel_limit_t * |
578 | intel_g4x_limit(struct intel_crtc_state *crtc_state) | |
044c7c41 | 579 | { |
a93e255f | 580 | struct drm_device *dev = crtc_state->base.crtc->dev; |
044c7c41 ML |
581 | const intel_limit_t *limit; |
582 | ||
a93e255f | 583 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
1974cad0 | 584 | if (intel_is_dual_link_lvds(dev)) |
e4b36699 | 585 | limit = &intel_limits_g4x_dual_channel_lvds; |
044c7c41 | 586 | else |
e4b36699 | 587 | limit = &intel_limits_g4x_single_channel_lvds; |
a93e255f ACO |
588 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI) || |
589 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_ANALOG)) { | |
e4b36699 | 590 | limit = &intel_limits_g4x_hdmi; |
a93e255f | 591 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO)) { |
e4b36699 | 592 | limit = &intel_limits_g4x_sdvo; |
044c7c41 | 593 | } else /* The option is for other outputs */ |
e4b36699 | 594 | limit = &intel_limits_i9xx_sdvo; |
044c7c41 ML |
595 | |
596 | return limit; | |
597 | } | |
598 | ||
a93e255f ACO |
599 | static const intel_limit_t * |
600 | intel_limit(struct intel_crtc_state *crtc_state, int refclk) | |
79e53945 | 601 | { |
a93e255f | 602 | struct drm_device *dev = crtc_state->base.crtc->dev; |
79e53945 JB |
603 | const intel_limit_t *limit; |
604 | ||
5ab7b0b7 ID |
605 | if (IS_BROXTON(dev)) |
606 | limit = &intel_limits_bxt; | |
607 | else if (HAS_PCH_SPLIT(dev)) | |
a93e255f | 608 | limit = intel_ironlake_limit(crtc_state, refclk); |
2c07245f | 609 | else if (IS_G4X(dev)) { |
a93e255f | 610 | limit = intel_g4x_limit(crtc_state); |
f2b115e6 | 611 | } else if (IS_PINEVIEW(dev)) { |
a93e255f | 612 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
f2b115e6 | 613 | limit = &intel_limits_pineview_lvds; |
2177832f | 614 | else |
f2b115e6 | 615 | limit = &intel_limits_pineview_sdvo; |
ef9348c8 CML |
616 | } else if (IS_CHERRYVIEW(dev)) { |
617 | limit = &intel_limits_chv; | |
a0c4da24 | 618 | } else if (IS_VALLEYVIEW(dev)) { |
dc730512 | 619 | limit = &intel_limits_vlv; |
a6c45cf0 | 620 | } else if (!IS_GEN2(dev)) { |
a93e255f | 621 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
a6c45cf0 CW |
622 | limit = &intel_limits_i9xx_lvds; |
623 | else | |
624 | limit = &intel_limits_i9xx_sdvo; | |
79e53945 | 625 | } else { |
a93e255f | 626 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
e4b36699 | 627 | limit = &intel_limits_i8xx_lvds; |
a93e255f | 628 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) |
e4b36699 | 629 | limit = &intel_limits_i8xx_dvo; |
5d536e28 DV |
630 | else |
631 | limit = &intel_limits_i8xx_dac; | |
79e53945 JB |
632 | } |
633 | return limit; | |
634 | } | |
635 | ||
dccbea3b ID |
636 | /* |
637 | * Platform specific helpers to calculate the port PLL loopback- (clock.m), | |
638 | * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast | |
639 | * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic. | |
640 | * The helpers' return value is the rate of the clock that is fed to the | |
641 | * display engine's pipe which can be the above fast dot clock rate or a | |
642 | * divided-down version of it. | |
643 | */ | |
f2b115e6 | 644 | /* m1 is reserved as 0 in Pineview, n is a ring counter */ |
dccbea3b | 645 | static int pnv_calc_dpll_params(int refclk, intel_clock_t *clock) |
79e53945 | 646 | { |
2177832f SL |
647 | clock->m = clock->m2 + 2; |
648 | clock->p = clock->p1 * clock->p2; | |
ed5ca77e | 649 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
dccbea3b | 650 | return 0; |
fb03ac01 VS |
651 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
652 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
dccbea3b ID |
653 | |
654 | return clock->dot; | |
2177832f SL |
655 | } |
656 | ||
7429e9d4 DV |
657 | static uint32_t i9xx_dpll_compute_m(struct dpll *dpll) |
658 | { | |
659 | return 5 * (dpll->m1 + 2) + (dpll->m2 + 2); | |
660 | } | |
661 | ||
dccbea3b | 662 | static int i9xx_calc_dpll_params(int refclk, intel_clock_t *clock) |
2177832f | 663 | { |
7429e9d4 | 664 | clock->m = i9xx_dpll_compute_m(clock); |
79e53945 | 665 | clock->p = clock->p1 * clock->p2; |
ed5ca77e | 666 | if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) |
dccbea3b | 667 | return 0; |
fb03ac01 VS |
668 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2); |
669 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
dccbea3b ID |
670 | |
671 | return clock->dot; | |
79e53945 JB |
672 | } |
673 | ||
dccbea3b | 674 | static int vlv_calc_dpll_params(int refclk, intel_clock_t *clock) |
589eca67 ID |
675 | { |
676 | clock->m = clock->m1 * clock->m2; | |
677 | clock->p = clock->p1 * clock->p2; | |
678 | if (WARN_ON(clock->n == 0 || clock->p == 0)) | |
dccbea3b | 679 | return 0; |
589eca67 ID |
680 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
681 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
dccbea3b ID |
682 | |
683 | return clock->dot / 5; | |
589eca67 ID |
684 | } |
685 | ||
dccbea3b | 686 | int chv_calc_dpll_params(int refclk, intel_clock_t *clock) |
ef9348c8 CML |
687 | { |
688 | clock->m = clock->m1 * clock->m2; | |
689 | clock->p = clock->p1 * clock->p2; | |
690 | if (WARN_ON(clock->n == 0 || clock->p == 0)) | |
dccbea3b | 691 | return 0; |
ef9348c8 CML |
692 | clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m, |
693 | clock->n << 22); | |
694 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
dccbea3b ID |
695 | |
696 | return clock->dot / 5; | |
ef9348c8 CML |
697 | } |
698 | ||
7c04d1d9 | 699 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
79e53945 JB |
700 | /** |
701 | * Returns whether the given set of divisors are valid for a given refclk with | |
702 | * the given connectors. | |
703 | */ | |
704 | ||
1b894b59 CW |
705 | static bool intel_PLL_is_valid(struct drm_device *dev, |
706 | const intel_limit_t *limit, | |
707 | const intel_clock_t *clock) | |
79e53945 | 708 | { |
f01b7962 VS |
709 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
710 | INTELPllInvalid("n out of range\n"); | |
79e53945 | 711 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
0206e353 | 712 | INTELPllInvalid("p1 out of range\n"); |
79e53945 | 713 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
0206e353 | 714 | INTELPllInvalid("m2 out of range\n"); |
79e53945 | 715 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
0206e353 | 716 | INTELPllInvalid("m1 out of range\n"); |
f01b7962 | 717 | |
666a4537 WB |
718 | if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev) && |
719 | !IS_CHERRYVIEW(dev) && !IS_BROXTON(dev)) | |
f01b7962 VS |
720 | if (clock->m1 <= clock->m2) |
721 | INTELPllInvalid("m1 <= m2\n"); | |
722 | ||
666a4537 | 723 | if (!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev) && !IS_BROXTON(dev)) { |
f01b7962 VS |
724 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
725 | INTELPllInvalid("p out of range\n"); | |
726 | if (clock->m < limit->m.min || limit->m.max < clock->m) | |
727 | INTELPllInvalid("m out of range\n"); | |
728 | } | |
729 | ||
79e53945 | 730 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
0206e353 | 731 | INTELPllInvalid("vco out of range\n"); |
79e53945 JB |
732 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
733 | * connector, etc., rather than just a single range. | |
734 | */ | |
735 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) | |
0206e353 | 736 | INTELPllInvalid("dot out of range\n"); |
79e53945 JB |
737 | |
738 | return true; | |
739 | } | |
740 | ||
3b1429d9 VS |
741 | static int |
742 | i9xx_select_p2_div(const intel_limit_t *limit, | |
743 | const struct intel_crtc_state *crtc_state, | |
744 | int target) | |
79e53945 | 745 | { |
3b1429d9 | 746 | struct drm_device *dev = crtc_state->base.crtc->dev; |
79e53945 | 747 | |
a93e255f | 748 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
79e53945 | 749 | /* |
a210b028 DV |
750 | * For LVDS just rely on its current settings for dual-channel. |
751 | * We haven't figured out how to reliably set up different | |
752 | * single/dual channel state, if we even can. | |
79e53945 | 753 | */ |
1974cad0 | 754 | if (intel_is_dual_link_lvds(dev)) |
3b1429d9 | 755 | return limit->p2.p2_fast; |
79e53945 | 756 | else |
3b1429d9 | 757 | return limit->p2.p2_slow; |
79e53945 JB |
758 | } else { |
759 | if (target < limit->p2.dot_limit) | |
3b1429d9 | 760 | return limit->p2.p2_slow; |
79e53945 | 761 | else |
3b1429d9 | 762 | return limit->p2.p2_fast; |
79e53945 | 763 | } |
3b1429d9 VS |
764 | } |
765 | ||
766 | static bool | |
767 | i9xx_find_best_dpll(const intel_limit_t *limit, | |
768 | struct intel_crtc_state *crtc_state, | |
769 | int target, int refclk, intel_clock_t *match_clock, | |
770 | intel_clock_t *best_clock) | |
771 | { | |
772 | struct drm_device *dev = crtc_state->base.crtc->dev; | |
773 | intel_clock_t clock; | |
774 | int err = target; | |
79e53945 | 775 | |
0206e353 | 776 | memset(best_clock, 0, sizeof(*best_clock)); |
79e53945 | 777 | |
3b1429d9 VS |
778 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
779 | ||
42158660 ZY |
780 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
781 | clock.m1++) { | |
782 | for (clock.m2 = limit->m2.min; | |
783 | clock.m2 <= limit->m2.max; clock.m2++) { | |
c0efc387 | 784 | if (clock.m2 >= clock.m1) |
42158660 ZY |
785 | break; |
786 | for (clock.n = limit->n.min; | |
787 | clock.n <= limit->n.max; clock.n++) { | |
788 | for (clock.p1 = limit->p1.min; | |
789 | clock.p1 <= limit->p1.max; clock.p1++) { | |
79e53945 JB |
790 | int this_err; |
791 | ||
dccbea3b | 792 | i9xx_calc_dpll_params(refclk, &clock); |
ac58c3f0 DV |
793 | if (!intel_PLL_is_valid(dev, limit, |
794 | &clock)) | |
795 | continue; | |
796 | if (match_clock && | |
797 | clock.p != match_clock->p) | |
798 | continue; | |
799 | ||
800 | this_err = abs(clock.dot - target); | |
801 | if (this_err < err) { | |
802 | *best_clock = clock; | |
803 | err = this_err; | |
804 | } | |
805 | } | |
806 | } | |
807 | } | |
808 | } | |
809 | ||
810 | return (err != target); | |
811 | } | |
812 | ||
813 | static bool | |
a93e255f ACO |
814 | pnv_find_best_dpll(const intel_limit_t *limit, |
815 | struct intel_crtc_state *crtc_state, | |
ee9300bb DV |
816 | int target, int refclk, intel_clock_t *match_clock, |
817 | intel_clock_t *best_clock) | |
79e53945 | 818 | { |
3b1429d9 | 819 | struct drm_device *dev = crtc_state->base.crtc->dev; |
79e53945 | 820 | intel_clock_t clock; |
79e53945 JB |
821 | int err = target; |
822 | ||
0206e353 | 823 | memset(best_clock, 0, sizeof(*best_clock)); |
79e53945 | 824 | |
3b1429d9 VS |
825 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
826 | ||
42158660 ZY |
827 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
828 | clock.m1++) { | |
829 | for (clock.m2 = limit->m2.min; | |
830 | clock.m2 <= limit->m2.max; clock.m2++) { | |
42158660 ZY |
831 | for (clock.n = limit->n.min; |
832 | clock.n <= limit->n.max; clock.n++) { | |
833 | for (clock.p1 = limit->p1.min; | |
834 | clock.p1 <= limit->p1.max; clock.p1++) { | |
79e53945 JB |
835 | int this_err; |
836 | ||
dccbea3b | 837 | pnv_calc_dpll_params(refclk, &clock); |
1b894b59 CW |
838 | if (!intel_PLL_is_valid(dev, limit, |
839 | &clock)) | |
79e53945 | 840 | continue; |
cec2f356 SP |
841 | if (match_clock && |
842 | clock.p != match_clock->p) | |
843 | continue; | |
79e53945 JB |
844 | |
845 | this_err = abs(clock.dot - target); | |
846 | if (this_err < err) { | |
847 | *best_clock = clock; | |
848 | err = this_err; | |
849 | } | |
850 | } | |
851 | } | |
852 | } | |
853 | } | |
854 | ||
855 | return (err != target); | |
856 | } | |
857 | ||
d4906093 | 858 | static bool |
a93e255f ACO |
859 | g4x_find_best_dpll(const intel_limit_t *limit, |
860 | struct intel_crtc_state *crtc_state, | |
ee9300bb DV |
861 | int target, int refclk, intel_clock_t *match_clock, |
862 | intel_clock_t *best_clock) | |
d4906093 | 863 | { |
3b1429d9 | 864 | struct drm_device *dev = crtc_state->base.crtc->dev; |
d4906093 ML |
865 | intel_clock_t clock; |
866 | int max_n; | |
3b1429d9 | 867 | bool found = false; |
6ba770dc AJ |
868 | /* approximately equals target * 0.00585 */ |
869 | int err_most = (target >> 8) + (target >> 9); | |
d4906093 ML |
870 | |
871 | memset(best_clock, 0, sizeof(*best_clock)); | |
3b1429d9 VS |
872 | |
873 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); | |
874 | ||
d4906093 | 875 | max_n = limit->n.max; |
f77f13e2 | 876 | /* based on hardware requirement, prefer smaller n to precision */ |
d4906093 | 877 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
f77f13e2 | 878 | /* based on hardware requirement, prefere larger m1,m2 */ |
d4906093 ML |
879 | for (clock.m1 = limit->m1.max; |
880 | clock.m1 >= limit->m1.min; clock.m1--) { | |
881 | for (clock.m2 = limit->m2.max; | |
882 | clock.m2 >= limit->m2.min; clock.m2--) { | |
883 | for (clock.p1 = limit->p1.max; | |
884 | clock.p1 >= limit->p1.min; clock.p1--) { | |
885 | int this_err; | |
886 | ||
dccbea3b | 887 | i9xx_calc_dpll_params(refclk, &clock); |
1b894b59 CW |
888 | if (!intel_PLL_is_valid(dev, limit, |
889 | &clock)) | |
d4906093 | 890 | continue; |
1b894b59 CW |
891 | |
892 | this_err = abs(clock.dot - target); | |
d4906093 ML |
893 | if (this_err < err_most) { |
894 | *best_clock = clock; | |
895 | err_most = this_err; | |
896 | max_n = clock.n; | |
897 | found = true; | |
898 | } | |
899 | } | |
900 | } | |
901 | } | |
902 | } | |
2c07245f ZW |
903 | return found; |
904 | } | |
905 | ||
d5dd62bd ID |
906 | /* |
907 | * Check if the calculated PLL configuration is more optimal compared to the | |
908 | * best configuration and error found so far. Return the calculated error. | |
909 | */ | |
910 | static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq, | |
911 | const intel_clock_t *calculated_clock, | |
912 | const intel_clock_t *best_clock, | |
913 | unsigned int best_error_ppm, | |
914 | unsigned int *error_ppm) | |
915 | { | |
9ca3ba01 ID |
916 | /* |
917 | * For CHV ignore the error and consider only the P value. | |
918 | * Prefer a bigger P value based on HW requirements. | |
919 | */ | |
920 | if (IS_CHERRYVIEW(dev)) { | |
921 | *error_ppm = 0; | |
922 | ||
923 | return calculated_clock->p > best_clock->p; | |
924 | } | |
925 | ||
24be4e46 ID |
926 | if (WARN_ON_ONCE(!target_freq)) |
927 | return false; | |
928 | ||
d5dd62bd ID |
929 | *error_ppm = div_u64(1000000ULL * |
930 | abs(target_freq - calculated_clock->dot), | |
931 | target_freq); | |
932 | /* | |
933 | * Prefer a better P value over a better (smaller) error if the error | |
934 | * is small. Ensure this preference for future configurations too by | |
935 | * setting the error to 0. | |
936 | */ | |
937 | if (*error_ppm < 100 && calculated_clock->p > best_clock->p) { | |
938 | *error_ppm = 0; | |
939 | ||
940 | return true; | |
941 | } | |
942 | ||
943 | return *error_ppm + 10 < best_error_ppm; | |
944 | } | |
945 | ||
a0c4da24 | 946 | static bool |
a93e255f ACO |
947 | vlv_find_best_dpll(const intel_limit_t *limit, |
948 | struct intel_crtc_state *crtc_state, | |
ee9300bb DV |
949 | int target, int refclk, intel_clock_t *match_clock, |
950 | intel_clock_t *best_clock) | |
a0c4da24 | 951 | { |
a93e255f | 952 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
a919ff14 | 953 | struct drm_device *dev = crtc->base.dev; |
6b4bf1c4 | 954 | intel_clock_t clock; |
69e4f900 | 955 | unsigned int bestppm = 1000000; |
27e639bf VS |
956 | /* min update 19.2 MHz */ |
957 | int max_n = min(limit->n.max, refclk / 19200); | |
49e497ef | 958 | bool found = false; |
a0c4da24 | 959 | |
6b4bf1c4 VS |
960 | target *= 5; /* fast clock */ |
961 | ||
962 | memset(best_clock, 0, sizeof(*best_clock)); | |
a0c4da24 JB |
963 | |
964 | /* based on hardware requirement, prefer smaller n to precision */ | |
27e639bf | 965 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
811bbf05 | 966 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
889059d8 | 967 | for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow; |
c1a9ae43 | 968 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
6b4bf1c4 | 969 | clock.p = clock.p1 * clock.p2; |
a0c4da24 | 970 | /* based on hardware requirement, prefer bigger m1,m2 values */ |
6b4bf1c4 | 971 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) { |
d5dd62bd | 972 | unsigned int ppm; |
69e4f900 | 973 | |
6b4bf1c4 VS |
974 | clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n, |
975 | refclk * clock.m1); | |
976 | ||
dccbea3b | 977 | vlv_calc_dpll_params(refclk, &clock); |
43b0ac53 | 978 | |
f01b7962 VS |
979 | if (!intel_PLL_is_valid(dev, limit, |
980 | &clock)) | |
43b0ac53 VS |
981 | continue; |
982 | ||
d5dd62bd ID |
983 | if (!vlv_PLL_is_optimal(dev, target, |
984 | &clock, | |
985 | best_clock, | |
986 | bestppm, &ppm)) | |
987 | continue; | |
6b4bf1c4 | 988 | |
d5dd62bd ID |
989 | *best_clock = clock; |
990 | bestppm = ppm; | |
991 | found = true; | |
a0c4da24 JB |
992 | } |
993 | } | |
994 | } | |
995 | } | |
a0c4da24 | 996 | |
49e497ef | 997 | return found; |
a0c4da24 | 998 | } |
a4fc5ed6 | 999 | |
ef9348c8 | 1000 | static bool |
a93e255f ACO |
1001 | chv_find_best_dpll(const intel_limit_t *limit, |
1002 | struct intel_crtc_state *crtc_state, | |
ef9348c8 CML |
1003 | int target, int refclk, intel_clock_t *match_clock, |
1004 | intel_clock_t *best_clock) | |
1005 | { | |
a93e255f | 1006 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
a919ff14 | 1007 | struct drm_device *dev = crtc->base.dev; |
9ca3ba01 | 1008 | unsigned int best_error_ppm; |
ef9348c8 CML |
1009 | intel_clock_t clock; |
1010 | uint64_t m2; | |
1011 | int found = false; | |
1012 | ||
1013 | memset(best_clock, 0, sizeof(*best_clock)); | |
9ca3ba01 | 1014 | best_error_ppm = 1000000; |
ef9348c8 CML |
1015 | |
1016 | /* | |
1017 | * Based on hardware doc, the n always set to 1, and m1 always | |
1018 | * set to 2. If requires to support 200Mhz refclk, we need to | |
1019 | * revisit this because n may not 1 anymore. | |
1020 | */ | |
1021 | clock.n = 1, clock.m1 = 2; | |
1022 | target *= 5; /* fast clock */ | |
1023 | ||
1024 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { | |
1025 | for (clock.p2 = limit->p2.p2_fast; | |
1026 | clock.p2 >= limit->p2.p2_slow; | |
1027 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { | |
9ca3ba01 | 1028 | unsigned int error_ppm; |
ef9348c8 CML |
1029 | |
1030 | clock.p = clock.p1 * clock.p2; | |
1031 | ||
1032 | m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p * | |
1033 | clock.n) << 22, refclk * clock.m1); | |
1034 | ||
1035 | if (m2 > INT_MAX/clock.m1) | |
1036 | continue; | |
1037 | ||
1038 | clock.m2 = m2; | |
1039 | ||
dccbea3b | 1040 | chv_calc_dpll_params(refclk, &clock); |
ef9348c8 CML |
1041 | |
1042 | if (!intel_PLL_is_valid(dev, limit, &clock)) | |
1043 | continue; | |
1044 | ||
9ca3ba01 ID |
1045 | if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock, |
1046 | best_error_ppm, &error_ppm)) | |
1047 | continue; | |
1048 | ||
1049 | *best_clock = clock; | |
1050 | best_error_ppm = error_ppm; | |
1051 | found = true; | |
ef9348c8 CML |
1052 | } |
1053 | } | |
1054 | ||
1055 | return found; | |
1056 | } | |
1057 | ||
5ab7b0b7 ID |
1058 | bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock, |
1059 | intel_clock_t *best_clock) | |
1060 | { | |
1061 | int refclk = i9xx_get_refclk(crtc_state, 0); | |
1062 | ||
1063 | return chv_find_best_dpll(intel_limit(crtc_state, refclk), crtc_state, | |
1064 | target_clock, refclk, NULL, best_clock); | |
1065 | } | |
1066 | ||
20ddf665 VS |
1067 | bool intel_crtc_active(struct drm_crtc *crtc) |
1068 | { | |
1069 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
1070 | ||
1071 | /* Be paranoid as we can arrive here with only partial | |
1072 | * state retrieved from the hardware during setup. | |
1073 | * | |
241bfc38 | 1074 | * We can ditch the adjusted_mode.crtc_clock check as soon |
20ddf665 VS |
1075 | * as Haswell has gained clock readout/fastboot support. |
1076 | * | |
66e514c1 | 1077 | * We can ditch the crtc->primary->fb check as soon as we can |
20ddf665 | 1078 | * properly reconstruct framebuffers. |
c3d1f436 MR |
1079 | * |
1080 | * FIXME: The intel_crtc->active here should be switched to | |
1081 | * crtc->state->active once we have proper CRTC states wired up | |
1082 | * for atomic. | |
20ddf665 | 1083 | */ |
c3d1f436 | 1084 | return intel_crtc->active && crtc->primary->state->fb && |
6e3c9717 | 1085 | intel_crtc->config->base.adjusted_mode.crtc_clock; |
20ddf665 VS |
1086 | } |
1087 | ||
a5c961d1 PZ |
1088 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, |
1089 | enum pipe pipe) | |
1090 | { | |
1091 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
1092 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
1093 | ||
6e3c9717 | 1094 | return intel_crtc->config->cpu_transcoder; |
a5c961d1 PZ |
1095 | } |
1096 | ||
fbf49ea2 VS |
1097 | static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe) |
1098 | { | |
1099 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f0f59a00 | 1100 | i915_reg_t reg = PIPEDSL(pipe); |
fbf49ea2 VS |
1101 | u32 line1, line2; |
1102 | u32 line_mask; | |
1103 | ||
1104 | if (IS_GEN2(dev)) | |
1105 | line_mask = DSL_LINEMASK_GEN2; | |
1106 | else | |
1107 | line_mask = DSL_LINEMASK_GEN3; | |
1108 | ||
1109 | line1 = I915_READ(reg) & line_mask; | |
6adfb1ef | 1110 | msleep(5); |
fbf49ea2 VS |
1111 | line2 = I915_READ(reg) & line_mask; |
1112 | ||
1113 | return line1 == line2; | |
1114 | } | |
1115 | ||
ab7ad7f6 KP |
1116 | /* |
1117 | * intel_wait_for_pipe_off - wait for pipe to turn off | |
575f7ab7 | 1118 | * @crtc: crtc whose pipe to wait for |
9d0498a2 JB |
1119 | * |
1120 | * After disabling a pipe, we can't wait for vblank in the usual way, | |
1121 | * spinning on the vblank interrupt status bit, since we won't actually | |
1122 | * see an interrupt when the pipe is disabled. | |
1123 | * | |
ab7ad7f6 KP |
1124 | * On Gen4 and above: |
1125 | * wait for the pipe register state bit to turn off | |
1126 | * | |
1127 | * Otherwise: | |
1128 | * wait for the display line value to settle (it usually | |
1129 | * ends up stopping at the start of the next frame). | |
58e10eb9 | 1130 | * |
9d0498a2 | 1131 | */ |
575f7ab7 | 1132 | static void intel_wait_for_pipe_off(struct intel_crtc *crtc) |
9d0498a2 | 1133 | { |
575f7ab7 | 1134 | struct drm_device *dev = crtc->base.dev; |
9d0498a2 | 1135 | struct drm_i915_private *dev_priv = dev->dev_private; |
6e3c9717 | 1136 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
575f7ab7 | 1137 | enum pipe pipe = crtc->pipe; |
ab7ad7f6 KP |
1138 | |
1139 | if (INTEL_INFO(dev)->gen >= 4) { | |
f0f59a00 | 1140 | i915_reg_t reg = PIPECONF(cpu_transcoder); |
ab7ad7f6 KP |
1141 | |
1142 | /* Wait for the Pipe State to go off */ | |
58e10eb9 CW |
1143 | if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0, |
1144 | 100)) | |
284637d9 | 1145 | WARN(1, "pipe_off wait timed out\n"); |
ab7ad7f6 | 1146 | } else { |
ab7ad7f6 | 1147 | /* Wait for the display line to settle */ |
fbf49ea2 | 1148 | if (wait_for(pipe_dsl_stopped(dev, pipe), 100)) |
284637d9 | 1149 | WARN(1, "pipe_off wait timed out\n"); |
ab7ad7f6 | 1150 | } |
79e53945 JB |
1151 | } |
1152 | ||
b24e7179 | 1153 | /* Only for pre-ILK configs */ |
55607e8a DV |
1154 | void assert_pll(struct drm_i915_private *dev_priv, |
1155 | enum pipe pipe, bool state) | |
b24e7179 | 1156 | { |
b24e7179 JB |
1157 | u32 val; |
1158 | bool cur_state; | |
1159 | ||
649636ef | 1160 | val = I915_READ(DPLL(pipe)); |
b24e7179 | 1161 | cur_state = !!(val & DPLL_VCO_ENABLE); |
e2c719b7 | 1162 | I915_STATE_WARN(cur_state != state, |
b24e7179 | 1163 | "PLL state assertion failure (expected %s, current %s)\n", |
87ad3212 | 1164 | onoff(state), onoff(cur_state)); |
b24e7179 | 1165 | } |
b24e7179 | 1166 | |
23538ef1 JN |
1167 | /* XXX: the dsi pll is shared between MIPI DSI ports */ |
1168 | static void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state) | |
1169 | { | |
1170 | u32 val; | |
1171 | bool cur_state; | |
1172 | ||
a580516d | 1173 | mutex_lock(&dev_priv->sb_lock); |
23538ef1 | 1174 | val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); |
a580516d | 1175 | mutex_unlock(&dev_priv->sb_lock); |
23538ef1 JN |
1176 | |
1177 | cur_state = val & DSI_PLL_VCO_EN; | |
e2c719b7 | 1178 | I915_STATE_WARN(cur_state != state, |
23538ef1 | 1179 | "DSI PLL state assertion failure (expected %s, current %s)\n", |
87ad3212 | 1180 | onoff(state), onoff(cur_state)); |
23538ef1 JN |
1181 | } |
1182 | #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true) | |
1183 | #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false) | |
1184 | ||
55607e8a | 1185 | struct intel_shared_dpll * |
e2b78267 DV |
1186 | intel_crtc_to_shared_dpll(struct intel_crtc *crtc) |
1187 | { | |
1188 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; | |
1189 | ||
6e3c9717 | 1190 | if (crtc->config->shared_dpll < 0) |
e2b78267 DV |
1191 | return NULL; |
1192 | ||
6e3c9717 | 1193 | return &dev_priv->shared_dplls[crtc->config->shared_dpll]; |
e2b78267 DV |
1194 | } |
1195 | ||
040484af | 1196 | /* For ILK+ */ |
55607e8a DV |
1197 | void assert_shared_dpll(struct drm_i915_private *dev_priv, |
1198 | struct intel_shared_dpll *pll, | |
1199 | bool state) | |
040484af | 1200 | { |
040484af | 1201 | bool cur_state; |
5358901f | 1202 | struct intel_dpll_hw_state hw_state; |
040484af | 1203 | |
87ad3212 | 1204 | if (WARN(!pll, "asserting DPLL %s with no DPLL\n", onoff(state))) |
ee7b9f93 | 1205 | return; |
ee7b9f93 | 1206 | |
5358901f | 1207 | cur_state = pll->get_hw_state(dev_priv, pll, &hw_state); |
e2c719b7 | 1208 | I915_STATE_WARN(cur_state != state, |
5358901f | 1209 | "%s assertion failure (expected %s, current %s)\n", |
87ad3212 | 1210 | pll->name, onoff(state), onoff(cur_state)); |
040484af | 1211 | } |
040484af JB |
1212 | |
1213 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, | |
1214 | enum pipe pipe, bool state) | |
1215 | { | |
040484af | 1216 | bool cur_state; |
ad80a810 PZ |
1217 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
1218 | pipe); | |
040484af | 1219 | |
affa9354 PZ |
1220 | if (HAS_DDI(dev_priv->dev)) { |
1221 | /* DDI does not have a specific FDI_TX register */ | |
649636ef | 1222 | u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
ad80a810 | 1223 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
bf507ef7 | 1224 | } else { |
649636ef | 1225 | u32 val = I915_READ(FDI_TX_CTL(pipe)); |
bf507ef7 ED |
1226 | cur_state = !!(val & FDI_TX_ENABLE); |
1227 | } | |
e2c719b7 | 1228 | I915_STATE_WARN(cur_state != state, |
040484af | 1229 | "FDI TX state assertion failure (expected %s, current %s)\n", |
87ad3212 | 1230 | onoff(state), onoff(cur_state)); |
040484af JB |
1231 | } |
1232 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) | |
1233 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) | |
1234 | ||
1235 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, | |
1236 | enum pipe pipe, bool state) | |
1237 | { | |
040484af JB |
1238 | u32 val; |
1239 | bool cur_state; | |
1240 | ||
649636ef | 1241 | val = I915_READ(FDI_RX_CTL(pipe)); |
d63fa0dc | 1242 | cur_state = !!(val & FDI_RX_ENABLE); |
e2c719b7 | 1243 | I915_STATE_WARN(cur_state != state, |
040484af | 1244 | "FDI RX state assertion failure (expected %s, current %s)\n", |
87ad3212 | 1245 | onoff(state), onoff(cur_state)); |
040484af JB |
1246 | } |
1247 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) | |
1248 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) | |
1249 | ||
1250 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, | |
1251 | enum pipe pipe) | |
1252 | { | |
040484af JB |
1253 | u32 val; |
1254 | ||
1255 | /* ILK FDI PLL is always enabled */ | |
3d13ef2e | 1256 | if (INTEL_INFO(dev_priv->dev)->gen == 5) |
040484af JB |
1257 | return; |
1258 | ||
bf507ef7 | 1259 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
affa9354 | 1260 | if (HAS_DDI(dev_priv->dev)) |
bf507ef7 ED |
1261 | return; |
1262 | ||
649636ef | 1263 | val = I915_READ(FDI_TX_CTL(pipe)); |
e2c719b7 | 1264 | I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n"); |
040484af JB |
1265 | } |
1266 | ||
55607e8a DV |
1267 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, |
1268 | enum pipe pipe, bool state) | |
040484af | 1269 | { |
040484af | 1270 | u32 val; |
55607e8a | 1271 | bool cur_state; |
040484af | 1272 | |
649636ef | 1273 | val = I915_READ(FDI_RX_CTL(pipe)); |
55607e8a | 1274 | cur_state = !!(val & FDI_RX_PLL_ENABLE); |
e2c719b7 | 1275 | I915_STATE_WARN(cur_state != state, |
55607e8a | 1276 | "FDI RX PLL assertion failure (expected %s, current %s)\n", |
87ad3212 | 1277 | onoff(state), onoff(cur_state)); |
040484af JB |
1278 | } |
1279 | ||
b680c37a DV |
1280 | void assert_panel_unlocked(struct drm_i915_private *dev_priv, |
1281 | enum pipe pipe) | |
ea0760cf | 1282 | { |
bedd4dba | 1283 | struct drm_device *dev = dev_priv->dev; |
f0f59a00 | 1284 | i915_reg_t pp_reg; |
ea0760cf JB |
1285 | u32 val; |
1286 | enum pipe panel_pipe = PIPE_A; | |
0de3b485 | 1287 | bool locked = true; |
ea0760cf | 1288 | |
bedd4dba JN |
1289 | if (WARN_ON(HAS_DDI(dev))) |
1290 | return; | |
1291 | ||
1292 | if (HAS_PCH_SPLIT(dev)) { | |
1293 | u32 port_sel; | |
1294 | ||
ea0760cf | 1295 | pp_reg = PCH_PP_CONTROL; |
bedd4dba JN |
1296 | port_sel = I915_READ(PCH_PP_ON_DELAYS) & PANEL_PORT_SELECT_MASK; |
1297 | ||
1298 | if (port_sel == PANEL_PORT_SELECT_LVDS && | |
1299 | I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT) | |
1300 | panel_pipe = PIPE_B; | |
1301 | /* XXX: else fix for eDP */ | |
666a4537 | 1302 | } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
bedd4dba JN |
1303 | /* presumably write lock depends on pipe, not port select */ |
1304 | pp_reg = VLV_PIPE_PP_CONTROL(pipe); | |
1305 | panel_pipe = pipe; | |
ea0760cf JB |
1306 | } else { |
1307 | pp_reg = PP_CONTROL; | |
bedd4dba JN |
1308 | if (I915_READ(LVDS) & LVDS_PIPEB_SELECT) |
1309 | panel_pipe = PIPE_B; | |
ea0760cf JB |
1310 | } |
1311 | ||
1312 | val = I915_READ(pp_reg); | |
1313 | if (!(val & PANEL_POWER_ON) || | |
ec49ba2d | 1314 | ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) |
ea0760cf JB |
1315 | locked = false; |
1316 | ||
e2c719b7 | 1317 | I915_STATE_WARN(panel_pipe == pipe && locked, |
ea0760cf | 1318 | "panel assertion failure, pipe %c regs locked\n", |
9db4a9c7 | 1319 | pipe_name(pipe)); |
ea0760cf JB |
1320 | } |
1321 | ||
93ce0ba6 JN |
1322 | static void assert_cursor(struct drm_i915_private *dev_priv, |
1323 | enum pipe pipe, bool state) | |
1324 | { | |
1325 | struct drm_device *dev = dev_priv->dev; | |
1326 | bool cur_state; | |
1327 | ||
d9d82081 | 1328 | if (IS_845G(dev) || IS_I865G(dev)) |
0b87c24e | 1329 | cur_state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE; |
d9d82081 | 1330 | else |
5efb3e28 | 1331 | cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE; |
93ce0ba6 | 1332 | |
e2c719b7 | 1333 | I915_STATE_WARN(cur_state != state, |
93ce0ba6 | 1334 | "cursor on pipe %c assertion failure (expected %s, current %s)\n", |
87ad3212 | 1335 | pipe_name(pipe), onoff(state), onoff(cur_state)); |
93ce0ba6 JN |
1336 | } |
1337 | #define assert_cursor_enabled(d, p) assert_cursor(d, p, true) | |
1338 | #define assert_cursor_disabled(d, p) assert_cursor(d, p, false) | |
1339 | ||
b840d907 JB |
1340 | void assert_pipe(struct drm_i915_private *dev_priv, |
1341 | enum pipe pipe, bool state) | |
b24e7179 | 1342 | { |
63d7bbe9 | 1343 | bool cur_state; |
702e7a56 PZ |
1344 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
1345 | pipe); | |
4feed0eb | 1346 | enum intel_display_power_domain power_domain; |
b24e7179 | 1347 | |
b6b5d049 VS |
1348 | /* if we need the pipe quirk it must be always on */ |
1349 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || | |
1350 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
8e636784 DV |
1351 | state = true; |
1352 | ||
4feed0eb ID |
1353 | power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); |
1354 | if (intel_display_power_get_if_enabled(dev_priv, power_domain)) { | |
649636ef | 1355 | u32 val = I915_READ(PIPECONF(cpu_transcoder)); |
69310161 | 1356 | cur_state = !!(val & PIPECONF_ENABLE); |
4feed0eb ID |
1357 | |
1358 | intel_display_power_put(dev_priv, power_domain); | |
1359 | } else { | |
1360 | cur_state = false; | |
69310161 PZ |
1361 | } |
1362 | ||
e2c719b7 | 1363 | I915_STATE_WARN(cur_state != state, |
63d7bbe9 | 1364 | "pipe %c assertion failure (expected %s, current %s)\n", |
87ad3212 | 1365 | pipe_name(pipe), onoff(state), onoff(cur_state)); |
b24e7179 JB |
1366 | } |
1367 | ||
931872fc CW |
1368 | static void assert_plane(struct drm_i915_private *dev_priv, |
1369 | enum plane plane, bool state) | |
b24e7179 | 1370 | { |
b24e7179 | 1371 | u32 val; |
931872fc | 1372 | bool cur_state; |
b24e7179 | 1373 | |
649636ef | 1374 | val = I915_READ(DSPCNTR(plane)); |
931872fc | 1375 | cur_state = !!(val & DISPLAY_PLANE_ENABLE); |
e2c719b7 | 1376 | I915_STATE_WARN(cur_state != state, |
931872fc | 1377 | "plane %c assertion failure (expected %s, current %s)\n", |
87ad3212 | 1378 | plane_name(plane), onoff(state), onoff(cur_state)); |
b24e7179 JB |
1379 | } |
1380 | ||
931872fc CW |
1381 | #define assert_plane_enabled(d, p) assert_plane(d, p, true) |
1382 | #define assert_plane_disabled(d, p) assert_plane(d, p, false) | |
1383 | ||
b24e7179 JB |
1384 | static void assert_planes_disabled(struct drm_i915_private *dev_priv, |
1385 | enum pipe pipe) | |
1386 | { | |
653e1026 | 1387 | struct drm_device *dev = dev_priv->dev; |
649636ef | 1388 | int i; |
b24e7179 | 1389 | |
653e1026 VS |
1390 | /* Primary planes are fixed to pipes on gen4+ */ |
1391 | if (INTEL_INFO(dev)->gen >= 4) { | |
649636ef | 1392 | u32 val = I915_READ(DSPCNTR(pipe)); |
e2c719b7 | 1393 | I915_STATE_WARN(val & DISPLAY_PLANE_ENABLE, |
28c05794 AJ |
1394 | "plane %c assertion failure, should be disabled but not\n", |
1395 | plane_name(pipe)); | |
19ec1358 | 1396 | return; |
28c05794 | 1397 | } |
19ec1358 | 1398 | |
b24e7179 | 1399 | /* Need to check both planes against the pipe */ |
055e393f | 1400 | for_each_pipe(dev_priv, i) { |
649636ef VS |
1401 | u32 val = I915_READ(DSPCNTR(i)); |
1402 | enum pipe cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> | |
b24e7179 | 1403 | DISPPLANE_SEL_PIPE_SHIFT; |
e2c719b7 | 1404 | I915_STATE_WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe, |
9db4a9c7 JB |
1405 | "plane %c assertion failure, should be off on pipe %c but is still active\n", |
1406 | plane_name(i), pipe_name(pipe)); | |
b24e7179 JB |
1407 | } |
1408 | } | |
1409 | ||
19332d7a JB |
1410 | static void assert_sprites_disabled(struct drm_i915_private *dev_priv, |
1411 | enum pipe pipe) | |
1412 | { | |
20674eef | 1413 | struct drm_device *dev = dev_priv->dev; |
649636ef | 1414 | int sprite; |
19332d7a | 1415 | |
7feb8b88 | 1416 | if (INTEL_INFO(dev)->gen >= 9) { |
3bdcfc0c | 1417 | for_each_sprite(dev_priv, pipe, sprite) { |
649636ef | 1418 | u32 val = I915_READ(PLANE_CTL(pipe, sprite)); |
e2c719b7 | 1419 | I915_STATE_WARN(val & PLANE_CTL_ENABLE, |
7feb8b88 DL |
1420 | "plane %d assertion failure, should be off on pipe %c but is still active\n", |
1421 | sprite, pipe_name(pipe)); | |
1422 | } | |
666a4537 | 1423 | } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
3bdcfc0c | 1424 | for_each_sprite(dev_priv, pipe, sprite) { |
649636ef | 1425 | u32 val = I915_READ(SPCNTR(pipe, sprite)); |
e2c719b7 | 1426 | I915_STATE_WARN(val & SP_ENABLE, |
20674eef | 1427 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
1fe47785 | 1428 | sprite_name(pipe, sprite), pipe_name(pipe)); |
20674eef VS |
1429 | } |
1430 | } else if (INTEL_INFO(dev)->gen >= 7) { | |
649636ef | 1431 | u32 val = I915_READ(SPRCTL(pipe)); |
e2c719b7 | 1432 | I915_STATE_WARN(val & SPRITE_ENABLE, |
06da8da2 | 1433 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
20674eef VS |
1434 | plane_name(pipe), pipe_name(pipe)); |
1435 | } else if (INTEL_INFO(dev)->gen >= 5) { | |
649636ef | 1436 | u32 val = I915_READ(DVSCNTR(pipe)); |
e2c719b7 | 1437 | I915_STATE_WARN(val & DVS_ENABLE, |
06da8da2 | 1438 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
20674eef | 1439 | plane_name(pipe), pipe_name(pipe)); |
19332d7a JB |
1440 | } |
1441 | } | |
1442 | ||
08c71e5e VS |
1443 | static void assert_vblank_disabled(struct drm_crtc *crtc) |
1444 | { | |
e2c719b7 | 1445 | if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0)) |
08c71e5e VS |
1446 | drm_crtc_vblank_put(crtc); |
1447 | } | |
1448 | ||
89eff4be | 1449 | static void ibx_assert_pch_refclk_enabled(struct drm_i915_private *dev_priv) |
92f2584a JB |
1450 | { |
1451 | u32 val; | |
1452 | bool enabled; | |
1453 | ||
e2c719b7 | 1454 | I915_STATE_WARN_ON(!(HAS_PCH_IBX(dev_priv->dev) || HAS_PCH_CPT(dev_priv->dev))); |
9d82aa17 | 1455 | |
92f2584a JB |
1456 | val = I915_READ(PCH_DREF_CONTROL); |
1457 | enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK | | |
1458 | DREF_SUPERSPREAD_SOURCE_MASK)); | |
e2c719b7 | 1459 | I915_STATE_WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n"); |
92f2584a JB |
1460 | } |
1461 | ||
ab9412ba DV |
1462 | static void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, |
1463 | enum pipe pipe) | |
92f2584a | 1464 | { |
92f2584a JB |
1465 | u32 val; |
1466 | bool enabled; | |
1467 | ||
649636ef | 1468 | val = I915_READ(PCH_TRANSCONF(pipe)); |
92f2584a | 1469 | enabled = !!(val & TRANS_ENABLE); |
e2c719b7 | 1470 | I915_STATE_WARN(enabled, |
9db4a9c7 JB |
1471 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
1472 | pipe_name(pipe)); | |
92f2584a JB |
1473 | } |
1474 | ||
4e634389 KP |
1475 | static bool dp_pipe_enabled(struct drm_i915_private *dev_priv, |
1476 | enum pipe pipe, u32 port_sel, u32 val) | |
f0575e92 KP |
1477 | { |
1478 | if ((val & DP_PORT_EN) == 0) | |
1479 | return false; | |
1480 | ||
1481 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
f0f59a00 | 1482 | u32 trans_dp_ctl = I915_READ(TRANS_DP_CTL(pipe)); |
f0575e92 KP |
1483 | if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel) |
1484 | return false; | |
44f37d1f CML |
1485 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
1486 | if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe)) | |
1487 | return false; | |
f0575e92 KP |
1488 | } else { |
1489 | if ((val & DP_PIPE_MASK) != (pipe << 30)) | |
1490 | return false; | |
1491 | } | |
1492 | return true; | |
1493 | } | |
1494 | ||
1519b995 KP |
1495 | static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv, |
1496 | enum pipe pipe, u32 val) | |
1497 | { | |
dc0fa718 | 1498 | if ((val & SDVO_ENABLE) == 0) |
1519b995 KP |
1499 | return false; |
1500 | ||
1501 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
dc0fa718 | 1502 | if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe)) |
1519b995 | 1503 | return false; |
44f37d1f CML |
1504 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
1505 | if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe)) | |
1506 | return false; | |
1519b995 | 1507 | } else { |
dc0fa718 | 1508 | if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe)) |
1519b995 KP |
1509 | return false; |
1510 | } | |
1511 | return true; | |
1512 | } | |
1513 | ||
1514 | static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv, | |
1515 | enum pipe pipe, u32 val) | |
1516 | { | |
1517 | if ((val & LVDS_PORT_EN) == 0) | |
1518 | return false; | |
1519 | ||
1520 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
1521 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) | |
1522 | return false; | |
1523 | } else { | |
1524 | if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe)) | |
1525 | return false; | |
1526 | } | |
1527 | return true; | |
1528 | } | |
1529 | ||
1530 | static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv, | |
1531 | enum pipe pipe, u32 val) | |
1532 | { | |
1533 | if ((val & ADPA_DAC_ENABLE) == 0) | |
1534 | return false; | |
1535 | if (HAS_PCH_CPT(dev_priv->dev)) { | |
1536 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) | |
1537 | return false; | |
1538 | } else { | |
1539 | if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe)) | |
1540 | return false; | |
1541 | } | |
1542 | return true; | |
1543 | } | |
1544 | ||
291906f1 | 1545 | static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv, |
f0f59a00 VS |
1546 | enum pipe pipe, i915_reg_t reg, |
1547 | u32 port_sel) | |
291906f1 | 1548 | { |
47a05eca | 1549 | u32 val = I915_READ(reg); |
e2c719b7 | 1550 | I915_STATE_WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val), |
291906f1 | 1551 | "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n", |
f0f59a00 | 1552 | i915_mmio_reg_offset(reg), pipe_name(pipe)); |
de9a35ab | 1553 | |
e2c719b7 | 1554 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0 |
75c5da27 | 1555 | && (val & DP_PIPEB_SELECT), |
de9a35ab | 1556 | "IBX PCH dp port still using transcoder B\n"); |
291906f1 JB |
1557 | } |
1558 | ||
1559 | static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv, | |
f0f59a00 | 1560 | enum pipe pipe, i915_reg_t reg) |
291906f1 | 1561 | { |
47a05eca | 1562 | u32 val = I915_READ(reg); |
e2c719b7 | 1563 | I915_STATE_WARN(hdmi_pipe_enabled(dev_priv, pipe, val), |
23c99e77 | 1564 | "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n", |
f0f59a00 | 1565 | i915_mmio_reg_offset(reg), pipe_name(pipe)); |
de9a35ab | 1566 | |
e2c719b7 | 1567 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_ENABLE) == 0 |
75c5da27 | 1568 | && (val & SDVO_PIPE_B_SELECT), |
de9a35ab | 1569 | "IBX PCH hdmi port still using transcoder B\n"); |
291906f1 JB |
1570 | } |
1571 | ||
1572 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, | |
1573 | enum pipe pipe) | |
1574 | { | |
291906f1 | 1575 | u32 val; |
291906f1 | 1576 | |
f0575e92 KP |
1577 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B); |
1578 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C); | |
1579 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D); | |
291906f1 | 1580 | |
649636ef | 1581 | val = I915_READ(PCH_ADPA); |
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 | 1585 | |
649636ef | 1586 | val = I915_READ(PCH_LVDS); |
e2c719b7 | 1587 | I915_STATE_WARN(lvds_pipe_enabled(dev_priv, pipe, val), |
291906f1 | 1588 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1589 | pipe_name(pipe)); |
291906f1 | 1590 | |
e2debe91 PZ |
1591 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB); |
1592 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC); | |
1593 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID); | |
291906f1 JB |
1594 | } |
1595 | ||
d288f65f | 1596 | static void vlv_enable_pll(struct intel_crtc *crtc, |
5cec258b | 1597 | const struct intel_crtc_state *pipe_config) |
87442f73 | 1598 | { |
426115cf DV |
1599 | struct drm_device *dev = crtc->base.dev; |
1600 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f0f59a00 | 1601 | i915_reg_t reg = DPLL(crtc->pipe); |
d288f65f | 1602 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
87442f73 | 1603 | |
426115cf | 1604 | assert_pipe_disabled(dev_priv, crtc->pipe); |
87442f73 | 1605 | |
87442f73 | 1606 | /* PLL is protected by panel, make sure we can write it */ |
6a9e7363 | 1607 | if (IS_MOBILE(dev_priv->dev)) |
426115cf | 1608 | assert_panel_unlocked(dev_priv, crtc->pipe); |
87442f73 | 1609 | |
426115cf DV |
1610 | I915_WRITE(reg, dpll); |
1611 | POSTING_READ(reg); | |
1612 | udelay(150); | |
1613 | ||
1614 | if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) | |
1615 | DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe); | |
1616 | ||
d288f65f | 1617 | I915_WRITE(DPLL_MD(crtc->pipe), pipe_config->dpll_hw_state.dpll_md); |
426115cf | 1618 | POSTING_READ(DPLL_MD(crtc->pipe)); |
87442f73 DV |
1619 | |
1620 | /* We do this three times for luck */ | |
426115cf | 1621 | I915_WRITE(reg, dpll); |
87442f73 DV |
1622 | POSTING_READ(reg); |
1623 | udelay(150); /* wait for warmup */ | |
426115cf | 1624 | I915_WRITE(reg, dpll); |
87442f73 DV |
1625 | POSTING_READ(reg); |
1626 | udelay(150); /* wait for warmup */ | |
426115cf | 1627 | I915_WRITE(reg, dpll); |
87442f73 DV |
1628 | POSTING_READ(reg); |
1629 | udelay(150); /* wait for warmup */ | |
1630 | } | |
1631 | ||
d288f65f | 1632 | static void chv_enable_pll(struct intel_crtc *crtc, |
5cec258b | 1633 | const struct intel_crtc_state *pipe_config) |
9d556c99 CML |
1634 | { |
1635 | struct drm_device *dev = crtc->base.dev; | |
1636 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1637 | int pipe = crtc->pipe; | |
1638 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
9d556c99 CML |
1639 | u32 tmp; |
1640 | ||
1641 | assert_pipe_disabled(dev_priv, crtc->pipe); | |
1642 | ||
a580516d | 1643 | mutex_lock(&dev_priv->sb_lock); |
9d556c99 CML |
1644 | |
1645 | /* Enable back the 10bit clock to display controller */ | |
1646 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); | |
1647 | tmp |= DPIO_DCLKP_EN; | |
1648 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp); | |
1649 | ||
54433e91 VS |
1650 | mutex_unlock(&dev_priv->sb_lock); |
1651 | ||
9d556c99 CML |
1652 | /* |
1653 | * Need to wait > 100ns between dclkp clock enable bit and PLL enable. | |
1654 | */ | |
1655 | udelay(1); | |
1656 | ||
1657 | /* Enable PLL */ | |
d288f65f | 1658 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
9d556c99 CML |
1659 | |
1660 | /* Check PLL is locked */ | |
a11b0703 | 1661 | if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) |
9d556c99 CML |
1662 | DRM_ERROR("PLL %d failed to lock\n", pipe); |
1663 | ||
a11b0703 | 1664 | /* not sure when this should be written */ |
d288f65f | 1665 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
a11b0703 | 1666 | POSTING_READ(DPLL_MD(pipe)); |
9d556c99 CML |
1667 | } |
1668 | ||
1c4e0274 VS |
1669 | static int intel_num_dvo_pipes(struct drm_device *dev) |
1670 | { | |
1671 | struct intel_crtc *crtc; | |
1672 | int count = 0; | |
1673 | ||
1674 | for_each_intel_crtc(dev, crtc) | |
3538b9df | 1675 | count += crtc->base.state->active && |
409ee761 | 1676 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO); |
1c4e0274 VS |
1677 | |
1678 | return count; | |
1679 | } | |
1680 | ||
66e3d5c0 | 1681 | static void i9xx_enable_pll(struct intel_crtc *crtc) |
63d7bbe9 | 1682 | { |
66e3d5c0 DV |
1683 | struct drm_device *dev = crtc->base.dev; |
1684 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f0f59a00 | 1685 | i915_reg_t reg = DPLL(crtc->pipe); |
6e3c9717 | 1686 | u32 dpll = crtc->config->dpll_hw_state.dpll; |
63d7bbe9 | 1687 | |
66e3d5c0 | 1688 | assert_pipe_disabled(dev_priv, crtc->pipe); |
58c6eaa2 | 1689 | |
63d7bbe9 | 1690 | /* No really, not for ILK+ */ |
3d13ef2e | 1691 | BUG_ON(INTEL_INFO(dev)->gen >= 5); |
63d7bbe9 JB |
1692 | |
1693 | /* PLL is protected by panel, make sure we can write it */ | |
66e3d5c0 DV |
1694 | if (IS_MOBILE(dev) && !IS_I830(dev)) |
1695 | assert_panel_unlocked(dev_priv, crtc->pipe); | |
63d7bbe9 | 1696 | |
1c4e0274 VS |
1697 | /* Enable DVO 2x clock on both PLLs if necessary */ |
1698 | if (IS_I830(dev) && intel_num_dvo_pipes(dev) > 0) { | |
1699 | /* | |
1700 | * It appears to be important that we don't enable this | |
1701 | * for the current pipe before otherwise configuring the | |
1702 | * PLL. No idea how this should be handled if multiple | |
1703 | * DVO outputs are enabled simultaneosly. | |
1704 | */ | |
1705 | dpll |= DPLL_DVO_2X_MODE; | |
1706 | I915_WRITE(DPLL(!crtc->pipe), | |
1707 | I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE); | |
1708 | } | |
66e3d5c0 | 1709 | |
c2b63374 VS |
1710 | /* |
1711 | * Apparently we need to have VGA mode enabled prior to changing | |
1712 | * the P1/P2 dividers. Otherwise the DPLL will keep using the old | |
1713 | * dividers, even though the register value does change. | |
1714 | */ | |
1715 | I915_WRITE(reg, 0); | |
1716 | ||
8e7a65aa VS |
1717 | I915_WRITE(reg, dpll); |
1718 | ||
66e3d5c0 DV |
1719 | /* Wait for the clocks to stabilize. */ |
1720 | POSTING_READ(reg); | |
1721 | udelay(150); | |
1722 | ||
1723 | if (INTEL_INFO(dev)->gen >= 4) { | |
1724 | I915_WRITE(DPLL_MD(crtc->pipe), | |
6e3c9717 | 1725 | crtc->config->dpll_hw_state.dpll_md); |
66e3d5c0 DV |
1726 | } else { |
1727 | /* The pixel multiplier can only be updated once the | |
1728 | * DPLL is enabled and the clocks are stable. | |
1729 | * | |
1730 | * So write it again. | |
1731 | */ | |
1732 | I915_WRITE(reg, dpll); | |
1733 | } | |
63d7bbe9 JB |
1734 | |
1735 | /* We do this three times for luck */ | |
66e3d5c0 | 1736 | I915_WRITE(reg, dpll); |
63d7bbe9 JB |
1737 | POSTING_READ(reg); |
1738 | udelay(150); /* wait for warmup */ | |
66e3d5c0 | 1739 | I915_WRITE(reg, dpll); |
63d7bbe9 JB |
1740 | POSTING_READ(reg); |
1741 | udelay(150); /* wait for warmup */ | |
66e3d5c0 | 1742 | I915_WRITE(reg, dpll); |
63d7bbe9 JB |
1743 | POSTING_READ(reg); |
1744 | udelay(150); /* wait for warmup */ | |
1745 | } | |
1746 | ||
1747 | /** | |
50b44a44 | 1748 | * i9xx_disable_pll - disable a PLL |
63d7bbe9 JB |
1749 | * @dev_priv: i915 private structure |
1750 | * @pipe: pipe PLL to disable | |
1751 | * | |
1752 | * Disable the PLL for @pipe, making sure the pipe is off first. | |
1753 | * | |
1754 | * Note! This is for pre-ILK only. | |
1755 | */ | |
1c4e0274 | 1756 | static void i9xx_disable_pll(struct intel_crtc *crtc) |
63d7bbe9 | 1757 | { |
1c4e0274 VS |
1758 | struct drm_device *dev = crtc->base.dev; |
1759 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1760 | enum pipe pipe = crtc->pipe; | |
1761 | ||
1762 | /* Disable DVO 2x clock on both PLLs if necessary */ | |
1763 | if (IS_I830(dev) && | |
409ee761 | 1764 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO) && |
3538b9df | 1765 | !intel_num_dvo_pipes(dev)) { |
1c4e0274 VS |
1766 | I915_WRITE(DPLL(PIPE_B), |
1767 | I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE); | |
1768 | I915_WRITE(DPLL(PIPE_A), | |
1769 | I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE); | |
1770 | } | |
1771 | ||
b6b5d049 VS |
1772 | /* Don't disable pipe or pipe PLLs if needed */ |
1773 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || | |
1774 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
63d7bbe9 JB |
1775 | return; |
1776 | ||
1777 | /* Make sure the pipe isn't still relying on us */ | |
1778 | assert_pipe_disabled(dev_priv, pipe); | |
1779 | ||
b8afb911 | 1780 | I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS); |
50b44a44 | 1781 | POSTING_READ(DPLL(pipe)); |
63d7bbe9 JB |
1782 | } |
1783 | ||
f6071166 JB |
1784 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
1785 | { | |
b8afb911 | 1786 | u32 val; |
f6071166 JB |
1787 | |
1788 | /* Make sure the pipe isn't still relying on us */ | |
1789 | assert_pipe_disabled(dev_priv, pipe); | |
1790 | ||
e5cbfbfb ID |
1791 | /* |
1792 | * Leave integrated clock source and reference clock enabled for pipe B. | |
1793 | * The latter is needed for VGA hotplug / manual detection. | |
1794 | */ | |
b8afb911 | 1795 | val = DPLL_VGA_MODE_DIS; |
f6071166 | 1796 | if (pipe == PIPE_B) |
60bfe44f | 1797 | val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REF_CLK_ENABLE_VLV; |
f6071166 JB |
1798 | I915_WRITE(DPLL(pipe), val); |
1799 | POSTING_READ(DPLL(pipe)); | |
076ed3b2 CML |
1800 | |
1801 | } | |
1802 | ||
1803 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) | |
1804 | { | |
d752048d | 1805 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
076ed3b2 CML |
1806 | u32 val; |
1807 | ||
a11b0703 VS |
1808 | /* Make sure the pipe isn't still relying on us */ |
1809 | assert_pipe_disabled(dev_priv, pipe); | |
076ed3b2 | 1810 | |
a11b0703 | 1811 | /* Set PLL en = 0 */ |
60bfe44f VS |
1812 | val = DPLL_SSC_REF_CLK_CHV | |
1813 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; | |
a11b0703 VS |
1814 | if (pipe != PIPE_A) |
1815 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
1816 | I915_WRITE(DPLL(pipe), val); | |
1817 | POSTING_READ(DPLL(pipe)); | |
d752048d | 1818 | |
a580516d | 1819 | mutex_lock(&dev_priv->sb_lock); |
d752048d VS |
1820 | |
1821 | /* Disable 10bit clock to display controller */ | |
1822 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); | |
1823 | val &= ~DPIO_DCLKP_EN; | |
1824 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); | |
1825 | ||
a580516d | 1826 | mutex_unlock(&dev_priv->sb_lock); |
f6071166 JB |
1827 | } |
1828 | ||
e4607fcf | 1829 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, |
9b6de0a1 VS |
1830 | struct intel_digital_port *dport, |
1831 | unsigned int expected_mask) | |
89b667f8 JB |
1832 | { |
1833 | u32 port_mask; | |
f0f59a00 | 1834 | i915_reg_t dpll_reg; |
89b667f8 | 1835 | |
e4607fcf CML |
1836 | switch (dport->port) { |
1837 | case PORT_B: | |
89b667f8 | 1838 | port_mask = DPLL_PORTB_READY_MASK; |
00fc31b7 | 1839 | dpll_reg = DPLL(0); |
e4607fcf CML |
1840 | break; |
1841 | case PORT_C: | |
89b667f8 | 1842 | port_mask = DPLL_PORTC_READY_MASK; |
00fc31b7 | 1843 | dpll_reg = DPLL(0); |
9b6de0a1 | 1844 | expected_mask <<= 4; |
00fc31b7 CML |
1845 | break; |
1846 | case PORT_D: | |
1847 | port_mask = DPLL_PORTD_READY_MASK; | |
1848 | dpll_reg = DPIO_PHY_STATUS; | |
e4607fcf CML |
1849 | break; |
1850 | default: | |
1851 | BUG(); | |
1852 | } | |
89b667f8 | 1853 | |
9b6de0a1 VS |
1854 | if (wait_for((I915_READ(dpll_reg) & port_mask) == expected_mask, 1000)) |
1855 | WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n", | |
1856 | port_name(dport->port), I915_READ(dpll_reg) & port_mask, expected_mask); | |
89b667f8 JB |
1857 | } |
1858 | ||
b14b1055 DV |
1859 | static void intel_prepare_shared_dpll(struct intel_crtc *crtc) |
1860 | { | |
1861 | struct drm_device *dev = crtc->base.dev; | |
1862 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1863 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); | |
1864 | ||
be19f0ff CW |
1865 | if (WARN_ON(pll == NULL)) |
1866 | return; | |
1867 | ||
3e369b76 | 1868 | WARN_ON(!pll->config.crtc_mask); |
b14b1055 DV |
1869 | if (pll->active == 0) { |
1870 | DRM_DEBUG_DRIVER("setting up %s\n", pll->name); | |
1871 | WARN_ON(pll->on); | |
1872 | assert_shared_dpll_disabled(dev_priv, pll); | |
1873 | ||
1874 | pll->mode_set(dev_priv, pll); | |
1875 | } | |
1876 | } | |
1877 | ||
92f2584a | 1878 | /** |
85b3894f | 1879 | * intel_enable_shared_dpll - enable PCH PLL |
92f2584a JB |
1880 | * @dev_priv: i915 private structure |
1881 | * @pipe: pipe PLL to enable | |
1882 | * | |
1883 | * The PCH PLL needs to be enabled before the PCH transcoder, since it | |
1884 | * drives the transcoder clock. | |
1885 | */ | |
85b3894f | 1886 | static void intel_enable_shared_dpll(struct intel_crtc *crtc) |
92f2584a | 1887 | { |
3d13ef2e DL |
1888 | struct drm_device *dev = crtc->base.dev; |
1889 | struct drm_i915_private *dev_priv = dev->dev_private; | |
e2b78267 | 1890 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
92f2584a | 1891 | |
87a875bb | 1892 | if (WARN_ON(pll == NULL)) |
48da64a8 CW |
1893 | return; |
1894 | ||
3e369b76 | 1895 | if (WARN_ON(pll->config.crtc_mask == 0)) |
48da64a8 | 1896 | return; |
ee7b9f93 | 1897 | |
74dd6928 | 1898 | DRM_DEBUG_KMS("enable %s (active %d, on? %d) for crtc %d\n", |
46edb027 | 1899 | pll->name, pll->active, pll->on, |
e2b78267 | 1900 | crtc->base.base.id); |
92f2584a | 1901 | |
cdbd2316 DV |
1902 | if (pll->active++) { |
1903 | WARN_ON(!pll->on); | |
e9d6944e | 1904 | assert_shared_dpll_enabled(dev_priv, pll); |
ee7b9f93 JB |
1905 | return; |
1906 | } | |
f4a091c7 | 1907 | WARN_ON(pll->on); |
ee7b9f93 | 1908 | |
bd2bb1b9 PZ |
1909 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
1910 | ||
46edb027 | 1911 | DRM_DEBUG_KMS("enabling %s\n", pll->name); |
e7b903d2 | 1912 | pll->enable(dev_priv, pll); |
ee7b9f93 | 1913 | pll->on = true; |
92f2584a JB |
1914 | } |
1915 | ||
f6daaec2 | 1916 | static void intel_disable_shared_dpll(struct intel_crtc *crtc) |
92f2584a | 1917 | { |
3d13ef2e DL |
1918 | struct drm_device *dev = crtc->base.dev; |
1919 | struct drm_i915_private *dev_priv = dev->dev_private; | |
e2b78267 | 1920 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
4c609cb8 | 1921 | |
92f2584a | 1922 | /* PCH only available on ILK+ */ |
80aa9312 JB |
1923 | if (INTEL_INFO(dev)->gen < 5) |
1924 | return; | |
1925 | ||
eddfcbcd ML |
1926 | if (pll == NULL) |
1927 | return; | |
92f2584a | 1928 | |
eddfcbcd | 1929 | if (WARN_ON(!(pll->config.crtc_mask & (1 << drm_crtc_index(&crtc->base))))) |
48da64a8 | 1930 | return; |
7a419866 | 1931 | |
46edb027 DV |
1932 | DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n", |
1933 | pll->name, pll->active, pll->on, | |
e2b78267 | 1934 | crtc->base.base.id); |
7a419866 | 1935 | |
48da64a8 | 1936 | if (WARN_ON(pll->active == 0)) { |
e9d6944e | 1937 | assert_shared_dpll_disabled(dev_priv, pll); |
48da64a8 CW |
1938 | return; |
1939 | } | |
1940 | ||
e9d6944e | 1941 | assert_shared_dpll_enabled(dev_priv, pll); |
f4a091c7 | 1942 | WARN_ON(!pll->on); |
cdbd2316 | 1943 | if (--pll->active) |
7a419866 | 1944 | return; |
ee7b9f93 | 1945 | |
46edb027 | 1946 | DRM_DEBUG_KMS("disabling %s\n", pll->name); |
e7b903d2 | 1947 | pll->disable(dev_priv, pll); |
ee7b9f93 | 1948 | pll->on = false; |
bd2bb1b9 PZ |
1949 | |
1950 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); | |
92f2584a JB |
1951 | } |
1952 | ||
b8a4f404 PZ |
1953 | static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
1954 | enum pipe pipe) | |
040484af | 1955 | { |
23670b32 | 1956 | struct drm_device *dev = dev_priv->dev; |
7c26e5c6 | 1957 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
e2b78267 | 1958 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
f0f59a00 VS |
1959 | i915_reg_t reg; |
1960 | uint32_t val, pipeconf_val; | |
040484af JB |
1961 | |
1962 | /* PCH only available on ILK+ */ | |
55522f37 | 1963 | BUG_ON(!HAS_PCH_SPLIT(dev)); |
040484af JB |
1964 | |
1965 | /* Make sure PCH DPLL is enabled */ | |
e72f9fbf | 1966 | assert_shared_dpll_enabled(dev_priv, |
e9d6944e | 1967 | intel_crtc_to_shared_dpll(intel_crtc)); |
040484af JB |
1968 | |
1969 | /* FDI must be feeding us bits for PCH ports */ | |
1970 | assert_fdi_tx_enabled(dev_priv, pipe); | |
1971 | assert_fdi_rx_enabled(dev_priv, pipe); | |
1972 | ||
23670b32 DV |
1973 | if (HAS_PCH_CPT(dev)) { |
1974 | /* Workaround: Set the timing override bit before enabling the | |
1975 | * pch transcoder. */ | |
1976 | reg = TRANS_CHICKEN2(pipe); | |
1977 | val = I915_READ(reg); | |
1978 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; | |
1979 | I915_WRITE(reg, val); | |
59c859d6 | 1980 | } |
23670b32 | 1981 | |
ab9412ba | 1982 | reg = PCH_TRANSCONF(pipe); |
040484af | 1983 | val = I915_READ(reg); |
5f7f726d | 1984 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
e9bcff5c JB |
1985 | |
1986 | if (HAS_PCH_IBX(dev_priv->dev)) { | |
1987 | /* | |
c5de7c6f VS |
1988 | * Make the BPC in transcoder be consistent with |
1989 | * that in pipeconf reg. For HDMI we must use 8bpc | |
1990 | * here for both 8bpc and 12bpc. | |
e9bcff5c | 1991 | */ |
dfd07d72 | 1992 | val &= ~PIPECONF_BPC_MASK; |
c5de7c6f VS |
1993 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_HDMI)) |
1994 | val |= PIPECONF_8BPC; | |
1995 | else | |
1996 | val |= pipeconf_val & PIPECONF_BPC_MASK; | |
e9bcff5c | 1997 | } |
5f7f726d PZ |
1998 | |
1999 | val &= ~TRANS_INTERLACE_MASK; | |
2000 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) | |
7c26e5c6 | 2001 | if (HAS_PCH_IBX(dev_priv->dev) && |
409ee761 | 2002 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
7c26e5c6 PZ |
2003 | val |= TRANS_LEGACY_INTERLACED_ILK; |
2004 | else | |
2005 | val |= TRANS_INTERLACED; | |
5f7f726d PZ |
2006 | else |
2007 | val |= TRANS_PROGRESSIVE; | |
2008 | ||
040484af JB |
2009 | I915_WRITE(reg, val | TRANS_ENABLE); |
2010 | if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100)) | |
4bb6f1f3 | 2011 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
040484af JB |
2012 | } |
2013 | ||
8fb033d7 | 2014 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
937bb610 | 2015 | enum transcoder cpu_transcoder) |
040484af | 2016 | { |
8fb033d7 | 2017 | u32 val, pipeconf_val; |
8fb033d7 PZ |
2018 | |
2019 | /* PCH only available on ILK+ */ | |
55522f37 | 2020 | BUG_ON(!HAS_PCH_SPLIT(dev_priv->dev)); |
8fb033d7 | 2021 | |
8fb033d7 | 2022 | /* FDI must be feeding us bits for PCH ports */ |
1a240d4d | 2023 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
937bb610 | 2024 | assert_fdi_rx_enabled(dev_priv, TRANSCODER_A); |
8fb033d7 | 2025 | |
223a6fdf | 2026 | /* Workaround: set timing override bit. */ |
36c0d0cf | 2027 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
23670b32 | 2028 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
36c0d0cf | 2029 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
223a6fdf | 2030 | |
25f3ef11 | 2031 | val = TRANS_ENABLE; |
937bb610 | 2032 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
8fb033d7 | 2033 | |
9a76b1c6 PZ |
2034 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
2035 | PIPECONF_INTERLACED_ILK) | |
a35f2679 | 2036 | val |= TRANS_INTERLACED; |
8fb033d7 PZ |
2037 | else |
2038 | val |= TRANS_PROGRESSIVE; | |
2039 | ||
ab9412ba DV |
2040 | I915_WRITE(LPT_TRANSCONF, val); |
2041 | if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100)) | |
937bb610 | 2042 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
8fb033d7 PZ |
2043 | } |
2044 | ||
b8a4f404 PZ |
2045 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
2046 | enum pipe pipe) | |
040484af | 2047 | { |
23670b32 | 2048 | struct drm_device *dev = dev_priv->dev; |
f0f59a00 VS |
2049 | i915_reg_t reg; |
2050 | uint32_t val; | |
040484af JB |
2051 | |
2052 | /* FDI relies on the transcoder */ | |
2053 | assert_fdi_tx_disabled(dev_priv, pipe); | |
2054 | assert_fdi_rx_disabled(dev_priv, pipe); | |
2055 | ||
291906f1 JB |
2056 | /* Ports must be off as well */ |
2057 | assert_pch_ports_disabled(dev_priv, pipe); | |
2058 | ||
ab9412ba | 2059 | reg = PCH_TRANSCONF(pipe); |
040484af JB |
2060 | val = I915_READ(reg); |
2061 | val &= ~TRANS_ENABLE; | |
2062 | I915_WRITE(reg, val); | |
2063 | /* wait for PCH transcoder off, transcoder state */ | |
2064 | if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50)) | |
4bb6f1f3 | 2065 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
23670b32 | 2066 | |
c465613b | 2067 | if (HAS_PCH_CPT(dev)) { |
23670b32 DV |
2068 | /* Workaround: Clear the timing override chicken bit again. */ |
2069 | reg = TRANS_CHICKEN2(pipe); | |
2070 | val = I915_READ(reg); | |
2071 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; | |
2072 | I915_WRITE(reg, val); | |
2073 | } | |
040484af JB |
2074 | } |
2075 | ||
ab4d966c | 2076 | static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
8fb033d7 | 2077 | { |
8fb033d7 PZ |
2078 | u32 val; |
2079 | ||
ab9412ba | 2080 | val = I915_READ(LPT_TRANSCONF); |
8fb033d7 | 2081 | val &= ~TRANS_ENABLE; |
ab9412ba | 2082 | I915_WRITE(LPT_TRANSCONF, val); |
8fb033d7 | 2083 | /* wait for PCH transcoder off, transcoder state */ |
ab9412ba | 2084 | if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50)) |
8a52fd9f | 2085 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
223a6fdf PZ |
2086 | |
2087 | /* Workaround: clear timing override bit. */ | |
36c0d0cf | 2088 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
23670b32 | 2089 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
36c0d0cf | 2090 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
040484af JB |
2091 | } |
2092 | ||
b24e7179 | 2093 | /** |
309cfea8 | 2094 | * intel_enable_pipe - enable a pipe, asserting requirements |
0372264a | 2095 | * @crtc: crtc responsible for the pipe |
b24e7179 | 2096 | * |
0372264a | 2097 | * Enable @crtc's pipe, making sure that various hardware specific requirements |
b24e7179 | 2098 | * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc. |
b24e7179 | 2099 | */ |
e1fdc473 | 2100 | static void intel_enable_pipe(struct intel_crtc *crtc) |
b24e7179 | 2101 | { |
0372264a PZ |
2102 | struct drm_device *dev = crtc->base.dev; |
2103 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2104 | enum pipe pipe = crtc->pipe; | |
1a70a728 | 2105 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
1a240d4d | 2106 | enum pipe pch_transcoder; |
f0f59a00 | 2107 | i915_reg_t reg; |
b24e7179 JB |
2108 | u32 val; |
2109 | ||
9e2ee2dd VS |
2110 | DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe)); |
2111 | ||
58c6eaa2 | 2112 | assert_planes_disabled(dev_priv, pipe); |
93ce0ba6 | 2113 | assert_cursor_disabled(dev_priv, pipe); |
58c6eaa2 DV |
2114 | assert_sprites_disabled(dev_priv, pipe); |
2115 | ||
681e5811 | 2116 | if (HAS_PCH_LPT(dev_priv->dev)) |
cc391bbb PZ |
2117 | pch_transcoder = TRANSCODER_A; |
2118 | else | |
2119 | pch_transcoder = pipe; | |
2120 | ||
b24e7179 JB |
2121 | /* |
2122 | * A pipe without a PLL won't actually be able to drive bits from | |
2123 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't | |
2124 | * need the check. | |
2125 | */ | |
50360403 | 2126 | if (HAS_GMCH_DISPLAY(dev_priv->dev)) |
a65347ba | 2127 | if (crtc->config->has_dsi_encoder) |
23538ef1 JN |
2128 | assert_dsi_pll_enabled(dev_priv); |
2129 | else | |
2130 | assert_pll_enabled(dev_priv, pipe); | |
040484af | 2131 | else { |
6e3c9717 | 2132 | if (crtc->config->has_pch_encoder) { |
040484af | 2133 | /* if driving the PCH, we need FDI enabled */ |
cc391bbb | 2134 | assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder); |
1a240d4d DV |
2135 | assert_fdi_tx_pll_enabled(dev_priv, |
2136 | (enum pipe) cpu_transcoder); | |
040484af JB |
2137 | } |
2138 | /* FIXME: assert CPU port conditions for SNB+ */ | |
2139 | } | |
b24e7179 | 2140 | |
702e7a56 | 2141 | reg = PIPECONF(cpu_transcoder); |
b24e7179 | 2142 | val = I915_READ(reg); |
7ad25d48 | 2143 | if (val & PIPECONF_ENABLE) { |
b6b5d049 VS |
2144 | WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
2145 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))); | |
00d70b15 | 2146 | return; |
7ad25d48 | 2147 | } |
00d70b15 CW |
2148 | |
2149 | I915_WRITE(reg, val | PIPECONF_ENABLE); | |
851855d8 | 2150 | POSTING_READ(reg); |
b7792d8b VS |
2151 | |
2152 | /* | |
2153 | * Until the pipe starts DSL will read as 0, which would cause | |
2154 | * an apparent vblank timestamp jump, which messes up also the | |
2155 | * frame count when it's derived from the timestamps. So let's | |
2156 | * wait for the pipe to start properly before we call | |
2157 | * drm_crtc_vblank_on() | |
2158 | */ | |
2159 | if (dev->max_vblank_count == 0 && | |
2160 | wait_for(intel_get_crtc_scanline(crtc) != crtc->scanline_offset, 50)) | |
2161 | DRM_ERROR("pipe %c didn't start\n", pipe_name(pipe)); | |
b24e7179 JB |
2162 | } |
2163 | ||
2164 | /** | |
309cfea8 | 2165 | * intel_disable_pipe - disable a pipe, asserting requirements |
575f7ab7 | 2166 | * @crtc: crtc whose pipes is to be disabled |
b24e7179 | 2167 | * |
575f7ab7 VS |
2168 | * Disable the pipe of @crtc, making sure that various hardware |
2169 | * specific requirements are met, if applicable, e.g. plane | |
2170 | * disabled, panel fitter off, etc. | |
b24e7179 JB |
2171 | * |
2172 | * Will wait until the pipe has shut down before returning. | |
2173 | */ | |
575f7ab7 | 2174 | static void intel_disable_pipe(struct intel_crtc *crtc) |
b24e7179 | 2175 | { |
575f7ab7 | 2176 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
6e3c9717 | 2177 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
575f7ab7 | 2178 | enum pipe pipe = crtc->pipe; |
f0f59a00 | 2179 | i915_reg_t reg; |
b24e7179 JB |
2180 | u32 val; |
2181 | ||
9e2ee2dd VS |
2182 | DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe)); |
2183 | ||
b24e7179 JB |
2184 | /* |
2185 | * Make sure planes won't keep trying to pump pixels to us, | |
2186 | * or we might hang the display. | |
2187 | */ | |
2188 | assert_planes_disabled(dev_priv, pipe); | |
93ce0ba6 | 2189 | assert_cursor_disabled(dev_priv, pipe); |
19332d7a | 2190 | assert_sprites_disabled(dev_priv, pipe); |
b24e7179 | 2191 | |
702e7a56 | 2192 | reg = PIPECONF(cpu_transcoder); |
b24e7179 | 2193 | val = I915_READ(reg); |
00d70b15 CW |
2194 | if ((val & PIPECONF_ENABLE) == 0) |
2195 | return; | |
2196 | ||
67adc644 VS |
2197 | /* |
2198 | * Double wide has implications for planes | |
2199 | * so best keep it disabled when not needed. | |
2200 | */ | |
6e3c9717 | 2201 | if (crtc->config->double_wide) |
67adc644 VS |
2202 | val &= ~PIPECONF_DOUBLE_WIDE; |
2203 | ||
2204 | /* Don't disable pipe or pipe PLLs if needed */ | |
b6b5d049 VS |
2205 | if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) && |
2206 | !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
67adc644 VS |
2207 | val &= ~PIPECONF_ENABLE; |
2208 | ||
2209 | I915_WRITE(reg, val); | |
2210 | if ((val & PIPECONF_ENABLE) == 0) | |
2211 | intel_wait_for_pipe_off(crtc); | |
b24e7179 JB |
2212 | } |
2213 | ||
693db184 CW |
2214 | static bool need_vtd_wa(struct drm_device *dev) |
2215 | { | |
2216 | #ifdef CONFIG_INTEL_IOMMU | |
2217 | if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped) | |
2218 | return true; | |
2219 | #endif | |
2220 | return false; | |
2221 | } | |
2222 | ||
832be82f VS |
2223 | static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv) |
2224 | { | |
2225 | return IS_GEN2(dev_priv) ? 2048 : 4096; | |
2226 | } | |
2227 | ||
27ba3910 VS |
2228 | static unsigned int intel_tile_width_bytes(const struct drm_i915_private *dev_priv, |
2229 | uint64_t fb_modifier, unsigned int cpp) | |
7b49f948 VS |
2230 | { |
2231 | switch (fb_modifier) { | |
2232 | case DRM_FORMAT_MOD_NONE: | |
2233 | return cpp; | |
2234 | case I915_FORMAT_MOD_X_TILED: | |
2235 | if (IS_GEN2(dev_priv)) | |
2236 | return 128; | |
2237 | else | |
2238 | return 512; | |
2239 | case I915_FORMAT_MOD_Y_TILED: | |
2240 | if (IS_GEN2(dev_priv) || HAS_128_BYTE_Y_TILING(dev_priv)) | |
2241 | return 128; | |
2242 | else | |
2243 | return 512; | |
2244 | case I915_FORMAT_MOD_Yf_TILED: | |
2245 | switch (cpp) { | |
2246 | case 1: | |
2247 | return 64; | |
2248 | case 2: | |
2249 | case 4: | |
2250 | return 128; | |
2251 | case 8: | |
2252 | case 16: | |
2253 | return 256; | |
2254 | default: | |
2255 | MISSING_CASE(cpp); | |
2256 | return cpp; | |
2257 | } | |
2258 | break; | |
2259 | default: | |
2260 | MISSING_CASE(fb_modifier); | |
2261 | return cpp; | |
2262 | } | |
2263 | } | |
2264 | ||
832be82f VS |
2265 | unsigned int intel_tile_height(const struct drm_i915_private *dev_priv, |
2266 | uint64_t fb_modifier, unsigned int cpp) | |
a57ce0b2 | 2267 | { |
832be82f VS |
2268 | if (fb_modifier == DRM_FORMAT_MOD_NONE) |
2269 | return 1; | |
2270 | else | |
2271 | return intel_tile_size(dev_priv) / | |
27ba3910 | 2272 | intel_tile_width_bytes(dev_priv, fb_modifier, cpp); |
6761dd31 TU |
2273 | } |
2274 | ||
8d0deca8 VS |
2275 | /* Return the tile dimensions in pixel units */ |
2276 | static void intel_tile_dims(const struct drm_i915_private *dev_priv, | |
2277 | unsigned int *tile_width, | |
2278 | unsigned int *tile_height, | |
2279 | uint64_t fb_modifier, | |
2280 | unsigned int cpp) | |
2281 | { | |
2282 | unsigned int tile_width_bytes = | |
2283 | intel_tile_width_bytes(dev_priv, fb_modifier, cpp); | |
2284 | ||
2285 | *tile_width = tile_width_bytes / cpp; | |
2286 | *tile_height = intel_tile_size(dev_priv) / tile_width_bytes; | |
2287 | } | |
2288 | ||
6761dd31 TU |
2289 | unsigned int |
2290 | intel_fb_align_height(struct drm_device *dev, unsigned int height, | |
832be82f | 2291 | uint32_t pixel_format, uint64_t fb_modifier) |
6761dd31 | 2292 | { |
832be82f VS |
2293 | unsigned int cpp = drm_format_plane_cpp(pixel_format, 0); |
2294 | unsigned int tile_height = intel_tile_height(to_i915(dev), fb_modifier, cpp); | |
2295 | ||
2296 | return ALIGN(height, tile_height); | |
a57ce0b2 JB |
2297 | } |
2298 | ||
1663b9d6 VS |
2299 | unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info) |
2300 | { | |
2301 | unsigned int size = 0; | |
2302 | int i; | |
2303 | ||
2304 | for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++) | |
2305 | size += rot_info->plane[i].width * rot_info->plane[i].height; | |
2306 | ||
2307 | return size; | |
2308 | } | |
2309 | ||
75c82a53 | 2310 | static void |
3465c580 VS |
2311 | intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, |
2312 | const struct drm_framebuffer *fb, | |
2313 | unsigned int rotation) | |
f64b98cd | 2314 | { |
832be82f | 2315 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
7723f47d | 2316 | struct intel_rotation_info *info = &view->params.rotated; |
8d0deca8 | 2317 | unsigned int tile_size, tile_width, tile_height, cpp; |
50470bb0 | 2318 | |
f64b98cd TU |
2319 | *view = i915_ggtt_view_normal; |
2320 | ||
3465c580 | 2321 | if (!intel_rotation_90_or_270(rotation)) |
75c82a53 | 2322 | return; |
50470bb0 | 2323 | |
9abc4648 | 2324 | *view = i915_ggtt_view_rotated; |
50470bb0 | 2325 | |
89e3e142 | 2326 | info->uv_offset = fb->offsets[1]; |
50470bb0 | 2327 | |
d9b3288e VS |
2328 | tile_size = intel_tile_size(dev_priv); |
2329 | ||
2330 | cpp = drm_format_plane_cpp(fb->pixel_format, 0); | |
8d0deca8 VS |
2331 | intel_tile_dims(dev_priv, &tile_width, &tile_height, |
2332 | fb->modifier[0], cpp); | |
d9b3288e | 2333 | |
1663b9d6 VS |
2334 | info->plane[0].width = DIV_ROUND_UP(fb->pitches[0], tile_width * cpp); |
2335 | info->plane[0].height = DIV_ROUND_UP(fb->height, tile_height); | |
84fe03f7 | 2336 | |
89e3e142 | 2337 | if (info->pixel_format == DRM_FORMAT_NV12) { |
832be82f | 2338 | cpp = drm_format_plane_cpp(fb->pixel_format, 1); |
8d0deca8 VS |
2339 | intel_tile_dims(dev_priv, &tile_width, &tile_height, |
2340 | fb->modifier[1], cpp); | |
d9b3288e | 2341 | |
1663b9d6 VS |
2342 | info->plane[1].width = DIV_ROUND_UP(fb->pitches[1], tile_width * cpp); |
2343 | info->plane[1].height = DIV_ROUND_UP(fb->height / 2, tile_height); | |
89e3e142 | 2344 | } |
f64b98cd TU |
2345 | } |
2346 | ||
603525d7 | 2347 | static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv) |
4e9a86b6 VS |
2348 | { |
2349 | if (INTEL_INFO(dev_priv)->gen >= 9) | |
2350 | return 256 * 1024; | |
985b8bb4 | 2351 | else if (IS_BROADWATER(dev_priv) || IS_CRESTLINE(dev_priv) || |
666a4537 | 2352 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
4e9a86b6 VS |
2353 | return 128 * 1024; |
2354 | else if (INTEL_INFO(dev_priv)->gen >= 4) | |
2355 | return 4 * 1024; | |
2356 | else | |
44c5905e | 2357 | return 0; |
4e9a86b6 VS |
2358 | } |
2359 | ||
603525d7 VS |
2360 | static unsigned int intel_surf_alignment(const struct drm_i915_private *dev_priv, |
2361 | uint64_t fb_modifier) | |
2362 | { | |
2363 | switch (fb_modifier) { | |
2364 | case DRM_FORMAT_MOD_NONE: | |
2365 | return intel_linear_alignment(dev_priv); | |
2366 | case I915_FORMAT_MOD_X_TILED: | |
2367 | if (INTEL_INFO(dev_priv)->gen >= 9) | |
2368 | return 256 * 1024; | |
2369 | return 0; | |
2370 | case I915_FORMAT_MOD_Y_TILED: | |
2371 | case I915_FORMAT_MOD_Yf_TILED: | |
2372 | return 1 * 1024 * 1024; | |
2373 | default: | |
2374 | MISSING_CASE(fb_modifier); | |
2375 | return 0; | |
2376 | } | |
2377 | } | |
2378 | ||
127bd2ac | 2379 | int |
3465c580 VS |
2380 | intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, |
2381 | unsigned int rotation) | |
6b95a207 | 2382 | { |
850c4cdc | 2383 | struct drm_device *dev = fb->dev; |
ce453d81 | 2384 | struct drm_i915_private *dev_priv = dev->dev_private; |
850c4cdc | 2385 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
f64b98cd | 2386 | struct i915_ggtt_view view; |
6b95a207 KH |
2387 | u32 alignment; |
2388 | int ret; | |
2389 | ||
ebcdd39e MR |
2390 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
2391 | ||
603525d7 | 2392 | alignment = intel_surf_alignment(dev_priv, fb->modifier[0]); |
6b95a207 | 2393 | |
3465c580 | 2394 | intel_fill_fb_ggtt_view(&view, fb, rotation); |
f64b98cd | 2395 | |
693db184 CW |
2396 | /* Note that the w/a also requires 64 PTE of padding following the |
2397 | * bo. We currently fill all unused PTE with the shadow page and so | |
2398 | * we should always have valid PTE following the scanout preventing | |
2399 | * the VT-d warning. | |
2400 | */ | |
2401 | if (need_vtd_wa(dev) && alignment < 256 * 1024) | |
2402 | alignment = 256 * 1024; | |
2403 | ||
d6dd6843 PZ |
2404 | /* |
2405 | * Global gtt pte registers are special registers which actually forward | |
2406 | * writes to a chunk of system memory. Which means that there is no risk | |
2407 | * that the register values disappear as soon as we call | |
2408 | * intel_runtime_pm_put(), so it is correct to wrap only the | |
2409 | * pin/unpin/fence and not more. | |
2410 | */ | |
2411 | intel_runtime_pm_get(dev_priv); | |
2412 | ||
7580d774 ML |
2413 | ret = i915_gem_object_pin_to_display_plane(obj, alignment, |
2414 | &view); | |
48b956c5 | 2415 | if (ret) |
b26a6b35 | 2416 | goto err_pm; |
6b95a207 KH |
2417 | |
2418 | /* Install a fence for tiled scan-out. Pre-i965 always needs a | |
2419 | * fence, whereas 965+ only requires a fence if using | |
2420 | * framebuffer compression. For simplicity, we always install | |
2421 | * a fence as the cost is not that onerous. | |
2422 | */ | |
9807216f VK |
2423 | if (view.type == I915_GGTT_VIEW_NORMAL) { |
2424 | ret = i915_gem_object_get_fence(obj); | |
2425 | if (ret == -EDEADLK) { | |
2426 | /* | |
2427 | * -EDEADLK means there are no free fences | |
2428 | * no pending flips. | |
2429 | * | |
2430 | * This is propagated to atomic, but it uses | |
2431 | * -EDEADLK to force a locking recovery, so | |
2432 | * change the returned error to -EBUSY. | |
2433 | */ | |
2434 | ret = -EBUSY; | |
2435 | goto err_unpin; | |
2436 | } else if (ret) | |
2437 | goto err_unpin; | |
1690e1eb | 2438 | |
9807216f VK |
2439 | i915_gem_object_pin_fence(obj); |
2440 | } | |
6b95a207 | 2441 | |
d6dd6843 | 2442 | intel_runtime_pm_put(dev_priv); |
6b95a207 | 2443 | return 0; |
48b956c5 CW |
2444 | |
2445 | err_unpin: | |
f64b98cd | 2446 | i915_gem_object_unpin_from_display_plane(obj, &view); |
b26a6b35 | 2447 | err_pm: |
d6dd6843 | 2448 | intel_runtime_pm_put(dev_priv); |
48b956c5 | 2449 | return ret; |
6b95a207 KH |
2450 | } |
2451 | ||
3465c580 | 2452 | static void intel_unpin_fb_obj(struct drm_framebuffer *fb, unsigned int rotation) |
1690e1eb | 2453 | { |
82bc3b2d | 2454 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
f64b98cd | 2455 | struct i915_ggtt_view view; |
82bc3b2d | 2456 | |
ebcdd39e MR |
2457 | WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex)); |
2458 | ||
3465c580 | 2459 | intel_fill_fb_ggtt_view(&view, fb, rotation); |
f64b98cd | 2460 | |
9807216f VK |
2461 | if (view.type == I915_GGTT_VIEW_NORMAL) |
2462 | i915_gem_object_unpin_fence(obj); | |
2463 | ||
f64b98cd | 2464 | i915_gem_object_unpin_from_display_plane(obj, &view); |
1690e1eb CW |
2465 | } |
2466 | ||
29cf9491 VS |
2467 | /* |
2468 | * Adjust the tile offset by moving the difference into | |
2469 | * the x/y offsets. | |
2470 | * | |
2471 | * Input tile dimensions and pitch must already be | |
2472 | * rotated to match x and y, and in pixel units. | |
2473 | */ | |
2474 | static u32 intel_adjust_tile_offset(int *x, int *y, | |
2475 | unsigned int tile_width, | |
2476 | unsigned int tile_height, | |
2477 | unsigned int tile_size, | |
2478 | unsigned int pitch_tiles, | |
2479 | u32 old_offset, | |
2480 | u32 new_offset) | |
2481 | { | |
2482 | unsigned int tiles; | |
2483 | ||
2484 | WARN_ON(old_offset & (tile_size - 1)); | |
2485 | WARN_ON(new_offset & (tile_size - 1)); | |
2486 | WARN_ON(new_offset > old_offset); | |
2487 | ||
2488 | tiles = (old_offset - new_offset) / tile_size; | |
2489 | ||
2490 | *y += tiles / pitch_tiles * tile_height; | |
2491 | *x += tiles % pitch_tiles * tile_width; | |
2492 | ||
2493 | return new_offset; | |
2494 | } | |
2495 | ||
8d0deca8 VS |
2496 | /* |
2497 | * Computes the linear offset to the base tile and adjusts | |
2498 | * x, y. bytes per pixel is assumed to be a power-of-two. | |
2499 | * | |
2500 | * In the 90/270 rotated case, x and y are assumed | |
2501 | * to be already rotated to match the rotated GTT view, and | |
2502 | * pitch is the tile_height aligned framebuffer height. | |
2503 | */ | |
4f2d9934 VS |
2504 | u32 intel_compute_tile_offset(int *x, int *y, |
2505 | const struct drm_framebuffer *fb, int plane, | |
8d0deca8 VS |
2506 | unsigned int pitch, |
2507 | unsigned int rotation) | |
c2c75131 | 2508 | { |
4f2d9934 VS |
2509 | const struct drm_i915_private *dev_priv = to_i915(fb->dev); |
2510 | uint64_t fb_modifier = fb->modifier[plane]; | |
2511 | unsigned int cpp = drm_format_plane_cpp(fb->pixel_format, plane); | |
29cf9491 VS |
2512 | u32 offset, offset_aligned, alignment; |
2513 | ||
2514 | alignment = intel_surf_alignment(dev_priv, fb_modifier); | |
2515 | if (alignment) | |
2516 | alignment--; | |
2517 | ||
b5c65338 | 2518 | if (fb_modifier != DRM_FORMAT_MOD_NONE) { |
8d0deca8 VS |
2519 | unsigned int tile_size, tile_width, tile_height; |
2520 | unsigned int tile_rows, tiles, pitch_tiles; | |
c2c75131 | 2521 | |
d843310d | 2522 | tile_size = intel_tile_size(dev_priv); |
8d0deca8 VS |
2523 | intel_tile_dims(dev_priv, &tile_width, &tile_height, |
2524 | fb_modifier, cpp); | |
2525 | ||
2526 | if (intel_rotation_90_or_270(rotation)) { | |
2527 | pitch_tiles = pitch / tile_height; | |
2528 | swap(tile_width, tile_height); | |
2529 | } else { | |
2530 | pitch_tiles = pitch / (tile_width * cpp); | |
2531 | } | |
d843310d VS |
2532 | |
2533 | tile_rows = *y / tile_height; | |
2534 | *y %= tile_height; | |
c2c75131 | 2535 | |
8d0deca8 VS |
2536 | tiles = *x / tile_width; |
2537 | *x %= tile_width; | |
bc752862 | 2538 | |
29cf9491 VS |
2539 | offset = (tile_rows * pitch_tiles + tiles) * tile_size; |
2540 | offset_aligned = offset & ~alignment; | |
bc752862 | 2541 | |
29cf9491 VS |
2542 | intel_adjust_tile_offset(x, y, tile_width, tile_height, |
2543 | tile_size, pitch_tiles, | |
2544 | offset, offset_aligned); | |
2545 | } else { | |
bc752862 | 2546 | offset = *y * pitch + *x * cpp; |
29cf9491 VS |
2547 | offset_aligned = offset & ~alignment; |
2548 | ||
4e9a86b6 VS |
2549 | *y = (offset & alignment) / pitch; |
2550 | *x = ((offset & alignment) - *y * pitch) / cpp; | |
bc752862 | 2551 | } |
29cf9491 VS |
2552 | |
2553 | return offset_aligned; | |
c2c75131 DV |
2554 | } |
2555 | ||
b35d63fa | 2556 | static int i9xx_format_to_fourcc(int format) |
46f297fb JB |
2557 | { |
2558 | switch (format) { | |
2559 | case DISPPLANE_8BPP: | |
2560 | return DRM_FORMAT_C8; | |
2561 | case DISPPLANE_BGRX555: | |
2562 | return DRM_FORMAT_XRGB1555; | |
2563 | case DISPPLANE_BGRX565: | |
2564 | return DRM_FORMAT_RGB565; | |
2565 | default: | |
2566 | case DISPPLANE_BGRX888: | |
2567 | return DRM_FORMAT_XRGB8888; | |
2568 | case DISPPLANE_RGBX888: | |
2569 | return DRM_FORMAT_XBGR8888; | |
2570 | case DISPPLANE_BGRX101010: | |
2571 | return DRM_FORMAT_XRGB2101010; | |
2572 | case DISPPLANE_RGBX101010: | |
2573 | return DRM_FORMAT_XBGR2101010; | |
2574 | } | |
2575 | } | |
2576 | ||
bc8d7dff DL |
2577 | static int skl_format_to_fourcc(int format, bool rgb_order, bool alpha) |
2578 | { | |
2579 | switch (format) { | |
2580 | case PLANE_CTL_FORMAT_RGB_565: | |
2581 | return DRM_FORMAT_RGB565; | |
2582 | default: | |
2583 | case PLANE_CTL_FORMAT_XRGB_8888: | |
2584 | if (rgb_order) { | |
2585 | if (alpha) | |
2586 | return DRM_FORMAT_ABGR8888; | |
2587 | else | |
2588 | return DRM_FORMAT_XBGR8888; | |
2589 | } else { | |
2590 | if (alpha) | |
2591 | return DRM_FORMAT_ARGB8888; | |
2592 | else | |
2593 | return DRM_FORMAT_XRGB8888; | |
2594 | } | |
2595 | case PLANE_CTL_FORMAT_XRGB_2101010: | |
2596 | if (rgb_order) | |
2597 | return DRM_FORMAT_XBGR2101010; | |
2598 | else | |
2599 | return DRM_FORMAT_XRGB2101010; | |
2600 | } | |
2601 | } | |
2602 | ||
5724dbd1 | 2603 | static bool |
f6936e29 DV |
2604 | intel_alloc_initial_plane_obj(struct intel_crtc *crtc, |
2605 | struct intel_initial_plane_config *plane_config) | |
46f297fb JB |
2606 | { |
2607 | struct drm_device *dev = crtc->base.dev; | |
3badb49f | 2608 | struct drm_i915_private *dev_priv = to_i915(dev); |
46f297fb JB |
2609 | struct drm_i915_gem_object *obj = NULL; |
2610 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; | |
2d14030b | 2611 | struct drm_framebuffer *fb = &plane_config->fb->base; |
f37b5c2b DV |
2612 | u32 base_aligned = round_down(plane_config->base, PAGE_SIZE); |
2613 | u32 size_aligned = round_up(plane_config->base + plane_config->size, | |
2614 | PAGE_SIZE); | |
2615 | ||
2616 | size_aligned -= base_aligned; | |
46f297fb | 2617 | |
ff2652ea CW |
2618 | if (plane_config->size == 0) |
2619 | return false; | |
2620 | ||
3badb49f PZ |
2621 | /* If the FB is too big, just don't use it since fbdev is not very |
2622 | * important and we should probably use that space with FBC or other | |
2623 | * features. */ | |
2624 | if (size_aligned * 2 > dev_priv->gtt.stolen_usable_size) | |
2625 | return false; | |
2626 | ||
12c83d99 TU |
2627 | mutex_lock(&dev->struct_mutex); |
2628 | ||
f37b5c2b DV |
2629 | obj = i915_gem_object_create_stolen_for_preallocated(dev, |
2630 | base_aligned, | |
2631 | base_aligned, | |
2632 | size_aligned); | |
12c83d99 TU |
2633 | if (!obj) { |
2634 | mutex_unlock(&dev->struct_mutex); | |
484b41dd | 2635 | return false; |
12c83d99 | 2636 | } |
46f297fb | 2637 | |
49af449b DL |
2638 | obj->tiling_mode = plane_config->tiling; |
2639 | if (obj->tiling_mode == I915_TILING_X) | |
6bf129df | 2640 | obj->stride = fb->pitches[0]; |
46f297fb | 2641 | |
6bf129df DL |
2642 | mode_cmd.pixel_format = fb->pixel_format; |
2643 | mode_cmd.width = fb->width; | |
2644 | mode_cmd.height = fb->height; | |
2645 | mode_cmd.pitches[0] = fb->pitches[0]; | |
18c5247e DV |
2646 | mode_cmd.modifier[0] = fb->modifier[0]; |
2647 | mode_cmd.flags = DRM_MODE_FB_MODIFIERS; | |
46f297fb | 2648 | |
6bf129df | 2649 | if (intel_framebuffer_init(dev, to_intel_framebuffer(fb), |
484b41dd | 2650 | &mode_cmd, obj)) { |
46f297fb JB |
2651 | DRM_DEBUG_KMS("intel fb init failed\n"); |
2652 | goto out_unref_obj; | |
2653 | } | |
12c83d99 | 2654 | |
46f297fb | 2655 | mutex_unlock(&dev->struct_mutex); |
484b41dd | 2656 | |
f6936e29 | 2657 | DRM_DEBUG_KMS("initial plane fb obj %p\n", obj); |
484b41dd | 2658 | return true; |
46f297fb JB |
2659 | |
2660 | out_unref_obj: | |
2661 | drm_gem_object_unreference(&obj->base); | |
2662 | mutex_unlock(&dev->struct_mutex); | |
484b41dd JB |
2663 | return false; |
2664 | } | |
2665 | ||
afd65eb4 MR |
2666 | /* Update plane->state->fb to match plane->fb after driver-internal updates */ |
2667 | static void | |
2668 | update_state_fb(struct drm_plane *plane) | |
2669 | { | |
2670 | if (plane->fb == plane->state->fb) | |
2671 | return; | |
2672 | ||
2673 | if (plane->state->fb) | |
2674 | drm_framebuffer_unreference(plane->state->fb); | |
2675 | plane->state->fb = plane->fb; | |
2676 | if (plane->state->fb) | |
2677 | drm_framebuffer_reference(plane->state->fb); | |
2678 | } | |
2679 | ||
5724dbd1 | 2680 | static void |
f6936e29 DV |
2681 | intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, |
2682 | struct intel_initial_plane_config *plane_config) | |
484b41dd JB |
2683 | { |
2684 | struct drm_device *dev = intel_crtc->base.dev; | |
d9ceb816 | 2685 | struct drm_i915_private *dev_priv = dev->dev_private; |
484b41dd JB |
2686 | struct drm_crtc *c; |
2687 | struct intel_crtc *i; | |
2ff8fde1 | 2688 | struct drm_i915_gem_object *obj; |
88595ac9 | 2689 | struct drm_plane *primary = intel_crtc->base.primary; |
be5651f2 | 2690 | struct drm_plane_state *plane_state = primary->state; |
200757f5 MR |
2691 | struct drm_crtc_state *crtc_state = intel_crtc->base.state; |
2692 | struct intel_plane *intel_plane = to_intel_plane(primary); | |
0a8d8a86 MR |
2693 | struct intel_plane_state *intel_state = |
2694 | to_intel_plane_state(plane_state); | |
88595ac9 | 2695 | struct drm_framebuffer *fb; |
484b41dd | 2696 | |
2d14030b | 2697 | if (!plane_config->fb) |
484b41dd JB |
2698 | return; |
2699 | ||
f6936e29 | 2700 | if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) { |
88595ac9 DV |
2701 | fb = &plane_config->fb->base; |
2702 | goto valid_fb; | |
f55548b5 | 2703 | } |
484b41dd | 2704 | |
2d14030b | 2705 | kfree(plane_config->fb); |
484b41dd JB |
2706 | |
2707 | /* | |
2708 | * Failed to alloc the obj, check to see if we should share | |
2709 | * an fb with another CRTC instead | |
2710 | */ | |
70e1e0ec | 2711 | for_each_crtc(dev, c) { |
484b41dd JB |
2712 | i = to_intel_crtc(c); |
2713 | ||
2714 | if (c == &intel_crtc->base) | |
2715 | continue; | |
2716 | ||
2ff8fde1 MR |
2717 | if (!i->active) |
2718 | continue; | |
2719 | ||
88595ac9 DV |
2720 | fb = c->primary->fb; |
2721 | if (!fb) | |
484b41dd JB |
2722 | continue; |
2723 | ||
88595ac9 | 2724 | obj = intel_fb_obj(fb); |
2ff8fde1 | 2725 | if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) { |
88595ac9 DV |
2726 | drm_framebuffer_reference(fb); |
2727 | goto valid_fb; | |
484b41dd JB |
2728 | } |
2729 | } | |
88595ac9 | 2730 | |
200757f5 MR |
2731 | /* |
2732 | * We've failed to reconstruct the BIOS FB. Current display state | |
2733 | * indicates that the primary plane is visible, but has a NULL FB, | |
2734 | * which will lead to problems later if we don't fix it up. The | |
2735 | * simplest solution is to just disable the primary plane now and | |
2736 | * pretend the BIOS never had it enabled. | |
2737 | */ | |
2738 | to_intel_plane_state(plane_state)->visible = false; | |
2739 | crtc_state->plane_mask &= ~(1 << drm_plane_index(primary)); | |
2740 | intel_pre_disable_primary(&intel_crtc->base); | |
2741 | intel_plane->disable_plane(primary, &intel_crtc->base); | |
2742 | ||
88595ac9 DV |
2743 | return; |
2744 | ||
2745 | valid_fb: | |
f44e2659 VS |
2746 | plane_state->src_x = 0; |
2747 | plane_state->src_y = 0; | |
be5651f2 ML |
2748 | plane_state->src_w = fb->width << 16; |
2749 | plane_state->src_h = fb->height << 16; | |
2750 | ||
f44e2659 VS |
2751 | plane_state->crtc_x = 0; |
2752 | plane_state->crtc_y = 0; | |
be5651f2 ML |
2753 | plane_state->crtc_w = fb->width; |
2754 | plane_state->crtc_h = fb->height; | |
2755 | ||
0a8d8a86 MR |
2756 | intel_state->src.x1 = plane_state->src_x; |
2757 | intel_state->src.y1 = plane_state->src_y; | |
2758 | intel_state->src.x2 = plane_state->src_x + plane_state->src_w; | |
2759 | intel_state->src.y2 = plane_state->src_y + plane_state->src_h; | |
2760 | intel_state->dst.x1 = plane_state->crtc_x; | |
2761 | intel_state->dst.y1 = plane_state->crtc_y; | |
2762 | intel_state->dst.x2 = plane_state->crtc_x + plane_state->crtc_w; | |
2763 | intel_state->dst.y2 = plane_state->crtc_y + plane_state->crtc_h; | |
2764 | ||
88595ac9 DV |
2765 | obj = intel_fb_obj(fb); |
2766 | if (obj->tiling_mode != I915_TILING_NONE) | |
2767 | dev_priv->preserve_bios_swizzle = true; | |
2768 | ||
be5651f2 ML |
2769 | drm_framebuffer_reference(fb); |
2770 | primary->fb = primary->state->fb = fb; | |
36750f28 | 2771 | primary->crtc = primary->state->crtc = &intel_crtc->base; |
36750f28 | 2772 | intel_crtc->base.state->plane_mask |= (1 << drm_plane_index(primary)); |
a9ff8714 | 2773 | obj->frontbuffer_bits |= to_intel_plane(primary)->frontbuffer_bit; |
46f297fb JB |
2774 | } |
2775 | ||
a8d201af ML |
2776 | static void i9xx_update_primary_plane(struct drm_plane *primary, |
2777 | const struct intel_crtc_state *crtc_state, | |
2778 | const struct intel_plane_state *plane_state) | |
81255565 | 2779 | { |
a8d201af | 2780 | struct drm_device *dev = primary->dev; |
81255565 | 2781 | struct drm_i915_private *dev_priv = dev->dev_private; |
a8d201af ML |
2782 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
2783 | struct drm_framebuffer *fb = plane_state->base.fb; | |
2784 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); | |
81255565 | 2785 | int plane = intel_crtc->plane; |
54ea9da8 | 2786 | u32 linear_offset; |
81255565 | 2787 | u32 dspcntr; |
f0f59a00 | 2788 | i915_reg_t reg = DSPCNTR(plane); |
8d0deca8 | 2789 | unsigned int rotation = plane_state->base.rotation; |
ac484963 | 2790 | int cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
54ea9da8 VS |
2791 | int x = plane_state->src.x1 >> 16; |
2792 | int y = plane_state->src.y1 >> 16; | |
c9ba6fad | 2793 | |
f45651ba VS |
2794 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
2795 | ||
fdd508a6 | 2796 | dspcntr |= DISPLAY_PLANE_ENABLE; |
f45651ba VS |
2797 | |
2798 | if (INTEL_INFO(dev)->gen < 4) { | |
2799 | if (intel_crtc->pipe == PIPE_B) | |
2800 | dspcntr |= DISPPLANE_SEL_PIPE_B; | |
2801 | ||
2802 | /* pipesrc and dspsize control the size that is scaled from, | |
2803 | * which should always be the user's requested size. | |
2804 | */ | |
2805 | I915_WRITE(DSPSIZE(plane), | |
a8d201af ML |
2806 | ((crtc_state->pipe_src_h - 1) << 16) | |
2807 | (crtc_state->pipe_src_w - 1)); | |
f45651ba | 2808 | I915_WRITE(DSPPOS(plane), 0); |
c14b0485 VS |
2809 | } else if (IS_CHERRYVIEW(dev) && plane == PLANE_B) { |
2810 | I915_WRITE(PRIMSIZE(plane), | |
a8d201af ML |
2811 | ((crtc_state->pipe_src_h - 1) << 16) | |
2812 | (crtc_state->pipe_src_w - 1)); | |
c14b0485 VS |
2813 | I915_WRITE(PRIMPOS(plane), 0); |
2814 | I915_WRITE(PRIMCNSTALPHA(plane), 0); | |
f45651ba | 2815 | } |
81255565 | 2816 | |
57779d06 VS |
2817 | switch (fb->pixel_format) { |
2818 | case DRM_FORMAT_C8: | |
81255565 JB |
2819 | dspcntr |= DISPPLANE_8BPP; |
2820 | break; | |
57779d06 | 2821 | case DRM_FORMAT_XRGB1555: |
57779d06 | 2822 | dspcntr |= DISPPLANE_BGRX555; |
81255565 | 2823 | break; |
57779d06 VS |
2824 | case DRM_FORMAT_RGB565: |
2825 | dspcntr |= DISPPLANE_BGRX565; | |
2826 | break; | |
2827 | case DRM_FORMAT_XRGB8888: | |
57779d06 VS |
2828 | dspcntr |= DISPPLANE_BGRX888; |
2829 | break; | |
2830 | case DRM_FORMAT_XBGR8888: | |
57779d06 VS |
2831 | dspcntr |= DISPPLANE_RGBX888; |
2832 | break; | |
2833 | case DRM_FORMAT_XRGB2101010: | |
57779d06 VS |
2834 | dspcntr |= DISPPLANE_BGRX101010; |
2835 | break; | |
2836 | case DRM_FORMAT_XBGR2101010: | |
57779d06 | 2837 | dspcntr |= DISPPLANE_RGBX101010; |
81255565 JB |
2838 | break; |
2839 | default: | |
baba133a | 2840 | BUG(); |
81255565 | 2841 | } |
57779d06 | 2842 | |
f45651ba VS |
2843 | if (INTEL_INFO(dev)->gen >= 4 && |
2844 | obj->tiling_mode != I915_TILING_NONE) | |
2845 | dspcntr |= DISPPLANE_TILED; | |
81255565 | 2846 | |
de1aa629 VS |
2847 | if (IS_G4X(dev)) |
2848 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; | |
2849 | ||
ac484963 | 2850 | linear_offset = y * fb->pitches[0] + x * cpp; |
81255565 | 2851 | |
c2c75131 DV |
2852 | if (INTEL_INFO(dev)->gen >= 4) { |
2853 | intel_crtc->dspaddr_offset = | |
4f2d9934 | 2854 | intel_compute_tile_offset(&x, &y, fb, 0, |
8d0deca8 | 2855 | fb->pitches[0], rotation); |
c2c75131 DV |
2856 | linear_offset -= intel_crtc->dspaddr_offset; |
2857 | } else { | |
e506a0c6 | 2858 | intel_crtc->dspaddr_offset = linear_offset; |
c2c75131 | 2859 | } |
e506a0c6 | 2860 | |
8d0deca8 | 2861 | if (rotation == BIT(DRM_ROTATE_180)) { |
48404c1e SJ |
2862 | dspcntr |= DISPPLANE_ROTATE_180; |
2863 | ||
a8d201af ML |
2864 | x += (crtc_state->pipe_src_w - 1); |
2865 | y += (crtc_state->pipe_src_h - 1); | |
48404c1e SJ |
2866 | |
2867 | /* Finding the last pixel of the last line of the display | |
2868 | data and adding to linear_offset*/ | |
2869 | linear_offset += | |
a8d201af | 2870 | (crtc_state->pipe_src_h - 1) * fb->pitches[0] + |
ac484963 | 2871 | (crtc_state->pipe_src_w - 1) * cpp; |
48404c1e SJ |
2872 | } |
2873 | ||
2db3366b PZ |
2874 | intel_crtc->adjusted_x = x; |
2875 | intel_crtc->adjusted_y = y; | |
2876 | ||
48404c1e SJ |
2877 | I915_WRITE(reg, dspcntr); |
2878 | ||
01f2c773 | 2879 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
a6c45cf0 | 2880 | if (INTEL_INFO(dev)->gen >= 4) { |
85ba7b7d DV |
2881 | I915_WRITE(DSPSURF(plane), |
2882 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); | |
5eddb70b | 2883 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
e506a0c6 | 2884 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
5eddb70b | 2885 | } else |
f343c5f6 | 2886 | I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset); |
5eddb70b | 2887 | POSTING_READ(reg); |
17638cd6 JB |
2888 | } |
2889 | ||
a8d201af ML |
2890 | static void i9xx_disable_primary_plane(struct drm_plane *primary, |
2891 | struct drm_crtc *crtc) | |
17638cd6 JB |
2892 | { |
2893 | struct drm_device *dev = crtc->dev; | |
2894 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2895 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
17638cd6 | 2896 | int plane = intel_crtc->plane; |
f45651ba | 2897 | |
a8d201af ML |
2898 | I915_WRITE(DSPCNTR(plane), 0); |
2899 | if (INTEL_INFO(dev_priv)->gen >= 4) | |
fdd508a6 | 2900 | I915_WRITE(DSPSURF(plane), 0); |
a8d201af ML |
2901 | else |
2902 | I915_WRITE(DSPADDR(plane), 0); | |
2903 | POSTING_READ(DSPCNTR(plane)); | |
2904 | } | |
c9ba6fad | 2905 | |
a8d201af ML |
2906 | static void ironlake_update_primary_plane(struct drm_plane *primary, |
2907 | const struct intel_crtc_state *crtc_state, | |
2908 | const struct intel_plane_state *plane_state) | |
2909 | { | |
2910 | struct drm_device *dev = primary->dev; | |
2911 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2912 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); | |
2913 | struct drm_framebuffer *fb = plane_state->base.fb; | |
2914 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); | |
2915 | int plane = intel_crtc->plane; | |
54ea9da8 | 2916 | u32 linear_offset; |
a8d201af ML |
2917 | u32 dspcntr; |
2918 | i915_reg_t reg = DSPCNTR(plane); | |
8d0deca8 | 2919 | unsigned int rotation = plane_state->base.rotation; |
ac484963 | 2920 | int cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
a8d201af ML |
2921 | int x = plane_state->src.x1 >> 16; |
2922 | int y = plane_state->src.y1 >> 16; | |
c9ba6fad | 2923 | |
f45651ba | 2924 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
fdd508a6 | 2925 | dspcntr |= DISPLAY_PLANE_ENABLE; |
f45651ba VS |
2926 | |
2927 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) | |
2928 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; | |
17638cd6 | 2929 | |
57779d06 VS |
2930 | switch (fb->pixel_format) { |
2931 | case DRM_FORMAT_C8: | |
17638cd6 JB |
2932 | dspcntr |= DISPPLANE_8BPP; |
2933 | break; | |
57779d06 VS |
2934 | case DRM_FORMAT_RGB565: |
2935 | dspcntr |= DISPPLANE_BGRX565; | |
17638cd6 | 2936 | break; |
57779d06 | 2937 | case DRM_FORMAT_XRGB8888: |
57779d06 VS |
2938 | dspcntr |= DISPPLANE_BGRX888; |
2939 | break; | |
2940 | case DRM_FORMAT_XBGR8888: | |
57779d06 VS |
2941 | dspcntr |= DISPPLANE_RGBX888; |
2942 | break; | |
2943 | case DRM_FORMAT_XRGB2101010: | |
57779d06 VS |
2944 | dspcntr |= DISPPLANE_BGRX101010; |
2945 | break; | |
2946 | case DRM_FORMAT_XBGR2101010: | |
57779d06 | 2947 | dspcntr |= DISPPLANE_RGBX101010; |
17638cd6 JB |
2948 | break; |
2949 | default: | |
baba133a | 2950 | BUG(); |
17638cd6 JB |
2951 | } |
2952 | ||
2953 | if (obj->tiling_mode != I915_TILING_NONE) | |
2954 | dspcntr |= DISPPLANE_TILED; | |
17638cd6 | 2955 | |
f45651ba | 2956 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) |
1f5d76db | 2957 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
17638cd6 | 2958 | |
ac484963 | 2959 | linear_offset = y * fb->pitches[0] + x * cpp; |
c2c75131 | 2960 | intel_crtc->dspaddr_offset = |
4f2d9934 | 2961 | intel_compute_tile_offset(&x, &y, fb, 0, |
8d0deca8 | 2962 | fb->pitches[0], rotation); |
c2c75131 | 2963 | linear_offset -= intel_crtc->dspaddr_offset; |
8d0deca8 | 2964 | if (rotation == BIT(DRM_ROTATE_180)) { |
48404c1e SJ |
2965 | dspcntr |= DISPPLANE_ROTATE_180; |
2966 | ||
2967 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) { | |
a8d201af ML |
2968 | x += (crtc_state->pipe_src_w - 1); |
2969 | y += (crtc_state->pipe_src_h - 1); | |
48404c1e SJ |
2970 | |
2971 | /* Finding the last pixel of the last line of the display | |
2972 | data and adding to linear_offset*/ | |
2973 | linear_offset += | |
a8d201af | 2974 | (crtc_state->pipe_src_h - 1) * fb->pitches[0] + |
ac484963 | 2975 | (crtc_state->pipe_src_w - 1) * cpp; |
48404c1e SJ |
2976 | } |
2977 | } | |
2978 | ||
2db3366b PZ |
2979 | intel_crtc->adjusted_x = x; |
2980 | intel_crtc->adjusted_y = y; | |
2981 | ||
48404c1e | 2982 | I915_WRITE(reg, dspcntr); |
17638cd6 | 2983 | |
01f2c773 | 2984 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
85ba7b7d DV |
2985 | I915_WRITE(DSPSURF(plane), |
2986 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); | |
b3dc685e | 2987 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
bc1c91eb DL |
2988 | I915_WRITE(DSPOFFSET(plane), (y << 16) | x); |
2989 | } else { | |
2990 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); | |
2991 | I915_WRITE(DSPLINOFF(plane), linear_offset); | |
2992 | } | |
17638cd6 | 2993 | POSTING_READ(reg); |
17638cd6 JB |
2994 | } |
2995 | ||
7b49f948 VS |
2996 | u32 intel_fb_stride_alignment(const struct drm_i915_private *dev_priv, |
2997 | uint64_t fb_modifier, uint32_t pixel_format) | |
b321803d | 2998 | { |
7b49f948 | 2999 | if (fb_modifier == DRM_FORMAT_MOD_NONE) { |
b321803d | 3000 | return 64; |
7b49f948 VS |
3001 | } else { |
3002 | int cpp = drm_format_plane_cpp(pixel_format, 0); | |
3003 | ||
27ba3910 | 3004 | return intel_tile_width_bytes(dev_priv, fb_modifier, cpp); |
b321803d DL |
3005 | } |
3006 | } | |
3007 | ||
44eb0cb9 MK |
3008 | u32 intel_plane_obj_offset(struct intel_plane *intel_plane, |
3009 | struct drm_i915_gem_object *obj, | |
3010 | unsigned int plane) | |
121920fa | 3011 | { |
ce7f1728 | 3012 | struct i915_ggtt_view view; |
dedf278c | 3013 | struct i915_vma *vma; |
44eb0cb9 | 3014 | u64 offset; |
121920fa | 3015 | |
e7941294 | 3016 | intel_fill_fb_ggtt_view(&view, intel_plane->base.state->fb, |
3465c580 | 3017 | intel_plane->base.state->rotation); |
121920fa | 3018 | |
ce7f1728 | 3019 | vma = i915_gem_obj_to_ggtt_view(obj, &view); |
dedf278c | 3020 | if (WARN(!vma, "ggtt vma for display object not found! (view=%u)\n", |
ce7f1728 | 3021 | view.type)) |
dedf278c TU |
3022 | return -1; |
3023 | ||
44eb0cb9 | 3024 | offset = vma->node.start; |
dedf278c TU |
3025 | |
3026 | if (plane == 1) { | |
7723f47d | 3027 | offset += vma->ggtt_view.params.rotated.uv_start_page * |
dedf278c TU |
3028 | PAGE_SIZE; |
3029 | } | |
3030 | ||
44eb0cb9 MK |
3031 | WARN_ON(upper_32_bits(offset)); |
3032 | ||
3033 | return lower_32_bits(offset); | |
121920fa TU |
3034 | } |
3035 | ||
e435d6e5 ML |
3036 | static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id) |
3037 | { | |
3038 | struct drm_device *dev = intel_crtc->base.dev; | |
3039 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3040 | ||
3041 | I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0); | |
3042 | I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0); | |
3043 | I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0); | |
e435d6e5 ML |
3044 | } |
3045 | ||
a1b2278e CK |
3046 | /* |
3047 | * This function detaches (aka. unbinds) unused scalers in hardware | |
3048 | */ | |
0583236e | 3049 | static void skl_detach_scalers(struct intel_crtc *intel_crtc) |
a1b2278e | 3050 | { |
a1b2278e CK |
3051 | struct intel_crtc_scaler_state *scaler_state; |
3052 | int i; | |
3053 | ||
a1b2278e CK |
3054 | scaler_state = &intel_crtc->config->scaler_state; |
3055 | ||
3056 | /* loop through and disable scalers that aren't in use */ | |
3057 | for (i = 0; i < intel_crtc->num_scalers; i++) { | |
e435d6e5 ML |
3058 | if (!scaler_state->scalers[i].in_use) |
3059 | skl_detach_scaler(intel_crtc, i); | |
a1b2278e CK |
3060 | } |
3061 | } | |
3062 | ||
6156a456 | 3063 | u32 skl_plane_ctl_format(uint32_t pixel_format) |
70d21f0e | 3064 | { |
6156a456 | 3065 | switch (pixel_format) { |
d161cf7a | 3066 | case DRM_FORMAT_C8: |
c34ce3d1 | 3067 | return PLANE_CTL_FORMAT_INDEXED; |
70d21f0e | 3068 | case DRM_FORMAT_RGB565: |
c34ce3d1 | 3069 | return PLANE_CTL_FORMAT_RGB_565; |
70d21f0e | 3070 | case DRM_FORMAT_XBGR8888: |
c34ce3d1 | 3071 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX; |
6156a456 | 3072 | case DRM_FORMAT_XRGB8888: |
c34ce3d1 | 3073 | return PLANE_CTL_FORMAT_XRGB_8888; |
6156a456 CK |
3074 | /* |
3075 | * XXX: For ARBG/ABGR formats we default to expecting scanout buffers | |
3076 | * to be already pre-multiplied. We need to add a knob (or a different | |
3077 | * DRM_FORMAT) for user-space to configure that. | |
3078 | */ | |
f75fb42a | 3079 | case DRM_FORMAT_ABGR8888: |
c34ce3d1 | 3080 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX | |
6156a456 | 3081 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
6156a456 | 3082 | case DRM_FORMAT_ARGB8888: |
c34ce3d1 | 3083 | return PLANE_CTL_FORMAT_XRGB_8888 | |
6156a456 | 3084 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
70d21f0e | 3085 | case DRM_FORMAT_XRGB2101010: |
c34ce3d1 | 3086 | return PLANE_CTL_FORMAT_XRGB_2101010; |
70d21f0e | 3087 | case DRM_FORMAT_XBGR2101010: |
c34ce3d1 | 3088 | return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010; |
6156a456 | 3089 | case DRM_FORMAT_YUYV: |
c34ce3d1 | 3090 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV; |
6156a456 | 3091 | case DRM_FORMAT_YVYU: |
c34ce3d1 | 3092 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU; |
6156a456 | 3093 | case DRM_FORMAT_UYVY: |
c34ce3d1 | 3094 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY; |
6156a456 | 3095 | case DRM_FORMAT_VYUY: |
c34ce3d1 | 3096 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY; |
70d21f0e | 3097 | default: |
4249eeef | 3098 | MISSING_CASE(pixel_format); |
70d21f0e | 3099 | } |
8cfcba41 | 3100 | |
c34ce3d1 | 3101 | return 0; |
6156a456 | 3102 | } |
70d21f0e | 3103 | |
6156a456 CK |
3104 | u32 skl_plane_ctl_tiling(uint64_t fb_modifier) |
3105 | { | |
6156a456 | 3106 | switch (fb_modifier) { |
30af77c4 | 3107 | case DRM_FORMAT_MOD_NONE: |
70d21f0e | 3108 | break; |
30af77c4 | 3109 | case I915_FORMAT_MOD_X_TILED: |
c34ce3d1 | 3110 | return PLANE_CTL_TILED_X; |
b321803d | 3111 | case I915_FORMAT_MOD_Y_TILED: |
c34ce3d1 | 3112 | return PLANE_CTL_TILED_Y; |
b321803d | 3113 | case I915_FORMAT_MOD_Yf_TILED: |
c34ce3d1 | 3114 | return PLANE_CTL_TILED_YF; |
70d21f0e | 3115 | default: |
6156a456 | 3116 | MISSING_CASE(fb_modifier); |
70d21f0e | 3117 | } |
8cfcba41 | 3118 | |
c34ce3d1 | 3119 | return 0; |
6156a456 | 3120 | } |
70d21f0e | 3121 | |
6156a456 CK |
3122 | u32 skl_plane_ctl_rotation(unsigned int rotation) |
3123 | { | |
3b7a5119 | 3124 | switch (rotation) { |
6156a456 CK |
3125 | case BIT(DRM_ROTATE_0): |
3126 | break; | |
1e8df167 SJ |
3127 | /* |
3128 | * DRM_ROTATE_ is counter clockwise to stay compatible with Xrandr | |
3129 | * while i915 HW rotation is clockwise, thats why this swapping. | |
3130 | */ | |
3b7a5119 | 3131 | case BIT(DRM_ROTATE_90): |
1e8df167 | 3132 | return PLANE_CTL_ROTATE_270; |
3b7a5119 | 3133 | case BIT(DRM_ROTATE_180): |
c34ce3d1 | 3134 | return PLANE_CTL_ROTATE_180; |
3b7a5119 | 3135 | case BIT(DRM_ROTATE_270): |
1e8df167 | 3136 | return PLANE_CTL_ROTATE_90; |
6156a456 CK |
3137 | default: |
3138 | MISSING_CASE(rotation); | |
3139 | } | |
3140 | ||
c34ce3d1 | 3141 | return 0; |
6156a456 CK |
3142 | } |
3143 | ||
a8d201af ML |
3144 | static void skylake_update_primary_plane(struct drm_plane *plane, |
3145 | const struct intel_crtc_state *crtc_state, | |
3146 | const struct intel_plane_state *plane_state) | |
6156a456 | 3147 | { |
a8d201af | 3148 | struct drm_device *dev = plane->dev; |
6156a456 | 3149 | struct drm_i915_private *dev_priv = dev->dev_private; |
a8d201af ML |
3150 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
3151 | struct drm_framebuffer *fb = plane_state->base.fb; | |
3152 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); | |
6156a456 CK |
3153 | int pipe = intel_crtc->pipe; |
3154 | u32 plane_ctl, stride_div, stride; | |
3155 | u32 tile_height, plane_offset, plane_size; | |
a8d201af | 3156 | unsigned int rotation = plane_state->base.rotation; |
6156a456 | 3157 | int x_offset, y_offset; |
44eb0cb9 | 3158 | u32 surf_addr; |
a8d201af ML |
3159 | int scaler_id = plane_state->scaler_id; |
3160 | int src_x = plane_state->src.x1 >> 16; | |
3161 | int src_y = plane_state->src.y1 >> 16; | |
3162 | int src_w = drm_rect_width(&plane_state->src) >> 16; | |
3163 | int src_h = drm_rect_height(&plane_state->src) >> 16; | |
3164 | int dst_x = plane_state->dst.x1; | |
3165 | int dst_y = plane_state->dst.y1; | |
3166 | int dst_w = drm_rect_width(&plane_state->dst); | |
3167 | int dst_h = drm_rect_height(&plane_state->dst); | |
70d21f0e | 3168 | |
6156a456 CK |
3169 | plane_ctl = PLANE_CTL_ENABLE | |
3170 | PLANE_CTL_PIPE_GAMMA_ENABLE | | |
3171 | PLANE_CTL_PIPE_CSC_ENABLE; | |
3172 | ||
3173 | plane_ctl |= skl_plane_ctl_format(fb->pixel_format); | |
3174 | plane_ctl |= skl_plane_ctl_tiling(fb->modifier[0]); | |
3175 | plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE; | |
6156a456 CK |
3176 | plane_ctl |= skl_plane_ctl_rotation(rotation); |
3177 | ||
7b49f948 | 3178 | stride_div = intel_fb_stride_alignment(dev_priv, fb->modifier[0], |
b321803d | 3179 | fb->pixel_format); |
dedf278c | 3180 | surf_addr = intel_plane_obj_offset(to_intel_plane(plane), obj, 0); |
3b7a5119 | 3181 | |
a42e5a23 PZ |
3182 | WARN_ON(drm_rect_width(&plane_state->src) == 0); |
3183 | ||
3b7a5119 | 3184 | if (intel_rotation_90_or_270(rotation)) { |
832be82f VS |
3185 | int cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
3186 | ||
3b7a5119 | 3187 | /* stride = Surface height in tiles */ |
832be82f | 3188 | tile_height = intel_tile_height(dev_priv, fb->modifier[0], cpp); |
3b7a5119 | 3189 | stride = DIV_ROUND_UP(fb->height, tile_height); |
a8d201af ML |
3190 | x_offset = stride * tile_height - src_y - src_h; |
3191 | y_offset = src_x; | |
6156a456 | 3192 | plane_size = (src_w - 1) << 16 | (src_h - 1); |
3b7a5119 SJ |
3193 | } else { |
3194 | stride = fb->pitches[0] / stride_div; | |
a8d201af ML |
3195 | x_offset = src_x; |
3196 | y_offset = src_y; | |
6156a456 | 3197 | plane_size = (src_h - 1) << 16 | (src_w - 1); |
3b7a5119 SJ |
3198 | } |
3199 | plane_offset = y_offset << 16 | x_offset; | |
b321803d | 3200 | |
2db3366b PZ |
3201 | intel_crtc->adjusted_x = x_offset; |
3202 | intel_crtc->adjusted_y = y_offset; | |
3203 | ||
70d21f0e | 3204 | I915_WRITE(PLANE_CTL(pipe, 0), plane_ctl); |
3b7a5119 SJ |
3205 | I915_WRITE(PLANE_OFFSET(pipe, 0), plane_offset); |
3206 | I915_WRITE(PLANE_SIZE(pipe, 0), plane_size); | |
3207 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); | |
6156a456 CK |
3208 | |
3209 | if (scaler_id >= 0) { | |
3210 | uint32_t ps_ctrl = 0; | |
3211 | ||
3212 | WARN_ON(!dst_w || !dst_h); | |
3213 | ps_ctrl = PS_SCALER_EN | PS_PLANE_SEL(0) | | |
3214 | crtc_state->scaler_state.scalers[scaler_id].mode; | |
3215 | I915_WRITE(SKL_PS_CTRL(pipe, scaler_id), ps_ctrl); | |
3216 | I915_WRITE(SKL_PS_PWR_GATE(pipe, scaler_id), 0); | |
3217 | I915_WRITE(SKL_PS_WIN_POS(pipe, scaler_id), (dst_x << 16) | dst_y); | |
3218 | I915_WRITE(SKL_PS_WIN_SZ(pipe, scaler_id), (dst_w << 16) | dst_h); | |
3219 | I915_WRITE(PLANE_POS(pipe, 0), 0); | |
3220 | } else { | |
3221 | I915_WRITE(PLANE_POS(pipe, 0), (dst_y << 16) | dst_x); | |
3222 | } | |
3223 | ||
121920fa | 3224 | I915_WRITE(PLANE_SURF(pipe, 0), surf_addr); |
70d21f0e DL |
3225 | |
3226 | POSTING_READ(PLANE_SURF(pipe, 0)); | |
3227 | } | |
3228 | ||
a8d201af ML |
3229 | static void skylake_disable_primary_plane(struct drm_plane *primary, |
3230 | struct drm_crtc *crtc) | |
17638cd6 JB |
3231 | { |
3232 | struct drm_device *dev = crtc->dev; | |
3233 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a8d201af | 3234 | int pipe = to_intel_crtc(crtc)->pipe; |
17638cd6 | 3235 | |
a8d201af ML |
3236 | I915_WRITE(PLANE_CTL(pipe, 0), 0); |
3237 | I915_WRITE(PLANE_SURF(pipe, 0), 0); | |
3238 | POSTING_READ(PLANE_SURF(pipe, 0)); | |
3239 | } | |
29b9bde6 | 3240 | |
a8d201af ML |
3241 | /* Assume fb object is pinned & idle & fenced and just update base pointers */ |
3242 | static int | |
3243 | intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, | |
3244 | int x, int y, enum mode_set_atomic state) | |
3245 | { | |
3246 | /* Support for kgdboc is disabled, this needs a major rework. */ | |
3247 | DRM_ERROR("legacy panic handler not supported any more.\n"); | |
3248 | ||
3249 | return -ENODEV; | |
81255565 JB |
3250 | } |
3251 | ||
7514747d | 3252 | static void intel_complete_page_flips(struct drm_device *dev) |
96a02917 | 3253 | { |
96a02917 VS |
3254 | struct drm_crtc *crtc; |
3255 | ||
70e1e0ec | 3256 | for_each_crtc(dev, crtc) { |
96a02917 VS |
3257 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
3258 | enum plane plane = intel_crtc->plane; | |
3259 | ||
3260 | intel_prepare_page_flip(dev, plane); | |
3261 | intel_finish_page_flip_plane(dev, plane); | |
3262 | } | |
7514747d VS |
3263 | } |
3264 | ||
3265 | static void intel_update_primary_planes(struct drm_device *dev) | |
3266 | { | |
7514747d | 3267 | struct drm_crtc *crtc; |
96a02917 | 3268 | |
70e1e0ec | 3269 | for_each_crtc(dev, crtc) { |
11c22da6 ML |
3270 | struct intel_plane *plane = to_intel_plane(crtc->primary); |
3271 | struct intel_plane_state *plane_state; | |
96a02917 | 3272 | |
11c22da6 | 3273 | drm_modeset_lock_crtc(crtc, &plane->base); |
11c22da6 ML |
3274 | plane_state = to_intel_plane_state(plane->base.state); |
3275 | ||
a8d201af ML |
3276 | if (plane_state->visible) |
3277 | plane->update_plane(&plane->base, | |
3278 | to_intel_crtc_state(crtc->state), | |
3279 | plane_state); | |
11c22da6 ML |
3280 | |
3281 | drm_modeset_unlock_crtc(crtc); | |
96a02917 VS |
3282 | } |
3283 | } | |
3284 | ||
7514747d VS |
3285 | void intel_prepare_reset(struct drm_device *dev) |
3286 | { | |
3287 | /* no reset support for gen2 */ | |
3288 | if (IS_GEN2(dev)) | |
3289 | return; | |
3290 | ||
3291 | /* reset doesn't touch the display */ | |
3292 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) | |
3293 | return; | |
3294 | ||
3295 | drm_modeset_lock_all(dev); | |
f98ce92f VS |
3296 | /* |
3297 | * Disabling the crtcs gracefully seems nicer. Also the | |
3298 | * g33 docs say we should at least disable all the planes. | |
3299 | */ | |
6b72d486 | 3300 | intel_display_suspend(dev); |
7514747d VS |
3301 | } |
3302 | ||
3303 | void intel_finish_reset(struct drm_device *dev) | |
3304 | { | |
3305 | struct drm_i915_private *dev_priv = to_i915(dev); | |
3306 | ||
3307 | /* | |
3308 | * Flips in the rings will be nuked by the reset, | |
3309 | * so complete all pending flips so that user space | |
3310 | * will get its events and not get stuck. | |
3311 | */ | |
3312 | intel_complete_page_flips(dev); | |
3313 | ||
3314 | /* no reset support for gen2 */ | |
3315 | if (IS_GEN2(dev)) | |
3316 | return; | |
3317 | ||
3318 | /* reset doesn't touch the display */ | |
3319 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) { | |
3320 | /* | |
3321 | * Flips in the rings have been nuked by the reset, | |
3322 | * so update the base address of all primary | |
3323 | * planes to the the last fb to make sure we're | |
3324 | * showing the correct fb after a reset. | |
11c22da6 ML |
3325 | * |
3326 | * FIXME: Atomic will make this obsolete since we won't schedule | |
3327 | * CS-based flips (which might get lost in gpu resets) any more. | |
7514747d VS |
3328 | */ |
3329 | intel_update_primary_planes(dev); | |
3330 | return; | |
3331 | } | |
3332 | ||
3333 | /* | |
3334 | * The display has been reset as well, | |
3335 | * so need a full re-initialization. | |
3336 | */ | |
3337 | intel_runtime_pm_disable_interrupts(dev_priv); | |
3338 | intel_runtime_pm_enable_interrupts(dev_priv); | |
3339 | ||
3340 | intel_modeset_init_hw(dev); | |
3341 | ||
3342 | spin_lock_irq(&dev_priv->irq_lock); | |
3343 | if (dev_priv->display.hpd_irq_setup) | |
3344 | dev_priv->display.hpd_irq_setup(dev); | |
3345 | spin_unlock_irq(&dev_priv->irq_lock); | |
3346 | ||
043e9bda | 3347 | intel_display_resume(dev); |
7514747d VS |
3348 | |
3349 | intel_hpd_init(dev_priv); | |
3350 | ||
3351 | drm_modeset_unlock_all(dev); | |
3352 | } | |
3353 | ||
7d5e3799 CW |
3354 | static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) |
3355 | { | |
3356 | struct drm_device *dev = crtc->dev; | |
3357 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3358 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
7d5e3799 CW |
3359 | bool pending; |
3360 | ||
3361 | if (i915_reset_in_progress(&dev_priv->gpu_error) || | |
3362 | intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) | |
3363 | return false; | |
3364 | ||
5e2d7afc | 3365 | spin_lock_irq(&dev->event_lock); |
7d5e3799 | 3366 | pending = to_intel_crtc(crtc)->unpin_work != NULL; |
5e2d7afc | 3367 | spin_unlock_irq(&dev->event_lock); |
7d5e3799 CW |
3368 | |
3369 | return pending; | |
3370 | } | |
3371 | ||
bfd16b2a ML |
3372 | static void intel_update_pipe_config(struct intel_crtc *crtc, |
3373 | struct intel_crtc_state *old_crtc_state) | |
e30e8f75 GP |
3374 | { |
3375 | struct drm_device *dev = crtc->base.dev; | |
3376 | struct drm_i915_private *dev_priv = dev->dev_private; | |
bfd16b2a ML |
3377 | struct intel_crtc_state *pipe_config = |
3378 | to_intel_crtc_state(crtc->base.state); | |
e30e8f75 | 3379 | |
bfd16b2a ML |
3380 | /* drm_atomic_helper_update_legacy_modeset_state might not be called. */ |
3381 | crtc->base.mode = crtc->base.state->mode; | |
3382 | ||
3383 | DRM_DEBUG_KMS("Updating pipe size %ix%i -> %ix%i\n", | |
3384 | old_crtc_state->pipe_src_w, old_crtc_state->pipe_src_h, | |
3385 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); | |
e30e8f75 | 3386 | |
44522d85 ML |
3387 | if (HAS_DDI(dev)) |
3388 | intel_set_pipe_csc(&crtc->base); | |
3389 | ||
e30e8f75 GP |
3390 | /* |
3391 | * Update pipe size and adjust fitter if needed: the reason for this is | |
3392 | * that in compute_mode_changes we check the native mode (not the pfit | |
3393 | * mode) to see if we can flip rather than do a full mode set. In the | |
3394 | * fastboot case, we'll flip, but if we don't update the pipesrc and | |
3395 | * pfit state, we'll end up with a big fb scanned out into the wrong | |
3396 | * sized surface. | |
e30e8f75 GP |
3397 | */ |
3398 | ||
e30e8f75 | 3399 | I915_WRITE(PIPESRC(crtc->pipe), |
bfd16b2a ML |
3400 | ((pipe_config->pipe_src_w - 1) << 16) | |
3401 | (pipe_config->pipe_src_h - 1)); | |
3402 | ||
3403 | /* on skylake this is done by detaching scalers */ | |
3404 | if (INTEL_INFO(dev)->gen >= 9) { | |
3405 | skl_detach_scalers(crtc); | |
3406 | ||
3407 | if (pipe_config->pch_pfit.enabled) | |
3408 | skylake_pfit_enable(crtc); | |
3409 | } else if (HAS_PCH_SPLIT(dev)) { | |
3410 | if (pipe_config->pch_pfit.enabled) | |
3411 | ironlake_pfit_enable(crtc); | |
3412 | else if (old_crtc_state->pch_pfit.enabled) | |
3413 | ironlake_pfit_disable(crtc, true); | |
e30e8f75 | 3414 | } |
e30e8f75 GP |
3415 | } |
3416 | ||
5e84e1a4 ZW |
3417 | static void intel_fdi_normal_train(struct drm_crtc *crtc) |
3418 | { | |
3419 | struct drm_device *dev = crtc->dev; | |
3420 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3421 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3422 | int pipe = intel_crtc->pipe; | |
f0f59a00 VS |
3423 | i915_reg_t reg; |
3424 | u32 temp; | |
5e84e1a4 ZW |
3425 | |
3426 | /* enable normal train */ | |
3427 | reg = FDI_TX_CTL(pipe); | |
3428 | temp = I915_READ(reg); | |
61e499bf | 3429 | if (IS_IVYBRIDGE(dev)) { |
357555c0 JB |
3430 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
3431 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; | |
61e499bf KP |
3432 | } else { |
3433 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3434 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; | |
357555c0 | 3435 | } |
5e84e1a4 ZW |
3436 | I915_WRITE(reg, temp); |
3437 | ||
3438 | reg = FDI_RX_CTL(pipe); | |
3439 | temp = I915_READ(reg); | |
3440 | if (HAS_PCH_CPT(dev)) { | |
3441 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3442 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; | |
3443 | } else { | |
3444 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3445 | temp |= FDI_LINK_TRAIN_NONE; | |
3446 | } | |
3447 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); | |
3448 | ||
3449 | /* wait one idle pattern time */ | |
3450 | POSTING_READ(reg); | |
3451 | udelay(1000); | |
357555c0 JB |
3452 | |
3453 | /* IVB wants error correction enabled */ | |
3454 | if (IS_IVYBRIDGE(dev)) | |
3455 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | | |
3456 | FDI_FE_ERRC_ENABLE); | |
5e84e1a4 ZW |
3457 | } |
3458 | ||
8db9d77b ZW |
3459 | /* The FDI link training functions for ILK/Ibexpeak. */ |
3460 | static void ironlake_fdi_link_train(struct drm_crtc *crtc) | |
3461 | { | |
3462 | struct drm_device *dev = crtc->dev; | |
3463 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3464 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3465 | int pipe = intel_crtc->pipe; | |
f0f59a00 VS |
3466 | i915_reg_t reg; |
3467 | u32 temp, tries; | |
8db9d77b | 3468 | |
1c8562f6 | 3469 | /* FDI needs bits from pipe first */ |
0fc932b8 | 3470 | assert_pipe_enabled(dev_priv, pipe); |
0fc932b8 | 3471 | |
e1a44743 AJ |
3472 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
3473 | for train result */ | |
5eddb70b CW |
3474 | reg = FDI_RX_IMR(pipe); |
3475 | temp = I915_READ(reg); | |
e1a44743 AJ |
3476 | temp &= ~FDI_RX_SYMBOL_LOCK; |
3477 | temp &= ~FDI_RX_BIT_LOCK; | |
5eddb70b CW |
3478 | I915_WRITE(reg, temp); |
3479 | I915_READ(reg); | |
e1a44743 AJ |
3480 | udelay(150); |
3481 | ||
8db9d77b | 3482 | /* enable CPU FDI TX and PCH FDI RX */ |
5eddb70b CW |
3483 | reg = FDI_TX_CTL(pipe); |
3484 | temp = I915_READ(reg); | |
627eb5a3 | 3485 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
6e3c9717 | 3486 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
8db9d77b ZW |
3487 | temp &= ~FDI_LINK_TRAIN_NONE; |
3488 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
5eddb70b | 3489 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
8db9d77b | 3490 | |
5eddb70b CW |
3491 | reg = FDI_RX_CTL(pipe); |
3492 | temp = I915_READ(reg); | |
8db9d77b ZW |
3493 | temp &= ~FDI_LINK_TRAIN_NONE; |
3494 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
5eddb70b CW |
3495 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
3496 | ||
3497 | POSTING_READ(reg); | |
8db9d77b ZW |
3498 | udelay(150); |
3499 | ||
5b2adf89 | 3500 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
8f5718a6 DV |
3501 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
3502 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | | |
3503 | FDI_RX_PHASE_SYNC_POINTER_EN); | |
5b2adf89 | 3504 | |
5eddb70b | 3505 | reg = FDI_RX_IIR(pipe); |
e1a44743 | 3506 | for (tries = 0; tries < 5; tries++) { |
5eddb70b | 3507 | temp = I915_READ(reg); |
8db9d77b ZW |
3508 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
3509 | ||
3510 | if ((temp & FDI_RX_BIT_LOCK)) { | |
3511 | DRM_DEBUG_KMS("FDI train 1 done.\n"); | |
5eddb70b | 3512 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
8db9d77b ZW |
3513 | break; |
3514 | } | |
8db9d77b | 3515 | } |
e1a44743 | 3516 | if (tries == 5) |
5eddb70b | 3517 | DRM_ERROR("FDI train 1 fail!\n"); |
8db9d77b ZW |
3518 | |
3519 | /* Train 2 */ | |
5eddb70b CW |
3520 | reg = FDI_TX_CTL(pipe); |
3521 | temp = I915_READ(reg); | |
8db9d77b ZW |
3522 | temp &= ~FDI_LINK_TRAIN_NONE; |
3523 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
5eddb70b | 3524 | I915_WRITE(reg, temp); |
8db9d77b | 3525 | |
5eddb70b CW |
3526 | reg = FDI_RX_CTL(pipe); |
3527 | temp = I915_READ(reg); | |
8db9d77b ZW |
3528 | temp &= ~FDI_LINK_TRAIN_NONE; |
3529 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
5eddb70b | 3530 | I915_WRITE(reg, temp); |
8db9d77b | 3531 | |
5eddb70b CW |
3532 | POSTING_READ(reg); |
3533 | udelay(150); | |
8db9d77b | 3534 | |
5eddb70b | 3535 | reg = FDI_RX_IIR(pipe); |
e1a44743 | 3536 | for (tries = 0; tries < 5; tries++) { |
5eddb70b | 3537 | temp = I915_READ(reg); |
8db9d77b ZW |
3538 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
3539 | ||
3540 | if (temp & FDI_RX_SYMBOL_LOCK) { | |
5eddb70b | 3541 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
8db9d77b ZW |
3542 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
3543 | break; | |
3544 | } | |
8db9d77b | 3545 | } |
e1a44743 | 3546 | if (tries == 5) |
5eddb70b | 3547 | DRM_ERROR("FDI train 2 fail!\n"); |
8db9d77b ZW |
3548 | |
3549 | DRM_DEBUG_KMS("FDI train done\n"); | |
5c5313c8 | 3550 | |
8db9d77b ZW |
3551 | } |
3552 | ||
0206e353 | 3553 | static const int snb_b_fdi_train_param[] = { |
8db9d77b ZW |
3554 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
3555 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, | |
3556 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, | |
3557 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, | |
3558 | }; | |
3559 | ||
3560 | /* The FDI link training functions for SNB/Cougarpoint. */ | |
3561 | static void gen6_fdi_link_train(struct drm_crtc *crtc) | |
3562 | { | |
3563 | struct drm_device *dev = crtc->dev; | |
3564 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3565 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3566 | int pipe = intel_crtc->pipe; | |
f0f59a00 VS |
3567 | i915_reg_t reg; |
3568 | u32 temp, i, retry; | |
8db9d77b | 3569 | |
e1a44743 AJ |
3570 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
3571 | for train result */ | |
5eddb70b CW |
3572 | reg = FDI_RX_IMR(pipe); |
3573 | temp = I915_READ(reg); | |
e1a44743 AJ |
3574 | temp &= ~FDI_RX_SYMBOL_LOCK; |
3575 | temp &= ~FDI_RX_BIT_LOCK; | |
5eddb70b CW |
3576 | I915_WRITE(reg, temp); |
3577 | ||
3578 | POSTING_READ(reg); | |
e1a44743 AJ |
3579 | udelay(150); |
3580 | ||
8db9d77b | 3581 | /* enable CPU FDI TX and PCH FDI RX */ |
5eddb70b CW |
3582 | reg = FDI_TX_CTL(pipe); |
3583 | temp = I915_READ(reg); | |
627eb5a3 | 3584 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
6e3c9717 | 3585 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
8db9d77b ZW |
3586 | temp &= ~FDI_LINK_TRAIN_NONE; |
3587 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3588 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; | |
3589 | /* SNB-B */ | |
3590 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; | |
5eddb70b | 3591 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
8db9d77b | 3592 | |
d74cf324 DV |
3593 | I915_WRITE(FDI_RX_MISC(pipe), |
3594 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); | |
3595 | ||
5eddb70b CW |
3596 | reg = FDI_RX_CTL(pipe); |
3597 | temp = I915_READ(reg); | |
8db9d77b ZW |
3598 | if (HAS_PCH_CPT(dev)) { |
3599 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3600 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; | |
3601 | } else { | |
3602 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3603 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3604 | } | |
5eddb70b CW |
3605 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
3606 | ||
3607 | POSTING_READ(reg); | |
8db9d77b ZW |
3608 | udelay(150); |
3609 | ||
0206e353 | 3610 | for (i = 0; i < 4; i++) { |
5eddb70b CW |
3611 | reg = FDI_TX_CTL(pipe); |
3612 | temp = I915_READ(reg); | |
8db9d77b ZW |
3613 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
3614 | temp |= snb_b_fdi_train_param[i]; | |
5eddb70b CW |
3615 | I915_WRITE(reg, temp); |
3616 | ||
3617 | POSTING_READ(reg); | |
8db9d77b ZW |
3618 | udelay(500); |
3619 | ||
fa37d39e SP |
3620 | for (retry = 0; retry < 5; retry++) { |
3621 | reg = FDI_RX_IIR(pipe); | |
3622 | temp = I915_READ(reg); | |
3623 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
3624 | if (temp & FDI_RX_BIT_LOCK) { | |
3625 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); | |
3626 | DRM_DEBUG_KMS("FDI train 1 done.\n"); | |
3627 | break; | |
3628 | } | |
3629 | udelay(50); | |
8db9d77b | 3630 | } |
fa37d39e SP |
3631 | if (retry < 5) |
3632 | break; | |
8db9d77b ZW |
3633 | } |
3634 | if (i == 4) | |
5eddb70b | 3635 | DRM_ERROR("FDI train 1 fail!\n"); |
8db9d77b ZW |
3636 | |
3637 | /* Train 2 */ | |
5eddb70b CW |
3638 | reg = FDI_TX_CTL(pipe); |
3639 | temp = I915_READ(reg); | |
8db9d77b ZW |
3640 | temp &= ~FDI_LINK_TRAIN_NONE; |
3641 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
3642 | if (IS_GEN6(dev)) { | |
3643 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; | |
3644 | /* SNB-B */ | |
3645 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; | |
3646 | } | |
5eddb70b | 3647 | I915_WRITE(reg, temp); |
8db9d77b | 3648 | |
5eddb70b CW |
3649 | reg = FDI_RX_CTL(pipe); |
3650 | temp = I915_READ(reg); | |
8db9d77b ZW |
3651 | if (HAS_PCH_CPT(dev)) { |
3652 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3653 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; | |
3654 | } else { | |
3655 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3656 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
3657 | } | |
5eddb70b CW |
3658 | I915_WRITE(reg, temp); |
3659 | ||
3660 | POSTING_READ(reg); | |
8db9d77b ZW |
3661 | udelay(150); |
3662 | ||
0206e353 | 3663 | for (i = 0; i < 4; i++) { |
5eddb70b CW |
3664 | reg = FDI_TX_CTL(pipe); |
3665 | temp = I915_READ(reg); | |
8db9d77b ZW |
3666 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
3667 | temp |= snb_b_fdi_train_param[i]; | |
5eddb70b CW |
3668 | I915_WRITE(reg, temp); |
3669 | ||
3670 | POSTING_READ(reg); | |
8db9d77b ZW |
3671 | udelay(500); |
3672 | ||
fa37d39e SP |
3673 | for (retry = 0; retry < 5; retry++) { |
3674 | reg = FDI_RX_IIR(pipe); | |
3675 | temp = I915_READ(reg); | |
3676 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
3677 | if (temp & FDI_RX_SYMBOL_LOCK) { | |
3678 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); | |
3679 | DRM_DEBUG_KMS("FDI train 2 done.\n"); | |
3680 | break; | |
3681 | } | |
3682 | udelay(50); | |
8db9d77b | 3683 | } |
fa37d39e SP |
3684 | if (retry < 5) |
3685 | break; | |
8db9d77b ZW |
3686 | } |
3687 | if (i == 4) | |
5eddb70b | 3688 | DRM_ERROR("FDI train 2 fail!\n"); |
8db9d77b ZW |
3689 | |
3690 | DRM_DEBUG_KMS("FDI train done.\n"); | |
3691 | } | |
3692 | ||
357555c0 JB |
3693 | /* Manual link training for Ivy Bridge A0 parts */ |
3694 | static void ivb_manual_fdi_link_train(struct drm_crtc *crtc) | |
3695 | { | |
3696 | struct drm_device *dev = crtc->dev; | |
3697 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3698 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3699 | int pipe = intel_crtc->pipe; | |
f0f59a00 VS |
3700 | i915_reg_t reg; |
3701 | u32 temp, i, j; | |
357555c0 JB |
3702 | |
3703 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit | |
3704 | for train result */ | |
3705 | reg = FDI_RX_IMR(pipe); | |
3706 | temp = I915_READ(reg); | |
3707 | temp &= ~FDI_RX_SYMBOL_LOCK; | |
3708 | temp &= ~FDI_RX_BIT_LOCK; | |
3709 | I915_WRITE(reg, temp); | |
3710 | ||
3711 | POSTING_READ(reg); | |
3712 | udelay(150); | |
3713 | ||
01a415fd DV |
3714 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
3715 | I915_READ(FDI_RX_IIR(pipe))); | |
3716 | ||
139ccd3f JB |
3717 | /* Try each vswing and preemphasis setting twice before moving on */ |
3718 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { | |
3719 | /* disable first in case we need to retry */ | |
3720 | reg = FDI_TX_CTL(pipe); | |
3721 | temp = I915_READ(reg); | |
3722 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); | |
3723 | temp &= ~FDI_TX_ENABLE; | |
3724 | I915_WRITE(reg, temp); | |
357555c0 | 3725 | |
139ccd3f JB |
3726 | reg = FDI_RX_CTL(pipe); |
3727 | temp = I915_READ(reg); | |
3728 | temp &= ~FDI_LINK_TRAIN_AUTO; | |
3729 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3730 | temp &= ~FDI_RX_ENABLE; | |
3731 | I915_WRITE(reg, temp); | |
357555c0 | 3732 | |
139ccd3f | 3733 | /* enable CPU FDI TX and PCH FDI RX */ |
357555c0 JB |
3734 | reg = FDI_TX_CTL(pipe); |
3735 | temp = I915_READ(reg); | |
139ccd3f | 3736 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
6e3c9717 | 3737 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
139ccd3f | 3738 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
357555c0 | 3739 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
139ccd3f JB |
3740 | temp |= snb_b_fdi_train_param[j/2]; |
3741 | temp |= FDI_COMPOSITE_SYNC; | |
3742 | I915_WRITE(reg, temp | FDI_TX_ENABLE); | |
357555c0 | 3743 | |
139ccd3f JB |
3744 | I915_WRITE(FDI_RX_MISC(pipe), |
3745 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); | |
357555c0 | 3746 | |
139ccd3f | 3747 | reg = FDI_RX_CTL(pipe); |
357555c0 | 3748 | temp = I915_READ(reg); |
139ccd3f JB |
3749 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
3750 | temp |= FDI_COMPOSITE_SYNC; | |
3751 | I915_WRITE(reg, temp | FDI_RX_ENABLE); | |
357555c0 | 3752 | |
139ccd3f JB |
3753 | POSTING_READ(reg); |
3754 | udelay(1); /* should be 0.5us */ | |
357555c0 | 3755 | |
139ccd3f JB |
3756 | for (i = 0; i < 4; i++) { |
3757 | reg = FDI_RX_IIR(pipe); | |
3758 | temp = I915_READ(reg); | |
3759 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
357555c0 | 3760 | |
139ccd3f JB |
3761 | if (temp & FDI_RX_BIT_LOCK || |
3762 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { | |
3763 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); | |
3764 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", | |
3765 | i); | |
3766 | break; | |
3767 | } | |
3768 | udelay(1); /* should be 0.5us */ | |
3769 | } | |
3770 | if (i == 4) { | |
3771 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); | |
3772 | continue; | |
3773 | } | |
357555c0 | 3774 | |
139ccd3f | 3775 | /* Train 2 */ |
357555c0 JB |
3776 | reg = FDI_TX_CTL(pipe); |
3777 | temp = I915_READ(reg); | |
139ccd3f JB |
3778 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
3779 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; | |
3780 | I915_WRITE(reg, temp); | |
3781 | ||
3782 | reg = FDI_RX_CTL(pipe); | |
3783 | temp = I915_READ(reg); | |
3784 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3785 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; | |
357555c0 JB |
3786 | I915_WRITE(reg, temp); |
3787 | ||
3788 | POSTING_READ(reg); | |
139ccd3f | 3789 | udelay(2); /* should be 1.5us */ |
357555c0 | 3790 | |
139ccd3f JB |
3791 | for (i = 0; i < 4; i++) { |
3792 | reg = FDI_RX_IIR(pipe); | |
3793 | temp = I915_READ(reg); | |
3794 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
357555c0 | 3795 | |
139ccd3f JB |
3796 | if (temp & FDI_RX_SYMBOL_LOCK || |
3797 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { | |
3798 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); | |
3799 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", | |
3800 | i); | |
3801 | goto train_done; | |
3802 | } | |
3803 | udelay(2); /* should be 1.5us */ | |
357555c0 | 3804 | } |
139ccd3f JB |
3805 | if (i == 4) |
3806 | DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2); | |
357555c0 | 3807 | } |
357555c0 | 3808 | |
139ccd3f | 3809 | train_done: |
357555c0 JB |
3810 | DRM_DEBUG_KMS("FDI train done.\n"); |
3811 | } | |
3812 | ||
88cefb6c | 3813 | static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc) |
2c07245f | 3814 | { |
88cefb6c | 3815 | struct drm_device *dev = intel_crtc->base.dev; |
2c07245f | 3816 | struct drm_i915_private *dev_priv = dev->dev_private; |
2c07245f | 3817 | int pipe = intel_crtc->pipe; |
f0f59a00 VS |
3818 | i915_reg_t reg; |
3819 | u32 temp; | |
c64e311e | 3820 | |
c98e9dcf | 3821 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
5eddb70b CW |
3822 | reg = FDI_RX_CTL(pipe); |
3823 | temp = I915_READ(reg); | |
627eb5a3 | 3824 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
6e3c9717 | 3825 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
dfd07d72 | 3826 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
5eddb70b CW |
3827 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
3828 | ||
3829 | POSTING_READ(reg); | |
c98e9dcf JB |
3830 | udelay(200); |
3831 | ||
3832 | /* Switch from Rawclk to PCDclk */ | |
5eddb70b CW |
3833 | temp = I915_READ(reg); |
3834 | I915_WRITE(reg, temp | FDI_PCDCLK); | |
3835 | ||
3836 | POSTING_READ(reg); | |
c98e9dcf JB |
3837 | udelay(200); |
3838 | ||
20749730 PZ |
3839 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
3840 | reg = FDI_TX_CTL(pipe); | |
3841 | temp = I915_READ(reg); | |
3842 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { | |
3843 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); | |
5eddb70b | 3844 | |
20749730 PZ |
3845 | POSTING_READ(reg); |
3846 | udelay(100); | |
6be4a607 | 3847 | } |
0e23b99d JB |
3848 | } |
3849 | ||
88cefb6c DV |
3850 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
3851 | { | |
3852 | struct drm_device *dev = intel_crtc->base.dev; | |
3853 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3854 | int pipe = intel_crtc->pipe; | |
f0f59a00 VS |
3855 | i915_reg_t reg; |
3856 | u32 temp; | |
88cefb6c DV |
3857 | |
3858 | /* Switch from PCDclk to Rawclk */ | |
3859 | reg = FDI_RX_CTL(pipe); | |
3860 | temp = I915_READ(reg); | |
3861 | I915_WRITE(reg, temp & ~FDI_PCDCLK); | |
3862 | ||
3863 | /* Disable CPU FDI TX PLL */ | |
3864 | reg = FDI_TX_CTL(pipe); | |
3865 | temp = I915_READ(reg); | |
3866 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); | |
3867 | ||
3868 | POSTING_READ(reg); | |
3869 | udelay(100); | |
3870 | ||
3871 | reg = FDI_RX_CTL(pipe); | |
3872 | temp = I915_READ(reg); | |
3873 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); | |
3874 | ||
3875 | /* Wait for the clocks to turn off. */ | |
3876 | POSTING_READ(reg); | |
3877 | udelay(100); | |
3878 | } | |
3879 | ||
0fc932b8 JB |
3880 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
3881 | { | |
3882 | struct drm_device *dev = crtc->dev; | |
3883 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3884 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3885 | int pipe = intel_crtc->pipe; | |
f0f59a00 VS |
3886 | i915_reg_t reg; |
3887 | u32 temp; | |
0fc932b8 JB |
3888 | |
3889 | /* disable CPU FDI tx and PCH FDI rx */ | |
3890 | reg = FDI_TX_CTL(pipe); | |
3891 | temp = I915_READ(reg); | |
3892 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); | |
3893 | POSTING_READ(reg); | |
3894 | ||
3895 | reg = FDI_RX_CTL(pipe); | |
3896 | temp = I915_READ(reg); | |
3897 | temp &= ~(0x7 << 16); | |
dfd07d72 | 3898 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
0fc932b8 JB |
3899 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
3900 | ||
3901 | POSTING_READ(reg); | |
3902 | udelay(100); | |
3903 | ||
3904 | /* Ironlake workaround, disable clock pointer after downing FDI */ | |
eba905b2 | 3905 | if (HAS_PCH_IBX(dev)) |
6f06ce18 | 3906 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
0fc932b8 JB |
3907 | |
3908 | /* still set train pattern 1 */ | |
3909 | reg = FDI_TX_CTL(pipe); | |
3910 | temp = I915_READ(reg); | |
3911 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3912 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3913 | I915_WRITE(reg, temp); | |
3914 | ||
3915 | reg = FDI_RX_CTL(pipe); | |
3916 | temp = I915_READ(reg); | |
3917 | if (HAS_PCH_CPT(dev)) { | |
3918 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3919 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; | |
3920 | } else { | |
3921 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3922 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3923 | } | |
3924 | /* BPC in FDI rx is consistent with that in PIPECONF */ | |
3925 | temp &= ~(0x07 << 16); | |
dfd07d72 | 3926 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
0fc932b8 JB |
3927 | I915_WRITE(reg, temp); |
3928 | ||
3929 | POSTING_READ(reg); | |
3930 | udelay(100); | |
3931 | } | |
3932 | ||
5dce5b93 CW |
3933 | bool intel_has_pending_fb_unpin(struct drm_device *dev) |
3934 | { | |
3935 | struct intel_crtc *crtc; | |
3936 | ||
3937 | /* Note that we don't need to be called with mode_config.lock here | |
3938 | * as our list of CRTC objects is static for the lifetime of the | |
3939 | * device and so cannot disappear as we iterate. Similarly, we can | |
3940 | * happily treat the predicates as racy, atomic checks as userspace | |
3941 | * cannot claim and pin a new fb without at least acquring the | |
3942 | * struct_mutex and so serialising with us. | |
3943 | */ | |
d3fcc808 | 3944 | for_each_intel_crtc(dev, crtc) { |
5dce5b93 CW |
3945 | if (atomic_read(&crtc->unpin_work_count) == 0) |
3946 | continue; | |
3947 | ||
3948 | if (crtc->unpin_work) | |
3949 | intel_wait_for_vblank(dev, crtc->pipe); | |
3950 | ||
3951 | return true; | |
3952 | } | |
3953 | ||
3954 | return false; | |
3955 | } | |
3956 | ||
d6bbafa1 CW |
3957 | static void page_flip_completed(struct intel_crtc *intel_crtc) |
3958 | { | |
3959 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); | |
3960 | struct intel_unpin_work *work = intel_crtc->unpin_work; | |
3961 | ||
3962 | /* ensure that the unpin work is consistent wrt ->pending. */ | |
3963 | smp_rmb(); | |
3964 | intel_crtc->unpin_work = NULL; | |
3965 | ||
3966 | if (work->event) | |
3967 | drm_send_vblank_event(intel_crtc->base.dev, | |
3968 | intel_crtc->pipe, | |
3969 | work->event); | |
3970 | ||
3971 | drm_crtc_vblank_put(&intel_crtc->base); | |
3972 | ||
3973 | wake_up_all(&dev_priv->pending_flip_queue); | |
3974 | queue_work(dev_priv->wq, &work->work); | |
3975 | ||
3976 | trace_i915_flip_complete(intel_crtc->plane, | |
3977 | work->pending_flip_obj); | |
3978 | } | |
3979 | ||
5008e874 | 3980 | static int intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc) |
e6c3a2a6 | 3981 | { |
0f91128d | 3982 | struct drm_device *dev = crtc->dev; |
5bb61643 | 3983 | struct drm_i915_private *dev_priv = dev->dev_private; |
5008e874 | 3984 | long ret; |
e6c3a2a6 | 3985 | |
2c10d571 | 3986 | WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue)); |
5008e874 ML |
3987 | |
3988 | ret = wait_event_interruptible_timeout( | |
3989 | dev_priv->pending_flip_queue, | |
3990 | !intel_crtc_has_pending_flip(crtc), | |
3991 | 60*HZ); | |
3992 | ||
3993 | if (ret < 0) | |
3994 | return ret; | |
3995 | ||
3996 | if (ret == 0) { | |
9c787942 | 3997 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
2c10d571 | 3998 | |
5e2d7afc | 3999 | spin_lock_irq(&dev->event_lock); |
9c787942 CW |
4000 | if (intel_crtc->unpin_work) { |
4001 | WARN_ONCE(1, "Removing stuck page flip\n"); | |
4002 | page_flip_completed(intel_crtc); | |
4003 | } | |
5e2d7afc | 4004 | spin_unlock_irq(&dev->event_lock); |
9c787942 | 4005 | } |
5bb61643 | 4006 | |
5008e874 | 4007 | return 0; |
e6c3a2a6 CW |
4008 | } |
4009 | ||
060f02d8 VS |
4010 | static void lpt_disable_iclkip(struct drm_i915_private *dev_priv) |
4011 | { | |
4012 | u32 temp; | |
4013 | ||
4014 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); | |
4015 | ||
4016 | mutex_lock(&dev_priv->sb_lock); | |
4017 | ||
4018 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); | |
4019 | temp |= SBI_SSCCTL_DISABLE; | |
4020 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); | |
4021 | ||
4022 | mutex_unlock(&dev_priv->sb_lock); | |
4023 | } | |
4024 | ||
e615efe4 ED |
4025 | /* Program iCLKIP clock to the desired frequency */ |
4026 | static void lpt_program_iclkip(struct drm_crtc *crtc) | |
4027 | { | |
4028 | struct drm_device *dev = crtc->dev; | |
4029 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6e3c9717 | 4030 | int clock = to_intel_crtc(crtc)->config->base.adjusted_mode.crtc_clock; |
e615efe4 ED |
4031 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
4032 | u32 temp; | |
4033 | ||
060f02d8 | 4034 | lpt_disable_iclkip(dev_priv); |
e615efe4 ED |
4035 | |
4036 | /* 20MHz is a corner case which is out of range for the 7-bit divisor */ | |
12d7ceed | 4037 | if (clock == 20000) { |
e615efe4 ED |
4038 | auxdiv = 1; |
4039 | divsel = 0x41; | |
4040 | phaseinc = 0x20; | |
4041 | } else { | |
4042 | /* The iCLK virtual clock root frequency is in MHz, | |
241bfc38 DL |
4043 | * but the adjusted_mode->crtc_clock in in KHz. To get the |
4044 | * divisors, it is necessary to divide one by another, so we | |
e615efe4 ED |
4045 | * convert the virtual clock precision to KHz here for higher |
4046 | * precision. | |
4047 | */ | |
4048 | u32 iclk_virtual_root_freq = 172800 * 1000; | |
4049 | u32 iclk_pi_range = 64; | |
4050 | u32 desired_divisor, msb_divisor_value, pi_value; | |
4051 | ||
a2572f5c | 4052 | desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq, clock); |
e615efe4 ED |
4053 | msb_divisor_value = desired_divisor / iclk_pi_range; |
4054 | pi_value = desired_divisor % iclk_pi_range; | |
4055 | ||
4056 | auxdiv = 0; | |
4057 | divsel = msb_divisor_value - 2; | |
4058 | phaseinc = pi_value; | |
4059 | } | |
4060 | ||
4061 | /* This should not happen with any sane values */ | |
4062 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & | |
4063 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); | |
4064 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & | |
4065 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); | |
4066 | ||
4067 | DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n", | |
12d7ceed | 4068 | clock, |
e615efe4 ED |
4069 | auxdiv, |
4070 | divsel, | |
4071 | phasedir, | |
4072 | phaseinc); | |
4073 | ||
060f02d8 VS |
4074 | mutex_lock(&dev_priv->sb_lock); |
4075 | ||
e615efe4 | 4076 | /* Program SSCDIVINTPHASE6 */ |
988d6ee8 | 4077 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
e615efe4 ED |
4078 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
4079 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); | |
4080 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; | |
4081 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); | |
4082 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); | |
4083 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; | |
988d6ee8 | 4084 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
e615efe4 ED |
4085 | |
4086 | /* Program SSCAUXDIV */ | |
988d6ee8 | 4087 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
e615efe4 ED |
4088 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
4089 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); | |
988d6ee8 | 4090 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
e615efe4 ED |
4091 | |
4092 | /* Enable modulator and associated divider */ | |
988d6ee8 | 4093 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
e615efe4 | 4094 | temp &= ~SBI_SSCCTL_DISABLE; |
988d6ee8 | 4095 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
e615efe4 | 4096 | |
060f02d8 VS |
4097 | mutex_unlock(&dev_priv->sb_lock); |
4098 | ||
e615efe4 ED |
4099 | /* Wait for initialization time */ |
4100 | udelay(24); | |
4101 | ||
4102 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); | |
4103 | } | |
4104 | ||
275f01b2 DV |
4105 | static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc, |
4106 | enum pipe pch_transcoder) | |
4107 | { | |
4108 | struct drm_device *dev = crtc->base.dev; | |
4109 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6e3c9717 | 4110 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
275f01b2 DV |
4111 | |
4112 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), | |
4113 | I915_READ(HTOTAL(cpu_transcoder))); | |
4114 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), | |
4115 | I915_READ(HBLANK(cpu_transcoder))); | |
4116 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), | |
4117 | I915_READ(HSYNC(cpu_transcoder))); | |
4118 | ||
4119 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), | |
4120 | I915_READ(VTOTAL(cpu_transcoder))); | |
4121 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), | |
4122 | I915_READ(VBLANK(cpu_transcoder))); | |
4123 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), | |
4124 | I915_READ(VSYNC(cpu_transcoder))); | |
4125 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), | |
4126 | I915_READ(VSYNCSHIFT(cpu_transcoder))); | |
4127 | } | |
4128 | ||
003632d9 | 4129 | static void cpt_set_fdi_bc_bifurcation(struct drm_device *dev, bool enable) |
1fbc0d78 DV |
4130 | { |
4131 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4132 | uint32_t temp; | |
4133 | ||
4134 | temp = I915_READ(SOUTH_CHICKEN1); | |
003632d9 | 4135 | if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable) |
1fbc0d78 DV |
4136 | return; |
4137 | ||
4138 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); | |
4139 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); | |
4140 | ||
003632d9 ACO |
4141 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
4142 | if (enable) | |
4143 | temp |= FDI_BC_BIFURCATION_SELECT; | |
4144 | ||
4145 | DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis"); | |
1fbc0d78 DV |
4146 | I915_WRITE(SOUTH_CHICKEN1, temp); |
4147 | POSTING_READ(SOUTH_CHICKEN1); | |
4148 | } | |
4149 | ||
4150 | static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc) | |
4151 | { | |
4152 | struct drm_device *dev = intel_crtc->base.dev; | |
1fbc0d78 DV |
4153 | |
4154 | switch (intel_crtc->pipe) { | |
4155 | case PIPE_A: | |
4156 | break; | |
4157 | case PIPE_B: | |
6e3c9717 | 4158 | if (intel_crtc->config->fdi_lanes > 2) |
003632d9 | 4159 | cpt_set_fdi_bc_bifurcation(dev, false); |
1fbc0d78 | 4160 | else |
003632d9 | 4161 | cpt_set_fdi_bc_bifurcation(dev, true); |
1fbc0d78 DV |
4162 | |
4163 | break; | |
4164 | case PIPE_C: | |
003632d9 | 4165 | cpt_set_fdi_bc_bifurcation(dev, true); |
1fbc0d78 DV |
4166 | |
4167 | break; | |
4168 | default: | |
4169 | BUG(); | |
4170 | } | |
4171 | } | |
4172 | ||
c48b5305 VS |
4173 | /* Return which DP Port should be selected for Transcoder DP control */ |
4174 | static enum port | |
4175 | intel_trans_dp_port_sel(struct drm_crtc *crtc) | |
4176 | { | |
4177 | struct drm_device *dev = crtc->dev; | |
4178 | struct intel_encoder *encoder; | |
4179 | ||
4180 | for_each_encoder_on_crtc(dev, crtc, encoder) { | |
4181 | if (encoder->type == INTEL_OUTPUT_DISPLAYPORT || | |
4182 | encoder->type == INTEL_OUTPUT_EDP) | |
4183 | return enc_to_dig_port(&encoder->base)->port; | |
4184 | } | |
4185 | ||
4186 | return -1; | |
4187 | } | |
4188 | ||
f67a559d JB |
4189 | /* |
4190 | * Enable PCH resources required for PCH ports: | |
4191 | * - PCH PLLs | |
4192 | * - FDI training & RX/TX | |
4193 | * - update transcoder timings | |
4194 | * - DP transcoding bits | |
4195 | * - transcoder | |
4196 | */ | |
4197 | static void ironlake_pch_enable(struct drm_crtc *crtc) | |
0e23b99d JB |
4198 | { |
4199 | struct drm_device *dev = crtc->dev; | |
4200 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4201 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4202 | int pipe = intel_crtc->pipe; | |
f0f59a00 | 4203 | u32 temp; |
2c07245f | 4204 | |
ab9412ba | 4205 | assert_pch_transcoder_disabled(dev_priv, pipe); |
e7e164db | 4206 | |
1fbc0d78 DV |
4207 | if (IS_IVYBRIDGE(dev)) |
4208 | ivybridge_update_fdi_bc_bifurcation(intel_crtc); | |
4209 | ||
cd986abb DV |
4210 | /* Write the TU size bits before fdi link training, so that error |
4211 | * detection works. */ | |
4212 | I915_WRITE(FDI_RX_TUSIZE1(pipe), | |
4213 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); | |
4214 | ||
3860b2ec VS |
4215 | /* |
4216 | * Sometimes spurious CPU pipe underruns happen during FDI | |
4217 | * training, at least with VGA+HDMI cloning. Suppress them. | |
4218 | */ | |
4219 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
4220 | ||
c98e9dcf | 4221 | /* For PCH output, training FDI link */ |
674cf967 | 4222 | dev_priv->display.fdi_link_train(crtc); |
2c07245f | 4223 | |
3ad8a208 DV |
4224 | /* We need to program the right clock selection before writing the pixel |
4225 | * mutliplier into the DPLL. */ | |
303b81e0 | 4226 | if (HAS_PCH_CPT(dev)) { |
ee7b9f93 | 4227 | u32 sel; |
4b645f14 | 4228 | |
c98e9dcf | 4229 | temp = I915_READ(PCH_DPLL_SEL); |
11887397 DV |
4230 | temp |= TRANS_DPLL_ENABLE(pipe); |
4231 | sel = TRANS_DPLLB_SEL(pipe); | |
6e3c9717 | 4232 | if (intel_crtc->config->shared_dpll == DPLL_ID_PCH_PLL_B) |
ee7b9f93 JB |
4233 | temp |= sel; |
4234 | else | |
4235 | temp &= ~sel; | |
c98e9dcf | 4236 | I915_WRITE(PCH_DPLL_SEL, temp); |
c98e9dcf | 4237 | } |
5eddb70b | 4238 | |
3ad8a208 DV |
4239 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
4240 | * transcoder, and we actually should do this to not upset any PCH | |
4241 | * transcoder that already use the clock when we share it. | |
4242 | * | |
4243 | * Note that enable_shared_dpll tries to do the right thing, but | |
4244 | * get_shared_dpll unconditionally resets the pll - we need that to have | |
4245 | * the right LVDS enable sequence. */ | |
85b3894f | 4246 | intel_enable_shared_dpll(intel_crtc); |
3ad8a208 | 4247 | |
d9b6cb56 JB |
4248 | /* set transcoder timing, panel must allow it */ |
4249 | assert_panel_unlocked(dev_priv, pipe); | |
275f01b2 | 4250 | ironlake_pch_transcoder_set_timings(intel_crtc, pipe); |
8db9d77b | 4251 | |
303b81e0 | 4252 | intel_fdi_normal_train(crtc); |
5e84e1a4 | 4253 | |
3860b2ec VS |
4254 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4255 | ||
c98e9dcf | 4256 | /* For PCH DP, enable TRANS_DP_CTL */ |
6e3c9717 | 4257 | if (HAS_PCH_CPT(dev) && intel_crtc->config->has_dp_encoder) { |
9c4edaee VS |
4258 | const struct drm_display_mode *adjusted_mode = |
4259 | &intel_crtc->config->base.adjusted_mode; | |
dfd07d72 | 4260 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
f0f59a00 | 4261 | i915_reg_t reg = TRANS_DP_CTL(pipe); |
5eddb70b CW |
4262 | temp = I915_READ(reg); |
4263 | temp &= ~(TRANS_DP_PORT_SEL_MASK | | |
220cad3c EA |
4264 | TRANS_DP_SYNC_MASK | |
4265 | TRANS_DP_BPC_MASK); | |
e3ef4479 | 4266 | temp |= TRANS_DP_OUTPUT_ENABLE; |
9325c9f0 | 4267 | temp |= bpc << 9; /* same format but at 11:9 */ |
c98e9dcf | 4268 | |
9c4edaee | 4269 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
5eddb70b | 4270 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
9c4edaee | 4271 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
5eddb70b | 4272 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
c98e9dcf JB |
4273 | |
4274 | switch (intel_trans_dp_port_sel(crtc)) { | |
c48b5305 | 4275 | case PORT_B: |
5eddb70b | 4276 | temp |= TRANS_DP_PORT_SEL_B; |
c98e9dcf | 4277 | break; |
c48b5305 | 4278 | case PORT_C: |
5eddb70b | 4279 | temp |= TRANS_DP_PORT_SEL_C; |
c98e9dcf | 4280 | break; |
c48b5305 | 4281 | case PORT_D: |
5eddb70b | 4282 | temp |= TRANS_DP_PORT_SEL_D; |
c98e9dcf JB |
4283 | break; |
4284 | default: | |
e95d41e1 | 4285 | BUG(); |
32f9d658 | 4286 | } |
2c07245f | 4287 | |
5eddb70b | 4288 | I915_WRITE(reg, temp); |
6be4a607 | 4289 | } |
b52eb4dc | 4290 | |
b8a4f404 | 4291 | ironlake_enable_pch_transcoder(dev_priv, pipe); |
f67a559d JB |
4292 | } |
4293 | ||
1507e5bd PZ |
4294 | static void lpt_pch_enable(struct drm_crtc *crtc) |
4295 | { | |
4296 | struct drm_device *dev = crtc->dev; | |
4297 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4298 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6e3c9717 | 4299 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
1507e5bd | 4300 | |
ab9412ba | 4301 | assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A); |
1507e5bd | 4302 | |
8c52b5e8 | 4303 | lpt_program_iclkip(crtc); |
1507e5bd | 4304 | |
0540e488 | 4305 | /* Set transcoder timing. */ |
275f01b2 | 4306 | ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A); |
1507e5bd | 4307 | |
937bb610 | 4308 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
f67a559d JB |
4309 | } |
4310 | ||
190f68c5 ACO |
4311 | struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc, |
4312 | struct intel_crtc_state *crtc_state) | |
ee7b9f93 | 4313 | { |
e2b78267 | 4314 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
8bd31e67 | 4315 | struct intel_shared_dpll *pll; |
de419ab6 | 4316 | struct intel_shared_dpll_config *shared_dpll; |
e2b78267 | 4317 | enum intel_dpll_id i; |
00490c22 | 4318 | int max = dev_priv->num_shared_dpll; |
ee7b9f93 | 4319 | |
de419ab6 ML |
4320 | shared_dpll = intel_atomic_get_shared_dpll_state(crtc_state->base.state); |
4321 | ||
98b6bd99 DV |
4322 | if (HAS_PCH_IBX(dev_priv->dev)) { |
4323 | /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */ | |
d94ab068 | 4324 | i = (enum intel_dpll_id) crtc->pipe; |
e72f9fbf | 4325 | pll = &dev_priv->shared_dplls[i]; |
98b6bd99 | 4326 | |
46edb027 DV |
4327 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", |
4328 | crtc->base.base.id, pll->name); | |
98b6bd99 | 4329 | |
de419ab6 | 4330 | WARN_ON(shared_dpll[i].crtc_mask); |
f2a69f44 | 4331 | |
98b6bd99 DV |
4332 | goto found; |
4333 | } | |
4334 | ||
bcddf610 S |
4335 | if (IS_BROXTON(dev_priv->dev)) { |
4336 | /* PLL is attached to port in bxt */ | |
4337 | struct intel_encoder *encoder; | |
4338 | struct intel_digital_port *intel_dig_port; | |
4339 | ||
4340 | encoder = intel_ddi_get_crtc_new_encoder(crtc_state); | |
4341 | if (WARN_ON(!encoder)) | |
4342 | return NULL; | |
4343 | ||
4344 | intel_dig_port = enc_to_dig_port(&encoder->base); | |
4345 | /* 1:1 mapping between ports and PLLs */ | |
4346 | i = (enum intel_dpll_id)intel_dig_port->port; | |
4347 | pll = &dev_priv->shared_dplls[i]; | |
4348 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", | |
4349 | crtc->base.base.id, pll->name); | |
de419ab6 | 4350 | WARN_ON(shared_dpll[i].crtc_mask); |
bcddf610 S |
4351 | |
4352 | goto found; | |
00490c22 ML |
4353 | } else if (INTEL_INFO(dev_priv)->gen < 9 && HAS_DDI(dev_priv)) |
4354 | /* Do not consider SPLL */ | |
4355 | max = 2; | |
bcddf610 | 4356 | |
00490c22 | 4357 | for (i = 0; i < max; i++) { |
e72f9fbf | 4358 | pll = &dev_priv->shared_dplls[i]; |
ee7b9f93 JB |
4359 | |
4360 | /* Only want to check enabled timings first */ | |
de419ab6 | 4361 | if (shared_dpll[i].crtc_mask == 0) |
ee7b9f93 JB |
4362 | continue; |
4363 | ||
190f68c5 | 4364 | if (memcmp(&crtc_state->dpll_hw_state, |
de419ab6 ML |
4365 | &shared_dpll[i].hw_state, |
4366 | sizeof(crtc_state->dpll_hw_state)) == 0) { | |
8bd31e67 | 4367 | DRM_DEBUG_KMS("CRTC:%d sharing existing %s (crtc mask 0x%08x, ative %d)\n", |
1e6f2ddc | 4368 | crtc->base.base.id, pll->name, |
de419ab6 | 4369 | shared_dpll[i].crtc_mask, |
8bd31e67 | 4370 | pll->active); |
ee7b9f93 JB |
4371 | goto found; |
4372 | } | |
4373 | } | |
4374 | ||
4375 | /* Ok no matching timings, maybe there's a free one? */ | |
e72f9fbf DV |
4376 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
4377 | pll = &dev_priv->shared_dplls[i]; | |
de419ab6 | 4378 | if (shared_dpll[i].crtc_mask == 0) { |
46edb027 DV |
4379 | DRM_DEBUG_KMS("CRTC:%d allocated %s\n", |
4380 | crtc->base.base.id, pll->name); | |
ee7b9f93 JB |
4381 | goto found; |
4382 | } | |
4383 | } | |
4384 | ||
4385 | return NULL; | |
4386 | ||
4387 | found: | |
de419ab6 ML |
4388 | if (shared_dpll[i].crtc_mask == 0) |
4389 | shared_dpll[i].hw_state = | |
4390 | crtc_state->dpll_hw_state; | |
f2a69f44 | 4391 | |
190f68c5 | 4392 | crtc_state->shared_dpll = i; |
46edb027 DV |
4393 | DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name, |
4394 | pipe_name(crtc->pipe)); | |
ee7b9f93 | 4395 | |
de419ab6 | 4396 | shared_dpll[i].crtc_mask |= 1 << crtc->pipe; |
e04c7350 | 4397 | |
ee7b9f93 JB |
4398 | return pll; |
4399 | } | |
4400 | ||
de419ab6 | 4401 | static void intel_shared_dpll_commit(struct drm_atomic_state *state) |
8bd31e67 | 4402 | { |
de419ab6 ML |
4403 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
4404 | struct intel_shared_dpll_config *shared_dpll; | |
8bd31e67 ACO |
4405 | struct intel_shared_dpll *pll; |
4406 | enum intel_dpll_id i; | |
4407 | ||
de419ab6 ML |
4408 | if (!to_intel_atomic_state(state)->dpll_set) |
4409 | return; | |
8bd31e67 | 4410 | |
de419ab6 | 4411 | shared_dpll = to_intel_atomic_state(state)->shared_dpll; |
8bd31e67 ACO |
4412 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
4413 | pll = &dev_priv->shared_dplls[i]; | |
de419ab6 | 4414 | pll->config = shared_dpll[i]; |
8bd31e67 ACO |
4415 | } |
4416 | } | |
4417 | ||
a1520318 | 4418 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
d4270e57 JB |
4419 | { |
4420 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f0f59a00 | 4421 | i915_reg_t dslreg = PIPEDSL(pipe); |
d4270e57 JB |
4422 | u32 temp; |
4423 | ||
4424 | temp = I915_READ(dslreg); | |
4425 | udelay(500); | |
4426 | if (wait_for(I915_READ(dslreg) != temp, 5)) { | |
d4270e57 | 4427 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
84f44ce7 | 4428 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
d4270e57 JB |
4429 | } |
4430 | } | |
4431 | ||
86adf9d7 ML |
4432 | static int |
4433 | skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach, | |
4434 | unsigned scaler_user, int *scaler_id, unsigned int rotation, | |
4435 | int src_w, int src_h, int dst_w, int dst_h) | |
a1b2278e | 4436 | { |
86adf9d7 ML |
4437 | struct intel_crtc_scaler_state *scaler_state = |
4438 | &crtc_state->scaler_state; | |
4439 | struct intel_crtc *intel_crtc = | |
4440 | to_intel_crtc(crtc_state->base.crtc); | |
a1b2278e | 4441 | int need_scaling; |
6156a456 CK |
4442 | |
4443 | need_scaling = intel_rotation_90_or_270(rotation) ? | |
4444 | (src_h != dst_w || src_w != dst_h): | |
4445 | (src_w != dst_w || src_h != dst_h); | |
a1b2278e CK |
4446 | |
4447 | /* | |
4448 | * if plane is being disabled or scaler is no more required or force detach | |
4449 | * - free scaler binded to this plane/crtc | |
4450 | * - in order to do this, update crtc->scaler_usage | |
4451 | * | |
4452 | * Here scaler state in crtc_state is set free so that | |
4453 | * scaler can be assigned to other user. Actual register | |
4454 | * update to free the scaler is done in plane/panel-fit programming. | |
4455 | * For this purpose crtc/plane_state->scaler_id isn't reset here. | |
4456 | */ | |
86adf9d7 | 4457 | if (force_detach || !need_scaling) { |
a1b2278e | 4458 | if (*scaler_id >= 0) { |
86adf9d7 | 4459 | scaler_state->scaler_users &= ~(1 << scaler_user); |
a1b2278e CK |
4460 | scaler_state->scalers[*scaler_id].in_use = 0; |
4461 | ||
86adf9d7 ML |
4462 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
4463 | "Staged freeing scaler id %d scaler_users = 0x%x\n", | |
4464 | intel_crtc->pipe, scaler_user, *scaler_id, | |
a1b2278e CK |
4465 | scaler_state->scaler_users); |
4466 | *scaler_id = -1; | |
4467 | } | |
4468 | return 0; | |
4469 | } | |
4470 | ||
4471 | /* range checks */ | |
4472 | if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H || | |
4473 | dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H || | |
4474 | ||
4475 | src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H || | |
4476 | dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H) { | |
86adf9d7 | 4477 | DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u " |
a1b2278e | 4478 | "size is out of scaler range\n", |
86adf9d7 | 4479 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h); |
a1b2278e CK |
4480 | return -EINVAL; |
4481 | } | |
4482 | ||
86adf9d7 ML |
4483 | /* mark this plane as a scaler user in crtc_state */ |
4484 | scaler_state->scaler_users |= (1 << scaler_user); | |
4485 | DRM_DEBUG_KMS("scaler_user index %u.%u: " | |
4486 | "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n", | |
4487 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h, | |
4488 | scaler_state->scaler_users); | |
4489 | ||
4490 | return 0; | |
4491 | } | |
4492 | ||
4493 | /** | |
4494 | * skl_update_scaler_crtc - Stages update to scaler state for a given crtc. | |
4495 | * | |
4496 | * @state: crtc's scaler state | |
86adf9d7 ML |
4497 | * |
4498 | * Return | |
4499 | * 0 - scaler_usage updated successfully | |
4500 | * error - requested scaling cannot be supported or other error condition | |
4501 | */ | |
e435d6e5 | 4502 | int skl_update_scaler_crtc(struct intel_crtc_state *state) |
86adf9d7 ML |
4503 | { |
4504 | struct intel_crtc *intel_crtc = to_intel_crtc(state->base.crtc); | |
7c5f93b0 | 4505 | const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode; |
86adf9d7 ML |
4506 | |
4507 | DRM_DEBUG_KMS("Updating scaler for [CRTC:%i] scaler_user index %u.%u\n", | |
4508 | intel_crtc->base.base.id, intel_crtc->pipe, SKL_CRTC_INDEX); | |
4509 | ||
e435d6e5 | 4510 | return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX, |
fa5a7970 | 4511 | &state->scaler_state.scaler_id, BIT(DRM_ROTATE_0), |
86adf9d7 | 4512 | state->pipe_src_w, state->pipe_src_h, |
aad941d5 | 4513 | adjusted_mode->crtc_hdisplay, adjusted_mode->crtc_vdisplay); |
86adf9d7 ML |
4514 | } |
4515 | ||
4516 | /** | |
4517 | * skl_update_scaler_plane - Stages update to scaler state for a given plane. | |
4518 | * | |
4519 | * @state: crtc's scaler state | |
86adf9d7 ML |
4520 | * @plane_state: atomic plane state to update |
4521 | * | |
4522 | * Return | |
4523 | * 0 - scaler_usage updated successfully | |
4524 | * error - requested scaling cannot be supported or other error condition | |
4525 | */ | |
da20eabd ML |
4526 | static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state, |
4527 | struct intel_plane_state *plane_state) | |
86adf9d7 ML |
4528 | { |
4529 | ||
4530 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); | |
da20eabd ML |
4531 | struct intel_plane *intel_plane = |
4532 | to_intel_plane(plane_state->base.plane); | |
86adf9d7 ML |
4533 | struct drm_framebuffer *fb = plane_state->base.fb; |
4534 | int ret; | |
4535 | ||
4536 | bool force_detach = !fb || !plane_state->visible; | |
4537 | ||
4538 | DRM_DEBUG_KMS("Updating scaler for [PLANE:%d] scaler_user index %u.%u\n", | |
4539 | intel_plane->base.base.id, intel_crtc->pipe, | |
4540 | drm_plane_index(&intel_plane->base)); | |
4541 | ||
4542 | ret = skl_update_scaler(crtc_state, force_detach, | |
4543 | drm_plane_index(&intel_plane->base), | |
4544 | &plane_state->scaler_id, | |
4545 | plane_state->base.rotation, | |
4546 | drm_rect_width(&plane_state->src) >> 16, | |
4547 | drm_rect_height(&plane_state->src) >> 16, | |
4548 | drm_rect_width(&plane_state->dst), | |
4549 | drm_rect_height(&plane_state->dst)); | |
4550 | ||
4551 | if (ret || plane_state->scaler_id < 0) | |
4552 | return ret; | |
4553 | ||
a1b2278e | 4554 | /* check colorkey */ |
818ed961 | 4555 | if (plane_state->ckey.flags != I915_SET_COLORKEY_NONE) { |
86adf9d7 | 4556 | DRM_DEBUG_KMS("[PLANE:%d] scaling with color key not allowed", |
818ed961 | 4557 | intel_plane->base.base.id); |
a1b2278e CK |
4558 | return -EINVAL; |
4559 | } | |
4560 | ||
4561 | /* Check src format */ | |
86adf9d7 ML |
4562 | switch (fb->pixel_format) { |
4563 | case DRM_FORMAT_RGB565: | |
4564 | case DRM_FORMAT_XBGR8888: | |
4565 | case DRM_FORMAT_XRGB8888: | |
4566 | case DRM_FORMAT_ABGR8888: | |
4567 | case DRM_FORMAT_ARGB8888: | |
4568 | case DRM_FORMAT_XRGB2101010: | |
4569 | case DRM_FORMAT_XBGR2101010: | |
4570 | case DRM_FORMAT_YUYV: | |
4571 | case DRM_FORMAT_YVYU: | |
4572 | case DRM_FORMAT_UYVY: | |
4573 | case DRM_FORMAT_VYUY: | |
4574 | break; | |
4575 | default: | |
4576 | DRM_DEBUG_KMS("[PLANE:%d] FB:%d unsupported scaling format 0x%x\n", | |
4577 | intel_plane->base.base.id, fb->base.id, fb->pixel_format); | |
4578 | return -EINVAL; | |
a1b2278e CK |
4579 | } |
4580 | ||
a1b2278e CK |
4581 | return 0; |
4582 | } | |
4583 | ||
e435d6e5 ML |
4584 | static void skylake_scaler_disable(struct intel_crtc *crtc) |
4585 | { | |
4586 | int i; | |
4587 | ||
4588 | for (i = 0; i < crtc->num_scalers; i++) | |
4589 | skl_detach_scaler(crtc, i); | |
4590 | } | |
4591 | ||
4592 | static void skylake_pfit_enable(struct intel_crtc *crtc) | |
bd2e244f JB |
4593 | { |
4594 | struct drm_device *dev = crtc->base.dev; | |
4595 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4596 | int pipe = crtc->pipe; | |
a1b2278e CK |
4597 | struct intel_crtc_scaler_state *scaler_state = |
4598 | &crtc->config->scaler_state; | |
4599 | ||
4600 | DRM_DEBUG_KMS("for crtc_state = %p\n", crtc->config); | |
4601 | ||
6e3c9717 | 4602 | if (crtc->config->pch_pfit.enabled) { |
a1b2278e CK |
4603 | int id; |
4604 | ||
4605 | if (WARN_ON(crtc->config->scaler_state.scaler_id < 0)) { | |
4606 | DRM_ERROR("Requesting pfit without getting a scaler first\n"); | |
4607 | return; | |
4608 | } | |
4609 | ||
4610 | id = scaler_state->scaler_id; | |
4611 | I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN | | |
4612 | PS_FILTER_MEDIUM | scaler_state->scalers[id].mode); | |
4613 | I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc->config->pch_pfit.pos); | |
4614 | I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc->config->pch_pfit.size); | |
4615 | ||
4616 | DRM_DEBUG_KMS("for crtc_state = %p scaler_id = %d\n", crtc->config, id); | |
bd2e244f JB |
4617 | } |
4618 | } | |
4619 | ||
b074cec8 JB |
4620 | static void ironlake_pfit_enable(struct intel_crtc *crtc) |
4621 | { | |
4622 | struct drm_device *dev = crtc->base.dev; | |
4623 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4624 | int pipe = crtc->pipe; | |
4625 | ||
6e3c9717 | 4626 | if (crtc->config->pch_pfit.enabled) { |
b074cec8 JB |
4627 | /* Force use of hard-coded filter coefficients |
4628 | * as some pre-programmed values are broken, | |
4629 | * e.g. x201. | |
4630 | */ | |
4631 | if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) | |
4632 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | | |
4633 | PF_PIPE_SEL_IVB(pipe)); | |
4634 | else | |
4635 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3); | |
6e3c9717 ACO |
4636 | I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos); |
4637 | I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size); | |
d4270e57 JB |
4638 | } |
4639 | } | |
4640 | ||
20bc8673 | 4641 | void hsw_enable_ips(struct intel_crtc *crtc) |
d77e4531 | 4642 | { |
cea165c3 VS |
4643 | struct drm_device *dev = crtc->base.dev; |
4644 | struct drm_i915_private *dev_priv = dev->dev_private; | |
d77e4531 | 4645 | |
6e3c9717 | 4646 | if (!crtc->config->ips_enabled) |
d77e4531 PZ |
4647 | return; |
4648 | ||
cea165c3 VS |
4649 | /* We can only enable IPS after we enable a plane and wait for a vblank */ |
4650 | intel_wait_for_vblank(dev, crtc->pipe); | |
4651 | ||
d77e4531 | 4652 | assert_plane_enabled(dev_priv, crtc->plane); |
cea165c3 | 4653 | if (IS_BROADWELL(dev)) { |
2a114cc1 BW |
4654 | mutex_lock(&dev_priv->rps.hw_lock); |
4655 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000)); | |
4656 | mutex_unlock(&dev_priv->rps.hw_lock); | |
4657 | /* Quoting Art Runyan: "its not safe to expect any particular | |
4658 | * value in IPS_CTL bit 31 after enabling IPS through the | |
e59150dc JB |
4659 | * mailbox." Moreover, the mailbox may return a bogus state, |
4660 | * so we need to just enable it and continue on. | |
2a114cc1 BW |
4661 | */ |
4662 | } else { | |
4663 | I915_WRITE(IPS_CTL, IPS_ENABLE); | |
4664 | /* The bit only becomes 1 in the next vblank, so this wait here | |
4665 | * is essentially intel_wait_for_vblank. If we don't have this | |
4666 | * and don't wait for vblanks until the end of crtc_enable, then | |
4667 | * the HW state readout code will complain that the expected | |
4668 | * IPS_CTL value is not the one we read. */ | |
4669 | if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50)) | |
4670 | DRM_ERROR("Timed out waiting for IPS enable\n"); | |
4671 | } | |
d77e4531 PZ |
4672 | } |
4673 | ||
20bc8673 | 4674 | void hsw_disable_ips(struct intel_crtc *crtc) |
d77e4531 PZ |
4675 | { |
4676 | struct drm_device *dev = crtc->base.dev; | |
4677 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4678 | ||
6e3c9717 | 4679 | if (!crtc->config->ips_enabled) |
d77e4531 PZ |
4680 | return; |
4681 | ||
4682 | assert_plane_enabled(dev_priv, crtc->plane); | |
23d0b130 | 4683 | if (IS_BROADWELL(dev)) { |
2a114cc1 BW |
4684 | mutex_lock(&dev_priv->rps.hw_lock); |
4685 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); | |
4686 | mutex_unlock(&dev_priv->rps.hw_lock); | |
23d0b130 BW |
4687 | /* wait for pcode to finish disabling IPS, which may take up to 42ms */ |
4688 | if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42)) | |
4689 | DRM_ERROR("Timed out waiting for IPS disable\n"); | |
e59150dc | 4690 | } else { |
2a114cc1 | 4691 | I915_WRITE(IPS_CTL, 0); |
e59150dc JB |
4692 | POSTING_READ(IPS_CTL); |
4693 | } | |
d77e4531 PZ |
4694 | |
4695 | /* We need to wait for a vblank before we can disable the plane. */ | |
4696 | intel_wait_for_vblank(dev, crtc->pipe); | |
4697 | } | |
4698 | ||
4699 | /** Loads the palette/gamma unit for the CRTC with the prepared values */ | |
4700 | static void intel_crtc_load_lut(struct drm_crtc *crtc) | |
4701 | { | |
4702 | struct drm_device *dev = crtc->dev; | |
4703 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4704 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4705 | enum pipe pipe = intel_crtc->pipe; | |
d77e4531 PZ |
4706 | int i; |
4707 | bool reenable_ips = false; | |
4708 | ||
4709 | /* The clocks have to be on to load the palette. */ | |
53d9f4e9 | 4710 | if (!crtc->state->active) |
d77e4531 PZ |
4711 | return; |
4712 | ||
50360403 | 4713 | if (HAS_GMCH_DISPLAY(dev_priv->dev)) { |
a65347ba | 4714 | if (intel_crtc->config->has_dsi_encoder) |
d77e4531 PZ |
4715 | assert_dsi_pll_enabled(dev_priv); |
4716 | else | |
4717 | assert_pll_enabled(dev_priv, pipe); | |
4718 | } | |
4719 | ||
d77e4531 PZ |
4720 | /* Workaround : Do not read or write the pipe palette/gamma data while |
4721 | * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled. | |
4722 | */ | |
6e3c9717 | 4723 | if (IS_HASWELL(dev) && intel_crtc->config->ips_enabled && |
d77e4531 PZ |
4724 | ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) == |
4725 | GAMMA_MODE_MODE_SPLIT)) { | |
4726 | hsw_disable_ips(intel_crtc); | |
4727 | reenable_ips = true; | |
4728 | } | |
4729 | ||
4730 | for (i = 0; i < 256; i++) { | |
f0f59a00 | 4731 | i915_reg_t palreg; |
f65a9c5b VS |
4732 | |
4733 | if (HAS_GMCH_DISPLAY(dev)) | |
4734 | palreg = PALETTE(pipe, i); | |
4735 | else | |
4736 | palreg = LGC_PALETTE(pipe, i); | |
4737 | ||
4738 | I915_WRITE(palreg, | |
d77e4531 PZ |
4739 | (intel_crtc->lut_r[i] << 16) | |
4740 | (intel_crtc->lut_g[i] << 8) | | |
4741 | intel_crtc->lut_b[i]); | |
4742 | } | |
4743 | ||
4744 | if (reenable_ips) | |
4745 | hsw_enable_ips(intel_crtc); | |
4746 | } | |
4747 | ||
7cac945f | 4748 | static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc) |
d3eedb1a | 4749 | { |
7cac945f | 4750 | if (intel_crtc->overlay) { |
d3eedb1a VS |
4751 | struct drm_device *dev = intel_crtc->base.dev; |
4752 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4753 | ||
4754 | mutex_lock(&dev->struct_mutex); | |
4755 | dev_priv->mm.interruptible = false; | |
4756 | (void) intel_overlay_switch_off(intel_crtc->overlay); | |
4757 | dev_priv->mm.interruptible = true; | |
4758 | mutex_unlock(&dev->struct_mutex); | |
4759 | } | |
4760 | ||
4761 | /* Let userspace switch the overlay on again. In most cases userspace | |
4762 | * has to recompute where to put it anyway. | |
4763 | */ | |
4764 | } | |
4765 | ||
87d4300a ML |
4766 | /** |
4767 | * intel_post_enable_primary - Perform operations after enabling primary plane | |
4768 | * @crtc: the CRTC whose primary plane was just enabled | |
4769 | * | |
4770 | * Performs potentially sleeping operations that must be done after the primary | |
4771 | * plane is enabled, such as updating FBC and IPS. Note that this may be | |
4772 | * called due to an explicit primary plane update, or due to an implicit | |
4773 | * re-enable that is caused when a sprite plane is updated to no longer | |
4774 | * completely hide the primary plane. | |
4775 | */ | |
4776 | static void | |
4777 | intel_post_enable_primary(struct drm_crtc *crtc) | |
a5c4d7bc VS |
4778 | { |
4779 | struct drm_device *dev = crtc->dev; | |
87d4300a | 4780 | struct drm_i915_private *dev_priv = dev->dev_private; |
a5c4d7bc VS |
4781 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
4782 | int pipe = intel_crtc->pipe; | |
a5c4d7bc | 4783 | |
87d4300a ML |
4784 | /* |
4785 | * FIXME IPS should be fine as long as one plane is | |
4786 | * enabled, but in practice it seems to have problems | |
4787 | * when going from primary only to sprite only and vice | |
4788 | * versa. | |
4789 | */ | |
a5c4d7bc VS |
4790 | hsw_enable_ips(intel_crtc); |
4791 | ||
f99d7069 | 4792 | /* |
87d4300a ML |
4793 | * Gen2 reports pipe underruns whenever all planes are disabled. |
4794 | * So don't enable underrun reporting before at least some planes | |
4795 | * are enabled. | |
4796 | * FIXME: Need to fix the logic to work when we turn off all planes | |
4797 | * but leave the pipe running. | |
f99d7069 | 4798 | */ |
87d4300a ML |
4799 | if (IS_GEN2(dev)) |
4800 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); | |
4801 | ||
aca7b684 VS |
4802 | /* Underruns don't always raise interrupts, so check manually. */ |
4803 | intel_check_cpu_fifo_underruns(dev_priv); | |
4804 | intel_check_pch_fifo_underruns(dev_priv); | |
a5c4d7bc VS |
4805 | } |
4806 | ||
87d4300a ML |
4807 | /** |
4808 | * intel_pre_disable_primary - Perform operations before disabling primary plane | |
4809 | * @crtc: the CRTC whose primary plane is to be disabled | |
4810 | * | |
4811 | * Performs potentially sleeping operations that must be done before the | |
4812 | * primary plane is disabled, such as updating FBC and IPS. Note that this may | |
4813 | * be called due to an explicit primary plane update, or due to an implicit | |
4814 | * disable that is caused when a sprite plane completely hides the primary | |
4815 | * plane. | |
4816 | */ | |
4817 | static void | |
4818 | intel_pre_disable_primary(struct drm_crtc *crtc) | |
a5c4d7bc VS |
4819 | { |
4820 | struct drm_device *dev = crtc->dev; | |
4821 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4822 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4823 | int pipe = intel_crtc->pipe; | |
a5c4d7bc | 4824 | |
87d4300a ML |
4825 | /* |
4826 | * Gen2 reports pipe underruns whenever all planes are disabled. | |
4827 | * So diasble underrun reporting before all the planes get disabled. | |
4828 | * FIXME: Need to fix the logic to work when we turn off all planes | |
4829 | * but leave the pipe running. | |
4830 | */ | |
4831 | if (IS_GEN2(dev)) | |
4832 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
a5c4d7bc | 4833 | |
87d4300a ML |
4834 | /* |
4835 | * Vblank time updates from the shadow to live plane control register | |
4836 | * are blocked if the memory self-refresh mode is active at that | |
4837 | * moment. So to make sure the plane gets truly disabled, disable | |
4838 | * first the self-refresh mode. The self-refresh enable bit in turn | |
4839 | * will be checked/applied by the HW only at the next frame start | |
4840 | * event which is after the vblank start event, so we need to have a | |
4841 | * wait-for-vblank between disabling the plane and the pipe. | |
4842 | */ | |
262cd2e1 | 4843 | if (HAS_GMCH_DISPLAY(dev)) { |
87d4300a | 4844 | intel_set_memory_cxsr(dev_priv, false); |
262cd2e1 VS |
4845 | dev_priv->wm.vlv.cxsr = false; |
4846 | intel_wait_for_vblank(dev, pipe); | |
4847 | } | |
87d4300a | 4848 | |
87d4300a ML |
4849 | /* |
4850 | * FIXME IPS should be fine as long as one plane is | |
4851 | * enabled, but in practice it seems to have problems | |
4852 | * when going from primary only to sprite only and vice | |
4853 | * versa. | |
4854 | */ | |
a5c4d7bc | 4855 | hsw_disable_ips(intel_crtc); |
87d4300a ML |
4856 | } |
4857 | ||
ac21b225 ML |
4858 | static void intel_post_plane_update(struct intel_crtc *crtc) |
4859 | { | |
4860 | struct intel_crtc_atomic_commit *atomic = &crtc->atomic; | |
92826fcd ML |
4861 | struct intel_crtc_state *pipe_config = |
4862 | to_intel_crtc_state(crtc->base.state); | |
ac21b225 | 4863 | struct drm_device *dev = crtc->base.dev; |
ac21b225 | 4864 | |
ac21b225 ML |
4865 | intel_frontbuffer_flip(dev, atomic->fb_bits); |
4866 | ||
ab1d3a0e | 4867 | crtc->wm.cxsr_allowed = true; |
852eb00d | 4868 | |
b9001114 | 4869 | if (pipe_config->wm_changed && pipe_config->base.active) |
f015c551 VS |
4870 | intel_update_watermarks(&crtc->base); |
4871 | ||
c80ac854 | 4872 | if (atomic->update_fbc) |
1eb52238 | 4873 | intel_fbc_post_update(crtc); |
ac21b225 ML |
4874 | |
4875 | if (atomic->post_enable_primary) | |
4876 | intel_post_enable_primary(&crtc->base); | |
4877 | ||
ac21b225 ML |
4878 | memset(atomic, 0, sizeof(*atomic)); |
4879 | } | |
4880 | ||
5c74cd73 | 4881 | static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state) |
ac21b225 | 4882 | { |
5c74cd73 | 4883 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
ac21b225 | 4884 | struct drm_device *dev = crtc->base.dev; |
eddfcbcd | 4885 | struct drm_i915_private *dev_priv = dev->dev_private; |
ac21b225 | 4886 | struct intel_crtc_atomic_commit *atomic = &crtc->atomic; |
ab1d3a0e ML |
4887 | struct intel_crtc_state *pipe_config = |
4888 | to_intel_crtc_state(crtc->base.state); | |
5c74cd73 ML |
4889 | struct drm_atomic_state *old_state = old_crtc_state->base.state; |
4890 | struct drm_plane *primary = crtc->base.primary; | |
4891 | struct drm_plane_state *old_pri_state = | |
4892 | drm_atomic_get_existing_plane_state(old_state, primary); | |
4893 | bool modeset = needs_modeset(&pipe_config->base); | |
ac21b225 | 4894 | |
1eb52238 PZ |
4895 | if (atomic->update_fbc) |
4896 | intel_fbc_pre_update(crtc); | |
ac21b225 | 4897 | |
5c74cd73 ML |
4898 | if (old_pri_state) { |
4899 | struct intel_plane_state *primary_state = | |
4900 | to_intel_plane_state(primary->state); | |
4901 | struct intel_plane_state *old_primary_state = | |
4902 | to_intel_plane_state(old_pri_state); | |
4903 | ||
4904 | if (old_primary_state->visible && | |
4905 | (modeset || !primary_state->visible)) | |
4906 | intel_pre_disable_primary(&crtc->base); | |
4907 | } | |
852eb00d | 4908 | |
ab1d3a0e | 4909 | if (pipe_config->disable_cxsr) { |
852eb00d | 4910 | crtc->wm.cxsr_allowed = false; |
2dfd178d ML |
4911 | |
4912 | if (old_crtc_state->base.active) | |
4913 | intel_set_memory_cxsr(dev_priv, false); | |
852eb00d | 4914 | } |
92826fcd | 4915 | |
ed4a6a7c MR |
4916 | /* |
4917 | * IVB workaround: must disable low power watermarks for at least | |
4918 | * one frame before enabling scaling. LP watermarks can be re-enabled | |
4919 | * when scaling is disabled. | |
4920 | * | |
4921 | * WaCxSRDisabledForSpriteScaling:ivb | |
4922 | */ | |
4923 | if (pipe_config->disable_lp_wm) { | |
4924 | ilk_disable_lp_wm(dev); | |
4925 | intel_wait_for_vblank(dev, crtc->pipe); | |
4926 | } | |
4927 | ||
4928 | /* | |
4929 | * If we're doing a modeset, we're done. No need to do any pre-vblank | |
4930 | * watermark programming here. | |
4931 | */ | |
4932 | if (needs_modeset(&pipe_config->base)) | |
4933 | return; | |
4934 | ||
4935 | /* | |
4936 | * For platforms that support atomic watermarks, program the | |
4937 | * 'intermediate' watermarks immediately. On pre-gen9 platforms, these | |
4938 | * will be the intermediate values that are safe for both pre- and | |
4939 | * post- vblank; when vblank happens, the 'active' values will be set | |
4940 | * to the final 'target' values and we'll do this again to get the | |
4941 | * optimal watermarks. For gen9+ platforms, the values we program here | |
4942 | * will be the final target values which will get automatically latched | |
4943 | * at vblank time; no further programming will be necessary. | |
4944 | * | |
4945 | * If a platform hasn't been transitioned to atomic watermarks yet, | |
4946 | * we'll continue to update watermarks the old way, if flags tell | |
4947 | * us to. | |
4948 | */ | |
4949 | if (dev_priv->display.initial_watermarks != NULL) | |
4950 | dev_priv->display.initial_watermarks(pipe_config); | |
4951 | else if (pipe_config->wm_changed) | |
92826fcd | 4952 | intel_update_watermarks(&crtc->base); |
ac21b225 ML |
4953 | } |
4954 | ||
d032ffa0 | 4955 | static void intel_crtc_disable_planes(struct drm_crtc *crtc, unsigned plane_mask) |
87d4300a ML |
4956 | { |
4957 | struct drm_device *dev = crtc->dev; | |
4958 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
d032ffa0 | 4959 | struct drm_plane *p; |
87d4300a ML |
4960 | int pipe = intel_crtc->pipe; |
4961 | ||
7cac945f | 4962 | intel_crtc_dpms_overlay_disable(intel_crtc); |
27321ae8 | 4963 | |
d032ffa0 ML |
4964 | drm_for_each_plane_mask(p, dev, plane_mask) |
4965 | to_intel_plane(p)->disable_plane(p, crtc); | |
f98551ae | 4966 | |
f99d7069 DV |
4967 | /* |
4968 | * FIXME: Once we grow proper nuclear flip support out of this we need | |
4969 | * to compute the mask of flip planes precisely. For the time being | |
4970 | * consider this a flip to a NULL plane. | |
4971 | */ | |
4972 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); | |
a5c4d7bc VS |
4973 | } |
4974 | ||
f67a559d JB |
4975 | static void ironlake_crtc_enable(struct drm_crtc *crtc) |
4976 | { | |
4977 | struct drm_device *dev = crtc->dev; | |
4978 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4979 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 4980 | struct intel_encoder *encoder; |
f67a559d | 4981 | int pipe = intel_crtc->pipe; |
f67a559d | 4982 | |
53d9f4e9 | 4983 | if (WARN_ON(intel_crtc->active)) |
f67a559d JB |
4984 | return; |
4985 | ||
81b088ca VS |
4986 | if (intel_crtc->config->has_pch_encoder) |
4987 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); | |
4988 | ||
6e3c9717 | 4989 | if (intel_crtc->config->has_pch_encoder) |
b14b1055 DV |
4990 | intel_prepare_shared_dpll(intel_crtc); |
4991 | ||
6e3c9717 | 4992 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 4993 | intel_dp_set_m_n(intel_crtc, M1_N1); |
29407aab DV |
4994 | |
4995 | intel_set_pipe_timings(intel_crtc); | |
4996 | ||
6e3c9717 | 4997 | if (intel_crtc->config->has_pch_encoder) { |
29407aab | 4998 | intel_cpu_transcoder_set_m_n(intel_crtc, |
6e3c9717 | 4999 | &intel_crtc->config->fdi_m_n, NULL); |
29407aab DV |
5000 | } |
5001 | ||
5002 | ironlake_set_pipeconf(crtc); | |
5003 | ||
f67a559d | 5004 | intel_crtc->active = true; |
8664281b | 5005 | |
a72e4c9f | 5006 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
8664281b | 5007 | |
f6736a1a | 5008 | for_each_encoder_on_crtc(dev, crtc, encoder) |
952735ee DV |
5009 | if (encoder->pre_enable) |
5010 | encoder->pre_enable(encoder); | |
f67a559d | 5011 | |
6e3c9717 | 5012 | if (intel_crtc->config->has_pch_encoder) { |
fff367c7 DV |
5013 | /* Note: FDI PLL enabling _must_ be done before we enable the |
5014 | * cpu pipes, hence this is separate from all the other fdi/pch | |
5015 | * enabling. */ | |
88cefb6c | 5016 | ironlake_fdi_pll_enable(intel_crtc); |
46b6f814 DV |
5017 | } else { |
5018 | assert_fdi_tx_disabled(dev_priv, pipe); | |
5019 | assert_fdi_rx_disabled(dev_priv, pipe); | |
5020 | } | |
f67a559d | 5021 | |
b074cec8 | 5022 | ironlake_pfit_enable(intel_crtc); |
f67a559d | 5023 | |
9c54c0dd JB |
5024 | /* |
5025 | * On ILK+ LUT must be loaded before the pipe is running but with | |
5026 | * clocks enabled | |
5027 | */ | |
5028 | intel_crtc_load_lut(crtc); | |
5029 | ||
1d5bf5d9 ID |
5030 | if (dev_priv->display.initial_watermarks != NULL) |
5031 | dev_priv->display.initial_watermarks(intel_crtc->config); | |
e1fdc473 | 5032 | intel_enable_pipe(intel_crtc); |
f67a559d | 5033 | |
6e3c9717 | 5034 | if (intel_crtc->config->has_pch_encoder) |
f67a559d | 5035 | ironlake_pch_enable(crtc); |
c98e9dcf | 5036 | |
f9b61ff6 DV |
5037 | assert_vblank_disabled(crtc); |
5038 | drm_crtc_vblank_on(crtc); | |
5039 | ||
fa5c73b1 DV |
5040 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5041 | encoder->enable(encoder); | |
61b77ddd DV |
5042 | |
5043 | if (HAS_PCH_CPT(dev)) | |
a1520318 | 5044 | cpt_verify_modeset(dev, intel_crtc->pipe); |
37ca8d4c VS |
5045 | |
5046 | /* Must wait for vblank to avoid spurious PCH FIFO underruns */ | |
5047 | if (intel_crtc->config->has_pch_encoder) | |
5048 | intel_wait_for_vblank(dev, pipe); | |
5049 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); | |
6be4a607 JB |
5050 | } |
5051 | ||
42db64ef PZ |
5052 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
5053 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) | |
5054 | { | |
f5adf94e | 5055 | return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A; |
42db64ef PZ |
5056 | } |
5057 | ||
4f771f10 PZ |
5058 | static void haswell_crtc_enable(struct drm_crtc *crtc) |
5059 | { | |
5060 | struct drm_device *dev = crtc->dev; | |
5061 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5062 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
5063 | struct intel_encoder *encoder; | |
99d736a2 ML |
5064 | int pipe = intel_crtc->pipe, hsw_workaround_pipe; |
5065 | struct intel_crtc_state *pipe_config = | |
5066 | to_intel_crtc_state(crtc->state); | |
4f771f10 | 5067 | |
53d9f4e9 | 5068 | if (WARN_ON(intel_crtc->active)) |
4f771f10 PZ |
5069 | return; |
5070 | ||
81b088ca VS |
5071 | if (intel_crtc->config->has_pch_encoder) |
5072 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, | |
5073 | false); | |
5074 | ||
df8ad70c DV |
5075 | if (intel_crtc_to_shared_dpll(intel_crtc)) |
5076 | intel_enable_shared_dpll(intel_crtc); | |
5077 | ||
6e3c9717 | 5078 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 5079 | intel_dp_set_m_n(intel_crtc, M1_N1); |
229fca97 DV |
5080 | |
5081 | intel_set_pipe_timings(intel_crtc); | |
5082 | ||
6e3c9717 ACO |
5083 | if (intel_crtc->config->cpu_transcoder != TRANSCODER_EDP) { |
5084 | I915_WRITE(PIPE_MULT(intel_crtc->config->cpu_transcoder), | |
5085 | intel_crtc->config->pixel_multiplier - 1); | |
ebb69c95 CT |
5086 | } |
5087 | ||
6e3c9717 | 5088 | if (intel_crtc->config->has_pch_encoder) { |
229fca97 | 5089 | intel_cpu_transcoder_set_m_n(intel_crtc, |
6e3c9717 | 5090 | &intel_crtc->config->fdi_m_n, NULL); |
229fca97 DV |
5091 | } |
5092 | ||
5093 | haswell_set_pipeconf(crtc); | |
5094 | ||
5095 | intel_set_pipe_csc(crtc); | |
5096 | ||
4f771f10 | 5097 | intel_crtc->active = true; |
8664281b | 5098 | |
6b698516 DV |
5099 | if (intel_crtc->config->has_pch_encoder) |
5100 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
5101 | else | |
5102 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); | |
5103 | ||
7d4aefd0 | 5104 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
4f771f10 PZ |
5105 | if (encoder->pre_enable) |
5106 | encoder->pre_enable(encoder); | |
7d4aefd0 | 5107 | } |
4f771f10 | 5108 | |
d2d65408 | 5109 | if (intel_crtc->config->has_pch_encoder) |
4fe9467d | 5110 | dev_priv->display.fdi_link_train(crtc); |
4fe9467d | 5111 | |
a65347ba | 5112 | if (!intel_crtc->config->has_dsi_encoder) |
7d4aefd0 | 5113 | intel_ddi_enable_pipe_clock(intel_crtc); |
4f771f10 | 5114 | |
1c132b44 | 5115 | if (INTEL_INFO(dev)->gen >= 9) |
e435d6e5 | 5116 | skylake_pfit_enable(intel_crtc); |
ff6d9f55 | 5117 | else |
1c132b44 | 5118 | ironlake_pfit_enable(intel_crtc); |
4f771f10 PZ |
5119 | |
5120 | /* | |
5121 | * On ILK+ LUT must be loaded before the pipe is running but with | |
5122 | * clocks enabled | |
5123 | */ | |
5124 | intel_crtc_load_lut(crtc); | |
5125 | ||
1f544388 | 5126 | intel_ddi_set_pipe_settings(crtc); |
a65347ba | 5127 | if (!intel_crtc->config->has_dsi_encoder) |
7d4aefd0 | 5128 | intel_ddi_enable_transcoder_func(crtc); |
4f771f10 | 5129 | |
1d5bf5d9 ID |
5130 | if (dev_priv->display.initial_watermarks != NULL) |
5131 | dev_priv->display.initial_watermarks(pipe_config); | |
5132 | else | |
5133 | intel_update_watermarks(crtc); | |
e1fdc473 | 5134 | intel_enable_pipe(intel_crtc); |
42db64ef | 5135 | |
6e3c9717 | 5136 | if (intel_crtc->config->has_pch_encoder) |
1507e5bd | 5137 | lpt_pch_enable(crtc); |
4f771f10 | 5138 | |
a65347ba | 5139 | if (intel_crtc->config->dp_encoder_is_mst) |
0e32b39c DA |
5140 | intel_ddi_set_vc_payload_alloc(crtc, true); |
5141 | ||
f9b61ff6 DV |
5142 | assert_vblank_disabled(crtc); |
5143 | drm_crtc_vblank_on(crtc); | |
5144 | ||
8807e55b | 5145 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
4f771f10 | 5146 | encoder->enable(encoder); |
8807e55b JN |
5147 | intel_opregion_notify_encoder(encoder, true); |
5148 | } | |
4f771f10 | 5149 | |
6b698516 DV |
5150 | if (intel_crtc->config->has_pch_encoder) { |
5151 | intel_wait_for_vblank(dev, pipe); | |
5152 | intel_wait_for_vblank(dev, pipe); | |
5153 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); | |
d2d65408 VS |
5154 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
5155 | true); | |
6b698516 | 5156 | } |
d2d65408 | 5157 | |
e4916946 PZ |
5158 | /* If we change the relative order between pipe/planes enabling, we need |
5159 | * to change the workaround. */ | |
99d736a2 ML |
5160 | hsw_workaround_pipe = pipe_config->hsw_workaround_pipe; |
5161 | if (IS_HASWELL(dev) && hsw_workaround_pipe != INVALID_PIPE) { | |
5162 | intel_wait_for_vblank(dev, hsw_workaround_pipe); | |
5163 | intel_wait_for_vblank(dev, hsw_workaround_pipe); | |
5164 | } | |
4f771f10 PZ |
5165 | } |
5166 | ||
bfd16b2a | 5167 | static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force) |
3f8dce3a DV |
5168 | { |
5169 | struct drm_device *dev = crtc->base.dev; | |
5170 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5171 | int pipe = crtc->pipe; | |
5172 | ||
5173 | /* To avoid upsetting the power well on haswell only disable the pfit if | |
5174 | * it's in use. The hw state code will make sure we get this right. */ | |
bfd16b2a | 5175 | if (force || crtc->config->pch_pfit.enabled) { |
3f8dce3a DV |
5176 | I915_WRITE(PF_CTL(pipe), 0); |
5177 | I915_WRITE(PF_WIN_POS(pipe), 0); | |
5178 | I915_WRITE(PF_WIN_SZ(pipe), 0); | |
5179 | } | |
5180 | } | |
5181 | ||
6be4a607 JB |
5182 | static void ironlake_crtc_disable(struct drm_crtc *crtc) |
5183 | { | |
5184 | struct drm_device *dev = crtc->dev; | |
5185 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5186 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 5187 | struct intel_encoder *encoder; |
6be4a607 | 5188 | int pipe = intel_crtc->pipe; |
b52eb4dc | 5189 | |
37ca8d4c VS |
5190 | if (intel_crtc->config->has_pch_encoder) |
5191 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); | |
5192 | ||
ea9d758d DV |
5193 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5194 | encoder->disable(encoder); | |
5195 | ||
f9b61ff6 DV |
5196 | drm_crtc_vblank_off(crtc); |
5197 | assert_vblank_disabled(crtc); | |
5198 | ||
3860b2ec VS |
5199 | /* |
5200 | * Sometimes spurious CPU pipe underruns happen when the | |
5201 | * pipe is already disabled, but FDI RX/TX is still enabled. | |
5202 | * Happens at least with VGA+HDMI cloning. Suppress them. | |
5203 | */ | |
5204 | if (intel_crtc->config->has_pch_encoder) | |
5205 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
5206 | ||
575f7ab7 | 5207 | intel_disable_pipe(intel_crtc); |
32f9d658 | 5208 | |
bfd16b2a | 5209 | ironlake_pfit_disable(intel_crtc, false); |
2c07245f | 5210 | |
3860b2ec | 5211 | if (intel_crtc->config->has_pch_encoder) { |
5a74f70a | 5212 | ironlake_fdi_disable(crtc); |
3860b2ec VS |
5213 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
5214 | } | |
5a74f70a | 5215 | |
bf49ec8c DV |
5216 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5217 | if (encoder->post_disable) | |
5218 | encoder->post_disable(encoder); | |
2c07245f | 5219 | |
6e3c9717 | 5220 | if (intel_crtc->config->has_pch_encoder) { |
d925c59a | 5221 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
6be4a607 | 5222 | |
d925c59a | 5223 | if (HAS_PCH_CPT(dev)) { |
f0f59a00 VS |
5224 | i915_reg_t reg; |
5225 | u32 temp; | |
5226 | ||
d925c59a DV |
5227 | /* disable TRANS_DP_CTL */ |
5228 | reg = TRANS_DP_CTL(pipe); | |
5229 | temp = I915_READ(reg); | |
5230 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | | |
5231 | TRANS_DP_PORT_SEL_MASK); | |
5232 | temp |= TRANS_DP_PORT_SEL_NONE; | |
5233 | I915_WRITE(reg, temp); | |
5234 | ||
5235 | /* disable DPLL_SEL */ | |
5236 | temp = I915_READ(PCH_DPLL_SEL); | |
11887397 | 5237 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
d925c59a | 5238 | I915_WRITE(PCH_DPLL_SEL, temp); |
9db4a9c7 | 5239 | } |
e3421a18 | 5240 | |
d925c59a DV |
5241 | ironlake_fdi_pll_disable(intel_crtc); |
5242 | } | |
81b088ca VS |
5243 | |
5244 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); | |
6be4a607 | 5245 | } |
1b3c7a47 | 5246 | |
4f771f10 | 5247 | static void haswell_crtc_disable(struct drm_crtc *crtc) |
ee7b9f93 | 5248 | { |
4f771f10 PZ |
5249 | struct drm_device *dev = crtc->dev; |
5250 | struct drm_i915_private *dev_priv = dev->dev_private; | |
ee7b9f93 | 5251 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
4f771f10 | 5252 | struct intel_encoder *encoder; |
6e3c9717 | 5253 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
ee7b9f93 | 5254 | |
d2d65408 VS |
5255 | if (intel_crtc->config->has_pch_encoder) |
5256 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, | |
5257 | false); | |
5258 | ||
8807e55b JN |
5259 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
5260 | intel_opregion_notify_encoder(encoder, false); | |
4f771f10 | 5261 | encoder->disable(encoder); |
8807e55b | 5262 | } |
4f771f10 | 5263 | |
f9b61ff6 DV |
5264 | drm_crtc_vblank_off(crtc); |
5265 | assert_vblank_disabled(crtc); | |
5266 | ||
575f7ab7 | 5267 | intel_disable_pipe(intel_crtc); |
4f771f10 | 5268 | |
6e3c9717 | 5269 | if (intel_crtc->config->dp_encoder_is_mst) |
a4bf214f VS |
5270 | intel_ddi_set_vc_payload_alloc(crtc, false); |
5271 | ||
a65347ba | 5272 | if (!intel_crtc->config->has_dsi_encoder) |
7d4aefd0 | 5273 | intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder); |
4f771f10 | 5274 | |
1c132b44 | 5275 | if (INTEL_INFO(dev)->gen >= 9) |
e435d6e5 | 5276 | skylake_scaler_disable(intel_crtc); |
ff6d9f55 | 5277 | else |
bfd16b2a | 5278 | ironlake_pfit_disable(intel_crtc, false); |
4f771f10 | 5279 | |
a65347ba | 5280 | if (!intel_crtc->config->has_dsi_encoder) |
7d4aefd0 | 5281 | intel_ddi_disable_pipe_clock(intel_crtc); |
4f771f10 | 5282 | |
97b040aa ID |
5283 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5284 | if (encoder->post_disable) | |
5285 | encoder->post_disable(encoder); | |
81b088ca | 5286 | |
92966a37 VS |
5287 | if (intel_crtc->config->has_pch_encoder) { |
5288 | lpt_disable_pch_transcoder(dev_priv); | |
503a74e9 | 5289 | lpt_disable_iclkip(dev_priv); |
92966a37 VS |
5290 | intel_ddi_fdi_disable(crtc); |
5291 | ||
81b088ca VS |
5292 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
5293 | true); | |
92966a37 | 5294 | } |
4f771f10 PZ |
5295 | } |
5296 | ||
2dd24552 JB |
5297 | static void i9xx_pfit_enable(struct intel_crtc *crtc) |
5298 | { | |
5299 | struct drm_device *dev = crtc->base.dev; | |
5300 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6e3c9717 | 5301 | struct intel_crtc_state *pipe_config = crtc->config; |
2dd24552 | 5302 | |
681a8504 | 5303 | if (!pipe_config->gmch_pfit.control) |
2dd24552 JB |
5304 | return; |
5305 | ||
2dd24552 | 5306 | /* |
c0b03411 DV |
5307 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
5308 | * according to register description and PRM. | |
2dd24552 | 5309 | */ |
c0b03411 DV |
5310 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
5311 | assert_pipe_disabled(dev_priv, crtc->pipe); | |
2dd24552 | 5312 | |
b074cec8 JB |
5313 | I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios); |
5314 | I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control); | |
5a80c45c DV |
5315 | |
5316 | /* Border color in case we don't scale up to the full screen. Black by | |
5317 | * default, change to something else for debugging. */ | |
5318 | I915_WRITE(BCLRPAT(crtc->pipe), 0); | |
2dd24552 JB |
5319 | } |
5320 | ||
d05410f9 DA |
5321 | static enum intel_display_power_domain port_to_power_domain(enum port port) |
5322 | { | |
5323 | switch (port) { | |
5324 | case PORT_A: | |
6331a704 | 5325 | return POWER_DOMAIN_PORT_DDI_A_LANES; |
d05410f9 | 5326 | case PORT_B: |
6331a704 | 5327 | return POWER_DOMAIN_PORT_DDI_B_LANES; |
d05410f9 | 5328 | case PORT_C: |
6331a704 | 5329 | return POWER_DOMAIN_PORT_DDI_C_LANES; |
d05410f9 | 5330 | case PORT_D: |
6331a704 | 5331 | return POWER_DOMAIN_PORT_DDI_D_LANES; |
d8e19f99 | 5332 | case PORT_E: |
6331a704 | 5333 | return POWER_DOMAIN_PORT_DDI_E_LANES; |
d05410f9 | 5334 | default: |
b9fec167 | 5335 | MISSING_CASE(port); |
d05410f9 DA |
5336 | return POWER_DOMAIN_PORT_OTHER; |
5337 | } | |
5338 | } | |
5339 | ||
25f78f58 VS |
5340 | static enum intel_display_power_domain port_to_aux_power_domain(enum port port) |
5341 | { | |
5342 | switch (port) { | |
5343 | case PORT_A: | |
5344 | return POWER_DOMAIN_AUX_A; | |
5345 | case PORT_B: | |
5346 | return POWER_DOMAIN_AUX_B; | |
5347 | case PORT_C: | |
5348 | return POWER_DOMAIN_AUX_C; | |
5349 | case PORT_D: | |
5350 | return POWER_DOMAIN_AUX_D; | |
5351 | case PORT_E: | |
5352 | /* FIXME: Check VBT for actual wiring of PORT E */ | |
5353 | return POWER_DOMAIN_AUX_D; | |
5354 | default: | |
b9fec167 | 5355 | MISSING_CASE(port); |
25f78f58 VS |
5356 | return POWER_DOMAIN_AUX_A; |
5357 | } | |
5358 | } | |
5359 | ||
319be8ae ID |
5360 | enum intel_display_power_domain |
5361 | intel_display_port_power_domain(struct intel_encoder *intel_encoder) | |
5362 | { | |
5363 | struct drm_device *dev = intel_encoder->base.dev; | |
5364 | struct intel_digital_port *intel_dig_port; | |
5365 | ||
5366 | switch (intel_encoder->type) { | |
5367 | case INTEL_OUTPUT_UNKNOWN: | |
5368 | /* Only DDI platforms should ever use this output type */ | |
5369 | WARN_ON_ONCE(!HAS_DDI(dev)); | |
5370 | case INTEL_OUTPUT_DISPLAYPORT: | |
5371 | case INTEL_OUTPUT_HDMI: | |
5372 | case INTEL_OUTPUT_EDP: | |
5373 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); | |
d05410f9 | 5374 | return port_to_power_domain(intel_dig_port->port); |
0e32b39c DA |
5375 | case INTEL_OUTPUT_DP_MST: |
5376 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; | |
5377 | return port_to_power_domain(intel_dig_port->port); | |
319be8ae ID |
5378 | case INTEL_OUTPUT_ANALOG: |
5379 | return POWER_DOMAIN_PORT_CRT; | |
5380 | case INTEL_OUTPUT_DSI: | |
5381 | return POWER_DOMAIN_PORT_DSI; | |
5382 | default: | |
5383 | return POWER_DOMAIN_PORT_OTHER; | |
5384 | } | |
5385 | } | |
5386 | ||
25f78f58 VS |
5387 | enum intel_display_power_domain |
5388 | intel_display_port_aux_power_domain(struct intel_encoder *intel_encoder) | |
5389 | { | |
5390 | struct drm_device *dev = intel_encoder->base.dev; | |
5391 | struct intel_digital_port *intel_dig_port; | |
5392 | ||
5393 | switch (intel_encoder->type) { | |
5394 | case INTEL_OUTPUT_UNKNOWN: | |
651174a4 ID |
5395 | case INTEL_OUTPUT_HDMI: |
5396 | /* | |
5397 | * Only DDI platforms should ever use these output types. | |
5398 | * We can get here after the HDMI detect code has already set | |
5399 | * the type of the shared encoder. Since we can't be sure | |
5400 | * what's the status of the given connectors, play safe and | |
5401 | * run the DP detection too. | |
5402 | */ | |
25f78f58 VS |
5403 | WARN_ON_ONCE(!HAS_DDI(dev)); |
5404 | case INTEL_OUTPUT_DISPLAYPORT: | |
5405 | case INTEL_OUTPUT_EDP: | |
5406 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); | |
5407 | return port_to_aux_power_domain(intel_dig_port->port); | |
5408 | case INTEL_OUTPUT_DP_MST: | |
5409 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; | |
5410 | return port_to_aux_power_domain(intel_dig_port->port); | |
5411 | default: | |
b9fec167 | 5412 | MISSING_CASE(intel_encoder->type); |
25f78f58 VS |
5413 | return POWER_DOMAIN_AUX_A; |
5414 | } | |
5415 | } | |
5416 | ||
74bff5f9 ML |
5417 | static unsigned long get_crtc_power_domains(struct drm_crtc *crtc, |
5418 | struct intel_crtc_state *crtc_state) | |
77d22dca | 5419 | { |
319be8ae | 5420 | struct drm_device *dev = crtc->dev; |
74bff5f9 | 5421 | struct drm_encoder *encoder; |
319be8ae ID |
5422 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
5423 | enum pipe pipe = intel_crtc->pipe; | |
77d22dca | 5424 | unsigned long mask; |
74bff5f9 | 5425 | enum transcoder transcoder = crtc_state->cpu_transcoder; |
77d22dca | 5426 | |
74bff5f9 | 5427 | if (!crtc_state->base.active) |
292b990e ML |
5428 | return 0; |
5429 | ||
77d22dca ID |
5430 | mask = BIT(POWER_DOMAIN_PIPE(pipe)); |
5431 | mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder)); | |
74bff5f9 ML |
5432 | if (crtc_state->pch_pfit.enabled || |
5433 | crtc_state->pch_pfit.force_thru) | |
77d22dca ID |
5434 | mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
5435 | ||
74bff5f9 ML |
5436 | drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) { |
5437 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); | |
5438 | ||
319be8ae | 5439 | mask |= BIT(intel_display_port_power_domain(intel_encoder)); |
74bff5f9 | 5440 | } |
319be8ae | 5441 | |
77d22dca ID |
5442 | return mask; |
5443 | } | |
5444 | ||
74bff5f9 ML |
5445 | static unsigned long |
5446 | modeset_get_crtc_power_domains(struct drm_crtc *crtc, | |
5447 | struct intel_crtc_state *crtc_state) | |
77d22dca | 5448 | { |
292b990e ML |
5449 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
5450 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
5451 | enum intel_display_power_domain domain; | |
5452 | unsigned long domains, new_domains, old_domains; | |
77d22dca | 5453 | |
292b990e | 5454 | old_domains = intel_crtc->enabled_power_domains; |
74bff5f9 ML |
5455 | intel_crtc->enabled_power_domains = new_domains = |
5456 | get_crtc_power_domains(crtc, crtc_state); | |
77d22dca | 5457 | |
292b990e ML |
5458 | domains = new_domains & ~old_domains; |
5459 | ||
5460 | for_each_power_domain(domain, domains) | |
5461 | intel_display_power_get(dev_priv, domain); | |
5462 | ||
5463 | return old_domains & ~new_domains; | |
5464 | } | |
5465 | ||
5466 | static void modeset_put_power_domains(struct drm_i915_private *dev_priv, | |
5467 | unsigned long domains) | |
5468 | { | |
5469 | enum intel_display_power_domain domain; | |
5470 | ||
5471 | for_each_power_domain(domain, domains) | |
5472 | intel_display_power_put(dev_priv, domain); | |
5473 | } | |
77d22dca | 5474 | |
adafdc6f MK |
5475 | static int intel_compute_max_dotclk(struct drm_i915_private *dev_priv) |
5476 | { | |
5477 | int max_cdclk_freq = dev_priv->max_cdclk_freq; | |
5478 | ||
5479 | if (INTEL_INFO(dev_priv)->gen >= 9 || | |
5480 | IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) | |
5481 | return max_cdclk_freq; | |
5482 | else if (IS_CHERRYVIEW(dev_priv)) | |
5483 | return max_cdclk_freq*95/100; | |
5484 | else if (INTEL_INFO(dev_priv)->gen < 4) | |
5485 | return 2*max_cdclk_freq*90/100; | |
5486 | else | |
5487 | return max_cdclk_freq*90/100; | |
5488 | } | |
5489 | ||
560a7ae4 DL |
5490 | static void intel_update_max_cdclk(struct drm_device *dev) |
5491 | { | |
5492 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5493 | ||
ef11bdb3 | 5494 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) { |
560a7ae4 DL |
5495 | u32 limit = I915_READ(SKL_DFSM) & SKL_DFSM_CDCLK_LIMIT_MASK; |
5496 | ||
5497 | if (limit == SKL_DFSM_CDCLK_LIMIT_675) | |
5498 | dev_priv->max_cdclk_freq = 675000; | |
5499 | else if (limit == SKL_DFSM_CDCLK_LIMIT_540) | |
5500 | dev_priv->max_cdclk_freq = 540000; | |
5501 | else if (limit == SKL_DFSM_CDCLK_LIMIT_450) | |
5502 | dev_priv->max_cdclk_freq = 450000; | |
5503 | else | |
5504 | dev_priv->max_cdclk_freq = 337500; | |
5505 | } else if (IS_BROADWELL(dev)) { | |
5506 | /* | |
5507 | * FIXME with extra cooling we can allow | |
5508 | * 540 MHz for ULX and 675 Mhz for ULT. | |
5509 | * How can we know if extra cooling is | |
5510 | * available? PCI ID, VTB, something else? | |
5511 | */ | |
5512 | if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
5513 | dev_priv->max_cdclk_freq = 450000; | |
5514 | else if (IS_BDW_ULX(dev)) | |
5515 | dev_priv->max_cdclk_freq = 450000; | |
5516 | else if (IS_BDW_ULT(dev)) | |
5517 | dev_priv->max_cdclk_freq = 540000; | |
5518 | else | |
5519 | dev_priv->max_cdclk_freq = 675000; | |
0904deaf MK |
5520 | } else if (IS_CHERRYVIEW(dev)) { |
5521 | dev_priv->max_cdclk_freq = 320000; | |
560a7ae4 DL |
5522 | } else if (IS_VALLEYVIEW(dev)) { |
5523 | dev_priv->max_cdclk_freq = 400000; | |
5524 | } else { | |
5525 | /* otherwise assume cdclk is fixed */ | |
5526 | dev_priv->max_cdclk_freq = dev_priv->cdclk_freq; | |
5527 | } | |
5528 | ||
adafdc6f MK |
5529 | dev_priv->max_dotclk_freq = intel_compute_max_dotclk(dev_priv); |
5530 | ||
560a7ae4 DL |
5531 | DRM_DEBUG_DRIVER("Max CD clock rate: %d kHz\n", |
5532 | dev_priv->max_cdclk_freq); | |
adafdc6f MK |
5533 | |
5534 | DRM_DEBUG_DRIVER("Max dotclock rate: %d kHz\n", | |
5535 | dev_priv->max_dotclk_freq); | |
560a7ae4 DL |
5536 | } |
5537 | ||
5538 | static void intel_update_cdclk(struct drm_device *dev) | |
5539 | { | |
5540 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5541 | ||
5542 | dev_priv->cdclk_freq = dev_priv->display.get_display_clock_speed(dev); | |
5543 | DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n", | |
5544 | dev_priv->cdclk_freq); | |
5545 | ||
5546 | /* | |
5547 | * Program the gmbus_freq based on the cdclk frequency. | |
5548 | * BSpec erroneously claims we should aim for 4MHz, but | |
5549 | * in fact 1MHz is the correct frequency. | |
5550 | */ | |
666a4537 | 5551 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
560a7ae4 DL |
5552 | /* |
5553 | * Program the gmbus_freq based on the cdclk frequency. | |
5554 | * BSpec erroneously claims we should aim for 4MHz, but | |
5555 | * in fact 1MHz is the correct frequency. | |
5556 | */ | |
5557 | I915_WRITE(GMBUSFREQ_VLV, DIV_ROUND_UP(dev_priv->cdclk_freq, 1000)); | |
5558 | } | |
5559 | ||
5560 | if (dev_priv->max_cdclk_freq == 0) | |
5561 | intel_update_max_cdclk(dev); | |
5562 | } | |
5563 | ||
70d0c574 | 5564 | static void broxton_set_cdclk(struct drm_device *dev, int frequency) |
f8437dd1 VK |
5565 | { |
5566 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5567 | uint32_t divider; | |
5568 | uint32_t ratio; | |
5569 | uint32_t current_freq; | |
5570 | int ret; | |
5571 | ||
5572 | /* frequency = 19.2MHz * ratio / 2 / div{1,1.5,2,4} */ | |
5573 | switch (frequency) { | |
5574 | case 144000: | |
5575 | divider = BXT_CDCLK_CD2X_DIV_SEL_4; | |
5576 | ratio = BXT_DE_PLL_RATIO(60); | |
5577 | break; | |
5578 | case 288000: | |
5579 | divider = BXT_CDCLK_CD2X_DIV_SEL_2; | |
5580 | ratio = BXT_DE_PLL_RATIO(60); | |
5581 | break; | |
5582 | case 384000: | |
5583 | divider = BXT_CDCLK_CD2X_DIV_SEL_1_5; | |
5584 | ratio = BXT_DE_PLL_RATIO(60); | |
5585 | break; | |
5586 | case 576000: | |
5587 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; | |
5588 | ratio = BXT_DE_PLL_RATIO(60); | |
5589 | break; | |
5590 | case 624000: | |
5591 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; | |
5592 | ratio = BXT_DE_PLL_RATIO(65); | |
5593 | break; | |
5594 | case 19200: | |
5595 | /* | |
5596 | * Bypass frequency with DE PLL disabled. Init ratio, divider | |
5597 | * to suppress GCC warning. | |
5598 | */ | |
5599 | ratio = 0; | |
5600 | divider = 0; | |
5601 | break; | |
5602 | default: | |
5603 | DRM_ERROR("unsupported CDCLK freq %d", frequency); | |
5604 | ||
5605 | return; | |
5606 | } | |
5607 | ||
5608 | mutex_lock(&dev_priv->rps.hw_lock); | |
5609 | /* Inform power controller of upcoming frequency change */ | |
5610 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, | |
5611 | 0x80000000); | |
5612 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5613 | ||
5614 | if (ret) { | |
5615 | DRM_ERROR("PCode CDCLK freq change notify failed (err %d, freq %d)\n", | |
5616 | ret, frequency); | |
5617 | return; | |
5618 | } | |
5619 | ||
5620 | current_freq = I915_READ(CDCLK_CTL) & CDCLK_FREQ_DECIMAL_MASK; | |
5621 | /* convert from .1 fixpoint MHz with -1MHz offset to kHz */ | |
5622 | current_freq = current_freq * 500 + 1000; | |
5623 | ||
5624 | /* | |
5625 | * DE PLL has to be disabled when | |
5626 | * - setting to 19.2MHz (bypass, PLL isn't used) | |
5627 | * - before setting to 624MHz (PLL needs toggling) | |
5628 | * - before setting to any frequency from 624MHz (PLL needs toggling) | |
5629 | */ | |
5630 | if (frequency == 19200 || frequency == 624000 || | |
5631 | current_freq == 624000) { | |
5632 | I915_WRITE(BXT_DE_PLL_ENABLE, ~BXT_DE_PLL_PLL_ENABLE); | |
5633 | /* Timeout 200us */ | |
5634 | if (wait_for(!(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK), | |
5635 | 1)) | |
5636 | DRM_ERROR("timout waiting for DE PLL unlock\n"); | |
5637 | } | |
5638 | ||
5639 | if (frequency != 19200) { | |
5640 | uint32_t val; | |
5641 | ||
5642 | val = I915_READ(BXT_DE_PLL_CTL); | |
5643 | val &= ~BXT_DE_PLL_RATIO_MASK; | |
5644 | val |= ratio; | |
5645 | I915_WRITE(BXT_DE_PLL_CTL, val); | |
5646 | ||
5647 | I915_WRITE(BXT_DE_PLL_ENABLE, BXT_DE_PLL_PLL_ENABLE); | |
5648 | /* Timeout 200us */ | |
5649 | if (wait_for(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK, 1)) | |
5650 | DRM_ERROR("timeout waiting for DE PLL lock\n"); | |
5651 | ||
5652 | val = I915_READ(CDCLK_CTL); | |
5653 | val &= ~BXT_CDCLK_CD2X_DIV_SEL_MASK; | |
5654 | val |= divider; | |
5655 | /* | |
5656 | * Disable SSA Precharge when CD clock frequency < 500 MHz, | |
5657 | * enable otherwise. | |
5658 | */ | |
5659 | val &= ~BXT_CDCLK_SSA_PRECHARGE_ENABLE; | |
5660 | if (frequency >= 500000) | |
5661 | val |= BXT_CDCLK_SSA_PRECHARGE_ENABLE; | |
5662 | ||
5663 | val &= ~CDCLK_FREQ_DECIMAL_MASK; | |
5664 | /* convert from kHz to .1 fixpoint MHz with -1MHz offset */ | |
5665 | val |= (frequency - 1000) / 500; | |
5666 | I915_WRITE(CDCLK_CTL, val); | |
5667 | } | |
5668 | ||
5669 | mutex_lock(&dev_priv->rps.hw_lock); | |
5670 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, | |
5671 | DIV_ROUND_UP(frequency, 25000)); | |
5672 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5673 | ||
5674 | if (ret) { | |
5675 | DRM_ERROR("PCode CDCLK freq set failed, (err %d, freq %d)\n", | |
5676 | ret, frequency); | |
5677 | return; | |
5678 | } | |
5679 | ||
a47871bd | 5680 | intel_update_cdclk(dev); |
f8437dd1 VK |
5681 | } |
5682 | ||
5683 | void broxton_init_cdclk(struct drm_device *dev) | |
5684 | { | |
5685 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5686 | uint32_t val; | |
5687 | ||
5688 | /* | |
5689 | * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT | |
5690 | * or else the reset will hang because there is no PCH to respond. | |
5691 | * Move the handshake programming to initialization sequence. | |
5692 | * Previously was left up to BIOS. | |
5693 | */ | |
5694 | val = I915_READ(HSW_NDE_RSTWRN_OPT); | |
5695 | val &= ~RESET_PCH_HANDSHAKE_ENABLE; | |
5696 | I915_WRITE(HSW_NDE_RSTWRN_OPT, val); | |
5697 | ||
5698 | /* Enable PG1 for cdclk */ | |
5699 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); | |
5700 | ||
5701 | /* check if cd clock is enabled */ | |
5702 | if (I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_PLL_ENABLE) { | |
5703 | DRM_DEBUG_KMS("Display already initialized\n"); | |
5704 | return; | |
5705 | } | |
5706 | ||
5707 | /* | |
5708 | * FIXME: | |
5709 | * - The initial CDCLK needs to be read from VBT. | |
5710 | * Need to make this change after VBT has changes for BXT. | |
5711 | * - check if setting the max (or any) cdclk freq is really necessary | |
5712 | * here, it belongs to modeset time | |
5713 | */ | |
5714 | broxton_set_cdclk(dev, 624000); | |
5715 | ||
5716 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); | |
22e02c0b VS |
5717 | POSTING_READ(DBUF_CTL); |
5718 | ||
f8437dd1 VK |
5719 | udelay(10); |
5720 | ||
5721 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) | |
5722 | DRM_ERROR("DBuf power enable timeout!\n"); | |
5723 | } | |
5724 | ||
5725 | void broxton_uninit_cdclk(struct drm_device *dev) | |
5726 | { | |
5727 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5728 | ||
5729 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST); | |
22e02c0b VS |
5730 | POSTING_READ(DBUF_CTL); |
5731 | ||
f8437dd1 VK |
5732 | udelay(10); |
5733 | ||
5734 | if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE) | |
5735 | DRM_ERROR("DBuf power disable timeout!\n"); | |
5736 | ||
5737 | /* Set minimum (bypass) frequency, in effect turning off the DE PLL */ | |
5738 | broxton_set_cdclk(dev, 19200); | |
5739 | ||
5740 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); | |
5741 | } | |
5742 | ||
5d96d8af DL |
5743 | static const struct skl_cdclk_entry { |
5744 | unsigned int freq; | |
5745 | unsigned int vco; | |
5746 | } skl_cdclk_frequencies[] = { | |
5747 | { .freq = 308570, .vco = 8640 }, | |
5748 | { .freq = 337500, .vco = 8100 }, | |
5749 | { .freq = 432000, .vco = 8640 }, | |
5750 | { .freq = 450000, .vco = 8100 }, | |
5751 | { .freq = 540000, .vco = 8100 }, | |
5752 | { .freq = 617140, .vco = 8640 }, | |
5753 | { .freq = 675000, .vco = 8100 }, | |
5754 | }; | |
5755 | ||
5756 | static unsigned int skl_cdclk_decimal(unsigned int freq) | |
5757 | { | |
5758 | return (freq - 1000) / 500; | |
5759 | } | |
5760 | ||
5761 | static unsigned int skl_cdclk_get_vco(unsigned int freq) | |
5762 | { | |
5763 | unsigned int i; | |
5764 | ||
5765 | for (i = 0; i < ARRAY_SIZE(skl_cdclk_frequencies); i++) { | |
5766 | const struct skl_cdclk_entry *e = &skl_cdclk_frequencies[i]; | |
5767 | ||
5768 | if (e->freq == freq) | |
5769 | return e->vco; | |
5770 | } | |
5771 | ||
5772 | return 8100; | |
5773 | } | |
5774 | ||
5775 | static void | |
5776 | skl_dpll0_enable(struct drm_i915_private *dev_priv, unsigned int required_vco) | |
5777 | { | |
5778 | unsigned int min_freq; | |
5779 | u32 val; | |
5780 | ||
5781 | /* select the minimum CDCLK before enabling DPLL 0 */ | |
5782 | val = I915_READ(CDCLK_CTL); | |
5783 | val &= ~CDCLK_FREQ_SEL_MASK | ~CDCLK_FREQ_DECIMAL_MASK; | |
5784 | val |= CDCLK_FREQ_337_308; | |
5785 | ||
5786 | if (required_vco == 8640) | |
5787 | min_freq = 308570; | |
5788 | else | |
5789 | min_freq = 337500; | |
5790 | ||
5791 | val = CDCLK_FREQ_337_308 | skl_cdclk_decimal(min_freq); | |
5792 | ||
5793 | I915_WRITE(CDCLK_CTL, val); | |
5794 | POSTING_READ(CDCLK_CTL); | |
5795 | ||
5796 | /* | |
5797 | * We always enable DPLL0 with the lowest link rate possible, but still | |
5798 | * taking into account the VCO required to operate the eDP panel at the | |
5799 | * desired frequency. The usual DP link rates operate with a VCO of | |
5800 | * 8100 while the eDP 1.4 alternate link rates need a VCO of 8640. | |
5801 | * The modeset code is responsible for the selection of the exact link | |
5802 | * rate later on, with the constraint of choosing a frequency that | |
5803 | * works with required_vco. | |
5804 | */ | |
5805 | val = I915_READ(DPLL_CTRL1); | |
5806 | ||
5807 | val &= ~(DPLL_CTRL1_HDMI_MODE(SKL_DPLL0) | DPLL_CTRL1_SSC(SKL_DPLL0) | | |
5808 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)); | |
5809 | val |= DPLL_CTRL1_OVERRIDE(SKL_DPLL0); | |
5810 | if (required_vco == 8640) | |
5811 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080, | |
5812 | SKL_DPLL0); | |
5813 | else | |
5814 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810, | |
5815 | SKL_DPLL0); | |
5816 | ||
5817 | I915_WRITE(DPLL_CTRL1, val); | |
5818 | POSTING_READ(DPLL_CTRL1); | |
5819 | ||
5820 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) | LCPLL_PLL_ENABLE); | |
5821 | ||
5822 | if (wait_for(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK, 5)) | |
5823 | DRM_ERROR("DPLL0 not locked\n"); | |
5824 | } | |
5825 | ||
5826 | static bool skl_cdclk_pcu_ready(struct drm_i915_private *dev_priv) | |
5827 | { | |
5828 | int ret; | |
5829 | u32 val; | |
5830 | ||
5831 | /* inform PCU we want to change CDCLK */ | |
5832 | val = SKL_CDCLK_PREPARE_FOR_CHANGE; | |
5833 | mutex_lock(&dev_priv->rps.hw_lock); | |
5834 | ret = sandybridge_pcode_read(dev_priv, SKL_PCODE_CDCLK_CONTROL, &val); | |
5835 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5836 | ||
5837 | return ret == 0 && (val & SKL_CDCLK_READY_FOR_CHANGE); | |
5838 | } | |
5839 | ||
5840 | static bool skl_cdclk_wait_for_pcu_ready(struct drm_i915_private *dev_priv) | |
5841 | { | |
5842 | unsigned int i; | |
5843 | ||
5844 | for (i = 0; i < 15; i++) { | |
5845 | if (skl_cdclk_pcu_ready(dev_priv)) | |
5846 | return true; | |
5847 | udelay(10); | |
5848 | } | |
5849 | ||
5850 | return false; | |
5851 | } | |
5852 | ||
5853 | static void skl_set_cdclk(struct drm_i915_private *dev_priv, unsigned int freq) | |
5854 | { | |
560a7ae4 | 5855 | struct drm_device *dev = dev_priv->dev; |
5d96d8af DL |
5856 | u32 freq_select, pcu_ack; |
5857 | ||
5858 | DRM_DEBUG_DRIVER("Changing CDCLK to %dKHz\n", freq); | |
5859 | ||
5860 | if (!skl_cdclk_wait_for_pcu_ready(dev_priv)) { | |
5861 | DRM_ERROR("failed to inform PCU about cdclk change\n"); | |
5862 | return; | |
5863 | } | |
5864 | ||
5865 | /* set CDCLK_CTL */ | |
5866 | switch(freq) { | |
5867 | case 450000: | |
5868 | case 432000: | |
5869 | freq_select = CDCLK_FREQ_450_432; | |
5870 | pcu_ack = 1; | |
5871 | break; | |
5872 | case 540000: | |
5873 | freq_select = CDCLK_FREQ_540; | |
5874 | pcu_ack = 2; | |
5875 | break; | |
5876 | case 308570: | |
5877 | case 337500: | |
5878 | default: | |
5879 | freq_select = CDCLK_FREQ_337_308; | |
5880 | pcu_ack = 0; | |
5881 | break; | |
5882 | case 617140: | |
5883 | case 675000: | |
5884 | freq_select = CDCLK_FREQ_675_617; | |
5885 | pcu_ack = 3; | |
5886 | break; | |
5887 | } | |
5888 | ||
5889 | I915_WRITE(CDCLK_CTL, freq_select | skl_cdclk_decimal(freq)); | |
5890 | POSTING_READ(CDCLK_CTL); | |
5891 | ||
5892 | /* inform PCU of the change */ | |
5893 | mutex_lock(&dev_priv->rps.hw_lock); | |
5894 | sandybridge_pcode_write(dev_priv, SKL_PCODE_CDCLK_CONTROL, pcu_ack); | |
5895 | mutex_unlock(&dev_priv->rps.hw_lock); | |
560a7ae4 DL |
5896 | |
5897 | intel_update_cdclk(dev); | |
5d96d8af DL |
5898 | } |
5899 | ||
5900 | void skl_uninit_cdclk(struct drm_i915_private *dev_priv) | |
5901 | { | |
5902 | /* disable DBUF power */ | |
5903 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST); | |
5904 | POSTING_READ(DBUF_CTL); | |
5905 | ||
5906 | udelay(10); | |
5907 | ||
5908 | if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE) | |
5909 | DRM_ERROR("DBuf power disable timeout\n"); | |
5910 | ||
ab96c1ee ID |
5911 | /* disable DPLL0 */ |
5912 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) & ~LCPLL_PLL_ENABLE); | |
5913 | if (wait_for(!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK), 1)) | |
5914 | DRM_ERROR("Couldn't disable DPLL0\n"); | |
5d96d8af DL |
5915 | } |
5916 | ||
5917 | void skl_init_cdclk(struct drm_i915_private *dev_priv) | |
5918 | { | |
5d96d8af DL |
5919 | unsigned int required_vco; |
5920 | ||
39d9b85a GW |
5921 | /* DPLL0 not enabled (happens on early BIOS versions) */ |
5922 | if (!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_ENABLE)) { | |
5923 | /* enable DPLL0 */ | |
5924 | required_vco = skl_cdclk_get_vco(dev_priv->skl_boot_cdclk); | |
5925 | skl_dpll0_enable(dev_priv, required_vco); | |
5d96d8af DL |
5926 | } |
5927 | ||
5d96d8af DL |
5928 | /* set CDCLK to the frequency the BIOS chose */ |
5929 | skl_set_cdclk(dev_priv, dev_priv->skl_boot_cdclk); | |
5930 | ||
5931 | /* enable DBUF power */ | |
5932 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); | |
5933 | POSTING_READ(DBUF_CTL); | |
5934 | ||
5935 | udelay(10); | |
5936 | ||
5937 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) | |
5938 | DRM_ERROR("DBuf power enable timeout\n"); | |
5939 | } | |
5940 | ||
c73666f3 SK |
5941 | int skl_sanitize_cdclk(struct drm_i915_private *dev_priv) |
5942 | { | |
5943 | uint32_t lcpll1 = I915_READ(LCPLL1_CTL); | |
5944 | uint32_t cdctl = I915_READ(CDCLK_CTL); | |
5945 | int freq = dev_priv->skl_boot_cdclk; | |
5946 | ||
f1b391a5 SK |
5947 | /* |
5948 | * check if the pre-os intialized the display | |
5949 | * There is SWF18 scratchpad register defined which is set by the | |
5950 | * pre-os which can be used by the OS drivers to check the status | |
5951 | */ | |
5952 | if ((I915_READ(SWF_ILK(0x18)) & 0x00FFFFFF) == 0) | |
5953 | goto sanitize; | |
5954 | ||
c73666f3 SK |
5955 | /* Is PLL enabled and locked ? */ |
5956 | if (!((lcpll1 & LCPLL_PLL_ENABLE) && (lcpll1 & LCPLL_PLL_LOCK))) | |
5957 | goto sanitize; | |
5958 | ||
5959 | /* DPLL okay; verify the cdclock | |
5960 | * | |
5961 | * Noticed in some instances that the freq selection is correct but | |
5962 | * decimal part is programmed wrong from BIOS where pre-os does not | |
5963 | * enable display. Verify the same as well. | |
5964 | */ | |
5965 | if (cdctl == ((cdctl & CDCLK_FREQ_SEL_MASK) | skl_cdclk_decimal(freq))) | |
5966 | /* All well; nothing to sanitize */ | |
5967 | return false; | |
5968 | sanitize: | |
5969 | /* | |
5970 | * As of now initialize with max cdclk till | |
5971 | * we get dynamic cdclk support | |
5972 | * */ | |
5973 | dev_priv->skl_boot_cdclk = dev_priv->max_cdclk_freq; | |
5974 | skl_init_cdclk(dev_priv); | |
5975 | ||
5976 | /* we did have to sanitize */ | |
5977 | return true; | |
5978 | } | |
5979 | ||
30a970c6 JB |
5980 | /* Adjust CDclk dividers to allow high res or save power if possible */ |
5981 | static void valleyview_set_cdclk(struct drm_device *dev, int cdclk) | |
5982 | { | |
5983 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5984 | u32 val, cmd; | |
5985 | ||
164dfd28 VK |
5986 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
5987 | != dev_priv->cdclk_freq); | |
d60c4473 | 5988 | |
dfcab17e | 5989 | if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */ |
30a970c6 | 5990 | cmd = 2; |
dfcab17e | 5991 | else if (cdclk == 266667) |
30a970c6 JB |
5992 | cmd = 1; |
5993 | else | |
5994 | cmd = 0; | |
5995 | ||
5996 | mutex_lock(&dev_priv->rps.hw_lock); | |
5997 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); | |
5998 | val &= ~DSPFREQGUAR_MASK; | |
5999 | val |= (cmd << DSPFREQGUAR_SHIFT); | |
6000 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); | |
6001 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & | |
6002 | DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT), | |
6003 | 50)) { | |
6004 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
6005 | } | |
6006 | mutex_unlock(&dev_priv->rps.hw_lock); | |
6007 | ||
54433e91 VS |
6008 | mutex_lock(&dev_priv->sb_lock); |
6009 | ||
dfcab17e | 6010 | if (cdclk == 400000) { |
6bcda4f0 | 6011 | u32 divider; |
30a970c6 | 6012 | |
6bcda4f0 | 6013 | divider = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
30a970c6 | 6014 | |
30a970c6 JB |
6015 | /* adjust cdclk divider */ |
6016 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); | |
87d5d259 | 6017 | val &= ~CCK_FREQUENCY_VALUES; |
30a970c6 JB |
6018 | val |= divider; |
6019 | vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val); | |
a877e801 VS |
6020 | |
6021 | if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) & | |
87d5d259 | 6022 | CCK_FREQUENCY_STATUS) == (divider << CCK_FREQUENCY_STATUS_SHIFT), |
a877e801 VS |
6023 | 50)) |
6024 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
30a970c6 JB |
6025 | } |
6026 | ||
30a970c6 JB |
6027 | /* adjust self-refresh exit latency value */ |
6028 | val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC); | |
6029 | val &= ~0x7f; | |
6030 | ||
6031 | /* | |
6032 | * For high bandwidth configs, we set a higher latency in the bunit | |
6033 | * so that the core display fetch happens in time to avoid underruns. | |
6034 | */ | |
dfcab17e | 6035 | if (cdclk == 400000) |
30a970c6 JB |
6036 | val |= 4500 / 250; /* 4.5 usec */ |
6037 | else | |
6038 | val |= 3000 / 250; /* 3.0 usec */ | |
6039 | vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val); | |
54433e91 | 6040 | |
a580516d | 6041 | mutex_unlock(&dev_priv->sb_lock); |
30a970c6 | 6042 | |
b6283055 | 6043 | intel_update_cdclk(dev); |
30a970c6 JB |
6044 | } |
6045 | ||
383c5a6a VS |
6046 | static void cherryview_set_cdclk(struct drm_device *dev, int cdclk) |
6047 | { | |
6048 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6049 | u32 val, cmd; | |
6050 | ||
164dfd28 VK |
6051 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
6052 | != dev_priv->cdclk_freq); | |
383c5a6a VS |
6053 | |
6054 | switch (cdclk) { | |
383c5a6a VS |
6055 | case 333333: |
6056 | case 320000: | |
383c5a6a | 6057 | case 266667: |
383c5a6a | 6058 | case 200000: |
383c5a6a VS |
6059 | break; |
6060 | default: | |
5f77eeb0 | 6061 | MISSING_CASE(cdclk); |
383c5a6a VS |
6062 | return; |
6063 | } | |
6064 | ||
9d0d3fda VS |
6065 | /* |
6066 | * Specs are full of misinformation, but testing on actual | |
6067 | * hardware has shown that we just need to write the desired | |
6068 | * CCK divider into the Punit register. | |
6069 | */ | |
6070 | cmd = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; | |
6071 | ||
383c5a6a VS |
6072 | mutex_lock(&dev_priv->rps.hw_lock); |
6073 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); | |
6074 | val &= ~DSPFREQGUAR_MASK_CHV; | |
6075 | val |= (cmd << DSPFREQGUAR_SHIFT_CHV); | |
6076 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); | |
6077 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & | |
6078 | DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV), | |
6079 | 50)) { | |
6080 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
6081 | } | |
6082 | mutex_unlock(&dev_priv->rps.hw_lock); | |
6083 | ||
b6283055 | 6084 | intel_update_cdclk(dev); |
383c5a6a VS |
6085 | } |
6086 | ||
30a970c6 JB |
6087 | static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv, |
6088 | int max_pixclk) | |
6089 | { | |
6bcda4f0 | 6090 | int freq_320 = (dev_priv->hpll_freq << 1) % 320000 != 0 ? 333333 : 320000; |
6cca3195 | 6091 | int limit = IS_CHERRYVIEW(dev_priv) ? 95 : 90; |
29dc7ef3 | 6092 | |
30a970c6 JB |
6093 | /* |
6094 | * Really only a few cases to deal with, as only 4 CDclks are supported: | |
6095 | * 200MHz | |
6096 | * 267MHz | |
29dc7ef3 | 6097 | * 320/333MHz (depends on HPLL freq) |
6cca3195 VS |
6098 | * 400MHz (VLV only) |
6099 | * So we check to see whether we're above 90% (VLV) or 95% (CHV) | |
6100 | * of the lower bin and adjust if needed. | |
e37c67a1 VS |
6101 | * |
6102 | * We seem to get an unstable or solid color picture at 200MHz. | |
6103 | * Not sure what's wrong. For now use 200MHz only when all pipes | |
6104 | * are off. | |
30a970c6 | 6105 | */ |
6cca3195 VS |
6106 | if (!IS_CHERRYVIEW(dev_priv) && |
6107 | max_pixclk > freq_320*limit/100) | |
dfcab17e | 6108 | return 400000; |
6cca3195 | 6109 | else if (max_pixclk > 266667*limit/100) |
29dc7ef3 | 6110 | return freq_320; |
e37c67a1 | 6111 | else if (max_pixclk > 0) |
dfcab17e | 6112 | return 266667; |
e37c67a1 VS |
6113 | else |
6114 | return 200000; | |
30a970c6 JB |
6115 | } |
6116 | ||
f8437dd1 VK |
6117 | static int broxton_calc_cdclk(struct drm_i915_private *dev_priv, |
6118 | int max_pixclk) | |
6119 | { | |
6120 | /* | |
6121 | * FIXME: | |
6122 | * - remove the guardband, it's not needed on BXT | |
6123 | * - set 19.2MHz bypass frequency if there are no active pipes | |
6124 | */ | |
6125 | if (max_pixclk > 576000*9/10) | |
6126 | return 624000; | |
6127 | else if (max_pixclk > 384000*9/10) | |
6128 | return 576000; | |
6129 | else if (max_pixclk > 288000*9/10) | |
6130 | return 384000; | |
6131 | else if (max_pixclk > 144000*9/10) | |
6132 | return 288000; | |
6133 | else | |
6134 | return 144000; | |
6135 | } | |
6136 | ||
e8788cbc | 6137 | /* Compute the max pixel clock for new configuration. */ |
a821fc46 ACO |
6138 | static int intel_mode_max_pixclk(struct drm_device *dev, |
6139 | struct drm_atomic_state *state) | |
30a970c6 | 6140 | { |
565602d7 ML |
6141 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
6142 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6143 | struct drm_crtc *crtc; | |
6144 | struct drm_crtc_state *crtc_state; | |
6145 | unsigned max_pixclk = 0, i; | |
6146 | enum pipe pipe; | |
30a970c6 | 6147 | |
565602d7 ML |
6148 | memcpy(intel_state->min_pixclk, dev_priv->min_pixclk, |
6149 | sizeof(intel_state->min_pixclk)); | |
304603f4 | 6150 | |
565602d7 ML |
6151 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
6152 | int pixclk = 0; | |
6153 | ||
6154 | if (crtc_state->enable) | |
6155 | pixclk = crtc_state->adjusted_mode.crtc_clock; | |
304603f4 | 6156 | |
565602d7 | 6157 | intel_state->min_pixclk[i] = pixclk; |
30a970c6 JB |
6158 | } |
6159 | ||
565602d7 ML |
6160 | for_each_pipe(dev_priv, pipe) |
6161 | max_pixclk = max(intel_state->min_pixclk[pipe], max_pixclk); | |
6162 | ||
30a970c6 JB |
6163 | return max_pixclk; |
6164 | } | |
6165 | ||
27c329ed | 6166 | static int valleyview_modeset_calc_cdclk(struct drm_atomic_state *state) |
30a970c6 | 6167 | { |
27c329ed ML |
6168 | struct drm_device *dev = state->dev; |
6169 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6170 | int max_pixclk = intel_mode_max_pixclk(dev, state); | |
1a617b77 ML |
6171 | struct intel_atomic_state *intel_state = |
6172 | to_intel_atomic_state(state); | |
30a970c6 | 6173 | |
304603f4 ACO |
6174 | if (max_pixclk < 0) |
6175 | return max_pixclk; | |
30a970c6 | 6176 | |
1a617b77 | 6177 | intel_state->cdclk = intel_state->dev_cdclk = |
27c329ed | 6178 | valleyview_calc_cdclk(dev_priv, max_pixclk); |
0a9ab303 | 6179 | |
1a617b77 ML |
6180 | if (!intel_state->active_crtcs) |
6181 | intel_state->dev_cdclk = valleyview_calc_cdclk(dev_priv, 0); | |
6182 | ||
27c329ed ML |
6183 | return 0; |
6184 | } | |
304603f4 | 6185 | |
27c329ed ML |
6186 | static int broxton_modeset_calc_cdclk(struct drm_atomic_state *state) |
6187 | { | |
6188 | struct drm_device *dev = state->dev; | |
6189 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6190 | int max_pixclk = intel_mode_max_pixclk(dev, state); | |
1a617b77 ML |
6191 | struct intel_atomic_state *intel_state = |
6192 | to_intel_atomic_state(state); | |
85a96e7a | 6193 | |
27c329ed ML |
6194 | if (max_pixclk < 0) |
6195 | return max_pixclk; | |
85a96e7a | 6196 | |
1a617b77 | 6197 | intel_state->cdclk = intel_state->dev_cdclk = |
27c329ed | 6198 | broxton_calc_cdclk(dev_priv, max_pixclk); |
85a96e7a | 6199 | |
1a617b77 ML |
6200 | if (!intel_state->active_crtcs) |
6201 | intel_state->dev_cdclk = broxton_calc_cdclk(dev_priv, 0); | |
6202 | ||
27c329ed | 6203 | return 0; |
30a970c6 JB |
6204 | } |
6205 | ||
1e69cd74 VS |
6206 | static void vlv_program_pfi_credits(struct drm_i915_private *dev_priv) |
6207 | { | |
6208 | unsigned int credits, default_credits; | |
6209 | ||
6210 | if (IS_CHERRYVIEW(dev_priv)) | |
6211 | default_credits = PFI_CREDIT(12); | |
6212 | else | |
6213 | default_credits = PFI_CREDIT(8); | |
6214 | ||
bfa7df01 | 6215 | if (dev_priv->cdclk_freq >= dev_priv->czclk_freq) { |
1e69cd74 VS |
6216 | /* CHV suggested value is 31 or 63 */ |
6217 | if (IS_CHERRYVIEW(dev_priv)) | |
fcc0008f | 6218 | credits = PFI_CREDIT_63; |
1e69cd74 VS |
6219 | else |
6220 | credits = PFI_CREDIT(15); | |
6221 | } else { | |
6222 | credits = default_credits; | |
6223 | } | |
6224 | ||
6225 | /* | |
6226 | * WA - write default credits before re-programming | |
6227 | * FIXME: should we also set the resend bit here? | |
6228 | */ | |
6229 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | | |
6230 | default_credits); | |
6231 | ||
6232 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | | |
6233 | credits | PFI_CREDIT_RESEND); | |
6234 | ||
6235 | /* | |
6236 | * FIXME is this guaranteed to clear | |
6237 | * immediately or should we poll for it? | |
6238 | */ | |
6239 | WARN_ON(I915_READ(GCI_CONTROL) & PFI_CREDIT_RESEND); | |
6240 | } | |
6241 | ||
27c329ed | 6242 | static void valleyview_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
30a970c6 | 6243 | { |
a821fc46 | 6244 | struct drm_device *dev = old_state->dev; |
30a970c6 | 6245 | struct drm_i915_private *dev_priv = dev->dev_private; |
1a617b77 ML |
6246 | struct intel_atomic_state *old_intel_state = |
6247 | to_intel_atomic_state(old_state); | |
6248 | unsigned req_cdclk = old_intel_state->dev_cdclk; | |
30a970c6 | 6249 | |
27c329ed ML |
6250 | /* |
6251 | * FIXME: We can end up here with all power domains off, yet | |
6252 | * with a CDCLK frequency other than the minimum. To account | |
6253 | * for this take the PIPE-A power domain, which covers the HW | |
6254 | * blocks needed for the following programming. This can be | |
6255 | * removed once it's guaranteed that we get here either with | |
6256 | * the minimum CDCLK set, or the required power domains | |
6257 | * enabled. | |
6258 | */ | |
6259 | intel_display_power_get(dev_priv, POWER_DOMAIN_PIPE_A); | |
738c05c0 | 6260 | |
27c329ed ML |
6261 | if (IS_CHERRYVIEW(dev)) |
6262 | cherryview_set_cdclk(dev, req_cdclk); | |
6263 | else | |
6264 | valleyview_set_cdclk(dev, req_cdclk); | |
738c05c0 | 6265 | |
27c329ed | 6266 | vlv_program_pfi_credits(dev_priv); |
1e69cd74 | 6267 | |
27c329ed | 6268 | intel_display_power_put(dev_priv, POWER_DOMAIN_PIPE_A); |
30a970c6 JB |
6269 | } |
6270 | ||
89b667f8 JB |
6271 | static void valleyview_crtc_enable(struct drm_crtc *crtc) |
6272 | { | |
6273 | struct drm_device *dev = crtc->dev; | |
a72e4c9f | 6274 | struct drm_i915_private *dev_priv = to_i915(dev); |
89b667f8 JB |
6275 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
6276 | struct intel_encoder *encoder; | |
6277 | int pipe = intel_crtc->pipe; | |
89b667f8 | 6278 | |
53d9f4e9 | 6279 | if (WARN_ON(intel_crtc->active)) |
89b667f8 JB |
6280 | return; |
6281 | ||
6e3c9717 | 6282 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 6283 | intel_dp_set_m_n(intel_crtc, M1_N1); |
5b18e57c DV |
6284 | |
6285 | intel_set_pipe_timings(intel_crtc); | |
6286 | ||
c14b0485 VS |
6287 | if (IS_CHERRYVIEW(dev) && pipe == PIPE_B) { |
6288 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6289 | ||
6290 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); | |
6291 | I915_WRITE(CHV_CANVAS(pipe), 0); | |
6292 | } | |
6293 | ||
5b18e57c DV |
6294 | i9xx_set_pipeconf(intel_crtc); |
6295 | ||
89b667f8 | 6296 | intel_crtc->active = true; |
89b667f8 | 6297 | |
a72e4c9f | 6298 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4a3436e8 | 6299 | |
89b667f8 JB |
6300 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6301 | if (encoder->pre_pll_enable) | |
6302 | encoder->pre_pll_enable(encoder); | |
6303 | ||
a65347ba | 6304 | if (!intel_crtc->config->has_dsi_encoder) { |
c0b4c660 VS |
6305 | if (IS_CHERRYVIEW(dev)) { |
6306 | chv_prepare_pll(intel_crtc, intel_crtc->config); | |
6e3c9717 | 6307 | chv_enable_pll(intel_crtc, intel_crtc->config); |
c0b4c660 VS |
6308 | } else { |
6309 | vlv_prepare_pll(intel_crtc, intel_crtc->config); | |
6e3c9717 | 6310 | vlv_enable_pll(intel_crtc, intel_crtc->config); |
c0b4c660 | 6311 | } |
9d556c99 | 6312 | } |
89b667f8 JB |
6313 | |
6314 | for_each_encoder_on_crtc(dev, crtc, encoder) | |
6315 | if (encoder->pre_enable) | |
6316 | encoder->pre_enable(encoder); | |
6317 | ||
2dd24552 JB |
6318 | i9xx_pfit_enable(intel_crtc); |
6319 | ||
63cbb074 VS |
6320 | intel_crtc_load_lut(crtc); |
6321 | ||
e1fdc473 | 6322 | intel_enable_pipe(intel_crtc); |
be6a6f8e | 6323 | |
4b3a9526 VS |
6324 | assert_vblank_disabled(crtc); |
6325 | drm_crtc_vblank_on(crtc); | |
6326 | ||
f9b61ff6 DV |
6327 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6328 | encoder->enable(encoder); | |
89b667f8 JB |
6329 | } |
6330 | ||
f13c2ef3 DV |
6331 | static void i9xx_set_pll_dividers(struct intel_crtc *crtc) |
6332 | { | |
6333 | struct drm_device *dev = crtc->base.dev; | |
6334 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6335 | ||
6e3c9717 ACO |
6336 | I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0); |
6337 | I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1); | |
f13c2ef3 DV |
6338 | } |
6339 | ||
0b8765c6 | 6340 | static void i9xx_crtc_enable(struct drm_crtc *crtc) |
79e53945 JB |
6341 | { |
6342 | struct drm_device *dev = crtc->dev; | |
a72e4c9f | 6343 | struct drm_i915_private *dev_priv = to_i915(dev); |
79e53945 | 6344 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
ef9c3aee | 6345 | struct intel_encoder *encoder; |
79e53945 | 6346 | int pipe = intel_crtc->pipe; |
79e53945 | 6347 | |
53d9f4e9 | 6348 | if (WARN_ON(intel_crtc->active)) |
f7abfe8b CW |
6349 | return; |
6350 | ||
f13c2ef3 DV |
6351 | i9xx_set_pll_dividers(intel_crtc); |
6352 | ||
6e3c9717 | 6353 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 6354 | intel_dp_set_m_n(intel_crtc, M1_N1); |
5b18e57c DV |
6355 | |
6356 | intel_set_pipe_timings(intel_crtc); | |
6357 | ||
5b18e57c DV |
6358 | i9xx_set_pipeconf(intel_crtc); |
6359 | ||
f7abfe8b | 6360 | intel_crtc->active = true; |
6b383a7f | 6361 | |
4a3436e8 | 6362 | if (!IS_GEN2(dev)) |
a72e4c9f | 6363 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4a3436e8 | 6364 | |
9d6d9f19 MK |
6365 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6366 | if (encoder->pre_enable) | |
6367 | encoder->pre_enable(encoder); | |
6368 | ||
f6736a1a DV |
6369 | i9xx_enable_pll(intel_crtc); |
6370 | ||
2dd24552 JB |
6371 | i9xx_pfit_enable(intel_crtc); |
6372 | ||
63cbb074 VS |
6373 | intel_crtc_load_lut(crtc); |
6374 | ||
f37fcc2a | 6375 | intel_update_watermarks(crtc); |
e1fdc473 | 6376 | intel_enable_pipe(intel_crtc); |
be6a6f8e | 6377 | |
4b3a9526 VS |
6378 | assert_vblank_disabled(crtc); |
6379 | drm_crtc_vblank_on(crtc); | |
6380 | ||
f9b61ff6 DV |
6381 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6382 | encoder->enable(encoder); | |
0b8765c6 | 6383 | } |
79e53945 | 6384 | |
87476d63 DV |
6385 | static void i9xx_pfit_disable(struct intel_crtc *crtc) |
6386 | { | |
6387 | struct drm_device *dev = crtc->base.dev; | |
6388 | struct drm_i915_private *dev_priv = dev->dev_private; | |
87476d63 | 6389 | |
6e3c9717 | 6390 | if (!crtc->config->gmch_pfit.control) |
328d8e82 | 6391 | return; |
87476d63 | 6392 | |
328d8e82 | 6393 | assert_pipe_disabled(dev_priv, crtc->pipe); |
87476d63 | 6394 | |
328d8e82 DV |
6395 | DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", |
6396 | I915_READ(PFIT_CONTROL)); | |
6397 | I915_WRITE(PFIT_CONTROL, 0); | |
87476d63 DV |
6398 | } |
6399 | ||
0b8765c6 JB |
6400 | static void i9xx_crtc_disable(struct drm_crtc *crtc) |
6401 | { | |
6402 | struct drm_device *dev = crtc->dev; | |
6403 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6404 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 6405 | struct intel_encoder *encoder; |
0b8765c6 | 6406 | int pipe = intel_crtc->pipe; |
ef9c3aee | 6407 | |
6304cd91 VS |
6408 | /* |
6409 | * On gen2 planes are double buffered but the pipe isn't, so we must | |
6410 | * wait for planes to fully turn off before disabling the pipe. | |
564ed191 ID |
6411 | * We also need to wait on all gmch platforms because of the |
6412 | * self-refresh mode constraint explained above. | |
6304cd91 | 6413 | */ |
564ed191 | 6414 | intel_wait_for_vblank(dev, pipe); |
6304cd91 | 6415 | |
4b3a9526 VS |
6416 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6417 | encoder->disable(encoder); | |
6418 | ||
f9b61ff6 DV |
6419 | drm_crtc_vblank_off(crtc); |
6420 | assert_vblank_disabled(crtc); | |
6421 | ||
575f7ab7 | 6422 | intel_disable_pipe(intel_crtc); |
24a1f16d | 6423 | |
87476d63 | 6424 | i9xx_pfit_disable(intel_crtc); |
24a1f16d | 6425 | |
89b667f8 JB |
6426 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6427 | if (encoder->post_disable) | |
6428 | encoder->post_disable(encoder); | |
6429 | ||
a65347ba | 6430 | if (!intel_crtc->config->has_dsi_encoder) { |
076ed3b2 CML |
6431 | if (IS_CHERRYVIEW(dev)) |
6432 | chv_disable_pll(dev_priv, pipe); | |
6433 | else if (IS_VALLEYVIEW(dev)) | |
6434 | vlv_disable_pll(dev_priv, pipe); | |
6435 | else | |
1c4e0274 | 6436 | i9xx_disable_pll(intel_crtc); |
076ed3b2 | 6437 | } |
0b8765c6 | 6438 | |
d6db995f VS |
6439 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6440 | if (encoder->post_pll_disable) | |
6441 | encoder->post_pll_disable(encoder); | |
6442 | ||
4a3436e8 | 6443 | if (!IS_GEN2(dev)) |
a72e4c9f | 6444 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
0b8765c6 JB |
6445 | } |
6446 | ||
b17d48e2 ML |
6447 | static void intel_crtc_disable_noatomic(struct drm_crtc *crtc) |
6448 | { | |
6449 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6450 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); | |
6451 | enum intel_display_power_domain domain; | |
6452 | unsigned long domains; | |
6453 | ||
6454 | if (!intel_crtc->active) | |
6455 | return; | |
6456 | ||
a539205a | 6457 | if (to_intel_plane_state(crtc->primary->state)->visible) { |
fc32b1fd ML |
6458 | WARN_ON(intel_crtc->unpin_work); |
6459 | ||
a539205a | 6460 | intel_pre_disable_primary(crtc); |
54a41961 ML |
6461 | |
6462 | intel_crtc_disable_planes(crtc, 1 << drm_plane_index(crtc->primary)); | |
6463 | to_intel_plane_state(crtc->primary->state)->visible = false; | |
a539205a ML |
6464 | } |
6465 | ||
b17d48e2 | 6466 | dev_priv->display.crtc_disable(crtc); |
37d9078b | 6467 | intel_crtc->active = false; |
58f9c0bc | 6468 | intel_fbc_disable(intel_crtc); |
37d9078b | 6469 | intel_update_watermarks(crtc); |
1f7457b1 | 6470 | intel_disable_shared_dpll(intel_crtc); |
b17d48e2 ML |
6471 | |
6472 | domains = intel_crtc->enabled_power_domains; | |
6473 | for_each_power_domain(domain, domains) | |
6474 | intel_display_power_put(dev_priv, domain); | |
6475 | intel_crtc->enabled_power_domains = 0; | |
565602d7 ML |
6476 | |
6477 | dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe); | |
6478 | dev_priv->min_pixclk[intel_crtc->pipe] = 0; | |
b17d48e2 ML |
6479 | } |
6480 | ||
6b72d486 ML |
6481 | /* |
6482 | * turn all crtc's off, but do not adjust state | |
6483 | * This has to be paired with a call to intel_modeset_setup_hw_state. | |
6484 | */ | |
70e0bd74 | 6485 | int intel_display_suspend(struct drm_device *dev) |
ee7b9f93 | 6486 | { |
e2c8b870 | 6487 | struct drm_i915_private *dev_priv = to_i915(dev); |
70e0bd74 | 6488 | struct drm_atomic_state *state; |
e2c8b870 | 6489 | int ret; |
70e0bd74 | 6490 | |
e2c8b870 ML |
6491 | state = drm_atomic_helper_suspend(dev); |
6492 | ret = PTR_ERR_OR_ZERO(state); | |
70e0bd74 ML |
6493 | if (ret) |
6494 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); | |
e2c8b870 ML |
6495 | else |
6496 | dev_priv->modeset_restore_state = state; | |
70e0bd74 | 6497 | return ret; |
ee7b9f93 JB |
6498 | } |
6499 | ||
ea5b213a | 6500 | void intel_encoder_destroy(struct drm_encoder *encoder) |
7e7d76c3 | 6501 | { |
4ef69c7a | 6502 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
ea5b213a | 6503 | |
ea5b213a CW |
6504 | drm_encoder_cleanup(encoder); |
6505 | kfree(intel_encoder); | |
7e7d76c3 JB |
6506 | } |
6507 | ||
0a91ca29 DV |
6508 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
6509 | * internal consistency). */ | |
b980514c | 6510 | static void intel_connector_check_state(struct intel_connector *connector) |
79e53945 | 6511 | { |
35dd3c64 ML |
6512 | struct drm_crtc *crtc = connector->base.state->crtc; |
6513 | ||
6514 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", | |
6515 | connector->base.base.id, | |
6516 | connector->base.name); | |
6517 | ||
0a91ca29 | 6518 | if (connector->get_hw_state(connector)) { |
e85376cb | 6519 | struct intel_encoder *encoder = connector->encoder; |
35dd3c64 | 6520 | struct drm_connector_state *conn_state = connector->base.state; |
0a91ca29 | 6521 | |
35dd3c64 ML |
6522 | I915_STATE_WARN(!crtc, |
6523 | "connector enabled without attached crtc\n"); | |
0a91ca29 | 6524 | |
35dd3c64 ML |
6525 | if (!crtc) |
6526 | return; | |
6527 | ||
6528 | I915_STATE_WARN(!crtc->state->active, | |
6529 | "connector is active, but attached crtc isn't\n"); | |
6530 | ||
e85376cb | 6531 | if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST) |
35dd3c64 ML |
6532 | return; |
6533 | ||
e85376cb | 6534 | I915_STATE_WARN(conn_state->best_encoder != &encoder->base, |
35dd3c64 ML |
6535 | "atomic encoder doesn't match attached encoder\n"); |
6536 | ||
e85376cb | 6537 | I915_STATE_WARN(conn_state->crtc != encoder->base.crtc, |
35dd3c64 ML |
6538 | "attached encoder crtc differs from connector crtc\n"); |
6539 | } else { | |
4d688a2a ML |
6540 | I915_STATE_WARN(crtc && crtc->state->active, |
6541 | "attached crtc is active, but connector isn't\n"); | |
35dd3c64 ML |
6542 | I915_STATE_WARN(!crtc && connector->base.state->best_encoder, |
6543 | "best encoder set without crtc!\n"); | |
0a91ca29 | 6544 | } |
79e53945 JB |
6545 | } |
6546 | ||
08d9bc92 ACO |
6547 | int intel_connector_init(struct intel_connector *connector) |
6548 | { | |
5350a031 | 6549 | drm_atomic_helper_connector_reset(&connector->base); |
08d9bc92 | 6550 | |
5350a031 | 6551 | if (!connector->base.state) |
08d9bc92 ACO |
6552 | return -ENOMEM; |
6553 | ||
08d9bc92 ACO |
6554 | return 0; |
6555 | } | |
6556 | ||
6557 | struct intel_connector *intel_connector_alloc(void) | |
6558 | { | |
6559 | struct intel_connector *connector; | |
6560 | ||
6561 | connector = kzalloc(sizeof *connector, GFP_KERNEL); | |
6562 | if (!connector) | |
6563 | return NULL; | |
6564 | ||
6565 | if (intel_connector_init(connector) < 0) { | |
6566 | kfree(connector); | |
6567 | return NULL; | |
6568 | } | |
6569 | ||
6570 | return connector; | |
6571 | } | |
6572 | ||
f0947c37 DV |
6573 | /* Simple connector->get_hw_state implementation for encoders that support only |
6574 | * one connector and no cloning and hence the encoder state determines the state | |
6575 | * of the connector. */ | |
6576 | bool intel_connector_get_hw_state(struct intel_connector *connector) | |
ea5b213a | 6577 | { |
24929352 | 6578 | enum pipe pipe = 0; |
f0947c37 | 6579 | struct intel_encoder *encoder = connector->encoder; |
ea5b213a | 6580 | |
f0947c37 | 6581 | return encoder->get_hw_state(encoder, &pipe); |
ea5b213a CW |
6582 | } |
6583 | ||
6d293983 | 6584 | static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state) |
d272ddfa | 6585 | { |
6d293983 ACO |
6586 | if (crtc_state->base.enable && crtc_state->has_pch_encoder) |
6587 | return crtc_state->fdi_lanes; | |
d272ddfa VS |
6588 | |
6589 | return 0; | |
6590 | } | |
6591 | ||
6d293983 | 6592 | static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe, |
5cec258b | 6593 | struct intel_crtc_state *pipe_config) |
1857e1da | 6594 | { |
6d293983 ACO |
6595 | struct drm_atomic_state *state = pipe_config->base.state; |
6596 | struct intel_crtc *other_crtc; | |
6597 | struct intel_crtc_state *other_crtc_state; | |
6598 | ||
1857e1da DV |
6599 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
6600 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6601 | if (pipe_config->fdi_lanes > 4) { | |
6602 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", | |
6603 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6604 | return -EINVAL; |
1857e1da DV |
6605 | } |
6606 | ||
bafb6553 | 6607 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
1857e1da DV |
6608 | if (pipe_config->fdi_lanes > 2) { |
6609 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", | |
6610 | pipe_config->fdi_lanes); | |
6d293983 | 6611 | return -EINVAL; |
1857e1da | 6612 | } else { |
6d293983 | 6613 | return 0; |
1857e1da DV |
6614 | } |
6615 | } | |
6616 | ||
6617 | if (INTEL_INFO(dev)->num_pipes == 2) | |
6d293983 | 6618 | return 0; |
1857e1da DV |
6619 | |
6620 | /* Ivybridge 3 pipe is really complicated */ | |
6621 | switch (pipe) { | |
6622 | case PIPE_A: | |
6d293983 | 6623 | return 0; |
1857e1da | 6624 | case PIPE_B: |
6d293983 ACO |
6625 | if (pipe_config->fdi_lanes <= 2) |
6626 | return 0; | |
6627 | ||
6628 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_C)); | |
6629 | other_crtc_state = | |
6630 | intel_atomic_get_crtc_state(state, other_crtc); | |
6631 | if (IS_ERR(other_crtc_state)) | |
6632 | return PTR_ERR(other_crtc_state); | |
6633 | ||
6634 | if (pipe_required_fdi_lanes(other_crtc_state) > 0) { | |
1857e1da DV |
6635 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
6636 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6637 | return -EINVAL; |
1857e1da | 6638 | } |
6d293983 | 6639 | return 0; |
1857e1da | 6640 | case PIPE_C: |
251cc67c VS |
6641 | if (pipe_config->fdi_lanes > 2) { |
6642 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", | |
6643 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6644 | return -EINVAL; |
251cc67c | 6645 | } |
6d293983 ACO |
6646 | |
6647 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_B)); | |
6648 | other_crtc_state = | |
6649 | intel_atomic_get_crtc_state(state, other_crtc); | |
6650 | if (IS_ERR(other_crtc_state)) | |
6651 | return PTR_ERR(other_crtc_state); | |
6652 | ||
6653 | if (pipe_required_fdi_lanes(other_crtc_state) > 2) { | |
1857e1da | 6654 | DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n"); |
6d293983 | 6655 | return -EINVAL; |
1857e1da | 6656 | } |
6d293983 | 6657 | return 0; |
1857e1da DV |
6658 | default: |
6659 | BUG(); | |
6660 | } | |
6661 | } | |
6662 | ||
e29c22c0 DV |
6663 | #define RETRY 1 |
6664 | static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc, | |
5cec258b | 6665 | struct intel_crtc_state *pipe_config) |
877d48d5 | 6666 | { |
1857e1da | 6667 | struct drm_device *dev = intel_crtc->base.dev; |
7c5f93b0 | 6668 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
6d293983 ACO |
6669 | int lane, link_bw, fdi_dotclock, ret; |
6670 | bool needs_recompute = false; | |
877d48d5 | 6671 | |
e29c22c0 | 6672 | retry: |
877d48d5 DV |
6673 | /* FDI is a binary signal running at ~2.7GHz, encoding |
6674 | * each output octet as 10 bits. The actual frequency | |
6675 | * is stored as a divider into a 100MHz clock, and the | |
6676 | * mode pixel clock is stored in units of 1KHz. | |
6677 | * Hence the bw of each lane in terms of the mode signal | |
6678 | * is: | |
6679 | */ | |
6680 | link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10; | |
6681 | ||
241bfc38 | 6682 | fdi_dotclock = adjusted_mode->crtc_clock; |
877d48d5 | 6683 | |
2bd89a07 | 6684 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
877d48d5 DV |
6685 | pipe_config->pipe_bpp); |
6686 | ||
6687 | pipe_config->fdi_lanes = lane; | |
6688 | ||
2bd89a07 | 6689 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
877d48d5 | 6690 | link_bw, &pipe_config->fdi_m_n); |
1857e1da | 6691 | |
6d293983 ACO |
6692 | ret = ironlake_check_fdi_lanes(intel_crtc->base.dev, |
6693 | intel_crtc->pipe, pipe_config); | |
6694 | if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) { | |
e29c22c0 DV |
6695 | pipe_config->pipe_bpp -= 2*3; |
6696 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", | |
6697 | pipe_config->pipe_bpp); | |
6698 | needs_recompute = true; | |
6699 | pipe_config->bw_constrained = true; | |
6700 | ||
6701 | goto retry; | |
6702 | } | |
6703 | ||
6704 | if (needs_recompute) | |
6705 | return RETRY; | |
6706 | ||
6d293983 | 6707 | return ret; |
877d48d5 DV |
6708 | } |
6709 | ||
8cfb3407 VS |
6710 | static bool pipe_config_supports_ips(struct drm_i915_private *dev_priv, |
6711 | struct intel_crtc_state *pipe_config) | |
6712 | { | |
6713 | if (pipe_config->pipe_bpp > 24) | |
6714 | return false; | |
6715 | ||
6716 | /* HSW can handle pixel rate up to cdclk? */ | |
6717 | if (IS_HASWELL(dev_priv->dev)) | |
6718 | return true; | |
6719 | ||
6720 | /* | |
b432e5cf VS |
6721 | * We compare against max which means we must take |
6722 | * the increased cdclk requirement into account when | |
6723 | * calculating the new cdclk. | |
6724 | * | |
6725 | * Should measure whether using a lower cdclk w/o IPS | |
8cfb3407 VS |
6726 | */ |
6727 | return ilk_pipe_pixel_rate(pipe_config) <= | |
6728 | dev_priv->max_cdclk_freq * 95 / 100; | |
6729 | } | |
6730 | ||
42db64ef | 6731 | static void hsw_compute_ips_config(struct intel_crtc *crtc, |
5cec258b | 6732 | struct intel_crtc_state *pipe_config) |
42db64ef | 6733 | { |
8cfb3407 VS |
6734 | struct drm_device *dev = crtc->base.dev; |
6735 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6736 | ||
d330a953 | 6737 | pipe_config->ips_enabled = i915.enable_ips && |
8cfb3407 VS |
6738 | hsw_crtc_supports_ips(crtc) && |
6739 | pipe_config_supports_ips(dev_priv, pipe_config); | |
42db64ef PZ |
6740 | } |
6741 | ||
39acb4aa VS |
6742 | static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc) |
6743 | { | |
6744 | const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); | |
6745 | ||
6746 | /* GDG double wide on either pipe, otherwise pipe A only */ | |
6747 | return INTEL_INFO(dev_priv)->gen < 4 && | |
6748 | (crtc->pipe == PIPE_A || IS_I915G(dev_priv)); | |
6749 | } | |
6750 | ||
a43f6e0f | 6751 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
5cec258b | 6752 | struct intel_crtc_state *pipe_config) |
79e53945 | 6753 | { |
a43f6e0f | 6754 | struct drm_device *dev = crtc->base.dev; |
8bd31e67 | 6755 | struct drm_i915_private *dev_priv = dev->dev_private; |
7c5f93b0 | 6756 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
89749350 | 6757 | |
ad3a4479 | 6758 | /* FIXME should check pixel clock limits on all platforms */ |
cf532bb2 | 6759 | if (INTEL_INFO(dev)->gen < 4) { |
39acb4aa | 6760 | int clock_limit = dev_priv->max_cdclk_freq * 9 / 10; |
cf532bb2 VS |
6761 | |
6762 | /* | |
39acb4aa | 6763 | * Enable double wide mode when the dot clock |
cf532bb2 | 6764 | * is > 90% of the (display) core speed. |
cf532bb2 | 6765 | */ |
39acb4aa VS |
6766 | if (intel_crtc_supports_double_wide(crtc) && |
6767 | adjusted_mode->crtc_clock > clock_limit) { | |
ad3a4479 | 6768 | clock_limit *= 2; |
cf532bb2 | 6769 | pipe_config->double_wide = true; |
ad3a4479 VS |
6770 | } |
6771 | ||
39acb4aa VS |
6772 | if (adjusted_mode->crtc_clock > clock_limit) { |
6773 | DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n", | |
6774 | adjusted_mode->crtc_clock, clock_limit, | |
6775 | yesno(pipe_config->double_wide)); | |
e29c22c0 | 6776 | return -EINVAL; |
39acb4aa | 6777 | } |
2c07245f | 6778 | } |
89749350 | 6779 | |
1d1d0e27 VS |
6780 | /* |
6781 | * Pipe horizontal size must be even in: | |
6782 | * - DVO ganged mode | |
6783 | * - LVDS dual channel mode | |
6784 | * - Double wide pipe | |
6785 | */ | |
a93e255f | 6786 | if ((intel_pipe_will_have_type(pipe_config, INTEL_OUTPUT_LVDS) && |
1d1d0e27 VS |
6787 | intel_is_dual_link_lvds(dev)) || pipe_config->double_wide) |
6788 | pipe_config->pipe_src_w &= ~1; | |
6789 | ||
8693a824 DL |
6790 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
6791 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. | |
44f46b42 CW |
6792 | */ |
6793 | if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) && | |
aad941d5 | 6794 | adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay) |
e29c22c0 | 6795 | return -EINVAL; |
44f46b42 | 6796 | |
f5adf94e | 6797 | if (HAS_IPS(dev)) |
a43f6e0f DV |
6798 | hsw_compute_ips_config(crtc, pipe_config); |
6799 | ||
877d48d5 | 6800 | if (pipe_config->has_pch_encoder) |
a43f6e0f | 6801 | return ironlake_fdi_compute_config(crtc, pipe_config); |
877d48d5 | 6802 | |
cf5a15be | 6803 | return 0; |
79e53945 JB |
6804 | } |
6805 | ||
1652d19e VS |
6806 | static int skylake_get_display_clock_speed(struct drm_device *dev) |
6807 | { | |
6808 | struct drm_i915_private *dev_priv = to_i915(dev); | |
6809 | uint32_t lcpll1 = I915_READ(LCPLL1_CTL); | |
6810 | uint32_t cdctl = I915_READ(CDCLK_CTL); | |
6811 | uint32_t linkrate; | |
6812 | ||
414355a7 | 6813 | if (!(lcpll1 & LCPLL_PLL_ENABLE)) |
1652d19e | 6814 | return 24000; /* 24MHz is the cd freq with NSSC ref */ |
1652d19e VS |
6815 | |
6816 | if ((cdctl & CDCLK_FREQ_SEL_MASK) == CDCLK_FREQ_540) | |
6817 | return 540000; | |
6818 | ||
6819 | linkrate = (I915_READ(DPLL_CTRL1) & | |
71cd8423 | 6820 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)) >> 1; |
1652d19e | 6821 | |
71cd8423 DL |
6822 | if (linkrate == DPLL_CTRL1_LINK_RATE_2160 || |
6823 | linkrate == DPLL_CTRL1_LINK_RATE_1080) { | |
1652d19e VS |
6824 | /* vco 8640 */ |
6825 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { | |
6826 | case CDCLK_FREQ_450_432: | |
6827 | return 432000; | |
6828 | case CDCLK_FREQ_337_308: | |
6829 | return 308570; | |
6830 | case CDCLK_FREQ_675_617: | |
6831 | return 617140; | |
6832 | default: | |
6833 | WARN(1, "Unknown cd freq selection\n"); | |
6834 | } | |
6835 | } else { | |
6836 | /* vco 8100 */ | |
6837 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { | |
6838 | case CDCLK_FREQ_450_432: | |
6839 | return 450000; | |
6840 | case CDCLK_FREQ_337_308: | |
6841 | return 337500; | |
6842 | case CDCLK_FREQ_675_617: | |
6843 | return 675000; | |
6844 | default: | |
6845 | WARN(1, "Unknown cd freq selection\n"); | |
6846 | } | |
6847 | } | |
6848 | ||
6849 | /* error case, do as if DPLL0 isn't enabled */ | |
6850 | return 24000; | |
6851 | } | |
6852 | ||
acd3f3d3 BP |
6853 | static int broxton_get_display_clock_speed(struct drm_device *dev) |
6854 | { | |
6855 | struct drm_i915_private *dev_priv = to_i915(dev); | |
6856 | uint32_t cdctl = I915_READ(CDCLK_CTL); | |
6857 | uint32_t pll_ratio = I915_READ(BXT_DE_PLL_CTL) & BXT_DE_PLL_RATIO_MASK; | |
6858 | uint32_t pll_enab = I915_READ(BXT_DE_PLL_ENABLE); | |
6859 | int cdclk; | |
6860 | ||
6861 | if (!(pll_enab & BXT_DE_PLL_PLL_ENABLE)) | |
6862 | return 19200; | |
6863 | ||
6864 | cdclk = 19200 * pll_ratio / 2; | |
6865 | ||
6866 | switch (cdctl & BXT_CDCLK_CD2X_DIV_SEL_MASK) { | |
6867 | case BXT_CDCLK_CD2X_DIV_SEL_1: | |
6868 | return cdclk; /* 576MHz or 624MHz */ | |
6869 | case BXT_CDCLK_CD2X_DIV_SEL_1_5: | |
6870 | return cdclk * 2 / 3; /* 384MHz */ | |
6871 | case BXT_CDCLK_CD2X_DIV_SEL_2: | |
6872 | return cdclk / 2; /* 288MHz */ | |
6873 | case BXT_CDCLK_CD2X_DIV_SEL_4: | |
6874 | return cdclk / 4; /* 144MHz */ | |
6875 | } | |
6876 | ||
6877 | /* error case, do as if DE PLL isn't enabled */ | |
6878 | return 19200; | |
6879 | } | |
6880 | ||
1652d19e VS |
6881 | static int broadwell_get_display_clock_speed(struct drm_device *dev) |
6882 | { | |
6883 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6884 | uint32_t lcpll = I915_READ(LCPLL_CTL); | |
6885 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; | |
6886 | ||
6887 | if (lcpll & LCPLL_CD_SOURCE_FCLK) | |
6888 | return 800000; | |
6889 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
6890 | return 450000; | |
6891 | else if (freq == LCPLL_CLK_FREQ_450) | |
6892 | return 450000; | |
6893 | else if (freq == LCPLL_CLK_FREQ_54O_BDW) | |
6894 | return 540000; | |
6895 | else if (freq == LCPLL_CLK_FREQ_337_5_BDW) | |
6896 | return 337500; | |
6897 | else | |
6898 | return 675000; | |
6899 | } | |
6900 | ||
6901 | static int haswell_get_display_clock_speed(struct drm_device *dev) | |
6902 | { | |
6903 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6904 | uint32_t lcpll = I915_READ(LCPLL_CTL); | |
6905 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; | |
6906 | ||
6907 | if (lcpll & LCPLL_CD_SOURCE_FCLK) | |
6908 | return 800000; | |
6909 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
6910 | return 450000; | |
6911 | else if (freq == LCPLL_CLK_FREQ_450) | |
6912 | return 450000; | |
6913 | else if (IS_HSW_ULT(dev)) | |
6914 | return 337500; | |
6915 | else | |
6916 | return 540000; | |
79e53945 JB |
6917 | } |
6918 | ||
25eb05fc JB |
6919 | static int valleyview_get_display_clock_speed(struct drm_device *dev) |
6920 | { | |
bfa7df01 VS |
6921 | return vlv_get_cck_clock_hpll(to_i915(dev), "cdclk", |
6922 | CCK_DISPLAY_CLOCK_CONTROL); | |
25eb05fc JB |
6923 | } |
6924 | ||
b37a6434 VS |
6925 | static int ilk_get_display_clock_speed(struct drm_device *dev) |
6926 | { | |
6927 | return 450000; | |
6928 | } | |
6929 | ||
e70236a8 JB |
6930 | static int i945_get_display_clock_speed(struct drm_device *dev) |
6931 | { | |
6932 | return 400000; | |
6933 | } | |
79e53945 | 6934 | |
e70236a8 | 6935 | static int i915_get_display_clock_speed(struct drm_device *dev) |
79e53945 | 6936 | { |
e907f170 | 6937 | return 333333; |
e70236a8 | 6938 | } |
79e53945 | 6939 | |
e70236a8 JB |
6940 | static int i9xx_misc_get_display_clock_speed(struct drm_device *dev) |
6941 | { | |
6942 | return 200000; | |
6943 | } | |
79e53945 | 6944 | |
257a7ffc DV |
6945 | static int pnv_get_display_clock_speed(struct drm_device *dev) |
6946 | { | |
6947 | u16 gcfgc = 0; | |
6948 | ||
6949 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); | |
6950 | ||
6951 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { | |
6952 | case GC_DISPLAY_CLOCK_267_MHZ_PNV: | |
e907f170 | 6953 | return 266667; |
257a7ffc | 6954 | case GC_DISPLAY_CLOCK_333_MHZ_PNV: |
e907f170 | 6955 | return 333333; |
257a7ffc | 6956 | case GC_DISPLAY_CLOCK_444_MHZ_PNV: |
e907f170 | 6957 | return 444444; |
257a7ffc DV |
6958 | case GC_DISPLAY_CLOCK_200_MHZ_PNV: |
6959 | return 200000; | |
6960 | default: | |
6961 | DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc); | |
6962 | case GC_DISPLAY_CLOCK_133_MHZ_PNV: | |
e907f170 | 6963 | return 133333; |
257a7ffc | 6964 | case GC_DISPLAY_CLOCK_167_MHZ_PNV: |
e907f170 | 6965 | return 166667; |
257a7ffc DV |
6966 | } |
6967 | } | |
6968 | ||
e70236a8 JB |
6969 | static int i915gm_get_display_clock_speed(struct drm_device *dev) |
6970 | { | |
6971 | u16 gcfgc = 0; | |
79e53945 | 6972 | |
e70236a8 JB |
6973 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
6974 | ||
6975 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) | |
e907f170 | 6976 | return 133333; |
e70236a8 JB |
6977 | else { |
6978 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { | |
6979 | case GC_DISPLAY_CLOCK_333_MHZ: | |
e907f170 | 6980 | return 333333; |
e70236a8 JB |
6981 | default: |
6982 | case GC_DISPLAY_CLOCK_190_200_MHZ: | |
6983 | return 190000; | |
79e53945 | 6984 | } |
e70236a8 JB |
6985 | } |
6986 | } | |
6987 | ||
6988 | static int i865_get_display_clock_speed(struct drm_device *dev) | |
6989 | { | |
e907f170 | 6990 | return 266667; |
e70236a8 JB |
6991 | } |
6992 | ||
1b1d2716 | 6993 | static int i85x_get_display_clock_speed(struct drm_device *dev) |
e70236a8 JB |
6994 | { |
6995 | u16 hpllcc = 0; | |
1b1d2716 | 6996 | |
65cd2b3f VS |
6997 | /* |
6998 | * 852GM/852GMV only supports 133 MHz and the HPLLCC | |
6999 | * encoding is different :( | |
7000 | * FIXME is this the right way to detect 852GM/852GMV? | |
7001 | */ | |
7002 | if (dev->pdev->revision == 0x1) | |
7003 | return 133333; | |
7004 | ||
1b1d2716 VS |
7005 | pci_bus_read_config_word(dev->pdev->bus, |
7006 | PCI_DEVFN(0, 3), HPLLCC, &hpllcc); | |
7007 | ||
e70236a8 JB |
7008 | /* Assume that the hardware is in the high speed state. This |
7009 | * should be the default. | |
7010 | */ | |
7011 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { | |
7012 | case GC_CLOCK_133_200: | |
1b1d2716 | 7013 | case GC_CLOCK_133_200_2: |
e70236a8 JB |
7014 | case GC_CLOCK_100_200: |
7015 | return 200000; | |
7016 | case GC_CLOCK_166_250: | |
7017 | return 250000; | |
7018 | case GC_CLOCK_100_133: | |
e907f170 | 7019 | return 133333; |
1b1d2716 VS |
7020 | case GC_CLOCK_133_266: |
7021 | case GC_CLOCK_133_266_2: | |
7022 | case GC_CLOCK_166_266: | |
7023 | return 266667; | |
e70236a8 | 7024 | } |
79e53945 | 7025 | |
e70236a8 JB |
7026 | /* Shouldn't happen */ |
7027 | return 0; | |
7028 | } | |
79e53945 | 7029 | |
e70236a8 JB |
7030 | static int i830_get_display_clock_speed(struct drm_device *dev) |
7031 | { | |
e907f170 | 7032 | return 133333; |
79e53945 JB |
7033 | } |
7034 | ||
34edce2f VS |
7035 | static unsigned int intel_hpll_vco(struct drm_device *dev) |
7036 | { | |
7037 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7038 | static const unsigned int blb_vco[8] = { | |
7039 | [0] = 3200000, | |
7040 | [1] = 4000000, | |
7041 | [2] = 5333333, | |
7042 | [3] = 4800000, | |
7043 | [4] = 6400000, | |
7044 | }; | |
7045 | static const unsigned int pnv_vco[8] = { | |
7046 | [0] = 3200000, | |
7047 | [1] = 4000000, | |
7048 | [2] = 5333333, | |
7049 | [3] = 4800000, | |
7050 | [4] = 2666667, | |
7051 | }; | |
7052 | static const unsigned int cl_vco[8] = { | |
7053 | [0] = 3200000, | |
7054 | [1] = 4000000, | |
7055 | [2] = 5333333, | |
7056 | [3] = 6400000, | |
7057 | [4] = 3333333, | |
7058 | [5] = 3566667, | |
7059 | [6] = 4266667, | |
7060 | }; | |
7061 | static const unsigned int elk_vco[8] = { | |
7062 | [0] = 3200000, | |
7063 | [1] = 4000000, | |
7064 | [2] = 5333333, | |
7065 | [3] = 4800000, | |
7066 | }; | |
7067 | static const unsigned int ctg_vco[8] = { | |
7068 | [0] = 3200000, | |
7069 | [1] = 4000000, | |
7070 | [2] = 5333333, | |
7071 | [3] = 6400000, | |
7072 | [4] = 2666667, | |
7073 | [5] = 4266667, | |
7074 | }; | |
7075 | const unsigned int *vco_table; | |
7076 | unsigned int vco; | |
7077 | uint8_t tmp = 0; | |
7078 | ||
7079 | /* FIXME other chipsets? */ | |
7080 | if (IS_GM45(dev)) | |
7081 | vco_table = ctg_vco; | |
7082 | else if (IS_G4X(dev)) | |
7083 | vco_table = elk_vco; | |
7084 | else if (IS_CRESTLINE(dev)) | |
7085 | vco_table = cl_vco; | |
7086 | else if (IS_PINEVIEW(dev)) | |
7087 | vco_table = pnv_vco; | |
7088 | else if (IS_G33(dev)) | |
7089 | vco_table = blb_vco; | |
7090 | else | |
7091 | return 0; | |
7092 | ||
7093 | tmp = I915_READ(IS_MOBILE(dev) ? HPLLVCO_MOBILE : HPLLVCO); | |
7094 | ||
7095 | vco = vco_table[tmp & 0x7]; | |
7096 | if (vco == 0) | |
7097 | DRM_ERROR("Bad HPLL VCO (HPLLVCO=0x%02x)\n", tmp); | |
7098 | else | |
7099 | DRM_DEBUG_KMS("HPLL VCO %u kHz\n", vco); | |
7100 | ||
7101 | return vco; | |
7102 | } | |
7103 | ||
7104 | static int gm45_get_display_clock_speed(struct drm_device *dev) | |
7105 | { | |
7106 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
7107 | uint16_t tmp = 0; | |
7108 | ||
7109 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
7110 | ||
7111 | cdclk_sel = (tmp >> 12) & 0x1; | |
7112 | ||
7113 | switch (vco) { | |
7114 | case 2666667: | |
7115 | case 4000000: | |
7116 | case 5333333: | |
7117 | return cdclk_sel ? 333333 : 222222; | |
7118 | case 3200000: | |
7119 | return cdclk_sel ? 320000 : 228571; | |
7120 | default: | |
7121 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u, CFGC=0x%04x\n", vco, tmp); | |
7122 | return 222222; | |
7123 | } | |
7124 | } | |
7125 | ||
7126 | static int i965gm_get_display_clock_speed(struct drm_device *dev) | |
7127 | { | |
7128 | static const uint8_t div_3200[] = { 16, 10, 8 }; | |
7129 | static const uint8_t div_4000[] = { 20, 12, 10 }; | |
7130 | static const uint8_t div_5333[] = { 24, 16, 14 }; | |
7131 | const uint8_t *div_table; | |
7132 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
7133 | uint16_t tmp = 0; | |
7134 | ||
7135 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
7136 | ||
7137 | cdclk_sel = ((tmp >> 8) & 0x1f) - 1; | |
7138 | ||
7139 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) | |
7140 | goto fail; | |
7141 | ||
7142 | switch (vco) { | |
7143 | case 3200000: | |
7144 | div_table = div_3200; | |
7145 | break; | |
7146 | case 4000000: | |
7147 | div_table = div_4000; | |
7148 | break; | |
7149 | case 5333333: | |
7150 | div_table = div_5333; | |
7151 | break; | |
7152 | default: | |
7153 | goto fail; | |
7154 | } | |
7155 | ||
7156 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); | |
7157 | ||
caf4e252 | 7158 | fail: |
34edce2f VS |
7159 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%04x\n", vco, tmp); |
7160 | return 200000; | |
7161 | } | |
7162 | ||
7163 | static int g33_get_display_clock_speed(struct drm_device *dev) | |
7164 | { | |
7165 | static const uint8_t div_3200[] = { 12, 10, 8, 7, 5, 16 }; | |
7166 | static const uint8_t div_4000[] = { 14, 12, 10, 8, 6, 20 }; | |
7167 | static const uint8_t div_4800[] = { 20, 14, 12, 10, 8, 24 }; | |
7168 | static const uint8_t div_5333[] = { 20, 16, 12, 12, 8, 28 }; | |
7169 | const uint8_t *div_table; | |
7170 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
7171 | uint16_t tmp = 0; | |
7172 | ||
7173 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
7174 | ||
7175 | cdclk_sel = (tmp >> 4) & 0x7; | |
7176 | ||
7177 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) | |
7178 | goto fail; | |
7179 | ||
7180 | switch (vco) { | |
7181 | case 3200000: | |
7182 | div_table = div_3200; | |
7183 | break; | |
7184 | case 4000000: | |
7185 | div_table = div_4000; | |
7186 | break; | |
7187 | case 4800000: | |
7188 | div_table = div_4800; | |
7189 | break; | |
7190 | case 5333333: | |
7191 | div_table = div_5333; | |
7192 | break; | |
7193 | default: | |
7194 | goto fail; | |
7195 | } | |
7196 | ||
7197 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); | |
7198 | ||
caf4e252 | 7199 | fail: |
34edce2f VS |
7200 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%08x\n", vco, tmp); |
7201 | return 190476; | |
7202 | } | |
7203 | ||
2c07245f | 7204 | static void |
a65851af | 7205 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
2c07245f | 7206 | { |
a65851af VS |
7207 | while (*num > DATA_LINK_M_N_MASK || |
7208 | *den > DATA_LINK_M_N_MASK) { | |
2c07245f ZW |
7209 | *num >>= 1; |
7210 | *den >>= 1; | |
7211 | } | |
7212 | } | |
7213 | ||
a65851af VS |
7214 | static void compute_m_n(unsigned int m, unsigned int n, |
7215 | uint32_t *ret_m, uint32_t *ret_n) | |
7216 | { | |
7217 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); | |
7218 | *ret_m = div_u64((uint64_t) m * *ret_n, n); | |
7219 | intel_reduce_m_n_ratio(ret_m, ret_n); | |
7220 | } | |
7221 | ||
e69d0bc1 DV |
7222 | void |
7223 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, | |
7224 | int pixel_clock, int link_clock, | |
7225 | struct intel_link_m_n *m_n) | |
2c07245f | 7226 | { |
e69d0bc1 | 7227 | m_n->tu = 64; |
a65851af VS |
7228 | |
7229 | compute_m_n(bits_per_pixel * pixel_clock, | |
7230 | link_clock * nlanes * 8, | |
7231 | &m_n->gmch_m, &m_n->gmch_n); | |
7232 | ||
7233 | compute_m_n(pixel_clock, link_clock, | |
7234 | &m_n->link_m, &m_n->link_n); | |
2c07245f ZW |
7235 | } |
7236 | ||
a7615030 CW |
7237 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
7238 | { | |
d330a953 JN |
7239 | if (i915.panel_use_ssc >= 0) |
7240 | return i915.panel_use_ssc != 0; | |
41aa3448 | 7241 | return dev_priv->vbt.lvds_use_ssc |
435793df | 7242 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
a7615030 CW |
7243 | } |
7244 | ||
a93e255f ACO |
7245 | static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state, |
7246 | int num_connectors) | |
c65d77d8 | 7247 | { |
a93e255f | 7248 | struct drm_device *dev = crtc_state->base.crtc->dev; |
c65d77d8 JB |
7249 | struct drm_i915_private *dev_priv = dev->dev_private; |
7250 | int refclk; | |
7251 | ||
a93e255f ACO |
7252 | WARN_ON(!crtc_state->base.state); |
7253 | ||
666a4537 | 7254 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev) || IS_BROXTON(dev)) { |
9a0ea498 | 7255 | refclk = 100000; |
a93e255f | 7256 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
c65d77d8 | 7257 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) { |
e91e941b VS |
7258 | refclk = dev_priv->vbt.lvds_ssc_freq; |
7259 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); | |
c65d77d8 JB |
7260 | } else if (!IS_GEN2(dev)) { |
7261 | refclk = 96000; | |
7262 | } else { | |
7263 | refclk = 48000; | |
7264 | } | |
7265 | ||
7266 | return refclk; | |
7267 | } | |
7268 | ||
7429e9d4 | 7269 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
c65d77d8 | 7270 | { |
7df00d7a | 7271 | return (1 << dpll->n) << 16 | dpll->m2; |
7429e9d4 | 7272 | } |
f47709a9 | 7273 | |
7429e9d4 DV |
7274 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
7275 | { | |
7276 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; | |
c65d77d8 JB |
7277 | } |
7278 | ||
f47709a9 | 7279 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
190f68c5 | 7280 | struct intel_crtc_state *crtc_state, |
a7516a05 JB |
7281 | intel_clock_t *reduced_clock) |
7282 | { | |
f47709a9 | 7283 | struct drm_device *dev = crtc->base.dev; |
a7516a05 JB |
7284 | u32 fp, fp2 = 0; |
7285 | ||
7286 | if (IS_PINEVIEW(dev)) { | |
190f68c5 | 7287 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
a7516a05 | 7288 | if (reduced_clock) |
7429e9d4 | 7289 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
a7516a05 | 7290 | } else { |
190f68c5 | 7291 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
a7516a05 | 7292 | if (reduced_clock) |
7429e9d4 | 7293 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
a7516a05 JB |
7294 | } |
7295 | ||
190f68c5 | 7296 | crtc_state->dpll_hw_state.fp0 = fp; |
a7516a05 | 7297 | |
f47709a9 | 7298 | crtc->lowfreq_avail = false; |
a93e255f | 7299 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
ab585dea | 7300 | reduced_clock) { |
190f68c5 | 7301 | crtc_state->dpll_hw_state.fp1 = fp2; |
f47709a9 | 7302 | crtc->lowfreq_avail = true; |
a7516a05 | 7303 | } else { |
190f68c5 | 7304 | crtc_state->dpll_hw_state.fp1 = fp; |
a7516a05 JB |
7305 | } |
7306 | } | |
7307 | ||
5e69f97f CML |
7308 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
7309 | pipe) | |
89b667f8 JB |
7310 | { |
7311 | u32 reg_val; | |
7312 | ||
7313 | /* | |
7314 | * PLLB opamp always calibrates to max value of 0x3f, force enable it | |
7315 | * and set it to a reasonable value instead. | |
7316 | */ | |
ab3c759a | 7317 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
89b667f8 JB |
7318 | reg_val &= 0xffffff00; |
7319 | reg_val |= 0x00000030; | |
ab3c759a | 7320 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
89b667f8 | 7321 | |
ab3c759a | 7322 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
89b667f8 JB |
7323 | reg_val &= 0x8cffffff; |
7324 | reg_val = 0x8c000000; | |
ab3c759a | 7325 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
89b667f8 | 7326 | |
ab3c759a | 7327 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
89b667f8 | 7328 | reg_val &= 0xffffff00; |
ab3c759a | 7329 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
89b667f8 | 7330 | |
ab3c759a | 7331 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
89b667f8 JB |
7332 | reg_val &= 0x00ffffff; |
7333 | reg_val |= 0xb0000000; | |
ab3c759a | 7334 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
89b667f8 JB |
7335 | } |
7336 | ||
b551842d DV |
7337 | static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc, |
7338 | struct intel_link_m_n *m_n) | |
7339 | { | |
7340 | struct drm_device *dev = crtc->base.dev; | |
7341 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7342 | int pipe = crtc->pipe; | |
7343 | ||
e3b95f1e DV |
7344 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
7345 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); | |
7346 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); | |
7347 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); | |
b551842d DV |
7348 | } |
7349 | ||
7350 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, | |
f769cd24 VK |
7351 | struct intel_link_m_n *m_n, |
7352 | struct intel_link_m_n *m2_n2) | |
b551842d DV |
7353 | { |
7354 | struct drm_device *dev = crtc->base.dev; | |
7355 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7356 | int pipe = crtc->pipe; | |
6e3c9717 | 7357 | enum transcoder transcoder = crtc->config->cpu_transcoder; |
b551842d DV |
7358 | |
7359 | if (INTEL_INFO(dev)->gen >= 5) { | |
7360 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); | |
7361 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); | |
7362 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); | |
7363 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); | |
f769cd24 VK |
7364 | /* M2_N2 registers to be set only for gen < 8 (M2_N2 available |
7365 | * for gen < 8) and if DRRS is supported (to make sure the | |
7366 | * registers are not unnecessarily accessed). | |
7367 | */ | |
44395bfe | 7368 | if (m2_n2 && (IS_CHERRYVIEW(dev) || INTEL_INFO(dev)->gen < 8) && |
6e3c9717 | 7369 | crtc->config->has_drrs) { |
f769cd24 VK |
7370 | I915_WRITE(PIPE_DATA_M2(transcoder), |
7371 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); | |
7372 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); | |
7373 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); | |
7374 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); | |
7375 | } | |
b551842d | 7376 | } else { |
e3b95f1e DV |
7377 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
7378 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); | |
7379 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); | |
7380 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); | |
b551842d DV |
7381 | } |
7382 | } | |
7383 | ||
fe3cd48d | 7384 | void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n) |
03afc4a2 | 7385 | { |
fe3cd48d R |
7386 | struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL; |
7387 | ||
7388 | if (m_n == M1_N1) { | |
7389 | dp_m_n = &crtc->config->dp_m_n; | |
7390 | dp_m2_n2 = &crtc->config->dp_m2_n2; | |
7391 | } else if (m_n == M2_N2) { | |
7392 | ||
7393 | /* | |
7394 | * M2_N2 registers are not supported. Hence m2_n2 divider value | |
7395 | * needs to be programmed into M1_N1. | |
7396 | */ | |
7397 | dp_m_n = &crtc->config->dp_m2_n2; | |
7398 | } else { | |
7399 | DRM_ERROR("Unsupported divider value\n"); | |
7400 | return; | |
7401 | } | |
7402 | ||
6e3c9717 ACO |
7403 | if (crtc->config->has_pch_encoder) |
7404 | intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n); | |
03afc4a2 | 7405 | else |
fe3cd48d | 7406 | intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2); |
03afc4a2 DV |
7407 | } |
7408 | ||
251ac862 DV |
7409 | static void vlv_compute_dpll(struct intel_crtc *crtc, |
7410 | struct intel_crtc_state *pipe_config) | |
bdd4b6a6 DV |
7411 | { |
7412 | u32 dpll, dpll_md; | |
7413 | ||
7414 | /* | |
7415 | * Enable DPIO clock input. We should never disable the reference | |
7416 | * clock for pipe B, since VGA hotplug / manual detection depends | |
7417 | * on it. | |
7418 | */ | |
60bfe44f VS |
7419 | dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REF_CLK_ENABLE_VLV | |
7420 | DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_REF_CLK_VLV; | |
bdd4b6a6 DV |
7421 | /* We should never disable this, set it here for state tracking */ |
7422 | if (crtc->pipe == PIPE_B) | |
7423 | dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
7424 | dpll |= DPLL_VCO_ENABLE; | |
d288f65f | 7425 | pipe_config->dpll_hw_state.dpll = dpll; |
bdd4b6a6 | 7426 | |
d288f65f | 7427 | dpll_md = (pipe_config->pixel_multiplier - 1) |
bdd4b6a6 | 7428 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
d288f65f | 7429 | pipe_config->dpll_hw_state.dpll_md = dpll_md; |
bdd4b6a6 DV |
7430 | } |
7431 | ||
d288f65f | 7432 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 7433 | const struct intel_crtc_state *pipe_config) |
a0c4da24 | 7434 | { |
f47709a9 | 7435 | struct drm_device *dev = crtc->base.dev; |
a0c4da24 | 7436 | struct drm_i915_private *dev_priv = dev->dev_private; |
f47709a9 | 7437 | int pipe = crtc->pipe; |
bdd4b6a6 | 7438 | u32 mdiv; |
a0c4da24 | 7439 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
bdd4b6a6 | 7440 | u32 coreclk, reg_val; |
a0c4da24 | 7441 | |
a580516d | 7442 | mutex_lock(&dev_priv->sb_lock); |
09153000 | 7443 | |
d288f65f VS |
7444 | bestn = pipe_config->dpll.n; |
7445 | bestm1 = pipe_config->dpll.m1; | |
7446 | bestm2 = pipe_config->dpll.m2; | |
7447 | bestp1 = pipe_config->dpll.p1; | |
7448 | bestp2 = pipe_config->dpll.p2; | |
a0c4da24 | 7449 | |
89b667f8 JB |
7450 | /* See eDP HDMI DPIO driver vbios notes doc */ |
7451 | ||
7452 | /* PLL B needs special handling */ | |
bdd4b6a6 | 7453 | if (pipe == PIPE_B) |
5e69f97f | 7454 | vlv_pllb_recal_opamp(dev_priv, pipe); |
89b667f8 JB |
7455 | |
7456 | /* Set up Tx target for periodic Rcomp update */ | |
ab3c759a | 7457 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
89b667f8 JB |
7458 | |
7459 | /* Disable target IRef on PLL */ | |
ab3c759a | 7460 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
89b667f8 | 7461 | reg_val &= 0x00ffffff; |
ab3c759a | 7462 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
89b667f8 JB |
7463 | |
7464 | /* Disable fast lock */ | |
ab3c759a | 7465 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
89b667f8 JB |
7466 | |
7467 | /* Set idtafcrecal before PLL is enabled */ | |
a0c4da24 JB |
7468 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
7469 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); | |
7470 | mdiv |= ((bestn << DPIO_N_SHIFT)); | |
a0c4da24 | 7471 | mdiv |= (1 << DPIO_K_SHIFT); |
7df5080b JB |
7472 | |
7473 | /* | |
7474 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, | |
7475 | * but we don't support that). | |
7476 | * Note: don't use the DAC post divider as it seems unstable. | |
7477 | */ | |
7478 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); | |
ab3c759a | 7479 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
a0c4da24 | 7480 | |
a0c4da24 | 7481 | mdiv |= DPIO_ENABLE_CALIBRATION; |
ab3c759a | 7482 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
a0c4da24 | 7483 | |
89b667f8 | 7484 | /* Set HBR and RBR LPF coefficients */ |
d288f65f | 7485 | if (pipe_config->port_clock == 162000 || |
409ee761 ACO |
7486 | intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG) || |
7487 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) | |
ab3c759a | 7488 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
885b0120 | 7489 | 0x009f0003); |
89b667f8 | 7490 | else |
ab3c759a | 7491 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
89b667f8 JB |
7492 | 0x00d0000f); |
7493 | ||
681a8504 | 7494 | if (pipe_config->has_dp_encoder) { |
89b667f8 | 7495 | /* Use SSC source */ |
bdd4b6a6 | 7496 | if (pipe == PIPE_A) |
ab3c759a | 7497 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7498 | 0x0df40000); |
7499 | else | |
ab3c759a | 7500 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7501 | 0x0df70000); |
7502 | } else { /* HDMI or VGA */ | |
7503 | /* Use bend source */ | |
bdd4b6a6 | 7504 | if (pipe == PIPE_A) |
ab3c759a | 7505 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7506 | 0x0df70000); |
7507 | else | |
ab3c759a | 7508 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7509 | 0x0df40000); |
7510 | } | |
a0c4da24 | 7511 | |
ab3c759a | 7512 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
89b667f8 | 7513 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
409ee761 ACO |
7514 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || |
7515 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) | |
89b667f8 | 7516 | coreclk |= 0x01000000; |
ab3c759a | 7517 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
a0c4da24 | 7518 | |
ab3c759a | 7519 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
a580516d | 7520 | mutex_unlock(&dev_priv->sb_lock); |
a0c4da24 JB |
7521 | } |
7522 | ||
251ac862 DV |
7523 | static void chv_compute_dpll(struct intel_crtc *crtc, |
7524 | struct intel_crtc_state *pipe_config) | |
1ae0d137 | 7525 | { |
60bfe44f VS |
7526 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV | |
7527 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS | | |
1ae0d137 VS |
7528 | DPLL_VCO_ENABLE; |
7529 | if (crtc->pipe != PIPE_A) | |
d288f65f | 7530 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
1ae0d137 | 7531 | |
d288f65f VS |
7532 | pipe_config->dpll_hw_state.dpll_md = |
7533 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; | |
1ae0d137 VS |
7534 | } |
7535 | ||
d288f65f | 7536 | static void chv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 7537 | const struct intel_crtc_state *pipe_config) |
9d556c99 CML |
7538 | { |
7539 | struct drm_device *dev = crtc->base.dev; | |
7540 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7541 | int pipe = crtc->pipe; | |
f0f59a00 | 7542 | i915_reg_t dpll_reg = DPLL(crtc->pipe); |
9d556c99 | 7543 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
9cbe40c1 | 7544 | u32 loopfilter, tribuf_calcntr; |
9d556c99 | 7545 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
a945ce7e | 7546 | u32 dpio_val; |
9cbe40c1 | 7547 | int vco; |
9d556c99 | 7548 | |
d288f65f VS |
7549 | bestn = pipe_config->dpll.n; |
7550 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; | |
7551 | bestm1 = pipe_config->dpll.m1; | |
7552 | bestm2 = pipe_config->dpll.m2 >> 22; | |
7553 | bestp1 = pipe_config->dpll.p1; | |
7554 | bestp2 = pipe_config->dpll.p2; | |
9cbe40c1 | 7555 | vco = pipe_config->dpll.vco; |
a945ce7e | 7556 | dpio_val = 0; |
9cbe40c1 | 7557 | loopfilter = 0; |
9d556c99 CML |
7558 | |
7559 | /* | |
7560 | * Enable Refclk and SSC | |
7561 | */ | |
a11b0703 | 7562 | I915_WRITE(dpll_reg, |
d288f65f | 7563 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
a11b0703 | 7564 | |
a580516d | 7565 | mutex_lock(&dev_priv->sb_lock); |
9d556c99 | 7566 | |
9d556c99 CML |
7567 | /* p1 and p2 divider */ |
7568 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), | |
7569 | 5 << DPIO_CHV_S1_DIV_SHIFT | | |
7570 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | | |
7571 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | | |
7572 | 1 << DPIO_CHV_K_DIV_SHIFT); | |
7573 | ||
7574 | /* Feedback post-divider - m2 */ | |
7575 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); | |
7576 | ||
7577 | /* Feedback refclk divider - n and m1 */ | |
7578 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), | |
7579 | DPIO_CHV_M1_DIV_BY_2 | | |
7580 | 1 << DPIO_CHV_N_DIV_SHIFT); | |
7581 | ||
7582 | /* M2 fraction division */ | |
25a25dfc | 7583 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac); |
9d556c99 CML |
7584 | |
7585 | /* M2 fraction division enable */ | |
a945ce7e VP |
7586 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
7587 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); | |
7588 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); | |
7589 | if (bestm2_frac) | |
7590 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; | |
7591 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val); | |
9d556c99 | 7592 | |
de3a0fde VP |
7593 | /* Program digital lock detect threshold */ |
7594 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); | |
7595 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | | |
7596 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); | |
7597 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); | |
7598 | if (!bestm2_frac) | |
7599 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; | |
7600 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); | |
7601 | ||
9d556c99 | 7602 | /* Loop filter */ |
9cbe40c1 VP |
7603 | if (vco == 5400000) { |
7604 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7605 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); | |
7606 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7607 | tribuf_calcntr = 0x9; | |
7608 | } else if (vco <= 6200000) { | |
7609 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7610 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); | |
7611 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7612 | tribuf_calcntr = 0x9; | |
7613 | } else if (vco <= 6480000) { | |
7614 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7615 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); | |
7616 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7617 | tribuf_calcntr = 0x8; | |
7618 | } else { | |
7619 | /* Not supported. Apply the same limits as in the max case */ | |
7620 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7621 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); | |
7622 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7623 | tribuf_calcntr = 0; | |
7624 | } | |
9d556c99 CML |
7625 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
7626 | ||
968040b2 | 7627 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
9cbe40c1 VP |
7628 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
7629 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); | |
7630 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); | |
7631 | ||
9d556c99 CML |
7632 | /* AFC Recal */ |
7633 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), | |
7634 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | | |
7635 | DPIO_AFC_RECAL); | |
7636 | ||
a580516d | 7637 | mutex_unlock(&dev_priv->sb_lock); |
9d556c99 CML |
7638 | } |
7639 | ||
d288f65f VS |
7640 | /** |
7641 | * vlv_force_pll_on - forcibly enable just the PLL | |
7642 | * @dev_priv: i915 private structure | |
7643 | * @pipe: pipe PLL to enable | |
7644 | * @dpll: PLL configuration | |
7645 | * | |
7646 | * Enable the PLL for @pipe using the supplied @dpll config. To be used | |
7647 | * in cases where we need the PLL enabled even when @pipe is not going to | |
7648 | * be enabled. | |
7649 | */ | |
3f36b937 TU |
7650 | int vlv_force_pll_on(struct drm_device *dev, enum pipe pipe, |
7651 | const struct dpll *dpll) | |
d288f65f VS |
7652 | { |
7653 | struct intel_crtc *crtc = | |
7654 | to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe)); | |
3f36b937 TU |
7655 | struct intel_crtc_state *pipe_config; |
7656 | ||
7657 | pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); | |
7658 | if (!pipe_config) | |
7659 | return -ENOMEM; | |
7660 | ||
7661 | pipe_config->base.crtc = &crtc->base; | |
7662 | pipe_config->pixel_multiplier = 1; | |
7663 | pipe_config->dpll = *dpll; | |
d288f65f VS |
7664 | |
7665 | if (IS_CHERRYVIEW(dev)) { | |
3f36b937 TU |
7666 | chv_compute_dpll(crtc, pipe_config); |
7667 | chv_prepare_pll(crtc, pipe_config); | |
7668 | chv_enable_pll(crtc, pipe_config); | |
d288f65f | 7669 | } else { |
3f36b937 TU |
7670 | vlv_compute_dpll(crtc, pipe_config); |
7671 | vlv_prepare_pll(crtc, pipe_config); | |
7672 | vlv_enable_pll(crtc, pipe_config); | |
d288f65f | 7673 | } |
3f36b937 TU |
7674 | |
7675 | kfree(pipe_config); | |
7676 | ||
7677 | return 0; | |
d288f65f VS |
7678 | } |
7679 | ||
7680 | /** | |
7681 | * vlv_force_pll_off - forcibly disable just the PLL | |
7682 | * @dev_priv: i915 private structure | |
7683 | * @pipe: pipe PLL to disable | |
7684 | * | |
7685 | * Disable the PLL for @pipe. To be used in cases where we need | |
7686 | * the PLL enabled even when @pipe is not going to be enabled. | |
7687 | */ | |
7688 | void vlv_force_pll_off(struct drm_device *dev, enum pipe pipe) | |
7689 | { | |
7690 | if (IS_CHERRYVIEW(dev)) | |
7691 | chv_disable_pll(to_i915(dev), pipe); | |
7692 | else | |
7693 | vlv_disable_pll(to_i915(dev), pipe); | |
7694 | } | |
7695 | ||
251ac862 DV |
7696 | static void i9xx_compute_dpll(struct intel_crtc *crtc, |
7697 | struct intel_crtc_state *crtc_state, | |
7698 | intel_clock_t *reduced_clock, | |
7699 | int num_connectors) | |
eb1cbe48 | 7700 | { |
f47709a9 | 7701 | struct drm_device *dev = crtc->base.dev; |
eb1cbe48 | 7702 | struct drm_i915_private *dev_priv = dev->dev_private; |
eb1cbe48 DV |
7703 | u32 dpll; |
7704 | bool is_sdvo; | |
190f68c5 | 7705 | struct dpll *clock = &crtc_state->dpll; |
eb1cbe48 | 7706 | |
190f68c5 | 7707 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
2a8f64ca | 7708 | |
a93e255f ACO |
7709 | is_sdvo = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO) || |
7710 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI); | |
eb1cbe48 DV |
7711 | |
7712 | dpll = DPLL_VGA_MODE_DIS; | |
7713 | ||
a93e255f | 7714 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
eb1cbe48 DV |
7715 | dpll |= DPLLB_MODE_LVDS; |
7716 | else | |
7717 | dpll |= DPLLB_MODE_DAC_SERIAL; | |
6cc5f341 | 7718 | |
ef1b460d | 7719 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
190f68c5 | 7720 | dpll |= (crtc_state->pixel_multiplier - 1) |
198a037f | 7721 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
eb1cbe48 | 7722 | } |
198a037f DV |
7723 | |
7724 | if (is_sdvo) | |
4a33e48d | 7725 | dpll |= DPLL_SDVO_HIGH_SPEED; |
198a037f | 7726 | |
190f68c5 | 7727 | if (crtc_state->has_dp_encoder) |
4a33e48d | 7728 | dpll |= DPLL_SDVO_HIGH_SPEED; |
eb1cbe48 DV |
7729 | |
7730 | /* compute bitmask from p1 value */ | |
7731 | if (IS_PINEVIEW(dev)) | |
7732 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; | |
7733 | else { | |
7734 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
7735 | if (IS_G4X(dev) && reduced_clock) | |
7736 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; | |
7737 | } | |
7738 | switch (clock->p2) { | |
7739 | case 5: | |
7740 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; | |
7741 | break; | |
7742 | case 7: | |
7743 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; | |
7744 | break; | |
7745 | case 10: | |
7746 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; | |
7747 | break; | |
7748 | case 14: | |
7749 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; | |
7750 | break; | |
7751 | } | |
7752 | if (INTEL_INFO(dev)->gen >= 4) | |
7753 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); | |
7754 | ||
190f68c5 | 7755 | if (crtc_state->sdvo_tv_clock) |
eb1cbe48 | 7756 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
a93e255f | 7757 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
eb1cbe48 DV |
7758 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
7759 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; | |
7760 | else | |
7761 | dpll |= PLL_REF_INPUT_DREFCLK; | |
7762 | ||
7763 | dpll |= DPLL_VCO_ENABLE; | |
190f68c5 | 7764 | crtc_state->dpll_hw_state.dpll = dpll; |
8bcc2795 | 7765 | |
eb1cbe48 | 7766 | if (INTEL_INFO(dev)->gen >= 4) { |
190f68c5 | 7767 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
ef1b460d | 7768 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
190f68c5 | 7769 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
eb1cbe48 DV |
7770 | } |
7771 | } | |
7772 | ||
251ac862 DV |
7773 | static void i8xx_compute_dpll(struct intel_crtc *crtc, |
7774 | struct intel_crtc_state *crtc_state, | |
7775 | intel_clock_t *reduced_clock, | |
7776 | int num_connectors) | |
eb1cbe48 | 7777 | { |
f47709a9 | 7778 | struct drm_device *dev = crtc->base.dev; |
eb1cbe48 | 7779 | struct drm_i915_private *dev_priv = dev->dev_private; |
eb1cbe48 | 7780 | u32 dpll; |
190f68c5 | 7781 | struct dpll *clock = &crtc_state->dpll; |
eb1cbe48 | 7782 | |
190f68c5 | 7783 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
2a8f64ca | 7784 | |
eb1cbe48 DV |
7785 | dpll = DPLL_VGA_MODE_DIS; |
7786 | ||
a93e255f | 7787 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
eb1cbe48 DV |
7788 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
7789 | } else { | |
7790 | if (clock->p1 == 2) | |
7791 | dpll |= PLL_P1_DIVIDE_BY_TWO; | |
7792 | else | |
7793 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
7794 | if (clock->p2 == 4) | |
7795 | dpll |= PLL_P2_DIVIDE_BY_4; | |
7796 | } | |
7797 | ||
a93e255f | 7798 | if (!IS_I830(dev) && intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) |
4a33e48d DV |
7799 | dpll |= DPLL_DVO_2X_MODE; |
7800 | ||
a93e255f | 7801 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
eb1cbe48 DV |
7802 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
7803 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; | |
7804 | else | |
7805 | dpll |= PLL_REF_INPUT_DREFCLK; | |
7806 | ||
7807 | dpll |= DPLL_VCO_ENABLE; | |
190f68c5 | 7808 | crtc_state->dpll_hw_state.dpll = dpll; |
eb1cbe48 DV |
7809 | } |
7810 | ||
8a654f3b | 7811 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc) |
b0e77b9c PZ |
7812 | { |
7813 | struct drm_device *dev = intel_crtc->base.dev; | |
7814 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7815 | enum pipe pipe = intel_crtc->pipe; | |
6e3c9717 | 7816 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
7c5f93b0 | 7817 | const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode; |
1caea6e9 VS |
7818 | uint32_t crtc_vtotal, crtc_vblank_end; |
7819 | int vsyncshift = 0; | |
4d8a62ea DV |
7820 | |
7821 | /* We need to be careful not to changed the adjusted mode, for otherwise | |
7822 | * the hw state checker will get angry at the mismatch. */ | |
7823 | crtc_vtotal = adjusted_mode->crtc_vtotal; | |
7824 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; | |
b0e77b9c | 7825 | |
609aeaca | 7826 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
b0e77b9c | 7827 | /* the chip adds 2 halflines automatically */ |
4d8a62ea DV |
7828 | crtc_vtotal -= 1; |
7829 | crtc_vblank_end -= 1; | |
609aeaca | 7830 | |
409ee761 | 7831 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
609aeaca VS |
7832 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
7833 | else | |
7834 | vsyncshift = adjusted_mode->crtc_hsync_start - | |
7835 | adjusted_mode->crtc_htotal / 2; | |
1caea6e9 VS |
7836 | if (vsyncshift < 0) |
7837 | vsyncshift += adjusted_mode->crtc_htotal; | |
b0e77b9c PZ |
7838 | } |
7839 | ||
7840 | if (INTEL_INFO(dev)->gen > 3) | |
fe2b8f9d | 7841 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
b0e77b9c | 7842 | |
fe2b8f9d | 7843 | I915_WRITE(HTOTAL(cpu_transcoder), |
b0e77b9c PZ |
7844 | (adjusted_mode->crtc_hdisplay - 1) | |
7845 | ((adjusted_mode->crtc_htotal - 1) << 16)); | |
fe2b8f9d | 7846 | I915_WRITE(HBLANK(cpu_transcoder), |
b0e77b9c PZ |
7847 | (adjusted_mode->crtc_hblank_start - 1) | |
7848 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); | |
fe2b8f9d | 7849 | I915_WRITE(HSYNC(cpu_transcoder), |
b0e77b9c PZ |
7850 | (adjusted_mode->crtc_hsync_start - 1) | |
7851 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); | |
7852 | ||
fe2b8f9d | 7853 | I915_WRITE(VTOTAL(cpu_transcoder), |
b0e77b9c | 7854 | (adjusted_mode->crtc_vdisplay - 1) | |
4d8a62ea | 7855 | ((crtc_vtotal - 1) << 16)); |
fe2b8f9d | 7856 | I915_WRITE(VBLANK(cpu_transcoder), |
b0e77b9c | 7857 | (adjusted_mode->crtc_vblank_start - 1) | |
4d8a62ea | 7858 | ((crtc_vblank_end - 1) << 16)); |
fe2b8f9d | 7859 | I915_WRITE(VSYNC(cpu_transcoder), |
b0e77b9c PZ |
7860 | (adjusted_mode->crtc_vsync_start - 1) | |
7861 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); | |
7862 | ||
b5e508d4 PZ |
7863 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
7864 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is | |
7865 | * documented on the DDI_FUNC_CTL register description, EDP Input Select | |
7866 | * bits. */ | |
7867 | if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP && | |
7868 | (pipe == PIPE_B || pipe == PIPE_C)) | |
7869 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); | |
7870 | ||
b0e77b9c PZ |
7871 | /* pipesrc controls the size that is scaled from, which should |
7872 | * always be the user's requested size. | |
7873 | */ | |
7874 | I915_WRITE(PIPESRC(pipe), | |
6e3c9717 ACO |
7875 | ((intel_crtc->config->pipe_src_w - 1) << 16) | |
7876 | (intel_crtc->config->pipe_src_h - 1)); | |
b0e77b9c PZ |
7877 | } |
7878 | ||
1bd1bd80 | 7879 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
5cec258b | 7880 | struct intel_crtc_state *pipe_config) |
1bd1bd80 DV |
7881 | { |
7882 | struct drm_device *dev = crtc->base.dev; | |
7883 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7884 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; | |
7885 | uint32_t tmp; | |
7886 | ||
7887 | tmp = I915_READ(HTOTAL(cpu_transcoder)); | |
2d112de7 ACO |
7888 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
7889 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7890 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
2d112de7 ACO |
7891 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
7892 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7893 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
2d112de7 ACO |
7894 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
7895 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 DV |
7896 | |
7897 | tmp = I915_READ(VTOTAL(cpu_transcoder)); | |
2d112de7 ACO |
7898 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
7899 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7900 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
2d112de7 ACO |
7901 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
7902 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7903 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
2d112de7 ACO |
7904 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
7905 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 DV |
7906 | |
7907 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { | |
2d112de7 ACO |
7908 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
7909 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; | |
7910 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; | |
1bd1bd80 DV |
7911 | } |
7912 | ||
7913 | tmp = I915_READ(PIPESRC(crtc->pipe)); | |
37327abd VS |
7914 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
7915 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; | |
7916 | ||
2d112de7 ACO |
7917 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
7918 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; | |
1bd1bd80 DV |
7919 | } |
7920 | ||
f6a83288 | 7921 | void intel_mode_from_pipe_config(struct drm_display_mode *mode, |
5cec258b | 7922 | struct intel_crtc_state *pipe_config) |
babea61d | 7923 | { |
2d112de7 ACO |
7924 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
7925 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; | |
7926 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; | |
7927 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; | |
babea61d | 7928 | |
2d112de7 ACO |
7929 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
7930 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; | |
7931 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; | |
7932 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; | |
babea61d | 7933 | |
2d112de7 | 7934 | mode->flags = pipe_config->base.adjusted_mode.flags; |
cd13f5ab | 7935 | mode->type = DRM_MODE_TYPE_DRIVER; |
babea61d | 7936 | |
2d112de7 ACO |
7937 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
7938 | mode->flags |= pipe_config->base.adjusted_mode.flags; | |
cd13f5ab ML |
7939 | |
7940 | mode->hsync = drm_mode_hsync(mode); | |
7941 | mode->vrefresh = drm_mode_vrefresh(mode); | |
7942 | drm_mode_set_name(mode); | |
babea61d JB |
7943 | } |
7944 | ||
84b046f3 DV |
7945 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc) |
7946 | { | |
7947 | struct drm_device *dev = intel_crtc->base.dev; | |
7948 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7949 | uint32_t pipeconf; | |
7950 | ||
9f11a9e4 | 7951 | pipeconf = 0; |
84b046f3 | 7952 | |
b6b5d049 VS |
7953 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
7954 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
7955 | pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE; | |
67c72a12 | 7956 | |
6e3c9717 | 7957 | if (intel_crtc->config->double_wide) |
cf532bb2 | 7958 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
84b046f3 | 7959 | |
ff9ce46e | 7960 | /* only g4x and later have fancy bpc/dither controls */ |
666a4537 | 7961 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
ff9ce46e | 7962 | /* Bspec claims that we can't use dithering for 30bpp pipes. */ |
6e3c9717 | 7963 | if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30) |
ff9ce46e | 7964 | pipeconf |= PIPECONF_DITHER_EN | |
84b046f3 | 7965 | PIPECONF_DITHER_TYPE_SP; |
84b046f3 | 7966 | |
6e3c9717 | 7967 | switch (intel_crtc->config->pipe_bpp) { |
ff9ce46e DV |
7968 | case 18: |
7969 | pipeconf |= PIPECONF_6BPC; | |
7970 | break; | |
7971 | case 24: | |
7972 | pipeconf |= PIPECONF_8BPC; | |
7973 | break; | |
7974 | case 30: | |
7975 | pipeconf |= PIPECONF_10BPC; | |
7976 | break; | |
7977 | default: | |
7978 | /* Case prevented by intel_choose_pipe_bpp_dither. */ | |
7979 | BUG(); | |
84b046f3 DV |
7980 | } |
7981 | } | |
7982 | ||
7983 | if (HAS_PIPE_CXSR(dev)) { | |
7984 | if (intel_crtc->lowfreq_avail) { | |
7985 | DRM_DEBUG_KMS("enabling CxSR downclocking\n"); | |
7986 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; | |
7987 | } else { | |
7988 | DRM_DEBUG_KMS("disabling CxSR downclocking\n"); | |
84b046f3 DV |
7989 | } |
7990 | } | |
7991 | ||
6e3c9717 | 7992 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { |
efc2cfff | 7993 | if (INTEL_INFO(dev)->gen < 4 || |
409ee761 | 7994 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
efc2cfff VS |
7995 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
7996 | else | |
7997 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; | |
7998 | } else | |
84b046f3 DV |
7999 | pipeconf |= PIPECONF_PROGRESSIVE; |
8000 | ||
666a4537 WB |
8001 | if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) && |
8002 | intel_crtc->config->limited_color_range) | |
9f11a9e4 | 8003 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
9c8e09b7 | 8004 | |
84b046f3 DV |
8005 | I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf); |
8006 | POSTING_READ(PIPECONF(intel_crtc->pipe)); | |
8007 | } | |
8008 | ||
190f68c5 ACO |
8009 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
8010 | struct intel_crtc_state *crtc_state) | |
79e53945 | 8011 | { |
c7653199 | 8012 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 8013 | struct drm_i915_private *dev_priv = dev->dev_private; |
c751ce4f | 8014 | int refclk, num_connectors = 0; |
c329a4ec DV |
8015 | intel_clock_t clock; |
8016 | bool ok; | |
d4906093 | 8017 | const intel_limit_t *limit; |
55bb9992 | 8018 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 8019 | struct drm_connector *connector; |
55bb9992 ACO |
8020 | struct drm_connector_state *connector_state; |
8021 | int i; | |
79e53945 | 8022 | |
dd3cd74a ACO |
8023 | memset(&crtc_state->dpll_hw_state, 0, |
8024 | sizeof(crtc_state->dpll_hw_state)); | |
8025 | ||
a65347ba JN |
8026 | if (crtc_state->has_dsi_encoder) |
8027 | return 0; | |
43565a06 | 8028 | |
a65347ba JN |
8029 | for_each_connector_in_state(state, connector, connector_state, i) { |
8030 | if (connector_state->crtc == &crtc->base) | |
8031 | num_connectors++; | |
79e53945 JB |
8032 | } |
8033 | ||
190f68c5 | 8034 | if (!crtc_state->clock_set) { |
a93e255f | 8035 | refclk = i9xx_get_refclk(crtc_state, num_connectors); |
79e53945 | 8036 | |
e9fd1c02 JN |
8037 | /* |
8038 | * Returns a set of divisors for the desired target clock with | |
8039 | * the given refclk, or FALSE. The returned values represent | |
8040 | * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + | |
8041 | * 2) / p1 / p2. | |
8042 | */ | |
a93e255f ACO |
8043 | limit = intel_limit(crtc_state, refclk); |
8044 | ok = dev_priv->display.find_dpll(limit, crtc_state, | |
190f68c5 | 8045 | crtc_state->port_clock, |
e9fd1c02 | 8046 | refclk, NULL, &clock); |
f2335330 | 8047 | if (!ok) { |
e9fd1c02 JN |
8048 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
8049 | return -EINVAL; | |
8050 | } | |
79e53945 | 8051 | |
f2335330 | 8052 | /* Compat-code for transition, will disappear. */ |
190f68c5 ACO |
8053 | crtc_state->dpll.n = clock.n; |
8054 | crtc_state->dpll.m1 = clock.m1; | |
8055 | crtc_state->dpll.m2 = clock.m2; | |
8056 | crtc_state->dpll.p1 = clock.p1; | |
8057 | crtc_state->dpll.p2 = clock.p2; | |
f47709a9 | 8058 | } |
7026d4ac | 8059 | |
e9fd1c02 | 8060 | if (IS_GEN2(dev)) { |
c329a4ec | 8061 | i8xx_compute_dpll(crtc, crtc_state, NULL, |
251ac862 | 8062 | num_connectors); |
9d556c99 | 8063 | } else if (IS_CHERRYVIEW(dev)) { |
251ac862 | 8064 | chv_compute_dpll(crtc, crtc_state); |
e9fd1c02 | 8065 | } else if (IS_VALLEYVIEW(dev)) { |
251ac862 | 8066 | vlv_compute_dpll(crtc, crtc_state); |
e9fd1c02 | 8067 | } else { |
c329a4ec | 8068 | i9xx_compute_dpll(crtc, crtc_state, NULL, |
251ac862 | 8069 | num_connectors); |
e9fd1c02 | 8070 | } |
79e53945 | 8071 | |
c8f7a0db | 8072 | return 0; |
f564048e EA |
8073 | } |
8074 | ||
2fa2fe9a | 8075 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 8076 | struct intel_crtc_state *pipe_config) |
2fa2fe9a DV |
8077 | { |
8078 | struct drm_device *dev = crtc->base.dev; | |
8079 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8080 | uint32_t tmp; | |
8081 | ||
dc9e7dec VS |
8082 | if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev))) |
8083 | return; | |
8084 | ||
2fa2fe9a | 8085 | tmp = I915_READ(PFIT_CONTROL); |
06922821 DV |
8086 | if (!(tmp & PFIT_ENABLE)) |
8087 | return; | |
2fa2fe9a | 8088 | |
06922821 | 8089 | /* Check whether the pfit is attached to our pipe. */ |
2fa2fe9a DV |
8090 | if (INTEL_INFO(dev)->gen < 4) { |
8091 | if (crtc->pipe != PIPE_B) | |
8092 | return; | |
2fa2fe9a DV |
8093 | } else { |
8094 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) | |
8095 | return; | |
8096 | } | |
8097 | ||
06922821 | 8098 | pipe_config->gmch_pfit.control = tmp; |
2fa2fe9a DV |
8099 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
8100 | if (INTEL_INFO(dev)->gen < 5) | |
8101 | pipe_config->gmch_pfit.lvds_border_bits = | |
8102 | I915_READ(LVDS) & LVDS_BORDER_ENABLE; | |
8103 | } | |
8104 | ||
acbec814 | 8105 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 8106 | struct intel_crtc_state *pipe_config) |
acbec814 JB |
8107 | { |
8108 | struct drm_device *dev = crtc->base.dev; | |
8109 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8110 | int pipe = pipe_config->cpu_transcoder; | |
8111 | intel_clock_t clock; | |
8112 | u32 mdiv; | |
662c6ecb | 8113 | int refclk = 100000; |
acbec814 | 8114 | |
f573de5a SK |
8115 | /* In case of MIPI DPLL will not even be used */ |
8116 | if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)) | |
8117 | return; | |
8118 | ||
a580516d | 8119 | mutex_lock(&dev_priv->sb_lock); |
ab3c759a | 8120 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
a580516d | 8121 | mutex_unlock(&dev_priv->sb_lock); |
acbec814 JB |
8122 | |
8123 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; | |
8124 | clock.m2 = mdiv & DPIO_M2DIV_MASK; | |
8125 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; | |
8126 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; | |
8127 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; | |
8128 | ||
dccbea3b | 8129 | pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock); |
acbec814 JB |
8130 | } |
8131 | ||
5724dbd1 DL |
8132 | static void |
8133 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, | |
8134 | struct intel_initial_plane_config *plane_config) | |
1ad292b5 JB |
8135 | { |
8136 | struct drm_device *dev = crtc->base.dev; | |
8137 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8138 | u32 val, base, offset; | |
8139 | int pipe = crtc->pipe, plane = crtc->plane; | |
8140 | int fourcc, pixel_format; | |
6761dd31 | 8141 | unsigned int aligned_height; |
b113d5ee | 8142 | struct drm_framebuffer *fb; |
1b842c89 | 8143 | struct intel_framebuffer *intel_fb; |
1ad292b5 | 8144 | |
42a7b088 DL |
8145 | val = I915_READ(DSPCNTR(plane)); |
8146 | if (!(val & DISPLAY_PLANE_ENABLE)) | |
8147 | return; | |
8148 | ||
d9806c9f | 8149 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 8150 | if (!intel_fb) { |
1ad292b5 JB |
8151 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
8152 | return; | |
8153 | } | |
8154 | ||
1b842c89 DL |
8155 | fb = &intel_fb->base; |
8156 | ||
18c5247e DV |
8157 | if (INTEL_INFO(dev)->gen >= 4) { |
8158 | if (val & DISPPLANE_TILED) { | |
49af449b | 8159 | plane_config->tiling = I915_TILING_X; |
18c5247e DV |
8160 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
8161 | } | |
8162 | } | |
1ad292b5 JB |
8163 | |
8164 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; | |
b35d63fa | 8165 | fourcc = i9xx_format_to_fourcc(pixel_format); |
b113d5ee DL |
8166 | fb->pixel_format = fourcc; |
8167 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
1ad292b5 JB |
8168 | |
8169 | if (INTEL_INFO(dev)->gen >= 4) { | |
49af449b | 8170 | if (plane_config->tiling) |
1ad292b5 JB |
8171 | offset = I915_READ(DSPTILEOFF(plane)); |
8172 | else | |
8173 | offset = I915_READ(DSPLINOFF(plane)); | |
8174 | base = I915_READ(DSPSURF(plane)) & 0xfffff000; | |
8175 | } else { | |
8176 | base = I915_READ(DSPADDR(plane)); | |
8177 | } | |
8178 | plane_config->base = base; | |
8179 | ||
8180 | val = I915_READ(PIPESRC(pipe)); | |
b113d5ee DL |
8181 | fb->width = ((val >> 16) & 0xfff) + 1; |
8182 | fb->height = ((val >> 0) & 0xfff) + 1; | |
1ad292b5 JB |
8183 | |
8184 | val = I915_READ(DSPSTRIDE(pipe)); | |
b113d5ee | 8185 | fb->pitches[0] = val & 0xffffffc0; |
1ad292b5 | 8186 | |
b113d5ee | 8187 | aligned_height = intel_fb_align_height(dev, fb->height, |
091df6cb DV |
8188 | fb->pixel_format, |
8189 | fb->modifier[0]); | |
1ad292b5 | 8190 | |
f37b5c2b | 8191 | plane_config->size = fb->pitches[0] * aligned_height; |
1ad292b5 | 8192 | |
2844a921 DL |
8193 | DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
8194 | pipe_name(pipe), plane, fb->width, fb->height, | |
8195 | fb->bits_per_pixel, base, fb->pitches[0], | |
8196 | plane_config->size); | |
1ad292b5 | 8197 | |
2d14030b | 8198 | plane_config->fb = intel_fb; |
1ad292b5 JB |
8199 | } |
8200 | ||
70b23a98 | 8201 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 8202 | struct intel_crtc_state *pipe_config) |
70b23a98 VS |
8203 | { |
8204 | struct drm_device *dev = crtc->base.dev; | |
8205 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8206 | int pipe = pipe_config->cpu_transcoder; | |
8207 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
8208 | intel_clock_t clock; | |
0d7b6b11 | 8209 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3; |
70b23a98 VS |
8210 | int refclk = 100000; |
8211 | ||
a580516d | 8212 | mutex_lock(&dev_priv->sb_lock); |
70b23a98 VS |
8213 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
8214 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); | |
8215 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); | |
8216 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); | |
0d7b6b11 | 8217 | pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
a580516d | 8218 | mutex_unlock(&dev_priv->sb_lock); |
70b23a98 VS |
8219 | |
8220 | clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0; | |
0d7b6b11 ID |
8221 | clock.m2 = (pll_dw0 & 0xff) << 22; |
8222 | if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN) | |
8223 | clock.m2 |= pll_dw2 & 0x3fffff; | |
70b23a98 VS |
8224 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; |
8225 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; | |
8226 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; | |
8227 | ||
dccbea3b | 8228 | pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock); |
70b23a98 VS |
8229 | } |
8230 | ||
0e8ffe1b | 8231 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 8232 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
8233 | { |
8234 | struct drm_device *dev = crtc->base.dev; | |
8235 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1729050e | 8236 | enum intel_display_power_domain power_domain; |
0e8ffe1b | 8237 | uint32_t tmp; |
1729050e | 8238 | bool ret; |
0e8ffe1b | 8239 | |
1729050e ID |
8240 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
8241 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) | |
b5482bd0 ID |
8242 | return false; |
8243 | ||
e143a21c | 8244 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 | 8245 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
eccb140b | 8246 | |
1729050e ID |
8247 | ret = false; |
8248 | ||
0e8ffe1b DV |
8249 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
8250 | if (!(tmp & PIPECONF_ENABLE)) | |
1729050e | 8251 | goto out; |
0e8ffe1b | 8252 | |
666a4537 | 8253 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
42571aef VS |
8254 | switch (tmp & PIPECONF_BPC_MASK) { |
8255 | case PIPECONF_6BPC: | |
8256 | pipe_config->pipe_bpp = 18; | |
8257 | break; | |
8258 | case PIPECONF_8BPC: | |
8259 | pipe_config->pipe_bpp = 24; | |
8260 | break; | |
8261 | case PIPECONF_10BPC: | |
8262 | pipe_config->pipe_bpp = 30; | |
8263 | break; | |
8264 | default: | |
8265 | break; | |
8266 | } | |
8267 | } | |
8268 | ||
666a4537 WB |
8269 | if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) && |
8270 | (tmp & PIPECONF_COLOR_RANGE_SELECT)) | |
b5a9fa09 DV |
8271 | pipe_config->limited_color_range = true; |
8272 | ||
282740f7 VS |
8273 | if (INTEL_INFO(dev)->gen < 4) |
8274 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; | |
8275 | ||
1bd1bd80 DV |
8276 | intel_get_pipe_timings(crtc, pipe_config); |
8277 | ||
2fa2fe9a DV |
8278 | i9xx_get_pfit_config(crtc, pipe_config); |
8279 | ||
6c49f241 DV |
8280 | if (INTEL_INFO(dev)->gen >= 4) { |
8281 | tmp = I915_READ(DPLL_MD(crtc->pipe)); | |
8282 | pipe_config->pixel_multiplier = | |
8283 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) | |
8284 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; | |
8bcc2795 | 8285 | pipe_config->dpll_hw_state.dpll_md = tmp; |
6c49f241 DV |
8286 | } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
8287 | tmp = I915_READ(DPLL(crtc->pipe)); | |
8288 | pipe_config->pixel_multiplier = | |
8289 | ((tmp & SDVO_MULTIPLIER_MASK) | |
8290 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; | |
8291 | } else { | |
8292 | /* Note that on i915G/GM the pixel multiplier is in the sdvo | |
8293 | * port and will be fixed up in the encoder->get_config | |
8294 | * function. */ | |
8295 | pipe_config->pixel_multiplier = 1; | |
8296 | } | |
8bcc2795 | 8297 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
666a4537 | 8298 | if (!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) { |
1c4e0274 VS |
8299 | /* |
8300 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs | |
8301 | * on 830. Filter it out here so that we don't | |
8302 | * report errors due to that. | |
8303 | */ | |
8304 | if (IS_I830(dev)) | |
8305 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; | |
8306 | ||
8bcc2795 DV |
8307 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
8308 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); | |
165e901c VS |
8309 | } else { |
8310 | /* Mask out read-only status bits. */ | |
8311 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | | |
8312 | DPLL_PORTC_READY_MASK | | |
8313 | DPLL_PORTB_READY_MASK); | |
8bcc2795 | 8314 | } |
6c49f241 | 8315 | |
70b23a98 VS |
8316 | if (IS_CHERRYVIEW(dev)) |
8317 | chv_crtc_clock_get(crtc, pipe_config); | |
8318 | else if (IS_VALLEYVIEW(dev)) | |
acbec814 JB |
8319 | vlv_crtc_clock_get(crtc, pipe_config); |
8320 | else | |
8321 | i9xx_crtc_clock_get(crtc, pipe_config); | |
18442d08 | 8322 | |
0f64614d VS |
8323 | /* |
8324 | * Normally the dotclock is filled in by the encoder .get_config() | |
8325 | * but in case the pipe is enabled w/o any ports we need a sane | |
8326 | * default. | |
8327 | */ | |
8328 | pipe_config->base.adjusted_mode.crtc_clock = | |
8329 | pipe_config->port_clock / pipe_config->pixel_multiplier; | |
8330 | ||
1729050e ID |
8331 | ret = true; |
8332 | ||
8333 | out: | |
8334 | intel_display_power_put(dev_priv, power_domain); | |
8335 | ||
8336 | return ret; | |
0e8ffe1b DV |
8337 | } |
8338 | ||
dde86e2d | 8339 | static void ironlake_init_pch_refclk(struct drm_device *dev) |
13d83a67 JB |
8340 | { |
8341 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13d83a67 | 8342 | struct intel_encoder *encoder; |
74cfd7ac | 8343 | u32 val, final; |
13d83a67 | 8344 | bool has_lvds = false; |
199e5d79 | 8345 | bool has_cpu_edp = false; |
199e5d79 | 8346 | bool has_panel = false; |
99eb6a01 KP |
8347 | bool has_ck505 = false; |
8348 | bool can_ssc = false; | |
13d83a67 JB |
8349 | |
8350 | /* We need to take the global config into account */ | |
b2784e15 | 8351 | for_each_intel_encoder(dev, encoder) { |
199e5d79 KP |
8352 | switch (encoder->type) { |
8353 | case INTEL_OUTPUT_LVDS: | |
8354 | has_panel = true; | |
8355 | has_lvds = true; | |
8356 | break; | |
8357 | case INTEL_OUTPUT_EDP: | |
8358 | has_panel = true; | |
2de6905f | 8359 | if (enc_to_dig_port(&encoder->base)->port == PORT_A) |
199e5d79 KP |
8360 | has_cpu_edp = true; |
8361 | break; | |
6847d71b PZ |
8362 | default: |
8363 | break; | |
13d83a67 JB |
8364 | } |
8365 | } | |
8366 | ||
99eb6a01 | 8367 | if (HAS_PCH_IBX(dev)) { |
41aa3448 | 8368 | has_ck505 = dev_priv->vbt.display_clock_mode; |
99eb6a01 KP |
8369 | can_ssc = has_ck505; |
8370 | } else { | |
8371 | has_ck505 = false; | |
8372 | can_ssc = true; | |
8373 | } | |
8374 | ||
2de6905f ID |
8375 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n", |
8376 | has_panel, has_lvds, has_ck505); | |
13d83a67 JB |
8377 | |
8378 | /* Ironlake: try to setup display ref clock before DPLL | |
8379 | * enabling. This is only under driver's control after | |
8380 | * PCH B stepping, previous chipset stepping should be | |
8381 | * ignoring this setting. | |
8382 | */ | |
74cfd7ac CW |
8383 | val = I915_READ(PCH_DREF_CONTROL); |
8384 | ||
8385 | /* As we must carefully and slowly disable/enable each source in turn, | |
8386 | * compute the final state we want first and check if we need to | |
8387 | * make any changes at all. | |
8388 | */ | |
8389 | final = val; | |
8390 | final &= ~DREF_NONSPREAD_SOURCE_MASK; | |
8391 | if (has_ck505) | |
8392 | final |= DREF_NONSPREAD_CK505_ENABLE; | |
8393 | else | |
8394 | final |= DREF_NONSPREAD_SOURCE_ENABLE; | |
8395 | ||
8396 | final &= ~DREF_SSC_SOURCE_MASK; | |
8397 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; | |
8398 | final &= ~DREF_SSC1_ENABLE; | |
8399 | ||
8400 | if (has_panel) { | |
8401 | final |= DREF_SSC_SOURCE_ENABLE; | |
8402 | ||
8403 | if (intel_panel_use_ssc(dev_priv) && can_ssc) | |
8404 | final |= DREF_SSC1_ENABLE; | |
8405 | ||
8406 | if (has_cpu_edp) { | |
8407 | if (intel_panel_use_ssc(dev_priv) && can_ssc) | |
8408 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; | |
8409 | else | |
8410 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; | |
8411 | } else | |
8412 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; | |
8413 | } else { | |
8414 | final |= DREF_SSC_SOURCE_DISABLE; | |
8415 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; | |
8416 | } | |
8417 | ||
8418 | if (final == val) | |
8419 | return; | |
8420 | ||
13d83a67 | 8421 | /* Always enable nonspread source */ |
74cfd7ac | 8422 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
13d83a67 | 8423 | |
99eb6a01 | 8424 | if (has_ck505) |
74cfd7ac | 8425 | val |= DREF_NONSPREAD_CK505_ENABLE; |
99eb6a01 | 8426 | else |
74cfd7ac | 8427 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
13d83a67 | 8428 | |
199e5d79 | 8429 | if (has_panel) { |
74cfd7ac CW |
8430 | val &= ~DREF_SSC_SOURCE_MASK; |
8431 | val |= DREF_SSC_SOURCE_ENABLE; | |
13d83a67 | 8432 | |
199e5d79 | 8433 | /* SSC must be turned on before enabling the CPU output */ |
99eb6a01 | 8434 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
199e5d79 | 8435 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
74cfd7ac | 8436 | val |= DREF_SSC1_ENABLE; |
e77166b5 | 8437 | } else |
74cfd7ac | 8438 | val &= ~DREF_SSC1_ENABLE; |
199e5d79 KP |
8439 | |
8440 | /* Get SSC going before enabling the outputs */ | |
74cfd7ac | 8441 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8442 | POSTING_READ(PCH_DREF_CONTROL); |
8443 | udelay(200); | |
8444 | ||
74cfd7ac | 8445 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
13d83a67 JB |
8446 | |
8447 | /* Enable CPU source on CPU attached eDP */ | |
199e5d79 | 8448 | if (has_cpu_edp) { |
99eb6a01 | 8449 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
199e5d79 | 8450 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
74cfd7ac | 8451 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
eba905b2 | 8452 | } else |
74cfd7ac | 8453 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
199e5d79 | 8454 | } else |
74cfd7ac | 8455 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
199e5d79 | 8456 | |
74cfd7ac | 8457 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8458 | POSTING_READ(PCH_DREF_CONTROL); |
8459 | udelay(200); | |
8460 | } else { | |
8461 | DRM_DEBUG_KMS("Disabling SSC entirely\n"); | |
8462 | ||
74cfd7ac | 8463 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
199e5d79 KP |
8464 | |
8465 | /* Turn off CPU output */ | |
74cfd7ac | 8466 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
199e5d79 | 8467 | |
74cfd7ac | 8468 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8469 | POSTING_READ(PCH_DREF_CONTROL); |
8470 | udelay(200); | |
8471 | ||
8472 | /* Turn off the SSC source */ | |
74cfd7ac CW |
8473 | val &= ~DREF_SSC_SOURCE_MASK; |
8474 | val |= DREF_SSC_SOURCE_DISABLE; | |
199e5d79 KP |
8475 | |
8476 | /* Turn off SSC1 */ | |
74cfd7ac | 8477 | val &= ~DREF_SSC1_ENABLE; |
199e5d79 | 8478 | |
74cfd7ac | 8479 | I915_WRITE(PCH_DREF_CONTROL, val); |
13d83a67 JB |
8480 | POSTING_READ(PCH_DREF_CONTROL); |
8481 | udelay(200); | |
8482 | } | |
74cfd7ac CW |
8483 | |
8484 | BUG_ON(val != final); | |
13d83a67 JB |
8485 | } |
8486 | ||
f31f2d55 | 8487 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
dde86e2d | 8488 | { |
f31f2d55 | 8489 | uint32_t tmp; |
dde86e2d | 8490 | |
0ff066a9 PZ |
8491 | tmp = I915_READ(SOUTH_CHICKEN2); |
8492 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; | |
8493 | I915_WRITE(SOUTH_CHICKEN2, tmp); | |
dde86e2d | 8494 | |
0ff066a9 PZ |
8495 | if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) & |
8496 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) | |
8497 | DRM_ERROR("FDI mPHY reset assert timeout\n"); | |
dde86e2d | 8498 | |
0ff066a9 PZ |
8499 | tmp = I915_READ(SOUTH_CHICKEN2); |
8500 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; | |
8501 | I915_WRITE(SOUTH_CHICKEN2, tmp); | |
dde86e2d | 8502 | |
0ff066a9 PZ |
8503 | if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) & |
8504 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) | |
8505 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); | |
f31f2d55 PZ |
8506 | } |
8507 | ||
8508 | /* WaMPhyProgramming:hsw */ | |
8509 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) | |
8510 | { | |
8511 | uint32_t tmp; | |
dde86e2d PZ |
8512 | |
8513 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); | |
8514 | tmp &= ~(0xFF << 24); | |
8515 | tmp |= (0x12 << 24); | |
8516 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); | |
8517 | ||
dde86e2d PZ |
8518 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
8519 | tmp |= (1 << 11); | |
8520 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); | |
8521 | ||
8522 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); | |
8523 | tmp |= (1 << 11); | |
8524 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); | |
8525 | ||
dde86e2d PZ |
8526 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
8527 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); | |
8528 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); | |
8529 | ||
8530 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); | |
8531 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); | |
8532 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); | |
8533 | ||
0ff066a9 PZ |
8534 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
8535 | tmp &= ~(7 << 13); | |
8536 | tmp |= (5 << 13); | |
8537 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); | |
dde86e2d | 8538 | |
0ff066a9 PZ |
8539 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
8540 | tmp &= ~(7 << 13); | |
8541 | tmp |= (5 << 13); | |
8542 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); | |
dde86e2d PZ |
8543 | |
8544 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); | |
8545 | tmp &= ~0xFF; | |
8546 | tmp |= 0x1C; | |
8547 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); | |
8548 | ||
8549 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); | |
8550 | tmp &= ~0xFF; | |
8551 | tmp |= 0x1C; | |
8552 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); | |
8553 | ||
8554 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); | |
8555 | tmp &= ~(0xFF << 16); | |
8556 | tmp |= (0x1C << 16); | |
8557 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); | |
8558 | ||
8559 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); | |
8560 | tmp &= ~(0xFF << 16); | |
8561 | tmp |= (0x1C << 16); | |
8562 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); | |
8563 | ||
0ff066a9 PZ |
8564 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
8565 | tmp |= (1 << 27); | |
8566 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); | |
dde86e2d | 8567 | |
0ff066a9 PZ |
8568 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
8569 | tmp |= (1 << 27); | |
8570 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); | |
dde86e2d | 8571 | |
0ff066a9 PZ |
8572 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
8573 | tmp &= ~(0xF << 28); | |
8574 | tmp |= (4 << 28); | |
8575 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); | |
dde86e2d | 8576 | |
0ff066a9 PZ |
8577 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
8578 | tmp &= ~(0xF << 28); | |
8579 | tmp |= (4 << 28); | |
8580 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); | |
f31f2d55 PZ |
8581 | } |
8582 | ||
2fa86a1f PZ |
8583 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
8584 | * Programming" based on the parameters passed: | |
8585 | * - Sequence to enable CLKOUT_DP | |
8586 | * - Sequence to enable CLKOUT_DP without spread | |
8587 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O | |
8588 | */ | |
8589 | static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread, | |
8590 | bool with_fdi) | |
f31f2d55 PZ |
8591 | { |
8592 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2fa86a1f PZ |
8593 | uint32_t reg, tmp; |
8594 | ||
8595 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) | |
8596 | with_spread = true; | |
c2699524 | 8597 | if (WARN(HAS_PCH_LPT_LP(dev) && with_fdi, "LP PCH doesn't have FDI\n")) |
2fa86a1f | 8598 | with_fdi = false; |
f31f2d55 | 8599 | |
a580516d | 8600 | mutex_lock(&dev_priv->sb_lock); |
f31f2d55 PZ |
8601 | |
8602 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8603 | tmp &= ~SBI_SSCCTL_DISABLE; | |
8604 | tmp |= SBI_SSCCTL_PATHALT; | |
8605 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8606 | ||
8607 | udelay(24); | |
8608 | ||
2fa86a1f PZ |
8609 | if (with_spread) { |
8610 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8611 | tmp &= ~SBI_SSCCTL_PATHALT; | |
8612 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
f31f2d55 | 8613 | |
2fa86a1f PZ |
8614 | if (with_fdi) { |
8615 | lpt_reset_fdi_mphy(dev_priv); | |
8616 | lpt_program_fdi_mphy(dev_priv); | |
8617 | } | |
8618 | } | |
dde86e2d | 8619 | |
c2699524 | 8620 | reg = HAS_PCH_LPT_LP(dev) ? SBI_GEN0 : SBI_DBUFF0; |
2fa86a1f PZ |
8621 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
8622 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; | |
8623 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); | |
c00db246 | 8624 | |
a580516d | 8625 | mutex_unlock(&dev_priv->sb_lock); |
dde86e2d PZ |
8626 | } |
8627 | ||
47701c3b PZ |
8628 | /* Sequence to disable CLKOUT_DP */ |
8629 | static void lpt_disable_clkout_dp(struct drm_device *dev) | |
8630 | { | |
8631 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8632 | uint32_t reg, tmp; | |
8633 | ||
a580516d | 8634 | mutex_lock(&dev_priv->sb_lock); |
47701c3b | 8635 | |
c2699524 | 8636 | reg = HAS_PCH_LPT_LP(dev) ? SBI_GEN0 : SBI_DBUFF0; |
47701c3b PZ |
8637 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
8638 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; | |
8639 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); | |
8640 | ||
8641 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8642 | if (!(tmp & SBI_SSCCTL_DISABLE)) { | |
8643 | if (!(tmp & SBI_SSCCTL_PATHALT)) { | |
8644 | tmp |= SBI_SSCCTL_PATHALT; | |
8645 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8646 | udelay(32); | |
8647 | } | |
8648 | tmp |= SBI_SSCCTL_DISABLE; | |
8649 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8650 | } | |
8651 | ||
a580516d | 8652 | mutex_unlock(&dev_priv->sb_lock); |
47701c3b PZ |
8653 | } |
8654 | ||
f7be2c21 VS |
8655 | #define BEND_IDX(steps) ((50 + (steps)) / 5) |
8656 | ||
8657 | static const uint16_t sscdivintphase[] = { | |
8658 | [BEND_IDX( 50)] = 0x3B23, | |
8659 | [BEND_IDX( 45)] = 0x3B23, | |
8660 | [BEND_IDX( 40)] = 0x3C23, | |
8661 | [BEND_IDX( 35)] = 0x3C23, | |
8662 | [BEND_IDX( 30)] = 0x3D23, | |
8663 | [BEND_IDX( 25)] = 0x3D23, | |
8664 | [BEND_IDX( 20)] = 0x3E23, | |
8665 | [BEND_IDX( 15)] = 0x3E23, | |
8666 | [BEND_IDX( 10)] = 0x3F23, | |
8667 | [BEND_IDX( 5)] = 0x3F23, | |
8668 | [BEND_IDX( 0)] = 0x0025, | |
8669 | [BEND_IDX( -5)] = 0x0025, | |
8670 | [BEND_IDX(-10)] = 0x0125, | |
8671 | [BEND_IDX(-15)] = 0x0125, | |
8672 | [BEND_IDX(-20)] = 0x0225, | |
8673 | [BEND_IDX(-25)] = 0x0225, | |
8674 | [BEND_IDX(-30)] = 0x0325, | |
8675 | [BEND_IDX(-35)] = 0x0325, | |
8676 | [BEND_IDX(-40)] = 0x0425, | |
8677 | [BEND_IDX(-45)] = 0x0425, | |
8678 | [BEND_IDX(-50)] = 0x0525, | |
8679 | }; | |
8680 | ||
8681 | /* | |
8682 | * Bend CLKOUT_DP | |
8683 | * steps -50 to 50 inclusive, in steps of 5 | |
8684 | * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz) | |
8685 | * change in clock period = -(steps / 10) * 5.787 ps | |
8686 | */ | |
8687 | static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps) | |
8688 | { | |
8689 | uint32_t tmp; | |
8690 | int idx = BEND_IDX(steps); | |
8691 | ||
8692 | if (WARN_ON(steps % 5 != 0)) | |
8693 | return; | |
8694 | ||
8695 | if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase))) | |
8696 | return; | |
8697 | ||
8698 | mutex_lock(&dev_priv->sb_lock); | |
8699 | ||
8700 | if (steps % 10 != 0) | |
8701 | tmp = 0xAAAAAAAB; | |
8702 | else | |
8703 | tmp = 0x00000000; | |
8704 | intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK); | |
8705 | ||
8706 | tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK); | |
8707 | tmp &= 0xffff0000; | |
8708 | tmp |= sscdivintphase[idx]; | |
8709 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK); | |
8710 | ||
8711 | mutex_unlock(&dev_priv->sb_lock); | |
8712 | } | |
8713 | ||
8714 | #undef BEND_IDX | |
8715 | ||
bf8fa3d3 PZ |
8716 | static void lpt_init_pch_refclk(struct drm_device *dev) |
8717 | { | |
bf8fa3d3 PZ |
8718 | struct intel_encoder *encoder; |
8719 | bool has_vga = false; | |
8720 | ||
b2784e15 | 8721 | for_each_intel_encoder(dev, encoder) { |
bf8fa3d3 PZ |
8722 | switch (encoder->type) { |
8723 | case INTEL_OUTPUT_ANALOG: | |
8724 | has_vga = true; | |
8725 | break; | |
6847d71b PZ |
8726 | default: |
8727 | break; | |
bf8fa3d3 PZ |
8728 | } |
8729 | } | |
8730 | ||
f7be2c21 VS |
8731 | if (has_vga) { |
8732 | lpt_bend_clkout_dp(to_i915(dev), 0); | |
47701c3b | 8733 | lpt_enable_clkout_dp(dev, true, true); |
f7be2c21 | 8734 | } else { |
47701c3b | 8735 | lpt_disable_clkout_dp(dev); |
f7be2c21 | 8736 | } |
bf8fa3d3 PZ |
8737 | } |
8738 | ||
dde86e2d PZ |
8739 | /* |
8740 | * Initialize reference clocks when the driver loads | |
8741 | */ | |
8742 | void intel_init_pch_refclk(struct drm_device *dev) | |
8743 | { | |
8744 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) | |
8745 | ironlake_init_pch_refclk(dev); | |
8746 | else if (HAS_PCH_LPT(dev)) | |
8747 | lpt_init_pch_refclk(dev); | |
8748 | } | |
8749 | ||
55bb9992 | 8750 | static int ironlake_get_refclk(struct intel_crtc_state *crtc_state) |
d9d444cb | 8751 | { |
55bb9992 | 8752 | struct drm_device *dev = crtc_state->base.crtc->dev; |
d9d444cb | 8753 | struct drm_i915_private *dev_priv = dev->dev_private; |
55bb9992 | 8754 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 8755 | struct drm_connector *connector; |
55bb9992 | 8756 | struct drm_connector_state *connector_state; |
d9d444cb | 8757 | struct intel_encoder *encoder; |
55bb9992 | 8758 | int num_connectors = 0, i; |
d9d444cb JB |
8759 | bool is_lvds = false; |
8760 | ||
da3ced29 | 8761 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
8762 | if (connector_state->crtc != crtc_state->base.crtc) |
8763 | continue; | |
8764 | ||
8765 | encoder = to_intel_encoder(connector_state->best_encoder); | |
8766 | ||
d9d444cb JB |
8767 | switch (encoder->type) { |
8768 | case INTEL_OUTPUT_LVDS: | |
8769 | is_lvds = true; | |
8770 | break; | |
6847d71b PZ |
8771 | default: |
8772 | break; | |
d9d444cb JB |
8773 | } |
8774 | num_connectors++; | |
8775 | } | |
8776 | ||
8777 | if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) { | |
e91e941b | 8778 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
41aa3448 | 8779 | dev_priv->vbt.lvds_ssc_freq); |
e91e941b | 8780 | return dev_priv->vbt.lvds_ssc_freq; |
d9d444cb JB |
8781 | } |
8782 | ||
8783 | return 120000; | |
8784 | } | |
8785 | ||
6ff93609 | 8786 | static void ironlake_set_pipeconf(struct drm_crtc *crtc) |
79e53945 | 8787 | { |
c8203565 | 8788 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
79e53945 JB |
8789 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8790 | int pipe = intel_crtc->pipe; | |
c8203565 PZ |
8791 | uint32_t val; |
8792 | ||
78114071 | 8793 | val = 0; |
c8203565 | 8794 | |
6e3c9717 | 8795 | switch (intel_crtc->config->pipe_bpp) { |
c8203565 | 8796 | case 18: |
dfd07d72 | 8797 | val |= PIPECONF_6BPC; |
c8203565 PZ |
8798 | break; |
8799 | case 24: | |
dfd07d72 | 8800 | val |= PIPECONF_8BPC; |
c8203565 PZ |
8801 | break; |
8802 | case 30: | |
dfd07d72 | 8803 | val |= PIPECONF_10BPC; |
c8203565 PZ |
8804 | break; |
8805 | case 36: | |
dfd07d72 | 8806 | val |= PIPECONF_12BPC; |
c8203565 PZ |
8807 | break; |
8808 | default: | |
cc769b62 PZ |
8809 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
8810 | BUG(); | |
c8203565 PZ |
8811 | } |
8812 | ||
6e3c9717 | 8813 | if (intel_crtc->config->dither) |
c8203565 PZ |
8814 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
8815 | ||
6e3c9717 | 8816 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
c8203565 PZ |
8817 | val |= PIPECONF_INTERLACED_ILK; |
8818 | else | |
8819 | val |= PIPECONF_PROGRESSIVE; | |
8820 | ||
6e3c9717 | 8821 | if (intel_crtc->config->limited_color_range) |
3685a8f3 | 8822 | val |= PIPECONF_COLOR_RANGE_SELECT; |
3685a8f3 | 8823 | |
c8203565 PZ |
8824 | I915_WRITE(PIPECONF(pipe), val); |
8825 | POSTING_READ(PIPECONF(pipe)); | |
8826 | } | |
8827 | ||
86d3efce VS |
8828 | /* |
8829 | * Set up the pipe CSC unit. | |
8830 | * | |
8831 | * Currently only full range RGB to limited range RGB conversion | |
8832 | * is supported, but eventually this should handle various | |
8833 | * RGB<->YCbCr scenarios as well. | |
8834 | */ | |
50f3b016 | 8835 | static void intel_set_pipe_csc(struct drm_crtc *crtc) |
86d3efce VS |
8836 | { |
8837 | struct drm_device *dev = crtc->dev; | |
8838 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8839 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
8840 | int pipe = intel_crtc->pipe; | |
8841 | uint16_t coeff = 0x7800; /* 1.0 */ | |
8842 | ||
8843 | /* | |
8844 | * TODO: Check what kind of values actually come out of the pipe | |
8845 | * with these coeff/postoff values and adjust to get the best | |
8846 | * accuracy. Perhaps we even need to take the bpc value into | |
8847 | * consideration. | |
8848 | */ | |
8849 | ||
6e3c9717 | 8850 | if (intel_crtc->config->limited_color_range) |
86d3efce VS |
8851 | coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */ |
8852 | ||
8853 | /* | |
8854 | * GY/GU and RY/RU should be the other way around according | |
8855 | * to BSpec, but reality doesn't agree. Just set them up in | |
8856 | * a way that results in the correct picture. | |
8857 | */ | |
8858 | I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16); | |
8859 | I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0); | |
8860 | ||
8861 | I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff); | |
8862 | I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0); | |
8863 | ||
8864 | I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0); | |
8865 | I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16); | |
8866 | ||
8867 | I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0); | |
8868 | I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0); | |
8869 | I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0); | |
8870 | ||
8871 | if (INTEL_INFO(dev)->gen > 6) { | |
8872 | uint16_t postoff = 0; | |
8873 | ||
6e3c9717 | 8874 | if (intel_crtc->config->limited_color_range) |
32cf0cb0 | 8875 | postoff = (16 * (1 << 12) / 255) & 0x1fff; |
86d3efce VS |
8876 | |
8877 | I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff); | |
8878 | I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff); | |
8879 | I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff); | |
8880 | ||
8881 | I915_WRITE(PIPE_CSC_MODE(pipe), 0); | |
8882 | } else { | |
8883 | uint32_t mode = CSC_MODE_YUV_TO_RGB; | |
8884 | ||
6e3c9717 | 8885 | if (intel_crtc->config->limited_color_range) |
86d3efce VS |
8886 | mode |= CSC_BLACK_SCREEN_OFFSET; |
8887 | ||
8888 | I915_WRITE(PIPE_CSC_MODE(pipe), mode); | |
8889 | } | |
8890 | } | |
8891 | ||
6ff93609 | 8892 | static void haswell_set_pipeconf(struct drm_crtc *crtc) |
ee2b0b38 | 8893 | { |
756f85cf PZ |
8894 | struct drm_device *dev = crtc->dev; |
8895 | struct drm_i915_private *dev_priv = dev->dev_private; | |
ee2b0b38 | 8896 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
756f85cf | 8897 | enum pipe pipe = intel_crtc->pipe; |
6e3c9717 | 8898 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
ee2b0b38 PZ |
8899 | uint32_t val; |
8900 | ||
3eff4faa | 8901 | val = 0; |
ee2b0b38 | 8902 | |
6e3c9717 | 8903 | if (IS_HASWELL(dev) && intel_crtc->config->dither) |
ee2b0b38 PZ |
8904 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
8905 | ||
6e3c9717 | 8906 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
ee2b0b38 PZ |
8907 | val |= PIPECONF_INTERLACED_ILK; |
8908 | else | |
8909 | val |= PIPECONF_PROGRESSIVE; | |
8910 | ||
702e7a56 PZ |
8911 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
8912 | POSTING_READ(PIPECONF(cpu_transcoder)); | |
3eff4faa DV |
8913 | |
8914 | I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT); | |
8915 | POSTING_READ(GAMMA_MODE(intel_crtc->pipe)); | |
756f85cf | 8916 | |
3cdf122c | 8917 | if (IS_BROADWELL(dev) || INTEL_INFO(dev)->gen >= 9) { |
756f85cf PZ |
8918 | val = 0; |
8919 | ||
6e3c9717 | 8920 | switch (intel_crtc->config->pipe_bpp) { |
756f85cf PZ |
8921 | case 18: |
8922 | val |= PIPEMISC_DITHER_6_BPC; | |
8923 | break; | |
8924 | case 24: | |
8925 | val |= PIPEMISC_DITHER_8_BPC; | |
8926 | break; | |
8927 | case 30: | |
8928 | val |= PIPEMISC_DITHER_10_BPC; | |
8929 | break; | |
8930 | case 36: | |
8931 | val |= PIPEMISC_DITHER_12_BPC; | |
8932 | break; | |
8933 | default: | |
8934 | /* Case prevented by pipe_config_set_bpp. */ | |
8935 | BUG(); | |
8936 | } | |
8937 | ||
6e3c9717 | 8938 | if (intel_crtc->config->dither) |
756f85cf PZ |
8939 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
8940 | ||
8941 | I915_WRITE(PIPEMISC(pipe), val); | |
8942 | } | |
ee2b0b38 PZ |
8943 | } |
8944 | ||
6591c6e4 | 8945 | static bool ironlake_compute_clocks(struct drm_crtc *crtc, |
190f68c5 | 8946 | struct intel_crtc_state *crtc_state, |
6591c6e4 PZ |
8947 | intel_clock_t *clock, |
8948 | bool *has_reduced_clock, | |
8949 | intel_clock_t *reduced_clock) | |
8950 | { | |
8951 | struct drm_device *dev = crtc->dev; | |
8952 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6591c6e4 | 8953 | int refclk; |
d4906093 | 8954 | const intel_limit_t *limit; |
c329a4ec | 8955 | bool ret; |
79e53945 | 8956 | |
55bb9992 | 8957 | refclk = ironlake_get_refclk(crtc_state); |
79e53945 | 8958 | |
d4906093 ML |
8959 | /* |
8960 | * Returns a set of divisors for the desired target clock with the given | |
8961 | * refclk, or FALSE. The returned values represent the clock equation: | |
8962 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. | |
8963 | */ | |
a93e255f ACO |
8964 | limit = intel_limit(crtc_state, refclk); |
8965 | ret = dev_priv->display.find_dpll(limit, crtc_state, | |
190f68c5 | 8966 | crtc_state->port_clock, |
ee9300bb | 8967 | refclk, NULL, clock); |
6591c6e4 PZ |
8968 | if (!ret) |
8969 | return false; | |
cda4b7d3 | 8970 | |
6591c6e4 PZ |
8971 | return true; |
8972 | } | |
8973 | ||
d4b1931c PZ |
8974 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
8975 | { | |
8976 | /* | |
8977 | * Account for spread spectrum to avoid | |
8978 | * oversubscribing the link. Max center spread | |
8979 | * is 2.5%; use 5% for safety's sake. | |
8980 | */ | |
8981 | u32 bps = target_clock * bpp * 21 / 20; | |
619d4d04 | 8982 | return DIV_ROUND_UP(bps, link_bw * 8); |
d4b1931c PZ |
8983 | } |
8984 | ||
7429e9d4 | 8985 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
6cf86a5e | 8986 | { |
7429e9d4 | 8987 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
f48d8f23 PZ |
8988 | } |
8989 | ||
de13a2e3 | 8990 | static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc, |
190f68c5 | 8991 | struct intel_crtc_state *crtc_state, |
7429e9d4 | 8992 | u32 *fp, |
9a7c7890 | 8993 | intel_clock_t *reduced_clock, u32 *fp2) |
79e53945 | 8994 | { |
de13a2e3 | 8995 | struct drm_crtc *crtc = &intel_crtc->base; |
79e53945 JB |
8996 | struct drm_device *dev = crtc->dev; |
8997 | struct drm_i915_private *dev_priv = dev->dev_private; | |
55bb9992 | 8998 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 8999 | struct drm_connector *connector; |
55bb9992 ACO |
9000 | struct drm_connector_state *connector_state; |
9001 | struct intel_encoder *encoder; | |
de13a2e3 | 9002 | uint32_t dpll; |
55bb9992 | 9003 | int factor, num_connectors = 0, i; |
09ede541 | 9004 | bool is_lvds = false, is_sdvo = false; |
79e53945 | 9005 | |
da3ced29 | 9006 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
9007 | if (connector_state->crtc != crtc_state->base.crtc) |
9008 | continue; | |
9009 | ||
9010 | encoder = to_intel_encoder(connector_state->best_encoder); | |
9011 | ||
9012 | switch (encoder->type) { | |
79e53945 JB |
9013 | case INTEL_OUTPUT_LVDS: |
9014 | is_lvds = true; | |
9015 | break; | |
9016 | case INTEL_OUTPUT_SDVO: | |
7d57382e | 9017 | case INTEL_OUTPUT_HDMI: |
79e53945 | 9018 | is_sdvo = true; |
79e53945 | 9019 | break; |
6847d71b PZ |
9020 | default: |
9021 | break; | |
79e53945 | 9022 | } |
43565a06 | 9023 | |
c751ce4f | 9024 | num_connectors++; |
79e53945 | 9025 | } |
79e53945 | 9026 | |
c1858123 | 9027 | /* Enable autotuning of the PLL clock (if permissible) */ |
8febb297 EA |
9028 | factor = 21; |
9029 | if (is_lvds) { | |
9030 | if ((intel_panel_use_ssc(dev_priv) && | |
e91e941b | 9031 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
f0b44056 | 9032 | (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev))) |
8febb297 | 9033 | factor = 25; |
190f68c5 | 9034 | } else if (crtc_state->sdvo_tv_clock) |
8febb297 | 9035 | factor = 20; |
c1858123 | 9036 | |
190f68c5 | 9037 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
7d0ac5b7 | 9038 | *fp |= FP_CB_TUNE; |
2c07245f | 9039 | |
9a7c7890 DV |
9040 | if (fp2 && (reduced_clock->m < factor * reduced_clock->n)) |
9041 | *fp2 |= FP_CB_TUNE; | |
9042 | ||
5eddb70b | 9043 | dpll = 0; |
2c07245f | 9044 | |
a07d6787 EA |
9045 | if (is_lvds) |
9046 | dpll |= DPLLB_MODE_LVDS; | |
9047 | else | |
9048 | dpll |= DPLLB_MODE_DAC_SERIAL; | |
198a037f | 9049 | |
190f68c5 | 9050 | dpll |= (crtc_state->pixel_multiplier - 1) |
ef1b460d | 9051 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
198a037f DV |
9052 | |
9053 | if (is_sdvo) | |
4a33e48d | 9054 | dpll |= DPLL_SDVO_HIGH_SPEED; |
190f68c5 | 9055 | if (crtc_state->has_dp_encoder) |
4a33e48d | 9056 | dpll |= DPLL_SDVO_HIGH_SPEED; |
79e53945 | 9057 | |
a07d6787 | 9058 | /* compute bitmask from p1 value */ |
190f68c5 | 9059 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
a07d6787 | 9060 | /* also FPA1 */ |
190f68c5 | 9061 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
a07d6787 | 9062 | |
190f68c5 | 9063 | switch (crtc_state->dpll.p2) { |
a07d6787 EA |
9064 | case 5: |
9065 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; | |
9066 | break; | |
9067 | case 7: | |
9068 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; | |
9069 | break; | |
9070 | case 10: | |
9071 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; | |
9072 | break; | |
9073 | case 14: | |
9074 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; | |
9075 | break; | |
79e53945 JB |
9076 | } |
9077 | ||
b4c09f3b | 9078 | if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
43565a06 | 9079 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
79e53945 JB |
9080 | else |
9081 | dpll |= PLL_REF_INPUT_DREFCLK; | |
9082 | ||
959e16d6 | 9083 | return dpll | DPLL_VCO_ENABLE; |
de13a2e3 PZ |
9084 | } |
9085 | ||
190f68c5 ACO |
9086 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
9087 | struct intel_crtc_state *crtc_state) | |
de13a2e3 | 9088 | { |
c7653199 | 9089 | struct drm_device *dev = crtc->base.dev; |
de13a2e3 | 9090 | intel_clock_t clock, reduced_clock; |
cbbab5bd | 9091 | u32 dpll = 0, fp = 0, fp2 = 0; |
e2f12b07 | 9092 | bool ok, has_reduced_clock = false; |
8b47047b | 9093 | bool is_lvds = false; |
e2b78267 | 9094 | struct intel_shared_dpll *pll; |
de13a2e3 | 9095 | |
dd3cd74a ACO |
9096 | memset(&crtc_state->dpll_hw_state, 0, |
9097 | sizeof(crtc_state->dpll_hw_state)); | |
9098 | ||
7905df29 | 9099 | is_lvds = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS); |
79e53945 | 9100 | |
5dc5298b PZ |
9101 | WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)), |
9102 | "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev)); | |
a07d6787 | 9103 | |
190f68c5 | 9104 | ok = ironlake_compute_clocks(&crtc->base, crtc_state, &clock, |
de13a2e3 | 9105 | &has_reduced_clock, &reduced_clock); |
190f68c5 | 9106 | if (!ok && !crtc_state->clock_set) { |
de13a2e3 PZ |
9107 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
9108 | return -EINVAL; | |
79e53945 | 9109 | } |
f47709a9 | 9110 | /* Compat-code for transition, will disappear. */ |
190f68c5 ACO |
9111 | if (!crtc_state->clock_set) { |
9112 | crtc_state->dpll.n = clock.n; | |
9113 | crtc_state->dpll.m1 = clock.m1; | |
9114 | crtc_state->dpll.m2 = clock.m2; | |
9115 | crtc_state->dpll.p1 = clock.p1; | |
9116 | crtc_state->dpll.p2 = clock.p2; | |
f47709a9 | 9117 | } |
79e53945 | 9118 | |
5dc5298b | 9119 | /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */ |
190f68c5 ACO |
9120 | if (crtc_state->has_pch_encoder) { |
9121 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); | |
cbbab5bd | 9122 | if (has_reduced_clock) |
7429e9d4 | 9123 | fp2 = i9xx_dpll_compute_fp(&reduced_clock); |
cbbab5bd | 9124 | |
190f68c5 | 9125 | dpll = ironlake_compute_dpll(crtc, crtc_state, |
cbbab5bd DV |
9126 | &fp, &reduced_clock, |
9127 | has_reduced_clock ? &fp2 : NULL); | |
9128 | ||
190f68c5 ACO |
9129 | crtc_state->dpll_hw_state.dpll = dpll; |
9130 | crtc_state->dpll_hw_state.fp0 = fp; | |
66e985c0 | 9131 | if (has_reduced_clock) |
190f68c5 | 9132 | crtc_state->dpll_hw_state.fp1 = fp2; |
66e985c0 | 9133 | else |
190f68c5 | 9134 | crtc_state->dpll_hw_state.fp1 = fp; |
66e985c0 | 9135 | |
190f68c5 | 9136 | pll = intel_get_shared_dpll(crtc, crtc_state); |
ee7b9f93 | 9137 | if (pll == NULL) { |
84f44ce7 | 9138 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", |
c7653199 | 9139 | pipe_name(crtc->pipe)); |
4b645f14 JB |
9140 | return -EINVAL; |
9141 | } | |
3fb37703 | 9142 | } |
79e53945 | 9143 | |
ab585dea | 9144 | if (is_lvds && has_reduced_clock) |
c7653199 | 9145 | crtc->lowfreq_avail = true; |
bcd644e0 | 9146 | else |
c7653199 | 9147 | crtc->lowfreq_avail = false; |
e2b78267 | 9148 | |
c8f7a0db | 9149 | return 0; |
79e53945 JB |
9150 | } |
9151 | ||
eb14cb74 VS |
9152 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
9153 | struct intel_link_m_n *m_n) | |
9154 | { | |
9155 | struct drm_device *dev = crtc->base.dev; | |
9156 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9157 | enum pipe pipe = crtc->pipe; | |
9158 | ||
9159 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); | |
9160 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); | |
9161 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) | |
9162 | & ~TU_SIZE_MASK; | |
9163 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); | |
9164 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) | |
9165 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
9166 | } | |
9167 | ||
9168 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, | |
9169 | enum transcoder transcoder, | |
b95af8be VK |
9170 | struct intel_link_m_n *m_n, |
9171 | struct intel_link_m_n *m2_n2) | |
72419203 DV |
9172 | { |
9173 | struct drm_device *dev = crtc->base.dev; | |
9174 | struct drm_i915_private *dev_priv = dev->dev_private; | |
eb14cb74 | 9175 | enum pipe pipe = crtc->pipe; |
72419203 | 9176 | |
eb14cb74 VS |
9177 | if (INTEL_INFO(dev)->gen >= 5) { |
9178 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); | |
9179 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); | |
9180 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) | |
9181 | & ~TU_SIZE_MASK; | |
9182 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); | |
9183 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) | |
9184 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
b95af8be VK |
9185 | /* Read M2_N2 registers only for gen < 8 (M2_N2 available for |
9186 | * gen < 8) and if DRRS is supported (to make sure the | |
9187 | * registers are not unnecessarily read). | |
9188 | */ | |
9189 | if (m2_n2 && INTEL_INFO(dev)->gen < 8 && | |
6e3c9717 | 9190 | crtc->config->has_drrs) { |
b95af8be VK |
9191 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
9192 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); | |
9193 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) | |
9194 | & ~TU_SIZE_MASK; | |
9195 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); | |
9196 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) | |
9197 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
9198 | } | |
eb14cb74 VS |
9199 | } else { |
9200 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); | |
9201 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); | |
9202 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) | |
9203 | & ~TU_SIZE_MASK; | |
9204 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); | |
9205 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) | |
9206 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
9207 | } | |
9208 | } | |
9209 | ||
9210 | void intel_dp_get_m_n(struct intel_crtc *crtc, | |
5cec258b | 9211 | struct intel_crtc_state *pipe_config) |
eb14cb74 | 9212 | { |
681a8504 | 9213 | if (pipe_config->has_pch_encoder) |
eb14cb74 VS |
9214 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
9215 | else | |
9216 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, | |
b95af8be VK |
9217 | &pipe_config->dp_m_n, |
9218 | &pipe_config->dp_m2_n2); | |
eb14cb74 | 9219 | } |
72419203 | 9220 | |
eb14cb74 | 9221 | static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc, |
5cec258b | 9222 | struct intel_crtc_state *pipe_config) |
eb14cb74 VS |
9223 | { |
9224 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, | |
b95af8be | 9225 | &pipe_config->fdi_m_n, NULL); |
72419203 DV |
9226 | } |
9227 | ||
bd2e244f | 9228 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 9229 | struct intel_crtc_state *pipe_config) |
bd2e244f JB |
9230 | { |
9231 | struct drm_device *dev = crtc->base.dev; | |
9232 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a1b2278e CK |
9233 | struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state; |
9234 | uint32_t ps_ctrl = 0; | |
9235 | int id = -1; | |
9236 | int i; | |
bd2e244f | 9237 | |
a1b2278e CK |
9238 | /* find scaler attached to this pipe */ |
9239 | for (i = 0; i < crtc->num_scalers; i++) { | |
9240 | ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i)); | |
9241 | if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) { | |
9242 | id = i; | |
9243 | pipe_config->pch_pfit.enabled = true; | |
9244 | pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i)); | |
9245 | pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i)); | |
9246 | break; | |
9247 | } | |
9248 | } | |
bd2e244f | 9249 | |
a1b2278e CK |
9250 | scaler_state->scaler_id = id; |
9251 | if (id >= 0) { | |
9252 | scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX); | |
9253 | } else { | |
9254 | scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX); | |
bd2e244f JB |
9255 | } |
9256 | } | |
9257 | ||
5724dbd1 DL |
9258 | static void |
9259 | skylake_get_initial_plane_config(struct intel_crtc *crtc, | |
9260 | struct intel_initial_plane_config *plane_config) | |
bc8d7dff DL |
9261 | { |
9262 | struct drm_device *dev = crtc->base.dev; | |
9263 | struct drm_i915_private *dev_priv = dev->dev_private; | |
40f46283 | 9264 | u32 val, base, offset, stride_mult, tiling; |
bc8d7dff DL |
9265 | int pipe = crtc->pipe; |
9266 | int fourcc, pixel_format; | |
6761dd31 | 9267 | unsigned int aligned_height; |
bc8d7dff | 9268 | struct drm_framebuffer *fb; |
1b842c89 | 9269 | struct intel_framebuffer *intel_fb; |
bc8d7dff | 9270 | |
d9806c9f | 9271 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 9272 | if (!intel_fb) { |
bc8d7dff DL |
9273 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
9274 | return; | |
9275 | } | |
9276 | ||
1b842c89 DL |
9277 | fb = &intel_fb->base; |
9278 | ||
bc8d7dff | 9279 | val = I915_READ(PLANE_CTL(pipe, 0)); |
42a7b088 DL |
9280 | if (!(val & PLANE_CTL_ENABLE)) |
9281 | goto error; | |
9282 | ||
bc8d7dff DL |
9283 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
9284 | fourcc = skl_format_to_fourcc(pixel_format, | |
9285 | val & PLANE_CTL_ORDER_RGBX, | |
9286 | val & PLANE_CTL_ALPHA_MASK); | |
9287 | fb->pixel_format = fourcc; | |
9288 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
9289 | ||
40f46283 DL |
9290 | tiling = val & PLANE_CTL_TILED_MASK; |
9291 | switch (tiling) { | |
9292 | case PLANE_CTL_TILED_LINEAR: | |
9293 | fb->modifier[0] = DRM_FORMAT_MOD_NONE; | |
9294 | break; | |
9295 | case PLANE_CTL_TILED_X: | |
9296 | plane_config->tiling = I915_TILING_X; | |
9297 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; | |
9298 | break; | |
9299 | case PLANE_CTL_TILED_Y: | |
9300 | fb->modifier[0] = I915_FORMAT_MOD_Y_TILED; | |
9301 | break; | |
9302 | case PLANE_CTL_TILED_YF: | |
9303 | fb->modifier[0] = I915_FORMAT_MOD_Yf_TILED; | |
9304 | break; | |
9305 | default: | |
9306 | MISSING_CASE(tiling); | |
9307 | goto error; | |
9308 | } | |
9309 | ||
bc8d7dff DL |
9310 | base = I915_READ(PLANE_SURF(pipe, 0)) & 0xfffff000; |
9311 | plane_config->base = base; | |
9312 | ||
9313 | offset = I915_READ(PLANE_OFFSET(pipe, 0)); | |
9314 | ||
9315 | val = I915_READ(PLANE_SIZE(pipe, 0)); | |
9316 | fb->height = ((val >> 16) & 0xfff) + 1; | |
9317 | fb->width = ((val >> 0) & 0x1fff) + 1; | |
9318 | ||
9319 | val = I915_READ(PLANE_STRIDE(pipe, 0)); | |
7b49f948 | 9320 | stride_mult = intel_fb_stride_alignment(dev_priv, fb->modifier[0], |
40f46283 | 9321 | fb->pixel_format); |
bc8d7dff DL |
9322 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
9323 | ||
9324 | aligned_height = intel_fb_align_height(dev, fb->height, | |
091df6cb DV |
9325 | fb->pixel_format, |
9326 | fb->modifier[0]); | |
bc8d7dff | 9327 | |
f37b5c2b | 9328 | plane_config->size = fb->pitches[0] * aligned_height; |
bc8d7dff DL |
9329 | |
9330 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", | |
9331 | pipe_name(pipe), fb->width, fb->height, | |
9332 | fb->bits_per_pixel, base, fb->pitches[0], | |
9333 | plane_config->size); | |
9334 | ||
2d14030b | 9335 | plane_config->fb = intel_fb; |
bc8d7dff DL |
9336 | return; |
9337 | ||
9338 | error: | |
9339 | kfree(fb); | |
9340 | } | |
9341 | ||
2fa2fe9a | 9342 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 9343 | struct intel_crtc_state *pipe_config) |
2fa2fe9a DV |
9344 | { |
9345 | struct drm_device *dev = crtc->base.dev; | |
9346 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9347 | uint32_t tmp; | |
9348 | ||
9349 | tmp = I915_READ(PF_CTL(crtc->pipe)); | |
9350 | ||
9351 | if (tmp & PF_ENABLE) { | |
fd4daa9c | 9352 | pipe_config->pch_pfit.enabled = true; |
2fa2fe9a DV |
9353 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
9354 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); | |
cb8b2a30 DV |
9355 | |
9356 | /* We currently do not free assignements of panel fitters on | |
9357 | * ivb/hsw (since we don't use the higher upscaling modes which | |
9358 | * differentiates them) so just WARN about this case for now. */ | |
9359 | if (IS_GEN7(dev)) { | |
9360 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != | |
9361 | PF_PIPE_SEL_IVB(crtc->pipe)); | |
9362 | } | |
2fa2fe9a | 9363 | } |
79e53945 JB |
9364 | } |
9365 | ||
5724dbd1 DL |
9366 | static void |
9367 | ironlake_get_initial_plane_config(struct intel_crtc *crtc, | |
9368 | struct intel_initial_plane_config *plane_config) | |
4c6baa59 JB |
9369 | { |
9370 | struct drm_device *dev = crtc->base.dev; | |
9371 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9372 | u32 val, base, offset; | |
aeee5a49 | 9373 | int pipe = crtc->pipe; |
4c6baa59 | 9374 | int fourcc, pixel_format; |
6761dd31 | 9375 | unsigned int aligned_height; |
b113d5ee | 9376 | struct drm_framebuffer *fb; |
1b842c89 | 9377 | struct intel_framebuffer *intel_fb; |
4c6baa59 | 9378 | |
42a7b088 DL |
9379 | val = I915_READ(DSPCNTR(pipe)); |
9380 | if (!(val & DISPLAY_PLANE_ENABLE)) | |
9381 | return; | |
9382 | ||
d9806c9f | 9383 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 9384 | if (!intel_fb) { |
4c6baa59 JB |
9385 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
9386 | return; | |
9387 | } | |
9388 | ||
1b842c89 DL |
9389 | fb = &intel_fb->base; |
9390 | ||
18c5247e DV |
9391 | if (INTEL_INFO(dev)->gen >= 4) { |
9392 | if (val & DISPPLANE_TILED) { | |
49af449b | 9393 | plane_config->tiling = I915_TILING_X; |
18c5247e DV |
9394 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
9395 | } | |
9396 | } | |
4c6baa59 JB |
9397 | |
9398 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; | |
b35d63fa | 9399 | fourcc = i9xx_format_to_fourcc(pixel_format); |
b113d5ee DL |
9400 | fb->pixel_format = fourcc; |
9401 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
4c6baa59 | 9402 | |
aeee5a49 | 9403 | base = I915_READ(DSPSURF(pipe)) & 0xfffff000; |
4c6baa59 | 9404 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
aeee5a49 | 9405 | offset = I915_READ(DSPOFFSET(pipe)); |
4c6baa59 | 9406 | } else { |
49af449b | 9407 | if (plane_config->tiling) |
aeee5a49 | 9408 | offset = I915_READ(DSPTILEOFF(pipe)); |
4c6baa59 | 9409 | else |
aeee5a49 | 9410 | offset = I915_READ(DSPLINOFF(pipe)); |
4c6baa59 JB |
9411 | } |
9412 | plane_config->base = base; | |
9413 | ||
9414 | val = I915_READ(PIPESRC(pipe)); | |
b113d5ee DL |
9415 | fb->width = ((val >> 16) & 0xfff) + 1; |
9416 | fb->height = ((val >> 0) & 0xfff) + 1; | |
4c6baa59 JB |
9417 | |
9418 | val = I915_READ(DSPSTRIDE(pipe)); | |
b113d5ee | 9419 | fb->pitches[0] = val & 0xffffffc0; |
4c6baa59 | 9420 | |
b113d5ee | 9421 | aligned_height = intel_fb_align_height(dev, fb->height, |
091df6cb DV |
9422 | fb->pixel_format, |
9423 | fb->modifier[0]); | |
4c6baa59 | 9424 | |
f37b5c2b | 9425 | plane_config->size = fb->pitches[0] * aligned_height; |
4c6baa59 | 9426 | |
2844a921 DL |
9427 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
9428 | pipe_name(pipe), fb->width, fb->height, | |
9429 | fb->bits_per_pixel, base, fb->pitches[0], | |
9430 | plane_config->size); | |
b113d5ee | 9431 | |
2d14030b | 9432 | plane_config->fb = intel_fb; |
4c6baa59 JB |
9433 | } |
9434 | ||
0e8ffe1b | 9435 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 9436 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
9437 | { |
9438 | struct drm_device *dev = crtc->base.dev; | |
9439 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1729050e | 9440 | enum intel_display_power_domain power_domain; |
0e8ffe1b | 9441 | uint32_t tmp; |
1729050e | 9442 | bool ret; |
0e8ffe1b | 9443 | |
1729050e ID |
9444 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
9445 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) | |
930e8c9e PZ |
9446 | return false; |
9447 | ||
e143a21c | 9448 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 | 9449 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
eccb140b | 9450 | |
1729050e | 9451 | ret = false; |
0e8ffe1b DV |
9452 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
9453 | if (!(tmp & PIPECONF_ENABLE)) | |
1729050e | 9454 | goto out; |
0e8ffe1b | 9455 | |
42571aef VS |
9456 | switch (tmp & PIPECONF_BPC_MASK) { |
9457 | case PIPECONF_6BPC: | |
9458 | pipe_config->pipe_bpp = 18; | |
9459 | break; | |
9460 | case PIPECONF_8BPC: | |
9461 | pipe_config->pipe_bpp = 24; | |
9462 | break; | |
9463 | case PIPECONF_10BPC: | |
9464 | pipe_config->pipe_bpp = 30; | |
9465 | break; | |
9466 | case PIPECONF_12BPC: | |
9467 | pipe_config->pipe_bpp = 36; | |
9468 | break; | |
9469 | default: | |
9470 | break; | |
9471 | } | |
9472 | ||
b5a9fa09 DV |
9473 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
9474 | pipe_config->limited_color_range = true; | |
9475 | ||
ab9412ba | 9476 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
66e985c0 DV |
9477 | struct intel_shared_dpll *pll; |
9478 | ||
88adfff1 DV |
9479 | pipe_config->has_pch_encoder = true; |
9480 | ||
627eb5a3 DV |
9481 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
9482 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> | |
9483 | FDI_DP_PORT_WIDTH_SHIFT) + 1; | |
72419203 DV |
9484 | |
9485 | ironlake_get_fdi_m_n_config(crtc, pipe_config); | |
6c49f241 | 9486 | |
c0d43d62 | 9487 | if (HAS_PCH_IBX(dev_priv->dev)) { |
d94ab068 DV |
9488 | pipe_config->shared_dpll = |
9489 | (enum intel_dpll_id) crtc->pipe; | |
c0d43d62 DV |
9490 | } else { |
9491 | tmp = I915_READ(PCH_DPLL_SEL); | |
9492 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) | |
9493 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B; | |
9494 | else | |
9495 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A; | |
9496 | } | |
66e985c0 DV |
9497 | |
9498 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; | |
9499 | ||
9500 | WARN_ON(!pll->get_hw_state(dev_priv, pll, | |
9501 | &pipe_config->dpll_hw_state)); | |
c93f54cf DV |
9502 | |
9503 | tmp = pipe_config->dpll_hw_state.dpll; | |
9504 | pipe_config->pixel_multiplier = | |
9505 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) | |
9506 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; | |
18442d08 VS |
9507 | |
9508 | ironlake_pch_clock_get(crtc, pipe_config); | |
6c49f241 DV |
9509 | } else { |
9510 | pipe_config->pixel_multiplier = 1; | |
627eb5a3 DV |
9511 | } |
9512 | ||
1bd1bd80 DV |
9513 | intel_get_pipe_timings(crtc, pipe_config); |
9514 | ||
2fa2fe9a DV |
9515 | ironlake_get_pfit_config(crtc, pipe_config); |
9516 | ||
1729050e ID |
9517 | ret = true; |
9518 | ||
9519 | out: | |
9520 | intel_display_power_put(dev_priv, power_domain); | |
9521 | ||
9522 | return ret; | |
0e8ffe1b DV |
9523 | } |
9524 | ||
be256dc7 PZ |
9525 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
9526 | { | |
9527 | struct drm_device *dev = dev_priv->dev; | |
be256dc7 | 9528 | struct intel_crtc *crtc; |
be256dc7 | 9529 | |
d3fcc808 | 9530 | for_each_intel_crtc(dev, crtc) |
e2c719b7 | 9531 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
be256dc7 PZ |
9532 | pipe_name(crtc->pipe)); |
9533 | ||
e2c719b7 RC |
9534 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n"); |
9535 | I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n"); | |
01403de3 VS |
9536 | I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); |
9537 | I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n"); | |
e2c719b7 RC |
9538 | I915_STATE_WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n"); |
9539 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, | |
be256dc7 | 9540 | "CPU PWM1 enabled\n"); |
c5107b87 | 9541 | if (IS_HASWELL(dev)) |
e2c719b7 | 9542 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
c5107b87 | 9543 | "CPU PWM2 enabled\n"); |
e2c719b7 | 9544 | I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE, |
be256dc7 | 9545 | "PCH PWM1 enabled\n"); |
e2c719b7 | 9546 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
be256dc7 | 9547 | "Utility pin enabled\n"); |
e2c719b7 | 9548 | I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n"); |
be256dc7 | 9549 | |
9926ada1 PZ |
9550 | /* |
9551 | * In theory we can still leave IRQs enabled, as long as only the HPD | |
9552 | * interrupts remain enabled. We used to check for that, but since it's | |
9553 | * gen-specific and since we only disable LCPLL after we fully disable | |
9554 | * the interrupts, the check below should be enough. | |
9555 | */ | |
e2c719b7 | 9556 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
be256dc7 PZ |
9557 | } |
9558 | ||
9ccd5aeb PZ |
9559 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) |
9560 | { | |
9561 | struct drm_device *dev = dev_priv->dev; | |
9562 | ||
9563 | if (IS_HASWELL(dev)) | |
9564 | return I915_READ(D_COMP_HSW); | |
9565 | else | |
9566 | return I915_READ(D_COMP_BDW); | |
9567 | } | |
9568 | ||
3c4c9b81 PZ |
9569 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) |
9570 | { | |
9571 | struct drm_device *dev = dev_priv->dev; | |
9572 | ||
9573 | if (IS_HASWELL(dev)) { | |
9574 | mutex_lock(&dev_priv->rps.hw_lock); | |
9575 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, | |
9576 | val)) | |
f475dadf | 9577 | DRM_ERROR("Failed to write to D_COMP\n"); |
3c4c9b81 PZ |
9578 | mutex_unlock(&dev_priv->rps.hw_lock); |
9579 | } else { | |
9ccd5aeb PZ |
9580 | I915_WRITE(D_COMP_BDW, val); |
9581 | POSTING_READ(D_COMP_BDW); | |
3c4c9b81 | 9582 | } |
be256dc7 PZ |
9583 | } |
9584 | ||
9585 | /* | |
9586 | * This function implements pieces of two sequences from BSpec: | |
9587 | * - Sequence for display software to disable LCPLL | |
9588 | * - Sequence for display software to allow package C8+ | |
9589 | * The steps implemented here are just the steps that actually touch the LCPLL | |
9590 | * register. Callers should take care of disabling all the display engine | |
9591 | * functions, doing the mode unset, fixing interrupts, etc. | |
9592 | */ | |
6ff58d53 PZ |
9593 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
9594 | bool switch_to_fclk, bool allow_power_down) | |
be256dc7 PZ |
9595 | { |
9596 | uint32_t val; | |
9597 | ||
9598 | assert_can_disable_lcpll(dev_priv); | |
9599 | ||
9600 | val = I915_READ(LCPLL_CTL); | |
9601 | ||
9602 | if (switch_to_fclk) { | |
9603 | val |= LCPLL_CD_SOURCE_FCLK; | |
9604 | I915_WRITE(LCPLL_CTL, val); | |
9605 | ||
9606 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & | |
9607 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) | |
9608 | DRM_ERROR("Switching to FCLK failed\n"); | |
9609 | ||
9610 | val = I915_READ(LCPLL_CTL); | |
9611 | } | |
9612 | ||
9613 | val |= LCPLL_PLL_DISABLE; | |
9614 | I915_WRITE(LCPLL_CTL, val); | |
9615 | POSTING_READ(LCPLL_CTL); | |
9616 | ||
9617 | if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1)) | |
9618 | DRM_ERROR("LCPLL still locked\n"); | |
9619 | ||
9ccd5aeb | 9620 | val = hsw_read_dcomp(dev_priv); |
be256dc7 | 9621 | val |= D_COMP_COMP_DISABLE; |
3c4c9b81 | 9622 | hsw_write_dcomp(dev_priv, val); |
be256dc7 PZ |
9623 | ndelay(100); |
9624 | ||
9ccd5aeb PZ |
9625 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
9626 | 1)) | |
be256dc7 PZ |
9627 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
9628 | ||
9629 | if (allow_power_down) { | |
9630 | val = I915_READ(LCPLL_CTL); | |
9631 | val |= LCPLL_POWER_DOWN_ALLOW; | |
9632 | I915_WRITE(LCPLL_CTL, val); | |
9633 | POSTING_READ(LCPLL_CTL); | |
9634 | } | |
9635 | } | |
9636 | ||
9637 | /* | |
9638 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL | |
9639 | * source. | |
9640 | */ | |
6ff58d53 | 9641 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
be256dc7 PZ |
9642 | { |
9643 | uint32_t val; | |
9644 | ||
9645 | val = I915_READ(LCPLL_CTL); | |
9646 | ||
9647 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | | |
9648 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) | |
9649 | return; | |
9650 | ||
a8a8bd54 PZ |
9651 | /* |
9652 | * Make sure we're not on PC8 state before disabling PC8, otherwise | |
9653 | * we'll hang the machine. To prevent PC8 state, just enable force_wake. | |
a8a8bd54 | 9654 | */ |
59bad947 | 9655 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
215733fa | 9656 | |
be256dc7 PZ |
9657 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
9658 | val &= ~LCPLL_POWER_DOWN_ALLOW; | |
9659 | I915_WRITE(LCPLL_CTL, val); | |
35d8f2eb | 9660 | POSTING_READ(LCPLL_CTL); |
be256dc7 PZ |
9661 | } |
9662 | ||
9ccd5aeb | 9663 | val = hsw_read_dcomp(dev_priv); |
be256dc7 PZ |
9664 | val |= D_COMP_COMP_FORCE; |
9665 | val &= ~D_COMP_COMP_DISABLE; | |
3c4c9b81 | 9666 | hsw_write_dcomp(dev_priv, val); |
be256dc7 PZ |
9667 | |
9668 | val = I915_READ(LCPLL_CTL); | |
9669 | val &= ~LCPLL_PLL_DISABLE; | |
9670 | I915_WRITE(LCPLL_CTL, val); | |
9671 | ||
9672 | if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5)) | |
9673 | DRM_ERROR("LCPLL not locked yet\n"); | |
9674 | ||
9675 | if (val & LCPLL_CD_SOURCE_FCLK) { | |
9676 | val = I915_READ(LCPLL_CTL); | |
9677 | val &= ~LCPLL_CD_SOURCE_FCLK; | |
9678 | I915_WRITE(LCPLL_CTL, val); | |
9679 | ||
9680 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & | |
9681 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) | |
9682 | DRM_ERROR("Switching back to LCPLL failed\n"); | |
9683 | } | |
215733fa | 9684 | |
59bad947 | 9685 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
b6283055 | 9686 | intel_update_cdclk(dev_priv->dev); |
be256dc7 PZ |
9687 | } |
9688 | ||
765dab67 PZ |
9689 | /* |
9690 | * Package states C8 and deeper are really deep PC states that can only be | |
9691 | * reached when all the devices on the system allow it, so even if the graphics | |
9692 | * device allows PC8+, it doesn't mean the system will actually get to these | |
9693 | * states. Our driver only allows PC8+ when going into runtime PM. | |
9694 | * | |
9695 | * The requirements for PC8+ are that all the outputs are disabled, the power | |
9696 | * well is disabled and most interrupts are disabled, and these are also | |
9697 | * requirements for runtime PM. When these conditions are met, we manually do | |
9698 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk | |
9699 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard | |
9700 | * hang the machine. | |
9701 | * | |
9702 | * When we really reach PC8 or deeper states (not just when we allow it) we lose | |
9703 | * the state of some registers, so when we come back from PC8+ we need to | |
9704 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't | |
9705 | * need to take care of the registers kept by RC6. Notice that this happens even | |
9706 | * if we don't put the device in PCI D3 state (which is what currently happens | |
9707 | * because of the runtime PM support). | |
9708 | * | |
9709 | * For more, read "Display Sequences for Package C8" on the hardware | |
9710 | * documentation. | |
9711 | */ | |
a14cb6fc | 9712 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
c67a470b | 9713 | { |
c67a470b PZ |
9714 | struct drm_device *dev = dev_priv->dev; |
9715 | uint32_t val; | |
9716 | ||
c67a470b PZ |
9717 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
9718 | ||
c2699524 | 9719 | if (HAS_PCH_LPT_LP(dev)) { |
c67a470b PZ |
9720 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
9721 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; | |
9722 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); | |
9723 | } | |
9724 | ||
9725 | lpt_disable_clkout_dp(dev); | |
c67a470b PZ |
9726 | hsw_disable_lcpll(dev_priv, true, true); |
9727 | } | |
9728 | ||
a14cb6fc | 9729 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
c67a470b PZ |
9730 | { |
9731 | struct drm_device *dev = dev_priv->dev; | |
9732 | uint32_t val; | |
9733 | ||
c67a470b PZ |
9734 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
9735 | ||
9736 | hsw_restore_lcpll(dev_priv); | |
c67a470b PZ |
9737 | lpt_init_pch_refclk(dev); |
9738 | ||
c2699524 | 9739 | if (HAS_PCH_LPT_LP(dev)) { |
c67a470b PZ |
9740 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
9741 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; | |
9742 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); | |
9743 | } | |
c67a470b PZ |
9744 | } |
9745 | ||
27c329ed | 9746 | static void broxton_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
f8437dd1 | 9747 | { |
a821fc46 | 9748 | struct drm_device *dev = old_state->dev; |
1a617b77 ML |
9749 | struct intel_atomic_state *old_intel_state = |
9750 | to_intel_atomic_state(old_state); | |
9751 | unsigned int req_cdclk = old_intel_state->dev_cdclk; | |
f8437dd1 | 9752 | |
27c329ed | 9753 | broxton_set_cdclk(dev, req_cdclk); |
f8437dd1 VK |
9754 | } |
9755 | ||
b432e5cf | 9756 | /* compute the max rate for new configuration */ |
27c329ed | 9757 | static int ilk_max_pixel_rate(struct drm_atomic_state *state) |
b432e5cf | 9758 | { |
565602d7 ML |
9759 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
9760 | struct drm_i915_private *dev_priv = state->dev->dev_private; | |
9761 | struct drm_crtc *crtc; | |
9762 | struct drm_crtc_state *cstate; | |
27c329ed | 9763 | struct intel_crtc_state *crtc_state; |
565602d7 ML |
9764 | unsigned max_pixel_rate = 0, i; |
9765 | enum pipe pipe; | |
b432e5cf | 9766 | |
565602d7 ML |
9767 | memcpy(intel_state->min_pixclk, dev_priv->min_pixclk, |
9768 | sizeof(intel_state->min_pixclk)); | |
27c329ed | 9769 | |
565602d7 ML |
9770 | for_each_crtc_in_state(state, crtc, cstate, i) { |
9771 | int pixel_rate; | |
27c329ed | 9772 | |
565602d7 ML |
9773 | crtc_state = to_intel_crtc_state(cstate); |
9774 | if (!crtc_state->base.enable) { | |
9775 | intel_state->min_pixclk[i] = 0; | |
b432e5cf | 9776 | continue; |
565602d7 | 9777 | } |
b432e5cf | 9778 | |
27c329ed | 9779 | pixel_rate = ilk_pipe_pixel_rate(crtc_state); |
b432e5cf VS |
9780 | |
9781 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ | |
565602d7 | 9782 | if (IS_BROADWELL(dev_priv) && crtc_state->ips_enabled) |
b432e5cf VS |
9783 | pixel_rate = DIV_ROUND_UP(pixel_rate * 100, 95); |
9784 | ||
565602d7 | 9785 | intel_state->min_pixclk[i] = pixel_rate; |
b432e5cf VS |
9786 | } |
9787 | ||
565602d7 ML |
9788 | for_each_pipe(dev_priv, pipe) |
9789 | max_pixel_rate = max(intel_state->min_pixclk[pipe], max_pixel_rate); | |
9790 | ||
b432e5cf VS |
9791 | return max_pixel_rate; |
9792 | } | |
9793 | ||
9794 | static void broadwell_set_cdclk(struct drm_device *dev, int cdclk) | |
9795 | { | |
9796 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9797 | uint32_t val, data; | |
9798 | int ret; | |
9799 | ||
9800 | if (WARN((I915_READ(LCPLL_CTL) & | |
9801 | (LCPLL_PLL_DISABLE | LCPLL_PLL_LOCK | | |
9802 | LCPLL_CD_CLOCK_DISABLE | LCPLL_ROOT_CD_CLOCK_DISABLE | | |
9803 | LCPLL_CD2X_CLOCK_DISABLE | LCPLL_POWER_DOWN_ALLOW | | |
9804 | LCPLL_CD_SOURCE_FCLK)) != LCPLL_PLL_LOCK, | |
9805 | "trying to change cdclk frequency with cdclk not enabled\n")) | |
9806 | return; | |
9807 | ||
9808 | mutex_lock(&dev_priv->rps.hw_lock); | |
9809 | ret = sandybridge_pcode_write(dev_priv, | |
9810 | BDW_PCODE_DISPLAY_FREQ_CHANGE_REQ, 0x0); | |
9811 | mutex_unlock(&dev_priv->rps.hw_lock); | |
9812 | if (ret) { | |
9813 | DRM_ERROR("failed to inform pcode about cdclk change\n"); | |
9814 | return; | |
9815 | } | |
9816 | ||
9817 | val = I915_READ(LCPLL_CTL); | |
9818 | val |= LCPLL_CD_SOURCE_FCLK; | |
9819 | I915_WRITE(LCPLL_CTL, val); | |
9820 | ||
9821 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & | |
9822 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) | |
9823 | DRM_ERROR("Switching to FCLK failed\n"); | |
9824 | ||
9825 | val = I915_READ(LCPLL_CTL); | |
9826 | val &= ~LCPLL_CLK_FREQ_MASK; | |
9827 | ||
9828 | switch (cdclk) { | |
9829 | case 450000: | |
9830 | val |= LCPLL_CLK_FREQ_450; | |
9831 | data = 0; | |
9832 | break; | |
9833 | case 540000: | |
9834 | val |= LCPLL_CLK_FREQ_54O_BDW; | |
9835 | data = 1; | |
9836 | break; | |
9837 | case 337500: | |
9838 | val |= LCPLL_CLK_FREQ_337_5_BDW; | |
9839 | data = 2; | |
9840 | break; | |
9841 | case 675000: | |
9842 | val |= LCPLL_CLK_FREQ_675_BDW; | |
9843 | data = 3; | |
9844 | break; | |
9845 | default: | |
9846 | WARN(1, "invalid cdclk frequency\n"); | |
9847 | return; | |
9848 | } | |
9849 | ||
9850 | I915_WRITE(LCPLL_CTL, val); | |
9851 | ||
9852 | val = I915_READ(LCPLL_CTL); | |
9853 | val &= ~LCPLL_CD_SOURCE_FCLK; | |
9854 | I915_WRITE(LCPLL_CTL, val); | |
9855 | ||
9856 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & | |
9857 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) | |
9858 | DRM_ERROR("Switching back to LCPLL failed\n"); | |
9859 | ||
9860 | mutex_lock(&dev_priv->rps.hw_lock); | |
9861 | sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, data); | |
9862 | mutex_unlock(&dev_priv->rps.hw_lock); | |
9863 | ||
9864 | intel_update_cdclk(dev); | |
9865 | ||
9866 | WARN(cdclk != dev_priv->cdclk_freq, | |
9867 | "cdclk requested %d kHz but got %d kHz\n", | |
9868 | cdclk, dev_priv->cdclk_freq); | |
9869 | } | |
9870 | ||
27c329ed | 9871 | static int broadwell_modeset_calc_cdclk(struct drm_atomic_state *state) |
b432e5cf | 9872 | { |
27c329ed | 9873 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
1a617b77 | 9874 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
27c329ed | 9875 | int max_pixclk = ilk_max_pixel_rate(state); |
b432e5cf VS |
9876 | int cdclk; |
9877 | ||
9878 | /* | |
9879 | * FIXME should also account for plane ratio | |
9880 | * once 64bpp pixel formats are supported. | |
9881 | */ | |
27c329ed | 9882 | if (max_pixclk > 540000) |
b432e5cf | 9883 | cdclk = 675000; |
27c329ed | 9884 | else if (max_pixclk > 450000) |
b432e5cf | 9885 | cdclk = 540000; |
27c329ed | 9886 | else if (max_pixclk > 337500) |
b432e5cf VS |
9887 | cdclk = 450000; |
9888 | else | |
9889 | cdclk = 337500; | |
9890 | ||
b432e5cf | 9891 | if (cdclk > dev_priv->max_cdclk_freq) { |
63ba534e ML |
9892 | DRM_DEBUG_KMS("requested cdclk (%d kHz) exceeds max (%d kHz)\n", |
9893 | cdclk, dev_priv->max_cdclk_freq); | |
9894 | return -EINVAL; | |
b432e5cf VS |
9895 | } |
9896 | ||
1a617b77 ML |
9897 | intel_state->cdclk = intel_state->dev_cdclk = cdclk; |
9898 | if (!intel_state->active_crtcs) | |
9899 | intel_state->dev_cdclk = 337500; | |
b432e5cf VS |
9900 | |
9901 | return 0; | |
9902 | } | |
9903 | ||
27c329ed | 9904 | static void broadwell_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
b432e5cf | 9905 | { |
27c329ed | 9906 | struct drm_device *dev = old_state->dev; |
1a617b77 ML |
9907 | struct intel_atomic_state *old_intel_state = |
9908 | to_intel_atomic_state(old_state); | |
9909 | unsigned req_cdclk = old_intel_state->dev_cdclk; | |
b432e5cf | 9910 | |
27c329ed | 9911 | broadwell_set_cdclk(dev, req_cdclk); |
b432e5cf VS |
9912 | } |
9913 | ||
190f68c5 ACO |
9914 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
9915 | struct intel_crtc_state *crtc_state) | |
09b4ddf9 | 9916 | { |
af3997b5 MK |
9917 | struct intel_encoder *intel_encoder = |
9918 | intel_ddi_get_crtc_new_encoder(crtc_state); | |
9919 | ||
9920 | if (intel_encoder->type != INTEL_OUTPUT_DSI) { | |
9921 | if (!intel_ddi_pll_select(crtc, crtc_state)) | |
9922 | return -EINVAL; | |
9923 | } | |
716c2e55 | 9924 | |
c7653199 | 9925 | crtc->lowfreq_avail = false; |
644cef34 | 9926 | |
c8f7a0db | 9927 | return 0; |
79e53945 JB |
9928 | } |
9929 | ||
3760b59c S |
9930 | static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv, |
9931 | enum port port, | |
9932 | struct intel_crtc_state *pipe_config) | |
9933 | { | |
9934 | switch (port) { | |
9935 | case PORT_A: | |
9936 | pipe_config->ddi_pll_sel = SKL_DPLL0; | |
9937 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; | |
9938 | break; | |
9939 | case PORT_B: | |
9940 | pipe_config->ddi_pll_sel = SKL_DPLL1; | |
9941 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; | |
9942 | break; | |
9943 | case PORT_C: | |
9944 | pipe_config->ddi_pll_sel = SKL_DPLL2; | |
9945 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; | |
9946 | break; | |
9947 | default: | |
9948 | DRM_ERROR("Incorrect port type\n"); | |
9949 | } | |
9950 | } | |
9951 | ||
96b7dfb7 S |
9952 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
9953 | enum port port, | |
5cec258b | 9954 | struct intel_crtc_state *pipe_config) |
96b7dfb7 | 9955 | { |
3148ade7 | 9956 | u32 temp, dpll_ctl1; |
96b7dfb7 S |
9957 | |
9958 | temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port); | |
9959 | pipe_config->ddi_pll_sel = temp >> (port * 3 + 1); | |
9960 | ||
9961 | switch (pipe_config->ddi_pll_sel) { | |
3148ade7 DL |
9962 | case SKL_DPLL0: |
9963 | /* | |
9964 | * On SKL the eDP DPLL (DPLL0 as we don't use SSC) is not part | |
9965 | * of the shared DPLL framework and thus needs to be read out | |
9966 | * separately | |
9967 | */ | |
9968 | dpll_ctl1 = I915_READ(DPLL_CTRL1); | |
9969 | pipe_config->dpll_hw_state.ctrl1 = dpll_ctl1 & 0x3f; | |
9970 | break; | |
96b7dfb7 S |
9971 | case SKL_DPLL1: |
9972 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; | |
9973 | break; | |
9974 | case SKL_DPLL2: | |
9975 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; | |
9976 | break; | |
9977 | case SKL_DPLL3: | |
9978 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; | |
9979 | break; | |
96b7dfb7 S |
9980 | } |
9981 | } | |
9982 | ||
7d2c8175 DL |
9983 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
9984 | enum port port, | |
5cec258b | 9985 | struct intel_crtc_state *pipe_config) |
7d2c8175 DL |
9986 | { |
9987 | pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); | |
9988 | ||
9989 | switch (pipe_config->ddi_pll_sel) { | |
9990 | case PORT_CLK_SEL_WRPLL1: | |
9991 | pipe_config->shared_dpll = DPLL_ID_WRPLL1; | |
9992 | break; | |
9993 | case PORT_CLK_SEL_WRPLL2: | |
9994 | pipe_config->shared_dpll = DPLL_ID_WRPLL2; | |
9995 | break; | |
00490c22 ML |
9996 | case PORT_CLK_SEL_SPLL: |
9997 | pipe_config->shared_dpll = DPLL_ID_SPLL; | |
79bd23da | 9998 | break; |
7d2c8175 DL |
9999 | } |
10000 | } | |
10001 | ||
26804afd | 10002 | static void haswell_get_ddi_port_state(struct intel_crtc *crtc, |
5cec258b | 10003 | struct intel_crtc_state *pipe_config) |
26804afd DV |
10004 | { |
10005 | struct drm_device *dev = crtc->base.dev; | |
10006 | struct drm_i915_private *dev_priv = dev->dev_private; | |
d452c5b6 | 10007 | struct intel_shared_dpll *pll; |
26804afd DV |
10008 | enum port port; |
10009 | uint32_t tmp; | |
10010 | ||
10011 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); | |
10012 | ||
10013 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; | |
10014 | ||
ef11bdb3 | 10015 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
96b7dfb7 | 10016 | skylake_get_ddi_pll(dev_priv, port, pipe_config); |
3760b59c S |
10017 | else if (IS_BROXTON(dev)) |
10018 | bxt_get_ddi_pll(dev_priv, port, pipe_config); | |
96b7dfb7 S |
10019 | else |
10020 | haswell_get_ddi_pll(dev_priv, port, pipe_config); | |
9cd86933 | 10021 | |
d452c5b6 DV |
10022 | if (pipe_config->shared_dpll >= 0) { |
10023 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; | |
10024 | ||
10025 | WARN_ON(!pll->get_hw_state(dev_priv, pll, | |
10026 | &pipe_config->dpll_hw_state)); | |
10027 | } | |
10028 | ||
26804afd DV |
10029 | /* |
10030 | * Haswell has only FDI/PCH transcoder A. It is which is connected to | |
10031 | * DDI E. So just check whether this pipe is wired to DDI E and whether | |
10032 | * the PCH transcoder is on. | |
10033 | */ | |
ca370455 DL |
10034 | if (INTEL_INFO(dev)->gen < 9 && |
10035 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { | |
26804afd DV |
10036 | pipe_config->has_pch_encoder = true; |
10037 | ||
10038 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); | |
10039 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> | |
10040 | FDI_DP_PORT_WIDTH_SHIFT) + 1; | |
10041 | ||
10042 | ironlake_get_fdi_m_n_config(crtc, pipe_config); | |
10043 | } | |
10044 | } | |
10045 | ||
0e8ffe1b | 10046 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 10047 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
10048 | { |
10049 | struct drm_device *dev = crtc->base.dev; | |
10050 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1729050e ID |
10051 | enum intel_display_power_domain power_domain; |
10052 | unsigned long power_domain_mask; | |
0e8ffe1b | 10053 | uint32_t tmp; |
1729050e | 10054 | bool ret; |
0e8ffe1b | 10055 | |
1729050e ID |
10056 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
10057 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) | |
b5482bd0 | 10058 | return false; |
1729050e ID |
10059 | power_domain_mask = BIT(power_domain); |
10060 | ||
10061 | ret = false; | |
b5482bd0 | 10062 | |
e143a21c | 10063 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
c0d43d62 DV |
10064 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
10065 | ||
eccb140b DV |
10066 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
10067 | if (tmp & TRANS_DDI_FUNC_ENABLE) { | |
10068 | enum pipe trans_edp_pipe; | |
10069 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { | |
10070 | default: | |
10071 | WARN(1, "unknown pipe linked to edp transcoder\n"); | |
10072 | case TRANS_DDI_EDP_INPUT_A_ONOFF: | |
10073 | case TRANS_DDI_EDP_INPUT_A_ON: | |
10074 | trans_edp_pipe = PIPE_A; | |
10075 | break; | |
10076 | case TRANS_DDI_EDP_INPUT_B_ONOFF: | |
10077 | trans_edp_pipe = PIPE_B; | |
10078 | break; | |
10079 | case TRANS_DDI_EDP_INPUT_C_ONOFF: | |
10080 | trans_edp_pipe = PIPE_C; | |
10081 | break; | |
10082 | } | |
10083 | ||
10084 | if (trans_edp_pipe == crtc->pipe) | |
10085 | pipe_config->cpu_transcoder = TRANSCODER_EDP; | |
10086 | } | |
10087 | ||
1729050e ID |
10088 | power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder); |
10089 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) | |
10090 | goto out; | |
10091 | power_domain_mask |= BIT(power_domain); | |
2bfce950 | 10092 | |
eccb140b | 10093 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
0e8ffe1b | 10094 | if (!(tmp & PIPECONF_ENABLE)) |
1729050e | 10095 | goto out; |
0e8ffe1b | 10096 | |
26804afd | 10097 | haswell_get_ddi_port_state(crtc, pipe_config); |
627eb5a3 | 10098 | |
1bd1bd80 DV |
10099 | intel_get_pipe_timings(crtc, pipe_config); |
10100 | ||
a1b2278e CK |
10101 | if (INTEL_INFO(dev)->gen >= 9) { |
10102 | skl_init_scalers(dev, crtc, pipe_config); | |
10103 | } | |
10104 | ||
af99ceda CK |
10105 | if (INTEL_INFO(dev)->gen >= 9) { |
10106 | pipe_config->scaler_state.scaler_id = -1; | |
10107 | pipe_config->scaler_state.scaler_users &= ~(1 << SKL_CRTC_INDEX); | |
10108 | } | |
10109 | ||
1729050e ID |
10110 | power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
10111 | if (intel_display_power_get_if_enabled(dev_priv, power_domain)) { | |
10112 | power_domain_mask |= BIT(power_domain); | |
1c132b44 | 10113 | if (INTEL_INFO(dev)->gen >= 9) |
bd2e244f | 10114 | skylake_get_pfit_config(crtc, pipe_config); |
ff6d9f55 | 10115 | else |
1c132b44 | 10116 | ironlake_get_pfit_config(crtc, pipe_config); |
bd2e244f | 10117 | } |
88adfff1 | 10118 | |
e59150dc JB |
10119 | if (IS_HASWELL(dev)) |
10120 | pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) && | |
10121 | (I915_READ(IPS_CTL) & IPS_ENABLE); | |
42db64ef | 10122 | |
ebb69c95 CT |
10123 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP) { |
10124 | pipe_config->pixel_multiplier = | |
10125 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; | |
10126 | } else { | |
10127 | pipe_config->pixel_multiplier = 1; | |
10128 | } | |
6c49f241 | 10129 | |
1729050e ID |
10130 | ret = true; |
10131 | ||
10132 | out: | |
10133 | for_each_power_domain(power_domain, power_domain_mask) | |
10134 | intel_display_power_put(dev_priv, power_domain); | |
10135 | ||
10136 | return ret; | |
0e8ffe1b DV |
10137 | } |
10138 | ||
55a08b3f ML |
10139 | static void i845_update_cursor(struct drm_crtc *crtc, u32 base, |
10140 | const struct intel_plane_state *plane_state) | |
560b85bb CW |
10141 | { |
10142 | struct drm_device *dev = crtc->dev; | |
10143 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10144 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
dc41c154 | 10145 | uint32_t cntl = 0, size = 0; |
560b85bb | 10146 | |
55a08b3f ML |
10147 | if (plane_state && plane_state->visible) { |
10148 | unsigned int width = plane_state->base.crtc_w; | |
10149 | unsigned int height = plane_state->base.crtc_h; | |
dc41c154 VS |
10150 | unsigned int stride = roundup_pow_of_two(width) * 4; |
10151 | ||
10152 | switch (stride) { | |
10153 | default: | |
10154 | WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n", | |
10155 | width, stride); | |
10156 | stride = 256; | |
10157 | /* fallthrough */ | |
10158 | case 256: | |
10159 | case 512: | |
10160 | case 1024: | |
10161 | case 2048: | |
10162 | break; | |
4b0e333e CW |
10163 | } |
10164 | ||
dc41c154 VS |
10165 | cntl |= CURSOR_ENABLE | |
10166 | CURSOR_GAMMA_ENABLE | | |
10167 | CURSOR_FORMAT_ARGB | | |
10168 | CURSOR_STRIDE(stride); | |
10169 | ||
10170 | size = (height << 12) | width; | |
4b0e333e | 10171 | } |
560b85bb | 10172 | |
dc41c154 VS |
10173 | if (intel_crtc->cursor_cntl != 0 && |
10174 | (intel_crtc->cursor_base != base || | |
10175 | intel_crtc->cursor_size != size || | |
10176 | intel_crtc->cursor_cntl != cntl)) { | |
10177 | /* On these chipsets we can only modify the base/size/stride | |
10178 | * whilst the cursor is disabled. | |
10179 | */ | |
0b87c24e VS |
10180 | I915_WRITE(CURCNTR(PIPE_A), 0); |
10181 | POSTING_READ(CURCNTR(PIPE_A)); | |
dc41c154 | 10182 | intel_crtc->cursor_cntl = 0; |
4b0e333e | 10183 | } |
560b85bb | 10184 | |
99d1f387 | 10185 | if (intel_crtc->cursor_base != base) { |
0b87c24e | 10186 | I915_WRITE(CURBASE(PIPE_A), base); |
99d1f387 VS |
10187 | intel_crtc->cursor_base = base; |
10188 | } | |
4726e0b0 | 10189 | |
dc41c154 VS |
10190 | if (intel_crtc->cursor_size != size) { |
10191 | I915_WRITE(CURSIZE, size); | |
10192 | intel_crtc->cursor_size = size; | |
4b0e333e | 10193 | } |
560b85bb | 10194 | |
4b0e333e | 10195 | if (intel_crtc->cursor_cntl != cntl) { |
0b87c24e VS |
10196 | I915_WRITE(CURCNTR(PIPE_A), cntl); |
10197 | POSTING_READ(CURCNTR(PIPE_A)); | |
4b0e333e | 10198 | intel_crtc->cursor_cntl = cntl; |
560b85bb | 10199 | } |
560b85bb CW |
10200 | } |
10201 | ||
55a08b3f ML |
10202 | static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base, |
10203 | const struct intel_plane_state *plane_state) | |
65a21cd6 JB |
10204 | { |
10205 | struct drm_device *dev = crtc->dev; | |
10206 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10207 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10208 | int pipe = intel_crtc->pipe; | |
663f3122 | 10209 | uint32_t cntl = 0; |
4b0e333e | 10210 | |
55a08b3f | 10211 | if (plane_state && plane_state->visible) { |
4b0e333e | 10212 | cntl = MCURSOR_GAMMA_ENABLE; |
55a08b3f | 10213 | switch (plane_state->base.crtc_w) { |
4726e0b0 SK |
10214 | case 64: |
10215 | cntl |= CURSOR_MODE_64_ARGB_AX; | |
10216 | break; | |
10217 | case 128: | |
10218 | cntl |= CURSOR_MODE_128_ARGB_AX; | |
10219 | break; | |
10220 | case 256: | |
10221 | cntl |= CURSOR_MODE_256_ARGB_AX; | |
10222 | break; | |
10223 | default: | |
55a08b3f | 10224 | MISSING_CASE(plane_state->base.crtc_w); |
4726e0b0 | 10225 | return; |
65a21cd6 | 10226 | } |
4b0e333e | 10227 | cntl |= pipe << 28; /* Connect to correct pipe */ |
47bf17a7 | 10228 | |
fc6f93bc | 10229 | if (HAS_DDI(dev)) |
47bf17a7 | 10230 | cntl |= CURSOR_PIPE_CSC_ENABLE; |
65a21cd6 | 10231 | |
55a08b3f ML |
10232 | if (plane_state->base.rotation == BIT(DRM_ROTATE_180)) |
10233 | cntl |= CURSOR_ROTATE_180; | |
10234 | } | |
4398ad45 | 10235 | |
4b0e333e CW |
10236 | if (intel_crtc->cursor_cntl != cntl) { |
10237 | I915_WRITE(CURCNTR(pipe), cntl); | |
10238 | POSTING_READ(CURCNTR(pipe)); | |
10239 | intel_crtc->cursor_cntl = cntl; | |
65a21cd6 | 10240 | } |
4b0e333e | 10241 | |
65a21cd6 | 10242 | /* and commit changes on next vblank */ |
5efb3e28 VS |
10243 | I915_WRITE(CURBASE(pipe), base); |
10244 | POSTING_READ(CURBASE(pipe)); | |
99d1f387 VS |
10245 | |
10246 | intel_crtc->cursor_base = base; | |
65a21cd6 JB |
10247 | } |
10248 | ||
cda4b7d3 | 10249 | /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */ |
6b383a7f | 10250 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, |
55a08b3f | 10251 | const struct intel_plane_state *plane_state) |
cda4b7d3 CW |
10252 | { |
10253 | struct drm_device *dev = crtc->dev; | |
10254 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10255 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10256 | int pipe = intel_crtc->pipe; | |
55a08b3f ML |
10257 | u32 base = intel_crtc->cursor_addr; |
10258 | u32 pos = 0; | |
cda4b7d3 | 10259 | |
55a08b3f ML |
10260 | if (plane_state) { |
10261 | int x = plane_state->base.crtc_x; | |
10262 | int y = plane_state->base.crtc_y; | |
cda4b7d3 | 10263 | |
55a08b3f ML |
10264 | if (x < 0) { |
10265 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; | |
10266 | x = -x; | |
10267 | } | |
10268 | pos |= x << CURSOR_X_SHIFT; | |
cda4b7d3 | 10269 | |
55a08b3f ML |
10270 | if (y < 0) { |
10271 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; | |
10272 | y = -y; | |
10273 | } | |
10274 | pos |= y << CURSOR_Y_SHIFT; | |
10275 | ||
10276 | /* ILK+ do this automagically */ | |
10277 | if (HAS_GMCH_DISPLAY(dev) && | |
10278 | plane_state->base.rotation == BIT(DRM_ROTATE_180)) { | |
10279 | base += (plane_state->base.crtc_h * | |
10280 | plane_state->base.crtc_w - 1) * 4; | |
10281 | } | |
cda4b7d3 | 10282 | } |
cda4b7d3 | 10283 | |
5efb3e28 VS |
10284 | I915_WRITE(CURPOS(pipe), pos); |
10285 | ||
8ac54669 | 10286 | if (IS_845G(dev) || IS_I865G(dev)) |
55a08b3f | 10287 | i845_update_cursor(crtc, base, plane_state); |
5efb3e28 | 10288 | else |
55a08b3f | 10289 | i9xx_update_cursor(crtc, base, plane_state); |
cda4b7d3 CW |
10290 | } |
10291 | ||
dc41c154 VS |
10292 | static bool cursor_size_ok(struct drm_device *dev, |
10293 | uint32_t width, uint32_t height) | |
10294 | { | |
10295 | if (width == 0 || height == 0) | |
10296 | return false; | |
10297 | ||
10298 | /* | |
10299 | * 845g/865g are special in that they are only limited by | |
10300 | * the width of their cursors, the height is arbitrary up to | |
10301 | * the precision of the register. Everything else requires | |
10302 | * square cursors, limited to a few power-of-two sizes. | |
10303 | */ | |
10304 | if (IS_845G(dev) || IS_I865G(dev)) { | |
10305 | if ((width & 63) != 0) | |
10306 | return false; | |
10307 | ||
10308 | if (width > (IS_845G(dev) ? 64 : 512)) | |
10309 | return false; | |
10310 | ||
10311 | if (height > 1023) | |
10312 | return false; | |
10313 | } else { | |
10314 | switch (width | height) { | |
10315 | case 256: | |
10316 | case 128: | |
10317 | if (IS_GEN2(dev)) | |
10318 | return false; | |
10319 | case 64: | |
10320 | break; | |
10321 | default: | |
10322 | return false; | |
10323 | } | |
10324 | } | |
10325 | ||
10326 | return true; | |
10327 | } | |
10328 | ||
79e53945 | 10329 | static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, |
7203425a | 10330 | u16 *blue, uint32_t start, uint32_t size) |
79e53945 | 10331 | { |
7203425a | 10332 | int end = (start + size > 256) ? 256 : start + size, i; |
79e53945 | 10333 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
79e53945 | 10334 | |
7203425a | 10335 | for (i = start; i < end; i++) { |
79e53945 JB |
10336 | intel_crtc->lut_r[i] = red[i] >> 8; |
10337 | intel_crtc->lut_g[i] = green[i] >> 8; | |
10338 | intel_crtc->lut_b[i] = blue[i] >> 8; | |
10339 | } | |
10340 | ||
10341 | intel_crtc_load_lut(crtc); | |
10342 | } | |
10343 | ||
79e53945 JB |
10344 | /* VESA 640x480x72Hz mode to set on the pipe */ |
10345 | static struct drm_display_mode load_detect_mode = { | |
10346 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, | |
10347 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), | |
10348 | }; | |
10349 | ||
a8bb6818 DV |
10350 | struct drm_framebuffer * |
10351 | __intel_framebuffer_create(struct drm_device *dev, | |
10352 | struct drm_mode_fb_cmd2 *mode_cmd, | |
10353 | struct drm_i915_gem_object *obj) | |
d2dff872 CW |
10354 | { |
10355 | struct intel_framebuffer *intel_fb; | |
10356 | int ret; | |
10357 | ||
10358 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); | |
dcb1394e | 10359 | if (!intel_fb) |
d2dff872 | 10360 | return ERR_PTR(-ENOMEM); |
d2dff872 CW |
10361 | |
10362 | ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj); | |
dd4916c5 DV |
10363 | if (ret) |
10364 | goto err; | |
d2dff872 CW |
10365 | |
10366 | return &intel_fb->base; | |
dcb1394e | 10367 | |
dd4916c5 | 10368 | err: |
dd4916c5 | 10369 | kfree(intel_fb); |
dd4916c5 | 10370 | return ERR_PTR(ret); |
d2dff872 CW |
10371 | } |
10372 | ||
b5ea642a | 10373 | static struct drm_framebuffer * |
a8bb6818 DV |
10374 | intel_framebuffer_create(struct drm_device *dev, |
10375 | struct drm_mode_fb_cmd2 *mode_cmd, | |
10376 | struct drm_i915_gem_object *obj) | |
10377 | { | |
10378 | struct drm_framebuffer *fb; | |
10379 | int ret; | |
10380 | ||
10381 | ret = i915_mutex_lock_interruptible(dev); | |
10382 | if (ret) | |
10383 | return ERR_PTR(ret); | |
10384 | fb = __intel_framebuffer_create(dev, mode_cmd, obj); | |
10385 | mutex_unlock(&dev->struct_mutex); | |
10386 | ||
10387 | return fb; | |
10388 | } | |
10389 | ||
d2dff872 CW |
10390 | static u32 |
10391 | intel_framebuffer_pitch_for_width(int width, int bpp) | |
10392 | { | |
10393 | u32 pitch = DIV_ROUND_UP(width * bpp, 8); | |
10394 | return ALIGN(pitch, 64); | |
10395 | } | |
10396 | ||
10397 | static u32 | |
10398 | intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp) | |
10399 | { | |
10400 | u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp); | |
1267a26b | 10401 | return PAGE_ALIGN(pitch * mode->vdisplay); |
d2dff872 CW |
10402 | } |
10403 | ||
10404 | static struct drm_framebuffer * | |
10405 | intel_framebuffer_create_for_mode(struct drm_device *dev, | |
10406 | struct drm_display_mode *mode, | |
10407 | int depth, int bpp) | |
10408 | { | |
dcb1394e | 10409 | struct drm_framebuffer *fb; |
d2dff872 | 10410 | struct drm_i915_gem_object *obj; |
0fed39bd | 10411 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
d2dff872 CW |
10412 | |
10413 | obj = i915_gem_alloc_object(dev, | |
10414 | intel_framebuffer_size_for_mode(mode, bpp)); | |
10415 | if (obj == NULL) | |
10416 | return ERR_PTR(-ENOMEM); | |
10417 | ||
10418 | mode_cmd.width = mode->hdisplay; | |
10419 | mode_cmd.height = mode->vdisplay; | |
308e5bcb JB |
10420 | mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width, |
10421 | bpp); | |
5ca0c34a | 10422 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); |
d2dff872 | 10423 | |
dcb1394e LW |
10424 | fb = intel_framebuffer_create(dev, &mode_cmd, obj); |
10425 | if (IS_ERR(fb)) | |
10426 | drm_gem_object_unreference_unlocked(&obj->base); | |
10427 | ||
10428 | return fb; | |
d2dff872 CW |
10429 | } |
10430 | ||
10431 | static struct drm_framebuffer * | |
10432 | mode_fits_in_fbdev(struct drm_device *dev, | |
10433 | struct drm_display_mode *mode) | |
10434 | { | |
0695726e | 10435 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
d2dff872 CW |
10436 | struct drm_i915_private *dev_priv = dev->dev_private; |
10437 | struct drm_i915_gem_object *obj; | |
10438 | struct drm_framebuffer *fb; | |
10439 | ||
4c0e5528 | 10440 | if (!dev_priv->fbdev) |
d2dff872 CW |
10441 | return NULL; |
10442 | ||
4c0e5528 | 10443 | if (!dev_priv->fbdev->fb) |
d2dff872 CW |
10444 | return NULL; |
10445 | ||
4c0e5528 DV |
10446 | obj = dev_priv->fbdev->fb->obj; |
10447 | BUG_ON(!obj); | |
10448 | ||
8bcd4553 | 10449 | fb = &dev_priv->fbdev->fb->base; |
01f2c773 VS |
10450 | if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay, |
10451 | fb->bits_per_pixel)) | |
d2dff872 CW |
10452 | return NULL; |
10453 | ||
01f2c773 | 10454 | if (obj->base.size < mode->vdisplay * fb->pitches[0]) |
d2dff872 CW |
10455 | return NULL; |
10456 | ||
edde3617 | 10457 | drm_framebuffer_reference(fb); |
d2dff872 | 10458 | return fb; |
4520f53a DV |
10459 | #else |
10460 | return NULL; | |
10461 | #endif | |
d2dff872 CW |
10462 | } |
10463 | ||
d3a40d1b ACO |
10464 | static int intel_modeset_setup_plane_state(struct drm_atomic_state *state, |
10465 | struct drm_crtc *crtc, | |
10466 | struct drm_display_mode *mode, | |
10467 | struct drm_framebuffer *fb, | |
10468 | int x, int y) | |
10469 | { | |
10470 | struct drm_plane_state *plane_state; | |
10471 | int hdisplay, vdisplay; | |
10472 | int ret; | |
10473 | ||
10474 | plane_state = drm_atomic_get_plane_state(state, crtc->primary); | |
10475 | if (IS_ERR(plane_state)) | |
10476 | return PTR_ERR(plane_state); | |
10477 | ||
10478 | if (mode) | |
10479 | drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay); | |
10480 | else | |
10481 | hdisplay = vdisplay = 0; | |
10482 | ||
10483 | ret = drm_atomic_set_crtc_for_plane(plane_state, fb ? crtc : NULL); | |
10484 | if (ret) | |
10485 | return ret; | |
10486 | drm_atomic_set_fb_for_plane(plane_state, fb); | |
10487 | plane_state->crtc_x = 0; | |
10488 | plane_state->crtc_y = 0; | |
10489 | plane_state->crtc_w = hdisplay; | |
10490 | plane_state->crtc_h = vdisplay; | |
10491 | plane_state->src_x = x << 16; | |
10492 | plane_state->src_y = y << 16; | |
10493 | plane_state->src_w = hdisplay << 16; | |
10494 | plane_state->src_h = vdisplay << 16; | |
10495 | ||
10496 | return 0; | |
10497 | } | |
10498 | ||
d2434ab7 | 10499 | bool intel_get_load_detect_pipe(struct drm_connector *connector, |
7173188d | 10500 | struct drm_display_mode *mode, |
51fd371b RC |
10501 | struct intel_load_detect_pipe *old, |
10502 | struct drm_modeset_acquire_ctx *ctx) | |
79e53945 JB |
10503 | { |
10504 | struct intel_crtc *intel_crtc; | |
d2434ab7 DV |
10505 | struct intel_encoder *intel_encoder = |
10506 | intel_attached_encoder(connector); | |
79e53945 | 10507 | struct drm_crtc *possible_crtc; |
4ef69c7a | 10508 | struct drm_encoder *encoder = &intel_encoder->base; |
79e53945 JB |
10509 | struct drm_crtc *crtc = NULL; |
10510 | struct drm_device *dev = encoder->dev; | |
94352cf9 | 10511 | struct drm_framebuffer *fb; |
51fd371b | 10512 | struct drm_mode_config *config = &dev->mode_config; |
edde3617 | 10513 | struct drm_atomic_state *state = NULL, *restore_state = NULL; |
944b0c76 | 10514 | struct drm_connector_state *connector_state; |
4be07317 | 10515 | struct intel_crtc_state *crtc_state; |
51fd371b | 10516 | int ret, i = -1; |
79e53945 | 10517 | |
d2dff872 | 10518 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
c23cc417 | 10519 | connector->base.id, connector->name, |
8e329a03 | 10520 | encoder->base.id, encoder->name); |
d2dff872 | 10521 | |
edde3617 ML |
10522 | old->restore_state = NULL; |
10523 | ||
51fd371b RC |
10524 | retry: |
10525 | ret = drm_modeset_lock(&config->connection_mutex, ctx); | |
10526 | if (ret) | |
ad3c558f | 10527 | goto fail; |
6e9f798d | 10528 | |
79e53945 JB |
10529 | /* |
10530 | * Algorithm gets a little messy: | |
7a5e4805 | 10531 | * |
79e53945 JB |
10532 | * - if the connector already has an assigned crtc, use it (but make |
10533 | * sure it's on first) | |
7a5e4805 | 10534 | * |
79e53945 JB |
10535 | * - try to find the first unused crtc that can drive this connector, |
10536 | * and use that if we find one | |
79e53945 JB |
10537 | */ |
10538 | ||
10539 | /* See if we already have a CRTC for this connector */ | |
edde3617 ML |
10540 | if (connector->state->crtc) { |
10541 | crtc = connector->state->crtc; | |
8261b191 | 10542 | |
51fd371b | 10543 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
4d02e2de | 10544 | if (ret) |
ad3c558f | 10545 | goto fail; |
8261b191 CW |
10546 | |
10547 | /* Make sure the crtc and connector are running */ | |
edde3617 | 10548 | goto found; |
79e53945 JB |
10549 | } |
10550 | ||
10551 | /* Find an unused one (if possible) */ | |
70e1e0ec | 10552 | for_each_crtc(dev, possible_crtc) { |
79e53945 JB |
10553 | i++; |
10554 | if (!(encoder->possible_crtcs & (1 << i))) | |
10555 | continue; | |
edde3617 ML |
10556 | |
10557 | ret = drm_modeset_lock(&possible_crtc->mutex, ctx); | |
10558 | if (ret) | |
10559 | goto fail; | |
10560 | ||
10561 | if (possible_crtc->state->enable) { | |
10562 | drm_modeset_unlock(&possible_crtc->mutex); | |
a459249c | 10563 | continue; |
edde3617 | 10564 | } |
a459249c VS |
10565 | |
10566 | crtc = possible_crtc; | |
10567 | break; | |
79e53945 JB |
10568 | } |
10569 | ||
10570 | /* | |
10571 | * If we didn't find an unused CRTC, don't use any. | |
10572 | */ | |
10573 | if (!crtc) { | |
7173188d | 10574 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
ad3c558f | 10575 | goto fail; |
79e53945 JB |
10576 | } |
10577 | ||
edde3617 ML |
10578 | found: |
10579 | intel_crtc = to_intel_crtc(crtc); | |
10580 | ||
4d02e2de DV |
10581 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
10582 | if (ret) | |
ad3c558f | 10583 | goto fail; |
79e53945 | 10584 | |
83a57153 | 10585 | state = drm_atomic_state_alloc(dev); |
edde3617 ML |
10586 | restore_state = drm_atomic_state_alloc(dev); |
10587 | if (!state || !restore_state) { | |
10588 | ret = -ENOMEM; | |
10589 | goto fail; | |
10590 | } | |
83a57153 ACO |
10591 | |
10592 | state->acquire_ctx = ctx; | |
edde3617 | 10593 | restore_state->acquire_ctx = ctx; |
83a57153 | 10594 | |
944b0c76 ACO |
10595 | connector_state = drm_atomic_get_connector_state(state, connector); |
10596 | if (IS_ERR(connector_state)) { | |
10597 | ret = PTR_ERR(connector_state); | |
10598 | goto fail; | |
10599 | } | |
10600 | ||
edde3617 ML |
10601 | ret = drm_atomic_set_crtc_for_connector(connector_state, crtc); |
10602 | if (ret) | |
10603 | goto fail; | |
944b0c76 | 10604 | |
4be07317 ACO |
10605 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
10606 | if (IS_ERR(crtc_state)) { | |
10607 | ret = PTR_ERR(crtc_state); | |
10608 | goto fail; | |
10609 | } | |
10610 | ||
49d6fa21 | 10611 | crtc_state->base.active = crtc_state->base.enable = true; |
4be07317 | 10612 | |
6492711d CW |
10613 | if (!mode) |
10614 | mode = &load_detect_mode; | |
79e53945 | 10615 | |
d2dff872 CW |
10616 | /* We need a framebuffer large enough to accommodate all accesses |
10617 | * that the plane may generate whilst we perform load detection. | |
10618 | * We can not rely on the fbcon either being present (we get called | |
10619 | * during its initialisation to detect all boot displays, or it may | |
10620 | * not even exist) or that it is large enough to satisfy the | |
10621 | * requested mode. | |
10622 | */ | |
94352cf9 DV |
10623 | fb = mode_fits_in_fbdev(dev, mode); |
10624 | if (fb == NULL) { | |
d2dff872 | 10625 | DRM_DEBUG_KMS("creating tmp fb for load-detection\n"); |
94352cf9 | 10626 | fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32); |
d2dff872 CW |
10627 | } else |
10628 | DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); | |
94352cf9 | 10629 | if (IS_ERR(fb)) { |
d2dff872 | 10630 | DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); |
412b61d8 | 10631 | goto fail; |
79e53945 | 10632 | } |
79e53945 | 10633 | |
d3a40d1b ACO |
10634 | ret = intel_modeset_setup_plane_state(state, crtc, mode, fb, 0, 0); |
10635 | if (ret) | |
10636 | goto fail; | |
10637 | ||
edde3617 ML |
10638 | drm_framebuffer_unreference(fb); |
10639 | ||
10640 | ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode); | |
10641 | if (ret) | |
10642 | goto fail; | |
10643 | ||
10644 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector)); | |
10645 | if (!ret) | |
10646 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc)); | |
10647 | if (!ret) | |
10648 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_plane_state(restore_state, crtc->primary)); | |
10649 | if (ret) { | |
10650 | DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret); | |
10651 | goto fail; | |
10652 | } | |
8c7b5ccb | 10653 | |
3ba86073 ML |
10654 | ret = drm_atomic_commit(state); |
10655 | if (ret) { | |
6492711d | 10656 | DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); |
412b61d8 | 10657 | goto fail; |
79e53945 | 10658 | } |
edde3617 ML |
10659 | |
10660 | old->restore_state = restore_state; | |
7173188d | 10661 | |
79e53945 | 10662 | /* let the connector get through one full cycle before testing */ |
9d0498a2 | 10663 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
7173188d | 10664 | return true; |
412b61d8 | 10665 | |
ad3c558f | 10666 | fail: |
e5d958ef | 10667 | drm_atomic_state_free(state); |
edde3617 ML |
10668 | drm_atomic_state_free(restore_state); |
10669 | restore_state = state = NULL; | |
83a57153 | 10670 | |
51fd371b RC |
10671 | if (ret == -EDEADLK) { |
10672 | drm_modeset_backoff(ctx); | |
10673 | goto retry; | |
10674 | } | |
10675 | ||
412b61d8 | 10676 | return false; |
79e53945 JB |
10677 | } |
10678 | ||
d2434ab7 | 10679 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
49172fee ACO |
10680 | struct intel_load_detect_pipe *old, |
10681 | struct drm_modeset_acquire_ctx *ctx) | |
79e53945 | 10682 | { |
d2434ab7 DV |
10683 | struct intel_encoder *intel_encoder = |
10684 | intel_attached_encoder(connector); | |
4ef69c7a | 10685 | struct drm_encoder *encoder = &intel_encoder->base; |
edde3617 | 10686 | struct drm_atomic_state *state = old->restore_state; |
d3a40d1b | 10687 | int ret; |
79e53945 | 10688 | |
d2dff872 | 10689 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
c23cc417 | 10690 | connector->base.id, connector->name, |
8e329a03 | 10691 | encoder->base.id, encoder->name); |
d2dff872 | 10692 | |
edde3617 | 10693 | if (!state) |
0622a53c | 10694 | return; |
79e53945 | 10695 | |
edde3617 ML |
10696 | ret = drm_atomic_commit(state); |
10697 | if (ret) { | |
10698 | DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret); | |
10699 | drm_atomic_state_free(state); | |
10700 | } | |
79e53945 JB |
10701 | } |
10702 | ||
da4a1efa | 10703 | static int i9xx_pll_refclk(struct drm_device *dev, |
5cec258b | 10704 | const struct intel_crtc_state *pipe_config) |
da4a1efa VS |
10705 | { |
10706 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10707 | u32 dpll = pipe_config->dpll_hw_state.dpll; | |
10708 | ||
10709 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) | |
e91e941b | 10710 | return dev_priv->vbt.lvds_ssc_freq; |
da4a1efa VS |
10711 | else if (HAS_PCH_SPLIT(dev)) |
10712 | return 120000; | |
10713 | else if (!IS_GEN2(dev)) | |
10714 | return 96000; | |
10715 | else | |
10716 | return 48000; | |
10717 | } | |
10718 | ||
79e53945 | 10719 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
f1f644dc | 10720 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 10721 | struct intel_crtc_state *pipe_config) |
79e53945 | 10722 | { |
f1f644dc | 10723 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 10724 | struct drm_i915_private *dev_priv = dev->dev_private; |
f1f644dc | 10725 | int pipe = pipe_config->cpu_transcoder; |
293623f7 | 10726 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
79e53945 JB |
10727 | u32 fp; |
10728 | intel_clock_t clock; | |
dccbea3b | 10729 | int port_clock; |
da4a1efa | 10730 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
79e53945 JB |
10731 | |
10732 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) | |
293623f7 | 10733 | fp = pipe_config->dpll_hw_state.fp0; |
79e53945 | 10734 | else |
293623f7 | 10735 | fp = pipe_config->dpll_hw_state.fp1; |
79e53945 JB |
10736 | |
10737 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; | |
f2b115e6 AJ |
10738 | if (IS_PINEVIEW(dev)) { |
10739 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; | |
10740 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
2177832f SL |
10741 | } else { |
10742 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; | |
10743 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
10744 | } | |
10745 | ||
a6c45cf0 | 10746 | if (!IS_GEN2(dev)) { |
f2b115e6 AJ |
10747 | if (IS_PINEVIEW(dev)) |
10748 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> | |
10749 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); | |
2177832f SL |
10750 | else |
10751 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> | |
79e53945 JB |
10752 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
10753 | ||
10754 | switch (dpll & DPLL_MODE_MASK) { | |
10755 | case DPLLB_MODE_DAC_SERIAL: | |
10756 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? | |
10757 | 5 : 10; | |
10758 | break; | |
10759 | case DPLLB_MODE_LVDS: | |
10760 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? | |
10761 | 7 : 14; | |
10762 | break; | |
10763 | default: | |
28c97730 | 10764 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
79e53945 | 10765 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
f1f644dc | 10766 | return; |
79e53945 JB |
10767 | } |
10768 | ||
ac58c3f0 | 10769 | if (IS_PINEVIEW(dev)) |
dccbea3b | 10770 | port_clock = pnv_calc_dpll_params(refclk, &clock); |
ac58c3f0 | 10771 | else |
dccbea3b | 10772 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
79e53945 | 10773 | } else { |
0fb58223 | 10774 | u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS); |
b1c560d1 | 10775 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
79e53945 JB |
10776 | |
10777 | if (is_lvds) { | |
10778 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> | |
10779 | DPLL_FPA01_P1_POST_DIV_SHIFT); | |
b1c560d1 VS |
10780 | |
10781 | if (lvds & LVDS_CLKB_POWER_UP) | |
10782 | clock.p2 = 7; | |
10783 | else | |
10784 | clock.p2 = 14; | |
79e53945 JB |
10785 | } else { |
10786 | if (dpll & PLL_P1_DIVIDE_BY_TWO) | |
10787 | clock.p1 = 2; | |
10788 | else { | |
10789 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> | |
10790 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; | |
10791 | } | |
10792 | if (dpll & PLL_P2_DIVIDE_BY_4) | |
10793 | clock.p2 = 4; | |
10794 | else | |
10795 | clock.p2 = 2; | |
79e53945 | 10796 | } |
da4a1efa | 10797 | |
dccbea3b | 10798 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
79e53945 JB |
10799 | } |
10800 | ||
18442d08 VS |
10801 | /* |
10802 | * This value includes pixel_multiplier. We will use | |
241bfc38 | 10803 | * port_clock to compute adjusted_mode.crtc_clock in the |
18442d08 VS |
10804 | * encoder's get_config() function. |
10805 | */ | |
dccbea3b | 10806 | pipe_config->port_clock = port_clock; |
f1f644dc JB |
10807 | } |
10808 | ||
6878da05 VS |
10809 | int intel_dotclock_calculate(int link_freq, |
10810 | const struct intel_link_m_n *m_n) | |
f1f644dc | 10811 | { |
f1f644dc JB |
10812 | /* |
10813 | * The calculation for the data clock is: | |
1041a02f | 10814 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
f1f644dc | 10815 | * But we want to avoid losing precison if possible, so: |
1041a02f | 10816 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
f1f644dc JB |
10817 | * |
10818 | * and the link clock is simpler: | |
1041a02f | 10819 | * link_clock = (m * link_clock) / n |
f1f644dc JB |
10820 | */ |
10821 | ||
6878da05 VS |
10822 | if (!m_n->link_n) |
10823 | return 0; | |
f1f644dc | 10824 | |
6878da05 VS |
10825 | return div_u64((u64)m_n->link_m * link_freq, m_n->link_n); |
10826 | } | |
f1f644dc | 10827 | |
18442d08 | 10828 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
5cec258b | 10829 | struct intel_crtc_state *pipe_config) |
6878da05 VS |
10830 | { |
10831 | struct drm_device *dev = crtc->base.dev; | |
79e53945 | 10832 | |
18442d08 VS |
10833 | /* read out port_clock from the DPLL */ |
10834 | i9xx_crtc_clock_get(crtc, pipe_config); | |
f1f644dc | 10835 | |
f1f644dc | 10836 | /* |
18442d08 | 10837 | * This value does not include pixel_multiplier. |
241bfc38 | 10838 | * We will check that port_clock and adjusted_mode.crtc_clock |
18442d08 VS |
10839 | * agree once we know their relationship in the encoder's |
10840 | * get_config() function. | |
79e53945 | 10841 | */ |
2d112de7 | 10842 | pipe_config->base.adjusted_mode.crtc_clock = |
18442d08 VS |
10843 | intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000, |
10844 | &pipe_config->fdi_m_n); | |
79e53945 JB |
10845 | } |
10846 | ||
10847 | /** Returns the currently programmed mode of the given pipe. */ | |
10848 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, | |
10849 | struct drm_crtc *crtc) | |
10850 | { | |
548f245b | 10851 | struct drm_i915_private *dev_priv = dev->dev_private; |
79e53945 | 10852 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
6e3c9717 | 10853 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
79e53945 | 10854 | struct drm_display_mode *mode; |
3f36b937 | 10855 | struct intel_crtc_state *pipe_config; |
fe2b8f9d PZ |
10856 | int htot = I915_READ(HTOTAL(cpu_transcoder)); |
10857 | int hsync = I915_READ(HSYNC(cpu_transcoder)); | |
10858 | int vtot = I915_READ(VTOTAL(cpu_transcoder)); | |
10859 | int vsync = I915_READ(VSYNC(cpu_transcoder)); | |
293623f7 | 10860 | enum pipe pipe = intel_crtc->pipe; |
79e53945 JB |
10861 | |
10862 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); | |
10863 | if (!mode) | |
10864 | return NULL; | |
10865 | ||
3f36b937 TU |
10866 | pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); |
10867 | if (!pipe_config) { | |
10868 | kfree(mode); | |
10869 | return NULL; | |
10870 | } | |
10871 | ||
f1f644dc JB |
10872 | /* |
10873 | * Construct a pipe_config sufficient for getting the clock info | |
10874 | * back out of crtc_clock_get. | |
10875 | * | |
10876 | * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need | |
10877 | * to use a real value here instead. | |
10878 | */ | |
3f36b937 TU |
10879 | pipe_config->cpu_transcoder = (enum transcoder) pipe; |
10880 | pipe_config->pixel_multiplier = 1; | |
10881 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(pipe)); | |
10882 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(pipe)); | |
10883 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(pipe)); | |
10884 | i9xx_crtc_clock_get(intel_crtc, pipe_config); | |
10885 | ||
10886 | mode->clock = pipe_config->port_clock / pipe_config->pixel_multiplier; | |
79e53945 JB |
10887 | mode->hdisplay = (htot & 0xffff) + 1; |
10888 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; | |
10889 | mode->hsync_start = (hsync & 0xffff) + 1; | |
10890 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; | |
10891 | mode->vdisplay = (vtot & 0xffff) + 1; | |
10892 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; | |
10893 | mode->vsync_start = (vsync & 0xffff) + 1; | |
10894 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; | |
10895 | ||
10896 | drm_mode_set_name(mode); | |
79e53945 | 10897 | |
3f36b937 TU |
10898 | kfree(pipe_config); |
10899 | ||
79e53945 JB |
10900 | return mode; |
10901 | } | |
10902 | ||
f047e395 CW |
10903 | void intel_mark_busy(struct drm_device *dev) |
10904 | { | |
c67a470b PZ |
10905 | struct drm_i915_private *dev_priv = dev->dev_private; |
10906 | ||
f62a0076 CW |
10907 | if (dev_priv->mm.busy) |
10908 | return; | |
10909 | ||
43694d69 | 10910 | intel_runtime_pm_get(dev_priv); |
c67a470b | 10911 | i915_update_gfx_val(dev_priv); |
43cf3bf0 CW |
10912 | if (INTEL_INFO(dev)->gen >= 6) |
10913 | gen6_rps_busy(dev_priv); | |
f62a0076 | 10914 | dev_priv->mm.busy = true; |
f047e395 CW |
10915 | } |
10916 | ||
10917 | void intel_mark_idle(struct drm_device *dev) | |
652c393a | 10918 | { |
c67a470b | 10919 | struct drm_i915_private *dev_priv = dev->dev_private; |
652c393a | 10920 | |
f62a0076 CW |
10921 | if (!dev_priv->mm.busy) |
10922 | return; | |
10923 | ||
10924 | dev_priv->mm.busy = false; | |
10925 | ||
3d13ef2e | 10926 | if (INTEL_INFO(dev)->gen >= 6) |
b29c19b6 | 10927 | gen6_rps_idle(dev->dev_private); |
bb4cdd53 | 10928 | |
43694d69 | 10929 | intel_runtime_pm_put(dev_priv); |
652c393a JB |
10930 | } |
10931 | ||
79e53945 JB |
10932 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
10933 | { | |
10934 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
67e77c5a DV |
10935 | struct drm_device *dev = crtc->dev; |
10936 | struct intel_unpin_work *work; | |
67e77c5a | 10937 | |
5e2d7afc | 10938 | spin_lock_irq(&dev->event_lock); |
67e77c5a DV |
10939 | work = intel_crtc->unpin_work; |
10940 | intel_crtc->unpin_work = NULL; | |
5e2d7afc | 10941 | spin_unlock_irq(&dev->event_lock); |
67e77c5a DV |
10942 | |
10943 | if (work) { | |
10944 | cancel_work_sync(&work->work); | |
10945 | kfree(work); | |
10946 | } | |
79e53945 JB |
10947 | |
10948 | drm_crtc_cleanup(crtc); | |
67e77c5a | 10949 | |
79e53945 JB |
10950 | kfree(intel_crtc); |
10951 | } | |
10952 | ||
6b95a207 KH |
10953 | static void intel_unpin_work_fn(struct work_struct *__work) |
10954 | { | |
10955 | struct intel_unpin_work *work = | |
10956 | container_of(__work, struct intel_unpin_work, work); | |
a9ff8714 VS |
10957 | struct intel_crtc *crtc = to_intel_crtc(work->crtc); |
10958 | struct drm_device *dev = crtc->base.dev; | |
10959 | struct drm_plane *primary = crtc->base.primary; | |
6b95a207 | 10960 | |
b4a98e57 | 10961 | mutex_lock(&dev->struct_mutex); |
3465c580 | 10962 | intel_unpin_fb_obj(work->old_fb, primary->state->rotation); |
05394f39 | 10963 | drm_gem_object_unreference(&work->pending_flip_obj->base); |
d9e86c0e | 10964 | |
f06cc1b9 | 10965 | if (work->flip_queued_req) |
146d84f0 | 10966 | i915_gem_request_assign(&work->flip_queued_req, NULL); |
b4a98e57 CW |
10967 | mutex_unlock(&dev->struct_mutex); |
10968 | ||
a9ff8714 | 10969 | intel_frontbuffer_flip_complete(dev, to_intel_plane(primary)->frontbuffer_bit); |
1eb52238 | 10970 | intel_fbc_post_update(crtc); |
89ed88ba | 10971 | drm_framebuffer_unreference(work->old_fb); |
f99d7069 | 10972 | |
a9ff8714 VS |
10973 | BUG_ON(atomic_read(&crtc->unpin_work_count) == 0); |
10974 | atomic_dec(&crtc->unpin_work_count); | |
b4a98e57 | 10975 | |
6b95a207 KH |
10976 | kfree(work); |
10977 | } | |
10978 | ||
1afe3e9d | 10979 | static void do_intel_finish_page_flip(struct drm_device *dev, |
49b14a5c | 10980 | struct drm_crtc *crtc) |
6b95a207 | 10981 | { |
6b95a207 KH |
10982 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
10983 | struct intel_unpin_work *work; | |
6b95a207 KH |
10984 | unsigned long flags; |
10985 | ||
10986 | /* Ignore early vblank irqs */ | |
10987 | if (intel_crtc == NULL) | |
10988 | return; | |
10989 | ||
f326038a DV |
10990 | /* |
10991 | * This is called both by irq handlers and the reset code (to complete | |
10992 | * lost pageflips) so needs the full irqsave spinlocks. | |
10993 | */ | |
6b95a207 KH |
10994 | spin_lock_irqsave(&dev->event_lock, flags); |
10995 | work = intel_crtc->unpin_work; | |
e7d841ca CW |
10996 | |
10997 | /* Ensure we don't miss a work->pending update ... */ | |
10998 | smp_rmb(); | |
10999 | ||
11000 | if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) { | |
6b95a207 KH |
11001 | spin_unlock_irqrestore(&dev->event_lock, flags); |
11002 | return; | |
11003 | } | |
11004 | ||
d6bbafa1 | 11005 | page_flip_completed(intel_crtc); |
0af7e4df | 11006 | |
6b95a207 | 11007 | spin_unlock_irqrestore(&dev->event_lock, flags); |
6b95a207 KH |
11008 | } |
11009 | ||
1afe3e9d JB |
11010 | void intel_finish_page_flip(struct drm_device *dev, int pipe) |
11011 | { | |
fbee40df | 11012 | struct drm_i915_private *dev_priv = dev->dev_private; |
1afe3e9d JB |
11013 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
11014 | ||
49b14a5c | 11015 | do_intel_finish_page_flip(dev, crtc); |
1afe3e9d JB |
11016 | } |
11017 | ||
11018 | void intel_finish_page_flip_plane(struct drm_device *dev, int plane) | |
11019 | { | |
fbee40df | 11020 | struct drm_i915_private *dev_priv = dev->dev_private; |
1afe3e9d JB |
11021 | struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane]; |
11022 | ||
49b14a5c | 11023 | do_intel_finish_page_flip(dev, crtc); |
1afe3e9d JB |
11024 | } |
11025 | ||
75f7f3ec VS |
11026 | /* Is 'a' after or equal to 'b'? */ |
11027 | static bool g4x_flip_count_after_eq(u32 a, u32 b) | |
11028 | { | |
11029 | return !((a - b) & 0x80000000); | |
11030 | } | |
11031 | ||
11032 | static bool page_flip_finished(struct intel_crtc *crtc) | |
11033 | { | |
11034 | struct drm_device *dev = crtc->base.dev; | |
11035 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11036 | ||
bdfa7542 VS |
11037 | if (i915_reset_in_progress(&dev_priv->gpu_error) || |
11038 | crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) | |
11039 | return true; | |
11040 | ||
75f7f3ec VS |
11041 | /* |
11042 | * The relevant registers doen't exist on pre-ctg. | |
11043 | * As the flip done interrupt doesn't trigger for mmio | |
11044 | * flips on gmch platforms, a flip count check isn't | |
11045 | * really needed there. But since ctg has the registers, | |
11046 | * include it in the check anyway. | |
11047 | */ | |
11048 | if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev)) | |
11049 | return true; | |
11050 | ||
e8861675 ML |
11051 | /* |
11052 | * BDW signals flip done immediately if the plane | |
11053 | * is disabled, even if the plane enable is already | |
11054 | * armed to occur at the next vblank :( | |
11055 | */ | |
11056 | ||
75f7f3ec VS |
11057 | /* |
11058 | * A DSPSURFLIVE check isn't enough in case the mmio and CS flips | |
11059 | * used the same base address. In that case the mmio flip might | |
11060 | * have completed, but the CS hasn't even executed the flip yet. | |
11061 | * | |
11062 | * A flip count check isn't enough as the CS might have updated | |
11063 | * the base address just after start of vblank, but before we | |
11064 | * managed to process the interrupt. This means we'd complete the | |
11065 | * CS flip too soon. | |
11066 | * | |
11067 | * Combining both checks should get us a good enough result. It may | |
11068 | * still happen that the CS flip has been executed, but has not | |
11069 | * yet actually completed. But in case the base address is the same | |
11070 | * anyway, we don't really care. | |
11071 | */ | |
11072 | return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) == | |
11073 | crtc->unpin_work->gtt_offset && | |
fd8f507c | 11074 | g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_G4X(crtc->pipe)), |
75f7f3ec VS |
11075 | crtc->unpin_work->flip_count); |
11076 | } | |
11077 | ||
6b95a207 KH |
11078 | void intel_prepare_page_flip(struct drm_device *dev, int plane) |
11079 | { | |
fbee40df | 11080 | struct drm_i915_private *dev_priv = dev->dev_private; |
6b95a207 KH |
11081 | struct intel_crtc *intel_crtc = |
11082 | to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]); | |
11083 | unsigned long flags; | |
11084 | ||
f326038a DV |
11085 | |
11086 | /* | |
11087 | * This is called both by irq handlers and the reset code (to complete | |
11088 | * lost pageflips) so needs the full irqsave spinlocks. | |
11089 | * | |
11090 | * NB: An MMIO update of the plane base pointer will also | |
e7d841ca CW |
11091 | * generate a page-flip completion irq, i.e. every modeset |
11092 | * is also accompanied by a spurious intel_prepare_page_flip(). | |
11093 | */ | |
6b95a207 | 11094 | spin_lock_irqsave(&dev->event_lock, flags); |
75f7f3ec | 11095 | if (intel_crtc->unpin_work && page_flip_finished(intel_crtc)) |
e7d841ca | 11096 | atomic_inc_not_zero(&intel_crtc->unpin_work->pending); |
6b95a207 KH |
11097 | spin_unlock_irqrestore(&dev->event_lock, flags); |
11098 | } | |
11099 | ||
6042639c | 11100 | static inline void intel_mark_page_flip_active(struct intel_unpin_work *work) |
e7d841ca CW |
11101 | { |
11102 | /* Ensure that the work item is consistent when activating it ... */ | |
11103 | smp_wmb(); | |
6042639c | 11104 | atomic_set(&work->pending, INTEL_FLIP_PENDING); |
e7d841ca CW |
11105 | /* and that it is marked active as soon as the irq could fire. */ |
11106 | smp_wmb(); | |
11107 | } | |
11108 | ||
8c9f3aaf JB |
11109 | static int intel_gen2_queue_flip(struct drm_device *dev, |
11110 | struct drm_crtc *crtc, | |
11111 | struct drm_framebuffer *fb, | |
ed8d1975 | 11112 | struct drm_i915_gem_object *obj, |
6258fbe2 | 11113 | struct drm_i915_gem_request *req, |
ed8d1975 | 11114 | uint32_t flags) |
8c9f3aaf | 11115 | { |
6258fbe2 | 11116 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf | 11117 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8c9f3aaf JB |
11118 | u32 flip_mask; |
11119 | int ret; | |
11120 | ||
5fb9de1a | 11121 | ret = intel_ring_begin(req, 6); |
8c9f3aaf | 11122 | if (ret) |
4fa62c89 | 11123 | return ret; |
8c9f3aaf JB |
11124 | |
11125 | /* Can't queue multiple flips, so wait for the previous | |
11126 | * one to finish before executing the next. | |
11127 | */ | |
11128 | if (intel_crtc->plane) | |
11129 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; | |
11130 | else | |
11131 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; | |
6d90c952 DV |
11132 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
11133 | intel_ring_emit(ring, MI_NOOP); | |
11134 | intel_ring_emit(ring, MI_DISPLAY_FLIP | | |
11135 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
11136 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 11137 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
6d90c952 | 11138 | intel_ring_emit(ring, 0); /* aux display base address, unused */ |
e7d841ca | 11139 | |
6042639c | 11140 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 11141 | return 0; |
8c9f3aaf JB |
11142 | } |
11143 | ||
11144 | static int intel_gen3_queue_flip(struct drm_device *dev, | |
11145 | struct drm_crtc *crtc, | |
11146 | struct drm_framebuffer *fb, | |
ed8d1975 | 11147 | struct drm_i915_gem_object *obj, |
6258fbe2 | 11148 | struct drm_i915_gem_request *req, |
ed8d1975 | 11149 | uint32_t flags) |
8c9f3aaf | 11150 | { |
6258fbe2 | 11151 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf | 11152 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8c9f3aaf JB |
11153 | u32 flip_mask; |
11154 | int ret; | |
11155 | ||
5fb9de1a | 11156 | ret = intel_ring_begin(req, 6); |
8c9f3aaf | 11157 | if (ret) |
4fa62c89 | 11158 | return ret; |
8c9f3aaf JB |
11159 | |
11160 | if (intel_crtc->plane) | |
11161 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; | |
11162 | else | |
11163 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; | |
6d90c952 DV |
11164 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
11165 | intel_ring_emit(ring, MI_NOOP); | |
11166 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | | |
11167 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
11168 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 11169 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
6d90c952 DV |
11170 | intel_ring_emit(ring, MI_NOOP); |
11171 | ||
6042639c | 11172 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 11173 | return 0; |
8c9f3aaf JB |
11174 | } |
11175 | ||
11176 | static int intel_gen4_queue_flip(struct drm_device *dev, | |
11177 | struct drm_crtc *crtc, | |
11178 | struct drm_framebuffer *fb, | |
ed8d1975 | 11179 | struct drm_i915_gem_object *obj, |
6258fbe2 | 11180 | struct drm_i915_gem_request *req, |
ed8d1975 | 11181 | uint32_t flags) |
8c9f3aaf | 11182 | { |
6258fbe2 | 11183 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf JB |
11184 | struct drm_i915_private *dev_priv = dev->dev_private; |
11185 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11186 | uint32_t pf, pipesrc; | |
11187 | int ret; | |
11188 | ||
5fb9de1a | 11189 | ret = intel_ring_begin(req, 4); |
8c9f3aaf | 11190 | if (ret) |
4fa62c89 | 11191 | return ret; |
8c9f3aaf JB |
11192 | |
11193 | /* i965+ uses the linear or tiled offsets from the | |
11194 | * Display Registers (which do not change across a page-flip) | |
11195 | * so we need only reprogram the base address. | |
11196 | */ | |
6d90c952 DV |
11197 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
11198 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
11199 | intel_ring_emit(ring, fb->pitches[0]); | |
75f7f3ec | 11200 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset | |
c2c75131 | 11201 | obj->tiling_mode); |
8c9f3aaf JB |
11202 | |
11203 | /* XXX Enabling the panel-fitter across page-flip is so far | |
11204 | * untested on non-native modes, so ignore it for now. | |
11205 | * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE; | |
11206 | */ | |
11207 | pf = 0; | |
11208 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; | |
6d90c952 | 11209 | intel_ring_emit(ring, pf | pipesrc); |
e7d841ca | 11210 | |
6042639c | 11211 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 11212 | return 0; |
8c9f3aaf JB |
11213 | } |
11214 | ||
11215 | static int intel_gen6_queue_flip(struct drm_device *dev, | |
11216 | struct drm_crtc *crtc, | |
11217 | struct drm_framebuffer *fb, | |
ed8d1975 | 11218 | struct drm_i915_gem_object *obj, |
6258fbe2 | 11219 | struct drm_i915_gem_request *req, |
ed8d1975 | 11220 | uint32_t flags) |
8c9f3aaf | 11221 | { |
6258fbe2 | 11222 | struct intel_engine_cs *ring = req->ring; |
8c9f3aaf JB |
11223 | struct drm_i915_private *dev_priv = dev->dev_private; |
11224 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11225 | uint32_t pf, pipesrc; | |
11226 | int ret; | |
11227 | ||
5fb9de1a | 11228 | ret = intel_ring_begin(req, 4); |
8c9f3aaf | 11229 | if (ret) |
4fa62c89 | 11230 | return ret; |
8c9f3aaf | 11231 | |
6d90c952 DV |
11232 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
11233 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
11234 | intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode); | |
75f7f3ec | 11235 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
8c9f3aaf | 11236 | |
dc257cf1 DV |
11237 | /* Contrary to the suggestions in the documentation, |
11238 | * "Enable Panel Fitter" does not seem to be required when page | |
11239 | * flipping with a non-native mode, and worse causes a normal | |
11240 | * modeset to fail. | |
11241 | * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE; | |
11242 | */ | |
11243 | pf = 0; | |
8c9f3aaf | 11244 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
6d90c952 | 11245 | intel_ring_emit(ring, pf | pipesrc); |
e7d841ca | 11246 | |
6042639c | 11247 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 11248 | return 0; |
8c9f3aaf JB |
11249 | } |
11250 | ||
7c9017e5 JB |
11251 | static int intel_gen7_queue_flip(struct drm_device *dev, |
11252 | struct drm_crtc *crtc, | |
11253 | struct drm_framebuffer *fb, | |
ed8d1975 | 11254 | struct drm_i915_gem_object *obj, |
6258fbe2 | 11255 | struct drm_i915_gem_request *req, |
ed8d1975 | 11256 | uint32_t flags) |
7c9017e5 | 11257 | { |
6258fbe2 | 11258 | struct intel_engine_cs *ring = req->ring; |
7c9017e5 | 11259 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
cb05d8de | 11260 | uint32_t plane_bit = 0; |
ffe74d75 CW |
11261 | int len, ret; |
11262 | ||
eba905b2 | 11263 | switch (intel_crtc->plane) { |
cb05d8de DV |
11264 | case PLANE_A: |
11265 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A; | |
11266 | break; | |
11267 | case PLANE_B: | |
11268 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B; | |
11269 | break; | |
11270 | case PLANE_C: | |
11271 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C; | |
11272 | break; | |
11273 | default: | |
11274 | WARN_ONCE(1, "unknown plane in flip command\n"); | |
4fa62c89 | 11275 | return -ENODEV; |
cb05d8de DV |
11276 | } |
11277 | ||
ffe74d75 | 11278 | len = 4; |
f476828a | 11279 | if (ring->id == RCS) { |
ffe74d75 | 11280 | len += 6; |
f476828a DL |
11281 | /* |
11282 | * On Gen 8, SRM is now taking an extra dword to accommodate | |
11283 | * 48bits addresses, and we need a NOOP for the batch size to | |
11284 | * stay even. | |
11285 | */ | |
11286 | if (IS_GEN8(dev)) | |
11287 | len += 2; | |
11288 | } | |
ffe74d75 | 11289 | |
f66fab8e VS |
11290 | /* |
11291 | * BSpec MI_DISPLAY_FLIP for IVB: | |
11292 | * "The full packet must be contained within the same cache line." | |
11293 | * | |
11294 | * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same | |
11295 | * cacheline, if we ever start emitting more commands before | |
11296 | * the MI_DISPLAY_FLIP we may need to first emit everything else, | |
11297 | * then do the cacheline alignment, and finally emit the | |
11298 | * MI_DISPLAY_FLIP. | |
11299 | */ | |
bba09b12 | 11300 | ret = intel_ring_cacheline_align(req); |
f66fab8e | 11301 | if (ret) |
4fa62c89 | 11302 | return ret; |
f66fab8e | 11303 | |
5fb9de1a | 11304 | ret = intel_ring_begin(req, len); |
7c9017e5 | 11305 | if (ret) |
4fa62c89 | 11306 | return ret; |
7c9017e5 | 11307 | |
ffe74d75 CW |
11308 | /* Unmask the flip-done completion message. Note that the bspec says that |
11309 | * we should do this for both the BCS and RCS, and that we must not unmask | |
11310 | * more than one flip event at any time (or ensure that one flip message | |
11311 | * can be sent by waiting for flip-done prior to queueing new flips). | |
11312 | * Experimentation says that BCS works despite DERRMR masking all | |
11313 | * flip-done completion events and that unmasking all planes at once | |
11314 | * for the RCS also doesn't appear to drop events. Setting the DERRMR | |
11315 | * to zero does lead to lockups within MI_DISPLAY_FLIP. | |
11316 | */ | |
11317 | if (ring->id == RCS) { | |
11318 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); | |
f92a9162 | 11319 | intel_ring_emit_reg(ring, DERRMR); |
ffe74d75 CW |
11320 | intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE | |
11321 | DERRMR_PIPEB_PRI_FLIP_DONE | | |
11322 | DERRMR_PIPEC_PRI_FLIP_DONE)); | |
f476828a | 11323 | if (IS_GEN8(dev)) |
f1afe24f | 11324 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8 | |
f476828a DL |
11325 | MI_SRM_LRM_GLOBAL_GTT); |
11326 | else | |
f1afe24f | 11327 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM | |
f476828a | 11328 | MI_SRM_LRM_GLOBAL_GTT); |
f92a9162 | 11329 | intel_ring_emit_reg(ring, DERRMR); |
ffe74d75 | 11330 | intel_ring_emit(ring, ring->scratch.gtt_offset + 256); |
f476828a DL |
11331 | if (IS_GEN8(dev)) { |
11332 | intel_ring_emit(ring, 0); | |
11333 | intel_ring_emit(ring, MI_NOOP); | |
11334 | } | |
ffe74d75 CW |
11335 | } |
11336 | ||
cb05d8de | 11337 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit); |
01f2c773 | 11338 | intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode)); |
75f7f3ec | 11339 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
7c9017e5 | 11340 | intel_ring_emit(ring, (MI_NOOP)); |
e7d841ca | 11341 | |
6042639c | 11342 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
83d4092b | 11343 | return 0; |
7c9017e5 JB |
11344 | } |
11345 | ||
84c33a64 SG |
11346 | static bool use_mmio_flip(struct intel_engine_cs *ring, |
11347 | struct drm_i915_gem_object *obj) | |
11348 | { | |
11349 | /* | |
11350 | * This is not being used for older platforms, because | |
11351 | * non-availability of flip done interrupt forces us to use | |
11352 | * CS flips. Older platforms derive flip done using some clever | |
11353 | * tricks involving the flip_pending status bits and vblank irqs. | |
11354 | * So using MMIO flips there would disrupt this mechanism. | |
11355 | */ | |
11356 | ||
8e09bf83 CW |
11357 | if (ring == NULL) |
11358 | return true; | |
11359 | ||
84c33a64 SG |
11360 | if (INTEL_INFO(ring->dev)->gen < 5) |
11361 | return false; | |
11362 | ||
11363 | if (i915.use_mmio_flip < 0) | |
11364 | return false; | |
11365 | else if (i915.use_mmio_flip > 0) | |
11366 | return true; | |
14bf993e OM |
11367 | else if (i915.enable_execlists) |
11368 | return true; | |
fd8e058a AG |
11369 | else if (obj->base.dma_buf && |
11370 | !reservation_object_test_signaled_rcu(obj->base.dma_buf->resv, | |
11371 | false)) | |
11372 | return true; | |
84c33a64 | 11373 | else |
b4716185 | 11374 | return ring != i915_gem_request_get_ring(obj->last_write_req); |
84c33a64 SG |
11375 | } |
11376 | ||
6042639c | 11377 | static void skl_do_mmio_flip(struct intel_crtc *intel_crtc, |
86efe24a | 11378 | unsigned int rotation, |
6042639c | 11379 | struct intel_unpin_work *work) |
ff944564 DL |
11380 | { |
11381 | struct drm_device *dev = intel_crtc->base.dev; | |
11382 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11383 | struct drm_framebuffer *fb = intel_crtc->base.primary->fb; | |
ff944564 | 11384 | const enum pipe pipe = intel_crtc->pipe; |
86efe24a | 11385 | u32 ctl, stride, tile_height; |
ff944564 DL |
11386 | |
11387 | ctl = I915_READ(PLANE_CTL(pipe, 0)); | |
11388 | ctl &= ~PLANE_CTL_TILED_MASK; | |
2ebef630 TU |
11389 | switch (fb->modifier[0]) { |
11390 | case DRM_FORMAT_MOD_NONE: | |
11391 | break; | |
11392 | case I915_FORMAT_MOD_X_TILED: | |
ff944564 | 11393 | ctl |= PLANE_CTL_TILED_X; |
2ebef630 TU |
11394 | break; |
11395 | case I915_FORMAT_MOD_Y_TILED: | |
11396 | ctl |= PLANE_CTL_TILED_Y; | |
11397 | break; | |
11398 | case I915_FORMAT_MOD_Yf_TILED: | |
11399 | ctl |= PLANE_CTL_TILED_YF; | |
11400 | break; | |
11401 | default: | |
11402 | MISSING_CASE(fb->modifier[0]); | |
11403 | } | |
ff944564 DL |
11404 | |
11405 | /* | |
11406 | * The stride is either expressed as a multiple of 64 bytes chunks for | |
11407 | * linear buffers or in number of tiles for tiled buffers. | |
11408 | */ | |
86efe24a TU |
11409 | if (intel_rotation_90_or_270(rotation)) { |
11410 | /* stride = Surface height in tiles */ | |
832be82f | 11411 | tile_height = intel_tile_height(dev_priv, fb->modifier[0], 0); |
86efe24a TU |
11412 | stride = DIV_ROUND_UP(fb->height, tile_height); |
11413 | } else { | |
11414 | stride = fb->pitches[0] / | |
7b49f948 VS |
11415 | intel_fb_stride_alignment(dev_priv, fb->modifier[0], |
11416 | fb->pixel_format); | |
86efe24a | 11417 | } |
ff944564 DL |
11418 | |
11419 | /* | |
11420 | * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on | |
11421 | * PLANE_SURF updates, the update is then guaranteed to be atomic. | |
11422 | */ | |
11423 | I915_WRITE(PLANE_CTL(pipe, 0), ctl); | |
11424 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); | |
11425 | ||
6042639c | 11426 | I915_WRITE(PLANE_SURF(pipe, 0), work->gtt_offset); |
ff944564 DL |
11427 | POSTING_READ(PLANE_SURF(pipe, 0)); |
11428 | } | |
11429 | ||
6042639c CW |
11430 | static void ilk_do_mmio_flip(struct intel_crtc *intel_crtc, |
11431 | struct intel_unpin_work *work) | |
84c33a64 SG |
11432 | { |
11433 | struct drm_device *dev = intel_crtc->base.dev; | |
11434 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11435 | struct intel_framebuffer *intel_fb = | |
11436 | to_intel_framebuffer(intel_crtc->base.primary->fb); | |
11437 | struct drm_i915_gem_object *obj = intel_fb->obj; | |
f0f59a00 | 11438 | i915_reg_t reg = DSPCNTR(intel_crtc->plane); |
84c33a64 | 11439 | u32 dspcntr; |
84c33a64 | 11440 | |
84c33a64 SG |
11441 | dspcntr = I915_READ(reg); |
11442 | ||
c5d97472 DL |
11443 | if (obj->tiling_mode != I915_TILING_NONE) |
11444 | dspcntr |= DISPPLANE_TILED; | |
11445 | else | |
11446 | dspcntr &= ~DISPPLANE_TILED; | |
11447 | ||
84c33a64 SG |
11448 | I915_WRITE(reg, dspcntr); |
11449 | ||
6042639c | 11450 | I915_WRITE(DSPSURF(intel_crtc->plane), work->gtt_offset); |
84c33a64 | 11451 | POSTING_READ(DSPSURF(intel_crtc->plane)); |
ff944564 DL |
11452 | } |
11453 | ||
11454 | /* | |
11455 | * XXX: This is the temporary way to update the plane registers until we get | |
11456 | * around to using the usual plane update functions for MMIO flips | |
11457 | */ | |
6042639c | 11458 | static void intel_do_mmio_flip(struct intel_mmio_flip *mmio_flip) |
ff944564 | 11459 | { |
6042639c CW |
11460 | struct intel_crtc *crtc = mmio_flip->crtc; |
11461 | struct intel_unpin_work *work; | |
11462 | ||
11463 | spin_lock_irq(&crtc->base.dev->event_lock); | |
11464 | work = crtc->unpin_work; | |
11465 | spin_unlock_irq(&crtc->base.dev->event_lock); | |
11466 | if (work == NULL) | |
11467 | return; | |
ff944564 | 11468 | |
6042639c | 11469 | intel_mark_page_flip_active(work); |
ff944564 | 11470 | |
6042639c | 11471 | intel_pipe_update_start(crtc); |
ff944564 | 11472 | |
6042639c | 11473 | if (INTEL_INFO(mmio_flip->i915)->gen >= 9) |
86efe24a | 11474 | skl_do_mmio_flip(crtc, mmio_flip->rotation, work); |
ff944564 DL |
11475 | else |
11476 | /* use_mmio_flip() retricts MMIO flips to ilk+ */ | |
6042639c | 11477 | ilk_do_mmio_flip(crtc, work); |
ff944564 | 11478 | |
6042639c | 11479 | intel_pipe_update_end(crtc); |
84c33a64 SG |
11480 | } |
11481 | ||
9362c7c5 | 11482 | static void intel_mmio_flip_work_func(struct work_struct *work) |
84c33a64 | 11483 | { |
b2cfe0ab CW |
11484 | struct intel_mmio_flip *mmio_flip = |
11485 | container_of(work, struct intel_mmio_flip, work); | |
fd8e058a AG |
11486 | struct intel_framebuffer *intel_fb = |
11487 | to_intel_framebuffer(mmio_flip->crtc->base.primary->fb); | |
11488 | struct drm_i915_gem_object *obj = intel_fb->obj; | |
84c33a64 | 11489 | |
6042639c | 11490 | if (mmio_flip->req) { |
eed29a5b | 11491 | WARN_ON(__i915_wait_request(mmio_flip->req, |
b2cfe0ab | 11492 | mmio_flip->crtc->reset_counter, |
bcafc4e3 CW |
11493 | false, NULL, |
11494 | &mmio_flip->i915->rps.mmioflips)); | |
6042639c CW |
11495 | i915_gem_request_unreference__unlocked(mmio_flip->req); |
11496 | } | |
84c33a64 | 11497 | |
fd8e058a AG |
11498 | /* For framebuffer backed by dmabuf, wait for fence */ |
11499 | if (obj->base.dma_buf) | |
11500 | WARN_ON(reservation_object_wait_timeout_rcu(obj->base.dma_buf->resv, | |
11501 | false, false, | |
11502 | MAX_SCHEDULE_TIMEOUT) < 0); | |
11503 | ||
6042639c | 11504 | intel_do_mmio_flip(mmio_flip); |
b2cfe0ab | 11505 | kfree(mmio_flip); |
84c33a64 SG |
11506 | } |
11507 | ||
11508 | static int intel_queue_mmio_flip(struct drm_device *dev, | |
11509 | struct drm_crtc *crtc, | |
86efe24a | 11510 | struct drm_i915_gem_object *obj) |
84c33a64 | 11511 | { |
b2cfe0ab CW |
11512 | struct intel_mmio_flip *mmio_flip; |
11513 | ||
11514 | mmio_flip = kmalloc(sizeof(*mmio_flip), GFP_KERNEL); | |
11515 | if (mmio_flip == NULL) | |
11516 | return -ENOMEM; | |
84c33a64 | 11517 | |
bcafc4e3 | 11518 | mmio_flip->i915 = to_i915(dev); |
eed29a5b | 11519 | mmio_flip->req = i915_gem_request_reference(obj->last_write_req); |
b2cfe0ab | 11520 | mmio_flip->crtc = to_intel_crtc(crtc); |
86efe24a | 11521 | mmio_flip->rotation = crtc->primary->state->rotation; |
536f5b5e | 11522 | |
b2cfe0ab CW |
11523 | INIT_WORK(&mmio_flip->work, intel_mmio_flip_work_func); |
11524 | schedule_work(&mmio_flip->work); | |
84c33a64 | 11525 | |
84c33a64 SG |
11526 | return 0; |
11527 | } | |
11528 | ||
8c9f3aaf JB |
11529 | static int intel_default_queue_flip(struct drm_device *dev, |
11530 | struct drm_crtc *crtc, | |
11531 | struct drm_framebuffer *fb, | |
ed8d1975 | 11532 | struct drm_i915_gem_object *obj, |
6258fbe2 | 11533 | struct drm_i915_gem_request *req, |
ed8d1975 | 11534 | uint32_t flags) |
8c9f3aaf JB |
11535 | { |
11536 | return -ENODEV; | |
11537 | } | |
11538 | ||
d6bbafa1 CW |
11539 | static bool __intel_pageflip_stall_check(struct drm_device *dev, |
11540 | struct drm_crtc *crtc) | |
11541 | { | |
11542 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11543 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11544 | struct intel_unpin_work *work = intel_crtc->unpin_work; | |
11545 | u32 addr; | |
11546 | ||
11547 | if (atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE) | |
11548 | return true; | |
11549 | ||
908565c2 CW |
11550 | if (atomic_read(&work->pending) < INTEL_FLIP_PENDING) |
11551 | return false; | |
11552 | ||
d6bbafa1 CW |
11553 | if (!work->enable_stall_check) |
11554 | return false; | |
11555 | ||
11556 | if (work->flip_ready_vblank == 0) { | |
3a8a946e DV |
11557 | if (work->flip_queued_req && |
11558 | !i915_gem_request_completed(work->flip_queued_req, true)) | |
d6bbafa1 CW |
11559 | return false; |
11560 | ||
1e3feefd | 11561 | work->flip_ready_vblank = drm_crtc_vblank_count(crtc); |
d6bbafa1 CW |
11562 | } |
11563 | ||
1e3feefd | 11564 | if (drm_crtc_vblank_count(crtc) - work->flip_ready_vblank < 3) |
d6bbafa1 CW |
11565 | return false; |
11566 | ||
11567 | /* Potential stall - if we see that the flip has happened, | |
11568 | * assume a missed interrupt. */ | |
11569 | if (INTEL_INFO(dev)->gen >= 4) | |
11570 | addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane))); | |
11571 | else | |
11572 | addr = I915_READ(DSPADDR(intel_crtc->plane)); | |
11573 | ||
11574 | /* There is a potential issue here with a false positive after a flip | |
11575 | * to the same address. We could address this by checking for a | |
11576 | * non-incrementing frame counter. | |
11577 | */ | |
11578 | return addr == work->gtt_offset; | |
11579 | } | |
11580 | ||
11581 | void intel_check_page_flip(struct drm_device *dev, int pipe) | |
11582 | { | |
11583 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11584 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
11585 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6ad790c0 | 11586 | struct intel_unpin_work *work; |
f326038a | 11587 | |
6c51d46f | 11588 | WARN_ON(!in_interrupt()); |
d6bbafa1 CW |
11589 | |
11590 | if (crtc == NULL) | |
11591 | return; | |
11592 | ||
f326038a | 11593 | spin_lock(&dev->event_lock); |
6ad790c0 CW |
11594 | work = intel_crtc->unpin_work; |
11595 | if (work != NULL && __intel_pageflip_stall_check(dev, crtc)) { | |
d6bbafa1 | 11596 | WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n", |
6ad790c0 | 11597 | work->flip_queued_vblank, drm_vblank_count(dev, pipe)); |
d6bbafa1 | 11598 | page_flip_completed(intel_crtc); |
6ad790c0 | 11599 | work = NULL; |
d6bbafa1 | 11600 | } |
6ad790c0 CW |
11601 | if (work != NULL && |
11602 | drm_vblank_count(dev, pipe) - work->flip_queued_vblank > 1) | |
11603 | intel_queue_rps_boost_for_request(dev, work->flip_queued_req); | |
f326038a | 11604 | spin_unlock(&dev->event_lock); |
d6bbafa1 CW |
11605 | } |
11606 | ||
6b95a207 KH |
11607 | static int intel_crtc_page_flip(struct drm_crtc *crtc, |
11608 | struct drm_framebuffer *fb, | |
ed8d1975 KP |
11609 | struct drm_pending_vblank_event *event, |
11610 | uint32_t page_flip_flags) | |
6b95a207 KH |
11611 | { |
11612 | struct drm_device *dev = crtc->dev; | |
11613 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f4510a27 | 11614 | struct drm_framebuffer *old_fb = crtc->primary->fb; |
2ff8fde1 | 11615 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
6b95a207 | 11616 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
455a6808 | 11617 | struct drm_plane *primary = crtc->primary; |
a071fa00 | 11618 | enum pipe pipe = intel_crtc->pipe; |
6b95a207 | 11619 | struct intel_unpin_work *work; |
a4872ba6 | 11620 | struct intel_engine_cs *ring; |
cf5d8a46 | 11621 | bool mmio_flip; |
91af127f | 11622 | struct drm_i915_gem_request *request = NULL; |
52e68630 | 11623 | int ret; |
6b95a207 | 11624 | |
2ff8fde1 MR |
11625 | /* |
11626 | * drm_mode_page_flip_ioctl() should already catch this, but double | |
11627 | * check to be safe. In the future we may enable pageflipping from | |
11628 | * a disabled primary plane. | |
11629 | */ | |
11630 | if (WARN_ON(intel_fb_obj(old_fb) == NULL)) | |
11631 | return -EBUSY; | |
11632 | ||
e6a595d2 | 11633 | /* Can't change pixel format via MI display flips. */ |
f4510a27 | 11634 | if (fb->pixel_format != crtc->primary->fb->pixel_format) |
e6a595d2 VS |
11635 | return -EINVAL; |
11636 | ||
11637 | /* | |
11638 | * TILEOFF/LINOFF registers can't be changed via MI display flips. | |
11639 | * Note that pitch changes could also affect these register. | |
11640 | */ | |
11641 | if (INTEL_INFO(dev)->gen > 3 && | |
f4510a27 MR |
11642 | (fb->offsets[0] != crtc->primary->fb->offsets[0] || |
11643 | fb->pitches[0] != crtc->primary->fb->pitches[0])) | |
e6a595d2 VS |
11644 | return -EINVAL; |
11645 | ||
f900db47 CW |
11646 | if (i915_terminally_wedged(&dev_priv->gpu_error)) |
11647 | goto out_hang; | |
11648 | ||
b14c5679 | 11649 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
6b95a207 KH |
11650 | if (work == NULL) |
11651 | return -ENOMEM; | |
11652 | ||
6b95a207 | 11653 | work->event = event; |
b4a98e57 | 11654 | work->crtc = crtc; |
ab8d6675 | 11655 | work->old_fb = old_fb; |
6b95a207 KH |
11656 | INIT_WORK(&work->work, intel_unpin_work_fn); |
11657 | ||
87b6b101 | 11658 | ret = drm_crtc_vblank_get(crtc); |
7317c75e JB |
11659 | if (ret) |
11660 | goto free_work; | |
11661 | ||
6b95a207 | 11662 | /* We borrow the event spin lock for protecting unpin_work */ |
5e2d7afc | 11663 | spin_lock_irq(&dev->event_lock); |
6b95a207 | 11664 | if (intel_crtc->unpin_work) { |
d6bbafa1 CW |
11665 | /* Before declaring the flip queue wedged, check if |
11666 | * the hardware completed the operation behind our backs. | |
11667 | */ | |
11668 | if (__intel_pageflip_stall_check(dev, crtc)) { | |
11669 | DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n"); | |
11670 | page_flip_completed(intel_crtc); | |
11671 | } else { | |
11672 | DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); | |
5e2d7afc | 11673 | spin_unlock_irq(&dev->event_lock); |
468f0b44 | 11674 | |
d6bbafa1 CW |
11675 | drm_crtc_vblank_put(crtc); |
11676 | kfree(work); | |
11677 | return -EBUSY; | |
11678 | } | |
6b95a207 KH |
11679 | } |
11680 | intel_crtc->unpin_work = work; | |
5e2d7afc | 11681 | spin_unlock_irq(&dev->event_lock); |
6b95a207 | 11682 | |
b4a98e57 CW |
11683 | if (atomic_read(&intel_crtc->unpin_work_count) >= 2) |
11684 | flush_workqueue(dev_priv->wq); | |
11685 | ||
75dfca80 | 11686 | /* Reference the objects for the scheduled work. */ |
ab8d6675 | 11687 | drm_framebuffer_reference(work->old_fb); |
05394f39 | 11688 | drm_gem_object_reference(&obj->base); |
6b95a207 | 11689 | |
f4510a27 | 11690 | crtc->primary->fb = fb; |
afd65eb4 | 11691 | update_state_fb(crtc->primary); |
e8216e50 | 11692 | intel_fbc_pre_update(intel_crtc); |
1ed1f968 | 11693 | |
e1f99ce6 | 11694 | work->pending_flip_obj = obj; |
e1f99ce6 | 11695 | |
89ed88ba CW |
11696 | ret = i915_mutex_lock_interruptible(dev); |
11697 | if (ret) | |
11698 | goto cleanup; | |
11699 | ||
b4a98e57 | 11700 | atomic_inc(&intel_crtc->unpin_work_count); |
10d83730 | 11701 | intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); |
e1f99ce6 | 11702 | |
75f7f3ec | 11703 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
fd8f507c | 11704 | work->flip_count = I915_READ(PIPE_FLIPCOUNT_G4X(pipe)) + 1; |
75f7f3ec | 11705 | |
666a4537 | 11706 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
4fa62c89 | 11707 | ring = &dev_priv->ring[BCS]; |
ab8d6675 | 11708 | if (obj->tiling_mode != intel_fb_obj(work->old_fb)->tiling_mode) |
8e09bf83 CW |
11709 | /* vlv: DISPLAY_FLIP fails to change tiling */ |
11710 | ring = NULL; | |
48bf5b2d | 11711 | } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) { |
2a92d5bc | 11712 | ring = &dev_priv->ring[BCS]; |
4fa62c89 | 11713 | } else if (INTEL_INFO(dev)->gen >= 7) { |
b4716185 | 11714 | ring = i915_gem_request_get_ring(obj->last_write_req); |
4fa62c89 VS |
11715 | if (ring == NULL || ring->id != RCS) |
11716 | ring = &dev_priv->ring[BCS]; | |
11717 | } else { | |
11718 | ring = &dev_priv->ring[RCS]; | |
11719 | } | |
11720 | ||
cf5d8a46 CW |
11721 | mmio_flip = use_mmio_flip(ring, obj); |
11722 | ||
11723 | /* When using CS flips, we want to emit semaphores between rings. | |
11724 | * However, when using mmio flips we will create a task to do the | |
11725 | * synchronisation, so all we want here is to pin the framebuffer | |
11726 | * into the display plane and skip any waits. | |
11727 | */ | |
7580d774 ML |
11728 | if (!mmio_flip) { |
11729 | ret = i915_gem_object_sync(obj, ring, &request); | |
11730 | if (ret) | |
11731 | goto cleanup_pending; | |
11732 | } | |
11733 | ||
3465c580 | 11734 | ret = intel_pin_and_fence_fb_obj(fb, primary->state->rotation); |
8c9f3aaf JB |
11735 | if (ret) |
11736 | goto cleanup_pending; | |
6b95a207 | 11737 | |
dedf278c TU |
11738 | work->gtt_offset = intel_plane_obj_offset(to_intel_plane(primary), |
11739 | obj, 0); | |
11740 | work->gtt_offset += intel_crtc->dspaddr_offset; | |
4fa62c89 | 11741 | |
cf5d8a46 | 11742 | if (mmio_flip) { |
86efe24a | 11743 | ret = intel_queue_mmio_flip(dev, crtc, obj); |
d6bbafa1 CW |
11744 | if (ret) |
11745 | goto cleanup_unpin; | |
11746 | ||
f06cc1b9 JH |
11747 | i915_gem_request_assign(&work->flip_queued_req, |
11748 | obj->last_write_req); | |
d6bbafa1 | 11749 | } else { |
6258fbe2 | 11750 | if (!request) { |
26827088 DG |
11751 | request = i915_gem_request_alloc(ring, NULL); |
11752 | if (IS_ERR(request)) { | |
11753 | ret = PTR_ERR(request); | |
6258fbe2 | 11754 | goto cleanup_unpin; |
26827088 | 11755 | } |
6258fbe2 JH |
11756 | } |
11757 | ||
11758 | ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, request, | |
d6bbafa1 CW |
11759 | page_flip_flags); |
11760 | if (ret) | |
11761 | goto cleanup_unpin; | |
11762 | ||
6258fbe2 | 11763 | i915_gem_request_assign(&work->flip_queued_req, request); |
d6bbafa1 CW |
11764 | } |
11765 | ||
91af127f | 11766 | if (request) |
75289874 | 11767 | i915_add_request_no_flush(request); |
91af127f | 11768 | |
1e3feefd | 11769 | work->flip_queued_vblank = drm_crtc_vblank_count(crtc); |
d6bbafa1 | 11770 | work->enable_stall_check = true; |
4fa62c89 | 11771 | |
ab8d6675 | 11772 | i915_gem_track_fb(intel_fb_obj(work->old_fb), obj, |
a9ff8714 | 11773 | to_intel_plane(primary)->frontbuffer_bit); |
c80ac854 | 11774 | mutex_unlock(&dev->struct_mutex); |
a071fa00 | 11775 | |
a9ff8714 VS |
11776 | intel_frontbuffer_flip_prepare(dev, |
11777 | to_intel_plane(primary)->frontbuffer_bit); | |
6b95a207 | 11778 | |
e5510fac JB |
11779 | trace_i915_flip_request(intel_crtc->plane, obj); |
11780 | ||
6b95a207 | 11781 | return 0; |
96b099fd | 11782 | |
4fa62c89 | 11783 | cleanup_unpin: |
3465c580 | 11784 | intel_unpin_fb_obj(fb, crtc->primary->state->rotation); |
8c9f3aaf | 11785 | cleanup_pending: |
0aa498d5 | 11786 | if (!IS_ERR_OR_NULL(request)) |
91af127f | 11787 | i915_gem_request_cancel(request); |
b4a98e57 | 11788 | atomic_dec(&intel_crtc->unpin_work_count); |
89ed88ba CW |
11789 | mutex_unlock(&dev->struct_mutex); |
11790 | cleanup: | |
f4510a27 | 11791 | crtc->primary->fb = old_fb; |
afd65eb4 | 11792 | update_state_fb(crtc->primary); |
89ed88ba CW |
11793 | |
11794 | drm_gem_object_unreference_unlocked(&obj->base); | |
ab8d6675 | 11795 | drm_framebuffer_unreference(work->old_fb); |
96b099fd | 11796 | |
5e2d7afc | 11797 | spin_lock_irq(&dev->event_lock); |
96b099fd | 11798 | intel_crtc->unpin_work = NULL; |
5e2d7afc | 11799 | spin_unlock_irq(&dev->event_lock); |
96b099fd | 11800 | |
87b6b101 | 11801 | drm_crtc_vblank_put(crtc); |
7317c75e | 11802 | free_work: |
96b099fd CW |
11803 | kfree(work); |
11804 | ||
f900db47 | 11805 | if (ret == -EIO) { |
02e0efb5 ML |
11806 | struct drm_atomic_state *state; |
11807 | struct drm_plane_state *plane_state; | |
11808 | ||
f900db47 | 11809 | out_hang: |
02e0efb5 ML |
11810 | state = drm_atomic_state_alloc(dev); |
11811 | if (!state) | |
11812 | return -ENOMEM; | |
11813 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); | |
11814 | ||
11815 | retry: | |
11816 | plane_state = drm_atomic_get_plane_state(state, primary); | |
11817 | ret = PTR_ERR_OR_ZERO(plane_state); | |
11818 | if (!ret) { | |
11819 | drm_atomic_set_fb_for_plane(plane_state, fb); | |
11820 | ||
11821 | ret = drm_atomic_set_crtc_for_plane(plane_state, crtc); | |
11822 | if (!ret) | |
11823 | ret = drm_atomic_commit(state); | |
11824 | } | |
11825 | ||
11826 | if (ret == -EDEADLK) { | |
11827 | drm_modeset_backoff(state->acquire_ctx); | |
11828 | drm_atomic_state_clear(state); | |
11829 | goto retry; | |
11830 | } | |
11831 | ||
11832 | if (ret) | |
11833 | drm_atomic_state_free(state); | |
11834 | ||
f0d3dad3 | 11835 | if (ret == 0 && event) { |
5e2d7afc | 11836 | spin_lock_irq(&dev->event_lock); |
a071fa00 | 11837 | drm_send_vblank_event(dev, pipe, event); |
5e2d7afc | 11838 | spin_unlock_irq(&dev->event_lock); |
f0d3dad3 | 11839 | } |
f900db47 | 11840 | } |
96b099fd | 11841 | return ret; |
6b95a207 KH |
11842 | } |
11843 | ||
da20eabd ML |
11844 | |
11845 | /** | |
11846 | * intel_wm_need_update - Check whether watermarks need updating | |
11847 | * @plane: drm plane | |
11848 | * @state: new plane state | |
11849 | * | |
11850 | * Check current plane state versus the new one to determine whether | |
11851 | * watermarks need to be recalculated. | |
11852 | * | |
11853 | * Returns true or false. | |
11854 | */ | |
11855 | static bool intel_wm_need_update(struct drm_plane *plane, | |
11856 | struct drm_plane_state *state) | |
11857 | { | |
d21fbe87 MR |
11858 | struct intel_plane_state *new = to_intel_plane_state(state); |
11859 | struct intel_plane_state *cur = to_intel_plane_state(plane->state); | |
11860 | ||
11861 | /* Update watermarks on tiling or size changes. */ | |
92826fcd ML |
11862 | if (new->visible != cur->visible) |
11863 | return true; | |
11864 | ||
11865 | if (!cur->base.fb || !new->base.fb) | |
11866 | return false; | |
11867 | ||
11868 | if (cur->base.fb->modifier[0] != new->base.fb->modifier[0] || | |
11869 | cur->base.rotation != new->base.rotation || | |
d21fbe87 MR |
11870 | drm_rect_width(&new->src) != drm_rect_width(&cur->src) || |
11871 | drm_rect_height(&new->src) != drm_rect_height(&cur->src) || | |
11872 | drm_rect_width(&new->dst) != drm_rect_width(&cur->dst) || | |
11873 | drm_rect_height(&new->dst) != drm_rect_height(&cur->dst)) | |
2791a16c | 11874 | return true; |
7809e5ae | 11875 | |
2791a16c | 11876 | return false; |
7809e5ae MR |
11877 | } |
11878 | ||
d21fbe87 MR |
11879 | static bool needs_scaling(struct intel_plane_state *state) |
11880 | { | |
11881 | int src_w = drm_rect_width(&state->src) >> 16; | |
11882 | int src_h = drm_rect_height(&state->src) >> 16; | |
11883 | int dst_w = drm_rect_width(&state->dst); | |
11884 | int dst_h = drm_rect_height(&state->dst); | |
11885 | ||
11886 | return (src_w != dst_w || src_h != dst_h); | |
11887 | } | |
11888 | ||
da20eabd ML |
11889 | int intel_plane_atomic_calc_changes(struct drm_crtc_state *crtc_state, |
11890 | struct drm_plane_state *plane_state) | |
11891 | { | |
ab1d3a0e | 11892 | struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state); |
da20eabd ML |
11893 | struct drm_crtc *crtc = crtc_state->crtc; |
11894 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11895 | struct drm_plane *plane = plane_state->plane; | |
11896 | struct drm_device *dev = crtc->dev; | |
ed4a6a7c | 11897 | struct drm_i915_private *dev_priv = to_i915(dev); |
da20eabd ML |
11898 | struct intel_plane_state *old_plane_state = |
11899 | to_intel_plane_state(plane->state); | |
11900 | int idx = intel_crtc->base.base.id, ret; | |
da20eabd ML |
11901 | bool mode_changed = needs_modeset(crtc_state); |
11902 | bool was_crtc_enabled = crtc->state->active; | |
11903 | bool is_crtc_enabled = crtc_state->active; | |
da20eabd ML |
11904 | bool turn_off, turn_on, visible, was_visible; |
11905 | struct drm_framebuffer *fb = plane_state->fb; | |
11906 | ||
11907 | if (crtc_state && INTEL_INFO(dev)->gen >= 9 && | |
11908 | plane->type != DRM_PLANE_TYPE_CURSOR) { | |
11909 | ret = skl_update_scaler_plane( | |
11910 | to_intel_crtc_state(crtc_state), | |
11911 | to_intel_plane_state(plane_state)); | |
11912 | if (ret) | |
11913 | return ret; | |
11914 | } | |
11915 | ||
da20eabd ML |
11916 | was_visible = old_plane_state->visible; |
11917 | visible = to_intel_plane_state(plane_state)->visible; | |
11918 | ||
11919 | if (!was_crtc_enabled && WARN_ON(was_visible)) | |
11920 | was_visible = false; | |
11921 | ||
35c08f43 ML |
11922 | /* |
11923 | * Visibility is calculated as if the crtc was on, but | |
11924 | * after scaler setup everything depends on it being off | |
11925 | * when the crtc isn't active. | |
11926 | */ | |
11927 | if (!is_crtc_enabled) | |
11928 | to_intel_plane_state(plane_state)->visible = visible = false; | |
da20eabd ML |
11929 | |
11930 | if (!was_visible && !visible) | |
11931 | return 0; | |
11932 | ||
e8861675 ML |
11933 | if (fb != old_plane_state->base.fb) |
11934 | pipe_config->fb_changed = true; | |
11935 | ||
da20eabd ML |
11936 | turn_off = was_visible && (!visible || mode_changed); |
11937 | turn_on = visible && (!was_visible || mode_changed); | |
11938 | ||
11939 | DRM_DEBUG_ATOMIC("[CRTC:%i] has [PLANE:%i] with fb %i\n", idx, | |
11940 | plane->base.id, fb ? fb->base.id : -1); | |
11941 | ||
11942 | DRM_DEBUG_ATOMIC("[PLANE:%i] visible %i -> %i, off %i, on %i, ms %i\n", | |
11943 | plane->base.id, was_visible, visible, | |
11944 | turn_off, turn_on, mode_changed); | |
11945 | ||
92826fcd ML |
11946 | if (turn_on || turn_off) { |
11947 | pipe_config->wm_changed = true; | |
11948 | ||
852eb00d | 11949 | /* must disable cxsr around plane enable/disable */ |
e8861675 | 11950 | if (plane->type != DRM_PLANE_TYPE_CURSOR) |
ab1d3a0e | 11951 | pipe_config->disable_cxsr = true; |
852eb00d | 11952 | } else if (intel_wm_need_update(plane, plane_state)) { |
92826fcd | 11953 | pipe_config->wm_changed = true; |
852eb00d | 11954 | } |
da20eabd | 11955 | |
ed4a6a7c MR |
11956 | /* Pre-gen9 platforms need two-step watermark updates */ |
11957 | if (pipe_config->wm_changed && INTEL_INFO(dev)->gen < 9 && | |
11958 | dev_priv->display.optimize_watermarks) | |
11959 | to_intel_crtc_state(crtc_state)->wm.need_postvbl_update = true; | |
11960 | ||
8be6ca85 | 11961 | if (visible || was_visible) |
a9ff8714 VS |
11962 | intel_crtc->atomic.fb_bits |= |
11963 | to_intel_plane(plane)->frontbuffer_bit; | |
11964 | ||
da20eabd ML |
11965 | switch (plane->type) { |
11966 | case DRM_PLANE_TYPE_PRIMARY: | |
da20eabd | 11967 | intel_crtc->atomic.post_enable_primary = turn_on; |
fcf38d13 | 11968 | intel_crtc->atomic.update_fbc = true; |
da20eabd | 11969 | |
da20eabd ML |
11970 | break; |
11971 | case DRM_PLANE_TYPE_CURSOR: | |
da20eabd ML |
11972 | break; |
11973 | case DRM_PLANE_TYPE_OVERLAY: | |
d21fbe87 MR |
11974 | /* |
11975 | * WaCxSRDisabledForSpriteScaling:ivb | |
11976 | * | |
11977 | * cstate->update_wm was already set above, so this flag will | |
11978 | * take effect when we commit and program watermarks. | |
11979 | */ | |
11980 | if (IS_IVYBRIDGE(dev) && | |
11981 | needs_scaling(to_intel_plane_state(plane_state)) && | |
e8861675 ML |
11982 | !needs_scaling(old_plane_state)) |
11983 | pipe_config->disable_lp_wm = true; | |
d21fbe87 MR |
11984 | |
11985 | break; | |
da20eabd ML |
11986 | } |
11987 | return 0; | |
11988 | } | |
11989 | ||
6d3a1ce7 ML |
11990 | static bool encoders_cloneable(const struct intel_encoder *a, |
11991 | const struct intel_encoder *b) | |
11992 | { | |
11993 | /* masks could be asymmetric, so check both ways */ | |
11994 | return a == b || (a->cloneable & (1 << b->type) && | |
11995 | b->cloneable & (1 << a->type)); | |
11996 | } | |
11997 | ||
11998 | static bool check_single_encoder_cloning(struct drm_atomic_state *state, | |
11999 | struct intel_crtc *crtc, | |
12000 | struct intel_encoder *encoder) | |
12001 | { | |
12002 | struct intel_encoder *source_encoder; | |
12003 | struct drm_connector *connector; | |
12004 | struct drm_connector_state *connector_state; | |
12005 | int i; | |
12006 | ||
12007 | for_each_connector_in_state(state, connector, connector_state, i) { | |
12008 | if (connector_state->crtc != &crtc->base) | |
12009 | continue; | |
12010 | ||
12011 | source_encoder = | |
12012 | to_intel_encoder(connector_state->best_encoder); | |
12013 | if (!encoders_cloneable(encoder, source_encoder)) | |
12014 | return false; | |
12015 | } | |
12016 | ||
12017 | return true; | |
12018 | } | |
12019 | ||
12020 | static bool check_encoder_cloning(struct drm_atomic_state *state, | |
12021 | struct intel_crtc *crtc) | |
12022 | { | |
12023 | struct intel_encoder *encoder; | |
12024 | struct drm_connector *connector; | |
12025 | struct drm_connector_state *connector_state; | |
12026 | int i; | |
12027 | ||
12028 | for_each_connector_in_state(state, connector, connector_state, i) { | |
12029 | if (connector_state->crtc != &crtc->base) | |
12030 | continue; | |
12031 | ||
12032 | encoder = to_intel_encoder(connector_state->best_encoder); | |
12033 | if (!check_single_encoder_cloning(state, crtc, encoder)) | |
12034 | return false; | |
12035 | } | |
12036 | ||
12037 | return true; | |
12038 | } | |
12039 | ||
12040 | static int intel_crtc_atomic_check(struct drm_crtc *crtc, | |
12041 | struct drm_crtc_state *crtc_state) | |
12042 | { | |
cf5a15be | 12043 | struct drm_device *dev = crtc->dev; |
ad421372 | 12044 | struct drm_i915_private *dev_priv = dev->dev_private; |
6d3a1ce7 | 12045 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
cf5a15be ML |
12046 | struct intel_crtc_state *pipe_config = |
12047 | to_intel_crtc_state(crtc_state); | |
6d3a1ce7 | 12048 | struct drm_atomic_state *state = crtc_state->state; |
4d20cd86 | 12049 | int ret; |
6d3a1ce7 ML |
12050 | bool mode_changed = needs_modeset(crtc_state); |
12051 | ||
12052 | if (mode_changed && !check_encoder_cloning(state, intel_crtc)) { | |
12053 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); | |
12054 | return -EINVAL; | |
12055 | } | |
12056 | ||
852eb00d | 12057 | if (mode_changed && !crtc_state->active) |
92826fcd | 12058 | pipe_config->wm_changed = true; |
eddfcbcd | 12059 | |
ad421372 ML |
12060 | if (mode_changed && crtc_state->enable && |
12061 | dev_priv->display.crtc_compute_clock && | |
12062 | !WARN_ON(pipe_config->shared_dpll != DPLL_ID_PRIVATE)) { | |
12063 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, | |
12064 | pipe_config); | |
12065 | if (ret) | |
12066 | return ret; | |
12067 | } | |
12068 | ||
e435d6e5 | 12069 | ret = 0; |
86c8bbbe MR |
12070 | if (dev_priv->display.compute_pipe_wm) { |
12071 | ret = dev_priv->display.compute_pipe_wm(intel_crtc, state); | |
ed4a6a7c MR |
12072 | if (ret) { |
12073 | DRM_DEBUG_KMS("Target pipe watermarks are invalid\n"); | |
12074 | return ret; | |
12075 | } | |
12076 | } | |
12077 | ||
12078 | if (dev_priv->display.compute_intermediate_wm && | |
12079 | !to_intel_atomic_state(state)->skip_intermediate_wm) { | |
12080 | if (WARN_ON(!dev_priv->display.compute_pipe_wm)) | |
12081 | return 0; | |
12082 | ||
12083 | /* | |
12084 | * Calculate 'intermediate' watermarks that satisfy both the | |
12085 | * old state and the new state. We can program these | |
12086 | * immediately. | |
12087 | */ | |
12088 | ret = dev_priv->display.compute_intermediate_wm(crtc->dev, | |
12089 | intel_crtc, | |
12090 | pipe_config); | |
12091 | if (ret) { | |
12092 | DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n"); | |
86c8bbbe | 12093 | return ret; |
ed4a6a7c | 12094 | } |
86c8bbbe MR |
12095 | } |
12096 | ||
e435d6e5 ML |
12097 | if (INTEL_INFO(dev)->gen >= 9) { |
12098 | if (mode_changed) | |
12099 | ret = skl_update_scaler_crtc(pipe_config); | |
12100 | ||
12101 | if (!ret) | |
12102 | ret = intel_atomic_setup_scalers(dev, intel_crtc, | |
12103 | pipe_config); | |
12104 | } | |
12105 | ||
12106 | return ret; | |
6d3a1ce7 ML |
12107 | } |
12108 | ||
65b38e0d | 12109 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { |
f6e5b160 CW |
12110 | .mode_set_base_atomic = intel_pipe_set_base_atomic, |
12111 | .load_lut = intel_crtc_load_lut, | |
ea2c67bb MR |
12112 | .atomic_begin = intel_begin_crtc_commit, |
12113 | .atomic_flush = intel_finish_crtc_commit, | |
6d3a1ce7 | 12114 | .atomic_check = intel_crtc_atomic_check, |
f6e5b160 CW |
12115 | }; |
12116 | ||
d29b2f9d ACO |
12117 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) |
12118 | { | |
12119 | struct intel_connector *connector; | |
12120 | ||
12121 | for_each_intel_connector(dev, connector) { | |
12122 | if (connector->base.encoder) { | |
12123 | connector->base.state->best_encoder = | |
12124 | connector->base.encoder; | |
12125 | connector->base.state->crtc = | |
12126 | connector->base.encoder->crtc; | |
12127 | } else { | |
12128 | connector->base.state->best_encoder = NULL; | |
12129 | connector->base.state->crtc = NULL; | |
12130 | } | |
12131 | } | |
12132 | } | |
12133 | ||
050f7aeb | 12134 | static void |
eba905b2 | 12135 | connected_sink_compute_bpp(struct intel_connector *connector, |
5cec258b | 12136 | struct intel_crtc_state *pipe_config) |
050f7aeb DV |
12137 | { |
12138 | int bpp = pipe_config->pipe_bpp; | |
12139 | ||
12140 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n", | |
12141 | connector->base.base.id, | |
c23cc417 | 12142 | connector->base.name); |
050f7aeb DV |
12143 | |
12144 | /* Don't use an invalid EDID bpc value */ | |
12145 | if (connector->base.display_info.bpc && | |
12146 | connector->base.display_info.bpc * 3 < bpp) { | |
12147 | DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n", | |
12148 | bpp, connector->base.display_info.bpc*3); | |
12149 | pipe_config->pipe_bpp = connector->base.display_info.bpc*3; | |
12150 | } | |
12151 | ||
013dd9e0 JN |
12152 | /* Clamp bpp to default limit on screens without EDID 1.4 */ |
12153 | if (connector->base.display_info.bpc == 0) { | |
12154 | int type = connector->base.connector_type; | |
12155 | int clamp_bpp = 24; | |
12156 | ||
12157 | /* Fall back to 18 bpp when DP sink capability is unknown. */ | |
12158 | if (type == DRM_MODE_CONNECTOR_DisplayPort || | |
12159 | type == DRM_MODE_CONNECTOR_eDP) | |
12160 | clamp_bpp = 18; | |
12161 | ||
12162 | if (bpp > clamp_bpp) { | |
12163 | DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of %d\n", | |
12164 | bpp, clamp_bpp); | |
12165 | pipe_config->pipe_bpp = clamp_bpp; | |
12166 | } | |
050f7aeb DV |
12167 | } |
12168 | } | |
12169 | ||
4e53c2e0 | 12170 | static int |
050f7aeb | 12171 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
5cec258b | 12172 | struct intel_crtc_state *pipe_config) |
4e53c2e0 | 12173 | { |
050f7aeb | 12174 | struct drm_device *dev = crtc->base.dev; |
1486017f | 12175 | struct drm_atomic_state *state; |
da3ced29 ACO |
12176 | struct drm_connector *connector; |
12177 | struct drm_connector_state *connector_state; | |
1486017f | 12178 | int bpp, i; |
4e53c2e0 | 12179 | |
666a4537 | 12180 | if ((IS_G4X(dev) || IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))) |
4e53c2e0 | 12181 | bpp = 10*3; |
d328c9d7 DV |
12182 | else if (INTEL_INFO(dev)->gen >= 5) |
12183 | bpp = 12*3; | |
12184 | else | |
12185 | bpp = 8*3; | |
12186 | ||
4e53c2e0 | 12187 | |
4e53c2e0 DV |
12188 | pipe_config->pipe_bpp = bpp; |
12189 | ||
1486017f ACO |
12190 | state = pipe_config->base.state; |
12191 | ||
4e53c2e0 | 12192 | /* Clamp display bpp to EDID value */ |
da3ced29 ACO |
12193 | for_each_connector_in_state(state, connector, connector_state, i) { |
12194 | if (connector_state->crtc != &crtc->base) | |
4e53c2e0 DV |
12195 | continue; |
12196 | ||
da3ced29 ACO |
12197 | connected_sink_compute_bpp(to_intel_connector(connector), |
12198 | pipe_config); | |
4e53c2e0 DV |
12199 | } |
12200 | ||
12201 | return bpp; | |
12202 | } | |
12203 | ||
644db711 DV |
12204 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
12205 | { | |
12206 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " | |
12207 | "type: 0x%x flags: 0x%x\n", | |
1342830c | 12208 | mode->crtc_clock, |
644db711 DV |
12209 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
12210 | mode->crtc_hsync_end, mode->crtc_htotal, | |
12211 | mode->crtc_vdisplay, mode->crtc_vsync_start, | |
12212 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); | |
12213 | } | |
12214 | ||
c0b03411 | 12215 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
5cec258b | 12216 | struct intel_crtc_state *pipe_config, |
c0b03411 DV |
12217 | const char *context) |
12218 | { | |
6a60cd87 CK |
12219 | struct drm_device *dev = crtc->base.dev; |
12220 | struct drm_plane *plane; | |
12221 | struct intel_plane *intel_plane; | |
12222 | struct intel_plane_state *state; | |
12223 | struct drm_framebuffer *fb; | |
12224 | ||
12225 | DRM_DEBUG_KMS("[CRTC:%d]%s config %p for pipe %c\n", crtc->base.base.id, | |
12226 | context, pipe_config, pipe_name(crtc->pipe)); | |
c0b03411 DV |
12227 | |
12228 | DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder)); | |
12229 | DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n", | |
12230 | pipe_config->pipe_bpp, pipe_config->dither); | |
12231 | DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", | |
12232 | pipe_config->has_pch_encoder, | |
12233 | pipe_config->fdi_lanes, | |
12234 | pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n, | |
12235 | pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n, | |
12236 | pipe_config->fdi_m_n.tu); | |
90a6b7b0 | 12237 | DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
eb14cb74 | 12238 | pipe_config->has_dp_encoder, |
90a6b7b0 | 12239 | pipe_config->lane_count, |
eb14cb74 VS |
12240 | pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n, |
12241 | pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n, | |
12242 | pipe_config->dp_m_n.tu); | |
b95af8be | 12243 | |
90a6b7b0 | 12244 | DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n", |
b95af8be | 12245 | pipe_config->has_dp_encoder, |
90a6b7b0 | 12246 | pipe_config->lane_count, |
b95af8be VK |
12247 | pipe_config->dp_m2_n2.gmch_m, |
12248 | pipe_config->dp_m2_n2.gmch_n, | |
12249 | pipe_config->dp_m2_n2.link_m, | |
12250 | pipe_config->dp_m2_n2.link_n, | |
12251 | pipe_config->dp_m2_n2.tu); | |
12252 | ||
55072d19 DV |
12253 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
12254 | pipe_config->has_audio, | |
12255 | pipe_config->has_infoframe); | |
12256 | ||
c0b03411 | 12257 | DRM_DEBUG_KMS("requested mode:\n"); |
2d112de7 | 12258 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
c0b03411 | 12259 | DRM_DEBUG_KMS("adjusted mode:\n"); |
2d112de7 ACO |
12260 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
12261 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); | |
d71b8d4a | 12262 | DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock); |
37327abd VS |
12263 | DRM_DEBUG_KMS("pipe src size: %dx%d\n", |
12264 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); | |
0ec463d3 TU |
12265 | DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n", |
12266 | crtc->num_scalers, | |
12267 | pipe_config->scaler_state.scaler_users, | |
12268 | pipe_config->scaler_state.scaler_id); | |
c0b03411 DV |
12269 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
12270 | pipe_config->gmch_pfit.control, | |
12271 | pipe_config->gmch_pfit.pgm_ratios, | |
12272 | pipe_config->gmch_pfit.lvds_border_bits); | |
fd4daa9c | 12273 | DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n", |
c0b03411 | 12274 | pipe_config->pch_pfit.pos, |
fd4daa9c CW |
12275 | pipe_config->pch_pfit.size, |
12276 | pipe_config->pch_pfit.enabled ? "enabled" : "disabled"); | |
42db64ef | 12277 | DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled); |
cf532bb2 | 12278 | DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide); |
6a60cd87 | 12279 | |
415ff0f6 | 12280 | if (IS_BROXTON(dev)) { |
05712c15 | 12281 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: ebb0: 0x%x, ebb4: 0x%x," |
415ff0f6 | 12282 | "pll0: 0x%x, pll1: 0x%x, pll2: 0x%x, pll3: 0x%x, " |
c8453338 | 12283 | "pll6: 0x%x, pll8: 0x%x, pll9: 0x%x, pll10: 0x%x, pcsdw12: 0x%x\n", |
415ff0f6 TU |
12284 | pipe_config->ddi_pll_sel, |
12285 | pipe_config->dpll_hw_state.ebb0, | |
05712c15 | 12286 | pipe_config->dpll_hw_state.ebb4, |
415ff0f6 TU |
12287 | pipe_config->dpll_hw_state.pll0, |
12288 | pipe_config->dpll_hw_state.pll1, | |
12289 | pipe_config->dpll_hw_state.pll2, | |
12290 | pipe_config->dpll_hw_state.pll3, | |
12291 | pipe_config->dpll_hw_state.pll6, | |
12292 | pipe_config->dpll_hw_state.pll8, | |
05712c15 | 12293 | pipe_config->dpll_hw_state.pll9, |
c8453338 | 12294 | pipe_config->dpll_hw_state.pll10, |
415ff0f6 | 12295 | pipe_config->dpll_hw_state.pcsdw12); |
ef11bdb3 | 12296 | } else if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) { |
415ff0f6 TU |
12297 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: " |
12298 | "ctrl1: 0x%x, cfgcr1: 0x%x, cfgcr2: 0x%x\n", | |
12299 | pipe_config->ddi_pll_sel, | |
12300 | pipe_config->dpll_hw_state.ctrl1, | |
12301 | pipe_config->dpll_hw_state.cfgcr1, | |
12302 | pipe_config->dpll_hw_state.cfgcr2); | |
12303 | } else if (HAS_DDI(dev)) { | |
00490c22 | 12304 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: wrpll: 0x%x spll: 0x%x\n", |
415ff0f6 | 12305 | pipe_config->ddi_pll_sel, |
00490c22 ML |
12306 | pipe_config->dpll_hw_state.wrpll, |
12307 | pipe_config->dpll_hw_state.spll); | |
415ff0f6 TU |
12308 | } else { |
12309 | DRM_DEBUG_KMS("dpll_hw_state: dpll: 0x%x, dpll_md: 0x%x, " | |
12310 | "fp0: 0x%x, fp1: 0x%x\n", | |
12311 | pipe_config->dpll_hw_state.dpll, | |
12312 | pipe_config->dpll_hw_state.dpll_md, | |
12313 | pipe_config->dpll_hw_state.fp0, | |
12314 | pipe_config->dpll_hw_state.fp1); | |
12315 | } | |
12316 | ||
6a60cd87 CK |
12317 | DRM_DEBUG_KMS("planes on this crtc\n"); |
12318 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { | |
12319 | intel_plane = to_intel_plane(plane); | |
12320 | if (intel_plane->pipe != crtc->pipe) | |
12321 | continue; | |
12322 | ||
12323 | state = to_intel_plane_state(plane->state); | |
12324 | fb = state->base.fb; | |
12325 | if (!fb) { | |
12326 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d " | |
12327 | "disabled, scaler_id = %d\n", | |
12328 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", | |
12329 | plane->base.id, intel_plane->pipe, | |
12330 | (crtc->base.primary == plane) ? 0 : intel_plane->plane + 1, | |
12331 | drm_plane_index(plane), state->scaler_id); | |
12332 | continue; | |
12333 | } | |
12334 | ||
12335 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d enabled", | |
12336 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", | |
12337 | plane->base.id, intel_plane->pipe, | |
12338 | crtc->base.primary == plane ? 0 : intel_plane->plane + 1, | |
12339 | drm_plane_index(plane)); | |
12340 | DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = 0x%x", | |
12341 | fb->base.id, fb->width, fb->height, fb->pixel_format); | |
12342 | DRM_DEBUG_KMS("\tscaler:%d src (%u, %u) %ux%u dst (%u, %u) %ux%u\n", | |
12343 | state->scaler_id, | |
12344 | state->src.x1 >> 16, state->src.y1 >> 16, | |
12345 | drm_rect_width(&state->src) >> 16, | |
12346 | drm_rect_height(&state->src) >> 16, | |
12347 | state->dst.x1, state->dst.y1, | |
12348 | drm_rect_width(&state->dst), drm_rect_height(&state->dst)); | |
12349 | } | |
c0b03411 DV |
12350 | } |
12351 | ||
5448a00d | 12352 | static bool check_digital_port_conflicts(struct drm_atomic_state *state) |
00f0b378 | 12353 | { |
5448a00d | 12354 | struct drm_device *dev = state->dev; |
da3ced29 | 12355 | struct drm_connector *connector; |
00f0b378 VS |
12356 | unsigned int used_ports = 0; |
12357 | ||
12358 | /* | |
12359 | * Walk the connector list instead of the encoder | |
12360 | * list to detect the problem on ddi platforms | |
12361 | * where there's just one encoder per digital port. | |
12362 | */ | |
0bff4858 VS |
12363 | drm_for_each_connector(connector, dev) { |
12364 | struct drm_connector_state *connector_state; | |
12365 | struct intel_encoder *encoder; | |
12366 | ||
12367 | connector_state = drm_atomic_get_existing_connector_state(state, connector); | |
12368 | if (!connector_state) | |
12369 | connector_state = connector->state; | |
12370 | ||
5448a00d | 12371 | if (!connector_state->best_encoder) |
00f0b378 VS |
12372 | continue; |
12373 | ||
5448a00d ACO |
12374 | encoder = to_intel_encoder(connector_state->best_encoder); |
12375 | ||
12376 | WARN_ON(!connector_state->crtc); | |
00f0b378 VS |
12377 | |
12378 | switch (encoder->type) { | |
12379 | unsigned int port_mask; | |
12380 | case INTEL_OUTPUT_UNKNOWN: | |
12381 | if (WARN_ON(!HAS_DDI(dev))) | |
12382 | break; | |
12383 | case INTEL_OUTPUT_DISPLAYPORT: | |
12384 | case INTEL_OUTPUT_HDMI: | |
12385 | case INTEL_OUTPUT_EDP: | |
12386 | port_mask = 1 << enc_to_dig_port(&encoder->base)->port; | |
12387 | ||
12388 | /* the same port mustn't appear more than once */ | |
12389 | if (used_ports & port_mask) | |
12390 | return false; | |
12391 | ||
12392 | used_ports |= port_mask; | |
12393 | default: | |
12394 | break; | |
12395 | } | |
12396 | } | |
12397 | ||
12398 | return true; | |
12399 | } | |
12400 | ||
83a57153 ACO |
12401 | static void |
12402 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) | |
12403 | { | |
12404 | struct drm_crtc_state tmp_state; | |
663a3640 | 12405 | struct intel_crtc_scaler_state scaler_state; |
4978cc93 ACO |
12406 | struct intel_dpll_hw_state dpll_hw_state; |
12407 | enum intel_dpll_id shared_dpll; | |
8504c74c | 12408 | uint32_t ddi_pll_sel; |
c4e2d043 | 12409 | bool force_thru; |
83a57153 | 12410 | |
7546a384 ACO |
12411 | /* FIXME: before the switch to atomic started, a new pipe_config was |
12412 | * kzalloc'd. Code that depends on any field being zero should be | |
12413 | * fixed, so that the crtc_state can be safely duplicated. For now, | |
12414 | * only fields that are know to not cause problems are preserved. */ | |
12415 | ||
83a57153 | 12416 | tmp_state = crtc_state->base; |
663a3640 | 12417 | scaler_state = crtc_state->scaler_state; |
4978cc93 ACO |
12418 | shared_dpll = crtc_state->shared_dpll; |
12419 | dpll_hw_state = crtc_state->dpll_hw_state; | |
8504c74c | 12420 | ddi_pll_sel = crtc_state->ddi_pll_sel; |
c4e2d043 | 12421 | force_thru = crtc_state->pch_pfit.force_thru; |
4978cc93 | 12422 | |
83a57153 | 12423 | memset(crtc_state, 0, sizeof *crtc_state); |
4978cc93 | 12424 | |
83a57153 | 12425 | crtc_state->base = tmp_state; |
663a3640 | 12426 | crtc_state->scaler_state = scaler_state; |
4978cc93 ACO |
12427 | crtc_state->shared_dpll = shared_dpll; |
12428 | crtc_state->dpll_hw_state = dpll_hw_state; | |
8504c74c | 12429 | crtc_state->ddi_pll_sel = ddi_pll_sel; |
c4e2d043 | 12430 | crtc_state->pch_pfit.force_thru = force_thru; |
83a57153 ACO |
12431 | } |
12432 | ||
548ee15b | 12433 | static int |
b8cecdf5 | 12434 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
b359283a | 12435 | struct intel_crtc_state *pipe_config) |
ee7b9f93 | 12436 | { |
b359283a | 12437 | struct drm_atomic_state *state = pipe_config->base.state; |
7758a113 | 12438 | struct intel_encoder *encoder; |
da3ced29 | 12439 | struct drm_connector *connector; |
0b901879 | 12440 | struct drm_connector_state *connector_state; |
d328c9d7 | 12441 | int base_bpp, ret = -EINVAL; |
0b901879 | 12442 | int i; |
e29c22c0 | 12443 | bool retry = true; |
ee7b9f93 | 12444 | |
83a57153 | 12445 | clear_intel_crtc_state(pipe_config); |
7758a113 | 12446 | |
e143a21c DV |
12447 | pipe_config->cpu_transcoder = |
12448 | (enum transcoder) to_intel_crtc(crtc)->pipe; | |
b8cecdf5 | 12449 | |
2960bc9c ID |
12450 | /* |
12451 | * Sanitize sync polarity flags based on requested ones. If neither | |
12452 | * positive or negative polarity is requested, treat this as meaning | |
12453 | * negative polarity. | |
12454 | */ | |
2d112de7 | 12455 | if (!(pipe_config->base.adjusted_mode.flags & |
2960bc9c | 12456 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
2d112de7 | 12457 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
2960bc9c | 12458 | |
2d112de7 | 12459 | if (!(pipe_config->base.adjusted_mode.flags & |
2960bc9c | 12460 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
2d112de7 | 12461 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
2960bc9c | 12462 | |
d328c9d7 DV |
12463 | base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
12464 | pipe_config); | |
12465 | if (base_bpp < 0) | |
4e53c2e0 DV |
12466 | goto fail; |
12467 | ||
e41a56be VS |
12468 | /* |
12469 | * Determine the real pipe dimensions. Note that stereo modes can | |
12470 | * increase the actual pipe size due to the frame doubling and | |
12471 | * insertion of additional space for blanks between the frame. This | |
12472 | * is stored in the crtc timings. We use the requested mode to do this | |
12473 | * computation to clearly distinguish it from the adjusted mode, which | |
12474 | * can be changed by the connectors in the below retry loop. | |
12475 | */ | |
2d112de7 | 12476 | drm_crtc_get_hv_timing(&pipe_config->base.mode, |
ecb7e16b GP |
12477 | &pipe_config->pipe_src_w, |
12478 | &pipe_config->pipe_src_h); | |
e41a56be | 12479 | |
e29c22c0 | 12480 | encoder_retry: |
ef1b460d | 12481 | /* Ensure the port clock defaults are reset when retrying. */ |
ff9a6750 | 12482 | pipe_config->port_clock = 0; |
ef1b460d | 12483 | pipe_config->pixel_multiplier = 1; |
ff9a6750 | 12484 | |
135c81b8 | 12485 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
2d112de7 ACO |
12486 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
12487 | CRTC_STEREO_DOUBLE); | |
135c81b8 | 12488 | |
7758a113 DV |
12489 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
12490 | * adjust it according to limitations or connector properties, and also | |
12491 | * a chance to reject the mode entirely. | |
47f1c6c9 | 12492 | */ |
da3ced29 | 12493 | for_each_connector_in_state(state, connector, connector_state, i) { |
0b901879 | 12494 | if (connector_state->crtc != crtc) |
7758a113 | 12495 | continue; |
7ae89233 | 12496 | |
0b901879 ACO |
12497 | encoder = to_intel_encoder(connector_state->best_encoder); |
12498 | ||
efea6e8e DV |
12499 | if (!(encoder->compute_config(encoder, pipe_config))) { |
12500 | DRM_DEBUG_KMS("Encoder config failure\n"); | |
7758a113 DV |
12501 | goto fail; |
12502 | } | |
ee7b9f93 | 12503 | } |
47f1c6c9 | 12504 | |
ff9a6750 DV |
12505 | /* Set default port clock if not overwritten by the encoder. Needs to be |
12506 | * done afterwards in case the encoder adjusts the mode. */ | |
12507 | if (!pipe_config->port_clock) | |
2d112de7 | 12508 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
241bfc38 | 12509 | * pipe_config->pixel_multiplier; |
ff9a6750 | 12510 | |
a43f6e0f | 12511 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
e29c22c0 | 12512 | if (ret < 0) { |
7758a113 DV |
12513 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
12514 | goto fail; | |
ee7b9f93 | 12515 | } |
e29c22c0 DV |
12516 | |
12517 | if (ret == RETRY) { | |
12518 | if (WARN(!retry, "loop in pipe configuration computation\n")) { | |
12519 | ret = -EINVAL; | |
12520 | goto fail; | |
12521 | } | |
12522 | ||
12523 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); | |
12524 | retry = false; | |
12525 | goto encoder_retry; | |
12526 | } | |
12527 | ||
e8fa4270 DV |
12528 | /* Dithering seems to not pass-through bits correctly when it should, so |
12529 | * only enable it on 6bpc panels. */ | |
12530 | pipe_config->dither = pipe_config->pipe_bpp == 6*3; | |
62f0ace5 | 12531 | DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n", |
d328c9d7 | 12532 | base_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
4e53c2e0 | 12533 | |
7758a113 | 12534 | fail: |
548ee15b | 12535 | return ret; |
ee7b9f93 | 12536 | } |
47f1c6c9 | 12537 | |
ea9d758d | 12538 | static void |
4740b0f2 | 12539 | intel_modeset_update_crtc_state(struct drm_atomic_state *state) |
ea9d758d | 12540 | { |
0a9ab303 ACO |
12541 | struct drm_crtc *crtc; |
12542 | struct drm_crtc_state *crtc_state; | |
8a75d157 | 12543 | int i; |
ea9d758d | 12544 | |
7668851f | 12545 | /* Double check state. */ |
8a75d157 | 12546 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
3cb480bc | 12547 | to_intel_crtc(crtc)->config = to_intel_crtc_state(crtc->state); |
fc467a22 ML |
12548 | |
12549 | /* Update hwmode for vblank functions */ | |
12550 | if (crtc->state->active) | |
12551 | crtc->hwmode = crtc->state->adjusted_mode; | |
12552 | else | |
12553 | crtc->hwmode.crtc_clock = 0; | |
61067a5e ML |
12554 | |
12555 | /* | |
12556 | * Update legacy state to satisfy fbc code. This can | |
12557 | * be removed when fbc uses the atomic state. | |
12558 | */ | |
12559 | if (drm_atomic_get_existing_plane_state(state, crtc->primary)) { | |
12560 | struct drm_plane_state *plane_state = crtc->primary->state; | |
12561 | ||
12562 | crtc->primary->fb = plane_state->fb; | |
12563 | crtc->x = plane_state->src_x >> 16; | |
12564 | crtc->y = plane_state->src_y >> 16; | |
12565 | } | |
ea9d758d | 12566 | } |
ea9d758d DV |
12567 | } |
12568 | ||
3bd26263 | 12569 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
f1f644dc | 12570 | { |
3bd26263 | 12571 | int diff; |
f1f644dc JB |
12572 | |
12573 | if (clock1 == clock2) | |
12574 | return true; | |
12575 | ||
12576 | if (!clock1 || !clock2) | |
12577 | return false; | |
12578 | ||
12579 | diff = abs(clock1 - clock2); | |
12580 | ||
12581 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) | |
12582 | return true; | |
12583 | ||
12584 | return false; | |
12585 | } | |
12586 | ||
25c5b266 DV |
12587 | #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \ |
12588 | list_for_each_entry((intel_crtc), \ | |
12589 | &(dev)->mode_config.crtc_list, \ | |
12590 | base.head) \ | |
95150bdf | 12591 | for_each_if (mask & (1 <<(intel_crtc)->pipe)) |
25c5b266 | 12592 | |
cfb23ed6 ML |
12593 | static bool |
12594 | intel_compare_m_n(unsigned int m, unsigned int n, | |
12595 | unsigned int m2, unsigned int n2, | |
12596 | bool exact) | |
12597 | { | |
12598 | if (m == m2 && n == n2) | |
12599 | return true; | |
12600 | ||
12601 | if (exact || !m || !n || !m2 || !n2) | |
12602 | return false; | |
12603 | ||
12604 | BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX); | |
12605 | ||
31d10b57 ML |
12606 | if (n > n2) { |
12607 | while (n > n2) { | |
cfb23ed6 ML |
12608 | m2 <<= 1; |
12609 | n2 <<= 1; | |
12610 | } | |
31d10b57 ML |
12611 | } else if (n < n2) { |
12612 | while (n < n2) { | |
cfb23ed6 ML |
12613 | m <<= 1; |
12614 | n <<= 1; | |
12615 | } | |
12616 | } | |
12617 | ||
31d10b57 ML |
12618 | if (n != n2) |
12619 | return false; | |
12620 | ||
12621 | return intel_fuzzy_clock_check(m, m2); | |
cfb23ed6 ML |
12622 | } |
12623 | ||
12624 | static bool | |
12625 | intel_compare_link_m_n(const struct intel_link_m_n *m_n, | |
12626 | struct intel_link_m_n *m2_n2, | |
12627 | bool adjust) | |
12628 | { | |
12629 | if (m_n->tu == m2_n2->tu && | |
12630 | intel_compare_m_n(m_n->gmch_m, m_n->gmch_n, | |
12631 | m2_n2->gmch_m, m2_n2->gmch_n, !adjust) && | |
12632 | intel_compare_m_n(m_n->link_m, m_n->link_n, | |
12633 | m2_n2->link_m, m2_n2->link_n, !adjust)) { | |
12634 | if (adjust) | |
12635 | *m2_n2 = *m_n; | |
12636 | ||
12637 | return true; | |
12638 | } | |
12639 | ||
12640 | return false; | |
12641 | } | |
12642 | ||
0e8ffe1b | 12643 | static bool |
2fa2fe9a | 12644 | intel_pipe_config_compare(struct drm_device *dev, |
5cec258b | 12645 | struct intel_crtc_state *current_config, |
cfb23ed6 ML |
12646 | struct intel_crtc_state *pipe_config, |
12647 | bool adjust) | |
0e8ffe1b | 12648 | { |
cfb23ed6 ML |
12649 | bool ret = true; |
12650 | ||
12651 | #define INTEL_ERR_OR_DBG_KMS(fmt, ...) \ | |
12652 | do { \ | |
12653 | if (!adjust) \ | |
12654 | DRM_ERROR(fmt, ##__VA_ARGS__); \ | |
12655 | else \ | |
12656 | DRM_DEBUG_KMS(fmt, ##__VA_ARGS__); \ | |
12657 | } while (0) | |
12658 | ||
66e985c0 DV |
12659 | #define PIPE_CONF_CHECK_X(name) \ |
12660 | if (current_config->name != pipe_config->name) { \ | |
cfb23ed6 | 12661 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
66e985c0 DV |
12662 | "(expected 0x%08x, found 0x%08x)\n", \ |
12663 | current_config->name, \ | |
12664 | pipe_config->name); \ | |
cfb23ed6 | 12665 | ret = false; \ |
66e985c0 DV |
12666 | } |
12667 | ||
08a24034 DV |
12668 | #define PIPE_CONF_CHECK_I(name) \ |
12669 | if (current_config->name != pipe_config->name) { \ | |
cfb23ed6 | 12670 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
08a24034 DV |
12671 | "(expected %i, found %i)\n", \ |
12672 | current_config->name, \ | |
12673 | pipe_config->name); \ | |
cfb23ed6 ML |
12674 | ret = false; \ |
12675 | } | |
12676 | ||
12677 | #define PIPE_CONF_CHECK_M_N(name) \ | |
12678 | if (!intel_compare_link_m_n(¤t_config->name, \ | |
12679 | &pipe_config->name,\ | |
12680 | adjust)) { \ | |
12681 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ | |
12682 | "(expected tu %i gmch %i/%i link %i/%i, " \ | |
12683 | "found tu %i, gmch %i/%i link %i/%i)\n", \ | |
12684 | current_config->name.tu, \ | |
12685 | current_config->name.gmch_m, \ | |
12686 | current_config->name.gmch_n, \ | |
12687 | current_config->name.link_m, \ | |
12688 | current_config->name.link_n, \ | |
12689 | pipe_config->name.tu, \ | |
12690 | pipe_config->name.gmch_m, \ | |
12691 | pipe_config->name.gmch_n, \ | |
12692 | pipe_config->name.link_m, \ | |
12693 | pipe_config->name.link_n); \ | |
12694 | ret = false; \ | |
12695 | } | |
12696 | ||
12697 | #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \ | |
12698 | if (!intel_compare_link_m_n(¤t_config->name, \ | |
12699 | &pipe_config->name, adjust) && \ | |
12700 | !intel_compare_link_m_n(¤t_config->alt_name, \ | |
12701 | &pipe_config->name, adjust)) { \ | |
12702 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ | |
12703 | "(expected tu %i gmch %i/%i link %i/%i, " \ | |
12704 | "or tu %i gmch %i/%i link %i/%i, " \ | |
12705 | "found tu %i, gmch %i/%i link %i/%i)\n", \ | |
12706 | current_config->name.tu, \ | |
12707 | current_config->name.gmch_m, \ | |
12708 | current_config->name.gmch_n, \ | |
12709 | current_config->name.link_m, \ | |
12710 | current_config->name.link_n, \ | |
12711 | current_config->alt_name.tu, \ | |
12712 | current_config->alt_name.gmch_m, \ | |
12713 | current_config->alt_name.gmch_n, \ | |
12714 | current_config->alt_name.link_m, \ | |
12715 | current_config->alt_name.link_n, \ | |
12716 | pipe_config->name.tu, \ | |
12717 | pipe_config->name.gmch_m, \ | |
12718 | pipe_config->name.gmch_n, \ | |
12719 | pipe_config->name.link_m, \ | |
12720 | pipe_config->name.link_n); \ | |
12721 | ret = false; \ | |
88adfff1 DV |
12722 | } |
12723 | ||
b95af8be VK |
12724 | /* This is required for BDW+ where there is only one set of registers for |
12725 | * switching between high and low RR. | |
12726 | * This macro can be used whenever a comparison has to be made between one | |
12727 | * hw state and multiple sw state variables. | |
12728 | */ | |
12729 | #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \ | |
12730 | if ((current_config->name != pipe_config->name) && \ | |
12731 | (current_config->alt_name != pipe_config->name)) { \ | |
cfb23ed6 | 12732 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
b95af8be VK |
12733 | "(expected %i or %i, found %i)\n", \ |
12734 | current_config->name, \ | |
12735 | current_config->alt_name, \ | |
12736 | pipe_config->name); \ | |
cfb23ed6 | 12737 | ret = false; \ |
b95af8be VK |
12738 | } |
12739 | ||
1bd1bd80 DV |
12740 | #define PIPE_CONF_CHECK_FLAGS(name, mask) \ |
12741 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ | |
cfb23ed6 | 12742 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name "(" #mask ") " \ |
1bd1bd80 DV |
12743 | "(expected %i, found %i)\n", \ |
12744 | current_config->name & (mask), \ | |
12745 | pipe_config->name & (mask)); \ | |
cfb23ed6 | 12746 | ret = false; \ |
1bd1bd80 DV |
12747 | } |
12748 | ||
5e550656 VS |
12749 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \ |
12750 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ | |
cfb23ed6 | 12751 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
5e550656 VS |
12752 | "(expected %i, found %i)\n", \ |
12753 | current_config->name, \ | |
12754 | pipe_config->name); \ | |
cfb23ed6 | 12755 | ret = false; \ |
5e550656 VS |
12756 | } |
12757 | ||
bb760063 DV |
12758 | #define PIPE_CONF_QUIRK(quirk) \ |
12759 | ((current_config->quirks | pipe_config->quirks) & (quirk)) | |
12760 | ||
eccb140b DV |
12761 | PIPE_CONF_CHECK_I(cpu_transcoder); |
12762 | ||
08a24034 DV |
12763 | PIPE_CONF_CHECK_I(has_pch_encoder); |
12764 | PIPE_CONF_CHECK_I(fdi_lanes); | |
cfb23ed6 | 12765 | PIPE_CONF_CHECK_M_N(fdi_m_n); |
08a24034 | 12766 | |
eb14cb74 | 12767 | PIPE_CONF_CHECK_I(has_dp_encoder); |
90a6b7b0 | 12768 | PIPE_CONF_CHECK_I(lane_count); |
b95af8be VK |
12769 | |
12770 | if (INTEL_INFO(dev)->gen < 8) { | |
cfb23ed6 ML |
12771 | PIPE_CONF_CHECK_M_N(dp_m_n); |
12772 | ||
cfb23ed6 ML |
12773 | if (current_config->has_drrs) |
12774 | PIPE_CONF_CHECK_M_N(dp_m2_n2); | |
12775 | } else | |
12776 | PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2); | |
eb14cb74 | 12777 | |
a65347ba JN |
12778 | PIPE_CONF_CHECK_I(has_dsi_encoder); |
12779 | ||
2d112de7 ACO |
12780 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
12781 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); | |
12782 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); | |
12783 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); | |
12784 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); | |
12785 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); | |
1bd1bd80 | 12786 | |
2d112de7 ACO |
12787 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
12788 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); | |
12789 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); | |
12790 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); | |
12791 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); | |
12792 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); | |
1bd1bd80 | 12793 | |
c93f54cf | 12794 | PIPE_CONF_CHECK_I(pixel_multiplier); |
6897b4b5 | 12795 | PIPE_CONF_CHECK_I(has_hdmi_sink); |
b5a9fa09 | 12796 | if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) || |
666a4537 | 12797 | IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) |
b5a9fa09 | 12798 | PIPE_CONF_CHECK_I(limited_color_range); |
e43823ec | 12799 | PIPE_CONF_CHECK_I(has_infoframe); |
6c49f241 | 12800 | |
9ed109a7 DV |
12801 | PIPE_CONF_CHECK_I(has_audio); |
12802 | ||
2d112de7 | 12803 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
1bd1bd80 DV |
12804 | DRM_MODE_FLAG_INTERLACE); |
12805 | ||
bb760063 | 12806 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
2d112de7 | 12807 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12808 | DRM_MODE_FLAG_PHSYNC); |
2d112de7 | 12809 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12810 | DRM_MODE_FLAG_NHSYNC); |
2d112de7 | 12811 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12812 | DRM_MODE_FLAG_PVSYNC); |
2d112de7 | 12813 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 DV |
12814 | DRM_MODE_FLAG_NVSYNC); |
12815 | } | |
045ac3b5 | 12816 | |
333b8ca8 | 12817 | PIPE_CONF_CHECK_X(gmch_pfit.control); |
e2ff2d4a DV |
12818 | /* pfit ratios are autocomputed by the hw on gen4+ */ |
12819 | if (INTEL_INFO(dev)->gen < 4) | |
12820 | PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios); | |
333b8ca8 | 12821 | PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits); |
9953599b | 12822 | |
bfd16b2a ML |
12823 | if (!adjust) { |
12824 | PIPE_CONF_CHECK_I(pipe_src_w); | |
12825 | PIPE_CONF_CHECK_I(pipe_src_h); | |
12826 | ||
12827 | PIPE_CONF_CHECK_I(pch_pfit.enabled); | |
12828 | if (current_config->pch_pfit.enabled) { | |
12829 | PIPE_CONF_CHECK_X(pch_pfit.pos); | |
12830 | PIPE_CONF_CHECK_X(pch_pfit.size); | |
12831 | } | |
2fa2fe9a | 12832 | |
7aefe2b5 ML |
12833 | PIPE_CONF_CHECK_I(scaler_state.scaler_id); |
12834 | } | |
a1b2278e | 12835 | |
e59150dc JB |
12836 | /* BDW+ don't expose a synchronous way to read the state */ |
12837 | if (IS_HASWELL(dev)) | |
12838 | PIPE_CONF_CHECK_I(ips_enabled); | |
42db64ef | 12839 | |
282740f7 VS |
12840 | PIPE_CONF_CHECK_I(double_wide); |
12841 | ||
26804afd DV |
12842 | PIPE_CONF_CHECK_X(ddi_pll_sel); |
12843 | ||
c0d43d62 | 12844 | PIPE_CONF_CHECK_I(shared_dpll); |
66e985c0 | 12845 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
8bcc2795 | 12846 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
66e985c0 DV |
12847 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
12848 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); | |
d452c5b6 | 12849 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
00490c22 | 12850 | PIPE_CONF_CHECK_X(dpll_hw_state.spll); |
3f4cd19f DL |
12851 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
12852 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); | |
12853 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); | |
c0d43d62 | 12854 | |
42571aef VS |
12855 | if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) |
12856 | PIPE_CONF_CHECK_I(pipe_bpp); | |
12857 | ||
2d112de7 | 12858 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
a9a7e98a | 12859 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
5e550656 | 12860 | |
66e985c0 | 12861 | #undef PIPE_CONF_CHECK_X |
08a24034 | 12862 | #undef PIPE_CONF_CHECK_I |
b95af8be | 12863 | #undef PIPE_CONF_CHECK_I_ALT |
1bd1bd80 | 12864 | #undef PIPE_CONF_CHECK_FLAGS |
5e550656 | 12865 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
bb760063 | 12866 | #undef PIPE_CONF_QUIRK |
cfb23ed6 | 12867 | #undef INTEL_ERR_OR_DBG_KMS |
88adfff1 | 12868 | |
cfb23ed6 | 12869 | return ret; |
0e8ffe1b DV |
12870 | } |
12871 | ||
08db6652 DL |
12872 | static void check_wm_state(struct drm_device *dev) |
12873 | { | |
12874 | struct drm_i915_private *dev_priv = dev->dev_private; | |
12875 | struct skl_ddb_allocation hw_ddb, *sw_ddb; | |
12876 | struct intel_crtc *intel_crtc; | |
12877 | int plane; | |
12878 | ||
12879 | if (INTEL_INFO(dev)->gen < 9) | |
12880 | return; | |
12881 | ||
12882 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); | |
12883 | sw_ddb = &dev_priv->wm.skl_hw.ddb; | |
12884 | ||
12885 | for_each_intel_crtc(dev, intel_crtc) { | |
12886 | struct skl_ddb_entry *hw_entry, *sw_entry; | |
12887 | const enum pipe pipe = intel_crtc->pipe; | |
12888 | ||
12889 | if (!intel_crtc->active) | |
12890 | continue; | |
12891 | ||
12892 | /* planes */ | |
dd740780 | 12893 | for_each_plane(dev_priv, pipe, plane) { |
08db6652 DL |
12894 | hw_entry = &hw_ddb.plane[pipe][plane]; |
12895 | sw_entry = &sw_ddb->plane[pipe][plane]; | |
12896 | ||
12897 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) | |
12898 | continue; | |
12899 | ||
12900 | DRM_ERROR("mismatch in DDB state pipe %c plane %d " | |
12901 | "(expected (%u,%u), found (%u,%u))\n", | |
12902 | pipe_name(pipe), plane + 1, | |
12903 | sw_entry->start, sw_entry->end, | |
12904 | hw_entry->start, hw_entry->end); | |
12905 | } | |
12906 | ||
12907 | /* cursor */ | |
4969d33e MR |
12908 | hw_entry = &hw_ddb.plane[pipe][PLANE_CURSOR]; |
12909 | sw_entry = &sw_ddb->plane[pipe][PLANE_CURSOR]; | |
08db6652 DL |
12910 | |
12911 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) | |
12912 | continue; | |
12913 | ||
12914 | DRM_ERROR("mismatch in DDB state pipe %c cursor " | |
12915 | "(expected (%u,%u), found (%u,%u))\n", | |
12916 | pipe_name(pipe), | |
12917 | sw_entry->start, sw_entry->end, | |
12918 | hw_entry->start, hw_entry->end); | |
12919 | } | |
12920 | } | |
12921 | ||
91d1b4bd | 12922 | static void |
35dd3c64 ML |
12923 | check_connector_state(struct drm_device *dev, |
12924 | struct drm_atomic_state *old_state) | |
8af6cf88 | 12925 | { |
35dd3c64 ML |
12926 | struct drm_connector_state *old_conn_state; |
12927 | struct drm_connector *connector; | |
12928 | int i; | |
8af6cf88 | 12929 | |
35dd3c64 ML |
12930 | for_each_connector_in_state(old_state, connector, old_conn_state, i) { |
12931 | struct drm_encoder *encoder = connector->encoder; | |
12932 | struct drm_connector_state *state = connector->state; | |
ad3c558f | 12933 | |
8af6cf88 DV |
12934 | /* This also checks the encoder/connector hw state with the |
12935 | * ->get_hw_state callbacks. */ | |
35dd3c64 | 12936 | intel_connector_check_state(to_intel_connector(connector)); |
8af6cf88 | 12937 | |
ad3c558f | 12938 | I915_STATE_WARN(state->best_encoder != encoder, |
35dd3c64 | 12939 | "connector's atomic encoder doesn't match legacy encoder\n"); |
8af6cf88 | 12940 | } |
91d1b4bd DV |
12941 | } |
12942 | ||
12943 | static void | |
12944 | check_encoder_state(struct drm_device *dev) | |
12945 | { | |
12946 | struct intel_encoder *encoder; | |
12947 | struct intel_connector *connector; | |
8af6cf88 | 12948 | |
b2784e15 | 12949 | for_each_intel_encoder(dev, encoder) { |
8af6cf88 | 12950 | bool enabled = false; |
4d20cd86 | 12951 | enum pipe pipe; |
8af6cf88 DV |
12952 | |
12953 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", | |
12954 | encoder->base.base.id, | |
8e329a03 | 12955 | encoder->base.name); |
8af6cf88 | 12956 | |
3a3371ff | 12957 | for_each_intel_connector(dev, connector) { |
4d20cd86 | 12958 | if (connector->base.state->best_encoder != &encoder->base) |
8af6cf88 DV |
12959 | continue; |
12960 | enabled = true; | |
ad3c558f ML |
12961 | |
12962 | I915_STATE_WARN(connector->base.state->crtc != | |
12963 | encoder->base.crtc, | |
12964 | "connector's crtc doesn't match encoder crtc\n"); | |
8af6cf88 | 12965 | } |
0e32b39c | 12966 | |
e2c719b7 | 12967 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
8af6cf88 DV |
12968 | "encoder's enabled state mismatch " |
12969 | "(expected %i, found %i)\n", | |
12970 | !!encoder->base.crtc, enabled); | |
7c60d198 ML |
12971 | |
12972 | if (!encoder->base.crtc) { | |
4d20cd86 | 12973 | bool active; |
7c60d198 | 12974 | |
4d20cd86 ML |
12975 | active = encoder->get_hw_state(encoder, &pipe); |
12976 | I915_STATE_WARN(active, | |
12977 | "encoder detached but still enabled on pipe %c.\n", | |
12978 | pipe_name(pipe)); | |
7c60d198 | 12979 | } |
8af6cf88 | 12980 | } |
91d1b4bd DV |
12981 | } |
12982 | ||
12983 | static void | |
4d20cd86 | 12984 | check_crtc_state(struct drm_device *dev, struct drm_atomic_state *old_state) |
91d1b4bd | 12985 | { |
fbee40df | 12986 | struct drm_i915_private *dev_priv = dev->dev_private; |
91d1b4bd | 12987 | struct intel_encoder *encoder; |
4d20cd86 ML |
12988 | struct drm_crtc_state *old_crtc_state; |
12989 | struct drm_crtc *crtc; | |
12990 | int i; | |
8af6cf88 | 12991 | |
4d20cd86 ML |
12992 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
12993 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
12994 | struct intel_crtc_state *pipe_config, *sw_config; | |
7b89b8de | 12995 | bool active; |
8af6cf88 | 12996 | |
bfd16b2a ML |
12997 | if (!needs_modeset(crtc->state) && |
12998 | !to_intel_crtc_state(crtc->state)->update_pipe) | |
4d20cd86 | 12999 | continue; |
045ac3b5 | 13000 | |
4d20cd86 ML |
13001 | __drm_atomic_helper_crtc_destroy_state(crtc, old_crtc_state); |
13002 | pipe_config = to_intel_crtc_state(old_crtc_state); | |
13003 | memset(pipe_config, 0, sizeof(*pipe_config)); | |
13004 | pipe_config->base.crtc = crtc; | |
13005 | pipe_config->base.state = old_state; | |
8af6cf88 | 13006 | |
4d20cd86 ML |
13007 | DRM_DEBUG_KMS("[CRTC:%d]\n", |
13008 | crtc->base.id); | |
8af6cf88 | 13009 | |
4d20cd86 ML |
13010 | active = dev_priv->display.get_pipe_config(intel_crtc, |
13011 | pipe_config); | |
d62cf62a | 13012 | |
b6b5d049 | 13013 | /* hw state is inconsistent with the pipe quirk */ |
4d20cd86 ML |
13014 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
13015 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
13016 | active = crtc->state->active; | |
6c49f241 | 13017 | |
4d20cd86 | 13018 | I915_STATE_WARN(crtc->state->active != active, |
0e8ffe1b | 13019 | "crtc active state doesn't match with hw state " |
4d20cd86 | 13020 | "(expected %i, found %i)\n", crtc->state->active, active); |
0e8ffe1b | 13021 | |
4d20cd86 | 13022 | I915_STATE_WARN(intel_crtc->active != crtc->state->active, |
53d9f4e9 | 13023 | "transitional active state does not match atomic hw state " |
4d20cd86 ML |
13024 | "(expected %i, found %i)\n", crtc->state->active, intel_crtc->active); |
13025 | ||
13026 | for_each_encoder_on_crtc(dev, crtc, encoder) { | |
13027 | enum pipe pipe; | |
13028 | ||
13029 | active = encoder->get_hw_state(encoder, &pipe); | |
13030 | I915_STATE_WARN(active != crtc->state->active, | |
13031 | "[ENCODER:%i] active %i with crtc active %i\n", | |
13032 | encoder->base.base.id, active, crtc->state->active); | |
13033 | ||
13034 | I915_STATE_WARN(active && intel_crtc->pipe != pipe, | |
13035 | "Encoder connected to wrong pipe %c\n", | |
13036 | pipe_name(pipe)); | |
13037 | ||
13038 | if (active) | |
13039 | encoder->get_config(encoder, pipe_config); | |
13040 | } | |
53d9f4e9 | 13041 | |
4d20cd86 | 13042 | if (!crtc->state->active) |
cfb23ed6 ML |
13043 | continue; |
13044 | ||
4d20cd86 ML |
13045 | sw_config = to_intel_crtc_state(crtc->state); |
13046 | if (!intel_pipe_config_compare(dev, sw_config, | |
13047 | pipe_config, false)) { | |
e2c719b7 | 13048 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); |
4d20cd86 | 13049 | intel_dump_pipe_config(intel_crtc, pipe_config, |
c0b03411 | 13050 | "[hw state]"); |
4d20cd86 | 13051 | intel_dump_pipe_config(intel_crtc, sw_config, |
c0b03411 DV |
13052 | "[sw state]"); |
13053 | } | |
8af6cf88 DV |
13054 | } |
13055 | } | |
13056 | ||
91d1b4bd DV |
13057 | static void |
13058 | check_shared_dpll_state(struct drm_device *dev) | |
13059 | { | |
fbee40df | 13060 | struct drm_i915_private *dev_priv = dev->dev_private; |
91d1b4bd DV |
13061 | struct intel_crtc *crtc; |
13062 | struct intel_dpll_hw_state dpll_hw_state; | |
13063 | int i; | |
5358901f DV |
13064 | |
13065 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { | |
13066 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
13067 | int enabled_crtcs = 0, active_crtcs = 0; | |
13068 | bool active; | |
13069 | ||
13070 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); | |
13071 | ||
13072 | DRM_DEBUG_KMS("%s\n", pll->name); | |
13073 | ||
13074 | active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state); | |
13075 | ||
e2c719b7 | 13076 | I915_STATE_WARN(pll->active > hweight32(pll->config.crtc_mask), |
5358901f | 13077 | "more active pll users than references: %i vs %i\n", |
3e369b76 | 13078 | pll->active, hweight32(pll->config.crtc_mask)); |
e2c719b7 | 13079 | I915_STATE_WARN(pll->active && !pll->on, |
5358901f | 13080 | "pll in active use but not on in sw tracking\n"); |
e2c719b7 | 13081 | I915_STATE_WARN(pll->on && !pll->active, |
35c95375 | 13082 | "pll in on but not on in use in sw tracking\n"); |
e2c719b7 | 13083 | I915_STATE_WARN(pll->on != active, |
5358901f DV |
13084 | "pll on state mismatch (expected %i, found %i)\n", |
13085 | pll->on, active); | |
13086 | ||
d3fcc808 | 13087 | for_each_intel_crtc(dev, crtc) { |
83d65738 | 13088 | if (crtc->base.state->enable && intel_crtc_to_shared_dpll(crtc) == pll) |
5358901f DV |
13089 | enabled_crtcs++; |
13090 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) | |
13091 | active_crtcs++; | |
13092 | } | |
e2c719b7 | 13093 | I915_STATE_WARN(pll->active != active_crtcs, |
5358901f DV |
13094 | "pll active crtcs mismatch (expected %i, found %i)\n", |
13095 | pll->active, active_crtcs); | |
e2c719b7 | 13096 | I915_STATE_WARN(hweight32(pll->config.crtc_mask) != enabled_crtcs, |
5358901f | 13097 | "pll enabled crtcs mismatch (expected %i, found %i)\n", |
3e369b76 | 13098 | hweight32(pll->config.crtc_mask), enabled_crtcs); |
66e985c0 | 13099 | |
e2c719b7 | 13100 | I915_STATE_WARN(pll->on && memcmp(&pll->config.hw_state, &dpll_hw_state, |
66e985c0 DV |
13101 | sizeof(dpll_hw_state)), |
13102 | "pll hw state mismatch\n"); | |
5358901f | 13103 | } |
8af6cf88 DV |
13104 | } |
13105 | ||
ee165b1a ML |
13106 | static void |
13107 | intel_modeset_check_state(struct drm_device *dev, | |
13108 | struct drm_atomic_state *old_state) | |
91d1b4bd | 13109 | { |
08db6652 | 13110 | check_wm_state(dev); |
35dd3c64 | 13111 | check_connector_state(dev, old_state); |
91d1b4bd | 13112 | check_encoder_state(dev); |
4d20cd86 | 13113 | check_crtc_state(dev, old_state); |
91d1b4bd DV |
13114 | check_shared_dpll_state(dev); |
13115 | } | |
13116 | ||
5cec258b | 13117 | void ironlake_check_encoder_dotclock(const struct intel_crtc_state *pipe_config, |
18442d08 VS |
13118 | int dotclock) |
13119 | { | |
13120 | /* | |
13121 | * FDI already provided one idea for the dotclock. | |
13122 | * Yell if the encoder disagrees. | |
13123 | */ | |
2d112de7 | 13124 | WARN(!intel_fuzzy_clock_check(pipe_config->base.adjusted_mode.crtc_clock, dotclock), |
18442d08 | 13125 | "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", |
2d112de7 | 13126 | pipe_config->base.adjusted_mode.crtc_clock, dotclock); |
18442d08 VS |
13127 | } |
13128 | ||
80715b2f VS |
13129 | static void update_scanline_offset(struct intel_crtc *crtc) |
13130 | { | |
13131 | struct drm_device *dev = crtc->base.dev; | |
13132 | ||
13133 | /* | |
13134 | * The scanline counter increments at the leading edge of hsync. | |
13135 | * | |
13136 | * On most platforms it starts counting from vtotal-1 on the | |
13137 | * first active line. That means the scanline counter value is | |
13138 | * always one less than what we would expect. Ie. just after | |
13139 | * start of vblank, which also occurs at start of hsync (on the | |
13140 | * last active line), the scanline counter will read vblank_start-1. | |
13141 | * | |
13142 | * On gen2 the scanline counter starts counting from 1 instead | |
13143 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 | |
13144 | * to keep the value positive), instead of adding one. | |
13145 | * | |
13146 | * On HSW+ the behaviour of the scanline counter depends on the output | |
13147 | * type. For DP ports it behaves like most other platforms, but on HDMI | |
13148 | * there's an extra 1 line difference. So we need to add two instead of | |
13149 | * one to the value. | |
13150 | */ | |
13151 | if (IS_GEN2(dev)) { | |
124abe07 | 13152 | const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode; |
80715b2f VS |
13153 | int vtotal; |
13154 | ||
124abe07 VS |
13155 | vtotal = adjusted_mode->crtc_vtotal; |
13156 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) | |
80715b2f VS |
13157 | vtotal /= 2; |
13158 | ||
13159 | crtc->scanline_offset = vtotal - 1; | |
13160 | } else if (HAS_DDI(dev) && | |
409ee761 | 13161 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) { |
80715b2f VS |
13162 | crtc->scanline_offset = 2; |
13163 | } else | |
13164 | crtc->scanline_offset = 1; | |
13165 | } | |
13166 | ||
ad421372 | 13167 | static void intel_modeset_clear_plls(struct drm_atomic_state *state) |
ed6739ef | 13168 | { |
225da59b | 13169 | struct drm_device *dev = state->dev; |
ed6739ef | 13170 | struct drm_i915_private *dev_priv = to_i915(dev); |
ad421372 | 13171 | struct intel_shared_dpll_config *shared_dpll = NULL; |
0a9ab303 ACO |
13172 | struct drm_crtc *crtc; |
13173 | struct drm_crtc_state *crtc_state; | |
0a9ab303 | 13174 | int i; |
ed6739ef ACO |
13175 | |
13176 | if (!dev_priv->display.crtc_compute_clock) | |
ad421372 | 13177 | return; |
ed6739ef | 13178 | |
0a9ab303 | 13179 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
fb1a38a9 ML |
13180 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
13181 | int old_dpll = to_intel_crtc_state(crtc->state)->shared_dpll; | |
0a9ab303 | 13182 | |
fb1a38a9 | 13183 | if (!needs_modeset(crtc_state)) |
225da59b ACO |
13184 | continue; |
13185 | ||
fb1a38a9 ML |
13186 | to_intel_crtc_state(crtc_state)->shared_dpll = DPLL_ID_PRIVATE; |
13187 | ||
13188 | if (old_dpll == DPLL_ID_PRIVATE) | |
13189 | continue; | |
0a9ab303 | 13190 | |
ad421372 ML |
13191 | if (!shared_dpll) |
13192 | shared_dpll = intel_atomic_get_shared_dpll_state(state); | |
ed6739ef | 13193 | |
fb1a38a9 | 13194 | shared_dpll[old_dpll].crtc_mask &= ~(1 << intel_crtc->pipe); |
ad421372 | 13195 | } |
ed6739ef ACO |
13196 | } |
13197 | ||
99d736a2 ML |
13198 | /* |
13199 | * This implements the workaround described in the "notes" section of the mode | |
13200 | * set sequence documentation. When going from no pipes or single pipe to | |
13201 | * multiple pipes, and planes are enabled after the pipe, we need to wait at | |
13202 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. | |
13203 | */ | |
13204 | static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state) | |
13205 | { | |
13206 | struct drm_crtc_state *crtc_state; | |
13207 | struct intel_crtc *intel_crtc; | |
13208 | struct drm_crtc *crtc; | |
13209 | struct intel_crtc_state *first_crtc_state = NULL; | |
13210 | struct intel_crtc_state *other_crtc_state = NULL; | |
13211 | enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE; | |
13212 | int i; | |
13213 | ||
13214 | /* look at all crtc's that are going to be enabled in during modeset */ | |
13215 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
13216 | intel_crtc = to_intel_crtc(crtc); | |
13217 | ||
13218 | if (!crtc_state->active || !needs_modeset(crtc_state)) | |
13219 | continue; | |
13220 | ||
13221 | if (first_crtc_state) { | |
13222 | other_crtc_state = to_intel_crtc_state(crtc_state); | |
13223 | break; | |
13224 | } else { | |
13225 | first_crtc_state = to_intel_crtc_state(crtc_state); | |
13226 | first_pipe = intel_crtc->pipe; | |
13227 | } | |
13228 | } | |
13229 | ||
13230 | /* No workaround needed? */ | |
13231 | if (!first_crtc_state) | |
13232 | return 0; | |
13233 | ||
13234 | /* w/a possibly needed, check how many crtc's are already enabled. */ | |
13235 | for_each_intel_crtc(state->dev, intel_crtc) { | |
13236 | struct intel_crtc_state *pipe_config; | |
13237 | ||
13238 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); | |
13239 | if (IS_ERR(pipe_config)) | |
13240 | return PTR_ERR(pipe_config); | |
13241 | ||
13242 | pipe_config->hsw_workaround_pipe = INVALID_PIPE; | |
13243 | ||
13244 | if (!pipe_config->base.active || | |
13245 | needs_modeset(&pipe_config->base)) | |
13246 | continue; | |
13247 | ||
13248 | /* 2 or more enabled crtcs means no need for w/a */ | |
13249 | if (enabled_pipe != INVALID_PIPE) | |
13250 | return 0; | |
13251 | ||
13252 | enabled_pipe = intel_crtc->pipe; | |
13253 | } | |
13254 | ||
13255 | if (enabled_pipe != INVALID_PIPE) | |
13256 | first_crtc_state->hsw_workaround_pipe = enabled_pipe; | |
13257 | else if (other_crtc_state) | |
13258 | other_crtc_state->hsw_workaround_pipe = first_pipe; | |
13259 | ||
13260 | return 0; | |
13261 | } | |
13262 | ||
27c329ed ML |
13263 | static int intel_modeset_all_pipes(struct drm_atomic_state *state) |
13264 | { | |
13265 | struct drm_crtc *crtc; | |
13266 | struct drm_crtc_state *crtc_state; | |
13267 | int ret = 0; | |
13268 | ||
13269 | /* add all active pipes to the state */ | |
13270 | for_each_crtc(state->dev, crtc) { | |
13271 | crtc_state = drm_atomic_get_crtc_state(state, crtc); | |
13272 | if (IS_ERR(crtc_state)) | |
13273 | return PTR_ERR(crtc_state); | |
13274 | ||
13275 | if (!crtc_state->active || needs_modeset(crtc_state)) | |
13276 | continue; | |
13277 | ||
13278 | crtc_state->mode_changed = true; | |
13279 | ||
13280 | ret = drm_atomic_add_affected_connectors(state, crtc); | |
13281 | if (ret) | |
13282 | break; | |
13283 | ||
13284 | ret = drm_atomic_add_affected_planes(state, crtc); | |
13285 | if (ret) | |
13286 | break; | |
13287 | } | |
13288 | ||
13289 | return ret; | |
13290 | } | |
13291 | ||
c347a676 | 13292 | static int intel_modeset_checks(struct drm_atomic_state *state) |
054518dd | 13293 | { |
565602d7 ML |
13294 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
13295 | struct drm_i915_private *dev_priv = state->dev->dev_private; | |
13296 | struct drm_crtc *crtc; | |
13297 | struct drm_crtc_state *crtc_state; | |
13298 | int ret = 0, i; | |
054518dd | 13299 | |
b359283a ML |
13300 | if (!check_digital_port_conflicts(state)) { |
13301 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); | |
13302 | return -EINVAL; | |
13303 | } | |
13304 | ||
565602d7 ML |
13305 | intel_state->modeset = true; |
13306 | intel_state->active_crtcs = dev_priv->active_crtcs; | |
13307 | ||
13308 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
13309 | if (crtc_state->active) | |
13310 | intel_state->active_crtcs |= 1 << i; | |
13311 | else | |
13312 | intel_state->active_crtcs &= ~(1 << i); | |
13313 | } | |
13314 | ||
054518dd ACO |
13315 | /* |
13316 | * See if the config requires any additional preparation, e.g. | |
13317 | * to adjust global state with pipes off. We need to do this | |
13318 | * here so we can get the modeset_pipe updated config for the new | |
13319 | * mode set on this crtc. For other crtcs we need to use the | |
13320 | * adjusted_mode bits in the crtc directly. | |
13321 | */ | |
27c329ed | 13322 | if (dev_priv->display.modeset_calc_cdclk) { |
27c329ed ML |
13323 | ret = dev_priv->display.modeset_calc_cdclk(state); |
13324 | ||
1a617b77 | 13325 | if (!ret && intel_state->dev_cdclk != dev_priv->cdclk_freq) |
27c329ed ML |
13326 | ret = intel_modeset_all_pipes(state); |
13327 | ||
13328 | if (ret < 0) | |
054518dd | 13329 | return ret; |
e8788cbc ML |
13330 | |
13331 | DRM_DEBUG_KMS("New cdclk calculated to be atomic %u, actual %u\n", | |
13332 | intel_state->cdclk, intel_state->dev_cdclk); | |
27c329ed | 13333 | } else |
1a617b77 | 13334 | to_intel_atomic_state(state)->cdclk = dev_priv->atomic_cdclk_freq; |
054518dd | 13335 | |
ad421372 | 13336 | intel_modeset_clear_plls(state); |
054518dd | 13337 | |
565602d7 | 13338 | if (IS_HASWELL(dev_priv)) |
ad421372 | 13339 | return haswell_mode_set_planes_workaround(state); |
99d736a2 | 13340 | |
ad421372 | 13341 | return 0; |
c347a676 ACO |
13342 | } |
13343 | ||
aa363136 MR |
13344 | /* |
13345 | * Handle calculation of various watermark data at the end of the atomic check | |
13346 | * phase. The code here should be run after the per-crtc and per-plane 'check' | |
13347 | * handlers to ensure that all derived state has been updated. | |
13348 | */ | |
13349 | static void calc_watermark_data(struct drm_atomic_state *state) | |
13350 | { | |
13351 | struct drm_device *dev = state->dev; | |
13352 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); | |
13353 | struct drm_crtc *crtc; | |
13354 | struct drm_crtc_state *cstate; | |
13355 | struct drm_plane *plane; | |
13356 | struct drm_plane_state *pstate; | |
13357 | ||
13358 | /* | |
13359 | * Calculate watermark configuration details now that derived | |
13360 | * plane/crtc state is all properly updated. | |
13361 | */ | |
13362 | drm_for_each_crtc(crtc, dev) { | |
13363 | cstate = drm_atomic_get_existing_crtc_state(state, crtc) ?: | |
13364 | crtc->state; | |
13365 | ||
13366 | if (cstate->active) | |
13367 | intel_state->wm_config.num_pipes_active++; | |
13368 | } | |
13369 | drm_for_each_legacy_plane(plane, dev) { | |
13370 | pstate = drm_atomic_get_existing_plane_state(state, plane) ?: | |
13371 | plane->state; | |
13372 | ||
13373 | if (!to_intel_plane_state(pstate)->visible) | |
13374 | continue; | |
13375 | ||
13376 | intel_state->wm_config.sprites_enabled = true; | |
13377 | if (pstate->crtc_w != pstate->src_w >> 16 || | |
13378 | pstate->crtc_h != pstate->src_h >> 16) | |
13379 | intel_state->wm_config.sprites_scaled = true; | |
13380 | } | |
13381 | } | |
13382 | ||
74c090b1 ML |
13383 | /** |
13384 | * intel_atomic_check - validate state object | |
13385 | * @dev: drm device | |
13386 | * @state: state to validate | |
13387 | */ | |
13388 | static int intel_atomic_check(struct drm_device *dev, | |
13389 | struct drm_atomic_state *state) | |
c347a676 | 13390 | { |
dd8b3bdb | 13391 | struct drm_i915_private *dev_priv = to_i915(dev); |
aa363136 | 13392 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
c347a676 ACO |
13393 | struct drm_crtc *crtc; |
13394 | struct drm_crtc_state *crtc_state; | |
13395 | int ret, i; | |
61333b60 | 13396 | bool any_ms = false; |
c347a676 | 13397 | |
74c090b1 | 13398 | ret = drm_atomic_helper_check_modeset(dev, state); |
054518dd ACO |
13399 | if (ret) |
13400 | return ret; | |
13401 | ||
c347a676 | 13402 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
cfb23ed6 ML |
13403 | struct intel_crtc_state *pipe_config = |
13404 | to_intel_crtc_state(crtc_state); | |
1ed51de9 | 13405 | |
ba8af3e5 ML |
13406 | memset(&to_intel_crtc(crtc)->atomic, 0, |
13407 | sizeof(struct intel_crtc_atomic_commit)); | |
13408 | ||
1ed51de9 DV |
13409 | /* Catch I915_MODE_FLAG_INHERITED */ |
13410 | if (crtc_state->mode.private_flags != crtc->state->mode.private_flags) | |
13411 | crtc_state->mode_changed = true; | |
cfb23ed6 | 13412 | |
61333b60 ML |
13413 | if (!crtc_state->enable) { |
13414 | if (needs_modeset(crtc_state)) | |
13415 | any_ms = true; | |
c347a676 | 13416 | continue; |
61333b60 | 13417 | } |
c347a676 | 13418 | |
26495481 | 13419 | if (!needs_modeset(crtc_state)) |
cfb23ed6 ML |
13420 | continue; |
13421 | ||
26495481 DV |
13422 | /* FIXME: For only active_changed we shouldn't need to do any |
13423 | * state recomputation at all. */ | |
13424 | ||
1ed51de9 DV |
13425 | ret = drm_atomic_add_affected_connectors(state, crtc); |
13426 | if (ret) | |
13427 | return ret; | |
b359283a | 13428 | |
cfb23ed6 | 13429 | ret = intel_modeset_pipe_config(crtc, pipe_config); |
c347a676 ACO |
13430 | if (ret) |
13431 | return ret; | |
13432 | ||
73831236 | 13433 | if (i915.fastboot && |
dd8b3bdb | 13434 | intel_pipe_config_compare(dev, |
cfb23ed6 | 13435 | to_intel_crtc_state(crtc->state), |
1ed51de9 | 13436 | pipe_config, true)) { |
26495481 | 13437 | crtc_state->mode_changed = false; |
bfd16b2a | 13438 | to_intel_crtc_state(crtc_state)->update_pipe = true; |
26495481 DV |
13439 | } |
13440 | ||
13441 | if (needs_modeset(crtc_state)) { | |
13442 | any_ms = true; | |
cfb23ed6 ML |
13443 | |
13444 | ret = drm_atomic_add_affected_planes(state, crtc); | |
13445 | if (ret) | |
13446 | return ret; | |
13447 | } | |
61333b60 | 13448 | |
26495481 DV |
13449 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, |
13450 | needs_modeset(crtc_state) ? | |
13451 | "[modeset]" : "[fastset]"); | |
c347a676 ACO |
13452 | } |
13453 | ||
61333b60 ML |
13454 | if (any_ms) { |
13455 | ret = intel_modeset_checks(state); | |
13456 | ||
13457 | if (ret) | |
13458 | return ret; | |
27c329ed | 13459 | } else |
dd8b3bdb | 13460 | intel_state->cdclk = dev_priv->cdclk_freq; |
76305b1a | 13461 | |
dd8b3bdb | 13462 | ret = drm_atomic_helper_check_planes(dev, state); |
aa363136 MR |
13463 | if (ret) |
13464 | return ret; | |
13465 | ||
f51be2e0 | 13466 | intel_fbc_choose_crtc(dev_priv, state); |
aa363136 MR |
13467 | calc_watermark_data(state); |
13468 | ||
13469 | return 0; | |
054518dd ACO |
13470 | } |
13471 | ||
5008e874 ML |
13472 | static int intel_atomic_prepare_commit(struct drm_device *dev, |
13473 | struct drm_atomic_state *state, | |
13474 | bool async) | |
13475 | { | |
7580d774 ML |
13476 | struct drm_i915_private *dev_priv = dev->dev_private; |
13477 | struct drm_plane_state *plane_state; | |
5008e874 | 13478 | struct drm_crtc_state *crtc_state; |
7580d774 | 13479 | struct drm_plane *plane; |
5008e874 ML |
13480 | struct drm_crtc *crtc; |
13481 | int i, ret; | |
13482 | ||
13483 | if (async) { | |
13484 | DRM_DEBUG_KMS("i915 does not yet support async commit\n"); | |
13485 | return -EINVAL; | |
13486 | } | |
13487 | ||
13488 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
13489 | ret = intel_crtc_wait_for_pending_flips(crtc); | |
13490 | if (ret) | |
13491 | return ret; | |
7580d774 ML |
13492 | |
13493 | if (atomic_read(&to_intel_crtc(crtc)->unpin_work_count) >= 2) | |
13494 | flush_workqueue(dev_priv->wq); | |
5008e874 ML |
13495 | } |
13496 | ||
f935675f ML |
13497 | ret = mutex_lock_interruptible(&dev->struct_mutex); |
13498 | if (ret) | |
13499 | return ret; | |
13500 | ||
5008e874 | 13501 | ret = drm_atomic_helper_prepare_planes(dev, state); |
7580d774 ML |
13502 | if (!ret && !async && !i915_reset_in_progress(&dev_priv->gpu_error)) { |
13503 | u32 reset_counter; | |
13504 | ||
13505 | reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); | |
13506 | mutex_unlock(&dev->struct_mutex); | |
13507 | ||
13508 | for_each_plane_in_state(state, plane, plane_state, i) { | |
13509 | struct intel_plane_state *intel_plane_state = | |
13510 | to_intel_plane_state(plane_state); | |
13511 | ||
13512 | if (!intel_plane_state->wait_req) | |
13513 | continue; | |
13514 | ||
13515 | ret = __i915_wait_request(intel_plane_state->wait_req, | |
13516 | reset_counter, true, | |
13517 | NULL, NULL); | |
13518 | ||
13519 | /* Swallow -EIO errors to allow updates during hw lockup. */ | |
13520 | if (ret == -EIO) | |
13521 | ret = 0; | |
13522 | ||
13523 | if (ret) | |
13524 | break; | |
13525 | } | |
13526 | ||
13527 | if (!ret) | |
13528 | return 0; | |
13529 | ||
13530 | mutex_lock(&dev->struct_mutex); | |
13531 | drm_atomic_helper_cleanup_planes(dev, state); | |
13532 | } | |
5008e874 | 13533 | |
f935675f | 13534 | mutex_unlock(&dev->struct_mutex); |
5008e874 ML |
13535 | return ret; |
13536 | } | |
13537 | ||
e8861675 ML |
13538 | static void intel_atomic_wait_for_vblanks(struct drm_device *dev, |
13539 | struct drm_i915_private *dev_priv, | |
13540 | unsigned crtc_mask) | |
13541 | { | |
13542 | unsigned last_vblank_count[I915_MAX_PIPES]; | |
13543 | enum pipe pipe; | |
13544 | int ret; | |
13545 | ||
13546 | if (!crtc_mask) | |
13547 | return; | |
13548 | ||
13549 | for_each_pipe(dev_priv, pipe) { | |
13550 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
13551 | ||
13552 | if (!((1 << pipe) & crtc_mask)) | |
13553 | continue; | |
13554 | ||
13555 | ret = drm_crtc_vblank_get(crtc); | |
13556 | if (WARN_ON(ret != 0)) { | |
13557 | crtc_mask &= ~(1 << pipe); | |
13558 | continue; | |
13559 | } | |
13560 | ||
13561 | last_vblank_count[pipe] = drm_crtc_vblank_count(crtc); | |
13562 | } | |
13563 | ||
13564 | for_each_pipe(dev_priv, pipe) { | |
13565 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
13566 | long lret; | |
13567 | ||
13568 | if (!((1 << pipe) & crtc_mask)) | |
13569 | continue; | |
13570 | ||
13571 | lret = wait_event_timeout(dev->vblank[pipe].queue, | |
13572 | last_vblank_count[pipe] != | |
13573 | drm_crtc_vblank_count(crtc), | |
13574 | msecs_to_jiffies(50)); | |
13575 | ||
13576 | WARN_ON(!lret); | |
13577 | ||
13578 | drm_crtc_vblank_put(crtc); | |
13579 | } | |
13580 | } | |
13581 | ||
13582 | static bool needs_vblank_wait(struct intel_crtc_state *crtc_state) | |
13583 | { | |
13584 | /* fb updated, need to unpin old fb */ | |
13585 | if (crtc_state->fb_changed) | |
13586 | return true; | |
13587 | ||
13588 | /* wm changes, need vblank before final wm's */ | |
13589 | if (crtc_state->wm_changed) | |
13590 | return true; | |
13591 | ||
13592 | /* | |
13593 | * cxsr is re-enabled after vblank. | |
13594 | * This is already handled by crtc_state->wm_changed, | |
13595 | * but added for clarity. | |
13596 | */ | |
13597 | if (crtc_state->disable_cxsr) | |
13598 | return true; | |
13599 | ||
13600 | return false; | |
13601 | } | |
13602 | ||
74c090b1 ML |
13603 | /** |
13604 | * intel_atomic_commit - commit validated state object | |
13605 | * @dev: DRM device | |
13606 | * @state: the top-level driver state object | |
13607 | * @async: asynchronous commit | |
13608 | * | |
13609 | * This function commits a top-level state object that has been validated | |
13610 | * with drm_atomic_helper_check(). | |
13611 | * | |
13612 | * FIXME: Atomic modeset support for i915 is not yet complete. At the moment | |
13613 | * we can only handle plane-related operations and do not yet support | |
13614 | * asynchronous commit. | |
13615 | * | |
13616 | * RETURNS | |
13617 | * Zero for success or -errno. | |
13618 | */ | |
13619 | static int intel_atomic_commit(struct drm_device *dev, | |
13620 | struct drm_atomic_state *state, | |
13621 | bool async) | |
a6778b3c | 13622 | { |
565602d7 | 13623 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
fbee40df | 13624 | struct drm_i915_private *dev_priv = dev->dev_private; |
0a9ab303 | 13625 | struct drm_crtc_state *crtc_state; |
7580d774 | 13626 | struct drm_crtc *crtc; |
ed4a6a7c | 13627 | struct intel_crtc_state *intel_cstate; |
565602d7 ML |
13628 | int ret = 0, i; |
13629 | bool hw_check = intel_state->modeset; | |
33c8df89 | 13630 | unsigned long put_domains[I915_MAX_PIPES] = {}; |
e8861675 | 13631 | unsigned crtc_vblank_mask = 0; |
a6778b3c | 13632 | |
5008e874 | 13633 | ret = intel_atomic_prepare_commit(dev, state, async); |
7580d774 ML |
13634 | if (ret) { |
13635 | DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret); | |
d4afb8cc | 13636 | return ret; |
7580d774 | 13637 | } |
d4afb8cc | 13638 | |
1c5e19f8 | 13639 | drm_atomic_helper_swap_state(dev, state); |
aa363136 | 13640 | dev_priv->wm.config = to_intel_atomic_state(state)->wm_config; |
1c5e19f8 | 13641 | |
565602d7 ML |
13642 | if (intel_state->modeset) { |
13643 | memcpy(dev_priv->min_pixclk, intel_state->min_pixclk, | |
13644 | sizeof(intel_state->min_pixclk)); | |
13645 | dev_priv->active_crtcs = intel_state->active_crtcs; | |
1a617b77 | 13646 | dev_priv->atomic_cdclk_freq = intel_state->cdclk; |
33c8df89 ML |
13647 | |
13648 | intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET); | |
565602d7 ML |
13649 | } |
13650 | ||
0a9ab303 | 13651 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
a539205a ML |
13652 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
13653 | ||
33c8df89 ML |
13654 | if (needs_modeset(crtc->state) || |
13655 | to_intel_crtc_state(crtc->state)->update_pipe) { | |
13656 | hw_check = true; | |
13657 | ||
13658 | put_domains[to_intel_crtc(crtc)->pipe] = | |
13659 | modeset_get_crtc_power_domains(crtc, | |
13660 | to_intel_crtc_state(crtc->state)); | |
13661 | } | |
13662 | ||
61333b60 ML |
13663 | if (!needs_modeset(crtc->state)) |
13664 | continue; | |
13665 | ||
5c74cd73 | 13666 | intel_pre_plane_update(to_intel_crtc_state(crtc_state)); |
460da916 | 13667 | |
a539205a ML |
13668 | if (crtc_state->active) { |
13669 | intel_crtc_disable_planes(crtc, crtc_state->plane_mask); | |
13670 | dev_priv->display.crtc_disable(crtc); | |
eddfcbcd | 13671 | intel_crtc->active = false; |
58f9c0bc | 13672 | intel_fbc_disable(intel_crtc); |
eddfcbcd | 13673 | intel_disable_shared_dpll(intel_crtc); |
9bbc8258 VS |
13674 | |
13675 | /* | |
13676 | * Underruns don't always raise | |
13677 | * interrupts, so check manually. | |
13678 | */ | |
13679 | intel_check_cpu_fifo_underruns(dev_priv); | |
13680 | intel_check_pch_fifo_underruns(dev_priv); | |
b9001114 ML |
13681 | |
13682 | if (!crtc->state->active) | |
13683 | intel_update_watermarks(crtc); | |
a539205a | 13684 | } |
b8cecdf5 | 13685 | } |
7758a113 | 13686 | |
ea9d758d DV |
13687 | /* Only after disabling all output pipelines that will be changed can we |
13688 | * update the the output configuration. */ | |
4740b0f2 | 13689 | intel_modeset_update_crtc_state(state); |
f6e5b160 | 13690 | |
565602d7 | 13691 | if (intel_state->modeset) { |
4740b0f2 ML |
13692 | intel_shared_dpll_commit(state); |
13693 | ||
13694 | drm_atomic_helper_update_legacy_modeset_state(state->dev, state); | |
33c8df89 ML |
13695 | |
13696 | if (dev_priv->display.modeset_commit_cdclk && | |
13697 | intel_state->dev_cdclk != dev_priv->cdclk_freq) | |
13698 | dev_priv->display.modeset_commit_cdclk(state); | |
4740b0f2 | 13699 | } |
47fab737 | 13700 | |
a6778b3c | 13701 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
0a9ab303 | 13702 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
f6ac4b2a ML |
13703 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
13704 | bool modeset = needs_modeset(crtc->state); | |
e8861675 ML |
13705 | struct intel_crtc_state *pipe_config = |
13706 | to_intel_crtc_state(crtc->state); | |
13707 | bool update_pipe = !modeset && pipe_config->update_pipe; | |
9f836f90 | 13708 | |
f6ac4b2a | 13709 | if (modeset && crtc->state->active) { |
a539205a ML |
13710 | update_scanline_offset(to_intel_crtc(crtc)); |
13711 | dev_priv->display.crtc_enable(crtc); | |
13712 | } | |
80715b2f | 13713 | |
f6ac4b2a | 13714 | if (!modeset) |
5c74cd73 | 13715 | intel_pre_plane_update(to_intel_crtc_state(crtc_state)); |
f6ac4b2a | 13716 | |
49227c4a PZ |
13717 | if (crtc->state->active && intel_crtc->atomic.update_fbc) |
13718 | intel_fbc_enable(intel_crtc); | |
13719 | ||
6173ee28 ML |
13720 | if (crtc->state->active && |
13721 | (crtc->state->planes_changed || update_pipe)) | |
62852622 | 13722 | drm_atomic_helper_commit_planes_on_crtc(crtc_state); |
bfd16b2a | 13723 | |
e8861675 ML |
13724 | if (pipe_config->base.active && needs_vblank_wait(pipe_config)) |
13725 | crtc_vblank_mask |= 1 << i; | |
80715b2f | 13726 | } |
a6778b3c | 13727 | |
a6778b3c | 13728 | /* FIXME: add subpixel order */ |
83a57153 | 13729 | |
e8861675 ML |
13730 | if (!state->legacy_cursor_update) |
13731 | intel_atomic_wait_for_vblanks(dev, dev_priv, crtc_vblank_mask); | |
f935675f | 13732 | |
33c8df89 | 13733 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
e8861675 ML |
13734 | intel_post_plane_update(to_intel_crtc(crtc)); |
13735 | ||
33c8df89 ML |
13736 | if (put_domains[i]) |
13737 | modeset_put_power_domains(dev_priv, put_domains[i]); | |
13738 | } | |
13739 | ||
13740 | if (intel_state->modeset) | |
13741 | intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET); | |
13742 | ||
ed4a6a7c MR |
13743 | /* |
13744 | * Now that the vblank has passed, we can go ahead and program the | |
13745 | * optimal watermarks on platforms that need two-step watermark | |
13746 | * programming. | |
13747 | * | |
13748 | * TODO: Move this (and other cleanup) to an async worker eventually. | |
13749 | */ | |
13750 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
13751 | intel_cstate = to_intel_crtc_state(crtc->state); | |
13752 | ||
13753 | if (dev_priv->display.optimize_watermarks) | |
13754 | dev_priv->display.optimize_watermarks(intel_cstate); | |
13755 | } | |
13756 | ||
f935675f | 13757 | mutex_lock(&dev->struct_mutex); |
d4afb8cc | 13758 | drm_atomic_helper_cleanup_planes(dev, state); |
f935675f | 13759 | mutex_unlock(&dev->struct_mutex); |
2bfb4627 | 13760 | |
565602d7 | 13761 | if (hw_check) |
ee165b1a ML |
13762 | intel_modeset_check_state(dev, state); |
13763 | ||
13764 | drm_atomic_state_free(state); | |
f30da187 | 13765 | |
75714940 MK |
13766 | /* As one of the primary mmio accessors, KMS has a high likelihood |
13767 | * of triggering bugs in unclaimed access. After we finish | |
13768 | * modesetting, see if an error has been flagged, and if so | |
13769 | * enable debugging for the next modeset - and hope we catch | |
13770 | * the culprit. | |
13771 | * | |
13772 | * XXX note that we assume display power is on at this point. | |
13773 | * This might hold true now but we need to add pm helper to check | |
13774 | * unclaimed only when the hardware is on, as atomic commits | |
13775 | * can happen also when the device is completely off. | |
13776 | */ | |
13777 | intel_uncore_arm_unclaimed_mmio_detection(dev_priv); | |
13778 | ||
74c090b1 | 13779 | return 0; |
7f27126e JB |
13780 | } |
13781 | ||
c0c36b94 CW |
13782 | void intel_crtc_restore_mode(struct drm_crtc *crtc) |
13783 | { | |
83a57153 ACO |
13784 | struct drm_device *dev = crtc->dev; |
13785 | struct drm_atomic_state *state; | |
e694eb02 | 13786 | struct drm_crtc_state *crtc_state; |
2bfb4627 | 13787 | int ret; |
83a57153 ACO |
13788 | |
13789 | state = drm_atomic_state_alloc(dev); | |
13790 | if (!state) { | |
e694eb02 | 13791 | DRM_DEBUG_KMS("[CRTC:%d] crtc restore failed, out of memory", |
83a57153 ACO |
13792 | crtc->base.id); |
13793 | return; | |
13794 | } | |
13795 | ||
e694eb02 | 13796 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
83a57153 | 13797 | |
e694eb02 ML |
13798 | retry: |
13799 | crtc_state = drm_atomic_get_crtc_state(state, crtc); | |
13800 | ret = PTR_ERR_OR_ZERO(crtc_state); | |
13801 | if (!ret) { | |
13802 | if (!crtc_state->active) | |
13803 | goto out; | |
83a57153 | 13804 | |
e694eb02 | 13805 | crtc_state->mode_changed = true; |
74c090b1 | 13806 | ret = drm_atomic_commit(state); |
83a57153 ACO |
13807 | } |
13808 | ||
e694eb02 ML |
13809 | if (ret == -EDEADLK) { |
13810 | drm_atomic_state_clear(state); | |
13811 | drm_modeset_backoff(state->acquire_ctx); | |
13812 | goto retry; | |
4ed9fb37 | 13813 | } |
4be07317 | 13814 | |
2bfb4627 | 13815 | if (ret) |
e694eb02 | 13816 | out: |
2bfb4627 | 13817 | drm_atomic_state_free(state); |
c0c36b94 CW |
13818 | } |
13819 | ||
25c5b266 DV |
13820 | #undef for_each_intel_crtc_masked |
13821 | ||
f6e5b160 | 13822 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
f6e5b160 | 13823 | .gamma_set = intel_crtc_gamma_set, |
74c090b1 | 13824 | .set_config = drm_atomic_helper_set_config, |
f6e5b160 CW |
13825 | .destroy = intel_crtc_destroy, |
13826 | .page_flip = intel_crtc_page_flip, | |
1356837e MR |
13827 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
13828 | .atomic_destroy_state = intel_crtc_destroy_state, | |
f6e5b160 CW |
13829 | }; |
13830 | ||
5358901f DV |
13831 | static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv, |
13832 | struct intel_shared_dpll *pll, | |
13833 | struct intel_dpll_hw_state *hw_state) | |
ee7b9f93 | 13834 | { |
5358901f | 13835 | uint32_t val; |
ee7b9f93 | 13836 | |
12fda387 | 13837 | if (!intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_PLLS)) |
bd2bb1b9 PZ |
13838 | return false; |
13839 | ||
5358901f | 13840 | val = I915_READ(PCH_DPLL(pll->id)); |
66e985c0 DV |
13841 | hw_state->dpll = val; |
13842 | hw_state->fp0 = I915_READ(PCH_FP0(pll->id)); | |
13843 | hw_state->fp1 = I915_READ(PCH_FP1(pll->id)); | |
5358901f | 13844 | |
12fda387 ID |
13845 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); |
13846 | ||
5358901f DV |
13847 | return val & DPLL_VCO_ENABLE; |
13848 | } | |
13849 | ||
15bdd4cf DV |
13850 | static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv, |
13851 | struct intel_shared_dpll *pll) | |
13852 | { | |
3e369b76 ACO |
13853 | I915_WRITE(PCH_FP0(pll->id), pll->config.hw_state.fp0); |
13854 | I915_WRITE(PCH_FP1(pll->id), pll->config.hw_state.fp1); | |
15bdd4cf DV |
13855 | } |
13856 | ||
e7b903d2 DV |
13857 | static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv, |
13858 | struct intel_shared_dpll *pll) | |
13859 | { | |
e7b903d2 | 13860 | /* PCH refclock must be enabled first */ |
89eff4be | 13861 | ibx_assert_pch_refclk_enabled(dev_priv); |
e7b903d2 | 13862 | |
3e369b76 | 13863 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
15bdd4cf DV |
13864 | |
13865 | /* Wait for the clocks to stabilize. */ | |
13866 | POSTING_READ(PCH_DPLL(pll->id)); | |
13867 | udelay(150); | |
13868 | ||
13869 | /* The pixel multiplier can only be updated once the | |
13870 | * DPLL is enabled and the clocks are stable. | |
13871 | * | |
13872 | * So write it again. | |
13873 | */ | |
3e369b76 | 13874 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
15bdd4cf | 13875 | POSTING_READ(PCH_DPLL(pll->id)); |
e7b903d2 DV |
13876 | udelay(200); |
13877 | } | |
13878 | ||
13879 | static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv, | |
13880 | struct intel_shared_dpll *pll) | |
13881 | { | |
13882 | struct drm_device *dev = dev_priv->dev; | |
13883 | struct intel_crtc *crtc; | |
e7b903d2 DV |
13884 | |
13885 | /* Make sure no transcoder isn't still depending on us. */ | |
d3fcc808 | 13886 | for_each_intel_crtc(dev, crtc) { |
e7b903d2 DV |
13887 | if (intel_crtc_to_shared_dpll(crtc) == pll) |
13888 | assert_pch_transcoder_disabled(dev_priv, crtc->pipe); | |
ee7b9f93 JB |
13889 | } |
13890 | ||
15bdd4cf DV |
13891 | I915_WRITE(PCH_DPLL(pll->id), 0); |
13892 | POSTING_READ(PCH_DPLL(pll->id)); | |
e7b903d2 DV |
13893 | udelay(200); |
13894 | } | |
13895 | ||
46edb027 DV |
13896 | static char *ibx_pch_dpll_names[] = { |
13897 | "PCH DPLL A", | |
13898 | "PCH DPLL B", | |
13899 | }; | |
13900 | ||
7c74ade1 | 13901 | static void ibx_pch_dpll_init(struct drm_device *dev) |
ee7b9f93 | 13902 | { |
e7b903d2 | 13903 | struct drm_i915_private *dev_priv = dev->dev_private; |
ee7b9f93 JB |
13904 | int i; |
13905 | ||
7c74ade1 | 13906 | dev_priv->num_shared_dpll = 2; |
ee7b9f93 | 13907 | |
e72f9fbf | 13908 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
46edb027 DV |
13909 | dev_priv->shared_dplls[i].id = i; |
13910 | dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i]; | |
15bdd4cf | 13911 | dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set; |
e7b903d2 DV |
13912 | dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable; |
13913 | dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable; | |
5358901f DV |
13914 | dev_priv->shared_dplls[i].get_hw_state = |
13915 | ibx_pch_dpll_get_hw_state; | |
ee7b9f93 JB |
13916 | } |
13917 | } | |
13918 | ||
7c74ade1 DV |
13919 | static void intel_shared_dpll_init(struct drm_device *dev) |
13920 | { | |
e7b903d2 | 13921 | struct drm_i915_private *dev_priv = dev->dev_private; |
7c74ade1 | 13922 | |
9cd86933 DV |
13923 | if (HAS_DDI(dev)) |
13924 | intel_ddi_pll_init(dev); | |
13925 | else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) | |
7c74ade1 DV |
13926 | ibx_pch_dpll_init(dev); |
13927 | else | |
13928 | dev_priv->num_shared_dpll = 0; | |
13929 | ||
13930 | BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS); | |
7c74ade1 DV |
13931 | } |
13932 | ||
6beb8c23 MR |
13933 | /** |
13934 | * intel_prepare_plane_fb - Prepare fb for usage on plane | |
13935 | * @plane: drm plane to prepare for | |
13936 | * @fb: framebuffer to prepare for presentation | |
13937 | * | |
13938 | * Prepares a framebuffer for usage on a display plane. Generally this | |
13939 | * involves pinning the underlying object and updating the frontbuffer tracking | |
13940 | * bits. Some older platforms need special physical address handling for | |
13941 | * cursor planes. | |
13942 | * | |
f935675f ML |
13943 | * Must be called with struct_mutex held. |
13944 | * | |
6beb8c23 MR |
13945 | * Returns 0 on success, negative error code on failure. |
13946 | */ | |
13947 | int | |
13948 | intel_prepare_plane_fb(struct drm_plane *plane, | |
d136dfee | 13949 | const struct drm_plane_state *new_state) |
465c120c MR |
13950 | { |
13951 | struct drm_device *dev = plane->dev; | |
844f9111 | 13952 | struct drm_framebuffer *fb = new_state->fb; |
6beb8c23 | 13953 | struct intel_plane *intel_plane = to_intel_plane(plane); |
6beb8c23 | 13954 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
1ee49399 | 13955 | struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb); |
6beb8c23 | 13956 | int ret = 0; |
465c120c | 13957 | |
1ee49399 | 13958 | if (!obj && !old_obj) |
465c120c MR |
13959 | return 0; |
13960 | ||
5008e874 ML |
13961 | if (old_obj) { |
13962 | struct drm_crtc_state *crtc_state = | |
13963 | drm_atomic_get_existing_crtc_state(new_state->state, plane->state->crtc); | |
13964 | ||
13965 | /* Big Hammer, we also need to ensure that any pending | |
13966 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the | |
13967 | * current scanout is retired before unpinning the old | |
13968 | * framebuffer. Note that we rely on userspace rendering | |
13969 | * into the buffer attached to the pipe they are waiting | |
13970 | * on. If not, userspace generates a GPU hang with IPEHR | |
13971 | * point to the MI_WAIT_FOR_EVENT. | |
13972 | * | |
13973 | * This should only fail upon a hung GPU, in which case we | |
13974 | * can safely continue. | |
13975 | */ | |
13976 | if (needs_modeset(crtc_state)) | |
13977 | ret = i915_gem_object_wait_rendering(old_obj, true); | |
13978 | ||
13979 | /* Swallow -EIO errors to allow updates during hw lockup. */ | |
13980 | if (ret && ret != -EIO) | |
f935675f | 13981 | return ret; |
5008e874 ML |
13982 | } |
13983 | ||
3c28ff22 AG |
13984 | /* For framebuffer backed by dmabuf, wait for fence */ |
13985 | if (obj && obj->base.dma_buf) { | |
bcf8be27 ML |
13986 | long lret; |
13987 | ||
13988 | lret = reservation_object_wait_timeout_rcu(obj->base.dma_buf->resv, | |
13989 | false, true, | |
13990 | MAX_SCHEDULE_TIMEOUT); | |
13991 | if (lret == -ERESTARTSYS) | |
13992 | return lret; | |
3c28ff22 | 13993 | |
bcf8be27 | 13994 | WARN(lret < 0, "waiting returns %li\n", lret); |
3c28ff22 AG |
13995 | } |
13996 | ||
1ee49399 ML |
13997 | if (!obj) { |
13998 | ret = 0; | |
13999 | } else if (plane->type == DRM_PLANE_TYPE_CURSOR && | |
6beb8c23 MR |
14000 | INTEL_INFO(dev)->cursor_needs_physical) { |
14001 | int align = IS_I830(dev) ? 16 * 1024 : 256; | |
14002 | ret = i915_gem_object_attach_phys(obj, align); | |
14003 | if (ret) | |
14004 | DRM_DEBUG_KMS("failed to attach phys object\n"); | |
14005 | } else { | |
3465c580 | 14006 | ret = intel_pin_and_fence_fb_obj(fb, new_state->rotation); |
6beb8c23 | 14007 | } |
465c120c | 14008 | |
7580d774 ML |
14009 | if (ret == 0) { |
14010 | if (obj) { | |
14011 | struct intel_plane_state *plane_state = | |
14012 | to_intel_plane_state(new_state); | |
14013 | ||
14014 | i915_gem_request_assign(&plane_state->wait_req, | |
14015 | obj->last_write_req); | |
14016 | } | |
14017 | ||
a9ff8714 | 14018 | i915_gem_track_fb(old_obj, obj, intel_plane->frontbuffer_bit); |
7580d774 | 14019 | } |
fdd508a6 | 14020 | |
6beb8c23 MR |
14021 | return ret; |
14022 | } | |
14023 | ||
38f3ce3a MR |
14024 | /** |
14025 | * intel_cleanup_plane_fb - Cleans up an fb after plane use | |
14026 | * @plane: drm plane to clean up for | |
14027 | * @fb: old framebuffer that was on plane | |
14028 | * | |
14029 | * Cleans up a framebuffer that has just been removed from a plane. | |
f935675f ML |
14030 | * |
14031 | * Must be called with struct_mutex held. | |
38f3ce3a MR |
14032 | */ |
14033 | void | |
14034 | intel_cleanup_plane_fb(struct drm_plane *plane, | |
d136dfee | 14035 | const struct drm_plane_state *old_state) |
38f3ce3a MR |
14036 | { |
14037 | struct drm_device *dev = plane->dev; | |
1ee49399 | 14038 | struct intel_plane *intel_plane = to_intel_plane(plane); |
7580d774 | 14039 | struct intel_plane_state *old_intel_state; |
1ee49399 ML |
14040 | struct drm_i915_gem_object *old_obj = intel_fb_obj(old_state->fb); |
14041 | struct drm_i915_gem_object *obj = intel_fb_obj(plane->state->fb); | |
38f3ce3a | 14042 | |
7580d774 ML |
14043 | old_intel_state = to_intel_plane_state(old_state); |
14044 | ||
1ee49399 | 14045 | if (!obj && !old_obj) |
38f3ce3a MR |
14046 | return; |
14047 | ||
1ee49399 ML |
14048 | if (old_obj && (plane->type != DRM_PLANE_TYPE_CURSOR || |
14049 | !INTEL_INFO(dev)->cursor_needs_physical)) | |
3465c580 | 14050 | intel_unpin_fb_obj(old_state->fb, old_state->rotation); |
1ee49399 ML |
14051 | |
14052 | /* prepare_fb aborted? */ | |
14053 | if ((old_obj && (old_obj->frontbuffer_bits & intel_plane->frontbuffer_bit)) || | |
14054 | (obj && !(obj->frontbuffer_bits & intel_plane->frontbuffer_bit))) | |
14055 | i915_gem_track_fb(old_obj, obj, intel_plane->frontbuffer_bit); | |
7580d774 ML |
14056 | |
14057 | i915_gem_request_assign(&old_intel_state->wait_req, NULL); | |
465c120c MR |
14058 | } |
14059 | ||
6156a456 CK |
14060 | int |
14061 | skl_max_scale(struct intel_crtc *intel_crtc, struct intel_crtc_state *crtc_state) | |
14062 | { | |
14063 | int max_scale; | |
14064 | struct drm_device *dev; | |
14065 | struct drm_i915_private *dev_priv; | |
14066 | int crtc_clock, cdclk; | |
14067 | ||
bf8a0af0 | 14068 | if (!intel_crtc || !crtc_state->base.enable) |
6156a456 CK |
14069 | return DRM_PLANE_HELPER_NO_SCALING; |
14070 | ||
14071 | dev = intel_crtc->base.dev; | |
14072 | dev_priv = dev->dev_private; | |
14073 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; | |
27c329ed | 14074 | cdclk = to_intel_atomic_state(crtc_state->base.state)->cdclk; |
6156a456 | 14075 | |
54bf1ce6 | 14076 | if (WARN_ON_ONCE(!crtc_clock || cdclk < crtc_clock)) |
6156a456 CK |
14077 | return DRM_PLANE_HELPER_NO_SCALING; |
14078 | ||
14079 | /* | |
14080 | * skl max scale is lower of: | |
14081 | * close to 3 but not 3, -1 is for that purpose | |
14082 | * or | |
14083 | * cdclk/crtc_clock | |
14084 | */ | |
14085 | max_scale = min((1 << 16) * 3 - 1, (1 << 8) * ((cdclk << 8) / crtc_clock)); | |
14086 | ||
14087 | return max_scale; | |
14088 | } | |
14089 | ||
465c120c | 14090 | static int |
3c692a41 | 14091 | intel_check_primary_plane(struct drm_plane *plane, |
061e4b8d | 14092 | struct intel_crtc_state *crtc_state, |
3c692a41 GP |
14093 | struct intel_plane_state *state) |
14094 | { | |
2b875c22 MR |
14095 | struct drm_crtc *crtc = state->base.crtc; |
14096 | struct drm_framebuffer *fb = state->base.fb; | |
6156a456 | 14097 | int min_scale = DRM_PLANE_HELPER_NO_SCALING; |
061e4b8d ML |
14098 | int max_scale = DRM_PLANE_HELPER_NO_SCALING; |
14099 | bool can_position = false; | |
465c120c | 14100 | |
693bdc28 VS |
14101 | if (INTEL_INFO(plane->dev)->gen >= 9) { |
14102 | /* use scaler when colorkey is not required */ | |
14103 | if (state->ckey.flags == I915_SET_COLORKEY_NONE) { | |
14104 | min_scale = 1; | |
14105 | max_scale = skl_max_scale(to_intel_crtc(crtc), crtc_state); | |
14106 | } | |
d8106366 | 14107 | can_position = true; |
6156a456 | 14108 | } |
d8106366 | 14109 | |
061e4b8d ML |
14110 | return drm_plane_helper_check_update(plane, crtc, fb, &state->src, |
14111 | &state->dst, &state->clip, | |
da20eabd ML |
14112 | min_scale, max_scale, |
14113 | can_position, true, | |
14114 | &state->visible); | |
14af293f GP |
14115 | } |
14116 | ||
613d2b27 ML |
14117 | static void intel_begin_crtc_commit(struct drm_crtc *crtc, |
14118 | struct drm_crtc_state *old_crtc_state) | |
3c692a41 | 14119 | { |
32b7eeec | 14120 | struct drm_device *dev = crtc->dev; |
3c692a41 | 14121 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
bfd16b2a ML |
14122 | struct intel_crtc_state *old_intel_state = |
14123 | to_intel_crtc_state(old_crtc_state); | |
14124 | bool modeset = needs_modeset(crtc->state); | |
3c692a41 | 14125 | |
c34c9ee4 | 14126 | /* Perform vblank evasion around commit operation */ |
62852622 | 14127 | intel_pipe_update_start(intel_crtc); |
0583236e | 14128 | |
bfd16b2a ML |
14129 | if (modeset) |
14130 | return; | |
14131 | ||
14132 | if (to_intel_crtc_state(crtc->state)->update_pipe) | |
14133 | intel_update_pipe_config(intel_crtc, old_intel_state); | |
14134 | else if (INTEL_INFO(dev)->gen >= 9) | |
0583236e | 14135 | skl_detach_scalers(intel_crtc); |
32b7eeec MR |
14136 | } |
14137 | ||
613d2b27 ML |
14138 | static void intel_finish_crtc_commit(struct drm_crtc *crtc, |
14139 | struct drm_crtc_state *old_crtc_state) | |
32b7eeec | 14140 | { |
32b7eeec | 14141 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
32b7eeec | 14142 | |
62852622 | 14143 | intel_pipe_update_end(intel_crtc); |
3c692a41 GP |
14144 | } |
14145 | ||
cf4c7c12 | 14146 | /** |
4a3b8769 MR |
14147 | * intel_plane_destroy - destroy a plane |
14148 | * @plane: plane to destroy | |
cf4c7c12 | 14149 | * |
4a3b8769 MR |
14150 | * Common destruction function for all types of planes (primary, cursor, |
14151 | * sprite). | |
cf4c7c12 | 14152 | */ |
4a3b8769 | 14153 | void intel_plane_destroy(struct drm_plane *plane) |
465c120c MR |
14154 | { |
14155 | struct intel_plane *intel_plane = to_intel_plane(plane); | |
14156 | drm_plane_cleanup(plane); | |
14157 | kfree(intel_plane); | |
14158 | } | |
14159 | ||
65a3fea0 | 14160 | const struct drm_plane_funcs intel_plane_funcs = { |
70a101f8 MR |
14161 | .update_plane = drm_atomic_helper_update_plane, |
14162 | .disable_plane = drm_atomic_helper_disable_plane, | |
3d7d6510 | 14163 | .destroy = intel_plane_destroy, |
c196e1d6 | 14164 | .set_property = drm_atomic_helper_plane_set_property, |
a98b3431 MR |
14165 | .atomic_get_property = intel_plane_atomic_get_property, |
14166 | .atomic_set_property = intel_plane_atomic_set_property, | |
ea2c67bb MR |
14167 | .atomic_duplicate_state = intel_plane_duplicate_state, |
14168 | .atomic_destroy_state = intel_plane_destroy_state, | |
14169 | ||
465c120c MR |
14170 | }; |
14171 | ||
14172 | static struct drm_plane *intel_primary_plane_create(struct drm_device *dev, | |
14173 | int pipe) | |
14174 | { | |
14175 | struct intel_plane *primary; | |
8e7d688b | 14176 | struct intel_plane_state *state; |
465c120c | 14177 | const uint32_t *intel_primary_formats; |
45e3743a | 14178 | unsigned int num_formats; |
465c120c MR |
14179 | |
14180 | primary = kzalloc(sizeof(*primary), GFP_KERNEL); | |
14181 | if (primary == NULL) | |
14182 | return NULL; | |
14183 | ||
8e7d688b MR |
14184 | state = intel_create_plane_state(&primary->base); |
14185 | if (!state) { | |
ea2c67bb MR |
14186 | kfree(primary); |
14187 | return NULL; | |
14188 | } | |
8e7d688b | 14189 | primary->base.state = &state->base; |
ea2c67bb | 14190 | |
465c120c MR |
14191 | primary->can_scale = false; |
14192 | primary->max_downscale = 1; | |
6156a456 CK |
14193 | if (INTEL_INFO(dev)->gen >= 9) { |
14194 | primary->can_scale = true; | |
af99ceda | 14195 | state->scaler_id = -1; |
6156a456 | 14196 | } |
465c120c MR |
14197 | primary->pipe = pipe; |
14198 | primary->plane = pipe; | |
a9ff8714 | 14199 | primary->frontbuffer_bit = INTEL_FRONTBUFFER_PRIMARY(pipe); |
c59cb179 | 14200 | primary->check_plane = intel_check_primary_plane; |
465c120c MR |
14201 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) |
14202 | primary->plane = !pipe; | |
14203 | ||
6c0fd451 DL |
14204 | if (INTEL_INFO(dev)->gen >= 9) { |
14205 | intel_primary_formats = skl_primary_formats; | |
14206 | num_formats = ARRAY_SIZE(skl_primary_formats); | |
a8d201af ML |
14207 | |
14208 | primary->update_plane = skylake_update_primary_plane; | |
14209 | primary->disable_plane = skylake_disable_primary_plane; | |
14210 | } else if (HAS_PCH_SPLIT(dev)) { | |
14211 | intel_primary_formats = i965_primary_formats; | |
14212 | num_formats = ARRAY_SIZE(i965_primary_formats); | |
14213 | ||
14214 | primary->update_plane = ironlake_update_primary_plane; | |
14215 | primary->disable_plane = i9xx_disable_primary_plane; | |
6c0fd451 | 14216 | } else if (INTEL_INFO(dev)->gen >= 4) { |
568db4f2 DL |
14217 | intel_primary_formats = i965_primary_formats; |
14218 | num_formats = ARRAY_SIZE(i965_primary_formats); | |
a8d201af ML |
14219 | |
14220 | primary->update_plane = i9xx_update_primary_plane; | |
14221 | primary->disable_plane = i9xx_disable_primary_plane; | |
6c0fd451 DL |
14222 | } else { |
14223 | intel_primary_formats = i8xx_primary_formats; | |
14224 | num_formats = ARRAY_SIZE(i8xx_primary_formats); | |
a8d201af ML |
14225 | |
14226 | primary->update_plane = i9xx_update_primary_plane; | |
14227 | primary->disable_plane = i9xx_disable_primary_plane; | |
465c120c MR |
14228 | } |
14229 | ||
14230 | drm_universal_plane_init(dev, &primary->base, 0, | |
65a3fea0 | 14231 | &intel_plane_funcs, |
465c120c | 14232 | intel_primary_formats, num_formats, |
b0b3b795 | 14233 | DRM_PLANE_TYPE_PRIMARY, NULL); |
48404c1e | 14234 | |
3b7a5119 SJ |
14235 | if (INTEL_INFO(dev)->gen >= 4) |
14236 | intel_create_rotation_property(dev, primary); | |
48404c1e | 14237 | |
ea2c67bb MR |
14238 | drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs); |
14239 | ||
465c120c MR |
14240 | return &primary->base; |
14241 | } | |
14242 | ||
3b7a5119 SJ |
14243 | void intel_create_rotation_property(struct drm_device *dev, struct intel_plane *plane) |
14244 | { | |
14245 | if (!dev->mode_config.rotation_property) { | |
14246 | unsigned long flags = BIT(DRM_ROTATE_0) | | |
14247 | BIT(DRM_ROTATE_180); | |
14248 | ||
14249 | if (INTEL_INFO(dev)->gen >= 9) | |
14250 | flags |= BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270); | |
14251 | ||
14252 | dev->mode_config.rotation_property = | |
14253 | drm_mode_create_rotation_property(dev, flags); | |
14254 | } | |
14255 | if (dev->mode_config.rotation_property) | |
14256 | drm_object_attach_property(&plane->base.base, | |
14257 | dev->mode_config.rotation_property, | |
14258 | plane->base.state->rotation); | |
14259 | } | |
14260 | ||
3d7d6510 | 14261 | static int |
852e787c | 14262 | intel_check_cursor_plane(struct drm_plane *plane, |
061e4b8d | 14263 | struct intel_crtc_state *crtc_state, |
852e787c | 14264 | struct intel_plane_state *state) |
3d7d6510 | 14265 | { |
061e4b8d | 14266 | struct drm_crtc *crtc = crtc_state->base.crtc; |
2b875c22 | 14267 | struct drm_framebuffer *fb = state->base.fb; |
757f9a3e | 14268 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
b29ec92c | 14269 | enum pipe pipe = to_intel_plane(plane)->pipe; |
757f9a3e GP |
14270 | unsigned stride; |
14271 | int ret; | |
3d7d6510 | 14272 | |
061e4b8d ML |
14273 | ret = drm_plane_helper_check_update(plane, crtc, fb, &state->src, |
14274 | &state->dst, &state->clip, | |
3d7d6510 MR |
14275 | DRM_PLANE_HELPER_NO_SCALING, |
14276 | DRM_PLANE_HELPER_NO_SCALING, | |
852e787c | 14277 | true, true, &state->visible); |
757f9a3e GP |
14278 | if (ret) |
14279 | return ret; | |
14280 | ||
757f9a3e GP |
14281 | /* if we want to turn off the cursor ignore width and height */ |
14282 | if (!obj) | |
da20eabd | 14283 | return 0; |
757f9a3e | 14284 | |
757f9a3e | 14285 | /* Check for which cursor types we support */ |
061e4b8d | 14286 | if (!cursor_size_ok(plane->dev, state->base.crtc_w, state->base.crtc_h)) { |
ea2c67bb MR |
14287 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
14288 | state->base.crtc_w, state->base.crtc_h); | |
757f9a3e GP |
14289 | return -EINVAL; |
14290 | } | |
14291 | ||
ea2c67bb MR |
14292 | stride = roundup_pow_of_two(state->base.crtc_w) * 4; |
14293 | if (obj->base.size < stride * state->base.crtc_h) { | |
757f9a3e GP |
14294 | DRM_DEBUG_KMS("buffer is too small\n"); |
14295 | return -ENOMEM; | |
14296 | } | |
14297 | ||
3a656b54 | 14298 | if (fb->modifier[0] != DRM_FORMAT_MOD_NONE) { |
757f9a3e | 14299 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
da20eabd | 14300 | return -EINVAL; |
32b7eeec MR |
14301 | } |
14302 | ||
b29ec92c VS |
14303 | /* |
14304 | * There's something wrong with the cursor on CHV pipe C. | |
14305 | * If it straddles the left edge of the screen then | |
14306 | * moving it away from the edge or disabling it often | |
14307 | * results in a pipe underrun, and often that can lead to | |
14308 | * dead pipe (constant underrun reported, and it scans | |
14309 | * out just a solid color). To recover from that, the | |
14310 | * display power well must be turned off and on again. | |
14311 | * Refuse the put the cursor into that compromised position. | |
14312 | */ | |
14313 | if (IS_CHERRYVIEW(plane->dev) && pipe == PIPE_C && | |
14314 | state->visible && state->base.crtc_x < 0) { | |
14315 | DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n"); | |
14316 | return -EINVAL; | |
14317 | } | |
14318 | ||
da20eabd | 14319 | return 0; |
852e787c | 14320 | } |
3d7d6510 | 14321 | |
a8ad0d8e ML |
14322 | static void |
14323 | intel_disable_cursor_plane(struct drm_plane *plane, | |
7fabf5ef | 14324 | struct drm_crtc *crtc) |
a8ad0d8e | 14325 | { |
f2858021 ML |
14326 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
14327 | ||
14328 | intel_crtc->cursor_addr = 0; | |
55a08b3f | 14329 | intel_crtc_update_cursor(crtc, NULL); |
a8ad0d8e ML |
14330 | } |
14331 | ||
f4a2cf29 | 14332 | static void |
55a08b3f ML |
14333 | intel_update_cursor_plane(struct drm_plane *plane, |
14334 | const struct intel_crtc_state *crtc_state, | |
14335 | const struct intel_plane_state *state) | |
852e787c | 14336 | { |
55a08b3f ML |
14337 | struct drm_crtc *crtc = crtc_state->base.crtc; |
14338 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ea2c67bb | 14339 | struct drm_device *dev = plane->dev; |
2b875c22 | 14340 | struct drm_i915_gem_object *obj = intel_fb_obj(state->base.fb); |
a912f12f | 14341 | uint32_t addr; |
852e787c | 14342 | |
f4a2cf29 | 14343 | if (!obj) |
a912f12f | 14344 | addr = 0; |
f4a2cf29 | 14345 | else if (!INTEL_INFO(dev)->cursor_needs_physical) |
a912f12f | 14346 | addr = i915_gem_obj_ggtt_offset(obj); |
f4a2cf29 | 14347 | else |
a912f12f | 14348 | addr = obj->phys_handle->busaddr; |
852e787c | 14349 | |
a912f12f | 14350 | intel_crtc->cursor_addr = addr; |
55a08b3f | 14351 | intel_crtc_update_cursor(crtc, state); |
852e787c GP |
14352 | } |
14353 | ||
3d7d6510 MR |
14354 | static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev, |
14355 | int pipe) | |
14356 | { | |
14357 | struct intel_plane *cursor; | |
8e7d688b | 14358 | struct intel_plane_state *state; |
3d7d6510 MR |
14359 | |
14360 | cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); | |
14361 | if (cursor == NULL) | |
14362 | return NULL; | |
14363 | ||
8e7d688b MR |
14364 | state = intel_create_plane_state(&cursor->base); |
14365 | if (!state) { | |
ea2c67bb MR |
14366 | kfree(cursor); |
14367 | return NULL; | |
14368 | } | |
8e7d688b | 14369 | cursor->base.state = &state->base; |
ea2c67bb | 14370 | |
3d7d6510 MR |
14371 | cursor->can_scale = false; |
14372 | cursor->max_downscale = 1; | |
14373 | cursor->pipe = pipe; | |
14374 | cursor->plane = pipe; | |
a9ff8714 | 14375 | cursor->frontbuffer_bit = INTEL_FRONTBUFFER_CURSOR(pipe); |
c59cb179 | 14376 | cursor->check_plane = intel_check_cursor_plane; |
55a08b3f | 14377 | cursor->update_plane = intel_update_cursor_plane; |
a8ad0d8e | 14378 | cursor->disable_plane = intel_disable_cursor_plane; |
3d7d6510 MR |
14379 | |
14380 | drm_universal_plane_init(dev, &cursor->base, 0, | |
65a3fea0 | 14381 | &intel_plane_funcs, |
3d7d6510 MR |
14382 | intel_cursor_formats, |
14383 | ARRAY_SIZE(intel_cursor_formats), | |
b0b3b795 | 14384 | DRM_PLANE_TYPE_CURSOR, NULL); |
4398ad45 VS |
14385 | |
14386 | if (INTEL_INFO(dev)->gen >= 4) { | |
14387 | if (!dev->mode_config.rotation_property) | |
14388 | dev->mode_config.rotation_property = | |
14389 | drm_mode_create_rotation_property(dev, | |
14390 | BIT(DRM_ROTATE_0) | | |
14391 | BIT(DRM_ROTATE_180)); | |
14392 | if (dev->mode_config.rotation_property) | |
14393 | drm_object_attach_property(&cursor->base.base, | |
14394 | dev->mode_config.rotation_property, | |
8e7d688b | 14395 | state->base.rotation); |
4398ad45 VS |
14396 | } |
14397 | ||
af99ceda CK |
14398 | if (INTEL_INFO(dev)->gen >=9) |
14399 | state->scaler_id = -1; | |
14400 | ||
ea2c67bb MR |
14401 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
14402 | ||
3d7d6510 MR |
14403 | return &cursor->base; |
14404 | } | |
14405 | ||
549e2bfb CK |
14406 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
14407 | struct intel_crtc_state *crtc_state) | |
14408 | { | |
14409 | int i; | |
14410 | struct intel_scaler *intel_scaler; | |
14411 | struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state; | |
14412 | ||
14413 | for (i = 0; i < intel_crtc->num_scalers; i++) { | |
14414 | intel_scaler = &scaler_state->scalers[i]; | |
14415 | intel_scaler->in_use = 0; | |
549e2bfb CK |
14416 | intel_scaler->mode = PS_SCALER_MODE_DYN; |
14417 | } | |
14418 | ||
14419 | scaler_state->scaler_id = -1; | |
14420 | } | |
14421 | ||
b358d0a6 | 14422 | static void intel_crtc_init(struct drm_device *dev, int pipe) |
79e53945 | 14423 | { |
fbee40df | 14424 | struct drm_i915_private *dev_priv = dev->dev_private; |
79e53945 | 14425 | struct intel_crtc *intel_crtc; |
f5de6e07 | 14426 | struct intel_crtc_state *crtc_state = NULL; |
3d7d6510 MR |
14427 | struct drm_plane *primary = NULL; |
14428 | struct drm_plane *cursor = NULL; | |
465c120c | 14429 | int i, ret; |
79e53945 | 14430 | |
955382f3 | 14431 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
79e53945 JB |
14432 | if (intel_crtc == NULL) |
14433 | return; | |
14434 | ||
f5de6e07 ACO |
14435 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
14436 | if (!crtc_state) | |
14437 | goto fail; | |
550acefd ACO |
14438 | intel_crtc->config = crtc_state; |
14439 | intel_crtc->base.state = &crtc_state->base; | |
07878248 | 14440 | crtc_state->base.crtc = &intel_crtc->base; |
f5de6e07 | 14441 | |
549e2bfb CK |
14442 | /* initialize shared scalers */ |
14443 | if (INTEL_INFO(dev)->gen >= 9) { | |
14444 | if (pipe == PIPE_C) | |
14445 | intel_crtc->num_scalers = 1; | |
14446 | else | |
14447 | intel_crtc->num_scalers = SKL_NUM_SCALERS; | |
14448 | ||
14449 | skl_init_scalers(dev, intel_crtc, crtc_state); | |
14450 | } | |
14451 | ||
465c120c | 14452 | primary = intel_primary_plane_create(dev, pipe); |
3d7d6510 MR |
14453 | if (!primary) |
14454 | goto fail; | |
14455 | ||
14456 | cursor = intel_cursor_plane_create(dev, pipe); | |
14457 | if (!cursor) | |
14458 | goto fail; | |
14459 | ||
465c120c | 14460 | ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary, |
f9882876 | 14461 | cursor, &intel_crtc_funcs, NULL); |
3d7d6510 MR |
14462 | if (ret) |
14463 | goto fail; | |
79e53945 JB |
14464 | |
14465 | drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256); | |
79e53945 JB |
14466 | for (i = 0; i < 256; i++) { |
14467 | intel_crtc->lut_r[i] = i; | |
14468 | intel_crtc->lut_g[i] = i; | |
14469 | intel_crtc->lut_b[i] = i; | |
14470 | } | |
14471 | ||
1f1c2e24 VS |
14472 | /* |
14473 | * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port | |
8c0f92e1 | 14474 | * is hooked to pipe B. Hence we want plane A feeding pipe B. |
1f1c2e24 | 14475 | */ |
80824003 JB |
14476 | intel_crtc->pipe = pipe; |
14477 | intel_crtc->plane = pipe; | |
3a77c4c4 | 14478 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) { |
28c97730 | 14479 | DRM_DEBUG_KMS("swapping pipes & planes for FBC\n"); |
e2e767ab | 14480 | intel_crtc->plane = !pipe; |
80824003 JB |
14481 | } |
14482 | ||
4b0e333e CW |
14483 | intel_crtc->cursor_base = ~0; |
14484 | intel_crtc->cursor_cntl = ~0; | |
dc41c154 | 14485 | intel_crtc->cursor_size = ~0; |
8d7849db | 14486 | |
852eb00d VS |
14487 | intel_crtc->wm.cxsr_allowed = true; |
14488 | ||
22fd0fab JB |
14489 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
14490 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); | |
14491 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base; | |
14492 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base; | |
14493 | ||
79e53945 | 14494 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
87b6b101 DV |
14495 | |
14496 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); | |
3d7d6510 MR |
14497 | return; |
14498 | ||
14499 | fail: | |
14500 | if (primary) | |
14501 | drm_plane_cleanup(primary); | |
14502 | if (cursor) | |
14503 | drm_plane_cleanup(cursor); | |
f5de6e07 | 14504 | kfree(crtc_state); |
3d7d6510 | 14505 | kfree(intel_crtc); |
79e53945 JB |
14506 | } |
14507 | ||
752aa88a JB |
14508 | enum pipe intel_get_pipe_from_connector(struct intel_connector *connector) |
14509 | { | |
14510 | struct drm_encoder *encoder = connector->base.encoder; | |
6e9f798d | 14511 | struct drm_device *dev = connector->base.dev; |
752aa88a | 14512 | |
51fd371b | 14513 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
752aa88a | 14514 | |
d3babd3f | 14515 | if (!encoder || WARN_ON(!encoder->crtc)) |
752aa88a JB |
14516 | return INVALID_PIPE; |
14517 | ||
14518 | return to_intel_crtc(encoder->crtc)->pipe; | |
14519 | } | |
14520 | ||
08d7b3d1 | 14521 | int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data, |
05394f39 | 14522 | struct drm_file *file) |
08d7b3d1 | 14523 | { |
08d7b3d1 | 14524 | struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data; |
7707e653 | 14525 | struct drm_crtc *drmmode_crtc; |
c05422d5 | 14526 | struct intel_crtc *crtc; |
08d7b3d1 | 14527 | |
7707e653 | 14528 | drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id); |
08d7b3d1 | 14529 | |
7707e653 | 14530 | if (!drmmode_crtc) { |
08d7b3d1 | 14531 | DRM_ERROR("no such CRTC id\n"); |
3f2c2057 | 14532 | return -ENOENT; |
08d7b3d1 CW |
14533 | } |
14534 | ||
7707e653 | 14535 | crtc = to_intel_crtc(drmmode_crtc); |
c05422d5 | 14536 | pipe_from_crtc_id->pipe = crtc->pipe; |
08d7b3d1 | 14537 | |
c05422d5 | 14538 | return 0; |
08d7b3d1 CW |
14539 | } |
14540 | ||
66a9278e | 14541 | static int intel_encoder_clones(struct intel_encoder *encoder) |
79e53945 | 14542 | { |
66a9278e DV |
14543 | struct drm_device *dev = encoder->base.dev; |
14544 | struct intel_encoder *source_encoder; | |
79e53945 | 14545 | int index_mask = 0; |
79e53945 JB |
14546 | int entry = 0; |
14547 | ||
b2784e15 | 14548 | for_each_intel_encoder(dev, source_encoder) { |
bc079e8b | 14549 | if (encoders_cloneable(encoder, source_encoder)) |
66a9278e DV |
14550 | index_mask |= (1 << entry); |
14551 | ||
79e53945 JB |
14552 | entry++; |
14553 | } | |
4ef69c7a | 14554 | |
79e53945 JB |
14555 | return index_mask; |
14556 | } | |
14557 | ||
4d302442 CW |
14558 | static bool has_edp_a(struct drm_device *dev) |
14559 | { | |
14560 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14561 | ||
14562 | if (!IS_MOBILE(dev)) | |
14563 | return false; | |
14564 | ||
14565 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) | |
14566 | return false; | |
14567 | ||
e3589908 | 14568 | if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE)) |
4d302442 CW |
14569 | return false; |
14570 | ||
14571 | return true; | |
14572 | } | |
14573 | ||
84b4e042 JB |
14574 | static bool intel_crt_present(struct drm_device *dev) |
14575 | { | |
14576 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14577 | ||
884497ed DL |
14578 | if (INTEL_INFO(dev)->gen >= 9) |
14579 | return false; | |
14580 | ||
cf404ce4 | 14581 | if (IS_HSW_ULT(dev) || IS_BDW_ULT(dev)) |
84b4e042 JB |
14582 | return false; |
14583 | ||
14584 | if (IS_CHERRYVIEW(dev)) | |
14585 | return false; | |
14586 | ||
65e472e4 VS |
14587 | if (HAS_PCH_LPT_H(dev) && I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED) |
14588 | return false; | |
14589 | ||
70ac54d0 VS |
14590 | /* DDI E can't be used if DDI A requires 4 lanes */ |
14591 | if (HAS_DDI(dev) && I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) | |
14592 | return false; | |
14593 | ||
e4abb733 | 14594 | if (!dev_priv->vbt.int_crt_support) |
84b4e042 JB |
14595 | return false; |
14596 | ||
14597 | return true; | |
14598 | } | |
14599 | ||
79e53945 JB |
14600 | static void intel_setup_outputs(struct drm_device *dev) |
14601 | { | |
725e30ad | 14602 | struct drm_i915_private *dev_priv = dev->dev_private; |
4ef69c7a | 14603 | struct intel_encoder *encoder; |
cb0953d7 | 14604 | bool dpd_is_edp = false; |
79e53945 | 14605 | |
c9093354 | 14606 | intel_lvds_init(dev); |
79e53945 | 14607 | |
84b4e042 | 14608 | if (intel_crt_present(dev)) |
79935fca | 14609 | intel_crt_init(dev); |
cb0953d7 | 14610 | |
c776eb2e VK |
14611 | if (IS_BROXTON(dev)) { |
14612 | /* | |
14613 | * FIXME: Broxton doesn't support port detection via the | |
14614 | * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to | |
14615 | * detect the ports. | |
14616 | */ | |
14617 | intel_ddi_init(dev, PORT_A); | |
14618 | intel_ddi_init(dev, PORT_B); | |
14619 | intel_ddi_init(dev, PORT_C); | |
14620 | } else if (HAS_DDI(dev)) { | |
0e72a5b5 ED |
14621 | int found; |
14622 | ||
de31facd JB |
14623 | /* |
14624 | * Haswell uses DDI functions to detect digital outputs. | |
14625 | * On SKL pre-D0 the strap isn't connected, so we assume | |
14626 | * it's there. | |
14627 | */ | |
77179400 | 14628 | found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED; |
de31facd | 14629 | /* WaIgnoreDDIAStrap: skl */ |
ef11bdb3 | 14630 | if (found || IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
0e72a5b5 ED |
14631 | intel_ddi_init(dev, PORT_A); |
14632 | ||
14633 | /* DDI B, C and D detection is indicated by the SFUSE_STRAP | |
14634 | * register */ | |
14635 | found = I915_READ(SFUSE_STRAP); | |
14636 | ||
14637 | if (found & SFUSE_STRAP_DDIB_DETECTED) | |
14638 | intel_ddi_init(dev, PORT_B); | |
14639 | if (found & SFUSE_STRAP_DDIC_DETECTED) | |
14640 | intel_ddi_init(dev, PORT_C); | |
14641 | if (found & SFUSE_STRAP_DDID_DETECTED) | |
14642 | intel_ddi_init(dev, PORT_D); | |
2800e4c2 RV |
14643 | /* |
14644 | * On SKL we don't have a way to detect DDI-E so we rely on VBT. | |
14645 | */ | |
ef11bdb3 | 14646 | if ((IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) && |
2800e4c2 RV |
14647 | (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp || |
14648 | dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi || | |
14649 | dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi)) | |
14650 | intel_ddi_init(dev, PORT_E); | |
14651 | ||
0e72a5b5 | 14652 | } else if (HAS_PCH_SPLIT(dev)) { |
cb0953d7 | 14653 | int found; |
5d8a7752 | 14654 | dpd_is_edp = intel_dp_is_edp(dev, PORT_D); |
270b3042 DV |
14655 | |
14656 | if (has_edp_a(dev)) | |
14657 | intel_dp_init(dev, DP_A, PORT_A); | |
cb0953d7 | 14658 | |
dc0fa718 | 14659 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
461ed3ca | 14660 | /* PCH SDVOB multiplex with HDMIB */ |
2a5c0832 | 14661 | found = intel_sdvo_init(dev, PCH_SDVOB, PORT_B); |
30ad48b7 | 14662 | if (!found) |
e2debe91 | 14663 | intel_hdmi_init(dev, PCH_HDMIB, PORT_B); |
5eb08b69 | 14664 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
ab9d7c30 | 14665 | intel_dp_init(dev, PCH_DP_B, PORT_B); |
30ad48b7 ZW |
14666 | } |
14667 | ||
dc0fa718 | 14668 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
e2debe91 | 14669 | intel_hdmi_init(dev, PCH_HDMIC, PORT_C); |
30ad48b7 | 14670 | |
dc0fa718 | 14671 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
e2debe91 | 14672 | intel_hdmi_init(dev, PCH_HDMID, PORT_D); |
30ad48b7 | 14673 | |
5eb08b69 | 14674 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
ab9d7c30 | 14675 | intel_dp_init(dev, PCH_DP_C, PORT_C); |
5eb08b69 | 14676 | |
270b3042 | 14677 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
ab9d7c30 | 14678 | intel_dp_init(dev, PCH_DP_D, PORT_D); |
666a4537 | 14679 | } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
e17ac6db VS |
14680 | /* |
14681 | * The DP_DETECTED bit is the latched state of the DDC | |
14682 | * SDA pin at boot. However since eDP doesn't require DDC | |
14683 | * (no way to plug in a DP->HDMI dongle) the DDC pins for | |
14684 | * eDP ports may have been muxed to an alternate function. | |
14685 | * Thus we can't rely on the DP_DETECTED bit alone to detect | |
14686 | * eDP ports. Consult the VBT as well as DP_DETECTED to | |
14687 | * detect eDP ports. | |
14688 | */ | |
e66eb81d | 14689 | if (I915_READ(VLV_HDMIB) & SDVO_DETECTED && |
d2182a66 | 14690 | !intel_dp_is_edp(dev, PORT_B)) |
e66eb81d VS |
14691 | intel_hdmi_init(dev, VLV_HDMIB, PORT_B); |
14692 | if (I915_READ(VLV_DP_B) & DP_DETECTED || | |
e17ac6db | 14693 | intel_dp_is_edp(dev, PORT_B)) |
e66eb81d | 14694 | intel_dp_init(dev, VLV_DP_B, PORT_B); |
585a94b8 | 14695 | |
e66eb81d | 14696 | if (I915_READ(VLV_HDMIC) & SDVO_DETECTED && |
d2182a66 | 14697 | !intel_dp_is_edp(dev, PORT_C)) |
e66eb81d VS |
14698 | intel_hdmi_init(dev, VLV_HDMIC, PORT_C); |
14699 | if (I915_READ(VLV_DP_C) & DP_DETECTED || | |
e17ac6db | 14700 | intel_dp_is_edp(dev, PORT_C)) |
e66eb81d | 14701 | intel_dp_init(dev, VLV_DP_C, PORT_C); |
19c03924 | 14702 | |
9418c1f1 | 14703 | if (IS_CHERRYVIEW(dev)) { |
e17ac6db | 14704 | /* eDP not supported on port D, so don't check VBT */ |
e66eb81d VS |
14705 | if (I915_READ(CHV_HDMID) & SDVO_DETECTED) |
14706 | intel_hdmi_init(dev, CHV_HDMID, PORT_D); | |
14707 | if (I915_READ(CHV_DP_D) & DP_DETECTED) | |
14708 | intel_dp_init(dev, CHV_DP_D, PORT_D); | |
9418c1f1 VS |
14709 | } |
14710 | ||
3cfca973 | 14711 | intel_dsi_init(dev); |
09da55dc | 14712 | } else if (!IS_GEN2(dev) && !IS_PINEVIEW(dev)) { |
27185ae1 | 14713 | bool found = false; |
7d57382e | 14714 | |
e2debe91 | 14715 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
b01f2c3a | 14716 | DRM_DEBUG_KMS("probing SDVOB\n"); |
2a5c0832 | 14717 | found = intel_sdvo_init(dev, GEN3_SDVOB, PORT_B); |
3fec3d2f | 14718 | if (!found && IS_G4X(dev)) { |
b01f2c3a | 14719 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
e2debe91 | 14720 | intel_hdmi_init(dev, GEN4_HDMIB, PORT_B); |
b01f2c3a | 14721 | } |
27185ae1 | 14722 | |
3fec3d2f | 14723 | if (!found && IS_G4X(dev)) |
ab9d7c30 | 14724 | intel_dp_init(dev, DP_B, PORT_B); |
725e30ad | 14725 | } |
13520b05 KH |
14726 | |
14727 | /* Before G4X SDVOC doesn't have its own detect register */ | |
13520b05 | 14728 | |
e2debe91 | 14729 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
b01f2c3a | 14730 | DRM_DEBUG_KMS("probing SDVOC\n"); |
2a5c0832 | 14731 | found = intel_sdvo_init(dev, GEN3_SDVOC, PORT_C); |
b01f2c3a | 14732 | } |
27185ae1 | 14733 | |
e2debe91 | 14734 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
27185ae1 | 14735 | |
3fec3d2f | 14736 | if (IS_G4X(dev)) { |
b01f2c3a | 14737 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
e2debe91 | 14738 | intel_hdmi_init(dev, GEN4_HDMIC, PORT_C); |
b01f2c3a | 14739 | } |
3fec3d2f | 14740 | if (IS_G4X(dev)) |
ab9d7c30 | 14741 | intel_dp_init(dev, DP_C, PORT_C); |
725e30ad | 14742 | } |
27185ae1 | 14743 | |
3fec3d2f | 14744 | if (IS_G4X(dev) && |
e7281eab | 14745 | (I915_READ(DP_D) & DP_DETECTED)) |
ab9d7c30 | 14746 | intel_dp_init(dev, DP_D, PORT_D); |
bad720ff | 14747 | } else if (IS_GEN2(dev)) |
79e53945 JB |
14748 | intel_dvo_init(dev); |
14749 | ||
103a196f | 14750 | if (SUPPORTS_TV(dev)) |
79e53945 JB |
14751 | intel_tv_init(dev); |
14752 | ||
0bc12bcb | 14753 | intel_psr_init(dev); |
7c8f8a70 | 14754 | |
b2784e15 | 14755 | for_each_intel_encoder(dev, encoder) { |
4ef69c7a CW |
14756 | encoder->base.possible_crtcs = encoder->crtc_mask; |
14757 | encoder->base.possible_clones = | |
66a9278e | 14758 | intel_encoder_clones(encoder); |
79e53945 | 14759 | } |
47356eb6 | 14760 | |
dde86e2d | 14761 | intel_init_pch_refclk(dev); |
270b3042 DV |
14762 | |
14763 | drm_helper_move_panel_connectors_to_head(dev); | |
79e53945 JB |
14764 | } |
14765 | ||
14766 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) | |
14767 | { | |
60a5ca01 | 14768 | struct drm_device *dev = fb->dev; |
79e53945 | 14769 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
79e53945 | 14770 | |
ef2d633e | 14771 | drm_framebuffer_cleanup(fb); |
60a5ca01 | 14772 | mutex_lock(&dev->struct_mutex); |
ef2d633e | 14773 | WARN_ON(!intel_fb->obj->framebuffer_references--); |
60a5ca01 VS |
14774 | drm_gem_object_unreference(&intel_fb->obj->base); |
14775 | mutex_unlock(&dev->struct_mutex); | |
79e53945 JB |
14776 | kfree(intel_fb); |
14777 | } | |
14778 | ||
14779 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, | |
05394f39 | 14780 | struct drm_file *file, |
79e53945 JB |
14781 | unsigned int *handle) |
14782 | { | |
14783 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | |
05394f39 | 14784 | struct drm_i915_gem_object *obj = intel_fb->obj; |
79e53945 | 14785 | |
cc917ab4 CW |
14786 | if (obj->userptr.mm) { |
14787 | DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n"); | |
14788 | return -EINVAL; | |
14789 | } | |
14790 | ||
05394f39 | 14791 | return drm_gem_handle_create(file, &obj->base, handle); |
79e53945 JB |
14792 | } |
14793 | ||
86c98588 RV |
14794 | static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb, |
14795 | struct drm_file *file, | |
14796 | unsigned flags, unsigned color, | |
14797 | struct drm_clip_rect *clips, | |
14798 | unsigned num_clips) | |
14799 | { | |
14800 | struct drm_device *dev = fb->dev; | |
14801 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | |
14802 | struct drm_i915_gem_object *obj = intel_fb->obj; | |
14803 | ||
14804 | mutex_lock(&dev->struct_mutex); | |
74b4ea1e | 14805 | intel_fb_obj_flush(obj, false, ORIGIN_DIRTYFB); |
86c98588 RV |
14806 | mutex_unlock(&dev->struct_mutex); |
14807 | ||
14808 | return 0; | |
14809 | } | |
14810 | ||
79e53945 JB |
14811 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
14812 | .destroy = intel_user_framebuffer_destroy, | |
14813 | .create_handle = intel_user_framebuffer_create_handle, | |
86c98588 | 14814 | .dirty = intel_user_framebuffer_dirty, |
79e53945 JB |
14815 | }; |
14816 | ||
b321803d DL |
14817 | static |
14818 | u32 intel_fb_pitch_limit(struct drm_device *dev, uint64_t fb_modifier, | |
14819 | uint32_t pixel_format) | |
14820 | { | |
14821 | u32 gen = INTEL_INFO(dev)->gen; | |
14822 | ||
14823 | if (gen >= 9) { | |
ac484963 VS |
14824 | int cpp = drm_format_plane_cpp(pixel_format, 0); |
14825 | ||
b321803d DL |
14826 | /* "The stride in bytes must not exceed the of the size of 8K |
14827 | * pixels and 32K bytes." | |
14828 | */ | |
ac484963 | 14829 | return min(8192 * cpp, 32768); |
666a4537 | 14830 | } else if (gen >= 5 && !IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) { |
b321803d DL |
14831 | return 32*1024; |
14832 | } else if (gen >= 4) { | |
14833 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) | |
14834 | return 16*1024; | |
14835 | else | |
14836 | return 32*1024; | |
14837 | } else if (gen >= 3) { | |
14838 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) | |
14839 | return 8*1024; | |
14840 | else | |
14841 | return 16*1024; | |
14842 | } else { | |
14843 | /* XXX DSPC is limited to 4k tiled */ | |
14844 | return 8*1024; | |
14845 | } | |
14846 | } | |
14847 | ||
b5ea642a DV |
14848 | static int intel_framebuffer_init(struct drm_device *dev, |
14849 | struct intel_framebuffer *intel_fb, | |
14850 | struct drm_mode_fb_cmd2 *mode_cmd, | |
14851 | struct drm_i915_gem_object *obj) | |
79e53945 | 14852 | { |
7b49f948 | 14853 | struct drm_i915_private *dev_priv = to_i915(dev); |
6761dd31 | 14854 | unsigned int aligned_height; |
79e53945 | 14855 | int ret; |
b321803d | 14856 | u32 pitch_limit, stride_alignment; |
79e53945 | 14857 | |
dd4916c5 DV |
14858 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
14859 | ||
2a80eada DV |
14860 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
14861 | /* Enforce that fb modifier and tiling mode match, but only for | |
14862 | * X-tiled. This is needed for FBC. */ | |
14863 | if (!!(obj->tiling_mode == I915_TILING_X) != | |
14864 | !!(mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED)) { | |
14865 | DRM_DEBUG("tiling_mode doesn't match fb modifier\n"); | |
14866 | return -EINVAL; | |
14867 | } | |
14868 | } else { | |
14869 | if (obj->tiling_mode == I915_TILING_X) | |
14870 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; | |
14871 | else if (obj->tiling_mode == I915_TILING_Y) { | |
14872 | DRM_DEBUG("No Y tiling for legacy addfb\n"); | |
14873 | return -EINVAL; | |
14874 | } | |
14875 | } | |
14876 | ||
9a8f0a12 TU |
14877 | /* Passed in modifier sanity checking. */ |
14878 | switch (mode_cmd->modifier[0]) { | |
14879 | case I915_FORMAT_MOD_Y_TILED: | |
14880 | case I915_FORMAT_MOD_Yf_TILED: | |
14881 | if (INTEL_INFO(dev)->gen < 9) { | |
14882 | DRM_DEBUG("Unsupported tiling 0x%llx!\n", | |
14883 | mode_cmd->modifier[0]); | |
14884 | return -EINVAL; | |
14885 | } | |
14886 | case DRM_FORMAT_MOD_NONE: | |
14887 | case I915_FORMAT_MOD_X_TILED: | |
14888 | break; | |
14889 | default: | |
c0f40428 JB |
14890 | DRM_DEBUG("Unsupported fb modifier 0x%llx!\n", |
14891 | mode_cmd->modifier[0]); | |
57cd6508 | 14892 | return -EINVAL; |
c16ed4be | 14893 | } |
57cd6508 | 14894 | |
7b49f948 VS |
14895 | stride_alignment = intel_fb_stride_alignment(dev_priv, |
14896 | mode_cmd->modifier[0], | |
b321803d DL |
14897 | mode_cmd->pixel_format); |
14898 | if (mode_cmd->pitches[0] & (stride_alignment - 1)) { | |
14899 | DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n", | |
14900 | mode_cmd->pitches[0], stride_alignment); | |
57cd6508 | 14901 | return -EINVAL; |
c16ed4be | 14902 | } |
57cd6508 | 14903 | |
b321803d DL |
14904 | pitch_limit = intel_fb_pitch_limit(dev, mode_cmd->modifier[0], |
14905 | mode_cmd->pixel_format); | |
a35cdaa0 | 14906 | if (mode_cmd->pitches[0] > pitch_limit) { |
b321803d DL |
14907 | DRM_DEBUG("%s pitch (%u) must be at less than %d\n", |
14908 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_NONE ? | |
2a80eada | 14909 | "tiled" : "linear", |
a35cdaa0 | 14910 | mode_cmd->pitches[0], pitch_limit); |
5d7bd705 | 14911 | return -EINVAL; |
c16ed4be | 14912 | } |
5d7bd705 | 14913 | |
2a80eada | 14914 | if (mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED && |
c16ed4be CW |
14915 | mode_cmd->pitches[0] != obj->stride) { |
14916 | DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n", | |
14917 | mode_cmd->pitches[0], obj->stride); | |
5d7bd705 | 14918 | return -EINVAL; |
c16ed4be | 14919 | } |
5d7bd705 | 14920 | |
57779d06 | 14921 | /* Reject formats not supported by any plane early. */ |
308e5bcb | 14922 | switch (mode_cmd->pixel_format) { |
57779d06 | 14923 | case DRM_FORMAT_C8: |
04b3924d VS |
14924 | case DRM_FORMAT_RGB565: |
14925 | case DRM_FORMAT_XRGB8888: | |
14926 | case DRM_FORMAT_ARGB8888: | |
57779d06 VS |
14927 | break; |
14928 | case DRM_FORMAT_XRGB1555: | |
c16ed4be | 14929 | if (INTEL_INFO(dev)->gen > 3) { |
4ee62c76 VS |
14930 | DRM_DEBUG("unsupported pixel format: %s\n", |
14931 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14932 | return -EINVAL; |
c16ed4be | 14933 | } |
57779d06 | 14934 | break; |
57779d06 | 14935 | case DRM_FORMAT_ABGR8888: |
666a4537 WB |
14936 | if (!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev) && |
14937 | INTEL_INFO(dev)->gen < 9) { | |
6c0fd451 DL |
14938 | DRM_DEBUG("unsupported pixel format: %s\n", |
14939 | drm_get_format_name(mode_cmd->pixel_format)); | |
14940 | return -EINVAL; | |
14941 | } | |
14942 | break; | |
14943 | case DRM_FORMAT_XBGR8888: | |
04b3924d | 14944 | case DRM_FORMAT_XRGB2101010: |
57779d06 | 14945 | case DRM_FORMAT_XBGR2101010: |
c16ed4be | 14946 | if (INTEL_INFO(dev)->gen < 4) { |
4ee62c76 VS |
14947 | DRM_DEBUG("unsupported pixel format: %s\n", |
14948 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14949 | return -EINVAL; |
c16ed4be | 14950 | } |
b5626747 | 14951 | break; |
7531208b | 14952 | case DRM_FORMAT_ABGR2101010: |
666a4537 | 14953 | if (!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) { |
7531208b DL |
14954 | DRM_DEBUG("unsupported pixel format: %s\n", |
14955 | drm_get_format_name(mode_cmd->pixel_format)); | |
14956 | return -EINVAL; | |
14957 | } | |
14958 | break; | |
04b3924d VS |
14959 | case DRM_FORMAT_YUYV: |
14960 | case DRM_FORMAT_UYVY: | |
14961 | case DRM_FORMAT_YVYU: | |
14962 | case DRM_FORMAT_VYUY: | |
c16ed4be | 14963 | if (INTEL_INFO(dev)->gen < 5) { |
4ee62c76 VS |
14964 | DRM_DEBUG("unsupported pixel format: %s\n", |
14965 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 14966 | return -EINVAL; |
c16ed4be | 14967 | } |
57cd6508 CW |
14968 | break; |
14969 | default: | |
4ee62c76 VS |
14970 | DRM_DEBUG("unsupported pixel format: %s\n", |
14971 | drm_get_format_name(mode_cmd->pixel_format)); | |
57cd6508 CW |
14972 | return -EINVAL; |
14973 | } | |
14974 | ||
90f9a336 VS |
14975 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
14976 | if (mode_cmd->offsets[0] != 0) | |
14977 | return -EINVAL; | |
14978 | ||
ec2c981e | 14979 | aligned_height = intel_fb_align_height(dev, mode_cmd->height, |
091df6cb DV |
14980 | mode_cmd->pixel_format, |
14981 | mode_cmd->modifier[0]); | |
53155c0a DV |
14982 | /* FIXME drm helper for size checks (especially planar formats)? */ |
14983 | if (obj->base.size < aligned_height * mode_cmd->pitches[0]) | |
14984 | return -EINVAL; | |
14985 | ||
c7d73f6a DV |
14986 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); |
14987 | intel_fb->obj = obj; | |
14988 | ||
79e53945 JB |
14989 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); |
14990 | if (ret) { | |
14991 | DRM_ERROR("framebuffer init failed %d\n", ret); | |
14992 | return ret; | |
14993 | } | |
14994 | ||
0b05e1e0 VS |
14995 | intel_fb->obj->framebuffer_references++; |
14996 | ||
79e53945 JB |
14997 | return 0; |
14998 | } | |
14999 | ||
79e53945 JB |
15000 | static struct drm_framebuffer * |
15001 | intel_user_framebuffer_create(struct drm_device *dev, | |
15002 | struct drm_file *filp, | |
1eb83451 | 15003 | const struct drm_mode_fb_cmd2 *user_mode_cmd) |
79e53945 | 15004 | { |
dcb1394e | 15005 | struct drm_framebuffer *fb; |
05394f39 | 15006 | struct drm_i915_gem_object *obj; |
76dc3769 | 15007 | struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd; |
79e53945 | 15008 | |
308e5bcb | 15009 | obj = to_intel_bo(drm_gem_object_lookup(dev, filp, |
76dc3769 | 15010 | mode_cmd.handles[0])); |
c8725226 | 15011 | if (&obj->base == NULL) |
cce13ff7 | 15012 | return ERR_PTR(-ENOENT); |
79e53945 | 15013 | |
92907cbb | 15014 | fb = intel_framebuffer_create(dev, &mode_cmd, obj); |
dcb1394e LW |
15015 | if (IS_ERR(fb)) |
15016 | drm_gem_object_unreference_unlocked(&obj->base); | |
15017 | ||
15018 | return fb; | |
79e53945 JB |
15019 | } |
15020 | ||
0695726e | 15021 | #ifndef CONFIG_DRM_FBDEV_EMULATION |
0632fef6 | 15022 | static inline void intel_fbdev_output_poll_changed(struct drm_device *dev) |
4520f53a DV |
15023 | { |
15024 | } | |
15025 | #endif | |
15026 | ||
79e53945 | 15027 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
79e53945 | 15028 | .fb_create = intel_user_framebuffer_create, |
0632fef6 | 15029 | .output_poll_changed = intel_fbdev_output_poll_changed, |
5ee67f1c MR |
15030 | .atomic_check = intel_atomic_check, |
15031 | .atomic_commit = intel_atomic_commit, | |
de419ab6 ML |
15032 | .atomic_state_alloc = intel_atomic_state_alloc, |
15033 | .atomic_state_clear = intel_atomic_state_clear, | |
79e53945 JB |
15034 | }; |
15035 | ||
e70236a8 JB |
15036 | /* Set up chip specific display functions */ |
15037 | static void intel_init_display(struct drm_device *dev) | |
15038 | { | |
15039 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15040 | ||
ee9300bb DV |
15041 | if (HAS_PCH_SPLIT(dev) || IS_G4X(dev)) |
15042 | dev_priv->display.find_dpll = g4x_find_best_dpll; | |
ef9348c8 CML |
15043 | else if (IS_CHERRYVIEW(dev)) |
15044 | dev_priv->display.find_dpll = chv_find_best_dpll; | |
ee9300bb DV |
15045 | else if (IS_VALLEYVIEW(dev)) |
15046 | dev_priv->display.find_dpll = vlv_find_best_dpll; | |
15047 | else if (IS_PINEVIEW(dev)) | |
15048 | dev_priv->display.find_dpll = pnv_find_best_dpll; | |
15049 | else | |
15050 | dev_priv->display.find_dpll = i9xx_find_best_dpll; | |
15051 | ||
bc8d7dff DL |
15052 | if (INTEL_INFO(dev)->gen >= 9) { |
15053 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; | |
5724dbd1 DL |
15054 | dev_priv->display.get_initial_plane_config = |
15055 | skylake_get_initial_plane_config; | |
bc8d7dff DL |
15056 | dev_priv->display.crtc_compute_clock = |
15057 | haswell_crtc_compute_clock; | |
15058 | dev_priv->display.crtc_enable = haswell_crtc_enable; | |
15059 | dev_priv->display.crtc_disable = haswell_crtc_disable; | |
bc8d7dff | 15060 | } else if (HAS_DDI(dev)) { |
0e8ffe1b | 15061 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
5724dbd1 DL |
15062 | dev_priv->display.get_initial_plane_config = |
15063 | ironlake_get_initial_plane_config; | |
797d0259 ACO |
15064 | dev_priv->display.crtc_compute_clock = |
15065 | haswell_crtc_compute_clock; | |
4f771f10 PZ |
15066 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
15067 | dev_priv->display.crtc_disable = haswell_crtc_disable; | |
09b4ddf9 | 15068 | } else if (HAS_PCH_SPLIT(dev)) { |
0e8ffe1b | 15069 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
5724dbd1 DL |
15070 | dev_priv->display.get_initial_plane_config = |
15071 | ironlake_get_initial_plane_config; | |
3fb37703 ACO |
15072 | dev_priv->display.crtc_compute_clock = |
15073 | ironlake_crtc_compute_clock; | |
76e5a89c DV |
15074 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
15075 | dev_priv->display.crtc_disable = ironlake_crtc_disable; | |
666a4537 | 15076 | } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
89b667f8 | 15077 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
5724dbd1 DL |
15078 | dev_priv->display.get_initial_plane_config = |
15079 | i9xx_get_initial_plane_config; | |
d6dfee7a | 15080 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
89b667f8 JB |
15081 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
15082 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
f564048e | 15083 | } else { |
0e8ffe1b | 15084 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
5724dbd1 DL |
15085 | dev_priv->display.get_initial_plane_config = |
15086 | i9xx_get_initial_plane_config; | |
d6dfee7a | 15087 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
76e5a89c DV |
15088 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
15089 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
f564048e | 15090 | } |
e70236a8 | 15091 | |
e70236a8 | 15092 | /* Returns the core display clock speed */ |
ef11bdb3 | 15093 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
1652d19e VS |
15094 | dev_priv->display.get_display_clock_speed = |
15095 | skylake_get_display_clock_speed; | |
acd3f3d3 BP |
15096 | else if (IS_BROXTON(dev)) |
15097 | dev_priv->display.get_display_clock_speed = | |
15098 | broxton_get_display_clock_speed; | |
1652d19e VS |
15099 | else if (IS_BROADWELL(dev)) |
15100 | dev_priv->display.get_display_clock_speed = | |
15101 | broadwell_get_display_clock_speed; | |
15102 | else if (IS_HASWELL(dev)) | |
15103 | dev_priv->display.get_display_clock_speed = | |
15104 | haswell_get_display_clock_speed; | |
666a4537 | 15105 | else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) |
25eb05fc JB |
15106 | dev_priv->display.get_display_clock_speed = |
15107 | valleyview_get_display_clock_speed; | |
b37a6434 VS |
15108 | else if (IS_GEN5(dev)) |
15109 | dev_priv->display.get_display_clock_speed = | |
15110 | ilk_get_display_clock_speed; | |
a7c66cd8 | 15111 | else if (IS_I945G(dev) || IS_BROADWATER(dev) || |
34edce2f | 15112 | IS_GEN6(dev) || IS_IVYBRIDGE(dev)) |
e70236a8 JB |
15113 | dev_priv->display.get_display_clock_speed = |
15114 | i945_get_display_clock_speed; | |
34edce2f VS |
15115 | else if (IS_GM45(dev)) |
15116 | dev_priv->display.get_display_clock_speed = | |
15117 | gm45_get_display_clock_speed; | |
15118 | else if (IS_CRESTLINE(dev)) | |
15119 | dev_priv->display.get_display_clock_speed = | |
15120 | i965gm_get_display_clock_speed; | |
15121 | else if (IS_PINEVIEW(dev)) | |
15122 | dev_priv->display.get_display_clock_speed = | |
15123 | pnv_get_display_clock_speed; | |
15124 | else if (IS_G33(dev) || IS_G4X(dev)) | |
15125 | dev_priv->display.get_display_clock_speed = | |
15126 | g33_get_display_clock_speed; | |
e70236a8 JB |
15127 | else if (IS_I915G(dev)) |
15128 | dev_priv->display.get_display_clock_speed = | |
15129 | i915_get_display_clock_speed; | |
257a7ffc | 15130 | else if (IS_I945GM(dev) || IS_845G(dev)) |
e70236a8 JB |
15131 | dev_priv->display.get_display_clock_speed = |
15132 | i9xx_misc_get_display_clock_speed; | |
15133 | else if (IS_I915GM(dev)) | |
15134 | dev_priv->display.get_display_clock_speed = | |
15135 | i915gm_get_display_clock_speed; | |
15136 | else if (IS_I865G(dev)) | |
15137 | dev_priv->display.get_display_clock_speed = | |
15138 | i865_get_display_clock_speed; | |
f0f8a9ce | 15139 | else if (IS_I85X(dev)) |
e70236a8 | 15140 | dev_priv->display.get_display_clock_speed = |
1b1d2716 | 15141 | i85x_get_display_clock_speed; |
623e01e5 VS |
15142 | else { /* 830 */ |
15143 | WARN(!IS_I830(dev), "Unknown platform. Assuming 133 MHz CDCLK\n"); | |
e70236a8 JB |
15144 | dev_priv->display.get_display_clock_speed = |
15145 | i830_get_display_clock_speed; | |
623e01e5 | 15146 | } |
e70236a8 | 15147 | |
7c10a2b5 | 15148 | if (IS_GEN5(dev)) { |
3bb11b53 | 15149 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
3bb11b53 SJ |
15150 | } else if (IS_GEN6(dev)) { |
15151 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; | |
3bb11b53 SJ |
15152 | } else if (IS_IVYBRIDGE(dev)) { |
15153 | /* FIXME: detect B0+ stepping and use auto training */ | |
15154 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; | |
059b2fe9 | 15155 | } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
3bb11b53 | 15156 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
27c329ed ML |
15157 | if (IS_BROADWELL(dev)) { |
15158 | dev_priv->display.modeset_commit_cdclk = | |
15159 | broadwell_modeset_commit_cdclk; | |
15160 | dev_priv->display.modeset_calc_cdclk = | |
15161 | broadwell_modeset_calc_cdclk; | |
15162 | } | |
666a4537 | 15163 | } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
27c329ed ML |
15164 | dev_priv->display.modeset_commit_cdclk = |
15165 | valleyview_modeset_commit_cdclk; | |
15166 | dev_priv->display.modeset_calc_cdclk = | |
15167 | valleyview_modeset_calc_cdclk; | |
f8437dd1 | 15168 | } else if (IS_BROXTON(dev)) { |
27c329ed ML |
15169 | dev_priv->display.modeset_commit_cdclk = |
15170 | broxton_modeset_commit_cdclk; | |
15171 | dev_priv->display.modeset_calc_cdclk = | |
15172 | broxton_modeset_calc_cdclk; | |
e70236a8 | 15173 | } |
8c9f3aaf | 15174 | |
8c9f3aaf JB |
15175 | switch (INTEL_INFO(dev)->gen) { |
15176 | case 2: | |
15177 | dev_priv->display.queue_flip = intel_gen2_queue_flip; | |
15178 | break; | |
15179 | ||
15180 | case 3: | |
15181 | dev_priv->display.queue_flip = intel_gen3_queue_flip; | |
15182 | break; | |
15183 | ||
15184 | case 4: | |
15185 | case 5: | |
15186 | dev_priv->display.queue_flip = intel_gen4_queue_flip; | |
15187 | break; | |
15188 | ||
15189 | case 6: | |
15190 | dev_priv->display.queue_flip = intel_gen6_queue_flip; | |
15191 | break; | |
7c9017e5 | 15192 | case 7: |
4e0bbc31 | 15193 | case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */ |
7c9017e5 JB |
15194 | dev_priv->display.queue_flip = intel_gen7_queue_flip; |
15195 | break; | |
830c81db | 15196 | case 9: |
ba343e02 TU |
15197 | /* Drop through - unsupported since execlist only. */ |
15198 | default: | |
15199 | /* Default just returns -ENODEV to indicate unsupported */ | |
15200 | dev_priv->display.queue_flip = intel_default_queue_flip; | |
8c9f3aaf | 15201 | } |
7bd688cd | 15202 | |
e39b999a | 15203 | mutex_init(&dev_priv->pps_mutex); |
e70236a8 JB |
15204 | } |
15205 | ||
b690e96c JB |
15206 | /* |
15207 | * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend, | |
15208 | * resume, or other times. This quirk makes sure that's the case for | |
15209 | * affected systems. | |
15210 | */ | |
0206e353 | 15211 | static void quirk_pipea_force(struct drm_device *dev) |
b690e96c JB |
15212 | { |
15213 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15214 | ||
15215 | dev_priv->quirks |= QUIRK_PIPEA_FORCE; | |
bc0daf48 | 15216 | DRM_INFO("applying pipe a force quirk\n"); |
b690e96c JB |
15217 | } |
15218 | ||
b6b5d049 VS |
15219 | static void quirk_pipeb_force(struct drm_device *dev) |
15220 | { | |
15221 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15222 | ||
15223 | dev_priv->quirks |= QUIRK_PIPEB_FORCE; | |
15224 | DRM_INFO("applying pipe b force quirk\n"); | |
15225 | } | |
15226 | ||
435793df KP |
15227 | /* |
15228 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason | |
15229 | */ | |
15230 | static void quirk_ssc_force_disable(struct drm_device *dev) | |
15231 | { | |
15232 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15233 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; | |
bc0daf48 | 15234 | DRM_INFO("applying lvds SSC disable quirk\n"); |
435793df KP |
15235 | } |
15236 | ||
4dca20ef | 15237 | /* |
5a15ab5b CE |
15238 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight |
15239 | * brightness value | |
4dca20ef CE |
15240 | */ |
15241 | static void quirk_invert_brightness(struct drm_device *dev) | |
15242 | { | |
15243 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15244 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; | |
bc0daf48 | 15245 | DRM_INFO("applying inverted panel brightness quirk\n"); |
435793df KP |
15246 | } |
15247 | ||
9c72cc6f SD |
15248 | /* Some VBT's incorrectly indicate no backlight is present */ |
15249 | static void quirk_backlight_present(struct drm_device *dev) | |
15250 | { | |
15251 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15252 | dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT; | |
15253 | DRM_INFO("applying backlight present quirk\n"); | |
15254 | } | |
15255 | ||
b690e96c JB |
15256 | struct intel_quirk { |
15257 | int device; | |
15258 | int subsystem_vendor; | |
15259 | int subsystem_device; | |
15260 | void (*hook)(struct drm_device *dev); | |
15261 | }; | |
15262 | ||
5f85f176 EE |
15263 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ |
15264 | struct intel_dmi_quirk { | |
15265 | void (*hook)(struct drm_device *dev); | |
15266 | const struct dmi_system_id (*dmi_id_list)[]; | |
15267 | }; | |
15268 | ||
15269 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) | |
15270 | { | |
15271 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); | |
15272 | return 1; | |
15273 | } | |
15274 | ||
15275 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { | |
15276 | { | |
15277 | .dmi_id_list = &(const struct dmi_system_id[]) { | |
15278 | { | |
15279 | .callback = intel_dmi_reverse_brightness, | |
15280 | .ident = "NCR Corporation", | |
15281 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), | |
15282 | DMI_MATCH(DMI_PRODUCT_NAME, ""), | |
15283 | }, | |
15284 | }, | |
15285 | { } /* terminating entry */ | |
15286 | }, | |
15287 | .hook = quirk_invert_brightness, | |
15288 | }, | |
15289 | }; | |
15290 | ||
c43b5634 | 15291 | static struct intel_quirk intel_quirks[] = { |
b690e96c JB |
15292 | /* Toshiba Protege R-205, S-209 needs pipe A force quirk */ |
15293 | { 0x2592, 0x1179, 0x0001, quirk_pipea_force }, | |
15294 | ||
b690e96c JB |
15295 | /* ThinkPad T60 needs pipe A force quirk (bug #16494) */ |
15296 | { 0x2782, 0x17aa, 0x201a, quirk_pipea_force }, | |
15297 | ||
5f080c0f VS |
15298 | /* 830 needs to leave pipe A & dpll A up */ |
15299 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, | |
15300 | ||
b6b5d049 VS |
15301 | /* 830 needs to leave pipe B & dpll B up */ |
15302 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force }, | |
15303 | ||
435793df KP |
15304 | /* Lenovo U160 cannot use SSC on LVDS */ |
15305 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, | |
070d329a MAS |
15306 | |
15307 | /* Sony Vaio Y cannot use SSC on LVDS */ | |
15308 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, | |
5a15ab5b | 15309 | |
be505f64 AH |
15310 | /* Acer Aspire 5734Z must invert backlight brightness */ |
15311 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, | |
15312 | ||
15313 | /* Acer/eMachines G725 */ | |
15314 | { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness }, | |
15315 | ||
15316 | /* Acer/eMachines e725 */ | |
15317 | { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness }, | |
15318 | ||
15319 | /* Acer/Packard Bell NCL20 */ | |
15320 | { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness }, | |
15321 | ||
15322 | /* Acer Aspire 4736Z */ | |
15323 | { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness }, | |
0f540c3a JN |
15324 | |
15325 | /* Acer Aspire 5336 */ | |
15326 | { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness }, | |
2e93a1aa SD |
15327 | |
15328 | /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */ | |
15329 | { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present }, | |
d4967d8c | 15330 | |
dfb3d47b SD |
15331 | /* Acer C720 Chromebook (Core i3 4005U) */ |
15332 | { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present }, | |
15333 | ||
b2a9601c | 15334 | /* Apple Macbook 2,1 (Core 2 T7400) */ |
15335 | { 0x27a2, 0x8086, 0x7270, quirk_backlight_present }, | |
15336 | ||
1b9448b0 JN |
15337 | /* Apple Macbook 4,1 */ |
15338 | { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present }, | |
15339 | ||
d4967d8c SD |
15340 | /* Toshiba CB35 Chromebook (Celeron 2955U) */ |
15341 | { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present }, | |
724cb06f SD |
15342 | |
15343 | /* HP Chromebook 14 (Celeron 2955U) */ | |
15344 | { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present }, | |
cf6f0af9 JN |
15345 | |
15346 | /* Dell Chromebook 11 */ | |
15347 | { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present }, | |
9be64eee JN |
15348 | |
15349 | /* Dell Chromebook 11 (2015 version) */ | |
15350 | { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present }, | |
b690e96c JB |
15351 | }; |
15352 | ||
15353 | static void intel_init_quirks(struct drm_device *dev) | |
15354 | { | |
15355 | struct pci_dev *d = dev->pdev; | |
15356 | int i; | |
15357 | ||
15358 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { | |
15359 | struct intel_quirk *q = &intel_quirks[i]; | |
15360 | ||
15361 | if (d->device == q->device && | |
15362 | (d->subsystem_vendor == q->subsystem_vendor || | |
15363 | q->subsystem_vendor == PCI_ANY_ID) && | |
15364 | (d->subsystem_device == q->subsystem_device || | |
15365 | q->subsystem_device == PCI_ANY_ID)) | |
15366 | q->hook(dev); | |
15367 | } | |
5f85f176 EE |
15368 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { |
15369 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) | |
15370 | intel_dmi_quirks[i].hook(dev); | |
15371 | } | |
b690e96c JB |
15372 | } |
15373 | ||
9cce37f4 JB |
15374 | /* Disable the VGA plane that we never use */ |
15375 | static void i915_disable_vga(struct drm_device *dev) | |
15376 | { | |
15377 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15378 | u8 sr1; | |
f0f59a00 | 15379 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev); |
9cce37f4 | 15380 | |
2b37c616 | 15381 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
9cce37f4 | 15382 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
3fdcf431 | 15383 | outb(SR01, VGA_SR_INDEX); |
9cce37f4 JB |
15384 | sr1 = inb(VGA_SR_DATA); |
15385 | outb(sr1 | 1<<5, VGA_SR_DATA); | |
15386 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); | |
15387 | udelay(300); | |
15388 | ||
01f5a626 | 15389 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
9cce37f4 JB |
15390 | POSTING_READ(vga_reg); |
15391 | } | |
15392 | ||
f817586c DV |
15393 | void intel_modeset_init_hw(struct drm_device *dev) |
15394 | { | |
1a617b77 ML |
15395 | struct drm_i915_private *dev_priv = dev->dev_private; |
15396 | ||
b6283055 | 15397 | intel_update_cdclk(dev); |
1a617b77 ML |
15398 | |
15399 | dev_priv->atomic_cdclk_freq = dev_priv->cdclk_freq; | |
15400 | ||
f817586c | 15401 | intel_init_clock_gating(dev); |
8090c6b9 | 15402 | intel_enable_gt_powersave(dev); |
f817586c DV |
15403 | } |
15404 | ||
d93c0372 MR |
15405 | /* |
15406 | * Calculate what we think the watermarks should be for the state we've read | |
15407 | * out of the hardware and then immediately program those watermarks so that | |
15408 | * we ensure the hardware settings match our internal state. | |
15409 | * | |
15410 | * We can calculate what we think WM's should be by creating a duplicate of the | |
15411 | * current state (which was constructed during hardware readout) and running it | |
15412 | * through the atomic check code to calculate new watermark values in the | |
15413 | * state object. | |
15414 | */ | |
15415 | static void sanitize_watermarks(struct drm_device *dev) | |
15416 | { | |
15417 | struct drm_i915_private *dev_priv = to_i915(dev); | |
15418 | struct drm_atomic_state *state; | |
15419 | struct drm_crtc *crtc; | |
15420 | struct drm_crtc_state *cstate; | |
15421 | struct drm_modeset_acquire_ctx ctx; | |
15422 | int ret; | |
15423 | int i; | |
15424 | ||
15425 | /* Only supported on platforms that use atomic watermark design */ | |
ed4a6a7c | 15426 | if (!dev_priv->display.optimize_watermarks) |
d93c0372 MR |
15427 | return; |
15428 | ||
15429 | /* | |
15430 | * We need to hold connection_mutex before calling duplicate_state so | |
15431 | * that the connector loop is protected. | |
15432 | */ | |
15433 | drm_modeset_acquire_init(&ctx, 0); | |
15434 | retry: | |
0cd1262d | 15435 | ret = drm_modeset_lock_all_ctx(dev, &ctx); |
d93c0372 MR |
15436 | if (ret == -EDEADLK) { |
15437 | drm_modeset_backoff(&ctx); | |
15438 | goto retry; | |
15439 | } else if (WARN_ON(ret)) { | |
0cd1262d | 15440 | goto fail; |
d93c0372 MR |
15441 | } |
15442 | ||
15443 | state = drm_atomic_helper_duplicate_state(dev, &ctx); | |
15444 | if (WARN_ON(IS_ERR(state))) | |
0cd1262d | 15445 | goto fail; |
d93c0372 | 15446 | |
ed4a6a7c MR |
15447 | /* |
15448 | * Hardware readout is the only time we don't want to calculate | |
15449 | * intermediate watermarks (since we don't trust the current | |
15450 | * watermarks). | |
15451 | */ | |
15452 | to_intel_atomic_state(state)->skip_intermediate_wm = true; | |
15453 | ||
d93c0372 MR |
15454 | ret = intel_atomic_check(dev, state); |
15455 | if (ret) { | |
15456 | /* | |
15457 | * If we fail here, it means that the hardware appears to be | |
15458 | * programmed in a way that shouldn't be possible, given our | |
15459 | * understanding of watermark requirements. This might mean a | |
15460 | * mistake in the hardware readout code or a mistake in the | |
15461 | * watermark calculations for a given platform. Raise a WARN | |
15462 | * so that this is noticeable. | |
15463 | * | |
15464 | * If this actually happens, we'll have to just leave the | |
15465 | * BIOS-programmed watermarks untouched and hope for the best. | |
15466 | */ | |
15467 | WARN(true, "Could not determine valid watermarks for inherited state\n"); | |
0cd1262d | 15468 | goto fail; |
d93c0372 MR |
15469 | } |
15470 | ||
15471 | /* Write calculated watermark values back */ | |
15472 | to_i915(dev)->wm.config = to_intel_atomic_state(state)->wm_config; | |
15473 | for_each_crtc_in_state(state, crtc, cstate, i) { | |
15474 | struct intel_crtc_state *cs = to_intel_crtc_state(cstate); | |
15475 | ||
ed4a6a7c MR |
15476 | cs->wm.need_postvbl_update = true; |
15477 | dev_priv->display.optimize_watermarks(cs); | |
d93c0372 MR |
15478 | } |
15479 | ||
15480 | drm_atomic_state_free(state); | |
0cd1262d | 15481 | fail: |
d93c0372 MR |
15482 | drm_modeset_drop_locks(&ctx); |
15483 | drm_modeset_acquire_fini(&ctx); | |
15484 | } | |
15485 | ||
79e53945 JB |
15486 | void intel_modeset_init(struct drm_device *dev) |
15487 | { | |
652c393a | 15488 | struct drm_i915_private *dev_priv = dev->dev_private; |
1fe47785 | 15489 | int sprite, ret; |
8cc87b75 | 15490 | enum pipe pipe; |
46f297fb | 15491 | struct intel_crtc *crtc; |
79e53945 JB |
15492 | |
15493 | drm_mode_config_init(dev); | |
15494 | ||
15495 | dev->mode_config.min_width = 0; | |
15496 | dev->mode_config.min_height = 0; | |
15497 | ||
019d96cb DA |
15498 | dev->mode_config.preferred_depth = 24; |
15499 | dev->mode_config.prefer_shadow = 1; | |
15500 | ||
25bab385 TU |
15501 | dev->mode_config.allow_fb_modifiers = true; |
15502 | ||
e6ecefaa | 15503 | dev->mode_config.funcs = &intel_mode_funcs; |
79e53945 | 15504 | |
b690e96c JB |
15505 | intel_init_quirks(dev); |
15506 | ||
1fa61106 ED |
15507 | intel_init_pm(dev); |
15508 | ||
e3c74757 BW |
15509 | if (INTEL_INFO(dev)->num_pipes == 0) |
15510 | return; | |
15511 | ||
69f92f67 LW |
15512 | /* |
15513 | * There may be no VBT; and if the BIOS enabled SSC we can | |
15514 | * just keep using it to avoid unnecessary flicker. Whereas if the | |
15515 | * BIOS isn't using it, don't assume it will work even if the VBT | |
15516 | * indicates as much. | |
15517 | */ | |
15518 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) { | |
15519 | bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & | |
15520 | DREF_SSC1_ENABLE); | |
15521 | ||
15522 | if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) { | |
15523 | DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n", | |
15524 | bios_lvds_use_ssc ? "en" : "dis", | |
15525 | dev_priv->vbt.lvds_use_ssc ? "en" : "dis"); | |
15526 | dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc; | |
15527 | } | |
15528 | } | |
15529 | ||
e70236a8 | 15530 | intel_init_display(dev); |
7c10a2b5 | 15531 | intel_init_audio(dev); |
e70236a8 | 15532 | |
a6c45cf0 CW |
15533 | if (IS_GEN2(dev)) { |
15534 | dev->mode_config.max_width = 2048; | |
15535 | dev->mode_config.max_height = 2048; | |
15536 | } else if (IS_GEN3(dev)) { | |
5e4d6fa7 KP |
15537 | dev->mode_config.max_width = 4096; |
15538 | dev->mode_config.max_height = 4096; | |
79e53945 | 15539 | } else { |
a6c45cf0 CW |
15540 | dev->mode_config.max_width = 8192; |
15541 | dev->mode_config.max_height = 8192; | |
79e53945 | 15542 | } |
068be561 | 15543 | |
dc41c154 VS |
15544 | if (IS_845G(dev) || IS_I865G(dev)) { |
15545 | dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512; | |
15546 | dev->mode_config.cursor_height = 1023; | |
15547 | } else if (IS_GEN2(dev)) { | |
068be561 DL |
15548 | dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH; |
15549 | dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT; | |
15550 | } else { | |
15551 | dev->mode_config.cursor_width = MAX_CURSOR_WIDTH; | |
15552 | dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT; | |
15553 | } | |
15554 | ||
5d4545ae | 15555 | dev->mode_config.fb_base = dev_priv->gtt.mappable_base; |
79e53945 | 15556 | |
28c97730 | 15557 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
7eb552ae BW |
15558 | INTEL_INFO(dev)->num_pipes, |
15559 | INTEL_INFO(dev)->num_pipes > 1 ? "s" : ""); | |
79e53945 | 15560 | |
055e393f | 15561 | for_each_pipe(dev_priv, pipe) { |
8cc87b75 | 15562 | intel_crtc_init(dev, pipe); |
3bdcfc0c | 15563 | for_each_sprite(dev_priv, pipe, sprite) { |
1fe47785 | 15564 | ret = intel_plane_init(dev, pipe, sprite); |
7f1f3851 | 15565 | if (ret) |
06da8da2 | 15566 | DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n", |
1fe47785 | 15567 | pipe_name(pipe), sprite_name(pipe, sprite), ret); |
7f1f3851 | 15568 | } |
79e53945 JB |
15569 | } |
15570 | ||
bfa7df01 VS |
15571 | intel_update_czclk(dev_priv); |
15572 | intel_update_cdclk(dev); | |
15573 | ||
e72f9fbf | 15574 | intel_shared_dpll_init(dev); |
ee7b9f93 | 15575 | |
9cce37f4 JB |
15576 | /* Just disable it once at startup */ |
15577 | i915_disable_vga(dev); | |
79e53945 | 15578 | intel_setup_outputs(dev); |
11be49eb | 15579 | |
6e9f798d | 15580 | drm_modeset_lock_all(dev); |
043e9bda | 15581 | intel_modeset_setup_hw_state(dev); |
6e9f798d | 15582 | drm_modeset_unlock_all(dev); |
46f297fb | 15583 | |
d3fcc808 | 15584 | for_each_intel_crtc(dev, crtc) { |
eeebeac5 ML |
15585 | struct intel_initial_plane_config plane_config = {}; |
15586 | ||
46f297fb JB |
15587 | if (!crtc->active) |
15588 | continue; | |
15589 | ||
46f297fb | 15590 | /* |
46f297fb JB |
15591 | * Note that reserving the BIOS fb up front prevents us |
15592 | * from stuffing other stolen allocations like the ring | |
15593 | * on top. This prevents some ugliness at boot time, and | |
15594 | * can even allow for smooth boot transitions if the BIOS | |
15595 | * fb is large enough for the active pipe configuration. | |
15596 | */ | |
eeebeac5 ML |
15597 | dev_priv->display.get_initial_plane_config(crtc, |
15598 | &plane_config); | |
15599 | ||
15600 | /* | |
15601 | * If the fb is shared between multiple heads, we'll | |
15602 | * just get the first one. | |
15603 | */ | |
15604 | intel_find_initial_plane_obj(crtc, &plane_config); | |
46f297fb | 15605 | } |
d93c0372 MR |
15606 | |
15607 | /* | |
15608 | * Make sure hardware watermarks really match the state we read out. | |
15609 | * Note that we need to do this after reconstructing the BIOS fb's | |
15610 | * since the watermark calculation done here will use pstate->fb. | |
15611 | */ | |
15612 | sanitize_watermarks(dev); | |
2c7111db CW |
15613 | } |
15614 | ||
7fad798e DV |
15615 | static void intel_enable_pipe_a(struct drm_device *dev) |
15616 | { | |
15617 | struct intel_connector *connector; | |
15618 | struct drm_connector *crt = NULL; | |
15619 | struct intel_load_detect_pipe load_detect_temp; | |
208bf9fd | 15620 | struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx; |
7fad798e DV |
15621 | |
15622 | /* We can't just switch on the pipe A, we need to set things up with a | |
15623 | * proper mode and output configuration. As a gross hack, enable pipe A | |
15624 | * by enabling the load detect pipe once. */ | |
3a3371ff | 15625 | for_each_intel_connector(dev, connector) { |
7fad798e DV |
15626 | if (connector->encoder->type == INTEL_OUTPUT_ANALOG) { |
15627 | crt = &connector->base; | |
15628 | break; | |
15629 | } | |
15630 | } | |
15631 | ||
15632 | if (!crt) | |
15633 | return; | |
15634 | ||
208bf9fd | 15635 | if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, ctx)) |
49172fee | 15636 | intel_release_load_detect_pipe(crt, &load_detect_temp, ctx); |
7fad798e DV |
15637 | } |
15638 | ||
fa555837 DV |
15639 | static bool |
15640 | intel_check_plane_mapping(struct intel_crtc *crtc) | |
15641 | { | |
7eb552ae BW |
15642 | struct drm_device *dev = crtc->base.dev; |
15643 | struct drm_i915_private *dev_priv = dev->dev_private; | |
649636ef | 15644 | u32 val; |
fa555837 | 15645 | |
7eb552ae | 15646 | if (INTEL_INFO(dev)->num_pipes == 1) |
fa555837 DV |
15647 | return true; |
15648 | ||
649636ef | 15649 | val = I915_READ(DSPCNTR(!crtc->plane)); |
fa555837 DV |
15650 | |
15651 | if ((val & DISPLAY_PLANE_ENABLE) && | |
15652 | (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe)) | |
15653 | return false; | |
15654 | ||
15655 | return true; | |
15656 | } | |
15657 | ||
02e93c35 VS |
15658 | static bool intel_crtc_has_encoders(struct intel_crtc *crtc) |
15659 | { | |
15660 | struct drm_device *dev = crtc->base.dev; | |
15661 | struct intel_encoder *encoder; | |
15662 | ||
15663 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) | |
15664 | return true; | |
15665 | ||
15666 | return false; | |
15667 | } | |
15668 | ||
dd756198 VS |
15669 | static bool intel_encoder_has_connectors(struct intel_encoder *encoder) |
15670 | { | |
15671 | struct drm_device *dev = encoder->base.dev; | |
15672 | struct intel_connector *connector; | |
15673 | ||
15674 | for_each_connector_on_encoder(dev, &encoder->base, connector) | |
15675 | return true; | |
15676 | ||
15677 | return false; | |
15678 | } | |
15679 | ||
24929352 DV |
15680 | static void intel_sanitize_crtc(struct intel_crtc *crtc) |
15681 | { | |
15682 | struct drm_device *dev = crtc->base.dev; | |
15683 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f0f59a00 | 15684 | i915_reg_t reg = PIPECONF(crtc->config->cpu_transcoder); |
24929352 | 15685 | |
24929352 | 15686 | /* Clear any frame start delays used for debugging left by the BIOS */ |
24929352 DV |
15687 | I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
15688 | ||
d3eaf884 | 15689 | /* restore vblank interrupts to correct state */ |
9625604c | 15690 | drm_crtc_vblank_reset(&crtc->base); |
d297e103 | 15691 | if (crtc->active) { |
f9cd7b88 VS |
15692 | struct intel_plane *plane; |
15693 | ||
9625604c | 15694 | drm_crtc_vblank_on(&crtc->base); |
f9cd7b88 VS |
15695 | |
15696 | /* Disable everything but the primary plane */ | |
15697 | for_each_intel_plane_on_crtc(dev, crtc, plane) { | |
15698 | if (plane->base.type == DRM_PLANE_TYPE_PRIMARY) | |
15699 | continue; | |
15700 | ||
15701 | plane->disable_plane(&plane->base, &crtc->base); | |
15702 | } | |
9625604c | 15703 | } |
d3eaf884 | 15704 | |
24929352 | 15705 | /* We need to sanitize the plane -> pipe mapping first because this will |
fa555837 DV |
15706 | * disable the crtc (and hence change the state) if it is wrong. Note |
15707 | * that gen4+ has a fixed plane -> pipe mapping. */ | |
15708 | if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) { | |
24929352 DV |
15709 | bool plane; |
15710 | ||
24929352 DV |
15711 | DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n", |
15712 | crtc->base.base.id); | |
15713 | ||
15714 | /* Pipe has the wrong plane attached and the plane is active. | |
15715 | * Temporarily change the plane mapping and disable everything | |
15716 | * ... */ | |
15717 | plane = crtc->plane; | |
b70709a6 | 15718 | to_intel_plane_state(crtc->base.primary->state)->visible = true; |
24929352 | 15719 | crtc->plane = !plane; |
b17d48e2 | 15720 | intel_crtc_disable_noatomic(&crtc->base); |
24929352 | 15721 | crtc->plane = plane; |
24929352 | 15722 | } |
24929352 | 15723 | |
7fad798e DV |
15724 | if (dev_priv->quirks & QUIRK_PIPEA_FORCE && |
15725 | crtc->pipe == PIPE_A && !crtc->active) { | |
15726 | /* BIOS forgot to enable pipe A, this mostly happens after | |
15727 | * resume. Force-enable the pipe to fix this, the update_dpms | |
15728 | * call below we restore the pipe to the right state, but leave | |
15729 | * the required bits on. */ | |
15730 | intel_enable_pipe_a(dev); | |
15731 | } | |
15732 | ||
24929352 DV |
15733 | /* Adjust the state of the output pipe according to whether we |
15734 | * have active connectors/encoders. */ | |
02e93c35 | 15735 | if (!intel_crtc_has_encoders(crtc)) |
b17d48e2 | 15736 | intel_crtc_disable_noatomic(&crtc->base); |
24929352 | 15737 | |
53d9f4e9 | 15738 | if (crtc->active != crtc->base.state->active) { |
02e93c35 | 15739 | struct intel_encoder *encoder; |
24929352 DV |
15740 | |
15741 | /* This can happen either due to bugs in the get_hw_state | |
b17d48e2 ML |
15742 | * functions or because of calls to intel_crtc_disable_noatomic, |
15743 | * or because the pipe is force-enabled due to the | |
24929352 DV |
15744 | * pipe A quirk. */ |
15745 | DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n", | |
15746 | crtc->base.base.id, | |
83d65738 | 15747 | crtc->base.state->enable ? "enabled" : "disabled", |
24929352 DV |
15748 | crtc->active ? "enabled" : "disabled"); |
15749 | ||
4be40c98 | 15750 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, NULL) < 0); |
49d6fa21 | 15751 | crtc->base.state->active = crtc->active; |
24929352 | 15752 | crtc->base.enabled = crtc->active; |
2aa974c9 | 15753 | crtc->base.state->connector_mask = 0; |
e87a52b3 | 15754 | crtc->base.state->encoder_mask = 0; |
24929352 DV |
15755 | |
15756 | /* Because we only establish the connector -> encoder -> | |
15757 | * crtc links if something is active, this means the | |
15758 | * crtc is now deactivated. Break the links. connector | |
15759 | * -> encoder links are only establish when things are | |
15760 | * actually up, hence no need to break them. */ | |
15761 | WARN_ON(crtc->active); | |
15762 | ||
2d406bb0 | 15763 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
24929352 | 15764 | encoder->base.crtc = NULL; |
24929352 | 15765 | } |
c5ab3bc0 | 15766 | |
a3ed6aad | 15767 | if (crtc->active || HAS_GMCH_DISPLAY(dev)) { |
4cc31489 DV |
15768 | /* |
15769 | * We start out with underrun reporting disabled to avoid races. | |
15770 | * For correct bookkeeping mark this on active crtcs. | |
15771 | * | |
c5ab3bc0 DV |
15772 | * Also on gmch platforms we dont have any hardware bits to |
15773 | * disable the underrun reporting. Which means we need to start | |
15774 | * out with underrun reporting disabled also on inactive pipes, | |
15775 | * since otherwise we'll complain about the garbage we read when | |
15776 | * e.g. coming up after runtime pm. | |
15777 | * | |
4cc31489 DV |
15778 | * No protection against concurrent access is required - at |
15779 | * worst a fifo underrun happens which also sets this to false. | |
15780 | */ | |
15781 | crtc->cpu_fifo_underrun_disabled = true; | |
15782 | crtc->pch_fifo_underrun_disabled = true; | |
15783 | } | |
24929352 DV |
15784 | } |
15785 | ||
15786 | static void intel_sanitize_encoder(struct intel_encoder *encoder) | |
15787 | { | |
15788 | struct intel_connector *connector; | |
15789 | struct drm_device *dev = encoder->base.dev; | |
15790 | ||
15791 | /* We need to check both for a crtc link (meaning that the | |
15792 | * encoder is active and trying to read from a pipe) and the | |
15793 | * pipe itself being active. */ | |
15794 | bool has_active_crtc = encoder->base.crtc && | |
15795 | to_intel_crtc(encoder->base.crtc)->active; | |
15796 | ||
dd756198 | 15797 | if (intel_encoder_has_connectors(encoder) && !has_active_crtc) { |
24929352 DV |
15798 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
15799 | encoder->base.base.id, | |
8e329a03 | 15800 | encoder->base.name); |
24929352 DV |
15801 | |
15802 | /* Connector is active, but has no active pipe. This is | |
15803 | * fallout from our resume register restoring. Disable | |
15804 | * the encoder manually again. */ | |
15805 | if (encoder->base.crtc) { | |
15806 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", | |
15807 | encoder->base.base.id, | |
8e329a03 | 15808 | encoder->base.name); |
24929352 | 15809 | encoder->disable(encoder); |
a62d1497 VS |
15810 | if (encoder->post_disable) |
15811 | encoder->post_disable(encoder); | |
24929352 | 15812 | } |
7f1950fb | 15813 | encoder->base.crtc = NULL; |
24929352 DV |
15814 | |
15815 | /* Inconsistent output/port/pipe state happens presumably due to | |
15816 | * a bug in one of the get_hw_state functions. Or someplace else | |
15817 | * in our code, like the register restore mess on resume. Clamp | |
15818 | * things to off as a safer default. */ | |
3a3371ff | 15819 | for_each_intel_connector(dev, connector) { |
24929352 DV |
15820 | if (connector->encoder != encoder) |
15821 | continue; | |
7f1950fb EE |
15822 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
15823 | connector->base.encoder = NULL; | |
24929352 DV |
15824 | } |
15825 | } | |
15826 | /* Enabled encoders without active connectors will be fixed in | |
15827 | * the crtc fixup. */ | |
15828 | } | |
15829 | ||
04098753 | 15830 | void i915_redisable_vga_power_on(struct drm_device *dev) |
0fde901f KM |
15831 | { |
15832 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f0f59a00 | 15833 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev); |
0fde901f | 15834 | |
04098753 ID |
15835 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
15836 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); | |
15837 | i915_disable_vga(dev); | |
15838 | } | |
15839 | } | |
15840 | ||
15841 | void i915_redisable_vga(struct drm_device *dev) | |
15842 | { | |
15843 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15844 | ||
8dc8a27c PZ |
15845 | /* This function can be called both from intel_modeset_setup_hw_state or |
15846 | * at a very early point in our resume sequence, where the power well | |
15847 | * structures are not yet restored. Since this function is at a very | |
15848 | * paranoid "someone might have enabled VGA while we were not looking" | |
15849 | * level, just check if the power well is enabled instead of trying to | |
15850 | * follow the "don't touch the power well if we don't need it" policy | |
15851 | * the rest of the driver uses. */ | |
6392f847 | 15852 | if (!intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_VGA)) |
8dc8a27c PZ |
15853 | return; |
15854 | ||
04098753 | 15855 | i915_redisable_vga_power_on(dev); |
6392f847 ID |
15856 | |
15857 | intel_display_power_put(dev_priv, POWER_DOMAIN_VGA); | |
0fde901f KM |
15858 | } |
15859 | ||
f9cd7b88 | 15860 | static bool primary_get_hw_state(struct intel_plane *plane) |
98ec7739 | 15861 | { |
f9cd7b88 | 15862 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
98ec7739 | 15863 | |
f9cd7b88 | 15864 | return I915_READ(DSPCNTR(plane->plane)) & DISPLAY_PLANE_ENABLE; |
d032ffa0 ML |
15865 | } |
15866 | ||
f9cd7b88 VS |
15867 | /* FIXME read out full plane state for all planes */ |
15868 | static void readout_plane_state(struct intel_crtc *crtc) | |
d032ffa0 | 15869 | { |
b26d3ea3 | 15870 | struct drm_plane *primary = crtc->base.primary; |
f9cd7b88 | 15871 | struct intel_plane_state *plane_state = |
b26d3ea3 | 15872 | to_intel_plane_state(primary->state); |
d032ffa0 | 15873 | |
19b8d387 | 15874 | plane_state->visible = crtc->active && |
b26d3ea3 ML |
15875 | primary_get_hw_state(to_intel_plane(primary)); |
15876 | ||
15877 | if (plane_state->visible) | |
15878 | crtc->base.state->plane_mask |= 1 << drm_plane_index(primary); | |
98ec7739 VS |
15879 | } |
15880 | ||
30e984df | 15881 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
24929352 DV |
15882 | { |
15883 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15884 | enum pipe pipe; | |
24929352 DV |
15885 | struct intel_crtc *crtc; |
15886 | struct intel_encoder *encoder; | |
15887 | struct intel_connector *connector; | |
5358901f | 15888 | int i; |
24929352 | 15889 | |
565602d7 ML |
15890 | dev_priv->active_crtcs = 0; |
15891 | ||
d3fcc808 | 15892 | for_each_intel_crtc(dev, crtc) { |
565602d7 ML |
15893 | struct intel_crtc_state *crtc_state = crtc->config; |
15894 | int pixclk = 0; | |
3b117c8f | 15895 | |
565602d7 ML |
15896 | __drm_atomic_helper_crtc_destroy_state(&crtc->base, &crtc_state->base); |
15897 | memset(crtc_state, 0, sizeof(*crtc_state)); | |
15898 | crtc_state->base.crtc = &crtc->base; | |
24929352 | 15899 | |
565602d7 ML |
15900 | crtc_state->base.active = crtc_state->base.enable = |
15901 | dev_priv->display.get_pipe_config(crtc, crtc_state); | |
15902 | ||
15903 | crtc->base.enabled = crtc_state->base.enable; | |
15904 | crtc->active = crtc_state->base.active; | |
15905 | ||
15906 | if (crtc_state->base.active) { | |
15907 | dev_priv->active_crtcs |= 1 << crtc->pipe; | |
15908 | ||
15909 | if (IS_BROADWELL(dev_priv)) { | |
15910 | pixclk = ilk_pipe_pixel_rate(crtc_state); | |
15911 | ||
15912 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ | |
15913 | if (crtc_state->ips_enabled) | |
15914 | pixclk = DIV_ROUND_UP(pixclk * 100, 95); | |
15915 | } else if (IS_VALLEYVIEW(dev_priv) || | |
15916 | IS_CHERRYVIEW(dev_priv) || | |
15917 | IS_BROXTON(dev_priv)) | |
15918 | pixclk = crtc_state->base.adjusted_mode.crtc_clock; | |
15919 | else | |
15920 | WARN_ON(dev_priv->display.modeset_calc_cdclk); | |
15921 | } | |
15922 | ||
15923 | dev_priv->min_pixclk[crtc->pipe] = pixclk; | |
b70709a6 | 15924 | |
f9cd7b88 | 15925 | readout_plane_state(crtc); |
24929352 DV |
15926 | |
15927 | DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n", | |
15928 | crtc->base.base.id, | |
15929 | crtc->active ? "enabled" : "disabled"); | |
15930 | } | |
15931 | ||
5358901f DV |
15932 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
15933 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
15934 | ||
3e369b76 ACO |
15935 | pll->on = pll->get_hw_state(dev_priv, pll, |
15936 | &pll->config.hw_state); | |
5358901f | 15937 | pll->active = 0; |
3e369b76 | 15938 | pll->config.crtc_mask = 0; |
d3fcc808 | 15939 | for_each_intel_crtc(dev, crtc) { |
1e6f2ddc | 15940 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) { |
5358901f | 15941 | pll->active++; |
3e369b76 | 15942 | pll->config.crtc_mask |= 1 << crtc->pipe; |
1e6f2ddc | 15943 | } |
5358901f | 15944 | } |
5358901f | 15945 | |
1e6f2ddc | 15946 | DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n", |
3e369b76 | 15947 | pll->name, pll->config.crtc_mask, pll->on); |
bd2bb1b9 | 15948 | |
3e369b76 | 15949 | if (pll->config.crtc_mask) |
bd2bb1b9 | 15950 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
5358901f DV |
15951 | } |
15952 | ||
b2784e15 | 15953 | for_each_intel_encoder(dev, encoder) { |
24929352 DV |
15954 | pipe = 0; |
15955 | ||
15956 | if (encoder->get_hw_state(encoder, &pipe)) { | |
045ac3b5 JB |
15957 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
15958 | encoder->base.crtc = &crtc->base; | |
6e3c9717 | 15959 | encoder->get_config(encoder, crtc->config); |
24929352 DV |
15960 | } else { |
15961 | encoder->base.crtc = NULL; | |
15962 | } | |
15963 | ||
6f2bcceb | 15964 | DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n", |
24929352 | 15965 | encoder->base.base.id, |
8e329a03 | 15966 | encoder->base.name, |
24929352 | 15967 | encoder->base.crtc ? "enabled" : "disabled", |
6f2bcceb | 15968 | pipe_name(pipe)); |
24929352 DV |
15969 | } |
15970 | ||
3a3371ff | 15971 | for_each_intel_connector(dev, connector) { |
24929352 DV |
15972 | if (connector->get_hw_state(connector)) { |
15973 | connector->base.dpms = DRM_MODE_DPMS_ON; | |
2aa974c9 ML |
15974 | |
15975 | encoder = connector->encoder; | |
15976 | connector->base.encoder = &encoder->base; | |
15977 | ||
15978 | if (encoder->base.crtc && | |
15979 | encoder->base.crtc->state->active) { | |
15980 | /* | |
15981 | * This has to be done during hardware readout | |
15982 | * because anything calling .crtc_disable may | |
15983 | * rely on the connector_mask being accurate. | |
15984 | */ | |
15985 | encoder->base.crtc->state->connector_mask |= | |
15986 | 1 << drm_connector_index(&connector->base); | |
e87a52b3 ML |
15987 | encoder->base.crtc->state->encoder_mask |= |
15988 | 1 << drm_encoder_index(&encoder->base); | |
2aa974c9 ML |
15989 | } |
15990 | ||
24929352 DV |
15991 | } else { |
15992 | connector->base.dpms = DRM_MODE_DPMS_OFF; | |
15993 | connector->base.encoder = NULL; | |
15994 | } | |
15995 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", | |
15996 | connector->base.base.id, | |
c23cc417 | 15997 | connector->base.name, |
24929352 DV |
15998 | connector->base.encoder ? "enabled" : "disabled"); |
15999 | } | |
7f4c6284 VS |
16000 | |
16001 | for_each_intel_crtc(dev, crtc) { | |
16002 | crtc->base.hwmode = crtc->config->base.adjusted_mode; | |
16003 | ||
16004 | memset(&crtc->base.mode, 0, sizeof(crtc->base.mode)); | |
16005 | if (crtc->base.state->active) { | |
16006 | intel_mode_from_pipe_config(&crtc->base.mode, crtc->config); | |
16007 | intel_mode_from_pipe_config(&crtc->base.state->adjusted_mode, crtc->config); | |
16008 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode)); | |
16009 | ||
16010 | /* | |
16011 | * The initial mode needs to be set in order to keep | |
16012 | * the atomic core happy. It wants a valid mode if the | |
16013 | * crtc's enabled, so we do the above call. | |
16014 | * | |
16015 | * At this point some state updated by the connectors | |
16016 | * in their ->detect() callback has not run yet, so | |
16017 | * no recalculation can be done yet. | |
16018 | * | |
16019 | * Even if we could do a recalculation and modeset | |
16020 | * right now it would cause a double modeset if | |
16021 | * fbdev or userspace chooses a different initial mode. | |
16022 | * | |
16023 | * If that happens, someone indicated they wanted a | |
16024 | * mode change, which means it's safe to do a full | |
16025 | * recalculation. | |
16026 | */ | |
16027 | crtc->base.state->mode.private_flags = I915_MODE_FLAG_INHERITED; | |
9eca6832 VS |
16028 | |
16029 | drm_calc_timestamping_constants(&crtc->base, &crtc->base.hwmode); | |
16030 | update_scanline_offset(crtc); | |
7f4c6284 VS |
16031 | } |
16032 | } | |
30e984df DV |
16033 | } |
16034 | ||
043e9bda ML |
16035 | /* Scan out the current hw modeset state, |
16036 | * and sanitizes it to the current state | |
16037 | */ | |
16038 | static void | |
16039 | intel_modeset_setup_hw_state(struct drm_device *dev) | |
30e984df DV |
16040 | { |
16041 | struct drm_i915_private *dev_priv = dev->dev_private; | |
16042 | enum pipe pipe; | |
30e984df DV |
16043 | struct intel_crtc *crtc; |
16044 | struct intel_encoder *encoder; | |
35c95375 | 16045 | int i; |
30e984df DV |
16046 | |
16047 | intel_modeset_readout_hw_state(dev); | |
24929352 DV |
16048 | |
16049 | /* HW state is read out, now we need to sanitize this mess. */ | |
b2784e15 | 16050 | for_each_intel_encoder(dev, encoder) { |
24929352 DV |
16051 | intel_sanitize_encoder(encoder); |
16052 | } | |
16053 | ||
055e393f | 16054 | for_each_pipe(dev_priv, pipe) { |
24929352 DV |
16055 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
16056 | intel_sanitize_crtc(crtc); | |
6e3c9717 ACO |
16057 | intel_dump_pipe_config(crtc, crtc->config, |
16058 | "[setup_hw_state]"); | |
24929352 | 16059 | } |
9a935856 | 16060 | |
d29b2f9d ACO |
16061 | intel_modeset_update_connector_atomic_state(dev); |
16062 | ||
35c95375 DV |
16063 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
16064 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
16065 | ||
16066 | if (!pll->on || pll->active) | |
16067 | continue; | |
16068 | ||
16069 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name); | |
16070 | ||
16071 | pll->disable(dev_priv, pll); | |
16072 | pll->on = false; | |
16073 | } | |
16074 | ||
666a4537 | 16075 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) |
6eb1a681 VS |
16076 | vlv_wm_get_hw_state(dev); |
16077 | else if (IS_GEN9(dev)) | |
3078999f PB |
16078 | skl_wm_get_hw_state(dev); |
16079 | else if (HAS_PCH_SPLIT(dev)) | |
243e6a44 | 16080 | ilk_wm_get_hw_state(dev); |
292b990e ML |
16081 | |
16082 | for_each_intel_crtc(dev, crtc) { | |
16083 | unsigned long put_domains; | |
16084 | ||
74bff5f9 | 16085 | put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc->config); |
292b990e ML |
16086 | if (WARN_ON(put_domains)) |
16087 | modeset_put_power_domains(dev_priv, put_domains); | |
16088 | } | |
16089 | intel_display_set_init_power(dev_priv, false); | |
010cf73d PZ |
16090 | |
16091 | intel_fbc_init_pipe_state(dev_priv); | |
043e9bda | 16092 | } |
7d0bc1ea | 16093 | |
043e9bda ML |
16094 | void intel_display_resume(struct drm_device *dev) |
16095 | { | |
e2c8b870 ML |
16096 | struct drm_i915_private *dev_priv = to_i915(dev); |
16097 | struct drm_atomic_state *state = dev_priv->modeset_restore_state; | |
16098 | struct drm_modeset_acquire_ctx ctx; | |
043e9bda | 16099 | int ret; |
e2c8b870 | 16100 | bool setup = false; |
f30da187 | 16101 | |
e2c8b870 | 16102 | dev_priv->modeset_restore_state = NULL; |
043e9bda | 16103 | |
ea49c9ac ML |
16104 | /* |
16105 | * This is a cludge because with real atomic modeset mode_config.mutex | |
16106 | * won't be taken. Unfortunately some probed state like | |
16107 | * audio_codec_enable is still protected by mode_config.mutex, so lock | |
16108 | * it here for now. | |
16109 | */ | |
16110 | mutex_lock(&dev->mode_config.mutex); | |
e2c8b870 | 16111 | drm_modeset_acquire_init(&ctx, 0); |
043e9bda | 16112 | |
e2c8b870 ML |
16113 | retry: |
16114 | ret = drm_modeset_lock_all_ctx(dev, &ctx); | |
043e9bda | 16115 | |
e2c8b870 ML |
16116 | if (ret == 0 && !setup) { |
16117 | setup = true; | |
043e9bda | 16118 | |
e2c8b870 ML |
16119 | intel_modeset_setup_hw_state(dev); |
16120 | i915_redisable_vga(dev); | |
45e2b5f6 | 16121 | } |
8af6cf88 | 16122 | |
e2c8b870 ML |
16123 | if (ret == 0 && state) { |
16124 | struct drm_crtc_state *crtc_state; | |
16125 | struct drm_crtc *crtc; | |
16126 | int i; | |
043e9bda | 16127 | |
e2c8b870 ML |
16128 | state->acquire_ctx = &ctx; |
16129 | ||
16130 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
16131 | /* | |
16132 | * Force recalculation even if we restore | |
16133 | * current state. With fast modeset this may not result | |
16134 | * in a modeset when the state is compatible. | |
16135 | */ | |
16136 | crtc_state->mode_changed = true; | |
16137 | } | |
16138 | ||
16139 | ret = drm_atomic_commit(state); | |
043e9bda ML |
16140 | } |
16141 | ||
e2c8b870 ML |
16142 | if (ret == -EDEADLK) { |
16143 | drm_modeset_backoff(&ctx); | |
16144 | goto retry; | |
16145 | } | |
043e9bda | 16146 | |
e2c8b870 ML |
16147 | drm_modeset_drop_locks(&ctx); |
16148 | drm_modeset_acquire_fini(&ctx); | |
ea49c9ac | 16149 | mutex_unlock(&dev->mode_config.mutex); |
043e9bda | 16150 | |
e2c8b870 ML |
16151 | if (ret) { |
16152 | DRM_ERROR("Restoring old state failed with %i\n", ret); | |
16153 | drm_atomic_state_free(state); | |
16154 | } | |
2c7111db CW |
16155 | } |
16156 | ||
16157 | void intel_modeset_gem_init(struct drm_device *dev) | |
16158 | { | |
484b41dd | 16159 | struct drm_crtc *c; |
2ff8fde1 | 16160 | struct drm_i915_gem_object *obj; |
e0d6149b | 16161 | int ret; |
484b41dd | 16162 | |
ae48434c | 16163 | intel_init_gt_powersave(dev); |
ae48434c | 16164 | |
1833b134 | 16165 | intel_modeset_init_hw(dev); |
02e792fb DV |
16166 | |
16167 | intel_setup_overlay(dev); | |
484b41dd JB |
16168 | |
16169 | /* | |
16170 | * Make sure any fbs we allocated at startup are properly | |
16171 | * pinned & fenced. When we do the allocation it's too early | |
16172 | * for this. | |
16173 | */ | |
70e1e0ec | 16174 | for_each_crtc(dev, c) { |
2ff8fde1 MR |
16175 | obj = intel_fb_obj(c->primary->fb); |
16176 | if (obj == NULL) | |
484b41dd JB |
16177 | continue; |
16178 | ||
e0d6149b | 16179 | mutex_lock(&dev->struct_mutex); |
3465c580 VS |
16180 | ret = intel_pin_and_fence_fb_obj(c->primary->fb, |
16181 | c->primary->state->rotation); | |
e0d6149b TU |
16182 | mutex_unlock(&dev->struct_mutex); |
16183 | if (ret) { | |
484b41dd JB |
16184 | DRM_ERROR("failed to pin boot fb on pipe %d\n", |
16185 | to_intel_crtc(c)->pipe); | |
66e514c1 DA |
16186 | drm_framebuffer_unreference(c->primary->fb); |
16187 | c->primary->fb = NULL; | |
36750f28 | 16188 | c->primary->crtc = c->primary->state->crtc = NULL; |
afd65eb4 | 16189 | update_state_fb(c->primary); |
36750f28 | 16190 | c->state->plane_mask &= ~(1 << drm_plane_index(c->primary)); |
484b41dd JB |
16191 | } |
16192 | } | |
0962c3c9 VS |
16193 | |
16194 | intel_backlight_register(dev); | |
79e53945 JB |
16195 | } |
16196 | ||
4932e2c3 ID |
16197 | void intel_connector_unregister(struct intel_connector *intel_connector) |
16198 | { | |
16199 | struct drm_connector *connector = &intel_connector->base; | |
16200 | ||
16201 | intel_panel_destroy_backlight(connector); | |
34ea3d38 | 16202 | drm_connector_unregister(connector); |
4932e2c3 ID |
16203 | } |
16204 | ||
79e53945 JB |
16205 | void intel_modeset_cleanup(struct drm_device *dev) |
16206 | { | |
652c393a | 16207 | struct drm_i915_private *dev_priv = dev->dev_private; |
19c8054c | 16208 | struct intel_connector *connector; |
652c393a | 16209 | |
2eb5252e ID |
16210 | intel_disable_gt_powersave(dev); |
16211 | ||
0962c3c9 VS |
16212 | intel_backlight_unregister(dev); |
16213 | ||
fd0c0642 DV |
16214 | /* |
16215 | * Interrupts and polling as the first thing to avoid creating havoc. | |
2eb5252e | 16216 | * Too much stuff here (turning of connectors, ...) would |
fd0c0642 DV |
16217 | * experience fancy races otherwise. |
16218 | */ | |
2aeb7d3a | 16219 | intel_irq_uninstall(dev_priv); |
eb21b92b | 16220 | |
fd0c0642 DV |
16221 | /* |
16222 | * Due to the hpd irq storm handling the hotplug work can re-arm the | |
16223 | * poll handlers. Hence disable polling after hpd handling is shut down. | |
16224 | */ | |
f87ea761 | 16225 | drm_kms_helper_poll_fini(dev); |
fd0c0642 | 16226 | |
723bfd70 JB |
16227 | intel_unregister_dsm_handler(); |
16228 | ||
c937ab3e | 16229 | intel_fbc_global_disable(dev_priv); |
69341a5e | 16230 | |
1630fe75 CW |
16231 | /* flush any delayed tasks or pending work */ |
16232 | flush_scheduled_work(); | |
16233 | ||
db31af1d | 16234 | /* destroy the backlight and sysfs files before encoders/connectors */ |
19c8054c JN |
16235 | for_each_intel_connector(dev, connector) |
16236 | connector->unregister(connector); | |
d9255d57 | 16237 | |
79e53945 | 16238 | drm_mode_config_cleanup(dev); |
4d7bb011 DV |
16239 | |
16240 | intel_cleanup_overlay(dev); | |
ae48434c | 16241 | |
ae48434c | 16242 | intel_cleanup_gt_powersave(dev); |
f5949141 DV |
16243 | |
16244 | intel_teardown_gmbus(dev); | |
79e53945 JB |
16245 | } |
16246 | ||
f1c79df3 ZW |
16247 | /* |
16248 | * Return which encoder is currently attached for connector. | |
16249 | */ | |
df0e9248 | 16250 | struct drm_encoder *intel_best_encoder(struct drm_connector *connector) |
79e53945 | 16251 | { |
df0e9248 CW |
16252 | return &intel_attached_encoder(connector)->base; |
16253 | } | |
f1c79df3 | 16254 | |
df0e9248 CW |
16255 | void intel_connector_attach_encoder(struct intel_connector *connector, |
16256 | struct intel_encoder *encoder) | |
16257 | { | |
16258 | connector->encoder = encoder; | |
16259 | drm_mode_connector_attach_encoder(&connector->base, | |
16260 | &encoder->base); | |
79e53945 | 16261 | } |
28d52043 DA |
16262 | |
16263 | /* | |
16264 | * set vga decode state - true == enable VGA decode | |
16265 | */ | |
16266 | int intel_modeset_vga_set_state(struct drm_device *dev, bool state) | |
16267 | { | |
16268 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a885b3cc | 16269 | unsigned reg = INTEL_INFO(dev)->gen >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL; |
28d52043 DA |
16270 | u16 gmch_ctrl; |
16271 | ||
75fa041d CW |
16272 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
16273 | DRM_ERROR("failed to read control word\n"); | |
16274 | return -EIO; | |
16275 | } | |
16276 | ||
c0cc8a55 CW |
16277 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
16278 | return 0; | |
16279 | ||
28d52043 DA |
16280 | if (state) |
16281 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; | |
16282 | else | |
16283 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; | |
75fa041d CW |
16284 | |
16285 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { | |
16286 | DRM_ERROR("failed to write control word\n"); | |
16287 | return -EIO; | |
16288 | } | |
16289 | ||
28d52043 DA |
16290 | return 0; |
16291 | } | |
c4a1d9e4 | 16292 | |
c4a1d9e4 | 16293 | struct intel_display_error_state { |
ff57f1b0 PZ |
16294 | |
16295 | u32 power_well_driver; | |
16296 | ||
63b66e5b CW |
16297 | int num_transcoders; |
16298 | ||
c4a1d9e4 CW |
16299 | struct intel_cursor_error_state { |
16300 | u32 control; | |
16301 | u32 position; | |
16302 | u32 base; | |
16303 | u32 size; | |
52331309 | 16304 | } cursor[I915_MAX_PIPES]; |
c4a1d9e4 CW |
16305 | |
16306 | struct intel_pipe_error_state { | |
ddf9c536 | 16307 | bool power_domain_on; |
c4a1d9e4 | 16308 | u32 source; |
f301b1e1 | 16309 | u32 stat; |
52331309 | 16310 | } pipe[I915_MAX_PIPES]; |
c4a1d9e4 CW |
16311 | |
16312 | struct intel_plane_error_state { | |
16313 | u32 control; | |
16314 | u32 stride; | |
16315 | u32 size; | |
16316 | u32 pos; | |
16317 | u32 addr; | |
16318 | u32 surface; | |
16319 | u32 tile_offset; | |
52331309 | 16320 | } plane[I915_MAX_PIPES]; |
63b66e5b CW |
16321 | |
16322 | struct intel_transcoder_error_state { | |
ddf9c536 | 16323 | bool power_domain_on; |
63b66e5b CW |
16324 | enum transcoder cpu_transcoder; |
16325 | ||
16326 | u32 conf; | |
16327 | ||
16328 | u32 htotal; | |
16329 | u32 hblank; | |
16330 | u32 hsync; | |
16331 | u32 vtotal; | |
16332 | u32 vblank; | |
16333 | u32 vsync; | |
16334 | } transcoder[4]; | |
c4a1d9e4 CW |
16335 | }; |
16336 | ||
16337 | struct intel_display_error_state * | |
16338 | intel_display_capture_error_state(struct drm_device *dev) | |
16339 | { | |
fbee40df | 16340 | struct drm_i915_private *dev_priv = dev->dev_private; |
c4a1d9e4 | 16341 | struct intel_display_error_state *error; |
63b66e5b CW |
16342 | int transcoders[] = { |
16343 | TRANSCODER_A, | |
16344 | TRANSCODER_B, | |
16345 | TRANSCODER_C, | |
16346 | TRANSCODER_EDP, | |
16347 | }; | |
c4a1d9e4 CW |
16348 | int i; |
16349 | ||
63b66e5b CW |
16350 | if (INTEL_INFO(dev)->num_pipes == 0) |
16351 | return NULL; | |
16352 | ||
9d1cb914 | 16353 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
c4a1d9e4 CW |
16354 | if (error == NULL) |
16355 | return NULL; | |
16356 | ||
190be112 | 16357 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
ff57f1b0 PZ |
16358 | error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER); |
16359 | ||
055e393f | 16360 | for_each_pipe(dev_priv, i) { |
ddf9c536 | 16361 | error->pipe[i].power_domain_on = |
f458ebbc DV |
16362 | __intel_display_power_is_enabled(dev_priv, |
16363 | POWER_DOMAIN_PIPE(i)); | |
ddf9c536 | 16364 | if (!error->pipe[i].power_domain_on) |
9d1cb914 PZ |
16365 | continue; |
16366 | ||
5efb3e28 VS |
16367 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
16368 | error->cursor[i].position = I915_READ(CURPOS(i)); | |
16369 | error->cursor[i].base = I915_READ(CURBASE(i)); | |
c4a1d9e4 CW |
16370 | |
16371 | error->plane[i].control = I915_READ(DSPCNTR(i)); | |
16372 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); | |
80ca378b | 16373 | if (INTEL_INFO(dev)->gen <= 3) { |
51889b35 | 16374 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
80ca378b PZ |
16375 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
16376 | } | |
ca291363 PZ |
16377 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
16378 | error->plane[i].addr = I915_READ(DSPADDR(i)); | |
c4a1d9e4 CW |
16379 | if (INTEL_INFO(dev)->gen >= 4) { |
16380 | error->plane[i].surface = I915_READ(DSPSURF(i)); | |
16381 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); | |
16382 | } | |
16383 | ||
c4a1d9e4 | 16384 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
f301b1e1 | 16385 | |
3abfce77 | 16386 | if (HAS_GMCH_DISPLAY(dev)) |
f301b1e1 | 16387 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
63b66e5b CW |
16388 | } |
16389 | ||
16390 | error->num_transcoders = INTEL_INFO(dev)->num_pipes; | |
16391 | if (HAS_DDI(dev_priv->dev)) | |
16392 | error->num_transcoders++; /* Account for eDP. */ | |
16393 | ||
16394 | for (i = 0; i < error->num_transcoders; i++) { | |
16395 | enum transcoder cpu_transcoder = transcoders[i]; | |
16396 | ||
ddf9c536 | 16397 | error->transcoder[i].power_domain_on = |
f458ebbc | 16398 | __intel_display_power_is_enabled(dev_priv, |
38cc1daf | 16399 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
ddf9c536 | 16400 | if (!error->transcoder[i].power_domain_on) |
9d1cb914 PZ |
16401 | continue; |
16402 | ||
63b66e5b CW |
16403 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
16404 | ||
16405 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); | |
16406 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); | |
16407 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); | |
16408 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); | |
16409 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); | |
16410 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); | |
16411 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); | |
c4a1d9e4 CW |
16412 | } |
16413 | ||
16414 | return error; | |
16415 | } | |
16416 | ||
edc3d884 MK |
16417 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
16418 | ||
c4a1d9e4 | 16419 | void |
edc3d884 | 16420 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
c4a1d9e4 CW |
16421 | struct drm_device *dev, |
16422 | struct intel_display_error_state *error) | |
16423 | { | |
055e393f | 16424 | struct drm_i915_private *dev_priv = dev->dev_private; |
c4a1d9e4 CW |
16425 | int i; |
16426 | ||
63b66e5b CW |
16427 | if (!error) |
16428 | return; | |
16429 | ||
edc3d884 | 16430 | err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes); |
190be112 | 16431 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
edc3d884 | 16432 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
ff57f1b0 | 16433 | error->power_well_driver); |
055e393f | 16434 | for_each_pipe(dev_priv, i) { |
edc3d884 | 16435 | err_printf(m, "Pipe [%d]:\n", i); |
ddf9c536 | 16436 | err_printf(m, " Power: %s\n", |
87ad3212 | 16437 | onoff(error->pipe[i].power_domain_on)); |
edc3d884 | 16438 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
f301b1e1 | 16439 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
edc3d884 MK |
16440 | |
16441 | err_printf(m, "Plane [%d]:\n", i); | |
16442 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); | |
16443 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); | |
80ca378b | 16444 | if (INTEL_INFO(dev)->gen <= 3) { |
edc3d884 MK |
16445 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
16446 | err_printf(m, " POS: %08x\n", error->plane[i].pos); | |
80ca378b | 16447 | } |
4b71a570 | 16448 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
edc3d884 | 16449 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
c4a1d9e4 | 16450 | if (INTEL_INFO(dev)->gen >= 4) { |
edc3d884 MK |
16451 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
16452 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); | |
c4a1d9e4 CW |
16453 | } |
16454 | ||
edc3d884 MK |
16455 | err_printf(m, "Cursor [%d]:\n", i); |
16456 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); | |
16457 | err_printf(m, " POS: %08x\n", error->cursor[i].position); | |
16458 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); | |
c4a1d9e4 | 16459 | } |
63b66e5b CW |
16460 | |
16461 | for (i = 0; i < error->num_transcoders; i++) { | |
1cf84bb6 | 16462 | err_printf(m, "CPU transcoder: %c\n", |
63b66e5b | 16463 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
ddf9c536 | 16464 | err_printf(m, " Power: %s\n", |
87ad3212 | 16465 | onoff(error->transcoder[i].power_domain_on)); |
63b66e5b CW |
16466 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
16467 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); | |
16468 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); | |
16469 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); | |
16470 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); | |
16471 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); | |
16472 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); | |
16473 | } | |
c4a1d9e4 | 16474 | } |