]>
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" |
5d723d7a | 37 | #include "intel_frontbuffer.h" |
760285e7 | 38 | #include <drm/i915_drm.h> |
79e53945 | 39 | #include "i915_drv.h" |
57822dc6 | 40 | #include "i915_gem_clflush.h" |
db18b6a6 | 41 | #include "intel_dsi.h" |
e5510fac | 42 | #include "i915_trace.h" |
319c1d42 | 43 | #include <drm/drm_atomic.h> |
c196e1d6 | 44 | #include <drm/drm_atomic_helper.h> |
760285e7 DH |
45 | #include <drm/drm_dp_helper.h> |
46 | #include <drm/drm_crtc_helper.h> | |
465c120c MR |
47 | #include <drm/drm_plane_helper.h> |
48 | #include <drm/drm_rect.h> | |
c0f372b3 | 49 | #include <linux/dma_remapping.h> |
fd8e058a | 50 | #include <linux/reservation.h> |
79e53945 | 51 | |
465c120c | 52 | /* Primary plane formats for gen <= 3 */ |
568db4f2 | 53 | static const uint32_t i8xx_primary_formats[] = { |
67fe7dc5 DL |
54 | DRM_FORMAT_C8, |
55 | DRM_FORMAT_RGB565, | |
465c120c | 56 | DRM_FORMAT_XRGB1555, |
67fe7dc5 | 57 | DRM_FORMAT_XRGB8888, |
465c120c MR |
58 | }; |
59 | ||
60 | /* Primary plane formats for gen >= 4 */ | |
568db4f2 | 61 | static const uint32_t i965_primary_formats[] = { |
6c0fd451 DL |
62 | DRM_FORMAT_C8, |
63 | DRM_FORMAT_RGB565, | |
64 | DRM_FORMAT_XRGB8888, | |
65 | DRM_FORMAT_XBGR8888, | |
66 | DRM_FORMAT_XRGB2101010, | |
67 | DRM_FORMAT_XBGR2101010, | |
68 | }; | |
69 | ||
714244e2 BW |
70 | static const uint64_t i9xx_format_modifiers[] = { |
71 | I915_FORMAT_MOD_X_TILED, | |
72 | DRM_FORMAT_MOD_LINEAR, | |
73 | DRM_FORMAT_MOD_INVALID | |
74 | }; | |
75 | ||
6c0fd451 | 76 | static const uint32_t skl_primary_formats[] = { |
67fe7dc5 DL |
77 | DRM_FORMAT_C8, |
78 | DRM_FORMAT_RGB565, | |
79 | DRM_FORMAT_XRGB8888, | |
465c120c | 80 | DRM_FORMAT_XBGR8888, |
67fe7dc5 | 81 | DRM_FORMAT_ARGB8888, |
465c120c MR |
82 | DRM_FORMAT_ABGR8888, |
83 | DRM_FORMAT_XRGB2101010, | |
465c120c | 84 | DRM_FORMAT_XBGR2101010, |
ea916ea0 KM |
85 | DRM_FORMAT_YUYV, |
86 | DRM_FORMAT_YVYU, | |
87 | DRM_FORMAT_UYVY, | |
88 | DRM_FORMAT_VYUY, | |
465c120c MR |
89 | }; |
90 | ||
714244e2 BW |
91 | static const uint64_t skl_format_modifiers_noccs[] = { |
92 | I915_FORMAT_MOD_Yf_TILED, | |
93 | I915_FORMAT_MOD_Y_TILED, | |
94 | I915_FORMAT_MOD_X_TILED, | |
95 | DRM_FORMAT_MOD_LINEAR, | |
96 | DRM_FORMAT_MOD_INVALID | |
97 | }; | |
98 | ||
99 | static const uint64_t skl_format_modifiers_ccs[] = { | |
100 | I915_FORMAT_MOD_Yf_TILED_CCS, | |
101 | I915_FORMAT_MOD_Y_TILED_CCS, | |
102 | I915_FORMAT_MOD_Yf_TILED, | |
103 | I915_FORMAT_MOD_Y_TILED, | |
104 | I915_FORMAT_MOD_X_TILED, | |
105 | DRM_FORMAT_MOD_LINEAR, | |
106 | DRM_FORMAT_MOD_INVALID | |
107 | }; | |
108 | ||
3d7d6510 MR |
109 | /* Cursor formats */ |
110 | static const uint32_t intel_cursor_formats[] = { | |
111 | DRM_FORMAT_ARGB8888, | |
112 | }; | |
113 | ||
714244e2 BW |
114 | static const uint64_t cursor_format_modifiers[] = { |
115 | DRM_FORMAT_MOD_LINEAR, | |
116 | DRM_FORMAT_MOD_INVALID | |
117 | }; | |
118 | ||
f1f644dc | 119 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 120 | struct intel_crtc_state *pipe_config); |
18442d08 | 121 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
5cec258b | 122 | struct intel_crtc_state *pipe_config); |
f1f644dc | 123 | |
24dbf51a CW |
124 | static int intel_framebuffer_init(struct intel_framebuffer *ifb, |
125 | struct drm_i915_gem_object *obj, | |
126 | struct drm_mode_fb_cmd2 *mode_cmd); | |
5b18e57c DV |
127 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc); |
128 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc); | |
bc58be60 | 129 | static void intel_set_pipe_src_size(struct intel_crtc *intel_crtc); |
29407aab | 130 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
f769cd24 VK |
131 | struct intel_link_m_n *m_n, |
132 | struct intel_link_m_n *m2_n2); | |
29407aab | 133 | static void ironlake_set_pipeconf(struct drm_crtc *crtc); |
229fca97 | 134 | static void haswell_set_pipeconf(struct drm_crtc *crtc); |
391bf048 | 135 | static void haswell_set_pipemisc(struct drm_crtc *crtc); |
d288f65f | 136 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 137 | const struct intel_crtc_state *pipe_config); |
d288f65f | 138 | static void chv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 139 | const struct intel_crtc_state *pipe_config); |
5a21b665 DV |
140 | static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *); |
141 | static void intel_finish_crtc_commit(struct drm_crtc *, struct drm_crtc_state *); | |
1c74eeaf NM |
142 | static void intel_crtc_init_scalers(struct intel_crtc *crtc, |
143 | struct intel_crtc_state *crtc_state); | |
bfd16b2a ML |
144 | static void skylake_pfit_enable(struct intel_crtc *crtc); |
145 | static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force); | |
146 | static void ironlake_pfit_enable(struct intel_crtc *crtc); | |
aecd36b8 VS |
147 | static void intel_modeset_setup_hw_state(struct drm_device *dev, |
148 | struct drm_modeset_acquire_ctx *ctx); | |
2622a081 | 149 | static void intel_pre_disable_primary_noatomic(struct drm_crtc *crtc); |
e7457a9a | 150 | |
d4906093 | 151 | struct intel_limit { |
4c5def93 ACO |
152 | struct { |
153 | int min, max; | |
154 | } dot, vco, n, m, m1, m2, p, p1; | |
155 | ||
156 | struct { | |
157 | int dot_limit; | |
158 | int p2_slow, p2_fast; | |
159 | } p2; | |
d4906093 | 160 | }; |
79e53945 | 161 | |
bfa7df01 | 162 | /* returns HPLL frequency in kHz */ |
49cd97a3 | 163 | int vlv_get_hpll_vco(struct drm_i915_private *dev_priv) |
bfa7df01 VS |
164 | { |
165 | int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; | |
166 | ||
167 | /* Obtain SKU information */ | |
168 | mutex_lock(&dev_priv->sb_lock); | |
169 | hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & | |
170 | CCK_FUSE_HPLL_FREQ_MASK; | |
171 | mutex_unlock(&dev_priv->sb_lock); | |
172 | ||
173 | return vco_freq[hpll_freq] * 1000; | |
174 | } | |
175 | ||
c30fec65 VS |
176 | int vlv_get_cck_clock(struct drm_i915_private *dev_priv, |
177 | const char *name, u32 reg, int ref_freq) | |
bfa7df01 VS |
178 | { |
179 | u32 val; | |
180 | int divider; | |
181 | ||
bfa7df01 VS |
182 | mutex_lock(&dev_priv->sb_lock); |
183 | val = vlv_cck_read(dev_priv, reg); | |
184 | mutex_unlock(&dev_priv->sb_lock); | |
185 | ||
186 | divider = val & CCK_FREQUENCY_VALUES; | |
187 | ||
188 | WARN((val & CCK_FREQUENCY_STATUS) != | |
189 | (divider << CCK_FREQUENCY_STATUS_SHIFT), | |
190 | "%s change in progress\n", name); | |
191 | ||
c30fec65 VS |
192 | return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1); |
193 | } | |
194 | ||
7ff89ca2 VS |
195 | int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv, |
196 | const char *name, u32 reg) | |
c30fec65 VS |
197 | { |
198 | if (dev_priv->hpll_freq == 0) | |
49cd97a3 | 199 | dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv); |
c30fec65 VS |
200 | |
201 | return vlv_get_cck_clock(dev_priv, name, reg, | |
202 | dev_priv->hpll_freq); | |
bfa7df01 VS |
203 | } |
204 | ||
bfa7df01 VS |
205 | static void intel_update_czclk(struct drm_i915_private *dev_priv) |
206 | { | |
666a4537 | 207 | if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))) |
bfa7df01 VS |
208 | return; |
209 | ||
210 | dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk", | |
211 | CCK_CZ_CLOCK_CONTROL); | |
212 | ||
213 | DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq); | |
214 | } | |
215 | ||
021357ac | 216 | static inline u32 /* units of 100MHz */ |
21a727b3 VS |
217 | intel_fdi_link_freq(struct drm_i915_private *dev_priv, |
218 | const struct intel_crtc_state *pipe_config) | |
021357ac | 219 | { |
21a727b3 VS |
220 | if (HAS_DDI(dev_priv)) |
221 | return pipe_config->port_clock; /* SPLL */ | |
222 | else if (IS_GEN5(dev_priv)) | |
223 | return ((I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2) * 10000; | |
e3b247da | 224 | else |
21a727b3 | 225 | return 270000; |
021357ac CW |
226 | } |
227 | ||
1b6f4958 | 228 | static const struct intel_limit intel_limits_i8xx_dac = { |
0206e353 | 229 | .dot = { .min = 25000, .max = 350000 }, |
9c333719 | 230 | .vco = { .min = 908000, .max = 1512000 }, |
91dbe5fb | 231 | .n = { .min = 2, .max = 16 }, |
0206e353 AJ |
232 | .m = { .min = 96, .max = 140 }, |
233 | .m1 = { .min = 18, .max = 26 }, | |
234 | .m2 = { .min = 6, .max = 16 }, | |
235 | .p = { .min = 4, .max = 128 }, | |
236 | .p1 = { .min = 2, .max = 33 }, | |
273e27ca EA |
237 | .p2 = { .dot_limit = 165000, |
238 | .p2_slow = 4, .p2_fast = 2 }, | |
e4b36699 KP |
239 | }; |
240 | ||
1b6f4958 | 241 | static const struct intel_limit intel_limits_i8xx_dvo = { |
5d536e28 | 242 | .dot = { .min = 25000, .max = 350000 }, |
9c333719 | 243 | .vco = { .min = 908000, .max = 1512000 }, |
91dbe5fb | 244 | .n = { .min = 2, .max = 16 }, |
5d536e28 DV |
245 | .m = { .min = 96, .max = 140 }, |
246 | .m1 = { .min = 18, .max = 26 }, | |
247 | .m2 = { .min = 6, .max = 16 }, | |
248 | .p = { .min = 4, .max = 128 }, | |
249 | .p1 = { .min = 2, .max = 33 }, | |
250 | .p2 = { .dot_limit = 165000, | |
251 | .p2_slow = 4, .p2_fast = 4 }, | |
252 | }; | |
253 | ||
1b6f4958 | 254 | static const struct intel_limit intel_limits_i8xx_lvds = { |
0206e353 | 255 | .dot = { .min = 25000, .max = 350000 }, |
9c333719 | 256 | .vco = { .min = 908000, .max = 1512000 }, |
91dbe5fb | 257 | .n = { .min = 2, .max = 16 }, |
0206e353 AJ |
258 | .m = { .min = 96, .max = 140 }, |
259 | .m1 = { .min = 18, .max = 26 }, | |
260 | .m2 = { .min = 6, .max = 16 }, | |
261 | .p = { .min = 4, .max = 128 }, | |
262 | .p1 = { .min = 1, .max = 6 }, | |
273e27ca EA |
263 | .p2 = { .dot_limit = 165000, |
264 | .p2_slow = 14, .p2_fast = 7 }, | |
e4b36699 | 265 | }; |
273e27ca | 266 | |
1b6f4958 | 267 | static const struct intel_limit intel_limits_i9xx_sdvo = { |
0206e353 AJ |
268 | .dot = { .min = 20000, .max = 400000 }, |
269 | .vco = { .min = 1400000, .max = 2800000 }, | |
270 | .n = { .min = 1, .max = 6 }, | |
271 | .m = { .min = 70, .max = 120 }, | |
4f7dfb67 PJ |
272 | .m1 = { .min = 8, .max = 18 }, |
273 | .m2 = { .min = 3, .max = 7 }, | |
0206e353 AJ |
274 | .p = { .min = 5, .max = 80 }, |
275 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
276 | .p2 = { .dot_limit = 200000, |
277 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
278 | }; |
279 | ||
1b6f4958 | 280 | static const struct intel_limit intel_limits_i9xx_lvds = { |
0206e353 AJ |
281 | .dot = { .min = 20000, .max = 400000 }, |
282 | .vco = { .min = 1400000, .max = 2800000 }, | |
283 | .n = { .min = 1, .max = 6 }, | |
284 | .m = { .min = 70, .max = 120 }, | |
53a7d2d1 PJ |
285 | .m1 = { .min = 8, .max = 18 }, |
286 | .m2 = { .min = 3, .max = 7 }, | |
0206e353 AJ |
287 | .p = { .min = 7, .max = 98 }, |
288 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
289 | .p2 = { .dot_limit = 112000, |
290 | .p2_slow = 14, .p2_fast = 7 }, | |
e4b36699 KP |
291 | }; |
292 | ||
273e27ca | 293 | |
1b6f4958 | 294 | static const struct intel_limit intel_limits_g4x_sdvo = { |
273e27ca EA |
295 | .dot = { .min = 25000, .max = 270000 }, |
296 | .vco = { .min = 1750000, .max = 3500000}, | |
297 | .n = { .min = 1, .max = 4 }, | |
298 | .m = { .min = 104, .max = 138 }, | |
299 | .m1 = { .min = 17, .max = 23 }, | |
300 | .m2 = { .min = 5, .max = 11 }, | |
301 | .p = { .min = 10, .max = 30 }, | |
302 | .p1 = { .min = 1, .max = 3}, | |
303 | .p2 = { .dot_limit = 270000, | |
304 | .p2_slow = 10, | |
305 | .p2_fast = 10 | |
044c7c41 | 306 | }, |
e4b36699 KP |
307 | }; |
308 | ||
1b6f4958 | 309 | static const struct intel_limit intel_limits_g4x_hdmi = { |
273e27ca EA |
310 | .dot = { .min = 22000, .max = 400000 }, |
311 | .vco = { .min = 1750000, .max = 3500000}, | |
312 | .n = { .min = 1, .max = 4 }, | |
313 | .m = { .min = 104, .max = 138 }, | |
314 | .m1 = { .min = 16, .max = 23 }, | |
315 | .m2 = { .min = 5, .max = 11 }, | |
316 | .p = { .min = 5, .max = 80 }, | |
317 | .p1 = { .min = 1, .max = 8}, | |
318 | .p2 = { .dot_limit = 165000, | |
319 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
320 | }; |
321 | ||
1b6f4958 | 322 | static const struct intel_limit intel_limits_g4x_single_channel_lvds = { |
273e27ca EA |
323 | .dot = { .min = 20000, .max = 115000 }, |
324 | .vco = { .min = 1750000, .max = 3500000 }, | |
325 | .n = { .min = 1, .max = 3 }, | |
326 | .m = { .min = 104, .max = 138 }, | |
327 | .m1 = { .min = 17, .max = 23 }, | |
328 | .m2 = { .min = 5, .max = 11 }, | |
329 | .p = { .min = 28, .max = 112 }, | |
330 | .p1 = { .min = 2, .max = 8 }, | |
331 | .p2 = { .dot_limit = 0, | |
332 | .p2_slow = 14, .p2_fast = 14 | |
044c7c41 | 333 | }, |
e4b36699 KP |
334 | }; |
335 | ||
1b6f4958 | 336 | static const struct intel_limit intel_limits_g4x_dual_channel_lvds = { |
273e27ca EA |
337 | .dot = { .min = 80000, .max = 224000 }, |
338 | .vco = { .min = 1750000, .max = 3500000 }, | |
339 | .n = { .min = 1, .max = 3 }, | |
340 | .m = { .min = 104, .max = 138 }, | |
341 | .m1 = { .min = 17, .max = 23 }, | |
342 | .m2 = { .min = 5, .max = 11 }, | |
343 | .p = { .min = 14, .max = 42 }, | |
344 | .p1 = { .min = 2, .max = 6 }, | |
345 | .p2 = { .dot_limit = 0, | |
346 | .p2_slow = 7, .p2_fast = 7 | |
044c7c41 | 347 | }, |
e4b36699 KP |
348 | }; |
349 | ||
1b6f4958 | 350 | static const struct intel_limit intel_limits_pineview_sdvo = { |
0206e353 AJ |
351 | .dot = { .min = 20000, .max = 400000}, |
352 | .vco = { .min = 1700000, .max = 3500000 }, | |
273e27ca | 353 | /* Pineview's Ncounter is a ring counter */ |
0206e353 AJ |
354 | .n = { .min = 3, .max = 6 }, |
355 | .m = { .min = 2, .max = 256 }, | |
273e27ca | 356 | /* Pineview only has one combined m divider, which we treat as m2. */ |
0206e353 AJ |
357 | .m1 = { .min = 0, .max = 0 }, |
358 | .m2 = { .min = 0, .max = 254 }, | |
359 | .p = { .min = 5, .max = 80 }, | |
360 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
361 | .p2 = { .dot_limit = 200000, |
362 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
363 | }; |
364 | ||
1b6f4958 | 365 | static const struct intel_limit intel_limits_pineview_lvds = { |
0206e353 AJ |
366 | .dot = { .min = 20000, .max = 400000 }, |
367 | .vco = { .min = 1700000, .max = 3500000 }, | |
368 | .n = { .min = 3, .max = 6 }, | |
369 | .m = { .min = 2, .max = 256 }, | |
370 | .m1 = { .min = 0, .max = 0 }, | |
371 | .m2 = { .min = 0, .max = 254 }, | |
372 | .p = { .min = 7, .max = 112 }, | |
373 | .p1 = { .min = 1, .max = 8 }, | |
273e27ca EA |
374 | .p2 = { .dot_limit = 112000, |
375 | .p2_slow = 14, .p2_fast = 14 }, | |
e4b36699 KP |
376 | }; |
377 | ||
273e27ca EA |
378 | /* Ironlake / Sandybridge |
379 | * | |
380 | * We calculate clock using (register_value + 2) for N/M1/M2, so here | |
381 | * the range value for them is (actual_value - 2). | |
382 | */ | |
1b6f4958 | 383 | static const struct intel_limit intel_limits_ironlake_dac = { |
273e27ca EA |
384 | .dot = { .min = 25000, .max = 350000 }, |
385 | .vco = { .min = 1760000, .max = 3510000 }, | |
386 | .n = { .min = 1, .max = 5 }, | |
387 | .m = { .min = 79, .max = 127 }, | |
388 | .m1 = { .min = 12, .max = 22 }, | |
389 | .m2 = { .min = 5, .max = 9 }, | |
390 | .p = { .min = 5, .max = 80 }, | |
391 | .p1 = { .min = 1, .max = 8 }, | |
392 | .p2 = { .dot_limit = 225000, | |
393 | .p2_slow = 10, .p2_fast = 5 }, | |
e4b36699 KP |
394 | }; |
395 | ||
1b6f4958 | 396 | static const struct intel_limit intel_limits_ironlake_single_lvds = { |
273e27ca EA |
397 | .dot = { .min = 25000, .max = 350000 }, |
398 | .vco = { .min = 1760000, .max = 3510000 }, | |
399 | .n = { .min = 1, .max = 3 }, | |
400 | .m = { .min = 79, .max = 118 }, | |
401 | .m1 = { .min = 12, .max = 22 }, | |
402 | .m2 = { .min = 5, .max = 9 }, | |
403 | .p = { .min = 28, .max = 112 }, | |
404 | .p1 = { .min = 2, .max = 8 }, | |
405 | .p2 = { .dot_limit = 225000, | |
406 | .p2_slow = 14, .p2_fast = 14 }, | |
b91ad0ec ZW |
407 | }; |
408 | ||
1b6f4958 | 409 | static const struct intel_limit intel_limits_ironlake_dual_lvds = { |
273e27ca EA |
410 | .dot = { .min = 25000, .max = 350000 }, |
411 | .vco = { .min = 1760000, .max = 3510000 }, | |
412 | .n = { .min = 1, .max = 3 }, | |
413 | .m = { .min = 79, .max = 127 }, | |
414 | .m1 = { .min = 12, .max = 22 }, | |
415 | .m2 = { .min = 5, .max = 9 }, | |
416 | .p = { .min = 14, .max = 56 }, | |
417 | .p1 = { .min = 2, .max = 8 }, | |
418 | .p2 = { .dot_limit = 225000, | |
419 | .p2_slow = 7, .p2_fast = 7 }, | |
b91ad0ec ZW |
420 | }; |
421 | ||
273e27ca | 422 | /* LVDS 100mhz refclk limits. */ |
1b6f4958 | 423 | static const struct intel_limit intel_limits_ironlake_single_lvds_100m = { |
273e27ca EA |
424 | .dot = { .min = 25000, .max = 350000 }, |
425 | .vco = { .min = 1760000, .max = 3510000 }, | |
426 | .n = { .min = 1, .max = 2 }, | |
427 | .m = { .min = 79, .max = 126 }, | |
428 | .m1 = { .min = 12, .max = 22 }, | |
429 | .m2 = { .min = 5, .max = 9 }, | |
430 | .p = { .min = 28, .max = 112 }, | |
0206e353 | 431 | .p1 = { .min = 2, .max = 8 }, |
273e27ca EA |
432 | .p2 = { .dot_limit = 225000, |
433 | .p2_slow = 14, .p2_fast = 14 }, | |
b91ad0ec ZW |
434 | }; |
435 | ||
1b6f4958 | 436 | static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = { |
273e27ca EA |
437 | .dot = { .min = 25000, .max = 350000 }, |
438 | .vco = { .min = 1760000, .max = 3510000 }, | |
439 | .n = { .min = 1, .max = 3 }, | |
440 | .m = { .min = 79, .max = 126 }, | |
441 | .m1 = { .min = 12, .max = 22 }, | |
442 | .m2 = { .min = 5, .max = 9 }, | |
443 | .p = { .min = 14, .max = 42 }, | |
0206e353 | 444 | .p1 = { .min = 2, .max = 6 }, |
273e27ca EA |
445 | .p2 = { .dot_limit = 225000, |
446 | .p2_slow = 7, .p2_fast = 7 }, | |
4547668a ZY |
447 | }; |
448 | ||
1b6f4958 | 449 | static const struct intel_limit intel_limits_vlv = { |
f01b7962 VS |
450 | /* |
451 | * These are the data rate limits (measured in fast clocks) | |
452 | * since those are the strictest limits we have. The fast | |
453 | * clock and actual rate limits are more relaxed, so checking | |
454 | * them would make no difference. | |
455 | */ | |
456 | .dot = { .min = 25000 * 5, .max = 270000 * 5 }, | |
75e53986 | 457 | .vco = { .min = 4000000, .max = 6000000 }, |
a0c4da24 | 458 | .n = { .min = 1, .max = 7 }, |
a0c4da24 JB |
459 | .m1 = { .min = 2, .max = 3 }, |
460 | .m2 = { .min = 11, .max = 156 }, | |
b99ab663 | 461 | .p1 = { .min = 2, .max = 3 }, |
5fdc9c49 | 462 | .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */ |
a0c4da24 JB |
463 | }; |
464 | ||
1b6f4958 | 465 | static const struct intel_limit intel_limits_chv = { |
ef9348c8 CML |
466 | /* |
467 | * These are the data rate limits (measured in fast clocks) | |
468 | * since those are the strictest limits we have. The fast | |
469 | * clock and actual rate limits are more relaxed, so checking | |
470 | * them would make no difference. | |
471 | */ | |
472 | .dot = { .min = 25000 * 5, .max = 540000 * 5}, | |
17fe1021 | 473 | .vco = { .min = 4800000, .max = 6480000 }, |
ef9348c8 CML |
474 | .n = { .min = 1, .max = 1 }, |
475 | .m1 = { .min = 2, .max = 2 }, | |
476 | .m2 = { .min = 24 << 22, .max = 175 << 22 }, | |
477 | .p1 = { .min = 2, .max = 4 }, | |
478 | .p2 = { .p2_slow = 1, .p2_fast = 14 }, | |
479 | }; | |
480 | ||
1b6f4958 | 481 | static const struct intel_limit intel_limits_bxt = { |
5ab7b0b7 ID |
482 | /* FIXME: find real dot limits */ |
483 | .dot = { .min = 0, .max = INT_MAX }, | |
e6292556 | 484 | .vco = { .min = 4800000, .max = 6700000 }, |
5ab7b0b7 ID |
485 | .n = { .min = 1, .max = 1 }, |
486 | .m1 = { .min = 2, .max = 2 }, | |
487 | /* FIXME: find real m2 limits */ | |
488 | .m2 = { .min = 2 << 22, .max = 255 << 22 }, | |
489 | .p1 = { .min = 2, .max = 4 }, | |
490 | .p2 = { .p2_slow = 1, .p2_fast = 20 }, | |
491 | }; | |
492 | ||
cdba954e ACO |
493 | static bool |
494 | needs_modeset(struct drm_crtc_state *state) | |
495 | { | |
fc596660 | 496 | return drm_atomic_crtc_needs_modeset(state); |
cdba954e ACO |
497 | } |
498 | ||
dccbea3b ID |
499 | /* |
500 | * Platform specific helpers to calculate the port PLL loopback- (clock.m), | |
501 | * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast | |
502 | * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic. | |
503 | * The helpers' return value is the rate of the clock that is fed to the | |
504 | * display engine's pipe which can be the above fast dot clock rate or a | |
505 | * divided-down version of it. | |
506 | */ | |
f2b115e6 | 507 | /* m1 is reserved as 0 in Pineview, n is a ring counter */ |
9e2c8475 | 508 | static int pnv_calc_dpll_params(int refclk, struct dpll *clock) |
79e53945 | 509 | { |
2177832f SL |
510 | clock->m = clock->m2 + 2; |
511 | clock->p = clock->p1 * clock->p2; | |
ed5ca77e | 512 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
dccbea3b | 513 | return 0; |
fb03ac01 VS |
514 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
515 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
dccbea3b ID |
516 | |
517 | return clock->dot; | |
2177832f SL |
518 | } |
519 | ||
7429e9d4 DV |
520 | static uint32_t i9xx_dpll_compute_m(struct dpll *dpll) |
521 | { | |
522 | return 5 * (dpll->m1 + 2) + (dpll->m2 + 2); | |
523 | } | |
524 | ||
9e2c8475 | 525 | static int i9xx_calc_dpll_params(int refclk, struct dpll *clock) |
2177832f | 526 | { |
7429e9d4 | 527 | clock->m = i9xx_dpll_compute_m(clock); |
79e53945 | 528 | clock->p = clock->p1 * clock->p2; |
ed5ca77e | 529 | if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) |
dccbea3b | 530 | return 0; |
fb03ac01 VS |
531 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2); |
532 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
dccbea3b ID |
533 | |
534 | return clock->dot; | |
79e53945 JB |
535 | } |
536 | ||
9e2c8475 | 537 | static int vlv_calc_dpll_params(int refclk, struct dpll *clock) |
589eca67 ID |
538 | { |
539 | clock->m = clock->m1 * clock->m2; | |
540 | clock->p = clock->p1 * clock->p2; | |
541 | if (WARN_ON(clock->n == 0 || clock->p == 0)) | |
dccbea3b | 542 | return 0; |
589eca67 ID |
543 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
544 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
dccbea3b ID |
545 | |
546 | return clock->dot / 5; | |
589eca67 ID |
547 | } |
548 | ||
9e2c8475 | 549 | int chv_calc_dpll_params(int refclk, struct dpll *clock) |
ef9348c8 CML |
550 | { |
551 | clock->m = clock->m1 * clock->m2; | |
552 | clock->p = clock->p1 * clock->p2; | |
553 | if (WARN_ON(clock->n == 0 || clock->p == 0)) | |
dccbea3b | 554 | return 0; |
ef9348c8 CML |
555 | clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m, |
556 | clock->n << 22); | |
557 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); | |
dccbea3b ID |
558 | |
559 | return clock->dot / 5; | |
ef9348c8 CML |
560 | } |
561 | ||
7c04d1d9 | 562 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
79e53945 JB |
563 | /** |
564 | * Returns whether the given set of divisors are valid for a given refclk with | |
565 | * the given connectors. | |
566 | */ | |
567 | ||
e2d214ae | 568 | static bool intel_PLL_is_valid(struct drm_i915_private *dev_priv, |
1b6f4958 | 569 | const struct intel_limit *limit, |
9e2c8475 | 570 | const struct dpll *clock) |
79e53945 | 571 | { |
f01b7962 VS |
572 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
573 | INTELPllInvalid("n out of range\n"); | |
79e53945 | 574 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
0206e353 | 575 | INTELPllInvalid("p1 out of range\n"); |
79e53945 | 576 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
0206e353 | 577 | INTELPllInvalid("m2 out of range\n"); |
79e53945 | 578 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
0206e353 | 579 | INTELPllInvalid("m1 out of range\n"); |
f01b7962 | 580 | |
e2d214ae | 581 | if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) && |
cc3f90f0 | 582 | !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv)) |
f01b7962 VS |
583 | if (clock->m1 <= clock->m2) |
584 | INTELPllInvalid("m1 <= m2\n"); | |
585 | ||
e2d214ae | 586 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) && |
cc3f90f0 | 587 | !IS_GEN9_LP(dev_priv)) { |
f01b7962 VS |
588 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
589 | INTELPllInvalid("p out of range\n"); | |
590 | if (clock->m < limit->m.min || limit->m.max < clock->m) | |
591 | INTELPllInvalid("m out of range\n"); | |
592 | } | |
593 | ||
79e53945 | 594 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
0206e353 | 595 | INTELPllInvalid("vco out of range\n"); |
79e53945 JB |
596 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
597 | * connector, etc., rather than just a single range. | |
598 | */ | |
599 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) | |
0206e353 | 600 | INTELPllInvalid("dot out of range\n"); |
79e53945 JB |
601 | |
602 | return true; | |
603 | } | |
604 | ||
3b1429d9 | 605 | static int |
1b6f4958 | 606 | i9xx_select_p2_div(const struct intel_limit *limit, |
3b1429d9 VS |
607 | const struct intel_crtc_state *crtc_state, |
608 | int target) | |
79e53945 | 609 | { |
3b1429d9 | 610 | struct drm_device *dev = crtc_state->base.crtc->dev; |
79e53945 | 611 | |
2d84d2b3 | 612 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
79e53945 | 613 | /* |
a210b028 DV |
614 | * For LVDS just rely on its current settings for dual-channel. |
615 | * We haven't figured out how to reliably set up different | |
616 | * single/dual channel state, if we even can. | |
79e53945 | 617 | */ |
1974cad0 | 618 | if (intel_is_dual_link_lvds(dev)) |
3b1429d9 | 619 | return limit->p2.p2_fast; |
79e53945 | 620 | else |
3b1429d9 | 621 | return limit->p2.p2_slow; |
79e53945 JB |
622 | } else { |
623 | if (target < limit->p2.dot_limit) | |
3b1429d9 | 624 | return limit->p2.p2_slow; |
79e53945 | 625 | else |
3b1429d9 | 626 | return limit->p2.p2_fast; |
79e53945 | 627 | } |
3b1429d9 VS |
628 | } |
629 | ||
70e8aa21 ACO |
630 | /* |
631 | * Returns a set of divisors for the desired target clock with the given | |
632 | * refclk, or FALSE. The returned values represent the clock equation: | |
633 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. | |
634 | * | |
635 | * Target and reference clocks are specified in kHz. | |
636 | * | |
637 | * If match_clock is provided, then best_clock P divider must match the P | |
638 | * divider from @match_clock used for LVDS downclocking. | |
639 | */ | |
3b1429d9 | 640 | static bool |
1b6f4958 | 641 | i9xx_find_best_dpll(const struct intel_limit *limit, |
3b1429d9 | 642 | struct intel_crtc_state *crtc_state, |
9e2c8475 ACO |
643 | int target, int refclk, struct dpll *match_clock, |
644 | struct dpll *best_clock) | |
3b1429d9 VS |
645 | { |
646 | struct drm_device *dev = crtc_state->base.crtc->dev; | |
9e2c8475 | 647 | struct dpll clock; |
3b1429d9 | 648 | int err = target; |
79e53945 | 649 | |
0206e353 | 650 | memset(best_clock, 0, sizeof(*best_clock)); |
79e53945 | 651 | |
3b1429d9 VS |
652 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
653 | ||
42158660 ZY |
654 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
655 | clock.m1++) { | |
656 | for (clock.m2 = limit->m2.min; | |
657 | clock.m2 <= limit->m2.max; clock.m2++) { | |
c0efc387 | 658 | if (clock.m2 >= clock.m1) |
42158660 ZY |
659 | break; |
660 | for (clock.n = limit->n.min; | |
661 | clock.n <= limit->n.max; clock.n++) { | |
662 | for (clock.p1 = limit->p1.min; | |
663 | clock.p1 <= limit->p1.max; clock.p1++) { | |
79e53945 JB |
664 | int this_err; |
665 | ||
dccbea3b | 666 | i9xx_calc_dpll_params(refclk, &clock); |
e2d214ae TU |
667 | if (!intel_PLL_is_valid(to_i915(dev), |
668 | limit, | |
ac58c3f0 DV |
669 | &clock)) |
670 | continue; | |
671 | if (match_clock && | |
672 | clock.p != match_clock->p) | |
673 | continue; | |
674 | ||
675 | this_err = abs(clock.dot - target); | |
676 | if (this_err < err) { | |
677 | *best_clock = clock; | |
678 | err = this_err; | |
679 | } | |
680 | } | |
681 | } | |
682 | } | |
683 | } | |
684 | ||
685 | return (err != target); | |
686 | } | |
687 | ||
70e8aa21 ACO |
688 | /* |
689 | * Returns a set of divisors for the desired target clock with the given | |
690 | * refclk, or FALSE. The returned values represent the clock equation: | |
691 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. | |
692 | * | |
693 | * Target and reference clocks are specified in kHz. | |
694 | * | |
695 | * If match_clock is provided, then best_clock P divider must match the P | |
696 | * divider from @match_clock used for LVDS downclocking. | |
697 | */ | |
ac58c3f0 | 698 | static bool |
1b6f4958 | 699 | pnv_find_best_dpll(const struct intel_limit *limit, |
a93e255f | 700 | struct intel_crtc_state *crtc_state, |
9e2c8475 ACO |
701 | int target, int refclk, struct dpll *match_clock, |
702 | struct dpll *best_clock) | |
79e53945 | 703 | { |
3b1429d9 | 704 | struct drm_device *dev = crtc_state->base.crtc->dev; |
9e2c8475 | 705 | struct dpll clock; |
79e53945 JB |
706 | int err = target; |
707 | ||
0206e353 | 708 | memset(best_clock, 0, sizeof(*best_clock)); |
79e53945 | 709 | |
3b1429d9 VS |
710 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
711 | ||
42158660 ZY |
712 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
713 | clock.m1++) { | |
714 | for (clock.m2 = limit->m2.min; | |
715 | clock.m2 <= limit->m2.max; clock.m2++) { | |
42158660 ZY |
716 | for (clock.n = limit->n.min; |
717 | clock.n <= limit->n.max; clock.n++) { | |
718 | for (clock.p1 = limit->p1.min; | |
719 | clock.p1 <= limit->p1.max; clock.p1++) { | |
79e53945 JB |
720 | int this_err; |
721 | ||
dccbea3b | 722 | pnv_calc_dpll_params(refclk, &clock); |
e2d214ae TU |
723 | if (!intel_PLL_is_valid(to_i915(dev), |
724 | limit, | |
1b894b59 | 725 | &clock)) |
79e53945 | 726 | continue; |
cec2f356 SP |
727 | if (match_clock && |
728 | clock.p != match_clock->p) | |
729 | continue; | |
79e53945 JB |
730 | |
731 | this_err = abs(clock.dot - target); | |
732 | if (this_err < err) { | |
733 | *best_clock = clock; | |
734 | err = this_err; | |
735 | } | |
736 | } | |
737 | } | |
738 | } | |
739 | } | |
740 | ||
741 | return (err != target); | |
742 | } | |
743 | ||
997c030c ACO |
744 | /* |
745 | * Returns a set of divisors for the desired target clock with the given | |
746 | * refclk, or FALSE. The returned values represent the clock equation: | |
747 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. | |
70e8aa21 ACO |
748 | * |
749 | * Target and reference clocks are specified in kHz. | |
750 | * | |
751 | * If match_clock is provided, then best_clock P divider must match the P | |
752 | * divider from @match_clock used for LVDS downclocking. | |
997c030c | 753 | */ |
d4906093 | 754 | static bool |
1b6f4958 | 755 | g4x_find_best_dpll(const struct intel_limit *limit, |
a93e255f | 756 | struct intel_crtc_state *crtc_state, |
9e2c8475 ACO |
757 | int target, int refclk, struct dpll *match_clock, |
758 | struct dpll *best_clock) | |
d4906093 | 759 | { |
3b1429d9 | 760 | struct drm_device *dev = crtc_state->base.crtc->dev; |
9e2c8475 | 761 | struct dpll clock; |
d4906093 | 762 | int max_n; |
3b1429d9 | 763 | bool found = false; |
6ba770dc AJ |
764 | /* approximately equals target * 0.00585 */ |
765 | int err_most = (target >> 8) + (target >> 9); | |
d4906093 ML |
766 | |
767 | memset(best_clock, 0, sizeof(*best_clock)); | |
3b1429d9 VS |
768 | |
769 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); | |
770 | ||
d4906093 | 771 | max_n = limit->n.max; |
f77f13e2 | 772 | /* based on hardware requirement, prefer smaller n to precision */ |
d4906093 | 773 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
f77f13e2 | 774 | /* based on hardware requirement, prefere larger m1,m2 */ |
d4906093 ML |
775 | for (clock.m1 = limit->m1.max; |
776 | clock.m1 >= limit->m1.min; clock.m1--) { | |
777 | for (clock.m2 = limit->m2.max; | |
778 | clock.m2 >= limit->m2.min; clock.m2--) { | |
779 | for (clock.p1 = limit->p1.max; | |
780 | clock.p1 >= limit->p1.min; clock.p1--) { | |
781 | int this_err; | |
782 | ||
dccbea3b | 783 | i9xx_calc_dpll_params(refclk, &clock); |
e2d214ae TU |
784 | if (!intel_PLL_is_valid(to_i915(dev), |
785 | limit, | |
1b894b59 | 786 | &clock)) |
d4906093 | 787 | continue; |
1b894b59 CW |
788 | |
789 | this_err = abs(clock.dot - target); | |
d4906093 ML |
790 | if (this_err < err_most) { |
791 | *best_clock = clock; | |
792 | err_most = this_err; | |
793 | max_n = clock.n; | |
794 | found = true; | |
795 | } | |
796 | } | |
797 | } | |
798 | } | |
799 | } | |
2c07245f ZW |
800 | return found; |
801 | } | |
802 | ||
d5dd62bd ID |
803 | /* |
804 | * Check if the calculated PLL configuration is more optimal compared to the | |
805 | * best configuration and error found so far. Return the calculated error. | |
806 | */ | |
807 | static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq, | |
9e2c8475 ACO |
808 | const struct dpll *calculated_clock, |
809 | const struct dpll *best_clock, | |
d5dd62bd ID |
810 | unsigned int best_error_ppm, |
811 | unsigned int *error_ppm) | |
812 | { | |
9ca3ba01 ID |
813 | /* |
814 | * For CHV ignore the error and consider only the P value. | |
815 | * Prefer a bigger P value based on HW requirements. | |
816 | */ | |
920a14b2 | 817 | if (IS_CHERRYVIEW(to_i915(dev))) { |
9ca3ba01 ID |
818 | *error_ppm = 0; |
819 | ||
820 | return calculated_clock->p > best_clock->p; | |
821 | } | |
822 | ||
24be4e46 ID |
823 | if (WARN_ON_ONCE(!target_freq)) |
824 | return false; | |
825 | ||
d5dd62bd ID |
826 | *error_ppm = div_u64(1000000ULL * |
827 | abs(target_freq - calculated_clock->dot), | |
828 | target_freq); | |
829 | /* | |
830 | * Prefer a better P value over a better (smaller) error if the error | |
831 | * is small. Ensure this preference for future configurations too by | |
832 | * setting the error to 0. | |
833 | */ | |
834 | if (*error_ppm < 100 && calculated_clock->p > best_clock->p) { | |
835 | *error_ppm = 0; | |
836 | ||
837 | return true; | |
838 | } | |
839 | ||
840 | return *error_ppm + 10 < best_error_ppm; | |
841 | } | |
842 | ||
65b3d6a9 ACO |
843 | /* |
844 | * Returns a set of divisors for the desired target clock with the given | |
845 | * refclk, or FALSE. The returned values represent the clock equation: | |
846 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. | |
847 | */ | |
a0c4da24 | 848 | static bool |
1b6f4958 | 849 | vlv_find_best_dpll(const struct intel_limit *limit, |
a93e255f | 850 | struct intel_crtc_state *crtc_state, |
9e2c8475 ACO |
851 | int target, int refclk, struct dpll *match_clock, |
852 | struct dpll *best_clock) | |
a0c4da24 | 853 | { |
a93e255f | 854 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
a919ff14 | 855 | struct drm_device *dev = crtc->base.dev; |
9e2c8475 | 856 | struct dpll clock; |
69e4f900 | 857 | unsigned int bestppm = 1000000; |
27e639bf VS |
858 | /* min update 19.2 MHz */ |
859 | int max_n = min(limit->n.max, refclk / 19200); | |
49e497ef | 860 | bool found = false; |
a0c4da24 | 861 | |
6b4bf1c4 VS |
862 | target *= 5; /* fast clock */ |
863 | ||
864 | memset(best_clock, 0, sizeof(*best_clock)); | |
a0c4da24 JB |
865 | |
866 | /* based on hardware requirement, prefer smaller n to precision */ | |
27e639bf | 867 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
811bbf05 | 868 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
889059d8 | 869 | for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow; |
c1a9ae43 | 870 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
6b4bf1c4 | 871 | clock.p = clock.p1 * clock.p2; |
a0c4da24 | 872 | /* based on hardware requirement, prefer bigger m1,m2 values */ |
6b4bf1c4 | 873 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) { |
d5dd62bd | 874 | unsigned int ppm; |
69e4f900 | 875 | |
6b4bf1c4 VS |
876 | clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n, |
877 | refclk * clock.m1); | |
878 | ||
dccbea3b | 879 | vlv_calc_dpll_params(refclk, &clock); |
43b0ac53 | 880 | |
e2d214ae TU |
881 | if (!intel_PLL_is_valid(to_i915(dev), |
882 | limit, | |
f01b7962 | 883 | &clock)) |
43b0ac53 VS |
884 | continue; |
885 | ||
d5dd62bd ID |
886 | if (!vlv_PLL_is_optimal(dev, target, |
887 | &clock, | |
888 | best_clock, | |
889 | bestppm, &ppm)) | |
890 | continue; | |
6b4bf1c4 | 891 | |
d5dd62bd ID |
892 | *best_clock = clock; |
893 | bestppm = ppm; | |
894 | found = true; | |
a0c4da24 JB |
895 | } |
896 | } | |
897 | } | |
898 | } | |
a0c4da24 | 899 | |
49e497ef | 900 | return found; |
a0c4da24 | 901 | } |
a4fc5ed6 | 902 | |
65b3d6a9 ACO |
903 | /* |
904 | * Returns a set of divisors for the desired target clock with the given | |
905 | * refclk, or FALSE. The returned values represent the clock equation: | |
906 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. | |
907 | */ | |
ef9348c8 | 908 | static bool |
1b6f4958 | 909 | chv_find_best_dpll(const struct intel_limit *limit, |
a93e255f | 910 | struct intel_crtc_state *crtc_state, |
9e2c8475 ACO |
911 | int target, int refclk, struct dpll *match_clock, |
912 | struct dpll *best_clock) | |
ef9348c8 | 913 | { |
a93e255f | 914 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
a919ff14 | 915 | struct drm_device *dev = crtc->base.dev; |
9ca3ba01 | 916 | unsigned int best_error_ppm; |
9e2c8475 | 917 | struct dpll clock; |
ef9348c8 CML |
918 | uint64_t m2; |
919 | int found = false; | |
920 | ||
921 | memset(best_clock, 0, sizeof(*best_clock)); | |
9ca3ba01 | 922 | best_error_ppm = 1000000; |
ef9348c8 CML |
923 | |
924 | /* | |
925 | * Based on hardware doc, the n always set to 1, and m1 always | |
926 | * set to 2. If requires to support 200Mhz refclk, we need to | |
927 | * revisit this because n may not 1 anymore. | |
928 | */ | |
929 | clock.n = 1, clock.m1 = 2; | |
930 | target *= 5; /* fast clock */ | |
931 | ||
932 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { | |
933 | for (clock.p2 = limit->p2.p2_fast; | |
934 | clock.p2 >= limit->p2.p2_slow; | |
935 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { | |
9ca3ba01 | 936 | unsigned int error_ppm; |
ef9348c8 CML |
937 | |
938 | clock.p = clock.p1 * clock.p2; | |
939 | ||
940 | m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p * | |
941 | clock.n) << 22, refclk * clock.m1); | |
942 | ||
943 | if (m2 > INT_MAX/clock.m1) | |
944 | continue; | |
945 | ||
946 | clock.m2 = m2; | |
947 | ||
dccbea3b | 948 | chv_calc_dpll_params(refclk, &clock); |
ef9348c8 | 949 | |
e2d214ae | 950 | if (!intel_PLL_is_valid(to_i915(dev), limit, &clock)) |
ef9348c8 CML |
951 | continue; |
952 | ||
9ca3ba01 ID |
953 | if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock, |
954 | best_error_ppm, &error_ppm)) | |
955 | continue; | |
956 | ||
957 | *best_clock = clock; | |
958 | best_error_ppm = error_ppm; | |
959 | found = true; | |
ef9348c8 CML |
960 | } |
961 | } | |
962 | ||
963 | return found; | |
964 | } | |
965 | ||
5ab7b0b7 | 966 | bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock, |
9e2c8475 | 967 | struct dpll *best_clock) |
5ab7b0b7 | 968 | { |
65b3d6a9 | 969 | int refclk = 100000; |
1b6f4958 | 970 | const struct intel_limit *limit = &intel_limits_bxt; |
5ab7b0b7 | 971 | |
65b3d6a9 | 972 | return chv_find_best_dpll(limit, crtc_state, |
5ab7b0b7 ID |
973 | target_clock, refclk, NULL, best_clock); |
974 | } | |
975 | ||
525b9311 | 976 | bool intel_crtc_active(struct intel_crtc *crtc) |
20ddf665 | 977 | { |
20ddf665 VS |
978 | /* Be paranoid as we can arrive here with only partial |
979 | * state retrieved from the hardware during setup. | |
980 | * | |
241bfc38 | 981 | * We can ditch the adjusted_mode.crtc_clock check as soon |
20ddf665 VS |
982 | * as Haswell has gained clock readout/fastboot support. |
983 | * | |
66e514c1 | 984 | * We can ditch the crtc->primary->fb check as soon as we can |
20ddf665 | 985 | * properly reconstruct framebuffers. |
c3d1f436 MR |
986 | * |
987 | * FIXME: The intel_crtc->active here should be switched to | |
988 | * crtc->state->active once we have proper CRTC states wired up | |
989 | * for atomic. | |
20ddf665 | 990 | */ |
525b9311 VS |
991 | return crtc->active && crtc->base.primary->state->fb && |
992 | crtc->config->base.adjusted_mode.crtc_clock; | |
20ddf665 VS |
993 | } |
994 | ||
a5c961d1 PZ |
995 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, |
996 | enum pipe pipe) | |
997 | { | |
98187836 | 998 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
a5c961d1 | 999 | |
e2af48c6 | 1000 | return crtc->config->cpu_transcoder; |
a5c961d1 PZ |
1001 | } |
1002 | ||
a87e55f8 VS |
1003 | static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv, |
1004 | enum pipe pipe) | |
fbf49ea2 | 1005 | { |
f0f59a00 | 1006 | i915_reg_t reg = PIPEDSL(pipe); |
fbf49ea2 VS |
1007 | u32 line1, line2; |
1008 | u32 line_mask; | |
1009 | ||
5db94019 | 1010 | if (IS_GEN2(dev_priv)) |
fbf49ea2 VS |
1011 | line_mask = DSL_LINEMASK_GEN2; |
1012 | else | |
1013 | line_mask = DSL_LINEMASK_GEN3; | |
1014 | ||
1015 | line1 = I915_READ(reg) & line_mask; | |
6adfb1ef | 1016 | msleep(5); |
fbf49ea2 VS |
1017 | line2 = I915_READ(reg) & line_mask; |
1018 | ||
a87e55f8 VS |
1019 | return line1 != line2; |
1020 | } | |
1021 | ||
1022 | static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state) | |
1023 | { | |
1024 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); | |
1025 | enum pipe pipe = crtc->pipe; | |
1026 | ||
1027 | /* Wait for the display line to settle/start moving */ | |
1028 | if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100)) | |
1029 | DRM_ERROR("pipe %c scanline %s wait timed out\n", | |
1030 | pipe_name(pipe), onoff(state)); | |
1031 | } | |
1032 | ||
1033 | static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc) | |
1034 | { | |
1035 | wait_for_pipe_scanline_moving(crtc, false); | |
1036 | } | |
1037 | ||
1038 | static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc) | |
1039 | { | |
1040 | wait_for_pipe_scanline_moving(crtc, true); | |
fbf49ea2 VS |
1041 | } |
1042 | ||
ab7ad7f6 KP |
1043 | /* |
1044 | * intel_wait_for_pipe_off - wait for pipe to turn off | |
575f7ab7 | 1045 | * @crtc: crtc whose pipe to wait for |
9d0498a2 JB |
1046 | * |
1047 | * After disabling a pipe, we can't wait for vblank in the usual way, | |
1048 | * spinning on the vblank interrupt status bit, since we won't actually | |
1049 | * see an interrupt when the pipe is disabled. | |
1050 | * | |
ab7ad7f6 KP |
1051 | * On Gen4 and above: |
1052 | * wait for the pipe register state bit to turn off | |
1053 | * | |
1054 | * Otherwise: | |
1055 | * wait for the display line value to settle (it usually | |
1056 | * ends up stopping at the start of the next frame). | |
58e10eb9 | 1057 | * |
9d0498a2 | 1058 | */ |
575f7ab7 | 1059 | static void intel_wait_for_pipe_off(struct intel_crtc *crtc) |
9d0498a2 | 1060 | { |
6315b5d3 | 1061 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
6e3c9717 | 1062 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
ab7ad7f6 | 1063 | |
6315b5d3 | 1064 | if (INTEL_GEN(dev_priv) >= 4) { |
f0f59a00 | 1065 | i915_reg_t reg = PIPECONF(cpu_transcoder); |
ab7ad7f6 KP |
1066 | |
1067 | /* Wait for the Pipe State to go off */ | |
b8511f53 CW |
1068 | if (intel_wait_for_register(dev_priv, |
1069 | reg, I965_PIPECONF_ACTIVE, 0, | |
1070 | 100)) | |
284637d9 | 1071 | WARN(1, "pipe_off wait timed out\n"); |
ab7ad7f6 | 1072 | } else { |
a87e55f8 | 1073 | intel_wait_for_pipe_scanline_stopped(crtc); |
ab7ad7f6 | 1074 | } |
79e53945 JB |
1075 | } |
1076 | ||
b24e7179 | 1077 | /* Only for pre-ILK configs */ |
55607e8a DV |
1078 | void assert_pll(struct drm_i915_private *dev_priv, |
1079 | enum pipe pipe, bool state) | |
b24e7179 | 1080 | { |
b24e7179 JB |
1081 | u32 val; |
1082 | bool cur_state; | |
1083 | ||
649636ef | 1084 | val = I915_READ(DPLL(pipe)); |
b24e7179 | 1085 | cur_state = !!(val & DPLL_VCO_ENABLE); |
e2c719b7 | 1086 | I915_STATE_WARN(cur_state != state, |
b24e7179 | 1087 | "PLL state assertion failure (expected %s, current %s)\n", |
87ad3212 | 1088 | onoff(state), onoff(cur_state)); |
b24e7179 | 1089 | } |
b24e7179 | 1090 | |
23538ef1 | 1091 | /* XXX: the dsi pll is shared between MIPI DSI ports */ |
8563b1e8 | 1092 | void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state) |
23538ef1 JN |
1093 | { |
1094 | u32 val; | |
1095 | bool cur_state; | |
1096 | ||
a580516d | 1097 | mutex_lock(&dev_priv->sb_lock); |
23538ef1 | 1098 | val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); |
a580516d | 1099 | mutex_unlock(&dev_priv->sb_lock); |
23538ef1 JN |
1100 | |
1101 | cur_state = val & DSI_PLL_VCO_EN; | |
e2c719b7 | 1102 | I915_STATE_WARN(cur_state != state, |
23538ef1 | 1103 | "DSI PLL state assertion failure (expected %s, current %s)\n", |
87ad3212 | 1104 | onoff(state), onoff(cur_state)); |
23538ef1 | 1105 | } |
23538ef1 | 1106 | |
040484af JB |
1107 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, |
1108 | enum pipe pipe, bool state) | |
1109 | { | |
040484af | 1110 | bool cur_state; |
ad80a810 PZ |
1111 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
1112 | pipe); | |
040484af | 1113 | |
2d1fe073 | 1114 | if (HAS_DDI(dev_priv)) { |
affa9354 | 1115 | /* DDI does not have a specific FDI_TX register */ |
649636ef | 1116 | u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
ad80a810 | 1117 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
bf507ef7 | 1118 | } else { |
649636ef | 1119 | u32 val = I915_READ(FDI_TX_CTL(pipe)); |
bf507ef7 ED |
1120 | cur_state = !!(val & FDI_TX_ENABLE); |
1121 | } | |
e2c719b7 | 1122 | I915_STATE_WARN(cur_state != state, |
040484af | 1123 | "FDI TX state assertion failure (expected %s, current %s)\n", |
87ad3212 | 1124 | onoff(state), onoff(cur_state)); |
040484af JB |
1125 | } |
1126 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) | |
1127 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) | |
1128 | ||
1129 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, | |
1130 | enum pipe pipe, bool state) | |
1131 | { | |
040484af JB |
1132 | u32 val; |
1133 | bool cur_state; | |
1134 | ||
649636ef | 1135 | val = I915_READ(FDI_RX_CTL(pipe)); |
d63fa0dc | 1136 | cur_state = !!(val & FDI_RX_ENABLE); |
e2c719b7 | 1137 | I915_STATE_WARN(cur_state != state, |
040484af | 1138 | "FDI RX state assertion failure (expected %s, current %s)\n", |
87ad3212 | 1139 | onoff(state), onoff(cur_state)); |
040484af JB |
1140 | } |
1141 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) | |
1142 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) | |
1143 | ||
1144 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, | |
1145 | enum pipe pipe) | |
1146 | { | |
040484af JB |
1147 | u32 val; |
1148 | ||
1149 | /* ILK FDI PLL is always enabled */ | |
7e22dbbb | 1150 | if (IS_GEN5(dev_priv)) |
040484af JB |
1151 | return; |
1152 | ||
bf507ef7 | 1153 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
2d1fe073 | 1154 | if (HAS_DDI(dev_priv)) |
bf507ef7 ED |
1155 | return; |
1156 | ||
649636ef | 1157 | val = I915_READ(FDI_TX_CTL(pipe)); |
e2c719b7 | 1158 | I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n"); |
040484af JB |
1159 | } |
1160 | ||
55607e8a DV |
1161 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, |
1162 | enum pipe pipe, bool state) | |
040484af | 1163 | { |
040484af | 1164 | u32 val; |
55607e8a | 1165 | bool cur_state; |
040484af | 1166 | |
649636ef | 1167 | val = I915_READ(FDI_RX_CTL(pipe)); |
55607e8a | 1168 | cur_state = !!(val & FDI_RX_PLL_ENABLE); |
e2c719b7 | 1169 | I915_STATE_WARN(cur_state != state, |
55607e8a | 1170 | "FDI RX PLL assertion failure (expected %s, current %s)\n", |
87ad3212 | 1171 | onoff(state), onoff(cur_state)); |
040484af JB |
1172 | } |
1173 | ||
4f8036a2 | 1174 | void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe) |
ea0760cf | 1175 | { |
f0f59a00 | 1176 | i915_reg_t pp_reg; |
ea0760cf JB |
1177 | u32 val; |
1178 | enum pipe panel_pipe = PIPE_A; | |
0de3b485 | 1179 | bool locked = true; |
ea0760cf | 1180 | |
4f8036a2 | 1181 | if (WARN_ON(HAS_DDI(dev_priv))) |
bedd4dba JN |
1182 | return; |
1183 | ||
4f8036a2 | 1184 | if (HAS_PCH_SPLIT(dev_priv)) { |
bedd4dba JN |
1185 | u32 port_sel; |
1186 | ||
44cb734c ID |
1187 | pp_reg = PP_CONTROL(0); |
1188 | port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK; | |
bedd4dba JN |
1189 | |
1190 | if (port_sel == PANEL_PORT_SELECT_LVDS && | |
1191 | I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT) | |
1192 | panel_pipe = PIPE_B; | |
1193 | /* XXX: else fix for eDP */ | |
4f8036a2 | 1194 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
bedd4dba | 1195 | /* presumably write lock depends on pipe, not port select */ |
44cb734c | 1196 | pp_reg = PP_CONTROL(pipe); |
bedd4dba | 1197 | panel_pipe = pipe; |
ea0760cf | 1198 | } else { |
44cb734c | 1199 | pp_reg = PP_CONTROL(0); |
bedd4dba JN |
1200 | if (I915_READ(LVDS) & LVDS_PIPEB_SELECT) |
1201 | panel_pipe = PIPE_B; | |
ea0760cf JB |
1202 | } |
1203 | ||
1204 | val = I915_READ(pp_reg); | |
1205 | if (!(val & PANEL_POWER_ON) || | |
ec49ba2d | 1206 | ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) |
ea0760cf JB |
1207 | locked = false; |
1208 | ||
e2c719b7 | 1209 | I915_STATE_WARN(panel_pipe == pipe && locked, |
ea0760cf | 1210 | "panel assertion failure, pipe %c regs locked\n", |
9db4a9c7 | 1211 | pipe_name(pipe)); |
ea0760cf JB |
1212 | } |
1213 | ||
b840d907 JB |
1214 | void assert_pipe(struct drm_i915_private *dev_priv, |
1215 | enum pipe pipe, bool state) | |
b24e7179 | 1216 | { |
63d7bbe9 | 1217 | bool cur_state; |
702e7a56 PZ |
1218 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
1219 | pipe); | |
4feed0eb | 1220 | enum intel_display_power_domain power_domain; |
b24e7179 | 1221 | |
e56134bc VS |
1222 | /* we keep both pipes enabled on 830 */ |
1223 | if (IS_I830(dev_priv)) | |
8e636784 DV |
1224 | state = true; |
1225 | ||
4feed0eb ID |
1226 | power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); |
1227 | if (intel_display_power_get_if_enabled(dev_priv, power_domain)) { | |
649636ef | 1228 | u32 val = I915_READ(PIPECONF(cpu_transcoder)); |
69310161 | 1229 | cur_state = !!(val & PIPECONF_ENABLE); |
4feed0eb ID |
1230 | |
1231 | intel_display_power_put(dev_priv, power_domain); | |
1232 | } else { | |
1233 | cur_state = false; | |
69310161 PZ |
1234 | } |
1235 | ||
e2c719b7 | 1236 | I915_STATE_WARN(cur_state != state, |
63d7bbe9 | 1237 | "pipe %c assertion failure (expected %s, current %s)\n", |
87ad3212 | 1238 | pipe_name(pipe), onoff(state), onoff(cur_state)); |
b24e7179 JB |
1239 | } |
1240 | ||
d87ce764 | 1241 | static void assert_plane(struct intel_plane *plane, bool state) |
b24e7179 | 1242 | { |
d87ce764 | 1243 | bool cur_state = plane->get_hw_state(plane); |
b24e7179 | 1244 | |
e2c719b7 | 1245 | I915_STATE_WARN(cur_state != state, |
d87ce764 VS |
1246 | "%s assertion failure (expected %s, current %s)\n", |
1247 | plane->base.name, onoff(state), onoff(cur_state)); | |
b24e7179 JB |
1248 | } |
1249 | ||
d87ce764 VS |
1250 | #define assert_plane_enabled(p) assert_plane(p, true) |
1251 | #define assert_plane_disabled(p) assert_plane(p, false) | |
931872fc | 1252 | |
d87ce764 | 1253 | static void assert_planes_disabled(struct intel_crtc *crtc) |
b24e7179 | 1254 | { |
d87ce764 VS |
1255 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
1256 | struct intel_plane *plane; | |
19332d7a | 1257 | |
d87ce764 VS |
1258 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) |
1259 | assert_plane_disabled(plane); | |
19332d7a JB |
1260 | } |
1261 | ||
08c71e5e VS |
1262 | static void assert_vblank_disabled(struct drm_crtc *crtc) |
1263 | { | |
e2c719b7 | 1264 | if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0)) |
08c71e5e VS |
1265 | drm_crtc_vblank_put(crtc); |
1266 | } | |
1267 | ||
7abd4b35 ACO |
1268 | void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, |
1269 | enum pipe pipe) | |
92f2584a | 1270 | { |
92f2584a JB |
1271 | u32 val; |
1272 | bool enabled; | |
1273 | ||
649636ef | 1274 | val = I915_READ(PCH_TRANSCONF(pipe)); |
92f2584a | 1275 | enabled = !!(val & TRANS_ENABLE); |
e2c719b7 | 1276 | I915_STATE_WARN(enabled, |
9db4a9c7 JB |
1277 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
1278 | pipe_name(pipe)); | |
92f2584a JB |
1279 | } |
1280 | ||
4e634389 KP |
1281 | static bool dp_pipe_enabled(struct drm_i915_private *dev_priv, |
1282 | enum pipe pipe, u32 port_sel, u32 val) | |
f0575e92 KP |
1283 | { |
1284 | if ((val & DP_PORT_EN) == 0) | |
1285 | return false; | |
1286 | ||
2d1fe073 | 1287 | if (HAS_PCH_CPT(dev_priv)) { |
f0f59a00 | 1288 | u32 trans_dp_ctl = I915_READ(TRANS_DP_CTL(pipe)); |
f0575e92 KP |
1289 | if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel) |
1290 | return false; | |
2d1fe073 | 1291 | } else if (IS_CHERRYVIEW(dev_priv)) { |
44f37d1f CML |
1292 | if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe)) |
1293 | return false; | |
f0575e92 KP |
1294 | } else { |
1295 | if ((val & DP_PIPE_MASK) != (pipe << 30)) | |
1296 | return false; | |
1297 | } | |
1298 | return true; | |
1299 | } | |
1300 | ||
1519b995 KP |
1301 | static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv, |
1302 | enum pipe pipe, u32 val) | |
1303 | { | |
dc0fa718 | 1304 | if ((val & SDVO_ENABLE) == 0) |
1519b995 KP |
1305 | return false; |
1306 | ||
2d1fe073 | 1307 | if (HAS_PCH_CPT(dev_priv)) { |
dc0fa718 | 1308 | if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe)) |
1519b995 | 1309 | return false; |
2d1fe073 | 1310 | } else if (IS_CHERRYVIEW(dev_priv)) { |
44f37d1f CML |
1311 | if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe)) |
1312 | return false; | |
1519b995 | 1313 | } else { |
dc0fa718 | 1314 | if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe)) |
1519b995 KP |
1315 | return false; |
1316 | } | |
1317 | return true; | |
1318 | } | |
1319 | ||
1320 | static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv, | |
1321 | enum pipe pipe, u32 val) | |
1322 | { | |
1323 | if ((val & LVDS_PORT_EN) == 0) | |
1324 | return false; | |
1325 | ||
2d1fe073 | 1326 | if (HAS_PCH_CPT(dev_priv)) { |
1519b995 KP |
1327 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
1328 | return false; | |
1329 | } else { | |
1330 | if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe)) | |
1331 | return false; | |
1332 | } | |
1333 | return true; | |
1334 | } | |
1335 | ||
1336 | static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv, | |
1337 | enum pipe pipe, u32 val) | |
1338 | { | |
1339 | if ((val & ADPA_DAC_ENABLE) == 0) | |
1340 | return false; | |
2d1fe073 | 1341 | if (HAS_PCH_CPT(dev_priv)) { |
1519b995 KP |
1342 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
1343 | return false; | |
1344 | } else { | |
1345 | if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe)) | |
1346 | return false; | |
1347 | } | |
1348 | return true; | |
1349 | } | |
1350 | ||
291906f1 | 1351 | static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv, |
f0f59a00 VS |
1352 | enum pipe pipe, i915_reg_t reg, |
1353 | u32 port_sel) | |
291906f1 | 1354 | { |
47a05eca | 1355 | u32 val = I915_READ(reg); |
e2c719b7 | 1356 | I915_STATE_WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val), |
291906f1 | 1357 | "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n", |
f0f59a00 | 1358 | i915_mmio_reg_offset(reg), pipe_name(pipe)); |
de9a35ab | 1359 | |
2d1fe073 | 1360 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && (val & DP_PORT_EN) == 0 |
75c5da27 | 1361 | && (val & DP_PIPEB_SELECT), |
de9a35ab | 1362 | "IBX PCH dp port still using transcoder B\n"); |
291906f1 JB |
1363 | } |
1364 | ||
1365 | static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv, | |
f0f59a00 | 1366 | enum pipe pipe, i915_reg_t reg) |
291906f1 | 1367 | { |
47a05eca | 1368 | u32 val = I915_READ(reg); |
e2c719b7 | 1369 | I915_STATE_WARN(hdmi_pipe_enabled(dev_priv, pipe, val), |
23c99e77 | 1370 | "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n", |
f0f59a00 | 1371 | i915_mmio_reg_offset(reg), pipe_name(pipe)); |
de9a35ab | 1372 | |
2d1fe073 | 1373 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && (val & SDVO_ENABLE) == 0 |
75c5da27 | 1374 | && (val & SDVO_PIPE_B_SELECT), |
de9a35ab | 1375 | "IBX PCH hdmi port still using transcoder B\n"); |
291906f1 JB |
1376 | } |
1377 | ||
1378 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, | |
1379 | enum pipe pipe) | |
1380 | { | |
291906f1 | 1381 | u32 val; |
291906f1 | 1382 | |
f0575e92 KP |
1383 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B); |
1384 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C); | |
1385 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D); | |
291906f1 | 1386 | |
649636ef | 1387 | val = I915_READ(PCH_ADPA); |
e2c719b7 | 1388 | I915_STATE_WARN(adpa_pipe_enabled(dev_priv, pipe, val), |
291906f1 | 1389 | "PCH VGA enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1390 | pipe_name(pipe)); |
291906f1 | 1391 | |
649636ef | 1392 | val = I915_READ(PCH_LVDS); |
e2c719b7 | 1393 | I915_STATE_WARN(lvds_pipe_enabled(dev_priv, pipe, val), |
291906f1 | 1394 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
9db4a9c7 | 1395 | pipe_name(pipe)); |
291906f1 | 1396 | |
e2debe91 PZ |
1397 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB); |
1398 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC); | |
1399 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID); | |
291906f1 JB |
1400 | } |
1401 | ||
cd2d34d9 VS |
1402 | static void _vlv_enable_pll(struct intel_crtc *crtc, |
1403 | const struct intel_crtc_state *pipe_config) | |
1404 | { | |
1405 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); | |
1406 | enum pipe pipe = crtc->pipe; | |
1407 | ||
1408 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); | |
1409 | POSTING_READ(DPLL(pipe)); | |
1410 | udelay(150); | |
1411 | ||
2c30b43b CW |
1412 | if (intel_wait_for_register(dev_priv, |
1413 | DPLL(pipe), | |
1414 | DPLL_LOCK_VLV, | |
1415 | DPLL_LOCK_VLV, | |
1416 | 1)) | |
cd2d34d9 VS |
1417 | DRM_ERROR("DPLL %d failed to lock\n", pipe); |
1418 | } | |
1419 | ||
d288f65f | 1420 | static void vlv_enable_pll(struct intel_crtc *crtc, |
5cec258b | 1421 | const struct intel_crtc_state *pipe_config) |
87442f73 | 1422 | { |
cd2d34d9 | 1423 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
8bd3f301 | 1424 | enum pipe pipe = crtc->pipe; |
87442f73 | 1425 | |
8bd3f301 | 1426 | assert_pipe_disabled(dev_priv, pipe); |
87442f73 | 1427 | |
87442f73 | 1428 | /* PLL is protected by panel, make sure we can write it */ |
7d1a83cb | 1429 | assert_panel_unlocked(dev_priv, pipe); |
87442f73 | 1430 | |
cd2d34d9 VS |
1431 | if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) |
1432 | _vlv_enable_pll(crtc, pipe_config); | |
426115cf | 1433 | |
8bd3f301 VS |
1434 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
1435 | POSTING_READ(DPLL_MD(pipe)); | |
87442f73 DV |
1436 | } |
1437 | ||
cd2d34d9 VS |
1438 | |
1439 | static void _chv_enable_pll(struct intel_crtc *crtc, | |
1440 | const struct intel_crtc_state *pipe_config) | |
9d556c99 | 1441 | { |
cd2d34d9 | 1442 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
8bd3f301 | 1443 | enum pipe pipe = crtc->pipe; |
9d556c99 | 1444 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
9d556c99 CML |
1445 | u32 tmp; |
1446 | ||
a580516d | 1447 | mutex_lock(&dev_priv->sb_lock); |
9d556c99 CML |
1448 | |
1449 | /* Enable back the 10bit clock to display controller */ | |
1450 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); | |
1451 | tmp |= DPIO_DCLKP_EN; | |
1452 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp); | |
1453 | ||
54433e91 VS |
1454 | mutex_unlock(&dev_priv->sb_lock); |
1455 | ||
9d556c99 CML |
1456 | /* |
1457 | * Need to wait > 100ns between dclkp clock enable bit and PLL enable. | |
1458 | */ | |
1459 | udelay(1); | |
1460 | ||
1461 | /* Enable PLL */ | |
d288f65f | 1462 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
9d556c99 CML |
1463 | |
1464 | /* Check PLL is locked */ | |
6b18826a CW |
1465 | if (intel_wait_for_register(dev_priv, |
1466 | DPLL(pipe), DPLL_LOCK_VLV, DPLL_LOCK_VLV, | |
1467 | 1)) | |
9d556c99 | 1468 | DRM_ERROR("PLL %d failed to lock\n", pipe); |
cd2d34d9 VS |
1469 | } |
1470 | ||
1471 | static void chv_enable_pll(struct intel_crtc *crtc, | |
1472 | const struct intel_crtc_state *pipe_config) | |
1473 | { | |
1474 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); | |
1475 | enum pipe pipe = crtc->pipe; | |
1476 | ||
1477 | assert_pipe_disabled(dev_priv, pipe); | |
1478 | ||
1479 | /* PLL is protected by panel, make sure we can write it */ | |
1480 | assert_panel_unlocked(dev_priv, pipe); | |
1481 | ||
1482 | if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) | |
1483 | _chv_enable_pll(crtc, pipe_config); | |
9d556c99 | 1484 | |
c231775c VS |
1485 | if (pipe != PIPE_A) { |
1486 | /* | |
1487 | * WaPixelRepeatModeFixForC0:chv | |
1488 | * | |
1489 | * DPLLCMD is AWOL. Use chicken bits to propagate | |
1490 | * the value from DPLLBMD to either pipe B or C. | |
1491 | */ | |
dfa311f0 | 1492 | I915_WRITE(CBR4_VLV, CBR_DPLLBMD_PIPE(pipe)); |
c231775c VS |
1493 | I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md); |
1494 | I915_WRITE(CBR4_VLV, 0); | |
1495 | dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md; | |
1496 | ||
1497 | /* | |
1498 | * DPLLB VGA mode also seems to cause problems. | |
1499 | * We should always have it disabled. | |
1500 | */ | |
1501 | WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0); | |
1502 | } else { | |
1503 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); | |
1504 | POSTING_READ(DPLL_MD(pipe)); | |
1505 | } | |
9d556c99 CML |
1506 | } |
1507 | ||
6315b5d3 | 1508 | static int intel_num_dvo_pipes(struct drm_i915_private *dev_priv) |
1c4e0274 VS |
1509 | { |
1510 | struct intel_crtc *crtc; | |
1511 | int count = 0; | |
1512 | ||
6315b5d3 | 1513 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
3538b9df | 1514 | count += crtc->base.state->active && |
2d84d2b3 VS |
1515 | intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO); |
1516 | } | |
1c4e0274 VS |
1517 | |
1518 | return count; | |
1519 | } | |
1520 | ||
939994da VS |
1521 | static void i9xx_enable_pll(struct intel_crtc *crtc, |
1522 | const struct intel_crtc_state *crtc_state) | |
63d7bbe9 | 1523 | { |
6315b5d3 | 1524 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
f0f59a00 | 1525 | i915_reg_t reg = DPLL(crtc->pipe); |
939994da | 1526 | u32 dpll = crtc_state->dpll_hw_state.dpll; |
bb408dd2 | 1527 | int i; |
63d7bbe9 | 1528 | |
66e3d5c0 | 1529 | assert_pipe_disabled(dev_priv, crtc->pipe); |
58c6eaa2 | 1530 | |
63d7bbe9 | 1531 | /* PLL is protected by panel, make sure we can write it */ |
50a0bc90 | 1532 | if (IS_MOBILE(dev_priv) && !IS_I830(dev_priv)) |
66e3d5c0 | 1533 | assert_panel_unlocked(dev_priv, crtc->pipe); |
63d7bbe9 | 1534 | |
1c4e0274 | 1535 | /* Enable DVO 2x clock on both PLLs if necessary */ |
6315b5d3 | 1536 | if (IS_I830(dev_priv) && intel_num_dvo_pipes(dev_priv) > 0) { |
1c4e0274 VS |
1537 | /* |
1538 | * It appears to be important that we don't enable this | |
1539 | * for the current pipe before otherwise configuring the | |
1540 | * PLL. No idea how this should be handled if multiple | |
1541 | * DVO outputs are enabled simultaneosly. | |
1542 | */ | |
1543 | dpll |= DPLL_DVO_2X_MODE; | |
1544 | I915_WRITE(DPLL(!crtc->pipe), | |
1545 | I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE); | |
1546 | } | |
66e3d5c0 | 1547 | |
c2b63374 VS |
1548 | /* |
1549 | * Apparently we need to have VGA mode enabled prior to changing | |
1550 | * the P1/P2 dividers. Otherwise the DPLL will keep using the old | |
1551 | * dividers, even though the register value does change. | |
1552 | */ | |
1553 | I915_WRITE(reg, 0); | |
1554 | ||
8e7a65aa VS |
1555 | I915_WRITE(reg, dpll); |
1556 | ||
66e3d5c0 DV |
1557 | /* Wait for the clocks to stabilize. */ |
1558 | POSTING_READ(reg); | |
1559 | udelay(150); | |
1560 | ||
6315b5d3 | 1561 | if (INTEL_GEN(dev_priv) >= 4) { |
66e3d5c0 | 1562 | I915_WRITE(DPLL_MD(crtc->pipe), |
939994da | 1563 | crtc_state->dpll_hw_state.dpll_md); |
66e3d5c0 DV |
1564 | } else { |
1565 | /* The pixel multiplier can only be updated once the | |
1566 | * DPLL is enabled and the clocks are stable. | |
1567 | * | |
1568 | * So write it again. | |
1569 | */ | |
1570 | I915_WRITE(reg, dpll); | |
1571 | } | |
63d7bbe9 JB |
1572 | |
1573 | /* We do this three times for luck */ | |
bb408dd2 VS |
1574 | for (i = 0; i < 3; i++) { |
1575 | I915_WRITE(reg, dpll); | |
1576 | POSTING_READ(reg); | |
1577 | udelay(150); /* wait for warmup */ | |
1578 | } | |
63d7bbe9 JB |
1579 | } |
1580 | ||
1c4e0274 | 1581 | static void i9xx_disable_pll(struct intel_crtc *crtc) |
63d7bbe9 | 1582 | { |
6315b5d3 | 1583 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
1c4e0274 VS |
1584 | enum pipe pipe = crtc->pipe; |
1585 | ||
1586 | /* Disable DVO 2x clock on both PLLs if necessary */ | |
50a0bc90 | 1587 | if (IS_I830(dev_priv) && |
2d84d2b3 | 1588 | intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO) && |
6315b5d3 | 1589 | !intel_num_dvo_pipes(dev_priv)) { |
1c4e0274 VS |
1590 | I915_WRITE(DPLL(PIPE_B), |
1591 | I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE); | |
1592 | I915_WRITE(DPLL(PIPE_A), | |
1593 | I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE); | |
1594 | } | |
1595 | ||
b6b5d049 | 1596 | /* Don't disable pipe or pipe PLLs if needed */ |
e56134bc | 1597 | if (IS_I830(dev_priv)) |
63d7bbe9 JB |
1598 | return; |
1599 | ||
1600 | /* Make sure the pipe isn't still relying on us */ | |
1601 | assert_pipe_disabled(dev_priv, pipe); | |
1602 | ||
b8afb911 | 1603 | I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS); |
50b44a44 | 1604 | POSTING_READ(DPLL(pipe)); |
63d7bbe9 JB |
1605 | } |
1606 | ||
f6071166 JB |
1607 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
1608 | { | |
b8afb911 | 1609 | u32 val; |
f6071166 JB |
1610 | |
1611 | /* Make sure the pipe isn't still relying on us */ | |
1612 | assert_pipe_disabled(dev_priv, pipe); | |
1613 | ||
03ed5cbf VS |
1614 | val = DPLL_INTEGRATED_REF_CLK_VLV | |
1615 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; | |
1616 | if (pipe != PIPE_A) | |
1617 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
1618 | ||
f6071166 JB |
1619 | I915_WRITE(DPLL(pipe), val); |
1620 | POSTING_READ(DPLL(pipe)); | |
076ed3b2 CML |
1621 | } |
1622 | ||
1623 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) | |
1624 | { | |
d752048d | 1625 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
076ed3b2 CML |
1626 | u32 val; |
1627 | ||
a11b0703 VS |
1628 | /* Make sure the pipe isn't still relying on us */ |
1629 | assert_pipe_disabled(dev_priv, pipe); | |
076ed3b2 | 1630 | |
60bfe44f VS |
1631 | val = DPLL_SSC_REF_CLK_CHV | |
1632 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; | |
a11b0703 VS |
1633 | if (pipe != PIPE_A) |
1634 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
03ed5cbf | 1635 | |
a11b0703 VS |
1636 | I915_WRITE(DPLL(pipe), val); |
1637 | POSTING_READ(DPLL(pipe)); | |
d752048d | 1638 | |
a580516d | 1639 | mutex_lock(&dev_priv->sb_lock); |
d752048d VS |
1640 | |
1641 | /* Disable 10bit clock to display controller */ | |
1642 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); | |
1643 | val &= ~DPIO_DCLKP_EN; | |
1644 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); | |
1645 | ||
a580516d | 1646 | mutex_unlock(&dev_priv->sb_lock); |
f6071166 JB |
1647 | } |
1648 | ||
e4607fcf | 1649 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, |
9b6de0a1 VS |
1650 | struct intel_digital_port *dport, |
1651 | unsigned int expected_mask) | |
89b667f8 JB |
1652 | { |
1653 | u32 port_mask; | |
f0f59a00 | 1654 | i915_reg_t dpll_reg; |
89b667f8 | 1655 | |
e4607fcf CML |
1656 | switch (dport->port) { |
1657 | case PORT_B: | |
89b667f8 | 1658 | port_mask = DPLL_PORTB_READY_MASK; |
00fc31b7 | 1659 | dpll_reg = DPLL(0); |
e4607fcf CML |
1660 | break; |
1661 | case PORT_C: | |
89b667f8 | 1662 | port_mask = DPLL_PORTC_READY_MASK; |
00fc31b7 | 1663 | dpll_reg = DPLL(0); |
9b6de0a1 | 1664 | expected_mask <<= 4; |
00fc31b7 CML |
1665 | break; |
1666 | case PORT_D: | |
1667 | port_mask = DPLL_PORTD_READY_MASK; | |
1668 | dpll_reg = DPIO_PHY_STATUS; | |
e4607fcf CML |
1669 | break; |
1670 | default: | |
1671 | BUG(); | |
1672 | } | |
89b667f8 | 1673 | |
370004d3 CW |
1674 | if (intel_wait_for_register(dev_priv, |
1675 | dpll_reg, port_mask, expected_mask, | |
1676 | 1000)) | |
9b6de0a1 VS |
1677 | WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n", |
1678 | port_name(dport->port), I915_READ(dpll_reg) & port_mask, expected_mask); | |
89b667f8 JB |
1679 | } |
1680 | ||
b8a4f404 PZ |
1681 | static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
1682 | enum pipe pipe) | |
040484af | 1683 | { |
98187836 VS |
1684 | struct intel_crtc *intel_crtc = intel_get_crtc_for_pipe(dev_priv, |
1685 | pipe); | |
f0f59a00 VS |
1686 | i915_reg_t reg; |
1687 | uint32_t val, pipeconf_val; | |
040484af | 1688 | |
040484af | 1689 | /* Make sure PCH DPLL is enabled */ |
8106ddbd | 1690 | assert_shared_dpll_enabled(dev_priv, intel_crtc->config->shared_dpll); |
040484af JB |
1691 | |
1692 | /* FDI must be feeding us bits for PCH ports */ | |
1693 | assert_fdi_tx_enabled(dev_priv, pipe); | |
1694 | assert_fdi_rx_enabled(dev_priv, pipe); | |
1695 | ||
6e266956 | 1696 | if (HAS_PCH_CPT(dev_priv)) { |
23670b32 DV |
1697 | /* Workaround: Set the timing override bit before enabling the |
1698 | * pch transcoder. */ | |
1699 | reg = TRANS_CHICKEN2(pipe); | |
1700 | val = I915_READ(reg); | |
1701 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; | |
1702 | I915_WRITE(reg, val); | |
59c859d6 | 1703 | } |
23670b32 | 1704 | |
ab9412ba | 1705 | reg = PCH_TRANSCONF(pipe); |
040484af | 1706 | val = I915_READ(reg); |
5f7f726d | 1707 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
e9bcff5c | 1708 | |
2d1fe073 | 1709 | if (HAS_PCH_IBX(dev_priv)) { |
e9bcff5c | 1710 | /* |
c5de7c6f VS |
1711 | * Make the BPC in transcoder be consistent with |
1712 | * that in pipeconf reg. For HDMI we must use 8bpc | |
1713 | * here for both 8bpc and 12bpc. | |
e9bcff5c | 1714 | */ |
dfd07d72 | 1715 | val &= ~PIPECONF_BPC_MASK; |
2d84d2b3 | 1716 | if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_HDMI)) |
c5de7c6f VS |
1717 | val |= PIPECONF_8BPC; |
1718 | else | |
1719 | val |= pipeconf_val & PIPECONF_BPC_MASK; | |
e9bcff5c | 1720 | } |
5f7f726d PZ |
1721 | |
1722 | val &= ~TRANS_INTERLACE_MASK; | |
1723 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) | |
2d1fe073 | 1724 | if (HAS_PCH_IBX(dev_priv) && |
2d84d2b3 | 1725 | intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO)) |
7c26e5c6 PZ |
1726 | val |= TRANS_LEGACY_INTERLACED_ILK; |
1727 | else | |
1728 | val |= TRANS_INTERLACED; | |
5f7f726d PZ |
1729 | else |
1730 | val |= TRANS_PROGRESSIVE; | |
1731 | ||
040484af | 1732 | I915_WRITE(reg, val | TRANS_ENABLE); |
650fbd84 CW |
1733 | if (intel_wait_for_register(dev_priv, |
1734 | reg, TRANS_STATE_ENABLE, TRANS_STATE_ENABLE, | |
1735 | 100)) | |
4bb6f1f3 | 1736 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
040484af JB |
1737 | } |
1738 | ||
8fb033d7 | 1739 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
937bb610 | 1740 | enum transcoder cpu_transcoder) |
040484af | 1741 | { |
8fb033d7 | 1742 | u32 val, pipeconf_val; |
8fb033d7 | 1743 | |
8fb033d7 | 1744 | /* FDI must be feeding us bits for PCH ports */ |
1a240d4d | 1745 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
a2196033 | 1746 | assert_fdi_rx_enabled(dev_priv, PIPE_A); |
8fb033d7 | 1747 | |
223a6fdf | 1748 | /* Workaround: set timing override bit. */ |
36c0d0cf | 1749 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
23670b32 | 1750 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
36c0d0cf | 1751 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
223a6fdf | 1752 | |
25f3ef11 | 1753 | val = TRANS_ENABLE; |
937bb610 | 1754 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
8fb033d7 | 1755 | |
9a76b1c6 PZ |
1756 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
1757 | PIPECONF_INTERLACED_ILK) | |
a35f2679 | 1758 | val |= TRANS_INTERLACED; |
8fb033d7 PZ |
1759 | else |
1760 | val |= TRANS_PROGRESSIVE; | |
1761 | ||
ab9412ba | 1762 | I915_WRITE(LPT_TRANSCONF, val); |
d9f96244 CW |
1763 | if (intel_wait_for_register(dev_priv, |
1764 | LPT_TRANSCONF, | |
1765 | TRANS_STATE_ENABLE, | |
1766 | TRANS_STATE_ENABLE, | |
1767 | 100)) | |
937bb610 | 1768 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
8fb033d7 PZ |
1769 | } |
1770 | ||
b8a4f404 PZ |
1771 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
1772 | enum pipe pipe) | |
040484af | 1773 | { |
f0f59a00 VS |
1774 | i915_reg_t reg; |
1775 | uint32_t val; | |
040484af JB |
1776 | |
1777 | /* FDI relies on the transcoder */ | |
1778 | assert_fdi_tx_disabled(dev_priv, pipe); | |
1779 | assert_fdi_rx_disabled(dev_priv, pipe); | |
1780 | ||
291906f1 JB |
1781 | /* Ports must be off as well */ |
1782 | assert_pch_ports_disabled(dev_priv, pipe); | |
1783 | ||
ab9412ba | 1784 | reg = PCH_TRANSCONF(pipe); |
040484af JB |
1785 | val = I915_READ(reg); |
1786 | val &= ~TRANS_ENABLE; | |
1787 | I915_WRITE(reg, val); | |
1788 | /* wait for PCH transcoder off, transcoder state */ | |
a7d04662 CW |
1789 | if (intel_wait_for_register(dev_priv, |
1790 | reg, TRANS_STATE_ENABLE, 0, | |
1791 | 50)) | |
4bb6f1f3 | 1792 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
23670b32 | 1793 | |
6e266956 | 1794 | if (HAS_PCH_CPT(dev_priv)) { |
23670b32 DV |
1795 | /* Workaround: Clear the timing override chicken bit again. */ |
1796 | reg = TRANS_CHICKEN2(pipe); | |
1797 | val = I915_READ(reg); | |
1798 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; | |
1799 | I915_WRITE(reg, val); | |
1800 | } | |
040484af JB |
1801 | } |
1802 | ||
b7076546 | 1803 | void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
8fb033d7 | 1804 | { |
8fb033d7 PZ |
1805 | u32 val; |
1806 | ||
ab9412ba | 1807 | val = I915_READ(LPT_TRANSCONF); |
8fb033d7 | 1808 | val &= ~TRANS_ENABLE; |
ab9412ba | 1809 | I915_WRITE(LPT_TRANSCONF, val); |
8fb033d7 | 1810 | /* wait for PCH transcoder off, transcoder state */ |
dfdb4749 CW |
1811 | if (intel_wait_for_register(dev_priv, |
1812 | LPT_TRANSCONF, TRANS_STATE_ENABLE, 0, | |
1813 | 50)) | |
8a52fd9f | 1814 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
223a6fdf PZ |
1815 | |
1816 | /* Workaround: clear timing override bit. */ | |
36c0d0cf | 1817 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
23670b32 | 1818 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
36c0d0cf | 1819 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
040484af JB |
1820 | } |
1821 | ||
a2196033 | 1822 | enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc) |
65f2130c VS |
1823 | { |
1824 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); | |
1825 | ||
1826 | WARN_ON(!crtc->config->has_pch_encoder); | |
1827 | ||
1828 | if (HAS_PCH_LPT(dev_priv)) | |
a2196033 | 1829 | return PIPE_A; |
65f2130c | 1830 | else |
a2196033 | 1831 | return crtc->pipe; |
65f2130c VS |
1832 | } |
1833 | ||
b24e7179 | 1834 | /** |
309cfea8 | 1835 | * intel_enable_pipe - enable a pipe, asserting requirements |
0372264a | 1836 | * @crtc: crtc responsible for the pipe |
b24e7179 | 1837 | * |
0372264a | 1838 | * Enable @crtc's pipe, making sure that various hardware specific requirements |
b24e7179 | 1839 | * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc. |
b24e7179 | 1840 | */ |
e1fdc473 | 1841 | static void intel_enable_pipe(struct intel_crtc *crtc) |
b24e7179 | 1842 | { |
0372264a | 1843 | struct drm_device *dev = crtc->base.dev; |
fac5e23e | 1844 | struct drm_i915_private *dev_priv = to_i915(dev); |
0372264a | 1845 | enum pipe pipe = crtc->pipe; |
1a70a728 | 1846 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
f0f59a00 | 1847 | i915_reg_t reg; |
b24e7179 JB |
1848 | u32 val; |
1849 | ||
9e2ee2dd VS |
1850 | DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe)); |
1851 | ||
d87ce764 | 1852 | assert_planes_disabled(crtc); |
58c6eaa2 | 1853 | |
b24e7179 JB |
1854 | /* |
1855 | * A pipe without a PLL won't actually be able to drive bits from | |
1856 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't | |
1857 | * need the check. | |
1858 | */ | |
09fa8bb9 | 1859 | if (HAS_GMCH_DISPLAY(dev_priv)) { |
d7edc4e5 | 1860 | if (intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DSI)) |
23538ef1 JN |
1861 | assert_dsi_pll_enabled(dev_priv); |
1862 | else | |
1863 | assert_pll_enabled(dev_priv, pipe); | |
09fa8bb9 | 1864 | } else { |
6e3c9717 | 1865 | if (crtc->config->has_pch_encoder) { |
040484af | 1866 | /* if driving the PCH, we need FDI enabled */ |
65f2130c | 1867 | assert_fdi_rx_pll_enabled(dev_priv, |
a2196033 | 1868 | intel_crtc_pch_transcoder(crtc)); |
1a240d4d DV |
1869 | assert_fdi_tx_pll_enabled(dev_priv, |
1870 | (enum pipe) cpu_transcoder); | |
040484af JB |
1871 | } |
1872 | /* FIXME: assert CPU port conditions for SNB+ */ | |
1873 | } | |
b24e7179 | 1874 | |
702e7a56 | 1875 | reg = PIPECONF(cpu_transcoder); |
b24e7179 | 1876 | val = I915_READ(reg); |
7ad25d48 | 1877 | if (val & PIPECONF_ENABLE) { |
e56134bc VS |
1878 | /* we keep both pipes enabled on 830 */ |
1879 | WARN_ON(!IS_I830(dev_priv)); | |
00d70b15 | 1880 | return; |
7ad25d48 | 1881 | } |
00d70b15 CW |
1882 | |
1883 | I915_WRITE(reg, val | PIPECONF_ENABLE); | |
851855d8 | 1884 | POSTING_READ(reg); |
b7792d8b VS |
1885 | |
1886 | /* | |
a87e55f8 VS |
1887 | * Until the pipe starts PIPEDSL reads will return a stale value, |
1888 | * which causes an apparent vblank timestamp jump when PIPEDSL | |
1889 | * resets to its proper value. That also messes up the frame count | |
1890 | * when it's derived from the timestamps. So let's wait for the | |
1891 | * pipe to start properly before we call drm_crtc_vblank_on() | |
b7792d8b | 1892 | */ |
a87e55f8 VS |
1893 | if (dev->max_vblank_count == 0) |
1894 | intel_wait_for_pipe_scanline_moving(crtc); | |
b24e7179 JB |
1895 | } |
1896 | ||
1897 | /** | |
309cfea8 | 1898 | * intel_disable_pipe - disable a pipe, asserting requirements |
575f7ab7 | 1899 | * @crtc: crtc whose pipes is to be disabled |
b24e7179 | 1900 | * |
575f7ab7 VS |
1901 | * Disable the pipe of @crtc, making sure that various hardware |
1902 | * specific requirements are met, if applicable, e.g. plane | |
1903 | * disabled, panel fitter off, etc. | |
b24e7179 JB |
1904 | * |
1905 | * Will wait until the pipe has shut down before returning. | |
1906 | */ | |
575f7ab7 | 1907 | static void intel_disable_pipe(struct intel_crtc *crtc) |
b24e7179 | 1908 | { |
fac5e23e | 1909 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
6e3c9717 | 1910 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
575f7ab7 | 1911 | enum pipe pipe = crtc->pipe; |
f0f59a00 | 1912 | i915_reg_t reg; |
b24e7179 JB |
1913 | u32 val; |
1914 | ||
9e2ee2dd VS |
1915 | DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe)); |
1916 | ||
b24e7179 JB |
1917 | /* |
1918 | * Make sure planes won't keep trying to pump pixels to us, | |
1919 | * or we might hang the display. | |
1920 | */ | |
d87ce764 | 1921 | assert_planes_disabled(crtc); |
b24e7179 | 1922 | |
702e7a56 | 1923 | reg = PIPECONF(cpu_transcoder); |
b24e7179 | 1924 | val = I915_READ(reg); |
00d70b15 CW |
1925 | if ((val & PIPECONF_ENABLE) == 0) |
1926 | return; | |
1927 | ||
67adc644 VS |
1928 | /* |
1929 | * Double wide has implications for planes | |
1930 | * so best keep it disabled when not needed. | |
1931 | */ | |
6e3c9717 | 1932 | if (crtc->config->double_wide) |
67adc644 VS |
1933 | val &= ~PIPECONF_DOUBLE_WIDE; |
1934 | ||
1935 | /* Don't disable pipe or pipe PLLs if needed */ | |
e56134bc | 1936 | if (!IS_I830(dev_priv)) |
67adc644 VS |
1937 | val &= ~PIPECONF_ENABLE; |
1938 | ||
1939 | I915_WRITE(reg, val); | |
1940 | if ((val & PIPECONF_ENABLE) == 0) | |
1941 | intel_wait_for_pipe_off(crtc); | |
b24e7179 JB |
1942 | } |
1943 | ||
832be82f VS |
1944 | static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv) |
1945 | { | |
1946 | return IS_GEN2(dev_priv) ? 2048 : 4096; | |
1947 | } | |
1948 | ||
d88c4afd VS |
1949 | static unsigned int |
1950 | intel_tile_width_bytes(const struct drm_framebuffer *fb, int plane) | |
7b49f948 | 1951 | { |
d88c4afd VS |
1952 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
1953 | unsigned int cpp = fb->format->cpp[plane]; | |
1954 | ||
1955 | switch (fb->modifier) { | |
2f075565 | 1956 | case DRM_FORMAT_MOD_LINEAR: |
7b49f948 VS |
1957 | return cpp; |
1958 | case I915_FORMAT_MOD_X_TILED: | |
1959 | if (IS_GEN2(dev_priv)) | |
1960 | return 128; | |
1961 | else | |
1962 | return 512; | |
2e2adb05 VS |
1963 | case I915_FORMAT_MOD_Y_TILED_CCS: |
1964 | if (plane == 1) | |
1965 | return 128; | |
1966 | /* fall through */ | |
7b49f948 VS |
1967 | case I915_FORMAT_MOD_Y_TILED: |
1968 | if (IS_GEN2(dev_priv) || HAS_128_BYTE_Y_TILING(dev_priv)) | |
1969 | return 128; | |
1970 | else | |
1971 | return 512; | |
2e2adb05 VS |
1972 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
1973 | if (plane == 1) | |
1974 | return 128; | |
1975 | /* fall through */ | |
7b49f948 VS |
1976 | case I915_FORMAT_MOD_Yf_TILED: |
1977 | switch (cpp) { | |
1978 | case 1: | |
1979 | return 64; | |
1980 | case 2: | |
1981 | case 4: | |
1982 | return 128; | |
1983 | case 8: | |
1984 | case 16: | |
1985 | return 256; | |
1986 | default: | |
1987 | MISSING_CASE(cpp); | |
1988 | return cpp; | |
1989 | } | |
1990 | break; | |
1991 | default: | |
d88c4afd | 1992 | MISSING_CASE(fb->modifier); |
7b49f948 VS |
1993 | return cpp; |
1994 | } | |
1995 | } | |
1996 | ||
d88c4afd VS |
1997 | static unsigned int |
1998 | intel_tile_height(const struct drm_framebuffer *fb, int plane) | |
a57ce0b2 | 1999 | { |
2f075565 | 2000 | if (fb->modifier == DRM_FORMAT_MOD_LINEAR) |
832be82f VS |
2001 | return 1; |
2002 | else | |
d88c4afd VS |
2003 | return intel_tile_size(to_i915(fb->dev)) / |
2004 | intel_tile_width_bytes(fb, plane); | |
6761dd31 TU |
2005 | } |
2006 | ||
8d0deca8 | 2007 | /* Return the tile dimensions in pixel units */ |
d88c4afd | 2008 | static void intel_tile_dims(const struct drm_framebuffer *fb, int plane, |
8d0deca8 | 2009 | unsigned int *tile_width, |
d88c4afd | 2010 | unsigned int *tile_height) |
8d0deca8 | 2011 | { |
d88c4afd VS |
2012 | unsigned int tile_width_bytes = intel_tile_width_bytes(fb, plane); |
2013 | unsigned int cpp = fb->format->cpp[plane]; | |
8d0deca8 VS |
2014 | |
2015 | *tile_width = tile_width_bytes / cpp; | |
d88c4afd | 2016 | *tile_height = intel_tile_size(to_i915(fb->dev)) / tile_width_bytes; |
8d0deca8 VS |
2017 | } |
2018 | ||
6761dd31 | 2019 | unsigned int |
d88c4afd VS |
2020 | intel_fb_align_height(const struct drm_framebuffer *fb, |
2021 | int plane, unsigned int height) | |
6761dd31 | 2022 | { |
d88c4afd | 2023 | unsigned int tile_height = intel_tile_height(fb, plane); |
832be82f VS |
2024 | |
2025 | return ALIGN(height, tile_height); | |
a57ce0b2 JB |
2026 | } |
2027 | ||
1663b9d6 VS |
2028 | unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info) |
2029 | { | |
2030 | unsigned int size = 0; | |
2031 | int i; | |
2032 | ||
2033 | for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++) | |
2034 | size += rot_info->plane[i].width * rot_info->plane[i].height; | |
2035 | ||
2036 | return size; | |
2037 | } | |
2038 | ||
75c82a53 | 2039 | static void |
3465c580 VS |
2040 | intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, |
2041 | const struct drm_framebuffer *fb, | |
2042 | unsigned int rotation) | |
f64b98cd | 2043 | { |
7b92c047 | 2044 | view->type = I915_GGTT_VIEW_NORMAL; |
bd2ef25d | 2045 | if (drm_rotation_90_or_270(rotation)) { |
7b92c047 | 2046 | view->type = I915_GGTT_VIEW_ROTATED; |
8bab1193 | 2047 | view->rotated = to_intel_framebuffer(fb)->rot_info; |
2d7a215f VS |
2048 | } |
2049 | } | |
50470bb0 | 2050 | |
fabac484 VS |
2051 | static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv) |
2052 | { | |
2053 | if (IS_I830(dev_priv)) | |
2054 | return 16 * 1024; | |
2055 | else if (IS_I85X(dev_priv)) | |
2056 | return 256; | |
d9e1551e VS |
2057 | else if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) |
2058 | return 32; | |
fabac484 VS |
2059 | else |
2060 | return 4 * 1024; | |
2061 | } | |
2062 | ||
603525d7 | 2063 | static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv) |
4e9a86b6 VS |
2064 | { |
2065 | if (INTEL_INFO(dev_priv)->gen >= 9) | |
2066 | return 256 * 1024; | |
c0f86832 | 2067 | else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) || |
666a4537 | 2068 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
4e9a86b6 VS |
2069 | return 128 * 1024; |
2070 | else if (INTEL_INFO(dev_priv)->gen >= 4) | |
2071 | return 4 * 1024; | |
2072 | else | |
44c5905e | 2073 | return 0; |
4e9a86b6 VS |
2074 | } |
2075 | ||
d88c4afd VS |
2076 | static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb, |
2077 | int plane) | |
603525d7 | 2078 | { |
d88c4afd VS |
2079 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
2080 | ||
b90c1ee1 | 2081 | /* AUX_DIST needs only 4K alignment */ |
2e2adb05 | 2082 | if (plane == 1) |
b90c1ee1 VS |
2083 | return 4096; |
2084 | ||
d88c4afd | 2085 | switch (fb->modifier) { |
2f075565 | 2086 | case DRM_FORMAT_MOD_LINEAR: |
603525d7 VS |
2087 | return intel_linear_alignment(dev_priv); |
2088 | case I915_FORMAT_MOD_X_TILED: | |
d88c4afd | 2089 | if (INTEL_GEN(dev_priv) >= 9) |
603525d7 VS |
2090 | return 256 * 1024; |
2091 | return 0; | |
2e2adb05 VS |
2092 | case I915_FORMAT_MOD_Y_TILED_CCS: |
2093 | case I915_FORMAT_MOD_Yf_TILED_CCS: | |
603525d7 VS |
2094 | case I915_FORMAT_MOD_Y_TILED: |
2095 | case I915_FORMAT_MOD_Yf_TILED: | |
2096 | return 1 * 1024 * 1024; | |
2097 | default: | |
d88c4afd | 2098 | MISSING_CASE(fb->modifier); |
603525d7 VS |
2099 | return 0; |
2100 | } | |
2101 | } | |
2102 | ||
058d88c4 CW |
2103 | struct i915_vma * |
2104 | intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, unsigned int rotation) | |
6b95a207 | 2105 | { |
850c4cdc | 2106 | struct drm_device *dev = fb->dev; |
fac5e23e | 2107 | struct drm_i915_private *dev_priv = to_i915(dev); |
850c4cdc | 2108 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
f64b98cd | 2109 | struct i915_ggtt_view view; |
058d88c4 | 2110 | struct i915_vma *vma; |
6b95a207 | 2111 | u32 alignment; |
6b95a207 | 2112 | |
ebcdd39e MR |
2113 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
2114 | ||
d88c4afd | 2115 | alignment = intel_surf_alignment(fb, 0); |
6b95a207 | 2116 | |
3465c580 | 2117 | intel_fill_fb_ggtt_view(&view, fb, rotation); |
f64b98cd | 2118 | |
693db184 CW |
2119 | /* Note that the w/a also requires 64 PTE of padding following the |
2120 | * bo. We currently fill all unused PTE with the shadow page and so | |
2121 | * we should always have valid PTE following the scanout preventing | |
2122 | * the VT-d warning. | |
2123 | */ | |
48f112fe | 2124 | if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024) |
693db184 CW |
2125 | alignment = 256 * 1024; |
2126 | ||
d6dd6843 PZ |
2127 | /* |
2128 | * Global gtt pte registers are special registers which actually forward | |
2129 | * writes to a chunk of system memory. Which means that there is no risk | |
2130 | * that the register values disappear as soon as we call | |
2131 | * intel_runtime_pm_put(), so it is correct to wrap only the | |
2132 | * pin/unpin/fence and not more. | |
2133 | */ | |
2134 | intel_runtime_pm_get(dev_priv); | |
2135 | ||
9db529aa DV |
2136 | atomic_inc(&dev_priv->gpu_error.pending_fb_pin); |
2137 | ||
058d88c4 | 2138 | vma = i915_gem_object_pin_to_display_plane(obj, alignment, &view); |
49ef5294 CW |
2139 | if (IS_ERR(vma)) |
2140 | goto err; | |
6b95a207 | 2141 | |
05a20d09 | 2142 | if (i915_vma_is_map_and_fenceable(vma)) { |
49ef5294 CW |
2143 | /* Install a fence for tiled scan-out. Pre-i965 always needs a |
2144 | * fence, whereas 965+ only requires a fence if using | |
2145 | * framebuffer compression. For simplicity, we always, when | |
2146 | * possible, install a fence as the cost is not that onerous. | |
2147 | * | |
2148 | * If we fail to fence the tiled scanout, then either the | |
2149 | * modeset will reject the change (which is highly unlikely as | |
2150 | * the affected systems, all but one, do not have unmappable | |
2151 | * space) or we will not be able to enable full powersaving | |
2152 | * techniques (also likely not to apply due to various limits | |
2153 | * FBC and the like impose on the size of the buffer, which | |
2154 | * presumably we violated anyway with this unmappable buffer). | |
2155 | * Anyway, it is presumably better to stumble onwards with | |
2156 | * something and try to run the system in a "less than optimal" | |
2157 | * mode that matches the user configuration. | |
2158 | */ | |
3bd40735 | 2159 | i915_vma_pin_fence(vma); |
9807216f | 2160 | } |
6b95a207 | 2161 | |
be1e3415 | 2162 | i915_vma_get(vma); |
49ef5294 | 2163 | err: |
9db529aa DV |
2164 | atomic_dec(&dev_priv->gpu_error.pending_fb_pin); |
2165 | ||
d6dd6843 | 2166 | intel_runtime_pm_put(dev_priv); |
058d88c4 | 2167 | return vma; |
6b95a207 KH |
2168 | } |
2169 | ||
be1e3415 | 2170 | void intel_unpin_fb_vma(struct i915_vma *vma) |
1690e1eb | 2171 | { |
be1e3415 | 2172 | lockdep_assert_held(&vma->vm->i915->drm.struct_mutex); |
f64b98cd | 2173 | |
49ef5294 | 2174 | i915_vma_unpin_fence(vma); |
058d88c4 | 2175 | i915_gem_object_unpin_from_display_plane(vma); |
be1e3415 | 2176 | i915_vma_put(vma); |
1690e1eb CW |
2177 | } |
2178 | ||
ef78ec94 VS |
2179 | static int intel_fb_pitch(const struct drm_framebuffer *fb, int plane, |
2180 | unsigned int rotation) | |
2181 | { | |
bd2ef25d | 2182 | if (drm_rotation_90_or_270(rotation)) |
ef78ec94 VS |
2183 | return to_intel_framebuffer(fb)->rotated[plane].pitch; |
2184 | else | |
2185 | return fb->pitches[plane]; | |
2186 | } | |
2187 | ||
6687c906 VS |
2188 | /* |
2189 | * Convert the x/y offsets into a linear offset. | |
2190 | * Only valid with 0/180 degree rotation, which is fine since linear | |
2191 | * offset is only used with linear buffers on pre-hsw and tiled buffers | |
2192 | * with gen2/3, and 90/270 degree rotations isn't supported on any of them. | |
2193 | */ | |
2194 | u32 intel_fb_xy_to_linear(int x, int y, | |
2949056c VS |
2195 | const struct intel_plane_state *state, |
2196 | int plane) | |
6687c906 | 2197 | { |
2949056c | 2198 | const struct drm_framebuffer *fb = state->base.fb; |
353c8598 | 2199 | unsigned int cpp = fb->format->cpp[plane]; |
6687c906 VS |
2200 | unsigned int pitch = fb->pitches[plane]; |
2201 | ||
2202 | return y * pitch + x * cpp; | |
2203 | } | |
2204 | ||
2205 | /* | |
2206 | * Add the x/y offsets derived from fb->offsets[] to the user | |
2207 | * specified plane src x/y offsets. The resulting x/y offsets | |
2208 | * specify the start of scanout from the beginning of the gtt mapping. | |
2209 | */ | |
2210 | void intel_add_fb_offsets(int *x, int *y, | |
2949056c VS |
2211 | const struct intel_plane_state *state, |
2212 | int plane) | |
6687c906 VS |
2213 | |
2214 | { | |
2949056c VS |
2215 | const struct intel_framebuffer *intel_fb = to_intel_framebuffer(state->base.fb); |
2216 | unsigned int rotation = state->base.rotation; | |
6687c906 | 2217 | |
bd2ef25d | 2218 | if (drm_rotation_90_or_270(rotation)) { |
6687c906 VS |
2219 | *x += intel_fb->rotated[plane].x; |
2220 | *y += intel_fb->rotated[plane].y; | |
2221 | } else { | |
2222 | *x += intel_fb->normal[plane].x; | |
2223 | *y += intel_fb->normal[plane].y; | |
2224 | } | |
2225 | } | |
2226 | ||
e8837d98 VS |
2227 | static u32 __intel_adjust_tile_offset(int *x, int *y, |
2228 | unsigned int tile_width, | |
2229 | unsigned int tile_height, | |
2230 | unsigned int tile_size, | |
2231 | unsigned int pitch_tiles, | |
2232 | u32 old_offset, | |
2233 | u32 new_offset) | |
29cf9491 | 2234 | { |
b9b24038 | 2235 | unsigned int pitch_pixels = pitch_tiles * tile_width; |
29cf9491 VS |
2236 | unsigned int tiles; |
2237 | ||
2238 | WARN_ON(old_offset & (tile_size - 1)); | |
2239 | WARN_ON(new_offset & (tile_size - 1)); | |
2240 | WARN_ON(new_offset > old_offset); | |
2241 | ||
2242 | tiles = (old_offset - new_offset) / tile_size; | |
2243 | ||
2244 | *y += tiles / pitch_tiles * tile_height; | |
2245 | *x += tiles % pitch_tiles * tile_width; | |
2246 | ||
b9b24038 VS |
2247 | /* minimize x in case it got needlessly big */ |
2248 | *y += *x / pitch_pixels * tile_height; | |
2249 | *x %= pitch_pixels; | |
2250 | ||
29cf9491 VS |
2251 | return new_offset; |
2252 | } | |
2253 | ||
e8837d98 VS |
2254 | static u32 _intel_adjust_tile_offset(int *x, int *y, |
2255 | const struct drm_framebuffer *fb, int plane, | |
2256 | unsigned int rotation, | |
2257 | u32 old_offset, u32 new_offset) | |
66a2d927 | 2258 | { |
e8837d98 | 2259 | const struct drm_i915_private *dev_priv = to_i915(fb->dev); |
353c8598 | 2260 | unsigned int cpp = fb->format->cpp[plane]; |
66a2d927 VS |
2261 | unsigned int pitch = intel_fb_pitch(fb, plane, rotation); |
2262 | ||
2263 | WARN_ON(new_offset > old_offset); | |
2264 | ||
2f075565 | 2265 | if (fb->modifier != DRM_FORMAT_MOD_LINEAR) { |
66a2d927 VS |
2266 | unsigned int tile_size, tile_width, tile_height; |
2267 | unsigned int pitch_tiles; | |
2268 | ||
2269 | tile_size = intel_tile_size(dev_priv); | |
d88c4afd | 2270 | intel_tile_dims(fb, plane, &tile_width, &tile_height); |
66a2d927 | 2271 | |
bd2ef25d | 2272 | if (drm_rotation_90_or_270(rotation)) { |
66a2d927 VS |
2273 | pitch_tiles = pitch / tile_height; |
2274 | swap(tile_width, tile_height); | |
2275 | } else { | |
2276 | pitch_tiles = pitch / (tile_width * cpp); | |
2277 | } | |
2278 | ||
e8837d98 VS |
2279 | __intel_adjust_tile_offset(x, y, tile_width, tile_height, |
2280 | tile_size, pitch_tiles, | |
2281 | old_offset, new_offset); | |
66a2d927 VS |
2282 | } else { |
2283 | old_offset += *y * pitch + *x * cpp; | |
2284 | ||
2285 | *y = (old_offset - new_offset) / pitch; | |
2286 | *x = ((old_offset - new_offset) - *y * pitch) / cpp; | |
2287 | } | |
2288 | ||
2289 | return new_offset; | |
2290 | } | |
2291 | ||
e8837d98 VS |
2292 | /* |
2293 | * Adjust the tile offset by moving the difference into | |
2294 | * the x/y offsets. | |
2295 | */ | |
2296 | static u32 intel_adjust_tile_offset(int *x, int *y, | |
2297 | const struct intel_plane_state *state, int plane, | |
2298 | u32 old_offset, u32 new_offset) | |
2299 | { | |
2300 | return _intel_adjust_tile_offset(x, y, state->base.fb, plane, | |
2301 | state->base.rotation, | |
2302 | old_offset, new_offset); | |
2303 | } | |
2304 | ||
8d0deca8 VS |
2305 | /* |
2306 | * Computes the linear offset to the base tile and adjusts | |
2307 | * x, y. bytes per pixel is assumed to be a power-of-two. | |
2308 | * | |
2309 | * In the 90/270 rotated case, x and y are assumed | |
2310 | * to be already rotated to match the rotated GTT view, and | |
2311 | * pitch is the tile_height aligned framebuffer height. | |
6687c906 VS |
2312 | * |
2313 | * This function is used when computing the derived information | |
2314 | * under intel_framebuffer, so using any of that information | |
2315 | * here is not allowed. Anything under drm_framebuffer can be | |
2316 | * used. This is why the user has to pass in the pitch since it | |
2317 | * is specified in the rotated orientation. | |
8d0deca8 | 2318 | */ |
6687c906 VS |
2319 | static u32 _intel_compute_tile_offset(const struct drm_i915_private *dev_priv, |
2320 | int *x, int *y, | |
2321 | const struct drm_framebuffer *fb, int plane, | |
2322 | unsigned int pitch, | |
2323 | unsigned int rotation, | |
2324 | u32 alignment) | |
c2c75131 | 2325 | { |
bae781b2 | 2326 | uint64_t fb_modifier = fb->modifier; |
353c8598 | 2327 | unsigned int cpp = fb->format->cpp[plane]; |
6687c906 | 2328 | u32 offset, offset_aligned; |
29cf9491 | 2329 | |
29cf9491 VS |
2330 | if (alignment) |
2331 | alignment--; | |
2332 | ||
2f075565 | 2333 | if (fb_modifier != DRM_FORMAT_MOD_LINEAR) { |
8d0deca8 VS |
2334 | unsigned int tile_size, tile_width, tile_height; |
2335 | unsigned int tile_rows, tiles, pitch_tiles; | |
c2c75131 | 2336 | |
d843310d | 2337 | tile_size = intel_tile_size(dev_priv); |
d88c4afd | 2338 | intel_tile_dims(fb, plane, &tile_width, &tile_height); |
8d0deca8 | 2339 | |
bd2ef25d | 2340 | if (drm_rotation_90_or_270(rotation)) { |
8d0deca8 VS |
2341 | pitch_tiles = pitch / tile_height; |
2342 | swap(tile_width, tile_height); | |
2343 | } else { | |
2344 | pitch_tiles = pitch / (tile_width * cpp); | |
2345 | } | |
d843310d VS |
2346 | |
2347 | tile_rows = *y / tile_height; | |
2348 | *y %= tile_height; | |
c2c75131 | 2349 | |
8d0deca8 VS |
2350 | tiles = *x / tile_width; |
2351 | *x %= tile_width; | |
bc752862 | 2352 | |
29cf9491 VS |
2353 | offset = (tile_rows * pitch_tiles + tiles) * tile_size; |
2354 | offset_aligned = offset & ~alignment; | |
bc752862 | 2355 | |
e8837d98 VS |
2356 | __intel_adjust_tile_offset(x, y, tile_width, tile_height, |
2357 | tile_size, pitch_tiles, | |
2358 | offset, offset_aligned); | |
29cf9491 | 2359 | } else { |
bc752862 | 2360 | offset = *y * pitch + *x * cpp; |
29cf9491 VS |
2361 | offset_aligned = offset & ~alignment; |
2362 | ||
4e9a86b6 VS |
2363 | *y = (offset & alignment) / pitch; |
2364 | *x = ((offset & alignment) - *y * pitch) / cpp; | |
bc752862 | 2365 | } |
29cf9491 VS |
2366 | |
2367 | return offset_aligned; | |
c2c75131 DV |
2368 | } |
2369 | ||
6687c906 | 2370 | u32 intel_compute_tile_offset(int *x, int *y, |
2949056c VS |
2371 | const struct intel_plane_state *state, |
2372 | int plane) | |
6687c906 | 2373 | { |
1e7b4fd8 VS |
2374 | struct intel_plane *intel_plane = to_intel_plane(state->base.plane); |
2375 | struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev); | |
2949056c VS |
2376 | const struct drm_framebuffer *fb = state->base.fb; |
2377 | unsigned int rotation = state->base.rotation; | |
ef78ec94 | 2378 | int pitch = intel_fb_pitch(fb, plane, rotation); |
1e7b4fd8 VS |
2379 | u32 alignment; |
2380 | ||
2381 | if (intel_plane->id == PLANE_CURSOR) | |
2382 | alignment = intel_cursor_alignment(dev_priv); | |
2383 | else | |
2384 | alignment = intel_surf_alignment(fb, plane); | |
6687c906 VS |
2385 | |
2386 | return _intel_compute_tile_offset(dev_priv, x, y, fb, plane, pitch, | |
2387 | rotation, alignment); | |
2388 | } | |
2389 | ||
e8837d98 VS |
2390 | /* Convert the fb->offset[] into x/y offsets */ |
2391 | static int intel_fb_offset_to_xy(int *x, int *y, | |
2392 | const struct drm_framebuffer *fb, int plane) | |
6687c906 | 2393 | { |
e8837d98 VS |
2394 | struct drm_i915_private *dev_priv = to_i915(fb->dev); |
2395 | ||
2396 | if (fb->modifier != DRM_FORMAT_MOD_LINEAR && | |
2397 | fb->offsets[plane] % intel_tile_size(dev_priv)) | |
2398 | return -EINVAL; | |
2399 | ||
2400 | *x = 0; | |
2401 | *y = 0; | |
6687c906 | 2402 | |
e8837d98 VS |
2403 | _intel_adjust_tile_offset(x, y, |
2404 | fb, plane, DRM_MODE_ROTATE_0, | |
2405 | fb->offsets[plane], 0); | |
2406 | ||
2407 | return 0; | |
6687c906 VS |
2408 | } |
2409 | ||
72618ebf VS |
2410 | static unsigned int intel_fb_modifier_to_tiling(uint64_t fb_modifier) |
2411 | { | |
2412 | switch (fb_modifier) { | |
2413 | case I915_FORMAT_MOD_X_TILED: | |
2414 | return I915_TILING_X; | |
2415 | case I915_FORMAT_MOD_Y_TILED: | |
2e2adb05 | 2416 | case I915_FORMAT_MOD_Y_TILED_CCS: |
72618ebf VS |
2417 | return I915_TILING_Y; |
2418 | default: | |
2419 | return I915_TILING_NONE; | |
2420 | } | |
2421 | } | |
2422 | ||
bbfb6ce8 VS |
2423 | static const struct drm_format_info ccs_formats[] = { |
2424 | { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, | |
2425 | { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, | |
2426 | { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, | |
2427 | { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, | |
2428 | }; | |
2429 | ||
2430 | static const struct drm_format_info * | |
2431 | lookup_format_info(const struct drm_format_info formats[], | |
2432 | int num_formats, u32 format) | |
2433 | { | |
2434 | int i; | |
2435 | ||
2436 | for (i = 0; i < num_formats; i++) { | |
2437 | if (formats[i].format == format) | |
2438 | return &formats[i]; | |
2439 | } | |
2440 | ||
2441 | return NULL; | |
2442 | } | |
2443 | ||
2444 | static const struct drm_format_info * | |
2445 | intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd) | |
2446 | { | |
2447 | switch (cmd->modifier[0]) { | |
2448 | case I915_FORMAT_MOD_Y_TILED_CCS: | |
2449 | case I915_FORMAT_MOD_Yf_TILED_CCS: | |
2450 | return lookup_format_info(ccs_formats, | |
2451 | ARRAY_SIZE(ccs_formats), | |
2452 | cmd->pixel_format); | |
2453 | default: | |
2454 | return NULL; | |
2455 | } | |
2456 | } | |
2457 | ||
6687c906 VS |
2458 | static int |
2459 | intel_fill_fb_info(struct drm_i915_private *dev_priv, | |
2460 | struct drm_framebuffer *fb) | |
2461 | { | |
2462 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | |
2463 | struct intel_rotation_info *rot_info = &intel_fb->rot_info; | |
2464 | u32 gtt_offset_rotated = 0; | |
2465 | unsigned int max_size = 0; | |
bcb0b461 | 2466 | int i, num_planes = fb->format->num_planes; |
6687c906 VS |
2467 | unsigned int tile_size = intel_tile_size(dev_priv); |
2468 | ||
2469 | for (i = 0; i < num_planes; i++) { | |
2470 | unsigned int width, height; | |
2471 | unsigned int cpp, size; | |
2472 | u32 offset; | |
2473 | int x, y; | |
e8837d98 | 2474 | int ret; |
6687c906 | 2475 | |
353c8598 | 2476 | cpp = fb->format->cpp[i]; |
145fcb11 VS |
2477 | width = drm_framebuffer_plane_width(fb->width, fb, i); |
2478 | height = drm_framebuffer_plane_height(fb->height, fb, i); | |
6687c906 | 2479 | |
e8837d98 VS |
2480 | ret = intel_fb_offset_to_xy(&x, &y, fb, i); |
2481 | if (ret) { | |
2482 | DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n", | |
2483 | i, fb->offsets[i]); | |
2484 | return ret; | |
2485 | } | |
6687c906 | 2486 | |
2e2adb05 VS |
2487 | if ((fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
2488 | fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS) && i == 1) { | |
2489 | int hsub = fb->format->hsub; | |
2490 | int vsub = fb->format->vsub; | |
2491 | int tile_width, tile_height; | |
2492 | int main_x, main_y; | |
2493 | int ccs_x, ccs_y; | |
2494 | ||
2495 | intel_tile_dims(fb, i, &tile_width, &tile_height); | |
e8837d98 VS |
2496 | tile_width *= hsub; |
2497 | tile_height *= vsub; | |
2e2adb05 | 2498 | |
e8837d98 VS |
2499 | ccs_x = (x * hsub) % tile_width; |
2500 | ccs_y = (y * vsub) % tile_height; | |
2501 | main_x = intel_fb->normal[0].x % tile_width; | |
2502 | main_y = intel_fb->normal[0].y % tile_height; | |
2e2adb05 VS |
2503 | |
2504 | /* | |
2505 | * CCS doesn't have its own x/y offset register, so the intra CCS tile | |
2506 | * x/y offsets must match between CCS and the main surface. | |
2507 | */ | |
2508 | if (main_x != ccs_x || main_y != ccs_y) { | |
2509 | DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n", | |
2510 | main_x, main_y, | |
2511 | ccs_x, ccs_y, | |
2512 | intel_fb->normal[0].x, | |
2513 | intel_fb->normal[0].y, | |
2514 | x, y); | |
2515 | return -EINVAL; | |
2516 | } | |
2517 | } | |
2518 | ||
60d5f2a4 VS |
2519 | /* |
2520 | * The fence (if used) is aligned to the start of the object | |
2521 | * so having the framebuffer wrap around across the edge of the | |
2522 | * fenced region doesn't really work. We have no API to configure | |
2523 | * the fence start offset within the object (nor could we probably | |
2524 | * on gen2/3). So it's just easier if we just require that the | |
2525 | * fb layout agrees with the fence layout. We already check that the | |
2526 | * fb stride matches the fence stride elsewhere. | |
2527 | */ | |
18db229d | 2528 | if (i == 0 && i915_gem_object_is_tiled(intel_fb->obj) && |
60d5f2a4 | 2529 | (x + width) * cpp > fb->pitches[i]) { |
144cc143 VS |
2530 | DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n", |
2531 | i, fb->offsets[i]); | |
60d5f2a4 VS |
2532 | return -EINVAL; |
2533 | } | |
2534 | ||
6687c906 VS |
2535 | /* |
2536 | * First pixel of the framebuffer from | |
2537 | * the start of the normal gtt mapping. | |
2538 | */ | |
2539 | intel_fb->normal[i].x = x; | |
2540 | intel_fb->normal[i].y = y; | |
2541 | ||
2542 | offset = _intel_compute_tile_offset(dev_priv, &x, &y, | |
3ca46c0a | 2543 | fb, i, fb->pitches[i], |
c2c446ad | 2544 | DRM_MODE_ROTATE_0, tile_size); |
6687c906 VS |
2545 | offset /= tile_size; |
2546 | ||
2f075565 | 2547 | if (fb->modifier != DRM_FORMAT_MOD_LINEAR) { |
6687c906 VS |
2548 | unsigned int tile_width, tile_height; |
2549 | unsigned int pitch_tiles; | |
2550 | struct drm_rect r; | |
2551 | ||
d88c4afd | 2552 | intel_tile_dims(fb, i, &tile_width, &tile_height); |
6687c906 VS |
2553 | |
2554 | rot_info->plane[i].offset = offset; | |
2555 | rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp); | |
2556 | rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width); | |
2557 | rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height); | |
2558 | ||
2559 | intel_fb->rotated[i].pitch = | |
2560 | rot_info->plane[i].height * tile_height; | |
2561 | ||
2562 | /* how many tiles does this plane need */ | |
2563 | size = rot_info->plane[i].stride * rot_info->plane[i].height; | |
2564 | /* | |
2565 | * If the plane isn't horizontally tile aligned, | |
2566 | * we need one more tile. | |
2567 | */ | |
2568 | if (x != 0) | |
2569 | size++; | |
2570 | ||
2571 | /* rotate the x/y offsets to match the GTT view */ | |
2572 | r.x1 = x; | |
2573 | r.y1 = y; | |
2574 | r.x2 = x + width; | |
2575 | r.y2 = y + height; | |
2576 | drm_rect_rotate(&r, | |
2577 | rot_info->plane[i].width * tile_width, | |
2578 | rot_info->plane[i].height * tile_height, | |
c2c446ad | 2579 | DRM_MODE_ROTATE_270); |
6687c906 VS |
2580 | x = r.x1; |
2581 | y = r.y1; | |
2582 | ||
2583 | /* rotate the tile dimensions to match the GTT view */ | |
2584 | pitch_tiles = intel_fb->rotated[i].pitch / tile_height; | |
2585 | swap(tile_width, tile_height); | |
2586 | ||
2587 | /* | |
2588 | * We only keep the x/y offsets, so push all of the | |
2589 | * gtt offset into the x/y offsets. | |
2590 | */ | |
e8837d98 VS |
2591 | __intel_adjust_tile_offset(&x, &y, |
2592 | tile_width, tile_height, | |
2593 | tile_size, pitch_tiles, | |
2594 | gtt_offset_rotated * tile_size, 0); | |
6687c906 VS |
2595 | |
2596 | gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height; | |
2597 | ||
2598 | /* | |
2599 | * First pixel of the framebuffer from | |
2600 | * the start of the rotated gtt mapping. | |
2601 | */ | |
2602 | intel_fb->rotated[i].x = x; | |
2603 | intel_fb->rotated[i].y = y; | |
2604 | } else { | |
2605 | size = DIV_ROUND_UP((y + height) * fb->pitches[i] + | |
2606 | x * cpp, tile_size); | |
2607 | } | |
2608 | ||
2609 | /* how many tiles in total needed in the bo */ | |
2610 | max_size = max(max_size, offset + size); | |
2611 | } | |
2612 | ||
144cc143 VS |
2613 | if (max_size * tile_size > intel_fb->obj->base.size) { |
2614 | DRM_DEBUG_KMS("fb too big for bo (need %u bytes, have %zu bytes)\n", | |
2615 | max_size * tile_size, intel_fb->obj->base.size); | |
6687c906 VS |
2616 | return -EINVAL; |
2617 | } | |
2618 | ||
2619 | return 0; | |
2620 | } | |
2621 | ||
b35d63fa | 2622 | static int i9xx_format_to_fourcc(int format) |
46f297fb JB |
2623 | { |
2624 | switch (format) { | |
2625 | case DISPPLANE_8BPP: | |
2626 | return DRM_FORMAT_C8; | |
2627 | case DISPPLANE_BGRX555: | |
2628 | return DRM_FORMAT_XRGB1555; | |
2629 | case DISPPLANE_BGRX565: | |
2630 | return DRM_FORMAT_RGB565; | |
2631 | default: | |
2632 | case DISPPLANE_BGRX888: | |
2633 | return DRM_FORMAT_XRGB8888; | |
2634 | case DISPPLANE_RGBX888: | |
2635 | return DRM_FORMAT_XBGR8888; | |
2636 | case DISPPLANE_BGRX101010: | |
2637 | return DRM_FORMAT_XRGB2101010; | |
2638 | case DISPPLANE_RGBX101010: | |
2639 | return DRM_FORMAT_XBGR2101010; | |
2640 | } | |
2641 | } | |
2642 | ||
bc8d7dff DL |
2643 | static int skl_format_to_fourcc(int format, bool rgb_order, bool alpha) |
2644 | { | |
2645 | switch (format) { | |
2646 | case PLANE_CTL_FORMAT_RGB_565: | |
2647 | return DRM_FORMAT_RGB565; | |
2648 | default: | |
2649 | case PLANE_CTL_FORMAT_XRGB_8888: | |
2650 | if (rgb_order) { | |
2651 | if (alpha) | |
2652 | return DRM_FORMAT_ABGR8888; | |
2653 | else | |
2654 | return DRM_FORMAT_XBGR8888; | |
2655 | } else { | |
2656 | if (alpha) | |
2657 | return DRM_FORMAT_ARGB8888; | |
2658 | else | |
2659 | return DRM_FORMAT_XRGB8888; | |
2660 | } | |
2661 | case PLANE_CTL_FORMAT_XRGB_2101010: | |
2662 | if (rgb_order) | |
2663 | return DRM_FORMAT_XBGR2101010; | |
2664 | else | |
2665 | return DRM_FORMAT_XRGB2101010; | |
2666 | } | |
2667 | } | |
2668 | ||
5724dbd1 | 2669 | static bool |
f6936e29 DV |
2670 | intel_alloc_initial_plane_obj(struct intel_crtc *crtc, |
2671 | struct intel_initial_plane_config *plane_config) | |
46f297fb JB |
2672 | { |
2673 | struct drm_device *dev = crtc->base.dev; | |
3badb49f | 2674 | struct drm_i915_private *dev_priv = to_i915(dev); |
72e96d64 | 2675 | struct i915_ggtt *ggtt = &dev_priv->ggtt; |
46f297fb JB |
2676 | struct drm_i915_gem_object *obj = NULL; |
2677 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; | |
2d14030b | 2678 | struct drm_framebuffer *fb = &plane_config->fb->base; |
f37b5c2b DV |
2679 | u32 base_aligned = round_down(plane_config->base, PAGE_SIZE); |
2680 | u32 size_aligned = round_up(plane_config->base + plane_config->size, | |
2681 | PAGE_SIZE); | |
2682 | ||
2683 | size_aligned -= base_aligned; | |
46f297fb | 2684 | |
ff2652ea CW |
2685 | if (plane_config->size == 0) |
2686 | return false; | |
2687 | ||
3badb49f PZ |
2688 | /* If the FB is too big, just don't use it since fbdev is not very |
2689 | * important and we should probably use that space with FBC or other | |
2690 | * features. */ | |
72e96d64 | 2691 | if (size_aligned * 2 > ggtt->stolen_usable_size) |
3badb49f PZ |
2692 | return false; |
2693 | ||
1d7a736a ID |
2694 | switch (fb->modifier) { |
2695 | case DRM_FORMAT_MOD_LINEAR: | |
2696 | case I915_FORMAT_MOD_X_TILED: | |
2697 | case I915_FORMAT_MOD_Y_TILED: | |
2698 | break; | |
2699 | default: | |
2700 | DRM_DEBUG_DRIVER("Unsupported modifier for initial FB: 0x%llx\n", | |
2701 | fb->modifier); | |
2702 | return false; | |
2703 | } | |
2704 | ||
12c83d99 | 2705 | mutex_lock(&dev->struct_mutex); |
187685cb | 2706 | obj = i915_gem_object_create_stolen_for_preallocated(dev_priv, |
f37b5c2b DV |
2707 | base_aligned, |
2708 | base_aligned, | |
2709 | size_aligned); | |
24dbf51a CW |
2710 | mutex_unlock(&dev->struct_mutex); |
2711 | if (!obj) | |
484b41dd | 2712 | return false; |
46f297fb | 2713 | |
1d7a736a ID |
2714 | switch (plane_config->tiling) { |
2715 | case I915_TILING_NONE: | |
2716 | break; | |
2717 | case I915_TILING_X: | |
2718 | case I915_TILING_Y: | |
2719 | obj->tiling_and_stride = fb->pitches[0] | plane_config->tiling; | |
2720 | break; | |
2721 | default: | |
2722 | MISSING_CASE(plane_config->tiling); | |
2723 | return false; | |
2724 | } | |
46f297fb | 2725 | |
438b74a5 | 2726 | mode_cmd.pixel_format = fb->format->format; |
6bf129df DL |
2727 | mode_cmd.width = fb->width; |
2728 | mode_cmd.height = fb->height; | |
2729 | mode_cmd.pitches[0] = fb->pitches[0]; | |
bae781b2 | 2730 | mode_cmd.modifier[0] = fb->modifier; |
18c5247e | 2731 | mode_cmd.flags = DRM_MODE_FB_MODIFIERS; |
46f297fb | 2732 | |
24dbf51a | 2733 | if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) { |
46f297fb JB |
2734 | DRM_DEBUG_KMS("intel fb init failed\n"); |
2735 | goto out_unref_obj; | |
2736 | } | |
12c83d99 | 2737 | |
484b41dd | 2738 | |
f6936e29 | 2739 | DRM_DEBUG_KMS("initial plane fb obj %p\n", obj); |
484b41dd | 2740 | return true; |
46f297fb JB |
2741 | |
2742 | out_unref_obj: | |
f8c417cd | 2743 | i915_gem_object_put(obj); |
484b41dd JB |
2744 | return false; |
2745 | } | |
2746 | ||
e9728bd8 VS |
2747 | static void |
2748 | intel_set_plane_visible(struct intel_crtc_state *crtc_state, | |
2749 | struct intel_plane_state *plane_state, | |
2750 | bool visible) | |
2751 | { | |
2752 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); | |
2753 | ||
2754 | plane_state->base.visible = visible; | |
2755 | ||
2756 | /* FIXME pre-g4x don't work like this */ | |
2757 | if (visible) { | |
2758 | crtc_state->base.plane_mask |= BIT(drm_plane_index(&plane->base)); | |
2759 | crtc_state->active_planes |= BIT(plane->id); | |
2760 | } else { | |
2761 | crtc_state->base.plane_mask &= ~BIT(drm_plane_index(&plane->base)); | |
2762 | crtc_state->active_planes &= ~BIT(plane->id); | |
2763 | } | |
2764 | ||
2765 | DRM_DEBUG_KMS("%s active planes 0x%x\n", | |
2766 | crtc_state->base.crtc->name, | |
2767 | crtc_state->active_planes); | |
2768 | } | |
2769 | ||
23ac1273 VS |
2770 | static void intel_plane_disable_noatomic(struct intel_crtc *crtc, |
2771 | struct intel_plane *plane) | |
2772 | { | |
2773 | struct intel_crtc_state *crtc_state = | |
2774 | to_intel_crtc_state(crtc->base.state); | |
2775 | struct intel_plane_state *plane_state = | |
2776 | to_intel_plane_state(plane->base.state); | |
2777 | ||
2778 | intel_set_plane_visible(crtc_state, plane_state, false); | |
2779 | ||
2780 | if (plane->id == PLANE_PRIMARY) | |
2781 | intel_pre_disable_primary_noatomic(&crtc->base); | |
2782 | ||
2783 | trace_intel_disable_plane(&plane->base, crtc); | |
2784 | plane->disable_plane(plane, crtc); | |
2785 | } | |
2786 | ||
5724dbd1 | 2787 | static void |
f6936e29 DV |
2788 | intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, |
2789 | struct intel_initial_plane_config *plane_config) | |
484b41dd JB |
2790 | { |
2791 | struct drm_device *dev = intel_crtc->base.dev; | |
fac5e23e | 2792 | struct drm_i915_private *dev_priv = to_i915(dev); |
484b41dd | 2793 | struct drm_crtc *c; |
2ff8fde1 | 2794 | struct drm_i915_gem_object *obj; |
88595ac9 | 2795 | struct drm_plane *primary = intel_crtc->base.primary; |
be5651f2 | 2796 | struct drm_plane_state *plane_state = primary->state; |
200757f5 MR |
2797 | struct drm_crtc_state *crtc_state = intel_crtc->base.state; |
2798 | struct intel_plane *intel_plane = to_intel_plane(primary); | |
0a8d8a86 MR |
2799 | struct intel_plane_state *intel_state = |
2800 | to_intel_plane_state(plane_state); | |
88595ac9 | 2801 | struct drm_framebuffer *fb; |
484b41dd | 2802 | |
2d14030b | 2803 | if (!plane_config->fb) |
484b41dd JB |
2804 | return; |
2805 | ||
f6936e29 | 2806 | if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) { |
88595ac9 DV |
2807 | fb = &plane_config->fb->base; |
2808 | goto valid_fb; | |
f55548b5 | 2809 | } |
484b41dd | 2810 | |
2d14030b | 2811 | kfree(plane_config->fb); |
484b41dd JB |
2812 | |
2813 | /* | |
2814 | * Failed to alloc the obj, check to see if we should share | |
2815 | * an fb with another CRTC instead | |
2816 | */ | |
70e1e0ec | 2817 | for_each_crtc(dev, c) { |
be1e3415 | 2818 | struct intel_plane_state *state; |
484b41dd JB |
2819 | |
2820 | if (c == &intel_crtc->base) | |
2821 | continue; | |
2822 | ||
be1e3415 | 2823 | if (!to_intel_crtc(c)->active) |
2ff8fde1 MR |
2824 | continue; |
2825 | ||
be1e3415 CW |
2826 | state = to_intel_plane_state(c->primary->state); |
2827 | if (!state->vma) | |
484b41dd JB |
2828 | continue; |
2829 | ||
be1e3415 CW |
2830 | if (intel_plane_ggtt_offset(state) == plane_config->base) { |
2831 | fb = c->primary->fb; | |
c3ed1103 | 2832 | drm_framebuffer_get(fb); |
88595ac9 | 2833 | goto valid_fb; |
484b41dd JB |
2834 | } |
2835 | } | |
88595ac9 | 2836 | |
200757f5 MR |
2837 | /* |
2838 | * We've failed to reconstruct the BIOS FB. Current display state | |
2839 | * indicates that the primary plane is visible, but has a NULL FB, | |
2840 | * which will lead to problems later if we don't fix it up. The | |
2841 | * simplest solution is to just disable the primary plane now and | |
2842 | * pretend the BIOS never had it enabled. | |
2843 | */ | |
23ac1273 | 2844 | intel_plane_disable_noatomic(intel_crtc, intel_plane); |
200757f5 | 2845 | |
88595ac9 DV |
2846 | return; |
2847 | ||
2848 | valid_fb: | |
be1e3415 CW |
2849 | mutex_lock(&dev->struct_mutex); |
2850 | intel_state->vma = | |
2851 | intel_pin_and_fence_fb_obj(fb, primary->state->rotation); | |
2852 | mutex_unlock(&dev->struct_mutex); | |
2853 | if (IS_ERR(intel_state->vma)) { | |
2854 | DRM_ERROR("failed to pin boot fb on pipe %d: %li\n", | |
2855 | intel_crtc->pipe, PTR_ERR(intel_state->vma)); | |
2856 | ||
2857 | intel_state->vma = NULL; | |
c3ed1103 | 2858 | drm_framebuffer_put(fb); |
be1e3415 CW |
2859 | return; |
2860 | } | |
2861 | ||
f44e2659 VS |
2862 | plane_state->src_x = 0; |
2863 | plane_state->src_y = 0; | |
be5651f2 ML |
2864 | plane_state->src_w = fb->width << 16; |
2865 | plane_state->src_h = fb->height << 16; | |
2866 | ||
f44e2659 VS |
2867 | plane_state->crtc_x = 0; |
2868 | plane_state->crtc_y = 0; | |
be5651f2 ML |
2869 | plane_state->crtc_w = fb->width; |
2870 | plane_state->crtc_h = fb->height; | |
2871 | ||
1638d30c RC |
2872 | intel_state->base.src = drm_plane_state_src(plane_state); |
2873 | intel_state->base.dst = drm_plane_state_dest(plane_state); | |
0a8d8a86 | 2874 | |
88595ac9 | 2875 | obj = intel_fb_obj(fb); |
3e510a8e | 2876 | if (i915_gem_object_is_tiled(obj)) |
88595ac9 DV |
2877 | dev_priv->preserve_bios_swizzle = true; |
2878 | ||
c3ed1103 | 2879 | drm_framebuffer_get(fb); |
be5651f2 | 2880 | primary->fb = primary->state->fb = fb; |
36750f28 | 2881 | primary->crtc = primary->state->crtc = &intel_crtc->base; |
e9728bd8 VS |
2882 | |
2883 | intel_set_plane_visible(to_intel_crtc_state(crtc_state), | |
2884 | to_intel_plane_state(plane_state), | |
2885 | true); | |
2886 | ||
faf5bf0a CW |
2887 | atomic_or(to_intel_plane(primary)->frontbuffer_bit, |
2888 | &obj->frontbuffer_bits); | |
46f297fb JB |
2889 | } |
2890 | ||
b63a16f6 VS |
2891 | static int skl_max_plane_width(const struct drm_framebuffer *fb, int plane, |
2892 | unsigned int rotation) | |
2893 | { | |
353c8598 | 2894 | int cpp = fb->format->cpp[plane]; |
b63a16f6 | 2895 | |
bae781b2 | 2896 | switch (fb->modifier) { |
2f075565 | 2897 | case DRM_FORMAT_MOD_LINEAR: |
b63a16f6 VS |
2898 | case I915_FORMAT_MOD_X_TILED: |
2899 | switch (cpp) { | |
2900 | case 8: | |
2901 | return 4096; | |
2902 | case 4: | |
2903 | case 2: | |
2904 | case 1: | |
2905 | return 8192; | |
2906 | default: | |
2907 | MISSING_CASE(cpp); | |
2908 | break; | |
2909 | } | |
2910 | break; | |
2e2adb05 VS |
2911 | case I915_FORMAT_MOD_Y_TILED_CCS: |
2912 | case I915_FORMAT_MOD_Yf_TILED_CCS: | |
2913 | /* FIXME AUX plane? */ | |
b63a16f6 VS |
2914 | case I915_FORMAT_MOD_Y_TILED: |
2915 | case I915_FORMAT_MOD_Yf_TILED: | |
2916 | switch (cpp) { | |
2917 | case 8: | |
2918 | return 2048; | |
2919 | case 4: | |
2920 | return 4096; | |
2921 | case 2: | |
2922 | case 1: | |
2923 | return 8192; | |
2924 | default: | |
2925 | MISSING_CASE(cpp); | |
2926 | break; | |
2927 | } | |
2928 | break; | |
2929 | default: | |
bae781b2 | 2930 | MISSING_CASE(fb->modifier); |
b63a16f6 VS |
2931 | } |
2932 | ||
2933 | return 2048; | |
2934 | } | |
2935 | ||
2e2adb05 VS |
2936 | static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state, |
2937 | int main_x, int main_y, u32 main_offset) | |
2938 | { | |
2939 | const struct drm_framebuffer *fb = plane_state->base.fb; | |
2940 | int hsub = fb->format->hsub; | |
2941 | int vsub = fb->format->vsub; | |
2942 | int aux_x = plane_state->aux.x; | |
2943 | int aux_y = plane_state->aux.y; | |
2944 | u32 aux_offset = plane_state->aux.offset; | |
2945 | u32 alignment = intel_surf_alignment(fb, 1); | |
2946 | ||
2947 | while (aux_offset >= main_offset && aux_y <= main_y) { | |
2948 | int x, y; | |
2949 | ||
2950 | if (aux_x == main_x && aux_y == main_y) | |
2951 | break; | |
2952 | ||
2953 | if (aux_offset == 0) | |
2954 | break; | |
2955 | ||
2956 | x = aux_x / hsub; | |
2957 | y = aux_y / vsub; | |
2958 | aux_offset = intel_adjust_tile_offset(&x, &y, plane_state, 1, | |
2959 | aux_offset, aux_offset - alignment); | |
2960 | aux_x = x * hsub + aux_x % hsub; | |
2961 | aux_y = y * vsub + aux_y % vsub; | |
2962 | } | |
2963 | ||
2964 | if (aux_x != main_x || aux_y != main_y) | |
2965 | return false; | |
2966 | ||
2967 | plane_state->aux.offset = aux_offset; | |
2968 | plane_state->aux.x = aux_x; | |
2969 | plane_state->aux.y = aux_y; | |
2970 | ||
2971 | return true; | |
2972 | } | |
2973 | ||
b63a16f6 VS |
2974 | static int skl_check_main_surface(struct intel_plane_state *plane_state) |
2975 | { | |
b63a16f6 VS |
2976 | const struct drm_framebuffer *fb = plane_state->base.fb; |
2977 | unsigned int rotation = plane_state->base.rotation; | |
cc926387 DV |
2978 | int x = plane_state->base.src.x1 >> 16; |
2979 | int y = plane_state->base.src.y1 >> 16; | |
2980 | int w = drm_rect_width(&plane_state->base.src) >> 16; | |
2981 | int h = drm_rect_height(&plane_state->base.src) >> 16; | |
b63a16f6 VS |
2982 | int max_width = skl_max_plane_width(fb, 0, rotation); |
2983 | int max_height = 4096; | |
8d970654 | 2984 | u32 alignment, offset, aux_offset = plane_state->aux.offset; |
b63a16f6 VS |
2985 | |
2986 | if (w > max_width || h > max_height) { | |
2987 | DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n", | |
2988 | w, h, max_width, max_height); | |
2989 | return -EINVAL; | |
2990 | } | |
2991 | ||
2992 | intel_add_fb_offsets(&x, &y, plane_state, 0); | |
2993 | offset = intel_compute_tile_offset(&x, &y, plane_state, 0); | |
d88c4afd | 2994 | alignment = intel_surf_alignment(fb, 0); |
b63a16f6 | 2995 | |
8d970654 VS |
2996 | /* |
2997 | * AUX surface offset is specified as the distance from the | |
2998 | * main surface offset, and it must be non-negative. Make | |
2999 | * sure that is what we will get. | |
3000 | */ | |
3001 | if (offset > aux_offset) | |
3002 | offset = intel_adjust_tile_offset(&x, &y, plane_state, 0, | |
3003 | offset, aux_offset & ~(alignment - 1)); | |
3004 | ||
b63a16f6 VS |
3005 | /* |
3006 | * When using an X-tiled surface, the plane blows up | |
3007 | * if the x offset + width exceed the stride. | |
3008 | * | |
3009 | * TODO: linear and Y-tiled seem fine, Yf untested, | |
3010 | */ | |
bae781b2 | 3011 | if (fb->modifier == I915_FORMAT_MOD_X_TILED) { |
353c8598 | 3012 | int cpp = fb->format->cpp[0]; |
b63a16f6 VS |
3013 | |
3014 | while ((x + w) * cpp > fb->pitches[0]) { | |
3015 | if (offset == 0) { | |
2e2adb05 | 3016 | DRM_DEBUG_KMS("Unable to find suitable display surface offset due to X-tiling\n"); |
b63a16f6 VS |
3017 | return -EINVAL; |
3018 | } | |
3019 | ||
3020 | offset = intel_adjust_tile_offset(&x, &y, plane_state, 0, | |
3021 | offset, offset - alignment); | |
3022 | } | |
3023 | } | |
3024 | ||
2e2adb05 VS |
3025 | /* |
3026 | * CCS AUX surface doesn't have its own x/y offsets, we must make sure | |
3027 | * they match with the main surface x/y offsets. | |
3028 | */ | |
3029 | if (fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS || | |
3030 | fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS) { | |
3031 | while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) { | |
3032 | if (offset == 0) | |
3033 | break; | |
3034 | ||
3035 | offset = intel_adjust_tile_offset(&x, &y, plane_state, 0, | |
3036 | offset, offset - alignment); | |
3037 | } | |
3038 | ||
3039 | if (x != plane_state->aux.x || y != plane_state->aux.y) { | |
3040 | DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n"); | |
3041 | return -EINVAL; | |
3042 | } | |
3043 | } | |
3044 | ||
b63a16f6 VS |
3045 | plane_state->main.offset = offset; |
3046 | plane_state->main.x = x; | |
3047 | plane_state->main.y = y; | |
3048 | ||
3049 | return 0; | |
3050 | } | |
3051 | ||
8d970654 VS |
3052 | static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state) |
3053 | { | |
3054 | const struct drm_framebuffer *fb = plane_state->base.fb; | |
3055 | unsigned int rotation = plane_state->base.rotation; | |
3056 | int max_width = skl_max_plane_width(fb, 1, rotation); | |
3057 | int max_height = 4096; | |
cc926387 DV |
3058 | int x = plane_state->base.src.x1 >> 17; |
3059 | int y = plane_state->base.src.y1 >> 17; | |
3060 | int w = drm_rect_width(&plane_state->base.src) >> 17; | |
3061 | int h = drm_rect_height(&plane_state->base.src) >> 17; | |
8d970654 VS |
3062 | u32 offset; |
3063 | ||
3064 | intel_add_fb_offsets(&x, &y, plane_state, 1); | |
3065 | offset = intel_compute_tile_offset(&x, &y, plane_state, 1); | |
3066 | ||
3067 | /* FIXME not quite sure how/if these apply to the chroma plane */ | |
3068 | if (w > max_width || h > max_height) { | |
3069 | DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n", | |
3070 | w, h, max_width, max_height); | |
3071 | return -EINVAL; | |
3072 | } | |
3073 | ||
3074 | plane_state->aux.offset = offset; | |
3075 | plane_state->aux.x = x; | |
3076 | plane_state->aux.y = y; | |
3077 | ||
3078 | return 0; | |
3079 | } | |
3080 | ||
2e2adb05 VS |
3081 | static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state) |
3082 | { | |
3083 | struct intel_plane *plane = to_intel_plane(plane_state->base.plane); | |
3084 | struct intel_crtc *crtc = to_intel_crtc(plane_state->base.crtc); | |
3085 | const struct drm_framebuffer *fb = plane_state->base.fb; | |
3086 | int src_x = plane_state->base.src.x1 >> 16; | |
3087 | int src_y = plane_state->base.src.y1 >> 16; | |
3088 | int hsub = fb->format->hsub; | |
3089 | int vsub = fb->format->vsub; | |
3090 | int x = src_x / hsub; | |
3091 | int y = src_y / vsub; | |
3092 | u32 offset; | |
3093 | ||
3094 | switch (plane->id) { | |
3095 | case PLANE_PRIMARY: | |
3096 | case PLANE_SPRITE0: | |
3097 | break; | |
3098 | default: | |
3099 | DRM_DEBUG_KMS("RC support only on plane 1 and 2\n"); | |
3100 | return -EINVAL; | |
3101 | } | |
3102 | ||
3103 | if (crtc->pipe == PIPE_C) { | |
3104 | DRM_DEBUG_KMS("No RC support on pipe C\n"); | |
3105 | return -EINVAL; | |
3106 | } | |
3107 | ||
3108 | if (plane_state->base.rotation & ~(DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180)) { | |
3109 | DRM_DEBUG_KMS("RC support only with 0/180 degree rotation %x\n", | |
3110 | plane_state->base.rotation); | |
3111 | return -EINVAL; | |
3112 | } | |
3113 | ||
3114 | intel_add_fb_offsets(&x, &y, plane_state, 1); | |
3115 | offset = intel_compute_tile_offset(&x, &y, plane_state, 1); | |
3116 | ||
3117 | plane_state->aux.offset = offset; | |
3118 | plane_state->aux.x = x * hsub + src_x % hsub; | |
3119 | plane_state->aux.y = y * vsub + src_y % vsub; | |
3120 | ||
3121 | return 0; | |
3122 | } | |
3123 | ||
b63a16f6 VS |
3124 | int skl_check_plane_surface(struct intel_plane_state *plane_state) |
3125 | { | |
3126 | const struct drm_framebuffer *fb = plane_state->base.fb; | |
3127 | unsigned int rotation = plane_state->base.rotation; | |
3128 | int ret; | |
3129 | ||
a5e4c7d0 VS |
3130 | if (!plane_state->base.visible) |
3131 | return 0; | |
3132 | ||
b63a16f6 | 3133 | /* Rotate src coordinates to match rotated GTT view */ |
bd2ef25d | 3134 | if (drm_rotation_90_or_270(rotation)) |
cc926387 | 3135 | drm_rect_rotate(&plane_state->base.src, |
da064b47 | 3136 | fb->width << 16, fb->height << 16, |
c2c446ad | 3137 | DRM_MODE_ROTATE_270); |
b63a16f6 | 3138 | |
8d970654 VS |
3139 | /* |
3140 | * Handle the AUX surface first since | |
3141 | * the main surface setup depends on it. | |
3142 | */ | |
438b74a5 | 3143 | if (fb->format->format == DRM_FORMAT_NV12) { |
8d970654 VS |
3144 | ret = skl_check_nv12_aux_surface(plane_state); |
3145 | if (ret) | |
3146 | return ret; | |
2e2adb05 VS |
3147 | } else if (fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
3148 | fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS) { | |
3149 | ret = skl_check_ccs_aux_surface(plane_state); | |
3150 | if (ret) | |
3151 | return ret; | |
8d970654 VS |
3152 | } else { |
3153 | plane_state->aux.offset = ~0xfff; | |
3154 | plane_state->aux.x = 0; | |
3155 | plane_state->aux.y = 0; | |
3156 | } | |
3157 | ||
b63a16f6 VS |
3158 | ret = skl_check_main_surface(plane_state); |
3159 | if (ret) | |
3160 | return ret; | |
3161 | ||
3162 | return 0; | |
3163 | } | |
3164 | ||
7145f60a VS |
3165 | static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state, |
3166 | const struct intel_plane_state *plane_state) | |
81255565 | 3167 | { |
7145f60a VS |
3168 | struct drm_i915_private *dev_priv = |
3169 | to_i915(plane_state->base.plane->dev); | |
3170 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); | |
3171 | const struct drm_framebuffer *fb = plane_state->base.fb; | |
8d0deca8 | 3172 | unsigned int rotation = plane_state->base.rotation; |
7145f60a | 3173 | u32 dspcntr; |
c9ba6fad | 3174 | |
7145f60a | 3175 | dspcntr = DISPLAY_PLANE_ENABLE | DISPPLANE_GAMMA_ENABLE; |
f45651ba | 3176 | |
6a4407a6 VS |
3177 | if (IS_G4X(dev_priv) || IS_GEN5(dev_priv) || |
3178 | IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv)) | |
7145f60a | 3179 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
f45651ba | 3180 | |
6a4407a6 VS |
3181 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
3182 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; | |
f45651ba | 3183 | |
d509e28b VS |
3184 | if (INTEL_GEN(dev_priv) < 4) |
3185 | dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe); | |
81255565 | 3186 | |
438b74a5 | 3187 | switch (fb->format->format) { |
57779d06 | 3188 | case DRM_FORMAT_C8: |
81255565 JB |
3189 | dspcntr |= DISPPLANE_8BPP; |
3190 | break; | |
57779d06 | 3191 | case DRM_FORMAT_XRGB1555: |
57779d06 | 3192 | dspcntr |= DISPPLANE_BGRX555; |
81255565 | 3193 | break; |
57779d06 VS |
3194 | case DRM_FORMAT_RGB565: |
3195 | dspcntr |= DISPPLANE_BGRX565; | |
3196 | break; | |
3197 | case DRM_FORMAT_XRGB8888: | |
57779d06 VS |
3198 | dspcntr |= DISPPLANE_BGRX888; |
3199 | break; | |
3200 | case DRM_FORMAT_XBGR8888: | |
57779d06 VS |
3201 | dspcntr |= DISPPLANE_RGBX888; |
3202 | break; | |
3203 | case DRM_FORMAT_XRGB2101010: | |
57779d06 VS |
3204 | dspcntr |= DISPPLANE_BGRX101010; |
3205 | break; | |
3206 | case DRM_FORMAT_XBGR2101010: | |
57779d06 | 3207 | dspcntr |= DISPPLANE_RGBX101010; |
81255565 JB |
3208 | break; |
3209 | default: | |
7145f60a VS |
3210 | MISSING_CASE(fb->format->format); |
3211 | return 0; | |
81255565 | 3212 | } |
57779d06 | 3213 | |
72618ebf | 3214 | if (INTEL_GEN(dev_priv) >= 4 && |
bae781b2 | 3215 | fb->modifier == I915_FORMAT_MOD_X_TILED) |
f45651ba | 3216 | dspcntr |= DISPPLANE_TILED; |
81255565 | 3217 | |
c2c446ad | 3218 | if (rotation & DRM_MODE_ROTATE_180) |
df0cd455 VS |
3219 | dspcntr |= DISPPLANE_ROTATE_180; |
3220 | ||
c2c446ad | 3221 | if (rotation & DRM_MODE_REFLECT_X) |
4ea7be2b VS |
3222 | dspcntr |= DISPPLANE_MIRROR; |
3223 | ||
7145f60a VS |
3224 | return dspcntr; |
3225 | } | |
de1aa629 | 3226 | |
f9407ae1 | 3227 | int i9xx_check_plane_surface(struct intel_plane_state *plane_state) |
5b7fcc44 VS |
3228 | { |
3229 | struct drm_i915_private *dev_priv = | |
3230 | to_i915(plane_state->base.plane->dev); | |
3231 | int src_x = plane_state->base.src.x1 >> 16; | |
3232 | int src_y = plane_state->base.src.y1 >> 16; | |
3233 | u32 offset; | |
81255565 | 3234 | |
5b7fcc44 | 3235 | intel_add_fb_offsets(&src_x, &src_y, plane_state, 0); |
e506a0c6 | 3236 | |
5b7fcc44 VS |
3237 | if (INTEL_GEN(dev_priv) >= 4) |
3238 | offset = intel_compute_tile_offset(&src_x, &src_y, | |
3239 | plane_state, 0); | |
3240 | else | |
3241 | offset = 0; | |
3242 | ||
3243 | /* HSW/BDW do this automagically in hardware */ | |
3244 | if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) { | |
3245 | unsigned int rotation = plane_state->base.rotation; | |
3246 | int src_w = drm_rect_width(&plane_state->base.src) >> 16; | |
3247 | int src_h = drm_rect_height(&plane_state->base.src) >> 16; | |
3248 | ||
c2c446ad | 3249 | if (rotation & DRM_MODE_ROTATE_180) { |
5b7fcc44 VS |
3250 | src_x += src_w - 1; |
3251 | src_y += src_h - 1; | |
c2c446ad | 3252 | } else if (rotation & DRM_MODE_REFLECT_X) { |
5b7fcc44 VS |
3253 | src_x += src_w - 1; |
3254 | } | |
48404c1e SJ |
3255 | } |
3256 | ||
5b7fcc44 VS |
3257 | plane_state->main.offset = offset; |
3258 | plane_state->main.x = src_x; | |
3259 | plane_state->main.y = src_y; | |
3260 | ||
3261 | return 0; | |
3262 | } | |
3263 | ||
282dbf9b | 3264 | static void i9xx_update_primary_plane(struct intel_plane *primary, |
7145f60a VS |
3265 | const struct intel_crtc_state *crtc_state, |
3266 | const struct intel_plane_state *plane_state) | |
3267 | { | |
282dbf9b | 3268 | struct drm_i915_private *dev_priv = to_i915(primary->base.dev); |
282dbf9b VS |
3269 | const struct drm_framebuffer *fb = plane_state->base.fb; |
3270 | enum plane plane = primary->plane; | |
7145f60a | 3271 | u32 linear_offset; |
a0864d59 | 3272 | u32 dspcntr = plane_state->ctl; |
7145f60a | 3273 | i915_reg_t reg = DSPCNTR(plane); |
5b7fcc44 VS |
3274 | int x = plane_state->main.x; |
3275 | int y = plane_state->main.y; | |
7145f60a | 3276 | unsigned long irqflags; |
e288881b | 3277 | u32 dspaddr_offset; |
7145f60a | 3278 | |
2949056c | 3279 | linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0); |
6687c906 | 3280 | |
5b7fcc44 | 3281 | if (INTEL_GEN(dev_priv) >= 4) |
e288881b | 3282 | dspaddr_offset = plane_state->main.offset; |
5b7fcc44 | 3283 | else |
e288881b | 3284 | dspaddr_offset = linear_offset; |
2db3366b | 3285 | |
dd584fc0 VS |
3286 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
3287 | ||
78587de2 VS |
3288 | if (INTEL_GEN(dev_priv) < 4) { |
3289 | /* pipesrc and dspsize control the size that is scaled from, | |
3290 | * which should always be the user's requested size. | |
3291 | */ | |
dd584fc0 VS |
3292 | I915_WRITE_FW(DSPSIZE(plane), |
3293 | ((crtc_state->pipe_src_h - 1) << 16) | | |
3294 | (crtc_state->pipe_src_w - 1)); | |
3295 | I915_WRITE_FW(DSPPOS(plane), 0); | |
78587de2 | 3296 | } else if (IS_CHERRYVIEW(dev_priv) && plane == PLANE_B) { |
dd584fc0 VS |
3297 | I915_WRITE_FW(PRIMSIZE(plane), |
3298 | ((crtc_state->pipe_src_h - 1) << 16) | | |
3299 | (crtc_state->pipe_src_w - 1)); | |
3300 | I915_WRITE_FW(PRIMPOS(plane), 0); | |
3301 | I915_WRITE_FW(PRIMCNSTALPHA(plane), 0); | |
78587de2 VS |
3302 | } |
3303 | ||
dd584fc0 | 3304 | I915_WRITE_FW(reg, dspcntr); |
48404c1e | 3305 | |
dd584fc0 | 3306 | I915_WRITE_FW(DSPSTRIDE(plane), fb->pitches[0]); |
3ba35e53 VS |
3307 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
3308 | I915_WRITE_FW(DSPSURF(plane), | |
3309 | intel_plane_ggtt_offset(plane_state) + | |
e288881b | 3310 | dspaddr_offset); |
3ba35e53 VS |
3311 | I915_WRITE_FW(DSPOFFSET(plane), (y << 16) | x); |
3312 | } else if (INTEL_GEN(dev_priv) >= 4) { | |
dd584fc0 VS |
3313 | I915_WRITE_FW(DSPSURF(plane), |
3314 | intel_plane_ggtt_offset(plane_state) + | |
e288881b | 3315 | dspaddr_offset); |
dd584fc0 VS |
3316 | I915_WRITE_FW(DSPTILEOFF(plane), (y << 16) | x); |
3317 | I915_WRITE_FW(DSPLINOFF(plane), linear_offset); | |
bfb81049 | 3318 | } else { |
dd584fc0 VS |
3319 | I915_WRITE_FW(DSPADDR(plane), |
3320 | intel_plane_ggtt_offset(plane_state) + | |
e288881b | 3321 | dspaddr_offset); |
bfb81049 | 3322 | } |
dd584fc0 VS |
3323 | POSTING_READ_FW(reg); |
3324 | ||
3325 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); | |
17638cd6 JB |
3326 | } |
3327 | ||
282dbf9b VS |
3328 | static void i9xx_disable_primary_plane(struct intel_plane *primary, |
3329 | struct intel_crtc *crtc) | |
17638cd6 | 3330 | { |
282dbf9b VS |
3331 | struct drm_i915_private *dev_priv = to_i915(primary->base.dev); |
3332 | enum plane plane = primary->plane; | |
dd584fc0 VS |
3333 | unsigned long irqflags; |
3334 | ||
3335 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); | |
f45651ba | 3336 | |
dd584fc0 | 3337 | I915_WRITE_FW(DSPCNTR(plane), 0); |
a8d201af | 3338 | if (INTEL_INFO(dev_priv)->gen >= 4) |
dd584fc0 | 3339 | I915_WRITE_FW(DSPSURF(plane), 0); |
a8d201af | 3340 | else |
dd584fc0 VS |
3341 | I915_WRITE_FW(DSPADDR(plane), 0); |
3342 | POSTING_READ_FW(DSPCNTR(plane)); | |
3343 | ||
3344 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); | |
a8d201af | 3345 | } |
c9ba6fad | 3346 | |
d87ce764 VS |
3347 | static bool i9xx_plane_get_hw_state(struct intel_plane *primary) |
3348 | { | |
3349 | ||
3350 | struct drm_i915_private *dev_priv = to_i915(primary->base.dev); | |
3351 | enum intel_display_power_domain power_domain; | |
3352 | enum plane plane = primary->plane; | |
3353 | enum pipe pipe = primary->pipe; | |
3354 | bool ret; | |
3355 | ||
3356 | /* | |
3357 | * Not 100% correct for planes that can move between pipes, | |
3358 | * but that's only the case for gen2-4 which don't have any | |
3359 | * display power wells. | |
3360 | */ | |
3361 | power_domain = POWER_DOMAIN_PIPE(pipe); | |
3362 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) | |
3363 | return false; | |
3364 | ||
3365 | ret = I915_READ(DSPCNTR(plane)) & DISPLAY_PLANE_ENABLE; | |
3366 | ||
3367 | intel_display_power_put(dev_priv, power_domain); | |
3368 | ||
3369 | return ret; | |
3370 | } | |
3371 | ||
d88c4afd VS |
3372 | static u32 |
3373 | intel_fb_stride_alignment(const struct drm_framebuffer *fb, int plane) | |
b321803d | 3374 | { |
2f075565 | 3375 | if (fb->modifier == DRM_FORMAT_MOD_LINEAR) |
b321803d | 3376 | return 64; |
d88c4afd VS |
3377 | else |
3378 | return intel_tile_width_bytes(fb, plane); | |
b321803d DL |
3379 | } |
3380 | ||
e435d6e5 ML |
3381 | static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id) |
3382 | { | |
3383 | struct drm_device *dev = intel_crtc->base.dev; | |
fac5e23e | 3384 | struct drm_i915_private *dev_priv = to_i915(dev); |
e435d6e5 ML |
3385 | |
3386 | I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0); | |
3387 | I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0); | |
3388 | I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0); | |
e435d6e5 ML |
3389 | } |
3390 | ||
a1b2278e CK |
3391 | /* |
3392 | * This function detaches (aka. unbinds) unused scalers in hardware | |
3393 | */ | |
0583236e | 3394 | static void skl_detach_scalers(struct intel_crtc *intel_crtc) |
a1b2278e | 3395 | { |
a1b2278e CK |
3396 | struct intel_crtc_scaler_state *scaler_state; |
3397 | int i; | |
3398 | ||
a1b2278e CK |
3399 | scaler_state = &intel_crtc->config->scaler_state; |
3400 | ||
3401 | /* loop through and disable scalers that aren't in use */ | |
3402 | for (i = 0; i < intel_crtc->num_scalers; i++) { | |
e435d6e5 ML |
3403 | if (!scaler_state->scalers[i].in_use) |
3404 | skl_detach_scaler(intel_crtc, i); | |
a1b2278e CK |
3405 | } |
3406 | } | |
3407 | ||
d2196774 VS |
3408 | u32 skl_plane_stride(const struct drm_framebuffer *fb, int plane, |
3409 | unsigned int rotation) | |
3410 | { | |
1b500535 VS |
3411 | u32 stride; |
3412 | ||
3413 | if (plane >= fb->format->num_planes) | |
3414 | return 0; | |
3415 | ||
3416 | stride = intel_fb_pitch(fb, plane, rotation); | |
d2196774 VS |
3417 | |
3418 | /* | |
3419 | * The stride is either expressed as a multiple of 64 bytes chunks for | |
3420 | * linear buffers or in number of tiles for tiled buffers. | |
3421 | */ | |
d88c4afd VS |
3422 | if (drm_rotation_90_or_270(rotation)) |
3423 | stride /= intel_tile_height(fb, plane); | |
3424 | else | |
3425 | stride /= intel_fb_stride_alignment(fb, plane); | |
d2196774 VS |
3426 | |
3427 | return stride; | |
3428 | } | |
3429 | ||
2e881264 | 3430 | static u32 skl_plane_ctl_format(uint32_t pixel_format) |
70d21f0e | 3431 | { |
6156a456 | 3432 | switch (pixel_format) { |
d161cf7a | 3433 | case DRM_FORMAT_C8: |
c34ce3d1 | 3434 | return PLANE_CTL_FORMAT_INDEXED; |
70d21f0e | 3435 | case DRM_FORMAT_RGB565: |
c34ce3d1 | 3436 | return PLANE_CTL_FORMAT_RGB_565; |
70d21f0e | 3437 | case DRM_FORMAT_XBGR8888: |
c34ce3d1 | 3438 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX; |
6156a456 | 3439 | case DRM_FORMAT_XRGB8888: |
c34ce3d1 | 3440 | return PLANE_CTL_FORMAT_XRGB_8888; |
6156a456 CK |
3441 | /* |
3442 | * XXX: For ARBG/ABGR formats we default to expecting scanout buffers | |
3443 | * to be already pre-multiplied. We need to add a knob (or a different | |
3444 | * DRM_FORMAT) for user-space to configure that. | |
3445 | */ | |
f75fb42a | 3446 | case DRM_FORMAT_ABGR8888: |
c34ce3d1 | 3447 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX | |
6156a456 | 3448 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
6156a456 | 3449 | case DRM_FORMAT_ARGB8888: |
c34ce3d1 | 3450 | return PLANE_CTL_FORMAT_XRGB_8888 | |
6156a456 | 3451 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
70d21f0e | 3452 | case DRM_FORMAT_XRGB2101010: |
c34ce3d1 | 3453 | return PLANE_CTL_FORMAT_XRGB_2101010; |
70d21f0e | 3454 | case DRM_FORMAT_XBGR2101010: |
c34ce3d1 | 3455 | return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010; |
6156a456 | 3456 | case DRM_FORMAT_YUYV: |
c34ce3d1 | 3457 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV; |
6156a456 | 3458 | case DRM_FORMAT_YVYU: |
c34ce3d1 | 3459 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU; |
6156a456 | 3460 | case DRM_FORMAT_UYVY: |
c34ce3d1 | 3461 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY; |
6156a456 | 3462 | case DRM_FORMAT_VYUY: |
c34ce3d1 | 3463 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY; |
70d21f0e | 3464 | default: |
4249eeef | 3465 | MISSING_CASE(pixel_format); |
70d21f0e | 3466 | } |
8cfcba41 | 3467 | |
c34ce3d1 | 3468 | return 0; |
6156a456 | 3469 | } |
70d21f0e | 3470 | |
2e881264 | 3471 | static u32 skl_plane_ctl_tiling(uint64_t fb_modifier) |
6156a456 | 3472 | { |
6156a456 | 3473 | switch (fb_modifier) { |
2f075565 | 3474 | case DRM_FORMAT_MOD_LINEAR: |
70d21f0e | 3475 | break; |
30af77c4 | 3476 | case I915_FORMAT_MOD_X_TILED: |
c34ce3d1 | 3477 | return PLANE_CTL_TILED_X; |
b321803d | 3478 | case I915_FORMAT_MOD_Y_TILED: |
c34ce3d1 | 3479 | return PLANE_CTL_TILED_Y; |
2e2adb05 | 3480 | case I915_FORMAT_MOD_Y_TILED_CCS: |
03ef6b01 | 3481 | return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE; |
b321803d | 3482 | case I915_FORMAT_MOD_Yf_TILED: |
c34ce3d1 | 3483 | return PLANE_CTL_TILED_YF; |
2e2adb05 | 3484 | case I915_FORMAT_MOD_Yf_TILED_CCS: |
03ef6b01 | 3485 | return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE; |
70d21f0e | 3486 | default: |
6156a456 | 3487 | MISSING_CASE(fb_modifier); |
70d21f0e | 3488 | } |
8cfcba41 | 3489 | |
c34ce3d1 | 3490 | return 0; |
6156a456 | 3491 | } |
70d21f0e | 3492 | |
2e881264 | 3493 | static u32 skl_plane_ctl_rotation(unsigned int rotation) |
6156a456 | 3494 | { |
3b7a5119 | 3495 | switch (rotation) { |
c2c446ad | 3496 | case DRM_MODE_ROTATE_0: |
6156a456 | 3497 | break; |
1e8df167 | 3498 | /* |
c2c446ad | 3499 | * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr |
1e8df167 SJ |
3500 | * while i915 HW rotation is clockwise, thats why this swapping. |
3501 | */ | |
c2c446ad | 3502 | case DRM_MODE_ROTATE_90: |
1e8df167 | 3503 | return PLANE_CTL_ROTATE_270; |
c2c446ad | 3504 | case DRM_MODE_ROTATE_180: |
c34ce3d1 | 3505 | return PLANE_CTL_ROTATE_180; |
c2c446ad | 3506 | case DRM_MODE_ROTATE_270: |
1e8df167 | 3507 | return PLANE_CTL_ROTATE_90; |
6156a456 CK |
3508 | default: |
3509 | MISSING_CASE(rotation); | |
3510 | } | |
3511 | ||
c34ce3d1 | 3512 | return 0; |
6156a456 CK |
3513 | } |
3514 | ||
2e881264 VS |
3515 | u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state, |
3516 | const struct intel_plane_state *plane_state) | |
46f788ba VS |
3517 | { |
3518 | struct drm_i915_private *dev_priv = | |
3519 | to_i915(plane_state->base.plane->dev); | |
3520 | const struct drm_framebuffer *fb = plane_state->base.fb; | |
3521 | unsigned int rotation = plane_state->base.rotation; | |
2e881264 | 3522 | const struct drm_intel_sprite_colorkey *key = &plane_state->ckey; |
46f788ba VS |
3523 | u32 plane_ctl; |
3524 | ||
3525 | plane_ctl = PLANE_CTL_ENABLE; | |
3526 | ||
6602be0e | 3527 | if (!IS_GEMINILAKE(dev_priv) && !IS_CANNONLAKE(dev_priv)) { |
46f788ba VS |
3528 | plane_ctl |= |
3529 | PLANE_CTL_PIPE_GAMMA_ENABLE | | |
3530 | PLANE_CTL_PIPE_CSC_ENABLE | | |
3531 | PLANE_CTL_PLANE_GAMMA_DISABLE; | |
3532 | } | |
3533 | ||
3534 | plane_ctl |= skl_plane_ctl_format(fb->format->format); | |
3535 | plane_ctl |= skl_plane_ctl_tiling(fb->modifier); | |
3536 | plane_ctl |= skl_plane_ctl_rotation(rotation); | |
3537 | ||
2e881264 VS |
3538 | if (key->flags & I915_SET_COLORKEY_DESTINATION) |
3539 | plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION; | |
3540 | else if (key->flags & I915_SET_COLORKEY_SOURCE) | |
3541 | plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE; | |
3542 | ||
46f788ba VS |
3543 | return plane_ctl; |
3544 | } | |
3545 | ||
73974893 ML |
3546 | static int |
3547 | __intel_display_resume(struct drm_device *dev, | |
581e49fe ML |
3548 | struct drm_atomic_state *state, |
3549 | struct drm_modeset_acquire_ctx *ctx) | |
73974893 ML |
3550 | { |
3551 | struct drm_crtc_state *crtc_state; | |
3552 | struct drm_crtc *crtc; | |
3553 | int i, ret; | |
11c22da6 | 3554 | |
aecd36b8 | 3555 | intel_modeset_setup_hw_state(dev, ctx); |
29b74b7f | 3556 | i915_redisable_vga(to_i915(dev)); |
73974893 ML |
3557 | |
3558 | if (!state) | |
3559 | return 0; | |
3560 | ||
aa5e9b47 ML |
3561 | /* |
3562 | * We've duplicated the state, pointers to the old state are invalid. | |
3563 | * | |
3564 | * Don't attempt to use the old state until we commit the duplicated state. | |
3565 | */ | |
3566 | for_each_new_crtc_in_state(state, crtc, crtc_state, i) { | |
73974893 ML |
3567 | /* |
3568 | * Force recalculation even if we restore | |
3569 | * current state. With fast modeset this may not result | |
3570 | * in a modeset when the state is compatible. | |
3571 | */ | |
3572 | crtc_state->mode_changed = true; | |
96a02917 | 3573 | } |
73974893 ML |
3574 | |
3575 | /* ignore any reset values/BIOS leftovers in the WM registers */ | |
602ae835 VS |
3576 | if (!HAS_GMCH_DISPLAY(to_i915(dev))) |
3577 | to_intel_atomic_state(state)->skip_intermediate_wm = true; | |
73974893 | 3578 | |
581e49fe | 3579 | ret = drm_atomic_helper_commit_duplicated_state(state, ctx); |
73974893 ML |
3580 | |
3581 | WARN_ON(ret == -EDEADLK); | |
3582 | return ret; | |
96a02917 VS |
3583 | } |
3584 | ||
4ac2ba2f VS |
3585 | static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv) |
3586 | { | |
ae98104b VS |
3587 | return intel_has_gpu_reset(dev_priv) && |
3588 | INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv); | |
4ac2ba2f VS |
3589 | } |
3590 | ||
c033666a | 3591 | void intel_prepare_reset(struct drm_i915_private *dev_priv) |
7514747d | 3592 | { |
73974893 ML |
3593 | struct drm_device *dev = &dev_priv->drm; |
3594 | struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx; | |
3595 | struct drm_atomic_state *state; | |
3596 | int ret; | |
3597 | ||
ce87ea15 DV |
3598 | |
3599 | /* reset doesn't touch the display */ | |
4f044a88 | 3600 | if (!i915_modparams.force_reset_modeset_test && |
ce87ea15 DV |
3601 | !gpu_reset_clobbers_display(dev_priv)) |
3602 | return; | |
3603 | ||
9db529aa DV |
3604 | /* We have a modeset vs reset deadlock, defensively unbreak it. */ |
3605 | set_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags); | |
3606 | wake_up_all(&dev_priv->gpu_error.wait_queue); | |
3607 | ||
3608 | if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) { | |
3609 | DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n"); | |
3610 | i915_gem_set_wedged(dev_priv); | |
3611 | } | |
97154ec2 | 3612 | |
73974893 ML |
3613 | /* |
3614 | * Need mode_config.mutex so that we don't | |
3615 | * trample ongoing ->detect() and whatnot. | |
3616 | */ | |
3617 | mutex_lock(&dev->mode_config.mutex); | |
3618 | drm_modeset_acquire_init(ctx, 0); | |
3619 | while (1) { | |
3620 | ret = drm_modeset_lock_all_ctx(dev, ctx); | |
3621 | if (ret != -EDEADLK) | |
3622 | break; | |
3623 | ||
3624 | drm_modeset_backoff(ctx); | |
3625 | } | |
f98ce92f VS |
3626 | /* |
3627 | * Disabling the crtcs gracefully seems nicer. Also the | |
3628 | * g33 docs say we should at least disable all the planes. | |
3629 | */ | |
73974893 ML |
3630 | state = drm_atomic_helper_duplicate_state(dev, ctx); |
3631 | if (IS_ERR(state)) { | |
3632 | ret = PTR_ERR(state); | |
73974893 | 3633 | DRM_ERROR("Duplicating state failed with %i\n", ret); |
1e5a15d6 | 3634 | return; |
73974893 ML |
3635 | } |
3636 | ||
3637 | ret = drm_atomic_helper_disable_all(dev, ctx); | |
3638 | if (ret) { | |
3639 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); | |
1e5a15d6 ACO |
3640 | drm_atomic_state_put(state); |
3641 | return; | |
73974893 ML |
3642 | } |
3643 | ||
3644 | dev_priv->modeset_restore_state = state; | |
3645 | state->acquire_ctx = ctx; | |
7514747d VS |
3646 | } |
3647 | ||
c033666a | 3648 | void intel_finish_reset(struct drm_i915_private *dev_priv) |
7514747d | 3649 | { |
73974893 ML |
3650 | struct drm_device *dev = &dev_priv->drm; |
3651 | struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx; | |
3652 | struct drm_atomic_state *state = dev_priv->modeset_restore_state; | |
3653 | int ret; | |
3654 | ||
ce87ea15 | 3655 | /* reset doesn't touch the display */ |
4f044a88 | 3656 | if (!i915_modparams.force_reset_modeset_test && |
ce87ea15 DV |
3657 | !gpu_reset_clobbers_display(dev_priv)) |
3658 | return; | |
3659 | ||
3660 | if (!state) | |
3661 | goto unlock; | |
3662 | ||
73974893 ML |
3663 | dev_priv->modeset_restore_state = NULL; |
3664 | ||
7514747d | 3665 | /* reset doesn't touch the display */ |
4ac2ba2f | 3666 | if (!gpu_reset_clobbers_display(dev_priv)) { |
ce87ea15 DV |
3667 | /* for testing only restore the display */ |
3668 | ret = __intel_display_resume(dev, state, ctx); | |
942d5d0d CW |
3669 | if (ret) |
3670 | DRM_ERROR("Restoring old state failed with %i\n", ret); | |
73974893 ML |
3671 | } else { |
3672 | /* | |
3673 | * The display has been reset as well, | |
3674 | * so need a full re-initialization. | |
3675 | */ | |
3676 | intel_runtime_pm_disable_interrupts(dev_priv); | |
3677 | intel_runtime_pm_enable_interrupts(dev_priv); | |
7514747d | 3678 | |
51f59205 | 3679 | intel_pps_unlock_regs_wa(dev_priv); |
73974893 | 3680 | intel_modeset_init_hw(dev); |
6ac43272 | 3681 | intel_init_clock_gating(dev_priv); |
7514747d | 3682 | |
73974893 ML |
3683 | spin_lock_irq(&dev_priv->irq_lock); |
3684 | if (dev_priv->display.hpd_irq_setup) | |
3685 | dev_priv->display.hpd_irq_setup(dev_priv); | |
3686 | spin_unlock_irq(&dev_priv->irq_lock); | |
7514747d | 3687 | |
581e49fe | 3688 | ret = __intel_display_resume(dev, state, ctx); |
73974893 ML |
3689 | if (ret) |
3690 | DRM_ERROR("Restoring old state failed with %i\n", ret); | |
7514747d | 3691 | |
73974893 ML |
3692 | intel_hpd_init(dev_priv); |
3693 | } | |
7514747d | 3694 | |
ce87ea15 DV |
3695 | drm_atomic_state_put(state); |
3696 | unlock: | |
73974893 ML |
3697 | drm_modeset_drop_locks(ctx); |
3698 | drm_modeset_acquire_fini(ctx); | |
3699 | mutex_unlock(&dev->mode_config.mutex); | |
9db529aa DV |
3700 | |
3701 | clear_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags); | |
7514747d VS |
3702 | } |
3703 | ||
1a15b77b VS |
3704 | static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state, |
3705 | const struct intel_crtc_state *new_crtc_state) | |
e30e8f75 | 3706 | { |
1a15b77b | 3707 | struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc); |
6315b5d3 | 3708 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
e30e8f75 | 3709 | |
bfd16b2a | 3710 | /* drm_atomic_helper_update_legacy_modeset_state might not be called. */ |
1a15b77b | 3711 | crtc->base.mode = new_crtc_state->base.mode; |
bfd16b2a | 3712 | |
e30e8f75 GP |
3713 | /* |
3714 | * Update pipe size and adjust fitter if needed: the reason for this is | |
3715 | * that in compute_mode_changes we check the native mode (not the pfit | |
3716 | * mode) to see if we can flip rather than do a full mode set. In the | |
3717 | * fastboot case, we'll flip, but if we don't update the pipesrc and | |
3718 | * pfit state, we'll end up with a big fb scanned out into the wrong | |
3719 | * sized surface. | |
e30e8f75 GP |
3720 | */ |
3721 | ||
e30e8f75 | 3722 | I915_WRITE(PIPESRC(crtc->pipe), |
1a15b77b VS |
3723 | ((new_crtc_state->pipe_src_w - 1) << 16) | |
3724 | (new_crtc_state->pipe_src_h - 1)); | |
bfd16b2a ML |
3725 | |
3726 | /* on skylake this is done by detaching scalers */ | |
6315b5d3 | 3727 | if (INTEL_GEN(dev_priv) >= 9) { |
bfd16b2a ML |
3728 | skl_detach_scalers(crtc); |
3729 | ||
1a15b77b | 3730 | if (new_crtc_state->pch_pfit.enabled) |
bfd16b2a | 3731 | skylake_pfit_enable(crtc); |
6e266956 | 3732 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
1a15b77b | 3733 | if (new_crtc_state->pch_pfit.enabled) |
bfd16b2a ML |
3734 | ironlake_pfit_enable(crtc); |
3735 | else if (old_crtc_state->pch_pfit.enabled) | |
3736 | ironlake_pfit_disable(crtc, true); | |
e30e8f75 | 3737 | } |
e30e8f75 GP |
3738 | } |
3739 | ||
4cbe4b2b | 3740 | static void intel_fdi_normal_train(struct intel_crtc *crtc) |
5e84e1a4 | 3741 | { |
4cbe4b2b | 3742 | struct drm_device *dev = crtc->base.dev; |
fac5e23e | 3743 | struct drm_i915_private *dev_priv = to_i915(dev); |
4cbe4b2b | 3744 | int pipe = crtc->pipe; |
f0f59a00 VS |
3745 | i915_reg_t reg; |
3746 | u32 temp; | |
5e84e1a4 ZW |
3747 | |
3748 | /* enable normal train */ | |
3749 | reg = FDI_TX_CTL(pipe); | |
3750 | temp = I915_READ(reg); | |
fd6b8f43 | 3751 | if (IS_IVYBRIDGE(dev_priv)) { |
357555c0 JB |
3752 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
3753 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; | |
61e499bf KP |
3754 | } else { |
3755 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3756 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; | |
357555c0 | 3757 | } |
5e84e1a4 ZW |
3758 | I915_WRITE(reg, temp); |
3759 | ||
3760 | reg = FDI_RX_CTL(pipe); | |
3761 | temp = I915_READ(reg); | |
6e266956 | 3762 | if (HAS_PCH_CPT(dev_priv)) { |
5e84e1a4 ZW |
3763 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
3764 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; | |
3765 | } else { | |
3766 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3767 | temp |= FDI_LINK_TRAIN_NONE; | |
3768 | } | |
3769 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); | |
3770 | ||
3771 | /* wait one idle pattern time */ | |
3772 | POSTING_READ(reg); | |
3773 | udelay(1000); | |
357555c0 JB |
3774 | |
3775 | /* IVB wants error correction enabled */ | |
fd6b8f43 | 3776 | if (IS_IVYBRIDGE(dev_priv)) |
357555c0 JB |
3777 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | |
3778 | FDI_FE_ERRC_ENABLE); | |
5e84e1a4 ZW |
3779 | } |
3780 | ||
8db9d77b | 3781 | /* The FDI link training functions for ILK/Ibexpeak. */ |
dc4a1094 ACO |
3782 | static void ironlake_fdi_link_train(struct intel_crtc *crtc, |
3783 | const struct intel_crtc_state *crtc_state) | |
8db9d77b | 3784 | { |
4cbe4b2b | 3785 | struct drm_device *dev = crtc->base.dev; |
fac5e23e | 3786 | struct drm_i915_private *dev_priv = to_i915(dev); |
4cbe4b2b | 3787 | int pipe = crtc->pipe; |
f0f59a00 VS |
3788 | i915_reg_t reg; |
3789 | u32 temp, tries; | |
8db9d77b | 3790 | |
1c8562f6 | 3791 | /* FDI needs bits from pipe first */ |
0fc932b8 | 3792 | assert_pipe_enabled(dev_priv, pipe); |
0fc932b8 | 3793 | |
e1a44743 AJ |
3794 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
3795 | for train result */ | |
5eddb70b CW |
3796 | reg = FDI_RX_IMR(pipe); |
3797 | temp = I915_READ(reg); | |
e1a44743 AJ |
3798 | temp &= ~FDI_RX_SYMBOL_LOCK; |
3799 | temp &= ~FDI_RX_BIT_LOCK; | |
5eddb70b CW |
3800 | I915_WRITE(reg, temp); |
3801 | I915_READ(reg); | |
e1a44743 AJ |
3802 | udelay(150); |
3803 | ||
8db9d77b | 3804 | /* enable CPU FDI TX and PCH FDI RX */ |
5eddb70b CW |
3805 | reg = FDI_TX_CTL(pipe); |
3806 | temp = I915_READ(reg); | |
627eb5a3 | 3807 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
dc4a1094 | 3808 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
8db9d77b ZW |
3809 | temp &= ~FDI_LINK_TRAIN_NONE; |
3810 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
5eddb70b | 3811 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
8db9d77b | 3812 | |
5eddb70b CW |
3813 | reg = FDI_RX_CTL(pipe); |
3814 | temp = I915_READ(reg); | |
8db9d77b ZW |
3815 | temp &= ~FDI_LINK_TRAIN_NONE; |
3816 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
5eddb70b CW |
3817 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
3818 | ||
3819 | POSTING_READ(reg); | |
8db9d77b ZW |
3820 | udelay(150); |
3821 | ||
5b2adf89 | 3822 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
8f5718a6 DV |
3823 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
3824 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | | |
3825 | FDI_RX_PHASE_SYNC_POINTER_EN); | |
5b2adf89 | 3826 | |
5eddb70b | 3827 | reg = FDI_RX_IIR(pipe); |
e1a44743 | 3828 | for (tries = 0; tries < 5; tries++) { |
5eddb70b | 3829 | temp = I915_READ(reg); |
8db9d77b ZW |
3830 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
3831 | ||
3832 | if ((temp & FDI_RX_BIT_LOCK)) { | |
3833 | DRM_DEBUG_KMS("FDI train 1 done.\n"); | |
5eddb70b | 3834 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
8db9d77b ZW |
3835 | break; |
3836 | } | |
8db9d77b | 3837 | } |
e1a44743 | 3838 | if (tries == 5) |
5eddb70b | 3839 | DRM_ERROR("FDI train 1 fail!\n"); |
8db9d77b ZW |
3840 | |
3841 | /* Train 2 */ | |
5eddb70b CW |
3842 | reg = FDI_TX_CTL(pipe); |
3843 | temp = I915_READ(reg); | |
8db9d77b ZW |
3844 | temp &= ~FDI_LINK_TRAIN_NONE; |
3845 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
5eddb70b | 3846 | I915_WRITE(reg, temp); |
8db9d77b | 3847 | |
5eddb70b CW |
3848 | reg = FDI_RX_CTL(pipe); |
3849 | temp = I915_READ(reg); | |
8db9d77b ZW |
3850 | temp &= ~FDI_LINK_TRAIN_NONE; |
3851 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
5eddb70b | 3852 | I915_WRITE(reg, temp); |
8db9d77b | 3853 | |
5eddb70b CW |
3854 | POSTING_READ(reg); |
3855 | udelay(150); | |
8db9d77b | 3856 | |
5eddb70b | 3857 | reg = FDI_RX_IIR(pipe); |
e1a44743 | 3858 | for (tries = 0; tries < 5; tries++) { |
5eddb70b | 3859 | temp = I915_READ(reg); |
8db9d77b ZW |
3860 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
3861 | ||
3862 | if (temp & FDI_RX_SYMBOL_LOCK) { | |
5eddb70b | 3863 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
8db9d77b ZW |
3864 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
3865 | break; | |
3866 | } | |
8db9d77b | 3867 | } |
e1a44743 | 3868 | if (tries == 5) |
5eddb70b | 3869 | DRM_ERROR("FDI train 2 fail!\n"); |
8db9d77b ZW |
3870 | |
3871 | DRM_DEBUG_KMS("FDI train done\n"); | |
5c5313c8 | 3872 | |
8db9d77b ZW |
3873 | } |
3874 | ||
0206e353 | 3875 | static const int snb_b_fdi_train_param[] = { |
8db9d77b ZW |
3876 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
3877 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, | |
3878 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, | |
3879 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, | |
3880 | }; | |
3881 | ||
3882 | /* The FDI link training functions for SNB/Cougarpoint. */ | |
dc4a1094 ACO |
3883 | static void gen6_fdi_link_train(struct intel_crtc *crtc, |
3884 | const struct intel_crtc_state *crtc_state) | |
8db9d77b | 3885 | { |
4cbe4b2b | 3886 | struct drm_device *dev = crtc->base.dev; |
fac5e23e | 3887 | struct drm_i915_private *dev_priv = to_i915(dev); |
4cbe4b2b | 3888 | int pipe = crtc->pipe; |
f0f59a00 VS |
3889 | i915_reg_t reg; |
3890 | u32 temp, i, retry; | |
8db9d77b | 3891 | |
e1a44743 AJ |
3892 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
3893 | for train result */ | |
5eddb70b CW |
3894 | reg = FDI_RX_IMR(pipe); |
3895 | temp = I915_READ(reg); | |
e1a44743 AJ |
3896 | temp &= ~FDI_RX_SYMBOL_LOCK; |
3897 | temp &= ~FDI_RX_BIT_LOCK; | |
5eddb70b CW |
3898 | I915_WRITE(reg, temp); |
3899 | ||
3900 | POSTING_READ(reg); | |
e1a44743 AJ |
3901 | udelay(150); |
3902 | ||
8db9d77b | 3903 | /* enable CPU FDI TX and PCH FDI RX */ |
5eddb70b CW |
3904 | reg = FDI_TX_CTL(pipe); |
3905 | temp = I915_READ(reg); | |
627eb5a3 | 3906 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
dc4a1094 | 3907 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
8db9d77b ZW |
3908 | temp &= ~FDI_LINK_TRAIN_NONE; |
3909 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3910 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; | |
3911 | /* SNB-B */ | |
3912 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; | |
5eddb70b | 3913 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
8db9d77b | 3914 | |
d74cf324 DV |
3915 | I915_WRITE(FDI_RX_MISC(pipe), |
3916 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); | |
3917 | ||
5eddb70b CW |
3918 | reg = FDI_RX_CTL(pipe); |
3919 | temp = I915_READ(reg); | |
6e266956 | 3920 | if (HAS_PCH_CPT(dev_priv)) { |
8db9d77b ZW |
3921 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
3922 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; | |
3923 | } else { | |
3924 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3925 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
3926 | } | |
5eddb70b CW |
3927 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
3928 | ||
3929 | POSTING_READ(reg); | |
8db9d77b ZW |
3930 | udelay(150); |
3931 | ||
0206e353 | 3932 | for (i = 0; i < 4; i++) { |
5eddb70b CW |
3933 | reg = FDI_TX_CTL(pipe); |
3934 | temp = I915_READ(reg); | |
8db9d77b ZW |
3935 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
3936 | temp |= snb_b_fdi_train_param[i]; | |
5eddb70b CW |
3937 | I915_WRITE(reg, temp); |
3938 | ||
3939 | POSTING_READ(reg); | |
8db9d77b ZW |
3940 | udelay(500); |
3941 | ||
fa37d39e SP |
3942 | for (retry = 0; retry < 5; retry++) { |
3943 | reg = FDI_RX_IIR(pipe); | |
3944 | temp = I915_READ(reg); | |
3945 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
3946 | if (temp & FDI_RX_BIT_LOCK) { | |
3947 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); | |
3948 | DRM_DEBUG_KMS("FDI train 1 done.\n"); | |
3949 | break; | |
3950 | } | |
3951 | udelay(50); | |
8db9d77b | 3952 | } |
fa37d39e SP |
3953 | if (retry < 5) |
3954 | break; | |
8db9d77b ZW |
3955 | } |
3956 | if (i == 4) | |
5eddb70b | 3957 | DRM_ERROR("FDI train 1 fail!\n"); |
8db9d77b ZW |
3958 | |
3959 | /* Train 2 */ | |
5eddb70b CW |
3960 | reg = FDI_TX_CTL(pipe); |
3961 | temp = I915_READ(reg); | |
8db9d77b ZW |
3962 | temp &= ~FDI_LINK_TRAIN_NONE; |
3963 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
5db94019 | 3964 | if (IS_GEN6(dev_priv)) { |
8db9d77b ZW |
3965 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
3966 | /* SNB-B */ | |
3967 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; | |
3968 | } | |
5eddb70b | 3969 | I915_WRITE(reg, temp); |
8db9d77b | 3970 | |
5eddb70b CW |
3971 | reg = FDI_RX_CTL(pipe); |
3972 | temp = I915_READ(reg); | |
6e266956 | 3973 | if (HAS_PCH_CPT(dev_priv)) { |
8db9d77b ZW |
3974 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
3975 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; | |
3976 | } else { | |
3977 | temp &= ~FDI_LINK_TRAIN_NONE; | |
3978 | temp |= FDI_LINK_TRAIN_PATTERN_2; | |
3979 | } | |
5eddb70b CW |
3980 | I915_WRITE(reg, temp); |
3981 | ||
3982 | POSTING_READ(reg); | |
8db9d77b ZW |
3983 | udelay(150); |
3984 | ||
0206e353 | 3985 | for (i = 0; i < 4; i++) { |
5eddb70b CW |
3986 | reg = FDI_TX_CTL(pipe); |
3987 | temp = I915_READ(reg); | |
8db9d77b ZW |
3988 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
3989 | temp |= snb_b_fdi_train_param[i]; | |
5eddb70b CW |
3990 | I915_WRITE(reg, temp); |
3991 | ||
3992 | POSTING_READ(reg); | |
8db9d77b ZW |
3993 | udelay(500); |
3994 | ||
fa37d39e SP |
3995 | for (retry = 0; retry < 5; retry++) { |
3996 | reg = FDI_RX_IIR(pipe); | |
3997 | temp = I915_READ(reg); | |
3998 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
3999 | if (temp & FDI_RX_SYMBOL_LOCK) { | |
4000 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); | |
4001 | DRM_DEBUG_KMS("FDI train 2 done.\n"); | |
4002 | break; | |
4003 | } | |
4004 | udelay(50); | |
8db9d77b | 4005 | } |
fa37d39e SP |
4006 | if (retry < 5) |
4007 | break; | |
8db9d77b ZW |
4008 | } |
4009 | if (i == 4) | |
5eddb70b | 4010 | DRM_ERROR("FDI train 2 fail!\n"); |
8db9d77b ZW |
4011 | |
4012 | DRM_DEBUG_KMS("FDI train done.\n"); | |
4013 | } | |
4014 | ||
357555c0 | 4015 | /* Manual link training for Ivy Bridge A0 parts */ |
dc4a1094 ACO |
4016 | static void ivb_manual_fdi_link_train(struct intel_crtc *crtc, |
4017 | const struct intel_crtc_state *crtc_state) | |
357555c0 | 4018 | { |
4cbe4b2b | 4019 | struct drm_device *dev = crtc->base.dev; |
fac5e23e | 4020 | struct drm_i915_private *dev_priv = to_i915(dev); |
4cbe4b2b | 4021 | int pipe = crtc->pipe; |
f0f59a00 VS |
4022 | i915_reg_t reg; |
4023 | u32 temp, i, j; | |
357555c0 JB |
4024 | |
4025 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit | |
4026 | for train result */ | |
4027 | reg = FDI_RX_IMR(pipe); | |
4028 | temp = I915_READ(reg); | |
4029 | temp &= ~FDI_RX_SYMBOL_LOCK; | |
4030 | temp &= ~FDI_RX_BIT_LOCK; | |
4031 | I915_WRITE(reg, temp); | |
4032 | ||
4033 | POSTING_READ(reg); | |
4034 | udelay(150); | |
4035 | ||
01a415fd DV |
4036 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
4037 | I915_READ(FDI_RX_IIR(pipe))); | |
4038 | ||
139ccd3f JB |
4039 | /* Try each vswing and preemphasis setting twice before moving on */ |
4040 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { | |
4041 | /* disable first in case we need to retry */ | |
4042 | reg = FDI_TX_CTL(pipe); | |
4043 | temp = I915_READ(reg); | |
4044 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); | |
4045 | temp &= ~FDI_TX_ENABLE; | |
4046 | I915_WRITE(reg, temp); | |
357555c0 | 4047 | |
139ccd3f JB |
4048 | reg = FDI_RX_CTL(pipe); |
4049 | temp = I915_READ(reg); | |
4050 | temp &= ~FDI_LINK_TRAIN_AUTO; | |
4051 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
4052 | temp &= ~FDI_RX_ENABLE; | |
4053 | I915_WRITE(reg, temp); | |
357555c0 | 4054 | |
139ccd3f | 4055 | /* enable CPU FDI TX and PCH FDI RX */ |
357555c0 JB |
4056 | reg = FDI_TX_CTL(pipe); |
4057 | temp = I915_READ(reg); | |
139ccd3f | 4058 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
dc4a1094 | 4059 | temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); |
139ccd3f | 4060 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
357555c0 | 4061 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
139ccd3f JB |
4062 | temp |= snb_b_fdi_train_param[j/2]; |
4063 | temp |= FDI_COMPOSITE_SYNC; | |
4064 | I915_WRITE(reg, temp | FDI_TX_ENABLE); | |
357555c0 | 4065 | |
139ccd3f JB |
4066 | I915_WRITE(FDI_RX_MISC(pipe), |
4067 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); | |
357555c0 | 4068 | |
139ccd3f | 4069 | reg = FDI_RX_CTL(pipe); |
357555c0 | 4070 | temp = I915_READ(reg); |
139ccd3f JB |
4071 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
4072 | temp |= FDI_COMPOSITE_SYNC; | |
4073 | I915_WRITE(reg, temp | FDI_RX_ENABLE); | |
357555c0 | 4074 | |
139ccd3f JB |
4075 | POSTING_READ(reg); |
4076 | udelay(1); /* should be 0.5us */ | |
357555c0 | 4077 | |
139ccd3f JB |
4078 | for (i = 0; i < 4; i++) { |
4079 | reg = FDI_RX_IIR(pipe); | |
4080 | temp = I915_READ(reg); | |
4081 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
357555c0 | 4082 | |
139ccd3f JB |
4083 | if (temp & FDI_RX_BIT_LOCK || |
4084 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { | |
4085 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); | |
4086 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", | |
4087 | i); | |
4088 | break; | |
4089 | } | |
4090 | udelay(1); /* should be 0.5us */ | |
4091 | } | |
4092 | if (i == 4) { | |
4093 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); | |
4094 | continue; | |
4095 | } | |
357555c0 | 4096 | |
139ccd3f | 4097 | /* Train 2 */ |
357555c0 JB |
4098 | reg = FDI_TX_CTL(pipe); |
4099 | temp = I915_READ(reg); | |
139ccd3f JB |
4100 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
4101 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; | |
4102 | I915_WRITE(reg, temp); | |
4103 | ||
4104 | reg = FDI_RX_CTL(pipe); | |
4105 | temp = I915_READ(reg); | |
4106 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; | |
4107 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; | |
357555c0 JB |
4108 | I915_WRITE(reg, temp); |
4109 | ||
4110 | POSTING_READ(reg); | |
139ccd3f | 4111 | udelay(2); /* should be 1.5us */ |
357555c0 | 4112 | |
139ccd3f JB |
4113 | for (i = 0; i < 4; i++) { |
4114 | reg = FDI_RX_IIR(pipe); | |
4115 | temp = I915_READ(reg); | |
4116 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); | |
357555c0 | 4117 | |
139ccd3f JB |
4118 | if (temp & FDI_RX_SYMBOL_LOCK || |
4119 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { | |
4120 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); | |
4121 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", | |
4122 | i); | |
4123 | goto train_done; | |
4124 | } | |
4125 | udelay(2); /* should be 1.5us */ | |
357555c0 | 4126 | } |
139ccd3f JB |
4127 | if (i == 4) |
4128 | DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2); | |
357555c0 | 4129 | } |
357555c0 | 4130 | |
139ccd3f | 4131 | train_done: |
357555c0 JB |
4132 | DRM_DEBUG_KMS("FDI train done.\n"); |
4133 | } | |
4134 | ||
88cefb6c | 4135 | static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc) |
2c07245f | 4136 | { |
88cefb6c | 4137 | struct drm_device *dev = intel_crtc->base.dev; |
fac5e23e | 4138 | struct drm_i915_private *dev_priv = to_i915(dev); |
2c07245f | 4139 | int pipe = intel_crtc->pipe; |
f0f59a00 VS |
4140 | i915_reg_t reg; |
4141 | u32 temp; | |
c64e311e | 4142 | |
c98e9dcf | 4143 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
5eddb70b CW |
4144 | reg = FDI_RX_CTL(pipe); |
4145 | temp = I915_READ(reg); | |
627eb5a3 | 4146 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
6e3c9717 | 4147 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
dfd07d72 | 4148 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
5eddb70b CW |
4149 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
4150 | ||
4151 | POSTING_READ(reg); | |
c98e9dcf JB |
4152 | udelay(200); |
4153 | ||
4154 | /* Switch from Rawclk to PCDclk */ | |
5eddb70b CW |
4155 | temp = I915_READ(reg); |
4156 | I915_WRITE(reg, temp | FDI_PCDCLK); | |
4157 | ||
4158 | POSTING_READ(reg); | |
c98e9dcf JB |
4159 | udelay(200); |
4160 | ||
20749730 PZ |
4161 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
4162 | reg = FDI_TX_CTL(pipe); | |
4163 | temp = I915_READ(reg); | |
4164 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { | |
4165 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); | |
5eddb70b | 4166 | |
20749730 PZ |
4167 | POSTING_READ(reg); |
4168 | udelay(100); | |
6be4a607 | 4169 | } |
0e23b99d JB |
4170 | } |
4171 | ||
88cefb6c DV |
4172 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
4173 | { | |
4174 | struct drm_device *dev = intel_crtc->base.dev; | |
fac5e23e | 4175 | struct drm_i915_private *dev_priv = to_i915(dev); |
88cefb6c | 4176 | int pipe = intel_crtc->pipe; |
f0f59a00 VS |
4177 | i915_reg_t reg; |
4178 | u32 temp; | |
88cefb6c DV |
4179 | |
4180 | /* Switch from PCDclk to Rawclk */ | |
4181 | reg = FDI_RX_CTL(pipe); | |
4182 | temp = I915_READ(reg); | |
4183 | I915_WRITE(reg, temp & ~FDI_PCDCLK); | |
4184 | ||
4185 | /* Disable CPU FDI TX PLL */ | |
4186 | reg = FDI_TX_CTL(pipe); | |
4187 | temp = I915_READ(reg); | |
4188 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); | |
4189 | ||
4190 | POSTING_READ(reg); | |
4191 | udelay(100); | |
4192 | ||
4193 | reg = FDI_RX_CTL(pipe); | |
4194 | temp = I915_READ(reg); | |
4195 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); | |
4196 | ||
4197 | /* Wait for the clocks to turn off. */ | |
4198 | POSTING_READ(reg); | |
4199 | udelay(100); | |
4200 | } | |
4201 | ||
0fc932b8 JB |
4202 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
4203 | { | |
4204 | struct drm_device *dev = crtc->dev; | |
fac5e23e | 4205 | struct drm_i915_private *dev_priv = to_i915(dev); |
0fc932b8 JB |
4206 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
4207 | int pipe = intel_crtc->pipe; | |
f0f59a00 VS |
4208 | i915_reg_t reg; |
4209 | u32 temp; | |
0fc932b8 JB |
4210 | |
4211 | /* disable CPU FDI tx and PCH FDI rx */ | |
4212 | reg = FDI_TX_CTL(pipe); | |
4213 | temp = I915_READ(reg); | |
4214 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); | |
4215 | POSTING_READ(reg); | |
4216 | ||
4217 | reg = FDI_RX_CTL(pipe); | |
4218 | temp = I915_READ(reg); | |
4219 | temp &= ~(0x7 << 16); | |
dfd07d72 | 4220 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
0fc932b8 JB |
4221 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
4222 | ||
4223 | POSTING_READ(reg); | |
4224 | udelay(100); | |
4225 | ||
4226 | /* Ironlake workaround, disable clock pointer after downing FDI */ | |
6e266956 | 4227 | if (HAS_PCH_IBX(dev_priv)) |
6f06ce18 | 4228 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
0fc932b8 JB |
4229 | |
4230 | /* still set train pattern 1 */ | |
4231 | reg = FDI_TX_CTL(pipe); | |
4232 | temp = I915_READ(reg); | |
4233 | temp &= ~FDI_LINK_TRAIN_NONE; | |
4234 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
4235 | I915_WRITE(reg, temp); | |
4236 | ||
4237 | reg = FDI_RX_CTL(pipe); | |
4238 | temp = I915_READ(reg); | |
6e266956 | 4239 | if (HAS_PCH_CPT(dev_priv)) { |
0fc932b8 JB |
4240 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
4241 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; | |
4242 | } else { | |
4243 | temp &= ~FDI_LINK_TRAIN_NONE; | |
4244 | temp |= FDI_LINK_TRAIN_PATTERN_1; | |
4245 | } | |
4246 | /* BPC in FDI rx is consistent with that in PIPECONF */ | |
4247 | temp &= ~(0x07 << 16); | |
dfd07d72 | 4248 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
0fc932b8 JB |
4249 | I915_WRITE(reg, temp); |
4250 | ||
4251 | POSTING_READ(reg); | |
4252 | udelay(100); | |
4253 | } | |
4254 | ||
49d73912 | 4255 | bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv) |
5dce5b93 | 4256 | { |
fa05887a DV |
4257 | struct drm_crtc *crtc; |
4258 | bool cleanup_done; | |
4259 | ||
4260 | drm_for_each_crtc(crtc, &dev_priv->drm) { | |
4261 | struct drm_crtc_commit *commit; | |
4262 | spin_lock(&crtc->commit_lock); | |
4263 | commit = list_first_entry_or_null(&crtc->commit_list, | |
4264 | struct drm_crtc_commit, commit_entry); | |
4265 | cleanup_done = commit ? | |
4266 | try_wait_for_completion(&commit->cleanup_done) : true; | |
4267 | spin_unlock(&crtc->commit_lock); | |
4268 | ||
4269 | if (cleanup_done) | |
5dce5b93 CW |
4270 | continue; |
4271 | ||
fa05887a | 4272 | drm_crtc_wait_one_vblank(crtc); |
5dce5b93 CW |
4273 | |
4274 | return true; | |
4275 | } | |
4276 | ||
4277 | return false; | |
4278 | } | |
4279 | ||
b7076546 | 4280 | void lpt_disable_iclkip(struct drm_i915_private *dev_priv) |
060f02d8 VS |
4281 | { |
4282 | u32 temp; | |
4283 | ||
4284 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); | |
4285 | ||
4286 | mutex_lock(&dev_priv->sb_lock); | |
4287 | ||
4288 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); | |
4289 | temp |= SBI_SSCCTL_DISABLE; | |
4290 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); | |
4291 | ||
4292 | mutex_unlock(&dev_priv->sb_lock); | |
4293 | } | |
4294 | ||
e615efe4 | 4295 | /* Program iCLKIP clock to the desired frequency */ |
0dcdc382 | 4296 | static void lpt_program_iclkip(struct intel_crtc *crtc) |
e615efe4 | 4297 | { |
0dcdc382 ACO |
4298 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
4299 | int clock = crtc->config->base.adjusted_mode.crtc_clock; | |
e615efe4 ED |
4300 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
4301 | u32 temp; | |
4302 | ||
060f02d8 | 4303 | lpt_disable_iclkip(dev_priv); |
e615efe4 | 4304 | |
64b46a06 VS |
4305 | /* The iCLK virtual clock root frequency is in MHz, |
4306 | * but the adjusted_mode->crtc_clock in in KHz. To get the | |
4307 | * divisors, it is necessary to divide one by another, so we | |
4308 | * convert the virtual clock precision to KHz here for higher | |
4309 | * precision. | |
4310 | */ | |
4311 | for (auxdiv = 0; auxdiv < 2; auxdiv++) { | |
e615efe4 ED |
4312 | u32 iclk_virtual_root_freq = 172800 * 1000; |
4313 | u32 iclk_pi_range = 64; | |
64b46a06 | 4314 | u32 desired_divisor; |
e615efe4 | 4315 | |
64b46a06 VS |
4316 | desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq, |
4317 | clock << auxdiv); | |
4318 | divsel = (desired_divisor / iclk_pi_range) - 2; | |
4319 | phaseinc = desired_divisor % iclk_pi_range; | |
e615efe4 | 4320 | |
64b46a06 VS |
4321 | /* |
4322 | * Near 20MHz is a corner case which is | |
4323 | * out of range for the 7-bit divisor | |
4324 | */ | |
4325 | if (divsel <= 0x7f) | |
4326 | break; | |
e615efe4 ED |
4327 | } |
4328 | ||
4329 | /* This should not happen with any sane values */ | |
4330 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & | |
4331 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); | |
4332 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & | |
4333 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); | |
4334 | ||
4335 | DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n", | |
12d7ceed | 4336 | clock, |
e615efe4 ED |
4337 | auxdiv, |
4338 | divsel, | |
4339 | phasedir, | |
4340 | phaseinc); | |
4341 | ||
060f02d8 VS |
4342 | mutex_lock(&dev_priv->sb_lock); |
4343 | ||
e615efe4 | 4344 | /* Program SSCDIVINTPHASE6 */ |
988d6ee8 | 4345 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
e615efe4 ED |
4346 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
4347 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); | |
4348 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; | |
4349 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); | |
4350 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); | |
4351 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; | |
988d6ee8 | 4352 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
e615efe4 ED |
4353 | |
4354 | /* Program SSCAUXDIV */ | |
988d6ee8 | 4355 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
e615efe4 ED |
4356 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
4357 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); | |
988d6ee8 | 4358 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
e615efe4 ED |
4359 | |
4360 | /* Enable modulator and associated divider */ | |
988d6ee8 | 4361 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
e615efe4 | 4362 | temp &= ~SBI_SSCCTL_DISABLE; |
988d6ee8 | 4363 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
e615efe4 | 4364 | |
060f02d8 VS |
4365 | mutex_unlock(&dev_priv->sb_lock); |
4366 | ||
e615efe4 ED |
4367 | /* Wait for initialization time */ |
4368 | udelay(24); | |
4369 | ||
4370 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); | |
4371 | } | |
4372 | ||
8802e5b6 VS |
4373 | int lpt_get_iclkip(struct drm_i915_private *dev_priv) |
4374 | { | |
4375 | u32 divsel, phaseinc, auxdiv; | |
4376 | u32 iclk_virtual_root_freq = 172800 * 1000; | |
4377 | u32 iclk_pi_range = 64; | |
4378 | u32 desired_divisor; | |
4379 | u32 temp; | |
4380 | ||
4381 | if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0) | |
4382 | return 0; | |
4383 | ||
4384 | mutex_lock(&dev_priv->sb_lock); | |
4385 | ||
4386 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); | |
4387 | if (temp & SBI_SSCCTL_DISABLE) { | |
4388 | mutex_unlock(&dev_priv->sb_lock); | |
4389 | return 0; | |
4390 | } | |
4391 | ||
4392 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); | |
4393 | divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >> | |
4394 | SBI_SSCDIVINTPHASE_DIVSEL_SHIFT; | |
4395 | phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >> | |
4396 | SBI_SSCDIVINTPHASE_INCVAL_SHIFT; | |
4397 | ||
4398 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); | |
4399 | auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >> | |
4400 | SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT; | |
4401 | ||
4402 | mutex_unlock(&dev_priv->sb_lock); | |
4403 | ||
4404 | desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc; | |
4405 | ||
4406 | return DIV_ROUND_CLOSEST(iclk_virtual_root_freq, | |
4407 | desired_divisor << auxdiv); | |
4408 | } | |
4409 | ||
275f01b2 DV |
4410 | static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc, |
4411 | enum pipe pch_transcoder) | |
4412 | { | |
4413 | struct drm_device *dev = crtc->base.dev; | |
fac5e23e | 4414 | struct drm_i915_private *dev_priv = to_i915(dev); |
6e3c9717 | 4415 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
275f01b2 DV |
4416 | |
4417 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), | |
4418 | I915_READ(HTOTAL(cpu_transcoder))); | |
4419 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), | |
4420 | I915_READ(HBLANK(cpu_transcoder))); | |
4421 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), | |
4422 | I915_READ(HSYNC(cpu_transcoder))); | |
4423 | ||
4424 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), | |
4425 | I915_READ(VTOTAL(cpu_transcoder))); | |
4426 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), | |
4427 | I915_READ(VBLANK(cpu_transcoder))); | |
4428 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), | |
4429 | I915_READ(VSYNC(cpu_transcoder))); | |
4430 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), | |
4431 | I915_READ(VSYNCSHIFT(cpu_transcoder))); | |
4432 | } | |
4433 | ||
003632d9 | 4434 | static void cpt_set_fdi_bc_bifurcation(struct drm_device *dev, bool enable) |
1fbc0d78 | 4435 | { |
fac5e23e | 4436 | struct drm_i915_private *dev_priv = to_i915(dev); |
1fbc0d78 DV |
4437 | uint32_t temp; |
4438 | ||
4439 | temp = I915_READ(SOUTH_CHICKEN1); | |
003632d9 | 4440 | if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable) |
1fbc0d78 DV |
4441 | return; |
4442 | ||
4443 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); | |
4444 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); | |
4445 | ||
003632d9 ACO |
4446 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
4447 | if (enable) | |
4448 | temp |= FDI_BC_BIFURCATION_SELECT; | |
4449 | ||
4450 | DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis"); | |
1fbc0d78 DV |
4451 | I915_WRITE(SOUTH_CHICKEN1, temp); |
4452 | POSTING_READ(SOUTH_CHICKEN1); | |
4453 | } | |
4454 | ||
4455 | static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc) | |
4456 | { | |
4457 | struct drm_device *dev = intel_crtc->base.dev; | |
1fbc0d78 DV |
4458 | |
4459 | switch (intel_crtc->pipe) { | |
4460 | case PIPE_A: | |
4461 | break; | |
4462 | case PIPE_B: | |
6e3c9717 | 4463 | if (intel_crtc->config->fdi_lanes > 2) |
003632d9 | 4464 | cpt_set_fdi_bc_bifurcation(dev, false); |
1fbc0d78 | 4465 | else |
003632d9 | 4466 | cpt_set_fdi_bc_bifurcation(dev, true); |
1fbc0d78 DV |
4467 | |
4468 | break; | |
4469 | case PIPE_C: | |
003632d9 | 4470 | cpt_set_fdi_bc_bifurcation(dev, true); |
1fbc0d78 DV |
4471 | |
4472 | break; | |
4473 | default: | |
4474 | BUG(); | |
4475 | } | |
4476 | } | |
4477 | ||
c48b5305 VS |
4478 | /* Return which DP Port should be selected for Transcoder DP control */ |
4479 | static enum port | |
4cbe4b2b | 4480 | intel_trans_dp_port_sel(struct intel_crtc *crtc) |
c48b5305 | 4481 | { |
4cbe4b2b | 4482 | struct drm_device *dev = crtc->base.dev; |
c48b5305 VS |
4483 | struct intel_encoder *encoder; |
4484 | ||
4cbe4b2b | 4485 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) { |
cca0502b | 4486 | if (encoder->type == INTEL_OUTPUT_DP || |
c48b5305 VS |
4487 | encoder->type == INTEL_OUTPUT_EDP) |
4488 | return enc_to_dig_port(&encoder->base)->port; | |
4489 | } | |
4490 | ||
4491 | return -1; | |
4492 | } | |
4493 | ||
f67a559d JB |
4494 | /* |
4495 | * Enable PCH resources required for PCH ports: | |
4496 | * - PCH PLLs | |
4497 | * - FDI training & RX/TX | |
4498 | * - update transcoder timings | |
4499 | * - DP transcoding bits | |
4500 | * - transcoder | |
4501 | */ | |
2ce42273 | 4502 | static void ironlake_pch_enable(const struct intel_crtc_state *crtc_state) |
0e23b99d | 4503 | { |
2ce42273 | 4504 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
4cbe4b2b | 4505 | struct drm_device *dev = crtc->base.dev; |
fac5e23e | 4506 | struct drm_i915_private *dev_priv = to_i915(dev); |
4cbe4b2b | 4507 | int pipe = crtc->pipe; |
f0f59a00 | 4508 | u32 temp; |
2c07245f | 4509 | |
ab9412ba | 4510 | assert_pch_transcoder_disabled(dev_priv, pipe); |
e7e164db | 4511 | |
fd6b8f43 | 4512 | if (IS_IVYBRIDGE(dev_priv)) |
4cbe4b2b | 4513 | ivybridge_update_fdi_bc_bifurcation(crtc); |
1fbc0d78 | 4514 | |
cd986abb DV |
4515 | /* Write the TU size bits before fdi link training, so that error |
4516 | * detection works. */ | |
4517 | I915_WRITE(FDI_RX_TUSIZE1(pipe), | |
4518 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); | |
4519 | ||
c98e9dcf | 4520 | /* For PCH output, training FDI link */ |
dc4a1094 | 4521 | dev_priv->display.fdi_link_train(crtc, crtc_state); |
2c07245f | 4522 | |
3ad8a208 DV |
4523 | /* We need to program the right clock selection before writing the pixel |
4524 | * mutliplier into the DPLL. */ | |
6e266956 | 4525 | if (HAS_PCH_CPT(dev_priv)) { |
ee7b9f93 | 4526 | u32 sel; |
4b645f14 | 4527 | |
c98e9dcf | 4528 | temp = I915_READ(PCH_DPLL_SEL); |
11887397 DV |
4529 | temp |= TRANS_DPLL_ENABLE(pipe); |
4530 | sel = TRANS_DPLLB_SEL(pipe); | |
2ce42273 | 4531 | if (crtc_state->shared_dpll == |
8106ddbd | 4532 | intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B)) |
ee7b9f93 JB |
4533 | temp |= sel; |
4534 | else | |
4535 | temp &= ~sel; | |
c98e9dcf | 4536 | I915_WRITE(PCH_DPLL_SEL, temp); |
c98e9dcf | 4537 | } |
5eddb70b | 4538 | |
3ad8a208 DV |
4539 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
4540 | * transcoder, and we actually should do this to not upset any PCH | |
4541 | * transcoder that already use the clock when we share it. | |
4542 | * | |
4543 | * Note that enable_shared_dpll tries to do the right thing, but | |
4544 | * get_shared_dpll unconditionally resets the pll - we need that to have | |
4545 | * the right LVDS enable sequence. */ | |
4cbe4b2b | 4546 | intel_enable_shared_dpll(crtc); |
3ad8a208 | 4547 | |
d9b6cb56 JB |
4548 | /* set transcoder timing, panel must allow it */ |
4549 | assert_panel_unlocked(dev_priv, pipe); | |
4cbe4b2b | 4550 | ironlake_pch_transcoder_set_timings(crtc, pipe); |
8db9d77b | 4551 | |
303b81e0 | 4552 | intel_fdi_normal_train(crtc); |
5e84e1a4 | 4553 | |
c98e9dcf | 4554 | /* For PCH DP, enable TRANS_DP_CTL */ |
6e266956 | 4555 | if (HAS_PCH_CPT(dev_priv) && |
2ce42273 | 4556 | intel_crtc_has_dp_encoder(crtc_state)) { |
9c4edaee | 4557 | const struct drm_display_mode *adjusted_mode = |
2ce42273 | 4558 | &crtc_state->base.adjusted_mode; |
dfd07d72 | 4559 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
f0f59a00 | 4560 | i915_reg_t reg = TRANS_DP_CTL(pipe); |
5eddb70b CW |
4561 | temp = I915_READ(reg); |
4562 | temp &= ~(TRANS_DP_PORT_SEL_MASK | | |
220cad3c EA |
4563 | TRANS_DP_SYNC_MASK | |
4564 | TRANS_DP_BPC_MASK); | |
e3ef4479 | 4565 | temp |= TRANS_DP_OUTPUT_ENABLE; |
9325c9f0 | 4566 | temp |= bpc << 9; /* same format but at 11:9 */ |
c98e9dcf | 4567 | |
9c4edaee | 4568 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
5eddb70b | 4569 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
9c4edaee | 4570 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
5eddb70b | 4571 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
c98e9dcf JB |
4572 | |
4573 | switch (intel_trans_dp_port_sel(crtc)) { | |
c48b5305 | 4574 | case PORT_B: |
5eddb70b | 4575 | temp |= TRANS_DP_PORT_SEL_B; |
c98e9dcf | 4576 | break; |
c48b5305 | 4577 | case PORT_C: |
5eddb70b | 4578 | temp |= TRANS_DP_PORT_SEL_C; |
c98e9dcf | 4579 | break; |
c48b5305 | 4580 | case PORT_D: |
5eddb70b | 4581 | temp |= TRANS_DP_PORT_SEL_D; |
c98e9dcf JB |
4582 | break; |
4583 | default: | |
e95d41e1 | 4584 | BUG(); |
32f9d658 | 4585 | } |
2c07245f | 4586 | |
5eddb70b | 4587 | I915_WRITE(reg, temp); |
6be4a607 | 4588 | } |
b52eb4dc | 4589 | |
b8a4f404 | 4590 | ironlake_enable_pch_transcoder(dev_priv, pipe); |
f67a559d JB |
4591 | } |
4592 | ||
2ce42273 | 4593 | static void lpt_pch_enable(const struct intel_crtc_state *crtc_state) |
1507e5bd | 4594 | { |
2ce42273 | 4595 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
0dcdc382 | 4596 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
2ce42273 | 4597 | enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; |
1507e5bd | 4598 | |
a2196033 | 4599 | assert_pch_transcoder_disabled(dev_priv, PIPE_A); |
1507e5bd | 4600 | |
8c52b5e8 | 4601 | lpt_program_iclkip(crtc); |
1507e5bd | 4602 | |
0540e488 | 4603 | /* Set transcoder timing. */ |
0dcdc382 | 4604 | ironlake_pch_transcoder_set_timings(crtc, PIPE_A); |
1507e5bd | 4605 | |
937bb610 | 4606 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
f67a559d JB |
4607 | } |
4608 | ||
a1520318 | 4609 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
d4270e57 | 4610 | { |
fac5e23e | 4611 | struct drm_i915_private *dev_priv = to_i915(dev); |
f0f59a00 | 4612 | i915_reg_t dslreg = PIPEDSL(pipe); |
d4270e57 JB |
4613 | u32 temp; |
4614 | ||
4615 | temp = I915_READ(dslreg); | |
4616 | udelay(500); | |
4617 | if (wait_for(I915_READ(dslreg) != temp, 5)) { | |
d4270e57 | 4618 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
84f44ce7 | 4619 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
d4270e57 JB |
4620 | } |
4621 | } | |
4622 | ||
86adf9d7 ML |
4623 | static int |
4624 | skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach, | |
d96a7d2a | 4625 | unsigned int scaler_user, int *scaler_id, |
86adf9d7 | 4626 | int src_w, int src_h, int dst_w, int dst_h) |
a1b2278e | 4627 | { |
86adf9d7 ML |
4628 | struct intel_crtc_scaler_state *scaler_state = |
4629 | &crtc_state->scaler_state; | |
4630 | struct intel_crtc *intel_crtc = | |
4631 | to_intel_crtc(crtc_state->base.crtc); | |
7f58cbb1 MK |
4632 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
4633 | const struct drm_display_mode *adjusted_mode = | |
4634 | &crtc_state->base.adjusted_mode; | |
a1b2278e | 4635 | int need_scaling; |
6156a456 | 4636 | |
d96a7d2a VS |
4637 | /* |
4638 | * Src coordinates are already rotated by 270 degrees for | |
4639 | * the 90/270 degree plane rotation cases (to match the | |
4640 | * GTT mapping), hence no need to account for rotation here. | |
4641 | */ | |
4642 | need_scaling = src_w != dst_w || src_h != dst_h; | |
a1b2278e | 4643 | |
e5c05931 SS |
4644 | if (crtc_state->ycbcr420 && scaler_user == SKL_CRTC_INDEX) |
4645 | need_scaling = true; | |
4646 | ||
7f58cbb1 MK |
4647 | /* |
4648 | * Scaling/fitting not supported in IF-ID mode in GEN9+ | |
4649 | * TODO: Interlace fetch mode doesn't support YUV420 planar formats. | |
4650 | * Once NV12 is enabled, handle it here while allocating scaler | |
4651 | * for NV12. | |
4652 | */ | |
4653 | if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable && | |
4654 | need_scaling && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { | |
4655 | DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n"); | |
4656 | return -EINVAL; | |
4657 | } | |
4658 | ||
a1b2278e CK |
4659 | /* |
4660 | * if plane is being disabled or scaler is no more required or force detach | |
4661 | * - free scaler binded to this plane/crtc | |
4662 | * - in order to do this, update crtc->scaler_usage | |
4663 | * | |
4664 | * Here scaler state in crtc_state is set free so that | |
4665 | * scaler can be assigned to other user. Actual register | |
4666 | * update to free the scaler is done in plane/panel-fit programming. | |
4667 | * For this purpose crtc/plane_state->scaler_id isn't reset here. | |
4668 | */ | |
86adf9d7 | 4669 | if (force_detach || !need_scaling) { |
a1b2278e | 4670 | if (*scaler_id >= 0) { |
86adf9d7 | 4671 | scaler_state->scaler_users &= ~(1 << scaler_user); |
a1b2278e CK |
4672 | scaler_state->scalers[*scaler_id].in_use = 0; |
4673 | ||
86adf9d7 ML |
4674 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
4675 | "Staged freeing scaler id %d scaler_users = 0x%x\n", | |
4676 | intel_crtc->pipe, scaler_user, *scaler_id, | |
a1b2278e CK |
4677 | scaler_state->scaler_users); |
4678 | *scaler_id = -1; | |
4679 | } | |
4680 | return 0; | |
4681 | } | |
4682 | ||
4683 | /* range checks */ | |
4684 | if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H || | |
4685 | dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H || | |
4686 | ||
4687 | src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H || | |
4688 | dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H) { | |
86adf9d7 | 4689 | DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u " |
a1b2278e | 4690 | "size is out of scaler range\n", |
86adf9d7 | 4691 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h); |
a1b2278e CK |
4692 | return -EINVAL; |
4693 | } | |
4694 | ||
86adf9d7 ML |
4695 | /* mark this plane as a scaler user in crtc_state */ |
4696 | scaler_state->scaler_users |= (1 << scaler_user); | |
4697 | DRM_DEBUG_KMS("scaler_user index %u.%u: " | |
4698 | "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n", | |
4699 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h, | |
4700 | scaler_state->scaler_users); | |
4701 | ||
4702 | return 0; | |
4703 | } | |
4704 | ||
4705 | /** | |
4706 | * skl_update_scaler_crtc - Stages update to scaler state for a given crtc. | |
4707 | * | |
4708 | * @state: crtc's scaler state | |
86adf9d7 ML |
4709 | * |
4710 | * Return | |
4711 | * 0 - scaler_usage updated successfully | |
4712 | * error - requested scaling cannot be supported or other error condition | |
4713 | */ | |
e435d6e5 | 4714 | int skl_update_scaler_crtc(struct intel_crtc_state *state) |
86adf9d7 | 4715 | { |
7c5f93b0 | 4716 | const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode; |
86adf9d7 | 4717 | |
e435d6e5 | 4718 | return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX, |
d96a7d2a | 4719 | &state->scaler_state.scaler_id, |
86adf9d7 | 4720 | state->pipe_src_w, state->pipe_src_h, |
aad941d5 | 4721 | adjusted_mode->crtc_hdisplay, adjusted_mode->crtc_vdisplay); |
86adf9d7 ML |
4722 | } |
4723 | ||
4724 | /** | |
4725 | * skl_update_scaler_plane - Stages update to scaler state for a given plane. | |
4726 | * | |
4727 | * @state: crtc's scaler state | |
86adf9d7 ML |
4728 | * @plane_state: atomic plane state to update |
4729 | * | |
4730 | * Return | |
4731 | * 0 - scaler_usage updated successfully | |
4732 | * error - requested scaling cannot be supported or other error condition | |
4733 | */ | |
da20eabd ML |
4734 | static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state, |
4735 | struct intel_plane_state *plane_state) | |
86adf9d7 ML |
4736 | { |
4737 | ||
da20eabd ML |
4738 | struct intel_plane *intel_plane = |
4739 | to_intel_plane(plane_state->base.plane); | |
86adf9d7 ML |
4740 | struct drm_framebuffer *fb = plane_state->base.fb; |
4741 | int ret; | |
4742 | ||
936e71e3 | 4743 | bool force_detach = !fb || !plane_state->base.visible; |
86adf9d7 | 4744 | |
86adf9d7 ML |
4745 | ret = skl_update_scaler(crtc_state, force_detach, |
4746 | drm_plane_index(&intel_plane->base), | |
4747 | &plane_state->scaler_id, | |
936e71e3 VS |
4748 | drm_rect_width(&plane_state->base.src) >> 16, |
4749 | drm_rect_height(&plane_state->base.src) >> 16, | |
4750 | drm_rect_width(&plane_state->base.dst), | |
4751 | drm_rect_height(&plane_state->base.dst)); | |
86adf9d7 ML |
4752 | |
4753 | if (ret || plane_state->scaler_id < 0) | |
4754 | return ret; | |
4755 | ||
a1b2278e | 4756 | /* check colorkey */ |
818ed961 | 4757 | if (plane_state->ckey.flags != I915_SET_COLORKEY_NONE) { |
72660ce0 VS |
4758 | DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed", |
4759 | intel_plane->base.base.id, | |
4760 | intel_plane->base.name); | |
a1b2278e CK |
4761 | return -EINVAL; |
4762 | } | |
4763 | ||
4764 | /* Check src format */ | |
438b74a5 | 4765 | switch (fb->format->format) { |
86adf9d7 ML |
4766 | case DRM_FORMAT_RGB565: |
4767 | case DRM_FORMAT_XBGR8888: | |
4768 | case DRM_FORMAT_XRGB8888: | |
4769 | case DRM_FORMAT_ABGR8888: | |
4770 | case DRM_FORMAT_ARGB8888: | |
4771 | case DRM_FORMAT_XRGB2101010: | |
4772 | case DRM_FORMAT_XBGR2101010: | |
4773 | case DRM_FORMAT_YUYV: | |
4774 | case DRM_FORMAT_YVYU: | |
4775 | case DRM_FORMAT_UYVY: | |
4776 | case DRM_FORMAT_VYUY: | |
4777 | break; | |
4778 | default: | |
72660ce0 VS |
4779 | DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n", |
4780 | intel_plane->base.base.id, intel_plane->base.name, | |
438b74a5 | 4781 | fb->base.id, fb->format->format); |
86adf9d7 | 4782 | return -EINVAL; |
a1b2278e CK |
4783 | } |
4784 | ||
a1b2278e CK |
4785 | return 0; |
4786 | } | |
4787 | ||
e435d6e5 ML |
4788 | static void skylake_scaler_disable(struct intel_crtc *crtc) |
4789 | { | |
4790 | int i; | |
4791 | ||
4792 | for (i = 0; i < crtc->num_scalers; i++) | |
4793 | skl_detach_scaler(crtc, i); | |
4794 | } | |
4795 | ||
4796 | static void skylake_pfit_enable(struct intel_crtc *crtc) | |
bd2e244f JB |
4797 | { |
4798 | struct drm_device *dev = crtc->base.dev; | |
fac5e23e | 4799 | struct drm_i915_private *dev_priv = to_i915(dev); |
bd2e244f | 4800 | int pipe = crtc->pipe; |
a1b2278e CK |
4801 | struct intel_crtc_scaler_state *scaler_state = |
4802 | &crtc->config->scaler_state; | |
4803 | ||
6e3c9717 | 4804 | if (crtc->config->pch_pfit.enabled) { |
a1b2278e CK |
4805 | int id; |
4806 | ||
c3f8ad57 | 4807 | if (WARN_ON(crtc->config->scaler_state.scaler_id < 0)) |
a1b2278e | 4808 | return; |
a1b2278e CK |
4809 | |
4810 | id = scaler_state->scaler_id; | |
4811 | I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN | | |
4812 | PS_FILTER_MEDIUM | scaler_state->scalers[id].mode); | |
4813 | I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc->config->pch_pfit.pos); | |
4814 | I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc->config->pch_pfit.size); | |
bd2e244f JB |
4815 | } |
4816 | } | |
4817 | ||
b074cec8 JB |
4818 | static void ironlake_pfit_enable(struct intel_crtc *crtc) |
4819 | { | |
4820 | struct drm_device *dev = crtc->base.dev; | |
fac5e23e | 4821 | struct drm_i915_private *dev_priv = to_i915(dev); |
b074cec8 JB |
4822 | int pipe = crtc->pipe; |
4823 | ||
6e3c9717 | 4824 | if (crtc->config->pch_pfit.enabled) { |
b074cec8 JB |
4825 | /* Force use of hard-coded filter coefficients |
4826 | * as some pre-programmed values are broken, | |
4827 | * e.g. x201. | |
4828 | */ | |
fd6b8f43 | 4829 | if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv)) |
b074cec8 JB |
4830 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | |
4831 | PF_PIPE_SEL_IVB(pipe)); | |
4832 | else | |
4833 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3); | |
6e3c9717 ACO |
4834 | I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos); |
4835 | I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size); | |
d4270e57 JB |
4836 | } |
4837 | } | |
4838 | ||
20bc8673 | 4839 | void hsw_enable_ips(struct intel_crtc *crtc) |
d77e4531 | 4840 | { |
cea165c3 | 4841 | struct drm_device *dev = crtc->base.dev; |
fac5e23e | 4842 | struct drm_i915_private *dev_priv = to_i915(dev); |
d77e4531 | 4843 | |
6e3c9717 | 4844 | if (!crtc->config->ips_enabled) |
d77e4531 PZ |
4845 | return; |
4846 | ||
307e4498 ML |
4847 | /* |
4848 | * We can only enable IPS after we enable a plane and wait for a vblank | |
4849 | * This function is called from post_plane_update, which is run after | |
4850 | * a vblank wait. | |
4851 | */ | |
cea165c3 | 4852 | |
d87ce764 VS |
4853 | assert_plane_enabled(to_intel_plane(crtc->base.primary)); |
4854 | ||
8652744b | 4855 | if (IS_BROADWELL(dev_priv)) { |
9f817501 | 4856 | mutex_lock(&dev_priv->pcu_lock); |
61843f0e VS |
4857 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, |
4858 | IPS_ENABLE | IPS_PCODE_CONTROL)); | |
9f817501 | 4859 | mutex_unlock(&dev_priv->pcu_lock); |
2a114cc1 BW |
4860 | /* Quoting Art Runyan: "its not safe to expect any particular |
4861 | * value in IPS_CTL bit 31 after enabling IPS through the | |
e59150dc JB |
4862 | * mailbox." Moreover, the mailbox may return a bogus state, |
4863 | * so we need to just enable it and continue on. | |
2a114cc1 BW |
4864 | */ |
4865 | } else { | |
4866 | I915_WRITE(IPS_CTL, IPS_ENABLE); | |
4867 | /* The bit only becomes 1 in the next vblank, so this wait here | |
4868 | * is essentially intel_wait_for_vblank. If we don't have this | |
4869 | * and don't wait for vblanks until the end of crtc_enable, then | |
4870 | * the HW state readout code will complain that the expected | |
4871 | * IPS_CTL value is not the one we read. */ | |
2ec9ba3c CW |
4872 | if (intel_wait_for_register(dev_priv, |
4873 | IPS_CTL, IPS_ENABLE, IPS_ENABLE, | |
4874 | 50)) | |
2a114cc1 BW |
4875 | DRM_ERROR("Timed out waiting for IPS enable\n"); |
4876 | } | |
d77e4531 PZ |
4877 | } |
4878 | ||
20bc8673 | 4879 | void hsw_disable_ips(struct intel_crtc *crtc) |
d77e4531 PZ |
4880 | { |
4881 | struct drm_device *dev = crtc->base.dev; | |
fac5e23e | 4882 | struct drm_i915_private *dev_priv = to_i915(dev); |
d77e4531 | 4883 | |
6e3c9717 | 4884 | if (!crtc->config->ips_enabled) |
d77e4531 PZ |
4885 | return; |
4886 | ||
d87ce764 VS |
4887 | assert_plane_enabled(to_intel_plane(crtc->base.primary)); |
4888 | ||
8652744b | 4889 | if (IS_BROADWELL(dev_priv)) { |
9f817501 | 4890 | mutex_lock(&dev_priv->pcu_lock); |
2a114cc1 | 4891 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); |
9f817501 | 4892 | mutex_unlock(&dev_priv->pcu_lock); |
37937ddb ID |
4893 | /* |
4894 | * Wait for PCODE to finish disabling IPS. The BSpec specified | |
4895 | * 42ms timeout value leads to occasional timeouts so use 100ms | |
4896 | * instead. | |
4897 | */ | |
b85c1ecf CW |
4898 | if (intel_wait_for_register(dev_priv, |
4899 | IPS_CTL, IPS_ENABLE, 0, | |
37937ddb | 4900 | 100)) |
23d0b130 | 4901 | DRM_ERROR("Timed out waiting for IPS disable\n"); |
e59150dc | 4902 | } else { |
2a114cc1 | 4903 | I915_WRITE(IPS_CTL, 0); |
e59150dc JB |
4904 | POSTING_READ(IPS_CTL); |
4905 | } | |
d77e4531 PZ |
4906 | |
4907 | /* We need to wait for a vblank before we can disable the plane. */ | |
0f0f74bc | 4908 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
d77e4531 PZ |
4909 | } |
4910 | ||
7cac945f | 4911 | static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc) |
d3eedb1a | 4912 | { |
7cac945f | 4913 | if (intel_crtc->overlay) { |
d3eedb1a | 4914 | struct drm_device *dev = intel_crtc->base.dev; |
d3eedb1a VS |
4915 | |
4916 | mutex_lock(&dev->struct_mutex); | |
d3eedb1a | 4917 | (void) intel_overlay_switch_off(intel_crtc->overlay); |
d3eedb1a VS |
4918 | mutex_unlock(&dev->struct_mutex); |
4919 | } | |
4920 | ||
4921 | /* Let userspace switch the overlay on again. In most cases userspace | |
4922 | * has to recompute where to put it anyway. | |
4923 | */ | |
4924 | } | |
4925 | ||
87d4300a ML |
4926 | /** |
4927 | * intel_post_enable_primary - Perform operations after enabling primary plane | |
4928 | * @crtc: the CRTC whose primary plane was just enabled | |
4929 | * | |
4930 | * Performs potentially sleeping operations that must be done after the primary | |
4931 | * plane is enabled, such as updating FBC and IPS. Note that this may be | |
4932 | * called due to an explicit primary plane update, or due to an implicit | |
4933 | * re-enable that is caused when a sprite plane is updated to no longer | |
4934 | * completely hide the primary plane. | |
4935 | */ | |
4936 | static void | |
4937 | intel_post_enable_primary(struct drm_crtc *crtc) | |
a5c4d7bc VS |
4938 | { |
4939 | struct drm_device *dev = crtc->dev; | |
fac5e23e | 4940 | struct drm_i915_private *dev_priv = to_i915(dev); |
a5c4d7bc VS |
4941 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
4942 | int pipe = intel_crtc->pipe; | |
a5c4d7bc | 4943 | |
87d4300a ML |
4944 | /* |
4945 | * FIXME IPS should be fine as long as one plane is | |
4946 | * enabled, but in practice it seems to have problems | |
4947 | * when going from primary only to sprite only and vice | |
4948 | * versa. | |
4949 | */ | |
a5c4d7bc VS |
4950 | hsw_enable_ips(intel_crtc); |
4951 | ||
f99d7069 | 4952 | /* |
87d4300a ML |
4953 | * Gen2 reports pipe underruns whenever all planes are disabled. |
4954 | * So don't enable underrun reporting before at least some planes | |
4955 | * are enabled. | |
4956 | * FIXME: Need to fix the logic to work when we turn off all planes | |
4957 | * but leave the pipe running. | |
f99d7069 | 4958 | */ |
5db94019 | 4959 | if (IS_GEN2(dev_priv)) |
87d4300a ML |
4960 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
4961 | ||
aca7b684 VS |
4962 | /* Underruns don't always raise interrupts, so check manually. */ |
4963 | intel_check_cpu_fifo_underruns(dev_priv); | |
4964 | intel_check_pch_fifo_underruns(dev_priv); | |
a5c4d7bc VS |
4965 | } |
4966 | ||
2622a081 | 4967 | /* FIXME move all this to pre_plane_update() with proper state tracking */ |
87d4300a ML |
4968 | static void |
4969 | intel_pre_disable_primary(struct drm_crtc *crtc) | |
a5c4d7bc VS |
4970 | { |
4971 | struct drm_device *dev = crtc->dev; | |
fac5e23e | 4972 | struct drm_i915_private *dev_priv = to_i915(dev); |
a5c4d7bc VS |
4973 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
4974 | int pipe = intel_crtc->pipe; | |
a5c4d7bc | 4975 | |
87d4300a ML |
4976 | /* |
4977 | * Gen2 reports pipe underruns whenever all planes are disabled. | |
4978 | * So diasble underrun reporting before all the planes get disabled. | |
4979 | * FIXME: Need to fix the logic to work when we turn off all planes | |
4980 | * but leave the pipe running. | |
4981 | */ | |
5db94019 | 4982 | if (IS_GEN2(dev_priv)) |
87d4300a | 4983 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
a5c4d7bc | 4984 | |
2622a081 VS |
4985 | /* |
4986 | * FIXME IPS should be fine as long as one plane is | |
4987 | * enabled, but in practice it seems to have problems | |
4988 | * when going from primary only to sprite only and vice | |
4989 | * versa. | |
4990 | */ | |
4991 | hsw_disable_ips(intel_crtc); | |
4992 | } | |
4993 | ||
4994 | /* FIXME get rid of this and use pre_plane_update */ | |
4995 | static void | |
4996 | intel_pre_disable_primary_noatomic(struct drm_crtc *crtc) | |
4997 | { | |
4998 | struct drm_device *dev = crtc->dev; | |
fac5e23e | 4999 | struct drm_i915_private *dev_priv = to_i915(dev); |
2622a081 VS |
5000 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
5001 | int pipe = intel_crtc->pipe; | |
5002 | ||
5003 | intel_pre_disable_primary(crtc); | |
5004 | ||
87d4300a ML |
5005 | /* |
5006 | * Vblank time updates from the shadow to live plane control register | |
5007 | * are blocked if the memory self-refresh mode is active at that | |
5008 | * moment. So to make sure the plane gets truly disabled, disable | |
5009 | * first the self-refresh mode. The self-refresh enable bit in turn | |
5010 | * will be checked/applied by the HW only at the next frame start | |
5011 | * event which is after the vblank start event, so we need to have a | |
5012 | * wait-for-vblank between disabling the plane and the pipe. | |
5013 | */ | |
11a85d6a VS |
5014 | if (HAS_GMCH_DISPLAY(dev_priv) && |
5015 | intel_set_memory_cxsr(dev_priv, false)) | |
0f0f74bc | 5016 | intel_wait_for_vblank(dev_priv, pipe); |
87d4300a ML |
5017 | } |
5018 | ||
5a21b665 DV |
5019 | static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state) |
5020 | { | |
5021 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); | |
5022 | struct drm_atomic_state *old_state = old_crtc_state->base.state; | |
5023 | struct intel_crtc_state *pipe_config = | |
f9a8c149 VS |
5024 | intel_atomic_get_new_crtc_state(to_intel_atomic_state(old_state), |
5025 | crtc); | |
5a21b665 DV |
5026 | struct drm_plane *primary = crtc->base.primary; |
5027 | struct drm_plane_state *old_pri_state = | |
5028 | drm_atomic_get_existing_plane_state(old_state, primary); | |
5029 | ||
5748b6a1 | 5030 | intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits); |
5a21b665 | 5031 | |
5a21b665 | 5032 | if (pipe_config->update_wm_post && pipe_config->base.active) |
432081bc | 5033 | intel_update_watermarks(crtc); |
5a21b665 DV |
5034 | |
5035 | if (old_pri_state) { | |
5036 | struct intel_plane_state *primary_state = | |
f9a8c149 VS |
5037 | intel_atomic_get_new_plane_state(to_intel_atomic_state(old_state), |
5038 | to_intel_plane(primary)); | |
5a21b665 DV |
5039 | struct intel_plane_state *old_primary_state = |
5040 | to_intel_plane_state(old_pri_state); | |
5041 | ||
5042 | intel_fbc_post_update(crtc); | |
5043 | ||
936e71e3 | 5044 | if (primary_state->base.visible && |
5a21b665 | 5045 | (needs_modeset(&pipe_config->base) || |
936e71e3 | 5046 | !old_primary_state->base.visible)) |
5a21b665 DV |
5047 | intel_post_enable_primary(&crtc->base); |
5048 | } | |
5049 | } | |
5050 | ||
aa5e9b47 ML |
5051 | static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state, |
5052 | struct intel_crtc_state *pipe_config) | |
ac21b225 | 5053 | { |
5c74cd73 | 5054 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
ac21b225 | 5055 | struct drm_device *dev = crtc->base.dev; |
fac5e23e | 5056 | struct drm_i915_private *dev_priv = to_i915(dev); |
5c74cd73 ML |
5057 | struct drm_atomic_state *old_state = old_crtc_state->base.state; |
5058 | struct drm_plane *primary = crtc->base.primary; | |
5059 | struct drm_plane_state *old_pri_state = | |
5060 | drm_atomic_get_existing_plane_state(old_state, primary); | |
5061 | bool modeset = needs_modeset(&pipe_config->base); | |
ccf010fb ML |
5062 | struct intel_atomic_state *old_intel_state = |
5063 | to_intel_atomic_state(old_state); | |
ac21b225 | 5064 | |
5c74cd73 ML |
5065 | if (old_pri_state) { |
5066 | struct intel_plane_state *primary_state = | |
f9a8c149 VS |
5067 | intel_atomic_get_new_plane_state(old_intel_state, |
5068 | to_intel_plane(primary)); | |
5c74cd73 ML |
5069 | struct intel_plane_state *old_primary_state = |
5070 | to_intel_plane_state(old_pri_state); | |
5071 | ||
faf68d92 | 5072 | intel_fbc_pre_update(crtc, pipe_config, primary_state); |
31ae71fc | 5073 | |
936e71e3 VS |
5074 | if (old_primary_state->base.visible && |
5075 | (modeset || !primary_state->base.visible)) | |
5c74cd73 ML |
5076 | intel_pre_disable_primary(&crtc->base); |
5077 | } | |
852eb00d | 5078 | |
5eeb798b VS |
5079 | /* |
5080 | * Vblank time updates from the shadow to live plane control register | |
5081 | * are blocked if the memory self-refresh mode is active at that | |
5082 | * moment. So to make sure the plane gets truly disabled, disable | |
5083 | * first the self-refresh mode. The self-refresh enable bit in turn | |
5084 | * will be checked/applied by the HW only at the next frame start | |
5085 | * event which is after the vblank start event, so we need to have a | |
5086 | * wait-for-vblank between disabling the plane and the pipe. | |
5087 | */ | |
5088 | if (HAS_GMCH_DISPLAY(dev_priv) && old_crtc_state->base.active && | |
5089 | pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false)) | |
5090 | intel_wait_for_vblank(dev_priv, crtc->pipe); | |
92826fcd | 5091 | |
ed4a6a7c MR |
5092 | /* |
5093 | * IVB workaround: must disable low power watermarks for at least | |
5094 | * one frame before enabling scaling. LP watermarks can be re-enabled | |
5095 | * when scaling is disabled. | |
5096 | * | |
5097 | * WaCxSRDisabledForSpriteScaling:ivb | |
5098 | */ | |
ddd2b792 | 5099 | if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev)) |
0f0f74bc | 5100 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
ed4a6a7c MR |
5101 | |
5102 | /* | |
5103 | * If we're doing a modeset, we're done. No need to do any pre-vblank | |
5104 | * watermark programming here. | |
5105 | */ | |
5106 | if (needs_modeset(&pipe_config->base)) | |
5107 | return; | |
5108 | ||
5109 | /* | |
5110 | * For platforms that support atomic watermarks, program the | |
5111 | * 'intermediate' watermarks immediately. On pre-gen9 platforms, these | |
5112 | * will be the intermediate values that are safe for both pre- and | |
5113 | * post- vblank; when vblank happens, the 'active' values will be set | |
5114 | * to the final 'target' values and we'll do this again to get the | |
5115 | * optimal watermarks. For gen9+ platforms, the values we program here | |
5116 | * will be the final target values which will get automatically latched | |
5117 | * at vblank time; no further programming will be necessary. | |
5118 | * | |
5119 | * If a platform hasn't been transitioned to atomic watermarks yet, | |
5120 | * we'll continue to update watermarks the old way, if flags tell | |
5121 | * us to. | |
5122 | */ | |
5123 | if (dev_priv->display.initial_watermarks != NULL) | |
ccf010fb ML |
5124 | dev_priv->display.initial_watermarks(old_intel_state, |
5125 | pipe_config); | |
caed361d | 5126 | else if (pipe_config->update_wm_pre) |
432081bc | 5127 | intel_update_watermarks(crtc); |
ac21b225 ML |
5128 | } |
5129 | ||
d032ffa0 | 5130 | static void intel_crtc_disable_planes(struct drm_crtc *crtc, unsigned plane_mask) |
87d4300a ML |
5131 | { |
5132 | struct drm_device *dev = crtc->dev; | |
5133 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
d032ffa0 | 5134 | struct drm_plane *p; |
87d4300a ML |
5135 | int pipe = intel_crtc->pipe; |
5136 | ||
7cac945f | 5137 | intel_crtc_dpms_overlay_disable(intel_crtc); |
27321ae8 | 5138 | |
d032ffa0 | 5139 | drm_for_each_plane_mask(p, dev, plane_mask) |
282dbf9b | 5140 | to_intel_plane(p)->disable_plane(to_intel_plane(p), intel_crtc); |
f98551ae | 5141 | |
f99d7069 DV |
5142 | /* |
5143 | * FIXME: Once we grow proper nuclear flip support out of this we need | |
5144 | * to compute the mask of flip planes precisely. For the time being | |
5145 | * consider this a flip to a NULL plane. | |
5146 | */ | |
5748b6a1 | 5147 | intel_frontbuffer_flip(to_i915(dev), INTEL_FRONTBUFFER_ALL_MASK(pipe)); |
a5c4d7bc VS |
5148 | } |
5149 | ||
fb1c98b1 | 5150 | static void intel_encoders_pre_pll_enable(struct drm_crtc *crtc, |
fd6bbda9 | 5151 | struct intel_crtc_state *crtc_state, |
fb1c98b1 ML |
5152 | struct drm_atomic_state *old_state) |
5153 | { | |
aa5e9b47 | 5154 | struct drm_connector_state *conn_state; |
fb1c98b1 ML |
5155 | struct drm_connector *conn; |
5156 | int i; | |
5157 | ||
aa5e9b47 | 5158 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
fb1c98b1 ML |
5159 | struct intel_encoder *encoder = |
5160 | to_intel_encoder(conn_state->best_encoder); | |
5161 | ||
5162 | if (conn_state->crtc != crtc) | |
5163 | continue; | |
5164 | ||
5165 | if (encoder->pre_pll_enable) | |
fd6bbda9 | 5166 | encoder->pre_pll_enable(encoder, crtc_state, conn_state); |
fb1c98b1 ML |
5167 | } |
5168 | } | |
5169 | ||
5170 | static void intel_encoders_pre_enable(struct drm_crtc *crtc, | |
fd6bbda9 | 5171 | struct intel_crtc_state *crtc_state, |
fb1c98b1 ML |
5172 | struct drm_atomic_state *old_state) |
5173 | { | |
aa5e9b47 | 5174 | struct drm_connector_state *conn_state; |
fb1c98b1 ML |
5175 | struct drm_connector *conn; |
5176 | int i; | |
5177 | ||
aa5e9b47 | 5178 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
fb1c98b1 ML |
5179 | struct intel_encoder *encoder = |
5180 | to_intel_encoder(conn_state->best_encoder); | |
5181 | ||
5182 | if (conn_state->crtc != crtc) | |
5183 | continue; | |
5184 | ||
5185 | if (encoder->pre_enable) | |
fd6bbda9 | 5186 | encoder->pre_enable(encoder, crtc_state, conn_state); |
fb1c98b1 ML |
5187 | } |
5188 | } | |
5189 | ||
5190 | static void intel_encoders_enable(struct drm_crtc *crtc, | |
fd6bbda9 | 5191 | struct intel_crtc_state *crtc_state, |
fb1c98b1 ML |
5192 | struct drm_atomic_state *old_state) |
5193 | { | |
aa5e9b47 | 5194 | struct drm_connector_state *conn_state; |
fb1c98b1 ML |
5195 | struct drm_connector *conn; |
5196 | int i; | |
5197 | ||
aa5e9b47 | 5198 | for_each_new_connector_in_state(old_state, conn, conn_state, i) { |
fb1c98b1 ML |
5199 | struct intel_encoder *encoder = |
5200 | to_intel_encoder(conn_state->best_encoder); | |
5201 | ||
5202 | if (conn_state->crtc != crtc) | |
5203 | continue; | |
5204 | ||
fd6bbda9 | 5205 | encoder->enable(encoder, crtc_state, conn_state); |
fb1c98b1 ML |
5206 | intel_opregion_notify_encoder(encoder, true); |
5207 | } | |
5208 | } | |
5209 | ||
5210 | static void intel_encoders_disable(struct drm_crtc *crtc, | |
fd6bbda9 | 5211 | struct intel_crtc_state *old_crtc_state, |
fb1c98b1 ML |
5212 | struct drm_atomic_state *old_state) |
5213 | { | |
5214 | struct drm_connector_state *old_conn_state; | |
5215 | struct drm_connector *conn; | |
5216 | int i; | |
5217 | ||
aa5e9b47 | 5218 | for_each_old_connector_in_state(old_state, conn, old_conn_state, i) { |
fb1c98b1 ML |
5219 | struct intel_encoder *encoder = |
5220 | to_intel_encoder(old_conn_state->best_encoder); | |
5221 | ||
5222 | if (old_conn_state->crtc != crtc) | |
5223 | continue; | |
5224 | ||
5225 | intel_opregion_notify_encoder(encoder, false); | |
fd6bbda9 | 5226 | encoder->disable(encoder, old_crtc_state, old_conn_state); |
fb1c98b1 ML |
5227 | } |
5228 | } | |
5229 | ||
5230 | static void intel_encoders_post_disable(struct drm_crtc *crtc, | |
fd6bbda9 | 5231 | struct intel_crtc_state *old_crtc_state, |
fb1c98b1 ML |
5232 | struct drm_atomic_state *old_state) |
5233 | { | |
5234 | struct drm_connector_state *old_conn_state; | |
5235 | struct drm_connector *conn; | |
5236 | int i; | |
5237 | ||
aa5e9b47 | 5238 | for_each_old_connector_in_state(old_state, conn, old_conn_state, i) { |
fb1c98b1 ML |
5239 | struct intel_encoder *encoder = |
5240 | to_intel_encoder(old_conn_state->best_encoder); | |
5241 | ||
5242 | if (old_conn_state->crtc != crtc) | |
5243 | continue; | |
5244 | ||
5245 | if (encoder->post_disable) | |
fd6bbda9 | 5246 | encoder->post_disable(encoder, old_crtc_state, old_conn_state); |
fb1c98b1 ML |
5247 | } |
5248 | } | |
5249 | ||
5250 | static void intel_encoders_post_pll_disable(struct drm_crtc *crtc, | |
fd6bbda9 | 5251 | struct intel_crtc_state *old_crtc_state, |
fb1c98b1 ML |
5252 | struct drm_atomic_state *old_state) |
5253 | { | |
5254 | struct drm_connector_state *old_conn_state; | |
5255 | struct drm_connector *conn; | |
5256 | int i; | |
5257 | ||
aa5e9b47 | 5258 | for_each_old_connector_in_state(old_state, conn, old_conn_state, i) { |
fb1c98b1 ML |
5259 | struct intel_encoder *encoder = |
5260 | to_intel_encoder(old_conn_state->best_encoder); | |
5261 | ||
5262 | if (old_conn_state->crtc != crtc) | |
5263 | continue; | |
5264 | ||
5265 | if (encoder->post_pll_disable) | |
fd6bbda9 | 5266 | encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state); |
fb1c98b1 ML |
5267 | } |
5268 | } | |
5269 | ||
4a806558 ML |
5270 | static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config, |
5271 | struct drm_atomic_state *old_state) | |
f67a559d | 5272 | { |
4a806558 | 5273 | struct drm_crtc *crtc = pipe_config->base.crtc; |
f67a559d | 5274 | struct drm_device *dev = crtc->dev; |
fac5e23e | 5275 | struct drm_i915_private *dev_priv = to_i915(dev); |
f67a559d JB |
5276 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
5277 | int pipe = intel_crtc->pipe; | |
ccf010fb ML |
5278 | struct intel_atomic_state *old_intel_state = |
5279 | to_intel_atomic_state(old_state); | |
f67a559d | 5280 | |
53d9f4e9 | 5281 | if (WARN_ON(intel_crtc->active)) |
f67a559d JB |
5282 | return; |
5283 | ||
b2c0593a VS |
5284 | /* |
5285 | * Sometimes spurious CPU pipe underruns happen during FDI | |
5286 | * training, at least with VGA+HDMI cloning. Suppress them. | |
5287 | * | |
5288 | * On ILK we get an occasional spurious CPU pipe underruns | |
5289 | * between eDP port A enable and vdd enable. Also PCH port | |
5290 | * enable seems to result in the occasional CPU pipe underrun. | |
5291 | * | |
5292 | * Spurious PCH underruns also occur during PCH enabling. | |
5293 | */ | |
5294 | if (intel_crtc->config->has_pch_encoder || IS_GEN5(dev_priv)) | |
5295 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
81b088ca VS |
5296 | if (intel_crtc->config->has_pch_encoder) |
5297 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); | |
5298 | ||
6e3c9717 | 5299 | if (intel_crtc->config->has_pch_encoder) |
b14b1055 DV |
5300 | intel_prepare_shared_dpll(intel_crtc); |
5301 | ||
37a5650b | 5302 | if (intel_crtc_has_dp_encoder(intel_crtc->config)) |
fe3cd48d | 5303 | intel_dp_set_m_n(intel_crtc, M1_N1); |
29407aab DV |
5304 | |
5305 | intel_set_pipe_timings(intel_crtc); | |
bc58be60 | 5306 | intel_set_pipe_src_size(intel_crtc); |
29407aab | 5307 | |
6e3c9717 | 5308 | if (intel_crtc->config->has_pch_encoder) { |
29407aab | 5309 | intel_cpu_transcoder_set_m_n(intel_crtc, |
6e3c9717 | 5310 | &intel_crtc->config->fdi_m_n, NULL); |
29407aab DV |
5311 | } |
5312 | ||
5313 | ironlake_set_pipeconf(crtc); | |
5314 | ||
f67a559d | 5315 | intel_crtc->active = true; |
8664281b | 5316 | |
fd6bbda9 | 5317 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
f67a559d | 5318 | |
6e3c9717 | 5319 | if (intel_crtc->config->has_pch_encoder) { |
fff367c7 DV |
5320 | /* Note: FDI PLL enabling _must_ be done before we enable the |
5321 | * cpu pipes, hence this is separate from all the other fdi/pch | |
5322 | * enabling. */ | |
88cefb6c | 5323 | ironlake_fdi_pll_enable(intel_crtc); |
46b6f814 DV |
5324 | } else { |
5325 | assert_fdi_tx_disabled(dev_priv, pipe); | |
5326 | assert_fdi_rx_disabled(dev_priv, pipe); | |
5327 | } | |
f67a559d | 5328 | |
b074cec8 | 5329 | ironlake_pfit_enable(intel_crtc); |
f67a559d | 5330 | |
9c54c0dd JB |
5331 | /* |
5332 | * On ILK+ LUT must be loaded before the pipe is running but with | |
5333 | * clocks enabled | |
5334 | */ | |
b95c5321 | 5335 | intel_color_load_luts(&pipe_config->base); |
9c54c0dd | 5336 | |
1d5bf5d9 | 5337 | if (dev_priv->display.initial_watermarks != NULL) |
ccf010fb | 5338 | dev_priv->display.initial_watermarks(old_intel_state, intel_crtc->config); |
e1fdc473 | 5339 | intel_enable_pipe(intel_crtc); |
f67a559d | 5340 | |
6e3c9717 | 5341 | if (intel_crtc->config->has_pch_encoder) |
2ce42273 | 5342 | ironlake_pch_enable(pipe_config); |
c98e9dcf | 5343 | |
f9b61ff6 DV |
5344 | assert_vblank_disabled(crtc); |
5345 | drm_crtc_vblank_on(crtc); | |
5346 | ||
fd6bbda9 | 5347 | intel_encoders_enable(crtc, pipe_config, old_state); |
61b77ddd | 5348 | |
6e266956 | 5349 | if (HAS_PCH_CPT(dev_priv)) |
a1520318 | 5350 | cpt_verify_modeset(dev, intel_crtc->pipe); |
37ca8d4c VS |
5351 | |
5352 | /* Must wait for vblank to avoid spurious PCH FIFO underruns */ | |
5353 | if (intel_crtc->config->has_pch_encoder) | |
0f0f74bc | 5354 | intel_wait_for_vblank(dev_priv, pipe); |
b2c0593a | 5355 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
37ca8d4c | 5356 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
6be4a607 JB |
5357 | } |
5358 | ||
42db64ef PZ |
5359 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
5360 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) | |
5361 | { | |
50a0bc90 | 5362 | return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A; |
42db64ef PZ |
5363 | } |
5364 | ||
ed69cd40 ID |
5365 | static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv, |
5366 | enum pipe pipe, bool apply) | |
5367 | { | |
5368 | u32 val = I915_READ(CLKGATE_DIS_PSL(pipe)); | |
5369 | u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS; | |
5370 | ||
5371 | if (apply) | |
5372 | val |= mask; | |
5373 | else | |
5374 | val &= ~mask; | |
5375 | ||
5376 | I915_WRITE(CLKGATE_DIS_PSL(pipe), val); | |
5377 | } | |
5378 | ||
4a806558 ML |
5379 | static void haswell_crtc_enable(struct intel_crtc_state *pipe_config, |
5380 | struct drm_atomic_state *old_state) | |
4f771f10 | 5381 | { |
4a806558 | 5382 | struct drm_crtc *crtc = pipe_config->base.crtc; |
6315b5d3 | 5383 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
4f771f10 | 5384 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
99d736a2 | 5385 | int pipe = intel_crtc->pipe, hsw_workaround_pipe; |
4d1de975 | 5386 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
ccf010fb ML |
5387 | struct intel_atomic_state *old_intel_state = |
5388 | to_intel_atomic_state(old_state); | |
ed69cd40 | 5389 | bool psl_clkgate_wa; |
4f771f10 | 5390 | |
53d9f4e9 | 5391 | if (WARN_ON(intel_crtc->active)) |
4f771f10 PZ |
5392 | return; |
5393 | ||
fd6bbda9 | 5394 | intel_encoders_pre_pll_enable(crtc, pipe_config, old_state); |
95a7a2ae | 5395 | |
8106ddbd | 5396 | if (intel_crtc->config->shared_dpll) |
df8ad70c DV |
5397 | intel_enable_shared_dpll(intel_crtc); |
5398 | ||
37a5650b | 5399 | if (intel_crtc_has_dp_encoder(intel_crtc->config)) |
fe3cd48d | 5400 | intel_dp_set_m_n(intel_crtc, M1_N1); |
229fca97 | 5401 | |
d7edc4e5 | 5402 | if (!transcoder_is_dsi(cpu_transcoder)) |
4d1de975 JN |
5403 | intel_set_pipe_timings(intel_crtc); |
5404 | ||
bc58be60 | 5405 | intel_set_pipe_src_size(intel_crtc); |
229fca97 | 5406 | |
4d1de975 JN |
5407 | if (cpu_transcoder != TRANSCODER_EDP && |
5408 | !transcoder_is_dsi(cpu_transcoder)) { | |
5409 | I915_WRITE(PIPE_MULT(cpu_transcoder), | |
6e3c9717 | 5410 | intel_crtc->config->pixel_multiplier - 1); |
ebb69c95 CT |
5411 | } |
5412 | ||
6e3c9717 | 5413 | if (intel_crtc->config->has_pch_encoder) { |
229fca97 | 5414 | intel_cpu_transcoder_set_m_n(intel_crtc, |
6e3c9717 | 5415 | &intel_crtc->config->fdi_m_n, NULL); |
229fca97 DV |
5416 | } |
5417 | ||
d7edc4e5 | 5418 | if (!transcoder_is_dsi(cpu_transcoder)) |
4d1de975 JN |
5419 | haswell_set_pipeconf(crtc); |
5420 | ||
391bf048 | 5421 | haswell_set_pipemisc(crtc); |
229fca97 | 5422 | |
b95c5321 | 5423 | intel_color_set_csc(&pipe_config->base); |
229fca97 | 5424 | |
4f771f10 | 5425 | intel_crtc->active = true; |
8664281b | 5426 | |
fd6bbda9 | 5427 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
4f771f10 | 5428 | |
d7edc4e5 | 5429 | if (!transcoder_is_dsi(cpu_transcoder)) |
3dc38eea | 5430 | intel_ddi_enable_pipe_clock(pipe_config); |
4f771f10 | 5431 | |
ed69cd40 ID |
5432 | /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */ |
5433 | psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) && | |
5434 | intel_crtc->config->pch_pfit.enabled; | |
5435 | if (psl_clkgate_wa) | |
5436 | glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true); | |
5437 | ||
6315b5d3 | 5438 | if (INTEL_GEN(dev_priv) >= 9) |
e435d6e5 | 5439 | skylake_pfit_enable(intel_crtc); |
ff6d9f55 | 5440 | else |
1c132b44 | 5441 | ironlake_pfit_enable(intel_crtc); |
4f771f10 PZ |
5442 | |
5443 | /* | |
5444 | * On ILK+ LUT must be loaded before the pipe is running but with | |
5445 | * clocks enabled | |
5446 | */ | |
b95c5321 | 5447 | intel_color_load_luts(&pipe_config->base); |
4f771f10 | 5448 | |
3dc38eea | 5449 | intel_ddi_set_pipe_settings(pipe_config); |
d7edc4e5 | 5450 | if (!transcoder_is_dsi(cpu_transcoder)) |
3dc38eea | 5451 | intel_ddi_enable_transcoder_func(pipe_config); |
4f771f10 | 5452 | |
1d5bf5d9 | 5453 | if (dev_priv->display.initial_watermarks != NULL) |
3125d39f | 5454 | dev_priv->display.initial_watermarks(old_intel_state, pipe_config); |
4d1de975 JN |
5455 | |
5456 | /* XXX: Do the pipe assertions at the right place for BXT DSI. */ | |
d7edc4e5 | 5457 | if (!transcoder_is_dsi(cpu_transcoder)) |
4d1de975 | 5458 | intel_enable_pipe(intel_crtc); |
42db64ef | 5459 | |
6e3c9717 | 5460 | if (intel_crtc->config->has_pch_encoder) |
2ce42273 | 5461 | lpt_pch_enable(pipe_config); |
4f771f10 | 5462 | |
0037071d | 5463 | if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DP_MST)) |
3dc38eea | 5464 | intel_ddi_set_vc_payload_alloc(pipe_config, true); |
0e32b39c | 5465 | |
f9b61ff6 DV |
5466 | assert_vblank_disabled(crtc); |
5467 | drm_crtc_vblank_on(crtc); | |
5468 | ||
fd6bbda9 | 5469 | intel_encoders_enable(crtc, pipe_config, old_state); |
4f771f10 | 5470 | |
ed69cd40 | 5471 | if (psl_clkgate_wa) { |
0f0f74bc | 5472 | intel_wait_for_vblank(dev_priv, pipe); |
ed69cd40 | 5473 | glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false); |
6b698516 | 5474 | } |
d2d65408 | 5475 | |
e4916946 PZ |
5476 | /* If we change the relative order between pipe/planes enabling, we need |
5477 | * to change the workaround. */ | |
99d736a2 | 5478 | hsw_workaround_pipe = pipe_config->hsw_workaround_pipe; |
772c2a51 | 5479 | if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) { |
0f0f74bc VS |
5480 | intel_wait_for_vblank(dev_priv, hsw_workaround_pipe); |
5481 | intel_wait_for_vblank(dev_priv, hsw_workaround_pipe); | |
99d736a2 | 5482 | } |
4f771f10 PZ |
5483 | } |
5484 | ||
bfd16b2a | 5485 | static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force) |
3f8dce3a DV |
5486 | { |
5487 | struct drm_device *dev = crtc->base.dev; | |
fac5e23e | 5488 | struct drm_i915_private *dev_priv = to_i915(dev); |
3f8dce3a DV |
5489 | int pipe = crtc->pipe; |
5490 | ||
5491 | /* To avoid upsetting the power well on haswell only disable the pfit if | |
5492 | * it's in use. The hw state code will make sure we get this right. */ | |
bfd16b2a | 5493 | if (force || crtc->config->pch_pfit.enabled) { |
3f8dce3a DV |
5494 | I915_WRITE(PF_CTL(pipe), 0); |
5495 | I915_WRITE(PF_WIN_POS(pipe), 0); | |
5496 | I915_WRITE(PF_WIN_SZ(pipe), 0); | |
5497 | } | |
5498 | } | |
5499 | ||
4a806558 ML |
5500 | static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state, |
5501 | struct drm_atomic_state *old_state) | |
6be4a607 | 5502 | { |
4a806558 | 5503 | struct drm_crtc *crtc = old_crtc_state->base.crtc; |
6be4a607 | 5504 | struct drm_device *dev = crtc->dev; |
fac5e23e | 5505 | struct drm_i915_private *dev_priv = to_i915(dev); |
6be4a607 JB |
5506 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
5507 | int pipe = intel_crtc->pipe; | |
b52eb4dc | 5508 | |
b2c0593a VS |
5509 | /* |
5510 | * Sometimes spurious CPU pipe underruns happen when the | |
5511 | * pipe is already disabled, but FDI RX/TX is still enabled. | |
5512 | * Happens at least with VGA+HDMI cloning. Suppress them. | |
5513 | */ | |
5514 | if (intel_crtc->config->has_pch_encoder) { | |
5515 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
37ca8d4c | 5516 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
b2c0593a | 5517 | } |
37ca8d4c | 5518 | |
fd6bbda9 | 5519 | intel_encoders_disable(crtc, old_crtc_state, old_state); |
ea9d758d | 5520 | |
f9b61ff6 DV |
5521 | drm_crtc_vblank_off(crtc); |
5522 | assert_vblank_disabled(crtc); | |
5523 | ||
575f7ab7 | 5524 | intel_disable_pipe(intel_crtc); |
32f9d658 | 5525 | |
bfd16b2a | 5526 | ironlake_pfit_disable(intel_crtc, false); |
2c07245f | 5527 | |
b2c0593a | 5528 | if (intel_crtc->config->has_pch_encoder) |
5a74f70a VS |
5529 | ironlake_fdi_disable(crtc); |
5530 | ||
fd6bbda9 | 5531 | intel_encoders_post_disable(crtc, old_crtc_state, old_state); |
2c07245f | 5532 | |
6e3c9717 | 5533 | if (intel_crtc->config->has_pch_encoder) { |
d925c59a | 5534 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
6be4a607 | 5535 | |
6e266956 | 5536 | if (HAS_PCH_CPT(dev_priv)) { |
f0f59a00 VS |
5537 | i915_reg_t reg; |
5538 | u32 temp; | |
5539 | ||
d925c59a DV |
5540 | /* disable TRANS_DP_CTL */ |
5541 | reg = TRANS_DP_CTL(pipe); | |
5542 | temp = I915_READ(reg); | |
5543 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | | |
5544 | TRANS_DP_PORT_SEL_MASK); | |
5545 | temp |= TRANS_DP_PORT_SEL_NONE; | |
5546 | I915_WRITE(reg, temp); | |
5547 | ||
5548 | /* disable DPLL_SEL */ | |
5549 | temp = I915_READ(PCH_DPLL_SEL); | |
11887397 | 5550 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
d925c59a | 5551 | I915_WRITE(PCH_DPLL_SEL, temp); |
9db4a9c7 | 5552 | } |
e3421a18 | 5553 | |
d925c59a DV |
5554 | ironlake_fdi_pll_disable(intel_crtc); |
5555 | } | |
81b088ca | 5556 | |
b2c0593a | 5557 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
81b088ca | 5558 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
6be4a607 | 5559 | } |
1b3c7a47 | 5560 | |
4a806558 ML |
5561 | static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state, |
5562 | struct drm_atomic_state *old_state) | |
ee7b9f93 | 5563 | { |
4a806558 | 5564 | struct drm_crtc *crtc = old_crtc_state->base.crtc; |
6315b5d3 | 5565 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
ee7b9f93 | 5566 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
6e3c9717 | 5567 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
ee7b9f93 | 5568 | |
fd6bbda9 | 5569 | intel_encoders_disable(crtc, old_crtc_state, old_state); |
4f771f10 | 5570 | |
f9b61ff6 DV |
5571 | drm_crtc_vblank_off(crtc); |
5572 | assert_vblank_disabled(crtc); | |
5573 | ||
4d1de975 | 5574 | /* XXX: Do the pipe assertions at the right place for BXT DSI. */ |
d7edc4e5 | 5575 | if (!transcoder_is_dsi(cpu_transcoder)) |
4d1de975 | 5576 | intel_disable_pipe(intel_crtc); |
4f771f10 | 5577 | |
0037071d | 5578 | if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DP_MST)) |
3dc38eea | 5579 | intel_ddi_set_vc_payload_alloc(intel_crtc->config, false); |
a4bf214f | 5580 | |
d7edc4e5 | 5581 | if (!transcoder_is_dsi(cpu_transcoder)) |
af25065b | 5582 | intel_ddi_disable_transcoder_func(old_crtc_state); |
4f771f10 | 5583 | |
6315b5d3 | 5584 | if (INTEL_GEN(dev_priv) >= 9) |
e435d6e5 | 5585 | skylake_scaler_disable(intel_crtc); |
ff6d9f55 | 5586 | else |
bfd16b2a | 5587 | ironlake_pfit_disable(intel_crtc, false); |
4f771f10 | 5588 | |
d7edc4e5 | 5589 | if (!transcoder_is_dsi(cpu_transcoder)) |
3dc38eea | 5590 | intel_ddi_disable_pipe_clock(intel_crtc->config); |
4f771f10 | 5591 | |
fd6bbda9 | 5592 | intel_encoders_post_disable(crtc, old_crtc_state, old_state); |
4f771f10 PZ |
5593 | } |
5594 | ||
2dd24552 JB |
5595 | static void i9xx_pfit_enable(struct intel_crtc *crtc) |
5596 | { | |
5597 | struct drm_device *dev = crtc->base.dev; | |
fac5e23e | 5598 | struct drm_i915_private *dev_priv = to_i915(dev); |
6e3c9717 | 5599 | struct intel_crtc_state *pipe_config = crtc->config; |
2dd24552 | 5600 | |
681a8504 | 5601 | if (!pipe_config->gmch_pfit.control) |
2dd24552 JB |
5602 | return; |
5603 | ||
2dd24552 | 5604 | /* |
c0b03411 DV |
5605 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
5606 | * according to register description and PRM. | |
2dd24552 | 5607 | */ |
c0b03411 DV |
5608 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
5609 | assert_pipe_disabled(dev_priv, crtc->pipe); | |
2dd24552 | 5610 | |
b074cec8 JB |
5611 | I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios); |
5612 | I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control); | |
5a80c45c DV |
5613 | |
5614 | /* Border color in case we don't scale up to the full screen. Black by | |
5615 | * default, change to something else for debugging. */ | |
5616 | I915_WRITE(BCLRPAT(crtc->pipe), 0); | |
2dd24552 JB |
5617 | } |
5618 | ||
79f255a0 | 5619 | enum intel_display_power_domain intel_port_to_power_domain(enum port port) |
d05410f9 DA |
5620 | { |
5621 | switch (port) { | |
5622 | case PORT_A: | |
6331a704 | 5623 | return POWER_DOMAIN_PORT_DDI_A_LANES; |
d05410f9 | 5624 | case PORT_B: |
6331a704 | 5625 | return POWER_DOMAIN_PORT_DDI_B_LANES; |
d05410f9 | 5626 | case PORT_C: |
6331a704 | 5627 | return POWER_DOMAIN_PORT_DDI_C_LANES; |
d05410f9 | 5628 | case PORT_D: |
6331a704 | 5629 | return POWER_DOMAIN_PORT_DDI_D_LANES; |
d8e19f99 | 5630 | case PORT_E: |
6331a704 | 5631 | return POWER_DOMAIN_PORT_DDI_E_LANES; |
d05410f9 | 5632 | default: |
b9fec167 | 5633 | MISSING_CASE(port); |
d05410f9 DA |
5634 | return POWER_DOMAIN_PORT_OTHER; |
5635 | } | |
5636 | } | |
5637 | ||
d8fc70b7 ACO |
5638 | static u64 get_crtc_power_domains(struct drm_crtc *crtc, |
5639 | struct intel_crtc_state *crtc_state) | |
77d22dca | 5640 | { |
319be8ae | 5641 | struct drm_device *dev = crtc->dev; |
37255d8d | 5642 | struct drm_i915_private *dev_priv = to_i915(dev); |
74bff5f9 | 5643 | struct drm_encoder *encoder; |
319be8ae ID |
5644 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
5645 | enum pipe pipe = intel_crtc->pipe; | |
d8fc70b7 | 5646 | u64 mask; |
74bff5f9 | 5647 | enum transcoder transcoder = crtc_state->cpu_transcoder; |
77d22dca | 5648 | |
74bff5f9 | 5649 | if (!crtc_state->base.active) |
292b990e ML |
5650 | return 0; |
5651 | ||
77d22dca ID |
5652 | mask = BIT(POWER_DOMAIN_PIPE(pipe)); |
5653 | mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder)); | |
74bff5f9 ML |
5654 | if (crtc_state->pch_pfit.enabled || |
5655 | crtc_state->pch_pfit.force_thru) | |
d8fc70b7 | 5656 | mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
77d22dca | 5657 | |
74bff5f9 ML |
5658 | drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) { |
5659 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); | |
5660 | ||
79f255a0 | 5661 | mask |= BIT_ULL(intel_encoder->power_domain); |
74bff5f9 | 5662 | } |
319be8ae | 5663 | |
37255d8d ML |
5664 | if (HAS_DDI(dev_priv) && crtc_state->has_audio) |
5665 | mask |= BIT(POWER_DOMAIN_AUDIO); | |
5666 | ||
15e7ec29 | 5667 | if (crtc_state->shared_dpll) |
d8fc70b7 | 5668 | mask |= BIT_ULL(POWER_DOMAIN_PLLS); |
15e7ec29 | 5669 | |
77d22dca ID |
5670 | return mask; |
5671 | } | |
5672 | ||
d2d15016 | 5673 | static u64 |
74bff5f9 ML |
5674 | modeset_get_crtc_power_domains(struct drm_crtc *crtc, |
5675 | struct intel_crtc_state *crtc_state) | |
77d22dca | 5676 | { |
fac5e23e | 5677 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
292b990e ML |
5678 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
5679 | enum intel_display_power_domain domain; | |
d8fc70b7 | 5680 | u64 domains, new_domains, old_domains; |
77d22dca | 5681 | |
292b990e | 5682 | old_domains = intel_crtc->enabled_power_domains; |
74bff5f9 ML |
5683 | intel_crtc->enabled_power_domains = new_domains = |
5684 | get_crtc_power_domains(crtc, crtc_state); | |
77d22dca | 5685 | |
5a21b665 | 5686 | domains = new_domains & ~old_domains; |
292b990e ML |
5687 | |
5688 | for_each_power_domain(domain, domains) | |
5689 | intel_display_power_get(dev_priv, domain); | |
5690 | ||
5a21b665 | 5691 | return old_domains & ~new_domains; |
292b990e ML |
5692 | } |
5693 | ||
5694 | static void modeset_put_power_domains(struct drm_i915_private *dev_priv, | |
d8fc70b7 | 5695 | u64 domains) |
292b990e ML |
5696 | { |
5697 | enum intel_display_power_domain domain; | |
5698 | ||
5699 | for_each_power_domain(domain, domains) | |
5700 | intel_display_power_put(dev_priv, domain); | |
5701 | } | |
77d22dca | 5702 | |
7ff89ca2 VS |
5703 | static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config, |
5704 | struct drm_atomic_state *old_state) | |
adafdc6f | 5705 | { |
ff32c54e VS |
5706 | struct intel_atomic_state *old_intel_state = |
5707 | to_intel_atomic_state(old_state); | |
7ff89ca2 VS |
5708 | struct drm_crtc *crtc = pipe_config->base.crtc; |
5709 | struct drm_device *dev = crtc->dev; | |
5710 | struct drm_i915_private *dev_priv = to_i915(dev); | |
5711 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
5712 | int pipe = intel_crtc->pipe; | |
adafdc6f | 5713 | |
7ff89ca2 VS |
5714 | if (WARN_ON(intel_crtc->active)) |
5715 | return; | |
adafdc6f | 5716 | |
7ff89ca2 VS |
5717 | if (intel_crtc_has_dp_encoder(intel_crtc->config)) |
5718 | intel_dp_set_m_n(intel_crtc, M1_N1); | |
b2045352 | 5719 | |
7ff89ca2 VS |
5720 | intel_set_pipe_timings(intel_crtc); |
5721 | intel_set_pipe_src_size(intel_crtc); | |
b2045352 | 5722 | |
7ff89ca2 VS |
5723 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) { |
5724 | struct drm_i915_private *dev_priv = to_i915(dev); | |
560a7ae4 | 5725 | |
7ff89ca2 VS |
5726 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); |
5727 | I915_WRITE(CHV_CANVAS(pipe), 0); | |
560a7ae4 DL |
5728 | } |
5729 | ||
7ff89ca2 | 5730 | i9xx_set_pipeconf(intel_crtc); |
560a7ae4 | 5731 | |
7ff89ca2 | 5732 | intel_crtc->active = true; |
92891e45 | 5733 | |
7ff89ca2 | 5734 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
5f199dfa | 5735 | |
7ff89ca2 | 5736 | intel_encoders_pre_pll_enable(crtc, pipe_config, old_state); |
5f199dfa | 5737 | |
7ff89ca2 VS |
5738 | if (IS_CHERRYVIEW(dev_priv)) { |
5739 | chv_prepare_pll(intel_crtc, intel_crtc->config); | |
5740 | chv_enable_pll(intel_crtc, intel_crtc->config); | |
5741 | } else { | |
5742 | vlv_prepare_pll(intel_crtc, intel_crtc->config); | |
5743 | vlv_enable_pll(intel_crtc, intel_crtc->config); | |
5f199dfa VS |
5744 | } |
5745 | ||
7ff89ca2 | 5746 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
5f199dfa | 5747 | |
7ff89ca2 | 5748 | i9xx_pfit_enable(intel_crtc); |
89b3c3c7 | 5749 | |
7ff89ca2 | 5750 | intel_color_load_luts(&pipe_config->base); |
89b3c3c7 | 5751 | |
ff32c54e VS |
5752 | dev_priv->display.initial_watermarks(old_intel_state, |
5753 | pipe_config); | |
7ff89ca2 VS |
5754 | intel_enable_pipe(intel_crtc); |
5755 | ||
5756 | assert_vblank_disabled(crtc); | |
5757 | drm_crtc_vblank_on(crtc); | |
89b3c3c7 | 5758 | |
7ff89ca2 | 5759 | intel_encoders_enable(crtc, pipe_config, old_state); |
89b3c3c7 ACO |
5760 | } |
5761 | ||
7ff89ca2 | 5762 | static void i9xx_set_pll_dividers(struct intel_crtc *crtc) |
2b73001e | 5763 | { |
7ff89ca2 VS |
5764 | struct drm_device *dev = crtc->base.dev; |
5765 | struct drm_i915_private *dev_priv = to_i915(dev); | |
83d7c81f | 5766 | |
7ff89ca2 VS |
5767 | I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0); |
5768 | I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1); | |
2b73001e VS |
5769 | } |
5770 | ||
7ff89ca2 VS |
5771 | static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config, |
5772 | struct drm_atomic_state *old_state) | |
2b73001e | 5773 | { |
04548cba VS |
5774 | struct intel_atomic_state *old_intel_state = |
5775 | to_intel_atomic_state(old_state); | |
7ff89ca2 VS |
5776 | struct drm_crtc *crtc = pipe_config->base.crtc; |
5777 | struct drm_device *dev = crtc->dev; | |
5778 | struct drm_i915_private *dev_priv = to_i915(dev); | |
5779 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
5780 | enum pipe pipe = intel_crtc->pipe; | |
2b73001e | 5781 | |
7ff89ca2 VS |
5782 | if (WARN_ON(intel_crtc->active)) |
5783 | return; | |
2b73001e | 5784 | |
7ff89ca2 | 5785 | i9xx_set_pll_dividers(intel_crtc); |
2b73001e | 5786 | |
7ff89ca2 VS |
5787 | if (intel_crtc_has_dp_encoder(intel_crtc->config)) |
5788 | intel_dp_set_m_n(intel_crtc, M1_N1); | |
83d7c81f | 5789 | |
7ff89ca2 VS |
5790 | intel_set_pipe_timings(intel_crtc); |
5791 | intel_set_pipe_src_size(intel_crtc); | |
2b73001e | 5792 | |
7ff89ca2 | 5793 | i9xx_set_pipeconf(intel_crtc); |
f8437dd1 | 5794 | |
7ff89ca2 | 5795 | intel_crtc->active = true; |
5f199dfa | 5796 | |
7ff89ca2 VS |
5797 | if (!IS_GEN2(dev_priv)) |
5798 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); | |
5f199dfa | 5799 | |
7ff89ca2 | 5800 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
f8437dd1 | 5801 | |
939994da | 5802 | i9xx_enable_pll(intel_crtc, pipe_config); |
f8437dd1 | 5803 | |
7ff89ca2 | 5804 | i9xx_pfit_enable(intel_crtc); |
f8437dd1 | 5805 | |
7ff89ca2 | 5806 | intel_color_load_luts(&pipe_config->base); |
f8437dd1 | 5807 | |
04548cba VS |
5808 | if (dev_priv->display.initial_watermarks != NULL) |
5809 | dev_priv->display.initial_watermarks(old_intel_state, | |
5810 | intel_crtc->config); | |
5811 | else | |
5812 | intel_update_watermarks(intel_crtc); | |
7ff89ca2 | 5813 | intel_enable_pipe(intel_crtc); |
f8437dd1 | 5814 | |
7ff89ca2 VS |
5815 | assert_vblank_disabled(crtc); |
5816 | drm_crtc_vblank_on(crtc); | |
f8437dd1 | 5817 | |
7ff89ca2 VS |
5818 | intel_encoders_enable(crtc, pipe_config, old_state); |
5819 | } | |
f8437dd1 | 5820 | |
7ff89ca2 VS |
5821 | static void i9xx_pfit_disable(struct intel_crtc *crtc) |
5822 | { | |
5823 | struct drm_device *dev = crtc->base.dev; | |
5824 | struct drm_i915_private *dev_priv = to_i915(dev); | |
f8437dd1 | 5825 | |
7ff89ca2 | 5826 | if (!crtc->config->gmch_pfit.control) |
f8437dd1 | 5827 | return; |
f8437dd1 | 5828 | |
7ff89ca2 VS |
5829 | assert_pipe_disabled(dev_priv, crtc->pipe); |
5830 | ||
5831 | DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", | |
5832 | I915_READ(PFIT_CONTROL)); | |
5833 | I915_WRITE(PFIT_CONTROL, 0); | |
f8437dd1 VK |
5834 | } |
5835 | ||
7ff89ca2 VS |
5836 | static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state, |
5837 | struct drm_atomic_state *old_state) | |
f8437dd1 | 5838 | { |
7ff89ca2 VS |
5839 | struct drm_crtc *crtc = old_crtc_state->base.crtc; |
5840 | struct drm_device *dev = crtc->dev; | |
5841 | struct drm_i915_private *dev_priv = to_i915(dev); | |
5842 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
5843 | int pipe = intel_crtc->pipe; | |
d66a2194 | 5844 | |
d66a2194 | 5845 | /* |
7ff89ca2 VS |
5846 | * On gen2 planes are double buffered but the pipe isn't, so we must |
5847 | * wait for planes to fully turn off before disabling the pipe. | |
d66a2194 | 5848 | */ |
7ff89ca2 VS |
5849 | if (IS_GEN2(dev_priv)) |
5850 | intel_wait_for_vblank(dev_priv, pipe); | |
d66a2194 | 5851 | |
7ff89ca2 | 5852 | intel_encoders_disable(crtc, old_crtc_state, old_state); |
d66a2194 | 5853 | |
7ff89ca2 VS |
5854 | drm_crtc_vblank_off(crtc); |
5855 | assert_vblank_disabled(crtc); | |
d66a2194 | 5856 | |
7ff89ca2 | 5857 | intel_disable_pipe(intel_crtc); |
d66a2194 | 5858 | |
7ff89ca2 | 5859 | i9xx_pfit_disable(intel_crtc); |
89b3c3c7 | 5860 | |
7ff89ca2 | 5861 | intel_encoders_post_disable(crtc, old_crtc_state, old_state); |
d66a2194 | 5862 | |
7ff89ca2 VS |
5863 | if (!intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DSI)) { |
5864 | if (IS_CHERRYVIEW(dev_priv)) | |
5865 | chv_disable_pll(dev_priv, pipe); | |
5866 | else if (IS_VALLEYVIEW(dev_priv)) | |
5867 | vlv_disable_pll(dev_priv, pipe); | |
5868 | else | |
5869 | i9xx_disable_pll(intel_crtc); | |
5870 | } | |
c2e001ef | 5871 | |
7ff89ca2 | 5872 | intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state); |
89b3c3c7 | 5873 | |
7ff89ca2 VS |
5874 | if (!IS_GEN2(dev_priv)) |
5875 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); | |
ff32c54e VS |
5876 | |
5877 | if (!dev_priv->display.initial_watermarks) | |
5878 | intel_update_watermarks(intel_crtc); | |
2ee0da16 VS |
5879 | |
5880 | /* clock the pipe down to 640x480@60 to potentially save power */ | |
5881 | if (IS_I830(dev_priv)) | |
5882 | i830_enable_pipe(dev_priv, pipe); | |
f8437dd1 VK |
5883 | } |
5884 | ||
da1d0e26 VS |
5885 | static void intel_crtc_disable_noatomic(struct drm_crtc *crtc, |
5886 | struct drm_modeset_acquire_ctx *ctx) | |
f8437dd1 | 5887 | { |
7ff89ca2 VS |
5888 | struct intel_encoder *encoder; |
5889 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
5890 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); | |
5891 | enum intel_display_power_domain domain; | |
23ac1273 | 5892 | struct intel_plane *plane; |
d2d15016 | 5893 | u64 domains; |
7ff89ca2 VS |
5894 | struct drm_atomic_state *state; |
5895 | struct intel_crtc_state *crtc_state; | |
5896 | int ret; | |
f8437dd1 | 5897 | |
7ff89ca2 VS |
5898 | if (!intel_crtc->active) |
5899 | return; | |
a8ca4934 | 5900 | |
23ac1273 VS |
5901 | for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) { |
5902 | const struct intel_plane_state *plane_state = | |
5903 | to_intel_plane_state(plane->base.state); | |
709e05c3 | 5904 | |
23ac1273 VS |
5905 | if (plane_state->base.visible) |
5906 | intel_plane_disable_noatomic(intel_crtc, plane); | |
7ff89ca2 | 5907 | } |
5d96d8af | 5908 | |
7ff89ca2 VS |
5909 | state = drm_atomic_state_alloc(crtc->dev); |
5910 | if (!state) { | |
5911 | DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory", | |
5912 | crtc->base.id, crtc->name); | |
1c3f7700 | 5913 | return; |
7ff89ca2 | 5914 | } |
9f7eb31a | 5915 | |
da1d0e26 | 5916 | state->acquire_ctx = ctx; |
ea61791e | 5917 | |
7ff89ca2 VS |
5918 | /* Everything's already locked, -EDEADLK can't happen. */ |
5919 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); | |
5920 | ret = drm_atomic_add_affected_connectors(state, crtc); | |
9f7eb31a | 5921 | |
7ff89ca2 | 5922 | WARN_ON(IS_ERR(crtc_state) || ret); |
5d96d8af | 5923 | |
7ff89ca2 | 5924 | dev_priv->display.crtc_disable(crtc_state, state); |
4a806558 | 5925 | |
0853695c | 5926 | drm_atomic_state_put(state); |
842e0307 | 5927 | |
78108b7c VS |
5928 | DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n", |
5929 | crtc->base.id, crtc->name); | |
842e0307 ML |
5930 | |
5931 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0); | |
5932 | crtc->state->active = false; | |
37d9078b | 5933 | intel_crtc->active = false; |
842e0307 ML |
5934 | crtc->enabled = false; |
5935 | crtc->state->connector_mask = 0; | |
5936 | crtc->state->encoder_mask = 0; | |
5937 | ||
5938 | for_each_encoder_on_crtc(crtc->dev, crtc, encoder) | |
5939 | encoder->base.crtc = NULL; | |
5940 | ||
58f9c0bc | 5941 | intel_fbc_disable(intel_crtc); |
432081bc | 5942 | intel_update_watermarks(intel_crtc); |
1f7457b1 | 5943 | intel_disable_shared_dpll(intel_crtc); |
b17d48e2 ML |
5944 | |
5945 | domains = intel_crtc->enabled_power_domains; | |
5946 | for_each_power_domain(domain, domains) | |
5947 | intel_display_power_put(dev_priv, domain); | |
5948 | intel_crtc->enabled_power_domains = 0; | |
565602d7 ML |
5949 | |
5950 | dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe); | |
d305e061 | 5951 | dev_priv->min_cdclk[intel_crtc->pipe] = 0; |
b17d48e2 ML |
5952 | } |
5953 | ||
6b72d486 ML |
5954 | /* |
5955 | * turn all crtc's off, but do not adjust state | |
5956 | * This has to be paired with a call to intel_modeset_setup_hw_state. | |
5957 | */ | |
70e0bd74 | 5958 | int intel_display_suspend(struct drm_device *dev) |
ee7b9f93 | 5959 | { |
e2c8b870 | 5960 | struct drm_i915_private *dev_priv = to_i915(dev); |
70e0bd74 | 5961 | struct drm_atomic_state *state; |
e2c8b870 | 5962 | int ret; |
70e0bd74 | 5963 | |
e2c8b870 ML |
5964 | state = drm_atomic_helper_suspend(dev); |
5965 | ret = PTR_ERR_OR_ZERO(state); | |
70e0bd74 ML |
5966 | if (ret) |
5967 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); | |
e2c8b870 ML |
5968 | else |
5969 | dev_priv->modeset_restore_state = state; | |
70e0bd74 | 5970 | return ret; |
ee7b9f93 JB |
5971 | } |
5972 | ||
ea5b213a | 5973 | void intel_encoder_destroy(struct drm_encoder *encoder) |
7e7d76c3 | 5974 | { |
4ef69c7a | 5975 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
ea5b213a | 5976 | |
ea5b213a CW |
5977 | drm_encoder_cleanup(encoder); |
5978 | kfree(intel_encoder); | |
7e7d76c3 JB |
5979 | } |
5980 | ||
0a91ca29 DV |
5981 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
5982 | * internal consistency). */ | |
749d98b8 ML |
5983 | static void intel_connector_verify_state(struct drm_crtc_state *crtc_state, |
5984 | struct drm_connector_state *conn_state) | |
79e53945 | 5985 | { |
749d98b8 | 5986 | struct intel_connector *connector = to_intel_connector(conn_state->connector); |
35dd3c64 ML |
5987 | |
5988 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", | |
5989 | connector->base.base.id, | |
5990 | connector->base.name); | |
5991 | ||
0a91ca29 | 5992 | if (connector->get_hw_state(connector)) { |
e85376cb | 5993 | struct intel_encoder *encoder = connector->encoder; |
0a91ca29 | 5994 | |
749d98b8 | 5995 | I915_STATE_WARN(!crtc_state, |
35dd3c64 | 5996 | "connector enabled without attached crtc\n"); |
0a91ca29 | 5997 | |
749d98b8 | 5998 | if (!crtc_state) |
35dd3c64 ML |
5999 | return; |
6000 | ||
749d98b8 | 6001 | I915_STATE_WARN(!crtc_state->active, |
35dd3c64 ML |
6002 | "connector is active, but attached crtc isn't\n"); |
6003 | ||
e85376cb | 6004 | if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST) |
35dd3c64 ML |
6005 | return; |
6006 | ||
e85376cb | 6007 | I915_STATE_WARN(conn_state->best_encoder != &encoder->base, |
35dd3c64 ML |
6008 | "atomic encoder doesn't match attached encoder\n"); |
6009 | ||
e85376cb | 6010 | I915_STATE_WARN(conn_state->crtc != encoder->base.crtc, |
35dd3c64 ML |
6011 | "attached encoder crtc differs from connector crtc\n"); |
6012 | } else { | |
749d98b8 | 6013 | I915_STATE_WARN(crtc_state && crtc_state->active, |
4d688a2a | 6014 | "attached crtc is active, but connector isn't\n"); |
749d98b8 | 6015 | I915_STATE_WARN(!crtc_state && conn_state->best_encoder, |
35dd3c64 | 6016 | "best encoder set without crtc!\n"); |
0a91ca29 | 6017 | } |
79e53945 JB |
6018 | } |
6019 | ||
08d9bc92 ACO |
6020 | int intel_connector_init(struct intel_connector *connector) |
6021 | { | |
11c1a9ec | 6022 | struct intel_digital_connector_state *conn_state; |
08d9bc92 | 6023 | |
11c1a9ec ML |
6024 | /* |
6025 | * Allocate enough memory to hold intel_digital_connector_state, | |
6026 | * This might be a few bytes too many, but for connectors that don't | |
6027 | * need it we'll free the state and allocate a smaller one on the first | |
6028 | * succesful commit anyway. | |
6029 | */ | |
6030 | conn_state = kzalloc(sizeof(*conn_state), GFP_KERNEL); | |
6031 | if (!conn_state) | |
08d9bc92 ACO |
6032 | return -ENOMEM; |
6033 | ||
11c1a9ec ML |
6034 | __drm_atomic_helper_connector_reset(&connector->base, |
6035 | &conn_state->base); | |
6036 | ||
08d9bc92 ACO |
6037 | return 0; |
6038 | } | |
6039 | ||
6040 | struct intel_connector *intel_connector_alloc(void) | |
6041 | { | |
6042 | struct intel_connector *connector; | |
6043 | ||
6044 | connector = kzalloc(sizeof *connector, GFP_KERNEL); | |
6045 | if (!connector) | |
6046 | return NULL; | |
6047 | ||
6048 | if (intel_connector_init(connector) < 0) { | |
6049 | kfree(connector); | |
6050 | return NULL; | |
6051 | } | |
6052 | ||
6053 | return connector; | |
6054 | } | |
6055 | ||
091a4f91 JA |
6056 | /* |
6057 | * Free the bits allocated by intel_connector_alloc. | |
6058 | * This should only be used after intel_connector_alloc has returned | |
6059 | * successfully, and before drm_connector_init returns successfully. | |
6060 | * Otherwise the destroy callbacks for the connector and the state should | |
6061 | * take care of proper cleanup/free | |
6062 | */ | |
6063 | void intel_connector_free(struct intel_connector *connector) | |
6064 | { | |
6065 | kfree(to_intel_digital_connector_state(connector->base.state)); | |
6066 | kfree(connector); | |
6067 | } | |
6068 | ||
f0947c37 DV |
6069 | /* Simple connector->get_hw_state implementation for encoders that support only |
6070 | * one connector and no cloning and hence the encoder state determines the state | |
6071 | * of the connector. */ | |
6072 | bool intel_connector_get_hw_state(struct intel_connector *connector) | |
ea5b213a | 6073 | { |
24929352 | 6074 | enum pipe pipe = 0; |
f0947c37 | 6075 | struct intel_encoder *encoder = connector->encoder; |
ea5b213a | 6076 | |
f0947c37 | 6077 | return encoder->get_hw_state(encoder, &pipe); |
ea5b213a CW |
6078 | } |
6079 | ||
6d293983 | 6080 | static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state) |
d272ddfa | 6081 | { |
6d293983 ACO |
6082 | if (crtc_state->base.enable && crtc_state->has_pch_encoder) |
6083 | return crtc_state->fdi_lanes; | |
d272ddfa VS |
6084 | |
6085 | return 0; | |
6086 | } | |
6087 | ||
6d293983 | 6088 | static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe, |
5cec258b | 6089 | struct intel_crtc_state *pipe_config) |
1857e1da | 6090 | { |
8652744b | 6091 | struct drm_i915_private *dev_priv = to_i915(dev); |
6d293983 ACO |
6092 | struct drm_atomic_state *state = pipe_config->base.state; |
6093 | struct intel_crtc *other_crtc; | |
6094 | struct intel_crtc_state *other_crtc_state; | |
6095 | ||
1857e1da DV |
6096 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
6097 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6098 | if (pipe_config->fdi_lanes > 4) { | |
6099 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", | |
6100 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6101 | return -EINVAL; |
1857e1da DV |
6102 | } |
6103 | ||
8652744b | 6104 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
1857e1da DV |
6105 | if (pipe_config->fdi_lanes > 2) { |
6106 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", | |
6107 | pipe_config->fdi_lanes); | |
6d293983 | 6108 | return -EINVAL; |
1857e1da | 6109 | } else { |
6d293983 | 6110 | return 0; |
1857e1da DV |
6111 | } |
6112 | } | |
6113 | ||
b7f05d4a | 6114 | if (INTEL_INFO(dev_priv)->num_pipes == 2) |
6d293983 | 6115 | return 0; |
1857e1da DV |
6116 | |
6117 | /* Ivybridge 3 pipe is really complicated */ | |
6118 | switch (pipe) { | |
6119 | case PIPE_A: | |
6d293983 | 6120 | return 0; |
1857e1da | 6121 | case PIPE_B: |
6d293983 ACO |
6122 | if (pipe_config->fdi_lanes <= 2) |
6123 | return 0; | |
6124 | ||
b91eb5cc | 6125 | other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C); |
6d293983 ACO |
6126 | other_crtc_state = |
6127 | intel_atomic_get_crtc_state(state, other_crtc); | |
6128 | if (IS_ERR(other_crtc_state)) | |
6129 | return PTR_ERR(other_crtc_state); | |
6130 | ||
6131 | if (pipe_required_fdi_lanes(other_crtc_state) > 0) { | |
1857e1da DV |
6132 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
6133 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6134 | return -EINVAL; |
1857e1da | 6135 | } |
6d293983 | 6136 | return 0; |
1857e1da | 6137 | case PIPE_C: |
251cc67c VS |
6138 | if (pipe_config->fdi_lanes > 2) { |
6139 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", | |
6140 | pipe_name(pipe), pipe_config->fdi_lanes); | |
6d293983 | 6141 | return -EINVAL; |
251cc67c | 6142 | } |
6d293983 | 6143 | |
b91eb5cc | 6144 | other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B); |
6d293983 ACO |
6145 | other_crtc_state = |
6146 | intel_atomic_get_crtc_state(state, other_crtc); | |
6147 | if (IS_ERR(other_crtc_state)) | |
6148 | return PTR_ERR(other_crtc_state); | |
6149 | ||
6150 | if (pipe_required_fdi_lanes(other_crtc_state) > 2) { | |
1857e1da | 6151 | DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n"); |
6d293983 | 6152 | return -EINVAL; |
1857e1da | 6153 | } |
6d293983 | 6154 | return 0; |
1857e1da DV |
6155 | default: |
6156 | BUG(); | |
6157 | } | |
6158 | } | |
6159 | ||
e29c22c0 DV |
6160 | #define RETRY 1 |
6161 | static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc, | |
5cec258b | 6162 | struct intel_crtc_state *pipe_config) |
877d48d5 | 6163 | { |
1857e1da | 6164 | struct drm_device *dev = intel_crtc->base.dev; |
7c5f93b0 | 6165 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
6d293983 ACO |
6166 | int lane, link_bw, fdi_dotclock, ret; |
6167 | bool needs_recompute = false; | |
877d48d5 | 6168 | |
e29c22c0 | 6169 | retry: |
877d48d5 DV |
6170 | /* FDI is a binary signal running at ~2.7GHz, encoding |
6171 | * each output octet as 10 bits. The actual frequency | |
6172 | * is stored as a divider into a 100MHz clock, and the | |
6173 | * mode pixel clock is stored in units of 1KHz. | |
6174 | * Hence the bw of each lane in terms of the mode signal | |
6175 | * is: | |
6176 | */ | |
21a727b3 | 6177 | link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config); |
877d48d5 | 6178 | |
241bfc38 | 6179 | fdi_dotclock = adjusted_mode->crtc_clock; |
877d48d5 | 6180 | |
2bd89a07 | 6181 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
877d48d5 DV |
6182 | pipe_config->pipe_bpp); |
6183 | ||
6184 | pipe_config->fdi_lanes = lane; | |
6185 | ||
2bd89a07 | 6186 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
b31e85ed | 6187 | link_bw, &pipe_config->fdi_m_n, false); |
1857e1da | 6188 | |
e3b247da | 6189 | ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config); |
6d293983 | 6190 | if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) { |
e29c22c0 | 6191 | pipe_config->pipe_bpp -= 2*3; |
7ff89ca2 VS |
6192 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", |
6193 | pipe_config->pipe_bpp); | |
6194 | needs_recompute = true; | |
6195 | pipe_config->bw_constrained = true; | |
257a7ffc | 6196 | |
7ff89ca2 | 6197 | goto retry; |
257a7ffc | 6198 | } |
79e53945 | 6199 | |
7ff89ca2 VS |
6200 | if (needs_recompute) |
6201 | return RETRY; | |
e70236a8 | 6202 | |
7ff89ca2 | 6203 | return ret; |
e70236a8 JB |
6204 | } |
6205 | ||
7ff89ca2 VS |
6206 | static bool pipe_config_supports_ips(struct drm_i915_private *dev_priv, |
6207 | struct intel_crtc_state *pipe_config) | |
e70236a8 | 6208 | { |
6e644626 VS |
6209 | if (pipe_config->ips_force_disable) |
6210 | return false; | |
6211 | ||
7ff89ca2 VS |
6212 | if (pipe_config->pipe_bpp > 24) |
6213 | return false; | |
e70236a8 | 6214 | |
7ff89ca2 VS |
6215 | /* HSW can handle pixel rate up to cdclk? */ |
6216 | if (IS_HASWELL(dev_priv)) | |
6217 | return true; | |
1b1d2716 | 6218 | |
65cd2b3f | 6219 | /* |
7ff89ca2 VS |
6220 | * We compare against max which means we must take |
6221 | * the increased cdclk requirement into account when | |
6222 | * calculating the new cdclk. | |
6223 | * | |
6224 | * Should measure whether using a lower cdclk w/o IPS | |
e70236a8 | 6225 | */ |
7ff89ca2 VS |
6226 | return pipe_config->pixel_rate <= |
6227 | dev_priv->max_cdclk_freq * 95 / 100; | |
e70236a8 | 6228 | } |
79e53945 | 6229 | |
7ff89ca2 VS |
6230 | static void hsw_compute_ips_config(struct intel_crtc *crtc, |
6231 | struct intel_crtc_state *pipe_config) | |
6232 | { | |
6233 | struct drm_device *dev = crtc->base.dev; | |
6234 | struct drm_i915_private *dev_priv = to_i915(dev); | |
34edce2f | 6235 | |
4f044a88 | 6236 | pipe_config->ips_enabled = i915_modparams.enable_ips && |
7ff89ca2 VS |
6237 | hsw_crtc_supports_ips(crtc) && |
6238 | pipe_config_supports_ips(dev_priv, pipe_config); | |
34edce2f VS |
6239 | } |
6240 | ||
7ff89ca2 | 6241 | static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc) |
34edce2f | 6242 | { |
7ff89ca2 | 6243 | const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
34edce2f | 6244 | |
7ff89ca2 VS |
6245 | /* GDG double wide on either pipe, otherwise pipe A only */ |
6246 | return INTEL_INFO(dev_priv)->gen < 4 && | |
6247 | (crtc->pipe == PIPE_A || IS_I915G(dev_priv)); | |
34edce2f VS |
6248 | } |
6249 | ||
ceb99320 VS |
6250 | static uint32_t ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config) |
6251 | { | |
6252 | uint32_t pixel_rate; | |
6253 | ||
6254 | pixel_rate = pipe_config->base.adjusted_mode.crtc_clock; | |
6255 | ||
6256 | /* | |
6257 | * We only use IF-ID interlacing. If we ever use | |
6258 | * PF-ID we'll need to adjust the pixel_rate here. | |
6259 | */ | |
6260 | ||
6261 | if (pipe_config->pch_pfit.enabled) { | |
6262 | uint64_t pipe_w, pipe_h, pfit_w, pfit_h; | |
6263 | uint32_t pfit_size = pipe_config->pch_pfit.size; | |
6264 | ||
6265 | pipe_w = pipe_config->pipe_src_w; | |
6266 | pipe_h = pipe_config->pipe_src_h; | |
6267 | ||
6268 | pfit_w = (pfit_size >> 16) & 0xFFFF; | |
6269 | pfit_h = pfit_size & 0xFFFF; | |
6270 | if (pipe_w < pfit_w) | |
6271 | pipe_w = pfit_w; | |
6272 | if (pipe_h < pfit_h) | |
6273 | pipe_h = pfit_h; | |
6274 | ||
6275 | if (WARN_ON(!pfit_w || !pfit_h)) | |
6276 | return pixel_rate; | |
6277 | ||
6278 | pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h, | |
6279 | pfit_w * pfit_h); | |
6280 | } | |
6281 | ||
6282 | return pixel_rate; | |
6283 | } | |
6284 | ||
7ff89ca2 | 6285 | static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state) |
34edce2f | 6286 | { |
7ff89ca2 | 6287 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
34edce2f | 6288 | |
7ff89ca2 VS |
6289 | if (HAS_GMCH_DISPLAY(dev_priv)) |
6290 | /* FIXME calculate proper pipe pixel rate for GMCH pfit */ | |
6291 | crtc_state->pixel_rate = | |
6292 | crtc_state->base.adjusted_mode.crtc_clock; | |
6293 | else | |
6294 | crtc_state->pixel_rate = | |
6295 | ilk_pipe_pixel_rate(crtc_state); | |
6296 | } | |
34edce2f | 6297 | |
7ff89ca2 VS |
6298 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
6299 | struct intel_crtc_state *pipe_config) | |
6300 | { | |
6301 | struct drm_device *dev = crtc->base.dev; | |
6302 | struct drm_i915_private *dev_priv = to_i915(dev); | |
6303 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; | |
6304 | int clock_limit = dev_priv->max_dotclk_freq; | |
34edce2f | 6305 | |
7ff89ca2 VS |
6306 | if (INTEL_GEN(dev_priv) < 4) { |
6307 | clock_limit = dev_priv->max_cdclk_freq * 9 / 10; | |
34edce2f | 6308 | |
7ff89ca2 VS |
6309 | /* |
6310 | * Enable double wide mode when the dot clock | |
6311 | * is > 90% of the (display) core speed. | |
6312 | */ | |
6313 | if (intel_crtc_supports_double_wide(crtc) && | |
6314 | adjusted_mode->crtc_clock > clock_limit) { | |
6315 | clock_limit = dev_priv->max_dotclk_freq; | |
6316 | pipe_config->double_wide = true; | |
6317 | } | |
34edce2f VS |
6318 | } |
6319 | ||
7ff89ca2 VS |
6320 | if (adjusted_mode->crtc_clock > clock_limit) { |
6321 | DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n", | |
6322 | adjusted_mode->crtc_clock, clock_limit, | |
6323 | yesno(pipe_config->double_wide)); | |
6324 | return -EINVAL; | |
6325 | } | |
34edce2f | 6326 | |
25edf915 SS |
6327 | if (pipe_config->ycbcr420 && pipe_config->base.ctm) { |
6328 | /* | |
6329 | * There is only one pipe CSC unit per pipe, and we need that | |
6330 | * for output conversion from RGB->YCBCR. So if CTM is already | |
6331 | * applied we can't support YCBCR420 output. | |
6332 | */ | |
6333 | DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n"); | |
6334 | return -EINVAL; | |
6335 | } | |
6336 | ||
7ff89ca2 VS |
6337 | /* |
6338 | * Pipe horizontal size must be even in: | |
6339 | * - DVO ganged mode | |
6340 | * - LVDS dual channel mode | |
6341 | * - Double wide pipe | |
6342 | */ | |
6343 | if ((intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) && | |
6344 | intel_is_dual_link_lvds(dev)) || pipe_config->double_wide) | |
6345 | pipe_config->pipe_src_w &= ~1; | |
34edce2f | 6346 | |
7ff89ca2 VS |
6347 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
6348 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. | |
6349 | */ | |
6350 | if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) && | |
6351 | adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay) | |
6352 | return -EINVAL; | |
34edce2f | 6353 | |
7ff89ca2 | 6354 | intel_crtc_compute_pixel_rate(pipe_config); |
34edce2f | 6355 | |
7ff89ca2 VS |
6356 | if (HAS_IPS(dev_priv)) |
6357 | hsw_compute_ips_config(crtc, pipe_config); | |
34edce2f | 6358 | |
7ff89ca2 VS |
6359 | if (pipe_config->has_pch_encoder) |
6360 | return ironlake_fdi_compute_config(crtc, pipe_config); | |
34edce2f | 6361 | |
7ff89ca2 | 6362 | return 0; |
34edce2f VS |
6363 | } |
6364 | ||
2c07245f | 6365 | static void |
a65851af | 6366 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
2c07245f | 6367 | { |
a65851af VS |
6368 | while (*num > DATA_LINK_M_N_MASK || |
6369 | *den > DATA_LINK_M_N_MASK) { | |
2c07245f ZW |
6370 | *num >>= 1; |
6371 | *den >>= 1; | |
6372 | } | |
6373 | } | |
6374 | ||
a65851af | 6375 | static void compute_m_n(unsigned int m, unsigned int n, |
b31e85ed JN |
6376 | uint32_t *ret_m, uint32_t *ret_n, |
6377 | bool reduce_m_n) | |
a65851af | 6378 | { |
9a86cda0 JN |
6379 | /* |
6380 | * Reduce M/N as much as possible without loss in precision. Several DP | |
6381 | * dongles in particular seem to be fussy about too large *link* M/N | |
6382 | * values. The passed in values are more likely to have the least | |
6383 | * significant bits zero than M after rounding below, so do this first. | |
6384 | */ | |
b31e85ed JN |
6385 | if (reduce_m_n) { |
6386 | while ((m & 1) == 0 && (n & 1) == 0) { | |
6387 | m >>= 1; | |
6388 | n >>= 1; | |
6389 | } | |
9a86cda0 JN |
6390 | } |
6391 | ||
a65851af VS |
6392 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); |
6393 | *ret_m = div_u64((uint64_t) m * *ret_n, n); | |
6394 | intel_reduce_m_n_ratio(ret_m, ret_n); | |
6395 | } | |
6396 | ||
e69d0bc1 DV |
6397 | void |
6398 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, | |
6399 | int pixel_clock, int link_clock, | |
b31e85ed JN |
6400 | struct intel_link_m_n *m_n, |
6401 | bool reduce_m_n) | |
2c07245f | 6402 | { |
e69d0bc1 | 6403 | m_n->tu = 64; |
a65851af VS |
6404 | |
6405 | compute_m_n(bits_per_pixel * pixel_clock, | |
6406 | link_clock * nlanes * 8, | |
b31e85ed JN |
6407 | &m_n->gmch_m, &m_n->gmch_n, |
6408 | reduce_m_n); | |
a65851af VS |
6409 | |
6410 | compute_m_n(pixel_clock, link_clock, | |
b31e85ed JN |
6411 | &m_n->link_m, &m_n->link_n, |
6412 | reduce_m_n); | |
2c07245f ZW |
6413 | } |
6414 | ||
a7615030 CW |
6415 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
6416 | { | |
4f044a88 MW |
6417 | if (i915_modparams.panel_use_ssc >= 0) |
6418 | return i915_modparams.panel_use_ssc != 0; | |
41aa3448 | 6419 | return dev_priv->vbt.lvds_use_ssc |
435793df | 6420 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
a7615030 CW |
6421 | } |
6422 | ||
7429e9d4 | 6423 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
c65d77d8 | 6424 | { |
7df00d7a | 6425 | return (1 << dpll->n) << 16 | dpll->m2; |
7429e9d4 | 6426 | } |
f47709a9 | 6427 | |
7429e9d4 DV |
6428 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
6429 | { | |
6430 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; | |
c65d77d8 JB |
6431 | } |
6432 | ||
f47709a9 | 6433 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
190f68c5 | 6434 | struct intel_crtc_state *crtc_state, |
9e2c8475 | 6435 | struct dpll *reduced_clock) |
a7516a05 | 6436 | { |
9b1e14f4 | 6437 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
a7516a05 JB |
6438 | u32 fp, fp2 = 0; |
6439 | ||
9b1e14f4 | 6440 | if (IS_PINEVIEW(dev_priv)) { |
190f68c5 | 6441 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
a7516a05 | 6442 | if (reduced_clock) |
7429e9d4 | 6443 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
a7516a05 | 6444 | } else { |
190f68c5 | 6445 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
a7516a05 | 6446 | if (reduced_clock) |
7429e9d4 | 6447 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
a7516a05 JB |
6448 | } |
6449 | ||
190f68c5 | 6450 | crtc_state->dpll_hw_state.fp0 = fp; |
a7516a05 | 6451 | |
2d84d2b3 | 6452 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
ab585dea | 6453 | reduced_clock) { |
190f68c5 | 6454 | crtc_state->dpll_hw_state.fp1 = fp2; |
a7516a05 | 6455 | } else { |
190f68c5 | 6456 | crtc_state->dpll_hw_state.fp1 = fp; |
a7516a05 JB |
6457 | } |
6458 | } | |
6459 | ||
5e69f97f CML |
6460 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
6461 | pipe) | |
89b667f8 JB |
6462 | { |
6463 | u32 reg_val; | |
6464 | ||
6465 | /* | |
6466 | * PLLB opamp always calibrates to max value of 0x3f, force enable it | |
6467 | * and set it to a reasonable value instead. | |
6468 | */ | |
ab3c759a | 6469 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
89b667f8 JB |
6470 | reg_val &= 0xffffff00; |
6471 | reg_val |= 0x00000030; | |
ab3c759a | 6472 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
89b667f8 | 6473 | |
ab3c759a | 6474 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
ed58570f ID |
6475 | reg_val &= 0x00ffffff; |
6476 | reg_val |= 0x8c000000; | |
ab3c759a | 6477 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
89b667f8 | 6478 | |
ab3c759a | 6479 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
89b667f8 | 6480 | reg_val &= 0xffffff00; |
ab3c759a | 6481 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
89b667f8 | 6482 | |
ab3c759a | 6483 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
89b667f8 JB |
6484 | reg_val &= 0x00ffffff; |
6485 | reg_val |= 0xb0000000; | |
ab3c759a | 6486 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
89b667f8 JB |
6487 | } |
6488 | ||
b551842d DV |
6489 | static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc, |
6490 | struct intel_link_m_n *m_n) | |
6491 | { | |
6492 | struct drm_device *dev = crtc->base.dev; | |
fac5e23e | 6493 | struct drm_i915_private *dev_priv = to_i915(dev); |
b551842d DV |
6494 | int pipe = crtc->pipe; |
6495 | ||
e3b95f1e DV |
6496 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
6497 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); | |
6498 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); | |
6499 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); | |
b551842d DV |
6500 | } |
6501 | ||
6502 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, | |
f769cd24 VK |
6503 | struct intel_link_m_n *m_n, |
6504 | struct intel_link_m_n *m2_n2) | |
b551842d | 6505 | { |
6315b5d3 | 6506 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
b551842d | 6507 | int pipe = crtc->pipe; |
6e3c9717 | 6508 | enum transcoder transcoder = crtc->config->cpu_transcoder; |
b551842d | 6509 | |
6315b5d3 | 6510 | if (INTEL_GEN(dev_priv) >= 5) { |
b551842d DV |
6511 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); |
6512 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); | |
6513 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); | |
6514 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); | |
f769cd24 VK |
6515 | /* M2_N2 registers to be set only for gen < 8 (M2_N2 available |
6516 | * for gen < 8) and if DRRS is supported (to make sure the | |
6517 | * registers are not unnecessarily accessed). | |
6518 | */ | |
920a14b2 TU |
6519 | if (m2_n2 && (IS_CHERRYVIEW(dev_priv) || |
6520 | INTEL_GEN(dev_priv) < 8) && crtc->config->has_drrs) { | |
f769cd24 VK |
6521 | I915_WRITE(PIPE_DATA_M2(transcoder), |
6522 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); | |
6523 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); | |
6524 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); | |
6525 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); | |
6526 | } | |
b551842d | 6527 | } else { |
e3b95f1e DV |
6528 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
6529 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); | |
6530 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); | |
6531 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); | |
b551842d DV |
6532 | } |
6533 | } | |
6534 | ||
fe3cd48d | 6535 | void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n) |
03afc4a2 | 6536 | { |
fe3cd48d R |
6537 | struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL; |
6538 | ||
6539 | if (m_n == M1_N1) { | |
6540 | dp_m_n = &crtc->config->dp_m_n; | |
6541 | dp_m2_n2 = &crtc->config->dp_m2_n2; | |
6542 | } else if (m_n == M2_N2) { | |
6543 | ||
6544 | /* | |
6545 | * M2_N2 registers are not supported. Hence m2_n2 divider value | |
6546 | * needs to be programmed into M1_N1. | |
6547 | */ | |
6548 | dp_m_n = &crtc->config->dp_m2_n2; | |
6549 | } else { | |
6550 | DRM_ERROR("Unsupported divider value\n"); | |
6551 | return; | |
6552 | } | |
6553 | ||
6e3c9717 ACO |
6554 | if (crtc->config->has_pch_encoder) |
6555 | intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n); | |
03afc4a2 | 6556 | else |
fe3cd48d | 6557 | intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2); |
03afc4a2 DV |
6558 | } |
6559 | ||
251ac862 DV |
6560 | static void vlv_compute_dpll(struct intel_crtc *crtc, |
6561 | struct intel_crtc_state *pipe_config) | |
bdd4b6a6 | 6562 | { |
03ed5cbf | 6563 | pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV | |
cd2d34d9 | 6564 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
03ed5cbf VS |
6565 | if (crtc->pipe != PIPE_A) |
6566 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
bdd4b6a6 | 6567 | |
cd2d34d9 | 6568 | /* DPLL not used with DSI, but still need the rest set up */ |
d7edc4e5 | 6569 | if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI)) |
cd2d34d9 VS |
6570 | pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE | |
6571 | DPLL_EXT_BUFFER_ENABLE_VLV; | |
6572 | ||
03ed5cbf VS |
6573 | pipe_config->dpll_hw_state.dpll_md = |
6574 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; | |
6575 | } | |
bdd4b6a6 | 6576 | |
03ed5cbf VS |
6577 | static void chv_compute_dpll(struct intel_crtc *crtc, |
6578 | struct intel_crtc_state *pipe_config) | |
6579 | { | |
6580 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV | | |
cd2d34d9 | 6581 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
03ed5cbf VS |
6582 | if (crtc->pipe != PIPE_A) |
6583 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; | |
6584 | ||
cd2d34d9 | 6585 | /* DPLL not used with DSI, but still need the rest set up */ |
d7edc4e5 | 6586 | if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI)) |
cd2d34d9 VS |
6587 | pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE; |
6588 | ||
03ed5cbf VS |
6589 | pipe_config->dpll_hw_state.dpll_md = |
6590 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; | |
bdd4b6a6 DV |
6591 | } |
6592 | ||
d288f65f | 6593 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 6594 | const struct intel_crtc_state *pipe_config) |
a0c4da24 | 6595 | { |
f47709a9 | 6596 | struct drm_device *dev = crtc->base.dev; |
fac5e23e | 6597 | struct drm_i915_private *dev_priv = to_i915(dev); |
cd2d34d9 | 6598 | enum pipe pipe = crtc->pipe; |
bdd4b6a6 | 6599 | u32 mdiv; |
a0c4da24 | 6600 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
bdd4b6a6 | 6601 | u32 coreclk, reg_val; |
a0c4da24 | 6602 | |
cd2d34d9 VS |
6603 | /* Enable Refclk */ |
6604 | I915_WRITE(DPLL(pipe), | |
6605 | pipe_config->dpll_hw_state.dpll & | |
6606 | ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV)); | |
6607 | ||
6608 | /* No need to actually set up the DPLL with DSI */ | |
6609 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) | |
6610 | return; | |
6611 | ||
a580516d | 6612 | mutex_lock(&dev_priv->sb_lock); |
09153000 | 6613 | |
d288f65f VS |
6614 | bestn = pipe_config->dpll.n; |
6615 | bestm1 = pipe_config->dpll.m1; | |
6616 | bestm2 = pipe_config->dpll.m2; | |
6617 | bestp1 = pipe_config->dpll.p1; | |
6618 | bestp2 = pipe_config->dpll.p2; | |
a0c4da24 | 6619 | |
89b667f8 JB |
6620 | /* See eDP HDMI DPIO driver vbios notes doc */ |
6621 | ||
6622 | /* PLL B needs special handling */ | |
bdd4b6a6 | 6623 | if (pipe == PIPE_B) |
5e69f97f | 6624 | vlv_pllb_recal_opamp(dev_priv, pipe); |
89b667f8 JB |
6625 | |
6626 | /* Set up Tx target for periodic Rcomp update */ | |
ab3c759a | 6627 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
89b667f8 JB |
6628 | |
6629 | /* Disable target IRef on PLL */ | |
ab3c759a | 6630 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
89b667f8 | 6631 | reg_val &= 0x00ffffff; |
ab3c759a | 6632 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
89b667f8 JB |
6633 | |
6634 | /* Disable fast lock */ | |
ab3c759a | 6635 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
89b667f8 JB |
6636 | |
6637 | /* Set idtafcrecal before PLL is enabled */ | |
a0c4da24 JB |
6638 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
6639 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); | |
6640 | mdiv |= ((bestn << DPIO_N_SHIFT)); | |
a0c4da24 | 6641 | mdiv |= (1 << DPIO_K_SHIFT); |
7df5080b JB |
6642 | |
6643 | /* | |
6644 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, | |
6645 | * but we don't support that). | |
6646 | * Note: don't use the DAC post divider as it seems unstable. | |
6647 | */ | |
6648 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); | |
ab3c759a | 6649 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
a0c4da24 | 6650 | |
a0c4da24 | 6651 | mdiv |= DPIO_ENABLE_CALIBRATION; |
ab3c759a | 6652 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
a0c4da24 | 6653 | |
89b667f8 | 6654 | /* Set HBR and RBR LPF coefficients */ |
d288f65f | 6655 | if (pipe_config->port_clock == 162000 || |
2d84d2b3 VS |
6656 | intel_crtc_has_type(crtc->config, INTEL_OUTPUT_ANALOG) || |
6657 | intel_crtc_has_type(crtc->config, INTEL_OUTPUT_HDMI)) | |
ab3c759a | 6658 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
885b0120 | 6659 | 0x009f0003); |
89b667f8 | 6660 | else |
ab3c759a | 6661 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
89b667f8 JB |
6662 | 0x00d0000f); |
6663 | ||
37a5650b | 6664 | if (intel_crtc_has_dp_encoder(pipe_config)) { |
89b667f8 | 6665 | /* Use SSC source */ |
bdd4b6a6 | 6666 | if (pipe == PIPE_A) |
ab3c759a | 6667 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
6668 | 0x0df40000); |
6669 | else | |
ab3c759a | 6670 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
6671 | 0x0df70000); |
6672 | } else { /* HDMI or VGA */ | |
6673 | /* Use bend source */ | |
bdd4b6a6 | 6674 | if (pipe == PIPE_A) |
ab3c759a | 6675 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
6676 | 0x0df70000); |
6677 | else | |
ab3c759a | 6678 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
89b667f8 JB |
6679 | 0x0df40000); |
6680 | } | |
a0c4da24 | 6681 | |
ab3c759a | 6682 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
89b667f8 | 6683 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
2210ce7f | 6684 | if (intel_crtc_has_dp_encoder(crtc->config)) |
89b667f8 | 6685 | coreclk |= 0x01000000; |
ab3c759a | 6686 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
a0c4da24 | 6687 | |
ab3c759a | 6688 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
a580516d | 6689 | mutex_unlock(&dev_priv->sb_lock); |
a0c4da24 JB |
6690 | } |
6691 | ||
d288f65f | 6692 | static void chv_prepare_pll(struct intel_crtc *crtc, |
5cec258b | 6693 | const struct intel_crtc_state *pipe_config) |
9d556c99 CML |
6694 | { |
6695 | struct drm_device *dev = crtc->base.dev; | |
fac5e23e | 6696 | struct drm_i915_private *dev_priv = to_i915(dev); |
cd2d34d9 | 6697 | enum pipe pipe = crtc->pipe; |
9d556c99 | 6698 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
9cbe40c1 | 6699 | u32 loopfilter, tribuf_calcntr; |
9d556c99 | 6700 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
a945ce7e | 6701 | u32 dpio_val; |
9cbe40c1 | 6702 | int vco; |
9d556c99 | 6703 | |
cd2d34d9 VS |
6704 | /* Enable Refclk and SSC */ |
6705 | I915_WRITE(DPLL(pipe), | |
6706 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); | |
6707 | ||
6708 | /* No need to actually set up the DPLL with DSI */ | |
6709 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) | |
6710 | return; | |
6711 | ||
d288f65f VS |
6712 | bestn = pipe_config->dpll.n; |
6713 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; | |
6714 | bestm1 = pipe_config->dpll.m1; | |
6715 | bestm2 = pipe_config->dpll.m2 >> 22; | |
6716 | bestp1 = pipe_config->dpll.p1; | |
6717 | bestp2 = pipe_config->dpll.p2; | |
9cbe40c1 | 6718 | vco = pipe_config->dpll.vco; |
a945ce7e | 6719 | dpio_val = 0; |
9cbe40c1 | 6720 | loopfilter = 0; |
9d556c99 | 6721 | |
a580516d | 6722 | mutex_lock(&dev_priv->sb_lock); |
9d556c99 | 6723 | |
9d556c99 CML |
6724 | /* p1 and p2 divider */ |
6725 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), | |
6726 | 5 << DPIO_CHV_S1_DIV_SHIFT | | |
6727 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | | |
6728 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | | |
6729 | 1 << DPIO_CHV_K_DIV_SHIFT); | |
6730 | ||
6731 | /* Feedback post-divider - m2 */ | |
6732 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); | |
6733 | ||
6734 | /* Feedback refclk divider - n and m1 */ | |
6735 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), | |
6736 | DPIO_CHV_M1_DIV_BY_2 | | |
6737 | 1 << DPIO_CHV_N_DIV_SHIFT); | |
6738 | ||
6739 | /* M2 fraction division */ | |
25a25dfc | 6740 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac); |
9d556c99 CML |
6741 | |
6742 | /* M2 fraction division enable */ | |
a945ce7e VP |
6743 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
6744 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); | |
6745 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); | |
6746 | if (bestm2_frac) | |
6747 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; | |
6748 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val); | |
9d556c99 | 6749 | |
de3a0fde VP |
6750 | /* Program digital lock detect threshold */ |
6751 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); | |
6752 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | | |
6753 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); | |
6754 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); | |
6755 | if (!bestm2_frac) | |
6756 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; | |
6757 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); | |
6758 | ||
9d556c99 | 6759 | /* Loop filter */ |
9cbe40c1 VP |
6760 | if (vco == 5400000) { |
6761 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); | |
6762 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); | |
6763 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
6764 | tribuf_calcntr = 0x9; | |
6765 | } else if (vco <= 6200000) { | |
6766 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); | |
6767 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); | |
6768 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
6769 | tribuf_calcntr = 0x9; | |
6770 | } else if (vco <= 6480000) { | |
6771 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); | |
6772 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); | |
6773 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
6774 | tribuf_calcntr = 0x8; | |
6775 | } else { | |
6776 | /* Not supported. Apply the same limits as in the max case */ | |
6777 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); | |
6778 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); | |
6779 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); | |
6780 | tribuf_calcntr = 0; | |
6781 | } | |
9d556c99 CML |
6782 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
6783 | ||
968040b2 | 6784 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
9cbe40c1 VP |
6785 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
6786 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); | |
6787 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); | |
6788 | ||
9d556c99 CML |
6789 | /* AFC Recal */ |
6790 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), | |
6791 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | | |
6792 | DPIO_AFC_RECAL); | |
6793 | ||
a580516d | 6794 | mutex_unlock(&dev_priv->sb_lock); |
9d556c99 CML |
6795 | } |
6796 | ||
d288f65f VS |
6797 | /** |
6798 | * vlv_force_pll_on - forcibly enable just the PLL | |
6799 | * @dev_priv: i915 private structure | |
6800 | * @pipe: pipe PLL to enable | |
6801 | * @dpll: PLL configuration | |
6802 | * | |
6803 | * Enable the PLL for @pipe using the supplied @dpll config. To be used | |
6804 | * in cases where we need the PLL enabled even when @pipe is not going to | |
6805 | * be enabled. | |
6806 | */ | |
30ad9814 | 6807 | int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe, |
3f36b937 | 6808 | const struct dpll *dpll) |
d288f65f | 6809 | { |
b91eb5cc | 6810 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
3f36b937 TU |
6811 | struct intel_crtc_state *pipe_config; |
6812 | ||
6813 | pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); | |
6814 | if (!pipe_config) | |
6815 | return -ENOMEM; | |
6816 | ||
6817 | pipe_config->base.crtc = &crtc->base; | |
6818 | pipe_config->pixel_multiplier = 1; | |
6819 | pipe_config->dpll = *dpll; | |
d288f65f | 6820 | |
30ad9814 | 6821 | if (IS_CHERRYVIEW(dev_priv)) { |
3f36b937 TU |
6822 | chv_compute_dpll(crtc, pipe_config); |
6823 | chv_prepare_pll(crtc, pipe_config); | |
6824 | chv_enable_pll(crtc, pipe_config); | |
d288f65f | 6825 | } else { |
3f36b937 TU |
6826 | vlv_compute_dpll(crtc, pipe_config); |
6827 | vlv_prepare_pll(crtc, pipe_config); | |
6828 | vlv_enable_pll(crtc, pipe_config); | |
d288f65f | 6829 | } |
3f36b937 TU |
6830 | |
6831 | kfree(pipe_config); | |
6832 | ||
6833 | return 0; | |
d288f65f VS |
6834 | } |
6835 | ||
6836 | /** | |
6837 | * vlv_force_pll_off - forcibly disable just the PLL | |
6838 | * @dev_priv: i915 private structure | |
6839 | * @pipe: pipe PLL to disable | |
6840 | * | |
6841 | * Disable the PLL for @pipe. To be used in cases where we need | |
6842 | * the PLL enabled even when @pipe is not going to be enabled. | |
6843 | */ | |
30ad9814 | 6844 | void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe) |
d288f65f | 6845 | { |
30ad9814 VS |
6846 | if (IS_CHERRYVIEW(dev_priv)) |
6847 | chv_disable_pll(dev_priv, pipe); | |
d288f65f | 6848 | else |
30ad9814 | 6849 | vlv_disable_pll(dev_priv, pipe); |
d288f65f VS |
6850 | } |
6851 | ||
251ac862 DV |
6852 | static void i9xx_compute_dpll(struct intel_crtc *crtc, |
6853 | struct intel_crtc_state *crtc_state, | |
9e2c8475 | 6854 | struct dpll *reduced_clock) |
eb1cbe48 | 6855 | { |
9b1e14f4 | 6856 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
eb1cbe48 | 6857 | u32 dpll; |
190f68c5 | 6858 | struct dpll *clock = &crtc_state->dpll; |
eb1cbe48 | 6859 | |
190f68c5 | 6860 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
2a8f64ca | 6861 | |
eb1cbe48 DV |
6862 | dpll = DPLL_VGA_MODE_DIS; |
6863 | ||
2d84d2b3 | 6864 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) |
eb1cbe48 DV |
6865 | dpll |= DPLLB_MODE_LVDS; |
6866 | else | |
6867 | dpll |= DPLLB_MODE_DAC_SERIAL; | |
6cc5f341 | 6868 | |
73f67aa8 JN |
6869 | if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) || |
6870 | IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) { | |
190f68c5 | 6871 | dpll |= (crtc_state->pixel_multiplier - 1) |
198a037f | 6872 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
eb1cbe48 | 6873 | } |
198a037f | 6874 | |
3d6e9ee0 VS |
6875 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) || |
6876 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) | |
4a33e48d | 6877 | dpll |= DPLL_SDVO_HIGH_SPEED; |
198a037f | 6878 | |
37a5650b | 6879 | if (intel_crtc_has_dp_encoder(crtc_state)) |
4a33e48d | 6880 | dpll |= DPLL_SDVO_HIGH_SPEED; |
eb1cbe48 DV |
6881 | |
6882 | /* compute bitmask from p1 value */ | |
9b1e14f4 | 6883 | if (IS_PINEVIEW(dev_priv)) |
eb1cbe48 DV |
6884 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; |
6885 | else { | |
6886 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
9beb5fea | 6887 | if (IS_G4X(dev_priv) && reduced_clock) |
eb1cbe48 DV |
6888 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
6889 | } | |
6890 | switch (clock->p2) { | |
6891 | case 5: | |
6892 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; | |
6893 | break; | |
6894 | case 7: | |
6895 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; | |
6896 | break; | |
6897 | case 10: | |
6898 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; | |
6899 | break; | |
6900 | case 14: | |
6901 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; | |
6902 | break; | |
6903 | } | |
9b1e14f4 | 6904 | if (INTEL_GEN(dev_priv) >= 4) |
eb1cbe48 DV |
6905 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); |
6906 | ||
190f68c5 | 6907 | if (crtc_state->sdvo_tv_clock) |
eb1cbe48 | 6908 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
2d84d2b3 | 6909 | else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
ceb41007 | 6910 | intel_panel_use_ssc(dev_priv)) |
eb1cbe48 DV |
6911 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
6912 | else | |
6913 | dpll |= PLL_REF_INPUT_DREFCLK; | |
6914 | ||
6915 | dpll |= DPLL_VCO_ENABLE; | |
190f68c5 | 6916 | crtc_state->dpll_hw_state.dpll = dpll; |
8bcc2795 | 6917 | |
9b1e14f4 | 6918 | if (INTEL_GEN(dev_priv) >= 4) { |
190f68c5 | 6919 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
ef1b460d | 6920 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
190f68c5 | 6921 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
eb1cbe48 DV |
6922 | } |
6923 | } | |
6924 | ||
251ac862 DV |
6925 | static void i8xx_compute_dpll(struct intel_crtc *crtc, |
6926 | struct intel_crtc_state *crtc_state, | |
9e2c8475 | 6927 | struct dpll *reduced_clock) |
eb1cbe48 | 6928 | { |
f47709a9 | 6929 | struct drm_device *dev = crtc->base.dev; |
fac5e23e | 6930 | struct drm_i915_private *dev_priv = to_i915(dev); |
eb1cbe48 | 6931 | u32 dpll; |
190f68c5 | 6932 | struct dpll *clock = &crtc_state->dpll; |
eb1cbe48 | 6933 | |
190f68c5 | 6934 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
2a8f64ca | 6935 | |
eb1cbe48 DV |
6936 | dpll = DPLL_VGA_MODE_DIS; |
6937 | ||
2d84d2b3 | 6938 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
eb1cbe48 DV |
6939 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
6940 | } else { | |
6941 | if (clock->p1 == 2) | |
6942 | dpll |= PLL_P1_DIVIDE_BY_TWO; | |
6943 | else | |
6944 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; | |
6945 | if (clock->p2 == 4) | |
6946 | dpll |= PLL_P2_DIVIDE_BY_4; | |
6947 | } | |
6948 | ||
50a0bc90 TU |
6949 | if (!IS_I830(dev_priv) && |
6950 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) | |
4a33e48d DV |
6951 | dpll |= DPLL_DVO_2X_MODE; |
6952 | ||
2d84d2b3 | 6953 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
ceb41007 | 6954 | intel_panel_use_ssc(dev_priv)) |
eb1cbe48 DV |
6955 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
6956 | else | |
6957 | dpll |= PLL_REF_INPUT_DREFCLK; | |
6958 | ||
6959 | dpll |= DPLL_VCO_ENABLE; | |
190f68c5 | 6960 | crtc_state->dpll_hw_state.dpll = dpll; |
eb1cbe48 DV |
6961 | } |
6962 | ||
8a654f3b | 6963 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc) |
b0e77b9c | 6964 | { |
6315b5d3 | 6965 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
b0e77b9c | 6966 | enum pipe pipe = intel_crtc->pipe; |
6e3c9717 | 6967 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
7c5f93b0 | 6968 | const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode; |
1caea6e9 VS |
6969 | uint32_t crtc_vtotal, crtc_vblank_end; |
6970 | int vsyncshift = 0; | |
4d8a62ea DV |
6971 | |
6972 | /* We need to be careful not to changed the adjusted mode, for otherwise | |
6973 | * the hw state checker will get angry at the mismatch. */ | |
6974 | crtc_vtotal = adjusted_mode->crtc_vtotal; | |
6975 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; | |
b0e77b9c | 6976 | |
609aeaca | 6977 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
b0e77b9c | 6978 | /* the chip adds 2 halflines automatically */ |
4d8a62ea DV |
6979 | crtc_vtotal -= 1; |
6980 | crtc_vblank_end -= 1; | |
609aeaca | 6981 | |
2d84d2b3 | 6982 | if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO)) |
609aeaca VS |
6983 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
6984 | else | |
6985 | vsyncshift = adjusted_mode->crtc_hsync_start - | |
6986 | adjusted_mode->crtc_htotal / 2; | |
1caea6e9 VS |
6987 | if (vsyncshift < 0) |
6988 | vsyncshift += adjusted_mode->crtc_htotal; | |
b0e77b9c PZ |
6989 | } |
6990 | ||
6315b5d3 | 6991 | if (INTEL_GEN(dev_priv) > 3) |
fe2b8f9d | 6992 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
b0e77b9c | 6993 | |
fe2b8f9d | 6994 | I915_WRITE(HTOTAL(cpu_transcoder), |
b0e77b9c PZ |
6995 | (adjusted_mode->crtc_hdisplay - 1) | |
6996 | ((adjusted_mode->crtc_htotal - 1) << 16)); | |
fe2b8f9d | 6997 | I915_WRITE(HBLANK(cpu_transcoder), |
b0e77b9c PZ |
6998 | (adjusted_mode->crtc_hblank_start - 1) | |
6999 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); | |
fe2b8f9d | 7000 | I915_WRITE(HSYNC(cpu_transcoder), |
b0e77b9c PZ |
7001 | (adjusted_mode->crtc_hsync_start - 1) | |
7002 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); | |
7003 | ||
fe2b8f9d | 7004 | I915_WRITE(VTOTAL(cpu_transcoder), |
b0e77b9c | 7005 | (adjusted_mode->crtc_vdisplay - 1) | |
4d8a62ea | 7006 | ((crtc_vtotal - 1) << 16)); |
fe2b8f9d | 7007 | I915_WRITE(VBLANK(cpu_transcoder), |
b0e77b9c | 7008 | (adjusted_mode->crtc_vblank_start - 1) | |
4d8a62ea | 7009 | ((crtc_vblank_end - 1) << 16)); |
fe2b8f9d | 7010 | I915_WRITE(VSYNC(cpu_transcoder), |
b0e77b9c PZ |
7011 | (adjusted_mode->crtc_vsync_start - 1) | |
7012 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); | |
7013 | ||
b5e508d4 PZ |
7014 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
7015 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is | |
7016 | * documented on the DDI_FUNC_CTL register description, EDP Input Select | |
7017 | * bits. */ | |
772c2a51 | 7018 | if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP && |
b5e508d4 PZ |
7019 | (pipe == PIPE_B || pipe == PIPE_C)) |
7020 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); | |
7021 | ||
bc58be60 JN |
7022 | } |
7023 | ||
7024 | static void intel_set_pipe_src_size(struct intel_crtc *intel_crtc) | |
7025 | { | |
7026 | struct drm_device *dev = intel_crtc->base.dev; | |
fac5e23e | 7027 | struct drm_i915_private *dev_priv = to_i915(dev); |
bc58be60 JN |
7028 | enum pipe pipe = intel_crtc->pipe; |
7029 | ||
b0e77b9c PZ |
7030 | /* pipesrc controls the size that is scaled from, which should |
7031 | * always be the user's requested size. | |
7032 | */ | |
7033 | I915_WRITE(PIPESRC(pipe), | |
6e3c9717 ACO |
7034 | ((intel_crtc->config->pipe_src_w - 1) << 16) | |
7035 | (intel_crtc->config->pipe_src_h - 1)); | |
b0e77b9c PZ |
7036 | } |
7037 | ||
1bd1bd80 | 7038 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
5cec258b | 7039 | struct intel_crtc_state *pipe_config) |
1bd1bd80 DV |
7040 | { |
7041 | struct drm_device *dev = crtc->base.dev; | |
fac5e23e | 7042 | struct drm_i915_private *dev_priv = to_i915(dev); |
1bd1bd80 DV |
7043 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
7044 | uint32_t tmp; | |
7045 | ||
7046 | tmp = I915_READ(HTOTAL(cpu_transcoder)); | |
2d112de7 ACO |
7047 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
7048 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7049 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
2d112de7 ACO |
7050 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
7051 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7052 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
2d112de7 ACO |
7053 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
7054 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 DV |
7055 | |
7056 | tmp = I915_READ(VTOTAL(cpu_transcoder)); | |
2d112de7 ACO |
7057 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
7058 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7059 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
2d112de7 ACO |
7060 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
7061 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 | 7062 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
2d112de7 ACO |
7063 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
7064 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; | |
1bd1bd80 DV |
7065 | |
7066 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { | |
2d112de7 ACO |
7067 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
7068 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; | |
7069 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; | |
1bd1bd80 | 7070 | } |
bc58be60 JN |
7071 | } |
7072 | ||
7073 | static void intel_get_pipe_src_size(struct intel_crtc *crtc, | |
7074 | struct intel_crtc_state *pipe_config) | |
7075 | { | |
7076 | struct drm_device *dev = crtc->base.dev; | |
fac5e23e | 7077 | struct drm_i915_private *dev_priv = to_i915(dev); |
bc58be60 | 7078 | u32 tmp; |
1bd1bd80 DV |
7079 | |
7080 | tmp = I915_READ(PIPESRC(crtc->pipe)); | |
37327abd VS |
7081 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
7082 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; | |
7083 | ||
2d112de7 ACO |
7084 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
7085 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; | |
1bd1bd80 DV |
7086 | } |
7087 | ||
f6a83288 | 7088 | void intel_mode_from_pipe_config(struct drm_display_mode *mode, |
5cec258b | 7089 | struct intel_crtc_state *pipe_config) |
babea61d | 7090 | { |
2d112de7 ACO |
7091 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
7092 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; | |
7093 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; | |
7094 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; | |
babea61d | 7095 | |
2d112de7 ACO |
7096 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
7097 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; | |
7098 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; | |
7099 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; | |
babea61d | 7100 | |
2d112de7 | 7101 | mode->flags = pipe_config->base.adjusted_mode.flags; |
cd13f5ab | 7102 | mode->type = DRM_MODE_TYPE_DRIVER; |
babea61d | 7103 | |
2d112de7 | 7104 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
cd13f5ab ML |
7105 | |
7106 | mode->hsync = drm_mode_hsync(mode); | |
7107 | mode->vrefresh = drm_mode_vrefresh(mode); | |
7108 | drm_mode_set_name(mode); | |
babea61d JB |
7109 | } |
7110 | ||
84b046f3 DV |
7111 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc) |
7112 | { | |
6315b5d3 | 7113 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
84b046f3 DV |
7114 | uint32_t pipeconf; |
7115 | ||
9f11a9e4 | 7116 | pipeconf = 0; |
84b046f3 | 7117 | |
e56134bc VS |
7118 | /* we keep both pipes enabled on 830 */ |
7119 | if (IS_I830(dev_priv)) | |
b6b5d049 | 7120 | pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE; |
67c72a12 | 7121 | |
6e3c9717 | 7122 | if (intel_crtc->config->double_wide) |
cf532bb2 | 7123 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
84b046f3 | 7124 | |
ff9ce46e | 7125 | /* only g4x and later have fancy bpc/dither controls */ |
9beb5fea TU |
7126 | if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
7127 | IS_CHERRYVIEW(dev_priv)) { | |
ff9ce46e | 7128 | /* Bspec claims that we can't use dithering for 30bpp pipes. */ |
6e3c9717 | 7129 | if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30) |
ff9ce46e | 7130 | pipeconf |= PIPECONF_DITHER_EN | |
84b046f3 | 7131 | PIPECONF_DITHER_TYPE_SP; |
84b046f3 | 7132 | |
6e3c9717 | 7133 | switch (intel_crtc->config->pipe_bpp) { |
ff9ce46e DV |
7134 | case 18: |
7135 | pipeconf |= PIPECONF_6BPC; | |
7136 | break; | |
7137 | case 24: | |
7138 | pipeconf |= PIPECONF_8BPC; | |
7139 | break; | |
7140 | case 30: | |
7141 | pipeconf |= PIPECONF_10BPC; | |
7142 | break; | |
7143 | default: | |
7144 | /* Case prevented by intel_choose_pipe_bpp_dither. */ | |
7145 | BUG(); | |
84b046f3 DV |
7146 | } |
7147 | } | |
7148 | ||
6e3c9717 | 7149 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { |
6315b5d3 | 7150 | if (INTEL_GEN(dev_priv) < 4 || |
2d84d2b3 | 7151 | intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO)) |
efc2cfff VS |
7152 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
7153 | else | |
7154 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; | |
7155 | } else | |
84b046f3 DV |
7156 | pipeconf |= PIPECONF_PROGRESSIVE; |
7157 | ||
920a14b2 | 7158 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
666a4537 | 7159 | intel_crtc->config->limited_color_range) |
9f11a9e4 | 7160 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
9c8e09b7 | 7161 | |
84b046f3 DV |
7162 | I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf); |
7163 | POSTING_READ(PIPECONF(intel_crtc->pipe)); | |
7164 | } | |
7165 | ||
81c97f52 ACO |
7166 | static int i8xx_crtc_compute_clock(struct intel_crtc *crtc, |
7167 | struct intel_crtc_state *crtc_state) | |
7168 | { | |
7169 | struct drm_device *dev = crtc->base.dev; | |
fac5e23e | 7170 | struct drm_i915_private *dev_priv = to_i915(dev); |
1b6f4958 | 7171 | const struct intel_limit *limit; |
81c97f52 ACO |
7172 | int refclk = 48000; |
7173 | ||
7174 | memset(&crtc_state->dpll_hw_state, 0, | |
7175 | sizeof(crtc_state->dpll_hw_state)); | |
7176 | ||
2d84d2b3 | 7177 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
81c97f52 ACO |
7178 | if (intel_panel_use_ssc(dev_priv)) { |
7179 | refclk = dev_priv->vbt.lvds_ssc_freq; | |
7180 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); | |
7181 | } | |
7182 | ||
7183 | limit = &intel_limits_i8xx_lvds; | |
2d84d2b3 | 7184 | } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) { |
81c97f52 ACO |
7185 | limit = &intel_limits_i8xx_dvo; |
7186 | } else { | |
7187 | limit = &intel_limits_i8xx_dac; | |
7188 | } | |
7189 | ||
7190 | if (!crtc_state->clock_set && | |
7191 | !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock, | |
7192 | refclk, NULL, &crtc_state->dpll)) { | |
7193 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); | |
7194 | return -EINVAL; | |
7195 | } | |
7196 | ||
7197 | i8xx_compute_dpll(crtc, crtc_state, NULL); | |
7198 | ||
7199 | return 0; | |
7200 | } | |
7201 | ||
19ec6693 ACO |
7202 | static int g4x_crtc_compute_clock(struct intel_crtc *crtc, |
7203 | struct intel_crtc_state *crtc_state) | |
7204 | { | |
7205 | struct drm_device *dev = crtc->base.dev; | |
fac5e23e | 7206 | struct drm_i915_private *dev_priv = to_i915(dev); |
1b6f4958 | 7207 | const struct intel_limit *limit; |
19ec6693 ACO |
7208 | int refclk = 96000; |
7209 | ||
7210 | memset(&crtc_state->dpll_hw_state, 0, | |
7211 | sizeof(crtc_state->dpll_hw_state)); | |
7212 | ||
2d84d2b3 | 7213 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
19ec6693 ACO |
7214 | if (intel_panel_use_ssc(dev_priv)) { |
7215 | refclk = dev_priv->vbt.lvds_ssc_freq; | |
7216 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); | |
7217 | } | |
7218 | ||
7219 | if (intel_is_dual_link_lvds(dev)) | |
7220 | limit = &intel_limits_g4x_dual_channel_lvds; | |
7221 | else | |
7222 | limit = &intel_limits_g4x_single_channel_lvds; | |
2d84d2b3 VS |
7223 | } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) || |
7224 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) { | |
19ec6693 | 7225 | limit = &intel_limits_g4x_hdmi; |
2d84d2b3 | 7226 | } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) { |
19ec6693 ACO |
7227 | limit = &intel_limits_g4x_sdvo; |
7228 | } else { | |
7229 | /* The option is for other outputs */ | |
7230 | limit = &intel_limits_i9xx_sdvo; | |
7231 | } | |
7232 | ||
7233 | if (!crtc_state->clock_set && | |
7234 | !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock, | |
7235 | refclk, NULL, &crtc_state->dpll)) { | |
7236 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); | |
7237 | return -EINVAL; | |
7238 | } | |
7239 | ||
7240 | i9xx_compute_dpll(crtc, crtc_state, NULL); | |
7241 | ||
7242 | return 0; | |
7243 | } | |
7244 | ||
70e8aa21 ACO |
7245 | static int pnv_crtc_compute_clock(struct intel_crtc *crtc, |
7246 | struct intel_crtc_state *crtc_state) | |
7247 | { | |
7248 | struct drm_device *dev = crtc->base.dev; | |
fac5e23e | 7249 | struct drm_i915_private *dev_priv = to_i915(dev); |
1b6f4958 | 7250 | const struct intel_limit *limit; |
70e8aa21 ACO |
7251 | int refclk = 96000; |
7252 | ||
7253 | memset(&crtc_state->dpll_hw_state, 0, | |
7254 | sizeof(crtc_state->dpll_hw_state)); | |
7255 | ||
2d84d2b3 | 7256 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
70e8aa21 ACO |
7257 | if (intel_panel_use_ssc(dev_priv)) { |
7258 | refclk = dev_priv->vbt.lvds_ssc_freq; | |
7259 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); | |
7260 | } | |
7261 | ||
7262 | limit = &intel_limits_pineview_lvds; | |
7263 | } else { | |
7264 | limit = &intel_limits_pineview_sdvo; | |
7265 | } | |
7266 | ||
7267 | if (!crtc_state->clock_set && | |
7268 | !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, | |
7269 | refclk, NULL, &crtc_state->dpll)) { | |
7270 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); | |
7271 | return -EINVAL; | |
7272 | } | |
7273 | ||
7274 | i9xx_compute_dpll(crtc, crtc_state, NULL); | |
7275 | ||
7276 | return 0; | |
7277 | } | |
7278 | ||
190f68c5 ACO |
7279 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
7280 | struct intel_crtc_state *crtc_state) | |
79e53945 | 7281 | { |
c7653199 | 7282 | struct drm_device *dev = crtc->base.dev; |
fac5e23e | 7283 | struct drm_i915_private *dev_priv = to_i915(dev); |
1b6f4958 | 7284 | const struct intel_limit *limit; |
81c97f52 | 7285 | int refclk = 96000; |
79e53945 | 7286 | |
dd3cd74a ACO |
7287 | memset(&crtc_state->dpll_hw_state, 0, |
7288 | sizeof(crtc_state->dpll_hw_state)); | |
7289 | ||
2d84d2b3 | 7290 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
70e8aa21 ACO |
7291 | if (intel_panel_use_ssc(dev_priv)) { |
7292 | refclk = dev_priv->vbt.lvds_ssc_freq; | |
7293 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); | |
7294 | } | |
43565a06 | 7295 | |
70e8aa21 ACO |
7296 | limit = &intel_limits_i9xx_lvds; |
7297 | } else { | |
7298 | limit = &intel_limits_i9xx_sdvo; | |
81c97f52 | 7299 | } |
79e53945 | 7300 | |
70e8aa21 ACO |
7301 | if (!crtc_state->clock_set && |
7302 | !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock, | |
7303 | refclk, NULL, &crtc_state->dpll)) { | |
7304 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); | |
7305 | return -EINVAL; | |
f47709a9 | 7306 | } |
7026d4ac | 7307 | |
81c97f52 | 7308 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
79e53945 | 7309 | |
c8f7a0db | 7310 | return 0; |
f564048e EA |
7311 | } |
7312 | ||
65b3d6a9 ACO |
7313 | static int chv_crtc_compute_clock(struct intel_crtc *crtc, |
7314 | struct intel_crtc_state *crtc_state) | |
7315 | { | |
7316 | int refclk = 100000; | |
1b6f4958 | 7317 | const struct intel_limit *limit = &intel_limits_chv; |
65b3d6a9 ACO |
7318 | |
7319 | memset(&crtc_state->dpll_hw_state, 0, | |
7320 | sizeof(crtc_state->dpll_hw_state)); | |
7321 | ||
65b3d6a9 ACO |
7322 | if (!crtc_state->clock_set && |
7323 | !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, | |
7324 | refclk, NULL, &crtc_state->dpll)) { | |
7325 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); | |
7326 | return -EINVAL; | |
7327 | } | |
7328 | ||
7329 | chv_compute_dpll(crtc, crtc_state); | |
7330 | ||
7331 | return 0; | |
7332 | } | |
7333 | ||
7334 | static int vlv_crtc_compute_clock(struct intel_crtc *crtc, | |
7335 | struct intel_crtc_state *crtc_state) | |
7336 | { | |
7337 | int refclk = 100000; | |
1b6f4958 | 7338 | const struct intel_limit *limit = &intel_limits_vlv; |
65b3d6a9 ACO |
7339 | |
7340 | memset(&crtc_state->dpll_hw_state, 0, | |
7341 | sizeof(crtc_state->dpll_hw_state)); | |
7342 | ||
65b3d6a9 ACO |
7343 | if (!crtc_state->clock_set && |
7344 | !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, | |
7345 | refclk, NULL, &crtc_state->dpll)) { | |
7346 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); | |
7347 | return -EINVAL; | |
7348 | } | |
7349 | ||
7350 | vlv_compute_dpll(crtc, crtc_state); | |
7351 | ||
7352 | return 0; | |
7353 | } | |
7354 | ||
2fa2fe9a | 7355 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 7356 | struct intel_crtc_state *pipe_config) |
2fa2fe9a | 7357 | { |
6315b5d3 | 7358 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
2fa2fe9a DV |
7359 | uint32_t tmp; |
7360 | ||
50a0bc90 TU |
7361 | if (INTEL_GEN(dev_priv) <= 3 && |
7362 | (IS_I830(dev_priv) || !IS_MOBILE(dev_priv))) | |
dc9e7dec VS |
7363 | return; |
7364 | ||
2fa2fe9a | 7365 | tmp = I915_READ(PFIT_CONTROL); |
06922821 DV |
7366 | if (!(tmp & PFIT_ENABLE)) |
7367 | return; | |
2fa2fe9a | 7368 | |
06922821 | 7369 | /* Check whether the pfit is attached to our pipe. */ |
6315b5d3 | 7370 | if (INTEL_GEN(dev_priv) < 4) { |
2fa2fe9a DV |
7371 | if (crtc->pipe != PIPE_B) |
7372 | return; | |
2fa2fe9a DV |
7373 | } else { |
7374 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) | |
7375 | return; | |
7376 | } | |
7377 | ||
06922821 | 7378 | pipe_config->gmch_pfit.control = tmp; |
2fa2fe9a | 7379 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
2fa2fe9a DV |
7380 | } |
7381 | ||
acbec814 | 7382 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 7383 | struct intel_crtc_state *pipe_config) |
acbec814 JB |
7384 | { |
7385 | struct drm_device *dev = crtc->base.dev; | |
fac5e23e | 7386 | struct drm_i915_private *dev_priv = to_i915(dev); |
acbec814 | 7387 | int pipe = pipe_config->cpu_transcoder; |
9e2c8475 | 7388 | struct dpll clock; |
acbec814 | 7389 | u32 mdiv; |
662c6ecb | 7390 | int refclk = 100000; |
acbec814 | 7391 | |
b521973b VS |
7392 | /* In case of DSI, DPLL will not be used */ |
7393 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) | |
f573de5a SK |
7394 | return; |
7395 | ||
a580516d | 7396 | mutex_lock(&dev_priv->sb_lock); |
ab3c759a | 7397 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
a580516d | 7398 | mutex_unlock(&dev_priv->sb_lock); |
acbec814 JB |
7399 | |
7400 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; | |
7401 | clock.m2 = mdiv & DPIO_M2DIV_MASK; | |
7402 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; | |
7403 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; | |
7404 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; | |
7405 | ||
dccbea3b | 7406 | pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock); |
acbec814 JB |
7407 | } |
7408 | ||
5724dbd1 DL |
7409 | static void |
7410 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, | |
7411 | struct intel_initial_plane_config *plane_config) | |
1ad292b5 JB |
7412 | { |
7413 | struct drm_device *dev = crtc->base.dev; | |
fac5e23e | 7414 | struct drm_i915_private *dev_priv = to_i915(dev); |
1ad292b5 JB |
7415 | u32 val, base, offset; |
7416 | int pipe = crtc->pipe, plane = crtc->plane; | |
7417 | int fourcc, pixel_format; | |
6761dd31 | 7418 | unsigned int aligned_height; |
b113d5ee | 7419 | struct drm_framebuffer *fb; |
1b842c89 | 7420 | struct intel_framebuffer *intel_fb; |
1ad292b5 | 7421 | |
42a7b088 DL |
7422 | val = I915_READ(DSPCNTR(plane)); |
7423 | if (!(val & DISPLAY_PLANE_ENABLE)) | |
7424 | return; | |
7425 | ||
d9806c9f | 7426 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 7427 | if (!intel_fb) { |
1ad292b5 JB |
7428 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
7429 | return; | |
7430 | } | |
7431 | ||
1b842c89 DL |
7432 | fb = &intel_fb->base; |
7433 | ||
d2e9f5fc VS |
7434 | fb->dev = dev; |
7435 | ||
6315b5d3 | 7436 | if (INTEL_GEN(dev_priv) >= 4) { |
18c5247e | 7437 | if (val & DISPPLANE_TILED) { |
49af449b | 7438 | plane_config->tiling = I915_TILING_X; |
bae781b2 | 7439 | fb->modifier = I915_FORMAT_MOD_X_TILED; |
18c5247e DV |
7440 | } |
7441 | } | |
1ad292b5 JB |
7442 | |
7443 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; | |
b35d63fa | 7444 | fourcc = i9xx_format_to_fourcc(pixel_format); |
2f3f4763 | 7445 | fb->format = drm_format_info(fourcc); |
1ad292b5 | 7446 | |
6315b5d3 | 7447 | if (INTEL_GEN(dev_priv) >= 4) { |
49af449b | 7448 | if (plane_config->tiling) |
1ad292b5 JB |
7449 | offset = I915_READ(DSPTILEOFF(plane)); |
7450 | else | |
7451 | offset = I915_READ(DSPLINOFF(plane)); | |
7452 | base = I915_READ(DSPSURF(plane)) & 0xfffff000; | |
7453 | } else { | |
7454 | base = I915_READ(DSPADDR(plane)); | |
7455 | } | |
7456 | plane_config->base = base; | |
7457 | ||
7458 | val = I915_READ(PIPESRC(pipe)); | |
b113d5ee DL |
7459 | fb->width = ((val >> 16) & 0xfff) + 1; |
7460 | fb->height = ((val >> 0) & 0xfff) + 1; | |
1ad292b5 JB |
7461 | |
7462 | val = I915_READ(DSPSTRIDE(pipe)); | |
b113d5ee | 7463 | fb->pitches[0] = val & 0xffffffc0; |
1ad292b5 | 7464 | |
d88c4afd | 7465 | aligned_height = intel_fb_align_height(fb, 0, fb->height); |
1ad292b5 | 7466 | |
f37b5c2b | 7467 | plane_config->size = fb->pitches[0] * aligned_height; |
1ad292b5 | 7468 | |
2844a921 DL |
7469 | DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
7470 | pipe_name(pipe), plane, fb->width, fb->height, | |
272725c7 | 7471 | fb->format->cpp[0] * 8, base, fb->pitches[0], |
2844a921 | 7472 | plane_config->size); |
1ad292b5 | 7473 | |
2d14030b | 7474 | plane_config->fb = intel_fb; |
1ad292b5 JB |
7475 | } |
7476 | ||
70b23a98 | 7477 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 7478 | struct intel_crtc_state *pipe_config) |
70b23a98 VS |
7479 | { |
7480 | struct drm_device *dev = crtc->base.dev; | |
fac5e23e | 7481 | struct drm_i915_private *dev_priv = to_i915(dev); |
70b23a98 VS |
7482 | int pipe = pipe_config->cpu_transcoder; |
7483 | enum dpio_channel port = vlv_pipe_to_channel(pipe); | |
9e2c8475 | 7484 | struct dpll clock; |
0d7b6b11 | 7485 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3; |
70b23a98 VS |
7486 | int refclk = 100000; |
7487 | ||
b521973b VS |
7488 | /* In case of DSI, DPLL will not be used */ |
7489 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) | |
7490 | return; | |
7491 | ||
a580516d | 7492 | mutex_lock(&dev_priv->sb_lock); |
70b23a98 VS |
7493 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
7494 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); | |
7495 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); | |
7496 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); | |
0d7b6b11 | 7497 | pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
a580516d | 7498 | mutex_unlock(&dev_priv->sb_lock); |
70b23a98 VS |
7499 | |
7500 | clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0; | |
0d7b6b11 ID |
7501 | clock.m2 = (pll_dw0 & 0xff) << 22; |
7502 | if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN) | |
7503 | clock.m2 |= pll_dw2 & 0x3fffff; | |
70b23a98 VS |
7504 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; |
7505 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; | |
7506 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; | |
7507 | ||
dccbea3b | 7508 | pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock); |
70b23a98 VS |
7509 | } |
7510 | ||
0e8ffe1b | 7511 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 7512 | struct intel_crtc_state *pipe_config) |
0e8ffe1b | 7513 | { |
6315b5d3 | 7514 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
1729050e | 7515 | enum intel_display_power_domain power_domain; |
0e8ffe1b | 7516 | uint32_t tmp; |
1729050e | 7517 | bool ret; |
0e8ffe1b | 7518 | |
1729050e ID |
7519 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
7520 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) | |
b5482bd0 ID |
7521 | return false; |
7522 | ||
e143a21c | 7523 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
8106ddbd | 7524 | pipe_config->shared_dpll = NULL; |
eccb140b | 7525 | |
1729050e ID |
7526 | ret = false; |
7527 | ||
0e8ffe1b DV |
7528 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
7529 | if (!(tmp & PIPECONF_ENABLE)) | |
1729050e | 7530 | goto out; |
0e8ffe1b | 7531 | |
9beb5fea TU |
7532 | if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
7533 | IS_CHERRYVIEW(dev_priv)) { | |
42571aef VS |
7534 | switch (tmp & PIPECONF_BPC_MASK) { |
7535 | case PIPECONF_6BPC: | |
7536 | pipe_config->pipe_bpp = 18; | |
7537 | break; | |
7538 | case PIPECONF_8BPC: | |
7539 | pipe_config->pipe_bpp = 24; | |
7540 | break; | |
7541 | case PIPECONF_10BPC: | |
7542 | pipe_config->pipe_bpp = 30; | |
7543 | break; | |
7544 | default: | |
7545 | break; | |
7546 | } | |
7547 | } | |
7548 | ||
920a14b2 | 7549 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
666a4537 | 7550 | (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
b5a9fa09 DV |
7551 | pipe_config->limited_color_range = true; |
7552 | ||
6315b5d3 | 7553 | if (INTEL_GEN(dev_priv) < 4) |
282740f7 VS |
7554 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; |
7555 | ||
1bd1bd80 | 7556 | intel_get_pipe_timings(crtc, pipe_config); |
bc58be60 | 7557 | intel_get_pipe_src_size(crtc, pipe_config); |
1bd1bd80 | 7558 | |
2fa2fe9a DV |
7559 | i9xx_get_pfit_config(crtc, pipe_config); |
7560 | ||
6315b5d3 | 7561 | if (INTEL_GEN(dev_priv) >= 4) { |
c231775c | 7562 | /* No way to read it out on pipes B and C */ |
920a14b2 | 7563 | if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A) |
c231775c VS |
7564 | tmp = dev_priv->chv_dpll_md[crtc->pipe]; |
7565 | else | |
7566 | tmp = I915_READ(DPLL_MD(crtc->pipe)); | |
6c49f241 DV |
7567 | pipe_config->pixel_multiplier = |
7568 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) | |
7569 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; | |
8bcc2795 | 7570 | pipe_config->dpll_hw_state.dpll_md = tmp; |
50a0bc90 | 7571 | } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) || |
73f67aa8 | 7572 | IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) { |
6c49f241 DV |
7573 | tmp = I915_READ(DPLL(crtc->pipe)); |
7574 | pipe_config->pixel_multiplier = | |
7575 | ((tmp & SDVO_MULTIPLIER_MASK) | |
7576 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; | |
7577 | } else { | |
7578 | /* Note that on i915G/GM the pixel multiplier is in the sdvo | |
7579 | * port and will be fixed up in the encoder->get_config | |
7580 | * function. */ | |
7581 | pipe_config->pixel_multiplier = 1; | |
7582 | } | |
8bcc2795 | 7583 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
920a14b2 | 7584 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) { |
1c4e0274 VS |
7585 | /* |
7586 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs | |
7587 | * on 830. Filter it out here so that we don't | |
7588 | * report errors due to that. | |
7589 | */ | |
50a0bc90 | 7590 | if (IS_I830(dev_priv)) |
1c4e0274 VS |
7591 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; |
7592 | ||
8bcc2795 DV |
7593 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
7594 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); | |
165e901c VS |
7595 | } else { |
7596 | /* Mask out read-only status bits. */ | |
7597 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | | |
7598 | DPLL_PORTC_READY_MASK | | |
7599 | DPLL_PORTB_READY_MASK); | |
8bcc2795 | 7600 | } |
6c49f241 | 7601 | |
920a14b2 | 7602 | if (IS_CHERRYVIEW(dev_priv)) |
70b23a98 | 7603 | chv_crtc_clock_get(crtc, pipe_config); |
11a914c2 | 7604 | else if (IS_VALLEYVIEW(dev_priv)) |
acbec814 JB |
7605 | vlv_crtc_clock_get(crtc, pipe_config); |
7606 | else | |
7607 | i9xx_crtc_clock_get(crtc, pipe_config); | |
18442d08 | 7608 | |
0f64614d VS |
7609 | /* |
7610 | * Normally the dotclock is filled in by the encoder .get_config() | |
7611 | * but in case the pipe is enabled w/o any ports we need a sane | |
7612 | * default. | |
7613 | */ | |
7614 | pipe_config->base.adjusted_mode.crtc_clock = | |
7615 | pipe_config->port_clock / pipe_config->pixel_multiplier; | |
7616 | ||
1729050e ID |
7617 | ret = true; |
7618 | ||
7619 | out: | |
7620 | intel_display_power_put(dev_priv, power_domain); | |
7621 | ||
7622 | return ret; | |
0e8ffe1b DV |
7623 | } |
7624 | ||
c39055b0 | 7625 | static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv) |
13d83a67 | 7626 | { |
13d83a67 | 7627 | struct intel_encoder *encoder; |
1c1a24d2 | 7628 | int i; |
74cfd7ac | 7629 | u32 val, final; |
13d83a67 | 7630 | bool has_lvds = false; |
199e5d79 | 7631 | bool has_cpu_edp = false; |
199e5d79 | 7632 | bool has_panel = false; |
99eb6a01 KP |
7633 | bool has_ck505 = false; |
7634 | bool can_ssc = false; | |
1c1a24d2 | 7635 | bool using_ssc_source = false; |
13d83a67 JB |
7636 | |
7637 | /* We need to take the global config into account */ | |
c39055b0 | 7638 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
199e5d79 KP |
7639 | switch (encoder->type) { |
7640 | case INTEL_OUTPUT_LVDS: | |
7641 | has_panel = true; | |
7642 | has_lvds = true; | |
7643 | break; | |
7644 | case INTEL_OUTPUT_EDP: | |
7645 | has_panel = true; | |
2de6905f | 7646 | if (enc_to_dig_port(&encoder->base)->port == PORT_A) |
199e5d79 KP |
7647 | has_cpu_edp = true; |
7648 | break; | |
6847d71b PZ |
7649 | default: |
7650 | break; | |
13d83a67 JB |
7651 | } |
7652 | } | |
7653 | ||
6e266956 | 7654 | if (HAS_PCH_IBX(dev_priv)) { |
41aa3448 | 7655 | has_ck505 = dev_priv->vbt.display_clock_mode; |
99eb6a01 KP |
7656 | can_ssc = has_ck505; |
7657 | } else { | |
7658 | has_ck505 = false; | |
7659 | can_ssc = true; | |
7660 | } | |
7661 | ||
1c1a24d2 L |
7662 | /* Check if any DPLLs are using the SSC source */ |
7663 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { | |
7664 | u32 temp = I915_READ(PCH_DPLL(i)); | |
7665 | ||
7666 | if (!(temp & DPLL_VCO_ENABLE)) | |
7667 | continue; | |
7668 | ||
7669 | if ((temp & PLL_REF_INPUT_MASK) == | |
7670 | PLLB_REF_INPUT_SPREADSPECTRUMIN) { | |
7671 | using_ssc_source = true; | |
7672 | break; | |
7673 | } | |
7674 | } | |
7675 | ||
7676 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n", | |
7677 | has_panel, has_lvds, has_ck505, using_ssc_source); | |
13d83a67 JB |
7678 | |
7679 | /* Ironlake: try to setup display ref clock before DPLL | |
7680 | * enabling. This is only under driver's control after | |
7681 | * PCH B stepping, previous chipset stepping should be | |
7682 | * ignoring this setting. | |
7683 | */ | |
74cfd7ac CW |
7684 | val = I915_READ(PCH_DREF_CONTROL); |
7685 | ||
7686 | /* As we must carefully and slowly disable/enable each source in turn, | |
7687 | * compute the final state we want first and check if we need to | |
7688 | * make any changes at all. | |
7689 | */ | |
7690 | final = val; | |
7691 | final &= ~DREF_NONSPREAD_SOURCE_MASK; | |
7692 | if (has_ck505) | |
7693 | final |= DREF_NONSPREAD_CK505_ENABLE; | |
7694 | else | |
7695 | final |= DREF_NONSPREAD_SOURCE_ENABLE; | |
7696 | ||
8c07eb68 | 7697 | final &= ~DREF_SSC_SOURCE_MASK; |
74cfd7ac | 7698 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
8c07eb68 | 7699 | final &= ~DREF_SSC1_ENABLE; |
74cfd7ac CW |
7700 | |
7701 | if (has_panel) { | |
7702 | final |= DREF_SSC_SOURCE_ENABLE; | |
7703 | ||
7704 | if (intel_panel_use_ssc(dev_priv) && can_ssc) | |
7705 | final |= DREF_SSC1_ENABLE; | |
7706 | ||
7707 | if (has_cpu_edp) { | |
7708 | if (intel_panel_use_ssc(dev_priv) && can_ssc) | |
7709 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; | |
7710 | else | |
7711 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; | |
7712 | } else | |
7713 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; | |
1c1a24d2 L |
7714 | } else if (using_ssc_source) { |
7715 | final |= DREF_SSC_SOURCE_ENABLE; | |
7716 | final |= DREF_SSC1_ENABLE; | |
74cfd7ac CW |
7717 | } |
7718 | ||
7719 | if (final == val) | |
7720 | return; | |
7721 | ||
13d83a67 | 7722 | /* Always enable nonspread source */ |
74cfd7ac | 7723 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
13d83a67 | 7724 | |
99eb6a01 | 7725 | if (has_ck505) |
74cfd7ac | 7726 | val |= DREF_NONSPREAD_CK505_ENABLE; |
99eb6a01 | 7727 | else |
74cfd7ac | 7728 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
13d83a67 | 7729 | |
199e5d79 | 7730 | if (has_panel) { |
74cfd7ac CW |
7731 | val &= ~DREF_SSC_SOURCE_MASK; |
7732 | val |= DREF_SSC_SOURCE_ENABLE; | |
13d83a67 | 7733 | |
199e5d79 | 7734 | /* SSC must be turned on before enabling the CPU output */ |
99eb6a01 | 7735 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
199e5d79 | 7736 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
74cfd7ac | 7737 | val |= DREF_SSC1_ENABLE; |
e77166b5 | 7738 | } else |
74cfd7ac | 7739 | val &= ~DREF_SSC1_ENABLE; |
199e5d79 KP |
7740 | |
7741 | /* Get SSC going before enabling the outputs */ | |
74cfd7ac | 7742 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
7743 | POSTING_READ(PCH_DREF_CONTROL); |
7744 | udelay(200); | |
7745 | ||
74cfd7ac | 7746 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
13d83a67 JB |
7747 | |
7748 | /* Enable CPU source on CPU attached eDP */ | |
199e5d79 | 7749 | if (has_cpu_edp) { |
99eb6a01 | 7750 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
199e5d79 | 7751 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
74cfd7ac | 7752 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
eba905b2 | 7753 | } else |
74cfd7ac | 7754 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
199e5d79 | 7755 | } else |
74cfd7ac | 7756 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
199e5d79 | 7757 | |
74cfd7ac | 7758 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
7759 | POSTING_READ(PCH_DREF_CONTROL); |
7760 | udelay(200); | |
7761 | } else { | |
1c1a24d2 | 7762 | DRM_DEBUG_KMS("Disabling CPU source output\n"); |
199e5d79 | 7763 | |
74cfd7ac | 7764 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
199e5d79 KP |
7765 | |
7766 | /* Turn off CPU output */ | |
74cfd7ac | 7767 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
199e5d79 | 7768 | |
74cfd7ac | 7769 | I915_WRITE(PCH_DREF_CONTROL, val); |
199e5d79 KP |
7770 | POSTING_READ(PCH_DREF_CONTROL); |
7771 | udelay(200); | |
7772 | ||
1c1a24d2 L |
7773 | if (!using_ssc_source) { |
7774 | DRM_DEBUG_KMS("Disabling SSC source\n"); | |
199e5d79 | 7775 | |
1c1a24d2 L |
7776 | /* Turn off the SSC source */ |
7777 | val &= ~DREF_SSC_SOURCE_MASK; | |
7778 | val |= DREF_SSC_SOURCE_DISABLE; | |
f165d283 | 7779 | |
1c1a24d2 L |
7780 | /* Turn off SSC1 */ |
7781 | val &= ~DREF_SSC1_ENABLE; | |
7782 | ||
7783 | I915_WRITE(PCH_DREF_CONTROL, val); | |
7784 | POSTING_READ(PCH_DREF_CONTROL); | |
7785 | udelay(200); | |
7786 | } | |
13d83a67 | 7787 | } |
74cfd7ac CW |
7788 | |
7789 | BUG_ON(val != final); | |
13d83a67 JB |
7790 | } |
7791 | ||
f31f2d55 | 7792 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
dde86e2d | 7793 | { |
f31f2d55 | 7794 | uint32_t tmp; |
dde86e2d | 7795 | |
0ff066a9 PZ |
7796 | tmp = I915_READ(SOUTH_CHICKEN2); |
7797 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; | |
7798 | I915_WRITE(SOUTH_CHICKEN2, tmp); | |
dde86e2d | 7799 | |
cf3598c2 ID |
7800 | if (wait_for_us(I915_READ(SOUTH_CHICKEN2) & |
7801 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) | |
0ff066a9 | 7802 | DRM_ERROR("FDI mPHY reset assert timeout\n"); |
dde86e2d | 7803 | |
0ff066a9 PZ |
7804 | tmp = I915_READ(SOUTH_CHICKEN2); |
7805 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; | |
7806 | I915_WRITE(SOUTH_CHICKEN2, tmp); | |
dde86e2d | 7807 | |
cf3598c2 ID |
7808 | if (wait_for_us((I915_READ(SOUTH_CHICKEN2) & |
7809 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) | |
0ff066a9 | 7810 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); |
f31f2d55 PZ |
7811 | } |
7812 | ||
7813 | /* WaMPhyProgramming:hsw */ | |
7814 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) | |
7815 | { | |
7816 | uint32_t tmp; | |
dde86e2d PZ |
7817 | |
7818 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); | |
7819 | tmp &= ~(0xFF << 24); | |
7820 | tmp |= (0x12 << 24); | |
7821 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); | |
7822 | ||
dde86e2d PZ |
7823 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
7824 | tmp |= (1 << 11); | |
7825 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); | |
7826 | ||
7827 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); | |
7828 | tmp |= (1 << 11); | |
7829 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); | |
7830 | ||
dde86e2d PZ |
7831 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
7832 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); | |
7833 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); | |
7834 | ||
7835 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); | |
7836 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); | |
7837 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); | |
7838 | ||
0ff066a9 PZ |
7839 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
7840 | tmp &= ~(7 << 13); | |
7841 | tmp |= (5 << 13); | |
7842 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); | |
dde86e2d | 7843 | |
0ff066a9 PZ |
7844 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
7845 | tmp &= ~(7 << 13); | |
7846 | tmp |= (5 << 13); | |
7847 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); | |
dde86e2d PZ |
7848 | |
7849 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); | |
7850 | tmp &= ~0xFF; | |
7851 | tmp |= 0x1C; | |
7852 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); | |
7853 | ||
7854 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); | |
7855 | tmp &= ~0xFF; | |
7856 | tmp |= 0x1C; | |
7857 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); | |
7858 | ||
7859 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); | |
7860 | tmp &= ~(0xFF << 16); | |
7861 | tmp |= (0x1C << 16); | |
7862 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); | |
7863 | ||
7864 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); | |
7865 | tmp &= ~(0xFF << 16); | |
7866 | tmp |= (0x1C << 16); | |
7867 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); | |
7868 | ||
0ff066a9 PZ |
7869 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
7870 | tmp |= (1 << 27); | |
7871 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); | |
dde86e2d | 7872 | |
0ff066a9 PZ |
7873 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
7874 | tmp |= (1 << 27); | |
7875 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); | |
dde86e2d | 7876 | |
0ff066a9 PZ |
7877 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
7878 | tmp &= ~(0xF << 28); | |
7879 | tmp |= (4 << 28); | |
7880 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); | |
dde86e2d | 7881 | |
0ff066a9 PZ |
7882 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
7883 | tmp &= ~(0xF << 28); | |
7884 | tmp |= (4 << 28); | |
7885 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); | |
f31f2d55 PZ |
7886 | } |
7887 | ||
2fa86a1f PZ |
7888 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
7889 | * Programming" based on the parameters passed: | |
7890 | * - Sequence to enable CLKOUT_DP | |
7891 | * - Sequence to enable CLKOUT_DP without spread | |
7892 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O | |
7893 | */ | |
c39055b0 ACO |
7894 | static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv, |
7895 | bool with_spread, bool with_fdi) | |
f31f2d55 | 7896 | { |
2fa86a1f PZ |
7897 | uint32_t reg, tmp; |
7898 | ||
7899 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) | |
7900 | with_spread = true; | |
4f8036a2 TU |
7901 | if (WARN(HAS_PCH_LPT_LP(dev_priv) && |
7902 | with_fdi, "LP PCH doesn't have FDI\n")) | |
2fa86a1f | 7903 | with_fdi = false; |
f31f2d55 | 7904 | |
a580516d | 7905 | mutex_lock(&dev_priv->sb_lock); |
f31f2d55 PZ |
7906 | |
7907 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
7908 | tmp &= ~SBI_SSCCTL_DISABLE; | |
7909 | tmp |= SBI_SSCCTL_PATHALT; | |
7910 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
7911 | ||
7912 | udelay(24); | |
7913 | ||
2fa86a1f PZ |
7914 | if (with_spread) { |
7915 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
7916 | tmp &= ~SBI_SSCCTL_PATHALT; | |
7917 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
f31f2d55 | 7918 | |
2fa86a1f PZ |
7919 | if (with_fdi) { |
7920 | lpt_reset_fdi_mphy(dev_priv); | |
7921 | lpt_program_fdi_mphy(dev_priv); | |
7922 | } | |
7923 | } | |
dde86e2d | 7924 | |
4f8036a2 | 7925 | reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0; |
2fa86a1f PZ |
7926 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
7927 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; | |
7928 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); | |
c00db246 | 7929 | |
a580516d | 7930 | mutex_unlock(&dev_priv->sb_lock); |
dde86e2d PZ |
7931 | } |
7932 | ||
47701c3b | 7933 | /* Sequence to disable CLKOUT_DP */ |
c39055b0 | 7934 | static void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv) |
47701c3b | 7935 | { |
47701c3b PZ |
7936 | uint32_t reg, tmp; |
7937 | ||
a580516d | 7938 | mutex_lock(&dev_priv->sb_lock); |
47701c3b | 7939 | |
4f8036a2 | 7940 | reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0; |
47701c3b PZ |
7941 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
7942 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; | |
7943 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); | |
7944 | ||
7945 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); | |
7946 | if (!(tmp & SBI_SSCCTL_DISABLE)) { | |
7947 | if (!(tmp & SBI_SSCCTL_PATHALT)) { | |
7948 | tmp |= SBI_SSCCTL_PATHALT; | |
7949 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
7950 | udelay(32); | |
7951 | } | |
7952 | tmp |= SBI_SSCCTL_DISABLE; | |
7953 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); | |
7954 | } | |
7955 | ||
a580516d | 7956 | mutex_unlock(&dev_priv->sb_lock); |
47701c3b PZ |
7957 | } |
7958 | ||
f7be2c21 VS |
7959 | #define BEND_IDX(steps) ((50 + (steps)) / 5) |
7960 | ||
7961 | static const uint16_t sscdivintphase[] = { | |
7962 | [BEND_IDX( 50)] = 0x3B23, | |
7963 | [BEND_IDX( 45)] = 0x3B23, | |
7964 | [BEND_IDX( 40)] = 0x3C23, | |
7965 | [BEND_IDX( 35)] = 0x3C23, | |
7966 | [BEND_IDX( 30)] = 0x3D23, | |
7967 | [BEND_IDX( 25)] = 0x3D23, | |
7968 | [BEND_IDX( 20)] = 0x3E23, | |
7969 | [BEND_IDX( 15)] = 0x3E23, | |
7970 | [BEND_IDX( 10)] = 0x3F23, | |
7971 | [BEND_IDX( 5)] = 0x3F23, | |
7972 | [BEND_IDX( 0)] = 0x0025, | |
7973 | [BEND_IDX( -5)] = 0x0025, | |
7974 | [BEND_IDX(-10)] = 0x0125, | |
7975 | [BEND_IDX(-15)] = 0x0125, | |
7976 | [BEND_IDX(-20)] = 0x0225, | |
7977 | [BEND_IDX(-25)] = 0x0225, | |
7978 | [BEND_IDX(-30)] = 0x0325, | |
7979 | [BEND_IDX(-35)] = 0x0325, | |
7980 | [BEND_IDX(-40)] = 0x0425, | |
7981 | [BEND_IDX(-45)] = 0x0425, | |
7982 | [BEND_IDX(-50)] = 0x0525, | |
7983 | }; | |
7984 | ||
7985 | /* | |
7986 | * Bend CLKOUT_DP | |
7987 | * steps -50 to 50 inclusive, in steps of 5 | |
7988 | * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz) | |
7989 | * change in clock period = -(steps / 10) * 5.787 ps | |
7990 | */ | |
7991 | static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps) | |
7992 | { | |
7993 | uint32_t tmp; | |
7994 | int idx = BEND_IDX(steps); | |
7995 | ||
7996 | if (WARN_ON(steps % 5 != 0)) | |
7997 | return; | |
7998 | ||
7999 | if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase))) | |
8000 | return; | |
8001 | ||
8002 | mutex_lock(&dev_priv->sb_lock); | |
8003 | ||
8004 | if (steps % 10 != 0) | |
8005 | tmp = 0xAAAAAAAB; | |
8006 | else | |
8007 | tmp = 0x00000000; | |
8008 | intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK); | |
8009 | ||
8010 | tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK); | |
8011 | tmp &= 0xffff0000; | |
8012 | tmp |= sscdivintphase[idx]; | |
8013 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK); | |
8014 | ||
8015 | mutex_unlock(&dev_priv->sb_lock); | |
8016 | } | |
8017 | ||
8018 | #undef BEND_IDX | |
8019 | ||
c39055b0 | 8020 | static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv) |
bf8fa3d3 | 8021 | { |
bf8fa3d3 PZ |
8022 | struct intel_encoder *encoder; |
8023 | bool has_vga = false; | |
8024 | ||
c39055b0 | 8025 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
bf8fa3d3 PZ |
8026 | switch (encoder->type) { |
8027 | case INTEL_OUTPUT_ANALOG: | |
8028 | has_vga = true; | |
8029 | break; | |
6847d71b PZ |
8030 | default: |
8031 | break; | |
bf8fa3d3 PZ |
8032 | } |
8033 | } | |
8034 | ||
f7be2c21 | 8035 | if (has_vga) { |
c39055b0 ACO |
8036 | lpt_bend_clkout_dp(dev_priv, 0); |
8037 | lpt_enable_clkout_dp(dev_priv, true, true); | |
f7be2c21 | 8038 | } else { |
c39055b0 | 8039 | lpt_disable_clkout_dp(dev_priv); |
f7be2c21 | 8040 | } |
bf8fa3d3 PZ |
8041 | } |
8042 | ||
dde86e2d PZ |
8043 | /* |
8044 | * Initialize reference clocks when the driver loads | |
8045 | */ | |
c39055b0 | 8046 | void intel_init_pch_refclk(struct drm_i915_private *dev_priv) |
dde86e2d | 8047 | { |
6e266956 | 8048 | if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) |
c39055b0 | 8049 | ironlake_init_pch_refclk(dev_priv); |
6e266956 | 8050 | else if (HAS_PCH_LPT(dev_priv)) |
c39055b0 | 8051 | lpt_init_pch_refclk(dev_priv); |
dde86e2d PZ |
8052 | } |
8053 | ||
6ff93609 | 8054 | static void ironlake_set_pipeconf(struct drm_crtc *crtc) |
79e53945 | 8055 | { |
fac5e23e | 8056 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
79e53945 JB |
8057 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8058 | int pipe = intel_crtc->pipe; | |
c8203565 PZ |
8059 | uint32_t val; |
8060 | ||
78114071 | 8061 | val = 0; |
c8203565 | 8062 | |
6e3c9717 | 8063 | switch (intel_crtc->config->pipe_bpp) { |
c8203565 | 8064 | case 18: |
dfd07d72 | 8065 | val |= PIPECONF_6BPC; |
c8203565 PZ |
8066 | break; |
8067 | case 24: | |
dfd07d72 | 8068 | val |= PIPECONF_8BPC; |
c8203565 PZ |
8069 | break; |
8070 | case 30: | |
dfd07d72 | 8071 | val |= PIPECONF_10BPC; |
c8203565 PZ |
8072 | break; |
8073 | case 36: | |
dfd07d72 | 8074 | val |= PIPECONF_12BPC; |
c8203565 PZ |
8075 | break; |
8076 | default: | |
cc769b62 PZ |
8077 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
8078 | BUG(); | |
c8203565 PZ |
8079 | } |
8080 | ||
6e3c9717 | 8081 | if (intel_crtc->config->dither) |
c8203565 PZ |
8082 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
8083 | ||
6e3c9717 | 8084 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
c8203565 PZ |
8085 | val |= PIPECONF_INTERLACED_ILK; |
8086 | else | |
8087 | val |= PIPECONF_PROGRESSIVE; | |
8088 | ||
6e3c9717 | 8089 | if (intel_crtc->config->limited_color_range) |
3685a8f3 | 8090 | val |= PIPECONF_COLOR_RANGE_SELECT; |
3685a8f3 | 8091 | |
c8203565 PZ |
8092 | I915_WRITE(PIPECONF(pipe), val); |
8093 | POSTING_READ(PIPECONF(pipe)); | |
8094 | } | |
8095 | ||
6ff93609 | 8096 | static void haswell_set_pipeconf(struct drm_crtc *crtc) |
ee2b0b38 | 8097 | { |
fac5e23e | 8098 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
ee2b0b38 | 8099 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
6e3c9717 | 8100 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
391bf048 | 8101 | u32 val = 0; |
ee2b0b38 | 8102 | |
391bf048 | 8103 | if (IS_HASWELL(dev_priv) && intel_crtc->config->dither) |
ee2b0b38 PZ |
8104 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
8105 | ||
6e3c9717 | 8106 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
ee2b0b38 PZ |
8107 | val |= PIPECONF_INTERLACED_ILK; |
8108 | else | |
8109 | val |= PIPECONF_PROGRESSIVE; | |
8110 | ||
702e7a56 PZ |
8111 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
8112 | POSTING_READ(PIPECONF(cpu_transcoder)); | |
391bf048 JN |
8113 | } |
8114 | ||
391bf048 JN |
8115 | static void haswell_set_pipemisc(struct drm_crtc *crtc) |
8116 | { | |
fac5e23e | 8117 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
391bf048 | 8118 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
b22ca995 | 8119 | struct intel_crtc_state *config = intel_crtc->config; |
756f85cf | 8120 | |
391bf048 JN |
8121 | if (IS_BROADWELL(dev_priv) || INTEL_INFO(dev_priv)->gen >= 9) { |
8122 | u32 val = 0; | |
756f85cf | 8123 | |
6e3c9717 | 8124 | switch (intel_crtc->config->pipe_bpp) { |
756f85cf PZ |
8125 | case 18: |
8126 | val |= PIPEMISC_DITHER_6_BPC; | |
8127 | break; | |
8128 | case 24: | |
8129 | val |= PIPEMISC_DITHER_8_BPC; | |
8130 | break; | |
8131 | case 30: | |
8132 | val |= PIPEMISC_DITHER_10_BPC; | |
8133 | break; | |
8134 | case 36: | |
8135 | val |= PIPEMISC_DITHER_12_BPC; | |
8136 | break; | |
8137 | default: | |
8138 | /* Case prevented by pipe_config_set_bpp. */ | |
8139 | BUG(); | |
8140 | } | |
8141 | ||
6e3c9717 | 8142 | if (intel_crtc->config->dither) |
756f85cf PZ |
8143 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
8144 | ||
b22ca995 SS |
8145 | if (config->ycbcr420) { |
8146 | val |= PIPEMISC_OUTPUT_COLORSPACE_YUV | | |
8147 | PIPEMISC_YUV420_ENABLE | | |
8148 | PIPEMISC_YUV420_MODE_FULL_BLEND; | |
8149 | } | |
8150 | ||
391bf048 | 8151 | I915_WRITE(PIPEMISC(intel_crtc->pipe), val); |
756f85cf | 8152 | } |
ee2b0b38 PZ |
8153 | } |
8154 | ||
d4b1931c PZ |
8155 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
8156 | { | |
8157 | /* | |
8158 | * Account for spread spectrum to avoid | |
8159 | * oversubscribing the link. Max center spread | |
8160 | * is 2.5%; use 5% for safety's sake. | |
8161 | */ | |
8162 | u32 bps = target_clock * bpp * 21 / 20; | |
619d4d04 | 8163 | return DIV_ROUND_UP(bps, link_bw * 8); |
d4b1931c PZ |
8164 | } |
8165 | ||
7429e9d4 | 8166 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
6cf86a5e | 8167 | { |
7429e9d4 | 8168 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
f48d8f23 PZ |
8169 | } |
8170 | ||
b75ca6f6 ACO |
8171 | static void ironlake_compute_dpll(struct intel_crtc *intel_crtc, |
8172 | struct intel_crtc_state *crtc_state, | |
9e2c8475 | 8173 | struct dpll *reduced_clock) |
79e53945 | 8174 | { |
de13a2e3 | 8175 | struct drm_crtc *crtc = &intel_crtc->base; |
79e53945 | 8176 | struct drm_device *dev = crtc->dev; |
fac5e23e | 8177 | struct drm_i915_private *dev_priv = to_i915(dev); |
b75ca6f6 | 8178 | u32 dpll, fp, fp2; |
3d6e9ee0 | 8179 | int factor; |
79e53945 | 8180 | |
c1858123 | 8181 | /* Enable autotuning of the PLL clock (if permissible) */ |
8febb297 | 8182 | factor = 21; |
3d6e9ee0 | 8183 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
8febb297 | 8184 | if ((intel_panel_use_ssc(dev_priv) && |
e91e941b | 8185 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
6e266956 | 8186 | (HAS_PCH_IBX(dev_priv) && intel_is_dual_link_lvds(dev))) |
8febb297 | 8187 | factor = 25; |
190f68c5 | 8188 | } else if (crtc_state->sdvo_tv_clock) |
8febb297 | 8189 | factor = 20; |
c1858123 | 8190 | |
b75ca6f6 ACO |
8191 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
8192 | ||
190f68c5 | 8193 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
b75ca6f6 ACO |
8194 | fp |= FP_CB_TUNE; |
8195 | ||
8196 | if (reduced_clock) { | |
8197 | fp2 = i9xx_dpll_compute_fp(reduced_clock); | |
2c07245f | 8198 | |
b75ca6f6 ACO |
8199 | if (reduced_clock->m < factor * reduced_clock->n) |
8200 | fp2 |= FP_CB_TUNE; | |
8201 | } else { | |
8202 | fp2 = fp; | |
8203 | } | |
9a7c7890 | 8204 | |
5eddb70b | 8205 | dpll = 0; |
2c07245f | 8206 | |
3d6e9ee0 | 8207 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) |
a07d6787 EA |
8208 | dpll |= DPLLB_MODE_LVDS; |
8209 | else | |
8210 | dpll |= DPLLB_MODE_DAC_SERIAL; | |
198a037f | 8211 | |
190f68c5 | 8212 | dpll |= (crtc_state->pixel_multiplier - 1) |
ef1b460d | 8213 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
198a037f | 8214 | |
3d6e9ee0 VS |
8215 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) || |
8216 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) | |
4a33e48d | 8217 | dpll |= DPLL_SDVO_HIGH_SPEED; |
3d6e9ee0 | 8218 | |
37a5650b | 8219 | if (intel_crtc_has_dp_encoder(crtc_state)) |
4a33e48d | 8220 | dpll |= DPLL_SDVO_HIGH_SPEED; |
79e53945 | 8221 | |
7d7f8633 VS |
8222 | /* |
8223 | * The high speed IO clock is only really required for | |
8224 | * SDVO/HDMI/DP, but we also enable it for CRT to make it | |
8225 | * possible to share the DPLL between CRT and HDMI. Enabling | |
8226 | * the clock needlessly does no real harm, except use up a | |
8227 | * bit of power potentially. | |
8228 | * | |
8229 | * We'll limit this to IVB with 3 pipes, since it has only two | |
8230 | * DPLLs and so DPLL sharing is the only way to get three pipes | |
8231 | * driving PCH ports at the same time. On SNB we could do this, | |
8232 | * and potentially avoid enabling the second DPLL, but it's not | |
8233 | * clear if it''s a win or loss power wise. No point in doing | |
8234 | * this on ILK at all since it has a fixed DPLL<->pipe mapping. | |
8235 | */ | |
8236 | if (INTEL_INFO(dev_priv)->num_pipes == 3 && | |
8237 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) | |
8238 | dpll |= DPLL_SDVO_HIGH_SPEED; | |
8239 | ||
a07d6787 | 8240 | /* compute bitmask from p1 value */ |
190f68c5 | 8241 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
a07d6787 | 8242 | /* also FPA1 */ |
190f68c5 | 8243 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
a07d6787 | 8244 | |
190f68c5 | 8245 | switch (crtc_state->dpll.p2) { |
a07d6787 EA |
8246 | case 5: |
8247 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; | |
8248 | break; | |
8249 | case 7: | |
8250 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; | |
8251 | break; | |
8252 | case 10: | |
8253 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; | |
8254 | break; | |
8255 | case 14: | |
8256 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; | |
8257 | break; | |
79e53945 JB |
8258 | } |
8259 | ||
3d6e9ee0 VS |
8260 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
8261 | intel_panel_use_ssc(dev_priv)) | |
43565a06 | 8262 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
79e53945 JB |
8263 | else |
8264 | dpll |= PLL_REF_INPUT_DREFCLK; | |
8265 | ||
b75ca6f6 ACO |
8266 | dpll |= DPLL_VCO_ENABLE; |
8267 | ||
8268 | crtc_state->dpll_hw_state.dpll = dpll; | |
8269 | crtc_state->dpll_hw_state.fp0 = fp; | |
8270 | crtc_state->dpll_hw_state.fp1 = fp2; | |
de13a2e3 PZ |
8271 | } |
8272 | ||
190f68c5 ACO |
8273 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
8274 | struct intel_crtc_state *crtc_state) | |
de13a2e3 | 8275 | { |
997c030c | 8276 | struct drm_device *dev = crtc->base.dev; |
fac5e23e | 8277 | struct drm_i915_private *dev_priv = to_i915(dev); |
1b6f4958 | 8278 | const struct intel_limit *limit; |
997c030c | 8279 | int refclk = 120000; |
de13a2e3 | 8280 | |
dd3cd74a ACO |
8281 | memset(&crtc_state->dpll_hw_state, 0, |
8282 | sizeof(crtc_state->dpll_hw_state)); | |
8283 | ||
ded220e2 ACO |
8284 | /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */ |
8285 | if (!crtc_state->has_pch_encoder) | |
8286 | return 0; | |
79e53945 | 8287 | |
2d84d2b3 | 8288 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
997c030c ACO |
8289 | if (intel_panel_use_ssc(dev_priv)) { |
8290 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", | |
8291 | dev_priv->vbt.lvds_ssc_freq); | |
8292 | refclk = dev_priv->vbt.lvds_ssc_freq; | |
8293 | } | |
8294 | ||
8295 | if (intel_is_dual_link_lvds(dev)) { | |
8296 | if (refclk == 100000) | |
8297 | limit = &intel_limits_ironlake_dual_lvds_100m; | |
8298 | else | |
8299 | limit = &intel_limits_ironlake_dual_lvds; | |
8300 | } else { | |
8301 | if (refclk == 100000) | |
8302 | limit = &intel_limits_ironlake_single_lvds_100m; | |
8303 | else | |
8304 | limit = &intel_limits_ironlake_single_lvds; | |
8305 | } | |
8306 | } else { | |
8307 | limit = &intel_limits_ironlake_dac; | |
8308 | } | |
8309 | ||
364ee29d | 8310 | if (!crtc_state->clock_set && |
997c030c ACO |
8311 | !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
8312 | refclk, NULL, &crtc_state->dpll)) { | |
364ee29d ACO |
8313 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
8314 | return -EINVAL; | |
f47709a9 | 8315 | } |
79e53945 | 8316 | |
cbaa3315 | 8317 | ironlake_compute_dpll(crtc, crtc_state, NULL); |
66e985c0 | 8318 | |
efd38b68 | 8319 | if (!intel_get_shared_dpll(crtc, crtc_state, NULL)) { |
ded220e2 ACO |
8320 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", |
8321 | pipe_name(crtc->pipe)); | |
8322 | return -EINVAL; | |
3fb37703 | 8323 | } |
79e53945 | 8324 | |
c8f7a0db | 8325 | return 0; |
79e53945 JB |
8326 | } |
8327 | ||
eb14cb74 VS |
8328 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
8329 | struct intel_link_m_n *m_n) | |
8330 | { | |
8331 | struct drm_device *dev = crtc->base.dev; | |
fac5e23e | 8332 | struct drm_i915_private *dev_priv = to_i915(dev); |
eb14cb74 VS |
8333 | enum pipe pipe = crtc->pipe; |
8334 | ||
8335 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); | |
8336 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); | |
8337 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) | |
8338 | & ~TU_SIZE_MASK; | |
8339 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); | |
8340 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) | |
8341 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
8342 | } | |
8343 | ||
8344 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, | |
8345 | enum transcoder transcoder, | |
b95af8be VK |
8346 | struct intel_link_m_n *m_n, |
8347 | struct intel_link_m_n *m2_n2) | |
72419203 | 8348 | { |
6315b5d3 | 8349 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
eb14cb74 | 8350 | enum pipe pipe = crtc->pipe; |
72419203 | 8351 | |
6315b5d3 | 8352 | if (INTEL_GEN(dev_priv) >= 5) { |
eb14cb74 VS |
8353 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); |
8354 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); | |
8355 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) | |
8356 | & ~TU_SIZE_MASK; | |
8357 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); | |
8358 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) | |
8359 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
b95af8be VK |
8360 | /* Read M2_N2 registers only for gen < 8 (M2_N2 available for |
8361 | * gen < 8) and if DRRS is supported (to make sure the | |
8362 | * registers are not unnecessarily read). | |
8363 | */ | |
6315b5d3 | 8364 | if (m2_n2 && INTEL_GEN(dev_priv) < 8 && |
6e3c9717 | 8365 | crtc->config->has_drrs) { |
b95af8be VK |
8366 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
8367 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); | |
8368 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) | |
8369 | & ~TU_SIZE_MASK; | |
8370 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); | |
8371 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) | |
8372 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
8373 | } | |
eb14cb74 VS |
8374 | } else { |
8375 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); | |
8376 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); | |
8377 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) | |
8378 | & ~TU_SIZE_MASK; | |
8379 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); | |
8380 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) | |
8381 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; | |
8382 | } | |
8383 | } | |
8384 | ||
8385 | void intel_dp_get_m_n(struct intel_crtc *crtc, | |
5cec258b | 8386 | struct intel_crtc_state *pipe_config) |
eb14cb74 | 8387 | { |
681a8504 | 8388 | if (pipe_config->has_pch_encoder) |
eb14cb74 VS |
8389 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
8390 | else | |
8391 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, | |
b95af8be VK |
8392 | &pipe_config->dp_m_n, |
8393 | &pipe_config->dp_m2_n2); | |
eb14cb74 | 8394 | } |
72419203 | 8395 | |
eb14cb74 | 8396 | static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc, |
5cec258b | 8397 | struct intel_crtc_state *pipe_config) |
eb14cb74 VS |
8398 | { |
8399 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, | |
b95af8be | 8400 | &pipe_config->fdi_m_n, NULL); |
72419203 DV |
8401 | } |
8402 | ||
bd2e244f | 8403 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 8404 | struct intel_crtc_state *pipe_config) |
bd2e244f JB |
8405 | { |
8406 | struct drm_device *dev = crtc->base.dev; | |
fac5e23e | 8407 | struct drm_i915_private *dev_priv = to_i915(dev); |
a1b2278e CK |
8408 | struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state; |
8409 | uint32_t ps_ctrl = 0; | |
8410 | int id = -1; | |
8411 | int i; | |
bd2e244f | 8412 | |
a1b2278e CK |
8413 | /* find scaler attached to this pipe */ |
8414 | for (i = 0; i < crtc->num_scalers; i++) { | |
8415 | ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i)); | |
8416 | if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) { | |
8417 | id = i; | |
8418 | pipe_config->pch_pfit.enabled = true; | |
8419 | pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i)); | |
8420 | pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i)); | |
8421 | break; | |
8422 | } | |
8423 | } | |
bd2e244f | 8424 | |
a1b2278e CK |
8425 | scaler_state->scaler_id = id; |
8426 | if (id >= 0) { | |
8427 | scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX); | |
8428 | } else { | |
8429 | scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX); | |
bd2e244f JB |
8430 | } |
8431 | } | |
8432 | ||
5724dbd1 DL |
8433 | static void |
8434 | skylake_get_initial_plane_config(struct intel_crtc *crtc, | |
8435 | struct intel_initial_plane_config *plane_config) | |
bc8d7dff DL |
8436 | { |
8437 | struct drm_device *dev = crtc->base.dev; | |
fac5e23e | 8438 | struct drm_i915_private *dev_priv = to_i915(dev); |
40f46283 | 8439 | u32 val, base, offset, stride_mult, tiling; |
bc8d7dff DL |
8440 | int pipe = crtc->pipe; |
8441 | int fourcc, pixel_format; | |
6761dd31 | 8442 | unsigned int aligned_height; |
bc8d7dff | 8443 | struct drm_framebuffer *fb; |
1b842c89 | 8444 | struct intel_framebuffer *intel_fb; |
bc8d7dff | 8445 | |
d9806c9f | 8446 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 8447 | if (!intel_fb) { |
bc8d7dff DL |
8448 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
8449 | return; | |
8450 | } | |
8451 | ||
1b842c89 DL |
8452 | fb = &intel_fb->base; |
8453 | ||
d2e9f5fc VS |
8454 | fb->dev = dev; |
8455 | ||
bc8d7dff | 8456 | val = I915_READ(PLANE_CTL(pipe, 0)); |
42a7b088 DL |
8457 | if (!(val & PLANE_CTL_ENABLE)) |
8458 | goto error; | |
8459 | ||
bc8d7dff DL |
8460 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
8461 | fourcc = skl_format_to_fourcc(pixel_format, | |
8462 | val & PLANE_CTL_ORDER_RGBX, | |
8463 | val & PLANE_CTL_ALPHA_MASK); | |
2f3f4763 | 8464 | fb->format = drm_format_info(fourcc); |
bc8d7dff | 8465 | |
40f46283 DL |
8466 | tiling = val & PLANE_CTL_TILED_MASK; |
8467 | switch (tiling) { | |
8468 | case PLANE_CTL_TILED_LINEAR: | |
2f075565 | 8469 | fb->modifier = DRM_FORMAT_MOD_LINEAR; |
40f46283 DL |
8470 | break; |
8471 | case PLANE_CTL_TILED_X: | |
8472 | plane_config->tiling = I915_TILING_X; | |
bae781b2 | 8473 | fb->modifier = I915_FORMAT_MOD_X_TILED; |
40f46283 DL |
8474 | break; |
8475 | case PLANE_CTL_TILED_Y: | |
1d7a736a | 8476 | plane_config->tiling = I915_TILING_Y; |
03ef6b01 | 8477 | if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE) |
2e2adb05 VS |
8478 | fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS; |
8479 | else | |
8480 | fb->modifier = I915_FORMAT_MOD_Y_TILED; | |
40f46283 DL |
8481 | break; |
8482 | case PLANE_CTL_TILED_YF: | |
03ef6b01 | 8483 | if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE) |
2e2adb05 VS |
8484 | fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS; |
8485 | else | |
8486 | fb->modifier = I915_FORMAT_MOD_Yf_TILED; | |
40f46283 DL |
8487 | break; |
8488 | default: | |
8489 | MISSING_CASE(tiling); | |
8490 | goto error; | |
8491 | } | |
8492 | ||
bc8d7dff DL |
8493 | base = I915_READ(PLANE_SURF(pipe, 0)) & 0xfffff000; |
8494 | plane_config->base = base; | |
8495 | ||
8496 | offset = I915_READ(PLANE_OFFSET(pipe, 0)); | |
8497 | ||
8498 | val = I915_READ(PLANE_SIZE(pipe, 0)); | |
8499 | fb->height = ((val >> 16) & 0xfff) + 1; | |
8500 | fb->width = ((val >> 0) & 0x1fff) + 1; | |
8501 | ||
8502 | val = I915_READ(PLANE_STRIDE(pipe, 0)); | |
d88c4afd | 8503 | stride_mult = intel_fb_stride_alignment(fb, 0); |
bc8d7dff DL |
8504 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
8505 | ||
d88c4afd | 8506 | aligned_height = intel_fb_align_height(fb, 0, fb->height); |
bc8d7dff | 8507 | |
f37b5c2b | 8508 | plane_config->size = fb->pitches[0] * aligned_height; |
bc8d7dff DL |
8509 | |
8510 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", | |
8511 | pipe_name(pipe), fb->width, fb->height, | |
272725c7 | 8512 | fb->format->cpp[0] * 8, base, fb->pitches[0], |
bc8d7dff DL |
8513 | plane_config->size); |
8514 | ||
2d14030b | 8515 | plane_config->fb = intel_fb; |
bc8d7dff DL |
8516 | return; |
8517 | ||
8518 | error: | |
d1a3a036 | 8519 | kfree(intel_fb); |
bc8d7dff DL |
8520 | } |
8521 | ||
2fa2fe9a | 8522 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
5cec258b | 8523 | struct intel_crtc_state *pipe_config) |
2fa2fe9a DV |
8524 | { |
8525 | struct drm_device *dev = crtc->base.dev; | |
fac5e23e | 8526 | struct drm_i915_private *dev_priv = to_i915(dev); |
2fa2fe9a DV |
8527 | uint32_t tmp; |
8528 | ||
8529 | tmp = I915_READ(PF_CTL(crtc->pipe)); | |
8530 | ||
8531 | if (tmp & PF_ENABLE) { | |
fd4daa9c | 8532 | pipe_config->pch_pfit.enabled = true; |
2fa2fe9a DV |
8533 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
8534 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); | |
cb8b2a30 DV |
8535 | |
8536 | /* We currently do not free assignements of panel fitters on | |
8537 | * ivb/hsw (since we don't use the higher upscaling modes which | |
8538 | * differentiates them) so just WARN about this case for now. */ | |
5db94019 | 8539 | if (IS_GEN7(dev_priv)) { |
cb8b2a30 DV |
8540 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != |
8541 | PF_PIPE_SEL_IVB(crtc->pipe)); | |
8542 | } | |
2fa2fe9a | 8543 | } |
79e53945 JB |
8544 | } |
8545 | ||
5724dbd1 DL |
8546 | static void |
8547 | ironlake_get_initial_plane_config(struct intel_crtc *crtc, | |
8548 | struct intel_initial_plane_config *plane_config) | |
4c6baa59 JB |
8549 | { |
8550 | struct drm_device *dev = crtc->base.dev; | |
fac5e23e | 8551 | struct drm_i915_private *dev_priv = to_i915(dev); |
4c6baa59 | 8552 | u32 val, base, offset; |
aeee5a49 | 8553 | int pipe = crtc->pipe; |
4c6baa59 | 8554 | int fourcc, pixel_format; |
6761dd31 | 8555 | unsigned int aligned_height; |
b113d5ee | 8556 | struct drm_framebuffer *fb; |
1b842c89 | 8557 | struct intel_framebuffer *intel_fb; |
4c6baa59 | 8558 | |
42a7b088 DL |
8559 | val = I915_READ(DSPCNTR(pipe)); |
8560 | if (!(val & DISPLAY_PLANE_ENABLE)) | |
8561 | return; | |
8562 | ||
d9806c9f | 8563 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
1b842c89 | 8564 | if (!intel_fb) { |
4c6baa59 JB |
8565 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
8566 | return; | |
8567 | } | |
8568 | ||
1b842c89 DL |
8569 | fb = &intel_fb->base; |
8570 | ||
d2e9f5fc VS |
8571 | fb->dev = dev; |
8572 | ||
6315b5d3 | 8573 | if (INTEL_GEN(dev_priv) >= 4) { |
18c5247e | 8574 | if (val & DISPPLANE_TILED) { |
49af449b | 8575 | plane_config->tiling = I915_TILING_X; |
bae781b2 | 8576 | fb->modifier = I915_FORMAT_MOD_X_TILED; |
18c5247e DV |
8577 | } |
8578 | } | |
4c6baa59 JB |
8579 | |
8580 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; | |
b35d63fa | 8581 | fourcc = i9xx_format_to_fourcc(pixel_format); |
2f3f4763 | 8582 | fb->format = drm_format_info(fourcc); |
4c6baa59 | 8583 | |
aeee5a49 | 8584 | base = I915_READ(DSPSURF(pipe)) & 0xfffff000; |
8652744b | 8585 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
aeee5a49 | 8586 | offset = I915_READ(DSPOFFSET(pipe)); |
4c6baa59 | 8587 | } else { |
49af449b | 8588 | if (plane_config->tiling) |
aeee5a49 | 8589 | offset = I915_READ(DSPTILEOFF(pipe)); |
4c6baa59 | 8590 | else |
aeee5a49 | 8591 | offset = I915_READ(DSPLINOFF(pipe)); |
4c6baa59 JB |
8592 | } |
8593 | plane_config->base = base; | |
8594 | ||
8595 | val = I915_READ(PIPESRC(pipe)); | |
b113d5ee DL |
8596 | fb->width = ((val >> 16) & 0xfff) + 1; |
8597 | fb->height = ((val >> 0) & 0xfff) + 1; | |
4c6baa59 JB |
8598 | |
8599 | val = I915_READ(DSPSTRIDE(pipe)); | |
b113d5ee | 8600 | fb->pitches[0] = val & 0xffffffc0; |
4c6baa59 | 8601 | |
d88c4afd | 8602 | aligned_height = intel_fb_align_height(fb, 0, fb->height); |
4c6baa59 | 8603 | |
f37b5c2b | 8604 | plane_config->size = fb->pitches[0] * aligned_height; |
4c6baa59 | 8605 | |
2844a921 DL |
8606 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
8607 | pipe_name(pipe), fb->width, fb->height, | |
272725c7 | 8608 | fb->format->cpp[0] * 8, base, fb->pitches[0], |
2844a921 | 8609 | plane_config->size); |
b113d5ee | 8610 | |
2d14030b | 8611 | plane_config->fb = intel_fb; |
4c6baa59 JB |
8612 | } |
8613 | ||
0e8ffe1b | 8614 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 8615 | struct intel_crtc_state *pipe_config) |
0e8ffe1b DV |
8616 | { |
8617 | struct drm_device *dev = crtc->base.dev; | |
fac5e23e | 8618 | struct drm_i915_private *dev_priv = to_i915(dev); |
1729050e | 8619 | enum intel_display_power_domain power_domain; |
0e8ffe1b | 8620 | uint32_t tmp; |
1729050e | 8621 | bool ret; |
0e8ffe1b | 8622 | |
1729050e ID |
8623 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
8624 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) | |
930e8c9e PZ |
8625 | return false; |
8626 | ||
e143a21c | 8627 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
8106ddbd | 8628 | pipe_config->shared_dpll = NULL; |
eccb140b | 8629 | |
1729050e | 8630 | ret = false; |
0e8ffe1b DV |
8631 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
8632 | if (!(tmp & PIPECONF_ENABLE)) | |
1729050e | 8633 | goto out; |
0e8ffe1b | 8634 | |
42571aef VS |
8635 | switch (tmp & PIPECONF_BPC_MASK) { |
8636 | case PIPECONF_6BPC: | |
8637 | pipe_config->pipe_bpp = 18; | |
8638 | break; | |
8639 | case PIPECONF_8BPC: | |
8640 | pipe_config->pipe_bpp = 24; | |
8641 | break; | |
8642 | case PIPECONF_10BPC: | |
8643 | pipe_config->pipe_bpp = 30; | |
8644 | break; | |
8645 | case PIPECONF_12BPC: | |
8646 | pipe_config->pipe_bpp = 36; | |
8647 | break; | |
8648 | default: | |
8649 | break; | |
8650 | } | |
8651 | ||
b5a9fa09 DV |
8652 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
8653 | pipe_config->limited_color_range = true; | |
8654 | ||
ab9412ba | 8655 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
66e985c0 | 8656 | struct intel_shared_dpll *pll; |
8106ddbd | 8657 | enum intel_dpll_id pll_id; |
66e985c0 | 8658 | |
88adfff1 DV |
8659 | pipe_config->has_pch_encoder = true; |
8660 | ||
627eb5a3 DV |
8661 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
8662 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> | |
8663 | FDI_DP_PORT_WIDTH_SHIFT) + 1; | |
72419203 DV |
8664 | |
8665 | ironlake_get_fdi_m_n_config(crtc, pipe_config); | |
6c49f241 | 8666 | |
2d1fe073 | 8667 | if (HAS_PCH_IBX(dev_priv)) { |
d9a7bc67 ID |
8668 | /* |
8669 | * The pipe->pch transcoder and pch transcoder->pll | |
8670 | * mapping is fixed. | |
8671 | */ | |
8106ddbd | 8672 | pll_id = (enum intel_dpll_id) crtc->pipe; |
c0d43d62 DV |
8673 | } else { |
8674 | tmp = I915_READ(PCH_DPLL_SEL); | |
8675 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) | |
8106ddbd | 8676 | pll_id = DPLL_ID_PCH_PLL_B; |
c0d43d62 | 8677 | else |
8106ddbd | 8678 | pll_id= DPLL_ID_PCH_PLL_A; |
c0d43d62 | 8679 | } |
66e985c0 | 8680 | |
8106ddbd ACO |
8681 | pipe_config->shared_dpll = |
8682 | intel_get_shared_dpll_by_id(dev_priv, pll_id); | |
8683 | pll = pipe_config->shared_dpll; | |
66e985c0 | 8684 | |
2edd6443 ACO |
8685 | WARN_ON(!pll->funcs.get_hw_state(dev_priv, pll, |
8686 | &pipe_config->dpll_hw_state)); | |
c93f54cf DV |
8687 | |
8688 | tmp = pipe_config->dpll_hw_state.dpll; | |
8689 | pipe_config->pixel_multiplier = | |
8690 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) | |
8691 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; | |
18442d08 VS |
8692 | |
8693 | ironlake_pch_clock_get(crtc, pipe_config); | |
6c49f241 DV |
8694 | } else { |
8695 | pipe_config->pixel_multiplier = 1; | |
627eb5a3 DV |
8696 | } |
8697 | ||
1bd1bd80 | 8698 | intel_get_pipe_timings(crtc, pipe_config); |
bc58be60 | 8699 | intel_get_pipe_src_size(crtc, pipe_config); |
1bd1bd80 | 8700 | |
2fa2fe9a DV |
8701 | ironlake_get_pfit_config(crtc, pipe_config); |
8702 | ||
1729050e ID |
8703 | ret = true; |
8704 | ||
8705 | out: | |
8706 | intel_display_power_put(dev_priv, power_domain); | |
8707 | ||
8708 | return ret; | |
0e8ffe1b DV |
8709 | } |
8710 | ||
be256dc7 PZ |
8711 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
8712 | { | |
91c8a326 | 8713 | struct drm_device *dev = &dev_priv->drm; |
be256dc7 | 8714 | struct intel_crtc *crtc; |
be256dc7 | 8715 | |
d3fcc808 | 8716 | for_each_intel_crtc(dev, crtc) |
e2c719b7 | 8717 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
be256dc7 PZ |
8718 | pipe_name(crtc->pipe)); |
8719 | ||
9c3a16c8 ID |
8720 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_CTL_DRIVER(HSW_DISP_PW_GLOBAL)), |
8721 | "Display power well on\n"); | |
e2c719b7 | 8722 | I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n"); |
01403de3 VS |
8723 | I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); |
8724 | I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n"); | |
44cb734c | 8725 | I915_STATE_WARN(I915_READ(PP_STATUS(0)) & PP_ON, "Panel power on\n"); |
e2c719b7 | 8726 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, |
be256dc7 | 8727 | "CPU PWM1 enabled\n"); |
772c2a51 | 8728 | if (IS_HASWELL(dev_priv)) |
e2c719b7 | 8729 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
c5107b87 | 8730 | "CPU PWM2 enabled\n"); |
e2c719b7 | 8731 | I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE, |
be256dc7 | 8732 | "PCH PWM1 enabled\n"); |
e2c719b7 | 8733 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
be256dc7 | 8734 | "Utility pin enabled\n"); |
e2c719b7 | 8735 | I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n"); |
be256dc7 | 8736 | |
9926ada1 PZ |
8737 | /* |
8738 | * In theory we can still leave IRQs enabled, as long as only the HPD | |
8739 | * interrupts remain enabled. We used to check for that, but since it's | |
8740 | * gen-specific and since we only disable LCPLL after we fully disable | |
8741 | * the interrupts, the check below should be enough. | |
8742 | */ | |
e2c719b7 | 8743 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
be256dc7 PZ |
8744 | } |
8745 | ||
9ccd5aeb PZ |
8746 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) |
8747 | { | |
772c2a51 | 8748 | if (IS_HASWELL(dev_priv)) |
9ccd5aeb PZ |
8749 | return I915_READ(D_COMP_HSW); |
8750 | else | |
8751 | return I915_READ(D_COMP_BDW); | |
8752 | } | |
8753 | ||
3c4c9b81 PZ |
8754 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) |
8755 | { | |
772c2a51 | 8756 | if (IS_HASWELL(dev_priv)) { |
9f817501 | 8757 | mutex_lock(&dev_priv->pcu_lock); |
3c4c9b81 PZ |
8758 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, |
8759 | val)) | |
79cf219a | 8760 | DRM_DEBUG_KMS("Failed to write to D_COMP\n"); |
9f817501 | 8761 | mutex_unlock(&dev_priv->pcu_lock); |
3c4c9b81 | 8762 | } else { |
9ccd5aeb PZ |
8763 | I915_WRITE(D_COMP_BDW, val); |
8764 | POSTING_READ(D_COMP_BDW); | |
3c4c9b81 | 8765 | } |
be256dc7 PZ |
8766 | } |
8767 | ||
8768 | /* | |
8769 | * This function implements pieces of two sequences from BSpec: | |
8770 | * - Sequence for display software to disable LCPLL | |
8771 | * - Sequence for display software to allow package C8+ | |
8772 | * The steps implemented here are just the steps that actually touch the LCPLL | |
8773 | * register. Callers should take care of disabling all the display engine | |
8774 | * functions, doing the mode unset, fixing interrupts, etc. | |
8775 | */ | |
6ff58d53 PZ |
8776 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
8777 | bool switch_to_fclk, bool allow_power_down) | |
be256dc7 PZ |
8778 | { |
8779 | uint32_t val; | |
8780 | ||
8781 | assert_can_disable_lcpll(dev_priv); | |
8782 | ||
8783 | val = I915_READ(LCPLL_CTL); | |
8784 | ||
8785 | if (switch_to_fclk) { | |
8786 | val |= LCPLL_CD_SOURCE_FCLK; | |
8787 | I915_WRITE(LCPLL_CTL, val); | |
8788 | ||
f53dd63f ID |
8789 | if (wait_for_us(I915_READ(LCPLL_CTL) & |
8790 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) | |
be256dc7 PZ |
8791 | DRM_ERROR("Switching to FCLK failed\n"); |
8792 | ||
8793 | val = I915_READ(LCPLL_CTL); | |
8794 | } | |
8795 | ||
8796 | val |= LCPLL_PLL_DISABLE; | |
8797 | I915_WRITE(LCPLL_CTL, val); | |
8798 | POSTING_READ(LCPLL_CTL); | |
8799 | ||
24d8441d | 8800 | if (intel_wait_for_register(dev_priv, LCPLL_CTL, LCPLL_PLL_LOCK, 0, 1)) |
be256dc7 PZ |
8801 | DRM_ERROR("LCPLL still locked\n"); |
8802 | ||
9ccd5aeb | 8803 | val = hsw_read_dcomp(dev_priv); |
be256dc7 | 8804 | val |= D_COMP_COMP_DISABLE; |
3c4c9b81 | 8805 | hsw_write_dcomp(dev_priv, val); |
be256dc7 PZ |
8806 | ndelay(100); |
8807 | ||
9ccd5aeb PZ |
8808 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
8809 | 1)) | |
be256dc7 PZ |
8810 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
8811 | ||
8812 | if (allow_power_down) { | |
8813 | val = I915_READ(LCPLL_CTL); | |
8814 | val |= LCPLL_POWER_DOWN_ALLOW; | |
8815 | I915_WRITE(LCPLL_CTL, val); | |
8816 | POSTING_READ(LCPLL_CTL); | |
8817 | } | |
8818 | } | |
8819 | ||
8820 | /* | |
8821 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL | |
8822 | * source. | |
8823 | */ | |
6ff58d53 | 8824 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
be256dc7 PZ |
8825 | { |
8826 | uint32_t val; | |
8827 | ||
8828 | val = I915_READ(LCPLL_CTL); | |
8829 | ||
8830 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | | |
8831 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) | |
8832 | return; | |
8833 | ||
a8a8bd54 PZ |
8834 | /* |
8835 | * Make sure we're not on PC8 state before disabling PC8, otherwise | |
8836 | * we'll hang the machine. To prevent PC8 state, just enable force_wake. | |
a8a8bd54 | 8837 | */ |
59bad947 | 8838 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
215733fa | 8839 | |
be256dc7 PZ |
8840 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
8841 | val &= ~LCPLL_POWER_DOWN_ALLOW; | |
8842 | I915_WRITE(LCPLL_CTL, val); | |
35d8f2eb | 8843 | POSTING_READ(LCPLL_CTL); |
be256dc7 PZ |
8844 | } |
8845 | ||
9ccd5aeb | 8846 | val = hsw_read_dcomp(dev_priv); |
be256dc7 PZ |
8847 | val |= D_COMP_COMP_FORCE; |
8848 | val &= ~D_COMP_COMP_DISABLE; | |
3c4c9b81 | 8849 | hsw_write_dcomp(dev_priv, val); |
be256dc7 PZ |
8850 | |
8851 | val = I915_READ(LCPLL_CTL); | |
8852 | val &= ~LCPLL_PLL_DISABLE; | |
8853 | I915_WRITE(LCPLL_CTL, val); | |
8854 | ||
93220c08 CW |
8855 | if (intel_wait_for_register(dev_priv, |
8856 | LCPLL_CTL, LCPLL_PLL_LOCK, LCPLL_PLL_LOCK, | |
8857 | 5)) | |
be256dc7 PZ |
8858 | DRM_ERROR("LCPLL not locked yet\n"); |
8859 | ||
8860 | if (val & LCPLL_CD_SOURCE_FCLK) { | |
8861 | val = I915_READ(LCPLL_CTL); | |
8862 | val &= ~LCPLL_CD_SOURCE_FCLK; | |
8863 | I915_WRITE(LCPLL_CTL, val); | |
8864 | ||
f53dd63f ID |
8865 | if (wait_for_us((I915_READ(LCPLL_CTL) & |
8866 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) | |
be256dc7 PZ |
8867 | DRM_ERROR("Switching back to LCPLL failed\n"); |
8868 | } | |
215733fa | 8869 | |
59bad947 | 8870 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
4c75b940 | 8871 | intel_update_cdclk(dev_priv); |
be256dc7 PZ |
8872 | } |
8873 | ||
765dab67 PZ |
8874 | /* |
8875 | * Package states C8 and deeper are really deep PC states that can only be | |
8876 | * reached when all the devices on the system allow it, so even if the graphics | |
8877 | * device allows PC8+, it doesn't mean the system will actually get to these | |
8878 | * states. Our driver only allows PC8+ when going into runtime PM. | |
8879 | * | |
8880 | * The requirements for PC8+ are that all the outputs are disabled, the power | |
8881 | * well is disabled and most interrupts are disabled, and these are also | |
8882 | * requirements for runtime PM. When these conditions are met, we manually do | |
8883 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk | |
8884 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard | |
8885 | * hang the machine. | |
8886 | * | |
8887 | * When we really reach PC8 or deeper states (not just when we allow it) we lose | |
8888 | * the state of some registers, so when we come back from PC8+ we need to | |
8889 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't | |
8890 | * need to take care of the registers kept by RC6. Notice that this happens even | |
8891 | * if we don't put the device in PCI D3 state (which is what currently happens | |
8892 | * because of the runtime PM support). | |
8893 | * | |
8894 | * For more, read "Display Sequences for Package C8" on the hardware | |
8895 | * documentation. | |
8896 | */ | |
a14cb6fc | 8897 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
c67a470b | 8898 | { |
c67a470b PZ |
8899 | uint32_t val; |
8900 | ||
c67a470b PZ |
8901 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
8902 | ||
4f8036a2 | 8903 | if (HAS_PCH_LPT_LP(dev_priv)) { |
c67a470b PZ |
8904 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
8905 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; | |
8906 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); | |
8907 | } | |
8908 | ||
c39055b0 | 8909 | lpt_disable_clkout_dp(dev_priv); |
c67a470b PZ |
8910 | hsw_disable_lcpll(dev_priv, true, true); |
8911 | } | |
8912 | ||
a14cb6fc | 8913 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
c67a470b | 8914 | { |
c67a470b PZ |
8915 | uint32_t val; |
8916 | ||
c67a470b PZ |
8917 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
8918 | ||
8919 | hsw_restore_lcpll(dev_priv); | |
c39055b0 | 8920 | lpt_init_pch_refclk(dev_priv); |
c67a470b | 8921 | |
4f8036a2 | 8922 | if (HAS_PCH_LPT_LP(dev_priv)) { |
c67a470b PZ |
8923 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
8924 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; | |
8925 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); | |
8926 | } | |
c67a470b PZ |
8927 | } |
8928 | ||
190f68c5 ACO |
8929 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
8930 | struct intel_crtc_state *crtc_state) | |
09b4ddf9 | 8931 | { |
d7edc4e5 | 8932 | if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI)) { |
44a126ba PZ |
8933 | struct intel_encoder *encoder = |
8934 | intel_ddi_get_crtc_new_encoder(crtc_state); | |
8935 | ||
8936 | if (!intel_get_shared_dpll(crtc, crtc_state, encoder)) { | |
8937 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", | |
8938 | pipe_name(crtc->pipe)); | |
af3997b5 | 8939 | return -EINVAL; |
44a126ba | 8940 | } |
af3997b5 | 8941 | } |
716c2e55 | 8942 | |
c8f7a0db | 8943 | return 0; |
79e53945 JB |
8944 | } |
8945 | ||
8b0f7e06 KM |
8946 | static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv, |
8947 | enum port port, | |
8948 | struct intel_crtc_state *pipe_config) | |
8949 | { | |
8950 | enum intel_dpll_id id; | |
8951 | u32 temp; | |
8952 | ||
8953 | temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port); | |
dfbd4508 | 8954 | id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port); |
8b0f7e06 KM |
8955 | |
8956 | if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2)) | |
8957 | return; | |
8958 | ||
8959 | pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); | |
8960 | } | |
8961 | ||
3760b59c S |
8962 | static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv, |
8963 | enum port port, | |
8964 | struct intel_crtc_state *pipe_config) | |
8965 | { | |
8106ddbd ACO |
8966 | enum intel_dpll_id id; |
8967 | ||
3760b59c S |
8968 | switch (port) { |
8969 | case PORT_A: | |
08250c4b | 8970 | id = DPLL_ID_SKL_DPLL0; |
3760b59c S |
8971 | break; |
8972 | case PORT_B: | |
08250c4b | 8973 | id = DPLL_ID_SKL_DPLL1; |
3760b59c S |
8974 | break; |
8975 | case PORT_C: | |
08250c4b | 8976 | id = DPLL_ID_SKL_DPLL2; |
3760b59c S |
8977 | break; |
8978 | default: | |
8979 | DRM_ERROR("Incorrect port type\n"); | |
8106ddbd | 8980 | return; |
3760b59c | 8981 | } |
8106ddbd ACO |
8982 | |
8983 | pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); | |
3760b59c S |
8984 | } |
8985 | ||
96b7dfb7 S |
8986 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
8987 | enum port port, | |
5cec258b | 8988 | struct intel_crtc_state *pipe_config) |
96b7dfb7 | 8989 | { |
8106ddbd | 8990 | enum intel_dpll_id id; |
a3c988ea | 8991 | u32 temp; |
96b7dfb7 S |
8992 | |
8993 | temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port); | |
c856052a | 8994 | id = temp >> (port * 3 + 1); |
96b7dfb7 | 8995 | |
c856052a | 8996 | if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3)) |
8106ddbd | 8997 | return; |
8106ddbd ACO |
8998 | |
8999 | pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); | |
96b7dfb7 S |
9000 | } |
9001 | ||
7d2c8175 DL |
9002 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
9003 | enum port port, | |
5cec258b | 9004 | struct intel_crtc_state *pipe_config) |
7d2c8175 | 9005 | { |
8106ddbd | 9006 | enum intel_dpll_id id; |
c856052a | 9007 | uint32_t ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); |
8106ddbd | 9008 | |
c856052a | 9009 | switch (ddi_pll_sel) { |
7d2c8175 | 9010 | case PORT_CLK_SEL_WRPLL1: |
8106ddbd | 9011 | id = DPLL_ID_WRPLL1; |
7d2c8175 DL |
9012 | break; |
9013 | case PORT_CLK_SEL_WRPLL2: | |
8106ddbd | 9014 | id = DPLL_ID_WRPLL2; |
7d2c8175 | 9015 | break; |
00490c22 | 9016 | case PORT_CLK_SEL_SPLL: |
8106ddbd | 9017 | id = DPLL_ID_SPLL; |
79bd23da | 9018 | break; |
9d16da65 ACO |
9019 | case PORT_CLK_SEL_LCPLL_810: |
9020 | id = DPLL_ID_LCPLL_810; | |
9021 | break; | |
9022 | case PORT_CLK_SEL_LCPLL_1350: | |
9023 | id = DPLL_ID_LCPLL_1350; | |
9024 | break; | |
9025 | case PORT_CLK_SEL_LCPLL_2700: | |
9026 | id = DPLL_ID_LCPLL_2700; | |
9027 | break; | |
8106ddbd | 9028 | default: |
c856052a | 9029 | MISSING_CASE(ddi_pll_sel); |
8106ddbd ACO |
9030 | /* fall through */ |
9031 | case PORT_CLK_SEL_NONE: | |
8106ddbd | 9032 | return; |
7d2c8175 | 9033 | } |
8106ddbd ACO |
9034 | |
9035 | pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id); | |
7d2c8175 DL |
9036 | } |
9037 | ||
cf30429e JN |
9038 | static bool hsw_get_transcoder_state(struct intel_crtc *crtc, |
9039 | struct intel_crtc_state *pipe_config, | |
d8fc70b7 | 9040 | u64 *power_domain_mask) |
cf30429e JN |
9041 | { |
9042 | struct drm_device *dev = crtc->base.dev; | |
fac5e23e | 9043 | struct drm_i915_private *dev_priv = to_i915(dev); |
cf30429e JN |
9044 | enum intel_display_power_domain power_domain; |
9045 | u32 tmp; | |
9046 | ||
d9a7bc67 ID |
9047 | /* |
9048 | * The pipe->transcoder mapping is fixed with the exception of the eDP | |
9049 | * transcoder handled below. | |
9050 | */ | |
cf30429e JN |
9051 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
9052 | ||
9053 | /* | |
9054 | * XXX: Do intel_display_power_get_if_enabled before reading this (for | |
9055 | * consistency and less surprising code; it's in always on power). | |
9056 | */ | |
9057 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); | |
9058 | if (tmp & TRANS_DDI_FUNC_ENABLE) { | |
9059 | enum pipe trans_edp_pipe; | |
9060 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { | |
9061 | default: | |
9062 | WARN(1, "unknown pipe linked to edp transcoder\n"); | |
9063 | case TRANS_DDI_EDP_INPUT_A_ONOFF: | |
9064 | case TRANS_DDI_EDP_INPUT_A_ON: | |
9065 | trans_edp_pipe = PIPE_A; | |
9066 | break; | |
9067 | case TRANS_DDI_EDP_INPUT_B_ONOFF: | |
9068 | trans_edp_pipe = PIPE_B; | |
9069 | break; | |
9070 | case TRANS_DDI_EDP_INPUT_C_ONOFF: | |
9071 | trans_edp_pipe = PIPE_C; | |
9072 | break; | |
9073 | } | |
9074 | ||
9075 | if (trans_edp_pipe == crtc->pipe) | |
9076 | pipe_config->cpu_transcoder = TRANSCODER_EDP; | |
9077 | } | |
9078 | ||
9079 | power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder); | |
9080 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) | |
9081 | return false; | |
d8fc70b7 | 9082 | *power_domain_mask |= BIT_ULL(power_domain); |
cf30429e JN |
9083 | |
9084 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); | |
9085 | ||
9086 | return tmp & PIPECONF_ENABLE; | |
9087 | } | |
9088 | ||
4d1de975 JN |
9089 | static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc, |
9090 | struct intel_crtc_state *pipe_config, | |
d8fc70b7 | 9091 | u64 *power_domain_mask) |
4d1de975 JN |
9092 | { |
9093 | struct drm_device *dev = crtc->base.dev; | |
fac5e23e | 9094 | struct drm_i915_private *dev_priv = to_i915(dev); |
4d1de975 JN |
9095 | enum intel_display_power_domain power_domain; |
9096 | enum port port; | |
9097 | enum transcoder cpu_transcoder; | |
9098 | u32 tmp; | |
9099 | ||
4d1de975 JN |
9100 | for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) { |
9101 | if (port == PORT_A) | |
9102 | cpu_transcoder = TRANSCODER_DSI_A; | |
9103 | else | |
9104 | cpu_transcoder = TRANSCODER_DSI_C; | |
9105 | ||
9106 | power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); | |
9107 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) | |
9108 | continue; | |
d8fc70b7 | 9109 | *power_domain_mask |= BIT_ULL(power_domain); |
4d1de975 | 9110 | |
db18b6a6 ID |
9111 | /* |
9112 | * The PLL needs to be enabled with a valid divider | |
9113 | * configuration, otherwise accessing DSI registers will hang | |
9114 | * the machine. See BSpec North Display Engine | |
9115 | * registers/MIPI[BXT]. We can break out here early, since we | |
9116 | * need the same DSI PLL to be enabled for both DSI ports. | |
9117 | */ | |
9118 | if (!intel_dsi_pll_is_enabled(dev_priv)) | |
9119 | break; | |
9120 | ||
4d1de975 JN |
9121 | /* XXX: this works for video mode only */ |
9122 | tmp = I915_READ(BXT_MIPI_PORT_CTRL(port)); | |
9123 | if (!(tmp & DPI_ENABLE)) | |
9124 | continue; | |
9125 | ||
9126 | tmp = I915_READ(MIPI_CTRL(port)); | |
9127 | if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe)) | |
9128 | continue; | |
9129 | ||
9130 | pipe_config->cpu_transcoder = cpu_transcoder; | |
4d1de975 JN |
9131 | break; |
9132 | } | |
9133 | ||
d7edc4e5 | 9134 | return transcoder_is_dsi(pipe_config->cpu_transcoder); |
4d1de975 JN |
9135 | } |
9136 | ||
26804afd | 9137 | static void haswell_get_ddi_port_state(struct intel_crtc *crtc, |
5cec258b | 9138 | struct intel_crtc_state *pipe_config) |
26804afd | 9139 | { |
6315b5d3 | 9140 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
d452c5b6 | 9141 | struct intel_shared_dpll *pll; |
26804afd DV |
9142 | enum port port; |
9143 | uint32_t tmp; | |
9144 | ||
9145 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); | |
9146 | ||
9147 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; | |
9148 | ||
8b0f7e06 KM |
9149 | if (IS_CANNONLAKE(dev_priv)) |
9150 | cannonlake_get_ddi_pll(dev_priv, port, pipe_config); | |
9151 | else if (IS_GEN9_BC(dev_priv)) | |
96b7dfb7 | 9152 | skylake_get_ddi_pll(dev_priv, port, pipe_config); |
cc3f90f0 | 9153 | else if (IS_GEN9_LP(dev_priv)) |
3760b59c | 9154 | bxt_get_ddi_pll(dev_priv, port, pipe_config); |
96b7dfb7 S |
9155 | else |
9156 | haswell_get_ddi_pll(dev_priv, port, pipe_config); | |
9cd86933 | 9157 | |
8106ddbd ACO |
9158 | pll = pipe_config->shared_dpll; |
9159 | if (pll) { | |
2edd6443 ACO |
9160 | WARN_ON(!pll->funcs.get_hw_state(dev_priv, pll, |
9161 | &pipe_config->dpll_hw_state)); | |
d452c5b6 DV |
9162 | } |
9163 | ||
26804afd DV |
9164 | /* |
9165 | * Haswell has only FDI/PCH transcoder A. It is which is connected to | |
9166 | * DDI E. So just check whether this pipe is wired to DDI E and whether | |
9167 | * the PCH transcoder is on. | |
9168 | */ | |
6315b5d3 | 9169 | if (INTEL_GEN(dev_priv) < 9 && |
ca370455 | 9170 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { |
26804afd DV |
9171 | pipe_config->has_pch_encoder = true; |
9172 | ||
9173 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); | |
9174 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> | |
9175 | FDI_DP_PORT_WIDTH_SHIFT) + 1; | |
9176 | ||
9177 | ironlake_get_fdi_m_n_config(crtc, pipe_config); | |
9178 | } | |
9179 | } | |
9180 | ||
0e8ffe1b | 9181 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
5cec258b | 9182 | struct intel_crtc_state *pipe_config) |
0e8ffe1b | 9183 | { |
6315b5d3 | 9184 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
1729050e | 9185 | enum intel_display_power_domain power_domain; |
d8fc70b7 | 9186 | u64 power_domain_mask; |
cf30429e | 9187 | bool active; |
0e8ffe1b | 9188 | |
e79dfb51 | 9189 | intel_crtc_init_scalers(crtc, pipe_config); |
5fb9dadf | 9190 | |
1729050e ID |
9191 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
9192 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) | |
b5482bd0 | 9193 | return false; |
d8fc70b7 | 9194 | power_domain_mask = BIT_ULL(power_domain); |
1729050e | 9195 | |
8106ddbd | 9196 | pipe_config->shared_dpll = NULL; |
c0d43d62 | 9197 | |
cf30429e | 9198 | active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask); |
eccb140b | 9199 | |
cc3f90f0 | 9200 | if (IS_GEN9_LP(dev_priv) && |
d7edc4e5 VS |
9201 | bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_mask)) { |
9202 | WARN_ON(active); | |
9203 | active = true; | |
4d1de975 JN |
9204 | } |
9205 | ||
cf30429e | 9206 | if (!active) |
1729050e | 9207 | goto out; |
0e8ffe1b | 9208 | |
d7edc4e5 | 9209 | if (!transcoder_is_dsi(pipe_config->cpu_transcoder)) { |
4d1de975 JN |
9210 | haswell_get_ddi_port_state(crtc, pipe_config); |
9211 | intel_get_pipe_timings(crtc, pipe_config); | |
9212 | } | |
627eb5a3 | 9213 | |
bc58be60 | 9214 | intel_get_pipe_src_size(crtc, pipe_config); |
1bd1bd80 | 9215 | |
05dc698c LL |
9216 | pipe_config->gamma_mode = |
9217 | I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK; | |
9218 | ||
bd30ca2d | 9219 | if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) { |
b22ca995 SS |
9220 | u32 tmp = I915_READ(PIPEMISC(crtc->pipe)); |
9221 | bool clrspace_yuv = tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV; | |
9222 | ||
bd30ca2d | 9223 | if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10) { |
b22ca995 SS |
9224 | bool blend_mode_420 = tmp & |
9225 | PIPEMISC_YUV420_MODE_FULL_BLEND; | |
9226 | ||
9227 | pipe_config->ycbcr420 = tmp & PIPEMISC_YUV420_ENABLE; | |
9228 | if (pipe_config->ycbcr420 != clrspace_yuv || | |
9229 | pipe_config->ycbcr420 != blend_mode_420) | |
9230 | DRM_DEBUG_KMS("Bad 4:2:0 mode (%08x)\n", tmp); | |
9231 | } else if (clrspace_yuv) { | |
9232 | DRM_DEBUG_KMS("YCbCr 4:2:0 Unsupported\n"); | |
9233 | } | |
9234 | } | |
9235 | ||
1729050e ID |
9236 | power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
9237 | if (intel_display_power_get_if_enabled(dev_priv, power_domain)) { | |
d8fc70b7 | 9238 | power_domain_mask |= BIT_ULL(power_domain); |
6315b5d3 | 9239 | if (INTEL_GEN(dev_priv) >= 9) |
bd2e244f | 9240 | skylake_get_pfit_config(crtc, pipe_config); |
ff6d9f55 | 9241 | else |
1c132b44 | 9242 | ironlake_get_pfit_config(crtc, pipe_config); |
bd2e244f | 9243 | } |
88adfff1 | 9244 | |
772c2a51 | 9245 | if (IS_HASWELL(dev_priv)) |
e59150dc JB |
9246 | pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) && |
9247 | (I915_READ(IPS_CTL) & IPS_ENABLE); | |
42db64ef | 9248 | |
4d1de975 JN |
9249 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP && |
9250 | !transcoder_is_dsi(pipe_config->cpu_transcoder)) { | |
ebb69c95 CT |
9251 | pipe_config->pixel_multiplier = |
9252 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; | |
9253 | } else { | |
9254 | pipe_config->pixel_multiplier = 1; | |
9255 | } | |
6c49f241 | 9256 | |
1729050e ID |
9257 | out: |
9258 | for_each_power_domain(power_domain, power_domain_mask) | |
9259 | intel_display_power_put(dev_priv, power_domain); | |
9260 | ||
cf30429e | 9261 | return active; |
0e8ffe1b DV |
9262 | } |
9263 | ||
cd5dcbf1 | 9264 | static u32 intel_cursor_base(const struct intel_plane_state *plane_state) |
1cecc830 VS |
9265 | { |
9266 | struct drm_i915_private *dev_priv = | |
9267 | to_i915(plane_state->base.plane->dev); | |
9268 | const struct drm_framebuffer *fb = plane_state->base.fb; | |
9269 | const struct drm_i915_gem_object *obj = intel_fb_obj(fb); | |
9270 | u32 base; | |
9271 | ||
9272 | if (INTEL_INFO(dev_priv)->cursor_needs_physical) | |
9273 | base = obj->phys_handle->busaddr; | |
9274 | else | |
9275 | base = intel_plane_ggtt_offset(plane_state); | |
9276 | ||
1e7b4fd8 VS |
9277 | base += plane_state->main.offset; |
9278 | ||
1cecc830 VS |
9279 | /* ILK+ do this automagically */ |
9280 | if (HAS_GMCH_DISPLAY(dev_priv) && | |
a82256bc | 9281 | plane_state->base.rotation & DRM_MODE_ROTATE_180) |
1cecc830 VS |
9282 | base += (plane_state->base.crtc_h * |
9283 | plane_state->base.crtc_w - 1) * fb->format->cpp[0]; | |
9284 | ||
9285 | return base; | |
9286 | } | |
9287 | ||
ed270223 VS |
9288 | static u32 intel_cursor_position(const struct intel_plane_state *plane_state) |
9289 | { | |
9290 | int x = plane_state->base.crtc_x; | |
9291 | int y = plane_state->base.crtc_y; | |
9292 | u32 pos = 0; | |
9293 | ||
9294 | if (x < 0) { | |
9295 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; | |
9296 | x = -x; | |
9297 | } | |
9298 | pos |= x << CURSOR_X_SHIFT; | |
9299 | ||
9300 | if (y < 0) { | |
9301 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; | |
9302 | y = -y; | |
9303 | } | |
9304 | pos |= y << CURSOR_Y_SHIFT; | |
9305 | ||
9306 | return pos; | |
9307 | } | |
9308 | ||
3637ecf0 VS |
9309 | static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state) |
9310 | { | |
9311 | const struct drm_mode_config *config = | |
9312 | &plane_state->base.plane->dev->mode_config; | |
9313 | int width = plane_state->base.crtc_w; | |
9314 | int height = plane_state->base.crtc_h; | |
9315 | ||
9316 | return width > 0 && width <= config->cursor_width && | |
9317 | height > 0 && height <= config->cursor_height; | |
9318 | } | |
9319 | ||
659056f2 VS |
9320 | static int intel_check_cursor(struct intel_crtc_state *crtc_state, |
9321 | struct intel_plane_state *plane_state) | |
9322 | { | |
9323 | const struct drm_framebuffer *fb = plane_state->base.fb; | |
1e7b4fd8 VS |
9324 | int src_x, src_y; |
9325 | u32 offset; | |
659056f2 VS |
9326 | int ret; |
9327 | ||
9328 | ret = drm_plane_helper_check_state(&plane_state->base, | |
9329 | &plane_state->clip, | |
9330 | DRM_PLANE_HELPER_NO_SCALING, | |
9331 | DRM_PLANE_HELPER_NO_SCALING, | |
9332 | true, true); | |
9333 | if (ret) | |
9334 | return ret; | |
9335 | ||
9336 | if (!fb) | |
9337 | return 0; | |
9338 | ||
9339 | if (fb->modifier != DRM_FORMAT_MOD_LINEAR) { | |
9340 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); | |
9341 | return -EINVAL; | |
9342 | } | |
9343 | ||
1e7b4fd8 VS |
9344 | src_x = plane_state->base.src_x >> 16; |
9345 | src_y = plane_state->base.src_y >> 16; | |
9346 | ||
9347 | intel_add_fb_offsets(&src_x, &src_y, plane_state, 0); | |
9348 | offset = intel_compute_tile_offset(&src_x, &src_y, plane_state, 0); | |
9349 | ||
9350 | if (src_x != 0 || src_y != 0) { | |
9351 | DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n"); | |
9352 | return -EINVAL; | |
9353 | } | |
9354 | ||
9355 | plane_state->main.offset = offset; | |
9356 | ||
659056f2 VS |
9357 | return 0; |
9358 | } | |
9359 | ||
292889e1 VS |
9360 | static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state, |
9361 | const struct intel_plane_state *plane_state) | |
9362 | { | |
1e1bb871 | 9363 | const struct drm_framebuffer *fb = plane_state->base.fb; |
292889e1 | 9364 | |
292889e1 VS |
9365 | return CURSOR_ENABLE | |
9366 | CURSOR_GAMMA_ENABLE | | |
9367 | CURSOR_FORMAT_ARGB | | |
1e1bb871 | 9368 | CURSOR_STRIDE(fb->pitches[0]); |
292889e1 VS |
9369 | } |
9370 | ||
659056f2 VS |
9371 | static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state) |
9372 | { | |
659056f2 | 9373 | int width = plane_state->base.crtc_w; |
659056f2 VS |
9374 | |
9375 | /* | |
9376 | * 845g/865g are only limited by the width of their cursors, | |
9377 | * the height is arbitrary up to the precision of the register. | |
9378 | */ | |
3637ecf0 | 9379 | return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64); |
659056f2 VS |
9380 | } |
9381 | ||
9382 | static int i845_check_cursor(struct intel_plane *plane, | |
9383 | struct intel_crtc_state *crtc_state, | |
9384 | struct intel_plane_state *plane_state) | |
9385 | { | |
9386 | const struct drm_framebuffer *fb = plane_state->base.fb; | |
659056f2 VS |
9387 | int ret; |
9388 | ||
9389 | ret = intel_check_cursor(crtc_state, plane_state); | |
9390 | if (ret) | |
9391 | return ret; | |
9392 | ||
9393 | /* if we want to turn off the cursor ignore width and height */ | |
1e1bb871 | 9394 | if (!fb) |
659056f2 VS |
9395 | return 0; |
9396 | ||
9397 | /* Check for which cursor types we support */ | |
9398 | if (!i845_cursor_size_ok(plane_state)) { | |
9399 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", | |
9400 | plane_state->base.crtc_w, | |
9401 | plane_state->base.crtc_h); | |
9402 | return -EINVAL; | |
9403 | } | |
9404 | ||
1e1bb871 | 9405 | switch (fb->pitches[0]) { |
292889e1 VS |
9406 | case 256: |
9407 | case 512: | |
9408 | case 1024: | |
9409 | case 2048: | |
9410 | break; | |
1e1bb871 VS |
9411 | default: |
9412 | DRM_DEBUG_KMS("Invalid cursor stride (%u)\n", | |
9413 | fb->pitches[0]); | |
9414 | return -EINVAL; | |
292889e1 VS |
9415 | } |
9416 | ||
659056f2 VS |
9417 | plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state); |
9418 | ||
9419 | return 0; | |
292889e1 VS |
9420 | } |
9421 | ||
b2d03b0d VS |
9422 | static void i845_update_cursor(struct intel_plane *plane, |
9423 | const struct intel_crtc_state *crtc_state, | |
55a08b3f | 9424 | const struct intel_plane_state *plane_state) |
560b85bb | 9425 | { |
cd5dcbf1 | 9426 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
b2d03b0d VS |
9427 | u32 cntl = 0, base = 0, pos = 0, size = 0; |
9428 | unsigned long irqflags; | |
560b85bb | 9429 | |
936e71e3 | 9430 | if (plane_state && plane_state->base.visible) { |
55a08b3f ML |
9431 | unsigned int width = plane_state->base.crtc_w; |
9432 | unsigned int height = plane_state->base.crtc_h; | |
dc41c154 | 9433 | |
a0864d59 | 9434 | cntl = plane_state->ctl; |
dc41c154 | 9435 | size = (height << 12) | width; |
560b85bb | 9436 | |
b2d03b0d VS |
9437 | base = intel_cursor_base(plane_state); |
9438 | pos = intel_cursor_position(plane_state); | |
4b0e333e | 9439 | } |
560b85bb | 9440 | |
b2d03b0d | 9441 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
4726e0b0 | 9442 | |
e11ffddb VS |
9443 | /* On these chipsets we can only modify the base/size/stride |
9444 | * whilst the cursor is disabled. | |
9445 | */ | |
9446 | if (plane->cursor.base != base || | |
9447 | plane->cursor.size != size || | |
9448 | plane->cursor.cntl != cntl) { | |
dd584fc0 | 9449 | I915_WRITE_FW(CURCNTR(PIPE_A), 0); |
dd584fc0 | 9450 | I915_WRITE_FW(CURBASE(PIPE_A), base); |
dd584fc0 | 9451 | I915_WRITE_FW(CURSIZE, size); |
b2d03b0d | 9452 | I915_WRITE_FW(CURPOS(PIPE_A), pos); |
dd584fc0 | 9453 | I915_WRITE_FW(CURCNTR(PIPE_A), cntl); |
75343a44 | 9454 | |
e11ffddb VS |
9455 | plane->cursor.base = base; |
9456 | plane->cursor.size = size; | |
9457 | plane->cursor.cntl = cntl; | |
9458 | } else { | |
9459 | I915_WRITE_FW(CURPOS(PIPE_A), pos); | |
560b85bb | 9460 | } |
e11ffddb | 9461 | |
75343a44 | 9462 | POSTING_READ_FW(CURCNTR(PIPE_A)); |
b2d03b0d VS |
9463 | |
9464 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); | |
9465 | } | |
9466 | ||
9467 | static void i845_disable_cursor(struct intel_plane *plane, | |
9468 | struct intel_crtc *crtc) | |
9469 | { | |
9470 | i845_update_cursor(plane, NULL, NULL); | |
560b85bb CW |
9471 | } |
9472 | ||
d87ce764 VS |
9473 | static bool i845_cursor_get_hw_state(struct intel_plane *plane) |
9474 | { | |
9475 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); | |
9476 | enum intel_display_power_domain power_domain; | |
9477 | bool ret; | |
9478 | ||
9479 | power_domain = POWER_DOMAIN_PIPE(PIPE_A); | |
9480 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) | |
9481 | return false; | |
9482 | ||
9483 | ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE; | |
9484 | ||
9485 | intel_display_power_put(dev_priv, power_domain); | |
9486 | ||
9487 | return ret; | |
9488 | } | |
9489 | ||
292889e1 VS |
9490 | static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state, |
9491 | const struct intel_plane_state *plane_state) | |
9492 | { | |
9493 | struct drm_i915_private *dev_priv = | |
9494 | to_i915(plane_state->base.plane->dev); | |
9495 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); | |
292889e1 VS |
9496 | u32 cntl; |
9497 | ||
9498 | cntl = MCURSOR_GAMMA_ENABLE; | |
9499 | ||
9500 | if (HAS_DDI(dev_priv)) | |
9501 | cntl |= CURSOR_PIPE_CSC_ENABLE; | |
9502 | ||
d509e28b | 9503 | cntl |= MCURSOR_PIPE_SELECT(crtc->pipe); |
292889e1 VS |
9504 | |
9505 | switch (plane_state->base.crtc_w) { | |
9506 | case 64: | |
9507 | cntl |= CURSOR_MODE_64_ARGB_AX; | |
9508 | break; | |
9509 | case 128: | |
9510 | cntl |= CURSOR_MODE_128_ARGB_AX; | |
9511 | break; | |
9512 | case 256: | |
9513 | cntl |= CURSOR_MODE_256_ARGB_AX; | |
9514 | break; | |
9515 | default: | |
9516 | MISSING_CASE(plane_state->base.crtc_w); | |
9517 | return 0; | |
9518 | } | |
9519 | ||
c2c446ad | 9520 | if (plane_state->base.rotation & DRM_MODE_ROTATE_180) |
292889e1 VS |
9521 | cntl |= CURSOR_ROTATE_180; |
9522 | ||
9523 | return cntl; | |
9524 | } | |
9525 | ||
659056f2 | 9526 | static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state) |
65a21cd6 | 9527 | { |
024faac7 VS |
9528 | struct drm_i915_private *dev_priv = |
9529 | to_i915(plane_state->base.plane->dev); | |
659056f2 VS |
9530 | int width = plane_state->base.crtc_w; |
9531 | int height = plane_state->base.crtc_h; | |
4b0e333e | 9532 | |
3637ecf0 | 9533 | if (!intel_cursor_size_ok(plane_state)) |
659056f2 | 9534 | return false; |
4398ad45 | 9535 | |
024faac7 VS |
9536 | /* Cursor width is limited to a few power-of-two sizes */ |
9537 | switch (width) { | |
659056f2 VS |
9538 | case 256: |
9539 | case 128: | |
659056f2 VS |
9540 | case 64: |
9541 | break; | |
9542 | default: | |
9543 | return false; | |
65a21cd6 | 9544 | } |
4b0e333e | 9545 | |
024faac7 VS |
9546 | /* |
9547 | * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor | |
9548 | * height from 8 lines up to the cursor width, when the | |
9549 | * cursor is not rotated. Everything else requires square | |
9550 | * cursors. | |
9551 | */ | |
9552 | if (HAS_CUR_FBC(dev_priv) && | |
a82256bc | 9553 | plane_state->base.rotation & DRM_MODE_ROTATE_0) { |
024faac7 VS |
9554 | if (height < 8 || height > width) |
9555 | return false; | |
9556 | } else { | |
9557 | if (height != width) | |
9558 | return false; | |
9559 | } | |
99d1f387 | 9560 | |
659056f2 | 9561 | return true; |
65a21cd6 JB |
9562 | } |
9563 | ||
659056f2 VS |
9564 | static int i9xx_check_cursor(struct intel_plane *plane, |
9565 | struct intel_crtc_state *crtc_state, | |
9566 | struct intel_plane_state *plane_state) | |
cda4b7d3 | 9567 | { |
659056f2 VS |
9568 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
9569 | const struct drm_framebuffer *fb = plane_state->base.fb; | |
659056f2 | 9570 | enum pipe pipe = plane->pipe; |
659056f2 | 9571 | int ret; |
cda4b7d3 | 9572 | |
659056f2 VS |
9573 | ret = intel_check_cursor(crtc_state, plane_state); |
9574 | if (ret) | |
9575 | return ret; | |
cda4b7d3 | 9576 | |
659056f2 | 9577 | /* if we want to turn off the cursor ignore width and height */ |
1e1bb871 | 9578 | if (!fb) |
659056f2 | 9579 | return 0; |
55a08b3f | 9580 | |
659056f2 VS |
9581 | /* Check for which cursor types we support */ |
9582 | if (!i9xx_cursor_size_ok(plane_state)) { | |
9583 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", | |
9584 | plane_state->base.crtc_w, | |
9585 | plane_state->base.crtc_h); | |
9586 | return -EINVAL; | |
cda4b7d3 | 9587 | } |
cda4b7d3 | 9588 | |
1e1bb871 VS |
9589 | if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) { |
9590 | DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n", | |
9591 | fb->pitches[0], plane_state->base.crtc_w); | |
9592 | return -EINVAL; | |
659056f2 | 9593 | } |
dd584fc0 | 9594 | |
659056f2 VS |
9595 | /* |
9596 | * There's something wrong with the cursor on CHV pipe C. | |
9597 | * If it straddles the left edge of the screen then | |
9598 | * moving it away from the edge or disabling it often | |
9599 | * results in a pipe underrun, and often that can lead to | |
9600 | * dead pipe (constant underrun reported, and it scans | |
9601 | * out just a solid color). To recover from that, the | |
9602 | * display power well must be turned off and on again. | |
9603 | * Refuse the put the cursor into that compromised position. | |
9604 | */ | |
9605 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C && | |
9606 | plane_state->base.visible && plane_state->base.crtc_x < 0) { | |
9607 | DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n"); | |
9608 | return -EINVAL; | |
9609 | } | |
5efb3e28 | 9610 | |
659056f2 | 9611 | plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state); |
dd584fc0 | 9612 | |
659056f2 | 9613 | return 0; |
cda4b7d3 CW |
9614 | } |
9615 | ||
b2d03b0d VS |
9616 | static void i9xx_update_cursor(struct intel_plane *plane, |
9617 | const struct intel_crtc_state *crtc_state, | |
55a08b3f | 9618 | const struct intel_plane_state *plane_state) |
dc41c154 | 9619 | { |
cd5dcbf1 VS |
9620 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
9621 | enum pipe pipe = plane->pipe; | |
024faac7 | 9622 | u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0; |
b2d03b0d | 9623 | unsigned long irqflags; |
dc41c154 | 9624 | |
b2d03b0d | 9625 | if (plane_state && plane_state->base.visible) { |
a0864d59 | 9626 | cntl = plane_state->ctl; |
dc41c154 | 9627 | |
024faac7 VS |
9628 | if (plane_state->base.crtc_h != plane_state->base.crtc_w) |
9629 | fbc_ctl = CUR_FBC_CTL_EN | (plane_state->base.crtc_h - 1); | |
dc41c154 | 9630 | |
b2d03b0d VS |
9631 | base = intel_cursor_base(plane_state); |
9632 | pos = intel_cursor_position(plane_state); | |
9633 | } | |
9634 | ||
9635 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); | |
9636 | ||
e11ffddb VS |
9637 | /* |
9638 | * On some platforms writing CURCNTR first will also | |
9639 | * cause CURPOS to be armed by the CURBASE write. | |
9640 | * Without the CURCNTR write the CURPOS write would | |
8753d2bc VS |
9641 | * arm itself. Thus we always start the full update |
9642 | * with a CURCNTR write. | |
9643 | * | |
9644 | * On other platforms CURPOS always requires the | |
9645 | * CURBASE write to arm the update. Additonally | |
9646 | * a write to any of the cursor register will cancel | |
9647 | * an already armed cursor update. Thus leaving out | |
9648 | * the CURBASE write after CURPOS could lead to a | |
9649 | * cursor that doesn't appear to move, or even change | |
9650 | * shape. Thus we always write CURBASE. | |
e11ffddb VS |
9651 | * |
9652 | * CURCNTR and CUR_FBC_CTL are always | |
9653 | * armed by the CURBASE write only. | |
9654 | */ | |
9655 | if (plane->cursor.base != base || | |
9656 | plane->cursor.size != fbc_ctl || | |
9657 | plane->cursor.cntl != cntl) { | |
dd584fc0 | 9658 | I915_WRITE_FW(CURCNTR(pipe), cntl); |
e11ffddb VS |
9659 | if (HAS_CUR_FBC(dev_priv)) |
9660 | I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl); | |
b2d03b0d | 9661 | I915_WRITE_FW(CURPOS(pipe), pos); |
75343a44 VS |
9662 | I915_WRITE_FW(CURBASE(pipe), base); |
9663 | ||
e11ffddb VS |
9664 | plane->cursor.base = base; |
9665 | plane->cursor.size = fbc_ctl; | |
9666 | plane->cursor.cntl = cntl; | |
dc41c154 | 9667 | } else { |
e11ffddb | 9668 | I915_WRITE_FW(CURPOS(pipe), pos); |
8753d2bc | 9669 | I915_WRITE_FW(CURBASE(pipe), base); |
dc41c154 VS |
9670 | } |
9671 | ||
dd584fc0 | 9672 | POSTING_READ_FW(CURBASE(pipe)); |
99d1f387 | 9673 | |
b2d03b0d | 9674 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
65a21cd6 JB |
9675 | } |
9676 | ||
b2d03b0d VS |
9677 | static void i9xx_disable_cursor(struct intel_plane *plane, |
9678 | struct intel_crtc *crtc) | |
cda4b7d3 | 9679 | { |
b2d03b0d | 9680 | i9xx_update_cursor(plane, NULL, NULL); |
dc41c154 VS |
9681 | } |
9682 | ||
d87ce764 VS |
9683 | static bool i9xx_cursor_get_hw_state(struct intel_plane *plane) |
9684 | { | |
9685 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); | |
9686 | enum intel_display_power_domain power_domain; | |
9687 | enum pipe pipe = plane->pipe; | |
9688 | bool ret; | |
9689 | ||
9690 | /* | |
9691 | * Not 100% correct for planes that can move between pipes, | |
9692 | * but that's only the case for gen2-3 which don't have any | |
9693 | * display power wells. | |
9694 | */ | |
9695 | power_domain = POWER_DOMAIN_PIPE(pipe); | |
9696 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) | |
9697 | return false; | |
9698 | ||
9699 | ret = I915_READ(CURCNTR(pipe)) & CURSOR_MODE; | |
9700 | ||
9701 | intel_display_power_put(dev_priv, power_domain); | |
9702 | ||
9703 | return ret; | |
9704 | } | |
dc41c154 | 9705 | |
79e53945 | 9706 | /* VESA 640x480x72Hz mode to set on the pipe */ |
bacdcd55 | 9707 | static const struct drm_display_mode load_detect_mode = { |
79e53945 JB |
9708 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, |
9709 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), | |
9710 | }; | |
9711 | ||
a8bb6818 | 9712 | struct drm_framebuffer * |
24dbf51a CW |
9713 | intel_framebuffer_create(struct drm_i915_gem_object *obj, |
9714 | struct drm_mode_fb_cmd2 *mode_cmd) | |
d2dff872 CW |
9715 | { |
9716 | struct intel_framebuffer *intel_fb; | |
9717 | int ret; | |
9718 | ||
9719 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); | |
dcb1394e | 9720 | if (!intel_fb) |
d2dff872 | 9721 | return ERR_PTR(-ENOMEM); |
d2dff872 | 9722 | |
24dbf51a | 9723 | ret = intel_framebuffer_init(intel_fb, obj, mode_cmd); |
dd4916c5 DV |
9724 | if (ret) |
9725 | goto err; | |
d2dff872 CW |
9726 | |
9727 | return &intel_fb->base; | |
dcb1394e | 9728 | |
dd4916c5 | 9729 | err: |
dd4916c5 | 9730 | kfree(intel_fb); |
dd4916c5 | 9731 | return ERR_PTR(ret); |
d2dff872 CW |
9732 | } |
9733 | ||
9734 | static u32 | |
9735 | intel_framebuffer_pitch_for_width(int width, int bpp) | |
9736 | { | |
9737 | u32 pitch = DIV_ROUND_UP(width * bpp, 8); | |
9738 | return ALIGN(pitch, 64); | |
9739 | } | |
9740 | ||
9741 | static u32 | |
bacdcd55 | 9742 | intel_framebuffer_size_for_mode(const struct drm_display_mode *mode, int bpp) |
d2dff872 CW |
9743 | { |
9744 | u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp); | |
1267a26b | 9745 | return PAGE_ALIGN(pitch * mode->vdisplay); |
d2dff872 CW |
9746 | } |
9747 | ||
9748 | static struct drm_framebuffer * | |
9749 | intel_framebuffer_create_for_mode(struct drm_device *dev, | |
bacdcd55 | 9750 | const struct drm_display_mode *mode, |
d2dff872 CW |
9751 | int depth, int bpp) |
9752 | { | |
dcb1394e | 9753 | struct drm_framebuffer *fb; |
d2dff872 | 9754 | struct drm_i915_gem_object *obj; |
0fed39bd | 9755 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
d2dff872 | 9756 | |
12d79d78 | 9757 | obj = i915_gem_object_create(to_i915(dev), |
d2dff872 | 9758 | intel_framebuffer_size_for_mode(mode, bpp)); |
fe3db79b CW |
9759 | if (IS_ERR(obj)) |
9760 | return ERR_CAST(obj); | |
d2dff872 CW |
9761 | |
9762 | mode_cmd.width = mode->hdisplay; | |
9763 | mode_cmd.height = mode->vdisplay; | |
308e5bcb JB |
9764 | mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width, |
9765 | bpp); | |
5ca0c34a | 9766 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); |
d2dff872 | 9767 | |
24dbf51a | 9768 | fb = intel_framebuffer_create(obj, &mode_cmd); |
dcb1394e | 9769 | if (IS_ERR(fb)) |
f0cd5182 | 9770 | i915_gem_object_put(obj); |
dcb1394e LW |
9771 | |
9772 | return fb; | |
d2dff872 CW |
9773 | } |
9774 | ||
9775 | static struct drm_framebuffer * | |
9776 | mode_fits_in_fbdev(struct drm_device *dev, | |
bacdcd55 | 9777 | const struct drm_display_mode *mode) |
d2dff872 | 9778 | { |
0695726e | 9779 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
fac5e23e | 9780 | struct drm_i915_private *dev_priv = to_i915(dev); |
d2dff872 CW |
9781 | struct drm_i915_gem_object *obj; |
9782 | struct drm_framebuffer *fb; | |
9783 | ||
4c0e5528 | 9784 | if (!dev_priv->fbdev) |
d2dff872 CW |
9785 | return NULL; |
9786 | ||
4c0e5528 | 9787 | if (!dev_priv->fbdev->fb) |
d2dff872 CW |
9788 | return NULL; |
9789 | ||
4c0e5528 DV |
9790 | obj = dev_priv->fbdev->fb->obj; |
9791 | BUG_ON(!obj); | |
9792 | ||
8bcd4553 | 9793 | fb = &dev_priv->fbdev->fb->base; |
01f2c773 | 9794 | if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay, |
272725c7 | 9795 | fb->format->cpp[0] * 8)) |
d2dff872 CW |
9796 | return NULL; |
9797 | ||
01f2c773 | 9798 | if (obj->base.size < mode->vdisplay * fb->pitches[0]) |
d2dff872 CW |
9799 | return NULL; |
9800 | ||
c3ed1103 | 9801 | drm_framebuffer_get(fb); |
d2dff872 | 9802 | return fb; |
4520f53a DV |
9803 | #else |
9804 | return NULL; | |
9805 | #endif | |
d2dff872 CW |
9806 | } |
9807 | ||
d3a40d1b ACO |
9808 | static int intel_modeset_setup_plane_state(struct drm_atomic_state *state, |
9809 | struct drm_crtc *crtc, | |
bacdcd55 | 9810 | const struct drm_display_mode *mode, |
d3a40d1b ACO |
9811 | struct drm_framebuffer *fb, |
9812 | int x, int y) | |
9813 | { | |
9814 | struct drm_plane_state *plane_state; | |
9815 | int hdisplay, vdisplay; | |
9816 | int ret; | |
9817 | ||
9818 | plane_state = drm_atomic_get_plane_state(state, crtc->primary); | |
9819 | if (IS_ERR(plane_state)) | |
9820 | return PTR_ERR(plane_state); | |
9821 | ||
9822 | if (mode) | |
196cd5d3 | 9823 | drm_mode_get_hv_timing(mode, &hdisplay, &vdisplay); |
d3a40d1b ACO |
9824 | else |
9825 | hdisplay = vdisplay = 0; | |
9826 | ||
9827 | ret = drm_atomic_set_crtc_for_plane(plane_state, fb ? crtc : NULL); | |
9828 | if (ret) | |
9829 | return ret; | |
9830 | drm_atomic_set_fb_for_plane(plane_state, fb); | |
9831 | plane_state->crtc_x = 0; | |
9832 | plane_state->crtc_y = 0; | |
9833 | plane_state->crtc_w = hdisplay; | |
9834 | plane_state->crtc_h = vdisplay; | |
9835 | plane_state->src_x = x << 16; | |
9836 | plane_state->src_y = y << 16; | |
9837 | plane_state->src_w = hdisplay << 16; | |
9838 | plane_state->src_h = vdisplay << 16; | |
9839 | ||
9840 | return 0; | |
9841 | } | |
9842 | ||
6c5ed5ae | 9843 | int intel_get_load_detect_pipe(struct drm_connector *connector, |
bacdcd55 | 9844 | const struct drm_display_mode *mode, |
6c5ed5ae ML |
9845 | struct intel_load_detect_pipe *old, |
9846 | struct drm_modeset_acquire_ctx *ctx) | |
79e53945 JB |
9847 | { |
9848 | struct intel_crtc *intel_crtc; | |
d2434ab7 DV |
9849 | struct intel_encoder *intel_encoder = |
9850 | intel_attached_encoder(connector); | |
79e53945 | 9851 | struct drm_crtc *possible_crtc; |
4ef69c7a | 9852 | struct drm_encoder *encoder = &intel_encoder->base; |
79e53945 JB |
9853 | struct drm_crtc *crtc = NULL; |
9854 | struct drm_device *dev = encoder->dev; | |
0f0f74bc | 9855 | struct drm_i915_private *dev_priv = to_i915(dev); |
94352cf9 | 9856 | struct drm_framebuffer *fb; |
51fd371b | 9857 | struct drm_mode_config *config = &dev->mode_config; |
edde3617 | 9858 | struct drm_atomic_state *state = NULL, *restore_state = NULL; |
944b0c76 | 9859 | struct drm_connector_state *connector_state; |
4be07317 | 9860 | struct intel_crtc_state *crtc_state; |
51fd371b | 9861 | int ret, i = -1; |
79e53945 | 9862 | |
d2dff872 | 9863 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
c23cc417 | 9864 | connector->base.id, connector->name, |
8e329a03 | 9865 | encoder->base.id, encoder->name); |
d2dff872 | 9866 | |
edde3617 ML |
9867 | old->restore_state = NULL; |
9868 | ||
6c5ed5ae | 9869 | WARN_ON(!drm_modeset_is_locked(&config->connection_mutex)); |
6e9f798d | 9870 | |
79e53945 JB |
9871 | /* |
9872 | * Algorithm gets a little messy: | |
7a5e4805 | 9873 | * |
79e53945 JB |
9874 | * - if the connector already has an assigned crtc, use it (but make |
9875 | * sure it's on first) | |
7a5e4805 | 9876 | * |
79e53945 JB |
9877 | * - try to find the first unused crtc that can drive this connector, |
9878 | * and use that if we find one | |
79e53945 JB |
9879 | */ |
9880 | ||
9881 | /* See if we already have a CRTC for this connector */ | |
edde3617 ML |
9882 | if (connector->state->crtc) { |
9883 | crtc = connector->state->crtc; | |
8261b191 | 9884 | |
51fd371b | 9885 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
4d02e2de | 9886 | if (ret) |
ad3c558f | 9887 | goto fail; |
8261b191 CW |
9888 | |
9889 | /* Make sure the crtc and connector are running */ | |
edde3617 | 9890 | goto found; |
79e53945 JB |
9891 | } |
9892 | ||
9893 | /* Find an unused one (if possible) */ | |
70e1e0ec | 9894 | for_each_crtc(dev, possible_crtc) { |
79e53945 JB |
9895 | i++; |
9896 | if (!(encoder->possible_crtcs & (1 << i))) | |
9897 | continue; | |
edde3617 ML |
9898 | |
9899 | ret = drm_modeset_lock(&possible_crtc->mutex, ctx); | |
9900 | if (ret) | |
9901 | goto fail; | |
9902 | ||
9903 | if (possible_crtc->state->enable) { | |
9904 | drm_modeset_unlock(&possible_crtc->mutex); | |
a459249c | 9905 | continue; |
edde3617 | 9906 | } |
a459249c VS |
9907 | |
9908 | crtc = possible_crtc; | |
9909 | break; | |
79e53945 JB |
9910 | } |
9911 | ||
9912 | /* | |
9913 | * If we didn't find an unused CRTC, don't use any. | |
9914 | */ | |
9915 | if (!crtc) { | |
7173188d | 9916 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
f4bf77b4 | 9917 | ret = -ENODEV; |
ad3c558f | 9918 | goto fail; |
79e53945 JB |
9919 | } |
9920 | ||
edde3617 ML |
9921 | found: |
9922 | intel_crtc = to_intel_crtc(crtc); | |
9923 | ||
4d02e2de DV |
9924 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
9925 | if (ret) | |
ad3c558f | 9926 | goto fail; |
79e53945 | 9927 | |
83a57153 | 9928 | state = drm_atomic_state_alloc(dev); |
edde3617 ML |
9929 | restore_state = drm_atomic_state_alloc(dev); |
9930 | if (!state || !restore_state) { | |
9931 | ret = -ENOMEM; | |
9932 | goto fail; | |
9933 | } | |
83a57153 ACO |
9934 | |
9935 | state->acquire_ctx = ctx; | |
edde3617 | 9936 | restore_state->acquire_ctx = ctx; |
83a57153 | 9937 | |
944b0c76 ACO |
9938 | connector_state = drm_atomic_get_connector_state(state, connector); |
9939 | if (IS_ERR(connector_state)) { | |
9940 | ret = PTR_ERR(connector_state); | |
9941 | goto fail; | |
9942 | } | |
9943 | ||
edde3617 ML |
9944 | ret = drm_atomic_set_crtc_for_connector(connector_state, crtc); |
9945 | if (ret) | |
9946 | goto fail; | |
944b0c76 | 9947 | |
4be07317 ACO |
9948 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
9949 | if (IS_ERR(crtc_state)) { | |
9950 | ret = PTR_ERR(crtc_state); | |
9951 | goto fail; | |
9952 | } | |
9953 | ||
49d6fa21 | 9954 | crtc_state->base.active = crtc_state->base.enable = true; |
4be07317 | 9955 | |
6492711d CW |
9956 | if (!mode) |
9957 | mode = &load_detect_mode; | |
79e53945 | 9958 | |
d2dff872 CW |
9959 | /* We need a framebuffer large enough to accommodate all accesses |
9960 | * that the plane may generate whilst we perform load detection. | |
9961 | * We can not rely on the fbcon either being present (we get called | |
9962 | * during its initialisation to detect all boot displays, or it may | |
9963 | * not even exist) or that it is large enough to satisfy the | |
9964 | * requested mode. | |
9965 | */ | |
94352cf9 DV |
9966 | fb = mode_fits_in_fbdev(dev, mode); |
9967 | if (fb == NULL) { | |
d2dff872 | 9968 | DRM_DEBUG_KMS("creating tmp fb for load-detection\n"); |
94352cf9 | 9969 | fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32); |
d2dff872 CW |
9970 | } else |
9971 | DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); | |
94352cf9 | 9972 | if (IS_ERR(fb)) { |
d2dff872 | 9973 | DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); |
f4bf77b4 | 9974 | ret = PTR_ERR(fb); |
412b61d8 | 9975 | goto fail; |
79e53945 | 9976 | } |
79e53945 | 9977 | |
d3a40d1b | 9978 | ret = intel_modeset_setup_plane_state(state, crtc, mode, fb, 0, 0); |
2b3a2e9f | 9979 | drm_framebuffer_put(fb); |
d3a40d1b ACO |
9980 | if (ret) |
9981 | goto fail; | |
9982 | ||
edde3617 ML |
9983 | ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode); |
9984 | if (ret) | |
9985 | goto fail; | |
9986 | ||
9987 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector)); | |
9988 | if (!ret) | |
9989 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc)); | |
9990 | if (!ret) | |
9991 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_plane_state(restore_state, crtc->primary)); | |
9992 | if (ret) { | |
9993 | DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret); | |
9994 | goto fail; | |
9995 | } | |
8c7b5ccb | 9996 | |
3ba86073 ML |
9997 | ret = drm_atomic_commit(state); |
9998 | if (ret) { | |
6492711d | 9999 | DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); |
412b61d8 | 10000 | goto fail; |
79e53945 | 10001 | } |
edde3617 ML |
10002 | |
10003 | old->restore_state = restore_state; | |
7abbd11f | 10004 | drm_atomic_state_put(state); |
7173188d | 10005 | |
79e53945 | 10006 | /* let the connector get through one full cycle before testing */ |
0f0f74bc | 10007 | intel_wait_for_vblank(dev_priv, intel_crtc->pipe); |
7173188d | 10008 | return true; |
412b61d8 | 10009 | |
ad3c558f | 10010 | fail: |
7fb71c8f CW |
10011 | if (state) { |
10012 | drm_atomic_state_put(state); | |
10013 | state = NULL; | |
10014 | } | |
10015 | if (restore_state) { | |
10016 | drm_atomic_state_put(restore_state); | |
10017 | restore_state = NULL; | |
10018 | } | |
83a57153 | 10019 | |
6c5ed5ae ML |
10020 | if (ret == -EDEADLK) |
10021 | return ret; | |
51fd371b | 10022 | |
412b61d8 | 10023 | return false; |
79e53945 JB |
10024 | } |
10025 | ||
d2434ab7 | 10026 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
49172fee ACO |
10027 | struct intel_load_detect_pipe *old, |
10028 | struct drm_modeset_acquire_ctx *ctx) | |
79e53945 | 10029 | { |
d2434ab7 DV |
10030 | struct intel_encoder *intel_encoder = |
10031 | intel_attached_encoder(connector); | |
4ef69c7a | 10032 | struct drm_encoder *encoder = &intel_encoder->base; |
edde3617 | 10033 | struct drm_atomic_state *state = old->restore_state; |
d3a40d1b | 10034 | int ret; |
79e53945 | 10035 | |
d2dff872 | 10036 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
c23cc417 | 10037 | connector->base.id, connector->name, |
8e329a03 | 10038 | encoder->base.id, encoder->name); |
d2dff872 | 10039 | |
edde3617 | 10040 | if (!state) |
0622a53c | 10041 | return; |
79e53945 | 10042 | |
581e49fe | 10043 | ret = drm_atomic_helper_commit_duplicated_state(state, ctx); |
0853695c | 10044 | if (ret) |
edde3617 | 10045 | DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret); |
0853695c | 10046 | drm_atomic_state_put(state); |
79e53945 JB |
10047 | } |
10048 | ||
da4a1efa | 10049 | static int i9xx_pll_refclk(struct drm_device *dev, |
5cec258b | 10050 | const struct intel_crtc_state *pipe_config) |
da4a1efa | 10051 | { |
fac5e23e | 10052 | struct drm_i915_private *dev_priv = to_i915(dev); |
da4a1efa VS |
10053 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
10054 | ||
10055 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) | |
e91e941b | 10056 | return dev_priv->vbt.lvds_ssc_freq; |
6e266956 | 10057 | else if (HAS_PCH_SPLIT(dev_priv)) |
da4a1efa | 10058 | return 120000; |
5db94019 | 10059 | else if (!IS_GEN2(dev_priv)) |
da4a1efa VS |
10060 | return 96000; |
10061 | else | |
10062 | return 48000; | |
10063 | } | |
10064 | ||
79e53945 | 10065 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
f1f644dc | 10066 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
5cec258b | 10067 | struct intel_crtc_state *pipe_config) |
79e53945 | 10068 | { |
f1f644dc | 10069 | struct drm_device *dev = crtc->base.dev; |
fac5e23e | 10070 | struct drm_i915_private *dev_priv = to_i915(dev); |
f1f644dc | 10071 | int pipe = pipe_config->cpu_transcoder; |
293623f7 | 10072 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
79e53945 | 10073 | u32 fp; |
9e2c8475 | 10074 | struct dpll clock; |
dccbea3b | 10075 | int port_clock; |
da4a1efa | 10076 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
79e53945 JB |
10077 | |
10078 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) | |
293623f7 | 10079 | fp = pipe_config->dpll_hw_state.fp0; |
79e53945 | 10080 | else |
293623f7 | 10081 | fp = pipe_config->dpll_hw_state.fp1; |
79e53945 JB |
10082 | |
10083 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; | |
9b1e14f4 | 10084 | if (IS_PINEVIEW(dev_priv)) { |
f2b115e6 AJ |
10085 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; |
10086 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
2177832f SL |
10087 | } else { |
10088 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; | |
10089 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; | |
10090 | } | |
10091 | ||
5db94019 | 10092 | if (!IS_GEN2(dev_priv)) { |
9b1e14f4 | 10093 | if (IS_PINEVIEW(dev_priv)) |
f2b115e6 AJ |
10094 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> |
10095 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); | |
2177832f SL |
10096 | else |
10097 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> | |
79e53945 JB |
10098 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
10099 | ||
10100 | switch (dpll & DPLL_MODE_MASK) { | |
10101 | case DPLLB_MODE_DAC_SERIAL: | |
10102 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? | |
10103 | 5 : 10; | |
10104 | break; | |
10105 | case DPLLB_MODE_LVDS: | |
10106 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? | |
10107 | 7 : 14; | |
10108 | break; | |
10109 | default: | |
28c97730 | 10110 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
79e53945 | 10111 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
f1f644dc | 10112 | return; |
79e53945 JB |
10113 | } |
10114 | ||
9b1e14f4 | 10115 | if (IS_PINEVIEW(dev_priv)) |
dccbea3b | 10116 | port_clock = pnv_calc_dpll_params(refclk, &clock); |
ac58c3f0 | 10117 | else |
dccbea3b | 10118 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
79e53945 | 10119 | } else { |
50a0bc90 | 10120 | u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS); |
b1c560d1 | 10121 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
79e53945 JB |
10122 | |
10123 | if (is_lvds) { | |
10124 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> | |
10125 | DPLL_FPA01_P1_POST_DIV_SHIFT); | |
b1c560d1 VS |
10126 | |
10127 | if (lvds & LVDS_CLKB_POWER_UP) | |
10128 | clock.p2 = 7; | |
10129 | else | |
10130 | clock.p2 = 14; | |
79e53945 JB |
10131 | } else { |
10132 | if (dpll & PLL_P1_DIVIDE_BY_TWO) | |
10133 | clock.p1 = 2; | |
10134 | else { | |
10135 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> | |
10136 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; | |
10137 | } | |
10138 | if (dpll & PLL_P2_DIVIDE_BY_4) | |
10139 | clock.p2 = 4; | |
10140 | else | |
10141 | clock.p2 = 2; | |
79e53945 | 10142 | } |
da4a1efa | 10143 | |
dccbea3b | 10144 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
79e53945 JB |
10145 | } |
10146 | ||
18442d08 VS |
10147 | /* |
10148 | * This value includes pixel_multiplier. We will use | |
241bfc38 | 10149 | * port_clock to compute adjusted_mode.crtc_clock in the |
18442d08 VS |
10150 | * encoder's get_config() function. |
10151 | */ | |
dccbea3b | 10152 | pipe_config->port_clock = port_clock; |
f1f644dc JB |
10153 | } |
10154 | ||
6878da05 VS |
10155 | int intel_dotclock_calculate(int link_freq, |
10156 | const struct intel_link_m_n *m_n) | |
f1f644dc | 10157 | { |
f1f644dc JB |
10158 | /* |
10159 | * The calculation for the data clock is: | |
1041a02f | 10160 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
f1f644dc | 10161 | * But we want to avoid losing precison if possible, so: |
1041a02f | 10162 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
f1f644dc JB |
10163 | * |
10164 | * and the link clock is simpler: | |
1041a02f | 10165 | * link_clock = (m * link_clock) / n |
f1f644dc JB |
10166 | */ |
10167 | ||
6878da05 VS |
10168 | if (!m_n->link_n) |
10169 | return 0; | |
f1f644dc | 10170 | |
3123698f | 10171 | return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n); |
6878da05 | 10172 | } |
f1f644dc | 10173 | |
18442d08 | 10174 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
5cec258b | 10175 | struct intel_crtc_state *pipe_config) |
6878da05 | 10176 | { |
e3b247da | 10177 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
79e53945 | 10178 | |
18442d08 VS |
10179 | /* read out port_clock from the DPLL */ |
10180 | i9xx_crtc_clock_get(crtc, pipe_config); | |
f1f644dc | 10181 | |
f1f644dc | 10182 | /* |
e3b247da VS |
10183 | * In case there is an active pipe without active ports, |
10184 | * we may need some idea for the dotclock anyway. | |
10185 | * Calculate one based on the FDI configuration. | |
79e53945 | 10186 | */ |
2d112de7 | 10187 | pipe_config->base.adjusted_mode.crtc_clock = |
21a727b3 | 10188 | intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config), |
18442d08 | 10189 | &pipe_config->fdi_m_n); |
79e53945 JB |
10190 | } |
10191 | ||
de330815 VS |
10192 | /* Returns the currently programmed mode of the given encoder. */ |
10193 | struct drm_display_mode * | |
10194 | intel_encoder_current_mode(struct intel_encoder *encoder) | |
79e53945 | 10195 | { |
de330815 VS |
10196 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
10197 | struct intel_crtc_state *crtc_state; | |
79e53945 | 10198 | struct drm_display_mode *mode; |
de330815 VS |
10199 | struct intel_crtc *crtc; |
10200 | enum pipe pipe; | |
10201 | ||
10202 | if (!encoder->get_hw_state(encoder, &pipe)) | |
10203 | return NULL; | |
10204 | ||
10205 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); | |
79e53945 JB |
10206 | |
10207 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); | |
10208 | if (!mode) | |
10209 | return NULL; | |
10210 | ||
de330815 VS |
10211 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
10212 | if (!crtc_state) { | |
3f36b937 TU |
10213 | kfree(mode); |
10214 | return NULL; | |
10215 | } | |
10216 | ||
de330815 | 10217 | crtc_state->base.crtc = &crtc->base; |
79e53945 | 10218 | |
de330815 VS |
10219 | if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) { |
10220 | kfree(crtc_state); | |
10221 | kfree(mode); | |
10222 | return NULL; | |
10223 | } | |
79e53945 | 10224 | |
de330815 | 10225 | encoder->get_config(encoder, crtc_state); |
79e53945 | 10226 | |
de330815 | 10227 | intel_mode_from_pipe_config(mode, crtc_state); |
79e53945 | 10228 | |
de330815 | 10229 | kfree(crtc_state); |
3f36b937 | 10230 | |
79e53945 JB |
10231 | return mode; |
10232 | } | |
10233 | ||
10234 | static void intel_crtc_destroy(struct drm_crtc *crtc) | |
10235 | { | |
10236 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
10237 | ||
10238 | drm_crtc_cleanup(crtc); | |
10239 | kfree(intel_crtc); | |
10240 | } | |
10241 | ||
5a21b665 DV |
10242 | /** |
10243 | * intel_wm_need_update - Check whether watermarks need updating | |
10244 | * @plane: drm plane | |
10245 | * @state: new plane state | |
10246 | * | |
10247 | * Check current plane state versus the new one to determine whether | |
10248 | * watermarks need to be recalculated. | |
10249 | * | |
10250 | * Returns true or false. | |
10251 | */ | |
10252 | static bool intel_wm_need_update(struct drm_plane *plane, | |
10253 | struct drm_plane_state *state) | |
10254 | { | |
10255 | struct intel_plane_state *new = to_intel_plane_state(state); | |
10256 | struct intel_plane_state *cur = to_intel_plane_state(plane->state); | |
10257 | ||
10258 | /* Update watermarks on tiling or size changes. */ | |
936e71e3 | 10259 | if (new->base.visible != cur->base.visible) |
5a21b665 DV |
10260 | return true; |
10261 | ||
10262 | if (!cur->base.fb || !new->base.fb) | |
10263 | return false; | |
10264 | ||
bae781b2 | 10265 | if (cur->base.fb->modifier != new->base.fb->modifier || |
5a21b665 | 10266 | cur->base.rotation != new->base.rotation || |
936e71e3 VS |
10267 | drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) || |
10268 | drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) || | |
10269 | drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) || | |
10270 | drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst)) | |
5a21b665 DV |
10271 | return true; |
10272 | ||
10273 | return false; | |
10274 | } | |
10275 | ||
b2b55502 | 10276 | static bool needs_scaling(const struct intel_plane_state *state) |
5a21b665 | 10277 | { |
936e71e3 VS |
10278 | int src_w = drm_rect_width(&state->base.src) >> 16; |
10279 | int src_h = drm_rect_height(&state->base.src) >> 16; | |
10280 | int dst_w = drm_rect_width(&state->base.dst); | |
10281 | int dst_h = drm_rect_height(&state->base.dst); | |
5a21b665 DV |
10282 | |
10283 | return (src_w != dst_w || src_h != dst_h); | |
10284 | } | |
d21fbe87 | 10285 | |
b2b55502 VS |
10286 | int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state, |
10287 | struct drm_crtc_state *crtc_state, | |
10288 | const struct intel_plane_state *old_plane_state, | |
da20eabd ML |
10289 | struct drm_plane_state *plane_state) |
10290 | { | |
ab1d3a0e | 10291 | struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state); |
da20eabd ML |
10292 | struct drm_crtc *crtc = crtc_state->crtc; |
10293 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
e9728bd8 | 10294 | struct intel_plane *plane = to_intel_plane(plane_state->plane); |
da20eabd | 10295 | struct drm_device *dev = crtc->dev; |
ed4a6a7c | 10296 | struct drm_i915_private *dev_priv = to_i915(dev); |
da20eabd | 10297 | bool mode_changed = needs_modeset(crtc_state); |
b2b55502 | 10298 | bool was_crtc_enabled = old_crtc_state->base.active; |
da20eabd | 10299 | bool is_crtc_enabled = crtc_state->active; |
da20eabd ML |
10300 | bool turn_off, turn_on, visible, was_visible; |
10301 | struct drm_framebuffer *fb = plane_state->fb; | |
78108b7c | 10302 | int ret; |
da20eabd | 10303 | |
e9728bd8 | 10304 | if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) { |
da20eabd ML |
10305 | ret = skl_update_scaler_plane( |
10306 | to_intel_crtc_state(crtc_state), | |
10307 | to_intel_plane_state(plane_state)); | |
10308 | if (ret) | |
10309 | return ret; | |
10310 | } | |
10311 | ||
936e71e3 | 10312 | was_visible = old_plane_state->base.visible; |
1d4258db | 10313 | visible = plane_state->visible; |
da20eabd ML |
10314 | |
10315 | if (!was_crtc_enabled && WARN_ON(was_visible)) | |
10316 | was_visible = false; | |
10317 | ||
35c08f43 ML |
10318 | /* |
10319 | * Visibility is calculated as if the crtc was on, but | |
10320 | * after scaler setup everything depends on it being off | |
10321 | * when the crtc isn't active. | |
f818ffea VS |
10322 | * |
10323 | * FIXME this is wrong for watermarks. Watermarks should also | |
10324 | * be computed as if the pipe would be active. Perhaps move | |
10325 | * per-plane wm computation to the .check_plane() hook, and | |
10326 | * only combine the results from all planes in the current place? | |
35c08f43 | 10327 | */ |
e9728bd8 | 10328 | if (!is_crtc_enabled) { |
1d4258db | 10329 | plane_state->visible = visible = false; |
e9728bd8 VS |
10330 | to_intel_crtc_state(crtc_state)->active_planes &= ~BIT(plane->id); |
10331 | } | |
da20eabd ML |
10332 | |
10333 | if (!was_visible && !visible) | |
10334 | return 0; | |
10335 | ||
e8861675 ML |
10336 | if (fb != old_plane_state->base.fb) |
10337 | pipe_config->fb_changed = true; | |
10338 | ||
da20eabd ML |
10339 | turn_off = was_visible && (!visible || mode_changed); |
10340 | turn_on = visible && (!was_visible || mode_changed); | |
10341 | ||
72660ce0 | 10342 | DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n", |
e9728bd8 VS |
10343 | intel_crtc->base.base.id, intel_crtc->base.name, |
10344 | plane->base.base.id, plane->base.name, | |
72660ce0 | 10345 | fb ? fb->base.id : -1); |
da20eabd | 10346 | |
72660ce0 | 10347 | DRM_DEBUG_ATOMIC("[PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n", |
e9728bd8 | 10348 | plane->base.base.id, plane->base.name, |
72660ce0 | 10349 | was_visible, visible, |
da20eabd ML |
10350 | turn_off, turn_on, mode_changed); |
10351 | ||
caed361d | 10352 | if (turn_on) { |
04548cba | 10353 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) |
b4ede6df | 10354 | pipe_config->update_wm_pre = true; |
caed361d VS |
10355 | |
10356 | /* must disable cxsr around plane enable/disable */ | |
e9728bd8 | 10357 | if (plane->id != PLANE_CURSOR) |
caed361d VS |
10358 | pipe_config->disable_cxsr = true; |
10359 | } else if (turn_off) { | |
04548cba | 10360 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) |
b4ede6df | 10361 | pipe_config->update_wm_post = true; |
92826fcd | 10362 | |
852eb00d | 10363 | /* must disable cxsr around plane enable/disable */ |
e9728bd8 | 10364 | if (plane->id != PLANE_CURSOR) |
ab1d3a0e | 10365 | pipe_config->disable_cxsr = true; |
e9728bd8 | 10366 | } else if (intel_wm_need_update(&plane->base, plane_state)) { |
04548cba | 10367 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) { |
b4ede6df VS |
10368 | /* FIXME bollocks */ |
10369 | pipe_config->update_wm_pre = true; | |
10370 | pipe_config->update_wm_post = true; | |
10371 | } | |
852eb00d | 10372 | } |
da20eabd | 10373 | |
8be6ca85 | 10374 | if (visible || was_visible) |
e9728bd8 | 10375 | pipe_config->fb_bits |= plane->frontbuffer_bit; |
a9ff8714 | 10376 | |
31ae71fc ML |
10377 | /* |
10378 | * WaCxSRDisabledForSpriteScaling:ivb | |
10379 | * | |
10380 | * cstate->update_wm was already set above, so this flag will | |
10381 | * take effect when we commit and program watermarks. | |
10382 | */ | |
e9728bd8 | 10383 | if (plane->id == PLANE_SPRITE0 && IS_IVYBRIDGE(dev_priv) && |
31ae71fc ML |
10384 | needs_scaling(to_intel_plane_state(plane_state)) && |
10385 | !needs_scaling(old_plane_state)) | |
10386 | pipe_config->disable_lp_wm = true; | |
d21fbe87 | 10387 | |
da20eabd ML |
10388 | return 0; |
10389 | } | |
10390 | ||
6d3a1ce7 ML |
10391 | static bool encoders_cloneable(const struct intel_encoder *a, |
10392 | const struct intel_encoder *b) | |
10393 | { | |
10394 | /* masks could be asymmetric, so check both ways */ | |
10395 | return a == b || (a->cloneable & (1 << b->type) && | |
10396 | b->cloneable & (1 << a->type)); | |
10397 | } | |
10398 | ||
10399 | static bool check_single_encoder_cloning(struct drm_atomic_state *state, | |
10400 | struct intel_crtc *crtc, | |
10401 | struct intel_encoder *encoder) | |
10402 | { | |
10403 | struct intel_encoder *source_encoder; | |
10404 | struct drm_connector *connector; | |
10405 | struct drm_connector_state *connector_state; | |
10406 | int i; | |
10407 | ||
aa5e9b47 | 10408 | for_each_new_connector_in_state(state, connector, connector_state, i) { |
6d3a1ce7 ML |
10409 | if (connector_state->crtc != &crtc->base) |
10410 | continue; | |
10411 | ||
10412 | source_encoder = | |
10413 | to_intel_encoder(connector_state->best_encoder); | |
10414 | if (!encoders_cloneable(encoder, source_encoder)) | |
10415 | return false; | |
10416 | } | |
10417 | ||
10418 | return true; | |
10419 | } | |
10420 | ||
6d3a1ce7 ML |
10421 | static int intel_crtc_atomic_check(struct drm_crtc *crtc, |
10422 | struct drm_crtc_state *crtc_state) | |
10423 | { | |
cf5a15be | 10424 | struct drm_device *dev = crtc->dev; |
fac5e23e | 10425 | struct drm_i915_private *dev_priv = to_i915(dev); |
6d3a1ce7 | 10426 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
cf5a15be ML |
10427 | struct intel_crtc_state *pipe_config = |
10428 | to_intel_crtc_state(crtc_state); | |
6d3a1ce7 | 10429 | struct drm_atomic_state *state = crtc_state->state; |
4d20cd86 | 10430 | int ret; |
6d3a1ce7 ML |
10431 | bool mode_changed = needs_modeset(crtc_state); |
10432 | ||
852eb00d | 10433 | if (mode_changed && !crtc_state->active) |
caed361d | 10434 | pipe_config->update_wm_post = true; |
eddfcbcd | 10435 | |
ad421372 ML |
10436 | if (mode_changed && crtc_state->enable && |
10437 | dev_priv->display.crtc_compute_clock && | |
8106ddbd | 10438 | !WARN_ON(pipe_config->shared_dpll)) { |
ad421372 ML |
10439 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, |
10440 | pipe_config); | |
10441 | if (ret) | |
10442 | return ret; | |
10443 | } | |
10444 | ||
82cf435b LL |
10445 | if (crtc_state->color_mgmt_changed) { |
10446 | ret = intel_color_check(crtc, crtc_state); | |
10447 | if (ret) | |
10448 | return ret; | |
e7852a4b LL |
10449 | |
10450 | /* | |
10451 | * Changing color management on Intel hardware is | |
10452 | * handled as part of planes update. | |
10453 | */ | |
10454 | crtc_state->planes_changed = true; | |
82cf435b LL |
10455 | } |
10456 | ||
e435d6e5 | 10457 | ret = 0; |
86c8bbbe | 10458 | if (dev_priv->display.compute_pipe_wm) { |
e3bddded | 10459 | ret = dev_priv->display.compute_pipe_wm(pipe_config); |
ed4a6a7c MR |
10460 | if (ret) { |
10461 | DRM_DEBUG_KMS("Target pipe watermarks are invalid\n"); | |
10462 | return ret; | |
10463 | } | |
10464 | } | |
10465 | ||
10466 | if (dev_priv->display.compute_intermediate_wm && | |
10467 | !to_intel_atomic_state(state)->skip_intermediate_wm) { | |
10468 | if (WARN_ON(!dev_priv->display.compute_pipe_wm)) | |
10469 | return 0; | |
10470 | ||
10471 | /* | |
10472 | * Calculate 'intermediate' watermarks that satisfy both the | |
10473 | * old state and the new state. We can program these | |
10474 | * immediately. | |
10475 | */ | |
6315b5d3 | 10476 | ret = dev_priv->display.compute_intermediate_wm(dev, |
ed4a6a7c MR |
10477 | intel_crtc, |
10478 | pipe_config); | |
10479 | if (ret) { | |
10480 | DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n"); | |
86c8bbbe | 10481 | return ret; |
ed4a6a7c | 10482 | } |
e3d5457c VS |
10483 | } else if (dev_priv->display.compute_intermediate_wm) { |
10484 | if (HAS_PCH_SPLIT(dev_priv) && INTEL_GEN(dev_priv) < 9) | |
10485 | pipe_config->wm.ilk.intermediate = pipe_config->wm.ilk.optimal; | |
86c8bbbe MR |
10486 | } |
10487 | ||
6315b5d3 | 10488 | if (INTEL_GEN(dev_priv) >= 9) { |
e435d6e5 ML |
10489 | if (mode_changed) |
10490 | ret = skl_update_scaler_crtc(pipe_config); | |
10491 | ||
73b0ca8e MK |
10492 | if (!ret) |
10493 | ret = skl_check_pipe_max_pixel_rate(intel_crtc, | |
10494 | pipe_config); | |
e435d6e5 | 10495 | if (!ret) |
6ebc6923 | 10496 | ret = intel_atomic_setup_scalers(dev_priv, intel_crtc, |
e435d6e5 ML |
10497 | pipe_config); |
10498 | } | |
10499 | ||
10500 | return ret; | |
6d3a1ce7 ML |
10501 | } |
10502 | ||
65b38e0d | 10503 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { |
5a21b665 DV |
10504 | .atomic_begin = intel_begin_crtc_commit, |
10505 | .atomic_flush = intel_finish_crtc_commit, | |
6d3a1ce7 | 10506 | .atomic_check = intel_crtc_atomic_check, |
f6e5b160 CW |
10507 | }; |
10508 | ||
d29b2f9d ACO |
10509 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) |
10510 | { | |
10511 | struct intel_connector *connector; | |
f9e905ca | 10512 | struct drm_connector_list_iter conn_iter; |
d29b2f9d | 10513 | |
f9e905ca DV |
10514 | drm_connector_list_iter_begin(dev, &conn_iter); |
10515 | for_each_intel_connector_iter(connector, &conn_iter) { | |
8863dc7f DV |
10516 | if (connector->base.state->crtc) |
10517 | drm_connector_unreference(&connector->base); | |
10518 | ||
d29b2f9d ACO |
10519 | if (connector->base.encoder) { |
10520 | connector->base.state->best_encoder = | |
10521 | connector->base.encoder; | |
10522 | connector->base.state->crtc = | |
10523 | connector->base.encoder->crtc; | |
8863dc7f DV |
10524 | |
10525 | drm_connector_reference(&connector->base); | |
d29b2f9d ACO |
10526 | } else { |
10527 | connector->base.state->best_encoder = NULL; | |
10528 | connector->base.state->crtc = NULL; | |
10529 | } | |
10530 | } | |
f9e905ca | 10531 | drm_connector_list_iter_end(&conn_iter); |
d29b2f9d ACO |
10532 | } |
10533 | ||
050f7aeb | 10534 | static void |
eba905b2 | 10535 | connected_sink_compute_bpp(struct intel_connector *connector, |
5cec258b | 10536 | struct intel_crtc_state *pipe_config) |
050f7aeb | 10537 | { |
6a2a5c5d | 10538 | const struct drm_display_info *info = &connector->base.display_info; |
050f7aeb DV |
10539 | int bpp = pipe_config->pipe_bpp; |
10540 | ||
10541 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n", | |
6a2a5c5d VS |
10542 | connector->base.base.id, |
10543 | connector->base.name); | |
050f7aeb DV |
10544 | |
10545 | /* Don't use an invalid EDID bpc value */ | |
6a2a5c5d | 10546 | if (info->bpc != 0 && info->bpc * 3 < bpp) { |
050f7aeb | 10547 | DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n", |
6a2a5c5d VS |
10548 | bpp, info->bpc * 3); |
10549 | pipe_config->pipe_bpp = info->bpc * 3; | |
050f7aeb DV |
10550 | } |
10551 | ||
196f954e | 10552 | /* Clamp bpp to 8 on screens without EDID 1.4 */ |
6a2a5c5d | 10553 | if (info->bpc == 0 && bpp > 24) { |
196f954e MK |
10554 | DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n", |
10555 | bpp); | |
10556 | pipe_config->pipe_bpp = 24; | |
050f7aeb DV |
10557 | } |
10558 | } | |
10559 | ||
4e53c2e0 | 10560 | static int |
050f7aeb | 10561 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
5cec258b | 10562 | struct intel_crtc_state *pipe_config) |
4e53c2e0 | 10563 | { |
9beb5fea | 10564 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
1486017f | 10565 | struct drm_atomic_state *state; |
da3ced29 ACO |
10566 | struct drm_connector *connector; |
10567 | struct drm_connector_state *connector_state; | |
1486017f | 10568 | int bpp, i; |
4e53c2e0 | 10569 | |
9beb5fea TU |
10570 | if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
10571 | IS_CHERRYVIEW(dev_priv))) | |
4e53c2e0 | 10572 | bpp = 10*3; |
9beb5fea | 10573 | else if (INTEL_GEN(dev_priv) >= 5) |
d328c9d7 DV |
10574 | bpp = 12*3; |
10575 | else | |
10576 | bpp = 8*3; | |
10577 | ||
4e53c2e0 | 10578 | |
4e53c2e0 DV |
10579 | pipe_config->pipe_bpp = bpp; |
10580 | ||
1486017f ACO |
10581 | state = pipe_config->base.state; |
10582 | ||
4e53c2e0 | 10583 | /* Clamp display bpp to EDID value */ |
aa5e9b47 | 10584 | for_each_new_connector_in_state(state, connector, connector_state, i) { |
da3ced29 | 10585 | if (connector_state->crtc != &crtc->base) |
4e53c2e0 DV |
10586 | continue; |
10587 | ||
da3ced29 ACO |
10588 | connected_sink_compute_bpp(to_intel_connector(connector), |
10589 | pipe_config); | |
4e53c2e0 DV |
10590 | } |
10591 | ||
10592 | return bpp; | |
10593 | } | |
10594 | ||
644db711 DV |
10595 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
10596 | { | |
10597 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " | |
10598 | "type: 0x%x flags: 0x%x\n", | |
1342830c | 10599 | mode->crtc_clock, |
644db711 DV |
10600 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
10601 | mode->crtc_hsync_end, mode->crtc_htotal, | |
10602 | mode->crtc_vdisplay, mode->crtc_vsync_start, | |
10603 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); | |
10604 | } | |
10605 | ||
f6982332 TU |
10606 | static inline void |
10607 | intel_dump_m_n_config(struct intel_crtc_state *pipe_config, char *id, | |
a4309657 | 10608 | unsigned int lane_count, struct intel_link_m_n *m_n) |
f6982332 | 10609 | { |
a4309657 TU |
10610 | DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
10611 | id, lane_count, | |
f6982332 TU |
10612 | m_n->gmch_m, m_n->gmch_n, |
10613 | m_n->link_m, m_n->link_n, m_n->tu); | |
10614 | } | |
10615 | ||
40b2be41 VS |
10616 | #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x |
10617 | ||
10618 | static const char * const output_type_str[] = { | |
10619 | OUTPUT_TYPE(UNUSED), | |
10620 | OUTPUT_TYPE(ANALOG), | |
10621 | OUTPUT_TYPE(DVO), | |
10622 | OUTPUT_TYPE(SDVO), | |
10623 | OUTPUT_TYPE(LVDS), | |
10624 | OUTPUT_TYPE(TVOUT), | |
10625 | OUTPUT_TYPE(HDMI), | |
10626 | OUTPUT_TYPE(DP), | |
10627 | OUTPUT_TYPE(EDP), | |
10628 | OUTPUT_TYPE(DSI), | |
10629 | OUTPUT_TYPE(UNKNOWN), | |
10630 | OUTPUT_TYPE(DP_MST), | |
10631 | }; | |
10632 | ||
10633 | #undef OUTPUT_TYPE | |
10634 | ||
10635 | static void snprintf_output_types(char *buf, size_t len, | |
10636 | unsigned int output_types) | |
10637 | { | |
10638 | char *str = buf; | |
10639 | int i; | |
10640 | ||
10641 | str[0] = '\0'; | |
10642 | ||
10643 | for (i = 0; i < ARRAY_SIZE(output_type_str); i++) { | |
10644 | int r; | |
10645 | ||
10646 | if ((output_types & BIT(i)) == 0) | |
10647 | continue; | |
10648 | ||
10649 | r = snprintf(str, len, "%s%s", | |
10650 | str != buf ? "," : "", output_type_str[i]); | |
10651 | if (r >= len) | |
10652 | break; | |
10653 | str += r; | |
10654 | len -= r; | |
10655 | ||
10656 | output_types &= ~BIT(i); | |
10657 | } | |
10658 | ||
10659 | WARN_ON_ONCE(output_types != 0); | |
10660 | } | |
10661 | ||
c0b03411 | 10662 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
5cec258b | 10663 | struct intel_crtc_state *pipe_config, |
c0b03411 DV |
10664 | const char *context) |
10665 | { | |
6a60cd87 | 10666 | struct drm_device *dev = crtc->base.dev; |
4f8036a2 | 10667 | struct drm_i915_private *dev_priv = to_i915(dev); |
6a60cd87 CK |
10668 | struct drm_plane *plane; |
10669 | struct intel_plane *intel_plane; | |
10670 | struct intel_plane_state *state; | |
10671 | struct drm_framebuffer *fb; | |
40b2be41 | 10672 | char buf[64]; |
6a60cd87 | 10673 | |
66766e4f TU |
10674 | DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n", |
10675 | crtc->base.base.id, crtc->base.name, context); | |
c0b03411 | 10676 | |
40b2be41 VS |
10677 | snprintf_output_types(buf, sizeof(buf), pipe_config->output_types); |
10678 | DRM_DEBUG_KMS("output_types: %s (0x%x)\n", | |
10679 | buf, pipe_config->output_types); | |
10680 | ||
2c89429e TU |
10681 | DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n", |
10682 | transcoder_name(pipe_config->cpu_transcoder), | |
c0b03411 | 10683 | pipe_config->pipe_bpp, pipe_config->dither); |
a4309657 TU |
10684 | |
10685 | if (pipe_config->has_pch_encoder) | |
10686 | intel_dump_m_n_config(pipe_config, "fdi", | |
10687 | pipe_config->fdi_lanes, | |
10688 | &pipe_config->fdi_m_n); | |
f6982332 | 10689 | |
b22ca995 SS |
10690 | if (pipe_config->ycbcr420) |
10691 | DRM_DEBUG_KMS("YCbCr 4:2:0 output enabled\n"); | |
10692 | ||
f6982332 | 10693 | if (intel_crtc_has_dp_encoder(pipe_config)) { |
a4309657 TU |
10694 | intel_dump_m_n_config(pipe_config, "dp m_n", |
10695 | pipe_config->lane_count, &pipe_config->dp_m_n); | |
d806e682 TU |
10696 | if (pipe_config->has_drrs) |
10697 | intel_dump_m_n_config(pipe_config, "dp m2_n2", | |
10698 | pipe_config->lane_count, | |
10699 | &pipe_config->dp_m2_n2); | |
f6982332 | 10700 | } |
b95af8be | 10701 | |
55072d19 | 10702 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
2c89429e | 10703 | pipe_config->has_audio, pipe_config->has_infoframe); |
55072d19 | 10704 | |
c0b03411 | 10705 | DRM_DEBUG_KMS("requested mode:\n"); |
2d112de7 | 10706 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
c0b03411 | 10707 | DRM_DEBUG_KMS("adjusted mode:\n"); |
2d112de7 ACO |
10708 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
10709 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); | |
a7d1b3f4 | 10710 | DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n", |
2c89429e | 10711 | pipe_config->port_clock, |
a7d1b3f4 VS |
10712 | pipe_config->pipe_src_w, pipe_config->pipe_src_h, |
10713 | pipe_config->pixel_rate); | |
dd2f616d TU |
10714 | |
10715 | if (INTEL_GEN(dev_priv) >= 9) | |
10716 | DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n", | |
10717 | crtc->num_scalers, | |
10718 | pipe_config->scaler_state.scaler_users, | |
10719 | pipe_config->scaler_state.scaler_id); | |
a74f8375 TU |
10720 | |
10721 | if (HAS_GMCH_DISPLAY(dev_priv)) | |
10722 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", | |
10723 | pipe_config->gmch_pfit.control, | |
10724 | pipe_config->gmch_pfit.pgm_ratios, | |
10725 | pipe_config->gmch_pfit.lvds_border_bits); | |
10726 | else | |
10727 | DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n", | |
10728 | pipe_config->pch_pfit.pos, | |
10729 | pipe_config->pch_pfit.size, | |
08c4d7fc | 10730 | enableddisabled(pipe_config->pch_pfit.enabled)); |
a74f8375 | 10731 | |
2c89429e TU |
10732 | DRM_DEBUG_KMS("ips: %i, double wide: %i\n", |
10733 | pipe_config->ips_enabled, pipe_config->double_wide); | |
6a60cd87 | 10734 | |
f50b79f0 | 10735 | intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state); |
415ff0f6 | 10736 | |
6a60cd87 CK |
10737 | DRM_DEBUG_KMS("planes on this crtc\n"); |
10738 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { | |
b3c11ac2 | 10739 | struct drm_format_name_buf format_name; |
6a60cd87 CK |
10740 | intel_plane = to_intel_plane(plane); |
10741 | if (intel_plane->pipe != crtc->pipe) | |
10742 | continue; | |
10743 | ||
10744 | state = to_intel_plane_state(plane->state); | |
10745 | fb = state->base.fb; | |
10746 | if (!fb) { | |
1d577e02 VS |
10747 | DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n", |
10748 | plane->base.id, plane->name, state->scaler_id); | |
6a60cd87 CK |
10749 | continue; |
10750 | } | |
10751 | ||
dd2f616d TU |
10752 | DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n", |
10753 | plane->base.id, plane->name, | |
b3c11ac2 | 10754 | fb->base.id, fb->width, fb->height, |
438b74a5 | 10755 | drm_get_format_name(fb->format->format, &format_name)); |
dd2f616d TU |
10756 | if (INTEL_GEN(dev_priv) >= 9) |
10757 | DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n", | |
10758 | state->scaler_id, | |
10759 | state->base.src.x1 >> 16, | |
10760 | state->base.src.y1 >> 16, | |
10761 | drm_rect_width(&state->base.src) >> 16, | |
10762 | drm_rect_height(&state->base.src) >> 16, | |
10763 | state->base.dst.x1, state->base.dst.y1, | |
10764 | drm_rect_width(&state->base.dst), | |
10765 | drm_rect_height(&state->base.dst)); | |
6a60cd87 | 10766 | } |
c0b03411 DV |
10767 | } |
10768 | ||
5448a00d | 10769 | static bool check_digital_port_conflicts(struct drm_atomic_state *state) |
00f0b378 | 10770 | { |
5448a00d | 10771 | struct drm_device *dev = state->dev; |
da3ced29 | 10772 | struct drm_connector *connector; |
2fd96b41 | 10773 | struct drm_connector_list_iter conn_iter; |
00f0b378 | 10774 | unsigned int used_ports = 0; |
477321e0 | 10775 | unsigned int used_mst_ports = 0; |
00f0b378 VS |
10776 | |
10777 | /* | |
10778 | * Walk the connector list instead of the encoder | |
10779 | * list to detect the problem on ddi platforms | |
10780 | * where there's just one encoder per digital port. | |
10781 | */ | |
2fd96b41 GP |
10782 | drm_connector_list_iter_begin(dev, &conn_iter); |
10783 | drm_for_each_connector_iter(connector, &conn_iter) { | |
0bff4858 VS |
10784 | struct drm_connector_state *connector_state; |
10785 | struct intel_encoder *encoder; | |
10786 | ||
10787 | connector_state = drm_atomic_get_existing_connector_state(state, connector); | |
10788 | if (!connector_state) | |
10789 | connector_state = connector->state; | |
10790 | ||
5448a00d | 10791 | if (!connector_state->best_encoder) |
00f0b378 VS |
10792 | continue; |
10793 | ||
5448a00d ACO |
10794 | encoder = to_intel_encoder(connector_state->best_encoder); |
10795 | ||
10796 | WARN_ON(!connector_state->crtc); | |
00f0b378 VS |
10797 | |
10798 | switch (encoder->type) { | |
10799 | unsigned int port_mask; | |
10800 | case INTEL_OUTPUT_UNKNOWN: | |
4f8036a2 | 10801 | if (WARN_ON(!HAS_DDI(to_i915(dev)))) |
00f0b378 | 10802 | break; |
cca0502b | 10803 | case INTEL_OUTPUT_DP: |
00f0b378 VS |
10804 | case INTEL_OUTPUT_HDMI: |
10805 | case INTEL_OUTPUT_EDP: | |
10806 | port_mask = 1 << enc_to_dig_port(&encoder->base)->port; | |
10807 | ||
10808 | /* the same port mustn't appear more than once */ | |
10809 | if (used_ports & port_mask) | |
10810 | return false; | |
10811 | ||
10812 | used_ports |= port_mask; | |
477321e0 VS |
10813 | break; |
10814 | case INTEL_OUTPUT_DP_MST: | |
10815 | used_mst_ports |= | |
10816 | 1 << enc_to_mst(&encoder->base)->primary->port; | |
10817 | break; | |
00f0b378 VS |
10818 | default: |
10819 | break; | |
10820 | } | |
10821 | } | |
2fd96b41 | 10822 | drm_connector_list_iter_end(&conn_iter); |
00f0b378 | 10823 | |
477321e0 VS |
10824 | /* can't mix MST and SST/HDMI on the same port */ |
10825 | if (used_ports & used_mst_ports) | |
10826 | return false; | |
10827 | ||
00f0b378 VS |
10828 | return true; |
10829 | } | |
10830 | ||
83a57153 ACO |
10831 | static void |
10832 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) | |
10833 | { | |
ff32c54e VS |
10834 | struct drm_i915_private *dev_priv = |
10835 | to_i915(crtc_state->base.crtc->dev); | |
663a3640 | 10836 | struct intel_crtc_scaler_state scaler_state; |
4978cc93 | 10837 | struct intel_dpll_hw_state dpll_hw_state; |
8106ddbd | 10838 | struct intel_shared_dpll *shared_dpll; |
ff32c54e | 10839 | struct intel_crtc_wm_state wm_state; |
6e644626 | 10840 | bool force_thru, ips_force_disable; |
83a57153 | 10841 | |
7546a384 ACO |
10842 | /* FIXME: before the switch to atomic started, a new pipe_config was |
10843 | * kzalloc'd. Code that depends on any field being zero should be | |
10844 | * fixed, so that the crtc_state can be safely duplicated. For now, | |
10845 | * only fields that are know to not cause problems are preserved. */ | |
10846 | ||
663a3640 | 10847 | scaler_state = crtc_state->scaler_state; |
4978cc93 ACO |
10848 | shared_dpll = crtc_state->shared_dpll; |
10849 | dpll_hw_state = crtc_state->dpll_hw_state; | |
c4e2d043 | 10850 | force_thru = crtc_state->pch_pfit.force_thru; |
6e644626 | 10851 | ips_force_disable = crtc_state->ips_force_disable; |
04548cba VS |
10852 | if (IS_G4X(dev_priv) || |
10853 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) | |
ff32c54e | 10854 | wm_state = crtc_state->wm; |
4978cc93 | 10855 | |
d2fa80a5 CW |
10856 | /* Keep base drm_crtc_state intact, only clear our extended struct */ |
10857 | BUILD_BUG_ON(offsetof(struct intel_crtc_state, base)); | |
10858 | memset(&crtc_state->base + 1, 0, | |
10859 | sizeof(*crtc_state) - sizeof(crtc_state->base)); | |
4978cc93 | 10860 | |
663a3640 | 10861 | crtc_state->scaler_state = scaler_state; |
4978cc93 ACO |
10862 | crtc_state->shared_dpll = shared_dpll; |
10863 | crtc_state->dpll_hw_state = dpll_hw_state; | |
c4e2d043 | 10864 | crtc_state->pch_pfit.force_thru = force_thru; |
6e644626 | 10865 | crtc_state->ips_force_disable = ips_force_disable; |
04548cba VS |
10866 | if (IS_G4X(dev_priv) || |
10867 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) | |
ff32c54e | 10868 | crtc_state->wm = wm_state; |
83a57153 ACO |
10869 | } |
10870 | ||
548ee15b | 10871 | static int |
b8cecdf5 | 10872 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
b359283a | 10873 | struct intel_crtc_state *pipe_config) |
ee7b9f93 | 10874 | { |
b359283a | 10875 | struct drm_atomic_state *state = pipe_config->base.state; |
7758a113 | 10876 | struct intel_encoder *encoder; |
da3ced29 | 10877 | struct drm_connector *connector; |
0b901879 | 10878 | struct drm_connector_state *connector_state; |
d328c9d7 | 10879 | int base_bpp, ret = -EINVAL; |
0b901879 | 10880 | int i; |
e29c22c0 | 10881 | bool retry = true; |
ee7b9f93 | 10882 | |
83a57153 | 10883 | clear_intel_crtc_state(pipe_config); |
7758a113 | 10884 | |
e143a21c DV |
10885 | pipe_config->cpu_transcoder = |
10886 | (enum transcoder) to_intel_crtc(crtc)->pipe; | |
b8cecdf5 | 10887 | |
2960bc9c ID |
10888 | /* |
10889 | * Sanitize sync polarity flags based on requested ones. If neither | |
10890 | * positive or negative polarity is requested, treat this as meaning | |
10891 | * negative polarity. | |
10892 | */ | |
2d112de7 | 10893 | if (!(pipe_config->base.adjusted_mode.flags & |
2960bc9c | 10894 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
2d112de7 | 10895 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
2960bc9c | 10896 | |
2d112de7 | 10897 | if (!(pipe_config->base.adjusted_mode.flags & |
2960bc9c | 10898 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
2d112de7 | 10899 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
2960bc9c | 10900 | |
d328c9d7 DV |
10901 | base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
10902 | pipe_config); | |
10903 | if (base_bpp < 0) | |
4e53c2e0 DV |
10904 | goto fail; |
10905 | ||
e41a56be VS |
10906 | /* |
10907 | * Determine the real pipe dimensions. Note that stereo modes can | |
10908 | * increase the actual pipe size due to the frame doubling and | |
10909 | * insertion of additional space for blanks between the frame. This | |
10910 | * is stored in the crtc timings. We use the requested mode to do this | |
10911 | * computation to clearly distinguish it from the adjusted mode, which | |
10912 | * can be changed by the connectors in the below retry loop. | |
10913 | */ | |
196cd5d3 | 10914 | drm_mode_get_hv_timing(&pipe_config->base.mode, |
ecb7e16b GP |
10915 | &pipe_config->pipe_src_w, |
10916 | &pipe_config->pipe_src_h); | |
e41a56be | 10917 | |
aa5e9b47 | 10918 | for_each_new_connector_in_state(state, connector, connector_state, i) { |
253c84c8 VS |
10919 | if (connector_state->crtc != crtc) |
10920 | continue; | |
10921 | ||
10922 | encoder = to_intel_encoder(connector_state->best_encoder); | |
10923 | ||
e25148d0 VS |
10924 | if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) { |
10925 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); | |
10926 | goto fail; | |
10927 | } | |
10928 | ||
253c84c8 VS |
10929 | /* |
10930 | * Determine output_types before calling the .compute_config() | |
10931 | * hooks so that the hooks can use this information safely. | |
10932 | */ | |
10933 | pipe_config->output_types |= 1 << encoder->type; | |
10934 | } | |
10935 | ||
e29c22c0 | 10936 | encoder_retry: |
ef1b460d | 10937 | /* Ensure the port clock defaults are reset when retrying. */ |
ff9a6750 | 10938 | pipe_config->port_clock = 0; |
ef1b460d | 10939 | pipe_config->pixel_multiplier = 1; |
ff9a6750 | 10940 | |
135c81b8 | 10941 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
2d112de7 ACO |
10942 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
10943 | CRTC_STEREO_DOUBLE); | |
135c81b8 | 10944 | |
7758a113 DV |
10945 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
10946 | * adjust it according to limitations or connector properties, and also | |
10947 | * a chance to reject the mode entirely. | |
47f1c6c9 | 10948 | */ |
aa5e9b47 | 10949 | for_each_new_connector_in_state(state, connector, connector_state, i) { |
0b901879 | 10950 | if (connector_state->crtc != crtc) |
7758a113 | 10951 | continue; |
7ae89233 | 10952 | |
0b901879 ACO |
10953 | encoder = to_intel_encoder(connector_state->best_encoder); |
10954 | ||
0a478c27 | 10955 | if (!(encoder->compute_config(encoder, pipe_config, connector_state))) { |
efea6e8e | 10956 | DRM_DEBUG_KMS("Encoder config failure\n"); |
7758a113 DV |
10957 | goto fail; |
10958 | } | |
ee7b9f93 | 10959 | } |
47f1c6c9 | 10960 | |
ff9a6750 DV |
10961 | /* Set default port clock if not overwritten by the encoder. Needs to be |
10962 | * done afterwards in case the encoder adjusts the mode. */ | |
10963 | if (!pipe_config->port_clock) | |
2d112de7 | 10964 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
241bfc38 | 10965 | * pipe_config->pixel_multiplier; |
ff9a6750 | 10966 | |
a43f6e0f | 10967 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
e29c22c0 | 10968 | if (ret < 0) { |
7758a113 DV |
10969 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
10970 | goto fail; | |
ee7b9f93 | 10971 | } |
e29c22c0 DV |
10972 | |
10973 | if (ret == RETRY) { | |
10974 | if (WARN(!retry, "loop in pipe configuration computation\n")) { | |
10975 | ret = -EINVAL; | |
10976 | goto fail; | |
10977 | } | |
10978 | ||
10979 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); | |
10980 | retry = false; | |
10981 | goto encoder_retry; | |
10982 | } | |
10983 | ||
e8fa4270 | 10984 | /* Dithering seems to not pass-through bits correctly when it should, so |
611032bf MN |
10985 | * only enable it on 6bpc panels and when its not a compliance |
10986 | * test requesting 6bpc video pattern. | |
10987 | */ | |
10988 | pipe_config->dither = (pipe_config->pipe_bpp == 6*3) && | |
10989 | !pipe_config->dither_force_disable; | |
62f0ace5 | 10990 | DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n", |
d328c9d7 | 10991 | base_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
4e53c2e0 | 10992 | |
7758a113 | 10993 | fail: |
548ee15b | 10994 | return ret; |
ee7b9f93 | 10995 | } |
47f1c6c9 | 10996 | |
ea9d758d | 10997 | static void |
4740b0f2 | 10998 | intel_modeset_update_crtc_state(struct drm_atomic_state *state) |
ea9d758d | 10999 | { |
0a9ab303 | 11000 | struct drm_crtc *crtc; |
aa5e9b47 | 11001 | struct drm_crtc_state *new_crtc_state; |
8a75d157 | 11002 | int i; |
ea9d758d | 11003 | |
7668851f | 11004 | /* Double check state. */ |
aa5e9b47 ML |
11005 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
11006 | to_intel_crtc(crtc)->config = to_intel_crtc_state(new_crtc_state); | |
fc467a22 | 11007 | |
61067a5e ML |
11008 | /* |
11009 | * Update legacy state to satisfy fbc code. This can | |
11010 | * be removed when fbc uses the atomic state. | |
11011 | */ | |
11012 | if (drm_atomic_get_existing_plane_state(state, crtc->primary)) { | |
11013 | struct drm_plane_state *plane_state = crtc->primary->state; | |
11014 | ||
11015 | crtc->primary->fb = plane_state->fb; | |
11016 | crtc->x = plane_state->src_x >> 16; | |
11017 | crtc->y = plane_state->src_y >> 16; | |
11018 | } | |
ea9d758d | 11019 | } |
ea9d758d DV |
11020 | } |
11021 | ||
3bd26263 | 11022 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
f1f644dc | 11023 | { |
3bd26263 | 11024 | int diff; |
f1f644dc JB |
11025 | |
11026 | if (clock1 == clock2) | |
11027 | return true; | |
11028 | ||
11029 | if (!clock1 || !clock2) | |
11030 | return false; | |
11031 | ||
11032 | diff = abs(clock1 - clock2); | |
11033 | ||
11034 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) | |
11035 | return true; | |
11036 | ||
11037 | return false; | |
11038 | } | |
11039 | ||
cfb23ed6 ML |
11040 | static bool |
11041 | intel_compare_m_n(unsigned int m, unsigned int n, | |
11042 | unsigned int m2, unsigned int n2, | |
11043 | bool exact) | |
11044 | { | |
11045 | if (m == m2 && n == n2) | |
11046 | return true; | |
11047 | ||
11048 | if (exact || !m || !n || !m2 || !n2) | |
11049 | return false; | |
11050 | ||
11051 | BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX); | |
11052 | ||
31d10b57 ML |
11053 | if (n > n2) { |
11054 | while (n > n2) { | |
cfb23ed6 ML |
11055 | m2 <<= 1; |
11056 | n2 <<= 1; | |
11057 | } | |
31d10b57 ML |
11058 | } else if (n < n2) { |
11059 | while (n < n2) { | |
cfb23ed6 ML |
11060 | m <<= 1; |
11061 | n <<= 1; | |
11062 | } | |
11063 | } | |
11064 | ||
31d10b57 ML |
11065 | if (n != n2) |
11066 | return false; | |
11067 | ||
11068 | return intel_fuzzy_clock_check(m, m2); | |
cfb23ed6 ML |
11069 | } |
11070 | ||
11071 | static bool | |
11072 | intel_compare_link_m_n(const struct intel_link_m_n *m_n, | |
11073 | struct intel_link_m_n *m2_n2, | |
11074 | bool adjust) | |
11075 | { | |
11076 | if (m_n->tu == m2_n2->tu && | |
11077 | intel_compare_m_n(m_n->gmch_m, m_n->gmch_n, | |
11078 | m2_n2->gmch_m, m2_n2->gmch_n, !adjust) && | |
11079 | intel_compare_m_n(m_n->link_m, m_n->link_n, | |
11080 | m2_n2->link_m, m2_n2->link_n, !adjust)) { | |
11081 | if (adjust) | |
11082 | *m2_n2 = *m_n; | |
11083 | ||
11084 | return true; | |
11085 | } | |
11086 | ||
11087 | return false; | |
11088 | } | |
11089 | ||
4e8048f8 TU |
11090 | static void __printf(3, 4) |
11091 | pipe_config_err(bool adjust, const char *name, const char *format, ...) | |
11092 | { | |
11093 | char *level; | |
11094 | unsigned int category; | |
11095 | struct va_format vaf; | |
11096 | va_list args; | |
11097 | ||
11098 | if (adjust) { | |
11099 | level = KERN_DEBUG; | |
11100 | category = DRM_UT_KMS; | |
11101 | } else { | |
11102 | level = KERN_ERR; | |
11103 | category = DRM_UT_NONE; | |
11104 | } | |
11105 | ||
11106 | va_start(args, format); | |
11107 | vaf.fmt = format; | |
11108 | vaf.va = &args; | |
11109 | ||
11110 | drm_printk(level, category, "mismatch in %s %pV", name, &vaf); | |
11111 | ||
11112 | va_end(args); | |
11113 | } | |
11114 | ||
0e8ffe1b | 11115 | static bool |
6315b5d3 | 11116 | intel_pipe_config_compare(struct drm_i915_private *dev_priv, |
5cec258b | 11117 | struct intel_crtc_state *current_config, |
cfb23ed6 ML |
11118 | struct intel_crtc_state *pipe_config, |
11119 | bool adjust) | |
0e8ffe1b | 11120 | { |
cfb23ed6 ML |
11121 | bool ret = true; |
11122 | ||
66e985c0 DV |
11123 | #define PIPE_CONF_CHECK_X(name) \ |
11124 | if (current_config->name != pipe_config->name) { \ | |
4e8048f8 | 11125 | pipe_config_err(adjust, __stringify(name), \ |
66e985c0 DV |
11126 | "(expected 0x%08x, found 0x%08x)\n", \ |
11127 | current_config->name, \ | |
11128 | pipe_config->name); \ | |
cfb23ed6 | 11129 | ret = false; \ |
66e985c0 DV |
11130 | } |
11131 | ||
08a24034 DV |
11132 | #define PIPE_CONF_CHECK_I(name) \ |
11133 | if (current_config->name != pipe_config->name) { \ | |
4e8048f8 | 11134 | pipe_config_err(adjust, __stringify(name), \ |
08a24034 DV |
11135 | "(expected %i, found %i)\n", \ |
11136 | current_config->name, \ | |
11137 | pipe_config->name); \ | |
cfb23ed6 ML |
11138 | ret = false; \ |
11139 | } | |
11140 | ||
8106ddbd ACO |
11141 | #define PIPE_CONF_CHECK_P(name) \ |
11142 | if (current_config->name != pipe_config->name) { \ | |
4e8048f8 | 11143 | pipe_config_err(adjust, __stringify(name), \ |
8106ddbd ACO |
11144 | "(expected %p, found %p)\n", \ |
11145 | current_config->name, \ | |
11146 | pipe_config->name); \ | |
11147 | ret = false; \ | |
11148 | } | |
11149 | ||
cfb23ed6 ML |
11150 | #define PIPE_CONF_CHECK_M_N(name) \ |
11151 | if (!intel_compare_link_m_n(¤t_config->name, \ | |
11152 | &pipe_config->name,\ | |
11153 | adjust)) { \ | |
4e8048f8 | 11154 | pipe_config_err(adjust, __stringify(name), \ |
cfb23ed6 ML |
11155 | "(expected tu %i gmch %i/%i link %i/%i, " \ |
11156 | "found tu %i, gmch %i/%i link %i/%i)\n", \ | |
11157 | current_config->name.tu, \ | |
11158 | current_config->name.gmch_m, \ | |
11159 | current_config->name.gmch_n, \ | |
11160 | current_config->name.link_m, \ | |
11161 | current_config->name.link_n, \ | |
11162 | pipe_config->name.tu, \ | |
11163 | pipe_config->name.gmch_m, \ | |
11164 | pipe_config->name.gmch_n, \ | |
11165 | pipe_config->name.link_m, \ | |
11166 | pipe_config->name.link_n); \ | |
11167 | ret = false; \ | |
11168 | } | |
11169 | ||
55c561a7 DV |
11170 | /* This is required for BDW+ where there is only one set of registers for |
11171 | * switching between high and low RR. | |
11172 | * This macro can be used whenever a comparison has to be made between one | |
11173 | * hw state and multiple sw state variables. | |
11174 | */ | |
cfb23ed6 ML |
11175 | #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \ |
11176 | if (!intel_compare_link_m_n(¤t_config->name, \ | |
11177 | &pipe_config->name, adjust) && \ | |
11178 | !intel_compare_link_m_n(¤t_config->alt_name, \ | |
11179 | &pipe_config->name, adjust)) { \ | |
4e8048f8 | 11180 | pipe_config_err(adjust, __stringify(name), \ |
cfb23ed6 ML |
11181 | "(expected tu %i gmch %i/%i link %i/%i, " \ |
11182 | "or tu %i gmch %i/%i link %i/%i, " \ | |
11183 | "found tu %i, gmch %i/%i link %i/%i)\n", \ | |
11184 | current_config->name.tu, \ | |
11185 | current_config->name.gmch_m, \ | |
11186 | current_config->name.gmch_n, \ | |
11187 | current_config->name.link_m, \ | |
11188 | current_config->name.link_n, \ | |
11189 | current_config->alt_name.tu, \ | |
11190 | current_config->alt_name.gmch_m, \ | |
11191 | current_config->alt_name.gmch_n, \ | |
11192 | current_config->alt_name.link_m, \ | |
11193 | current_config->alt_name.link_n, \ | |
11194 | pipe_config->name.tu, \ | |
11195 | pipe_config->name.gmch_m, \ | |
11196 | pipe_config->name.gmch_n, \ | |
11197 | pipe_config->name.link_m, \ | |
11198 | pipe_config->name.link_n); \ | |
11199 | ret = false; \ | |
88adfff1 DV |
11200 | } |
11201 | ||
1bd1bd80 DV |
11202 | #define PIPE_CONF_CHECK_FLAGS(name, mask) \ |
11203 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ | |
4e8048f8 TU |
11204 | pipe_config_err(adjust, __stringify(name), \ |
11205 | "(%x) (expected %i, found %i)\n", \ | |
11206 | (mask), \ | |
1bd1bd80 DV |
11207 | current_config->name & (mask), \ |
11208 | pipe_config->name & (mask)); \ | |
cfb23ed6 | 11209 | ret = false; \ |
1bd1bd80 DV |
11210 | } |
11211 | ||
5e550656 VS |
11212 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \ |
11213 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ | |
4e8048f8 | 11214 | pipe_config_err(adjust, __stringify(name), \ |
5e550656 VS |
11215 | "(expected %i, found %i)\n", \ |
11216 | current_config->name, \ | |
11217 | pipe_config->name); \ | |
cfb23ed6 | 11218 | ret = false; \ |
5e550656 VS |
11219 | } |
11220 | ||
bb760063 DV |
11221 | #define PIPE_CONF_QUIRK(quirk) \ |
11222 | ((current_config->quirks | pipe_config->quirks) & (quirk)) | |
11223 | ||
eccb140b DV |
11224 | PIPE_CONF_CHECK_I(cpu_transcoder); |
11225 | ||
08a24034 DV |
11226 | PIPE_CONF_CHECK_I(has_pch_encoder); |
11227 | PIPE_CONF_CHECK_I(fdi_lanes); | |
cfb23ed6 | 11228 | PIPE_CONF_CHECK_M_N(fdi_m_n); |
08a24034 | 11229 | |
90a6b7b0 | 11230 | PIPE_CONF_CHECK_I(lane_count); |
95a7a2ae | 11231 | PIPE_CONF_CHECK_X(lane_lat_optim_mask); |
b95af8be | 11232 | |
6315b5d3 | 11233 | if (INTEL_GEN(dev_priv) < 8) { |
cfb23ed6 ML |
11234 | PIPE_CONF_CHECK_M_N(dp_m_n); |
11235 | ||
cfb23ed6 ML |
11236 | if (current_config->has_drrs) |
11237 | PIPE_CONF_CHECK_M_N(dp_m2_n2); | |
11238 | } else | |
11239 | PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2); | |
eb14cb74 | 11240 | |
253c84c8 | 11241 | PIPE_CONF_CHECK_X(output_types); |
a65347ba | 11242 | |
2d112de7 ACO |
11243 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
11244 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); | |
11245 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); | |
11246 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); | |
11247 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); | |
11248 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); | |
1bd1bd80 | 11249 | |
2d112de7 ACO |
11250 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
11251 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); | |
11252 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); | |
11253 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); | |
11254 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); | |
11255 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); | |
1bd1bd80 | 11256 | |
c93f54cf | 11257 | PIPE_CONF_CHECK_I(pixel_multiplier); |
6897b4b5 | 11258 | PIPE_CONF_CHECK_I(has_hdmi_sink); |
772c2a51 | 11259 | if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) || |
920a14b2 | 11260 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
b5a9fa09 | 11261 | PIPE_CONF_CHECK_I(limited_color_range); |
15953637 SS |
11262 | |
11263 | PIPE_CONF_CHECK_I(hdmi_scrambling); | |
11264 | PIPE_CONF_CHECK_I(hdmi_high_tmds_clock_ratio); | |
e43823ec | 11265 | PIPE_CONF_CHECK_I(has_infoframe); |
60436fd4 | 11266 | PIPE_CONF_CHECK_I(ycbcr420); |
6c49f241 | 11267 | |
9ed109a7 DV |
11268 | PIPE_CONF_CHECK_I(has_audio); |
11269 | ||
2d112de7 | 11270 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
1bd1bd80 DV |
11271 | DRM_MODE_FLAG_INTERLACE); |
11272 | ||
bb760063 | 11273 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
2d112de7 | 11274 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 11275 | DRM_MODE_FLAG_PHSYNC); |
2d112de7 | 11276 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 11277 | DRM_MODE_FLAG_NHSYNC); |
2d112de7 | 11278 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 | 11279 | DRM_MODE_FLAG_PVSYNC); |
2d112de7 | 11280 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
bb760063 DV |
11281 | DRM_MODE_FLAG_NVSYNC); |
11282 | } | |
045ac3b5 | 11283 | |
333b8ca8 | 11284 | PIPE_CONF_CHECK_X(gmch_pfit.control); |
e2ff2d4a | 11285 | /* pfit ratios are autocomputed by the hw on gen4+ */ |
6315b5d3 | 11286 | if (INTEL_GEN(dev_priv) < 4) |
7f7d8dd6 | 11287 | PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios); |
333b8ca8 | 11288 | PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits); |
9953599b | 11289 | |
bfd16b2a ML |
11290 | if (!adjust) { |
11291 | PIPE_CONF_CHECK_I(pipe_src_w); | |
11292 | PIPE_CONF_CHECK_I(pipe_src_h); | |
11293 | ||
11294 | PIPE_CONF_CHECK_I(pch_pfit.enabled); | |
11295 | if (current_config->pch_pfit.enabled) { | |
11296 | PIPE_CONF_CHECK_X(pch_pfit.pos); | |
11297 | PIPE_CONF_CHECK_X(pch_pfit.size); | |
11298 | } | |
2fa2fe9a | 11299 | |
7aefe2b5 | 11300 | PIPE_CONF_CHECK_I(scaler_state.scaler_id); |
a7d1b3f4 | 11301 | PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate); |
7aefe2b5 | 11302 | } |
a1b2278e | 11303 | |
e59150dc | 11304 | /* BDW+ don't expose a synchronous way to read the state */ |
772c2a51 | 11305 | if (IS_HASWELL(dev_priv)) |
e59150dc | 11306 | PIPE_CONF_CHECK_I(ips_enabled); |
42db64ef | 11307 | |
282740f7 VS |
11308 | PIPE_CONF_CHECK_I(double_wide); |
11309 | ||
8106ddbd | 11310 | PIPE_CONF_CHECK_P(shared_dpll); |
66e985c0 | 11311 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
8bcc2795 | 11312 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
66e985c0 DV |
11313 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
11314 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); | |
d452c5b6 | 11315 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
00490c22 | 11316 | PIPE_CONF_CHECK_X(dpll_hw_state.spll); |
3f4cd19f DL |
11317 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
11318 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); | |
11319 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); | |
2de38138 PZ |
11320 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0); |
11321 | PIPE_CONF_CHECK_X(dpll_hw_state.ebb0); | |
11322 | PIPE_CONF_CHECK_X(dpll_hw_state.ebb4); | |
11323 | PIPE_CONF_CHECK_X(dpll_hw_state.pll0); | |
11324 | PIPE_CONF_CHECK_X(dpll_hw_state.pll1); | |
11325 | PIPE_CONF_CHECK_X(dpll_hw_state.pll2); | |
11326 | PIPE_CONF_CHECK_X(dpll_hw_state.pll3); | |
11327 | PIPE_CONF_CHECK_X(dpll_hw_state.pll6); | |
11328 | PIPE_CONF_CHECK_X(dpll_hw_state.pll8); | |
11329 | PIPE_CONF_CHECK_X(dpll_hw_state.pll9); | |
11330 | PIPE_CONF_CHECK_X(dpll_hw_state.pll10); | |
11331 | PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12); | |
c0d43d62 | 11332 | |
47eacbab VS |
11333 | PIPE_CONF_CHECK_X(dsi_pll.ctrl); |
11334 | PIPE_CONF_CHECK_X(dsi_pll.div); | |
11335 | ||
9beb5fea | 11336 | if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) |
42571aef VS |
11337 | PIPE_CONF_CHECK_I(pipe_bpp); |
11338 | ||
2d112de7 | 11339 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
a9a7e98a | 11340 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
5e550656 | 11341 | |
66e985c0 | 11342 | #undef PIPE_CONF_CHECK_X |
08a24034 | 11343 | #undef PIPE_CONF_CHECK_I |
8106ddbd | 11344 | #undef PIPE_CONF_CHECK_P |
1bd1bd80 | 11345 | #undef PIPE_CONF_CHECK_FLAGS |
5e550656 | 11346 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
bb760063 | 11347 | #undef PIPE_CONF_QUIRK |
88adfff1 | 11348 | |
cfb23ed6 | 11349 | return ret; |
0e8ffe1b DV |
11350 | } |
11351 | ||
e3b247da VS |
11352 | static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv, |
11353 | const struct intel_crtc_state *pipe_config) | |
11354 | { | |
11355 | if (pipe_config->has_pch_encoder) { | |
21a727b3 | 11356 | int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config), |
e3b247da VS |
11357 | &pipe_config->fdi_m_n); |
11358 | int dotclock = pipe_config->base.adjusted_mode.crtc_clock; | |
11359 | ||
11360 | /* | |
11361 | * FDI already provided one idea for the dotclock. | |
11362 | * Yell if the encoder disagrees. | |
11363 | */ | |
11364 | WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock), | |
11365 | "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", | |
11366 | fdi_dotclock, dotclock); | |
11367 | } | |
11368 | } | |
11369 | ||
c0ead703 ML |
11370 | static void verify_wm_state(struct drm_crtc *crtc, |
11371 | struct drm_crtc_state *new_state) | |
08db6652 | 11372 | { |
6315b5d3 | 11373 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
08db6652 | 11374 | struct skl_ddb_allocation hw_ddb, *sw_ddb; |
3de8a14c | 11375 | struct skl_pipe_wm hw_wm, *sw_wm; |
11376 | struct skl_plane_wm *hw_plane_wm, *sw_plane_wm; | |
11377 | struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry; | |
e7c84544 ML |
11378 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
11379 | const enum pipe pipe = intel_crtc->pipe; | |
3de8a14c | 11380 | int plane, level, max_level = ilk_wm_max_level(dev_priv); |
08db6652 | 11381 | |
6315b5d3 | 11382 | if (INTEL_GEN(dev_priv) < 9 || !new_state->active) |
08db6652 DL |
11383 | return; |
11384 | ||
3de8a14c | 11385 | skl_pipe_wm_get_hw_state(crtc, &hw_wm); |
03af79e0 | 11386 | sw_wm = &to_intel_crtc_state(new_state)->wm.skl.optimal; |
3de8a14c | 11387 | |
08db6652 DL |
11388 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); |
11389 | sw_ddb = &dev_priv->wm.skl_hw.ddb; | |
11390 | ||
e7c84544 | 11391 | /* planes */ |
8b364b41 | 11392 | for_each_universal_plane(dev_priv, pipe, plane) { |
3de8a14c | 11393 | hw_plane_wm = &hw_wm.planes[plane]; |
11394 | sw_plane_wm = &sw_wm->planes[plane]; | |
08db6652 | 11395 | |
3de8a14c | 11396 | /* Watermarks */ |
11397 | for (level = 0; level <= max_level; level++) { | |
11398 | if (skl_wm_level_equals(&hw_plane_wm->wm[level], | |
11399 | &sw_plane_wm->wm[level])) | |
11400 | continue; | |
11401 | ||
11402 | DRM_ERROR("mismatch in WM pipe %c plane %d level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n", | |
11403 | pipe_name(pipe), plane + 1, level, | |
11404 | sw_plane_wm->wm[level].plane_en, | |
11405 | sw_plane_wm->wm[level].plane_res_b, | |
11406 | sw_plane_wm->wm[level].plane_res_l, | |
11407 | hw_plane_wm->wm[level].plane_en, | |
11408 | hw_plane_wm->wm[level].plane_res_b, | |
11409 | hw_plane_wm->wm[level].plane_res_l); | |
11410 | } | |
08db6652 | 11411 | |
3de8a14c | 11412 | if (!skl_wm_level_equals(&hw_plane_wm->trans_wm, |
11413 | &sw_plane_wm->trans_wm)) { | |
11414 | DRM_ERROR("mismatch in trans WM pipe %c plane %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n", | |
11415 | pipe_name(pipe), plane + 1, | |
11416 | sw_plane_wm->trans_wm.plane_en, | |
11417 | sw_plane_wm->trans_wm.plane_res_b, | |
11418 | sw_plane_wm->trans_wm.plane_res_l, | |
11419 | hw_plane_wm->trans_wm.plane_en, | |
11420 | hw_plane_wm->trans_wm.plane_res_b, | |
11421 | hw_plane_wm->trans_wm.plane_res_l); | |
11422 | } | |
11423 | ||
11424 | /* DDB */ | |
11425 | hw_ddb_entry = &hw_ddb.plane[pipe][plane]; | |
11426 | sw_ddb_entry = &sw_ddb->plane[pipe][plane]; | |
11427 | ||
11428 | if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) { | |
faccd994 | 11429 | DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n", |
3de8a14c | 11430 | pipe_name(pipe), plane + 1, |
11431 | sw_ddb_entry->start, sw_ddb_entry->end, | |
11432 | hw_ddb_entry->start, hw_ddb_entry->end); | |
11433 | } | |
e7c84544 | 11434 | } |
08db6652 | 11435 | |
27082493 L |
11436 | /* |
11437 | * cursor | |
11438 | * If the cursor plane isn't active, we may not have updated it's ddb | |
11439 | * allocation. In that case since the ddb allocation will be updated | |
11440 | * once the plane becomes visible, we can skip this check | |
11441 | */ | |
cd5dcbf1 | 11442 | if (1) { |
3de8a14c | 11443 | hw_plane_wm = &hw_wm.planes[PLANE_CURSOR]; |
11444 | sw_plane_wm = &sw_wm->planes[PLANE_CURSOR]; | |
11445 | ||
11446 | /* Watermarks */ | |
11447 | for (level = 0; level <= max_level; level++) { | |
11448 | if (skl_wm_level_equals(&hw_plane_wm->wm[level], | |
11449 | &sw_plane_wm->wm[level])) | |
11450 | continue; | |
11451 | ||
11452 | DRM_ERROR("mismatch in WM pipe %c cursor level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n", | |
11453 | pipe_name(pipe), level, | |
11454 | sw_plane_wm->wm[level].plane_en, | |
11455 | sw_plane_wm->wm[level].plane_res_b, | |
11456 | sw_plane_wm->wm[level].plane_res_l, | |
11457 | hw_plane_wm->wm[level].plane_en, | |
11458 | hw_plane_wm->wm[level].plane_res_b, | |
11459 | hw_plane_wm->wm[level].plane_res_l); | |
11460 | } | |
11461 | ||
11462 | if (!skl_wm_level_equals(&hw_plane_wm->trans_wm, | |
11463 | &sw_plane_wm->trans_wm)) { | |
11464 | DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n", | |
11465 | pipe_name(pipe), | |
11466 | sw_plane_wm->trans_wm.plane_en, | |
11467 | sw_plane_wm->trans_wm.plane_res_b, | |
11468 | sw_plane_wm->trans_wm.plane_res_l, | |
11469 | hw_plane_wm->trans_wm.plane_en, | |
11470 | hw_plane_wm->trans_wm.plane_res_b, | |
11471 | hw_plane_wm->trans_wm.plane_res_l); | |
11472 | } | |
11473 | ||
11474 | /* DDB */ | |
11475 | hw_ddb_entry = &hw_ddb.plane[pipe][PLANE_CURSOR]; | |
11476 | sw_ddb_entry = &sw_ddb->plane[pipe][PLANE_CURSOR]; | |
27082493 | 11477 | |
3de8a14c | 11478 | if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) { |
faccd994 | 11479 | DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n", |
27082493 | 11480 | pipe_name(pipe), |
3de8a14c | 11481 | sw_ddb_entry->start, sw_ddb_entry->end, |
11482 | hw_ddb_entry->start, hw_ddb_entry->end); | |
27082493 | 11483 | } |
08db6652 DL |
11484 | } |
11485 | } | |
11486 | ||
91d1b4bd | 11487 | static void |
677100ce ML |
11488 | verify_connector_state(struct drm_device *dev, |
11489 | struct drm_atomic_state *state, | |
11490 | struct drm_crtc *crtc) | |
8af6cf88 | 11491 | { |
35dd3c64 | 11492 | struct drm_connector *connector; |
aa5e9b47 | 11493 | struct drm_connector_state *new_conn_state; |
677100ce | 11494 | int i; |
8af6cf88 | 11495 | |
aa5e9b47 | 11496 | for_each_new_connector_in_state(state, connector, new_conn_state, i) { |
35dd3c64 | 11497 | struct drm_encoder *encoder = connector->encoder; |
749d98b8 | 11498 | struct drm_crtc_state *crtc_state = NULL; |
ad3c558f | 11499 | |
aa5e9b47 | 11500 | if (new_conn_state->crtc != crtc) |
e7c84544 ML |
11501 | continue; |
11502 | ||
749d98b8 ML |
11503 | if (crtc) |
11504 | crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc); | |
11505 | ||
11506 | intel_connector_verify_state(crtc_state, new_conn_state); | |
8af6cf88 | 11507 | |
aa5e9b47 | 11508 | I915_STATE_WARN(new_conn_state->best_encoder != encoder, |
35dd3c64 | 11509 | "connector's atomic encoder doesn't match legacy encoder\n"); |
8af6cf88 | 11510 | } |
91d1b4bd DV |
11511 | } |
11512 | ||
11513 | static void | |
86b04268 | 11514 | verify_encoder_state(struct drm_device *dev, struct drm_atomic_state *state) |
91d1b4bd DV |
11515 | { |
11516 | struct intel_encoder *encoder; | |
86b04268 DV |
11517 | struct drm_connector *connector; |
11518 | struct drm_connector_state *old_conn_state, *new_conn_state; | |
11519 | int i; | |
8af6cf88 | 11520 | |
b2784e15 | 11521 | for_each_intel_encoder(dev, encoder) { |
86b04268 | 11522 | bool enabled = false, found = false; |
4d20cd86 | 11523 | enum pipe pipe; |
8af6cf88 DV |
11524 | |
11525 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", | |
11526 | encoder->base.base.id, | |
8e329a03 | 11527 | encoder->base.name); |
8af6cf88 | 11528 | |
86b04268 DV |
11529 | for_each_oldnew_connector_in_state(state, connector, old_conn_state, |
11530 | new_conn_state, i) { | |
11531 | if (old_conn_state->best_encoder == &encoder->base) | |
11532 | found = true; | |
11533 | ||
11534 | if (new_conn_state->best_encoder != &encoder->base) | |
8af6cf88 | 11535 | continue; |
86b04268 | 11536 | found = enabled = true; |
ad3c558f | 11537 | |
86b04268 | 11538 | I915_STATE_WARN(new_conn_state->crtc != |
ad3c558f ML |
11539 | encoder->base.crtc, |
11540 | "connector's crtc doesn't match encoder crtc\n"); | |
8af6cf88 | 11541 | } |
86b04268 DV |
11542 | |
11543 | if (!found) | |
11544 | continue; | |
0e32b39c | 11545 | |
e2c719b7 | 11546 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
8af6cf88 DV |
11547 | "encoder's enabled state mismatch " |
11548 | "(expected %i, found %i)\n", | |
11549 | !!encoder->base.crtc, enabled); | |
7c60d198 ML |
11550 | |
11551 | if (!encoder->base.crtc) { | |
4d20cd86 | 11552 | bool active; |
7c60d198 | 11553 | |
4d20cd86 ML |
11554 | active = encoder->get_hw_state(encoder, &pipe); |
11555 | I915_STATE_WARN(active, | |
11556 | "encoder detached but still enabled on pipe %c.\n", | |
11557 | pipe_name(pipe)); | |
7c60d198 | 11558 | } |
8af6cf88 | 11559 | } |
91d1b4bd DV |
11560 | } |
11561 | ||
11562 | static void | |
c0ead703 ML |
11563 | verify_crtc_state(struct drm_crtc *crtc, |
11564 | struct drm_crtc_state *old_crtc_state, | |
11565 | struct drm_crtc_state *new_crtc_state) | |
91d1b4bd | 11566 | { |
e7c84544 | 11567 | struct drm_device *dev = crtc->dev; |
fac5e23e | 11568 | struct drm_i915_private *dev_priv = to_i915(dev); |
91d1b4bd | 11569 | struct intel_encoder *encoder; |
e7c84544 ML |
11570 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
11571 | struct intel_crtc_state *pipe_config, *sw_config; | |
11572 | struct drm_atomic_state *old_state; | |
11573 | bool active; | |
045ac3b5 | 11574 | |
e7c84544 | 11575 | old_state = old_crtc_state->state; |
ec2dc6a0 | 11576 | __drm_atomic_helper_crtc_destroy_state(old_crtc_state); |
e7c84544 ML |
11577 | pipe_config = to_intel_crtc_state(old_crtc_state); |
11578 | memset(pipe_config, 0, sizeof(*pipe_config)); | |
11579 | pipe_config->base.crtc = crtc; | |
11580 | pipe_config->base.state = old_state; | |
8af6cf88 | 11581 | |
78108b7c | 11582 | DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name); |
8af6cf88 | 11583 | |
e7c84544 | 11584 | active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config); |
d62cf62a | 11585 | |
e56134bc VS |
11586 | /* we keep both pipes enabled on 830 */ |
11587 | if (IS_I830(dev_priv)) | |
e7c84544 | 11588 | active = new_crtc_state->active; |
6c49f241 | 11589 | |
e7c84544 ML |
11590 | I915_STATE_WARN(new_crtc_state->active != active, |
11591 | "crtc active state doesn't match with hw state " | |
11592 | "(expected %i, found %i)\n", new_crtc_state->active, active); | |
0e8ffe1b | 11593 | |
e7c84544 ML |
11594 | I915_STATE_WARN(intel_crtc->active != new_crtc_state->active, |
11595 | "transitional active state does not match atomic hw state " | |
11596 | "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active); | |
4d20cd86 | 11597 | |
e7c84544 ML |
11598 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
11599 | enum pipe pipe; | |
4d20cd86 | 11600 | |
e7c84544 ML |
11601 | active = encoder->get_hw_state(encoder, &pipe); |
11602 | I915_STATE_WARN(active != new_crtc_state->active, | |
11603 | "[ENCODER:%i] active %i with crtc active %i\n", | |
11604 | encoder->base.base.id, active, new_crtc_state->active); | |
4d20cd86 | 11605 | |
e7c84544 ML |
11606 | I915_STATE_WARN(active && intel_crtc->pipe != pipe, |
11607 | "Encoder connected to wrong pipe %c\n", | |
11608 | pipe_name(pipe)); | |
4d20cd86 | 11609 | |
253c84c8 VS |
11610 | if (active) { |
11611 | pipe_config->output_types |= 1 << encoder->type; | |
e7c84544 | 11612 | encoder->get_config(encoder, pipe_config); |
253c84c8 | 11613 | } |
e7c84544 | 11614 | } |
53d9f4e9 | 11615 | |
a7d1b3f4 VS |
11616 | intel_crtc_compute_pixel_rate(pipe_config); |
11617 | ||
e7c84544 ML |
11618 | if (!new_crtc_state->active) |
11619 | return; | |
cfb23ed6 | 11620 | |
e7c84544 | 11621 | intel_pipe_config_sanity_check(dev_priv, pipe_config); |
e3b247da | 11622 | |
749d98b8 | 11623 | sw_config = to_intel_crtc_state(new_crtc_state); |
6315b5d3 | 11624 | if (!intel_pipe_config_compare(dev_priv, sw_config, |
e7c84544 ML |
11625 | pipe_config, false)) { |
11626 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); | |
11627 | intel_dump_pipe_config(intel_crtc, pipe_config, | |
11628 | "[hw state]"); | |
11629 | intel_dump_pipe_config(intel_crtc, sw_config, | |
11630 | "[sw state]"); | |
8af6cf88 DV |
11631 | } |
11632 | } | |
11633 | ||
91d1b4bd | 11634 | static void |
c0ead703 ML |
11635 | verify_single_dpll_state(struct drm_i915_private *dev_priv, |
11636 | struct intel_shared_dpll *pll, | |
11637 | struct drm_crtc *crtc, | |
11638 | struct drm_crtc_state *new_state) | |
91d1b4bd | 11639 | { |
91d1b4bd | 11640 | struct intel_dpll_hw_state dpll_hw_state; |
e7c84544 ML |
11641 | unsigned crtc_mask; |
11642 | bool active; | |
5358901f | 11643 | |
e7c84544 | 11644 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); |
5358901f | 11645 | |
e7c84544 | 11646 | DRM_DEBUG_KMS("%s\n", pll->name); |
5358901f | 11647 | |
e7c84544 | 11648 | active = pll->funcs.get_hw_state(dev_priv, pll, &dpll_hw_state); |
5358901f | 11649 | |
e7c84544 ML |
11650 | if (!(pll->flags & INTEL_DPLL_ALWAYS_ON)) { |
11651 | I915_STATE_WARN(!pll->on && pll->active_mask, | |
11652 | "pll in active use but not on in sw tracking\n"); | |
11653 | I915_STATE_WARN(pll->on && !pll->active_mask, | |
11654 | "pll is on but not used by any active crtc\n"); | |
11655 | I915_STATE_WARN(pll->on != active, | |
11656 | "pll on state mismatch (expected %i, found %i)\n", | |
11657 | pll->on, active); | |
11658 | } | |
5358901f | 11659 | |
e7c84544 | 11660 | if (!crtc) { |
2c42e535 | 11661 | I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask, |
e7c84544 | 11662 | "more active pll users than references: %x vs %x\n", |
2c42e535 | 11663 | pll->active_mask, pll->state.crtc_mask); |
5358901f | 11664 | |
e7c84544 ML |
11665 | return; |
11666 | } | |
11667 | ||
11668 | crtc_mask = 1 << drm_crtc_index(crtc); | |
11669 | ||
11670 | if (new_state->active) | |
11671 | I915_STATE_WARN(!(pll->active_mask & crtc_mask), | |
11672 | "pll active mismatch (expected pipe %c in active mask 0x%02x)\n", | |
11673 | pipe_name(drm_crtc_index(crtc)), pll->active_mask); | |
11674 | else | |
11675 | I915_STATE_WARN(pll->active_mask & crtc_mask, | |
11676 | "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n", | |
11677 | pipe_name(drm_crtc_index(crtc)), pll->active_mask); | |
2dd66ebd | 11678 | |
2c42e535 | 11679 | I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask), |
e7c84544 | 11680 | "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n", |
2c42e535 | 11681 | crtc_mask, pll->state.crtc_mask); |
66e985c0 | 11682 | |
2c42e535 | 11683 | I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state, |
e7c84544 ML |
11684 | &dpll_hw_state, |
11685 | sizeof(dpll_hw_state)), | |
11686 | "pll hw state mismatch\n"); | |
11687 | } | |
11688 | ||
11689 | static void | |
c0ead703 ML |
11690 | verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc, |
11691 | struct drm_crtc_state *old_crtc_state, | |
11692 | struct drm_crtc_state *new_crtc_state) | |
e7c84544 | 11693 | { |
fac5e23e | 11694 | struct drm_i915_private *dev_priv = to_i915(dev); |
e7c84544 ML |
11695 | struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state); |
11696 | struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state); | |
11697 | ||
11698 | if (new_state->shared_dpll) | |
c0ead703 | 11699 | verify_single_dpll_state(dev_priv, new_state->shared_dpll, crtc, new_crtc_state); |
e7c84544 ML |
11700 | |
11701 | if (old_state->shared_dpll && | |
11702 | old_state->shared_dpll != new_state->shared_dpll) { | |
11703 | unsigned crtc_mask = 1 << drm_crtc_index(crtc); | |
11704 | struct intel_shared_dpll *pll = old_state->shared_dpll; | |
11705 | ||
11706 | I915_STATE_WARN(pll->active_mask & crtc_mask, | |
11707 | "pll active mismatch (didn't expect pipe %c in active mask)\n", | |
11708 | pipe_name(drm_crtc_index(crtc))); | |
2c42e535 | 11709 | I915_STATE_WARN(pll->state.crtc_mask & crtc_mask, |
e7c84544 ML |
11710 | "pll enabled crtcs mismatch (found %x in enabled mask)\n", |
11711 | pipe_name(drm_crtc_index(crtc))); | |
5358901f | 11712 | } |
8af6cf88 DV |
11713 | } |
11714 | ||
e7c84544 | 11715 | static void |
c0ead703 | 11716 | intel_modeset_verify_crtc(struct drm_crtc *crtc, |
677100ce ML |
11717 | struct drm_atomic_state *state, |
11718 | struct drm_crtc_state *old_state, | |
11719 | struct drm_crtc_state *new_state) | |
e7c84544 | 11720 | { |
5a21b665 DV |
11721 | if (!needs_modeset(new_state) && |
11722 | !to_intel_crtc_state(new_state)->update_pipe) | |
11723 | return; | |
11724 | ||
c0ead703 | 11725 | verify_wm_state(crtc, new_state); |
677100ce | 11726 | verify_connector_state(crtc->dev, state, crtc); |
c0ead703 ML |
11727 | verify_crtc_state(crtc, old_state, new_state); |
11728 | verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state); | |
e7c84544 ML |
11729 | } |
11730 | ||
11731 | static void | |
c0ead703 | 11732 | verify_disabled_dpll_state(struct drm_device *dev) |
e7c84544 | 11733 | { |
fac5e23e | 11734 | struct drm_i915_private *dev_priv = to_i915(dev); |
e7c84544 ML |
11735 | int i; |
11736 | ||
11737 | for (i = 0; i < dev_priv->num_shared_dpll; i++) | |
c0ead703 | 11738 | verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL); |
e7c84544 ML |
11739 | } |
11740 | ||
11741 | static void | |
677100ce ML |
11742 | intel_modeset_verify_disabled(struct drm_device *dev, |
11743 | struct drm_atomic_state *state) | |
e7c84544 | 11744 | { |
86b04268 | 11745 | verify_encoder_state(dev, state); |
677100ce | 11746 | verify_connector_state(dev, state, NULL); |
c0ead703 | 11747 | verify_disabled_dpll_state(dev); |
e7c84544 ML |
11748 | } |
11749 | ||
80715b2f VS |
11750 | static void update_scanline_offset(struct intel_crtc *crtc) |
11751 | { | |
4f8036a2 | 11752 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
80715b2f VS |
11753 | |
11754 | /* | |
11755 | * The scanline counter increments at the leading edge of hsync. | |
11756 | * | |
11757 | * On most platforms it starts counting from vtotal-1 on the | |
11758 | * first active line. That means the scanline counter value is | |
11759 | * always one less than what we would expect. Ie. just after | |
11760 | * start of vblank, which also occurs at start of hsync (on the | |
11761 | * last active line), the scanline counter will read vblank_start-1. | |
11762 | * | |
11763 | * On gen2 the scanline counter starts counting from 1 instead | |
11764 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 | |
11765 | * to keep the value positive), instead of adding one. | |
11766 | * | |
11767 | * On HSW+ the behaviour of the scanline counter depends on the output | |
11768 | * type. For DP ports it behaves like most other platforms, but on HDMI | |
11769 | * there's an extra 1 line difference. So we need to add two instead of | |
11770 | * one to the value. | |
ec1b4ee2 VS |
11771 | * |
11772 | * On VLV/CHV DSI the scanline counter would appear to increment | |
11773 | * approx. 1/3 of a scanline before start of vblank. Unfortunately | |
11774 | * that means we can't tell whether we're in vblank or not while | |
11775 | * we're on that particular line. We must still set scanline_offset | |
11776 | * to 1 so that the vblank timestamps come out correct when we query | |
11777 | * the scanline counter from within the vblank interrupt handler. | |
11778 | * However if queried just before the start of vblank we'll get an | |
11779 | * answer that's slightly in the future. | |
80715b2f | 11780 | */ |
4f8036a2 | 11781 | if (IS_GEN2(dev_priv)) { |
124abe07 | 11782 | const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode; |
80715b2f VS |
11783 | int vtotal; |
11784 | ||
124abe07 VS |
11785 | vtotal = adjusted_mode->crtc_vtotal; |
11786 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) | |
80715b2f VS |
11787 | vtotal /= 2; |
11788 | ||
11789 | crtc->scanline_offset = vtotal - 1; | |
4f8036a2 | 11790 | } else if (HAS_DDI(dev_priv) && |
2d84d2b3 | 11791 | intel_crtc_has_type(crtc->config, INTEL_OUTPUT_HDMI)) { |
80715b2f VS |
11792 | crtc->scanline_offset = 2; |
11793 | } else | |
11794 | crtc->scanline_offset = 1; | |
11795 | } | |
11796 | ||
ad421372 | 11797 | static void intel_modeset_clear_plls(struct drm_atomic_state *state) |
ed6739ef | 11798 | { |
225da59b | 11799 | struct drm_device *dev = state->dev; |
ed6739ef | 11800 | struct drm_i915_private *dev_priv = to_i915(dev); |
0a9ab303 | 11801 | struct drm_crtc *crtc; |
aa5e9b47 | 11802 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
0a9ab303 | 11803 | int i; |
ed6739ef ACO |
11804 | |
11805 | if (!dev_priv->display.crtc_compute_clock) | |
ad421372 | 11806 | return; |
ed6739ef | 11807 | |
aa5e9b47 | 11808 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
fb1a38a9 | 11809 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
8106ddbd | 11810 | struct intel_shared_dpll *old_dpll = |
aa5e9b47 | 11811 | to_intel_crtc_state(old_crtc_state)->shared_dpll; |
0a9ab303 | 11812 | |
aa5e9b47 | 11813 | if (!needs_modeset(new_crtc_state)) |
225da59b ACO |
11814 | continue; |
11815 | ||
aa5e9b47 | 11816 | to_intel_crtc_state(new_crtc_state)->shared_dpll = NULL; |
fb1a38a9 | 11817 | |
8106ddbd | 11818 | if (!old_dpll) |
fb1a38a9 | 11819 | continue; |
0a9ab303 | 11820 | |
a1c414ee | 11821 | intel_release_shared_dpll(old_dpll, intel_crtc, state); |
ad421372 | 11822 | } |
ed6739ef ACO |
11823 | } |
11824 | ||
99d736a2 ML |
11825 | /* |
11826 | * This implements the workaround described in the "notes" section of the mode | |
11827 | * set sequence documentation. When going from no pipes or single pipe to | |
11828 | * multiple pipes, and planes are enabled after the pipe, we need to wait at | |
11829 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. | |
11830 | */ | |
11831 | static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state) | |
11832 | { | |
11833 | struct drm_crtc_state *crtc_state; | |
11834 | struct intel_crtc *intel_crtc; | |
11835 | struct drm_crtc *crtc; | |
11836 | struct intel_crtc_state *first_crtc_state = NULL; | |
11837 | struct intel_crtc_state *other_crtc_state = NULL; | |
11838 | enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE; | |
11839 | int i; | |
11840 | ||
11841 | /* look at all crtc's that are going to be enabled in during modeset */ | |
aa5e9b47 | 11842 | for_each_new_crtc_in_state(state, crtc, crtc_state, i) { |
99d736a2 ML |
11843 | intel_crtc = to_intel_crtc(crtc); |
11844 | ||
11845 | if (!crtc_state->active || !needs_modeset(crtc_state)) | |
11846 | continue; | |
11847 | ||
11848 | if (first_crtc_state) { | |
11849 | other_crtc_state = to_intel_crtc_state(crtc_state); | |
11850 | break; | |
11851 | } else { | |
11852 | first_crtc_state = to_intel_crtc_state(crtc_state); | |
11853 | first_pipe = intel_crtc->pipe; | |
11854 | } | |
11855 | } | |
11856 | ||
11857 | /* No workaround needed? */ | |
11858 | if (!first_crtc_state) | |
11859 | return 0; | |
11860 | ||
11861 | /* w/a possibly needed, check how many crtc's are already enabled. */ | |
11862 | for_each_intel_crtc(state->dev, intel_crtc) { | |
11863 | struct intel_crtc_state *pipe_config; | |
11864 | ||
11865 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); | |
11866 | if (IS_ERR(pipe_config)) | |
11867 | return PTR_ERR(pipe_config); | |
11868 | ||
11869 | pipe_config->hsw_workaround_pipe = INVALID_PIPE; | |
11870 | ||
11871 | if (!pipe_config->base.active || | |
11872 | needs_modeset(&pipe_config->base)) | |
11873 | continue; | |
11874 | ||
11875 | /* 2 or more enabled crtcs means no need for w/a */ | |
11876 | if (enabled_pipe != INVALID_PIPE) | |
11877 | return 0; | |
11878 | ||
11879 | enabled_pipe = intel_crtc->pipe; | |
11880 | } | |
11881 | ||
11882 | if (enabled_pipe != INVALID_PIPE) | |
11883 | first_crtc_state->hsw_workaround_pipe = enabled_pipe; | |
11884 | else if (other_crtc_state) | |
11885 | other_crtc_state->hsw_workaround_pipe = first_pipe; | |
11886 | ||
11887 | return 0; | |
11888 | } | |
11889 | ||
8d96561a VS |
11890 | static int intel_lock_all_pipes(struct drm_atomic_state *state) |
11891 | { | |
11892 | struct drm_crtc *crtc; | |
11893 | ||
11894 | /* Add all pipes to the state */ | |
11895 | for_each_crtc(state->dev, crtc) { | |
11896 | struct drm_crtc_state *crtc_state; | |
11897 | ||
11898 | crtc_state = drm_atomic_get_crtc_state(state, crtc); | |
11899 | if (IS_ERR(crtc_state)) | |
11900 | return PTR_ERR(crtc_state); | |
11901 | } | |
11902 | ||
11903 | return 0; | |
11904 | } | |
11905 | ||
27c329ed ML |
11906 | static int intel_modeset_all_pipes(struct drm_atomic_state *state) |
11907 | { | |
11908 | struct drm_crtc *crtc; | |
27c329ed | 11909 | |
8d96561a VS |
11910 | /* |
11911 | * Add all pipes to the state, and force | |
11912 | * a modeset on all the active ones. | |
11913 | */ | |
27c329ed | 11914 | for_each_crtc(state->dev, crtc) { |
9780aad5 VS |
11915 | struct drm_crtc_state *crtc_state; |
11916 | int ret; | |
11917 | ||
27c329ed ML |
11918 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
11919 | if (IS_ERR(crtc_state)) | |
11920 | return PTR_ERR(crtc_state); | |
11921 | ||
11922 | if (!crtc_state->active || needs_modeset(crtc_state)) | |
11923 | continue; | |
11924 | ||
11925 | crtc_state->mode_changed = true; | |
11926 | ||
11927 | ret = drm_atomic_add_affected_connectors(state, crtc); | |
11928 | if (ret) | |
9780aad5 | 11929 | return ret; |
27c329ed ML |
11930 | |
11931 | ret = drm_atomic_add_affected_planes(state, crtc); | |
11932 | if (ret) | |
9780aad5 | 11933 | return ret; |
27c329ed ML |
11934 | } |
11935 | ||
9780aad5 | 11936 | return 0; |
27c329ed ML |
11937 | } |
11938 | ||
c347a676 | 11939 | static int intel_modeset_checks(struct drm_atomic_state *state) |
054518dd | 11940 | { |
565602d7 | 11941 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
fac5e23e | 11942 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
565602d7 | 11943 | struct drm_crtc *crtc; |
aa5e9b47 | 11944 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
565602d7 | 11945 | int ret = 0, i; |
054518dd | 11946 | |
b359283a ML |
11947 | if (!check_digital_port_conflicts(state)) { |
11948 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); | |
11949 | return -EINVAL; | |
11950 | } | |
11951 | ||
68b342c9 VS |
11952 | /* keep the current setting */ |
11953 | if (!intel_state->cdclk.force_min_cdclk_changed) | |
11954 | intel_state->cdclk.force_min_cdclk = | |
11955 | dev_priv->cdclk.force_min_cdclk; | |
11956 | ||
11957 | ||
565602d7 ML |
11958 | intel_state->modeset = true; |
11959 | intel_state->active_crtcs = dev_priv->active_crtcs; | |
bb0f4aab VS |
11960 | intel_state->cdclk.logical = dev_priv->cdclk.logical; |
11961 | intel_state->cdclk.actual = dev_priv->cdclk.actual; | |
163e0af5 | 11962 | intel_state->cdclk.pipe = INVALID_PIPE; |
565602d7 | 11963 | |
aa5e9b47 ML |
11964 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
11965 | if (new_crtc_state->active) | |
565602d7 ML |
11966 | intel_state->active_crtcs |= 1 << i; |
11967 | else | |
11968 | intel_state->active_crtcs &= ~(1 << i); | |
8b4a7d05 | 11969 | |
aa5e9b47 | 11970 | if (old_crtc_state->active != new_crtc_state->active) |
8b4a7d05 | 11971 | intel_state->active_pipe_changes |= drm_crtc_mask(crtc); |
565602d7 ML |
11972 | } |
11973 | ||
054518dd ACO |
11974 | /* |
11975 | * See if the config requires any additional preparation, e.g. | |
11976 | * to adjust global state with pipes off. We need to do this | |
11977 | * here so we can get the modeset_pipe updated config for the new | |
11978 | * mode set on this crtc. For other crtcs we need to use the | |
11979 | * adjusted_mode bits in the crtc directly. | |
11980 | */ | |
27c329ed | 11981 | if (dev_priv->display.modeset_calc_cdclk) { |
163e0af5 VS |
11982 | enum pipe pipe; |
11983 | ||
27c329ed | 11984 | ret = dev_priv->display.modeset_calc_cdclk(state); |
c89e39f3 CT |
11985 | if (ret < 0) |
11986 | return ret; | |
27c329ed | 11987 | |
8d96561a | 11988 | /* |
bb0f4aab | 11989 | * Writes to dev_priv->cdclk.logical must protected by |
8d96561a VS |
11990 | * holding all the crtc locks, even if we don't end up |
11991 | * touching the hardware | |
11992 | */ | |
bb0f4aab VS |
11993 | if (!intel_cdclk_state_compare(&dev_priv->cdclk.logical, |
11994 | &intel_state->cdclk.logical)) { | |
8d96561a VS |
11995 | ret = intel_lock_all_pipes(state); |
11996 | if (ret < 0) | |
11997 | return ret; | |
11998 | } | |
11999 | ||
163e0af5 VS |
12000 | if (is_power_of_2(intel_state->active_crtcs)) { |
12001 | struct drm_crtc *crtc; | |
12002 | struct drm_crtc_state *crtc_state; | |
12003 | ||
12004 | pipe = ilog2(intel_state->active_crtcs); | |
12005 | crtc = &intel_get_crtc_for_pipe(dev_priv, pipe)->base; | |
12006 | crtc_state = drm_atomic_get_new_crtc_state(state, crtc); | |
12007 | if (crtc_state && needs_modeset(crtc_state)) | |
12008 | pipe = INVALID_PIPE; | |
12009 | } else { | |
12010 | pipe = INVALID_PIPE; | |
12011 | } | |
12012 | ||
8d96561a | 12013 | /* All pipes must be switched off while we change the cdclk. */ |
163e0af5 VS |
12014 | if (pipe != INVALID_PIPE && |
12015 | intel_cdclk_needs_cd2x_update(dev_priv, | |
12016 | &dev_priv->cdclk.actual, | |
12017 | &intel_state->cdclk.actual)) { | |
12018 | ret = intel_lock_all_pipes(state); | |
12019 | if (ret < 0) | |
12020 | return ret; | |
12021 | ||
12022 | intel_state->cdclk.pipe = pipe; | |
12023 | } else if (!intel_cdclk_state_compare(&dev_priv->cdclk.actual, | |
bb0f4aab | 12024 | &intel_state->cdclk.actual)) { |
27c329ed | 12025 | ret = intel_modeset_all_pipes(state); |
8d96561a VS |
12026 | if (ret < 0) |
12027 | return ret; | |
163e0af5 VS |
12028 | |
12029 | intel_state->cdclk.pipe = INVALID_PIPE; | |
8d96561a | 12030 | } |
e8788cbc | 12031 | |
bb0f4aab VS |
12032 | DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n", |
12033 | intel_state->cdclk.logical.cdclk, | |
12034 | intel_state->cdclk.actual.cdclk); | |
e0ca7a6b | 12035 | } |
054518dd | 12036 | |
ad421372 | 12037 | intel_modeset_clear_plls(state); |
054518dd | 12038 | |
565602d7 | 12039 | if (IS_HASWELL(dev_priv)) |
ad421372 | 12040 | return haswell_mode_set_planes_workaround(state); |
99d736a2 | 12041 | |
ad421372 | 12042 | return 0; |
c347a676 ACO |
12043 | } |
12044 | ||
aa363136 MR |
12045 | /* |
12046 | * Handle calculation of various watermark data at the end of the atomic check | |
12047 | * phase. The code here should be run after the per-crtc and per-plane 'check' | |
12048 | * handlers to ensure that all derived state has been updated. | |
12049 | */ | |
55994c2c | 12050 | static int calc_watermark_data(struct drm_atomic_state *state) |
aa363136 MR |
12051 | { |
12052 | struct drm_device *dev = state->dev; | |
98d39494 | 12053 | struct drm_i915_private *dev_priv = to_i915(dev); |
98d39494 MR |
12054 | |
12055 | /* Is there platform-specific watermark information to calculate? */ | |
12056 | if (dev_priv->display.compute_global_watermarks) | |
55994c2c MR |
12057 | return dev_priv->display.compute_global_watermarks(state); |
12058 | ||
12059 | return 0; | |
aa363136 MR |
12060 | } |
12061 | ||
74c090b1 ML |
12062 | /** |
12063 | * intel_atomic_check - validate state object | |
12064 | * @dev: drm device | |
12065 | * @state: state to validate | |
12066 | */ | |
12067 | static int intel_atomic_check(struct drm_device *dev, | |
12068 | struct drm_atomic_state *state) | |
c347a676 | 12069 | { |
dd8b3bdb | 12070 | struct drm_i915_private *dev_priv = to_i915(dev); |
aa363136 | 12071 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
c347a676 | 12072 | struct drm_crtc *crtc; |
aa5e9b47 | 12073 | struct drm_crtc_state *old_crtc_state, *crtc_state; |
c347a676 | 12074 | int ret, i; |
68b342c9 | 12075 | bool any_ms = intel_state->cdclk.force_min_cdclk_changed; |
c347a676 | 12076 | |
74c090b1 | 12077 | ret = drm_atomic_helper_check_modeset(dev, state); |
054518dd ACO |
12078 | if (ret) |
12079 | return ret; | |
12080 | ||
aa5e9b47 | 12081 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, crtc_state, i) { |
cfb23ed6 ML |
12082 | struct intel_crtc_state *pipe_config = |
12083 | to_intel_crtc_state(crtc_state); | |
1ed51de9 DV |
12084 | |
12085 | /* Catch I915_MODE_FLAG_INHERITED */ | |
aa5e9b47 | 12086 | if (crtc_state->mode.private_flags != old_crtc_state->mode.private_flags) |
1ed51de9 | 12087 | crtc_state->mode_changed = true; |
cfb23ed6 | 12088 | |
af4a879e | 12089 | if (!needs_modeset(crtc_state)) |
c347a676 ACO |
12090 | continue; |
12091 | ||
af4a879e DV |
12092 | if (!crtc_state->enable) { |
12093 | any_ms = true; | |
cfb23ed6 | 12094 | continue; |
af4a879e | 12095 | } |
cfb23ed6 | 12096 | |
26495481 DV |
12097 | /* FIXME: For only active_changed we shouldn't need to do any |
12098 | * state recomputation at all. */ | |
12099 | ||
1ed51de9 DV |
12100 | ret = drm_atomic_add_affected_connectors(state, crtc); |
12101 | if (ret) | |
12102 | return ret; | |
b359283a | 12103 | |
cfb23ed6 | 12104 | ret = intel_modeset_pipe_config(crtc, pipe_config); |
25aa1c39 ML |
12105 | if (ret) { |
12106 | intel_dump_pipe_config(to_intel_crtc(crtc), | |
12107 | pipe_config, "[failed]"); | |
c347a676 | 12108 | return ret; |
25aa1c39 | 12109 | } |
c347a676 | 12110 | |
4f044a88 | 12111 | if (i915_modparams.fastboot && |
6315b5d3 | 12112 | intel_pipe_config_compare(dev_priv, |
aa5e9b47 | 12113 | to_intel_crtc_state(old_crtc_state), |
1ed51de9 | 12114 | pipe_config, true)) { |
26495481 | 12115 | crtc_state->mode_changed = false; |
aa5e9b47 | 12116 | pipe_config->update_pipe = true; |
26495481 DV |
12117 | } |
12118 | ||
af4a879e | 12119 | if (needs_modeset(crtc_state)) |
26495481 | 12120 | any_ms = true; |
cfb23ed6 | 12121 | |
af4a879e DV |
12122 | ret = drm_atomic_add_affected_planes(state, crtc); |
12123 | if (ret) | |
12124 | return ret; | |
61333b60 | 12125 | |
26495481 DV |
12126 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, |
12127 | needs_modeset(crtc_state) ? | |
12128 | "[modeset]" : "[fastset]"); | |
c347a676 ACO |
12129 | } |
12130 | ||
61333b60 ML |
12131 | if (any_ms) { |
12132 | ret = intel_modeset_checks(state); | |
12133 | ||
12134 | if (ret) | |
12135 | return ret; | |
e0ca7a6b | 12136 | } else { |
bb0f4aab | 12137 | intel_state->cdclk.logical = dev_priv->cdclk.logical; |
e0ca7a6b | 12138 | } |
76305b1a | 12139 | |
dd8b3bdb | 12140 | ret = drm_atomic_helper_check_planes(dev, state); |
aa363136 MR |
12141 | if (ret) |
12142 | return ret; | |
12143 | ||
f51be2e0 | 12144 | intel_fbc_choose_crtc(dev_priv, state); |
55994c2c | 12145 | return calc_watermark_data(state); |
054518dd ACO |
12146 | } |
12147 | ||
5008e874 | 12148 | static int intel_atomic_prepare_commit(struct drm_device *dev, |
d07f0e59 | 12149 | struct drm_atomic_state *state) |
5008e874 | 12150 | { |
fd70075f | 12151 | return drm_atomic_helper_prepare_planes(dev, state); |
5008e874 ML |
12152 | } |
12153 | ||
a2991414 ML |
12154 | u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc) |
12155 | { | |
12156 | struct drm_device *dev = crtc->base.dev; | |
12157 | ||
12158 | if (!dev->max_vblank_count) | |
ca814b25 | 12159 | return drm_crtc_accurate_vblank_count(&crtc->base); |
a2991414 ML |
12160 | |
12161 | return dev->driver->get_vblank_counter(dev, crtc->pipe); | |
12162 | } | |
12163 | ||
896e5bb0 L |
12164 | static void intel_update_crtc(struct drm_crtc *crtc, |
12165 | struct drm_atomic_state *state, | |
12166 | struct drm_crtc_state *old_crtc_state, | |
b44d5c0c | 12167 | struct drm_crtc_state *new_crtc_state) |
896e5bb0 L |
12168 | { |
12169 | struct drm_device *dev = crtc->dev; | |
12170 | struct drm_i915_private *dev_priv = to_i915(dev); | |
12171 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
aa5e9b47 ML |
12172 | struct intel_crtc_state *pipe_config = to_intel_crtc_state(new_crtc_state); |
12173 | bool modeset = needs_modeset(new_crtc_state); | |
896e5bb0 L |
12174 | |
12175 | if (modeset) { | |
12176 | update_scanline_offset(intel_crtc); | |
12177 | dev_priv->display.crtc_enable(pipe_config, state); | |
12178 | } else { | |
aa5e9b47 ML |
12179 | intel_pre_plane_update(to_intel_crtc_state(old_crtc_state), |
12180 | pipe_config); | |
896e5bb0 L |
12181 | } |
12182 | ||
12183 | if (drm_atomic_get_existing_plane_state(state, crtc->primary)) { | |
12184 | intel_fbc_enable( | |
12185 | intel_crtc, pipe_config, | |
12186 | to_intel_plane_state(crtc->primary->state)); | |
12187 | } | |
12188 | ||
12189 | drm_atomic_helper_commit_planes_on_crtc(old_crtc_state); | |
896e5bb0 L |
12190 | } |
12191 | ||
b44d5c0c | 12192 | static void intel_update_crtcs(struct drm_atomic_state *state) |
896e5bb0 L |
12193 | { |
12194 | struct drm_crtc *crtc; | |
aa5e9b47 | 12195 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
896e5bb0 L |
12196 | int i; |
12197 | ||
aa5e9b47 ML |
12198 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
12199 | if (!new_crtc_state->active) | |
896e5bb0 L |
12200 | continue; |
12201 | ||
12202 | intel_update_crtc(crtc, state, old_crtc_state, | |
b44d5c0c | 12203 | new_crtc_state); |
896e5bb0 L |
12204 | } |
12205 | } | |
12206 | ||
b44d5c0c | 12207 | static void skl_update_crtcs(struct drm_atomic_state *state) |
27082493 | 12208 | { |
0f0f74bc | 12209 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
27082493 L |
12210 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
12211 | struct drm_crtc *crtc; | |
ce0ba283 | 12212 | struct intel_crtc *intel_crtc; |
aa5e9b47 | 12213 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
ce0ba283 | 12214 | struct intel_crtc_state *cstate; |
27082493 L |
12215 | unsigned int updated = 0; |
12216 | bool progress; | |
12217 | enum pipe pipe; | |
5eff503b ML |
12218 | int i; |
12219 | ||
12220 | const struct skl_ddb_entry *entries[I915_MAX_PIPES] = {}; | |
12221 | ||
aa5e9b47 | 12222 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) |
5eff503b | 12223 | /* ignore allocations for crtc's that have been turned off. */ |
aa5e9b47 | 12224 | if (new_crtc_state->active) |
5eff503b | 12225 | entries[i] = &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb; |
27082493 L |
12226 | |
12227 | /* | |
12228 | * Whenever the number of active pipes changes, we need to make sure we | |
12229 | * update the pipes in the right order so that their ddb allocations | |
12230 | * never overlap with eachother inbetween CRTC updates. Otherwise we'll | |
12231 | * cause pipe underruns and other bad stuff. | |
12232 | */ | |
12233 | do { | |
27082493 L |
12234 | progress = false; |
12235 | ||
aa5e9b47 | 12236 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
27082493 L |
12237 | bool vbl_wait = false; |
12238 | unsigned int cmask = drm_crtc_mask(crtc); | |
ce0ba283 L |
12239 | |
12240 | intel_crtc = to_intel_crtc(crtc); | |
21794813 | 12241 | cstate = to_intel_crtc_state(new_crtc_state); |
ce0ba283 | 12242 | pipe = intel_crtc->pipe; |
27082493 | 12243 | |
5eff503b | 12244 | if (updated & cmask || !cstate->base.active) |
27082493 | 12245 | continue; |
5eff503b | 12246 | |
2b68504b MK |
12247 | if (skl_ddb_allocation_overlaps(dev_priv, |
12248 | entries, | |
12249 | &cstate->wm.skl.ddb, | |
12250 | i)) | |
27082493 L |
12251 | continue; |
12252 | ||
12253 | updated |= cmask; | |
5eff503b | 12254 | entries[i] = &cstate->wm.skl.ddb; |
27082493 L |
12255 | |
12256 | /* | |
12257 | * If this is an already active pipe, it's DDB changed, | |
12258 | * and this isn't the last pipe that needs updating | |
12259 | * then we need to wait for a vblank to pass for the | |
12260 | * new ddb allocation to take effect. | |
12261 | */ | |
ce0ba283 | 12262 | if (!skl_ddb_entry_equal(&cstate->wm.skl.ddb, |
512b5527 | 12263 | &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb) && |
aa5e9b47 | 12264 | !new_crtc_state->active_changed && |
27082493 L |
12265 | intel_state->wm_results.dirty_pipes != updated) |
12266 | vbl_wait = true; | |
12267 | ||
12268 | intel_update_crtc(crtc, state, old_crtc_state, | |
b44d5c0c | 12269 | new_crtc_state); |
27082493 L |
12270 | |
12271 | if (vbl_wait) | |
0f0f74bc | 12272 | intel_wait_for_vblank(dev_priv, pipe); |
27082493 L |
12273 | |
12274 | progress = true; | |
12275 | } | |
12276 | } while (progress); | |
12277 | } | |
12278 | ||
ba318c61 CW |
12279 | static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv) |
12280 | { | |
12281 | struct intel_atomic_state *state, *next; | |
12282 | struct llist_node *freed; | |
12283 | ||
12284 | freed = llist_del_all(&dev_priv->atomic_helper.free_list); | |
12285 | llist_for_each_entry_safe(state, next, freed, freed) | |
12286 | drm_atomic_state_put(&state->base); | |
12287 | } | |
12288 | ||
12289 | static void intel_atomic_helper_free_state_worker(struct work_struct *work) | |
12290 | { | |
12291 | struct drm_i915_private *dev_priv = | |
12292 | container_of(work, typeof(*dev_priv), atomic_helper.free_work); | |
12293 | ||
12294 | intel_atomic_helper_free_state(dev_priv); | |
12295 | } | |
12296 | ||
9db529aa DV |
12297 | static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state) |
12298 | { | |
12299 | struct wait_queue_entry wait_fence, wait_reset; | |
12300 | struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev); | |
12301 | ||
12302 | init_wait_entry(&wait_fence, 0); | |
12303 | init_wait_entry(&wait_reset, 0); | |
12304 | for (;;) { | |
12305 | prepare_to_wait(&intel_state->commit_ready.wait, | |
12306 | &wait_fence, TASK_UNINTERRUPTIBLE); | |
12307 | prepare_to_wait(&dev_priv->gpu_error.wait_queue, | |
12308 | &wait_reset, TASK_UNINTERRUPTIBLE); | |
12309 | ||
12310 | ||
12311 | if (i915_sw_fence_done(&intel_state->commit_ready) | |
12312 | || test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags)) | |
12313 | break; | |
12314 | ||
12315 | schedule(); | |
12316 | } | |
12317 | finish_wait(&intel_state->commit_ready.wait, &wait_fence); | |
12318 | finish_wait(&dev_priv->gpu_error.wait_queue, &wait_reset); | |
12319 | } | |
12320 | ||
94f05024 | 12321 | static void intel_atomic_commit_tail(struct drm_atomic_state *state) |
a6778b3c | 12322 | { |
94f05024 | 12323 | struct drm_device *dev = state->dev; |
565602d7 | 12324 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
fac5e23e | 12325 | struct drm_i915_private *dev_priv = to_i915(dev); |
aa5e9b47 | 12326 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
7580d774 | 12327 | struct drm_crtc *crtc; |
5a21b665 | 12328 | struct intel_crtc_state *intel_cstate; |
d8fc70b7 | 12329 | u64 put_domains[I915_MAX_PIPES] = {}; |
e95433c7 | 12330 | int i; |
a6778b3c | 12331 | |
9db529aa | 12332 | intel_atomic_commit_fence_wait(intel_state); |
42b062b0 | 12333 | |
ea0000f0 DV |
12334 | drm_atomic_helper_wait_for_dependencies(state); |
12335 | ||
c3b32658 | 12336 | if (intel_state->modeset) |
5a21b665 | 12337 | intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET); |
565602d7 | 12338 | |
aa5e9b47 | 12339 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
a539205a ML |
12340 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
12341 | ||
aa5e9b47 ML |
12342 | if (needs_modeset(new_crtc_state) || |
12343 | to_intel_crtc_state(new_crtc_state)->update_pipe) { | |
5a21b665 DV |
12344 | |
12345 | put_domains[to_intel_crtc(crtc)->pipe] = | |
12346 | modeset_get_crtc_power_domains(crtc, | |
aa5e9b47 | 12347 | to_intel_crtc_state(new_crtc_state)); |
5a21b665 DV |
12348 | } |
12349 | ||
aa5e9b47 | 12350 | if (!needs_modeset(new_crtc_state)) |
61333b60 ML |
12351 | continue; |
12352 | ||
aa5e9b47 ML |
12353 | intel_pre_plane_update(to_intel_crtc_state(old_crtc_state), |
12354 | to_intel_crtc_state(new_crtc_state)); | |
460da916 | 12355 | |
29ceb0e6 VS |
12356 | if (old_crtc_state->active) { |
12357 | intel_crtc_disable_planes(crtc, old_crtc_state->plane_mask); | |
4a806558 | 12358 | dev_priv->display.crtc_disable(to_intel_crtc_state(old_crtc_state), state); |
eddfcbcd | 12359 | intel_crtc->active = false; |
58f9c0bc | 12360 | intel_fbc_disable(intel_crtc); |
eddfcbcd | 12361 | intel_disable_shared_dpll(intel_crtc); |
9bbc8258 VS |
12362 | |
12363 | /* | |
12364 | * Underruns don't always raise | |
12365 | * interrupts, so check manually. | |
12366 | */ | |
12367 | intel_check_cpu_fifo_underruns(dev_priv); | |
12368 | intel_check_pch_fifo_underruns(dev_priv); | |
b9001114 | 12369 | |
ad76202c VS |
12370 | /* FIXME unify this for all platforms */ |
12371 | if (!new_crtc_state->active && | |
12372 | !HAS_GMCH_DISPLAY(dev_priv) && | |
12373 | dev_priv->display.initial_watermarks) | |
12374 | dev_priv->display.initial_watermarks(intel_state, | |
12375 | to_intel_crtc_state(new_crtc_state)); | |
a539205a | 12376 | } |
b8cecdf5 | 12377 | } |
7758a113 | 12378 | |
ea9d758d DV |
12379 | /* Only after disabling all output pipelines that will be changed can we |
12380 | * update the the output configuration. */ | |
4740b0f2 | 12381 | intel_modeset_update_crtc_state(state); |
f6e5b160 | 12382 | |
565602d7 | 12383 | if (intel_state->modeset) { |
4740b0f2 | 12384 | drm_atomic_helper_update_legacy_modeset_state(state->dev, state); |
33c8df89 | 12385 | |
163e0af5 VS |
12386 | intel_set_cdclk_pre_plane_update(dev_priv, |
12387 | &intel_state->cdclk.actual, | |
12388 | &dev_priv->cdclk.actual, | |
12389 | intel_state->cdclk.pipe); | |
f6d1973d | 12390 | |
656d1b89 L |
12391 | /* |
12392 | * SKL workaround: bspec recommends we disable the SAGV when we | |
12393 | * have more then one pipe enabled | |
12394 | */ | |
56feca91 | 12395 | if (!intel_can_enable_sagv(state)) |
16dcdc4e | 12396 | intel_disable_sagv(dev_priv); |
656d1b89 | 12397 | |
677100ce | 12398 | intel_modeset_verify_disabled(dev, state); |
4740b0f2 | 12399 | } |
47fab737 | 12400 | |
896e5bb0 | 12401 | /* Complete the events for pipes that have now been disabled */ |
aa5e9b47 ML |
12402 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
12403 | bool modeset = needs_modeset(new_crtc_state); | |
80715b2f | 12404 | |
1f7528c4 | 12405 | /* Complete events for now disable pipes here. */ |
aa5e9b47 | 12406 | if (modeset && !new_crtc_state->active && new_crtc_state->event) { |
1f7528c4 | 12407 | spin_lock_irq(&dev->event_lock); |
aa5e9b47 | 12408 | drm_crtc_send_vblank_event(crtc, new_crtc_state->event); |
1f7528c4 DV |
12409 | spin_unlock_irq(&dev->event_lock); |
12410 | ||
aa5e9b47 | 12411 | new_crtc_state->event = NULL; |
1f7528c4 | 12412 | } |
177246a8 MR |
12413 | } |
12414 | ||
896e5bb0 | 12415 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
b44d5c0c | 12416 | dev_priv->display.update_crtcs(state); |
896e5bb0 | 12417 | |
163e0af5 VS |
12418 | if (intel_state->modeset) |
12419 | intel_set_cdclk_post_plane_update(dev_priv, | |
12420 | &intel_state->cdclk.actual, | |
12421 | &dev_priv->cdclk.actual, | |
12422 | intel_state->cdclk.pipe); | |
12423 | ||
94f05024 DV |
12424 | /* FIXME: We should call drm_atomic_helper_commit_hw_done() here |
12425 | * already, but still need the state for the delayed optimization. To | |
12426 | * fix this: | |
12427 | * - wrap the optimization/post_plane_update stuff into a per-crtc work. | |
12428 | * - schedule that vblank worker _before_ calling hw_done | |
12429 | * - at the start of commit_tail, cancel it _synchrously | |
12430 | * - switch over to the vblank wait helper in the core after that since | |
12431 | * we don't need out special handling any more. | |
12432 | */ | |
b44d5c0c | 12433 | drm_atomic_helper_wait_for_flip_done(dev, state); |
5a21b665 DV |
12434 | |
12435 | /* | |
12436 | * Now that the vblank has passed, we can go ahead and program the | |
12437 | * optimal watermarks on platforms that need two-step watermark | |
12438 | * programming. | |
12439 | * | |
12440 | * TODO: Move this (and other cleanup) to an async worker eventually. | |
12441 | */ | |
aa5e9b47 ML |
12442 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
12443 | intel_cstate = to_intel_crtc_state(new_crtc_state); | |
5a21b665 DV |
12444 | |
12445 | if (dev_priv->display.optimize_watermarks) | |
ccf010fb ML |
12446 | dev_priv->display.optimize_watermarks(intel_state, |
12447 | intel_cstate); | |
5a21b665 DV |
12448 | } |
12449 | ||
aa5e9b47 | 12450 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
5a21b665 DV |
12451 | intel_post_plane_update(to_intel_crtc_state(old_crtc_state)); |
12452 | ||
12453 | if (put_domains[i]) | |
12454 | modeset_put_power_domains(dev_priv, put_domains[i]); | |
12455 | ||
aa5e9b47 | 12456 | intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state); |
5a21b665 DV |
12457 | } |
12458 | ||
56feca91 | 12459 | if (intel_state->modeset && intel_can_enable_sagv(state)) |
16dcdc4e | 12460 | intel_enable_sagv(dev_priv); |
656d1b89 | 12461 | |
94f05024 DV |
12462 | drm_atomic_helper_commit_hw_done(state); |
12463 | ||
d5553c09 CW |
12464 | if (intel_state->modeset) { |
12465 | /* As one of the primary mmio accessors, KMS has a high | |
12466 | * likelihood of triggering bugs in unclaimed access. After we | |
12467 | * finish modesetting, see if an error has been flagged, and if | |
12468 | * so enable debugging for the next modeset - and hope we catch | |
12469 | * the culprit. | |
12470 | */ | |
12471 | intel_uncore_arm_unclaimed_mmio_detection(dev_priv); | |
5a21b665 | 12472 | intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET); |
d5553c09 | 12473 | } |
5a21b665 | 12474 | |
5a21b665 | 12475 | drm_atomic_helper_cleanup_planes(dev, state); |
5a21b665 | 12476 | |
ea0000f0 DV |
12477 | drm_atomic_helper_commit_cleanup_done(state); |
12478 | ||
0853695c | 12479 | drm_atomic_state_put(state); |
f30da187 | 12480 | |
ba318c61 | 12481 | intel_atomic_helper_free_state(dev_priv); |
94f05024 DV |
12482 | } |
12483 | ||
12484 | static void intel_atomic_commit_work(struct work_struct *work) | |
12485 | { | |
c004a90b CW |
12486 | struct drm_atomic_state *state = |
12487 | container_of(work, struct drm_atomic_state, commit_work); | |
12488 | ||
94f05024 DV |
12489 | intel_atomic_commit_tail(state); |
12490 | } | |
12491 | ||
c004a90b CW |
12492 | static int __i915_sw_fence_call |
12493 | intel_atomic_commit_ready(struct i915_sw_fence *fence, | |
12494 | enum i915_sw_fence_notify notify) | |
12495 | { | |
12496 | struct intel_atomic_state *state = | |
12497 | container_of(fence, struct intel_atomic_state, commit_ready); | |
12498 | ||
12499 | switch (notify) { | |
12500 | case FENCE_COMPLETE: | |
42b062b0 | 12501 | /* we do blocking waits in the worker, nothing to do here */ |
c004a90b | 12502 | break; |
c004a90b | 12503 | case FENCE_FREE: |
eb955eee CW |
12504 | { |
12505 | struct intel_atomic_helper *helper = | |
12506 | &to_i915(state->base.dev)->atomic_helper; | |
12507 | ||
12508 | if (llist_add(&state->freed, &helper->free_list)) | |
12509 | schedule_work(&helper->free_work); | |
12510 | break; | |
12511 | } | |
c004a90b CW |
12512 | } |
12513 | ||
12514 | return NOTIFY_DONE; | |
12515 | } | |
12516 | ||
6c9c1b38 DV |
12517 | static void intel_atomic_track_fbs(struct drm_atomic_state *state) |
12518 | { | |
aa5e9b47 | 12519 | struct drm_plane_state *old_plane_state, *new_plane_state; |
6c9c1b38 | 12520 | struct drm_plane *plane; |
6c9c1b38 DV |
12521 | int i; |
12522 | ||
aa5e9b47 | 12523 | for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i) |
faf5bf0a | 12524 | i915_gem_track_fb(intel_fb_obj(old_plane_state->fb), |
aa5e9b47 | 12525 | intel_fb_obj(new_plane_state->fb), |
faf5bf0a | 12526 | to_intel_plane(plane)->frontbuffer_bit); |
6c9c1b38 DV |
12527 | } |
12528 | ||
94f05024 DV |
12529 | /** |
12530 | * intel_atomic_commit - commit validated state object | |
12531 | * @dev: DRM device | |
12532 | * @state: the top-level driver state object | |
12533 | * @nonblock: nonblocking commit | |
12534 | * | |
12535 | * This function commits a top-level state object that has been validated | |
12536 | * with drm_atomic_helper_check(). | |
12537 | * | |
94f05024 DV |
12538 | * RETURNS |
12539 | * Zero for success or -errno. | |
12540 | */ | |
12541 | static int intel_atomic_commit(struct drm_device *dev, | |
12542 | struct drm_atomic_state *state, | |
12543 | bool nonblock) | |
12544 | { | |
12545 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); | |
fac5e23e | 12546 | struct drm_i915_private *dev_priv = to_i915(dev); |
94f05024 DV |
12547 | int ret = 0; |
12548 | ||
c004a90b CW |
12549 | drm_atomic_state_get(state); |
12550 | i915_sw_fence_init(&intel_state->commit_ready, | |
12551 | intel_atomic_commit_ready); | |
94f05024 | 12552 | |
440df938 VS |
12553 | /* |
12554 | * The intel_legacy_cursor_update() fast path takes care | |
12555 | * of avoiding the vblank waits for simple cursor | |
12556 | * movement and flips. For cursor on/off and size changes, | |
12557 | * we want to perform the vblank waits so that watermark | |
12558 | * updates happen during the correct frames. Gen9+ have | |
12559 | * double buffered watermarks and so shouldn't need this. | |
12560 | * | |
3cf50c63 ML |
12561 | * Unset state->legacy_cursor_update before the call to |
12562 | * drm_atomic_helper_setup_commit() because otherwise | |
12563 | * drm_atomic_helper_wait_for_flip_done() is a noop and | |
12564 | * we get FIFO underruns because we didn't wait | |
12565 | * for vblank. | |
440df938 VS |
12566 | * |
12567 | * FIXME doing watermarks and fb cleanup from a vblank worker | |
12568 | * (assuming we had any) would solve these problems. | |
12569 | */ | |
213f1bd0 ML |
12570 | if (INTEL_GEN(dev_priv) < 9 && state->legacy_cursor_update) { |
12571 | struct intel_crtc_state *new_crtc_state; | |
12572 | struct intel_crtc *crtc; | |
12573 | int i; | |
12574 | ||
12575 | for_each_new_intel_crtc_in_state(intel_state, crtc, new_crtc_state, i) | |
12576 | if (new_crtc_state->wm.need_postvbl_update || | |
12577 | new_crtc_state->update_wm_post) | |
12578 | state->legacy_cursor_update = false; | |
12579 | } | |
440df938 | 12580 | |
3cf50c63 ML |
12581 | ret = intel_atomic_prepare_commit(dev, state); |
12582 | if (ret) { | |
12583 | DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret); | |
12584 | i915_sw_fence_commit(&intel_state->commit_ready); | |
12585 | return ret; | |
12586 | } | |
12587 | ||
12588 | ret = drm_atomic_helper_setup_commit(state, nonblock); | |
12589 | if (!ret) | |
12590 | ret = drm_atomic_helper_swap_state(state, true); | |
440df938 | 12591 | |
0806f4ee ML |
12592 | if (ret) { |
12593 | i915_sw_fence_commit(&intel_state->commit_ready); | |
12594 | ||
0806f4ee | 12595 | drm_atomic_helper_cleanup_planes(dev, state); |
0806f4ee ML |
12596 | return ret; |
12597 | } | |
94f05024 | 12598 | dev_priv->wm.distrust_bios_wm = false; |
3c0fb588 | 12599 | intel_shared_dpll_swap_state(state); |
6c9c1b38 | 12600 | intel_atomic_track_fbs(state); |
94f05024 | 12601 | |
c3b32658 | 12602 | if (intel_state->modeset) { |
d305e061 VS |
12603 | memcpy(dev_priv->min_cdclk, intel_state->min_cdclk, |
12604 | sizeof(intel_state->min_cdclk)); | |
c3b32658 | 12605 | dev_priv->active_crtcs = intel_state->active_crtcs; |
68b342c9 VS |
12606 | dev_priv->cdclk.force_min_cdclk = |
12607 | intel_state->cdclk.force_min_cdclk; | |
933af93a ID |
12608 | |
12609 | intel_cdclk_swap_state(intel_state); | |
c3b32658 ML |
12610 | } |
12611 | ||
0853695c | 12612 | drm_atomic_state_get(state); |
42b062b0 | 12613 | INIT_WORK(&state->commit_work, intel_atomic_commit_work); |
c004a90b CW |
12614 | |
12615 | i915_sw_fence_commit(&intel_state->commit_ready); | |
eda41bdc VS |
12616 | if (nonblock && intel_state->modeset) { |
12617 | queue_work(dev_priv->modeset_wq, &state->commit_work); | |
12618 | } else if (nonblock) { | |
42b062b0 | 12619 | queue_work(system_unbound_wq, &state->commit_work); |
eda41bdc VS |
12620 | } else { |
12621 | if (intel_state->modeset) | |
12622 | flush_workqueue(dev_priv->modeset_wq); | |
94f05024 | 12623 | intel_atomic_commit_tail(state); |
eda41bdc | 12624 | } |
75714940 | 12625 | |
74c090b1 | 12626 | return 0; |
7f27126e JB |
12627 | } |
12628 | ||
f6e5b160 | 12629 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
3fab2f09 | 12630 | .gamma_set = drm_atomic_helper_legacy_gamma_set, |
74c090b1 | 12631 | .set_config = drm_atomic_helper_set_config, |
f6e5b160 | 12632 | .destroy = intel_crtc_destroy, |
4c01ded5 | 12633 | .page_flip = drm_atomic_helper_page_flip, |
1356837e MR |
12634 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
12635 | .atomic_destroy_state = intel_crtc_destroy_state, | |
8c6b709d | 12636 | .set_crc_source = intel_crtc_set_crc_source, |
f6e5b160 CW |
12637 | }; |
12638 | ||
74d290f8 CW |
12639 | struct wait_rps_boost { |
12640 | struct wait_queue_entry wait; | |
12641 | ||
12642 | struct drm_crtc *crtc; | |
12643 | struct drm_i915_gem_request *request; | |
12644 | }; | |
12645 | ||
12646 | static int do_rps_boost(struct wait_queue_entry *_wait, | |
12647 | unsigned mode, int sync, void *key) | |
12648 | { | |
12649 | struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait); | |
12650 | struct drm_i915_gem_request *rq = wait->request; | |
12651 | ||
12652 | gen6_rps_boost(rq, NULL); | |
12653 | i915_gem_request_put(rq); | |
12654 | ||
12655 | drm_crtc_vblank_put(wait->crtc); | |
12656 | ||
12657 | list_del(&wait->wait.entry); | |
12658 | kfree(wait); | |
12659 | return 1; | |
12660 | } | |
12661 | ||
12662 | static void add_rps_boost_after_vblank(struct drm_crtc *crtc, | |
12663 | struct dma_fence *fence) | |
12664 | { | |
12665 | struct wait_rps_boost *wait; | |
12666 | ||
12667 | if (!dma_fence_is_i915(fence)) | |
12668 | return; | |
12669 | ||
12670 | if (INTEL_GEN(to_i915(crtc->dev)) < 6) | |
12671 | return; | |
12672 | ||
12673 | if (drm_crtc_vblank_get(crtc)) | |
12674 | return; | |
12675 | ||
12676 | wait = kmalloc(sizeof(*wait), GFP_KERNEL); | |
12677 | if (!wait) { | |
12678 | drm_crtc_vblank_put(crtc); | |
12679 | return; | |
12680 | } | |
12681 | ||
12682 | wait->request = to_request(dma_fence_get(fence)); | |
12683 | wait->crtc = crtc; | |
12684 | ||
12685 | wait->wait.func = do_rps_boost; | |
12686 | wait->wait.flags = 0; | |
12687 | ||
12688 | add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait); | |
12689 | } | |
12690 | ||
6beb8c23 MR |
12691 | /** |
12692 | * intel_prepare_plane_fb - Prepare fb for usage on plane | |
12693 | * @plane: drm plane to prepare for | |
12694 | * @fb: framebuffer to prepare for presentation | |
12695 | * | |
12696 | * Prepares a framebuffer for usage on a display plane. Generally this | |
12697 | * involves pinning the underlying object and updating the frontbuffer tracking | |
12698 | * bits. Some older platforms need special physical address handling for | |
12699 | * cursor planes. | |
12700 | * | |
f935675f ML |
12701 | * Must be called with struct_mutex held. |
12702 | * | |
6beb8c23 MR |
12703 | * Returns 0 on success, negative error code on failure. |
12704 | */ | |
12705 | int | |
12706 | intel_prepare_plane_fb(struct drm_plane *plane, | |
1832040d | 12707 | struct drm_plane_state *new_state) |
465c120c | 12708 | { |
c004a90b CW |
12709 | struct intel_atomic_state *intel_state = |
12710 | to_intel_atomic_state(new_state->state); | |
b7f05d4a | 12711 | struct drm_i915_private *dev_priv = to_i915(plane->dev); |
844f9111 | 12712 | struct drm_framebuffer *fb = new_state->fb; |
6beb8c23 | 12713 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
1ee49399 | 12714 | struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb); |
c004a90b | 12715 | int ret; |
465c120c | 12716 | |
5008e874 ML |
12717 | if (old_obj) { |
12718 | struct drm_crtc_state *crtc_state = | |
c004a90b CW |
12719 | drm_atomic_get_existing_crtc_state(new_state->state, |
12720 | plane->state->crtc); | |
5008e874 ML |
12721 | |
12722 | /* Big Hammer, we also need to ensure that any pending | |
12723 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the | |
12724 | * current scanout is retired before unpinning the old | |
12725 | * framebuffer. Note that we rely on userspace rendering | |
12726 | * into the buffer attached to the pipe they are waiting | |
12727 | * on. If not, userspace generates a GPU hang with IPEHR | |
12728 | * point to the MI_WAIT_FOR_EVENT. | |
12729 | * | |
12730 | * This should only fail upon a hung GPU, in which case we | |
12731 | * can safely continue. | |
12732 | */ | |
c004a90b CW |
12733 | if (needs_modeset(crtc_state)) { |
12734 | ret = i915_sw_fence_await_reservation(&intel_state->commit_ready, | |
12735 | old_obj->resv, NULL, | |
12736 | false, 0, | |
12737 | GFP_KERNEL); | |
12738 | if (ret < 0) | |
12739 | return ret; | |
f4457ae7 | 12740 | } |
5008e874 ML |
12741 | } |
12742 | ||
c004a90b CW |
12743 | if (new_state->fence) { /* explicit fencing */ |
12744 | ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready, | |
12745 | new_state->fence, | |
12746 | I915_FENCE_TIMEOUT, | |
12747 | GFP_KERNEL); | |
12748 | if (ret < 0) | |
12749 | return ret; | |
12750 | } | |
12751 | ||
c37efb99 CW |
12752 | if (!obj) |
12753 | return 0; | |
12754 | ||
4d3088c7 | 12755 | ret = i915_gem_object_pin_pages(obj); |
fd70075f CW |
12756 | if (ret) |
12757 | return ret; | |
12758 | ||
4d3088c7 CW |
12759 | ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex); |
12760 | if (ret) { | |
12761 | i915_gem_object_unpin_pages(obj); | |
12762 | return ret; | |
12763 | } | |
12764 | ||
fd70075f CW |
12765 | if (plane->type == DRM_PLANE_TYPE_CURSOR && |
12766 | INTEL_INFO(dev_priv)->cursor_needs_physical) { | |
12767 | const int align = intel_cursor_alignment(dev_priv); | |
12768 | ||
12769 | ret = i915_gem_object_attach_phys(obj, align); | |
12770 | } else { | |
12771 | struct i915_vma *vma; | |
12772 | ||
12773 | vma = intel_pin_and_fence_fb_obj(fb, new_state->rotation); | |
12774 | if (!IS_ERR(vma)) | |
12775 | to_intel_plane_state(new_state)->vma = vma; | |
12776 | else | |
12777 | ret = PTR_ERR(vma); | |
12778 | } | |
12779 | ||
12780 | i915_gem_object_wait_priority(obj, 0, I915_PRIORITY_DISPLAY); | |
12781 | ||
12782 | mutex_unlock(&dev_priv->drm.struct_mutex); | |
4d3088c7 | 12783 | i915_gem_object_unpin_pages(obj); |
fd70075f CW |
12784 | if (ret) |
12785 | return ret; | |
12786 | ||
c004a90b | 12787 | if (!new_state->fence) { /* implicit fencing */ |
74d290f8 CW |
12788 | struct dma_fence *fence; |
12789 | ||
c004a90b CW |
12790 | ret = i915_sw_fence_await_reservation(&intel_state->commit_ready, |
12791 | obj->resv, NULL, | |
12792 | false, I915_FENCE_TIMEOUT, | |
12793 | GFP_KERNEL); | |
12794 | if (ret < 0) | |
12795 | return ret; | |
74d290f8 CW |
12796 | |
12797 | fence = reservation_object_get_excl_rcu(obj->resv); | |
12798 | if (fence) { | |
12799 | add_rps_boost_after_vblank(new_state->crtc, fence); | |
12800 | dma_fence_put(fence); | |
12801 | } | |
12802 | } else { | |
12803 | add_rps_boost_after_vblank(new_state->crtc, new_state->fence); | |
c004a90b | 12804 | } |
5a21b665 | 12805 | |
d07f0e59 | 12806 | return 0; |
6beb8c23 MR |
12807 | } |
12808 | ||
38f3ce3a MR |
12809 | /** |
12810 | * intel_cleanup_plane_fb - Cleans up an fb after plane use | |
12811 | * @plane: drm plane to clean up for | |
12812 | * @fb: old framebuffer that was on plane | |
12813 | * | |
12814 | * Cleans up a framebuffer that has just been removed from a plane. | |
f935675f ML |
12815 | * |
12816 | * Must be called with struct_mutex held. | |
38f3ce3a MR |
12817 | */ |
12818 | void | |
12819 | intel_cleanup_plane_fb(struct drm_plane *plane, | |
1832040d | 12820 | struct drm_plane_state *old_state) |
38f3ce3a | 12821 | { |
be1e3415 | 12822 | struct i915_vma *vma; |
38f3ce3a | 12823 | |
be1e3415 CW |
12824 | /* Should only be called after a successful intel_prepare_plane_fb()! */ |
12825 | vma = fetch_and_zero(&to_intel_plane_state(old_state)->vma); | |
fd70075f CW |
12826 | if (vma) { |
12827 | mutex_lock(&plane->dev->struct_mutex); | |
be1e3415 | 12828 | intel_unpin_fb_vma(vma); |
fd70075f CW |
12829 | mutex_unlock(&plane->dev->struct_mutex); |
12830 | } | |
465c120c MR |
12831 | } |
12832 | ||
6156a456 CK |
12833 | int |
12834 | skl_max_scale(struct intel_crtc *intel_crtc, struct intel_crtc_state *crtc_state) | |
12835 | { | |
5b7280f0 | 12836 | struct drm_i915_private *dev_priv; |
6156a456 | 12837 | int max_scale; |
5b7280f0 | 12838 | int crtc_clock, max_dotclk; |
6156a456 | 12839 | |
bf8a0af0 | 12840 | if (!intel_crtc || !crtc_state->base.enable) |
6156a456 CK |
12841 | return DRM_PLANE_HELPER_NO_SCALING; |
12842 | ||
5b7280f0 ACO |
12843 | dev_priv = to_i915(intel_crtc->base.dev); |
12844 | ||
6156a456 | 12845 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; |
5b7280f0 ACO |
12846 | max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk; |
12847 | ||
12848 | if (IS_GEMINILAKE(dev_priv)) | |
12849 | max_dotclk *= 2; | |
6156a456 | 12850 | |
5b7280f0 | 12851 | if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock)) |
6156a456 CK |
12852 | return DRM_PLANE_HELPER_NO_SCALING; |
12853 | ||
12854 | /* | |
12855 | * skl max scale is lower of: | |
12856 | * close to 3 but not 3, -1 is for that purpose | |
12857 | * or | |
12858 | * cdclk/crtc_clock | |
12859 | */ | |
5b7280f0 ACO |
12860 | max_scale = min((1 << 16) * 3 - 1, |
12861 | (1 << 8) * ((max_dotclk << 8) / crtc_clock)); | |
6156a456 CK |
12862 | |
12863 | return max_scale; | |
12864 | } | |
12865 | ||
465c120c | 12866 | static int |
282dbf9b | 12867 | intel_check_primary_plane(struct intel_plane *plane, |
061e4b8d | 12868 | struct intel_crtc_state *crtc_state, |
3c692a41 GP |
12869 | struct intel_plane_state *state) |
12870 | { | |
282dbf9b | 12871 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
2b875c22 | 12872 | struct drm_crtc *crtc = state->base.crtc; |
6156a456 | 12873 | int min_scale = DRM_PLANE_HELPER_NO_SCALING; |
061e4b8d ML |
12874 | int max_scale = DRM_PLANE_HELPER_NO_SCALING; |
12875 | bool can_position = false; | |
b63a16f6 | 12876 | int ret; |
465c120c | 12877 | |
b63a16f6 | 12878 | if (INTEL_GEN(dev_priv) >= 9) { |
693bdc28 VS |
12879 | /* use scaler when colorkey is not required */ |
12880 | if (state->ckey.flags == I915_SET_COLORKEY_NONE) { | |
12881 | min_scale = 1; | |
12882 | max_scale = skl_max_scale(to_intel_crtc(crtc), crtc_state); | |
12883 | } | |
d8106366 | 12884 | can_position = true; |
6156a456 | 12885 | } |
d8106366 | 12886 | |
cc926387 DV |
12887 | ret = drm_plane_helper_check_state(&state->base, |
12888 | &state->clip, | |
12889 | min_scale, max_scale, | |
12890 | can_position, true); | |
b63a16f6 VS |
12891 | if (ret) |
12892 | return ret; | |
12893 | ||
cc926387 | 12894 | if (!state->base.fb) |
b63a16f6 VS |
12895 | return 0; |
12896 | ||
12897 | if (INTEL_GEN(dev_priv) >= 9) { | |
12898 | ret = skl_check_plane_surface(state); | |
12899 | if (ret) | |
12900 | return ret; | |
a0864d59 VS |
12901 | |
12902 | state->ctl = skl_plane_ctl(crtc_state, state); | |
12903 | } else { | |
5b7fcc44 VS |
12904 | ret = i9xx_check_plane_surface(state); |
12905 | if (ret) | |
12906 | return ret; | |
12907 | ||
a0864d59 | 12908 | state->ctl = i9xx_plane_ctl(crtc_state, state); |
b63a16f6 VS |
12909 | } |
12910 | ||
12911 | return 0; | |
14af293f GP |
12912 | } |
12913 | ||
5a21b665 DV |
12914 | static void intel_begin_crtc_commit(struct drm_crtc *crtc, |
12915 | struct drm_crtc_state *old_crtc_state) | |
12916 | { | |
12917 | struct drm_device *dev = crtc->dev; | |
62e0fb88 | 12918 | struct drm_i915_private *dev_priv = to_i915(dev); |
5a21b665 | 12919 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
ccf010fb | 12920 | struct intel_crtc_state *old_intel_cstate = |
5a21b665 | 12921 | to_intel_crtc_state(old_crtc_state); |
ccf010fb ML |
12922 | struct intel_atomic_state *old_intel_state = |
12923 | to_intel_atomic_state(old_crtc_state->state); | |
d3a8fb32 VS |
12924 | struct intel_crtc_state *intel_cstate = |
12925 | intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc); | |
12926 | bool modeset = needs_modeset(&intel_cstate->base); | |
5a21b665 | 12927 | |
567f0792 ML |
12928 | if (!modeset && |
12929 | (intel_cstate->base.color_mgmt_changed || | |
12930 | intel_cstate->update_pipe)) { | |
5c857e60 VS |
12931 | intel_color_set_csc(&intel_cstate->base); |
12932 | intel_color_load_luts(&intel_cstate->base); | |
567f0792 ML |
12933 | } |
12934 | ||
5a21b665 | 12935 | /* Perform vblank evasion around commit operation */ |
d3a8fb32 | 12936 | intel_pipe_update_start(intel_cstate); |
5a21b665 DV |
12937 | |
12938 | if (modeset) | |
e62929b3 | 12939 | goto out; |
5a21b665 | 12940 | |
ccf010fb | 12941 | if (intel_cstate->update_pipe) |
1a15b77b | 12942 | intel_update_pipe_config(old_intel_cstate, intel_cstate); |
ccf010fb | 12943 | else if (INTEL_GEN(dev_priv) >= 9) |
5a21b665 | 12944 | skl_detach_scalers(intel_crtc); |
62e0fb88 | 12945 | |
e62929b3 | 12946 | out: |
ccf010fb ML |
12947 | if (dev_priv->display.atomic_update_watermarks) |
12948 | dev_priv->display.atomic_update_watermarks(old_intel_state, | |
12949 | intel_cstate); | |
5a21b665 DV |
12950 | } |
12951 | ||
12952 | static void intel_finish_crtc_commit(struct drm_crtc *crtc, | |
12953 | struct drm_crtc_state *old_crtc_state) | |
12954 | { | |
12955 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
d3a8fb32 VS |
12956 | struct intel_atomic_state *old_intel_state = |
12957 | to_intel_atomic_state(old_crtc_state->state); | |
12958 | struct intel_crtc_state *new_crtc_state = | |
12959 | intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc); | |
5a21b665 | 12960 | |
d3a8fb32 | 12961 | intel_pipe_update_end(new_crtc_state); |
5a21b665 DV |
12962 | } |
12963 | ||
cf4c7c12 | 12964 | /** |
4a3b8769 MR |
12965 | * intel_plane_destroy - destroy a plane |
12966 | * @plane: plane to destroy | |
cf4c7c12 | 12967 | * |
4a3b8769 MR |
12968 | * Common destruction function for all types of planes (primary, cursor, |
12969 | * sprite). | |
cf4c7c12 | 12970 | */ |
4a3b8769 | 12971 | void intel_plane_destroy(struct drm_plane *plane) |
465c120c | 12972 | { |
465c120c | 12973 | drm_plane_cleanup(plane); |
69ae561f | 12974 | kfree(to_intel_plane(plane)); |
465c120c MR |
12975 | } |
12976 | ||
714244e2 BW |
12977 | static bool i8xx_mod_supported(uint32_t format, uint64_t modifier) |
12978 | { | |
12979 | switch (format) { | |
12980 | case DRM_FORMAT_C8: | |
12981 | case DRM_FORMAT_RGB565: | |
12982 | case DRM_FORMAT_XRGB1555: | |
12983 | case DRM_FORMAT_XRGB8888: | |
12984 | return modifier == DRM_FORMAT_MOD_LINEAR || | |
12985 | modifier == I915_FORMAT_MOD_X_TILED; | |
12986 | default: | |
12987 | return false; | |
12988 | } | |
12989 | } | |
12990 | ||
12991 | static bool i965_mod_supported(uint32_t format, uint64_t modifier) | |
12992 | { | |
12993 | switch (format) { | |
12994 | case DRM_FORMAT_C8: | |
12995 | case DRM_FORMAT_RGB565: | |
12996 | case DRM_FORMAT_XRGB8888: | |
12997 | case DRM_FORMAT_XBGR8888: | |
12998 | case DRM_FORMAT_XRGB2101010: | |
12999 | case DRM_FORMAT_XBGR2101010: | |
13000 | return modifier == DRM_FORMAT_MOD_LINEAR || | |
13001 | modifier == I915_FORMAT_MOD_X_TILED; | |
13002 | default: | |
13003 | return false; | |
13004 | } | |
13005 | } | |
13006 | ||
13007 | static bool skl_mod_supported(uint32_t format, uint64_t modifier) | |
13008 | { | |
13009 | switch (format) { | |
13010 | case DRM_FORMAT_XRGB8888: | |
13011 | case DRM_FORMAT_XBGR8888: | |
13012 | case DRM_FORMAT_ARGB8888: | |
13013 | case DRM_FORMAT_ABGR8888: | |
13014 | if (modifier == I915_FORMAT_MOD_Yf_TILED_CCS || | |
13015 | modifier == I915_FORMAT_MOD_Y_TILED_CCS) | |
13016 | return true; | |
13017 | /* fall through */ | |
13018 | case DRM_FORMAT_RGB565: | |
13019 | case DRM_FORMAT_XRGB2101010: | |
13020 | case DRM_FORMAT_XBGR2101010: | |
13021 | case DRM_FORMAT_YUYV: | |
13022 | case DRM_FORMAT_YVYU: | |
13023 | case DRM_FORMAT_UYVY: | |
13024 | case DRM_FORMAT_VYUY: | |
13025 | if (modifier == I915_FORMAT_MOD_Yf_TILED) | |
13026 | return true; | |
13027 | /* fall through */ | |
13028 | case DRM_FORMAT_C8: | |
13029 | if (modifier == DRM_FORMAT_MOD_LINEAR || | |
13030 | modifier == I915_FORMAT_MOD_X_TILED || | |
13031 | modifier == I915_FORMAT_MOD_Y_TILED) | |
13032 | return true; | |
13033 | /* fall through */ | |
13034 | default: | |
13035 | return false; | |
13036 | } | |
13037 | } | |
13038 | ||
13039 | static bool intel_primary_plane_format_mod_supported(struct drm_plane *plane, | |
13040 | uint32_t format, | |
13041 | uint64_t modifier) | |
13042 | { | |
13043 | struct drm_i915_private *dev_priv = to_i915(plane->dev); | |
13044 | ||
13045 | if (WARN_ON(modifier == DRM_FORMAT_MOD_INVALID)) | |
13046 | return false; | |
13047 | ||
13048 | if ((modifier >> 56) != DRM_FORMAT_MOD_VENDOR_INTEL && | |
13049 | modifier != DRM_FORMAT_MOD_LINEAR) | |
13050 | return false; | |
13051 | ||
13052 | if (INTEL_GEN(dev_priv) >= 9) | |
13053 | return skl_mod_supported(format, modifier); | |
13054 | else if (INTEL_GEN(dev_priv) >= 4) | |
13055 | return i965_mod_supported(format, modifier); | |
13056 | else | |
13057 | return i8xx_mod_supported(format, modifier); | |
13058 | ||
13059 | unreachable(); | |
13060 | } | |
13061 | ||
13062 | static bool intel_cursor_plane_format_mod_supported(struct drm_plane *plane, | |
13063 | uint32_t format, | |
13064 | uint64_t modifier) | |
13065 | { | |
13066 | if (WARN_ON(modifier == DRM_FORMAT_MOD_INVALID)) | |
13067 | return false; | |
13068 | ||
13069 | return modifier == DRM_FORMAT_MOD_LINEAR && format == DRM_FORMAT_ARGB8888; | |
13070 | } | |
13071 | ||
13072 | static struct drm_plane_funcs intel_plane_funcs = { | |
70a101f8 MR |
13073 | .update_plane = drm_atomic_helper_update_plane, |
13074 | .disable_plane = drm_atomic_helper_disable_plane, | |
3d7d6510 | 13075 | .destroy = intel_plane_destroy, |
a98b3431 MR |
13076 | .atomic_get_property = intel_plane_atomic_get_property, |
13077 | .atomic_set_property = intel_plane_atomic_set_property, | |
ea2c67bb MR |
13078 | .atomic_duplicate_state = intel_plane_duplicate_state, |
13079 | .atomic_destroy_state = intel_plane_destroy_state, | |
714244e2 | 13080 | .format_mod_supported = intel_primary_plane_format_mod_supported, |
465c120c MR |
13081 | }; |
13082 | ||
f79f2692 ML |
13083 | static int |
13084 | intel_legacy_cursor_update(struct drm_plane *plane, | |
13085 | struct drm_crtc *crtc, | |
13086 | struct drm_framebuffer *fb, | |
13087 | int crtc_x, int crtc_y, | |
13088 | unsigned int crtc_w, unsigned int crtc_h, | |
13089 | uint32_t src_x, uint32_t src_y, | |
34a2ab5e DV |
13090 | uint32_t src_w, uint32_t src_h, |
13091 | struct drm_modeset_acquire_ctx *ctx) | |
f79f2692 ML |
13092 | { |
13093 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); | |
13094 | int ret; | |
13095 | struct drm_plane_state *old_plane_state, *new_plane_state; | |
13096 | struct intel_plane *intel_plane = to_intel_plane(plane); | |
13097 | struct drm_framebuffer *old_fb; | |
13098 | struct drm_crtc_state *crtc_state = crtc->state; | |
fd70075f | 13099 | struct i915_vma *old_vma, *vma; |
f79f2692 ML |
13100 | |
13101 | /* | |
13102 | * When crtc is inactive or there is a modeset pending, | |
13103 | * wait for it to complete in the slowpath | |
13104 | */ | |
13105 | if (!crtc_state->active || needs_modeset(crtc_state) || | |
13106 | to_intel_crtc_state(crtc_state)->update_pipe) | |
13107 | goto slow; | |
13108 | ||
13109 | old_plane_state = plane->state; | |
669c9215 ML |
13110 | /* |
13111 | * Don't do an async update if there is an outstanding commit modifying | |
13112 | * the plane. This prevents our async update's changes from getting | |
13113 | * overridden by a previous synchronous update's state. | |
13114 | */ | |
13115 | if (old_plane_state->commit && | |
13116 | !try_wait_for_completion(&old_plane_state->commit->hw_done)) | |
13117 | goto slow; | |
f79f2692 ML |
13118 | |
13119 | /* | |
13120 | * If any parameters change that may affect watermarks, | |
13121 | * take the slowpath. Only changing fb or position should be | |
13122 | * in the fastpath. | |
13123 | */ | |
13124 | if (old_plane_state->crtc != crtc || | |
13125 | old_plane_state->src_w != src_w || | |
13126 | old_plane_state->src_h != src_h || | |
13127 | old_plane_state->crtc_w != crtc_w || | |
13128 | old_plane_state->crtc_h != crtc_h || | |
a5509abd | 13129 | !old_plane_state->fb != !fb) |
f79f2692 ML |
13130 | goto slow; |
13131 | ||
13132 | new_plane_state = intel_plane_duplicate_state(plane); | |
13133 | if (!new_plane_state) | |
13134 | return -ENOMEM; | |
13135 | ||
13136 | drm_atomic_set_fb_for_plane(new_plane_state, fb); | |
13137 | ||
13138 | new_plane_state->src_x = src_x; | |
13139 | new_plane_state->src_y = src_y; | |
13140 | new_plane_state->src_w = src_w; | |
13141 | new_plane_state->src_h = src_h; | |
13142 | new_plane_state->crtc_x = crtc_x; | |
13143 | new_plane_state->crtc_y = crtc_y; | |
13144 | new_plane_state->crtc_w = crtc_w; | |
13145 | new_plane_state->crtc_h = crtc_h; | |
13146 | ||
13147 | ret = intel_plane_atomic_check_with_state(to_intel_crtc_state(crtc->state), | |
b2b55502 VS |
13148 | to_intel_crtc_state(crtc->state), /* FIXME need a new crtc state? */ |
13149 | to_intel_plane_state(plane->state), | |
f79f2692 ML |
13150 | to_intel_plane_state(new_plane_state)); |
13151 | if (ret) | |
13152 | goto out_free; | |
13153 | ||
f79f2692 ML |
13154 | ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex); |
13155 | if (ret) | |
13156 | goto out_free; | |
13157 | ||
13158 | if (INTEL_INFO(dev_priv)->cursor_needs_physical) { | |
fabac484 | 13159 | int align = intel_cursor_alignment(dev_priv); |
f79f2692 ML |
13160 | |
13161 | ret = i915_gem_object_attach_phys(intel_fb_obj(fb), align); | |
13162 | if (ret) { | |
13163 | DRM_DEBUG_KMS("failed to attach phys object\n"); | |
13164 | goto out_unlock; | |
13165 | } | |
13166 | } else { | |
f79f2692 ML |
13167 | vma = intel_pin_and_fence_fb_obj(fb, new_plane_state->rotation); |
13168 | if (IS_ERR(vma)) { | |
13169 | DRM_DEBUG_KMS("failed to pin object\n"); | |
13170 | ||
13171 | ret = PTR_ERR(vma); | |
13172 | goto out_unlock; | |
13173 | } | |
be1e3415 CW |
13174 | |
13175 | to_intel_plane_state(new_plane_state)->vma = vma; | |
f79f2692 ML |
13176 | } |
13177 | ||
13178 | old_fb = old_plane_state->fb; | |
13179 | ||
13180 | i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb), | |
13181 | intel_plane->frontbuffer_bit); | |
13182 | ||
13183 | /* Swap plane state */ | |
669c9215 | 13184 | plane->state = new_plane_state; |
f79f2692 | 13185 | |
72259536 VS |
13186 | if (plane->state->visible) { |
13187 | trace_intel_update_plane(plane, to_intel_crtc(crtc)); | |
282dbf9b | 13188 | intel_plane->update_plane(intel_plane, |
a5509abd VS |
13189 | to_intel_crtc_state(crtc->state), |
13190 | to_intel_plane_state(plane->state)); | |
72259536 VS |
13191 | } else { |
13192 | trace_intel_disable_plane(plane, to_intel_crtc(crtc)); | |
282dbf9b | 13193 | intel_plane->disable_plane(intel_plane, to_intel_crtc(crtc)); |
72259536 | 13194 | } |
f79f2692 | 13195 | |
669c9215 | 13196 | old_vma = fetch_and_zero(&to_intel_plane_state(old_plane_state)->vma); |
fd70075f CW |
13197 | if (old_vma) |
13198 | intel_unpin_fb_vma(old_vma); | |
f79f2692 ML |
13199 | |
13200 | out_unlock: | |
13201 | mutex_unlock(&dev_priv->drm.struct_mutex); | |
13202 | out_free: | |
669c9215 ML |
13203 | if (ret) |
13204 | intel_plane_destroy_state(plane, new_plane_state); | |
13205 | else | |
13206 | intel_plane_destroy_state(plane, old_plane_state); | |
f79f2692 ML |
13207 | return ret; |
13208 | ||
f79f2692 ML |
13209 | slow: |
13210 | return drm_atomic_helper_update_plane(plane, crtc, fb, | |
13211 | crtc_x, crtc_y, crtc_w, crtc_h, | |
34a2ab5e | 13212 | src_x, src_y, src_w, src_h, ctx); |
f79f2692 ML |
13213 | } |
13214 | ||
13215 | static const struct drm_plane_funcs intel_cursor_plane_funcs = { | |
13216 | .update_plane = intel_legacy_cursor_update, | |
13217 | .disable_plane = drm_atomic_helper_disable_plane, | |
13218 | .destroy = intel_plane_destroy, | |
f79f2692 ML |
13219 | .atomic_get_property = intel_plane_atomic_get_property, |
13220 | .atomic_set_property = intel_plane_atomic_set_property, | |
13221 | .atomic_duplicate_state = intel_plane_duplicate_state, | |
13222 | .atomic_destroy_state = intel_plane_destroy_state, | |
714244e2 | 13223 | .format_mod_supported = intel_cursor_plane_format_mod_supported, |
f79f2692 ML |
13224 | }; |
13225 | ||
b079bd17 | 13226 | static struct intel_plane * |
580503c7 | 13227 | intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe) |
465c120c | 13228 | { |
fca0ce2a VS |
13229 | struct intel_plane *primary = NULL; |
13230 | struct intel_plane_state *state = NULL; | |
465c120c | 13231 | const uint32_t *intel_primary_formats; |
93ca7e00 | 13232 | unsigned int supported_rotations; |
45e3743a | 13233 | unsigned int num_formats; |
714244e2 | 13234 | const uint64_t *modifiers; |
fca0ce2a | 13235 | int ret; |
465c120c MR |
13236 | |
13237 | primary = kzalloc(sizeof(*primary), GFP_KERNEL); | |
b079bd17 VS |
13238 | if (!primary) { |
13239 | ret = -ENOMEM; | |
fca0ce2a | 13240 | goto fail; |
b079bd17 | 13241 | } |
465c120c | 13242 | |
8e7d688b | 13243 | state = intel_create_plane_state(&primary->base); |
b079bd17 VS |
13244 | if (!state) { |
13245 | ret = -ENOMEM; | |
fca0ce2a | 13246 | goto fail; |
b079bd17 VS |
13247 | } |
13248 | ||
8e7d688b | 13249 | primary->base.state = &state->base; |
ea2c67bb | 13250 | |
465c120c MR |
13251 | primary->can_scale = false; |
13252 | primary->max_downscale = 1; | |
580503c7 | 13253 | if (INTEL_GEN(dev_priv) >= 9) { |
6156a456 | 13254 | primary->can_scale = true; |
af99ceda | 13255 | state->scaler_id = -1; |
6156a456 | 13256 | } |
465c120c | 13257 | primary->pipe = pipe; |
e3c566df VS |
13258 | /* |
13259 | * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS | |
13260 | * port is hooked to pipe B. Hence we want plane A feeding pipe B. | |
13261 | */ | |
13262 | if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4) | |
13263 | primary->plane = (enum plane) !pipe; | |
13264 | else | |
13265 | primary->plane = (enum plane) pipe; | |
b14e5848 | 13266 | primary->id = PLANE_PRIMARY; |
a9ff8714 | 13267 | primary->frontbuffer_bit = INTEL_FRONTBUFFER_PRIMARY(pipe); |
c59cb179 | 13268 | primary->check_plane = intel_check_primary_plane; |
465c120c | 13269 | |
8bc0d7ac | 13270 | if (INTEL_GEN(dev_priv) >= 10) { |
6c0fd451 DL |
13271 | intel_primary_formats = skl_primary_formats; |
13272 | num_formats = ARRAY_SIZE(skl_primary_formats); | |
714244e2 BW |
13273 | modifiers = skl_format_modifiers_ccs; |
13274 | ||
9a8cc576 | 13275 | primary->update_plane = skl_update_plane; |
779d4d8f | 13276 | primary->disable_plane = skl_disable_plane; |
d87ce764 | 13277 | primary->get_hw_state = skl_plane_get_hw_state; |
714244e2 BW |
13278 | } else if (INTEL_GEN(dev_priv) >= 9) { |
13279 | intel_primary_formats = skl_primary_formats; | |
13280 | num_formats = ARRAY_SIZE(skl_primary_formats); | |
13281 | if (pipe < PIPE_C) | |
13282 | modifiers = skl_format_modifiers_ccs; | |
13283 | else | |
13284 | modifiers = skl_format_modifiers_noccs; | |
a8d201af | 13285 | |
9a8cc576 | 13286 | primary->update_plane = skl_update_plane; |
779d4d8f | 13287 | primary->disable_plane = skl_disable_plane; |
d87ce764 | 13288 | primary->get_hw_state = skl_plane_get_hw_state; |
580503c7 | 13289 | } else if (INTEL_GEN(dev_priv) >= 4) { |
568db4f2 DL |
13290 | intel_primary_formats = i965_primary_formats; |
13291 | num_formats = ARRAY_SIZE(i965_primary_formats); | |
714244e2 | 13292 | modifiers = i9xx_format_modifiers; |
a8d201af ML |
13293 | |
13294 | primary->update_plane = i9xx_update_primary_plane; | |
13295 | primary->disable_plane = i9xx_disable_primary_plane; | |
d87ce764 | 13296 | primary->get_hw_state = i9xx_plane_get_hw_state; |
6c0fd451 DL |
13297 | } else { |
13298 | intel_primary_formats = i8xx_primary_formats; | |
13299 | num_formats = ARRAY_SIZE(i8xx_primary_formats); | |
714244e2 | 13300 | modifiers = i9xx_format_modifiers; |
a8d201af ML |
13301 | |
13302 | primary->update_plane = i9xx_update_primary_plane; | |
13303 | primary->disable_plane = i9xx_disable_primary_plane; | |
d87ce764 | 13304 | primary->get_hw_state = i9xx_plane_get_hw_state; |
465c120c MR |
13305 | } |
13306 | ||
580503c7 VS |
13307 | if (INTEL_GEN(dev_priv) >= 9) |
13308 | ret = drm_universal_plane_init(&dev_priv->drm, &primary->base, | |
13309 | 0, &intel_plane_funcs, | |
38573dc1 | 13310 | intel_primary_formats, num_formats, |
714244e2 | 13311 | modifiers, |
38573dc1 VS |
13312 | DRM_PLANE_TYPE_PRIMARY, |
13313 | "plane 1%c", pipe_name(pipe)); | |
9beb5fea | 13314 | else if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) |
580503c7 VS |
13315 | ret = drm_universal_plane_init(&dev_priv->drm, &primary->base, |
13316 | 0, &intel_plane_funcs, | |
38573dc1 | 13317 | intel_primary_formats, num_formats, |
714244e2 | 13318 | modifiers, |
38573dc1 VS |
13319 | DRM_PLANE_TYPE_PRIMARY, |
13320 | "primary %c", pipe_name(pipe)); | |
13321 | else | |
580503c7 VS |
13322 | ret = drm_universal_plane_init(&dev_priv->drm, &primary->base, |
13323 | 0, &intel_plane_funcs, | |
38573dc1 | 13324 | intel_primary_formats, num_formats, |
714244e2 | 13325 | modifiers, |
38573dc1 VS |
13326 | DRM_PLANE_TYPE_PRIMARY, |
13327 | "plane %c", plane_name(primary->plane)); | |
fca0ce2a VS |
13328 | if (ret) |
13329 | goto fail; | |
48404c1e | 13330 | |
5481e27f | 13331 | if (INTEL_GEN(dev_priv) >= 9) { |
93ca7e00 | 13332 | supported_rotations = |
c2c446ad RF |
13333 | DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 | |
13334 | DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270; | |
4ea7be2b VS |
13335 | } else if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) { |
13336 | supported_rotations = | |
c2c446ad RF |
13337 | DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 | |
13338 | DRM_MODE_REFLECT_X; | |
5481e27f | 13339 | } else if (INTEL_GEN(dev_priv) >= 4) { |
93ca7e00 | 13340 | supported_rotations = |
c2c446ad | 13341 | DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180; |
93ca7e00 | 13342 | } else { |
c2c446ad | 13343 | supported_rotations = DRM_MODE_ROTATE_0; |
93ca7e00 VS |
13344 | } |
13345 | ||
5481e27f | 13346 | if (INTEL_GEN(dev_priv) >= 4) |
93ca7e00 | 13347 | drm_plane_create_rotation_property(&primary->base, |
c2c446ad | 13348 | DRM_MODE_ROTATE_0, |
93ca7e00 | 13349 | supported_rotations); |
48404c1e | 13350 | |
ea2c67bb MR |
13351 | drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs); |
13352 | ||
b079bd17 | 13353 | return primary; |
fca0ce2a VS |
13354 | |
13355 | fail: | |
13356 | kfree(state); | |
13357 | kfree(primary); | |
13358 | ||
b079bd17 | 13359 | return ERR_PTR(ret); |
465c120c MR |
13360 | } |
13361 | ||
b079bd17 | 13362 | static struct intel_plane * |
b2d03b0d VS |
13363 | intel_cursor_plane_create(struct drm_i915_private *dev_priv, |
13364 | enum pipe pipe) | |
3d7d6510 | 13365 | { |
fca0ce2a VS |
13366 | struct intel_plane *cursor = NULL; |
13367 | struct intel_plane_state *state = NULL; | |
13368 | int ret; | |
3d7d6510 MR |
13369 | |
13370 | cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); | |
b079bd17 VS |
13371 | if (!cursor) { |
13372 | ret = -ENOMEM; | |
fca0ce2a | 13373 | goto fail; |
b079bd17 | 13374 | } |
3d7d6510 | 13375 | |
8e7d688b | 13376 | state = intel_create_plane_state(&cursor->base); |
b079bd17 VS |
13377 | if (!state) { |
13378 | ret = -ENOMEM; | |
fca0ce2a | 13379 | goto fail; |
b079bd17 VS |
13380 | } |
13381 | ||
8e7d688b | 13382 | cursor->base.state = &state->base; |
ea2c67bb | 13383 | |
3d7d6510 MR |
13384 | cursor->can_scale = false; |
13385 | cursor->max_downscale = 1; | |
13386 | cursor->pipe = pipe; | |
13387 | cursor->plane = pipe; | |
b14e5848 | 13388 | cursor->id = PLANE_CURSOR; |
a9ff8714 | 13389 | cursor->frontbuffer_bit = INTEL_FRONTBUFFER_CURSOR(pipe); |
b2d03b0d VS |
13390 | |
13391 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) { | |
13392 | cursor->update_plane = i845_update_cursor; | |
13393 | cursor->disable_plane = i845_disable_cursor; | |
d87ce764 | 13394 | cursor->get_hw_state = i845_cursor_get_hw_state; |
659056f2 | 13395 | cursor->check_plane = i845_check_cursor; |
b2d03b0d VS |
13396 | } else { |
13397 | cursor->update_plane = i9xx_update_cursor; | |
13398 | cursor->disable_plane = i9xx_disable_cursor; | |
d87ce764 | 13399 | cursor->get_hw_state = i9xx_cursor_get_hw_state; |
659056f2 | 13400 | cursor->check_plane = i9xx_check_cursor; |
b2d03b0d | 13401 | } |
3d7d6510 | 13402 | |
cd5dcbf1 VS |
13403 | cursor->cursor.base = ~0; |
13404 | cursor->cursor.cntl = ~0; | |
024faac7 VS |
13405 | |
13406 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv)) | |
13407 | cursor->cursor.size = ~0; | |
3d7d6510 | 13408 | |
580503c7 | 13409 | ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base, |
f79f2692 | 13410 | 0, &intel_cursor_plane_funcs, |
fca0ce2a VS |
13411 | intel_cursor_formats, |
13412 | ARRAY_SIZE(intel_cursor_formats), | |
714244e2 BW |
13413 | cursor_format_modifiers, |
13414 | DRM_PLANE_TYPE_CURSOR, | |
38573dc1 | 13415 | "cursor %c", pipe_name(pipe)); |
fca0ce2a VS |
13416 | if (ret) |
13417 | goto fail; | |
4398ad45 | 13418 | |
5481e27f | 13419 | if (INTEL_GEN(dev_priv) >= 4) |
93ca7e00 | 13420 | drm_plane_create_rotation_property(&cursor->base, |
c2c446ad RF |
13421 | DRM_MODE_ROTATE_0, |
13422 | DRM_MODE_ROTATE_0 | | |
13423 | DRM_MODE_ROTATE_180); | |
4398ad45 | 13424 | |
580503c7 | 13425 | if (INTEL_GEN(dev_priv) >= 9) |
af99ceda CK |
13426 | state->scaler_id = -1; |
13427 | ||
ea2c67bb MR |
13428 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
13429 | ||
b079bd17 | 13430 | return cursor; |
fca0ce2a VS |
13431 | |
13432 | fail: | |
13433 | kfree(state); | |
13434 | kfree(cursor); | |
13435 | ||
b079bd17 | 13436 | return ERR_PTR(ret); |
3d7d6510 MR |
13437 | } |
13438 | ||
1c74eeaf NM |
13439 | static void intel_crtc_init_scalers(struct intel_crtc *crtc, |
13440 | struct intel_crtc_state *crtc_state) | |
549e2bfb | 13441 | { |
65edccce VS |
13442 | struct intel_crtc_scaler_state *scaler_state = |
13443 | &crtc_state->scaler_state; | |
1c74eeaf | 13444 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
549e2bfb | 13445 | int i; |
549e2bfb | 13446 | |
1c74eeaf NM |
13447 | crtc->num_scalers = dev_priv->info.num_scalers[crtc->pipe]; |
13448 | if (!crtc->num_scalers) | |
13449 | return; | |
13450 | ||
65edccce VS |
13451 | for (i = 0; i < crtc->num_scalers; i++) { |
13452 | struct intel_scaler *scaler = &scaler_state->scalers[i]; | |
13453 | ||
13454 | scaler->in_use = 0; | |
13455 | scaler->mode = PS_SCALER_MODE_DYN; | |
549e2bfb CK |
13456 | } |
13457 | ||
13458 | scaler_state->scaler_id = -1; | |
13459 | } | |
13460 | ||
5ab0d85b | 13461 | static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe) |
79e53945 JB |
13462 | { |
13463 | struct intel_crtc *intel_crtc; | |
f5de6e07 | 13464 | struct intel_crtc_state *crtc_state = NULL; |
b079bd17 VS |
13465 | struct intel_plane *primary = NULL; |
13466 | struct intel_plane *cursor = NULL; | |
a81d6fa0 | 13467 | int sprite, ret; |
79e53945 | 13468 | |
955382f3 | 13469 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
b079bd17 VS |
13470 | if (!intel_crtc) |
13471 | return -ENOMEM; | |
79e53945 | 13472 | |
f5de6e07 | 13473 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
b079bd17 VS |
13474 | if (!crtc_state) { |
13475 | ret = -ENOMEM; | |
f5de6e07 | 13476 | goto fail; |
b079bd17 | 13477 | } |
550acefd ACO |
13478 | intel_crtc->config = crtc_state; |
13479 | intel_crtc->base.state = &crtc_state->base; | |
07878248 | 13480 | crtc_state->base.crtc = &intel_crtc->base; |
f5de6e07 | 13481 | |
580503c7 | 13482 | primary = intel_primary_plane_create(dev_priv, pipe); |
b079bd17 VS |
13483 | if (IS_ERR(primary)) { |
13484 | ret = PTR_ERR(primary); | |
3d7d6510 | 13485 | goto fail; |
b079bd17 | 13486 | } |
d97d7b48 | 13487 | intel_crtc->plane_ids_mask |= BIT(primary->id); |
3d7d6510 | 13488 | |
a81d6fa0 | 13489 | for_each_sprite(dev_priv, pipe, sprite) { |
b079bd17 VS |
13490 | struct intel_plane *plane; |
13491 | ||
580503c7 | 13492 | plane = intel_sprite_plane_create(dev_priv, pipe, sprite); |
d2b2cbce | 13493 | if (IS_ERR(plane)) { |
b079bd17 VS |
13494 | ret = PTR_ERR(plane); |
13495 | goto fail; | |
13496 | } | |
d97d7b48 | 13497 | intel_crtc->plane_ids_mask |= BIT(plane->id); |
a81d6fa0 VS |
13498 | } |
13499 | ||
580503c7 | 13500 | cursor = intel_cursor_plane_create(dev_priv, pipe); |
d2b2cbce | 13501 | if (IS_ERR(cursor)) { |
b079bd17 | 13502 | ret = PTR_ERR(cursor); |
3d7d6510 | 13503 | goto fail; |
b079bd17 | 13504 | } |
d97d7b48 | 13505 | intel_crtc->plane_ids_mask |= BIT(cursor->id); |
3d7d6510 | 13506 | |
5ab0d85b | 13507 | ret = drm_crtc_init_with_planes(&dev_priv->drm, &intel_crtc->base, |
b079bd17 VS |
13508 | &primary->base, &cursor->base, |
13509 | &intel_crtc_funcs, | |
4d5d72b7 | 13510 | "pipe %c", pipe_name(pipe)); |
3d7d6510 MR |
13511 | if (ret) |
13512 | goto fail; | |
79e53945 | 13513 | |
80824003 | 13514 | intel_crtc->pipe = pipe; |
e3c566df | 13515 | intel_crtc->plane = primary->plane; |
80824003 | 13516 | |
1c74eeaf NM |
13517 | /* initialize shared scalers */ |
13518 | intel_crtc_init_scalers(intel_crtc, crtc_state); | |
13519 | ||
22fd0fab JB |
13520 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
13521 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); | |
e2af48c6 VS |
13522 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = intel_crtc; |
13523 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = intel_crtc; | |
22fd0fab | 13524 | |
79e53945 | 13525 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
87b6b101 | 13526 | |
8563b1e8 LL |
13527 | intel_color_init(&intel_crtc->base); |
13528 | ||
87b6b101 | 13529 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); |
b079bd17 VS |
13530 | |
13531 | return 0; | |
3d7d6510 MR |
13532 | |
13533 | fail: | |
b079bd17 VS |
13534 | /* |
13535 | * drm_mode_config_cleanup() will free up any | |
13536 | * crtcs/planes already initialized. | |
13537 | */ | |
f5de6e07 | 13538 | kfree(crtc_state); |
3d7d6510 | 13539 | kfree(intel_crtc); |
b079bd17 VS |
13540 | |
13541 | return ret; | |
79e53945 JB |
13542 | } |
13543 | ||
752aa88a JB |
13544 | enum pipe intel_get_pipe_from_connector(struct intel_connector *connector) |
13545 | { | |
6e9f798d | 13546 | struct drm_device *dev = connector->base.dev; |
752aa88a | 13547 | |
51fd371b | 13548 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
752aa88a | 13549 | |
51ec53da | 13550 | if (!connector->base.state->crtc) |
752aa88a JB |
13551 | return INVALID_PIPE; |
13552 | ||
51ec53da | 13553 | return to_intel_crtc(connector->base.state->crtc)->pipe; |
752aa88a JB |
13554 | } |
13555 | ||
08d7b3d1 | 13556 | int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data, |
05394f39 | 13557 | struct drm_file *file) |
08d7b3d1 | 13558 | { |
08d7b3d1 | 13559 | struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data; |
7707e653 | 13560 | struct drm_crtc *drmmode_crtc; |
c05422d5 | 13561 | struct intel_crtc *crtc; |
08d7b3d1 | 13562 | |
418da172 | 13563 | drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id); |
71240ed2 | 13564 | if (!drmmode_crtc) |
3f2c2057 | 13565 | return -ENOENT; |
08d7b3d1 | 13566 | |
7707e653 | 13567 | crtc = to_intel_crtc(drmmode_crtc); |
c05422d5 | 13568 | pipe_from_crtc_id->pipe = crtc->pipe; |
08d7b3d1 | 13569 | |
c05422d5 | 13570 | return 0; |
08d7b3d1 CW |
13571 | } |
13572 | ||
66a9278e | 13573 | static int intel_encoder_clones(struct intel_encoder *encoder) |
79e53945 | 13574 | { |
66a9278e DV |
13575 | struct drm_device *dev = encoder->base.dev; |
13576 | struct intel_encoder *source_encoder; | |
79e53945 | 13577 | int index_mask = 0; |
79e53945 JB |
13578 | int entry = 0; |
13579 | ||
b2784e15 | 13580 | for_each_intel_encoder(dev, source_encoder) { |
bc079e8b | 13581 | if (encoders_cloneable(encoder, source_encoder)) |
66a9278e DV |
13582 | index_mask |= (1 << entry); |
13583 | ||
79e53945 JB |
13584 | entry++; |
13585 | } | |
4ef69c7a | 13586 | |
79e53945 JB |
13587 | return index_mask; |
13588 | } | |
13589 | ||
646d5772 | 13590 | static bool has_edp_a(struct drm_i915_private *dev_priv) |
4d302442 | 13591 | { |
646d5772 | 13592 | if (!IS_MOBILE(dev_priv)) |
4d302442 CW |
13593 | return false; |
13594 | ||
13595 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) | |
13596 | return false; | |
13597 | ||
5db94019 | 13598 | if (IS_GEN5(dev_priv) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE)) |
4d302442 CW |
13599 | return false; |
13600 | ||
13601 | return true; | |
13602 | } | |
13603 | ||
6315b5d3 | 13604 | static bool intel_crt_present(struct drm_i915_private *dev_priv) |
84b4e042 | 13605 | { |
6315b5d3 | 13606 | if (INTEL_GEN(dev_priv) >= 9) |
884497ed DL |
13607 | return false; |
13608 | ||
50a0bc90 | 13609 | if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv)) |
84b4e042 JB |
13610 | return false; |
13611 | ||
920a14b2 | 13612 | if (IS_CHERRYVIEW(dev_priv)) |
84b4e042 JB |
13613 | return false; |
13614 | ||
4f8036a2 TU |
13615 | if (HAS_PCH_LPT_H(dev_priv) && |
13616 | I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED) | |
65e472e4 VS |
13617 | return false; |
13618 | ||
70ac54d0 | 13619 | /* DDI E can't be used if DDI A requires 4 lanes */ |
4f8036a2 | 13620 | if (HAS_DDI(dev_priv) && I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) |
70ac54d0 VS |
13621 | return false; |
13622 | ||
e4abb733 | 13623 | if (!dev_priv->vbt.int_crt_support) |
84b4e042 JB |
13624 | return false; |
13625 | ||
13626 | return true; | |
13627 | } | |
13628 | ||
8090ba8c ID |
13629 | void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv) |
13630 | { | |
13631 | int pps_num; | |
13632 | int pps_idx; | |
13633 | ||
13634 | if (HAS_DDI(dev_priv)) | |
13635 | return; | |
13636 | /* | |
13637 | * This w/a is needed at least on CPT/PPT, but to be sure apply it | |
13638 | * everywhere where registers can be write protected. | |
13639 | */ | |
13640 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) | |
13641 | pps_num = 2; | |
13642 | else | |
13643 | pps_num = 1; | |
13644 | ||
13645 | for (pps_idx = 0; pps_idx < pps_num; pps_idx++) { | |
13646 | u32 val = I915_READ(PP_CONTROL(pps_idx)); | |
13647 | ||
13648 | val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS; | |
13649 | I915_WRITE(PP_CONTROL(pps_idx), val); | |
13650 | } | |
13651 | } | |
13652 | ||
44cb734c ID |
13653 | static void intel_pps_init(struct drm_i915_private *dev_priv) |
13654 | { | |
cc3f90f0 | 13655 | if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv)) |
44cb734c ID |
13656 | dev_priv->pps_mmio_base = PCH_PPS_BASE; |
13657 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) | |
13658 | dev_priv->pps_mmio_base = VLV_PPS_BASE; | |
13659 | else | |
13660 | dev_priv->pps_mmio_base = PPS_BASE; | |
8090ba8c ID |
13661 | |
13662 | intel_pps_unlock_regs_wa(dev_priv); | |
44cb734c ID |
13663 | } |
13664 | ||
c39055b0 | 13665 | static void intel_setup_outputs(struct drm_i915_private *dev_priv) |
79e53945 | 13666 | { |
4ef69c7a | 13667 | struct intel_encoder *encoder; |
cb0953d7 | 13668 | bool dpd_is_edp = false; |
79e53945 | 13669 | |
44cb734c ID |
13670 | intel_pps_init(dev_priv); |
13671 | ||
97a824e1 ID |
13672 | /* |
13673 | * intel_edp_init_connector() depends on this completing first, to | |
13674 | * prevent the registeration of both eDP and LVDS and the incorrect | |
13675 | * sharing of the PPS. | |
13676 | */ | |
c39055b0 | 13677 | intel_lvds_init(dev_priv); |
79e53945 | 13678 | |
6315b5d3 | 13679 | if (intel_crt_present(dev_priv)) |
c39055b0 | 13680 | intel_crt_init(dev_priv); |
cb0953d7 | 13681 | |
cc3f90f0 | 13682 | if (IS_GEN9_LP(dev_priv)) { |
c776eb2e VK |
13683 | /* |
13684 | * FIXME: Broxton doesn't support port detection via the | |
13685 | * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to | |
13686 | * detect the ports. | |
13687 | */ | |
c39055b0 ACO |
13688 | intel_ddi_init(dev_priv, PORT_A); |
13689 | intel_ddi_init(dev_priv, PORT_B); | |
13690 | intel_ddi_init(dev_priv, PORT_C); | |
c6c794a2 | 13691 | |
c39055b0 | 13692 | intel_dsi_init(dev_priv); |
4f8036a2 | 13693 | } else if (HAS_DDI(dev_priv)) { |
0e72a5b5 ED |
13694 | int found; |
13695 | ||
de31facd JB |
13696 | /* |
13697 | * Haswell uses DDI functions to detect digital outputs. | |
13698 | * On SKL pre-D0 the strap isn't connected, so we assume | |
13699 | * it's there. | |
13700 | */ | |
77179400 | 13701 | found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED; |
de31facd | 13702 | /* WaIgnoreDDIAStrap: skl */ |
b976dc53 | 13703 | if (found || IS_GEN9_BC(dev_priv)) |
c39055b0 | 13704 | intel_ddi_init(dev_priv, PORT_A); |
0e72a5b5 ED |
13705 | |
13706 | /* DDI B, C and D detection is indicated by the SFUSE_STRAP | |
13707 | * register */ | |
13708 | found = I915_READ(SFUSE_STRAP); | |
13709 | ||
13710 | if (found & SFUSE_STRAP_DDIB_DETECTED) | |
c39055b0 | 13711 | intel_ddi_init(dev_priv, PORT_B); |
0e72a5b5 | 13712 | if (found & SFUSE_STRAP_DDIC_DETECTED) |
c39055b0 | 13713 | intel_ddi_init(dev_priv, PORT_C); |
0e72a5b5 | 13714 | if (found & SFUSE_STRAP_DDID_DETECTED) |
c39055b0 | 13715 | intel_ddi_init(dev_priv, PORT_D); |
2800e4c2 RV |
13716 | /* |
13717 | * On SKL we don't have a way to detect DDI-E so we rely on VBT. | |
13718 | */ | |
b976dc53 | 13719 | if (IS_GEN9_BC(dev_priv) && |
2800e4c2 RV |
13720 | (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp || |
13721 | dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi || | |
13722 | dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi)) | |
c39055b0 | 13723 | intel_ddi_init(dev_priv, PORT_E); |
2800e4c2 | 13724 | |
6e266956 | 13725 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
cb0953d7 | 13726 | int found; |
7b91bf7f | 13727 | dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D); |
270b3042 | 13728 | |
646d5772 | 13729 | if (has_edp_a(dev_priv)) |
c39055b0 | 13730 | intel_dp_init(dev_priv, DP_A, PORT_A); |
cb0953d7 | 13731 | |
dc0fa718 | 13732 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
461ed3ca | 13733 | /* PCH SDVOB multiplex with HDMIB */ |
c39055b0 | 13734 | found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B); |
30ad48b7 | 13735 | if (!found) |
c39055b0 | 13736 | intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B); |
5eb08b69 | 13737 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
c39055b0 | 13738 | intel_dp_init(dev_priv, PCH_DP_B, PORT_B); |
30ad48b7 ZW |
13739 | } |
13740 | ||
dc0fa718 | 13741 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
c39055b0 | 13742 | intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C); |
30ad48b7 | 13743 | |
dc0fa718 | 13744 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
c39055b0 | 13745 | intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D); |
30ad48b7 | 13746 | |
5eb08b69 | 13747 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
c39055b0 | 13748 | intel_dp_init(dev_priv, PCH_DP_C, PORT_C); |
5eb08b69 | 13749 | |
270b3042 | 13750 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
c39055b0 | 13751 | intel_dp_init(dev_priv, PCH_DP_D, PORT_D); |
920a14b2 | 13752 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
22f35042 | 13753 | bool has_edp, has_port; |
457c52d8 | 13754 | |
e17ac6db VS |
13755 | /* |
13756 | * The DP_DETECTED bit is the latched state of the DDC | |
13757 | * SDA pin at boot. However since eDP doesn't require DDC | |
13758 | * (no way to plug in a DP->HDMI dongle) the DDC pins for | |
13759 | * eDP ports may have been muxed to an alternate function. | |
13760 | * Thus we can't rely on the DP_DETECTED bit alone to detect | |
13761 | * eDP ports. Consult the VBT as well as DP_DETECTED to | |
13762 | * detect eDP ports. | |
22f35042 VS |
13763 | * |
13764 | * Sadly the straps seem to be missing sometimes even for HDMI | |
13765 | * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap | |
13766 | * and VBT for the presence of the port. Additionally we can't | |
13767 | * trust the port type the VBT declares as we've seen at least | |
13768 | * HDMI ports that the VBT claim are DP or eDP. | |
e17ac6db | 13769 | */ |
7b91bf7f | 13770 | has_edp = intel_dp_is_port_edp(dev_priv, PORT_B); |
22f35042 VS |
13771 | has_port = intel_bios_is_port_present(dev_priv, PORT_B); |
13772 | if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port) | |
c39055b0 | 13773 | has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B); |
22f35042 | 13774 | if ((I915_READ(VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp) |
c39055b0 | 13775 | intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B); |
585a94b8 | 13776 | |
7b91bf7f | 13777 | has_edp = intel_dp_is_port_edp(dev_priv, PORT_C); |
22f35042 VS |
13778 | has_port = intel_bios_is_port_present(dev_priv, PORT_C); |
13779 | if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port) | |
c39055b0 | 13780 | has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C); |
22f35042 | 13781 | if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp) |
c39055b0 | 13782 | intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C); |
19c03924 | 13783 | |
920a14b2 | 13784 | if (IS_CHERRYVIEW(dev_priv)) { |
22f35042 VS |
13785 | /* |
13786 | * eDP not supported on port D, | |
13787 | * so no need to worry about it | |
13788 | */ | |
13789 | has_port = intel_bios_is_port_present(dev_priv, PORT_D); | |
13790 | if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port) | |
c39055b0 | 13791 | intel_dp_init(dev_priv, CHV_DP_D, PORT_D); |
22f35042 | 13792 | if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port) |
c39055b0 | 13793 | intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D); |
9418c1f1 VS |
13794 | } |
13795 | ||
c39055b0 | 13796 | intel_dsi_init(dev_priv); |
5db94019 | 13797 | } else if (!IS_GEN2(dev_priv) && !IS_PINEVIEW(dev_priv)) { |
27185ae1 | 13798 | bool found = false; |
7d57382e | 13799 | |
e2debe91 | 13800 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
b01f2c3a | 13801 | DRM_DEBUG_KMS("probing SDVOB\n"); |
c39055b0 | 13802 | found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B); |
9beb5fea | 13803 | if (!found && IS_G4X(dev_priv)) { |
b01f2c3a | 13804 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
c39055b0 | 13805 | intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B); |
b01f2c3a | 13806 | } |
27185ae1 | 13807 | |
9beb5fea | 13808 | if (!found && IS_G4X(dev_priv)) |
c39055b0 | 13809 | intel_dp_init(dev_priv, DP_B, PORT_B); |
725e30ad | 13810 | } |
13520b05 KH |
13811 | |
13812 | /* Before G4X SDVOC doesn't have its own detect register */ | |
13520b05 | 13813 | |
e2debe91 | 13814 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
b01f2c3a | 13815 | DRM_DEBUG_KMS("probing SDVOC\n"); |
c39055b0 | 13816 | found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C); |
b01f2c3a | 13817 | } |
27185ae1 | 13818 | |
e2debe91 | 13819 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
27185ae1 | 13820 | |
9beb5fea | 13821 | if (IS_G4X(dev_priv)) { |
b01f2c3a | 13822 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
c39055b0 | 13823 | intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C); |
b01f2c3a | 13824 | } |
9beb5fea | 13825 | if (IS_G4X(dev_priv)) |
c39055b0 | 13826 | intel_dp_init(dev_priv, DP_C, PORT_C); |
725e30ad | 13827 | } |
27185ae1 | 13828 | |
9beb5fea | 13829 | if (IS_G4X(dev_priv) && (I915_READ(DP_D) & DP_DETECTED)) |
c39055b0 | 13830 | intel_dp_init(dev_priv, DP_D, PORT_D); |
5db94019 | 13831 | } else if (IS_GEN2(dev_priv)) |
c39055b0 | 13832 | intel_dvo_init(dev_priv); |
79e53945 | 13833 | |
56b857a5 | 13834 | if (SUPPORTS_TV(dev_priv)) |
c39055b0 | 13835 | intel_tv_init(dev_priv); |
79e53945 | 13836 | |
c39055b0 | 13837 | intel_psr_init(dev_priv); |
7c8f8a70 | 13838 | |
c39055b0 | 13839 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
4ef69c7a CW |
13840 | encoder->base.possible_crtcs = encoder->crtc_mask; |
13841 | encoder->base.possible_clones = | |
66a9278e | 13842 | intel_encoder_clones(encoder); |
79e53945 | 13843 | } |
47356eb6 | 13844 | |
c39055b0 | 13845 | intel_init_pch_refclk(dev_priv); |
270b3042 | 13846 | |
c39055b0 | 13847 | drm_helper_move_panel_connectors_to_head(&dev_priv->drm); |
79e53945 JB |
13848 | } |
13849 | ||
13850 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) | |
13851 | { | |
13852 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | |
79e53945 | 13853 | |
ef2d633e | 13854 | drm_framebuffer_cleanup(fb); |
70001cd2 | 13855 | |
dd689287 CW |
13856 | i915_gem_object_lock(intel_fb->obj); |
13857 | WARN_ON(!intel_fb->obj->framebuffer_references--); | |
13858 | i915_gem_object_unlock(intel_fb->obj); | |
13859 | ||
f8c417cd | 13860 | i915_gem_object_put(intel_fb->obj); |
70001cd2 | 13861 | |
79e53945 JB |
13862 | kfree(intel_fb); |
13863 | } | |
13864 | ||
13865 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, | |
05394f39 | 13866 | struct drm_file *file, |
79e53945 JB |
13867 | unsigned int *handle) |
13868 | { | |
13869 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); | |
05394f39 | 13870 | struct drm_i915_gem_object *obj = intel_fb->obj; |
79e53945 | 13871 | |
cc917ab4 CW |
13872 | if (obj->userptr.mm) { |
13873 | DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n"); | |
13874 | return -EINVAL; | |
13875 | } | |
13876 | ||
05394f39 | 13877 | return drm_gem_handle_create(file, &obj->base, handle); |
79e53945 JB |
13878 | } |
13879 | ||
86c98588 RV |
13880 | static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb, |
13881 | struct drm_file *file, | |
13882 | unsigned flags, unsigned color, | |
13883 | struct drm_clip_rect *clips, | |
13884 | unsigned num_clips) | |
13885 | { | |
5a97bcc6 | 13886 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
86c98588 | 13887 | |
5a97bcc6 | 13888 | i915_gem_object_flush_if_display(obj); |
d59b21ec | 13889 | intel_fb_obj_flush(obj, ORIGIN_DIRTYFB); |
86c98588 RV |
13890 | |
13891 | return 0; | |
13892 | } | |
13893 | ||
79e53945 JB |
13894 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
13895 | .destroy = intel_user_framebuffer_destroy, | |
13896 | .create_handle = intel_user_framebuffer_create_handle, | |
86c98588 | 13897 | .dirty = intel_user_framebuffer_dirty, |
79e53945 JB |
13898 | }; |
13899 | ||
b321803d | 13900 | static |
920a14b2 TU |
13901 | u32 intel_fb_pitch_limit(struct drm_i915_private *dev_priv, |
13902 | uint64_t fb_modifier, uint32_t pixel_format) | |
b321803d | 13903 | { |
24dbf51a | 13904 | u32 gen = INTEL_GEN(dev_priv); |
b321803d DL |
13905 | |
13906 | if (gen >= 9) { | |
ac484963 VS |
13907 | int cpp = drm_format_plane_cpp(pixel_format, 0); |
13908 | ||
b321803d DL |
13909 | /* "The stride in bytes must not exceed the of the size of 8K |
13910 | * pixels and 32K bytes." | |
13911 | */ | |
ac484963 | 13912 | return min(8192 * cpp, 32768); |
6401c37d | 13913 | } else if (gen >= 5 && !HAS_GMCH_DISPLAY(dev_priv)) { |
b321803d DL |
13914 | return 32*1024; |
13915 | } else if (gen >= 4) { | |
13916 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) | |
13917 | return 16*1024; | |
13918 | else | |
13919 | return 32*1024; | |
13920 | } else if (gen >= 3) { | |
13921 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) | |
13922 | return 8*1024; | |
13923 | else | |
13924 | return 16*1024; | |
13925 | } else { | |
13926 | /* XXX DSPC is limited to 4k tiled */ | |
13927 | return 8*1024; | |
13928 | } | |
13929 | } | |
13930 | ||
24dbf51a CW |
13931 | static int intel_framebuffer_init(struct intel_framebuffer *intel_fb, |
13932 | struct drm_i915_gem_object *obj, | |
13933 | struct drm_mode_fb_cmd2 *mode_cmd) | |
79e53945 | 13934 | { |
24dbf51a | 13935 | struct drm_i915_private *dev_priv = to_i915(obj->base.dev); |
2e2adb05 | 13936 | struct drm_framebuffer *fb = &intel_fb->base; |
b3c11ac2 | 13937 | struct drm_format_name_buf format_name; |
2e2adb05 | 13938 | u32 pitch_limit; |
dd689287 | 13939 | unsigned int tiling, stride; |
24dbf51a | 13940 | int ret = -EINVAL; |
2e2adb05 | 13941 | int i; |
79e53945 | 13942 | |
dd689287 CW |
13943 | i915_gem_object_lock(obj); |
13944 | obj->framebuffer_references++; | |
13945 | tiling = i915_gem_object_get_tiling(obj); | |
13946 | stride = i915_gem_object_get_stride(obj); | |
13947 | i915_gem_object_unlock(obj); | |
dd4916c5 | 13948 | |
2a80eada | 13949 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
c2ff7370 VS |
13950 | /* |
13951 | * If there's a fence, enforce that | |
13952 | * the fb modifier and tiling mode match. | |
13953 | */ | |
13954 | if (tiling != I915_TILING_NONE && | |
13955 | tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) { | |
144cc143 | 13956 | DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n"); |
24dbf51a | 13957 | goto err; |
2a80eada DV |
13958 | } |
13959 | } else { | |
c2ff7370 | 13960 | if (tiling == I915_TILING_X) { |
2a80eada | 13961 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; |
c2ff7370 | 13962 | } else if (tiling == I915_TILING_Y) { |
144cc143 | 13963 | DRM_DEBUG_KMS("No Y tiling for legacy addfb\n"); |
24dbf51a | 13964 | goto err; |
2a80eada DV |
13965 | } |
13966 | } | |
13967 | ||
9a8f0a12 TU |
13968 | /* Passed in modifier sanity checking. */ |
13969 | switch (mode_cmd->modifier[0]) { | |
2e2adb05 VS |
13970 | case I915_FORMAT_MOD_Y_TILED_CCS: |
13971 | case I915_FORMAT_MOD_Yf_TILED_CCS: | |
13972 | switch (mode_cmd->pixel_format) { | |
13973 | case DRM_FORMAT_XBGR8888: | |
13974 | case DRM_FORMAT_ABGR8888: | |
13975 | case DRM_FORMAT_XRGB8888: | |
13976 | case DRM_FORMAT_ARGB8888: | |
13977 | break; | |
13978 | default: | |
13979 | DRM_DEBUG_KMS("RC supported only with RGB8888 formats\n"); | |
13980 | goto err; | |
13981 | } | |
13982 | /* fall through */ | |
9a8f0a12 TU |
13983 | case I915_FORMAT_MOD_Y_TILED: |
13984 | case I915_FORMAT_MOD_Yf_TILED: | |
6315b5d3 | 13985 | if (INTEL_GEN(dev_priv) < 9) { |
144cc143 VS |
13986 | DRM_DEBUG_KMS("Unsupported tiling 0x%llx!\n", |
13987 | mode_cmd->modifier[0]); | |
24dbf51a | 13988 | goto err; |
9a8f0a12 | 13989 | } |
2f075565 | 13990 | case DRM_FORMAT_MOD_LINEAR: |
9a8f0a12 TU |
13991 | case I915_FORMAT_MOD_X_TILED: |
13992 | break; | |
13993 | default: | |
144cc143 VS |
13994 | DRM_DEBUG_KMS("Unsupported fb modifier 0x%llx!\n", |
13995 | mode_cmd->modifier[0]); | |
24dbf51a | 13996 | goto err; |
c16ed4be | 13997 | } |
57cd6508 | 13998 | |
c2ff7370 VS |
13999 | /* |
14000 | * gen2/3 display engine uses the fence if present, | |
14001 | * so the tiling mode must match the fb modifier exactly. | |
14002 | */ | |
14003 | if (INTEL_INFO(dev_priv)->gen < 4 && | |
14004 | tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) { | |
144cc143 | 14005 | DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n"); |
9aceb5c1 | 14006 | goto err; |
c2ff7370 VS |
14007 | } |
14008 | ||
920a14b2 | 14009 | pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->modifier[0], |
b321803d | 14010 | mode_cmd->pixel_format); |
a35cdaa0 | 14011 | if (mode_cmd->pitches[0] > pitch_limit) { |
144cc143 | 14012 | DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n", |
2f075565 | 14013 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ? |
144cc143 VS |
14014 | "tiled" : "linear", |
14015 | mode_cmd->pitches[0], pitch_limit); | |
24dbf51a | 14016 | goto err; |
c16ed4be | 14017 | } |
5d7bd705 | 14018 | |
c2ff7370 VS |
14019 | /* |
14020 | * If there's a fence, enforce that | |
14021 | * the fb pitch and fence stride match. | |
14022 | */ | |
144cc143 VS |
14023 | if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) { |
14024 | DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n", | |
14025 | mode_cmd->pitches[0], stride); | |
24dbf51a | 14026 | goto err; |
c16ed4be | 14027 | } |
5d7bd705 | 14028 | |
57779d06 | 14029 | /* Reject formats not supported by any plane early. */ |
308e5bcb | 14030 | switch (mode_cmd->pixel_format) { |
57779d06 | 14031 | case DRM_FORMAT_C8: |
04b3924d VS |
14032 | case DRM_FORMAT_RGB565: |
14033 | case DRM_FORMAT_XRGB8888: | |
14034 | case DRM_FORMAT_ARGB8888: | |
57779d06 VS |
14035 | break; |
14036 | case DRM_FORMAT_XRGB1555: | |
6315b5d3 | 14037 | if (INTEL_GEN(dev_priv) > 3) { |
144cc143 VS |
14038 | DRM_DEBUG_KMS("unsupported pixel format: %s\n", |
14039 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); | |
9aceb5c1 | 14040 | goto err; |
c16ed4be | 14041 | } |
57779d06 | 14042 | break; |
57779d06 | 14043 | case DRM_FORMAT_ABGR8888: |
920a14b2 | 14044 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) && |
6315b5d3 | 14045 | INTEL_GEN(dev_priv) < 9) { |
144cc143 VS |
14046 | DRM_DEBUG_KMS("unsupported pixel format: %s\n", |
14047 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); | |
9aceb5c1 | 14048 | goto err; |
6c0fd451 DL |
14049 | } |
14050 | break; | |
14051 | case DRM_FORMAT_XBGR8888: | |
04b3924d | 14052 | case DRM_FORMAT_XRGB2101010: |
57779d06 | 14053 | case DRM_FORMAT_XBGR2101010: |
6315b5d3 | 14054 | if (INTEL_GEN(dev_priv) < 4) { |
144cc143 VS |
14055 | DRM_DEBUG_KMS("unsupported pixel format: %s\n", |
14056 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); | |
9aceb5c1 | 14057 | goto err; |
c16ed4be | 14058 | } |
b5626747 | 14059 | break; |
7531208b | 14060 | case DRM_FORMAT_ABGR2101010: |
920a14b2 | 14061 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) { |
144cc143 VS |
14062 | DRM_DEBUG_KMS("unsupported pixel format: %s\n", |
14063 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); | |
9aceb5c1 | 14064 | goto err; |
7531208b DL |
14065 | } |
14066 | break; | |
04b3924d VS |
14067 | case DRM_FORMAT_YUYV: |
14068 | case DRM_FORMAT_UYVY: | |
14069 | case DRM_FORMAT_YVYU: | |
14070 | case DRM_FORMAT_VYUY: | |
ab33081a | 14071 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) { |
144cc143 VS |
14072 | DRM_DEBUG_KMS("unsupported pixel format: %s\n", |
14073 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); | |
9aceb5c1 | 14074 | goto err; |
c16ed4be | 14075 | } |
57cd6508 CW |
14076 | break; |
14077 | default: | |
144cc143 VS |
14078 | DRM_DEBUG_KMS("unsupported pixel format: %s\n", |
14079 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); | |
9aceb5c1 | 14080 | goto err; |
57cd6508 CW |
14081 | } |
14082 | ||
90f9a336 VS |
14083 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
14084 | if (mode_cmd->offsets[0] != 0) | |
24dbf51a | 14085 | goto err; |
90f9a336 | 14086 | |
2e2adb05 | 14087 | drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd); |
d88c4afd | 14088 | |
2e2adb05 VS |
14089 | for (i = 0; i < fb->format->num_planes; i++) { |
14090 | u32 stride_alignment; | |
14091 | ||
14092 | if (mode_cmd->handles[i] != mode_cmd->handles[0]) { | |
14093 | DRM_DEBUG_KMS("bad plane %d handle\n", i); | |
814feed3 | 14094 | goto err; |
2e2adb05 VS |
14095 | } |
14096 | ||
14097 | stride_alignment = intel_fb_stride_alignment(fb, i); | |
14098 | ||
14099 | /* | |
14100 | * Display WA #0531: skl,bxt,kbl,glk | |
14101 | * | |
14102 | * Render decompression and plane width > 3840 | |
14103 | * combined with horizontal panning requires the | |
14104 | * plane stride to be a multiple of 4. We'll just | |
14105 | * require the entire fb to accommodate that to avoid | |
14106 | * potential runtime errors at plane configuration time. | |
14107 | */ | |
14108 | if (IS_GEN9(dev_priv) && i == 0 && fb->width > 3840 && | |
14109 | (fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS || | |
14110 | fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS)) | |
14111 | stride_alignment *= 4; | |
14112 | ||
14113 | if (fb->pitches[i] & (stride_alignment - 1)) { | |
14114 | DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n", | |
14115 | i, fb->pitches[i], stride_alignment); | |
14116 | goto err; | |
14117 | } | |
d88c4afd VS |
14118 | } |
14119 | ||
c7d73f6a DV |
14120 | intel_fb->obj = obj; |
14121 | ||
2e2adb05 | 14122 | ret = intel_fill_fb_info(dev_priv, fb); |
6687c906 | 14123 | if (ret) |
9aceb5c1 | 14124 | goto err; |
2d7a215f | 14125 | |
2e2adb05 | 14126 | ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs); |
79e53945 JB |
14127 | if (ret) { |
14128 | DRM_ERROR("framebuffer init failed %d\n", ret); | |
24dbf51a | 14129 | goto err; |
79e53945 JB |
14130 | } |
14131 | ||
79e53945 | 14132 | return 0; |
24dbf51a CW |
14133 | |
14134 | err: | |
dd689287 CW |
14135 | i915_gem_object_lock(obj); |
14136 | obj->framebuffer_references--; | |
14137 | i915_gem_object_unlock(obj); | |
24dbf51a | 14138 | return ret; |
79e53945 JB |
14139 | } |
14140 | ||
79e53945 JB |
14141 | static struct drm_framebuffer * |
14142 | intel_user_framebuffer_create(struct drm_device *dev, | |
14143 | struct drm_file *filp, | |
1eb83451 | 14144 | const struct drm_mode_fb_cmd2 *user_mode_cmd) |
79e53945 | 14145 | { |
dcb1394e | 14146 | struct drm_framebuffer *fb; |
05394f39 | 14147 | struct drm_i915_gem_object *obj; |
76dc3769 | 14148 | struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd; |
79e53945 | 14149 | |
03ac0642 CW |
14150 | obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]); |
14151 | if (!obj) | |
cce13ff7 | 14152 | return ERR_PTR(-ENOENT); |
79e53945 | 14153 | |
24dbf51a | 14154 | fb = intel_framebuffer_create(obj, &mode_cmd); |
dcb1394e | 14155 | if (IS_ERR(fb)) |
f0cd5182 | 14156 | i915_gem_object_put(obj); |
dcb1394e LW |
14157 | |
14158 | return fb; | |
79e53945 JB |
14159 | } |
14160 | ||
778e23a9 CW |
14161 | static void intel_atomic_state_free(struct drm_atomic_state *state) |
14162 | { | |
14163 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); | |
14164 | ||
14165 | drm_atomic_state_default_release(state); | |
14166 | ||
14167 | i915_sw_fence_fini(&intel_state->commit_ready); | |
14168 | ||
14169 | kfree(state); | |
14170 | } | |
14171 | ||
79e53945 | 14172 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
79e53945 | 14173 | .fb_create = intel_user_framebuffer_create, |
bbfb6ce8 | 14174 | .get_format_info = intel_get_format_info, |
0632fef6 | 14175 | .output_poll_changed = intel_fbdev_output_poll_changed, |
5ee67f1c MR |
14176 | .atomic_check = intel_atomic_check, |
14177 | .atomic_commit = intel_atomic_commit, | |
de419ab6 ML |
14178 | .atomic_state_alloc = intel_atomic_state_alloc, |
14179 | .atomic_state_clear = intel_atomic_state_clear, | |
778e23a9 | 14180 | .atomic_state_free = intel_atomic_state_free, |
79e53945 JB |
14181 | }; |
14182 | ||
88212941 ID |
14183 | /** |
14184 | * intel_init_display_hooks - initialize the display modesetting hooks | |
14185 | * @dev_priv: device private | |
14186 | */ | |
14187 | void intel_init_display_hooks(struct drm_i915_private *dev_priv) | |
e70236a8 | 14188 | { |
7ff89ca2 VS |
14189 | intel_init_cdclk_hooks(dev_priv); |
14190 | ||
88212941 | 14191 | if (INTEL_INFO(dev_priv)->gen >= 9) { |
bc8d7dff | 14192 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
5724dbd1 DL |
14193 | dev_priv->display.get_initial_plane_config = |
14194 | skylake_get_initial_plane_config; | |
bc8d7dff DL |
14195 | dev_priv->display.crtc_compute_clock = |
14196 | haswell_crtc_compute_clock; | |
14197 | dev_priv->display.crtc_enable = haswell_crtc_enable; | |
14198 | dev_priv->display.crtc_disable = haswell_crtc_disable; | |
88212941 | 14199 | } else if (HAS_DDI(dev_priv)) { |
0e8ffe1b | 14200 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
5724dbd1 DL |
14201 | dev_priv->display.get_initial_plane_config = |
14202 | ironlake_get_initial_plane_config; | |
797d0259 ACO |
14203 | dev_priv->display.crtc_compute_clock = |
14204 | haswell_crtc_compute_clock; | |
4f771f10 PZ |
14205 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
14206 | dev_priv->display.crtc_disable = haswell_crtc_disable; | |
88212941 | 14207 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
0e8ffe1b | 14208 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
5724dbd1 DL |
14209 | dev_priv->display.get_initial_plane_config = |
14210 | ironlake_get_initial_plane_config; | |
3fb37703 ACO |
14211 | dev_priv->display.crtc_compute_clock = |
14212 | ironlake_crtc_compute_clock; | |
76e5a89c DV |
14213 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
14214 | dev_priv->display.crtc_disable = ironlake_crtc_disable; | |
65b3d6a9 | 14215 | } else if (IS_CHERRYVIEW(dev_priv)) { |
89b667f8 | 14216 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
5724dbd1 DL |
14217 | dev_priv->display.get_initial_plane_config = |
14218 | i9xx_get_initial_plane_config; | |
65b3d6a9 ACO |
14219 | dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock; |
14220 | dev_priv->display.crtc_enable = valleyview_crtc_enable; | |
14221 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
14222 | } else if (IS_VALLEYVIEW(dev_priv)) { | |
14223 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; | |
14224 | dev_priv->display.get_initial_plane_config = | |
14225 | i9xx_get_initial_plane_config; | |
14226 | dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock; | |
89b667f8 JB |
14227 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
14228 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
19ec6693 ACO |
14229 | } else if (IS_G4X(dev_priv)) { |
14230 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; | |
14231 | dev_priv->display.get_initial_plane_config = | |
14232 | i9xx_get_initial_plane_config; | |
14233 | dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock; | |
14234 | dev_priv->display.crtc_enable = i9xx_crtc_enable; | |
14235 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
70e8aa21 ACO |
14236 | } else if (IS_PINEVIEW(dev_priv)) { |
14237 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; | |
14238 | dev_priv->display.get_initial_plane_config = | |
14239 | i9xx_get_initial_plane_config; | |
14240 | dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock; | |
14241 | dev_priv->display.crtc_enable = i9xx_crtc_enable; | |
14242 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
81c97f52 | 14243 | } else if (!IS_GEN2(dev_priv)) { |
0e8ffe1b | 14244 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
5724dbd1 DL |
14245 | dev_priv->display.get_initial_plane_config = |
14246 | i9xx_get_initial_plane_config; | |
d6dfee7a | 14247 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
76e5a89c DV |
14248 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
14249 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
81c97f52 ACO |
14250 | } else { |
14251 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; | |
14252 | dev_priv->display.get_initial_plane_config = | |
14253 | i9xx_get_initial_plane_config; | |
14254 | dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock; | |
14255 | dev_priv->display.crtc_enable = i9xx_crtc_enable; | |
14256 | dev_priv->display.crtc_disable = i9xx_crtc_disable; | |
f564048e | 14257 | } |
e70236a8 | 14258 | |
88212941 | 14259 | if (IS_GEN5(dev_priv)) { |
3bb11b53 | 14260 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
88212941 | 14261 | } else if (IS_GEN6(dev_priv)) { |
3bb11b53 | 14262 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; |
88212941 | 14263 | } else if (IS_IVYBRIDGE(dev_priv)) { |
3bb11b53 SJ |
14264 | /* FIXME: detect B0+ stepping and use auto training */ |
14265 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; | |
88212941 | 14266 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
3bb11b53 | 14267 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
445e780b VS |
14268 | } |
14269 | ||
bd30ca2d | 14270 | if (INTEL_GEN(dev_priv) >= 9) |
27082493 L |
14271 | dev_priv->display.update_crtcs = skl_update_crtcs; |
14272 | else | |
14273 | dev_priv->display.update_crtcs = intel_update_crtcs; | |
e70236a8 JB |
14274 | } |
14275 | ||
435793df KP |
14276 | /* |
14277 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason | |
14278 | */ | |
14279 | static void quirk_ssc_force_disable(struct drm_device *dev) | |
14280 | { | |
fac5e23e | 14281 | struct drm_i915_private *dev_priv = to_i915(dev); |
435793df | 14282 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; |
bc0daf48 | 14283 | DRM_INFO("applying lvds SSC disable quirk\n"); |
435793df KP |
14284 | } |
14285 | ||
4dca20ef | 14286 | /* |
5a15ab5b CE |
14287 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight |
14288 | * brightness value | |
4dca20ef CE |
14289 | */ |
14290 | static void quirk_invert_brightness(struct drm_device *dev) | |
14291 | { | |
fac5e23e | 14292 | struct drm_i915_private *dev_priv = to_i915(dev); |
4dca20ef | 14293 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; |
bc0daf48 | 14294 | DRM_INFO("applying inverted panel brightness quirk\n"); |
435793df KP |
14295 | } |
14296 | ||
9c72cc6f SD |
14297 | /* Some VBT's incorrectly indicate no backlight is present */ |
14298 | static void quirk_backlight_present(struct drm_device *dev) | |
14299 | { | |
fac5e23e | 14300 | struct drm_i915_private *dev_priv = to_i915(dev); |
9c72cc6f SD |
14301 | dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT; |
14302 | DRM_INFO("applying backlight present quirk\n"); | |
14303 | } | |
14304 | ||
c99a259b MN |
14305 | /* Toshiba Satellite P50-C-18C requires T12 delay to be min 800ms |
14306 | * which is 300 ms greater than eDP spec T12 min. | |
14307 | */ | |
14308 | static void quirk_increase_t12_delay(struct drm_device *dev) | |
14309 | { | |
14310 | struct drm_i915_private *dev_priv = to_i915(dev); | |
14311 | ||
14312 | dev_priv->quirks |= QUIRK_INCREASE_T12_DELAY; | |
14313 | DRM_INFO("Applying T12 delay quirk\n"); | |
14314 | } | |
14315 | ||
af25065b CT |
14316 | /* |
14317 | * GeminiLake NUC HDMI outputs require additional off time | |
14318 | * this allows the onboard retimer to correctly sync to signal | |
14319 | */ | |
14320 | static void quirk_increase_ddi_disabled_time(struct drm_device *dev) | |
14321 | { | |
14322 | struct drm_i915_private *dev_priv = to_i915(dev); | |
14323 | ||
14324 | dev_priv->quirks |= QUIRK_INCREASE_DDI_DISABLED_TIME; | |
14325 | DRM_INFO("Applying Increase DDI Disabled quirk\n"); | |
14326 | } | |
14327 | ||
b690e96c JB |
14328 | struct intel_quirk { |
14329 | int device; | |
14330 | int subsystem_vendor; | |
14331 | int subsystem_device; | |
14332 | void (*hook)(struct drm_device *dev); | |
14333 | }; | |
14334 | ||
5f85f176 EE |
14335 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ |
14336 | struct intel_dmi_quirk { | |
14337 | void (*hook)(struct drm_device *dev); | |
14338 | const struct dmi_system_id (*dmi_id_list)[]; | |
14339 | }; | |
14340 | ||
14341 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) | |
14342 | { | |
14343 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); | |
14344 | return 1; | |
14345 | } | |
14346 | ||
14347 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { | |
14348 | { | |
14349 | .dmi_id_list = &(const struct dmi_system_id[]) { | |
14350 | { | |
14351 | .callback = intel_dmi_reverse_brightness, | |
14352 | .ident = "NCR Corporation", | |
14353 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), | |
14354 | DMI_MATCH(DMI_PRODUCT_NAME, ""), | |
14355 | }, | |
14356 | }, | |
14357 | { } /* terminating entry */ | |
14358 | }, | |
14359 | .hook = quirk_invert_brightness, | |
14360 | }, | |
14361 | }; | |
14362 | ||
c43b5634 | 14363 | static struct intel_quirk intel_quirks[] = { |
435793df KP |
14364 | /* Lenovo U160 cannot use SSC on LVDS */ |
14365 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, | |
070d329a MAS |
14366 | |
14367 | /* Sony Vaio Y cannot use SSC on LVDS */ | |
14368 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, | |
5a15ab5b | 14369 | |
be505f64 AH |
14370 | /* Acer Aspire 5734Z must invert backlight brightness */ |
14371 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, | |
14372 | ||
14373 | /* Acer/eMachines G725 */ | |
14374 | { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness }, | |
14375 | ||
14376 | /* Acer/eMachines e725 */ | |
14377 | { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness }, | |
14378 | ||
14379 | /* Acer/Packard Bell NCL20 */ | |
14380 | { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness }, | |
14381 | ||
14382 | /* Acer Aspire 4736Z */ | |
14383 | { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness }, | |
0f540c3a JN |
14384 | |
14385 | /* Acer Aspire 5336 */ | |
14386 | { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness }, | |
2e93a1aa SD |
14387 | |
14388 | /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */ | |
14389 | { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present }, | |
d4967d8c | 14390 | |
dfb3d47b SD |
14391 | /* Acer C720 Chromebook (Core i3 4005U) */ |
14392 | { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present }, | |
14393 | ||
b2a9601c | 14394 | /* Apple Macbook 2,1 (Core 2 T7400) */ |
14395 | { 0x27a2, 0x8086, 0x7270, quirk_backlight_present }, | |
14396 | ||
1b9448b0 JN |
14397 | /* Apple Macbook 4,1 */ |
14398 | { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present }, | |
14399 | ||
d4967d8c SD |
14400 | /* Toshiba CB35 Chromebook (Celeron 2955U) */ |
14401 | { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present }, | |
724cb06f SD |
14402 | |
14403 | /* HP Chromebook 14 (Celeron 2955U) */ | |
14404 | { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present }, | |
cf6f0af9 JN |
14405 | |
14406 | /* Dell Chromebook 11 */ | |
14407 | { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present }, | |
9be64eee JN |
14408 | |
14409 | /* Dell Chromebook 11 (2015 version) */ | |
14410 | { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present }, | |
c99a259b MN |
14411 | |
14412 | /* Toshiba Satellite P50-C-18C */ | |
14413 | { 0x191B, 0x1179, 0xF840, quirk_increase_t12_delay }, | |
af25065b CT |
14414 | |
14415 | /* GeminiLake NUC */ | |
14416 | { 0x3185, 0x8086, 0x2072, quirk_increase_ddi_disabled_time }, | |
14417 | { 0x3184, 0x8086, 0x2072, quirk_increase_ddi_disabled_time }, | |
14418 | /* ASRock ITX*/ | |
14419 | { 0x3185, 0x1849, 0x2212, quirk_increase_ddi_disabled_time }, | |
14420 | { 0x3184, 0x1849, 0x2212, quirk_increase_ddi_disabled_time }, | |
b690e96c JB |
14421 | }; |
14422 | ||
14423 | static void intel_init_quirks(struct drm_device *dev) | |
14424 | { | |
14425 | struct pci_dev *d = dev->pdev; | |
14426 | int i; | |
14427 | ||
14428 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { | |
14429 | struct intel_quirk *q = &intel_quirks[i]; | |
14430 | ||
14431 | if (d->device == q->device && | |
14432 | (d->subsystem_vendor == q->subsystem_vendor || | |
14433 | q->subsystem_vendor == PCI_ANY_ID) && | |
14434 | (d->subsystem_device == q->subsystem_device || | |
14435 | q->subsystem_device == PCI_ANY_ID)) | |
14436 | q->hook(dev); | |
14437 | } | |
5f85f176 EE |
14438 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { |
14439 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) | |
14440 | intel_dmi_quirks[i].hook(dev); | |
14441 | } | |
b690e96c JB |
14442 | } |
14443 | ||
9cce37f4 | 14444 | /* Disable the VGA plane that we never use */ |
29b74b7f | 14445 | static void i915_disable_vga(struct drm_i915_private *dev_priv) |
9cce37f4 | 14446 | { |
52a05c30 | 14447 | struct pci_dev *pdev = dev_priv->drm.pdev; |
9cce37f4 | 14448 | u8 sr1; |
920a14b2 | 14449 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv); |
9cce37f4 | 14450 | |
2b37c616 | 14451 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
52a05c30 | 14452 | vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO); |
3fdcf431 | 14453 | outb(SR01, VGA_SR_INDEX); |
9cce37f4 JB |
14454 | sr1 = inb(VGA_SR_DATA); |
14455 | outb(sr1 | 1<<5, VGA_SR_DATA); | |
52a05c30 | 14456 | vga_put(pdev, VGA_RSRC_LEGACY_IO); |
9cce37f4 JB |
14457 | udelay(300); |
14458 | ||
01f5a626 | 14459 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
9cce37f4 JB |
14460 | POSTING_READ(vga_reg); |
14461 | } | |
14462 | ||
f817586c DV |
14463 | void intel_modeset_init_hw(struct drm_device *dev) |
14464 | { | |
fac5e23e | 14465 | struct drm_i915_private *dev_priv = to_i915(dev); |
1a617b77 | 14466 | |
4c75b940 | 14467 | intel_update_cdclk(dev_priv); |
bb0f4aab | 14468 | dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw; |
f817586c DV |
14469 | } |
14470 | ||
d93c0372 MR |
14471 | /* |
14472 | * Calculate what we think the watermarks should be for the state we've read | |
14473 | * out of the hardware and then immediately program those watermarks so that | |
14474 | * we ensure the hardware settings match our internal state. | |
14475 | * | |
14476 | * We can calculate what we think WM's should be by creating a duplicate of the | |
14477 | * current state (which was constructed during hardware readout) and running it | |
14478 | * through the atomic check code to calculate new watermark values in the | |
14479 | * state object. | |
14480 | */ | |
14481 | static void sanitize_watermarks(struct drm_device *dev) | |
14482 | { | |
14483 | struct drm_i915_private *dev_priv = to_i915(dev); | |
14484 | struct drm_atomic_state *state; | |
ccf010fb | 14485 | struct intel_atomic_state *intel_state; |
d93c0372 MR |
14486 | struct drm_crtc *crtc; |
14487 | struct drm_crtc_state *cstate; | |
14488 | struct drm_modeset_acquire_ctx ctx; | |
14489 | int ret; | |
14490 | int i; | |
14491 | ||
14492 | /* Only supported on platforms that use atomic watermark design */ | |
ed4a6a7c | 14493 | if (!dev_priv->display.optimize_watermarks) |
d93c0372 MR |
14494 | return; |
14495 | ||
14496 | /* | |
14497 | * We need to hold connection_mutex before calling duplicate_state so | |
14498 | * that the connector loop is protected. | |
14499 | */ | |
14500 | drm_modeset_acquire_init(&ctx, 0); | |
14501 | retry: | |
0cd1262d | 14502 | ret = drm_modeset_lock_all_ctx(dev, &ctx); |
d93c0372 MR |
14503 | if (ret == -EDEADLK) { |
14504 | drm_modeset_backoff(&ctx); | |
14505 | goto retry; | |
14506 | } else if (WARN_ON(ret)) { | |
0cd1262d | 14507 | goto fail; |
d93c0372 MR |
14508 | } |
14509 | ||
14510 | state = drm_atomic_helper_duplicate_state(dev, &ctx); | |
14511 | if (WARN_ON(IS_ERR(state))) | |
0cd1262d | 14512 | goto fail; |
d93c0372 | 14513 | |
ccf010fb ML |
14514 | intel_state = to_intel_atomic_state(state); |
14515 | ||
ed4a6a7c MR |
14516 | /* |
14517 | * Hardware readout is the only time we don't want to calculate | |
14518 | * intermediate watermarks (since we don't trust the current | |
14519 | * watermarks). | |
14520 | */ | |
602ae835 VS |
14521 | if (!HAS_GMCH_DISPLAY(dev_priv)) |
14522 | intel_state->skip_intermediate_wm = true; | |
ed4a6a7c | 14523 | |
d93c0372 MR |
14524 | ret = intel_atomic_check(dev, state); |
14525 | if (ret) { | |
14526 | /* | |
14527 | * If we fail here, it means that the hardware appears to be | |
14528 | * programmed in a way that shouldn't be possible, given our | |
14529 | * understanding of watermark requirements. This might mean a | |
14530 | * mistake in the hardware readout code or a mistake in the | |
14531 | * watermark calculations for a given platform. Raise a WARN | |
14532 | * so that this is noticeable. | |
14533 | * | |
14534 | * If this actually happens, we'll have to just leave the | |
14535 | * BIOS-programmed watermarks untouched and hope for the best. | |
14536 | */ | |
14537 | WARN(true, "Could not determine valid watermarks for inherited state\n"); | |
b9a1b717 | 14538 | goto put_state; |
d93c0372 MR |
14539 | } |
14540 | ||
14541 | /* Write calculated watermark values back */ | |
aa5e9b47 | 14542 | for_each_new_crtc_in_state(state, crtc, cstate, i) { |
d93c0372 MR |
14543 | struct intel_crtc_state *cs = to_intel_crtc_state(cstate); |
14544 | ||
ed4a6a7c | 14545 | cs->wm.need_postvbl_update = true; |
ccf010fb | 14546 | dev_priv->display.optimize_watermarks(intel_state, cs); |
5d25aa47 ML |
14547 | |
14548 | to_intel_crtc_state(crtc->state)->wm = cs->wm; | |
d93c0372 MR |
14549 | } |
14550 | ||
b9a1b717 | 14551 | put_state: |
0853695c | 14552 | drm_atomic_state_put(state); |
0cd1262d | 14553 | fail: |
d93c0372 MR |
14554 | drm_modeset_drop_locks(&ctx); |
14555 | drm_modeset_acquire_fini(&ctx); | |
14556 | } | |
14557 | ||
b079bd17 | 14558 | int intel_modeset_init(struct drm_device *dev) |
79e53945 | 14559 | { |
72e96d64 JL |
14560 | struct drm_i915_private *dev_priv = to_i915(dev); |
14561 | struct i915_ggtt *ggtt = &dev_priv->ggtt; | |
8cc87b75 | 14562 | enum pipe pipe; |
46f297fb | 14563 | struct intel_crtc *crtc; |
79e53945 | 14564 | |
eda41bdc VS |
14565 | dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0); |
14566 | ||
79e53945 JB |
14567 | drm_mode_config_init(dev); |
14568 | ||
14569 | dev->mode_config.min_width = 0; | |
14570 | dev->mode_config.min_height = 0; | |
14571 | ||
019d96cb DA |
14572 | dev->mode_config.preferred_depth = 24; |
14573 | dev->mode_config.prefer_shadow = 1; | |
14574 | ||
25bab385 TU |
14575 | dev->mode_config.allow_fb_modifiers = true; |
14576 | ||
e6ecefaa | 14577 | dev->mode_config.funcs = &intel_mode_funcs; |
79e53945 | 14578 | |
400c19d9 | 14579 | init_llist_head(&dev_priv->atomic_helper.free_list); |
eb955eee | 14580 | INIT_WORK(&dev_priv->atomic_helper.free_work, |
ba318c61 | 14581 | intel_atomic_helper_free_state_worker); |
eb955eee | 14582 | |
b690e96c JB |
14583 | intel_init_quirks(dev); |
14584 | ||
62d75df7 | 14585 | intel_init_pm(dev_priv); |
1fa61106 | 14586 | |
b7f05d4a | 14587 | if (INTEL_INFO(dev_priv)->num_pipes == 0) |
b079bd17 | 14588 | return 0; |
e3c74757 | 14589 | |
69f92f67 LW |
14590 | /* |
14591 | * There may be no VBT; and if the BIOS enabled SSC we can | |
14592 | * just keep using it to avoid unnecessary flicker. Whereas if the | |
14593 | * BIOS isn't using it, don't assume it will work even if the VBT | |
14594 | * indicates as much. | |
14595 | */ | |
6e266956 | 14596 | if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) { |
69f92f67 LW |
14597 | bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & |
14598 | DREF_SSC1_ENABLE); | |
14599 | ||
14600 | if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) { | |
14601 | DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n", | |
14602 | bios_lvds_use_ssc ? "en" : "dis", | |
14603 | dev_priv->vbt.lvds_use_ssc ? "en" : "dis"); | |
14604 | dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc; | |
14605 | } | |
14606 | } | |
14607 | ||
5db94019 | 14608 | if (IS_GEN2(dev_priv)) { |
a6c45cf0 CW |
14609 | dev->mode_config.max_width = 2048; |
14610 | dev->mode_config.max_height = 2048; | |
5db94019 | 14611 | } else if (IS_GEN3(dev_priv)) { |
5e4d6fa7 KP |
14612 | dev->mode_config.max_width = 4096; |
14613 | dev->mode_config.max_height = 4096; | |
79e53945 | 14614 | } else { |
a6c45cf0 CW |
14615 | dev->mode_config.max_width = 8192; |
14616 | dev->mode_config.max_height = 8192; | |
79e53945 | 14617 | } |
068be561 | 14618 | |
2a307c2e JN |
14619 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) { |
14620 | dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512; | |
dc41c154 | 14621 | dev->mode_config.cursor_height = 1023; |
5db94019 | 14622 | } else if (IS_GEN2(dev_priv)) { |
068be561 DL |
14623 | dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH; |
14624 | dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT; | |
14625 | } else { | |
14626 | dev->mode_config.cursor_width = MAX_CURSOR_WIDTH; | |
14627 | dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT; | |
14628 | } | |
14629 | ||
b06f4c80 | 14630 | dev->mode_config.fb_base = ggtt->gmadr.start; |
79e53945 | 14631 | |
28c97730 | 14632 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
b7f05d4a TU |
14633 | INTEL_INFO(dev_priv)->num_pipes, |
14634 | INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : ""); | |
79e53945 | 14635 | |
055e393f | 14636 | for_each_pipe(dev_priv, pipe) { |
b079bd17 VS |
14637 | int ret; |
14638 | ||
5ab0d85b | 14639 | ret = intel_crtc_init(dev_priv, pipe); |
b079bd17 VS |
14640 | if (ret) { |
14641 | drm_mode_config_cleanup(dev); | |
14642 | return ret; | |
14643 | } | |
79e53945 JB |
14644 | } |
14645 | ||
e72f9fbf | 14646 | intel_shared_dpll_init(dev); |
ee7b9f93 | 14647 | |
5be6e334 VS |
14648 | intel_update_czclk(dev_priv); |
14649 | intel_modeset_init_hw(dev); | |
14650 | ||
b2045352 | 14651 | if (dev_priv->max_cdclk_freq == 0) |
4c75b940 | 14652 | intel_update_max_cdclk(dev_priv); |
b2045352 | 14653 | |
9cce37f4 | 14654 | /* Just disable it once at startup */ |
29b74b7f | 14655 | i915_disable_vga(dev_priv); |
c39055b0 | 14656 | intel_setup_outputs(dev_priv); |
11be49eb | 14657 | |
6e9f798d | 14658 | drm_modeset_lock_all(dev); |
aecd36b8 | 14659 | intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx); |
6e9f798d | 14660 | drm_modeset_unlock_all(dev); |
46f297fb | 14661 | |
d3fcc808 | 14662 | for_each_intel_crtc(dev, crtc) { |
eeebeac5 ML |
14663 | struct intel_initial_plane_config plane_config = {}; |
14664 | ||
46f297fb JB |
14665 | if (!crtc->active) |
14666 | continue; | |
14667 | ||
46f297fb | 14668 | /* |
46f297fb JB |
14669 | * Note that reserving the BIOS fb up front prevents us |
14670 | * from stuffing other stolen allocations like the ring | |
14671 | * on top. This prevents some ugliness at boot time, and | |
14672 | * can even allow for smooth boot transitions if the BIOS | |
14673 | * fb is large enough for the active pipe configuration. | |
14674 | */ | |
eeebeac5 ML |
14675 | dev_priv->display.get_initial_plane_config(crtc, |
14676 | &plane_config); | |
14677 | ||
14678 | /* | |
14679 | * If the fb is shared between multiple heads, we'll | |
14680 | * just get the first one. | |
14681 | */ | |
14682 | intel_find_initial_plane_obj(crtc, &plane_config); | |
46f297fb | 14683 | } |
d93c0372 MR |
14684 | |
14685 | /* | |
14686 | * Make sure hardware watermarks really match the state we read out. | |
14687 | * Note that we need to do this after reconstructing the BIOS fb's | |
14688 | * since the watermark calculation done here will use pstate->fb. | |
14689 | */ | |
602ae835 VS |
14690 | if (!HAS_GMCH_DISPLAY(dev_priv)) |
14691 | sanitize_watermarks(dev); | |
b079bd17 VS |
14692 | |
14693 | return 0; | |
2c7111db CW |
14694 | } |
14695 | ||
2ee0da16 VS |
14696 | void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe) |
14697 | { | |
14698 | /* 640x480@60Hz, ~25175 kHz */ | |
14699 | struct dpll clock = { | |
14700 | .m1 = 18, | |
14701 | .m2 = 7, | |
14702 | .p1 = 13, | |
14703 | .p2 = 4, | |
14704 | .n = 2, | |
14705 | }; | |
14706 | u32 dpll, fp; | |
14707 | int i; | |
14708 | ||
14709 | WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154); | |
14710 | ||
14711 | DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n", | |
14712 | pipe_name(pipe), clock.vco, clock.dot); | |
14713 | ||
14714 | fp = i9xx_dpll_compute_fp(&clock); | |
14715 | dpll = (I915_READ(DPLL(pipe)) & DPLL_DVO_2X_MODE) | | |
14716 | DPLL_VGA_MODE_DIS | | |
14717 | ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) | | |
14718 | PLL_P2_DIVIDE_BY_4 | | |
14719 | PLL_REF_INPUT_DREFCLK | | |
14720 | DPLL_VCO_ENABLE; | |
14721 | ||
14722 | I915_WRITE(FP0(pipe), fp); | |
14723 | I915_WRITE(FP1(pipe), fp); | |
14724 | ||
14725 | I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16)); | |
14726 | I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16)); | |
14727 | I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16)); | |
14728 | I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16)); | |
14729 | I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16)); | |
14730 | I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16)); | |
14731 | I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1)); | |
14732 | ||
14733 | /* | |
14734 | * Apparently we need to have VGA mode enabled prior to changing | |
14735 | * the P1/P2 dividers. Otherwise the DPLL will keep using the old | |
14736 | * dividers, even though the register value does change. | |
14737 | */ | |
14738 | I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS); | |
14739 | I915_WRITE(DPLL(pipe), dpll); | |
14740 | ||
14741 | /* Wait for the clocks to stabilize. */ | |
14742 | POSTING_READ(DPLL(pipe)); | |
14743 | udelay(150); | |
14744 | ||
14745 | /* The pixel multiplier can only be updated once the | |
14746 | * DPLL is enabled and the clocks are stable. | |
14747 | * | |
14748 | * So write it again. | |
14749 | */ | |
14750 | I915_WRITE(DPLL(pipe), dpll); | |
14751 | ||
14752 | /* We do this three times for luck */ | |
14753 | for (i = 0; i < 3 ; i++) { | |
14754 | I915_WRITE(DPLL(pipe), dpll); | |
14755 | POSTING_READ(DPLL(pipe)); | |
14756 | udelay(150); /* wait for warmup */ | |
14757 | } | |
14758 | ||
14759 | I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE); | |
14760 | POSTING_READ(PIPECONF(pipe)); | |
14761 | } | |
14762 | ||
14763 | void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe) | |
14764 | { | |
a87e55f8 VS |
14765 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
14766 | ||
2ee0da16 VS |
14767 | DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n", |
14768 | pipe_name(pipe)); | |
14769 | ||
4488496d VS |
14770 | WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE); |
14771 | WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE); | |
14772 | WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE); | |
14773 | WARN_ON(I915_READ(CURCNTR(PIPE_A)) & CURSOR_MODE); | |
14774 | WARN_ON(I915_READ(CURCNTR(PIPE_B)) & CURSOR_MODE); | |
2ee0da16 VS |
14775 | |
14776 | I915_WRITE(PIPECONF(pipe), 0); | |
14777 | POSTING_READ(PIPECONF(pipe)); | |
14778 | ||
a87e55f8 | 14779 | intel_wait_for_pipe_scanline_stopped(crtc); |
2ee0da16 VS |
14780 | |
14781 | I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS); | |
14782 | POSTING_READ(DPLL(pipe)); | |
14783 | } | |
14784 | ||
23ac1273 VS |
14785 | static bool intel_plane_mapping_ok(struct intel_crtc *crtc, |
14786 | struct intel_plane *primary) | |
fa555837 | 14787 | { |
b7f05d4a | 14788 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
23ac1273 VS |
14789 | enum plane plane = primary->plane; |
14790 | u32 val = I915_READ(DSPCNTR(plane)); | |
fa555837 | 14791 | |
23ac1273 VS |
14792 | return (val & DISPLAY_PLANE_ENABLE) == 0 || |
14793 | (val & DISPPLANE_SEL_PIPE_MASK) == DISPPLANE_SEL_PIPE(crtc->pipe); | |
14794 | } | |
fa555837 | 14795 | |
23ac1273 VS |
14796 | static void |
14797 | intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv) | |
14798 | { | |
14799 | struct intel_crtc *crtc; | |
fa555837 | 14800 | |
23ac1273 VS |
14801 | if (INTEL_GEN(dev_priv) >= 4) |
14802 | return; | |
fa555837 | 14803 | |
23ac1273 VS |
14804 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
14805 | struct intel_plane *plane = | |
14806 | to_intel_plane(crtc->base.primary); | |
14807 | ||
14808 | if (intel_plane_mapping_ok(crtc, plane)) | |
14809 | continue; | |
14810 | ||
14811 | DRM_DEBUG_KMS("%s attached to the wrong pipe, disabling plane\n", | |
14812 | plane->base.name); | |
14813 | intel_plane_disable_noatomic(crtc, plane); | |
14814 | } | |
fa555837 DV |
14815 | } |
14816 | ||
02e93c35 VS |
14817 | static bool intel_crtc_has_encoders(struct intel_crtc *crtc) |
14818 | { | |
14819 | struct drm_device *dev = crtc->base.dev; | |
14820 | struct intel_encoder *encoder; | |
14821 | ||
14822 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) | |
14823 | return true; | |
14824 | ||
14825 | return false; | |
14826 | } | |
14827 | ||
496b0fc3 ML |
14828 | static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder) |
14829 | { | |
14830 | struct drm_device *dev = encoder->base.dev; | |
14831 | struct intel_connector *connector; | |
14832 | ||
14833 | for_each_connector_on_encoder(dev, &encoder->base, connector) | |
14834 | return connector; | |
14835 | ||
14836 | return NULL; | |
14837 | } | |
14838 | ||
a168f5b3 | 14839 | static bool has_pch_trancoder(struct drm_i915_private *dev_priv, |
ecf837d9 | 14840 | enum pipe pch_transcoder) |
a168f5b3 VS |
14841 | { |
14842 | return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) || | |
ecf837d9 | 14843 | (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A); |
a168f5b3 VS |
14844 | } |
14845 | ||
aecd36b8 VS |
14846 | static void intel_sanitize_crtc(struct intel_crtc *crtc, |
14847 | struct drm_modeset_acquire_ctx *ctx) | |
24929352 DV |
14848 | { |
14849 | struct drm_device *dev = crtc->base.dev; | |
fac5e23e | 14850 | struct drm_i915_private *dev_priv = to_i915(dev); |
4d1de975 | 14851 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
24929352 | 14852 | |
24929352 | 14853 | /* Clear any frame start delays used for debugging left by the BIOS */ |
4d1de975 JN |
14854 | if (!transcoder_is_dsi(cpu_transcoder)) { |
14855 | i915_reg_t reg = PIPECONF(cpu_transcoder); | |
14856 | ||
14857 | I915_WRITE(reg, | |
14858 | I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); | |
14859 | } | |
24929352 | 14860 | |
d297e103 | 14861 | if (crtc->active) { |
f9cd7b88 VS |
14862 | struct intel_plane *plane; |
14863 | ||
f9cd7b88 VS |
14864 | /* Disable everything but the primary plane */ |
14865 | for_each_intel_plane_on_crtc(dev, crtc, plane) { | |
23ac1273 VS |
14866 | const struct intel_plane_state *plane_state = |
14867 | to_intel_plane_state(plane->base.state); | |
f9cd7b88 | 14868 | |
23ac1273 VS |
14869 | if (plane_state->base.visible && |
14870 | plane->base.type != DRM_PLANE_TYPE_PRIMARY) | |
14871 | intel_plane_disable_noatomic(crtc, plane); | |
f9cd7b88 | 14872 | } |
9625604c | 14873 | } |
d3eaf884 | 14874 | |
24929352 DV |
14875 | /* Adjust the state of the output pipe according to whether we |
14876 | * have active connectors/encoders. */ | |
842e0307 | 14877 | if (crtc->active && !intel_crtc_has_encoders(crtc)) |
da1d0e26 | 14878 | intel_crtc_disable_noatomic(&crtc->base, ctx); |
24929352 | 14879 | |
49cff963 | 14880 | if (crtc->active || HAS_GMCH_DISPLAY(dev_priv)) { |
4cc31489 DV |
14881 | /* |
14882 | * We start out with underrun reporting disabled to avoid races. | |
14883 | * For correct bookkeeping mark this on active crtcs. | |
14884 | * | |
c5ab3bc0 DV |
14885 | * Also on gmch platforms we dont have any hardware bits to |
14886 | * disable the underrun reporting. Which means we need to start | |
14887 | * out with underrun reporting disabled also on inactive pipes, | |
14888 | * since otherwise we'll complain about the garbage we read when | |
14889 | * e.g. coming up after runtime pm. | |
14890 | * | |
4cc31489 DV |
14891 | * No protection against concurrent access is required - at |
14892 | * worst a fifo underrun happens which also sets this to false. | |
14893 | */ | |
14894 | crtc->cpu_fifo_underrun_disabled = true; | |
a168f5b3 VS |
14895 | /* |
14896 | * We track the PCH trancoder underrun reporting state | |
14897 | * within the crtc. With crtc for pipe A housing the underrun | |
14898 | * reporting state for PCH transcoder A, crtc for pipe B housing | |
14899 | * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A, | |
14900 | * and marking underrun reporting as disabled for the non-existing | |
14901 | * PCH transcoders B and C would prevent enabling the south | |
14902 | * error interrupt (see cpt_can_enable_serr_int()). | |
14903 | */ | |
ecf837d9 | 14904 | if (has_pch_trancoder(dev_priv, crtc->pipe)) |
a168f5b3 | 14905 | crtc->pch_fifo_underrun_disabled = true; |
4cc31489 | 14906 | } |
24929352 DV |
14907 | } |
14908 | ||
14909 | static void intel_sanitize_encoder(struct intel_encoder *encoder) | |
14910 | { | |
14911 | struct intel_connector *connector; | |
24929352 DV |
14912 | |
14913 | /* We need to check both for a crtc link (meaning that the | |
14914 | * encoder is active and trying to read from a pipe) and the | |
14915 | * pipe itself being active. */ | |
14916 | bool has_active_crtc = encoder->base.crtc && | |
14917 | to_intel_crtc(encoder->base.crtc)->active; | |
14918 | ||
496b0fc3 ML |
14919 | connector = intel_encoder_find_connector(encoder); |
14920 | if (connector && !has_active_crtc) { | |
24929352 DV |
14921 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
14922 | encoder->base.base.id, | |
8e329a03 | 14923 | encoder->base.name); |
24929352 DV |
14924 | |
14925 | /* Connector is active, but has no active pipe. This is | |
14926 | * fallout from our resume register restoring. Disable | |
14927 | * the encoder manually again. */ | |
14928 | if (encoder->base.crtc) { | |
fd6bbda9 ML |
14929 | struct drm_crtc_state *crtc_state = encoder->base.crtc->state; |
14930 | ||
24929352 DV |
14931 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", |
14932 | encoder->base.base.id, | |
8e329a03 | 14933 | encoder->base.name); |
fd6bbda9 | 14934 | encoder->disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state); |
a62d1497 | 14935 | if (encoder->post_disable) |
fd6bbda9 | 14936 | encoder->post_disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state); |
24929352 | 14937 | } |
7f1950fb | 14938 | encoder->base.crtc = NULL; |
24929352 DV |
14939 | |
14940 | /* Inconsistent output/port/pipe state happens presumably due to | |
14941 | * a bug in one of the get_hw_state functions. Or someplace else | |
14942 | * in our code, like the register restore mess on resume. Clamp | |
14943 | * things to off as a safer default. */ | |
fd6bbda9 ML |
14944 | |
14945 | connector->base.dpms = DRM_MODE_DPMS_OFF; | |
14946 | connector->base.encoder = NULL; | |
24929352 DV |
14947 | } |
14948 | /* Enabled encoders without active connectors will be fixed in | |
14949 | * the crtc fixup. */ | |
14950 | } | |
14951 | ||
29b74b7f | 14952 | void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv) |
0fde901f | 14953 | { |
920a14b2 | 14954 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv); |
0fde901f | 14955 | |
04098753 ID |
14956 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
14957 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); | |
29b74b7f | 14958 | i915_disable_vga(dev_priv); |
04098753 ID |
14959 | } |
14960 | } | |
14961 | ||
29b74b7f | 14962 | void i915_redisable_vga(struct drm_i915_private *dev_priv) |
04098753 | 14963 | { |
8dc8a27c PZ |
14964 | /* This function can be called both from intel_modeset_setup_hw_state or |
14965 | * at a very early point in our resume sequence, where the power well | |
14966 | * structures are not yet restored. Since this function is at a very | |
14967 | * paranoid "someone might have enabled VGA while we were not looking" | |
14968 | * level, just check if the power well is enabled instead of trying to | |
14969 | * follow the "don't touch the power well if we don't need it" policy | |
14970 | * the rest of the driver uses. */ | |
6392f847 | 14971 | if (!intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_VGA)) |
8dc8a27c PZ |
14972 | return; |
14973 | ||
29b74b7f | 14974 | i915_redisable_vga_power_on(dev_priv); |
6392f847 ID |
14975 | |
14976 | intel_display_power_put(dev_priv, POWER_DOMAIN_VGA); | |
0fde901f KM |
14977 | } |
14978 | ||
f9cd7b88 VS |
14979 | /* FIXME read out full plane state for all planes */ |
14980 | static void readout_plane_state(struct intel_crtc *crtc) | |
d032ffa0 | 14981 | { |
23ac1273 VS |
14982 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
14983 | struct intel_crtc_state *crtc_state = | |
14984 | to_intel_crtc_state(crtc->base.state); | |
14985 | struct intel_plane *plane; | |
d032ffa0 | 14986 | |
23ac1273 VS |
14987 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
14988 | struct intel_plane_state *plane_state = | |
14989 | to_intel_plane_state(plane->base.state); | |
14990 | bool visible = plane->get_hw_state(plane); | |
b26d3ea3 | 14991 | |
23ac1273 VS |
14992 | intel_set_plane_visible(crtc_state, plane_state, visible); |
14993 | } | |
98ec7739 VS |
14994 | } |
14995 | ||
30e984df | 14996 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
24929352 | 14997 | { |
fac5e23e | 14998 | struct drm_i915_private *dev_priv = to_i915(dev); |
24929352 | 14999 | enum pipe pipe; |
24929352 DV |
15000 | struct intel_crtc *crtc; |
15001 | struct intel_encoder *encoder; | |
15002 | struct intel_connector *connector; | |
f9e905ca | 15003 | struct drm_connector_list_iter conn_iter; |
5358901f | 15004 | int i; |
24929352 | 15005 | |
565602d7 ML |
15006 | dev_priv->active_crtcs = 0; |
15007 | ||
d3fcc808 | 15008 | for_each_intel_crtc(dev, crtc) { |
a8cd6da0 VS |
15009 | struct intel_crtc_state *crtc_state = |
15010 | to_intel_crtc_state(crtc->base.state); | |
3b117c8f | 15011 | |
ec2dc6a0 | 15012 | __drm_atomic_helper_crtc_destroy_state(&crtc_state->base); |
565602d7 ML |
15013 | memset(crtc_state, 0, sizeof(*crtc_state)); |
15014 | crtc_state->base.crtc = &crtc->base; | |
24929352 | 15015 | |
565602d7 ML |
15016 | crtc_state->base.active = crtc_state->base.enable = |
15017 | dev_priv->display.get_pipe_config(crtc, crtc_state); | |
15018 | ||
15019 | crtc->base.enabled = crtc_state->base.enable; | |
15020 | crtc->active = crtc_state->base.active; | |
15021 | ||
aca1ebf4 | 15022 | if (crtc_state->base.active) |
565602d7 ML |
15023 | dev_priv->active_crtcs |= 1 << crtc->pipe; |
15024 | ||
f9cd7b88 | 15025 | readout_plane_state(crtc); |
24929352 | 15026 | |
78108b7c VS |
15027 | DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n", |
15028 | crtc->base.base.id, crtc->base.name, | |
a8cd6da0 | 15029 | enableddisabled(crtc_state->base.active)); |
24929352 DV |
15030 | } |
15031 | ||
5358901f DV |
15032 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
15033 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
15034 | ||
2edd6443 | 15035 | pll->on = pll->funcs.get_hw_state(dev_priv, pll, |
2c42e535 ACO |
15036 | &pll->state.hw_state); |
15037 | pll->state.crtc_mask = 0; | |
d3fcc808 | 15038 | for_each_intel_crtc(dev, crtc) { |
a8cd6da0 VS |
15039 | struct intel_crtc_state *crtc_state = |
15040 | to_intel_crtc_state(crtc->base.state); | |
15041 | ||
15042 | if (crtc_state->base.active && | |
15043 | crtc_state->shared_dpll == pll) | |
2c42e535 | 15044 | pll->state.crtc_mask |= 1 << crtc->pipe; |
5358901f | 15045 | } |
2c42e535 | 15046 | pll->active_mask = pll->state.crtc_mask; |
5358901f | 15047 | |
1e6f2ddc | 15048 | DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n", |
2c42e535 | 15049 | pll->name, pll->state.crtc_mask, pll->on); |
5358901f DV |
15050 | } |
15051 | ||
b2784e15 | 15052 | for_each_intel_encoder(dev, encoder) { |
24929352 DV |
15053 | pipe = 0; |
15054 | ||
15055 | if (encoder->get_hw_state(encoder, &pipe)) { | |
a8cd6da0 VS |
15056 | struct intel_crtc_state *crtc_state; |
15057 | ||
98187836 | 15058 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
a8cd6da0 | 15059 | crtc_state = to_intel_crtc_state(crtc->base.state); |
e2af48c6 | 15060 | |
045ac3b5 | 15061 | encoder->base.crtc = &crtc->base; |
a8cd6da0 VS |
15062 | crtc_state->output_types |= 1 << encoder->type; |
15063 | encoder->get_config(encoder, crtc_state); | |
24929352 DV |
15064 | } else { |
15065 | encoder->base.crtc = NULL; | |
15066 | } | |
15067 | ||
6f2bcceb | 15068 | DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n", |
08c4d7fc TU |
15069 | encoder->base.base.id, encoder->base.name, |
15070 | enableddisabled(encoder->base.crtc), | |
6f2bcceb | 15071 | pipe_name(pipe)); |
24929352 DV |
15072 | } |
15073 | ||
f9e905ca DV |
15074 | drm_connector_list_iter_begin(dev, &conn_iter); |
15075 | for_each_intel_connector_iter(connector, &conn_iter) { | |
24929352 DV |
15076 | if (connector->get_hw_state(connector)) { |
15077 | connector->base.dpms = DRM_MODE_DPMS_ON; | |
2aa974c9 ML |
15078 | |
15079 | encoder = connector->encoder; | |
15080 | connector->base.encoder = &encoder->base; | |
15081 | ||
15082 | if (encoder->base.crtc && | |
15083 | encoder->base.crtc->state->active) { | |
15084 | /* | |
15085 | * This has to be done during hardware readout | |
15086 | * because anything calling .crtc_disable may | |
15087 | * rely on the connector_mask being accurate. | |
15088 | */ | |
15089 | encoder->base.crtc->state->connector_mask |= | |
15090 | 1 << drm_connector_index(&connector->base); | |
e87a52b3 ML |
15091 | encoder->base.crtc->state->encoder_mask |= |
15092 | 1 << drm_encoder_index(&encoder->base); | |
2aa974c9 ML |
15093 | } |
15094 | ||
24929352 DV |
15095 | } else { |
15096 | connector->base.dpms = DRM_MODE_DPMS_OFF; | |
15097 | connector->base.encoder = NULL; | |
15098 | } | |
15099 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", | |
08c4d7fc TU |
15100 | connector->base.base.id, connector->base.name, |
15101 | enableddisabled(connector->base.encoder)); | |
24929352 | 15102 | } |
f9e905ca | 15103 | drm_connector_list_iter_end(&conn_iter); |
7f4c6284 VS |
15104 | |
15105 | for_each_intel_crtc(dev, crtc) { | |
a8cd6da0 VS |
15106 | struct intel_crtc_state *crtc_state = |
15107 | to_intel_crtc_state(crtc->base.state); | |
d305e061 | 15108 | int min_cdclk = 0; |
aca1ebf4 | 15109 | |
7f4c6284 | 15110 | memset(&crtc->base.mode, 0, sizeof(crtc->base.mode)); |
a8cd6da0 VS |
15111 | if (crtc_state->base.active) { |
15112 | intel_mode_from_pipe_config(&crtc->base.mode, crtc_state); | |
15113 | intel_mode_from_pipe_config(&crtc_state->base.adjusted_mode, crtc_state); | |
7f4c6284 VS |
15114 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode)); |
15115 | ||
15116 | /* | |
15117 | * The initial mode needs to be set in order to keep | |
15118 | * the atomic core happy. It wants a valid mode if the | |
15119 | * crtc's enabled, so we do the above call. | |
15120 | * | |
7800fb69 DV |
15121 | * But we don't set all the derived state fully, hence |
15122 | * set a flag to indicate that a full recalculation is | |
15123 | * needed on the next commit. | |
7f4c6284 | 15124 | */ |
a8cd6da0 | 15125 | crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED; |
9eca6832 | 15126 | |
a7d1b3f4 VS |
15127 | intel_crtc_compute_pixel_rate(crtc_state); |
15128 | ||
9c61de4c | 15129 | if (dev_priv->display.modeset_calc_cdclk) { |
d305e061 | 15130 | min_cdclk = intel_crtc_compute_min_cdclk(crtc_state); |
9c61de4c VS |
15131 | if (WARN_ON(min_cdclk < 0)) |
15132 | min_cdclk = 0; | |
15133 | } | |
aca1ebf4 | 15134 | |
5caa0fea DV |
15135 | drm_calc_timestamping_constants(&crtc->base, |
15136 | &crtc_state->base.adjusted_mode); | |
9eca6832 | 15137 | update_scanline_offset(crtc); |
7f4c6284 | 15138 | } |
e3b247da | 15139 | |
d305e061 | 15140 | dev_priv->min_cdclk[crtc->pipe] = min_cdclk; |
aca1ebf4 | 15141 | |
a8cd6da0 | 15142 | intel_pipe_config_sanity_check(dev_priv, crtc_state); |
7f4c6284 | 15143 | } |
30e984df DV |
15144 | } |
15145 | ||
62b69566 ACO |
15146 | static void |
15147 | get_encoder_power_domains(struct drm_i915_private *dev_priv) | |
15148 | { | |
15149 | struct intel_encoder *encoder; | |
15150 | ||
15151 | for_each_intel_encoder(&dev_priv->drm, encoder) { | |
15152 | u64 get_domains; | |
15153 | enum intel_display_power_domain domain; | |
15154 | ||
15155 | if (!encoder->get_power_domains) | |
15156 | continue; | |
15157 | ||
15158 | get_domains = encoder->get_power_domains(encoder); | |
15159 | for_each_power_domain(domain, get_domains) | |
15160 | intel_display_power_get(dev_priv, domain); | |
15161 | } | |
15162 | } | |
15163 | ||
043e9bda ML |
15164 | /* Scan out the current hw modeset state, |
15165 | * and sanitizes it to the current state | |
15166 | */ | |
15167 | static void | |
aecd36b8 VS |
15168 | intel_modeset_setup_hw_state(struct drm_device *dev, |
15169 | struct drm_modeset_acquire_ctx *ctx) | |
30e984df | 15170 | { |
fac5e23e | 15171 | struct drm_i915_private *dev_priv = to_i915(dev); |
30e984df DV |
15172 | struct intel_crtc *crtc; |
15173 | struct intel_encoder *encoder; | |
35c95375 | 15174 | int i; |
30e984df | 15175 | |
6ac43272 VS |
15176 | if (IS_HASWELL(dev_priv)) { |
15177 | /* | |
15178 | * WaRsPkgCStateDisplayPMReq:hsw | |
15179 | * System hang if this isn't done before disabling all planes! | |
15180 | */ | |
15181 | I915_WRITE(CHICKEN_PAR1_1, | |
15182 | I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES); | |
15183 | } | |
15184 | ||
30e984df | 15185 | intel_modeset_readout_hw_state(dev); |
24929352 DV |
15186 | |
15187 | /* HW state is read out, now we need to sanitize this mess. */ | |
62b69566 ACO |
15188 | get_encoder_power_domains(dev_priv); |
15189 | ||
41df9073 VS |
15190 | /* |
15191 | * intel_sanitize_plane_mapping() may need to do vblank | |
15192 | * waits, so we need vblank interrupts restored beforehand. | |
15193 | */ | |
15194 | for_each_intel_crtc(&dev_priv->drm, crtc) { | |
15195 | drm_crtc_vblank_reset(&crtc->base); | |
23ac1273 | 15196 | |
41df9073 VS |
15197 | if (crtc->active) |
15198 | drm_crtc_vblank_on(&crtc->base); | |
24929352 DV |
15199 | } |
15200 | ||
41df9073 | 15201 | intel_sanitize_plane_mapping(dev_priv); |
e2af48c6 | 15202 | |
41df9073 VS |
15203 | for_each_intel_encoder(dev, encoder) |
15204 | intel_sanitize_encoder(encoder); | |
15205 | ||
15206 | for_each_intel_crtc(&dev_priv->drm, crtc) { | |
aecd36b8 | 15207 | intel_sanitize_crtc(crtc, ctx); |
6e3c9717 ACO |
15208 | intel_dump_pipe_config(crtc, crtc->config, |
15209 | "[setup_hw_state]"); | |
24929352 | 15210 | } |
9a935856 | 15211 | |
d29b2f9d ACO |
15212 | intel_modeset_update_connector_atomic_state(dev); |
15213 | ||
35c95375 DV |
15214 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
15215 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; | |
15216 | ||
2dd66ebd | 15217 | if (!pll->on || pll->active_mask) |
35c95375 DV |
15218 | continue; |
15219 | ||
15220 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name); | |
15221 | ||
2edd6443 | 15222 | pll->funcs.disable(dev_priv, pll); |
35c95375 DV |
15223 | pll->on = false; |
15224 | } | |
15225 | ||
04548cba VS |
15226 | if (IS_G4X(dev_priv)) { |
15227 | g4x_wm_get_hw_state(dev); | |
15228 | g4x_wm_sanitize(dev_priv); | |
15229 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { | |
6eb1a681 | 15230 | vlv_wm_get_hw_state(dev); |
602ae835 | 15231 | vlv_wm_sanitize(dev_priv); |
a029fa4d | 15232 | } else if (INTEL_GEN(dev_priv) >= 9) { |
3078999f | 15233 | skl_wm_get_hw_state(dev); |
602ae835 | 15234 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
243e6a44 | 15235 | ilk_wm_get_hw_state(dev); |
602ae835 | 15236 | } |
292b990e ML |
15237 | |
15238 | for_each_intel_crtc(dev, crtc) { | |
d8fc70b7 | 15239 | u64 put_domains; |
292b990e | 15240 | |
74bff5f9 | 15241 | put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc->config); |
292b990e ML |
15242 | if (WARN_ON(put_domains)) |
15243 | modeset_put_power_domains(dev_priv, put_domains); | |
15244 | } | |
15245 | intel_display_set_init_power(dev_priv, false); | |
010cf73d | 15246 | |
8d8c386c ID |
15247 | intel_power_domains_verify_state(dev_priv); |
15248 | ||
010cf73d | 15249 | intel_fbc_init_pipe_state(dev_priv); |
043e9bda | 15250 | } |
7d0bc1ea | 15251 | |
043e9bda ML |
15252 | void intel_display_resume(struct drm_device *dev) |
15253 | { | |
e2c8b870 ML |
15254 | struct drm_i915_private *dev_priv = to_i915(dev); |
15255 | struct drm_atomic_state *state = dev_priv->modeset_restore_state; | |
15256 | struct drm_modeset_acquire_ctx ctx; | |
043e9bda | 15257 | int ret; |
f30da187 | 15258 | |
e2c8b870 | 15259 | dev_priv->modeset_restore_state = NULL; |
73974893 ML |
15260 | if (state) |
15261 | state->acquire_ctx = &ctx; | |
043e9bda | 15262 | |
e2c8b870 | 15263 | drm_modeset_acquire_init(&ctx, 0); |
043e9bda | 15264 | |
73974893 ML |
15265 | while (1) { |
15266 | ret = drm_modeset_lock_all_ctx(dev, &ctx); | |
15267 | if (ret != -EDEADLK) | |
15268 | break; | |
043e9bda | 15269 | |
e2c8b870 | 15270 | drm_modeset_backoff(&ctx); |
e2c8b870 | 15271 | } |
043e9bda | 15272 | |
73974893 | 15273 | if (!ret) |
581e49fe | 15274 | ret = __intel_display_resume(dev, state, &ctx); |
73974893 | 15275 | |
2503a0fe | 15276 | intel_enable_ipc(dev_priv); |
e2c8b870 ML |
15277 | drm_modeset_drop_locks(&ctx); |
15278 | drm_modeset_acquire_fini(&ctx); | |
043e9bda | 15279 | |
0853695c | 15280 | if (ret) |
e2c8b870 | 15281 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
3c5e37f1 CW |
15282 | if (state) |
15283 | drm_atomic_state_put(state); | |
2c7111db CW |
15284 | } |
15285 | ||
15286 | void intel_modeset_gem_init(struct drm_device *dev) | |
15287 | { | |
dc97997a | 15288 | struct drm_i915_private *dev_priv = to_i915(dev); |
484b41dd | 15289 | |
1ee8da6d | 15290 | intel_setup_overlay(dev_priv); |
1ebaa0b9 CW |
15291 | } |
15292 | ||
15293 | int intel_connector_register(struct drm_connector *connector) | |
15294 | { | |
15295 | struct intel_connector *intel_connector = to_intel_connector(connector); | |
15296 | int ret; | |
15297 | ||
15298 | ret = intel_backlight_device_register(intel_connector); | |
15299 | if (ret) | |
15300 | goto err; | |
15301 | ||
15302 | return 0; | |
0962c3c9 | 15303 | |
1ebaa0b9 CW |
15304 | err: |
15305 | return ret; | |
79e53945 JB |
15306 | } |
15307 | ||
c191eca1 | 15308 | void intel_connector_unregister(struct drm_connector *connector) |
4932e2c3 | 15309 | { |
e63d87c0 | 15310 | struct intel_connector *intel_connector = to_intel_connector(connector); |
4932e2c3 | 15311 | |
e63d87c0 | 15312 | intel_backlight_device_unregister(intel_connector); |
4932e2c3 | 15313 | intel_panel_destroy_backlight(connector); |
4932e2c3 ID |
15314 | } |
15315 | ||
713946d1 MN |
15316 | static void intel_hpd_poll_fini(struct drm_device *dev) |
15317 | { | |
15318 | struct intel_connector *connector; | |
15319 | struct drm_connector_list_iter conn_iter; | |
15320 | ||
15321 | /* First disable polling... */ | |
15322 | drm_kms_helper_poll_fini(dev); | |
15323 | ||
15324 | /* Then kill the work that may have been queued by hpd. */ | |
15325 | drm_connector_list_iter_begin(dev, &conn_iter); | |
15326 | for_each_intel_connector_iter(connector, &conn_iter) { | |
15327 | if (connector->modeset_retry_work.func) | |
15328 | cancel_work_sync(&connector->modeset_retry_work); | |
15329 | } | |
15330 | drm_connector_list_iter_end(&conn_iter); | |
15331 | } | |
15332 | ||
79e53945 JB |
15333 | void intel_modeset_cleanup(struct drm_device *dev) |
15334 | { | |
fac5e23e | 15335 | struct drm_i915_private *dev_priv = to_i915(dev); |
652c393a | 15336 | |
eb955eee CW |
15337 | flush_work(&dev_priv->atomic_helper.free_work); |
15338 | WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list)); | |
15339 | ||
dc97997a | 15340 | intel_disable_gt_powersave(dev_priv); |
2eb5252e | 15341 | |
fd0c0642 DV |
15342 | /* |
15343 | * Interrupts and polling as the first thing to avoid creating havoc. | |
2eb5252e | 15344 | * Too much stuff here (turning of connectors, ...) would |
fd0c0642 DV |
15345 | * experience fancy races otherwise. |
15346 | */ | |
2aeb7d3a | 15347 | intel_irq_uninstall(dev_priv); |
eb21b92b | 15348 | |
fd0c0642 DV |
15349 | /* |
15350 | * Due to the hpd irq storm handling the hotplug work can re-arm the | |
15351 | * poll handlers. Hence disable polling after hpd handling is shut down. | |
15352 | */ | |
713946d1 | 15353 | intel_hpd_poll_fini(dev); |
fd0c0642 | 15354 | |
4f256d82 DV |
15355 | /* poll work can call into fbdev, hence clean that up afterwards */ |
15356 | intel_fbdev_fini(dev_priv); | |
15357 | ||
723bfd70 JB |
15358 | intel_unregister_dsm_handler(); |
15359 | ||
c937ab3e | 15360 | intel_fbc_global_disable(dev_priv); |
69341a5e | 15361 | |
1630fe75 CW |
15362 | /* flush any delayed tasks or pending work */ |
15363 | flush_scheduled_work(); | |
15364 | ||
79e53945 | 15365 | drm_mode_config_cleanup(dev); |
4d7bb011 | 15366 | |
1ee8da6d | 15367 | intel_cleanup_overlay(dev_priv); |
ae48434c | 15368 | |
dc97997a | 15369 | intel_cleanup_gt_powersave(dev_priv); |
f5949141 | 15370 | |
40196446 | 15371 | intel_teardown_gmbus(dev_priv); |
eda41bdc VS |
15372 | |
15373 | destroy_workqueue(dev_priv->modeset_wq); | |
79e53945 JB |
15374 | } |
15375 | ||
df0e9248 CW |
15376 | void intel_connector_attach_encoder(struct intel_connector *connector, |
15377 | struct intel_encoder *encoder) | |
15378 | { | |
15379 | connector->encoder = encoder; | |
15380 | drm_mode_connector_attach_encoder(&connector->base, | |
15381 | &encoder->base); | |
79e53945 | 15382 | } |
28d52043 DA |
15383 | |
15384 | /* | |
15385 | * set vga decode state - true == enable VGA decode | |
15386 | */ | |
6315b5d3 | 15387 | int intel_modeset_vga_set_state(struct drm_i915_private *dev_priv, bool state) |
28d52043 | 15388 | { |
6315b5d3 | 15389 | unsigned reg = INTEL_GEN(dev_priv) >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL; |
28d52043 DA |
15390 | u16 gmch_ctrl; |
15391 | ||
75fa041d CW |
15392 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
15393 | DRM_ERROR("failed to read control word\n"); | |
15394 | return -EIO; | |
15395 | } | |
15396 | ||
c0cc8a55 CW |
15397 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
15398 | return 0; | |
15399 | ||
28d52043 DA |
15400 | if (state) |
15401 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; | |
15402 | else | |
15403 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; | |
75fa041d CW |
15404 | |
15405 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { | |
15406 | DRM_ERROR("failed to write control word\n"); | |
15407 | return -EIO; | |
15408 | } | |
15409 | ||
28d52043 DA |
15410 | return 0; |
15411 | } | |
c4a1d9e4 | 15412 | |
98a2f411 CW |
15413 | #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR) |
15414 | ||
c4a1d9e4 | 15415 | struct intel_display_error_state { |
ff57f1b0 PZ |
15416 | |
15417 | u32 power_well_driver; | |
15418 | ||
63b66e5b CW |
15419 | int num_transcoders; |
15420 | ||
c4a1d9e4 CW |
15421 | struct intel_cursor_error_state { |
15422 | u32 control; | |
15423 | u32 position; | |
15424 | u32 base; | |
15425 | u32 size; | |
52331309 | 15426 | } cursor[I915_MAX_PIPES]; |
c4a1d9e4 CW |
15427 | |
15428 | struct intel_pipe_error_state { | |
ddf9c536 | 15429 | bool power_domain_on; |
c4a1d9e4 | 15430 | u32 source; |
f301b1e1 | 15431 | u32 stat; |
52331309 | 15432 | } pipe[I915_MAX_PIPES]; |
c4a1d9e4 CW |
15433 | |
15434 | struct intel_plane_error_state { | |
15435 | u32 control; | |
15436 | u32 stride; | |
15437 | u32 size; | |
15438 | u32 pos; | |
15439 | u32 addr; | |
15440 | u32 surface; | |
15441 | u32 tile_offset; | |
52331309 | 15442 | } plane[I915_MAX_PIPES]; |
63b66e5b CW |
15443 | |
15444 | struct intel_transcoder_error_state { | |
ddf9c536 | 15445 | bool power_domain_on; |
63b66e5b CW |
15446 | enum transcoder cpu_transcoder; |
15447 | ||
15448 | u32 conf; | |
15449 | ||
15450 | u32 htotal; | |
15451 | u32 hblank; | |
15452 | u32 hsync; | |
15453 | u32 vtotal; | |
15454 | u32 vblank; | |
15455 | u32 vsync; | |
15456 | } transcoder[4]; | |
c4a1d9e4 CW |
15457 | }; |
15458 | ||
15459 | struct intel_display_error_state * | |
c033666a | 15460 | intel_display_capture_error_state(struct drm_i915_private *dev_priv) |
c4a1d9e4 | 15461 | { |
c4a1d9e4 | 15462 | struct intel_display_error_state *error; |
63b66e5b CW |
15463 | int transcoders[] = { |
15464 | TRANSCODER_A, | |
15465 | TRANSCODER_B, | |
15466 | TRANSCODER_C, | |
15467 | TRANSCODER_EDP, | |
15468 | }; | |
c4a1d9e4 CW |
15469 | int i; |
15470 | ||
c033666a | 15471 | if (INTEL_INFO(dev_priv)->num_pipes == 0) |
63b66e5b CW |
15472 | return NULL; |
15473 | ||
9d1cb914 | 15474 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
c4a1d9e4 CW |
15475 | if (error == NULL) |
15476 | return NULL; | |
15477 | ||
c033666a | 15478 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
9c3a16c8 ID |
15479 | error->power_well_driver = |
15480 | I915_READ(HSW_PWR_WELL_CTL_DRIVER(HSW_DISP_PW_GLOBAL)); | |
ff57f1b0 | 15481 | |
055e393f | 15482 | for_each_pipe(dev_priv, i) { |
ddf9c536 | 15483 | error->pipe[i].power_domain_on = |
f458ebbc DV |
15484 | __intel_display_power_is_enabled(dev_priv, |
15485 | POWER_DOMAIN_PIPE(i)); | |
ddf9c536 | 15486 | if (!error->pipe[i].power_domain_on) |
9d1cb914 PZ |
15487 | continue; |
15488 | ||
5efb3e28 VS |
15489 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
15490 | error->cursor[i].position = I915_READ(CURPOS(i)); | |
15491 | error->cursor[i].base = I915_READ(CURBASE(i)); | |
c4a1d9e4 CW |
15492 | |
15493 | error->plane[i].control = I915_READ(DSPCNTR(i)); | |
15494 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); | |
c033666a | 15495 | if (INTEL_GEN(dev_priv) <= 3) { |
51889b35 | 15496 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
80ca378b PZ |
15497 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
15498 | } | |
c033666a | 15499 | if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv)) |
ca291363 | 15500 | error->plane[i].addr = I915_READ(DSPADDR(i)); |
c033666a | 15501 | if (INTEL_GEN(dev_priv) >= 4) { |
c4a1d9e4 CW |
15502 | error->plane[i].surface = I915_READ(DSPSURF(i)); |
15503 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); | |
15504 | } | |
15505 | ||
c4a1d9e4 | 15506 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
f301b1e1 | 15507 | |
c033666a | 15508 | if (HAS_GMCH_DISPLAY(dev_priv)) |
f301b1e1 | 15509 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
63b66e5b CW |
15510 | } |
15511 | ||
4d1de975 | 15512 | /* Note: this does not include DSI transcoders. */ |
c033666a | 15513 | error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes; |
2d1fe073 | 15514 | if (HAS_DDI(dev_priv)) |
63b66e5b CW |
15515 | error->num_transcoders++; /* Account for eDP. */ |
15516 | ||
15517 | for (i = 0; i < error->num_transcoders; i++) { | |
15518 | enum transcoder cpu_transcoder = transcoders[i]; | |
15519 | ||
ddf9c536 | 15520 | error->transcoder[i].power_domain_on = |
f458ebbc | 15521 | __intel_display_power_is_enabled(dev_priv, |
38cc1daf | 15522 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
ddf9c536 | 15523 | if (!error->transcoder[i].power_domain_on) |
9d1cb914 PZ |
15524 | continue; |
15525 | ||
63b66e5b CW |
15526 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
15527 | ||
15528 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); | |
15529 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); | |
15530 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); | |
15531 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); | |
15532 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); | |
15533 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); | |
15534 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); | |
c4a1d9e4 CW |
15535 | } |
15536 | ||
15537 | return error; | |
15538 | } | |
15539 | ||
edc3d884 MK |
15540 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
15541 | ||
c4a1d9e4 | 15542 | void |
edc3d884 | 15543 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
c4a1d9e4 CW |
15544 | struct intel_display_error_state *error) |
15545 | { | |
5a4c6f1b | 15546 | struct drm_i915_private *dev_priv = m->i915; |
c4a1d9e4 CW |
15547 | int i; |
15548 | ||
63b66e5b CW |
15549 | if (!error) |
15550 | return; | |
15551 | ||
b7f05d4a | 15552 | err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev_priv)->num_pipes); |
8652744b | 15553 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
edc3d884 | 15554 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
ff57f1b0 | 15555 | error->power_well_driver); |
055e393f | 15556 | for_each_pipe(dev_priv, i) { |
edc3d884 | 15557 | err_printf(m, "Pipe [%d]:\n", i); |
ddf9c536 | 15558 | err_printf(m, " Power: %s\n", |
87ad3212 | 15559 | onoff(error->pipe[i].power_domain_on)); |
edc3d884 | 15560 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
f301b1e1 | 15561 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
edc3d884 MK |
15562 | |
15563 | err_printf(m, "Plane [%d]:\n", i); | |
15564 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); | |
15565 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); | |
5f56d5f9 | 15566 | if (INTEL_GEN(dev_priv) <= 3) { |
edc3d884 MK |
15567 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
15568 | err_printf(m, " POS: %08x\n", error->plane[i].pos); | |
80ca378b | 15569 | } |
772c2a51 | 15570 | if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv)) |
edc3d884 | 15571 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
5f56d5f9 | 15572 | if (INTEL_GEN(dev_priv) >= 4) { |
edc3d884 MK |
15573 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
15574 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); | |
c4a1d9e4 CW |
15575 | } |
15576 | ||
edc3d884 MK |
15577 | err_printf(m, "Cursor [%d]:\n", i); |
15578 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); | |
15579 | err_printf(m, " POS: %08x\n", error->cursor[i].position); | |
15580 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); | |
c4a1d9e4 | 15581 | } |
63b66e5b CW |
15582 | |
15583 | for (i = 0; i < error->num_transcoders; i++) { | |
da205630 | 15584 | err_printf(m, "CPU transcoder: %s\n", |
63b66e5b | 15585 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
ddf9c536 | 15586 | err_printf(m, " Power: %s\n", |
87ad3212 | 15587 | onoff(error->transcoder[i].power_domain_on)); |
63b66e5b CW |
15588 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
15589 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); | |
15590 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); | |
15591 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); | |
15592 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); | |
15593 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); | |
15594 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); | |
15595 | } | |
c4a1d9e4 | 15596 | } |
98a2f411 CW |
15597 | |
15598 | #endif |