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" |
c37efb99 | 39 | #include "i915_gem_dmabuf.h" |
db18b6a6 | 40 | #include "intel_dsi.h" |
e5510fac | 41 | #include "i915_trace.h" |
319c1d42 | 42 | #include <drm/drm_atomic.h> |
c196e1d6 | 43 | #include <drm/drm_atomic_helper.h> |
760285e7 DH |
44 | #include <drm/drm_dp_helper.h> |
45 | #include <drm/drm_crtc_helper.h> | |
465c120c MR |
46 | #include <drm/drm_plane_helper.h> |
47 | #include <drm/drm_rect.h> | |
c0f372b3 | 48 | #include <linux/dma_remapping.h> |
fd8e058a | 49 | #include <linux/reservation.h> |
79e53945 | 50 | |
5a21b665 DV |
51 | static bool is_mmio_work(struct intel_flip_work *work) |
52 | { | |
53 | return work->mmio_work.func; | |
54 | } | |
55 | ||
465c120c | 56 | /* Primary plane formats for gen <= 3 */ |
568db4f2 | 57 | static const uint32_t i8xx_primary_formats[] = { |
67fe7dc5 DL |
58 | DRM_FORMAT_C8, |
59 | DRM_FORMAT_RGB565, | |
465c120c | 60 | DRM_FORMAT_XRGB1555, |
67fe7dc5 | 61 | DRM_FORMAT_XRGB8888, |
465c120c MR |
62 | }; |
63 | ||
64 | /* Primary plane formats for gen >= 4 */ | |
568db4f2 | 65 | static const uint32_t i965_primary_formats[] = { |
6c0fd451 DL |
66 | DRM_FORMAT_C8, |
67 | DRM_FORMAT_RGB565, | |
68 | DRM_FORMAT_XRGB8888, | |
69 | DRM_FORMAT_XBGR8888, | |
70 | DRM_FORMAT_XRGB2101010, | |
71 | DRM_FORMAT_XBGR2101010, | |
72 | }; | |
73 | ||
74 | static const uint32_t skl_primary_formats[] = { | |
67fe7dc5 DL |
75 | DRM_FORMAT_C8, |
76 | DRM_FORMAT_RGB565, | |
77 | DRM_FORMAT_XRGB8888, | |
465c120c | 78 | DRM_FORMAT_XBGR8888, |
67fe7dc5 | 79 | DRM_FORMAT_ARGB8888, |
465c120c MR |
80 | DRM_FORMAT_ABGR8888, |
81 | DRM_FORMAT_XRGB2101010, | |
465c120c | 82 | DRM_FORMAT_XBGR2101010, |
ea916ea0 KM |
83 | DRM_FORMAT_YUYV, |
84 | DRM_FORMAT_YVYU, | |
85 | DRM_FORMAT_UYVY, | |
86 | DRM_FORMAT_VYUY, | |
465c120c MR |
87 | }; |
88 | ||
3d7d6510 MR |
89 | /* Cursor formats */ |
90 | static const uint32_t intel_cursor_formats[] = { | |
91 | DRM_FORMAT_ARGB8888, | |
92 | }; | |
93 | ||
f1f644dc | 94 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 95 | struct intel_crtc_state *pipe_config); |
18442d08 | 96 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
5cec258b | 97 | struct intel_crtc_state *pipe_config); |
f1f644dc | 98 | |
eb1bfe80 JB |
99 | static int intel_framebuffer_init(struct drm_device *dev, |
100 | struct intel_framebuffer *ifb, | |
101 | struct drm_mode_fb_cmd2 *mode_cmd, | |
102 | struct drm_i915_gem_object *obj); | |
5b18e57c DV |
103 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc); |
104 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc); | |
bc58be60 | 105 | static void intel_set_pipe_src_size(struct intel_crtc *intel_crtc); |
29407aab | 106 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
f769cd24 VK |
107 | struct intel_link_m_n *m_n, |
108 | struct intel_link_m_n *m2_n2); | |
29407aab | 109 | static void ironlake_set_pipeconf(struct drm_crtc *crtc); |
229fca97 | 110 | static void haswell_set_pipeconf(struct drm_crtc *crtc); |
391bf048 | 111 | static void haswell_set_pipemisc(struct drm_crtc *crtc); |
d288f65f | 112 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 113 | const struct intel_crtc_state *pipe_config); |
d288f65f | 114 | static void chv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 115 | const struct intel_crtc_state *pipe_config); |
5a21b665 DV |
116 | static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *); |
117 | static void intel_finish_crtc_commit(struct drm_crtc *, struct drm_crtc_state *); | |
549e2bfb CK |
118 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
119 | struct intel_crtc_state *crtc_state); | |
bfd16b2a ML |
120 | static void skylake_pfit_enable(struct intel_crtc *crtc); |
121 | static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force); | |
122 | static void ironlake_pfit_enable(struct intel_crtc *crtc); | |
043e9bda | 123 | static void intel_modeset_setup_hw_state(struct drm_device *dev); |
2622a081 | 124 | static void intel_pre_disable_primary_noatomic(struct drm_crtc *crtc); |
4e5ca60f | 125 | static int ilk_max_pixel_rate(struct drm_atomic_state *state); |
324513c0 | 126 | static int bxt_calc_cdclk(int max_pixclk); |
e7457a9a | 127 | |
d4906093 | 128 | struct intel_limit { |
4c5def93 ACO |
129 | struct { |
130 | int min, max; | |
131 | } dot, vco, n, m, m1, m2, p, p1; | |
132 | ||
133 | struct { | |
134 | int dot_limit; | |
135 | int p2_slow, p2_fast; | |
136 | } p2; | |
d4906093 | 137 | }; |
79e53945 | 138 | |
bfa7df01 VS |
139 | /* returns HPLL frequency in kHz */ |
140 | static int valleyview_get_vco(struct drm_i915_private *dev_priv) | |
141 | { | |
142 | int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; | |
143 | ||
144 | /* Obtain SKU information */ | |
145 | mutex_lock(&dev_priv->sb_lock); | |
146 | hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & | |
147 | CCK_FUSE_HPLL_FREQ_MASK; | |
148 | mutex_unlock(&dev_priv->sb_lock); | |
149 | ||
150 | return vco_freq[hpll_freq] * 1000; | |
151 | } | |
152 | ||
c30fec65 VS |
153 | int vlv_get_cck_clock(struct drm_i915_private *dev_priv, |
154 | const char *name, u32 reg, int ref_freq) | |
bfa7df01 VS |
155 | { |
156 | u32 val; | |
157 | int divider; | |
158 | ||
bfa7df01 VS |
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 | ||
c30fec65 VS |
169 | return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1); |
170 | } | |
171 | ||
172 | static int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv, | |
173 | const char *name, u32 reg) | |
174 | { | |
175 | if (dev_priv->hpll_freq == 0) | |
176 | dev_priv->hpll_freq = valleyview_get_vco(dev_priv); | |
177 | ||
178 | return vlv_get_cck_clock(dev_priv, name, reg, | |
179 | dev_priv->hpll_freq); | |
bfa7df01 VS |
180 | } |
181 | ||
e7dc33f3 VS |
182 | static int |
183 | intel_pch_rawclk(struct drm_i915_private *dev_priv) | |
d2acd215 | 184 | { |
e7dc33f3 VS |
185 | return (I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK) * 1000; |
186 | } | |
d2acd215 | 187 | |
e7dc33f3 VS |
188 | static int |
189 | intel_vlv_hrawclk(struct drm_i915_private *dev_priv) | |
190 | { | |
19ab4ed3 | 191 | /* RAWCLK_FREQ_VLV register updated from power well code */ |
35d38d1f VS |
192 | return vlv_get_cck_clock_hpll(dev_priv, "hrawclk", |
193 | CCK_DISPLAY_REF_CLOCK_CONTROL); | |
d2acd215 DV |
194 | } |
195 | ||
e7dc33f3 VS |
196 | static int |
197 | intel_g4x_hrawclk(struct drm_i915_private *dev_priv) | |
79e50a4f | 198 | { |
79e50a4f JN |
199 | uint32_t clkcfg; |
200 | ||
e7dc33f3 | 201 | /* hrawclock is 1/4 the FSB frequency */ |
79e50a4f JN |
202 | clkcfg = I915_READ(CLKCFG); |
203 | switch (clkcfg & CLKCFG_FSB_MASK) { | |
204 | case CLKCFG_FSB_400: | |
e7dc33f3 | 205 | return 100000; |
79e50a4f | 206 | case CLKCFG_FSB_533: |
e7dc33f3 | 207 | return 133333; |
79e50a4f | 208 | case CLKCFG_FSB_667: |
e7dc33f3 | 209 | return 166667; |
79e50a4f | 210 | case CLKCFG_FSB_800: |
e7dc33f3 | 211 | return 200000; |
79e50a4f | 212 | case CLKCFG_FSB_1067: |
e7dc33f3 | 213 | return 266667; |
79e50a4f | 214 | case CLKCFG_FSB_1333: |
e7dc33f3 | 215 | return 333333; |
79e50a4f JN |
216 | /* these two are just a guess; one of them might be right */ |
217 | case CLKCFG_FSB_1600: | |
218 | case CLKCFG_FSB_1600_ALT: | |
e7dc33f3 | 219 | return 400000; |
79e50a4f | 220 | default: |
e7dc33f3 | 221 | return 133333; |
79e50a4f JN |
222 | } |
223 | } | |
224 | ||
19ab4ed3 | 225 | void intel_update_rawclk(struct drm_i915_private *dev_priv) |
e7dc33f3 VS |
226 | { |
227 | if (HAS_PCH_SPLIT(dev_priv)) | |
228 | dev_priv->rawclk_freq = intel_pch_rawclk(dev_priv); | |
229 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) | |
230 | dev_priv->rawclk_freq = intel_vlv_hrawclk(dev_priv); | |
231 | else if (IS_G4X(dev_priv) || IS_PINEVIEW(dev_priv)) | |
232 | dev_priv->rawclk_freq = intel_g4x_hrawclk(dev_priv); | |
233 | else | |
234 | return; /* no rawclk on other platforms, or no need to know it */ | |
235 | ||
236 | DRM_DEBUG_DRIVER("rawclk rate: %d kHz\n", dev_priv->rawclk_freq); | |
237 | } | |
238 | ||
bfa7df01 VS |
239 | static void intel_update_czclk(struct drm_i915_private *dev_priv) |
240 | { | |
666a4537 | 241 | if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))) |
bfa7df01 VS |
242 | return; |
243 | ||
244 | dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk", | |
245 | CCK_CZ_CLOCK_CONTROL); | |
246 | ||
247 | DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq); | |
248 | } | |
249 | ||
021357ac | 250 | static inline u32 /* units of 100MHz */ |
21a727b3 VS |
251 | intel_fdi_link_freq(struct drm_i915_private *dev_priv, |
252 | const struct intel_crtc_state *pipe_config) | |
021357ac | 253 | { |
21a727b3 VS |
254 | if (HAS_DDI(dev_priv)) |
255 | return pipe_config->port_clock; /* SPLL */ | |
256 | else if (IS_GEN5(dev_priv)) | |
257 | return ((I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2) * 10000; | |
e3b247da | 258 | else |
21a727b3 | 259 | return 270000; |
021357ac CW |
260 | } |
261 | ||
1b6f4958 | 262 | static const struct intel_limit intel_limits_i8xx_dac = { |
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 = 2, .max = 33 }, | |
273e27ca EA |
271 | .p2 = { .dot_limit = 165000, |
272 | .p2_slow = 4, .p2_fast = 2 }, | |
e4b36699 KP |
273 | }; |
274 | ||
1b6f4958 | 275 | static const struct intel_limit intel_limits_i8xx_dvo = { |
5d536e28 | 276 | .dot = { .min = 25000, .max = 350000 }, |
9c333719 | 277 | .vco = { .min = 908000, .max = 1512000 }, |
91dbe5fb | 278 | .n = { .min = 2, .max = 16 }, |
5d536e28 DV |
279 | .m = { .min = 96, .max = 140 }, |
280 | .m1 = { .min = 18, .max = 26 }, | |
281 | .m2 = { .min = 6, .max = 16 }, | |
282 | .p = { .min = 4, .max = 128 }, | |
283 | .p1 = { .min = 2, .max = 33 }, | |
284 | .p2 = { .dot_limit = 165000, | |
285 | .p2_slow = 4, .p2_fast = 4 }, | |
286 | }; | |
287 | ||
1b6f4958 | 288 | static const struct intel_limit intel_limits_i8xx_lvds = { |
0206e353 | 289 | .dot = { .min = 25000, .max = 350000 }, |
9c333719 | 290 | .vco = { .min = 908000, .max = 1512000 }, |
91dbe5fb | 291 | .n = { .min = 2, .max = 16 }, |
0206e353 AJ |
292 | .m = { .min = 96, .max = 140 }, |
293 | .m1 = { .min = 18, .max = 26 }, | |
294 | .m2 = { .min = 6, .max = 16 }, | |
295 | .p = { .min = 4, .max = 128 }, | |
296 | .p1 = { .min = 1, .max = 6 }, | |
273e27ca EA |
297 | .p2 = { .dot_limit = 165000, |
298 | .p2_slow = 14, .p2_fast = 7 }, | |
e4b36699 | 299 | }; |
273e27ca | 300 | |
1b6f4958 | 301 | static const struct intel_limit intel_limits_i9xx_sdvo = { |
0206e353 AJ |
302 | .dot = { .min = 20000, .max = 400000 }, |
303 | .vco = { .min = 1400000, .max = 2800000 }, | |
304 | .n = { .min = 1, .max = 6 }, | |
305 | .m = { .min = 70, .max = 120 }, | |
4f7dfb67 PJ |
306 | .m1 = { .min = 8, .max = 18 }, |
307 | .m2 = { .min = 3, .max = 7 }, | |
0206e353 AJ |
308 | .p = { .min = 5, .max = 80 }, |
309 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
310 | .p2 = { .dot_limit = 200000, |
311 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
312 | }; |
313 | ||
1b6f4958 | 314 | static const struct intel_limit intel_limits_i9xx_lvds = { |
0206e353 AJ |
315 | .dot = { .min = 20000, .max = 400000 }, |
316 | .vco = { .min = 1400000, .max = 2800000 }, | |
317 | .n = { .min = 1, .max = 6 }, | |
318 | .m = { .min = 70, .max = 120 }, | |
53a7d2d1 PJ |
319 | .m1 = { .min = 8, .max = 18 }, |
320 | .m2 = { .min = 3, .max = 7 }, | |
0206e353 AJ |
321 | .p = { .min = 7, .max = 98 }, |
322 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
323 | .p2 = { .dot_limit = 112000, |
324 | .p2_slow = 14, .p2_fast = 7 }, | |
e4b36699 KP |
325 | }; |
326 | ||
273e27ca | 327 | |
1b6f4958 | 328 | static const struct intel_limit intel_limits_g4x_sdvo = { |
273e27ca EA |
329 | .dot = { .min = 25000, .max = 270000 }, |
330 | .vco = { .min = 1750000, .max = 3500000}, | |
331 | .n = { .min = 1, .max = 4 }, | |
332 | .m = { .min = 104, .max = 138 }, | |
333 | .m1 = { .min = 17, .max = 23 }, | |
334 | .m2 = { .min = 5, .max = 11 }, | |
335 | .p = { .min = 10, .max = 30 }, | |
336 | .p1 = { .min = 1, .max = 3}, | |
337 | .p2 = { .dot_limit = 270000, | |
338 | .p2_slow = 10, | |
339 | .p2_fast = 10 | |
044c7c41 | 340 | }, |
e4b36699 KP |
341 | }; |
342 | ||
1b6f4958 | 343 | static const struct intel_limit intel_limits_g4x_hdmi = { |
273e27ca EA |
344 | .dot = { .min = 22000, .max = 400000 }, |
345 | .vco = { .min = 1750000, .max = 3500000}, | |
346 | .n = { .min = 1, .max = 4 }, | |
347 | .m = { .min = 104, .max = 138 }, | |
348 | .m1 = { .min = 16, .max = 23 }, | |
349 | .m2 = { .min = 5, .max = 11 }, | |
350 | .p = { .min = 5, .max = 80 }, | |
351 | .p1 = { .min = 1, .max = 8}, | |
352 | .p2 = { .dot_limit = 165000, | |
353 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
354 | }; |
355 | ||
1b6f4958 | 356 | static const struct intel_limit intel_limits_g4x_single_channel_lvds = { |
273e27ca EA |
357 | .dot = { .min = 20000, .max = 115000 }, |
358 | .vco = { .min = 1750000, .max = 3500000 }, | |
359 | .n = { .min = 1, .max = 3 }, | |
360 | .m = { .min = 104, .max = 138 }, | |
361 | .m1 = { .min = 17, .max = 23 }, | |
362 | .m2 = { .min = 5, .max = 11 }, | |
363 | .p = { .min = 28, .max = 112 }, | |
364 | .p1 = { .min = 2, .max = 8 }, | |
365 | .p2 = { .dot_limit = 0, | |
366 | .p2_slow = 14, .p2_fast = 14 | |
044c7c41 | 367 | }, |
e4b36699 KP |
368 | }; |
369 | ||
1b6f4958 | 370 | static const struct intel_limit intel_limits_g4x_dual_channel_lvds = { |
273e27ca EA |
371 | .dot = { .min = 80000, .max = 224000 }, |
372 | .vco = { .min = 1750000, .max = 3500000 }, | |
373 | .n = { .min = 1, .max = 3 }, | |
374 | .m = { .min = 104, .max = 138 }, | |
375 | .m1 = { .min = 17, .max = 23 }, | |
376 | .m2 = { .min = 5, .max = 11 }, | |
377 | .p = { .min = 14, .max = 42 }, | |
378 | .p1 = { .min = 2, .max = 6 }, | |
379 | .p2 = { .dot_limit = 0, | |
380 | .p2_slow = 7, .p2_fast = 7 | |
044c7c41 | 381 | }, |
e4b36699 KP |
382 | }; |
383 | ||
1b6f4958 | 384 | static const struct intel_limit intel_limits_pineview_sdvo = { |
0206e353 AJ |
385 | .dot = { .min = 20000, .max = 400000}, |
386 | .vco = { .min = 1700000, .max = 3500000 }, | |
273e27ca | 387 | /* Pineview's Ncounter is a ring counter */ |
0206e353 AJ |
388 | .n = { .min = 3, .max = 6 }, |
389 | .m = { .min = 2, .max = 256 }, | |
273e27ca | 390 | /* Pineview only has one combined m divider, which we treat as m2. */ |
0206e353 AJ |
391 | .m1 = { .min = 0, .max = 0 }, |
392 | .m2 = { .min = 0, .max = 254 }, | |
393 | .p = { .min = 5, .max = 80 }, | |
394 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
395 | .p2 = { .dot_limit = 200000, |
396 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
397 | }; |
398 | ||
1b6f4958 | 399 | static const struct intel_limit intel_limits_pineview_lvds = { |
0206e353 AJ |
400 | .dot = { .min = 20000, .max = 400000 }, |
401 | .vco = { .min = 1700000, .max = 3500000 }, | |
402 | .n = { .min = 3, .max = 6 }, | |
403 | .m = { .min = 2, .max = 256 }, | |
404 | .m1 = { .min = 0, .max = 0 }, | |
405 | .m2 = { .min = 0, .max = 254 }, | |
406 | .p = { .min = 7, .max = 112 }, | |
407 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
408 | .p2 = { .dot_limit = 112000, |
409 | .p2_slow = 14, .p2_fast = 14 }, | |
e4b36699 KP |
410 | }; |
411 | ||
273e27ca EA |
412 | /* Ironlake / Sandybridge |
413 | * | |
414 | * We calculate clock using (register_value + 2) for N/M1/M2, so here | |
415 | * the range value for them is (actual_value - 2). | |
416 | */ | |
1b6f4958 | 417 | static const struct intel_limit intel_limits_ironlake_dac = { |
273e27ca EA |
418 | .dot = { .min = 25000, .max = 350000 }, |
419 | .vco = { .min = 1760000, .max = 3510000 }, | |
420 | .n = { .min = 1, .max = 5 }, | |
421 | .m = { .min = 79, .max = 127 }, | |
422 | .m1 = { .min = 12, .max = 22 }, | |
423 | .m2 = { .min = 5, .max = 9 }, | |
424 | .p = { .min = 5, .max = 80 }, | |
425 | .p1 = { .min = 1, .max = 8 }, | |
426 | .p2 = { .dot_limit = 225000, | |
427 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
428 | }; |
429 | ||
1b6f4958 | 430 | static const struct intel_limit intel_limits_ironlake_single_lvds = { |
273e27ca EA |
431 | .dot = { .min = 25000, .max = 350000 }, |
432 | .vco = { .min = 1760000, .max = 3510000 }, | |
433 | .n = { .min = 1, .max = 3 }, | |
434 | .m = { .min = 79, .max = 118 }, | |
435 | .m1 = { .min = 12, .max = 22 }, | |
436 | .m2 = { .min = 5, .max = 9 }, | |
437 | .p = { .min = 28, .max = 112 }, | |
438 | .p1 = { .min = 2, .max = 8 }, | |
439 | .p2 = { .dot_limit = 225000, | |
440 | .p2_slow = 14, .p2_fast = 14 }, | |
b91ad0ec ZW |
441 | }; |
442 | ||
1b6f4958 | 443 | static const struct intel_limit intel_limits_ironlake_dual_lvds = { |
273e27ca EA |
444 | .dot = { .min = 25000, .max = 350000 }, |
445 | .vco = { .min = 1760000, .max = 3510000 }, | |
446 | .n = { .min = 1, .max = 3 }, | |
447 | .m = { .min = 79, .max = 127 }, | |
448 | .m1 = { .min = 12, .max = 22 }, | |
449 | .m2 = { .min = 5, .max = 9 }, | |
450 | .p = { .min = 14, .max = 56 }, | |
451 | .p1 = { .min = 2, .max = 8 }, | |
452 | .p2 = { .dot_limit = 225000, | |
453 | .p2_slow = 7, .p2_fast = 7 }, | |
b91ad0ec ZW |
454 | }; |
455 | ||
273e27ca | 456 | /* LVDS 100mhz refclk limits. */ |
1b6f4958 | 457 | static const struct intel_limit intel_limits_ironlake_single_lvds_100m = { |
273e27ca EA |
458 | .dot = { .min = 25000, .max = 350000 }, |
459 | .vco = { .min = 1760000, .max = 3510000 }, | |
460 | .n = { .min = 1, .max = 2 }, | |
461 | .m = { .min = 79, .max = 126 }, | |
462 | .m1 = { .min = 12, .max = 22 }, | |
463 | .m2 = { .min = 5, .max = 9 }, | |
464 | .p = { .min = 28, .max = 112 }, | |
0206e353 | 465 | .p1 = { .min = 2, .max = 8 }, |
273e27ca EA |
466 | .p2 = { .dot_limit = 225000, |
467 | .p2_slow = 14, .p2_fast = 14 }, | |
b91ad0ec ZW |
468 | }; |
469 | ||
1b6f4958 | 470 | static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = { |
273e27ca EA |
471 | .dot = { .min = 25000, .max = 350000 }, |
472 | .vco = { .min = 1760000, .max = 3510000 }, | |
473 | .n = { .min = 1, .max = 3 }, | |
474 | .m = { .min = 79, .max = 126 }, | |
475 | .m1 = { .min = 12, .max = 22 }, | |
476 | .m2 = { .min = 5, .max = 9 }, | |
477 | .p = { .min = 14, .max = 42 }, | |
0206e353 | 478 | .p1 = { .min = 2, .max = 6 }, |
273e27ca EA |
479 | .p2 = { .dot_limit = 225000, |
480 | .p2_slow = 7, .p2_fast = 7 }, | |
4547668a ZY |
481 | }; |
482 | ||
1b6f4958 | 483 | static const struct intel_limit intel_limits_vlv = { |
f01b7962 VS |
484 | /* |
485 | * These are the data rate limits (measured in fast clocks) | |
486 | * since those are the strictest limits we have. The fast | |
487 | * clock and actual rate limits are more relaxed, so checking | |
488 | * them would make no difference. | |
489 | */ | |
490 | .dot = { .min = 25000 * 5, .max = 270000 * 5 }, | |
75e53986 | 491 | .vco = { .min = 4000000, .max = 6000000 }, |
a0c4da24 | 492 | .n = { .min = 1, .max = 7 }, |
a0c4da24 JB |
493 | .m1 = { .min = 2, .max = 3 }, |
494 | .m2 = { .min = 11, .max = 156 }, | |
b99ab663 | 495 | .p1 = { .min = 2, .max = 3 }, |
5fdc9c49 | 496 | .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */ |
a0c4da24 JB |
497 | }; |
498 | ||
1b6f4958 | 499 | static const struct intel_limit intel_limits_chv = { |
ef9348c8 CML |
500 | /* |
501 | * These are the data rate limits (measured in fast clocks) | |
502 | * since those are the strictest limits we have. The fast | |
503 | * clock and actual rate limits are more relaxed, so checking | |
504 | * them would make no difference. | |
505 | */ | |
506 | .dot = { .min = 25000 * 5, .max = 540000 * 5}, | |
17fe1021 | 507 | .vco = { .min = 4800000, .max = 6480000 }, |
ef9348c8 CML |
508 | .n = { .min = 1, .max = 1 }, |
509 | .m1 = { .min = 2, .max = 2 }, | |
510 | .m2 = { .min = 24 << 22, .max = 175 << 22 }, | |
511 | .p1 = { .min = 2, .max = 4 }, | |
512 | .p2 = { .p2_slow = 1, .p2_fast = 14 }, | |
513 | }; | |
514 | ||
1b6f4958 | 515 | static const struct intel_limit intel_limits_bxt = { |
5ab7b0b7 ID |
516 | /* FIXME: find real dot limits */ |
517 | .dot = { .min = 0, .max = INT_MAX }, | |
e6292556 | 518 | .vco = { .min = 4800000, .max = 6700000 }, |
5ab7b0b7 ID |
519 | .n = { .min = 1, .max = 1 }, |
520 | .m1 = { .min = 2, .max = 2 }, | |
521 | /* FIXME: find real m2 limits */ | |
522 | .m2 = { .min = 2 << 22, .max = 255 << 22 }, | |
523 | .p1 = { .min = 2, .max = 4 }, | |
524 | .p2 = { .p2_slow = 1, .p2_fast = 20 }, | |
525 | }; | |
526 | ||
cdba954e ACO |
527 | static bool |
528 | needs_modeset(struct drm_crtc_state *state) | |
529 | { | |
fc596660 | 530 | return drm_atomic_crtc_needs_modeset(state); |
cdba954e ACO |
531 | } |
532 | ||
e0638cdf PZ |
533 | /** |
534 | * Returns whether any output on the specified pipe is of the specified type | |
535 | */ | |
4093561b | 536 | bool intel_pipe_has_type(struct intel_crtc *crtc, enum intel_output_type type) |
e0638cdf | 537 | { |
409ee761 | 538 | struct drm_device *dev = crtc->base.dev; |
e0638cdf PZ |
539 | struct intel_encoder *encoder; |
540 | ||
409ee761 | 541 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
e0638cdf PZ |
542 | if (encoder->type == type) |
543 | return true; | |
544 | ||
545 | return false; | |
546 | } | |
547 | ||
d0737e1d ACO |
548 | /** |
549 | * Returns whether any output on the specified pipe will have the specified | |
550 | * type after a staged modeset is complete, i.e., the same as | |
551 | * intel_pipe_has_type() but looking at encoder->new_crtc instead of | |
552 | * encoder->crtc. | |
553 | */ | |
a93e255f ACO |
554 | static bool intel_pipe_will_have_type(const struct intel_crtc_state *crtc_state, |
555 | int type) | |
d0737e1d | 556 | { |
a93e255f | 557 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 558 | struct drm_connector *connector; |
a93e255f | 559 | struct drm_connector_state *connector_state; |
d0737e1d | 560 | struct intel_encoder *encoder; |
a93e255f ACO |
561 | int i, num_connectors = 0; |
562 | ||
da3ced29 | 563 | for_each_connector_in_state(state, connector, connector_state, i) { |
a93e255f ACO |
564 | if (connector_state->crtc != crtc_state->base.crtc) |
565 | continue; | |
566 | ||
567 | num_connectors++; | |
d0737e1d | 568 | |
a93e255f ACO |
569 | encoder = to_intel_encoder(connector_state->best_encoder); |
570 | if (encoder->type == type) | |
d0737e1d | 571 | return true; |
a93e255f ACO |
572 | } |
573 | ||
574 | WARN_ON(num_connectors == 0); | |
d0737e1d ACO |
575 | |
576 | return false; | |
577 | } | |
578 | ||
dccbea3b ID |
579 | /* |
580 | * Platform specific helpers to calculate the port PLL loopback- (clock.m), | |
581 | * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast | |
582 | * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic. | |
583 | * The helpers' return value is the rate of the clock that is fed to the | |
584 | * display engine's pipe which can be the above fast dot clock rate or a | |
585 | * divided-down version of it. | |
586 | */ | |
f2b115e6 | 587 | /* m1 is reserved as 0 in Pineview, n is a ring counter */ |
9e2c8475 | 588 | static int pnv_calc_dpll_params(int refclk, struct dpll *clock) |
79e53945 | 589 | { |
2177832f SL |
590 | clock->m = clock->m2 + 2; |
591 | clock->p = clock->p1 * clock->p2; | |
ed5ca77e | 592 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
dccbea3b | 593 | return 0; |
fb03ac01 VS |
594 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
595 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
dccbea3b ID |
596 | |
597 | return clock->dot; | |
2177832f SL |
598 | } |
599 | ||
7429e9d4 DV |
600 | static uint32_t i9xx_dpll_compute_m(struct dpll *dpll) |
601 | { | |
602 | return 5 * (dpll->m1 + 2) + (dpll->m2 + 2); | |
603 | } | |
604 | ||
9e2c8475 | 605 | static int i9xx_calc_dpll_params(int refclk, struct dpll *clock) |
2177832f | 606 | { |
7429e9d4 | 607 | clock->m = i9xx_dpll_compute_m(clock); |
79e53945 | 608 | clock->p = clock->p1 * clock->p2; |
ed5ca77e | 609 | if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) |
dccbea3b | 610 | return 0; |
fb03ac01 VS |
611 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2); |
612 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
dccbea3b ID |
613 | |
614 | return clock->dot; | |
79e53945 JB |
615 | } |
616 | ||
9e2c8475 | 617 | static int vlv_calc_dpll_params(int refclk, struct dpll *clock) |
589eca67 ID |
618 | { |
619 | clock->m = clock->m1 * clock->m2; | |
620 | clock->p = clock->p1 * clock->p2; | |
621 | if (WARN_ON(clock->n == 0 || clock->p == 0)) | |
dccbea3b | 622 | return 0; |
589eca67 ID |
623 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
624 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
dccbea3b ID |
625 | |
626 | return clock->dot / 5; | |
589eca67 ID |
627 | } |
628 | ||
9e2c8475 | 629 | int chv_calc_dpll_params(int refclk, struct dpll *clock) |
ef9348c8 CML |
630 | { |
631 | clock->m = clock->m1 * clock->m2; | |
632 | clock->p = clock->p1 * clock->p2; | |
633 | if (WARN_ON(clock->n == 0 || clock->p == 0)) | |
dccbea3b | 634 | return 0; |
ef9348c8 CML |
635 | clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m, |
636 | clock->n << 22); | |
637 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
dccbea3b ID |
638 | |
639 | return clock->dot / 5; | |
ef9348c8 CML |
640 | } |
641 | ||
7c04d1d9 | 642 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
79e53945 JB |
643 | /** |
644 | * Returns whether the given set of divisors are valid for a given refclk with | |
645 | * the given connectors. | |
646 | */ | |
647 | ||
1b894b59 | 648 | static bool intel_PLL_is_valid(struct drm_device *dev, |
1b6f4958 | 649 | const struct intel_limit *limit, |
9e2c8475 | 650 | const struct dpll *clock) |
79e53945 | 651 | { |
f01b7962 VS |
652 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
653 | INTELPllInvalid("n out of range\n"); | |
79e53945 | 654 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
0206e353 | 655 | INTELPllInvalid("p1 out of range\n"); |
79e53945 | 656 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
0206e353 | 657 | INTELPllInvalid("m2 out of range\n"); |
79e53945 | 658 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
0206e353 | 659 | INTELPllInvalid("m1 out of range\n"); |
f01b7962 | 660 | |
666a4537 WB |
661 | if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev) && |
662 | !IS_CHERRYVIEW(dev) && !IS_BROXTON(dev)) | |
f01b7962 VS |
663 | if (clock->m1 <= clock->m2) |
664 | INTELPllInvalid("m1 <= m2\n"); | |
665 | ||
666a4537 | 666 | if (!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev) && !IS_BROXTON(dev)) { |
f01b7962 VS |
667 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
668 | INTELPllInvalid("p out of range\n"); | |
669 | if (clock->m < limit->m.min || limit->m.max < clock->m) | |
670 | INTELPllInvalid("m out of range\n"); | |
671 | } | |
672 | ||
79e53945 | 673 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
0206e353 | 674 | INTELPllInvalid("vco out of range\n"); |
79e53945 JB |
675 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
676 | * connector, etc., rather than just a single range. | |
677 | */ | |
678 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) | |
0206e353 | 679 | INTELPllInvalid("dot out of range\n"); |
79e53945 JB |
680 | |
681 | return true; | |
682 | } | |
683 | ||
3b1429d9 | 684 | static int |
1b6f4958 | 685 | i9xx_select_p2_div(const struct intel_limit *limit, |
3b1429d9 VS |
686 | const struct intel_crtc_state *crtc_state, |
687 | int target) | |
79e53945 | 688 | { |
3b1429d9 | 689 | struct drm_device *dev = crtc_state->base.crtc->dev; |
79e53945 | 690 | |
a93e255f | 691 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
79e53945 | 692 | /* |
a210b028 DV |
693 | * For LVDS just rely on its current settings for dual-channel. |
694 | * We haven't figured out how to reliably set up different | |
695 | * single/dual channel state, if we even can. | |
79e53945 | 696 | */ |
1974cad0 | 697 | if (intel_is_dual_link_lvds(dev)) |
3b1429d9 | 698 | return limit->p2.p2_fast; |
79e53945 | 699 | else |
3b1429d9 | 700 | return limit->p2.p2_slow; |
79e53945 JB |
701 | } else { |
702 | if (target < limit->p2.dot_limit) | |
3b1429d9 | 703 | return limit->p2.p2_slow; |
79e53945 | 704 | else |
3b1429d9 | 705 | return limit->p2.p2_fast; |
79e53945 | 706 | } |
3b1429d9 VS |
707 | } |
708 | ||
70e8aa21 ACO |
709 | /* |
710 | * Returns a set of divisors for the desired target clock with the given | |
711 | * refclk, or FALSE. The returned values represent the clock equation: | |
712 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. | |
713 | * | |
714 | * Target and reference clocks are specified in kHz. | |
715 | * | |
716 | * If match_clock is provided, then best_clock P divider must match the P | |
717 | * divider from @match_clock used for LVDS downclocking. | |
718 | */ | |
3b1429d9 | 719 | static bool |
1b6f4958 | 720 | i9xx_find_best_dpll(const struct intel_limit *limit, |
3b1429d9 | 721 | struct intel_crtc_state *crtc_state, |
9e2c8475 ACO |
722 | int target, int refclk, struct dpll *match_clock, |
723 | struct dpll *best_clock) | |
3b1429d9 VS |
724 | { |
725 | struct drm_device *dev = crtc_state->base.crtc->dev; | |
9e2c8475 | 726 | struct dpll clock; |
3b1429d9 | 727 | int err = target; |
79e53945 | 728 | |
0206e353 | 729 | memset(best_clock, 0, sizeof(*best_clock)); |
79e53945 | 730 | |
3b1429d9 VS |
731 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
732 | ||
42158660 ZY |
733 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
734 | clock.m1++) { | |
735 | for (clock.m2 = limit->m2.min; | |
736 | clock.m2 <= limit->m2.max; clock.m2++) { | |
c0efc387 | 737 | if (clock.m2 >= clock.m1) |
42158660 ZY |
738 | break; |
739 | for (clock.n = limit->n.min; | |
740 | clock.n <= limit->n.max; clock.n++) { | |
741 | for (clock.p1 = limit->p1.min; | |
742 | clock.p1 <= limit->p1.max; clock.p1++) { | |
79e53945 JB |
743 | int this_err; |
744 | ||
dccbea3b | 745 | i9xx_calc_dpll_params(refclk, &clock); |
ac58c3f0 DV |
746 | if (!intel_PLL_is_valid(dev, limit, |
747 | &clock)) | |
748 | continue; | |
749 | if (match_clock && | |
750 | clock.p != match_clock->p) | |
751 | continue; | |
752 | ||
753 | this_err = abs(clock.dot - target); | |
754 | if (this_err < err) { | |
755 | *best_clock = clock; | |
756 | err = this_err; | |
757 | } | |
758 | } | |
759 | } | |
760 | } | |
761 | } | |
762 | ||
763 | return (err != target); | |
764 | } | |
765 | ||
70e8aa21 ACO |
766 | /* |
767 | * Returns a set of divisors for the desired target clock with the given | |
768 | * refclk, or FALSE. The returned values represent the clock equation: | |
769 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. | |
770 | * | |
771 | * Target and reference clocks are specified in kHz. | |
772 | * | |
773 | * If match_clock is provided, then best_clock P divider must match the P | |
774 | * divider from @match_clock used for LVDS downclocking. | |
775 | */ | |
ac58c3f0 | 776 | static bool |
1b6f4958 | 777 | pnv_find_best_dpll(const struct intel_limit *limit, |
a93e255f | 778 | struct intel_crtc_state *crtc_state, |
9e2c8475 ACO |
779 | int target, int refclk, struct dpll *match_clock, |
780 | struct dpll *best_clock) | |
79e53945 | 781 | { |
3b1429d9 | 782 | struct drm_device *dev = crtc_state->base.crtc->dev; |
9e2c8475 | 783 | struct dpll clock; |
79e53945 JB |
784 | int err = target; |
785 | ||
0206e353 | 786 | memset(best_clock, 0, sizeof(*best_clock)); |
79e53945 | 787 | |
3b1429d9 VS |
788 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
789 | ||
42158660 ZY |
790 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
791 | clock.m1++) { | |
792 | for (clock.m2 = limit->m2.min; | |
793 | clock.m2 <= limit->m2.max; clock.m2++) { | |
42158660 ZY |
794 | for (clock.n = limit->n.min; |
795 | clock.n <= limit->n.max; clock.n++) { | |
796 | for (clock.p1 = limit->p1.min; | |
797 | clock.p1 <= limit->p1.max; clock.p1++) { | |
79e53945 JB |
798 | int this_err; |
799 | ||
dccbea3b | 800 | pnv_calc_dpll_params(refclk, &clock); |
1b894b59 CW |
801 | if (!intel_PLL_is_valid(dev, limit, |
802 | &clock)) | |
79e53945 | 803 | continue; |
cec2f356 SP |
804 | if (match_clock && |
805 | clock.p != match_clock->p) | |
806 | continue; | |
79e53945 JB |
807 | |
808 | this_err = abs(clock.dot - target); | |
809 | if (this_err < err) { | |
810 | *best_clock = clock; | |
811 | err = this_err; | |
812 | } | |
813 | } | |
814 | } | |
815 | } | |
816 | } | |
817 | ||
818 | return (err != target); | |
819 | } | |
820 | ||
997c030c ACO |
821 | /* |
822 | * Returns a set of divisors for the desired target clock with the given | |
823 | * refclk, or FALSE. The returned values represent the clock equation: | |
824 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. | |
70e8aa21 ACO |
825 | * |
826 | * Target and reference clocks are specified in kHz. | |
827 | * | |
828 | * If match_clock is provided, then best_clock P divider must match the P | |
829 | * divider from @match_clock used for LVDS downclocking. | |
997c030c | 830 | */ |
d4906093 | 831 | static bool |
1b6f4958 | 832 | g4x_find_best_dpll(const struct intel_limit *limit, |
a93e255f | 833 | struct intel_crtc_state *crtc_state, |
9e2c8475 ACO |
834 | int target, int refclk, struct dpll *match_clock, |
835 | struct dpll *best_clock) | |
d4906093 | 836 | { |
3b1429d9 | 837 | struct drm_device *dev = crtc_state->base.crtc->dev; |
9e2c8475 | 838 | struct dpll clock; |
d4906093 | 839 | int max_n; |
3b1429d9 | 840 | bool found = false; |
6ba770dc AJ |
841 | /* approximately equals target * 0.00585 */ |
842 | int err_most = (target >> 8) + (target >> 9); | |
d4906093 ML |
843 | |
844 | memset(best_clock, 0, sizeof(*best_clock)); | |
3b1429d9 VS |
845 | |
846 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); | |
847 | ||
d4906093 | 848 | max_n = limit->n.max; |
f77f13e2 | 849 | /* based on hardware requirement, prefer smaller n to precision */ |
d4906093 | 850 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
f77f13e2 | 851 | /* based on hardware requirement, prefere larger m1,m2 */ |
d4906093 ML |
852 | for (clock.m1 = limit->m1.max; |
853 | clock.m1 >= limit->m1.min; clock.m1--) { | |
854 | for (clock.m2 = limit->m2.max; | |
855 | clock.m2 >= limit->m2.min; clock.m2--) { | |
856 | for (clock.p1 = limit->p1.max; | |
857 | clock.p1 >= limit->p1.min; clock.p1--) { | |
858 | int this_err; | |
859 | ||
dccbea3b | 860 | i9xx_calc_dpll_params(refclk, &clock); |
1b894b59 CW |
861 | if (!intel_PLL_is_valid(dev, limit, |
862 | &clock)) | |
d4906093 | 863 | continue; |
1b894b59 CW |
864 | |
865 | this_err = abs(clock.dot - target); | |
d4906093 ML |
866 | if (this_err < err_most) { |
867 | *best_clock = clock; | |
868 | err_most = this_err; | |
869 | max_n = clock.n; | |
870 | found = true; | |
871 | } | |
872 | } | |
873 | } | |
874 | } | |
875 | } | |
2c07245f ZW |
876 | return found; |
877 | } | |
878 | ||
d5dd62bd ID |
879 | /* |
880 | * Check if the calculated PLL configuration is more optimal compared to the | |
881 | * best configuration and error found so far. Return the calculated error. | |
882 | */ | |
883 | static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq, | |
9e2c8475 ACO |
884 | const struct dpll *calculated_clock, |
885 | const struct dpll *best_clock, | |
d5dd62bd ID |
886 | unsigned int best_error_ppm, |
887 | unsigned int *error_ppm) | |
888 | { | |
9ca3ba01 ID |
889 | /* |
890 | * For CHV ignore the error and consider only the P value. | |
891 | * Prefer a bigger P value based on HW requirements. | |
892 | */ | |
893 | if (IS_CHERRYVIEW(dev)) { | |
894 | *error_ppm = 0; | |
895 | ||
896 | return calculated_clock->p > best_clock->p; | |
897 | } | |
898 | ||
24be4e46 ID |
899 | if (WARN_ON_ONCE(!target_freq)) |
900 | return false; | |
901 | ||
d5dd62bd ID |
902 | *error_ppm = div_u64(1000000ULL * |
903 | abs(target_freq - calculated_clock->dot), | |
904 | target_freq); | |
905 | /* | |
906 | * Prefer a better P value over a better (smaller) error if the error | |
907 | * is small. Ensure this preference for future configurations too by | |
908 | * setting the error to 0. | |
909 | */ | |
910 | if (*error_ppm < 100 && calculated_clock->p > best_clock->p) { | |
911 | *error_ppm = 0; | |
912 | ||
913 | return true; | |
914 | } | |
915 | ||
916 | return *error_ppm + 10 < best_error_ppm; | |
917 | } | |
918 | ||
65b3d6a9 ACO |
919 | /* |
920 | * Returns a set of divisors for the desired target clock with the given | |
921 | * refclk, or FALSE. The returned values represent the clock equation: | |
922 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. | |
923 | */ | |
a0c4da24 | 924 | static bool |
1b6f4958 | 925 | vlv_find_best_dpll(const struct intel_limit *limit, |
a93e255f | 926 | struct intel_crtc_state *crtc_state, |
9e2c8475 ACO |
927 | int target, int refclk, struct dpll *match_clock, |
928 | struct dpll *best_clock) | |
a0c4da24 | 929 | { |
a93e255f | 930 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
a919ff14 | 931 | struct drm_device *dev = crtc->base.dev; |
9e2c8475 | 932 | struct dpll clock; |
69e4f900 | 933 | unsigned int bestppm = 1000000; |
27e639bf VS |
934 | /* min update 19.2 MHz */ |
935 | int max_n = min(limit->n.max, refclk / 19200); | |
49e497ef | 936 | bool found = false; |
a0c4da24 | 937 | |
6b4bf1c4 VS |
938 | target *= 5; /* fast clock */ |
939 | ||
940 | memset(best_clock, 0, sizeof(*best_clock)); | |
a0c4da24 JB |
941 | |
942 | /* based on hardware requirement, prefer smaller n to precision */ | |
27e639bf | 943 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
811bbf05 | 944 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
889059d8 | 945 | for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow; |
c1a9ae43 | 946 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
6b4bf1c4 | 947 | clock.p = clock.p1 * clock.p2; |
a0c4da24 | 948 | /* based on hardware requirement, prefer bigger m1,m2 values */ |
6b4bf1c4 | 949 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) { |
d5dd62bd | 950 | unsigned int ppm; |
69e4f900 | 951 | |
6b4bf1c4 VS |
952 | clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n, |
953 | refclk * clock.m1); | |
954 | ||
dccbea3b | 955 | vlv_calc_dpll_params(refclk, &clock); |
43b0ac53 | 956 | |
f01b7962 VS |
957 | if (!intel_PLL_is_valid(dev, limit, |
958 | &clock)) | |
43b0ac53 VS |
959 | continue; |
960 | ||
d5dd62bd ID |
961 | if (!vlv_PLL_is_optimal(dev, target, |
962 | &clock, | |
963 | best_clock, | |
964 | bestppm, &ppm)) | |
965 | continue; | |
6b4bf1c4 | 966 | |
d5dd62bd ID |
967 | *best_clock = clock; |
968 | bestppm = ppm; | |
969 | found = true; | |
a0c4da24 JB |
970 | } |
971 | } | |
972 | } | |
973 | } | |
a0c4da24 | 974 | |
49e497ef | 975 | return found; |
a0c4da24 | 976 | } |
a4fc5ed6 | 977 | |
65b3d6a9 ACO |
978 | /* |
979 | * Returns a set of divisors for the desired target clock with the given | |
980 | * refclk, or FALSE. The returned values represent the clock equation: | |
981 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. | |
982 | */ | |
ef9348c8 | 983 | static bool |
1b6f4958 | 984 | chv_find_best_dpll(const struct intel_limit *limit, |
a93e255f | 985 | struct intel_crtc_state *crtc_state, |
9e2c8475 ACO |
986 | int target, int refclk, struct dpll *match_clock, |
987 | struct dpll *best_clock) | |
ef9348c8 | 988 | { |
a93e255f | 989 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
a919ff14 | 990 | struct drm_device *dev = crtc->base.dev; |
9ca3ba01 | 991 | unsigned int best_error_ppm; |
9e2c8475 | 992 | struct dpll clock; |
ef9348c8 CML |
993 | uint64_t m2; |
994 | int found = false; | |
995 | ||
996 | memset(best_clock, 0, sizeof(*best_clock)); | |
9ca3ba01 | 997 | best_error_ppm = 1000000; |
ef9348c8 CML |
998 | |
999 | /* | |
1000 | * Based on hardware doc, the n always set to 1, and m1 always | |
1001 | * set to 2. If requires to support 200Mhz refclk, we need to | |
1002 | * revisit this because n may not 1 anymore. | |
1003 | */ | |
1004 | clock.n = 1, clock.m1 = 2; | |
1005 | target *= 5; /* fast clock */ | |
1006 | ||
1007 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { | |
1008 | for (clock.p2 = limit->p2.p2_fast; | |
1009 | clock.p2 >= limit->p2.p2_slow; | |
1010 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { | |
9ca3ba01 | 1011 | unsigned int error_ppm; |
ef9348c8 CML |
1012 | |
1013 | clock.p = clock.p1 * clock.p2; | |
1014 | ||
1015 | m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p * | |
1016 | clock.n) << 22, refclk * clock.m1); | |
1017 | ||
1018 | if (m2 > INT_MAX/clock.m1) | |
1019 | continue; | |
1020 | ||
1021 | clock.m2 = m2; | |
1022 | ||
dccbea3b | 1023 | chv_calc_dpll_params(refclk, &clock); |
ef9348c8 CML |
1024 | |
1025 | if (!intel_PLL_is_valid(dev, limit, &clock)) | |
1026 | continue; | |
1027 | ||
9ca3ba01 ID |
1028 | if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock, |
1029 | best_error_ppm, &error_ppm)) | |
1030 | continue; | |
1031 | ||
1032 | *best_clock = clock; | |
1033 | best_error_ppm = error_ppm; | |
1034 | found = true; | |
ef9348c8 CML |
1035 | } |
1036 | } | |
1037 | ||
1038 | return found; | |
1039 | } | |
1040 | ||
5ab7b0b7 | 1041 | bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock, |
9e2c8475 | 1042 | struct dpll *best_clock) |
5ab7b0b7 | 1043 | { |
65b3d6a9 | 1044 | int refclk = 100000; |
1b6f4958 | 1045 | const struct intel_limit *limit = &intel_limits_bxt; |
5ab7b0b7 | 1046 | |
65b3d6a9 | 1047 | return chv_find_best_dpll(limit, crtc_state, |
5ab7b0b7 ID |
1048 | target_clock, refclk, NULL, best_clock); |
1049 | } | |
1050 | ||
20ddf665 VS |
1051 | bool intel_crtc_active(struct drm_crtc *crtc) |
1052 | { | |
1053 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
1054 | ||
1055 | /* Be paranoid as we can arrive here with only partial | |
1056 | * state retrieved from the hardware during setup. | |
1057 | * | |
241bfc38 | 1058 | * We can ditch the adjusted_mode.crtc_clock check as soon |
20ddf665 VS |
1059 | * as Haswell has gained clock readout/fastboot support. |
1060 | * | |
66e514c1 | 1061 | * We can ditch the crtc->primary->fb check as soon as we can |
20ddf665 | 1062 | * properly reconstruct framebuffers. |
c3d1f436 MR |
1063 | * |
1064 | * FIXME: The intel_crtc->active here should be switched to | |
1065 | * crtc->state->active once we have proper CRTC states wired up | |
1066 | * for atomic. | |
20ddf665 | 1067 | */ |
c3d1f436 | 1068 | return intel_crtc->active && crtc->primary->state->fb && |
6e3c9717 | 1069 | intel_crtc->config->base.adjusted_mode.crtc_clock; |
20ddf665 VS |
1070 | } |
1071 | ||
a5c961d1 PZ |
1072 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, |
1073 | enum pipe pipe) | |
1074 | { | |
1075 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
1076 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
1077 | ||
6e3c9717 | 1078 | return intel_crtc->config->cpu_transcoder; |
a5c961d1 PZ |
1079 | } |
1080 | ||
fbf49ea2 VS |
1081 | static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe) |
1082 | { | |
1083 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f0f59a00 | 1084 | i915_reg_t reg = PIPEDSL(pipe); |
fbf49ea2 VS |
1085 | u32 line1, line2; |
1086 | u32 line_mask; | |
1087 | ||
1088 | if (IS_GEN2(dev)) | |
1089 | line_mask = DSL_LINEMASK_GEN2; | |
1090 | else | |
1091 | line_mask = DSL_LINEMASK_GEN3; | |
1092 | ||
1093 | line1 = I915_READ(reg) & line_mask; | |
6adfb1ef | 1094 | msleep(5); |
fbf49ea2 VS |
1095 | line2 = I915_READ(reg) & line_mask; |
1096 | ||
1097 | return line1 == line2; | |
1098 | } | |
1099 | ||
ab7ad7f6 KP |
1100 | /* |
1101 | * intel_wait_for_pipe_off - wait for pipe to turn off | |
575f7ab7 | 1102 | * @crtc: crtc whose pipe to wait for |
9d0498a2 JB |
1103 | * |
1104 | * After disabling a pipe, we can't wait for vblank in the usual way, | |
1105 | * spinning on the vblank interrupt status bit, since we won't actually | |
1106 | * see an interrupt when the pipe is disabled. | |
1107 | * | |
ab7ad7f6 KP |
1108 | * On Gen4 and above: |
1109 | * wait for the pipe register state bit to turn off | |
1110 | * | |
1111 | * Otherwise: | |
1112 | * wait for the display line value to settle (it usually | |
1113 | * ends up stopping at the start of the next frame). | |
58e10eb9 | 1114 | * |
9d0498a2 | 1115 | */ |
575f7ab7 | 1116 | static void intel_wait_for_pipe_off(struct intel_crtc *crtc) |
9d0498a2 | 1117 | { |
575f7ab7 | 1118 | struct drm_device *dev = crtc->base.dev; |
9d0498a2 | 1119 | struct drm_i915_private *dev_priv = dev->dev_private; |
6e3c9717 | 1120 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
575f7ab7 | 1121 | enum pipe pipe = crtc->pipe; |
ab7ad7f6 KP |
1122 | |
1123 | if (INTEL_INFO(dev)->gen >= 4) { | |
f0f59a00 | 1124 | i915_reg_t reg = PIPECONF(cpu_transcoder); |
ab7ad7f6 KP |
1125 | |
1126 | /* Wait for the Pipe State to go off */ | |
58e10eb9 CW |
1127 | if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0, |
1128 | 100)) | |
284637d9 | 1129 | WARN(1, "pipe_off wait timed out\n"); |
ab7ad7f6 | 1130 | } else { |
ab7ad7f6 | 1131 | /* Wait for the display line to settle */ |
fbf49ea2 | 1132 | if (wait_for(pipe_dsl_stopped(dev, pipe), 100)) |
284637d9 | 1133 | WARN(1, "pipe_off wait timed out\n"); |
ab7ad7f6 | 1134 | } |
79e53945 JB |
1135 | } |
1136 | ||
b24e7179 | 1137 | /* Only for pre-ILK configs */ |
55607e8a DV |
1138 | void assert_pll(struct drm_i915_private *dev_priv, |
1139 | enum pipe pipe, bool state) | |
b24e7179 | 1140 | { |
b24e7179 JB |
1141 | u32 val; |
1142 | bool cur_state; | |
1143 | ||
649636ef | 1144 | val = I915_READ(DPLL(pipe)); |
b24e7179 | 1145 | cur_state = !!(val & DPLL_VCO_ENABLE); |
e2c719b7 | 1146 | I915_STATE_WARN(cur_state != state, |
b24e7179 | 1147 | "PLL state assertion failure (expected %s, current %s)\n", |
87ad3212 | 1148 | onoff(state), onoff(cur_state)); |
b24e7179 | 1149 | } |
b24e7179 | 1150 | |
23538ef1 | 1151 | /* XXX: the dsi pll is shared between MIPI DSI ports */ |
8563b1e8 | 1152 | void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state) |
23538ef1 JN |
1153 | { |
1154 | u32 val; | |
1155 | bool cur_state; | |
1156 | ||
a580516d | 1157 | mutex_lock(&dev_priv->sb_lock); |
23538ef1 | 1158 | val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); |
a580516d | 1159 | mutex_unlock(&dev_priv->sb_lock); |
23538ef1 JN |
1160 | |
1161 | cur_state = val & DSI_PLL_VCO_EN; | |
e2c719b7 | 1162 | I915_STATE_WARN(cur_state != state, |
23538ef1 | 1163 | "DSI PLL state assertion failure (expected %s, current %s)\n", |
87ad3212 | 1164 | onoff(state), onoff(cur_state)); |
23538ef1 | 1165 | } |
23538ef1 | 1166 | |
040484af JB |
1167 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, |
1168 | enum pipe pipe, bool state) | |
1169 | { | |
040484af | 1170 | bool cur_state; |
ad80a810 PZ |
1171 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
1172 | pipe); | |
040484af | 1173 | |
2d1fe073 | 1174 | if (HAS_DDI(dev_priv)) { |
affa9354 | 1175 | /* DDI does not have a specific FDI_TX register */ |
649636ef | 1176 | u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
ad80a810 | 1177 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
bf507ef7 | 1178 | } else { |
649636ef | 1179 | u32 val = I915_READ(FDI_TX_CTL(pipe)); |
bf507ef7 ED |
1180 | cur_state = !!(val & FDI_TX_ENABLE); |
1181 | } | |
e2c719b7 | 1182 | I915_STATE_WARN(cur_state != state, |
040484af | 1183 | "FDI TX state assertion failure (expected %s, current %s)\n", |
87ad3212 | 1184 | onoff(state), onoff(cur_state)); |
040484af JB |
1185 | } |
1186 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) | |
1187 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) | |
1188 | ||
1189 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, | |
1190 | enum pipe pipe, bool state) | |
1191 | { | |
040484af JB |
1192 | u32 val; |
1193 | bool cur_state; | |
1194 | ||
649636ef | 1195 | val = I915_READ(FDI_RX_CTL(pipe)); |
d63fa0dc | 1196 | cur_state = !!(val & FDI_RX_ENABLE); |
e2c719b7 | 1197 | I915_STATE_WARN(cur_state != state, |
040484af | 1198 | "FDI RX state assertion failure (expected %s, current %s)\n", |
87ad3212 | 1199 | onoff(state), onoff(cur_state)); |
040484af JB |
1200 | } |
1201 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) | |
1202 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) | |
1203 | ||
1204 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, | |
1205 | enum pipe pipe) | |
1206 | { | |
040484af JB |
1207 | u32 val; |
1208 | ||
1209 | /* ILK FDI PLL is always enabled */ | |
7e22dbbb | 1210 | if (IS_GEN5(dev_priv)) |
040484af JB |
1211 | return; |
1212 | ||
bf507ef7 | 1213 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
2d1fe073 | 1214 | if (HAS_DDI(dev_priv)) |
bf507ef7 ED |
1215 | return; |
1216 | ||
649636ef | 1217 | val = I915_READ(FDI_TX_CTL(pipe)); |
e2c719b7 | 1218 | I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n"); |
040484af JB |
1219 | } |
1220 | ||
55607e8a DV |
1221 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, |
1222 | enum pipe pipe, bool state) | |
040484af | 1223 | { |
040484af | 1224 | u32 val; |
55607e8a | 1225 | bool cur_state; |
040484af | 1226 | |
649636ef | 1227 | val = I915_READ(FDI_RX_CTL(pipe)); |
55607e8a | 1228 | cur_state = !!(val & FDI_RX_PLL_ENABLE); |
e2c719b7 | 1229 | I915_STATE_WARN(cur_state != state, |
55607e8a | 1230 | "FDI RX PLL assertion failure (expected %s, current %s)\n", |
87ad3212 | 1231 | onoff(state), onoff(cur_state)); |
040484af JB |
1232 | } |
1233 | ||
b680c37a DV |
1234 | void assert_panel_unlocked(struct drm_i915_private *dev_priv, |
1235 | enum pipe pipe) | |
ea0760cf | 1236 | { |
bedd4dba | 1237 | struct drm_device *dev = dev_priv->dev; |
f0f59a00 | 1238 | i915_reg_t pp_reg; |
ea0760cf JB |
1239 | u32 val; |
1240 | enum pipe panel_pipe = PIPE_A; | |
0de3b485 | 1241 | bool locked = true; |
ea0760cf | 1242 | |
bedd4dba JN |
1243 | if (WARN_ON(HAS_DDI(dev))) |
1244 | return; | |
1245 | ||
1246 | if (HAS_PCH_SPLIT(dev)) { | |
1247 | u32 port_sel; | |
1248 | ||
ea0760cf | 1249 | pp_reg = PCH_PP_CONTROL; |
bedd4dba JN |
1250 | port_sel = I915_READ(PCH_PP_ON_DELAYS) & PANEL_PORT_SELECT_MASK; |
1251 | ||
1252 | if (port_sel == PANEL_PORT_SELECT_LVDS && | |
1253 | I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT) | |
1254 | panel_pipe = PIPE_B; | |
1255 | /* XXX: else fix for eDP */ | |
666a4537 | 1256 | } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
bedd4dba JN |
1257 | /* presumably write lock depends on pipe, not port select */ |
1258 | pp_reg = VLV_PIPE_PP_CONTROL(pipe); | |
1259 | panel_pipe = pipe; | |
ea0760cf JB |
1260 | } else { |
1261 | pp_reg = PP_CONTROL; | |
bedd4dba JN |
1262 | if (I915_READ(LVDS) & LVDS_PIPEB_SELECT) |
1263 | panel_pipe = PIPE_B; | |
ea0760cf JB |
1264 | } |
1265 | ||
1266 | val = I915_READ(pp_reg); | |
1267 | if (!(val & PANEL_POWER_ON) || | |
ec49ba2d | 1268 | ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) |
ea0760cf JB |
1269 | locked = false; |
1270 | ||
e2c719b7 | 1271 | I915_STATE_WARN(panel_pipe == pipe && locked, |
ea0760cf | 1272 | "panel assertion failure, pipe %c regs locked\n", |
9db4a9c7 | 1273 | pipe_name(pipe)); |
ea0760cf JB |
1274 | } |
1275 | ||
93ce0ba6 JN |
1276 | static void assert_cursor(struct drm_i915_private *dev_priv, |
1277 | enum pipe pipe, bool state) | |
1278 | { | |
1279 | struct drm_device *dev = dev_priv->dev; | |
1280 | bool cur_state; | |
1281 | ||
d9d82081 | 1282 | if (IS_845G(dev) || IS_I865G(dev)) |
0b87c24e | 1283 | cur_state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE; |
d9d82081 | 1284 | else |
5efb3e28 | 1285 | cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE; |
93ce0ba6 | 1286 | |
e2c719b7 | 1287 | I915_STATE_WARN(cur_state != state, |
93ce0ba6 | 1288 | "cursor on pipe %c assertion failure (expected %s, current %s)\n", |
87ad3212 | 1289 | pipe_name(pipe), onoff(state), onoff(cur_state)); |
93ce0ba6 JN |
1290 | } |
1291 | #define assert_cursor_enabled(d, p) assert_cursor(d, p, true) | |
1292 | #define assert_cursor_disabled(d, p) assert_cursor(d, p, false) | |
1293 | ||
b840d907 JB |
1294 | void assert_pipe(struct drm_i915_private *dev_priv, |
1295 | enum pipe pipe, bool state) | |
b24e7179 | 1296 | { |
63d7bbe9 | 1297 | bool cur_state; |
702e7a56 PZ |
1298 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
1299 | pipe); | |
4feed0eb | 1300 | enum intel_display_power_domain power_domain; |
b24e7179 | 1301 | |
b6b5d049 VS |
1302 | /* if we need the pipe quirk it must be always on */ |
1303 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || | |
1304 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
8e636784 DV |
1305 | state = true; |
1306 | ||
4feed0eb ID |
1307 | power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); |
1308 | if (intel_display_power_get_if_enabled(dev_priv, power_domain)) { | |
649636ef | 1309 | u32 val = I915_READ(PIPECONF(cpu_transcoder)); |
69310161 | 1310 | cur_state = !!(val & PIPECONF_ENABLE); |
4feed0eb ID |
1311 | |
1312 | intel_display_power_put(dev_priv, power_domain); | |
1313 | } else { | |
1314 | cur_state = false; | |
69310161 PZ |
1315 | } |
1316 | ||
e2c719b7 | 1317 | I915_STATE_WARN(cur_state != state, |
63d7bbe9 | 1318 | "pipe %c assertion failure (expected %s, current %s)\n", |
87ad3212 | 1319 | pipe_name(pipe), onoff(state), onoff(cur_state)); |
b24e7179 JB |
1320 | } |
1321 | ||
931872fc CW |
1322 | static void assert_plane(struct drm_i915_private *dev_priv, |
1323 | enum plane plane, bool state) | |
b24e7179 | 1324 | { |
b24e7179 | 1325 | u32 val; |
931872fc | 1326 | bool cur_state; |
b24e7179 | 1327 | |
649636ef | 1328 | val = I915_READ(DSPCNTR(plane)); |
931872fc | 1329 | cur_state = !!(val & DISPLAY_PLANE_ENABLE); |
e2c719b7 | 1330 | I915_STATE_WARN(cur_state != state, |
931872fc | 1331 | "plane %c assertion failure (expected %s, current %s)\n", |
87ad3212 | 1332 | plane_name(plane), onoff(state), onoff(cur_state)); |
b24e7179 JB |
1333 | } |
1334 | ||
931872fc CW |
1335 | #define assert_plane_enabled(d, p) assert_plane(d, p, true) |
1336 | #define assert_plane_disabled(d, p) assert_plane(d, p, false) | |
1337 | ||
b24e7179 JB |
1338 | static void assert_planes_disabled(struct drm_i915_private *dev_priv, |
1339 | enum pipe pipe) | |
1340 | { | |
653e1026 | 1341 | struct drm_device *dev = dev_priv->dev; |
649636ef | 1342 | int i; |
b24e7179 | 1343 | |
653e1026 VS |
1344 | /* Primary planes are fixed to pipes on gen4+ */ |
1345 | if (INTEL_INFO(dev)->gen >= 4) { | |
649636ef | 1346 | u32 val = I915_READ(DSPCNTR(pipe)); |
e2c719b7 | 1347 | I915_STATE_WARN(val & DISPLAY_PLANE_ENABLE, |
28c05794 AJ |
1348 | "plane %c assertion failure, should be disabled but not\n", |
1349 | plane_name(pipe)); | |
19ec1358 | 1350 | return; |
28c05794 | 1351 | } |
19ec1358 | 1352 | |
b24e7179 | 1353 | /* Need to check both planes against the pipe */ |
055e393f | 1354 | for_each_pipe(dev_priv, i) { |
649636ef VS |
1355 | u32 val = I915_READ(DSPCNTR(i)); |
1356 | enum pipe cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> | |
b24e7179 | 1357 | DISPPLANE_SEL_PIPE_SHIFT; |
e2c719b7 | 1358 | I915_STATE_WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe, |
9db4a9c7 JB |
1359 | "plane %c assertion failure, should be off on pipe %c but is still active\n", |
1360 | plane_name(i), pipe_name(pipe)); | |
b24e7179 JB |
1361 | } |
1362 | } | |
1363 | ||
19332d7a JB |
1364 | static void assert_sprites_disabled(struct drm_i915_private *dev_priv, |
1365 | enum pipe pipe) | |
1366 | { | |
20674eef | 1367 | struct drm_device *dev = dev_priv->dev; |
649636ef | 1368 | int sprite; |
19332d7a | 1369 | |
7feb8b88 | 1370 | if (INTEL_INFO(dev)->gen >= 9) { |
3bdcfc0c | 1371 | for_each_sprite(dev_priv, pipe, sprite) { |
649636ef | 1372 | u32 val = I915_READ(PLANE_CTL(pipe, sprite)); |
e2c719b7 | 1373 | I915_STATE_WARN(val & PLANE_CTL_ENABLE, |
7feb8b88 DL |
1374 | "plane %d assertion failure, should be off on pipe %c but is still active\n", |
1375 | sprite, pipe_name(pipe)); | |
1376 | } | |
666a4537 | 1377 | } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
3bdcfc0c | 1378 | for_each_sprite(dev_priv, pipe, sprite) { |
649636ef | 1379 | u32 val = I915_READ(SPCNTR(pipe, sprite)); |
e2c719b7 | 1380 | I915_STATE_WARN(val & SP_ENABLE, |
20674eef | 1381 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
1fe47785 | 1382 | sprite_name(pipe, sprite), pipe_name(pipe)); |
20674eef VS |
1383 | } |
1384 | } else if (INTEL_INFO(dev)->gen >= 7) { | |
649636ef | 1385 | u32 val = I915_READ(SPRCTL(pipe)); |
e2c719b7 | 1386 | I915_STATE_WARN(val & SPRITE_ENABLE, |
06da8da2 | 1387 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
20674eef VS |
1388 | plane_name(pipe), pipe_name(pipe)); |
1389 | } else if (INTEL_INFO(dev)->gen >= 5) { | |
649636ef | 1390 | u32 val = I915_READ(DVSCNTR(pipe)); |
e2c719b7 | 1391 | I915_STATE_WARN(val & DVS_ENABLE, |
06da8da2 | 1392 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
20674eef | 1393 | plane_name(pipe), pipe_name(pipe)); |
19332d7a JB |
1394 | } |
1395 | } | |
1396 | ||
08c71e5e VS |
1397 | static void assert_vblank_disabled(struct drm_crtc *crtc) |
1398 | { | |
e2c719b7 | 1399 | if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0)) |
08c71e5e VS |
1400 | drm_crtc_vblank_put(crtc); |
1401 | } | |
1402 | ||
7abd4b35 ACO |
1403 | void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, |
1404 | enum pipe pipe) | |
92f2584a | 1405 | { |
92f2584a JB |
1406 | u32 val; |
1407 | bool enabled; | |
1408 | ||
649636ef | 1409 | val = I915_READ(PCH_TRANSCONF(pipe)); |
92f2584a | 1410 | enabled = !!(val & TRANS_ENABLE); |
e2c719b7 | 1411 | I915_STATE_WARN(enabled, |
9db4a9c7 JB |
1412 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
1413 | pipe_name(pipe)); | |
92f2584a JB |
1414 | } |
1415 | ||
4e634389 KP |
1416 | static bool dp_pipe_enabled(struct drm_i915_private *dev_priv, |
1417 | enum pipe pipe, u32 port_sel, u32 val) | |
f0575e92 KP |
1418 | { |
1419 | if ((val & DP_PORT_EN) == 0) | |
1420 | return false; | |
1421 | ||
2d1fe073 | 1422 | if (HAS_PCH_CPT(dev_priv)) { |
f0f59a00 | 1423 | u32 trans_dp_ctl = I915_READ(TRANS_DP_CTL(pipe)); |
f0575e92 KP |
1424 | if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel) |
1425 | return false; | |
2d1fe073 | 1426 | } else if (IS_CHERRYVIEW(dev_priv)) { |
44f37d1f CML |
1427 | if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe)) |
1428 | return false; | |
f0575e92 KP |
1429 | } else { |
1430 | if ((val & DP_PIPE_MASK) != (pipe << 30)) | |
1431 | return false; | |
1432 | } | |
1433 | return true; | |
1434 | } | |
1435 | ||
1519b995 KP |
1436 | static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv, |
1437 | enum pipe pipe, u32 val) | |
1438 | { | |
dc0fa718 | 1439 | if ((val & SDVO_ENABLE) == 0) |
1519b995 KP |
1440 | return false; |
1441 | ||
2d1fe073 | 1442 | if (HAS_PCH_CPT(dev_priv)) { |
dc0fa718 | 1443 | if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe)) |
1519b995 | 1444 | return false; |
2d1fe073 | 1445 | } else if (IS_CHERRYVIEW(dev_priv)) { |
44f37d1f CML |
1446 | if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe)) |
1447 | return false; | |
1519b995 | 1448 | } else { |
dc0fa718 | 1449 | if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe)) |
1519b995 KP |
1450 | return false; |
1451 | } | |
1452 | return true; | |
1453 | } | |
1454 | ||
1455 | static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv, | |
1456 | enum pipe pipe, u32 val) | |
1457 | { | |
1458 | if ((val & LVDS_PORT_EN) == 0) | |
1459 | return false; | |
1460 | ||
2d1fe073 | 1461 | if (HAS_PCH_CPT(dev_priv)) { |
1519b995 KP |
1462 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
1463 | return false; | |
1464 | } else { | |
1465 | if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe)) | |
1466 | return false; | |
1467 | } | |
1468 | return true; | |
1469 | } | |
1470 | ||
1471 | static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv, | |
1472 | enum pipe pipe, u32 val) | |
1473 | { | |
1474 | if ((val & ADPA_DAC_ENABLE) == 0) | |
1475 | return false; | |
2d1fe073 | 1476 | if (HAS_PCH_CPT(dev_priv)) { |
1519b995 KP |
1477 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
1478 | return false; | |
1479 | } else { | |
1480 | if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe)) | |
1481 | return false; | |
1482 | } | |
1483 | return true; | |
1484 | } | |
1485 | ||
291906f1 | 1486 | static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv, |
f0f59a00 VS |
1487 | enum pipe pipe, i915_reg_t reg, |
1488 | u32 port_sel) | |
291906f1 | 1489 | { |
47a05eca | 1490 | u32 val = I915_READ(reg); |
e2c719b7 | 1491 | I915_STATE_WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val), |
291906f1 | 1492 | "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n", |
f0f59a00 | 1493 | i915_mmio_reg_offset(reg), pipe_name(pipe)); |
de9a35ab | 1494 | |
2d1fe073 | 1495 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && (val & DP_PORT_EN) == 0 |
75c5da27 | 1496 | && (val & DP_PIPEB_SELECT), |
de9a35ab | 1497 | "IBX PCH dp port still using transcoder B\n"); |
291906f1 JB |
1498 | } |
1499 | ||
1500 | static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv, | |
f0f59a00 | 1501 | enum pipe pipe, i915_reg_t reg) |
291906f1 | 1502 | { |
47a05eca | 1503 | u32 val = I915_READ(reg); |
e2c719b7 | 1504 | I915_STATE_WARN(hdmi_pipe_enabled(dev_priv, pipe, val), |
23c99e77 | 1505 | "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n", |
f0f59a00 | 1506 | i915_mmio_reg_offset(reg), pipe_name(pipe)); |
de9a35ab | 1507 | |
2d1fe073 | 1508 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && (val & SDVO_ENABLE) == 0 |
75c5da27 | 1509 | && (val & SDVO_PIPE_B_SELECT), |
de9a35ab | 1510 | "IBX PCH hdmi port still using transcoder B\n"); |
291906f1 JB |
1511 | } |
1512 | ||
1513 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, | |
1514 | enum pipe pipe) | |
1515 | { | |
291906f1 | 1516 | u32 val; |
291906f1 | 1517 | |
f0575e92 KP |
1518 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B); |
1519 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C); | |
1520 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D); | |
291906f1 | 1521 | |
649636ef | 1522 | val = I915_READ(PCH_ADPA); |
e2c719b7 | 1523 | I915_STATE_WARN(adpa_pipe_enabled(dev_priv, pipe, val), |
291906f1 | 1524 | "PCH VGA enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1525 | pipe_name(pipe)); |
291906f1 | 1526 | |
649636ef | 1527 | val = I915_READ(PCH_LVDS); |
e2c719b7 | 1528 | I915_STATE_WARN(lvds_pipe_enabled(dev_priv, pipe, val), |
291906f1 | 1529 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1530 | pipe_name(pipe)); |
291906f1 | 1531 | |
e2debe91 PZ |
1532 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB); |
1533 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC); | |
1534 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID); | |
291906f1 JB |
1535 | } |
1536 | ||
cd2d34d9 VS |
1537 | static void _vlv_enable_pll(struct intel_crtc *crtc, |
1538 | const struct intel_crtc_state *pipe_config) | |
1539 | { | |
1540 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); | |
1541 | enum pipe pipe = crtc->pipe; | |
1542 | ||
1543 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); | |
1544 | POSTING_READ(DPLL(pipe)); | |
1545 | udelay(150); | |
1546 | ||
1547 | if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) | |
1548 | DRM_ERROR("DPLL %d failed to lock\n", pipe); | |
1549 | } | |
1550 | ||
d288f65f | 1551 | static void vlv_enable_pll(struct intel_crtc *crtc, |
5cec258b | 1552 | const struct intel_crtc_state *pipe_config) |
87442f73 | 1553 | { |
cd2d34d9 | 1554 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
8bd3f301 | 1555 | enum pipe pipe = crtc->pipe; |
87442f73 | 1556 | |
8bd3f301 | 1557 | assert_pipe_disabled(dev_priv, pipe); |
87442f73 | 1558 | |
87442f73 | 1559 | /* PLL is protected by panel, make sure we can write it */ |
7d1a83cb | 1560 | assert_panel_unlocked(dev_priv, pipe); |
87442f73 | 1561 | |
cd2d34d9 VS |
1562 | if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) |
1563 | _vlv_enable_pll(crtc, pipe_config); | |
426115cf | 1564 | |
8bd3f301 VS |
1565 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
1566 | POSTING_READ(DPLL_MD(pipe)); | |
87442f73 DV |
1567 | } |
1568 | ||
cd2d34d9 VS |
1569 | |
1570 | static void _chv_enable_pll(struct intel_crtc *crtc, | |
1571 | const struct intel_crtc_state *pipe_config) | |
9d556c99 | 1572 | { |
cd2d34d9 | 1573 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
8bd3f301 | 1574 | enum pipe pipe = crtc->pipe; |
9d556c99 | 1575 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
9d556c99 CML |
1576 | u32 tmp; |
1577 | ||
a580516d | 1578 | mutex_lock(&dev_priv->sb_lock); |
9d556c99 CML |
1579 | |
1580 | /* Enable back the 10bit clock to display controller */ | |
1581 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); | |
1582 | tmp |= DPIO_DCLKP_EN; | |
1583 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp); | |
1584 | ||
54433e91 VS |
1585 | mutex_unlock(&dev_priv->sb_lock); |
1586 | ||
9d556c99 CML |
1587 | /* |
1588 | * Need to wait > 100ns between dclkp clock enable bit and PLL enable. | |
1589 | */ | |
1590 | udelay(1); | |
1591 | ||
1592 | /* Enable PLL */ | |
d288f65f | 1593 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
9d556c99 CML |
1594 | |
1595 | /* Check PLL is locked */ | |
a11b0703 | 1596 | if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) |
9d556c99 | 1597 | DRM_ERROR("PLL %d failed to lock\n", pipe); |
cd2d34d9 VS |
1598 | } |
1599 | ||
1600 | static void chv_enable_pll(struct intel_crtc *crtc, | |
1601 | const struct intel_crtc_state *pipe_config) | |
1602 | { | |
1603 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); | |
1604 | enum pipe pipe = crtc->pipe; | |
1605 | ||
1606 | assert_pipe_disabled(dev_priv, pipe); | |
1607 | ||
1608 | /* PLL is protected by panel, make sure we can write it */ | |
1609 | assert_panel_unlocked(dev_priv, pipe); | |
1610 | ||
1611 | if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) | |
1612 | _chv_enable_pll(crtc, pipe_config); | |
9d556c99 | 1613 | |
c231775c VS |
1614 | if (pipe != PIPE_A) { |
1615 | /* | |
1616 | * WaPixelRepeatModeFixForC0:chv | |
1617 | * | |
1618 | * DPLLCMD is AWOL. Use chicken bits to propagate | |
1619 | * the value from DPLLBMD to either pipe B or C. | |
1620 | */ | |
1621 | I915_WRITE(CBR4_VLV, pipe == PIPE_B ? CBR_DPLLBMD_PIPE_B : CBR_DPLLBMD_PIPE_C); | |
1622 | I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md); | |
1623 | I915_WRITE(CBR4_VLV, 0); | |
1624 | dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md; | |
1625 | ||
1626 | /* | |
1627 | * DPLLB VGA mode also seems to cause problems. | |
1628 | * We should always have it disabled. | |
1629 | */ | |
1630 | WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0); | |
1631 | } else { | |
1632 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); | |
1633 | POSTING_READ(DPLL_MD(pipe)); | |
1634 | } | |
9d556c99 CML |
1635 | } |
1636 | ||
1c4e0274 VS |
1637 | static int intel_num_dvo_pipes(struct drm_device *dev) |
1638 | { | |
1639 | struct intel_crtc *crtc; | |
1640 | int count = 0; | |
1641 | ||
1642 | for_each_intel_crtc(dev, crtc) | |
3538b9df | 1643 | count += crtc->base.state->active && |
409ee761 | 1644 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO); |
1c4e0274 VS |
1645 | |
1646 | return count; | |
1647 | } | |
1648 | ||
66e3d5c0 | 1649 | static void i9xx_enable_pll(struct intel_crtc *crtc) |
63d7bbe9 | 1650 | { |
66e3d5c0 DV |
1651 | struct drm_device *dev = crtc->base.dev; |
1652 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f0f59a00 | 1653 | i915_reg_t reg = DPLL(crtc->pipe); |
6e3c9717 | 1654 | u32 dpll = crtc->config->dpll_hw_state.dpll; |
63d7bbe9 | 1655 | |
66e3d5c0 | 1656 | assert_pipe_disabled(dev_priv, crtc->pipe); |
58c6eaa2 | 1657 | |
63d7bbe9 | 1658 | /* PLL is protected by panel, make sure we can write it */ |
66e3d5c0 DV |
1659 | if (IS_MOBILE(dev) && !IS_I830(dev)) |
1660 | assert_panel_unlocked(dev_priv, crtc->pipe); | |
63d7bbe9 | 1661 | |
1c4e0274 VS |
1662 | /* Enable DVO 2x clock on both PLLs if necessary */ |
1663 | if (IS_I830(dev) && intel_num_dvo_pipes(dev) > 0) { | |
1664 | /* | |
1665 | * It appears to be important that we don't enable this | |
1666 | * for the current pipe before otherwise configuring the | |
1667 | * PLL. No idea how this should be handled if multiple | |
1668 | * DVO outputs are enabled simultaneosly. | |
1669 | */ | |
1670 | dpll |= DPLL_DVO_2X_MODE; | |
1671 | I915_WRITE(DPLL(!crtc->pipe), | |
1672 | I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE); | |
1673 | } | |
66e3d5c0 | 1674 | |
c2b63374 VS |
1675 | /* |
1676 | * Apparently we need to have VGA mode enabled prior to changing | |
1677 | * the P1/P2 dividers. Otherwise the DPLL will keep using the old | |
1678 | * dividers, even though the register value does change. | |
1679 | */ | |
1680 | I915_WRITE(reg, 0); | |
1681 | ||
8e7a65aa VS |
1682 | I915_WRITE(reg, dpll); |
1683 | ||
66e3d5c0 DV |
1684 | /* Wait for the clocks to stabilize. */ |
1685 | POSTING_READ(reg); | |
1686 | udelay(150); | |
1687 | ||
1688 | if (INTEL_INFO(dev)->gen >= 4) { | |
1689 | I915_WRITE(DPLL_MD(crtc->pipe), | |
6e3c9717 | 1690 | crtc->config->dpll_hw_state.dpll_md); |
66e3d5c0 DV |
1691 | } else { |
1692 | /* The pixel multiplier can only be updated once the | |
1693 | * DPLL is enabled and the clocks are stable. | |
1694 | * | |
1695 | * So write it again. | |
1696 | */ | |
1697 | I915_WRITE(reg, dpll); | |
1698 | } | |
63d7bbe9 JB |
1699 | |
1700 | /* We do this three times for luck */ | |
66e3d5c0 | 1701 | I915_WRITE(reg, dpll); |
63d7bbe9 JB |
1702 | POSTING_READ(reg); |
1703 | udelay(150); /* wait for warmup */ | |
66e3d5c0 | 1704 | I915_WRITE(reg, dpll); |
63d7bbe9 JB |
1705 | POSTING_READ(reg); |
1706 | udelay(150); /* wait for warmup */ | |
66e3d5c0 | 1707 | I915_WRITE(reg, dpll); |
63d7bbe9 JB |
1708 | POSTING_READ(reg); |
1709 | udelay(150); /* wait for warmup */ | |
1710 | } | |
1711 | ||
1712 | /** | |
50b44a44 | 1713 | * i9xx_disable_pll - disable a PLL |
63d7bbe9 JB |
1714 | * @dev_priv: i915 private structure |
1715 | * @pipe: pipe PLL to disable | |
1716 | * | |
1717 | * Disable the PLL for @pipe, making sure the pipe is off first. | |
1718 | * | |
1719 | * Note! This is for pre-ILK only. | |
1720 | */ | |
1c4e0274 | 1721 | static void i9xx_disable_pll(struct intel_crtc *crtc) |
63d7bbe9 | 1722 | { |
1c4e0274 VS |
1723 | struct drm_device *dev = crtc->base.dev; |
1724 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1725 | enum pipe pipe = crtc->pipe; | |
1726 | ||
1727 | /* Disable DVO 2x clock on both PLLs if necessary */ | |
1728 | if (IS_I830(dev) && | |
409ee761 | 1729 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO) && |
3538b9df | 1730 | !intel_num_dvo_pipes(dev)) { |
1c4e0274 VS |
1731 | I915_WRITE(DPLL(PIPE_B), |
1732 | I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE); | |
1733 | I915_WRITE(DPLL(PIPE_A), | |
1734 | I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE); | |
1735 | } | |
1736 | ||
b6b5d049 VS |
1737 | /* Don't disable pipe or pipe PLLs if needed */ |
1738 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || | |
1739 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
63d7bbe9 JB |
1740 | return; |
1741 | ||
1742 | /* Make sure the pipe isn't still relying on us */ | |
1743 | assert_pipe_disabled(dev_priv, pipe); | |
1744 | ||
b8afb911 | 1745 | I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS); |
50b44a44 | 1746 | POSTING_READ(DPLL(pipe)); |
63d7bbe9 JB |
1747 | } |
1748 | ||
f6071166 JB |
1749 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
1750 | { | |
b8afb911 | 1751 | u32 val; |
f6071166 JB |
1752 | |
1753 | /* Make sure the pipe isn't still relying on us */ | |
1754 | assert_pipe_disabled(dev_priv, pipe); | |
1755 | ||
03ed5cbf VS |
1756 | val = DPLL_INTEGRATED_REF_CLK_VLV | |
1757 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; | |
1758 | if (pipe != PIPE_A) | |
1759 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
1760 | ||
f6071166 JB |
1761 | I915_WRITE(DPLL(pipe), val); |
1762 | POSTING_READ(DPLL(pipe)); | |
076ed3b2 CML |
1763 | } |
1764 | ||
1765 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) | |
1766 | { | |
d752048d | 1767 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
076ed3b2 CML |
1768 | u32 val; |
1769 | ||
a11b0703 VS |
1770 | /* Make sure the pipe isn't still relying on us */ |
1771 | assert_pipe_disabled(dev_priv, pipe); | |
076ed3b2 | 1772 | |
60bfe44f VS |
1773 | val = DPLL_SSC_REF_CLK_CHV | |
1774 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; | |
a11b0703 VS |
1775 | if (pipe != PIPE_A) |
1776 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
03ed5cbf | 1777 | |
a11b0703 VS |
1778 | I915_WRITE(DPLL(pipe), val); |
1779 | POSTING_READ(DPLL(pipe)); | |
d752048d | 1780 | |
a580516d | 1781 | mutex_lock(&dev_priv->sb_lock); |
d752048d VS |
1782 | |
1783 | /* Disable 10bit clock to display controller */ | |
1784 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); | |
1785 | val &= ~DPIO_DCLKP_EN; | |
1786 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); | |
1787 | ||
a580516d | 1788 | mutex_unlock(&dev_priv->sb_lock); |
f6071166 JB |
1789 | } |
1790 | ||
e4607fcf | 1791 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, |
9b6de0a1 VS |
1792 | struct intel_digital_port *dport, |
1793 | unsigned int expected_mask) | |
89b667f8 JB |
1794 | { |
1795 | u32 port_mask; | |
f0f59a00 | 1796 | i915_reg_t dpll_reg; |
89b667f8 | 1797 | |
e4607fcf CML |
1798 | switch (dport->port) { |
1799 | case PORT_B: | |
89b667f8 | 1800 | port_mask = DPLL_PORTB_READY_MASK; |
00fc31b7 | 1801 | dpll_reg = DPLL(0); |
e4607fcf CML |
1802 | break; |
1803 | case PORT_C: | |
89b667f8 | 1804 | port_mask = DPLL_PORTC_READY_MASK; |
00fc31b7 | 1805 | dpll_reg = DPLL(0); |
9b6de0a1 | 1806 | expected_mask <<= 4; |
00fc31b7 CML |
1807 | break; |
1808 | case PORT_D: | |
1809 | port_mask = DPLL_PORTD_READY_MASK; | |
1810 | dpll_reg = DPIO_PHY_STATUS; | |
e4607fcf CML |
1811 | break; |
1812 | default: | |
1813 | BUG(); | |
1814 | } | |
89b667f8 | 1815 | |
9b6de0a1 VS |
1816 | if (wait_for((I915_READ(dpll_reg) & port_mask) == expected_mask, 1000)) |
1817 | WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n", | |
1818 | port_name(dport->port), I915_READ(dpll_reg) & port_mask, expected_mask); | |
89b667f8 JB |
1819 | } |
1820 | ||
b8a4f404 PZ |
1821 | static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
1822 | enum pipe pipe) | |
040484af | 1823 | { |
23670b32 | 1824 | struct drm_device *dev = dev_priv->dev; |
7c26e5c6 | 1825 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
e2b78267 | 1826 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
f0f59a00 VS |
1827 | i915_reg_t reg; |
1828 | uint32_t val, pipeconf_val; | |
040484af | 1829 | |
040484af | 1830 | /* Make sure PCH DPLL is enabled */ |
8106ddbd | 1831 | assert_shared_dpll_enabled(dev_priv, intel_crtc->config->shared_dpll); |
040484af JB |
1832 | |
1833 | /* FDI must be feeding us bits for PCH ports */ | |
1834 | assert_fdi_tx_enabled(dev_priv, pipe); | |
1835 | assert_fdi_rx_enabled(dev_priv, pipe); | |
1836 | ||
23670b32 DV |
1837 | if (HAS_PCH_CPT(dev)) { |
1838 | /* Workaround: Set the timing override bit before enabling the | |
1839 | * pch transcoder. */ | |
1840 | reg = TRANS_CHICKEN2(pipe); | |
1841 | val = I915_READ(reg); | |
1842 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; | |
1843 | I915_WRITE(reg, val); | |
59c859d6 | 1844 | } |
23670b32 | 1845 | |
ab9412ba | 1846 | reg = PCH_TRANSCONF(pipe); |
040484af | 1847 | val = I915_READ(reg); |
5f7f726d | 1848 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
e9bcff5c | 1849 | |
2d1fe073 | 1850 | if (HAS_PCH_IBX(dev_priv)) { |
e9bcff5c | 1851 | /* |
c5de7c6f VS |
1852 | * Make the BPC in transcoder be consistent with |
1853 | * that in pipeconf reg. For HDMI we must use 8bpc | |
1854 | * here for both 8bpc and 12bpc. | |
e9bcff5c | 1855 | */ |
dfd07d72 | 1856 | val &= ~PIPECONF_BPC_MASK; |
c5de7c6f VS |
1857 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_HDMI)) |
1858 | val |= PIPECONF_8BPC; | |
1859 | else | |
1860 | val |= pipeconf_val & PIPECONF_BPC_MASK; | |
e9bcff5c | 1861 | } |
5f7f726d PZ |
1862 | |
1863 | val &= ~TRANS_INTERLACE_MASK; | |
1864 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) | |
2d1fe073 | 1865 | if (HAS_PCH_IBX(dev_priv) && |
409ee761 | 1866 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
7c26e5c6 PZ |
1867 | val |= TRANS_LEGACY_INTERLACED_ILK; |
1868 | else | |
1869 | val |= TRANS_INTERLACED; | |
5f7f726d PZ |
1870 | else |
1871 | val |= TRANS_PROGRESSIVE; | |
1872 | ||
040484af JB |
1873 | I915_WRITE(reg, val | TRANS_ENABLE); |
1874 | if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100)) | |
4bb6f1f3 | 1875 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
040484af JB |
1876 | } |
1877 | ||
8fb033d7 | 1878 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
937bb610 | 1879 | enum transcoder cpu_transcoder) |
040484af | 1880 | { |
8fb033d7 | 1881 | u32 val, pipeconf_val; |
8fb033d7 | 1882 | |
8fb033d7 | 1883 | /* FDI must be feeding us bits for PCH ports */ |
1a240d4d | 1884 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
937bb610 | 1885 | assert_fdi_rx_enabled(dev_priv, TRANSCODER_A); |
8fb033d7 | 1886 | |
223a6fdf | 1887 | /* Workaround: set timing override bit. */ |
36c0d0cf | 1888 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
23670b32 | 1889 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
36c0d0cf | 1890 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
223a6fdf | 1891 | |
25f3ef11 | 1892 | val = TRANS_ENABLE; |
937bb610 | 1893 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
8fb033d7 | 1894 | |
9a76b1c6 PZ |
1895 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
1896 | PIPECONF_INTERLACED_ILK) | |
a35f2679 | 1897 | val |= TRANS_INTERLACED; |
8fb033d7 PZ |
1898 | else |
1899 | val |= TRANS_PROGRESSIVE; | |
1900 | ||
ab9412ba DV |
1901 | I915_WRITE(LPT_TRANSCONF, val); |
1902 | if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100)) | |
937bb610 | 1903 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
8fb033d7 PZ |
1904 | } |
1905 | ||
b8a4f404 PZ |
1906 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
1907 | enum pipe pipe) | |
040484af | 1908 | { |
23670b32 | 1909 | struct drm_device *dev = dev_priv->dev; |
f0f59a00 VS |
1910 | i915_reg_t reg; |
1911 | uint32_t val; | |
040484af JB |
1912 | |
1913 | /* FDI relies on the transcoder */ | |
1914 | assert_fdi_tx_disabled(dev_priv, pipe); | |
1915 | assert_fdi_rx_disabled(dev_priv, pipe); | |
1916 | ||
291906f1 JB |
1917 | /* Ports must be off as well */ |
1918 | assert_pch_ports_disabled(dev_priv, pipe); | |
1919 | ||
ab9412ba | 1920 | reg = PCH_TRANSCONF(pipe); |
040484af JB |
1921 | val = I915_READ(reg); |
1922 | val &= ~TRANS_ENABLE; | |
1923 | I915_WRITE(reg, val); | |
1924 | /* wait for PCH transcoder off, transcoder state */ | |
1925 | if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50)) | |
4bb6f1f3 | 1926 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
23670b32 | 1927 | |
c465613b | 1928 | if (HAS_PCH_CPT(dev)) { |
23670b32 DV |
1929 | /* Workaround: Clear the timing override chicken bit again. */ |
1930 | reg = TRANS_CHICKEN2(pipe); | |
1931 | val = I915_READ(reg); | |
1932 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; | |
1933 | I915_WRITE(reg, val); | |
1934 | } | |
040484af JB |
1935 | } |
1936 | ||
ab4d966c | 1937 | static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
8fb033d7 | 1938 | { |
8fb033d7 PZ |
1939 | u32 val; |
1940 | ||
ab9412ba | 1941 | val = I915_READ(LPT_TRANSCONF); |
8fb033d7 | 1942 | val &= ~TRANS_ENABLE; |
ab9412ba | 1943 | I915_WRITE(LPT_TRANSCONF, val); |
8fb033d7 | 1944 | /* wait for PCH transcoder off, transcoder state */ |
ab9412ba | 1945 | if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50)) |
8a52fd9f | 1946 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
223a6fdf PZ |
1947 | |
1948 | /* Workaround: clear timing override bit. */ | |
36c0d0cf | 1949 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
23670b32 | 1950 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
36c0d0cf | 1951 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
040484af JB |
1952 | } |
1953 | ||
b24e7179 | 1954 | /** |
309cfea8 | 1955 | * intel_enable_pipe - enable a pipe, asserting requirements |
0372264a | 1956 | * @crtc: crtc responsible for the pipe |
b24e7179 | 1957 | * |
0372264a | 1958 | * Enable @crtc's pipe, making sure that various hardware specific requirements |
b24e7179 | 1959 | * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc. |
b24e7179 | 1960 | */ |
e1fdc473 | 1961 | static void intel_enable_pipe(struct intel_crtc *crtc) |
b24e7179 | 1962 | { |
0372264a PZ |
1963 | struct drm_device *dev = crtc->base.dev; |
1964 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1965 | enum pipe pipe = crtc->pipe; | |
1a70a728 | 1966 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
1a240d4d | 1967 | enum pipe pch_transcoder; |
f0f59a00 | 1968 | i915_reg_t reg; |
b24e7179 JB |
1969 | u32 val; |
1970 | ||
9e2ee2dd VS |
1971 | DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe)); |
1972 | ||
58c6eaa2 | 1973 | assert_planes_disabled(dev_priv, pipe); |
93ce0ba6 | 1974 | assert_cursor_disabled(dev_priv, pipe); |
58c6eaa2 DV |
1975 | assert_sprites_disabled(dev_priv, pipe); |
1976 | ||
2d1fe073 | 1977 | if (HAS_PCH_LPT(dev_priv)) |
cc391bbb PZ |
1978 | pch_transcoder = TRANSCODER_A; |
1979 | else | |
1980 | pch_transcoder = pipe; | |
1981 | ||
b24e7179 JB |
1982 | /* |
1983 | * A pipe without a PLL won't actually be able to drive bits from | |
1984 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't | |
1985 | * need the check. | |
1986 | */ | |
2d1fe073 | 1987 | if (HAS_GMCH_DISPLAY(dev_priv)) |
a65347ba | 1988 | if (crtc->config->has_dsi_encoder) |
23538ef1 JN |
1989 | assert_dsi_pll_enabled(dev_priv); |
1990 | else | |
1991 | assert_pll_enabled(dev_priv, pipe); | |
040484af | 1992 | else { |
6e3c9717 | 1993 | if (crtc->config->has_pch_encoder) { |
040484af | 1994 | /* if driving the PCH, we need FDI enabled */ |
cc391bbb | 1995 | assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder); |
1a240d4d DV |
1996 | assert_fdi_tx_pll_enabled(dev_priv, |
1997 | (enum pipe) cpu_transcoder); | |
040484af JB |
1998 | } |
1999 | /* FIXME: assert CPU port conditions for SNB+ */ | |
2000 | } | |
b24e7179 | 2001 | |
702e7a56 | 2002 | reg = PIPECONF(cpu_transcoder); |
b24e7179 | 2003 | val = I915_READ(reg); |
7ad25d48 | 2004 | if (val & PIPECONF_ENABLE) { |
b6b5d049 VS |
2005 | WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
2006 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))); | |
00d70b15 | 2007 | return; |
7ad25d48 | 2008 | } |
00d70b15 CW |
2009 | |
2010 | I915_WRITE(reg, val | PIPECONF_ENABLE); | |
851855d8 | 2011 | POSTING_READ(reg); |
b7792d8b VS |
2012 | |
2013 | /* | |
2014 | * Until the pipe starts DSL will read as 0, which would cause | |
2015 | * an apparent vblank timestamp jump, which messes up also the | |
2016 | * frame count when it's derived from the timestamps. So let's | |
2017 | * wait for the pipe to start properly before we call | |
2018 | * drm_crtc_vblank_on() | |
2019 | */ | |
2020 | if (dev->max_vblank_count == 0 && | |
2021 | wait_for(intel_get_crtc_scanline(crtc) != crtc->scanline_offset, 50)) | |
2022 | DRM_ERROR("pipe %c didn't start\n", pipe_name(pipe)); | |
b24e7179 JB |
2023 | } |
2024 | ||
2025 | /** | |
309cfea8 | 2026 | * intel_disable_pipe - disable a pipe, asserting requirements |
575f7ab7 | 2027 | * @crtc: crtc whose pipes is to be disabled |
b24e7179 | 2028 | * |
575f7ab7 VS |
2029 | * Disable the pipe of @crtc, making sure that various hardware |
2030 | * specific requirements are met, if applicable, e.g. plane | |
2031 | * disabled, panel fitter off, etc. | |
b24e7179 JB |
2032 | * |
2033 | * Will wait until the pipe has shut down before returning. | |
2034 | */ | |
575f7ab7 | 2035 | static void intel_disable_pipe(struct intel_crtc *crtc) |
b24e7179 | 2036 | { |
575f7ab7 | 2037 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
6e3c9717 | 2038 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
575f7ab7 | 2039 | enum pipe pipe = crtc->pipe; |
f0f59a00 | 2040 | i915_reg_t reg; |
b24e7179 JB |
2041 | u32 val; |
2042 | ||
9e2ee2dd VS |
2043 | DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe)); |
2044 | ||
b24e7179 JB |
2045 | /* |
2046 | * Make sure planes won't keep trying to pump pixels to us, | |
2047 | * or we might hang the display. | |
2048 | */ | |
2049 | assert_planes_disabled(dev_priv, pipe); | |
93ce0ba6 | 2050 | assert_cursor_disabled(dev_priv, pipe); |
19332d7a | 2051 | assert_sprites_disabled(dev_priv, pipe); |
b24e7179 | 2052 | |
702e7a56 | 2053 | reg = PIPECONF(cpu_transcoder); |
b24e7179 | 2054 | val = I915_READ(reg); |
00d70b15 CW |
2055 | if ((val & PIPECONF_ENABLE) == 0) |
2056 | return; | |
2057 | ||
67adc644 VS |
2058 | /* |
2059 | * Double wide has implications for planes | |
2060 | * so best keep it disabled when not needed. | |
2061 | */ | |
6e3c9717 | 2062 | if (crtc->config->double_wide) |
67adc644 VS |
2063 | val &= ~PIPECONF_DOUBLE_WIDE; |
2064 | ||
2065 | /* Don't disable pipe or pipe PLLs if needed */ | |
b6b5d049 VS |
2066 | if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) && |
2067 | !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
67adc644 VS |
2068 | val &= ~PIPECONF_ENABLE; |
2069 | ||
2070 | I915_WRITE(reg, val); | |
2071 | if ((val & PIPECONF_ENABLE) == 0) | |
2072 | intel_wait_for_pipe_off(crtc); | |
b24e7179 JB |
2073 | } |
2074 | ||
693db184 CW |
2075 | static bool need_vtd_wa(struct drm_device *dev) |
2076 | { | |
2077 | #ifdef CONFIG_INTEL_IOMMU | |
2078 | if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped) | |
2079 | return true; | |
2080 | #endif | |
2081 | return false; | |
2082 | } | |
2083 | ||
832be82f VS |
2084 | static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv) |
2085 | { | |
2086 | return IS_GEN2(dev_priv) ? 2048 : 4096; | |
2087 | } | |
2088 | ||
27ba3910 VS |
2089 | static unsigned int intel_tile_width_bytes(const struct drm_i915_private *dev_priv, |
2090 | uint64_t fb_modifier, unsigned int cpp) | |
7b49f948 VS |
2091 | { |
2092 | switch (fb_modifier) { | |
2093 | case DRM_FORMAT_MOD_NONE: | |
2094 | return cpp; | |
2095 | case I915_FORMAT_MOD_X_TILED: | |
2096 | if (IS_GEN2(dev_priv)) | |
2097 | return 128; | |
2098 | else | |
2099 | return 512; | |
2100 | case I915_FORMAT_MOD_Y_TILED: | |
2101 | if (IS_GEN2(dev_priv) || HAS_128_BYTE_Y_TILING(dev_priv)) | |
2102 | return 128; | |
2103 | else | |
2104 | return 512; | |
2105 | case I915_FORMAT_MOD_Yf_TILED: | |
2106 | switch (cpp) { | |
2107 | case 1: | |
2108 | return 64; | |
2109 | case 2: | |
2110 | case 4: | |
2111 | return 128; | |
2112 | case 8: | |
2113 | case 16: | |
2114 | return 256; | |
2115 | default: | |
2116 | MISSING_CASE(cpp); | |
2117 | return cpp; | |
2118 | } | |
2119 | break; | |
2120 | default: | |
2121 | MISSING_CASE(fb_modifier); | |
2122 | return cpp; | |
2123 | } | |
2124 | } | |
2125 | ||
832be82f VS |
2126 | unsigned int intel_tile_height(const struct drm_i915_private *dev_priv, |
2127 | uint64_t fb_modifier, unsigned int cpp) | |
a57ce0b2 | 2128 | { |
832be82f VS |
2129 | if (fb_modifier == DRM_FORMAT_MOD_NONE) |
2130 | return 1; | |
2131 | else | |
2132 | return intel_tile_size(dev_priv) / | |
27ba3910 | 2133 | intel_tile_width_bytes(dev_priv, fb_modifier, cpp); |
6761dd31 TU |
2134 | } |
2135 | ||
8d0deca8 VS |
2136 | /* Return the tile dimensions in pixel units */ |
2137 | static void intel_tile_dims(const struct drm_i915_private *dev_priv, | |
2138 | unsigned int *tile_width, | |
2139 | unsigned int *tile_height, | |
2140 | uint64_t fb_modifier, | |
2141 | unsigned int cpp) | |
2142 | { | |
2143 | unsigned int tile_width_bytes = | |
2144 | intel_tile_width_bytes(dev_priv, fb_modifier, cpp); | |
2145 | ||
2146 | *tile_width = tile_width_bytes / cpp; | |
2147 | *tile_height = intel_tile_size(dev_priv) / tile_width_bytes; | |
2148 | } | |
2149 | ||
6761dd31 TU |
2150 | unsigned int |
2151 | intel_fb_align_height(struct drm_device *dev, unsigned int height, | |
832be82f | 2152 | uint32_t pixel_format, uint64_t fb_modifier) |
6761dd31 | 2153 | { |
832be82f VS |
2154 | unsigned int cpp = drm_format_plane_cpp(pixel_format, 0); |
2155 | unsigned int tile_height = intel_tile_height(to_i915(dev), fb_modifier, cpp); | |
2156 | ||
2157 | return ALIGN(height, tile_height); | |
a57ce0b2 JB |
2158 | } |
2159 | ||
1663b9d6 VS |
2160 | unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info) |
2161 | { | |
2162 | unsigned int size = 0; | |
2163 | int i; | |
2164 | ||
2165 | for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++) | |
2166 | size += rot_info->plane[i].width * rot_info->plane[i].height; | |
2167 | ||
2168 | return size; | |
2169 | } | |
2170 | ||
75c82a53 | 2171 | static void |
3465c580 VS |
2172 | intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, |
2173 | const struct drm_framebuffer *fb, | |
2174 | unsigned int rotation) | |
f64b98cd | 2175 | { |
2d7a215f VS |
2176 | if (intel_rotation_90_or_270(rotation)) { |
2177 | *view = i915_ggtt_view_rotated; | |
2178 | view->params.rotated = to_intel_framebuffer(fb)->rot_info; | |
2179 | } else { | |
2180 | *view = i915_ggtt_view_normal; | |
2181 | } | |
2182 | } | |
50470bb0 | 2183 | |
2d7a215f VS |
2184 | static void |
2185 | intel_fill_fb_info(struct drm_i915_private *dev_priv, | |
2186 | struct drm_framebuffer *fb) | |
2187 | { | |
2188 | struct intel_rotation_info *info = &to_intel_framebuffer(fb)->rot_info; | |
2189 | unsigned int tile_size, tile_width, tile_height, cpp; | |
50470bb0 | 2190 | |
d9b3288e VS |
2191 | tile_size = intel_tile_size(dev_priv); |
2192 | ||
2193 | cpp = drm_format_plane_cpp(fb->pixel_format, 0); | |
8d0deca8 VS |
2194 | intel_tile_dims(dev_priv, &tile_width, &tile_height, |
2195 | fb->modifier[0], cpp); | |
d9b3288e | 2196 | |
1663b9d6 VS |
2197 | info->plane[0].width = DIV_ROUND_UP(fb->pitches[0], tile_width * cpp); |
2198 | info->plane[0].height = DIV_ROUND_UP(fb->height, tile_height); | |
84fe03f7 | 2199 | |
89e3e142 | 2200 | if (info->pixel_format == DRM_FORMAT_NV12) { |
832be82f | 2201 | cpp = drm_format_plane_cpp(fb->pixel_format, 1); |
8d0deca8 VS |
2202 | intel_tile_dims(dev_priv, &tile_width, &tile_height, |
2203 | fb->modifier[1], cpp); | |
d9b3288e | 2204 | |
2d7a215f | 2205 | info->uv_offset = fb->offsets[1]; |
1663b9d6 VS |
2206 | info->plane[1].width = DIV_ROUND_UP(fb->pitches[1], tile_width * cpp); |
2207 | info->plane[1].height = DIV_ROUND_UP(fb->height / 2, tile_height); | |
89e3e142 | 2208 | } |
f64b98cd TU |
2209 | } |
2210 | ||
603525d7 | 2211 | static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv) |
4e9a86b6 VS |
2212 | { |
2213 | if (INTEL_INFO(dev_priv)->gen >= 9) | |
2214 | return 256 * 1024; | |
985b8bb4 | 2215 | else if (IS_BROADWATER(dev_priv) || IS_CRESTLINE(dev_priv) || |
666a4537 | 2216 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
4e9a86b6 VS |
2217 | return 128 * 1024; |
2218 | else if (INTEL_INFO(dev_priv)->gen >= 4) | |
2219 | return 4 * 1024; | |
2220 | else | |
44c5905e | 2221 | return 0; |
4e9a86b6 VS |
2222 | } |
2223 | ||
603525d7 VS |
2224 | static unsigned int intel_surf_alignment(const struct drm_i915_private *dev_priv, |
2225 | uint64_t fb_modifier) | |
2226 | { | |
2227 | switch (fb_modifier) { | |
2228 | case DRM_FORMAT_MOD_NONE: | |
2229 | return intel_linear_alignment(dev_priv); | |
2230 | case I915_FORMAT_MOD_X_TILED: | |
2231 | if (INTEL_INFO(dev_priv)->gen >= 9) | |
2232 | return 256 * 1024; | |
2233 | return 0; | |
2234 | case I915_FORMAT_MOD_Y_TILED: | |
2235 | case I915_FORMAT_MOD_Yf_TILED: | |
2236 | return 1 * 1024 * 1024; | |
2237 | default: | |
2238 | MISSING_CASE(fb_modifier); | |
2239 | return 0; | |
2240 | } | |
2241 | } | |
2242 | ||
127bd2ac | 2243 | int |
3465c580 VS |
2244 | intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, |
2245 | unsigned int rotation) | |
6b95a207 | 2246 | { |
850c4cdc | 2247 | struct drm_device *dev = fb->dev; |
ce453d81 | 2248 | struct drm_i915_private *dev_priv = dev->dev_private; |
850c4cdc | 2249 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
f64b98cd | 2250 | struct i915_ggtt_view view; |
6b95a207 KH |
2251 | u32 alignment; |
2252 | int ret; | |
2253 | ||
ebcdd39e MR |
2254 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
2255 | ||
603525d7 | 2256 | alignment = intel_surf_alignment(dev_priv, fb->modifier[0]); |
6b95a207 | 2257 | |
3465c580 | 2258 | intel_fill_fb_ggtt_view(&view, fb, rotation); |
f64b98cd | 2259 | |
693db184 CW |
2260 | /* Note that the w/a also requires 64 PTE of padding following the |
2261 | * bo. We currently fill all unused PTE with the shadow page and so | |
2262 | * we should always have valid PTE following the scanout preventing | |
2263 | * the VT-d warning. | |
2264 | */ | |
2265 | if (need_vtd_wa(dev) && alignment < 256 * 1024) | |
2266 | alignment = 256 * 1024; | |
2267 | ||
d6dd6843 PZ |
2268 | /* |
2269 | * Global gtt pte registers are special registers which actually forward | |
2270 | * writes to a chunk of system memory. Which means that there is no risk | |
2271 | * that the register values disappear as soon as we call | |
2272 | * intel_runtime_pm_put(), so it is correct to wrap only the | |
2273 | * pin/unpin/fence and not more. | |
2274 | */ | |
2275 | intel_runtime_pm_get(dev_priv); | |
2276 | ||
7580d774 ML |
2277 | ret = i915_gem_object_pin_to_display_plane(obj, alignment, |
2278 | &view); | |
48b956c5 | 2279 | if (ret) |
b26a6b35 | 2280 | goto err_pm; |
6b95a207 KH |
2281 | |
2282 | /* Install a fence for tiled scan-out. Pre-i965 always needs a | |
2283 | * fence, whereas 965+ only requires a fence if using | |
2284 | * framebuffer compression. For simplicity, we always install | |
2285 | * a fence as the cost is not that onerous. | |
2286 | */ | |
9807216f VK |
2287 | if (view.type == I915_GGTT_VIEW_NORMAL) { |
2288 | ret = i915_gem_object_get_fence(obj); | |
2289 | if (ret == -EDEADLK) { | |
2290 | /* | |
2291 | * -EDEADLK means there are no free fences | |
2292 | * no pending flips. | |
2293 | * | |
2294 | * This is propagated to atomic, but it uses | |
2295 | * -EDEADLK to force a locking recovery, so | |
2296 | * change the returned error to -EBUSY. | |
2297 | */ | |
2298 | ret = -EBUSY; | |
2299 | goto err_unpin; | |
2300 | } else if (ret) | |
2301 | goto err_unpin; | |
1690e1eb | 2302 | |
9807216f VK |
2303 | i915_gem_object_pin_fence(obj); |
2304 | } | |
6b95a207 | 2305 | |
d6dd6843 | 2306 | intel_runtime_pm_put(dev_priv); |
6b95a207 | 2307 | return 0; |
48b956c5 CW |
2308 | |
2309 | err_unpin: | |
f64b98cd | 2310 | i915_gem_object_unpin_from_display_plane(obj, &view); |
b26a6b35 | 2311 | err_pm: |
d6dd6843 | 2312 | intel_runtime_pm_put(dev_priv); |
48b956c5 | 2313 | return ret; |
6b95a207 KH |
2314 | } |
2315 | ||
fb4b8ce1 | 2316 | void intel_unpin_fb_obj(struct drm_framebuffer *fb, unsigned int rotation) |
1690e1eb | 2317 | { |
82bc3b2d | 2318 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
f64b98cd | 2319 | struct i915_ggtt_view view; |
82bc3b2d | 2320 | |
ebcdd39e MR |
2321 | WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex)); |
2322 | ||
3465c580 | 2323 | intel_fill_fb_ggtt_view(&view, fb, rotation); |
f64b98cd | 2324 | |
9807216f VK |
2325 | if (view.type == I915_GGTT_VIEW_NORMAL) |
2326 | i915_gem_object_unpin_fence(obj); | |
2327 | ||
f64b98cd | 2328 | i915_gem_object_unpin_from_display_plane(obj, &view); |
1690e1eb CW |
2329 | } |
2330 | ||
29cf9491 VS |
2331 | /* |
2332 | * Adjust the tile offset by moving the difference into | |
2333 | * the x/y offsets. | |
2334 | * | |
2335 | * Input tile dimensions and pitch must already be | |
2336 | * rotated to match x and y, and in pixel units. | |
2337 | */ | |
2338 | static u32 intel_adjust_tile_offset(int *x, int *y, | |
2339 | unsigned int tile_width, | |
2340 | unsigned int tile_height, | |
2341 | unsigned int tile_size, | |
2342 | unsigned int pitch_tiles, | |
2343 | u32 old_offset, | |
2344 | u32 new_offset) | |
2345 | { | |
2346 | unsigned int tiles; | |
2347 | ||
2348 | WARN_ON(old_offset & (tile_size - 1)); | |
2349 | WARN_ON(new_offset & (tile_size - 1)); | |
2350 | WARN_ON(new_offset > old_offset); | |
2351 | ||
2352 | tiles = (old_offset - new_offset) / tile_size; | |
2353 | ||
2354 | *y += tiles / pitch_tiles * tile_height; | |
2355 | *x += tiles % pitch_tiles * tile_width; | |
2356 | ||
2357 | return new_offset; | |
2358 | } | |
2359 | ||
8d0deca8 VS |
2360 | /* |
2361 | * Computes the linear offset to the base tile and adjusts | |
2362 | * x, y. bytes per pixel is assumed to be a power-of-two. | |
2363 | * | |
2364 | * In the 90/270 rotated case, x and y are assumed | |
2365 | * to be already rotated to match the rotated GTT view, and | |
2366 | * pitch is the tile_height aligned framebuffer height. | |
2367 | */ | |
4f2d9934 VS |
2368 | u32 intel_compute_tile_offset(int *x, int *y, |
2369 | const struct drm_framebuffer *fb, int plane, | |
8d0deca8 VS |
2370 | unsigned int pitch, |
2371 | unsigned int rotation) | |
c2c75131 | 2372 | { |
4f2d9934 VS |
2373 | const struct drm_i915_private *dev_priv = to_i915(fb->dev); |
2374 | uint64_t fb_modifier = fb->modifier[plane]; | |
2375 | unsigned int cpp = drm_format_plane_cpp(fb->pixel_format, plane); | |
29cf9491 VS |
2376 | u32 offset, offset_aligned, alignment; |
2377 | ||
2378 | alignment = intel_surf_alignment(dev_priv, fb_modifier); | |
2379 | if (alignment) | |
2380 | alignment--; | |
2381 | ||
b5c65338 | 2382 | if (fb_modifier != DRM_FORMAT_MOD_NONE) { |
8d0deca8 VS |
2383 | unsigned int tile_size, tile_width, tile_height; |
2384 | unsigned int tile_rows, tiles, pitch_tiles; | |
c2c75131 | 2385 | |
d843310d | 2386 | tile_size = intel_tile_size(dev_priv); |
8d0deca8 VS |
2387 | intel_tile_dims(dev_priv, &tile_width, &tile_height, |
2388 | fb_modifier, cpp); | |
2389 | ||
2390 | if (intel_rotation_90_or_270(rotation)) { | |
2391 | pitch_tiles = pitch / tile_height; | |
2392 | swap(tile_width, tile_height); | |
2393 | } else { | |
2394 | pitch_tiles = pitch / (tile_width * cpp); | |
2395 | } | |
d843310d VS |
2396 | |
2397 | tile_rows = *y / tile_height; | |
2398 | *y %= tile_height; | |
c2c75131 | 2399 | |
8d0deca8 VS |
2400 | tiles = *x / tile_width; |
2401 | *x %= tile_width; | |
bc752862 | 2402 | |
29cf9491 VS |
2403 | offset = (tile_rows * pitch_tiles + tiles) * tile_size; |
2404 | offset_aligned = offset & ~alignment; | |
bc752862 | 2405 | |
29cf9491 VS |
2406 | intel_adjust_tile_offset(x, y, tile_width, tile_height, |
2407 | tile_size, pitch_tiles, | |
2408 | offset, offset_aligned); | |
2409 | } else { | |
bc752862 | 2410 | offset = *y * pitch + *x * cpp; |
29cf9491 VS |
2411 | offset_aligned = offset & ~alignment; |
2412 | ||
4e9a86b6 VS |
2413 | *y = (offset & alignment) / pitch; |
2414 | *x = ((offset & alignment) - *y * pitch) / cpp; | |
bc752862 | 2415 | } |
29cf9491 VS |
2416 | |
2417 | return offset_aligned; | |
c2c75131 DV |
2418 | } |
2419 | ||
b35d63fa | 2420 | static int i9xx_format_to_fourcc(int format) |
46f297fb JB |
2421 | { |
2422 | switch (format) { | |
2423 | case DISPPLANE_8BPP: | |
2424 | return DRM_FORMAT_C8; | |
2425 | case DISPPLANE_BGRX555: | |
2426 | return DRM_FORMAT_XRGB1555; | |
2427 | case DISPPLANE_BGRX565: | |
2428 | return DRM_FORMAT_RGB565; | |
2429 | default: | |
2430 | case DISPPLANE_BGRX888: | |
2431 | return DRM_FORMAT_XRGB8888; | |
2432 | case DISPPLANE_RGBX888: | |
2433 | return DRM_FORMAT_XBGR8888; | |
2434 | case DISPPLANE_BGRX101010: | |
2435 | return DRM_FORMAT_XRGB2101010; | |
2436 | case DISPPLANE_RGBX101010: | |
2437 | return DRM_FORMAT_XBGR2101010; | |
2438 | } | |
2439 | } | |
2440 | ||
bc8d7dff DL |
2441 | static int skl_format_to_fourcc(int format, bool rgb_order, bool alpha) |
2442 | { | |
2443 | switch (format) { | |
2444 | case PLANE_CTL_FORMAT_RGB_565: | |
2445 | return DRM_FORMAT_RGB565; | |
2446 | default: | |
2447 | case PLANE_CTL_FORMAT_XRGB_8888: | |
2448 | if (rgb_order) { | |
2449 | if (alpha) | |
2450 | return DRM_FORMAT_ABGR8888; | |
2451 | else | |
2452 | return DRM_FORMAT_XBGR8888; | |
2453 | } else { | |
2454 | if (alpha) | |
2455 | return DRM_FORMAT_ARGB8888; | |
2456 | else | |
2457 | return DRM_FORMAT_XRGB8888; | |
2458 | } | |
2459 | case PLANE_CTL_FORMAT_XRGB_2101010: | |
2460 | if (rgb_order) | |
2461 | return DRM_FORMAT_XBGR2101010; | |
2462 | else | |
2463 | return DRM_FORMAT_XRGB2101010; | |
2464 | } | |
2465 | } | |
2466 | ||
5724dbd1 | 2467 | static bool |
f6936e29 DV |
2468 | intel_alloc_initial_plane_obj(struct intel_crtc *crtc, |
2469 | struct intel_initial_plane_config *plane_config) | |
46f297fb JB |
2470 | { |
2471 | struct drm_device *dev = crtc->base.dev; | |
3badb49f | 2472 | struct drm_i915_private *dev_priv = to_i915(dev); |
72e96d64 | 2473 | struct i915_ggtt *ggtt = &dev_priv->ggtt; |
46f297fb JB |
2474 | struct drm_i915_gem_object *obj = NULL; |
2475 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; | |
2d14030b | 2476 | struct drm_framebuffer *fb = &plane_config->fb->base; |
f37b5c2b DV |
2477 | u32 base_aligned = round_down(plane_config->base, PAGE_SIZE); |
2478 | u32 size_aligned = round_up(plane_config->base + plane_config->size, | |
2479 | PAGE_SIZE); | |
2480 | ||
2481 | size_aligned -= base_aligned; | |
46f297fb | 2482 | |
ff2652ea CW |
2483 | if (plane_config->size == 0) |
2484 | return false; | |
2485 | ||
3badb49f PZ |
2486 | /* If the FB is too big, just don't use it since fbdev is not very |
2487 | * important and we should probably use that space with FBC or other | |
2488 | * features. */ | |
72e96d64 | 2489 | if (size_aligned * 2 > ggtt->stolen_usable_size) |
3badb49f PZ |
2490 | return false; |
2491 | ||
12c83d99 TU |
2492 | mutex_lock(&dev->struct_mutex); |
2493 | ||
f37b5c2b DV |
2494 | obj = i915_gem_object_create_stolen_for_preallocated(dev, |
2495 | base_aligned, | |
2496 | base_aligned, | |
2497 | size_aligned); | |
12c83d99 TU |
2498 | if (!obj) { |
2499 | mutex_unlock(&dev->struct_mutex); | |
484b41dd | 2500 | return false; |
12c83d99 | 2501 | } |
46f297fb | 2502 | |
49af449b DL |
2503 | obj->tiling_mode = plane_config->tiling; |
2504 | if (obj->tiling_mode == I915_TILING_X) | |
6bf129df | 2505 | obj->stride = fb->pitches[0]; |
46f297fb | 2506 | |
6bf129df DL |
2507 | mode_cmd.pixel_format = fb->pixel_format; |
2508 | mode_cmd.width = fb->width; | |
2509 | mode_cmd.height = fb->height; | |
2510 | mode_cmd.pitches[0] = fb->pitches[0]; | |
18c5247e DV |
2511 | mode_cmd.modifier[0] = fb->modifier[0]; |
2512 | mode_cmd.flags = DRM_MODE_FB_MODIFIERS; | |
46f297fb | 2513 | |
6bf129df | 2514 | if (intel_framebuffer_init(dev, to_intel_framebuffer(fb), |
484b41dd | 2515 | &mode_cmd, obj)) { |
46f297fb JB |
2516 | DRM_DEBUG_KMS("intel fb init failed\n"); |
2517 | goto out_unref_obj; | |
2518 | } | |
12c83d99 | 2519 | |
46f297fb | 2520 | mutex_unlock(&dev->struct_mutex); |
484b41dd | 2521 | |
f6936e29 | 2522 | DRM_DEBUG_KMS("initial plane fb obj %p\n", obj); |
484b41dd | 2523 | return true; |
46f297fb JB |
2524 | |
2525 | out_unref_obj: | |
2526 | drm_gem_object_unreference(&obj->base); | |
2527 | mutex_unlock(&dev->struct_mutex); | |
484b41dd JB |
2528 | return false; |
2529 | } | |
2530 | ||
5a21b665 DV |
2531 | /* Update plane->state->fb to match plane->fb after driver-internal updates */ |
2532 | static void | |
2533 | update_state_fb(struct drm_plane *plane) | |
2534 | { | |
2535 | if (plane->fb == plane->state->fb) | |
2536 | return; | |
2537 | ||
2538 | if (plane->state->fb) | |
2539 | drm_framebuffer_unreference(plane->state->fb); | |
2540 | plane->state->fb = plane->fb; | |
2541 | if (plane->state->fb) | |
2542 | drm_framebuffer_reference(plane->state->fb); | |
2543 | } | |
2544 | ||
5724dbd1 | 2545 | static void |
f6936e29 DV |
2546 | intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, |
2547 | struct intel_initial_plane_config *plane_config) | |
484b41dd JB |
2548 | { |
2549 | struct drm_device *dev = intel_crtc->base.dev; | |
d9ceb816 | 2550 | struct drm_i915_private *dev_priv = dev->dev_private; |
484b41dd JB |
2551 | struct drm_crtc *c; |
2552 | struct intel_crtc *i; | |
2ff8fde1 | 2553 | struct drm_i915_gem_object *obj; |
88595ac9 | 2554 | struct drm_plane *primary = intel_crtc->base.primary; |
be5651f2 | 2555 | struct drm_plane_state *plane_state = primary->state; |
200757f5 MR |
2556 | struct drm_crtc_state *crtc_state = intel_crtc->base.state; |
2557 | struct intel_plane *intel_plane = to_intel_plane(primary); | |
0a8d8a86 MR |
2558 | struct intel_plane_state *intel_state = |
2559 | to_intel_plane_state(plane_state); | |
88595ac9 | 2560 | struct drm_framebuffer *fb; |
484b41dd | 2561 | |
2d14030b | 2562 | if (!plane_config->fb) |
484b41dd JB |
2563 | return; |
2564 | ||
f6936e29 | 2565 | if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) { |
88595ac9 DV |
2566 | fb = &plane_config->fb->base; |
2567 | goto valid_fb; | |
f55548b5 | 2568 | } |
484b41dd | 2569 | |
2d14030b | 2570 | kfree(plane_config->fb); |
484b41dd JB |
2571 | |
2572 | /* | |
2573 | * Failed to alloc the obj, check to see if we should share | |
2574 | * an fb with another CRTC instead | |
2575 | */ | |
70e1e0ec | 2576 | for_each_crtc(dev, c) { |
484b41dd JB |
2577 | i = to_intel_crtc(c); |
2578 | ||
2579 | if (c == &intel_crtc->base) | |
2580 | continue; | |
2581 | ||
2ff8fde1 MR |
2582 | if (!i->active) |
2583 | continue; | |
2584 | ||
88595ac9 DV |
2585 | fb = c->primary->fb; |
2586 | if (!fb) | |
484b41dd JB |
2587 | continue; |
2588 | ||
88595ac9 | 2589 | obj = intel_fb_obj(fb); |
2ff8fde1 | 2590 | if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) { |
88595ac9 DV |
2591 | drm_framebuffer_reference(fb); |
2592 | goto valid_fb; | |
484b41dd JB |
2593 | } |
2594 | } | |
88595ac9 | 2595 | |
200757f5 MR |
2596 | /* |
2597 | * We've failed to reconstruct the BIOS FB. Current display state | |
2598 | * indicates that the primary plane is visible, but has a NULL FB, | |
2599 | * which will lead to problems later if we don't fix it up. The | |
2600 | * simplest solution is to just disable the primary plane now and | |
2601 | * pretend the BIOS never had it enabled. | |
2602 | */ | |
2603 | to_intel_plane_state(plane_state)->visible = false; | |
2604 | crtc_state->plane_mask &= ~(1 << drm_plane_index(primary)); | |
2622a081 | 2605 | intel_pre_disable_primary_noatomic(&intel_crtc->base); |
200757f5 MR |
2606 | intel_plane->disable_plane(primary, &intel_crtc->base); |
2607 | ||
88595ac9 DV |
2608 | return; |
2609 | ||
2610 | valid_fb: | |
f44e2659 VS |
2611 | plane_state->src_x = 0; |
2612 | plane_state->src_y = 0; | |
be5651f2 ML |
2613 | plane_state->src_w = fb->width << 16; |
2614 | plane_state->src_h = fb->height << 16; | |
2615 | ||
f44e2659 VS |
2616 | plane_state->crtc_x = 0; |
2617 | plane_state->crtc_y = 0; | |
be5651f2 ML |
2618 | plane_state->crtc_w = fb->width; |
2619 | plane_state->crtc_h = fb->height; | |
2620 | ||
0a8d8a86 MR |
2621 | intel_state->src.x1 = plane_state->src_x; |
2622 | intel_state->src.y1 = plane_state->src_y; | |
2623 | intel_state->src.x2 = plane_state->src_x + plane_state->src_w; | |
2624 | intel_state->src.y2 = plane_state->src_y + plane_state->src_h; | |
2625 | intel_state->dst.x1 = plane_state->crtc_x; | |
2626 | intel_state->dst.y1 = plane_state->crtc_y; | |
2627 | intel_state->dst.x2 = plane_state->crtc_x + plane_state->crtc_w; | |
2628 | intel_state->dst.y2 = plane_state->crtc_y + plane_state->crtc_h; | |
2629 | ||
88595ac9 DV |
2630 | obj = intel_fb_obj(fb); |
2631 | if (obj->tiling_mode != I915_TILING_NONE) | |
2632 | dev_priv->preserve_bios_swizzle = true; | |
2633 | ||
be5651f2 ML |
2634 | drm_framebuffer_reference(fb); |
2635 | primary->fb = primary->state->fb = fb; | |
36750f28 | 2636 | primary->crtc = primary->state->crtc = &intel_crtc->base; |
36750f28 | 2637 | intel_crtc->base.state->plane_mask |= (1 << drm_plane_index(primary)); |
a9ff8714 | 2638 | obj->frontbuffer_bits |= to_intel_plane(primary)->frontbuffer_bit; |
46f297fb JB |
2639 | } |
2640 | ||
a8d201af ML |
2641 | static void i9xx_update_primary_plane(struct drm_plane *primary, |
2642 | const struct intel_crtc_state *crtc_state, | |
2643 | const struct intel_plane_state *plane_state) | |
81255565 | 2644 | { |
a8d201af | 2645 | struct drm_device *dev = primary->dev; |
81255565 | 2646 | struct drm_i915_private *dev_priv = dev->dev_private; |
a8d201af ML |
2647 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
2648 | struct drm_framebuffer *fb = plane_state->base.fb; | |
2649 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); | |
81255565 | 2650 | int plane = intel_crtc->plane; |
54ea9da8 | 2651 | u32 linear_offset; |
81255565 | 2652 | u32 dspcntr; |
f0f59a00 | 2653 | i915_reg_t reg = DSPCNTR(plane); |
8d0deca8 | 2654 | unsigned int rotation = plane_state->base.rotation; |
ac484963 | 2655 | int cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
54ea9da8 VS |
2656 | int x = plane_state->src.x1 >> 16; |
2657 | int y = plane_state->src.y1 >> 16; | |
c9ba6fad | 2658 | |
f45651ba VS |
2659 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
2660 | ||
fdd508a6 | 2661 | dspcntr |= DISPLAY_PLANE_ENABLE; |
f45651ba VS |
2662 | |
2663 | if (INTEL_INFO(dev)->gen < 4) { | |
2664 | if (intel_crtc->pipe == PIPE_B) | |
2665 | dspcntr |= DISPPLANE_SEL_PIPE_B; | |
2666 | ||
2667 | /* pipesrc and dspsize control the size that is scaled from, | |
2668 | * which should always be the user's requested size. | |
2669 | */ | |
2670 | I915_WRITE(DSPSIZE(plane), | |
a8d201af ML |
2671 | ((crtc_state->pipe_src_h - 1) << 16) | |
2672 | (crtc_state->pipe_src_w - 1)); | |
f45651ba | 2673 | I915_WRITE(DSPPOS(plane), 0); |
c14b0485 VS |
2674 | } else if (IS_CHERRYVIEW(dev) && plane == PLANE_B) { |
2675 | I915_WRITE(PRIMSIZE(plane), | |
a8d201af ML |
2676 | ((crtc_state->pipe_src_h - 1) << 16) | |
2677 | (crtc_state->pipe_src_w - 1)); | |
c14b0485 VS |
2678 | I915_WRITE(PRIMPOS(plane), 0); |
2679 | I915_WRITE(PRIMCNSTALPHA(plane), 0); | |
f45651ba | 2680 | } |
81255565 | 2681 | |
57779d06 VS |
2682 | switch (fb->pixel_format) { |
2683 | case DRM_FORMAT_C8: | |
81255565 JB |
2684 | dspcntr |= DISPPLANE_8BPP; |
2685 | break; | |
57779d06 | 2686 | case DRM_FORMAT_XRGB1555: |
57779d06 | 2687 | dspcntr |= DISPPLANE_BGRX555; |
81255565 | 2688 | break; |
57779d06 VS |
2689 | case DRM_FORMAT_RGB565: |
2690 | dspcntr |= DISPPLANE_BGRX565; | |
2691 | break; | |
2692 | case DRM_FORMAT_XRGB8888: | |
57779d06 VS |
2693 | dspcntr |= DISPPLANE_BGRX888; |
2694 | break; | |
2695 | case DRM_FORMAT_XBGR8888: | |
57779d06 VS |
2696 | dspcntr |= DISPPLANE_RGBX888; |
2697 | break; | |
2698 | case DRM_FORMAT_XRGB2101010: | |
57779d06 VS |
2699 | dspcntr |= DISPPLANE_BGRX101010; |
2700 | break; | |
2701 | case DRM_FORMAT_XBGR2101010: | |
57779d06 | 2702 | dspcntr |= DISPPLANE_RGBX101010; |
81255565 JB |
2703 | break; |
2704 | default: | |
baba133a | 2705 | BUG(); |
81255565 | 2706 | } |
57779d06 | 2707 | |
f45651ba VS |
2708 | if (INTEL_INFO(dev)->gen >= 4 && |
2709 | obj->tiling_mode != I915_TILING_NONE) | |
2710 | dspcntr |= DISPPLANE_TILED; | |
81255565 | 2711 | |
de1aa629 VS |
2712 | if (IS_G4X(dev)) |
2713 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; | |
2714 | ||
ac484963 | 2715 | linear_offset = y * fb->pitches[0] + x * cpp; |
81255565 | 2716 | |
c2c75131 DV |
2717 | if (INTEL_INFO(dev)->gen >= 4) { |
2718 | intel_crtc->dspaddr_offset = | |
4f2d9934 | 2719 | intel_compute_tile_offset(&x, &y, fb, 0, |
8d0deca8 | 2720 | fb->pitches[0], rotation); |
c2c75131 DV |
2721 | linear_offset -= intel_crtc->dspaddr_offset; |
2722 | } else { | |
e506a0c6 | 2723 | intel_crtc->dspaddr_offset = linear_offset; |
c2c75131 | 2724 | } |
e506a0c6 | 2725 | |
8d0deca8 | 2726 | if (rotation == BIT(DRM_ROTATE_180)) { |
48404c1e SJ |
2727 | dspcntr |= DISPPLANE_ROTATE_180; |
2728 | ||
a8d201af ML |
2729 | x += (crtc_state->pipe_src_w - 1); |
2730 | y += (crtc_state->pipe_src_h - 1); | |
48404c1e SJ |
2731 | |
2732 | /* Finding the last pixel of the last line of the display | |
2733 | data and adding to linear_offset*/ | |
2734 | linear_offset += | |
a8d201af | 2735 | (crtc_state->pipe_src_h - 1) * fb->pitches[0] + |
ac484963 | 2736 | (crtc_state->pipe_src_w - 1) * cpp; |
48404c1e SJ |
2737 | } |
2738 | ||
2db3366b PZ |
2739 | intel_crtc->adjusted_x = x; |
2740 | intel_crtc->adjusted_y = y; | |
2741 | ||
48404c1e SJ |
2742 | I915_WRITE(reg, dspcntr); |
2743 | ||
01f2c773 | 2744 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
a6c45cf0 | 2745 | if (INTEL_INFO(dev)->gen >= 4) { |
85ba7b7d DV |
2746 | I915_WRITE(DSPSURF(plane), |
2747 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); | |
5eddb70b | 2748 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
e506a0c6 | 2749 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
5eddb70b | 2750 | } else |
f343c5f6 | 2751 | I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset); |
5eddb70b | 2752 | POSTING_READ(reg); |
17638cd6 JB |
2753 | } |
2754 | ||
a8d201af ML |
2755 | static void i9xx_disable_primary_plane(struct drm_plane *primary, |
2756 | struct drm_crtc *crtc) | |
17638cd6 JB |
2757 | { |
2758 | struct drm_device *dev = crtc->dev; | |
2759 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2760 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
17638cd6 | 2761 | int plane = intel_crtc->plane; |
f45651ba | 2762 | |
a8d201af ML |
2763 | I915_WRITE(DSPCNTR(plane), 0); |
2764 | if (INTEL_INFO(dev_priv)->gen >= 4) | |
fdd508a6 | 2765 | I915_WRITE(DSPSURF(plane), 0); |
a8d201af ML |
2766 | else |
2767 | I915_WRITE(DSPADDR(plane), 0); | |
2768 | POSTING_READ(DSPCNTR(plane)); | |
2769 | } | |
c9ba6fad | 2770 | |
a8d201af ML |
2771 | static void ironlake_update_primary_plane(struct drm_plane *primary, |
2772 | const struct intel_crtc_state *crtc_state, | |
2773 | const struct intel_plane_state *plane_state) | |
2774 | { | |
2775 | struct drm_device *dev = primary->dev; | |
2776 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2777 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); | |
2778 | struct drm_framebuffer *fb = plane_state->base.fb; | |
2779 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); | |
2780 | int plane = intel_crtc->plane; | |
54ea9da8 | 2781 | u32 linear_offset; |
a8d201af ML |
2782 | u32 dspcntr; |
2783 | i915_reg_t reg = DSPCNTR(plane); | |
8d0deca8 | 2784 | unsigned int rotation = plane_state->base.rotation; |
ac484963 | 2785 | int cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
a8d201af ML |
2786 | int x = plane_state->src.x1 >> 16; |
2787 | int y = plane_state->src.y1 >> 16; | |
c9ba6fad | 2788 | |
f45651ba | 2789 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
fdd508a6 | 2790 | dspcntr |= DISPLAY_PLANE_ENABLE; |
f45651ba VS |
2791 | |
2792 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) | |
2793 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; | |
17638cd6 | 2794 | |
57779d06 VS |
2795 | switch (fb->pixel_format) { |
2796 | case DRM_FORMAT_C8: | |
17638cd6 JB |
2797 | dspcntr |= DISPPLANE_8BPP; |
2798 | break; | |
57779d06 VS |
2799 | case DRM_FORMAT_RGB565: |
2800 | dspcntr |= DISPPLANE_BGRX565; | |
17638cd6 | 2801 | break; |
57779d06 | 2802 | case DRM_FORMAT_XRGB8888: |
57779d06 VS |
2803 | dspcntr |= DISPPLANE_BGRX888; |
2804 | break; | |
2805 | case DRM_FORMAT_XBGR8888: | |
57779d06 VS |
2806 | dspcntr |= DISPPLANE_RGBX888; |
2807 | break; | |
2808 | case DRM_FORMAT_XRGB2101010: | |
57779d06 VS |
2809 | dspcntr |= DISPPLANE_BGRX101010; |
2810 | break; | |
2811 | case DRM_FORMAT_XBGR2101010: | |
57779d06 | 2812 | dspcntr |= DISPPLANE_RGBX101010; |
17638cd6 JB |
2813 | break; |
2814 | default: | |
baba133a | 2815 | BUG(); |
17638cd6 JB |
2816 | } |
2817 | ||
2818 | if (obj->tiling_mode != I915_TILING_NONE) | |
2819 | dspcntr |= DISPPLANE_TILED; | |
17638cd6 | 2820 | |
f45651ba | 2821 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) |
1f5d76db | 2822 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
17638cd6 | 2823 | |
ac484963 | 2824 | linear_offset = y * fb->pitches[0] + x * cpp; |
c2c75131 | 2825 | intel_crtc->dspaddr_offset = |
4f2d9934 | 2826 | intel_compute_tile_offset(&x, &y, fb, 0, |
8d0deca8 | 2827 | fb->pitches[0], rotation); |
c2c75131 | 2828 | linear_offset -= intel_crtc->dspaddr_offset; |
8d0deca8 | 2829 | if (rotation == BIT(DRM_ROTATE_180)) { |
48404c1e SJ |
2830 | dspcntr |= DISPPLANE_ROTATE_180; |
2831 | ||
2832 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) { | |
a8d201af ML |
2833 | x += (crtc_state->pipe_src_w - 1); |
2834 | y += (crtc_state->pipe_src_h - 1); | |
48404c1e SJ |
2835 | |
2836 | /* Finding the last pixel of the last line of the display | |
2837 | data and adding to linear_offset*/ | |
2838 | linear_offset += | |
a8d201af | 2839 | (crtc_state->pipe_src_h - 1) * fb->pitches[0] + |
ac484963 | 2840 | (crtc_state->pipe_src_w - 1) * cpp; |
48404c1e SJ |
2841 | } |
2842 | } | |
2843 | ||
2db3366b PZ |
2844 | intel_crtc->adjusted_x = x; |
2845 | intel_crtc->adjusted_y = y; | |
2846 | ||
48404c1e | 2847 | I915_WRITE(reg, dspcntr); |
17638cd6 | 2848 | |
01f2c773 | 2849 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
85ba7b7d DV |
2850 | I915_WRITE(DSPSURF(plane), |
2851 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); | |
b3dc685e | 2852 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
bc1c91eb DL |
2853 | I915_WRITE(DSPOFFSET(plane), (y << 16) | x); |
2854 | } else { | |
2855 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); | |
2856 | I915_WRITE(DSPLINOFF(plane), linear_offset); | |
2857 | } | |
17638cd6 | 2858 | POSTING_READ(reg); |
17638cd6 JB |
2859 | } |
2860 | ||
7b49f948 VS |
2861 | u32 intel_fb_stride_alignment(const struct drm_i915_private *dev_priv, |
2862 | uint64_t fb_modifier, uint32_t pixel_format) | |
b321803d | 2863 | { |
7b49f948 | 2864 | if (fb_modifier == DRM_FORMAT_MOD_NONE) { |
b321803d | 2865 | return 64; |
7b49f948 VS |
2866 | } else { |
2867 | int cpp = drm_format_plane_cpp(pixel_format, 0); | |
2868 | ||
27ba3910 | 2869 | return intel_tile_width_bytes(dev_priv, fb_modifier, cpp); |
b321803d DL |
2870 | } |
2871 | } | |
2872 | ||
44eb0cb9 MK |
2873 | u32 intel_plane_obj_offset(struct intel_plane *intel_plane, |
2874 | struct drm_i915_gem_object *obj, | |
2875 | unsigned int plane) | |
121920fa | 2876 | { |
ce7f1728 | 2877 | struct i915_ggtt_view view; |
dedf278c | 2878 | struct i915_vma *vma; |
44eb0cb9 | 2879 | u64 offset; |
121920fa | 2880 | |
e7941294 | 2881 | intel_fill_fb_ggtt_view(&view, intel_plane->base.state->fb, |
3465c580 | 2882 | intel_plane->base.state->rotation); |
121920fa | 2883 | |
ce7f1728 | 2884 | vma = i915_gem_obj_to_ggtt_view(obj, &view); |
dedf278c | 2885 | if (WARN(!vma, "ggtt vma for display object not found! (view=%u)\n", |
ce7f1728 | 2886 | view.type)) |
dedf278c TU |
2887 | return -1; |
2888 | ||
44eb0cb9 | 2889 | offset = vma->node.start; |
dedf278c TU |
2890 | |
2891 | if (plane == 1) { | |
7723f47d | 2892 | offset += vma->ggtt_view.params.rotated.uv_start_page * |
dedf278c TU |
2893 | PAGE_SIZE; |
2894 | } | |
2895 | ||
44eb0cb9 MK |
2896 | WARN_ON(upper_32_bits(offset)); |
2897 | ||
2898 | return lower_32_bits(offset); | |
121920fa TU |
2899 | } |
2900 | ||
e435d6e5 ML |
2901 | static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id) |
2902 | { | |
2903 | struct drm_device *dev = intel_crtc->base.dev; | |
2904 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2905 | ||
2906 | I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0); | |
2907 | I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0); | |
2908 | I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0); | |
e435d6e5 ML |
2909 | } |
2910 | ||
a1b2278e CK |
2911 | /* |
2912 | * This function detaches (aka. unbinds) unused scalers in hardware | |
2913 | */ | |
0583236e | 2914 | static void skl_detach_scalers(struct intel_crtc *intel_crtc) |
a1b2278e | 2915 | { |
a1b2278e CK |
2916 | struct intel_crtc_scaler_state *scaler_state; |
2917 | int i; | |
2918 | ||
a1b2278e CK |
2919 | scaler_state = &intel_crtc->config->scaler_state; |
2920 | ||
2921 | /* loop through and disable scalers that aren't in use */ | |
2922 | for (i = 0; i < intel_crtc->num_scalers; i++) { | |
e435d6e5 ML |
2923 | if (!scaler_state->scalers[i].in_use) |
2924 | skl_detach_scaler(intel_crtc, i); | |
a1b2278e CK |
2925 | } |
2926 | } | |
2927 | ||
6156a456 | 2928 | u32 skl_plane_ctl_format(uint32_t pixel_format) |
70d21f0e | 2929 | { |
6156a456 | 2930 | switch (pixel_format) { |
d161cf7a | 2931 | case DRM_FORMAT_C8: |
c34ce3d1 | 2932 | return PLANE_CTL_FORMAT_INDEXED; |
70d21f0e | 2933 | case DRM_FORMAT_RGB565: |
c34ce3d1 | 2934 | return PLANE_CTL_FORMAT_RGB_565; |
70d21f0e | 2935 | case DRM_FORMAT_XBGR8888: |
c34ce3d1 | 2936 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX; |
6156a456 | 2937 | case DRM_FORMAT_XRGB8888: |
c34ce3d1 | 2938 | return PLANE_CTL_FORMAT_XRGB_8888; |
6156a456 CK |
2939 | /* |
2940 | * XXX: For ARBG/ABGR formats we default to expecting scanout buffers | |
2941 | * to be already pre-multiplied. We need to add a knob (or a different | |
2942 | * DRM_FORMAT) for user-space to configure that. | |
2943 | */ | |
f75fb42a | 2944 | case DRM_FORMAT_ABGR8888: |
c34ce3d1 | 2945 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX | |
6156a456 | 2946 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
6156a456 | 2947 | case DRM_FORMAT_ARGB8888: |
c34ce3d1 | 2948 | return PLANE_CTL_FORMAT_XRGB_8888 | |
6156a456 | 2949 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
70d21f0e | 2950 | case DRM_FORMAT_XRGB2101010: |
c34ce3d1 | 2951 | return PLANE_CTL_FORMAT_XRGB_2101010; |
70d21f0e | 2952 | case DRM_FORMAT_XBGR2101010: |
c34ce3d1 | 2953 | return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010; |
6156a456 | 2954 | case DRM_FORMAT_YUYV: |
c34ce3d1 | 2955 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV; |
6156a456 | 2956 | case DRM_FORMAT_YVYU: |
c34ce3d1 | 2957 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU; |
6156a456 | 2958 | case DRM_FORMAT_UYVY: |
c34ce3d1 | 2959 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY; |
6156a456 | 2960 | case DRM_FORMAT_VYUY: |
c34ce3d1 | 2961 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY; |
70d21f0e | 2962 | default: |
4249eeef | 2963 | MISSING_CASE(pixel_format); |
70d21f0e | 2964 | } |
8cfcba41 | 2965 | |
c34ce3d1 | 2966 | return 0; |
6156a456 | 2967 | } |
70d21f0e | 2968 | |
6156a456 CK |
2969 | u32 skl_plane_ctl_tiling(uint64_t fb_modifier) |
2970 | { | |
6156a456 | 2971 | switch (fb_modifier) { |
30af77c4 | 2972 | case DRM_FORMAT_MOD_NONE: |
70d21f0e | 2973 | break; |
30af77c4 | 2974 | case I915_FORMAT_MOD_X_TILED: |
c34ce3d1 | 2975 | return PLANE_CTL_TILED_X; |
b321803d | 2976 | case I915_FORMAT_MOD_Y_TILED: |
c34ce3d1 | 2977 | return PLANE_CTL_TILED_Y; |
b321803d | 2978 | case I915_FORMAT_MOD_Yf_TILED: |
c34ce3d1 | 2979 | return PLANE_CTL_TILED_YF; |
70d21f0e | 2980 | default: |
6156a456 | 2981 | MISSING_CASE(fb_modifier); |
70d21f0e | 2982 | } |
8cfcba41 | 2983 | |
c34ce3d1 | 2984 | return 0; |
6156a456 | 2985 | } |
70d21f0e | 2986 | |
6156a456 CK |
2987 | u32 skl_plane_ctl_rotation(unsigned int rotation) |
2988 | { | |
3b7a5119 | 2989 | switch (rotation) { |
6156a456 CK |
2990 | case BIT(DRM_ROTATE_0): |
2991 | break; | |
1e8df167 SJ |
2992 | /* |
2993 | * DRM_ROTATE_ is counter clockwise to stay compatible with Xrandr | |
2994 | * while i915 HW rotation is clockwise, thats why this swapping. | |
2995 | */ | |
3b7a5119 | 2996 | case BIT(DRM_ROTATE_90): |
1e8df167 | 2997 | return PLANE_CTL_ROTATE_270; |
3b7a5119 | 2998 | case BIT(DRM_ROTATE_180): |
c34ce3d1 | 2999 | return PLANE_CTL_ROTATE_180; |
3b7a5119 | 3000 | case BIT(DRM_ROTATE_270): |
1e8df167 | 3001 | return PLANE_CTL_ROTATE_90; |
6156a456 CK |
3002 | default: |
3003 | MISSING_CASE(rotation); | |
3004 | } | |
3005 | ||
c34ce3d1 | 3006 | return 0; |
6156a456 CK |
3007 | } |
3008 | ||
a8d201af ML |
3009 | static void skylake_update_primary_plane(struct drm_plane *plane, |
3010 | const struct intel_crtc_state *crtc_state, | |
3011 | const struct intel_plane_state *plane_state) | |
6156a456 | 3012 | { |
a8d201af | 3013 | struct drm_device *dev = plane->dev; |
6156a456 | 3014 | struct drm_i915_private *dev_priv = dev->dev_private; |
a8d201af ML |
3015 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
3016 | struct drm_framebuffer *fb = plane_state->base.fb; | |
3017 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); | |
6156a456 CK |
3018 | int pipe = intel_crtc->pipe; |
3019 | u32 plane_ctl, stride_div, stride; | |
3020 | u32 tile_height, plane_offset, plane_size; | |
a8d201af | 3021 | unsigned int rotation = plane_state->base.rotation; |
6156a456 | 3022 | int x_offset, y_offset; |
44eb0cb9 | 3023 | u32 surf_addr; |
a8d201af ML |
3024 | int scaler_id = plane_state->scaler_id; |
3025 | int src_x = plane_state->src.x1 >> 16; | |
3026 | int src_y = plane_state->src.y1 >> 16; | |
3027 | int src_w = drm_rect_width(&plane_state->src) >> 16; | |
3028 | int src_h = drm_rect_height(&plane_state->src) >> 16; | |
3029 | int dst_x = plane_state->dst.x1; | |
3030 | int dst_y = plane_state->dst.y1; | |
3031 | int dst_w = drm_rect_width(&plane_state->dst); | |
3032 | int dst_h = drm_rect_height(&plane_state->dst); | |
70d21f0e | 3033 | |
6156a456 CK |
3034 | plane_ctl = PLANE_CTL_ENABLE | |
3035 | PLANE_CTL_PIPE_GAMMA_ENABLE | | |
3036 | PLANE_CTL_PIPE_CSC_ENABLE; | |
3037 | ||
3038 | plane_ctl |= skl_plane_ctl_format(fb->pixel_format); | |
3039 | plane_ctl |= skl_plane_ctl_tiling(fb->modifier[0]); | |
3040 | plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE; | |
6156a456 CK |
3041 | plane_ctl |= skl_plane_ctl_rotation(rotation); |
3042 | ||
7b49f948 | 3043 | stride_div = intel_fb_stride_alignment(dev_priv, fb->modifier[0], |
b321803d | 3044 | fb->pixel_format); |
dedf278c | 3045 | surf_addr = intel_plane_obj_offset(to_intel_plane(plane), obj, 0); |
3b7a5119 | 3046 | |
a42e5a23 PZ |
3047 | WARN_ON(drm_rect_width(&plane_state->src) == 0); |
3048 | ||
3b7a5119 | 3049 | if (intel_rotation_90_or_270(rotation)) { |
832be82f VS |
3050 | int cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
3051 | ||
3b7a5119 | 3052 | /* stride = Surface height in tiles */ |
832be82f | 3053 | tile_height = intel_tile_height(dev_priv, fb->modifier[0], cpp); |
3b7a5119 | 3054 | stride = DIV_ROUND_UP(fb->height, tile_height); |
a8d201af ML |
3055 | x_offset = stride * tile_height - src_y - src_h; |
3056 | y_offset = src_x; | |
6156a456 | 3057 | plane_size = (src_w - 1) << 16 | (src_h - 1); |
3b7a5119 SJ |
3058 | } else { |
3059 | stride = fb->pitches[0] / stride_div; | |
a8d201af ML |
3060 | x_offset = src_x; |
3061 | y_offset = src_y; | |
6156a456 | 3062 | plane_size = (src_h - 1) << 16 | (src_w - 1); |
3b7a5119 SJ |
3063 | } |
3064 | plane_offset = y_offset << 16 | x_offset; | |
b321803d | 3065 | |
2db3366b PZ |
3066 | intel_crtc->adjusted_x = x_offset; |
3067 | intel_crtc->adjusted_y = y_offset; | |
3068 | ||
70d21f0e | 3069 | I915_WRITE(PLANE_CTL(pipe, 0), plane_ctl); |
3b7a5119 SJ |
3070 | I915_WRITE(PLANE_OFFSET(pipe, 0), plane_offset); |
3071 | I915_WRITE(PLANE_SIZE(pipe, 0), plane_size); | |
3072 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); | |
6156a456 CK |
3073 | |
3074 | if (scaler_id >= 0) { | |
3075 | uint32_t ps_ctrl = 0; | |
3076 | ||
3077 | WARN_ON(!dst_w || !dst_h); | |
3078 | ps_ctrl = PS_SCALER_EN | PS_PLANE_SEL(0) | | |
3079 | crtc_state->scaler_state.scalers[scaler_id].mode; | |
3080 | I915_WRITE(SKL_PS_CTRL(pipe, scaler_id), ps_ctrl); | |
3081 | I915_WRITE(SKL_PS_PWR_GATE(pipe, scaler_id), 0); | |
3082 | I915_WRITE(SKL_PS_WIN_POS(pipe, scaler_id), (dst_x << 16) | dst_y); | |
3083 | I915_WRITE(SKL_PS_WIN_SZ(pipe, scaler_id), (dst_w << 16) | dst_h); | |
3084 | I915_WRITE(PLANE_POS(pipe, 0), 0); | |
3085 | } else { | |
3086 | I915_WRITE(PLANE_POS(pipe, 0), (dst_y << 16) | dst_x); | |
3087 | } | |
3088 | ||
121920fa | 3089 | I915_WRITE(PLANE_SURF(pipe, 0), surf_addr); |
70d21f0e DL |
3090 | |
3091 | POSTING_READ(PLANE_SURF(pipe, 0)); | |
3092 | } | |
3093 | ||
a8d201af ML |
3094 | static void skylake_disable_primary_plane(struct drm_plane *primary, |
3095 | struct drm_crtc *crtc) | |
17638cd6 JB |
3096 | { |
3097 | struct drm_device *dev = crtc->dev; | |
3098 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a8d201af | 3099 | int pipe = to_intel_crtc(crtc)->pipe; |
17638cd6 | 3100 | |
a8d201af ML |
3101 | I915_WRITE(PLANE_CTL(pipe, 0), 0); |
3102 | I915_WRITE(PLANE_SURF(pipe, 0), 0); | |
3103 | POSTING_READ(PLANE_SURF(pipe, 0)); | |
3104 | } | |
29b9bde6 | 3105 | |
a8d201af ML |
3106 | /* Assume fb object is pinned & idle & fenced and just update base pointers */ |
3107 | static int | |
3108 | intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, | |
3109 | int x, int y, enum mode_set_atomic state) | |
3110 | { | |
3111 | /* Support for kgdboc is disabled, this needs a major rework. */ | |
3112 | DRM_ERROR("legacy panic handler not supported any more.\n"); | |
3113 | ||
3114 | return -ENODEV; | |
81255565 JB |
3115 | } |
3116 | ||
5a21b665 DV |
3117 | static void intel_complete_page_flips(struct drm_i915_private *dev_priv) |
3118 | { | |
3119 | struct intel_crtc *crtc; | |
3120 | ||
3121 | for_each_intel_crtc(dev_priv->dev, crtc) | |
3122 | intel_finish_page_flip_cs(dev_priv, crtc->pipe); | |
3123 | } | |
3124 | ||
7514747d VS |
3125 | static void intel_update_primary_planes(struct drm_device *dev) |
3126 | { | |
7514747d | 3127 | struct drm_crtc *crtc; |
96a02917 | 3128 | |
70e1e0ec | 3129 | for_each_crtc(dev, crtc) { |
11c22da6 ML |
3130 | struct intel_plane *plane = to_intel_plane(crtc->primary); |
3131 | struct intel_plane_state *plane_state; | |
96a02917 | 3132 | |
11c22da6 | 3133 | drm_modeset_lock_crtc(crtc, &plane->base); |
11c22da6 ML |
3134 | plane_state = to_intel_plane_state(plane->base.state); |
3135 | ||
a8d201af ML |
3136 | if (plane_state->visible) |
3137 | plane->update_plane(&plane->base, | |
3138 | to_intel_crtc_state(crtc->state), | |
3139 | plane_state); | |
11c22da6 ML |
3140 | |
3141 | drm_modeset_unlock_crtc(crtc); | |
96a02917 VS |
3142 | } |
3143 | } | |
3144 | ||
c033666a | 3145 | void intel_prepare_reset(struct drm_i915_private *dev_priv) |
7514747d VS |
3146 | { |
3147 | /* no reset support for gen2 */ | |
c033666a | 3148 | if (IS_GEN2(dev_priv)) |
7514747d VS |
3149 | return; |
3150 | ||
3151 | /* reset doesn't touch the display */ | |
c033666a | 3152 | if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) |
7514747d VS |
3153 | return; |
3154 | ||
c033666a | 3155 | drm_modeset_lock_all(dev_priv->dev); |
f98ce92f VS |
3156 | /* |
3157 | * Disabling the crtcs gracefully seems nicer. Also the | |
3158 | * g33 docs say we should at least disable all the planes. | |
3159 | */ | |
c033666a | 3160 | intel_display_suspend(dev_priv->dev); |
7514747d VS |
3161 | } |
3162 | ||
c033666a | 3163 | void intel_finish_reset(struct drm_i915_private *dev_priv) |
7514747d | 3164 | { |
5a21b665 DV |
3165 | /* |
3166 | * Flips in the rings will be nuked by the reset, | |
3167 | * so complete all pending flips so that user space | |
3168 | * will get its events and not get stuck. | |
3169 | */ | |
3170 | intel_complete_page_flips(dev_priv); | |
3171 | ||
7514747d | 3172 | /* no reset support for gen2 */ |
c033666a | 3173 | if (IS_GEN2(dev_priv)) |
7514747d VS |
3174 | return; |
3175 | ||
3176 | /* reset doesn't touch the display */ | |
c033666a | 3177 | if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) { |
7514747d VS |
3178 | /* |
3179 | * Flips in the rings have been nuked by the reset, | |
3180 | * so update the base address of all primary | |
3181 | * planes to the the last fb to make sure we're | |
3182 | * showing the correct fb after a reset. | |
11c22da6 ML |
3183 | * |
3184 | * FIXME: Atomic will make this obsolete since we won't schedule | |
3185 | * CS-based flips (which might get lost in gpu resets) any more. | |
7514747d | 3186 | */ |
c033666a | 3187 | intel_update_primary_planes(dev_priv->dev); |
7514747d VS |
3188 | return; |
3189 | } | |
3190 | ||
3191 | /* | |
3192 | * The display has been reset as well, | |
3193 | * so need a full re-initialization. | |
3194 | */ | |
3195 | intel_runtime_pm_disable_interrupts(dev_priv); | |
3196 | intel_runtime_pm_enable_interrupts(dev_priv); | |
3197 | ||
c033666a | 3198 | intel_modeset_init_hw(dev_priv->dev); |
7514747d VS |
3199 | |
3200 | spin_lock_irq(&dev_priv->irq_lock); | |
3201 | if (dev_priv->display.hpd_irq_setup) | |
91d14251 | 3202 | dev_priv->display.hpd_irq_setup(dev_priv); |
7514747d VS |
3203 | spin_unlock_irq(&dev_priv->irq_lock); |
3204 | ||
c033666a | 3205 | intel_display_resume(dev_priv->dev); |
7514747d VS |
3206 | |
3207 | intel_hpd_init(dev_priv); | |
3208 | ||
c033666a | 3209 | drm_modeset_unlock_all(dev_priv->dev); |
7514747d VS |
3210 | } |
3211 | ||
7d5e3799 CW |
3212 | static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) |
3213 | { | |
5a21b665 DV |
3214 | struct drm_device *dev = crtc->dev; |
3215 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3216 | unsigned reset_counter; | |
3217 | bool pending; | |
3218 | ||
3219 | reset_counter = i915_reset_counter(&to_i915(dev)->gpu_error); | |
3220 | if (intel_crtc->reset_counter != reset_counter) | |
3221 | return false; | |
3222 | ||
3223 | spin_lock_irq(&dev->event_lock); | |
3224 | pending = to_intel_crtc(crtc)->flip_work != NULL; | |
3225 | spin_unlock_irq(&dev->event_lock); | |
3226 | ||
3227 | return pending; | |
7d5e3799 CW |
3228 | } |
3229 | ||
bfd16b2a ML |
3230 | static void intel_update_pipe_config(struct intel_crtc *crtc, |
3231 | struct intel_crtc_state *old_crtc_state) | |
e30e8f75 GP |
3232 | { |
3233 | struct drm_device *dev = crtc->base.dev; | |
3234 | struct drm_i915_private *dev_priv = dev->dev_private; | |
bfd16b2a ML |
3235 | struct intel_crtc_state *pipe_config = |
3236 | to_intel_crtc_state(crtc->base.state); | |
e30e8f75 | 3237 | |
bfd16b2a ML |
3238 | /* drm_atomic_helper_update_legacy_modeset_state might not be called. */ |
3239 | crtc->base.mode = crtc->base.state->mode; | |
3240 | ||
3241 | DRM_DEBUG_KMS("Updating pipe size %ix%i -> %ix%i\n", | |
3242 | old_crtc_state->pipe_src_w, old_crtc_state->pipe_src_h, | |
3243 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); | |
e30e8f75 GP |
3244 | |
3245 | /* | |
3246 | * Update pipe size and adjust fitter if needed: the reason for this is | |
3247 | * that in compute_mode_changes we check the native mode (not the pfit | |
3248 | * mode) to see if we can flip rather than do a full mode set. In the | |
3249 | * fastboot case, we'll flip, but if we don't update the pipesrc and | |
3250 | * pfit state, we'll end up with a big fb scanned out into the wrong | |
3251 | * sized surface. | |
e30e8f75 GP |
3252 | */ |
3253 | ||
e30e8f75 | 3254 | I915_WRITE(PIPESRC(crtc->pipe), |
bfd16b2a ML |
3255 | ((pipe_config->pipe_src_w - 1) << 16) | |
3256 | (pipe_config->pipe_src_h - 1)); | |
3257 | ||
3258 | /* on skylake this is done by detaching scalers */ | |
3259 | if (INTEL_INFO(dev)->gen >= 9) { | |
3260 | skl_detach_scalers(crtc); | |
3261 | ||
3262 | if (pipe_config->pch_pfit.enabled) | |
3263 | skylake_pfit_enable(crtc); | |
3264 | } else if (HAS_PCH_SPLIT(dev)) { | |
3265 | if (pipe_config->pch_pfit.enabled) | |
3266 | ironlake_pfit_enable(crtc); | |
3267 | else if (old_crtc_state->pch_pfit.enabled) | |
3268 | ironlake_pfit_disable(crtc, true); | |
e30e8f75 | 3269 | } |
e30e8f75 GP |
3270 | } |
3271 | ||
5e84e1a4 ZW |
3272 | static void intel_fdi_normal_train(struct drm_crtc *crtc) |
3273 | { | |
3274 | struct drm_device *dev = crtc->dev; | |
3275 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3276 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3277 | int pipe = intel_crtc->pipe; | |
f0f59a00 VS |
3278 | i915_reg_t reg; |
3279 | u32 temp; | |
5e84e1a4 ZW |
3280 | |
3281 | /* enable normal train */ | |
3282 | reg = FDI_TX_CTL(pipe); | |
3283 | temp = I915_READ(reg); | |
61e499bf | 3284 | if (IS_IVYBRIDGE(dev)) { |
357555c0 JB |
3285 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
3286 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; | |
61e499bf KP |
3287 | } else { |
3288 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3289 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; | |
357555c0 | 3290 | } |
5e84e1a4 ZW |
3291 | I915_WRITE(reg, temp); |
3292 | ||
3293 | reg = FDI_RX_CTL(pipe); | |
3294 | temp = I915_READ(reg); | |
3295 | if (HAS_PCH_CPT(dev)) { | |
3296 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3297 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; | |
3298 | } else { | |
3299 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3300 | temp |= FDI_LINK_TRAIN_NONE; | |
3301 | } | |
3302 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); | |
3303 | ||
3304 | /* wait one idle pattern time */ | |
3305 | POSTING_READ(reg); | |
3306 | udelay(1000); | |
357555c0 JB |
3307 | |
3308 | /* IVB wants error correction enabled */ | |
3309 | if (IS_IVYBRIDGE(dev)) | |
3310 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | | |
3311 | FDI_FE_ERRC_ENABLE); | |
5e84e1a4 ZW |
3312 | } |
3313 | ||
8db9d77b ZW |
3314 | /* The FDI link training functions for ILK/Ibexpeak. */ |
3315 | static void ironlake_fdi_link_train(struct drm_crtc *crtc) | |
3316 | { | |
3317 | struct drm_device *dev = crtc->dev; | |
3318 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3319 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3320 | int pipe = intel_crtc->pipe; | |
f0f59a00 VS |
3321 | i915_reg_t reg; |
3322 | u32 temp, tries; | |
8db9d77b | 3323 | |
1c8562f6 | 3324 | /* FDI needs bits from pipe first */ |
0fc932b8 | 3325 | assert_pipe_enabled(dev_priv, pipe); |
0fc932b8 | 3326 | |
e1a44743 AJ |
3327 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
3328 | for train result */ | |
5eddb70b CW |
3329 | reg = FDI_RX_IMR(pipe); |
3330 | temp = I915_READ(reg); | |
e1a44743 AJ |
3331 | temp &= ~FDI_RX_SYMBOL_LOCK; |
3332 | temp &= ~FDI_RX_BIT_LOCK; | |
5eddb70b CW |
3333 | I915_WRITE(reg, temp); |
3334 | I915_READ(reg); | |
e1a44743 AJ |
3335 | udelay(150); |
3336 | ||
8db9d77b | 3337 | /* enable CPU FDI TX and PCH FDI RX */ |
5eddb70b CW |
3338 | reg = FDI_TX_CTL(pipe); |
3339 | temp = I915_READ(reg); | |
627eb5a3 | 3340 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
6e3c9717 | 3341 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
8db9d77b ZW |
3342 | temp &= ~FDI_LINK_TRAIN_NONE; |
3343 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
5eddb70b | 3344 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
8db9d77b | 3345 | |
5eddb70b CW |
3346 | reg = FDI_RX_CTL(pipe); |
3347 | temp = I915_READ(reg); | |
8db9d77b ZW |
3348 | temp &= ~FDI_LINK_TRAIN_NONE; |
3349 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
5eddb70b CW |
3350 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
3351 | ||
3352 | POSTING_READ(reg); | |
8db9d77b ZW |
3353 | udelay(150); |
3354 | ||
5b2adf89 | 3355 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
8f5718a6 DV |
3356 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
3357 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | | |
3358 | FDI_RX_PHASE_SYNC_POINTER_EN); | |
5b2adf89 | 3359 | |
5eddb70b | 3360 | reg = FDI_RX_IIR(pipe); |
e1a44743 | 3361 | for (tries = 0; tries < 5; tries++) { |
5eddb70b | 3362 | temp = I915_READ(reg); |
8db9d77b ZW |
3363 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
3364 | ||
3365 | if ((temp & FDI_RX_BIT_LOCK)) { | |
3366 | DRM_DEBUG_KMS("FDI train 1 done.\n"); | |
5eddb70b | 3367 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
8db9d77b ZW |
3368 | break; |
3369 | } | |
8db9d77b | 3370 | } |
e1a44743 | 3371 | if (tries == 5) |
5eddb70b | 3372 | DRM_ERROR("FDI train 1 fail!\n"); |
8db9d77b ZW |
3373 | |
3374 | /* Train 2 */ | |
5eddb70b CW |
3375 | reg = FDI_TX_CTL(pipe); |
3376 | temp = I915_READ(reg); | |
8db9d77b ZW |
3377 | temp &= ~FDI_LINK_TRAIN_NONE; |
3378 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
5eddb70b | 3379 | I915_WRITE(reg, temp); |
8db9d77b | 3380 | |
5eddb70b CW |
3381 | reg = FDI_RX_CTL(pipe); |
3382 | temp = I915_READ(reg); | |
8db9d77b ZW |
3383 | temp &= ~FDI_LINK_TRAIN_NONE; |
3384 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
5eddb70b | 3385 | I915_WRITE(reg, temp); |
8db9d77b | 3386 | |
5eddb70b CW |
3387 | POSTING_READ(reg); |
3388 | udelay(150); | |
8db9d77b | 3389 | |
5eddb70b | 3390 | reg = FDI_RX_IIR(pipe); |
e1a44743 | 3391 | for (tries = 0; tries < 5; tries++) { |
5eddb70b | 3392 | temp = I915_READ(reg); |
8db9d77b ZW |
3393 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
3394 | ||
3395 | if (temp & FDI_RX_SYMBOL_LOCK) { | |
5eddb70b | 3396 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
8db9d77b ZW |
3397 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
3398 | break; | |
3399 | } | |
8db9d77b | 3400 | } |
e1a44743 | 3401 | if (tries == 5) |
5eddb70b | 3402 | DRM_ERROR("FDI train 2 fail!\n"); |
8db9d77b ZW |
3403 | |
3404 | DRM_DEBUG_KMS("FDI train done\n"); | |
5c5313c8 | 3405 | |
8db9d77b ZW |
3406 | } |
3407 | ||
0206e353 | 3408 | static const int snb_b_fdi_train_param[] = { |
8db9d77b ZW |
3409 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
3410 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, | |
3411 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, | |
3412 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, | |
3413 | }; | |
3414 | ||
3415 | /* The FDI link training functions for SNB/Cougarpoint. */ | |
3416 | static void gen6_fdi_link_train(struct drm_crtc *crtc) | |
3417 | { | |
3418 | struct drm_device *dev = crtc->dev; | |
3419 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3420 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3421 | int pipe = intel_crtc->pipe; | |
f0f59a00 VS |
3422 | i915_reg_t reg; |
3423 | u32 temp, i, retry; | |
8db9d77b | 3424 | |
e1a44743 AJ |
3425 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
3426 | for train result */ | |
5eddb70b CW |
3427 | reg = FDI_RX_IMR(pipe); |
3428 | temp = I915_READ(reg); | |
e1a44743 AJ |
3429 | temp &= ~FDI_RX_SYMBOL_LOCK; |
3430 | temp &= ~FDI_RX_BIT_LOCK; | |
5eddb70b CW |
3431 | I915_WRITE(reg, temp); |
3432 | ||
3433 | POSTING_READ(reg); | |
e1a44743 AJ |
3434 | udelay(150); |
3435 | ||
8db9d77b | 3436 | /* enable CPU FDI TX and PCH FDI RX */ |
5eddb70b CW |
3437 | reg = FDI_TX_CTL(pipe); |
3438 | temp = I915_READ(reg); | |
627eb5a3 | 3439 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
6e3c9717 | 3440 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
8db9d77b ZW |
3441 | temp &= ~FDI_LINK_TRAIN_NONE; |
3442 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3443 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; | |
3444 | /* SNB-B */ | |
3445 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; | |
5eddb70b | 3446 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
8db9d77b | 3447 | |
d74cf324 DV |
3448 | I915_WRITE(FDI_RX_MISC(pipe), |
3449 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); | |
3450 | ||
5eddb70b CW |
3451 | reg = FDI_RX_CTL(pipe); |
3452 | temp = I915_READ(reg); | |
8db9d77b ZW |
3453 | if (HAS_PCH_CPT(dev)) { |
3454 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3455 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; | |
3456 | } else { | |
3457 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3458 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3459 | } | |
5eddb70b CW |
3460 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
3461 | ||
3462 | POSTING_READ(reg); | |
8db9d77b ZW |
3463 | udelay(150); |
3464 | ||
0206e353 | 3465 | for (i = 0; i < 4; i++) { |
5eddb70b CW |
3466 | reg = FDI_TX_CTL(pipe); |
3467 | temp = I915_READ(reg); | |
8db9d77b ZW |
3468 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
3469 | temp |= snb_b_fdi_train_param[i]; | |
5eddb70b CW |
3470 | I915_WRITE(reg, temp); |
3471 | ||
3472 | POSTING_READ(reg); | |
8db9d77b ZW |
3473 | udelay(500); |
3474 | ||
fa37d39e SP |
3475 | for (retry = 0; retry < 5; retry++) { |
3476 | reg = FDI_RX_IIR(pipe); | |
3477 | temp = I915_READ(reg); | |
3478 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
3479 | if (temp & FDI_RX_BIT_LOCK) { | |
3480 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); | |
3481 | DRM_DEBUG_KMS("FDI train 1 done.\n"); | |
3482 | break; | |
3483 | } | |
3484 | udelay(50); | |
8db9d77b | 3485 | } |
fa37d39e SP |
3486 | if (retry < 5) |
3487 | break; | |
8db9d77b ZW |
3488 | } |
3489 | if (i == 4) | |
5eddb70b | 3490 | DRM_ERROR("FDI train 1 fail!\n"); |
8db9d77b ZW |
3491 | |
3492 | /* Train 2 */ | |
5eddb70b CW |
3493 | reg = FDI_TX_CTL(pipe); |
3494 | temp = I915_READ(reg); | |
8db9d77b ZW |
3495 | temp &= ~FDI_LINK_TRAIN_NONE; |
3496 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
3497 | if (IS_GEN6(dev)) { | |
3498 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; | |
3499 | /* SNB-B */ | |
3500 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; | |
3501 | } | |
5eddb70b | 3502 | I915_WRITE(reg, temp); |
8db9d77b | 3503 | |
5eddb70b CW |
3504 | reg = FDI_RX_CTL(pipe); |
3505 | temp = I915_READ(reg); | |
8db9d77b ZW |
3506 | if (HAS_PCH_CPT(dev)) { |
3507 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3508 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; | |
3509 | } else { | |
3510 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3511 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
3512 | } | |
5eddb70b CW |
3513 | I915_WRITE(reg, temp); |
3514 | ||
3515 | POSTING_READ(reg); | |
8db9d77b ZW |
3516 | udelay(150); |
3517 | ||
0206e353 | 3518 | for (i = 0; i < 4; i++) { |
5eddb70b CW |
3519 | reg = FDI_TX_CTL(pipe); |
3520 | temp = I915_READ(reg); | |
8db9d77b ZW |
3521 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
3522 | temp |= snb_b_fdi_train_param[i]; | |
5eddb70b CW |
3523 | I915_WRITE(reg, temp); |
3524 | ||
3525 | POSTING_READ(reg); | |
8db9d77b ZW |
3526 | udelay(500); |
3527 | ||
fa37d39e SP |
3528 | for (retry = 0; retry < 5; retry++) { |
3529 | reg = FDI_RX_IIR(pipe); | |
3530 | temp = I915_READ(reg); | |
3531 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
3532 | if (temp & FDI_RX_SYMBOL_LOCK) { | |
3533 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); | |
3534 | DRM_DEBUG_KMS("FDI train 2 done.\n"); | |
3535 | break; | |
3536 | } | |
3537 | udelay(50); | |
8db9d77b | 3538 | } |
fa37d39e SP |
3539 | if (retry < 5) |
3540 | break; | |
8db9d77b ZW |
3541 | } |
3542 | if (i == 4) | |
5eddb70b | 3543 | DRM_ERROR("FDI train 2 fail!\n"); |
8db9d77b ZW |
3544 | |
3545 | DRM_DEBUG_KMS("FDI train done.\n"); | |
3546 | } | |
3547 | ||
357555c0 JB |
3548 | /* Manual link training for Ivy Bridge A0 parts */ |
3549 | static void ivb_manual_fdi_link_train(struct drm_crtc *crtc) | |
3550 | { | |
3551 | struct drm_device *dev = crtc->dev; | |
3552 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3553 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3554 | int pipe = intel_crtc->pipe; | |
f0f59a00 VS |
3555 | i915_reg_t reg; |
3556 | u32 temp, i, j; | |
357555c0 JB |
3557 | |
3558 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit | |
3559 | for train result */ | |
3560 | reg = FDI_RX_IMR(pipe); | |
3561 | temp = I915_READ(reg); | |
3562 | temp &= ~FDI_RX_SYMBOL_LOCK; | |
3563 | temp &= ~FDI_RX_BIT_LOCK; | |
3564 | I915_WRITE(reg, temp); | |
3565 | ||
3566 | POSTING_READ(reg); | |
3567 | udelay(150); | |
3568 | ||
01a415fd DV |
3569 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
3570 | I915_READ(FDI_RX_IIR(pipe))); | |
3571 | ||
139ccd3f JB |
3572 | /* Try each vswing and preemphasis setting twice before moving on */ |
3573 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { | |
3574 | /* disable first in case we need to retry */ | |
3575 | reg = FDI_TX_CTL(pipe); | |
3576 | temp = I915_READ(reg); | |
3577 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); | |
3578 | temp &= ~FDI_TX_ENABLE; | |
3579 | I915_WRITE(reg, temp); | |
357555c0 | 3580 | |
139ccd3f JB |
3581 | reg = FDI_RX_CTL(pipe); |
3582 | temp = I915_READ(reg); | |
3583 | temp &= ~FDI_LINK_TRAIN_AUTO; | |
3584 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3585 | temp &= ~FDI_RX_ENABLE; | |
3586 | I915_WRITE(reg, temp); | |
357555c0 | 3587 | |
139ccd3f | 3588 | /* enable CPU FDI TX and PCH FDI RX */ |
357555c0 JB |
3589 | reg = FDI_TX_CTL(pipe); |
3590 | temp = I915_READ(reg); | |
139ccd3f | 3591 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
6e3c9717 | 3592 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
139ccd3f | 3593 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
357555c0 | 3594 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
139ccd3f JB |
3595 | temp |= snb_b_fdi_train_param[j/2]; |
3596 | temp |= FDI_COMPOSITE_SYNC; | |
3597 | I915_WRITE(reg, temp | FDI_TX_ENABLE); | |
357555c0 | 3598 | |
139ccd3f JB |
3599 | I915_WRITE(FDI_RX_MISC(pipe), |
3600 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); | |
357555c0 | 3601 | |
139ccd3f | 3602 | reg = FDI_RX_CTL(pipe); |
357555c0 | 3603 | temp = I915_READ(reg); |
139ccd3f JB |
3604 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
3605 | temp |= FDI_COMPOSITE_SYNC; | |
3606 | I915_WRITE(reg, temp | FDI_RX_ENABLE); | |
357555c0 | 3607 | |
139ccd3f JB |
3608 | POSTING_READ(reg); |
3609 | udelay(1); /* should be 0.5us */ | |
357555c0 | 3610 | |
139ccd3f JB |
3611 | for (i = 0; i < 4; i++) { |
3612 | reg = FDI_RX_IIR(pipe); | |
3613 | temp = I915_READ(reg); | |
3614 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
357555c0 | 3615 | |
139ccd3f JB |
3616 | if (temp & FDI_RX_BIT_LOCK || |
3617 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { | |
3618 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); | |
3619 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", | |
3620 | i); | |
3621 | break; | |
3622 | } | |
3623 | udelay(1); /* should be 0.5us */ | |
3624 | } | |
3625 | if (i == 4) { | |
3626 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); | |
3627 | continue; | |
3628 | } | |
357555c0 | 3629 | |
139ccd3f | 3630 | /* Train 2 */ |
357555c0 JB |
3631 | reg = FDI_TX_CTL(pipe); |
3632 | temp = I915_READ(reg); | |
139ccd3f JB |
3633 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
3634 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; | |
3635 | I915_WRITE(reg, temp); | |
3636 | ||
3637 | reg = FDI_RX_CTL(pipe); | |
3638 | temp = I915_READ(reg); | |
3639 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3640 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; | |
357555c0 JB |
3641 | I915_WRITE(reg, temp); |
3642 | ||
3643 | POSTING_READ(reg); | |
139ccd3f | 3644 | udelay(2); /* should be 1.5us */ |
357555c0 | 3645 | |
139ccd3f JB |
3646 | for (i = 0; i < 4; i++) { |
3647 | reg = FDI_RX_IIR(pipe); | |
3648 | temp = I915_READ(reg); | |
3649 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
357555c0 | 3650 | |
139ccd3f JB |
3651 | if (temp & FDI_RX_SYMBOL_LOCK || |
3652 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { | |
3653 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); | |
3654 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", | |
3655 | i); | |
3656 | goto train_done; | |
3657 | } | |
3658 | udelay(2); /* should be 1.5us */ | |
357555c0 | 3659 | } |
139ccd3f JB |
3660 | if (i == 4) |
3661 | DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2); | |
357555c0 | 3662 | } |
357555c0 | 3663 | |
139ccd3f | 3664 | train_done: |
357555c0 JB |
3665 | DRM_DEBUG_KMS("FDI train done.\n"); |
3666 | } | |
3667 | ||
88cefb6c | 3668 | static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc) |
2c07245f | 3669 | { |
88cefb6c | 3670 | struct drm_device *dev = intel_crtc->base.dev; |
2c07245f | 3671 | struct drm_i915_private *dev_priv = dev->dev_private; |
2c07245f | 3672 | int pipe = intel_crtc->pipe; |
f0f59a00 VS |
3673 | i915_reg_t reg; |
3674 | u32 temp; | |
c64e311e | 3675 | |
c98e9dcf | 3676 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
5eddb70b CW |
3677 | reg = FDI_RX_CTL(pipe); |
3678 | temp = I915_READ(reg); | |
627eb5a3 | 3679 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
6e3c9717 | 3680 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
dfd07d72 | 3681 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
5eddb70b CW |
3682 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
3683 | ||
3684 | POSTING_READ(reg); | |
c98e9dcf JB |
3685 | udelay(200); |
3686 | ||
3687 | /* Switch from Rawclk to PCDclk */ | |
5eddb70b CW |
3688 | temp = I915_READ(reg); |
3689 | I915_WRITE(reg, temp | FDI_PCDCLK); | |
3690 | ||
3691 | POSTING_READ(reg); | |
c98e9dcf JB |
3692 | udelay(200); |
3693 | ||
20749730 PZ |
3694 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
3695 | reg = FDI_TX_CTL(pipe); | |
3696 | temp = I915_READ(reg); | |
3697 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { | |
3698 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); | |
5eddb70b | 3699 | |
20749730 PZ |
3700 | POSTING_READ(reg); |
3701 | udelay(100); | |
6be4a607 | 3702 | } |
0e23b99d JB |
3703 | } |
3704 | ||
88cefb6c DV |
3705 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
3706 | { | |
3707 | struct drm_device *dev = intel_crtc->base.dev; | |
3708 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3709 | int pipe = intel_crtc->pipe; | |
f0f59a00 VS |
3710 | i915_reg_t reg; |
3711 | u32 temp; | |
88cefb6c DV |
3712 | |
3713 | /* Switch from PCDclk to Rawclk */ | |
3714 | reg = FDI_RX_CTL(pipe); | |
3715 | temp = I915_READ(reg); | |
3716 | I915_WRITE(reg, temp & ~FDI_PCDCLK); | |
3717 | ||
3718 | /* Disable CPU FDI TX PLL */ | |
3719 | reg = FDI_TX_CTL(pipe); | |
3720 | temp = I915_READ(reg); | |
3721 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); | |
3722 | ||
3723 | POSTING_READ(reg); | |
3724 | udelay(100); | |
3725 | ||
3726 | reg = FDI_RX_CTL(pipe); | |
3727 | temp = I915_READ(reg); | |
3728 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); | |
3729 | ||
3730 | /* Wait for the clocks to turn off. */ | |
3731 | POSTING_READ(reg); | |
3732 | udelay(100); | |
3733 | } | |
3734 | ||
0fc932b8 JB |
3735 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
3736 | { | |
3737 | struct drm_device *dev = crtc->dev; | |
3738 | struct drm_i915_private *dev_priv = dev->dev_private; | |
3739 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3740 | int pipe = intel_crtc->pipe; | |
f0f59a00 VS |
3741 | i915_reg_t reg; |
3742 | u32 temp; | |
0fc932b8 JB |
3743 | |
3744 | /* disable CPU FDI tx and PCH FDI rx */ | |
3745 | reg = FDI_TX_CTL(pipe); | |
3746 | temp = I915_READ(reg); | |
3747 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); | |
3748 | POSTING_READ(reg); | |
3749 | ||
3750 | reg = FDI_RX_CTL(pipe); | |
3751 | temp = I915_READ(reg); | |
3752 | temp &= ~(0x7 << 16); | |
dfd07d72 | 3753 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
0fc932b8 JB |
3754 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
3755 | ||
3756 | POSTING_READ(reg); | |
3757 | udelay(100); | |
3758 | ||
3759 | /* Ironlake workaround, disable clock pointer after downing FDI */ | |
eba905b2 | 3760 | if (HAS_PCH_IBX(dev)) |
6f06ce18 | 3761 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
0fc932b8 JB |
3762 | |
3763 | /* still set train pattern 1 */ | |
3764 | reg = FDI_TX_CTL(pipe); | |
3765 | temp = I915_READ(reg); | |
3766 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3767 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3768 | I915_WRITE(reg, temp); | |
3769 | ||
3770 | reg = FDI_RX_CTL(pipe); | |
3771 | temp = I915_READ(reg); | |
3772 | if (HAS_PCH_CPT(dev)) { | |
3773 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
3774 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; | |
3775 | } else { | |
3776 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3777 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3778 | } | |
3779 | /* BPC in FDI rx is consistent with that in PIPECONF */ | |
3780 | temp &= ~(0x07 << 16); | |
dfd07d72 | 3781 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
0fc932b8 JB |
3782 | I915_WRITE(reg, temp); |
3783 | ||
3784 | POSTING_READ(reg); | |
3785 | udelay(100); | |
3786 | } | |
3787 | ||
5dce5b93 CW |
3788 | bool intel_has_pending_fb_unpin(struct drm_device *dev) |
3789 | { | |
3790 | struct intel_crtc *crtc; | |
3791 | ||
3792 | /* Note that we don't need to be called with mode_config.lock here | |
3793 | * as our list of CRTC objects is static for the lifetime of the | |
3794 | * device and so cannot disappear as we iterate. Similarly, we can | |
3795 | * happily treat the predicates as racy, atomic checks as userspace | |
3796 | * cannot claim and pin a new fb without at least acquring the | |
3797 | * struct_mutex and so serialising with us. | |
3798 | */ | |
d3fcc808 | 3799 | for_each_intel_crtc(dev, crtc) { |
5dce5b93 CW |
3800 | if (atomic_read(&crtc->unpin_work_count) == 0) |
3801 | continue; | |
3802 | ||
5a21b665 | 3803 | if (crtc->flip_work) |
5dce5b93 CW |
3804 | intel_wait_for_vblank(dev, crtc->pipe); |
3805 | ||
3806 | return true; | |
3807 | } | |
3808 | ||
3809 | return false; | |
3810 | } | |
3811 | ||
5a21b665 | 3812 | static void page_flip_completed(struct intel_crtc *intel_crtc) |
d6bbafa1 CW |
3813 | { |
3814 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); | |
5a21b665 DV |
3815 | struct intel_flip_work *work = intel_crtc->flip_work; |
3816 | ||
3817 | intel_crtc->flip_work = NULL; | |
d6bbafa1 CW |
3818 | |
3819 | if (work->event) | |
560ce1dc | 3820 | drm_crtc_send_vblank_event(&intel_crtc->base, work->event); |
d6bbafa1 CW |
3821 | |
3822 | drm_crtc_vblank_put(&intel_crtc->base); | |
3823 | ||
5a21b665 | 3824 | wake_up_all(&dev_priv->pending_flip_queue); |
143f73b3 | 3825 | queue_work(dev_priv->wq, &work->unpin_work); |
5a21b665 DV |
3826 | |
3827 | trace_i915_flip_complete(intel_crtc->plane, | |
3828 | work->pending_flip_obj); | |
d6bbafa1 CW |
3829 | } |
3830 | ||
5008e874 | 3831 | static int intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc) |
e6c3a2a6 | 3832 | { |
0f91128d | 3833 | struct drm_device *dev = crtc->dev; |
5bb61643 | 3834 | struct drm_i915_private *dev_priv = dev->dev_private; |
5008e874 | 3835 | long ret; |
e6c3a2a6 | 3836 | |
2c10d571 | 3837 | WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue)); |
5008e874 ML |
3838 | |
3839 | ret = wait_event_interruptible_timeout( | |
3840 | dev_priv->pending_flip_queue, | |
3841 | !intel_crtc_has_pending_flip(crtc), | |
3842 | 60*HZ); | |
3843 | ||
3844 | if (ret < 0) | |
3845 | return ret; | |
3846 | ||
5a21b665 DV |
3847 | if (ret == 0) { |
3848 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
3849 | struct intel_flip_work *work; | |
3850 | ||
3851 | spin_lock_irq(&dev->event_lock); | |
3852 | work = intel_crtc->flip_work; | |
3853 | if (work && !is_mmio_work(work)) { | |
3854 | WARN_ONCE(1, "Removing stuck page flip\n"); | |
3855 | page_flip_completed(intel_crtc); | |
3856 | } | |
3857 | spin_unlock_irq(&dev->event_lock); | |
3858 | } | |
5bb61643 | 3859 | |
5008e874 | 3860 | return 0; |
e6c3a2a6 CW |
3861 | } |
3862 | ||
060f02d8 VS |
3863 | static void lpt_disable_iclkip(struct drm_i915_private *dev_priv) |
3864 | { | |
3865 | u32 temp; | |
3866 | ||
3867 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); | |
3868 | ||
3869 | mutex_lock(&dev_priv->sb_lock); | |
3870 | ||
3871 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); | |
3872 | temp |= SBI_SSCCTL_DISABLE; | |
3873 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); | |
3874 | ||
3875 | mutex_unlock(&dev_priv->sb_lock); | |
3876 | } | |
3877 | ||
e615efe4 ED |
3878 | /* Program iCLKIP clock to the desired frequency */ |
3879 | static void lpt_program_iclkip(struct drm_crtc *crtc) | |
3880 | { | |
64b46a06 | 3881 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
6e3c9717 | 3882 | int clock = to_intel_crtc(crtc)->config->base.adjusted_mode.crtc_clock; |
e615efe4 ED |
3883 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
3884 | u32 temp; | |
3885 | ||
060f02d8 | 3886 | lpt_disable_iclkip(dev_priv); |
e615efe4 | 3887 | |
64b46a06 VS |
3888 | /* The iCLK virtual clock root frequency is in MHz, |
3889 | * but the adjusted_mode->crtc_clock in in KHz. To get the | |
3890 | * divisors, it is necessary to divide one by another, so we | |
3891 | * convert the virtual clock precision to KHz here for higher | |
3892 | * precision. | |
3893 | */ | |
3894 | for (auxdiv = 0; auxdiv < 2; auxdiv++) { | |
e615efe4 ED |
3895 | u32 iclk_virtual_root_freq = 172800 * 1000; |
3896 | u32 iclk_pi_range = 64; | |
64b46a06 | 3897 | u32 desired_divisor; |
e615efe4 | 3898 | |
64b46a06 VS |
3899 | desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq, |
3900 | clock << auxdiv); | |
3901 | divsel = (desired_divisor / iclk_pi_range) - 2; | |
3902 | phaseinc = desired_divisor % iclk_pi_range; | |
e615efe4 | 3903 | |
64b46a06 VS |
3904 | /* |
3905 | * Near 20MHz is a corner case which is | |
3906 | * out of range for the 7-bit divisor | |
3907 | */ | |
3908 | if (divsel <= 0x7f) | |
3909 | break; | |
e615efe4 ED |
3910 | } |
3911 | ||
3912 | /* This should not happen with any sane values */ | |
3913 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & | |
3914 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); | |
3915 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & | |
3916 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); | |
3917 | ||
3918 | DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n", | |
12d7ceed | 3919 | clock, |
e615efe4 ED |
3920 | auxdiv, |
3921 | divsel, | |
3922 | phasedir, | |
3923 | phaseinc); | |
3924 | ||
060f02d8 VS |
3925 | mutex_lock(&dev_priv->sb_lock); |
3926 | ||
e615efe4 | 3927 | /* Program SSCDIVINTPHASE6 */ |
988d6ee8 | 3928 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
e615efe4 ED |
3929 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
3930 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); | |
3931 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; | |
3932 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); | |
3933 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); | |
3934 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; | |
988d6ee8 | 3935 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
e615efe4 ED |
3936 | |
3937 | /* Program SSCAUXDIV */ | |
988d6ee8 | 3938 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
e615efe4 ED |
3939 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
3940 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); | |
988d6ee8 | 3941 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
e615efe4 ED |
3942 | |
3943 | /* Enable modulator and associated divider */ | |
988d6ee8 | 3944 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
e615efe4 | 3945 | temp &= ~SBI_SSCCTL_DISABLE; |
988d6ee8 | 3946 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
e615efe4 | 3947 | |
060f02d8 VS |
3948 | mutex_unlock(&dev_priv->sb_lock); |
3949 | ||
e615efe4 ED |
3950 | /* Wait for initialization time */ |
3951 | udelay(24); | |
3952 | ||
3953 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); | |
3954 | } | |
3955 | ||
8802e5b6 VS |
3956 | int lpt_get_iclkip(struct drm_i915_private *dev_priv) |
3957 | { | |
3958 | u32 divsel, phaseinc, auxdiv; | |
3959 | u32 iclk_virtual_root_freq = 172800 * 1000; | |
3960 | u32 iclk_pi_range = 64; | |
3961 | u32 desired_divisor; | |
3962 | u32 temp; | |
3963 | ||
3964 | if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0) | |
3965 | return 0; | |
3966 | ||
3967 | mutex_lock(&dev_priv->sb_lock); | |
3968 | ||
3969 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); | |
3970 | if (temp & SBI_SSCCTL_DISABLE) { | |
3971 | mutex_unlock(&dev_priv->sb_lock); | |
3972 | return 0; | |
3973 | } | |
3974 | ||
3975 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); | |
3976 | divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >> | |
3977 | SBI_SSCDIVINTPHASE_DIVSEL_SHIFT; | |
3978 | phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >> | |
3979 | SBI_SSCDIVINTPHASE_INCVAL_SHIFT; | |
3980 | ||
3981 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); | |
3982 | auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >> | |
3983 | SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT; | |
3984 | ||
3985 | mutex_unlock(&dev_priv->sb_lock); | |
3986 | ||
3987 | desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc; | |
3988 | ||
3989 | return DIV_ROUND_CLOSEST(iclk_virtual_root_freq, | |
3990 | desired_divisor << auxdiv); | |
3991 | } | |
3992 | ||
275f01b2 DV |
3993 | static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc, |
3994 | enum pipe pch_transcoder) | |
3995 | { | |
3996 | struct drm_device *dev = crtc->base.dev; | |
3997 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6e3c9717 | 3998 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
275f01b2 DV |
3999 | |
4000 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), | |
4001 | I915_READ(HTOTAL(cpu_transcoder))); | |
4002 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), | |
4003 | I915_READ(HBLANK(cpu_transcoder))); | |
4004 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), | |
4005 | I915_READ(HSYNC(cpu_transcoder))); | |
4006 | ||
4007 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), | |
4008 | I915_READ(VTOTAL(cpu_transcoder))); | |
4009 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), | |
4010 | I915_READ(VBLANK(cpu_transcoder))); | |
4011 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), | |
4012 | I915_READ(VSYNC(cpu_transcoder))); | |
4013 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), | |
4014 | I915_READ(VSYNCSHIFT(cpu_transcoder))); | |
4015 | } | |
4016 | ||
003632d9 | 4017 | static void cpt_set_fdi_bc_bifurcation(struct drm_device *dev, bool enable) |
1fbc0d78 DV |
4018 | { |
4019 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4020 | uint32_t temp; | |
4021 | ||
4022 | temp = I915_READ(SOUTH_CHICKEN1); | |
003632d9 | 4023 | if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable) |
1fbc0d78 DV |
4024 | return; |
4025 | ||
4026 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); | |
4027 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); | |
4028 | ||
003632d9 ACO |
4029 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
4030 | if (enable) | |
4031 | temp |= FDI_BC_BIFURCATION_SELECT; | |
4032 | ||
4033 | DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis"); | |
1fbc0d78 DV |
4034 | I915_WRITE(SOUTH_CHICKEN1, temp); |
4035 | POSTING_READ(SOUTH_CHICKEN1); | |
4036 | } | |
4037 | ||
4038 | static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc) | |
4039 | { | |
4040 | struct drm_device *dev = intel_crtc->base.dev; | |
1fbc0d78 DV |
4041 | |
4042 | switch (intel_crtc->pipe) { | |
4043 | case PIPE_A: | |
4044 | break; | |
4045 | case PIPE_B: | |
6e3c9717 | 4046 | if (intel_crtc->config->fdi_lanes > 2) |
003632d9 | 4047 | cpt_set_fdi_bc_bifurcation(dev, false); |
1fbc0d78 | 4048 | else |
003632d9 | 4049 | cpt_set_fdi_bc_bifurcation(dev, true); |
1fbc0d78 DV |
4050 | |
4051 | break; | |
4052 | case PIPE_C: | |
003632d9 | 4053 | cpt_set_fdi_bc_bifurcation(dev, true); |
1fbc0d78 DV |
4054 | |
4055 | break; | |
4056 | default: | |
4057 | BUG(); | |
4058 | } | |
4059 | } | |
4060 | ||
c48b5305 VS |
4061 | /* Return which DP Port should be selected for Transcoder DP control */ |
4062 | static enum port | |
4063 | intel_trans_dp_port_sel(struct drm_crtc *crtc) | |
4064 | { | |
4065 | struct drm_device *dev = crtc->dev; | |
4066 | struct intel_encoder *encoder; | |
4067 | ||
4068 | for_each_encoder_on_crtc(dev, crtc, encoder) { | |
4069 | if (encoder->type == INTEL_OUTPUT_DISPLAYPORT || | |
4070 | encoder->type == INTEL_OUTPUT_EDP) | |
4071 | return enc_to_dig_port(&encoder->base)->port; | |
4072 | } | |
4073 | ||
4074 | return -1; | |
4075 | } | |
4076 | ||
f67a559d JB |
4077 | /* |
4078 | * Enable PCH resources required for PCH ports: | |
4079 | * - PCH PLLs | |
4080 | * - FDI training & RX/TX | |
4081 | * - update transcoder timings | |
4082 | * - DP transcoding bits | |
4083 | * - transcoder | |
4084 | */ | |
4085 | static void ironlake_pch_enable(struct drm_crtc *crtc) | |
0e23b99d JB |
4086 | { |
4087 | struct drm_device *dev = crtc->dev; | |
4088 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4089 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4090 | int pipe = intel_crtc->pipe; | |
f0f59a00 | 4091 | u32 temp; |
2c07245f | 4092 | |
ab9412ba | 4093 | assert_pch_transcoder_disabled(dev_priv, pipe); |
e7e164db | 4094 | |
1fbc0d78 DV |
4095 | if (IS_IVYBRIDGE(dev)) |
4096 | ivybridge_update_fdi_bc_bifurcation(intel_crtc); | |
4097 | ||
cd986abb DV |
4098 | /* Write the TU size bits before fdi link training, so that error |
4099 | * detection works. */ | |
4100 | I915_WRITE(FDI_RX_TUSIZE1(pipe), | |
4101 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); | |
4102 | ||
c98e9dcf | 4103 | /* For PCH output, training FDI link */ |
674cf967 | 4104 | dev_priv->display.fdi_link_train(crtc); |
2c07245f | 4105 | |
3ad8a208 DV |
4106 | /* We need to program the right clock selection before writing the pixel |
4107 | * mutliplier into the DPLL. */ | |
303b81e0 | 4108 | if (HAS_PCH_CPT(dev)) { |
ee7b9f93 | 4109 | u32 sel; |
4b645f14 | 4110 | |
c98e9dcf | 4111 | temp = I915_READ(PCH_DPLL_SEL); |
11887397 DV |
4112 | temp |= TRANS_DPLL_ENABLE(pipe); |
4113 | sel = TRANS_DPLLB_SEL(pipe); | |
8106ddbd ACO |
4114 | if (intel_crtc->config->shared_dpll == |
4115 | intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B)) | |
ee7b9f93 JB |
4116 | temp |= sel; |
4117 | else | |
4118 | temp &= ~sel; | |
c98e9dcf | 4119 | I915_WRITE(PCH_DPLL_SEL, temp); |
c98e9dcf | 4120 | } |
5eddb70b | 4121 | |
3ad8a208 DV |
4122 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
4123 | * transcoder, and we actually should do this to not upset any PCH | |
4124 | * transcoder that already use the clock when we share it. | |
4125 | * | |
4126 | * Note that enable_shared_dpll tries to do the right thing, but | |
4127 | * get_shared_dpll unconditionally resets the pll - we need that to have | |
4128 | * the right LVDS enable sequence. */ | |
85b3894f | 4129 | intel_enable_shared_dpll(intel_crtc); |
3ad8a208 | 4130 | |
d9b6cb56 JB |
4131 | /* set transcoder timing, panel must allow it */ |
4132 | assert_panel_unlocked(dev_priv, pipe); | |
275f01b2 | 4133 | ironlake_pch_transcoder_set_timings(intel_crtc, pipe); |
8db9d77b | 4134 | |
303b81e0 | 4135 | intel_fdi_normal_train(crtc); |
5e84e1a4 | 4136 | |
c98e9dcf | 4137 | /* For PCH DP, enable TRANS_DP_CTL */ |
6e3c9717 | 4138 | if (HAS_PCH_CPT(dev) && intel_crtc->config->has_dp_encoder) { |
9c4edaee VS |
4139 | const struct drm_display_mode *adjusted_mode = |
4140 | &intel_crtc->config->base.adjusted_mode; | |
dfd07d72 | 4141 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
f0f59a00 | 4142 | i915_reg_t reg = TRANS_DP_CTL(pipe); |
5eddb70b CW |
4143 | temp = I915_READ(reg); |
4144 | temp &= ~(TRANS_DP_PORT_SEL_MASK | | |
220cad3c EA |
4145 | TRANS_DP_SYNC_MASK | |
4146 | TRANS_DP_BPC_MASK); | |
e3ef4479 | 4147 | temp |= TRANS_DP_OUTPUT_ENABLE; |
9325c9f0 | 4148 | temp |= bpc << 9; /* same format but at 11:9 */ |
c98e9dcf | 4149 | |
9c4edaee | 4150 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
5eddb70b | 4151 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
9c4edaee | 4152 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
5eddb70b | 4153 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
c98e9dcf JB |
4154 | |
4155 | switch (intel_trans_dp_port_sel(crtc)) { | |
c48b5305 | 4156 | case PORT_B: |
5eddb70b | 4157 | temp |= TRANS_DP_PORT_SEL_B; |
c98e9dcf | 4158 | break; |
c48b5305 | 4159 | case PORT_C: |
5eddb70b | 4160 | temp |= TRANS_DP_PORT_SEL_C; |
c98e9dcf | 4161 | break; |
c48b5305 | 4162 | case PORT_D: |
5eddb70b | 4163 | temp |= TRANS_DP_PORT_SEL_D; |
c98e9dcf JB |
4164 | break; |
4165 | default: | |
e95d41e1 | 4166 | BUG(); |
32f9d658 | 4167 | } |
2c07245f | 4168 | |
5eddb70b | 4169 | I915_WRITE(reg, temp); |
6be4a607 | 4170 | } |
b52eb4dc | 4171 | |
b8a4f404 | 4172 | ironlake_enable_pch_transcoder(dev_priv, pipe); |
f67a559d JB |
4173 | } |
4174 | ||
1507e5bd PZ |
4175 | static void lpt_pch_enable(struct drm_crtc *crtc) |
4176 | { | |
4177 | struct drm_device *dev = crtc->dev; | |
4178 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4179 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
6e3c9717 | 4180 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
1507e5bd | 4181 | |
ab9412ba | 4182 | assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A); |
1507e5bd | 4183 | |
8c52b5e8 | 4184 | lpt_program_iclkip(crtc); |
1507e5bd | 4185 | |
0540e488 | 4186 | /* Set transcoder timing. */ |
275f01b2 | 4187 | ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A); |
1507e5bd | 4188 | |
937bb610 | 4189 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
f67a559d JB |
4190 | } |
4191 | ||
a1520318 | 4192 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
d4270e57 JB |
4193 | { |
4194 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f0f59a00 | 4195 | i915_reg_t dslreg = PIPEDSL(pipe); |
d4270e57 JB |
4196 | u32 temp; |
4197 | ||
4198 | temp = I915_READ(dslreg); | |
4199 | udelay(500); | |
4200 | if (wait_for(I915_READ(dslreg) != temp, 5)) { | |
d4270e57 | 4201 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
84f44ce7 | 4202 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
d4270e57 JB |
4203 | } |
4204 | } | |
4205 | ||
86adf9d7 ML |
4206 | static int |
4207 | skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach, | |
4208 | unsigned scaler_user, int *scaler_id, unsigned int rotation, | |
4209 | int src_w, int src_h, int dst_w, int dst_h) | |
a1b2278e | 4210 | { |
86adf9d7 ML |
4211 | struct intel_crtc_scaler_state *scaler_state = |
4212 | &crtc_state->scaler_state; | |
4213 | struct intel_crtc *intel_crtc = | |
4214 | to_intel_crtc(crtc_state->base.crtc); | |
a1b2278e | 4215 | int need_scaling; |
6156a456 CK |
4216 | |
4217 | need_scaling = intel_rotation_90_or_270(rotation) ? | |
4218 | (src_h != dst_w || src_w != dst_h): | |
4219 | (src_w != dst_w || src_h != dst_h); | |
a1b2278e CK |
4220 | |
4221 | /* | |
4222 | * if plane is being disabled or scaler is no more required or force detach | |
4223 | * - free scaler binded to this plane/crtc | |
4224 | * - in order to do this, update crtc->scaler_usage | |
4225 | * | |
4226 | * Here scaler state in crtc_state is set free so that | |
4227 | * scaler can be assigned to other user. Actual register | |
4228 | * update to free the scaler is done in plane/panel-fit programming. | |
4229 | * For this purpose crtc/plane_state->scaler_id isn't reset here. | |
4230 | */ | |
86adf9d7 | 4231 | if (force_detach || !need_scaling) { |
a1b2278e | 4232 | if (*scaler_id >= 0) { |
86adf9d7 | 4233 | scaler_state->scaler_users &= ~(1 << scaler_user); |
a1b2278e CK |
4234 | scaler_state->scalers[*scaler_id].in_use = 0; |
4235 | ||
86adf9d7 ML |
4236 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
4237 | "Staged freeing scaler id %d scaler_users = 0x%x\n", | |
4238 | intel_crtc->pipe, scaler_user, *scaler_id, | |
a1b2278e CK |
4239 | scaler_state->scaler_users); |
4240 | *scaler_id = -1; | |
4241 | } | |
4242 | return 0; | |
4243 | } | |
4244 | ||
4245 | /* range checks */ | |
4246 | if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H || | |
4247 | dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H || | |
4248 | ||
4249 | src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H || | |
4250 | dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H) { | |
86adf9d7 | 4251 | DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u " |
a1b2278e | 4252 | "size is out of scaler range\n", |
86adf9d7 | 4253 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h); |
a1b2278e CK |
4254 | return -EINVAL; |
4255 | } | |
4256 | ||
86adf9d7 ML |
4257 | /* mark this plane as a scaler user in crtc_state */ |
4258 | scaler_state->scaler_users |= (1 << scaler_user); | |
4259 | DRM_DEBUG_KMS("scaler_user index %u.%u: " | |
4260 | "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n", | |
4261 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h, | |
4262 | scaler_state->scaler_users); | |
4263 | ||
4264 | return 0; | |
4265 | } | |
4266 | ||
4267 | /** | |
4268 | * skl_update_scaler_crtc - Stages update to scaler state for a given crtc. | |
4269 | * | |
4270 | * @state: crtc's scaler state | |
86adf9d7 ML |
4271 | * |
4272 | * Return | |
4273 | * 0 - scaler_usage updated successfully | |
4274 | * error - requested scaling cannot be supported or other error condition | |
4275 | */ | |
e435d6e5 | 4276 | int skl_update_scaler_crtc(struct intel_crtc_state *state) |
86adf9d7 ML |
4277 | { |
4278 | struct intel_crtc *intel_crtc = to_intel_crtc(state->base.crtc); | |
7c5f93b0 | 4279 | const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode; |
86adf9d7 | 4280 | |
78108b7c VS |
4281 | DRM_DEBUG_KMS("Updating scaler for [CRTC:%d:%s] scaler_user index %u.%u\n", |
4282 | intel_crtc->base.base.id, intel_crtc->base.name, | |
4283 | intel_crtc->pipe, SKL_CRTC_INDEX); | |
86adf9d7 | 4284 | |
e435d6e5 | 4285 | return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX, |
fa5a7970 | 4286 | &state->scaler_state.scaler_id, BIT(DRM_ROTATE_0), |
86adf9d7 | 4287 | state->pipe_src_w, state->pipe_src_h, |
aad941d5 | 4288 | adjusted_mode->crtc_hdisplay, adjusted_mode->crtc_vdisplay); |
86adf9d7 ML |
4289 | } |
4290 | ||
4291 | /** | |
4292 | * skl_update_scaler_plane - Stages update to scaler state for a given plane. | |
4293 | * | |
4294 | * @state: crtc's scaler state | |
86adf9d7 ML |
4295 | * @plane_state: atomic plane state to update |
4296 | * | |
4297 | * Return | |
4298 | * 0 - scaler_usage updated successfully | |
4299 | * error - requested scaling cannot be supported or other error condition | |
4300 | */ | |
da20eabd ML |
4301 | static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state, |
4302 | struct intel_plane_state *plane_state) | |
86adf9d7 ML |
4303 | { |
4304 | ||
4305 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); | |
da20eabd ML |
4306 | struct intel_plane *intel_plane = |
4307 | to_intel_plane(plane_state->base.plane); | |
86adf9d7 ML |
4308 | struct drm_framebuffer *fb = plane_state->base.fb; |
4309 | int ret; | |
4310 | ||
4311 | bool force_detach = !fb || !plane_state->visible; | |
4312 | ||
72660ce0 VS |
4313 | DRM_DEBUG_KMS("Updating scaler for [PLANE:%d:%s] scaler_user index %u.%u\n", |
4314 | intel_plane->base.base.id, intel_plane->base.name, | |
4315 | intel_crtc->pipe, drm_plane_index(&intel_plane->base)); | |
86adf9d7 ML |
4316 | |
4317 | ret = skl_update_scaler(crtc_state, force_detach, | |
4318 | drm_plane_index(&intel_plane->base), | |
4319 | &plane_state->scaler_id, | |
4320 | plane_state->base.rotation, | |
4321 | drm_rect_width(&plane_state->src) >> 16, | |
4322 | drm_rect_height(&plane_state->src) >> 16, | |
4323 | drm_rect_width(&plane_state->dst), | |
4324 | drm_rect_height(&plane_state->dst)); | |
4325 | ||
4326 | if (ret || plane_state->scaler_id < 0) | |
4327 | return ret; | |
4328 | ||
a1b2278e | 4329 | /* check colorkey */ |
818ed961 | 4330 | if (plane_state->ckey.flags != I915_SET_COLORKEY_NONE) { |
72660ce0 VS |
4331 | DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed", |
4332 | intel_plane->base.base.id, | |
4333 | intel_plane->base.name); | |
a1b2278e CK |
4334 | return -EINVAL; |
4335 | } | |
4336 | ||
4337 | /* Check src format */ | |
86adf9d7 ML |
4338 | switch (fb->pixel_format) { |
4339 | case DRM_FORMAT_RGB565: | |
4340 | case DRM_FORMAT_XBGR8888: | |
4341 | case DRM_FORMAT_XRGB8888: | |
4342 | case DRM_FORMAT_ABGR8888: | |
4343 | case DRM_FORMAT_ARGB8888: | |
4344 | case DRM_FORMAT_XRGB2101010: | |
4345 | case DRM_FORMAT_XBGR2101010: | |
4346 | case DRM_FORMAT_YUYV: | |
4347 | case DRM_FORMAT_YVYU: | |
4348 | case DRM_FORMAT_UYVY: | |
4349 | case DRM_FORMAT_VYUY: | |
4350 | break; | |
4351 | default: | |
72660ce0 VS |
4352 | DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n", |
4353 | intel_plane->base.base.id, intel_plane->base.name, | |
4354 | fb->base.id, fb->pixel_format); | |
86adf9d7 | 4355 | return -EINVAL; |
a1b2278e CK |
4356 | } |
4357 | ||
a1b2278e CK |
4358 | return 0; |
4359 | } | |
4360 | ||
e435d6e5 ML |
4361 | static void skylake_scaler_disable(struct intel_crtc *crtc) |
4362 | { | |
4363 | int i; | |
4364 | ||
4365 | for (i = 0; i < crtc->num_scalers; i++) | |
4366 | skl_detach_scaler(crtc, i); | |
4367 | } | |
4368 | ||
4369 | static void skylake_pfit_enable(struct intel_crtc *crtc) | |
bd2e244f JB |
4370 | { |
4371 | struct drm_device *dev = crtc->base.dev; | |
4372 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4373 | int pipe = crtc->pipe; | |
a1b2278e CK |
4374 | struct intel_crtc_scaler_state *scaler_state = |
4375 | &crtc->config->scaler_state; | |
4376 | ||
4377 | DRM_DEBUG_KMS("for crtc_state = %p\n", crtc->config); | |
4378 | ||
6e3c9717 | 4379 | if (crtc->config->pch_pfit.enabled) { |
a1b2278e CK |
4380 | int id; |
4381 | ||
4382 | if (WARN_ON(crtc->config->scaler_state.scaler_id < 0)) { | |
4383 | DRM_ERROR("Requesting pfit without getting a scaler first\n"); | |
4384 | return; | |
4385 | } | |
4386 | ||
4387 | id = scaler_state->scaler_id; | |
4388 | I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN | | |
4389 | PS_FILTER_MEDIUM | scaler_state->scalers[id].mode); | |
4390 | I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc->config->pch_pfit.pos); | |
4391 | I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc->config->pch_pfit.size); | |
4392 | ||
4393 | DRM_DEBUG_KMS("for crtc_state = %p scaler_id = %d\n", crtc->config, id); | |
bd2e244f JB |
4394 | } |
4395 | } | |
4396 | ||
b074cec8 JB |
4397 | static void ironlake_pfit_enable(struct intel_crtc *crtc) |
4398 | { | |
4399 | struct drm_device *dev = crtc->base.dev; | |
4400 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4401 | int pipe = crtc->pipe; | |
4402 | ||
6e3c9717 | 4403 | if (crtc->config->pch_pfit.enabled) { |
b074cec8 JB |
4404 | /* Force use of hard-coded filter coefficients |
4405 | * as some pre-programmed values are broken, | |
4406 | * e.g. x201. | |
4407 | */ | |
4408 | if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) | |
4409 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | | |
4410 | PF_PIPE_SEL_IVB(pipe)); | |
4411 | else | |
4412 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3); | |
6e3c9717 ACO |
4413 | I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos); |
4414 | I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size); | |
d4270e57 JB |
4415 | } |
4416 | } | |
4417 | ||
20bc8673 | 4418 | void hsw_enable_ips(struct intel_crtc *crtc) |
d77e4531 | 4419 | { |
cea165c3 VS |
4420 | struct drm_device *dev = crtc->base.dev; |
4421 | struct drm_i915_private *dev_priv = dev->dev_private; | |
d77e4531 | 4422 | |
6e3c9717 | 4423 | if (!crtc->config->ips_enabled) |
d77e4531 PZ |
4424 | return; |
4425 | ||
307e4498 ML |
4426 | /* |
4427 | * We can only enable IPS after we enable a plane and wait for a vblank | |
4428 | * This function is called from post_plane_update, which is run after | |
4429 | * a vblank wait. | |
4430 | */ | |
cea165c3 | 4431 | |
d77e4531 | 4432 | assert_plane_enabled(dev_priv, crtc->plane); |
cea165c3 | 4433 | if (IS_BROADWELL(dev)) { |
2a114cc1 BW |
4434 | mutex_lock(&dev_priv->rps.hw_lock); |
4435 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000)); | |
4436 | mutex_unlock(&dev_priv->rps.hw_lock); | |
4437 | /* Quoting Art Runyan: "its not safe to expect any particular | |
4438 | * value in IPS_CTL bit 31 after enabling IPS through the | |
e59150dc JB |
4439 | * mailbox." Moreover, the mailbox may return a bogus state, |
4440 | * so we need to just enable it and continue on. | |
2a114cc1 BW |
4441 | */ |
4442 | } else { | |
4443 | I915_WRITE(IPS_CTL, IPS_ENABLE); | |
4444 | /* The bit only becomes 1 in the next vblank, so this wait here | |
4445 | * is essentially intel_wait_for_vblank. If we don't have this | |
4446 | * and don't wait for vblanks until the end of crtc_enable, then | |
4447 | * the HW state readout code will complain that the expected | |
4448 | * IPS_CTL value is not the one we read. */ | |
4449 | if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50)) | |
4450 | DRM_ERROR("Timed out waiting for IPS enable\n"); | |
4451 | } | |
d77e4531 PZ |
4452 | } |
4453 | ||
20bc8673 | 4454 | void hsw_disable_ips(struct intel_crtc *crtc) |
d77e4531 PZ |
4455 | { |
4456 | struct drm_device *dev = crtc->base.dev; | |
4457 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4458 | ||
6e3c9717 | 4459 | if (!crtc->config->ips_enabled) |
d77e4531 PZ |
4460 | return; |
4461 | ||
4462 | assert_plane_enabled(dev_priv, crtc->plane); | |
23d0b130 | 4463 | if (IS_BROADWELL(dev)) { |
2a114cc1 BW |
4464 | mutex_lock(&dev_priv->rps.hw_lock); |
4465 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); | |
4466 | mutex_unlock(&dev_priv->rps.hw_lock); | |
23d0b130 BW |
4467 | /* wait for pcode to finish disabling IPS, which may take up to 42ms */ |
4468 | if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42)) | |
4469 | DRM_ERROR("Timed out waiting for IPS disable\n"); | |
e59150dc | 4470 | } else { |
2a114cc1 | 4471 | I915_WRITE(IPS_CTL, 0); |
e59150dc JB |
4472 | POSTING_READ(IPS_CTL); |
4473 | } | |
d77e4531 PZ |
4474 | |
4475 | /* We need to wait for a vblank before we can disable the plane. */ | |
4476 | intel_wait_for_vblank(dev, crtc->pipe); | |
4477 | } | |
4478 | ||
7cac945f | 4479 | static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc) |
d3eedb1a | 4480 | { |
7cac945f | 4481 | if (intel_crtc->overlay) { |
d3eedb1a VS |
4482 | struct drm_device *dev = intel_crtc->base.dev; |
4483 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4484 | ||
4485 | mutex_lock(&dev->struct_mutex); | |
4486 | dev_priv->mm.interruptible = false; | |
4487 | (void) intel_overlay_switch_off(intel_crtc->overlay); | |
4488 | dev_priv->mm.interruptible = true; | |
4489 | mutex_unlock(&dev->struct_mutex); | |
4490 | } | |
4491 | ||
4492 | /* Let userspace switch the overlay on again. In most cases userspace | |
4493 | * has to recompute where to put it anyway. | |
4494 | */ | |
4495 | } | |
4496 | ||
87d4300a ML |
4497 | /** |
4498 | * intel_post_enable_primary - Perform operations after enabling primary plane | |
4499 | * @crtc: the CRTC whose primary plane was just enabled | |
4500 | * | |
4501 | * Performs potentially sleeping operations that must be done after the primary | |
4502 | * plane is enabled, such as updating FBC and IPS. Note that this may be | |
4503 | * called due to an explicit primary plane update, or due to an implicit | |
4504 | * re-enable that is caused when a sprite plane is updated to no longer | |
4505 | * completely hide the primary plane. | |
4506 | */ | |
4507 | static void | |
4508 | intel_post_enable_primary(struct drm_crtc *crtc) | |
a5c4d7bc VS |
4509 | { |
4510 | struct drm_device *dev = crtc->dev; | |
87d4300a | 4511 | struct drm_i915_private *dev_priv = dev->dev_private; |
a5c4d7bc VS |
4512 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
4513 | int pipe = intel_crtc->pipe; | |
a5c4d7bc | 4514 | |
87d4300a ML |
4515 | /* |
4516 | * FIXME IPS should be fine as long as one plane is | |
4517 | * enabled, but in practice it seems to have problems | |
4518 | * when going from primary only to sprite only and vice | |
4519 | * versa. | |
4520 | */ | |
a5c4d7bc VS |
4521 | hsw_enable_ips(intel_crtc); |
4522 | ||
f99d7069 | 4523 | /* |
87d4300a ML |
4524 | * Gen2 reports pipe underruns whenever all planes are disabled. |
4525 | * So don't enable underrun reporting before at least some planes | |
4526 | * are enabled. | |
4527 | * FIXME: Need to fix the logic to work when we turn off all planes | |
4528 | * but leave the pipe running. | |
f99d7069 | 4529 | */ |
87d4300a ML |
4530 | if (IS_GEN2(dev)) |
4531 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); | |
4532 | ||
aca7b684 VS |
4533 | /* Underruns don't always raise interrupts, so check manually. */ |
4534 | intel_check_cpu_fifo_underruns(dev_priv); | |
4535 | intel_check_pch_fifo_underruns(dev_priv); | |
a5c4d7bc VS |
4536 | } |
4537 | ||
2622a081 | 4538 | /* FIXME move all this to pre_plane_update() with proper state tracking */ |
87d4300a ML |
4539 | static void |
4540 | intel_pre_disable_primary(struct drm_crtc *crtc) | |
a5c4d7bc VS |
4541 | { |
4542 | struct drm_device *dev = crtc->dev; | |
4543 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4544 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4545 | int pipe = intel_crtc->pipe; | |
a5c4d7bc | 4546 | |
87d4300a ML |
4547 | /* |
4548 | * Gen2 reports pipe underruns whenever all planes are disabled. | |
4549 | * So diasble underrun reporting before all the planes get disabled. | |
4550 | * FIXME: Need to fix the logic to work when we turn off all planes | |
4551 | * but leave the pipe running. | |
4552 | */ | |
4553 | if (IS_GEN2(dev)) | |
4554 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
a5c4d7bc | 4555 | |
2622a081 VS |
4556 | /* |
4557 | * FIXME IPS should be fine as long as one plane is | |
4558 | * enabled, but in practice it seems to have problems | |
4559 | * when going from primary only to sprite only and vice | |
4560 | * versa. | |
4561 | */ | |
4562 | hsw_disable_ips(intel_crtc); | |
4563 | } | |
4564 | ||
4565 | /* FIXME get rid of this and use pre_plane_update */ | |
4566 | static void | |
4567 | intel_pre_disable_primary_noatomic(struct drm_crtc *crtc) | |
4568 | { | |
4569 | struct drm_device *dev = crtc->dev; | |
4570 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4571 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4572 | int pipe = intel_crtc->pipe; | |
4573 | ||
4574 | intel_pre_disable_primary(crtc); | |
4575 | ||
87d4300a ML |
4576 | /* |
4577 | * Vblank time updates from the shadow to live plane control register | |
4578 | * are blocked if the memory self-refresh mode is active at that | |
4579 | * moment. So to make sure the plane gets truly disabled, disable | |
4580 | * first the self-refresh mode. The self-refresh enable bit in turn | |
4581 | * will be checked/applied by the HW only at the next frame start | |
4582 | * event which is after the vblank start event, so we need to have a | |
4583 | * wait-for-vblank between disabling the plane and the pipe. | |
4584 | */ | |
262cd2e1 | 4585 | if (HAS_GMCH_DISPLAY(dev)) { |
87d4300a | 4586 | intel_set_memory_cxsr(dev_priv, false); |
262cd2e1 VS |
4587 | dev_priv->wm.vlv.cxsr = false; |
4588 | intel_wait_for_vblank(dev, pipe); | |
4589 | } | |
87d4300a ML |
4590 | } |
4591 | ||
5a21b665 DV |
4592 | static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state) |
4593 | { | |
4594 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); | |
4595 | struct drm_atomic_state *old_state = old_crtc_state->base.state; | |
4596 | struct intel_crtc_state *pipe_config = | |
4597 | to_intel_crtc_state(crtc->base.state); | |
4598 | struct drm_device *dev = crtc->base.dev; | |
4599 | struct drm_plane *primary = crtc->base.primary; | |
4600 | struct drm_plane_state *old_pri_state = | |
4601 | drm_atomic_get_existing_plane_state(old_state, primary); | |
4602 | ||
4603 | intel_frontbuffer_flip(dev, pipe_config->fb_bits); | |
4604 | ||
4605 | crtc->wm.cxsr_allowed = true; | |
4606 | ||
4607 | if (pipe_config->update_wm_post && pipe_config->base.active) | |
4608 | intel_update_watermarks(&crtc->base); | |
4609 | ||
4610 | if (old_pri_state) { | |
4611 | struct intel_plane_state *primary_state = | |
4612 | to_intel_plane_state(primary->state); | |
4613 | struct intel_plane_state *old_primary_state = | |
4614 | to_intel_plane_state(old_pri_state); | |
4615 | ||
4616 | intel_fbc_post_update(crtc); | |
4617 | ||
4618 | if (primary_state->visible && | |
4619 | (needs_modeset(&pipe_config->base) || | |
4620 | !old_primary_state->visible)) | |
4621 | intel_post_enable_primary(&crtc->base); | |
4622 | } | |
4623 | } | |
4624 | ||
5c74cd73 | 4625 | static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state) |
ac21b225 | 4626 | { |
5c74cd73 | 4627 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
ac21b225 | 4628 | struct drm_device *dev = crtc->base.dev; |
eddfcbcd | 4629 | struct drm_i915_private *dev_priv = dev->dev_private; |
ab1d3a0e ML |
4630 | struct intel_crtc_state *pipe_config = |
4631 | to_intel_crtc_state(crtc->base.state); | |
5c74cd73 ML |
4632 | struct drm_atomic_state *old_state = old_crtc_state->base.state; |
4633 | struct drm_plane *primary = crtc->base.primary; | |
4634 | struct drm_plane_state *old_pri_state = | |
4635 | drm_atomic_get_existing_plane_state(old_state, primary); | |
4636 | bool modeset = needs_modeset(&pipe_config->base); | |
ac21b225 | 4637 | |
5c74cd73 ML |
4638 | if (old_pri_state) { |
4639 | struct intel_plane_state *primary_state = | |
4640 | to_intel_plane_state(primary->state); | |
4641 | struct intel_plane_state *old_primary_state = | |
4642 | to_intel_plane_state(old_pri_state); | |
4643 | ||
faf68d92 | 4644 | intel_fbc_pre_update(crtc, pipe_config, primary_state); |
31ae71fc | 4645 | |
5c74cd73 ML |
4646 | if (old_primary_state->visible && |
4647 | (modeset || !primary_state->visible)) | |
4648 | intel_pre_disable_primary(&crtc->base); | |
4649 | } | |
852eb00d | 4650 | |
a4015f9a | 4651 | if (pipe_config->disable_cxsr && HAS_GMCH_DISPLAY(dev)) { |
852eb00d | 4652 | crtc->wm.cxsr_allowed = false; |
2dfd178d | 4653 | |
2622a081 VS |
4654 | /* |
4655 | * Vblank time updates from the shadow to live plane control register | |
4656 | * are blocked if the memory self-refresh mode is active at that | |
4657 | * moment. So to make sure the plane gets truly disabled, disable | |
4658 | * first the self-refresh mode. The self-refresh enable bit in turn | |
4659 | * will be checked/applied by the HW only at the next frame start | |
4660 | * event which is after the vblank start event, so we need to have a | |
4661 | * wait-for-vblank between disabling the plane and the pipe. | |
4662 | */ | |
4663 | if (old_crtc_state->base.active) { | |
2dfd178d | 4664 | intel_set_memory_cxsr(dev_priv, false); |
2622a081 VS |
4665 | dev_priv->wm.vlv.cxsr = false; |
4666 | intel_wait_for_vblank(dev, crtc->pipe); | |
4667 | } | |
852eb00d | 4668 | } |
92826fcd | 4669 | |
ed4a6a7c MR |
4670 | /* |
4671 | * IVB workaround: must disable low power watermarks for at least | |
4672 | * one frame before enabling scaling. LP watermarks can be re-enabled | |
4673 | * when scaling is disabled. | |
4674 | * | |
4675 | * WaCxSRDisabledForSpriteScaling:ivb | |
4676 | */ | |
4677 | if (pipe_config->disable_lp_wm) { | |
4678 | ilk_disable_lp_wm(dev); | |
4679 | intel_wait_for_vblank(dev, crtc->pipe); | |
4680 | } | |
4681 | ||
4682 | /* | |
4683 | * If we're doing a modeset, we're done. No need to do any pre-vblank | |
4684 | * watermark programming here. | |
4685 | */ | |
4686 | if (needs_modeset(&pipe_config->base)) | |
4687 | return; | |
4688 | ||
4689 | /* | |
4690 | * For platforms that support atomic watermarks, program the | |
4691 | * 'intermediate' watermarks immediately. On pre-gen9 platforms, these | |
4692 | * will be the intermediate values that are safe for both pre- and | |
4693 | * post- vblank; when vblank happens, the 'active' values will be set | |
4694 | * to the final 'target' values and we'll do this again to get the | |
4695 | * optimal watermarks. For gen9+ platforms, the values we program here | |
4696 | * will be the final target values which will get automatically latched | |
4697 | * at vblank time; no further programming will be necessary. | |
4698 | * | |
4699 | * If a platform hasn't been transitioned to atomic watermarks yet, | |
4700 | * we'll continue to update watermarks the old way, if flags tell | |
4701 | * us to. | |
4702 | */ | |
4703 | if (dev_priv->display.initial_watermarks != NULL) | |
4704 | dev_priv->display.initial_watermarks(pipe_config); | |
caed361d | 4705 | else if (pipe_config->update_wm_pre) |
92826fcd | 4706 | intel_update_watermarks(&crtc->base); |
ac21b225 ML |
4707 | } |
4708 | ||
d032ffa0 | 4709 | static void intel_crtc_disable_planes(struct drm_crtc *crtc, unsigned plane_mask) |
87d4300a ML |
4710 | { |
4711 | struct drm_device *dev = crtc->dev; | |
4712 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
d032ffa0 | 4713 | struct drm_plane *p; |
87d4300a ML |
4714 | int pipe = intel_crtc->pipe; |
4715 | ||
7cac945f | 4716 | intel_crtc_dpms_overlay_disable(intel_crtc); |
27321ae8 | 4717 | |
d032ffa0 ML |
4718 | drm_for_each_plane_mask(p, dev, plane_mask) |
4719 | to_intel_plane(p)->disable_plane(p, crtc); | |
f98551ae | 4720 | |
f99d7069 DV |
4721 | /* |
4722 | * FIXME: Once we grow proper nuclear flip support out of this we need | |
4723 | * to compute the mask of flip planes precisely. For the time being | |
4724 | * consider this a flip to a NULL plane. | |
4725 | */ | |
4726 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); | |
a5c4d7bc VS |
4727 | } |
4728 | ||
f67a559d JB |
4729 | static void ironlake_crtc_enable(struct drm_crtc *crtc) |
4730 | { | |
4731 | struct drm_device *dev = crtc->dev; | |
4732 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4733 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 4734 | struct intel_encoder *encoder; |
f67a559d | 4735 | int pipe = intel_crtc->pipe; |
b95c5321 ML |
4736 | struct intel_crtc_state *pipe_config = |
4737 | to_intel_crtc_state(crtc->state); | |
f67a559d | 4738 | |
53d9f4e9 | 4739 | if (WARN_ON(intel_crtc->active)) |
f67a559d JB |
4740 | return; |
4741 | ||
b2c0593a VS |
4742 | /* |
4743 | * Sometimes spurious CPU pipe underruns happen during FDI | |
4744 | * training, at least with VGA+HDMI cloning. Suppress them. | |
4745 | * | |
4746 | * On ILK we get an occasional spurious CPU pipe underruns | |
4747 | * between eDP port A enable and vdd enable. Also PCH port | |
4748 | * enable seems to result in the occasional CPU pipe underrun. | |
4749 | * | |
4750 | * Spurious PCH underruns also occur during PCH enabling. | |
4751 | */ | |
4752 | if (intel_crtc->config->has_pch_encoder || IS_GEN5(dev_priv)) | |
4753 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
81b088ca VS |
4754 | if (intel_crtc->config->has_pch_encoder) |
4755 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); | |
4756 | ||
6e3c9717 | 4757 | if (intel_crtc->config->has_pch_encoder) |
b14b1055 DV |
4758 | intel_prepare_shared_dpll(intel_crtc); |
4759 | ||
6e3c9717 | 4760 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 4761 | intel_dp_set_m_n(intel_crtc, M1_N1); |
29407aab DV |
4762 | |
4763 | intel_set_pipe_timings(intel_crtc); | |
bc58be60 | 4764 | intel_set_pipe_src_size(intel_crtc); |
29407aab | 4765 | |
6e3c9717 | 4766 | if (intel_crtc->config->has_pch_encoder) { |
29407aab | 4767 | intel_cpu_transcoder_set_m_n(intel_crtc, |
6e3c9717 | 4768 | &intel_crtc->config->fdi_m_n, NULL); |
29407aab DV |
4769 | } |
4770 | ||
4771 | ironlake_set_pipeconf(crtc); | |
4772 | ||
f67a559d | 4773 | intel_crtc->active = true; |
8664281b | 4774 | |
f6736a1a | 4775 | for_each_encoder_on_crtc(dev, crtc, encoder) |
952735ee DV |
4776 | if (encoder->pre_enable) |
4777 | encoder->pre_enable(encoder); | |
f67a559d | 4778 | |
6e3c9717 | 4779 | if (intel_crtc->config->has_pch_encoder) { |
fff367c7 DV |
4780 | /* Note: FDI PLL enabling _must_ be done before we enable the |
4781 | * cpu pipes, hence this is separate from all the other fdi/pch | |
4782 | * enabling. */ | |
88cefb6c | 4783 | ironlake_fdi_pll_enable(intel_crtc); |
46b6f814 DV |
4784 | } else { |
4785 | assert_fdi_tx_disabled(dev_priv, pipe); | |
4786 | assert_fdi_rx_disabled(dev_priv, pipe); | |
4787 | } | |
f67a559d | 4788 | |
b074cec8 | 4789 | ironlake_pfit_enable(intel_crtc); |
f67a559d | 4790 | |
9c54c0dd JB |
4791 | /* |
4792 | * On ILK+ LUT must be loaded before the pipe is running but with | |
4793 | * clocks enabled | |
4794 | */ | |
b95c5321 | 4795 | intel_color_load_luts(&pipe_config->base); |
9c54c0dd | 4796 | |
1d5bf5d9 ID |
4797 | if (dev_priv->display.initial_watermarks != NULL) |
4798 | dev_priv->display.initial_watermarks(intel_crtc->config); | |
e1fdc473 | 4799 | intel_enable_pipe(intel_crtc); |
f67a559d | 4800 | |
6e3c9717 | 4801 | if (intel_crtc->config->has_pch_encoder) |
f67a559d | 4802 | ironlake_pch_enable(crtc); |
c98e9dcf | 4803 | |
f9b61ff6 DV |
4804 | assert_vblank_disabled(crtc); |
4805 | drm_crtc_vblank_on(crtc); | |
4806 | ||
fa5c73b1 DV |
4807 | for_each_encoder_on_crtc(dev, crtc, encoder) |
4808 | encoder->enable(encoder); | |
61b77ddd DV |
4809 | |
4810 | if (HAS_PCH_CPT(dev)) | |
a1520318 | 4811 | cpt_verify_modeset(dev, intel_crtc->pipe); |
37ca8d4c VS |
4812 | |
4813 | /* Must wait for vblank to avoid spurious PCH FIFO underruns */ | |
4814 | if (intel_crtc->config->has_pch_encoder) | |
4815 | intel_wait_for_vblank(dev, pipe); | |
b2c0593a | 4816 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
37ca8d4c | 4817 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
6be4a607 JB |
4818 | } |
4819 | ||
42db64ef PZ |
4820 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
4821 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) | |
4822 | { | |
f5adf94e | 4823 | return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A; |
42db64ef PZ |
4824 | } |
4825 | ||
4f771f10 PZ |
4826 | static void haswell_crtc_enable(struct drm_crtc *crtc) |
4827 | { | |
4828 | struct drm_device *dev = crtc->dev; | |
4829 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4830 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
4831 | struct intel_encoder *encoder; | |
99d736a2 | 4832 | int pipe = intel_crtc->pipe, hsw_workaround_pipe; |
4d1de975 | 4833 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
99d736a2 ML |
4834 | struct intel_crtc_state *pipe_config = |
4835 | to_intel_crtc_state(crtc->state); | |
4f771f10 | 4836 | |
53d9f4e9 | 4837 | if (WARN_ON(intel_crtc->active)) |
4f771f10 PZ |
4838 | return; |
4839 | ||
81b088ca VS |
4840 | if (intel_crtc->config->has_pch_encoder) |
4841 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, | |
4842 | false); | |
4843 | ||
95a7a2ae ID |
4844 | for_each_encoder_on_crtc(dev, crtc, encoder) |
4845 | if (encoder->pre_pll_enable) | |
4846 | encoder->pre_pll_enable(encoder); | |
4847 | ||
8106ddbd | 4848 | if (intel_crtc->config->shared_dpll) |
df8ad70c DV |
4849 | intel_enable_shared_dpll(intel_crtc); |
4850 | ||
6e3c9717 | 4851 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 4852 | intel_dp_set_m_n(intel_crtc, M1_N1); |
229fca97 | 4853 | |
4d1de975 JN |
4854 | if (!intel_crtc->config->has_dsi_encoder) |
4855 | intel_set_pipe_timings(intel_crtc); | |
4856 | ||
bc58be60 | 4857 | intel_set_pipe_src_size(intel_crtc); |
229fca97 | 4858 | |
4d1de975 JN |
4859 | if (cpu_transcoder != TRANSCODER_EDP && |
4860 | !transcoder_is_dsi(cpu_transcoder)) { | |
4861 | I915_WRITE(PIPE_MULT(cpu_transcoder), | |
6e3c9717 | 4862 | intel_crtc->config->pixel_multiplier - 1); |
ebb69c95 CT |
4863 | } |
4864 | ||
6e3c9717 | 4865 | if (intel_crtc->config->has_pch_encoder) { |
229fca97 | 4866 | intel_cpu_transcoder_set_m_n(intel_crtc, |
6e3c9717 | 4867 | &intel_crtc->config->fdi_m_n, NULL); |
229fca97 DV |
4868 | } |
4869 | ||
4d1de975 JN |
4870 | if (!intel_crtc->config->has_dsi_encoder) |
4871 | haswell_set_pipeconf(crtc); | |
4872 | ||
391bf048 | 4873 | haswell_set_pipemisc(crtc); |
229fca97 | 4874 | |
b95c5321 | 4875 | intel_color_set_csc(&pipe_config->base); |
229fca97 | 4876 | |
4f771f10 | 4877 | intel_crtc->active = true; |
8664281b | 4878 | |
6b698516 DV |
4879 | if (intel_crtc->config->has_pch_encoder) |
4880 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
4881 | else | |
4882 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); | |
4883 | ||
7d4aefd0 | 4884 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
4f771f10 PZ |
4885 | if (encoder->pre_enable) |
4886 | encoder->pre_enable(encoder); | |
7d4aefd0 | 4887 | } |
4f771f10 | 4888 | |
d2d65408 | 4889 | if (intel_crtc->config->has_pch_encoder) |
4fe9467d | 4890 | dev_priv->display.fdi_link_train(crtc); |
4fe9467d | 4891 | |
a65347ba | 4892 | if (!intel_crtc->config->has_dsi_encoder) |
7d4aefd0 | 4893 | intel_ddi_enable_pipe_clock(intel_crtc); |
4f771f10 | 4894 | |
1c132b44 | 4895 | if (INTEL_INFO(dev)->gen >= 9) |
e435d6e5 | 4896 | skylake_pfit_enable(intel_crtc); |
ff6d9f55 | 4897 | else |
1c132b44 | 4898 | ironlake_pfit_enable(intel_crtc); |
4f771f10 PZ |
4899 | |
4900 | /* | |
4901 | * On ILK+ LUT must be loaded before the pipe is running but with | |
4902 | * clocks enabled | |
4903 | */ | |
b95c5321 | 4904 | intel_color_load_luts(&pipe_config->base); |
4f771f10 | 4905 | |
1f544388 | 4906 | intel_ddi_set_pipe_settings(crtc); |
a65347ba | 4907 | if (!intel_crtc->config->has_dsi_encoder) |
7d4aefd0 | 4908 | intel_ddi_enable_transcoder_func(crtc); |
4f771f10 | 4909 | |
1d5bf5d9 ID |
4910 | if (dev_priv->display.initial_watermarks != NULL) |
4911 | dev_priv->display.initial_watermarks(pipe_config); | |
4912 | else | |
4913 | intel_update_watermarks(crtc); | |
4d1de975 JN |
4914 | |
4915 | /* XXX: Do the pipe assertions at the right place for BXT DSI. */ | |
4916 | if (!intel_crtc->config->has_dsi_encoder) | |
4917 | intel_enable_pipe(intel_crtc); | |
42db64ef | 4918 | |
6e3c9717 | 4919 | if (intel_crtc->config->has_pch_encoder) |
1507e5bd | 4920 | lpt_pch_enable(crtc); |
4f771f10 | 4921 | |
a65347ba | 4922 | if (intel_crtc->config->dp_encoder_is_mst) |
0e32b39c DA |
4923 | intel_ddi_set_vc_payload_alloc(crtc, true); |
4924 | ||
f9b61ff6 DV |
4925 | assert_vblank_disabled(crtc); |
4926 | drm_crtc_vblank_on(crtc); | |
4927 | ||
8807e55b | 4928 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
4f771f10 | 4929 | encoder->enable(encoder); |
8807e55b JN |
4930 | intel_opregion_notify_encoder(encoder, true); |
4931 | } | |
4f771f10 | 4932 | |
6b698516 DV |
4933 | if (intel_crtc->config->has_pch_encoder) { |
4934 | intel_wait_for_vblank(dev, pipe); | |
4935 | intel_wait_for_vblank(dev, pipe); | |
4936 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); | |
d2d65408 VS |
4937 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
4938 | true); | |
6b698516 | 4939 | } |
d2d65408 | 4940 | |
e4916946 PZ |
4941 | /* If we change the relative order between pipe/planes enabling, we need |
4942 | * to change the workaround. */ | |
99d736a2 ML |
4943 | hsw_workaround_pipe = pipe_config->hsw_workaround_pipe; |
4944 | if (IS_HASWELL(dev) && hsw_workaround_pipe != INVALID_PIPE) { | |
4945 | intel_wait_for_vblank(dev, hsw_workaround_pipe); | |
4946 | intel_wait_for_vblank(dev, hsw_workaround_pipe); | |
4947 | } | |
4f771f10 PZ |
4948 | } |
4949 | ||
bfd16b2a | 4950 | static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force) |
3f8dce3a DV |
4951 | { |
4952 | struct drm_device *dev = crtc->base.dev; | |
4953 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4954 | int pipe = crtc->pipe; | |
4955 | ||
4956 | /* To avoid upsetting the power well on haswell only disable the pfit if | |
4957 | * it's in use. The hw state code will make sure we get this right. */ | |
bfd16b2a | 4958 | if (force || crtc->config->pch_pfit.enabled) { |
3f8dce3a DV |
4959 | I915_WRITE(PF_CTL(pipe), 0); |
4960 | I915_WRITE(PF_WIN_POS(pipe), 0); | |
4961 | I915_WRITE(PF_WIN_SZ(pipe), 0); | |
4962 | } | |
4963 | } | |
4964 | ||
6be4a607 JB |
4965 | static void ironlake_crtc_disable(struct drm_crtc *crtc) |
4966 | { | |
4967 | struct drm_device *dev = crtc->dev; | |
4968 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4969 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 4970 | struct intel_encoder *encoder; |
6be4a607 | 4971 | int pipe = intel_crtc->pipe; |
b52eb4dc | 4972 | |
b2c0593a VS |
4973 | /* |
4974 | * Sometimes spurious CPU pipe underruns happen when the | |
4975 | * pipe is already disabled, but FDI RX/TX is still enabled. | |
4976 | * Happens at least with VGA+HDMI cloning. Suppress them. | |
4977 | */ | |
4978 | if (intel_crtc->config->has_pch_encoder) { | |
4979 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
37ca8d4c | 4980 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
b2c0593a | 4981 | } |
37ca8d4c | 4982 | |
ea9d758d DV |
4983 | for_each_encoder_on_crtc(dev, crtc, encoder) |
4984 | encoder->disable(encoder); | |
4985 | ||
f9b61ff6 DV |
4986 | drm_crtc_vblank_off(crtc); |
4987 | assert_vblank_disabled(crtc); | |
4988 | ||
575f7ab7 | 4989 | intel_disable_pipe(intel_crtc); |
32f9d658 | 4990 | |
bfd16b2a | 4991 | ironlake_pfit_disable(intel_crtc, false); |
2c07245f | 4992 | |
b2c0593a | 4993 | if (intel_crtc->config->has_pch_encoder) |
5a74f70a VS |
4994 | ironlake_fdi_disable(crtc); |
4995 | ||
bf49ec8c DV |
4996 | for_each_encoder_on_crtc(dev, crtc, encoder) |
4997 | if (encoder->post_disable) | |
4998 | encoder->post_disable(encoder); | |
2c07245f | 4999 | |
6e3c9717 | 5000 | if (intel_crtc->config->has_pch_encoder) { |
d925c59a | 5001 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
6be4a607 | 5002 | |
d925c59a | 5003 | if (HAS_PCH_CPT(dev)) { |
f0f59a00 VS |
5004 | i915_reg_t reg; |
5005 | u32 temp; | |
5006 | ||
d925c59a DV |
5007 | /* disable TRANS_DP_CTL */ |
5008 | reg = TRANS_DP_CTL(pipe); | |
5009 | temp = I915_READ(reg); | |
5010 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | | |
5011 | TRANS_DP_PORT_SEL_MASK); | |
5012 | temp |= TRANS_DP_PORT_SEL_NONE; | |
5013 | I915_WRITE(reg, temp); | |
5014 | ||
5015 | /* disable DPLL_SEL */ | |
5016 | temp = I915_READ(PCH_DPLL_SEL); | |
11887397 | 5017 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
d925c59a | 5018 | I915_WRITE(PCH_DPLL_SEL, temp); |
9db4a9c7 | 5019 | } |
e3421a18 | 5020 | |
d925c59a DV |
5021 | ironlake_fdi_pll_disable(intel_crtc); |
5022 | } | |
81b088ca | 5023 | |
b2c0593a | 5024 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
81b088ca | 5025 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
6be4a607 | 5026 | } |
1b3c7a47 | 5027 | |
4f771f10 | 5028 | static void haswell_crtc_disable(struct drm_crtc *crtc) |
ee7b9f93 | 5029 | { |
4f771f10 PZ |
5030 | struct drm_device *dev = crtc->dev; |
5031 | struct drm_i915_private *dev_priv = dev->dev_private; | |
ee7b9f93 | 5032 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
4f771f10 | 5033 | struct intel_encoder *encoder; |
6e3c9717 | 5034 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
ee7b9f93 | 5035 | |
d2d65408 VS |
5036 | if (intel_crtc->config->has_pch_encoder) |
5037 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, | |
5038 | false); | |
5039 | ||
8807e55b JN |
5040 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
5041 | intel_opregion_notify_encoder(encoder, false); | |
4f771f10 | 5042 | encoder->disable(encoder); |
8807e55b | 5043 | } |
4f771f10 | 5044 | |
f9b61ff6 DV |
5045 | drm_crtc_vblank_off(crtc); |
5046 | assert_vblank_disabled(crtc); | |
5047 | ||
4d1de975 JN |
5048 | /* XXX: Do the pipe assertions at the right place for BXT DSI. */ |
5049 | if (!intel_crtc->config->has_dsi_encoder) | |
5050 | intel_disable_pipe(intel_crtc); | |
4f771f10 | 5051 | |
6e3c9717 | 5052 | if (intel_crtc->config->dp_encoder_is_mst) |
a4bf214f VS |
5053 | intel_ddi_set_vc_payload_alloc(crtc, false); |
5054 | ||
a65347ba | 5055 | if (!intel_crtc->config->has_dsi_encoder) |
7d4aefd0 | 5056 | intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder); |
4f771f10 | 5057 | |
1c132b44 | 5058 | if (INTEL_INFO(dev)->gen >= 9) |
e435d6e5 | 5059 | skylake_scaler_disable(intel_crtc); |
ff6d9f55 | 5060 | else |
bfd16b2a | 5061 | ironlake_pfit_disable(intel_crtc, false); |
4f771f10 | 5062 | |
a65347ba | 5063 | if (!intel_crtc->config->has_dsi_encoder) |
7d4aefd0 | 5064 | intel_ddi_disable_pipe_clock(intel_crtc); |
4f771f10 | 5065 | |
97b040aa ID |
5066 | for_each_encoder_on_crtc(dev, crtc, encoder) |
5067 | if (encoder->post_disable) | |
5068 | encoder->post_disable(encoder); | |
81b088ca | 5069 | |
92966a37 VS |
5070 | if (intel_crtc->config->has_pch_encoder) { |
5071 | lpt_disable_pch_transcoder(dev_priv); | |
503a74e9 | 5072 | lpt_disable_iclkip(dev_priv); |
92966a37 VS |
5073 | intel_ddi_fdi_disable(crtc); |
5074 | ||
81b088ca VS |
5075 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
5076 | true); | |
92966a37 | 5077 | } |
4f771f10 PZ |
5078 | } |
5079 | ||
2dd24552 JB |
5080 | static void i9xx_pfit_enable(struct intel_crtc *crtc) |
5081 | { | |
5082 | struct drm_device *dev = crtc->base.dev; | |
5083 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6e3c9717 | 5084 | struct intel_crtc_state *pipe_config = crtc->config; |
2dd24552 | 5085 | |
681a8504 | 5086 | if (!pipe_config->gmch_pfit.control) |
2dd24552 JB |
5087 | return; |
5088 | ||
2dd24552 | 5089 | /* |
c0b03411 DV |
5090 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
5091 | * according to register description and PRM. | |
2dd24552 | 5092 | */ |
c0b03411 DV |
5093 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
5094 | assert_pipe_disabled(dev_priv, crtc->pipe); | |
2dd24552 | 5095 | |
b074cec8 JB |
5096 | I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios); |
5097 | I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control); | |
5a80c45c DV |
5098 | |
5099 | /* Border color in case we don't scale up to the full screen. Black by | |
5100 | * default, change to something else for debugging. */ | |
5101 | I915_WRITE(BCLRPAT(crtc->pipe), 0); | |
2dd24552 JB |
5102 | } |
5103 | ||
d05410f9 DA |
5104 | static enum intel_display_power_domain port_to_power_domain(enum port port) |
5105 | { | |
5106 | switch (port) { | |
5107 | case PORT_A: | |
6331a704 | 5108 | return POWER_DOMAIN_PORT_DDI_A_LANES; |
d05410f9 | 5109 | case PORT_B: |
6331a704 | 5110 | return POWER_DOMAIN_PORT_DDI_B_LANES; |
d05410f9 | 5111 | case PORT_C: |
6331a704 | 5112 | return POWER_DOMAIN_PORT_DDI_C_LANES; |
d05410f9 | 5113 | case PORT_D: |
6331a704 | 5114 | return POWER_DOMAIN_PORT_DDI_D_LANES; |
d8e19f99 | 5115 | case PORT_E: |
6331a704 | 5116 | return POWER_DOMAIN_PORT_DDI_E_LANES; |
d05410f9 | 5117 | default: |
b9fec167 | 5118 | MISSING_CASE(port); |
d05410f9 DA |
5119 | return POWER_DOMAIN_PORT_OTHER; |
5120 | } | |
5121 | } | |
5122 | ||
25f78f58 VS |
5123 | static enum intel_display_power_domain port_to_aux_power_domain(enum port port) |
5124 | { | |
5125 | switch (port) { | |
5126 | case PORT_A: | |
5127 | return POWER_DOMAIN_AUX_A; | |
5128 | case PORT_B: | |
5129 | return POWER_DOMAIN_AUX_B; | |
5130 | case PORT_C: | |
5131 | return POWER_DOMAIN_AUX_C; | |
5132 | case PORT_D: | |
5133 | return POWER_DOMAIN_AUX_D; | |
5134 | case PORT_E: | |
5135 | /* FIXME: Check VBT for actual wiring of PORT E */ | |
5136 | return POWER_DOMAIN_AUX_D; | |
5137 | default: | |
b9fec167 | 5138 | MISSING_CASE(port); |
25f78f58 VS |
5139 | return POWER_DOMAIN_AUX_A; |
5140 | } | |
5141 | } | |
5142 | ||
319be8ae ID |
5143 | enum intel_display_power_domain |
5144 | intel_display_port_power_domain(struct intel_encoder *intel_encoder) | |
5145 | { | |
5146 | struct drm_device *dev = intel_encoder->base.dev; | |
5147 | struct intel_digital_port *intel_dig_port; | |
5148 | ||
5149 | switch (intel_encoder->type) { | |
5150 | case INTEL_OUTPUT_UNKNOWN: | |
5151 | /* Only DDI platforms should ever use this output type */ | |
5152 | WARN_ON_ONCE(!HAS_DDI(dev)); | |
5153 | case INTEL_OUTPUT_DISPLAYPORT: | |
5154 | case INTEL_OUTPUT_HDMI: | |
5155 | case INTEL_OUTPUT_EDP: | |
5156 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); | |
d05410f9 | 5157 | return port_to_power_domain(intel_dig_port->port); |
0e32b39c DA |
5158 | case INTEL_OUTPUT_DP_MST: |
5159 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; | |
5160 | return port_to_power_domain(intel_dig_port->port); | |
319be8ae ID |
5161 | case INTEL_OUTPUT_ANALOG: |
5162 | return POWER_DOMAIN_PORT_CRT; | |
5163 | case INTEL_OUTPUT_DSI: | |
5164 | return POWER_DOMAIN_PORT_DSI; | |
5165 | default: | |
5166 | return POWER_DOMAIN_PORT_OTHER; | |
5167 | } | |
5168 | } | |
5169 | ||
25f78f58 VS |
5170 | enum intel_display_power_domain |
5171 | intel_display_port_aux_power_domain(struct intel_encoder *intel_encoder) | |
5172 | { | |
5173 | struct drm_device *dev = intel_encoder->base.dev; | |
5174 | struct intel_digital_port *intel_dig_port; | |
5175 | ||
5176 | switch (intel_encoder->type) { | |
5177 | case INTEL_OUTPUT_UNKNOWN: | |
651174a4 ID |
5178 | case INTEL_OUTPUT_HDMI: |
5179 | /* | |
5180 | * Only DDI platforms should ever use these output types. | |
5181 | * We can get here after the HDMI detect code has already set | |
5182 | * the type of the shared encoder. Since we can't be sure | |
5183 | * what's the status of the given connectors, play safe and | |
5184 | * run the DP detection too. | |
5185 | */ | |
25f78f58 VS |
5186 | WARN_ON_ONCE(!HAS_DDI(dev)); |
5187 | case INTEL_OUTPUT_DISPLAYPORT: | |
5188 | case INTEL_OUTPUT_EDP: | |
5189 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); | |
5190 | return port_to_aux_power_domain(intel_dig_port->port); | |
5191 | case INTEL_OUTPUT_DP_MST: | |
5192 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; | |
5193 | return port_to_aux_power_domain(intel_dig_port->port); | |
5194 | default: | |
b9fec167 | 5195 | MISSING_CASE(intel_encoder->type); |
25f78f58 VS |
5196 | return POWER_DOMAIN_AUX_A; |
5197 | } | |
5198 | } | |
5199 | ||
74bff5f9 ML |
5200 | static unsigned long get_crtc_power_domains(struct drm_crtc *crtc, |
5201 | struct intel_crtc_state *crtc_state) | |
77d22dca | 5202 | { |
319be8ae | 5203 | struct drm_device *dev = crtc->dev; |
74bff5f9 | 5204 | struct drm_encoder *encoder; |
319be8ae ID |
5205 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
5206 | enum pipe pipe = intel_crtc->pipe; | |
77d22dca | 5207 | unsigned long mask; |
74bff5f9 | 5208 | enum transcoder transcoder = crtc_state->cpu_transcoder; |
77d22dca | 5209 | |
74bff5f9 | 5210 | if (!crtc_state->base.active) |
292b990e ML |
5211 | return 0; |
5212 | ||
77d22dca ID |
5213 | mask = BIT(POWER_DOMAIN_PIPE(pipe)); |
5214 | mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder)); | |
74bff5f9 ML |
5215 | if (crtc_state->pch_pfit.enabled || |
5216 | crtc_state->pch_pfit.force_thru) | |
77d22dca ID |
5217 | mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
5218 | ||
74bff5f9 ML |
5219 | drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) { |
5220 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); | |
5221 | ||
319be8ae | 5222 | mask |= BIT(intel_display_port_power_domain(intel_encoder)); |
74bff5f9 | 5223 | } |
319be8ae | 5224 | |
15e7ec29 ML |
5225 | if (crtc_state->shared_dpll) |
5226 | mask |= BIT(POWER_DOMAIN_PLLS); | |
5227 | ||
77d22dca ID |
5228 | return mask; |
5229 | } | |
5230 | ||
74bff5f9 ML |
5231 | static unsigned long |
5232 | modeset_get_crtc_power_domains(struct drm_crtc *crtc, | |
5233 | struct intel_crtc_state *crtc_state) | |
77d22dca | 5234 | { |
292b990e ML |
5235 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
5236 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
5237 | enum intel_display_power_domain domain; | |
5a21b665 | 5238 | unsigned long domains, new_domains, old_domains; |
77d22dca | 5239 | |
292b990e | 5240 | old_domains = intel_crtc->enabled_power_domains; |
74bff5f9 ML |
5241 | intel_crtc->enabled_power_domains = new_domains = |
5242 | get_crtc_power_domains(crtc, crtc_state); | |
77d22dca | 5243 | |
5a21b665 | 5244 | domains = new_domains & ~old_domains; |
292b990e ML |
5245 | |
5246 | for_each_power_domain(domain, domains) | |
5247 | intel_display_power_get(dev_priv, domain); | |
5248 | ||
5a21b665 | 5249 | return old_domains & ~new_domains; |
292b990e ML |
5250 | } |
5251 | ||
5252 | static void modeset_put_power_domains(struct drm_i915_private *dev_priv, | |
5253 | unsigned long domains) | |
5254 | { | |
5255 | enum intel_display_power_domain domain; | |
5256 | ||
5257 | for_each_power_domain(domain, domains) | |
5258 | intel_display_power_put(dev_priv, domain); | |
5259 | } | |
77d22dca | 5260 | |
adafdc6f MK |
5261 | static int intel_compute_max_dotclk(struct drm_i915_private *dev_priv) |
5262 | { | |
5263 | int max_cdclk_freq = dev_priv->max_cdclk_freq; | |
5264 | ||
5265 | if (INTEL_INFO(dev_priv)->gen >= 9 || | |
5266 | IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) | |
5267 | return max_cdclk_freq; | |
5268 | else if (IS_CHERRYVIEW(dev_priv)) | |
5269 | return max_cdclk_freq*95/100; | |
5270 | else if (INTEL_INFO(dev_priv)->gen < 4) | |
5271 | return 2*max_cdclk_freq*90/100; | |
5272 | else | |
5273 | return max_cdclk_freq*90/100; | |
5274 | } | |
5275 | ||
b2045352 VS |
5276 | static int skl_calc_cdclk(int max_pixclk, int vco); |
5277 | ||
560a7ae4 DL |
5278 | static void intel_update_max_cdclk(struct drm_device *dev) |
5279 | { | |
5280 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5281 | ||
ef11bdb3 | 5282 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) { |
560a7ae4 | 5283 | u32 limit = I915_READ(SKL_DFSM) & SKL_DFSM_CDCLK_LIMIT_MASK; |
b2045352 VS |
5284 | int max_cdclk, vco; |
5285 | ||
5286 | vco = dev_priv->skl_preferred_vco_freq; | |
63911d72 | 5287 | WARN_ON(vco != 8100000 && vco != 8640000); |
560a7ae4 | 5288 | |
b2045352 VS |
5289 | /* |
5290 | * Use the lower (vco 8640) cdclk values as a | |
5291 | * first guess. skl_calc_cdclk() will correct it | |
5292 | * if the preferred vco is 8100 instead. | |
5293 | */ | |
560a7ae4 | 5294 | if (limit == SKL_DFSM_CDCLK_LIMIT_675) |
487ed2e4 | 5295 | max_cdclk = 617143; |
560a7ae4 | 5296 | else if (limit == SKL_DFSM_CDCLK_LIMIT_540) |
b2045352 | 5297 | max_cdclk = 540000; |
560a7ae4 | 5298 | else if (limit == SKL_DFSM_CDCLK_LIMIT_450) |
b2045352 | 5299 | max_cdclk = 432000; |
560a7ae4 | 5300 | else |
487ed2e4 | 5301 | max_cdclk = 308571; |
b2045352 VS |
5302 | |
5303 | dev_priv->max_cdclk_freq = skl_calc_cdclk(max_cdclk, vco); | |
281c114f MR |
5304 | } else if (IS_BROXTON(dev)) { |
5305 | dev_priv->max_cdclk_freq = 624000; | |
560a7ae4 DL |
5306 | } else if (IS_BROADWELL(dev)) { |
5307 | /* | |
5308 | * FIXME with extra cooling we can allow | |
5309 | * 540 MHz for ULX and 675 Mhz for ULT. | |
5310 | * How can we know if extra cooling is | |
5311 | * available? PCI ID, VTB, something else? | |
5312 | */ | |
5313 | if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
5314 | dev_priv->max_cdclk_freq = 450000; | |
5315 | else if (IS_BDW_ULX(dev)) | |
5316 | dev_priv->max_cdclk_freq = 450000; | |
5317 | else if (IS_BDW_ULT(dev)) | |
5318 | dev_priv->max_cdclk_freq = 540000; | |
5319 | else | |
5320 | dev_priv->max_cdclk_freq = 675000; | |
0904deaf MK |
5321 | } else if (IS_CHERRYVIEW(dev)) { |
5322 | dev_priv->max_cdclk_freq = 320000; | |
560a7ae4 DL |
5323 | } else if (IS_VALLEYVIEW(dev)) { |
5324 | dev_priv->max_cdclk_freq = 400000; | |
5325 | } else { | |
5326 | /* otherwise assume cdclk is fixed */ | |
5327 | dev_priv->max_cdclk_freq = dev_priv->cdclk_freq; | |
5328 | } | |
5329 | ||
adafdc6f MK |
5330 | dev_priv->max_dotclk_freq = intel_compute_max_dotclk(dev_priv); |
5331 | ||
560a7ae4 DL |
5332 | DRM_DEBUG_DRIVER("Max CD clock rate: %d kHz\n", |
5333 | dev_priv->max_cdclk_freq); | |
adafdc6f MK |
5334 | |
5335 | DRM_DEBUG_DRIVER("Max dotclock rate: %d kHz\n", | |
5336 | dev_priv->max_dotclk_freq); | |
560a7ae4 DL |
5337 | } |
5338 | ||
5339 | static void intel_update_cdclk(struct drm_device *dev) | |
5340 | { | |
5341 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5342 | ||
5343 | dev_priv->cdclk_freq = dev_priv->display.get_display_clock_speed(dev); | |
2f2a121a | 5344 | |
83d7c81f | 5345 | if (INTEL_GEN(dev_priv) >= 9) |
709e05c3 VS |
5346 | DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz, VCO: %d kHz, ref: %d kHz\n", |
5347 | dev_priv->cdclk_freq, dev_priv->cdclk_pll.vco, | |
5348 | dev_priv->cdclk_pll.ref); | |
2f2a121a VS |
5349 | else |
5350 | DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n", | |
5351 | dev_priv->cdclk_freq); | |
560a7ae4 DL |
5352 | |
5353 | /* | |
b5d99ff9 VS |
5354 | * 9:0 CMBUS [sic] CDCLK frequency (cdfreq): |
5355 | * Programmng [sic] note: bit[9:2] should be programmed to the number | |
5356 | * of cdclk that generates 4MHz reference clock freq which is used to | |
5357 | * generate GMBus clock. This will vary with the cdclk freq. | |
560a7ae4 | 5358 | */ |
b5d99ff9 | 5359 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
560a7ae4 | 5360 | I915_WRITE(GMBUSFREQ_VLV, DIV_ROUND_UP(dev_priv->cdclk_freq, 1000)); |
560a7ae4 DL |
5361 | } |
5362 | ||
92891e45 VS |
5363 | /* convert from kHz to .1 fixpoint MHz with -1MHz offset */ |
5364 | static int skl_cdclk_decimal(int cdclk) | |
5365 | { | |
5366 | return DIV_ROUND_CLOSEST(cdclk - 1000, 500); | |
5367 | } | |
5368 | ||
5f199dfa VS |
5369 | static int bxt_de_pll_vco(struct drm_i915_private *dev_priv, int cdclk) |
5370 | { | |
5371 | int ratio; | |
5372 | ||
5373 | if (cdclk == dev_priv->cdclk_pll.ref) | |
5374 | return 0; | |
5375 | ||
5376 | switch (cdclk) { | |
5377 | default: | |
5378 | MISSING_CASE(cdclk); | |
5379 | case 144000: | |
5380 | case 288000: | |
5381 | case 384000: | |
5382 | case 576000: | |
5383 | ratio = 60; | |
5384 | break; | |
5385 | case 624000: | |
5386 | ratio = 65; | |
5387 | break; | |
5388 | } | |
5389 | ||
5390 | return dev_priv->cdclk_pll.ref * ratio; | |
5391 | } | |
5392 | ||
2b73001e VS |
5393 | static void bxt_de_pll_disable(struct drm_i915_private *dev_priv) |
5394 | { | |
5395 | I915_WRITE(BXT_DE_PLL_ENABLE, 0); | |
5396 | ||
5397 | /* Timeout 200us */ | |
5398 | if (wait_for((I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK) == 0, 1)) | |
5399 | DRM_ERROR("timeout waiting for DE PLL unlock\n"); | |
83d7c81f VS |
5400 | |
5401 | dev_priv->cdclk_pll.vco = 0; | |
2b73001e VS |
5402 | } |
5403 | ||
5f199dfa | 5404 | static void bxt_de_pll_enable(struct drm_i915_private *dev_priv, int vco) |
2b73001e | 5405 | { |
5f199dfa | 5406 | int ratio = DIV_ROUND_CLOSEST(vco, dev_priv->cdclk_pll.ref); |
2b73001e VS |
5407 | u32 val; |
5408 | ||
5409 | val = I915_READ(BXT_DE_PLL_CTL); | |
5410 | val &= ~BXT_DE_PLL_RATIO_MASK; | |
5f199dfa | 5411 | val |= BXT_DE_PLL_RATIO(ratio); |
2b73001e VS |
5412 | I915_WRITE(BXT_DE_PLL_CTL, val); |
5413 | ||
5414 | I915_WRITE(BXT_DE_PLL_ENABLE, BXT_DE_PLL_PLL_ENABLE); | |
5415 | ||
5416 | /* Timeout 200us */ | |
5417 | if (wait_for((I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK) != 0, 1)) | |
5418 | DRM_ERROR("timeout waiting for DE PLL lock\n"); | |
83d7c81f | 5419 | |
5f199dfa | 5420 | dev_priv->cdclk_pll.vco = vco; |
2b73001e VS |
5421 | } |
5422 | ||
324513c0 | 5423 | static void bxt_set_cdclk(struct drm_i915_private *dev_priv, int cdclk) |
f8437dd1 | 5424 | { |
5f199dfa VS |
5425 | u32 val, divider; |
5426 | int vco, ret; | |
f8437dd1 | 5427 | |
5f199dfa VS |
5428 | vco = bxt_de_pll_vco(dev_priv, cdclk); |
5429 | ||
5430 | DRM_DEBUG_DRIVER("Changing CDCLK to %d kHz (VCO %d kHz)\n", cdclk, vco); | |
5431 | ||
5432 | /* cdclk = vco / 2 / div{1,1.5,2,4} */ | |
5433 | switch (DIV_ROUND_CLOSEST(vco, cdclk)) { | |
5434 | case 8: | |
f8437dd1 | 5435 | divider = BXT_CDCLK_CD2X_DIV_SEL_4; |
f8437dd1 | 5436 | break; |
5f199dfa | 5437 | case 4: |
f8437dd1 | 5438 | divider = BXT_CDCLK_CD2X_DIV_SEL_2; |
f8437dd1 | 5439 | break; |
5f199dfa | 5440 | case 3: |
f8437dd1 | 5441 | divider = BXT_CDCLK_CD2X_DIV_SEL_1_5; |
f8437dd1 | 5442 | break; |
5f199dfa | 5443 | case 2: |
f8437dd1 | 5444 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; |
f8437dd1 VK |
5445 | break; |
5446 | default: | |
5f199dfa VS |
5447 | WARN_ON(cdclk != dev_priv->cdclk_pll.ref); |
5448 | WARN_ON(vco != 0); | |
f8437dd1 | 5449 | |
5f199dfa VS |
5450 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; |
5451 | break; | |
f8437dd1 VK |
5452 | } |
5453 | ||
f8437dd1 | 5454 | /* Inform power controller of upcoming frequency change */ |
5f199dfa | 5455 | mutex_lock(&dev_priv->rps.hw_lock); |
f8437dd1 VK |
5456 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, |
5457 | 0x80000000); | |
5458 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5459 | ||
5460 | if (ret) { | |
5461 | DRM_ERROR("PCode CDCLK freq change notify failed (err %d, freq %d)\n", | |
9ef56154 | 5462 | ret, cdclk); |
f8437dd1 VK |
5463 | return; |
5464 | } | |
5465 | ||
5f199dfa VS |
5466 | if (dev_priv->cdclk_pll.vco != 0 && |
5467 | dev_priv->cdclk_pll.vco != vco) | |
2b73001e | 5468 | bxt_de_pll_disable(dev_priv); |
f8437dd1 | 5469 | |
5f199dfa VS |
5470 | if (dev_priv->cdclk_pll.vco != vco) |
5471 | bxt_de_pll_enable(dev_priv, vco); | |
f8437dd1 | 5472 | |
5f199dfa VS |
5473 | val = divider | skl_cdclk_decimal(cdclk); |
5474 | /* | |
5475 | * FIXME if only the cd2x divider needs changing, it could be done | |
5476 | * without shutting off the pipe (if only one pipe is active). | |
5477 | */ | |
5478 | val |= BXT_CDCLK_CD2X_PIPE_NONE; | |
5479 | /* | |
5480 | * Disable SSA Precharge when CD clock frequency < 500 MHz, | |
5481 | * enable otherwise. | |
5482 | */ | |
5483 | if (cdclk >= 500000) | |
5484 | val |= BXT_CDCLK_SSA_PRECHARGE_ENABLE; | |
5485 | I915_WRITE(CDCLK_CTL, val); | |
f8437dd1 VK |
5486 | |
5487 | mutex_lock(&dev_priv->rps.hw_lock); | |
5488 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, | |
9ef56154 | 5489 | DIV_ROUND_UP(cdclk, 25000)); |
f8437dd1 VK |
5490 | mutex_unlock(&dev_priv->rps.hw_lock); |
5491 | ||
5492 | if (ret) { | |
5493 | DRM_ERROR("PCode CDCLK freq set failed, (err %d, freq %d)\n", | |
9ef56154 | 5494 | ret, cdclk); |
f8437dd1 VK |
5495 | return; |
5496 | } | |
5497 | ||
c6c4696f | 5498 | intel_update_cdclk(dev_priv->dev); |
f8437dd1 VK |
5499 | } |
5500 | ||
d66a2194 | 5501 | static void bxt_sanitize_cdclk(struct drm_i915_private *dev_priv) |
f8437dd1 | 5502 | { |
d66a2194 ID |
5503 | u32 cdctl, expected; |
5504 | ||
089c6fd5 | 5505 | intel_update_cdclk(dev_priv->dev); |
f8437dd1 | 5506 | |
d66a2194 ID |
5507 | if (dev_priv->cdclk_pll.vco == 0 || |
5508 | dev_priv->cdclk_freq == dev_priv->cdclk_pll.ref) | |
5509 | goto sanitize; | |
5510 | ||
5511 | /* DPLL okay; verify the cdclock | |
5512 | * | |
5513 | * Some BIOS versions leave an incorrect decimal frequency value and | |
5514 | * set reserved MBZ bits in CDCLK_CTL at least during exiting from S4, | |
5515 | * so sanitize this register. | |
5516 | */ | |
5517 | cdctl = I915_READ(CDCLK_CTL); | |
5518 | /* | |
5519 | * Let's ignore the pipe field, since BIOS could have configured the | |
5520 | * dividers both synching to an active pipe, or asynchronously | |
5521 | * (PIPE_NONE). | |
5522 | */ | |
5523 | cdctl &= ~BXT_CDCLK_CD2X_PIPE_NONE; | |
5524 | ||
5525 | expected = (cdctl & BXT_CDCLK_CD2X_DIV_SEL_MASK) | | |
5526 | skl_cdclk_decimal(dev_priv->cdclk_freq); | |
5527 | /* | |
5528 | * Disable SSA Precharge when CD clock frequency < 500 MHz, | |
5529 | * enable otherwise. | |
5530 | */ | |
5531 | if (dev_priv->cdclk_freq >= 500000) | |
5532 | expected |= BXT_CDCLK_SSA_PRECHARGE_ENABLE; | |
5533 | ||
5534 | if (cdctl == expected) | |
5535 | /* All well; nothing to sanitize */ | |
5536 | return; | |
5537 | ||
5538 | sanitize: | |
5539 | DRM_DEBUG_KMS("Sanitizing cdclk programmed by pre-os\n"); | |
5540 | ||
5541 | /* force cdclk programming */ | |
5542 | dev_priv->cdclk_freq = 0; | |
5543 | ||
5544 | /* force full PLL disable + enable */ | |
5545 | dev_priv->cdclk_pll.vco = -1; | |
5546 | } | |
5547 | ||
324513c0 | 5548 | void bxt_init_cdclk(struct drm_i915_private *dev_priv) |
d66a2194 ID |
5549 | { |
5550 | bxt_sanitize_cdclk(dev_priv); | |
5551 | ||
5552 | if (dev_priv->cdclk_freq != 0 && dev_priv->cdclk_pll.vco != 0) | |
089c6fd5 | 5553 | return; |
c2e001ef | 5554 | |
f8437dd1 VK |
5555 | /* |
5556 | * FIXME: | |
5557 | * - The initial CDCLK needs to be read from VBT. | |
5558 | * Need to make this change after VBT has changes for BXT. | |
f8437dd1 | 5559 | */ |
324513c0 | 5560 | bxt_set_cdclk(dev_priv, bxt_calc_cdclk(0)); |
f8437dd1 VK |
5561 | } |
5562 | ||
324513c0 | 5563 | void bxt_uninit_cdclk(struct drm_i915_private *dev_priv) |
f8437dd1 | 5564 | { |
324513c0 | 5565 | bxt_set_cdclk(dev_priv, dev_priv->cdclk_pll.ref); |
f8437dd1 VK |
5566 | } |
5567 | ||
a8ca4934 VS |
5568 | static int skl_calc_cdclk(int max_pixclk, int vco) |
5569 | { | |
63911d72 | 5570 | if (vco == 8640000) { |
a8ca4934 | 5571 | if (max_pixclk > 540000) |
487ed2e4 | 5572 | return 617143; |
a8ca4934 VS |
5573 | else if (max_pixclk > 432000) |
5574 | return 540000; | |
487ed2e4 | 5575 | else if (max_pixclk > 308571) |
a8ca4934 VS |
5576 | return 432000; |
5577 | else | |
487ed2e4 | 5578 | return 308571; |
a8ca4934 | 5579 | } else { |
a8ca4934 VS |
5580 | if (max_pixclk > 540000) |
5581 | return 675000; | |
5582 | else if (max_pixclk > 450000) | |
5583 | return 540000; | |
5584 | else if (max_pixclk > 337500) | |
5585 | return 450000; | |
5586 | else | |
5587 | return 337500; | |
5588 | } | |
5589 | } | |
5590 | ||
ea61791e VS |
5591 | static void |
5592 | skl_dpll0_update(struct drm_i915_private *dev_priv) | |
5d96d8af | 5593 | { |
ea61791e | 5594 | u32 val; |
5d96d8af | 5595 | |
709e05c3 | 5596 | dev_priv->cdclk_pll.ref = 24000; |
1c3f7700 | 5597 | dev_priv->cdclk_pll.vco = 0; |
709e05c3 | 5598 | |
ea61791e | 5599 | val = I915_READ(LCPLL1_CTL); |
1c3f7700 | 5600 | if ((val & LCPLL_PLL_ENABLE) == 0) |
ea61791e | 5601 | return; |
5d96d8af | 5602 | |
1c3f7700 ID |
5603 | if (WARN_ON((val & LCPLL_PLL_LOCK) == 0)) |
5604 | return; | |
9f7eb31a | 5605 | |
ea61791e VS |
5606 | val = I915_READ(DPLL_CTRL1); |
5607 | ||
1c3f7700 ID |
5608 | if (WARN_ON((val & (DPLL_CTRL1_HDMI_MODE(SKL_DPLL0) | |
5609 | DPLL_CTRL1_SSC(SKL_DPLL0) | | |
5610 | DPLL_CTRL1_OVERRIDE(SKL_DPLL0))) != | |
5611 | DPLL_CTRL1_OVERRIDE(SKL_DPLL0))) | |
5612 | return; | |
9f7eb31a | 5613 | |
ea61791e VS |
5614 | switch (val & DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)) { |
5615 | case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810, SKL_DPLL0): | |
5616 | case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1350, SKL_DPLL0): | |
5617 | case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1620, SKL_DPLL0): | |
5618 | case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_2700, SKL_DPLL0): | |
63911d72 | 5619 | dev_priv->cdclk_pll.vco = 8100000; |
ea61791e VS |
5620 | break; |
5621 | case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080, SKL_DPLL0): | |
5622 | case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_2160, SKL_DPLL0): | |
63911d72 | 5623 | dev_priv->cdclk_pll.vco = 8640000; |
ea61791e VS |
5624 | break; |
5625 | default: | |
5626 | MISSING_CASE(val & DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)); | |
ea61791e VS |
5627 | break; |
5628 | } | |
5d96d8af DL |
5629 | } |
5630 | ||
b2045352 VS |
5631 | void skl_set_preferred_cdclk_vco(struct drm_i915_private *dev_priv, int vco) |
5632 | { | |
5633 | bool changed = dev_priv->skl_preferred_vco_freq != vco; | |
5634 | ||
5635 | dev_priv->skl_preferred_vco_freq = vco; | |
5636 | ||
5637 | if (changed) | |
5638 | intel_update_max_cdclk(dev_priv->dev); | |
5639 | } | |
5640 | ||
5d96d8af | 5641 | static void |
3861fc60 | 5642 | skl_dpll0_enable(struct drm_i915_private *dev_priv, int vco) |
5d96d8af | 5643 | { |
a8ca4934 | 5644 | int min_cdclk = skl_calc_cdclk(0, vco); |
5d96d8af DL |
5645 | u32 val; |
5646 | ||
63911d72 | 5647 | WARN_ON(vco != 8100000 && vco != 8640000); |
b2045352 | 5648 | |
5d96d8af | 5649 | /* select the minimum CDCLK before enabling DPLL 0 */ |
9ef56154 | 5650 | val = CDCLK_FREQ_337_308 | skl_cdclk_decimal(min_cdclk); |
5d96d8af DL |
5651 | I915_WRITE(CDCLK_CTL, val); |
5652 | POSTING_READ(CDCLK_CTL); | |
5653 | ||
5654 | /* | |
5655 | * We always enable DPLL0 with the lowest link rate possible, but still | |
5656 | * taking into account the VCO required to operate the eDP panel at the | |
5657 | * desired frequency. The usual DP link rates operate with a VCO of | |
5658 | * 8100 while the eDP 1.4 alternate link rates need a VCO of 8640. | |
5659 | * The modeset code is responsible for the selection of the exact link | |
5660 | * rate later on, with the constraint of choosing a frequency that | |
a8ca4934 | 5661 | * works with vco. |
5d96d8af DL |
5662 | */ |
5663 | val = I915_READ(DPLL_CTRL1); | |
5664 | ||
5665 | val &= ~(DPLL_CTRL1_HDMI_MODE(SKL_DPLL0) | DPLL_CTRL1_SSC(SKL_DPLL0) | | |
5666 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)); | |
5667 | val |= DPLL_CTRL1_OVERRIDE(SKL_DPLL0); | |
63911d72 | 5668 | if (vco == 8640000) |
5d96d8af DL |
5669 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080, |
5670 | SKL_DPLL0); | |
5671 | else | |
5672 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810, | |
5673 | SKL_DPLL0); | |
5674 | ||
5675 | I915_WRITE(DPLL_CTRL1, val); | |
5676 | POSTING_READ(DPLL_CTRL1); | |
5677 | ||
5678 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) | LCPLL_PLL_ENABLE); | |
5679 | ||
5680 | if (wait_for(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK, 5)) | |
5681 | DRM_ERROR("DPLL0 not locked\n"); | |
1cd593e0 | 5682 | |
63911d72 | 5683 | dev_priv->cdclk_pll.vco = vco; |
b2045352 VS |
5684 | |
5685 | /* We'll want to keep using the current vco from now on. */ | |
5686 | skl_set_preferred_cdclk_vco(dev_priv, vco); | |
5d96d8af DL |
5687 | } |
5688 | ||
430e05de VS |
5689 | static void |
5690 | skl_dpll0_disable(struct drm_i915_private *dev_priv) | |
5691 | { | |
5692 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) & ~LCPLL_PLL_ENABLE); | |
5693 | if (wait_for(!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK), 1)) | |
5694 | DRM_ERROR("Couldn't disable DPLL0\n"); | |
1cd593e0 | 5695 | |
63911d72 | 5696 | dev_priv->cdclk_pll.vco = 0; |
430e05de VS |
5697 | } |
5698 | ||
5d96d8af DL |
5699 | static bool skl_cdclk_pcu_ready(struct drm_i915_private *dev_priv) |
5700 | { | |
5701 | int ret; | |
5702 | u32 val; | |
5703 | ||
5704 | /* inform PCU we want to change CDCLK */ | |
5705 | val = SKL_CDCLK_PREPARE_FOR_CHANGE; | |
5706 | mutex_lock(&dev_priv->rps.hw_lock); | |
5707 | ret = sandybridge_pcode_read(dev_priv, SKL_PCODE_CDCLK_CONTROL, &val); | |
5708 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5709 | ||
5710 | return ret == 0 && (val & SKL_CDCLK_READY_FOR_CHANGE); | |
5711 | } | |
5712 | ||
5713 | static bool skl_cdclk_wait_for_pcu_ready(struct drm_i915_private *dev_priv) | |
5714 | { | |
5715 | unsigned int i; | |
5716 | ||
5717 | for (i = 0; i < 15; i++) { | |
5718 | if (skl_cdclk_pcu_ready(dev_priv)) | |
5719 | return true; | |
5720 | udelay(10); | |
5721 | } | |
5722 | ||
5723 | return false; | |
5724 | } | |
5725 | ||
1cd593e0 | 5726 | static void skl_set_cdclk(struct drm_i915_private *dev_priv, int cdclk, int vco) |
5d96d8af | 5727 | { |
560a7ae4 | 5728 | struct drm_device *dev = dev_priv->dev; |
5d96d8af DL |
5729 | u32 freq_select, pcu_ack; |
5730 | ||
1cd593e0 VS |
5731 | WARN_ON((cdclk == 24000) != (vco == 0)); |
5732 | ||
63911d72 | 5733 | DRM_DEBUG_DRIVER("Changing CDCLK to %d kHz (VCO %d kHz)\n", cdclk, vco); |
5d96d8af DL |
5734 | |
5735 | if (!skl_cdclk_wait_for_pcu_ready(dev_priv)) { | |
5736 | DRM_ERROR("failed to inform PCU about cdclk change\n"); | |
5737 | return; | |
5738 | } | |
5739 | ||
5740 | /* set CDCLK_CTL */ | |
9ef56154 | 5741 | switch (cdclk) { |
5d96d8af DL |
5742 | case 450000: |
5743 | case 432000: | |
5744 | freq_select = CDCLK_FREQ_450_432; | |
5745 | pcu_ack = 1; | |
5746 | break; | |
5747 | case 540000: | |
5748 | freq_select = CDCLK_FREQ_540; | |
5749 | pcu_ack = 2; | |
5750 | break; | |
487ed2e4 | 5751 | case 308571: |
5d96d8af DL |
5752 | case 337500: |
5753 | default: | |
5754 | freq_select = CDCLK_FREQ_337_308; | |
5755 | pcu_ack = 0; | |
5756 | break; | |
487ed2e4 | 5757 | case 617143: |
5d96d8af DL |
5758 | case 675000: |
5759 | freq_select = CDCLK_FREQ_675_617; | |
5760 | pcu_ack = 3; | |
5761 | break; | |
5762 | } | |
5763 | ||
63911d72 VS |
5764 | if (dev_priv->cdclk_pll.vco != 0 && |
5765 | dev_priv->cdclk_pll.vco != vco) | |
1cd593e0 VS |
5766 | skl_dpll0_disable(dev_priv); |
5767 | ||
63911d72 | 5768 | if (dev_priv->cdclk_pll.vco != vco) |
1cd593e0 VS |
5769 | skl_dpll0_enable(dev_priv, vco); |
5770 | ||
9ef56154 | 5771 | I915_WRITE(CDCLK_CTL, freq_select | skl_cdclk_decimal(cdclk)); |
5d96d8af DL |
5772 | POSTING_READ(CDCLK_CTL); |
5773 | ||
5774 | /* inform PCU of the change */ | |
5775 | mutex_lock(&dev_priv->rps.hw_lock); | |
5776 | sandybridge_pcode_write(dev_priv, SKL_PCODE_CDCLK_CONTROL, pcu_ack); | |
5777 | mutex_unlock(&dev_priv->rps.hw_lock); | |
560a7ae4 DL |
5778 | |
5779 | intel_update_cdclk(dev); | |
5d96d8af DL |
5780 | } |
5781 | ||
9f7eb31a VS |
5782 | static void skl_sanitize_cdclk(struct drm_i915_private *dev_priv); |
5783 | ||
5d96d8af DL |
5784 | void skl_uninit_cdclk(struct drm_i915_private *dev_priv) |
5785 | { | |
709e05c3 | 5786 | skl_set_cdclk(dev_priv, dev_priv->cdclk_pll.ref, 0); |
5d96d8af DL |
5787 | } |
5788 | ||
5789 | void skl_init_cdclk(struct drm_i915_private *dev_priv) | |
5790 | { | |
9f7eb31a VS |
5791 | int cdclk, vco; |
5792 | ||
5793 | skl_sanitize_cdclk(dev_priv); | |
5d96d8af | 5794 | |
63911d72 | 5795 | if (dev_priv->cdclk_freq != 0 && dev_priv->cdclk_pll.vco != 0) { |
9f7eb31a VS |
5796 | /* |
5797 | * Use the current vco as our initial | |
5798 | * guess as to what the preferred vco is. | |
5799 | */ | |
5800 | if (dev_priv->skl_preferred_vco_freq == 0) | |
5801 | skl_set_preferred_cdclk_vco(dev_priv, | |
63911d72 | 5802 | dev_priv->cdclk_pll.vco); |
70c2c184 | 5803 | return; |
1cd593e0 | 5804 | } |
5d96d8af | 5805 | |
70c2c184 VS |
5806 | vco = dev_priv->skl_preferred_vco_freq; |
5807 | if (vco == 0) | |
63911d72 | 5808 | vco = 8100000; |
70c2c184 | 5809 | cdclk = skl_calc_cdclk(0, vco); |
5d96d8af | 5810 | |
70c2c184 | 5811 | skl_set_cdclk(dev_priv, cdclk, vco); |
5d96d8af DL |
5812 | } |
5813 | ||
9f7eb31a | 5814 | static void skl_sanitize_cdclk(struct drm_i915_private *dev_priv) |
c73666f3 | 5815 | { |
09492498 | 5816 | uint32_t cdctl, expected; |
c73666f3 | 5817 | |
f1b391a5 SK |
5818 | /* |
5819 | * check if the pre-os intialized the display | |
5820 | * There is SWF18 scratchpad register defined which is set by the | |
5821 | * pre-os which can be used by the OS drivers to check the status | |
5822 | */ | |
5823 | if ((I915_READ(SWF_ILK(0x18)) & 0x00FFFFFF) == 0) | |
5824 | goto sanitize; | |
5825 | ||
1c3f7700 | 5826 | intel_update_cdclk(dev_priv->dev); |
c73666f3 | 5827 | /* Is PLL enabled and locked ? */ |
1c3f7700 ID |
5828 | if (dev_priv->cdclk_pll.vco == 0 || |
5829 | dev_priv->cdclk_freq == dev_priv->cdclk_pll.ref) | |
c73666f3 SK |
5830 | goto sanitize; |
5831 | ||
5832 | /* DPLL okay; verify the cdclock | |
5833 | * | |
5834 | * Noticed in some instances that the freq selection is correct but | |
5835 | * decimal part is programmed wrong from BIOS where pre-os does not | |
5836 | * enable display. Verify the same as well. | |
5837 | */ | |
09492498 VS |
5838 | cdctl = I915_READ(CDCLK_CTL); |
5839 | expected = (cdctl & CDCLK_FREQ_SEL_MASK) | | |
5840 | skl_cdclk_decimal(dev_priv->cdclk_freq); | |
5841 | if (cdctl == expected) | |
c73666f3 | 5842 | /* All well; nothing to sanitize */ |
9f7eb31a | 5843 | return; |
c89e39f3 | 5844 | |
9f7eb31a VS |
5845 | sanitize: |
5846 | DRM_DEBUG_KMS("Sanitizing cdclk programmed by pre-os\n"); | |
c73666f3 | 5847 | |
9f7eb31a VS |
5848 | /* force cdclk programming */ |
5849 | dev_priv->cdclk_freq = 0; | |
5850 | /* force full PLL disable + enable */ | |
63911d72 | 5851 | dev_priv->cdclk_pll.vco = -1; |
c73666f3 SK |
5852 | } |
5853 | ||
30a970c6 JB |
5854 | /* Adjust CDclk dividers to allow high res or save power if possible */ |
5855 | static void valleyview_set_cdclk(struct drm_device *dev, int cdclk) | |
5856 | { | |
5857 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5858 | u32 val, cmd; | |
5859 | ||
164dfd28 VK |
5860 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
5861 | != dev_priv->cdclk_freq); | |
d60c4473 | 5862 | |
dfcab17e | 5863 | if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */ |
30a970c6 | 5864 | cmd = 2; |
dfcab17e | 5865 | else if (cdclk == 266667) |
30a970c6 JB |
5866 | cmd = 1; |
5867 | else | |
5868 | cmd = 0; | |
5869 | ||
5870 | mutex_lock(&dev_priv->rps.hw_lock); | |
5871 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); | |
5872 | val &= ~DSPFREQGUAR_MASK; | |
5873 | val |= (cmd << DSPFREQGUAR_SHIFT); | |
5874 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); | |
5875 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & | |
5876 | DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT), | |
5877 | 50)) { | |
5878 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
5879 | } | |
5880 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5881 | ||
54433e91 VS |
5882 | mutex_lock(&dev_priv->sb_lock); |
5883 | ||
dfcab17e | 5884 | if (cdclk == 400000) { |
6bcda4f0 | 5885 | u32 divider; |
30a970c6 | 5886 | |
6bcda4f0 | 5887 | divider = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
30a970c6 | 5888 | |
30a970c6 JB |
5889 | /* adjust cdclk divider */ |
5890 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); | |
87d5d259 | 5891 | val &= ~CCK_FREQUENCY_VALUES; |
30a970c6 JB |
5892 | val |= divider; |
5893 | vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val); | |
a877e801 VS |
5894 | |
5895 | if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) & | |
87d5d259 | 5896 | CCK_FREQUENCY_STATUS) == (divider << CCK_FREQUENCY_STATUS_SHIFT), |
a877e801 VS |
5897 | 50)) |
5898 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
30a970c6 JB |
5899 | } |
5900 | ||
30a970c6 JB |
5901 | /* adjust self-refresh exit latency value */ |
5902 | val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC); | |
5903 | val &= ~0x7f; | |
5904 | ||
5905 | /* | |
5906 | * For high bandwidth configs, we set a higher latency in the bunit | |
5907 | * so that the core display fetch happens in time to avoid underruns. | |
5908 | */ | |
dfcab17e | 5909 | if (cdclk == 400000) |
30a970c6 JB |
5910 | val |= 4500 / 250; /* 4.5 usec */ |
5911 | else | |
5912 | val |= 3000 / 250; /* 3.0 usec */ | |
5913 | vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val); | |
54433e91 | 5914 | |
a580516d | 5915 | mutex_unlock(&dev_priv->sb_lock); |
30a970c6 | 5916 | |
b6283055 | 5917 | intel_update_cdclk(dev); |
30a970c6 JB |
5918 | } |
5919 | ||
383c5a6a VS |
5920 | static void cherryview_set_cdclk(struct drm_device *dev, int cdclk) |
5921 | { | |
5922 | struct drm_i915_private *dev_priv = dev->dev_private; | |
5923 | u32 val, cmd; | |
5924 | ||
164dfd28 VK |
5925 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
5926 | != dev_priv->cdclk_freq); | |
383c5a6a VS |
5927 | |
5928 | switch (cdclk) { | |
383c5a6a VS |
5929 | case 333333: |
5930 | case 320000: | |
383c5a6a | 5931 | case 266667: |
383c5a6a | 5932 | case 200000: |
383c5a6a VS |
5933 | break; |
5934 | default: | |
5f77eeb0 | 5935 | MISSING_CASE(cdclk); |
383c5a6a VS |
5936 | return; |
5937 | } | |
5938 | ||
9d0d3fda VS |
5939 | /* |
5940 | * Specs are full of misinformation, but testing on actual | |
5941 | * hardware has shown that we just need to write the desired | |
5942 | * CCK divider into the Punit register. | |
5943 | */ | |
5944 | cmd = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; | |
5945 | ||
383c5a6a VS |
5946 | mutex_lock(&dev_priv->rps.hw_lock); |
5947 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); | |
5948 | val &= ~DSPFREQGUAR_MASK_CHV; | |
5949 | val |= (cmd << DSPFREQGUAR_SHIFT_CHV); | |
5950 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); | |
5951 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & | |
5952 | DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV), | |
5953 | 50)) { | |
5954 | DRM_ERROR("timed out waiting for CDclk change\n"); | |
5955 | } | |
5956 | mutex_unlock(&dev_priv->rps.hw_lock); | |
5957 | ||
b6283055 | 5958 | intel_update_cdclk(dev); |
383c5a6a VS |
5959 | } |
5960 | ||
30a970c6 JB |
5961 | static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv, |
5962 | int max_pixclk) | |
5963 | { | |
6bcda4f0 | 5964 | int freq_320 = (dev_priv->hpll_freq << 1) % 320000 != 0 ? 333333 : 320000; |
6cca3195 | 5965 | int limit = IS_CHERRYVIEW(dev_priv) ? 95 : 90; |
29dc7ef3 | 5966 | |
30a970c6 JB |
5967 | /* |
5968 | * Really only a few cases to deal with, as only 4 CDclks are supported: | |
5969 | * 200MHz | |
5970 | * 267MHz | |
29dc7ef3 | 5971 | * 320/333MHz (depends on HPLL freq) |
6cca3195 VS |
5972 | * 400MHz (VLV only) |
5973 | * So we check to see whether we're above 90% (VLV) or 95% (CHV) | |
5974 | * of the lower bin and adjust if needed. | |
e37c67a1 VS |
5975 | * |
5976 | * We seem to get an unstable or solid color picture at 200MHz. | |
5977 | * Not sure what's wrong. For now use 200MHz only when all pipes | |
5978 | * are off. | |
30a970c6 | 5979 | */ |
6cca3195 VS |
5980 | if (!IS_CHERRYVIEW(dev_priv) && |
5981 | max_pixclk > freq_320*limit/100) | |
dfcab17e | 5982 | return 400000; |
6cca3195 | 5983 | else if (max_pixclk > 266667*limit/100) |
29dc7ef3 | 5984 | return freq_320; |
e37c67a1 | 5985 | else if (max_pixclk > 0) |
dfcab17e | 5986 | return 266667; |
e37c67a1 VS |
5987 | else |
5988 | return 200000; | |
30a970c6 JB |
5989 | } |
5990 | ||
324513c0 | 5991 | static int bxt_calc_cdclk(int max_pixclk) |
f8437dd1 | 5992 | { |
760e1477 | 5993 | if (max_pixclk > 576000) |
f8437dd1 | 5994 | return 624000; |
760e1477 | 5995 | else if (max_pixclk > 384000) |
f8437dd1 | 5996 | return 576000; |
760e1477 | 5997 | else if (max_pixclk > 288000) |
f8437dd1 | 5998 | return 384000; |
760e1477 | 5999 | else if (max_pixclk > 144000) |
f8437dd1 VK |
6000 | return 288000; |
6001 | else | |
6002 | return 144000; | |
6003 | } | |
6004 | ||
e8788cbc | 6005 | /* Compute the max pixel clock for new configuration. */ |
a821fc46 ACO |
6006 | static int intel_mode_max_pixclk(struct drm_device *dev, |
6007 | struct drm_atomic_state *state) | |
30a970c6 | 6008 | { |
565602d7 ML |
6009 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
6010 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6011 | struct drm_crtc *crtc; | |
6012 | struct drm_crtc_state *crtc_state; | |
6013 | unsigned max_pixclk = 0, i; | |
6014 | enum pipe pipe; | |
30a970c6 | 6015 | |
565602d7 ML |
6016 | memcpy(intel_state->min_pixclk, dev_priv->min_pixclk, |
6017 | sizeof(intel_state->min_pixclk)); | |
304603f4 | 6018 | |
565602d7 ML |
6019 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
6020 | int pixclk = 0; | |
6021 | ||
6022 | if (crtc_state->enable) | |
6023 | pixclk = crtc_state->adjusted_mode.crtc_clock; | |
304603f4 | 6024 | |
565602d7 | 6025 | intel_state->min_pixclk[i] = pixclk; |
30a970c6 JB |
6026 | } |
6027 | ||
565602d7 ML |
6028 | for_each_pipe(dev_priv, pipe) |
6029 | max_pixclk = max(intel_state->min_pixclk[pipe], max_pixclk); | |
6030 | ||
30a970c6 JB |
6031 | return max_pixclk; |
6032 | } | |
6033 | ||
27c329ed | 6034 | static int valleyview_modeset_calc_cdclk(struct drm_atomic_state *state) |
30a970c6 | 6035 | { |
27c329ed ML |
6036 | struct drm_device *dev = state->dev; |
6037 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6038 | int max_pixclk = intel_mode_max_pixclk(dev, state); | |
1a617b77 ML |
6039 | struct intel_atomic_state *intel_state = |
6040 | to_intel_atomic_state(state); | |
30a970c6 | 6041 | |
1a617b77 | 6042 | intel_state->cdclk = intel_state->dev_cdclk = |
27c329ed | 6043 | valleyview_calc_cdclk(dev_priv, max_pixclk); |
0a9ab303 | 6044 | |
1a617b77 ML |
6045 | if (!intel_state->active_crtcs) |
6046 | intel_state->dev_cdclk = valleyview_calc_cdclk(dev_priv, 0); | |
6047 | ||
27c329ed ML |
6048 | return 0; |
6049 | } | |
304603f4 | 6050 | |
324513c0 | 6051 | static int bxt_modeset_calc_cdclk(struct drm_atomic_state *state) |
27c329ed | 6052 | { |
4e5ca60f | 6053 | int max_pixclk = ilk_max_pixel_rate(state); |
1a617b77 ML |
6054 | struct intel_atomic_state *intel_state = |
6055 | to_intel_atomic_state(state); | |
85a96e7a | 6056 | |
1a617b77 | 6057 | intel_state->cdclk = intel_state->dev_cdclk = |
324513c0 | 6058 | bxt_calc_cdclk(max_pixclk); |
85a96e7a | 6059 | |
1a617b77 | 6060 | if (!intel_state->active_crtcs) |
324513c0 | 6061 | intel_state->dev_cdclk = bxt_calc_cdclk(0); |
1a617b77 | 6062 | |
27c329ed | 6063 | return 0; |
30a970c6 JB |
6064 | } |
6065 | ||
1e69cd74 VS |
6066 | static void vlv_program_pfi_credits(struct drm_i915_private *dev_priv) |
6067 | { | |
6068 | unsigned int credits, default_credits; | |
6069 | ||
6070 | if (IS_CHERRYVIEW(dev_priv)) | |
6071 | default_credits = PFI_CREDIT(12); | |
6072 | else | |
6073 | default_credits = PFI_CREDIT(8); | |
6074 | ||
bfa7df01 | 6075 | if (dev_priv->cdclk_freq >= dev_priv->czclk_freq) { |
1e69cd74 VS |
6076 | /* CHV suggested value is 31 or 63 */ |
6077 | if (IS_CHERRYVIEW(dev_priv)) | |
fcc0008f | 6078 | credits = PFI_CREDIT_63; |
1e69cd74 VS |
6079 | else |
6080 | credits = PFI_CREDIT(15); | |
6081 | } else { | |
6082 | credits = default_credits; | |
6083 | } | |
6084 | ||
6085 | /* | |
6086 | * WA - write default credits before re-programming | |
6087 | * FIXME: should we also set the resend bit here? | |
6088 | */ | |
6089 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | | |
6090 | default_credits); | |
6091 | ||
6092 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | | |
6093 | credits | PFI_CREDIT_RESEND); | |
6094 | ||
6095 | /* | |
6096 | * FIXME is this guaranteed to clear | |
6097 | * immediately or should we poll for it? | |
6098 | */ | |
6099 | WARN_ON(I915_READ(GCI_CONTROL) & PFI_CREDIT_RESEND); | |
6100 | } | |
6101 | ||
27c329ed | 6102 | static void valleyview_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
30a970c6 | 6103 | { |
a821fc46 | 6104 | struct drm_device *dev = old_state->dev; |
30a970c6 | 6105 | struct drm_i915_private *dev_priv = dev->dev_private; |
1a617b77 ML |
6106 | struct intel_atomic_state *old_intel_state = |
6107 | to_intel_atomic_state(old_state); | |
6108 | unsigned req_cdclk = old_intel_state->dev_cdclk; | |
30a970c6 | 6109 | |
27c329ed ML |
6110 | /* |
6111 | * FIXME: We can end up here with all power domains off, yet | |
6112 | * with a CDCLK frequency other than the minimum. To account | |
6113 | * for this take the PIPE-A power domain, which covers the HW | |
6114 | * blocks needed for the following programming. This can be | |
6115 | * removed once it's guaranteed that we get here either with | |
6116 | * the minimum CDCLK set, or the required power domains | |
6117 | * enabled. | |
6118 | */ | |
6119 | intel_display_power_get(dev_priv, POWER_DOMAIN_PIPE_A); | |
738c05c0 | 6120 | |
27c329ed ML |
6121 | if (IS_CHERRYVIEW(dev)) |
6122 | cherryview_set_cdclk(dev, req_cdclk); | |
6123 | else | |
6124 | valleyview_set_cdclk(dev, req_cdclk); | |
738c05c0 | 6125 | |
27c329ed | 6126 | vlv_program_pfi_credits(dev_priv); |
1e69cd74 | 6127 | |
27c329ed | 6128 | intel_display_power_put(dev_priv, POWER_DOMAIN_PIPE_A); |
30a970c6 JB |
6129 | } |
6130 | ||
89b667f8 JB |
6131 | static void valleyview_crtc_enable(struct drm_crtc *crtc) |
6132 | { | |
6133 | struct drm_device *dev = crtc->dev; | |
a72e4c9f | 6134 | struct drm_i915_private *dev_priv = to_i915(dev); |
89b667f8 JB |
6135 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
6136 | struct intel_encoder *encoder; | |
b95c5321 ML |
6137 | struct intel_crtc_state *pipe_config = |
6138 | to_intel_crtc_state(crtc->state); | |
89b667f8 | 6139 | int pipe = intel_crtc->pipe; |
89b667f8 | 6140 | |
53d9f4e9 | 6141 | if (WARN_ON(intel_crtc->active)) |
89b667f8 JB |
6142 | return; |
6143 | ||
6e3c9717 | 6144 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 6145 | intel_dp_set_m_n(intel_crtc, M1_N1); |
5b18e57c DV |
6146 | |
6147 | intel_set_pipe_timings(intel_crtc); | |
bc58be60 | 6148 | intel_set_pipe_src_size(intel_crtc); |
5b18e57c | 6149 | |
c14b0485 VS |
6150 | if (IS_CHERRYVIEW(dev) && pipe == PIPE_B) { |
6151 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6152 | ||
6153 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); | |
6154 | I915_WRITE(CHV_CANVAS(pipe), 0); | |
6155 | } | |
6156 | ||
5b18e57c DV |
6157 | i9xx_set_pipeconf(intel_crtc); |
6158 | ||
89b667f8 | 6159 | intel_crtc->active = true; |
89b667f8 | 6160 | |
a72e4c9f | 6161 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4a3436e8 | 6162 | |
89b667f8 JB |
6163 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6164 | if (encoder->pre_pll_enable) | |
6165 | encoder->pre_pll_enable(encoder); | |
6166 | ||
cd2d34d9 VS |
6167 | if (IS_CHERRYVIEW(dev)) { |
6168 | chv_prepare_pll(intel_crtc, intel_crtc->config); | |
6169 | chv_enable_pll(intel_crtc, intel_crtc->config); | |
6170 | } else { | |
6171 | vlv_prepare_pll(intel_crtc, intel_crtc->config); | |
6172 | vlv_enable_pll(intel_crtc, intel_crtc->config); | |
9d556c99 | 6173 | } |
89b667f8 JB |
6174 | |
6175 | for_each_encoder_on_crtc(dev, crtc, encoder) | |
6176 | if (encoder->pre_enable) | |
6177 | encoder->pre_enable(encoder); | |
6178 | ||
2dd24552 JB |
6179 | i9xx_pfit_enable(intel_crtc); |
6180 | ||
b95c5321 | 6181 | intel_color_load_luts(&pipe_config->base); |
63cbb074 | 6182 | |
caed361d | 6183 | intel_update_watermarks(crtc); |
e1fdc473 | 6184 | intel_enable_pipe(intel_crtc); |
be6a6f8e | 6185 | |
4b3a9526 VS |
6186 | assert_vblank_disabled(crtc); |
6187 | drm_crtc_vblank_on(crtc); | |
6188 | ||
f9b61ff6 DV |
6189 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6190 | encoder->enable(encoder); | |
89b667f8 JB |
6191 | } |
6192 | ||
f13c2ef3 DV |
6193 | static void i9xx_set_pll_dividers(struct intel_crtc *crtc) |
6194 | { | |
6195 | struct drm_device *dev = crtc->base.dev; | |
6196 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6197 | ||
6e3c9717 ACO |
6198 | I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0); |
6199 | I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1); | |
f13c2ef3 DV |
6200 | } |
6201 | ||
0b8765c6 | 6202 | static void i9xx_crtc_enable(struct drm_crtc *crtc) |
79e53945 JB |
6203 | { |
6204 | struct drm_device *dev = crtc->dev; | |
a72e4c9f | 6205 | struct drm_i915_private *dev_priv = to_i915(dev); |
79e53945 | 6206 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
ef9c3aee | 6207 | struct intel_encoder *encoder; |
b95c5321 ML |
6208 | struct intel_crtc_state *pipe_config = |
6209 | to_intel_crtc_state(crtc->state); | |
cd2d34d9 | 6210 | enum pipe pipe = intel_crtc->pipe; |
79e53945 | 6211 | |
53d9f4e9 | 6212 | if (WARN_ON(intel_crtc->active)) |
f7abfe8b CW |
6213 | return; |
6214 | ||
f13c2ef3 DV |
6215 | i9xx_set_pll_dividers(intel_crtc); |
6216 | ||
6e3c9717 | 6217 | if (intel_crtc->config->has_dp_encoder) |
fe3cd48d | 6218 | intel_dp_set_m_n(intel_crtc, M1_N1); |
5b18e57c DV |
6219 | |
6220 | intel_set_pipe_timings(intel_crtc); | |
bc58be60 | 6221 | intel_set_pipe_src_size(intel_crtc); |
5b18e57c | 6222 | |
5b18e57c DV |
6223 | i9xx_set_pipeconf(intel_crtc); |
6224 | ||
f7abfe8b | 6225 | intel_crtc->active = true; |
6b383a7f | 6226 | |
4a3436e8 | 6227 | if (!IS_GEN2(dev)) |
a72e4c9f | 6228 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4a3436e8 | 6229 | |
9d6d9f19 MK |
6230 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6231 | if (encoder->pre_enable) | |
6232 | encoder->pre_enable(encoder); | |
6233 | ||
f6736a1a DV |
6234 | i9xx_enable_pll(intel_crtc); |
6235 | ||
2dd24552 JB |
6236 | i9xx_pfit_enable(intel_crtc); |
6237 | ||
b95c5321 | 6238 | intel_color_load_luts(&pipe_config->base); |
63cbb074 | 6239 | |
f37fcc2a | 6240 | intel_update_watermarks(crtc); |
e1fdc473 | 6241 | intel_enable_pipe(intel_crtc); |
be6a6f8e | 6242 | |
4b3a9526 VS |
6243 | assert_vblank_disabled(crtc); |
6244 | drm_crtc_vblank_on(crtc); | |
6245 | ||
f9b61ff6 DV |
6246 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6247 | encoder->enable(encoder); | |
0b8765c6 | 6248 | } |
79e53945 | 6249 | |
87476d63 DV |
6250 | static void i9xx_pfit_disable(struct intel_crtc *crtc) |
6251 | { | |
6252 | struct drm_device *dev = crtc->base.dev; | |
6253 | struct drm_i915_private *dev_priv = dev->dev_private; | |
87476d63 | 6254 | |
6e3c9717 | 6255 | if (!crtc->config->gmch_pfit.control) |
328d8e82 | 6256 | return; |
87476d63 | 6257 | |
328d8e82 | 6258 | assert_pipe_disabled(dev_priv, crtc->pipe); |
87476d63 | 6259 | |
328d8e82 DV |
6260 | DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", |
6261 | I915_READ(PFIT_CONTROL)); | |
6262 | I915_WRITE(PFIT_CONTROL, 0); | |
87476d63 DV |
6263 | } |
6264 | ||
0b8765c6 JB |
6265 | static void i9xx_crtc_disable(struct drm_crtc *crtc) |
6266 | { | |
6267 | struct drm_device *dev = crtc->dev; | |
6268 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6269 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ef9c3aee | 6270 | struct intel_encoder *encoder; |
0b8765c6 | 6271 | int pipe = intel_crtc->pipe; |
ef9c3aee | 6272 | |
6304cd91 VS |
6273 | /* |
6274 | * On gen2 planes are double buffered but the pipe isn't, so we must | |
6275 | * wait for planes to fully turn off before disabling the pipe. | |
6276 | */ | |
90e83e53 ACO |
6277 | if (IS_GEN2(dev)) |
6278 | intel_wait_for_vblank(dev, pipe); | |
6304cd91 | 6279 | |
4b3a9526 VS |
6280 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6281 | encoder->disable(encoder); | |
6282 | ||
f9b61ff6 DV |
6283 | drm_crtc_vblank_off(crtc); |
6284 | assert_vblank_disabled(crtc); | |
6285 | ||
575f7ab7 | 6286 | intel_disable_pipe(intel_crtc); |
24a1f16d | 6287 | |
87476d63 | 6288 | i9xx_pfit_disable(intel_crtc); |
24a1f16d | 6289 | |
89b667f8 JB |
6290 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6291 | if (encoder->post_disable) | |
6292 | encoder->post_disable(encoder); | |
6293 | ||
a65347ba | 6294 | if (!intel_crtc->config->has_dsi_encoder) { |
076ed3b2 CML |
6295 | if (IS_CHERRYVIEW(dev)) |
6296 | chv_disable_pll(dev_priv, pipe); | |
6297 | else if (IS_VALLEYVIEW(dev)) | |
6298 | vlv_disable_pll(dev_priv, pipe); | |
6299 | else | |
1c4e0274 | 6300 | i9xx_disable_pll(intel_crtc); |
076ed3b2 | 6301 | } |
0b8765c6 | 6302 | |
d6db995f VS |
6303 | for_each_encoder_on_crtc(dev, crtc, encoder) |
6304 | if (encoder->post_pll_disable) | |
6305 | encoder->post_pll_disable(encoder); | |
6306 | ||
4a3436e8 | 6307 | if (!IS_GEN2(dev)) |
a72e4c9f | 6308 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
0b8765c6 JB |
6309 | } |
6310 | ||
b17d48e2 ML |
6311 | static void intel_crtc_disable_noatomic(struct drm_crtc *crtc) |
6312 | { | |
842e0307 | 6313 | struct intel_encoder *encoder; |
b17d48e2 ML |
6314 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
6315 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); | |
6316 | enum intel_display_power_domain domain; | |
6317 | unsigned long domains; | |
6318 | ||
6319 | if (!intel_crtc->active) | |
6320 | return; | |
6321 | ||
a539205a | 6322 | if (to_intel_plane_state(crtc->primary->state)->visible) { |
5a21b665 | 6323 | WARN_ON(intel_crtc->flip_work); |
fc32b1fd | 6324 | |
2622a081 | 6325 | intel_pre_disable_primary_noatomic(crtc); |
54a41961 ML |
6326 | |
6327 | intel_crtc_disable_planes(crtc, 1 << drm_plane_index(crtc->primary)); | |
6328 | to_intel_plane_state(crtc->primary->state)->visible = false; | |
a539205a ML |
6329 | } |
6330 | ||
b17d48e2 | 6331 | dev_priv->display.crtc_disable(crtc); |
842e0307 | 6332 | |
78108b7c VS |
6333 | DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n", |
6334 | crtc->base.id, crtc->name); | |
842e0307 ML |
6335 | |
6336 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0); | |
6337 | crtc->state->active = false; | |
37d9078b | 6338 | intel_crtc->active = false; |
842e0307 ML |
6339 | crtc->enabled = false; |
6340 | crtc->state->connector_mask = 0; | |
6341 | crtc->state->encoder_mask = 0; | |
6342 | ||
6343 | for_each_encoder_on_crtc(crtc->dev, crtc, encoder) | |
6344 | encoder->base.crtc = NULL; | |
6345 | ||
58f9c0bc | 6346 | intel_fbc_disable(intel_crtc); |
37d9078b | 6347 | intel_update_watermarks(crtc); |
1f7457b1 | 6348 | intel_disable_shared_dpll(intel_crtc); |
b17d48e2 ML |
6349 | |
6350 | domains = intel_crtc->enabled_power_domains; | |
6351 | for_each_power_domain(domain, domains) | |
6352 | intel_display_power_put(dev_priv, domain); | |
6353 | intel_crtc->enabled_power_domains = 0; | |
565602d7 ML |
6354 | |
6355 | dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe); | |
6356 | dev_priv->min_pixclk[intel_crtc->pipe] = 0; | |
b17d48e2 ML |
6357 | } |
6358 | ||
6b72d486 ML |
6359 | /* |
6360 | * turn all crtc's off, but do not adjust state | |
6361 | * This has to be paired with a call to intel_modeset_setup_hw_state. | |
6362 | */ | |
70e0bd74 | 6363 | int intel_display_suspend(struct drm_device *dev) |
ee7b9f93 | 6364 | { |
e2c8b870 | 6365 | struct drm_i915_private *dev_priv = to_i915(dev); |
70e0bd74 | 6366 | struct drm_atomic_state *state; |
e2c8b870 | 6367 | int ret; |
70e0bd74 | 6368 | |
e2c8b870 ML |
6369 | state = drm_atomic_helper_suspend(dev); |
6370 | ret = PTR_ERR_OR_ZERO(state); | |
70e0bd74 ML |
6371 | if (ret) |
6372 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); | |
e2c8b870 ML |
6373 | else |
6374 | dev_priv->modeset_restore_state = state; | |
70e0bd74 | 6375 | return ret; |
ee7b9f93 JB |
6376 | } |
6377 | ||
ea5b213a | 6378 | void intel_encoder_destroy(struct drm_encoder *encoder) |
7e7d76c3 | 6379 | { |
4ef69c7a | 6380 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
ea5b213a | 6381 | |
ea5b213a CW |
6382 | drm_encoder_cleanup(encoder); |
6383 | kfree(intel_encoder); | |
7e7d76c3 JB |
6384 | } |
6385 | ||
0a91ca29 DV |
6386 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
6387 | * internal consistency). */ | |
5a21b665 | 6388 | static void intel_connector_verify_state(struct intel_connector *connector) |
79e53945 | 6389 | { |
5a21b665 | 6390 | struct drm_crtc *crtc = connector->base.state->crtc; |
35dd3c64 ML |
6391 | |
6392 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", | |
6393 | connector->base.base.id, | |
6394 | connector->base.name); | |
6395 | ||
0a91ca29 | 6396 | if (connector->get_hw_state(connector)) { |
e85376cb | 6397 | struct intel_encoder *encoder = connector->encoder; |
5a21b665 | 6398 | struct drm_connector_state *conn_state = connector->base.state; |
0a91ca29 | 6399 | |
35dd3c64 ML |
6400 | I915_STATE_WARN(!crtc, |
6401 | "connector enabled without attached crtc\n"); | |
0a91ca29 | 6402 | |
35dd3c64 ML |
6403 | if (!crtc) |
6404 | return; | |
6405 | ||
6406 | I915_STATE_WARN(!crtc->state->active, | |
6407 | "connector is active, but attached crtc isn't\n"); | |
6408 | ||
e85376cb | 6409 | if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST) |
35dd3c64 ML |
6410 | return; |
6411 | ||
e85376cb | 6412 | I915_STATE_WARN(conn_state->best_encoder != &encoder->base, |
35dd3c64 ML |
6413 | "atomic encoder doesn't match attached encoder\n"); |
6414 | ||
e85376cb | 6415 | I915_STATE_WARN(conn_state->crtc != encoder->base.crtc, |
35dd3c64 ML |
6416 | "attached encoder crtc differs from connector crtc\n"); |
6417 | } else { | |
4d688a2a ML |
6418 | I915_STATE_WARN(crtc && crtc->state->active, |
6419 | "attached crtc is active, but connector isn't\n"); | |
5a21b665 | 6420 | I915_STATE_WARN(!crtc && connector->base.state->best_encoder, |
35dd3c64 | 6421 | "best encoder set without crtc!\n"); |
0a91ca29 | 6422 | } |
79e53945 JB |
6423 | } |
6424 | ||
08d9bc92 ACO |
6425 | int intel_connector_init(struct intel_connector *connector) |
6426 | { | |
5350a031 | 6427 | drm_atomic_helper_connector_reset(&connector->base); |
08d9bc92 | 6428 | |
5350a031 | 6429 | if (!connector->base.state) |
08d9bc92 ACO |
6430 | return -ENOMEM; |
6431 | ||
08d9bc92 ACO |
6432 | return 0; |
6433 | } | |
6434 | ||
6435 | struct intel_connector *intel_connector_alloc(void) | |
6436 | { | |
6437 | struct intel_connector *connector; | |
6438 | ||
6439 | connector = kzalloc(sizeof *connector, GFP_KERNEL); | |
6440 | if (!connector) | |
6441 | return NULL; | |
6442 | ||
6443 | if (intel_connector_init(connector) < 0) { | |
6444 | kfree(connector); | |
6445 | return NULL; | |
6446 | } | |
6447 | ||
6448 | return connector; | |
6449 | } | |
6450 | ||
f0947c37 DV |
6451 | /* Simple connector->get_hw_state implementation for encoders that support only |
6452 | * one connector and no cloning and hence the encoder state determines the state | |
6453 | * of the connector. */ | |
6454 | bool intel_connector_get_hw_state(struct intel_connector *connector) | |
ea5b213a | 6455 | { |
24929352 | 6456 | enum pipe pipe = 0; |
f0947c37 | 6457 | struct intel_encoder *encoder = connector->encoder; |
ea5b213a | 6458 | |
f0947c37 | 6459 | return encoder->get_hw_state(encoder, &pipe); |
ea5b213a CW |
6460 | } |
6461 | ||
6d293983 | 6462 | static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state) |
d272ddfa | 6463 | { |
6d293983 ACO |
6464 | if (crtc_state->base.enable && crtc_state->has_pch_encoder) |
6465 | return crtc_state->fdi_lanes; | |
d272ddfa VS |
6466 | |
6467 | return 0; | |
6468 | } | |
6469 | ||
6d293983 | 6470 | static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe, |
5cec258b | 6471 | struct intel_crtc_state *pipe_config) |
1857e1da | 6472 | { |
6d293983 ACO |
6473 | struct drm_atomic_state *state = pipe_config->base.state; |
6474 | struct intel_crtc *other_crtc; | |
6475 | struct intel_crtc_state *other_crtc_state; | |
6476 | ||
1857e1da DV |
6477 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
6478 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6479 | if (pipe_config->fdi_lanes > 4) { | |
6480 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", | |
6481 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6482 | return -EINVAL; |
1857e1da DV |
6483 | } |
6484 | ||
bafb6553 | 6485 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
1857e1da DV |
6486 | if (pipe_config->fdi_lanes > 2) { |
6487 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", | |
6488 | pipe_config->fdi_lanes); | |
6d293983 | 6489 | return -EINVAL; |
1857e1da | 6490 | } else { |
6d293983 | 6491 | return 0; |
1857e1da DV |
6492 | } |
6493 | } | |
6494 | ||
6495 | if (INTEL_INFO(dev)->num_pipes == 2) | |
6d293983 | 6496 | return 0; |
1857e1da DV |
6497 | |
6498 | /* Ivybridge 3 pipe is really complicated */ | |
6499 | switch (pipe) { | |
6500 | case PIPE_A: | |
6d293983 | 6501 | return 0; |
1857e1da | 6502 | case PIPE_B: |
6d293983 ACO |
6503 | if (pipe_config->fdi_lanes <= 2) |
6504 | return 0; | |
6505 | ||
6506 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_C)); | |
6507 | other_crtc_state = | |
6508 | intel_atomic_get_crtc_state(state, other_crtc); | |
6509 | if (IS_ERR(other_crtc_state)) | |
6510 | return PTR_ERR(other_crtc_state); | |
6511 | ||
6512 | if (pipe_required_fdi_lanes(other_crtc_state) > 0) { | |
1857e1da DV |
6513 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
6514 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6515 | return -EINVAL; |
1857e1da | 6516 | } |
6d293983 | 6517 | return 0; |
1857e1da | 6518 | case PIPE_C: |
251cc67c VS |
6519 | if (pipe_config->fdi_lanes > 2) { |
6520 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", | |
6521 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6522 | return -EINVAL; |
251cc67c | 6523 | } |
6d293983 ACO |
6524 | |
6525 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_B)); | |
6526 | other_crtc_state = | |
6527 | intel_atomic_get_crtc_state(state, other_crtc); | |
6528 | if (IS_ERR(other_crtc_state)) | |
6529 | return PTR_ERR(other_crtc_state); | |
6530 | ||
6531 | if (pipe_required_fdi_lanes(other_crtc_state) > 2) { | |
1857e1da | 6532 | DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n"); |
6d293983 | 6533 | return -EINVAL; |
1857e1da | 6534 | } |
6d293983 | 6535 | return 0; |
1857e1da DV |
6536 | default: |
6537 | BUG(); | |
6538 | } | |
6539 | } | |
6540 | ||
e29c22c0 DV |
6541 | #define RETRY 1 |
6542 | static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc, | |
5cec258b | 6543 | struct intel_crtc_state *pipe_config) |
877d48d5 | 6544 | { |
1857e1da | 6545 | struct drm_device *dev = intel_crtc->base.dev; |
7c5f93b0 | 6546 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
6d293983 ACO |
6547 | int lane, link_bw, fdi_dotclock, ret; |
6548 | bool needs_recompute = false; | |
877d48d5 | 6549 | |
e29c22c0 | 6550 | retry: |
877d48d5 DV |
6551 | /* FDI is a binary signal running at ~2.7GHz, encoding |
6552 | * each output octet as 10 bits. The actual frequency | |
6553 | * is stored as a divider into a 100MHz clock, and the | |
6554 | * mode pixel clock is stored in units of 1KHz. | |
6555 | * Hence the bw of each lane in terms of the mode signal | |
6556 | * is: | |
6557 | */ | |
21a727b3 | 6558 | link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config); |
877d48d5 | 6559 | |
241bfc38 | 6560 | fdi_dotclock = adjusted_mode->crtc_clock; |
877d48d5 | 6561 | |
2bd89a07 | 6562 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
877d48d5 DV |
6563 | pipe_config->pipe_bpp); |
6564 | ||
6565 | pipe_config->fdi_lanes = lane; | |
6566 | ||
2bd89a07 | 6567 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
877d48d5 | 6568 | link_bw, &pipe_config->fdi_m_n); |
1857e1da | 6569 | |
e3b247da | 6570 | ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config); |
6d293983 | 6571 | if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) { |
e29c22c0 DV |
6572 | pipe_config->pipe_bpp -= 2*3; |
6573 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", | |
6574 | pipe_config->pipe_bpp); | |
6575 | needs_recompute = true; | |
6576 | pipe_config->bw_constrained = true; | |
6577 | ||
6578 | goto retry; | |
6579 | } | |
6580 | ||
6581 | if (needs_recompute) | |
6582 | return RETRY; | |
6583 | ||
6d293983 | 6584 | return ret; |
877d48d5 DV |
6585 | } |
6586 | ||
8cfb3407 VS |
6587 | static bool pipe_config_supports_ips(struct drm_i915_private *dev_priv, |
6588 | struct intel_crtc_state *pipe_config) | |
6589 | { | |
6590 | if (pipe_config->pipe_bpp > 24) | |
6591 | return false; | |
6592 | ||
6593 | /* HSW can handle pixel rate up to cdclk? */ | |
2d1fe073 | 6594 | if (IS_HASWELL(dev_priv)) |
8cfb3407 VS |
6595 | return true; |
6596 | ||
6597 | /* | |
b432e5cf VS |
6598 | * We compare against max which means we must take |
6599 | * the increased cdclk requirement into account when | |
6600 | * calculating the new cdclk. | |
6601 | * | |
6602 | * Should measure whether using a lower cdclk w/o IPS | |
8cfb3407 VS |
6603 | */ |
6604 | return ilk_pipe_pixel_rate(pipe_config) <= | |
6605 | dev_priv->max_cdclk_freq * 95 / 100; | |
6606 | } | |
6607 | ||
42db64ef | 6608 | static void hsw_compute_ips_config(struct intel_crtc *crtc, |
5cec258b | 6609 | struct intel_crtc_state *pipe_config) |
42db64ef | 6610 | { |
8cfb3407 VS |
6611 | struct drm_device *dev = crtc->base.dev; |
6612 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6613 | ||
d330a953 | 6614 | pipe_config->ips_enabled = i915.enable_ips && |
8cfb3407 VS |
6615 | hsw_crtc_supports_ips(crtc) && |
6616 | pipe_config_supports_ips(dev_priv, pipe_config); | |
42db64ef PZ |
6617 | } |
6618 | ||
39acb4aa VS |
6619 | static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc) |
6620 | { | |
6621 | const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); | |
6622 | ||
6623 | /* GDG double wide on either pipe, otherwise pipe A only */ | |
6624 | return INTEL_INFO(dev_priv)->gen < 4 && | |
6625 | (crtc->pipe == PIPE_A || IS_I915G(dev_priv)); | |
6626 | } | |
6627 | ||
a43f6e0f | 6628 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
5cec258b | 6629 | struct intel_crtc_state *pipe_config) |
79e53945 | 6630 | { |
a43f6e0f | 6631 | struct drm_device *dev = crtc->base.dev; |
8bd31e67 | 6632 | struct drm_i915_private *dev_priv = dev->dev_private; |
7c5f93b0 | 6633 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
f3261156 | 6634 | int clock_limit = dev_priv->max_dotclk_freq; |
89749350 | 6635 | |
cf532bb2 | 6636 | if (INTEL_INFO(dev)->gen < 4) { |
f3261156 | 6637 | clock_limit = dev_priv->max_cdclk_freq * 9 / 10; |
cf532bb2 VS |
6638 | |
6639 | /* | |
39acb4aa | 6640 | * Enable double wide mode when the dot clock |
cf532bb2 | 6641 | * is > 90% of the (display) core speed. |
cf532bb2 | 6642 | */ |
39acb4aa VS |
6643 | if (intel_crtc_supports_double_wide(crtc) && |
6644 | adjusted_mode->crtc_clock > clock_limit) { | |
f3261156 | 6645 | clock_limit = dev_priv->max_dotclk_freq; |
cf532bb2 | 6646 | pipe_config->double_wide = true; |
ad3a4479 | 6647 | } |
f3261156 | 6648 | } |
ad3a4479 | 6649 | |
f3261156 VS |
6650 | if (adjusted_mode->crtc_clock > clock_limit) { |
6651 | DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n", | |
6652 | adjusted_mode->crtc_clock, clock_limit, | |
6653 | yesno(pipe_config->double_wide)); | |
6654 | return -EINVAL; | |
2c07245f | 6655 | } |
89749350 | 6656 | |
1d1d0e27 VS |
6657 | /* |
6658 | * Pipe horizontal size must be even in: | |
6659 | * - DVO ganged mode | |
6660 | * - LVDS dual channel mode | |
6661 | * - Double wide pipe | |
6662 | */ | |
a93e255f | 6663 | if ((intel_pipe_will_have_type(pipe_config, INTEL_OUTPUT_LVDS) && |
1d1d0e27 VS |
6664 | intel_is_dual_link_lvds(dev)) || pipe_config->double_wide) |
6665 | pipe_config->pipe_src_w &= ~1; | |
6666 | ||
8693a824 DL |
6667 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
6668 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. | |
44f46b42 CW |
6669 | */ |
6670 | if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) && | |
aad941d5 | 6671 | adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay) |
e29c22c0 | 6672 | return -EINVAL; |
44f46b42 | 6673 | |
f5adf94e | 6674 | if (HAS_IPS(dev)) |
a43f6e0f DV |
6675 | hsw_compute_ips_config(crtc, pipe_config); |
6676 | ||
877d48d5 | 6677 | if (pipe_config->has_pch_encoder) |
a43f6e0f | 6678 | return ironlake_fdi_compute_config(crtc, pipe_config); |
877d48d5 | 6679 | |
cf5a15be | 6680 | return 0; |
79e53945 JB |
6681 | } |
6682 | ||
1652d19e VS |
6683 | static int skylake_get_display_clock_speed(struct drm_device *dev) |
6684 | { | |
6685 | struct drm_i915_private *dev_priv = to_i915(dev); | |
ea61791e | 6686 | uint32_t cdctl; |
1652d19e | 6687 | |
ea61791e | 6688 | skl_dpll0_update(dev_priv); |
1652d19e | 6689 | |
63911d72 | 6690 | if (dev_priv->cdclk_pll.vco == 0) |
709e05c3 | 6691 | return dev_priv->cdclk_pll.ref; |
1652d19e | 6692 | |
ea61791e | 6693 | cdctl = I915_READ(CDCLK_CTL); |
1652d19e | 6694 | |
63911d72 | 6695 | if (dev_priv->cdclk_pll.vco == 8640000) { |
1652d19e VS |
6696 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { |
6697 | case CDCLK_FREQ_450_432: | |
6698 | return 432000; | |
6699 | case CDCLK_FREQ_337_308: | |
487ed2e4 | 6700 | return 308571; |
ea61791e VS |
6701 | case CDCLK_FREQ_540: |
6702 | return 540000; | |
1652d19e | 6703 | case CDCLK_FREQ_675_617: |
487ed2e4 | 6704 | return 617143; |
1652d19e | 6705 | default: |
ea61791e | 6706 | MISSING_CASE(cdctl & CDCLK_FREQ_SEL_MASK); |
1652d19e VS |
6707 | } |
6708 | } else { | |
1652d19e VS |
6709 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { |
6710 | case CDCLK_FREQ_450_432: | |
6711 | return 450000; | |
6712 | case CDCLK_FREQ_337_308: | |
6713 | return 337500; | |
ea61791e VS |
6714 | case CDCLK_FREQ_540: |
6715 | return 540000; | |
1652d19e VS |
6716 | case CDCLK_FREQ_675_617: |
6717 | return 675000; | |
6718 | default: | |
ea61791e | 6719 | MISSING_CASE(cdctl & CDCLK_FREQ_SEL_MASK); |
1652d19e VS |
6720 | } |
6721 | } | |
6722 | ||
709e05c3 | 6723 | return dev_priv->cdclk_pll.ref; |
1652d19e VS |
6724 | } |
6725 | ||
83d7c81f VS |
6726 | static void bxt_de_pll_update(struct drm_i915_private *dev_priv) |
6727 | { | |
6728 | u32 val; | |
6729 | ||
6730 | dev_priv->cdclk_pll.ref = 19200; | |
1c3f7700 | 6731 | dev_priv->cdclk_pll.vco = 0; |
83d7c81f VS |
6732 | |
6733 | val = I915_READ(BXT_DE_PLL_ENABLE); | |
1c3f7700 | 6734 | if ((val & BXT_DE_PLL_PLL_ENABLE) == 0) |
83d7c81f | 6735 | return; |
83d7c81f | 6736 | |
1c3f7700 ID |
6737 | if (WARN_ON((val & BXT_DE_PLL_LOCK) == 0)) |
6738 | return; | |
83d7c81f VS |
6739 | |
6740 | val = I915_READ(BXT_DE_PLL_CTL); | |
6741 | dev_priv->cdclk_pll.vco = (val & BXT_DE_PLL_RATIO_MASK) * | |
6742 | dev_priv->cdclk_pll.ref; | |
6743 | } | |
6744 | ||
acd3f3d3 BP |
6745 | static int broxton_get_display_clock_speed(struct drm_device *dev) |
6746 | { | |
6747 | struct drm_i915_private *dev_priv = to_i915(dev); | |
f5986242 VS |
6748 | u32 divider; |
6749 | int div, vco; | |
acd3f3d3 | 6750 | |
83d7c81f VS |
6751 | bxt_de_pll_update(dev_priv); |
6752 | ||
f5986242 VS |
6753 | vco = dev_priv->cdclk_pll.vco; |
6754 | if (vco == 0) | |
6755 | return dev_priv->cdclk_pll.ref; | |
acd3f3d3 | 6756 | |
f5986242 | 6757 | divider = I915_READ(CDCLK_CTL) & BXT_CDCLK_CD2X_DIV_SEL_MASK; |
acd3f3d3 | 6758 | |
f5986242 | 6759 | switch (divider) { |
acd3f3d3 | 6760 | case BXT_CDCLK_CD2X_DIV_SEL_1: |
f5986242 VS |
6761 | div = 2; |
6762 | break; | |
acd3f3d3 | 6763 | case BXT_CDCLK_CD2X_DIV_SEL_1_5: |
f5986242 VS |
6764 | div = 3; |
6765 | break; | |
acd3f3d3 | 6766 | case BXT_CDCLK_CD2X_DIV_SEL_2: |
f5986242 VS |
6767 | div = 4; |
6768 | break; | |
acd3f3d3 | 6769 | case BXT_CDCLK_CD2X_DIV_SEL_4: |
f5986242 VS |
6770 | div = 8; |
6771 | break; | |
6772 | default: | |
6773 | MISSING_CASE(divider); | |
6774 | return dev_priv->cdclk_pll.ref; | |
acd3f3d3 BP |
6775 | } |
6776 | ||
f5986242 | 6777 | return DIV_ROUND_CLOSEST(vco, div); |
acd3f3d3 BP |
6778 | } |
6779 | ||
1652d19e VS |
6780 | static int broadwell_get_display_clock_speed(struct drm_device *dev) |
6781 | { | |
6782 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6783 | uint32_t lcpll = I915_READ(LCPLL_CTL); | |
6784 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; | |
6785 | ||
6786 | if (lcpll & LCPLL_CD_SOURCE_FCLK) | |
6787 | return 800000; | |
6788 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
6789 | return 450000; | |
6790 | else if (freq == LCPLL_CLK_FREQ_450) | |
6791 | return 450000; | |
6792 | else if (freq == LCPLL_CLK_FREQ_54O_BDW) | |
6793 | return 540000; | |
6794 | else if (freq == LCPLL_CLK_FREQ_337_5_BDW) | |
6795 | return 337500; | |
6796 | else | |
6797 | return 675000; | |
6798 | } | |
6799 | ||
6800 | static int haswell_get_display_clock_speed(struct drm_device *dev) | |
6801 | { | |
6802 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6803 | uint32_t lcpll = I915_READ(LCPLL_CTL); | |
6804 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; | |
6805 | ||
6806 | if (lcpll & LCPLL_CD_SOURCE_FCLK) | |
6807 | return 800000; | |
6808 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) | |
6809 | return 450000; | |
6810 | else if (freq == LCPLL_CLK_FREQ_450) | |
6811 | return 450000; | |
6812 | else if (IS_HSW_ULT(dev)) | |
6813 | return 337500; | |
6814 | else | |
6815 | return 540000; | |
79e53945 JB |
6816 | } |
6817 | ||
25eb05fc JB |
6818 | static int valleyview_get_display_clock_speed(struct drm_device *dev) |
6819 | { | |
bfa7df01 VS |
6820 | return vlv_get_cck_clock_hpll(to_i915(dev), "cdclk", |
6821 | CCK_DISPLAY_CLOCK_CONTROL); | |
25eb05fc JB |
6822 | } |
6823 | ||
b37a6434 VS |
6824 | static int ilk_get_display_clock_speed(struct drm_device *dev) |
6825 | { | |
6826 | return 450000; | |
6827 | } | |
6828 | ||
e70236a8 JB |
6829 | static int i945_get_display_clock_speed(struct drm_device *dev) |
6830 | { | |
6831 | return 400000; | |
6832 | } | |
79e53945 | 6833 | |
e70236a8 | 6834 | static int i915_get_display_clock_speed(struct drm_device *dev) |
79e53945 | 6835 | { |
e907f170 | 6836 | return 333333; |
e70236a8 | 6837 | } |
79e53945 | 6838 | |
e70236a8 JB |
6839 | static int i9xx_misc_get_display_clock_speed(struct drm_device *dev) |
6840 | { | |
6841 | return 200000; | |
6842 | } | |
79e53945 | 6843 | |
257a7ffc DV |
6844 | static int pnv_get_display_clock_speed(struct drm_device *dev) |
6845 | { | |
6846 | u16 gcfgc = 0; | |
6847 | ||
6848 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); | |
6849 | ||
6850 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { | |
6851 | case GC_DISPLAY_CLOCK_267_MHZ_PNV: | |
e907f170 | 6852 | return 266667; |
257a7ffc | 6853 | case GC_DISPLAY_CLOCK_333_MHZ_PNV: |
e907f170 | 6854 | return 333333; |
257a7ffc | 6855 | case GC_DISPLAY_CLOCK_444_MHZ_PNV: |
e907f170 | 6856 | return 444444; |
257a7ffc DV |
6857 | case GC_DISPLAY_CLOCK_200_MHZ_PNV: |
6858 | return 200000; | |
6859 | default: | |
6860 | DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc); | |
6861 | case GC_DISPLAY_CLOCK_133_MHZ_PNV: | |
e907f170 | 6862 | return 133333; |
257a7ffc | 6863 | case GC_DISPLAY_CLOCK_167_MHZ_PNV: |
e907f170 | 6864 | return 166667; |
257a7ffc DV |
6865 | } |
6866 | } | |
6867 | ||
e70236a8 JB |
6868 | static int i915gm_get_display_clock_speed(struct drm_device *dev) |
6869 | { | |
6870 | u16 gcfgc = 0; | |
79e53945 | 6871 | |
e70236a8 JB |
6872 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
6873 | ||
6874 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) | |
e907f170 | 6875 | return 133333; |
e70236a8 JB |
6876 | else { |
6877 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { | |
6878 | case GC_DISPLAY_CLOCK_333_MHZ: | |
e907f170 | 6879 | return 333333; |
e70236a8 JB |
6880 | default: |
6881 | case GC_DISPLAY_CLOCK_190_200_MHZ: | |
6882 | return 190000; | |
79e53945 | 6883 | } |
e70236a8 JB |
6884 | } |
6885 | } | |
6886 | ||
6887 | static int i865_get_display_clock_speed(struct drm_device *dev) | |
6888 | { | |
e907f170 | 6889 | return 266667; |
e70236a8 JB |
6890 | } |
6891 | ||
1b1d2716 | 6892 | static int i85x_get_display_clock_speed(struct drm_device *dev) |
e70236a8 JB |
6893 | { |
6894 | u16 hpllcc = 0; | |
1b1d2716 | 6895 | |
65cd2b3f VS |
6896 | /* |
6897 | * 852GM/852GMV only supports 133 MHz and the HPLLCC | |
6898 | * encoding is different :( | |
6899 | * FIXME is this the right way to detect 852GM/852GMV? | |
6900 | */ | |
6901 | if (dev->pdev->revision == 0x1) | |
6902 | return 133333; | |
6903 | ||
1b1d2716 VS |
6904 | pci_bus_read_config_word(dev->pdev->bus, |
6905 | PCI_DEVFN(0, 3), HPLLCC, &hpllcc); | |
6906 | ||
e70236a8 JB |
6907 | /* Assume that the hardware is in the high speed state. This |
6908 | * should be the default. | |
6909 | */ | |
6910 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { | |
6911 | case GC_CLOCK_133_200: | |
1b1d2716 | 6912 | case GC_CLOCK_133_200_2: |
e70236a8 JB |
6913 | case GC_CLOCK_100_200: |
6914 | return 200000; | |
6915 | case GC_CLOCK_166_250: | |
6916 | return 250000; | |
6917 | case GC_CLOCK_100_133: | |
e907f170 | 6918 | return 133333; |
1b1d2716 VS |
6919 | case GC_CLOCK_133_266: |
6920 | case GC_CLOCK_133_266_2: | |
6921 | case GC_CLOCK_166_266: | |
6922 | return 266667; | |
e70236a8 | 6923 | } |
79e53945 | 6924 | |
e70236a8 JB |
6925 | /* Shouldn't happen */ |
6926 | return 0; | |
6927 | } | |
79e53945 | 6928 | |
e70236a8 JB |
6929 | static int i830_get_display_clock_speed(struct drm_device *dev) |
6930 | { | |
e907f170 | 6931 | return 133333; |
79e53945 JB |
6932 | } |
6933 | ||
34edce2f VS |
6934 | static unsigned int intel_hpll_vco(struct drm_device *dev) |
6935 | { | |
6936 | struct drm_i915_private *dev_priv = dev->dev_private; | |
6937 | static const unsigned int blb_vco[8] = { | |
6938 | [0] = 3200000, | |
6939 | [1] = 4000000, | |
6940 | [2] = 5333333, | |
6941 | [3] = 4800000, | |
6942 | [4] = 6400000, | |
6943 | }; | |
6944 | static const unsigned int pnv_vco[8] = { | |
6945 | [0] = 3200000, | |
6946 | [1] = 4000000, | |
6947 | [2] = 5333333, | |
6948 | [3] = 4800000, | |
6949 | [4] = 2666667, | |
6950 | }; | |
6951 | static const unsigned int cl_vco[8] = { | |
6952 | [0] = 3200000, | |
6953 | [1] = 4000000, | |
6954 | [2] = 5333333, | |
6955 | [3] = 6400000, | |
6956 | [4] = 3333333, | |
6957 | [5] = 3566667, | |
6958 | [6] = 4266667, | |
6959 | }; | |
6960 | static const unsigned int elk_vco[8] = { | |
6961 | [0] = 3200000, | |
6962 | [1] = 4000000, | |
6963 | [2] = 5333333, | |
6964 | [3] = 4800000, | |
6965 | }; | |
6966 | static const unsigned int ctg_vco[8] = { | |
6967 | [0] = 3200000, | |
6968 | [1] = 4000000, | |
6969 | [2] = 5333333, | |
6970 | [3] = 6400000, | |
6971 | [4] = 2666667, | |
6972 | [5] = 4266667, | |
6973 | }; | |
6974 | const unsigned int *vco_table; | |
6975 | unsigned int vco; | |
6976 | uint8_t tmp = 0; | |
6977 | ||
6978 | /* FIXME other chipsets? */ | |
6979 | if (IS_GM45(dev)) | |
6980 | vco_table = ctg_vco; | |
6981 | else if (IS_G4X(dev)) | |
6982 | vco_table = elk_vco; | |
6983 | else if (IS_CRESTLINE(dev)) | |
6984 | vco_table = cl_vco; | |
6985 | else if (IS_PINEVIEW(dev)) | |
6986 | vco_table = pnv_vco; | |
6987 | else if (IS_G33(dev)) | |
6988 | vco_table = blb_vco; | |
6989 | else | |
6990 | return 0; | |
6991 | ||
6992 | tmp = I915_READ(IS_MOBILE(dev) ? HPLLVCO_MOBILE : HPLLVCO); | |
6993 | ||
6994 | vco = vco_table[tmp & 0x7]; | |
6995 | if (vco == 0) | |
6996 | DRM_ERROR("Bad HPLL VCO (HPLLVCO=0x%02x)\n", tmp); | |
6997 | else | |
6998 | DRM_DEBUG_KMS("HPLL VCO %u kHz\n", vco); | |
6999 | ||
7000 | return vco; | |
7001 | } | |
7002 | ||
7003 | static int gm45_get_display_clock_speed(struct drm_device *dev) | |
7004 | { | |
7005 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
7006 | uint16_t tmp = 0; | |
7007 | ||
7008 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
7009 | ||
7010 | cdclk_sel = (tmp >> 12) & 0x1; | |
7011 | ||
7012 | switch (vco) { | |
7013 | case 2666667: | |
7014 | case 4000000: | |
7015 | case 5333333: | |
7016 | return cdclk_sel ? 333333 : 222222; | |
7017 | case 3200000: | |
7018 | return cdclk_sel ? 320000 : 228571; | |
7019 | default: | |
7020 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u, CFGC=0x%04x\n", vco, tmp); | |
7021 | return 222222; | |
7022 | } | |
7023 | } | |
7024 | ||
7025 | static int i965gm_get_display_clock_speed(struct drm_device *dev) | |
7026 | { | |
7027 | static const uint8_t div_3200[] = { 16, 10, 8 }; | |
7028 | static const uint8_t div_4000[] = { 20, 12, 10 }; | |
7029 | static const uint8_t div_5333[] = { 24, 16, 14 }; | |
7030 | const uint8_t *div_table; | |
7031 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
7032 | uint16_t tmp = 0; | |
7033 | ||
7034 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
7035 | ||
7036 | cdclk_sel = ((tmp >> 8) & 0x1f) - 1; | |
7037 | ||
7038 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) | |
7039 | goto fail; | |
7040 | ||
7041 | switch (vco) { | |
7042 | case 3200000: | |
7043 | div_table = div_3200; | |
7044 | break; | |
7045 | case 4000000: | |
7046 | div_table = div_4000; | |
7047 | break; | |
7048 | case 5333333: | |
7049 | div_table = div_5333; | |
7050 | break; | |
7051 | default: | |
7052 | goto fail; | |
7053 | } | |
7054 | ||
7055 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); | |
7056 | ||
caf4e252 | 7057 | fail: |
34edce2f VS |
7058 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%04x\n", vco, tmp); |
7059 | return 200000; | |
7060 | } | |
7061 | ||
7062 | static int g33_get_display_clock_speed(struct drm_device *dev) | |
7063 | { | |
7064 | static const uint8_t div_3200[] = { 12, 10, 8, 7, 5, 16 }; | |
7065 | static const uint8_t div_4000[] = { 14, 12, 10, 8, 6, 20 }; | |
7066 | static const uint8_t div_4800[] = { 20, 14, 12, 10, 8, 24 }; | |
7067 | static const uint8_t div_5333[] = { 20, 16, 12, 12, 8, 28 }; | |
7068 | const uint8_t *div_table; | |
7069 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); | |
7070 | uint16_t tmp = 0; | |
7071 | ||
7072 | pci_read_config_word(dev->pdev, GCFGC, &tmp); | |
7073 | ||
7074 | cdclk_sel = (tmp >> 4) & 0x7; | |
7075 | ||
7076 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) | |
7077 | goto fail; | |
7078 | ||
7079 | switch (vco) { | |
7080 | case 3200000: | |
7081 | div_table = div_3200; | |
7082 | break; | |
7083 | case 4000000: | |
7084 | div_table = div_4000; | |
7085 | break; | |
7086 | case 4800000: | |
7087 | div_table = div_4800; | |
7088 | break; | |
7089 | case 5333333: | |
7090 | div_table = div_5333; | |
7091 | break; | |
7092 | default: | |
7093 | goto fail; | |
7094 | } | |
7095 | ||
7096 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); | |
7097 | ||
caf4e252 | 7098 | fail: |
34edce2f VS |
7099 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%08x\n", vco, tmp); |
7100 | return 190476; | |
7101 | } | |
7102 | ||
2c07245f | 7103 | static void |
a65851af | 7104 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
2c07245f | 7105 | { |
a65851af VS |
7106 | while (*num > DATA_LINK_M_N_MASK || |
7107 | *den > DATA_LINK_M_N_MASK) { | |
2c07245f ZW |
7108 | *num >>= 1; |
7109 | *den >>= 1; | |
7110 | } | |
7111 | } | |
7112 | ||
a65851af VS |
7113 | static void compute_m_n(unsigned int m, unsigned int n, |
7114 | uint32_t *ret_m, uint32_t *ret_n) | |
7115 | { | |
7116 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); | |
7117 | *ret_m = div_u64((uint64_t) m * *ret_n, n); | |
7118 | intel_reduce_m_n_ratio(ret_m, ret_n); | |
7119 | } | |
7120 | ||
e69d0bc1 DV |
7121 | void |
7122 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, | |
7123 | int pixel_clock, int link_clock, | |
7124 | struct intel_link_m_n *m_n) | |
2c07245f | 7125 | { |
e69d0bc1 | 7126 | m_n->tu = 64; |
a65851af VS |
7127 | |
7128 | compute_m_n(bits_per_pixel * pixel_clock, | |
7129 | link_clock * nlanes * 8, | |
7130 | &m_n->gmch_m, &m_n->gmch_n); | |
7131 | ||
7132 | compute_m_n(pixel_clock, link_clock, | |
7133 | &m_n->link_m, &m_n->link_n); | |
2c07245f ZW |
7134 | } |
7135 | ||
a7615030 CW |
7136 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
7137 | { | |
d330a953 JN |
7138 | if (i915.panel_use_ssc >= 0) |
7139 | return i915.panel_use_ssc != 0; | |
41aa3448 | 7140 | return dev_priv->vbt.lvds_use_ssc |
435793df | 7141 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
a7615030 CW |
7142 | } |
7143 | ||
7429e9d4 | 7144 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
c65d77d8 | 7145 | { |
7df00d7a | 7146 | return (1 << dpll->n) << 16 | dpll->m2; |
7429e9d4 | 7147 | } |
f47709a9 | 7148 | |
7429e9d4 DV |
7149 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
7150 | { | |
7151 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; | |
c65d77d8 JB |
7152 | } |
7153 | ||
f47709a9 | 7154 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
190f68c5 | 7155 | struct intel_crtc_state *crtc_state, |
9e2c8475 | 7156 | struct dpll *reduced_clock) |
a7516a05 | 7157 | { |
f47709a9 | 7158 | struct drm_device *dev = crtc->base.dev; |
a7516a05 JB |
7159 | u32 fp, fp2 = 0; |
7160 | ||
7161 | if (IS_PINEVIEW(dev)) { | |
190f68c5 | 7162 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
a7516a05 | 7163 | if (reduced_clock) |
7429e9d4 | 7164 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
a7516a05 | 7165 | } else { |
190f68c5 | 7166 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
a7516a05 | 7167 | if (reduced_clock) |
7429e9d4 | 7168 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
a7516a05 JB |
7169 | } |
7170 | ||
190f68c5 | 7171 | crtc_state->dpll_hw_state.fp0 = fp; |
a7516a05 | 7172 | |
f47709a9 | 7173 | crtc->lowfreq_avail = false; |
a93e255f | 7174 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
ab585dea | 7175 | reduced_clock) { |
190f68c5 | 7176 | crtc_state->dpll_hw_state.fp1 = fp2; |
f47709a9 | 7177 | crtc->lowfreq_avail = true; |
a7516a05 | 7178 | } else { |
190f68c5 | 7179 | crtc_state->dpll_hw_state.fp1 = fp; |
a7516a05 JB |
7180 | } |
7181 | } | |
7182 | ||
5e69f97f CML |
7183 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
7184 | pipe) | |
89b667f8 JB |
7185 | { |
7186 | u32 reg_val; | |
7187 | ||
7188 | /* | |
7189 | * PLLB opamp always calibrates to max value of 0x3f, force enable it | |
7190 | * and set it to a reasonable value instead. | |
7191 | */ | |
ab3c759a | 7192 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
89b667f8 JB |
7193 | reg_val &= 0xffffff00; |
7194 | reg_val |= 0x00000030; | |
ab3c759a | 7195 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
89b667f8 | 7196 | |
ab3c759a | 7197 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
89b667f8 JB |
7198 | reg_val &= 0x8cffffff; |
7199 | reg_val = 0x8c000000; | |
ab3c759a | 7200 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
89b667f8 | 7201 | |
ab3c759a | 7202 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
89b667f8 | 7203 | reg_val &= 0xffffff00; |
ab3c759a | 7204 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
89b667f8 | 7205 | |
ab3c759a | 7206 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
89b667f8 JB |
7207 | reg_val &= 0x00ffffff; |
7208 | reg_val |= 0xb0000000; | |
ab3c759a | 7209 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
89b667f8 JB |
7210 | } |
7211 | ||
b551842d DV |
7212 | static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc, |
7213 | struct intel_link_m_n *m_n) | |
7214 | { | |
7215 | struct drm_device *dev = crtc->base.dev; | |
7216 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7217 | int pipe = crtc->pipe; | |
7218 | ||
e3b95f1e DV |
7219 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
7220 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); | |
7221 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); | |
7222 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); | |
b551842d DV |
7223 | } |
7224 | ||
7225 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, | |
f769cd24 VK |
7226 | struct intel_link_m_n *m_n, |
7227 | struct intel_link_m_n *m2_n2) | |
b551842d DV |
7228 | { |
7229 | struct drm_device *dev = crtc->base.dev; | |
7230 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7231 | int pipe = crtc->pipe; | |
6e3c9717 | 7232 | enum transcoder transcoder = crtc->config->cpu_transcoder; |
b551842d DV |
7233 | |
7234 | if (INTEL_INFO(dev)->gen >= 5) { | |
7235 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); | |
7236 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); | |
7237 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); | |
7238 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); | |
f769cd24 VK |
7239 | /* M2_N2 registers to be set only for gen < 8 (M2_N2 available |
7240 | * for gen < 8) and if DRRS is supported (to make sure the | |
7241 | * registers are not unnecessarily accessed). | |
7242 | */ | |
44395bfe | 7243 | if (m2_n2 && (IS_CHERRYVIEW(dev) || INTEL_INFO(dev)->gen < 8) && |
6e3c9717 | 7244 | crtc->config->has_drrs) { |
f769cd24 VK |
7245 | I915_WRITE(PIPE_DATA_M2(transcoder), |
7246 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); | |
7247 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); | |
7248 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); | |
7249 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); | |
7250 | } | |
b551842d | 7251 | } else { |
e3b95f1e DV |
7252 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
7253 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); | |
7254 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); | |
7255 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); | |
b551842d DV |
7256 | } |
7257 | } | |
7258 | ||
fe3cd48d | 7259 | void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n) |
03afc4a2 | 7260 | { |
fe3cd48d R |
7261 | struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL; |
7262 | ||
7263 | if (m_n == M1_N1) { | |
7264 | dp_m_n = &crtc->config->dp_m_n; | |
7265 | dp_m2_n2 = &crtc->config->dp_m2_n2; | |
7266 | } else if (m_n == M2_N2) { | |
7267 | ||
7268 | /* | |
7269 | * M2_N2 registers are not supported. Hence m2_n2 divider value | |
7270 | * needs to be programmed into M1_N1. | |
7271 | */ | |
7272 | dp_m_n = &crtc->config->dp_m2_n2; | |
7273 | } else { | |
7274 | DRM_ERROR("Unsupported divider value\n"); | |
7275 | return; | |
7276 | } | |
7277 | ||
6e3c9717 ACO |
7278 | if (crtc->config->has_pch_encoder) |
7279 | intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n); | |
03afc4a2 | 7280 | else |
fe3cd48d | 7281 | intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2); |
03afc4a2 DV |
7282 | } |
7283 | ||
251ac862 DV |
7284 | static void vlv_compute_dpll(struct intel_crtc *crtc, |
7285 | struct intel_crtc_state *pipe_config) | |
bdd4b6a6 | 7286 | { |
03ed5cbf | 7287 | pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV | |
cd2d34d9 | 7288 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
03ed5cbf VS |
7289 | if (crtc->pipe != PIPE_A) |
7290 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
bdd4b6a6 | 7291 | |
cd2d34d9 | 7292 | /* DPLL not used with DSI, but still need the rest set up */ |
187a1c07 | 7293 | if (!pipe_config->has_dsi_encoder) |
cd2d34d9 VS |
7294 | pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE | |
7295 | DPLL_EXT_BUFFER_ENABLE_VLV; | |
7296 | ||
03ed5cbf VS |
7297 | pipe_config->dpll_hw_state.dpll_md = |
7298 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; | |
7299 | } | |
bdd4b6a6 | 7300 | |
03ed5cbf VS |
7301 | static void chv_compute_dpll(struct intel_crtc *crtc, |
7302 | struct intel_crtc_state *pipe_config) | |
7303 | { | |
7304 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV | | |
cd2d34d9 | 7305 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
03ed5cbf VS |
7306 | if (crtc->pipe != PIPE_A) |
7307 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
7308 | ||
cd2d34d9 | 7309 | /* DPLL not used with DSI, but still need the rest set up */ |
187a1c07 | 7310 | if (!pipe_config->has_dsi_encoder) |
cd2d34d9 VS |
7311 | pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE; |
7312 | ||
03ed5cbf VS |
7313 | pipe_config->dpll_hw_state.dpll_md = |
7314 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; | |
bdd4b6a6 DV |
7315 | } |
7316 | ||
d288f65f | 7317 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 7318 | const struct intel_crtc_state *pipe_config) |
a0c4da24 | 7319 | { |
f47709a9 | 7320 | struct drm_device *dev = crtc->base.dev; |
a0c4da24 | 7321 | struct drm_i915_private *dev_priv = dev->dev_private; |
cd2d34d9 | 7322 | enum pipe pipe = crtc->pipe; |
bdd4b6a6 | 7323 | u32 mdiv; |
a0c4da24 | 7324 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
bdd4b6a6 | 7325 | u32 coreclk, reg_val; |
a0c4da24 | 7326 | |
cd2d34d9 VS |
7327 | /* Enable Refclk */ |
7328 | I915_WRITE(DPLL(pipe), | |
7329 | pipe_config->dpll_hw_state.dpll & | |
7330 | ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV)); | |
7331 | ||
7332 | /* No need to actually set up the DPLL with DSI */ | |
7333 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) | |
7334 | return; | |
7335 | ||
a580516d | 7336 | mutex_lock(&dev_priv->sb_lock); |
09153000 | 7337 | |
d288f65f VS |
7338 | bestn = pipe_config->dpll.n; |
7339 | bestm1 = pipe_config->dpll.m1; | |
7340 | bestm2 = pipe_config->dpll.m2; | |
7341 | bestp1 = pipe_config->dpll.p1; | |
7342 | bestp2 = pipe_config->dpll.p2; | |
a0c4da24 | 7343 | |
89b667f8 JB |
7344 | /* See eDP HDMI DPIO driver vbios notes doc */ |
7345 | ||
7346 | /* PLL B needs special handling */ | |
bdd4b6a6 | 7347 | if (pipe == PIPE_B) |
5e69f97f | 7348 | vlv_pllb_recal_opamp(dev_priv, pipe); |
89b667f8 JB |
7349 | |
7350 | /* Set up Tx target for periodic Rcomp update */ | |
ab3c759a | 7351 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
89b667f8 JB |
7352 | |
7353 | /* Disable target IRef on PLL */ | |
ab3c759a | 7354 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
89b667f8 | 7355 | reg_val &= 0x00ffffff; |
ab3c759a | 7356 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
89b667f8 JB |
7357 | |
7358 | /* Disable fast lock */ | |
ab3c759a | 7359 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
89b667f8 JB |
7360 | |
7361 | /* Set idtafcrecal before PLL is enabled */ | |
a0c4da24 JB |
7362 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
7363 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); | |
7364 | mdiv |= ((bestn << DPIO_N_SHIFT)); | |
a0c4da24 | 7365 | mdiv |= (1 << DPIO_K_SHIFT); |
7df5080b JB |
7366 | |
7367 | /* | |
7368 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, | |
7369 | * but we don't support that). | |
7370 | * Note: don't use the DAC post divider as it seems unstable. | |
7371 | */ | |
7372 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); | |
ab3c759a | 7373 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
a0c4da24 | 7374 | |
a0c4da24 | 7375 | mdiv |= DPIO_ENABLE_CALIBRATION; |
ab3c759a | 7376 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
a0c4da24 | 7377 | |
89b667f8 | 7378 | /* Set HBR and RBR LPF coefficients */ |
d288f65f | 7379 | if (pipe_config->port_clock == 162000 || |
409ee761 ACO |
7380 | intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG) || |
7381 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) | |
ab3c759a | 7382 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
885b0120 | 7383 | 0x009f0003); |
89b667f8 | 7384 | else |
ab3c759a | 7385 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
89b667f8 JB |
7386 | 0x00d0000f); |
7387 | ||
681a8504 | 7388 | if (pipe_config->has_dp_encoder) { |
89b667f8 | 7389 | /* Use SSC source */ |
bdd4b6a6 | 7390 | if (pipe == PIPE_A) |
ab3c759a | 7391 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7392 | 0x0df40000); |
7393 | else | |
ab3c759a | 7394 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7395 | 0x0df70000); |
7396 | } else { /* HDMI or VGA */ | |
7397 | /* Use bend source */ | |
bdd4b6a6 | 7398 | if (pipe == PIPE_A) |
ab3c759a | 7399 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7400 | 0x0df70000); |
7401 | else | |
ab3c759a | 7402 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
7403 | 0x0df40000); |
7404 | } | |
a0c4da24 | 7405 | |
ab3c759a | 7406 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
89b667f8 | 7407 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
409ee761 ACO |
7408 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || |
7409 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) | |
89b667f8 | 7410 | coreclk |= 0x01000000; |
ab3c759a | 7411 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
a0c4da24 | 7412 | |
ab3c759a | 7413 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
a580516d | 7414 | mutex_unlock(&dev_priv->sb_lock); |
a0c4da24 JB |
7415 | } |
7416 | ||
d288f65f | 7417 | static void chv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 7418 | const struct intel_crtc_state *pipe_config) |
9d556c99 CML |
7419 | { |
7420 | struct drm_device *dev = crtc->base.dev; | |
7421 | struct drm_i915_private *dev_priv = dev->dev_private; | |
cd2d34d9 | 7422 | enum pipe pipe = crtc->pipe; |
9d556c99 | 7423 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
9cbe40c1 | 7424 | u32 loopfilter, tribuf_calcntr; |
9d556c99 | 7425 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
a945ce7e | 7426 | u32 dpio_val; |
9cbe40c1 | 7427 | int vco; |
9d556c99 | 7428 | |
cd2d34d9 VS |
7429 | /* Enable Refclk and SSC */ |
7430 | I915_WRITE(DPLL(pipe), | |
7431 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); | |
7432 | ||
7433 | /* No need to actually set up the DPLL with DSI */ | |
7434 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) | |
7435 | return; | |
7436 | ||
d288f65f VS |
7437 | bestn = pipe_config->dpll.n; |
7438 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; | |
7439 | bestm1 = pipe_config->dpll.m1; | |
7440 | bestm2 = pipe_config->dpll.m2 >> 22; | |
7441 | bestp1 = pipe_config->dpll.p1; | |
7442 | bestp2 = pipe_config->dpll.p2; | |
9cbe40c1 | 7443 | vco = pipe_config->dpll.vco; |
a945ce7e | 7444 | dpio_val = 0; |
9cbe40c1 | 7445 | loopfilter = 0; |
9d556c99 | 7446 | |
a580516d | 7447 | mutex_lock(&dev_priv->sb_lock); |
9d556c99 | 7448 | |
9d556c99 CML |
7449 | /* p1 and p2 divider */ |
7450 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), | |
7451 | 5 << DPIO_CHV_S1_DIV_SHIFT | | |
7452 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | | |
7453 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | | |
7454 | 1 << DPIO_CHV_K_DIV_SHIFT); | |
7455 | ||
7456 | /* Feedback post-divider - m2 */ | |
7457 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); | |
7458 | ||
7459 | /* Feedback refclk divider - n and m1 */ | |
7460 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), | |
7461 | DPIO_CHV_M1_DIV_BY_2 | | |
7462 | 1 << DPIO_CHV_N_DIV_SHIFT); | |
7463 | ||
7464 | /* M2 fraction division */ | |
25a25dfc | 7465 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac); |
9d556c99 CML |
7466 | |
7467 | /* M2 fraction division enable */ | |
a945ce7e VP |
7468 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
7469 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); | |
7470 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); | |
7471 | if (bestm2_frac) | |
7472 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; | |
7473 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val); | |
9d556c99 | 7474 | |
de3a0fde VP |
7475 | /* Program digital lock detect threshold */ |
7476 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); | |
7477 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | | |
7478 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); | |
7479 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); | |
7480 | if (!bestm2_frac) | |
7481 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; | |
7482 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); | |
7483 | ||
9d556c99 | 7484 | /* Loop filter */ |
9cbe40c1 VP |
7485 | if (vco == 5400000) { |
7486 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7487 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); | |
7488 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7489 | tribuf_calcntr = 0x9; | |
7490 | } else if (vco <= 6200000) { | |
7491 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7492 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); | |
7493 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7494 | tribuf_calcntr = 0x9; | |
7495 | } else if (vco <= 6480000) { | |
7496 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7497 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); | |
7498 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7499 | tribuf_calcntr = 0x8; | |
7500 | } else { | |
7501 | /* Not supported. Apply the same limits as in the max case */ | |
7502 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); | |
7503 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); | |
7504 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
7505 | tribuf_calcntr = 0; | |
7506 | } | |
9d556c99 CML |
7507 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
7508 | ||
968040b2 | 7509 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
9cbe40c1 VP |
7510 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
7511 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); | |
7512 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); | |
7513 | ||
9d556c99 CML |
7514 | /* AFC Recal */ |
7515 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), | |
7516 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | | |
7517 | DPIO_AFC_RECAL); | |
7518 | ||
a580516d | 7519 | mutex_unlock(&dev_priv->sb_lock); |
9d556c99 CML |
7520 | } |
7521 | ||
d288f65f VS |
7522 | /** |
7523 | * vlv_force_pll_on - forcibly enable just the PLL | |
7524 | * @dev_priv: i915 private structure | |
7525 | * @pipe: pipe PLL to enable | |
7526 | * @dpll: PLL configuration | |
7527 | * | |
7528 | * Enable the PLL for @pipe using the supplied @dpll config. To be used | |
7529 | * in cases where we need the PLL enabled even when @pipe is not going to | |
7530 | * be enabled. | |
7531 | */ | |
3f36b937 TU |
7532 | int vlv_force_pll_on(struct drm_device *dev, enum pipe pipe, |
7533 | const struct dpll *dpll) | |
d288f65f VS |
7534 | { |
7535 | struct intel_crtc *crtc = | |
7536 | to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe)); | |
3f36b937 TU |
7537 | struct intel_crtc_state *pipe_config; |
7538 | ||
7539 | pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); | |
7540 | if (!pipe_config) | |
7541 | return -ENOMEM; | |
7542 | ||
7543 | pipe_config->base.crtc = &crtc->base; | |
7544 | pipe_config->pixel_multiplier = 1; | |
7545 | pipe_config->dpll = *dpll; | |
d288f65f VS |
7546 | |
7547 | if (IS_CHERRYVIEW(dev)) { | |
3f36b937 TU |
7548 | chv_compute_dpll(crtc, pipe_config); |
7549 | chv_prepare_pll(crtc, pipe_config); | |
7550 | chv_enable_pll(crtc, pipe_config); | |
d288f65f | 7551 | } else { |
3f36b937 TU |
7552 | vlv_compute_dpll(crtc, pipe_config); |
7553 | vlv_prepare_pll(crtc, pipe_config); | |
7554 | vlv_enable_pll(crtc, pipe_config); | |
d288f65f | 7555 | } |
3f36b937 TU |
7556 | |
7557 | kfree(pipe_config); | |
7558 | ||
7559 | return 0; | |
d288f65f VS |
7560 | } |
7561 | ||
7562 | /** | |
7563 | * vlv_force_pll_off - forcibly disable just the PLL | |
7564 | * @dev_priv: i915 private structure | |
7565 | * @pipe: pipe PLL to disable | |
7566 | * | |
7567 | * Disable the PLL for @pipe. To be used in cases where we need | |
7568 | * the PLL enabled even when @pipe is not going to be enabled. | |
7569 | */ | |
7570 | void vlv_force_pll_off(struct drm_device *dev, enum pipe pipe) | |
7571 | { | |
7572 | if (IS_CHERRYVIEW(dev)) | |
7573 | chv_disable_pll(to_i915(dev), pipe); | |
7574 | else | |
7575 | vlv_disable_pll(to_i915(dev), pipe); | |
7576 | } | |
7577 | ||
251ac862 DV |
7578 | static void i9xx_compute_dpll(struct intel_crtc *crtc, |
7579 | struct intel_crtc_state *crtc_state, | |
9e2c8475 | 7580 | struct dpll *reduced_clock) |
eb1cbe48 | 7581 | { |
f47709a9 | 7582 | struct drm_device *dev = crtc->base.dev; |
eb1cbe48 | 7583 | struct drm_i915_private *dev_priv = dev->dev_private; |
eb1cbe48 DV |
7584 | u32 dpll; |
7585 | bool is_sdvo; | |
190f68c5 | 7586 | struct dpll *clock = &crtc_state->dpll; |
eb1cbe48 | 7587 | |
190f68c5 | 7588 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
2a8f64ca | 7589 | |
a93e255f ACO |
7590 | is_sdvo = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO) || |
7591 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI); | |
eb1cbe48 DV |
7592 | |
7593 | dpll = DPLL_VGA_MODE_DIS; | |
7594 | ||
a93e255f | 7595 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
eb1cbe48 DV |
7596 | dpll |= DPLLB_MODE_LVDS; |
7597 | else | |
7598 | dpll |= DPLLB_MODE_DAC_SERIAL; | |
6cc5f341 | 7599 | |
ef1b460d | 7600 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
190f68c5 | 7601 | dpll |= (crtc_state->pixel_multiplier - 1) |
198a037f | 7602 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
eb1cbe48 | 7603 | } |
198a037f DV |
7604 | |
7605 | if (is_sdvo) | |
4a33e48d | 7606 | dpll |= DPLL_SDVO_HIGH_SPEED; |
198a037f | 7607 | |
190f68c5 | 7608 | if (crtc_state->has_dp_encoder) |
4a33e48d | 7609 | dpll |= DPLL_SDVO_HIGH_SPEED; |
eb1cbe48 DV |
7610 | |
7611 | /* compute bitmask from p1 value */ | |
7612 | if (IS_PINEVIEW(dev)) | |
7613 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; | |
7614 | else { | |
7615 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
7616 | if (IS_G4X(dev) && reduced_clock) | |
7617 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; | |
7618 | } | |
7619 | switch (clock->p2) { | |
7620 | case 5: | |
7621 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; | |
7622 | break; | |
7623 | case 7: | |
7624 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; | |
7625 | break; | |
7626 | case 10: | |
7627 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; | |
7628 | break; | |
7629 | case 14: | |
7630 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; | |
7631 | break; | |
7632 | } | |
7633 | if (INTEL_INFO(dev)->gen >= 4) | |
7634 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); | |
7635 | ||
190f68c5 | 7636 | if (crtc_state->sdvo_tv_clock) |
eb1cbe48 | 7637 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
a93e255f | 7638 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
ceb41007 | 7639 | intel_panel_use_ssc(dev_priv)) |
eb1cbe48 DV |
7640 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
7641 | else | |
7642 | dpll |= PLL_REF_INPUT_DREFCLK; | |
7643 | ||
7644 | dpll |= DPLL_VCO_ENABLE; | |
190f68c5 | 7645 | crtc_state->dpll_hw_state.dpll = dpll; |
8bcc2795 | 7646 | |
eb1cbe48 | 7647 | if (INTEL_INFO(dev)->gen >= 4) { |
190f68c5 | 7648 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
ef1b460d | 7649 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
190f68c5 | 7650 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
eb1cbe48 DV |
7651 | } |
7652 | } | |
7653 | ||
251ac862 DV |
7654 | static void i8xx_compute_dpll(struct intel_crtc *crtc, |
7655 | struct intel_crtc_state *crtc_state, | |
9e2c8475 | 7656 | struct dpll *reduced_clock) |
eb1cbe48 | 7657 | { |
f47709a9 | 7658 | struct drm_device *dev = crtc->base.dev; |
eb1cbe48 | 7659 | struct drm_i915_private *dev_priv = dev->dev_private; |
eb1cbe48 | 7660 | u32 dpll; |
190f68c5 | 7661 | struct dpll *clock = &crtc_state->dpll; |
eb1cbe48 | 7662 | |
190f68c5 | 7663 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
2a8f64ca | 7664 | |
eb1cbe48 DV |
7665 | dpll = DPLL_VGA_MODE_DIS; |
7666 | ||
a93e255f | 7667 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
eb1cbe48 DV |
7668 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
7669 | } else { | |
7670 | if (clock->p1 == 2) | |
7671 | dpll |= PLL_P1_DIVIDE_BY_TWO; | |
7672 | else | |
7673 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
7674 | if (clock->p2 == 4) | |
7675 | dpll |= PLL_P2_DIVIDE_BY_4; | |
7676 | } | |
7677 | ||
a93e255f | 7678 | if (!IS_I830(dev) && intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) |
4a33e48d DV |
7679 | dpll |= DPLL_DVO_2X_MODE; |
7680 | ||
a93e255f | 7681 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
ceb41007 | 7682 | intel_panel_use_ssc(dev_priv)) |
eb1cbe48 DV |
7683 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
7684 | else | |
7685 | dpll |= PLL_REF_INPUT_DREFCLK; | |
7686 | ||
7687 | dpll |= DPLL_VCO_ENABLE; | |
190f68c5 | 7688 | crtc_state->dpll_hw_state.dpll = dpll; |
eb1cbe48 DV |
7689 | } |
7690 | ||
8a654f3b | 7691 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc) |
b0e77b9c PZ |
7692 | { |
7693 | struct drm_device *dev = intel_crtc->base.dev; | |
7694 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7695 | enum pipe pipe = intel_crtc->pipe; | |
6e3c9717 | 7696 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
7c5f93b0 | 7697 | const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode; |
1caea6e9 VS |
7698 | uint32_t crtc_vtotal, crtc_vblank_end; |
7699 | int vsyncshift = 0; | |
4d8a62ea DV |
7700 | |
7701 | /* We need to be careful not to changed the adjusted mode, for otherwise | |
7702 | * the hw state checker will get angry at the mismatch. */ | |
7703 | crtc_vtotal = adjusted_mode->crtc_vtotal; | |
7704 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; | |
b0e77b9c | 7705 | |
609aeaca | 7706 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
b0e77b9c | 7707 | /* the chip adds 2 halflines automatically */ |
4d8a62ea DV |
7708 | crtc_vtotal -= 1; |
7709 | crtc_vblank_end -= 1; | |
609aeaca | 7710 | |
409ee761 | 7711 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
609aeaca VS |
7712 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
7713 | else | |
7714 | vsyncshift = adjusted_mode->crtc_hsync_start - | |
7715 | adjusted_mode->crtc_htotal / 2; | |
1caea6e9 VS |
7716 | if (vsyncshift < 0) |
7717 | vsyncshift += adjusted_mode->crtc_htotal; | |
b0e77b9c PZ |
7718 | } |
7719 | ||
7720 | if (INTEL_INFO(dev)->gen > 3) | |
fe2b8f9d | 7721 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
b0e77b9c | 7722 | |
fe2b8f9d | 7723 | I915_WRITE(HTOTAL(cpu_transcoder), |
b0e77b9c PZ |
7724 | (adjusted_mode->crtc_hdisplay - 1) | |
7725 | ((adjusted_mode->crtc_htotal - 1) << 16)); | |
fe2b8f9d | 7726 | I915_WRITE(HBLANK(cpu_transcoder), |
b0e77b9c PZ |
7727 | (adjusted_mode->crtc_hblank_start - 1) | |
7728 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); | |
fe2b8f9d | 7729 | I915_WRITE(HSYNC(cpu_transcoder), |
b0e77b9c PZ |
7730 | (adjusted_mode->crtc_hsync_start - 1) | |
7731 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); | |
7732 | ||
fe2b8f9d | 7733 | I915_WRITE(VTOTAL(cpu_transcoder), |
b0e77b9c | 7734 | (adjusted_mode->crtc_vdisplay - 1) | |
4d8a62ea | 7735 | ((crtc_vtotal - 1) << 16)); |
fe2b8f9d | 7736 | I915_WRITE(VBLANK(cpu_transcoder), |
b0e77b9c | 7737 | (adjusted_mode->crtc_vblank_start - 1) | |
4d8a62ea | 7738 | ((crtc_vblank_end - 1) << 16)); |
fe2b8f9d | 7739 | I915_WRITE(VSYNC(cpu_transcoder), |
b0e77b9c PZ |
7740 | (adjusted_mode->crtc_vsync_start - 1) | |
7741 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); | |
7742 | ||
b5e508d4 PZ |
7743 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
7744 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is | |
7745 | * documented on the DDI_FUNC_CTL register description, EDP Input Select | |
7746 | * bits. */ | |
7747 | if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP && | |
7748 | (pipe == PIPE_B || pipe == PIPE_C)) | |
7749 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); | |
7750 | ||
bc58be60 JN |
7751 | } |
7752 | ||
7753 | static void intel_set_pipe_src_size(struct intel_crtc *intel_crtc) | |
7754 | { | |
7755 | struct drm_device *dev = intel_crtc->base.dev; | |
7756 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7757 | enum pipe pipe = intel_crtc->pipe; | |
7758 | ||
b0e77b9c PZ |
7759 | /* pipesrc controls the size that is scaled from, which should |
7760 | * always be the user's requested size. | |
7761 | */ | |
7762 | I915_WRITE(PIPESRC(pipe), | |
6e3c9717 ACO |
7763 | ((intel_crtc->config->pipe_src_w - 1) << 16) | |
7764 | (intel_crtc->config->pipe_src_h - 1)); | |
b0e77b9c PZ |
7765 | } |
7766 | ||
1bd1bd80 | 7767 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
5cec258b | 7768 | struct intel_crtc_state *pipe_config) |
1bd1bd80 DV |
7769 | { |
7770 | struct drm_device *dev = crtc->base.dev; | |
7771 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7772 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; | |
7773 | uint32_t tmp; | |
7774 | ||
7775 | tmp = I915_READ(HTOTAL(cpu_transcoder)); | |
2d112de7 ACO |
7776 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
7777 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7778 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
2d112de7 ACO |
7779 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
7780 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7781 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
2d112de7 ACO |
7782 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
7783 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 DV |
7784 | |
7785 | tmp = I915_READ(VTOTAL(cpu_transcoder)); | |
2d112de7 ACO |
7786 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
7787 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7788 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
2d112de7 ACO |
7789 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
7790 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7791 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
2d112de7 ACO |
7792 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
7793 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 DV |
7794 | |
7795 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { | |
2d112de7 ACO |
7796 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
7797 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; | |
7798 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; | |
1bd1bd80 | 7799 | } |
bc58be60 JN |
7800 | } |
7801 | ||
7802 | static void intel_get_pipe_src_size(struct intel_crtc *crtc, | |
7803 | struct intel_crtc_state *pipe_config) | |
7804 | { | |
7805 | struct drm_device *dev = crtc->base.dev; | |
7806 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7807 | u32 tmp; | |
1bd1bd80 DV |
7808 | |
7809 | tmp = I915_READ(PIPESRC(crtc->pipe)); | |
37327abd VS |
7810 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
7811 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; | |
7812 | ||
2d112de7 ACO |
7813 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
7814 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; | |
1bd1bd80 DV |
7815 | } |
7816 | ||
f6a83288 | 7817 | void intel_mode_from_pipe_config(struct drm_display_mode *mode, |
5cec258b | 7818 | struct intel_crtc_state *pipe_config) |
babea61d | 7819 | { |
2d112de7 ACO |
7820 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
7821 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; | |
7822 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; | |
7823 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; | |
babea61d | 7824 | |
2d112de7 ACO |
7825 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
7826 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; | |
7827 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; | |
7828 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; | |
babea61d | 7829 | |
2d112de7 | 7830 | mode->flags = pipe_config->base.adjusted_mode.flags; |
cd13f5ab | 7831 | mode->type = DRM_MODE_TYPE_DRIVER; |
babea61d | 7832 | |
2d112de7 ACO |
7833 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
7834 | mode->flags |= pipe_config->base.adjusted_mode.flags; | |
cd13f5ab ML |
7835 | |
7836 | mode->hsync = drm_mode_hsync(mode); | |
7837 | mode->vrefresh = drm_mode_vrefresh(mode); | |
7838 | drm_mode_set_name(mode); | |
babea61d JB |
7839 | } |
7840 | ||
84b046f3 DV |
7841 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc) |
7842 | { | |
7843 | struct drm_device *dev = intel_crtc->base.dev; | |
7844 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7845 | uint32_t pipeconf; | |
7846 | ||
9f11a9e4 | 7847 | pipeconf = 0; |
84b046f3 | 7848 | |
b6b5d049 VS |
7849 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
7850 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
7851 | pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE; | |
67c72a12 | 7852 | |
6e3c9717 | 7853 | if (intel_crtc->config->double_wide) |
cf532bb2 | 7854 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
84b046f3 | 7855 | |
ff9ce46e | 7856 | /* only g4x and later have fancy bpc/dither controls */ |
666a4537 | 7857 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
ff9ce46e | 7858 | /* Bspec claims that we can't use dithering for 30bpp pipes. */ |
6e3c9717 | 7859 | if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30) |
ff9ce46e | 7860 | pipeconf |= PIPECONF_DITHER_EN | |
84b046f3 | 7861 | PIPECONF_DITHER_TYPE_SP; |
84b046f3 | 7862 | |
6e3c9717 | 7863 | switch (intel_crtc->config->pipe_bpp) { |
ff9ce46e DV |
7864 | case 18: |
7865 | pipeconf |= PIPECONF_6BPC; | |
7866 | break; | |
7867 | case 24: | |
7868 | pipeconf |= PIPECONF_8BPC; | |
7869 | break; | |
7870 | case 30: | |
7871 | pipeconf |= PIPECONF_10BPC; | |
7872 | break; | |
7873 | default: | |
7874 | /* Case prevented by intel_choose_pipe_bpp_dither. */ | |
7875 | BUG(); | |
84b046f3 DV |
7876 | } |
7877 | } | |
7878 | ||
7879 | if (HAS_PIPE_CXSR(dev)) { | |
7880 | if (intel_crtc->lowfreq_avail) { | |
7881 | DRM_DEBUG_KMS("enabling CxSR downclocking\n"); | |
7882 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; | |
7883 | } else { | |
7884 | DRM_DEBUG_KMS("disabling CxSR downclocking\n"); | |
84b046f3 DV |
7885 | } |
7886 | } | |
7887 | ||
6e3c9717 | 7888 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { |
efc2cfff | 7889 | if (INTEL_INFO(dev)->gen < 4 || |
409ee761 | 7890 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
efc2cfff VS |
7891 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
7892 | else | |
7893 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; | |
7894 | } else | |
84b046f3 DV |
7895 | pipeconf |= PIPECONF_PROGRESSIVE; |
7896 | ||
666a4537 WB |
7897 | if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) && |
7898 | intel_crtc->config->limited_color_range) | |
9f11a9e4 | 7899 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
9c8e09b7 | 7900 | |
84b046f3 DV |
7901 | I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf); |
7902 | POSTING_READ(PIPECONF(intel_crtc->pipe)); | |
7903 | } | |
7904 | ||
81c97f52 ACO |
7905 | static int i8xx_crtc_compute_clock(struct intel_crtc *crtc, |
7906 | struct intel_crtc_state *crtc_state) | |
7907 | { | |
7908 | struct drm_device *dev = crtc->base.dev; | |
7909 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1b6f4958 | 7910 | const struct intel_limit *limit; |
81c97f52 ACO |
7911 | int refclk = 48000; |
7912 | ||
7913 | memset(&crtc_state->dpll_hw_state, 0, | |
7914 | sizeof(crtc_state->dpll_hw_state)); | |
7915 | ||
7916 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { | |
7917 | if (intel_panel_use_ssc(dev_priv)) { | |
7918 | refclk = dev_priv->vbt.lvds_ssc_freq; | |
7919 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); | |
7920 | } | |
7921 | ||
7922 | limit = &intel_limits_i8xx_lvds; | |
7923 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) { | |
7924 | limit = &intel_limits_i8xx_dvo; | |
7925 | } else { | |
7926 | limit = &intel_limits_i8xx_dac; | |
7927 | } | |
7928 | ||
7929 | if (!crtc_state->clock_set && | |
7930 | !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock, | |
7931 | refclk, NULL, &crtc_state->dpll)) { | |
7932 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); | |
7933 | return -EINVAL; | |
7934 | } | |
7935 | ||
7936 | i8xx_compute_dpll(crtc, crtc_state, NULL); | |
7937 | ||
7938 | return 0; | |
7939 | } | |
7940 | ||
19ec6693 ACO |
7941 | static int g4x_crtc_compute_clock(struct intel_crtc *crtc, |
7942 | struct intel_crtc_state *crtc_state) | |
7943 | { | |
7944 | struct drm_device *dev = crtc->base.dev; | |
7945 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1b6f4958 | 7946 | const struct intel_limit *limit; |
19ec6693 ACO |
7947 | int refclk = 96000; |
7948 | ||
7949 | memset(&crtc_state->dpll_hw_state, 0, | |
7950 | sizeof(crtc_state->dpll_hw_state)); | |
7951 | ||
7952 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { | |
7953 | if (intel_panel_use_ssc(dev_priv)) { | |
7954 | refclk = dev_priv->vbt.lvds_ssc_freq; | |
7955 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); | |
7956 | } | |
7957 | ||
7958 | if (intel_is_dual_link_lvds(dev)) | |
7959 | limit = &intel_limits_g4x_dual_channel_lvds; | |
7960 | else | |
7961 | limit = &intel_limits_g4x_single_channel_lvds; | |
7962 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI) || | |
7963 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_ANALOG)) { | |
7964 | limit = &intel_limits_g4x_hdmi; | |
7965 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO)) { | |
7966 | limit = &intel_limits_g4x_sdvo; | |
7967 | } else { | |
7968 | /* The option is for other outputs */ | |
7969 | limit = &intel_limits_i9xx_sdvo; | |
7970 | } | |
7971 | ||
7972 | if (!crtc_state->clock_set && | |
7973 | !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock, | |
7974 | refclk, NULL, &crtc_state->dpll)) { | |
7975 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); | |
7976 | return -EINVAL; | |
7977 | } | |
7978 | ||
7979 | i9xx_compute_dpll(crtc, crtc_state, NULL); | |
7980 | ||
7981 | return 0; | |
7982 | } | |
7983 | ||
70e8aa21 ACO |
7984 | static int pnv_crtc_compute_clock(struct intel_crtc *crtc, |
7985 | struct intel_crtc_state *crtc_state) | |
7986 | { | |
7987 | struct drm_device *dev = crtc->base.dev; | |
7988 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1b6f4958 | 7989 | const struct intel_limit *limit; |
70e8aa21 ACO |
7990 | int refclk = 96000; |
7991 | ||
7992 | memset(&crtc_state->dpll_hw_state, 0, | |
7993 | sizeof(crtc_state->dpll_hw_state)); | |
7994 | ||
7995 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { | |
7996 | if (intel_panel_use_ssc(dev_priv)) { | |
7997 | refclk = dev_priv->vbt.lvds_ssc_freq; | |
7998 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); | |
7999 | } | |
8000 | ||
8001 | limit = &intel_limits_pineview_lvds; | |
8002 | } else { | |
8003 | limit = &intel_limits_pineview_sdvo; | |
8004 | } | |
8005 | ||
8006 | if (!crtc_state->clock_set && | |
8007 | !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, | |
8008 | refclk, NULL, &crtc_state->dpll)) { | |
8009 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); | |
8010 | return -EINVAL; | |
8011 | } | |
8012 | ||
8013 | i9xx_compute_dpll(crtc, crtc_state, NULL); | |
8014 | ||
8015 | return 0; | |
8016 | } | |
8017 | ||
190f68c5 ACO |
8018 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
8019 | struct intel_crtc_state *crtc_state) | |
79e53945 | 8020 | { |
c7653199 | 8021 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 8022 | struct drm_i915_private *dev_priv = dev->dev_private; |
1b6f4958 | 8023 | const struct intel_limit *limit; |
81c97f52 | 8024 | int refclk = 96000; |
79e53945 | 8025 | |
dd3cd74a ACO |
8026 | memset(&crtc_state->dpll_hw_state, 0, |
8027 | sizeof(crtc_state->dpll_hw_state)); | |
8028 | ||
70e8aa21 ACO |
8029 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
8030 | if (intel_panel_use_ssc(dev_priv)) { | |
8031 | refclk = dev_priv->vbt.lvds_ssc_freq; | |
8032 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); | |
8033 | } | |
43565a06 | 8034 | |
70e8aa21 ACO |
8035 | limit = &intel_limits_i9xx_lvds; |
8036 | } else { | |
8037 | limit = &intel_limits_i9xx_sdvo; | |
81c97f52 | 8038 | } |
79e53945 | 8039 | |
70e8aa21 ACO |
8040 | if (!crtc_state->clock_set && |
8041 | !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock, | |
8042 | refclk, NULL, &crtc_state->dpll)) { | |
8043 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); | |
8044 | return -EINVAL; | |
f47709a9 | 8045 | } |
7026d4ac | 8046 | |
81c97f52 | 8047 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
79e53945 | 8048 | |
c8f7a0db | 8049 | return 0; |
f564048e EA |
8050 | } |
8051 | ||
65b3d6a9 ACO |
8052 | static int chv_crtc_compute_clock(struct intel_crtc *crtc, |
8053 | struct intel_crtc_state *crtc_state) | |
8054 | { | |
8055 | int refclk = 100000; | |
1b6f4958 | 8056 | const struct intel_limit *limit = &intel_limits_chv; |
65b3d6a9 ACO |
8057 | |
8058 | memset(&crtc_state->dpll_hw_state, 0, | |
8059 | sizeof(crtc_state->dpll_hw_state)); | |
8060 | ||
65b3d6a9 ACO |
8061 | if (!crtc_state->clock_set && |
8062 | !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, | |
8063 | refclk, NULL, &crtc_state->dpll)) { | |
8064 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); | |
8065 | return -EINVAL; | |
8066 | } | |
8067 | ||
8068 | chv_compute_dpll(crtc, crtc_state); | |
8069 | ||
8070 | return 0; | |
8071 | } | |
8072 | ||
8073 | static int vlv_crtc_compute_clock(struct intel_crtc *crtc, | |
8074 | struct intel_crtc_state *crtc_state) | |
8075 | { | |
8076 | int refclk = 100000; | |
1b6f4958 | 8077 | const struct intel_limit *limit = &intel_limits_vlv; |
65b3d6a9 ACO |
8078 | |
8079 | memset(&crtc_state->dpll_hw_state, 0, | |
8080 | sizeof(crtc_state->dpll_hw_state)); | |
8081 | ||
65b3d6a9 ACO |
8082 | if (!crtc_state->clock_set && |
8083 | !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, | |
8084 | refclk, NULL, &crtc_state->dpll)) { | |
8085 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); | |
8086 | return -EINVAL; | |
8087 | } | |
8088 | ||
8089 | vlv_compute_dpll(crtc, crtc_state); | |
8090 | ||
8091 | return 0; | |
8092 | } | |
8093 | ||
2fa2fe9a | 8094 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 8095 | struct intel_crtc_state *pipe_config) |
2fa2fe9a DV |
8096 | { |
8097 | struct drm_device *dev = crtc->base.dev; | |
8098 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8099 | uint32_t tmp; | |
8100 | ||
dc9e7dec VS |
8101 | if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev))) |
8102 | return; | |
8103 | ||
2fa2fe9a | 8104 | tmp = I915_READ(PFIT_CONTROL); |
06922821 DV |
8105 | if (!(tmp & PFIT_ENABLE)) |
8106 | return; | |
2fa2fe9a | 8107 | |
06922821 | 8108 | /* Check whether the pfit is attached to our pipe. */ |
2fa2fe9a DV |
8109 | if (INTEL_INFO(dev)->gen < 4) { |
8110 | if (crtc->pipe != PIPE_B) | |
8111 | return; | |
2fa2fe9a DV |
8112 | } else { |
8113 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) | |
8114 | return; | |
8115 | } | |
8116 | ||
06922821 | 8117 | pipe_config->gmch_pfit.control = tmp; |
2fa2fe9a | 8118 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
2fa2fe9a DV |
8119 | } |
8120 | ||
acbec814 | 8121 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 8122 | struct intel_crtc_state *pipe_config) |
acbec814 JB |
8123 | { |
8124 | struct drm_device *dev = crtc->base.dev; | |
8125 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8126 | int pipe = pipe_config->cpu_transcoder; | |
9e2c8475 | 8127 | struct dpll clock; |
acbec814 | 8128 | u32 mdiv; |
662c6ecb | 8129 | int refclk = 100000; |
acbec814 | 8130 | |
b521973b VS |
8131 | /* In case of DSI, DPLL will not be used */ |
8132 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) | |
f573de5a SK |
8133 | return; |
8134 | ||
a580516d | 8135 | mutex_lock(&dev_priv->sb_lock); |
ab3c759a | 8136 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
a580516d | 8137 | mutex_unlock(&dev_priv->sb_lock); |
acbec814 JB |
8138 | |
8139 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; | |
8140 | clock.m2 = mdiv & DPIO_M2DIV_MASK; | |
8141 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; | |
8142 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; | |
8143 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; | |
8144 | ||
dccbea3b | 8145 | pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock); |
acbec814 JB |
8146 | } |
8147 | ||
5724dbd1 DL |
8148 | static void |
8149 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, | |
8150 | struct intel_initial_plane_config *plane_config) | |
1ad292b5 JB |
8151 | { |
8152 | struct drm_device *dev = crtc->base.dev; | |
8153 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8154 | u32 val, base, offset; | |
8155 | int pipe = crtc->pipe, plane = crtc->plane; | |
8156 | int fourcc, pixel_format; | |
6761dd31 | 8157 | unsigned int aligned_height; |
b113d5ee | 8158 | struct drm_framebuffer *fb; |
1b842c89 | 8159 | struct intel_framebuffer *intel_fb; |
1ad292b5 | 8160 | |
42a7b088 DL |
8161 | val = I915_READ(DSPCNTR(plane)); |
8162 | if (!(val & DISPLAY_PLANE_ENABLE)) | |
8163 | return; | |
8164 | ||
d9806c9f | 8165 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 8166 | if (!intel_fb) { |
1ad292b5 JB |
8167 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
8168 | return; | |
8169 | } | |
8170 | ||
1b842c89 DL |
8171 | fb = &intel_fb->base; |
8172 | ||
18c5247e DV |
8173 | if (INTEL_INFO(dev)->gen >= 4) { |
8174 | if (val & DISPPLANE_TILED) { | |
49af449b | 8175 | plane_config->tiling = I915_TILING_X; |
18c5247e DV |
8176 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
8177 | } | |
8178 | } | |
1ad292b5 JB |
8179 | |
8180 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; | |
b35d63fa | 8181 | fourcc = i9xx_format_to_fourcc(pixel_format); |
b113d5ee DL |
8182 | fb->pixel_format = fourcc; |
8183 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
1ad292b5 JB |
8184 | |
8185 | if (INTEL_INFO(dev)->gen >= 4) { | |
49af449b | 8186 | if (plane_config->tiling) |
1ad292b5 JB |
8187 | offset = I915_READ(DSPTILEOFF(plane)); |
8188 | else | |
8189 | offset = I915_READ(DSPLINOFF(plane)); | |
8190 | base = I915_READ(DSPSURF(plane)) & 0xfffff000; | |
8191 | } else { | |
8192 | base = I915_READ(DSPADDR(plane)); | |
8193 | } | |
8194 | plane_config->base = base; | |
8195 | ||
8196 | val = I915_READ(PIPESRC(pipe)); | |
b113d5ee DL |
8197 | fb->width = ((val >> 16) & 0xfff) + 1; |
8198 | fb->height = ((val >> 0) & 0xfff) + 1; | |
1ad292b5 JB |
8199 | |
8200 | val = I915_READ(DSPSTRIDE(pipe)); | |
b113d5ee | 8201 | fb->pitches[0] = val & 0xffffffc0; |
1ad292b5 | 8202 | |
b113d5ee | 8203 | aligned_height = intel_fb_align_height(dev, fb->height, |
091df6cb DV |
8204 | fb->pixel_format, |
8205 | fb->modifier[0]); | |
1ad292b5 | 8206 | |
f37b5c2b | 8207 | plane_config->size = fb->pitches[0] * aligned_height; |
1ad292b5 | 8208 | |
2844a921 DL |
8209 | DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
8210 | pipe_name(pipe), plane, fb->width, fb->height, | |
8211 | fb->bits_per_pixel, base, fb->pitches[0], | |
8212 | plane_config->size); | |
1ad292b5 | 8213 | |
2d14030b | 8214 | plane_config->fb = intel_fb; |
1ad292b5 JB |
8215 | } |
8216 | ||
70b23a98 | 8217 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 8218 | struct intel_crtc_state *pipe_config) |
70b23a98 VS |
8219 | { |
8220 | struct drm_device *dev = crtc->base.dev; | |
8221 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8222 | int pipe = pipe_config->cpu_transcoder; | |
8223 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
9e2c8475 | 8224 | struct dpll clock; |
0d7b6b11 | 8225 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3; |
70b23a98 VS |
8226 | int refclk = 100000; |
8227 | ||
b521973b VS |
8228 | /* In case of DSI, DPLL will not be used */ |
8229 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) | |
8230 | return; | |
8231 | ||
a580516d | 8232 | mutex_lock(&dev_priv->sb_lock); |
70b23a98 VS |
8233 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
8234 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); | |
8235 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); | |
8236 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); | |
0d7b6b11 | 8237 | pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
a580516d | 8238 | mutex_unlock(&dev_priv->sb_lock); |
70b23a98 VS |
8239 | |
8240 | clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0; | |
0d7b6b11 ID |
8241 | clock.m2 = (pll_dw0 & 0xff) << 22; |
8242 | if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN) | |
8243 | clock.m2 |= pll_dw2 & 0x3fffff; | |
70b23a98 VS |
8244 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; |
8245 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; | |
8246 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; | |
8247 | ||
dccbea3b | 8248 | pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock); |
70b23a98 VS |
8249 | } |
8250 | ||
0e8ffe1b | 8251 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 8252 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
8253 | { |
8254 | struct drm_device *dev = crtc->base.dev; | |
8255 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1729050e | 8256 | enum intel_display_power_domain power_domain; |
0e8ffe1b | 8257 | uint32_t tmp; |
1729050e | 8258 | bool ret; |
0e8ffe1b | 8259 | |
1729050e ID |
8260 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
8261 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) | |
b5482bd0 ID |
8262 | return false; |
8263 | ||
e143a21c | 8264 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
8106ddbd | 8265 | pipe_config->shared_dpll = NULL; |
eccb140b | 8266 | |
1729050e ID |
8267 | ret = false; |
8268 | ||
0e8ffe1b DV |
8269 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
8270 | if (!(tmp & PIPECONF_ENABLE)) | |
1729050e | 8271 | goto out; |
0e8ffe1b | 8272 | |
666a4537 | 8273 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
42571aef VS |
8274 | switch (tmp & PIPECONF_BPC_MASK) { |
8275 | case PIPECONF_6BPC: | |
8276 | pipe_config->pipe_bpp = 18; | |
8277 | break; | |
8278 | case PIPECONF_8BPC: | |
8279 | pipe_config->pipe_bpp = 24; | |
8280 | break; | |
8281 | case PIPECONF_10BPC: | |
8282 | pipe_config->pipe_bpp = 30; | |
8283 | break; | |
8284 | default: | |
8285 | break; | |
8286 | } | |
8287 | } | |
8288 | ||
666a4537 WB |
8289 | if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) && |
8290 | (tmp & PIPECONF_COLOR_RANGE_SELECT)) | |
b5a9fa09 DV |
8291 | pipe_config->limited_color_range = true; |
8292 | ||
282740f7 VS |
8293 | if (INTEL_INFO(dev)->gen < 4) |
8294 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; | |
8295 | ||
1bd1bd80 | 8296 | intel_get_pipe_timings(crtc, pipe_config); |
bc58be60 | 8297 | intel_get_pipe_src_size(crtc, pipe_config); |
1bd1bd80 | 8298 | |
2fa2fe9a DV |
8299 | i9xx_get_pfit_config(crtc, pipe_config); |
8300 | ||
6c49f241 | 8301 | if (INTEL_INFO(dev)->gen >= 4) { |
c231775c VS |
8302 | /* No way to read it out on pipes B and C */ |
8303 | if (IS_CHERRYVIEW(dev) && crtc->pipe != PIPE_A) | |
8304 | tmp = dev_priv->chv_dpll_md[crtc->pipe]; | |
8305 | else | |
8306 | tmp = I915_READ(DPLL_MD(crtc->pipe)); | |
6c49f241 DV |
8307 | pipe_config->pixel_multiplier = |
8308 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) | |
8309 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; | |
8bcc2795 | 8310 | pipe_config->dpll_hw_state.dpll_md = tmp; |
6c49f241 DV |
8311 | } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
8312 | tmp = I915_READ(DPLL(crtc->pipe)); | |
8313 | pipe_config->pixel_multiplier = | |
8314 | ((tmp & SDVO_MULTIPLIER_MASK) | |
8315 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; | |
8316 | } else { | |
8317 | /* Note that on i915G/GM the pixel multiplier is in the sdvo | |
8318 | * port and will be fixed up in the encoder->get_config | |
8319 | * function. */ | |
8320 | pipe_config->pixel_multiplier = 1; | |
8321 | } | |
8bcc2795 | 8322 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
666a4537 | 8323 | if (!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) { |
1c4e0274 VS |
8324 | /* |
8325 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs | |
8326 | * on 830. Filter it out here so that we don't | |
8327 | * report errors due to that. | |
8328 | */ | |
8329 | if (IS_I830(dev)) | |
8330 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; | |
8331 | ||
8bcc2795 DV |
8332 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
8333 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); | |
165e901c VS |
8334 | } else { |
8335 | /* Mask out read-only status bits. */ | |
8336 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | | |
8337 | DPLL_PORTC_READY_MASK | | |
8338 | DPLL_PORTB_READY_MASK); | |
8bcc2795 | 8339 | } |
6c49f241 | 8340 | |
70b23a98 VS |
8341 | if (IS_CHERRYVIEW(dev)) |
8342 | chv_crtc_clock_get(crtc, pipe_config); | |
8343 | else if (IS_VALLEYVIEW(dev)) | |
acbec814 JB |
8344 | vlv_crtc_clock_get(crtc, pipe_config); |
8345 | else | |
8346 | i9xx_crtc_clock_get(crtc, pipe_config); | |
18442d08 | 8347 | |
0f64614d VS |
8348 | /* |
8349 | * Normally the dotclock is filled in by the encoder .get_config() | |
8350 | * but in case the pipe is enabled w/o any ports we need a sane | |
8351 | * default. | |
8352 | */ | |
8353 | pipe_config->base.adjusted_mode.crtc_clock = | |
8354 | pipe_config->port_clock / pipe_config->pixel_multiplier; | |
8355 | ||
1729050e ID |
8356 | ret = true; |
8357 | ||
8358 | out: | |
8359 | intel_display_power_put(dev_priv, power_domain); | |
8360 | ||
8361 | return ret; | |
0e8ffe1b DV |
8362 | } |
8363 | ||
dde86e2d | 8364 | static void ironlake_init_pch_refclk(struct drm_device *dev) |
13d83a67 JB |
8365 | { |
8366 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13d83a67 | 8367 | struct intel_encoder *encoder; |
1c1a24d2 | 8368 | int i; |
74cfd7ac | 8369 | u32 val, final; |
13d83a67 | 8370 | bool has_lvds = false; |
199e5d79 | 8371 | bool has_cpu_edp = false; |
199e5d79 | 8372 | bool has_panel = false; |
99eb6a01 KP |
8373 | bool has_ck505 = false; |
8374 | bool can_ssc = false; | |
1c1a24d2 | 8375 | bool using_ssc_source = false; |
13d83a67 JB |
8376 | |
8377 | /* We need to take the global config into account */ | |
b2784e15 | 8378 | for_each_intel_encoder(dev, encoder) { |
199e5d79 KP |
8379 | switch (encoder->type) { |
8380 | case INTEL_OUTPUT_LVDS: | |
8381 | has_panel = true; | |
8382 | has_lvds = true; | |
8383 | break; | |
8384 | case INTEL_OUTPUT_EDP: | |
8385 | has_panel = true; | |
2de6905f | 8386 | if (enc_to_dig_port(&encoder->base)->port == PORT_A) |
199e5d79 KP |
8387 | has_cpu_edp = true; |
8388 | break; | |
6847d71b PZ |
8389 | default: |
8390 | break; | |
13d83a67 JB |
8391 | } |
8392 | } | |
8393 | ||
99eb6a01 | 8394 | if (HAS_PCH_IBX(dev)) { |
41aa3448 | 8395 | has_ck505 = dev_priv->vbt.display_clock_mode; |
99eb6a01 KP |
8396 | can_ssc = has_ck505; |
8397 | } else { | |
8398 | has_ck505 = false; | |
8399 | can_ssc = true; | |
8400 | } | |
8401 | ||
1c1a24d2 L |
8402 | /* Check if any DPLLs are using the SSC source */ |
8403 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { | |
8404 | u32 temp = I915_READ(PCH_DPLL(i)); | |
8405 | ||
8406 | if (!(temp & DPLL_VCO_ENABLE)) | |
8407 | continue; | |
8408 | ||
8409 | if ((temp & PLL_REF_INPUT_MASK) == | |
8410 | PLLB_REF_INPUT_SPREADSPECTRUMIN) { | |
8411 | using_ssc_source = true; | |
8412 | break; | |
8413 | } | |
8414 | } | |
8415 | ||
8416 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n", | |
8417 | has_panel, has_lvds, has_ck505, using_ssc_source); | |
13d83a67 JB |
8418 | |
8419 | /* Ironlake: try to setup display ref clock before DPLL | |
8420 | * enabling. This is only under driver's control after | |
8421 | * PCH B stepping, previous chipset stepping should be | |
8422 | * ignoring this setting. | |
8423 | */ | |
74cfd7ac CW |
8424 | val = I915_READ(PCH_DREF_CONTROL); |
8425 | ||
8426 | /* As we must carefully and slowly disable/enable each source in turn, | |
8427 | * compute the final state we want first and check if we need to | |
8428 | * make any changes at all. | |
8429 | */ | |
8430 | final = val; | |
8431 | final &= ~DREF_NONSPREAD_SOURCE_MASK; | |
8432 | if (has_ck505) | |
8433 | final |= DREF_NONSPREAD_CK505_ENABLE; | |
8434 | else | |
8435 | final |= DREF_NONSPREAD_SOURCE_ENABLE; | |
8436 | ||
8c07eb68 | 8437 | final &= ~DREF_SSC_SOURCE_MASK; |
74cfd7ac | 8438 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
8c07eb68 | 8439 | final &= ~DREF_SSC1_ENABLE; |
74cfd7ac CW |
8440 | |
8441 | if (has_panel) { | |
8442 | final |= DREF_SSC_SOURCE_ENABLE; | |
8443 | ||
8444 | if (intel_panel_use_ssc(dev_priv) && can_ssc) | |
8445 | final |= DREF_SSC1_ENABLE; | |
8446 | ||
8447 | if (has_cpu_edp) { | |
8448 | if (intel_panel_use_ssc(dev_priv) && can_ssc) | |
8449 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; | |
8450 | else | |
8451 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; | |
8452 | } else | |
8453 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; | |
1c1a24d2 L |
8454 | } else if (using_ssc_source) { |
8455 | final |= DREF_SSC_SOURCE_ENABLE; | |
8456 | final |= DREF_SSC1_ENABLE; | |
74cfd7ac CW |
8457 | } |
8458 | ||
8459 | if (final == val) | |
8460 | return; | |
8461 | ||
13d83a67 | 8462 | /* Always enable nonspread source */ |
74cfd7ac | 8463 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
13d83a67 | 8464 | |
99eb6a01 | 8465 | if (has_ck505) |
74cfd7ac | 8466 | val |= DREF_NONSPREAD_CK505_ENABLE; |
99eb6a01 | 8467 | else |
74cfd7ac | 8468 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
13d83a67 | 8469 | |
199e5d79 | 8470 | if (has_panel) { |
74cfd7ac CW |
8471 | val &= ~DREF_SSC_SOURCE_MASK; |
8472 | val |= DREF_SSC_SOURCE_ENABLE; | |
13d83a67 | 8473 | |
199e5d79 | 8474 | /* SSC must be turned on before enabling the CPU output */ |
99eb6a01 | 8475 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
199e5d79 | 8476 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
74cfd7ac | 8477 | val |= DREF_SSC1_ENABLE; |
e77166b5 | 8478 | } else |
74cfd7ac | 8479 | val &= ~DREF_SSC1_ENABLE; |
199e5d79 KP |
8480 | |
8481 | /* Get SSC going before enabling the outputs */ | |
74cfd7ac | 8482 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8483 | POSTING_READ(PCH_DREF_CONTROL); |
8484 | udelay(200); | |
8485 | ||
74cfd7ac | 8486 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
13d83a67 JB |
8487 | |
8488 | /* Enable CPU source on CPU attached eDP */ | |
199e5d79 | 8489 | if (has_cpu_edp) { |
99eb6a01 | 8490 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
199e5d79 | 8491 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
74cfd7ac | 8492 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
eba905b2 | 8493 | } else |
74cfd7ac | 8494 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
199e5d79 | 8495 | } else |
74cfd7ac | 8496 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
199e5d79 | 8497 | |
74cfd7ac | 8498 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8499 | POSTING_READ(PCH_DREF_CONTROL); |
8500 | udelay(200); | |
8501 | } else { | |
1c1a24d2 | 8502 | DRM_DEBUG_KMS("Disabling CPU source output\n"); |
199e5d79 | 8503 | |
74cfd7ac | 8504 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
199e5d79 KP |
8505 | |
8506 | /* Turn off CPU output */ | |
74cfd7ac | 8507 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
199e5d79 | 8508 | |
74cfd7ac | 8509 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
8510 | POSTING_READ(PCH_DREF_CONTROL); |
8511 | udelay(200); | |
8512 | ||
1c1a24d2 L |
8513 | if (!using_ssc_source) { |
8514 | DRM_DEBUG_KMS("Disabling SSC source\n"); | |
199e5d79 | 8515 | |
1c1a24d2 L |
8516 | /* Turn off the SSC source */ |
8517 | val &= ~DREF_SSC_SOURCE_MASK; | |
8518 | val |= DREF_SSC_SOURCE_DISABLE; | |
f165d283 | 8519 | |
1c1a24d2 L |
8520 | /* Turn off SSC1 */ |
8521 | val &= ~DREF_SSC1_ENABLE; | |
8522 | ||
8523 | I915_WRITE(PCH_DREF_CONTROL, val); | |
8524 | POSTING_READ(PCH_DREF_CONTROL); | |
8525 | udelay(200); | |
8526 | } | |
13d83a67 | 8527 | } |
74cfd7ac CW |
8528 | |
8529 | BUG_ON(val != final); | |
13d83a67 JB |
8530 | } |
8531 | ||
f31f2d55 | 8532 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
dde86e2d | 8533 | { |
f31f2d55 | 8534 | uint32_t tmp; |
dde86e2d | 8535 | |
0ff066a9 PZ |
8536 | tmp = I915_READ(SOUTH_CHICKEN2); |
8537 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; | |
8538 | I915_WRITE(SOUTH_CHICKEN2, tmp); | |
dde86e2d | 8539 | |
0ff066a9 PZ |
8540 | if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) & |
8541 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) | |
8542 | DRM_ERROR("FDI mPHY reset assert timeout\n"); | |
dde86e2d | 8543 | |
0ff066a9 PZ |
8544 | tmp = I915_READ(SOUTH_CHICKEN2); |
8545 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; | |
8546 | I915_WRITE(SOUTH_CHICKEN2, tmp); | |
dde86e2d | 8547 | |
0ff066a9 PZ |
8548 | if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) & |
8549 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) | |
8550 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); | |
f31f2d55 PZ |
8551 | } |
8552 | ||
8553 | /* WaMPhyProgramming:hsw */ | |
8554 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) | |
8555 | { | |
8556 | uint32_t tmp; | |
dde86e2d PZ |
8557 | |
8558 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); | |
8559 | tmp &= ~(0xFF << 24); | |
8560 | tmp |= (0x12 << 24); | |
8561 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); | |
8562 | ||
dde86e2d PZ |
8563 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
8564 | tmp |= (1 << 11); | |
8565 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); | |
8566 | ||
8567 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); | |
8568 | tmp |= (1 << 11); | |
8569 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); | |
8570 | ||
dde86e2d PZ |
8571 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
8572 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); | |
8573 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); | |
8574 | ||
8575 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); | |
8576 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); | |
8577 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); | |
8578 | ||
0ff066a9 PZ |
8579 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
8580 | tmp &= ~(7 << 13); | |
8581 | tmp |= (5 << 13); | |
8582 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); | |
dde86e2d | 8583 | |
0ff066a9 PZ |
8584 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
8585 | tmp &= ~(7 << 13); | |
8586 | tmp |= (5 << 13); | |
8587 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); | |
dde86e2d PZ |
8588 | |
8589 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); | |
8590 | tmp &= ~0xFF; | |
8591 | tmp |= 0x1C; | |
8592 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); | |
8593 | ||
8594 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); | |
8595 | tmp &= ~0xFF; | |
8596 | tmp |= 0x1C; | |
8597 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); | |
8598 | ||
8599 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); | |
8600 | tmp &= ~(0xFF << 16); | |
8601 | tmp |= (0x1C << 16); | |
8602 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); | |
8603 | ||
8604 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); | |
8605 | tmp &= ~(0xFF << 16); | |
8606 | tmp |= (0x1C << 16); | |
8607 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); | |
8608 | ||
0ff066a9 PZ |
8609 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
8610 | tmp |= (1 << 27); | |
8611 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); | |
dde86e2d | 8612 | |
0ff066a9 PZ |
8613 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
8614 | tmp |= (1 << 27); | |
8615 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); | |
dde86e2d | 8616 | |
0ff066a9 PZ |
8617 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
8618 | tmp &= ~(0xF << 28); | |
8619 | tmp |= (4 << 28); | |
8620 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); | |
dde86e2d | 8621 | |
0ff066a9 PZ |
8622 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
8623 | tmp &= ~(0xF << 28); | |
8624 | tmp |= (4 << 28); | |
8625 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); | |
f31f2d55 PZ |
8626 | } |
8627 | ||
2fa86a1f PZ |
8628 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
8629 | * Programming" based on the parameters passed: | |
8630 | * - Sequence to enable CLKOUT_DP | |
8631 | * - Sequence to enable CLKOUT_DP without spread | |
8632 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O | |
8633 | */ | |
8634 | static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread, | |
8635 | bool with_fdi) | |
f31f2d55 PZ |
8636 | { |
8637 | struct drm_i915_private *dev_priv = dev->dev_private; | |
2fa86a1f PZ |
8638 | uint32_t reg, tmp; |
8639 | ||
8640 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) | |
8641 | with_spread = true; | |
c2699524 | 8642 | if (WARN(HAS_PCH_LPT_LP(dev) && with_fdi, "LP PCH doesn't have FDI\n")) |
2fa86a1f | 8643 | with_fdi = false; |
f31f2d55 | 8644 | |
a580516d | 8645 | mutex_lock(&dev_priv->sb_lock); |
f31f2d55 PZ |
8646 | |
8647 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8648 | tmp &= ~SBI_SSCCTL_DISABLE; | |
8649 | tmp |= SBI_SSCCTL_PATHALT; | |
8650 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8651 | ||
8652 | udelay(24); | |
8653 | ||
2fa86a1f PZ |
8654 | if (with_spread) { |
8655 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8656 | tmp &= ~SBI_SSCCTL_PATHALT; | |
8657 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
f31f2d55 | 8658 | |
2fa86a1f PZ |
8659 | if (with_fdi) { |
8660 | lpt_reset_fdi_mphy(dev_priv); | |
8661 | lpt_program_fdi_mphy(dev_priv); | |
8662 | } | |
8663 | } | |
dde86e2d | 8664 | |
c2699524 | 8665 | reg = HAS_PCH_LPT_LP(dev) ? SBI_GEN0 : SBI_DBUFF0; |
2fa86a1f PZ |
8666 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
8667 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; | |
8668 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); | |
c00db246 | 8669 | |
a580516d | 8670 | mutex_unlock(&dev_priv->sb_lock); |
dde86e2d PZ |
8671 | } |
8672 | ||
47701c3b PZ |
8673 | /* Sequence to disable CLKOUT_DP */ |
8674 | static void lpt_disable_clkout_dp(struct drm_device *dev) | |
8675 | { | |
8676 | struct drm_i915_private *dev_priv = dev->dev_private; | |
8677 | uint32_t reg, tmp; | |
8678 | ||
a580516d | 8679 | mutex_lock(&dev_priv->sb_lock); |
47701c3b | 8680 | |
c2699524 | 8681 | reg = HAS_PCH_LPT_LP(dev) ? SBI_GEN0 : SBI_DBUFF0; |
47701c3b PZ |
8682 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
8683 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; | |
8684 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); | |
8685 | ||
8686 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
8687 | if (!(tmp & SBI_SSCCTL_DISABLE)) { | |
8688 | if (!(tmp & SBI_SSCCTL_PATHALT)) { | |
8689 | tmp |= SBI_SSCCTL_PATHALT; | |
8690 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8691 | udelay(32); | |
8692 | } | |
8693 | tmp |= SBI_SSCCTL_DISABLE; | |
8694 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
8695 | } | |
8696 | ||
a580516d | 8697 | mutex_unlock(&dev_priv->sb_lock); |
47701c3b PZ |
8698 | } |
8699 | ||
f7be2c21 VS |
8700 | #define BEND_IDX(steps) ((50 + (steps)) / 5) |
8701 | ||
8702 | static const uint16_t sscdivintphase[] = { | |
8703 | [BEND_IDX( 50)] = 0x3B23, | |
8704 | [BEND_IDX( 45)] = 0x3B23, | |
8705 | [BEND_IDX( 40)] = 0x3C23, | |
8706 | [BEND_IDX( 35)] = 0x3C23, | |
8707 | [BEND_IDX( 30)] = 0x3D23, | |
8708 | [BEND_IDX( 25)] = 0x3D23, | |
8709 | [BEND_IDX( 20)] = 0x3E23, | |
8710 | [BEND_IDX( 15)] = 0x3E23, | |
8711 | [BEND_IDX( 10)] = 0x3F23, | |
8712 | [BEND_IDX( 5)] = 0x3F23, | |
8713 | [BEND_IDX( 0)] = 0x0025, | |
8714 | [BEND_IDX( -5)] = 0x0025, | |
8715 | [BEND_IDX(-10)] = 0x0125, | |
8716 | [BEND_IDX(-15)] = 0x0125, | |
8717 | [BEND_IDX(-20)] = 0x0225, | |
8718 | [BEND_IDX(-25)] = 0x0225, | |
8719 | [BEND_IDX(-30)] = 0x0325, | |
8720 | [BEND_IDX(-35)] = 0x0325, | |
8721 | [BEND_IDX(-40)] = 0x0425, | |
8722 | [BEND_IDX(-45)] = 0x0425, | |
8723 | [BEND_IDX(-50)] = 0x0525, | |
8724 | }; | |
8725 | ||
8726 | /* | |
8727 | * Bend CLKOUT_DP | |
8728 | * steps -50 to 50 inclusive, in steps of 5 | |
8729 | * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz) | |
8730 | * change in clock period = -(steps / 10) * 5.787 ps | |
8731 | */ | |
8732 | static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps) | |
8733 | { | |
8734 | uint32_t tmp; | |
8735 | int idx = BEND_IDX(steps); | |
8736 | ||
8737 | if (WARN_ON(steps % 5 != 0)) | |
8738 | return; | |
8739 | ||
8740 | if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase))) | |
8741 | return; | |
8742 | ||
8743 | mutex_lock(&dev_priv->sb_lock); | |
8744 | ||
8745 | if (steps % 10 != 0) | |
8746 | tmp = 0xAAAAAAAB; | |
8747 | else | |
8748 | tmp = 0x00000000; | |
8749 | intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK); | |
8750 | ||
8751 | tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK); | |
8752 | tmp &= 0xffff0000; | |
8753 | tmp |= sscdivintphase[idx]; | |
8754 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK); | |
8755 | ||
8756 | mutex_unlock(&dev_priv->sb_lock); | |
8757 | } | |
8758 | ||
8759 | #undef BEND_IDX | |
8760 | ||
bf8fa3d3 PZ |
8761 | static void lpt_init_pch_refclk(struct drm_device *dev) |
8762 | { | |
bf8fa3d3 PZ |
8763 | struct intel_encoder *encoder; |
8764 | bool has_vga = false; | |
8765 | ||
b2784e15 | 8766 | for_each_intel_encoder(dev, encoder) { |
bf8fa3d3 PZ |
8767 | switch (encoder->type) { |
8768 | case INTEL_OUTPUT_ANALOG: | |
8769 | has_vga = true; | |
8770 | break; | |
6847d71b PZ |
8771 | default: |
8772 | break; | |
bf8fa3d3 PZ |
8773 | } |
8774 | } | |
8775 | ||
f7be2c21 VS |
8776 | if (has_vga) { |
8777 | lpt_bend_clkout_dp(to_i915(dev), 0); | |
47701c3b | 8778 | lpt_enable_clkout_dp(dev, true, true); |
f7be2c21 | 8779 | } else { |
47701c3b | 8780 | lpt_disable_clkout_dp(dev); |
f7be2c21 | 8781 | } |
bf8fa3d3 PZ |
8782 | } |
8783 | ||
dde86e2d PZ |
8784 | /* |
8785 | * Initialize reference clocks when the driver loads | |
8786 | */ | |
8787 | void intel_init_pch_refclk(struct drm_device *dev) | |
8788 | { | |
8789 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) | |
8790 | ironlake_init_pch_refclk(dev); | |
8791 | else if (HAS_PCH_LPT(dev)) | |
8792 | lpt_init_pch_refclk(dev); | |
8793 | } | |
8794 | ||
6ff93609 | 8795 | static void ironlake_set_pipeconf(struct drm_crtc *crtc) |
79e53945 | 8796 | { |
c8203565 | 8797 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
79e53945 JB |
8798 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8799 | int pipe = intel_crtc->pipe; | |
c8203565 PZ |
8800 | uint32_t val; |
8801 | ||
78114071 | 8802 | val = 0; |
c8203565 | 8803 | |
6e3c9717 | 8804 | switch (intel_crtc->config->pipe_bpp) { |
c8203565 | 8805 | case 18: |
dfd07d72 | 8806 | val |= PIPECONF_6BPC; |
c8203565 PZ |
8807 | break; |
8808 | case 24: | |
dfd07d72 | 8809 | val |= PIPECONF_8BPC; |
c8203565 PZ |
8810 | break; |
8811 | case 30: | |
dfd07d72 | 8812 | val |= PIPECONF_10BPC; |
c8203565 PZ |
8813 | break; |
8814 | case 36: | |
dfd07d72 | 8815 | val |= PIPECONF_12BPC; |
c8203565 PZ |
8816 | break; |
8817 | default: | |
cc769b62 PZ |
8818 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
8819 | BUG(); | |
c8203565 PZ |
8820 | } |
8821 | ||
6e3c9717 | 8822 | if (intel_crtc->config->dither) |
c8203565 PZ |
8823 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
8824 | ||
6e3c9717 | 8825 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
c8203565 PZ |
8826 | val |= PIPECONF_INTERLACED_ILK; |
8827 | else | |
8828 | val |= PIPECONF_PROGRESSIVE; | |
8829 | ||
6e3c9717 | 8830 | if (intel_crtc->config->limited_color_range) |
3685a8f3 | 8831 | val |= PIPECONF_COLOR_RANGE_SELECT; |
3685a8f3 | 8832 | |
c8203565 PZ |
8833 | I915_WRITE(PIPECONF(pipe), val); |
8834 | POSTING_READ(PIPECONF(pipe)); | |
8835 | } | |
8836 | ||
6ff93609 | 8837 | static void haswell_set_pipeconf(struct drm_crtc *crtc) |
ee2b0b38 | 8838 | { |
391bf048 | 8839 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
ee2b0b38 | 8840 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
6e3c9717 | 8841 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
391bf048 | 8842 | u32 val = 0; |
ee2b0b38 | 8843 | |
391bf048 | 8844 | if (IS_HASWELL(dev_priv) && intel_crtc->config->dither) |
ee2b0b38 PZ |
8845 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
8846 | ||
6e3c9717 | 8847 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
ee2b0b38 PZ |
8848 | val |= PIPECONF_INTERLACED_ILK; |
8849 | else | |
8850 | val |= PIPECONF_PROGRESSIVE; | |
8851 | ||
702e7a56 PZ |
8852 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
8853 | POSTING_READ(PIPECONF(cpu_transcoder)); | |
391bf048 JN |
8854 | } |
8855 | ||
391bf048 JN |
8856 | static void haswell_set_pipemisc(struct drm_crtc *crtc) |
8857 | { | |
8858 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; | |
8859 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
756f85cf | 8860 | |
391bf048 JN |
8861 | if (IS_BROADWELL(dev_priv) || INTEL_INFO(dev_priv)->gen >= 9) { |
8862 | u32 val = 0; | |
756f85cf | 8863 | |
6e3c9717 | 8864 | switch (intel_crtc->config->pipe_bpp) { |
756f85cf PZ |
8865 | case 18: |
8866 | val |= PIPEMISC_DITHER_6_BPC; | |
8867 | break; | |
8868 | case 24: | |
8869 | val |= PIPEMISC_DITHER_8_BPC; | |
8870 | break; | |
8871 | case 30: | |
8872 | val |= PIPEMISC_DITHER_10_BPC; | |
8873 | break; | |
8874 | case 36: | |
8875 | val |= PIPEMISC_DITHER_12_BPC; | |
8876 | break; | |
8877 | default: | |
8878 | /* Case prevented by pipe_config_set_bpp. */ | |
8879 | BUG(); | |
8880 | } | |
8881 | ||
6e3c9717 | 8882 | if (intel_crtc->config->dither) |
756f85cf PZ |
8883 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
8884 | ||
391bf048 | 8885 | I915_WRITE(PIPEMISC(intel_crtc->pipe), val); |
756f85cf | 8886 | } |
ee2b0b38 PZ |
8887 | } |
8888 | ||
d4b1931c PZ |
8889 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
8890 | { | |
8891 | /* | |
8892 | * Account for spread spectrum to avoid | |
8893 | * oversubscribing the link. Max center spread | |
8894 | * is 2.5%; use 5% for safety's sake. | |
8895 | */ | |
8896 | u32 bps = target_clock * bpp * 21 / 20; | |
619d4d04 | 8897 | return DIV_ROUND_UP(bps, link_bw * 8); |
d4b1931c PZ |
8898 | } |
8899 | ||
7429e9d4 | 8900 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
6cf86a5e | 8901 | { |
7429e9d4 | 8902 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
f48d8f23 PZ |
8903 | } |
8904 | ||
b75ca6f6 ACO |
8905 | static void ironlake_compute_dpll(struct intel_crtc *intel_crtc, |
8906 | struct intel_crtc_state *crtc_state, | |
9e2c8475 | 8907 | struct dpll *reduced_clock) |
79e53945 | 8908 | { |
de13a2e3 | 8909 | struct drm_crtc *crtc = &intel_crtc->base; |
79e53945 JB |
8910 | struct drm_device *dev = crtc->dev; |
8911 | struct drm_i915_private *dev_priv = dev->dev_private; | |
55bb9992 | 8912 | struct drm_atomic_state *state = crtc_state->base.state; |
da3ced29 | 8913 | struct drm_connector *connector; |
55bb9992 ACO |
8914 | struct drm_connector_state *connector_state; |
8915 | struct intel_encoder *encoder; | |
b75ca6f6 | 8916 | u32 dpll, fp, fp2; |
ceb41007 | 8917 | int factor, i; |
09ede541 | 8918 | bool is_lvds = false, is_sdvo = false; |
79e53945 | 8919 | |
da3ced29 | 8920 | for_each_connector_in_state(state, connector, connector_state, i) { |
55bb9992 ACO |
8921 | if (connector_state->crtc != crtc_state->base.crtc) |
8922 | continue; | |
8923 | ||
8924 | encoder = to_intel_encoder(connector_state->best_encoder); | |
8925 | ||
8926 | switch (encoder->type) { | |
79e53945 JB |
8927 | case INTEL_OUTPUT_LVDS: |
8928 | is_lvds = true; | |
8929 | break; | |
8930 | case INTEL_OUTPUT_SDVO: | |
7d57382e | 8931 | case INTEL_OUTPUT_HDMI: |
79e53945 | 8932 | is_sdvo = true; |
79e53945 | 8933 | break; |
6847d71b PZ |
8934 | default: |
8935 | break; | |
79e53945 JB |
8936 | } |
8937 | } | |
79e53945 | 8938 | |
c1858123 | 8939 | /* Enable autotuning of the PLL clock (if permissible) */ |
8febb297 EA |
8940 | factor = 21; |
8941 | if (is_lvds) { | |
8942 | if ((intel_panel_use_ssc(dev_priv) && | |
e91e941b | 8943 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
f0b44056 | 8944 | (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev))) |
8febb297 | 8945 | factor = 25; |
190f68c5 | 8946 | } else if (crtc_state->sdvo_tv_clock) |
8febb297 | 8947 | factor = 20; |
c1858123 | 8948 | |
b75ca6f6 ACO |
8949 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
8950 | ||
190f68c5 | 8951 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
b75ca6f6 ACO |
8952 | fp |= FP_CB_TUNE; |
8953 | ||
8954 | if (reduced_clock) { | |
8955 | fp2 = i9xx_dpll_compute_fp(reduced_clock); | |
2c07245f | 8956 | |
b75ca6f6 ACO |
8957 | if (reduced_clock->m < factor * reduced_clock->n) |
8958 | fp2 |= FP_CB_TUNE; | |
8959 | } else { | |
8960 | fp2 = fp; | |
8961 | } | |
9a7c7890 | 8962 | |
5eddb70b | 8963 | dpll = 0; |
2c07245f | 8964 | |
a07d6787 EA |
8965 | if (is_lvds) |
8966 | dpll |= DPLLB_MODE_LVDS; | |
8967 | else | |
8968 | dpll |= DPLLB_MODE_DAC_SERIAL; | |
198a037f | 8969 | |
190f68c5 | 8970 | dpll |= (crtc_state->pixel_multiplier - 1) |
ef1b460d | 8971 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
198a037f DV |
8972 | |
8973 | if (is_sdvo) | |
4a33e48d | 8974 | dpll |= DPLL_SDVO_HIGH_SPEED; |
190f68c5 | 8975 | if (crtc_state->has_dp_encoder) |
4a33e48d | 8976 | dpll |= DPLL_SDVO_HIGH_SPEED; |
79e53945 | 8977 | |
a07d6787 | 8978 | /* compute bitmask from p1 value */ |
190f68c5 | 8979 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
a07d6787 | 8980 | /* also FPA1 */ |
190f68c5 | 8981 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
a07d6787 | 8982 | |
190f68c5 | 8983 | switch (crtc_state->dpll.p2) { |
a07d6787 EA |
8984 | case 5: |
8985 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; | |
8986 | break; | |
8987 | case 7: | |
8988 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; | |
8989 | break; | |
8990 | case 10: | |
8991 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; | |
8992 | break; | |
8993 | case 14: | |
8994 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; | |
8995 | break; | |
79e53945 JB |
8996 | } |
8997 | ||
ceb41007 | 8998 | if (is_lvds && intel_panel_use_ssc(dev_priv)) |
43565a06 | 8999 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
79e53945 JB |
9000 | else |
9001 | dpll |= PLL_REF_INPUT_DREFCLK; | |
9002 | ||
b75ca6f6 ACO |
9003 | dpll |= DPLL_VCO_ENABLE; |
9004 | ||
9005 | crtc_state->dpll_hw_state.dpll = dpll; | |
9006 | crtc_state->dpll_hw_state.fp0 = fp; | |
9007 | crtc_state->dpll_hw_state.fp1 = fp2; | |
de13a2e3 PZ |
9008 | } |
9009 | ||
190f68c5 ACO |
9010 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
9011 | struct intel_crtc_state *crtc_state) | |
de13a2e3 | 9012 | { |
997c030c ACO |
9013 | struct drm_device *dev = crtc->base.dev; |
9014 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9e2c8475 | 9015 | struct dpll reduced_clock; |
7ed9f894 | 9016 | bool has_reduced_clock = false; |
e2b78267 | 9017 | struct intel_shared_dpll *pll; |
1b6f4958 | 9018 | const struct intel_limit *limit; |
997c030c | 9019 | int refclk = 120000; |
de13a2e3 | 9020 | |
dd3cd74a ACO |
9021 | memset(&crtc_state->dpll_hw_state, 0, |
9022 | sizeof(crtc_state->dpll_hw_state)); | |
9023 | ||
ded220e2 ACO |
9024 | crtc->lowfreq_avail = false; |
9025 | ||
9026 | /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */ | |
9027 | if (!crtc_state->has_pch_encoder) | |
9028 | return 0; | |
79e53945 | 9029 | |
997c030c ACO |
9030 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
9031 | if (intel_panel_use_ssc(dev_priv)) { | |
9032 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", | |
9033 | dev_priv->vbt.lvds_ssc_freq); | |
9034 | refclk = dev_priv->vbt.lvds_ssc_freq; | |
9035 | } | |
9036 | ||
9037 | if (intel_is_dual_link_lvds(dev)) { | |
9038 | if (refclk == 100000) | |
9039 | limit = &intel_limits_ironlake_dual_lvds_100m; | |
9040 | else | |
9041 | limit = &intel_limits_ironlake_dual_lvds; | |
9042 | } else { | |
9043 | if (refclk == 100000) | |
9044 | limit = &intel_limits_ironlake_single_lvds_100m; | |
9045 | else | |
9046 | limit = &intel_limits_ironlake_single_lvds; | |
9047 | } | |
9048 | } else { | |
9049 | limit = &intel_limits_ironlake_dac; | |
9050 | } | |
9051 | ||
364ee29d | 9052 | if (!crtc_state->clock_set && |
997c030c ACO |
9053 | !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
9054 | refclk, NULL, &crtc_state->dpll)) { | |
364ee29d ACO |
9055 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
9056 | return -EINVAL; | |
f47709a9 | 9057 | } |
79e53945 | 9058 | |
b75ca6f6 ACO |
9059 | ironlake_compute_dpll(crtc, crtc_state, |
9060 | has_reduced_clock ? &reduced_clock : NULL); | |
66e985c0 | 9061 | |
ded220e2 ACO |
9062 | pll = intel_get_shared_dpll(crtc, crtc_state, NULL); |
9063 | if (pll == NULL) { | |
9064 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", | |
9065 | pipe_name(crtc->pipe)); | |
9066 | return -EINVAL; | |
3fb37703 | 9067 | } |
79e53945 | 9068 | |
ded220e2 ACO |
9069 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
9070 | has_reduced_clock) | |
c7653199 | 9071 | crtc->lowfreq_avail = true; |
e2b78267 | 9072 | |
c8f7a0db | 9073 | return 0; |
79e53945 JB |
9074 | } |
9075 | ||
eb14cb74 VS |
9076 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
9077 | struct intel_link_m_n *m_n) | |
9078 | { | |
9079 | struct drm_device *dev = crtc->base.dev; | |
9080 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9081 | enum pipe pipe = crtc->pipe; | |
9082 | ||
9083 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); | |
9084 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); | |
9085 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) | |
9086 | & ~TU_SIZE_MASK; | |
9087 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); | |
9088 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) | |
9089 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
9090 | } | |
9091 | ||
9092 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, | |
9093 | enum transcoder transcoder, | |
b95af8be VK |
9094 | struct intel_link_m_n *m_n, |
9095 | struct intel_link_m_n *m2_n2) | |
72419203 DV |
9096 | { |
9097 | struct drm_device *dev = crtc->base.dev; | |
9098 | struct drm_i915_private *dev_priv = dev->dev_private; | |
eb14cb74 | 9099 | enum pipe pipe = crtc->pipe; |
72419203 | 9100 | |
eb14cb74 VS |
9101 | if (INTEL_INFO(dev)->gen >= 5) { |
9102 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); | |
9103 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); | |
9104 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) | |
9105 | & ~TU_SIZE_MASK; | |
9106 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); | |
9107 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) | |
9108 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
b95af8be VK |
9109 | /* Read M2_N2 registers only for gen < 8 (M2_N2 available for |
9110 | * gen < 8) and if DRRS is supported (to make sure the | |
9111 | * registers are not unnecessarily read). | |
9112 | */ | |
9113 | if (m2_n2 && INTEL_INFO(dev)->gen < 8 && | |
6e3c9717 | 9114 | crtc->config->has_drrs) { |
b95af8be VK |
9115 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
9116 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); | |
9117 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) | |
9118 | & ~TU_SIZE_MASK; | |
9119 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); | |
9120 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) | |
9121 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
9122 | } | |
eb14cb74 VS |
9123 | } else { |
9124 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); | |
9125 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); | |
9126 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) | |
9127 | & ~TU_SIZE_MASK; | |
9128 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); | |
9129 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) | |
9130 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
9131 | } | |
9132 | } | |
9133 | ||
9134 | void intel_dp_get_m_n(struct intel_crtc *crtc, | |
5cec258b | 9135 | struct intel_crtc_state *pipe_config) |
eb14cb74 | 9136 | { |
681a8504 | 9137 | if (pipe_config->has_pch_encoder) |
eb14cb74 VS |
9138 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
9139 | else | |
9140 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, | |
b95af8be VK |
9141 | &pipe_config->dp_m_n, |
9142 | &pipe_config->dp_m2_n2); | |
eb14cb74 | 9143 | } |
72419203 | 9144 | |
eb14cb74 | 9145 | static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc, |
5cec258b | 9146 | struct intel_crtc_state *pipe_config) |
eb14cb74 VS |
9147 | { |
9148 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, | |
b95af8be | 9149 | &pipe_config->fdi_m_n, NULL); |
72419203 DV |
9150 | } |
9151 | ||
bd2e244f | 9152 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 9153 | struct intel_crtc_state *pipe_config) |
bd2e244f JB |
9154 | { |
9155 | struct drm_device *dev = crtc->base.dev; | |
9156 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a1b2278e CK |
9157 | struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state; |
9158 | uint32_t ps_ctrl = 0; | |
9159 | int id = -1; | |
9160 | int i; | |
bd2e244f | 9161 | |
a1b2278e CK |
9162 | /* find scaler attached to this pipe */ |
9163 | for (i = 0; i < crtc->num_scalers; i++) { | |
9164 | ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i)); | |
9165 | if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) { | |
9166 | id = i; | |
9167 | pipe_config->pch_pfit.enabled = true; | |
9168 | pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i)); | |
9169 | pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i)); | |
9170 | break; | |
9171 | } | |
9172 | } | |
bd2e244f | 9173 | |
a1b2278e CK |
9174 | scaler_state->scaler_id = id; |
9175 | if (id >= 0) { | |
9176 | scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX); | |
9177 | } else { | |
9178 | scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX); | |
bd2e244f JB |
9179 | } |
9180 | } | |
9181 | ||
5724dbd1 DL |
9182 | static void |
9183 | skylake_get_initial_plane_config(struct intel_crtc *crtc, | |
9184 | struct intel_initial_plane_config *plane_config) | |
bc8d7dff DL |
9185 | { |
9186 | struct drm_device *dev = crtc->base.dev; | |
9187 | struct drm_i915_private *dev_priv = dev->dev_private; | |
40f46283 | 9188 | u32 val, base, offset, stride_mult, tiling; |
bc8d7dff DL |
9189 | int pipe = crtc->pipe; |
9190 | int fourcc, pixel_format; | |
6761dd31 | 9191 | unsigned int aligned_height; |
bc8d7dff | 9192 | struct drm_framebuffer *fb; |
1b842c89 | 9193 | struct intel_framebuffer *intel_fb; |
bc8d7dff | 9194 | |
d9806c9f | 9195 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 9196 | if (!intel_fb) { |
bc8d7dff DL |
9197 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
9198 | return; | |
9199 | } | |
9200 | ||
1b842c89 DL |
9201 | fb = &intel_fb->base; |
9202 | ||
bc8d7dff | 9203 | val = I915_READ(PLANE_CTL(pipe, 0)); |
42a7b088 DL |
9204 | if (!(val & PLANE_CTL_ENABLE)) |
9205 | goto error; | |
9206 | ||
bc8d7dff DL |
9207 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
9208 | fourcc = skl_format_to_fourcc(pixel_format, | |
9209 | val & PLANE_CTL_ORDER_RGBX, | |
9210 | val & PLANE_CTL_ALPHA_MASK); | |
9211 | fb->pixel_format = fourcc; | |
9212 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
9213 | ||
40f46283 DL |
9214 | tiling = val & PLANE_CTL_TILED_MASK; |
9215 | switch (tiling) { | |
9216 | case PLANE_CTL_TILED_LINEAR: | |
9217 | fb->modifier[0] = DRM_FORMAT_MOD_NONE; | |
9218 | break; | |
9219 | case PLANE_CTL_TILED_X: | |
9220 | plane_config->tiling = I915_TILING_X; | |
9221 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; | |
9222 | break; | |
9223 | case PLANE_CTL_TILED_Y: | |
9224 | fb->modifier[0] = I915_FORMAT_MOD_Y_TILED; | |
9225 | break; | |
9226 | case PLANE_CTL_TILED_YF: | |
9227 | fb->modifier[0] = I915_FORMAT_MOD_Yf_TILED; | |
9228 | break; | |
9229 | default: | |
9230 | MISSING_CASE(tiling); | |
9231 | goto error; | |
9232 | } | |
9233 | ||
bc8d7dff DL |
9234 | base = I915_READ(PLANE_SURF(pipe, 0)) & 0xfffff000; |
9235 | plane_config->base = base; | |
9236 | ||
9237 | offset = I915_READ(PLANE_OFFSET(pipe, 0)); | |
9238 | ||
9239 | val = I915_READ(PLANE_SIZE(pipe, 0)); | |
9240 | fb->height = ((val >> 16) & 0xfff) + 1; | |
9241 | fb->width = ((val >> 0) & 0x1fff) + 1; | |
9242 | ||
9243 | val = I915_READ(PLANE_STRIDE(pipe, 0)); | |
7b49f948 | 9244 | stride_mult = intel_fb_stride_alignment(dev_priv, fb->modifier[0], |
40f46283 | 9245 | fb->pixel_format); |
bc8d7dff DL |
9246 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
9247 | ||
9248 | aligned_height = intel_fb_align_height(dev, fb->height, | |
091df6cb DV |
9249 | fb->pixel_format, |
9250 | fb->modifier[0]); | |
bc8d7dff | 9251 | |
f37b5c2b | 9252 | plane_config->size = fb->pitches[0] * aligned_height; |
bc8d7dff DL |
9253 | |
9254 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", | |
9255 | pipe_name(pipe), fb->width, fb->height, | |
9256 | fb->bits_per_pixel, base, fb->pitches[0], | |
9257 | plane_config->size); | |
9258 | ||
2d14030b | 9259 | plane_config->fb = intel_fb; |
bc8d7dff DL |
9260 | return; |
9261 | ||
9262 | error: | |
9263 | kfree(fb); | |
9264 | } | |
9265 | ||
2fa2fe9a | 9266 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 9267 | struct intel_crtc_state *pipe_config) |
2fa2fe9a DV |
9268 | { |
9269 | struct drm_device *dev = crtc->base.dev; | |
9270 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9271 | uint32_t tmp; | |
9272 | ||
9273 | tmp = I915_READ(PF_CTL(crtc->pipe)); | |
9274 | ||
9275 | if (tmp & PF_ENABLE) { | |
fd4daa9c | 9276 | pipe_config->pch_pfit.enabled = true; |
2fa2fe9a DV |
9277 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
9278 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); | |
cb8b2a30 DV |
9279 | |
9280 | /* We currently do not free assignements of panel fitters on | |
9281 | * ivb/hsw (since we don't use the higher upscaling modes which | |
9282 | * differentiates them) so just WARN about this case for now. */ | |
9283 | if (IS_GEN7(dev)) { | |
9284 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != | |
9285 | PF_PIPE_SEL_IVB(crtc->pipe)); | |
9286 | } | |
2fa2fe9a | 9287 | } |
79e53945 JB |
9288 | } |
9289 | ||
5724dbd1 DL |
9290 | static void |
9291 | ironlake_get_initial_plane_config(struct intel_crtc *crtc, | |
9292 | struct intel_initial_plane_config *plane_config) | |
4c6baa59 JB |
9293 | { |
9294 | struct drm_device *dev = crtc->base.dev; | |
9295 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9296 | u32 val, base, offset; | |
aeee5a49 | 9297 | int pipe = crtc->pipe; |
4c6baa59 | 9298 | int fourcc, pixel_format; |
6761dd31 | 9299 | unsigned int aligned_height; |
b113d5ee | 9300 | struct drm_framebuffer *fb; |
1b842c89 | 9301 | struct intel_framebuffer *intel_fb; |
4c6baa59 | 9302 | |
42a7b088 DL |
9303 | val = I915_READ(DSPCNTR(pipe)); |
9304 | if (!(val & DISPLAY_PLANE_ENABLE)) | |
9305 | return; | |
9306 | ||
d9806c9f | 9307 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 9308 | if (!intel_fb) { |
4c6baa59 JB |
9309 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
9310 | return; | |
9311 | } | |
9312 | ||
1b842c89 DL |
9313 | fb = &intel_fb->base; |
9314 | ||
18c5247e DV |
9315 | if (INTEL_INFO(dev)->gen >= 4) { |
9316 | if (val & DISPPLANE_TILED) { | |
49af449b | 9317 | plane_config->tiling = I915_TILING_X; |
18c5247e DV |
9318 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
9319 | } | |
9320 | } | |
4c6baa59 JB |
9321 | |
9322 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; | |
b35d63fa | 9323 | fourcc = i9xx_format_to_fourcc(pixel_format); |
b113d5ee DL |
9324 | fb->pixel_format = fourcc; |
9325 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; | |
4c6baa59 | 9326 | |
aeee5a49 | 9327 | base = I915_READ(DSPSURF(pipe)) & 0xfffff000; |
4c6baa59 | 9328 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
aeee5a49 | 9329 | offset = I915_READ(DSPOFFSET(pipe)); |
4c6baa59 | 9330 | } else { |
49af449b | 9331 | if (plane_config->tiling) |
aeee5a49 | 9332 | offset = I915_READ(DSPTILEOFF(pipe)); |
4c6baa59 | 9333 | else |
aeee5a49 | 9334 | offset = I915_READ(DSPLINOFF(pipe)); |
4c6baa59 JB |
9335 | } |
9336 | plane_config->base = base; | |
9337 | ||
9338 | val = I915_READ(PIPESRC(pipe)); | |
b113d5ee DL |
9339 | fb->width = ((val >> 16) & 0xfff) + 1; |
9340 | fb->height = ((val >> 0) & 0xfff) + 1; | |
4c6baa59 JB |
9341 | |
9342 | val = I915_READ(DSPSTRIDE(pipe)); | |
b113d5ee | 9343 | fb->pitches[0] = val & 0xffffffc0; |
4c6baa59 | 9344 | |
b113d5ee | 9345 | aligned_height = intel_fb_align_height(dev, fb->height, |
091df6cb DV |
9346 | fb->pixel_format, |
9347 | fb->modifier[0]); | |
4c6baa59 | 9348 | |
f37b5c2b | 9349 | plane_config->size = fb->pitches[0] * aligned_height; |
4c6baa59 | 9350 | |
2844a921 DL |
9351 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
9352 | pipe_name(pipe), fb->width, fb->height, | |
9353 | fb->bits_per_pixel, base, fb->pitches[0], | |
9354 | plane_config->size); | |
b113d5ee | 9355 | |
2d14030b | 9356 | plane_config->fb = intel_fb; |
4c6baa59 JB |
9357 | } |
9358 | ||
0e8ffe1b | 9359 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 9360 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
9361 | { |
9362 | struct drm_device *dev = crtc->base.dev; | |
9363 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1729050e | 9364 | enum intel_display_power_domain power_domain; |
0e8ffe1b | 9365 | uint32_t tmp; |
1729050e | 9366 | bool ret; |
0e8ffe1b | 9367 | |
1729050e ID |
9368 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
9369 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) | |
930e8c9e PZ |
9370 | return false; |
9371 | ||
e143a21c | 9372 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
8106ddbd | 9373 | pipe_config->shared_dpll = NULL; |
eccb140b | 9374 | |
1729050e | 9375 | ret = false; |
0e8ffe1b DV |
9376 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
9377 | if (!(tmp & PIPECONF_ENABLE)) | |
1729050e | 9378 | goto out; |
0e8ffe1b | 9379 | |
42571aef VS |
9380 | switch (tmp & PIPECONF_BPC_MASK) { |
9381 | case PIPECONF_6BPC: | |
9382 | pipe_config->pipe_bpp = 18; | |
9383 | break; | |
9384 | case PIPECONF_8BPC: | |
9385 | pipe_config->pipe_bpp = 24; | |
9386 | break; | |
9387 | case PIPECONF_10BPC: | |
9388 | pipe_config->pipe_bpp = 30; | |
9389 | break; | |
9390 | case PIPECONF_12BPC: | |
9391 | pipe_config->pipe_bpp = 36; | |
9392 | break; | |
9393 | default: | |
9394 | break; | |
9395 | } | |
9396 | ||
b5a9fa09 DV |
9397 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
9398 | pipe_config->limited_color_range = true; | |
9399 | ||
ab9412ba | 9400 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
66e985c0 | 9401 | struct intel_shared_dpll *pll; |
8106ddbd | 9402 | enum intel_dpll_id pll_id; |
66e985c0 | 9403 | |
88adfff1 DV |
9404 | pipe_config->has_pch_encoder = true; |
9405 | ||
627eb5a3 DV |
9406 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
9407 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> | |
9408 | FDI_DP_PORT_WIDTH_SHIFT) + 1; | |
72419203 DV |
9409 | |
9410 | ironlake_get_fdi_m_n_config(crtc, pipe_config); | |
6c49f241 | 9411 | |
2d1fe073 | 9412 | if (HAS_PCH_IBX(dev_priv)) { |
d9a7bc67 ID |
9413 | /* |
9414 | * The pipe->pch transcoder and pch transcoder->pll | |
9415 | * mapping is fixed. | |
9416 | */ | |
8106ddbd | 9417 | pll_id = (enum intel_dpll_id) crtc->pipe; |
c0d43d62 DV |
9418 | } else { |
9419 | tmp = I915_READ(PCH_DPLL_SEL); | |
9420 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) | |
8106ddbd | 9421 | pll_id = DPLL_ID_PCH_PLL_B; |
c0d43d62 | 9422 | else |
8106ddbd | 9423 | pll_id= DPLL_ID_PCH_PLL_A; |
c0d43d62 | 9424 | } |
66e985c0 | 9425 | |
8106ddbd ACO |
9426 | pipe_config->shared_dpll = |
9427 | intel_get_shared_dpll_by_id(dev_priv, pll_id); | |
9428 | pll = pipe_config->shared_dpll; | |
66e985c0 | 9429 | |
2edd6443 ACO |
9430 | WARN_ON(!pll->funcs.get_hw_state(dev_priv, pll, |
9431 | &pipe_config->dpll_hw_state)); | |
c93f54cf DV |
9432 | |
9433 | tmp = pipe_config->dpll_hw_state.dpll; | |
9434 | pipe_config->pixel_multiplier = | |
9435 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) | |
9436 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; | |
18442d08 VS |
9437 | |
9438 | ironlake_pch_clock_get(crtc, pipe_config); | |
6c49f241 DV |
9439 | } else { |
9440 | pipe_config->pixel_multiplier = 1; | |
627eb5a3 DV |
9441 | } |
9442 | ||
1bd1bd80 | 9443 | intel_get_pipe_timings(crtc, pipe_config); |
bc58be60 | 9444 | intel_get_pipe_src_size(crtc, pipe_config); |
1bd1bd80 | 9445 | |
2fa2fe9a DV |
9446 | ironlake_get_pfit_config(crtc, pipe_config); |
9447 | ||
1729050e ID |
9448 | ret = true; |
9449 | ||
9450 | out: | |
9451 | intel_display_power_put(dev_priv, power_domain); | |
9452 | ||
9453 | return ret; | |
0e8ffe1b DV |
9454 | } |
9455 | ||
be256dc7 PZ |
9456 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
9457 | { | |
9458 | struct drm_device *dev = dev_priv->dev; | |
be256dc7 | 9459 | struct intel_crtc *crtc; |
be256dc7 | 9460 | |
d3fcc808 | 9461 | for_each_intel_crtc(dev, crtc) |
e2c719b7 | 9462 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
be256dc7 PZ |
9463 | pipe_name(crtc->pipe)); |
9464 | ||
e2c719b7 RC |
9465 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n"); |
9466 | I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n"); | |
01403de3 VS |
9467 | I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); |
9468 | I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n"); | |
e2c719b7 RC |
9469 | I915_STATE_WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n"); |
9470 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, | |
be256dc7 | 9471 | "CPU PWM1 enabled\n"); |
c5107b87 | 9472 | if (IS_HASWELL(dev)) |
e2c719b7 | 9473 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
c5107b87 | 9474 | "CPU PWM2 enabled\n"); |
e2c719b7 | 9475 | I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE, |
be256dc7 | 9476 | "PCH PWM1 enabled\n"); |
e2c719b7 | 9477 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
be256dc7 | 9478 | "Utility pin enabled\n"); |
e2c719b7 | 9479 | I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n"); |
be256dc7 | 9480 | |
9926ada1 PZ |
9481 | /* |
9482 | * In theory we can still leave IRQs enabled, as long as only the HPD | |
9483 | * interrupts remain enabled. We used to check for that, but since it's | |
9484 | * gen-specific and since we only disable LCPLL after we fully disable | |
9485 | * the interrupts, the check below should be enough. | |
9486 | */ | |
e2c719b7 | 9487 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
be256dc7 PZ |
9488 | } |
9489 | ||
9ccd5aeb PZ |
9490 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) |
9491 | { | |
9492 | struct drm_device *dev = dev_priv->dev; | |
9493 | ||
9494 | if (IS_HASWELL(dev)) | |
9495 | return I915_READ(D_COMP_HSW); | |
9496 | else | |
9497 | return I915_READ(D_COMP_BDW); | |
9498 | } | |
9499 | ||
3c4c9b81 PZ |
9500 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) |
9501 | { | |
9502 | struct drm_device *dev = dev_priv->dev; | |
9503 | ||
9504 | if (IS_HASWELL(dev)) { | |
9505 | mutex_lock(&dev_priv->rps.hw_lock); | |
9506 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, | |
9507 | val)) | |
f475dadf | 9508 | DRM_ERROR("Failed to write to D_COMP\n"); |
3c4c9b81 PZ |
9509 | mutex_unlock(&dev_priv->rps.hw_lock); |
9510 | } else { | |
9ccd5aeb PZ |
9511 | I915_WRITE(D_COMP_BDW, val); |
9512 | POSTING_READ(D_COMP_BDW); | |
3c4c9b81 | 9513 | } |
be256dc7 PZ |
9514 | } |
9515 | ||
9516 | /* | |
9517 | * This function implements pieces of two sequences from BSpec: | |
9518 | * - Sequence for display software to disable LCPLL | |
9519 | * - Sequence for display software to allow package C8+ | |
9520 | * The steps implemented here are just the steps that actually touch the LCPLL | |
9521 | * register. Callers should take care of disabling all the display engine | |
9522 | * functions, doing the mode unset, fixing interrupts, etc. | |
9523 | */ | |
6ff58d53 PZ |
9524 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
9525 | bool switch_to_fclk, bool allow_power_down) | |
be256dc7 PZ |
9526 | { |
9527 | uint32_t val; | |
9528 | ||
9529 | assert_can_disable_lcpll(dev_priv); | |
9530 | ||
9531 | val = I915_READ(LCPLL_CTL); | |
9532 | ||
9533 | if (switch_to_fclk) { | |
9534 | val |= LCPLL_CD_SOURCE_FCLK; | |
9535 | I915_WRITE(LCPLL_CTL, val); | |
9536 | ||
9537 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & | |
9538 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) | |
9539 | DRM_ERROR("Switching to FCLK failed\n"); | |
9540 | ||
9541 | val = I915_READ(LCPLL_CTL); | |
9542 | } | |
9543 | ||
9544 | val |= LCPLL_PLL_DISABLE; | |
9545 | I915_WRITE(LCPLL_CTL, val); | |
9546 | POSTING_READ(LCPLL_CTL); | |
9547 | ||
9548 | if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1)) | |
9549 | DRM_ERROR("LCPLL still locked\n"); | |
9550 | ||
9ccd5aeb | 9551 | val = hsw_read_dcomp(dev_priv); |
be256dc7 | 9552 | val |= D_COMP_COMP_DISABLE; |
3c4c9b81 | 9553 | hsw_write_dcomp(dev_priv, val); |
be256dc7 PZ |
9554 | ndelay(100); |
9555 | ||
9ccd5aeb PZ |
9556 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
9557 | 1)) | |
be256dc7 PZ |
9558 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
9559 | ||
9560 | if (allow_power_down) { | |
9561 | val = I915_READ(LCPLL_CTL); | |
9562 | val |= LCPLL_POWER_DOWN_ALLOW; | |
9563 | I915_WRITE(LCPLL_CTL, val); | |
9564 | POSTING_READ(LCPLL_CTL); | |
9565 | } | |
9566 | } | |
9567 | ||
9568 | /* | |
9569 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL | |
9570 | * source. | |
9571 | */ | |
6ff58d53 | 9572 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
be256dc7 PZ |
9573 | { |
9574 | uint32_t val; | |
9575 | ||
9576 | val = I915_READ(LCPLL_CTL); | |
9577 | ||
9578 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | | |
9579 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) | |
9580 | return; | |
9581 | ||
a8a8bd54 PZ |
9582 | /* |
9583 | * Make sure we're not on PC8 state before disabling PC8, otherwise | |
9584 | * we'll hang the machine. To prevent PC8 state, just enable force_wake. | |
a8a8bd54 | 9585 | */ |
59bad947 | 9586 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
215733fa | 9587 | |
be256dc7 PZ |
9588 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
9589 | val &= ~LCPLL_POWER_DOWN_ALLOW; | |
9590 | I915_WRITE(LCPLL_CTL, val); | |
35d8f2eb | 9591 | POSTING_READ(LCPLL_CTL); |
be256dc7 PZ |
9592 | } |
9593 | ||
9ccd5aeb | 9594 | val = hsw_read_dcomp(dev_priv); |
be256dc7 PZ |
9595 | val |= D_COMP_COMP_FORCE; |
9596 | val &= ~D_COMP_COMP_DISABLE; | |
3c4c9b81 | 9597 | hsw_write_dcomp(dev_priv, val); |
be256dc7 PZ |
9598 | |
9599 | val = I915_READ(LCPLL_CTL); | |
9600 | val &= ~LCPLL_PLL_DISABLE; | |
9601 | I915_WRITE(LCPLL_CTL, val); | |
9602 | ||
9603 | if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5)) | |
9604 | DRM_ERROR("LCPLL not locked yet\n"); | |
9605 | ||
9606 | if (val & LCPLL_CD_SOURCE_FCLK) { | |
9607 | val = I915_READ(LCPLL_CTL); | |
9608 | val &= ~LCPLL_CD_SOURCE_FCLK; | |
9609 | I915_WRITE(LCPLL_CTL, val); | |
9610 | ||
9611 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & | |
9612 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) | |
9613 | DRM_ERROR("Switching back to LCPLL failed\n"); | |
9614 | } | |
215733fa | 9615 | |
59bad947 | 9616 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
b6283055 | 9617 | intel_update_cdclk(dev_priv->dev); |
be256dc7 PZ |
9618 | } |
9619 | ||
765dab67 PZ |
9620 | /* |
9621 | * Package states C8 and deeper are really deep PC states that can only be | |
9622 | * reached when all the devices on the system allow it, so even if the graphics | |
9623 | * device allows PC8+, it doesn't mean the system will actually get to these | |
9624 | * states. Our driver only allows PC8+ when going into runtime PM. | |
9625 | * | |
9626 | * The requirements for PC8+ are that all the outputs are disabled, the power | |
9627 | * well is disabled and most interrupts are disabled, and these are also | |
9628 | * requirements for runtime PM. When these conditions are met, we manually do | |
9629 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk | |
9630 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard | |
9631 | * hang the machine. | |
9632 | * | |
9633 | * When we really reach PC8 or deeper states (not just when we allow it) we lose | |
9634 | * the state of some registers, so when we come back from PC8+ we need to | |
9635 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't | |
9636 | * need to take care of the registers kept by RC6. Notice that this happens even | |
9637 | * if we don't put the device in PCI D3 state (which is what currently happens | |
9638 | * because of the runtime PM support). | |
9639 | * | |
9640 | * For more, read "Display Sequences for Package C8" on the hardware | |
9641 | * documentation. | |
9642 | */ | |
a14cb6fc | 9643 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
c67a470b | 9644 | { |
c67a470b PZ |
9645 | struct drm_device *dev = dev_priv->dev; |
9646 | uint32_t val; | |
9647 | ||
c67a470b PZ |
9648 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
9649 | ||
c2699524 | 9650 | if (HAS_PCH_LPT_LP(dev)) { |
c67a470b PZ |
9651 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
9652 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; | |
9653 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); | |
9654 | } | |
9655 | ||
9656 | lpt_disable_clkout_dp(dev); | |
c67a470b PZ |
9657 | hsw_disable_lcpll(dev_priv, true, true); |
9658 | } | |
9659 | ||
a14cb6fc | 9660 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
c67a470b PZ |
9661 | { |
9662 | struct drm_device *dev = dev_priv->dev; | |
9663 | uint32_t val; | |
9664 | ||
c67a470b PZ |
9665 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
9666 | ||
9667 | hsw_restore_lcpll(dev_priv); | |
c67a470b PZ |
9668 | lpt_init_pch_refclk(dev); |
9669 | ||
c2699524 | 9670 | if (HAS_PCH_LPT_LP(dev)) { |
c67a470b PZ |
9671 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
9672 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; | |
9673 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); | |
9674 | } | |
c67a470b PZ |
9675 | } |
9676 | ||
324513c0 | 9677 | static void bxt_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
f8437dd1 | 9678 | { |
a821fc46 | 9679 | struct drm_device *dev = old_state->dev; |
1a617b77 ML |
9680 | struct intel_atomic_state *old_intel_state = |
9681 | to_intel_atomic_state(old_state); | |
9682 | unsigned int req_cdclk = old_intel_state->dev_cdclk; | |
f8437dd1 | 9683 | |
324513c0 | 9684 | bxt_set_cdclk(to_i915(dev), req_cdclk); |
f8437dd1 VK |
9685 | } |
9686 | ||
b432e5cf | 9687 | /* compute the max rate for new configuration */ |
27c329ed | 9688 | static int ilk_max_pixel_rate(struct drm_atomic_state *state) |
b432e5cf | 9689 | { |
565602d7 ML |
9690 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
9691 | struct drm_i915_private *dev_priv = state->dev->dev_private; | |
9692 | struct drm_crtc *crtc; | |
9693 | struct drm_crtc_state *cstate; | |
27c329ed | 9694 | struct intel_crtc_state *crtc_state; |
565602d7 ML |
9695 | unsigned max_pixel_rate = 0, i; |
9696 | enum pipe pipe; | |
b432e5cf | 9697 | |
565602d7 ML |
9698 | memcpy(intel_state->min_pixclk, dev_priv->min_pixclk, |
9699 | sizeof(intel_state->min_pixclk)); | |
27c329ed | 9700 | |
565602d7 ML |
9701 | for_each_crtc_in_state(state, crtc, cstate, i) { |
9702 | int pixel_rate; | |
27c329ed | 9703 | |
565602d7 ML |
9704 | crtc_state = to_intel_crtc_state(cstate); |
9705 | if (!crtc_state->base.enable) { | |
9706 | intel_state->min_pixclk[i] = 0; | |
b432e5cf | 9707 | continue; |
565602d7 | 9708 | } |
b432e5cf | 9709 | |
27c329ed | 9710 | pixel_rate = ilk_pipe_pixel_rate(crtc_state); |
b432e5cf VS |
9711 | |
9712 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ | |
565602d7 | 9713 | if (IS_BROADWELL(dev_priv) && crtc_state->ips_enabled) |
b432e5cf VS |
9714 | pixel_rate = DIV_ROUND_UP(pixel_rate * 100, 95); |
9715 | ||
565602d7 | 9716 | intel_state->min_pixclk[i] = pixel_rate; |
b432e5cf VS |
9717 | } |
9718 | ||
565602d7 ML |
9719 | for_each_pipe(dev_priv, pipe) |
9720 | max_pixel_rate = max(intel_state->min_pixclk[pipe], max_pixel_rate); | |
9721 | ||
b432e5cf VS |
9722 | return max_pixel_rate; |
9723 | } | |
9724 | ||
9725 | static void broadwell_set_cdclk(struct drm_device *dev, int cdclk) | |
9726 | { | |
9727 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9728 | uint32_t val, data; | |
9729 | int ret; | |
9730 | ||
9731 | if (WARN((I915_READ(LCPLL_CTL) & | |
9732 | (LCPLL_PLL_DISABLE | LCPLL_PLL_LOCK | | |
9733 | LCPLL_CD_CLOCK_DISABLE | LCPLL_ROOT_CD_CLOCK_DISABLE | | |
9734 | LCPLL_CD2X_CLOCK_DISABLE | LCPLL_POWER_DOWN_ALLOW | | |
9735 | LCPLL_CD_SOURCE_FCLK)) != LCPLL_PLL_LOCK, | |
9736 | "trying to change cdclk frequency with cdclk not enabled\n")) | |
9737 | return; | |
9738 | ||
9739 | mutex_lock(&dev_priv->rps.hw_lock); | |
9740 | ret = sandybridge_pcode_write(dev_priv, | |
9741 | BDW_PCODE_DISPLAY_FREQ_CHANGE_REQ, 0x0); | |
9742 | mutex_unlock(&dev_priv->rps.hw_lock); | |
9743 | if (ret) { | |
9744 | DRM_ERROR("failed to inform pcode about cdclk change\n"); | |
9745 | return; | |
9746 | } | |
9747 | ||
9748 | val = I915_READ(LCPLL_CTL); | |
9749 | val |= LCPLL_CD_SOURCE_FCLK; | |
9750 | I915_WRITE(LCPLL_CTL, val); | |
9751 | ||
5ba00178 TU |
9752 | if (wait_for_us(I915_READ(LCPLL_CTL) & |
9753 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) | |
b432e5cf VS |
9754 | DRM_ERROR("Switching to FCLK failed\n"); |
9755 | ||
9756 | val = I915_READ(LCPLL_CTL); | |
9757 | val &= ~LCPLL_CLK_FREQ_MASK; | |
9758 | ||
9759 | switch (cdclk) { | |
9760 | case 450000: | |
9761 | val |= LCPLL_CLK_FREQ_450; | |
9762 | data = 0; | |
9763 | break; | |
9764 | case 540000: | |
9765 | val |= LCPLL_CLK_FREQ_54O_BDW; | |
9766 | data = 1; | |
9767 | break; | |
9768 | case 337500: | |
9769 | val |= LCPLL_CLK_FREQ_337_5_BDW; | |
9770 | data = 2; | |
9771 | break; | |
9772 | case 675000: | |
9773 | val |= LCPLL_CLK_FREQ_675_BDW; | |
9774 | data = 3; | |
9775 | break; | |
9776 | default: | |
9777 | WARN(1, "invalid cdclk frequency\n"); | |
9778 | return; | |
9779 | } | |
9780 | ||
9781 | I915_WRITE(LCPLL_CTL, val); | |
9782 | ||
9783 | val = I915_READ(LCPLL_CTL); | |
9784 | val &= ~LCPLL_CD_SOURCE_FCLK; | |
9785 | I915_WRITE(LCPLL_CTL, val); | |
9786 | ||
5ba00178 TU |
9787 | if (wait_for_us((I915_READ(LCPLL_CTL) & |
9788 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) | |
b432e5cf VS |
9789 | DRM_ERROR("Switching back to LCPLL failed\n"); |
9790 | ||
9791 | mutex_lock(&dev_priv->rps.hw_lock); | |
9792 | sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, data); | |
9793 | mutex_unlock(&dev_priv->rps.hw_lock); | |
9794 | ||
7f1052a8 VS |
9795 | I915_WRITE(CDCLK_FREQ, DIV_ROUND_CLOSEST(cdclk, 1000) - 1); |
9796 | ||
b432e5cf VS |
9797 | intel_update_cdclk(dev); |
9798 | ||
9799 | WARN(cdclk != dev_priv->cdclk_freq, | |
9800 | "cdclk requested %d kHz but got %d kHz\n", | |
9801 | cdclk, dev_priv->cdclk_freq); | |
9802 | } | |
9803 | ||
587c7914 VS |
9804 | static int broadwell_calc_cdclk(int max_pixclk) |
9805 | { | |
9806 | if (max_pixclk > 540000) | |
9807 | return 675000; | |
9808 | else if (max_pixclk > 450000) | |
9809 | return 540000; | |
9810 | else if (max_pixclk > 337500) | |
9811 | return 450000; | |
9812 | else | |
9813 | return 337500; | |
9814 | } | |
9815 | ||
27c329ed | 9816 | static int broadwell_modeset_calc_cdclk(struct drm_atomic_state *state) |
b432e5cf | 9817 | { |
27c329ed | 9818 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
1a617b77 | 9819 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
27c329ed | 9820 | int max_pixclk = ilk_max_pixel_rate(state); |
b432e5cf VS |
9821 | int cdclk; |
9822 | ||
9823 | /* | |
9824 | * FIXME should also account for plane ratio | |
9825 | * once 64bpp pixel formats are supported. | |
9826 | */ | |
587c7914 | 9827 | cdclk = broadwell_calc_cdclk(max_pixclk); |
b432e5cf | 9828 | |
b432e5cf | 9829 | if (cdclk > dev_priv->max_cdclk_freq) { |
63ba534e ML |
9830 | DRM_DEBUG_KMS("requested cdclk (%d kHz) exceeds max (%d kHz)\n", |
9831 | cdclk, dev_priv->max_cdclk_freq); | |
9832 | return -EINVAL; | |
b432e5cf VS |
9833 | } |
9834 | ||
1a617b77 ML |
9835 | intel_state->cdclk = intel_state->dev_cdclk = cdclk; |
9836 | if (!intel_state->active_crtcs) | |
587c7914 | 9837 | intel_state->dev_cdclk = broadwell_calc_cdclk(0); |
b432e5cf VS |
9838 | |
9839 | return 0; | |
9840 | } | |
9841 | ||
27c329ed | 9842 | static void broadwell_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
b432e5cf | 9843 | { |
27c329ed | 9844 | struct drm_device *dev = old_state->dev; |
1a617b77 ML |
9845 | struct intel_atomic_state *old_intel_state = |
9846 | to_intel_atomic_state(old_state); | |
9847 | unsigned req_cdclk = old_intel_state->dev_cdclk; | |
b432e5cf | 9848 | |
27c329ed | 9849 | broadwell_set_cdclk(dev, req_cdclk); |
b432e5cf VS |
9850 | } |
9851 | ||
c89e39f3 CT |
9852 | static int skl_modeset_calc_cdclk(struct drm_atomic_state *state) |
9853 | { | |
9854 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); | |
9855 | struct drm_i915_private *dev_priv = to_i915(state->dev); | |
9856 | const int max_pixclk = ilk_max_pixel_rate(state); | |
a8ca4934 | 9857 | int vco = intel_state->cdclk_pll_vco; |
c89e39f3 CT |
9858 | int cdclk; |
9859 | ||
9860 | /* | |
9861 | * FIXME should also account for plane ratio | |
9862 | * once 64bpp pixel formats are supported. | |
9863 | */ | |
a8ca4934 | 9864 | cdclk = skl_calc_cdclk(max_pixclk, vco); |
c89e39f3 CT |
9865 | |
9866 | /* | |
9867 | * FIXME move the cdclk caclulation to | |
9868 | * compute_config() so we can fail gracegully. | |
9869 | */ | |
9870 | if (cdclk > dev_priv->max_cdclk_freq) { | |
9871 | DRM_ERROR("requested cdclk (%d kHz) exceeds max (%d kHz)\n", | |
9872 | cdclk, dev_priv->max_cdclk_freq); | |
9873 | cdclk = dev_priv->max_cdclk_freq; | |
9874 | } | |
9875 | ||
9876 | intel_state->cdclk = intel_state->dev_cdclk = cdclk; | |
9877 | if (!intel_state->active_crtcs) | |
a8ca4934 | 9878 | intel_state->dev_cdclk = skl_calc_cdclk(0, vco); |
c89e39f3 CT |
9879 | |
9880 | return 0; | |
9881 | } | |
9882 | ||
9883 | static void skl_modeset_commit_cdclk(struct drm_atomic_state *old_state) | |
9884 | { | |
1cd593e0 VS |
9885 | struct drm_i915_private *dev_priv = to_i915(old_state->dev); |
9886 | struct intel_atomic_state *intel_state = to_intel_atomic_state(old_state); | |
9887 | unsigned int req_cdclk = intel_state->dev_cdclk; | |
9888 | unsigned int req_vco = intel_state->cdclk_pll_vco; | |
c89e39f3 | 9889 | |
1cd593e0 | 9890 | skl_set_cdclk(dev_priv, req_cdclk, req_vco); |
c89e39f3 CT |
9891 | } |
9892 | ||
190f68c5 ACO |
9893 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
9894 | struct intel_crtc_state *crtc_state) | |
09b4ddf9 | 9895 | { |
af3997b5 MK |
9896 | struct intel_encoder *intel_encoder = |
9897 | intel_ddi_get_crtc_new_encoder(crtc_state); | |
9898 | ||
9899 | if (intel_encoder->type != INTEL_OUTPUT_DSI) { | |
9900 | if (!intel_ddi_pll_select(crtc, crtc_state)) | |
9901 | return -EINVAL; | |
9902 | } | |
716c2e55 | 9903 | |
c7653199 | 9904 | crtc->lowfreq_avail = false; |
644cef34 | 9905 | |
c8f7a0db | 9906 | return 0; |
79e53945 JB |
9907 | } |
9908 | ||
3760b59c S |
9909 | static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv, |
9910 | enum port port, | |
9911 | struct intel_crtc_state *pipe_config) | |
9912 | { | |
8106ddbd ACO |
9913 | enum intel_dpll_id id; |
9914 | ||
3760b59c S |
9915 | switch (port) { |
9916 | case PORT_A: | |
9917 | pipe_config->ddi_pll_sel = SKL_DPLL0; | |
08250c4b | 9918 | id = DPLL_ID_SKL_DPLL0; |
3760b59c S |
9919 | break; |
9920 | case PORT_B: | |
9921 | pipe_config->ddi_pll_sel = SKL_DPLL1; | |
08250c4b | 9922 | id = DPLL_ID_SKL_DPLL1; |
3760b59c S |
9923 | break; |
9924 | case PORT_C: | |
9925 | pipe_config->ddi_pll_sel = SKL_DPLL2; | |
08250c4b | 9926 | id = DPLL_ID_SKL_DPLL2; |
3760b59c S |
9927 | break; |
9928 | default: | |
9929 | DRM_ERROR("Incorrect port type\n"); | |
8106ddbd | 9930 | return; |
3760b59c | 9931 | } |
8106ddbd ACO |
9932 | |
9933 | pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); | |
3760b59c S |
9934 | } |
9935 | ||
96b7dfb7 S |
9936 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
9937 | enum port port, | |
5cec258b | 9938 | struct intel_crtc_state *pipe_config) |
96b7dfb7 | 9939 | { |
8106ddbd | 9940 | enum intel_dpll_id id; |
a3c988ea | 9941 | u32 temp; |
96b7dfb7 S |
9942 | |
9943 | temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port); | |
9944 | pipe_config->ddi_pll_sel = temp >> (port * 3 + 1); | |
9945 | ||
9946 | switch (pipe_config->ddi_pll_sel) { | |
3148ade7 | 9947 | case SKL_DPLL0: |
a3c988ea ACO |
9948 | id = DPLL_ID_SKL_DPLL0; |
9949 | break; | |
96b7dfb7 | 9950 | case SKL_DPLL1: |
8106ddbd | 9951 | id = DPLL_ID_SKL_DPLL1; |
96b7dfb7 S |
9952 | break; |
9953 | case SKL_DPLL2: | |
8106ddbd | 9954 | id = DPLL_ID_SKL_DPLL2; |
96b7dfb7 S |
9955 | break; |
9956 | case SKL_DPLL3: | |
8106ddbd | 9957 | id = DPLL_ID_SKL_DPLL3; |
96b7dfb7 | 9958 | break; |
8106ddbd ACO |
9959 | default: |
9960 | MISSING_CASE(pipe_config->ddi_pll_sel); | |
9961 | return; | |
96b7dfb7 | 9962 | } |
8106ddbd ACO |
9963 | |
9964 | pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); | |
96b7dfb7 S |
9965 | } |
9966 | ||
7d2c8175 DL |
9967 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
9968 | enum port port, | |
5cec258b | 9969 | struct intel_crtc_state *pipe_config) |
7d2c8175 | 9970 | { |
8106ddbd ACO |
9971 | enum intel_dpll_id id; |
9972 | ||
7d2c8175 DL |
9973 | pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); |
9974 | ||
9975 | switch (pipe_config->ddi_pll_sel) { | |
9976 | case PORT_CLK_SEL_WRPLL1: | |
8106ddbd | 9977 | id = DPLL_ID_WRPLL1; |
7d2c8175 DL |
9978 | break; |
9979 | case PORT_CLK_SEL_WRPLL2: | |
8106ddbd | 9980 | id = DPLL_ID_WRPLL2; |
7d2c8175 | 9981 | break; |
00490c22 | 9982 | case PORT_CLK_SEL_SPLL: |
8106ddbd | 9983 | id = DPLL_ID_SPLL; |
79bd23da | 9984 | break; |
9d16da65 ACO |
9985 | case PORT_CLK_SEL_LCPLL_810: |
9986 | id = DPLL_ID_LCPLL_810; | |
9987 | break; | |
9988 | case PORT_CLK_SEL_LCPLL_1350: | |
9989 | id = DPLL_ID_LCPLL_1350; | |
9990 | break; | |
9991 | case PORT_CLK_SEL_LCPLL_2700: | |
9992 | id = DPLL_ID_LCPLL_2700; | |
9993 | break; | |
8106ddbd ACO |
9994 | default: |
9995 | MISSING_CASE(pipe_config->ddi_pll_sel); | |
9996 | /* fall through */ | |
9997 | case PORT_CLK_SEL_NONE: | |
8106ddbd | 9998 | return; |
7d2c8175 | 9999 | } |
8106ddbd ACO |
10000 | |
10001 | pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); | |
7d2c8175 DL |
10002 | } |
10003 | ||
cf30429e JN |
10004 | static bool hsw_get_transcoder_state(struct intel_crtc *crtc, |
10005 | struct intel_crtc_state *pipe_config, | |
10006 | unsigned long *power_domain_mask) | |
10007 | { | |
10008 | struct drm_device *dev = crtc->base.dev; | |
10009 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10010 | enum intel_display_power_domain power_domain; | |
10011 | u32 tmp; | |
10012 | ||
d9a7bc67 ID |
10013 | /* |
10014 | * The pipe->transcoder mapping is fixed with the exception of the eDP | |
10015 | * transcoder handled below. | |
10016 | */ | |
cf30429e JN |
10017 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
10018 | ||
10019 | /* | |
10020 | * XXX: Do intel_display_power_get_if_enabled before reading this (for | |
10021 | * consistency and less surprising code; it's in always on power). | |
10022 | */ | |
10023 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); | |
10024 | if (tmp & TRANS_DDI_FUNC_ENABLE) { | |
10025 | enum pipe trans_edp_pipe; | |
10026 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { | |
10027 | default: | |
10028 | WARN(1, "unknown pipe linked to edp transcoder\n"); | |
10029 | case TRANS_DDI_EDP_INPUT_A_ONOFF: | |
10030 | case TRANS_DDI_EDP_INPUT_A_ON: | |
10031 | trans_edp_pipe = PIPE_A; | |
10032 | break; | |
10033 | case TRANS_DDI_EDP_INPUT_B_ONOFF: | |
10034 | trans_edp_pipe = PIPE_B; | |
10035 | break; | |
10036 | case TRANS_DDI_EDP_INPUT_C_ONOFF: | |
10037 | trans_edp_pipe = PIPE_C; | |
10038 | break; | |
10039 | } | |
10040 | ||
10041 | if (trans_edp_pipe == crtc->pipe) | |
10042 | pipe_config->cpu_transcoder = TRANSCODER_EDP; | |
10043 | } | |
10044 | ||
10045 | power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder); | |
10046 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) | |
10047 | return false; | |
10048 | *power_domain_mask |= BIT(power_domain); | |
10049 | ||
10050 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); | |
10051 | ||
10052 | return tmp & PIPECONF_ENABLE; | |
10053 | } | |
10054 | ||
4d1de975 JN |
10055 | static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc, |
10056 | struct intel_crtc_state *pipe_config, | |
10057 | unsigned long *power_domain_mask) | |
10058 | { | |
10059 | struct drm_device *dev = crtc->base.dev; | |
10060 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10061 | enum intel_display_power_domain power_domain; | |
10062 | enum port port; | |
10063 | enum transcoder cpu_transcoder; | |
10064 | u32 tmp; | |
10065 | ||
10066 | pipe_config->has_dsi_encoder = false; | |
10067 | ||
10068 | for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) { | |
10069 | if (port == PORT_A) | |
10070 | cpu_transcoder = TRANSCODER_DSI_A; | |
10071 | else | |
10072 | cpu_transcoder = TRANSCODER_DSI_C; | |
10073 | ||
10074 | power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); | |
10075 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) | |
10076 | continue; | |
10077 | *power_domain_mask |= BIT(power_domain); | |
10078 | ||
db18b6a6 ID |
10079 | /* |
10080 | * The PLL needs to be enabled with a valid divider | |
10081 | * configuration, otherwise accessing DSI registers will hang | |
10082 | * the machine. See BSpec North Display Engine | |
10083 | * registers/MIPI[BXT]. We can break out here early, since we | |
10084 | * need the same DSI PLL to be enabled for both DSI ports. | |
10085 | */ | |
10086 | if (!intel_dsi_pll_is_enabled(dev_priv)) | |
10087 | break; | |
10088 | ||
4d1de975 JN |
10089 | /* XXX: this works for video mode only */ |
10090 | tmp = I915_READ(BXT_MIPI_PORT_CTRL(port)); | |
10091 | if (!(tmp & DPI_ENABLE)) | |
10092 | continue; | |
10093 | ||
10094 | tmp = I915_READ(MIPI_CTRL(port)); | |
10095 | if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe)) | |
10096 | continue; | |
10097 | ||
10098 | pipe_config->cpu_transcoder = cpu_transcoder; | |
10099 | pipe_config->has_dsi_encoder = true; | |
10100 | break; | |
10101 | } | |
10102 | ||
10103 | return pipe_config->has_dsi_encoder; | |
10104 | } | |
10105 | ||
26804afd | 10106 | static void haswell_get_ddi_port_state(struct intel_crtc *crtc, |
5cec258b | 10107 | struct intel_crtc_state *pipe_config) |
26804afd DV |
10108 | { |
10109 | struct drm_device *dev = crtc->base.dev; | |
10110 | struct drm_i915_private *dev_priv = dev->dev_private; | |
d452c5b6 | 10111 | struct intel_shared_dpll *pll; |
26804afd DV |
10112 | enum port port; |
10113 | uint32_t tmp; | |
10114 | ||
10115 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); | |
10116 | ||
10117 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; | |
10118 | ||
ef11bdb3 | 10119 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
96b7dfb7 | 10120 | skylake_get_ddi_pll(dev_priv, port, pipe_config); |
3760b59c S |
10121 | else if (IS_BROXTON(dev)) |
10122 | bxt_get_ddi_pll(dev_priv, port, pipe_config); | |
96b7dfb7 S |
10123 | else |
10124 | haswell_get_ddi_pll(dev_priv, port, pipe_config); | |
9cd86933 | 10125 | |
8106ddbd ACO |
10126 | pll = pipe_config->shared_dpll; |
10127 | if (pll) { | |
2edd6443 ACO |
10128 | WARN_ON(!pll->funcs.get_hw_state(dev_priv, pll, |
10129 | &pipe_config->dpll_hw_state)); | |
d452c5b6 DV |
10130 | } |
10131 | ||
26804afd DV |
10132 | /* |
10133 | * Haswell has only FDI/PCH transcoder A. It is which is connected to | |
10134 | * DDI E. So just check whether this pipe is wired to DDI E and whether | |
10135 | * the PCH transcoder is on. | |
10136 | */ | |
ca370455 DL |
10137 | if (INTEL_INFO(dev)->gen < 9 && |
10138 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { | |
26804afd DV |
10139 | pipe_config->has_pch_encoder = true; |
10140 | ||
10141 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); | |
10142 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> | |
10143 | FDI_DP_PORT_WIDTH_SHIFT) + 1; | |
10144 | ||
10145 | ironlake_get_fdi_m_n_config(crtc, pipe_config); | |
10146 | } | |
10147 | } | |
10148 | ||
0e8ffe1b | 10149 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 10150 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
10151 | { |
10152 | struct drm_device *dev = crtc->base.dev; | |
10153 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1729050e ID |
10154 | enum intel_display_power_domain power_domain; |
10155 | unsigned long power_domain_mask; | |
cf30429e | 10156 | bool active; |
0e8ffe1b | 10157 | |
1729050e ID |
10158 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
10159 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) | |
b5482bd0 | 10160 | return false; |
1729050e ID |
10161 | power_domain_mask = BIT(power_domain); |
10162 | ||
8106ddbd | 10163 | pipe_config->shared_dpll = NULL; |
c0d43d62 | 10164 | |
cf30429e | 10165 | active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask); |
eccb140b | 10166 | |
4d1de975 JN |
10167 | if (IS_BROXTON(dev_priv)) { |
10168 | bxt_get_dsi_transcoder_state(crtc, pipe_config, | |
10169 | &power_domain_mask); | |
10170 | WARN_ON(active && pipe_config->has_dsi_encoder); | |
10171 | if (pipe_config->has_dsi_encoder) | |
10172 | active = true; | |
10173 | } | |
10174 | ||
cf30429e | 10175 | if (!active) |
1729050e | 10176 | goto out; |
0e8ffe1b | 10177 | |
4d1de975 JN |
10178 | if (!pipe_config->has_dsi_encoder) { |
10179 | haswell_get_ddi_port_state(crtc, pipe_config); | |
10180 | intel_get_pipe_timings(crtc, pipe_config); | |
10181 | } | |
627eb5a3 | 10182 | |
bc58be60 | 10183 | intel_get_pipe_src_size(crtc, pipe_config); |
1bd1bd80 | 10184 | |
05dc698c LL |
10185 | pipe_config->gamma_mode = |
10186 | I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK; | |
10187 | ||
a1b2278e CK |
10188 | if (INTEL_INFO(dev)->gen >= 9) { |
10189 | skl_init_scalers(dev, crtc, pipe_config); | |
10190 | } | |
10191 | ||
af99ceda CK |
10192 | if (INTEL_INFO(dev)->gen >= 9) { |
10193 | pipe_config->scaler_state.scaler_id = -1; | |
10194 | pipe_config->scaler_state.scaler_users &= ~(1 << SKL_CRTC_INDEX); | |
10195 | } | |
10196 | ||
1729050e ID |
10197 | power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
10198 | if (intel_display_power_get_if_enabled(dev_priv, power_domain)) { | |
10199 | power_domain_mask |= BIT(power_domain); | |
1c132b44 | 10200 | if (INTEL_INFO(dev)->gen >= 9) |
bd2e244f | 10201 | skylake_get_pfit_config(crtc, pipe_config); |
ff6d9f55 | 10202 | else |
1c132b44 | 10203 | ironlake_get_pfit_config(crtc, pipe_config); |
bd2e244f | 10204 | } |
88adfff1 | 10205 | |
e59150dc JB |
10206 | if (IS_HASWELL(dev)) |
10207 | pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) && | |
10208 | (I915_READ(IPS_CTL) & IPS_ENABLE); | |
42db64ef | 10209 | |
4d1de975 JN |
10210 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP && |
10211 | !transcoder_is_dsi(pipe_config->cpu_transcoder)) { | |
ebb69c95 CT |
10212 | pipe_config->pixel_multiplier = |
10213 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; | |
10214 | } else { | |
10215 | pipe_config->pixel_multiplier = 1; | |
10216 | } | |
6c49f241 | 10217 | |
1729050e ID |
10218 | out: |
10219 | for_each_power_domain(power_domain, power_domain_mask) | |
10220 | intel_display_power_put(dev_priv, power_domain); | |
10221 | ||
cf30429e | 10222 | return active; |
0e8ffe1b DV |
10223 | } |
10224 | ||
55a08b3f ML |
10225 | static void i845_update_cursor(struct drm_crtc *crtc, u32 base, |
10226 | const struct intel_plane_state *plane_state) | |
560b85bb CW |
10227 | { |
10228 | struct drm_device *dev = crtc->dev; | |
10229 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10230 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
dc41c154 | 10231 | uint32_t cntl = 0, size = 0; |
560b85bb | 10232 | |
55a08b3f ML |
10233 | if (plane_state && plane_state->visible) { |
10234 | unsigned int width = plane_state->base.crtc_w; | |
10235 | unsigned int height = plane_state->base.crtc_h; | |
dc41c154 VS |
10236 | unsigned int stride = roundup_pow_of_two(width) * 4; |
10237 | ||
10238 | switch (stride) { | |
10239 | default: | |
10240 | WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n", | |
10241 | width, stride); | |
10242 | stride = 256; | |
10243 | /* fallthrough */ | |
10244 | case 256: | |
10245 | case 512: | |
10246 | case 1024: | |
10247 | case 2048: | |
10248 | break; | |
4b0e333e CW |
10249 | } |
10250 | ||
dc41c154 VS |
10251 | cntl |= CURSOR_ENABLE | |
10252 | CURSOR_GAMMA_ENABLE | | |
10253 | CURSOR_FORMAT_ARGB | | |
10254 | CURSOR_STRIDE(stride); | |
10255 | ||
10256 | size = (height << 12) | width; | |
4b0e333e | 10257 | } |
560b85bb | 10258 | |
dc41c154 VS |
10259 | if (intel_crtc->cursor_cntl != 0 && |
10260 | (intel_crtc->cursor_base != base || | |
10261 | intel_crtc->cursor_size != size || | |
10262 | intel_crtc->cursor_cntl != cntl)) { | |
10263 | /* On these chipsets we can only modify the base/size/stride | |
10264 | * whilst the cursor is disabled. | |
10265 | */ | |
0b87c24e VS |
10266 | I915_WRITE(CURCNTR(PIPE_A), 0); |
10267 | POSTING_READ(CURCNTR(PIPE_A)); | |
dc41c154 | 10268 | intel_crtc->cursor_cntl = 0; |
4b0e333e | 10269 | } |
560b85bb | 10270 | |
99d1f387 | 10271 | if (intel_crtc->cursor_base != base) { |
0b87c24e | 10272 | I915_WRITE(CURBASE(PIPE_A), base); |
99d1f387 VS |
10273 | intel_crtc->cursor_base = base; |
10274 | } | |
4726e0b0 | 10275 | |
dc41c154 VS |
10276 | if (intel_crtc->cursor_size != size) { |
10277 | I915_WRITE(CURSIZE, size); | |
10278 | intel_crtc->cursor_size = size; | |
4b0e333e | 10279 | } |
560b85bb | 10280 | |
4b0e333e | 10281 | if (intel_crtc->cursor_cntl != cntl) { |
0b87c24e VS |
10282 | I915_WRITE(CURCNTR(PIPE_A), cntl); |
10283 | POSTING_READ(CURCNTR(PIPE_A)); | |
4b0e333e | 10284 | intel_crtc->cursor_cntl = cntl; |
560b85bb | 10285 | } |
560b85bb CW |
10286 | } |
10287 | ||
55a08b3f ML |
10288 | static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base, |
10289 | const struct intel_plane_state *plane_state) | |
65a21cd6 JB |
10290 | { |
10291 | struct drm_device *dev = crtc->dev; | |
10292 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10293 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10294 | int pipe = intel_crtc->pipe; | |
663f3122 | 10295 | uint32_t cntl = 0; |
4b0e333e | 10296 | |
55a08b3f | 10297 | if (plane_state && plane_state->visible) { |
4b0e333e | 10298 | cntl = MCURSOR_GAMMA_ENABLE; |
55a08b3f | 10299 | switch (plane_state->base.crtc_w) { |
4726e0b0 SK |
10300 | case 64: |
10301 | cntl |= CURSOR_MODE_64_ARGB_AX; | |
10302 | break; | |
10303 | case 128: | |
10304 | cntl |= CURSOR_MODE_128_ARGB_AX; | |
10305 | break; | |
10306 | case 256: | |
10307 | cntl |= CURSOR_MODE_256_ARGB_AX; | |
10308 | break; | |
10309 | default: | |
55a08b3f | 10310 | MISSING_CASE(plane_state->base.crtc_w); |
4726e0b0 | 10311 | return; |
65a21cd6 | 10312 | } |
4b0e333e | 10313 | cntl |= pipe << 28; /* Connect to correct pipe */ |
47bf17a7 | 10314 | |
fc6f93bc | 10315 | if (HAS_DDI(dev)) |
47bf17a7 | 10316 | cntl |= CURSOR_PIPE_CSC_ENABLE; |
65a21cd6 | 10317 | |
55a08b3f ML |
10318 | if (plane_state->base.rotation == BIT(DRM_ROTATE_180)) |
10319 | cntl |= CURSOR_ROTATE_180; | |
10320 | } | |
4398ad45 | 10321 | |
4b0e333e CW |
10322 | if (intel_crtc->cursor_cntl != cntl) { |
10323 | I915_WRITE(CURCNTR(pipe), cntl); | |
10324 | POSTING_READ(CURCNTR(pipe)); | |
10325 | intel_crtc->cursor_cntl = cntl; | |
65a21cd6 | 10326 | } |
4b0e333e | 10327 | |
65a21cd6 | 10328 | /* and commit changes on next vblank */ |
5efb3e28 VS |
10329 | I915_WRITE(CURBASE(pipe), base); |
10330 | POSTING_READ(CURBASE(pipe)); | |
99d1f387 VS |
10331 | |
10332 | intel_crtc->cursor_base = base; | |
65a21cd6 JB |
10333 | } |
10334 | ||
cda4b7d3 | 10335 | /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */ |
6b383a7f | 10336 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, |
55a08b3f | 10337 | const struct intel_plane_state *plane_state) |
cda4b7d3 CW |
10338 | { |
10339 | struct drm_device *dev = crtc->dev; | |
10340 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10341 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10342 | int pipe = intel_crtc->pipe; | |
55a08b3f ML |
10343 | u32 base = intel_crtc->cursor_addr; |
10344 | u32 pos = 0; | |
cda4b7d3 | 10345 | |
55a08b3f ML |
10346 | if (plane_state) { |
10347 | int x = plane_state->base.crtc_x; | |
10348 | int y = plane_state->base.crtc_y; | |
cda4b7d3 | 10349 | |
55a08b3f ML |
10350 | if (x < 0) { |
10351 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; | |
10352 | x = -x; | |
10353 | } | |
10354 | pos |= x << CURSOR_X_SHIFT; | |
cda4b7d3 | 10355 | |
55a08b3f ML |
10356 | if (y < 0) { |
10357 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; | |
10358 | y = -y; | |
10359 | } | |
10360 | pos |= y << CURSOR_Y_SHIFT; | |
10361 | ||
10362 | /* ILK+ do this automagically */ | |
10363 | if (HAS_GMCH_DISPLAY(dev) && | |
10364 | plane_state->base.rotation == BIT(DRM_ROTATE_180)) { | |
10365 | base += (plane_state->base.crtc_h * | |
10366 | plane_state->base.crtc_w - 1) * 4; | |
10367 | } | |
cda4b7d3 | 10368 | } |
cda4b7d3 | 10369 | |
5efb3e28 VS |
10370 | I915_WRITE(CURPOS(pipe), pos); |
10371 | ||
8ac54669 | 10372 | if (IS_845G(dev) || IS_I865G(dev)) |
55a08b3f | 10373 | i845_update_cursor(crtc, base, plane_state); |
5efb3e28 | 10374 | else |
55a08b3f | 10375 | i9xx_update_cursor(crtc, base, plane_state); |
cda4b7d3 CW |
10376 | } |
10377 | ||
dc41c154 VS |
10378 | static bool cursor_size_ok(struct drm_device *dev, |
10379 | uint32_t width, uint32_t height) | |
10380 | { | |
10381 | if (width == 0 || height == 0) | |
10382 | return false; | |
10383 | ||
10384 | /* | |
10385 | * 845g/865g are special in that they are only limited by | |
10386 | * the width of their cursors, the height is arbitrary up to | |
10387 | * the precision of the register. Everything else requires | |
10388 | * square cursors, limited to a few power-of-two sizes. | |
10389 | */ | |
10390 | if (IS_845G(dev) || IS_I865G(dev)) { | |
10391 | if ((width & 63) != 0) | |
10392 | return false; | |
10393 | ||
10394 | if (width > (IS_845G(dev) ? 64 : 512)) | |
10395 | return false; | |
10396 | ||
10397 | if (height > 1023) | |
10398 | return false; | |
10399 | } else { | |
10400 | switch (width | height) { | |
10401 | case 256: | |
10402 | case 128: | |
10403 | if (IS_GEN2(dev)) | |
10404 | return false; | |
10405 | case 64: | |
10406 | break; | |
10407 | default: | |
10408 | return false; | |
10409 | } | |
10410 | } | |
10411 | ||
10412 | return true; | |
10413 | } | |
10414 | ||
79e53945 JB |
10415 | /* VESA 640x480x72Hz mode to set on the pipe */ |
10416 | static struct drm_display_mode load_detect_mode = { | |
10417 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, | |
10418 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), | |
10419 | }; | |
10420 | ||
a8bb6818 DV |
10421 | struct drm_framebuffer * |
10422 | __intel_framebuffer_create(struct drm_device *dev, | |
10423 | struct drm_mode_fb_cmd2 *mode_cmd, | |
10424 | struct drm_i915_gem_object *obj) | |
d2dff872 CW |
10425 | { |
10426 | struct intel_framebuffer *intel_fb; | |
10427 | int ret; | |
10428 | ||
10429 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); | |
dcb1394e | 10430 | if (!intel_fb) |
d2dff872 | 10431 | return ERR_PTR(-ENOMEM); |
d2dff872 CW |
10432 | |
10433 | ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj); | |
dd4916c5 DV |
10434 | if (ret) |
10435 | goto err; | |
d2dff872 CW |
10436 | |
10437 | return &intel_fb->base; | |
dcb1394e | 10438 | |
dd4916c5 | 10439 | err: |
dd4916c5 | 10440 | kfree(intel_fb); |
dd4916c5 | 10441 | return ERR_PTR(ret); |
d2dff872 CW |
10442 | } |
10443 | ||
b5ea642a | 10444 | static struct drm_framebuffer * |
a8bb6818 DV |
10445 | intel_framebuffer_create(struct drm_device *dev, |
10446 | struct drm_mode_fb_cmd2 *mode_cmd, | |
10447 | struct drm_i915_gem_object *obj) | |
10448 | { | |
10449 | struct drm_framebuffer *fb; | |
10450 | int ret; | |
10451 | ||
10452 | ret = i915_mutex_lock_interruptible(dev); | |
10453 | if (ret) | |
10454 | return ERR_PTR(ret); | |
10455 | fb = __intel_framebuffer_create(dev, mode_cmd, obj); | |
10456 | mutex_unlock(&dev->struct_mutex); | |
10457 | ||
10458 | return fb; | |
10459 | } | |
10460 | ||
d2dff872 CW |
10461 | static u32 |
10462 | intel_framebuffer_pitch_for_width(int width, int bpp) | |
10463 | { | |
10464 | u32 pitch = DIV_ROUND_UP(width * bpp, 8); | |
10465 | return ALIGN(pitch, 64); | |
10466 | } | |
10467 | ||
10468 | static u32 | |
10469 | intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp) | |
10470 | { | |
10471 | u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp); | |
1267a26b | 10472 | return PAGE_ALIGN(pitch * mode->vdisplay); |
d2dff872 CW |
10473 | } |
10474 | ||
10475 | static struct drm_framebuffer * | |
10476 | intel_framebuffer_create_for_mode(struct drm_device *dev, | |
10477 | struct drm_display_mode *mode, | |
10478 | int depth, int bpp) | |
10479 | { | |
dcb1394e | 10480 | struct drm_framebuffer *fb; |
d2dff872 | 10481 | struct drm_i915_gem_object *obj; |
0fed39bd | 10482 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
d2dff872 | 10483 | |
d37cd8a8 | 10484 | obj = i915_gem_object_create(dev, |
d2dff872 | 10485 | intel_framebuffer_size_for_mode(mode, bpp)); |
fe3db79b CW |
10486 | if (IS_ERR(obj)) |
10487 | return ERR_CAST(obj); | |
d2dff872 CW |
10488 | |
10489 | mode_cmd.width = mode->hdisplay; | |
10490 | mode_cmd.height = mode->vdisplay; | |
308e5bcb JB |
10491 | mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width, |
10492 | bpp); | |
5ca0c34a | 10493 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); |
d2dff872 | 10494 | |
dcb1394e LW |
10495 | fb = intel_framebuffer_create(dev, &mode_cmd, obj); |
10496 | if (IS_ERR(fb)) | |
10497 | drm_gem_object_unreference_unlocked(&obj->base); | |
10498 | ||
10499 | return fb; | |
d2dff872 CW |
10500 | } |
10501 | ||
10502 | static struct drm_framebuffer * | |
10503 | mode_fits_in_fbdev(struct drm_device *dev, | |
10504 | struct drm_display_mode *mode) | |
10505 | { | |
0695726e | 10506 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
d2dff872 CW |
10507 | struct drm_i915_private *dev_priv = dev->dev_private; |
10508 | struct drm_i915_gem_object *obj; | |
10509 | struct drm_framebuffer *fb; | |
10510 | ||
4c0e5528 | 10511 | if (!dev_priv->fbdev) |
d2dff872 CW |
10512 | return NULL; |
10513 | ||
4c0e5528 | 10514 | if (!dev_priv->fbdev->fb) |
d2dff872 CW |
10515 | return NULL; |
10516 | ||
4c0e5528 DV |
10517 | obj = dev_priv->fbdev->fb->obj; |
10518 | BUG_ON(!obj); | |
10519 | ||
8bcd4553 | 10520 | fb = &dev_priv->fbdev->fb->base; |
01f2c773 VS |
10521 | if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay, |
10522 | fb->bits_per_pixel)) | |
d2dff872 CW |
10523 | return NULL; |
10524 | ||
01f2c773 | 10525 | if (obj->base.size < mode->vdisplay * fb->pitches[0]) |
d2dff872 CW |
10526 | return NULL; |
10527 | ||
edde3617 | 10528 | drm_framebuffer_reference(fb); |
d2dff872 | 10529 | return fb; |
4520f53a DV |
10530 | #else |
10531 | return NULL; | |
10532 | #endif | |
d2dff872 CW |
10533 | } |
10534 | ||
d3a40d1b ACO |
10535 | static int intel_modeset_setup_plane_state(struct drm_atomic_state *state, |
10536 | struct drm_crtc *crtc, | |
10537 | struct drm_display_mode *mode, | |
10538 | struct drm_framebuffer *fb, | |
10539 | int x, int y) | |
10540 | { | |
10541 | struct drm_plane_state *plane_state; | |
10542 | int hdisplay, vdisplay; | |
10543 | int ret; | |
10544 | ||
10545 | plane_state = drm_atomic_get_plane_state(state, crtc->primary); | |
10546 | if (IS_ERR(plane_state)) | |
10547 | return PTR_ERR(plane_state); | |
10548 | ||
10549 | if (mode) | |
10550 | drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay); | |
10551 | else | |
10552 | hdisplay = vdisplay = 0; | |
10553 | ||
10554 | ret = drm_atomic_set_crtc_for_plane(plane_state, fb ? crtc : NULL); | |
10555 | if (ret) | |
10556 | return ret; | |
10557 | drm_atomic_set_fb_for_plane(plane_state, fb); | |
10558 | plane_state->crtc_x = 0; | |
10559 | plane_state->crtc_y = 0; | |
10560 | plane_state->crtc_w = hdisplay; | |
10561 | plane_state->crtc_h = vdisplay; | |
10562 | plane_state->src_x = x << 16; | |
10563 | plane_state->src_y = y << 16; | |
10564 | plane_state->src_w = hdisplay << 16; | |
10565 | plane_state->src_h = vdisplay << 16; | |
10566 | ||
10567 | return 0; | |
10568 | } | |
10569 | ||
d2434ab7 | 10570 | bool intel_get_load_detect_pipe(struct drm_connector *connector, |
7173188d | 10571 | struct drm_display_mode *mode, |
51fd371b RC |
10572 | struct intel_load_detect_pipe *old, |
10573 | struct drm_modeset_acquire_ctx *ctx) | |
79e53945 JB |
10574 | { |
10575 | struct intel_crtc *intel_crtc; | |
d2434ab7 DV |
10576 | struct intel_encoder *intel_encoder = |
10577 | intel_attached_encoder(connector); | |
79e53945 | 10578 | struct drm_crtc *possible_crtc; |
4ef69c7a | 10579 | struct drm_encoder *encoder = &intel_encoder->base; |
79e53945 JB |
10580 | struct drm_crtc *crtc = NULL; |
10581 | struct drm_device *dev = encoder->dev; | |
94352cf9 | 10582 | struct drm_framebuffer *fb; |
51fd371b | 10583 | struct drm_mode_config *config = &dev->mode_config; |
edde3617 | 10584 | struct drm_atomic_state *state = NULL, *restore_state = NULL; |
944b0c76 | 10585 | struct drm_connector_state *connector_state; |
4be07317 | 10586 | struct intel_crtc_state *crtc_state; |
51fd371b | 10587 | int ret, i = -1; |
79e53945 | 10588 | |
d2dff872 | 10589 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
c23cc417 | 10590 | connector->base.id, connector->name, |
8e329a03 | 10591 | encoder->base.id, encoder->name); |
d2dff872 | 10592 | |
edde3617 ML |
10593 | old->restore_state = NULL; |
10594 | ||
51fd371b RC |
10595 | retry: |
10596 | ret = drm_modeset_lock(&config->connection_mutex, ctx); | |
10597 | if (ret) | |
ad3c558f | 10598 | goto fail; |
6e9f798d | 10599 | |
79e53945 JB |
10600 | /* |
10601 | * Algorithm gets a little messy: | |
7a5e4805 | 10602 | * |
79e53945 JB |
10603 | * - if the connector already has an assigned crtc, use it (but make |
10604 | * sure it's on first) | |
7a5e4805 | 10605 | * |
79e53945 JB |
10606 | * - try to find the first unused crtc that can drive this connector, |
10607 | * and use that if we find one | |
79e53945 JB |
10608 | */ |
10609 | ||
10610 | /* See if we already have a CRTC for this connector */ | |
edde3617 ML |
10611 | if (connector->state->crtc) { |
10612 | crtc = connector->state->crtc; | |
8261b191 | 10613 | |
51fd371b | 10614 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
4d02e2de | 10615 | if (ret) |
ad3c558f | 10616 | goto fail; |
8261b191 CW |
10617 | |
10618 | /* Make sure the crtc and connector are running */ | |
edde3617 | 10619 | goto found; |
79e53945 JB |
10620 | } |
10621 | ||
10622 | /* Find an unused one (if possible) */ | |
70e1e0ec | 10623 | for_each_crtc(dev, possible_crtc) { |
79e53945 JB |
10624 | i++; |
10625 | if (!(encoder->possible_crtcs & (1 << i))) | |
10626 | continue; | |
edde3617 ML |
10627 | |
10628 | ret = drm_modeset_lock(&possible_crtc->mutex, ctx); | |
10629 | if (ret) | |
10630 | goto fail; | |
10631 | ||
10632 | if (possible_crtc->state->enable) { | |
10633 | drm_modeset_unlock(&possible_crtc->mutex); | |
a459249c | 10634 | continue; |
edde3617 | 10635 | } |
a459249c VS |
10636 | |
10637 | crtc = possible_crtc; | |
10638 | break; | |
79e53945 JB |
10639 | } |
10640 | ||
10641 | /* | |
10642 | * If we didn't find an unused CRTC, don't use any. | |
10643 | */ | |
10644 | if (!crtc) { | |
7173188d | 10645 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
ad3c558f | 10646 | goto fail; |
79e53945 JB |
10647 | } |
10648 | ||
edde3617 ML |
10649 | found: |
10650 | intel_crtc = to_intel_crtc(crtc); | |
10651 | ||
4d02e2de DV |
10652 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
10653 | if (ret) | |
ad3c558f | 10654 | goto fail; |
79e53945 | 10655 | |
83a57153 | 10656 | state = drm_atomic_state_alloc(dev); |
edde3617 ML |
10657 | restore_state = drm_atomic_state_alloc(dev); |
10658 | if (!state || !restore_state) { | |
10659 | ret = -ENOMEM; | |
10660 | goto fail; | |
10661 | } | |
83a57153 ACO |
10662 | |
10663 | state->acquire_ctx = ctx; | |
edde3617 | 10664 | restore_state->acquire_ctx = ctx; |
83a57153 | 10665 | |
944b0c76 ACO |
10666 | connector_state = drm_atomic_get_connector_state(state, connector); |
10667 | if (IS_ERR(connector_state)) { | |
10668 | ret = PTR_ERR(connector_state); | |
10669 | goto fail; | |
10670 | } | |
10671 | ||
edde3617 ML |
10672 | ret = drm_atomic_set_crtc_for_connector(connector_state, crtc); |
10673 | if (ret) | |
10674 | goto fail; | |
944b0c76 | 10675 | |
4be07317 ACO |
10676 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
10677 | if (IS_ERR(crtc_state)) { | |
10678 | ret = PTR_ERR(crtc_state); | |
10679 | goto fail; | |
10680 | } | |
10681 | ||
49d6fa21 | 10682 | crtc_state->base.active = crtc_state->base.enable = true; |
4be07317 | 10683 | |
6492711d CW |
10684 | if (!mode) |
10685 | mode = &load_detect_mode; | |
79e53945 | 10686 | |
d2dff872 CW |
10687 | /* We need a framebuffer large enough to accommodate all accesses |
10688 | * that the plane may generate whilst we perform load detection. | |
10689 | * We can not rely on the fbcon either being present (we get called | |
10690 | * during its initialisation to detect all boot displays, or it may | |
10691 | * not even exist) or that it is large enough to satisfy the | |
10692 | * requested mode. | |
10693 | */ | |
94352cf9 DV |
10694 | fb = mode_fits_in_fbdev(dev, mode); |
10695 | if (fb == NULL) { | |
d2dff872 | 10696 | DRM_DEBUG_KMS("creating tmp fb for load-detection\n"); |
94352cf9 | 10697 | fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32); |
d2dff872 CW |
10698 | } else |
10699 | DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); | |
94352cf9 | 10700 | if (IS_ERR(fb)) { |
d2dff872 | 10701 | DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); |
412b61d8 | 10702 | goto fail; |
79e53945 | 10703 | } |
79e53945 | 10704 | |
d3a40d1b ACO |
10705 | ret = intel_modeset_setup_plane_state(state, crtc, mode, fb, 0, 0); |
10706 | if (ret) | |
10707 | goto fail; | |
10708 | ||
edde3617 ML |
10709 | drm_framebuffer_unreference(fb); |
10710 | ||
10711 | ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode); | |
10712 | if (ret) | |
10713 | goto fail; | |
10714 | ||
10715 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector)); | |
10716 | if (!ret) | |
10717 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc)); | |
10718 | if (!ret) | |
10719 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_plane_state(restore_state, crtc->primary)); | |
10720 | if (ret) { | |
10721 | DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret); | |
10722 | goto fail; | |
10723 | } | |
8c7b5ccb | 10724 | |
3ba86073 ML |
10725 | ret = drm_atomic_commit(state); |
10726 | if (ret) { | |
6492711d | 10727 | DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); |
412b61d8 | 10728 | goto fail; |
79e53945 | 10729 | } |
edde3617 ML |
10730 | |
10731 | old->restore_state = restore_state; | |
7173188d | 10732 | |
79e53945 | 10733 | /* let the connector get through one full cycle before testing */ |
9d0498a2 | 10734 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
7173188d | 10735 | return true; |
412b61d8 | 10736 | |
ad3c558f | 10737 | fail: |
e5d958ef | 10738 | drm_atomic_state_free(state); |
edde3617 ML |
10739 | drm_atomic_state_free(restore_state); |
10740 | restore_state = state = NULL; | |
83a57153 | 10741 | |
51fd371b RC |
10742 | if (ret == -EDEADLK) { |
10743 | drm_modeset_backoff(ctx); | |
10744 | goto retry; | |
10745 | } | |
10746 | ||
412b61d8 | 10747 | return false; |
79e53945 JB |
10748 | } |
10749 | ||
d2434ab7 | 10750 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
49172fee ACO |
10751 | struct intel_load_detect_pipe *old, |
10752 | struct drm_modeset_acquire_ctx *ctx) | |
79e53945 | 10753 | { |
d2434ab7 DV |
10754 | struct intel_encoder *intel_encoder = |
10755 | intel_attached_encoder(connector); | |
4ef69c7a | 10756 | struct drm_encoder *encoder = &intel_encoder->base; |
edde3617 | 10757 | struct drm_atomic_state *state = old->restore_state; |
d3a40d1b | 10758 | int ret; |
79e53945 | 10759 | |
d2dff872 | 10760 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
c23cc417 | 10761 | connector->base.id, connector->name, |
8e329a03 | 10762 | encoder->base.id, encoder->name); |
d2dff872 | 10763 | |
edde3617 | 10764 | if (!state) |
0622a53c | 10765 | return; |
79e53945 | 10766 | |
edde3617 ML |
10767 | ret = drm_atomic_commit(state); |
10768 | if (ret) { | |
10769 | DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret); | |
10770 | drm_atomic_state_free(state); | |
10771 | } | |
79e53945 JB |
10772 | } |
10773 | ||
da4a1efa | 10774 | static int i9xx_pll_refclk(struct drm_device *dev, |
5cec258b | 10775 | const struct intel_crtc_state *pipe_config) |
da4a1efa VS |
10776 | { |
10777 | struct drm_i915_private *dev_priv = dev->dev_private; | |
10778 | u32 dpll = pipe_config->dpll_hw_state.dpll; | |
10779 | ||
10780 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) | |
e91e941b | 10781 | return dev_priv->vbt.lvds_ssc_freq; |
da4a1efa VS |
10782 | else if (HAS_PCH_SPLIT(dev)) |
10783 | return 120000; | |
10784 | else if (!IS_GEN2(dev)) | |
10785 | return 96000; | |
10786 | else | |
10787 | return 48000; | |
10788 | } | |
10789 | ||
79e53945 | 10790 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
f1f644dc | 10791 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 10792 | struct intel_crtc_state *pipe_config) |
79e53945 | 10793 | { |
f1f644dc | 10794 | struct drm_device *dev = crtc->base.dev; |
79e53945 | 10795 | struct drm_i915_private *dev_priv = dev->dev_private; |
f1f644dc | 10796 | int pipe = pipe_config->cpu_transcoder; |
293623f7 | 10797 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
79e53945 | 10798 | u32 fp; |
9e2c8475 | 10799 | struct dpll clock; |
dccbea3b | 10800 | int port_clock; |
da4a1efa | 10801 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
79e53945 JB |
10802 | |
10803 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) | |
293623f7 | 10804 | fp = pipe_config->dpll_hw_state.fp0; |
79e53945 | 10805 | else |
293623f7 | 10806 | fp = pipe_config->dpll_hw_state.fp1; |
79e53945 JB |
10807 | |
10808 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; | |
f2b115e6 AJ |
10809 | if (IS_PINEVIEW(dev)) { |
10810 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; | |
10811 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
2177832f SL |
10812 | } else { |
10813 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; | |
10814 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
10815 | } | |
10816 | ||
a6c45cf0 | 10817 | if (!IS_GEN2(dev)) { |
f2b115e6 AJ |
10818 | if (IS_PINEVIEW(dev)) |
10819 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> | |
10820 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); | |
2177832f SL |
10821 | else |
10822 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> | |
79e53945 JB |
10823 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
10824 | ||
10825 | switch (dpll & DPLL_MODE_MASK) { | |
10826 | case DPLLB_MODE_DAC_SERIAL: | |
10827 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? | |
10828 | 5 : 10; | |
10829 | break; | |
10830 | case DPLLB_MODE_LVDS: | |
10831 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? | |
10832 | 7 : 14; | |
10833 | break; | |
10834 | default: | |
28c97730 | 10835 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
79e53945 | 10836 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
f1f644dc | 10837 | return; |
79e53945 JB |
10838 | } |
10839 | ||
ac58c3f0 | 10840 | if (IS_PINEVIEW(dev)) |
dccbea3b | 10841 | port_clock = pnv_calc_dpll_params(refclk, &clock); |
ac58c3f0 | 10842 | else |
dccbea3b | 10843 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
79e53945 | 10844 | } else { |
0fb58223 | 10845 | u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS); |
b1c560d1 | 10846 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
79e53945 JB |
10847 | |
10848 | if (is_lvds) { | |
10849 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> | |
10850 | DPLL_FPA01_P1_POST_DIV_SHIFT); | |
b1c560d1 VS |
10851 | |
10852 | if (lvds & LVDS_CLKB_POWER_UP) | |
10853 | clock.p2 = 7; | |
10854 | else | |
10855 | clock.p2 = 14; | |
79e53945 JB |
10856 | } else { |
10857 | if (dpll & PLL_P1_DIVIDE_BY_TWO) | |
10858 | clock.p1 = 2; | |
10859 | else { | |
10860 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> | |
10861 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; | |
10862 | } | |
10863 | if (dpll & PLL_P2_DIVIDE_BY_4) | |
10864 | clock.p2 = 4; | |
10865 | else | |
10866 | clock.p2 = 2; | |
79e53945 | 10867 | } |
da4a1efa | 10868 | |
dccbea3b | 10869 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
79e53945 JB |
10870 | } |
10871 | ||
18442d08 VS |
10872 | /* |
10873 | * This value includes pixel_multiplier. We will use | |
241bfc38 | 10874 | * port_clock to compute adjusted_mode.crtc_clock in the |
18442d08 VS |
10875 | * encoder's get_config() function. |
10876 | */ | |
dccbea3b | 10877 | pipe_config->port_clock = port_clock; |
f1f644dc JB |
10878 | } |
10879 | ||
6878da05 VS |
10880 | int intel_dotclock_calculate(int link_freq, |
10881 | const struct intel_link_m_n *m_n) | |
f1f644dc | 10882 | { |
f1f644dc JB |
10883 | /* |
10884 | * The calculation for the data clock is: | |
1041a02f | 10885 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
f1f644dc | 10886 | * But we want to avoid losing precison if possible, so: |
1041a02f | 10887 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
f1f644dc JB |
10888 | * |
10889 | * and the link clock is simpler: | |
1041a02f | 10890 | * link_clock = (m * link_clock) / n |
f1f644dc JB |
10891 | */ |
10892 | ||
6878da05 VS |
10893 | if (!m_n->link_n) |
10894 | return 0; | |
f1f644dc | 10895 | |
6878da05 VS |
10896 | return div_u64((u64)m_n->link_m * link_freq, m_n->link_n); |
10897 | } | |
f1f644dc | 10898 | |
18442d08 | 10899 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
5cec258b | 10900 | struct intel_crtc_state *pipe_config) |
6878da05 | 10901 | { |
e3b247da | 10902 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
79e53945 | 10903 | |
18442d08 VS |
10904 | /* read out port_clock from the DPLL */ |
10905 | i9xx_crtc_clock_get(crtc, pipe_config); | |
f1f644dc | 10906 | |
f1f644dc | 10907 | /* |
e3b247da VS |
10908 | * In case there is an active pipe without active ports, |
10909 | * we may need some idea for the dotclock anyway. | |
10910 | * Calculate one based on the FDI configuration. | |
79e53945 | 10911 | */ |
2d112de7 | 10912 | pipe_config->base.adjusted_mode.crtc_clock = |
21a727b3 | 10913 | intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config), |
18442d08 | 10914 | &pipe_config->fdi_m_n); |
79e53945 JB |
10915 | } |
10916 | ||
10917 | /** Returns the currently programmed mode of the given pipe. */ | |
10918 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, | |
10919 | struct drm_crtc *crtc) | |
10920 | { | |
548f245b | 10921 | struct drm_i915_private *dev_priv = dev->dev_private; |
79e53945 | 10922 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
6e3c9717 | 10923 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
79e53945 | 10924 | struct drm_display_mode *mode; |
3f36b937 | 10925 | struct intel_crtc_state *pipe_config; |
fe2b8f9d PZ |
10926 | int htot = I915_READ(HTOTAL(cpu_transcoder)); |
10927 | int hsync = I915_READ(HSYNC(cpu_transcoder)); | |
10928 | int vtot = I915_READ(VTOTAL(cpu_transcoder)); | |
10929 | int vsync = I915_READ(VSYNC(cpu_transcoder)); | |
293623f7 | 10930 | enum pipe pipe = intel_crtc->pipe; |
79e53945 JB |
10931 | |
10932 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); | |
10933 | if (!mode) | |
10934 | return NULL; | |
10935 | ||
3f36b937 TU |
10936 | pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); |
10937 | if (!pipe_config) { | |
10938 | kfree(mode); | |
10939 | return NULL; | |
10940 | } | |
10941 | ||
f1f644dc JB |
10942 | /* |
10943 | * Construct a pipe_config sufficient for getting the clock info | |
10944 | * back out of crtc_clock_get. | |
10945 | * | |
10946 | * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need | |
10947 | * to use a real value here instead. | |
10948 | */ | |
3f36b937 TU |
10949 | pipe_config->cpu_transcoder = (enum transcoder) pipe; |
10950 | pipe_config->pixel_multiplier = 1; | |
10951 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(pipe)); | |
10952 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(pipe)); | |
10953 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(pipe)); | |
10954 | i9xx_crtc_clock_get(intel_crtc, pipe_config); | |
10955 | ||
10956 | mode->clock = pipe_config->port_clock / pipe_config->pixel_multiplier; | |
79e53945 JB |
10957 | mode->hdisplay = (htot & 0xffff) + 1; |
10958 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; | |
10959 | mode->hsync_start = (hsync & 0xffff) + 1; | |
10960 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; | |
10961 | mode->vdisplay = (vtot & 0xffff) + 1; | |
10962 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; | |
10963 | mode->vsync_start = (vsync & 0xffff) + 1; | |
10964 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; | |
10965 | ||
10966 | drm_mode_set_name(mode); | |
79e53945 | 10967 | |
3f36b937 TU |
10968 | kfree(pipe_config); |
10969 | ||
79e53945 JB |
10970 | return mode; |
10971 | } | |
10972 | ||
7d993739 | 10973 | void intel_mark_busy(struct drm_i915_private *dev_priv) |
f047e395 | 10974 | { |
f62a0076 CW |
10975 | if (dev_priv->mm.busy) |
10976 | return; | |
10977 | ||
43694d69 | 10978 | intel_runtime_pm_get(dev_priv); |
c67a470b | 10979 | i915_update_gfx_val(dev_priv); |
7d993739 | 10980 | if (INTEL_GEN(dev_priv) >= 6) |
43cf3bf0 | 10981 | gen6_rps_busy(dev_priv); |
f62a0076 | 10982 | dev_priv->mm.busy = true; |
f047e395 CW |
10983 | } |
10984 | ||
7d993739 | 10985 | void intel_mark_idle(struct drm_i915_private *dev_priv) |
652c393a | 10986 | { |
f62a0076 CW |
10987 | if (!dev_priv->mm.busy) |
10988 | return; | |
10989 | ||
10990 | dev_priv->mm.busy = false; | |
10991 | ||
7d993739 TU |
10992 | if (INTEL_GEN(dev_priv) >= 6) |
10993 | gen6_rps_idle(dev_priv); | |
bb4cdd53 | 10994 | |
43694d69 | 10995 | intel_runtime_pm_put(dev_priv); |
652c393a JB |
10996 | } |
10997 | ||
79e53945 JB |
10998 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
10999 | { | |
11000 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
67e77c5a | 11001 | struct drm_device *dev = crtc->dev; |
51cbaf01 | 11002 | struct intel_flip_work *work; |
67e77c5a | 11003 | |
5e2d7afc | 11004 | spin_lock_irq(&dev->event_lock); |
5a21b665 DV |
11005 | work = intel_crtc->flip_work; |
11006 | intel_crtc->flip_work = NULL; | |
11007 | spin_unlock_irq(&dev->event_lock); | |
67e77c5a | 11008 | |
5a21b665 | 11009 | if (work) { |
51cbaf01 ML |
11010 | cancel_work_sync(&work->mmio_work); |
11011 | cancel_work_sync(&work->unpin_work); | |
5a21b665 | 11012 | kfree(work); |
67e77c5a | 11013 | } |
79e53945 JB |
11014 | |
11015 | drm_crtc_cleanup(crtc); | |
67e77c5a | 11016 | |
79e53945 JB |
11017 | kfree(intel_crtc); |
11018 | } | |
11019 | ||
6b95a207 KH |
11020 | static void intel_unpin_work_fn(struct work_struct *__work) |
11021 | { | |
51cbaf01 ML |
11022 | struct intel_flip_work *work = |
11023 | container_of(__work, struct intel_flip_work, unpin_work); | |
5a21b665 DV |
11024 | struct intel_crtc *crtc = to_intel_crtc(work->crtc); |
11025 | struct drm_device *dev = crtc->base.dev; | |
11026 | struct drm_plane *primary = crtc->base.primary; | |
03f476e1 | 11027 | |
5a21b665 DV |
11028 | if (is_mmio_work(work)) |
11029 | flush_work(&work->mmio_work); | |
03f476e1 | 11030 | |
5a21b665 DV |
11031 | mutex_lock(&dev->struct_mutex); |
11032 | intel_unpin_fb_obj(work->old_fb, primary->state->rotation); | |
11033 | drm_gem_object_unreference(&work->pending_flip_obj->base); | |
143f73b3 | 11034 | |
5a21b665 DV |
11035 | if (work->flip_queued_req) |
11036 | i915_gem_request_assign(&work->flip_queued_req, NULL); | |
11037 | mutex_unlock(&dev->struct_mutex); | |
143f73b3 | 11038 | |
5a21b665 DV |
11039 | intel_frontbuffer_flip_complete(dev, to_intel_plane(primary)->frontbuffer_bit); |
11040 | intel_fbc_post_update(crtc); | |
11041 | drm_framebuffer_unreference(work->old_fb); | |
143f73b3 | 11042 | |
5a21b665 DV |
11043 | BUG_ON(atomic_read(&crtc->unpin_work_count) == 0); |
11044 | atomic_dec(&crtc->unpin_work_count); | |
a6747b73 | 11045 | |
5a21b665 DV |
11046 | kfree(work); |
11047 | } | |
d9e86c0e | 11048 | |
5a21b665 DV |
11049 | /* Is 'a' after or equal to 'b'? */ |
11050 | static bool g4x_flip_count_after_eq(u32 a, u32 b) | |
11051 | { | |
11052 | return !((a - b) & 0x80000000); | |
11053 | } | |
143f73b3 | 11054 | |
5a21b665 DV |
11055 | static bool __pageflip_finished_cs(struct intel_crtc *crtc, |
11056 | struct intel_flip_work *work) | |
11057 | { | |
11058 | struct drm_device *dev = crtc->base.dev; | |
11059 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11060 | unsigned reset_counter; | |
143f73b3 | 11061 | |
5a21b665 DV |
11062 | reset_counter = i915_reset_counter(&dev_priv->gpu_error); |
11063 | if (crtc->reset_counter != reset_counter) | |
11064 | return true; | |
143f73b3 | 11065 | |
5a21b665 DV |
11066 | /* |
11067 | * The relevant registers doen't exist on pre-ctg. | |
11068 | * As the flip done interrupt doesn't trigger for mmio | |
11069 | * flips on gmch platforms, a flip count check isn't | |
11070 | * really needed there. But since ctg has the registers, | |
11071 | * include it in the check anyway. | |
11072 | */ | |
11073 | if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev)) | |
11074 | return true; | |
b4a98e57 | 11075 | |
5a21b665 DV |
11076 | /* |
11077 | * BDW signals flip done immediately if the plane | |
11078 | * is disabled, even if the plane enable is already | |
11079 | * armed to occur at the next vblank :( | |
11080 | */ | |
f99d7069 | 11081 | |
5a21b665 DV |
11082 | /* |
11083 | * A DSPSURFLIVE check isn't enough in case the mmio and CS flips | |
11084 | * used the same base address. In that case the mmio flip might | |
11085 | * have completed, but the CS hasn't even executed the flip yet. | |
11086 | * | |
11087 | * A flip count check isn't enough as the CS might have updated | |
11088 | * the base address just after start of vblank, but before we | |
11089 | * managed to process the interrupt. This means we'd complete the | |
11090 | * CS flip too soon. | |
11091 | * | |
11092 | * Combining both checks should get us a good enough result. It may | |
11093 | * still happen that the CS flip has been executed, but has not | |
11094 | * yet actually completed. But in case the base address is the same | |
11095 | * anyway, we don't really care. | |
11096 | */ | |
11097 | return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) == | |
11098 | crtc->flip_work->gtt_offset && | |
11099 | g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_G4X(crtc->pipe)), | |
11100 | crtc->flip_work->flip_count); | |
11101 | } | |
b4a98e57 | 11102 | |
5a21b665 DV |
11103 | static bool |
11104 | __pageflip_finished_mmio(struct intel_crtc *crtc, | |
11105 | struct intel_flip_work *work) | |
11106 | { | |
11107 | /* | |
11108 | * MMIO work completes when vblank is different from | |
11109 | * flip_queued_vblank. | |
11110 | * | |
11111 | * Reset counter value doesn't matter, this is handled by | |
11112 | * i915_wait_request finishing early, so no need to handle | |
11113 | * reset here. | |
11114 | */ | |
11115 | return intel_crtc_get_vblank_counter(crtc) != work->flip_queued_vblank; | |
6b95a207 KH |
11116 | } |
11117 | ||
51cbaf01 ML |
11118 | |
11119 | static bool pageflip_finished(struct intel_crtc *crtc, | |
11120 | struct intel_flip_work *work) | |
11121 | { | |
11122 | if (!atomic_read(&work->pending)) | |
11123 | return false; | |
11124 | ||
11125 | smp_rmb(); | |
11126 | ||
5a21b665 DV |
11127 | if (is_mmio_work(work)) |
11128 | return __pageflip_finished_mmio(crtc, work); | |
11129 | else | |
11130 | return __pageflip_finished_cs(crtc, work); | |
11131 | } | |
11132 | ||
11133 | void intel_finish_page_flip_cs(struct drm_i915_private *dev_priv, int pipe) | |
11134 | { | |
11135 | struct drm_device *dev = dev_priv->dev; | |
11136 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
11137 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11138 | struct intel_flip_work *work; | |
11139 | unsigned long flags; | |
11140 | ||
11141 | /* Ignore early vblank irqs */ | |
11142 | if (!crtc) | |
11143 | return; | |
11144 | ||
51cbaf01 | 11145 | /* |
5a21b665 DV |
11146 | * This is called both by irq handlers and the reset code (to complete |
11147 | * lost pageflips) so needs the full irqsave spinlocks. | |
51cbaf01 | 11148 | */ |
5a21b665 DV |
11149 | spin_lock_irqsave(&dev->event_lock, flags); |
11150 | work = intel_crtc->flip_work; | |
11151 | ||
11152 | if (work != NULL && | |
11153 | !is_mmio_work(work) && | |
11154 | pageflip_finished(intel_crtc, work)) | |
11155 | page_flip_completed(intel_crtc); | |
11156 | ||
11157 | spin_unlock_irqrestore(&dev->event_lock, flags); | |
75f7f3ec VS |
11158 | } |
11159 | ||
51cbaf01 | 11160 | void intel_finish_page_flip_mmio(struct drm_i915_private *dev_priv, int pipe) |
6b95a207 | 11161 | { |
91d14251 | 11162 | struct drm_device *dev = dev_priv->dev; |
5251f04e ML |
11163 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
11164 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
51cbaf01 | 11165 | struct intel_flip_work *work; |
6b95a207 KH |
11166 | unsigned long flags; |
11167 | ||
5251f04e ML |
11168 | /* Ignore early vblank irqs */ |
11169 | if (!crtc) | |
11170 | return; | |
f326038a DV |
11171 | |
11172 | /* | |
11173 | * This is called both by irq handlers and the reset code (to complete | |
11174 | * lost pageflips) so needs the full irqsave spinlocks. | |
e7d841ca | 11175 | */ |
6b95a207 | 11176 | spin_lock_irqsave(&dev->event_lock, flags); |
5a21b665 | 11177 | work = intel_crtc->flip_work; |
5251f04e | 11178 | |
5a21b665 DV |
11179 | if (work != NULL && |
11180 | is_mmio_work(work) && | |
11181 | pageflip_finished(intel_crtc, work)) | |
11182 | page_flip_completed(intel_crtc); | |
5251f04e | 11183 | |
6b95a207 KH |
11184 | spin_unlock_irqrestore(&dev->event_lock, flags); |
11185 | } | |
11186 | ||
5a21b665 DV |
11187 | static inline void intel_mark_page_flip_active(struct intel_crtc *crtc, |
11188 | struct intel_flip_work *work) | |
84c33a64 | 11189 | { |
5a21b665 | 11190 | work->flip_queued_vblank = intel_crtc_get_vblank_counter(crtc); |
84c33a64 | 11191 | |
5a21b665 DV |
11192 | /* Ensure that the work item is consistent when activating it ... */ |
11193 | smp_mb__before_atomic(); | |
11194 | atomic_set(&work->pending, 1); | |
11195 | } | |
a6747b73 | 11196 | |
5a21b665 DV |
11197 | static int intel_gen2_queue_flip(struct drm_device *dev, |
11198 | struct drm_crtc *crtc, | |
11199 | struct drm_framebuffer *fb, | |
11200 | struct drm_i915_gem_object *obj, | |
11201 | struct drm_i915_gem_request *req, | |
11202 | uint32_t flags) | |
11203 | { | |
11204 | struct intel_engine_cs *engine = req->engine; | |
11205 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11206 | u32 flip_mask; | |
11207 | int ret; | |
143f73b3 | 11208 | |
5a21b665 DV |
11209 | ret = intel_ring_begin(req, 6); |
11210 | if (ret) | |
11211 | return ret; | |
143f73b3 | 11212 | |
5a21b665 DV |
11213 | /* Can't queue multiple flips, so wait for the previous |
11214 | * one to finish before executing the next. | |
11215 | */ | |
11216 | if (intel_crtc->plane) | |
11217 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; | |
11218 | else | |
11219 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; | |
11220 | intel_ring_emit(engine, MI_WAIT_FOR_EVENT | flip_mask); | |
11221 | intel_ring_emit(engine, MI_NOOP); | |
11222 | intel_ring_emit(engine, MI_DISPLAY_FLIP | | |
11223 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
11224 | intel_ring_emit(engine, fb->pitches[0]); | |
11225 | intel_ring_emit(engine, intel_crtc->flip_work->gtt_offset); | |
11226 | intel_ring_emit(engine, 0); /* aux display base address, unused */ | |
143f73b3 | 11227 | |
5a21b665 DV |
11228 | return 0; |
11229 | } | |
84c33a64 | 11230 | |
5a21b665 DV |
11231 | static int intel_gen3_queue_flip(struct drm_device *dev, |
11232 | struct drm_crtc *crtc, | |
11233 | struct drm_framebuffer *fb, | |
11234 | struct drm_i915_gem_object *obj, | |
11235 | struct drm_i915_gem_request *req, | |
11236 | uint32_t flags) | |
11237 | { | |
11238 | struct intel_engine_cs *engine = req->engine; | |
11239 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11240 | u32 flip_mask; | |
11241 | int ret; | |
d55dbd06 | 11242 | |
5a21b665 DV |
11243 | ret = intel_ring_begin(req, 6); |
11244 | if (ret) | |
11245 | return ret; | |
d55dbd06 | 11246 | |
5a21b665 DV |
11247 | if (intel_crtc->plane) |
11248 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; | |
11249 | else | |
11250 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; | |
11251 | intel_ring_emit(engine, MI_WAIT_FOR_EVENT | flip_mask); | |
11252 | intel_ring_emit(engine, MI_NOOP); | |
11253 | intel_ring_emit(engine, MI_DISPLAY_FLIP_I915 | | |
11254 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
11255 | intel_ring_emit(engine, fb->pitches[0]); | |
11256 | intel_ring_emit(engine, intel_crtc->flip_work->gtt_offset); | |
11257 | intel_ring_emit(engine, MI_NOOP); | |
fd8e058a | 11258 | |
5a21b665 DV |
11259 | return 0; |
11260 | } | |
84c33a64 | 11261 | |
5a21b665 DV |
11262 | static int intel_gen4_queue_flip(struct drm_device *dev, |
11263 | struct drm_crtc *crtc, | |
11264 | struct drm_framebuffer *fb, | |
11265 | struct drm_i915_gem_object *obj, | |
11266 | struct drm_i915_gem_request *req, | |
11267 | uint32_t flags) | |
11268 | { | |
11269 | struct intel_engine_cs *engine = req->engine; | |
11270 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11271 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11272 | uint32_t pf, pipesrc; | |
11273 | int ret; | |
143f73b3 | 11274 | |
5a21b665 DV |
11275 | ret = intel_ring_begin(req, 4); |
11276 | if (ret) | |
11277 | return ret; | |
143f73b3 | 11278 | |
5a21b665 DV |
11279 | /* i965+ uses the linear or tiled offsets from the |
11280 | * Display Registers (which do not change across a page-flip) | |
11281 | * so we need only reprogram the base address. | |
11282 | */ | |
11283 | intel_ring_emit(engine, MI_DISPLAY_FLIP | | |
11284 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
11285 | intel_ring_emit(engine, fb->pitches[0]); | |
11286 | intel_ring_emit(engine, intel_crtc->flip_work->gtt_offset | | |
11287 | obj->tiling_mode); | |
11288 | ||
11289 | /* XXX Enabling the panel-fitter across page-flip is so far | |
11290 | * untested on non-native modes, so ignore it for now. | |
11291 | * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE; | |
11292 | */ | |
11293 | pf = 0; | |
11294 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; | |
11295 | intel_ring_emit(engine, pf | pipesrc); | |
143f73b3 | 11296 | |
5a21b665 | 11297 | return 0; |
8c9f3aaf JB |
11298 | } |
11299 | ||
5a21b665 DV |
11300 | static int intel_gen6_queue_flip(struct drm_device *dev, |
11301 | struct drm_crtc *crtc, | |
11302 | struct drm_framebuffer *fb, | |
11303 | struct drm_i915_gem_object *obj, | |
11304 | struct drm_i915_gem_request *req, | |
11305 | uint32_t flags) | |
da20eabd | 11306 | { |
5a21b665 DV |
11307 | struct intel_engine_cs *engine = req->engine; |
11308 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11309 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11310 | uint32_t pf, pipesrc; | |
11311 | int ret; | |
d21fbe87 | 11312 | |
5a21b665 DV |
11313 | ret = intel_ring_begin(req, 4); |
11314 | if (ret) | |
11315 | return ret; | |
92826fcd | 11316 | |
5a21b665 DV |
11317 | intel_ring_emit(engine, MI_DISPLAY_FLIP | |
11318 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); | |
11319 | intel_ring_emit(engine, fb->pitches[0] | obj->tiling_mode); | |
11320 | intel_ring_emit(engine, intel_crtc->flip_work->gtt_offset); | |
92826fcd | 11321 | |
5a21b665 DV |
11322 | /* Contrary to the suggestions in the documentation, |
11323 | * "Enable Panel Fitter" does not seem to be required when page | |
11324 | * flipping with a non-native mode, and worse causes a normal | |
11325 | * modeset to fail. | |
11326 | * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE; | |
11327 | */ | |
11328 | pf = 0; | |
11329 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; | |
11330 | intel_ring_emit(engine, pf | pipesrc); | |
7809e5ae | 11331 | |
5a21b665 | 11332 | return 0; |
7809e5ae MR |
11333 | } |
11334 | ||
5a21b665 DV |
11335 | static int intel_gen7_queue_flip(struct drm_device *dev, |
11336 | struct drm_crtc *crtc, | |
11337 | struct drm_framebuffer *fb, | |
11338 | struct drm_i915_gem_object *obj, | |
11339 | struct drm_i915_gem_request *req, | |
11340 | uint32_t flags) | |
d21fbe87 | 11341 | { |
5a21b665 DV |
11342 | struct intel_engine_cs *engine = req->engine; |
11343 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11344 | uint32_t plane_bit = 0; | |
11345 | int len, ret; | |
d21fbe87 | 11346 | |
5a21b665 DV |
11347 | switch (intel_crtc->plane) { |
11348 | case PLANE_A: | |
11349 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A; | |
11350 | break; | |
11351 | case PLANE_B: | |
11352 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B; | |
11353 | break; | |
11354 | case PLANE_C: | |
11355 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C; | |
11356 | break; | |
11357 | default: | |
11358 | WARN_ONCE(1, "unknown plane in flip command\n"); | |
11359 | return -ENODEV; | |
11360 | } | |
11361 | ||
11362 | len = 4; | |
11363 | if (engine->id == RCS) { | |
11364 | len += 6; | |
11365 | /* | |
11366 | * On Gen 8, SRM is now taking an extra dword to accommodate | |
11367 | * 48bits addresses, and we need a NOOP for the batch size to | |
11368 | * stay even. | |
11369 | */ | |
11370 | if (IS_GEN8(dev)) | |
11371 | len += 2; | |
11372 | } | |
11373 | ||
11374 | /* | |
11375 | * BSpec MI_DISPLAY_FLIP for IVB: | |
11376 | * "The full packet must be contained within the same cache line." | |
11377 | * | |
11378 | * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same | |
11379 | * cacheline, if we ever start emitting more commands before | |
11380 | * the MI_DISPLAY_FLIP we may need to first emit everything else, | |
11381 | * then do the cacheline alignment, and finally emit the | |
11382 | * MI_DISPLAY_FLIP. | |
11383 | */ | |
11384 | ret = intel_ring_cacheline_align(req); | |
11385 | if (ret) | |
11386 | return ret; | |
11387 | ||
11388 | ret = intel_ring_begin(req, len); | |
11389 | if (ret) | |
11390 | return ret; | |
11391 | ||
11392 | /* Unmask the flip-done completion message. Note that the bspec says that | |
11393 | * we should do this for both the BCS and RCS, and that we must not unmask | |
11394 | * more than one flip event at any time (or ensure that one flip message | |
11395 | * can be sent by waiting for flip-done prior to queueing new flips). | |
11396 | * Experimentation says that BCS works despite DERRMR masking all | |
11397 | * flip-done completion events and that unmasking all planes at once | |
11398 | * for the RCS also doesn't appear to drop events. Setting the DERRMR | |
11399 | * to zero does lead to lockups within MI_DISPLAY_FLIP. | |
11400 | */ | |
11401 | if (engine->id == RCS) { | |
11402 | intel_ring_emit(engine, MI_LOAD_REGISTER_IMM(1)); | |
11403 | intel_ring_emit_reg(engine, DERRMR); | |
11404 | intel_ring_emit(engine, ~(DERRMR_PIPEA_PRI_FLIP_DONE | | |
11405 | DERRMR_PIPEB_PRI_FLIP_DONE | | |
11406 | DERRMR_PIPEC_PRI_FLIP_DONE)); | |
11407 | if (IS_GEN8(dev)) | |
11408 | intel_ring_emit(engine, MI_STORE_REGISTER_MEM_GEN8 | | |
11409 | MI_SRM_LRM_GLOBAL_GTT); | |
11410 | else | |
11411 | intel_ring_emit(engine, MI_STORE_REGISTER_MEM | | |
11412 | MI_SRM_LRM_GLOBAL_GTT); | |
11413 | intel_ring_emit_reg(engine, DERRMR); | |
11414 | intel_ring_emit(engine, engine->scratch.gtt_offset + 256); | |
11415 | if (IS_GEN8(dev)) { | |
11416 | intel_ring_emit(engine, 0); | |
11417 | intel_ring_emit(engine, MI_NOOP); | |
11418 | } | |
11419 | } | |
11420 | ||
11421 | intel_ring_emit(engine, MI_DISPLAY_FLIP_I915 | plane_bit); | |
11422 | intel_ring_emit(engine, (fb->pitches[0] | obj->tiling_mode)); | |
11423 | intel_ring_emit(engine, intel_crtc->flip_work->gtt_offset); | |
11424 | intel_ring_emit(engine, (MI_NOOP)); | |
11425 | ||
11426 | return 0; | |
11427 | } | |
11428 | ||
11429 | static bool use_mmio_flip(struct intel_engine_cs *engine, | |
11430 | struct drm_i915_gem_object *obj) | |
11431 | { | |
c37efb99 CW |
11432 | struct reservation_object *resv; |
11433 | ||
5a21b665 DV |
11434 | /* |
11435 | * This is not being used for older platforms, because | |
11436 | * non-availability of flip done interrupt forces us to use | |
11437 | * CS flips. Older platforms derive flip done using some clever | |
11438 | * tricks involving the flip_pending status bits and vblank irqs. | |
11439 | * So using MMIO flips there would disrupt this mechanism. | |
11440 | */ | |
11441 | ||
11442 | if (engine == NULL) | |
11443 | return true; | |
11444 | ||
11445 | if (INTEL_GEN(engine->i915) < 5) | |
11446 | return false; | |
11447 | ||
11448 | if (i915.use_mmio_flip < 0) | |
11449 | return false; | |
11450 | else if (i915.use_mmio_flip > 0) | |
11451 | return true; | |
11452 | else if (i915.enable_execlists) | |
11453 | return true; | |
c37efb99 CW |
11454 | |
11455 | resv = i915_gem_object_get_dmabuf_resv(obj); | |
11456 | if (resv && !reservation_object_test_signaled_rcu(resv, false)) | |
5a21b665 | 11457 | return true; |
c37efb99 CW |
11458 | |
11459 | return engine != i915_gem_request_get_engine(obj->last_write_req); | |
5a21b665 DV |
11460 | } |
11461 | ||
11462 | static void skl_do_mmio_flip(struct intel_crtc *intel_crtc, | |
11463 | unsigned int rotation, | |
11464 | struct intel_flip_work *work) | |
11465 | { | |
11466 | struct drm_device *dev = intel_crtc->base.dev; | |
11467 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11468 | struct drm_framebuffer *fb = intel_crtc->base.primary->fb; | |
11469 | const enum pipe pipe = intel_crtc->pipe; | |
11470 | u32 ctl, stride, tile_height; | |
11471 | ||
11472 | ctl = I915_READ(PLANE_CTL(pipe, 0)); | |
11473 | ctl &= ~PLANE_CTL_TILED_MASK; | |
11474 | switch (fb->modifier[0]) { | |
11475 | case DRM_FORMAT_MOD_NONE: | |
11476 | break; | |
11477 | case I915_FORMAT_MOD_X_TILED: | |
11478 | ctl |= PLANE_CTL_TILED_X; | |
11479 | break; | |
11480 | case I915_FORMAT_MOD_Y_TILED: | |
11481 | ctl |= PLANE_CTL_TILED_Y; | |
11482 | break; | |
11483 | case I915_FORMAT_MOD_Yf_TILED: | |
11484 | ctl |= PLANE_CTL_TILED_YF; | |
11485 | break; | |
11486 | default: | |
11487 | MISSING_CASE(fb->modifier[0]); | |
11488 | } | |
11489 | ||
11490 | /* | |
11491 | * The stride is either expressed as a multiple of 64 bytes chunks for | |
11492 | * linear buffers or in number of tiles for tiled buffers. | |
11493 | */ | |
11494 | if (intel_rotation_90_or_270(rotation)) { | |
11495 | /* stride = Surface height in tiles */ | |
11496 | tile_height = intel_tile_height(dev_priv, fb->modifier[0], 0); | |
11497 | stride = DIV_ROUND_UP(fb->height, tile_height); | |
11498 | } else { | |
11499 | stride = fb->pitches[0] / | |
11500 | intel_fb_stride_alignment(dev_priv, fb->modifier[0], | |
11501 | fb->pixel_format); | |
11502 | } | |
11503 | ||
11504 | /* | |
11505 | * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on | |
11506 | * PLANE_SURF updates, the update is then guaranteed to be atomic. | |
11507 | */ | |
11508 | I915_WRITE(PLANE_CTL(pipe, 0), ctl); | |
11509 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); | |
11510 | ||
11511 | I915_WRITE(PLANE_SURF(pipe, 0), work->gtt_offset); | |
11512 | POSTING_READ(PLANE_SURF(pipe, 0)); | |
11513 | } | |
11514 | ||
11515 | static void ilk_do_mmio_flip(struct intel_crtc *intel_crtc, | |
11516 | struct intel_flip_work *work) | |
11517 | { | |
11518 | struct drm_device *dev = intel_crtc->base.dev; | |
11519 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11520 | struct intel_framebuffer *intel_fb = | |
11521 | to_intel_framebuffer(intel_crtc->base.primary->fb); | |
11522 | struct drm_i915_gem_object *obj = intel_fb->obj; | |
11523 | i915_reg_t reg = DSPCNTR(intel_crtc->plane); | |
11524 | u32 dspcntr; | |
11525 | ||
11526 | dspcntr = I915_READ(reg); | |
11527 | ||
11528 | if (obj->tiling_mode != I915_TILING_NONE) | |
11529 | dspcntr |= DISPPLANE_TILED; | |
11530 | else | |
11531 | dspcntr &= ~DISPPLANE_TILED; | |
11532 | ||
11533 | I915_WRITE(reg, dspcntr); | |
11534 | ||
11535 | I915_WRITE(DSPSURF(intel_crtc->plane), work->gtt_offset); | |
11536 | POSTING_READ(DSPSURF(intel_crtc->plane)); | |
11537 | } | |
11538 | ||
11539 | static void intel_mmio_flip_work_func(struct work_struct *w) | |
11540 | { | |
11541 | struct intel_flip_work *work = | |
11542 | container_of(w, struct intel_flip_work, mmio_work); | |
11543 | struct intel_crtc *crtc = to_intel_crtc(work->crtc); | |
11544 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); | |
11545 | struct intel_framebuffer *intel_fb = | |
11546 | to_intel_framebuffer(crtc->base.primary->fb); | |
11547 | struct drm_i915_gem_object *obj = intel_fb->obj; | |
c37efb99 | 11548 | struct reservation_object *resv; |
5a21b665 DV |
11549 | |
11550 | if (work->flip_queued_req) | |
11551 | WARN_ON(__i915_wait_request(work->flip_queued_req, | |
11552 | false, NULL, | |
11553 | &dev_priv->rps.mmioflips)); | |
11554 | ||
11555 | /* For framebuffer backed by dmabuf, wait for fence */ | |
c37efb99 CW |
11556 | resv = i915_gem_object_get_dmabuf_resv(obj); |
11557 | if (resv) | |
11558 | WARN_ON(reservation_object_wait_timeout_rcu(resv, false, false, | |
5a21b665 DV |
11559 | MAX_SCHEDULE_TIMEOUT) < 0); |
11560 | ||
11561 | intel_pipe_update_start(crtc); | |
11562 | ||
11563 | if (INTEL_GEN(dev_priv) >= 9) | |
11564 | skl_do_mmio_flip(crtc, work->rotation, work); | |
11565 | else | |
11566 | /* use_mmio_flip() retricts MMIO flips to ilk+ */ | |
11567 | ilk_do_mmio_flip(crtc, work); | |
11568 | ||
11569 | intel_pipe_update_end(crtc, work); | |
11570 | } | |
11571 | ||
11572 | static int intel_default_queue_flip(struct drm_device *dev, | |
11573 | struct drm_crtc *crtc, | |
11574 | struct drm_framebuffer *fb, | |
11575 | struct drm_i915_gem_object *obj, | |
11576 | struct drm_i915_gem_request *req, | |
11577 | uint32_t flags) | |
11578 | { | |
11579 | return -ENODEV; | |
11580 | } | |
11581 | ||
11582 | static bool __pageflip_stall_check_cs(struct drm_i915_private *dev_priv, | |
11583 | struct intel_crtc *intel_crtc, | |
11584 | struct intel_flip_work *work) | |
11585 | { | |
11586 | u32 addr, vblank; | |
11587 | ||
11588 | if (!atomic_read(&work->pending)) | |
11589 | return false; | |
11590 | ||
11591 | smp_rmb(); | |
11592 | ||
11593 | vblank = intel_crtc_get_vblank_counter(intel_crtc); | |
11594 | if (work->flip_ready_vblank == 0) { | |
11595 | if (work->flip_queued_req && | |
11596 | !i915_gem_request_completed(work->flip_queued_req, true)) | |
11597 | return false; | |
11598 | ||
11599 | work->flip_ready_vblank = vblank; | |
11600 | } | |
11601 | ||
11602 | if (vblank - work->flip_ready_vblank < 3) | |
11603 | return false; | |
11604 | ||
11605 | /* Potential stall - if we see that the flip has happened, | |
11606 | * assume a missed interrupt. */ | |
11607 | if (INTEL_GEN(dev_priv) >= 4) | |
11608 | addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane))); | |
11609 | else | |
11610 | addr = I915_READ(DSPADDR(intel_crtc->plane)); | |
11611 | ||
11612 | /* There is a potential issue here with a false positive after a flip | |
11613 | * to the same address. We could address this by checking for a | |
11614 | * non-incrementing frame counter. | |
11615 | */ | |
11616 | return addr == work->gtt_offset; | |
11617 | } | |
11618 | ||
11619 | void intel_check_page_flip(struct drm_i915_private *dev_priv, int pipe) | |
11620 | { | |
11621 | struct drm_device *dev = dev_priv->dev; | |
11622 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
11623 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11624 | struct intel_flip_work *work; | |
11625 | ||
11626 | WARN_ON(!in_interrupt()); | |
11627 | ||
11628 | if (crtc == NULL) | |
11629 | return; | |
11630 | ||
11631 | spin_lock(&dev->event_lock); | |
11632 | work = intel_crtc->flip_work; | |
11633 | ||
11634 | if (work != NULL && !is_mmio_work(work) && | |
11635 | __pageflip_stall_check_cs(dev_priv, intel_crtc, work)) { | |
11636 | WARN_ONCE(1, | |
11637 | "Kicking stuck page flip: queued at %d, now %d\n", | |
11638 | work->flip_queued_vblank, intel_crtc_get_vblank_counter(intel_crtc)); | |
11639 | page_flip_completed(intel_crtc); | |
11640 | work = NULL; | |
11641 | } | |
11642 | ||
11643 | if (work != NULL && !is_mmio_work(work) && | |
11644 | intel_crtc_get_vblank_counter(intel_crtc) - work->flip_queued_vblank > 1) | |
11645 | intel_queue_rps_boost_for_request(work->flip_queued_req); | |
11646 | spin_unlock(&dev->event_lock); | |
11647 | } | |
11648 | ||
ee042aa4 | 11649 | __maybe_unused |
5a21b665 DV |
11650 | static int intel_crtc_page_flip(struct drm_crtc *crtc, |
11651 | struct drm_framebuffer *fb, | |
11652 | struct drm_pending_vblank_event *event, | |
11653 | uint32_t page_flip_flags) | |
11654 | { | |
11655 | struct drm_device *dev = crtc->dev; | |
11656 | struct drm_i915_private *dev_priv = dev->dev_private; | |
11657 | struct drm_framebuffer *old_fb = crtc->primary->fb; | |
11658 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); | |
11659 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11660 | struct drm_plane *primary = crtc->primary; | |
11661 | enum pipe pipe = intel_crtc->pipe; | |
11662 | struct intel_flip_work *work; | |
11663 | struct intel_engine_cs *engine; | |
11664 | bool mmio_flip; | |
11665 | struct drm_i915_gem_request *request = NULL; | |
11666 | int ret; | |
11667 | ||
11668 | /* | |
11669 | * drm_mode_page_flip_ioctl() should already catch this, but double | |
11670 | * check to be safe. In the future we may enable pageflipping from | |
11671 | * a disabled primary plane. | |
11672 | */ | |
11673 | if (WARN_ON(intel_fb_obj(old_fb) == NULL)) | |
11674 | return -EBUSY; | |
11675 | ||
11676 | /* Can't change pixel format via MI display flips. */ | |
11677 | if (fb->pixel_format != crtc->primary->fb->pixel_format) | |
11678 | return -EINVAL; | |
11679 | ||
11680 | /* | |
11681 | * TILEOFF/LINOFF registers can't be changed via MI display flips. | |
11682 | * Note that pitch changes could also affect these register. | |
11683 | */ | |
11684 | if (INTEL_INFO(dev)->gen > 3 && | |
11685 | (fb->offsets[0] != crtc->primary->fb->offsets[0] || | |
11686 | fb->pitches[0] != crtc->primary->fb->pitches[0])) | |
11687 | return -EINVAL; | |
11688 | ||
11689 | if (i915_terminally_wedged(&dev_priv->gpu_error)) | |
11690 | goto out_hang; | |
11691 | ||
11692 | work = kzalloc(sizeof(*work), GFP_KERNEL); | |
11693 | if (work == NULL) | |
11694 | return -ENOMEM; | |
11695 | ||
11696 | work->event = event; | |
11697 | work->crtc = crtc; | |
11698 | work->old_fb = old_fb; | |
11699 | INIT_WORK(&work->unpin_work, intel_unpin_work_fn); | |
11700 | ||
11701 | ret = drm_crtc_vblank_get(crtc); | |
11702 | if (ret) | |
11703 | goto free_work; | |
11704 | ||
11705 | /* We borrow the event spin lock for protecting flip_work */ | |
11706 | spin_lock_irq(&dev->event_lock); | |
11707 | if (intel_crtc->flip_work) { | |
11708 | /* Before declaring the flip queue wedged, check if | |
11709 | * the hardware completed the operation behind our backs. | |
11710 | */ | |
11711 | if (pageflip_finished(intel_crtc, intel_crtc->flip_work)) { | |
11712 | DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n"); | |
11713 | page_flip_completed(intel_crtc); | |
11714 | } else { | |
11715 | DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); | |
11716 | spin_unlock_irq(&dev->event_lock); | |
11717 | ||
11718 | drm_crtc_vblank_put(crtc); | |
11719 | kfree(work); | |
11720 | return -EBUSY; | |
11721 | } | |
11722 | } | |
11723 | intel_crtc->flip_work = work; | |
11724 | spin_unlock_irq(&dev->event_lock); | |
11725 | ||
11726 | if (atomic_read(&intel_crtc->unpin_work_count) >= 2) | |
11727 | flush_workqueue(dev_priv->wq); | |
11728 | ||
11729 | /* Reference the objects for the scheduled work. */ | |
11730 | drm_framebuffer_reference(work->old_fb); | |
11731 | drm_gem_object_reference(&obj->base); | |
11732 | ||
11733 | crtc->primary->fb = fb; | |
11734 | update_state_fb(crtc->primary); | |
faf68d92 ML |
11735 | |
11736 | intel_fbc_pre_update(intel_crtc, intel_crtc->config, | |
11737 | to_intel_plane_state(primary->state)); | |
5a21b665 DV |
11738 | |
11739 | work->pending_flip_obj = obj; | |
11740 | ||
11741 | ret = i915_mutex_lock_interruptible(dev); | |
11742 | if (ret) | |
11743 | goto cleanup; | |
11744 | ||
11745 | intel_crtc->reset_counter = i915_reset_counter(&dev_priv->gpu_error); | |
11746 | if (__i915_reset_in_progress_or_wedged(intel_crtc->reset_counter)) { | |
11747 | ret = -EIO; | |
11748 | goto cleanup; | |
11749 | } | |
11750 | ||
11751 | atomic_inc(&intel_crtc->unpin_work_count); | |
11752 | ||
11753 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) | |
11754 | work->flip_count = I915_READ(PIPE_FLIPCOUNT_G4X(pipe)) + 1; | |
11755 | ||
11756 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { | |
11757 | engine = &dev_priv->engine[BCS]; | |
11758 | if (obj->tiling_mode != intel_fb_obj(work->old_fb)->tiling_mode) | |
11759 | /* vlv: DISPLAY_FLIP fails to change tiling */ | |
11760 | engine = NULL; | |
11761 | } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) { | |
11762 | engine = &dev_priv->engine[BCS]; | |
11763 | } else if (INTEL_INFO(dev)->gen >= 7) { | |
11764 | engine = i915_gem_request_get_engine(obj->last_write_req); | |
11765 | if (engine == NULL || engine->id != RCS) | |
11766 | engine = &dev_priv->engine[BCS]; | |
11767 | } else { | |
11768 | engine = &dev_priv->engine[RCS]; | |
11769 | } | |
11770 | ||
11771 | mmio_flip = use_mmio_flip(engine, obj); | |
11772 | ||
11773 | /* When using CS flips, we want to emit semaphores between rings. | |
11774 | * However, when using mmio flips we will create a task to do the | |
11775 | * synchronisation, so all we want here is to pin the framebuffer | |
11776 | * into the display plane and skip any waits. | |
11777 | */ | |
11778 | if (!mmio_flip) { | |
11779 | ret = i915_gem_object_sync(obj, engine, &request); | |
11780 | if (!ret && !request) { | |
11781 | request = i915_gem_request_alloc(engine, NULL); | |
11782 | ret = PTR_ERR_OR_ZERO(request); | |
11783 | } | |
11784 | ||
11785 | if (ret) | |
11786 | goto cleanup_pending; | |
11787 | } | |
11788 | ||
11789 | ret = intel_pin_and_fence_fb_obj(fb, primary->state->rotation); | |
11790 | if (ret) | |
11791 | goto cleanup_pending; | |
11792 | ||
11793 | work->gtt_offset = intel_plane_obj_offset(to_intel_plane(primary), | |
11794 | obj, 0); | |
11795 | work->gtt_offset += intel_crtc->dspaddr_offset; | |
11796 | work->rotation = crtc->primary->state->rotation; | |
11797 | ||
11798 | if (mmio_flip) { | |
11799 | INIT_WORK(&work->mmio_work, intel_mmio_flip_work_func); | |
11800 | ||
11801 | i915_gem_request_assign(&work->flip_queued_req, | |
11802 | obj->last_write_req); | |
11803 | ||
11804 | schedule_work(&work->mmio_work); | |
11805 | } else { | |
11806 | i915_gem_request_assign(&work->flip_queued_req, request); | |
11807 | ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, request, | |
11808 | page_flip_flags); | |
11809 | if (ret) | |
11810 | goto cleanup_unpin; | |
11811 | ||
11812 | intel_mark_page_flip_active(intel_crtc, work); | |
11813 | ||
11814 | i915_add_request_no_flush(request); | |
11815 | } | |
11816 | ||
11817 | i915_gem_track_fb(intel_fb_obj(old_fb), obj, | |
11818 | to_intel_plane(primary)->frontbuffer_bit); | |
11819 | mutex_unlock(&dev->struct_mutex); | |
11820 | ||
11821 | intel_frontbuffer_flip_prepare(dev, | |
11822 | to_intel_plane(primary)->frontbuffer_bit); | |
11823 | ||
11824 | trace_i915_flip_request(intel_crtc->plane, obj); | |
11825 | ||
11826 | return 0; | |
11827 | ||
11828 | cleanup_unpin: | |
11829 | intel_unpin_fb_obj(fb, crtc->primary->state->rotation); | |
11830 | cleanup_pending: | |
11831 | if (!IS_ERR_OR_NULL(request)) | |
11832 | i915_add_request_no_flush(request); | |
11833 | atomic_dec(&intel_crtc->unpin_work_count); | |
11834 | mutex_unlock(&dev->struct_mutex); | |
11835 | cleanup: | |
11836 | crtc->primary->fb = old_fb; | |
11837 | update_state_fb(crtc->primary); | |
11838 | ||
11839 | drm_gem_object_unreference_unlocked(&obj->base); | |
11840 | drm_framebuffer_unreference(work->old_fb); | |
11841 | ||
11842 | spin_lock_irq(&dev->event_lock); | |
11843 | intel_crtc->flip_work = NULL; | |
11844 | spin_unlock_irq(&dev->event_lock); | |
11845 | ||
11846 | drm_crtc_vblank_put(crtc); | |
11847 | free_work: | |
11848 | kfree(work); | |
11849 | ||
11850 | if (ret == -EIO) { | |
11851 | struct drm_atomic_state *state; | |
11852 | struct drm_plane_state *plane_state; | |
11853 | ||
11854 | out_hang: | |
11855 | state = drm_atomic_state_alloc(dev); | |
11856 | if (!state) | |
11857 | return -ENOMEM; | |
11858 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); | |
11859 | ||
11860 | retry: | |
11861 | plane_state = drm_atomic_get_plane_state(state, primary); | |
11862 | ret = PTR_ERR_OR_ZERO(plane_state); | |
11863 | if (!ret) { | |
11864 | drm_atomic_set_fb_for_plane(plane_state, fb); | |
11865 | ||
11866 | ret = drm_atomic_set_crtc_for_plane(plane_state, crtc); | |
11867 | if (!ret) | |
11868 | ret = drm_atomic_commit(state); | |
11869 | } | |
11870 | ||
11871 | if (ret == -EDEADLK) { | |
11872 | drm_modeset_backoff(state->acquire_ctx); | |
11873 | drm_atomic_state_clear(state); | |
11874 | goto retry; | |
11875 | } | |
11876 | ||
11877 | if (ret) | |
11878 | drm_atomic_state_free(state); | |
11879 | ||
11880 | if (ret == 0 && event) { | |
11881 | spin_lock_irq(&dev->event_lock); | |
11882 | drm_crtc_send_vblank_event(crtc, event); | |
11883 | spin_unlock_irq(&dev->event_lock); | |
11884 | } | |
11885 | } | |
11886 | return ret; | |
11887 | } | |
11888 | ||
11889 | ||
11890 | /** | |
11891 | * intel_wm_need_update - Check whether watermarks need updating | |
11892 | * @plane: drm plane | |
11893 | * @state: new plane state | |
11894 | * | |
11895 | * Check current plane state versus the new one to determine whether | |
11896 | * watermarks need to be recalculated. | |
11897 | * | |
11898 | * Returns true or false. | |
11899 | */ | |
11900 | static bool intel_wm_need_update(struct drm_plane *plane, | |
11901 | struct drm_plane_state *state) | |
11902 | { | |
11903 | struct intel_plane_state *new = to_intel_plane_state(state); | |
11904 | struct intel_plane_state *cur = to_intel_plane_state(plane->state); | |
11905 | ||
11906 | /* Update watermarks on tiling or size changes. */ | |
11907 | if (new->visible != cur->visible) | |
11908 | return true; | |
11909 | ||
11910 | if (!cur->base.fb || !new->base.fb) | |
11911 | return false; | |
11912 | ||
11913 | if (cur->base.fb->modifier[0] != new->base.fb->modifier[0] || | |
11914 | cur->base.rotation != new->base.rotation || | |
11915 | drm_rect_width(&new->src) != drm_rect_width(&cur->src) || | |
11916 | drm_rect_height(&new->src) != drm_rect_height(&cur->src) || | |
11917 | drm_rect_width(&new->dst) != drm_rect_width(&cur->dst) || | |
11918 | drm_rect_height(&new->dst) != drm_rect_height(&cur->dst)) | |
11919 | return true; | |
11920 | ||
11921 | return false; | |
11922 | } | |
11923 | ||
11924 | static bool needs_scaling(struct intel_plane_state *state) | |
11925 | { | |
11926 | int src_w = drm_rect_width(&state->src) >> 16; | |
11927 | int src_h = drm_rect_height(&state->src) >> 16; | |
11928 | int dst_w = drm_rect_width(&state->dst); | |
11929 | int dst_h = drm_rect_height(&state->dst); | |
11930 | ||
11931 | return (src_w != dst_w || src_h != dst_h); | |
11932 | } | |
d21fbe87 | 11933 | |
da20eabd ML |
11934 | int intel_plane_atomic_calc_changes(struct drm_crtc_state *crtc_state, |
11935 | struct drm_plane_state *plane_state) | |
11936 | { | |
ab1d3a0e | 11937 | struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state); |
da20eabd ML |
11938 | struct drm_crtc *crtc = crtc_state->crtc; |
11939 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
11940 | struct drm_plane *plane = plane_state->plane; | |
11941 | struct drm_device *dev = crtc->dev; | |
ed4a6a7c | 11942 | struct drm_i915_private *dev_priv = to_i915(dev); |
da20eabd ML |
11943 | struct intel_plane_state *old_plane_state = |
11944 | to_intel_plane_state(plane->state); | |
da20eabd ML |
11945 | bool mode_changed = needs_modeset(crtc_state); |
11946 | bool was_crtc_enabled = crtc->state->active; | |
11947 | bool is_crtc_enabled = crtc_state->active; | |
da20eabd ML |
11948 | bool turn_off, turn_on, visible, was_visible; |
11949 | struct drm_framebuffer *fb = plane_state->fb; | |
78108b7c | 11950 | int ret; |
da20eabd ML |
11951 | |
11952 | if (crtc_state && INTEL_INFO(dev)->gen >= 9 && | |
11953 | plane->type != DRM_PLANE_TYPE_CURSOR) { | |
11954 | ret = skl_update_scaler_plane( | |
11955 | to_intel_crtc_state(crtc_state), | |
11956 | to_intel_plane_state(plane_state)); | |
11957 | if (ret) | |
11958 | return ret; | |
11959 | } | |
11960 | ||
da20eabd ML |
11961 | was_visible = old_plane_state->visible; |
11962 | visible = to_intel_plane_state(plane_state)->visible; | |
11963 | ||
11964 | if (!was_crtc_enabled && WARN_ON(was_visible)) | |
11965 | was_visible = false; | |
11966 | ||
35c08f43 ML |
11967 | /* |
11968 | * Visibility is calculated as if the crtc was on, but | |
11969 | * after scaler setup everything depends on it being off | |
11970 | * when the crtc isn't active. | |
f818ffea VS |
11971 | * |
11972 | * FIXME this is wrong for watermarks. Watermarks should also | |
11973 | * be computed as if the pipe would be active. Perhaps move | |
11974 | * per-plane wm computation to the .check_plane() hook, and | |
11975 | * only combine the results from all planes in the current place? | |
35c08f43 ML |
11976 | */ |
11977 | if (!is_crtc_enabled) | |
11978 | to_intel_plane_state(plane_state)->visible = visible = false; | |
da20eabd ML |
11979 | |
11980 | if (!was_visible && !visible) | |
11981 | return 0; | |
11982 | ||
e8861675 ML |
11983 | if (fb != old_plane_state->base.fb) |
11984 | pipe_config->fb_changed = true; | |
11985 | ||
da20eabd ML |
11986 | turn_off = was_visible && (!visible || mode_changed); |
11987 | turn_on = visible && (!was_visible || mode_changed); | |
11988 | ||
72660ce0 | 11989 | DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n", |
78108b7c VS |
11990 | intel_crtc->base.base.id, |
11991 | intel_crtc->base.name, | |
72660ce0 VS |
11992 | plane->base.id, plane->name, |
11993 | fb ? fb->base.id : -1); | |
da20eabd | 11994 | |
72660ce0 VS |
11995 | DRM_DEBUG_ATOMIC("[PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n", |
11996 | plane->base.id, plane->name, | |
11997 | was_visible, visible, | |
da20eabd ML |
11998 | turn_off, turn_on, mode_changed); |
11999 | ||
caed361d VS |
12000 | if (turn_on) { |
12001 | pipe_config->update_wm_pre = true; | |
12002 | ||
12003 | /* must disable cxsr around plane enable/disable */ | |
12004 | if (plane->type != DRM_PLANE_TYPE_CURSOR) | |
12005 | pipe_config->disable_cxsr = true; | |
12006 | } else if (turn_off) { | |
12007 | pipe_config->update_wm_post = true; | |
92826fcd | 12008 | |
852eb00d | 12009 | /* must disable cxsr around plane enable/disable */ |
e8861675 | 12010 | if (plane->type != DRM_PLANE_TYPE_CURSOR) |
ab1d3a0e | 12011 | pipe_config->disable_cxsr = true; |
852eb00d | 12012 | } else if (intel_wm_need_update(plane, plane_state)) { |
caed361d VS |
12013 | /* FIXME bollocks */ |
12014 | pipe_config->update_wm_pre = true; | |
12015 | pipe_config->update_wm_post = true; | |
852eb00d | 12016 | } |
da20eabd | 12017 | |
ed4a6a7c | 12018 | /* Pre-gen9 platforms need two-step watermark updates */ |
caed361d VS |
12019 | if ((pipe_config->update_wm_pre || pipe_config->update_wm_post) && |
12020 | INTEL_INFO(dev)->gen < 9 && dev_priv->display.optimize_watermarks) | |
ed4a6a7c MR |
12021 | to_intel_crtc_state(crtc_state)->wm.need_postvbl_update = true; |
12022 | ||
8be6ca85 | 12023 | if (visible || was_visible) |
cd202f69 | 12024 | pipe_config->fb_bits |= to_intel_plane(plane)->frontbuffer_bit; |
a9ff8714 | 12025 | |
31ae71fc ML |
12026 | /* |
12027 | * WaCxSRDisabledForSpriteScaling:ivb | |
12028 | * | |
12029 | * cstate->update_wm was already set above, so this flag will | |
12030 | * take effect when we commit and program watermarks. | |
12031 | */ | |
12032 | if (plane->type == DRM_PLANE_TYPE_OVERLAY && IS_IVYBRIDGE(dev) && | |
12033 | needs_scaling(to_intel_plane_state(plane_state)) && | |
12034 | !needs_scaling(old_plane_state)) | |
12035 | pipe_config->disable_lp_wm = true; | |
d21fbe87 | 12036 | |
da20eabd ML |
12037 | return 0; |
12038 | } | |
12039 | ||
6d3a1ce7 ML |
12040 | static bool encoders_cloneable(const struct intel_encoder *a, |
12041 | const struct intel_encoder *b) | |
12042 | { | |
12043 | /* masks could be asymmetric, so check both ways */ | |
12044 | return a == b || (a->cloneable & (1 << b->type) && | |
12045 | b->cloneable & (1 << a->type)); | |
12046 | } | |
12047 | ||
12048 | static bool check_single_encoder_cloning(struct drm_atomic_state *state, | |
12049 | struct intel_crtc *crtc, | |
12050 | struct intel_encoder *encoder) | |
12051 | { | |
12052 | struct intel_encoder *source_encoder; | |
12053 | struct drm_connector *connector; | |
12054 | struct drm_connector_state *connector_state; | |
12055 | int i; | |
12056 | ||
12057 | for_each_connector_in_state(state, connector, connector_state, i) { | |
12058 | if (connector_state->crtc != &crtc->base) | |
12059 | continue; | |
12060 | ||
12061 | source_encoder = | |
12062 | to_intel_encoder(connector_state->best_encoder); | |
12063 | if (!encoders_cloneable(encoder, source_encoder)) | |
12064 | return false; | |
12065 | } | |
12066 | ||
12067 | return true; | |
12068 | } | |
12069 | ||
12070 | static bool check_encoder_cloning(struct drm_atomic_state *state, | |
12071 | struct intel_crtc *crtc) | |
12072 | { | |
12073 | struct intel_encoder *encoder; | |
12074 | struct drm_connector *connector; | |
12075 | struct drm_connector_state *connector_state; | |
12076 | int i; | |
12077 | ||
12078 | for_each_connector_in_state(state, connector, connector_state, i) { | |
12079 | if (connector_state->crtc != &crtc->base) | |
12080 | continue; | |
12081 | ||
12082 | encoder = to_intel_encoder(connector_state->best_encoder); | |
12083 | if (!check_single_encoder_cloning(state, crtc, encoder)) | |
12084 | return false; | |
12085 | } | |
12086 | ||
12087 | return true; | |
12088 | } | |
12089 | ||
12090 | static int intel_crtc_atomic_check(struct drm_crtc *crtc, | |
12091 | struct drm_crtc_state *crtc_state) | |
12092 | { | |
cf5a15be | 12093 | struct drm_device *dev = crtc->dev; |
ad421372 | 12094 | struct drm_i915_private *dev_priv = dev->dev_private; |
6d3a1ce7 | 12095 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
cf5a15be ML |
12096 | struct intel_crtc_state *pipe_config = |
12097 | to_intel_crtc_state(crtc_state); | |
6d3a1ce7 | 12098 | struct drm_atomic_state *state = crtc_state->state; |
4d20cd86 | 12099 | int ret; |
6d3a1ce7 ML |
12100 | bool mode_changed = needs_modeset(crtc_state); |
12101 | ||
12102 | if (mode_changed && !check_encoder_cloning(state, intel_crtc)) { | |
12103 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); | |
12104 | return -EINVAL; | |
12105 | } | |
12106 | ||
852eb00d | 12107 | if (mode_changed && !crtc_state->active) |
caed361d | 12108 | pipe_config->update_wm_post = true; |
eddfcbcd | 12109 | |
ad421372 ML |
12110 | if (mode_changed && crtc_state->enable && |
12111 | dev_priv->display.crtc_compute_clock && | |
8106ddbd | 12112 | !WARN_ON(pipe_config->shared_dpll)) { |
ad421372 ML |
12113 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, |
12114 | pipe_config); | |
12115 | if (ret) | |
12116 | return ret; | |
12117 | } | |
12118 | ||
82cf435b LL |
12119 | if (crtc_state->color_mgmt_changed) { |
12120 | ret = intel_color_check(crtc, crtc_state); | |
12121 | if (ret) | |
12122 | return ret; | |
12123 | } | |
12124 | ||
e435d6e5 | 12125 | ret = 0; |
86c8bbbe | 12126 | if (dev_priv->display.compute_pipe_wm) { |
e3bddded | 12127 | ret = dev_priv->display.compute_pipe_wm(pipe_config); |
ed4a6a7c MR |
12128 | if (ret) { |
12129 | DRM_DEBUG_KMS("Target pipe watermarks are invalid\n"); | |
12130 | return ret; | |
12131 | } | |
12132 | } | |
12133 | ||
12134 | if (dev_priv->display.compute_intermediate_wm && | |
12135 | !to_intel_atomic_state(state)->skip_intermediate_wm) { | |
12136 | if (WARN_ON(!dev_priv->display.compute_pipe_wm)) | |
12137 | return 0; | |
12138 | ||
12139 | /* | |
12140 | * Calculate 'intermediate' watermarks that satisfy both the | |
12141 | * old state and the new state. We can program these | |
12142 | * immediately. | |
12143 | */ | |
12144 | ret = dev_priv->display.compute_intermediate_wm(crtc->dev, | |
12145 | intel_crtc, | |
12146 | pipe_config); | |
12147 | if (ret) { | |
12148 | DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n"); | |
86c8bbbe | 12149 | return ret; |
ed4a6a7c | 12150 | } |
e3d5457c VS |
12151 | } else if (dev_priv->display.compute_intermediate_wm) { |
12152 | if (HAS_PCH_SPLIT(dev_priv) && INTEL_GEN(dev_priv) < 9) | |
12153 | pipe_config->wm.ilk.intermediate = pipe_config->wm.ilk.optimal; | |
86c8bbbe MR |
12154 | } |
12155 | ||
e435d6e5 ML |
12156 | if (INTEL_INFO(dev)->gen >= 9) { |
12157 | if (mode_changed) | |
12158 | ret = skl_update_scaler_crtc(pipe_config); | |
12159 | ||
12160 | if (!ret) | |
12161 | ret = intel_atomic_setup_scalers(dev, intel_crtc, | |
12162 | pipe_config); | |
12163 | } | |
12164 | ||
12165 | return ret; | |
6d3a1ce7 ML |
12166 | } |
12167 | ||
65b38e0d | 12168 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { |
f6e5b160 | 12169 | .mode_set_base_atomic = intel_pipe_set_base_atomic, |
5a21b665 DV |
12170 | .atomic_begin = intel_begin_crtc_commit, |
12171 | .atomic_flush = intel_finish_crtc_commit, | |
6d3a1ce7 | 12172 | .atomic_check = intel_crtc_atomic_check, |
f6e5b160 CW |
12173 | }; |
12174 | ||
d29b2f9d ACO |
12175 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) |
12176 | { | |
12177 | struct intel_connector *connector; | |
12178 | ||
12179 | for_each_intel_connector(dev, connector) { | |
8863dc7f DV |
12180 | if (connector->base.state->crtc) |
12181 | drm_connector_unreference(&connector->base); | |
12182 | ||
d29b2f9d ACO |
12183 | if (connector->base.encoder) { |
12184 | connector->base.state->best_encoder = | |
12185 | connector->base.encoder; | |
12186 | connector->base.state->crtc = | |
12187 | connector->base.encoder->crtc; | |
8863dc7f DV |
12188 | |
12189 | drm_connector_reference(&connector->base); | |
d29b2f9d ACO |
12190 | } else { |
12191 | connector->base.state->best_encoder = NULL; | |
12192 | connector->base.state->crtc = NULL; | |
12193 | } | |
12194 | } | |
12195 | } | |
12196 | ||
050f7aeb | 12197 | static void |
eba905b2 | 12198 | connected_sink_compute_bpp(struct intel_connector *connector, |
5cec258b | 12199 | struct intel_crtc_state *pipe_config) |
050f7aeb DV |
12200 | { |
12201 | int bpp = pipe_config->pipe_bpp; | |
12202 | ||
12203 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n", | |
12204 | connector->base.base.id, | |
c23cc417 | 12205 | connector->base.name); |
050f7aeb DV |
12206 | |
12207 | /* Don't use an invalid EDID bpc value */ | |
12208 | if (connector->base.display_info.bpc && | |
12209 | connector->base.display_info.bpc * 3 < bpp) { | |
12210 | DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n", | |
12211 | bpp, connector->base.display_info.bpc*3); | |
12212 | pipe_config->pipe_bpp = connector->base.display_info.bpc*3; | |
12213 | } | |
12214 | ||
013dd9e0 JN |
12215 | /* Clamp bpp to default limit on screens without EDID 1.4 */ |
12216 | if (connector->base.display_info.bpc == 0) { | |
12217 | int type = connector->base.connector_type; | |
12218 | int clamp_bpp = 24; | |
12219 | ||
12220 | /* Fall back to 18 bpp when DP sink capability is unknown. */ | |
12221 | if (type == DRM_MODE_CONNECTOR_DisplayPort || | |
12222 | type == DRM_MODE_CONNECTOR_eDP) | |
12223 | clamp_bpp = 18; | |
12224 | ||
12225 | if (bpp > clamp_bpp) { | |
12226 | DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of %d\n", | |
12227 | bpp, clamp_bpp); | |
12228 | pipe_config->pipe_bpp = clamp_bpp; | |
12229 | } | |
050f7aeb DV |
12230 | } |
12231 | } | |
12232 | ||
4e53c2e0 | 12233 | static int |
050f7aeb | 12234 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
5cec258b | 12235 | struct intel_crtc_state *pipe_config) |
4e53c2e0 | 12236 | { |
050f7aeb | 12237 | struct drm_device *dev = crtc->base.dev; |
1486017f | 12238 | struct drm_atomic_state *state; |
da3ced29 ACO |
12239 | struct drm_connector *connector; |
12240 | struct drm_connector_state *connector_state; | |
1486017f | 12241 | int bpp, i; |
4e53c2e0 | 12242 | |
666a4537 | 12243 | if ((IS_G4X(dev) || IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))) |
4e53c2e0 | 12244 | bpp = 10*3; |
d328c9d7 DV |
12245 | else if (INTEL_INFO(dev)->gen >= 5) |
12246 | bpp = 12*3; | |
12247 | else | |
12248 | bpp = 8*3; | |
12249 | ||
4e53c2e0 | 12250 | |
4e53c2e0 DV |
12251 | pipe_config->pipe_bpp = bpp; |
12252 | ||
1486017f ACO |
12253 | state = pipe_config->base.state; |
12254 | ||
4e53c2e0 | 12255 | /* Clamp display bpp to EDID value */ |
da3ced29 ACO |
12256 | for_each_connector_in_state(state, connector, connector_state, i) { |
12257 | if (connector_state->crtc != &crtc->base) | |
4e53c2e0 DV |
12258 | continue; |
12259 | ||
da3ced29 ACO |
12260 | connected_sink_compute_bpp(to_intel_connector(connector), |
12261 | pipe_config); | |
4e53c2e0 DV |
12262 | } |
12263 | ||
12264 | return bpp; | |
12265 | } | |
12266 | ||
644db711 DV |
12267 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
12268 | { | |
12269 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " | |
12270 | "type: 0x%x flags: 0x%x\n", | |
1342830c | 12271 | mode->crtc_clock, |
644db711 DV |
12272 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
12273 | mode->crtc_hsync_end, mode->crtc_htotal, | |
12274 | mode->crtc_vdisplay, mode->crtc_vsync_start, | |
12275 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); | |
12276 | } | |
12277 | ||
c0b03411 | 12278 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
5cec258b | 12279 | struct intel_crtc_state *pipe_config, |
c0b03411 DV |
12280 | const char *context) |
12281 | { | |
6a60cd87 CK |
12282 | struct drm_device *dev = crtc->base.dev; |
12283 | struct drm_plane *plane; | |
12284 | struct intel_plane *intel_plane; | |
12285 | struct intel_plane_state *state; | |
12286 | struct drm_framebuffer *fb; | |
12287 | ||
78108b7c VS |
12288 | DRM_DEBUG_KMS("[CRTC:%d:%s]%s config %p for pipe %c\n", |
12289 | crtc->base.base.id, crtc->base.name, | |
6a60cd87 | 12290 | context, pipe_config, pipe_name(crtc->pipe)); |
c0b03411 | 12291 | |
da205630 | 12292 | DRM_DEBUG_KMS("cpu_transcoder: %s\n", transcoder_name(pipe_config->cpu_transcoder)); |
c0b03411 DV |
12293 | DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n", |
12294 | pipe_config->pipe_bpp, pipe_config->dither); | |
12295 | DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", | |
12296 | pipe_config->has_pch_encoder, | |
12297 | pipe_config->fdi_lanes, | |
12298 | pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n, | |
12299 | pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n, | |
12300 | pipe_config->fdi_m_n.tu); | |
90a6b7b0 | 12301 | DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
eb14cb74 | 12302 | pipe_config->has_dp_encoder, |
90a6b7b0 | 12303 | pipe_config->lane_count, |
eb14cb74 VS |
12304 | pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n, |
12305 | pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n, | |
12306 | pipe_config->dp_m_n.tu); | |
b95af8be | 12307 | |
90a6b7b0 | 12308 | DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n", |
b95af8be | 12309 | pipe_config->has_dp_encoder, |
90a6b7b0 | 12310 | pipe_config->lane_count, |
b95af8be VK |
12311 | pipe_config->dp_m2_n2.gmch_m, |
12312 | pipe_config->dp_m2_n2.gmch_n, | |
12313 | pipe_config->dp_m2_n2.link_m, | |
12314 | pipe_config->dp_m2_n2.link_n, | |
12315 | pipe_config->dp_m2_n2.tu); | |
12316 | ||
55072d19 DV |
12317 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
12318 | pipe_config->has_audio, | |
12319 | pipe_config->has_infoframe); | |
12320 | ||
c0b03411 | 12321 | DRM_DEBUG_KMS("requested mode:\n"); |
2d112de7 | 12322 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
c0b03411 | 12323 | DRM_DEBUG_KMS("adjusted mode:\n"); |
2d112de7 ACO |
12324 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
12325 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); | |
d71b8d4a | 12326 | DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock); |
37327abd VS |
12327 | DRM_DEBUG_KMS("pipe src size: %dx%d\n", |
12328 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); | |
0ec463d3 TU |
12329 | DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n", |
12330 | crtc->num_scalers, | |
12331 | pipe_config->scaler_state.scaler_users, | |
12332 | pipe_config->scaler_state.scaler_id); | |
c0b03411 DV |
12333 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
12334 | pipe_config->gmch_pfit.control, | |
12335 | pipe_config->gmch_pfit.pgm_ratios, | |
12336 | pipe_config->gmch_pfit.lvds_border_bits); | |
fd4daa9c | 12337 | DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n", |
c0b03411 | 12338 | pipe_config->pch_pfit.pos, |
fd4daa9c CW |
12339 | pipe_config->pch_pfit.size, |
12340 | pipe_config->pch_pfit.enabled ? "enabled" : "disabled"); | |
42db64ef | 12341 | DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled); |
cf532bb2 | 12342 | DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide); |
6a60cd87 | 12343 | |
415ff0f6 | 12344 | if (IS_BROXTON(dev)) { |
05712c15 | 12345 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: ebb0: 0x%x, ebb4: 0x%x," |
415ff0f6 | 12346 | "pll0: 0x%x, pll1: 0x%x, pll2: 0x%x, pll3: 0x%x, " |
c8453338 | 12347 | "pll6: 0x%x, pll8: 0x%x, pll9: 0x%x, pll10: 0x%x, pcsdw12: 0x%x\n", |
415ff0f6 TU |
12348 | pipe_config->ddi_pll_sel, |
12349 | pipe_config->dpll_hw_state.ebb0, | |
05712c15 | 12350 | pipe_config->dpll_hw_state.ebb4, |
415ff0f6 TU |
12351 | pipe_config->dpll_hw_state.pll0, |
12352 | pipe_config->dpll_hw_state.pll1, | |
12353 | pipe_config->dpll_hw_state.pll2, | |
12354 | pipe_config->dpll_hw_state.pll3, | |
12355 | pipe_config->dpll_hw_state.pll6, | |
12356 | pipe_config->dpll_hw_state.pll8, | |
05712c15 | 12357 | pipe_config->dpll_hw_state.pll9, |
c8453338 | 12358 | pipe_config->dpll_hw_state.pll10, |
415ff0f6 | 12359 | pipe_config->dpll_hw_state.pcsdw12); |
ef11bdb3 | 12360 | } else if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) { |
415ff0f6 TU |
12361 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: " |
12362 | "ctrl1: 0x%x, cfgcr1: 0x%x, cfgcr2: 0x%x\n", | |
12363 | pipe_config->ddi_pll_sel, | |
12364 | pipe_config->dpll_hw_state.ctrl1, | |
12365 | pipe_config->dpll_hw_state.cfgcr1, | |
12366 | pipe_config->dpll_hw_state.cfgcr2); | |
12367 | } else if (HAS_DDI(dev)) { | |
1260f07e | 12368 | DRM_DEBUG_KMS("ddi_pll_sel: 0x%x; dpll_hw_state: wrpll: 0x%x spll: 0x%x\n", |
415ff0f6 | 12369 | pipe_config->ddi_pll_sel, |
00490c22 ML |
12370 | pipe_config->dpll_hw_state.wrpll, |
12371 | pipe_config->dpll_hw_state.spll); | |
415ff0f6 TU |
12372 | } else { |
12373 | DRM_DEBUG_KMS("dpll_hw_state: dpll: 0x%x, dpll_md: 0x%x, " | |
12374 | "fp0: 0x%x, fp1: 0x%x\n", | |
12375 | pipe_config->dpll_hw_state.dpll, | |
12376 | pipe_config->dpll_hw_state.dpll_md, | |
12377 | pipe_config->dpll_hw_state.fp0, | |
12378 | pipe_config->dpll_hw_state.fp1); | |
12379 | } | |
12380 | ||
6a60cd87 CK |
12381 | DRM_DEBUG_KMS("planes on this crtc\n"); |
12382 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { | |
12383 | intel_plane = to_intel_plane(plane); | |
12384 | if (intel_plane->pipe != crtc->pipe) | |
12385 | continue; | |
12386 | ||
12387 | state = to_intel_plane_state(plane->state); | |
12388 | fb = state->base.fb; | |
12389 | if (!fb) { | |
1d577e02 VS |
12390 | DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n", |
12391 | plane->base.id, plane->name, state->scaler_id); | |
6a60cd87 CK |
12392 | continue; |
12393 | } | |
12394 | ||
1d577e02 VS |
12395 | DRM_DEBUG_KMS("[PLANE:%d:%s] enabled", |
12396 | plane->base.id, plane->name); | |
12397 | DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = %s", | |
12398 | fb->base.id, fb->width, fb->height, | |
12399 | drm_get_format_name(fb->pixel_format)); | |
12400 | DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n", | |
12401 | state->scaler_id, | |
12402 | state->src.x1 >> 16, state->src.y1 >> 16, | |
12403 | drm_rect_width(&state->src) >> 16, | |
12404 | drm_rect_height(&state->src) >> 16, | |
12405 | state->dst.x1, state->dst.y1, | |
12406 | drm_rect_width(&state->dst), | |
12407 | drm_rect_height(&state->dst)); | |
6a60cd87 | 12408 | } |
c0b03411 DV |
12409 | } |
12410 | ||
5448a00d | 12411 | static bool check_digital_port_conflicts(struct drm_atomic_state *state) |
00f0b378 | 12412 | { |
5448a00d | 12413 | struct drm_device *dev = state->dev; |
da3ced29 | 12414 | struct drm_connector *connector; |
00f0b378 VS |
12415 | unsigned int used_ports = 0; |
12416 | ||
12417 | /* | |
12418 | * Walk the connector list instead of the encoder | |
12419 | * list to detect the problem on ddi platforms | |
12420 | * where there's just one encoder per digital port. | |
12421 | */ | |
0bff4858 VS |
12422 | drm_for_each_connector(connector, dev) { |
12423 | struct drm_connector_state *connector_state; | |
12424 | struct intel_encoder *encoder; | |
12425 | ||
12426 | connector_state = drm_atomic_get_existing_connector_state(state, connector); | |
12427 | if (!connector_state) | |
12428 | connector_state = connector->state; | |
12429 | ||
5448a00d | 12430 | if (!connector_state->best_encoder) |
00f0b378 VS |
12431 | continue; |
12432 | ||
5448a00d ACO |
12433 | encoder = to_intel_encoder(connector_state->best_encoder); |
12434 | ||
12435 | WARN_ON(!connector_state->crtc); | |
00f0b378 VS |
12436 | |
12437 | switch (encoder->type) { | |
12438 | unsigned int port_mask; | |
12439 | case INTEL_OUTPUT_UNKNOWN: | |
12440 | if (WARN_ON(!HAS_DDI(dev))) | |
12441 | break; | |
12442 | case INTEL_OUTPUT_DISPLAYPORT: | |
12443 | case INTEL_OUTPUT_HDMI: | |
12444 | case INTEL_OUTPUT_EDP: | |
12445 | port_mask = 1 << enc_to_dig_port(&encoder->base)->port; | |
12446 | ||
12447 | /* the same port mustn't appear more than once */ | |
12448 | if (used_ports & port_mask) | |
12449 | return false; | |
12450 | ||
12451 | used_ports |= port_mask; | |
12452 | default: | |
12453 | break; | |
12454 | } | |
12455 | } | |
12456 | ||
12457 | return true; | |
12458 | } | |
12459 | ||
83a57153 ACO |
12460 | static void |
12461 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) | |
12462 | { | |
12463 | struct drm_crtc_state tmp_state; | |
663a3640 | 12464 | struct intel_crtc_scaler_state scaler_state; |
4978cc93 | 12465 | struct intel_dpll_hw_state dpll_hw_state; |
8106ddbd | 12466 | struct intel_shared_dpll *shared_dpll; |
8504c74c | 12467 | uint32_t ddi_pll_sel; |
c4e2d043 | 12468 | bool force_thru; |
83a57153 | 12469 | |
7546a384 ACO |
12470 | /* FIXME: before the switch to atomic started, a new pipe_config was |
12471 | * kzalloc'd. Code that depends on any field being zero should be | |
12472 | * fixed, so that the crtc_state can be safely duplicated. For now, | |
12473 | * only fields that are know to not cause problems are preserved. */ | |
12474 | ||
83a57153 | 12475 | tmp_state = crtc_state->base; |
663a3640 | 12476 | scaler_state = crtc_state->scaler_state; |
4978cc93 ACO |
12477 | shared_dpll = crtc_state->shared_dpll; |
12478 | dpll_hw_state = crtc_state->dpll_hw_state; | |
8504c74c | 12479 | ddi_pll_sel = crtc_state->ddi_pll_sel; |
c4e2d043 | 12480 | force_thru = crtc_state->pch_pfit.force_thru; |
4978cc93 | 12481 | |
83a57153 | 12482 | memset(crtc_state, 0, sizeof *crtc_state); |
4978cc93 | 12483 | |
83a57153 | 12484 | crtc_state->base = tmp_state; |
663a3640 | 12485 | crtc_state->scaler_state = scaler_state; |
4978cc93 ACO |
12486 | crtc_state->shared_dpll = shared_dpll; |
12487 | crtc_state->dpll_hw_state = dpll_hw_state; | |
8504c74c | 12488 | crtc_state->ddi_pll_sel = ddi_pll_sel; |
c4e2d043 | 12489 | crtc_state->pch_pfit.force_thru = force_thru; |
83a57153 ACO |
12490 | } |
12491 | ||
548ee15b | 12492 | static int |
b8cecdf5 | 12493 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
b359283a | 12494 | struct intel_crtc_state *pipe_config) |
ee7b9f93 | 12495 | { |
b359283a | 12496 | struct drm_atomic_state *state = pipe_config->base.state; |
7758a113 | 12497 | struct intel_encoder *encoder; |
da3ced29 | 12498 | struct drm_connector *connector; |
0b901879 | 12499 | struct drm_connector_state *connector_state; |
d328c9d7 | 12500 | int base_bpp, ret = -EINVAL; |
0b901879 | 12501 | int i; |
e29c22c0 | 12502 | bool retry = true; |
ee7b9f93 | 12503 | |
83a57153 | 12504 | clear_intel_crtc_state(pipe_config); |
7758a113 | 12505 | |
e143a21c DV |
12506 | pipe_config->cpu_transcoder = |
12507 | (enum transcoder) to_intel_crtc(crtc)->pipe; | |
b8cecdf5 | 12508 | |
2960bc9c ID |
12509 | /* |
12510 | * Sanitize sync polarity flags based on requested ones. If neither | |
12511 | * positive or negative polarity is requested, treat this as meaning | |
12512 | * negative polarity. | |
12513 | */ | |
2d112de7 | 12514 | if (!(pipe_config->base.adjusted_mode.flags & |
2960bc9c | 12515 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
2d112de7 | 12516 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
2960bc9c | 12517 | |
2d112de7 | 12518 | if (!(pipe_config->base.adjusted_mode.flags & |
2960bc9c | 12519 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
2d112de7 | 12520 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
2960bc9c | 12521 | |
d328c9d7 DV |
12522 | base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
12523 | pipe_config); | |
12524 | if (base_bpp < 0) | |
4e53c2e0 DV |
12525 | goto fail; |
12526 | ||
e41a56be VS |
12527 | /* |
12528 | * Determine the real pipe dimensions. Note that stereo modes can | |
12529 | * increase the actual pipe size due to the frame doubling and | |
12530 | * insertion of additional space for blanks between the frame. This | |
12531 | * is stored in the crtc timings. We use the requested mode to do this | |
12532 | * computation to clearly distinguish it from the adjusted mode, which | |
12533 | * can be changed by the connectors in the below retry loop. | |
12534 | */ | |
2d112de7 | 12535 | drm_crtc_get_hv_timing(&pipe_config->base.mode, |
ecb7e16b GP |
12536 | &pipe_config->pipe_src_w, |
12537 | &pipe_config->pipe_src_h); | |
e41a56be | 12538 | |
e29c22c0 | 12539 | encoder_retry: |
ef1b460d | 12540 | /* Ensure the port clock defaults are reset when retrying. */ |
ff9a6750 | 12541 | pipe_config->port_clock = 0; |
ef1b460d | 12542 | pipe_config->pixel_multiplier = 1; |
ff9a6750 | 12543 | |
135c81b8 | 12544 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
2d112de7 ACO |
12545 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
12546 | CRTC_STEREO_DOUBLE); | |
135c81b8 | 12547 | |
7758a113 DV |
12548 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
12549 | * adjust it according to limitations or connector properties, and also | |
12550 | * a chance to reject the mode entirely. | |
47f1c6c9 | 12551 | */ |
da3ced29 | 12552 | for_each_connector_in_state(state, connector, connector_state, i) { |
0b901879 | 12553 | if (connector_state->crtc != crtc) |
7758a113 | 12554 | continue; |
7ae89233 | 12555 | |
0b901879 ACO |
12556 | encoder = to_intel_encoder(connector_state->best_encoder); |
12557 | ||
efea6e8e DV |
12558 | if (!(encoder->compute_config(encoder, pipe_config))) { |
12559 | DRM_DEBUG_KMS("Encoder config failure\n"); | |
7758a113 DV |
12560 | goto fail; |
12561 | } | |
ee7b9f93 | 12562 | } |
47f1c6c9 | 12563 | |
ff9a6750 DV |
12564 | /* Set default port clock if not overwritten by the encoder. Needs to be |
12565 | * done afterwards in case the encoder adjusts the mode. */ | |
12566 | if (!pipe_config->port_clock) | |
2d112de7 | 12567 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
241bfc38 | 12568 | * pipe_config->pixel_multiplier; |
ff9a6750 | 12569 | |
a43f6e0f | 12570 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
e29c22c0 | 12571 | if (ret < 0) { |
7758a113 DV |
12572 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
12573 | goto fail; | |
ee7b9f93 | 12574 | } |
e29c22c0 DV |
12575 | |
12576 | if (ret == RETRY) { | |
12577 | if (WARN(!retry, "loop in pipe configuration computation\n")) { | |
12578 | ret = -EINVAL; | |
12579 | goto fail; | |
12580 | } | |
12581 | ||
12582 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); | |
12583 | retry = false; | |
12584 | goto encoder_retry; | |
12585 | } | |
12586 | ||
e8fa4270 DV |
12587 | /* Dithering seems to not pass-through bits correctly when it should, so |
12588 | * only enable it on 6bpc panels. */ | |
12589 | pipe_config->dither = pipe_config->pipe_bpp == 6*3; | |
62f0ace5 | 12590 | DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n", |
d328c9d7 | 12591 | base_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
4e53c2e0 | 12592 | |
7758a113 | 12593 | fail: |
548ee15b | 12594 | return ret; |
ee7b9f93 | 12595 | } |
47f1c6c9 | 12596 | |
ea9d758d | 12597 | static void |
4740b0f2 | 12598 | intel_modeset_update_crtc_state(struct drm_atomic_state *state) |
ea9d758d | 12599 | { |
0a9ab303 ACO |
12600 | struct drm_crtc *crtc; |
12601 | struct drm_crtc_state *crtc_state; | |
8a75d157 | 12602 | int i; |
ea9d758d | 12603 | |
7668851f | 12604 | /* Double check state. */ |
8a75d157 | 12605 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
3cb480bc | 12606 | to_intel_crtc(crtc)->config = to_intel_crtc_state(crtc->state); |
fc467a22 ML |
12607 | |
12608 | /* Update hwmode for vblank functions */ | |
12609 | if (crtc->state->active) | |
12610 | crtc->hwmode = crtc->state->adjusted_mode; | |
12611 | else | |
12612 | crtc->hwmode.crtc_clock = 0; | |
61067a5e ML |
12613 | |
12614 | /* | |
12615 | * Update legacy state to satisfy fbc code. This can | |
12616 | * be removed when fbc uses the atomic state. | |
12617 | */ | |
12618 | if (drm_atomic_get_existing_plane_state(state, crtc->primary)) { | |
12619 | struct drm_plane_state *plane_state = crtc->primary->state; | |
12620 | ||
12621 | crtc->primary->fb = plane_state->fb; | |
12622 | crtc->x = plane_state->src_x >> 16; | |
12623 | crtc->y = plane_state->src_y >> 16; | |
12624 | } | |
ea9d758d | 12625 | } |
ea9d758d DV |
12626 | } |
12627 | ||
3bd26263 | 12628 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
f1f644dc | 12629 | { |
3bd26263 | 12630 | int diff; |
f1f644dc JB |
12631 | |
12632 | if (clock1 == clock2) | |
12633 | return true; | |
12634 | ||
12635 | if (!clock1 || !clock2) | |
12636 | return false; | |
12637 | ||
12638 | diff = abs(clock1 - clock2); | |
12639 | ||
12640 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) | |
12641 | return true; | |
12642 | ||
12643 | return false; | |
12644 | } | |
12645 | ||
25c5b266 DV |
12646 | #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \ |
12647 | list_for_each_entry((intel_crtc), \ | |
12648 | &(dev)->mode_config.crtc_list, \ | |
12649 | base.head) \ | |
95150bdf | 12650 | for_each_if (mask & (1 <<(intel_crtc)->pipe)) |
25c5b266 | 12651 | |
cfb23ed6 ML |
12652 | static bool |
12653 | intel_compare_m_n(unsigned int m, unsigned int n, | |
12654 | unsigned int m2, unsigned int n2, | |
12655 | bool exact) | |
12656 | { | |
12657 | if (m == m2 && n == n2) | |
12658 | return true; | |
12659 | ||
12660 | if (exact || !m || !n || !m2 || !n2) | |
12661 | return false; | |
12662 | ||
12663 | BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX); | |
12664 | ||
31d10b57 ML |
12665 | if (n > n2) { |
12666 | while (n > n2) { | |
cfb23ed6 ML |
12667 | m2 <<= 1; |
12668 | n2 <<= 1; | |
12669 | } | |
31d10b57 ML |
12670 | } else if (n < n2) { |
12671 | while (n < n2) { | |
cfb23ed6 ML |
12672 | m <<= 1; |
12673 | n <<= 1; | |
12674 | } | |
12675 | } | |
12676 | ||
31d10b57 ML |
12677 | if (n != n2) |
12678 | return false; | |
12679 | ||
12680 | return intel_fuzzy_clock_check(m, m2); | |
cfb23ed6 ML |
12681 | } |
12682 | ||
12683 | static bool | |
12684 | intel_compare_link_m_n(const struct intel_link_m_n *m_n, | |
12685 | struct intel_link_m_n *m2_n2, | |
12686 | bool adjust) | |
12687 | { | |
12688 | if (m_n->tu == m2_n2->tu && | |
12689 | intel_compare_m_n(m_n->gmch_m, m_n->gmch_n, | |
12690 | m2_n2->gmch_m, m2_n2->gmch_n, !adjust) && | |
12691 | intel_compare_m_n(m_n->link_m, m_n->link_n, | |
12692 | m2_n2->link_m, m2_n2->link_n, !adjust)) { | |
12693 | if (adjust) | |
12694 | *m2_n2 = *m_n; | |
12695 | ||
12696 | return true; | |
12697 | } | |
12698 | ||
12699 | return false; | |
12700 | } | |
12701 | ||
0e8ffe1b | 12702 | static bool |
2fa2fe9a | 12703 | intel_pipe_config_compare(struct drm_device *dev, |
5cec258b | 12704 | struct intel_crtc_state *current_config, |
cfb23ed6 ML |
12705 | struct intel_crtc_state *pipe_config, |
12706 | bool adjust) | |
0e8ffe1b | 12707 | { |
cfb23ed6 ML |
12708 | bool ret = true; |
12709 | ||
12710 | #define INTEL_ERR_OR_DBG_KMS(fmt, ...) \ | |
12711 | do { \ | |
12712 | if (!adjust) \ | |
12713 | DRM_ERROR(fmt, ##__VA_ARGS__); \ | |
12714 | else \ | |
12715 | DRM_DEBUG_KMS(fmt, ##__VA_ARGS__); \ | |
12716 | } while (0) | |
12717 | ||
66e985c0 DV |
12718 | #define PIPE_CONF_CHECK_X(name) \ |
12719 | if (current_config->name != pipe_config->name) { \ | |
cfb23ed6 | 12720 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
66e985c0 DV |
12721 | "(expected 0x%08x, found 0x%08x)\n", \ |
12722 | current_config->name, \ | |
12723 | pipe_config->name); \ | |
cfb23ed6 | 12724 | ret = false; \ |
66e985c0 DV |
12725 | } |
12726 | ||
08a24034 DV |
12727 | #define PIPE_CONF_CHECK_I(name) \ |
12728 | if (current_config->name != pipe_config->name) { \ | |
cfb23ed6 | 12729 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
08a24034 DV |
12730 | "(expected %i, found %i)\n", \ |
12731 | current_config->name, \ | |
12732 | pipe_config->name); \ | |
cfb23ed6 ML |
12733 | ret = false; \ |
12734 | } | |
12735 | ||
8106ddbd ACO |
12736 | #define PIPE_CONF_CHECK_P(name) \ |
12737 | if (current_config->name != pipe_config->name) { \ | |
12738 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ | |
12739 | "(expected %p, found %p)\n", \ | |
12740 | current_config->name, \ | |
12741 | pipe_config->name); \ | |
12742 | ret = false; \ | |
12743 | } | |
12744 | ||
cfb23ed6 ML |
12745 | #define PIPE_CONF_CHECK_M_N(name) \ |
12746 | if (!intel_compare_link_m_n(¤t_config->name, \ | |
12747 | &pipe_config->name,\ | |
12748 | adjust)) { \ | |
12749 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ | |
12750 | "(expected tu %i gmch %i/%i link %i/%i, " \ | |
12751 | "found tu %i, gmch %i/%i link %i/%i)\n", \ | |
12752 | current_config->name.tu, \ | |
12753 | current_config->name.gmch_m, \ | |
12754 | current_config->name.gmch_n, \ | |
12755 | current_config->name.link_m, \ | |
12756 | current_config->name.link_n, \ | |
12757 | pipe_config->name.tu, \ | |
12758 | pipe_config->name.gmch_m, \ | |
12759 | pipe_config->name.gmch_n, \ | |
12760 | pipe_config->name.link_m, \ | |
12761 | pipe_config->name.link_n); \ | |
12762 | ret = false; \ | |
12763 | } | |
12764 | ||
55c561a7 DV |
12765 | /* This is required for BDW+ where there is only one set of registers for |
12766 | * switching between high and low RR. | |
12767 | * This macro can be used whenever a comparison has to be made between one | |
12768 | * hw state and multiple sw state variables. | |
12769 | */ | |
cfb23ed6 ML |
12770 | #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \ |
12771 | if (!intel_compare_link_m_n(¤t_config->name, \ | |
12772 | &pipe_config->name, adjust) && \ | |
12773 | !intel_compare_link_m_n(¤t_config->alt_name, \ | |
12774 | &pipe_config->name, adjust)) { \ | |
12775 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ | |
12776 | "(expected tu %i gmch %i/%i link %i/%i, " \ | |
12777 | "or tu %i gmch %i/%i link %i/%i, " \ | |
12778 | "found tu %i, gmch %i/%i link %i/%i)\n", \ | |
12779 | current_config->name.tu, \ | |
12780 | current_config->name.gmch_m, \ | |
12781 | current_config->name.gmch_n, \ | |
12782 | current_config->name.link_m, \ | |
12783 | current_config->name.link_n, \ | |
12784 | current_config->alt_name.tu, \ | |
12785 | current_config->alt_name.gmch_m, \ | |
12786 | current_config->alt_name.gmch_n, \ | |
12787 | current_config->alt_name.link_m, \ | |
12788 | current_config->alt_name.link_n, \ | |
12789 | pipe_config->name.tu, \ | |
12790 | pipe_config->name.gmch_m, \ | |
12791 | pipe_config->name.gmch_n, \ | |
12792 | pipe_config->name.link_m, \ | |
12793 | pipe_config->name.link_n); \ | |
12794 | ret = false; \ | |
88adfff1 DV |
12795 | } |
12796 | ||
1bd1bd80 DV |
12797 | #define PIPE_CONF_CHECK_FLAGS(name, mask) \ |
12798 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ | |
cfb23ed6 | 12799 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name "(" #mask ") " \ |
1bd1bd80 DV |
12800 | "(expected %i, found %i)\n", \ |
12801 | current_config->name & (mask), \ | |
12802 | pipe_config->name & (mask)); \ | |
cfb23ed6 | 12803 | ret = false; \ |
1bd1bd80 DV |
12804 | } |
12805 | ||
5e550656 VS |
12806 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \ |
12807 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ | |
cfb23ed6 | 12808 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
5e550656 VS |
12809 | "(expected %i, found %i)\n", \ |
12810 | current_config->name, \ | |
12811 | pipe_config->name); \ | |
cfb23ed6 | 12812 | ret = false; \ |
5e550656 VS |
12813 | } |
12814 | ||
bb760063 DV |
12815 | #define PIPE_CONF_QUIRK(quirk) \ |
12816 | ((current_config->quirks | pipe_config->quirks) & (quirk)) | |
12817 | ||
eccb140b DV |
12818 | PIPE_CONF_CHECK_I(cpu_transcoder); |
12819 | ||
08a24034 DV |
12820 | PIPE_CONF_CHECK_I(has_pch_encoder); |
12821 | PIPE_CONF_CHECK_I(fdi_lanes); | |
cfb23ed6 | 12822 | PIPE_CONF_CHECK_M_N(fdi_m_n); |
08a24034 | 12823 | |
eb14cb74 | 12824 | PIPE_CONF_CHECK_I(has_dp_encoder); |
90a6b7b0 | 12825 | PIPE_CONF_CHECK_I(lane_count); |
95a7a2ae | 12826 | PIPE_CONF_CHECK_X(lane_lat_optim_mask); |
b95af8be VK |
12827 | |
12828 | if (INTEL_INFO(dev)->gen < 8) { | |
cfb23ed6 ML |
12829 | PIPE_CONF_CHECK_M_N(dp_m_n); |
12830 | ||
cfb23ed6 ML |
12831 | if (current_config->has_drrs) |
12832 | PIPE_CONF_CHECK_M_N(dp_m2_n2); | |
12833 | } else | |
12834 | PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2); | |
eb14cb74 | 12835 | |
a65347ba JN |
12836 | PIPE_CONF_CHECK_I(has_dsi_encoder); |
12837 | ||
2d112de7 ACO |
12838 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
12839 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); | |
12840 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); | |
12841 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); | |
12842 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); | |
12843 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); | |
1bd1bd80 | 12844 | |
2d112de7 ACO |
12845 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
12846 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); | |
12847 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); | |
12848 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); | |
12849 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); | |
12850 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); | |
1bd1bd80 | 12851 | |
c93f54cf | 12852 | PIPE_CONF_CHECK_I(pixel_multiplier); |
6897b4b5 | 12853 | PIPE_CONF_CHECK_I(has_hdmi_sink); |
b5a9fa09 | 12854 | if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) || |
666a4537 | 12855 | IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) |
b5a9fa09 | 12856 | PIPE_CONF_CHECK_I(limited_color_range); |
e43823ec | 12857 | PIPE_CONF_CHECK_I(has_infoframe); |
6c49f241 | 12858 | |
9ed109a7 DV |
12859 | PIPE_CONF_CHECK_I(has_audio); |
12860 | ||
2d112de7 | 12861 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
1bd1bd80 DV |
12862 | DRM_MODE_FLAG_INTERLACE); |
12863 | ||
bb760063 | 12864 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
2d112de7 | 12865 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12866 | DRM_MODE_FLAG_PHSYNC); |
2d112de7 | 12867 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12868 | DRM_MODE_FLAG_NHSYNC); |
2d112de7 | 12869 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 12870 | DRM_MODE_FLAG_PVSYNC); |
2d112de7 | 12871 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 DV |
12872 | DRM_MODE_FLAG_NVSYNC); |
12873 | } | |
045ac3b5 | 12874 | |
333b8ca8 | 12875 | PIPE_CONF_CHECK_X(gmch_pfit.control); |
e2ff2d4a DV |
12876 | /* pfit ratios are autocomputed by the hw on gen4+ */ |
12877 | if (INTEL_INFO(dev)->gen < 4) | |
7f7d8dd6 | 12878 | PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios); |
333b8ca8 | 12879 | PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits); |
9953599b | 12880 | |
bfd16b2a ML |
12881 | if (!adjust) { |
12882 | PIPE_CONF_CHECK_I(pipe_src_w); | |
12883 | PIPE_CONF_CHECK_I(pipe_src_h); | |
12884 | ||
12885 | PIPE_CONF_CHECK_I(pch_pfit.enabled); | |
12886 | if (current_config->pch_pfit.enabled) { | |
12887 | PIPE_CONF_CHECK_X(pch_pfit.pos); | |
12888 | PIPE_CONF_CHECK_X(pch_pfit.size); | |
12889 | } | |
2fa2fe9a | 12890 | |
7aefe2b5 ML |
12891 | PIPE_CONF_CHECK_I(scaler_state.scaler_id); |
12892 | } | |
a1b2278e | 12893 | |
e59150dc JB |
12894 | /* BDW+ don't expose a synchronous way to read the state */ |
12895 | if (IS_HASWELL(dev)) | |
12896 | PIPE_CONF_CHECK_I(ips_enabled); | |
42db64ef | 12897 | |
282740f7 VS |
12898 | PIPE_CONF_CHECK_I(double_wide); |
12899 | ||
26804afd DV |
12900 | PIPE_CONF_CHECK_X(ddi_pll_sel); |
12901 | ||
8106ddbd | 12902 | PIPE_CONF_CHECK_P(shared_dpll); |
66e985c0 | 12903 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
8bcc2795 | 12904 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
66e985c0 DV |
12905 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
12906 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); | |
d452c5b6 | 12907 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
00490c22 | 12908 | PIPE_CONF_CHECK_X(dpll_hw_state.spll); |
3f4cd19f DL |
12909 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
12910 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); | |
12911 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); | |
c0d43d62 | 12912 | |
47eacbab VS |
12913 | PIPE_CONF_CHECK_X(dsi_pll.ctrl); |
12914 | PIPE_CONF_CHECK_X(dsi_pll.div); | |
12915 | ||
42571aef VS |
12916 | if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) |
12917 | PIPE_CONF_CHECK_I(pipe_bpp); | |
12918 | ||
2d112de7 | 12919 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
a9a7e98a | 12920 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
5e550656 | 12921 | |
66e985c0 | 12922 | #undef PIPE_CONF_CHECK_X |
08a24034 | 12923 | #undef PIPE_CONF_CHECK_I |
8106ddbd | 12924 | #undef PIPE_CONF_CHECK_P |
1bd1bd80 | 12925 | #undef PIPE_CONF_CHECK_FLAGS |
5e550656 | 12926 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
bb760063 | 12927 | #undef PIPE_CONF_QUIRK |
cfb23ed6 | 12928 | #undef INTEL_ERR_OR_DBG_KMS |
88adfff1 | 12929 | |
cfb23ed6 | 12930 | return ret; |
0e8ffe1b DV |
12931 | } |
12932 | ||
e3b247da VS |
12933 | static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv, |
12934 | const struct intel_crtc_state *pipe_config) | |
12935 | { | |
12936 | if (pipe_config->has_pch_encoder) { | |
21a727b3 | 12937 | int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config), |
e3b247da VS |
12938 | &pipe_config->fdi_m_n); |
12939 | int dotclock = pipe_config->base.adjusted_mode.crtc_clock; | |
12940 | ||
12941 | /* | |
12942 | * FDI already provided one idea for the dotclock. | |
12943 | * Yell if the encoder disagrees. | |
12944 | */ | |
12945 | WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock), | |
12946 | "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", | |
12947 | fdi_dotclock, dotclock); | |
12948 | } | |
12949 | } | |
12950 | ||
c0ead703 ML |
12951 | static void verify_wm_state(struct drm_crtc *crtc, |
12952 | struct drm_crtc_state *new_state) | |
08db6652 | 12953 | { |
e7c84544 | 12954 | struct drm_device *dev = crtc->dev; |
08db6652 DL |
12955 | struct drm_i915_private *dev_priv = dev->dev_private; |
12956 | struct skl_ddb_allocation hw_ddb, *sw_ddb; | |
e7c84544 ML |
12957 | struct skl_ddb_entry *hw_entry, *sw_entry; |
12958 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
12959 | const enum pipe pipe = intel_crtc->pipe; | |
08db6652 DL |
12960 | int plane; |
12961 | ||
e7c84544 | 12962 | if (INTEL_INFO(dev)->gen < 9 || !new_state->active) |
08db6652 DL |
12963 | return; |
12964 | ||
12965 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); | |
12966 | sw_ddb = &dev_priv->wm.skl_hw.ddb; | |
12967 | ||
e7c84544 ML |
12968 | /* planes */ |
12969 | for_each_plane(dev_priv, pipe, plane) { | |
12970 | hw_entry = &hw_ddb.plane[pipe][plane]; | |
12971 | sw_entry = &sw_ddb->plane[pipe][plane]; | |
08db6652 | 12972 | |
e7c84544 | 12973 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) |
08db6652 DL |
12974 | continue; |
12975 | ||
e7c84544 ML |
12976 | DRM_ERROR("mismatch in DDB state pipe %c plane %d " |
12977 | "(expected (%u,%u), found (%u,%u))\n", | |
12978 | pipe_name(pipe), plane + 1, | |
12979 | sw_entry->start, sw_entry->end, | |
12980 | hw_entry->start, hw_entry->end); | |
12981 | } | |
08db6652 | 12982 | |
e7c84544 ML |
12983 | /* cursor */ |
12984 | hw_entry = &hw_ddb.plane[pipe][PLANE_CURSOR]; | |
12985 | sw_entry = &sw_ddb->plane[pipe][PLANE_CURSOR]; | |
08db6652 | 12986 | |
e7c84544 | 12987 | if (!skl_ddb_entry_equal(hw_entry, sw_entry)) { |
08db6652 DL |
12988 | DRM_ERROR("mismatch in DDB state pipe %c cursor " |
12989 | "(expected (%u,%u), found (%u,%u))\n", | |
12990 | pipe_name(pipe), | |
12991 | sw_entry->start, sw_entry->end, | |
12992 | hw_entry->start, hw_entry->end); | |
12993 | } | |
12994 | } | |
12995 | ||
91d1b4bd | 12996 | static void |
c0ead703 | 12997 | verify_connector_state(struct drm_device *dev, struct drm_crtc *crtc) |
8af6cf88 | 12998 | { |
35dd3c64 | 12999 | struct drm_connector *connector; |
8af6cf88 | 13000 | |
e7c84544 | 13001 | drm_for_each_connector(connector, dev) { |
35dd3c64 ML |
13002 | struct drm_encoder *encoder = connector->encoder; |
13003 | struct drm_connector_state *state = connector->state; | |
ad3c558f | 13004 | |
e7c84544 ML |
13005 | if (state->crtc != crtc) |
13006 | continue; | |
13007 | ||
5a21b665 | 13008 | intel_connector_verify_state(to_intel_connector(connector)); |
8af6cf88 | 13009 | |
ad3c558f | 13010 | I915_STATE_WARN(state->best_encoder != encoder, |
35dd3c64 | 13011 | "connector's atomic encoder doesn't match legacy encoder\n"); |
8af6cf88 | 13012 | } |
91d1b4bd DV |
13013 | } |
13014 | ||
13015 | static void | |
c0ead703 | 13016 | verify_encoder_state(struct drm_device *dev) |
91d1b4bd DV |
13017 | { |
13018 | struct intel_encoder *encoder; | |
13019 | struct intel_connector *connector; | |
8af6cf88 | 13020 | |
b2784e15 | 13021 | for_each_intel_encoder(dev, encoder) { |
8af6cf88 | 13022 | bool enabled = false; |
4d20cd86 | 13023 | enum pipe pipe; |
8af6cf88 DV |
13024 | |
13025 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", | |
13026 | encoder->base.base.id, | |
8e329a03 | 13027 | encoder->base.name); |
8af6cf88 | 13028 | |
3a3371ff | 13029 | for_each_intel_connector(dev, connector) { |
4d20cd86 | 13030 | if (connector->base.state->best_encoder != &encoder->base) |
8af6cf88 DV |
13031 | continue; |
13032 | enabled = true; | |
ad3c558f ML |
13033 | |
13034 | I915_STATE_WARN(connector->base.state->crtc != | |
13035 | encoder->base.crtc, | |
13036 | "connector's crtc doesn't match encoder crtc\n"); | |
8af6cf88 | 13037 | } |
0e32b39c | 13038 | |
e2c719b7 | 13039 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
8af6cf88 DV |
13040 | "encoder's enabled state mismatch " |
13041 | "(expected %i, found %i)\n", | |
13042 | !!encoder->base.crtc, enabled); | |
7c60d198 ML |
13043 | |
13044 | if (!encoder->base.crtc) { | |
4d20cd86 | 13045 | bool active; |
7c60d198 | 13046 | |
4d20cd86 ML |
13047 | active = encoder->get_hw_state(encoder, &pipe); |
13048 | I915_STATE_WARN(active, | |
13049 | "encoder detached but still enabled on pipe %c.\n", | |
13050 | pipe_name(pipe)); | |
7c60d198 | 13051 | } |
8af6cf88 | 13052 | } |
91d1b4bd DV |
13053 | } |
13054 | ||
13055 | static void | |
c0ead703 ML |
13056 | verify_crtc_state(struct drm_crtc *crtc, |
13057 | struct drm_crtc_state *old_crtc_state, | |
13058 | struct drm_crtc_state *new_crtc_state) | |
91d1b4bd | 13059 | { |
e7c84544 | 13060 | struct drm_device *dev = crtc->dev; |
fbee40df | 13061 | struct drm_i915_private *dev_priv = dev->dev_private; |
91d1b4bd | 13062 | struct intel_encoder *encoder; |
e7c84544 ML |
13063 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
13064 | struct intel_crtc_state *pipe_config, *sw_config; | |
13065 | struct drm_atomic_state *old_state; | |
13066 | bool active; | |
045ac3b5 | 13067 | |
e7c84544 | 13068 | old_state = old_crtc_state->state; |
ec2dc6a0 | 13069 | __drm_atomic_helper_crtc_destroy_state(old_crtc_state); |
e7c84544 ML |
13070 | pipe_config = to_intel_crtc_state(old_crtc_state); |
13071 | memset(pipe_config, 0, sizeof(*pipe_config)); | |
13072 | pipe_config->base.crtc = crtc; | |
13073 | pipe_config->base.state = old_state; | |
8af6cf88 | 13074 | |
78108b7c | 13075 | DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name); |
8af6cf88 | 13076 | |
e7c84544 | 13077 | active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config); |
d62cf62a | 13078 | |
e7c84544 ML |
13079 | /* hw state is inconsistent with the pipe quirk */ |
13080 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || | |
13081 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) | |
13082 | active = new_crtc_state->active; | |
6c49f241 | 13083 | |
e7c84544 ML |
13084 | I915_STATE_WARN(new_crtc_state->active != active, |
13085 | "crtc active state doesn't match with hw state " | |
13086 | "(expected %i, found %i)\n", new_crtc_state->active, active); | |
0e8ffe1b | 13087 | |
e7c84544 ML |
13088 | I915_STATE_WARN(intel_crtc->active != new_crtc_state->active, |
13089 | "transitional active state does not match atomic hw state " | |
13090 | "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active); | |
4d20cd86 | 13091 | |
e7c84544 ML |
13092 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
13093 | enum pipe pipe; | |
4d20cd86 | 13094 | |
e7c84544 ML |
13095 | active = encoder->get_hw_state(encoder, &pipe); |
13096 | I915_STATE_WARN(active != new_crtc_state->active, | |
13097 | "[ENCODER:%i] active %i with crtc active %i\n", | |
13098 | encoder->base.base.id, active, new_crtc_state->active); | |
4d20cd86 | 13099 | |
e7c84544 ML |
13100 | I915_STATE_WARN(active && intel_crtc->pipe != pipe, |
13101 | "Encoder connected to wrong pipe %c\n", | |
13102 | pipe_name(pipe)); | |
4d20cd86 | 13103 | |
e7c84544 ML |
13104 | if (active) |
13105 | encoder->get_config(encoder, pipe_config); | |
13106 | } | |
53d9f4e9 | 13107 | |
e7c84544 ML |
13108 | if (!new_crtc_state->active) |
13109 | return; | |
cfb23ed6 | 13110 | |
e7c84544 | 13111 | intel_pipe_config_sanity_check(dev_priv, pipe_config); |
e3b247da | 13112 | |
e7c84544 ML |
13113 | sw_config = to_intel_crtc_state(crtc->state); |
13114 | if (!intel_pipe_config_compare(dev, sw_config, | |
13115 | pipe_config, false)) { | |
13116 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); | |
13117 | intel_dump_pipe_config(intel_crtc, pipe_config, | |
13118 | "[hw state]"); | |
13119 | intel_dump_pipe_config(intel_crtc, sw_config, | |
13120 | "[sw state]"); | |
8af6cf88 DV |
13121 | } |
13122 | } | |
13123 | ||
91d1b4bd | 13124 | static void |
c0ead703 ML |
13125 | verify_single_dpll_state(struct drm_i915_private *dev_priv, |
13126 | struct intel_shared_dpll *pll, | |
13127 | struct drm_crtc *crtc, | |
13128 | struct drm_crtc_state *new_state) | |
91d1b4bd | 13129 | { |
91d1b4bd | 13130 | struct intel_dpll_hw_state dpll_hw_state; |
e7c84544 ML |
13131 | unsigned crtc_mask; |
13132 | bool active; | |
5358901f | 13133 | |
e7c84544 | 13134 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); |
5358901f | 13135 | |
e7c84544 | 13136 | DRM_DEBUG_KMS("%s\n", pll->name); |
5358901f | 13137 | |
e7c84544 | 13138 | active = pll->funcs.get_hw_state(dev_priv, pll, &dpll_hw_state); |
5358901f | 13139 | |
e7c84544 ML |
13140 | if (!(pll->flags & INTEL_DPLL_ALWAYS_ON)) { |
13141 | I915_STATE_WARN(!pll->on && pll->active_mask, | |
13142 | "pll in active use but not on in sw tracking\n"); | |
13143 | I915_STATE_WARN(pll->on && !pll->active_mask, | |
13144 | "pll is on but not used by any active crtc\n"); | |
13145 | I915_STATE_WARN(pll->on != active, | |
13146 | "pll on state mismatch (expected %i, found %i)\n", | |
13147 | pll->on, active); | |
13148 | } | |
5358901f | 13149 | |
e7c84544 | 13150 | if (!crtc) { |
2dd66ebd | 13151 | I915_STATE_WARN(pll->active_mask & ~pll->config.crtc_mask, |
e7c84544 ML |
13152 | "more active pll users than references: %x vs %x\n", |
13153 | pll->active_mask, pll->config.crtc_mask); | |
5358901f | 13154 | |
e7c84544 ML |
13155 | return; |
13156 | } | |
13157 | ||
13158 | crtc_mask = 1 << drm_crtc_index(crtc); | |
13159 | ||
13160 | if (new_state->active) | |
13161 | I915_STATE_WARN(!(pll->active_mask & crtc_mask), | |
13162 | "pll active mismatch (expected pipe %c in active mask 0x%02x)\n", | |
13163 | pipe_name(drm_crtc_index(crtc)), pll->active_mask); | |
13164 | else | |
13165 | I915_STATE_WARN(pll->active_mask & crtc_mask, | |
13166 | "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n", | |
13167 | pipe_name(drm_crtc_index(crtc)), pll->active_mask); | |
2dd66ebd | 13168 | |
e7c84544 ML |
13169 | I915_STATE_WARN(!(pll->config.crtc_mask & crtc_mask), |
13170 | "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n", | |
13171 | crtc_mask, pll->config.crtc_mask); | |
66e985c0 | 13172 | |
e7c84544 ML |
13173 | I915_STATE_WARN(pll->on && memcmp(&pll->config.hw_state, |
13174 | &dpll_hw_state, | |
13175 | sizeof(dpll_hw_state)), | |
13176 | "pll hw state mismatch\n"); | |
13177 | } | |
13178 | ||
13179 | static void | |
c0ead703 ML |
13180 | verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc, |
13181 | struct drm_crtc_state *old_crtc_state, | |
13182 | struct drm_crtc_state *new_crtc_state) | |
e7c84544 ML |
13183 | { |
13184 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13185 | struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state); | |
13186 | struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state); | |
13187 | ||
13188 | if (new_state->shared_dpll) | |
c0ead703 | 13189 | verify_single_dpll_state(dev_priv, new_state->shared_dpll, crtc, new_crtc_state); |
e7c84544 ML |
13190 | |
13191 | if (old_state->shared_dpll && | |
13192 | old_state->shared_dpll != new_state->shared_dpll) { | |
13193 | unsigned crtc_mask = 1 << drm_crtc_index(crtc); | |
13194 | struct intel_shared_dpll *pll = old_state->shared_dpll; | |
13195 | ||
13196 | I915_STATE_WARN(pll->active_mask & crtc_mask, | |
13197 | "pll active mismatch (didn't expect pipe %c in active mask)\n", | |
13198 | pipe_name(drm_crtc_index(crtc))); | |
13199 | I915_STATE_WARN(pll->config.crtc_mask & crtc_mask, | |
13200 | "pll enabled crtcs mismatch (found %x in enabled mask)\n", | |
13201 | pipe_name(drm_crtc_index(crtc))); | |
5358901f | 13202 | } |
8af6cf88 DV |
13203 | } |
13204 | ||
e7c84544 | 13205 | static void |
c0ead703 | 13206 | intel_modeset_verify_crtc(struct drm_crtc *crtc, |
e7c84544 ML |
13207 | struct drm_crtc_state *old_state, |
13208 | struct drm_crtc_state *new_state) | |
13209 | { | |
5a21b665 DV |
13210 | if (!needs_modeset(new_state) && |
13211 | !to_intel_crtc_state(new_state)->update_pipe) | |
13212 | return; | |
13213 | ||
c0ead703 | 13214 | verify_wm_state(crtc, new_state); |
5a21b665 | 13215 | verify_connector_state(crtc->dev, crtc); |
c0ead703 ML |
13216 | verify_crtc_state(crtc, old_state, new_state); |
13217 | verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state); | |
e7c84544 ML |
13218 | } |
13219 | ||
13220 | static void | |
c0ead703 | 13221 | verify_disabled_dpll_state(struct drm_device *dev) |
e7c84544 ML |
13222 | { |
13223 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13224 | int i; | |
13225 | ||
13226 | for (i = 0; i < dev_priv->num_shared_dpll; i++) | |
c0ead703 | 13227 | verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL); |
e7c84544 ML |
13228 | } |
13229 | ||
13230 | static void | |
c0ead703 | 13231 | intel_modeset_verify_disabled(struct drm_device *dev) |
e7c84544 | 13232 | { |
c0ead703 ML |
13233 | verify_encoder_state(dev); |
13234 | verify_connector_state(dev, NULL); | |
13235 | verify_disabled_dpll_state(dev); | |
e7c84544 ML |
13236 | } |
13237 | ||
80715b2f VS |
13238 | static void update_scanline_offset(struct intel_crtc *crtc) |
13239 | { | |
13240 | struct drm_device *dev = crtc->base.dev; | |
13241 | ||
13242 | /* | |
13243 | * The scanline counter increments at the leading edge of hsync. | |
13244 | * | |
13245 | * On most platforms it starts counting from vtotal-1 on the | |
13246 | * first active line. That means the scanline counter value is | |
13247 | * always one less than what we would expect. Ie. just after | |
13248 | * start of vblank, which also occurs at start of hsync (on the | |
13249 | * last active line), the scanline counter will read vblank_start-1. | |
13250 | * | |
13251 | * On gen2 the scanline counter starts counting from 1 instead | |
13252 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 | |
13253 | * to keep the value positive), instead of adding one. | |
13254 | * | |
13255 | * On HSW+ the behaviour of the scanline counter depends on the output | |
13256 | * type. For DP ports it behaves like most other platforms, but on HDMI | |
13257 | * there's an extra 1 line difference. So we need to add two instead of | |
13258 | * one to the value. | |
13259 | */ | |
13260 | if (IS_GEN2(dev)) { | |
124abe07 | 13261 | const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode; |
80715b2f VS |
13262 | int vtotal; |
13263 | ||
124abe07 VS |
13264 | vtotal = adjusted_mode->crtc_vtotal; |
13265 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) | |
80715b2f VS |
13266 | vtotal /= 2; |
13267 | ||
13268 | crtc->scanline_offset = vtotal - 1; | |
13269 | } else if (HAS_DDI(dev) && | |
409ee761 | 13270 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) { |
80715b2f VS |
13271 | crtc->scanline_offset = 2; |
13272 | } else | |
13273 | crtc->scanline_offset = 1; | |
13274 | } | |
13275 | ||
ad421372 | 13276 | static void intel_modeset_clear_plls(struct drm_atomic_state *state) |
ed6739ef | 13277 | { |
225da59b | 13278 | struct drm_device *dev = state->dev; |
ed6739ef | 13279 | struct drm_i915_private *dev_priv = to_i915(dev); |
ad421372 | 13280 | struct intel_shared_dpll_config *shared_dpll = NULL; |
0a9ab303 ACO |
13281 | struct drm_crtc *crtc; |
13282 | struct drm_crtc_state *crtc_state; | |
0a9ab303 | 13283 | int i; |
ed6739ef ACO |
13284 | |
13285 | if (!dev_priv->display.crtc_compute_clock) | |
ad421372 | 13286 | return; |
ed6739ef | 13287 | |
0a9ab303 | 13288 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
fb1a38a9 | 13289 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8106ddbd ACO |
13290 | struct intel_shared_dpll *old_dpll = |
13291 | to_intel_crtc_state(crtc->state)->shared_dpll; | |
0a9ab303 | 13292 | |
fb1a38a9 | 13293 | if (!needs_modeset(crtc_state)) |
225da59b ACO |
13294 | continue; |
13295 | ||
8106ddbd | 13296 | to_intel_crtc_state(crtc_state)->shared_dpll = NULL; |
fb1a38a9 | 13297 | |
8106ddbd | 13298 | if (!old_dpll) |
fb1a38a9 | 13299 | continue; |
0a9ab303 | 13300 | |
ad421372 ML |
13301 | if (!shared_dpll) |
13302 | shared_dpll = intel_atomic_get_shared_dpll_state(state); | |
ed6739ef | 13303 | |
8106ddbd | 13304 | intel_shared_dpll_config_put(shared_dpll, old_dpll, intel_crtc); |
ad421372 | 13305 | } |
ed6739ef ACO |
13306 | } |
13307 | ||
99d736a2 ML |
13308 | /* |
13309 | * This implements the workaround described in the "notes" section of the mode | |
13310 | * set sequence documentation. When going from no pipes or single pipe to | |
13311 | * multiple pipes, and planes are enabled after the pipe, we need to wait at | |
13312 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. | |
13313 | */ | |
13314 | static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state) | |
13315 | { | |
13316 | struct drm_crtc_state *crtc_state; | |
13317 | struct intel_crtc *intel_crtc; | |
13318 | struct drm_crtc *crtc; | |
13319 | struct intel_crtc_state *first_crtc_state = NULL; | |
13320 | struct intel_crtc_state *other_crtc_state = NULL; | |
13321 | enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE; | |
13322 | int i; | |
13323 | ||
13324 | /* look at all crtc's that are going to be enabled in during modeset */ | |
13325 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
13326 | intel_crtc = to_intel_crtc(crtc); | |
13327 | ||
13328 | if (!crtc_state->active || !needs_modeset(crtc_state)) | |
13329 | continue; | |
13330 | ||
13331 | if (first_crtc_state) { | |
13332 | other_crtc_state = to_intel_crtc_state(crtc_state); | |
13333 | break; | |
13334 | } else { | |
13335 | first_crtc_state = to_intel_crtc_state(crtc_state); | |
13336 | first_pipe = intel_crtc->pipe; | |
13337 | } | |
13338 | } | |
13339 | ||
13340 | /* No workaround needed? */ | |
13341 | if (!first_crtc_state) | |
13342 | return 0; | |
13343 | ||
13344 | /* w/a possibly needed, check how many crtc's are already enabled. */ | |
13345 | for_each_intel_crtc(state->dev, intel_crtc) { | |
13346 | struct intel_crtc_state *pipe_config; | |
13347 | ||
13348 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); | |
13349 | if (IS_ERR(pipe_config)) | |
13350 | return PTR_ERR(pipe_config); | |
13351 | ||
13352 | pipe_config->hsw_workaround_pipe = INVALID_PIPE; | |
13353 | ||
13354 | if (!pipe_config->base.active || | |
13355 | needs_modeset(&pipe_config->base)) | |
13356 | continue; | |
13357 | ||
13358 | /* 2 or more enabled crtcs means no need for w/a */ | |
13359 | if (enabled_pipe != INVALID_PIPE) | |
13360 | return 0; | |
13361 | ||
13362 | enabled_pipe = intel_crtc->pipe; | |
13363 | } | |
13364 | ||
13365 | if (enabled_pipe != INVALID_PIPE) | |
13366 | first_crtc_state->hsw_workaround_pipe = enabled_pipe; | |
13367 | else if (other_crtc_state) | |
13368 | other_crtc_state->hsw_workaround_pipe = first_pipe; | |
13369 | ||
13370 | return 0; | |
13371 | } | |
13372 | ||
27c329ed ML |
13373 | static int intel_modeset_all_pipes(struct drm_atomic_state *state) |
13374 | { | |
13375 | struct drm_crtc *crtc; | |
13376 | struct drm_crtc_state *crtc_state; | |
13377 | int ret = 0; | |
13378 | ||
13379 | /* add all active pipes to the state */ | |
13380 | for_each_crtc(state->dev, crtc) { | |
13381 | crtc_state = drm_atomic_get_crtc_state(state, crtc); | |
13382 | if (IS_ERR(crtc_state)) | |
13383 | return PTR_ERR(crtc_state); | |
13384 | ||
13385 | if (!crtc_state->active || needs_modeset(crtc_state)) | |
13386 | continue; | |
13387 | ||
13388 | crtc_state->mode_changed = true; | |
13389 | ||
13390 | ret = drm_atomic_add_affected_connectors(state, crtc); | |
13391 | if (ret) | |
13392 | break; | |
13393 | ||
13394 | ret = drm_atomic_add_affected_planes(state, crtc); | |
13395 | if (ret) | |
13396 | break; | |
13397 | } | |
13398 | ||
13399 | return ret; | |
13400 | } | |
13401 | ||
c347a676 | 13402 | static int intel_modeset_checks(struct drm_atomic_state *state) |
054518dd | 13403 | { |
565602d7 ML |
13404 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
13405 | struct drm_i915_private *dev_priv = state->dev->dev_private; | |
13406 | struct drm_crtc *crtc; | |
13407 | struct drm_crtc_state *crtc_state; | |
13408 | int ret = 0, i; | |
054518dd | 13409 | |
b359283a ML |
13410 | if (!check_digital_port_conflicts(state)) { |
13411 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); | |
13412 | return -EINVAL; | |
13413 | } | |
13414 | ||
565602d7 ML |
13415 | intel_state->modeset = true; |
13416 | intel_state->active_crtcs = dev_priv->active_crtcs; | |
13417 | ||
13418 | for_each_crtc_in_state(state, crtc, crtc_state, i) { | |
13419 | if (crtc_state->active) | |
13420 | intel_state->active_crtcs |= 1 << i; | |
13421 | else | |
13422 | intel_state->active_crtcs &= ~(1 << i); | |
8b4a7d05 MR |
13423 | |
13424 | if (crtc_state->active != crtc->state->active) | |
13425 | intel_state->active_pipe_changes |= drm_crtc_mask(crtc); | |
565602d7 ML |
13426 | } |
13427 | ||
054518dd ACO |
13428 | /* |
13429 | * See if the config requires any additional preparation, e.g. | |
13430 | * to adjust global state with pipes off. We need to do this | |
13431 | * here so we can get the modeset_pipe updated config for the new | |
13432 | * mode set on this crtc. For other crtcs we need to use the | |
13433 | * adjusted_mode bits in the crtc directly. | |
13434 | */ | |
27c329ed | 13435 | if (dev_priv->display.modeset_calc_cdclk) { |
c89e39f3 | 13436 | if (!intel_state->cdclk_pll_vco) |
63911d72 | 13437 | intel_state->cdclk_pll_vco = dev_priv->cdclk_pll.vco; |
b2045352 VS |
13438 | if (!intel_state->cdclk_pll_vco) |
13439 | intel_state->cdclk_pll_vco = dev_priv->skl_preferred_vco_freq; | |
c89e39f3 | 13440 | |
27c329ed | 13441 | ret = dev_priv->display.modeset_calc_cdclk(state); |
c89e39f3 CT |
13442 | if (ret < 0) |
13443 | return ret; | |
27c329ed | 13444 | |
c89e39f3 | 13445 | if (intel_state->dev_cdclk != dev_priv->cdclk_freq || |
63911d72 | 13446 | intel_state->cdclk_pll_vco != dev_priv->cdclk_pll.vco) |
27c329ed ML |
13447 | ret = intel_modeset_all_pipes(state); |
13448 | ||
13449 | if (ret < 0) | |
054518dd | 13450 | return ret; |
e8788cbc ML |
13451 | |
13452 | DRM_DEBUG_KMS("New cdclk calculated to be atomic %u, actual %u\n", | |
13453 | intel_state->cdclk, intel_state->dev_cdclk); | |
27c329ed | 13454 | } else |
1a617b77 | 13455 | to_intel_atomic_state(state)->cdclk = dev_priv->atomic_cdclk_freq; |
054518dd | 13456 | |
ad421372 | 13457 | intel_modeset_clear_plls(state); |
054518dd | 13458 | |
565602d7 | 13459 | if (IS_HASWELL(dev_priv)) |
ad421372 | 13460 | return haswell_mode_set_planes_workaround(state); |
99d736a2 | 13461 | |
ad421372 | 13462 | return 0; |
c347a676 ACO |
13463 | } |
13464 | ||
aa363136 MR |
13465 | /* |
13466 | * Handle calculation of various watermark data at the end of the atomic check | |
13467 | * phase. The code here should be run after the per-crtc and per-plane 'check' | |
13468 | * handlers to ensure that all derived state has been updated. | |
13469 | */ | |
55994c2c | 13470 | static int calc_watermark_data(struct drm_atomic_state *state) |
aa363136 MR |
13471 | { |
13472 | struct drm_device *dev = state->dev; | |
98d39494 | 13473 | struct drm_i915_private *dev_priv = to_i915(dev); |
98d39494 MR |
13474 | |
13475 | /* Is there platform-specific watermark information to calculate? */ | |
13476 | if (dev_priv->display.compute_global_watermarks) | |
55994c2c MR |
13477 | return dev_priv->display.compute_global_watermarks(state); |
13478 | ||
13479 | return 0; | |
aa363136 MR |
13480 | } |
13481 | ||
74c090b1 ML |
13482 | /** |
13483 | * intel_atomic_check - validate state object | |
13484 | * @dev: drm device | |
13485 | * @state: state to validate | |
13486 | */ | |
13487 | static int intel_atomic_check(struct drm_device *dev, | |
13488 | struct drm_atomic_state *state) | |
c347a676 | 13489 | { |
dd8b3bdb | 13490 | struct drm_i915_private *dev_priv = to_i915(dev); |
aa363136 | 13491 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
c347a676 ACO |
13492 | struct drm_crtc *crtc; |
13493 | struct drm_crtc_state *crtc_state; | |
13494 | int ret, i; | |
61333b60 | 13495 | bool any_ms = false; |
c347a676 | 13496 | |
74c090b1 | 13497 | ret = drm_atomic_helper_check_modeset(dev, state); |
054518dd ACO |
13498 | if (ret) |
13499 | return ret; | |
13500 | ||
c347a676 | 13501 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
cfb23ed6 ML |
13502 | struct intel_crtc_state *pipe_config = |
13503 | to_intel_crtc_state(crtc_state); | |
1ed51de9 DV |
13504 | |
13505 | /* Catch I915_MODE_FLAG_INHERITED */ | |
13506 | if (crtc_state->mode.private_flags != crtc->state->mode.private_flags) | |
13507 | crtc_state->mode_changed = true; | |
cfb23ed6 | 13508 | |
af4a879e | 13509 | if (!needs_modeset(crtc_state)) |
c347a676 ACO |
13510 | continue; |
13511 | ||
af4a879e DV |
13512 | if (!crtc_state->enable) { |
13513 | any_ms = true; | |
cfb23ed6 | 13514 | continue; |
af4a879e | 13515 | } |
cfb23ed6 | 13516 | |
26495481 DV |
13517 | /* FIXME: For only active_changed we shouldn't need to do any |
13518 | * state recomputation at all. */ | |
13519 | ||
1ed51de9 DV |
13520 | ret = drm_atomic_add_affected_connectors(state, crtc); |
13521 | if (ret) | |
13522 | return ret; | |
b359283a | 13523 | |
cfb23ed6 | 13524 | ret = intel_modeset_pipe_config(crtc, pipe_config); |
25aa1c39 ML |
13525 | if (ret) { |
13526 | intel_dump_pipe_config(to_intel_crtc(crtc), | |
13527 | pipe_config, "[failed]"); | |
c347a676 | 13528 | return ret; |
25aa1c39 | 13529 | } |
c347a676 | 13530 | |
73831236 | 13531 | if (i915.fastboot && |
dd8b3bdb | 13532 | intel_pipe_config_compare(dev, |
cfb23ed6 | 13533 | to_intel_crtc_state(crtc->state), |
1ed51de9 | 13534 | pipe_config, true)) { |
26495481 | 13535 | crtc_state->mode_changed = false; |
bfd16b2a | 13536 | to_intel_crtc_state(crtc_state)->update_pipe = true; |
26495481 DV |
13537 | } |
13538 | ||
af4a879e | 13539 | if (needs_modeset(crtc_state)) |
26495481 | 13540 | any_ms = true; |
cfb23ed6 | 13541 | |
af4a879e DV |
13542 | ret = drm_atomic_add_affected_planes(state, crtc); |
13543 | if (ret) | |
13544 | return ret; | |
61333b60 | 13545 | |
26495481 DV |
13546 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, |
13547 | needs_modeset(crtc_state) ? | |
13548 | "[modeset]" : "[fastset]"); | |
c347a676 ACO |
13549 | } |
13550 | ||
61333b60 ML |
13551 | if (any_ms) { |
13552 | ret = intel_modeset_checks(state); | |
13553 | ||
13554 | if (ret) | |
13555 | return ret; | |
27c329ed | 13556 | } else |
dd8b3bdb | 13557 | intel_state->cdclk = dev_priv->cdclk_freq; |
76305b1a | 13558 | |
dd8b3bdb | 13559 | ret = drm_atomic_helper_check_planes(dev, state); |
aa363136 MR |
13560 | if (ret) |
13561 | return ret; | |
13562 | ||
f51be2e0 | 13563 | intel_fbc_choose_crtc(dev_priv, state); |
55994c2c | 13564 | return calc_watermark_data(state); |
054518dd ACO |
13565 | } |
13566 | ||
5008e874 ML |
13567 | static int intel_atomic_prepare_commit(struct drm_device *dev, |
13568 | struct drm_atomic_state *state, | |
81072bfd | 13569 | bool nonblock) |
5008e874 | 13570 | { |
7580d774 ML |
13571 | struct drm_i915_private *dev_priv = dev->dev_private; |
13572 | struct drm_plane_state *plane_state; | |
5008e874 | 13573 | struct drm_crtc_state *crtc_state; |
7580d774 | 13574 | struct drm_plane *plane; |
5008e874 ML |
13575 | struct drm_crtc *crtc; |
13576 | int i, ret; | |
13577 | ||
5a21b665 DV |
13578 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
13579 | if (state->legacy_cursor_update) | |
a6747b73 ML |
13580 | continue; |
13581 | ||
5a21b665 DV |
13582 | ret = intel_crtc_wait_for_pending_flips(crtc); |
13583 | if (ret) | |
13584 | return ret; | |
5008e874 | 13585 | |
5a21b665 DV |
13586 | if (atomic_read(&to_intel_crtc(crtc)->unpin_work_count) >= 2) |
13587 | flush_workqueue(dev_priv->wq); | |
d55dbd06 ML |
13588 | } |
13589 | ||
f935675f ML |
13590 | ret = mutex_lock_interruptible(&dev->struct_mutex); |
13591 | if (ret) | |
13592 | return ret; | |
13593 | ||
5008e874 | 13594 | ret = drm_atomic_helper_prepare_planes(dev, state); |
f7e5838b | 13595 | mutex_unlock(&dev->struct_mutex); |
7580d774 | 13596 | |
21daaeee | 13597 | if (!ret && !nonblock) { |
7580d774 ML |
13598 | for_each_plane_in_state(state, plane, plane_state, i) { |
13599 | struct intel_plane_state *intel_plane_state = | |
13600 | to_intel_plane_state(plane_state); | |
13601 | ||
13602 | if (!intel_plane_state->wait_req) | |
13603 | continue; | |
13604 | ||
13605 | ret = __i915_wait_request(intel_plane_state->wait_req, | |
299259a3 | 13606 | true, NULL, NULL); |
f7e5838b | 13607 | if (ret) { |
f4457ae7 CW |
13608 | /* Any hang should be swallowed by the wait */ |
13609 | WARN_ON(ret == -EIO); | |
f7e5838b CW |
13610 | mutex_lock(&dev->struct_mutex); |
13611 | drm_atomic_helper_cleanup_planes(dev, state); | |
13612 | mutex_unlock(&dev->struct_mutex); | |
7580d774 | 13613 | break; |
f7e5838b | 13614 | } |
7580d774 | 13615 | } |
7580d774 | 13616 | } |
5008e874 ML |
13617 | |
13618 | return ret; | |
13619 | } | |
13620 | ||
a2991414 ML |
13621 | u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc) |
13622 | { | |
13623 | struct drm_device *dev = crtc->base.dev; | |
13624 | ||
13625 | if (!dev->max_vblank_count) | |
13626 | return drm_accurate_vblank_count(&crtc->base); | |
13627 | ||
13628 | return dev->driver->get_vblank_counter(dev, crtc->pipe); | |
13629 | } | |
13630 | ||
5a21b665 DV |
13631 | static void intel_atomic_wait_for_vblanks(struct drm_device *dev, |
13632 | struct drm_i915_private *dev_priv, | |
13633 | unsigned crtc_mask) | |
e8861675 | 13634 | { |
5a21b665 DV |
13635 | unsigned last_vblank_count[I915_MAX_PIPES]; |
13636 | enum pipe pipe; | |
13637 | int ret; | |
e8861675 | 13638 | |
5a21b665 DV |
13639 | if (!crtc_mask) |
13640 | return; | |
e8861675 | 13641 | |
5a21b665 DV |
13642 | for_each_pipe(dev_priv, pipe) { |
13643 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
e8861675 | 13644 | |
5a21b665 | 13645 | if (!((1 << pipe) & crtc_mask)) |
e8861675 ML |
13646 | continue; |
13647 | ||
5a21b665 DV |
13648 | ret = drm_crtc_vblank_get(crtc); |
13649 | if (WARN_ON(ret != 0)) { | |
13650 | crtc_mask &= ~(1 << pipe); | |
13651 | continue; | |
e8861675 ML |
13652 | } |
13653 | ||
5a21b665 | 13654 | last_vblank_count[pipe] = drm_crtc_vblank_count(crtc); |
e8861675 ML |
13655 | } |
13656 | ||
5a21b665 DV |
13657 | for_each_pipe(dev_priv, pipe) { |
13658 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; | |
13659 | long lret; | |
e8861675 | 13660 | |
5a21b665 DV |
13661 | if (!((1 << pipe) & crtc_mask)) |
13662 | continue; | |
d55dbd06 | 13663 | |
5a21b665 DV |
13664 | lret = wait_event_timeout(dev->vblank[pipe].queue, |
13665 | last_vblank_count[pipe] != | |
13666 | drm_crtc_vblank_count(crtc), | |
13667 | msecs_to_jiffies(50)); | |
d55dbd06 | 13668 | |
5a21b665 | 13669 | WARN(!lret, "pipe %c vblank wait timed out\n", pipe_name(pipe)); |
d55dbd06 | 13670 | |
5a21b665 | 13671 | drm_crtc_vblank_put(crtc); |
d55dbd06 ML |
13672 | } |
13673 | } | |
13674 | ||
5a21b665 | 13675 | static bool needs_vblank_wait(struct intel_crtc_state *crtc_state) |
a6747b73 | 13676 | { |
5a21b665 DV |
13677 | /* fb updated, need to unpin old fb */ |
13678 | if (crtc_state->fb_changed) | |
13679 | return true; | |
a6747b73 | 13680 | |
5a21b665 DV |
13681 | /* wm changes, need vblank before final wm's */ |
13682 | if (crtc_state->update_wm_post) | |
13683 | return true; | |
a6747b73 | 13684 | |
5a21b665 DV |
13685 | /* |
13686 | * cxsr is re-enabled after vblank. | |
13687 | * This is already handled by crtc_state->update_wm_post, | |
13688 | * but added for clarity. | |
13689 | */ | |
13690 | if (crtc_state->disable_cxsr) | |
13691 | return true; | |
a6747b73 | 13692 | |
5a21b665 | 13693 | return false; |
e8861675 ML |
13694 | } |
13695 | ||
94f05024 | 13696 | static void intel_atomic_commit_tail(struct drm_atomic_state *state) |
a6778b3c | 13697 | { |
94f05024 | 13698 | struct drm_device *dev = state->dev; |
565602d7 | 13699 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
fbee40df | 13700 | struct drm_i915_private *dev_priv = dev->dev_private; |
29ceb0e6 | 13701 | struct drm_crtc_state *old_crtc_state; |
7580d774 | 13702 | struct drm_crtc *crtc; |
5a21b665 | 13703 | struct intel_crtc_state *intel_cstate; |
94f05024 DV |
13704 | struct drm_plane *plane; |
13705 | struct drm_plane_state *plane_state; | |
5a21b665 DV |
13706 | bool hw_check = intel_state->modeset; |
13707 | unsigned long put_domains[I915_MAX_PIPES] = {}; | |
13708 | unsigned crtc_vblank_mask = 0; | |
94f05024 | 13709 | int i, ret; |
a6778b3c | 13710 | |
94f05024 DV |
13711 | for_each_plane_in_state(state, plane, plane_state, i) { |
13712 | struct intel_plane_state *intel_plane_state = | |
13713 | to_intel_plane_state(plane_state); | |
ea0000f0 | 13714 | |
94f05024 DV |
13715 | if (!intel_plane_state->wait_req) |
13716 | continue; | |
d4afb8cc | 13717 | |
94f05024 DV |
13718 | ret = __i915_wait_request(intel_plane_state->wait_req, |
13719 | true, NULL, NULL); | |
13720 | /* EIO should be eaten, and we can't get interrupted in the | |
13721 | * worker, and blocking commits have waited already. */ | |
13722 | WARN_ON(ret); | |
13723 | } | |
1c5e19f8 | 13724 | |
ea0000f0 DV |
13725 | drm_atomic_helper_wait_for_dependencies(state); |
13726 | ||
565602d7 ML |
13727 | if (intel_state->modeset) { |
13728 | memcpy(dev_priv->min_pixclk, intel_state->min_pixclk, | |
13729 | sizeof(intel_state->min_pixclk)); | |
13730 | dev_priv->active_crtcs = intel_state->active_crtcs; | |
1a617b77 | 13731 | dev_priv->atomic_cdclk_freq = intel_state->cdclk; |
5a21b665 DV |
13732 | |
13733 | intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET); | |
565602d7 ML |
13734 | } |
13735 | ||
29ceb0e6 | 13736 | for_each_crtc_in_state(state, crtc, old_crtc_state, i) { |
a539205a ML |
13737 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
13738 | ||
5a21b665 DV |
13739 | if (needs_modeset(crtc->state) || |
13740 | to_intel_crtc_state(crtc->state)->update_pipe) { | |
13741 | hw_check = true; | |
13742 | ||
13743 | put_domains[to_intel_crtc(crtc)->pipe] = | |
13744 | modeset_get_crtc_power_domains(crtc, | |
13745 | to_intel_crtc_state(crtc->state)); | |
13746 | } | |
13747 | ||
61333b60 ML |
13748 | if (!needs_modeset(crtc->state)) |
13749 | continue; | |
13750 | ||
29ceb0e6 | 13751 | intel_pre_plane_update(to_intel_crtc_state(old_crtc_state)); |
460da916 | 13752 | |
29ceb0e6 VS |
13753 | if (old_crtc_state->active) { |
13754 | intel_crtc_disable_planes(crtc, old_crtc_state->plane_mask); | |
a539205a | 13755 | dev_priv->display.crtc_disable(crtc); |
eddfcbcd | 13756 | intel_crtc->active = false; |
58f9c0bc | 13757 | intel_fbc_disable(intel_crtc); |
eddfcbcd | 13758 | intel_disable_shared_dpll(intel_crtc); |
9bbc8258 VS |
13759 | |
13760 | /* | |
13761 | * Underruns don't always raise | |
13762 | * interrupts, so check manually. | |
13763 | */ | |
13764 | intel_check_cpu_fifo_underruns(dev_priv); | |
13765 | intel_check_pch_fifo_underruns(dev_priv); | |
b9001114 ML |
13766 | |
13767 | if (!crtc->state->active) | |
13768 | intel_update_watermarks(crtc); | |
a539205a | 13769 | } |
b8cecdf5 | 13770 | } |
7758a113 | 13771 | |
ea9d758d DV |
13772 | /* Only after disabling all output pipelines that will be changed can we |
13773 | * update the the output configuration. */ | |
4740b0f2 | 13774 | intel_modeset_update_crtc_state(state); |
f6e5b160 | 13775 | |
565602d7 | 13776 | if (intel_state->modeset) { |
4740b0f2 | 13777 | drm_atomic_helper_update_legacy_modeset_state(state->dev, state); |
33c8df89 ML |
13778 | |
13779 | if (dev_priv->display.modeset_commit_cdclk && | |
c89e39f3 | 13780 | (intel_state->dev_cdclk != dev_priv->cdclk_freq || |
63911d72 | 13781 | intel_state->cdclk_pll_vco != dev_priv->cdclk_pll.vco)) |
33c8df89 | 13782 | dev_priv->display.modeset_commit_cdclk(state); |
f6d1973d | 13783 | |
c0ead703 | 13784 | intel_modeset_verify_disabled(dev); |
4740b0f2 | 13785 | } |
47fab737 | 13786 | |
a6778b3c | 13787 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
29ceb0e6 | 13788 | for_each_crtc_in_state(state, crtc, old_crtc_state, i) { |
f6ac4b2a ML |
13789 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
13790 | bool modeset = needs_modeset(crtc->state); | |
5a21b665 DV |
13791 | struct intel_crtc_state *pipe_config = |
13792 | to_intel_crtc_state(crtc->state); | |
9f836f90 | 13793 | |
f6ac4b2a | 13794 | if (modeset && crtc->state->active) { |
a539205a ML |
13795 | update_scanline_offset(to_intel_crtc(crtc)); |
13796 | dev_priv->display.crtc_enable(crtc); | |
13797 | } | |
80715b2f | 13798 | |
1f7528c4 DV |
13799 | /* Complete events for now disable pipes here. */ |
13800 | if (modeset && !crtc->state->active && crtc->state->event) { | |
13801 | spin_lock_irq(&dev->event_lock); | |
13802 | drm_crtc_send_vblank_event(crtc, crtc->state->event); | |
13803 | spin_unlock_irq(&dev->event_lock); | |
13804 | ||
13805 | crtc->state->event = NULL; | |
13806 | } | |
13807 | ||
f6ac4b2a | 13808 | if (!modeset) |
29ceb0e6 | 13809 | intel_pre_plane_update(to_intel_crtc_state(old_crtc_state)); |
f6ac4b2a | 13810 | |
5a21b665 DV |
13811 | if (crtc->state->active && |
13812 | drm_atomic_get_existing_plane_state(state, crtc->primary)) | |
faf68d92 | 13813 | intel_fbc_enable(intel_crtc, pipe_config, to_intel_plane_state(crtc->primary->state)); |
5a21b665 | 13814 | |
1f7528c4 | 13815 | if (crtc->state->active) |
5a21b665 | 13816 | drm_atomic_helper_commit_planes_on_crtc(old_crtc_state); |
f6d1973d | 13817 | |
5a21b665 DV |
13818 | if (pipe_config->base.active && needs_vblank_wait(pipe_config)) |
13819 | crtc_vblank_mask |= 1 << i; | |
177246a8 MR |
13820 | } |
13821 | ||
94f05024 DV |
13822 | /* FIXME: We should call drm_atomic_helper_commit_hw_done() here |
13823 | * already, but still need the state for the delayed optimization. To | |
13824 | * fix this: | |
13825 | * - wrap the optimization/post_plane_update stuff into a per-crtc work. | |
13826 | * - schedule that vblank worker _before_ calling hw_done | |
13827 | * - at the start of commit_tail, cancel it _synchrously | |
13828 | * - switch over to the vblank wait helper in the core after that since | |
13829 | * we don't need out special handling any more. | |
13830 | */ | |
5a21b665 DV |
13831 | if (!state->legacy_cursor_update) |
13832 | intel_atomic_wait_for_vblanks(dev, dev_priv, crtc_vblank_mask); | |
13833 | ||
13834 | /* | |
13835 | * Now that the vblank has passed, we can go ahead and program the | |
13836 | * optimal watermarks on platforms that need two-step watermark | |
13837 | * programming. | |
13838 | * | |
13839 | * TODO: Move this (and other cleanup) to an async worker eventually. | |
13840 | */ | |
13841 | for_each_crtc_in_state(state, crtc, old_crtc_state, i) { | |
13842 | intel_cstate = to_intel_crtc_state(crtc->state); | |
13843 | ||
13844 | if (dev_priv->display.optimize_watermarks) | |
13845 | dev_priv->display.optimize_watermarks(intel_cstate); | |
13846 | } | |
13847 | ||
13848 | for_each_crtc_in_state(state, crtc, old_crtc_state, i) { | |
13849 | intel_post_plane_update(to_intel_crtc_state(old_crtc_state)); | |
13850 | ||
13851 | if (put_domains[i]) | |
13852 | modeset_put_power_domains(dev_priv, put_domains[i]); | |
13853 | ||
13854 | intel_modeset_verify_crtc(crtc, old_crtc_state, crtc->state); | |
13855 | } | |
13856 | ||
94f05024 DV |
13857 | drm_atomic_helper_commit_hw_done(state); |
13858 | ||
5a21b665 DV |
13859 | if (intel_state->modeset) |
13860 | intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET); | |
13861 | ||
13862 | mutex_lock(&dev->struct_mutex); | |
13863 | drm_atomic_helper_cleanup_planes(dev, state); | |
13864 | mutex_unlock(&dev->struct_mutex); | |
13865 | ||
ea0000f0 DV |
13866 | drm_atomic_helper_commit_cleanup_done(state); |
13867 | ||
ee165b1a | 13868 | drm_atomic_state_free(state); |
f30da187 | 13869 | |
75714940 MK |
13870 | /* As one of the primary mmio accessors, KMS has a high likelihood |
13871 | * of triggering bugs in unclaimed access. After we finish | |
13872 | * modesetting, see if an error has been flagged, and if so | |
13873 | * enable debugging for the next modeset - and hope we catch | |
13874 | * the culprit. | |
13875 | * | |
13876 | * XXX note that we assume display power is on at this point. | |
13877 | * This might hold true now but we need to add pm helper to check | |
13878 | * unclaimed only when the hardware is on, as atomic commits | |
13879 | * can happen also when the device is completely off. | |
13880 | */ | |
13881 | intel_uncore_arm_unclaimed_mmio_detection(dev_priv); | |
94f05024 DV |
13882 | } |
13883 | ||
13884 | static void intel_atomic_commit_work(struct work_struct *work) | |
13885 | { | |
13886 | struct drm_atomic_state *state = container_of(work, | |
13887 | struct drm_atomic_state, | |
13888 | commit_work); | |
13889 | intel_atomic_commit_tail(state); | |
13890 | } | |
13891 | ||
6c9c1b38 DV |
13892 | static void intel_atomic_track_fbs(struct drm_atomic_state *state) |
13893 | { | |
13894 | struct drm_plane_state *old_plane_state; | |
13895 | struct drm_plane *plane; | |
13896 | struct drm_i915_gem_object *obj, *old_obj; | |
13897 | struct intel_plane *intel_plane; | |
13898 | int i; | |
13899 | ||
13900 | mutex_lock(&state->dev->struct_mutex); | |
13901 | for_each_plane_in_state(state, plane, old_plane_state, i) { | |
13902 | obj = intel_fb_obj(plane->state->fb); | |
13903 | old_obj = intel_fb_obj(old_plane_state->fb); | |
13904 | intel_plane = to_intel_plane(plane); | |
13905 | ||
13906 | i915_gem_track_fb(old_obj, obj, intel_plane->frontbuffer_bit); | |
13907 | } | |
13908 | mutex_unlock(&state->dev->struct_mutex); | |
13909 | } | |
13910 | ||
94f05024 DV |
13911 | /** |
13912 | * intel_atomic_commit - commit validated state object | |
13913 | * @dev: DRM device | |
13914 | * @state: the top-level driver state object | |
13915 | * @nonblock: nonblocking commit | |
13916 | * | |
13917 | * This function commits a top-level state object that has been validated | |
13918 | * with drm_atomic_helper_check(). | |
13919 | * | |
13920 | * FIXME: Atomic modeset support for i915 is not yet complete. At the moment | |
13921 | * nonblocking commits are only safe for pure plane updates. Everything else | |
13922 | * should work though. | |
13923 | * | |
13924 | * RETURNS | |
13925 | * Zero for success or -errno. | |
13926 | */ | |
13927 | static int intel_atomic_commit(struct drm_device *dev, | |
13928 | struct drm_atomic_state *state, | |
13929 | bool nonblock) | |
13930 | { | |
13931 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); | |
13932 | struct drm_i915_private *dev_priv = dev->dev_private; | |
13933 | int ret = 0; | |
13934 | ||
13935 | if (intel_state->modeset && nonblock) { | |
13936 | DRM_DEBUG_KMS("nonblocking commit for modeset not yet implemented.\n"); | |
13937 | return -EINVAL; | |
13938 | } | |
13939 | ||
13940 | ret = drm_atomic_helper_setup_commit(state, nonblock); | |
13941 | if (ret) | |
13942 | return ret; | |
13943 | ||
13944 | INIT_WORK(&state->commit_work, intel_atomic_commit_work); | |
13945 | ||
13946 | ret = intel_atomic_prepare_commit(dev, state, nonblock); | |
13947 | if (ret) { | |
13948 | DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret); | |
13949 | return ret; | |
13950 | } | |
13951 | ||
13952 | drm_atomic_helper_swap_state(state, true); | |
13953 | dev_priv->wm.distrust_bios_wm = false; | |
13954 | dev_priv->wm.skl_results = intel_state->wm_results; | |
13955 | intel_shared_dpll_commit(state); | |
6c9c1b38 | 13956 | intel_atomic_track_fbs(state); |
94f05024 DV |
13957 | |
13958 | if (nonblock) | |
13959 | queue_work(system_unbound_wq, &state->commit_work); | |
13960 | else | |
13961 | intel_atomic_commit_tail(state); | |
75714940 | 13962 | |
74c090b1 | 13963 | return 0; |
7f27126e JB |
13964 | } |
13965 | ||
c0c36b94 CW |
13966 | void intel_crtc_restore_mode(struct drm_crtc *crtc) |
13967 | { | |
83a57153 ACO |
13968 | struct drm_device *dev = crtc->dev; |
13969 | struct drm_atomic_state *state; | |
e694eb02 | 13970 | struct drm_crtc_state *crtc_state; |
2bfb4627 | 13971 | int ret; |
83a57153 ACO |
13972 | |
13973 | state = drm_atomic_state_alloc(dev); | |
13974 | if (!state) { | |
78108b7c VS |
13975 | DRM_DEBUG_KMS("[CRTC:%d:%s] crtc restore failed, out of memory", |
13976 | crtc->base.id, crtc->name); | |
83a57153 ACO |
13977 | return; |
13978 | } | |
13979 | ||
e694eb02 | 13980 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
83a57153 | 13981 | |
e694eb02 ML |
13982 | retry: |
13983 | crtc_state = drm_atomic_get_crtc_state(state, crtc); | |
13984 | ret = PTR_ERR_OR_ZERO(crtc_state); | |
13985 | if (!ret) { | |
13986 | if (!crtc_state->active) | |
13987 | goto out; | |
83a57153 | 13988 | |
e694eb02 | 13989 | crtc_state->mode_changed = true; |
74c090b1 | 13990 | ret = drm_atomic_commit(state); |
83a57153 ACO |
13991 | } |
13992 | ||
e694eb02 ML |
13993 | if (ret == -EDEADLK) { |
13994 | drm_atomic_state_clear(state); | |
13995 | drm_modeset_backoff(state->acquire_ctx); | |
13996 | goto retry; | |
4ed9fb37 | 13997 | } |
4be07317 | 13998 | |
2bfb4627 | 13999 | if (ret) |
e694eb02 | 14000 | out: |
2bfb4627 | 14001 | drm_atomic_state_free(state); |
c0c36b94 CW |
14002 | } |
14003 | ||
25c5b266 DV |
14004 | #undef for_each_intel_crtc_masked |
14005 | ||
f6e5b160 | 14006 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
82cf435b | 14007 | .gamma_set = drm_atomic_helper_legacy_gamma_set, |
74c090b1 | 14008 | .set_config = drm_atomic_helper_set_config, |
82cf435b | 14009 | .set_property = drm_atomic_helper_crtc_set_property, |
f6e5b160 | 14010 | .destroy = intel_crtc_destroy, |
ee042aa4 | 14011 | .page_flip = drm_atomic_helper_page_flip, |
1356837e MR |
14012 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
14013 | .atomic_destroy_state = intel_crtc_destroy_state, | |
f6e5b160 CW |
14014 | }; |
14015 | ||
6beb8c23 MR |
14016 | /** |
14017 | * intel_prepare_plane_fb - Prepare fb for usage on plane | |
14018 | * @plane: drm plane to prepare for | |
14019 | * @fb: framebuffer to prepare for presentation | |
14020 | * | |
14021 | * Prepares a framebuffer for usage on a display plane. Generally this | |
14022 | * involves pinning the underlying object and updating the frontbuffer tracking | |
14023 | * bits. Some older platforms need special physical address handling for | |
14024 | * cursor planes. | |
14025 | * | |
f935675f ML |
14026 | * Must be called with struct_mutex held. |
14027 | * | |
6beb8c23 MR |
14028 | * Returns 0 on success, negative error code on failure. |
14029 | */ | |
14030 | int | |
14031 | intel_prepare_plane_fb(struct drm_plane *plane, | |
d136dfee | 14032 | const struct drm_plane_state *new_state) |
465c120c MR |
14033 | { |
14034 | struct drm_device *dev = plane->dev; | |
844f9111 | 14035 | struct drm_framebuffer *fb = new_state->fb; |
6beb8c23 | 14036 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
1ee49399 | 14037 | struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb); |
c37efb99 | 14038 | struct reservation_object *resv; |
6beb8c23 | 14039 | int ret = 0; |
465c120c | 14040 | |
1ee49399 | 14041 | if (!obj && !old_obj) |
465c120c MR |
14042 | return 0; |
14043 | ||
5008e874 ML |
14044 | if (old_obj) { |
14045 | struct drm_crtc_state *crtc_state = | |
14046 | drm_atomic_get_existing_crtc_state(new_state->state, plane->state->crtc); | |
14047 | ||
14048 | /* Big Hammer, we also need to ensure that any pending | |
14049 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the | |
14050 | * current scanout is retired before unpinning the old | |
14051 | * framebuffer. Note that we rely on userspace rendering | |
14052 | * into the buffer attached to the pipe they are waiting | |
14053 | * on. If not, userspace generates a GPU hang with IPEHR | |
14054 | * point to the MI_WAIT_FOR_EVENT. | |
14055 | * | |
14056 | * This should only fail upon a hung GPU, in which case we | |
14057 | * can safely continue. | |
14058 | */ | |
14059 | if (needs_modeset(crtc_state)) | |
14060 | ret = i915_gem_object_wait_rendering(old_obj, true); | |
f4457ae7 CW |
14061 | if (ret) { |
14062 | /* GPU hangs should have been swallowed by the wait */ | |
14063 | WARN_ON(ret == -EIO); | |
f935675f | 14064 | return ret; |
f4457ae7 | 14065 | } |
5008e874 ML |
14066 | } |
14067 | ||
c37efb99 CW |
14068 | if (!obj) |
14069 | return 0; | |
14070 | ||
5a21b665 | 14071 | /* For framebuffer backed by dmabuf, wait for fence */ |
c37efb99 CW |
14072 | resv = i915_gem_object_get_dmabuf_resv(obj); |
14073 | if (resv) { | |
5a21b665 DV |
14074 | long lret; |
14075 | ||
c37efb99 | 14076 | lret = reservation_object_wait_timeout_rcu(resv, false, true, |
5a21b665 DV |
14077 | MAX_SCHEDULE_TIMEOUT); |
14078 | if (lret == -ERESTARTSYS) | |
14079 | return lret; | |
14080 | ||
14081 | WARN(lret < 0, "waiting returns %li\n", lret); | |
14082 | } | |
14083 | ||
c37efb99 | 14084 | if (plane->type == DRM_PLANE_TYPE_CURSOR && |
6beb8c23 MR |
14085 | INTEL_INFO(dev)->cursor_needs_physical) { |
14086 | int align = IS_I830(dev) ? 16 * 1024 : 256; | |
14087 | ret = i915_gem_object_attach_phys(obj, align); | |
14088 | if (ret) | |
14089 | DRM_DEBUG_KMS("failed to attach phys object\n"); | |
14090 | } else { | |
3465c580 | 14091 | ret = intel_pin_and_fence_fb_obj(fb, new_state->rotation); |
6beb8c23 | 14092 | } |
465c120c | 14093 | |
c37efb99 | 14094 | if (ret == 0) { |
6c9c1b38 DV |
14095 | struct intel_plane_state *plane_state = |
14096 | to_intel_plane_state(new_state); | |
7580d774 | 14097 | |
6c9c1b38 DV |
14098 | i915_gem_request_assign(&plane_state->wait_req, |
14099 | obj->last_write_req); | |
7580d774 | 14100 | } |
fdd508a6 | 14101 | |
6beb8c23 MR |
14102 | return ret; |
14103 | } | |
14104 | ||
38f3ce3a MR |
14105 | /** |
14106 | * intel_cleanup_plane_fb - Cleans up an fb after plane use | |
14107 | * @plane: drm plane to clean up for | |
14108 | * @fb: old framebuffer that was on plane | |
14109 | * | |
14110 | * Cleans up a framebuffer that has just been removed from a plane. | |
f935675f ML |
14111 | * |
14112 | * Must be called with struct_mutex held. | |
38f3ce3a MR |
14113 | */ |
14114 | void | |
14115 | intel_cleanup_plane_fb(struct drm_plane *plane, | |
d136dfee | 14116 | const struct drm_plane_state *old_state) |
38f3ce3a MR |
14117 | { |
14118 | struct drm_device *dev = plane->dev; | |
7580d774 | 14119 | struct intel_plane_state *old_intel_state; |
1ee49399 ML |
14120 | struct drm_i915_gem_object *old_obj = intel_fb_obj(old_state->fb); |
14121 | struct drm_i915_gem_object *obj = intel_fb_obj(plane->state->fb); | |
38f3ce3a | 14122 | |
7580d774 ML |
14123 | old_intel_state = to_intel_plane_state(old_state); |
14124 | ||
1ee49399 | 14125 | if (!obj && !old_obj) |
38f3ce3a MR |
14126 | return; |
14127 | ||
1ee49399 ML |
14128 | if (old_obj && (plane->type != DRM_PLANE_TYPE_CURSOR || |
14129 | !INTEL_INFO(dev)->cursor_needs_physical)) | |
3465c580 | 14130 | intel_unpin_fb_obj(old_state->fb, old_state->rotation); |
1ee49399 | 14131 | |
7580d774 | 14132 | i915_gem_request_assign(&old_intel_state->wait_req, NULL); |
465c120c MR |
14133 | } |
14134 | ||
6156a456 CK |
14135 | int |
14136 | skl_max_scale(struct intel_crtc *intel_crtc, struct intel_crtc_state *crtc_state) | |
14137 | { | |
14138 | int max_scale; | |
14139 | struct drm_device *dev; | |
14140 | struct drm_i915_private *dev_priv; | |
14141 | int crtc_clock, cdclk; | |
14142 | ||
bf8a0af0 | 14143 | if (!intel_crtc || !crtc_state->base.enable) |
6156a456 CK |
14144 | return DRM_PLANE_HELPER_NO_SCALING; |
14145 | ||
14146 | dev = intel_crtc->base.dev; | |
14147 | dev_priv = dev->dev_private; | |
14148 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; | |
27c329ed | 14149 | cdclk = to_intel_atomic_state(crtc_state->base.state)->cdclk; |
6156a456 | 14150 | |
54bf1ce6 | 14151 | if (WARN_ON_ONCE(!crtc_clock || cdclk < crtc_clock)) |
6156a456 CK |
14152 | return DRM_PLANE_HELPER_NO_SCALING; |
14153 | ||
14154 | /* | |
14155 | * skl max scale is lower of: | |
14156 | * close to 3 but not 3, -1 is for that purpose | |
14157 | * or | |
14158 | * cdclk/crtc_clock | |
14159 | */ | |
14160 | max_scale = min((1 << 16) * 3 - 1, (1 << 8) * ((cdclk << 8) / crtc_clock)); | |
14161 | ||
14162 | return max_scale; | |
14163 | } | |
14164 | ||
465c120c | 14165 | static int |
3c692a41 | 14166 | intel_check_primary_plane(struct drm_plane *plane, |
061e4b8d | 14167 | struct intel_crtc_state *crtc_state, |
3c692a41 GP |
14168 | struct intel_plane_state *state) |
14169 | { | |
2b875c22 MR |
14170 | struct drm_crtc *crtc = state->base.crtc; |
14171 | struct drm_framebuffer *fb = state->base.fb; | |
6156a456 | 14172 | int min_scale = DRM_PLANE_HELPER_NO_SCALING; |
061e4b8d ML |
14173 | int max_scale = DRM_PLANE_HELPER_NO_SCALING; |
14174 | bool can_position = false; | |
465c120c | 14175 | |
693bdc28 VS |
14176 | if (INTEL_INFO(plane->dev)->gen >= 9) { |
14177 | /* use scaler when colorkey is not required */ | |
14178 | if (state->ckey.flags == I915_SET_COLORKEY_NONE) { | |
14179 | min_scale = 1; | |
14180 | max_scale = skl_max_scale(to_intel_crtc(crtc), crtc_state); | |
14181 | } | |
d8106366 | 14182 | can_position = true; |
6156a456 | 14183 | } |
d8106366 | 14184 | |
061e4b8d ML |
14185 | return drm_plane_helper_check_update(plane, crtc, fb, &state->src, |
14186 | &state->dst, &state->clip, | |
9b8b013d | 14187 | state->base.rotation, |
da20eabd ML |
14188 | min_scale, max_scale, |
14189 | can_position, true, | |
14190 | &state->visible); | |
14af293f GP |
14191 | } |
14192 | ||
5a21b665 DV |
14193 | static void intel_begin_crtc_commit(struct drm_crtc *crtc, |
14194 | struct drm_crtc_state *old_crtc_state) | |
14195 | { | |
14196 | struct drm_device *dev = crtc->dev; | |
14197 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
14198 | struct intel_crtc_state *old_intel_state = | |
14199 | to_intel_crtc_state(old_crtc_state); | |
14200 | bool modeset = needs_modeset(crtc->state); | |
14201 | ||
14202 | /* Perform vblank evasion around commit operation */ | |
14203 | intel_pipe_update_start(intel_crtc); | |
14204 | ||
14205 | if (modeset) | |
14206 | return; | |
14207 | ||
14208 | if (crtc->state->color_mgmt_changed || to_intel_crtc_state(crtc->state)->update_pipe) { | |
14209 | intel_color_set_csc(crtc->state); | |
14210 | intel_color_load_luts(crtc->state); | |
14211 | } | |
14212 | ||
14213 | if (to_intel_crtc_state(crtc->state)->update_pipe) | |
14214 | intel_update_pipe_config(intel_crtc, old_intel_state); | |
14215 | else if (INTEL_INFO(dev)->gen >= 9) | |
14216 | skl_detach_scalers(intel_crtc); | |
14217 | } | |
14218 | ||
14219 | static void intel_finish_crtc_commit(struct drm_crtc *crtc, | |
14220 | struct drm_crtc_state *old_crtc_state) | |
14221 | { | |
14222 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
14223 | ||
14224 | intel_pipe_update_end(intel_crtc, NULL); | |
14225 | } | |
14226 | ||
cf4c7c12 | 14227 | /** |
4a3b8769 MR |
14228 | * intel_plane_destroy - destroy a plane |
14229 | * @plane: plane to destroy | |
cf4c7c12 | 14230 | * |
4a3b8769 MR |
14231 | * Common destruction function for all types of planes (primary, cursor, |
14232 | * sprite). | |
cf4c7c12 | 14233 | */ |
4a3b8769 | 14234 | void intel_plane_destroy(struct drm_plane *plane) |
465c120c | 14235 | { |
69ae561f VS |
14236 | if (!plane) |
14237 | return; | |
14238 | ||
465c120c | 14239 | drm_plane_cleanup(plane); |
69ae561f | 14240 | kfree(to_intel_plane(plane)); |
465c120c MR |
14241 | } |
14242 | ||
65a3fea0 | 14243 | const struct drm_plane_funcs intel_plane_funcs = { |
70a101f8 MR |
14244 | .update_plane = drm_atomic_helper_update_plane, |
14245 | .disable_plane = drm_atomic_helper_disable_plane, | |
3d7d6510 | 14246 | .destroy = intel_plane_destroy, |
c196e1d6 | 14247 | .set_property = drm_atomic_helper_plane_set_property, |
a98b3431 MR |
14248 | .atomic_get_property = intel_plane_atomic_get_property, |
14249 | .atomic_set_property = intel_plane_atomic_set_property, | |
ea2c67bb MR |
14250 | .atomic_duplicate_state = intel_plane_duplicate_state, |
14251 | .atomic_destroy_state = intel_plane_destroy_state, | |
14252 | ||
465c120c MR |
14253 | }; |
14254 | ||
14255 | static struct drm_plane *intel_primary_plane_create(struct drm_device *dev, | |
14256 | int pipe) | |
14257 | { | |
fca0ce2a VS |
14258 | struct intel_plane *primary = NULL; |
14259 | struct intel_plane_state *state = NULL; | |
465c120c | 14260 | const uint32_t *intel_primary_formats; |
45e3743a | 14261 | unsigned int num_formats; |
fca0ce2a | 14262 | int ret; |
465c120c MR |
14263 | |
14264 | primary = kzalloc(sizeof(*primary), GFP_KERNEL); | |
fca0ce2a VS |
14265 | if (!primary) |
14266 | goto fail; | |
465c120c | 14267 | |
8e7d688b | 14268 | state = intel_create_plane_state(&primary->base); |
fca0ce2a VS |
14269 | if (!state) |
14270 | goto fail; | |
8e7d688b | 14271 | primary->base.state = &state->base; |
ea2c67bb | 14272 | |
465c120c MR |
14273 | primary->can_scale = false; |
14274 | primary->max_downscale = 1; | |
6156a456 CK |
14275 | if (INTEL_INFO(dev)->gen >= 9) { |
14276 | primary->can_scale = true; | |
af99ceda | 14277 | state->scaler_id = -1; |
6156a456 | 14278 | } |
465c120c MR |
14279 | primary->pipe = pipe; |
14280 | primary->plane = pipe; | |
a9ff8714 | 14281 | primary->frontbuffer_bit = INTEL_FRONTBUFFER_PRIMARY(pipe); |
c59cb179 | 14282 | primary->check_plane = intel_check_primary_plane; |
465c120c MR |
14283 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) |
14284 | primary->plane = !pipe; | |
14285 | ||
6c0fd451 DL |
14286 | if (INTEL_INFO(dev)->gen >= 9) { |
14287 | intel_primary_formats = skl_primary_formats; | |
14288 | num_formats = ARRAY_SIZE(skl_primary_formats); | |
a8d201af ML |
14289 | |
14290 | primary->update_plane = skylake_update_primary_plane; | |
14291 | primary->disable_plane = skylake_disable_primary_plane; | |
14292 | } else if (HAS_PCH_SPLIT(dev)) { | |
14293 | intel_primary_formats = i965_primary_formats; | |
14294 | num_formats = ARRAY_SIZE(i965_primary_formats); | |
14295 | ||
14296 | primary->update_plane = ironlake_update_primary_plane; | |
14297 | primary->disable_plane = i9xx_disable_primary_plane; | |
6c0fd451 | 14298 | } else if (INTEL_INFO(dev)->gen >= 4) { |
568db4f2 DL |
14299 | intel_primary_formats = i965_primary_formats; |
14300 | num_formats = ARRAY_SIZE(i965_primary_formats); | |
a8d201af ML |
14301 | |
14302 | primary->update_plane = i9xx_update_primary_plane; | |
14303 | primary->disable_plane = i9xx_disable_primary_plane; | |
6c0fd451 DL |
14304 | } else { |
14305 | intel_primary_formats = i8xx_primary_formats; | |
14306 | num_formats = ARRAY_SIZE(i8xx_primary_formats); | |
a8d201af ML |
14307 | |
14308 | primary->update_plane = i9xx_update_primary_plane; | |
14309 | primary->disable_plane = i9xx_disable_primary_plane; | |
465c120c MR |
14310 | } |
14311 | ||
38573dc1 VS |
14312 | if (INTEL_INFO(dev)->gen >= 9) |
14313 | ret = drm_universal_plane_init(dev, &primary->base, 0, | |
14314 | &intel_plane_funcs, | |
14315 | intel_primary_formats, num_formats, | |
14316 | DRM_PLANE_TYPE_PRIMARY, | |
14317 | "plane 1%c", pipe_name(pipe)); | |
14318 | else if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) | |
14319 | ret = drm_universal_plane_init(dev, &primary->base, 0, | |
14320 | &intel_plane_funcs, | |
14321 | intel_primary_formats, num_formats, | |
14322 | DRM_PLANE_TYPE_PRIMARY, | |
14323 | "primary %c", pipe_name(pipe)); | |
14324 | else | |
14325 | ret = drm_universal_plane_init(dev, &primary->base, 0, | |
14326 | &intel_plane_funcs, | |
14327 | intel_primary_formats, num_formats, | |
14328 | DRM_PLANE_TYPE_PRIMARY, | |
14329 | "plane %c", plane_name(primary->plane)); | |
fca0ce2a VS |
14330 | if (ret) |
14331 | goto fail; | |
48404c1e | 14332 | |
3b7a5119 SJ |
14333 | if (INTEL_INFO(dev)->gen >= 4) |
14334 | intel_create_rotation_property(dev, primary); | |
48404c1e | 14335 | |
ea2c67bb MR |
14336 | drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs); |
14337 | ||
465c120c | 14338 | return &primary->base; |
fca0ce2a VS |
14339 | |
14340 | fail: | |
14341 | kfree(state); | |
14342 | kfree(primary); | |
14343 | ||
14344 | return NULL; | |
465c120c MR |
14345 | } |
14346 | ||
3b7a5119 SJ |
14347 | void intel_create_rotation_property(struct drm_device *dev, struct intel_plane *plane) |
14348 | { | |
14349 | if (!dev->mode_config.rotation_property) { | |
14350 | unsigned long flags = BIT(DRM_ROTATE_0) | | |
14351 | BIT(DRM_ROTATE_180); | |
14352 | ||
14353 | if (INTEL_INFO(dev)->gen >= 9) | |
14354 | flags |= BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270); | |
14355 | ||
14356 | dev->mode_config.rotation_property = | |
14357 | drm_mode_create_rotation_property(dev, flags); | |
14358 | } | |
14359 | if (dev->mode_config.rotation_property) | |
14360 | drm_object_attach_property(&plane->base.base, | |
14361 | dev->mode_config.rotation_property, | |
14362 | plane->base.state->rotation); | |
14363 | } | |
14364 | ||
3d7d6510 | 14365 | static int |
852e787c | 14366 | intel_check_cursor_plane(struct drm_plane *plane, |
061e4b8d | 14367 | struct intel_crtc_state *crtc_state, |
852e787c | 14368 | struct intel_plane_state *state) |
3d7d6510 | 14369 | { |
061e4b8d | 14370 | struct drm_crtc *crtc = crtc_state->base.crtc; |
2b875c22 | 14371 | struct drm_framebuffer *fb = state->base.fb; |
757f9a3e | 14372 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
b29ec92c | 14373 | enum pipe pipe = to_intel_plane(plane)->pipe; |
757f9a3e GP |
14374 | unsigned stride; |
14375 | int ret; | |
3d7d6510 | 14376 | |
061e4b8d ML |
14377 | ret = drm_plane_helper_check_update(plane, crtc, fb, &state->src, |
14378 | &state->dst, &state->clip, | |
9b8b013d | 14379 | state->base.rotation, |
3d7d6510 MR |
14380 | DRM_PLANE_HELPER_NO_SCALING, |
14381 | DRM_PLANE_HELPER_NO_SCALING, | |
852e787c | 14382 | true, true, &state->visible); |
757f9a3e GP |
14383 | if (ret) |
14384 | return ret; | |
14385 | ||
757f9a3e GP |
14386 | /* if we want to turn off the cursor ignore width and height */ |
14387 | if (!obj) | |
da20eabd | 14388 | return 0; |
757f9a3e | 14389 | |
757f9a3e | 14390 | /* Check for which cursor types we support */ |
061e4b8d | 14391 | if (!cursor_size_ok(plane->dev, state->base.crtc_w, state->base.crtc_h)) { |
ea2c67bb MR |
14392 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
14393 | state->base.crtc_w, state->base.crtc_h); | |
757f9a3e GP |
14394 | return -EINVAL; |
14395 | } | |
14396 | ||
ea2c67bb MR |
14397 | stride = roundup_pow_of_two(state->base.crtc_w) * 4; |
14398 | if (obj->base.size < stride * state->base.crtc_h) { | |
757f9a3e GP |
14399 | DRM_DEBUG_KMS("buffer is too small\n"); |
14400 | return -ENOMEM; | |
14401 | } | |
14402 | ||
3a656b54 | 14403 | if (fb->modifier[0] != DRM_FORMAT_MOD_NONE) { |
757f9a3e | 14404 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
da20eabd | 14405 | return -EINVAL; |
32b7eeec MR |
14406 | } |
14407 | ||
b29ec92c VS |
14408 | /* |
14409 | * There's something wrong with the cursor on CHV pipe C. | |
14410 | * If it straddles the left edge of the screen then | |
14411 | * moving it away from the edge or disabling it often | |
14412 | * results in a pipe underrun, and often that can lead to | |
14413 | * dead pipe (constant underrun reported, and it scans | |
14414 | * out just a solid color). To recover from that, the | |
14415 | * display power well must be turned off and on again. | |
14416 | * Refuse the put the cursor into that compromised position. | |
14417 | */ | |
14418 | if (IS_CHERRYVIEW(plane->dev) && pipe == PIPE_C && | |
14419 | state->visible && state->base.crtc_x < 0) { | |
14420 | DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n"); | |
14421 | return -EINVAL; | |
14422 | } | |
14423 | ||
da20eabd | 14424 | return 0; |
852e787c | 14425 | } |
3d7d6510 | 14426 | |
a8ad0d8e ML |
14427 | static void |
14428 | intel_disable_cursor_plane(struct drm_plane *plane, | |
7fabf5ef | 14429 | struct drm_crtc *crtc) |
a8ad0d8e | 14430 | { |
f2858021 ML |
14431 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
14432 | ||
14433 | intel_crtc->cursor_addr = 0; | |
55a08b3f | 14434 | intel_crtc_update_cursor(crtc, NULL); |
a8ad0d8e ML |
14435 | } |
14436 | ||
f4a2cf29 | 14437 | static void |
55a08b3f ML |
14438 | intel_update_cursor_plane(struct drm_plane *plane, |
14439 | const struct intel_crtc_state *crtc_state, | |
14440 | const struct intel_plane_state *state) | |
852e787c | 14441 | { |
55a08b3f ML |
14442 | struct drm_crtc *crtc = crtc_state->base.crtc; |
14443 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
ea2c67bb | 14444 | struct drm_device *dev = plane->dev; |
2b875c22 | 14445 | struct drm_i915_gem_object *obj = intel_fb_obj(state->base.fb); |
a912f12f | 14446 | uint32_t addr; |
852e787c | 14447 | |
f4a2cf29 | 14448 | if (!obj) |
a912f12f | 14449 | addr = 0; |
f4a2cf29 | 14450 | else if (!INTEL_INFO(dev)->cursor_needs_physical) |
a912f12f | 14451 | addr = i915_gem_obj_ggtt_offset(obj); |
f4a2cf29 | 14452 | else |
a912f12f | 14453 | addr = obj->phys_handle->busaddr; |
852e787c | 14454 | |
a912f12f | 14455 | intel_crtc->cursor_addr = addr; |
55a08b3f | 14456 | intel_crtc_update_cursor(crtc, state); |
852e787c GP |
14457 | } |
14458 | ||
3d7d6510 MR |
14459 | static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev, |
14460 | int pipe) | |
14461 | { | |
fca0ce2a VS |
14462 | struct intel_plane *cursor = NULL; |
14463 | struct intel_plane_state *state = NULL; | |
14464 | int ret; | |
3d7d6510 MR |
14465 | |
14466 | cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); | |
fca0ce2a VS |
14467 | if (!cursor) |
14468 | goto fail; | |
3d7d6510 | 14469 | |
8e7d688b | 14470 | state = intel_create_plane_state(&cursor->base); |
fca0ce2a VS |
14471 | if (!state) |
14472 | goto fail; | |
8e7d688b | 14473 | cursor->base.state = &state->base; |
ea2c67bb | 14474 | |
3d7d6510 MR |
14475 | cursor->can_scale = false; |
14476 | cursor->max_downscale = 1; | |
14477 | cursor->pipe = pipe; | |
14478 | cursor->plane = pipe; | |
a9ff8714 | 14479 | cursor->frontbuffer_bit = INTEL_FRONTBUFFER_CURSOR(pipe); |
c59cb179 | 14480 | cursor->check_plane = intel_check_cursor_plane; |
55a08b3f | 14481 | cursor->update_plane = intel_update_cursor_plane; |
a8ad0d8e | 14482 | cursor->disable_plane = intel_disable_cursor_plane; |
3d7d6510 | 14483 | |
fca0ce2a VS |
14484 | ret = drm_universal_plane_init(dev, &cursor->base, 0, |
14485 | &intel_plane_funcs, | |
14486 | intel_cursor_formats, | |
14487 | ARRAY_SIZE(intel_cursor_formats), | |
38573dc1 VS |
14488 | DRM_PLANE_TYPE_CURSOR, |
14489 | "cursor %c", pipe_name(pipe)); | |
fca0ce2a VS |
14490 | if (ret) |
14491 | goto fail; | |
4398ad45 VS |
14492 | |
14493 | if (INTEL_INFO(dev)->gen >= 4) { | |
14494 | if (!dev->mode_config.rotation_property) | |
14495 | dev->mode_config.rotation_property = | |
14496 | drm_mode_create_rotation_property(dev, | |
14497 | BIT(DRM_ROTATE_0) | | |
14498 | BIT(DRM_ROTATE_180)); | |
14499 | if (dev->mode_config.rotation_property) | |
14500 | drm_object_attach_property(&cursor->base.base, | |
14501 | dev->mode_config.rotation_property, | |
8e7d688b | 14502 | state->base.rotation); |
4398ad45 VS |
14503 | } |
14504 | ||
af99ceda CK |
14505 | if (INTEL_INFO(dev)->gen >=9) |
14506 | state->scaler_id = -1; | |
14507 | ||
ea2c67bb MR |
14508 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
14509 | ||
3d7d6510 | 14510 | return &cursor->base; |
fca0ce2a VS |
14511 | |
14512 | fail: | |
14513 | kfree(state); | |
14514 | kfree(cursor); | |
14515 | ||
14516 | return NULL; | |
3d7d6510 MR |
14517 | } |
14518 | ||
549e2bfb CK |
14519 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
14520 | struct intel_crtc_state *crtc_state) | |
14521 | { | |
14522 | int i; | |
14523 | struct intel_scaler *intel_scaler; | |
14524 | struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state; | |
14525 | ||
14526 | for (i = 0; i < intel_crtc->num_scalers; i++) { | |
14527 | intel_scaler = &scaler_state->scalers[i]; | |
14528 | intel_scaler->in_use = 0; | |
549e2bfb CK |
14529 | intel_scaler->mode = PS_SCALER_MODE_DYN; |
14530 | } | |
14531 | ||
14532 | scaler_state->scaler_id = -1; | |
14533 | } | |
14534 | ||
b358d0a6 | 14535 | static void intel_crtc_init(struct drm_device *dev, int pipe) |
79e53945 | 14536 | { |
fbee40df | 14537 | struct drm_i915_private *dev_priv = dev->dev_private; |
79e53945 | 14538 | struct intel_crtc *intel_crtc; |
f5de6e07 | 14539 | struct intel_crtc_state *crtc_state = NULL; |
3d7d6510 MR |
14540 | struct drm_plane *primary = NULL; |
14541 | struct drm_plane *cursor = NULL; | |
8563b1e8 | 14542 | int ret; |
79e53945 | 14543 | |
955382f3 | 14544 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
79e53945 JB |
14545 | if (intel_crtc == NULL) |
14546 | return; | |
14547 | ||
f5de6e07 ACO |
14548 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
14549 | if (!crtc_state) | |
14550 | goto fail; | |
550acefd ACO |
14551 | intel_crtc->config = crtc_state; |
14552 | intel_crtc->base.state = &crtc_state->base; | |
07878248 | 14553 | crtc_state->base.crtc = &intel_crtc->base; |
f5de6e07 | 14554 | |
549e2bfb CK |
14555 | /* initialize shared scalers */ |
14556 | if (INTEL_INFO(dev)->gen >= 9) { | |
14557 | if (pipe == PIPE_C) | |
14558 | intel_crtc->num_scalers = 1; | |
14559 | else | |
14560 | intel_crtc->num_scalers = SKL_NUM_SCALERS; | |
14561 | ||
14562 | skl_init_scalers(dev, intel_crtc, crtc_state); | |
14563 | } | |
14564 | ||
465c120c | 14565 | primary = intel_primary_plane_create(dev, pipe); |
3d7d6510 MR |
14566 | if (!primary) |
14567 | goto fail; | |
14568 | ||
14569 | cursor = intel_cursor_plane_create(dev, pipe); | |
14570 | if (!cursor) | |
14571 | goto fail; | |
14572 | ||
465c120c | 14573 | ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary, |
4d5d72b7 VS |
14574 | cursor, &intel_crtc_funcs, |
14575 | "pipe %c", pipe_name(pipe)); | |
3d7d6510 MR |
14576 | if (ret) |
14577 | goto fail; | |
79e53945 | 14578 | |
1f1c2e24 VS |
14579 | /* |
14580 | * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port | |
8c0f92e1 | 14581 | * is hooked to pipe B. Hence we want plane A feeding pipe B. |
1f1c2e24 | 14582 | */ |
80824003 JB |
14583 | intel_crtc->pipe = pipe; |
14584 | intel_crtc->plane = pipe; | |
3a77c4c4 | 14585 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) { |
28c97730 | 14586 | DRM_DEBUG_KMS("swapping pipes & planes for FBC\n"); |
e2e767ab | 14587 | intel_crtc->plane = !pipe; |
80824003 JB |
14588 | } |
14589 | ||
4b0e333e CW |
14590 | intel_crtc->cursor_base = ~0; |
14591 | intel_crtc->cursor_cntl = ~0; | |
dc41c154 | 14592 | intel_crtc->cursor_size = ~0; |
8d7849db | 14593 | |
852eb00d VS |
14594 | intel_crtc->wm.cxsr_allowed = true; |
14595 | ||
22fd0fab JB |
14596 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
14597 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); | |
14598 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base; | |
14599 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base; | |
14600 | ||
79e53945 | 14601 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
87b6b101 | 14602 | |
8563b1e8 LL |
14603 | intel_color_init(&intel_crtc->base); |
14604 | ||
87b6b101 | 14605 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); |
3d7d6510 MR |
14606 | return; |
14607 | ||
14608 | fail: | |
69ae561f VS |
14609 | intel_plane_destroy(primary); |
14610 | intel_plane_destroy(cursor); | |
f5de6e07 | 14611 | kfree(crtc_state); |
3d7d6510 | 14612 | kfree(intel_crtc); |
79e53945 JB |
14613 | } |
14614 | ||
752aa88a JB |
14615 | enum pipe intel_get_pipe_from_connector(struct intel_connector *connector) |
14616 | { | |
14617 | struct drm_encoder *encoder = connector->base.encoder; | |
6e9f798d | 14618 | struct drm_device *dev = connector->base.dev; |
752aa88a | 14619 | |
51fd371b | 14620 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
752aa88a | 14621 | |
d3babd3f | 14622 | if (!encoder || WARN_ON(!encoder->crtc)) |
752aa88a JB |
14623 | return INVALID_PIPE; |
14624 | ||
14625 | return to_intel_crtc(encoder->crtc)->pipe; | |
14626 | } | |
14627 | ||
08d7b3d1 | 14628 | int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data, |
05394f39 | 14629 | struct drm_file *file) |
08d7b3d1 | 14630 | { |
08d7b3d1 | 14631 | struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data; |
7707e653 | 14632 | struct drm_crtc *drmmode_crtc; |
c05422d5 | 14633 | struct intel_crtc *crtc; |
08d7b3d1 | 14634 | |
7707e653 | 14635 | drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id); |
08d7b3d1 | 14636 | |
7707e653 | 14637 | if (!drmmode_crtc) { |
08d7b3d1 | 14638 | DRM_ERROR("no such CRTC id\n"); |
3f2c2057 | 14639 | return -ENOENT; |
08d7b3d1 CW |
14640 | } |
14641 | ||
7707e653 | 14642 | crtc = to_intel_crtc(drmmode_crtc); |
c05422d5 | 14643 | pipe_from_crtc_id->pipe = crtc->pipe; |
08d7b3d1 | 14644 | |
c05422d5 | 14645 | return 0; |
08d7b3d1 CW |
14646 | } |
14647 | ||
66a9278e | 14648 | static int intel_encoder_clones(struct intel_encoder *encoder) |
79e53945 | 14649 | { |
66a9278e DV |
14650 | struct drm_device *dev = encoder->base.dev; |
14651 | struct intel_encoder *source_encoder; | |
79e53945 | 14652 | int index_mask = 0; |
79e53945 JB |
14653 | int entry = 0; |
14654 | ||
b2784e15 | 14655 | for_each_intel_encoder(dev, source_encoder) { |
bc079e8b | 14656 | if (encoders_cloneable(encoder, source_encoder)) |
66a9278e DV |
14657 | index_mask |= (1 << entry); |
14658 | ||
79e53945 JB |
14659 | entry++; |
14660 | } | |
4ef69c7a | 14661 | |
79e53945 JB |
14662 | return index_mask; |
14663 | } | |
14664 | ||
4d302442 CW |
14665 | static bool has_edp_a(struct drm_device *dev) |
14666 | { | |
14667 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14668 | ||
14669 | if (!IS_MOBILE(dev)) | |
14670 | return false; | |
14671 | ||
14672 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) | |
14673 | return false; | |
14674 | ||
e3589908 | 14675 | if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE)) |
4d302442 CW |
14676 | return false; |
14677 | ||
14678 | return true; | |
14679 | } | |
14680 | ||
84b4e042 JB |
14681 | static bool intel_crt_present(struct drm_device *dev) |
14682 | { | |
14683 | struct drm_i915_private *dev_priv = dev->dev_private; | |
14684 | ||
884497ed DL |
14685 | if (INTEL_INFO(dev)->gen >= 9) |
14686 | return false; | |
14687 | ||
cf404ce4 | 14688 | if (IS_HSW_ULT(dev) || IS_BDW_ULT(dev)) |
84b4e042 JB |
14689 | return false; |
14690 | ||
14691 | if (IS_CHERRYVIEW(dev)) | |
14692 | return false; | |
14693 | ||
65e472e4 VS |
14694 | if (HAS_PCH_LPT_H(dev) && I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED) |
14695 | return false; | |
14696 | ||
70ac54d0 VS |
14697 | /* DDI E can't be used if DDI A requires 4 lanes */ |
14698 | if (HAS_DDI(dev) && I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) | |
14699 | return false; | |
14700 | ||
e4abb733 | 14701 | if (!dev_priv->vbt.int_crt_support) |
84b4e042 JB |
14702 | return false; |
14703 | ||
14704 | return true; | |
14705 | } | |
14706 | ||
79e53945 JB |
14707 | static void intel_setup_outputs(struct drm_device *dev) |
14708 | { | |
725e30ad | 14709 | struct drm_i915_private *dev_priv = dev->dev_private; |
4ef69c7a | 14710 | struct intel_encoder *encoder; |
cb0953d7 | 14711 | bool dpd_is_edp = false; |
79e53945 | 14712 | |
97a824e1 ID |
14713 | /* |
14714 | * intel_edp_init_connector() depends on this completing first, to | |
14715 | * prevent the registeration of both eDP and LVDS and the incorrect | |
14716 | * sharing of the PPS. | |
14717 | */ | |
c9093354 | 14718 | intel_lvds_init(dev); |
79e53945 | 14719 | |
84b4e042 | 14720 | if (intel_crt_present(dev)) |
79935fca | 14721 | intel_crt_init(dev); |
cb0953d7 | 14722 | |
c776eb2e VK |
14723 | if (IS_BROXTON(dev)) { |
14724 | /* | |
14725 | * FIXME: Broxton doesn't support port detection via the | |
14726 | * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to | |
14727 | * detect the ports. | |
14728 | */ | |
14729 | intel_ddi_init(dev, PORT_A); | |
14730 | intel_ddi_init(dev, PORT_B); | |
14731 | intel_ddi_init(dev, PORT_C); | |
c6c794a2 SS |
14732 | |
14733 | intel_dsi_init(dev); | |
c776eb2e | 14734 | } else if (HAS_DDI(dev)) { |
0e72a5b5 ED |
14735 | int found; |
14736 | ||
de31facd JB |
14737 | /* |
14738 | * Haswell uses DDI functions to detect digital outputs. | |
14739 | * On SKL pre-D0 the strap isn't connected, so we assume | |
14740 | * it's there. | |
14741 | */ | |
77179400 | 14742 | found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED; |
de31facd | 14743 | /* WaIgnoreDDIAStrap: skl */ |
ef11bdb3 | 14744 | if (found || IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
0e72a5b5 ED |
14745 | intel_ddi_init(dev, PORT_A); |
14746 | ||
14747 | /* DDI B, C and D detection is indicated by the SFUSE_STRAP | |
14748 | * register */ | |
14749 | found = I915_READ(SFUSE_STRAP); | |
14750 | ||
14751 | if (found & SFUSE_STRAP_DDIB_DETECTED) | |
14752 | intel_ddi_init(dev, PORT_B); | |
14753 | if (found & SFUSE_STRAP_DDIC_DETECTED) | |
14754 | intel_ddi_init(dev, PORT_C); | |
14755 | if (found & SFUSE_STRAP_DDID_DETECTED) | |
14756 | intel_ddi_init(dev, PORT_D); | |
2800e4c2 RV |
14757 | /* |
14758 | * On SKL we don't have a way to detect DDI-E so we rely on VBT. | |
14759 | */ | |
ef11bdb3 | 14760 | if ((IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) && |
2800e4c2 RV |
14761 | (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp || |
14762 | dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi || | |
14763 | dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi)) | |
14764 | intel_ddi_init(dev, PORT_E); | |
14765 | ||
0e72a5b5 | 14766 | } else if (HAS_PCH_SPLIT(dev)) { |
cb0953d7 | 14767 | int found; |
5d8a7752 | 14768 | dpd_is_edp = intel_dp_is_edp(dev, PORT_D); |
270b3042 DV |
14769 | |
14770 | if (has_edp_a(dev)) | |
14771 | intel_dp_init(dev, DP_A, PORT_A); | |
cb0953d7 | 14772 | |
dc0fa718 | 14773 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
461ed3ca | 14774 | /* PCH SDVOB multiplex with HDMIB */ |
2a5c0832 | 14775 | found = intel_sdvo_init(dev, PCH_SDVOB, PORT_B); |
30ad48b7 | 14776 | if (!found) |
e2debe91 | 14777 | intel_hdmi_init(dev, PCH_HDMIB, PORT_B); |
5eb08b69 | 14778 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
ab9d7c30 | 14779 | intel_dp_init(dev, PCH_DP_B, PORT_B); |
30ad48b7 ZW |
14780 | } |
14781 | ||
dc0fa718 | 14782 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
e2debe91 | 14783 | intel_hdmi_init(dev, PCH_HDMIC, PORT_C); |
30ad48b7 | 14784 | |
dc0fa718 | 14785 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
e2debe91 | 14786 | intel_hdmi_init(dev, PCH_HDMID, PORT_D); |
30ad48b7 | 14787 | |
5eb08b69 | 14788 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
ab9d7c30 | 14789 | intel_dp_init(dev, PCH_DP_C, PORT_C); |
5eb08b69 | 14790 | |
270b3042 | 14791 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
ab9d7c30 | 14792 | intel_dp_init(dev, PCH_DP_D, PORT_D); |
666a4537 | 14793 | } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
22f35042 | 14794 | bool has_edp, has_port; |
457c52d8 | 14795 | |
e17ac6db VS |
14796 | /* |
14797 | * The DP_DETECTED bit is the latched state of the DDC | |
14798 | * SDA pin at boot. However since eDP doesn't require DDC | |
14799 | * (no way to plug in a DP->HDMI dongle) the DDC pins for | |
14800 | * eDP ports may have been muxed to an alternate function. | |
14801 | * Thus we can't rely on the DP_DETECTED bit alone to detect | |
14802 | * eDP ports. Consult the VBT as well as DP_DETECTED to | |
14803 | * detect eDP ports. | |
22f35042 VS |
14804 | * |
14805 | * Sadly the straps seem to be missing sometimes even for HDMI | |
14806 | * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap | |
14807 | * and VBT for the presence of the port. Additionally we can't | |
14808 | * trust the port type the VBT declares as we've seen at least | |
14809 | * HDMI ports that the VBT claim are DP or eDP. | |
e17ac6db | 14810 | */ |
457c52d8 | 14811 | has_edp = intel_dp_is_edp(dev, PORT_B); |
22f35042 VS |
14812 | has_port = intel_bios_is_port_present(dev_priv, PORT_B); |
14813 | if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port) | |
457c52d8 | 14814 | has_edp &= intel_dp_init(dev, VLV_DP_B, PORT_B); |
22f35042 | 14815 | if ((I915_READ(VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp) |
e66eb81d | 14816 | intel_hdmi_init(dev, VLV_HDMIB, PORT_B); |
585a94b8 | 14817 | |
457c52d8 | 14818 | has_edp = intel_dp_is_edp(dev, PORT_C); |
22f35042 VS |
14819 | has_port = intel_bios_is_port_present(dev_priv, PORT_C); |
14820 | if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port) | |
457c52d8 | 14821 | has_edp &= intel_dp_init(dev, VLV_DP_C, PORT_C); |
22f35042 | 14822 | if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp) |
e66eb81d | 14823 | intel_hdmi_init(dev, VLV_HDMIC, PORT_C); |
19c03924 | 14824 | |
9418c1f1 | 14825 | if (IS_CHERRYVIEW(dev)) { |
22f35042 VS |
14826 | /* |
14827 | * eDP not supported on port D, | |
14828 | * so no need to worry about it | |
14829 | */ | |
14830 | has_port = intel_bios_is_port_present(dev_priv, PORT_D); | |
14831 | if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port) | |
e66eb81d | 14832 | intel_dp_init(dev, CHV_DP_D, PORT_D); |
22f35042 VS |
14833 | if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port) |
14834 | intel_hdmi_init(dev, CHV_HDMID, PORT_D); | |
9418c1f1 VS |
14835 | } |
14836 | ||
3cfca973 | 14837 | intel_dsi_init(dev); |
09da55dc | 14838 | } else if (!IS_GEN2(dev) && !IS_PINEVIEW(dev)) { |
27185ae1 | 14839 | bool found = false; |
7d57382e | 14840 | |
e2debe91 | 14841 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
b01f2c3a | 14842 | DRM_DEBUG_KMS("probing SDVOB\n"); |
2a5c0832 | 14843 | found = intel_sdvo_init(dev, GEN3_SDVOB, PORT_B); |
3fec3d2f | 14844 | if (!found && IS_G4X(dev)) { |
b01f2c3a | 14845 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
e2debe91 | 14846 | intel_hdmi_init(dev, GEN4_HDMIB, PORT_B); |
b01f2c3a | 14847 | } |
27185ae1 | 14848 | |
3fec3d2f | 14849 | if (!found && IS_G4X(dev)) |
ab9d7c30 | 14850 | intel_dp_init(dev, DP_B, PORT_B); |
725e30ad | 14851 | } |
13520b05 KH |
14852 | |
14853 | /* Before G4X SDVOC doesn't have its own detect register */ | |
13520b05 | 14854 | |
e2debe91 | 14855 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
b01f2c3a | 14856 | DRM_DEBUG_KMS("probing SDVOC\n"); |
2a5c0832 | 14857 | found = intel_sdvo_init(dev, GEN3_SDVOC, PORT_C); |
b01f2c3a | 14858 | } |
27185ae1 | 14859 | |
e2debe91 | 14860 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
27185ae1 | 14861 | |
3fec3d2f | 14862 | if (IS_G4X(dev)) { |
b01f2c3a | 14863 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
e2debe91 | 14864 | intel_hdmi_init(dev, GEN4_HDMIC, PORT_C); |
b01f2c3a | 14865 | } |
3fec3d2f | 14866 | if (IS_G4X(dev)) |
ab9d7c30 | 14867 | intel_dp_init(dev, DP_C, PORT_C); |
725e30ad | 14868 | } |
27185ae1 | 14869 | |
3fec3d2f | 14870 | if (IS_G4X(dev) && |
e7281eab | 14871 | (I915_READ(DP_D) & DP_DETECTED)) |
ab9d7c30 | 14872 | intel_dp_init(dev, DP_D, PORT_D); |
bad720ff | 14873 | } else if (IS_GEN2(dev)) |
79e53945 JB |
14874 | intel_dvo_init(dev); |
14875 | ||
103a196f | 14876 | if (SUPPORTS_TV(dev)) |
79e53945 JB |
14877 | intel_tv_init(dev); |
14878 | ||
0bc12bcb | 14879 | intel_psr_init(dev); |
7c8f8a70 | 14880 | |
b2784e15 | 14881 | for_each_intel_encoder(dev, encoder) { |
4ef69c7a CW |
14882 | encoder->base.possible_crtcs = encoder->crtc_mask; |
14883 | encoder->base.possible_clones = | |
66a9278e | 14884 | intel_encoder_clones(encoder); |
79e53945 | 14885 | } |
47356eb6 | 14886 | |
dde86e2d | 14887 | intel_init_pch_refclk(dev); |
270b3042 DV |
14888 | |
14889 | drm_helper_move_panel_connectors_to_head(dev); | |
79e53945 JB |
14890 | } |
14891 | ||
14892 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) | |
14893 | { | |
60a5ca01 | 14894 | struct drm_device *dev = fb->dev; |
79e53945 | 14895 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
79e53945 | 14896 | |
ef2d633e | 14897 | drm_framebuffer_cleanup(fb); |
60a5ca01 | 14898 | mutex_lock(&dev->struct_mutex); |
ef2d633e | 14899 | WARN_ON(!intel_fb->obj->framebuffer_references--); |
60a5ca01 VS |
14900 | drm_gem_object_unreference(&intel_fb->obj->base); |
14901 | mutex_unlock(&dev->struct_mutex); | |
79e53945 JB |
14902 | kfree(intel_fb); |
14903 | } | |
14904 | ||
14905 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, | |
05394f39 | 14906 | struct drm_file *file, |
79e53945 JB |
14907 | unsigned int *handle) |
14908 | { | |
14909 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | |
05394f39 | 14910 | struct drm_i915_gem_object *obj = intel_fb->obj; |
79e53945 | 14911 | |
cc917ab4 CW |
14912 | if (obj->userptr.mm) { |
14913 | DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n"); | |
14914 | return -EINVAL; | |
14915 | } | |
14916 | ||
05394f39 | 14917 | return drm_gem_handle_create(file, &obj->base, handle); |
79e53945 JB |
14918 | } |
14919 | ||
86c98588 RV |
14920 | static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb, |
14921 | struct drm_file *file, | |
14922 | unsigned flags, unsigned color, | |
14923 | struct drm_clip_rect *clips, | |
14924 | unsigned num_clips) | |
14925 | { | |
14926 | struct drm_device *dev = fb->dev; | |
14927 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | |
14928 | struct drm_i915_gem_object *obj = intel_fb->obj; | |
14929 | ||
14930 | mutex_lock(&dev->struct_mutex); | |
74b4ea1e | 14931 | intel_fb_obj_flush(obj, false, ORIGIN_DIRTYFB); |
86c98588 RV |
14932 | mutex_unlock(&dev->struct_mutex); |
14933 | ||
14934 | return 0; | |
14935 | } | |
14936 | ||
79e53945 JB |
14937 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
14938 | .destroy = intel_user_framebuffer_destroy, | |
14939 | .create_handle = intel_user_framebuffer_create_handle, | |
86c98588 | 14940 | .dirty = intel_user_framebuffer_dirty, |
79e53945 JB |
14941 | }; |
14942 | ||
b321803d DL |
14943 | static |
14944 | u32 intel_fb_pitch_limit(struct drm_device *dev, uint64_t fb_modifier, | |
14945 | uint32_t pixel_format) | |
14946 | { | |
14947 | u32 gen = INTEL_INFO(dev)->gen; | |
14948 | ||
14949 | if (gen >= 9) { | |
ac484963 VS |
14950 | int cpp = drm_format_plane_cpp(pixel_format, 0); |
14951 | ||
b321803d DL |
14952 | /* "The stride in bytes must not exceed the of the size of 8K |
14953 | * pixels and 32K bytes." | |
14954 | */ | |
ac484963 | 14955 | return min(8192 * cpp, 32768); |
666a4537 | 14956 | } else if (gen >= 5 && !IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) { |
b321803d DL |
14957 | return 32*1024; |
14958 | } else if (gen >= 4) { | |
14959 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) | |
14960 | return 16*1024; | |
14961 | else | |
14962 | return 32*1024; | |
14963 | } else if (gen >= 3) { | |
14964 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) | |
14965 | return 8*1024; | |
14966 | else | |
14967 | return 16*1024; | |
14968 | } else { | |
14969 | /* XXX DSPC is limited to 4k tiled */ | |
14970 | return 8*1024; | |
14971 | } | |
14972 | } | |
14973 | ||
b5ea642a DV |
14974 | static int intel_framebuffer_init(struct drm_device *dev, |
14975 | struct intel_framebuffer *intel_fb, | |
14976 | struct drm_mode_fb_cmd2 *mode_cmd, | |
14977 | struct drm_i915_gem_object *obj) | |
79e53945 | 14978 | { |
7b49f948 | 14979 | struct drm_i915_private *dev_priv = to_i915(dev); |
6761dd31 | 14980 | unsigned int aligned_height; |
79e53945 | 14981 | int ret; |
b321803d | 14982 | u32 pitch_limit, stride_alignment; |
79e53945 | 14983 | |
dd4916c5 DV |
14984 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
14985 | ||
2a80eada DV |
14986 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
14987 | /* Enforce that fb modifier and tiling mode match, but only for | |
14988 | * X-tiled. This is needed for FBC. */ | |
14989 | if (!!(obj->tiling_mode == I915_TILING_X) != | |
14990 | !!(mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED)) { | |
14991 | DRM_DEBUG("tiling_mode doesn't match fb modifier\n"); | |
14992 | return -EINVAL; | |
14993 | } | |
14994 | } else { | |
14995 | if (obj->tiling_mode == I915_TILING_X) | |
14996 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; | |
14997 | else if (obj->tiling_mode == I915_TILING_Y) { | |
14998 | DRM_DEBUG("No Y tiling for legacy addfb\n"); | |
14999 | return -EINVAL; | |
15000 | } | |
15001 | } | |
15002 | ||
9a8f0a12 TU |
15003 | /* Passed in modifier sanity checking. */ |
15004 | switch (mode_cmd->modifier[0]) { | |
15005 | case I915_FORMAT_MOD_Y_TILED: | |
15006 | case I915_FORMAT_MOD_Yf_TILED: | |
15007 | if (INTEL_INFO(dev)->gen < 9) { | |
15008 | DRM_DEBUG("Unsupported tiling 0x%llx!\n", | |
15009 | mode_cmd->modifier[0]); | |
15010 | return -EINVAL; | |
15011 | } | |
15012 | case DRM_FORMAT_MOD_NONE: | |
15013 | case I915_FORMAT_MOD_X_TILED: | |
15014 | break; | |
15015 | default: | |
c0f40428 JB |
15016 | DRM_DEBUG("Unsupported fb modifier 0x%llx!\n", |
15017 | mode_cmd->modifier[0]); | |
57cd6508 | 15018 | return -EINVAL; |
c16ed4be | 15019 | } |
57cd6508 | 15020 | |
7b49f948 VS |
15021 | stride_alignment = intel_fb_stride_alignment(dev_priv, |
15022 | mode_cmd->modifier[0], | |
b321803d DL |
15023 | mode_cmd->pixel_format); |
15024 | if (mode_cmd->pitches[0] & (stride_alignment - 1)) { | |
15025 | DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n", | |
15026 | mode_cmd->pitches[0], stride_alignment); | |
57cd6508 | 15027 | return -EINVAL; |
c16ed4be | 15028 | } |
57cd6508 | 15029 | |
b321803d DL |
15030 | pitch_limit = intel_fb_pitch_limit(dev, mode_cmd->modifier[0], |
15031 | mode_cmd->pixel_format); | |
a35cdaa0 | 15032 | if (mode_cmd->pitches[0] > pitch_limit) { |
b321803d DL |
15033 | DRM_DEBUG("%s pitch (%u) must be at less than %d\n", |
15034 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_NONE ? | |
2a80eada | 15035 | "tiled" : "linear", |
a35cdaa0 | 15036 | mode_cmd->pitches[0], pitch_limit); |
5d7bd705 | 15037 | return -EINVAL; |
c16ed4be | 15038 | } |
5d7bd705 | 15039 | |
2a80eada | 15040 | if (mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED && |
c16ed4be CW |
15041 | mode_cmd->pitches[0] != obj->stride) { |
15042 | DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n", | |
15043 | mode_cmd->pitches[0], obj->stride); | |
5d7bd705 | 15044 | return -EINVAL; |
c16ed4be | 15045 | } |
5d7bd705 | 15046 | |
57779d06 | 15047 | /* Reject formats not supported by any plane early. */ |
308e5bcb | 15048 | switch (mode_cmd->pixel_format) { |
57779d06 | 15049 | case DRM_FORMAT_C8: |
04b3924d VS |
15050 | case DRM_FORMAT_RGB565: |
15051 | case DRM_FORMAT_XRGB8888: | |
15052 | case DRM_FORMAT_ARGB8888: | |
57779d06 VS |
15053 | break; |
15054 | case DRM_FORMAT_XRGB1555: | |
c16ed4be | 15055 | if (INTEL_INFO(dev)->gen > 3) { |
4ee62c76 VS |
15056 | DRM_DEBUG("unsupported pixel format: %s\n", |
15057 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 15058 | return -EINVAL; |
c16ed4be | 15059 | } |
57779d06 | 15060 | break; |
57779d06 | 15061 | case DRM_FORMAT_ABGR8888: |
666a4537 WB |
15062 | if (!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev) && |
15063 | INTEL_INFO(dev)->gen < 9) { | |
6c0fd451 DL |
15064 | DRM_DEBUG("unsupported pixel format: %s\n", |
15065 | drm_get_format_name(mode_cmd->pixel_format)); | |
15066 | return -EINVAL; | |
15067 | } | |
15068 | break; | |
15069 | case DRM_FORMAT_XBGR8888: | |
04b3924d | 15070 | case DRM_FORMAT_XRGB2101010: |
57779d06 | 15071 | case DRM_FORMAT_XBGR2101010: |
c16ed4be | 15072 | if (INTEL_INFO(dev)->gen < 4) { |
4ee62c76 VS |
15073 | DRM_DEBUG("unsupported pixel format: %s\n", |
15074 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 15075 | return -EINVAL; |
c16ed4be | 15076 | } |
b5626747 | 15077 | break; |
7531208b | 15078 | case DRM_FORMAT_ABGR2101010: |
666a4537 | 15079 | if (!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) { |
7531208b DL |
15080 | DRM_DEBUG("unsupported pixel format: %s\n", |
15081 | drm_get_format_name(mode_cmd->pixel_format)); | |
15082 | return -EINVAL; | |
15083 | } | |
15084 | break; | |
04b3924d VS |
15085 | case DRM_FORMAT_YUYV: |
15086 | case DRM_FORMAT_UYVY: | |
15087 | case DRM_FORMAT_YVYU: | |
15088 | case DRM_FORMAT_VYUY: | |
c16ed4be | 15089 | if (INTEL_INFO(dev)->gen < 5) { |
4ee62c76 VS |
15090 | DRM_DEBUG("unsupported pixel format: %s\n", |
15091 | drm_get_format_name(mode_cmd->pixel_format)); | |
57779d06 | 15092 | return -EINVAL; |
c16ed4be | 15093 | } |
57cd6508 CW |
15094 | break; |
15095 | default: | |
4ee62c76 VS |
15096 | DRM_DEBUG("unsupported pixel format: %s\n", |
15097 | drm_get_format_name(mode_cmd->pixel_format)); | |
57cd6508 CW |
15098 | return -EINVAL; |
15099 | } | |
15100 | ||
90f9a336 VS |
15101 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
15102 | if (mode_cmd->offsets[0] != 0) | |
15103 | return -EINVAL; | |
15104 | ||
ec2c981e | 15105 | aligned_height = intel_fb_align_height(dev, mode_cmd->height, |
091df6cb DV |
15106 | mode_cmd->pixel_format, |
15107 | mode_cmd->modifier[0]); | |
53155c0a DV |
15108 | /* FIXME drm helper for size checks (especially planar formats)? */ |
15109 | if (obj->base.size < aligned_height * mode_cmd->pitches[0]) | |
15110 | return -EINVAL; | |
15111 | ||
c7d73f6a DV |
15112 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); |
15113 | intel_fb->obj = obj; | |
15114 | ||
2d7a215f VS |
15115 | intel_fill_fb_info(dev_priv, &intel_fb->base); |
15116 | ||
79e53945 JB |
15117 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); |
15118 | if (ret) { | |
15119 | DRM_ERROR("framebuffer init failed %d\n", ret); | |
15120 | return ret; | |
15121 | } | |
15122 | ||
0b05e1e0 VS |
15123 | intel_fb->obj->framebuffer_references++; |
15124 | ||
79e53945 JB |
15125 | return 0; |
15126 | } | |
15127 | ||
79e53945 JB |
15128 | static struct drm_framebuffer * |
15129 | intel_user_framebuffer_create(struct drm_device *dev, | |
15130 | struct drm_file *filp, | |
1eb83451 | 15131 | const struct drm_mode_fb_cmd2 *user_mode_cmd) |
79e53945 | 15132 | { |
dcb1394e | 15133 | struct drm_framebuffer *fb; |
05394f39 | 15134 | struct drm_i915_gem_object *obj; |
76dc3769 | 15135 | struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd; |
79e53945 | 15136 | |
a8ad0bd8 | 15137 | obj = to_intel_bo(drm_gem_object_lookup(filp, mode_cmd.handles[0])); |
c8725226 | 15138 | if (&obj->base == NULL) |
cce13ff7 | 15139 | return ERR_PTR(-ENOENT); |
79e53945 | 15140 | |
92907cbb | 15141 | fb = intel_framebuffer_create(dev, &mode_cmd, obj); |
dcb1394e LW |
15142 | if (IS_ERR(fb)) |
15143 | drm_gem_object_unreference_unlocked(&obj->base); | |
15144 | ||
15145 | return fb; | |
79e53945 JB |
15146 | } |
15147 | ||
0695726e | 15148 | #ifndef CONFIG_DRM_FBDEV_EMULATION |
0632fef6 | 15149 | static inline void intel_fbdev_output_poll_changed(struct drm_device *dev) |
4520f53a DV |
15150 | { |
15151 | } | |
15152 | #endif | |
15153 | ||
79e53945 | 15154 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
79e53945 | 15155 | .fb_create = intel_user_framebuffer_create, |
0632fef6 | 15156 | .output_poll_changed = intel_fbdev_output_poll_changed, |
5ee67f1c MR |
15157 | .atomic_check = intel_atomic_check, |
15158 | .atomic_commit = intel_atomic_commit, | |
de419ab6 ML |
15159 | .atomic_state_alloc = intel_atomic_state_alloc, |
15160 | .atomic_state_clear = intel_atomic_state_clear, | |
79e53945 JB |
15161 | }; |
15162 | ||
88212941 ID |
15163 | /** |
15164 | * intel_init_display_hooks - initialize the display modesetting hooks | |
15165 | * @dev_priv: device private | |
15166 | */ | |
15167 | void intel_init_display_hooks(struct drm_i915_private *dev_priv) | |
e70236a8 | 15168 | { |
88212941 | 15169 | if (INTEL_INFO(dev_priv)->gen >= 9) { |
bc8d7dff | 15170 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
5724dbd1 DL |
15171 | dev_priv->display.get_initial_plane_config = |
15172 | skylake_get_initial_plane_config; | |
bc8d7dff DL |
15173 | dev_priv->display.crtc_compute_clock = |
15174 | haswell_crtc_compute_clock; | |
15175 | dev_priv->display.crtc_enable = haswell_crtc_enable; | |
15176 | dev_priv->display.crtc_disable = haswell_crtc_disable; | |
88212941 | 15177 | } else if (HAS_DDI(dev_priv)) { |
0e8ffe1b | 15178 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
5724dbd1 DL |
15179 | dev_priv->display.get_initial_plane_config = |
15180 | ironlake_get_initial_plane_config; | |
797d0259 ACO |
15181 | dev_priv->display.crtc_compute_clock = |
15182 | haswell_crtc_compute_clock; | |
4f771f10 PZ |
15183 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
15184 | dev_priv->display.crtc_disable = haswell_crtc_disable; | |
88212941 | 15185 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
0e8ffe1b | 15186 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
5724dbd1 DL |
15187 | dev_priv->display.get_initial_plane_config = |
15188 | ironlake_get_initial_plane_config; | |
3fb37703 ACO |
15189 | dev_priv->display.crtc_compute_clock = |
15190 | ironlake_crtc_compute_clock; | |
76e5a89c DV |
15191 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
15192 | dev_priv->display.crtc_disable = ironlake_crtc_disable; | |
65b3d6a9 | 15193 | } else if (IS_CHERRYVIEW(dev_priv)) { |
89b667f8 | 15194 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
5724dbd1 DL |
15195 | dev_priv->display.get_initial_plane_config = |
15196 | i9xx_get_initial_plane_config; | |
65b3d6a9 ACO |
15197 | dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock; |
15198 | dev_priv->display.crtc_enable = valleyview_crtc_enable; | |
15199 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
15200 | } else if (IS_VALLEYVIEW(dev_priv)) { | |
15201 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; | |
15202 | dev_priv->display.get_initial_plane_config = | |
15203 | i9xx_get_initial_plane_config; | |
15204 | dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock; | |
89b667f8 JB |
15205 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
15206 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
19ec6693 ACO |
15207 | } else if (IS_G4X(dev_priv)) { |
15208 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; | |
15209 | dev_priv->display.get_initial_plane_config = | |
15210 | i9xx_get_initial_plane_config; | |
15211 | dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock; | |
15212 | dev_priv->display.crtc_enable = i9xx_crtc_enable; | |
15213 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
70e8aa21 ACO |
15214 | } else if (IS_PINEVIEW(dev_priv)) { |
15215 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; | |
15216 | dev_priv->display.get_initial_plane_config = | |
15217 | i9xx_get_initial_plane_config; | |
15218 | dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock; | |
15219 | dev_priv->display.crtc_enable = i9xx_crtc_enable; | |
15220 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
81c97f52 | 15221 | } else if (!IS_GEN2(dev_priv)) { |
0e8ffe1b | 15222 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
5724dbd1 DL |
15223 | dev_priv->display.get_initial_plane_config = |
15224 | i9xx_get_initial_plane_config; | |
d6dfee7a | 15225 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
76e5a89c DV |
15226 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
15227 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
81c97f52 ACO |
15228 | } else { |
15229 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; | |
15230 | dev_priv->display.get_initial_plane_config = | |
15231 | i9xx_get_initial_plane_config; | |
15232 | dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock; | |
15233 | dev_priv->display.crtc_enable = i9xx_crtc_enable; | |
15234 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
f564048e | 15235 | } |
e70236a8 | 15236 | |
e70236a8 | 15237 | /* Returns the core display clock speed */ |
88212941 | 15238 | if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) |
1652d19e VS |
15239 | dev_priv->display.get_display_clock_speed = |
15240 | skylake_get_display_clock_speed; | |
88212941 | 15241 | else if (IS_BROXTON(dev_priv)) |
acd3f3d3 BP |
15242 | dev_priv->display.get_display_clock_speed = |
15243 | broxton_get_display_clock_speed; | |
88212941 | 15244 | else if (IS_BROADWELL(dev_priv)) |
1652d19e VS |
15245 | dev_priv->display.get_display_clock_speed = |
15246 | broadwell_get_display_clock_speed; | |
88212941 | 15247 | else if (IS_HASWELL(dev_priv)) |
1652d19e VS |
15248 | dev_priv->display.get_display_clock_speed = |
15249 | haswell_get_display_clock_speed; | |
88212941 | 15250 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
25eb05fc JB |
15251 | dev_priv->display.get_display_clock_speed = |
15252 | valleyview_get_display_clock_speed; | |
88212941 | 15253 | else if (IS_GEN5(dev_priv)) |
b37a6434 VS |
15254 | dev_priv->display.get_display_clock_speed = |
15255 | ilk_get_display_clock_speed; | |
88212941 ID |
15256 | else if (IS_I945G(dev_priv) || IS_BROADWATER(dev_priv) || |
15257 | IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv)) | |
e70236a8 JB |
15258 | dev_priv->display.get_display_clock_speed = |
15259 | i945_get_display_clock_speed; | |
88212941 | 15260 | else if (IS_GM45(dev_priv)) |
34edce2f VS |
15261 | dev_priv->display.get_display_clock_speed = |
15262 | gm45_get_display_clock_speed; | |
88212941 | 15263 | else if (IS_CRESTLINE(dev_priv)) |
34edce2f VS |
15264 | dev_priv->display.get_display_clock_speed = |
15265 | i965gm_get_display_clock_speed; | |
88212941 | 15266 | else if (IS_PINEVIEW(dev_priv)) |
34edce2f VS |
15267 | dev_priv->display.get_display_clock_speed = |
15268 | pnv_get_display_clock_speed; | |
88212941 | 15269 | else if (IS_G33(dev_priv) || IS_G4X(dev_priv)) |
34edce2f VS |
15270 | dev_priv->display.get_display_clock_speed = |
15271 | g33_get_display_clock_speed; | |
88212941 | 15272 | else if (IS_I915G(dev_priv)) |
e70236a8 JB |
15273 | dev_priv->display.get_display_clock_speed = |
15274 | i915_get_display_clock_speed; | |
88212941 | 15275 | else if (IS_I945GM(dev_priv) || IS_845G(dev_priv)) |
e70236a8 JB |
15276 | dev_priv->display.get_display_clock_speed = |
15277 | i9xx_misc_get_display_clock_speed; | |
88212941 | 15278 | else if (IS_I915GM(dev_priv)) |
e70236a8 JB |
15279 | dev_priv->display.get_display_clock_speed = |
15280 | i915gm_get_display_clock_speed; | |
88212941 | 15281 | else if (IS_I865G(dev_priv)) |
e70236a8 JB |
15282 | dev_priv->display.get_display_clock_speed = |
15283 | i865_get_display_clock_speed; | |
88212941 | 15284 | else if (IS_I85X(dev_priv)) |
e70236a8 | 15285 | dev_priv->display.get_display_clock_speed = |
1b1d2716 | 15286 | i85x_get_display_clock_speed; |
623e01e5 | 15287 | else { /* 830 */ |
88212941 | 15288 | WARN(!IS_I830(dev_priv), "Unknown platform. Assuming 133 MHz CDCLK\n"); |
e70236a8 JB |
15289 | dev_priv->display.get_display_clock_speed = |
15290 | i830_get_display_clock_speed; | |
623e01e5 | 15291 | } |
e70236a8 | 15292 | |
88212941 | 15293 | if (IS_GEN5(dev_priv)) { |
3bb11b53 | 15294 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
88212941 | 15295 | } else if (IS_GEN6(dev_priv)) { |
3bb11b53 | 15296 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; |
88212941 | 15297 | } else if (IS_IVYBRIDGE(dev_priv)) { |
3bb11b53 SJ |
15298 | /* FIXME: detect B0+ stepping and use auto training */ |
15299 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; | |
88212941 | 15300 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
3bb11b53 | 15301 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
445e780b VS |
15302 | } |
15303 | ||
15304 | if (IS_BROADWELL(dev_priv)) { | |
15305 | dev_priv->display.modeset_commit_cdclk = | |
15306 | broadwell_modeset_commit_cdclk; | |
15307 | dev_priv->display.modeset_calc_cdclk = | |
15308 | broadwell_modeset_calc_cdclk; | |
88212941 | 15309 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
27c329ed ML |
15310 | dev_priv->display.modeset_commit_cdclk = |
15311 | valleyview_modeset_commit_cdclk; | |
15312 | dev_priv->display.modeset_calc_cdclk = | |
15313 | valleyview_modeset_calc_cdclk; | |
88212941 | 15314 | } else if (IS_BROXTON(dev_priv)) { |
27c329ed | 15315 | dev_priv->display.modeset_commit_cdclk = |
324513c0 | 15316 | bxt_modeset_commit_cdclk; |
27c329ed | 15317 | dev_priv->display.modeset_calc_cdclk = |
324513c0 | 15318 | bxt_modeset_calc_cdclk; |
c89e39f3 CT |
15319 | } else if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) { |
15320 | dev_priv->display.modeset_commit_cdclk = | |
15321 | skl_modeset_commit_cdclk; | |
15322 | dev_priv->display.modeset_calc_cdclk = | |
15323 | skl_modeset_calc_cdclk; | |
e70236a8 | 15324 | } |
5a21b665 DV |
15325 | |
15326 | switch (INTEL_INFO(dev_priv)->gen) { | |
15327 | case 2: | |
15328 | dev_priv->display.queue_flip = intel_gen2_queue_flip; | |
15329 | break; | |
15330 | ||
15331 | case 3: | |
15332 | dev_priv->display.queue_flip = intel_gen3_queue_flip; | |
15333 | break; | |
15334 | ||
15335 | case 4: | |
15336 | case 5: | |
15337 | dev_priv->display.queue_flip = intel_gen4_queue_flip; | |
15338 | break; | |
15339 | ||
15340 | case 6: | |
15341 | dev_priv->display.queue_flip = intel_gen6_queue_flip; | |
15342 | break; | |
15343 | case 7: | |
15344 | case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */ | |
15345 | dev_priv->display.queue_flip = intel_gen7_queue_flip; | |
15346 | break; | |
15347 | case 9: | |
15348 | /* Drop through - unsupported since execlist only. */ | |
15349 | default: | |
15350 | /* Default just returns -ENODEV to indicate unsupported */ | |
15351 | dev_priv->display.queue_flip = intel_default_queue_flip; | |
15352 | } | |
e70236a8 JB |
15353 | } |
15354 | ||
b690e96c JB |
15355 | /* |
15356 | * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend, | |
15357 | * resume, or other times. This quirk makes sure that's the case for | |
15358 | * affected systems. | |
15359 | */ | |
0206e353 | 15360 | static void quirk_pipea_force(struct drm_device *dev) |
b690e96c JB |
15361 | { |
15362 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15363 | ||
15364 | dev_priv->quirks |= QUIRK_PIPEA_FORCE; | |
bc0daf48 | 15365 | DRM_INFO("applying pipe a force quirk\n"); |
b690e96c JB |
15366 | } |
15367 | ||
b6b5d049 VS |
15368 | static void quirk_pipeb_force(struct drm_device *dev) |
15369 | { | |
15370 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15371 | ||
15372 | dev_priv->quirks |= QUIRK_PIPEB_FORCE; | |
15373 | DRM_INFO("applying pipe b force quirk\n"); | |
15374 | } | |
15375 | ||
435793df KP |
15376 | /* |
15377 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason | |
15378 | */ | |
15379 | static void quirk_ssc_force_disable(struct drm_device *dev) | |
15380 | { | |
15381 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15382 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; | |
bc0daf48 | 15383 | DRM_INFO("applying lvds SSC disable quirk\n"); |
435793df KP |
15384 | } |
15385 | ||
4dca20ef | 15386 | /* |
5a15ab5b CE |
15387 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight |
15388 | * brightness value | |
4dca20ef CE |
15389 | */ |
15390 | static void quirk_invert_brightness(struct drm_device *dev) | |
15391 | { | |
15392 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15393 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; | |
bc0daf48 | 15394 | DRM_INFO("applying inverted panel brightness quirk\n"); |
435793df KP |
15395 | } |
15396 | ||
9c72cc6f SD |
15397 | /* Some VBT's incorrectly indicate no backlight is present */ |
15398 | static void quirk_backlight_present(struct drm_device *dev) | |
15399 | { | |
15400 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15401 | dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT; | |
15402 | DRM_INFO("applying backlight present quirk\n"); | |
15403 | } | |
15404 | ||
b690e96c JB |
15405 | struct intel_quirk { |
15406 | int device; | |
15407 | int subsystem_vendor; | |
15408 | int subsystem_device; | |
15409 | void (*hook)(struct drm_device *dev); | |
15410 | }; | |
15411 | ||
5f85f176 EE |
15412 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ |
15413 | struct intel_dmi_quirk { | |
15414 | void (*hook)(struct drm_device *dev); | |
15415 | const struct dmi_system_id (*dmi_id_list)[]; | |
15416 | }; | |
15417 | ||
15418 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) | |
15419 | { | |
15420 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); | |
15421 | return 1; | |
15422 | } | |
15423 | ||
15424 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { | |
15425 | { | |
15426 | .dmi_id_list = &(const struct dmi_system_id[]) { | |
15427 | { | |
15428 | .callback = intel_dmi_reverse_brightness, | |
15429 | .ident = "NCR Corporation", | |
15430 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), | |
15431 | DMI_MATCH(DMI_PRODUCT_NAME, ""), | |
15432 | }, | |
15433 | }, | |
15434 | { } /* terminating entry */ | |
15435 | }, | |
15436 | .hook = quirk_invert_brightness, | |
15437 | }, | |
15438 | }; | |
15439 | ||
c43b5634 | 15440 | static struct intel_quirk intel_quirks[] = { |
b690e96c JB |
15441 | /* Toshiba Protege R-205, S-209 needs pipe A force quirk */ |
15442 | { 0x2592, 0x1179, 0x0001, quirk_pipea_force }, | |
15443 | ||
b690e96c JB |
15444 | /* ThinkPad T60 needs pipe A force quirk (bug #16494) */ |
15445 | { 0x2782, 0x17aa, 0x201a, quirk_pipea_force }, | |
15446 | ||
5f080c0f VS |
15447 | /* 830 needs to leave pipe A & dpll A up */ |
15448 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, | |
15449 | ||
b6b5d049 VS |
15450 | /* 830 needs to leave pipe B & dpll B up */ |
15451 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force }, | |
15452 | ||
435793df KP |
15453 | /* Lenovo U160 cannot use SSC on LVDS */ |
15454 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, | |
070d329a MAS |
15455 | |
15456 | /* Sony Vaio Y cannot use SSC on LVDS */ | |
15457 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, | |
5a15ab5b | 15458 | |
be505f64 AH |
15459 | /* Acer Aspire 5734Z must invert backlight brightness */ |
15460 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, | |
15461 | ||
15462 | /* Acer/eMachines G725 */ | |
15463 | { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness }, | |
15464 | ||
15465 | /* Acer/eMachines e725 */ | |
15466 | { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness }, | |
15467 | ||
15468 | /* Acer/Packard Bell NCL20 */ | |
15469 | { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness }, | |
15470 | ||
15471 | /* Acer Aspire 4736Z */ | |
15472 | { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness }, | |
0f540c3a JN |
15473 | |
15474 | /* Acer Aspire 5336 */ | |
15475 | { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness }, | |
2e93a1aa SD |
15476 | |
15477 | /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */ | |
15478 | { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present }, | |
d4967d8c | 15479 | |
dfb3d47b SD |
15480 | /* Acer C720 Chromebook (Core i3 4005U) */ |
15481 | { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present }, | |
15482 | ||
b2a9601c | 15483 | /* Apple Macbook 2,1 (Core 2 T7400) */ |
15484 | { 0x27a2, 0x8086, 0x7270, quirk_backlight_present }, | |
15485 | ||
1b9448b0 JN |
15486 | /* Apple Macbook 4,1 */ |
15487 | { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present }, | |
15488 | ||
d4967d8c SD |
15489 | /* Toshiba CB35 Chromebook (Celeron 2955U) */ |
15490 | { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present }, | |
724cb06f SD |
15491 | |
15492 | /* HP Chromebook 14 (Celeron 2955U) */ | |
15493 | { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present }, | |
cf6f0af9 JN |
15494 | |
15495 | /* Dell Chromebook 11 */ | |
15496 | { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present }, | |
9be64eee JN |
15497 | |
15498 | /* Dell Chromebook 11 (2015 version) */ | |
15499 | { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present }, | |
b690e96c JB |
15500 | }; |
15501 | ||
15502 | static void intel_init_quirks(struct drm_device *dev) | |
15503 | { | |
15504 | struct pci_dev *d = dev->pdev; | |
15505 | int i; | |
15506 | ||
15507 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { | |
15508 | struct intel_quirk *q = &intel_quirks[i]; | |
15509 | ||
15510 | if (d->device == q->device && | |
15511 | (d->subsystem_vendor == q->subsystem_vendor || | |
15512 | q->subsystem_vendor == PCI_ANY_ID) && | |
15513 | (d->subsystem_device == q->subsystem_device || | |
15514 | q->subsystem_device == PCI_ANY_ID)) | |
15515 | q->hook(dev); | |
15516 | } | |
5f85f176 EE |
15517 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { |
15518 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) | |
15519 | intel_dmi_quirks[i].hook(dev); | |
15520 | } | |
b690e96c JB |
15521 | } |
15522 | ||
9cce37f4 JB |
15523 | /* Disable the VGA plane that we never use */ |
15524 | static void i915_disable_vga(struct drm_device *dev) | |
15525 | { | |
15526 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15527 | u8 sr1; | |
f0f59a00 | 15528 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev); |
9cce37f4 | 15529 | |
2b37c616 | 15530 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
9cce37f4 | 15531 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
3fdcf431 | 15532 | outb(SR01, VGA_SR_INDEX); |
9cce37f4 JB |
15533 | sr1 = inb(VGA_SR_DATA); |
15534 | outb(sr1 | 1<<5, VGA_SR_DATA); | |
15535 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); | |
15536 | udelay(300); | |
15537 | ||
01f5a626 | 15538 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
9cce37f4 JB |
15539 | POSTING_READ(vga_reg); |
15540 | } | |
15541 | ||
f817586c DV |
15542 | void intel_modeset_init_hw(struct drm_device *dev) |
15543 | { | |
1a617b77 ML |
15544 | struct drm_i915_private *dev_priv = dev->dev_private; |
15545 | ||
b6283055 | 15546 | intel_update_cdclk(dev); |
1a617b77 ML |
15547 | |
15548 | dev_priv->atomic_cdclk_freq = dev_priv->cdclk_freq; | |
15549 | ||
f817586c | 15550 | intel_init_clock_gating(dev); |
dc97997a | 15551 | intel_enable_gt_powersave(dev_priv); |
f817586c DV |
15552 | } |
15553 | ||
d93c0372 MR |
15554 | /* |
15555 | * Calculate what we think the watermarks should be for the state we've read | |
15556 | * out of the hardware and then immediately program those watermarks so that | |
15557 | * we ensure the hardware settings match our internal state. | |
15558 | * | |
15559 | * We can calculate what we think WM's should be by creating a duplicate of the | |
15560 | * current state (which was constructed during hardware readout) and running it | |
15561 | * through the atomic check code to calculate new watermark values in the | |
15562 | * state object. | |
15563 | */ | |
15564 | static void sanitize_watermarks(struct drm_device *dev) | |
15565 | { | |
15566 | struct drm_i915_private *dev_priv = to_i915(dev); | |
15567 | struct drm_atomic_state *state; | |
15568 | struct drm_crtc *crtc; | |
15569 | struct drm_crtc_state *cstate; | |
15570 | struct drm_modeset_acquire_ctx ctx; | |
15571 | int ret; | |
15572 | int i; | |
15573 | ||
15574 | /* Only supported on platforms that use atomic watermark design */ | |
ed4a6a7c | 15575 | if (!dev_priv->display.optimize_watermarks) |
d93c0372 MR |
15576 | return; |
15577 | ||
15578 | /* | |
15579 | * We need to hold connection_mutex before calling duplicate_state so | |
15580 | * that the connector loop is protected. | |
15581 | */ | |
15582 | drm_modeset_acquire_init(&ctx, 0); | |
15583 | retry: | |
0cd1262d | 15584 | ret = drm_modeset_lock_all_ctx(dev, &ctx); |
d93c0372 MR |
15585 | if (ret == -EDEADLK) { |
15586 | drm_modeset_backoff(&ctx); | |
15587 | goto retry; | |
15588 | } else if (WARN_ON(ret)) { | |
0cd1262d | 15589 | goto fail; |
d93c0372 MR |
15590 | } |
15591 | ||
15592 | state = drm_atomic_helper_duplicate_state(dev, &ctx); | |
15593 | if (WARN_ON(IS_ERR(state))) | |
0cd1262d | 15594 | goto fail; |
d93c0372 | 15595 | |
ed4a6a7c MR |
15596 | /* |
15597 | * Hardware readout is the only time we don't want to calculate | |
15598 | * intermediate watermarks (since we don't trust the current | |
15599 | * watermarks). | |
15600 | */ | |
15601 | to_intel_atomic_state(state)->skip_intermediate_wm = true; | |
15602 | ||
d93c0372 MR |
15603 | ret = intel_atomic_check(dev, state); |
15604 | if (ret) { | |
15605 | /* | |
15606 | * If we fail here, it means that the hardware appears to be | |
15607 | * programmed in a way that shouldn't be possible, given our | |
15608 | * understanding of watermark requirements. This might mean a | |
15609 | * mistake in the hardware readout code or a mistake in the | |
15610 | * watermark calculations for a given platform. Raise a WARN | |
15611 | * so that this is noticeable. | |
15612 | * | |
15613 | * If this actually happens, we'll have to just leave the | |
15614 | * BIOS-programmed watermarks untouched and hope for the best. | |
15615 | */ | |
15616 | WARN(true, "Could not determine valid watermarks for inherited state\n"); | |
0cd1262d | 15617 | goto fail; |
d93c0372 MR |
15618 | } |
15619 | ||
15620 | /* Write calculated watermark values back */ | |
d93c0372 MR |
15621 | for_each_crtc_in_state(state, crtc, cstate, i) { |
15622 | struct intel_crtc_state *cs = to_intel_crtc_state(cstate); | |
15623 | ||
ed4a6a7c MR |
15624 | cs->wm.need_postvbl_update = true; |
15625 | dev_priv->display.optimize_watermarks(cs); | |
d93c0372 MR |
15626 | } |
15627 | ||
15628 | drm_atomic_state_free(state); | |
0cd1262d | 15629 | fail: |
d93c0372 MR |
15630 | drm_modeset_drop_locks(&ctx); |
15631 | drm_modeset_acquire_fini(&ctx); | |
15632 | } | |
15633 | ||
79e53945 JB |
15634 | void intel_modeset_init(struct drm_device *dev) |
15635 | { | |
72e96d64 JL |
15636 | struct drm_i915_private *dev_priv = to_i915(dev); |
15637 | struct i915_ggtt *ggtt = &dev_priv->ggtt; | |
1fe47785 | 15638 | int sprite, ret; |
8cc87b75 | 15639 | enum pipe pipe; |
46f297fb | 15640 | struct intel_crtc *crtc; |
79e53945 JB |
15641 | |
15642 | drm_mode_config_init(dev); | |
15643 | ||
15644 | dev->mode_config.min_width = 0; | |
15645 | dev->mode_config.min_height = 0; | |
15646 | ||
019d96cb DA |
15647 | dev->mode_config.preferred_depth = 24; |
15648 | dev->mode_config.prefer_shadow = 1; | |
15649 | ||
25bab385 TU |
15650 | dev->mode_config.allow_fb_modifiers = true; |
15651 | ||
e6ecefaa | 15652 | dev->mode_config.funcs = &intel_mode_funcs; |
79e53945 | 15653 | |
b690e96c JB |
15654 | intel_init_quirks(dev); |
15655 | ||
1fa61106 ED |
15656 | intel_init_pm(dev); |
15657 | ||
e3c74757 BW |
15658 | if (INTEL_INFO(dev)->num_pipes == 0) |
15659 | return; | |
15660 | ||
69f92f67 LW |
15661 | /* |
15662 | * There may be no VBT; and if the BIOS enabled SSC we can | |
15663 | * just keep using it to avoid unnecessary flicker. Whereas if the | |
15664 | * BIOS isn't using it, don't assume it will work even if the VBT | |
15665 | * indicates as much. | |
15666 | */ | |
15667 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) { | |
15668 | bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & | |
15669 | DREF_SSC1_ENABLE); | |
15670 | ||
15671 | if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) { | |
15672 | DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n", | |
15673 | bios_lvds_use_ssc ? "en" : "dis", | |
15674 | dev_priv->vbt.lvds_use_ssc ? "en" : "dis"); | |
15675 | dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc; | |
15676 | } | |
15677 | } | |
15678 | ||
a6c45cf0 CW |
15679 | if (IS_GEN2(dev)) { |
15680 | dev->mode_config.max_width = 2048; | |
15681 | dev->mode_config.max_height = 2048; | |
15682 | } else if (IS_GEN3(dev)) { | |
5e4d6fa7 KP |
15683 | dev->mode_config.max_width = 4096; |
15684 | dev->mode_config.max_height = 4096; | |
79e53945 | 15685 | } else { |
a6c45cf0 CW |
15686 | dev->mode_config.max_width = 8192; |
15687 | dev->mode_config.max_height = 8192; | |
79e53945 | 15688 | } |
068be561 | 15689 | |
dc41c154 VS |
15690 | if (IS_845G(dev) || IS_I865G(dev)) { |
15691 | dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512; | |
15692 | dev->mode_config.cursor_height = 1023; | |
15693 | } else if (IS_GEN2(dev)) { | |
068be561 DL |
15694 | dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH; |
15695 | dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT; | |
15696 | } else { | |
15697 | dev->mode_config.cursor_width = MAX_CURSOR_WIDTH; | |
15698 | dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT; | |
15699 | } | |
15700 | ||
72e96d64 | 15701 | dev->mode_config.fb_base = ggtt->mappable_base; |
79e53945 | 15702 | |
28c97730 | 15703 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
7eb552ae BW |
15704 | INTEL_INFO(dev)->num_pipes, |
15705 | INTEL_INFO(dev)->num_pipes > 1 ? "s" : ""); | |
79e53945 | 15706 | |
055e393f | 15707 | for_each_pipe(dev_priv, pipe) { |
8cc87b75 | 15708 | intel_crtc_init(dev, pipe); |
3bdcfc0c | 15709 | for_each_sprite(dev_priv, pipe, sprite) { |
1fe47785 | 15710 | ret = intel_plane_init(dev, pipe, sprite); |
7f1f3851 | 15711 | if (ret) |
06da8da2 | 15712 | DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n", |
1fe47785 | 15713 | pipe_name(pipe), sprite_name(pipe, sprite), ret); |
7f1f3851 | 15714 | } |
79e53945 JB |
15715 | } |
15716 | ||
bfa7df01 VS |
15717 | intel_update_czclk(dev_priv); |
15718 | intel_update_cdclk(dev); | |
15719 | ||
e72f9fbf | 15720 | intel_shared_dpll_init(dev); |
ee7b9f93 | 15721 | |
b2045352 VS |
15722 | if (dev_priv->max_cdclk_freq == 0) |
15723 | intel_update_max_cdclk(dev); | |
15724 | ||
9cce37f4 JB |
15725 | /* Just disable it once at startup */ |
15726 | i915_disable_vga(dev); | |
79e53945 | 15727 | intel_setup_outputs(dev); |
11be49eb | 15728 | |
6e9f798d | 15729 | drm_modeset_lock_all(dev); |
043e9bda | 15730 | intel_modeset_setup_hw_state(dev); |
6e9f798d | 15731 | drm_modeset_unlock_all(dev); |
46f297fb | 15732 | |
d3fcc808 | 15733 | for_each_intel_crtc(dev, crtc) { |
eeebeac5 ML |
15734 | struct intel_initial_plane_config plane_config = {}; |
15735 | ||
46f297fb JB |
15736 | if (!crtc->active) |
15737 | continue; | |
15738 | ||
46f297fb | 15739 | /* |
46f297fb JB |
15740 | * Note that reserving the BIOS fb up front prevents us |
15741 | * from stuffing other stolen allocations like the ring | |
15742 | * on top. This prevents some ugliness at boot time, and | |
15743 | * can even allow for smooth boot transitions if the BIOS | |
15744 | * fb is large enough for the active pipe configuration. | |
15745 | */ | |
eeebeac5 ML |
15746 | dev_priv->display.get_initial_plane_config(crtc, |
15747 | &plane_config); | |
15748 | ||
15749 | /* | |
15750 | * If the fb is shared between multiple heads, we'll | |
15751 | * just get the first one. | |
15752 | */ | |
15753 | intel_find_initial_plane_obj(crtc, &plane_config); | |
46f297fb | 15754 | } |
d93c0372 MR |
15755 | |
15756 | /* | |
15757 | * Make sure hardware watermarks really match the state we read out. | |
15758 | * Note that we need to do this after reconstructing the BIOS fb's | |
15759 | * since the watermark calculation done here will use pstate->fb. | |
15760 | */ | |
15761 | sanitize_watermarks(dev); | |
2c7111db CW |
15762 | } |
15763 | ||
7fad798e DV |
15764 | static void intel_enable_pipe_a(struct drm_device *dev) |
15765 | { | |
15766 | struct intel_connector *connector; | |
15767 | struct drm_connector *crt = NULL; | |
15768 | struct intel_load_detect_pipe load_detect_temp; | |
208bf9fd | 15769 | struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx; |
7fad798e DV |
15770 | |
15771 | /* We can't just switch on the pipe A, we need to set things up with a | |
15772 | * proper mode and output configuration. As a gross hack, enable pipe A | |
15773 | * by enabling the load detect pipe once. */ | |
3a3371ff | 15774 | for_each_intel_connector(dev, connector) { |
7fad798e DV |
15775 | if (connector->encoder->type == INTEL_OUTPUT_ANALOG) { |
15776 | crt = &connector->base; | |
15777 | break; | |
15778 | } | |
15779 | } | |
15780 | ||
15781 | if (!crt) | |
15782 | return; | |
15783 | ||
208bf9fd | 15784 | if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, ctx)) |
49172fee | 15785 | intel_release_load_detect_pipe(crt, &load_detect_temp, ctx); |
7fad798e DV |
15786 | } |
15787 | ||
fa555837 DV |
15788 | static bool |
15789 | intel_check_plane_mapping(struct intel_crtc *crtc) | |
15790 | { | |
7eb552ae BW |
15791 | struct drm_device *dev = crtc->base.dev; |
15792 | struct drm_i915_private *dev_priv = dev->dev_private; | |
649636ef | 15793 | u32 val; |
fa555837 | 15794 | |
7eb552ae | 15795 | if (INTEL_INFO(dev)->num_pipes == 1) |
fa555837 DV |
15796 | return true; |
15797 | ||
649636ef | 15798 | val = I915_READ(DSPCNTR(!crtc->plane)); |
fa555837 DV |
15799 | |
15800 | if ((val & DISPLAY_PLANE_ENABLE) && | |
15801 | (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe)) | |
15802 | return false; | |
15803 | ||
15804 | return true; | |
15805 | } | |
15806 | ||
02e93c35 VS |
15807 | static bool intel_crtc_has_encoders(struct intel_crtc *crtc) |
15808 | { | |
15809 | struct drm_device *dev = crtc->base.dev; | |
15810 | struct intel_encoder *encoder; | |
15811 | ||
15812 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) | |
15813 | return true; | |
15814 | ||
15815 | return false; | |
15816 | } | |
15817 | ||
dd756198 VS |
15818 | static bool intel_encoder_has_connectors(struct intel_encoder *encoder) |
15819 | { | |
15820 | struct drm_device *dev = encoder->base.dev; | |
15821 | struct intel_connector *connector; | |
15822 | ||
15823 | for_each_connector_on_encoder(dev, &encoder->base, connector) | |
15824 | return true; | |
15825 | ||
15826 | return false; | |
15827 | } | |
15828 | ||
24929352 DV |
15829 | static void intel_sanitize_crtc(struct intel_crtc *crtc) |
15830 | { | |
15831 | struct drm_device *dev = crtc->base.dev; | |
15832 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4d1de975 | 15833 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
24929352 | 15834 | |
24929352 | 15835 | /* Clear any frame start delays used for debugging left by the BIOS */ |
4d1de975 JN |
15836 | if (!transcoder_is_dsi(cpu_transcoder)) { |
15837 | i915_reg_t reg = PIPECONF(cpu_transcoder); | |
15838 | ||
15839 | I915_WRITE(reg, | |
15840 | I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); | |
15841 | } | |
24929352 | 15842 | |
d3eaf884 | 15843 | /* restore vblank interrupts to correct state */ |
9625604c | 15844 | drm_crtc_vblank_reset(&crtc->base); |
d297e103 | 15845 | if (crtc->active) { |
f9cd7b88 VS |
15846 | struct intel_plane *plane; |
15847 | ||
9625604c | 15848 | drm_crtc_vblank_on(&crtc->base); |
f9cd7b88 VS |
15849 | |
15850 | /* Disable everything but the primary plane */ | |
15851 | for_each_intel_plane_on_crtc(dev, crtc, plane) { | |
15852 | if (plane->base.type == DRM_PLANE_TYPE_PRIMARY) | |
15853 | continue; | |
15854 | ||
15855 | plane->disable_plane(&plane->base, &crtc->base); | |
15856 | } | |
9625604c | 15857 | } |
d3eaf884 | 15858 | |
24929352 | 15859 | /* We need to sanitize the plane -> pipe mapping first because this will |
fa555837 DV |
15860 | * disable the crtc (and hence change the state) if it is wrong. Note |
15861 | * that gen4+ has a fixed plane -> pipe mapping. */ | |
15862 | if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) { | |
24929352 DV |
15863 | bool plane; |
15864 | ||
78108b7c VS |
15865 | DRM_DEBUG_KMS("[CRTC:%d:%s] wrong plane connection detected!\n", |
15866 | crtc->base.base.id, crtc->base.name); | |
24929352 DV |
15867 | |
15868 | /* Pipe has the wrong plane attached and the plane is active. | |
15869 | * Temporarily change the plane mapping and disable everything | |
15870 | * ... */ | |
15871 | plane = crtc->plane; | |
b70709a6 | 15872 | to_intel_plane_state(crtc->base.primary->state)->visible = true; |
24929352 | 15873 | crtc->plane = !plane; |
b17d48e2 | 15874 | intel_crtc_disable_noatomic(&crtc->base); |
24929352 | 15875 | crtc->plane = plane; |
24929352 | 15876 | } |
24929352 | 15877 | |
7fad798e DV |
15878 | if (dev_priv->quirks & QUIRK_PIPEA_FORCE && |
15879 | crtc->pipe == PIPE_A && !crtc->active) { | |
15880 | /* BIOS forgot to enable pipe A, this mostly happens after | |
15881 | * resume. Force-enable the pipe to fix this, the update_dpms | |
15882 | * call below we restore the pipe to the right state, but leave | |
15883 | * the required bits on. */ | |
15884 | intel_enable_pipe_a(dev); | |
15885 | } | |
15886 | ||
24929352 DV |
15887 | /* Adjust the state of the output pipe according to whether we |
15888 | * have active connectors/encoders. */ | |
842e0307 | 15889 | if (crtc->active && !intel_crtc_has_encoders(crtc)) |
b17d48e2 | 15890 | intel_crtc_disable_noatomic(&crtc->base); |
24929352 | 15891 | |
a3ed6aad | 15892 | if (crtc->active || HAS_GMCH_DISPLAY(dev)) { |
4cc31489 DV |
15893 | /* |
15894 | * We start out with underrun reporting disabled to avoid races. | |
15895 | * For correct bookkeeping mark this on active crtcs. | |
15896 | * | |
c5ab3bc0 DV |
15897 | * Also on gmch platforms we dont have any hardware bits to |
15898 | * disable the underrun reporting. Which means we need to start | |
15899 | * out with underrun reporting disabled also on inactive pipes, | |
15900 | * since otherwise we'll complain about the garbage we read when | |
15901 | * e.g. coming up after runtime pm. | |
15902 | * | |
4cc31489 DV |
15903 | * No protection against concurrent access is required - at |
15904 | * worst a fifo underrun happens which also sets this to false. | |
15905 | */ | |
15906 | crtc->cpu_fifo_underrun_disabled = true; | |
15907 | crtc->pch_fifo_underrun_disabled = true; | |
15908 | } | |
24929352 DV |
15909 | } |
15910 | ||
15911 | static void intel_sanitize_encoder(struct intel_encoder *encoder) | |
15912 | { | |
15913 | struct intel_connector *connector; | |
15914 | struct drm_device *dev = encoder->base.dev; | |
15915 | ||
15916 | /* We need to check both for a crtc link (meaning that the | |
15917 | * encoder is active and trying to read from a pipe) and the | |
15918 | * pipe itself being active. */ | |
15919 | bool has_active_crtc = encoder->base.crtc && | |
15920 | to_intel_crtc(encoder->base.crtc)->active; | |
15921 | ||
dd756198 | 15922 | if (intel_encoder_has_connectors(encoder) && !has_active_crtc) { |
24929352 DV |
15923 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
15924 | encoder->base.base.id, | |
8e329a03 | 15925 | encoder->base.name); |
24929352 DV |
15926 | |
15927 | /* Connector is active, but has no active pipe. This is | |
15928 | * fallout from our resume register restoring. Disable | |
15929 | * the encoder manually again. */ | |
15930 | if (encoder->base.crtc) { | |
15931 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", | |
15932 | encoder->base.base.id, | |
8e329a03 | 15933 | encoder->base.name); |
24929352 | 15934 | encoder->disable(encoder); |
a62d1497 VS |
15935 | if (encoder->post_disable) |
15936 | encoder->post_disable(encoder); | |
24929352 | 15937 | } |
7f1950fb | 15938 | encoder->base.crtc = NULL; |
24929352 DV |
15939 | |
15940 | /* Inconsistent output/port/pipe state happens presumably due to | |
15941 | * a bug in one of the get_hw_state functions. Or someplace else | |
15942 | * in our code, like the register restore mess on resume. Clamp | |
15943 | * things to off as a safer default. */ | |
3a3371ff | 15944 | for_each_intel_connector(dev, connector) { |
24929352 DV |
15945 | if (connector->encoder != encoder) |
15946 | continue; | |
7f1950fb EE |
15947 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
15948 | connector->base.encoder = NULL; | |
24929352 DV |
15949 | } |
15950 | } | |
15951 | /* Enabled encoders without active connectors will be fixed in | |
15952 | * the crtc fixup. */ | |
15953 | } | |
15954 | ||
04098753 | 15955 | void i915_redisable_vga_power_on(struct drm_device *dev) |
0fde901f KM |
15956 | { |
15957 | struct drm_i915_private *dev_priv = dev->dev_private; | |
f0f59a00 | 15958 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev); |
0fde901f | 15959 | |
04098753 ID |
15960 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
15961 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); | |
15962 | i915_disable_vga(dev); | |
15963 | } | |
15964 | } | |
15965 | ||
15966 | void i915_redisable_vga(struct drm_device *dev) | |
15967 | { | |
15968 | struct drm_i915_private *dev_priv = dev->dev_private; | |
15969 | ||
8dc8a27c PZ |
15970 | /* This function can be called both from intel_modeset_setup_hw_state or |
15971 | * at a very early point in our resume sequence, where the power well | |
15972 | * structures are not yet restored. Since this function is at a very | |
15973 | * paranoid "someone might have enabled VGA while we were not looking" | |
15974 | * level, just check if the power well is enabled instead of trying to | |
15975 | * follow the "don't touch the power well if we don't need it" policy | |
15976 | * the rest of the driver uses. */ | |
6392f847 | 15977 | if (!intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_VGA)) |
8dc8a27c PZ |
15978 | return; |
15979 | ||
04098753 | 15980 | i915_redisable_vga_power_on(dev); |
6392f847 ID |
15981 | |
15982 | intel_display_power_put(dev_priv, POWER_DOMAIN_VGA); | |
0fde901f KM |
15983 | } |
15984 | ||
f9cd7b88 | 15985 | static bool primary_get_hw_state(struct intel_plane *plane) |
98ec7739 | 15986 | { |
f9cd7b88 | 15987 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
98ec7739 | 15988 | |
f9cd7b88 | 15989 | return I915_READ(DSPCNTR(plane->plane)) & DISPLAY_PLANE_ENABLE; |
d032ffa0 ML |
15990 | } |
15991 | ||
f9cd7b88 VS |
15992 | /* FIXME read out full plane state for all planes */ |
15993 | static void readout_plane_state(struct intel_crtc *crtc) | |
d032ffa0 | 15994 | { |
b26d3ea3 | 15995 | struct drm_plane *primary = crtc->base.primary; |
f9cd7b88 | 15996 | struct intel_plane_state *plane_state = |
b26d3ea3 | 15997 | to_intel_plane_state(primary->state); |
d032ffa0 | 15998 | |
19b8d387 | 15999 | plane_state->visible = crtc->active && |
b26d3ea3 ML |
16000 | primary_get_hw_state(to_intel_plane(primary)); |
16001 | ||
16002 | if (plane_state->visible) | |
16003 | crtc->base.state->plane_mask |= 1 << drm_plane_index(primary); | |
98ec7739 VS |
16004 | } |
16005 | ||
30e984df | 16006 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
24929352 DV |
16007 | { |
16008 | struct drm_i915_private *dev_priv = dev->dev_private; | |
16009 | enum pipe pipe; | |
24929352 DV |
16010 | struct intel_crtc *crtc; |
16011 | struct intel_encoder *encoder; | |
16012 | struct intel_connector *connector; | |
5358901f | 16013 | int i; |
24929352 | 16014 | |
565602d7 ML |
16015 | dev_priv->active_crtcs = 0; |
16016 | ||
d3fcc808 | 16017 | for_each_intel_crtc(dev, crtc) { |
565602d7 ML |
16018 | struct intel_crtc_state *crtc_state = crtc->config; |
16019 | int pixclk = 0; | |
3b117c8f | 16020 | |
ec2dc6a0 | 16021 | __drm_atomic_helper_crtc_destroy_state(&crtc_state->base); |
565602d7 ML |
16022 | memset(crtc_state, 0, sizeof(*crtc_state)); |
16023 | crtc_state->base.crtc = &crtc->base; | |
24929352 | 16024 | |
565602d7 ML |
16025 | crtc_state->base.active = crtc_state->base.enable = |
16026 | dev_priv->display.get_pipe_config(crtc, crtc_state); | |
16027 | ||
16028 | crtc->base.enabled = crtc_state->base.enable; | |
16029 | crtc->active = crtc_state->base.active; | |
16030 | ||
16031 | if (crtc_state->base.active) { | |
16032 | dev_priv->active_crtcs |= 1 << crtc->pipe; | |
16033 | ||
c89e39f3 | 16034 | if (INTEL_GEN(dev_priv) >= 9 || IS_BROADWELL(dev_priv)) |
565602d7 | 16035 | pixclk = ilk_pipe_pixel_rate(crtc_state); |
9558d15d | 16036 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
565602d7 ML |
16037 | pixclk = crtc_state->base.adjusted_mode.crtc_clock; |
16038 | else | |
16039 | WARN_ON(dev_priv->display.modeset_calc_cdclk); | |
9558d15d VS |
16040 | |
16041 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ | |
16042 | if (IS_BROADWELL(dev_priv) && crtc_state->ips_enabled) | |
16043 | pixclk = DIV_ROUND_UP(pixclk * 100, 95); | |
565602d7 ML |
16044 | } |
16045 | ||
16046 | dev_priv->min_pixclk[crtc->pipe] = pixclk; | |
b70709a6 | 16047 | |
f9cd7b88 | 16048 | readout_plane_state(crtc); |
24929352 | 16049 | |
78108b7c VS |
16050 | DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n", |
16051 | crtc->base.base.id, crtc->base.name, | |
24929352 DV |
16052 | crtc->active ? "enabled" : "disabled"); |
16053 | } | |
16054 | ||
5358901f DV |
16055 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
16056 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
16057 | ||
2edd6443 ACO |
16058 | pll->on = pll->funcs.get_hw_state(dev_priv, pll, |
16059 | &pll->config.hw_state); | |
3e369b76 | 16060 | pll->config.crtc_mask = 0; |
d3fcc808 | 16061 | for_each_intel_crtc(dev, crtc) { |
2dd66ebd | 16062 | if (crtc->active && crtc->config->shared_dpll == pll) |
3e369b76 | 16063 | pll->config.crtc_mask |= 1 << crtc->pipe; |
5358901f | 16064 | } |
2dd66ebd | 16065 | pll->active_mask = pll->config.crtc_mask; |
5358901f | 16066 | |
1e6f2ddc | 16067 | DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n", |
3e369b76 | 16068 | pll->name, pll->config.crtc_mask, pll->on); |
5358901f DV |
16069 | } |
16070 | ||
b2784e15 | 16071 | for_each_intel_encoder(dev, encoder) { |
24929352 DV |
16072 | pipe = 0; |
16073 | ||
16074 | if (encoder->get_hw_state(encoder, &pipe)) { | |
045ac3b5 JB |
16075 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
16076 | encoder->base.crtc = &crtc->base; | |
6e3c9717 | 16077 | encoder->get_config(encoder, crtc->config); |
24929352 DV |
16078 | } else { |
16079 | encoder->base.crtc = NULL; | |
16080 | } | |
16081 | ||
6f2bcceb | 16082 | DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n", |
24929352 | 16083 | encoder->base.base.id, |
8e329a03 | 16084 | encoder->base.name, |
24929352 | 16085 | encoder->base.crtc ? "enabled" : "disabled", |
6f2bcceb | 16086 | pipe_name(pipe)); |
24929352 DV |
16087 | } |
16088 | ||
3a3371ff | 16089 | for_each_intel_connector(dev, connector) { |
24929352 DV |
16090 | if (connector->get_hw_state(connector)) { |
16091 | connector->base.dpms = DRM_MODE_DPMS_ON; | |
2aa974c9 ML |
16092 | |
16093 | encoder = connector->encoder; | |
16094 | connector->base.encoder = &encoder->base; | |
16095 | ||
16096 | if (encoder->base.crtc && | |
16097 | encoder->base.crtc->state->active) { | |
16098 | /* | |
16099 | * This has to be done during hardware readout | |
16100 | * because anything calling .crtc_disable may | |
16101 | * rely on the connector_mask being accurate. | |
16102 | */ | |
16103 | encoder->base.crtc->state->connector_mask |= | |
16104 | 1 << drm_connector_index(&connector->base); | |
e87a52b3 ML |
16105 | encoder->base.crtc->state->encoder_mask |= |
16106 | 1 << drm_encoder_index(&encoder->base); | |
2aa974c9 ML |
16107 | } |
16108 | ||
24929352 DV |
16109 | } else { |
16110 | connector->base.dpms = DRM_MODE_DPMS_OFF; | |
16111 | connector->base.encoder = NULL; | |
16112 | } | |
16113 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", | |
16114 | connector->base.base.id, | |
c23cc417 | 16115 | connector->base.name, |
24929352 DV |
16116 | connector->base.encoder ? "enabled" : "disabled"); |
16117 | } | |
7f4c6284 VS |
16118 | |
16119 | for_each_intel_crtc(dev, crtc) { | |
16120 | crtc->base.hwmode = crtc->config->base.adjusted_mode; | |
16121 | ||
16122 | memset(&crtc->base.mode, 0, sizeof(crtc->base.mode)); | |
16123 | if (crtc->base.state->active) { | |
16124 | intel_mode_from_pipe_config(&crtc->base.mode, crtc->config); | |
16125 | intel_mode_from_pipe_config(&crtc->base.state->adjusted_mode, crtc->config); | |
16126 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode)); | |
16127 | ||
16128 | /* | |
16129 | * The initial mode needs to be set in order to keep | |
16130 | * the atomic core happy. It wants a valid mode if the | |
16131 | * crtc's enabled, so we do the above call. | |
16132 | * | |
16133 | * At this point some state updated by the connectors | |
16134 | * in their ->detect() callback has not run yet, so | |
16135 | * no recalculation can be done yet. | |
16136 | * | |
16137 | * Even if we could do a recalculation and modeset | |
16138 | * right now it would cause a double modeset if | |
16139 | * fbdev or userspace chooses a different initial mode. | |
16140 | * | |
16141 | * If that happens, someone indicated they wanted a | |
16142 | * mode change, which means it's safe to do a full | |
16143 | * recalculation. | |
16144 | */ | |
16145 | crtc->base.state->mode.private_flags = I915_MODE_FLAG_INHERITED; | |
9eca6832 VS |
16146 | |
16147 | drm_calc_timestamping_constants(&crtc->base, &crtc->base.hwmode); | |
16148 | update_scanline_offset(crtc); | |
7f4c6284 | 16149 | } |
e3b247da VS |
16150 | |
16151 | intel_pipe_config_sanity_check(dev_priv, crtc->config); | |
7f4c6284 | 16152 | } |
30e984df DV |
16153 | } |
16154 | ||
043e9bda ML |
16155 | /* Scan out the current hw modeset state, |
16156 | * and sanitizes it to the current state | |
16157 | */ | |
16158 | static void | |
16159 | intel_modeset_setup_hw_state(struct drm_device *dev) | |
30e984df DV |
16160 | { |
16161 | struct drm_i915_private *dev_priv = dev->dev_private; | |
16162 | enum pipe pipe; | |
30e984df DV |
16163 | struct intel_crtc *crtc; |
16164 | struct intel_encoder *encoder; | |
35c95375 | 16165 | int i; |
30e984df DV |
16166 | |
16167 | intel_modeset_readout_hw_state(dev); | |
24929352 DV |
16168 | |
16169 | /* HW state is read out, now we need to sanitize this mess. */ | |
b2784e15 | 16170 | for_each_intel_encoder(dev, encoder) { |
24929352 DV |
16171 | intel_sanitize_encoder(encoder); |
16172 | } | |
16173 | ||
055e393f | 16174 | for_each_pipe(dev_priv, pipe) { |
24929352 DV |
16175 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
16176 | intel_sanitize_crtc(crtc); | |
6e3c9717 ACO |
16177 | intel_dump_pipe_config(crtc, crtc->config, |
16178 | "[setup_hw_state]"); | |
24929352 | 16179 | } |
9a935856 | 16180 | |
d29b2f9d ACO |
16181 | intel_modeset_update_connector_atomic_state(dev); |
16182 | ||
35c95375 DV |
16183 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
16184 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
16185 | ||
2dd66ebd | 16186 | if (!pll->on || pll->active_mask) |
35c95375 DV |
16187 | continue; |
16188 | ||
16189 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name); | |
16190 | ||
2edd6443 | 16191 | pll->funcs.disable(dev_priv, pll); |
35c95375 DV |
16192 | pll->on = false; |
16193 | } | |
16194 | ||
666a4537 | 16195 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) |
6eb1a681 VS |
16196 | vlv_wm_get_hw_state(dev); |
16197 | else if (IS_GEN9(dev)) | |
3078999f PB |
16198 | skl_wm_get_hw_state(dev); |
16199 | else if (HAS_PCH_SPLIT(dev)) | |
243e6a44 | 16200 | ilk_wm_get_hw_state(dev); |
292b990e ML |
16201 | |
16202 | for_each_intel_crtc(dev, crtc) { | |
16203 | unsigned long put_domains; | |
16204 | ||
74bff5f9 | 16205 | put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc->config); |
292b990e ML |
16206 | if (WARN_ON(put_domains)) |
16207 | modeset_put_power_domains(dev_priv, put_domains); | |
16208 | } | |
16209 | intel_display_set_init_power(dev_priv, false); | |
010cf73d PZ |
16210 | |
16211 | intel_fbc_init_pipe_state(dev_priv); | |
043e9bda | 16212 | } |
7d0bc1ea | 16213 | |
043e9bda ML |
16214 | void intel_display_resume(struct drm_device *dev) |
16215 | { | |
e2c8b870 ML |
16216 | struct drm_i915_private *dev_priv = to_i915(dev); |
16217 | struct drm_atomic_state *state = dev_priv->modeset_restore_state; | |
16218 | struct drm_modeset_acquire_ctx ctx; | |
043e9bda | 16219 | int ret; |
e2c8b870 | 16220 | bool setup = false; |
f30da187 | 16221 | |
e2c8b870 | 16222 | dev_priv->modeset_restore_state = NULL; |
043e9bda | 16223 | |
ea49c9ac ML |
16224 | /* |
16225 | * This is a cludge because with real atomic modeset mode_config.mutex | |
16226 | * won't be taken. Unfortunately some probed state like | |
16227 | * audio_codec_enable is still protected by mode_config.mutex, so lock | |
16228 | * it here for now. | |
16229 | */ | |
16230 | mutex_lock(&dev->mode_config.mutex); | |
e2c8b870 | 16231 | drm_modeset_acquire_init(&ctx, 0); |
043e9bda | 16232 | |
e2c8b870 ML |
16233 | retry: |
16234 | ret = drm_modeset_lock_all_ctx(dev, &ctx); | |
043e9bda | 16235 | |
e2c8b870 ML |
16236 | if (ret == 0 && !setup) { |
16237 | setup = true; | |
043e9bda | 16238 | |
e2c8b870 ML |
16239 | intel_modeset_setup_hw_state(dev); |
16240 | i915_redisable_vga(dev); | |
45e2b5f6 | 16241 | } |
8af6cf88 | 16242 | |
e2c8b870 ML |
16243 | if (ret == 0 && state) { |
16244 | struct drm_crtc_state *crtc_state; | |
16245 | struct drm_crtc *crtc; | |
16246 | int i; | |
043e9bda | 16247 | |
e2c8b870 ML |
16248 | state->acquire_ctx = &ctx; |
16249 | ||
e3d5457c VS |
16250 | /* ignore any reset values/BIOS leftovers in the WM registers */ |
16251 | to_intel_atomic_state(state)->skip_intermediate_wm = true; | |
16252 | ||
e2c8b870 ML |
16253 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
16254 | /* | |
16255 | * Force recalculation even if we restore | |
16256 | * current state. With fast modeset this may not result | |
16257 | * in a modeset when the state is compatible. | |
16258 | */ | |
16259 | crtc_state->mode_changed = true; | |
16260 | } | |
16261 | ||
16262 | ret = drm_atomic_commit(state); | |
043e9bda ML |
16263 | } |
16264 | ||
e2c8b870 ML |
16265 | if (ret == -EDEADLK) { |
16266 | drm_modeset_backoff(&ctx); | |
16267 | goto retry; | |
16268 | } | |
043e9bda | 16269 | |
e2c8b870 ML |
16270 | drm_modeset_drop_locks(&ctx); |
16271 | drm_modeset_acquire_fini(&ctx); | |
ea49c9ac | 16272 | mutex_unlock(&dev->mode_config.mutex); |
043e9bda | 16273 | |
e2c8b870 ML |
16274 | if (ret) { |
16275 | DRM_ERROR("Restoring old state failed with %i\n", ret); | |
16276 | drm_atomic_state_free(state); | |
16277 | } | |
2c7111db CW |
16278 | } |
16279 | ||
16280 | void intel_modeset_gem_init(struct drm_device *dev) | |
16281 | { | |
dc97997a | 16282 | struct drm_i915_private *dev_priv = to_i915(dev); |
484b41dd | 16283 | struct drm_crtc *c; |
2ff8fde1 | 16284 | struct drm_i915_gem_object *obj; |
e0d6149b | 16285 | int ret; |
484b41dd | 16286 | |
dc97997a | 16287 | intel_init_gt_powersave(dev_priv); |
ae48434c | 16288 | |
1833b134 | 16289 | intel_modeset_init_hw(dev); |
02e792fb | 16290 | |
1ee8da6d | 16291 | intel_setup_overlay(dev_priv); |
484b41dd JB |
16292 | |
16293 | /* | |
16294 | * Make sure any fbs we allocated at startup are properly | |
16295 | * pinned & fenced. When we do the allocation it's too early | |
16296 | * for this. | |
16297 | */ | |
70e1e0ec | 16298 | for_each_crtc(dev, c) { |
2ff8fde1 MR |
16299 | obj = intel_fb_obj(c->primary->fb); |
16300 | if (obj == NULL) | |
484b41dd JB |
16301 | continue; |
16302 | ||
e0d6149b | 16303 | mutex_lock(&dev->struct_mutex); |
3465c580 VS |
16304 | ret = intel_pin_and_fence_fb_obj(c->primary->fb, |
16305 | c->primary->state->rotation); | |
e0d6149b TU |
16306 | mutex_unlock(&dev->struct_mutex); |
16307 | if (ret) { | |
484b41dd JB |
16308 | DRM_ERROR("failed to pin boot fb on pipe %d\n", |
16309 | to_intel_crtc(c)->pipe); | |
66e514c1 | 16310 | drm_framebuffer_unreference(c->primary->fb); |
5a21b665 | 16311 | c->primary->fb = NULL; |
36750f28 | 16312 | c->primary->crtc = c->primary->state->crtc = NULL; |
5a21b665 | 16313 | update_state_fb(c->primary); |
36750f28 | 16314 | c->state->plane_mask &= ~(1 << drm_plane_index(c->primary)); |
484b41dd JB |
16315 | } |
16316 | } | |
1ebaa0b9 CW |
16317 | } |
16318 | ||
16319 | int intel_connector_register(struct drm_connector *connector) | |
16320 | { | |
16321 | struct intel_connector *intel_connector = to_intel_connector(connector); | |
16322 | int ret; | |
16323 | ||
16324 | ret = intel_backlight_device_register(intel_connector); | |
16325 | if (ret) | |
16326 | goto err; | |
16327 | ||
16328 | return 0; | |
0962c3c9 | 16329 | |
1ebaa0b9 CW |
16330 | err: |
16331 | return ret; | |
79e53945 JB |
16332 | } |
16333 | ||
c191eca1 | 16334 | void intel_connector_unregister(struct drm_connector *connector) |
4932e2c3 | 16335 | { |
e63d87c0 | 16336 | struct intel_connector *intel_connector = to_intel_connector(connector); |
4932e2c3 | 16337 | |
e63d87c0 | 16338 | intel_backlight_device_unregister(intel_connector); |
4932e2c3 | 16339 | intel_panel_destroy_backlight(connector); |
4932e2c3 ID |
16340 | } |
16341 | ||
79e53945 JB |
16342 | void intel_modeset_cleanup(struct drm_device *dev) |
16343 | { | |
652c393a | 16344 | struct drm_i915_private *dev_priv = dev->dev_private; |
652c393a | 16345 | |
dc97997a | 16346 | intel_disable_gt_powersave(dev_priv); |
2eb5252e | 16347 | |
fd0c0642 DV |
16348 | /* |
16349 | * Interrupts and polling as the first thing to avoid creating havoc. | |
2eb5252e | 16350 | * Too much stuff here (turning of connectors, ...) would |
fd0c0642 DV |
16351 | * experience fancy races otherwise. |
16352 | */ | |
2aeb7d3a | 16353 | intel_irq_uninstall(dev_priv); |
eb21b92b | 16354 | |
fd0c0642 DV |
16355 | /* |
16356 | * Due to the hpd irq storm handling the hotplug work can re-arm the | |
16357 | * poll handlers. Hence disable polling after hpd handling is shut down. | |
16358 | */ | |
f87ea761 | 16359 | drm_kms_helper_poll_fini(dev); |
fd0c0642 | 16360 | |
723bfd70 JB |
16361 | intel_unregister_dsm_handler(); |
16362 | ||
c937ab3e | 16363 | intel_fbc_global_disable(dev_priv); |
69341a5e | 16364 | |
1630fe75 CW |
16365 | /* flush any delayed tasks or pending work */ |
16366 | flush_scheduled_work(); | |
16367 | ||
79e53945 | 16368 | drm_mode_config_cleanup(dev); |
4d7bb011 | 16369 | |
1ee8da6d | 16370 | intel_cleanup_overlay(dev_priv); |
ae48434c | 16371 | |
dc97997a | 16372 | intel_cleanup_gt_powersave(dev_priv); |
f5949141 DV |
16373 | |
16374 | intel_teardown_gmbus(dev); | |
79e53945 JB |
16375 | } |
16376 | ||
df0e9248 CW |
16377 | void intel_connector_attach_encoder(struct intel_connector *connector, |
16378 | struct intel_encoder *encoder) | |
16379 | { | |
16380 | connector->encoder = encoder; | |
16381 | drm_mode_connector_attach_encoder(&connector->base, | |
16382 | &encoder->base); | |
79e53945 | 16383 | } |
28d52043 DA |
16384 | |
16385 | /* | |
16386 | * set vga decode state - true == enable VGA decode | |
16387 | */ | |
16388 | int intel_modeset_vga_set_state(struct drm_device *dev, bool state) | |
16389 | { | |
16390 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a885b3cc | 16391 | unsigned reg = INTEL_INFO(dev)->gen >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL; |
28d52043 DA |
16392 | u16 gmch_ctrl; |
16393 | ||
75fa041d CW |
16394 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
16395 | DRM_ERROR("failed to read control word\n"); | |
16396 | return -EIO; | |
16397 | } | |
16398 | ||
c0cc8a55 CW |
16399 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
16400 | return 0; | |
16401 | ||
28d52043 DA |
16402 | if (state) |
16403 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; | |
16404 | else | |
16405 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; | |
75fa041d CW |
16406 | |
16407 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { | |
16408 | DRM_ERROR("failed to write control word\n"); | |
16409 | return -EIO; | |
16410 | } | |
16411 | ||
28d52043 DA |
16412 | return 0; |
16413 | } | |
c4a1d9e4 | 16414 | |
c4a1d9e4 | 16415 | struct intel_display_error_state { |
ff57f1b0 PZ |
16416 | |
16417 | u32 power_well_driver; | |
16418 | ||
63b66e5b CW |
16419 | int num_transcoders; |
16420 | ||
c4a1d9e4 CW |
16421 | struct intel_cursor_error_state { |
16422 | u32 control; | |
16423 | u32 position; | |
16424 | u32 base; | |
16425 | u32 size; | |
52331309 | 16426 | } cursor[I915_MAX_PIPES]; |
c4a1d9e4 CW |
16427 | |
16428 | struct intel_pipe_error_state { | |
ddf9c536 | 16429 | bool power_domain_on; |
c4a1d9e4 | 16430 | u32 source; |
f301b1e1 | 16431 | u32 stat; |
52331309 | 16432 | } pipe[I915_MAX_PIPES]; |
c4a1d9e4 CW |
16433 | |
16434 | struct intel_plane_error_state { | |
16435 | u32 control; | |
16436 | u32 stride; | |
16437 | u32 size; | |
16438 | u32 pos; | |
16439 | u32 addr; | |
16440 | u32 surface; | |
16441 | u32 tile_offset; | |
52331309 | 16442 | } plane[I915_MAX_PIPES]; |
63b66e5b CW |
16443 | |
16444 | struct intel_transcoder_error_state { | |
ddf9c536 | 16445 | bool power_domain_on; |
63b66e5b CW |
16446 | enum transcoder cpu_transcoder; |
16447 | ||
16448 | u32 conf; | |
16449 | ||
16450 | u32 htotal; | |
16451 | u32 hblank; | |
16452 | u32 hsync; | |
16453 | u32 vtotal; | |
16454 | u32 vblank; | |
16455 | u32 vsync; | |
16456 | } transcoder[4]; | |
c4a1d9e4 CW |
16457 | }; |
16458 | ||
16459 | struct intel_display_error_state * | |
c033666a | 16460 | intel_display_capture_error_state(struct drm_i915_private *dev_priv) |
c4a1d9e4 | 16461 | { |
c4a1d9e4 | 16462 | struct intel_display_error_state *error; |
63b66e5b CW |
16463 | int transcoders[] = { |
16464 | TRANSCODER_A, | |
16465 | TRANSCODER_B, | |
16466 | TRANSCODER_C, | |
16467 | TRANSCODER_EDP, | |
16468 | }; | |
c4a1d9e4 CW |
16469 | int i; |
16470 | ||
c033666a | 16471 | if (INTEL_INFO(dev_priv)->num_pipes == 0) |
63b66e5b CW |
16472 | return NULL; |
16473 | ||
9d1cb914 | 16474 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
c4a1d9e4 CW |
16475 | if (error == NULL) |
16476 | return NULL; | |
16477 | ||
c033666a | 16478 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
ff57f1b0 PZ |
16479 | error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER); |
16480 | ||
055e393f | 16481 | for_each_pipe(dev_priv, i) { |
ddf9c536 | 16482 | error->pipe[i].power_domain_on = |
f458ebbc DV |
16483 | __intel_display_power_is_enabled(dev_priv, |
16484 | POWER_DOMAIN_PIPE(i)); | |
ddf9c536 | 16485 | if (!error->pipe[i].power_domain_on) |
9d1cb914 PZ |
16486 | continue; |
16487 | ||
5efb3e28 VS |
16488 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
16489 | error->cursor[i].position = I915_READ(CURPOS(i)); | |
16490 | error->cursor[i].base = I915_READ(CURBASE(i)); | |
c4a1d9e4 CW |
16491 | |
16492 | error->plane[i].control = I915_READ(DSPCNTR(i)); | |
16493 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); | |
c033666a | 16494 | if (INTEL_GEN(dev_priv) <= 3) { |
51889b35 | 16495 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
80ca378b PZ |
16496 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
16497 | } | |
c033666a | 16498 | if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv)) |
ca291363 | 16499 | error->plane[i].addr = I915_READ(DSPADDR(i)); |
c033666a | 16500 | if (INTEL_GEN(dev_priv) >= 4) { |
c4a1d9e4 CW |
16501 | error->plane[i].surface = I915_READ(DSPSURF(i)); |
16502 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); | |
16503 | } | |
16504 | ||
c4a1d9e4 | 16505 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
f301b1e1 | 16506 | |
c033666a | 16507 | if (HAS_GMCH_DISPLAY(dev_priv)) |
f301b1e1 | 16508 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
63b66e5b CW |
16509 | } |
16510 | ||
4d1de975 | 16511 | /* Note: this does not include DSI transcoders. */ |
c033666a | 16512 | error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes; |
2d1fe073 | 16513 | if (HAS_DDI(dev_priv)) |
63b66e5b CW |
16514 | error->num_transcoders++; /* Account for eDP. */ |
16515 | ||
16516 | for (i = 0; i < error->num_transcoders; i++) { | |
16517 | enum transcoder cpu_transcoder = transcoders[i]; | |
16518 | ||
ddf9c536 | 16519 | error->transcoder[i].power_domain_on = |
f458ebbc | 16520 | __intel_display_power_is_enabled(dev_priv, |
38cc1daf | 16521 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
ddf9c536 | 16522 | if (!error->transcoder[i].power_domain_on) |
9d1cb914 PZ |
16523 | continue; |
16524 | ||
63b66e5b CW |
16525 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
16526 | ||
16527 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); | |
16528 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); | |
16529 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); | |
16530 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); | |
16531 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); | |
16532 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); | |
16533 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); | |
c4a1d9e4 CW |
16534 | } |
16535 | ||
16536 | return error; | |
16537 | } | |
16538 | ||
edc3d884 MK |
16539 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
16540 | ||
c4a1d9e4 | 16541 | void |
edc3d884 | 16542 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
c4a1d9e4 CW |
16543 | struct drm_device *dev, |
16544 | struct intel_display_error_state *error) | |
16545 | { | |
055e393f | 16546 | struct drm_i915_private *dev_priv = dev->dev_private; |
c4a1d9e4 CW |
16547 | int i; |
16548 | ||
63b66e5b CW |
16549 | if (!error) |
16550 | return; | |
16551 | ||
edc3d884 | 16552 | err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes); |
190be112 | 16553 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
edc3d884 | 16554 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
ff57f1b0 | 16555 | error->power_well_driver); |
055e393f | 16556 | for_each_pipe(dev_priv, i) { |
edc3d884 | 16557 | err_printf(m, "Pipe [%d]:\n", i); |
ddf9c536 | 16558 | err_printf(m, " Power: %s\n", |
87ad3212 | 16559 | onoff(error->pipe[i].power_domain_on)); |
edc3d884 | 16560 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
f301b1e1 | 16561 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
edc3d884 MK |
16562 | |
16563 | err_printf(m, "Plane [%d]:\n", i); | |
16564 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); | |
16565 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); | |
80ca378b | 16566 | if (INTEL_INFO(dev)->gen <= 3) { |
edc3d884 MK |
16567 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
16568 | err_printf(m, " POS: %08x\n", error->plane[i].pos); | |
80ca378b | 16569 | } |
4b71a570 | 16570 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
edc3d884 | 16571 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
c4a1d9e4 | 16572 | if (INTEL_INFO(dev)->gen >= 4) { |
edc3d884 MK |
16573 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
16574 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); | |
c4a1d9e4 CW |
16575 | } |
16576 | ||
edc3d884 MK |
16577 | err_printf(m, "Cursor [%d]:\n", i); |
16578 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); | |
16579 | err_printf(m, " POS: %08x\n", error->cursor[i].position); | |
16580 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); | |
c4a1d9e4 | 16581 | } |
63b66e5b CW |
16582 | |
16583 | for (i = 0; i < error->num_transcoders; i++) { | |
da205630 | 16584 | err_printf(m, "CPU transcoder: %s\n", |
63b66e5b | 16585 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
ddf9c536 | 16586 | err_printf(m, " Power: %s\n", |
87ad3212 | 16587 | onoff(error->transcoder[i].power_domain_on)); |
63b66e5b CW |
16588 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
16589 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); | |
16590 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); | |
16591 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); | |
16592 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); | |
16593 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); | |
16594 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); | |
16595 | } | |
c4a1d9e4 | 16596 | } |